@github/copilot-sdk 0.2.2 → 0.3.0-preview.1

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
@@ -13,7 +13,9 @@ import {
13
13
  import { createServerRpc, registerClientSessionApiHandlers } from "./generated/rpc.js";
14
14
  import { getSdkProtocolVersion } from "./sdkProtocolVersion.js";
15
15
  import { CopilotSession, NO_RESULT_PERMISSION_V2_ERROR } from "./session.js";
16
+ import { createSessionFsAdapter } from "./sessionFsProvider.js";
16
17
  import { getTraceContext } from "./telemetry.js";
18
+ import { defaultJoinSessionPermissionHandler } from "./types.js";
17
19
  const MIN_PROTOCOL_VERSION = 2;
18
20
  function isZodSchema(value) {
19
21
  return value != null && typeof value === "object" && "toJSONSchema" in value && typeof value.toJSONSchema === "function";
@@ -74,6 +76,7 @@ function getBundledCliPath() {
74
76
  );
75
77
  }
76
78
  class CopilotClient {
79
+ cliStartTimeout = null;
77
80
  cliProcess = null;
78
81
  connection = null;
79
82
  socket = null;
@@ -141,9 +144,9 @@ class CopilotClient {
141
144
  "isChildProcess must be used in conjunction with useStdio and not with cliUrl"
142
145
  );
143
146
  }
144
- if (options.cliUrl && (options.githubToken || options.useLoggedInUser !== void 0)) {
147
+ if (options.cliUrl && (options.gitHubToken || options.useLoggedInUser !== void 0)) {
145
148
  throw new Error(
146
- "githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
149
+ "gitHubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
147
150
  );
148
151
  }
149
152
  if (options.sessionFs) {
@@ -175,10 +178,11 @@ class CopilotClient {
175
178
  autoStart: options.autoStart ?? true,
176
179
  autoRestart: false,
177
180
  env: effectiveEnv,
178
- githubToken: options.githubToken,
179
- // Default useLoggedInUser to false when githubToken is provided, otherwise true
180
- useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
181
- telemetry: options.telemetry
181
+ gitHubToken: options.gitHubToken,
182
+ // Default useLoggedInUser to false when gitHubToken is provided, otherwise true
183
+ useLoggedInUser: options.useLoggedInUser ?? (options.gitHubToken ? false : true),
184
+ telemetry: options.telemetry,
185
+ sessionIdleTimeoutSeconds: options.sessionIdleTimeoutSeconds ?? 0
182
186
  };
183
187
  }
184
188
  /**
@@ -344,6 +348,10 @@ class CopilotClient {
344
348
  }
345
349
  this.cliProcess = null;
346
350
  }
351
+ if (this.cliStartTimeout) {
352
+ clearTimeout(this.cliStartTimeout);
353
+ this.cliStartTimeout = null;
354
+ }
347
355
  this.state = "disconnected";
348
356
  this.actualPort = null;
349
357
  this.stderrBuffer = "";
@@ -401,6 +409,10 @@ class CopilotClient {
401
409
  }
402
410
  this.cliProcess = null;
403
411
  }
412
+ if (this.cliStartTimeout) {
413
+ clearTimeout(this.cliStartTimeout);
414
+ this.cliStartTimeout = null;
415
+ }
404
416
  this.state = "disconnected";
405
417
  this.actualPort = null;
406
418
  this.stderrBuffer = "";
@@ -479,7 +491,9 @@ class CopilotClient {
479
491
  this.sessions.set(sessionId, session);
480
492
  if (this.sessionFsConfig) {
481
493
  if (config.createSessionFsHandler) {
482
- session.clientSessionApis.sessionFs = config.createSessionFsHandler(session);
494
+ session.clientSessionApis.sessionFs = createSessionFsAdapter(
495
+ config.createSessionFsHandler(session)
496
+ );
483
497
  } else {
484
498
  throw new Error(
485
499
  "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
@@ -515,15 +529,18 @@ class CopilotClient {
515
529
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
516
530
  workingDirectory: config.workingDirectory,
517
531
  streaming: config.streaming,
532
+ includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
518
533
  mcpServers: config.mcpServers,
519
534
  envValueMode: "direct",
520
535
  customAgents: config.customAgents,
536
+ defaultAgent: config.defaultAgent,
521
537
  agent: config.agent,
522
538
  configDir: config.configDir,
523
539
  enableConfigDiscovery: config.enableConfigDiscovery,
524
540
  skillDirectories: config.skillDirectories,
525
541
  disabledSkills: config.disabledSkills,
526
- infiniteSessions: config.infiniteSessions
542
+ infiniteSessions: config.infiniteSessions,
543
+ gitHubToken: config.gitHubToken
527
544
  });
528
545
  const { workspacePath, capabilities } = response;
529
546
  session["_workspacePath"] = workspacePath;
@@ -601,7 +618,9 @@ class CopilotClient {
601
618
  this.sessions.set(sessionId, session);
602
619
  if (this.sessionFsConfig) {
603
620
  if (config.createSessionFsHandler) {
604
- session.clientSessionApis.sessionFs = config.createSessionFsHandler(session);
621
+ session.clientSessionApis.sessionFs = createSessionFsAdapter(
622
+ config.createSessionFsHandler(session)
623
+ );
605
624
  } else {
606
625
  throw new Error(
607
626
  "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
@@ -631,7 +650,7 @@ class CopilotClient {
631
650
  })),
632
651
  provider: config.provider,
633
652
  modelCapabilities: config.modelCapabilities,
634
- requestPermission: true,
653
+ requestPermission: config.onPermissionRequest !== defaultJoinSessionPermissionHandler,
635
654
  requestUserInput: !!config.onUserInputRequest,
636
655
  requestElicitation: !!config.onElicitationRequest,
637
656
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
@@ -639,14 +658,17 @@ class CopilotClient {
639
658
  configDir: config.configDir,
640
659
  enableConfigDiscovery: config.enableConfigDiscovery,
641
660
  streaming: config.streaming,
661
+ includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
642
662
  mcpServers: config.mcpServers,
643
663
  envValueMode: "direct",
644
664
  customAgents: config.customAgents,
665
+ defaultAgent: config.defaultAgent,
645
666
  agent: config.agent,
646
667
  skillDirectories: config.skillDirectories,
647
668
  disabledSkills: config.disabledSkills,
648
669
  infiniteSessions: config.infiniteSessions,
649
- disableResume: config.disableResume
670
+ disableResume: config.disableResume,
671
+ gitHubToken: config.gitHubToken
650
672
  });
651
673
  const { workspacePath, capabilities } = response;
652
674
  session["_workspacePath"] = workspacePath;
@@ -743,6 +765,22 @@ class CopilotClient {
743
765
  const result = await this.connection.sendRequest("models.list", {});
744
766
  const response = result;
745
767
  models = response.models;
768
+ for (const model of models) {
769
+ const m = model;
770
+ if (!m.capabilities) {
771
+ m.capabilities = {
772
+ supports: {},
773
+ limits: { max_context_window_tokens: 0 }
774
+ };
775
+ } else {
776
+ if (!m.capabilities.supports) m.capabilities.supports = {};
777
+ if (!m.capabilities.limits) {
778
+ m.capabilities.limits = { max_context_window_tokens: 0 };
779
+ } else if (m.capabilities.limits.max_context_window_tokens === void 0) {
780
+ m.capabilities.limits.max_context_window_tokens = 0;
781
+ }
782
+ }
783
+ }
746
784
  }
747
785
  this.modelsCache = [...models];
748
786
  return [...models];
@@ -980,16 +1018,22 @@ class CopilotClient {
980
1018
  } else if (this.options.port > 0) {
981
1019
  args.push("--port", this.options.port.toString());
982
1020
  }
983
- if (this.options.githubToken) {
1021
+ if (this.options.gitHubToken) {
984
1022
  args.push("--auth-token-env", "COPILOT_SDK_AUTH_TOKEN");
985
1023
  }
986
1024
  if (!this.options.useLoggedInUser) {
987
1025
  args.push("--no-auto-login");
988
1026
  }
1027
+ if (this.options.sessionIdleTimeoutSeconds !== void 0 && this.options.sessionIdleTimeoutSeconds > 0) {
1028
+ args.push(
1029
+ "--session-idle-timeout",
1030
+ this.options.sessionIdleTimeoutSeconds.toString()
1031
+ );
1032
+ }
989
1033
  const envWithoutNodeDebug = { ...this.options.env };
990
1034
  delete envWithoutNodeDebug.NODE_DEBUG;
991
- if (this.options.githubToken) {
992
- envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
1035
+ if (this.options.gitHubToken) {
1036
+ envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.gitHubToken;
993
1037
  }
994
1038
  if (!this.options.cliPath) {
995
1039
  throw new Error(
@@ -1113,7 +1157,7 @@ stderr: ${stderrOutput}`
1113
1157
  }
1114
1158
  }
1115
1159
  });
1116
- setTimeout(() => {
1160
+ this.cliStartTimeout = setTimeout(() => {
1117
1161
  if (!resolved) {
1118
1162
  resolved = true;
1119
1163
  reject(new Error("Timeout waiting for CLI server to start"));
@@ -1370,7 +1414,7 @@ stderr: ${stderrOutput}`
1370
1414
  }
1371
1415
  return {
1372
1416
  result: {
1373
- kind: "denied-no-approval-rule-and-could-not-request-from-user"
1417
+ kind: "user-not-available"
1374
1418
  }
1375
1419
  };
1376
1420
  }
@@ -1,5 +1,5 @@
1
1
  import type { CopilotSession } from "./session.js";
2
- import type { PermissionHandler, ResumeSessionConfig } from "./types.js";
2
+ import { type PermissionHandler, type ResumeSessionConfig } from "./types.js";
3
3
  export type JoinSessionConfig = Omit<ResumeSessionConfig, "onPermissionRequest"> & {
4
4
  onPermissionRequest?: PermissionHandler;
5
5
  };
package/dist/extension.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CopilotClient } from "./client.js";
2
- const defaultJoinSessionPermissionHandler = () => ({
3
- kind: "no-result"
4
- });
2
+ import {
3
+ defaultJoinSessionPermissionHandler
4
+ } from "./types.js";
5
5
  async function joinSession(config = {}) {
6
6
  const sessionId = process.env.SESSION_ID;
7
7
  if (!sessionId) {