@github/copilot-sdk 1.0.0-beta.1 → 1.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,10 @@
4
4
  * JSON-RPC based SDK for programmatic control of GitHub Copilot CLI
5
5
  */
6
6
  export { CopilotClient } from "./client.js";
7
+ export { RuntimeConnection } from "./types.js";
8
+ export { BuiltInTools, ToolSet } from "./toolSet.js";
7
9
  export { CopilotSession, type AssistantMessageEvent } from "./session.js";
8
- export { defineTool, approveAll, convertMcpCallToolResult, createSessionFsAdapter, SYSTEM_PROMPT_SECTIONS, } from "./types.js";
9
- export type { CommandContext, CommandDefinition, CommandHandler, ConnectionState, CopilotClientOptions, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, InputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventType, SessionLifecycleHandler, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemPromptSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
10
+ export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasHostContextCapabilities, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
11
+ export { defineTool, approveAll, convertMcpCallToolResult, createSessionFsAdapter, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
12
+ export type * from "./generated/session-events.js";
13
+ export type { CommandContext, CommandDefinition, CommandHandler, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, CopilotClientMode, CopilotClientOptions, StdioRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, LargeToolOutputConfig, UiInputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolTelemetry, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
package/dist/index.js CHANGED
@@ -1,18 +1,31 @@
1
1
  import { CopilotClient } from "./client.js";
2
+ import { RuntimeConnection } from "./types.js";
3
+ import { BuiltInTools, ToolSet } from "./toolSet.js";
2
4
  import { CopilotSession } from "./session.js";
5
+ import {
6
+ Canvas,
7
+ CanvasError,
8
+ createCanvas
9
+ } from "./canvas.js";
3
10
  import {
4
11
  defineTool,
5
12
  approveAll,
6
13
  convertMcpCallToolResult,
7
14
  createSessionFsAdapter,
8
- SYSTEM_PROMPT_SECTIONS
15
+ SYSTEM_MESSAGE_SECTIONS
9
16
  } from "./types.js";
10
17
  export {
18
+ BuiltInTools,
19
+ Canvas,
20
+ CanvasError,
11
21
  CopilotClient,
12
22
  CopilotSession,
13
- SYSTEM_PROMPT_SECTIONS,
23
+ RuntimeConnection,
24
+ SYSTEM_MESSAGE_SECTIONS,
25
+ ToolSet,
14
26
  approveAll,
15
27
  convertMcpCallToolResult,
28
+ createCanvas,
16
29
  createSessionFsAdapter,
17
30
  defineTool
18
31
  };
package/dist/session.d.ts CHANGED
@@ -1,12 +1,6 @@
1
- /**
2
- * Copilot Session - represents a single conversation session with the Copilot CLI.
3
- * @module session
4
- */
5
- import type { MessageConnection } from "vscode-jsonrpc/node.js";
6
1
  import { createSessionRpc } from "./generated/rpc.js";
7
- import type { ClientSessionApiHandlers } from "./generated/rpc.js";
8
- import type { CommandHandler, ElicitationHandler, ElicitationContext, MessageOptions, PermissionHandler, PermissionRequestResult, ReasoningEffort, ModelCapabilitiesOverride, SectionTransformFn, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionHooks, SessionUiApi, Tool, ToolHandler, TraceContextProvider, TypedSessionEventHandler, UserInputHandler, UserInputResponse } from "./types.js";
9
- export declare const NO_RESULT_PERMISSION_V2_ERROR = "Permission handlers cannot return 'no-result' when connected to a protocol v2 server.";
2
+ import type { OpenCanvasInstance } from "./generated/rpc.js";
3
+ import type { MessageOptions, ContextTier, ReasoningEffort, ReasoningSummary, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TypedSessionEventHandler } from "./types.js";
10
4
  /** Assistant message event - the final response from the assistant. */
11
5
  export type AssistantMessageEvent = Extract<SessionEvent, {
12
6
  type: "assistant.message";
@@ -43,27 +37,19 @@ export declare class CopilotSession {
43
37
  private eventHandlers;
44
38
  private typedEventHandlers;
45
39
  private toolHandlers;
40
+ private canvases;
46
41
  private commandHandlers;
47
42
  private permissionHandler?;
48
43
  private userInputHandler?;
49
44
  private elicitationHandler?;
45
+ private exitPlanModeHandler?;
46
+ private autoModeSwitchHandler?;
50
47
  private hooks?;
51
48
  private transformCallbacks?;
52
49
  private _rpc;
53
50
  private traceContextProvider?;
54
51
  private _capabilities;
55
- /** @internal Client session API handlers, populated by CopilotClient during create/resume. */
56
- clientSessionApis: ClientSessionApiHandlers;
57
- /**
58
- * Creates a new CopilotSession instance.
59
- *
60
- * @param sessionId - The unique identifier for this session
61
- * @param connection - The JSON-RPC message connection to the Copilot CLI
62
- * @param workspacePath - Path to the session workspace directory (when infinite sessions enabled)
63
- * @param traceContextProvider - Optional callback to get W3C Trace Context for outbound RPCs
64
- * @internal This constructor is internal. Use {@link CopilotClient.createSession} to create sessions.
65
- */
66
- constructor(sessionId: string, connection: MessageConnection, _workspacePath?: string | undefined, traceContextProvider?: TraceContextProvider);
52
+ private openCanvasInstances;
67
53
  /**
68
54
  * Typed session-scoped RPC methods.
69
55
  */
@@ -110,6 +96,7 @@ export declare class CopilotSession {
110
96
  * });
111
97
  * ```
112
98
  */
99
+ send(prompt: string): Promise<string>;
113
100
  send(options: MessageOptions): Promise<string>;
114
101
  /**
115
102
  * Sends a message to this session and waits until the session becomes idle.
@@ -134,6 +121,7 @@ export declare class CopilotSession {
134
121
  * console.log(response?.data.content); // "4"
135
122
  * ```
136
123
  */
124
+ sendAndWait(prompt: string, timeout?: number): Promise<AssistantMessageEvent | undefined>;
137
125
  sendAndWait(options: MessageOptions, timeout?: number): Promise<AssistantMessageEvent | undefined>;
138
126
  /**
139
127
  * Subscribes to events from this session.
@@ -181,167 +169,20 @@ export declare class CopilotSession {
181
169
  * ```
182
170
  */
183
171
  on(handler: SessionEventHandler): () => void;
172
+ private upsertOpenCanvasFromEvent;
173
+ private upsertOpenCanvas;
184
174
  /**
185
- * Dispatches an event to all registered handlers.
186
- * Also handles broadcast request events internally (external tool calls, permissions).
187
- *
188
- * @param event - The session event to dispatch
189
- * @internal This method is for internal use by the SDK.
190
- */
191
- _dispatchEvent(event: SessionEvent): void;
192
- /**
193
- * Handles broadcast request events by executing local handlers and responding via RPC.
194
- * Handlers are dispatched as fire-and-forget — rejections propagate as unhandled promise
195
- * rejections, consistent with standard EventEmitter / event handler semantics.
196
- * @internal
175
+ * Snapshot of canvas instances currently known to be open for this session.
176
+ * Populated from the `session.resume` response and live `session.canvas.opened`
177
+ * events. Returns a defensive copy — mutating the returned array has no effect
178
+ * on the session.
197
179
  */
198
- private _handleBroadcastEvent;
199
- /**
200
- * Executes a tool handler and sends the result back via RPC.
201
- * @internal
202
- */
203
- private _executeToolAndRespond;
204
- /**
205
- * Executes a permission handler and sends the result back via RPC.
206
- * @internal
207
- */
208
- private _executePermissionAndRespond;
209
- /**
210
- * Executes a command handler and sends the result back via RPC.
211
- * @internal
212
- */
213
- private _executeCommandAndRespond;
214
- /**
215
- * Registers custom tool handlers for this session.
216
- *
217
- * Tools allow the assistant to execute custom functions. When the assistant
218
- * invokes a tool, the corresponding handler is called with the tool arguments.
219
- *
220
- * @param tools - An array of tool definitions with their handlers, or undefined to clear all tools
221
- * @internal This method is typically called internally when creating a session with tools.
222
- */
223
- registerTools(tools?: Tool[]): void;
224
- /**
225
- * Retrieves a registered tool handler by name.
226
- *
227
- * @param name - The name of the tool to retrieve
228
- * @returns The tool handler if found, or undefined
229
- * @internal This method is for internal use by the SDK.
230
- */
231
- getToolHandler(name: string): ToolHandler | undefined;
232
- /**
233
- * Registers command handlers for this session.
234
- *
235
- * @param commands - An array of command definitions with handlers, or undefined to clear
236
- * @internal This method is typically called internally when creating/resuming a session.
237
- */
238
- registerCommands(commands?: {
239
- name: string;
240
- handler: CommandHandler;
241
- }[]): void;
242
- /**
243
- * Registers the elicitation handler for this session.
244
- *
245
- * @param handler - The handler to invoke when the server dispatches an elicitation request
246
- * @internal This method is typically called internally when creating/resuming a session.
247
- */
248
- registerElicitationHandler(handler?: ElicitationHandler): void;
249
- /**
250
- * Handles an elicitation.requested broadcast event.
251
- * Invokes the registered handler and responds via handlePendingElicitation RPC.
252
- * @internal
253
- */
254
- _handleElicitationRequest(context: ElicitationContext, requestId: string): Promise<void>;
255
- /**
256
- * Sets the host capabilities for this session.
257
- *
258
- * @param capabilities - The capabilities object from the create/resume response
259
- * @internal This method is typically called internally when creating/resuming a session.
260
- */
261
- setCapabilities(capabilities?: SessionCapabilities): void;
180
+ get openCanvases(): OpenCanvasInstance[];
262
181
  private assertElicitation;
263
182
  private _elicitation;
264
183
  private _confirm;
265
184
  private _select;
266
185
  private _input;
267
- /**
268
- * Registers a handler for permission requests.
269
- *
270
- * When the assistant needs permission to perform certain actions (e.g., file operations),
271
- * this handler is called to approve or deny the request.
272
- *
273
- * @param handler - The permission handler function, or undefined to remove the handler
274
- * @internal This method is typically called internally when creating a session.
275
- */
276
- registerPermissionHandler(handler?: PermissionHandler): void;
277
- /**
278
- * Registers a user input handler for ask_user requests.
279
- *
280
- * When the agent needs input from the user (via ask_user tool),
281
- * this handler is called to provide the response.
282
- *
283
- * @param handler - The user input handler function, or undefined to remove the handler
284
- * @internal This method is typically called internally when creating a session.
285
- */
286
- registerUserInputHandler(handler?: UserInputHandler): void;
287
- /**
288
- * Registers hook handlers for session lifecycle events.
289
- *
290
- * Hooks allow custom logic to be executed at various points during
291
- * the session lifecycle (before/after tool use, session start/end, etc.).
292
- *
293
- * @param hooks - The hook handlers object, or undefined to remove all hooks
294
- * @internal This method is typically called internally when creating a session.
295
- */
296
- registerHooks(hooks?: SessionHooks): void;
297
- /**
298
- * Registers transform callbacks for system message sections.
299
- *
300
- * @param callbacks - Map of section ID to transform callback, or undefined to clear
301
- * @internal This method is typically called internally when creating a session.
302
- */
303
- registerTransformCallbacks(callbacks?: Map<string, SectionTransformFn>): void;
304
- /**
305
- * Handles a systemMessage.transform request from the runtime.
306
- * Dispatches each section to its registered transform callback.
307
- *
308
- * @param sections - Map of section IDs to their current rendered content
309
- * @returns A promise that resolves with the transformed sections
310
- * @internal This method is for internal use by the SDK.
311
- */
312
- _handleSystemMessageTransform(sections: Record<string, {
313
- content: string;
314
- }>): Promise<{
315
- sections: Record<string, {
316
- content: string;
317
- }>;
318
- }>;
319
- /**
320
- * Handles a permission request in the v2 protocol format (synchronous RPC).
321
- * Used as a back-compat adapter when connected to a v2 server.
322
- *
323
- * @param request - The permission request data from the CLI
324
- * @returns A promise that resolves with the permission decision
325
- * @internal This method is for internal use by the SDK.
326
- */
327
- _handlePermissionRequestV2(request: unknown): Promise<PermissionRequestResult>;
328
- /**
329
- * Handles a user input request from the Copilot CLI.
330
- *
331
- * @param request - The user input request data from the CLI
332
- * @returns A promise that resolves with the user's response
333
- * @internal This method is for internal use by the SDK.
334
- */
335
- _handleUserInputRequest(request: unknown): Promise<UserInputResponse>;
336
- /**
337
- * Handles a hooks invocation from the Copilot CLI.
338
- *
339
- * @param hookType - The type of hook being invoked
340
- * @param input - The input data for the hook
341
- * @returns A promise that resolves with the hook output, or undefined
342
- * @internal This method is for internal use by the SDK.
343
- */
344
- _handleHooksInvoke(hookType: string, input: unknown): Promise<unknown>;
345
186
  /**
346
187
  * Retrieves all events and messages from this session's history.
347
188
  *
@@ -353,7 +194,7 @@ export declare class CopilotSession {
353
194
  *
354
195
  * @example
355
196
  * ```typescript
356
- * const events = await session.getMessages();
197
+ * const events = await session.getEvents();
357
198
  * for (const event of events) {
358
199
  * if (event.type === "assistant.message") {
359
200
  * console.log("Assistant:", event.data.content);
@@ -361,7 +202,7 @@ export declare class CopilotSession {
361
202
  * }
362
203
  * ```
363
204
  */
364
- getMessages(): Promise<SessionEvent[]>;
205
+ getEvents(): Promise<SessionEvent[]>;
365
206
  /**
366
207
  * Disconnects this session and releases all in-memory resources (event handlers,
367
208
  * tool handlers, permission handlers).
@@ -384,16 +225,6 @@ export declare class CopilotSession {
384
225
  * ```
385
226
  */
386
227
  disconnect(): Promise<void>;
387
- /**
388
- * @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
389
- *
390
- * Disconnects this session and releases all in-memory resources.
391
- * Session data on disk is preserved for later resumption.
392
- *
393
- * @returns A promise that resolves when the session is disconnected
394
- * @throws Error if the connection fails
395
- */
396
- destroy(): Promise<void>;
397
228
  /** Enables `await using session = ...` syntax for automatic cleanup. */
398
229
  [Symbol.asyncDispose](): Promise<void>;
399
230
  /**
@@ -432,6 +263,8 @@ export declare class CopilotSession {
432
263
  */
433
264
  setModel(model: string, options?: {
434
265
  reasoningEffort?: ReasoningEffort;
266
+ reasoningSummary?: ReasoningSummary;
267
+ contextTier?: ContextTier;
435
268
  modelCapabilities?: ModelCapabilitiesOverride;
436
269
  }): Promise<void>;
437
270
  /**