@github/copilot-sdk 1.0.0-beta.8 → 1.0.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/README.md +25 -10
- package/dist/canvas.d.ts +26 -3
- package/dist/cjs/client.js +273 -42
- package/dist/cjs/extension.js +3 -1
- package/dist/cjs/generated/rpc.js +83 -17
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/session.js +34 -5
- package/dist/cjs/toolSet.js +107 -0
- package/dist/client.d.ts +17 -25
- package/dist/client.js +273 -42
- package/dist/extension.d.ts +1 -1
- package/dist/extension.js +3 -1
- package/dist/generated/rpc.d.ts +949 -303
- package/dist/generated/rpc.js +83 -17
- package/dist/generated/session-events.d.ts +267 -22
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -0
- package/dist/session.d.ts +9 -5
- package/dist/session.js +34 -5
- package/dist/toolSet.d.ts +75 -0
- package/dist/toolSet.js +82 -0
- package/dist/types.d.ts +306 -8
- package/docs/agent-author.md +31 -7
- package/docs/examples.md +26 -16
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CopilotClient } from "./client.js";
|
|
2
2
|
import { RuntimeConnection } from "./types.js";
|
|
3
|
+
import { BuiltInTools, ToolSet } from "./toolSet.js";
|
|
3
4
|
import { CopilotSession } from "./session.js";
|
|
4
5
|
import {
|
|
5
6
|
Canvas,
|
|
@@ -14,12 +15,14 @@ import {
|
|
|
14
15
|
SYSTEM_MESSAGE_SECTIONS
|
|
15
16
|
} from "./types.js";
|
|
16
17
|
export {
|
|
18
|
+
BuiltInTools,
|
|
17
19
|
Canvas,
|
|
18
20
|
CanvasError,
|
|
19
21
|
CopilotClient,
|
|
20
22
|
CopilotSession,
|
|
21
23
|
RuntimeConnection,
|
|
22
24
|
SYSTEM_MESSAGE_SECTIONS,
|
|
25
|
+
ToolSet,
|
|
23
26
|
approveAll,
|
|
24
27
|
convertMcpCallToolResult,
|
|
25
28
|
createCanvas,
|
package/dist/session.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSessionRpc } from "./generated/rpc.js";
|
|
2
2
|
import type { OpenCanvasInstance } from "./generated/rpc.js";
|
|
3
|
-
import type { MessageOptions, ReasoningEffort, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TypedSessionEventHandler } from "./types.js";
|
|
3
|
+
import type { MessageOptions, ContextTier, ReasoningEffort, ReasoningSummary, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TypedSessionEventHandler } from "./types.js";
|
|
4
4
|
/** Assistant message event - the final response from the assistant. */
|
|
5
5
|
export type AssistantMessageEvent = Extract<SessionEvent, {
|
|
6
6
|
type: "assistant.message";
|
|
@@ -169,11 +169,13 @@ export declare class CopilotSession {
|
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
171
171
|
on(handler: SessionEventHandler): () => void;
|
|
172
|
+
private upsertOpenCanvasFromEvent;
|
|
173
|
+
private upsertOpenCanvas;
|
|
172
174
|
/**
|
|
173
|
-
* Snapshot of canvas instances
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
175
|
+
* Snapshot of canvas instances currently known to be open for this session.
|
|
176
|
+
* Populated from the `session.resume` response and live `session.canvas.opened`
|
|
177
|
+
* events. Returns a defensive copy — mutating the returned array has no effect
|
|
178
|
+
* on the session.
|
|
177
179
|
*/
|
|
178
180
|
get openCanvases(): OpenCanvasInstance[];
|
|
179
181
|
private assertElicitation;
|
|
@@ -261,6 +263,8 @@ export declare class CopilotSession {
|
|
|
261
263
|
*/
|
|
262
264
|
setModel(model: string, options?: {
|
|
263
265
|
reasoningEffort?: ReasoningEffort;
|
|
266
|
+
reasoningSummary?: ReasoningSummary;
|
|
267
|
+
contextTier?: ContextTier;
|
|
264
268
|
modelCapabilities?: ModelCapabilitiesOverride;
|
|
265
269
|
}): Promise<void>;
|
|
266
270
|
/**
|
package/dist/session.js
CHANGED
|
@@ -10,6 +10,13 @@ function deserializeHookInput(raw) {
|
|
|
10
10
|
const { cwd, ...rest } = obj;
|
|
11
11
|
return { ...rest, timestamp: new Date(obj.timestamp), workingDirectory: cwd };
|
|
12
12
|
}
|
|
13
|
+
function isOpenCanvasInstance(value) {
|
|
14
|
+
if (!value || typeof value !== "object") {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const instance = value;
|
|
18
|
+
return typeof instance.instanceId === "string" && instance.instanceId.length > 0 && typeof instance.extensionId === "string" && instance.extensionId.length > 0 && typeof instance.canvasId === "string" && instance.canvasId.length > 0 && typeof instance.reopen === "boolean" && (instance.availability === "ready" || instance.availability === "stale");
|
|
19
|
+
}
|
|
13
20
|
class CopilotSession {
|
|
14
21
|
/**
|
|
15
22
|
* Creates a new CopilotSession instance.
|
|
@@ -94,8 +101,10 @@ class CopilotSession {
|
|
|
94
101
|
...await getTraceContext(this.traceContextProvider),
|
|
95
102
|
sessionId: this.sessionId,
|
|
96
103
|
prompt: options.prompt,
|
|
104
|
+
displayPrompt: options.displayPrompt,
|
|
97
105
|
attachments: options.attachments,
|
|
98
106
|
mode: options.mode,
|
|
107
|
+
agentMode: options.agentMode,
|
|
99
108
|
requestHeaders: options.requestHeaders
|
|
100
109
|
});
|
|
101
110
|
return response.messageId;
|
|
@@ -242,6 +251,25 @@ class CopilotSession {
|
|
|
242
251
|
}
|
|
243
252
|
} else if (event.type === "capabilities.changed") {
|
|
244
253
|
this._capabilities = { ...this._capabilities, ...event.data };
|
|
254
|
+
} else if (event.type === "session.canvas.opened") {
|
|
255
|
+
this.upsertOpenCanvasFromEvent(event.data);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
upsertOpenCanvasFromEvent(data) {
|
|
259
|
+
if (!isOpenCanvasInstance(data)) {
|
|
260
|
+
console.warn("failed to deserialize session.canvas.opened payload");
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this.upsertOpenCanvas(data);
|
|
264
|
+
}
|
|
265
|
+
upsertOpenCanvas(instance) {
|
|
266
|
+
const index = this.openCanvasInstances.findIndex(
|
|
267
|
+
(open) => open.instanceId === instance.instanceId
|
|
268
|
+
);
|
|
269
|
+
if (index >= 0) {
|
|
270
|
+
this.openCanvasInstances[index] = instance;
|
|
271
|
+
} else {
|
|
272
|
+
this.openCanvasInstances.push(instance);
|
|
245
273
|
}
|
|
246
274
|
}
|
|
247
275
|
/**
|
|
@@ -408,7 +436,7 @@ class CopilotSession {
|
|
|
408
436
|
throw toCanvasRpcError(error);
|
|
409
437
|
}
|
|
410
438
|
},
|
|
411
|
-
async
|
|
439
|
+
async invoke(params) {
|
|
412
440
|
const canvas = self.canvases.get(params.canvasId);
|
|
413
441
|
if (!canvas) throw new Error(`No canvas registered with id "${params.canvasId}"`);
|
|
414
442
|
const handler = canvas.actionHandlers.get(params.actionName);
|
|
@@ -523,10 +551,10 @@ class CopilotSession {
|
|
|
523
551
|
this._capabilities = capabilities ?? {};
|
|
524
552
|
}
|
|
525
553
|
/**
|
|
526
|
-
* Snapshot of canvas instances
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
554
|
+
* Snapshot of canvas instances currently known to be open for this session.
|
|
555
|
+
* Populated from the `session.resume` response and live `session.canvas.opened`
|
|
556
|
+
* events. Returns a defensive copy — mutating the returned array has no effect
|
|
557
|
+
* on the session.
|
|
530
558
|
*/
|
|
531
559
|
get openCanvases() {
|
|
532
560
|
return [...this.openCanvasInstances];
|
|
@@ -716,6 +744,7 @@ class CopilotSession {
|
|
|
716
744
|
preToolUse: this.hooks.onPreToolUse,
|
|
717
745
|
preMcpToolCall: this.hooks.onPreMcpToolCall,
|
|
718
746
|
postToolUse: this.hooks.onPostToolUse,
|
|
747
|
+
postToolUseFailure: this.hooks.onPostToolUseFailure,
|
|
719
748
|
userPromptSubmitted: this.hooks.onUserPromptSubmitted,
|
|
720
749
|
sessionStart: this.hooks.onSessionStart,
|
|
721
750
|
sessionEnd: this.hooks.onSessionEnd,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder that produces a list of source-qualified tool filter strings for
|
|
3
|
+
* {@link SessionConfigBase.availableTools}.
|
|
4
|
+
*
|
|
5
|
+
* Tools are classified by the runtime at registration time (not from name
|
|
6
|
+
* parsing), so `addBuiltIn("foo")` matches only tools the runtime registered
|
|
7
|
+
* as built-in, even if an MCP server or custom-agent extension happens to
|
|
8
|
+
* register a tool with the same wire name.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const tools = new ToolSet()
|
|
13
|
+
* .addBuiltIn(BuiltInTools.Isolated)
|
|
14
|
+
* .addMcp("*")
|
|
15
|
+
* .addCustom("*");
|
|
16
|
+
*
|
|
17
|
+
* const session = await client.createSession({
|
|
18
|
+
* availableTools: tools,
|
|
19
|
+
* // ...
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class ToolSet {
|
|
24
|
+
private readonly items;
|
|
25
|
+
/**
|
|
26
|
+
* Adds one or more built-in tool patterns.
|
|
27
|
+
*
|
|
28
|
+
* @param name A specific built-in tool name (e.g. `"bash"`) or `"*"` to match all
|
|
29
|
+
* built-in tools.
|
|
30
|
+
*/
|
|
31
|
+
addBuiltIn(name: string): ToolSet;
|
|
32
|
+
/**
|
|
33
|
+
* Adds a list of built-in tool patterns (e.g. {@link BuiltInTools.Isolated}).
|
|
34
|
+
*/
|
|
35
|
+
addBuiltIn(names: readonly string[]): ToolSet;
|
|
36
|
+
/**
|
|
37
|
+
* Adds a custom tool pattern. Matches tools registered via the SDK's
|
|
38
|
+
* `tools` option or via custom agents.
|
|
39
|
+
*
|
|
40
|
+
* @param name A specific custom tool name or `"*"` to match all custom tools.
|
|
41
|
+
*/
|
|
42
|
+
addCustom(name: string): ToolSet;
|
|
43
|
+
/**
|
|
44
|
+
* Adds an MCP tool pattern. Matches tools advertised by any configured
|
|
45
|
+
* MCP server.
|
|
46
|
+
*
|
|
47
|
+
* @param toolName The runtime's canonical wire name for the MCP tool
|
|
48
|
+
* (e.g. `"github-list_issues"`), or `"*"` to match all MCP tools from
|
|
49
|
+
* any server.
|
|
50
|
+
*/
|
|
51
|
+
addMcp(toolName: string): ToolSet;
|
|
52
|
+
/**
|
|
53
|
+
* Returns a defensive copy of the accumulated filter strings, suitable for
|
|
54
|
+
* passing as {@link SessionConfigBase.availableTools}.
|
|
55
|
+
*/
|
|
56
|
+
toArray(): string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Curated sets of built-in tool names for common scenarios. Each constant is
|
|
60
|
+
* meant to be passed to {@link ToolSet.addBuiltIn}.
|
|
61
|
+
*/
|
|
62
|
+
export declare const BuiltInTools: {
|
|
63
|
+
/**
|
|
64
|
+
* Built-in tools that operate only within the bounds of a single session —
|
|
65
|
+
* no host filesystem access outside the session, no cross-session state,
|
|
66
|
+
* no host environment access, no network. Safe to enable in `Mode = "empty"`
|
|
67
|
+
* scenarios (e.g. multi-tenant servers) without leaking host capabilities.
|
|
68
|
+
*
|
|
69
|
+
* **Contract:** tools in this set MUST NOT be extended (even behind options
|
|
70
|
+
* or args) to read or write state outside the session boundary. Adding
|
|
71
|
+
* cross-session or host-state behavior to one of these tools is a
|
|
72
|
+
* breaking change that requires removing it from this set.
|
|
73
|
+
*/
|
|
74
|
+
readonly Isolated: readonly string[];
|
|
75
|
+
};
|
package/dist/toolSet.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const VALID_TOOL_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
2
|
+
function validateName(kind, name) {
|
|
3
|
+
if (name === "*") {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (!VALID_TOOL_NAME.test(name)) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`Invalid ${kind} tool name '${name}': tool names must match /^[a-zA-Z0-9_-]+$/ or be the wildcard '*'.`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class ToolSet {
|
|
13
|
+
items = [];
|
|
14
|
+
addBuiltIn(nameOrNames) {
|
|
15
|
+
const names = typeof nameOrNames === "string" ? [nameOrNames] : nameOrNames;
|
|
16
|
+
for (const name of names) {
|
|
17
|
+
validateName("builtin", name);
|
|
18
|
+
this.items.push(`builtin:${name}`);
|
|
19
|
+
}
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Adds a custom tool pattern. Matches tools registered via the SDK's
|
|
24
|
+
* `tools` option or via custom agents.
|
|
25
|
+
*
|
|
26
|
+
* @param name A specific custom tool name or `"*"` to match all custom tools.
|
|
27
|
+
*/
|
|
28
|
+
addCustom(name) {
|
|
29
|
+
validateName("custom", name);
|
|
30
|
+
this.items.push(`custom:${name}`);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Adds an MCP tool pattern. Matches tools advertised by any configured
|
|
35
|
+
* MCP server.
|
|
36
|
+
*
|
|
37
|
+
* @param toolName The runtime's canonical wire name for the MCP tool
|
|
38
|
+
* (e.g. `"github-list_issues"`), or `"*"` to match all MCP tools from
|
|
39
|
+
* any server.
|
|
40
|
+
*/
|
|
41
|
+
addMcp(toolName) {
|
|
42
|
+
validateName("mcp", toolName);
|
|
43
|
+
this.items.push(`mcp:${toolName}`);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns a defensive copy of the accumulated filter strings, suitable for
|
|
48
|
+
* passing as {@link SessionConfigBase.availableTools}.
|
|
49
|
+
*/
|
|
50
|
+
toArray() {
|
|
51
|
+
return [...this.items];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const BuiltInTools = {
|
|
55
|
+
/**
|
|
56
|
+
* Built-in tools that operate only within the bounds of a single session —
|
|
57
|
+
* no host filesystem access outside the session, no cross-session state,
|
|
58
|
+
* no host environment access, no network. Safe to enable in `Mode = "empty"`
|
|
59
|
+
* scenarios (e.g. multi-tenant servers) without leaking host capabilities.
|
|
60
|
+
*
|
|
61
|
+
* **Contract:** tools in this set MUST NOT be extended (even behind options
|
|
62
|
+
* or args) to read or write state outside the session boundary. Adding
|
|
63
|
+
* cross-session or host-state behavior to one of these tools is a
|
|
64
|
+
* breaking change that requires removing it from this set.
|
|
65
|
+
*/
|
|
66
|
+
Isolated: [
|
|
67
|
+
"ask_user",
|
|
68
|
+
"task_complete",
|
|
69
|
+
"exit_plan_mode",
|
|
70
|
+
"task",
|
|
71
|
+
"read_agent",
|
|
72
|
+
"write_agent",
|
|
73
|
+
"list_agents",
|
|
74
|
+
"send_inbox",
|
|
75
|
+
"context_board",
|
|
76
|
+
"skill"
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
BuiltInTools,
|
|
81
|
+
ToolSet
|
|
82
|
+
};
|