@oona/vlo 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +83 -2
- package/dist/agent.d.ts +151 -0
- package/dist/agent.js +445 -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 +95 -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
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@oona/vlo/host` — everything that touches durable state or the network.
|
|
3
|
+
*
|
|
4
|
+
* The authoring surface (`@oona/vlo`) has no dependency on any of this: a workflow compiles
|
|
5
|
+
* and unit-tests without a journal, a kernel or a port.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from "node:events";
|
|
8
|
+
import { $ as DeriveIdsOutput, A as HttpPushTransport, B as WorkerOptions, C as drainHost, D as TickCounts, E as DispatcherOptions, F as ActivityHandler, G as isTerminalRunStatus, H as findWorker, I as ActivityImpls, L as TaskContext, M as PushedTask, N as TaskTransport, O as FetchLike, P as BlobStore, R as UsageInput, S as DrainResult, T as DispatcherMode, U as withRetryInput, V as defineWorker, W as TERMINAL_RUN_STATUSES, Y as Workflow, _ as HandleTaskOptions, a as mergeDomains, at as PlanRetryInput, b as DEFAULT_DRAIN_MAX_MS, c as HostContext, ct as ReduceStepInput, d as SignalRegistration, et as HashAtSeq, f as TaskScheduled, g as InProcessTransport, h as InProcessTracker, i as defineDomain, it as KernelVersion, j as PushResult, k as HttpPushOptions, l as QueueConfig, lt as RefoldCheckOutput, m as InProcessOptions, n as DomainDef, nt as KernelError, o as ActivityRegistration, ot as PrepareEventInput, p as Validator, r as Registries, rt as KernelResult, s as AuthConfig, st as Prepared, t as Domain, tt as Kernel, u as Role, ut as RetryPlan, v as TaskReporter, w as Dispatcher, x as DrainOptions, y as handleTask, z as Worker } from "./domain-CJN6n_JD.js";
|
|
9
|
+
import { A as StepState, B as TaskUpdate, C as KernelState, E as Reduction, F as NewTask, I as NewTimer, L as RunPatch, M as Completion, N as Emit, O as RunStatus, P as NewSpawn, R as RunRef, S as Json, V as Transition, _ as Cause, a as NewRunRow, b as EventInput, c as RunRow, d as SignalWaitRow, f as StateRow, h as TimerRow, i as JournalTx, j as Usage, l as SchemaRow, m as TaskRow, n as Journal, o as NewSignalRow, p as TaskClaimFilter, r as JournalClosed, s as RunQuery, t as ApplyTransitionOptions, u as SignalRow, w as Kind, y as Envelope, z as SignalWait } from "./types-BLQQMmkc.js";
|
|
10
|
+
/** A fetch-style request handler: what `Host.fetch`, `handler()` and `listen()` all speak. */
|
|
11
|
+
type FetchHandler = (request: Request) => Promise<Response>;
|
|
12
|
+
/** `"api/vlo"`, `"/api/vlo/"` and `"/api/vlo"` all normalise to `"/api/vlo"`; `""` to none. */
|
|
13
|
+
export declare function normalizeBasePath(value: string | undefined): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Builds the `/v1` router for a context. Every {@link VloError} becomes a JSON error response
|
|
16
|
+
* with its status; anything else is a 500. Routes a role is not held for answer 404
|
|
17
|
+
* `role_not_served`. `createHost` calls this; only custom hosts need it directly.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createRouter(ctx: HostContext): FetchHandler;
|
|
20
|
+
/** A bound `node:http` server. */
|
|
21
|
+
interface Listening {
|
|
22
|
+
/** `http://<host>:<port>`, with the port actually bound. */
|
|
23
|
+
url: string;
|
|
24
|
+
/** The port actually bound; differs from the request when `0` was asked for. */
|
|
25
|
+
port: number;
|
|
26
|
+
/** Closes every open connection (SSE streams included) and stops listening. */
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Serves a fetch-style handler on `port` (`0` picks a free one) and `host` (default
|
|
31
|
+
* `127.0.0.1`). Rejects when the port cannot be bound. Response bodies are streamed, so an
|
|
32
|
+
* SSE response works without a framework.
|
|
33
|
+
*/
|
|
34
|
+
export declare function listen(handler: FetchHandler, port: number, host?: string): Promise<Listening>;
|
|
35
|
+
/** Blob store used when {@link CreateHostOptions.blob} is absent: a `file://` directory relative to the working directory. */
|
|
36
|
+
export declare const DEFAULT_BLOB_URL = "file://.vlo/blobs";
|
|
37
|
+
/** Port {@link serve} binds when `port` is absent. */
|
|
38
|
+
export declare const DEFAULT_PORT = 4100;
|
|
39
|
+
/** How often an open SSE stream re-reads the journal when `streamPollMs` is absent, in milliseconds. */
|
|
40
|
+
export declare const DEFAULT_STREAM_POLL_MS = 500;
|
|
41
|
+
/** How long `stop()` gives in-process handlers to report before the journal closes. */
|
|
42
|
+
export declare const SHUTDOWN_GRACE_MS = 5000;
|
|
43
|
+
/** What {@link createHost} needs: durable stores, the registries, and which roles this process plays. */
|
|
44
|
+
interface CreateHostOptions {
|
|
45
|
+
/** A `Journal`, or a URL the host opens (and closes on `stop`). */
|
|
46
|
+
journal: Journal | string;
|
|
47
|
+
/** A `BlobStore`, or a `file://` / `gcs://` URL to open. Default {@link DEFAULT_BLOB_URL}. */
|
|
48
|
+
blob?: BlobStore | string;
|
|
49
|
+
/** Workflows this host can run, by name. Starting an unregistered one is refused. Optional when `domains` supplies them. */
|
|
50
|
+
workflows?: readonly Workflow[];
|
|
51
|
+
/** Domains from `defineDomain`; their registries are flattened onto the four arrays below. */
|
|
52
|
+
domains?: readonly Domain[];
|
|
53
|
+
/**
|
|
54
|
+
* Activities whose output schema the host enforces before folding a result. Unregistered
|
|
55
|
+
* activities still run; their output is folded as opaque JSON.
|
|
56
|
+
*/
|
|
57
|
+
activities?: readonly ActivityRegistration[];
|
|
58
|
+
/** Workers run in this process. Each adds a `worker:<queue>` role when `roles` is absent. */
|
|
59
|
+
workers?: readonly Worker[];
|
|
60
|
+
/** Signals whose payload the host validates before delivery. Unregistered signals pass through as-is. */
|
|
61
|
+
signals?: readonly SignalRegistration[];
|
|
62
|
+
/** Roles this process holds. Default: `orchestrator`, `api`, plus one `worker:<queue>` per queue of every worker. */
|
|
63
|
+
roles?: readonly Role[];
|
|
64
|
+
/** Per-queue delivery: a push URL and secret, or `mode: "pull"`. Queues not listed are in-process only. */
|
|
65
|
+
queues?: Record<string, QueueConfig>;
|
|
66
|
+
/** Credentials for the control plane, inbound pushes, callbacks and signed links. Absent ⇒ open host. */
|
|
67
|
+
auth?: AuthConfig;
|
|
68
|
+
/** Namespace new runs are created in and `listRuns` filters by. Default `"default"`. */
|
|
69
|
+
namespace?: string;
|
|
70
|
+
/** Base URL peers reach this host on; fills `complete_url` on an outbound push. */
|
|
71
|
+
publicUrl?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Path prefix this host is mounted under, e.g. `"/api/vlo"` for a Next route file at
|
|
74
|
+
* `app/api/vlo/[[...path]]/route.ts`. The router strips it before matching and every URL
|
|
75
|
+
* built from `publicUrl` carries it.
|
|
76
|
+
*/
|
|
77
|
+
basePath?: string;
|
|
78
|
+
/** How often an open SSE stream looks for new journal events. Default 500 ms. */
|
|
79
|
+
streamPollMs?: number;
|
|
80
|
+
/** Clock for every journaled timestamp, in epoch milliseconds. Default `Date.now`. */
|
|
81
|
+
now?: () => number;
|
|
82
|
+
/** Injected for tests; otherwise the wasm kernel is loaded on `start`. */
|
|
83
|
+
kernel?: Kernel;
|
|
84
|
+
/** Outbox dispatcher tuning. Only read when this host holds the `orchestrator` role. */
|
|
85
|
+
dispatcher?: DispatcherOptions;
|
|
86
|
+
}
|
|
87
|
+
/** A running (or startable) host: the fetch handler plus the controls a process owner needs. */
|
|
88
|
+
interface Host {
|
|
89
|
+
/** The HTTP surface as a `(Request) => Response`. Starts the host on first call. */
|
|
90
|
+
readonly fetch: FetchHandler;
|
|
91
|
+
/** Loads the kernel, migrates the journal and starts the dispatcher. Idempotent. */
|
|
92
|
+
start(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Stops the dispatcher, waits up to {@link SHUTDOWN_GRACE_MS} for in-process handlers, then
|
|
95
|
+
* closes the journal if the host opened it from a URL. Idempotent.
|
|
96
|
+
*/
|
|
97
|
+
stop(): Promise<void>;
|
|
98
|
+
/** One dispatcher pass. Rejects on a host without the `orchestrator` role. */
|
|
99
|
+
tick(): Promise<TickCounts>;
|
|
100
|
+
/**
|
|
101
|
+
* Ticks until the outbox is idle or `maxMs` (default 25 s) runs out. Concurrent callers
|
|
102
|
+
* share one drain. Rejects on a host without the `orchestrator` role.
|
|
103
|
+
*/
|
|
104
|
+
drain(options?: DrainOptions): Promise<DrainResult>;
|
|
105
|
+
/** In-memory side channel: `emit` (from `cmd.emit`), `warning` (dispatcher) and `task_scheduled`. */
|
|
106
|
+
readonly events: EventEmitter;
|
|
107
|
+
/** The journal this host reads and writes. */
|
|
108
|
+
readonly journal: Journal;
|
|
109
|
+
/** Roles this process holds. */
|
|
110
|
+
readonly roles: ReadonlySet<Role>;
|
|
111
|
+
/** Base URL peers reach this host on. Settable, so {@link serve} can fill it after binding a port. */
|
|
112
|
+
publicUrl: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds a host without binding a port or starting it. Nothing is loaded or migrated until
|
|
116
|
+
* `start()` (or the first `fetch`). A `journal` given as a URL is opened here and closed by
|
|
117
|
+
* `stop()`; a `Journal` instance is left to its owner.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { createClient, createHost, defineWorker } from "@oona/vlo/host";
|
|
122
|
+
*
|
|
123
|
+
* const host = createHost({
|
|
124
|
+
* journal: "sqlite://./.vlo/dev.db",
|
|
125
|
+
* workflows: [pipeline],
|
|
126
|
+
* activities: [render],
|
|
127
|
+
* workers: [defineWorker({ "pull.render": (input: { clip: string }) => ({ rendered: input.clip }) })],
|
|
128
|
+
* });
|
|
129
|
+
* await host.start();
|
|
130
|
+
*
|
|
131
|
+
* const client = createClient({ fetch: host.fetch });
|
|
132
|
+
* const run = await client.start(pipeline, { clip: "reel" });
|
|
133
|
+
* await client.waitFor(run.run_id, "completed");
|
|
134
|
+
* await host.stop();
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function createHost(options: CreateHostOptions): Host;
|
|
138
|
+
/** {@link CreateHostOptions} plus where to listen. */
|
|
139
|
+
interface ServeOptions extends CreateHostOptions {
|
|
140
|
+
/** TCP port to bind. Default {@link DEFAULT_PORT}; `0` picks a free one. */
|
|
141
|
+
port?: number;
|
|
142
|
+
/** Interface to bind. Default `127.0.0.1`. */
|
|
143
|
+
hostname?: string;
|
|
144
|
+
}
|
|
145
|
+
/** A bound server: the listener's `url`, `port` and `close()`, plus the host behind it. */
|
|
146
|
+
interface ServeResult extends Listening {
|
|
147
|
+
/** The host serving requests. `close()` on the result stops it too. */
|
|
148
|
+
host: Host;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Binds a port, tells the host its own URL, then starts it. `publicUrl` is set to the
|
|
152
|
+
* listener's URL unless the options give one, so pushed tasks carry a working `complete_url`.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { serve } from "@oona/vlo/host";
|
|
157
|
+
*
|
|
158
|
+
* const server = await serve({
|
|
159
|
+
* journal: "postgres://user:pass@localhost/app",
|
|
160
|
+
* workflows: [pipeline],
|
|
161
|
+
* activities: [render],
|
|
162
|
+
* auth: { token: "control-plane-token" },
|
|
163
|
+
* port: 4100,
|
|
164
|
+
* });
|
|
165
|
+
* console.log(server.url); // http://127.0.0.1:4100
|
|
166
|
+
* await server.close();
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function serve(options: ServeOptions): Promise<ServeResult>;
|
|
170
|
+
/**
|
|
171
|
+
* Next route file: `export const { GET, POST } = handler({ … })`. The host is created on the
|
|
172
|
+
* first request and shared by every request after, so a serverless function pays for the
|
|
173
|
+
* kernel load once per instance. Pair it with `dispatcher: { mode: "manual" }` and a cron on
|
|
174
|
+
* `POST /v1/timers/tick`.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* // app/api/vlo/[[...path]]/route.ts
|
|
179
|
+
* import { handler } from "@oona/vlo/host";
|
|
180
|
+
*
|
|
181
|
+
* export const { GET, POST } = handler({
|
|
182
|
+
* journal: process.env.DATABASE_URL ?? "sqlite://./.vlo/dev.db",
|
|
183
|
+
* workflows: [pipeline],
|
|
184
|
+
* activities: [render],
|
|
185
|
+
* basePath: "/api/vlo",
|
|
186
|
+
* dispatcher: { mode: "manual" },
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export declare function handler(options: CreateHostOptions): {
|
|
191
|
+
GET: FetchHandler;
|
|
192
|
+
POST: FetchHandler;
|
|
193
|
+
};
|
|
194
|
+
/** Reports straight into this host's journal via {@link completeTask}, {@link failTask} and {@link heartbeatTask}. */
|
|
195
|
+
export declare function localReporter(ctx: HostContext): TaskReporter;
|
|
196
|
+
/**
|
|
197
|
+
* Reports over HTTP to the host that owns the task. `completeUrl` is the task's base URL
|
|
198
|
+
* (`…/v1/tasks/{id}`); the three verbs hang off it. Each call has a 10 s timeout and throws
|
|
199
|
+
* a plain `Error` on a non-2xx answer, which for `heartbeat` is how a lost lease surfaces.
|
|
200
|
+
*/
|
|
201
|
+
export declare function remoteReporter(completeUrl: string, token: string | undefined, fetchImpl?: FetchLike): TaskReporter;
|
|
202
|
+
interface PullWorkerOptions {
|
|
203
|
+
/** The host's base URL, e.g. `https://vlo.example.com`. */
|
|
204
|
+
baseUrl: string;
|
|
205
|
+
/** Control-plane bearer token; also sent when reporting results. */
|
|
206
|
+
token?: string;
|
|
207
|
+
/** The activity implementations to run. */
|
|
208
|
+
worker: Worker;
|
|
209
|
+
/** Queues to poll, round-robin. Defaults to the queues the worker declares. */
|
|
210
|
+
queues?: readonly string[];
|
|
211
|
+
/** How long the host may hold a poll open with no work. Capped at 25 s by the host. */
|
|
212
|
+
waitMs?: number;
|
|
213
|
+
/** Tasks run at once. Default 4; at most 10 are requested per poll. */
|
|
214
|
+
concurrency?: number;
|
|
215
|
+
/** Stops polling when aborted; in-flight handlers see it on `ctx.signal`. */
|
|
216
|
+
signal?: AbortSignal;
|
|
217
|
+
/** Sent as `worker_id` and recorded on the task. Default `vlo-pull-<8 hex>`. */
|
|
218
|
+
workerId?: string;
|
|
219
|
+
/** `fetch` implementation. Default `globalThis.fetch`. */
|
|
220
|
+
fetch?: FetchLike;
|
|
221
|
+
/** Called for a poll that failed; the loop backs off and carries on. */
|
|
222
|
+
onError?: (error: unknown) => void;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Runs until `signal` aborts, then resolves once the tasks in flight have reported. Throws
|
|
226
|
+
* a `TypeError` when there is no queue to poll. A failed poll goes to `onError` and the loop
|
|
227
|
+
* retries after 1 s. Runs on the worker side; the host only needs the `api` role.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* import { defineWorker, runPullWorker } from "@oona/vlo/host";
|
|
232
|
+
*
|
|
233
|
+
* const abort = new AbortController();
|
|
234
|
+
* const loop = runPullWorker({
|
|
235
|
+
* baseUrl: "https://vlo.example.com",
|
|
236
|
+
* token: "control-plane-token",
|
|
237
|
+
* worker: defineWorker(
|
|
238
|
+
* { "pull.render": (input: { clip: string }) => ({ rendered: input.clip.toUpperCase() }) },
|
|
239
|
+
* { queues: ["media"] },
|
|
240
|
+
* ),
|
|
241
|
+
* waitMs: 5_000,
|
|
242
|
+
* signal: abort.signal,
|
|
243
|
+
* onError: (error) => console.error(error),
|
|
244
|
+
* });
|
|
245
|
+
* process.once("SIGTERM", () => abort.abort());
|
|
246
|
+
* await loop;
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export declare function runPullWorker(options: PullWorkerOptions): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Push signatures. Same shape as the repo's Zernio webhook verifier: HMAC-SHA256, hex,
|
|
252
|
+
* compared timing-safe — but the signed string binds the task and a timestamp as well as
|
|
253
|
+
* the body, so a captured push cannot be replayed onto a different attempt or an hour later.
|
|
254
|
+
*/
|
|
255
|
+
/** Header carrying the pushed task's id. */
|
|
256
|
+
export declare const TASK_ID_HEADER = "vlo-task-id";
|
|
257
|
+
/** Header carrying the attempt number. */
|
|
258
|
+
export declare const ATTEMPT_HEADER = "vlo-attempt";
|
|
259
|
+
/** Header carrying the signing time, epoch milliseconds. */
|
|
260
|
+
export declare const TIMESTAMP_HEADER = "vlo-timestamp";
|
|
261
|
+
/** Header carrying the signature, `v1=<hex>`. */
|
|
262
|
+
export declare const SIGNATURE_HEADER = "vlo-signature";
|
|
263
|
+
/**
|
|
264
|
+
* Signs a push: `v1=` + HMAC-SHA256 over `taskId.attempt.tsMs.sha256(body)`, hex. The
|
|
265
|
+
* dispatcher's HTTP transport calls this; a custom transport signs the same way.
|
|
266
|
+
*/
|
|
267
|
+
export declare function signPush(secret: string, taskId: string, attempt: number, tsMs: number, body: string): string;
|
|
268
|
+
/** Anything with `Headers.get` semantics. */
|
|
269
|
+
interface HeaderSource {
|
|
270
|
+
/** The header's value, or null when absent. */
|
|
271
|
+
get(name: string): string | null;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* True when the `vlo-*` headers sign `rawBody` with `secret` and the timestamp is within
|
|
275
|
+
* 5 minutes of `nowMs` (default `Date.now()`). Missing or malformed headers are false, never
|
|
276
|
+
* thrown; the comparison is timing-safe.
|
|
277
|
+
*/
|
|
278
|
+
export declare function verifySignature(secret: string, headers: HeaderSource, rawBody: string, nowMs?: number): boolean;
|
|
279
|
+
/** What a task report resolved to. */
|
|
280
|
+
interface TaskResult {
|
|
281
|
+
/** True when the attempt had already been settled, so nothing was written. */
|
|
282
|
+
duplicate: boolean;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Records an attempt's output. Validated against the registered activity's output schema
|
|
286
|
+
* when there is one; a violation fails the attempt with `schema_violation` and no retry.
|
|
287
|
+
* The first terminal result for an attempt wins; later ones return `duplicate: true`.
|
|
288
|
+
*
|
|
289
|
+
* @throws {@link TaskNotFound} when no task has that id.
|
|
290
|
+
*/
|
|
291
|
+
export declare function completeTask(ctx: HostContext, taskId: string, attempt: number, output: unknown, usage?: Usage): Promise<TaskResult>;
|
|
292
|
+
/**
|
|
293
|
+
* Records an attempt's failure: a `retrying` event when `retryable` and the kernel's retry
|
|
294
|
+
* plan allows another attempt, otherwise a `failed` event. The first terminal result for an
|
|
295
|
+
* attempt wins; later ones return `duplicate: true`.
|
|
296
|
+
*
|
|
297
|
+
* `cause` names who lost the attempt: the handler by default, the reaper on a dead lease.
|
|
298
|
+
* `usage` is banked whichever way the attempt ends — tokens burned before a throw are spent.
|
|
299
|
+
*
|
|
300
|
+
* @throws {@link TaskNotFound} when no task has that id.
|
|
301
|
+
*/
|
|
302
|
+
export declare function failTask(ctx: HostContext, taskId: string, attempt: number, error: string, retryable?: boolean, cause?: Cause, usage?: Usage): Promise<TaskResult>;
|
|
303
|
+
/**
|
|
304
|
+
* Extends the attempt's lease by the task's `lease_ttl_ms` from now.
|
|
305
|
+
*
|
|
306
|
+
* @throws {@link TaskNotFound} when no task has that id.
|
|
307
|
+
* @throws {@link LeaseLost} when the task is not running at that attempt any more.
|
|
308
|
+
*/
|
|
309
|
+
export declare function heartbeatTask(ctx: HostContext, taskId: string, attempt: number): Promise<void>;
|
|
310
|
+
/** What one `applyEvent` call did. */
|
|
311
|
+
interface TxOutcome {
|
|
312
|
+
/** False when the source decided there was nothing to submit. */
|
|
313
|
+
applied: boolean;
|
|
314
|
+
/** True for an at-least-once redelivery the kernel has already folded. */
|
|
315
|
+
duplicate: boolean;
|
|
316
|
+
/** The run row as it was locked, before the transition. */
|
|
317
|
+
run: RunRow;
|
|
318
|
+
/** The kernel's write-set. Present only when `applied` is true. */
|
|
319
|
+
transition?: Transition;
|
|
320
|
+
/** Buffered signals that matched a wait this transition opened; applied after commit. */
|
|
321
|
+
followUps: EventInput[];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* The event to submit. A function form runs inside the transaction with the run already
|
|
325
|
+
* locked, so it can read and write journal rows before deciding — returning `null` commits
|
|
326
|
+
* whatever it did without folding anything.
|
|
327
|
+
*/
|
|
328
|
+
type EventSource = EventInput | ((tx: JournalTx, run: RunRow) => Promise<EventInput | null>);
|
|
329
|
+
/** Extra journal work to commit atomically with the transition. */
|
|
330
|
+
type AfterApply = (tx: JournalTx, outcome: TxOutcome) => Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* Submits one event. Owns its transaction, recovers a reducer throw or a divergence into
|
|
333
|
+
* the matching marker, then runs the post-commit work (buffered signals, emits, kick).
|
|
334
|
+
*
|
|
335
|
+
* A `ReducerFailed` is swallowed: the run is failed with an `app_error` marker and that
|
|
336
|
+
* outcome is returned. A `Nondeterminism` is recorded as a marker and then rethrown.
|
|
337
|
+
*
|
|
338
|
+
* @throws {@link RunNotFound} when no run has that id.
|
|
339
|
+
* @throws {@link RunTerminal} when the run ended and the event is not a task result or a closing marker.
|
|
340
|
+
* @throws {@link WorkflowRejected} when the run's workflow is not registered on this host.
|
|
341
|
+
* @throws {@link IllegalEvent} when the kernel refuses the event for a reason other than a duplicate.
|
|
342
|
+
* @throws {@link Nondeterminism} after journaling the divergence.
|
|
343
|
+
*/
|
|
344
|
+
export declare function applyEvent(ctx: HostContext, runId: string, source: EventSource, after?: AfterApply): Promise<TxOutcome>;
|
|
345
|
+
/** The checkpoint a fold starts from. Both fields are absent before the `started` event. */
|
|
346
|
+
interface FoldState {
|
|
347
|
+
/** Kernel-owned state at the checkpoint. */
|
|
348
|
+
kernelState?: KernelState;
|
|
349
|
+
/** User state at the checkpoint, byte-exact JSON text. */
|
|
350
|
+
state?: string;
|
|
351
|
+
}
|
|
352
|
+
/** A checkpoint rebuilt from the journal by {@link rebuildCheckpoint}. */
|
|
353
|
+
interface Rebuilt {
|
|
354
|
+
/** Kernel-owned state after the last input event. */
|
|
355
|
+
kernelState: KernelState;
|
|
356
|
+
/** User state after the last input event, byte-exact JSON text. */
|
|
357
|
+
state: string;
|
|
358
|
+
/** Hash of the pair above, equal to the last journaled `state_hash`. */
|
|
359
|
+
stateHash: string;
|
|
360
|
+
/** Seq of the last event folded. */
|
|
361
|
+
seq: number;
|
|
362
|
+
/** Run status after the last event folded. */
|
|
363
|
+
status: RunStatus;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* One event → one write-set. The reducer runs here and nowhere else. Pure: nothing is
|
|
367
|
+
* journaled, the caller applies the returned transition.
|
|
368
|
+
*
|
|
369
|
+
* @throws {@link ReducerFailed} when the workflow's reducer throws; carries the trigger event.
|
|
370
|
+
* @throws {@link IllegalEvent} when the kernel refuses to prepare or reduce the event.
|
|
371
|
+
*/
|
|
372
|
+
export declare function foldEvent(ctx: HostContext, workflow: Workflow, run: RunRef, at: FoldState, event: EventInput): Transition;
|
|
373
|
+
/**
|
|
374
|
+
* Replays every input event in the journal. Kernel outputs (scheduled tasks, signal waits,
|
|
375
|
+
* the `complete` marker) are recomputed, never re-fed.
|
|
376
|
+
*
|
|
377
|
+
* @throws {@link Nondeterminism} at the first event whose replayed `seq` or `state_hash`
|
|
378
|
+
* differs from the journaled one, or when `events` holds nothing foldable.
|
|
379
|
+
*/
|
|
380
|
+
export declare function rebuildCheckpoint(ctx: HostContext, workflow: Workflow, run: RunRow, events: readonly Envelope[]): Rebuilt;
|
|
381
|
+
/** A run as the API returns it: the row minus internals, with the output inlined. */
|
|
382
|
+
interface RunView {
|
|
383
|
+
/** The run's id. */
|
|
384
|
+
run_id: string;
|
|
385
|
+
/** Workflow name. */
|
|
386
|
+
workflow: string;
|
|
387
|
+
/** Current status. */
|
|
388
|
+
status: RunStatus;
|
|
389
|
+
/** Seq of the last journaled event. */
|
|
390
|
+
last_seq: number;
|
|
391
|
+
/** Caller-supplied search attributes given at start. */
|
|
392
|
+
search: Record<string, Json>;
|
|
393
|
+
/** When the row was created, epoch milliseconds. */
|
|
394
|
+
created_at_ms: number;
|
|
395
|
+
/** When the row last changed, epoch milliseconds. */
|
|
396
|
+
updated_at_ms: number;
|
|
397
|
+
/** When the `started` event was folded, epoch milliseconds. */
|
|
398
|
+
started_at_ms?: number;
|
|
399
|
+
/** When the run reached a terminal status, epoch milliseconds. */
|
|
400
|
+
closed_at_ms?: number;
|
|
401
|
+
/** The parent run, for a spawned child. */
|
|
402
|
+
parent_run_id?: string;
|
|
403
|
+
/** The run this one continued from, when it was started by a `continue_as_new`. */
|
|
404
|
+
continued_from?: string;
|
|
405
|
+
/** The successor this run handed its input to; set once the run is `continued`. */
|
|
406
|
+
continued_to?: string;
|
|
407
|
+
/** Completion output, read back from the blob store when it was offloaded. */
|
|
408
|
+
output?: Json;
|
|
409
|
+
/** Why the run failed: the `error` of its closing marker. Present only when `status` is `failed`. */
|
|
410
|
+
error?: string;
|
|
411
|
+
/** The closing marker's cause (`app_error` or `nondeterminism_detected`). Present with `error`. */
|
|
412
|
+
cause?: Cause;
|
|
413
|
+
}
|
|
414
|
+
/** What {@link startRun} needs. */
|
|
415
|
+
interface StartRunInput {
|
|
416
|
+
/** Name of a workflow registered on this host. */
|
|
417
|
+
workflow: string;
|
|
418
|
+
/** Start input, journaled on the `started` event. `undefined` is stored as `null`. */
|
|
419
|
+
input: Json;
|
|
420
|
+
/** Caller-chosen id. Default `run_<32 hex>`. Creating an existing id is a no-op. */
|
|
421
|
+
runId?: string;
|
|
422
|
+
/** Search attributes returned on the view and stored on the row. */
|
|
423
|
+
search?: Record<string, Json>;
|
|
424
|
+
/** Namespace to create the run in. Default: the host's. */
|
|
425
|
+
namespace?: string;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Writes a `created` run row and kicks the dispatcher; the `started` event is folded by the
|
|
429
|
+
* outbox. Idempotent on `runId`. Runs on a host with the `api` role.
|
|
430
|
+
*
|
|
431
|
+
* @throws {@link WorkflowRejected} when the workflow is not registered.
|
|
432
|
+
*/
|
|
433
|
+
export declare function startRun(ctx: HostContext, opts: StartRunInput): Promise<{
|
|
434
|
+
run_id: string;
|
|
435
|
+
}>;
|
|
436
|
+
/** What {@link signalRun} returns. */
|
|
437
|
+
interface SignalResult$1 {
|
|
438
|
+
/** The stored signal's id, `sig_<32 hex>`. */
|
|
439
|
+
signal_id: string;
|
|
440
|
+
/**
|
|
441
|
+
* True when an open wait folded the signal into the run. False in two cases: nothing was
|
|
442
|
+
* waiting, so the signal is buffered until a wait with that name opens; or the wait it
|
|
443
|
+
* matched had already closed — its timeout fired first, or the run has ended — a late
|
|
444
|
+
* signal. A late signal is recorded against the closed step, never folded, never buffered,
|
|
445
|
+
* and the stale wait row is dropped.
|
|
446
|
+
*/
|
|
447
|
+
delivered: boolean;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Stores a signal and, when the run is waiting on that name, delivers it in the same
|
|
451
|
+
* transaction. Validated against the registered signal schema when there is one. Never
|
|
452
|
+
* answers 409 for an ended run: the signal is stored and reported as not delivered.
|
|
453
|
+
*
|
|
454
|
+
* @throws {@link BadRequest} when the payload fails the schema.
|
|
455
|
+
* @throws {@link RunNotFound} when no run has that id.
|
|
456
|
+
*/
|
|
457
|
+
export declare function signalRun(ctx: HostContext, runId: string, name: string, payload: Json): Promise<SignalResult$1>;
|
|
458
|
+
/**
|
|
459
|
+
* Folds a `cancel` marker and returns the run. Cancelling an ended run is a no-op that
|
|
460
|
+
* still returns the view.
|
|
461
|
+
*
|
|
462
|
+
* @throws {@link RunNotFound} when no run has that id.
|
|
463
|
+
*/
|
|
464
|
+
export declare function cancelRun(ctx: HostContext, runId: string): Promise<RunView>;
|
|
465
|
+
/**
|
|
466
|
+
* Reads one run, inlining an offloaded output.
|
|
467
|
+
*
|
|
468
|
+
* @throws {@link RunNotFound} when no run has that id.
|
|
469
|
+
*/
|
|
470
|
+
export declare function getRunView(ctx: HostContext, runId: string): Promise<RunView>;
|
|
471
|
+
/** Lists runs in the host's namespace unless `query.namespace` says otherwise. */
|
|
472
|
+
export declare function listRuns(ctx: HostContext, query: RunQuery): Promise<RunView[]>;
|
|
473
|
+
/** Journaled events with `seq > sinceSeq`, ascending. Empty for an unknown run. */
|
|
474
|
+
export declare function readRunEvents(ctx: HostContext, runId: string, sinceSeq: number): Promise<Envelope[]>;
|
|
475
|
+
/** How long a minted link stays valid when the request gives no `expires_in_ms`: 7 days. */
|
|
476
|
+
export declare const DEFAULT_LINK_TTL_MS: number;
|
|
477
|
+
/** What a link token binds: one run, one signal, one deadline. */
|
|
478
|
+
interface SignalLinkClaims {
|
|
479
|
+
/** The run the signal is delivered to. */
|
|
480
|
+
runId: string;
|
|
481
|
+
/** The signal's name. */
|
|
482
|
+
name: string;
|
|
483
|
+
/** Epoch milliseconds after which the token is refused. Floored to an integer when signed. */
|
|
484
|
+
expiresAtMs: number;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* The secret signed links are minted with. Falls back to the control-plane token and then
|
|
488
|
+
* the push secret so a single-secret deployment gets links for free; `undefined` disables
|
|
489
|
+
* them rather than signing with an empty key.
|
|
490
|
+
*/
|
|
491
|
+
export declare function linkSecret(auth: AuthConfig): string | undefined;
|
|
492
|
+
/**
|
|
493
|
+
* Mints the token for a link: `v1.<expiresAtMs>.<hmac-sha256 hex>`. The host's
|
|
494
|
+
* `POST /v1/runs/{id}/links/{name}` route does this for you; call it directly to mint
|
|
495
|
+
* links out of band with the same secret ({@link linkSecret}).
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* const token = signSignalLink(secret, {
|
|
500
|
+
* runId: "run_1",
|
|
501
|
+
* name: "approve",
|
|
502
|
+
* expiresAtMs: Date.now() + DEFAULT_LINK_TTL_MS,
|
|
503
|
+
* });
|
|
504
|
+
* verifySignalLink(secret, token, "run_1", "approve", Date.now()); // true
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
export declare function signSignalLink(secret: string, link: SignalLinkClaims): string;
|
|
508
|
+
/**
|
|
509
|
+
* True when `token` was signed with `secret` for exactly this `(runId, name)` and has not
|
|
510
|
+
* expired at `nowMs`. Malformed tokens are false, never thrown; the comparison is timing-safe.
|
|
511
|
+
*/
|
|
512
|
+
export declare function verifySignalLink(secret: string, token: string, runId: string, name: string, nowMs: number): boolean;
|
|
513
|
+
/**
|
|
514
|
+
* Base of every error the host maps to an HTTP response. The router turns one into
|
|
515
|
+
* `{ error: { code, message } }` with `status`; anything else is a 500 `internal`.
|
|
516
|
+
*/
|
|
517
|
+
export declare class VloError extends Error {
|
|
518
|
+
/** HTTP status the router answers with. */
|
|
519
|
+
readonly status: number;
|
|
520
|
+
/** Stable machine-readable code, e.g. `run_not_found`. */
|
|
521
|
+
readonly code: string;
|
|
522
|
+
/** `name` is set to the concrete subclass name. */
|
|
523
|
+
constructor(code: string, message: string, status: number);
|
|
524
|
+
}
|
|
525
|
+
/** No run with that id. `run_not_found`, 404. */
|
|
526
|
+
export declare class RunNotFound extends VloError {
|
|
527
|
+
readonly runId: string;
|
|
528
|
+
/** @param runId The id that was looked up; kept on the error. */
|
|
529
|
+
constructor(runId: string);
|
|
530
|
+
}
|
|
531
|
+
/** No task with that id. `task_not_found`, 404. */
|
|
532
|
+
export declare class TaskNotFound extends VloError {
|
|
533
|
+
readonly taskId: string;
|
|
534
|
+
/** @param taskId The id that was looked up; kept on the error. */
|
|
535
|
+
constructor(taskId: string);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The run already ended, so a non-task event (a signal, say) cannot be applied.
|
|
539
|
+
* `run_terminal`, 409. A late task result on an ended run is a duplicate, not this.
|
|
540
|
+
*/
|
|
541
|
+
export declare class RunTerminal extends VloError {
|
|
542
|
+
/** `status` is the terminal status the run is in. */
|
|
543
|
+
constructor(runId: string, status: string);
|
|
544
|
+
}
|
|
545
|
+
/** The kernel refused the event: a duplicate, a stale attempt or an illegal transition. */
|
|
546
|
+
export declare class IllegalEvent extends VloError {
|
|
547
|
+
/** The kernel's refusal, verbatim. Its `code` becomes this error's `code`. */
|
|
548
|
+
readonly kernelError: KernelError;
|
|
549
|
+
/** Code is the kernel's (`unknown_step`, `bad_seq`, `illegal_transition`, …), status 409. */
|
|
550
|
+
constructor(error: KernelError);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The checkpoint or the re-fold disagreed with the journal. The run is failed first: the
|
|
554
|
+
* `nondeterminism` marker it records carries `cause: "nondeterminism_detected"`, which is the
|
|
555
|
+
* kernel's `Cause` value and stays as it is. This error's own code is `refold_mismatch`.
|
|
556
|
+
*/
|
|
557
|
+
export declare class Nondeterminism extends VloError {
|
|
558
|
+
/** The run that diverged. */
|
|
559
|
+
readonly runId: string;
|
|
560
|
+
/** The first journal seq the replay disagreed at; 0 when the journal holds nothing foldable. */
|
|
561
|
+
readonly seq: number;
|
|
562
|
+
/** `refold_mismatch`, 409. */
|
|
563
|
+
constructor(
|
|
564
|
+
/** The run that diverged. */
|
|
565
|
+
runId: string,
|
|
566
|
+
/** The first journal seq the replay disagreed at; 0 when the journal holds nothing foldable. */
|
|
567
|
+
seq: number, detail: string);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* The reducer threw, or the host could not honour what it asked for. `applyEvent` swallows
|
|
571
|
+
* this and records a `fail` marker with `cause: "app_error"` (the kernel's `Cause` value; this
|
|
572
|
+
* error's own code is `reducer_failed`). Also raised when a `spawn` or `continue_as_new`
|
|
573
|
+
* names a workflow this host has not registered.
|
|
574
|
+
*/
|
|
575
|
+
export declare class ReducerFailed extends VloError {
|
|
576
|
+
/** The run whose reducer threw. */
|
|
577
|
+
readonly runId: string;
|
|
578
|
+
/** The event being folded when the reducer threw; journaled on the `fail` marker. */
|
|
579
|
+
readonly trigger?: EventInput | undefined;
|
|
580
|
+
/** The reducer's own message, without the folding context; journaled as the `fail` marker's `error`. */
|
|
581
|
+
readonly reason: string;
|
|
582
|
+
/** `reducer_failed`, 409. Callers of `applyEvent` never see it; the run is failed instead. */
|
|
583
|
+
constructor(
|
|
584
|
+
/** The run whose reducer threw. */
|
|
585
|
+
runId: string, message: string,
|
|
586
|
+
/** The event being folded when the reducer threw; journaled on the `fail` marker. */
|
|
587
|
+
trigger?: EventInput | undefined,
|
|
588
|
+
/** Default: `message`. */
|
|
589
|
+
reason?: string);
|
|
590
|
+
}
|
|
591
|
+
/** The host was asked to run a workflow it does not have registered. */
|
|
592
|
+
export declare class WorkflowRejected extends VloError {
|
|
593
|
+
/** `unknown_workflow`, 400. */
|
|
594
|
+
constructor(name: string);
|
|
595
|
+
}
|
|
596
|
+
/** Bearer token or push signature missing or wrong. `unauthorized`, 401. */
|
|
597
|
+
export declare class Unauthorized extends VloError {
|
|
598
|
+
/** Message defaults to `missing or invalid credentials`. */
|
|
599
|
+
constructor(message?: string);
|
|
600
|
+
}
|
|
601
|
+
/** Malformed body, query or signal payload. `bad_request`, 400. */
|
|
602
|
+
export declare class BadRequest extends VloError {
|
|
603
|
+
/** `bad_request`, 400. */
|
|
604
|
+
constructor(message: string);
|
|
605
|
+
}
|
|
606
|
+
/** The worker's lease is gone: stop working, someone else owns the attempt. */
|
|
607
|
+
export declare class LeaseLost extends VloError {
|
|
608
|
+
/** `lease_lost`, 410. */
|
|
609
|
+
constructor(taskId: string, attempt: number);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Loads the wasm kernel once per process and returns the same instance afterwards. Looks for
|
|
613
|
+
* `vlo_kernel_bg.wasm` in the package's `wasm/` directory, or at `VLO_KERNEL_WASM`. Rejects
|
|
614
|
+
* when the bytes are missing or the kernel speaks a different protocol version.
|
|
615
|
+
*/
|
|
616
|
+
export declare function loadKernel(): Promise<Kernel>;
|
|
617
|
+
interface PostgresJournalOptions {
|
|
618
|
+
/** Schema that owns every journal table. Default `vlo`. */
|
|
619
|
+
schema?: string;
|
|
620
|
+
/** Maximum pooled connections. */
|
|
621
|
+
max?: number;
|
|
622
|
+
}
|
|
623
|
+
/** Options for {@link openJournal}. Only the Postgres journal reads any. */
|
|
624
|
+
type JournalOptions = PostgresJournalOptions;
|
|
625
|
+
/**
|
|
626
|
+
* Opens a journal by URL: `sqlite://:memory:`, `sqlite://./.vlo/dev.db`,
|
|
627
|
+
* `sqlite:///abs/path.db`, `postgres://…` or `postgresql://…`. Nothing is created or
|
|
628
|
+
* migrated until `migrate()`. Throws a plain `Error` on any other scheme.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```ts
|
|
632
|
+
* import { openJournal } from "@oona/vlo/host";
|
|
633
|
+
*
|
|
634
|
+
* const journal = openJournal("postgres://user:pass@localhost/app", { schema: "vlo", max: 5 });
|
|
635
|
+
* await journal.migrate();
|
|
636
|
+
* const run = await journal.getRun("run_1");
|
|
637
|
+
* await journal.close();
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
export declare function openJournal(url: string, opts?: JournalOptions): Journal;
|
|
641
|
+
/**
|
|
642
|
+
* Opens a blob store by URL: `file://<dir>` (relative to the working directory when the
|
|
643
|
+
* path is) or `gcs://<bucket>/<prefix>`. The GCS client is only loaded on first use.
|
|
644
|
+
* Throws a plain `Error` on any other scheme or an empty directory or bucket.
|
|
645
|
+
*/
|
|
646
|
+
export declare function openBlobStore(url: string): BlobStore;
|
|
647
|
+
/** The slice of `@google-cloud/storage` used here, so a fake client needs nothing more. */
|
|
648
|
+
interface GcsFileLike {
|
|
649
|
+
/** `[true]` when the object exists. */
|
|
650
|
+
exists(): Promise<[boolean]>;
|
|
651
|
+
/** Uploads the bytes. The store passes `resumable: false` and an octet-stream content type. */
|
|
652
|
+
save(data: Uint8Array, options?: {
|
|
653
|
+
resumable?: boolean;
|
|
654
|
+
contentType?: string;
|
|
655
|
+
}): Promise<unknown>;
|
|
656
|
+
/** Downloads the object's bytes. */
|
|
657
|
+
download(): Promise<[Uint8Array]>;
|
|
658
|
+
}
|
|
659
|
+
/** The slice of a GCS bucket handle used here. */
|
|
660
|
+
interface GcsBucketLike {
|
|
661
|
+
/** A handle for the object at `name`. */
|
|
662
|
+
file(name: string): GcsFileLike;
|
|
663
|
+
}
|
|
664
|
+
/** The slice of a GCS client used here. */
|
|
665
|
+
interface GcsClientLike {
|
|
666
|
+
/** A handle for the bucket. */
|
|
667
|
+
bucket(name: string): GcsBucketLike;
|
|
668
|
+
}
|
|
669
|
+
/** Where a {@link GcsBlobStore} writes. */
|
|
670
|
+
interface GcsBlobStoreOptions {
|
|
671
|
+
/** Bucket name. Required. */
|
|
672
|
+
bucket: string;
|
|
673
|
+
/** Key prefix inside the bucket, e.g. `vlo/blobs`. */
|
|
674
|
+
prefix?: string;
|
|
675
|
+
/** GCP project for the default client. Absent ⇒ the credentials' project. */
|
|
676
|
+
projectId?: string;
|
|
677
|
+
/** Injected client. Absent ⇒ `@google-cloud/storage` with ADC. */
|
|
678
|
+
client?: GcsClientLike;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* The Google Cloud Storage {@link BlobStore}. Opened by `openBlobStore("gcs://…")`. Needs
|
|
682
|
+
* the optional peer dependency `@google-cloud/storage` unless a `client` is injected.
|
|
683
|
+
*/
|
|
684
|
+
export declare class GcsBlobStore implements BlobStore {
|
|
685
|
+
private readonly bucketName;
|
|
686
|
+
private readonly prefix;
|
|
687
|
+
private readonly projectId;
|
|
688
|
+
private bucket;
|
|
689
|
+
/** Throws a plain `Error` when `bucket` is empty. No network call is made here. */
|
|
690
|
+
constructor(options: GcsBlobStoreOptions);
|
|
691
|
+
/** Uploads unless an object with that digest already exists; returns the sha256 hex digest. */
|
|
692
|
+
put(bytes: Uint8Array): Promise<string>;
|
|
693
|
+
/** Downloads the blob; rejects with the client's error when it is missing. */
|
|
694
|
+
get(sha256Hex: string): Promise<Uint8Array>;
|
|
695
|
+
private keyFor;
|
|
696
|
+
private open;
|
|
697
|
+
}
|
|
698
|
+
/** Anything shaped like `fetch`. `host.fetch` is the in-process case. */
|
|
699
|
+
type ClientFetch = (request: Request) => Promise<Response>;
|
|
700
|
+
/** How to reach a host. */
|
|
701
|
+
interface ClientOptions {
|
|
702
|
+
/** Absent when `fetch` is a host handler: requests still need a syntactically valid URL. */
|
|
703
|
+
baseUrl?: string;
|
|
704
|
+
/** Bearer token for the control plane, when the host has one. */
|
|
705
|
+
token?: string;
|
|
706
|
+
/** Transport. Default `globalThis.fetch`; pass `host.fetch` to skip the socket. */
|
|
707
|
+
fetch?: ClientFetch;
|
|
708
|
+
}
|
|
709
|
+
/** Options for `Client.start`. */
|
|
710
|
+
interface StartOptions {
|
|
711
|
+
/** Caller-chosen run id. Default: host-generated. */
|
|
712
|
+
runId?: string;
|
|
713
|
+
/** Search attributes stored on the run. */
|
|
714
|
+
search?: Record<string, Json>;
|
|
715
|
+
}
|
|
716
|
+
/** Options for `Client.startFresh`. */
|
|
717
|
+
interface StartFreshOptions {
|
|
718
|
+
/** The key every run of this unit of work shares; the first run's id. */
|
|
719
|
+
runId: string;
|
|
720
|
+
/** Search attributes stored on the run when one is started. */
|
|
721
|
+
search?: Record<string, Json>;
|
|
722
|
+
/** How many ended runs to walk past before giving up. Default 50. */
|
|
723
|
+
maxChain?: number;
|
|
724
|
+
}
|
|
725
|
+
/** What `Client.startFresh` returns. */
|
|
726
|
+
interface StartFreshResult {
|
|
727
|
+
/** The run started or joined. */
|
|
728
|
+
run: RunView;
|
|
729
|
+
/** True when a live run under the key was joined instead of a new one started. */
|
|
730
|
+
joined: boolean;
|
|
731
|
+
}
|
|
732
|
+
/** What `Client.signal` returns. */
|
|
733
|
+
interface SignalResult {
|
|
734
|
+
/** The stored signal's id. */
|
|
735
|
+
signal_id: string;
|
|
736
|
+
/** False when nothing was waiting: the signal is buffered until a wait opens. */
|
|
737
|
+
delivered: boolean;
|
|
738
|
+
}
|
|
739
|
+
/** Filters for `Client.list`. */
|
|
740
|
+
interface ListQuery {
|
|
741
|
+
/** Status to match. */
|
|
742
|
+
status?: RunStatus;
|
|
743
|
+
/** Workflow name to match. */
|
|
744
|
+
workflow?: string;
|
|
745
|
+
/** Maximum runs. Host default 50. */
|
|
746
|
+
limit?: number;
|
|
747
|
+
}
|
|
748
|
+
/** Options for `Client.signalLink`. */
|
|
749
|
+
interface SignalLinkOptions {
|
|
750
|
+
/** How long the link stays valid. Default 7 days. */
|
|
751
|
+
expiresInMs?: number;
|
|
752
|
+
}
|
|
753
|
+
/** A minted signal link, as the host returns it. */
|
|
754
|
+
interface SignalLink {
|
|
755
|
+
/** Absolute URL carrying the `?token=`. */
|
|
756
|
+
url: string;
|
|
757
|
+
/** When the token stops working, epoch milliseconds. */
|
|
758
|
+
expires_at_ms: number;
|
|
759
|
+
}
|
|
760
|
+
/** Options for `Client.stream`. */
|
|
761
|
+
interface StreamOptions {
|
|
762
|
+
/** Replay journal events after this seq. Default 0: from the beginning. */
|
|
763
|
+
since?: number;
|
|
764
|
+
/** Closes the stream when aborted. */
|
|
765
|
+
signal?: AbortSignal;
|
|
766
|
+
}
|
|
767
|
+
/** One SSE frame, already decoded. `end` is the last one a stream sends. */
|
|
768
|
+
type StreamMessage = {
|
|
769
|
+
type: "journal";
|
|
770
|
+
seq: number;
|
|
771
|
+
data: Envelope;
|
|
772
|
+
} | {
|
|
773
|
+
type: "emit";
|
|
774
|
+
data: {
|
|
775
|
+
channel: string;
|
|
776
|
+
data: Json;
|
|
777
|
+
};
|
|
778
|
+
} | {
|
|
779
|
+
type: "end";
|
|
780
|
+
data: RunView;
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* The control-plane client. Every method maps to one `/v1` route and throws a plain `Error`
|
|
784
|
+
* carrying the status and body on a non-2xx answer. Names may be passed as the definition
|
|
785
|
+
* objects themselves (`activity(...)`, `signal(...)`, `defineWorkflow(...)`).
|
|
786
|
+
*/
|
|
787
|
+
interface Client {
|
|
788
|
+
/** Starts a run and returns its view once the row exists (status `created` or later). */
|
|
789
|
+
start(workflow: string | {
|
|
790
|
+
name: string;
|
|
791
|
+
}, input: Json, options?: StartOptions): Promise<RunView>;
|
|
792
|
+
/** Sends a signal; buffered when the run is not waiting for it yet. */
|
|
793
|
+
signal(runId: string, name: string | {
|
|
794
|
+
name: string;
|
|
795
|
+
}, payload: Json): Promise<SignalResult>;
|
|
796
|
+
/**
|
|
797
|
+
* Mints a URL that delivers this one signal to this one run without a bearer token —
|
|
798
|
+
* the thing you put in an email. The host signs it; opening it renders a confirmation
|
|
799
|
+
* form, and submitting that form is what signals the run.
|
|
800
|
+
*/
|
|
801
|
+
signalLink(runId: string, name: string | {
|
|
802
|
+
name: string;
|
|
803
|
+
}, options?: SignalLinkOptions): Promise<SignalLink>;
|
|
804
|
+
/**
|
|
805
|
+
* Starts a run under `runId`, or under `${runId}_2`, `_3`, … once earlier runs with the
|
|
806
|
+
* key have ended: the first id with no run is started, a live one is joined. The walk is
|
|
807
|
+
* deterministic, so two concurrent callers land on the same id and the insert's
|
|
808
|
+
* `ON CONFLICT DO NOTHING` makes one of them the joiner.
|
|
809
|
+
*/
|
|
810
|
+
startFresh(workflow: string | {
|
|
811
|
+
name: string;
|
|
812
|
+
}, input: Json, options: StartFreshOptions): Promise<StartFreshResult>;
|
|
813
|
+
/** The run's current view. */
|
|
814
|
+
get(runId: string): Promise<RunView>;
|
|
815
|
+
/** The run's current view, or `null` when the host has no such run. */
|
|
816
|
+
find(runId: string): Promise<RunView | null>;
|
|
817
|
+
/** Journaled events with `seq > since` (default 0). */
|
|
818
|
+
events(runId: string, since?: number): Promise<Envelope[]>;
|
|
819
|
+
/** Live events over SSE: journal envelopes, `cmd.emit` payloads, then one `end`. */
|
|
820
|
+
stream(runId: string, options?: StreamOptions): AsyncIterable<StreamMessage>;
|
|
821
|
+
/** Cancels the run and returns its view. */
|
|
822
|
+
cancel(runId: string): Promise<RunView>;
|
|
823
|
+
/** Runs in the host's namespace matching the query. */
|
|
824
|
+
list(query?: ListQuery): Promise<RunView[]>;
|
|
825
|
+
/** Polls every 50 ms until the run reaches one of `status`. Throws after `timeoutMs` (default 10 s). */
|
|
826
|
+
waitFor(runId: string, status: RunStatus | readonly RunStatus[], timeoutMs?: number): Promise<RunView>;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Builds a {@link Client}. With no options it talks to `http://vlo.localhost` over
|
|
830
|
+
* `globalThis.fetch`, which is only useful together with `fetch: host.fetch`.
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```ts
|
|
834
|
+
* import { createClient } from "@oona/vlo/host";
|
|
835
|
+
*
|
|
836
|
+
* const client = createClient({ baseUrl: "http://127.0.0.1:4100", token: "control-plane-token" });
|
|
837
|
+
* const run = await client.start(pipeline, { clip: "reel" });
|
|
838
|
+
* await client.signal(run.run_id, "approve", { by: "me" });
|
|
839
|
+
* const done = await client.waitFor(run.run_id, "completed");
|
|
840
|
+
* console.log(done.output);
|
|
841
|
+
* ```
|
|
842
|
+
*/
|
|
843
|
+
export declare function createClient(options?: ClientOptions): Client;
|
|
844
|
+
export { type ActivityHandler, type ActivityImpls, type ActivityRegistration, type AfterApply, type ApplyTransitionOptions, type AuthConfig, type BlobStore, type Client, type ClientFetch, type ClientOptions, type Completion, type CreateHostOptions, DEFAULT_DRAIN_MAX_MS, type DeriveIdsOutput, Dispatcher, type DispatcherMode, type DispatcherOptions, type Domain, type DomainDef, type DrainOptions, type DrainResult, type Emit, type Envelope, type EventInput, type EventSource, type FetchHandler, type FetchLike, type FoldState, type GcsBlobStoreOptions, type GcsBucketLike, type GcsClientLike, type GcsFileLike, type HandleTaskOptions, type HashAtSeq, type HeaderSource, type Host, type HostContext, type HttpPushOptions, HttpPushTransport, type InProcessOptions, InProcessTracker, InProcessTransport, type Journal, JournalClosed, type JournalOptions, type JournalTx, type Kernel, type KernelError, type Reduction as KernelReduction, type KernelResult, type KernelState, type KernelVersion, type Kind, type ListQuery, type Listening, type NewRunRow, type NewSignalRow, type NewSpawn, type NewTask, type NewTimer, type PlanRetryInput, type PostgresJournalOptions, type PrepareEventInput, type Prepared, type PullWorkerOptions, type PushResult, type PushedTask, type QueueConfig, type Rebuilt, type ReduceStepInput, type RefoldCheckOutput, type Registries, type RetryPlan, type Role, type RunPatch, type RunQuery, type RunRef, type RunRow, type RunView, type SchemaRow, type ServeOptions, type ServeResult, type SignalLink, type SignalLinkClaims, type SignalLinkOptions, type SignalRegistration, type SignalResult, type SignalRow, type SignalResult$1 as SignalRunResult, type SignalWait, type SignalWaitRow, type StartFreshOptions, type StartFreshResult, type StartOptions, type StartRunInput, type StateRow, type StepState, type StreamMessage, type StreamOptions, TERMINAL_RUN_STATUSES, type TaskClaimFilter, type TaskContext, type TaskReporter, type TaskResult, type TaskRow, type TaskScheduled, type TaskTransport, type TaskUpdate, type TickCounts, type TimerRow, type Transition, type TxOutcome, type UsageInput, type Validator, type Worker, type WorkerOptions, defineDomain, defineWorker, drainHost, findWorker, handleTask, isTerminalRunStatus, mergeDomains, withRetryInput };
|