@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/index.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
|
}
|
|
@@ -8764,10 +8932,10 @@ var SYSTEM_MESSAGE_SECTIONS = {
|
|
|
8764
8932
|
tool_instructions: { description: "Per-tool usage instructions" },
|
|
8765
8933
|
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
8766
8934
|
runtime_instructions: {
|
|
8767
|
-
description: "Runtime-provided context and instructions
|
|
8935
|
+
description: "Runtime-provided system-prompt context and instructions, such as system notifications, memories, workspace context, and content-exclusion policy. Mode-specific instructions can travel in transition messages instead."
|
|
8768
8936
|
},
|
|
8769
8937
|
last_instructions: {
|
|
8770
|
-
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
8938
|
+
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion, and configured subagent-model guidance when the task tool is available"
|
|
8771
8939
|
}
|
|
8772
8940
|
};
|
|
8773
8941
|
function isAttributedPermissionResult(result) {
|
|
@@ -8910,6 +9078,18 @@ function copyDefinedWorkflowAgentOption(source, target, key) {
|
|
|
8910
9078
|
target[key] = value;
|
|
8911
9079
|
}
|
|
8912
9080
|
}
|
|
9081
|
+
function toToolDefinition(tool) {
|
|
9082
|
+
return {
|
|
9083
|
+
name: tool.name,
|
|
9084
|
+
description: tool.description ?? "",
|
|
9085
|
+
parameters: toJsonSchema(tool.parameters),
|
|
9086
|
+
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
9087
|
+
skipPermission: tool.skipPermission,
|
|
9088
|
+
defer: tool.defer,
|
|
9089
|
+
metadata: tool.metadata,
|
|
9090
|
+
isTerminal: tool.isTerminal
|
|
9091
|
+
};
|
|
9092
|
+
}
|
|
8913
9093
|
var workflowExecutionStore = new AsyncLocalStorage();
|
|
8914
9094
|
function throwIfWorkflowExecutionIsActive() {
|
|
8915
9095
|
if (workflowExecutionStore.getStore()?.active) {
|
|
@@ -9130,6 +9310,8 @@ var CopilotSession = class {
|
|
|
9130
9310
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
9131
9311
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
9132
9312
|
toolHandlers = /* @__PURE__ */ new Map();
|
|
9313
|
+
/** Settles once every earlier `setTools` call has finished. */
|
|
9314
|
+
setToolsQueue = Promise.resolve();
|
|
9133
9315
|
pendingExternalTools = /* @__PURE__ */ new Map();
|
|
9134
9316
|
canvases = /* @__PURE__ */ new Map();
|
|
9135
9317
|
bearerTokenProviders = /* @__PURE__ */ new Map();
|
|
@@ -9941,7 +10123,20 @@ var CopilotSession = class {
|
|
|
9941
10123
|
}
|
|
9942
10124
|
for (const tool of tools) {
|
|
9943
10125
|
if (tool.handler) {
|
|
9944
|
-
|
|
10126
|
+
const handler = tool.handler;
|
|
10127
|
+
if (tool.name === "apply_patch" && tool.overridesBuiltInTool && toJsonSchema(tool.parameters)?.type === "string") {
|
|
10128
|
+
this.toolHandlers.set(tool.name, (args, invocation) => {
|
|
10129
|
+
if (typeof args === "string") {
|
|
10130
|
+
return handler(args, invocation);
|
|
10131
|
+
}
|
|
10132
|
+
if (typeof args === "object" && args !== null && "input" in args && typeof args.input === "string") {
|
|
10133
|
+
return handler(args.input, invocation);
|
|
10134
|
+
}
|
|
10135
|
+
throw new TypeError("apply_patch string override requires a string input");
|
|
10136
|
+
});
|
|
10137
|
+
} else {
|
|
10138
|
+
this.toolHandlers.set(tool.name, handler);
|
|
10139
|
+
}
|
|
9945
10140
|
}
|
|
9946
10141
|
}
|
|
9947
10142
|
}
|
|
@@ -10536,7 +10731,9 @@ var CopilotSession = class {
|
|
|
10536
10731
|
sessionStart: this.hooks.onSessionStart,
|
|
10537
10732
|
sessionEnd: this.hooks.onSessionEnd,
|
|
10538
10733
|
errorOccurred: this.hooks.onErrorOccurred,
|
|
10539
|
-
agentStop: this.hooks.onAgentStop
|
|
10734
|
+
agentStop: this.hooks.onAgentStop,
|
|
10735
|
+
subagentStart: this.hooks.onSubagentStart,
|
|
10736
|
+
subagentStop: this.hooks.onSubagentStop
|
|
10540
10737
|
};
|
|
10541
10738
|
const handler = handlerMap[hookType];
|
|
10542
10739
|
if (!handler) {
|
|
@@ -10700,6 +10897,59 @@ var CopilotSession = class {
|
|
|
10700
10897
|
async setAutoTier(autoTier) {
|
|
10701
10898
|
return await this.rpc.model.switchAutoTier({ autoTier });
|
|
10702
10899
|
}
|
|
10900
|
+
/**
|
|
10901
|
+
* Replace the tools this client supplies to the session.
|
|
10902
|
+
*
|
|
10903
|
+
* `tools` becomes the complete set of tools this client implements,
|
|
10904
|
+
* replacing the ones it supplied when the session was created or resumed,
|
|
10905
|
+
* or in an earlier call. Built-in, MCP, and plugin tools, and tools other
|
|
10906
|
+
* connected clients supply, are unaffected. Pass an empty array to remove
|
|
10907
|
+
* all of this client's tools.
|
|
10908
|
+
*
|
|
10909
|
+
* Tools are defined the same way as for `createSession`: calls to tools
|
|
10910
|
+
* with a `handler` are dispatched to it, and tools without one are
|
|
10911
|
+
* declaration-only. Once the runtime accepts the replacement, every tool
|
|
10912
|
+
* call this session dispatches uses the new handlers; calls already
|
|
10913
|
+
* running finish on their original handlers. If the runtime rejects the
|
|
10914
|
+
* replacement, this rejects and the previous tools and handlers stay in
|
|
10915
|
+
* place. Concurrent calls on the same session are applied one at a time,
|
|
10916
|
+
* in the order they are made.
|
|
10917
|
+
*
|
|
10918
|
+
* The agent sees the new tools from its next model request, which can fall
|
|
10919
|
+
* within a turn in progress. A model request already in flight was made
|
|
10920
|
+
* with the previous tools, so the agent can still call a tool you removed.
|
|
10921
|
+
* This session doesn't answer that call, and it can stay pending until the
|
|
10922
|
+
* turn is aborted. If a running turn might still call a tool you remove,
|
|
10923
|
+
* replace tools while the session is idle.
|
|
10924
|
+
*
|
|
10925
|
+
* @param tools - The complete set of tools this client supplies
|
|
10926
|
+
*
|
|
10927
|
+
* @experimental Wraps the experimental `session.tools.set` RPC and may change
|
|
10928
|
+
* or be removed in a future release.
|
|
10929
|
+
*
|
|
10930
|
+
* @example
|
|
10931
|
+
* ```typescript
|
|
10932
|
+
* await session.setTools([
|
|
10933
|
+
* defineTool("search_issues", {
|
|
10934
|
+
* description: "Search the issues shown on the current page",
|
|
10935
|
+
* parameters: z.object({ query: z.string() }),
|
|
10936
|
+
* handler: async ({ query }) => searchIssues(query),
|
|
10937
|
+
* }),
|
|
10938
|
+
* ]);
|
|
10939
|
+
* ```
|
|
10940
|
+
*/
|
|
10941
|
+
async setTools(tools) {
|
|
10942
|
+
const definitions = tools.map(toToolDefinition);
|
|
10943
|
+
const replacement = this.setToolsQueue.then(async () => {
|
|
10944
|
+
await this.rpc.tools.set({ tools: definitions });
|
|
10945
|
+
this.registerTools(tools);
|
|
10946
|
+
});
|
|
10947
|
+
this.setToolsQueue = replacement.then(
|
|
10948
|
+
() => void 0,
|
|
10949
|
+
() => void 0
|
|
10950
|
+
);
|
|
10951
|
+
await replacement;
|
|
10952
|
+
}
|
|
10703
10953
|
/**
|
|
10704
10954
|
* Log a message to the session timeline.
|
|
10705
10955
|
* The message appears in the session event stream and is visible to SDK consumers
|
|
@@ -10955,6 +11205,7 @@ var EXCLUDED_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
|
10955
11205
|
"app.js",
|
|
10956
11206
|
"assets",
|
|
10957
11207
|
"changelog.json",
|
|
11208
|
+
"cli-main.js",
|
|
10958
11209
|
"copilot",
|
|
10959
11210
|
"copilot.exe",
|
|
10960
11211
|
"foundry-local-sdk",
|
|
@@ -11298,6 +11549,7 @@ var BuiltInTools = {
|
|
|
11298
11549
|
// src/sdk/nodejs/dist/client.js
|
|
11299
11550
|
var MIN_PROTOCOL_VERSION = 3;
|
|
11300
11551
|
var RUNTIME_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
11552
|
+
var CLOUD_SESSION_CLEANUP_TIMEOUT_MS = 1e4;
|
|
11301
11553
|
function createMessageConnection(reader, writer) {
|
|
11302
11554
|
let dispatch;
|
|
11303
11555
|
let finishDrain;
|
|
@@ -11826,6 +12078,11 @@ var CopilotClient = class _CopilotClient {
|
|
|
11826
12078
|
"SessionFsConfig declares capabilities.sqlite but the provider does not implement sqlite."
|
|
11827
12079
|
);
|
|
11828
12080
|
}
|
|
12081
|
+
if (this.sessionFsConfig.capabilities?.binary && (!provider.readFileBytes || !provider.writeFileBytes)) {
|
|
12082
|
+
throw new Error(
|
|
12083
|
+
"SessionFsConfig declares capabilities.binary but the provider does not implement readFileBytes and writeFileBytes."
|
|
12084
|
+
);
|
|
12085
|
+
}
|
|
11829
12086
|
session.clientSessionApis.sessionFs = createSessionFsAdapter(provider);
|
|
11830
12087
|
}
|
|
11831
12088
|
setupClientGlobalHandlers() {
|
|
@@ -12509,12 +12766,13 @@ var CopilotClient = class _CopilotClient {
|
|
|
12509
12766
|
if (config.onEvent) {
|
|
12510
12767
|
s.on(config.onEvent);
|
|
12511
12768
|
}
|
|
12512
|
-
this.sessions.set(sessionId, s);
|
|
12513
12769
|
this.setupSessionFs(s, config);
|
|
12770
|
+
this.sessions.set(sessionId, s);
|
|
12514
12771
|
return s;
|
|
12515
12772
|
};
|
|
12516
12773
|
let session;
|
|
12517
12774
|
let registeredId;
|
|
12775
|
+
let uninitializedCloudSessionId;
|
|
12518
12776
|
if (localSessionId !== void 0) {
|
|
12519
12777
|
try {
|
|
12520
12778
|
session = initializeSession(localSessionId);
|
|
@@ -12637,7 +12895,9 @@ var CopilotClient = class _CopilotClient {
|
|
|
12637
12895
|
);
|
|
12638
12896
|
}
|
|
12639
12897
|
if (session === void 0) {
|
|
12898
|
+
uninitializedCloudSessionId = returnedSessionId;
|
|
12640
12899
|
session = initializeSession(returnedSessionId);
|
|
12900
|
+
uninitializedCloudSessionId = void 0;
|
|
12641
12901
|
registeredId = returnedSessionId;
|
|
12642
12902
|
}
|
|
12643
12903
|
this.assignGitHubTokenProvider(gitHubTokenProviderRegistrationId, returnedSessionId);
|
|
@@ -12659,6 +12919,20 @@ var CopilotClient = class _CopilotClient {
|
|
|
12659
12919
|
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
12660
12920
|
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
12661
12921
|
}
|
|
12922
|
+
if (uninitializedCloudSessionId !== void 0) {
|
|
12923
|
+
try {
|
|
12924
|
+
await withTimeout(
|
|
12925
|
+
this.deleteSession(uninitializedCloudSessionId),
|
|
12926
|
+
CLOUD_SESSION_CLEANUP_TIMEOUT_MS,
|
|
12927
|
+
`session.delete timed out after ${CLOUD_SESSION_CLEANUP_TIMEOUT_MS}ms`
|
|
12928
|
+
);
|
|
12929
|
+
} catch (cleanupError) {
|
|
12930
|
+
throw new AggregateError(
|
|
12931
|
+
[e, cleanupError],
|
|
12932
|
+
"Failed to initialize and delete cloud session"
|
|
12933
|
+
);
|
|
12934
|
+
}
|
|
12935
|
+
}
|
|
12662
12936
|
throw e;
|
|
12663
12937
|
}
|
|
12664
12938
|
for (const entry of this.hostHandoffs.values()) {
|
|
@@ -12758,8 +13032,8 @@ var CopilotClient = class _CopilotClient {
|
|
|
12758
13032
|
if (config.onEvent) {
|
|
12759
13033
|
session.on(config.onEvent);
|
|
12760
13034
|
}
|
|
12761
|
-
this.sessions.set(sessionId, session);
|
|
12762
13035
|
this.setupSessionFs(session, config);
|
|
13036
|
+
this.sessions.set(sessionId, session);
|
|
12763
13037
|
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
12764
13038
|
const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
|
|
12765
13039
|
config.gitHubTokenProvider,
|
|
@@ -14066,6 +14340,7 @@ export {
|
|
|
14066
14340
|
RuntimeConnection,
|
|
14067
14341
|
SYSTEM_MESSAGE_SECTIONS,
|
|
14068
14342
|
SessionFsSqliteTransactionFailure,
|
|
14343
|
+
SessionFsWriteFailure,
|
|
14069
14344
|
ToolSet,
|
|
14070
14345
|
WorkflowResumeError,
|
|
14071
14346
|
approveAll,
|
package/copilot-sdk/session.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createSessionRpc } from "./generated/rpc.js";
|
|
2
2
|
import type { ModelSwitchAutoTierResult } from "./generated/rpc.js";
|
|
3
3
|
import type { OpenCanvasInstance } from "./generated/rpc.js";
|
|
4
|
-
import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TranscriptRecovery, TypedSessionEventHandler } from "./types.js";
|
|
4
|
+
import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, Tool, TranscriptRecovery, TypedSessionEventHandler } from "./types.js";
|
|
5
5
|
import { type SessionWorkflowApi } from "./workflow.js";
|
|
6
6
|
/** Assistant message event - the final response from the assistant. */
|
|
7
7
|
export type AssistantMessageEvent = Extract<SessionEvent, {
|
|
@@ -45,6 +45,8 @@ export declare class CopilotSession {
|
|
|
45
45
|
private eventHandlers;
|
|
46
46
|
private typedEventHandlers;
|
|
47
47
|
private toolHandlers;
|
|
48
|
+
/** Settles once every earlier `setTools` call has finished. */
|
|
49
|
+
private setToolsQueue;
|
|
48
50
|
private pendingExternalTools;
|
|
49
51
|
private canvases;
|
|
50
52
|
private bearerTokenProviders;
|
|
@@ -364,6 +366,48 @@ export declare class CopilotSession {
|
|
|
364
366
|
* ```
|
|
365
367
|
*/
|
|
366
368
|
setAutoTier(autoTier: AutoTier | null): Promise<ModelSwitchAutoTierResult>;
|
|
369
|
+
/**
|
|
370
|
+
* Replace the tools this client supplies to the session.
|
|
371
|
+
*
|
|
372
|
+
* `tools` becomes the complete set of tools this client implements,
|
|
373
|
+
* replacing the ones it supplied when the session was created or resumed,
|
|
374
|
+
* or in an earlier call. Built-in, MCP, and plugin tools, and tools other
|
|
375
|
+
* connected clients supply, are unaffected. Pass an empty array to remove
|
|
376
|
+
* all of this client's tools.
|
|
377
|
+
*
|
|
378
|
+
* Tools are defined the same way as for `createSession`: calls to tools
|
|
379
|
+
* with a `handler` are dispatched to it, and tools without one are
|
|
380
|
+
* declaration-only. Once the runtime accepts the replacement, every tool
|
|
381
|
+
* call this session dispatches uses the new handlers; calls already
|
|
382
|
+
* running finish on their original handlers. If the runtime rejects the
|
|
383
|
+
* replacement, this rejects and the previous tools and handlers stay in
|
|
384
|
+
* place. Concurrent calls on the same session are applied one at a time,
|
|
385
|
+
* in the order they are made.
|
|
386
|
+
*
|
|
387
|
+
* The agent sees the new tools from its next model request, which can fall
|
|
388
|
+
* within a turn in progress. A model request already in flight was made
|
|
389
|
+
* with the previous tools, so the agent can still call a tool you removed.
|
|
390
|
+
* This session doesn't answer that call, and it can stay pending until the
|
|
391
|
+
* turn is aborted. If a running turn might still call a tool you remove,
|
|
392
|
+
* replace tools while the session is idle.
|
|
393
|
+
*
|
|
394
|
+
* @param tools - The complete set of tools this client supplies
|
|
395
|
+
*
|
|
396
|
+
* @experimental Wraps the experimental `session.tools.set` RPC and may change
|
|
397
|
+
* or be removed in a future release.
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```typescript
|
|
401
|
+
* await session.setTools([
|
|
402
|
+
* defineTool("search_issues", {
|
|
403
|
+
* description: "Search the issues shown on the current page",
|
|
404
|
+
* parameters: z.object({ query: z.string() }),
|
|
405
|
+
* handler: async ({ query }) => searchIssues(query),
|
|
406
|
+
* }),
|
|
407
|
+
* ]);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
setTools(tools: Tool[]): Promise<void>;
|
|
367
411
|
/**
|
|
368
412
|
* Log a message to the session timeline.
|
|
369
413
|
* The message appears in the session event stream and is visible to SDK consumers
|
|
@@ -37,6 +37,10 @@ export declare class SessionFsSqliteTransactionFailure extends Error {
|
|
|
37
37
|
readonly errorClass: SessionFsSqliteTransactionErrorClass;
|
|
38
38
|
constructor(message: string, errorClass?: SessionFsSqliteTransactionErrorClass);
|
|
39
39
|
}
|
|
40
|
+
/** Throw from `writeFile` only when the provider changed the target before failing. */
|
|
41
|
+
export declare class SessionFsWriteFailure extends Error {
|
|
42
|
+
readonly writeChanged = true;
|
|
43
|
+
}
|
|
40
44
|
/**
|
|
41
45
|
* SQLite operations for the per-session database.
|
|
42
46
|
* Implementers provide query execution and existence checking.
|
|
@@ -78,7 +82,11 @@ export interface SessionFsSqliteProvider {
|
|
|
78
82
|
export interface SessionFsProvider {
|
|
79
83
|
/** Reads the full content of a file. Throw if the file does not exist. */
|
|
80
84
|
readFile(path: string): Promise<string>;
|
|
81
|
-
/**
|
|
85
|
+
/** Read exact file bytes. Required when capabilities.binary is enabled. */
|
|
86
|
+
readFileBytes?(path: string): Promise<Uint8Array>;
|
|
87
|
+
/** Write exact file bytes. Required when capabilities.binary is enabled. */
|
|
88
|
+
writeFileBytes?(path: string, content: Uint8Array, mode?: number): Promise<void>;
|
|
89
|
+
/** Writes content to a file, creating parent directories if needed. Throw {@link SessionFsWriteFailure} if a failed write changed the target. */
|
|
82
90
|
writeFile(path: string, content: string, mode?: number): Promise<void>;
|
|
83
91
|
/** Appends content to a file, creating parent directories if needed. */
|
|
84
92
|
appendFile(path: string, content: string, mode?: number): Promise<void>;
|