@github/copilot-sdk 1.0.0-beta.1 → 1.0.0-beta.10
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 +52 -43
- package/dist/canvas.d.ts +126 -0
- package/dist/canvas.js +49 -0
- package/dist/cjs/canvas.js +75 -0
- package/dist/cjs/client.js +536 -299
- package/dist/cjs/extension.js +9 -2
- package/dist/cjs/generated/rpc.js +1319 -14
- package/dist/cjs/index.js +22 -7
- package/dist/cjs/session.js +179 -93
- package/dist/cjs/sessionFsProvider.js +34 -0
- package/dist/cjs/toolSet.js +107 -0
- package/dist/cjs/types.js +38 -4
- package/dist/client.d.ts +63 -73
- package/dist/client.js +537 -300
- package/dist/extension.d.ts +3 -1
- package/dist/extension.js +10 -2
- package/dist/generated/rpc.d.ts +10187 -1028
- package/dist/generated/rpc.js +1319 -14
- package/dist/generated/session-events.d.ts +1982 -195
- package/dist/index.d.ts +6 -2
- package/dist/index.js +15 -2
- package/dist/session.d.ts +18 -186
- package/dist/session.js +179 -92
- package/dist/sessionFsProvider.d.ts +29 -2
- package/dist/sessionFsProvider.js +34 -0
- package/dist/toolSet.d.ts +75 -0
- package/dist/toolSet.js +82 -0
- package/dist/types.d.ts +730 -123
- package/dist/types.js +36 -3
- package/docs/agent-author.md +31 -7
- package/docs/examples.md +23 -16
- package/package.json +3 -3
package/dist/types.js
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
import { createSessionFsAdapter } from "./sessionFsProvider.js";
|
|
2
|
+
const RuntimeConnection = {
|
|
3
|
+
/**
|
|
4
|
+
* Spawn a runtime child process and communicate over its stdin/stdout.
|
|
5
|
+
* This is the default if no {@link CopilotClientOptions.connection} is set.
|
|
6
|
+
*/
|
|
7
|
+
forStdio(opts = {}) {
|
|
8
|
+
return { kind: "stdio", path: opts.path, args: opts.args };
|
|
9
|
+
},
|
|
10
|
+
/**
|
|
11
|
+
* Spawn a runtime child process that listens on a TCP socket and connect to it.
|
|
12
|
+
*/
|
|
13
|
+
forTcp(opts = {}) {
|
|
14
|
+
return {
|
|
15
|
+
kind: "tcp",
|
|
16
|
+
port: opts.port,
|
|
17
|
+
connectionToken: opts.connectionToken,
|
|
18
|
+
path: opts.path,
|
|
19
|
+
args: opts.args
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Connect to an already-running runtime at the given URL. The SDK does not
|
|
24
|
+
* spawn a process in this mode.
|
|
25
|
+
*/
|
|
26
|
+
forUri(url, opts = {}) {
|
|
27
|
+
return { kind: "uri", url, connectionToken: opts.connectionToken };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
2
30
|
function convertMcpCallToolResult(callResult) {
|
|
3
31
|
const textParts = [];
|
|
4
32
|
const binaryResults = [];
|
|
@@ -23,9 +51,10 @@ function convertMcpCallToolResult(callResult) {
|
|
|
23
51
|
textParts.push(block.resource.text);
|
|
24
52
|
}
|
|
25
53
|
if (block.resource?.blob) {
|
|
54
|
+
const mimeType = block.resource.mimeType;
|
|
26
55
|
binaryResults.push({
|
|
27
56
|
data: block.resource.blob,
|
|
28
|
-
mimeType:
|
|
57
|
+
mimeType: typeof mimeType === "string" && mimeType ? mimeType : "application/octet-stream",
|
|
29
58
|
type: "resource",
|
|
30
59
|
description: block.resource.uri
|
|
31
60
|
});
|
|
@@ -43,7 +72,7 @@ function convertMcpCallToolResult(callResult) {
|
|
|
43
72
|
function defineTool(name, config) {
|
|
44
73
|
return { name, ...config };
|
|
45
74
|
}
|
|
46
|
-
const
|
|
75
|
+
const SYSTEM_MESSAGE_SECTIONS = {
|
|
47
76
|
identity: { description: "Agent identity preamble and mode statement" },
|
|
48
77
|
tone: { description: "Response style, conciseness rules, output formatting preferences" },
|
|
49
78
|
tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
|
|
@@ -53,6 +82,9 @@ const SYSTEM_PROMPT_SECTIONS = {
|
|
|
53
82
|
safety: { description: "Environment limitations, prohibited actions, security policies" },
|
|
54
83
|
tool_instructions: { description: "Per-tool usage instructions" },
|
|
55
84
|
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
85
|
+
runtime_instructions: {
|
|
86
|
+
description: "Runtime-provided context and instructions (e.g. system notifications, memories, workspace context, mode-specific instructions, content-exclusion policy)"
|
|
87
|
+
},
|
|
56
88
|
last_instructions: {
|
|
57
89
|
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
58
90
|
}
|
|
@@ -62,7 +94,8 @@ const defaultJoinSessionPermissionHandler = () => ({
|
|
|
62
94
|
kind: "no-result"
|
|
63
95
|
});
|
|
64
96
|
export {
|
|
65
|
-
|
|
97
|
+
RuntimeConnection,
|
|
98
|
+
SYSTEM_MESSAGE_SECTIONS,
|
|
66
99
|
approveAll,
|
|
67
100
|
convertMcpCallToolResult,
|
|
68
101
|
createSessionFsAdapter,
|
package/docs/agent-author.md
CHANGED
|
@@ -118,19 +118,20 @@ hooks: {
|
|
|
118
118
|
onUserPromptSubmitted: async (input, invocation) => { ... },
|
|
119
119
|
onPreToolUse: async (input, invocation) => { ... },
|
|
120
120
|
onPostToolUse: async (input, invocation) => { ... },
|
|
121
|
+
onPostToolUseFailure: async (input, invocation) => { ... },
|
|
121
122
|
onSessionStart: async (input, invocation) => { ... },
|
|
122
123
|
onSessionEnd: async (input, invocation) => { ... },
|
|
123
124
|
onErrorOccurred: async (input, invocation) => { ... },
|
|
124
125
|
}
|
|
125
126
|
```
|
|
126
127
|
|
|
127
|
-
All hook inputs include `timestamp` (
|
|
128
|
+
All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
|
|
128
129
|
All handlers receive `invocation: { sessionId: string }` as the second argument.
|
|
129
130
|
All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
130
131
|
|
|
131
132
|
### onUserPromptSubmitted
|
|
132
133
|
|
|
133
|
-
**Input:** `{ prompt: string, timestamp,
|
|
134
|
+
**Input:** `{ prompt: string, timestamp, workingDirectory }`
|
|
134
135
|
|
|
135
136
|
**Output (all fields optional):**
|
|
136
137
|
| Field | Type | Effect |
|
|
@@ -140,7 +141,7 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
|
140
141
|
|
|
141
142
|
### onPreToolUse
|
|
142
143
|
|
|
143
|
-
**Input:** `{ toolName: string, toolArgs: unknown, timestamp,
|
|
144
|
+
**Input:** `{ toolName: string, toolArgs: unknown, timestamp, workingDirectory }`
|
|
144
145
|
|
|
145
146
|
**Output (all fields optional):**
|
|
146
147
|
| Field | Type | Effect |
|
|
@@ -152,7 +153,10 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
|
152
153
|
|
|
153
154
|
### onPostToolUse
|
|
154
155
|
|
|
155
|
-
**Input:** `{ toolName: string, toolArgs: unknown, toolResult: ToolResultObject, timestamp,
|
|
156
|
+
**Input:** `{ toolName: string, toolArgs: unknown, toolResult: ToolResultObject, timestamp, workingDirectory }`
|
|
157
|
+
|
|
158
|
+
Fires only when the tool returned a successful result. To observe non-success
|
|
159
|
+
outcomes, register `onPostToolUseFailure` as well.
|
|
156
160
|
|
|
157
161
|
**Output (all fields optional):**
|
|
158
162
|
| Field | Type | Effect |
|
|
@@ -160,9 +164,29 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
|
160
164
|
| `modifiedResult` | `ToolResultObject` | Replaces the tool result |
|
|
161
165
|
| `additionalContext` | `string` | Injected into the conversation |
|
|
162
166
|
|
|
167
|
+
### onPostToolUseFailure
|
|
168
|
+
|
|
169
|
+
**Input:** `{ toolName: string, toolArgs: unknown, error: string, timestamp, workingDirectory }`
|
|
170
|
+
|
|
171
|
+
Fires after a tool execution whose result was `"failure"`. `onPostToolUse`
|
|
172
|
+
does **not** fire for these outcomes, so register this handler to observe or
|
|
173
|
+
react to them — useful for telemetry, replay buffers, fault-injection tests,
|
|
174
|
+
or pairing pre/post tool tracking that would otherwise leak when the tool
|
|
175
|
+
fails. Note the input shape differs from `onPostToolUse`: only `error` (the
|
|
176
|
+
stringified failure message) is provided, not the full `toolResult`.
|
|
177
|
+
|
|
178
|
+
**Output (all fields optional):**
|
|
179
|
+
| Field | Type | Effect |
|
|
180
|
+
|-------|------|--------|
|
|
181
|
+
| `additionalContext` | `string` | Appended as hidden guidance the model sees alongside the failed tool result |
|
|
182
|
+
|
|
183
|
+
Note: only `"failure"` results trigger this hook. Other non-success
|
|
184
|
+
`resultType` values (`"rejected"`, `"denied"`, `"timeout"`) do not currently
|
|
185
|
+
fire it.
|
|
186
|
+
|
|
163
187
|
### onSessionStart
|
|
164
188
|
|
|
165
|
-
**Input:** `{ source: "startup" \| "resume" \| "new", initialPrompt?: string, timestamp,
|
|
189
|
+
**Input:** `{ source: "startup" \| "resume" \| "new", initialPrompt?: string, timestamp, workingDirectory }`
|
|
166
190
|
|
|
167
191
|
**Output (all fields optional):**
|
|
168
192
|
| Field | Type | Effect |
|
|
@@ -171,7 +195,7 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
|
171
195
|
|
|
172
196
|
### onSessionEnd
|
|
173
197
|
|
|
174
|
-
**Input:** `{ reason: "complete" \| "error" \| "abort" \| "timeout" \| "user_exit", finalMessage?: string, error?: string, timestamp,
|
|
198
|
+
**Input:** `{ reason: "complete" \| "error" \| "abort" \| "timeout" \| "user_exit", finalMessage?: string, error?: string, timestamp, workingDirectory }`
|
|
175
199
|
|
|
176
200
|
**Output (all fields optional):**
|
|
177
201
|
| Field | Type | Effect |
|
|
@@ -181,7 +205,7 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
|
|
|
181
205
|
|
|
182
206
|
### onErrorOccurred
|
|
183
207
|
|
|
184
|
-
**Input:** `{ error: string, errorContext: "model_call" \| "tool_execution" \| "system" \| "user_input", recoverable: boolean, timestamp,
|
|
208
|
+
**Input:** `{ error: string, errorContext: "model_call" \| "tool_execution" \| "system" \| "user_input", recoverable: boolean, timestamp, workingDirectory }`
|
|
185
209
|
|
|
186
210
|
**Output (all fields optional):**
|
|
187
211
|
| Field | Type | Effect |
|
package/docs/examples.md
CHANGED
|
@@ -152,16 +152,17 @@ Hooks intercept and modify behavior at key lifecycle points. Register them in th
|
|
|
152
152
|
|
|
153
153
|
### Available Hooks
|
|
154
154
|
|
|
155
|
-
| Hook | Fires When
|
|
156
|
-
| ----------------------- |
|
|
157
|
-
| `onUserPromptSubmitted` | User sends a message
|
|
158
|
-
| `onPreToolUse` | Before a tool executes
|
|
159
|
-
| `onPostToolUse` | After a tool executes
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
| Hook | Fires When | Can Modify |
|
|
156
|
+
| ----------------------- | ---------------------------------------- | ------------------------------------------- |
|
|
157
|
+
| `onUserPromptSubmitted` | User sends a message | The prompt text, add context |
|
|
158
|
+
| `onPreToolUse` | Before a tool executes | Tool args, permission decision, add context |
|
|
159
|
+
| `onPostToolUse` | After a tool executes successfully | Tool result, add context |
|
|
160
|
+
| `onPostToolUseFailure` | After a tool execution returns a failure | Add hidden guidance to the model |
|
|
161
|
+
| `onSessionStart` | Session starts or resumes | Add context, modify config |
|
|
162
|
+
| `onSessionEnd` | Session ends | Cleanup actions, summary |
|
|
163
|
+
| `onErrorOccurred` | An error occurs | Error handling strategy (retry/skip/abort) |
|
|
164
|
+
|
|
165
|
+
All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
|
|
165
166
|
|
|
166
167
|
### Modifying the user's message
|
|
167
168
|
|
|
@@ -267,12 +268,18 @@ hooks: {
|
|
|
267
268
|
}
|
|
268
269
|
```
|
|
269
270
|
|
|
270
|
-
###
|
|
271
|
+
### Reacting when a tool fails
|
|
272
|
+
|
|
273
|
+
`onPostToolUse` only fires for successful tool executions. To observe or react
|
|
274
|
+
to failures, register `onPostToolUseFailure`. The input includes
|
|
275
|
+
`input.error` (the stringified failure message); only `additionalContext` on
|
|
276
|
+
the return value is consumed by the runtime, and it is appended as hidden
|
|
277
|
+
guidance alongside the failed tool result.
|
|
271
278
|
|
|
272
279
|
```js
|
|
273
280
|
hooks: {
|
|
274
|
-
|
|
275
|
-
if (input.toolName === "bash"
|
|
281
|
+
onPostToolUseFailure: async (input) => {
|
|
282
|
+
if (input.toolName === "bash") {
|
|
276
283
|
return {
|
|
277
284
|
additionalContext: "The command failed. Try a different approach.",
|
|
278
285
|
};
|
|
@@ -561,12 +568,12 @@ const session = await joinSession({
|
|
|
561
568
|
onPermissionRequest: async (request) => {
|
|
562
569
|
if (request.kind === "shell") {
|
|
563
570
|
// request.fullCommandText has the shell command
|
|
564
|
-
return { kind: "
|
|
571
|
+
return { kind: "approve-once" };
|
|
565
572
|
}
|
|
566
573
|
if (request.kind === "write") {
|
|
567
|
-
return { kind: "
|
|
574
|
+
return { kind: "approve-once" };
|
|
568
575
|
}
|
|
569
|
-
return { kind: "
|
|
576
|
+
return { kind: "reject" };
|
|
570
577
|
},
|
|
571
578
|
});
|
|
572
579
|
```
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/github/copilot-sdk.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.0-beta.
|
|
7
|
+
"version": "1.0.0-beta.10",
|
|
8
8
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
9
9
|
"main": "./dist/cjs/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
|
|
41
41
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
42
42
|
"lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
43
|
-
"typecheck": "tsc --noEmit",
|
|
43
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
44
44
|
"generate": "cd ../scripts/codegen && npm run generate",
|
|
45
45
|
"update:protocol-version": "tsx scripts/update-protocol-version.ts",
|
|
46
46
|
"prepublishOnly": "npm run build",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"author": "GitHub",
|
|
57
57
|
"license": "MIT",
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@github/copilot": "^1.0.
|
|
59
|
+
"@github/copilot": "^1.0.56-1",
|
|
60
60
|
"vscode-jsonrpc": "^8.2.1",
|
|
61
61
|
"zod": "^4.3.6"
|
|
62
62
|
},
|