@smithers-orchestrator/driver 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +80 -0
  3. package/src/ContinueAsNewHandler.ts +7 -0
  4. package/src/CreateWorkflowSession.ts +5 -0
  5. package/src/CreateWorkflowSessionOptions.ts +9 -0
  6. package/src/OutputAccessor.ts +20 -0
  7. package/src/OutputKey.ts +1 -0
  8. package/src/OutputSnapshot.ts +3 -0
  9. package/src/RunAuthContext.ts +6 -0
  10. package/src/RunOptions.ts +42 -0
  11. package/src/RunResult.ts +9 -0
  12. package/src/RunStatus.ts +9 -0
  13. package/src/SafeParser.ts +5 -0
  14. package/src/SchedulerWaitHandler.ts +6 -0
  15. package/src/SmithersCtx.js +195 -0
  16. package/src/SmithersCtxOptions.ts +14 -0
  17. package/src/SmithersRuntimeConfig.ts +3 -0
  18. package/src/SmithersTaskRuntime.ts +22 -0
  19. package/src/SpawnCaptureOptions.ts +12 -0
  20. package/src/SpawnCaptureResult.ts +5 -0
  21. package/src/TaskCompletedEvent.ts +5 -0
  22. package/src/TaskExecutor.ts +7 -0
  23. package/src/TaskExecutorContext.ts +7 -0
  24. package/src/TaskFailedEvent.ts +5 -0
  25. package/src/WaitHandler.ts +8 -0
  26. package/src/WorkflowDefinition.ts +16 -0
  27. package/src/WorkflowDriver.js +519 -0
  28. package/src/WorkflowDriverOptions.ts +27 -0
  29. package/src/WorkflowElement.ts +5 -0
  30. package/src/WorkflowGraphRenderer.ts +9 -0
  31. package/src/WorkflowRuntime.ts +3 -0
  32. package/src/WorkflowSession.ts +11 -0
  33. package/src/buildCurrentScopes.js +34 -0
  34. package/src/child-process.js +222 -0
  35. package/src/defaultTaskExecutor.js +28 -0
  36. package/src/filterRowsByNodeId.js +19 -0
  37. package/src/ignoreSyncError.js +16 -0
  38. package/src/index.d.ts +411 -0
  39. package/src/index.js +31 -0
  40. package/src/interop.js +1 -0
  41. package/src/normalizeInputRow.js +27 -0
  42. package/src/task-runtime.js +30 -0
  43. package/src/withAbort.js +43 -0
  44. package/src/withLogicalIterationShortcuts.js +46 -0
  45. package/src/workflow-types.ts +20 -0
@@ -0,0 +1,222 @@
1
+ import { spawn } from "node:child_process";
2
+ import { Effect, Metric } from "effect";
3
+ import { ignoreSyncError } from "./interop.js";
4
+ import { toSmithersError } from "@smithers-orchestrator/errors/toSmithersError";
5
+ import { SmithersError } from "@smithers-orchestrator/errors/SmithersError";
6
+ import { toolOutputTruncatedTotal } from "@smithers-orchestrator/observability/metrics";
7
+ import { logDebug, logWarning } from "@smithers-orchestrator/observability/logging";
8
+ /** @typedef {import("./SpawnCaptureOptions.ts").SpawnCaptureOptions} SpawnCaptureOptions */
9
+ /** @typedef {import("./SpawnCaptureResult.ts").SpawnCaptureResult} SpawnCaptureResult */
10
+
11
+ /**
12
+ * @param {string} text
13
+ * @param {number} maxBytes
14
+ * @returns {string}
15
+ */
16
+ function truncateToBytes(text, maxBytes) {
17
+ const buf = Buffer.from(text, "utf8");
18
+ if (buf.length <= maxBytes)
19
+ return text;
20
+ return buf.subarray(0, maxBytes).toString("utf8");
21
+ }
22
+ /**
23
+ * @param {string} command
24
+ * @param {string[]} args
25
+ * @param {SpawnCaptureOptions} options
26
+ * @returns {Effect.Effect<SpawnCaptureResult, SmithersError>}
27
+ */
28
+ export function spawnCaptureEffect(command, args, options) {
29
+ const { cwd, env, input, signal, timeoutMs, idleTimeoutMs, maxOutputBytes = 200_000, detached = false, onStdout, onStderr, } = options;
30
+ const errorDetails = {
31
+ command,
32
+ args,
33
+ cwd,
34
+ timeoutMs,
35
+ idleTimeoutMs,
36
+ };
37
+ const logAnnotations = {
38
+ command,
39
+ args: args.join(" "),
40
+ cwd,
41
+ timeoutMs: timeoutMs ?? null,
42
+ idleTimeoutMs: idleTimeoutMs ?? null,
43
+ };
44
+ const span = `process:${command}`;
45
+ return (Effect.async((resume) => {
46
+ let stdout = "";
47
+ let stderr = "";
48
+ let settled = false;
49
+ let stdoutTruncated = false;
50
+ let stderrTruncated = false;
51
+ logDebug("spawning child process", logAnnotations, span);
52
+ const child = spawn(command, args, {
53
+ cwd,
54
+ env,
55
+ detached,
56
+ stdio: ["pipe", "pipe", "pipe"],
57
+ });
58
+ /**
59
+ * @param {string} reason
60
+ * @param {"PROCESS_ABORTED" | "PROCESS_TIMEOUT" | "PROCESS_IDLE_TIMEOUT"} code
61
+ */
62
+ const kill = (reason, code) => {
63
+ logWarning("child process interrupted", {
64
+ ...logAnnotations,
65
+ reason,
66
+ errorCode: code,
67
+ }, span);
68
+ try {
69
+ if (detached && child.pid) {
70
+ process.kill(-child.pid, "SIGKILL");
71
+ }
72
+ else {
73
+ child.kill("SIGKILL");
74
+ }
75
+ }
76
+ catch {
77
+ try {
78
+ child.kill("SIGKILL");
79
+ }
80
+ catch {
81
+ // ignore
82
+ }
83
+ }
84
+ if (!settled) {
85
+ settled = true;
86
+ resume(Effect.fail(new SmithersError(code, reason, errorDetails)));
87
+ }
88
+ };
89
+ let totalTimer;
90
+ let idleTimer;
91
+ const resetIdle = () => {
92
+ if (idleTimer)
93
+ clearTimeout(idleTimer);
94
+ if (idleTimeoutMs) {
95
+ idleTimer = setTimeout(() => {
96
+ kill(`CLI idle timed out after ${idleTimeoutMs}ms`, "PROCESS_IDLE_TIMEOUT");
97
+ }, idleTimeoutMs);
98
+ }
99
+ };
100
+ if (timeoutMs) {
101
+ totalTimer = setTimeout(() => {
102
+ kill(`CLI timed out after ${timeoutMs}ms`, "PROCESS_TIMEOUT");
103
+ }, timeoutMs);
104
+ }
105
+ resetIdle();
106
+ /**
107
+ * @param {SpawnCaptureResult} result
108
+ */
109
+ const finalize = (result) => {
110
+ if (settled)
111
+ return;
112
+ settled = true;
113
+ if (totalTimer)
114
+ clearTimeout(totalTimer);
115
+ if (idleTimer)
116
+ clearTimeout(idleTimer);
117
+ logDebug("child process completed", {
118
+ ...logAnnotations,
119
+ exitCode: result.exitCode,
120
+ stderrBytes: Buffer.byteLength(result.stderr, "utf8"),
121
+ stdoutBytes: Buffer.byteLength(result.stdout, "utf8"),
122
+ }, span);
123
+ let truncationCount = 0;
124
+ if (stdoutTruncated)
125
+ truncationCount++;
126
+ if (stderrTruncated)
127
+ truncationCount++;
128
+ resume(Effect.succeed({ result, truncationCount }));
129
+ };
130
+ if (signal) {
131
+ if (signal.aborted) {
132
+ kill("CLI aborted", "PROCESS_ABORTED");
133
+ }
134
+ else {
135
+ signal.addEventListener("abort", () => kill("CLI aborted", "PROCESS_ABORTED"), {
136
+ once: true,
137
+ });
138
+ }
139
+ }
140
+ child.stdout?.on("data", (chunk) => {
141
+ resetIdle();
142
+ const text = chunk.toString("utf8");
143
+ const nextStdout = stdout + text;
144
+ if (!stdoutTruncated && Buffer.byteLength(nextStdout, "utf8") > maxOutputBytes) {
145
+ stdoutTruncated = true;
146
+ logWarning("child process stdout truncated", {
147
+ ...logAnnotations,
148
+ maxOutputBytes,
149
+ stream: "stdout",
150
+ }, span);
151
+ }
152
+ stdout = truncateToBytes(nextStdout, maxOutputBytes);
153
+ onStdout?.(text);
154
+ });
155
+ child.stderr?.on("data", (chunk) => {
156
+ resetIdle();
157
+ const text = chunk.toString("utf8");
158
+ const nextStderr = stderr + text;
159
+ if (!stderrTruncated && Buffer.byteLength(nextStderr, "utf8") > maxOutputBytes) {
160
+ stderrTruncated = true;
161
+ logWarning("child process stderr truncated", {
162
+ ...logAnnotations,
163
+ maxOutputBytes,
164
+ stream: "stderr",
165
+ }, span);
166
+ }
167
+ stderr = truncateToBytes(nextStderr, maxOutputBytes);
168
+ onStderr?.(text);
169
+ });
170
+ child.on("error", (error) => {
171
+ if (totalTimer)
172
+ clearTimeout(totalTimer);
173
+ if (idleTimer)
174
+ clearTimeout(idleTimer);
175
+ if (!settled) {
176
+ settled = true;
177
+ const smithersError = toSmithersError(error, `spawn ${command}`, {
178
+ code: "PROCESS_SPAWN_FAILED",
179
+ details: errorDetails,
180
+ });
181
+ logWarning("failed to spawn child process", {
182
+ ...logAnnotations,
183
+ error: smithersError.message,
184
+ }, span);
185
+ resume(Effect.fail(smithersError));
186
+ }
187
+ });
188
+ child.on("close", (code) => {
189
+ finalize({ stdout, stderr, exitCode: code ?? null });
190
+ });
191
+ if (input) {
192
+ child.stdin?.write(input);
193
+ }
194
+ child.stdin?.end();
195
+ return Effect.gen(function* () {
196
+ if (totalTimer)
197
+ clearTimeout(totalTimer);
198
+ if (idleTimer)
199
+ clearTimeout(idleTimer);
200
+ if (!settled) {
201
+ yield* Effect.try({
202
+ try: () => {
203
+ if (detached && child.pid) {
204
+ process.kill(-child.pid, "SIGKILL");
205
+ }
206
+ else {
207
+ child.kill("SIGKILL");
208
+ }
209
+ },
210
+ catch: (cause) => toSmithersError(cause, "kill process group", {
211
+ code: "PROCESS_ABORTED",
212
+ details: errorDetails,
213
+ }),
214
+ }).pipe(Effect.catchAll(() => ignoreSyncError("kill fallback", () => child.kill("SIGKILL"))));
215
+ }
216
+ });
217
+ })).pipe(Effect.tap(({ truncationCount }) => truncationCount > 0
218
+ ? Metric.incrementBy(toolOutputTruncatedTotal, truncationCount)
219
+ : Effect.void), Effect.map(({ result }) => result), Effect.annotateLogs({
220
+ ...logAnnotations,
221
+ }), Effect.withLogSpan(span));
222
+ }
@@ -0,0 +1,28 @@
1
+ import { withAbort } from "./withAbort.js";
2
+ /** @typedef {import("@smithers-orchestrator/graph").TaskDescriptor} TaskDescriptor */
3
+ /** @typedef {import("./workflow-types.ts").TaskExecutorContext} TaskExecutorContext */
4
+
5
+ /**
6
+ * @param {TaskDescriptor} task
7
+ * @param {TaskExecutorContext} context
8
+ * @returns {Promise<unknown>}
9
+ */
10
+ export async function defaultTaskExecutor(task, context) {
11
+ if (typeof task.computeFn === "function") {
12
+ return withAbort(Promise.resolve().then(() => task.computeFn()), context.signal);
13
+ }
14
+ if ("staticPayload" in task && task.staticPayload !== undefined) {
15
+ return task.staticPayload;
16
+ }
17
+ const agent = Array.isArray(task.agent) ? task.agent[0] : task.agent;
18
+ if (agent && typeof agent === "object") {
19
+ const target = agent;
20
+ for (const method of ["execute", "run", "call"]) {
21
+ const fn = target[method];
22
+ if (typeof fn === "function") {
23
+ return withAbort(Promise.resolve().then(() => fn(task, context)), context.signal);
24
+ }
25
+ }
26
+ }
27
+ return task.prompt ?? null;
28
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @param {readonly any[]} rows
3
+ * @param {string} lookupNodeId
4
+ * @param {Set<string>} currentScopes
5
+ * @returns {any[]}
6
+ */
7
+ export function filterRowsByNodeId(rows, lookupNodeId, currentScopes) {
8
+ const exact = rows.filter((row) => row.nodeId === lookupNodeId);
9
+ if (exact.length > 0 || lookupNodeId.includes("@@"))
10
+ return exact;
11
+ const sortedScopes = [...currentScopes].sort((a, b) => b.length - a.length);
12
+ for (const scope of sortedScopes) {
13
+ const scopedId = lookupNodeId + scope;
14
+ const matched = rows.filter((row) => row.nodeId === scopedId);
15
+ if (matched.length > 0)
16
+ return matched;
17
+ }
18
+ return [];
19
+ }
@@ -0,0 +1,16 @@
1
+ import { Effect } from "effect";
2
+ /**
3
+ * @param {string} _label
4
+ * @param {() => void} fn
5
+ * @returns {Effect.Effect<void>}
6
+ */
7
+ export function ignoreSyncError(_label, fn) {
8
+ return Effect.sync(() => {
9
+ try {
10
+ fn();
11
+ }
12
+ catch {
13
+ // Best-effort cleanup intentionally swallows failures.
14
+ }
15
+ });
16
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,411 @@
1
+ import * as _smithers_graph_types from '@smithers-orchestrator/graph/types';
2
+ import { WorkflowGraph as WorkflowGraph$1, TaskDescriptor as TaskDescriptor$1 } from '@smithers-orchestrator/graph/types';
3
+ import { SmithersEvent } from '@smithers-orchestrator/observability/SmithersEvent';
4
+ import * as _smithers_scheduler from '@smithers-orchestrator/scheduler';
5
+ import { WaitReason as WaitReason$1, EngineDecision as EngineDecision$1 } from '@smithers-orchestrator/scheduler';
6
+ import { z } from 'zod';
7
+ import { SmithersWorkflowOptions } from '@smithers-orchestrator/scheduler/SmithersWorkflowOptions';
8
+ import { SchemaRegistryEntry } from '@smithers-orchestrator/db/SchemaRegistryEntry';
9
+ import * as _smithers_graph from '@smithers-orchestrator/graph';
10
+ import { ExtractOptions, WorkflowGraph } from '@smithers-orchestrator/graph';
11
+
12
+ type TaskCompletedEvent = {
13
+ nodeId: string;
14
+ iteration: number;
15
+ output: unknown;
16
+ };
17
+
18
+ type TaskFailedEvent = {
19
+ nodeId: string;
20
+ iteration: number;
21
+ error: unknown;
22
+ };
23
+
24
+ type WorkflowSession$2 = {
25
+ submitGraph(graph: WorkflowGraph$1): unknown;
26
+ taskCompleted(event: TaskCompletedEvent): unknown;
27
+ taskFailed(event: TaskFailedEvent): unknown;
28
+ getNextDecision?(): unknown;
29
+ cancelRequested?(): unknown;
30
+ };
31
+
32
+ type WorkflowRuntime$2 = {
33
+ runPromise<A>(effect: unknown): Promise<A>;
34
+ };
35
+
36
+ type RunAuthContext$2 = {
37
+ triggeredBy: string;
38
+ scopes: string[];
39
+ role: string;
40
+ createdAt: string;
41
+ };
42
+
43
+ type HotReloadOptions$1 = {
44
+ /** Root directory to watch for changes (default: auto-detect from workflow entry) */
45
+ rootDir?: string;
46
+ /** Directory for generation overlays (default: .smithers/hmr/<runId>) */
47
+ outDir?: string;
48
+ /** Max overlay generations to keep (default: 3) */
49
+ maxGenerations?: number;
50
+ /** Whether to cancel tasks that become unmounted after hot reload (default: false) */
51
+ cancelUnmounted?: boolean;
52
+ /** Debounce interval in ms for file change events (default: 100) */
53
+ debounceMs?: number;
54
+ };
55
+ type RunOptions$2 = {
56
+ runId?: string;
57
+ parentRunId?: string | null;
58
+ input: Record<string, unknown>;
59
+ maxConcurrency?: number;
60
+ onProgress?: (e: SmithersEvent) => void;
61
+ signal?: AbortSignal;
62
+ resume?: boolean;
63
+ force?: boolean;
64
+ workflowPath?: string;
65
+ rootDir?: string;
66
+ logDir?: string | null;
67
+ allowNetwork?: boolean;
68
+ maxOutputBytes?: number;
69
+ toolTimeoutMs?: number;
70
+ hot?: boolean | HotReloadOptions$1;
71
+ auth?: RunAuthContext$2 | null;
72
+ config?: Record<string, unknown>;
73
+ cliAgentToolsDefault?: "all" | "explicit-only";
74
+ resumeClaim?: {
75
+ claimOwnerId: string;
76
+ claimHeartbeatAtMs: number;
77
+ restoreRuntimeOwnerId?: string | null;
78
+ restoreHeartbeatAtMs?: number | null;
79
+ };
80
+ };
81
+
82
+ type RunStatus$1 = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "finished" | "continued" | "failed" | "cancelled";
83
+
84
+ type RunResult$2 = {
85
+ readonly runId: string;
86
+ readonly status: RunStatus$1;
87
+ readonly output?: unknown;
88
+ readonly error?: unknown;
89
+ readonly nextRunId?: string;
90
+ };
91
+
92
+ type ContinueAsNewHandler$1 = (transition: unknown, context: {
93
+ runId: string;
94
+ options: RunOptions$2;
95
+ }) => Promise<RunResult$2> | RunResult$2;
96
+
97
+ type CreateWorkflowSessionOptions = {
98
+ db?: unknown;
99
+ runId: string;
100
+ rootDir?: string;
101
+ workflowPath?: string | null;
102
+ options: RunOptions$2;
103
+ };
104
+
105
+ type CreateWorkflowSession$1 = (opts: CreateWorkflowSessionOptions) => unknown;
106
+
107
+ type SchedulerWaitHandler$1 = (durationMs: number, context: {
108
+ runId: string;
109
+ tasks: readonly TaskDescriptor$1[];
110
+ }) => Promise<void> | void;
111
+
112
+ type TaskExecutorContext = {
113
+ runId: string;
114
+ options: RunOptions$2;
115
+ signal?: AbortSignal;
116
+ };
117
+
118
+ type TaskExecutor$1 = (task: TaskDescriptor$1, context: TaskExecutorContext) => Promise<unknown> | unknown;
119
+
120
+ type WaitHandler$1 = (reason: WaitReason$1, context: {
121
+ runId: string;
122
+ options: RunOptions$2;
123
+ }) => Promise<EngineDecision$1 | RunResult$2> | EngineDecision$1 | RunResult$2;
124
+
125
+ type InferRow<TTable> = TTable extends {
126
+ $inferSelect: infer R;
127
+ } ? R : never;
128
+ type InferOutputEntry$1<T> = T extends z.ZodTypeAny ? z.infer<T> : T extends {
129
+ $inferSelect: unknown;
130
+ } ? InferRow<T> : never;
131
+ type FallbackTableName<Schema> = [keyof Schema & string] extends [never] ? string : never;
132
+ type OutputAccessor$2<Schema, TRow = unknown> = {
133
+ (table: FallbackTableName<Schema>): Array<TRow>;
134
+ <K extends keyof Schema & string>(table: K): Array<InferOutputEntry$1<Schema[K]>>;
135
+ } & {
136
+ [K in keyof Schema & string]: Array<InferOutputEntry$1<Schema[K]>>;
137
+ };
138
+
139
+ type SmithersRuntimeConfig$1 = {
140
+ cliAgentToolsDefault?: "all" | "explicit-only";
141
+ };
142
+
143
+ type OutputSnapshot$2<TFallback = unknown> = {
144
+ [tableName: string]: Array<TFallback>;
145
+ };
146
+
147
+ type SmithersCtxOptions$2 = {
148
+ runId: string;
149
+ iteration: number;
150
+ iterations?: Record<string, number>;
151
+ input: unknown;
152
+ auth?: RunAuthContext$2 | null;
153
+ outputs: OutputSnapshot$2;
154
+ zodToKeyName?: Map<any, string>;
155
+ runtimeConfig?: SmithersRuntimeConfig$1;
156
+ };
157
+
158
+ type SafeParser$1 = {
159
+ safeParse(value: unknown): {
160
+ success: true;
161
+ data: unknown;
162
+ } | {
163
+ success: false;
164
+ error?: unknown;
165
+ };
166
+ };
167
+
168
+ type OutputKey$2 = {
169
+ nodeId: string;
170
+ iteration?: number;
171
+ };
172
+
173
+ /**
174
+ * @template {unknown} [Schema=unknown]
175
+ */
176
+ declare class SmithersCtx<Schema extends unknown = unknown> {
177
+ /**
178
+ * @param {SmithersCtxOptions} opts
179
+ */
180
+ constructor(opts: SmithersCtxOptions$1);
181
+ /** @type {string} */
182
+ runId: string;
183
+ /** @type {number} */
184
+ iteration: number;
185
+ /** @type {Record<string, number> | undefined} */
186
+ iterations: Record<string, number> | undefined;
187
+ /** @type {Schema extends { input: infer T } ? T : unknown} */
188
+ input: Schema extends {
189
+ input: infer T;
190
+ } ? T : unknown;
191
+ /** @type {RunAuthContext | null} */
192
+ auth: RunAuthContext$1 | null;
193
+ /** @type {SmithersRuntimeConfig | null | undefined} */
194
+ __smithersRuntime: SmithersRuntimeConfig | null | undefined;
195
+ /** @type {OutputAccessor<Schema>} */
196
+ outputs: OutputAccessor$1<Schema>;
197
+ /** @type {import("./OutputSnapshot.ts").OutputSnapshot} */
198
+ _outputs: OutputSnapshot$2;
199
+ /** @type {Map<unknown, string> | undefined} */
200
+ _zodToKeyName: Map<unknown, string> | undefined;
201
+ /** @type {Set<string>} */
202
+ _currentScopes: Set<string>;
203
+ /**
204
+ * @param {TableRef} table
205
+ * @param {OutputKey} key
206
+ * @returns {OutputRow}
207
+ */
208
+ output(table: TableRef, key: OutputKey$1): OutputRow;
209
+ /**
210
+ * @param {TableRef} table
211
+ * @param {OutputKey} key
212
+ * @returns {OutputRow | undefined}
213
+ */
214
+ outputMaybe(table: TableRef, key: OutputKey$1): OutputRow | undefined;
215
+ /**
216
+ * @param {TableRef} table
217
+ * @param {string} nodeId
218
+ * @returns {OutputRow | undefined}
219
+ */
220
+ latest(table: TableRef, nodeId: string): OutputRow | undefined;
221
+ /**
222
+ * @param {unknown} value
223
+ * @param {SafeParser} schema
224
+ * @returns {unknown[]}
225
+ */
226
+ latestArray(value: unknown, schema: SafeParser): unknown[];
227
+ /**
228
+ * @param {TableRef} table
229
+ * @param {string} nodeId
230
+ * @returns {number}
231
+ */
232
+ iterationCount(table: TableRef, nodeId: string): number;
233
+ /**
234
+ * @param {TableRef} table
235
+ * @returns {string}
236
+ */
237
+ resolveTableName(table: TableRef): string;
238
+ /**
239
+ * @param {TableRef} table
240
+ * @param {OutputKey} key
241
+ * @returns {OutputRow | undefined}
242
+ */
243
+ resolveRow(table: TableRef, key: OutputKey$1): OutputRow | undefined;
244
+ }
245
+ type OutputKey$1 = OutputKey$2;
246
+ type SafeParser = SafeParser$1;
247
+ type SmithersCtxOptions$1 = SmithersCtxOptions$2;
248
+ type RunAuthContext$1 = RunAuthContext$2;
249
+ type SmithersRuntimeConfig = SmithersRuntimeConfig$1;
250
+ type TableRef = unknown;
251
+ type OutputRow = Record<string, unknown> & {
252
+ iteration?: number;
253
+ nodeId?: string;
254
+ };
255
+ type OutputAccessor$1<Schema> = OutputAccessor$2<Schema>;
256
+
257
+ type WorkflowElement = {
258
+ type: unknown;
259
+ props: unknown;
260
+ key: string | number | null;
261
+ };
262
+
263
+ type WorkflowSmithersCtx<Schema = unknown> = SmithersCtx<Schema>;
264
+ type WorkflowDefinition$1<Schema = unknown> = {
265
+ readableName?: string;
266
+ description?: string;
267
+ db?: unknown;
268
+ build: (ctx: WorkflowSmithersCtx<Schema>) => WorkflowElement;
269
+ opts: SmithersWorkflowOptions;
270
+ schemaRegistry?: Map<string, SchemaRegistryEntry>;
271
+ zodToKeyName?: Map<z.ZodObject<z.ZodRawShape>, string>;
272
+ };
273
+
274
+ type WorkflowGraphRenderer$1 = {
275
+ render(element: WorkflowElement, opts?: ExtractOptions): Promise<WorkflowGraph> | WorkflowGraph;
276
+ };
277
+
278
+ type WorkflowDriverOptions$1<Schema = unknown> = {
279
+ workflow: WorkflowDefinition$1<Schema>;
280
+ runtime: WorkflowRuntime$2;
281
+ renderer: WorkflowGraphRenderer$1;
282
+ session?: WorkflowSession$2;
283
+ createSession?: CreateWorkflowSession$1;
284
+ db?: unknown;
285
+ runId?: string;
286
+ rootDir?: string;
287
+ workflowPath?: string | null;
288
+ executeTask?: TaskExecutor$1;
289
+ onSchedulerWait?: SchedulerWaitHandler$1;
290
+ onWait?: WaitHandler$1;
291
+ continueAsNew?: ContinueAsNewHandler$1;
292
+ };
293
+
294
+ /**
295
+ * @template {unknown} [Schema=unknown]
296
+ */
297
+ declare class WorkflowDriver<Schema extends unknown = unknown> {
298
+ /**
299
+ * @param {import("./WorkflowDriverOptions.ts").WorkflowDriverOptions<Schema>} options
300
+ */
301
+ constructor(options: WorkflowDriverOptions$1<Schema>);
302
+ /** @type {import("./WorkflowDefinition.ts").WorkflowDefinition<Schema>} */
303
+ workflow: WorkflowDefinition$1<Schema>;
304
+ /** @type {WorkflowRuntime} */
305
+ runtime: WorkflowRuntime$1;
306
+ /** @type {unknown} */
307
+ db: unknown;
308
+ /** @type {string | undefined} */
309
+ configuredRunId: string | undefined;
310
+ /** @type {string | undefined} */
311
+ rootDir: string | undefined;
312
+ /** @type {string | null | undefined} */
313
+ workflowPath: string | null | undefined;
314
+ /** @type {TaskExecutor} */
315
+ executeTask: TaskExecutor;
316
+ /** @type {SchedulerWaitHandler | undefined} */
317
+ onSchedulerWait: SchedulerWaitHandler | undefined;
318
+ /** @type {WaitHandler | undefined} */
319
+ onWait: WaitHandler | undefined;
320
+ /** @type {ContinueAsNewHandler | undefined} */
321
+ continueAsNewHandler: ContinueAsNewHandler | undefined;
322
+ /** @type {CreateWorkflowSession | undefined} */
323
+ createSession: CreateWorkflowSession | undefined;
324
+ /** @type {WorkflowGraphRenderer} */
325
+ renderer: WorkflowGraphRenderer;
326
+ /** @type {WorkflowSession | undefined} */
327
+ session: WorkflowSession$1 | undefined;
328
+ /** @type {string} */
329
+ activeRunId: string;
330
+ /** @type {RunOptions | undefined} */
331
+ activeOptions: RunOptions$1 | undefined;
332
+ /** @type {import("@smithers-orchestrator/graph").WorkflowGraph | undefined} */
333
+ lastGraph: _smithers_graph.WorkflowGraph | undefined;
334
+ /** @type {Map<string, string>} */
335
+ outputTablesByNodeId: Map<string, string>;
336
+ /** @type {OutputSnapshot} */
337
+ baseOutputs: OutputSnapshot$1;
338
+ /**
339
+ * @param {RunOptions} options
340
+ * @returns {Promise<RunResult>}
341
+ */
342
+ run(options: RunOptions$1): Promise<RunResult$1>;
343
+ /**
344
+ * @param {string} runId
345
+ * @param {RunOptions} options
346
+ * @returns {Promise<WorkflowSession>}
347
+ */
348
+ initializeSession(runId: string, options: RunOptions$1): Promise<WorkflowSession$1>;
349
+ /**
350
+ * @param {RenderContext} context
351
+ * @returns {Promise<EngineDecision>}
352
+ */
353
+ renderAndSubmit(context: RenderContext): Promise<EngineDecision>;
354
+ /**
355
+ * @param {readonly TaskDescriptor[]} tasks
356
+ * @returns {Promise<EngineDecision | RunResult>}
357
+ */
358
+ executeTasks(tasks: readonly TaskDescriptor[]): Promise<EngineDecision | RunResult$1>;
359
+ /**
360
+ * @param {WaitReason} reason
361
+ * @returns {Promise<EngineDecision | RunResult>}
362
+ */
363
+ handleWait(reason: WaitReason): Promise<EngineDecision | RunResult$1>;
364
+ /**
365
+ * @param {unknown} transition
366
+ * @returns {Promise<RunResult>}
367
+ */
368
+ continueAsNew(transition: unknown): Promise<RunResult$1>;
369
+ /**
370
+ * @returns {Promise<RunResult>}
371
+ */
372
+ cancelRun(): Promise<RunResult$1>;
373
+ /**
374
+ * @template A
375
+ * @param {unknown} effect
376
+ * @returns {Promise<A>}
377
+ */
378
+ runEffect<A>(effect: unknown): Promise<A>;
379
+ }
380
+ type CreateWorkflowSession = CreateWorkflowSession$1;
381
+ type OutputSnapshot$1 = OutputSnapshot$2;
382
+ type WorkflowSession$1 = WorkflowSession$2;
383
+ type WorkflowRuntime$1 = WorkflowRuntime$2;
384
+ type WorkflowGraphRenderer = WorkflowGraphRenderer$1;
385
+ type TaskExecutor = TaskExecutor$1;
386
+ type SchedulerWaitHandler = SchedulerWaitHandler$1;
387
+ type WaitHandler = WaitHandler$1;
388
+ type ContinueAsNewHandler = ContinueAsNewHandler$1;
389
+ type RunOptions$1 = RunOptions$2;
390
+ type RunResult$1 = _smithers_scheduler.RunResult;
391
+ type EngineDecision = _smithers_scheduler.EngineDecision;
392
+ type RenderContext = _smithers_scheduler.RenderContext;
393
+ type WaitReason = _smithers_scheduler.WaitReason;
394
+ type TaskDescriptor = _smithers_graph_types.TaskDescriptor;
395
+
396
+ type HotReloadOptions = HotReloadOptions$1;
397
+ type OutputAccessor<Schema = any> = OutputAccessor$2<Schema>;
398
+ type InferOutputEntry<T> = InferOutputEntry$1<T>;
399
+ type OutputKey = OutputKey$2;
400
+ type OutputSnapshot = OutputSnapshot$2;
401
+ type RunAuthContext = RunAuthContext$2;
402
+ type RunOptions = RunOptions$2;
403
+ type RunResult = RunResult$2;
404
+ type RunStatus = RunStatus$1;
405
+ type SmithersCtxOptions = SmithersCtxOptions$2;
406
+ type WorkflowDefinition<Schema = unknown> = WorkflowDefinition$1<Schema>;
407
+ type WorkflowDriverOptions<Schema = unknown> = WorkflowDriverOptions$1<Schema>;
408
+ type WorkflowRuntime = WorkflowRuntime$2;
409
+ type WorkflowSession = WorkflowSession$2;
410
+
411
+ export { type HotReloadOptions, type InferOutputEntry, type OutputAccessor, type OutputKey, type OutputSnapshot, type RunAuthContext, type RunOptions, type RunResult, type RunStatus, SmithersCtx, type SmithersCtxOptions, type WorkflowDefinition, WorkflowDriver, type WorkflowDriverOptions, type WorkflowRuntime, type WorkflowSession };