@github/copilot-sdk 1.0.0-beta.3 → 1.0.0-beta.5

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
@@ -6,4 +6,5 @@
6
6
  export { CopilotClient } from "./client.js";
7
7
  export { CopilotSession, type AssistantMessageEvent } from "./session.js";
8
8
  export { defineTool, approveAll, convertMcpCallToolResult, createSessionFsAdapter, SYSTEM_PROMPT_SECTIONS, } from "./types.js";
9
- export type { CommandContext, CommandDefinition, CommandHandler, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, ConnectionState, CopilotClientOptions, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, 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";
9
+ export type * from "./generated/session-events.js";
10
+ export type { CommandContext, CommandDefinition, CommandHandler, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, ConnectionState, CopilotClientOptions, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, InputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventType, SessionLifecycleHandler, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemPromptSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
package/dist/session.d.ts CHANGED
@@ -216,8 +216,8 @@ export declare class CopilotSession {
216
216
  /**
217
217
  * Registers custom tool handlers for this session.
218
218
  *
219
- * Tools allow the assistant to execute custom functions. When the assistant
220
- * invokes a tool, the corresponding handler is called with the tool arguments.
219
+ * Tools with handlers allow the assistant to execute custom functions automatically.
220
+ * Declaration-only tools are surfaced as events and left pending for the consumer.
221
221
  *
222
222
  * @param tools - An array of tool definitions with their handlers, or undefined to clear all tools
223
223
  * @internal This method is typically called internally when creating a session with tools.
package/dist/session.js CHANGED
@@ -373,8 +373,8 @@ class CopilotSession {
373
373
  /**
374
374
  * Registers custom tool handlers for this session.
375
375
  *
376
- * Tools allow the assistant to execute custom functions. When the assistant
377
- * invokes a tool, the corresponding handler is called with the tool arguments.
376
+ * Tools with handlers allow the assistant to execute custom functions automatically.
377
+ * Declaration-only tools are surfaced as events and left pending for the consumer.
378
378
  *
379
379
  * @param tools - An array of tool definitions with their handlers, or undefined to clear all tools
380
380
  * @internal This method is typically called internally when creating a session with tools.
@@ -385,7 +385,9 @@ class CopilotSession {
385
385
  return;
386
386
  }
387
387
  for (const tool of tools) {
388
- this.toolHandlers.set(tool.name, tool.handler);
388
+ if (tool.handler) {
389
+ this.toolHandlers.set(tool.name, tool.handler);
390
+ }
389
391
  }
390
392
  }
391
393
  /**
@@ -1,10 +1,35 @@
1
- import type { SessionFsHandler, SessionFsStatResult, SessionFsReaddirWithTypesEntry } from "./generated/rpc.js";
1
+ import type { SessionFsHandler, SessionFsStatResult, SessionFsReaddirWithTypesEntry, SessionFsSqliteQueryResult as GeneratedSqliteQueryResult, SessionFsSqliteQueryType } from "./generated/rpc.js";
2
+ export type { SessionFsSqliteQueryType };
2
3
  /**
3
4
  * File metadata returned by {@link SessionFsProvider.stat}.
4
5
  * Same shape as the generated {@link SessionFsStatResult} but without the
5
6
  * `error` field, since providers signal errors by throwing.
6
7
  */
7
8
  export type SessionFsFileInfo = Omit<SessionFsStatResult, "error">;
9
+ /**
10
+ * Result of a SQLite query execution via {@link SessionFsSqliteProvider.query}.
11
+ * Same shape as the generated {@link GeneratedSqliteQueryResult} but without the
12
+ * `error` field, since providers signal errors by throwing.
13
+ */
14
+ export type SessionFsSqliteQueryResult = Omit<GeneratedSqliteQueryResult, "error">;
15
+ /**
16
+ * SQLite operations for the per-session database.
17
+ * Implementers provide query execution and existence checking.
18
+ */
19
+ export interface SessionFsSqliteProvider {
20
+ /**
21
+ * Execute a SQLite query against the per-session database.
22
+ *
23
+ * @param queryType - How to execute: `"exec"` for DDL/multi-statement, `"query"` for SELECT, `"run"` for INSERT/UPDATE/DELETE.
24
+ * @param query - SQL query to execute.
25
+ * @param params - Optional named bind parameters.
26
+ */
27
+ query(queryType: SessionFsSqliteQueryType, query: string, params?: Record<string, string | number | null>): Promise<SessionFsSqliteQueryResult | undefined>;
28
+ /**
29
+ * Check whether the per-session database already exists, without creating it.
30
+ */
31
+ exists(): Promise<boolean>;
32
+ }
8
33
  /**
9
34
  * Interface for session filesystem providers. Implementers use idiomatic
10
35
  * TypeScript patterns: throw on error, return values directly. Use
@@ -35,6 +60,8 @@ export interface SessionFsProvider {
35
60
  rm(path: string, recursive: boolean, force: boolean): Promise<void>;
36
61
  /** Renames/moves a file or directory. */
37
62
  rename(src: string, dest: string): Promise<void>;
63
+ /** Per-session SQLite database operations. Optional — omit if the provider does not support SQLite. */
64
+ sqlite?: SessionFsSqliteProvider;
38
65
  }
39
66
  /**
40
67
  * Wraps a {@link SessionFsProvider} into the {@link SessionFsHandler}
@@ -1,3 +1,15 @@
1
+ function normalizeSqliteParams(params) {
2
+ if (!params) {
3
+ return void 0;
4
+ }
5
+ const normalized = {};
6
+ for (const [key, value] of Object.entries(params)) {
7
+ if (value !== void 0) {
8
+ normalized[key] = value;
9
+ }
10
+ }
11
+ return normalized;
12
+ }
1
13
  function createSessionFsAdapter(provider) {
2
14
  return {
3
15
  readFile: async ({ path }) => {
@@ -84,6 +96,28 @@ function createSessionFsAdapter(provider) {
84
96
  } catch (err) {
85
97
  return toSessionFsError(err);
86
98
  }
99
+ },
100
+ // Unlike the FS methods above, SQLite methods let errors propagate to the JSON-RPC layer
101
+ // rather than catching and mapping via toSessionFsError. The FS error mapping is specifically
102
+ // for translating Node.js errno codes (e.g., ENOENT) into SessionFsError, which isn't
103
+ // meaningful for SQL errors. Letting exceptions propagate preserves the original error
104
+ // message in the JSON-RPC error response.
105
+ sqliteQuery: async ({ queryType, query, params: bindParams }) => {
106
+ if (!provider.sqlite) {
107
+ throw new Error("SQLite is not supported by this provider");
108
+ }
109
+ const result = await provider.sqlite.query(
110
+ queryType,
111
+ query,
112
+ normalizeSqliteParams(bindParams)
113
+ );
114
+ return result ?? { rows: [], columns: [], rowsAffected: 0 };
115
+ },
116
+ sqliteExists: async () => {
117
+ if (!provider.sqlite) {
118
+ throw new Error("SQLite is not supported by this provider");
119
+ }
120
+ return { exists: await provider.sqlite.exists() };
87
121
  }
88
122
  };
89
123
  }
package/dist/types.d.ts CHANGED
@@ -4,10 +4,15 @@
4
4
  import type { SessionFsProvider } from "./sessionFsProvider.js";
5
5
  import type { SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
6
6
  import type { CopilotSession } from "./session.js";
7
+ import type { RemoteSessionMode } from "./generated/rpc.js";
8
+ export type { RemoteSessionMode } from "./generated/rpc.js";
7
9
  export type SessionEvent = GeneratedSessionEvent;
8
10
  export type { SessionFsProvider } from "./sessionFsProvider.js";
9
11
  export { createSessionFsAdapter } from "./sessionFsProvider.js";
10
12
  export type { SessionFsFileInfo } from "./sessionFsProvider.js";
13
+ export type { SessionFsSqliteQueryResult } from "./sessionFsProvider.js";
14
+ export type { SessionFsSqliteQueryType } from "./sessionFsProvider.js";
15
+ export type { SessionFsSqliteProvider } from "./sessionFsProvider.js";
11
16
  /**
12
17
  * Options for creating a CopilotClient
13
18
  */
@@ -199,7 +204,7 @@ export type ToolResultType = "success" | "failure" | "rejected" | "denied" | "ti
199
204
  export type ToolBinaryResult = {
200
205
  data: string;
201
206
  mimeType: string;
202
- type: string;
207
+ type: "image" | "resource";
203
208
  description?: string;
204
209
  };
205
210
  export type ToolResultObject = {
@@ -211,6 +216,20 @@ export type ToolResultObject = {
211
216
  toolTelemetry?: Record<string, unknown>;
212
217
  };
213
218
  export type ToolResult = string | ToolResultObject;
219
+ /**
220
+ * GitHub repository metadata to associate with a cloud session.
221
+ */
222
+ export interface CloudSessionRepository {
223
+ owner: string;
224
+ name: string;
225
+ branch?: string;
226
+ }
227
+ /**
228
+ * Options for creating a remote session in the cloud.
229
+ */
230
+ export interface CloudSessionOptions {
231
+ repository?: CloudSessionRepository;
232
+ }
214
233
  /**
215
234
  * Content block types within an MCP CallToolResult.
216
235
  */
@@ -269,12 +288,16 @@ export interface ZodSchema<T = unknown> {
269
288
  * - A Zod schema (provides type inference for handler)
270
289
  * - A raw JSON schema object
271
290
  * - Omitted (no parameters)
291
+ *
292
+ * If `handler` is omitted, the SDK exposes the declaration but does not
293
+ * automatically invoke the tool. Consumers can resolve tool calls by observing
294
+ * external tool request events and calling the pending-tool RPC.
272
295
  */
273
296
  export interface Tool<TArgs = unknown> {
274
297
  name: string;
275
298
  description?: string;
276
299
  parameters?: ZodSchema<TArgs> | Record<string, unknown>;
277
- handler: ToolHandler<TArgs>;
300
+ handler?: ToolHandler<TArgs>;
278
301
  /**
279
302
  * When true, explicitly indicates this tool is intended to override a built-in tool
280
303
  * of the same name. If not set and the name clashes with a built-in tool, the runtime
@@ -293,7 +316,7 @@ export interface Tool<TArgs = unknown> {
293
316
  export declare function defineTool<T = unknown>(name: string, config: {
294
317
  description?: string;
295
318
  parameters?: ZodSchema<T> | Record<string, unknown>;
296
- handler: ToolHandler<T>;
319
+ handler?: ToolHandler<T>;
297
320
  overridesBuiltInTool?: boolean;
298
321
  skipPermission?: boolean;
299
322
  }): Tool<T>;
@@ -703,6 +726,9 @@ export type AutoModeSwitchHandler = (request: AutoModeSwitchRequest, invocation:
703
726
  * Base interface for all hook inputs
704
727
  */
705
728
  export interface BaseHookInput {
729
+ /** The runtime session ID of the session that triggered the hook.
730
+ * For sub-agent hooks this differs from `invocation.sessionId`. */
731
+ sessionId: string;
706
732
  timestamp: number;
707
733
  cwd: string;
708
734
  }
@@ -889,7 +915,7 @@ interface MCPServerConfigBase {
889
915
  export interface MCPStdioServerConfig extends MCPServerConfigBase {
890
916
  type?: "local" | "stdio";
891
917
  command: string;
892
- args: string[];
918
+ args?: string[];
893
919
  /**
894
920
  * Environment variables to pass to the server.
895
921
  */
@@ -956,6 +982,12 @@ export interface CustomAgentConfig {
956
982
  * When omitted, no skills are injected (opt-in model).
957
983
  */
958
984
  skills?: string[];
985
+ /**
986
+ * Model identifier for this agent (e.g. "claude-haiku-4.5").
987
+ * When set, the runtime will attempt to use this model for the agent,
988
+ * falling back to the parent session model if unavailable.
989
+ */
990
+ model?: string;
959
991
  }
960
992
  /**
961
993
  * Configuration for the default agent (the built-in agent that handles
@@ -1040,7 +1072,8 @@ export interface SessionConfig {
1040
1072
  */
1041
1073
  enableConfigDiscovery?: boolean;
1042
1074
  /**
1043
- * Tools exposed to the CLI server
1075
+ * Tools exposed to the CLI server. Tools without a handler are declaration-only
1076
+ * and must be resolved by the consumer via pending external tool request RPCs.
1044
1077
  */
1045
1078
  tools?: Tool<any>[];
1046
1079
  /**
@@ -1079,10 +1112,11 @@ export interface SessionConfig {
1079
1112
  */
1080
1113
  enableSessionTelemetry?: boolean;
1081
1114
  /**
1082
- * Handler for permission requests from the server.
1083
- * When provided, the server will call this handler to request permission for operations.
1115
+ * Optional handler for permission requests from the server.
1116
+ * When omitted, permission requests are surfaced as events and left pending for
1117
+ * the consumer to resolve via the pending permission RPC.
1084
1118
  */
1085
- onPermissionRequest: PermissionHandler;
1119
+ onPermissionRequest?: PermissionHandler;
1086
1120
  /**
1087
1121
  * Handler for user input requests from the agent.
1088
1122
  * When provided, enables the ask_user tool allowing the agent to ask questions.
@@ -1176,6 +1210,18 @@ export interface SessionConfig {
1176
1210
  * the identity used for content exclusion, model routing, and quota checks.
1177
1211
  */
1178
1212
  gitHubToken?: string;
1213
+ /**
1214
+ * Per-session remote behavior control:
1215
+ * - `"off"` — local only, no remote export (default)
1216
+ * - `"export"` — export session events to GitHub without enabling remote steering
1217
+ * - `"on"` — export to GitHub AND enable remote steering
1218
+ */
1219
+ remoteSession?: RemoteSessionMode;
1220
+ /**
1221
+ * Creates a remote session in the cloud instead of a local session.
1222
+ * The optional repository is associated with the cloud session.
1223
+ */
1224
+ cloud?: CloudSessionOptions;
1179
1225
  /**
1180
1226
  * Optional event handler that is registered on the session before the
1181
1227
  * session.create RPC is issued. This guarantees that early events emitted
@@ -1195,7 +1241,7 @@ export interface SessionConfig {
1195
1241
  /**
1196
1242
  * Configuration for resuming a session
1197
1243
  */
1198
- export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "commands" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "enableSessionTelemetry" | "modelCapabilities" | "streaming" | "includeSubAgentStreamingEvents" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "onElicitationRequest" | "onExitPlanMode" | "onAutoModeSwitch" | "hooks" | "workingDirectory" | "configDir" | "enableConfigDiscovery" | "mcpServers" | "customAgents" | "defaultAgent" | "agent" | "skillDirectories" | "instructionDirectories" | "disabledSkills" | "infiniteSessions" | "gitHubToken" | "onEvent" | "createSessionFsHandler"> & {
1244
+ export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "commands" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "enableSessionTelemetry" | "modelCapabilities" | "streaming" | "includeSubAgentStreamingEvents" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "onElicitationRequest" | "onExitPlanMode" | "onAutoModeSwitch" | "hooks" | "workingDirectory" | "configDir" | "enableConfigDiscovery" | "mcpServers" | "customAgents" | "defaultAgent" | "agent" | "skillDirectories" | "instructionDirectories" | "disabledSkills" | "infiniteSessions" | "gitHubToken" | "remoteSession" | "onEvent" | "createSessionFsHandler"> & {
1199
1245
  /**
1200
1246
  * When true, skips emitting the session.resume event.
1201
1247
  * Useful for reconnecting to a session without triggering resume-related side effects.
@@ -1384,6 +1430,19 @@ export interface SessionFsConfig {
1384
1430
  * Path conventions used by this filesystem provider.
1385
1431
  */
1386
1432
  conventions: "windows" | "posix";
1433
+ /**
1434
+ * Optional capabilities declared by this provider.
1435
+ * The runtime uses these to determine which features are available.
1436
+ */
1437
+ capabilities?: {
1438
+ /**
1439
+ * Whether this provider supports SQLite query/exists operations.
1440
+ * When false or omitted, the runtime will not offer SQL tools or
1441
+ * todo tracking for sessions using this provider.
1442
+ * @default false
1443
+ */
1444
+ sqlite?: boolean;
1445
+ };
1387
1446
  }
1388
1447
  /**
1389
1448
  * Filter options for listing sessions
@@ -1470,7 +1529,7 @@ export interface ModelPolicy {
1470
1529
  * Model billing information
1471
1530
  */
1472
1531
  export interface ModelBilling {
1473
- multiplier: number;
1532
+ multiplier?: number;
1474
1533
  }
1475
1534
  /**
1476
1535
  * Information about an available model
package/docs/examples.md CHANGED
@@ -561,12 +561,12 @@ const session = await joinSession({
561
561
  onPermissionRequest: async (request) => {
562
562
  if (request.kind === "shell") {
563
563
  // request.fullCommandText has the shell command
564
- return { kind: "approved" };
564
+ return { kind: "approve-once" };
565
565
  }
566
566
  if (request.kind === "write") {
567
- return { kind: "approved" };
567
+ return { kind: "approve-once" };
568
568
  }
569
- return { kind: "denied-by-rules" };
569
+ return { kind: "reject" };
570
570
  },
571
571
  });
572
572
  ```
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/github/copilot-sdk.git"
6
6
  },
7
- "version": "1.0.0-beta.3",
7
+ "version": "1.0.0-beta.5",
8
8
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
9
9
  "main": "./dist/cjs/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
41
41
  "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
42
42
  "lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
43
- "typecheck": "tsc --noEmit",
43
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
44
44
  "generate": "cd ../scripts/codegen && npm run generate",
45
45
  "update:protocol-version": "tsx scripts/update-protocol-version.ts",
46
46
  "prepublishOnly": "npm run build",
@@ -56,7 +56,7 @@
56
56
  "author": "GitHub",
57
57
  "license": "MIT",
58
58
  "dependencies": {
59
- "@github/copilot": "^1.0.44-2",
59
+ "@github/copilot": "^1.0.51",
60
60
  "vscode-jsonrpc": "^8.2.1",
61
61
  "zod": "^4.3.6"
62
62
  },