@github/copilot-sdk
Advanced tools
+1
-0
@@ -88,2 +88,3 @@ import { CopilotSession } from "./session.js"; | ||
| private executeToolCall; | ||
| private handlePermissionRequest; | ||
| private normalizeToolResult; | ||
@@ -90,0 +91,0 @@ private isToolResultObject; |
+44
-2
@@ -220,2 +220,3 @@ import { spawn } from "node:child_process"; | ||
| provider: config.provider, | ||
| requestPermission: !!config.onPermissionRequest, | ||
| streaming: config.streaming | ||
@@ -226,2 +227,5 @@ }); | ||
| session.registerTools(config.tools); | ||
| if (config.onPermissionRequest) { | ||
| session.registerPermissionHandler(config.onPermissionRequest); | ||
| } | ||
| this.sessions.set(sessionId, session); | ||
@@ -249,2 +253,3 @@ return session; | ||
| provider: config.provider, | ||
| requestPermission: !!config.onPermissionRequest, | ||
| streaming: config.streaming | ||
@@ -255,2 +260,5 @@ }); | ||
| session.registerTools(config.tools); | ||
| if (config.onPermissionRequest) { | ||
| session.registerPermissionHandler(config.onPermissionRequest); | ||
| } | ||
| this.sessions.set(resumedSessionId, session); | ||
@@ -340,4 +348,15 @@ return session; | ||
| const isJsFile = this.options.cliPath.endsWith(".js"); | ||
| const command = isJsFile ? "node" : this.options.cliPath; | ||
| const spawnArgs = isJsFile ? [this.options.cliPath, ...args] : args; | ||
| const isAbsolutePath = this.options.cliPath.startsWith("/") || /^[a-zA-Z]:/.test(this.options.cliPath); | ||
| let command; | ||
| let spawnArgs; | ||
| if (isJsFile) { | ||
| command = "node"; | ||
| spawnArgs = [this.options.cliPath, ...args]; | ||
| } else if (process.platform === "win32" && !isAbsolutePath) { | ||
| command = "cmd"; | ||
| spawnArgs = ["/c", `"${this.options.cliPath}"`, ...args]; | ||
| } else { | ||
| command = this.options.cliPath; | ||
| spawnArgs = args; | ||
| } | ||
| this.cliProcess = spawn(command, spawnArgs, { | ||
@@ -458,2 +477,6 @@ stdio: this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"], | ||
| ); | ||
| this.connection.onRequest( | ||
| "permission.request", | ||
| async (params) => await this.handlePermissionRequest(params) | ||
| ); | ||
| this.connection.onClose(() => { | ||
@@ -513,2 +536,21 @@ if (this.state === "connected" && this.options.autoRestart) { | ||
| } | ||
| async handlePermissionRequest(params) { | ||
| if (!params || typeof params.sessionId !== "string" || !params.permissionRequest) { | ||
| throw new Error("Invalid permission request payload"); | ||
| } | ||
| const session = this.sessions.get(params.sessionId); | ||
| if (!session) { | ||
| throw new Error(`Session not found: ${params.sessionId}`); | ||
| } | ||
| try { | ||
| const result = await session._handlePermissionRequest(params.permissionRequest); | ||
| return { result }; | ||
| } catch (_error) { | ||
| return { | ||
| result: { | ||
| kind: "denied-no-approval-rule-and-could-not-request-from-user" | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| normalizeToolResult(result) { | ||
@@ -515,0 +557,0 @@ if (result === void 0 || result === null) { |
+1
-1
@@ -9,2 +9,2 @@ /** | ||
| export { defineTool } from "./types.js"; | ||
| export type { ConnectionState, CopilotClientOptions, MessageOptions, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, ZodSchema, } from "./types.js"; | ||
| export type { ConnectionState, CopilotClientOptions, MessageOptions, PermissionHandler, PermissionRequest, PermissionRequestResult, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, ZodSchema, } from "./types.js"; |
@@ -5,3 +5,3 @@ /** | ||
| import type { MessageConnection } from "vscode-jsonrpc/node"; | ||
| import type { MessageOptions, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js"; | ||
| import type { MessageOptions, PermissionHandler, PermissionRequestResult, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js"; | ||
| export declare class CopilotSession { | ||
@@ -12,2 +12,3 @@ readonly sessionId: string; | ||
| private toolHandlers; | ||
| private permissionHandler?; | ||
| constructor(sessionId: string, connection: MessageConnection); | ||
@@ -29,2 +30,4 @@ /** | ||
| getToolHandler(name: string): ToolHandler | undefined; | ||
| registerPermissionHandler(handler?: PermissionHandler): void; | ||
| _handlePermissionRequest(request: unknown): Promise<PermissionRequestResult>; | ||
| /** | ||
@@ -31,0 +34,0 @@ * Get all events/messages from this session |
+18
-0
@@ -8,2 +8,3 @@ class CopilotSession { | ||
| toolHandlers = /* @__PURE__ */ new Map(); | ||
| permissionHandler; | ||
| /** | ||
@@ -54,2 +55,18 @@ * Send a message to this session | ||
| } | ||
| registerPermissionHandler(handler) { | ||
| this.permissionHandler = handler; | ||
| } | ||
| async _handlePermissionRequest(request) { | ||
| if (!this.permissionHandler) { | ||
| return { kind: "denied-no-approval-rule-and-could-not-request-from-user" }; | ||
| } | ||
| try { | ||
| const result = await this.permissionHandler(request, { | ||
| sessionId: this.sessionId | ||
| }); | ||
| return result; | ||
| } catch (_error) { | ||
| return { kind: "denied-no-approval-rule-and-could-not-request-from-user" }; | ||
| } | ||
| } | ||
| /** | ||
@@ -73,2 +90,3 @@ * Get all events/messages from this session | ||
| this.toolHandlers.clear(); | ||
| this.permissionHandler = void 0; | ||
| } | ||
@@ -75,0 +93,0 @@ /** |
+19
-6
@@ -154,2 +154,17 @@ /** | ||
| export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig; | ||
| /** | ||
| * Permission request types from the server | ||
| */ | ||
| export interface PermissionRequest { | ||
| kind: "shell" | "write" | "mcp" | "read" | "url"; | ||
| toolCallId?: string; | ||
| [key: string]: unknown; | ||
| } | ||
| export interface PermissionRequestResult { | ||
| kind: "approved" | "denied-by-rules" | "denied-no-approval-rule-and-could-not-request-from-user" | "denied-interactively-by-user"; | ||
| rules?: unknown[]; | ||
| } | ||
| export type PermissionHandler = (request: PermissionRequest, invocation: { | ||
| sessionId: string; | ||
| }) => Promise<PermissionRequestResult> | PermissionRequestResult; | ||
| export interface SessionConfig { | ||
@@ -190,8 +205,6 @@ /** | ||
| /** | ||
| * Enable streaming of assistant message and reasoning chunks. | ||
| * When true, ephemeral assistant.message_delta and assistant.reasoning_delta | ||
| * events are sent as the response is generated. Clients should accumulate | ||
| * deltaContent values to build the full response. | ||
| * @default false | ||
| * Handler for permission requests from the server. | ||
| * When provided, the server will call this handler to request permission for operations. | ||
| */ | ||
| onPermissionRequest?: PermissionHandler; | ||
| streaming?: boolean; | ||
@@ -202,3 +215,3 @@ } | ||
| */ | ||
| export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming">; | ||
| export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming" | "onPermissionRequest">; | ||
| /** | ||
@@ -205,0 +218,0 @@ * Configuration for a custom API provider. |
+2
-2
@@ -7,3 +7,3 @@ { | ||
| }, | ||
| "version": "0.1.10-preview.0", | ||
| "version": "0.1.10-preview.1", | ||
| "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC", | ||
@@ -43,3 +43,3 @@ "main": "./dist/index.js", | ||
| "dependencies": { | ||
| "@github/copilot": "^0.0.377", | ||
| "@github/copilot": "^0.0.378-0", | ||
| "vscode-jsonrpc": "^8.2.1", | ||
@@ -46,0 +46,0 @@ "zod": "^4.3.5" |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
44858
6.7%1530
5.3%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated