@github/copilot-sdk 1.0.9-preview.2 → 1.0.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/README.md +29 -6
- package/dist/cjs/client.js +20 -2
- package/dist/cjs/generated/rpc.js +43 -2
- package/dist/cjs/session.js +35 -12
- package/dist/cjs/types.js +12 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +20 -2
- package/dist/generated/rpc.d.ts +304 -18
- package/dist/generated/rpc.js +43 -2
- package/dist/generated/session-events.d.ts +303 -8
- package/dist/index.d.ts +1 -1
- package/dist/session.d.ts +9 -0
- package/dist/session.js +35 -12
- package/dist/types.d.ts +88 -6
- package/dist/types.js +12 -1
- package/docs/agent-author.md +3 -3
- package/docs/examples.md +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ import { CopilotClient, approveAll } from "@github/copilot-sdk";
|
|
|
36
36
|
const client = new CopilotClient();
|
|
37
37
|
await client.start();
|
|
38
38
|
|
|
39
|
-
//
|
|
39
|
+
// approveAll is only valid when managed settings are disabled.
|
|
40
40
|
const session = await client.createSession({
|
|
41
41
|
model: "gpt-5",
|
|
42
42
|
onPermissionRequest: approveAll,
|
|
@@ -131,13 +131,14 @@ Create a new conversation session.
|
|
|
131
131
|
|
|
132
132
|
- `sessionId?: string` - Custom session ID.
|
|
133
133
|
- `model?: string` - Model to use ("gpt-5", "claude-sonnet-4.5", etc.). **Required when using custom provider.**
|
|
134
|
-
- `reasoningEffort?: "low" | "medium" | "high" | "xhigh"` - Reasoning effort level for models that support it. Use `listModels()` to check which models support this option.
|
|
134
|
+
- `reasoningEffort?: "low" | "medium" | "high" | "xhigh" | "max"` - Reasoning effort level for models that support it. Use `listModels()` to check which models support this option.
|
|
135
135
|
- `tools?: Tool[]` - Custom tools exposed to the CLI. Tools without `handler` are declaration-only and must be resolved via pending tool-call RPCs.
|
|
136
136
|
- `systemMessage?: SystemMessageConfig` - System message customization (see below)
|
|
137
137
|
- `infiniteSessions?: InfiniteSessionConfig` - Configure automatic context compaction (see below)
|
|
138
|
+
- `workingDirectory?: string` - Working directory for the session (default: runtime process cwd).
|
|
138
139
|
- `enableSessionStore?: boolean` - Enables the cross-session store for search and retrieval across sessions. When unset in `"copilot-cli"` mode, the runtime default applies (enabled). In `"empty"` mode, defaults to disabled.
|
|
139
140
|
- `provider?: ProviderConfig` - Custom API provider configuration (BYOK - Bring Your Own Key). See [Custom Providers](#custom-providers) section.
|
|
140
|
-
- `onPermissionRequest?: PermissionHandler` - Optional handler called before each tool execution to approve or deny it. When omitted, permission requests are emitted as events and left pending for manual resolution.
|
|
141
|
+
- `onPermissionRequest?: PermissionHandler` - Optional handler called before each tool execution to approve or deny it. When omitted, permission requests are emitted as events and left pending for manual resolution. `approveAll` approves requests when managed settings are disabled and throws when `enableManagedSettings` is true. Custom handlers can inspect `managedApprovalRequired` for human-facing confirmation logic. See [Permission Handling](#permission-handling) section.
|
|
141
142
|
- `onUserInputRequest?: UserInputHandler` - Handler for user input requests from the agent. Enables the `ask_user` tool. See [User Input Requests](#user-input-requests) section.
|
|
142
143
|
- `onElicitationRequest?: ElicitationHandler` - Handler for elicitation requests dispatched by the server. Enables this client to present form-based UI dialogs on behalf of the agent or other session participants. See [Elicitation Requests](#elicitation-requests) section.
|
|
143
144
|
- `hooks?: SessionHooks` - Hook handlers for session lifecycle events. See [Session Hooks](#session-hooks) section.
|
|
@@ -862,7 +863,7 @@ An `onPermissionRequest` handler is optional when you create or resume a session
|
|
|
862
863
|
|
|
863
864
|
### Approve All (simplest)
|
|
864
865
|
|
|
865
|
-
Use the built-in `approveAll` helper
|
|
866
|
+
Use the built-in `approveAll` helper when managed settings are disabled:
|
|
866
867
|
|
|
867
868
|
```typescript
|
|
868
869
|
import { CopilotClient, approveAll } from "@github/copilot-sdk";
|
|
@@ -873,9 +874,11 @@ const session = await client.createSession({
|
|
|
873
874
|
});
|
|
874
875
|
```
|
|
875
876
|
|
|
877
|
+
When `enableManagedSettings` is true for the session, `approveAll` throws. Use a custom handler for managed sessions; request-level `managedApprovalRequired` remains available for human-facing confirmation logic.
|
|
878
|
+
|
|
876
879
|
### Custom Permission Handler
|
|
877
880
|
|
|
878
|
-
Provide your own function to inspect each request and apply custom logic:
|
|
881
|
+
Provide your own function to inspect each request and apply custom logic. Check `managedApprovalRequired` before any automatic approval:
|
|
879
882
|
|
|
880
883
|
```typescript
|
|
881
884
|
import type { PermissionRequest, PermissionRequestResult } from "@github/copilot-sdk";
|
|
@@ -883,6 +886,11 @@ import type { PermissionRequest, PermissionRequestResult } from "@github/copilot
|
|
|
883
886
|
const session = await client.createSession({
|
|
884
887
|
model: "gpt-5",
|
|
885
888
|
onPermissionRequest: (request: PermissionRequest, invocation): PermissionRequestResult => {
|
|
889
|
+
if ("managedApprovalRequired" in request && request.managedApprovalRequired === true) {
|
|
890
|
+
// Leave the request pending for the host's human-facing confirmation flow.
|
|
891
|
+
return { kind: "no-result" };
|
|
892
|
+
}
|
|
893
|
+
|
|
886
894
|
// request.kind — what type of operation is being requested:
|
|
887
895
|
// "shell" — executing a shell command
|
|
888
896
|
// "write" — writing or editing a file
|
|
@@ -920,7 +928,7 @@ The handler must return one of the `PermissionDecision` shapes (or `{ kind: "no-
|
|
|
920
928
|
| `"approve-permanently"` | Allow this request and persist the approval across sessions (currently used for URL domains) | `domain` (URL domain to approve) |
|
|
921
929
|
| `"reject"` | Deny the request | `feedback?` (optional string surfaced to the agent) |
|
|
922
930
|
| `"user-not-available"` | Deny the request because no user is available to confirm it | — |
|
|
923
|
-
| `"no-result"` |
|
|
931
|
+
| `"no-result"` | Suppress this SDK client's response so another connected client can answer the pending request | — |
|
|
924
932
|
|
|
925
933
|
### Resuming Sessions
|
|
926
934
|
|
|
@@ -1101,6 +1109,21 @@ try {
|
|
|
1101
1109
|
}
|
|
1102
1110
|
```
|
|
1103
1111
|
|
|
1112
|
+
## Development
|
|
1113
|
+
|
|
1114
|
+
From the repository root:
|
|
1115
|
+
|
|
1116
|
+
```bash
|
|
1117
|
+
cd test/harness
|
|
1118
|
+
npm ci
|
|
1119
|
+
```
|
|
1120
|
+
|
|
1121
|
+
```bash
|
|
1122
|
+
cd nodejs
|
|
1123
|
+
npm ci
|
|
1124
|
+
npm test
|
|
1125
|
+
```
|
|
1126
|
+
|
|
1104
1127
|
## License
|
|
1105
1128
|
|
|
1106
1129
|
MIT
|
package/dist/cjs/client.js
CHANGED
|
@@ -920,6 +920,10 @@ class CopilotClient {
|
|
|
920
920
|
}
|
|
921
921
|
return {};
|
|
922
922
|
}
|
|
923
|
+
/** Mode-specific default for enableExperimentalMode. */
|
|
924
|
+
experimentalModeForMode(supplied) {
|
|
925
|
+
return this.options.mode === "empty" ? supplied ?? false : supplied;
|
|
926
|
+
}
|
|
923
927
|
/**
|
|
924
928
|
* Returns the systemMessage config to use, adjusted for the current mode.
|
|
925
929
|
* In empty mode we ensure the environment_context section is removed
|
|
@@ -1021,7 +1025,10 @@ class CopilotClient {
|
|
|
1021
1025
|
this.connection,
|
|
1022
1026
|
void 0,
|
|
1023
1027
|
this.onGetTraceContext,
|
|
1024
|
-
{
|
|
1028
|
+
{
|
|
1029
|
+
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1030
|
+
managedSettingsEnabled: config.enableManagedSettings
|
|
1031
|
+
}
|
|
1025
1032
|
);
|
|
1026
1033
|
s.registerTools(config.tools);
|
|
1027
1034
|
s.registerCanvases(config.canvases);
|
|
@@ -1070,6 +1077,7 @@ class CopilotClient {
|
|
|
1070
1077
|
clientName: config.clientName,
|
|
1071
1078
|
reasoningEffort: config.reasoningEffort,
|
|
1072
1079
|
reasoningSummary: config.reasoningSummary,
|
|
1080
|
+
isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
|
|
1073
1081
|
contextTier: config.contextTier,
|
|
1074
1082
|
tools: config.tools?.map((tool) => ({
|
|
1075
1083
|
name: tool.name,
|
|
@@ -1109,10 +1117,12 @@ class CopilotClient {
|
|
|
1109
1117
|
requestUserInput: !!config.onUserInputRequest,
|
|
1110
1118
|
requestElicitation: !!config.onElicitationRequest,
|
|
1111
1119
|
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
1120
|
+
...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
|
|
1112
1121
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
1113
1122
|
requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
|
|
1114
1123
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
1115
1124
|
workingDirectory: config.workingDirectory,
|
|
1125
|
+
additionalDirectories: config.additionalDirectories,
|
|
1116
1126
|
streaming: config.streaming,
|
|
1117
1127
|
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
1118
1128
|
...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
|
|
@@ -1137,6 +1147,7 @@ class CopilotClient {
|
|
|
1137
1147
|
pluginDirectories: config.pluginDirectories,
|
|
1138
1148
|
instructionDirectories: config.instructionDirectories,
|
|
1139
1149
|
disabledSkills: config.disabledSkills,
|
|
1150
|
+
disabledMcpServers: config.disabledMcpServers,
|
|
1140
1151
|
infiniteSessions: config.infiniteSessions,
|
|
1141
1152
|
memory: config.memory,
|
|
1142
1153
|
gitHubToken: config.gitHubToken,
|
|
@@ -1219,7 +1230,10 @@ class CopilotClient {
|
|
|
1219
1230
|
this.connection,
|
|
1220
1231
|
void 0,
|
|
1221
1232
|
this.onGetTraceContext,
|
|
1222
|
-
{
|
|
1233
|
+
{
|
|
1234
|
+
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1235
|
+
managedSettingsEnabled: config.enableManagedSettings
|
|
1236
|
+
}
|
|
1223
1237
|
);
|
|
1224
1238
|
session.registerTools(config.tools);
|
|
1225
1239
|
session.registerCanvases(config.canvases);
|
|
@@ -1273,6 +1287,7 @@ class CopilotClient {
|
|
|
1273
1287
|
model: config.model,
|
|
1274
1288
|
reasoningEffort: config.reasoningEffort,
|
|
1275
1289
|
reasoningSummary: config.reasoningSummary,
|
|
1290
|
+
isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
|
|
1276
1291
|
contextTier: config.contextTier,
|
|
1277
1292
|
systemMessage: wireSystemMessage,
|
|
1278
1293
|
availableTools: toolFilterOptions.availableTools,
|
|
@@ -1313,10 +1328,12 @@ class CopilotClient {
|
|
|
1313
1328
|
requestUserInput: !!config.onUserInputRequest,
|
|
1314
1329
|
requestElicitation: !!config.onElicitationRequest,
|
|
1315
1330
|
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
1331
|
+
...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
|
|
1316
1332
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
1317
1333
|
requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
|
|
1318
1334
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
1319
1335
|
workingDirectory: config.workingDirectory,
|
|
1336
|
+
additionalDirectories: config.additionalDirectories,
|
|
1320
1337
|
configDir: config.configDirectory,
|
|
1321
1338
|
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
1322
1339
|
skipEmbeddingRetrieval: config.skipEmbeddingRetrieval,
|
|
@@ -1341,6 +1358,7 @@ class CopilotClient {
|
|
|
1341
1358
|
pluginDirectories: config.pluginDirectories,
|
|
1342
1359
|
instructionDirectories: config.instructionDirectories,
|
|
1343
1360
|
disabledSkills: config.disabledSkills,
|
|
1361
|
+
disabledMcpServers: config.disabledMcpServers,
|
|
1344
1362
|
infiniteSessions: config.infiniteSessions,
|
|
1345
1363
|
memory: config.memory,
|
|
1346
1364
|
disableResume: config.suppressResumeEvent,
|
|
@@ -171,6 +171,27 @@ function createServerRpc(connection) {
|
|
|
171
171
|
discover: async (params) => connection.sendRequest("mcp.discover", params)
|
|
172
172
|
},
|
|
173
173
|
/** @experimental */
|
|
174
|
+
extensions: {
|
|
175
|
+
/**
|
|
176
|
+
* Discovers user and enabled installed-plugin extensions from persisted Copilot home state, including enablement preferences. Launch-scoped additional plugins are not included.
|
|
177
|
+
*
|
|
178
|
+
* @returns Extensions discovered from persisted Copilot home state and their effective loading mode. Launch-scoped additional plugins are not included.
|
|
179
|
+
*/
|
|
180
|
+
discover: async () => connection.sendRequest("extensions.discover", {}),
|
|
181
|
+
/**
|
|
182
|
+
* Persistently enables extension IDs for future sessions. Active sessions are unchanged; use session.extensions.enable to update them.
|
|
183
|
+
*
|
|
184
|
+
* @param params Source-qualified extension identifiers to persistently enable for future sessions.
|
|
185
|
+
*/
|
|
186
|
+
enable: async (params) => connection.sendRequest("extensions.enable", params),
|
|
187
|
+
/**
|
|
188
|
+
* Persistently disables extension IDs for future sessions. Active sessions are unchanged; use session.extensions.disable to update them.
|
|
189
|
+
*
|
|
190
|
+
* @param params Source-qualified extension identifiers to persistently disable for future sessions.
|
|
191
|
+
*/
|
|
192
|
+
disable: async (params) => connection.sendRequest("extensions.disable", params)
|
|
193
|
+
},
|
|
194
|
+
/** @experimental */
|
|
174
195
|
plugins: {
|
|
175
196
|
/**
|
|
176
197
|
* Lists plugins installed in user/global state.
|
|
@@ -1165,6 +1186,12 @@ function createSessionRpc(connection, sessionId) {
|
|
|
1165
1186
|
* @returns Agents available to the session.
|
|
1166
1187
|
*/
|
|
1167
1188
|
list: async (params) => connection.sendRequest("session.agent.list", { sessionId, ...params }),
|
|
1189
|
+
/**
|
|
1190
|
+
* Sets an in-memory authored prompt override for an available agent. For built-in agents, this replaces only the static base prompt while preserving runtime-owned dynamic prompt composition and behavior. The special `general-purpose` agent is not overrideable. Overrides are not persisted; resumed and forked sessions start without them, so the host must re-apply them.
|
|
1191
|
+
*
|
|
1192
|
+
* @param params An in-memory authored prompt override for an available agent.
|
|
1193
|
+
*/
|
|
1194
|
+
setPrompt: async (params) => connection.sendRequest("session.agent.setPrompt", { sessionId, ...params }),
|
|
1168
1195
|
/**
|
|
1169
1196
|
* Gets the currently selected custom agent for the session.
|
|
1170
1197
|
*
|
|
@@ -1406,6 +1433,12 @@ function createSessionRpc(connection, sessionId) {
|
|
|
1406
1433
|
* @returns Indicates whether the pending MCP OAuth response was accepted.
|
|
1407
1434
|
*/
|
|
1408
1435
|
handlePendingRequest: async (params) => connection.sendRequest("session.mcp.oauth.handlePendingRequest", { sessionId, ...params }),
|
|
1436
|
+
/**
|
|
1437
|
+
* Notifies the session that MCP OAuth authentication succeeded and updated credentials were persisted, so cached tool definitions can be refreshed.
|
|
1438
|
+
*
|
|
1439
|
+
* @param params Identifies the MCP server whose persisted OAuth credentials were updated.
|
|
1440
|
+
*/
|
|
1441
|
+
authenticationStateChanged: async (params) => connection.sendRequest("session.mcp.oauth.authenticationStateChanged", { sessionId, ...params }),
|
|
1409
1442
|
/**
|
|
1410
1443
|
* Starts OAuth authentication for a remote MCP server.
|
|
1411
1444
|
*
|
|
@@ -2129,7 +2162,15 @@ function createSessionRpc(connection, sessionId) {
|
|
|
2129
2162
|
*
|
|
2130
2163
|
* @returns Markdown summary of the conversation context (empty when not available).
|
|
2131
2164
|
*/
|
|
2132
|
-
summarizeForHandoff: async () => connection.sendRequest("session.history.summarizeForHandoff", { sessionId })
|
|
2165
|
+
summarizeForHandoff: async () => connection.sendRequest("session.history.summarizeForHandoff", { sessionId }),
|
|
2166
|
+
/**
|
|
2167
|
+
* Clears the session's conversation history, keeping only system and developer messages, and seeds the fresh context window with a first user message. Must be called from inside a tool handler: the clear has to drop the results of the tool calls its wipe orphans, and it rejects when no tool call is in flight.
|
|
2168
|
+
*
|
|
2169
|
+
* @param params Parameters for clearing the conversation and seeding the window that replaces it.
|
|
2170
|
+
*
|
|
2171
|
+
* @returns What a successful clear removed. A clear that could not be applied rejects instead of reporting a count.
|
|
2172
|
+
*/
|
|
2173
|
+
clearContext: async (params) => connection.sendRequest("session.history.clearContext", { sessionId, ...params })
|
|
2133
2174
|
},
|
|
2134
2175
|
/** @experimental */
|
|
2135
2176
|
queue: {
|
|
@@ -2207,7 +2248,7 @@ function createSessionRpc(connection, sessionId) {
|
|
|
2207
2248
|
/** @experimental */
|
|
2208
2249
|
eventLog: {
|
|
2209
2250
|
/**
|
|
2210
|
-
* Reads a batch of session events from a cursor, optionally waiting for new events.
|
|
2251
|
+
* Reads a batch of session events from a cursor, optionally waiting for new events. Supports tail-first reads via `direction: backward`.
|
|
2211
2252
|
*
|
|
2212
2253
|
* @param params Cursor, batch size, and optional long-poll/filter parameters for reading session events.
|
|
2213
2254
|
*
|
package/dist/cjs/session.js
CHANGED
|
@@ -224,6 +224,7 @@ class CopilotSession {
|
|
|
224
224
|
this._workspacePath = _workspacePath;
|
|
225
225
|
this.traceContextProvider = traceContextProvider;
|
|
226
226
|
this.mcpAuthHandler = options?.mcpAuthHandler;
|
|
227
|
+
this.managedSettingsEnabled = options?.managedSettingsEnabled === true;
|
|
227
228
|
}
|
|
228
229
|
sessionId;
|
|
229
230
|
connection;
|
|
@@ -246,6 +247,7 @@ class CopilotSession {
|
|
|
246
247
|
transformCallbacks;
|
|
247
248
|
_rpc = null;
|
|
248
249
|
traceContextProvider;
|
|
250
|
+
managedSettingsEnabled;
|
|
249
251
|
_capabilities = {};
|
|
250
252
|
openCanvasInstances = [];
|
|
251
253
|
disconnected = false;
|
|
@@ -272,7 +274,7 @@ class CopilotSession {
|
|
|
272
274
|
limits: options?.limits
|
|
273
275
|
}
|
|
274
276
|
});
|
|
275
|
-
return
|
|
277
|
+
return this.settleFactoryRun(envelope);
|
|
276
278
|
}),
|
|
277
279
|
resume: (async (runId, options) => {
|
|
278
280
|
let response;
|
|
@@ -290,7 +292,7 @@ class CopilotSession {
|
|
|
290
292
|
}
|
|
291
293
|
throw error;
|
|
292
294
|
}
|
|
293
|
-
return
|
|
295
|
+
return this.settleFactoryRun(response.run);
|
|
294
296
|
}),
|
|
295
297
|
getRun: async (runId) => toPublicFactoryRunResult(await this.rpc.factory.getRun({ runId })),
|
|
296
298
|
waitForRun: (runId, options) => this.waitForFactoryRun(runId, options?.signal),
|
|
@@ -299,6 +301,19 @@ class CopilotSession {
|
|
|
299
301
|
getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
|
|
300
302
|
cancel: async (runId) => toPublicFactoryRunResult(await this.rpc.factory.cancel({ runId }))
|
|
301
303
|
};
|
|
304
|
+
/**
|
|
305
|
+
* Resolve a start/resume envelope into the terminal envelope callers expect.
|
|
306
|
+
*
|
|
307
|
+
* The CLI may answer `session.factory.run` and `session.factory.resume`
|
|
308
|
+
* before the run settles, so a non-terminal envelope is followed by a wait
|
|
309
|
+
* on the run's terminal state.
|
|
310
|
+
*/
|
|
311
|
+
settleFactoryRun(envelope) {
|
|
312
|
+
if ((0, import_factory.isFactoryRunTerminal)(envelope.status)) {
|
|
313
|
+
return Promise.resolve(toPublicFactoryRunResult(envelope));
|
|
314
|
+
}
|
|
315
|
+
return this.waitForFactoryRun(envelope.runId);
|
|
316
|
+
}
|
|
302
317
|
/**
|
|
303
318
|
* Resolve when a factory run reaches a terminal status.
|
|
304
319
|
*
|
|
@@ -434,22 +449,20 @@ class CopilotSession {
|
|
|
434
449
|
async sendAndWait(optionsOrPrompt, timeout) {
|
|
435
450
|
const options = typeof optionsOrPrompt === "string" ? { prompt: optionsOrPrompt } : optionsOrPrompt;
|
|
436
451
|
const effectiveTimeout = timeout ?? 6e4;
|
|
437
|
-
let
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
resolveIdle = resolve;
|
|
441
|
-
rejectWithError = reject;
|
|
452
|
+
let resolveOutcome;
|
|
453
|
+
const outcomePromise = new Promise((resolve) => {
|
|
454
|
+
resolveOutcome = resolve;
|
|
442
455
|
});
|
|
443
456
|
let lastAssistantMessage;
|
|
444
457
|
const unsubscribe = this.on((event) => {
|
|
445
458
|
if (event.type === "assistant.message") {
|
|
446
459
|
lastAssistantMessage = event;
|
|
447
460
|
} else if (event.type === "session.idle") {
|
|
448
|
-
|
|
461
|
+
resolveOutcome({ kind: "idle" });
|
|
449
462
|
} else if (event.type === "session.error") {
|
|
450
463
|
const error = new Error(event.data.message);
|
|
451
464
|
error.stack = event.data.stack;
|
|
452
|
-
|
|
465
|
+
resolveOutcome({ kind: "error", error });
|
|
453
466
|
}
|
|
454
467
|
});
|
|
455
468
|
let timeoutId;
|
|
@@ -465,7 +478,10 @@ class CopilotSession {
|
|
|
465
478
|
effectiveTimeout
|
|
466
479
|
);
|
|
467
480
|
});
|
|
468
|
-
await Promise.race([
|
|
481
|
+
const outcome = await Promise.race([outcomePromise, timeoutPromise]);
|
|
482
|
+
if (outcome.kind === "error") {
|
|
483
|
+
throw outcome.error;
|
|
484
|
+
}
|
|
469
485
|
return lastAssistantMessage;
|
|
470
486
|
} finally {
|
|
471
487
|
if (timeoutId !== void 0) {
|
|
@@ -704,7 +720,8 @@ class CopilotSession {
|
|
|
704
720
|
async _executePermissionAndRespond(requestId, permissionRequest) {
|
|
705
721
|
try {
|
|
706
722
|
const result = await this.permissionHandler(permissionRequest, {
|
|
707
|
-
sessionId: this.sessionId
|
|
723
|
+
sessionId: this.sessionId,
|
|
724
|
+
managedSettingsEnabled: this.managedSettingsEnabled
|
|
708
725
|
});
|
|
709
726
|
if (result.kind === "no-result") {
|
|
710
727
|
return;
|
|
@@ -713,10 +730,15 @@ class CopilotSession {
|
|
|
713
730
|
return;
|
|
714
731
|
}
|
|
715
732
|
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
716
|
-
} catch (
|
|
733
|
+
} catch (error) {
|
|
717
734
|
if (this.disconnected) {
|
|
718
735
|
return;
|
|
719
736
|
}
|
|
737
|
+
console.error("Permission handler or response delivery failed", {
|
|
738
|
+
sessionId: this.sessionId,
|
|
739
|
+
requestId,
|
|
740
|
+
error
|
|
741
|
+
});
|
|
720
742
|
try {
|
|
721
743
|
await this.rpc.permissions.handlePendingPermissionRequest({
|
|
722
744
|
requestId,
|
|
@@ -1361,6 +1383,7 @@ class CopilotSession {
|
|
|
1361
1383
|
postToolUse: this.hooks.onPostToolUse,
|
|
1362
1384
|
postToolUseFailure: this.hooks.onPostToolUseFailure,
|
|
1363
1385
|
userPromptSubmitted: this.hooks.onUserPromptSubmitted,
|
|
1386
|
+
userPromptTransformed: this.hooks.onUserPromptTransformed,
|
|
1364
1387
|
sessionStart: this.hooks.onSessionStart,
|
|
1365
1388
|
sessionEnd: this.hooks.onSessionEnd,
|
|
1366
1389
|
errorOccurred: this.hooks.onErrorOccurred,
|
package/dist/cjs/types.js
CHANGED
|
@@ -141,7 +141,18 @@ const SYSTEM_MESSAGE_SECTIONS = {
|
|
|
141
141
|
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
|
-
const approveAll = () =>
|
|
144
|
+
const approveAll = (request, invocation) => {
|
|
145
|
+
if (invocation.managedSettingsEnabled) {
|
|
146
|
+
throw new Error("approveAll cannot be used when managed settings are enabled");
|
|
147
|
+
}
|
|
148
|
+
if ("managedApprovalRequired" in request) {
|
|
149
|
+
const managedApprovalRequired = request.managedApprovalRequired;
|
|
150
|
+
if (managedApprovalRequired !== void 0 && managedApprovalRequired !== false) {
|
|
151
|
+
return { kind: "no-result" };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { kind: "approve-once" };
|
|
155
|
+
};
|
|
145
156
|
const defaultJoinSessionPermissionHandler = () => ({
|
|
146
157
|
kind: "no-result"
|
|
147
158
|
});
|
package/dist/client.d.ts
CHANGED
|
@@ -180,6 +180,8 @@ export declare class CopilotClient {
|
|
|
180
180
|
forceStop(): Promise<void>;
|
|
181
181
|
/** Mode-specific defaults spread under the caller's config (app values win). */
|
|
182
182
|
private configDefaultsForMode;
|
|
183
|
+
/** Mode-specific default for enableExperimentalMode. */
|
|
184
|
+
private experimentalModeForMode;
|
|
183
185
|
/**
|
|
184
186
|
* Returns the systemMessage config to use, adjusted for the current mode.
|
|
185
187
|
* In empty mode we ensure the environment_context section is removed
|
package/dist/client.js
CHANGED
|
@@ -897,6 +897,10 @@ class CopilotClient {
|
|
|
897
897
|
}
|
|
898
898
|
return {};
|
|
899
899
|
}
|
|
900
|
+
/** Mode-specific default for enableExperimentalMode. */
|
|
901
|
+
experimentalModeForMode(supplied) {
|
|
902
|
+
return this.options.mode === "empty" ? supplied ?? false : supplied;
|
|
903
|
+
}
|
|
900
904
|
/**
|
|
901
905
|
* Returns the systemMessage config to use, adjusted for the current mode.
|
|
902
906
|
* In empty mode we ensure the environment_context section is removed
|
|
@@ -998,7 +1002,10 @@ class CopilotClient {
|
|
|
998
1002
|
this.connection,
|
|
999
1003
|
void 0,
|
|
1000
1004
|
this.onGetTraceContext,
|
|
1001
|
-
{
|
|
1005
|
+
{
|
|
1006
|
+
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1007
|
+
managedSettingsEnabled: config.enableManagedSettings
|
|
1008
|
+
}
|
|
1002
1009
|
);
|
|
1003
1010
|
s.registerTools(config.tools);
|
|
1004
1011
|
s.registerCanvases(config.canvases);
|
|
@@ -1047,6 +1054,7 @@ class CopilotClient {
|
|
|
1047
1054
|
clientName: config.clientName,
|
|
1048
1055
|
reasoningEffort: config.reasoningEffort,
|
|
1049
1056
|
reasoningSummary: config.reasoningSummary,
|
|
1057
|
+
isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
|
|
1050
1058
|
contextTier: config.contextTier,
|
|
1051
1059
|
tools: config.tools?.map((tool) => ({
|
|
1052
1060
|
name: tool.name,
|
|
@@ -1086,10 +1094,12 @@ class CopilotClient {
|
|
|
1086
1094
|
requestUserInput: !!config.onUserInputRequest,
|
|
1087
1095
|
requestElicitation: !!config.onElicitationRequest,
|
|
1088
1096
|
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
1097
|
+
...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
|
|
1089
1098
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
1090
1099
|
requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
|
|
1091
1100
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
1092
1101
|
workingDirectory: config.workingDirectory,
|
|
1102
|
+
additionalDirectories: config.additionalDirectories,
|
|
1093
1103
|
streaming: config.streaming,
|
|
1094
1104
|
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
1095
1105
|
...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
|
|
@@ -1114,6 +1124,7 @@ class CopilotClient {
|
|
|
1114
1124
|
pluginDirectories: config.pluginDirectories,
|
|
1115
1125
|
instructionDirectories: config.instructionDirectories,
|
|
1116
1126
|
disabledSkills: config.disabledSkills,
|
|
1127
|
+
disabledMcpServers: config.disabledMcpServers,
|
|
1117
1128
|
infiniteSessions: config.infiniteSessions,
|
|
1118
1129
|
memory: config.memory,
|
|
1119
1130
|
gitHubToken: config.gitHubToken,
|
|
@@ -1196,7 +1207,10 @@ class CopilotClient {
|
|
|
1196
1207
|
this.connection,
|
|
1197
1208
|
void 0,
|
|
1198
1209
|
this.onGetTraceContext,
|
|
1199
|
-
{
|
|
1210
|
+
{
|
|
1211
|
+
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1212
|
+
managedSettingsEnabled: config.enableManagedSettings
|
|
1213
|
+
}
|
|
1200
1214
|
);
|
|
1201
1215
|
session.registerTools(config.tools);
|
|
1202
1216
|
session.registerCanvases(config.canvases);
|
|
@@ -1250,6 +1264,7 @@ class CopilotClient {
|
|
|
1250
1264
|
model: config.model,
|
|
1251
1265
|
reasoningEffort: config.reasoningEffort,
|
|
1252
1266
|
reasoningSummary: config.reasoningSummary,
|
|
1267
|
+
isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
|
|
1253
1268
|
contextTier: config.contextTier,
|
|
1254
1269
|
systemMessage: wireSystemMessage,
|
|
1255
1270
|
availableTools: toolFilterOptions.availableTools,
|
|
@@ -1290,10 +1305,12 @@ class CopilotClient {
|
|
|
1290
1305
|
requestUserInput: !!config.onUserInputRequest,
|
|
1291
1306
|
requestElicitation: !!config.onElicitationRequest,
|
|
1292
1307
|
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
1308
|
+
...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
|
|
1293
1309
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
1294
1310
|
requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
|
|
1295
1311
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
1296
1312
|
workingDirectory: config.workingDirectory,
|
|
1313
|
+
additionalDirectories: config.additionalDirectories,
|
|
1297
1314
|
configDir: config.configDirectory,
|
|
1298
1315
|
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
1299
1316
|
skipEmbeddingRetrieval: config.skipEmbeddingRetrieval,
|
|
@@ -1318,6 +1335,7 @@ class CopilotClient {
|
|
|
1318
1335
|
pluginDirectories: config.pluginDirectories,
|
|
1319
1336
|
instructionDirectories: config.instructionDirectories,
|
|
1320
1337
|
disabledSkills: config.disabledSkills,
|
|
1338
|
+
disabledMcpServers: config.disabledMcpServers,
|
|
1321
1339
|
infiniteSessions: config.infiniteSessions,
|
|
1322
1340
|
memory: config.memory,
|
|
1323
1341
|
disableResume: config.suppressResumeEvent,
|