@demlik/tea 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -7
- package/dist/agent/index.d.ts +49 -36
- package/dist/agent/index.js +12 -8
- package/dist/chunk-4LPY67E4.js +18 -0
- package/dist/chunk-4LPY67E4.js.map +1 -0
- package/dist/chunk-5XU6ZJO2.js +533 -0
- package/dist/chunk-5XU6ZJO2.js.map +1 -0
- package/dist/{chunk-AQ6ZIMEA.js → chunk-6NG4V5SB.js} +89 -115
- package/dist/chunk-6NG4V5SB.js.map +1 -0
- package/dist/{chunk-HYDWG35Q.js → chunk-7MGXQZPW.js} +11 -9
- package/dist/chunk-7MGXQZPW.js.map +1 -0
- package/dist/{chunk-BLJ2JQSH.js → chunk-BCTEOVOU.js} +3 -3
- package/dist/{chunk-BLJ2JQSH.js.map → chunk-BCTEOVOU.js.map} +1 -1
- package/dist/chunk-CH5KTOEZ.js +710 -0
- package/dist/chunk-CH5KTOEZ.js.map +1 -0
- package/dist/chunk-CIHSHLQX.js +64 -0
- package/dist/chunk-CIHSHLQX.js.map +1 -0
- package/dist/{chunk-Z2L3LSNV.js → chunk-EHUDXAKC.js} +246 -210
- package/dist/chunk-EHUDXAKC.js.map +1 -0
- package/dist/chunk-GOX2CYIM.js +380 -0
- package/dist/chunk-GOX2CYIM.js.map +1 -0
- package/dist/chunk-IVJP3GKJ.js +104 -0
- package/dist/chunk-IVJP3GKJ.js.map +1 -0
- package/dist/{chunk-F7FMAWLA.js → chunk-MVZS5FDM.js} +13 -6
- package/dist/chunk-MVZS5FDM.js.map +1 -0
- package/dist/{chunk-LYLTKJWM.js → chunk-MYNLY3HP.js} +9 -8
- package/dist/chunk-MYNLY3HP.js.map +1 -0
- package/dist/{chunk-I5MQMJDW.js → chunk-NSIAORRY.js} +20 -30
- package/dist/chunk-NSIAORRY.js.map +1 -0
- package/dist/{chunk-MYXFNWAJ.js → chunk-QNGYQMZB.js} +4 -4
- package/dist/chunk-QNGYQMZB.js.map +1 -0
- package/dist/chunk-WT5PBPLB.js +98 -0
- package/dist/chunk-WT5PBPLB.js.map +1 -0
- package/dist/{core-CTzMJ82M.d.ts → core-BbgtiXdg.d.ts} +231 -139
- package/dist/do/index.d.ts +37 -32
- package/dist/do/index.js +21 -14
- package/dist/do/index.js.map +1 -1
- package/dist/{durable-effects-B0-qGQDy.d.ts → durable-effects-7MTK_jnj.d.ts} +1 -1
- package/dist/effect/index.d.ts +151 -0
- package/dist/effect/index.js +98 -0
- package/dist/effect/index.js.map +1 -0
- package/dist/extension/index.d.ts +6 -7
- package/dist/extension/index.js +3 -2
- package/dist/extension/index.js.map +1 -1
- package/dist/flow/index.d.ts +68 -70
- package/dist/flow/index.js +32 -27
- package/dist/flow/index.js.map +1 -1
- package/dist/idempotency/index.d.ts +6 -7
- package/dist/idempotency/index.js +4 -2
- package/dist/{index-DJWIER_3.d.ts → index-7vV8xmsD.d.ts} +1 -1
- package/dist/{index-NjrT3fL2.d.ts → index-Bz5Rh9Ga.d.ts} +19 -96
- package/dist/index-CjFDUBeq.d.ts +207 -0
- package/dist/{index-6A7dB8f6.d.ts → index-CkFYA9Y6.d.ts} +14 -16
- package/dist/{index-B5BZ-_cT.d.ts → index-Cou86-GX.d.ts} +189 -108
- package/dist/{index-TvRb1KVf.d.ts → index-DU6JpQ8G.d.ts} +1 -1
- package/dist/{index-q0hXFeZ0.d.ts → index-Xufl55W8.d.ts} +286 -215
- package/dist/{index-4vZzljCD.d.ts → index-_dOR3xqA.d.ts} +57 -45
- package/dist/index.d.ts +181 -385
- package/dist/index.js +2 -1
- package/dist/jev/index.d.ts +147 -99
- package/dist/jev/index.js +329 -233
- package/dist/jev/index.js.map +1 -1
- package/dist/{machine-CdIcN2Xm.d.ts → machine-BQzTV8On.d.ts} +171 -280
- package/dist/machine-viz/index.d.ts +5 -5
- package/dist/machine-viz/index.js +8 -4
- package/dist/machine-viz/index.js.map +1 -1
- package/dist/mem/index.d.ts +3 -4
- package/dist/mem/index.js +2 -1
- package/dist/mem/index.js.map +1 -1
- package/dist/node/index.d.ts +119 -78
- package/dist/node/index.js +52 -38
- package/dist/node/index.js.map +1 -1
- package/dist/paginate/index.d.ts +27 -33
- package/dist/paginate/index.js +6 -4
- package/dist/parity/index.d.ts +4 -5
- package/dist/parity/index.js +3 -2
- package/dist/parity/index.js.map +1 -1
- package/dist/pbt/index.d.ts +2 -2
- package/dist/pbt/index.js +2 -1
- package/dist/pbt/index.js.map +1 -1
- package/dist/persistence/index.d.ts +6 -7
- package/dist/persistence/index.js +5 -3
- package/dist/promise/index.d.ts +186 -0
- package/dist/promise/index.js +5 -0
- package/dist/promise/index.js.map +1 -0
- package/dist/protocol-ClRZBhHQ.d.ts +53 -0
- package/dist/react/index.d.ts +36 -17
- package/dist/react/index.js +27 -4
- package/dist/react/index.js.map +1 -1
- package/dist/resilience/index.d.ts +63 -455
- package/dist/resilience/index.js +37 -483
- package/dist/resilience/index.js.map +1 -1
- package/dist/{runtime-types-LWDoi943.d.ts → runtime-types-CiVpC0HN.d.ts} +131 -388
- package/dist/testing/index.d.ts +165 -15
- package/dist/testing/index.js +104 -3
- package/dist/testing/index.js.map +1 -1
- package/dist/timing/index.d.ts +25 -22
- package/dist/timing/index.js +4 -3
- package/dist/timing/index.js.map +1 -1
- package/dist/{types-DP3f5NIl.d.ts → types-LxZxGYda.d.ts} +2 -2
- package/dist/work-queue/index.d.ts +5 -6
- package/package.json +18 -5
- package/dist/chunk-AQ6ZIMEA.js.map +0 -1
- package/dist/chunk-F2US5BW6.js +0 -72
- package/dist/chunk-F2US5BW6.js.map +0 -1
- package/dist/chunk-F7FMAWLA.js.map +0 -1
- package/dist/chunk-HUKZQX6U.js +0 -97
- package/dist/chunk-HUKZQX6U.js.map +0 -1
- package/dist/chunk-HYDWG35Q.js.map +0 -1
- package/dist/chunk-I5MQMJDW.js.map +0 -1
- package/dist/chunk-LYLTKJWM.js.map +0 -1
- package/dist/chunk-MYXFNWAJ.js.map +0 -1
- package/dist/chunk-RQULHGYH.js +0 -1804
- package/dist/chunk-RQULHGYH.js.map +0 -1
- package/dist/chunk-Z2L3LSNV.js.map +0 -1
- package/dist/index-DMCeMPMJ.d.ts +0 -272
|
@@ -1,59 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as CmdOf, b as CmdDef, g as TaggedError, r as MalformedResult, T as TimerDeps, C as Cmd } from './core-BbgtiXdg.js';
|
|
2
2
|
import { RetryState, AnyRetryPolicy } from './retry-backoff/index.js';
|
|
3
|
-
import { T as TtlCache, D as DeadlineExceeded, a as DeadlineSub } from './index-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The closed set of cross-module Msg/Cmd discriminant strings. Declared `as
|
|
7
|
-
* const` so each entry is usable as both a value (construction / reducer keys /
|
|
8
|
-
* switch labels) and, via `typeof MsgType.X`, a literal type (`readonly type:`
|
|
9
|
-
* fields). The single source of truth for issue #60.
|
|
10
|
-
*/
|
|
11
|
-
declare const MsgType: {
|
|
12
|
-
/** The "run the port for `key`" effect Cmd resilient-call emits. */
|
|
13
|
-
readonly ResilientRun: "resilient_run";
|
|
14
|
-
/** PRIVATE success settle Msg (read only by `agentEvents`, #47). */
|
|
15
|
-
readonly ResilientOk: "resilient_ok";
|
|
16
|
-
/** Failure settle Msg — routed to the `fail` verb (back off via retry). */
|
|
17
|
-
readonly ResilientErr: "resilient_err";
|
|
18
|
-
/** Begin a run. */
|
|
19
|
-
readonly AgentStart: "agent_start";
|
|
20
|
-
/** PRIVATE tool-fan-out success settle Msg (read only by `agentEvents`, #47). */
|
|
21
|
-
readonly AgentToolOk: "agent_tool_ok";
|
|
22
|
-
/** Tool-fan-out failure settle Msg. */
|
|
23
|
-
readonly AgentToolErr: "agent_tool_err";
|
|
24
|
-
/**
|
|
25
|
-
* Re-fire the one outstanding effect on rehydrate (the do↔agent seam). Fired
|
|
26
|
-
* by `do/host`'s `autoBoot` via the typed `agentBootMsg` constructor, matched
|
|
27
|
-
* by the agent reducer — see `AgentBootPort` in `../agent`.
|
|
28
|
-
*/
|
|
29
|
-
readonly AgentBoot: "agent_boot";
|
|
30
|
-
/**
|
|
31
|
-
* Stop the run from outside and settle it `cancelled` — what an `AbortSignal`
|
|
32
|
-
* handed to `driveToDone` / a defined agent's `run` dispatches on abort. A
|
|
33
|
-
* transition, never a throw: the outcome lands in the Model, so a reload reads
|
|
34
|
-
* a run that ended rather than one to resume.
|
|
35
|
-
*/
|
|
36
|
-
readonly AgentCancel: "agent_cancel";
|
|
37
|
-
/**
|
|
38
|
-
* The "summarize the oldest N turns" effect Cmd the agent emits when its
|
|
39
|
-
* `CompactionPolicy` asks to compact before a brain call. A DEDICATED
|
|
40
|
-
* round-trip (design B1), distinct from the brain call's `resilient_run`, so
|
|
41
|
-
* compaction is its own honest `Awaiting` state — see `../agent`.
|
|
42
|
-
*/
|
|
43
|
-
readonly CompactRun: "compact_run";
|
|
44
|
-
/** Compaction round-trip resolved — carries the summary text the fold-back folds. */
|
|
45
|
-
readonly CompactOk: "compact_ok";
|
|
46
|
-
/** Compaction round-trip failed (exhausted retry) — surfaced as data, not a stall. */
|
|
47
|
-
readonly CompactErr: "compact_err";
|
|
48
|
-
/** Refresh port resolved — carries the fresh `Token`. */
|
|
49
|
-
readonly TokenRefreshed: "token_refreshed";
|
|
50
|
-
/** Refresh port rejected — carries the rejection (errors are data). */
|
|
51
|
-
readonly TokenRefreshFailed: "token_refresh_failed";
|
|
52
|
-
/** The 401 the consumer dispatches when a guarded call comes back unauthorized. */
|
|
53
|
-
readonly Unauthorized: "unauthorized";
|
|
54
|
-
};
|
|
55
|
-
/** The union of every discriminant string in the protocol. */
|
|
56
|
-
type MsgTypeValue = (typeof MsgType)[keyof typeof MsgType];
|
|
3
|
+
import { T as TtlCache, D as DeadlineExceeded, a as DeadlineSub } from './index-Xufl55W8.js';
|
|
57
4
|
|
|
58
5
|
/**
|
|
59
6
|
* @packageDocumentation
|
|
@@ -404,13 +351,47 @@ interface DeadlineConfig {
|
|
|
404
351
|
/** Budget of in-process time from the moment a call starts, in ms. */
|
|
405
352
|
readonly ms: number;
|
|
406
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* The family every unnamed knob speaks: `resilient_run` / `resilient_run_ok` /
|
|
356
|
+
* `resilient_run_err`. Identical to the `MsgType.Resilient*` literals, which
|
|
357
|
+
* stay the vocabulary of every knob that passes no name.
|
|
358
|
+
*/
|
|
359
|
+
declare const DEFAULT_RESILIENT_NAME = "resilient";
|
|
360
|
+
type DefaultResilientName = typeof DEFAULT_RESILIENT_NAME;
|
|
361
|
+
/** The run Cmd's `type` for the `N` family. */
|
|
362
|
+
type ResilientRunType<N extends string> = `${N}_run`;
|
|
363
|
+
/** The success settle Msg's `type` for the `N` family — minted by the engine. */
|
|
364
|
+
type ResilientOkType<N extends string> = `${N}_run_ok`;
|
|
365
|
+
/** The failure settle Msg's `type` for the `N` family — minted by the engine. */
|
|
366
|
+
type ResilientErrType<N extends string> = `${N}_run_err`;
|
|
407
367
|
/**
|
|
408
368
|
* The resilience knob. EVERY field is optional: omit a brick and its gate is
|
|
409
369
|
* skipped entirely (the slice still carries a default brick state so the shape
|
|
410
370
|
* stays uniform across configs, but the gate is never consulted). An empty
|
|
411
371
|
* config `{}` is a valid pass-through — a bare effect with no resilience at all.
|
|
372
|
+
*
|
|
373
|
+
* `N` is the knob's Msg-name family (see {@link ResilientName}); it is carried on
|
|
374
|
+
* the config so the run Cmd and the two settle Msgs are named from ONE place.
|
|
412
375
|
*/
|
|
413
|
-
interface ResilientConfig {
|
|
376
|
+
interface ResilientConfig<N extends string = DefaultResilientName> {
|
|
377
|
+
/**
|
|
378
|
+
* What this knob's Cmd and settle Msgs are called: `<name>_run`, and the
|
|
379
|
+
* `<name>_run_ok` / `<name>_run_err` the engine mints from the run handler's
|
|
380
|
+
* outcome. Omit it and the family is `resilient` — `resilient_run` /
|
|
381
|
+
* `resilient_run_ok` / `resilient_run_err`.
|
|
382
|
+
*
|
|
383
|
+
* Name a knob when a machine holds more than one of the resilient family.
|
|
384
|
+
* Two unnamed knobs meet in ONE `resilient_run_ok` cell whose payload is the union
|
|
385
|
+
* of both results, and the consumer discriminates by hand on `key` — which the
|
|
386
|
+
* type checker cannot see. Under distinct names each knob settles into its own
|
|
387
|
+
* cell, already narrowed to its own payload.
|
|
388
|
+
*
|
|
389
|
+
* The name is a value AND a type: the settle Msg types are generic in `N`, and
|
|
390
|
+
* `N` is not inferable from `I` / `R`, so an opted-in knob spells all three
|
|
391
|
+
* type arguments — `createResilientCall<In, Out, "jev">({ name: "jev", … })`.
|
|
392
|
+
* The `name` field is typed at `N`, so the two cannot drift apart.
|
|
393
|
+
*/
|
|
394
|
+
readonly name?: N;
|
|
414
395
|
/**
|
|
415
396
|
* The backoff brick. Omit and a failure is terminal (no backoff, no timer).
|
|
416
397
|
*
|
|
@@ -418,7 +399,7 @@ interface ResilientConfig {
|
|
|
418
399
|
* wall-clock outage budget (`DurationRetryPolicy`), or explicit
|
|
419
400
|
* `unbounded: true`. A duration bound needs no extra wiring: every path that
|
|
420
401
|
* records a failure already holds the instant it was observed as DATA —
|
|
421
|
-
* `
|
|
402
|
+
* `settle`'s `msg.at` (stamped at the interpret boundary) and `gate`'s `at`
|
|
422
403
|
* (the caller's `attempt` / the retry timer's `atMs`) — so the streak clock
|
|
423
404
|
* is fed from a Msg, never from a `Date.now()` inside a verb (invariant 2).
|
|
424
405
|
*/
|
|
@@ -461,7 +442,7 @@ interface CallBudget {
|
|
|
461
442
|
* `phase` so each phase carries only its own data (pattern 11):
|
|
462
443
|
*
|
|
463
444
|
* - `idle` — never attempted, or fully settled and forgotten.
|
|
464
|
-
* - `running` — the effect Cmd is out; awaiting `
|
|
445
|
+
* - `running` — the effect Cmd is out; awaiting `settle`.
|
|
465
446
|
* Carries the deadline budget ({@link CallBudget}) and the
|
|
466
447
|
* last `input` so a retry can re-issue it.
|
|
467
448
|
* - `waiting_retry` — a transient failure backed off; the retry timer is armed
|
|
@@ -517,13 +498,30 @@ interface ResilientState<I, R> {
|
|
|
517
498
|
readonly retry: Readonly<Record<string, RetryState>>;
|
|
518
499
|
readonly cache: TtlCache<R>;
|
|
519
500
|
readonly calls: Readonly<Record<string, CallPhase<I, R>>>;
|
|
501
|
+
/**
|
|
502
|
+
* The instant of the latest clocked transition this slice saw — the `at` of
|
|
503
|
+
* the last `attempt` / `resume` / `settleFailed`, settled Msg or timer fire.
|
|
504
|
+
* `timer` counts the soonest deadline down from it, so the built-in `timer`
|
|
505
|
+
* Sub gets a relative `ms` without anything reading a clock. `0` until the
|
|
506
|
+
* first clocked transition.
|
|
507
|
+
*/
|
|
508
|
+
readonly clockMs: number;
|
|
520
509
|
}
|
|
521
510
|
/**
|
|
522
|
-
* The
|
|
523
|
-
*
|
|
524
|
-
* is
|
|
511
|
+
* The failures a run handler may return (ADR 0021). `port_rejected` is the
|
|
512
|
+
* work failing — carry the cause beside the tag (`err({ _tag: "port_rejected",
|
|
513
|
+
* cause })`); `deadline_exceeded` is a handler that timed the work out itself.
|
|
514
|
+
* Either one settles as `<name>_run_err` and feeds the retry / breaker. Any
|
|
515
|
+
* other failure is a contract breach and goes to the error sink.
|
|
525
516
|
*/
|
|
526
|
-
|
|
517
|
+
type RunErr = TaggedError<"port_rejected" | "deadline_exceeded">;
|
|
518
|
+
/**
|
|
519
|
+
* The one effect this knob emits: "run the work for `key` with `input`". It is
|
|
520
|
+
* `Cmd.define`d, so the handler you write for it returns an outcome and the
|
|
521
|
+
* engine mints `<name>_run_ok` / `<name>_run_err` (ADR 0021). It carries no
|
|
522
|
+
* closure — `input` is plain data (invariant 3).
|
|
523
|
+
*/
|
|
524
|
+
declare function runCmdDef<I, R, N extends string = DefaultResilientName>(name?: N): CmdDef<`${N}_run`, {
|
|
527
525
|
readonly key: string;
|
|
528
526
|
readonly input: I;
|
|
529
527
|
}, R, {
|
|
@@ -532,24 +530,109 @@ declare function runCmdDef<I, R>(): CmdDef<"resilient_run", {
|
|
|
532
530
|
} | {
|
|
533
531
|
readonly [detail: string]: unknown;
|
|
534
532
|
readonly _tag: "port_rejected";
|
|
535
|
-
}
|
|
536
|
-
type RunCmdDef<I, R> = ReturnType<typeof runCmdDef<I, R>>;
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
533
|
+
}>;
|
|
534
|
+
type RunCmdDef<I, R, N extends string = DefaultResilientName> = ReturnType<typeof runCmdDef<I, R, N>>;
|
|
535
|
+
/**
|
|
536
|
+
* The run Cmd value. `R` is its settle value — `unknown` reads any knob's run
|
|
537
|
+
* Cmd; the knob's own verbs emit it at their `R`, which is what lets a machine
|
|
538
|
+
* list `cmds: [rc.run]` and take the verbs' Cmds as its own.
|
|
539
|
+
*/
|
|
540
|
+
type RunCmd<I, N extends string = DefaultResilientName, R = unknown> = CmdOf<RunCmdDef<I, R, N>>;
|
|
541
|
+
/**
|
|
542
|
+
* The settle Msgs the engine mints from a run handler's outcome:
|
|
543
|
+
* `<name>_run_ok` carrying the handler's `value`, `<name>_run_err` carrying its
|
|
544
|
+
* declared `error`. Each carries the run Cmd it settles (`cmd.key` names the
|
|
545
|
+
* call) and the `at` the engine stamped. Both are generic in the knob's name
|
|
546
|
+
* family `N`, so two knobs named apart land in two `update` cells whose
|
|
547
|
+
* payloads are already narrowed.
|
|
548
|
+
*
|
|
549
|
+
* They are the `SettledOk` / `SettledErr` pair `Cmd.define` mints, spelled out
|
|
550
|
+
* so a helper that folds the error into a richer type of its own (llm-call's
|
|
551
|
+
* `LlmErr`, jev-ask's `JevAskErr`) can hand `settle` its Msg with `E` widened.
|
|
552
|
+
*/
|
|
553
|
+
type SucceedMsg<R, N extends string = DefaultResilientName, I = unknown> = {
|
|
554
|
+
readonly type: ResilientOkType<N>;
|
|
555
|
+
readonly cmd: RunCmd<I, N>;
|
|
556
|
+
readonly value: R;
|
|
543
557
|
readonly at: number;
|
|
544
558
|
};
|
|
545
|
-
type FailMsg = {
|
|
546
|
-
readonly type:
|
|
547
|
-
readonly
|
|
559
|
+
type FailMsg<N extends string = DefaultResilientName, I = unknown, E = RunErr | MalformedResult> = {
|
|
560
|
+
readonly type: ResilientErrType<N>;
|
|
561
|
+
readonly cmd: RunCmd<I, N>;
|
|
562
|
+
readonly error: E;
|
|
563
|
+
readonly at: number;
|
|
564
|
+
};
|
|
565
|
+
/**
|
|
566
|
+
* What `settle` reads off a settled Msg: the call's `key` (on `cmd`), the
|
|
567
|
+
* engine's `at`, and the handler's `value` or `error`. {@link SucceedMsg} and
|
|
568
|
+
* {@link FailMsg} are both one of these, so an engine-minted Msg passes
|
|
569
|
+
* straight in; a helper that settles from its own data (a fallback answer, a
|
|
570
|
+
* compaction summary) builds the record without inventing a whole run Cmd.
|
|
571
|
+
*/
|
|
572
|
+
type SettleMsg<R, N extends string = DefaultResilientName> = {
|
|
573
|
+
readonly type?: ResilientOkType<N>;
|
|
574
|
+
readonly cmd: {
|
|
575
|
+
readonly key: string;
|
|
576
|
+
};
|
|
577
|
+
readonly value: R;
|
|
578
|
+
readonly at: number;
|
|
579
|
+
} | {
|
|
580
|
+
readonly type?: ResilientErrType<N>;
|
|
581
|
+
readonly cmd: {
|
|
582
|
+
readonly key: string;
|
|
583
|
+
};
|
|
548
584
|
readonly error: unknown;
|
|
549
585
|
readonly at: number;
|
|
550
586
|
};
|
|
551
|
-
/**
|
|
552
|
-
|
|
587
|
+
/**
|
|
588
|
+
* How a settled call ended — the third thing `settle` hands back, and the only
|
|
589
|
+
* place the port's value can be read from.
|
|
590
|
+
*
|
|
591
|
+
* - `done` — the port answered; `value` is its result.
|
|
592
|
+
* - `failed` — no retry is left (or no retry brick); `error` is the last
|
|
593
|
+
* failure.
|
|
594
|
+
* - `retrying` — backed off; the retry timer is armed and the call is still
|
|
595
|
+
* live.
|
|
596
|
+
*/
|
|
597
|
+
type SettleOutcome<R> = {
|
|
598
|
+
readonly kind: "done";
|
|
599
|
+
readonly value: R;
|
|
600
|
+
} | {
|
|
601
|
+
readonly kind: "failed";
|
|
602
|
+
readonly error: unknown;
|
|
603
|
+
} | {
|
|
604
|
+
readonly kind: "retrying";
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* What `settle` returns: the settled slice, the Cmds it emitted, and the
|
|
608
|
+
* {@link SettleOutcome}. One record, so the slice update and the result read
|
|
609
|
+
* cannot be split apart in a hand-wired `update` cell.
|
|
610
|
+
*/
|
|
611
|
+
interface SettleResult<I, R, N extends string = DefaultResilientName> {
|
|
612
|
+
readonly call: ResilientState<I, R>;
|
|
613
|
+
readonly cmds: readonly RunCmd<I, N, R>[];
|
|
614
|
+
readonly outcome: SettleOutcome<R>;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* The deadline Msg tag this knob's timers dispatch, derived from its name the
|
|
618
|
+
* same way the settle Msgs are. The DEFAULT family keeps the bare
|
|
619
|
+
* `"deadline_exceeded"` literal.
|
|
620
|
+
*/
|
|
621
|
+
type ResilientDeadlineType<N extends string = DefaultResilientName> = N extends DefaultResilientName ? "deadline_exceeded" : `${N}_deadline`;
|
|
622
|
+
/**
|
|
623
|
+
* The name a deadline carries for the `N` family — `undefined` for the
|
|
624
|
+
* default family (no name at all, so the bare literal is dispatched), the name
|
|
625
|
+
* itself otherwise. One conditional, so the value and {@link
|
|
626
|
+
* ResilientDeadlineType} can never disagree about which family is unnamed.
|
|
627
|
+
*/
|
|
628
|
+
type DeadlineNameOf<N extends string = DefaultResilientName> = N extends DefaultResilientName ? undefined : N;
|
|
629
|
+
/**
|
|
630
|
+
* The retry / deadline timer Msg — a `DeadlineExceeded` whose tag is this
|
|
631
|
+
* knob's ({@link ResilientDeadlineType}), keyed by the call `key` through the
|
|
632
|
+
* Sub `id`. Bare `ResilientTimerMsg` is the default family's, so it is the same
|
|
633
|
+
* `DeadlineExceeded` it has always been.
|
|
634
|
+
*/
|
|
635
|
+
type ResilientTimerMsg<N extends string = DefaultResilientName> = DeadlineExceeded<DeadlineNameOf<N>>;
|
|
553
636
|
/**
|
|
554
637
|
* The plain-data error a deadline-failed call settles with. A `{_tag, ...}`
|
|
555
638
|
* sentinel — NEVER a `new Error(...)` — so the slice stays JSON-serializable
|
|
@@ -562,11 +645,6 @@ type DeadlineExceededError = {
|
|
|
562
645
|
readonly id: string;
|
|
563
646
|
readonly atMs: number;
|
|
564
647
|
};
|
|
565
|
-
/** Ports the consumer supplies to `handlers`. */
|
|
566
|
-
interface ResilientPorts<I, R> {
|
|
567
|
-
/** The fallible work this knob wraps. Throws on failure → routed to `fail`. */
|
|
568
|
-
readonly run: (input: I, key: string) => Promise<R>;
|
|
569
|
-
}
|
|
570
648
|
/**
|
|
571
649
|
* Build a resilient-call knob from `config`. `rng` is injected for retry
|
|
572
650
|
* jitter — pass a fixed `() => 0.5` in tests to pin backoff; defaults to
|
|
@@ -574,43 +652,46 @@ interface ResilientPorts<I, R> {
|
|
|
574
652
|
* curried onto the factory rather than threaded through every verb so callers
|
|
575
653
|
* spell the determinism choice once.
|
|
576
654
|
*
|
|
577
|
-
* Returns
|
|
578
|
-
*
|
|
579
|
-
* `withResilience` (`../with-resilience`) — see the migration map at the top
|
|
580
|
-
* of this module.
|
|
655
|
+
* Returns plain functions and the run Cmd def (ADR 0022) — see the module doc
|
|
656
|
+
* for the wiring. `I` is the work's input type, `R` its result type.
|
|
581
657
|
*/
|
|
582
|
-
declare function createResilientCall<I, R>(config: ResilientConfig
|
|
658
|
+
declare function createResilientCall<I, R, N extends string = DefaultResilientName>(config: ResilientConfig<N>, rng?: () => number): {
|
|
659
|
+
name: N;
|
|
660
|
+
/** The `Cmd.define`d run Cmd; list it in the machine's `cmds`. */
|
|
661
|
+
run: CmdDef<`${N}_run`, {
|
|
662
|
+
readonly key: string;
|
|
663
|
+
readonly input: I;
|
|
664
|
+
}, R, {
|
|
665
|
+
readonly [detail: string]: unknown;
|
|
666
|
+
readonly _tag: "deadline_exceeded";
|
|
667
|
+
} | {
|
|
668
|
+
readonly [detail: string]: unknown;
|
|
669
|
+
readonly _tag: "port_rejected";
|
|
670
|
+
}>;
|
|
583
671
|
init: () => ResilientState<I, R>;
|
|
584
|
-
attempt: (s: ResilientState<I, R>, key: string, input: I, at: number) => readonly [ResilientState<I, R>, readonly RunCmd<I>[]];
|
|
672
|
+
attempt: (s: ResilientState<I, R>, key: string, input: I, at: number) => readonly [ResilientState<I, R>, readonly RunCmd<I, N, R>[]];
|
|
585
673
|
resume: (s: ResilientState<I, R>, at: number) => ResilientState<I, R>;
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
readonly input: I;
|
|
595
|
-
}, {
|
|
596
|
-
readonly [detail: string]: unknown;
|
|
597
|
-
readonly _tag: "deadline_exceeded";
|
|
598
|
-
} | {
|
|
599
|
-
readonly [detail: string]: unknown;
|
|
600
|
-
readonly _tag: "port_rejected";
|
|
601
|
-
}, unknown>, ctx: Readonly<Record<never, never>>) => Promise<FailMsg | SucceedMsg<R>>;
|
|
602
|
-
};
|
|
674
|
+
settle: (s: ResilientState<I, R>, msg: SettleMsg<R, N>) => SettleResult<I, R, N>;
|
|
675
|
+
settleFailed: (s: ResilientState<I, R>, key: string, error: unknown, at: number) => readonly [ResilientState<I, R>, readonly RunCmd<I, N, R>[]];
|
|
676
|
+
onTimer: (slice: ResilientState<I, R>, msg: {
|
|
677
|
+
readonly id: string;
|
|
678
|
+
readonly atMs: number;
|
|
679
|
+
}) => readonly [ResilientState<I, R>, readonly RunCmd<I, N, R>[]];
|
|
680
|
+
deadlines: (s: ResilientState<I, R>) => readonly DeadlineSub<DeadlineNameOf<N>>[];
|
|
681
|
+
timer: (s: ResilientState<I, R>) => TimerDeps<ResilientTimerMsg<N>> | null;
|
|
603
682
|
};
|
|
604
683
|
/**
|
|
605
684
|
* Lift a knob result `[slice, cmds]` into a host `[State, cmds]` where the
|
|
606
685
|
* slice lives at `state.resilience`. A convenience for the common single-slice
|
|
607
686
|
* host; consumers with a differently-named field spread by hand. Pure — a thin
|
|
608
|
-
* record rebuild, no clock / RNG.
|
|
609
|
-
*
|
|
610
|
-
*
|
|
687
|
+
* record rebuild, no clock / RNG.
|
|
688
|
+
*
|
|
689
|
+
* The record rebuild itself is `liftSlice` from the root door (#231) — this
|
|
690
|
+
* stays as the named, pre-keyed convenience for the `state.resilience` field,
|
|
691
|
+
* unchanged in name, signature and subpath.
|
|
611
692
|
*/
|
|
612
693
|
declare function liftResilience<S extends {
|
|
613
694
|
resilience: ResilientState<I, R>;
|
|
614
|
-
}, I, R, C extends Cmd>(state: S,
|
|
695
|
+
}, I, R, C extends Cmd>(state: S, result: readonly [ResilientState<I, R>, readonly C[]]): readonly [S, readonly C[]];
|
|
615
696
|
|
|
616
|
-
export {
|
|
697
|
+
export { initBucket as A, initCircuit as B, type CacheConfig as C, DEFAULT_RESILIENT_NAME as D, initWindow as E, type FailMsg as F, liftResilience as G, onFailure as H, onSuccess as I, record as J, refill as K, remaining as L, runCmdDef as M, tryConsume as N, type RunCmd as R, type SucceedMsg as S, type TokenBucket as T, type ResilientState as a, type ResilientTimerMsg as b, type ResilientConfig as c, type CallBudget as d, type CallPhase as e, type CircuitConfig as f, type CircuitPolicy as g, type CircuitState as h, type DeadlineExceededError as i, type DeadlineNameOf as j, type DefaultResilientName as k, type RateLimitConfig as l, type DeadlineConfig as m, type ResilientDeadlineType as n, type ResilientErrType as o, type ResilientOkType as p, type ResilientRunType as q, type RunCmdDef as r, type RunErr as s, type SettleMsg as t, type SettleOutcome as u, type SettleResult as v, type SlidingWindow as w, canPass as x, createResilientCall as y, defaultCircuitPolicy as z };
|