@github/copilot-sdk 0.0.1 → 0.1.9
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/README.md +1 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.js +549 -0
- package/dist/generated/session-events.d.ts +351 -0
- package/dist/generated/session-events.js +0 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/session.d.ts +39 -0
- package/dist/session.js +83 -0
- package/dist/types.d.ts +269 -0
- package/dist/types.js +6 -0
- package/package.json +67 -2
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
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
|
+
/**
|
|
190
|
+
* Configuration for resuming a session
|
|
191
|
+
*/
|
|
192
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider">;
|
|
193
|
+
/**
|
|
194
|
+
* Configuration for a custom API provider.
|
|
195
|
+
*/
|
|
196
|
+
export interface ProviderConfig {
|
|
197
|
+
/**
|
|
198
|
+
* Provider type. Defaults to "openai" for generic OpenAI-compatible APIs.
|
|
199
|
+
*/
|
|
200
|
+
type?: "openai" | "azure" | "anthropic";
|
|
201
|
+
/**
|
|
202
|
+
* API format (openai/azure only). Defaults to "completions".
|
|
203
|
+
*/
|
|
204
|
+
wireApi?: "completions" | "responses";
|
|
205
|
+
/**
|
|
206
|
+
* API endpoint URL
|
|
207
|
+
*/
|
|
208
|
+
baseUrl: string;
|
|
209
|
+
/**
|
|
210
|
+
* API key. Optional for local providers like Ollama.
|
|
211
|
+
*/
|
|
212
|
+
apiKey?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Bearer token for authentication. Sets the Authorization header directly.
|
|
215
|
+
* Use this for services requiring bearer token auth instead of API key.
|
|
216
|
+
* Takes precedence over apiKey when both are set.
|
|
217
|
+
*/
|
|
218
|
+
bearerToken?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Azure-specific options
|
|
221
|
+
*/
|
|
222
|
+
azure?: {
|
|
223
|
+
/**
|
|
224
|
+
* API version. Defaults to "2024-10-21".
|
|
225
|
+
*/
|
|
226
|
+
apiVersion?: string;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Options for sending a message to a session
|
|
231
|
+
*/
|
|
232
|
+
export interface MessageOptions {
|
|
233
|
+
/**
|
|
234
|
+
* The prompt/message to send
|
|
235
|
+
*/
|
|
236
|
+
prompt: string;
|
|
237
|
+
/**
|
|
238
|
+
* File or directory attachments
|
|
239
|
+
*/
|
|
240
|
+
attachments?: Array<{
|
|
241
|
+
type: "file" | "directory";
|
|
242
|
+
path: string;
|
|
243
|
+
displayName?: string;
|
|
244
|
+
}>;
|
|
245
|
+
/**
|
|
246
|
+
* Message delivery mode
|
|
247
|
+
* - "enqueue": Add to queue (default)
|
|
248
|
+
* - "immediate": Send immediately
|
|
249
|
+
*/
|
|
250
|
+
mode?: "enqueue" | "immediate";
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Event handler callback type
|
|
254
|
+
*/
|
|
255
|
+
export type SessionEventHandler = (event: SessionEvent) => void;
|
|
256
|
+
/**
|
|
257
|
+
* Connection state
|
|
258
|
+
*/
|
|
259
|
+
export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
|
|
260
|
+
/**
|
|
261
|
+
* Metadata about a session
|
|
262
|
+
*/
|
|
263
|
+
export interface SessionMetadata {
|
|
264
|
+
sessionId: string;
|
|
265
|
+
startTime: Date;
|
|
266
|
+
modifiedTime: Date;
|
|
267
|
+
summary?: string;
|
|
268
|
+
isRemote: boolean;
|
|
269
|
+
}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
|
-
|
|
2
1
|
{
|
|
3
2
|
"name": "@github/copilot-sdk",
|
|
4
|
-
"
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/github/copilot-sdk.git"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.1.9",
|
|
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.375-1",
|
|
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
|
}
|