@pi-unipi/subagents 2.6.0 → 2.6.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/README.md +89 -78
- package/agents/delegate.md +14 -0
- package/agents/oracle.md +78 -0
- package/agents/researcher.md +52 -0
- package/agents/reviewer.md +79 -0
- package/agents/scout.md +50 -0
- package/agents/worker.md +59 -0
- package/package.json +19 -17
- package/prompts/council.md +48 -0
- package/prompts/gather-context-and-clarify.md +13 -0
- package/prompts/parallel-cleanup.md +59 -0
- package/prompts/parallel-research.md +50 -0
- package/prompts/parallel-review.md +54 -0
- package/prompts/review-loop.md +43 -0
- package/skills/council-mode/SKILL.md +230 -0
- package/skills/subagents/SKILL.md +49 -0
- package/skills/subagents/references/constraints-and-recipes.md +259 -0
- package/skills/subagents/references/execution-controls.md +454 -0
- package/skills/subagents/references/management-authoring-rpc.md +161 -0
- package/skills/subagents/references/multi-lane-orchestration.md +39 -0
- package/skills/subagents/references/prompting-and-roles.md +267 -0
- package/src/acceptance.ts +331 -0
- package/src/agent-manager.ts +405 -0
- package/src/agent-memory.ts +300 -0
- package/src/agent-overrides.ts +183 -0
- package/src/agent-runner.ts +265 -0
- package/src/async-runner.ts +417 -0
- package/src/authority-policy.ts +47 -0
- package/src/budgets.ts +285 -0
- package/src/child-safety.ts +140 -0
- package/src/config.ts +226 -0
- package/src/conversation-viewer.ts +281 -0
- package/src/core-compat.ts +94 -0
- package/src/custom-agents.ts +323 -0
- package/src/file-system-retry.ts +50 -0
- package/src/fleet-data.ts +61 -0
- package/src/fleet-view.ts +316 -0
- package/src/foreground-detach.ts +59 -0
- package/src/fork-context.ts +285 -0
- package/src/global.d.ts +7 -0
- package/src/guide.ts +129 -0
- package/src/index.ts +1149 -0
- package/src/mission-state.ts +133 -0
- package/src/mission-store.ts +434 -0
- package/src/model-resolver.ts +79 -0
- package/src/output-limits.ts +142 -0
- package/src/parity-types.ts +315 -0
- package/src/pi-args.ts +161 -0
- package/src/pi-spawn.ts +147 -0
- package/src/result-files.ts +232 -0
- package/src/result-watcher.ts +221 -0
- package/src/retained-children.ts +176 -0
- package/src/run-fanout-budget.ts +356 -0
- package/src/scheduled-runs.ts +351 -0
- package/src/schemas.ts +263 -0
- package/src/slash-commands.ts +77 -0
- package/src/supervisor-channel.ts +249 -0
- package/src/tool-handler.ts +1144 -0
- package/src/types.ts +238 -0
- package/src/widget.ts +447 -0
- package/src/workflow-script.ts +737 -0
- package/src/workflow-worker.ts +384 -0
- package/src/worktree.ts +614 -0
- package/dist/agent-manager.d.ts +0 -81
- package/dist/agent-manager.d.ts.map +0 -1
- package/dist/agent-manager.js +0 -295
- package/dist/agent-manager.js.map +0 -1
- package/dist/agent-runner.d.ts +0 -51
- package/dist/agent-runner.d.ts.map +0 -1
- package/dist/agent-runner.js +0 -262
- package/dist/agent-runner.js.map +0 -1
- package/dist/config.d.ts +0 -24
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -132
- package/dist/config.js.map +0 -1
- package/dist/conversation-viewer.d.ts +0 -40
- package/dist/conversation-viewer.d.ts.map +0 -1
- package/dist/conversation-viewer.js +0 -276
- package/dist/conversation-viewer.js.map +0 -1
- package/dist/core-compat.d.ts +0 -21
- package/dist/core-compat.d.ts.map +0 -1
- package/dist/core-compat.js +0 -86
- package/dist/core-compat.js.map +0 -1
- package/dist/custom-agents.d.ts +0 -14
- package/dist/custom-agents.d.ts.map +0 -1
- package/dist/custom-agents.js +0 -113
- package/dist/custom-agents.js.map +0 -1
- package/dist/file-lock.d.ts +0 -42
- package/dist/file-lock.d.ts.map +0 -1
- package/dist/file-lock.js +0 -91
- package/dist/file-lock.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -758
- package/dist/index.js.map +0 -1
- package/dist/model-resolver.d.ts +0 -19
- package/dist/model-resolver.d.ts.map +0 -1
- package/dist/model-resolver.js +0 -61
- package/dist/model-resolver.js.map +0 -1
- package/dist/types.d.ts +0 -98
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -47
- package/dist/types.js.map +0 -1
- package/dist/widget.d.ts +0 -56
- package/dist/widget.d.ts.map +0 -1
- package/dist/widget.js +0 -396
- package/dist/widget.js.map +0 -1
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pi-unipi/subagents — workflowScript host runtime
|
|
3
|
+
*
|
|
4
|
+
* Ported from pi-subagents src/workflows/scripted-workflow.ts (host half).
|
|
5
|
+
* Spawns the sandbox worker, routes RPC calls (run/all/steer/status/state) to
|
|
6
|
+
* host callbacks, tracks children + trace, enforces the unawaited-launch
|
|
7
|
+
* contract, and resolves with { value, emits, console, trace, children }.
|
|
8
|
+
*
|
|
9
|
+
* The launch callback is OURS: in-process AgentManager.spawn (foreground) —
|
|
10
|
+
* Phase 3 swaps in the process-based runner for async workflows.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Worker } from "node:worker_threads";
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { dirname, resolve as resolvePath } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
19
|
+
const requireFromPackage = createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
export interface WorkflowScriptTraceEntry {
|
|
22
|
+
operation: "run" | "steer" | "status";
|
|
23
|
+
key: string;
|
|
24
|
+
state: string;
|
|
25
|
+
durationMs?: number;
|
|
26
|
+
phase?: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
agent?: string;
|
|
29
|
+
runId?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface WorkflowScriptChildResult {
|
|
34
|
+
key: string;
|
|
35
|
+
ok: boolean;
|
|
36
|
+
output: string;
|
|
37
|
+
error?: string;
|
|
38
|
+
detached?: boolean;
|
|
39
|
+
runId?: string;
|
|
40
|
+
agent?: string;
|
|
41
|
+
artifactPaths?: string[];
|
|
42
|
+
[extra: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WorkflowSteerResult {
|
|
46
|
+
key: string;
|
|
47
|
+
state: "queued" | "delivered" | "missed" | "failed";
|
|
48
|
+
requestId?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface WorkflowScriptResult {
|
|
53
|
+
value: unknown;
|
|
54
|
+
emits: unknown[];
|
|
55
|
+
console: Array<{ level: "log" | "info" | "warn" | "error"; text: string }>;
|
|
56
|
+
trace: WorkflowScriptTraceEntry[];
|
|
57
|
+
children: WorkflowScriptChildResult[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class WorkflowScriptError extends Error {
|
|
61
|
+
readonly partial: Omit<WorkflowScriptResult, "value">;
|
|
62
|
+
|
|
63
|
+
constructor(message: string, partial: Omit<WorkflowScriptResult, "value">) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.name = "WorkflowScriptError";
|
|
66
|
+
this.partial = partial;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface RunWorkflowScriptOptions {
|
|
71
|
+
script: string;
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
/** Spawn-budget admission hook (called before children start; may throw). */
|
|
75
|
+
admit?: (calls: Array<{ key: string; params: Record<string, unknown> }>) => void | Promise<void>;
|
|
76
|
+
/** OUR launch path: in-process foreground spawn (Phase 3: process runner). */
|
|
77
|
+
launch: (
|
|
78
|
+
key: string,
|
|
79
|
+
params: Record<string, unknown>,
|
|
80
|
+
signal: AbortSignal,
|
|
81
|
+
admission: { admitted: boolean },
|
|
82
|
+
) => Promise<WorkflowScriptChildResult>;
|
|
83
|
+
status: (keyOrRunId: string, signal: AbortSignal) => Promise<WorkflowScriptChildResult>;
|
|
84
|
+
steer?: (
|
|
85
|
+
key: string,
|
|
86
|
+
message: string,
|
|
87
|
+
options: { mode?: string; index?: number; ackTimeoutMs?: number },
|
|
88
|
+
signal: AbortSignal,
|
|
89
|
+
) => Promise<WorkflowSteerResult>;
|
|
90
|
+
state?: {
|
|
91
|
+
get: (key: string) => unknown | Promise<unknown>;
|
|
92
|
+
set: (key: string, value: unknown) => void | Promise<void>;
|
|
93
|
+
};
|
|
94
|
+
onTrace?: (trace: WorkflowScriptTraceEntry[]) => void;
|
|
95
|
+
onEmit?: (emits: unknown[]) => void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
99
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function isPlainJsonObject(value: unknown): value is Record<string, unknown> {
|
|
103
|
+
if (!isRecord(value)) return false;
|
|
104
|
+
const prototype = Object.getPrototypeOf(value);
|
|
105
|
+
return prototype === null || prototype === Object.prototype;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function assertWorkflowJsonValue(value: unknown, path = "value", seen = new Set<object>()): void {
|
|
109
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return;
|
|
110
|
+
if (typeof value === "number") {
|
|
111
|
+
if (!Number.isFinite(value)) throw new Error(`${path} must contain only finite JSON numbers.`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (typeof value !== "object") throw new Error(`${path} must be a JSON value; received ${typeof value}.`);
|
|
115
|
+
if (seen.has(value)) throw new Error(`${path} must not contain cycles.`);
|
|
116
|
+
seen.add(value);
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
for (let index = 0; index < value.length; index++) {
|
|
119
|
+
if (!Object.hasOwn(value, index)) throw new Error(`${path} must not contain sparse array entries.`);
|
|
120
|
+
assertWorkflowJsonValue(value[index], `${path}[${index}]`, seen);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
const prototype = Object.getPrototypeOf(value);
|
|
124
|
+
if (prototype !== null && prototype !== Object.prototype) {
|
|
125
|
+
throw new Error(`${path} must contain only plain JSON objects.`);
|
|
126
|
+
}
|
|
127
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
128
|
+
throw new Error(`${path} must not contain symbol keys.`);
|
|
129
|
+
}
|
|
130
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
131
|
+
assertWorkflowJsonValue(entry, `${path}.${key}`, seen);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
seen.delete(value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function formatWorkflowJsonPreview(value: unknown, maxLength: number): string | undefined {
|
|
138
|
+
try {
|
|
139
|
+
assertWorkflowJsonValue(value);
|
|
140
|
+
const serialized = JSON.stringify(value);
|
|
141
|
+
return typeof serialized === "string" ? serialized.slice(0, maxLength) : undefined;
|
|
142
|
+
} catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface SimpleWorkflowRunPreview {
|
|
148
|
+
agent?: string;
|
|
149
|
+
task?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Display-only preview for the exact simple `return runs.run(key, {...})` form. */
|
|
153
|
+
export function previewSimpleWorkflowRun(script: string | undefined): SimpleWorkflowRunPreview | undefined {
|
|
154
|
+
const body = script
|
|
155
|
+
?.match(/^\s*return\s+(?:await\s+)?runs\.run\s*\(\s*(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`[^`$\\]*`)\s*,\s*\{([\s\S]*)\}\s*\)\s*;?\s*$/)
|
|
156
|
+
?.[1];
|
|
157
|
+
if (body === undefined) return undefined;
|
|
158
|
+
const readProperty = (name: "agent" | "task"): string | undefined => {
|
|
159
|
+
const match = body.match(
|
|
160
|
+
new RegExp(`(?:^|,)\\s*(?:${name}|["']${name}["'])\\s*:\\s*("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\u0060[^\u0060$\\\\]*\u0060)`),
|
|
161
|
+
);
|
|
162
|
+
if (!match?.[1]) return undefined;
|
|
163
|
+
const literal = match[1];
|
|
164
|
+
if (literal.startsWith('"')) {
|
|
165
|
+
try {
|
|
166
|
+
return JSON.parse(literal) as string;
|
|
167
|
+
} catch {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (literal.slice(1, -1).includes("\\")) return undefined;
|
|
172
|
+
return literal.slice(1, -1);
|
|
173
|
+
};
|
|
174
|
+
const agent = readProperty("agent");
|
|
175
|
+
const task = readProperty("task");
|
|
176
|
+
return { ...(agent !== undefined ? { agent } : {}), ...(task !== undefined ? { task } : {}) };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function stableJson(value: unknown): string {
|
|
180
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
181
|
+
if (isRecord(value)) {
|
|
182
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
|
|
183
|
+
}
|
|
184
|
+
return JSON.stringify(value) ?? "undefined";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function omitUndefinedWorkflowValues(value: unknown, seen = new Set<object>()): unknown {
|
|
188
|
+
if (value === null || typeof value !== "object") return value;
|
|
189
|
+
if (seen.has(value)) return value;
|
|
190
|
+
seen.add(value);
|
|
191
|
+
const normalized = Array.isArray(value)
|
|
192
|
+
? value.map((entry) => (entry === undefined ? null : omitUndefinedWorkflowValues(entry, seen)))
|
|
193
|
+
: isPlainJsonObject(value)
|
|
194
|
+
? Object.fromEntries(
|
|
195
|
+
Object.entries(value).flatMap(([key, entry]) =>
|
|
196
|
+
entry === undefined ? [] : [[key, omitUndefinedWorkflowValues(entry, seen)]],
|
|
197
|
+
),
|
|
198
|
+
)
|
|
199
|
+
: value;
|
|
200
|
+
seen.delete(value);
|
|
201
|
+
return normalized;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function omitNonJsonWorkflowResultMetadata(value: unknown): unknown {
|
|
205
|
+
const normalized = omitUndefinedWorkflowValues(value);
|
|
206
|
+
if (!isPlainJsonObject(normalized) || !Object.hasOwn(normalized, "results")) return normalized;
|
|
207
|
+
try {
|
|
208
|
+
assertWorkflowJsonValue(normalized.results, "runs.run result.results");
|
|
209
|
+
return normalized;
|
|
210
|
+
} catch {
|
|
211
|
+
const { results: _results, ...safeResult } = normalized;
|
|
212
|
+
return safeResult;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
217
|
+
|
|
218
|
+
function validateKey(value: unknown, owner = "runs.run"): string {
|
|
219
|
+
if (typeof value !== "string" || !KEY_PATTERN.test(value)) {
|
|
220
|
+
throw new Error(`${owner} key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.`);
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function workflowStringMetadata(params: Record<string, unknown>): Pick<WorkflowScriptTraceEntry, "phase" | "label" | "agent"> {
|
|
226
|
+
return {
|
|
227
|
+
...(typeof params.phase === "string" && params.phase.trim() ? { phase: params.phase.trim() } : {}),
|
|
228
|
+
...(typeof params.label === "string" && params.label.trim() ? { label: params.label.trim() } : {}),
|
|
229
|
+
...(typeof params.agent === "string" && params.agent.trim() ? { agent: params.agent.trim() } : {}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Resolve acorn robustly (bare specifier, then package.json main). */
|
|
234
|
+
function resolveWorkflowParserEntry(): string {
|
|
235
|
+
try {
|
|
236
|
+
return requireFromPackage.resolve("acorn");
|
|
237
|
+
} catch (primaryError) {
|
|
238
|
+
try {
|
|
239
|
+
const manifestPath = requireFromPackage.resolve("acorn/package.json");
|
|
240
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as { main?: unknown };
|
|
241
|
+
const entry = typeof manifest.main === "string" && manifest.main ? manifest.main : "./dist/acorn.js";
|
|
242
|
+
return resolvePath(dirname(manifestPath), entry);
|
|
243
|
+
} catch {
|
|
244
|
+
throw primaryError;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Worker source: compiled .js in published installs, .ts under jiti/tsx (transpiled inline). */
|
|
250
|
+
function loadWorkerSource(): string {
|
|
251
|
+
const base = resolvePath(dirname(fileURLToPath(import.meta.url)), "workflow-worker");
|
|
252
|
+
for (const candidate of [`${base}.js`, `${base}.ts`]) {
|
|
253
|
+
try {
|
|
254
|
+
return readFileSync(candidate, "utf8");
|
|
255
|
+
} catch {
|
|
256
|
+
// try next
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
throw new Error("workflow-worker source not found (expected workflow-worker.js or .ts)");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export async function runWorkflowScript(options: RunWorkflowScriptOptions): Promise<WorkflowScriptResult> {
|
|
263
|
+
if (!options.script.trim()) throw new Error("workflowScript must not be empty.");
|
|
264
|
+
if (options.timeoutMs !== undefined && (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1)) {
|
|
265
|
+
throw new Error("workflow script timeout must be a positive integer.");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
let acornPath: string;
|
|
269
|
+
try {
|
|
270
|
+
acornPath = resolveWorkflowParserEntry();
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
"Workflow parser dependency 'acorn' is unavailable from @pi-unipi/subagents. Reinstall dependencies before launching workflowScript.",
|
|
274
|
+
{ cause: error },
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const worker = new Worker(loadWorkerSource(), { eval: true, workerData: { acornPath } });
|
|
279
|
+
const emits: unknown[] = [];
|
|
280
|
+
const consoleEntries: WorkflowScriptResult["console"] = [];
|
|
281
|
+
const trace: WorkflowScriptTraceEntry[] = [];
|
|
282
|
+
const children = new Map<string, WorkflowScriptChildResult>();
|
|
283
|
+
const childOrder: string[] = [];
|
|
284
|
+
const launches = new Map<string, { fingerprint: string; promise: Promise<WorkflowScriptChildResult>; observed: boolean }>();
|
|
285
|
+
const steers = new Map<number, { key: string; promise: Promise<WorkflowSteerResult>; observed: boolean }>();
|
|
286
|
+
const stoppedLaunches = new Set<string>();
|
|
287
|
+
const batchAdmissions = new Map<string, Promise<void>>();
|
|
288
|
+
const childController = new AbortController();
|
|
289
|
+
let settled = false;
|
|
290
|
+
let finishing = false;
|
|
291
|
+
|
|
292
|
+
const partial = (): Omit<WorkflowScriptResult, "value"> => ({
|
|
293
|
+
emits,
|
|
294
|
+
console: consoleEntries,
|
|
295
|
+
trace,
|
|
296
|
+
children: childOrder.flatMap((key) => {
|
|
297
|
+
const child = children.get(key);
|
|
298
|
+
return child ? [child] : [];
|
|
299
|
+
}),
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const traceChanged = () => {
|
|
303
|
+
try {
|
|
304
|
+
options.onTrace?.([...trace]);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error("Workflow onTrace callback failed:", error);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
return await new Promise<WorkflowScriptResult>((resolve, reject) => {
|
|
311
|
+
const finish = (outcome: { value: unknown } | { error: Error }) => {
|
|
312
|
+
if (settled || finishing) return;
|
|
313
|
+
finishing = true;
|
|
314
|
+
childController.abort("error" in outcome ? outcome.error : new Error("Workflow script completed."));
|
|
315
|
+
void Promise.allSettled([...steers.values()].map(({ promise }) => promise)).then(() => {
|
|
316
|
+
if (settled) return;
|
|
317
|
+
settled = true;
|
|
318
|
+
if (timer) clearTimeout(timer);
|
|
319
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
320
|
+
void worker.terminate();
|
|
321
|
+
const unobservedKeys =
|
|
322
|
+
"value" in outcome ? [...launches].filter(([, launch]) => !launch.observed).map(([key]) => key) : [];
|
|
323
|
+
const completionError =
|
|
324
|
+
unobservedKeys.length > 0
|
|
325
|
+
? new Error(
|
|
326
|
+
`workflowScript completed with unawaited runs.run launch(es): ${unobservedKeys.map((key) => `'${key}'`).join(", ")}. For ordinary parallel fanout use await runs.all([{key, agent, task}, ...]); do not read .output from unawaited launches.`,
|
|
327
|
+
)
|
|
328
|
+
: "value" in outcome
|
|
329
|
+
? (() => {
|
|
330
|
+
const unobservedSteers = [...steers.values()].filter((steer) => !steer.observed).map((steer) => steer.key);
|
|
331
|
+
return unobservedSteers.length > 0
|
|
332
|
+
? new Error(`workflowScript completed with unawaited runs.steer call(s): ${unobservedSteers.map((key) => `'${key}'`).join(", ")}. Await or return each call.`)
|
|
333
|
+
: undefined;
|
|
334
|
+
})()
|
|
335
|
+
: undefined;
|
|
336
|
+
if ("error" in outcome) reject(new WorkflowScriptError(outcome.error.message, partial()));
|
|
337
|
+
else if (completionError) reject(new WorkflowScriptError(completionError.message, partial()));
|
|
338
|
+
else resolve({ value: outcome.value, ...partial() });
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
const onAbort = () => {
|
|
342
|
+
const signalReason = options.signal?.reason;
|
|
343
|
+
const error =
|
|
344
|
+
signalReason instanceof Error
|
|
345
|
+
? signalReason
|
|
346
|
+
: typeof signalReason === "string"
|
|
347
|
+
? new Error(signalReason)
|
|
348
|
+
: new Error("Workflow script aborted.");
|
|
349
|
+
for (const key of launches.keys()) {
|
|
350
|
+
if (children.has(key)) continue;
|
|
351
|
+
stoppedLaunches.add(key);
|
|
352
|
+
const started = trace.findLast(
|
|
353
|
+
(entry) => entry.operation === "run" && entry.key === key && entry.state === "started",
|
|
354
|
+
);
|
|
355
|
+
trace.push({
|
|
356
|
+
operation: "run",
|
|
357
|
+
key,
|
|
358
|
+
state: "stopped",
|
|
359
|
+
...(started?.agent ? { agent: started.agent } : {}),
|
|
360
|
+
...(started?.phase ? { phase: started.phase } : {}),
|
|
361
|
+
...(started?.label ? { label: started.label } : {}),
|
|
362
|
+
error: error.message,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
traceChanged();
|
|
366
|
+
finish({ error });
|
|
367
|
+
};
|
|
368
|
+
const timer =
|
|
369
|
+
options.timeoutMs === undefined
|
|
370
|
+
? undefined
|
|
371
|
+
: setTimeout(() => finish({ error: new Error(`Workflow script timed out after ${options.timeoutMs}ms.`) }), options.timeoutMs);
|
|
372
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
373
|
+
if (options.signal?.aborted) return onAbort();
|
|
374
|
+
|
|
375
|
+
worker.on("error", (error) =>
|
|
376
|
+
finish({ error: new Error(`Workflow worker failed: ${error instanceof Error ? error.message : String(error)}`) }),
|
|
377
|
+
);
|
|
378
|
+
worker.on("exit", (code) => {
|
|
379
|
+
if (!settled && code !== 0) finish({ error: new Error(`Workflow worker exited with code ${code}.`) });
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
worker.on("message", (msg: Record<string, unknown>) => {
|
|
384
|
+
if (settled) return;
|
|
385
|
+
if (msg.type === "emit") {
|
|
386
|
+
try {
|
|
387
|
+
assertWorkflowJsonValue(msg.value, "emit");
|
|
388
|
+
} catch (error) {
|
|
389
|
+
finish({ error: new Error(`Workflow emit could not be persisted: ${error instanceof Error ? error.message : String(error)}`) });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
emits.push(msg.value);
|
|
393
|
+
try {
|
|
394
|
+
options.onEmit?.([...emits]);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
emits.pop();
|
|
397
|
+
finish({ error: new Error(`Workflow emit could not be persisted: ${error instanceof Error ? error.message : String(error)}`) });
|
|
398
|
+
}
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (msg.type === "console") {
|
|
402
|
+
const level = msg.level;
|
|
403
|
+
if ((level === "log" || level === "info" || level === "warn" || level === "error") && typeof msg.text === "string") {
|
|
404
|
+
consoleEntries.push({ level, text: msg.text });
|
|
405
|
+
}
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (msg.type === "complete") {
|
|
409
|
+
try {
|
|
410
|
+
assertWorkflowJsonValue(msg.value, "return");
|
|
411
|
+
} catch (error) {
|
|
412
|
+
return finish({ error: new Error(`Workflow return could not be persisted: ${error instanceof Error ? error.message : String(error)}`) });
|
|
413
|
+
}
|
|
414
|
+
return finish({ value: msg.value });
|
|
415
|
+
}
|
|
416
|
+
if (msg.type === "error") {
|
|
417
|
+
return finish({ error: new Error(typeof msg.error === "string" ? msg.error : "Workflow script failed.") });
|
|
418
|
+
}
|
|
419
|
+
if (msg.type === "callObserved" && typeof msg.callId === "number") {
|
|
420
|
+
if (msg.operation === "steer") {
|
|
421
|
+
const steer = steers.get(msg.callId);
|
|
422
|
+
if (steer) steer.observed = true;
|
|
423
|
+
}
|
|
424
|
+
// run/all observations are tracked via the launches map by key.
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (msg.type !== "call" || typeof msg.callId !== "number" || typeof msg.method !== "string" || !isRecord(msg.args)) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const respond = (promise: Promise<unknown>, responsePath?: string) => {
|
|
432
|
+
void promise.then(
|
|
433
|
+
(value) => {
|
|
434
|
+
if (settled) return;
|
|
435
|
+
const normalized = responsePath ? omitNonJsonWorkflowResultMetadata(value) : omitUndefinedWorkflowValues(value);
|
|
436
|
+
if (!responsePath) {
|
|
437
|
+
worker.postMessage({ type: "response", callId: msg.callId, ok: true, value: normalized });
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
assertWorkflowJsonValue(normalized, responsePath);
|
|
442
|
+
worker.postMessage({ type: "response", callId: msg.callId, ok: true, value: normalized });
|
|
443
|
+
} catch (error) {
|
|
444
|
+
worker.postMessage({
|
|
445
|
+
type: "response",
|
|
446
|
+
callId: msg.callId,
|
|
447
|
+
ok: false,
|
|
448
|
+
error: `${responsePath} must contain only JSON data before it can be returned from workflowScript. Return a plain projection such as { runId, ok, output }. ${error instanceof Error ? error.message : String(error)}`,
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
(error: unknown) => {
|
|
453
|
+
if (!settled) {
|
|
454
|
+
worker.postMessage({
|
|
455
|
+
type: "response",
|
|
456
|
+
callId: msg.callId,
|
|
457
|
+
ok: false,
|
|
458
|
+
error: error instanceof Error ? error.message : String(error),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
if (msg.method === "state.get" || msg.method === "state.set") {
|
|
466
|
+
if (!options.state) return respond(Promise.reject(new Error("Workflow state is unavailable without a mission.")));
|
|
467
|
+
let key: string;
|
|
468
|
+
try {
|
|
469
|
+
key = validateKey(msg.args.key, "state");
|
|
470
|
+
} catch (error) {
|
|
471
|
+
return respond(Promise.reject(error));
|
|
472
|
+
}
|
|
473
|
+
if (msg.method === "state.get") return respond(Promise.resolve().then(() => options.state!.get(key)));
|
|
474
|
+
const value = msg.args.value;
|
|
475
|
+
try {
|
|
476
|
+
assertWorkflowJsonValue(value, `state.set('${key}') value`);
|
|
477
|
+
} catch (error) {
|
|
478
|
+
return respond(Promise.reject(error));
|
|
479
|
+
}
|
|
480
|
+
return respond(Promise.resolve().then(() => options.state!.set(key, value)));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (msg.method === "status") {
|
|
484
|
+
const keyOrRunId = msg.args.keyOrRunId;
|
|
485
|
+
if (typeof keyOrRunId !== "string" || !keyOrRunId.trim()) {
|
|
486
|
+
return respond(Promise.reject(new Error("runs.status(keyOrRunId) requires a non-empty string.")));
|
|
487
|
+
}
|
|
488
|
+
const known = children.get(keyOrRunId);
|
|
489
|
+
const target = known?.runId ?? keyOrRunId;
|
|
490
|
+
trace.push({ operation: "status", key: keyOrRunId, state: "started", ...(known?.runId ? { runId: known.runId } : {}) });
|
|
491
|
+
traceChanged();
|
|
492
|
+
if (settled || finishing) return;
|
|
493
|
+
respond(
|
|
494
|
+
options.status(target, childController.signal).then((result) => {
|
|
495
|
+
if (settled || finishing) return result;
|
|
496
|
+
trace.push({
|
|
497
|
+
operation: "status",
|
|
498
|
+
key: keyOrRunId,
|
|
499
|
+
state: result.ok ? "completed" : "failed",
|
|
500
|
+
...(result.runId ? { runId: result.runId } : {}),
|
|
501
|
+
...(!result.ok ? { error: result.output } : {}),
|
|
502
|
+
});
|
|
503
|
+
traceChanged();
|
|
504
|
+
if (!result.ok) throw new Error(`Status '${keyOrRunId}' failed: ${result.output}`);
|
|
505
|
+
return result;
|
|
506
|
+
}),
|
|
507
|
+
);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (msg.method === "steer") {
|
|
512
|
+
let key: string;
|
|
513
|
+
try {
|
|
514
|
+
key = validateKey(msg.args.key, "runs.steer");
|
|
515
|
+
} catch (error) {
|
|
516
|
+
return respond(Promise.reject(error));
|
|
517
|
+
}
|
|
518
|
+
const steerMessage = msg.args.message;
|
|
519
|
+
if (typeof steerMessage !== "string" || !steerMessage.trim()) {
|
|
520
|
+
return respond(Promise.reject(new Error(`runs.steer('${key}') requires a non-empty message.`)));
|
|
521
|
+
}
|
|
522
|
+
const steerOptions = isRecord(msg.args.options) ? (msg.args.options as { mode?: string; index?: number; ackTimeoutMs?: number }) : {};
|
|
523
|
+
const startedAt = Date.now();
|
|
524
|
+
trace.push({ operation: "steer", key, state: "started" });
|
|
525
|
+
traceChanged();
|
|
526
|
+
const promise = Promise.resolve()
|
|
527
|
+
.then(() => {
|
|
528
|
+
if (!launches.has(key)) throw new Error(`runs.steer('${key}') requires a prior runs.run/runs.all launch with that key.`);
|
|
529
|
+
if (!options.steer) throw new Error("Workflow steering is unavailable in this host.");
|
|
530
|
+
return options.steer(key, steerMessage.trim(), steerOptions, childController.signal);
|
|
531
|
+
})
|
|
532
|
+
.then(
|
|
533
|
+
(receipt) => {
|
|
534
|
+
trace.push({ operation: "steer", key, state: receipt.state, durationMs: Date.now() - startedAt, ...(receipt.error ? { error: receipt.error } : {}) });
|
|
535
|
+
traceChanged();
|
|
536
|
+
return receipt;
|
|
537
|
+
},
|
|
538
|
+
(error: unknown) => {
|
|
539
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
540
|
+
trace.push({ operation: "steer", key, state: "failed", durationMs: Date.now() - startedAt, error: text });
|
|
541
|
+
traceChanged();
|
|
542
|
+
throw error;
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
steers.set(msg.callId, { key, promise, observed: false });
|
|
546
|
+
respond(promise);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (msg.method === "all") {
|
|
551
|
+
// runs.all(...) is itself the observation: every child is awaited by the batch.
|
|
552
|
+
// Batch launch: runs.all([...]) — admits the whole group atomically.
|
|
553
|
+
const calls = Array.isArray(msg.args.calls) ? msg.args.calls : [];
|
|
554
|
+
const valid = calls.filter(
|
|
555
|
+
(call): call is { key: string; params: Record<string, unknown> } =>
|
|
556
|
+
isRecord(call) && typeof call.key === "string" && isRecord(call.params),
|
|
557
|
+
);
|
|
558
|
+
const admission = Promise.resolve().then(() => {
|
|
559
|
+
if (settled || finishing) return;
|
|
560
|
+
return options.admit?.(valid);
|
|
561
|
+
}).catch((error: unknown) => {
|
|
562
|
+
// Admission failures (e.g. fanout budget) reject every child in the
|
|
563
|
+
// batch; runs.all collects them as ordinary failures (reference
|
|
564
|
+
// semantics: no partial starts, siblings report the rejection).
|
|
565
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
566
|
+
for (const { key } of valid) {
|
|
567
|
+
const failure: WorkflowScriptChildResult = { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
568
|
+
children.set(key, failure);
|
|
569
|
+
if (!childOrder.includes(key)) childOrder.push(key);
|
|
570
|
+
}
|
|
571
|
+
throw error;
|
|
572
|
+
});
|
|
573
|
+
const promises = valid.map(({ key, params }) =>
|
|
574
|
+
admission.then(async () => {
|
|
575
|
+
if (settled || finishing || stoppedLaunches.has(key)) {
|
|
576
|
+
const reason = childController.signal.reason;
|
|
577
|
+
const text = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.";
|
|
578
|
+
return { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
579
|
+
}
|
|
580
|
+
const startedAt = Date.now();
|
|
581
|
+
return options.launch(key, { ...params, async: params.async ?? false }, childController.signal, { admitted: true }).then(
|
|
582
|
+
(result) => {
|
|
583
|
+
const normalized = !result.ok && !result.error ? { ...result, error: result.output } : result;
|
|
584
|
+
children.set(key, normalized);
|
|
585
|
+
childOrder.push(key);
|
|
586
|
+
trace.push({
|
|
587
|
+
operation: "run",
|
|
588
|
+
key,
|
|
589
|
+
state: normalized.ok ? "completed" : "failed",
|
|
590
|
+
durationMs: Date.now() - startedAt,
|
|
591
|
+
...workflowStringMetadata(params),
|
|
592
|
+
...(normalized.agent ? { agent: normalized.agent } : {}),
|
|
593
|
+
...(normalized.runId ? { runId: normalized.runId } : {}),
|
|
594
|
+
...(!normalized.ok ? { error: normalized.error ?? normalized.output } : {}),
|
|
595
|
+
});
|
|
596
|
+
traceChanged();
|
|
597
|
+
return normalized;
|
|
598
|
+
},
|
|
599
|
+
(error: unknown) => {
|
|
600
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
601
|
+
const failure: WorkflowScriptChildResult = { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
602
|
+
children.set(key, failure);
|
|
603
|
+
childOrder.push(key);
|
|
604
|
+
trace.push({ operation: "run", key, state: "failed", durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), error: text });
|
|
605
|
+
traceChanged();
|
|
606
|
+
return failure;
|
|
607
|
+
},
|
|
608
|
+
);
|
|
609
|
+
}, (error: unknown) => {
|
|
610
|
+
// Admission rejection already recorded the failure per child; map
|
|
611
|
+
// this arm to the same failure so Promise.all collects it.
|
|
612
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
613
|
+
return { key, ok: false, output: text, error: text, artifactPaths: [] } satisfies WorkflowScriptChildResult;
|
|
614
|
+
}),
|
|
615
|
+
);
|
|
616
|
+
// Mark all keys observed (runs.all is itself the observation).
|
|
617
|
+
for (const { key } of valid) {
|
|
618
|
+
const existing = launches.get(key);
|
|
619
|
+
if (existing) existing.observed = true;
|
|
620
|
+
}
|
|
621
|
+
const batchPromise = Promise.all(promises).then((results) => {
|
|
622
|
+
for (const result of results) {
|
|
623
|
+
const entry = launches.get(result.key);
|
|
624
|
+
if (entry) entry.observed = true;
|
|
625
|
+
}
|
|
626
|
+
return results;
|
|
627
|
+
});
|
|
628
|
+
for (const { key, params } of valid) {
|
|
629
|
+
const fingerprint = stableJson(params);
|
|
630
|
+
launches.set(key, { fingerprint, promise: batchPromise.then((rs) => rs.find((r) => r.key === key)!) , observed: true });
|
|
631
|
+
}
|
|
632
|
+
respond(batchPromise, "runs.all(...) results");
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (msg.method !== "run") return respond(Promise.reject(new Error(`Unknown runs API method '${msg.method}'.`)));
|
|
637
|
+
|
|
638
|
+
let key: string;
|
|
639
|
+
try {
|
|
640
|
+
key = validateKey(msg.args.key);
|
|
641
|
+
} catch (error) {
|
|
642
|
+
return respond(Promise.reject(error));
|
|
643
|
+
}
|
|
644
|
+
const params = msg.args.params;
|
|
645
|
+
if (!isRecord(params)) return respond(Promise.reject(new Error(`runs.run('${key}', params) requires a params object.`)));
|
|
646
|
+
if (params.action !== undefined) return respond(Promise.reject(new Error(`runs.run('${key}') accepts execution params only; management action is not allowed.`)));
|
|
647
|
+
if (params.workflowScript !== undefined) return respond(Promise.reject(new Error(`runs.run('${key}') cannot start a nested workflow script.`)));
|
|
648
|
+
if (params.tasks !== undefined || params.chain !== undefined || params.parallel !== undefined || params.concurrency !== undefined) {
|
|
649
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') accepts one child via { agent, task }; use runs.all(...) and JavaScript control flow for orchestration.`)));
|
|
650
|
+
}
|
|
651
|
+
if (params.resume !== undefined && params.agent !== undefined) {
|
|
652
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') resume and agent are mutually exclusive.`)));
|
|
653
|
+
}
|
|
654
|
+
if (typeof params.resume === "string" && !params.resume.trim()) {
|
|
655
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') resume must be a non-empty retained run id.`)));
|
|
656
|
+
}
|
|
657
|
+
if (params.resume !== undefined && (typeof params.task !== "string" || !params.task.trim())) {
|
|
658
|
+
return respond(Promise.reject(new Error(`runs.run('${key}') resume requires a non-empty task follow-up.`)));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const fingerprint = stableJson(params);
|
|
662
|
+
const existing = launches.get(key);
|
|
663
|
+
if (existing) {
|
|
664
|
+
if (existing.fingerprint !== fingerprint) {
|
|
665
|
+
return respond(Promise.reject(new Error(`Duplicate workflow key '${key}' used with incompatible launch params.`)));
|
|
666
|
+
}
|
|
667
|
+
existing.observed = true;
|
|
668
|
+
trace.push({ operation: "run", key, state: "reused", ...workflowStringMetadata(params) });
|
|
669
|
+
traceChanged();
|
|
670
|
+
return respond(
|
|
671
|
+
existing.promise.then((result) => {
|
|
672
|
+
if (result.ok) return result;
|
|
673
|
+
throw new Error(`Run '${key}' failed: ${result.error ?? result.output}`);
|
|
674
|
+
}),
|
|
675
|
+
`runs.run('${key}') result`,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const startedAt = Date.now();
|
|
680
|
+
const admission = Promise.resolve().then(() => {
|
|
681
|
+
if (settled || finishing) return;
|
|
682
|
+
return options.admit?.([{ key, params }]);
|
|
683
|
+
});
|
|
684
|
+
const promise = admission
|
|
685
|
+
.then(async () => {
|
|
686
|
+
if (settled || finishing || stoppedLaunches.has(key)) {
|
|
687
|
+
const reason = childController.signal.reason;
|
|
688
|
+
const text = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Workflow script aborted.";
|
|
689
|
+
return { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
690
|
+
}
|
|
691
|
+
return options.launch(key, { ...params, async: params.async ?? false }, childController.signal, { admitted: true });
|
|
692
|
+
})
|
|
693
|
+
.then(
|
|
694
|
+
(result) => {
|
|
695
|
+
const normalized = !result.ok && !result.error ? { ...result, error: result.output } : result;
|
|
696
|
+
if (stoppedLaunches.has(key)) return normalized;
|
|
697
|
+
children.set(key, normalized);
|
|
698
|
+
const state = normalized.ok ? "completed" : "failed";
|
|
699
|
+
trace.push({
|
|
700
|
+
operation: "run",
|
|
701
|
+
key,
|
|
702
|
+
state,
|
|
703
|
+
durationMs: Date.now() - startedAt,
|
|
704
|
+
...workflowStringMetadata(params),
|
|
705
|
+
...(normalized.agent ? { agent: normalized.agent } : {}),
|
|
706
|
+
...(normalized.runId ? { runId: normalized.runId } : {}),
|
|
707
|
+
...(!normalized.ok ? { error: normalized.error ?? normalized.output } : {}),
|
|
708
|
+
});
|
|
709
|
+
traceChanged();
|
|
710
|
+
return normalized;
|
|
711
|
+
},
|
|
712
|
+
(error: unknown) => {
|
|
713
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
714
|
+
const failure: WorkflowScriptChildResult = { key, ok: false, output: text, error: text, artifactPaths: [] };
|
|
715
|
+
if (stoppedLaunches.has(key)) return failure;
|
|
716
|
+
children.set(key, failure);
|
|
717
|
+
trace.push({ operation: "run", key, state: "failed", durationMs: Date.now() - startedAt, ...workflowStringMetadata(params), error: text });
|
|
718
|
+
traceChanged();
|
|
719
|
+
return failure;
|
|
720
|
+
},
|
|
721
|
+
);
|
|
722
|
+
launches.set(key, { fingerprint, promise, observed: true });
|
|
723
|
+
if (!childOrder.includes(key)) childOrder.push(key);
|
|
724
|
+
trace.push({ operation: "run", key, state: "started", ...workflowStringMetadata(params) });
|
|
725
|
+
traceChanged();
|
|
726
|
+
respond(
|
|
727
|
+
promise.then((result) => {
|
|
728
|
+
if (result.ok) return result;
|
|
729
|
+
throw new Error(`Run '${key}' failed: ${result.error ?? result.output}`);
|
|
730
|
+
}),
|
|
731
|
+
`runs.run('${key}') result`,
|
|
732
|
+
);
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
worker.postMessage({ type: "start", script: options.script, stateEnabled: options.state !== undefined });
|
|
736
|
+
});
|
|
737
|
+
}
|