@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/README.md CHANGED
@@ -86,8 +86,8 @@ new CopilotClient(options?: CopilotClientOptions)
86
86
  - `useStdio?: boolean` - Use stdio transport instead of TCP (default: true)
87
87
  - `logLevel?: string` - Log level (default: "info")
88
88
  - `autoStart?: boolean` - Auto-start server (default: true)
89
- - `githubToken?: string` - GitHub token for authentication. When provided, takes priority over other auth methods.
90
- - `useLoggedInUser?: boolean` - Whether to use logged-in user for authentication (default: true, but false when `githubToken` is provided). Cannot be used with `cliUrl`.
89
+ - `gitHubToken?: string` - GitHub token for authentication. When provided, takes priority over other auth methods.
90
+ - `useLoggedInUser?: boolean` - Whether to use logged-in user for authentication (default: true, but false when `gitHubToken` is provided). Cannot be used with `cliUrl`.
91
91
  - `telemetry?: TelemetryConfig` - OpenTelemetry configuration for the CLI process. Providing this object enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
92
92
  - `onGetTraceContext?: TraceContextProvider` - Advanced: callback for linking your application's own OpenTelemetry spans into the same distributed trace as the CLI's spans. Not needed for normal telemetry collection. See [Telemetry](#telemetry) below.
93
93
 
@@ -32,7 +32,9 @@ var import_node = require("vscode-jsonrpc/node.js");
32
32
  var import_rpc = require("./generated/rpc.js");
33
33
  var import_sdkProtocolVersion = require("./sdkProtocolVersion.js");
34
34
  var import_session = require("./session.js");
35
+ var import_sessionFsProvider = require("./sessionFsProvider.js");
35
36
  var import_telemetry = require("./telemetry.js");
37
+ var import_types = require("./types.js");
36
38
  const import_meta = {};
37
39
  const MIN_PROTOCOL_VERSION = 2;
38
40
  function isZodSchema(value) {
@@ -94,6 +96,7 @@ function getBundledCliPath() {
94
96
  );
95
97
  }
96
98
  class CopilotClient {
99
+ cliStartTimeout = null;
97
100
  cliProcess = null;
98
101
  connection = null;
99
102
  socket = null;
@@ -161,9 +164,9 @@ class CopilotClient {
161
164
  "isChildProcess must be used in conjunction with useStdio and not with cliUrl"
162
165
  );
163
166
  }
164
- if (options.cliUrl && (options.githubToken || options.useLoggedInUser !== void 0)) {
167
+ if (options.cliUrl && (options.gitHubToken || options.useLoggedInUser !== void 0)) {
165
168
  throw new Error(
166
- "githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
169
+ "gitHubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
167
170
  );
168
171
  }
169
172
  if (options.sessionFs) {
@@ -195,10 +198,11 @@ class CopilotClient {
195
198
  autoStart: options.autoStart ?? true,
196
199
  autoRestart: false,
197
200
  env: effectiveEnv,
198
- githubToken: options.githubToken,
199
- // Default useLoggedInUser to false when githubToken is provided, otherwise true
200
- useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
201
- telemetry: options.telemetry
201
+ gitHubToken: options.gitHubToken,
202
+ // Default useLoggedInUser to false when gitHubToken is provided, otherwise true
203
+ useLoggedInUser: options.useLoggedInUser ?? (options.gitHubToken ? false : true),
204
+ telemetry: options.telemetry,
205
+ sessionIdleTimeoutSeconds: options.sessionIdleTimeoutSeconds ?? 0
202
206
  };
203
207
  }
204
208
  /**
@@ -364,6 +368,10 @@ class CopilotClient {
364
368
  }
365
369
  this.cliProcess = null;
366
370
  }
371
+ if (this.cliStartTimeout) {
372
+ clearTimeout(this.cliStartTimeout);
373
+ this.cliStartTimeout = null;
374
+ }
367
375
  this.state = "disconnected";
368
376
  this.actualPort = null;
369
377
  this.stderrBuffer = "";
@@ -421,6 +429,10 @@ class CopilotClient {
421
429
  }
422
430
  this.cliProcess = null;
423
431
  }
432
+ if (this.cliStartTimeout) {
433
+ clearTimeout(this.cliStartTimeout);
434
+ this.cliStartTimeout = null;
435
+ }
424
436
  this.state = "disconnected";
425
437
  this.actualPort = null;
426
438
  this.stderrBuffer = "";
@@ -499,7 +511,9 @@ class CopilotClient {
499
511
  this.sessions.set(sessionId, session);
500
512
  if (this.sessionFsConfig) {
501
513
  if (config.createSessionFsHandler) {
502
- session.clientSessionApis.sessionFs = config.createSessionFsHandler(session);
514
+ session.clientSessionApis.sessionFs = (0, import_sessionFsProvider.createSessionFsAdapter)(
515
+ config.createSessionFsHandler(session)
516
+ );
503
517
  } else {
504
518
  throw new Error(
505
519
  "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
@@ -535,15 +549,18 @@ class CopilotClient {
535
549
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
536
550
  workingDirectory: config.workingDirectory,
537
551
  streaming: config.streaming,
552
+ includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
538
553
  mcpServers: config.mcpServers,
539
554
  envValueMode: "direct",
540
555
  customAgents: config.customAgents,
556
+ defaultAgent: config.defaultAgent,
541
557
  agent: config.agent,
542
558
  configDir: config.configDir,
543
559
  enableConfigDiscovery: config.enableConfigDiscovery,
544
560
  skillDirectories: config.skillDirectories,
545
561
  disabledSkills: config.disabledSkills,
546
- infiniteSessions: config.infiniteSessions
562
+ infiniteSessions: config.infiniteSessions,
563
+ gitHubToken: config.gitHubToken
547
564
  });
548
565
  const { workspacePath, capabilities } = response;
549
566
  session["_workspacePath"] = workspacePath;
@@ -621,7 +638,9 @@ class CopilotClient {
621
638
  this.sessions.set(sessionId, session);
622
639
  if (this.sessionFsConfig) {
623
640
  if (config.createSessionFsHandler) {
624
- session.clientSessionApis.sessionFs = config.createSessionFsHandler(session);
641
+ session.clientSessionApis.sessionFs = (0, import_sessionFsProvider.createSessionFsAdapter)(
642
+ config.createSessionFsHandler(session)
643
+ );
625
644
  } else {
626
645
  throw new Error(
627
646
  "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
@@ -651,7 +670,7 @@ class CopilotClient {
651
670
  })),
652
671
  provider: config.provider,
653
672
  modelCapabilities: config.modelCapabilities,
654
- requestPermission: true,
673
+ requestPermission: config.onPermissionRequest !== import_types.defaultJoinSessionPermissionHandler,
655
674
  requestUserInput: !!config.onUserInputRequest,
656
675
  requestElicitation: !!config.onElicitationRequest,
657
676
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
@@ -659,14 +678,17 @@ class CopilotClient {
659
678
  configDir: config.configDir,
660
679
  enableConfigDiscovery: config.enableConfigDiscovery,
661
680
  streaming: config.streaming,
681
+ includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
662
682
  mcpServers: config.mcpServers,
663
683
  envValueMode: "direct",
664
684
  customAgents: config.customAgents,
685
+ defaultAgent: config.defaultAgent,
665
686
  agent: config.agent,
666
687
  skillDirectories: config.skillDirectories,
667
688
  disabledSkills: config.disabledSkills,
668
689
  infiniteSessions: config.infiniteSessions,
669
- disableResume: config.disableResume
690
+ disableResume: config.disableResume,
691
+ gitHubToken: config.gitHubToken
670
692
  });
671
693
  const { workspacePath, capabilities } = response;
672
694
  session["_workspacePath"] = workspacePath;
@@ -763,6 +785,22 @@ class CopilotClient {
763
785
  const result = await this.connection.sendRequest("models.list", {});
764
786
  const response = result;
765
787
  models = response.models;
788
+ for (const model of models) {
789
+ const m = model;
790
+ if (!m.capabilities) {
791
+ m.capabilities = {
792
+ supports: {},
793
+ limits: { max_context_window_tokens: 0 }
794
+ };
795
+ } else {
796
+ if (!m.capabilities.supports) m.capabilities.supports = {};
797
+ if (!m.capabilities.limits) {
798
+ m.capabilities.limits = { max_context_window_tokens: 0 };
799
+ } else if (m.capabilities.limits.max_context_window_tokens === void 0) {
800
+ m.capabilities.limits.max_context_window_tokens = 0;
801
+ }
802
+ }
803
+ }
766
804
  }
767
805
  this.modelsCache = [...models];
768
806
  return [...models];
@@ -1000,16 +1038,22 @@ class CopilotClient {
1000
1038
  } else if (this.options.port > 0) {
1001
1039
  args.push("--port", this.options.port.toString());
1002
1040
  }
1003
- if (this.options.githubToken) {
1041
+ if (this.options.gitHubToken) {
1004
1042
  args.push("--auth-token-env", "COPILOT_SDK_AUTH_TOKEN");
1005
1043
  }
1006
1044
  if (!this.options.useLoggedInUser) {
1007
1045
  args.push("--no-auto-login");
1008
1046
  }
1047
+ if (this.options.sessionIdleTimeoutSeconds !== void 0 && this.options.sessionIdleTimeoutSeconds > 0) {
1048
+ args.push(
1049
+ "--session-idle-timeout",
1050
+ this.options.sessionIdleTimeoutSeconds.toString()
1051
+ );
1052
+ }
1009
1053
  const envWithoutNodeDebug = { ...this.options.env };
1010
1054
  delete envWithoutNodeDebug.NODE_DEBUG;
1011
- if (this.options.githubToken) {
1012
- envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
1055
+ if (this.options.gitHubToken) {
1056
+ envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.gitHubToken;
1013
1057
  }
1014
1058
  if (!this.options.cliPath) {
1015
1059
  throw new Error(
@@ -1133,7 +1177,7 @@ stderr: ${stderrOutput}`
1133
1177
  }
1134
1178
  }
1135
1179
  });
1136
- setTimeout(() => {
1180
+ this.cliStartTimeout = setTimeout(() => {
1137
1181
  if (!resolved) {
1138
1182
  resolved = true;
1139
1183
  reject(new Error("Timeout waiting for CLI server to start"));
@@ -1390,7 +1434,7 @@ stderr: ${stderrOutput}`
1390
1434
  }
1391
1435
  return {
1392
1436
  result: {
1393
- kind: "denied-no-approval-rule-and-could-not-request-from-user"
1437
+ kind: "user-not-available"
1394
1438
  }
1395
1439
  };
1396
1440
  }
@@ -22,9 +22,7 @@ __export(extension_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(extension_exports);
24
24
  var import_client = require("./client.js");
25
- const defaultJoinSessionPermissionHandler = () => ({
26
- kind: "no-result"
27
- });
25
+ var import_types = require("./types.js");
28
26
  async function joinSession(config = {}) {
29
27
  const sessionId = process.env.SESSION_ID;
30
28
  if (!sessionId) {
@@ -35,7 +33,7 @@ async function joinSession(config = {}) {
35
33
  const client = new import_client.CopilotClient({ isChildProcess: true });
36
34
  return client.resumeSession(sessionId, {
37
35
  ...config,
38
- onPermissionRequest: config.onPermissionRequest ?? defaultJoinSessionPermissionHandler,
36
+ onPermissionRequest: config.onPermissionRequest ?? import_types.defaultJoinSessionPermissionHandler,
39
37
  disableResume: config.disableResume ?? true
40
38
  });
41
39
  }
@@ -27,21 +27,30 @@ function createServerRpc(connection) {
27
27
  return {
28
28
  ping: async (params) => connection.sendRequest("ping", params),
29
29
  models: {
30
- list: async () => connection.sendRequest("models.list", {})
30
+ list: async (params) => connection.sendRequest("models.list", params)
31
31
  },
32
32
  tools: {
33
33
  list: async (params) => connection.sendRequest("tools.list", params)
34
34
  },
35
35
  account: {
36
- getQuota: async () => connection.sendRequest("account.getQuota", {})
36
+ getQuota: async (params) => connection.sendRequest("account.getQuota", params)
37
37
  },
38
38
  mcp: {
39
39
  config: {
40
40
  list: async () => connection.sendRequest("mcp.config.list", {}),
41
41
  add: async (params) => connection.sendRequest("mcp.config.add", params),
42
42
  update: async (params) => connection.sendRequest("mcp.config.update", params),
43
- remove: async (params) => connection.sendRequest("mcp.config.remove", params)
44
- }
43
+ remove: async (params) => connection.sendRequest("mcp.config.remove", params),
44
+ enable: async (params) => connection.sendRequest("mcp.config.enable", params),
45
+ disable: async (params) => connection.sendRequest("mcp.config.disable", params)
46
+ },
47
+ discover: async (params) => connection.sendRequest("mcp.discover", params)
48
+ },
49
+ skills: {
50
+ config: {
51
+ setDisabledSkills: async (params) => connection.sendRequest("skills.config.setDisabledSkills", params)
52
+ },
53
+ discover: async (params) => connection.sendRequest("skills.discover", params)
45
54
  },
46
55
  sessionFs: {
47
56
  setProvider: async (params) => connection.sendRequest("sessionFs.setProvider", params)
@@ -54,6 +63,9 @@ function createServerRpc(connection) {
54
63
  }
55
64
  function createSessionRpc(connection, sessionId) {
56
65
  return {
66
+ auth: {
67
+ getStatus: async () => connection.sendRequest("session.auth.getStatus", { sessionId })
68
+ },
57
69
  model: {
58
70
  getCurrent: async () => connection.sendRequest("session.model.getCurrent", { sessionId }),
59
71
  switchTo: async (params) => connection.sendRequest("session.model.switchTo", { sessionId, ...params })
@@ -62,15 +74,23 @@ function createSessionRpc(connection, sessionId) {
62
74
  get: async () => connection.sendRequest("session.mode.get", { sessionId }),
63
75
  set: async (params) => connection.sendRequest("session.mode.set", { sessionId, ...params })
64
76
  },
77
+ name: {
78
+ get: async () => connection.sendRequest("session.name.get", { sessionId }),
79
+ set: async (params) => connection.sendRequest("session.name.set", { sessionId, ...params })
80
+ },
65
81
  plan: {
66
82
  read: async () => connection.sendRequest("session.plan.read", { sessionId }),
67
83
  update: async (params) => connection.sendRequest("session.plan.update", { sessionId, ...params }),
68
84
  delete: async () => connection.sendRequest("session.plan.delete", { sessionId })
69
85
  },
70
- workspace: {
71
- listFiles: async () => connection.sendRequest("session.workspace.listFiles", { sessionId }),
72
- readFile: async (params) => connection.sendRequest("session.workspace.readFile", { sessionId, ...params }),
73
- createFile: async (params) => connection.sendRequest("session.workspace.createFile", { sessionId, ...params })
86
+ workspaces: {
87
+ getWorkspace: async () => connection.sendRequest("session.workspaces.getWorkspace", { sessionId }),
88
+ listFiles: async () => connection.sendRequest("session.workspaces.listFiles", { sessionId }),
89
+ readFile: async (params) => connection.sendRequest("session.workspaces.readFile", { sessionId, ...params }),
90
+ createFile: async (params) => connection.sendRequest("session.workspaces.createFile", { sessionId, ...params })
91
+ },
92
+ instructions: {
93
+ getSources: async () => connection.sendRequest("session.instructions.getSources", { sessionId })
74
94
  },
75
95
  /** @experimental */
76
96
  fleet: {
@@ -96,7 +116,11 @@ function createSessionRpc(connection, sessionId) {
96
116
  list: async () => connection.sendRequest("session.mcp.list", { sessionId }),
97
117
  enable: async (params) => connection.sendRequest("session.mcp.enable", { sessionId, ...params }),
98
118
  disable: async (params) => connection.sendRequest("session.mcp.disable", { sessionId, ...params }),
99
- reload: async () => connection.sendRequest("session.mcp.reload", { sessionId })
119
+ reload: async () => connection.sendRequest("session.mcp.reload", { sessionId }),
120
+ /** @experimental */
121
+ oauth: {
122
+ login: async (params) => connection.sendRequest("session.mcp.oauth.login", { sessionId, ...params })
123
+ }
100
124
  },
101
125
  /** @experimental */
102
126
  plugins: {
@@ -120,7 +144,9 @@ function createSessionRpc(connection, sessionId) {
120
144
  handlePendingElicitation: async (params) => connection.sendRequest("session.ui.handlePendingElicitation", { sessionId, ...params })
121
145
  },
122
146
  permissions: {
123
- handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params })
147
+ handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params }),
148
+ setApproveAll: async (params) => connection.sendRequest("session.permissions.setApproveAll", { sessionId, ...params }),
149
+ resetSessionApprovals: async () => connection.sendRequest("session.permissions.resetSessionApprovals", { sessionId })
124
150
  },
125
151
  log: async (params) => connection.sendRequest("session.log", { sessionId, ...params }),
126
152
  shell: {
@@ -131,6 +157,10 @@ function createSessionRpc(connection, sessionId) {
131
157
  history: {
132
158
  compact: async () => connection.sendRequest("session.history.compact", { sessionId }),
133
159
  truncate: async (params) => connection.sendRequest("session.history.truncate", { sessionId, ...params })
160
+ },
161
+ /** @experimental */
162
+ usage: {
163
+ getMetrics: async () => connection.sendRequest("session.usage.getMetrics", { sessionId })
134
164
  }
135
165
  };
136
166
  }
package/dist/cjs/index.js CHANGED
@@ -22,6 +22,8 @@ __export(index_exports, {
22
22
  CopilotSession: () => import_session.CopilotSession,
23
23
  SYSTEM_PROMPT_SECTIONS: () => import_types.SYSTEM_PROMPT_SECTIONS,
24
24
  approveAll: () => import_types.approveAll,
25
+ convertMcpCallToolResult: () => import_types.convertMcpCallToolResult,
26
+ createSessionFsAdapter: () => import_types.createSessionFsAdapter,
25
27
  defineTool: () => import_types.defineTool
26
28
  });
27
29
  module.exports = __toCommonJS(index_exports);
@@ -34,5 +36,7 @@ var import_types = require("./types.js");
34
36
  CopilotSession,
35
37
  SYSTEM_PROMPT_SECTIONS,
36
38
  approveAll,
39
+ convertMcpCallToolResult,
40
+ createSessionFsAdapter,
37
41
  defineTool
38
42
  });
@@ -124,7 +124,8 @@ class CopilotSession {
124
124
  sessionId: this.sessionId,
125
125
  prompt: options.prompt,
126
126
  attachments: options.attachments,
127
- mode: options.mode
127
+ mode: options.mode,
128
+ requestHeaders: options.requestHeaders
128
129
  });
129
130
  return response.messageId;
130
131
  }
@@ -348,7 +349,7 @@ class CopilotSession {
348
349
  await this.rpc.permissions.handlePendingPermissionRequest({
349
350
  requestId,
350
351
  result: {
351
- kind: "denied-no-approval-rule-and-could-not-request-from-user"
352
+ kind: "user-not-available"
352
353
  }
353
354
  });
354
355
  } catch (rpcError) {
@@ -626,7 +627,7 @@ class CopilotSession {
626
627
  */
627
628
  async _handlePermissionRequestV2(request) {
628
629
  if (!this.permissionHandler) {
629
- return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
630
+ return { kind: "user-not-available" };
630
631
  }
631
632
  try {
632
633
  const result = await this.permissionHandler(request, {
@@ -640,7 +641,7 @@ class CopilotSession {
640
641
  if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
641
642
  throw error;
642
643
  }
643
- return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
644
+ return { kind: "user-not-available" };
644
645
  }
645
646
  }
646
647
  /**
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sessionFsProvider_exports = {};
20
+ __export(sessionFsProvider_exports, {
21
+ createSessionFsAdapter: () => createSessionFsAdapter
22
+ });
23
+ module.exports = __toCommonJS(sessionFsProvider_exports);
24
+ function createSessionFsAdapter(provider) {
25
+ return {
26
+ readFile: async ({ path }) => {
27
+ try {
28
+ const content = await provider.readFile(path);
29
+ return { content };
30
+ } catch (err) {
31
+ return { content: "", error: toSessionFsError(err) };
32
+ }
33
+ },
34
+ writeFile: async ({ path, content, mode }) => {
35
+ try {
36
+ await provider.writeFile(path, content, mode);
37
+ return void 0;
38
+ } catch (err) {
39
+ return toSessionFsError(err);
40
+ }
41
+ },
42
+ appendFile: async ({ path, content, mode }) => {
43
+ try {
44
+ await provider.appendFile(path, content, mode);
45
+ return void 0;
46
+ } catch (err) {
47
+ return toSessionFsError(err);
48
+ }
49
+ },
50
+ exists: async ({ path }) => {
51
+ try {
52
+ return { exists: await provider.exists(path) };
53
+ } catch {
54
+ return { exists: false };
55
+ }
56
+ },
57
+ stat: async ({ path }) => {
58
+ try {
59
+ return await provider.stat(path);
60
+ } catch (err) {
61
+ return {
62
+ isFile: false,
63
+ isDirectory: false,
64
+ size: 0,
65
+ mtime: (/* @__PURE__ */ new Date()).toISOString(),
66
+ birthtime: (/* @__PURE__ */ new Date()).toISOString(),
67
+ error: toSessionFsError(err)
68
+ };
69
+ }
70
+ },
71
+ mkdir: async ({ path, recursive, mode }) => {
72
+ try {
73
+ await provider.mkdir(path, recursive ?? false, mode);
74
+ return void 0;
75
+ } catch (err) {
76
+ return toSessionFsError(err);
77
+ }
78
+ },
79
+ readdir: async ({ path }) => {
80
+ try {
81
+ const entries = await provider.readdir(path);
82
+ return { entries };
83
+ } catch (err) {
84
+ return { entries: [], error: toSessionFsError(err) };
85
+ }
86
+ },
87
+ readdirWithTypes: async ({ path }) => {
88
+ try {
89
+ const entries = await provider.readdirWithTypes(path);
90
+ return { entries };
91
+ } catch (err) {
92
+ return { entries: [], error: toSessionFsError(err) };
93
+ }
94
+ },
95
+ rm: async ({ path, recursive, force }) => {
96
+ try {
97
+ await provider.rm(path, recursive ?? false, force ?? false);
98
+ return void 0;
99
+ } catch (err) {
100
+ return toSessionFsError(err);
101
+ }
102
+ },
103
+ rename: async ({ src, dest }) => {
104
+ try {
105
+ await provider.rename(src, dest);
106
+ return void 0;
107
+ } catch (err) {
108
+ return toSessionFsError(err);
109
+ }
110
+ }
111
+ };
112
+ }
113
+ function toSessionFsError(err) {
114
+ const e = err;
115
+ const code = e.code === "ENOENT" ? "ENOENT" : "UNKNOWN";
116
+ return { code, message: e.message ?? String(err) };
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ createSessionFsAdapter
121
+ });
package/dist/cjs/types.js CHANGED
@@ -20,9 +20,54 @@ var types_exports = {};
20
20
  __export(types_exports, {
21
21
  SYSTEM_PROMPT_SECTIONS: () => SYSTEM_PROMPT_SECTIONS,
22
22
  approveAll: () => approveAll,
23
+ convertMcpCallToolResult: () => convertMcpCallToolResult,
24
+ createSessionFsAdapter: () => import_sessionFsProvider.createSessionFsAdapter,
25
+ defaultJoinSessionPermissionHandler: () => defaultJoinSessionPermissionHandler,
23
26
  defineTool: () => defineTool
24
27
  });
25
28
  module.exports = __toCommonJS(types_exports);
29
+ var import_sessionFsProvider = require("./sessionFsProvider.js");
30
+ function convertMcpCallToolResult(callResult) {
31
+ const textParts = [];
32
+ const binaryResults = [];
33
+ for (const block of callResult.content) {
34
+ switch (block.type) {
35
+ case "text":
36
+ if (typeof block.text === "string") {
37
+ textParts.push(block.text);
38
+ }
39
+ break;
40
+ case "image":
41
+ if (typeof block.data === "string" && block.data && typeof block.mimeType === "string") {
42
+ binaryResults.push({
43
+ data: block.data,
44
+ mimeType: block.mimeType,
45
+ type: "image"
46
+ });
47
+ }
48
+ break;
49
+ case "resource": {
50
+ if (block.resource?.text) {
51
+ textParts.push(block.resource.text);
52
+ }
53
+ if (block.resource?.blob) {
54
+ binaryResults.push({
55
+ data: block.resource.blob,
56
+ mimeType: block.resource.mimeType ?? "application/octet-stream",
57
+ type: "resource",
58
+ description: block.resource.uri
59
+ });
60
+ }
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ return {
66
+ textResultForLlm: textParts.join("\n"),
67
+ resultType: callResult.isError ? "failure" : "success",
68
+ ...binaryResults.length > 0 ? { binaryResultsForLlm: binaryResults } : {}
69
+ };
70
+ }
26
71
  function defineTool(name, config) {
27
72
  return { name, ...config };
28
73
  }
@@ -40,10 +85,16 @@ const SYSTEM_PROMPT_SECTIONS = {
40
85
  description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
41
86
  }
42
87
  };
43
- const approveAll = () => ({ kind: "approved" });
88
+ const approveAll = () => ({ kind: "approve-once" });
89
+ const defaultJoinSessionPermissionHandler = () => ({
90
+ kind: "no-result"
91
+ });
44
92
  // Annotate the CommonJS export names for ESM import in node:
45
93
  0 && (module.exports = {
46
94
  SYSTEM_PROMPT_SECTIONS,
47
95
  approveAll,
96
+ convertMcpCallToolResult,
97
+ createSessionFsAdapter,
98
+ defaultJoinSessionPermissionHandler,
48
99
  defineTool
49
100
  });
package/dist/client.d.ts CHANGED
@@ -35,6 +35,7 @@ import type { ConnectionState, CopilotClientOptions, GetAuthStatusResponse, GetS
35
35
  * ```
36
36
  */
37
37
  export declare class CopilotClient {
38
+ private cliStartTimeout;
38
39
  private cliProcess;
39
40
  private connection;
40
41
  private socket;