@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.
Files changed (116) hide show
  1. package/README.md +30 -7
  2. package/dist/agent/index.d.ts +49 -36
  3. package/dist/agent/index.js +12 -8
  4. package/dist/chunk-4LPY67E4.js +18 -0
  5. package/dist/chunk-4LPY67E4.js.map +1 -0
  6. package/dist/chunk-5XU6ZJO2.js +533 -0
  7. package/dist/chunk-5XU6ZJO2.js.map +1 -0
  8. package/dist/{chunk-AQ6ZIMEA.js → chunk-6NG4V5SB.js} +89 -115
  9. package/dist/chunk-6NG4V5SB.js.map +1 -0
  10. package/dist/{chunk-HYDWG35Q.js → chunk-7MGXQZPW.js} +11 -9
  11. package/dist/chunk-7MGXQZPW.js.map +1 -0
  12. package/dist/{chunk-BLJ2JQSH.js → chunk-BCTEOVOU.js} +3 -3
  13. package/dist/{chunk-BLJ2JQSH.js.map → chunk-BCTEOVOU.js.map} +1 -1
  14. package/dist/chunk-CH5KTOEZ.js +710 -0
  15. package/dist/chunk-CH5KTOEZ.js.map +1 -0
  16. package/dist/chunk-CIHSHLQX.js +64 -0
  17. package/dist/chunk-CIHSHLQX.js.map +1 -0
  18. package/dist/{chunk-Z2L3LSNV.js → chunk-EHUDXAKC.js} +246 -210
  19. package/dist/chunk-EHUDXAKC.js.map +1 -0
  20. package/dist/chunk-GOX2CYIM.js +380 -0
  21. package/dist/chunk-GOX2CYIM.js.map +1 -0
  22. package/dist/chunk-IVJP3GKJ.js +104 -0
  23. package/dist/chunk-IVJP3GKJ.js.map +1 -0
  24. package/dist/{chunk-F7FMAWLA.js → chunk-MVZS5FDM.js} +13 -6
  25. package/dist/chunk-MVZS5FDM.js.map +1 -0
  26. package/dist/{chunk-LYLTKJWM.js → chunk-MYNLY3HP.js} +9 -8
  27. package/dist/chunk-MYNLY3HP.js.map +1 -0
  28. package/dist/{chunk-I5MQMJDW.js → chunk-NSIAORRY.js} +20 -30
  29. package/dist/chunk-NSIAORRY.js.map +1 -0
  30. package/dist/{chunk-MYXFNWAJ.js → chunk-QNGYQMZB.js} +4 -4
  31. package/dist/chunk-QNGYQMZB.js.map +1 -0
  32. package/dist/chunk-WT5PBPLB.js +98 -0
  33. package/dist/chunk-WT5PBPLB.js.map +1 -0
  34. package/dist/{core-CTzMJ82M.d.ts → core-BbgtiXdg.d.ts} +231 -139
  35. package/dist/do/index.d.ts +37 -32
  36. package/dist/do/index.js +21 -14
  37. package/dist/do/index.js.map +1 -1
  38. package/dist/{durable-effects-B0-qGQDy.d.ts → durable-effects-7MTK_jnj.d.ts} +1 -1
  39. package/dist/effect/index.d.ts +151 -0
  40. package/dist/effect/index.js +98 -0
  41. package/dist/effect/index.js.map +1 -0
  42. package/dist/extension/index.d.ts +6 -7
  43. package/dist/extension/index.js +3 -2
  44. package/dist/extension/index.js.map +1 -1
  45. package/dist/flow/index.d.ts +68 -70
  46. package/dist/flow/index.js +32 -27
  47. package/dist/flow/index.js.map +1 -1
  48. package/dist/idempotency/index.d.ts +6 -7
  49. package/dist/idempotency/index.js +4 -2
  50. package/dist/{index-DJWIER_3.d.ts → index-7vV8xmsD.d.ts} +1 -1
  51. package/dist/{index-NjrT3fL2.d.ts → index-Bz5Rh9Ga.d.ts} +19 -96
  52. package/dist/index-CjFDUBeq.d.ts +207 -0
  53. package/dist/{index-6A7dB8f6.d.ts → index-CkFYA9Y6.d.ts} +14 -16
  54. package/dist/{index-B5BZ-_cT.d.ts → index-Cou86-GX.d.ts} +189 -108
  55. package/dist/{index-TvRb1KVf.d.ts → index-DU6JpQ8G.d.ts} +1 -1
  56. package/dist/{index-q0hXFeZ0.d.ts → index-Xufl55W8.d.ts} +286 -215
  57. package/dist/{index-4vZzljCD.d.ts → index-_dOR3xqA.d.ts} +57 -45
  58. package/dist/index.d.ts +181 -385
  59. package/dist/index.js +2 -1
  60. package/dist/jev/index.d.ts +147 -99
  61. package/dist/jev/index.js +329 -233
  62. package/dist/jev/index.js.map +1 -1
  63. package/dist/{machine-CdIcN2Xm.d.ts → machine-BQzTV8On.d.ts} +171 -280
  64. package/dist/machine-viz/index.d.ts +5 -5
  65. package/dist/machine-viz/index.js +8 -4
  66. package/dist/machine-viz/index.js.map +1 -1
  67. package/dist/mem/index.d.ts +3 -4
  68. package/dist/mem/index.js +2 -1
  69. package/dist/mem/index.js.map +1 -1
  70. package/dist/node/index.d.ts +119 -78
  71. package/dist/node/index.js +52 -38
  72. package/dist/node/index.js.map +1 -1
  73. package/dist/paginate/index.d.ts +27 -33
  74. package/dist/paginate/index.js +6 -4
  75. package/dist/parity/index.d.ts +4 -5
  76. package/dist/parity/index.js +3 -2
  77. package/dist/parity/index.js.map +1 -1
  78. package/dist/pbt/index.d.ts +2 -2
  79. package/dist/pbt/index.js +2 -1
  80. package/dist/pbt/index.js.map +1 -1
  81. package/dist/persistence/index.d.ts +6 -7
  82. package/dist/persistence/index.js +5 -3
  83. package/dist/promise/index.d.ts +186 -0
  84. package/dist/promise/index.js +5 -0
  85. package/dist/promise/index.js.map +1 -0
  86. package/dist/protocol-ClRZBhHQ.d.ts +53 -0
  87. package/dist/react/index.d.ts +36 -17
  88. package/dist/react/index.js +27 -4
  89. package/dist/react/index.js.map +1 -1
  90. package/dist/resilience/index.d.ts +63 -455
  91. package/dist/resilience/index.js +37 -483
  92. package/dist/resilience/index.js.map +1 -1
  93. package/dist/{runtime-types-LWDoi943.d.ts → runtime-types-CiVpC0HN.d.ts} +131 -388
  94. package/dist/testing/index.d.ts +165 -15
  95. package/dist/testing/index.js +104 -3
  96. package/dist/testing/index.js.map +1 -1
  97. package/dist/timing/index.d.ts +25 -22
  98. package/dist/timing/index.js +4 -3
  99. package/dist/timing/index.js.map +1 -1
  100. package/dist/{types-DP3f5NIl.d.ts → types-LxZxGYda.d.ts} +2 -2
  101. package/dist/work-queue/index.d.ts +5 -6
  102. package/package.json +18 -5
  103. package/dist/chunk-AQ6ZIMEA.js.map +0 -1
  104. package/dist/chunk-F2US5BW6.js +0 -72
  105. package/dist/chunk-F2US5BW6.js.map +0 -1
  106. package/dist/chunk-F7FMAWLA.js.map +0 -1
  107. package/dist/chunk-HUKZQX6U.js +0 -97
  108. package/dist/chunk-HUKZQX6U.js.map +0 -1
  109. package/dist/chunk-HYDWG35Q.js.map +0 -1
  110. package/dist/chunk-I5MQMJDW.js.map +0 -1
  111. package/dist/chunk-LYLTKJWM.js.map +0 -1
  112. package/dist/chunk-MYXFNWAJ.js.map +0 -1
  113. package/dist/chunk-RQULHGYH.js +0 -1804
  114. package/dist/chunk-RQULHGYH.js.map +0 -1
  115. package/dist/chunk-Z2L3LSNV.js.map +0 -1
  116. package/dist/index-DMCeMPMJ.d.ts +0 -272
@@ -1,59 +1,6 @@
1
- import { a as CmdOf, b as CmdDef, i as CmdValue, C as Cmd } from './core-CTzMJ82M.js';
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-q0hXFeZ0.js';
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
- * `fail`'s `msg.at` (stamped at the interpret boundary) and `gate`'s `at`
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 `succeed` / `fail`.
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 one effect this knob emits: "run the port for `key` with `input`". The
523
- * consumer's `handlers(ports)` interprets it; it carries no closure — `input`
524
- * is plain data (invariant 3).
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
- declare function runCmdDef<I, R>(): CmdDef<"resilient_run", {
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
- }, unknown>;
536
- type RunCmdDef<I, R> = ReturnType<typeof runCmdDef<I, R>>;
537
- type RunCmd<I> = CmdOf<RunCmdDef<I, unknown>>;
538
- /** Settle Msgs the `handlers` port dispatches back. `at` is stamped at the boundary. */
539
- type SucceedMsg<R> = {
540
- readonly type: typeof MsgType.ResilientOk;
541
- readonly key: string;
542
- readonly result: R;
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: typeof MsgType.ResilientErr;
547
- readonly key: string;
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
- /** The retry / deadline timer Msg — `DeadlineExceeded`, keyed by the call `key`. */
552
- type ResilientTimerMsg = DeadlineExceeded;
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 the uniform L2 knob contract. `I` is the port input type, `R` the
578
- * port result type. Consumers outside the package reach this through
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, rng?: () => number): {
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
- succeed: (s: ResilientState<I, R>, key: string, msg: SucceedMsg<R>) => readonly [ResilientState<I, R>, readonly RunCmd<I>[]];
587
- fail: (s: ResilientState<I, R>, key: string, msg: FailMsg) => readonly [ResilientState<I, R>, readonly RunCmd<I>[]];
588
- settleFailed: (s: ResilientState<I, R>, key: string, error: unknown) => readonly [ResilientState<I, R>, readonly RunCmd<I>[]];
589
- onTimer: (s: ResilientState<I, R>, msg: ResilientTimerMsg) => readonly [ResilientState<I, R>, readonly RunCmd<I>[]];
590
- subs: (s: ResilientState<I, R>) => readonly DeadlineSub[];
591
- handlers: (ports: ResilientPorts<I, R>) => {
592
- resilient_run: (cmd: CmdValue<"resilient_run", {
593
- readonly key: string;
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. Under `withResilience` the wrapper owns
609
- * `model.$resilience`, so there is nothing to lift; this is for the embedded
610
- * slice consumers only.
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, [slice, cmds]: readonly [ResilientState<I, R>, readonly C[]]): readonly [S, readonly C[]];
695
+ }, I, R, C extends Cmd>(state: S, result: readonly [ResilientState<I, R>, readonly C[]]): readonly [S, readonly C[]];
615
696
 
616
- export { runCmdDef as A, tryConsume as B, type CircuitConfig as C, type DeadlineConfig as D, type FailMsg as F, MsgType as M, type RunCmd as R, type SucceedMsg as S, type TokenBucket as T, type ResilientState as a, type MsgTypeValue as b, type RateLimitConfig as c, type ResilientPorts as d, type ResilientConfig as e, type ResilientTimerMsg as f, type CacheConfig as g, type CallBudget as h, type CallPhase as i, type CircuitPolicy as j, type CircuitState as k, type DeadlineExceededError as l, type RunCmdDef as m, type SlidingWindow as n, canPass as o, createResilientCall as p, defaultCircuitPolicy as q, initBucket as r, initCircuit as s, initWindow as t, liftResilience as u, onFailure as v, onSuccess as w, record as x, refill as y, remaining as z };
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 };
@@ -1,4 +1,4 @@
1
- import { B as BootingRuntime } from './runtime-types-LWDoi943.js';
1
+ import { B as BootingRuntime } from './runtime-types-CiVpC0HN.js';
2
2
 
3
3
  /**
4
4
  * A recorded run, sufficient to reproduce it via `../trace-replay`.