@github/copilot-sdk 1.0.15-preview.3 → 1.0.15-preview.4

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/session.js CHANGED
@@ -5,27 +5,12 @@ import { CanvasError } from "./canvas.js";
5
5
  import { getTraceContext } from "./telemetry.js";
6
6
  import { isResponseSchema, toJsonSchema } from "./schema.js";
7
7
  import { isAttributedPermissionResult } from "./types.js";
8
- import {
9
- FACTORY_AGENT_OPTION_KEYS,
10
- getFactoryDefinition,
11
- FactoryResumeError,
12
- isFactoryRunTerminal
13
- } from "./factory.js";
14
8
  import {
15
9
  WORKFLOW_AGENT_OPTION_KEYS,
16
10
  getWorkflowDefinition,
17
11
  WorkflowResumeError,
18
12
  isWorkflowRunTerminal
19
13
  } from "./workflow.js";
20
- function isFactoryResumeErrorCode(value) {
21
- 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";
22
- }
23
- function copyDefinedFactoryAgentOption(source, target, key) {
24
- const value = source[key];
25
- if (value !== void 0) {
26
- target[key] = value;
27
- }
28
- }
29
14
  function isWorkflowResumeErrorCode(value) {
30
15
  return value === "not_found" || value === "non_resumable" || value === "workflow_run_not_resumable" || value === "already_active" || value === "workflow_already_running" || value === "workflow_limits_invalid" || value === "workflow_session_disposed" || value === "workflow_storage_unavailable" || value === "workflow_storage_corrupt";
31
16
  }
@@ -35,14 +20,6 @@ function copyDefinedWorkflowAgentOption(source, target, key) {
35
20
  target[key] = value;
36
21
  }
37
22
  }
38
- const factoryExecutionStore = new AsyncLocalStorage();
39
- function throwIfFactoryExecutionIsActive() {
40
- if (factoryExecutionStore.getStore()?.active) {
41
- throw new Error(
42
- "factory.run, factory.resume, and factory.pause are not allowed while a factory body is running on this call path."
43
- );
44
- }
45
- }
46
23
  const workflowExecutionStore = new AsyncLocalStorage();
47
24
  function throwIfWorkflowExecutionIsActive() {
48
25
  if (workflowExecutionStore.getStore()?.active) {
@@ -55,10 +32,6 @@ function runInWorkflowHelperScope(helperScope, callback) {
55
32
  const current = workflowExecutionStore.getStore();
56
33
  return workflowExecutionStore.run({ active: current?.active ?? false, helperScope }, callback);
57
34
  }
58
- function runInFactoryHelperScope(helperScope, callback) {
59
- const current = factoryExecutionStore.getStore();
60
- return factoryExecutionStore.run({ active: current?.active ?? false, helperScope }, callback);
61
- }
62
35
  function deserializeHookInput(raw) {
63
36
  if (!raw || typeof raw !== "object" || typeof raw.timestamp !== "number") {
64
37
  return raw;
@@ -81,68 +54,20 @@ function isOpenCanvasInstance(value) {
81
54
  }
82
55
  const FACTORY_LOG_FLUSH_DELAY_MS = 10;
83
56
  const MAX_FACTORY_FANOUT_ITEMS = 4096;
84
- function assertFactoryFanoutSize(kind, size) {
57
+ function assertWorkflowFanoutSize(kind, size) {
85
58
  if (size > MAX_FACTORY_FANOUT_ITEMS) {
86
59
  throw new Error(
87
60
  `${kind}() accepts at most ${MAX_FACTORY_FANOUT_ITEMS} items; got ${size}.`
88
61
  );
89
62
  }
90
63
  }
91
- async function runFactoryParallel(thunks) {
92
- if (!Array.isArray(thunks)) {
93
- throw new Error(
94
- "parallel() expects an array of functions, not promises. Wrap each call: () => agent(...)"
95
- );
96
- }
97
- assertFactoryFanoutSize("parallel", thunks.length);
98
- if (thunks.some((thunk) => typeof thunk !== "function")) {
99
- throw new Error(
100
- "parallel() expects an array of functions, not promises. Wrap each call: () => agent(...)"
101
- );
102
- }
103
- return Promise.all(
104
- thunks.map(
105
- (thunk) => Promise.resolve().then(() => runInFactoryHelperScope("parallel", thunk)).catch((error) => {
106
- if (isFactoryFatalError(error)) {
107
- throw error;
108
- }
109
- return null;
110
- })
111
- )
112
- );
113
- }
114
- async function runFactoryPipeline(items, ...stages) {
115
- if (!Array.isArray(items)) {
116
- throw new Error("pipeline(items, ...stages): items must be an array");
117
- }
118
- assertFactoryFanoutSize("pipeline", items.length);
119
- return Promise.all(
120
- items.map(async (item, index) => {
121
- let previous = item;
122
- for (const stage of stages) {
123
- try {
124
- previous = await runInFactoryHelperScope(
125
- "pipeline",
126
- () => stage(previous, item, index)
127
- );
128
- } catch (error) {
129
- if (isFactoryFatalError(error)) {
130
- throw error;
131
- }
132
- return null;
133
- }
134
- }
135
- return previous;
136
- })
137
- );
138
- }
139
64
  async function runWorkflowParallel(thunks) {
140
65
  if (!Array.isArray(thunks)) {
141
66
  throw new Error(
142
67
  "parallel() expects an array of functions, not promises. Wrap each call: () => agent(...)"
143
68
  );
144
69
  }
145
- assertFactoryFanoutSize("parallel", thunks.length);
70
+ assertWorkflowFanoutSize("parallel", thunks.length);
146
71
  if (thunks.some((thunk) => typeof thunk !== "function")) {
147
72
  throw new Error(
148
73
  "parallel() expects an array of functions, not promises. Wrap each call: () => agent(...)"
@@ -151,7 +76,7 @@ async function runWorkflowParallel(thunks) {
151
76
  return Promise.all(
152
77
  thunks.map(
153
78
  (thunk) => Promise.resolve().then(() => runInWorkflowHelperScope("parallel", thunk)).catch((error) => {
154
- if (isFactoryFatalError(error)) {
79
+ if (isWorkflowFatalError(error)) {
155
80
  throw error;
156
81
  }
157
82
  return null;
@@ -163,7 +88,7 @@ async function runWorkflowPipeline(items, ...stages) {
163
88
  if (!Array.isArray(items)) {
164
89
  throw new Error("pipeline(items, ...stages): items must be an array");
165
90
  }
166
- assertFactoryFanoutSize("pipeline", items.length);
91
+ assertWorkflowFanoutSize("pipeline", items.length);
167
92
  return Promise.all(
168
93
  items.map(async (item, index) => {
169
94
  let previous = item;
@@ -174,7 +99,7 @@ async function runWorkflowPipeline(items, ...stages) {
174
99
  () => stage(previous, item, index)
175
100
  );
176
101
  } catch (error) {
177
- if (isFactoryFatalError(error)) {
102
+ if (isWorkflowFatalError(error)) {
178
103
  throw error;
179
104
  }
180
105
  return null;
@@ -184,85 +109,6 @@ async function runWorkflowPipeline(items, ...stages) {
184
109
  })
185
110
  );
186
111
  }
187
- class FactoryProgressBuffer {
188
- constructor(send) {
189
- this.send = send;
190
- }
191
- send;
192
- nextSeq = 0;
193
- pending = [];
194
- flushTimer;
195
- flushTail = Promise.resolve();
196
- flushError;
197
- flushFailed = false;
198
- closed = false;
199
- enqueue(kind, text) {
200
- if (this.closed) {
201
- throw new Error("Cannot log after the factory run has settled");
202
- }
203
- this.pending.push({ seq: this.nextSeq++, kind, text });
204
- this.scheduleFlush();
205
- }
206
- async flush() {
207
- this.clearFlushTimer();
208
- const lines = this.pending.splice(0);
209
- if (lines.length > 0) {
210
- this.flushTail = this.flushTail.then(async () => {
211
- try {
212
- await this.send(lines);
213
- } catch (error) {
214
- if (!this.flushFailed) {
215
- this.flushFailed = true;
216
- this.flushError = error;
217
- }
218
- }
219
- });
220
- }
221
- await this.flushTail;
222
- if (this.flushFailed) {
223
- throw this.flushError;
224
- }
225
- }
226
- async close() {
227
- this.closed = true;
228
- this.clearFlushTimer();
229
- const lines = this.pending.splice(0);
230
- await this.flushTail;
231
- if (this.flushFailed) {
232
- console.warn(
233
- "Ignoring a background factory progress flush failure after the factory body settled",
234
- this.flushError
235
- );
236
- }
237
- if (lines.length > 0) {
238
- try {
239
- await this.send(lines);
240
- } catch (error) {
241
- console.warn(
242
- "Failed to flush final factory progress after the factory body settled",
243
- error
244
- );
245
- }
246
- }
247
- }
248
- scheduleFlush() {
249
- if (this.flushTimer !== void 0) {
250
- return;
251
- }
252
- this.flushTimer = setTimeout(() => {
253
- this.flushTimer = void 0;
254
- void this.flush().catch(() => {
255
- });
256
- }, FACTORY_LOG_FLUSH_DELAY_MS);
257
- this.flushTimer.unref?.();
258
- }
259
- clearFlushTimer() {
260
- if (this.flushTimer !== void 0) {
261
- clearTimeout(this.flushTimer);
262
- this.flushTimer = void 0;
263
- }
264
- }
265
- }
266
112
  class WorkflowProgressBuffer {
267
113
  constructor(send) {
268
114
  this.send = send;
@@ -342,38 +188,30 @@ class WorkflowProgressBuffer {
342
188
  }
343
189
  }
344
190
  }
345
- async function awaitFactoryOperation(operation, signal) {
191
+ async function awaitWorkflowOperation(operation, signal) {
346
192
  let rejectAbort;
347
193
  const abortPromise = new Promise((_resolve, reject) => {
348
194
  rejectAbort = reject;
349
195
  });
350
- const onAbort = () => rejectAbort?.(signal.reason ?? new DOMException("Factory run was aborted", "AbortError"));
196
+ const onAbort = () => rejectAbort?.(signal.reason ?? new DOMException("Workflow run was aborted", "AbortError"));
351
197
  signal.addEventListener("abort", onAbort, { once: true });
352
198
  try {
353
- throwIfFactoryAborted(signal);
199
+ throwIfWorkflowAborted(signal);
354
200
  return await Promise.race([operation(), abortPromise]);
355
201
  } finally {
356
202
  signal.removeEventListener("abort", onAbort);
357
203
  }
358
204
  }
359
- async function awaitWorkflowOperation(operation, signal) {
360
- return awaitFactoryOperation(operation, signal);
361
- }
362
- function throwIfFactoryAborted(signal) {
363
- if (signal.aborted) {
364
- throw signal.reason ?? new DOMException("Factory run was aborted", "AbortError");
365
- }
366
- }
367
205
  function throwIfWorkflowAborted(signal) {
368
206
  if (signal.aborted) {
369
207
  throw signal.reason ?? new DOMException("Workflow run was aborted", "AbortError");
370
208
  }
371
209
  }
372
- function isFactoryAbortError(error) {
210
+ function isWorkflowAbortError(error) {
373
211
  return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
374
212
  }
375
- function isFactoryFatalError(error) {
376
- return isFactoryAbortError(error) || error instanceof ResponseError || error instanceof ConnectionError;
213
+ function isWorkflowFatalError(error) {
214
+ return isWorkflowAbortError(error) || error instanceof ResponseError || error instanceof ConnectionError;
377
215
  }
378
216
  const TOOL_SEARCH_TOOL_NAME = "tool_search_tool";
379
217
  class CopilotSession {
@@ -405,8 +243,6 @@ class CopilotSession {
405
243
  canvases = /* @__PURE__ */ new Map();
406
244
  bearerTokenProviders = /* @__PURE__ */ new Map();
407
245
  commandHandlers = /* @__PURE__ */ new Map();
408
- factories = /* @__PURE__ */ new Map();
409
- factoryAbortControllers = /* @__PURE__ */ new Map();
410
246
  workflows = /* @__PURE__ */ new Map();
411
247
  workflowAbortControllers = /* @__PURE__ */ new Map();
412
248
  permissionHandler;
@@ -430,68 +266,11 @@ class CopilotSession {
430
266
  /** @internal Client session API handlers, populated by CopilotClient during create/resume. */
431
267
  clientSessionApis = {};
432
268
  /**
433
- * Friendly factory API for running registered factories by name or handle.
269
+ * Friendly workflow API for running registered workflows by name or handle.
434
270
  *
435
- * @experimental Part of the experimental Agent Factories surface and may
271
+ * @experimental Part of the experimental Dynamic Workflows surface and may
436
272
  * change or be removed in future SDK or CLI releases.
437
273
  */
438
- factory = {
439
- run: (async (nameOrHandle, options) => {
440
- throwIfFactoryExecutionIsActive();
441
- const name = typeof nameOrHandle === "string" ? nameOrHandle : getFactoryDefinition(nameOrHandle).meta.name;
442
- if (options?.resumeFromRunId !== void 0) {
443
- return this.factory.resume(options.resumeFromRunId, {
444
- limits: options.limits,
445
- notifyOnComplete: options.notifyOnComplete,
446
- logPhaseNames: options.logPhaseNames
447
- });
448
- }
449
- const envelope = await this.rpc.factory.run({
450
- name,
451
- args: options?.args === void 0 ? {} : options.args,
452
- options: {
453
- limits: options?.limits,
454
- notifyOnComplete: options?.notifyOnComplete,
455
- logPhaseNames: options?.logPhaseNames
456
- }
457
- });
458
- return this.settleFactoryRun(envelope);
459
- }),
460
- resume: (async (runId, options) => {
461
- throwIfFactoryExecutionIsActive();
462
- let response;
463
- try {
464
- response = await this.rpc.factory.resume({
465
- runId,
466
- limits: options?.limits,
467
- notifyOnComplete: options?.notifyOnComplete,
468
- logPhaseNames: options?.logPhaseNames
469
- });
470
- } catch (error) {
471
- if (error instanceof ResponseError && typeof error.data === "object" && error.data !== null) {
472
- const code = error.data.code;
473
- if (isFactoryResumeErrorCode(code)) {
474
- throw new FactoryResumeError(code, error.message);
475
- }
476
- }
477
- throw error;
478
- }
479
- return this.settleFactoryRun(response.run);
480
- }),
481
- getRun: async (runId) => this.rpc.factory.getRun({ runId }),
482
- waitForRun: (runId, options) => this.waitForFactoryRun(runId, options?.signal),
483
- listRuns: (async (options) => {
484
- const page = await this.rpc.factory.listRuns(options ?? {});
485
- return options === void 0 ? page.runs : page;
486
- }),
487
- getRunDetail: (runId) => this.rpc.factory.getRunDetail({ runId }),
488
- getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
489
- pause: async (runId) => {
490
- throwIfFactoryExecutionIsActive();
491
- return this.rpc.factory.pause({ runId });
492
- },
493
- cancel: async (runId) => this.rpc.factory.cancel({ runId })
494
- };
495
274
  workflow = {
496
275
  run: (async (nameOrHandle, options) => {
497
276
  throwIfWorkflowExecutionIsActive();
@@ -542,93 +321,6 @@ class CopilotSession {
542
321
  },
543
322
  cancel: async (runId) => this.rpc.workflow.cancel({ runId })
544
323
  };
545
- /**
546
- * Resolve a start/resume envelope into the terminal envelope callers expect.
547
- *
548
- * The CLI may answer `session.factory.run` and `session.factory.resume`
549
- * before the run settles, so a non-terminal envelope is followed by a wait
550
- * on the run's terminal state.
551
- */
552
- settleFactoryRun(envelope) {
553
- if (isFactoryRunTerminal(envelope.status)) {
554
- return Promise.resolve(envelope);
555
- }
556
- return this.waitForFactoryRun(envelope.runId);
557
- }
558
- /**
559
- * Resolve when a factory run reaches a terminal status.
560
- *
561
- * The subscription is installed *before* the first read so a transition
562
- * landing between the two cannot be missed, and re-reads are serialized so
563
- * overlapping invalidation events cannot interleave — the run's revision
564
- * advances once per operation, so a burst of events is common and must
565
- * collapse into a single in-flight read. A bounded periodic re-read keeps a
566
- * dropped invalidation from leaving the wait pending forever.
567
- */
568
- waitForFactoryRun(runId, signal) {
569
- const abortError = () => signal?.reason ?? new DOMException("Factory run wait was aborted", "AbortError");
570
- if (signal?.aborted === true) {
571
- return Promise.reject(abortError());
572
- }
573
- return new Promise((resolve, reject) => {
574
- let settled = false;
575
- let reading = false;
576
- let rereadRequested = false;
577
- let pollHandle;
578
- let unsubscribe;
579
- let onAbort;
580
- const finish = (complete) => {
581
- if (settled) {
582
- return;
583
- }
584
- settled = true;
585
- if (pollHandle !== void 0) {
586
- clearInterval(pollHandle);
587
- }
588
- unsubscribe?.();
589
- if (onAbort !== void 0) {
590
- signal?.removeEventListener("abort", onAbort);
591
- }
592
- complete();
593
- };
594
- const read = async () => {
595
- if (settled) {
596
- return;
597
- }
598
- if (reading) {
599
- rereadRequested = true;
600
- return;
601
- }
602
- reading = true;
603
- try {
604
- do {
605
- rereadRequested = false;
606
- const envelope = await this.rpc.factory.getRun({ runId });
607
- if (isFactoryRunTerminal(envelope.status)) {
608
- finish(() => resolve(envelope));
609
- return;
610
- }
611
- } while (rereadRequested && !settled);
612
- } catch (error) {
613
- finish(() => reject(error));
614
- } finally {
615
- reading = false;
616
- }
617
- };
618
- if (signal !== void 0) {
619
- onAbort = () => finish(() => reject(abortError()));
620
- signal.addEventListener("abort", onAbort, { once: true });
621
- }
622
- unsubscribe = this.on("factory.run_updated", (event) => {
623
- if (event.data.runId === runId) {
624
- void read();
625
- }
626
- });
627
- pollHandle = setInterval(() => void read(), 5e3);
628
- pollHandle.unref?.();
629
- void read();
630
- });
631
- }
632
324
  settleWorkflowRun(envelope) {
633
325
  if (isWorkflowRunTerminal(envelope.status)) {
634
326
  return Promise.resolve(envelope);
@@ -699,7 +391,7 @@ class CopilotSession {
699
391
  onAbort = () => finish(() => reject(abortError()));
700
392
  signal.addEventListener("abort", onAbort, { once: true });
701
393
  }
702
- unsubscribe = this.on("factory.run_updated", (event) => {
394
+ unsubscribe = this.on("workflow.run_updated", (event) => {
703
395
  if (event.data.runId === runId) {
704
396
  void read();
705
397
  }
@@ -965,13 +657,6 @@ class CopilotSession {
965
657
  this.autoModeSwitchHandler = void 0;
966
658
  this.commandHandlers.clear();
967
659
  this.canvases.clear();
968
- this.factories.clear();
969
- for (const controllersForRun of this.factoryAbortControllers.values()) {
970
- for (const controller of controllersForRun.values()) {
971
- controller.abort();
972
- }
973
- }
974
- this.factoryAbortControllers.clear();
975
660
  this.workflows.clear();
976
661
  for (const controllersForRun of this.workflowAbortControllers.values()) {
977
662
  for (const controller of controllersForRun.values()) {
@@ -1426,192 +1111,6 @@ class CopilotSession {
1426
1111
  }
1427
1112
  };
1428
1113
  }
1429
- /**
1430
- * Registers factory closures and reverse-RPC handlers for this session.
1431
- *
1432
- * @param factories - Factory handles declared by the joining extension.
1433
- * @internal Called by the SDK when an extension joins a session.
1434
- */
1435
- registerFactories(factories) {
1436
- this.factories.clear();
1437
- if (!factories || factories.length === 0) {
1438
- delete this.clientSessionApis.factory;
1439
- return;
1440
- }
1441
- for (const handle of factories) {
1442
- const definition = getFactoryDefinition(handle);
1443
- if (this.factories.has(definition.meta.name)) {
1444
- throw new Error(
1445
- `Duplicate factory name "${definition.meta.name}". Factory names must be unique within a joinSession call.`
1446
- );
1447
- }
1448
- this.factories.set(definition.meta.name, definition);
1449
- }
1450
- const self = this;
1451
- this.clientSessionApis.factory = {
1452
- async execute(params) {
1453
- const definition = self.factories.get(params.name);
1454
- if (!definition) {
1455
- const message = `No factory registered with name "${params.name}"`;
1456
- throw new ResponseError(ErrorCodes.InvalidParams, message, {
1457
- code: "factory_not_found",
1458
- name: params.name
1459
- });
1460
- }
1461
- const controller = new AbortController();
1462
- let controllersForRun = self.factoryAbortControllers.get(params.runId);
1463
- if (controllersForRun === void 0) {
1464
- controllersForRun = /* @__PURE__ */ new Map();
1465
- self.factoryAbortControllers.set(params.runId, controllersForRun);
1466
- }
1467
- controllersForRun.set(params.executionToken, controller);
1468
- const progress = new FactoryProgressBuffer(async (lines) => {
1469
- await self.rpc.factory.log({
1470
- runId: params.runId,
1471
- executionToken: params.executionToken,
1472
- lines
1473
- });
1474
- });
1475
- try {
1476
- const context = {
1477
- runId: params.runId,
1478
- args: params.args,
1479
- session: self,
1480
- signal: controller.signal,
1481
- phase: (title) => {
1482
- throwIfFactoryAborted(controller.signal);
1483
- progress.enqueue("phase", title);
1484
- },
1485
- log: (message) => {
1486
- throwIfFactoryAborted(controller.signal);
1487
- progress.enqueue("log", message);
1488
- },
1489
- agent: async (prompt, options = {}) => {
1490
- await progress.flush();
1491
- const opts = {};
1492
- for (const key of FACTORY_AGENT_OPTION_KEYS) {
1493
- copyDefinedFactoryAgentOption(options, opts, key);
1494
- }
1495
- const response = await awaitFactoryOperation(
1496
- () => self.rpc.factory.agent({
1497
- factoryRunId: params.runId,
1498
- executionToken: params.executionToken,
1499
- prompt,
1500
- opts
1501
- }),
1502
- controller.signal
1503
- );
1504
- return response.result ?? null;
1505
- },
1506
- step: async (key, producer, options = {}) => {
1507
- await progress.flush();
1508
- if (options.volatile) {
1509
- throwIfFactoryAborted(controller.signal);
1510
- return producer();
1511
- }
1512
- const cached = await awaitFactoryOperation(
1513
- () => self.rpc.factory.journal.get({
1514
- runId: params.runId,
1515
- executionToken: params.executionToken,
1516
- key
1517
- }),
1518
- controller.signal
1519
- );
1520
- if (cached.hit) {
1521
- if (cached.resultJson === void 0) {
1522
- throw new Error(
1523
- `step("${key}") journal returned a hit without a result`
1524
- );
1525
- }
1526
- assertFactoryStepResult(cached.resultJson, key);
1527
- return cached.resultJson;
1528
- }
1529
- const result2 = await producer();
1530
- assertFactoryStepResult(result2, key);
1531
- await awaitFactoryOperation(
1532
- () => self.rpc.factory.journal.put({
1533
- runId: params.runId,
1534
- executionToken: params.executionToken,
1535
- key,
1536
- resultJson: result2
1537
- }),
1538
- controller.signal
1539
- );
1540
- return result2;
1541
- },
1542
- pause: async (key) => {
1543
- if (typeof key !== "string" || key.length === 0) {
1544
- throw new Error("Factory pause checkpoint key must not be empty");
1545
- }
1546
- const helperScope = factoryExecutionStore.getStore()?.helperScope;
1547
- if (helperScope !== void 0) {
1548
- throw new Error(
1549
- `Factory pause checkpoints are not allowed inside ${helperScope}() branches`
1550
- );
1551
- }
1552
- await progress.flush();
1553
- const response = await awaitFactoryOperation(
1554
- () => self.internalRpc.factory.pauseAtCheckpoint({
1555
- runId: params.runId,
1556
- executionToken: params.executionToken,
1557
- key
1558
- }),
1559
- controller.signal
1560
- );
1561
- switch (response.action) {
1562
- case "continue":
1563
- return;
1564
- case "pause":
1565
- await awaitFactoryOperation(
1566
- () => new Promise(() => {
1567
- }),
1568
- controller.signal
1569
- );
1570
- }
1571
- },
1572
- parallel: runFactoryParallel,
1573
- pipeline: runFactoryPipeline,
1574
- factory: async () => {
1575
- throw new Error("nested factories are not supported");
1576
- }
1577
- };
1578
- const execution = { active: true };
1579
- const result = await factoryExecutionStore.run(execution, async () => {
1580
- try {
1581
- return await definition.run(context);
1582
- } finally {
1583
- execution.active = false;
1584
- }
1585
- });
1586
- if (result === void 0) {
1587
- return {};
1588
- }
1589
- assertFactoryResult(result);
1590
- return { result };
1591
- } finally {
1592
- try {
1593
- await progress.close();
1594
- } finally {
1595
- const controllersForRun2 = self.factoryAbortControllers.get(params.runId);
1596
- if (controllersForRun2?.get(params.executionToken) === controller) {
1597
- controllersForRun2.delete(params.executionToken);
1598
- if (controllersForRun2.size === 0) {
1599
- self.factoryAbortControllers.delete(params.runId);
1600
- }
1601
- }
1602
- }
1603
- }
1604
- },
1605
- async abort(params) {
1606
- const controllersForRun = self.factoryAbortControllers.get(params.runId);
1607
- const controller = controllersForRun?.get(params.executionToken);
1608
- if (controller !== void 0) {
1609
- controller.abort(new DOMException("Factory run was aborted", "AbortError"));
1610
- }
1611
- return {};
1612
- }
1613
- };
1614
- }
1615
1114
  /**
1616
1115
  * Registers workflow closures and reverse-RPC handlers for this session.
1617
1116
  *
@@ -2478,20 +1977,6 @@ function assertStrictJson(value, context) {
2478
1977
  };
2479
1978
  visit(value, "$", context.allowTopLevelUndefined);
2480
1979
  }
2481
- function assertFactoryResult(value) {
2482
- assertStrictJson(value, {
2483
- code: "factory_result_not_json",
2484
- label: "Factory result",
2485
- allowTopLevelUndefined: true
2486
- });
2487
- }
2488
- function assertFactoryStepResult(value, key) {
2489
- assertStrictJson(value, {
2490
- code: "factory_step_not_json",
2491
- label: `Factory step "${key}" result`,
2492
- allowTopLevelUndefined: false
2493
- });
2494
- }
2495
1980
  function assertWorkflowResult(value) {
2496
1981
  assertStrictJson(value, {
2497
1982
  code: "workflow_result_not_json",