@github/copilot-sdk 1.0.10-preview.0 → 1.0.11-preview.2
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/cjs/client.js +2 -0
- package/dist/cjs/factory.js +10 -0
- package/dist/cjs/generated/rpc.js +4 -2
- package/dist/cjs/session.js +40 -16
- package/dist/client.js +2 -0
- package/dist/factory.d.ts +24 -34
- package/dist/factory.js +9 -0
- package/dist/generated/rpc.d.ts +141 -132
- package/dist/generated/rpc.js +4 -2
- package/dist/generated/session-events.d.ts +53 -101
- package/dist/session.js +41 -16
- package/dist/types.d.ts +9 -1
- package/docs/factories.md +4 -4
- package/package.json +2 -2
package/dist/cjs/client.js
CHANGED
|
@@ -1111,6 +1111,7 @@ class CopilotClient {
|
|
|
1111
1111
|
models: config.models,
|
|
1112
1112
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1113
1113
|
enableCitations: config.enableCitations,
|
|
1114
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1114
1115
|
sessionLimits: config.sessionLimits,
|
|
1115
1116
|
modelCapabilities: config.modelCapabilities,
|
|
1116
1117
|
largeOutput: toWireLargeOutput(config.largeOutput),
|
|
@@ -1298,6 +1299,7 @@ class CopilotClient {
|
|
|
1298
1299
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1299
1300
|
excludedBuiltinAgents: config.excludedBuiltinAgents,
|
|
1300
1301
|
enableCitations: config.enableCitations,
|
|
1302
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1301
1303
|
sessionLimits: config.sessionLimits,
|
|
1302
1304
|
tools: config.tools?.map((tool) => ({
|
|
1303
1305
|
name: tool.name,
|
package/dist/cjs/factory.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var factory_exports = {};
|
|
20
20
|
__export(factory_exports, {
|
|
21
|
+
FACTORY_AGENT_OPTION_KEYS: () => FACTORY_AGENT_OPTION_KEYS,
|
|
21
22
|
FactoryResumeError: () => FactoryResumeError,
|
|
22
23
|
defineFactory: () => defineFactory,
|
|
23
24
|
getFactoryDefinition: () => getFactoryDefinition,
|
|
@@ -33,6 +34,14 @@ const FACTORY_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
33
34
|
function isFactoryRunTerminal(status) {
|
|
34
35
|
return FACTORY_TERMINAL_STATUSES.has(status);
|
|
35
36
|
}
|
|
37
|
+
const FACTORY_AGENT_OPTION_KEYS = [
|
|
38
|
+
"label",
|
|
39
|
+
"schema",
|
|
40
|
+
"model",
|
|
41
|
+
"reasoningEffort",
|
|
42
|
+
"contextTier",
|
|
43
|
+
"agent"
|
|
44
|
+
];
|
|
36
45
|
class FactoryResumeError extends Error {
|
|
37
46
|
constructor(code, message) {
|
|
38
47
|
super(message);
|
|
@@ -116,6 +125,7 @@ function getFactoryDefinition(handle) {
|
|
|
116
125
|
}
|
|
117
126
|
// Annotate the CommonJS export names for ESM import in node:
|
|
118
127
|
0 && (module.exports = {
|
|
128
|
+
FACTORY_AGENT_OPTION_KEYS,
|
|
119
129
|
FactoryResumeError,
|
|
120
130
|
defineFactory,
|
|
121
131
|
getFactoryDefinition,
|
|
@@ -872,9 +872,11 @@ function createSessionRpc(connection, sessionId) {
|
|
|
872
872
|
/**
|
|
873
873
|
* Lists durable factory runs for this session in creation order.
|
|
874
874
|
*
|
|
875
|
-
* @
|
|
875
|
+
* @param params Parameters for paging factory runs.
|
|
876
|
+
*
|
|
877
|
+
* @returns A page of factory runs in durable creation order.
|
|
876
878
|
*/
|
|
877
|
-
listRuns: async () => connection.sendRequest("session.factory.listRuns", { sessionId }),
|
|
879
|
+
listRuns: async (params) => connection.sendRequest("session.factory.listRuns", { sessionId, ...params }),
|
|
878
880
|
/**
|
|
879
881
|
* Gets durable and live observability detail for one factory run.
|
|
880
882
|
*
|
package/dist/cjs/session.js
CHANGED
|
@@ -21,13 +21,28 @@ __export(session_exports, {
|
|
|
21
21
|
CopilotSession: () => CopilotSession
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(session_exports);
|
|
24
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
24
25
|
var import_node = require("vscode-jsonrpc/node.js");
|
|
25
26
|
var import_rpc = require("./generated/rpc.js");
|
|
26
27
|
var import_canvas = require("./canvas.js");
|
|
27
28
|
var import_telemetry = require("./telemetry.js");
|
|
28
29
|
var import_factory = require("./factory.js");
|
|
29
30
|
function isFactoryResumeErrorCode(value) {
|
|
30
|
-
return value === "not_found" || value === "non_resumable" || value === "already_active" || value === "
|
|
31
|
+
return value === "not_found" || value === "non_resumable" || value === "already_active" || value === "factory_already_running" || value === "factory_limits_invalid" || value === "factory_session_disposed" || value === "factory_storage_unavailable" || value === "factory_storage_corrupt";
|
|
32
|
+
}
|
|
33
|
+
function copyDefinedFactoryAgentOption(source, target, key) {
|
|
34
|
+
const value = source[key];
|
|
35
|
+
if (value !== void 0) {
|
|
36
|
+
target[key] = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const factoryExecutionStore = new import_node_async_hooks.AsyncLocalStorage();
|
|
40
|
+
function throwIfFactoryExecutionIsActive() {
|
|
41
|
+
if (factoryExecutionStore.getStore()?.active) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"factory.run and factory.resume are not allowed while a factory body is running on this call path."
|
|
44
|
+
);
|
|
45
|
+
}
|
|
31
46
|
}
|
|
32
47
|
function deserializeHookInput(raw) {
|
|
33
48
|
if (!raw || typeof raw !== "object" || typeof raw.timestamp !== "number") {
|
|
@@ -148,7 +163,10 @@ class FactoryProgressBuffer {
|
|
|
148
163
|
const lines = this.pending.splice(0);
|
|
149
164
|
await this.flushTail;
|
|
150
165
|
if (this.flushFailed) {
|
|
151
|
-
|
|
166
|
+
console.warn(
|
|
167
|
+
"Ignoring a background factory progress flush failure after the factory body settled",
|
|
168
|
+
this.flushError
|
|
169
|
+
);
|
|
152
170
|
}
|
|
153
171
|
if (lines.length > 0) {
|
|
154
172
|
try {
|
|
@@ -179,9 +197,6 @@ class FactoryProgressBuffer {
|
|
|
179
197
|
}
|
|
180
198
|
}
|
|
181
199
|
}
|
|
182
|
-
function toPublicFactoryRunResult(envelope) {
|
|
183
|
-
return envelope;
|
|
184
|
-
}
|
|
185
200
|
async function awaitFactoryOperation(operation, signal) {
|
|
186
201
|
let rejectAbort;
|
|
187
202
|
const abortPromise = new Promise((_resolve, reject) => {
|
|
@@ -261,6 +276,7 @@ class CopilotSession {
|
|
|
261
276
|
*/
|
|
262
277
|
factory = {
|
|
263
278
|
run: (async (nameOrHandle, options) => {
|
|
279
|
+
throwIfFactoryExecutionIsActive();
|
|
264
280
|
const name = typeof nameOrHandle === "string" ? nameOrHandle : (0, import_factory.getFactoryDefinition)(nameOrHandle).meta.name;
|
|
265
281
|
if (options?.resumeFromRunId !== void 0) {
|
|
266
282
|
return this.factory.resume(options.resumeFromRunId, {
|
|
@@ -277,6 +293,7 @@ class CopilotSession {
|
|
|
277
293
|
return this.settleFactoryRun(envelope);
|
|
278
294
|
}),
|
|
279
295
|
resume: (async (runId, options) => {
|
|
296
|
+
throwIfFactoryExecutionIsActive();
|
|
280
297
|
let response;
|
|
281
298
|
try {
|
|
282
299
|
response = await this.rpc.factory.resume({
|
|
@@ -294,12 +311,12 @@ class CopilotSession {
|
|
|
294
311
|
}
|
|
295
312
|
return this.settleFactoryRun(response.run);
|
|
296
313
|
}),
|
|
297
|
-
getRun: async (runId) =>
|
|
314
|
+
getRun: async (runId) => this.rpc.factory.getRun({ runId }),
|
|
298
315
|
waitForRun: (runId, options) => this.waitForFactoryRun(runId, options?.signal),
|
|
299
|
-
listRuns: async () => (await this.rpc.factory.listRuns()).runs,
|
|
316
|
+
listRuns: async () => (await this.rpc.factory.listRuns({})).runs,
|
|
300
317
|
getRunDetail: (runId) => this.rpc.factory.getRunDetail({ runId }),
|
|
301
318
|
getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
|
|
302
|
-
cancel: async (runId) =>
|
|
319
|
+
cancel: async (runId) => this.rpc.factory.cancel({ runId })
|
|
303
320
|
};
|
|
304
321
|
/**
|
|
305
322
|
* Resolve a start/resume envelope into the terminal envelope callers expect.
|
|
@@ -310,7 +327,7 @@ class CopilotSession {
|
|
|
310
327
|
*/
|
|
311
328
|
settleFactoryRun(envelope) {
|
|
312
329
|
if ((0, import_factory.isFactoryRunTerminal)(envelope.status)) {
|
|
313
|
-
return Promise.resolve(
|
|
330
|
+
return Promise.resolve(envelope);
|
|
314
331
|
}
|
|
315
332
|
return this.waitForFactoryRun(envelope.runId);
|
|
316
333
|
}
|
|
@@ -364,7 +381,7 @@ class CopilotSession {
|
|
|
364
381
|
rereadRequested = false;
|
|
365
382
|
const envelope = await this.rpc.factory.getRun({ runId });
|
|
366
383
|
if ((0, import_factory.isFactoryRunTerminal)(envelope.status)) {
|
|
367
|
-
finish(() => resolve(
|
|
384
|
+
finish(() => resolve(envelope));
|
|
368
385
|
return;
|
|
369
386
|
}
|
|
370
387
|
} while (rereadRequested && !settled);
|
|
@@ -964,16 +981,16 @@ class CopilotSession {
|
|
|
964
981
|
},
|
|
965
982
|
agent: async (prompt, options = {}) => {
|
|
966
983
|
await progress.flush();
|
|
984
|
+
const opts = {};
|
|
985
|
+
for (const key of import_factory.FACTORY_AGENT_OPTION_KEYS) {
|
|
986
|
+
copyDefinedFactoryAgentOption(options, opts, key);
|
|
987
|
+
}
|
|
967
988
|
const response = await awaitFactoryOperation(
|
|
968
989
|
() => self.rpc.factory.agent({
|
|
969
990
|
factoryRunId: params.runId,
|
|
970
991
|
executionToken: params.executionToken,
|
|
971
992
|
prompt,
|
|
972
|
-
opts
|
|
973
|
-
label: options.label,
|
|
974
|
-
schema: options.schema,
|
|
975
|
-
model: options.model
|
|
976
|
-
}
|
|
993
|
+
opts
|
|
977
994
|
}),
|
|
978
995
|
controller.signal
|
|
979
996
|
);
|
|
@@ -1021,7 +1038,14 @@ class CopilotSession {
|
|
|
1021
1038
|
throw new Error("nested factories are not supported");
|
|
1022
1039
|
}
|
|
1023
1040
|
};
|
|
1024
|
-
const
|
|
1041
|
+
const execution = { active: true };
|
|
1042
|
+
const result = await factoryExecutionStore.run(execution, async () => {
|
|
1043
|
+
try {
|
|
1044
|
+
return await definition.run(context);
|
|
1045
|
+
} finally {
|
|
1046
|
+
execution.active = false;
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1025
1049
|
if (result === void 0) {
|
|
1026
1050
|
return {};
|
|
1027
1051
|
}
|
package/dist/client.js
CHANGED
|
@@ -1088,6 +1088,7 @@ class CopilotClient {
|
|
|
1088
1088
|
models: config.models,
|
|
1089
1089
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1090
1090
|
enableCitations: config.enableCitations,
|
|
1091
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1091
1092
|
sessionLimits: config.sessionLimits,
|
|
1092
1093
|
modelCapabilities: config.modelCapabilities,
|
|
1093
1094
|
largeOutput: toWireLargeOutput(config.largeOutput),
|
|
@@ -1275,6 +1276,7 @@ class CopilotClient {
|
|
|
1275
1276
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1276
1277
|
excludedBuiltinAgents: config.excludedBuiltinAgents,
|
|
1277
1278
|
enableCitations: config.enableCitations,
|
|
1279
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1278
1280
|
sessionLimits: config.sessionLimits,
|
|
1279
1281
|
tools: config.tools?.map((tool) => ({
|
|
1280
1282
|
name: tool.name,
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
|
-
import type { FactoryGetRunProgressRequest, FactoryProgressPage, FactoryRunDetail, FactoryRunResult
|
|
1
|
+
import type { FactoryGetRunProgressRequest, FactoryProgressPage, FactoryRunDetail, FactoryRunResult, FactoryRunStatus, FactoryRunSummary } from "./generated/rpc.js";
|
|
2
|
+
import type { ContextTier } from "./generated/session-events.js";
|
|
2
3
|
import type { CopilotSession } from "./session.js";
|
|
3
4
|
import type { FactoryLimits, FactoryMeta } from "./types.js";
|
|
4
|
-
|
|
5
|
-
* The envelope describing a factory run: its identity, status, and — once it
|
|
6
|
-
* has completed — its result. `getRun` returns this for an in-flight run too,
|
|
7
|
-
* so `status` may be `pending` or `running` and the outcome fields absent.
|
|
8
|
-
*
|
|
9
|
-
* `result` is re-typed here rather than taken from the generated wire type. The
|
|
10
|
-
* runtime returns any JSON value — including `null`, a string, a number, or an
|
|
11
|
-
* array — but the schema models the field as an opaque node, which the
|
|
12
|
-
* generator renders as an object. Narrowing the correction to this surface
|
|
13
|
-
* keeps the `x-opaque-json` handling unchanged for every other consumer.
|
|
14
|
-
*
|
|
15
|
-
* This override is temporary. Once the schema distinguishes an opaque JSON
|
|
16
|
-
* value from an opaque in-process value and that ships in a CLI release,
|
|
17
|
-
* regenerating produces the right type directly, and this declaration, the
|
|
18
|
-
* `toPublicFactoryRunResult` boundary helper, and the casts around it should
|
|
19
|
-
* all be deleted. Tracked by github/copilot-agent-runtime#14122.
|
|
20
|
-
*
|
|
21
|
-
* @experimental Part of the experimental Agent Factories surface and may
|
|
22
|
-
* change or be removed in future SDK or CLI releases.
|
|
23
|
-
*/
|
|
24
|
-
export type FactoryRunResult = Omit<WireFactoryRunResult, "result"> & {
|
|
25
|
-
/** Completed factory result. */
|
|
26
|
-
result?: JsonValue;
|
|
27
|
-
};
|
|
5
|
+
export type { FactoryRunResult };
|
|
28
6
|
export type { FactoryAgentSummary, FactoryPhaseStatus, FactoryPhaseObservation, FactoryProgressLine, FactoryProgressPage, FactoryRunDetail, FactoryRunStatus, FactoryRunSummary, } from "./generated/rpc.js";
|
|
29
7
|
/**
|
|
30
8
|
* Whether a factory run status is terminal.
|
|
@@ -70,7 +48,11 @@ export interface FactoryAgentOptions {
|
|
|
70
48
|
label?: string;
|
|
71
49
|
schema?: FactoryJsonSchema;
|
|
72
50
|
model?: string;
|
|
51
|
+
reasoningEffort?: string;
|
|
52
|
+
contextTier?: ContextTier;
|
|
53
|
+
agent?: string;
|
|
73
54
|
}
|
|
55
|
+
export declare const FACTORY_AGENT_OPTION_KEYS: readonly ["label", "schema", "model", "reasoningEffort", "contextTier", "agent"];
|
|
74
56
|
/**
|
|
75
57
|
* Options for a durable factory step.
|
|
76
58
|
*
|
|
@@ -127,7 +109,10 @@ export interface FactoryContext<TArgs extends JsonValue = JsonValue> {
|
|
|
127
109
|
factory(name: string, args?: JsonValue): Promise<JsonValue | void>;
|
|
128
110
|
/** Caller-supplied input, forwarded verbatim. */
|
|
129
111
|
args: TArgs;
|
|
130
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* The session instance returned by `joinSession`. It refuses calls that
|
|
114
|
+
* start or resume a factory run.
|
|
115
|
+
*/
|
|
131
116
|
session: CopilotSession;
|
|
132
117
|
/** Cooperative cancellation signal for the current factory run. */
|
|
133
118
|
signal: AbortSignal;
|
|
@@ -199,7 +184,7 @@ export interface ResumeOptions {
|
|
|
199
184
|
* @experimental Part of the experimental Agent Factories surface and may
|
|
200
185
|
* change or be removed in future SDK or CLI releases.
|
|
201
186
|
*/
|
|
202
|
-
export type FactoryResumeErrorCode = "not_found" | "non_resumable" | "already_active" | "
|
|
187
|
+
export type FactoryResumeErrorCode = "not_found" | "non_resumable" | "already_active" | "factory_already_running" | "factory_limits_invalid" | "factory_session_disposed" | "factory_storage_unavailable" | "factory_storage_corrupt";
|
|
203
188
|
/**
|
|
204
189
|
* Friendly factory API exposed on a session.
|
|
205
190
|
*
|
|
@@ -212,18 +197,21 @@ export interface SessionFactoryApi {
|
|
|
212
197
|
*
|
|
213
198
|
* The envelope is returned for every outcome, including `error`, `halted`,
|
|
214
199
|
* and `cancelled` — inspect `status` and read `result` only when the run
|
|
215
|
-
* completed.
|
|
216
|
-
*
|
|
217
|
-
*
|
|
200
|
+
* completed. SDK-initiated runs do not request permission, so they have no
|
|
201
|
+
* declined outcome. The model's `run_factory` tool requests permission
|
|
202
|
+
* before a durable row exists; declining it creates no run row. Failures
|
|
203
|
+
* that occur before a run exists (such as an unknown factory or attempting
|
|
204
|
+
* to start a run while the session is at its active top-level run limit)
|
|
205
|
+
* still reject.
|
|
218
206
|
*/
|
|
219
207
|
run(name: string, options?: RunOptions): Promise<FactoryRunResult>;
|
|
220
208
|
run<TArgs extends JsonValue>(factory: FactoryHandle<TArgs, JsonValue | void>, options?: RunOptions<TArgs>): Promise<FactoryRunResult>;
|
|
221
209
|
/**
|
|
222
210
|
* Resume a run from its persisted factory name, arguments, journal, and accounting.
|
|
223
211
|
*
|
|
224
|
-
* Resolves with the run envelope like {@link SessionFactoryApi.run}.
|
|
225
|
-
*
|
|
226
|
-
* {@link FactoryResumeError}.
|
|
212
|
+
* Resolves with the run envelope like {@link SessionFactoryApi.run}.
|
|
213
|
+
* SDK-initiated resumes do not request permission. A pre-execution failure
|
|
214
|
+
* with a documented resume code rejects with {@link FactoryResumeError}.
|
|
227
215
|
*/
|
|
228
216
|
resume(runId: string, options?: ResumeOptions): Promise<FactoryRunResult>;
|
|
229
217
|
/** Read the latest durable envelope for a factory run. */
|
|
@@ -245,7 +233,9 @@ export interface SessionFactoryApi {
|
|
|
245
233
|
waitForRun(runId: string, options?: {
|
|
246
234
|
signal?: AbortSignal;
|
|
247
235
|
}): Promise<FactoryRunResult>;
|
|
248
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* List the newest default page of this session's durable factory runs.
|
|
238
|
+
*/
|
|
249
239
|
listRuns(): Promise<FactoryRunSummary[]>;
|
|
250
240
|
/** Read durable phases, direct agents, and the latest progress tail for a run. */
|
|
251
241
|
getRunDetail(runId: string): Promise<FactoryRunDetail>;
|
package/dist/factory.js
CHANGED
|
@@ -7,6 +7,14 @@ const FACTORY_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
7
7
|
function isFactoryRunTerminal(status) {
|
|
8
8
|
return FACTORY_TERMINAL_STATUSES.has(status);
|
|
9
9
|
}
|
|
10
|
+
const FACTORY_AGENT_OPTION_KEYS = [
|
|
11
|
+
"label",
|
|
12
|
+
"schema",
|
|
13
|
+
"model",
|
|
14
|
+
"reasoningEffort",
|
|
15
|
+
"contextTier",
|
|
16
|
+
"agent"
|
|
17
|
+
];
|
|
10
18
|
class FactoryResumeError extends Error {
|
|
11
19
|
constructor(code, message) {
|
|
12
20
|
super(message);
|
|
@@ -89,6 +97,7 @@ function getFactoryDefinition(handle) {
|
|
|
89
97
|
return definition;
|
|
90
98
|
}
|
|
91
99
|
export {
|
|
100
|
+
FACTORY_AGENT_OPTION_KEYS,
|
|
92
101
|
FactoryResumeError,
|
|
93
102
|
defineFactory,
|
|
94
103
|
getFactoryDefinition,
|