@github/copilot-sdk 1.0.29-preview.7 → 1.0.29-preview.9

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/session.d.ts CHANGED
@@ -16,7 +16,7 @@ export type AssistantMessageEvent = Extract<SessionEvent, {
16
16
  *
17
17
  * @example
18
18
  * ```typescript
19
- * const session = await client.createSession({ model: "gpt-4" });
19
+ * const session = await client.createSession({ model: "gpt-5.4" });
20
20
  *
21
21
  * // Subscribe to events
22
22
  * session.on((event) => {
package/dist/session.js CHANGED
@@ -1164,6 +1164,13 @@ class CopilotSession {
1164
1164
  } else if (typeof rawResult === "string") {
1165
1165
  result = rawResult;
1166
1166
  } else if (isToolResultObject(rawResult)) {
1167
+ try {
1168
+ JSON.stringify(rawResult.toolTelemetry);
1169
+ } catch (error) {
1170
+ const message = error instanceof Error ? error.message : String(error);
1171
+ throw new Error(`failed to serialize tool telemetry: ${message}`);
1172
+ }
1173
+ JSON.stringify(rawResult);
1167
1174
  result = rawResult;
1168
1175
  } else {
1169
1176
  result = JSON.stringify(rawResult);
package/dist/types.d.ts CHANGED
@@ -142,14 +142,10 @@ export interface StdioRuntimeConnection extends ChildProcessRuntimeConnection {
142
142
  * {@link RuntimeConnection.forInProcess}.
143
143
  *
144
144
  * @experimental The in-process (FFI) transport is experimental and its behavior may
145
- * change. Per-client options that are lowered to environment variables — including
146
- * {@link CopilotClientOptions.env}, {@link CopilotClientOptions.telemetry},
147
- * {@link CopilotClientOptions.gitHubToken}, and
148
- * {@link CopilotClientOptions.baseDirectory} — are **not** honored with this
149
- * transport, because the native runtime loads into the shared host process and its
150
- * worker inherits that process's ambient environment. To configure the in-process
151
- * runtime, set the corresponding environment variables on the host process before
152
- * constructing the client. See https://github.com/github/copilot-sdk/issues/1934.
145
+ * change. Typed authentication and {@link CopilotClientOptions.baseDirectory}
146
+ * are scoped to this host. Client-level `env`, `workingDirectory` and
147
+ * `telemetry` are unsupported; set working directories
148
+ * on individual sessions.
153
149
  */
154
150
  export interface InProcessRuntimeConnection {
155
151
  readonly kind: "inprocess";
@@ -228,11 +224,9 @@ export declare const RuntimeConnection: {
228
224
  /**
229
225
  * Host the runtime in-process over the native runtime library's C ABI (FFI).
230
226
  *
231
- * @experimental Per-client options lowered to environment variables (`env`,
232
- * `telemetry`, `gitHubToken`, `baseDirectory`) are **not** honored in-process;
233
- * the worker inherits the host process's ambient environment. Set the
234
- * corresponding environment variables on the host process instead. See
235
- * https://github.com/github/copilot-sdk/issues/1934.
227
+ * @experimental Runtime configuration from `gitHubToken` and
228
+ * `baseDirectory` is scoped to this host, not the process environment.
229
+ * Client-level `env`, `telemetry` and `workingDirectory` are unsupported.
236
230
  */
237
231
  readonly forInProcess: (options?: Pick<InProcessRuntimeConnection, "runOnUiThread">) => InProcessRuntimeConnection;
238
232
  };
@@ -327,6 +321,7 @@ export interface CopilotClientOptions {
327
321
  /**
328
322
  * Base directory for Copilot data (session state, config, etc.).
329
323
  * Sets the COPILOT_HOME environment variable on the spawned runtime.
324
+ * In-process hosts also keep their runtime cache in this directory's `cache` subdirectory.
330
325
  * When not set, the runtime defaults to ~/.copilot.
331
326
  * Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
332
327
  */
@@ -362,6 +357,7 @@ export interface CopilotClientOptions {
362
357
  logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
363
358
  /**
364
359
  * Environment variables to pass to the runtime process. If not set, inherits process.env.
360
+ * Unsupported with {@link RuntimeConnection.forInProcess}; use typed client/session options.
365
361
  */
366
362
  env?: Record<string, string | undefined>;
367
363
  /**
package/dist/types.js CHANGED
@@ -38,11 +38,9 @@ const RuntimeConnection = {
38
38
  /**
39
39
  * Host the runtime in-process over the native runtime library's C ABI (FFI).
40
40
  *
41
- * @experimental Per-client options lowered to environment variables (`env`,
42
- * `telemetry`, `gitHubToken`, `baseDirectory`) are **not** honored in-process;
43
- * the worker inherits the host process's ambient environment. Set the
44
- * corresponding environment variables on the host process instead. See
45
- * https://github.com/github/copilot-sdk/issues/1934.
41
+ * @experimental Runtime configuration from `gitHubToken` and
42
+ * `baseDirectory` is scoped to this host, not the process environment.
43
+ * Client-level `env`, `telemetry` and `workingDirectory` are unsupported.
46
44
  */
47
45
  forInProcess(options = {}) {
48
46
  return { kind: "inprocess", ...options };
@@ -95,7 +95,7 @@ tools: [
95
95
  // Return value: string or ToolResultObject
96
96
  // string → treated as success
97
97
  // { textResultForLlm, resultType } → structured result
98
- // resultType: "success" | "failure" | "rejected" | "denied"
98
+ // resultType: "success" | "failure" | "rejected" | "denied" | "timeout"
99
99
  return `Result: ${args.arg1}`;
100
100
  },
101
101
  },
@@ -105,7 +105,7 @@ tools: [
105
105
  **Constraints:**
106
106
 
107
107
  - Tool names must be unique across ALL loaded extensions. Collisions cause the second extension to fail to load.
108
- - Handler must return a string or `{ textResultForLlm: string, resultType?: string }`.
108
+ - Handler must return a string or `{ textResultForLlm: string, resultType: "success" | "failure" | "rejected" | "denied" | "timeout" }`. `resultType` is required: an object without a recognized `resultType` is not a structured result, and the model receives it serialized as JSON text.
109
109
  - Handler receives `(args, invocation)` — the second argument has `sessionId`, `toolCallId`, `toolName`.
110
110
  - Use `session.log()` to surface messages to the user. Don't use `console.log()` (stdout is reserved for JSON-RPC).
111
111
 
@@ -116,12 +116,15 @@ tools: [
116
116
  ```js
117
117
  hooks: {
118
118
  onUserPromptSubmitted: async (input, invocation) => { ... },
119
+ onUserPromptTransformed: async (input, invocation) => { ... },
119
120
  onPreToolUse: async (input, invocation) => { ... },
121
+ onPreMcpToolCall: async (input, invocation) => { ... },
120
122
  onPostToolUse: async (input, invocation) => { ... },
121
123
  onPostToolUseFailure: async (input, invocation) => { ... },
122
124
  onSessionStart: async (input, invocation) => { ... },
123
125
  onSessionEnd: async (input, invocation) => { ... },
124
126
  onErrorOccurred: async (input, invocation) => { ... },
127
+ onAgentStop: async (input, invocation) => { ... },
125
128
  onSubagentStart: async (input, invocation) => { ... },
126
129
  onSubagentStop: async (input, invocation) => { ... },
127
130
  }
@@ -143,6 +146,20 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
143
146
  | `decision` | `"block"` | Refuses the prompt: no model turn runs and no user message is recorded |
144
147
  | `reason` | `string` | Why the prompt was blocked, carried by the ephemeral `session.warning` (`warningType: "policy_blocked"`) |
145
148
 
149
+ ### onUserPromptTransformed
150
+
151
+ Fires after the runtime adds generated context to the submitted prompt, before
152
+ the result is stored in session history or sent to the model. `prompt` is the
153
+ prompt after `onUserPromptSubmitted`; `transformedPrompt` also carries the
154
+ runtime-generated context.
155
+
156
+ **Input:** `{ prompt: string, transformedPrompt: string, timestamp, workingDirectory }`
157
+
158
+ **Output (all fields optional):**
159
+ | Field | Type | Effect |
160
+ |-------|------|--------|
161
+ | `modifiedTransformedPrompt` | `string` | Replaces the content stored in session history and sent to the model |
162
+
146
163
  ### onPreToolUse
147
164
 
148
165
  **Input:** `{ toolName: string, toolArgs: unknown, timestamp, workingDirectory }`
@@ -155,6 +172,19 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
155
172
  | `modifiedArgs` | `unknown` | Replaces the tool arguments |
156
173
  | `additionalContext` | `string` | Injected into the conversation |
157
174
 
175
+ ### onPreMcpToolCall
176
+
177
+ Fires before a tool call is sent to an MCP server. It controls only the `_meta`
178
+ object sent with the request; to allow, deny or change the call itself, use
179
+ `onPreToolUse`.
180
+
181
+ **Input:** `{ toolCallId?: string, serverName: string, toolName: string, arguments: unknown, _meta?: Record<string, unknown>, timestamp, workingDirectory }`
182
+
183
+ **Output (all fields optional):**
184
+ | Field | Type | Effect |
185
+ |-------|------|--------|
186
+ | `metaToUse` | `Record<string, unknown> \| null` | An object becomes the request's `_meta`; `null` omits it; leaving it out keeps the current `_meta` |
187
+
158
188
  ### onPostToolUse
159
189
 
160
190
  **Input:** `{ toolName: string, toolArgs: unknown, toolResult: ToolResultObject, timestamp, workingDirectory }`
@@ -218,6 +248,23 @@ fire it.
218
248
  | `retryCount` | `number` | Max retries (when errorHandling is "retry") |
219
249
  | `userNotification` | `string` | Message shown to the user |
220
250
 
251
+ ### onAgentStop
252
+
253
+ Fires when the top-level agent reaches a natural terminal stop: it went idle
254
+ without pending work and was not aborted. Sub-agents fire `onSubagentStop`
255
+ instead.
256
+
257
+ **Input:** `{ stopReason?: string, transcriptPath?: string, stopHookActive?: boolean, timestamp, workingDirectory }`
258
+
259
+ `stopHookActive` is `true` when this stop follows an earlier `"block"` from this
260
+ hook; check it to avoid blocking indefinitely. The runtime also caps
261
+ consecutive blocks.
262
+
263
+ **Output (optional):**
264
+ | Field | Type | Effect |
265
+ |-------|------|--------|
266
+ | `decision` and `reason` | `"block"` and `string` | Keep the agent running; `reason` is enqueued as its next user message |
267
+
221
268
  ### onSubagentStart
222
269
 
223
270
  Fires before a sub-agent's first turn. The input's `sessionId` and the
package/docs/examples.md CHANGED
@@ -152,15 +152,20 @@ Hooks intercept and modify behavior at key lifecycle points. Register them in th
152
152
 
153
153
  ### Available Hooks
154
154
 
155
- | Hook | Fires When | Can Modify |
156
- | ----------------------- | ---------------------------------------- | ------------------------------------------- |
157
- | `onUserPromptSubmitted` | User sends a message | The prompt text, add context |
158
- | `onPreToolUse` | Before a tool executes | Tool args, permission decision, add context |
159
- | `onPostToolUse` | After a tool executes successfully | Tool result, add context |
160
- | `onPostToolUseFailure` | After a tool execution returns a failure | Add hidden guidance to the model |
161
- | `onSessionStart` | Session starts or resumes | Add context |
162
- | `onSessionEnd` | Session ends | Cleanup actions, summary |
163
- | `onErrorOccurred` | An error occurs | Error handling strategy (retry/skip/abort) |
155
+ | Hook | Fires When | Can Modify |
156
+ | ------------------------- | -------------------------------------------- | ------------------------------------------- |
157
+ | `onUserPromptSubmitted` | User sends a message | The prompt text, add context |
158
+ | `onUserPromptTransformed` | Runtime has transformed the submitted prompt | The transformed prompt |
159
+ | `onPreToolUse` | Before a tool executes | Tool args, permission decision, add context |
160
+ | `onPreMcpToolCall` | Before an MCP tool call is sent | The request's `_meta` |
161
+ | `onPostToolUse` | After a tool executes successfully | Tool result, add context |
162
+ | `onPostToolUseFailure` | After a tool execution returns a failure | Add hidden guidance to the model |
163
+ | `onSessionStart` | Session starts or resumes | Add context |
164
+ | `onSessionEnd` | Session ends | Cleanup actions, summary |
165
+ | `onErrorOccurred` | An error occurs | Error handling strategy (retry/skip/abort) |
166
+ | `onAgentStop` | Top-level agent naturally stops | Block the stop and request another turn |
167
+ | `onSubagentStart` | Before a sub-agent's first turn | Add context to its prompt |
168
+ | `onSubagentStop` | After a sub-agent completes a turn | Request another turn, replace its response |
164
169
 
165
170
  All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
166
171
 
package/docs/workflows.md CHANGED
@@ -225,7 +225,6 @@ Observation does not restore execution eligibility. Starting, resuming, pausing,
225
225
  ```ts
226
226
  const runs = await session.workflow.listRuns();
227
227
  const runsPage = await session.workflow.listRuns({
228
- afterSeq,
229
228
  beforeSeq,
230
229
  limit,
231
230
  });
@@ -233,15 +232,15 @@ const detail = await session.workflow.getRunDetail(runId);
233
232
  const progressPage = await session.workflow.getRunProgress(runId, {
234
233
  phaseId,
235
234
  afterSeq,
236
- beforeSeq,
237
235
  limit,
238
236
  });
239
237
  ```
240
238
 
241
239
  - `listRuns()` returns only the runs array from the newest default page of this session's durable workflow runs. This overload preserves the original convenience API.
242
- - `listRuns({ afterSeq, beforeSeq, limit })` returns the full page. Its `oldestSeq`, `newestSeq`, `hasMoreNewer`, and `omittedOlder` fields let callers continue paging without raw RPC calls.
240
+ - `listRuns({ afterSeq, limit })` or `listRuns({ beforeSeq, limit })` returns the full page. Its `oldestSeq`, `newestSeq`, `hasMoreNewer`, and `omittedOlder` fields let callers continue paging without raw RPC calls.
243
241
  - `getRunDetail(runId)` returns phases, prompt-safe agent summaries, and the latest progress page. Each current-runtime agent summary includes `consumedNanoAiu`, the known spend from that direct agent and its descendants. Older runtimes omit the field, and historical agents without attributable charge rows also omit it when the run contains unattributed spend.
244
242
  - `getRunProgress(runId, options?)` pages progress forward, backward, by phase, or from the latest tail.
243
+ - Both paging calls take at most one cursor: `afterSeq` pages forward and `beforeSeq` pages backward, each exclusive of the given sequence number. A request with both fails with JSON-RPC `-32602` and `data.code: "workflow_runs_invalid_cursor"` from `listRuns`, or `"workflow_progress_invalid_cursor"` from `getRunProgress`.
245
244
 
246
245
  `getRun(runId)` reads the latest run envelope. `pause(runId)` pauses a running attempt and returns its `paused` envelope. `cancel(runId)` cancels a run and returns its terminal envelope.
247
246
 
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "url": "https://github.com/github/copilot-agent-runtime.git",
6
6
  "directory": "src/sdk/nodejs"
7
7
  },
8
- "version": "1.0.29-preview.7",
9
- "copilotCliVersion": "1.0.106-8",
8
+ "version": "1.0.29-preview.9",
9
+ "copilotCliVersion": "1.0.106-10",
10
10
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
11
11
  "main": "./dist/cjs/index.js",
12
12
  "types": "./dist/index.d.ts",
@@ -68,7 +68,7 @@
68
68
  "author": "GitHub",
69
69
  "license": "MIT",
70
70
  "dependencies": {
71
- "koffi": "3.3.3",
71
+ "koffi": "3.3.4",
72
72
  "vscode-jsonrpc": "10.0.0",
73
73
  "zod": "4.6.7"
74
74
  },
@@ -117,18 +117,18 @@
117
117
  "README.md"
118
118
  ],
119
119
  "copilotRuntime": {
120
- "sourceSha": "fc20da543d03b6522fc0ac5fefc724be82045156",
121
- "version": "1.0.106-8",
120
+ "sourceSha": "b3da66080b3d00711a816a990fdaf6308ff17a1f",
121
+ "version": "1.0.106-10",
122
122
  "visibility": "public"
123
123
  },
124
124
  "optionalDependencies": {
125
- "@github/copilot-sdk-darwin-arm64": "1.0.29-preview.7",
126
- "@github/copilot-sdk-darwin-x64": "1.0.29-preview.7",
127
- "@github/copilot-sdk-linux-arm64": "1.0.29-preview.7",
128
- "@github/copilot-sdk-linux-x64": "1.0.29-preview.7",
129
- "@github/copilot-sdk-linuxmusl-arm64": "1.0.29-preview.7",
130
- "@github/copilot-sdk-linuxmusl-x64": "1.0.29-preview.7",
131
- "@github/copilot-sdk-win32-arm64": "1.0.29-preview.7",
132
- "@github/copilot-sdk-win32-x64": "1.0.29-preview.7"
125
+ "@github/copilot-sdk-darwin-arm64": "1.0.29-preview.9",
126
+ "@github/copilot-sdk-darwin-x64": "1.0.29-preview.9",
127
+ "@github/copilot-sdk-linux-arm64": "1.0.29-preview.9",
128
+ "@github/copilot-sdk-linux-x64": "1.0.29-preview.9",
129
+ "@github/copilot-sdk-linuxmusl-arm64": "1.0.29-preview.9",
130
+ "@github/copilot-sdk-linuxmusl-x64": "1.0.29-preview.9",
131
+ "@github/copilot-sdk-win32-arm64": "1.0.29-preview.9",
132
+ "@github/copilot-sdk-win32-x64": "1.0.29-preview.9"
133
133
  }
134
134
  }