@github/copilot-sdk 0.1.10-preview.0 → 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 +44 -2
- 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 +19 -6
- 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
|
@@ -217,11 +217,15 @@ class CopilotClient {
|
|
|
217
217
|
availableTools: config.availableTools,
|
|
218
218
|
excludedTools: config.excludedTools,
|
|
219
219
|
provider: config.provider,
|
|
220
|
+
requestPermission: !!config.onPermissionRequest,
|
|
220
221
|
streaming: config.streaming
|
|
221
222
|
});
|
|
222
223
|
const sessionId = response.sessionId;
|
|
223
224
|
const session = new CopilotSession(sessionId, this.connection);
|
|
224
225
|
session.registerTools(config.tools);
|
|
226
|
+
if (config.onPermissionRequest) {
|
|
227
|
+
session.registerPermissionHandler(config.onPermissionRequest);
|
|
228
|
+
}
|
|
225
229
|
this.sessions.set(sessionId, session);
|
|
226
230
|
return session;
|
|
227
231
|
}
|
|
@@ -244,11 +248,15 @@ class CopilotClient {
|
|
|
244
248
|
parameters: toJsonSchema(tool.parameters)
|
|
245
249
|
})),
|
|
246
250
|
provider: config.provider,
|
|
251
|
+
requestPermission: !!config.onPermissionRequest,
|
|
247
252
|
streaming: config.streaming
|
|
248
253
|
});
|
|
249
254
|
const resumedSessionId = response.sessionId;
|
|
250
255
|
const session = new CopilotSession(resumedSessionId, this.connection);
|
|
251
256
|
session.registerTools(config.tools);
|
|
257
|
+
if (config.onPermissionRequest) {
|
|
258
|
+
session.registerPermissionHandler(config.onPermissionRequest);
|
|
259
|
+
}
|
|
252
260
|
this.sessions.set(resumedSessionId, session);
|
|
253
261
|
return session;
|
|
254
262
|
}
|
|
@@ -333,8 +341,19 @@ class CopilotClient {
|
|
|
333
341
|
const envWithoutNodeDebug = { ...this.options.env };
|
|
334
342
|
delete envWithoutNodeDebug.NODE_DEBUG;
|
|
335
343
|
const isJsFile = this.options.cliPath.endsWith(".js");
|
|
336
|
-
const
|
|
337
|
-
|
|
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
|
+
}
|
|
338
357
|
this.cliProcess = spawn(command, spawnArgs, {
|
|
339
358
|
stdio: this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"],
|
|
340
359
|
cwd: this.options.cwd,
|
|
@@ -450,6 +469,10 @@ class CopilotClient {
|
|
|
450
469
|
"tool.call",
|
|
451
470
|
async (params) => await this.handleToolCallRequest(params)
|
|
452
471
|
);
|
|
472
|
+
this.connection.onRequest(
|
|
473
|
+
"permission.request",
|
|
474
|
+
async (params) => await this.handlePermissionRequest(params)
|
|
475
|
+
);
|
|
453
476
|
this.connection.onClose(() => {
|
|
454
477
|
if (this.state === "connected" && this.options.autoRestart) {
|
|
455
478
|
void this.reconnect();
|
|
@@ -504,6 +527,25 @@ class CopilotClient {
|
|
|
504
527
|
};
|
|
505
528
|
}
|
|
506
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
|
+
}
|
|
507
549
|
normalizeToolResult(result) {
|
|
508
550
|
if (result === void 0 || result === null) {
|
|
509
551
|
return {
|
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
|
|
@@ -186,18 +201,16 @@ export interface SessionConfig {
|
|
|
186
201
|
*/
|
|
187
202
|
provider?: ProviderConfig;
|
|
188
203
|
/**
|
|
189
|
-
*
|
|
190
|
-
* When
|
|
191
|
-
* events are sent as the response is generated. Clients should accumulate
|
|
192
|
-
* deltaContent values to build the full response.
|
|
193
|
-
* @default false
|
|
204
|
+
* Handler for permission requests from the server.
|
|
205
|
+
* When provided, the server will call this handler to request permission for operations.
|
|
194
206
|
*/
|
|
207
|
+
onPermissionRequest?: PermissionHandler;
|
|
195
208
|
streaming?: boolean;
|
|
196
209
|
}
|
|
197
210
|
/**
|
|
198
211
|
* Configuration for resuming a session
|
|
199
212
|
*/
|
|
200
|
-
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming">;
|
|
213
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming" | "onPermissionRequest">;
|
|
201
214
|
/**
|
|
202
215
|
* Configuration for a custom API provider.
|
|
203
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.10-preview.
|
|
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
|
},
|