@github/copilot-sdk 0.1.30 → 0.1.31-unstable.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/client.d.ts +6 -8
- package/dist/client.js +29 -98
- package/dist/extension.d.ts +2 -0
- package/dist/extension.js +5 -0
- package/dist/generated/rpc.d.ts +39 -3
- package/dist/generated/rpc.js +6 -0
- package/dist/generated/session-events.d.ts +1942 -13
- package/dist/sdkProtocolVersion.d.ts +1 -1
- package/dist/sdkProtocolVersion.js +1 -1
- package/dist/session.d.ts +19 -9
- package/dist/session.js +69 -20
- package/dist/types.d.ts +6 -0
- package/package.json +6 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The SDK protocol version.
|
|
3
3
|
* This must match the version expected by the copilot-agent-runtime server.
|
|
4
4
|
*/
|
|
5
|
-
export declare const SDK_PROTOCOL_VERSION =
|
|
5
|
+
export declare const SDK_PROTOCOL_VERSION = 3;
|
|
6
6
|
/**
|
|
7
7
|
* Gets the SDK protocol version.
|
|
8
8
|
* @returns The protocol version number
|
package/dist/session.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { MessageConnection } from "vscode-jsonrpc/node";
|
|
6
6
|
import { createSessionRpc } from "./generated/rpc.js";
|
|
7
|
-
import type { MessageOptions, PermissionHandler,
|
|
7
|
+
import type { MessageOptions, PermissionHandler, SessionEvent, SessionEventHandler, SessionEventType, SessionHooks, Tool, ToolHandler, TypedSessionEventHandler, UserInputHandler, UserInputResponse } from "./types.js";
|
|
8
8
|
/** Assistant message event - the final response from the assistant. */
|
|
9
9
|
export type AssistantMessageEvent = Extract<SessionEvent, {
|
|
10
10
|
type: "assistant.message";
|
|
@@ -155,11 +155,29 @@ export declare class CopilotSession {
|
|
|
155
155
|
on(handler: SessionEventHandler): () => void;
|
|
156
156
|
/**
|
|
157
157
|
* Dispatches an event to all registered handlers.
|
|
158
|
+
* Also handles broadcast request events internally (external tool calls, permissions).
|
|
158
159
|
*
|
|
159
160
|
* @param event - The session event to dispatch
|
|
160
161
|
* @internal This method is for internal use by the SDK.
|
|
161
162
|
*/
|
|
162
163
|
_dispatchEvent(event: SessionEvent): void;
|
|
164
|
+
/**
|
|
165
|
+
* Handles broadcast request events by executing local handlers and responding via RPC.
|
|
166
|
+
* Handlers are dispatched as fire-and-forget — rejections propagate as unhandled promise
|
|
167
|
+
* rejections, consistent with standard EventEmitter / event handler semantics.
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
private _handleBroadcastEvent;
|
|
171
|
+
/**
|
|
172
|
+
* Executes a tool handler and sends the result back via RPC.
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
private _executeToolAndRespond;
|
|
176
|
+
/**
|
|
177
|
+
* Executes a permission handler and sends the result back via RPC.
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
private _executePermissionAndRespond;
|
|
163
181
|
/**
|
|
164
182
|
* Registers custom tool handlers for this session.
|
|
165
183
|
*
|
|
@@ -208,14 +226,6 @@ export declare class CopilotSession {
|
|
|
208
226
|
* @internal This method is typically called internally when creating a session.
|
|
209
227
|
*/
|
|
210
228
|
registerHooks(hooks?: SessionHooks): void;
|
|
211
|
-
/**
|
|
212
|
-
* Handles a permission request from the Copilot CLI.
|
|
213
|
-
*
|
|
214
|
-
* @param request - The permission request data from the CLI
|
|
215
|
-
* @returns A promise that resolves with the permission decision
|
|
216
|
-
* @internal This method is for internal use by the SDK.
|
|
217
|
-
*/
|
|
218
|
-
_handlePermissionRequest(request: unknown): Promise<PermissionRequestResult>;
|
|
219
229
|
/**
|
|
220
230
|
* Handles a user input request from the Copilot CLI.
|
|
221
231
|
*
|
package/dist/session.js
CHANGED
|
@@ -152,11 +152,13 @@ class CopilotSession {
|
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Dispatches an event to all registered handlers.
|
|
155
|
+
* Also handles broadcast request events internally (external tool calls, permissions).
|
|
155
156
|
*
|
|
156
157
|
* @param event - The session event to dispatch
|
|
157
158
|
* @internal This method is for internal use by the SDK.
|
|
158
159
|
*/
|
|
159
160
|
_dispatchEvent(event) {
|
|
161
|
+
this._handleBroadcastEvent(event);
|
|
160
162
|
const typedHandlers = this.typedEventHandlers.get(event.type);
|
|
161
163
|
if (typedHandlers) {
|
|
162
164
|
for (const handler of typedHandlers) {
|
|
@@ -173,6 +175,73 @@ class CopilotSession {
|
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Handles broadcast request events by executing local handlers and responding via RPC.
|
|
180
|
+
* Handlers are dispatched as fire-and-forget — rejections propagate as unhandled promise
|
|
181
|
+
* rejections, consistent with standard EventEmitter / event handler semantics.
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
_handleBroadcastEvent(event) {
|
|
185
|
+
if (event.type === "external_tool.requested") {
|
|
186
|
+
const { requestId, toolName } = event.data;
|
|
187
|
+
const args = event.data.arguments;
|
|
188
|
+
const toolCallId = event.data.toolCallId;
|
|
189
|
+
const handler = this.toolHandlers.get(toolName);
|
|
190
|
+
if (handler) {
|
|
191
|
+
void this._executeToolAndRespond(requestId, toolName, toolCallId, args, handler);
|
|
192
|
+
}
|
|
193
|
+
} else if (event.type === "permission.requested") {
|
|
194
|
+
const { requestId, permissionRequest } = event.data;
|
|
195
|
+
if (this.permissionHandler) {
|
|
196
|
+
void this._executePermissionAndRespond(requestId, permissionRequest);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Executes a tool handler and sends the result back via RPC.
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
async _executeToolAndRespond(requestId, toolName, toolCallId, args, handler) {
|
|
205
|
+
try {
|
|
206
|
+
const rawResult = await handler(args, {
|
|
207
|
+
sessionId: this.sessionId,
|
|
208
|
+
toolCallId,
|
|
209
|
+
toolName,
|
|
210
|
+
arguments: args
|
|
211
|
+
});
|
|
212
|
+
let result;
|
|
213
|
+
if (rawResult == null) {
|
|
214
|
+
result = "";
|
|
215
|
+
} else if (typeof rawResult === "string") {
|
|
216
|
+
result = rawResult;
|
|
217
|
+
} else {
|
|
218
|
+
result = JSON.stringify(rawResult);
|
|
219
|
+
}
|
|
220
|
+
await this.rpc.tools.handlePendingToolCall({ requestId, result });
|
|
221
|
+
} catch (error) {
|
|
222
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
223
|
+
await this.rpc.tools.handlePendingToolCall({ requestId, error: message });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Executes a permission handler and sends the result back via RPC.
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
async _executePermissionAndRespond(requestId, permissionRequest) {
|
|
231
|
+
try {
|
|
232
|
+
const result = await this.permissionHandler(permissionRequest, {
|
|
233
|
+
sessionId: this.sessionId
|
|
234
|
+
});
|
|
235
|
+
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
236
|
+
} catch (_error) {
|
|
237
|
+
await this.rpc.permissions.handlePendingPermissionRequest({
|
|
238
|
+
requestId,
|
|
239
|
+
result: {
|
|
240
|
+
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
176
245
|
/**
|
|
177
246
|
* Registers custom tool handlers for this session.
|
|
178
247
|
*
|
|
@@ -237,26 +306,6 @@ class CopilotSession {
|
|
|
237
306
|
registerHooks(hooks) {
|
|
238
307
|
this.hooks = hooks;
|
|
239
308
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Handles a permission request from the Copilot CLI.
|
|
242
|
-
*
|
|
243
|
-
* @param request - The permission request data from the CLI
|
|
244
|
-
* @returns A promise that resolves with the permission decision
|
|
245
|
-
* @internal This method is for internal use by the SDK.
|
|
246
|
-
*/
|
|
247
|
-
async _handlePermissionRequest(request) {
|
|
248
|
-
if (!this.permissionHandler) {
|
|
249
|
-
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
250
|
-
}
|
|
251
|
-
try {
|
|
252
|
-
const result = await this.permissionHandler(request, {
|
|
253
|
-
sessionId: this.sessionId
|
|
254
|
-
});
|
|
255
|
-
return result;
|
|
256
|
-
} catch (_error) {
|
|
257
|
-
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
309
|
/**
|
|
261
310
|
* Handles a user input request from the Copilot CLI.
|
|
262
311
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export interface CopilotClientOptions {
|
|
|
32
32
|
* @default true
|
|
33
33
|
*/
|
|
34
34
|
useStdio?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* When true, indicates the SDK is running as a child process of the Copilot CLI server, and should
|
|
37
|
+
* use its own stdio for communicating with the existing parent process. Can only be used in combination
|
|
38
|
+
* with useStdio: true.
|
|
39
|
+
*/
|
|
40
|
+
isChildProcess?: boolean;
|
|
35
41
|
/**
|
|
36
42
|
* URL of an existing Copilot CLI server to connect to over TCP
|
|
37
43
|
* When provided, the client will not spawn a CLI process
|
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": "0.1.
|
|
7
|
+
"version": "0.1.31-unstable.0",
|
|
8
8
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"import": "./dist/index.js",
|
|
14
14
|
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./extension": {
|
|
17
|
+
"import": "./dist/extension.js",
|
|
18
|
+
"types": "./dist/extension.d.ts"
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
"type": "module",
|
|
@@ -40,7 +44,7 @@
|
|
|
40
44
|
"author": "GitHub",
|
|
41
45
|
"license": "MIT",
|
|
42
46
|
"dependencies": {
|
|
43
|
-
"@github/copilot": "^0.0.
|
|
47
|
+
"@github/copilot": "^0.0.421",
|
|
44
48
|
"vscode-jsonrpc": "^8.2.1",
|
|
45
49
|
"zod": "^4.3.6"
|
|
46
50
|
},
|