@github/copilot-sdk 1.0.13-preview.1 → 1.0.13-preview.3
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 +20 -2
- package/dist/cjs/client.js +97 -4
- package/dist/cjs/generated/rpc.js +29 -1
- package/dist/cjs/session.js +29 -5
- package/dist/client.d.ts +5 -0
- package/dist/client.js +97 -4
- package/dist/extension.d.ts +1 -1
- package/dist/factory.d.ts +35 -1
- package/dist/generated/rpc.d.ts +83 -11
- package/dist/generated/rpc.js +29 -1
- package/dist/generated/session-events.d.ts +1081 -235
- package/dist/index.d.ts +2 -2
- package/dist/session.d.ts +1 -0
- package/dist/session.js +29 -5
- package/dist/types.d.ts +43 -5
- package/docs/factories.md +25 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -137,12 +137,26 @@ Create a new conversation session.
|
|
|
137
137
|
- `infiniteSessions?: InfiniteSessionConfig` - Configure automatic context compaction (see below)
|
|
138
138
|
- `workingDirectory?: string` - Working directory for the session (default: runtime process cwd).
|
|
139
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.
|
|
140
|
+
- `gitHubTokenProvider?: GitHubTokenProvider` - Acquires rotating, session-scoped GitHub tokens. Token results require a positive `expiresIn` value in seconds remaining when the callback completes; production tokens typically last eight hours. Cannot be combined with `gitHubToken`.
|
|
140
141
|
- `provider?: ProviderConfig` - Custom API provider configuration (BYOK - Bring Your Own Key). See [Custom Providers](#custom-providers) section.
|
|
141
142
|
- `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.
|
|
142
|
-
- `onUserInputRequest?: UserInputHandler` - Handler for
|
|
143
|
+
- `onUserInputRequest?: UserInputHandler` - Handler for legacy question-and-answer requests from the agent. Enables the legacy `ask_user` tool. See [User Input Requests](#user-input-requests) section.
|
|
144
|
+
- `askUserVariant?: "legacy" | "elicitation"` - Selects the model-facing `ask_user` tool shape when creating or cold-resuming a session. Defaults to `"legacy"`; use `"elicitation"` with `onElicitationRequest`.
|
|
143
145
|
- `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.
|
|
144
146
|
- `hooks?: SessionHooks` - Hook handlers for session lifecycle events. See [Session Hooks](#session-hooks) section.
|
|
145
147
|
|
|
148
|
+
```typescript
|
|
149
|
+
const session = await client.createSession({
|
|
150
|
+
gitHubTokenProvider: async ({ host }) => ({
|
|
151
|
+
kind: "token",
|
|
152
|
+
accessToken: await acquireTokenForHost(host),
|
|
153
|
+
expiresIn: 8 * 60 * 60,
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Initial acquisition runs during session creation or resume. Cancellation, provider errors, and invalid token responses reject that operation instead of falling back to ambient authentication. Idle sessions refresh only before their next credential-consuming operation; there is no background refresh timer.
|
|
159
|
+
|
|
146
160
|
##### `resumeSession(sessionId: string, config?: ResumeSessionConfig): Promise<CopilotSession>`
|
|
147
161
|
|
|
148
162
|
Resume an existing session. Returns the session with `workspacePath` populated if infinite sessions were enabled.
|
|
@@ -946,7 +960,7 @@ To let a specific custom tool bypass the permission prompt entirely, set `skipPe
|
|
|
946
960
|
|
|
947
961
|
## User Input Requests
|
|
948
962
|
|
|
949
|
-
Enable the
|
|
963
|
+
Enable the legacy question-and-answer `ask_user` tool by providing an `onUserInputRequest` handler:
|
|
950
964
|
|
|
951
965
|
```typescript
|
|
952
966
|
const session = await client.createSession({
|
|
@@ -978,6 +992,7 @@ Register an `onElicitationRequest` handler to let your client act as an elicitat
|
|
|
978
992
|
const session = await client.createSession({
|
|
979
993
|
model: "gpt-5",
|
|
980
994
|
onPermissionRequest: approveAll,
|
|
995
|
+
askUserVariant: "elicitation",
|
|
981
996
|
onElicitationRequest: async (context) => {
|
|
982
997
|
// context.sessionId - Session that triggered the request
|
|
983
998
|
// context.message - Description of what information is needed
|
|
@@ -999,6 +1014,9 @@ const session = await client.createSession({
|
|
|
999
1014
|
console.log(session.capabilities.ui?.elicitation); // true
|
|
1000
1015
|
```
|
|
1001
1016
|
|
|
1017
|
+
Set `askUserVariant: "elicitation"` to expose the structured form as the model's
|
|
1018
|
+
`ask_user` tool. Omit it to retain the legacy SDK behavior.
|
|
1019
|
+
|
|
1002
1020
|
When `onElicitationRequest` is provided, the SDK sends `requestElicitation: true` during session create/resume, which enables `session.capabilities.ui.elicitation` on the session.
|
|
1003
1021
|
|
|
1004
1022
|
In multi-client scenarios:
|
package/dist/cjs/client.js
CHANGED
|
@@ -294,6 +294,7 @@ class CopilotClient {
|
|
|
294
294
|
builtinPluginDirectories = [];
|
|
295
295
|
onGitHubTelemetry;
|
|
296
296
|
clientGlobalHandlers = {};
|
|
297
|
+
githubTokenProviders = /* @__PURE__ */ new Map();
|
|
297
298
|
/**
|
|
298
299
|
* Typed server-scoped RPC methods.
|
|
299
300
|
* @throws Error if the client is not connected
|
|
@@ -551,8 +552,53 @@ class CopilotClient {
|
|
|
551
552
|
}
|
|
552
553
|
};
|
|
553
554
|
}
|
|
555
|
+
handlers.gitHubToken = {
|
|
556
|
+
getToken: (params) => this.acquireGitHubToken(params)
|
|
557
|
+
};
|
|
554
558
|
this.clientGlobalHandlers = handlers;
|
|
555
559
|
}
|
|
560
|
+
async acquireGitHubToken(params) {
|
|
561
|
+
const registration = this.githubTokenProviders.get(params.registrationId);
|
|
562
|
+
if (!registration) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
`No GitHub token provider registered for registration ID "${params.registrationId}"`
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
return await registration.provider({
|
|
568
|
+
host: params.host,
|
|
569
|
+
sessionId: params.sessionId ?? registration.sessionId,
|
|
570
|
+
reason: params.reason
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
registerGitHubTokenProvider(provider, sessionId) {
|
|
574
|
+
if (!provider) {
|
|
575
|
+
return void 0;
|
|
576
|
+
}
|
|
577
|
+
const registrationId = (0, import_node_crypto.randomUUID)();
|
|
578
|
+
this.githubTokenProviders.set(registrationId, { provider, sessionId, committed: false });
|
|
579
|
+
return registrationId;
|
|
580
|
+
}
|
|
581
|
+
assignGitHubTokenProvider(registrationId, sessionId) {
|
|
582
|
+
if (!registrationId) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const registration = this.githubTokenProviders.get(registrationId);
|
|
586
|
+
if (registration) {
|
|
587
|
+
registration.sessionId = sessionId;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
commitGitHubTokenProvider(sessionId, registrationId) {
|
|
591
|
+
for (const [candidateId, registration2] of this.githubTokenProviders) {
|
|
592
|
+
if (registration2.sessionId === sessionId && registration2.committed) {
|
|
593
|
+
this.githubTokenProviders.delete(candidateId);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
const registration = registrationId ? this.githubTokenProviders.get(registrationId) : void 0;
|
|
597
|
+
if (registration) {
|
|
598
|
+
registration.sessionId = sessionId;
|
|
599
|
+
registration.committed = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
556
602
|
/**
|
|
557
603
|
* Starts the CLI server and establishes a connection.
|
|
558
604
|
*
|
|
@@ -669,6 +715,7 @@ class CopilotClient {
|
|
|
669
715
|
session._markDisconnected();
|
|
670
716
|
}
|
|
671
717
|
this.sessions.clear();
|
|
718
|
+
this.githubTokenProviders.clear();
|
|
672
719
|
if (this.connection && (this.cliProcess || this.ffiHost) && !this.isExternalServer) {
|
|
673
720
|
const runtimeShutdownStart = Date.now();
|
|
674
721
|
const shutdownPromise = this.rpc.runtime.shutdown();
|
|
@@ -823,6 +870,7 @@ class CopilotClient {
|
|
|
823
870
|
session._markDisconnected();
|
|
824
871
|
}
|
|
825
872
|
this.sessions.clear();
|
|
873
|
+
this.githubTokenProviders.clear();
|
|
826
874
|
if (this.messageWriter) {
|
|
827
875
|
this.messageWriter.suppressWriteErrors = true;
|
|
828
876
|
}
|
|
@@ -1026,6 +1074,9 @@ class CopilotClient {
|
|
|
1026
1074
|
}
|
|
1027
1075
|
}
|
|
1028
1076
|
async createSession(config) {
|
|
1077
|
+
if (config.gitHubToken !== void 0 && config.gitHubTokenProvider !== void 0) {
|
|
1078
|
+
throw new Error("gitHubToken and gitHubTokenProvider are mutually exclusive");
|
|
1079
|
+
}
|
|
1029
1080
|
if (!this.connection) {
|
|
1030
1081
|
await this.start();
|
|
1031
1082
|
}
|
|
@@ -1036,6 +1087,11 @@ class CopilotClient {
|
|
|
1036
1087
|
const callerSessionId = config.sessionId;
|
|
1037
1088
|
const useServerGeneratedId = config.cloud != null && callerSessionId == null;
|
|
1038
1089
|
const localSessionId = useServerGeneratedId ? void 0 : callerSessionId ?? (0, import_node_crypto.randomUUID)();
|
|
1090
|
+
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
1091
|
+
const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
|
|
1092
|
+
config.gitHubTokenProvider,
|
|
1093
|
+
localSessionId
|
|
1094
|
+
);
|
|
1039
1095
|
const {
|
|
1040
1096
|
wireProvider: bearerWireProvider,
|
|
1041
1097
|
wireProviders: bearerWireProviders,
|
|
@@ -1052,7 +1108,10 @@ class CopilotClient {
|
|
|
1052
1108
|
this.onGetTraceContext,
|
|
1053
1109
|
{
|
|
1054
1110
|
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1055
|
-
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0
|
|
1111
|
+
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0,
|
|
1112
|
+
onDisconnected: gitHubTokenProviderRegistrationId === void 0 ? void 0 : () => this.githubTokenProviders.delete(
|
|
1113
|
+
gitHubTokenProviderRegistrationId
|
|
1114
|
+
)
|
|
1056
1115
|
}
|
|
1057
1116
|
);
|
|
1058
1117
|
s.registerTools(config.tools);
|
|
@@ -1090,10 +1149,16 @@ class CopilotClient {
|
|
|
1090
1149
|
let session;
|
|
1091
1150
|
let registeredId;
|
|
1092
1151
|
if (localSessionId !== void 0) {
|
|
1093
|
-
|
|
1094
|
-
|
|
1152
|
+
try {
|
|
1153
|
+
session = initializeSession(localSessionId);
|
|
1154
|
+
registeredId = localSessionId;
|
|
1155
|
+
} catch (error) {
|
|
1156
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1157
|
+
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
1158
|
+
}
|
|
1159
|
+
throw error;
|
|
1160
|
+
}
|
|
1095
1161
|
}
|
|
1096
|
-
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
1097
1162
|
try {
|
|
1098
1163
|
const response = await this.connection.sendRequest("session.create", {
|
|
1099
1164
|
...await (0, import_telemetry.getTraceContext)(this.onGetTraceContext),
|
|
@@ -1143,6 +1208,7 @@ class CopilotClient {
|
|
|
1143
1208
|
requestPermission: !!config.onPermissionRequest,
|
|
1144
1209
|
requestUserInput: !!config.onUserInputRequest,
|
|
1145
1210
|
requestElicitation: !!config.onElicitationRequest,
|
|
1211
|
+
askUserVariant: config.askUserVariant,
|
|
1146
1212
|
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
1147
1213
|
...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
|
|
1148
1214
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
@@ -1178,6 +1244,7 @@ class CopilotClient {
|
|
|
1178
1244
|
infiniteSessions: config.infiniteSessions,
|
|
1179
1245
|
memory: config.memory,
|
|
1180
1246
|
gitHubToken: config.gitHubToken,
|
|
1247
|
+
gitHubTokenProviderRegistrationId,
|
|
1181
1248
|
remoteSession: config.remoteSession,
|
|
1182
1249
|
cloud: config.cloud,
|
|
1183
1250
|
expAssignments: config.expAssignments,
|
|
@@ -1201,6 +1268,7 @@ class CopilotClient {
|
|
|
1201
1268
|
session = initializeSession(returnedSessionId);
|
|
1202
1269
|
registeredId = returnedSessionId;
|
|
1203
1270
|
}
|
|
1271
|
+
this.assignGitHubTokenProvider(gitHubTokenProviderRegistrationId, returnedSessionId);
|
|
1204
1272
|
if (config.onMcpAuthRequest) {
|
|
1205
1273
|
await this.connection.sendRequest("session.eventLog.registerInterest", {
|
|
1206
1274
|
sessionId: returnedSessionId,
|
|
@@ -1210,10 +1278,14 @@ class CopilotClient {
|
|
|
1210
1278
|
session["_workspacePath"] = workspacePath;
|
|
1211
1279
|
session.setCapabilities(capabilities);
|
|
1212
1280
|
await this.updateSessionOptionsForMode(session, config);
|
|
1281
|
+
this.commitGitHubTokenProvider(returnedSessionId, gitHubTokenProviderRegistrationId);
|
|
1213
1282
|
} catch (e) {
|
|
1214
1283
|
if (registeredId !== void 0) {
|
|
1215
1284
|
this.sessions.delete(registeredId);
|
|
1216
1285
|
}
|
|
1286
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1287
|
+
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
1288
|
+
}
|
|
1217
1289
|
throw e;
|
|
1218
1290
|
}
|
|
1219
1291
|
return session;
|
|
@@ -1250,6 +1322,9 @@ class CopilotClient {
|
|
|
1250
1322
|
return this.resumeSessionInternal(sessionId, config, factories, extensionOptions);
|
|
1251
1323
|
}
|
|
1252
1324
|
async resumeSessionInternal(sessionId, config, factories, extensionOptions) {
|
|
1325
|
+
if (config.gitHubToken !== void 0 && config.gitHubTokenProvider !== void 0) {
|
|
1326
|
+
throw new Error("gitHubToken and gitHubTokenProvider are mutually exclusive");
|
|
1327
|
+
}
|
|
1253
1328
|
if (!this.connection) {
|
|
1254
1329
|
await this.start();
|
|
1255
1330
|
}
|
|
@@ -1307,6 +1382,15 @@ class CopilotClient {
|
|
|
1307
1382
|
this.sessions.set(sessionId, session);
|
|
1308
1383
|
this.setupSessionFs(session, config);
|
|
1309
1384
|
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
1385
|
+
const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
|
|
1386
|
+
config.gitHubTokenProvider,
|
|
1387
|
+
sessionId
|
|
1388
|
+
);
|
|
1389
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1390
|
+
session._setOnDisconnected(
|
|
1391
|
+
() => this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId)
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1310
1394
|
try {
|
|
1311
1395
|
const response = await this.connection.sendRequest("session.resume", {
|
|
1312
1396
|
...await (0, import_telemetry.getTraceContext)(this.onGetTraceContext),
|
|
@@ -1357,6 +1441,7 @@ class CopilotClient {
|
|
|
1357
1441
|
requestPermission: config.onPermissionRequest !== import_types.defaultJoinSessionPermissionHandler,
|
|
1358
1442
|
requestUserInput: !!config.onUserInputRequest,
|
|
1359
1443
|
requestElicitation: !!config.onElicitationRequest,
|
|
1444
|
+
askUserVariant: config.askUserVariant,
|
|
1360
1445
|
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
1361
1446
|
...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
|
|
1362
1447
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
@@ -1394,6 +1479,7 @@ class CopilotClient {
|
|
|
1394
1479
|
disableResume: config.suppressResumeEvent,
|
|
1395
1480
|
continuePendingWork: config.continuePendingWork,
|
|
1396
1481
|
gitHubToken: config.gitHubToken,
|
|
1482
|
+
gitHubTokenProviderRegistrationId,
|
|
1397
1483
|
remoteSession: config.remoteSession,
|
|
1398
1484
|
openCanvases: config.openCanvases,
|
|
1399
1485
|
expAssignments: config.expAssignments,
|
|
@@ -1423,8 +1509,12 @@ class CopilotClient {
|
|
|
1423
1509
|
});
|
|
1424
1510
|
}
|
|
1425
1511
|
await this.updateSessionOptionsForMode(session, config);
|
|
1512
|
+
this.commitGitHubTokenProvider(sessionId, gitHubTokenProviderRegistrationId);
|
|
1426
1513
|
} catch (e) {
|
|
1427
1514
|
this.sessions.delete(sessionId);
|
|
1515
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1516
|
+
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
1517
|
+
}
|
|
1428
1518
|
throw e;
|
|
1429
1519
|
}
|
|
1430
1520
|
return session;
|
|
@@ -1613,7 +1703,9 @@ class CopilotClient {
|
|
|
1613
1703
|
if (!success) {
|
|
1614
1704
|
throw new Error(`Failed to delete session ${sessionId}: ${error || "Unknown error"}`);
|
|
1615
1705
|
}
|
|
1706
|
+
const session = this.sessions.get(sessionId);
|
|
1616
1707
|
this.sessions.delete(sessionId);
|
|
1708
|
+
session?._runOnDisconnected();
|
|
1617
1709
|
}
|
|
1618
1710
|
/**
|
|
1619
1711
|
* List all available sessions.
|
|
@@ -2161,6 +2253,7 @@ stderr: ${stderrOutput}`
|
|
|
2161
2253
|
);
|
|
2162
2254
|
this.connection.onClose(() => {
|
|
2163
2255
|
this.state = "disconnected";
|
|
2256
|
+
this.githubTokenProviders.clear();
|
|
2164
2257
|
});
|
|
2165
2258
|
this.connection.onError((_error) => {
|
|
2166
2259
|
this.state = "disconnected";
|
|
@@ -200,7 +200,7 @@ function createServerRpc(connection) {
|
|
|
200
200
|
disable: async (params) => connection.sendRequest("extensions.disable", params)
|
|
201
201
|
},
|
|
202
202
|
/**
|
|
203
|
-
* Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime
|
|
203
|
+
* Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime uses its built-in extension launcher.
|
|
204
204
|
*
|
|
205
205
|
* @experimental
|
|
206
206
|
*/
|
|
@@ -773,6 +773,15 @@ function createSessionRpc(connection, sessionId) {
|
|
|
773
773
|
* @experimental
|
|
774
774
|
*/
|
|
775
775
|
sendMessages: async (params) => connection.sendRequest("session.sendMessages", { sessionId, ...params }),
|
|
776
|
+
/** @experimental */
|
|
777
|
+
sandbox: {
|
|
778
|
+
/**
|
|
779
|
+
* Returns whether managed policy requires sandbox enforcement and whether an enforcement failure has permanently blocked the session.
|
|
780
|
+
*
|
|
781
|
+
* @returns Managed sandbox enforcement state for a session.
|
|
782
|
+
*/
|
|
783
|
+
getEnforcementStatus: async () => connection.sendRequest("session.sandbox.getEnforcementStatus", { sessionId })
|
|
784
|
+
},
|
|
776
785
|
/**
|
|
777
786
|
* Aborts the current agent turn.
|
|
778
787
|
*
|
|
@@ -2540,6 +2549,25 @@ function createInternalSessionRpc(connection, sessionId) {
|
|
|
2540
2549
|
}
|
|
2541
2550
|
},
|
|
2542
2551
|
/** @experimental */
|
|
2552
|
+
factory: {
|
|
2553
|
+
/**
|
|
2554
|
+
* Internal tool-originated factory invocation.
|
|
2555
|
+
*
|
|
2556
|
+
* @param params Internal parameters for invoking a registered factory from a tool.
|
|
2557
|
+
*
|
|
2558
|
+
* @returns Complete current or terminal factory run envelope.
|
|
2559
|
+
*/
|
|
2560
|
+
runFromTool: async (params) => connection.sendRequest("session.factory.runFromTool", { sessionId, ...params }),
|
|
2561
|
+
/**
|
|
2562
|
+
* Internal tool-originated factory resume.
|
|
2563
|
+
*
|
|
2564
|
+
* @param params Internal parameters for resuming a factory run from a tool.
|
|
2565
|
+
*
|
|
2566
|
+
* @returns Resolved persisted factory identity and resumed run envelope.
|
|
2567
|
+
*/
|
|
2568
|
+
resumeFromTool: async (params) => connection.sendRequest("session.factory.resumeFromTool", { sessionId, ...params })
|
|
2569
|
+
},
|
|
2570
|
+
/** @experimental */
|
|
2543
2571
|
model: {
|
|
2544
2572
|
/**
|
|
2545
2573
|
* Resolves and applies organization-managed and repository model overlays.
|
package/dist/cjs/session.js
CHANGED
|
@@ -241,6 +241,7 @@ class CopilotSession {
|
|
|
241
241
|
this.traceContextProvider = traceContextProvider;
|
|
242
242
|
this.mcpAuthHandler = options?.mcpAuthHandler;
|
|
243
243
|
this.managedSettingsEnabled = options?.managedSettingsEnabled === true;
|
|
244
|
+
this.onDisconnected = options?.onDisconnected;
|
|
244
245
|
}
|
|
245
246
|
sessionId;
|
|
246
247
|
connection;
|
|
@@ -267,6 +268,7 @@ class CopilotSession {
|
|
|
267
268
|
_capabilities = {};
|
|
268
269
|
openCanvasInstances = [];
|
|
269
270
|
disconnected = false;
|
|
271
|
+
onDisconnected;
|
|
270
272
|
/** @internal Client session API handlers, populated by CopilotClient during create/resume. */
|
|
271
273
|
clientSessionApis = {};
|
|
272
274
|
/**
|
|
@@ -281,14 +283,18 @@ class CopilotSession {
|
|
|
281
283
|
const name = typeof nameOrHandle === "string" ? nameOrHandle : (0, import_factory.getFactoryDefinition)(nameOrHandle).meta.name;
|
|
282
284
|
if (options?.resumeFromRunId !== void 0) {
|
|
283
285
|
return this.factory.resume(options.resumeFromRunId, {
|
|
284
|
-
limits: options.limits
|
|
286
|
+
limits: options.limits,
|
|
287
|
+
notifyOnComplete: options.notifyOnComplete,
|
|
288
|
+
logPhaseNames: options.logPhaseNames
|
|
285
289
|
});
|
|
286
290
|
}
|
|
287
291
|
const envelope = await this.rpc.factory.run({
|
|
288
292
|
name,
|
|
289
293
|
args: options?.args === void 0 ? {} : options.args,
|
|
290
294
|
options: {
|
|
291
|
-
limits: options?.limits
|
|
295
|
+
limits: options?.limits,
|
|
296
|
+
notifyOnComplete: options?.notifyOnComplete,
|
|
297
|
+
logPhaseNames: options?.logPhaseNames
|
|
292
298
|
}
|
|
293
299
|
});
|
|
294
300
|
return this.settleFactoryRun(envelope);
|
|
@@ -299,7 +305,9 @@ class CopilotSession {
|
|
|
299
305
|
try {
|
|
300
306
|
response = await this.rpc.factory.resume({
|
|
301
307
|
runId,
|
|
302
|
-
limits: options?.limits
|
|
308
|
+
limits: options?.limits,
|
|
309
|
+
notifyOnComplete: options?.notifyOnComplete,
|
|
310
|
+
logPhaseNames: options?.logPhaseNames
|
|
303
311
|
});
|
|
304
312
|
} catch (error) {
|
|
305
313
|
if (error instanceof import_node.ResponseError && typeof error.data === "object" && error.data !== null) {
|
|
@@ -314,7 +322,10 @@ class CopilotSession {
|
|
|
314
322
|
}),
|
|
315
323
|
getRun: async (runId) => this.rpc.factory.getRun({ runId }),
|
|
316
324
|
waitForRun: (runId, options) => this.waitForFactoryRun(runId, options?.signal),
|
|
317
|
-
listRuns: async () =>
|
|
325
|
+
listRuns: (async (options) => {
|
|
326
|
+
const page = await this.rpc.factory.listRuns(options ?? {});
|
|
327
|
+
return options === void 0 ? page.runs : page;
|
|
328
|
+
}),
|
|
318
329
|
getRunDetail: (runId) => this.rpc.factory.getRunDetail({ runId }),
|
|
319
330
|
getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
|
|
320
331
|
cancel: async (runId) => this.rpc.factory.cancel({ runId })
|
|
@@ -475,7 +486,7 @@ class CopilotSession {
|
|
|
475
486
|
const unsubscribe = this.on((event) => {
|
|
476
487
|
if (event.type === "assistant.message") {
|
|
477
488
|
lastAssistantMessage = event;
|
|
478
|
-
} else if (event.type === "session.idle") {
|
|
489
|
+
} else if (event.type === "session.idle" && event.data.mode !== "autopilot") {
|
|
479
490
|
resolveOutcome({ kind: "idle" });
|
|
480
491
|
} else if (event.type === "session.error") {
|
|
481
492
|
const error = new Error(event.data.message);
|
|
@@ -510,7 +521,11 @@ class CopilotSession {
|
|
|
510
521
|
}
|
|
511
522
|
/** @internal */
|
|
512
523
|
_markDisconnected() {
|
|
524
|
+
if (this.disconnected) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
513
527
|
this.disconnected = true;
|
|
528
|
+
this._runOnDisconnected();
|
|
514
529
|
this.eventHandlers.clear();
|
|
515
530
|
this.typedEventHandlers.clear();
|
|
516
531
|
this.toolHandlers.clear();
|
|
@@ -530,6 +545,15 @@ class CopilotSession {
|
|
|
530
545
|
this.factoryAbortControllers.clear();
|
|
531
546
|
this.transformCallbacks?.clear();
|
|
532
547
|
}
|
|
548
|
+
/** @internal */
|
|
549
|
+
_runOnDisconnected() {
|
|
550
|
+
this.onDisconnected?.();
|
|
551
|
+
this.onDisconnected = void 0;
|
|
552
|
+
}
|
|
553
|
+
/** @internal */
|
|
554
|
+
_setOnDisconnected(callback) {
|
|
555
|
+
this.onDisconnected = callback;
|
|
556
|
+
}
|
|
533
557
|
on(eventTypeOrHandler, handler) {
|
|
534
558
|
if (typeof eventTypeOrHandler === "string" && handler) {
|
|
535
559
|
const eventType = eventTypeOrHandler;
|
package/dist/client.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare class CopilotClient {
|
|
|
40
40
|
private builtinPluginDirectories;
|
|
41
41
|
private onGitHubTelemetry?;
|
|
42
42
|
private clientGlobalHandlers;
|
|
43
|
+
private githubTokenProviders;
|
|
43
44
|
/**
|
|
44
45
|
* Typed server-scoped RPC methods.
|
|
45
46
|
* @throws Error if the client is not connected
|
|
@@ -96,6 +97,10 @@ export declare class CopilotClient {
|
|
|
96
97
|
private validateSessionFsConfig;
|
|
97
98
|
private setupSessionFs;
|
|
98
99
|
private setupClientGlobalHandlers;
|
|
100
|
+
private acquireGitHubToken;
|
|
101
|
+
private registerGitHubTokenProvider;
|
|
102
|
+
private assignGitHubTokenProvider;
|
|
103
|
+
private commitGitHubTokenProvider;
|
|
99
104
|
/**
|
|
100
105
|
* Starts the CLI server and establishes a connection.
|
|
101
106
|
*
|