@github/copilot-sdk 0.2.2-preview.0 → 0.3.0-preview.0
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/cjs/client.js +41 -4
- package/dist/cjs/extension.js +2 -4
- package/dist/cjs/generated/rpc.js +33 -9
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/session.js +2 -1
- package/dist/cjs/sessionFsProvider.js +121 -0
- package/dist/cjs/types.js +51 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +41 -4
- package/dist/extension.d.ts +1 -1
- package/dist/extension.js +3 -3
- package/dist/generated/rpc.d.ts +1250 -1022
- package/dist/generated/rpc.js +33 -9
- package/dist/generated/session-events.d.ts +3490 -2890
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -1
- package/dist/session.js +2 -1
- package/dist/sessionFsProvider.d.ts +44 -0
- package/dist/sessionFsProvider.js +97 -0
- package/dist/types.d.ts +108 -13
- package/dist/types.js +48 -0
- package/docs/agent-author.md +22 -14
- package/docs/examples.md +35 -31
- package/package.json +2 -2
package/dist/cjs/client.js
CHANGED
|
@@ -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;
|
|
@@ -364,6 +367,10 @@ class CopilotClient {
|
|
|
364
367
|
}
|
|
365
368
|
this.cliProcess = null;
|
|
366
369
|
}
|
|
370
|
+
if (this.cliStartTimeout) {
|
|
371
|
+
clearTimeout(this.cliStartTimeout);
|
|
372
|
+
this.cliStartTimeout = null;
|
|
373
|
+
}
|
|
367
374
|
this.state = "disconnected";
|
|
368
375
|
this.actualPort = null;
|
|
369
376
|
this.stderrBuffer = "";
|
|
@@ -421,6 +428,10 @@ class CopilotClient {
|
|
|
421
428
|
}
|
|
422
429
|
this.cliProcess = null;
|
|
423
430
|
}
|
|
431
|
+
if (this.cliStartTimeout) {
|
|
432
|
+
clearTimeout(this.cliStartTimeout);
|
|
433
|
+
this.cliStartTimeout = null;
|
|
434
|
+
}
|
|
424
435
|
this.state = "disconnected";
|
|
425
436
|
this.actualPort = null;
|
|
426
437
|
this.stderrBuffer = "";
|
|
@@ -499,7 +510,9 @@ class CopilotClient {
|
|
|
499
510
|
this.sessions.set(sessionId, session);
|
|
500
511
|
if (this.sessionFsConfig) {
|
|
501
512
|
if (config.createSessionFsHandler) {
|
|
502
|
-
session.clientSessionApis.sessionFs =
|
|
513
|
+
session.clientSessionApis.sessionFs = (0, import_sessionFsProvider.createSessionFsAdapter)(
|
|
514
|
+
config.createSessionFsHandler(session)
|
|
515
|
+
);
|
|
503
516
|
} else {
|
|
504
517
|
throw new Error(
|
|
505
518
|
"createSessionFsHandler is required in session config when sessionFs is enabled in client options."
|
|
@@ -535,11 +548,14 @@ class CopilotClient {
|
|
|
535
548
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
536
549
|
workingDirectory: config.workingDirectory,
|
|
537
550
|
streaming: config.streaming,
|
|
551
|
+
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
538
552
|
mcpServers: config.mcpServers,
|
|
539
553
|
envValueMode: "direct",
|
|
540
554
|
customAgents: config.customAgents,
|
|
555
|
+
defaultAgent: config.defaultAgent,
|
|
541
556
|
agent: config.agent,
|
|
542
557
|
configDir: config.configDir,
|
|
558
|
+
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
543
559
|
skillDirectories: config.skillDirectories,
|
|
544
560
|
disabledSkills: config.disabledSkills,
|
|
545
561
|
infiniteSessions: config.infiniteSessions
|
|
@@ -620,7 +636,9 @@ class CopilotClient {
|
|
|
620
636
|
this.sessions.set(sessionId, session);
|
|
621
637
|
if (this.sessionFsConfig) {
|
|
622
638
|
if (config.createSessionFsHandler) {
|
|
623
|
-
session.clientSessionApis.sessionFs =
|
|
639
|
+
session.clientSessionApis.sessionFs = (0, import_sessionFsProvider.createSessionFsAdapter)(
|
|
640
|
+
config.createSessionFsHandler(session)
|
|
641
|
+
);
|
|
624
642
|
} else {
|
|
625
643
|
throw new Error(
|
|
626
644
|
"createSessionFsHandler is required in session config when sessionFs is enabled in client options."
|
|
@@ -650,16 +668,19 @@ class CopilotClient {
|
|
|
650
668
|
})),
|
|
651
669
|
provider: config.provider,
|
|
652
670
|
modelCapabilities: config.modelCapabilities,
|
|
653
|
-
requestPermission:
|
|
671
|
+
requestPermission: config.onPermissionRequest !== import_types.defaultJoinSessionPermissionHandler,
|
|
654
672
|
requestUserInput: !!config.onUserInputRequest,
|
|
655
673
|
requestElicitation: !!config.onElicitationRequest,
|
|
656
674
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
657
675
|
workingDirectory: config.workingDirectory,
|
|
658
676
|
configDir: config.configDir,
|
|
677
|
+
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
659
678
|
streaming: config.streaming,
|
|
679
|
+
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
660
680
|
mcpServers: config.mcpServers,
|
|
661
681
|
envValueMode: "direct",
|
|
662
682
|
customAgents: config.customAgents,
|
|
683
|
+
defaultAgent: config.defaultAgent,
|
|
663
684
|
agent: config.agent,
|
|
664
685
|
skillDirectories: config.skillDirectories,
|
|
665
686
|
disabledSkills: config.disabledSkills,
|
|
@@ -761,6 +782,22 @@ class CopilotClient {
|
|
|
761
782
|
const result = await this.connection.sendRequest("models.list", {});
|
|
762
783
|
const response = result;
|
|
763
784
|
models = response.models;
|
|
785
|
+
for (const model of models) {
|
|
786
|
+
const m = model;
|
|
787
|
+
if (!m.capabilities) {
|
|
788
|
+
m.capabilities = {
|
|
789
|
+
supports: {},
|
|
790
|
+
limits: { max_context_window_tokens: 0 }
|
|
791
|
+
};
|
|
792
|
+
} else {
|
|
793
|
+
if (!m.capabilities.supports) m.capabilities.supports = {};
|
|
794
|
+
if (!m.capabilities.limits) {
|
|
795
|
+
m.capabilities.limits = { max_context_window_tokens: 0 };
|
|
796
|
+
} else if (m.capabilities.limits.max_context_window_tokens === void 0) {
|
|
797
|
+
m.capabilities.limits.max_context_window_tokens = 0;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
764
801
|
}
|
|
765
802
|
this.modelsCache = [...models];
|
|
766
803
|
return [...models];
|
|
@@ -1131,7 +1168,7 @@ stderr: ${stderrOutput}`
|
|
|
1131
1168
|
}
|
|
1132
1169
|
}
|
|
1133
1170
|
});
|
|
1134
|
-
setTimeout(() => {
|
|
1171
|
+
this.cliStartTimeout = setTimeout(() => {
|
|
1135
1172
|
if (!resolved) {
|
|
1136
1173
|
resolved = true;
|
|
1137
1174
|
reject(new Error("Timeout waiting for CLI server to start"));
|
package/dist/cjs/extension.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -41,10 +41,21 @@ function createServerRpc(connection) {
|
|
|
41
41
|
add: async (params) => connection.sendRequest("mcp.config.add", params),
|
|
42
42
|
update: async (params) => connection.sendRequest("mcp.config.update", params),
|
|
43
43
|
remove: async (params) => connection.sendRequest("mcp.config.remove", params)
|
|
44
|
-
}
|
|
44
|
+
},
|
|
45
|
+
discover: async (params) => connection.sendRequest("mcp.discover", params)
|
|
46
|
+
},
|
|
47
|
+
skills: {
|
|
48
|
+
config: {
|
|
49
|
+
setDisabledSkills: async (params) => connection.sendRequest("skills.config.setDisabledSkills", params)
|
|
50
|
+
},
|
|
51
|
+
discover: async (params) => connection.sendRequest("skills.discover", params)
|
|
45
52
|
},
|
|
46
53
|
sessionFs: {
|
|
47
54
|
setProvider: async (params) => connection.sendRequest("sessionFs.setProvider", params)
|
|
55
|
+
},
|
|
56
|
+
/** @experimental */
|
|
57
|
+
sessions: {
|
|
58
|
+
fork: async (params) => connection.sendRequest("sessions.fork", params)
|
|
48
59
|
}
|
|
49
60
|
};
|
|
50
61
|
}
|
|
@@ -58,15 +69,23 @@ function createSessionRpc(connection, sessionId) {
|
|
|
58
69
|
get: async () => connection.sendRequest("session.mode.get", { sessionId }),
|
|
59
70
|
set: async (params) => connection.sendRequest("session.mode.set", { sessionId, ...params })
|
|
60
71
|
},
|
|
72
|
+
name: {
|
|
73
|
+
get: async () => connection.sendRequest("session.name.get", { sessionId }),
|
|
74
|
+
set: async (params) => connection.sendRequest("session.name.set", { sessionId, ...params })
|
|
75
|
+
},
|
|
61
76
|
plan: {
|
|
62
77
|
read: async () => connection.sendRequest("session.plan.read", { sessionId }),
|
|
63
78
|
update: async (params) => connection.sendRequest("session.plan.update", { sessionId, ...params }),
|
|
64
79
|
delete: async () => connection.sendRequest("session.plan.delete", { sessionId })
|
|
65
80
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
workspaces: {
|
|
82
|
+
getWorkspace: async () => connection.sendRequest("session.workspaces.getWorkspace", { sessionId }),
|
|
83
|
+
listFiles: async () => connection.sendRequest("session.workspaces.listFiles", { sessionId }),
|
|
84
|
+
readFile: async (params) => connection.sendRequest("session.workspaces.readFile", { sessionId, ...params }),
|
|
85
|
+
createFile: async (params) => connection.sendRequest("session.workspaces.createFile", { sessionId, ...params })
|
|
86
|
+
},
|
|
87
|
+
instructions: {
|
|
88
|
+
getSources: async () => connection.sendRequest("session.instructions.getSources", { sessionId })
|
|
70
89
|
},
|
|
71
90
|
/** @experimental */
|
|
72
91
|
fleet: {
|
|
@@ -105,10 +124,6 @@ function createSessionRpc(connection, sessionId) {
|
|
|
105
124
|
disable: async (params) => connection.sendRequest("session.extensions.disable", { sessionId, ...params }),
|
|
106
125
|
reload: async () => connection.sendRequest("session.extensions.reload", { sessionId })
|
|
107
126
|
},
|
|
108
|
-
/** @experimental */
|
|
109
|
-
compaction: {
|
|
110
|
-
compact: async () => connection.sendRequest("session.compaction.compact", { sessionId })
|
|
111
|
-
},
|
|
112
127
|
tools: {
|
|
113
128
|
handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
|
|
114
129
|
},
|
|
@@ -126,6 +141,15 @@ function createSessionRpc(connection, sessionId) {
|
|
|
126
141
|
shell: {
|
|
127
142
|
exec: async (params) => connection.sendRequest("session.shell.exec", { sessionId, ...params }),
|
|
128
143
|
kill: async (params) => connection.sendRequest("session.shell.kill", { sessionId, ...params })
|
|
144
|
+
},
|
|
145
|
+
/** @experimental */
|
|
146
|
+
history: {
|
|
147
|
+
compact: async () => connection.sendRequest("session.history.compact", { sessionId }),
|
|
148
|
+
truncate: async (params) => connection.sendRequest("session.history.truncate", { sessionId, ...params })
|
|
149
|
+
},
|
|
150
|
+
/** @experimental */
|
|
151
|
+
usage: {
|
|
152
|
+
getMetrics: async () => connection.sendRequest("session.usage.getMetrics", { sessionId })
|
|
129
153
|
}
|
|
130
154
|
};
|
|
131
155
|
}
|
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
|
});
|
package/dist/cjs/session.js
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -41,9 +86,15 @@ const SYSTEM_PROMPT_SECTIONS = {
|
|
|
41
86
|
}
|
|
42
87
|
};
|
|
43
88
|
const approveAll = () => ({ kind: "approved" });
|
|
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
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;
|
|
@@ -344,6 +347,10 @@ class CopilotClient {
|
|
|
344
347
|
}
|
|
345
348
|
this.cliProcess = null;
|
|
346
349
|
}
|
|
350
|
+
if (this.cliStartTimeout) {
|
|
351
|
+
clearTimeout(this.cliStartTimeout);
|
|
352
|
+
this.cliStartTimeout = null;
|
|
353
|
+
}
|
|
347
354
|
this.state = "disconnected";
|
|
348
355
|
this.actualPort = null;
|
|
349
356
|
this.stderrBuffer = "";
|
|
@@ -401,6 +408,10 @@ class CopilotClient {
|
|
|
401
408
|
}
|
|
402
409
|
this.cliProcess = null;
|
|
403
410
|
}
|
|
411
|
+
if (this.cliStartTimeout) {
|
|
412
|
+
clearTimeout(this.cliStartTimeout);
|
|
413
|
+
this.cliStartTimeout = null;
|
|
414
|
+
}
|
|
404
415
|
this.state = "disconnected";
|
|
405
416
|
this.actualPort = null;
|
|
406
417
|
this.stderrBuffer = "";
|
|
@@ -479,7 +490,9 @@ class CopilotClient {
|
|
|
479
490
|
this.sessions.set(sessionId, session);
|
|
480
491
|
if (this.sessionFsConfig) {
|
|
481
492
|
if (config.createSessionFsHandler) {
|
|
482
|
-
session.clientSessionApis.sessionFs =
|
|
493
|
+
session.clientSessionApis.sessionFs = createSessionFsAdapter(
|
|
494
|
+
config.createSessionFsHandler(session)
|
|
495
|
+
);
|
|
483
496
|
} else {
|
|
484
497
|
throw new Error(
|
|
485
498
|
"createSessionFsHandler is required in session config when sessionFs is enabled in client options."
|
|
@@ -515,11 +528,14 @@ class CopilotClient {
|
|
|
515
528
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
516
529
|
workingDirectory: config.workingDirectory,
|
|
517
530
|
streaming: config.streaming,
|
|
531
|
+
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
518
532
|
mcpServers: config.mcpServers,
|
|
519
533
|
envValueMode: "direct",
|
|
520
534
|
customAgents: config.customAgents,
|
|
535
|
+
defaultAgent: config.defaultAgent,
|
|
521
536
|
agent: config.agent,
|
|
522
537
|
configDir: config.configDir,
|
|
538
|
+
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
523
539
|
skillDirectories: config.skillDirectories,
|
|
524
540
|
disabledSkills: config.disabledSkills,
|
|
525
541
|
infiniteSessions: config.infiniteSessions
|
|
@@ -600,7 +616,9 @@ class CopilotClient {
|
|
|
600
616
|
this.sessions.set(sessionId, session);
|
|
601
617
|
if (this.sessionFsConfig) {
|
|
602
618
|
if (config.createSessionFsHandler) {
|
|
603
|
-
session.clientSessionApis.sessionFs =
|
|
619
|
+
session.clientSessionApis.sessionFs = createSessionFsAdapter(
|
|
620
|
+
config.createSessionFsHandler(session)
|
|
621
|
+
);
|
|
604
622
|
} else {
|
|
605
623
|
throw new Error(
|
|
606
624
|
"createSessionFsHandler is required in session config when sessionFs is enabled in client options."
|
|
@@ -630,16 +648,19 @@ class CopilotClient {
|
|
|
630
648
|
})),
|
|
631
649
|
provider: config.provider,
|
|
632
650
|
modelCapabilities: config.modelCapabilities,
|
|
633
|
-
requestPermission:
|
|
651
|
+
requestPermission: config.onPermissionRequest !== defaultJoinSessionPermissionHandler,
|
|
634
652
|
requestUserInput: !!config.onUserInputRequest,
|
|
635
653
|
requestElicitation: !!config.onElicitationRequest,
|
|
636
654
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
637
655
|
workingDirectory: config.workingDirectory,
|
|
638
656
|
configDir: config.configDir,
|
|
657
|
+
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
639
658
|
streaming: config.streaming,
|
|
659
|
+
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
640
660
|
mcpServers: config.mcpServers,
|
|
641
661
|
envValueMode: "direct",
|
|
642
662
|
customAgents: config.customAgents,
|
|
663
|
+
defaultAgent: config.defaultAgent,
|
|
643
664
|
agent: config.agent,
|
|
644
665
|
skillDirectories: config.skillDirectories,
|
|
645
666
|
disabledSkills: config.disabledSkills,
|
|
@@ -741,6 +762,22 @@ class CopilotClient {
|
|
|
741
762
|
const result = await this.connection.sendRequest("models.list", {});
|
|
742
763
|
const response = result;
|
|
743
764
|
models = response.models;
|
|
765
|
+
for (const model of models) {
|
|
766
|
+
const m = model;
|
|
767
|
+
if (!m.capabilities) {
|
|
768
|
+
m.capabilities = {
|
|
769
|
+
supports: {},
|
|
770
|
+
limits: { max_context_window_tokens: 0 }
|
|
771
|
+
};
|
|
772
|
+
} else {
|
|
773
|
+
if (!m.capabilities.supports) m.capabilities.supports = {};
|
|
774
|
+
if (!m.capabilities.limits) {
|
|
775
|
+
m.capabilities.limits = { max_context_window_tokens: 0 };
|
|
776
|
+
} else if (m.capabilities.limits.max_context_window_tokens === void 0) {
|
|
777
|
+
m.capabilities.limits.max_context_window_tokens = 0;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
744
781
|
}
|
|
745
782
|
this.modelsCache = [...models];
|
|
746
783
|
return [...models];
|
|
@@ -1111,7 +1148,7 @@ stderr: ${stderrOutput}`
|
|
|
1111
1148
|
}
|
|
1112
1149
|
}
|
|
1113
1150
|
});
|
|
1114
|
-
setTimeout(() => {
|
|
1151
|
+
this.cliStartTimeout = setTimeout(() => {
|
|
1115
1152
|
if (!resolved) {
|
|
1116
1153
|
resolved = true;
|
|
1117
1154
|
reject(new Error("Timeout waiting for CLI server to start"));
|
package/dist/extension.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CopilotSession } from "./session.js";
|
|
2
|
-
import type
|
|
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
|
-
|
|
3
|
-
|
|
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) {
|