@nagi-js/core 0.1.1-rc.18 → 0.1.1-rc.20
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 +49 -870
- package/dist/index.js +634 -2307
- 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-DFSYjJE3.d.ts +906 -0
- package/package.json +6 -1
|
@@ -0,0 +1,906 @@
|
|
|
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
|
+
type DriftPolicy = "freeze" | "synthesize";
|
|
693
|
+
interface WorkerRunOnceOpts {
|
|
694
|
+
readonly maxSteps?: number;
|
|
695
|
+
}
|
|
696
|
+
interface WorkerRunUntilEmptyOpts {
|
|
697
|
+
readonly deadline?: number;
|
|
698
|
+
}
|
|
699
|
+
interface WorkerRunResult {
|
|
700
|
+
readonly processed: number;
|
|
701
|
+
}
|
|
702
|
+
interface Worker {
|
|
703
|
+
run(): Promise<void>;
|
|
704
|
+
runOnce(opts?: WorkerRunOnceOpts): Promise<WorkerRunResult>;
|
|
705
|
+
runUntilEmpty(opts?: WorkerRunUntilEmptyOpts): Promise<WorkerRunResult>;
|
|
706
|
+
}
|
|
707
|
+
type ClaimToken = string & {
|
|
708
|
+
readonly __brand: "ClaimToken";
|
|
709
|
+
};
|
|
710
|
+
interface SerializedError {
|
|
711
|
+
readonly name: string;
|
|
712
|
+
readonly message: string;
|
|
713
|
+
readonly stack?: string;
|
|
714
|
+
readonly cause?: Json;
|
|
715
|
+
}
|
|
716
|
+
type SettleSignalResult = {
|
|
717
|
+
readonly tag: "delivered";
|
|
718
|
+
readonly attempt: AttemptNumber;
|
|
719
|
+
readonly payload: Json;
|
|
720
|
+
readonly signalName?: string;
|
|
721
|
+
} | {
|
|
722
|
+
readonly tag: "buffered";
|
|
723
|
+
} | {
|
|
724
|
+
readonly tag: "noop";
|
|
725
|
+
};
|
|
726
|
+
interface TimedOutSignal {
|
|
727
|
+
readonly runId: RunId;
|
|
728
|
+
readonly stepId: StepId;
|
|
729
|
+
readonly attempt: AttemptNumber;
|
|
730
|
+
readonly fireAt: Date;
|
|
731
|
+
}
|
|
732
|
+
interface Store {
|
|
733
|
+
appendFact(runId: RunId, fact: Fact): Promise<void>;
|
|
734
|
+
loadRunState(runId: RunId): Promise<RunState>;
|
|
735
|
+
settleSignal(args: {
|
|
736
|
+
readonly runId: RunId;
|
|
737
|
+
readonly stepId: StepId;
|
|
738
|
+
readonly at: Date;
|
|
739
|
+
readonly incoming?: {
|
|
740
|
+
readonly payload: Json;
|
|
741
|
+
readonly signalName?: string;
|
|
742
|
+
};
|
|
743
|
+
}): Promise<SettleSignalResult>;
|
|
744
|
+
tryStartRun(runId: RunId, fact: FlowStartedFact, concurrency?: {
|
|
745
|
+
readonly key: string;
|
|
746
|
+
readonly mode: ConcurrencyMode;
|
|
747
|
+
}): Promise<{
|
|
748
|
+
readonly started: boolean;
|
|
749
|
+
readonly canceled: ReadonlyArray<{
|
|
750
|
+
readonly runId: RunId;
|
|
751
|
+
readonly fact: FlowCanceledByConcurrencyFact;
|
|
752
|
+
}>;
|
|
753
|
+
}>;
|
|
754
|
+
tryStartRunOnTx(tx: Tx, runId: RunId, fact: FlowStartedFact, concurrency?: {
|
|
755
|
+
readonly key: string;
|
|
756
|
+
readonly mode: ConcurrencyMode;
|
|
757
|
+
}): Promise<{
|
|
758
|
+
readonly started: boolean;
|
|
759
|
+
readonly canceled: ReadonlyArray<{
|
|
760
|
+
readonly runId: RunId;
|
|
761
|
+
readonly fact: FlowCanceledByConcurrencyFact;
|
|
762
|
+
}>;
|
|
763
|
+
}>;
|
|
764
|
+
claimStep(runId: RunId, stepId: StepId, attempt: AttemptNumber): Promise<ClaimToken | null>;
|
|
765
|
+
extendLease(runId: RunId, stepId: StepId, attempt: AttemptNumber, leaseMs: Millis): Promise<void>;
|
|
766
|
+
sweepLeases(args: {
|
|
767
|
+
readonly now: Date;
|
|
768
|
+
readonly queue: Queue;
|
|
769
|
+
readonly limit?: number;
|
|
770
|
+
}): Promise<readonly ReapedLease[]>;
|
|
771
|
+
upsertTimer(runId: RunId, stepId: StepId, fireAt: Date): Promise<void>;
|
|
772
|
+
sweepSignalTimeouts(args: {
|
|
773
|
+
readonly now: Date;
|
|
774
|
+
readonly limit?: number;
|
|
775
|
+
}): Promise<readonly TimedOutSignal[]>;
|
|
776
|
+
settleStep(runId: RunId, stepId: StepId, fact: StepCompletedFact | StepFailedFact): Promise<void>;
|
|
777
|
+
recordOnce(runId: RunId, stepId: StepId, scope: string, value: Json): Promise<void>;
|
|
778
|
+
getOnce(runId: RunId, stepId: StepId, scope: string): Promise<Json | null>;
|
|
779
|
+
runStep<T extends Json>(runId: RunId, stepId: StepId, attempt: AttemptNumber, body: (tx: Tx) => Promise<{
|
|
780
|
+
readonly output: T;
|
|
781
|
+
readonly fact: StepCompletedFact | StepFailedFact | StepCanceledFact;
|
|
782
|
+
}>): Promise<T>;
|
|
783
|
+
upsertSnapshot(args: {
|
|
784
|
+
readonly flowHash: string;
|
|
785
|
+
readonly flowId: string;
|
|
786
|
+
readonly dag: Json;
|
|
787
|
+
}): Promise<void>;
|
|
788
|
+
getRef(flowId: string): Promise<string | null>;
|
|
789
|
+
setRef(flowId: string, flowHash: string): Promise<void>;
|
|
790
|
+
loadSnapshot(flowHash: string): Promise<{
|
|
791
|
+
readonly flowId: string;
|
|
792
|
+
readonly dag: Json;
|
|
793
|
+
} | null>;
|
|
794
|
+
appendGlobalFact(fact: GlobalFact): Promise<void>;
|
|
795
|
+
queryRuns(opts: QueryRunsOpts): Promise<QueryRunsResult>;
|
|
796
|
+
describe(runId: RunId): Promise<RunDescription>;
|
|
797
|
+
listChildren(parentRunId: RunId): Promise<ReadonlyArray<RunId>>;
|
|
798
|
+
pruneFacts(opts: Required<PruneOpts>): Promise<PruneResult>;
|
|
799
|
+
readonly stream?: StreamTransport;
|
|
800
|
+
}
|
|
801
|
+
interface StreamTransport {
|
|
802
|
+
subscribeStream(runId: RunId, stepId: StepId, opts?: {
|
|
803
|
+
readonly replayBuffered?: boolean;
|
|
804
|
+
}): AsyncIterable<StreamEvent<Json>>;
|
|
805
|
+
publishChunk(runId: RunId, stepId: StepId, chunk: Json): void;
|
|
806
|
+
}
|
|
807
|
+
interface QueryRunsWhere<FlowId extends string = string> {
|
|
808
|
+
readonly flowId?: FlowId;
|
|
809
|
+
readonly status?: ReadonlyArray<RunStatus>;
|
|
810
|
+
readonly input?: Record<string, Json>;
|
|
811
|
+
}
|
|
812
|
+
type QueryRunsOpts<FlowId extends string = string> = {
|
|
813
|
+
readonly where?: QueryRunsWhere<FlowId>;
|
|
814
|
+
readonly latest: true;
|
|
815
|
+
readonly limit?: never;
|
|
816
|
+
readonly cursor?: never;
|
|
817
|
+
} | {
|
|
818
|
+
readonly where?: QueryRunsWhere<FlowId>;
|
|
819
|
+
readonly latest?: false;
|
|
820
|
+
readonly limit?: number;
|
|
821
|
+
readonly cursor?: string;
|
|
822
|
+
};
|
|
823
|
+
interface RunSummary<FlowId extends string = string> {
|
|
824
|
+
readonly runId: RunId;
|
|
825
|
+
readonly flowId: FlowId;
|
|
826
|
+
readonly status: RunStatus;
|
|
827
|
+
readonly startedAt: Date;
|
|
828
|
+
readonly completedAt: Date | null;
|
|
829
|
+
readonly input: Json;
|
|
830
|
+
}
|
|
831
|
+
interface QueryRunsResult<FlowId extends string = string> {
|
|
832
|
+
readonly runs: ReadonlyArray<RunSummary<FlowId>>;
|
|
833
|
+
readonly cursor: string | null;
|
|
834
|
+
}
|
|
835
|
+
type PrunableStatus = Extract<RunStatus, "completed" | "failed" | "canceled">;
|
|
836
|
+
interface PruneOpts {
|
|
837
|
+
readonly olderThan: Date;
|
|
838
|
+
readonly statuses?: ReadonlyArray<PrunableStatus>;
|
|
839
|
+
readonly batchSize?: number;
|
|
840
|
+
readonly keepSummary?: boolean;
|
|
841
|
+
}
|
|
842
|
+
interface PruneResult {
|
|
843
|
+
readonly runsPruned: number;
|
|
844
|
+
readonly factsPruned: number;
|
|
845
|
+
}
|
|
846
|
+
interface QueueMessage {
|
|
847
|
+
readonly receipt: string;
|
|
848
|
+
readonly runId: RunId;
|
|
849
|
+
readonly stepId: StepId;
|
|
850
|
+
readonly payload: Json;
|
|
851
|
+
readonly attempt: AttemptNumber;
|
|
852
|
+
readonly readCount: number;
|
|
853
|
+
readonly flowId?: string;
|
|
854
|
+
}
|
|
855
|
+
interface QueueDequeueOpts {
|
|
856
|
+
readonly count: number;
|
|
857
|
+
}
|
|
858
|
+
interface QueueEnqueueOpts {
|
|
859
|
+
readonly attempt?: AttemptNumber;
|
|
860
|
+
readonly delayMs?: Millis;
|
|
861
|
+
readonly payload?: Json;
|
|
862
|
+
readonly flowId?: string;
|
|
863
|
+
}
|
|
864
|
+
interface QueueInspectEntry {
|
|
865
|
+
readonly stepId: StepId;
|
|
866
|
+
readonly attempt: AttemptNumber;
|
|
867
|
+
readonly readCount: number;
|
|
868
|
+
readonly visibleAt: Date;
|
|
869
|
+
}
|
|
870
|
+
interface Queue {
|
|
871
|
+
enqueue(runId: RunId, stepId: StepId, opts?: QueueEnqueueOpts): Promise<void>;
|
|
872
|
+
dequeue(opts: QueueDequeueOpts): Promise<readonly QueueMessage[]>;
|
|
873
|
+
ack(receipt: string): Promise<void>;
|
|
874
|
+
nack(receipt: string, opts?: {
|
|
875
|
+
delayMs?: Millis;
|
|
876
|
+
}): Promise<void>;
|
|
877
|
+
extend(receipt: string, leaseMs: Millis): Promise<void>;
|
|
878
|
+
ensureSchema?(): Promise<void>;
|
|
879
|
+
inspect?(runId: RunId): Promise<readonly QueueInspectEntry[]>;
|
|
880
|
+
withTx?(tx: Tx): Queue;
|
|
881
|
+
}
|
|
882
|
+
interface Clock {
|
|
883
|
+
now(): Date;
|
|
884
|
+
sleep(ms: Millis, signal?: AbortSignal): Promise<void>;
|
|
885
|
+
}
|
|
886
|
+
type RunStatus = "pending" | "running" | "completed" | "failed" | "canceled";
|
|
887
|
+
type StepStatus = "pending" | "running" | "completed" | "failed" | "canceled" | "skipped";
|
|
888
|
+
|
|
889
|
+
type ReplayMode = "inspect" | "continue";
|
|
890
|
+
interface ReplayOpts {
|
|
891
|
+
readonly mode: ReplayMode;
|
|
892
|
+
readonly allowDrift?: boolean;
|
|
893
|
+
readonly fireHooks?: boolean;
|
|
894
|
+
readonly from?: StepId;
|
|
895
|
+
}
|
|
896
|
+
interface OperatorAuditOpts {
|
|
897
|
+
readonly actor: string;
|
|
898
|
+
readonly note?: string;
|
|
899
|
+
}
|
|
900
|
+
interface Operator {
|
|
901
|
+
skip(runId: RunId, stepId: StepId, opts: OperatorAuditOpts): Promise<void>;
|
|
902
|
+
retry(runId: RunId, stepId: StepId, opts: OperatorAuditOpts): Promise<void>;
|
|
903
|
+
abort(runId: RunId, opts: OperatorAuditOpts): Promise<void>;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
export { type ParentLink as $, type AttemptNumber as A, type BackoffStrategy as B, type CancelArgs as C, DEFAULT_REAPER_INTERVAL_MS as D, type LogEntry as E, type Fact as F, type GlobalFact as G, type LogLevel as H, type InferSchemaInput as I, type Json as J, type Logger as K, type LeaseReapedFact as L, type MatchArm as M, type MatchArmGuard as N, type MatchArmOtherwise as O, type MatchArmOutput as P, type MatchArmSelectedFact as Q, type MatchArmShape as R, type MatchGuardConfig as S, type Millis as T, type NeedRef as U, type NeedsMap as V, type NeedsOutputs as W, type OnceRecordedFact as X, type Operator as Y, type OperatorAuditOpts as Z, type Optional as _, type Builder as a, type StepView as a$, type ParentRef as a0, type PrunableStatus as a1, type PruneOpts as a2, type PruneResult as a3, type QueryRunsOpts as a4, type QueryRunsResult as a5, type QueryRunsWhere as a6, type Queue as a7, type QueueDequeueOpts as a8, type QueueEnqueueOpts as a9, type SkipReason as aA, type SnapshotGoneDisposition as aB, type SnapshotGonePolicy as aC, StandardSchemaV1 as aD, type Step as aE, type StepAbortRequestedFact as aF, type StepCancelCause as aG, type StepCanceledFact as aH, type StepCompleteEvent as aI, type StepCompletedFact as aJ, type StepCtx as aK, type StepErrorEvent as aL, type StepEvent as aM, type StepFailedFact as aN, type StepId as aO, type StepKind as aP, type StepMap as aQ, type StepOutput as aR, type StepResetFact as aS, type StepRetriedFact as aT, type StepRetryEvent as aU, type StepRunStatus as aV, type StepSkippedFact as aW, type StepStartEvent as aX, type StepStartedFact as aY, type StepState as aZ, type StepStatus as a_, type QueueInspectEntry as aa, type QueueMessage as ab, type ReapedLease as ac, type ReaperDecision as ad, type Register as ae, type ReplayMode as af, type ReplayOpts as ag, type Resolved as ah, type ResolvedConcurrency as ai, type ResolvedNeeds as aj, type RetryPolicy as ak, type RowDelta as al, type RunCancelCause as am, type RunDescription as an, type RunId as ao, type RunPhase as ap, type RunState as aq, type RunStatus as ar, type RunSummary as as, type RunView as at, type SerializedError as au, type SettleSignalResult as av, type SignalBufferedFact as aw, type SignalConfig as ax, type SignalReceivedEvent as ay, type SignalReceivedFact as az, type ClaimToken as b, type Store as b0, type StreamEvent as b1, type StreamTransport as b2, type StreamingStepCtx as b3, type StreamingTaskConfig as b4, type StringKeyOf as b5, type SubflowConfig as b6, type SubflowStepOutput as b7, type TaskConfig as b8, type TimedOutSignal as b9, type Tx as ba, type Worker as bb, type WorkerConfig as bc, type WorkerRunOnceOpts as bd, type WorkerRunResult as be, type WorkerRunUntilEmptyOpts as bf, attemptOf as bg, decideExpiredLeaseAction as bh, errorOf as bi, foldRun as bj, isStepTerminal as bk, isTerminalRun as bl, outputOf as bm, resolvedOf as bn, rowDeltaOf as bo, runStatusOf as bp, stepStateOf as bq, stepStatusOf as br, unwrap as bs, type Clock as c, type ConcurrencyMode as d, type DriftPolicy as e, type FactKind as f, type Flow as g, type FlowCanceledByConcurrencyFact as h, type FlowCanceledByOperatorFact as i, type FlowCanceledExplicitlyFact as j, type FlowCanceledFact as k, type FlowCompleteEvent as l, type FlowCompletedFact as m, type FlowConcurrency as n, type FlowConfig as o, type FlowErrorEvent as p, type FlowEvent as q, type FlowFailedFact as r, type FlowHooks as s, type FlowIdOf as t, type FlowInput as u, type FlowOutput as v, type FlowRefUpdatedFact as w, type FlowStartEvent as x, type FlowStartedFact as y, type InferSchemaOutput as z };
|