@github/copilot-sdk 1.0.0-beta.6 → 1.0.0-beta.8
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 +3 -7
- package/dist/canvas.d.ts +103 -0
- package/dist/canvas.js +49 -0
- package/dist/cjs/canvas.js +75 -0
- package/dist/cjs/client.js +16 -126
- package/dist/cjs/extension.js +7 -0
- package/dist/cjs/generated/rpc.js +109 -2
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/session.js +84 -32
- package/dist/cjs/types.js +6 -3
- package/dist/client.d.ts +1 -26
- package/dist/client.js +17 -127
- package/dist/extension.d.ts +3 -1
- package/dist/extension.js +8 -0
- package/dist/generated/rpc.d.ts +1282 -248
- package/dist/generated/rpc.js +109 -2
- package/dist/generated/session-events.d.ts +485 -88
- package/dist/index.d.ts +3 -2
- package/dist/index.js +10 -2
- package/dist/session.d.ts +10 -0
- package/dist/session.js +84 -31
- package/dist/types.d.ts +52 -9
- package/dist/types.js +5 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -131,10 +131,6 @@ Resume an existing session. Returns the session with `workspacePath` populated i
|
|
|
131
131
|
|
|
132
132
|
Ping the server to check connectivity.
|
|
133
133
|
|
|
134
|
-
##### `getState(): ConnectionState`
|
|
135
|
-
|
|
136
|
-
Get current connection state.
|
|
137
|
-
|
|
138
134
|
##### `listSessions(filter?: SessionListFilter): Promise<SessionMetadata[]>`
|
|
139
135
|
|
|
140
136
|
List all available sessions. Optionally filter by working directory context.
|
|
@@ -573,8 +569,8 @@ The SDK auto-injects environment context, tool instructions, and security guardr
|
|
|
573
569
|
Use `mode: "customize"` to selectively override individual sections of the prompt while preserving the rest:
|
|
574
570
|
|
|
575
571
|
```typescript
|
|
576
|
-
import {
|
|
577
|
-
import type { SectionOverride,
|
|
572
|
+
import { SYSTEM_MESSAGE_SECTIONS } from "@github/copilot-sdk";
|
|
573
|
+
import type { SectionOverride, SystemMessageSection } from "@github/copilot-sdk";
|
|
578
574
|
|
|
579
575
|
const session = await client.createSession({
|
|
580
576
|
model: "gpt-5",
|
|
@@ -597,7 +593,7 @@ const session = await client.createSession({
|
|
|
597
593
|
});
|
|
598
594
|
```
|
|
599
595
|
|
|
600
|
-
Available section IDs: `identity`, `tone`, `tool_efficiency`, `environment_context`, `code_change_rules`, `guidelines`, `safety`, `tool_instructions`, `custom_instructions`, `last_instructions`. Use the `
|
|
596
|
+
Available section IDs: `identity`, `tone`, `tool_efficiency`, `environment_context`, `code_change_rules`, `guidelines`, `safety`, `tool_instructions`, `custom_instructions`, `runtime_instructions`, `last_instructions`. Use the `SYSTEM_MESSAGE_SECTIONS` constant for descriptions of each section.
|
|
601
597
|
|
|
602
598
|
Each section override supports four actions:
|
|
603
599
|
|
package/dist/canvas.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CanvasJsonSchema, CanvasProviderCloseRequest, CanvasProviderInvokeActionRequest, CanvasProviderOpenRequest, CanvasProviderOpenResult } from "./generated/rpc.js";
|
|
2
|
+
export type { CanvasJsonSchema, CanvasHostContext } from "./generated/rpc.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extension-owned canvases declared via
|
|
5
|
+
* `joinSession({ canvases: [createCanvas({...})] })`.
|
|
6
|
+
*
|
|
7
|
+
* The runtime sends provider callbacks as `canvas.open`, `canvas.close`, and
|
|
8
|
+
* `canvas.invokeAction` JSON-RPC requests via the codegen client session API
|
|
9
|
+
* pipeline. The SDK routes those requests by `canvasId` to the in-process
|
|
10
|
+
* handlers bound by `createCanvas`. Re-opening with an existing `instanceId`
|
|
11
|
+
* is how the host focuses an existing panel; reload is a renderer-only concern.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* A single agent-callable action contributed by a canvas. The metadata
|
|
15
|
+
* (`name`, `description`, `inputSchema`) is serialized over the wire on
|
|
16
|
+
* `session.create` / `session.resume`; the `handler` closure is stripped
|
|
17
|
+
* before the declaration is sent and dispatched in-process by the SDK.
|
|
18
|
+
*
|
|
19
|
+
* Names MUST NOT start with `canvas.` — that prefix is reserved for
|
|
20
|
+
* lifecycle verbs.
|
|
21
|
+
*/
|
|
22
|
+
export interface CanvasAction {
|
|
23
|
+
/** Action identifier, unique within the canvas. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Description shown to the model when picking an action. */
|
|
26
|
+
description?: string;
|
|
27
|
+
/** Optional JSON Schema for the action's `input` payload. */
|
|
28
|
+
inputSchema?: CanvasJsonSchema;
|
|
29
|
+
/** Required per-action dispatch handler. */
|
|
30
|
+
handler: (ctx: CanvasProviderInvokeActionRequest) => Promise<unknown> | unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Declarative metadata for a single canvas, serialized over the wire on
|
|
34
|
+
* `session.create` / `session.resume`.
|
|
35
|
+
*/
|
|
36
|
+
export interface CanvasDeclaration {
|
|
37
|
+
/** Canvas id, unique within the declaring connection. */
|
|
38
|
+
id: string;
|
|
39
|
+
/** Human-readable label shown in discovery and host UI chrome. */
|
|
40
|
+
displayName: string;
|
|
41
|
+
/** Short, single-sentence description shown to the agent in canvas catalogs. */
|
|
42
|
+
description: string;
|
|
43
|
+
/** Optional JSON Schema for the `input` payload accepted by `canvas.open`. */
|
|
44
|
+
inputSchema?: CanvasJsonSchema;
|
|
45
|
+
/** Agent-invocable actions exposed via `invoke_canvas_action`. */
|
|
46
|
+
actions?: Omit<CanvasAction, "handler">[];
|
|
47
|
+
}
|
|
48
|
+
/** Structured error returned from canvas handlers. */
|
|
49
|
+
export declare class CanvasError extends Error {
|
|
50
|
+
readonly code: string;
|
|
51
|
+
constructor(code: string, message: string);
|
|
52
|
+
/** Default error when an action is declared but no `handler` is wired. */
|
|
53
|
+
static noHandler(): CanvasError;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Options accepted by {@link createCanvas}. Combines the declarative
|
|
57
|
+
* {@link CanvasDeclaration} fields with the in-process handler closures.
|
|
58
|
+
*/
|
|
59
|
+
export interface CanvasOptions {
|
|
60
|
+
/** @see CanvasDeclaration.id */
|
|
61
|
+
id: string;
|
|
62
|
+
/** @see CanvasDeclaration.displayName */
|
|
63
|
+
displayName: string;
|
|
64
|
+
/** @see CanvasDeclaration.description */
|
|
65
|
+
description: string;
|
|
66
|
+
/** @see CanvasDeclaration.inputSchema */
|
|
67
|
+
inputSchema?: CanvasJsonSchema;
|
|
68
|
+
/**
|
|
69
|
+
* Agent-invocable actions exposed via `invoke_canvas_action`. Each action
|
|
70
|
+
* carries its own required `handler`; the action's wire metadata
|
|
71
|
+
* (`name`, `description`, `inputSchema`) is what reaches the runtime.
|
|
72
|
+
*/
|
|
73
|
+
actions?: CanvasAction[];
|
|
74
|
+
/** Required. Open a new canvas instance. */
|
|
75
|
+
open: (ctx: CanvasProviderOpenRequest) => Promise<CanvasProviderOpenResult> | CanvasProviderOpenResult;
|
|
76
|
+
/**
|
|
77
|
+
* Optional. Notified when a canvas instance is closed by the user, the
|
|
78
|
+
* agent, or the host. Fire-and-forget: the return value is ignored and
|
|
79
|
+
* errors are logged but not surfaced to the runtime.
|
|
80
|
+
*/
|
|
81
|
+
onClose?: (ctx: CanvasProviderCloseRequest) => Promise<void> | void;
|
|
82
|
+
}
|
|
83
|
+
/** A registered canvas: declarative metadata + in-process handler closures.
|
|
84
|
+
*
|
|
85
|
+
* Node intentionally uses a per-canvas factory pattern (mirroring
|
|
86
|
+
* {@link https://github.com/github/copilot-sdk | `DefineTool`}'s co-location
|
|
87
|
+
* ergonomics) where other SDKs (Rust, Python, Go, .NET) expose a single
|
|
88
|
+
* `CanvasHandler` per session that switches on `canvasId`. Both shapes target
|
|
89
|
+
* the same JSON-RPC wire protocol; the divergence is API ergonomics only.
|
|
90
|
+
*/
|
|
91
|
+
export declare class Canvas {
|
|
92
|
+
readonly declaration: CanvasDeclaration;
|
|
93
|
+
readonly open: NonNullable<CanvasOptions["open"]>;
|
|
94
|
+
readonly onClose?: CanvasOptions["onClose"];
|
|
95
|
+
}
|
|
96
|
+
/** Create a canvas declaration with bound in-process handlers.
|
|
97
|
+
*
|
|
98
|
+
* Node intentionally uses this per-canvas factory pattern (mirroring
|
|
99
|
+
* `DefineTool`'s co-location ergonomics) where other SDKs (Rust, Python, Go,
|
|
100
|
+
* .NET) expose a single `CanvasHandler` per session that switches on
|
|
101
|
+
* `canvasId`. Both shapes target the same JSON-RPC wire protocol.
|
|
102
|
+
*/
|
|
103
|
+
export declare function createCanvas(options: CanvasOptions): Canvas;
|
package/dist/canvas.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
class CanvasError extends Error {
|
|
2
|
+
constructor(code, message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.code = code;
|
|
5
|
+
this.name = "CanvasError";
|
|
6
|
+
}
|
|
7
|
+
/** Default error when an action is declared but no `handler` is wired. */
|
|
8
|
+
static noHandler() {
|
|
9
|
+
return new CanvasError(
|
|
10
|
+
"canvas_action_no_handler",
|
|
11
|
+
"No handler implemented for this canvas action"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class Canvas {
|
|
16
|
+
declaration;
|
|
17
|
+
open;
|
|
18
|
+
onClose;
|
|
19
|
+
/** @internal */
|
|
20
|
+
actionHandlers;
|
|
21
|
+
/** @internal */
|
|
22
|
+
constructor(options) {
|
|
23
|
+
const actionHandlers = /* @__PURE__ */ new Map();
|
|
24
|
+
const wireActions = options.actions?.map(
|
|
25
|
+
({ handler, ...wire }) => {
|
|
26
|
+
actionHandlers.set(wire.name, handler);
|
|
27
|
+
return wire;
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
this.declaration = {
|
|
31
|
+
id: options.id,
|
|
32
|
+
displayName: options.displayName,
|
|
33
|
+
description: options.description,
|
|
34
|
+
inputSchema: options.inputSchema,
|
|
35
|
+
actions: wireActions
|
|
36
|
+
};
|
|
37
|
+
this.open = options.open;
|
|
38
|
+
this.onClose = options.onClose;
|
|
39
|
+
this.actionHandlers = actionHandlers;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function createCanvas(options) {
|
|
43
|
+
return new Canvas(options);
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
Canvas,
|
|
47
|
+
CanvasError,
|
|
48
|
+
createCanvas
|
|
49
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
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 canvas_exports = {};
|
|
20
|
+
__export(canvas_exports, {
|
|
21
|
+
Canvas: () => Canvas,
|
|
22
|
+
CanvasError: () => CanvasError,
|
|
23
|
+
createCanvas: () => createCanvas
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(canvas_exports);
|
|
26
|
+
class CanvasError extends Error {
|
|
27
|
+
constructor(code, message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.name = "CanvasError";
|
|
31
|
+
}
|
|
32
|
+
/** Default error when an action is declared but no `handler` is wired. */
|
|
33
|
+
static noHandler() {
|
|
34
|
+
return new CanvasError(
|
|
35
|
+
"canvas_action_no_handler",
|
|
36
|
+
"No handler implemented for this canvas action"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class Canvas {
|
|
41
|
+
declaration;
|
|
42
|
+
open;
|
|
43
|
+
onClose;
|
|
44
|
+
/** @internal */
|
|
45
|
+
actionHandlers;
|
|
46
|
+
/** @internal */
|
|
47
|
+
constructor(options) {
|
|
48
|
+
const actionHandlers = /* @__PURE__ */ new Map();
|
|
49
|
+
const wireActions = options.actions?.map(
|
|
50
|
+
({ handler, ...wire }) => {
|
|
51
|
+
actionHandlers.set(wire.name, handler);
|
|
52
|
+
return wire;
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
this.declaration = {
|
|
56
|
+
id: options.id,
|
|
57
|
+
displayName: options.displayName,
|
|
58
|
+
description: options.description,
|
|
59
|
+
inputSchema: options.inputSchema,
|
|
60
|
+
actions: wireActions
|
|
61
|
+
};
|
|
62
|
+
this.open = options.open;
|
|
63
|
+
this.onClose = options.onClose;
|
|
64
|
+
this.actionHandlers = actionHandlers;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function createCanvas(options) {
|
|
68
|
+
return new Canvas(options);
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
Canvas,
|
|
73
|
+
CanvasError,
|
|
74
|
+
createCanvas
|
|
75
|
+
});
|
package/dist/cjs/client.js
CHANGED
|
@@ -36,7 +36,7 @@ var import_sessionFsProvider = require("./sessionFsProvider.js");
|
|
|
36
36
|
var import_telemetry = require("./telemetry.js");
|
|
37
37
|
var import_types = require("./types.js");
|
|
38
38
|
const import_meta = {};
|
|
39
|
-
const MIN_PROTOCOL_VERSION =
|
|
39
|
+
const MIN_PROTOCOL_VERSION = 3;
|
|
40
40
|
function isZodSchema(value) {
|
|
41
41
|
return value != null && typeof value === "object" && "toJSONSchema" in value && typeof value.toJSONSchema === "function";
|
|
42
42
|
}
|
|
@@ -572,6 +572,7 @@ class CopilotClient {
|
|
|
572
572
|
this.onGetTraceContext
|
|
573
573
|
);
|
|
574
574
|
session.registerTools(config.tools);
|
|
575
|
+
session.registerCanvases(config.canvases);
|
|
575
576
|
session.registerCommands(config.commands);
|
|
576
577
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
577
578
|
if (config.onUserInputRequest) {
|
|
@@ -614,6 +615,10 @@ class CopilotClient {
|
|
|
614
615
|
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
615
616
|
skipPermission: tool.skipPermission
|
|
616
617
|
})),
|
|
618
|
+
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
619
|
+
requestCanvasRenderer: config.requestCanvasRenderer,
|
|
620
|
+
requestExtensions: config.requestExtensions,
|
|
621
|
+
extensionInfo: config.extensionInfo,
|
|
617
622
|
commands: config.commands?.map((cmd) => ({
|
|
618
623
|
name: cmd.name,
|
|
619
624
|
description: cmd.description
|
|
@@ -624,7 +629,7 @@ class CopilotClient {
|
|
|
624
629
|
provider: config.provider,
|
|
625
630
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
626
631
|
modelCapabilities: config.modelCapabilities,
|
|
627
|
-
requestPermission:
|
|
632
|
+
requestPermission: !!config.onPermissionRequest,
|
|
628
633
|
requestUserInput: !!config.onUserInputRequest,
|
|
629
634
|
requestElicitation: !!config.onElicitationRequest,
|
|
630
635
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
@@ -692,6 +697,7 @@ class CopilotClient {
|
|
|
692
697
|
this.onGetTraceContext
|
|
693
698
|
);
|
|
694
699
|
session.registerTools(config.tools);
|
|
700
|
+
session.registerCanvases(config.canvases);
|
|
695
701
|
session.registerCommands(config.commands);
|
|
696
702
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
697
703
|
if (config.onUserInputRequest) {
|
|
@@ -738,6 +744,10 @@ class CopilotClient {
|
|
|
738
744
|
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
739
745
|
skipPermission: tool.skipPermission
|
|
740
746
|
})),
|
|
747
|
+
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
748
|
+
requestCanvasRenderer: config.requestCanvasRenderer,
|
|
749
|
+
requestExtensions: config.requestExtensions,
|
|
750
|
+
extensionInfo: config.extensionInfo,
|
|
741
751
|
commands: config.commands?.map((cmd) => ({
|
|
742
752
|
name: cmd.name,
|
|
743
753
|
description: cmd.description
|
|
@@ -767,32 +777,19 @@ class CopilotClient {
|
|
|
767
777
|
suppressResumeEvent: config.suppressResumeEvent,
|
|
768
778
|
continuePendingWork: config.continuePendingWork,
|
|
769
779
|
gitHubToken: config.gitHubToken,
|
|
770
|
-
remoteSession: config.remoteSession
|
|
780
|
+
remoteSession: config.remoteSession,
|
|
781
|
+
openCanvases: config.openCanvases
|
|
771
782
|
});
|
|
772
|
-
const { workspacePath, capabilities } = response;
|
|
783
|
+
const { workspacePath, capabilities, openCanvases } = response;
|
|
773
784
|
session["_workspacePath"] = workspacePath;
|
|
774
785
|
session.setCapabilities(capabilities);
|
|
786
|
+
session.setOpenCanvases(openCanvases ?? []);
|
|
775
787
|
} catch (e) {
|
|
776
788
|
this.sessions.delete(sessionId);
|
|
777
789
|
throw e;
|
|
778
790
|
}
|
|
779
791
|
return session;
|
|
780
792
|
}
|
|
781
|
-
/**
|
|
782
|
-
* Gets the current connection state of the client.
|
|
783
|
-
*
|
|
784
|
-
* @returns The current connection state: "disconnected", "connecting", "connected", or "error"
|
|
785
|
-
*
|
|
786
|
-
* @example
|
|
787
|
-
* ```typescript
|
|
788
|
-
* if (client.getState() === "connected") {
|
|
789
|
-
* const session = await client.createSession({ onPermissionRequest: approveAll });
|
|
790
|
-
* }
|
|
791
|
-
* ```
|
|
792
|
-
*/
|
|
793
|
-
getState() {
|
|
794
|
-
return this.state;
|
|
795
|
-
}
|
|
796
793
|
/**
|
|
797
794
|
* Sends a ping request to the server to verify connectivity.
|
|
798
795
|
*
|
|
@@ -1381,14 +1378,6 @@ stderr: ${stderrOutput}`
|
|
|
1381
1378
|
this.connection.onNotification("session.lifecycle", (notification) => {
|
|
1382
1379
|
this.handleSessionLifecycleNotification(notification);
|
|
1383
1380
|
});
|
|
1384
|
-
this.connection.onRequest(
|
|
1385
|
-
"tool.call",
|
|
1386
|
-
async (params) => await this.handleToolCallRequestV2(params)
|
|
1387
|
-
);
|
|
1388
|
-
this.connection.onRequest(
|
|
1389
|
-
"permission.request",
|
|
1390
|
-
async (params) => await this.handlePermissionRequestV2(params)
|
|
1391
|
-
);
|
|
1392
1381
|
this.connection.onRequest(
|
|
1393
1382
|
"userInput.request",
|
|
1394
1383
|
async (params) => await this.handleUserInputRequest(params)
|
|
@@ -1530,105 +1519,6 @@ stderr: ${stderrOutput}`
|
|
|
1530
1519
|
}
|
|
1531
1520
|
return await session._handleSystemMessageTransform(params.sections);
|
|
1532
1521
|
}
|
|
1533
|
-
// ========================================================================
|
|
1534
|
-
// Protocol v2 backward-compatibility adapters
|
|
1535
|
-
// ========================================================================
|
|
1536
|
-
/**
|
|
1537
|
-
* Handles a v2-style tool.call RPC request from the server.
|
|
1538
|
-
* Looks up the session and tool handler, executes it, and returns the result
|
|
1539
|
-
* in the v2 response format.
|
|
1540
|
-
*/
|
|
1541
|
-
async handleToolCallRequestV2(params) {
|
|
1542
|
-
if (!params || typeof params.sessionId !== "string" || typeof params.toolCallId !== "string" || typeof params.toolName !== "string") {
|
|
1543
|
-
throw new Error("Invalid tool call payload");
|
|
1544
|
-
}
|
|
1545
|
-
const session = this.sessions.get(params.sessionId);
|
|
1546
|
-
if (!session) {
|
|
1547
|
-
throw new Error(`Unknown session ${params.sessionId}`);
|
|
1548
|
-
}
|
|
1549
|
-
const handler = session.getToolHandler(params.toolName);
|
|
1550
|
-
if (!handler) {
|
|
1551
|
-
return {
|
|
1552
|
-
result: {
|
|
1553
|
-
textResultForLlm: `Tool '${params.toolName}' is not supported by this client instance.`,
|
|
1554
|
-
resultType: "failure",
|
|
1555
|
-
error: `tool '${params.toolName}' not supported`,
|
|
1556
|
-
toolTelemetry: {}
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
try {
|
|
1561
|
-
const traceparent = params.traceparent;
|
|
1562
|
-
const tracestate = params.tracestate;
|
|
1563
|
-
const invocation = {
|
|
1564
|
-
sessionId: params.sessionId,
|
|
1565
|
-
toolCallId: params.toolCallId,
|
|
1566
|
-
toolName: params.toolName,
|
|
1567
|
-
arguments: params.arguments,
|
|
1568
|
-
traceparent,
|
|
1569
|
-
tracestate
|
|
1570
|
-
};
|
|
1571
|
-
const result = await handler(params.arguments, invocation);
|
|
1572
|
-
return { result: this.normalizeToolResultV2(result) };
|
|
1573
|
-
} catch (error) {
|
|
1574
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1575
|
-
return {
|
|
1576
|
-
result: {
|
|
1577
|
-
textResultForLlm: "Invoking this tool produced an error. Detailed information is not available.",
|
|
1578
|
-
resultType: "failure",
|
|
1579
|
-
error: message,
|
|
1580
|
-
toolTelemetry: {}
|
|
1581
|
-
}
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Handles a v2-style permission.request RPC request from the server.
|
|
1587
|
-
*/
|
|
1588
|
-
async handlePermissionRequestV2(params) {
|
|
1589
|
-
if (!params || typeof params.sessionId !== "string" || !params.permissionRequest) {
|
|
1590
|
-
throw new Error("Invalid permission request payload");
|
|
1591
|
-
}
|
|
1592
|
-
const session = this.sessions.get(params.sessionId);
|
|
1593
|
-
if (!session) {
|
|
1594
|
-
throw new Error(`Session not found: ${params.sessionId}`);
|
|
1595
|
-
}
|
|
1596
|
-
try {
|
|
1597
|
-
const result = await session._handlePermissionRequestV2(params.permissionRequest);
|
|
1598
|
-
return { result };
|
|
1599
|
-
} catch (error) {
|
|
1600
|
-
if (error instanceof Error && error.message === import_session.NO_RESULT_PERMISSION_V2_ERROR) {
|
|
1601
|
-
throw error;
|
|
1602
|
-
}
|
|
1603
|
-
return {
|
|
1604
|
-
result: {
|
|
1605
|
-
kind: "user-not-available"
|
|
1606
|
-
}
|
|
1607
|
-
};
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
normalizeToolResultV2(result) {
|
|
1611
|
-
if (result === void 0 || result === null) {
|
|
1612
|
-
return {
|
|
1613
|
-
textResultForLlm: "Tool returned no result",
|
|
1614
|
-
resultType: "failure",
|
|
1615
|
-
error: "tool returned no result",
|
|
1616
|
-
toolTelemetry: {}
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
if (this.isToolResultObject(result)) {
|
|
1620
|
-
return result;
|
|
1621
|
-
}
|
|
1622
|
-
const textResult = typeof result === "string" ? result : JSON.stringify(result);
|
|
1623
|
-
return {
|
|
1624
|
-
textResultForLlm: textResult,
|
|
1625
|
-
resultType: "success",
|
|
1626
|
-
toolTelemetry: {}
|
|
1627
|
-
};
|
|
1628
|
-
}
|
|
1629
|
-
isToolResultObject(value) {
|
|
1630
|
-
return typeof value === "object" && value !== null && "textResultForLlm" in value && typeof value.textResultForLlm === "string" && "resultType" in value;
|
|
1631
|
-
}
|
|
1632
1522
|
}
|
|
1633
1523
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1634
1524
|
0 && (module.exports = {
|
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) {
|
|
@@ -39,5 +43,8 @@ async function joinSession(config = {}) {
|
|
|
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
|
});
|
|
@@ -275,7 +275,7 @@ function createServerRpc(connection) {
|
|
|
275
275
|
*
|
|
276
276
|
* @param params Session metadata records to enrich with summary and context information.
|
|
277
277
|
*
|
|
278
|
-
* @returns The
|
|
278
|
+
* @returns The enriched metadata records, with summary and context fields backfilled where available. Sessions confirmed empty and unnamed are omitted.
|
|
279
279
|
*/
|
|
280
280
|
enrichMetadata: async (params) => connection.sendRequest("sessions.enrichMetadata", params),
|
|
281
281
|
/**
|
|
@@ -371,6 +371,43 @@ function createSessionRpc(connection, sessionId) {
|
|
|
371
371
|
setCredentials: async (params) => connection.sendRequest("session.auth.setCredentials", { sessionId, ...params })
|
|
372
372
|
},
|
|
373
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 */
|
|
374
411
|
model: {
|
|
375
412
|
/**
|
|
376
413
|
* Gets the currently selected model for the session.
|
|
@@ -501,7 +538,15 @@ function createSessionRpc(connection, sessionId) {
|
|
|
501
538
|
*
|
|
502
539
|
* @returns Descriptor for the saved paste file, or null when the workspace is unavailable.
|
|
503
540
|
*/
|
|
504
|
-
saveLargePaste: async (params) => connection.sendRequest("session.workspaces.saveLargePaste", { sessionId, ...params })
|
|
541
|
+
saveLargePaste: async (params) => connection.sendRequest("session.workspaces.saveLargePaste", { sessionId, ...params }),
|
|
542
|
+
/**
|
|
543
|
+
* Computes a diff for the session workspace.
|
|
544
|
+
*
|
|
545
|
+
* @param params Parameters for computing a workspace diff.
|
|
546
|
+
*
|
|
547
|
+
* @returns Workspace diff result for the requested mode.
|
|
548
|
+
*/
|
|
549
|
+
diff: async (params) => connection.sendRequest("session.workspaces.diff", { sessionId, ...params })
|
|
505
550
|
},
|
|
506
551
|
/** @experimental */
|
|
507
552
|
instructions: {
|
|
@@ -738,6 +783,53 @@ function createSessionRpc(connection, sessionId) {
|
|
|
738
783
|
* @returns OAuth authorization URL the caller should open, or empty when cached tokens already authenticated the server.
|
|
739
784
|
*/
|
|
740
785
|
login: async (params) => connection.sendRequest("session.mcp.oauth.login", { sessionId, ...params })
|
|
786
|
+
},
|
|
787
|
+
/** @experimental */
|
|
788
|
+
apps: {
|
|
789
|
+
/**
|
|
790
|
+
* Fetch an MCP resource (typically a `ui://` MCP App bundle, per SEP-1865) from a connected server. Requires the `mcp-apps` session capability.
|
|
791
|
+
*
|
|
792
|
+
* @param params MCP server and resource URI to fetch.
|
|
793
|
+
*
|
|
794
|
+
* @returns Resource contents returned by the MCP server.
|
|
795
|
+
*/
|
|
796
|
+
readResource: async (params) => connection.sendRequest("session.mcp.apps.readResource", { sessionId, ...params }),
|
|
797
|
+
/**
|
|
798
|
+
* 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"`.
|
|
799
|
+
*
|
|
800
|
+
* @param params MCP server to list app-callable tools for.
|
|
801
|
+
*
|
|
802
|
+
* @returns App-callable tools from the named MCP server.
|
|
803
|
+
*/
|
|
804
|
+
listTools: async (params) => connection.sendRequest("session.mcp.apps.listTools", { sessionId, ...params }),
|
|
805
|
+
/**
|
|
806
|
+
* 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`.
|
|
807
|
+
*
|
|
808
|
+
* @param params MCP server, tool name, and arguments to invoke from an MCP App view.
|
|
809
|
+
*
|
|
810
|
+
* @returns Standard MCP CallToolResult
|
|
811
|
+
*/
|
|
812
|
+
callTool: async (params) => connection.sendRequest("session.mcp.apps.callTool", { sessionId, ...params }),
|
|
813
|
+
/**
|
|
814
|
+
* 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.
|
|
815
|
+
*
|
|
816
|
+
* @param params Host context to advertise to MCP App guests.
|
|
817
|
+
*/
|
|
818
|
+
setHostContext: async (params) => connection.sendRequest("session.mcp.apps.setHostContext", { sessionId, ...params }),
|
|
819
|
+
/**
|
|
820
|
+
* Read the current host context advertised to MCP App guests.
|
|
821
|
+
*
|
|
822
|
+
* @returns Current host context advertised to MCP App guests.
|
|
823
|
+
*/
|
|
824
|
+
getHostContext: async () => connection.sendRequest("session.mcp.apps.getHostContext", { sessionId }),
|
|
825
|
+
/**
|
|
826
|
+
* 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.
|
|
827
|
+
*
|
|
828
|
+
* @param params MCP server to diagnose MCP Apps wiring for.
|
|
829
|
+
*
|
|
830
|
+
* @returns Diagnostic snapshot of MCP Apps wiring for the named server.
|
|
831
|
+
*/
|
|
832
|
+
diagnose: async (params) => connection.sendRequest("session.mcp.apps.diagnose", { sessionId, ...params })
|
|
741
833
|
}
|
|
742
834
|
},
|
|
743
835
|
/** @experimental */
|
|
@@ -1374,6 +1466,21 @@ function registerClientSessionApiHandlers(connection, getHandlers) {
|
|
|
1374
1466
|
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
1375
1467
|
return handler.sqliteExists(params);
|
|
1376
1468
|
});
|
|
1469
|
+
connection.onRequest("canvas.open", async (params) => {
|
|
1470
|
+
const handler = getHandlers(params.sessionId).canvas;
|
|
1471
|
+
if (!handler) throw new Error(`No canvas handler registered for session: ${params.sessionId}`);
|
|
1472
|
+
return handler.open(params);
|
|
1473
|
+
});
|
|
1474
|
+
connection.onRequest("canvas.close", async (params) => {
|
|
1475
|
+
const handler = getHandlers(params.sessionId).canvas;
|
|
1476
|
+
if (!handler) throw new Error(`No canvas handler registered for session: ${params.sessionId}`);
|
|
1477
|
+
return handler.close(params);
|
|
1478
|
+
});
|
|
1479
|
+
connection.onRequest("canvas.invokeAction", async (params) => {
|
|
1480
|
+
const handler = getHandlers(params.sessionId).canvas;
|
|
1481
|
+
if (!handler) throw new Error(`No canvas handler registered for session: ${params.sessionId}`);
|
|
1482
|
+
return handler.invokeAction(params);
|
|
1483
|
+
});
|
|
1377
1484
|
}
|
|
1378
1485
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1379
1486
|
0 && (module.exports = {
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,12 +18,15 @@ 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
25
|
RuntimeConnection: () => import_types.RuntimeConnection,
|
|
24
|
-
|
|
26
|
+
SYSTEM_MESSAGE_SECTIONS: () => import_types2.SYSTEM_MESSAGE_SECTIONS,
|
|
25
27
|
approveAll: () => import_types2.approveAll,
|
|
26
28
|
convertMcpCallToolResult: () => import_types2.convertMcpCallToolResult,
|
|
29
|
+
createCanvas: () => import_canvas.createCanvas,
|
|
27
30
|
createSessionFsAdapter: () => import_types2.createSessionFsAdapter,
|
|
28
31
|
defineTool: () => import_types2.defineTool
|
|
29
32
|
});
|
|
@@ -31,15 +34,19 @@ module.exports = __toCommonJS(index_exports);
|
|
|
31
34
|
var import_client = require("./client.js");
|
|
32
35
|
var import_types = require("./types.js");
|
|
33
36
|
var import_session = require("./session.js");
|
|
37
|
+
var import_canvas = require("./canvas.js");
|
|
34
38
|
var import_types2 = require("./types.js");
|
|
35
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
40
|
0 && (module.exports = {
|
|
41
|
+
Canvas,
|
|
42
|
+
CanvasError,
|
|
37
43
|
CopilotClient,
|
|
38
44
|
CopilotSession,
|
|
39
45
|
RuntimeConnection,
|
|
40
|
-
|
|
46
|
+
SYSTEM_MESSAGE_SECTIONS,
|
|
41
47
|
approveAll,
|
|
42
48
|
convertMcpCallToolResult,
|
|
49
|
+
createCanvas,
|
|
43
50
|
createSessionFsAdapter,
|
|
44
51
|
defineTool
|
|
45
52
|
});
|