@nagi-js/core 0.1.1-rc.18 → 0.1.1-rc.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-VQTYTI6X.js +1833 -0
- package/dist/chunk-VQTYTI6X.js.map +1 -0
- package/dist/index.d.ts +48 -870
- package/dist/index.js +607 -2310
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +15 -0
- package/dist/testing.js +1335 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-DfxwD2MH.d.ts +905 -0
- package/package.json +6 -1
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
type SkipReason = "when-false" | "transitive" | "manual";
|
|
2
|
+
type StepCancelCause = {
|
|
3
|
+
readonly kind: "run-canceled";
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: "aborted";
|
|
6
|
+
readonly error?: SerializedError;
|
|
7
|
+
};
|
|
8
|
+
type RunCancelCause = {
|
|
9
|
+
readonly kind: "concurrency";
|
|
10
|
+
readonly canceledByRunId: RunId;
|
|
11
|
+
readonly concurrencyKey: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "explicit";
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
readonly note?: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: "operator";
|
|
18
|
+
readonly actor: string;
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
readonly note?: string;
|
|
21
|
+
};
|
|
22
|
+
type StepState = {
|
|
23
|
+
readonly tag: "pending";
|
|
24
|
+
} | {
|
|
25
|
+
readonly tag: "running";
|
|
26
|
+
readonly attempt: AttemptNumber;
|
|
27
|
+
} | {
|
|
28
|
+
readonly tag: "awaitingSignal";
|
|
29
|
+
readonly attempt: AttemptNumber;
|
|
30
|
+
} | {
|
|
31
|
+
readonly tag: "awaitingChild";
|
|
32
|
+
readonly attempt: AttemptNumber;
|
|
33
|
+
} | {
|
|
34
|
+
readonly tag: "backoff";
|
|
35
|
+
readonly failedAttempt: AttemptNumber;
|
|
36
|
+
readonly retryAt: Date;
|
|
37
|
+
readonly error: SerializedError;
|
|
38
|
+
} | {
|
|
39
|
+
readonly tag: "aborting";
|
|
40
|
+
readonly attempt: AttemptNumber;
|
|
41
|
+
} | {
|
|
42
|
+
readonly tag: "completed";
|
|
43
|
+
readonly attempt: AttemptNumber;
|
|
44
|
+
readonly output: Json;
|
|
45
|
+
} | {
|
|
46
|
+
readonly tag: "failed";
|
|
47
|
+
readonly attempt: AttemptNumber;
|
|
48
|
+
readonly error: SerializedError;
|
|
49
|
+
} | {
|
|
50
|
+
readonly tag: "skipped";
|
|
51
|
+
readonly reason: SkipReason;
|
|
52
|
+
} | {
|
|
53
|
+
readonly tag: "canceled";
|
|
54
|
+
readonly cause: StepCancelCause;
|
|
55
|
+
};
|
|
56
|
+
type Resolved<T = Json> = {
|
|
57
|
+
readonly tag: "value";
|
|
58
|
+
readonly value: T;
|
|
59
|
+
} | {
|
|
60
|
+
readonly tag: "skipped";
|
|
61
|
+
};
|
|
62
|
+
type RunPhase = {
|
|
63
|
+
readonly tag: "pending";
|
|
64
|
+
} | {
|
|
65
|
+
readonly tag: "running";
|
|
66
|
+
} | {
|
|
67
|
+
readonly tag: "completed";
|
|
68
|
+
readonly output: Json;
|
|
69
|
+
} | {
|
|
70
|
+
readonly tag: "failed";
|
|
71
|
+
readonly error: SerializedError;
|
|
72
|
+
} | {
|
|
73
|
+
readonly tag: "canceled";
|
|
74
|
+
readonly cause: RunCancelCause;
|
|
75
|
+
};
|
|
76
|
+
interface RunState {
|
|
77
|
+
readonly runId: RunId;
|
|
78
|
+
readonly flowId: string;
|
|
79
|
+
readonly input: Json;
|
|
80
|
+
readonly phase: RunPhase;
|
|
81
|
+
readonly steps: Readonly<Record<StepId, StepState>>;
|
|
82
|
+
readonly selectedArms: Readonly<Record<StepId, string>>;
|
|
83
|
+
readonly bufferedSignals: Readonly<Record<StepId, {
|
|
84
|
+
readonly payload: Json;
|
|
85
|
+
readonly signalName?: string;
|
|
86
|
+
}>>;
|
|
87
|
+
readonly facts: readonly Fact[];
|
|
88
|
+
readonly parent?: ParentLink;
|
|
89
|
+
readonly flowHash?: string;
|
|
90
|
+
readonly codeVersion?: string;
|
|
91
|
+
}
|
|
92
|
+
declare function stepStateOf(runState: RunState, stepId: StepId): StepState;
|
|
93
|
+
declare function runStatusOf(state: RunState): RunStatus;
|
|
94
|
+
declare function stepStatusOf(s: StepState): StepStatus;
|
|
95
|
+
declare function outputOf(s: StepState): Json | null;
|
|
96
|
+
declare function errorOf(s: StepState): SerializedError | undefined;
|
|
97
|
+
declare function attemptOf(s: StepState): AttemptNumber;
|
|
98
|
+
declare function resolvedOf(s: StepState): Resolved;
|
|
99
|
+
declare function unwrap<T>(r: Resolved<T>): T;
|
|
100
|
+
declare function isTerminalRun(state: RunState): boolean;
|
|
101
|
+
declare function isStepTerminal(s: StepState): boolean;
|
|
102
|
+
|
|
103
|
+
interface FactBase {
|
|
104
|
+
readonly runId: RunId;
|
|
105
|
+
readonly at: Date;
|
|
106
|
+
}
|
|
107
|
+
type RowDelta = {
|
|
108
|
+
readonly row: "run";
|
|
109
|
+
readonly status: "running";
|
|
110
|
+
readonly flowId: string;
|
|
111
|
+
readonly input: Json;
|
|
112
|
+
readonly startedAt: Date;
|
|
113
|
+
readonly flowHash: string | null;
|
|
114
|
+
readonly codeVersion: string | null;
|
|
115
|
+
readonly parent: ParentLink | null;
|
|
116
|
+
} | {
|
|
117
|
+
readonly row: "run";
|
|
118
|
+
readonly status: "completed";
|
|
119
|
+
readonly output: Json;
|
|
120
|
+
readonly completedAt: Date;
|
|
121
|
+
} | {
|
|
122
|
+
readonly row: "run";
|
|
123
|
+
readonly status: "failed";
|
|
124
|
+
readonly error: SerializedError;
|
|
125
|
+
readonly completedAt: Date;
|
|
126
|
+
} | {
|
|
127
|
+
readonly row: "run";
|
|
128
|
+
readonly status: "canceled";
|
|
129
|
+
readonly canceledByRunId: RunId | null;
|
|
130
|
+
readonly completedAt: Date;
|
|
131
|
+
} | {
|
|
132
|
+
readonly row: "step";
|
|
133
|
+
readonly status: "running";
|
|
134
|
+
readonly stepId: StepId;
|
|
135
|
+
readonly attempt: AttemptNumber;
|
|
136
|
+
readonly startedAt: Date;
|
|
137
|
+
} | {
|
|
138
|
+
readonly row: "step";
|
|
139
|
+
readonly status: "completed";
|
|
140
|
+
readonly stepId: StepId;
|
|
141
|
+
readonly attempt: AttemptNumber;
|
|
142
|
+
readonly output: Json;
|
|
143
|
+
} | {
|
|
144
|
+
readonly row: "step";
|
|
145
|
+
readonly status: "failed";
|
|
146
|
+
readonly stepId: StepId;
|
|
147
|
+
readonly attempt: AttemptNumber;
|
|
148
|
+
readonly error: SerializedError;
|
|
149
|
+
} | {
|
|
150
|
+
readonly row: "step";
|
|
151
|
+
readonly status: "canceled";
|
|
152
|
+
readonly stepId: StepId;
|
|
153
|
+
readonly attempt: AttemptNumber;
|
|
154
|
+
readonly error: SerializedError | null;
|
|
155
|
+
} | {
|
|
156
|
+
readonly row: "step";
|
|
157
|
+
readonly status: "skipped";
|
|
158
|
+
readonly stepId: StepId;
|
|
159
|
+
} | {
|
|
160
|
+
readonly row: "step";
|
|
161
|
+
readonly status: "reset";
|
|
162
|
+
readonly stepId: StepId;
|
|
163
|
+
} | {
|
|
164
|
+
readonly row: "once";
|
|
165
|
+
readonly stepId: StepId;
|
|
166
|
+
readonly scope: string;
|
|
167
|
+
readonly value: Json;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
interface FlowStartedFact extends FactBase {
|
|
171
|
+
readonly kind: "flow.started";
|
|
172
|
+
readonly flowId: string;
|
|
173
|
+
readonly input: Json;
|
|
174
|
+
readonly flowHash?: string;
|
|
175
|
+
readonly codeVersion?: string;
|
|
176
|
+
readonly parent?: ParentLink;
|
|
177
|
+
}
|
|
178
|
+
interface FlowCompletedFact extends FactBase {
|
|
179
|
+
readonly kind: "flow.completed";
|
|
180
|
+
readonly output: Json;
|
|
181
|
+
}
|
|
182
|
+
interface FlowFailedFact extends FactBase {
|
|
183
|
+
readonly kind: "flow.failed";
|
|
184
|
+
readonly error: SerializedError;
|
|
185
|
+
}
|
|
186
|
+
interface FlowCanceledByConcurrencyFact extends FactBase {
|
|
187
|
+
readonly kind: "flow.canceled";
|
|
188
|
+
readonly cause: "concurrency";
|
|
189
|
+
readonly canceledByRunId: RunId;
|
|
190
|
+
readonly concurrencyKey: string;
|
|
191
|
+
}
|
|
192
|
+
interface FlowCanceledExplicitlyFact extends FactBase {
|
|
193
|
+
readonly kind: "flow.canceled";
|
|
194
|
+
readonly cause: "explicit";
|
|
195
|
+
readonly reason: string;
|
|
196
|
+
readonly note?: string;
|
|
197
|
+
}
|
|
198
|
+
interface FlowCanceledByOperatorFact extends FactBase {
|
|
199
|
+
readonly kind: "flow.canceled";
|
|
200
|
+
readonly cause: "operator";
|
|
201
|
+
readonly actor: string;
|
|
202
|
+
readonly reason: string;
|
|
203
|
+
readonly note?: string;
|
|
204
|
+
}
|
|
205
|
+
type FlowCanceledFact = FlowCanceledByConcurrencyFact | FlowCanceledExplicitlyFact | FlowCanceledByOperatorFact;
|
|
206
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
207
|
+
type CancelArgs = DistributiveOmit<FlowCanceledExplicitlyFact | FlowCanceledByOperatorFact, "kind" | "runId" | "at">;
|
|
208
|
+
type FlowFact = FlowStartedFact | FlowCompletedFact | FlowFailedFact | FlowCanceledFact;
|
|
209
|
+
interface FlowRefUpdatedFact {
|
|
210
|
+
readonly kind: "flow_ref.updated";
|
|
211
|
+
readonly flowId: string;
|
|
212
|
+
readonly from: string | null;
|
|
213
|
+
readonly to: string;
|
|
214
|
+
readonly at: Date;
|
|
215
|
+
}
|
|
216
|
+
type GlobalFact = FlowRefUpdatedFact;
|
|
217
|
+
|
|
218
|
+
interface StepStartedFact extends FactBase {
|
|
219
|
+
readonly kind: "step.started";
|
|
220
|
+
readonly stepId: StepId;
|
|
221
|
+
readonly attempt: AttemptNumber;
|
|
222
|
+
readonly stepKind: StepKind;
|
|
223
|
+
}
|
|
224
|
+
interface StepCompletedFact extends FactBase {
|
|
225
|
+
readonly kind: "step.completed";
|
|
226
|
+
readonly stepId: StepId;
|
|
227
|
+
readonly attempt: AttemptNumber;
|
|
228
|
+
readonly output: Json;
|
|
229
|
+
}
|
|
230
|
+
interface StepFailedFact extends FactBase {
|
|
231
|
+
readonly kind: "step.failed";
|
|
232
|
+
readonly stepId: StepId;
|
|
233
|
+
readonly attempt: AttemptNumber;
|
|
234
|
+
readonly error: SerializedError;
|
|
235
|
+
}
|
|
236
|
+
interface StepCanceledFact extends FactBase {
|
|
237
|
+
readonly kind: "step.canceled";
|
|
238
|
+
readonly stepId: StepId;
|
|
239
|
+
readonly attempt: AttemptNumber;
|
|
240
|
+
readonly error?: SerializedError;
|
|
241
|
+
}
|
|
242
|
+
interface StepRetriedFact extends FactBase {
|
|
243
|
+
readonly kind: "step.retried";
|
|
244
|
+
readonly stepId: StepId;
|
|
245
|
+
readonly attempt: AttemptNumber;
|
|
246
|
+
readonly nextAttemptAt: Date;
|
|
247
|
+
readonly error: SerializedError;
|
|
248
|
+
}
|
|
249
|
+
interface StepSkippedFact extends FactBase {
|
|
250
|
+
readonly kind: "step.skipped";
|
|
251
|
+
readonly stepId: StepId;
|
|
252
|
+
readonly reason: SkipReason;
|
|
253
|
+
readonly actor?: string;
|
|
254
|
+
readonly note?: string;
|
|
255
|
+
}
|
|
256
|
+
interface StepResetFact extends FactBase {
|
|
257
|
+
readonly kind: "step.reset";
|
|
258
|
+
readonly stepId: StepId;
|
|
259
|
+
readonly cascadedFrom?: StepId;
|
|
260
|
+
readonly actor?: string;
|
|
261
|
+
readonly note?: string;
|
|
262
|
+
}
|
|
263
|
+
interface StepAbortRequestedFact extends FactBase {
|
|
264
|
+
readonly kind: "step.abort-requested";
|
|
265
|
+
readonly stepId: StepId;
|
|
266
|
+
readonly attempt: AttemptNumber;
|
|
267
|
+
readonly actor: string;
|
|
268
|
+
readonly note?: string;
|
|
269
|
+
}
|
|
270
|
+
interface MatchArmSelectedFact extends FactBase {
|
|
271
|
+
readonly kind: "match.arm-selected";
|
|
272
|
+
readonly stepId: StepId;
|
|
273
|
+
readonly arm: string;
|
|
274
|
+
}
|
|
275
|
+
interface OnceRecordedFact extends FactBase {
|
|
276
|
+
readonly kind: "once.recorded";
|
|
277
|
+
readonly stepId: StepId;
|
|
278
|
+
readonly scope: string;
|
|
279
|
+
readonly value: Json;
|
|
280
|
+
}
|
|
281
|
+
type StepFact = StepStartedFact | StepCompletedFact | StepFailedFact | StepCanceledFact | StepRetriedFact | StepSkippedFact | StepResetFact | StepAbortRequestedFact | MatchArmSelectedFact | OnceRecordedFact;
|
|
282
|
+
|
|
283
|
+
interface SignalReceivedFact extends FactBase {
|
|
284
|
+
readonly kind: "signal.received";
|
|
285
|
+
readonly stepId: StepId;
|
|
286
|
+
readonly payload: Json;
|
|
287
|
+
readonly signalName?: string;
|
|
288
|
+
}
|
|
289
|
+
interface SignalBufferedFact extends FactBase {
|
|
290
|
+
readonly kind: "signal.buffered";
|
|
291
|
+
readonly stepId: StepId;
|
|
292
|
+
readonly payload: Json;
|
|
293
|
+
readonly signalName?: string;
|
|
294
|
+
}
|
|
295
|
+
type SignalFact = SignalReceivedFact | SignalBufferedFact;
|
|
296
|
+
|
|
297
|
+
interface LeaseReapedFact extends FactBase {
|
|
298
|
+
readonly kind: "lease.reaped";
|
|
299
|
+
readonly stepId: StepId;
|
|
300
|
+
readonly attempt: AttemptNumber;
|
|
301
|
+
readonly reapedAt: Date;
|
|
302
|
+
readonly reason: "expired";
|
|
303
|
+
}
|
|
304
|
+
type LeaseFact = LeaseReapedFact;
|
|
305
|
+
|
|
306
|
+
type Fact = FlowFact | StepFact | SignalFact | LeaseFact;
|
|
307
|
+
type FactKind = Fact["kind"];
|
|
308
|
+
declare function foldRun(runId: RunId, facts: readonly Fact[]): RunState;
|
|
309
|
+
declare function rowDeltaOf(fact: Fact): RowDelta | null;
|
|
310
|
+
|
|
311
|
+
type StepRunStatus = StepStatus;
|
|
312
|
+
interface RunView {
|
|
313
|
+
readonly runId: RunId;
|
|
314
|
+
readonly flowId: string;
|
|
315
|
+
readonly flowHash: string;
|
|
316
|
+
readonly status: RunStatus;
|
|
317
|
+
readonly startedAt: Date;
|
|
318
|
+
readonly completedAt?: Date;
|
|
319
|
+
readonly input: Json;
|
|
320
|
+
readonly output?: Json;
|
|
321
|
+
readonly error?: Json;
|
|
322
|
+
readonly canceledByRunId?: RunId;
|
|
323
|
+
readonly concurrencyKey?: string;
|
|
324
|
+
readonly parent?: {
|
|
325
|
+
readonly runId: RunId;
|
|
326
|
+
readonly stepId: StepId;
|
|
327
|
+
};
|
|
328
|
+
readonly children: readonly RunId[];
|
|
329
|
+
}
|
|
330
|
+
interface StepView {
|
|
331
|
+
readonly stepId: StepId;
|
|
332
|
+
readonly attempt: AttemptNumber;
|
|
333
|
+
readonly status: StepRunStatus;
|
|
334
|
+
readonly startedAt?: Date;
|
|
335
|
+
readonly completedAt?: Date;
|
|
336
|
+
readonly output?: Json;
|
|
337
|
+
readonly error?: Json;
|
|
338
|
+
readonly lease?: {
|
|
339
|
+
readonly expiresAt: Date;
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
type RunDescription = {
|
|
343
|
+
readonly run: RunView;
|
|
344
|
+
readonly steps: readonly StepView[];
|
|
345
|
+
} | null;
|
|
346
|
+
|
|
347
|
+
type ReaperDecision = {
|
|
348
|
+
readonly tag: "skip";
|
|
349
|
+
readonly reason: "terminal" | "still-live" | "child-active";
|
|
350
|
+
} | {
|
|
351
|
+
readonly tag: "reap";
|
|
352
|
+
readonly nextAttempt: AttemptNumber;
|
|
353
|
+
readonly backoffMs: Millis;
|
|
354
|
+
};
|
|
355
|
+
declare function decideExpiredLeaseAction(args: {
|
|
356
|
+
readonly lease: {
|
|
357
|
+
readonly runId: RunId;
|
|
358
|
+
readonly stepId: StepId;
|
|
359
|
+
readonly attempt: AttemptNumber;
|
|
360
|
+
readonly expiresAt: Date;
|
|
361
|
+
};
|
|
362
|
+
readonly stepStatus: StepRunStatus;
|
|
363
|
+
readonly childActive: boolean;
|
|
364
|
+
readonly now: Date;
|
|
365
|
+
}): ReaperDecision;
|
|
366
|
+
interface ReapedLease {
|
|
367
|
+
readonly runId: RunId;
|
|
368
|
+
readonly stepId: StepId;
|
|
369
|
+
readonly attempt: AttemptNumber;
|
|
370
|
+
readonly nextAttempt: AttemptNumber;
|
|
371
|
+
}
|
|
372
|
+
declare const DEFAULT_REAPER_INTERVAL_MS: Millis;
|
|
373
|
+
|
|
374
|
+
type Json = string | number | boolean | null | Json[] | {
|
|
375
|
+
[key: string]: Json;
|
|
376
|
+
};
|
|
377
|
+
type Millis = number;
|
|
378
|
+
type RunId = string & {
|
|
379
|
+
readonly __brand: "RunId";
|
|
380
|
+
};
|
|
381
|
+
type StepId = string;
|
|
382
|
+
type AttemptNumber = number;
|
|
383
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
384
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
385
|
+
}
|
|
386
|
+
declare namespace StandardSchemaV1 {
|
|
387
|
+
interface Props<Input = unknown, Output = Input> {
|
|
388
|
+
readonly version: 1;
|
|
389
|
+
readonly vendor: string;
|
|
390
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
391
|
+
readonly types?: Types<Input, Output>;
|
|
392
|
+
}
|
|
393
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
394
|
+
interface SuccessResult<Output> {
|
|
395
|
+
readonly value: Output;
|
|
396
|
+
readonly issues?: undefined;
|
|
397
|
+
}
|
|
398
|
+
interface FailureResult {
|
|
399
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
400
|
+
}
|
|
401
|
+
interface Issue {
|
|
402
|
+
readonly message: string;
|
|
403
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment>;
|
|
404
|
+
}
|
|
405
|
+
interface PathSegment {
|
|
406
|
+
readonly key: PropertyKey;
|
|
407
|
+
}
|
|
408
|
+
interface Types<Input = unknown, Output = Input> {
|
|
409
|
+
readonly input: Input;
|
|
410
|
+
readonly output: Output;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
type InferSchemaInput<S> = S extends StandardSchemaV1<infer I, unknown> ? I : never;
|
|
414
|
+
type InferSchemaOutput<S> = S extends StandardSchemaV1<unknown, infer O> ? O : never;
|
|
415
|
+
interface Register {
|
|
416
|
+
}
|
|
417
|
+
type Tx = Register extends {
|
|
418
|
+
tx: infer T;
|
|
419
|
+
} ? T : unknown;
|
|
420
|
+
type StepKind = "task" | "activity" | "signal" | "match" | "subflow" | "streaming";
|
|
421
|
+
interface Step<Output = unknown> {
|
|
422
|
+
readonly kind: StepKind;
|
|
423
|
+
readonly id: StepId;
|
|
424
|
+
readonly __output?: Output;
|
|
425
|
+
}
|
|
426
|
+
type StepOutput<S> = S extends Step<infer O> ? O : never;
|
|
427
|
+
type StepMap = Readonly<Record<string, Step<unknown>>>;
|
|
428
|
+
interface Optional<S extends Step = Step> {
|
|
429
|
+
readonly __optional: S;
|
|
430
|
+
}
|
|
431
|
+
type NeedRef = Step | Optional<Step>;
|
|
432
|
+
type NeedsMap = Readonly<Record<string, NeedRef>>;
|
|
433
|
+
type NeedsOutputs<N extends NeedsMap> = {
|
|
434
|
+
readonly [K in keyof N]: StepOutput<N[K]>;
|
|
435
|
+
};
|
|
436
|
+
type ResolvedNeeds<N extends NeedsMap> = {
|
|
437
|
+
readonly [K in keyof N]: N[K] extends Optional<infer S> ? Resolved<StepOutput<S>> : N[K] extends Step ? StepOutput<N[K]> : never;
|
|
438
|
+
};
|
|
439
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
440
|
+
interface LogEntry {
|
|
441
|
+
readonly level: LogLevel;
|
|
442
|
+
readonly msg: string;
|
|
443
|
+
readonly attrs?: Record<string, unknown>;
|
|
444
|
+
}
|
|
445
|
+
interface Logger {
|
|
446
|
+
debug(message: string, attrs?: Record<string, unknown>): void;
|
|
447
|
+
info(message: string, attrs?: Record<string, unknown>): void;
|
|
448
|
+
warn(message: string, attrs?: Record<string, unknown>): void;
|
|
449
|
+
error(message: string, attrs?: Record<string, unknown>): void;
|
|
450
|
+
}
|
|
451
|
+
interface StepCtx<Input = unknown> {
|
|
452
|
+
readonly input: Input;
|
|
453
|
+
readonly tx: Tx;
|
|
454
|
+
readonly runId: RunId;
|
|
455
|
+
readonly stepId: StepId;
|
|
456
|
+
readonly attempt: AttemptNumber;
|
|
457
|
+
readonly signal: AbortSignal;
|
|
458
|
+
readonly now: () => Date;
|
|
459
|
+
readonly logger: Logger;
|
|
460
|
+
once<T extends Json>(scope: string, fn: () => Promise<T>): Promise<T>;
|
|
461
|
+
idempotencyKey(scope: string): string;
|
|
462
|
+
}
|
|
463
|
+
type ActivityCtx<Input = unknown> = Omit<StepCtx<Input>, "tx">;
|
|
464
|
+
type StreamEvent<C = Json> = {
|
|
465
|
+
readonly kind: "chunk";
|
|
466
|
+
readonly chunk: C;
|
|
467
|
+
} | {
|
|
468
|
+
readonly kind: "dropped";
|
|
469
|
+
readonly count: number;
|
|
470
|
+
} | {
|
|
471
|
+
readonly kind: "retry";
|
|
472
|
+
readonly attempt: AttemptNumber;
|
|
473
|
+
} | {
|
|
474
|
+
readonly kind: "error";
|
|
475
|
+
readonly error: SerializedError;
|
|
476
|
+
};
|
|
477
|
+
interface StreamingStepCtx<Input = unknown, Chunk = Json> extends StepCtx<Input> {
|
|
478
|
+
readonly emit: (chunk: Chunk) => Promise<void>;
|
|
479
|
+
}
|
|
480
|
+
type BackoffStrategy = "exponential" | "linear" | "fixed";
|
|
481
|
+
interface RetryPolicy {
|
|
482
|
+
readonly maxAttempts: number;
|
|
483
|
+
readonly backoff: BackoffStrategy;
|
|
484
|
+
readonly initialDelayMs?: Millis;
|
|
485
|
+
readonly maxDelayMs?: Millis;
|
|
486
|
+
readonly retryOn?: (error: unknown) => boolean;
|
|
487
|
+
}
|
|
488
|
+
interface StepConfigBase<Input, N extends NeedsMap> {
|
|
489
|
+
readonly needs?: N;
|
|
490
|
+
readonly when?: (args: {
|
|
491
|
+
readonly input: NoInfer<Input>;
|
|
492
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
493
|
+
}) => boolean;
|
|
494
|
+
}
|
|
495
|
+
interface StepLifecycleHooks<Output> {
|
|
496
|
+
readonly onStart?: (event: StepStartEvent) => void | Promise<void>;
|
|
497
|
+
readonly onComplete?: (event: StepCompleteEvent & {
|
|
498
|
+
readonly output: NoInfer<Output>;
|
|
499
|
+
}) => void | Promise<void>;
|
|
500
|
+
readonly onError?: (event: StepErrorEvent) => void | Promise<void>;
|
|
501
|
+
readonly onRetry?: (event: StepRetryEvent) => void | Promise<void>;
|
|
502
|
+
}
|
|
503
|
+
interface TaskConfig<Input, N extends NeedsMap, Output> extends StepConfigBase<Input, N>, StepLifecycleHooks<Output> {
|
|
504
|
+
readonly retry?: RetryPolicy;
|
|
505
|
+
readonly run: (args: {
|
|
506
|
+
readonly input: NoInfer<Input>;
|
|
507
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
508
|
+
readonly ctx: StepCtx<NoInfer<Input>>;
|
|
509
|
+
}) => Promise<Output>;
|
|
510
|
+
}
|
|
511
|
+
interface ActivityConfig<Input, N extends NeedsMap, Output> extends StepConfigBase<Input, N>, StepLifecycleHooks<Output> {
|
|
512
|
+
readonly retry?: RetryPolicy;
|
|
513
|
+
readonly run: (args: {
|
|
514
|
+
readonly input: NoInfer<Input>;
|
|
515
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
516
|
+
readonly ctx: ActivityCtx<NoInfer<Input>>;
|
|
517
|
+
}) => Promise<Output>;
|
|
518
|
+
}
|
|
519
|
+
interface StreamingTaskConfig<Input, N extends NeedsMap, Output, Chunk> extends StepConfigBase<Input, N>, StepLifecycleHooks<Output> {
|
|
520
|
+
readonly retry?: RetryPolicy;
|
|
521
|
+
readonly run: (args: {
|
|
522
|
+
readonly input: NoInfer<Input>;
|
|
523
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
524
|
+
readonly ctx: StreamingStepCtx<NoInfer<Input>, Chunk>;
|
|
525
|
+
}) => Promise<Output>;
|
|
526
|
+
}
|
|
527
|
+
interface SignalConfig<Input, N extends NeedsMap, Schema extends StandardSchemaV1> extends StepConfigBase<Input, N> {
|
|
528
|
+
readonly schema: Schema;
|
|
529
|
+
readonly names?: readonly [string, ...string[]];
|
|
530
|
+
readonly timeoutMs: Millis | "unbounded";
|
|
531
|
+
}
|
|
532
|
+
interface MatchArmGuard<Input, N extends NeedsMap, M extends StepMap> {
|
|
533
|
+
readonly when: (args: {
|
|
534
|
+
readonly input: NoInfer<Input>;
|
|
535
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
536
|
+
}) => boolean;
|
|
537
|
+
readonly otherwise?: never;
|
|
538
|
+
readonly build: (b: Builder<Input>) => M;
|
|
539
|
+
}
|
|
540
|
+
interface MatchArmOtherwise<Input, M extends StepMap> {
|
|
541
|
+
readonly otherwise: true;
|
|
542
|
+
readonly when?: never;
|
|
543
|
+
readonly build: (b: Builder<Input>) => M;
|
|
544
|
+
}
|
|
545
|
+
type MatchArm<Input, N extends NeedsMap, M extends StepMap> = MatchArmGuard<Input, N, M> | MatchArmOtherwise<Input, M>;
|
|
546
|
+
type MatchArmShape<Input, N extends NeedsMap> = {
|
|
547
|
+
readonly when: (args: {
|
|
548
|
+
readonly input: NoInfer<Input>;
|
|
549
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
550
|
+
}) => boolean;
|
|
551
|
+
readonly otherwise?: never;
|
|
552
|
+
readonly build: (b: Builder<Input>) => StepMap;
|
|
553
|
+
} | {
|
|
554
|
+
readonly otherwise: true;
|
|
555
|
+
readonly when?: never;
|
|
556
|
+
readonly build: (b: Builder<Input>) => StepMap;
|
|
557
|
+
};
|
|
558
|
+
interface MatchGuardConfig<Input, N extends NeedsMap, M extends StepMap> {
|
|
559
|
+
readonly needs?: N;
|
|
560
|
+
readonly arms: ReadonlyArray<MatchArm<Input, N, M>>;
|
|
561
|
+
}
|
|
562
|
+
type MatchArmOutput<M extends StepMap> = {
|
|
563
|
+
readonly [K in keyof M]: StepOutput<M[K]>;
|
|
564
|
+
};
|
|
565
|
+
interface SubflowConfig<Input, N extends NeedsMap, Child extends Flow> extends StepConfigBase<Input, N> {
|
|
566
|
+
readonly input: (args: {
|
|
567
|
+
readonly input: NoInfer<Input>;
|
|
568
|
+
readonly needs: NoInfer<ResolvedNeeds<N>>;
|
|
569
|
+
}) => FlowInput<Child>;
|
|
570
|
+
}
|
|
571
|
+
interface SubflowStepOutput<ChildOutput> {
|
|
572
|
+
readonly childRunId: RunId;
|
|
573
|
+
readonly output: ChildOutput;
|
|
574
|
+
}
|
|
575
|
+
interface Builder<Input = unknown> {
|
|
576
|
+
task<N extends NeedsMap, Output>(config: TaskConfig<Input, N, Output>): Step<Output>;
|
|
577
|
+
activity<N extends NeedsMap, Output>(config: ActivityConfig<Input, N, Output>): Step<Output>;
|
|
578
|
+
streamingTask<N extends NeedsMap, O, C = Json>(config: StreamingTaskConfig<Input, N, O, C>): Step<O>;
|
|
579
|
+
signal<N extends NeedsMap, S extends StandardSchemaV1>(config: SignalConfig<Input, N, S>): Step<InferSchemaOutput<S>>;
|
|
580
|
+
subflow<N extends NeedsMap, Child extends Flow>(child: Child, config: SubflowConfig<Input, N, Child>): Step<SubflowStepOutput<FlowOutput<Child>>>;
|
|
581
|
+
match<N extends NeedsMap, Arms extends ReadonlyArray<MatchArmShape<Input, N>>>(config: {
|
|
582
|
+
readonly needs?: N;
|
|
583
|
+
readonly arms: Arms;
|
|
584
|
+
}): Step<MatchArmOutput<ReturnType<Arms[number]["build"]>>>;
|
|
585
|
+
}
|
|
586
|
+
type ConcurrencyMode = "cancel-in-progress";
|
|
587
|
+
type StringKeyOf<Input> = {
|
|
588
|
+
[K in keyof Input]-?: Input[K] extends string ? K : never;
|
|
589
|
+
}[keyof Input];
|
|
590
|
+
type FlowConcurrency<Input = Json> = StringKeyOf<Input> | {
|
|
591
|
+
readonly keyFn: (input: Input) => string;
|
|
592
|
+
readonly mode?: ConcurrencyMode;
|
|
593
|
+
};
|
|
594
|
+
interface ResolvedConcurrency {
|
|
595
|
+
readonly keyFn: (input: Json) => string;
|
|
596
|
+
readonly mode: ConcurrencyMode;
|
|
597
|
+
}
|
|
598
|
+
interface FlowConfig<Id extends string, InputSchema extends StandardSchemaV1, R extends StepMap, Output = unknown> {
|
|
599
|
+
readonly id: Id;
|
|
600
|
+
readonly input: InputSchema;
|
|
601
|
+
readonly build: (b: Builder<InferSchemaOutput<InputSchema>>) => R;
|
|
602
|
+
output?(steps: NeedsOutputs<R>): Output;
|
|
603
|
+
readonly concurrency?: FlowConcurrency<InferSchemaOutput<InputSchema>>;
|
|
604
|
+
readonly onStart?: (event: FlowStartEvent) => void | Promise<void>;
|
|
605
|
+
readonly onComplete?: (event: FlowCompleteEvent & {
|
|
606
|
+
readonly output: NoInfer<Output>;
|
|
607
|
+
}) => void | Promise<void>;
|
|
608
|
+
readonly onError?: (event: FlowErrorEvent) => void | Promise<void>;
|
|
609
|
+
}
|
|
610
|
+
interface Flow<Id extends string = string, InputSchema extends StandardSchemaV1 = StandardSchemaV1, M extends StepMap = StepMap, Output = unknown> {
|
|
611
|
+
readonly id: Id;
|
|
612
|
+
readonly input: InputSchema;
|
|
613
|
+
readonly steps: M;
|
|
614
|
+
output?(steps: NeedsOutputs<M>): Output;
|
|
615
|
+
readonly onStart?: (event: FlowStartEvent) => void | Promise<void>;
|
|
616
|
+
readonly onComplete?: (event: FlowCompleteEvent) => void | Promise<void>;
|
|
617
|
+
readonly onError?: (event: FlowErrorEvent) => void | Promise<void>;
|
|
618
|
+
readonly concurrency?: ResolvedConcurrency;
|
|
619
|
+
}
|
|
620
|
+
type FlowInput<F> = F extends Flow<string, infer S, StepMap, unknown> ? InferSchemaOutput<S> : never;
|
|
621
|
+
type FlowOutput<F> = F extends Flow<string, StandardSchemaV1, StepMap, infer O> ? O : never;
|
|
622
|
+
type FlowIdOf<T extends ReadonlyArray<Flow>> = T[number] extends Flow<infer Id> ? Id : never;
|
|
623
|
+
interface ParentLink {
|
|
624
|
+
readonly runId: RunId;
|
|
625
|
+
readonly stepId: StepId;
|
|
626
|
+
}
|
|
627
|
+
interface ParentRef extends ParentLink {
|
|
628
|
+
readonly attempt: AttemptNumber;
|
|
629
|
+
}
|
|
630
|
+
interface FlowEvent {
|
|
631
|
+
readonly runId: RunId;
|
|
632
|
+
readonly flowId: string;
|
|
633
|
+
readonly at: Date;
|
|
634
|
+
}
|
|
635
|
+
interface FlowStartEvent extends FlowEvent {
|
|
636
|
+
readonly input: Json;
|
|
637
|
+
readonly parent?: ParentRef;
|
|
638
|
+
}
|
|
639
|
+
interface FlowCompleteEvent extends FlowEvent {
|
|
640
|
+
readonly output: Json;
|
|
641
|
+
}
|
|
642
|
+
interface FlowErrorEvent extends FlowEvent {
|
|
643
|
+
readonly error: SerializedError;
|
|
644
|
+
}
|
|
645
|
+
interface StepEvent extends FlowEvent {
|
|
646
|
+
readonly stepId: StepId;
|
|
647
|
+
readonly attempt: AttemptNumber;
|
|
648
|
+
readonly kind: StepKind;
|
|
649
|
+
}
|
|
650
|
+
interface StepStartEvent extends StepEvent {
|
|
651
|
+
readonly input: Json;
|
|
652
|
+
}
|
|
653
|
+
interface StepCompleteEvent extends StepEvent {
|
|
654
|
+
readonly output: Json;
|
|
655
|
+
readonly durationMs?: Millis;
|
|
656
|
+
}
|
|
657
|
+
interface StepErrorEvent extends StepEvent {
|
|
658
|
+
readonly error: SerializedError;
|
|
659
|
+
}
|
|
660
|
+
interface StepRetryEvent extends StepEvent {
|
|
661
|
+
readonly error: SerializedError;
|
|
662
|
+
readonly nextAttemptAt: Date;
|
|
663
|
+
}
|
|
664
|
+
interface SignalReceivedEvent extends StepEvent {
|
|
665
|
+
readonly payload: Json;
|
|
666
|
+
}
|
|
667
|
+
interface FlowHooks {
|
|
668
|
+
readonly onFlowStart?: (event: FlowStartEvent) => void | Promise<void>;
|
|
669
|
+
readonly onFlowComplete?: (event: FlowCompleteEvent) => void | Promise<void>;
|
|
670
|
+
readonly onFlowError?: (event: FlowErrorEvent) => void | Promise<void>;
|
|
671
|
+
readonly onStepStart?: (event: StepStartEvent) => void | Promise<void>;
|
|
672
|
+
readonly onStepComplete?: (event: StepCompleteEvent) => void | Promise<void>;
|
|
673
|
+
readonly onStepError?: (event: StepErrorEvent) => void | Promise<void>;
|
|
674
|
+
readonly onStepRetry?: (event: StepRetryEvent) => void | Promise<void>;
|
|
675
|
+
readonly onSignalReceived?: (event: SignalReceivedEvent) => void | Promise<void>;
|
|
676
|
+
}
|
|
677
|
+
interface WorkerConfig {
|
|
678
|
+
readonly concurrency?: number;
|
|
679
|
+
readonly pollIntervalMs?: Millis;
|
|
680
|
+
readonly signal?: AbortSignal;
|
|
681
|
+
readonly timerSweepIntervalMs?: Millis;
|
|
682
|
+
readonly snapshotGonePolicy?: SnapshotGonePolicy;
|
|
683
|
+
readonly maxConcurrencyPerFlow?: number;
|
|
684
|
+
}
|
|
685
|
+
type SnapshotGoneDisposition = {
|
|
686
|
+
readonly action: "retry";
|
|
687
|
+
readonly delayMs: Millis;
|
|
688
|
+
} | {
|
|
689
|
+
readonly action: "fail";
|
|
690
|
+
};
|
|
691
|
+
type SnapshotGonePolicy = (readCount: number) => SnapshotGoneDisposition;
|
|
692
|
+
interface WorkerRunOnceOpts {
|
|
693
|
+
readonly maxSteps?: number;
|
|
694
|
+
}
|
|
695
|
+
interface WorkerRunUntilEmptyOpts {
|
|
696
|
+
readonly deadline?: number;
|
|
697
|
+
}
|
|
698
|
+
interface WorkerRunResult {
|
|
699
|
+
readonly processed: number;
|
|
700
|
+
}
|
|
701
|
+
interface Worker {
|
|
702
|
+
run(): Promise<void>;
|
|
703
|
+
runOnce(opts?: WorkerRunOnceOpts): Promise<WorkerRunResult>;
|
|
704
|
+
runUntilEmpty(opts?: WorkerRunUntilEmptyOpts): Promise<WorkerRunResult>;
|
|
705
|
+
}
|
|
706
|
+
type ClaimToken = string & {
|
|
707
|
+
readonly __brand: "ClaimToken";
|
|
708
|
+
};
|
|
709
|
+
interface SerializedError {
|
|
710
|
+
readonly name: string;
|
|
711
|
+
readonly message: string;
|
|
712
|
+
readonly stack?: string;
|
|
713
|
+
readonly cause?: Json;
|
|
714
|
+
}
|
|
715
|
+
type SettleSignalResult = {
|
|
716
|
+
readonly tag: "delivered";
|
|
717
|
+
readonly attempt: AttemptNumber;
|
|
718
|
+
readonly payload: Json;
|
|
719
|
+
readonly signalName?: string;
|
|
720
|
+
} | {
|
|
721
|
+
readonly tag: "buffered";
|
|
722
|
+
} | {
|
|
723
|
+
readonly tag: "noop";
|
|
724
|
+
};
|
|
725
|
+
interface TimedOutSignal {
|
|
726
|
+
readonly runId: RunId;
|
|
727
|
+
readonly stepId: StepId;
|
|
728
|
+
readonly attempt: AttemptNumber;
|
|
729
|
+
readonly fireAt: Date;
|
|
730
|
+
}
|
|
731
|
+
interface Store {
|
|
732
|
+
appendFact(runId: RunId, fact: Fact): Promise<void>;
|
|
733
|
+
loadRunState(runId: RunId): Promise<RunState>;
|
|
734
|
+
settleSignal(args: {
|
|
735
|
+
readonly runId: RunId;
|
|
736
|
+
readonly stepId: StepId;
|
|
737
|
+
readonly at: Date;
|
|
738
|
+
readonly incoming?: {
|
|
739
|
+
readonly payload: Json;
|
|
740
|
+
readonly signalName?: string;
|
|
741
|
+
};
|
|
742
|
+
}): Promise<SettleSignalResult>;
|
|
743
|
+
tryStartRun(runId: RunId, fact: FlowStartedFact, concurrency?: {
|
|
744
|
+
readonly key: string;
|
|
745
|
+
readonly mode: ConcurrencyMode;
|
|
746
|
+
}): Promise<{
|
|
747
|
+
readonly started: boolean;
|
|
748
|
+
readonly canceled: ReadonlyArray<{
|
|
749
|
+
readonly runId: RunId;
|
|
750
|
+
readonly fact: FlowCanceledByConcurrencyFact;
|
|
751
|
+
}>;
|
|
752
|
+
}>;
|
|
753
|
+
tryStartRunOnTx(tx: Tx, runId: RunId, fact: FlowStartedFact, concurrency?: {
|
|
754
|
+
readonly key: string;
|
|
755
|
+
readonly mode: ConcurrencyMode;
|
|
756
|
+
}): Promise<{
|
|
757
|
+
readonly started: boolean;
|
|
758
|
+
readonly canceled: ReadonlyArray<{
|
|
759
|
+
readonly runId: RunId;
|
|
760
|
+
readonly fact: FlowCanceledByConcurrencyFact;
|
|
761
|
+
}>;
|
|
762
|
+
}>;
|
|
763
|
+
claimStep(runId: RunId, stepId: StepId, attempt: AttemptNumber): Promise<ClaimToken | null>;
|
|
764
|
+
extendLease(runId: RunId, stepId: StepId, attempt: AttemptNumber, leaseMs: Millis): Promise<void>;
|
|
765
|
+
sweepLeases(args: {
|
|
766
|
+
readonly now: Date;
|
|
767
|
+
readonly queue: Queue;
|
|
768
|
+
readonly limit?: number;
|
|
769
|
+
}): Promise<readonly ReapedLease[]>;
|
|
770
|
+
upsertTimer(runId: RunId, stepId: StepId, fireAt: Date): Promise<void>;
|
|
771
|
+
sweepSignalTimeouts(args: {
|
|
772
|
+
readonly now: Date;
|
|
773
|
+
readonly limit?: number;
|
|
774
|
+
}): Promise<readonly TimedOutSignal[]>;
|
|
775
|
+
settleStep(runId: RunId, stepId: StepId, fact: StepCompletedFact | StepFailedFact): Promise<void>;
|
|
776
|
+
recordOnce(runId: RunId, stepId: StepId, scope: string, value: Json): Promise<void>;
|
|
777
|
+
getOnce(runId: RunId, stepId: StepId, scope: string): Promise<Json | null>;
|
|
778
|
+
runStep<T extends Json>(runId: RunId, stepId: StepId, attempt: AttemptNumber, body: (tx: Tx) => Promise<{
|
|
779
|
+
readonly output: T;
|
|
780
|
+
readonly fact: StepCompletedFact | StepFailedFact | StepCanceledFact;
|
|
781
|
+
}>): Promise<T>;
|
|
782
|
+
upsertSnapshot(args: {
|
|
783
|
+
readonly flowHash: string;
|
|
784
|
+
readonly flowId: string;
|
|
785
|
+
readonly dag: Json;
|
|
786
|
+
}): Promise<void>;
|
|
787
|
+
getRef(flowId: string): Promise<string | null>;
|
|
788
|
+
setRef(flowId: string, flowHash: string): Promise<void>;
|
|
789
|
+
loadSnapshot(flowHash: string): Promise<{
|
|
790
|
+
readonly flowId: string;
|
|
791
|
+
readonly dag: Json;
|
|
792
|
+
} | null>;
|
|
793
|
+
appendGlobalFact(fact: GlobalFact): Promise<void>;
|
|
794
|
+
queryRuns(opts: QueryRunsOpts): Promise<QueryRunsResult>;
|
|
795
|
+
describe(runId: RunId): Promise<RunDescription>;
|
|
796
|
+
listChildren(parentRunId: RunId): Promise<ReadonlyArray<RunId>>;
|
|
797
|
+
pruneFacts(opts: Required<PruneOpts>): Promise<PruneResult>;
|
|
798
|
+
readonly stream?: StreamTransport;
|
|
799
|
+
}
|
|
800
|
+
interface StreamTransport {
|
|
801
|
+
subscribeStream(runId: RunId, stepId: StepId, opts?: {
|
|
802
|
+
readonly replayBuffered?: boolean;
|
|
803
|
+
}): AsyncIterable<StreamEvent<Json>>;
|
|
804
|
+
publishChunk(runId: RunId, stepId: StepId, chunk: Json): void;
|
|
805
|
+
}
|
|
806
|
+
interface QueryRunsWhere<FlowId extends string = string> {
|
|
807
|
+
readonly flowId?: FlowId;
|
|
808
|
+
readonly status?: ReadonlyArray<RunStatus>;
|
|
809
|
+
readonly input?: Record<string, Json>;
|
|
810
|
+
}
|
|
811
|
+
type QueryRunsOpts<FlowId extends string = string> = {
|
|
812
|
+
readonly where?: QueryRunsWhere<FlowId>;
|
|
813
|
+
readonly latest: true;
|
|
814
|
+
readonly limit?: never;
|
|
815
|
+
readonly cursor?: never;
|
|
816
|
+
} | {
|
|
817
|
+
readonly where?: QueryRunsWhere<FlowId>;
|
|
818
|
+
readonly latest?: false;
|
|
819
|
+
readonly limit?: number;
|
|
820
|
+
readonly cursor?: string;
|
|
821
|
+
};
|
|
822
|
+
interface RunSummary<FlowId extends string = string> {
|
|
823
|
+
readonly runId: RunId;
|
|
824
|
+
readonly flowId: FlowId;
|
|
825
|
+
readonly status: RunStatus;
|
|
826
|
+
readonly startedAt: Date;
|
|
827
|
+
readonly completedAt: Date | null;
|
|
828
|
+
readonly input: Json;
|
|
829
|
+
}
|
|
830
|
+
interface QueryRunsResult<FlowId extends string = string> {
|
|
831
|
+
readonly runs: ReadonlyArray<RunSummary<FlowId>>;
|
|
832
|
+
readonly cursor: string | null;
|
|
833
|
+
}
|
|
834
|
+
type PrunableStatus = Extract<RunStatus, "completed" | "failed" | "canceled">;
|
|
835
|
+
interface PruneOpts {
|
|
836
|
+
readonly olderThan: Date;
|
|
837
|
+
readonly statuses?: ReadonlyArray<PrunableStatus>;
|
|
838
|
+
readonly batchSize?: number;
|
|
839
|
+
readonly keepSummary?: boolean;
|
|
840
|
+
}
|
|
841
|
+
interface PruneResult {
|
|
842
|
+
readonly runsPruned: number;
|
|
843
|
+
readonly factsPruned: number;
|
|
844
|
+
}
|
|
845
|
+
interface QueueMessage {
|
|
846
|
+
readonly receipt: string;
|
|
847
|
+
readonly runId: RunId;
|
|
848
|
+
readonly stepId: StepId;
|
|
849
|
+
readonly payload: Json;
|
|
850
|
+
readonly attempt: AttemptNumber;
|
|
851
|
+
readonly readCount: number;
|
|
852
|
+
readonly flowId?: string;
|
|
853
|
+
}
|
|
854
|
+
interface QueueDequeueOpts {
|
|
855
|
+
readonly count: number;
|
|
856
|
+
}
|
|
857
|
+
interface QueueEnqueueOpts {
|
|
858
|
+
readonly attempt?: AttemptNumber;
|
|
859
|
+
readonly delayMs?: Millis;
|
|
860
|
+
readonly payload?: Json;
|
|
861
|
+
readonly flowId?: string;
|
|
862
|
+
}
|
|
863
|
+
interface QueueInspectEntry {
|
|
864
|
+
readonly stepId: StepId;
|
|
865
|
+
readonly attempt: AttemptNumber;
|
|
866
|
+
readonly readCount: number;
|
|
867
|
+
readonly visibleAt: Date;
|
|
868
|
+
}
|
|
869
|
+
interface Queue {
|
|
870
|
+
enqueue(runId: RunId, stepId: StepId, opts?: QueueEnqueueOpts): Promise<void>;
|
|
871
|
+
dequeue(opts: QueueDequeueOpts): Promise<readonly QueueMessage[]>;
|
|
872
|
+
ack(receipt: string): Promise<void>;
|
|
873
|
+
nack(receipt: string, opts?: {
|
|
874
|
+
delayMs?: Millis;
|
|
875
|
+
}): Promise<void>;
|
|
876
|
+
extend(receipt: string, leaseMs: Millis): Promise<void>;
|
|
877
|
+
ensureSchema?(): Promise<void>;
|
|
878
|
+
inspect?(runId: RunId): Promise<readonly QueueInspectEntry[]>;
|
|
879
|
+
withTx?(tx: Tx): Queue;
|
|
880
|
+
}
|
|
881
|
+
interface Clock {
|
|
882
|
+
now(): Date;
|
|
883
|
+
sleep(ms: Millis, signal?: AbortSignal): Promise<void>;
|
|
884
|
+
}
|
|
885
|
+
type RunStatus = "pending" | "running" | "completed" | "failed" | "canceled";
|
|
886
|
+
type StepStatus = "pending" | "running" | "completed" | "failed" | "canceled" | "skipped";
|
|
887
|
+
|
|
888
|
+
type ReplayMode = "inspect" | "continue";
|
|
889
|
+
interface ReplayOpts {
|
|
890
|
+
readonly mode: ReplayMode;
|
|
891
|
+
readonly allowDrift?: boolean;
|
|
892
|
+
readonly fireHooks?: boolean;
|
|
893
|
+
readonly from?: StepId;
|
|
894
|
+
}
|
|
895
|
+
interface OperatorAuditOpts {
|
|
896
|
+
readonly actor: string;
|
|
897
|
+
readonly note?: string;
|
|
898
|
+
}
|
|
899
|
+
interface Operator {
|
|
900
|
+
skip(runId: RunId, stepId: StepId, opts: OperatorAuditOpts): Promise<void>;
|
|
901
|
+
retry(runId: RunId, stepId: StepId, opts: OperatorAuditOpts): Promise<void>;
|
|
902
|
+
abort(runId: RunId, opts: OperatorAuditOpts): Promise<void>;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export { type ParentRef as $, type AttemptNumber as A, type BackoffStrategy as B, type CancelArgs as C, DEFAULT_REAPER_INTERVAL_MS as D, type LogLevel as E, type Fact as F, type GlobalFact as G, type Logger as H, type InferSchemaInput as I, type Json as J, type MatchArmGuard as K, type LeaseReapedFact as L, type MatchArm as M, type MatchArmOtherwise as N, type MatchArmOutput as O, type MatchArmSelectedFact as P, type MatchArmShape as Q, type MatchGuardConfig as R, type Millis as S, type NeedRef as T, type NeedsMap as U, type NeedsOutputs as V, type OnceRecordedFact as W, type Operator as X, type OperatorAuditOpts as Y, type Optional as Z, type ParentLink as _, type Builder as a, type Store as a$, type PrunableStatus as a0, type PruneOpts as a1, type PruneResult as a2, type QueryRunsOpts as a3, type QueryRunsResult as a4, type QueryRunsWhere as a5, type Queue as a6, type QueueDequeueOpts as a7, type QueueEnqueueOpts as a8, type QueueInspectEntry as a9, type SnapshotGoneDisposition as aA, type SnapshotGonePolicy as aB, StandardSchemaV1 as aC, type Step as aD, type StepAbortRequestedFact as aE, type StepCancelCause as aF, type StepCanceledFact as aG, type StepCompleteEvent as aH, type StepCompletedFact as aI, type StepCtx as aJ, type StepErrorEvent as aK, type StepEvent as aL, type StepFailedFact as aM, type StepId as aN, type StepKind as aO, type StepMap as aP, type StepOutput as aQ, type StepResetFact as aR, type StepRetriedFact as aS, type StepRetryEvent as aT, type StepRunStatus as aU, type StepSkippedFact as aV, type StepStartEvent as aW, type StepStartedFact as aX, type StepState as aY, type StepStatus as aZ, type StepView as a_, type QueueMessage as aa, type ReapedLease as ab, type ReaperDecision as ac, type Register as ad, type ReplayMode as ae, type ReplayOpts as af, type Resolved as ag, type ResolvedConcurrency as ah, type ResolvedNeeds as ai, type RetryPolicy as aj, type RowDelta as ak, type RunCancelCause as al, type RunDescription as am, type RunId as an, type RunPhase as ao, type RunState as ap, type RunStatus as aq, type RunSummary as ar, type RunView as as, type SerializedError as at, type SettleSignalResult as au, type SignalBufferedFact as av, type SignalConfig as aw, type SignalReceivedEvent as ax, type SignalReceivedFact as ay, type SkipReason as az, type ClaimToken as b, type StreamEvent as b0, type StreamTransport as b1, type StreamingStepCtx as b2, type StreamingTaskConfig as b3, type StringKeyOf as b4, type SubflowConfig as b5, type SubflowStepOutput as b6, type TaskConfig as b7, type TimedOutSignal as b8, type Tx as b9, type Worker as ba, type WorkerConfig as bb, type WorkerRunOnceOpts as bc, type WorkerRunResult as bd, type WorkerRunUntilEmptyOpts as be, attemptOf as bf, decideExpiredLeaseAction as bg, errorOf as bh, foldRun as bi, isStepTerminal as bj, isTerminalRun as bk, outputOf as bl, resolvedOf as bm, rowDeltaOf as bn, runStatusOf as bo, stepStateOf as bp, stepStatusOf as bq, unwrap as br, type Clock as c, type ConcurrencyMode as d, type FactKind as e, type Flow as f, type FlowCanceledByConcurrencyFact as g, type FlowCanceledByOperatorFact as h, type FlowCanceledExplicitlyFact as i, type FlowCanceledFact as j, type FlowCompleteEvent as k, type FlowCompletedFact as l, type FlowConcurrency as m, type FlowConfig as n, type FlowErrorEvent as o, type FlowEvent as p, type FlowFailedFact as q, type FlowHooks as r, type FlowIdOf as s, type FlowInput as t, type FlowOutput as u, type FlowRefUpdatedFact as v, type FlowStartEvent as w, type FlowStartedFact as x, type InferSchemaOutput as y, type LogEntry as z };
|