import { CopilotClient } from "./client.js";
import {
  defaultJoinSessionPermissionHandler
} from "./types.js";
import {
  Canvas,
  CanvasError,
  createCanvas
} from "./canvas.js";
import {
  defineFactory,
  FactoryResumeError,
  isFactoryRunTerminal
} from "./factory.js";
async function joinSession(config = {}) {
  const sessionId = process.env.SESSION_ID;
  if (!sessionId) {
    throw new Error(
      "joinSession() is intended for extensions running as child processes of the Copilot CLI."
    );
  }
  const client = new CopilotClient({ _internalConnection: { kind: "parent-process" } });
  const {
    extensionSdkPath: _stripped,
    factories,
    ...rest
  } = config;
  void _stripped;
  return client.resumeSessionForExtension(
    sessionId,
    {
      ...rest,
      onPermissionRequest: config.onPermissionRequest ?? defaultJoinSessionPermissionHandler,
      suppressResumeEvent: config.suppressResumeEvent ?? true
    },
    factories
  );
}
export {
  Canvas,
  CanvasError,
  FactoryResumeError,
  createCanvas,
  defineFactory,
  isFactoryRunTerminal,
  joinSession
};
