@github/copilot-sdk-win32-x64 1.0.17-preview.2 → 1.0.17-preview.4
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/copilot-sdk/canvas.d.ts +6 -1
- package/copilot-sdk/docs/agent-author.md +29 -2
- package/copilot-sdk/extension.js +293 -19
- package/copilot-sdk/generated/rpc.d.ts +1128 -411
- package/copilot-sdk/generated/session-events.d.ts +255 -4
- package/copilot-sdk/index.d.ts +2 -2
- package/copilot-sdk/index.js +296 -21
- package/copilot-sdk/session.d.ts +45 -1
- package/copilot-sdk/sessionFsProvider.d.ts +9 -1
- package/copilot-sdk/types.d.ts +83 -2
- package/package.json +1 -1
- package/prebuilds/win32-x64/copilot-runtime.exe +0 -0
- package/prebuilds/win32-x64/dpapi.node +0 -0
- package/prebuilds/win32-x64/msal-node-runtime.node +0 -0
- package/prebuilds/win32-x64/msalruntime.dll +0 -0
- package/prebuilds/win32-x64/runtime.node +2 -2
- package/ripgrep/bin/win32-x64/rg.exe +0 -0
- package/schemas/api.schema.json +1359 -125
- package/schemas/session-events.schema.json +434 -7
- package/tgrep/bin/win32-x64/tgrep.exe +0 -0
- package/prebuilds/win32-x64/OneAuthInterop.LICENSE.txt +0 -192
- package/prebuilds/win32-x64/OneAuthInterop.dll +0 -0
- package/prebuilds/win32-x64/OneAuthInterop.dll.stamp.json +0 -4
package/copilot-sdk/canvas.d.ts
CHANGED
|
@@ -32,7 +32,12 @@ export interface CanvasAction {
|
|
|
32
32
|
description?: string;
|
|
33
33
|
/** Optional JSON Schema for the action's `input` payload. */
|
|
34
34
|
inputSchema?: CanvasJsonSchema;
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Required per-action dispatch handler. The returned value becomes the
|
|
37
|
+
* `invoke_canvas_action` tool result. Return a `ToolResultObject`
|
|
38
|
+
* (with `binaryResultsForLlm`) to send text and images to the model, as a
|
|
39
|
+
* tool handler would; any other value is rendered to the model as JSON text.
|
|
40
|
+
*/
|
|
36
41
|
handler: (ctx: CanvasProviderInvokeActionRequest) => Promise<unknown> | unknown;
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
@@ -122,10 +122,12 @@ hooks: {
|
|
|
122
122
|
onSessionStart: async (input, invocation) => { ... },
|
|
123
123
|
onSessionEnd: async (input, invocation) => { ... },
|
|
124
124
|
onErrorOccurred: async (input, invocation) => { ... },
|
|
125
|
+
onSubagentStart: async (input, invocation) => { ... },
|
|
126
|
+
onSubagentStop: async (input, invocation) => { ... },
|
|
125
127
|
}
|
|
126
128
|
```
|
|
127
129
|
|
|
128
|
-
All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
|
|
130
|
+
All hook inputs include `sessionId`, `timestamp` (`Date`) and `workingDirectory`.
|
|
129
131
|
All handlers receive `invocation: { sessionId: string }` as the second argument.
|
|
130
132
|
All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
131
133
|
|
|
@@ -214,7 +216,32 @@ fire it.
|
|
|
214
216
|
| `retryCount` | `number` | Max retries (when errorHandling is "retry") |
|
|
215
217
|
| `userNotification` | `string` | Message shown to the user |
|
|
216
218
|
|
|
217
|
-
|
|
219
|
+
### onSubagentStart
|
|
220
|
+
|
|
221
|
+
Fires before a sub-agent's first turn. The input's `sessionId` and the
|
|
222
|
+
invocation's `sessionId` identify the parent session, not the child.
|
|
223
|
+
|
|
224
|
+
**Input:** `{ sessionId: string, transcriptPath: string, agentName: string, agentDisplayName?: string, agentDescription?: string, timestamp, workingDirectory }`
|
|
225
|
+
|
|
226
|
+
**Output (optional):**
|
|
227
|
+
| Field | Type | Effect |
|
|
228
|
+
|-------|------|--------|
|
|
229
|
+
| `additionalContext` | `string` | Prepended to the child's initial prompt |
|
|
230
|
+
|
|
231
|
+
### onSubagentStop
|
|
232
|
+
|
|
233
|
+
Fires after a sub-agent completes a turn. The input includes the child's last
|
|
234
|
+
assistant `response` and the parent's session metadata. `agentId` is available
|
|
235
|
+
when the task registry supplies one. This is distinct from `onAgentStop`, which
|
|
236
|
+
only runs for the top-level agent.
|
|
237
|
+
|
|
238
|
+
**Input:** `{ sessionId: string, transcriptPath: string, agentName: string, agentDisplayName?: string, agentDescription?: string, agentId?: string, agentType: string, stopReason: "end_turn", response: string, timestamp, workingDirectory }`
|
|
239
|
+
|
|
240
|
+
**Output (choose one, or return nothing):**
|
|
241
|
+
| Field | Type | Effect |
|
|
242
|
+
|-------|------|--------|
|
|
243
|
+
| `decision` and `reason` | `"block"` and `string` | Continue the child for another turn using `reason` |
|
|
244
|
+
| `modifiedResponse` | `string` | Replace the child's response reported to the parent |
|
|
218
245
|
|
|
219
246
|
## Session Object
|
|
220
247
|
|
package/copilot-sdk/extension.js
CHANGED
|
@@ -4151,7 +4151,48 @@ function createServerRpc(connection) {
|
|
|
4151
4151
|
*
|
|
4152
4152
|
* @returns Whether the host running this runtime can run the command sandbox. The runtime checks `supported` once per process. A capability answer can change while the process runs, for example after the user installs a missing package.
|
|
4153
4153
|
*/
|
|
4154
|
-
getHostSupport: async () => connection.sendRequest("sandbox.getHostSupport", {})
|
|
4154
|
+
getHostSupport: async () => connection.sendRequest("sandbox.getHostSupport", {}),
|
|
4155
|
+
/** @experimental */
|
|
4156
|
+
proxyCa: {
|
|
4157
|
+
/**
|
|
4158
|
+
* Reports whether the persistent certificate authority of the sandbox credential proxy exists, whether OS trust includes it, and whether it must be rotated. Changes nothing.
|
|
4159
|
+
*
|
|
4160
|
+
* @param params Identifies the credential hosts that the persistent certificate authority of the sandbox credential proxy must cover. The runtime always adds the hosts from the saved user settings.
|
|
4161
|
+
*
|
|
4162
|
+
* @returns Status of the persistent certificate authority of the sandbox credential proxy.
|
|
4163
|
+
*/
|
|
4164
|
+
getStatus: async (params) => connection.sendRequest("sandbox.proxyCa.getStatus", params),
|
|
4165
|
+
/**
|
|
4166
|
+
* Creates the persistent certificate authority of the sandbox credential proxy if none is stored, without changing OS trust, and returns the path of its public certificate. Keeps an existing certificate authority, even one that must be rotated. Fails where OS trust is unsupported. Trust it with sandbox.proxyCa.trust: the CLI trusts only the hosts in the saved user settings, so it refuses a certificate authority that also covers hosts from sandboxConfig.
|
|
4167
|
+
*
|
|
4168
|
+
* @param params Identifies the credential hosts that the persistent certificate authority of the sandbox credential proxy must cover. The runtime always adds the hosts from the saved user settings.
|
|
4169
|
+
*
|
|
4170
|
+
* @returns Result of creating the persistent certificate authority of the sandbox credential proxy.
|
|
4171
|
+
*/
|
|
4172
|
+
create: async (params) => connection.sendRequest("sandbox.proxyCa.create", params),
|
|
4173
|
+
/**
|
|
4174
|
+
* Replaces the persistent certificate authority of the sandbox credential proxy with a new one for the current credential hosts. If OS trust included the old one, removes it and trusts the new one, which can show an OS authentication prompt. Running sandboxed tools keep the old certificate authority until they restart.
|
|
4175
|
+
*
|
|
4176
|
+
* @param params Identifies the credential hosts that the persistent certificate authority of the sandbox credential proxy must cover. The runtime always adds the hosts from the saved user settings.
|
|
4177
|
+
*
|
|
4178
|
+
* @returns Status of the persistent certificate authority of the sandbox credential proxy.
|
|
4179
|
+
*/
|
|
4180
|
+
rotate: async (params) => connection.sendRequest("sandbox.proxyCa.rotate", params),
|
|
4181
|
+
/**
|
|
4182
|
+
* Adds the persistent certificate authority of the sandbox credential proxy to OS trust, so sandboxed clients that read only OS trust accept the proxy. Call create first. Refuses a certificate authority that is not constrained to the current credential hosts. Can show an OS authentication prompt.
|
|
4183
|
+
*
|
|
4184
|
+
* @param params Identifies the credential hosts that the persistent certificate authority of the sandbox credential proxy must cover. The runtime always adds the hosts from the saved user settings.
|
|
4185
|
+
*
|
|
4186
|
+
* @returns Status of the persistent certificate authority of the sandbox credential proxy.
|
|
4187
|
+
*/
|
|
4188
|
+
trust: async (params) => connection.sendRequest("sandbox.proxyCa.trust", params),
|
|
4189
|
+
/**
|
|
4190
|
+
* Removes the persistent certificate authority of the sandbox credential proxy from OS trust. Keeps the stored certificate authority. Can show an OS authentication prompt. Sandboxed clients that read only OS trust then reject the proxy; clients that read the per-process certificate bundle continue to work.
|
|
4191
|
+
*
|
|
4192
|
+
* @returns Status of the persistent certificate authority of the sandbox credential proxy.
|
|
4193
|
+
*/
|
|
4194
|
+
remove: async () => connection.sendRequest("sandbox.proxyCa.remove", {})
|
|
4195
|
+
}
|
|
4155
4196
|
},
|
|
4156
4197
|
/** @experimental */
|
|
4157
4198
|
tools: {
|
|
@@ -5071,22 +5112,55 @@ function createInternalServerRpc(connection) {
|
|
|
5071
5112
|
* @param params Params to attach or detach an in-process ExtensionController delegate.
|
|
5072
5113
|
*/
|
|
5073
5114
|
configureSessionExtensions: async (params) => connection.sendRequest("sessions.configureSessionExtensions", params)
|
|
5074
|
-
},
|
|
5075
|
-
/** @experimental */
|
|
5076
|
-
accounts: {
|
|
5077
|
-
/**
|
|
5078
|
-
* Acquire a Microsoft Entra access token through the runtime's OneAuth broker. Account-scoped because it uses the same native broker as the account stack: a trusted host application mints a scoped Entra token for its own use, most notably to authenticate to a remote MCP server whose authorization server is Entra ID (in place of the generic browser-OAuth flow).
|
|
5079
|
-
*
|
|
5080
|
-
* @param params OneAuth token request supplied by a trusted host application.
|
|
5081
|
-
*
|
|
5082
|
-
* @returns Result of a OneAuth token acquisition.
|
|
5083
|
-
*/
|
|
5084
|
-
acquireEntraToken: async (params) => connection.sendRequest("accounts.acquireEntraToken", params)
|
|
5085
5115
|
}
|
|
5086
5116
|
};
|
|
5087
5117
|
}
|
|
5088
5118
|
function createSessionRpc(connection, sessionId) {
|
|
5089
5119
|
return {
|
|
5120
|
+
/** @experimental */
|
|
5121
|
+
providers: {
|
|
5122
|
+
/**
|
|
5123
|
+
* Returns adapter definitions and supported operations in this session's effective provider catalog, without running discovery. Does not list provider instances or select inference models.
|
|
5124
|
+
*
|
|
5125
|
+
* @returns Normalized model-provider adapter definitions available to the session, not discovered instances.
|
|
5126
|
+
*/
|
|
5127
|
+
getCatalog: async () => connection.sendRequest("session.providers.getCatalog", { sessionId }),
|
|
5128
|
+
/**
|
|
5129
|
+
* Discovers reachable instances using an adapter from this session's effective provider catalog and provider-specific discovery input.
|
|
5130
|
+
*
|
|
5131
|
+
* @param params Provider discovery parameters.
|
|
5132
|
+
*
|
|
5133
|
+
* @returns Provider instances found by a discovery operation.
|
|
5134
|
+
*/
|
|
5135
|
+
discover: async (params) => connection.sendRequest("session.providers.discover", { ...params, sessionId }),
|
|
5136
|
+
/**
|
|
5137
|
+
* Gets current health and version information for a discovered model-provider instance.
|
|
5138
|
+
*
|
|
5139
|
+
* @param params Provider status request parameters.
|
|
5140
|
+
*
|
|
5141
|
+
* @returns Current health information for a provider instance.
|
|
5142
|
+
*/
|
|
5143
|
+
getStatus: async (params) => connection.sendRequest("session.providers.getStatus", { ...params, sessionId }),
|
|
5144
|
+
/** @experimental */
|
|
5145
|
+
models: {
|
|
5146
|
+
/**
|
|
5147
|
+
* Lists models installed or otherwise available from a discovered model-provider instance.
|
|
5148
|
+
*
|
|
5149
|
+
* @param params Provider model inventory request parameters.
|
|
5150
|
+
*
|
|
5151
|
+
* @returns Models offered for agent conversations by one provider instance. Adapters exclude known-incompatible models, but retain candidates with unknown capabilities. Listing does not guarantee compatibility.
|
|
5152
|
+
*/
|
|
5153
|
+
list: async (params) => connection.sendRequest("session.providers.models.list", { ...params, sessionId }),
|
|
5154
|
+
/**
|
|
5155
|
+
* Translates a discovered model into the provider and model configuration needed to use it, and reports whether each is already registered in this session. Prepares only: it registers nothing, writes nothing, and performs no provider requests.
|
|
5156
|
+
*
|
|
5157
|
+
* @param params A discovered instance and one of its models to translate into provider configuration. Pass back the instance and model as returned by `session.providers.discover` and `session.providers.models.list`.
|
|
5158
|
+
*
|
|
5159
|
+
* @returns Provider configuration prepared from a discovered model. Preparing a plan changes nothing: it neither registers the model with the session nor writes durable configuration. To apply it, pass `provider` and `model` to `session.provider.add`, omitting whichever the dispositions report as already configured.
|
|
5160
|
+
*/
|
|
5161
|
+
prepareConfiguration: async (params) => connection.sendRequest("session.providers.models.prepareConfiguration", { ...params, sessionId })
|
|
5162
|
+
}
|
|
5163
|
+
},
|
|
5090
5164
|
/**
|
|
5091
5165
|
* Suspends the session while preserving persisted state for later resume.
|
|
5092
5166
|
*
|
|
@@ -5694,16 +5768,18 @@ function createSessionRpc(connection, sessionId) {
|
|
|
5694
5768
|
*/
|
|
5695
5769
|
getSources: async () => connection.sendRequest("session.instructions.getSources", { sessionId }),
|
|
5696
5770
|
/**
|
|
5697
|
-
*
|
|
5771
|
+
* For local sessions, invalidates instruction discovery and the model-facing prompt, then returns freshly discovered sources. The updated prompt takes effect on the next turn. Remote sessions must reload on their agent host instead.
|
|
5772
|
+
*
|
|
5773
|
+
* @returns Instruction sources loaded for the session, in merge order.
|
|
5698
5774
|
*/
|
|
5699
5775
|
reload: async () => connection.sendRequest("session.instructions.reload", { sessionId })
|
|
5700
5776
|
},
|
|
5701
5777
|
/** @experimental */
|
|
5702
5778
|
customizations: {
|
|
5703
5779
|
/**
|
|
5704
|
-
*
|
|
5780
|
+
* For local sessions, reconciles repository context and discovered instructions, plugins, skills, agents, hooks, MCP servers, and extensions after files appear or change under the working directory. Independent component failures are returned in outcomes and errors; a rejected call can have partially applied earlier steps. Remote sessions must reload on their agent host instead. The model-facing context is rebuilt on the next turn.
|
|
5705
5781
|
*
|
|
5706
|
-
* @returns
|
|
5782
|
+
* @returns Results of reloading discovered session customizations. Inspect outcomes for reloaded, skipped, or failed subsystems; a rejection may follow partial mutation. Changes to the model-facing prompt and tools apply on the next turn.
|
|
5707
5783
|
*/
|
|
5708
5784
|
reload: async () => connection.sendRequest("session.customizations.reload", { sessionId })
|
|
5709
5785
|
},
|
|
@@ -7407,6 +7483,33 @@ function createInternalSessionRpc(connection, sessionId) {
|
|
|
7407
7483
|
finalizeInvocationEffect: async (params) => connection.sendRequest("session.commands.finalizeInvocationEffect", { ...params, sessionId })
|
|
7408
7484
|
},
|
|
7409
7485
|
/** @experimental */
|
|
7486
|
+
ui: {
|
|
7487
|
+
/**
|
|
7488
|
+
* Resolves a pending elicitation request after direct interaction in the trusted in-process client. Only an accepted response to the built-in ask_user tool can become trusted human evidence.
|
|
7489
|
+
*
|
|
7490
|
+
* @param params Pending elicitation request ID and the user's response (accept/decline/cancel + form values).
|
|
7491
|
+
*
|
|
7492
|
+
* @returns Indicates whether the elicitation response was accepted; false if it was already resolved by another client.
|
|
7493
|
+
*/
|
|
7494
|
+
handleHumanAskUser: async (params) => connection.sendRequest("session.ui.handleHumanAskUser", { ...params, sessionId }),
|
|
7495
|
+
/**
|
|
7496
|
+
* Resolves a pending `user_input.requested` event after direct interaction in the trusted in-process client.
|
|
7497
|
+
*
|
|
7498
|
+
* @param params Request ID of a pending `user_input.requested` event and the user's response.
|
|
7499
|
+
*
|
|
7500
|
+
* @returns Indicates whether the pending UI request was resolved by this call.
|
|
7501
|
+
*/
|
|
7502
|
+
handleHumanUserInput: async (params) => connection.sendRequest("session.ui.handleHumanUserInput", { ...params, sessionId }),
|
|
7503
|
+
/**
|
|
7504
|
+
* Resolves a pending `exit_plan_mode.requested` event after direct interaction in the trusted in-process client.
|
|
7505
|
+
*
|
|
7506
|
+
* @param params Request ID of a pending `exit_plan_mode.requested` event and the user's response.
|
|
7507
|
+
*
|
|
7508
|
+
* @returns Indicates whether the pending UI request was resolved by this call.
|
|
7509
|
+
*/
|
|
7510
|
+
handleHumanExitPlanMode: async (params) => connection.sendRequest("session.ui.handleHumanExitPlanMode", { ...params, sessionId })
|
|
7511
|
+
},
|
|
7512
|
+
/** @experimental */
|
|
7410
7513
|
settings: {
|
|
7411
7514
|
/**
|
|
7412
7515
|
* Returns a redacted snapshot of session runtime settings, with secrets and raw feature flags excluded. Internal: the runtime settings shape is a runtime-internal surface and is deliberately kept out of the public SDK, because consumers should not depend on the runtime's internal settings layout. It remains callable in-process and is expected to be reworked as the runtime internals are consolidated.
|
|
@@ -7559,11 +7662,21 @@ function registerClientSessionApiHandlers(connection, getHandlers) {
|
|
|
7559
7662
|
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
7560
7663
|
return handler.readFile(params);
|
|
7561
7664
|
});
|
|
7665
|
+
connection.onRequest("sessionFs.readFileBytes", async (params) => {
|
|
7666
|
+
const handler = getHandlers(params.sessionId).sessionFs;
|
|
7667
|
+
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
7668
|
+
return handler.readFileBytes(params);
|
|
7669
|
+
});
|
|
7562
7670
|
connection.onRequest("sessionFs.writeFile", async (params) => {
|
|
7563
7671
|
const handler = getHandlers(params.sessionId).sessionFs;
|
|
7564
7672
|
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
7565
7673
|
return handler.writeFile(params);
|
|
7566
7674
|
});
|
|
7675
|
+
connection.onRequest("sessionFs.writeFileBytes", async (params) => {
|
|
7676
|
+
const handler = getHandlers(params.sessionId).sessionFs;
|
|
7677
|
+
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
7678
|
+
return handler.writeFileBytes(params);
|
|
7679
|
+
});
|
|
7567
7680
|
connection.onRequest("sessionFs.appendFile", async (params) => {
|
|
7568
7681
|
const handler = getHandlers(params.sessionId).sessionFs;
|
|
7569
7682
|
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
@@ -7752,6 +7865,8 @@ function isResponseSchema(value) {
|
|
|
7752
7865
|
}
|
|
7753
7866
|
|
|
7754
7867
|
// src/sdk/nodejs/dist/sessionFsProvider.js
|
|
7868
|
+
var MAX_BINARY_BYTES = (64 * 1024 * 1024 - 1024) / 4 * 3;
|
|
7869
|
+
var MAX_BINARY_CONTENT_LENGTH = Math.ceil(MAX_BINARY_BYTES / 3) * 4;
|
|
7755
7870
|
var SessionFsSqliteTransactionFailure = class extends Error {
|
|
7756
7871
|
/** Failure classification reported to the runtime. */
|
|
7757
7872
|
errorClass;
|
|
@@ -7761,6 +7876,9 @@ var SessionFsSqliteTransactionFailure = class extends Error {
|
|
|
7761
7876
|
this.errorClass = errorClass;
|
|
7762
7877
|
}
|
|
7763
7878
|
};
|
|
7879
|
+
var SessionFsWriteFailure = class extends Error {
|
|
7880
|
+
writeChanged = true;
|
|
7881
|
+
};
|
|
7764
7882
|
function normalizeSqliteParams(params) {
|
|
7765
7883
|
if (!params) {
|
|
7766
7884
|
return void 0;
|
|
@@ -7783,10 +7901,60 @@ function createSessionFsAdapter(provider) {
|
|
|
7783
7901
|
return { content: "", error: toSessionFsError(err) };
|
|
7784
7902
|
}
|
|
7785
7903
|
},
|
|
7904
|
+
readFileBytes: async ({ path }) => {
|
|
7905
|
+
if (!provider.readFileBytes) {
|
|
7906
|
+
return {
|
|
7907
|
+
content: "",
|
|
7908
|
+
error: { code: "UNKNOWN", message: "Binary reads are not supported" }
|
|
7909
|
+
};
|
|
7910
|
+
}
|
|
7911
|
+
try {
|
|
7912
|
+
const bytes = await provider.readFileBytes(path);
|
|
7913
|
+
if (bytes.length > MAX_BINARY_BYTES) {
|
|
7914
|
+
return {
|
|
7915
|
+
content: "",
|
|
7916
|
+
error: {
|
|
7917
|
+
code: "UNKNOWN",
|
|
7918
|
+
message: "sessionFs.readFileBytes content exceeds the binary read limit"
|
|
7919
|
+
}
|
|
7920
|
+
};
|
|
7921
|
+
}
|
|
7922
|
+
return {
|
|
7923
|
+
content: Buffer.from(bytes).toString("base64")
|
|
7924
|
+
};
|
|
7925
|
+
} catch (err) {
|
|
7926
|
+
return { content: "", error: toSessionFsError(err) };
|
|
7927
|
+
}
|
|
7928
|
+
},
|
|
7786
7929
|
writeFile: async ({ path, content, mode }) => {
|
|
7787
7930
|
try {
|
|
7788
7931
|
await provider.writeFile(path, content, mode);
|
|
7789
7932
|
return void 0;
|
|
7933
|
+
} catch (err) {
|
|
7934
|
+
const error = toSessionFsError(err);
|
|
7935
|
+
return err instanceof SessionFsWriteFailure ? { ...error, writeChanged: true } : error;
|
|
7936
|
+
}
|
|
7937
|
+
},
|
|
7938
|
+
writeFileBytes: async ({ path, content, mode }) => {
|
|
7939
|
+
if (!provider.writeFileBytes) {
|
|
7940
|
+
return { code: "UNKNOWN", message: "Binary writes are not supported" };
|
|
7941
|
+
}
|
|
7942
|
+
if (content.length > MAX_BINARY_CONTENT_LENGTH) {
|
|
7943
|
+
return {
|
|
7944
|
+
code: "UNKNOWN",
|
|
7945
|
+
message: "sessionFs.writeFileBytes content exceeds the binary write limit"
|
|
7946
|
+
};
|
|
7947
|
+
}
|
|
7948
|
+
const bytes = Buffer.from(content, "base64");
|
|
7949
|
+
if (bytes.toString("base64") !== content || bytes.length > MAX_BINARY_BYTES) {
|
|
7950
|
+
return {
|
|
7951
|
+
code: "UNKNOWN",
|
|
7952
|
+
message: "invalid sessionFs.writeFileBytes base64 content"
|
|
7953
|
+
};
|
|
7954
|
+
}
|
|
7955
|
+
try {
|
|
7956
|
+
await provider.writeFileBytes(path, bytes, mode);
|
|
7957
|
+
return void 0;
|
|
7790
7958
|
} catch (err) {
|
|
7791
7959
|
return toSessionFsError(err);
|
|
7792
7960
|
}
|
|
@@ -8782,6 +8950,18 @@ function copyDefinedWorkflowAgentOption(source, target, key) {
|
|
|
8782
8950
|
target[key] = value;
|
|
8783
8951
|
}
|
|
8784
8952
|
}
|
|
8953
|
+
function toToolDefinition(tool) {
|
|
8954
|
+
return {
|
|
8955
|
+
name: tool.name,
|
|
8956
|
+
description: tool.description ?? "",
|
|
8957
|
+
parameters: toJsonSchema(tool.parameters),
|
|
8958
|
+
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
8959
|
+
skipPermission: tool.skipPermission,
|
|
8960
|
+
defer: tool.defer,
|
|
8961
|
+
metadata: tool.metadata,
|
|
8962
|
+
isTerminal: tool.isTerminal
|
|
8963
|
+
};
|
|
8964
|
+
}
|
|
8785
8965
|
var workflowExecutionStore = new AsyncLocalStorage();
|
|
8786
8966
|
function throwIfWorkflowExecutionIsActive() {
|
|
8787
8967
|
if (workflowExecutionStore.getStore()?.active) {
|
|
@@ -9002,6 +9182,8 @@ var CopilotSession = class {
|
|
|
9002
9182
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
9003
9183
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
9004
9184
|
toolHandlers = /* @__PURE__ */ new Map();
|
|
9185
|
+
/** Settles once every earlier `setTools` call has finished. */
|
|
9186
|
+
setToolsQueue = Promise.resolve();
|
|
9005
9187
|
pendingExternalTools = /* @__PURE__ */ new Map();
|
|
9006
9188
|
canvases = /* @__PURE__ */ new Map();
|
|
9007
9189
|
bearerTokenProviders = /* @__PURE__ */ new Map();
|
|
@@ -9813,7 +9995,20 @@ var CopilotSession = class {
|
|
|
9813
9995
|
}
|
|
9814
9996
|
for (const tool of tools) {
|
|
9815
9997
|
if (tool.handler) {
|
|
9816
|
-
|
|
9998
|
+
const handler = tool.handler;
|
|
9999
|
+
if (tool.name === "apply_patch" && tool.overridesBuiltInTool && toJsonSchema(tool.parameters)?.type === "string") {
|
|
10000
|
+
this.toolHandlers.set(tool.name, (args, invocation) => {
|
|
10001
|
+
if (typeof args === "string") {
|
|
10002
|
+
return handler(args, invocation);
|
|
10003
|
+
}
|
|
10004
|
+
if (typeof args === "object" && args !== null && "input" in args && typeof args.input === "string") {
|
|
10005
|
+
return handler(args.input, invocation);
|
|
10006
|
+
}
|
|
10007
|
+
throw new TypeError("apply_patch string override requires a string input");
|
|
10008
|
+
});
|
|
10009
|
+
} else {
|
|
10010
|
+
this.toolHandlers.set(tool.name, handler);
|
|
10011
|
+
}
|
|
9817
10012
|
}
|
|
9818
10013
|
}
|
|
9819
10014
|
}
|
|
@@ -10408,7 +10603,9 @@ var CopilotSession = class {
|
|
|
10408
10603
|
sessionStart: this.hooks.onSessionStart,
|
|
10409
10604
|
sessionEnd: this.hooks.onSessionEnd,
|
|
10410
10605
|
errorOccurred: this.hooks.onErrorOccurred,
|
|
10411
|
-
agentStop: this.hooks.onAgentStop
|
|
10606
|
+
agentStop: this.hooks.onAgentStop,
|
|
10607
|
+
subagentStart: this.hooks.onSubagentStart,
|
|
10608
|
+
subagentStop: this.hooks.onSubagentStop
|
|
10412
10609
|
};
|
|
10413
10610
|
const handler = handlerMap[hookType];
|
|
10414
10611
|
if (!handler) {
|
|
@@ -10572,6 +10769,59 @@ var CopilotSession = class {
|
|
|
10572
10769
|
async setAutoTier(autoTier) {
|
|
10573
10770
|
return await this.rpc.model.switchAutoTier({ autoTier });
|
|
10574
10771
|
}
|
|
10772
|
+
/**
|
|
10773
|
+
* Replace the tools this client supplies to the session.
|
|
10774
|
+
*
|
|
10775
|
+
* `tools` becomes the complete set of tools this client implements,
|
|
10776
|
+
* replacing the ones it supplied when the session was created or resumed,
|
|
10777
|
+
* or in an earlier call. Built-in, MCP, and plugin tools, and tools other
|
|
10778
|
+
* connected clients supply, are unaffected. Pass an empty array to remove
|
|
10779
|
+
* all of this client's tools.
|
|
10780
|
+
*
|
|
10781
|
+
* Tools are defined the same way as for `createSession`: calls to tools
|
|
10782
|
+
* with a `handler` are dispatched to it, and tools without one are
|
|
10783
|
+
* declaration-only. Once the runtime accepts the replacement, every tool
|
|
10784
|
+
* call this session dispatches uses the new handlers; calls already
|
|
10785
|
+
* running finish on their original handlers. If the runtime rejects the
|
|
10786
|
+
* replacement, this rejects and the previous tools and handlers stay in
|
|
10787
|
+
* place. Concurrent calls on the same session are applied one at a time,
|
|
10788
|
+
* in the order they are made.
|
|
10789
|
+
*
|
|
10790
|
+
* The agent sees the new tools from its next model request, which can fall
|
|
10791
|
+
* within a turn in progress. A model request already in flight was made
|
|
10792
|
+
* with the previous tools, so the agent can still call a tool you removed.
|
|
10793
|
+
* This session doesn't answer that call, and it can stay pending until the
|
|
10794
|
+
* turn is aborted. If a running turn might still call a tool you remove,
|
|
10795
|
+
* replace tools while the session is idle.
|
|
10796
|
+
*
|
|
10797
|
+
* @param tools - The complete set of tools this client supplies
|
|
10798
|
+
*
|
|
10799
|
+
* @experimental Wraps the experimental `session.tools.set` RPC and may change
|
|
10800
|
+
* or be removed in a future release.
|
|
10801
|
+
*
|
|
10802
|
+
* @example
|
|
10803
|
+
* ```typescript
|
|
10804
|
+
* await session.setTools([
|
|
10805
|
+
* defineTool("search_issues", {
|
|
10806
|
+
* description: "Search the issues shown on the current page",
|
|
10807
|
+
* parameters: z.object({ query: z.string() }),
|
|
10808
|
+
* handler: async ({ query }) => searchIssues(query),
|
|
10809
|
+
* }),
|
|
10810
|
+
* ]);
|
|
10811
|
+
* ```
|
|
10812
|
+
*/
|
|
10813
|
+
async setTools(tools) {
|
|
10814
|
+
const definitions = tools.map(toToolDefinition);
|
|
10815
|
+
const replacement = this.setToolsQueue.then(async () => {
|
|
10816
|
+
await this.rpc.tools.set({ tools: definitions });
|
|
10817
|
+
this.registerTools(tools);
|
|
10818
|
+
});
|
|
10819
|
+
this.setToolsQueue = replacement.then(
|
|
10820
|
+
() => void 0,
|
|
10821
|
+
() => void 0
|
|
10822
|
+
);
|
|
10823
|
+
await replacement;
|
|
10824
|
+
}
|
|
10575
10825
|
/**
|
|
10576
10826
|
* Log a message to the session timeline.
|
|
10577
10827
|
* The message appears in the session event stream and is visible to SDK consumers
|
|
@@ -10827,6 +11077,7 @@ var EXCLUDED_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
|
10827
11077
|
"app.js",
|
|
10828
11078
|
"assets",
|
|
10829
11079
|
"changelog.json",
|
|
11080
|
+
"cli-main.js",
|
|
10830
11081
|
"copilot",
|
|
10831
11082
|
"copilot.exe",
|
|
10832
11083
|
"foundry-local-sdk",
|
|
@@ -11145,6 +11396,7 @@ var ToolSet = class {
|
|
|
11145
11396
|
// src/sdk/nodejs/dist/client.js
|
|
11146
11397
|
var MIN_PROTOCOL_VERSION = 3;
|
|
11147
11398
|
var RUNTIME_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
11399
|
+
var CLOUD_SESSION_CLEANUP_TIMEOUT_MS = 1e4;
|
|
11148
11400
|
function createMessageConnection(reader, writer) {
|
|
11149
11401
|
let dispatch;
|
|
11150
11402
|
let finishDrain;
|
|
@@ -11673,6 +11925,11 @@ var CopilotClient = class _CopilotClient {
|
|
|
11673
11925
|
"SessionFsConfig declares capabilities.sqlite but the provider does not implement sqlite."
|
|
11674
11926
|
);
|
|
11675
11927
|
}
|
|
11928
|
+
if (this.sessionFsConfig.capabilities?.binary && (!provider.readFileBytes || !provider.writeFileBytes)) {
|
|
11929
|
+
throw new Error(
|
|
11930
|
+
"SessionFsConfig declares capabilities.binary but the provider does not implement readFileBytes and writeFileBytes."
|
|
11931
|
+
);
|
|
11932
|
+
}
|
|
11676
11933
|
session.clientSessionApis.sessionFs = createSessionFsAdapter(provider);
|
|
11677
11934
|
}
|
|
11678
11935
|
setupClientGlobalHandlers() {
|
|
@@ -12356,12 +12613,13 @@ var CopilotClient = class _CopilotClient {
|
|
|
12356
12613
|
if (config.onEvent) {
|
|
12357
12614
|
s.on(config.onEvent);
|
|
12358
12615
|
}
|
|
12359
|
-
this.sessions.set(sessionId, s);
|
|
12360
12616
|
this.setupSessionFs(s, config);
|
|
12617
|
+
this.sessions.set(sessionId, s);
|
|
12361
12618
|
return s;
|
|
12362
12619
|
};
|
|
12363
12620
|
let session;
|
|
12364
12621
|
let registeredId;
|
|
12622
|
+
let uninitializedCloudSessionId;
|
|
12365
12623
|
if (localSessionId !== void 0) {
|
|
12366
12624
|
try {
|
|
12367
12625
|
session = initializeSession(localSessionId);
|
|
@@ -12484,7 +12742,9 @@ var CopilotClient = class _CopilotClient {
|
|
|
12484
12742
|
);
|
|
12485
12743
|
}
|
|
12486
12744
|
if (session === void 0) {
|
|
12745
|
+
uninitializedCloudSessionId = returnedSessionId;
|
|
12487
12746
|
session = initializeSession(returnedSessionId);
|
|
12747
|
+
uninitializedCloudSessionId = void 0;
|
|
12488
12748
|
registeredId = returnedSessionId;
|
|
12489
12749
|
}
|
|
12490
12750
|
this.assignGitHubTokenProvider(gitHubTokenProviderRegistrationId, returnedSessionId);
|
|
@@ -12506,6 +12766,20 @@ var CopilotClient = class _CopilotClient {
|
|
|
12506
12766
|
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
12507
12767
|
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
12508
12768
|
}
|
|
12769
|
+
if (uninitializedCloudSessionId !== void 0) {
|
|
12770
|
+
try {
|
|
12771
|
+
await withTimeout(
|
|
12772
|
+
this.deleteSession(uninitializedCloudSessionId),
|
|
12773
|
+
CLOUD_SESSION_CLEANUP_TIMEOUT_MS,
|
|
12774
|
+
`session.delete timed out after ${CLOUD_SESSION_CLEANUP_TIMEOUT_MS}ms`
|
|
12775
|
+
);
|
|
12776
|
+
} catch (cleanupError) {
|
|
12777
|
+
throw new AggregateError(
|
|
12778
|
+
[e, cleanupError],
|
|
12779
|
+
"Failed to initialize and delete cloud session"
|
|
12780
|
+
);
|
|
12781
|
+
}
|
|
12782
|
+
}
|
|
12509
12783
|
throw e;
|
|
12510
12784
|
}
|
|
12511
12785
|
for (const entry of this.hostHandoffs.values()) {
|
|
@@ -12605,8 +12879,8 @@ var CopilotClient = class _CopilotClient {
|
|
|
12605
12879
|
if (config.onEvent) {
|
|
12606
12880
|
session.on(config.onEvent);
|
|
12607
12881
|
}
|
|
12608
|
-
this.sessions.set(sessionId, session);
|
|
12609
12882
|
this.setupSessionFs(session, config);
|
|
12883
|
+
this.sessions.set(sessionId, session);
|
|
12610
12884
|
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
12611
12885
|
const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
|
|
12612
12886
|
config.gitHubTokenProvider,
|