@github/copilot-sdk 1.0.17-preview.3 → 1.0.17-preview.5

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/dist/client.js CHANGED
@@ -32,6 +32,7 @@ import { ToolSet } from "./toolSet.js";
32
32
  import { defaultJoinSessionPermissionHandler } from "./types.js";
33
33
  const MIN_PROTOCOL_VERSION = 3;
34
34
  const RUNTIME_SHUTDOWN_TIMEOUT_MS = 1e4;
35
+ const CLOUD_SESSION_CLEANUP_TIMEOUT_MS = 1e4;
35
36
  function createMessageConnection(reader, writer) {
36
37
  let dispatch;
37
38
  let finishDrain;
@@ -560,6 +561,11 @@ class CopilotClient {
560
561
  "SessionFsConfig declares capabilities.sqlite but the provider does not implement sqlite."
561
562
  );
562
563
  }
564
+ if (this.sessionFsConfig.capabilities?.binary && (!provider.readFileBytes || !provider.writeFileBytes)) {
565
+ throw new Error(
566
+ "SessionFsConfig declares capabilities.binary but the provider does not implement readFileBytes and writeFileBytes."
567
+ );
568
+ }
563
569
  session.clientSessionApis.sessionFs = createSessionFsAdapter(provider);
564
570
  }
565
571
  setupClientGlobalHandlers() {
@@ -1243,12 +1249,13 @@ class CopilotClient {
1243
1249
  if (config.onEvent) {
1244
1250
  s.on(config.onEvent);
1245
1251
  }
1246
- this.sessions.set(sessionId, s);
1247
1252
  this.setupSessionFs(s, config);
1253
+ this.sessions.set(sessionId, s);
1248
1254
  return s;
1249
1255
  };
1250
1256
  let session;
1251
1257
  let registeredId;
1258
+ let uninitializedCloudSessionId;
1252
1259
  if (localSessionId !== void 0) {
1253
1260
  try {
1254
1261
  session = initializeSession(localSessionId);
@@ -1371,7 +1378,9 @@ class CopilotClient {
1371
1378
  );
1372
1379
  }
1373
1380
  if (session === void 0) {
1381
+ uninitializedCloudSessionId = returnedSessionId;
1374
1382
  session = initializeSession(returnedSessionId);
1383
+ uninitializedCloudSessionId = void 0;
1375
1384
  registeredId = returnedSessionId;
1376
1385
  }
1377
1386
  this.assignGitHubTokenProvider(gitHubTokenProviderRegistrationId, returnedSessionId);
@@ -1393,6 +1402,20 @@ class CopilotClient {
1393
1402
  if (gitHubTokenProviderRegistrationId !== void 0) {
1394
1403
  this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
1395
1404
  }
1405
+ if (uninitializedCloudSessionId !== void 0) {
1406
+ try {
1407
+ await withTimeout(
1408
+ this.deleteSession(uninitializedCloudSessionId),
1409
+ CLOUD_SESSION_CLEANUP_TIMEOUT_MS,
1410
+ `session.delete timed out after ${CLOUD_SESSION_CLEANUP_TIMEOUT_MS}ms`
1411
+ );
1412
+ } catch (cleanupError) {
1413
+ throw new AggregateError(
1414
+ [e, cleanupError],
1415
+ "Failed to initialize and delete cloud session"
1416
+ );
1417
+ }
1418
+ }
1396
1419
  throw e;
1397
1420
  }
1398
1421
  for (const entry of this.hostHandoffs.values()) {
@@ -1492,8 +1515,8 @@ class CopilotClient {
1492
1515
  if (config.onEvent) {
1493
1516
  session.on(config.onEvent);
1494
1517
  }
1495
- this.sessions.set(sessionId, session);
1496
1518
  this.setupSessionFs(session, config);
1519
+ this.sessions.set(sessionId, session);
1497
1520
  const toolFilterOptions = this.resolveToolFilterOptions(config);
1498
1521
  const gitHubTokenProviderRegistrationId = this.registerGitHubTokenProvider(
1499
1522
  config.gitHubTokenProvider,