@github/copilot-sdk 1.0.13-preview.0 → 1.0.13-preview.2
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 +13 -0
- package/dist/cjs/client.js +100 -5
- package/dist/cjs/generated/rpc.js +25 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/session.js +16 -1
- package/dist/cjs/types.js +8 -0
- package/dist/client.d.ts +7 -1
- package/dist/client.js +100 -5
- package/dist/generated/rpc.d.ts +259 -19
- package/dist/generated/rpc.js +25 -1
- package/dist/generated/session-events.d.ts +1009 -53
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/session.d.ts +1 -0
- package/dist/session.js +16 -1
- package/dist/types.d.ts +49 -9
- package/dist/types.js +7 -0
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -271,6 +271,7 @@ class CopilotClient {
|
|
|
271
271
|
builtinPluginDirectories = [];
|
|
272
272
|
onGitHubTelemetry;
|
|
273
273
|
clientGlobalHandlers = {};
|
|
274
|
+
githubTokenProviders = /* @__PURE__ */ new Map();
|
|
274
275
|
/**
|
|
275
276
|
* Typed server-scoped RPC methods.
|
|
276
277
|
* @throws Error if the client is not connected
|
|
@@ -528,8 +529,53 @@ class CopilotClient {
|
|
|
528
529
|
}
|
|
529
530
|
};
|
|
530
531
|
}
|
|
532
|
+
handlers.gitHubToken = {
|
|
533
|
+
getToken: (params) => this.acquireGitHubToken(params)
|
|
534
|
+
};
|
|
531
535
|
this.clientGlobalHandlers = handlers;
|
|
532
536
|
}
|
|
537
|
+
async acquireGitHubToken(params) {
|
|
538
|
+
const registration = this.githubTokenProviders.get(params.registrationId);
|
|
539
|
+
if (!registration) {
|
|
540
|
+
throw new Error(
|
|
541
|
+
`No GitHub token provider registered for registration ID "${params.registrationId}"`
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
return await registration.provider({
|
|
545
|
+
host: params.host,
|
|
546
|
+
sessionId: params.sessionId ?? registration.sessionId,
|
|
547
|
+
reason: params.reason
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
registerGitHubTokenProvider(provider, sessionId) {
|
|
551
|
+
if (!provider) {
|
|
552
|
+
return void 0;
|
|
553
|
+
}
|
|
554
|
+
const registrationId = randomUUID();
|
|
555
|
+
this.githubTokenProviders.set(registrationId, { provider, sessionId, committed: false });
|
|
556
|
+
return registrationId;
|
|
557
|
+
}
|
|
558
|
+
assignGitHubTokenProvider(registrationId, sessionId) {
|
|
559
|
+
if (!registrationId) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const registration = this.githubTokenProviders.get(registrationId);
|
|
563
|
+
if (registration) {
|
|
564
|
+
registration.sessionId = sessionId;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
commitGitHubTokenProvider(sessionId, registrationId) {
|
|
568
|
+
for (const [candidateId, registration2] of this.githubTokenProviders) {
|
|
569
|
+
if (registration2.sessionId === sessionId && registration2.committed) {
|
|
570
|
+
this.githubTokenProviders.delete(candidateId);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const registration = registrationId ? this.githubTokenProviders.get(registrationId) : void 0;
|
|
574
|
+
if (registration) {
|
|
575
|
+
registration.sessionId = sessionId;
|
|
576
|
+
registration.committed = true;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
533
579
|
/**
|
|
534
580
|
* Starts the CLI server and establishes a connection.
|
|
535
581
|
*
|
|
@@ -646,6 +692,7 @@ class CopilotClient {
|
|
|
646
692
|
session._markDisconnected();
|
|
647
693
|
}
|
|
648
694
|
this.sessions.clear();
|
|
695
|
+
this.githubTokenProviders.clear();
|
|
649
696
|
if (this.connection && (this.cliProcess || this.ffiHost) && !this.isExternalServer) {
|
|
650
697
|
const runtimeShutdownStart = Date.now();
|
|
651
698
|
const shutdownPromise = this.rpc.runtime.shutdown();
|
|
@@ -800,6 +847,7 @@ class CopilotClient {
|
|
|
800
847
|
session._markDisconnected();
|
|
801
848
|
}
|
|
802
849
|
this.sessions.clear();
|
|
850
|
+
this.githubTokenProviders.clear();
|
|
803
851
|
if (this.messageWriter) {
|
|
804
852
|
this.messageWriter.suppressWriteErrors = true;
|
|
805
853
|
}
|
|
@@ -965,7 +1013,8 @@ class CopilotClient {
|
|
|
965
1013
|
*
|
|
966
1014
|
* In empty mode, defaults the four overridable feature flags to safe values
|
|
967
1015
|
* (caller values from `config` win). `installedPlugins=[]` is unconditional
|
|
968
|
-
* in empty mode
|
|
1016
|
+
* in empty mode. `includedBuiltinSkills` defaults to `[]`, but callers can
|
|
1017
|
+
* explicitly allow selected runtime-bundled skills.
|
|
969
1018
|
*/
|
|
970
1019
|
async updateSessionOptionsForMode(session, config) {
|
|
971
1020
|
const patch = {};
|
|
@@ -975,6 +1024,7 @@ class CopilotClient {
|
|
|
975
1024
|
patch.coauthorEnabled = config.coauthorEnabled ?? false;
|
|
976
1025
|
patch.manageScheduleEnabled = config.manageScheduleEnabled ?? false;
|
|
977
1026
|
patch.installedPlugins = [];
|
|
1027
|
+
patch.includedBuiltinSkills = config.includedBuiltinSkills ?? [];
|
|
978
1028
|
} else {
|
|
979
1029
|
if (config.skipCustomInstructions !== void 0)
|
|
980
1030
|
patch.skipCustomInstructions = config.skipCustomInstructions;
|
|
@@ -984,6 +1034,8 @@ class CopilotClient {
|
|
|
984
1034
|
patch.coauthorEnabled = config.coauthorEnabled;
|
|
985
1035
|
if (config.manageScheduleEnabled !== void 0)
|
|
986
1036
|
patch.manageScheduleEnabled = config.manageScheduleEnabled;
|
|
1037
|
+
if (config.includedBuiltinSkills !== void 0)
|
|
1038
|
+
patch.includedBuiltinSkills = config.includedBuiltinSkills;
|
|
987
1039
|
}
|
|
988
1040
|
if (Object.keys(patch).length === 0) {
|
|
989
1041
|
return;
|
|
@@ -999,6 +1051,9 @@ class CopilotClient {
|
|
|
999
1051
|
}
|
|
1000
1052
|
}
|
|
1001
1053
|
async createSession(config) {
|
|
1054
|
+
if (config.gitHubToken !== void 0 && config.gitHubTokenProvider !== void 0) {
|
|
1055
|
+
throw new Error("gitHubToken and gitHubTokenProvider are mutually exclusive");
|
|
1056
|
+
}
|
|
1002
1057
|
if (!this.connection) {
|
|
1003
1058
|
await this.start();
|
|
1004
1059
|
}
|
|
@@ -1009,6 +1064,11 @@ class CopilotClient {
|
|
|
1009
1064
|
const callerSessionId = config.sessionId;
|
|
1010
1065
|
const useServerGeneratedId = config.cloud != null && callerSessionId == null;
|
|
1011
1066
|
const localSessionId = useServerGeneratedId ? void 0 : callerSessionId ?? randomUUID();
|
|
1067
|
+
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
1068
|
+
const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
|
|
1069
|
+
config.gitHubTokenProvider,
|
|
1070
|
+
localSessionId
|
|
1071
|
+
);
|
|
1012
1072
|
const {
|
|
1013
1073
|
wireProvider: bearerWireProvider,
|
|
1014
1074
|
wireProviders: bearerWireProviders,
|
|
@@ -1025,7 +1085,10 @@ class CopilotClient {
|
|
|
1025
1085
|
this.onGetTraceContext,
|
|
1026
1086
|
{
|
|
1027
1087
|
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1028
|
-
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0
|
|
1088
|
+
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0,
|
|
1089
|
+
onDisconnected: gitHubTokenProviderRegistrationId === void 0 ? void 0 : () => this.githubTokenProviders.delete(
|
|
1090
|
+
gitHubTokenProviderRegistrationId
|
|
1091
|
+
)
|
|
1029
1092
|
}
|
|
1030
1093
|
);
|
|
1031
1094
|
s.registerTools(config.tools);
|
|
@@ -1063,10 +1126,16 @@ class CopilotClient {
|
|
|
1063
1126
|
let session;
|
|
1064
1127
|
let registeredId;
|
|
1065
1128
|
if (localSessionId !== void 0) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1129
|
+
try {
|
|
1130
|
+
session = initializeSession(localSessionId);
|
|
1131
|
+
registeredId = localSessionId;
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1134
|
+
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
1135
|
+
}
|
|
1136
|
+
throw error;
|
|
1137
|
+
}
|
|
1068
1138
|
}
|
|
1069
|
-
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
1070
1139
|
try {
|
|
1071
1140
|
const response = await this.connection.sendRequest("session.create", {
|
|
1072
1141
|
...await getTraceContext(this.onGetTraceContext),
|
|
@@ -1151,6 +1220,7 @@ class CopilotClient {
|
|
|
1151
1220
|
infiniteSessions: config.infiniteSessions,
|
|
1152
1221
|
memory: config.memory,
|
|
1153
1222
|
gitHubToken: config.gitHubToken,
|
|
1223
|
+
gitHubTokenProviderRegistrationId,
|
|
1154
1224
|
remoteSession: config.remoteSession,
|
|
1155
1225
|
cloud: config.cloud,
|
|
1156
1226
|
expAssignments: config.expAssignments,
|
|
@@ -1174,6 +1244,7 @@ class CopilotClient {
|
|
|
1174
1244
|
session = initializeSession(returnedSessionId);
|
|
1175
1245
|
registeredId = returnedSessionId;
|
|
1176
1246
|
}
|
|
1247
|
+
this.assignGitHubTokenProvider(gitHubTokenProviderRegistrationId, returnedSessionId);
|
|
1177
1248
|
if (config.onMcpAuthRequest) {
|
|
1178
1249
|
await this.connection.sendRequest("session.eventLog.registerInterest", {
|
|
1179
1250
|
sessionId: returnedSessionId,
|
|
@@ -1183,10 +1254,14 @@ class CopilotClient {
|
|
|
1183
1254
|
session["_workspacePath"] = workspacePath;
|
|
1184
1255
|
session.setCapabilities(capabilities);
|
|
1185
1256
|
await this.updateSessionOptionsForMode(session, config);
|
|
1257
|
+
this.commitGitHubTokenProvider(returnedSessionId, gitHubTokenProviderRegistrationId);
|
|
1186
1258
|
} catch (e) {
|
|
1187
1259
|
if (registeredId !== void 0) {
|
|
1188
1260
|
this.sessions.delete(registeredId);
|
|
1189
1261
|
}
|
|
1262
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1263
|
+
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
1264
|
+
}
|
|
1190
1265
|
throw e;
|
|
1191
1266
|
}
|
|
1192
1267
|
return session;
|
|
@@ -1223,6 +1298,9 @@ class CopilotClient {
|
|
|
1223
1298
|
return this.resumeSessionInternal(sessionId, config, factories, extensionOptions);
|
|
1224
1299
|
}
|
|
1225
1300
|
async resumeSessionInternal(sessionId, config, factories, extensionOptions) {
|
|
1301
|
+
if (config.gitHubToken !== void 0 && config.gitHubTokenProvider !== void 0) {
|
|
1302
|
+
throw new Error("gitHubToken and gitHubTokenProvider are mutually exclusive");
|
|
1303
|
+
}
|
|
1226
1304
|
if (!this.connection) {
|
|
1227
1305
|
await this.start();
|
|
1228
1306
|
}
|
|
@@ -1280,6 +1358,15 @@ class CopilotClient {
|
|
|
1280
1358
|
this.sessions.set(sessionId, session);
|
|
1281
1359
|
this.setupSessionFs(session, config);
|
|
1282
1360
|
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
1361
|
+
const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
|
|
1362
|
+
config.gitHubTokenProvider,
|
|
1363
|
+
sessionId
|
|
1364
|
+
);
|
|
1365
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1366
|
+
session._setOnDisconnected(
|
|
1367
|
+
() => this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId)
|
|
1368
|
+
);
|
|
1369
|
+
}
|
|
1283
1370
|
try {
|
|
1284
1371
|
const response = await this.connection.sendRequest("session.resume", {
|
|
1285
1372
|
...await getTraceContext(this.onGetTraceContext),
|
|
@@ -1367,6 +1454,7 @@ class CopilotClient {
|
|
|
1367
1454
|
disableResume: config.suppressResumeEvent,
|
|
1368
1455
|
continuePendingWork: config.continuePendingWork,
|
|
1369
1456
|
gitHubToken: config.gitHubToken,
|
|
1457
|
+
gitHubTokenProviderRegistrationId,
|
|
1370
1458
|
remoteSession: config.remoteSession,
|
|
1371
1459
|
openCanvases: config.openCanvases,
|
|
1372
1460
|
expAssignments: config.expAssignments,
|
|
@@ -1396,8 +1484,12 @@ class CopilotClient {
|
|
|
1396
1484
|
});
|
|
1397
1485
|
}
|
|
1398
1486
|
await this.updateSessionOptionsForMode(session, config);
|
|
1487
|
+
this.commitGitHubTokenProvider(sessionId, gitHubTokenProviderRegistrationId);
|
|
1399
1488
|
} catch (e) {
|
|
1400
1489
|
this.sessions.delete(sessionId);
|
|
1490
|
+
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
1491
|
+
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
1492
|
+
}
|
|
1401
1493
|
throw e;
|
|
1402
1494
|
}
|
|
1403
1495
|
return session;
|
|
@@ -1586,7 +1678,9 @@ class CopilotClient {
|
|
|
1586
1678
|
if (!success) {
|
|
1587
1679
|
throw new Error(`Failed to delete session ${sessionId}: ${error || "Unknown error"}`);
|
|
1588
1680
|
}
|
|
1681
|
+
const session = this.sessions.get(sessionId);
|
|
1589
1682
|
this.sessions.delete(sessionId);
|
|
1683
|
+
session?._runOnDisconnected();
|
|
1590
1684
|
}
|
|
1591
1685
|
/**
|
|
1592
1686
|
* List all available sessions.
|
|
@@ -2134,6 +2228,7 @@ stderr: ${stderrOutput}`
|
|
|
2134
2228
|
);
|
|
2135
2229
|
this.connection.onClose(() => {
|
|
2136
2230
|
this.state = "disconnected";
|
|
2231
|
+
this.githubTokenProviders.clear();
|
|
2137
2232
|
});
|
|
2138
2233
|
this.connection.onError((_error) => {
|
|
2139
2234
|
this.state = "disconnected";
|