/** * Child-side `@github/copilot-sdk/extension` implementation. * * Design: `docs/canvas-extensions-design.md` §4, §4.1. A canvas extension from * `github/awesome-copilot` is a directory of plain `.mjs` files whose only * external import is `@github/copilot-sdk/extension` — GitHub's own * `docs/extensions.md` states the import "is resolved automatically — you don't * install it", and none of the 23 catalog extensions ships `node_modules`. This * module is what hoocode resolves that specifier to inside the forked child, so a * catalog canvas runs byte-identical to upstream with nothing written into its * directory. * * What this is not: the SDK's `joinSession` resolves to a full `CopilotSession` * (messaging, events, RPC passthrough, factories). This shim implements the * canvas surface and `log` only. `tools`, `hooks`, and `factories` are accepted * and reported as unsupported so an extension that uses them fails visibly rather * than half-working (design doc §6.2). The canvas types themselves are held * structurally identical to the SDK's by * `test/canvas-protocol-conformance.test.ts`. */ import { type CanvasDeclaration, type CanvasJsonSchema, type CanvasLogLevel, type CanvasProviderCloseRequest, type CanvasProviderInvokeActionRequest, type CanvasProviderOpenRequest, type CanvasProviderOpenResult } from "../protocol.js"; /** * A single agent-callable action contributed by a canvas. Mirrors the SDK's * `CanvasAction`: the `handler` closure is stripped before the declaration is * sent and dispatched in-process here. */ export interface CanvasAction { /** Action identifier, unique within the canvas. */ name: string; /** Description shown to the model when picking an action. */ description?: string; /** Optional JSON Schema for the action's `input` payload. */ inputSchema?: CanvasJsonSchema; /** Required per-action dispatch handler. */ handler: (ctx: CanvasProviderInvokeActionRequest) => Promise | unknown; } /** Options accepted by {@link createCanvas}. Mirrors the SDK's `CanvasOptions`. */ export interface CanvasOptions { /** Canvas id, unique within the declaring connection. */ id: string; /** Human-readable label shown in discovery and host UI chrome. */ displayName: string; /** Short, single-sentence description shown to the agent in canvas catalogs. */ description: string; /** Optional JSON Schema for the `input` payload accepted by `canvas.open`. */ inputSchema?: CanvasJsonSchema; /** Agent-invocable actions, each carrying its own required handler. */ actions?: CanvasAction[]; /** Required. Open a new canvas instance. */ open: (ctx: CanvasProviderOpenRequest) => Promise | CanvasProviderOpenResult; /** * Optional. Notified when a canvas instance is closed. Fire-and-forget: the * return value is ignored and errors are logged but not surfaced. */ onClose?: (ctx: CanvasProviderCloseRequest) => Promise | void; } /** Structured error returned from canvas handlers. Mirrors the SDK's `CanvasError`. */ export declare class CanvasError extends Error { readonly code: string; constructor(code: string, message: string); /** Default error when an action is declared but no `handler` is wired. */ static noHandler(): CanvasError; } /** A registered canvas: declarative metadata plus in-process handler closures. */ export declare class Canvas { readonly declaration: CanvasDeclaration; readonly open: NonNullable; readonly onClose?: CanvasOptions["onClose"]; /** Handlers by action name, kept out of the declaration that crosses the wire. */ readonly handlers: ReadonlyMap; constructor(options: CanvasOptions); } /** Create a canvas declaration with bound in-process handlers. */ export declare function createCanvas(options: CanvasOptions): Canvas; /** Configuration accepted by {@link joinSession}. */ export interface JoinSessionConfig { canvases?: Canvas[]; /** Accepted and reported as unsupported (design doc §6.2). */ tools?: unknown; /** Accepted and reported as unsupported (design doc §6.2). */ hooks?: unknown; /** Accepted and reported as unsupported (design doc §6.2). */ factories?: unknown; /** Accepted and reported as unsupported (design doc §6.2). */ onPermissionRequest?: unknown; } /** * The subset of the SDK's `CopilotSession` this shim provides. Deliberately small: * see the module header. */ export interface CanvasShimSession { /** Log a message to the session timeline. */ log(message: string, options?: { level?: CanvasLogLevel; ephemeral?: boolean; }): Promise; } /** Streams the shim reads from and writes to. Injectable so tests need no child process. */ export interface CanvasShimStreams { input: { setEncoding(encoding: "utf8"): unknown; on(event: "data", listener: (chunk: string) => void): unknown; }; write(chunk: string): unknown; /** Provider identifier; the runner passes it in the environment. */ extensionId: string; } /** * Join the host session: announce the declared canvases, then serve provider * callbacks until the input stream ends. */ export declare function joinSession(config?: JoinSessionConfig, streams?: CanvasShimStreams): Promise; //# sourceMappingURL=index.d.ts.map