@github/copilot-sdk 0.1.33-unstable.1 → 0.2.1-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.
- package/README.md +276 -6
- package/dist/cjs/client.js +1329 -0
- package/dist/cjs/extension.js +45 -0
- package/dist/cjs/generated/rpc.js +123 -0
- package/dist/cjs/generated/session-events.js +16 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/sdkProtocolVersion.js +33 -0
- package/dist/cjs/session.js +774 -0
- package/dist/cjs/telemetry.js +35 -0
- package/dist/cjs/types.js +49 -0
- package/dist/client.d.ts +2 -4
- package/dist/client.js +216 -88
- package/dist/extension.d.ts +6 -7
- package/dist/extension.js +5 -1
- package/dist/generated/rpc.d.ts +540 -1
- package/dist/generated/rpc.js +41 -2
- package/dist/generated/session-events.d.ts +829 -25
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/session.d.ts +81 -4
- package/dist/session.js +231 -8
- package/dist/telemetry.d.ts +14 -0
- package/dist/telemetry.js +11 -0
- package/dist/types.d.ts +340 -6
- package/dist/types.js +15 -0
- package/docs/agent-author.md +0 -2
- package/docs/examples.md +2 -15
- package/docs/extensions.md +0 -2
- package/package.json +19 -7
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,38 @@ export type SessionEvent = GeneratedSessionEvent;
|
|
|
6
6
|
/**
|
|
7
7
|
* Options for creating a CopilotClient
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* W3C Trace Context headers used for distributed trace propagation.
|
|
11
|
+
*/
|
|
12
|
+
export interface TraceContext {
|
|
13
|
+
traceparent?: string;
|
|
14
|
+
tracestate?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Callback that returns the current W3C Trace Context.
|
|
18
|
+
* Wire this up to your OpenTelemetry (or other tracing) SDK to enable
|
|
19
|
+
* distributed trace propagation between your app and the Copilot CLI.
|
|
20
|
+
*/
|
|
21
|
+
export type TraceContextProvider = () => TraceContext | Promise<TraceContext>;
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for OpenTelemetry instrumentation.
|
|
24
|
+
*
|
|
25
|
+
* When provided via {@link CopilotClientOptions.telemetry}, the SDK sets
|
|
26
|
+
* the corresponding environment variables on the spawned CLI process so
|
|
27
|
+
* that the CLI's built-in OTel exporter is configured automatically.
|
|
28
|
+
*/
|
|
29
|
+
export interface TelemetryConfig {
|
|
30
|
+
/** OTLP HTTP endpoint URL for trace/metric export. Sets OTEL_EXPORTER_OTLP_ENDPOINT. */
|
|
31
|
+
otlpEndpoint?: string;
|
|
32
|
+
/** File path for JSON-lines trace output. Sets COPILOT_OTEL_FILE_EXPORTER_PATH. */
|
|
33
|
+
filePath?: string;
|
|
34
|
+
/** Exporter backend type: "otlp-http" or "file". Sets COPILOT_OTEL_EXPORTER_TYPE. */
|
|
35
|
+
exporterType?: string;
|
|
36
|
+
/** Instrumentation scope name. Sets COPILOT_OTEL_SOURCE_NAME. */
|
|
37
|
+
sourceName?: string;
|
|
38
|
+
/** Whether to capture message content (prompts, responses). Sets OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. */
|
|
39
|
+
captureContent?: boolean;
|
|
40
|
+
}
|
|
9
41
|
export interface CopilotClientOptions {
|
|
10
42
|
/**
|
|
11
43
|
* Path to the CLI executable or JavaScript entry point.
|
|
@@ -56,8 +88,7 @@ export interface CopilotClientOptions {
|
|
|
56
88
|
*/
|
|
57
89
|
autoStart?: boolean;
|
|
58
90
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @default true
|
|
91
|
+
* @deprecated This option has no effect and will be removed in a future release.
|
|
61
92
|
*/
|
|
62
93
|
autoRestart?: boolean;
|
|
63
94
|
/**
|
|
@@ -84,6 +115,37 @@ export interface CopilotClientOptions {
|
|
|
84
115
|
* available from your custom provider.
|
|
85
116
|
*/
|
|
86
117
|
onListModels?: () => Promise<ModelInfo[]> | ModelInfo[];
|
|
118
|
+
/**
|
|
119
|
+
* OpenTelemetry configuration for the CLI process.
|
|
120
|
+
* When provided, the corresponding OTel environment variables are set
|
|
121
|
+
* on the spawned CLI server.
|
|
122
|
+
*/
|
|
123
|
+
telemetry?: TelemetryConfig;
|
|
124
|
+
/**
|
|
125
|
+
* Advanced: callback that returns the current W3C Trace Context for distributed
|
|
126
|
+
* trace propagation. Most users do not need this — the {@link telemetry} config
|
|
127
|
+
* alone is sufficient to collect traces from the CLI.
|
|
128
|
+
*
|
|
129
|
+
* This callback is only useful when your application creates its own
|
|
130
|
+
* OpenTelemetry spans and you want them to appear in the **same** distributed
|
|
131
|
+
* trace as the CLI's spans. The SDK calls this before `session.create`,
|
|
132
|
+
* `session.resume`, and `session.send` RPCs to inject `traceparent`/`tracestate`
|
|
133
|
+
* into the request.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* import { propagation, context } from "@opentelemetry/api";
|
|
138
|
+
*
|
|
139
|
+
* const client = new CopilotClient({
|
|
140
|
+
* onGetTraceContext: () => {
|
|
141
|
+
* const carrier: Record<string, string> = {};
|
|
142
|
+
* propagation.inject(context.active(), carrier);
|
|
143
|
+
* return carrier;
|
|
144
|
+
* },
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
onGetTraceContext?: TraceContextProvider;
|
|
87
149
|
}
|
|
88
150
|
/**
|
|
89
151
|
* Configuration for creating a session
|
|
@@ -109,6 +171,10 @@ export interface ToolInvocation {
|
|
|
109
171
|
toolCallId: string;
|
|
110
172
|
toolName: string;
|
|
111
173
|
arguments: unknown;
|
|
174
|
+
/** W3C Trace Context traceparent from the CLI's execute_tool span. */
|
|
175
|
+
traceparent?: string;
|
|
176
|
+
/** W3C Trace Context tracestate from the CLI's execute_tool span. */
|
|
177
|
+
tracestate?: string;
|
|
112
178
|
}
|
|
113
179
|
export type ToolHandler<TArgs = unknown> = (args: TArgs, invocation: ToolInvocation) => Promise<unknown> | unknown;
|
|
114
180
|
/**
|
|
@@ -136,6 +202,10 @@ export interface Tool<TArgs = unknown> {
|
|
|
136
202
|
* will return an error.
|
|
137
203
|
*/
|
|
138
204
|
overridesBuiltInTool?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* When true, the tool can execute without a permission prompt.
|
|
207
|
+
*/
|
|
208
|
+
skipPermission?: boolean;
|
|
139
209
|
}
|
|
140
210
|
/**
|
|
141
211
|
* Helper to define a tool with Zod schema and get type inference for the handler.
|
|
@@ -146,7 +216,189 @@ export declare function defineTool<T = unknown>(name: string, config: {
|
|
|
146
216
|
parameters?: ZodSchema<T> | Record<string, unknown>;
|
|
147
217
|
handler: ToolHandler<T>;
|
|
148
218
|
overridesBuiltInTool?: boolean;
|
|
219
|
+
skipPermission?: boolean;
|
|
149
220
|
}): Tool<T>;
|
|
221
|
+
/**
|
|
222
|
+
* Context passed to a command handler when a command is executed.
|
|
223
|
+
*/
|
|
224
|
+
export interface CommandContext {
|
|
225
|
+
/** Session ID where the command was invoked */
|
|
226
|
+
sessionId: string;
|
|
227
|
+
/** The full command text (e.g. "/deploy production") */
|
|
228
|
+
command: string;
|
|
229
|
+
/** Command name without leading / */
|
|
230
|
+
commandName: string;
|
|
231
|
+
/** Raw argument string after the command name */
|
|
232
|
+
args: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Handler invoked when a registered command is executed by a user.
|
|
236
|
+
*/
|
|
237
|
+
export type CommandHandler = (context: CommandContext) => Promise<void> | void;
|
|
238
|
+
/**
|
|
239
|
+
* Definition of a slash command registered with the session.
|
|
240
|
+
* When the CLI is running with a TUI, registered commands appear as
|
|
241
|
+
* `/commandName` for the user to invoke.
|
|
242
|
+
*/
|
|
243
|
+
export interface CommandDefinition {
|
|
244
|
+
/** Command name (without leading /). */
|
|
245
|
+
name: string;
|
|
246
|
+
/** Human-readable description shown in command completion UI. */
|
|
247
|
+
description?: string;
|
|
248
|
+
/** Handler invoked when the command is executed. */
|
|
249
|
+
handler: CommandHandler;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Capabilities reported by the CLI host for this session.
|
|
253
|
+
*/
|
|
254
|
+
export interface SessionCapabilities {
|
|
255
|
+
ui?: {
|
|
256
|
+
/** Whether the host supports interactive elicitation dialogs. */
|
|
257
|
+
elicitation?: boolean;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* A single field in an elicitation schema — matches the MCP SDK's
|
|
262
|
+
* `PrimitiveSchemaDefinition` union.
|
|
263
|
+
*/
|
|
264
|
+
export type ElicitationSchemaField = {
|
|
265
|
+
type: "string";
|
|
266
|
+
title?: string;
|
|
267
|
+
description?: string;
|
|
268
|
+
enum: string[];
|
|
269
|
+
enumNames?: string[];
|
|
270
|
+
default?: string;
|
|
271
|
+
} | {
|
|
272
|
+
type: "string";
|
|
273
|
+
title?: string;
|
|
274
|
+
description?: string;
|
|
275
|
+
oneOf: {
|
|
276
|
+
const: string;
|
|
277
|
+
title: string;
|
|
278
|
+
}[];
|
|
279
|
+
default?: string;
|
|
280
|
+
} | {
|
|
281
|
+
type: "array";
|
|
282
|
+
title?: string;
|
|
283
|
+
description?: string;
|
|
284
|
+
minItems?: number;
|
|
285
|
+
maxItems?: number;
|
|
286
|
+
items: {
|
|
287
|
+
type: "string";
|
|
288
|
+
enum: string[];
|
|
289
|
+
};
|
|
290
|
+
default?: string[];
|
|
291
|
+
} | {
|
|
292
|
+
type: "array";
|
|
293
|
+
title?: string;
|
|
294
|
+
description?: string;
|
|
295
|
+
minItems?: number;
|
|
296
|
+
maxItems?: number;
|
|
297
|
+
items: {
|
|
298
|
+
anyOf: {
|
|
299
|
+
const: string;
|
|
300
|
+
title: string;
|
|
301
|
+
}[];
|
|
302
|
+
};
|
|
303
|
+
default?: string[];
|
|
304
|
+
} | {
|
|
305
|
+
type: "boolean";
|
|
306
|
+
title?: string;
|
|
307
|
+
description?: string;
|
|
308
|
+
default?: boolean;
|
|
309
|
+
} | {
|
|
310
|
+
type: "string";
|
|
311
|
+
title?: string;
|
|
312
|
+
description?: string;
|
|
313
|
+
minLength?: number;
|
|
314
|
+
maxLength?: number;
|
|
315
|
+
format?: "email" | "uri" | "date" | "date-time";
|
|
316
|
+
default?: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: "number" | "integer";
|
|
319
|
+
title?: string;
|
|
320
|
+
description?: string;
|
|
321
|
+
minimum?: number;
|
|
322
|
+
maximum?: number;
|
|
323
|
+
default?: number;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Schema describing the form fields for an elicitation request.
|
|
327
|
+
*/
|
|
328
|
+
export interface ElicitationSchema {
|
|
329
|
+
type: "object";
|
|
330
|
+
properties: Record<string, ElicitationSchemaField>;
|
|
331
|
+
required?: string[];
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Primitive field value in an elicitation result.
|
|
335
|
+
* Matches MCP SDK's `ElicitResult.content` value type.
|
|
336
|
+
*/
|
|
337
|
+
export type ElicitationFieldValue = string | number | boolean | string[];
|
|
338
|
+
/**
|
|
339
|
+
* Result returned from an elicitation request.
|
|
340
|
+
*/
|
|
341
|
+
export interface ElicitationResult {
|
|
342
|
+
/** User action: "accept" (submitted), "decline" (rejected), or "cancel" (dismissed). */
|
|
343
|
+
action: "accept" | "decline" | "cancel";
|
|
344
|
+
/** Form values submitted by the user (present when action is "accept"). */
|
|
345
|
+
content?: Record<string, ElicitationFieldValue>;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Parameters for a raw elicitation request.
|
|
349
|
+
*/
|
|
350
|
+
export interface ElicitationParams {
|
|
351
|
+
/** Message describing what information is needed from the user. */
|
|
352
|
+
message: string;
|
|
353
|
+
/** JSON Schema describing the form fields to present. */
|
|
354
|
+
requestedSchema: ElicitationSchema;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Options for the `input()` convenience method.
|
|
358
|
+
*/
|
|
359
|
+
export interface InputOptions {
|
|
360
|
+
/** Title label for the input field. */
|
|
361
|
+
title?: string;
|
|
362
|
+
/** Descriptive text shown below the field. */
|
|
363
|
+
description?: string;
|
|
364
|
+
/** Minimum character length. */
|
|
365
|
+
minLength?: number;
|
|
366
|
+
/** Maximum character length. */
|
|
367
|
+
maxLength?: number;
|
|
368
|
+
/** Semantic format hint. */
|
|
369
|
+
format?: "email" | "uri" | "date" | "date-time";
|
|
370
|
+
/** Default value pre-populated in the field. */
|
|
371
|
+
default?: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* The `session.ui` API object providing interactive UI methods.
|
|
375
|
+
* Only usable when the CLI host supports elicitation.
|
|
376
|
+
*/
|
|
377
|
+
export interface SessionUiApi {
|
|
378
|
+
/**
|
|
379
|
+
* Shows a generic elicitation dialog with a custom schema.
|
|
380
|
+
* @throws Error if the host does not support elicitation.
|
|
381
|
+
*/
|
|
382
|
+
elicitation(params: ElicitationParams): Promise<ElicitationResult>;
|
|
383
|
+
/**
|
|
384
|
+
* Shows a confirmation dialog and returns the user's boolean answer.
|
|
385
|
+
* Returns `false` if the user declines or cancels.
|
|
386
|
+
* @throws Error if the host does not support elicitation.
|
|
387
|
+
*/
|
|
388
|
+
confirm(message: string): Promise<boolean>;
|
|
389
|
+
/**
|
|
390
|
+
* Shows a selection dialog with the given options.
|
|
391
|
+
* Returns the selected value, or `null` if the user declines/cancels.
|
|
392
|
+
* @throws Error if the host does not support elicitation.
|
|
393
|
+
*/
|
|
394
|
+
select(message: string, options: string[]): Promise<string | null>;
|
|
395
|
+
/**
|
|
396
|
+
* Shows a text input dialog.
|
|
397
|
+
* Returns the entered text, or `null` if the user declines/cancels.
|
|
398
|
+
* @throws Error if the host does not support elicitation.
|
|
399
|
+
*/
|
|
400
|
+
input(message: string, options?: InputOptions): Promise<string | null>;
|
|
401
|
+
}
|
|
150
402
|
export interface ToolCallRequestPayload {
|
|
151
403
|
sessionId: string;
|
|
152
404
|
toolCallId: string;
|
|
@@ -156,6 +408,46 @@ export interface ToolCallRequestPayload {
|
|
|
156
408
|
export interface ToolCallResponsePayload {
|
|
157
409
|
result: ToolResult;
|
|
158
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Known system prompt section identifiers for the "customize" mode.
|
|
413
|
+
* Each section corresponds to a distinct part of the system prompt.
|
|
414
|
+
*/
|
|
415
|
+
export type SystemPromptSection = "identity" | "tone" | "tool_efficiency" | "environment_context" | "code_change_rules" | "guidelines" | "safety" | "tool_instructions" | "custom_instructions" | "last_instructions";
|
|
416
|
+
/** Section metadata for documentation and tooling. */
|
|
417
|
+
export declare const SYSTEM_PROMPT_SECTIONS: Record<SystemPromptSection, {
|
|
418
|
+
description: string;
|
|
419
|
+
}>;
|
|
420
|
+
/**
|
|
421
|
+
* Transform callback for a single section: receives current content, returns new content.
|
|
422
|
+
*/
|
|
423
|
+
export type SectionTransformFn = (currentContent: string) => string | Promise<string>;
|
|
424
|
+
/**
|
|
425
|
+
* Override action: a string literal for static overrides, or a callback for transforms.
|
|
426
|
+
*
|
|
427
|
+
* - `"replace"`: Replace section content entirely
|
|
428
|
+
* - `"remove"`: Remove the section
|
|
429
|
+
* - `"append"`: Append to existing section content
|
|
430
|
+
* - `"prepend"`: Prepend to existing section content
|
|
431
|
+
* - `function`: Transform callback — receives current section content, returns new content
|
|
432
|
+
*/
|
|
433
|
+
export type SectionOverrideAction = "replace" | "remove" | "append" | "prepend" | SectionTransformFn;
|
|
434
|
+
/**
|
|
435
|
+
* Override operation for a single system prompt section.
|
|
436
|
+
*/
|
|
437
|
+
export interface SectionOverride {
|
|
438
|
+
/**
|
|
439
|
+
* The operation to perform on this section.
|
|
440
|
+
* Can be a string action or a transform callback function.
|
|
441
|
+
*/
|
|
442
|
+
action: SectionOverrideAction;
|
|
443
|
+
/**
|
|
444
|
+
* Content for the override. Optional for all actions.
|
|
445
|
+
* - For replace, omitting content replaces with an empty string.
|
|
446
|
+
* - For append/prepend, content is added before/after the existing section.
|
|
447
|
+
* - Ignored for the remove action.
|
|
448
|
+
*/
|
|
449
|
+
content?: string;
|
|
450
|
+
}
|
|
159
451
|
/**
|
|
160
452
|
* Append mode: Use CLI foundation with optional appended content (default).
|
|
161
453
|
*/
|
|
@@ -178,12 +470,31 @@ export interface SystemMessageReplaceConfig {
|
|
|
178
470
|
*/
|
|
179
471
|
content: string;
|
|
180
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* Customize mode: Override individual sections of the system prompt.
|
|
475
|
+
* Keeps the SDK-managed prompt structure while allowing targeted modifications.
|
|
476
|
+
*/
|
|
477
|
+
export interface SystemMessageCustomizeConfig {
|
|
478
|
+
mode: "customize";
|
|
479
|
+
/**
|
|
480
|
+
* Override specific sections of the system prompt by section ID.
|
|
481
|
+
* Unknown section IDs gracefully fall back: content-bearing overrides are appended
|
|
482
|
+
* to additional instructions, and "remove" on unknown sections is a silent no-op.
|
|
483
|
+
*/
|
|
484
|
+
sections?: Partial<Record<SystemPromptSection, SectionOverride>>;
|
|
485
|
+
/**
|
|
486
|
+
* Additional content appended after all sections.
|
|
487
|
+
* Equivalent to append mode's content field — provided for convenience.
|
|
488
|
+
*/
|
|
489
|
+
content?: string;
|
|
490
|
+
}
|
|
181
491
|
/**
|
|
182
492
|
* System message configuration for session creation.
|
|
183
493
|
* - Append mode (default): SDK foundation + optional custom content
|
|
184
494
|
* - Replace mode: Full control, caller provides entire system message
|
|
495
|
+
* - Customize mode: Section-level overrides with graceful fallback
|
|
185
496
|
*/
|
|
186
|
-
export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig;
|
|
497
|
+
export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig | SystemMessageCustomizeConfig;
|
|
187
498
|
/**
|
|
188
499
|
* Permission request types from the server
|
|
189
500
|
*/
|
|
@@ -193,7 +504,9 @@ export interface PermissionRequest {
|
|
|
193
504
|
[key: string]: unknown;
|
|
194
505
|
}
|
|
195
506
|
import type { SessionPermissionsHandlePendingPermissionRequestParams } from "./generated/rpc.js";
|
|
196
|
-
export type PermissionRequestResult = SessionPermissionsHandlePendingPermissionRequestParams["result"]
|
|
507
|
+
export type PermissionRequestResult = SessionPermissionsHandlePendingPermissionRequestParams["result"] | {
|
|
508
|
+
kind: "no-result";
|
|
509
|
+
};
|
|
197
510
|
export type PermissionHandler = (request: PermissionRequest, invocation: {
|
|
198
511
|
sessionId: string;
|
|
199
512
|
}) => Promise<PermissionRequestResult> | PermissionRequestResult;
|
|
@@ -543,6 +856,12 @@ export interface SessionConfig {
|
|
|
543
856
|
* Tools exposed to the CLI server
|
|
544
857
|
*/
|
|
545
858
|
tools?: Tool<any>[];
|
|
859
|
+
/**
|
|
860
|
+
* Slash commands registered for this session.
|
|
861
|
+
* When the CLI has a TUI, each command appears as `/name` for the user to invoke.
|
|
862
|
+
* The handler is called when the user executes the command.
|
|
863
|
+
*/
|
|
864
|
+
commands?: CommandDefinition[];
|
|
546
865
|
/**
|
|
547
866
|
* System message configuration
|
|
548
867
|
* Controls how the system prompt is constructed
|
|
@@ -613,11 +932,21 @@ export interface SessionConfig {
|
|
|
613
932
|
* Set to `{ enabled: false }` to disable.
|
|
614
933
|
*/
|
|
615
934
|
infiniteSessions?: InfiniteSessionConfig;
|
|
935
|
+
/**
|
|
936
|
+
* Optional event handler that is registered on the session before the
|
|
937
|
+
* session.create RPC is issued. This guarantees that early events emitted
|
|
938
|
+
* by the CLI during session creation (e.g. session.start) are delivered to
|
|
939
|
+
* the handler.
|
|
940
|
+
*
|
|
941
|
+
* Equivalent to calling `session.on(handler)` immediately after creation,
|
|
942
|
+
* but executes earlier in the lifecycle so no events are missed.
|
|
943
|
+
*/
|
|
944
|
+
onEvent?: SessionEventHandler;
|
|
616
945
|
}
|
|
617
946
|
/**
|
|
618
947
|
* Configuration for resuming a session
|
|
619
948
|
*/
|
|
620
|
-
export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "streaming" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "hooks" | "workingDirectory" | "configDir" | "mcpServers" | "customAgents" | "agent" | "skillDirectories" | "disabledSkills" | "infiniteSessions"> & {
|
|
949
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "commands" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "streaming" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "hooks" | "workingDirectory" | "configDir" | "mcpServers" | "customAgents" | "agent" | "skillDirectories" | "disabledSkills" | "infiniteSessions" | "onEvent"> & {
|
|
621
950
|
/**
|
|
622
951
|
* When true, skips emitting the session.resume event.
|
|
623
952
|
* Useful for reconnecting to a session without triggering resume-related side effects.
|
|
@@ -670,7 +999,7 @@ export interface MessageOptions {
|
|
|
670
999
|
*/
|
|
671
1000
|
prompt: string;
|
|
672
1001
|
/**
|
|
673
|
-
* File, directory, or
|
|
1002
|
+
* File, directory, selection, or blob attachments
|
|
674
1003
|
*/
|
|
675
1004
|
attachments?: Array<{
|
|
676
1005
|
type: "file";
|
|
@@ -695,6 +1024,11 @@ export interface MessageOptions {
|
|
|
695
1024
|
};
|
|
696
1025
|
};
|
|
697
1026
|
text?: string;
|
|
1027
|
+
} | {
|
|
1028
|
+
type: "blob";
|
|
1029
|
+
data: string;
|
|
1030
|
+
mimeType: string;
|
|
1031
|
+
displayName?: string;
|
|
698
1032
|
}>;
|
|
699
1033
|
/**
|
|
700
1034
|
* Message delivery mode
|
package/dist/types.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
function defineTool(name, config) {
|
|
2
2
|
return { name, ...config };
|
|
3
3
|
}
|
|
4
|
+
const SYSTEM_PROMPT_SECTIONS = {
|
|
5
|
+
identity: { description: "Agent identity preamble and mode statement" },
|
|
6
|
+
tone: { description: "Response style, conciseness rules, output formatting preferences" },
|
|
7
|
+
tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
|
|
8
|
+
environment_context: { description: "CWD, OS, git root, directory listing, available tools" },
|
|
9
|
+
code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" },
|
|
10
|
+
guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" },
|
|
11
|
+
safety: { description: "Environment limitations, prohibited actions, security policies" },
|
|
12
|
+
tool_instructions: { description: "Per-tool usage instructions" },
|
|
13
|
+
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
14
|
+
last_instructions: {
|
|
15
|
+
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
4
18
|
const approveAll = () => ({ kind: "approved" });
|
|
5
19
|
export {
|
|
20
|
+
SYSTEM_PROMPT_SECTIONS,
|
|
6
21
|
approveAll,
|
|
7
22
|
defineTool
|
|
8
23
|
};
|
package/docs/agent-author.md
CHANGED
|
@@ -59,11 +59,9 @@ Discovery rules:
|
|
|
59
59
|
## Minimal Skeleton
|
|
60
60
|
|
|
61
61
|
```js
|
|
62
|
-
import { approveAll } from "@github/copilot-sdk";
|
|
63
62
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
64
63
|
|
|
65
64
|
await joinSession({
|
|
66
|
-
onPermissionRequest: approveAll, // Required — handle permission requests
|
|
67
65
|
tools: [], // Optional — custom tools
|
|
68
66
|
hooks: {}, // Optional — lifecycle hooks
|
|
69
67
|
});
|
package/docs/examples.md
CHANGED
|
@@ -7,11 +7,9 @@ A practical guide to writing extensions using the `@github/copilot-sdk` extensio
|
|
|
7
7
|
Every extension starts with the same boilerplate:
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
import { approveAll } from "@github/copilot-sdk";
|
|
11
10
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
12
11
|
|
|
13
12
|
const session = await joinSession({
|
|
14
|
-
onPermissionRequest: approveAll,
|
|
15
13
|
hooks: { /* ... */ },
|
|
16
14
|
tools: [ /* ... */ ],
|
|
17
15
|
});
|
|
@@ -33,7 +31,6 @@ Use `session.log()` to surface messages to the user in the CLI timeline:
|
|
|
33
31
|
|
|
34
32
|
```js
|
|
35
33
|
const session = await joinSession({
|
|
36
|
-
onPermissionRequest: approveAll,
|
|
37
34
|
hooks: {
|
|
38
35
|
onSessionStart: async () => {
|
|
39
36
|
await session.log("My extension loaded");
|
|
@@ -383,7 +380,6 @@ function copyToClipboard(text) {
|
|
|
383
380
|
}
|
|
384
381
|
|
|
385
382
|
const session = await joinSession({
|
|
386
|
-
onPermissionRequest: approveAll,
|
|
387
383
|
hooks: {
|
|
388
384
|
onUserPromptSubmitted: async (input) => {
|
|
389
385
|
if (/\\bcopy\\b/i.test(input.prompt)) {
|
|
@@ -425,15 +421,12 @@ Correlate `tool.execution_start` / `tool.execution_complete` events by `toolCall
|
|
|
425
421
|
```js
|
|
426
422
|
import { existsSync, watchFile, readFileSync } from "node:fs";
|
|
427
423
|
import { join } from "node:path";
|
|
428
|
-
import { approveAll } from "@github/copilot-sdk";
|
|
429
424
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
430
425
|
|
|
431
426
|
const agentEdits = new Set(); // toolCallIds for in-flight agent edits
|
|
432
427
|
const recentAgentPaths = new Set(); // paths recently written by the agent
|
|
433
428
|
|
|
434
|
-
const session = await joinSession(
|
|
435
|
-
onPermissionRequest: approveAll,
|
|
436
|
-
});
|
|
429
|
+
const session = await joinSession();
|
|
437
430
|
|
|
438
431
|
const workspace = session.workspacePath; // e.g. ~/.copilot/session-state/<id>
|
|
439
432
|
if (workspace) {
|
|
@@ -480,14 +473,11 @@ Filter out agent edits by tracking `tool.execution_start` / `tool.execution_comp
|
|
|
480
473
|
```js
|
|
481
474
|
import { watch, readFileSync, statSync } from "node:fs";
|
|
482
475
|
import { join, relative, resolve } from "node:path";
|
|
483
|
-
import { approveAll } from "@github/copilot-sdk";
|
|
484
476
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
485
477
|
|
|
486
478
|
const agentEditPaths = new Set();
|
|
487
479
|
|
|
488
|
-
const session = await joinSession(
|
|
489
|
-
onPermissionRequest: approveAll,
|
|
490
|
-
});
|
|
480
|
+
const session = await joinSession();
|
|
491
481
|
|
|
492
482
|
const cwd = process.cwd();
|
|
493
483
|
const IGNORE = new Set(["node_modules", ".git", "dist"]);
|
|
@@ -582,7 +572,6 @@ Register `onUserInputRequest` to enable the agent's `ask_user` tool:
|
|
|
582
572
|
|
|
583
573
|
```js
|
|
584
574
|
const session = await joinSession({
|
|
585
|
-
onPermissionRequest: approveAll,
|
|
586
575
|
onUserInputRequest: async (request) => {
|
|
587
576
|
// request.question has the agent's question
|
|
588
577
|
// request.choices has the options (if multiple choice)
|
|
@@ -599,7 +588,6 @@ An extension that combines tools, hooks, and events.
|
|
|
599
588
|
|
|
600
589
|
```js
|
|
601
590
|
import { execFile, exec } from "node:child_process";
|
|
602
|
-
import { approveAll } from "@github/copilot-sdk";
|
|
603
591
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
604
592
|
|
|
605
593
|
const isWindows = process.platform === "win32";
|
|
@@ -617,7 +605,6 @@ function openInEditor(filePath) {
|
|
|
617
605
|
}
|
|
618
606
|
|
|
619
607
|
const session = await joinSession({
|
|
620
|
-
onPermissionRequest: approveAll,
|
|
621
608
|
hooks: {
|
|
622
609
|
onUserPromptSubmitted: async (input) => {
|
|
623
610
|
if (/\\bcopy this\\b/i.test(input.prompt)) {
|
package/docs/extensions.md
CHANGED
|
@@ -39,11 +39,9 @@ Extensions add custom tools, hooks, and behaviors to the Copilot CLI. They run a
|
|
|
39
39
|
Extensions use `@github/copilot-sdk` for all interactions with the CLI:
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
|
-
import { approveAll } from "@github/copilot-sdk";
|
|
43
42
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
44
43
|
|
|
45
44
|
const session = await joinSession({
|
|
46
|
-
onPermissionRequest: approveAll,
|
|
47
45
|
tools: [
|
|
48
46
|
/* ... */
|
|
49
47
|
],
|
package/package.json
CHANGED
|
@@ -4,18 +4,30 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/github/copilot-sdk.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.1
|
|
7
|
+
"version": "0.2.1-preview.0",
|
|
8
8
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
9
|
-
"main": "./dist/index.js",
|
|
9
|
+
"main": "./dist/cjs/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import":
|
|
14
|
-
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/cjs/index.js"
|
|
20
|
+
}
|
|
15
21
|
},
|
|
16
22
|
"./extension": {
|
|
17
|
-
"import":
|
|
18
|
-
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/extension.d.ts",
|
|
25
|
+
"default": "./dist/extension.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/extension.d.ts",
|
|
29
|
+
"default": "./dist/cjs/extension.js"
|
|
30
|
+
}
|
|
19
31
|
}
|
|
20
32
|
},
|
|
21
33
|
"type": "module",
|
|
@@ -44,7 +56,7 @@
|
|
|
44
56
|
"author": "GitHub",
|
|
45
57
|
"license": "MIT",
|
|
46
58
|
"dependencies": {
|
|
47
|
-
"@github/copilot": "^1.0.
|
|
59
|
+
"@github/copilot": "^1.0.11",
|
|
48
60
|
"vscode-jsonrpc": "^8.2.1",
|
|
49
61
|
"zod": "^4.3.6"
|
|
50
62
|
},
|