@github/copilot-sdk 1.0.9 → 1.0.11-preview.1
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 +12 -6
- package/dist/cjs/factory.js +10 -0
- package/dist/cjs/generated/rpc.js +24 -2
- package/dist/cjs/session.js +40 -16
- package/dist/client.js +12 -6
- package/dist/factory.d.ts +24 -34
- package/dist/factory.js +9 -0
- package/dist/generated/rpc.d.ts +404 -130
- package/dist/generated/rpc.js +24 -2
- package/dist/generated/session-events.d.ts +73 -109
- package/dist/index.d.ts +1 -1
- package/dist/session.js +41 -16
- package/dist/types.d.ts +82 -1
- package/docs/factories.md +4 -4
- package/package.json +2 -2
package/dist/cjs/client.js
CHANGED
|
@@ -1027,7 +1027,7 @@ class CopilotClient {
|
|
|
1027
1027
|
this.onGetTraceContext,
|
|
1028
1028
|
{
|
|
1029
1029
|
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1030
|
-
managedSettingsEnabled: config.enableManagedSettings
|
|
1030
|
+
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0
|
|
1031
1031
|
}
|
|
1032
1032
|
);
|
|
1033
1033
|
s.registerTools(config.tools);
|
|
@@ -1086,7 +1086,8 @@ class CopilotClient {
|
|
|
1086
1086
|
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
1087
1087
|
skipPermission: tool.skipPermission,
|
|
1088
1088
|
defer: tool.defer,
|
|
1089
|
-
metadata: tool.metadata
|
|
1089
|
+
metadata: tool.metadata,
|
|
1090
|
+
isTerminal: tool.isTerminal
|
|
1090
1091
|
})),
|
|
1091
1092
|
toolSearch: config.toolSearch,
|
|
1092
1093
|
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
@@ -1110,6 +1111,7 @@ class CopilotClient {
|
|
|
1110
1111
|
models: config.models,
|
|
1111
1112
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1112
1113
|
enableCitations: config.enableCitations,
|
|
1114
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1113
1115
|
sessionLimits: config.sessionLimits,
|
|
1114
1116
|
modelCapabilities: config.modelCapabilities,
|
|
1115
1117
|
largeOutput: toWireLargeOutput(config.largeOutput),
|
|
@@ -1154,7 +1156,8 @@ class CopilotClient {
|
|
|
1154
1156
|
remoteSession: config.remoteSession,
|
|
1155
1157
|
cloud: config.cloud,
|
|
1156
1158
|
expAssignments: config.expAssignments,
|
|
1157
|
-
enableManagedSettings: config.enableManagedSettings
|
|
1159
|
+
enableManagedSettings: config.enableManagedSettings,
|
|
1160
|
+
managedSettings: config.managedSettings
|
|
1158
1161
|
});
|
|
1159
1162
|
const {
|
|
1160
1163
|
sessionId: returnedSessionId,
|
|
@@ -1232,7 +1235,7 @@ class CopilotClient {
|
|
|
1232
1235
|
this.onGetTraceContext,
|
|
1233
1236
|
{
|
|
1234
1237
|
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1235
|
-
managedSettingsEnabled: config.enableManagedSettings
|
|
1238
|
+
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0
|
|
1236
1239
|
}
|
|
1237
1240
|
);
|
|
1238
1241
|
session.registerTools(config.tools);
|
|
@@ -1296,6 +1299,7 @@ class CopilotClient {
|
|
|
1296
1299
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1297
1300
|
excludedBuiltinAgents: config.excludedBuiltinAgents,
|
|
1298
1301
|
enableCitations: config.enableCitations,
|
|
1302
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1299
1303
|
sessionLimits: config.sessionLimits,
|
|
1300
1304
|
tools: config.tools?.map((tool) => ({
|
|
1301
1305
|
name: tool.name,
|
|
@@ -1304,7 +1308,8 @@ class CopilotClient {
|
|
|
1304
1308
|
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
1305
1309
|
skipPermission: tool.skipPermission,
|
|
1306
1310
|
defer: tool.defer,
|
|
1307
|
-
metadata: tool.metadata
|
|
1311
|
+
metadata: tool.metadata,
|
|
1312
|
+
isTerminal: tool.isTerminal
|
|
1308
1313
|
})),
|
|
1309
1314
|
toolSearch: config.toolSearch,
|
|
1310
1315
|
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
@@ -1367,7 +1372,8 @@ class CopilotClient {
|
|
|
1367
1372
|
remoteSession: config.remoteSession,
|
|
1368
1373
|
openCanvases: config.openCanvases,
|
|
1369
1374
|
expAssignments: config.expAssignments,
|
|
1370
|
-
enableManagedSettings: config.enableManagedSettings
|
|
1375
|
+
enableManagedSettings: config.enableManagedSettings,
|
|
1376
|
+
managedSettings: config.managedSettings
|
|
1371
1377
|
});
|
|
1372
1378
|
const { workspacePath, capabilities, openCanvases } = response;
|
|
1373
1379
|
session["_workspacePath"] = workspacePath;
|
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,
|
|
@@ -191,6 +191,12 @@ function createServerRpc(connection) {
|
|
|
191
191
|
*/
|
|
192
192
|
disable: async (params) => connection.sendRequest("extensions.disable", params)
|
|
193
193
|
},
|
|
194
|
+
/**
|
|
195
|
+
* Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime temporarily falls back to its built-in Node launcher for backward compatibility.
|
|
196
|
+
*
|
|
197
|
+
* @experimental
|
|
198
|
+
*/
|
|
199
|
+
registerExtensionLaunchProvider: async () => connection.sendRequest("registerExtensionLaunchProvider", {}),
|
|
194
200
|
/** @experimental */
|
|
195
201
|
plugins: {
|
|
196
202
|
/**
|
|
@@ -381,6 +387,15 @@ function createServerRpc(connection) {
|
|
|
381
387
|
}
|
|
382
388
|
},
|
|
383
389
|
/** @experimental */
|
|
390
|
+
managedSettings: {
|
|
391
|
+
/**
|
|
392
|
+
* Discovers device-managed settings from production MDM and managed-file sources, validates them against the runtime-owned managed-settings schema, and returns the canonical JSON without requiring a session.
|
|
393
|
+
*
|
|
394
|
+
* @returns Validated device-managed settings discovered before a session exists.
|
|
395
|
+
*/
|
|
396
|
+
read: async () => connection.sendRequest("managedSettings.read", {})
|
|
397
|
+
},
|
|
398
|
+
/** @experimental */
|
|
384
399
|
runtime: {
|
|
385
400
|
/**
|
|
386
401
|
* Gracefully shuts down an SDK-owned runtime. The response is sent only after cleanup completes; callers may then terminate the owned runtime process.
|
|
@@ -857,9 +872,11 @@ function createSessionRpc(connection, sessionId) {
|
|
|
857
872
|
/**
|
|
858
873
|
* Lists durable factory runs for this session in creation order.
|
|
859
874
|
*
|
|
860
|
-
* @
|
|
875
|
+
* @param params Parameters for paging factory runs.
|
|
876
|
+
*
|
|
877
|
+
* @returns A page of factory runs in durable creation order.
|
|
861
878
|
*/
|
|
862
|
-
listRuns: async () => connection.sendRequest("session.factory.listRuns", { sessionId }),
|
|
879
|
+
listRuns: async (params) => connection.sendRequest("session.factory.listRuns", { sessionId, ...params }),
|
|
863
880
|
/**
|
|
864
881
|
* Gets durable and live observability detail for one factory run.
|
|
865
882
|
*
|
|
@@ -2623,6 +2640,11 @@ function registerClientSessionApiHandlers(connection, getHandlers) {
|
|
|
2623
2640
|
});
|
|
2624
2641
|
}
|
|
2625
2642
|
function registerClientGlobalApiHandlers(connection, handlers) {
|
|
2643
|
+
connection.onRequest("extensionLaunchProvider.resolve", async (params) => {
|
|
2644
|
+
const handler = handlers.extensionLaunchProvider;
|
|
2645
|
+
if (!handler) throw new Error("No extensionLaunchProvider client-global handler registered");
|
|
2646
|
+
return handler.resolve(params);
|
|
2647
|
+
});
|
|
2626
2648
|
connection.onRequest("llmInference.httpRequestStart", async (params) => {
|
|
2627
2649
|
const handler = handlers.llmInference;
|
|
2628
2650
|
if (!handler) throw new Error("No llmInference client-global handler registered");
|
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
|
@@ -1004,7 +1004,7 @@ class CopilotClient {
|
|
|
1004
1004
|
this.onGetTraceContext,
|
|
1005
1005
|
{
|
|
1006
1006
|
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1007
|
-
managedSettingsEnabled: config.enableManagedSettings
|
|
1007
|
+
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0
|
|
1008
1008
|
}
|
|
1009
1009
|
);
|
|
1010
1010
|
s.registerTools(config.tools);
|
|
@@ -1063,7 +1063,8 @@ class CopilotClient {
|
|
|
1063
1063
|
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
1064
1064
|
skipPermission: tool.skipPermission,
|
|
1065
1065
|
defer: tool.defer,
|
|
1066
|
-
metadata: tool.metadata
|
|
1066
|
+
metadata: tool.metadata,
|
|
1067
|
+
isTerminal: tool.isTerminal
|
|
1067
1068
|
})),
|
|
1068
1069
|
toolSearch: config.toolSearch,
|
|
1069
1070
|
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
@@ -1087,6 +1088,7 @@ class CopilotClient {
|
|
|
1087
1088
|
models: config.models,
|
|
1088
1089
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1089
1090
|
enableCitations: config.enableCitations,
|
|
1091
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1090
1092
|
sessionLimits: config.sessionLimits,
|
|
1091
1093
|
modelCapabilities: config.modelCapabilities,
|
|
1092
1094
|
largeOutput: toWireLargeOutput(config.largeOutput),
|
|
@@ -1131,7 +1133,8 @@ class CopilotClient {
|
|
|
1131
1133
|
remoteSession: config.remoteSession,
|
|
1132
1134
|
cloud: config.cloud,
|
|
1133
1135
|
expAssignments: config.expAssignments,
|
|
1134
|
-
enableManagedSettings: config.enableManagedSettings
|
|
1136
|
+
enableManagedSettings: config.enableManagedSettings,
|
|
1137
|
+
managedSettings: config.managedSettings
|
|
1135
1138
|
});
|
|
1136
1139
|
const {
|
|
1137
1140
|
sessionId: returnedSessionId,
|
|
@@ -1209,7 +1212,7 @@ class CopilotClient {
|
|
|
1209
1212
|
this.onGetTraceContext,
|
|
1210
1213
|
{
|
|
1211
1214
|
mcpAuthHandler: config.onMcpAuthRequest,
|
|
1212
|
-
managedSettingsEnabled: config.enableManagedSettings
|
|
1215
|
+
managedSettingsEnabled: config.enableManagedSettings === true || config.managedSettings !== void 0
|
|
1213
1216
|
}
|
|
1214
1217
|
);
|
|
1215
1218
|
session.registerTools(config.tools);
|
|
@@ -1273,6 +1276,7 @@ class CopilotClient {
|
|
|
1273
1276
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
1274
1277
|
excludedBuiltinAgents: config.excludedBuiltinAgents,
|
|
1275
1278
|
enableCitations: config.enableCitations,
|
|
1279
|
+
enableFileChangeTracking: config.enableFileChangeTracking,
|
|
1276
1280
|
sessionLimits: config.sessionLimits,
|
|
1277
1281
|
tools: config.tools?.map((tool) => ({
|
|
1278
1282
|
name: tool.name,
|
|
@@ -1281,7 +1285,8 @@ class CopilotClient {
|
|
|
1281
1285
|
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
1282
1286
|
skipPermission: tool.skipPermission,
|
|
1283
1287
|
defer: tool.defer,
|
|
1284
|
-
metadata: tool.metadata
|
|
1288
|
+
metadata: tool.metadata,
|
|
1289
|
+
isTerminal: tool.isTerminal
|
|
1285
1290
|
})),
|
|
1286
1291
|
toolSearch: config.toolSearch,
|
|
1287
1292
|
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
@@ -1344,7 +1349,8 @@ class CopilotClient {
|
|
|
1344
1349
|
remoteSession: config.remoteSession,
|
|
1345
1350
|
openCanvases: config.openCanvases,
|
|
1346
1351
|
expAssignments: config.expAssignments,
|
|
1347
|
-
enableManagedSettings: config.enableManagedSettings
|
|
1352
|
+
enableManagedSettings: config.enableManagedSettings,
|
|
1353
|
+
managedSettings: config.managedSettings
|
|
1348
1354
|
});
|
|
1349
1355
|
const { workspacePath, capabilities, openCanvases } = response;
|
|
1350
1356
|
session["_workspacePath"] = workspacePath;
|
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,
|