@github/copilot-sdk 0.0.1 → 0.1.10-preview.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.
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Type definitions for the Copilot SDK
3
+ */
4
+ import type { SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
5
+ export type SessionEvent = GeneratedSessionEvent;
6
+ /**
7
+ * Options for creating a CopilotClient
8
+ */
9
+ export interface CopilotClientOptions {
10
+ /**
11
+ * Path to the Copilot CLI executable
12
+ * @default "copilot" (searches PATH)
13
+ */
14
+ cliPath?: string;
15
+ /**
16
+ * Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
17
+ */
18
+ cliArgs?: string[];
19
+ /**
20
+ * Working directory for the CLI process
21
+ * If not set, inherits the current process's working directory
22
+ */
23
+ cwd?: string;
24
+ /**
25
+ * Port for the CLI server (TCP mode only)
26
+ * @default 0 (random available port)
27
+ */
28
+ port?: number;
29
+ /**
30
+ * Use stdio transport instead of TCP
31
+ * When true, communicates with CLI via stdin/stdout pipes
32
+ * @default true
33
+ */
34
+ useStdio?: boolean;
35
+ /**
36
+ * URL of an existing Copilot CLI server to connect to over TCP
37
+ * When provided, the client will not spawn a CLI process
38
+ * Format: "host:port" or "http://host:port" or just "port" (defaults to localhost)
39
+ * Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"
40
+ * Mutually exclusive with cliPath, useStdio
41
+ */
42
+ cliUrl?: string;
43
+ /**
44
+ * Log level for the CLI server
45
+ */
46
+ logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
47
+ /**
48
+ * Auto-start the CLI server on first use
49
+ * @default true
50
+ */
51
+ autoStart?: boolean;
52
+ /**
53
+ * Auto-restart the CLI server if it crashes
54
+ * @default true
55
+ */
56
+ autoRestart?: boolean;
57
+ /**
58
+ * Environment variables to pass to the CLI process. If not set, inherits process.env.
59
+ */
60
+ env?: Record<string, string | undefined>;
61
+ }
62
+ /**
63
+ * Configuration for creating a session
64
+ */
65
+ export type ToolResultType = "success" | "failure" | "rejected" | "denied";
66
+ export type ToolBinaryResult = {
67
+ data: string;
68
+ mimeType: string;
69
+ type: string;
70
+ description?: string;
71
+ };
72
+ export type ToolResultObject = {
73
+ textResultForLlm: string;
74
+ binaryResultsForLlm?: ToolBinaryResult[];
75
+ resultType: ToolResultType;
76
+ error?: string;
77
+ sessionLog?: string;
78
+ toolTelemetry?: Record<string, unknown>;
79
+ };
80
+ export type ToolResult = string | ToolResultObject;
81
+ export interface ToolInvocation {
82
+ sessionId: string;
83
+ toolCallId: string;
84
+ toolName: string;
85
+ arguments: unknown;
86
+ }
87
+ export type ToolHandler<TArgs = unknown> = (args: TArgs, invocation: ToolInvocation) => Promise<unknown> | unknown;
88
+ /**
89
+ * Zod-like schema interface for type inference.
90
+ * Any object with `toJSONSchema()` method is treated as a Zod schema.
91
+ */
92
+ export interface ZodSchema<T = unknown> {
93
+ _output: T;
94
+ toJSONSchema(): Record<string, unknown>;
95
+ }
96
+ /**
97
+ * Tool definition. Parameters can be either:
98
+ * - A Zod schema (provides type inference for handler)
99
+ * - A raw JSON schema object
100
+ * - Omitted (no parameters)
101
+ */
102
+ export interface Tool<TArgs = unknown> {
103
+ name: string;
104
+ description?: string;
105
+ parameters?: ZodSchema<TArgs> | Record<string, unknown>;
106
+ handler: ToolHandler<TArgs>;
107
+ }
108
+ /**
109
+ * Helper to define a tool with Zod schema and get type inference for the handler.
110
+ * Without this helper, TypeScript cannot infer handler argument types from Zod schemas.
111
+ */
112
+ export declare function defineTool<T = unknown>(name: string, config: {
113
+ description?: string;
114
+ parameters?: ZodSchema<T> | Record<string, unknown>;
115
+ handler: ToolHandler<T>;
116
+ }): Tool<T>;
117
+ export interface ToolCallRequestPayload {
118
+ sessionId: string;
119
+ toolCallId: string;
120
+ toolName: string;
121
+ arguments: unknown;
122
+ }
123
+ export interface ToolCallResponsePayload {
124
+ result: ToolResult;
125
+ }
126
+ /**
127
+ * Append mode: Use CLI foundation with optional appended content (default).
128
+ */
129
+ export interface SystemMessageAppendConfig {
130
+ mode?: "append";
131
+ /**
132
+ * Additional instructions appended after SDK-managed sections.
133
+ */
134
+ content?: string;
135
+ }
136
+ /**
137
+ * Replace mode: Use caller-provided system message entirely.
138
+ * Removes all SDK guardrails including security restrictions.
139
+ */
140
+ export interface SystemMessageReplaceConfig {
141
+ mode: "replace";
142
+ /**
143
+ * Complete system message content.
144
+ * Replaces the entire SDK-managed system message.
145
+ */
146
+ content: string;
147
+ }
148
+ /**
149
+ * System message configuration for session creation.
150
+ * - Append mode (default): SDK foundation + optional custom content
151
+ * - Replace mode: Full control, caller provides entire system message
152
+ */
153
+ export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig;
154
+ export interface SessionConfig {
155
+ /**
156
+ * Optional custom session ID
157
+ * If not provided, server will generate one
158
+ */
159
+ sessionId?: string;
160
+ /**
161
+ * Model to use for this session
162
+ */
163
+ model?: string;
164
+ /**
165
+ * Tools exposed to the CLI server
166
+ */
167
+ tools?: Tool<any>[];
168
+ /**
169
+ * System message configuration
170
+ * Controls how the system prompt is constructed
171
+ */
172
+ systemMessage?: SystemMessageConfig;
173
+ /**
174
+ * List of tool names to allow. When specified, only these tools will be available.
175
+ * Takes precedence over excludedTools.
176
+ */
177
+ availableTools?: string[];
178
+ /**
179
+ * List of tool names to disable. All other tools remain available.
180
+ * Ignored if availableTools is specified.
181
+ */
182
+ excludedTools?: string[];
183
+ /**
184
+ * Custom provider configuration (BYOK - Bring Your Own Key).
185
+ * When specified, uses the provided API endpoint instead of the Copilot API.
186
+ */
187
+ provider?: ProviderConfig;
188
+ /**
189
+ * Enable streaming of assistant message and reasoning chunks.
190
+ * When true, ephemeral assistant.message_delta and assistant.reasoning_delta
191
+ * events are sent as the response is generated. Clients should accumulate
192
+ * deltaContent values to build the full response.
193
+ * @default false
194
+ */
195
+ streaming?: boolean;
196
+ }
197
+ /**
198
+ * Configuration for resuming a session
199
+ */
200
+ export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming">;
201
+ /**
202
+ * Configuration for a custom API provider.
203
+ */
204
+ export interface ProviderConfig {
205
+ /**
206
+ * Provider type. Defaults to "openai" for generic OpenAI-compatible APIs.
207
+ */
208
+ type?: "openai" | "azure" | "anthropic";
209
+ /**
210
+ * API format (openai/azure only). Defaults to "completions".
211
+ */
212
+ wireApi?: "completions" | "responses";
213
+ /**
214
+ * API endpoint URL
215
+ */
216
+ baseUrl: string;
217
+ /**
218
+ * API key. Optional for local providers like Ollama.
219
+ */
220
+ apiKey?: string;
221
+ /**
222
+ * Bearer token for authentication. Sets the Authorization header directly.
223
+ * Use this for services requiring bearer token auth instead of API key.
224
+ * Takes precedence over apiKey when both are set.
225
+ */
226
+ bearerToken?: string;
227
+ /**
228
+ * Azure-specific options
229
+ */
230
+ azure?: {
231
+ /**
232
+ * API version. Defaults to "2024-10-21".
233
+ */
234
+ apiVersion?: string;
235
+ };
236
+ }
237
+ /**
238
+ * Options for sending a message to a session
239
+ */
240
+ export interface MessageOptions {
241
+ /**
242
+ * The prompt/message to send
243
+ */
244
+ prompt: string;
245
+ /**
246
+ * File or directory attachments
247
+ */
248
+ attachments?: Array<{
249
+ type: "file" | "directory";
250
+ path: string;
251
+ displayName?: string;
252
+ }>;
253
+ /**
254
+ * Message delivery mode
255
+ * - "enqueue": Add to queue (default)
256
+ * - "immediate": Send immediately
257
+ */
258
+ mode?: "enqueue" | "immediate";
259
+ }
260
+ /**
261
+ * Event handler callback type
262
+ */
263
+ export type SessionEventHandler = (event: SessionEvent) => void;
264
+ /**
265
+ * Connection state
266
+ */
267
+ export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
268
+ /**
269
+ * Metadata about a session
270
+ */
271
+ export interface SessionMetadata {
272
+ sessionId: string;
273
+ startTime: Date;
274
+ modifiedTime: Date;
275
+ summary?: string;
276
+ isRemote: boolean;
277
+ }
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ function defineTool(name, config) {
2
+ return { name, ...config };
3
+ }
4
+ export {
5
+ defineTool
6
+ };
package/package.json CHANGED
@@ -1,5 +1,70 @@
1
-
2
1
  {
3
2
  "name": "@github/copilot-sdk",
4
- "version": "0.0.1"
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/github/copilot-sdk.git"
6
+ },
7
+ "version": "0.1.10-preview.0",
8
+ "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "type": "module",
18
+ "scripts": {
19
+ "clean": "rimraf --glob dist *.tgz",
20
+ "build": "tsx esbuild-copilotsdk-nodejs.ts",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
24
+ "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
25
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
26
+ "lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
27
+ "typecheck": "tsc --noEmit",
28
+ "generate:session-types": "tsx scripts/generate-session-types.ts",
29
+ "prepublishOnly": "npm run build",
30
+ "package": "npm run clean && npm run build && node scripts/set-version.js && npm pack && npm version 0.1.0 --no-git-tag-version --allow-same-version"
31
+ },
32
+ "keywords": [
33
+ "github",
34
+ "copilot",
35
+ "sdk",
36
+ "jsonrpc",
37
+ "agent"
38
+ ],
39
+ "author": "GitHub",
40
+ "license": "MIT",
41
+ "dependencies": {
42
+ "@github/copilot": "^0.0.377",
43
+ "vscode-jsonrpc": "^8.2.1",
44
+ "zod": "^4.3.5"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^22.0.0",
48
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
49
+ "@typescript-eslint/parser": "^8.0.0",
50
+ "esbuild": "^0.27.0",
51
+ "eslint": "^9.0.0",
52
+ "glob": "^11.0.0",
53
+ "json-schema": "^0.4.0",
54
+ "json-schema-to-typescript": "^15.0.4",
55
+ "prettier": "^3.4.0",
56
+ "quicktype-core": "^23.2.6",
57
+ "rimraf": "^6.1.2",
58
+ "semver": "^7.7.3",
59
+ "tsx": "^4.20.6",
60
+ "typescript": "^5.0.0",
61
+ "vitest": "^4.0.16"
62
+ },
63
+ "engines": {
64
+ "node": ">=18.0.0"
65
+ },
66
+ "files": [
67
+ "dist/**/*",
68
+ "README.md"
69
+ ]
5
70
  }