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