@github/copilot-sdk 1.0.0-beta.5 → 1.0.0-beta.7
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 +25 -30
- package/dist/canvas.d.ts +163 -0
- package/dist/canvas.js +92 -0
- package/dist/cjs/canvas.js +119 -0
- package/dist/cjs/client.js +243 -251
- package/dist/cjs/extension.js +9 -2
- package/dist/cjs/generated/rpc.js +97 -1
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/session.js +64 -90
- package/dist/cjs/types.js +36 -3
- package/dist/client.d.ts +46 -49
- package/dist/client.js +246 -252
- package/dist/extension.d.ts +3 -1
- package/dist/extension.js +10 -2
- package/dist/generated/rpc.d.ts +796 -63
- package/dist/generated/rpc.js +97 -1
- package/dist/generated/session-events.d.ts +491 -78
- package/dist/index.d.ts +4 -2
- package/dist/index.js +12 -2
- package/dist/session.d.ts +13 -210
- package/dist/session.js +63 -88
- package/dist/types.d.ts +291 -121
- package/dist/types.js +34 -2
- package/package.json +2 -2
package/dist/cjs/extension.js
CHANGED
|
@@ -18,11 +18,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var extension_exports = {};
|
|
20
20
|
__export(extension_exports, {
|
|
21
|
+
Canvas: () => import_canvas.Canvas,
|
|
22
|
+
CanvasError: () => import_canvas.CanvasError,
|
|
23
|
+
createCanvas: () => import_canvas.createCanvas,
|
|
21
24
|
joinSession: () => joinSession
|
|
22
25
|
});
|
|
23
26
|
module.exports = __toCommonJS(extension_exports);
|
|
24
27
|
var import_client = require("./client.js");
|
|
25
28
|
var import_types = require("./types.js");
|
|
29
|
+
var import_canvas = require("./canvas.js");
|
|
26
30
|
async function joinSession(config = {}) {
|
|
27
31
|
const sessionId = process.env.SESSION_ID;
|
|
28
32
|
if (!sessionId) {
|
|
@@ -30,14 +34,17 @@ async function joinSession(config = {}) {
|
|
|
30
34
|
"joinSession() is intended for extensions running as child processes of the Copilot CLI."
|
|
31
35
|
);
|
|
32
36
|
}
|
|
33
|
-
const client = new import_client.CopilotClient({
|
|
37
|
+
const client = new import_client.CopilotClient({ _internalConnection: { kind: "parent-process" } });
|
|
34
38
|
return client.resumeSession(sessionId, {
|
|
35
39
|
...config,
|
|
36
40
|
onPermissionRequest: config.onPermissionRequest ?? import_types.defaultJoinSessionPermissionHandler,
|
|
37
|
-
|
|
41
|
+
suppressResumeEvent: config.suppressResumeEvent ?? true
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
45
|
0 && (module.exports = {
|
|
46
|
+
Canvas,
|
|
47
|
+
CanvasError,
|
|
48
|
+
createCanvas,
|
|
42
49
|
joinSession
|
|
43
50
|
});
|
|
@@ -64,6 +64,16 @@ function createServerRpc(connection) {
|
|
|
64
64
|
*/
|
|
65
65
|
getQuota: async (params) => connection.sendRequest("account.getQuota", params)
|
|
66
66
|
},
|
|
67
|
+
secrets: {
|
|
68
|
+
/**
|
|
69
|
+
* Registers secret values for redaction in session logs and exports. The SDK calls this to inject dynamically generated secret values (e.g., OIDC tokens).
|
|
70
|
+
*
|
|
71
|
+
* @param params Secret values to add to the redaction filter.
|
|
72
|
+
*
|
|
73
|
+
* @returns Confirmation that the secret values were registered.
|
|
74
|
+
*/
|
|
75
|
+
addFilterValues: async (params) => connection.sendRequest("secrets.addFilterValues", params)
|
|
76
|
+
},
|
|
67
77
|
mcp: {
|
|
68
78
|
config: {
|
|
69
79
|
/**
|
|
@@ -361,6 +371,43 @@ function createSessionRpc(connection, sessionId) {
|
|
|
361
371
|
setCredentials: async (params) => connection.sendRequest("session.auth.setCredentials", { sessionId, ...params })
|
|
362
372
|
},
|
|
363
373
|
/** @experimental */
|
|
374
|
+
canvas: {
|
|
375
|
+
/**
|
|
376
|
+
* Lists canvases declared for the session.
|
|
377
|
+
*
|
|
378
|
+
* @returns Declared canvases available in this session.
|
|
379
|
+
*/
|
|
380
|
+
list: async () => connection.sendRequest("session.canvas.list", { sessionId }),
|
|
381
|
+
/**
|
|
382
|
+
* Lists currently open canvas instances for the live session.
|
|
383
|
+
*
|
|
384
|
+
* @returns Live open-canvas snapshot.
|
|
385
|
+
*/
|
|
386
|
+
listOpen: async () => connection.sendRequest("session.canvas.listOpen", { sessionId }),
|
|
387
|
+
/**
|
|
388
|
+
* Opens or focuses a canvas instance.
|
|
389
|
+
*
|
|
390
|
+
* @param params Canvas open parameters.
|
|
391
|
+
*
|
|
392
|
+
* @returns Open canvas instance snapshot.
|
|
393
|
+
*/
|
|
394
|
+
open: async (params) => connection.sendRequest("session.canvas.open", { sessionId, ...params }),
|
|
395
|
+
/**
|
|
396
|
+
* Closes an open canvas instance.
|
|
397
|
+
*
|
|
398
|
+
* @param params Canvas close parameters.
|
|
399
|
+
*/
|
|
400
|
+
close: async (params) => connection.sendRequest("session.canvas.close", { sessionId, ...params }),
|
|
401
|
+
/**
|
|
402
|
+
* Invokes an action on an open canvas instance.
|
|
403
|
+
*
|
|
404
|
+
* @param params Canvas action invocation parameters.
|
|
405
|
+
*
|
|
406
|
+
* @returns Canvas action invocation result.
|
|
407
|
+
*/
|
|
408
|
+
invokeAction: async (params) => connection.sendRequest("session.canvas.invokeAction", { sessionId, ...params })
|
|
409
|
+
},
|
|
410
|
+
/** @experimental */
|
|
364
411
|
model: {
|
|
365
412
|
/**
|
|
366
413
|
* Gets the currently selected model for the session.
|
|
@@ -728,6 +775,53 @@ function createSessionRpc(connection, sessionId) {
|
|
|
728
775
|
* @returns OAuth authorization URL the caller should open, or empty when cached tokens already authenticated the server.
|
|
729
776
|
*/
|
|
730
777
|
login: async (params) => connection.sendRequest("session.mcp.oauth.login", { sessionId, ...params })
|
|
778
|
+
},
|
|
779
|
+
/** @experimental */
|
|
780
|
+
apps: {
|
|
781
|
+
/**
|
|
782
|
+
* Fetch an MCP resource (typically a `ui://` MCP App bundle, per SEP-1865) from a connected server. Requires the `mcp-apps` session capability.
|
|
783
|
+
*
|
|
784
|
+
* @param params MCP server and resource URI to fetch.
|
|
785
|
+
*
|
|
786
|
+
* @returns Resource contents returned by the MCP server.
|
|
787
|
+
*/
|
|
788
|
+
readResource: async (params) => connection.sendRequest("session.mcp.apps.readResource", { sessionId, ...params }),
|
|
789
|
+
/**
|
|
790
|
+
* List tools that an MCP App view is allowed to call (SEP-1865 visibility filter). Returns tools whose `_meta.ui.visibility` is unset (default `["model","app"]`) or includes `"app"`.
|
|
791
|
+
*
|
|
792
|
+
* @param params MCP server to list app-callable tools for.
|
|
793
|
+
*
|
|
794
|
+
* @returns App-callable tools from the named MCP server.
|
|
795
|
+
*/
|
|
796
|
+
listTools: async (params) => connection.sendRequest("session.mcp.apps.listTools", { sessionId, ...params }),
|
|
797
|
+
/**
|
|
798
|
+
* Call an MCP tool from an MCP App view (SEP-1865). Enforces the visibility check that prevents an app iframe from invoking model-only tools. Returns the standard MCP `CallToolResult`.
|
|
799
|
+
*
|
|
800
|
+
* @param params MCP server, tool name, and arguments to invoke from an MCP App view.
|
|
801
|
+
*
|
|
802
|
+
* @returns Standard MCP CallToolResult
|
|
803
|
+
*/
|
|
804
|
+
callTool: async (params) => connection.sendRequest("session.mcp.apps.callTool", { sessionId, ...params }),
|
|
805
|
+
/**
|
|
806
|
+
* Replace the host context returned to MCP App guests on `ui/initialize`. Hosts use this to advertise theme, locale, or other metadata to the guest UI.
|
|
807
|
+
*
|
|
808
|
+
* @param params Host context to advertise to MCP App guests.
|
|
809
|
+
*/
|
|
810
|
+
setHostContext: async (params) => connection.sendRequest("session.mcp.apps.setHostContext", { sessionId, ...params }),
|
|
811
|
+
/**
|
|
812
|
+
* Read the current host context advertised to MCP App guests.
|
|
813
|
+
*
|
|
814
|
+
* @returns Current host context advertised to MCP App guests.
|
|
815
|
+
*/
|
|
816
|
+
getHostContext: async () => connection.sendRequest("session.mcp.apps.getHostContext", { sessionId }),
|
|
817
|
+
/**
|
|
818
|
+
* Diagnose MCP Apps wiring for a specific MCP server. Reports the session capability, feature-flag state, advertised extension, and how many tools have `_meta.ui` populated.
|
|
819
|
+
*
|
|
820
|
+
* @param params MCP server to diagnose MCP Apps wiring for.
|
|
821
|
+
*
|
|
822
|
+
* @returns Diagnostic snapshot of MCP Apps wiring for the named server.
|
|
823
|
+
*/
|
|
824
|
+
diagnose: async (params) => connection.sendRequest("session.mcp.apps.diagnose", { sessionId, ...params })
|
|
731
825
|
}
|
|
732
826
|
},
|
|
733
827
|
/** @experimental */
|
|
@@ -1168,9 +1262,11 @@ function createSessionRpc(connection, sessionId) {
|
|
|
1168
1262
|
/**
|
|
1169
1263
|
* Compacts the session history to reduce context usage.
|
|
1170
1264
|
*
|
|
1265
|
+
* @param params Optional compaction parameters.
|
|
1266
|
+
*
|
|
1171
1267
|
* @returns Compaction outcome with the number of tokens and messages removed, summary text, and the resulting context window breakdown.
|
|
1172
1268
|
*/
|
|
1173
|
-
compact: async () => connection.sendRequest("session.history.compact", { sessionId }),
|
|
1269
|
+
compact: async (params) => connection.sendRequest("session.history.compact", { sessionId, ...params }),
|
|
1174
1270
|
/**
|
|
1175
1271
|
* Truncates persisted session history to a specific event.
|
|
1176
1272
|
*
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,25 +18,35 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var index_exports = {};
|
|
20
20
|
__export(index_exports, {
|
|
21
|
+
Canvas: () => import_canvas.Canvas,
|
|
22
|
+
CanvasError: () => import_canvas.CanvasError,
|
|
21
23
|
CopilotClient: () => import_client.CopilotClient,
|
|
22
24
|
CopilotSession: () => import_session.CopilotSession,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
RuntimeConnection: () => import_types.RuntimeConnection,
|
|
26
|
+
SYSTEM_MESSAGE_SECTIONS: () => import_types2.SYSTEM_MESSAGE_SECTIONS,
|
|
27
|
+
approveAll: () => import_types2.approveAll,
|
|
28
|
+
convertMcpCallToolResult: () => import_types2.convertMcpCallToolResult,
|
|
29
|
+
createCanvas: () => import_canvas.createCanvas,
|
|
30
|
+
createSessionFsAdapter: () => import_types2.createSessionFsAdapter,
|
|
31
|
+
defineTool: () => import_types2.defineTool
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(index_exports);
|
|
30
34
|
var import_client = require("./client.js");
|
|
31
|
-
var import_session = require("./session.js");
|
|
32
35
|
var import_types = require("./types.js");
|
|
36
|
+
var import_session = require("./session.js");
|
|
37
|
+
var import_canvas = require("./canvas.js");
|
|
38
|
+
var import_types2 = require("./types.js");
|
|
33
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
40
|
0 && (module.exports = {
|
|
41
|
+
Canvas,
|
|
42
|
+
CanvasError,
|
|
35
43
|
CopilotClient,
|
|
36
44
|
CopilotSession,
|
|
37
|
-
|
|
45
|
+
RuntimeConnection,
|
|
46
|
+
SYSTEM_MESSAGE_SECTIONS,
|
|
38
47
|
approveAll,
|
|
39
48
|
convertMcpCallToolResult,
|
|
49
|
+
createCanvas,
|
|
40
50
|
createSessionFsAdapter,
|
|
41
51
|
defineTool
|
|
42
52
|
});
|
package/dist/cjs/session.js
CHANGED
|
@@ -18,14 +18,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var session_exports = {};
|
|
20
20
|
__export(session_exports, {
|
|
21
|
-
CopilotSession: () => CopilotSession
|
|
22
|
-
NO_RESULT_PERMISSION_V2_ERROR: () => NO_RESULT_PERMISSION_V2_ERROR
|
|
21
|
+
CopilotSession: () => CopilotSession
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(session_exports);
|
|
25
24
|
var import_node = require("vscode-jsonrpc/node.js");
|
|
26
25
|
var import_rpc = require("./generated/rpc.js");
|
|
27
26
|
var import_telemetry = require("./telemetry.js");
|
|
28
|
-
|
|
27
|
+
function deserializeHookInput(raw) {
|
|
28
|
+
if (!raw || typeof raw !== "object" || typeof raw.timestamp !== "number") {
|
|
29
|
+
return raw;
|
|
30
|
+
}
|
|
31
|
+
const obj = raw;
|
|
32
|
+
const { cwd, ...rest } = obj;
|
|
33
|
+
return { ...rest, timestamp: new Date(obj.timestamp), workingDirectory: cwd };
|
|
34
|
+
}
|
|
29
35
|
class CopilotSession {
|
|
30
36
|
/**
|
|
31
37
|
* Creates a new CopilotSession instance.
|
|
@@ -45,6 +51,7 @@ class CopilotSession {
|
|
|
45
51
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
46
52
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
47
53
|
toolHandlers = /* @__PURE__ */ new Map();
|
|
54
|
+
canvases = /* @__PURE__ */ new Map();
|
|
48
55
|
commandHandlers = /* @__PURE__ */ new Map();
|
|
49
56
|
permissionHandler;
|
|
50
57
|
userInputHandler;
|
|
@@ -56,6 +63,7 @@ class CopilotSession {
|
|
|
56
63
|
_rpc = null;
|
|
57
64
|
traceContextProvider;
|
|
58
65
|
_capabilities = {};
|
|
66
|
+
openCanvasInstances = [];
|
|
59
67
|
/** @internal Client session API handlers, populated by CopilotClient during create/resume. */
|
|
60
68
|
clientSessionApis = {};
|
|
61
69
|
/**
|
|
@@ -102,25 +110,8 @@ class CopilotSession {
|
|
|
102
110
|
input: (message, options) => this._input(message, options)
|
|
103
111
|
};
|
|
104
112
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
* The message is processed asynchronously. Subscribe to events via {@link on}
|
|
109
|
-
* to receive streaming responses and other session events.
|
|
110
|
-
*
|
|
111
|
-
* @param options - The message options including the prompt and optional attachments
|
|
112
|
-
* @returns A promise that resolves with the message ID of the response
|
|
113
|
-
* @throws Error if the session has been disconnected or the connection fails
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const messageId = await session.send({
|
|
118
|
-
* prompt: "Explain this code",
|
|
119
|
-
* attachments: [{ type: "file", path: "./src/index.ts" }]
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
async send(options) {
|
|
113
|
+
async send(optionsOrPrompt) {
|
|
114
|
+
const options = typeof optionsOrPrompt === "string" ? { prompt: optionsOrPrompt } : optionsOrPrompt;
|
|
124
115
|
const response = await this.connection.sendRequest("session.send", {
|
|
125
116
|
...await (0, import_telemetry.getTraceContext)(this.traceContextProvider),
|
|
126
117
|
sessionId: this.sessionId,
|
|
@@ -131,30 +122,8 @@ class CopilotSession {
|
|
|
131
122
|
});
|
|
132
123
|
return response.messageId;
|
|
133
124
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
*
|
|
137
|
-
* This is a convenience method that combines {@link send} with waiting for
|
|
138
|
-
* the `session.idle` event. Use this when you want to block until the
|
|
139
|
-
* assistant has finished processing the message.
|
|
140
|
-
*
|
|
141
|
-
* Events are still delivered to handlers registered via {@link on} while waiting.
|
|
142
|
-
*
|
|
143
|
-
* @param options - The message options including the prompt and optional attachments
|
|
144
|
-
* @param timeout - Timeout in milliseconds (default: 60000). Controls how long to wait; does not abort in-flight agent work.
|
|
145
|
-
* @returns A promise that resolves with the final assistant message when the session becomes idle,
|
|
146
|
-
* or undefined if no assistant message was received
|
|
147
|
-
* @throws Error if the timeout is reached before the session becomes idle
|
|
148
|
-
* @throws Error if the session has been disconnected or the connection fails
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* // Send and wait for completion with default 60s timeout
|
|
153
|
-
* const response = await session.sendAndWait({ prompt: "What is 2+2?" });
|
|
154
|
-
* console.log(response?.data.content); // "4"
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
async sendAndWait(options, timeout) {
|
|
125
|
+
async sendAndWait(optionsOrPrompt, timeout) {
|
|
126
|
+
const options = typeof optionsOrPrompt === "string" ? { prompt: optionsOrPrompt } : optionsOrPrompt;
|
|
158
127
|
const effectiveTimeout = timeout ?? 6e4;
|
|
159
128
|
let resolveIdle;
|
|
160
129
|
let rejectWithError;
|
|
@@ -424,6 +393,31 @@ class CopilotSession {
|
|
|
424
393
|
getToolHandler(name) {
|
|
425
394
|
return this.toolHandlers.get(name);
|
|
426
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Registers canvas declarations and handlers for this session.
|
|
398
|
+
*
|
|
399
|
+
* @param canvases - Canvases created via `createCanvas`, or undefined to clear all canvases
|
|
400
|
+
* @internal Called by the SDK when creating/resuming a session with `canvases`.
|
|
401
|
+
*/
|
|
402
|
+
registerCanvases(canvases) {
|
|
403
|
+
this.canvases.clear();
|
|
404
|
+
if (!canvases) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
for (const canvas of canvases) {
|
|
408
|
+
this.canvases.set(canvas.declaration.id, canvas);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Retrieves a registered canvas by id.
|
|
413
|
+
*
|
|
414
|
+
* @param canvasId - The id of the canvas to retrieve
|
|
415
|
+
* @returns The registered Canvas if found, or undefined
|
|
416
|
+
* @internal Used by the SDK's direct `canvas.*` dispatcher.
|
|
417
|
+
*/
|
|
418
|
+
getCanvas(canvasId) {
|
|
419
|
+
return this.canvases.get(canvasId);
|
|
420
|
+
}
|
|
427
421
|
/**
|
|
428
422
|
* Registers command handlers for this session.
|
|
429
423
|
*
|
|
@@ -520,6 +514,24 @@ class CopilotSession {
|
|
|
520
514
|
setCapabilities(capabilities) {
|
|
521
515
|
this._capabilities = capabilities ?? {};
|
|
522
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
* Snapshot of canvas instances that were already open when the session was
|
|
519
|
+
* resumed. Populated from the `session.resume` response; empty for freshly
|
|
520
|
+
* created sessions. Returns a defensive copy — mutating the returned array
|
|
521
|
+
* has no effect on the session.
|
|
522
|
+
*/
|
|
523
|
+
get openCanvases() {
|
|
524
|
+
return [...this.openCanvasInstances];
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Sets the open-canvas snapshot for this session.
|
|
528
|
+
*
|
|
529
|
+
* @param instances - The `openCanvases` array from the `session.resume` response.
|
|
530
|
+
* @internal This method is typically called internally when resuming a session.
|
|
531
|
+
*/
|
|
532
|
+
setOpenCanvases(instances) {
|
|
533
|
+
this.openCanvasInstances = [...instances];
|
|
534
|
+
}
|
|
523
535
|
assertElicitation() {
|
|
524
536
|
if (!this._capabilities.ui?.elicitation) {
|
|
525
537
|
throw new Error(
|
|
@@ -659,33 +671,6 @@ class CopilotSession {
|
|
|
659
671
|
}
|
|
660
672
|
return { sections: result };
|
|
661
673
|
}
|
|
662
|
-
/**
|
|
663
|
-
* Handles a permission request in the v2 protocol format (synchronous RPC).
|
|
664
|
-
* Used as a back-compat adapter when connected to a v2 server.
|
|
665
|
-
*
|
|
666
|
-
* @param request - The permission request data from the CLI
|
|
667
|
-
* @returns A promise that resolves with the permission decision
|
|
668
|
-
* @internal This method is for internal use by the SDK.
|
|
669
|
-
*/
|
|
670
|
-
async _handlePermissionRequestV2(request) {
|
|
671
|
-
if (!this.permissionHandler) {
|
|
672
|
-
return { kind: "user-not-available" };
|
|
673
|
-
}
|
|
674
|
-
try {
|
|
675
|
-
const result = await this.permissionHandler(request, {
|
|
676
|
-
sessionId: this.sessionId
|
|
677
|
-
});
|
|
678
|
-
if (result.kind === "no-result") {
|
|
679
|
-
throw new Error(NO_RESULT_PERMISSION_V2_ERROR);
|
|
680
|
-
}
|
|
681
|
-
return result;
|
|
682
|
-
} catch (error) {
|
|
683
|
-
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
684
|
-
throw error;
|
|
685
|
-
}
|
|
686
|
-
return { kind: "user-not-available" };
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
674
|
/**
|
|
690
675
|
* Handles a user input request from the Copilot CLI.
|
|
691
676
|
*
|
|
@@ -718,8 +703,10 @@ class CopilotSession {
|
|
|
718
703
|
if (!this.hooks) {
|
|
719
704
|
return void 0;
|
|
720
705
|
}
|
|
706
|
+
const normalized = deserializeHookInput(input);
|
|
721
707
|
const handlerMap = {
|
|
722
708
|
preToolUse: this.hooks.onPreToolUse,
|
|
709
|
+
preMcpToolCall: this.hooks.onPreMcpToolCall,
|
|
723
710
|
postToolUse: this.hooks.onPostToolUse,
|
|
724
711
|
userPromptSubmitted: this.hooks.onUserPromptSubmitted,
|
|
725
712
|
sessionStart: this.hooks.onSessionStart,
|
|
@@ -731,7 +718,7 @@ class CopilotSession {
|
|
|
731
718
|
return void 0;
|
|
732
719
|
}
|
|
733
720
|
try {
|
|
734
|
-
const result = await handler(
|
|
721
|
+
const result = await handler(normalized, { sessionId: this.sessionId });
|
|
735
722
|
return result;
|
|
736
723
|
} catch (_error) {
|
|
737
724
|
return void 0;
|
|
@@ -748,7 +735,7 @@ class CopilotSession {
|
|
|
748
735
|
*
|
|
749
736
|
* @example
|
|
750
737
|
* ```typescript
|
|
751
|
-
* const events = await session.
|
|
738
|
+
* const events = await session.getEvents();
|
|
752
739
|
* for (const event of events) {
|
|
753
740
|
* if (event.type === "assistant.message") {
|
|
754
741
|
* console.log("Assistant:", event.data.content);
|
|
@@ -756,7 +743,7 @@ class CopilotSession {
|
|
|
756
743
|
* }
|
|
757
744
|
* ```
|
|
758
745
|
*/
|
|
759
|
-
async
|
|
746
|
+
async getEvents() {
|
|
760
747
|
const response = await this.connection.sendRequest("session.getMessages", {
|
|
761
748
|
sessionId: this.sessionId
|
|
762
749
|
});
|
|
@@ -796,18 +783,6 @@ class CopilotSession {
|
|
|
796
783
|
this.exitPlanModeHandler = void 0;
|
|
797
784
|
this.autoModeSwitchHandler = void 0;
|
|
798
785
|
}
|
|
799
|
-
/**
|
|
800
|
-
* @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
|
|
801
|
-
*
|
|
802
|
-
* Disconnects this session and releases all in-memory resources.
|
|
803
|
-
* Session data on disk is preserved for later resumption.
|
|
804
|
-
*
|
|
805
|
-
* @returns A promise that resolves when the session is disconnected
|
|
806
|
-
* @throws Error if the connection fails
|
|
807
|
-
*/
|
|
808
|
-
async destroy() {
|
|
809
|
-
return this.disconnect();
|
|
810
|
-
}
|
|
811
786
|
/** Enables `await using session = ...` syntax for automatic cleanup. */
|
|
812
787
|
async [Symbol.asyncDispose]() {
|
|
813
788
|
return this.disconnect();
|
|
@@ -894,6 +869,5 @@ function isToolResultObject(value) {
|
|
|
894
869
|
}
|
|
895
870
|
// Annotate the CommonJS export names for ESM import in node:
|
|
896
871
|
0 && (module.exports = {
|
|
897
|
-
CopilotSession
|
|
898
|
-
NO_RESULT_PERMISSION_V2_ERROR
|
|
872
|
+
CopilotSession
|
|
899
873
|
});
|
package/dist/cjs/types.js
CHANGED
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var types_exports = {};
|
|
20
20
|
__export(types_exports, {
|
|
21
|
-
|
|
21
|
+
RuntimeConnection: () => RuntimeConnection,
|
|
22
|
+
SYSTEM_MESSAGE_SECTIONS: () => SYSTEM_MESSAGE_SECTIONS,
|
|
22
23
|
approveAll: () => approveAll,
|
|
23
24
|
convertMcpCallToolResult: () => convertMcpCallToolResult,
|
|
24
25
|
createSessionFsAdapter: () => import_sessionFsProvider.createSessionFsAdapter,
|
|
@@ -27,6 +28,34 @@ __export(types_exports, {
|
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(types_exports);
|
|
29
30
|
var import_sessionFsProvider = require("./sessionFsProvider.js");
|
|
31
|
+
const RuntimeConnection = {
|
|
32
|
+
/**
|
|
33
|
+
* Spawn a runtime child process and communicate over its stdin/stdout.
|
|
34
|
+
* This is the default if no {@link CopilotClientOptions.connection} is set.
|
|
35
|
+
*/
|
|
36
|
+
forStdio(opts = {}) {
|
|
37
|
+
return { kind: "stdio", path: opts.path, args: opts.args };
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Spawn a runtime child process that listens on a TCP socket and connect to it.
|
|
41
|
+
*/
|
|
42
|
+
forTcp(opts = {}) {
|
|
43
|
+
return {
|
|
44
|
+
kind: "tcp",
|
|
45
|
+
port: opts.port,
|
|
46
|
+
connectionToken: opts.connectionToken,
|
|
47
|
+
path: opts.path,
|
|
48
|
+
args: opts.args
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Connect to an already-running runtime at the given URL. The SDK does not
|
|
53
|
+
* spawn a process in this mode.
|
|
54
|
+
*/
|
|
55
|
+
forUri(url, opts = {}) {
|
|
56
|
+
return { kind: "uri", url, connectionToken: opts.connectionToken };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
30
59
|
function convertMcpCallToolResult(callResult) {
|
|
31
60
|
const textParts = [];
|
|
32
61
|
const binaryResults = [];
|
|
@@ -72,7 +101,7 @@ function convertMcpCallToolResult(callResult) {
|
|
|
72
101
|
function defineTool(name, config) {
|
|
73
102
|
return { name, ...config };
|
|
74
103
|
}
|
|
75
|
-
const
|
|
104
|
+
const SYSTEM_MESSAGE_SECTIONS = {
|
|
76
105
|
identity: { description: "Agent identity preamble and mode statement" },
|
|
77
106
|
tone: { description: "Response style, conciseness rules, output formatting preferences" },
|
|
78
107
|
tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
|
|
@@ -82,6 +111,9 @@ const SYSTEM_PROMPT_SECTIONS = {
|
|
|
82
111
|
safety: { description: "Environment limitations, prohibited actions, security policies" },
|
|
83
112
|
tool_instructions: { description: "Per-tool usage instructions" },
|
|
84
113
|
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
114
|
+
runtime_instructions: {
|
|
115
|
+
description: "Runtime-provided context and instructions (e.g. system notifications, memories, workspace context, mode-specific instructions, content-exclusion policy)"
|
|
116
|
+
},
|
|
85
117
|
last_instructions: {
|
|
86
118
|
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
87
119
|
}
|
|
@@ -92,7 +124,8 @@ const defaultJoinSessionPermissionHandler = () => ({
|
|
|
92
124
|
});
|
|
93
125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
126
|
0 && (module.exports = {
|
|
95
|
-
|
|
127
|
+
RuntimeConnection,
|
|
128
|
+
SYSTEM_MESSAGE_SECTIONS,
|
|
96
129
|
approveAll,
|
|
97
130
|
convertMcpCallToolResult,
|
|
98
131
|
createSessionFsAdapter,
|