@github/copilot-sdk 0.1.9 → 0.1.10-preview.1
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 +1 -0
- package/dist/client.js +48 -4
- package/dist/generated/session-events.d.ts +34 -1
- package/dist/index.d.ts +1 -1
- package/dist/session.d.ts +4 -1
- package/dist/session.js +18 -0
- package/dist/types.d.ts +22 -1
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export declare class CopilotClient {
|
|
|
85
85
|
private handleSessionEventNotification;
|
|
86
86
|
private handleToolCallRequest;
|
|
87
87
|
private executeToolCall;
|
|
88
|
+
private handlePermissionRequest;
|
|
88
89
|
private normalizeToolResult;
|
|
89
90
|
private isToolResultObject;
|
|
90
91
|
private buildUnsupportedToolResult;
|
package/dist/client.js
CHANGED
|
@@ -216,11 +216,16 @@ class CopilotClient {
|
|
|
216
216
|
systemMessage: config.systemMessage,
|
|
217
217
|
availableTools: config.availableTools,
|
|
218
218
|
excludedTools: config.excludedTools,
|
|
219
|
-
provider: config.provider
|
|
219
|
+
provider: config.provider,
|
|
220
|
+
requestPermission: !!config.onPermissionRequest,
|
|
221
|
+
streaming: config.streaming
|
|
220
222
|
});
|
|
221
223
|
const sessionId = response.sessionId;
|
|
222
224
|
const session = new CopilotSession(sessionId, this.connection);
|
|
223
225
|
session.registerTools(config.tools);
|
|
226
|
+
if (config.onPermissionRequest) {
|
|
227
|
+
session.registerPermissionHandler(config.onPermissionRequest);
|
|
228
|
+
}
|
|
224
229
|
this.sessions.set(sessionId, session);
|
|
225
230
|
return session;
|
|
226
231
|
}
|
|
@@ -242,11 +247,16 @@ class CopilotClient {
|
|
|
242
247
|
description: tool.description,
|
|
243
248
|
parameters: toJsonSchema(tool.parameters)
|
|
244
249
|
})),
|
|
245
|
-
provider: config.provider
|
|
250
|
+
provider: config.provider,
|
|
251
|
+
requestPermission: !!config.onPermissionRequest,
|
|
252
|
+
streaming: config.streaming
|
|
246
253
|
});
|
|
247
254
|
const resumedSessionId = response.sessionId;
|
|
248
255
|
const session = new CopilotSession(resumedSessionId, this.connection);
|
|
249
256
|
session.registerTools(config.tools);
|
|
257
|
+
if (config.onPermissionRequest) {
|
|
258
|
+
session.registerPermissionHandler(config.onPermissionRequest);
|
|
259
|
+
}
|
|
250
260
|
this.sessions.set(resumedSessionId, session);
|
|
251
261
|
return session;
|
|
252
262
|
}
|
|
@@ -331,8 +341,19 @@ class CopilotClient {
|
|
|
331
341
|
const envWithoutNodeDebug = { ...this.options.env };
|
|
332
342
|
delete envWithoutNodeDebug.NODE_DEBUG;
|
|
333
343
|
const isJsFile = this.options.cliPath.endsWith(".js");
|
|
334
|
-
const
|
|
335
|
-
|
|
344
|
+
const isAbsolutePath = this.options.cliPath.startsWith("/") || /^[a-zA-Z]:/.test(this.options.cliPath);
|
|
345
|
+
let command;
|
|
346
|
+
let spawnArgs;
|
|
347
|
+
if (isJsFile) {
|
|
348
|
+
command = "node";
|
|
349
|
+
spawnArgs = [this.options.cliPath, ...args];
|
|
350
|
+
} else if (process.platform === "win32" && !isAbsolutePath) {
|
|
351
|
+
command = "cmd";
|
|
352
|
+
spawnArgs = ["/c", `"${this.options.cliPath}"`, ...args];
|
|
353
|
+
} else {
|
|
354
|
+
command = this.options.cliPath;
|
|
355
|
+
spawnArgs = args;
|
|
356
|
+
}
|
|
336
357
|
this.cliProcess = spawn(command, spawnArgs, {
|
|
337
358
|
stdio: this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"],
|
|
338
359
|
cwd: this.options.cwd,
|
|
@@ -448,6 +469,10 @@ class CopilotClient {
|
|
|
448
469
|
"tool.call",
|
|
449
470
|
async (params) => await this.handleToolCallRequest(params)
|
|
450
471
|
);
|
|
472
|
+
this.connection.onRequest(
|
|
473
|
+
"permission.request",
|
|
474
|
+
async (params) => await this.handlePermissionRequest(params)
|
|
475
|
+
);
|
|
451
476
|
this.connection.onClose(() => {
|
|
452
477
|
if (this.state === "connected" && this.options.autoRestart) {
|
|
453
478
|
void this.reconnect();
|
|
@@ -502,6 +527,25 @@ class CopilotClient {
|
|
|
502
527
|
};
|
|
503
528
|
}
|
|
504
529
|
}
|
|
530
|
+
async handlePermissionRequest(params) {
|
|
531
|
+
if (!params || typeof params.sessionId !== "string" || !params.permissionRequest) {
|
|
532
|
+
throw new Error("Invalid permission request payload");
|
|
533
|
+
}
|
|
534
|
+
const session = this.sessions.get(params.sessionId);
|
|
535
|
+
if (!session) {
|
|
536
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
537
|
+
}
|
|
538
|
+
try {
|
|
539
|
+
const result = await session._handlePermissionRequest(params.permissionRequest);
|
|
540
|
+
return { result };
|
|
541
|
+
} catch (_error) {
|
|
542
|
+
return {
|
|
543
|
+
result: {
|
|
544
|
+
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
505
549
|
normalizeToolResult(result) {
|
|
506
550
|
if (result === void 0 || result === null) {
|
|
507
551
|
return {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generated from: @github/copilot/session-events.schema.json
|
|
5
5
|
* Generated by: scripts/generate-session-types.ts
|
|
6
|
-
* Generated at: 2026-01-
|
|
6
|
+
* Generated at: 2026-01-08T23:59:19.905Z
|
|
7
7
|
*
|
|
8
8
|
* To update these types:
|
|
9
9
|
* 1. Update the schema in copilot-agent-runtime
|
|
@@ -139,6 +139,27 @@ export type SessionEvent = {
|
|
|
139
139
|
data: {
|
|
140
140
|
intent: string;
|
|
141
141
|
};
|
|
142
|
+
} | {
|
|
143
|
+
id: string;
|
|
144
|
+
timestamp: string;
|
|
145
|
+
parentId: string | null;
|
|
146
|
+
ephemeral?: boolean;
|
|
147
|
+
type: "assistant.reasoning";
|
|
148
|
+
data: {
|
|
149
|
+
reasoningId: string;
|
|
150
|
+
content: string;
|
|
151
|
+
chunkContent?: string;
|
|
152
|
+
};
|
|
153
|
+
} | {
|
|
154
|
+
id: string;
|
|
155
|
+
timestamp: string;
|
|
156
|
+
parentId: string | null;
|
|
157
|
+
ephemeral?: true;
|
|
158
|
+
type: "assistant.reasoning_delta";
|
|
159
|
+
data: {
|
|
160
|
+
reasoningId: string;
|
|
161
|
+
deltaContent: string;
|
|
162
|
+
};
|
|
142
163
|
} | {
|
|
143
164
|
id: string;
|
|
144
165
|
timestamp: string;
|
|
@@ -157,6 +178,18 @@ export type SessionEvent = {
|
|
|
157
178
|
}[];
|
|
158
179
|
parentToolCallId?: string;
|
|
159
180
|
};
|
|
181
|
+
} | {
|
|
182
|
+
id: string;
|
|
183
|
+
timestamp: string;
|
|
184
|
+
parentId: string | null;
|
|
185
|
+
ephemeral?: true;
|
|
186
|
+
type: "assistant.message_delta";
|
|
187
|
+
data: {
|
|
188
|
+
messageId: string;
|
|
189
|
+
deltaContent: string;
|
|
190
|
+
totalResponseSizeBytes?: number;
|
|
191
|
+
parentToolCallId?: string;
|
|
192
|
+
};
|
|
160
193
|
} | {
|
|
161
194
|
id: string;
|
|
162
195
|
timestamp: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
export { CopilotClient } from "./client.js";
|
|
7
7
|
export { CopilotSession } from "./session.js";
|
|
8
8
|
export { defineTool } from "./types.js";
|
|
9
|
-
export type { ConnectionState, CopilotClientOptions, MessageOptions, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, ZodSchema, } from "./types.js";
|
|
9
|
+
export type { ConnectionState, CopilotClientOptions, MessageOptions, PermissionHandler, PermissionRequest, PermissionRequestResult, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, ZodSchema, } from "./types.js";
|
package/dist/session.d.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* Copilot Session - represents a single conversation session with the CLI
|
|
3
3
|
*/
|
|
4
4
|
import type { MessageConnection } from "vscode-jsonrpc/node";
|
|
5
|
-
import type { MessageOptions, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js";
|
|
5
|
+
import type { MessageOptions, PermissionHandler, PermissionRequestResult, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js";
|
|
6
6
|
export declare class CopilotSession {
|
|
7
7
|
readonly sessionId: string;
|
|
8
8
|
private connection;
|
|
9
9
|
private eventHandlers;
|
|
10
10
|
private toolHandlers;
|
|
11
|
+
private permissionHandler?;
|
|
11
12
|
constructor(sessionId: string, connection: MessageConnection);
|
|
12
13
|
/**
|
|
13
14
|
* Send a message to this session
|
|
@@ -24,6 +25,8 @@ export declare class CopilotSession {
|
|
|
24
25
|
_dispatchEvent(event: SessionEvent): void;
|
|
25
26
|
registerTools(tools?: Tool[]): void;
|
|
26
27
|
getToolHandler(name: string): ToolHandler | undefined;
|
|
28
|
+
registerPermissionHandler(handler?: PermissionHandler): void;
|
|
29
|
+
_handlePermissionRequest(request: unknown): Promise<PermissionRequestResult>;
|
|
27
30
|
/**
|
|
28
31
|
* Get all events/messages from this session
|
|
29
32
|
*/
|
package/dist/session.js
CHANGED
|
@@ -5,6 +5,7 @@ class CopilotSession {
|
|
|
5
5
|
}
|
|
6
6
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
7
7
|
toolHandlers = /* @__PURE__ */ new Map();
|
|
8
|
+
permissionHandler;
|
|
8
9
|
/**
|
|
9
10
|
* Send a message to this session
|
|
10
11
|
*/
|
|
@@ -50,6 +51,22 @@ class CopilotSession {
|
|
|
50
51
|
getToolHandler(name) {
|
|
51
52
|
return this.toolHandlers.get(name);
|
|
52
53
|
}
|
|
54
|
+
registerPermissionHandler(handler) {
|
|
55
|
+
this.permissionHandler = handler;
|
|
56
|
+
}
|
|
57
|
+
async _handlePermissionRequest(request) {
|
|
58
|
+
if (!this.permissionHandler) {
|
|
59
|
+
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const result = await this.permissionHandler(request, {
|
|
63
|
+
sessionId: this.sessionId
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
} catch (_error) {
|
|
67
|
+
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
53
70
|
/**
|
|
54
71
|
* Get all events/messages from this session
|
|
55
72
|
*/
|
|
@@ -68,6 +85,7 @@ class CopilotSession {
|
|
|
68
85
|
});
|
|
69
86
|
this.eventHandlers.clear();
|
|
70
87
|
this.toolHandlers.clear();
|
|
88
|
+
this.permissionHandler = void 0;
|
|
71
89
|
}
|
|
72
90
|
/**
|
|
73
91
|
* Abort the currently processing message in this session
|
package/dist/types.d.ts
CHANGED
|
@@ -151,6 +151,21 @@ export interface SystemMessageReplaceConfig {
|
|
|
151
151
|
* - Replace mode: Full control, caller provides entire system message
|
|
152
152
|
*/
|
|
153
153
|
export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig;
|
|
154
|
+
/**
|
|
155
|
+
* Permission request types from the server
|
|
156
|
+
*/
|
|
157
|
+
export interface PermissionRequest {
|
|
158
|
+
kind: "shell" | "write" | "mcp" | "read" | "url";
|
|
159
|
+
toolCallId?: string;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
}
|
|
162
|
+
export interface PermissionRequestResult {
|
|
163
|
+
kind: "approved" | "denied-by-rules" | "denied-no-approval-rule-and-could-not-request-from-user" | "denied-interactively-by-user";
|
|
164
|
+
rules?: unknown[];
|
|
165
|
+
}
|
|
166
|
+
export type PermissionHandler = (request: PermissionRequest, invocation: {
|
|
167
|
+
sessionId: string;
|
|
168
|
+
}) => Promise<PermissionRequestResult> | PermissionRequestResult;
|
|
154
169
|
export interface SessionConfig {
|
|
155
170
|
/**
|
|
156
171
|
* Optional custom session ID
|
|
@@ -185,11 +200,17 @@ export interface SessionConfig {
|
|
|
185
200
|
* When specified, uses the provided API endpoint instead of the Copilot API.
|
|
186
201
|
*/
|
|
187
202
|
provider?: ProviderConfig;
|
|
203
|
+
/**
|
|
204
|
+
* Handler for permission requests from the server.
|
|
205
|
+
* When provided, the server will call this handler to request permission for operations.
|
|
206
|
+
*/
|
|
207
|
+
onPermissionRequest?: PermissionHandler;
|
|
208
|
+
streaming?: boolean;
|
|
188
209
|
}
|
|
189
210
|
/**
|
|
190
211
|
* Configuration for resuming a session
|
|
191
212
|
*/
|
|
192
|
-
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider">;
|
|
213
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming" | "onPermissionRequest">;
|
|
193
214
|
/**
|
|
194
215
|
* Configuration for a custom API provider.
|
|
195
216
|
*/
|
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.10-preview.1",
|
|
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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"author": "GitHub",
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@github/copilot": "^0.0.
|
|
42
|
+
"@github/copilot": "^0.0.378-0",
|
|
43
43
|
"vscode-jsonrpc": "^8.2.1",
|
|
44
44
|
"zod": "^4.3.5"
|
|
45
45
|
},
|