@oona/vlo 0.0.0-stage → 0.1.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.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +53 -2
- package/dist/agent.d.ts +107 -0
- package/dist/agent.js +324 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +1540 -0
- package/dist/define-DwM_Qhbw.js +74 -0
- package/dist/domain-Bs8TeDCv.js +338 -0
- package/dist/domain-CJN6n_JD.d.ts +860 -0
- package/dist/host.d.ts +844 -0
- package/dist/host.js +314 -0
- package/dist/index-CIIcdblQ.d.ts +824 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/roles-D25bG980.js +3869 -0
- package/dist/src-DVCYkPA7.js +734 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +511 -0
- package/dist/types-BLQQMmkc.d.ts +746 -0
- package/dist/vlo_kernel-CtzHHfHA.js +276 -0
- package/package.json +93 -4
- package/wasm/vlo_kernel.d.ts +82 -0
- package/wasm/vlo_kernel.js +382 -0
- package/wasm/vlo_kernel_bg.wasm +0 -0
- package/wasm/vlo_kernel_bg.wasm.d.ts +15 -0
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { D as RetryPolicy, S as Json, j as Usage, v as Command } from "./types-BLQQMmkc.js";
|
|
3
|
+
import { X as WorkflowDef, u as Role } from "./domain-CJN6n_JD.js";
|
|
4
|
+
/**
|
|
5
|
+
* Retry policy an activity gets when {@link ActivityOptions.retry} is omitted: three
|
|
6
|
+
* attempts, exponential backoff from 1 s to a 10 min cap, factor 2, full jitter. Each
|
|
7
|
+
* field is also the fallback for any {@link RetryOptions} field left unset.
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_RETRY: RetryPolicy;
|
|
10
|
+
/**
|
|
11
|
+
* Queue an activity is dispatched on when {@link ActivityOptions.queue} is omitted, and the
|
|
12
|
+
* queue a worker serves when {@link WorkerOptions.queues} is omitted.
|
|
13
|
+
*/
|
|
14
|
+
declare const DEFAULT_QUEUE = "default";
|
|
15
|
+
/** Lease a worker holds before it must heartbeat. Long tasks heartbeat, they do not raise this. */
|
|
16
|
+
declare const DEFAULT_LEASE_MS = 60000;
|
|
17
|
+
/**
|
|
18
|
+
* Authoring form of {@link RetryPolicy} (camelCase, all optional); the wire form is
|
|
19
|
+
* snake_case. Every omitted field falls back to {@link DEFAULT_RETRY}.
|
|
20
|
+
*/
|
|
21
|
+
interface RetryOptions {
|
|
22
|
+
/** Attempts in total, the first one included. Default `3`. */
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
/** `"fixed"` waits `initialMs` every time; `"exponential"` multiplies it by `factor` per attempt. Default `"exponential"`. */
|
|
25
|
+
backoff?: RetryPolicy["backoff"];
|
|
26
|
+
/** Delay before the second attempt, in milliseconds. Default `1_000`. */
|
|
27
|
+
initialMs?: number;
|
|
28
|
+
/** Ceiling on any single delay, in milliseconds. Default `600_000`. */
|
|
29
|
+
maxMs?: number;
|
|
30
|
+
/** Growth multiplier for exponential backoff; a value ≤ 1 behaves like fixed. Default `2`. */
|
|
31
|
+
factor?: number;
|
|
32
|
+
/** `"full"` scales each delay by a journaled random fraction; `"none"` uses it as is. Default `"full"`. */
|
|
33
|
+
jitter?: RetryPolicy["jitter"];
|
|
34
|
+
}
|
|
35
|
+
/** What {@link activity} needs: the two Zod schemas plus optional dispatch knobs. */
|
|
36
|
+
interface ActivityOptions<I extends z.ZodType, O extends z.ZodType> {
|
|
37
|
+
/** Schema of the task input. `cmd.task` validates against it before the command leaves the reducer. */
|
|
38
|
+
input: I;
|
|
39
|
+
/** Schema of the handler's return value. The host validates against it before folding `task_done`. */
|
|
40
|
+
output: O;
|
|
41
|
+
/** Retry policy; see {@link RetryOptions}. Part of the content hash. Default {@link DEFAULT_RETRY}. */
|
|
42
|
+
retry?: RetryOptions;
|
|
43
|
+
/** Queue the task is dispatched on. Default {@link DEFAULT_QUEUE}. Outside the content hash. */
|
|
44
|
+
queue?: string;
|
|
45
|
+
/** Lease a worker holds on an attempt before it must heartbeat, in milliseconds. Default {@link DEFAULT_LEASE_MS}. Outside the content hash. */
|
|
46
|
+
leaseMs?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Wall-clock budget for one attempt. The worker aborts the handler at it and reports
|
|
49
|
+
* `cause: "timeout"`; the host reaps the attempt if the worker never answers at all.
|
|
50
|
+
*
|
|
51
|
+
* Deliberately outside the content hash: a timeout is an operational knob, not part of the
|
|
52
|
+
* activity's contract, so tuning it must not version the schema out from under live runs.
|
|
53
|
+
*/
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A defined activity: the value {@link activity} returns, passed to `cmd.task`, {@link step}
|
|
58
|
+
* and {@link fanOut}. `I` and `O` are the inferred input and output types.
|
|
59
|
+
*/
|
|
60
|
+
interface Activity<I = unknown, O = unknown> {
|
|
61
|
+
/** Discriminator the config loader uses to find activities among a module's exports. */
|
|
62
|
+
readonly kind: "activity";
|
|
63
|
+
/** The name given to {@link activity}; the key a worker registers its handler under. */
|
|
64
|
+
readonly name: string;
|
|
65
|
+
/** Content hash of `name`, both JSON schemas and the retry policy. It is the version. */
|
|
66
|
+
readonly hash: string;
|
|
67
|
+
/** `${name}@${hash}` — the `schema_ref` on the wire. */
|
|
68
|
+
readonly schemaRef: string;
|
|
69
|
+
/** Input schema, as given. */
|
|
70
|
+
readonly input: z.ZodType<I>;
|
|
71
|
+
/** Output schema, as given. */
|
|
72
|
+
readonly output: z.ZodType<O>;
|
|
73
|
+
/** Resolved retry policy in wire form. */
|
|
74
|
+
readonly retry: RetryPolicy;
|
|
75
|
+
/** Queue tasks are dispatched on. */
|
|
76
|
+
readonly queue: string;
|
|
77
|
+
/** Lease per attempt, in milliseconds. */
|
|
78
|
+
readonly leaseMs: number;
|
|
79
|
+
/** Per-attempt wall-clock budget, in milliseconds; absent when none was set. */
|
|
80
|
+
readonly timeoutMs?: number;
|
|
81
|
+
/** JSON Schema of both schemas, as registered with the host and used for the hash. */
|
|
82
|
+
readonly jsonSchema: {
|
|
83
|
+
input: Json;
|
|
84
|
+
output: Json;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A defined signal: the value {@link signal} returns, passed to `cmd.awaitSignal`,
|
|
89
|
+
* `cmd.awaitHuman` and {@link waitFor}. `T` is the inferred payload type.
|
|
90
|
+
*/
|
|
91
|
+
interface SignalDef<T = unknown> {
|
|
92
|
+
/** Discriminator the config loader uses to find signals among a module's exports. */
|
|
93
|
+
readonly kind: "signal";
|
|
94
|
+
/** The name given to {@link signal}; the name a sender delivers the signal under. */
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/** Content hash of `name` and the JSON schema. It is the version. */
|
|
97
|
+
readonly hash: string;
|
|
98
|
+
/** `${name}@${hash}` — the `schema_ref` on the wire. */
|
|
99
|
+
readonly schemaRef: string;
|
|
100
|
+
/** Payload schema, as given. A host that has the signal registered validates inbound payloads against it. */
|
|
101
|
+
readonly schema: z.ZodType<T>;
|
|
102
|
+
/** JSON Schema of `schema`, as registered with the host and used for the hash. */
|
|
103
|
+
readonly jsonSchema: Json;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Defines an activity: a named unit of work a worker implements and a reducer requests
|
|
107
|
+
* with `cmd.task`.
|
|
108
|
+
*
|
|
109
|
+
* The content hash covers `name`, both schemas (as JSON Schema, projected by
|
|
110
|
+
* {@link projectSchema} so annotations such as `description` and `default` are
|
|
111
|
+
* hash-neutral) and the resolved retry policy, so changing any of them yields a new
|
|
112
|
+
* `schemaRef`; `queue`, `leaseMs` and `timeoutMs` are operational and hash-neutral. Runs
|
|
113
|
+
* pin the `schemaRef` per event, so old and new versions coexist.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { z } from "zod";
|
|
118
|
+
* import { activity } from "@oona/vlo";
|
|
119
|
+
*
|
|
120
|
+
* export const work = activity("example.work", {
|
|
121
|
+
* input: z.object({ item: z.string() }),
|
|
122
|
+
* output: z.object({ upper: z.string() }),
|
|
123
|
+
* retry: { maxAttempts: 3 },
|
|
124
|
+
* queue: "default",
|
|
125
|
+
* timeoutMs: 30_000,
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function activity<I extends z.ZodType, O extends z.ZodType>(name: string, options: ActivityOptions<I, O>): Activity<z.infer<I>, z.infer<O>>;
|
|
130
|
+
/**
|
|
131
|
+
* Defines a signal: a named, typed message a run can park on with `cmd.awaitSignal`,
|
|
132
|
+
* `cmd.awaitHuman` or {@link waitFor}, delivered from outside through the host's API.
|
|
133
|
+
*
|
|
134
|
+
* The content hash covers `name` and the schema as JSON Schema, projected the same way as
|
|
135
|
+
* an activity's. A host that has the definition registered rejects an inbound payload the
|
|
136
|
+
* schema does not accept.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { z } from "zod";
|
|
141
|
+
* import { signal } from "@oona/vlo";
|
|
142
|
+
*
|
|
143
|
+
* export const approve = signal("example.approve", z.object({ by: z.string() }));
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare function signal<S extends z.ZodType>(name: string, schema: S): SignalDef<z.infer<S>>;
|
|
147
|
+
/** Thrown synchronously by `cmd.task` when the input does not match the activity's schema. */
|
|
148
|
+
declare class ActivityInputError extends Error {
|
|
149
|
+
/** Name of the activity whose input schema rejected the value. */
|
|
150
|
+
readonly activity: string;
|
|
151
|
+
/** @param detail - The Zod issues, joined as `path: message; …`. */
|
|
152
|
+
constructor(activity: string, detail: string);
|
|
153
|
+
}
|
|
154
|
+
/** Per-call overrides for `cmd.task`. */
|
|
155
|
+
interface TaskOptions {
|
|
156
|
+
/** Step id. Defaults to a kernel-derived id; set it when a phase fans out. */
|
|
157
|
+
id?: string;
|
|
158
|
+
/** Queue for this task only. Defaults to the activity's `queue`. */
|
|
159
|
+
queue?: string;
|
|
160
|
+
}
|
|
161
|
+
/** When a `cmd.timer` fires. Exactly one of `ms` / `atMs` is required. */
|
|
162
|
+
interface TimerOptions {
|
|
163
|
+
/** Delay in milliseconds, counted from the timestamp of the event being reduced. */
|
|
164
|
+
ms?: number;
|
|
165
|
+
/** Absolute epoch time in milliseconds. */
|
|
166
|
+
atMs?: number;
|
|
167
|
+
/** Step id. Defaults to a kernel-derived id. */
|
|
168
|
+
id?: string;
|
|
169
|
+
}
|
|
170
|
+
/** Per-call overrides for `cmd.spawn`. */
|
|
171
|
+
interface SpawnOptions {
|
|
172
|
+
/** Step id of the child step. Defaults to a kernel-derived id. */
|
|
173
|
+
id?: string;
|
|
174
|
+
}
|
|
175
|
+
/** Per-call overrides for `cmd.awaitSignal`. */
|
|
176
|
+
interface AwaitSignalOptions {
|
|
177
|
+
/** Step id of the wait. Defaults to a kernel-derived id. */
|
|
178
|
+
id?: string;
|
|
179
|
+
/**
|
|
180
|
+
* Deadline for the wait, counted from the timestamp of the event being reduced. A `timer`
|
|
181
|
+
* event with step id `<id>:timeout` reaches the reducer when the deadline passes; the
|
|
182
|
+
* losing side of the race is cancelled by the kernel. Requires an explicit `id`.
|
|
183
|
+
*/
|
|
184
|
+
timeoutMs?: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Requests one attempt-tracked execution of `target` with `input`.
|
|
188
|
+
*
|
|
189
|
+
* `input` is parsed with the activity's Zod schema; the parsed value (defaults applied) is
|
|
190
|
+
* what travels. The activity's `queue`, `retry`, `leaseMs` and `timeoutMs` are copied onto
|
|
191
|
+
* the command; `options.queue` overrides the queue for this call.
|
|
192
|
+
*
|
|
193
|
+
* @throws {@link ActivityInputError} when the input does not match the activity's schema.
|
|
194
|
+
*/
|
|
195
|
+
declare function task<I, O>(target: Activity<I, O>, input: I, options?: TaskOptions): Command;
|
|
196
|
+
/**
|
|
197
|
+
* Schedules a `timer` event for the run. `ms` is relative to the timestamp of the event
|
|
198
|
+
* being reduced; `atMs` is absolute epoch milliseconds.
|
|
199
|
+
*
|
|
200
|
+
* Throws a `TypeError` synchronously when neither or both of `ms` / `atMs` are given.
|
|
201
|
+
*/
|
|
202
|
+
declare function timer(options: TimerOptions): Command;
|
|
203
|
+
/**
|
|
204
|
+
* Starts a child run of `workflow` (a name, or anything with a `name` such as a
|
|
205
|
+
* {@link Workflow}) with `input`. The child's terminal status and output come back to this
|
|
206
|
+
* run as a `child_done` event on the spawn's step id. The workflow must be registered on
|
|
207
|
+
* the host that dispatches the command.
|
|
208
|
+
*/
|
|
209
|
+
declare function spawn(workflow: string | {
|
|
210
|
+
name: string;
|
|
211
|
+
}, input: Json, options?: SpawnOptions): Command;
|
|
212
|
+
/**
|
|
213
|
+
* Parks the run until a signal named after `definition` is delivered; the payload arrives
|
|
214
|
+
* on a `signal` event. A signal that arrived before the wait was opened is buffered and
|
|
215
|
+
* delivered immediately, oldest first. The run holds no compute while parked. With
|
|
216
|
+
* `timeoutMs` the kernel also opens a timer step `<id>:timeout` and cancels whichever of
|
|
217
|
+
* the two loses; see {@link signalTimeoutStepId}.
|
|
218
|
+
*/
|
|
219
|
+
declare function awaitSignal<T>(definition: SignalDef<T>, options?: AwaitSignalOptions): Command;
|
|
220
|
+
/**
|
|
221
|
+
* Publishes `data` on a side channel. Emits never enter the run's history and never come
|
|
222
|
+
* back to the reducer; the host forwards them to event-stream subscribers, which is where
|
|
223
|
+
* progress ticks and UI hints belong.
|
|
224
|
+
*/
|
|
225
|
+
declare function emit(channel: string, data: Json): Command;
|
|
226
|
+
/**
|
|
227
|
+
* Closes the run as `completed` with `output`. It must be the last command of the reduction;
|
|
228
|
+
* the kernel rejects any command after it.
|
|
229
|
+
*/
|
|
230
|
+
declare function complete(output: Json): Command;
|
|
231
|
+
/**
|
|
232
|
+
* Closes the run as `continued`, carrying `input` as the start input of a successor run. It
|
|
233
|
+
* must be the last command of the reduction. The host starts the successor (same workflow,
|
|
234
|
+
* this `input`) in the same transaction and links the two runs by `continued_from` and
|
|
235
|
+
* `continued_to`; a parent run is notified once, by the run that finally closes.
|
|
236
|
+
*/
|
|
237
|
+
declare function continueAsNew(input: Json): Command;
|
|
238
|
+
interface AwaitHumanOptions {
|
|
239
|
+
/** Step id of the wait. The deadline timer is `${id}:timeout`, so it is required. */
|
|
240
|
+
id: string;
|
|
241
|
+
/** Deadline for the reply. Without one the run waits forever. */
|
|
242
|
+
timeoutMs?: number;
|
|
243
|
+
/** Rendered by whatever asks the human — "context travels with the ask". */
|
|
244
|
+
context?: Json;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Step id of the timer the kernel pairs with a signal wait `id` that carries a
|
|
248
|
+
* `timeoutMs`. A `timer` event with this step id means the deadline won the race.
|
|
249
|
+
*/
|
|
250
|
+
declare function signalTimeoutStepId(id: string): string;
|
|
251
|
+
/** @deprecated Use {@link signalTimeoutStepId}; same string. */
|
|
252
|
+
declare const humanTimeoutStepId: typeof signalTimeoutStepId;
|
|
253
|
+
/**
|
|
254
|
+
* Ask a human. Sugar over `await_signal` (with its deadline) + `emit`: the wait reserves
|
|
255
|
+
* `id` and the kernel opens `${id}:timeout` beside it, so whichever arrives first wins and
|
|
256
|
+
* the kernel cancels the loser. Returns commands — spread it into a reduction.
|
|
257
|
+
*/
|
|
258
|
+
declare function awaitHuman<T>(definition: SignalDef<T>, options: AwaitHumanOptions): Command[];
|
|
259
|
+
/**
|
|
260
|
+
* The command constructors a reducer returns to the engine. Each builds a plain
|
|
261
|
+
* {@link Command}; nothing runs until the host applies the reduction. `task`, `timer`,
|
|
262
|
+
* `spawn` and `awaitSignal` open a step, `emit` records a side effect, `complete` and
|
|
263
|
+
* `continueAsNew` close the run and must come last.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* import { cmd, defineWorkflow } from "@oona/vlo";
|
|
268
|
+
* import { approve, work } from "./activities.ts";
|
|
269
|
+
*
|
|
270
|
+
* export default defineWorkflow("review", {
|
|
271
|
+
* init: (input: { item: string }) => ({ item: input.item, upper: null as string | null }),
|
|
272
|
+
* on: {
|
|
273
|
+
* started: (s) => [s, [cmd.task(work, { item: s.item })]],
|
|
274
|
+
* task_done: (s, e) => [
|
|
275
|
+
* { ...s, upper: (e.output as { upper: string }).upper },
|
|
276
|
+
* cmd.awaitHuman(approve, { id: "approval", timeoutMs: 86_400_000 }),
|
|
277
|
+
* ],
|
|
278
|
+
* signal: (s) => [s, [cmd.complete({ upper: s.upper })]],
|
|
279
|
+
* timer: (s) => [s, [cmd.complete(null)]],
|
|
280
|
+
* },
|
|
281
|
+
* });
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
declare const cmd: {
|
|
285
|
+
/** Runs an activity once, with retries. Throws {@link ActivityInputError} on bad input. */
|
|
286
|
+
readonly task: typeof task;
|
|
287
|
+
/** Fires a `timer` event after `ms` or at `atMs`. */
|
|
288
|
+
readonly timer: typeof timer;
|
|
289
|
+
/** Starts a child run; its result arrives as `child_done`. */
|
|
290
|
+
readonly spawn: typeof spawn;
|
|
291
|
+
/** Parks the run until the named signal is delivered. */
|
|
292
|
+
readonly awaitSignal: typeof awaitSignal;
|
|
293
|
+
/** `awaitSignal` with a deadline + `emit("human", …)`; returns a `Command[]`. */
|
|
294
|
+
readonly awaitHuman: typeof awaitHuman;
|
|
295
|
+
/** Publishes on a side channel; never journaled. */
|
|
296
|
+
readonly emit: typeof emit;
|
|
297
|
+
/** Closes the run as `completed`. Must be last. */
|
|
298
|
+
readonly complete: typeof complete;
|
|
299
|
+
/** Closes the run as `continued` with a fresh start input. Must be last. */
|
|
300
|
+
readonly continueAsNew: typeof continueAsNew;
|
|
301
|
+
};
|
|
302
|
+
/** Progress of a {@link fanOut} or {@link fanOutRuns} phase in flight; absent from {@link SeqState} otherwise. */
|
|
303
|
+
interface FanState {
|
|
304
|
+
/** Name of the activity or workflow being fanned out. */
|
|
305
|
+
activity: string;
|
|
306
|
+
/** Number of items `select` returned. */
|
|
307
|
+
total: number;
|
|
308
|
+
/** Index of the next item to dispatch. */
|
|
309
|
+
next: number;
|
|
310
|
+
/** Step ids currently in flight. */
|
|
311
|
+
outstanding: string[];
|
|
312
|
+
/** Outputs by item index; `null` until that item's task or child run settles. */
|
|
313
|
+
outputs: Json[];
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* State of a workflow built by {@link sequence}. `mapInput`, `select`, `when` and `output`
|
|
317
|
+
* callbacks read it; the run completes with `results` (or `output(state)`) as its output.
|
|
318
|
+
*/
|
|
319
|
+
interface SeqState {
|
|
320
|
+
/** Index of the phase currently in flight. */
|
|
321
|
+
phase: number;
|
|
322
|
+
/** The run's start input. */
|
|
323
|
+
input: Json;
|
|
324
|
+
/** Outputs of finished {@link step}, {@link fanOut} and {@link fanOutRuns} phases, keyed by activity or workflow name. */
|
|
325
|
+
results: Record<string, Json>;
|
|
326
|
+
/** Payloads of finished {@link waitFor} phases, keyed by signal name; `null` after a `"continue"` timeout. */
|
|
327
|
+
signals: Record<string, Json>;
|
|
328
|
+
/** Present only while a {@link fanOut} or {@link fanOutRuns} phase is in flight. */
|
|
329
|
+
fan?: FanState;
|
|
330
|
+
/**
|
|
331
|
+
* The run's banked usage as of the last folded event (`event.usage_total`). Absent on a
|
|
332
|
+
* checkpoint written before any event was folded with this field.
|
|
333
|
+
*/
|
|
334
|
+
usage?: Usage;
|
|
335
|
+
}
|
|
336
|
+
/** An activity with its input and output types erased, as `sequence` stores it; Zod still validates every input. */
|
|
337
|
+
type ErasedActivity = Activity<Json, Json>;
|
|
338
|
+
/** What a phase does when its task or child run did not succeed. Default: `"fail"`. */
|
|
339
|
+
type OnFailure = "fail" | "continue";
|
|
340
|
+
/** Options for {@link step}. */
|
|
341
|
+
interface StepOptions {
|
|
342
|
+
/** Explicit step id; default: the kernel-derived `task#n`. Set it when a handler keys on the step id. */
|
|
343
|
+
id?: string;
|
|
344
|
+
/** `"fail"` (default) fails the run on a task that did not succeed; `"continue"` stores `null` and advances. */
|
|
345
|
+
onFailure?: OnFailure;
|
|
346
|
+
/** Pure gate evaluated when the phase is entered; `false` stores `null` and advances without a task. */
|
|
347
|
+
when?: (state: SeqState) => boolean;
|
|
348
|
+
}
|
|
349
|
+
/** Options for {@link fanOut}. */
|
|
350
|
+
interface FanOutOptions {
|
|
351
|
+
/** Maximum tasks in flight at once; an integer ≥ 1. */
|
|
352
|
+
concurrency: number;
|
|
353
|
+
/** `"fail"` (default) fails the run on any task that did not succeed; `"continue"` stores `null` for that item. */
|
|
354
|
+
onFailure?: OnFailure;
|
|
355
|
+
}
|
|
356
|
+
/** Options for {@link fanOutRuns}. */
|
|
357
|
+
interface FanOutRunsOptions {
|
|
358
|
+
/** Maximum child runs in flight at once; an integer ≥ 1. */
|
|
359
|
+
concurrency: number;
|
|
360
|
+
/** `"fail"` (default) fails the run on any child that did not complete; `"continue"` records its status and moves on. */
|
|
361
|
+
onFailure?: OnFailure;
|
|
362
|
+
}
|
|
363
|
+
/** The terminal status a child run reports to its parent, mapped from the child's run status. */
|
|
364
|
+
type ChildStatus = "succeeded" | "failed" | "cancelled";
|
|
365
|
+
/** One child's outcome as {@link fanOutRuns} stores it. */
|
|
366
|
+
interface ChildResult<O = Json> {
|
|
367
|
+
/** `succeeded` for a completed child, else `failed` or `cancelled`. */
|
|
368
|
+
status: ChildStatus;
|
|
369
|
+
/** The child's completion output; `null` unless it completed. */
|
|
370
|
+
output: O | null;
|
|
371
|
+
/** The child's run id, for a journal read of its own events. */
|
|
372
|
+
child_run_id: string;
|
|
373
|
+
}
|
|
374
|
+
/** Options for {@link sequence}. */
|
|
375
|
+
interface SequenceOptions {
|
|
376
|
+
/** Shapes the completion output; default: `state.results`. Pure. */
|
|
377
|
+
output?: (state: SeqState) => Json;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* One phase of a {@link sequence}, as built by {@link step}, {@link fanOut}, {@link fanOutRuns},
|
|
381
|
+
* {@link waitFor} or {@link sleep}. Treat it as opaque; the shape is exposed for inspection only.
|
|
382
|
+
*/
|
|
383
|
+
type SeqStep = {
|
|
384
|
+
/** A single task. */
|
|
385
|
+
readonly kind: "step";
|
|
386
|
+
/** Key in `results`: the activity name. */
|
|
387
|
+
readonly key: string;
|
|
388
|
+
/** The activity to run. */
|
|
389
|
+
readonly activity: ErasedActivity;
|
|
390
|
+
/** Builds the task input from state; absent means "the previous phase's value". */
|
|
391
|
+
readonly mapInput?: (state: SeqState) => Json;
|
|
392
|
+
/** Explicit step id; absent means kernel-derived. */
|
|
393
|
+
readonly id?: string;
|
|
394
|
+
/** What a task that did not succeed does; absent means `"fail"`. */
|
|
395
|
+
readonly onFailure?: OnFailure;
|
|
396
|
+
/** Gate evaluated on phase entry; absent means always run. */
|
|
397
|
+
readonly when?: (state: SeqState) => boolean;
|
|
398
|
+
} | {
|
|
399
|
+
/** One task per selected item. */
|
|
400
|
+
readonly kind: "fan_out";
|
|
401
|
+
/** Key in `results`: the activity name. */
|
|
402
|
+
readonly key: string;
|
|
403
|
+
/** The activity to run per item. */
|
|
404
|
+
readonly activity: ErasedActivity;
|
|
405
|
+
/** Pure selector of the items; re-evaluated on every event of the phase. */
|
|
406
|
+
readonly select: (state: SeqState) => Json[];
|
|
407
|
+
/** Maximum tasks in flight at once. */
|
|
408
|
+
readonly concurrency: number;
|
|
409
|
+
/** What a task that did not succeed does; absent means `"fail"`. */
|
|
410
|
+
readonly onFailure?: OnFailure;
|
|
411
|
+
} | {
|
|
412
|
+
/** One child run per selected item. */
|
|
413
|
+
readonly kind: "fan_out_runs";
|
|
414
|
+
/** Key in `results`: the workflow name. */
|
|
415
|
+
readonly key: string;
|
|
416
|
+
/** The workflow to spawn per item. */
|
|
417
|
+
readonly workflow: string;
|
|
418
|
+
/** Pure selector of the child inputs; re-evaluated on every event of the phase. */
|
|
419
|
+
readonly select: (state: SeqState) => Json[];
|
|
420
|
+
/** Maximum child runs in flight at once. */
|
|
421
|
+
readonly concurrency: number;
|
|
422
|
+
/** What a child that did not complete does; absent means `"fail"`. */
|
|
423
|
+
readonly onFailure?: OnFailure;
|
|
424
|
+
} | {
|
|
425
|
+
/** A parked wait for a signal. */
|
|
426
|
+
readonly kind: "wait_for";
|
|
427
|
+
/** Key in `signals`: the signal name. */
|
|
428
|
+
readonly key: string;
|
|
429
|
+
/** The signal to wait for. */
|
|
430
|
+
readonly signal: SignalDef<Json>;
|
|
431
|
+
/** Deadline in milliseconds; absent means wait forever. */
|
|
432
|
+
readonly timeoutMs?: number;
|
|
433
|
+
/** What the deadline does; absent means `"fail"`. */
|
|
434
|
+
readonly onTimeout?: OnTimeout;
|
|
435
|
+
/** Emitted on the `human` channel when the wait opens. */
|
|
436
|
+
readonly context?: Json;
|
|
437
|
+
} | {
|
|
438
|
+
/** A timer that stores nothing. */
|
|
439
|
+
readonly kind: "sleep";
|
|
440
|
+
/** Duration in milliseconds. */
|
|
441
|
+
readonly ms: number;
|
|
442
|
+
};
|
|
443
|
+
/** What a `waitFor` deadline does when it fires first. Default: `"fail"`. */
|
|
444
|
+
type OnTimeout = "fail" | "continue";
|
|
445
|
+
/** Deadline and presentation options for {@link waitFor}. */
|
|
446
|
+
interface WaitForOptions {
|
|
447
|
+
/** Deadline in milliseconds, counted from when the wait opens. Absent: the run waits forever. */
|
|
448
|
+
timeoutMs?: number;
|
|
449
|
+
/** `"fail"` (default) fails the run at the deadline; `"continue"` advances with a `null` payload. */
|
|
450
|
+
onTimeout?: OnTimeout;
|
|
451
|
+
/** Emitted on the `human` channel alongside the wait, for whatever renders the ask. */
|
|
452
|
+
context?: Json;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* A {@link sequence} phase that runs `target` once.
|
|
456
|
+
*
|
|
457
|
+
* Without `mapInput` the task input is the run's start input for phase 0 and the previous
|
|
458
|
+
* phase's stored value afterwards (sleeps are skipped). The output is stored in
|
|
459
|
+
* `results[target.name]`. A task that does not succeed fails the run, unless
|
|
460
|
+
* `onFailure: "continue"` stores `null` instead; `when` returning `false` also stores `null`
|
|
461
|
+
* and skips the task. `id` pins the step id for handlers that key on it.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```ts
|
|
465
|
+
* import { defineWorkflow, resultOf, sequence, step } from "@oona/vlo";
|
|
466
|
+
* import { finish, notify, plan } from "./activities.ts";
|
|
467
|
+
*
|
|
468
|
+
* export default defineWorkflow("example", sequence([
|
|
469
|
+
* step(plan),
|
|
470
|
+
* step(finish, (state) => ({ uppers: resultOf(state, plan).items, approvedBy: "auto" })),
|
|
471
|
+
* step(notify, undefined, { onFailure: "continue", when: (s) => resultOf(s, plan).items.length > 0 }),
|
|
472
|
+
* ]));
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
declare function step<I, O>(target: Activity<I, O>, mapInput?: (state: SeqState) => I, options?: StepOptions): SeqStep;
|
|
476
|
+
/**
|
|
477
|
+
* A {@link sequence} phase that runs `target` once per item `select` returns, at most
|
|
478
|
+
* `concurrency` at a time, with step ids `${target.name}#${index}`.
|
|
479
|
+
*
|
|
480
|
+
* `select` must be pure and read only state written by earlier phases: it is re-evaluated
|
|
481
|
+
* on every event of the phase and the run fails if it returns a different count. Outputs
|
|
482
|
+
* are stored in `results[target.name]` in item order; an empty selection stores `[]` and
|
|
483
|
+
* moves on. A task that does not succeed fails the run, unless `onFailure: "continue"`
|
|
484
|
+
* stores `null` for that item.
|
|
485
|
+
*
|
|
486
|
+
* Throws a `TypeError` synchronously unless `concurrency` is an integer ≥ 1.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```ts
|
|
490
|
+
* import { defineWorkflow, fanOut, resultOf, sequence, step } from "@oona/vlo";
|
|
491
|
+
* import { plan, work } from "./activities.ts";
|
|
492
|
+
*
|
|
493
|
+
* export default defineWorkflow("example", sequence([
|
|
494
|
+
* step(plan),
|
|
495
|
+
* fanOut(work, (state) => resultOf(state, plan).items.map((item) => ({ item })), { concurrency: 2 }),
|
|
496
|
+
* ]));
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
declare function fanOut<I, O>(target: Activity<I, O>, select: (state: SeqState) => I[], options: FanOutOptions): SeqStep;
|
|
500
|
+
/**
|
|
501
|
+
* A {@link sequence} phase that spawns one child run of `target` per item `select` returns,
|
|
502
|
+
* at most `concurrency` at a time, with step ids `${workflow}#${index}`.
|
|
503
|
+
*
|
|
504
|
+
* `select` has the same purity rule as {@link fanOut}. Each item is the child's start input.
|
|
505
|
+
* The phase stores a {@link ChildResult} per item in `results[workflow]`, in item order;
|
|
506
|
+
* read it with {@link fanOutRunsResultsOf}. An empty selection stores `[]` and moves on.
|
|
507
|
+
* A child that did not complete fails the run, unless `onFailure: "continue"` records its
|
|
508
|
+
* status and moves on. The child workflow must be registered on the same host.
|
|
509
|
+
*
|
|
510
|
+
* Throws a `TypeError` synchronously unless `concurrency` is an integer ≥ 1.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```ts
|
|
514
|
+
* import { defineWorkflow, fanOutRuns, fanOutRunsResultsOf, resultOf, sequence, step } from "@oona/vlo";
|
|
515
|
+
* import { plan, summarise } from "./activities.ts";
|
|
516
|
+
* import { readSource } from "./read-source.workflow.ts";
|
|
517
|
+
*
|
|
518
|
+
* export default defineWorkflow("research", sequence([
|
|
519
|
+
* step(plan),
|
|
520
|
+
* fanOutRuns(readSource, (s) => resultOf(s, plan).sourceIds.map((sourceId) => ({ sourceId })), {
|
|
521
|
+
* concurrency: 5,
|
|
522
|
+
* onFailure: "continue",
|
|
523
|
+
* }),
|
|
524
|
+
* step(summarise, (s) => ({ read: fanOutRunsResultsOf(s, readSource).filter((r) => r.status === "succeeded").length })),
|
|
525
|
+
* ]));
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
declare function fanOutRuns<I extends Json = Json>(target: string | {
|
|
529
|
+
readonly name: string;
|
|
530
|
+
}, select: (state: SeqState) => I[], options: FanOutRunsOptions): SeqStep;
|
|
531
|
+
/**
|
|
532
|
+
* A {@link sequence} phase that parks the run until `definition` is delivered.
|
|
533
|
+
*
|
|
534
|
+
* The payload is stored in `signals[definition.name]`. With `timeoutMs` the wait races the
|
|
535
|
+
* kernel's paired deadline timer (the loser is cancelled): `onTimeout: "fail"` (default)
|
|
536
|
+
* fails the run, `"continue"` stores `null` and advances. `context` is emitted on the
|
|
537
|
+
* `human` channel when the wait opens. A signal or deadline arriving for a phase already
|
|
538
|
+
* left behind is ignored.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```ts
|
|
542
|
+
* import { defineWorkflow, sequence, signalOf, step, waitFor } from "@oona/vlo";
|
|
543
|
+
* import { approve, finish, plan } from "./activities.ts";
|
|
544
|
+
*
|
|
545
|
+
* export default defineWorkflow("example", sequence([
|
|
546
|
+
* step(plan),
|
|
547
|
+
* waitFor(approve, { timeoutMs: 86_400_000, onTimeout: "fail", context: { what: "plan" } }),
|
|
548
|
+
* step(finish, (state) => ({ uppers: [], approvedBy: signalOf(state, approve).by })),
|
|
549
|
+
* ]));
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
declare function waitFor<T>(definition: SignalDef<T>, options?: WaitForOptions): SeqStep;
|
|
553
|
+
/**
|
|
554
|
+
* A {@link sequence} phase that parks the run on a timer for `ms` milliseconds. It stores
|
|
555
|
+
* nothing: the phase after it receives the value of the last phase that stored one.
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```ts
|
|
559
|
+
* import { defineWorkflow, sequence, sleep, step } from "@oona/vlo";
|
|
560
|
+
* import { plan, finish } from "./activities.ts";
|
|
561
|
+
*
|
|
562
|
+
* export default defineWorkflow("example", sequence([
|
|
563
|
+
* step(plan),
|
|
564
|
+
* sleep(60_000),
|
|
565
|
+
* step(finish, (state) => ({ uppers: [], approvedBy: "timer" })),
|
|
566
|
+
* ]));
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
declare function sleep(ms: number): SeqStep;
|
|
570
|
+
/**
|
|
571
|
+
* Compiles an ordered list of phases into a {@link WorkflowDef} for {@link defineWorkflow}.
|
|
572
|
+
*
|
|
573
|
+
* Phases run one after another: {@link step}, {@link fanOut}, {@link fanOutRuns},
|
|
574
|
+
* {@link waitFor} and {@link sleep}. Outputs go to `results` keyed by activity or workflow
|
|
575
|
+
* name and signal payloads to `signals` keyed by signal name, so two phases on the same
|
|
576
|
+
* target share a key. After the last phase the run completes with `results`, or with
|
|
577
|
+
* `options.output(state)`. `state.usage` always holds the run's banked usage as of the
|
|
578
|
+
* last event. Events that do not belong to the current phase are ignored: state
|
|
579
|
+
* unchanged, no commands.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* import {
|
|
584
|
+
* defineWorkflow, fanOut, fanOutResultsOf, resultOf, sequence, signalOf, step, waitFor,
|
|
585
|
+
* } from "@oona/vlo";
|
|
586
|
+
* import { approve, finish, plan, work } from "./activities.ts";
|
|
587
|
+
*
|
|
588
|
+
* export default defineWorkflow("example", sequence([
|
|
589
|
+
* step(plan),
|
|
590
|
+
* fanOut(work, (s) => resultOf(s, plan).items.map((item) => ({ item })), { concurrency: 2 }),
|
|
591
|
+
* waitFor(approve),
|
|
592
|
+
* step(finish, (s) => ({
|
|
593
|
+
* uppers: fanOutResultsOf(s, work).map((o) => o.upper),
|
|
594
|
+
* approvedBy: signalOf(s, approve).by,
|
|
595
|
+
* })),
|
|
596
|
+
* ], { output: (s) => ({ report: resultOf(s, finish).report, tokens: s.usage?.tokens ?? 0 }) }));
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
declare function sequence(steps: readonly SeqStep[], options?: SequenceOptions): WorkflowDef<SeqState, Json>;
|
|
600
|
+
/**
|
|
601
|
+
* The output of an earlier {@link step} on `target`, typed as the activity's output.
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```ts
|
|
605
|
+
* step(finish, (state) => ({ uppers: resultOf(state, plan).items, approvedBy: "auto" }))
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
declare function resultOf<I, O>(state: SeqState, target: Activity<I, O>): O;
|
|
609
|
+
/**
|
|
610
|
+
* The outputs of an earlier {@link fanOut} on `target`, in item order. An empty
|
|
611
|
+
* selection stored `[]`.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```ts
|
|
615
|
+
* step(finish, (state) => ({
|
|
616
|
+
* uppers: fanOutResultsOf(state, work).map((output) => output.upper),
|
|
617
|
+
* approvedBy: "auto",
|
|
618
|
+
* }))
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
declare function fanOutResultsOf<I, O>(state: SeqState, target: Activity<I, O>): O[];
|
|
622
|
+
/**
|
|
623
|
+
* The outcomes of an earlier {@link fanOutRuns} on `target`, in item order: one
|
|
624
|
+
* {@link ChildResult} per child, whose `output` is `null` unless the child completed. An
|
|
625
|
+
* empty selection stored `[]`. `O` is the child workflow's completion output type.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* step(summarise, (state) => ({
|
|
630
|
+
* read: fanOutRunsResultsOf<{ ok: boolean }>(state, readSource).filter((r) => r.output?.ok).length,
|
|
631
|
+
* }))
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
declare function fanOutRunsResultsOf<O = Json>(state: SeqState, target: string | {
|
|
635
|
+
readonly name: string;
|
|
636
|
+
}): ChildResult<O>[];
|
|
637
|
+
/**
|
|
638
|
+
* The payload an earlier {@link waitFor} on `definition` received, typed as the signal's
|
|
639
|
+
* payload. After an `onTimeout: "continue"` deadline the stored value is `null`, which
|
|
640
|
+
* this returns as-is; narrow it yourself when that option is in play.
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* step(finish, (state) => ({ uppers: [], approvedBy: signalOf(state, approve).by }))
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function signalOf<T>(state: SeqState, definition: SignalDef<T>): T;
|
|
648
|
+
/**
|
|
649
|
+
* Deterministic JSON: object keys sorted recursively, arrays in order, no whitespace.
|
|
650
|
+
* Throws on anything JSON cannot represent losslessly (undefined, NaN, Infinity, bigint,
|
|
651
|
+
* function, symbol) rather than silently dropping it, because a dropped field would make
|
|
652
|
+
* two different schemas hash the same.
|
|
653
|
+
*/
|
|
654
|
+
declare function canonicalJson(value: unknown): string;
|
|
655
|
+
/** Full SHA-256 of `data` as 64 lowercase hex characters; strings are hashed as UTF-8. */
|
|
656
|
+
declare function sha256Hex(data: string | Uint8Array): string;
|
|
657
|
+
/** SHA-256 of the canonical encoding, truncated to `HASH_CHARS`. */
|
|
658
|
+
declare function contentHash(value: unknown): string;
|
|
659
|
+
/** Version tag folded into every activity and signal hash. Bump when the projection changes. */
|
|
660
|
+
declare const SCHEMA_HASH_VERSION = 1;
|
|
661
|
+
/** Keywords removed from every schema object before hashing, at any depth. */
|
|
662
|
+
declare const ANNOTATION_KEYWORDS: readonly string[];
|
|
663
|
+
/**
|
|
664
|
+
* Keywords whose value is a map from a user-chosen name to a schema. The names are opaque
|
|
665
|
+
* (a property may be called `default`), only the values are schemas.
|
|
666
|
+
*/
|
|
667
|
+
declare const NAMED_SCHEMA_MAPS: readonly string[];
|
|
668
|
+
/**
|
|
669
|
+
* Returns a copy of `schema` with every annotation keyword removed from every schema
|
|
670
|
+
* object in it. Arrays are walked (`anyOf`, `prefixItems`, …) in order; the entries of a
|
|
671
|
+
* name-keyed map (`properties`, `$defs`, …) keep their names and have their values
|
|
672
|
+
* projected; scalars pass through. The input is never mutated.
|
|
673
|
+
*/
|
|
674
|
+
declare function projectSchema(schema: Json): Json;
|
|
675
|
+
/** A reference to an environment variable, as {@link env} builds it. Resolved at load time. */
|
|
676
|
+
interface EnvRef {
|
|
677
|
+
/** Name of the environment variable. */
|
|
678
|
+
readonly __env: string;
|
|
679
|
+
/** When `true`, an unset or empty variable resolves to "absent" instead of failing the load. */
|
|
680
|
+
readonly optional?: boolean;
|
|
681
|
+
}
|
|
682
|
+
/** A literal value, or the name of the environment variable holding it. */
|
|
683
|
+
type Ref = string | EnvRef;
|
|
684
|
+
/**
|
|
685
|
+
* Refers to an environment variable by name so a secret never sits in `vlo.config.ts`.
|
|
686
|
+
*
|
|
687
|
+
* The value is read when the profile is loaded, not when `env` is called. An unset or empty
|
|
688
|
+
* variable fails the load with a message naming the variable, unless `optional` is `true`,
|
|
689
|
+
* in which case the field is simply absent.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```ts
|
|
693
|
+
* import { defineConfig, env } from "@oona/vlo";
|
|
694
|
+
*
|
|
695
|
+
* export default defineConfig({
|
|
696
|
+
* workflows: ["*.workflow.ts"],
|
|
697
|
+
* profiles: {
|
|
698
|
+
* prod: {
|
|
699
|
+
* journal: env("DATABASE_URL"),
|
|
700
|
+
* auth: { token: env("VLO_TOKEN"), pushSecret: env("VLO_PUSH_SECRET", { optional: true }) },
|
|
701
|
+
* },
|
|
702
|
+
* },
|
|
703
|
+
* });
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
declare function env(name: string, options?: {
|
|
707
|
+
optional?: boolean;
|
|
708
|
+
}): EnvRef;
|
|
709
|
+
/**
|
|
710
|
+
* How tasks on one queue reach their workers. A queue with neither `url` nor `mode` is
|
|
711
|
+
* served only by a worker in the same process.
|
|
712
|
+
*/
|
|
713
|
+
interface QueueProfile {
|
|
714
|
+
/** Endpoint the dispatcher pushes tasks to, payload included. */
|
|
715
|
+
url?: Ref;
|
|
716
|
+
/** HMAC secret shared with the worker behind `url`; required for an HTTP push. */
|
|
717
|
+
secret?: Ref;
|
|
718
|
+
/** `"push"` delivers to `url`; `"pull"` never pushes and lets workers long-poll the host instead. */
|
|
719
|
+
mode?: "push" | "pull";
|
|
720
|
+
}
|
|
721
|
+
/** Outbox dispatcher settings for a profile holding the `orchestrator` role. */
|
|
722
|
+
interface DispatcherProfile {
|
|
723
|
+
/** `manual` never arms the interval: something outside must call the tick route. */
|
|
724
|
+
mode?: "loop" | "manual";
|
|
725
|
+
/** Interval between dispatcher passes in `loop` mode, in milliseconds. Default `500`. */
|
|
726
|
+
tickMs?: number;
|
|
727
|
+
}
|
|
728
|
+
/** Platform `vlo deploy` renders templates for. */
|
|
729
|
+
type DeployTarget = "cloud-run" | "vercel";
|
|
730
|
+
/** What `vlo deploy` needs to write templates. Never a secret — only names and regions. */
|
|
731
|
+
interface DeployProfile {
|
|
732
|
+
/** Which set of templates to render. */
|
|
733
|
+
target: DeployTarget;
|
|
734
|
+
/** Cloud project id, where the target needs one. */
|
|
735
|
+
project?: Ref;
|
|
736
|
+
/** Region the service runs in. Default `europe-west4`. */
|
|
737
|
+
region?: Ref;
|
|
738
|
+
/**
|
|
739
|
+
* First segment of every generated resource name: `<namePrefix>-<env>-<service>`. Must
|
|
740
|
+
* equal the `prefix` of each entry in the Terraform `local.envs` the templates join.
|
|
741
|
+
* Default `vlo`.
|
|
742
|
+
*/
|
|
743
|
+
namePrefix?: Ref;
|
|
744
|
+
/** Component name inside the per-env prefix, e.g. `<namePrefix>-<env>-<service>`. Default `vlo`. */
|
|
745
|
+
service?: Ref;
|
|
746
|
+
/** Bucket for offloaded payloads. Defaults to the bucket named by a `gcs://` `blob` URL. */
|
|
747
|
+
bucket?: Ref;
|
|
748
|
+
/** Terraform envs this profile is deployed to. Default `["staging", "prod"]`. */
|
|
749
|
+
envs?: readonly string[];
|
|
750
|
+
/** Middle segment of the generated Secret Manager secret ids. Default `vlo`. */
|
|
751
|
+
secretName?: Ref;
|
|
752
|
+
/** Cron expression driving the tick route on serverless targets. Default every minute. */
|
|
753
|
+
cron?: Ref;
|
|
754
|
+
}
|
|
755
|
+
/** One environment's wiring: where state lives, how queues deliver, which roles run. */
|
|
756
|
+
interface Profile {
|
|
757
|
+
/** @deprecated Use `publicUrl`. Kept so existing configs keep loading. */
|
|
758
|
+
host?: Ref;
|
|
759
|
+
/** Base URL peers reach this host on. Fills `complete_url` on an outbound push. */
|
|
760
|
+
publicUrl?: Ref;
|
|
761
|
+
/** Journal URL: `sqlite://<path>` or a Postgres connection string. Required. */
|
|
762
|
+
journal: Ref;
|
|
763
|
+
/** Blob store URL for payloads over the inline limit: `file://<dir>` or `gcs://<bucket>/<prefix>`. Default `file://.vlo/blobs`. */
|
|
764
|
+
blob?: Ref;
|
|
765
|
+
/** Delivery settings per queue name; see {@link QueueProfile}. */
|
|
766
|
+
queues?: Record<string, QueueProfile>;
|
|
767
|
+
/** `token`: bearer for the control-plane routes. `pushSecret`: HMAC secret inbound pushes are verified with. */
|
|
768
|
+
auth?: {
|
|
769
|
+
token?: Ref;
|
|
770
|
+
pushSecret?: Ref;
|
|
771
|
+
};
|
|
772
|
+
/** Port `vlo serve` listens on. `--port` and `PORT` take precedence. */
|
|
773
|
+
port?: number;
|
|
774
|
+
/** Roles this process runs. Absent ⇒ orchestrator + api + every in-process worker. */
|
|
775
|
+
roles?: readonly Role[];
|
|
776
|
+
/** Outbox dispatcher settings; see {@link DispatcherProfile}. */
|
|
777
|
+
dispatcher?: DispatcherProfile;
|
|
778
|
+
/** Template inputs for `vlo deploy`; see {@link DeployProfile}. */
|
|
779
|
+
deploy?: DeployProfile;
|
|
780
|
+
}
|
|
781
|
+
/** The shape of `vlo.config.ts`'s default export; build it with {@link defineConfig}. */
|
|
782
|
+
interface VloConfig {
|
|
783
|
+
/** Globs, relative to the config file. Every matching module is imported. */
|
|
784
|
+
workflows: string | readonly string[];
|
|
785
|
+
/** Globs of modules exporting {@link defineWorker} results. */
|
|
786
|
+
workers?: string | readonly string[];
|
|
787
|
+
/** Optional: modules exporting `activity()` / `signal()` definitions to register. */
|
|
788
|
+
activities?: string | readonly string[];
|
|
789
|
+
/**
|
|
790
|
+
* Named environments; at least one is required. `vlo dev` picks `local` when present, else
|
|
791
|
+
* the only profile, unless `--profile` / `VLO_PROFILE` names one; `serve`, `doctor` and
|
|
792
|
+
* `deploy` always need a name.
|
|
793
|
+
*/
|
|
794
|
+
profiles: Record<string, Profile>;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Types and checks a `vlo.config.ts` and returns it unchanged for `export default`.
|
|
798
|
+
*
|
|
799
|
+
* Throws a `TypeError` when `profiles` is empty. Values wrapped with {@link env} are
|
|
800
|
+
* resolved later, when the CLI loads the profile.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* import { defineConfig, env } from "@oona/vlo";
|
|
805
|
+
*
|
|
806
|
+
* export default defineConfig({
|
|
807
|
+
* workflows: ["./workflows/*.workflow.ts"],
|
|
808
|
+
* workers: ["./workers/*.worker.ts"],
|
|
809
|
+
* profiles: {
|
|
810
|
+
* local: { journal: "sqlite://.vlo/dev.db", blob: "file://.vlo/blobs" },
|
|
811
|
+
* prod: {
|
|
812
|
+
* journal: env("DATABASE_URL"),
|
|
813
|
+
* auth: { token: env("VLO_TOKEN") },
|
|
814
|
+
* roles: ["orchestrator", "api"],
|
|
815
|
+
* queues: { media: { mode: "pull" } },
|
|
816
|
+
* dispatcher: { mode: "manual" },
|
|
817
|
+
* deploy: { target: "vercel", cron: "* * * * *" },
|
|
818
|
+
* },
|
|
819
|
+
* },
|
|
820
|
+
* });
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
823
|
+
declare function defineConfig(config: VloConfig): VloConfig;
|
|
824
|
+
export { DEFAULT_QUEUE as $, ErasedActivity as A, WaitForOptions as B, fanOutRuns as C, waitFor as D, step as E, OnTimeout as F, TaskOptions as G, AwaitHumanOptions as H, SeqState as I, humanTimeoutStepId as J, TimerOptions as K, SeqStep as L, FanOutRunsOptions as M, FanState as N, ChildResult as O, OnFailure as P, DEFAULT_LEASE_MS as Q, SequenceOptions as R, fanOut as S, sleep as T, AwaitSignalOptions as U, ActivityInputError as V, SpawnOptions as W, Activity as X, signalTimeoutStepId as Y, ActivityOptions as Z, sha256Hex as _, Profile as a, resultOf as b, VloConfig as c, ANNOTATION_KEYWORDS as d, DEFAULT_RETRY as et, NAMED_SCHEMA_MAPS as f, contentHash as g, canonicalJson as h, EnvRef as i, signal as it, FanOutOptions as j, ChildStatus as k, defineConfig as l, projectSchema as m, DeployTarget as n, SignalDef as nt, QueueProfile as o, SCHEMA_HASH_VERSION as p, cmd as q, DispatcherProfile as r, activity as rt, Ref as s, DeployProfile as t, RetryOptions as tt, env as u, fanOutResultsOf as v, sequence as w, signalOf as x, fanOutRunsResultsOf as y, StepOptions as z };
|