@demlik/tea 0.13.0 → 0.15.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 +11 -9
- package/dist/agent/index.d.ts +638 -45
- package/dist/agent/index.js +9 -19
- package/dist/{chunk-RH5EFRVJ.js → chunk-22POWGFA.js} +31 -5
- package/dist/chunk-22POWGFA.js.map +1 -0
- package/dist/{chunk-DMYGQB4O.js → chunk-3B5X7SBB.js} +23 -6
- package/dist/chunk-3B5X7SBB.js.map +1 -0
- package/dist/chunk-66PY5WYF.js +1816 -0
- package/dist/chunk-66PY5WYF.js.map +1 -0
- package/dist/{chunk-25LBDCBC.js → chunk-6IQPODUF.js} +2 -2
- package/dist/{chunk-25LBDCBC.js.map → chunk-6IQPODUF.js.map} +1 -1
- package/dist/chunk-AYS5N6WY.js +505 -0
- package/dist/chunk-AYS5N6WY.js.map +1 -0
- package/dist/{chunk-EWJP3YYP.js → chunk-HWVW4AXC.js} +3 -3
- package/dist/chunk-HWVW4AXC.js.map +1 -0
- package/dist/{chunk-O4MVQTEJ.js → chunk-L3TND7LA.js} +20 -16
- package/dist/chunk-L3TND7LA.js.map +1 -0
- package/dist/{chunk-J6527VRQ.js → chunk-LFZUK6J2.js} +3 -3
- package/dist/chunk-LFZUK6J2.js.map +1 -0
- package/dist/{chunk-D736QUGF.js → chunk-MYXFNWAJ.js} +4 -5
- package/dist/chunk-MYXFNWAJ.js.map +1 -0
- package/dist/{chunk-K575PT4S.js → chunk-PR6TB3BL.js} +15 -4
- package/dist/chunk-PR6TB3BL.js.map +1 -0
- package/dist/{chunk-YUXP55T2.js → chunk-Q5CQTBFA.js} +57 -7
- package/dist/chunk-Q5CQTBFA.js.map +1 -0
- package/dist/{batch-window/index.js → chunk-QPEVCJ5Q.js} +4 -8
- package/dist/chunk-QPEVCJ5Q.js.map +1 -0
- package/dist/chunk-TCLBCERH.js +1480 -0
- package/dist/chunk-TCLBCERH.js.map +1 -0
- package/dist/{chunk-FV3Z5MBE.js → chunk-TXN2KFHF.js} +14 -4
- package/dist/chunk-TXN2KFHF.js.map +1 -0
- package/dist/{chunk-MUUROGIH.js → chunk-V46HSVCK.js} +62 -12
- package/dist/chunk-V46HSVCK.js.map +1 -0
- package/dist/{chunk-Q2UM7BXU.js → chunk-VBDU4JL6.js} +2 -2
- package/dist/chunk-VBDU4JL6.js.map +1 -0
- package/dist/{chunk-ZVJZ72HY.js → chunk-VTQI2NHP.js} +25 -11
- package/dist/chunk-VTQI2NHP.js.map +1 -0
- package/dist/{core-Co0LWkIA.d.ts → core-DnzqWy6u.d.ts} +72 -23
- package/dist/devtools/index.d.ts +2 -2
- package/dist/devtools/index.js +207 -2
- package/dist/devtools/index.js.map +1 -1
- package/dist/do/index.d.ts +43 -29
- package/dist/do/index.js +36 -25
- package/dist/do/index.js.map +1 -1
- package/dist/{durable-effects-C6uwzjb5.d.ts → durable-effects-CWzA-o2B.d.ts} +2 -2
- package/dist/extension/index.d.ts +300 -3
- package/dist/extension/index.js +596 -5
- package/dist/extension/index.js.map +1 -1
- package/dist/flow/index.d.ts +1284 -0
- package/dist/flow/index.js +732 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/idempotency/index.d.ts +90 -116
- package/dist/idempotency/index.js +4 -1
- package/dist/index-Bc40JWVl.d.ts +131 -0
- package/dist/{batch-window/index.d.ts → index-C2DwkjlP.d.ts} +7 -12
- package/dist/index-CA_7I5g9.d.ts +806 -0
- package/dist/index-CSyMYDAB.d.ts +69 -0
- package/dist/{fan-out/index.d.ts → index-CuNO9m8i.d.ts} +7 -9
- package/dist/{debounce/index.d.ts → index-DHSUmQTR.d.ts} +7 -7
- package/dist/{recorder/index.d.ts → index-DrIRb_Ch.d.ts} +4 -7
- package/dist/index-HSYgG2Yt.d.ts +380 -0
- package/dist/{monitored-run/index.d.ts → index-KXqTRJyb.d.ts} +37 -13
- package/dist/{snapshot/index.d.ts → index-ZCMhnVKN.d.ts} +15 -78
- package/dist/index.d.ts +771 -6
- package/dist/index.js +1 -2
- package/dist/jev/index.d.ts +646 -0
- package/dist/jev/index.js +485 -0
- package/dist/jev/index.js.map +1 -0
- package/dist/machine-DGlPWCWI.d.ts +1781 -0
- package/dist/machine-viz/index.d.ts +1 -1
- package/dist/machine-viz/index.js +12 -5
- package/dist/machine-viz/index.js.map +1 -1
- package/dist/mem/index.d.ts +18 -3
- package/dist/mem/index.js +22 -2
- package/dist/mem/index.js.map +1 -1
- package/dist/node/index.d.ts +104 -6
- package/dist/node/index.js +132 -9
- package/dist/node/index.js.map +1 -1
- package/dist/{paginator → paginate}/index.d.ts +140 -6
- package/dist/paginate/index.js +7 -0
- package/dist/parity/index.d.ts +4 -10
- package/dist/parity/index.js +4 -7
- package/dist/parity/index.js.map +1 -1
- package/dist/pbt/index.d.ts +247 -5
- package/dist/pbt/index.js +124 -5
- package/dist/pbt/index.js.map +1 -1
- package/dist/{trace-replay → persistence}/index.d.ts +7 -5
- package/dist/persistence/index.js +6 -0
- package/dist/{protocol-B5YmJr0d.d.ts → protocol-D8VbH-VH.d.ts} +10 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +1 -2
- package/dist/react/index.js.map +1 -1
- package/dist/resilience/index.d.ts +744 -0
- package/dist/resilience/index.js +657 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/retry-backoff/index.d.ts +3 -2
- package/dist/retry-backoff/index.js +1 -1
- package/dist/runtime-types-CMF13BBh.d.ts +998 -0
- package/dist/testing/index.d.ts +147 -3
- package/dist/testing/index.js +95 -3
- package/dist/testing/index.js.map +1 -1
- package/dist/{throttled-input → timing}/index.d.ts +143 -12
- package/dist/{throttled-input → timing}/index.js +57 -12
- package/dist/timing/index.js.map +1 -0
- package/dist/{types-XS_miRnB.d.ts → types-BseNPIhr.d.ts} +1 -1
- package/dist/work-queue/index.d.ts +130 -54
- package/dist/work-queue/index.js +3 -2
- package/dist/work-queue/index.js.map +1 -1
- package/package.json +45 -218
- package/dist/authed-call/index.d.ts +0 -120
- package/dist/authed-call/index.js +0 -134
- package/dist/authed-call/index.js.map +0 -1
- package/dist/await-terminal/index.d.ts +0 -101
- package/dist/await-terminal/index.js +0 -76
- package/dist/await-terminal/index.js.map +0 -1
- package/dist/batch-window/index.js.map +0 -1
- package/dist/cache/index.d.ts +0 -152
- package/dist/cache/index.js +0 -8
- package/dist/chart/index.d.ts +0 -218
- package/dist/chart/index.js +0 -16
- package/dist/chart/index.js.map +0 -1
- package/dist/chart/inspect/index.d.ts +0 -86
- package/dist/chart/inspect/index.js +0 -5
- package/dist/chart/inspect/react.d.ts +0 -113
- package/dist/chart/inspect/react.js +0 -11
- package/dist/chart/inspect/react.js.map +0 -1
- package/dist/chart/inspect/styles.css +0 -286
- package/dist/chart/lane/index.d.ts +0 -362
- package/dist/chart/lane/index.js +0 -9
- package/dist/chart/lane/index.js.map +0 -1
- package/dist/chart/lane/react.d.ts +0 -84
- package/dist/chart/lane/react.js +0 -559
- package/dist/chart/lane/react.js.map +0 -1
- package/dist/chart/lane/server.d.ts +0 -148
- package/dist/chart/lane/server.js +0 -209
- package/dist/chart/lane/server.js.map +0 -1
- package/dist/chart/lane/styles.css +0 -498
- package/dist/chart/lane/viewer/assets/abnfDiagram-N423BO3Z-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/architectureDiagram-T3A2C74G-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/blockDiagram-VBNYF7ZC-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/c4Diagram-5PPSVZJV-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/chunk-2GRJ4B5K-HdDf8SI3.js +0 -1
- package/dist/chart/lane/viewer/assets/chunk-5RXB4S5H-CcNtpUd7.js +0 -231
- package/dist/chart/lane/viewer/assets/chunk-5VM5RSS4-BP4fRS_5.js +0 -15
- package/dist/chart/lane/viewer/assets/chunk-KBJHAD2P-DZOw7xU6.js +0 -1
- package/dist/chart/lane/viewer/assets/chunk-NSK5VX7P-CBCyTZMs.js +0 -128
- package/dist/chart/lane/viewer/assets/classDiagram-JCYQIIEL-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/classDiagram-v2-OCEON4UE-D4uAiFr8.js +0 -206
- package/dist/chart/lane/viewer/assets/cose-bilkent-JH36ORCC-DOwCrGXH.js +0 -1
- package/dist/chart/lane/viewer/assets/cynefinDiagram-MW4NZA55-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/dagre-K_PewWfS.js +0 -1
- package/dist/chart/lane/viewer/assets/dagre-VZM6K2ZE-831qZcA8.js +0 -4
- package/dist/chart/lane/viewer/assets/diagram-7IWD3JNH-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-B4RE2ZJO-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-LBJQPF4R-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-Q27KOJAE-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-UB23O5K3-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/ebnfDiagram-BXEA7PRR-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/erDiagram-JOGREHBK-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/flowDiagram-UKHOOZJN-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/ganttDiagram-PKOTCBZU-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/gitGraphDiagram-DS77QQ5N-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/index-9SkH5NA3.css +0 -1
- package/dist/chart/lane/viewer/assets/index-Bgt4sXpW.js +0 -195
- package/dist/chart/lane/viewer/assets/infoDiagram-6WML65LV-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/ishikawaDiagram-WSZJBQD7-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/journeyDiagram-NVQOT4AX-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/kanban-definition-27J2QSJJ-G7PaPzy-.js +0 -89
- package/dist/chart/lane/viewer/assets/katex-DOwCrGXH.js +0 -1
- package/dist/chart/lane/viewer/assets/mindmap-definition-FAOFIHXS-CGj9nrVk.js +0 -96
- package/dist/chart/lane/viewer/assets/path-fybaL0A-.js +0 -1
- package/dist/chart/lane/viewer/assets/pegDiagram-VL7TDLO6-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/pieDiagram-7S7Q4E2Y-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/quadrantDiagram-CIZ2JOQS-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/railroadDiagram-AXF67PYL-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/requirementDiagram-LRYGKXZP-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/sankeyDiagram-W5VNT64P-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/sequenceDiagram-SI44F4Z6-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/stateDiagram-OKZ733FA-B_88AzBS.js +0 -1
- package/dist/chart/lane/viewer/assets/stateDiagram-v2-UEYNNEHI-CR5gcgq6.js +0 -1
- package/dist/chart/lane/viewer/assets/swimlanes-SLNWSIFB-B4xK-rwg.js +0 -1
- package/dist/chart/lane/viewer/assets/swimlanesDiagram-ULZ7WXOC-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/timeline-definition-Z64GVDOM-CCv52MfY.js +0 -120
- package/dist/chart/lane/viewer/assets/vennDiagram-T6HMQDX7-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/wardleyDiagram-T6FBY63Y-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/xychartDiagram-ELKLHX3M-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/index.html +0 -15
- package/dist/chart/report/index.d.ts +0 -117
- package/dist/chart/report/index.js +0 -32
- package/dist/chart/report/index.js.map +0 -1
- package/dist/chunk-2YFLOCWX.js +0 -15
- package/dist/chunk-2YFLOCWX.js.map +0 -1
- package/dist/chunk-3I52QZZ5.js +0 -519
- package/dist/chunk-3I52QZZ5.js.map +0 -1
- package/dist/chunk-3ZAFFRRB.js +0 -457
- package/dist/chunk-3ZAFFRRB.js.map +0 -1
- package/dist/chunk-4EQZ76JC.js +0 -33
- package/dist/chunk-4EQZ76JC.js.map +0 -1
- package/dist/chunk-4KLG43GY.js +0 -223
- package/dist/chunk-4KLG43GY.js.map +0 -1
- package/dist/chunk-7FRZ2CT2.js +0 -424
- package/dist/chunk-7FRZ2CT2.js.map +0 -1
- package/dist/chunk-AZZLE7XR.js +0 -62
- package/dist/chunk-AZZLE7XR.js.map +0 -1
- package/dist/chunk-BYQUGDD3.js +0 -16
- package/dist/chunk-BYQUGDD3.js.map +0 -1
- package/dist/chunk-CIQG5L42.js +0 -685
- package/dist/chunk-CIQG5L42.js.map +0 -1
- package/dist/chunk-CLM6ERNO.js +0 -61
- package/dist/chunk-CLM6ERNO.js.map +0 -1
- package/dist/chunk-COS5MSTO.js +0 -88
- package/dist/chunk-COS5MSTO.js.map +0 -1
- package/dist/chunk-CRPZJVD2.js +0 -71
- package/dist/chunk-CRPZJVD2.js.map +0 -1
- package/dist/chunk-D62FDQKE.js +0 -53
- package/dist/chunk-D62FDQKE.js.map +0 -1
- package/dist/chunk-D736QUGF.js.map +0 -1
- package/dist/chunk-DGE4PV4A.js +0 -26
- package/dist/chunk-DGE4PV4A.js.map +0 -1
- package/dist/chunk-DMYGQB4O.js.map +0 -1
- package/dist/chunk-EWJP3YYP.js.map +0 -1
- package/dist/chunk-FV3Z5MBE.js.map +0 -1
- package/dist/chunk-HCEVHFJ7.js +0 -54
- package/dist/chunk-HCEVHFJ7.js.map +0 -1
- package/dist/chunk-J6527VRQ.js.map +0 -1
- package/dist/chunk-JELSZN25.js +0 -47
- package/dist/chunk-JELSZN25.js.map +0 -1
- package/dist/chunk-K575PT4S.js.map +0 -1
- package/dist/chunk-L57ZOT5K.js +0 -184
- package/dist/chunk-L57ZOT5K.js.map +0 -1
- package/dist/chunk-MU6MCIAC.js +0 -15
- package/dist/chunk-MU6MCIAC.js.map +0 -1
- package/dist/chunk-MUUROGIH.js.map +0 -1
- package/dist/chunk-NR7BU22N.js +0 -758
- package/dist/chunk-NR7BU22N.js.map +0 -1
- package/dist/chunk-O4MVQTEJ.js.map +0 -1
- package/dist/chunk-OOYD44JI.js +0 -317
- package/dist/chunk-OOYD44JI.js.map +0 -1
- package/dist/chunk-Q2UM7BXU.js.map +0 -1
- package/dist/chunk-RH5EFRVJ.js.map +0 -1
- package/dist/chunk-S2EGRPCM.js +0 -47
- package/dist/chunk-S2EGRPCM.js.map +0 -1
- package/dist/chunk-SINXE47Y.js +0 -55
- package/dist/chunk-SINXE47Y.js.map +0 -1
- package/dist/chunk-UF4MZSLT.js +0 -53
- package/dist/chunk-UF4MZSLT.js.map +0 -1
- package/dist/chunk-UOC2PL46.js +0 -13
- package/dist/chunk-UOC2PL46.js.map +0 -1
- package/dist/chunk-VYFAZN3F.js +0 -372
- package/dist/chunk-VYFAZN3F.js.map +0 -1
- package/dist/chunk-WRAA7GVZ.js +0 -209
- package/dist/chunk-WRAA7GVZ.js.map +0 -1
- package/dist/chunk-XGELA764.js +0 -163
- package/dist/chunk-XGELA764.js.map +0 -1
- package/dist/chunk-YUXP55T2.js.map +0 -1
- package/dist/chunk-YWIKDKHY.js +0 -307
- package/dist/chunk-YWIKDKHY.js.map +0 -1
- package/dist/chunk-ZJ5AOYBH.js +0 -8
- package/dist/chunk-ZJ5AOYBH.js.map +0 -1
- package/dist/chunk-ZSUUOEPL.js +0 -731
- package/dist/chunk-ZSUUOEPL.js.map +0 -1
- package/dist/chunk-ZVJZ72HY.js.map +0 -1
- package/dist/circuit-breaker/index.d.ts +0 -197
- package/dist/circuit-breaker/index.js +0 -3
- package/dist/circuit-breaker/index.js.map +0 -1
- package/dist/deadline/index.d.ts +0 -199
- package/dist/deadline/index.js +0 -6
- package/dist/deadline/index.js.map +0 -1
- package/dist/debounce/index.js +0 -3
- package/dist/debounce/index.js.map +0 -1
- package/dist/extension/react.d.ts +0 -121
- package/dist/extension/react.js +0 -75
- package/dist/extension/react.js.map +0 -1
- package/dist/extension/subs/index.d.ts +0 -45
- package/dist/extension/subs/index.js +0 -80
- package/dist/extension/subs/index.js.map +0 -1
- package/dist/extension/test-utils.d.ts +0 -128
- package/dist/extension/test-utils.js +0 -277
- package/dist/extension/test-utils.js.map +0 -1
- package/dist/fan-out/index.js +0 -5
- package/dist/fan-out/index.js.map +0 -1
- package/dist/fold-BJPdjc9w.d.ts +0 -435
- package/dist/graph-B3L5e0N1.d.ts +0 -923
- package/dist/idempotency/adapter.d.ts +0 -62
- package/dist/idempotency/adapter.js +0 -4
- package/dist/idempotency/adapter.js.map +0 -1
- package/dist/idempotent-intake/index.d.ts +0 -188
- package/dist/idempotent-intake/index.js +0 -7
- package/dist/idempotent-intake/index.js.map +0 -1
- package/dist/journal/index.d.ts +0 -373
- package/dist/journal/index.js +0 -3
- package/dist/journal/index.js.map +0 -1
- package/dist/llm-call/index.d.ts +0 -311
- package/dist/llm-call/index.js +0 -16
- package/dist/llm-call/index.js.map +0 -1
- package/dist/machine-BtFWQmmq.d.ts +0 -804
- package/dist/monitored-run/index.js +0 -10
- package/dist/monitored-run/index.js.map +0 -1
- package/dist/paginated-walk/index.d.ts +0 -235
- package/dist/paginated-walk/index.js +0 -16
- package/dist/paginated-walk/index.js.map +0 -1
- package/dist/paginator/index.js +0 -3
- package/dist/paginator/index.js.map +0 -1
- package/dist/pbt/arbitraries/index.d.ts +0 -136
- package/dist/pbt/arbitraries/index.js +0 -3
- package/dist/pbt/arbitraries/index.js.map +0 -1
- package/dist/pbt/runners/index.d.ts +0 -118
- package/dist/pbt/runners/index.js +0 -5
- package/dist/pbt/runners/index.js.map +0 -1
- package/dist/poller/index.d.ts +0 -352
- package/dist/poller/index.js +0 -115
- package/dist/poller/index.js.map +0 -1
- package/dist/prediction/index.d.ts +0 -131
- package/dist/prediction/index.js +0 -4
- package/dist/prediction/index.js.map +0 -1
- package/dist/pure/index.d.ts +0 -3
- package/dist/pure/index.js +0 -4
- package/dist/pure/index.js.map +0 -1
- package/dist/rate-limit/index.d.ts +0 -115
- package/dist/rate-limit/index.js +0 -3
- package/dist/rate-limit/index.js.map +0 -1
- package/dist/reconciler/index.d.ts +0 -193
- package/dist/reconciler/index.js +0 -164
- package/dist/reconciler/index.js.map +0 -1
- package/dist/recorder/index.js +0 -3
- package/dist/recorder/index.js.map +0 -1
- package/dist/reducer-4GNR6b8B.d.ts +0 -447
- package/dist/resilient-call/index.d.ts +0 -320
- package/dist/resilient-call/index.js +0 -14
- package/dist/resilient-call/index.js.map +0 -1
- package/dist/retry-to-success/index.d.ts +0 -109
- package/dist/retry-to-success/index.js +0 -37
- package/dist/retry-to-success/index.js.map +0 -1
- package/dist/run-pAcmBpah.d.ts +0 -713
- package/dist/runtime-types-CNLmhWif.d.ts +0 -517
- package/dist/saga/index.d.ts +0 -241
- package/dist/saga/index.js +0 -150
- package/dist/saga/index.js.map +0 -1
- package/dist/samples-B3My5oh2.d.ts +0 -59
- package/dist/snapshot/index.js +0 -5
- package/dist/snapshot/index.js.map +0 -1
- package/dist/subs/index.d.ts +0 -472
- package/dist/subs/index.js +0 -7
- package/dist/subs/index.js.map +0 -1
- package/dist/throttle/index.d.ts +0 -134
- package/dist/throttle/index.js +0 -3
- package/dist/throttle/index.js.map +0 -1
- package/dist/throttled-input/index.js.map +0 -1
- package/dist/token-refresh/index.d.ts +0 -216
- package/dist/token-refresh/index.js +0 -6
- package/dist/token-refresh/index.js.map +0 -1
- package/dist/trace-replay/index.js +0 -6
- package/dist/trace-replay/index.js.map +0 -1
- package/dist/with-deadline/index.d.ts +0 -197
- package/dist/with-deadline/index.js +0 -111
- package/dist/with-deadline/index.js.map +0 -1
- package/dist/with-resilience/index.d.ts +0 -225
- package/dist/with-resilience/index.js +0 -240
- package/dist/with-resilience/index.js.map +0 -1
- package/dist/with-telemetry/index.d.ts +0 -150
- package/dist/with-telemetry/index.js +0 -70
- package/dist/with-telemetry/index.js.map +0 -1
- package/dist/work-queue/adapter.d.ts +0 -84
- package/dist/work-queue/adapter.js +0 -4
- package/dist/work-queue/adapter.js.map +0 -1
- package/dist/work-queue/ops.d.ts +0 -71
- package/dist/work-queue/ops.js +0 -3
- package/dist/work-queue/ops.js.map +0 -1
- package/dist/workflow/index.d.ts +0 -485
- package/dist/workflow/index.js +0 -244
- package/dist/workflow/index.js.map +0 -1
- /package/dist/{cache → paginate}/index.js.map +0 -0
- /package/dist/{chart/inspect → persistence}/index.js.map +0 -0
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
import { a as CmdOf, b as CmdDef, i as NoCtx, C as Cmd } from './core-DnzqWy6u.js';
|
|
2
|
+
import { RetryState, AnyRetryPolicy } from './retry-backoff/index.js';
|
|
3
|
+
import { T as TtlCache, D as DeadlineExceeded, a as DeadlineSub, s as subscribeDeadline } from './index-HSYgG2Yt.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* internal/resilience/circuit-breaker — per-target failure tracking as pure state + ops.
|
|
8
|
+
*
|
|
9
|
+
* Same shape as `../../work-queue/ops.ts`, `../rate-limit/`, and
|
|
10
|
+
* `../../idempotency/`: a state type plus pure transition functions.
|
|
11
|
+
* Host-agnostic by construction — no `Date.now()`, no timers, no I/O. The
|
|
12
|
+
* caller injects the clock (`nowMs`) and wires the result into its own reducer
|
|
13
|
+
* / interpret. This keeps the breaker inside TEA's invariant 2 (transitions are
|
|
14
|
+
* pure: same inputs → same outputs, no `Date.now`) so a consumer can fold it
|
|
15
|
+
* through `update` and exercise it with `replay` / the pbt fold without a fake
|
|
16
|
+
* clock.
|
|
17
|
+
*
|
|
18
|
+
* Every op returns a NEW state value and never mutates its input (invariant 1 —
|
|
19
|
+
* state is a value, not a place). `canPass` returns a `[next, allowed]` tuple so
|
|
20
|
+
* the caller branches on the decision while threading the advanced state forward
|
|
21
|
+
* — same convention as `rate-limit`'s `tryConsume` / `record`. `onSuccess` /
|
|
22
|
+
* `onFailure` are the outcome-recording transitions the caller folds in once the
|
|
23
|
+
* guarded call resolves.
|
|
24
|
+
*
|
|
25
|
+
* ## The phase machine
|
|
26
|
+
*
|
|
27
|
+
* A circuit breaker guards a fallible downstream target (an HTTP backend, a DB,
|
|
28
|
+
* a flaky tool call). Instead of hammering a target that is already failing, it
|
|
29
|
+
* trips OPEN after enough failures and fast-fails subsequent calls for a
|
|
30
|
+
* cooldown, then probes with a few trial calls before fully closing again.
|
|
31
|
+
* Three phases, each carrying ONLY its own data so impossible states are
|
|
32
|
+
* unrepresentable (pattern 11):
|
|
33
|
+
*
|
|
34
|
+
* - **closed** — the healthy steady state. Calls pass through. Carries
|
|
35
|
+
* `failures`: the count of *consecutive* failures since the last success.
|
|
36
|
+
* A success resets it to 0; the `failureThreshold`-th failure trips the
|
|
37
|
+
* breaker OPEN. Only `closed` has a failure counter — `open` and
|
|
38
|
+
* `half_open` don't, because in those phases the count is irrelevant
|
|
39
|
+
* (the breaker has already tripped / is already probing).
|
|
40
|
+
*
|
|
41
|
+
* - **open** — the tripped state. All calls fast-fail (no downstream load).
|
|
42
|
+
* Carries `openedAtMs`: the clock reading at which the breaker tripped.
|
|
43
|
+
* `canPass` compares `nowMs - openedAtMs` against `cooldownMs` to decide
|
|
44
|
+
* when to start probing. Only `open` carries a timestamp — neither other
|
|
45
|
+
* phase is timing anything.
|
|
46
|
+
*
|
|
47
|
+
* - **half_open** — the probing state. A limited number of trial calls are
|
|
48
|
+
* allowed through to test whether the target has recovered. Carries
|
|
49
|
+
* `probes`: the count of probes admitted so far this probing round.
|
|
50
|
+
* `canPass` admits while `probes < halfOpenMaxProbes`, then fast-fails the
|
|
51
|
+
* rest (so a slow target can't be flooded by every queued caller at once).
|
|
52
|
+
* A probe success closes the breaker; a probe failure re-opens it (and
|
|
53
|
+
* resets the cooldown clock). Only `half_open` counts in-flight probes.
|
|
54
|
+
*
|
|
55
|
+
* ### Transition table
|
|
56
|
+
*
|
|
57
|
+
* Rows are the current phase; columns are the event. `→` denotes the next
|
|
58
|
+
* phase; `self` means unchanged. `nowMs` is the injected clock.
|
|
59
|
+
*
|
|
60
|
+
* | from \ event | onSuccess | onFailure | canPass (→ allowed?) |
|
|
61
|
+
* | ------------ | -------------- | -------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
62
|
+
* | closed | closed(0) | failures+1; trip → open(nowMs) at thr. | self → true (always) |
|
|
63
|
+
* | open | self *(¹)* | self | elapsed ≥ cooldown → half_open(1), true; else self → false |
|
|
64
|
+
* | half_open | → closed(0) | → open(nowMs) (probe failed) | probes < max → half_open(probes+1), true; else self → false |
|
|
65
|
+
*
|
|
66
|
+
* *(¹)* `onSuccess` on `open` "shouldn't happen": no call was admitted while
|
|
67
|
+
* open, so no success can be reported for one. We leave the state unchanged
|
|
68
|
+
* rather than throw — the breaker is a coordination aid, not a correctness
|
|
69
|
+
* gate, and a spurious success report (e.g. a late-arriving result from before
|
|
70
|
+
* the trip) must not silently un-trip the breaker. `onFailure` on `open` is
|
|
71
|
+
* likewise a no-op: the breaker is already tripped; the `open` clock is anchored
|
|
72
|
+
* at the trip, not bumped by late failures.
|
|
73
|
+
*
|
|
74
|
+
* ### The probe-admission asymmetry
|
|
75
|
+
*
|
|
76
|
+
* Entering `half_open` happens inside `canPass`, not `onSuccess` / `onFailure`,
|
|
77
|
+
* because the cooldown is a *time* condition and only `canPass` reads the clock
|
|
78
|
+
* against `openedAtMs`. The first `canPass` after the cooldown elapses both
|
|
79
|
+
* transitions the phase AND admits the probe (`[half_open(1), true]`) — one
|
|
80
|
+
* caller drives the recovery attempt. Subsequent `canPass` calls in the same
|
|
81
|
+
* round admit up to `halfOpenMaxProbes` total, then fast-fail until a probe
|
|
82
|
+
* resolves and `onSuccess` / `onFailure` moves the phase out of `half_open`.
|
|
83
|
+
*
|
|
84
|
+
* This module is a textbook three-state machine — a clean `/machine-viz` demo.
|
|
85
|
+
*
|
|
86
|
+
* Internal to the package (`src/internal/resilience/`), not a published
|
|
87
|
+
* subpath (#46); same one-shape-per-module rule as `work-queue`, `rate-limit`,
|
|
88
|
+
* and `idempotency`.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* Circuit-breaker policy — pure configuration, no mutable state. One policy is
|
|
92
|
+
* shared across all the calls guarded by one logical breaker (often a
|
|
93
|
+
* module-scope const). `CircuitState` carries the mutable counts; this carries
|
|
94
|
+
* the thresholds those counts are compared against.
|
|
95
|
+
*/
|
|
96
|
+
interface CircuitPolicy {
|
|
97
|
+
/**
|
|
98
|
+
* Consecutive failures in `closed` that trip the breaker `open`. The
|
|
99
|
+
* `failureThreshold`-th failure is the one that trips — with a threshold of
|
|
100
|
+
* 5, the breaker survives 4 failures and opens on the 5th.
|
|
101
|
+
*/
|
|
102
|
+
readonly failureThreshold: number;
|
|
103
|
+
/**
|
|
104
|
+
* How long the breaker stays `open` before `canPass` starts admitting
|
|
105
|
+
* probes, in milliseconds. Measured from `openedAtMs`; the cutoff is
|
|
106
|
+
* half-open (`elapsed >= cooldownMs` admits), matching `rate-limit` /
|
|
107
|
+
* `idempotency` window edges — a breaker opened at `t` first probes at
|
|
108
|
+
* `t + cooldownMs`.
|
|
109
|
+
*/
|
|
110
|
+
readonly cooldownMs: number;
|
|
111
|
+
/**
|
|
112
|
+
* How many probe calls `half_open` admits before fast-failing the rest of
|
|
113
|
+
* the round. Caps the load on a recovering target — a single slow probe
|
|
114
|
+
* can't be joined by every queued caller. The round ends when a probe
|
|
115
|
+
* resolves: success closes the breaker, failure re-opens it.
|
|
116
|
+
*/
|
|
117
|
+
readonly halfOpenMaxProbes: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Sensible defaults: trip after 5 consecutive failures, cool down for 30s,
|
|
121
|
+
* admit a single probe before deciding. Tuned for guarding a network backend;
|
|
122
|
+
* override per call site rather than mutating this shared const.
|
|
123
|
+
*/
|
|
124
|
+
declare const defaultCircuitPolicy: CircuitPolicy;
|
|
125
|
+
/**
|
|
126
|
+
* The breaker's phase. A discriminated union on `phase` so each phase carries
|
|
127
|
+
* ONLY its own data and impossible combinations are unrepresentable (pattern
|
|
128
|
+
* 11): there is no state with both a failure count AND an open timestamp,
|
|
129
|
+
* because such a state is meaningless. `phase` is the discriminant; every field
|
|
130
|
+
* is `readonly` so the whole value is trivially JSON-serializable into a
|
|
131
|
+
* consumer's `Store<S>` and safe to thread through a pure reducer.
|
|
132
|
+
*
|
|
133
|
+
* - `closed` carries `failures` — consecutive failures since last success.
|
|
134
|
+
* - `open` carries `openedAtMs` — clock reading when it tripped.
|
|
135
|
+
* - `half_open` carries `probes` — probes admitted this round.
|
|
136
|
+
*/
|
|
137
|
+
type CircuitState = {
|
|
138
|
+
readonly phase: "closed";
|
|
139
|
+
readonly failures: number;
|
|
140
|
+
} | {
|
|
141
|
+
readonly phase: "open";
|
|
142
|
+
readonly openedAtMs: number;
|
|
143
|
+
} | {
|
|
144
|
+
readonly phase: "half_open";
|
|
145
|
+
readonly probes: number;
|
|
146
|
+
};
|
|
147
|
+
/** The starting state: closed with zero recorded failures. */
|
|
148
|
+
declare function initCircuit(): CircuitState;
|
|
149
|
+
/**
|
|
150
|
+
* Record a successful guarded call. PURE — returns a new state; the input is
|
|
151
|
+
* never mutated.
|
|
152
|
+
*
|
|
153
|
+
* - `closed` → reset `failures` to 0 (a success breaks the consecutive run).
|
|
154
|
+
* - `half_open` → the probe succeeded; the target has recovered → `closed`.
|
|
155
|
+
* - `open` → unchanged. A success "shouldn't happen" while open (no call
|
|
156
|
+
* was admitted to produce one); a late/spurious success must
|
|
157
|
+
* not silently un-trip the breaker. See module header note ¹.
|
|
158
|
+
*/
|
|
159
|
+
declare function onSuccess(state: CircuitState, _policy: CircuitPolicy): CircuitState;
|
|
160
|
+
/**
|
|
161
|
+
* Record a failed guarded call. PURE — returns a new state; the input is never
|
|
162
|
+
* mutated. `nowMs` is the injected clock, stamped onto the `open` phase when the
|
|
163
|
+
* breaker trips so `canPass` can measure the cooldown later.
|
|
164
|
+
*
|
|
165
|
+
* - `closed` → `failures + 1`; if that reaches `failureThreshold`, trip to
|
|
166
|
+
* `open(nowMs)`. The threshold-th failure is the one that trips.
|
|
167
|
+
* - `half_open` → the probe failed; the target is still unhealthy →
|
|
168
|
+
* `open(nowMs)`, restarting the cooldown clock so a fresh
|
|
169
|
+
* cooldown elapses before the next probe round.
|
|
170
|
+
* - `open` → unchanged. The breaker is already tripped; the `open` clock
|
|
171
|
+
* is anchored at the original trip, not bumped by late
|
|
172
|
+
* failures. See module header note ¹.
|
|
173
|
+
*/
|
|
174
|
+
declare function onFailure(state: CircuitState, policy: CircuitPolicy, nowMs: number): CircuitState;
|
|
175
|
+
/**
|
|
176
|
+
* Decide whether a call may pass, advancing the phase as a side effect of the
|
|
177
|
+
* decision. PURE — returns `[next, allowed]`; the input is never mutated.
|
|
178
|
+
* Branch on the boolean, thread the state forward regardless:
|
|
179
|
+
*
|
|
180
|
+
* const [c1, allowed] = canPass(state.circuit, policy, nowMs);
|
|
181
|
+
* if (!allowed) return [{ ...state, circuit: c1 }, [fastFailCmd]];
|
|
182
|
+
* return [{ ...state, circuit: c1 }, [doGuardedCallCmd]];
|
|
183
|
+
*
|
|
184
|
+
* - `closed` → `[state, true]` — always passes; failures are recorded by
|
|
185
|
+
* `onFailure` once the call resolves, not gated here.
|
|
186
|
+
* - `open` → if `nowMs - openedAtMs >= cooldownMs` the cooldown has
|
|
187
|
+
* elapsed → enter `half_open` and admit this caller as the
|
|
188
|
+
* first probe: `[half_open(1), true]`. Otherwise still cooling
|
|
189
|
+
* down → `[state, false]` (fast-fail, no downstream load).
|
|
190
|
+
* - `half_open` → admit while `probes < halfOpenMaxProbes`, incrementing the
|
|
191
|
+
* count: `[half_open(probes+1), true]`. Once the cap is hit →
|
|
192
|
+
* `[state, false]` until a probe resolves and `onSuccess` /
|
|
193
|
+
* `onFailure` moves the phase out of `half_open`.
|
|
194
|
+
*
|
|
195
|
+
* Entering `half_open` lives here (not in `onSuccess` / `onFailure`) because the
|
|
196
|
+
* cooldown is a time condition and only `canPass` reads `nowMs` against
|
|
197
|
+
* `openedAtMs`. See the module header's probe-admission note.
|
|
198
|
+
*/
|
|
199
|
+
declare function canPass(state: CircuitState, policy: CircuitPolicy, nowMs: number): readonly [CircuitState, boolean];
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* internal/resilience/rate-limit — two rate limiters as pure state + ops.
|
|
203
|
+
*
|
|
204
|
+
* Same shape as `../../work-queue/ops.ts`: a state type plus pure
|
|
205
|
+
* transition functions. Host-agnostic by construction — no `Date.now()`, no
|
|
206
|
+
* timers, no I/O. The caller injects the clock (`nowMs`) and wires the result
|
|
207
|
+
* into its own reducer / interpret. This keeps the limiters inside TEA's
|
|
208
|
+
* invariant 2 (transitions are pure: same inputs → same outputs, no `Date.now`)
|
|
209
|
+
* so a consumer can fold them through `update` and exercise them with `replay`
|
|
210
|
+
* / the pbt fold without a fake clock.
|
|
211
|
+
*
|
|
212
|
+
* Every op returns a NEW state value and never mutates its input (invariant 1 —
|
|
213
|
+
* state is a value, not a place). The `tryConsume` / `record` ops return a
|
|
214
|
+
* `[next, ok]` tuple so the caller branches on the decision while threading the
|
|
215
|
+
* advanced state forward; `refill` / `remaining` are read-shaped helpers.
|
|
216
|
+
*
|
|
217
|
+
* Two complementary algorithms, picked by the cost the caller wants to pay:
|
|
218
|
+
*
|
|
219
|
+
* - **Token bucket** — O(1) state (four numbers), smooths bursts against a
|
|
220
|
+
* steady refill rate. Allows a burst up to `capacity`, then throttles to
|
|
221
|
+
* `refillPerSec`. Cheapest; the default choice.
|
|
222
|
+
* - **Sliding window log** — O(limit) state (one timestamp per in-window
|
|
223
|
+
* hit), exact "no more than `limit` events per `windowMs`". Pay the memory
|
|
224
|
+
* for precise window edges when a token bucket's continuous refill would
|
|
225
|
+
* let through too many at a boundary.
|
|
226
|
+
*
|
|
227
|
+
* Internal to the package (`src/internal/resilience/`), not a published
|
|
228
|
+
* subpath (#46); same one-shape-per-module rule as `work-queue` and `do`.
|
|
229
|
+
*/
|
|
230
|
+
/**
|
|
231
|
+
* A token bucket: `tokens` of `capacity` available now, replenished at
|
|
232
|
+
* `refillPerSec` tokens per second. `lastRefillMs` is the clock reading at
|
|
233
|
+
* which `tokens` was last computed — `refill` advances it. All four fields are
|
|
234
|
+
* plain numbers so the whole bucket is trivially JSON-serializable into a
|
|
235
|
+
* consumer's `Store<S>`.
|
|
236
|
+
*/
|
|
237
|
+
interface TokenBucket {
|
|
238
|
+
readonly tokens: number;
|
|
239
|
+
readonly capacity: number;
|
|
240
|
+
readonly refillPerSec: number;
|
|
241
|
+
readonly lastRefillMs: number;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a full bucket. Starts at `capacity` tokens (the conventional "a fresh
|
|
245
|
+
* limiter lets the first burst through" behavior) and stamps `lastRefillMs`
|
|
246
|
+
* with the caller's clock so the first `refill` measures elapsed time from
|
|
247
|
+
* boot, not from epoch 0.
|
|
248
|
+
*/
|
|
249
|
+
declare function initBucket(capacity: number, refillPerSec: number, nowMs: number): TokenBucket;
|
|
250
|
+
/**
|
|
251
|
+
* Add the tokens accrued since `lastRefillMs`, clamped to `capacity`, and
|
|
252
|
+
* advance `lastRefillMs` to `nowMs`. PURE — returns a new bucket; the input is
|
|
253
|
+
* untouched.
|
|
254
|
+
*
|
|
255
|
+
* A `nowMs` at or before `lastRefillMs` (clock not advanced, or skewed
|
|
256
|
+
* backwards) adds a non-positive amount; `Math.max(0, …)` floors the elapsed
|
|
257
|
+
* term so a backwards clock can never *remove* tokens. `lastRefillMs` still
|
|
258
|
+
* advances to `nowMs` so the bucket tracks the latest reading the caller
|
|
259
|
+
* presented — the next forward step measures from there, not from a stale
|
|
260
|
+
* future timestamp.
|
|
261
|
+
*/
|
|
262
|
+
declare function refill(bucket: TokenBucket, nowMs: number): TokenBucket;
|
|
263
|
+
/**
|
|
264
|
+
* Refill against `nowMs`, then attempt to take `n` tokens (default 1).
|
|
265
|
+
*
|
|
266
|
+
* On success returns `[next, true]` with `n` subtracted; on failure returns
|
|
267
|
+
* `[refilled, false]` — the refilled bucket (so the caller keeps the advanced
|
|
268
|
+
* clock + accrued tokens) with no tokens spent. Branch on the boolean, thread
|
|
269
|
+
* the bucket forward regardless:
|
|
270
|
+
*
|
|
271
|
+
* const [b1, ok] = tryConsume(bucket, nowMs);
|
|
272
|
+
* return ok ? [{ ...state, bucket: b1 }, [doWork]] : [{ ...state, bucket: b1 }, []];
|
|
273
|
+
*
|
|
274
|
+
* PURE — input bucket is never mutated.
|
|
275
|
+
*/
|
|
276
|
+
declare function tryConsume(bucket: TokenBucket, nowMs: number, n?: number): readonly [TokenBucket, boolean];
|
|
277
|
+
/**
|
|
278
|
+
* A sliding-window log: the timestamps of every hit still inside the trailing
|
|
279
|
+
* `windowMs`, capped at `limit` events per window. `hits` is `readonly` and
|
|
280
|
+
* kept oldest-first (pruning slices the stale prefix off the front, recording
|
|
281
|
+
* appends to the back), so the array is its own sorted index. Exact at the
|
|
282
|
+
* window edge — unlike a token bucket's continuous refill, a hit leaves the
|
|
283
|
+
* count the instant it ages past `windowMs`.
|
|
284
|
+
*/
|
|
285
|
+
interface SlidingWindow {
|
|
286
|
+
readonly hits: readonly number[];
|
|
287
|
+
readonly windowMs: number;
|
|
288
|
+
readonly limit: number;
|
|
289
|
+
}
|
|
290
|
+
/** Create an empty window. No hits recorded yet. */
|
|
291
|
+
declare function initWindow(windowMs: number, limit: number): SlidingWindow;
|
|
292
|
+
/**
|
|
293
|
+
* Prune hits older than `nowMs - windowMs`, then record `nowMs` if there is
|
|
294
|
+
* room. Returns `[next, true]` with the hit appended when `hits.length < limit`
|
|
295
|
+
* after pruning, else `[pruned, false]` — the pruned window (capacity recovers
|
|
296
|
+
* as old hits age out) with nothing appended.
|
|
297
|
+
*
|
|
298
|
+
* The cutoff is half-open (see {@link prune}): a hit exactly `windowMs` old is
|
|
299
|
+
* pruned, so a hit recorded at `t` no longer counts at `t + windowMs`. That
|
|
300
|
+
* makes the window's capacity fully recover `windowMs` after the last hit, the
|
|
301
|
+
* behavior tests pin.
|
|
302
|
+
*
|
|
303
|
+
* PURE — input window is never mutated; `hits` is rebuilt by `filter` +
|
|
304
|
+
* spread.
|
|
305
|
+
*/
|
|
306
|
+
declare function record(window: SlidingWindow, nowMs: number): readonly [SlidingWindow, boolean];
|
|
307
|
+
/**
|
|
308
|
+
* How many more hits `record` would accept at `nowMs` without blocking —
|
|
309
|
+
* `limit` minus the live (post-prune) hit count, floored at 0. Read-only: it
|
|
310
|
+
* prunes a local copy to answer but returns no new window. Use it to render a
|
|
311
|
+
* "N requests remaining" affordance without committing a hit.
|
|
312
|
+
*/
|
|
313
|
+
declare function remaining(window: SlidingWindow, nowMs: number): number;
|
|
314
|
+
|
|
315
|
+
/** Circuit-breaker knob — only the two numbers a consumer ever tunes. */
|
|
316
|
+
interface CircuitConfig {
|
|
317
|
+
/** Consecutive failures that trip the breaker open. */
|
|
318
|
+
readonly threshold: number;
|
|
319
|
+
/** How long the breaker stays open before admitting a probe, in ms. */
|
|
320
|
+
readonly cooldownMs: number;
|
|
321
|
+
/**
|
|
322
|
+
* Probes admitted in `half_open` before fast-failing the rest of the round.
|
|
323
|
+
* Defaults to 1 (a single probe decides recovery) — matches the circuit-
|
|
324
|
+
* breaker module's `defaultCircuitPolicy`.
|
|
325
|
+
*/
|
|
326
|
+
readonly halfOpenMaxProbes?: number;
|
|
327
|
+
}
|
|
328
|
+
/** Token-bucket rate-limit knob. */
|
|
329
|
+
interface RateLimitConfig {
|
|
330
|
+
/** Burst size — the bucket starts full at `capacity`. */
|
|
331
|
+
readonly capacity: number;
|
|
332
|
+
/** Steady-state refill rate, tokens per second. */
|
|
333
|
+
readonly refillPerSec: number;
|
|
334
|
+
}
|
|
335
|
+
/** Per-entry TTL cache knob. */
|
|
336
|
+
interface CacheConfig {
|
|
337
|
+
/** How long a cached success stays fresh, in ms. */
|
|
338
|
+
readonly ttlMs: number;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Overall deadline knob — a budget of IN-PROCESS time per in-flight call.
|
|
342
|
+
*
|
|
343
|
+
* The budget is charged in elapsed time this process actually observed, not by
|
|
344
|
+
* a position on the host's wall clock. Time in which no process exists — a DO
|
|
345
|
+
* eviction, a crash between attempts, a redeploy — is NOT charged: `resume`
|
|
346
|
+
* re-anchors every live call's charging clock, so downtime lands outside every
|
|
347
|
+
* segment. A timeout therefore means "the tool took too long", never "the host
|
|
348
|
+
* was away too long" (#144).
|
|
349
|
+
*/
|
|
350
|
+
interface DeadlineConfig {
|
|
351
|
+
/** Budget of in-process time from the moment a call starts, in ms. */
|
|
352
|
+
readonly ms: number;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* The family every unnamed knob speaks: `resilient_run` / `resilient_ok` /
|
|
356
|
+
* `resilient_err`. Identical to the `MsgType.Resilient*` literals, which stay
|
|
357
|
+
* 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. */
|
|
364
|
+
type ResilientOkType<N extends string> = `${N}_ok`;
|
|
365
|
+
/** The failure settle Msg's `type` for the `N` family. */
|
|
366
|
+
type ResilientErrType<N extends string> = `${N}_err`;
|
|
367
|
+
/**
|
|
368
|
+
* The resilience knob. EVERY field is optional: omit a brick and its gate is
|
|
369
|
+
* skipped entirely (the slice still carries a default brick state so the shape
|
|
370
|
+
* stays uniform across configs, but the gate is never consulted). An empty
|
|
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.
|
|
375
|
+
*/
|
|
376
|
+
interface ResilientConfig<N extends string = DefaultResilientName> {
|
|
377
|
+
/**
|
|
378
|
+
* What this knob's Cmd and settle Msgs are called: `<name>_run`, `<name>_ok`,
|
|
379
|
+
* `<name>_err`. Omit it and the family is `resilient` — `resilient_run` /
|
|
380
|
+
* `resilient_ok` / `resilient_err`, exactly as before this parameter existed.
|
|
381
|
+
*
|
|
382
|
+
* Name a knob when a machine mounts more than one of the resilient family.
|
|
383
|
+
* Two unnamed knobs meet in ONE `resilient_ok` cell whose payload is the union
|
|
384
|
+
* of both results, and the consumer discriminates by hand on `key` — which the
|
|
385
|
+
* type checker cannot see. Under distinct names each knob settles into its own
|
|
386
|
+
* cell, already narrowed to its own payload.
|
|
387
|
+
*
|
|
388
|
+
* The name is a value AND a type: the settle Msg types are generic in `N`, and
|
|
389
|
+
* `N` is not inferable from `I` / `R`, so an opted-in knob spells all three
|
|
390
|
+
* type arguments — `createResilientCall<In, Out, "jev">({ name: "jev", … })`.
|
|
391
|
+
* The `name` field is typed at `N`, so the two cannot drift apart.
|
|
392
|
+
*/
|
|
393
|
+
readonly name?: N;
|
|
394
|
+
/**
|
|
395
|
+
* The backoff brick. Omit and a failure is terminal (no backoff, no timer).
|
|
396
|
+
*
|
|
397
|
+
* Any bound the `../retry-backoff` union admits: a count (`RetryPolicy`), a
|
|
398
|
+
* wall-clock outage budget (`DurationRetryPolicy`), or explicit
|
|
399
|
+
* `unbounded: true`. A duration bound needs no extra wiring: every path that
|
|
400
|
+
* records a failure already holds the instant it was observed as DATA —
|
|
401
|
+
* `fail`'s `msg.at` (stamped at the interpret boundary) and `gate`'s `at`
|
|
402
|
+
* (the caller's `attempt` / the retry timer's `atMs`) — so the streak clock
|
|
403
|
+
* is fed from a Msg, never from a `Date.now()` inside a verb (invariant 2).
|
|
404
|
+
*/
|
|
405
|
+
readonly retry?: AnyRetryPolicy;
|
|
406
|
+
readonly circuit?: CircuitConfig;
|
|
407
|
+
readonly rateLimit?: RateLimitConfig;
|
|
408
|
+
readonly cache?: CacheConfig;
|
|
409
|
+
readonly deadline?: DeadlineConfig;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* What is left of one call's deadline budget, and where the currently open
|
|
413
|
+
* charging segment starts. Plain data, so it persists with the rest of the slice
|
|
414
|
+
* — but the DURABLE fact is `remainingMs`, a duration, never an instant.
|
|
415
|
+
*
|
|
416
|
+
* The accounting has one rule, applied at every transition that carries a clock
|
|
417
|
+
* (`attempt`'s `at`, a settle Msg's `at`, a timer's `atMs`): charge the segment
|
|
418
|
+
* that just closed and open a new one at the same instant —
|
|
419
|
+
* `remainingMs -= at - chargingSinceMs; chargingSinceMs = at`. See {@link charge}.
|
|
420
|
+
*
|
|
421
|
+
* `chargingSinceMs` is an IN-PROCESS anchor, not a persisted deadline. It is
|
|
422
|
+
* meaningful only while the process that wrote it is alive, and `resume` re-bases
|
|
423
|
+
* it on every live call before anything reads it after a reload — which is what
|
|
424
|
+
* keeps downtime out of the budget. Nothing derives a timeout from it across a
|
|
425
|
+
* resume; the only durable answer to "how much budget is left" is `remainingMs`.
|
|
426
|
+
*
|
|
427
|
+
* `remainingMs` is `0` when the `deadline` brick is absent, which is also the
|
|
428
|
+
* "no cap armed" reading `subs` uses — a call with a real budget always has
|
|
429
|
+
* `remainingMs > 0`, because `gate` settles a call whose budget reached zero
|
|
430
|
+
* rather than letting it enter `running`.
|
|
431
|
+
*/
|
|
432
|
+
interface CallBudget {
|
|
433
|
+
/** In-process ms left when the open segment started. `0` = no deadline brick. */
|
|
434
|
+
readonly remainingMs: number;
|
|
435
|
+
/** The instant the open segment started, on the clock of the process that opened it. */
|
|
436
|
+
readonly chargingSinceMs: number;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Per-key call phase. `key` indexes a logical call; several can be in flight at
|
|
440
|
+
* once (the generalization of the example's single `url`). Discriminated on
|
|
441
|
+
* `phase` so each phase carries only its own data (pattern 11):
|
|
442
|
+
*
|
|
443
|
+
* - `idle` — never attempted, or fully settled and forgotten.
|
|
444
|
+
* - `running` — the effect Cmd is out; awaiting `succeed` / `fail`.
|
|
445
|
+
* Carries the deadline budget ({@link CallBudget}) and the
|
|
446
|
+
* last `input` so a retry can re-issue it.
|
|
447
|
+
* - `waiting_retry` — a transient failure backed off; the retry timer is armed
|
|
448
|
+
* for `retryAtMs`. Carries `input` for the re-attempt, and
|
|
449
|
+
* the same budget — backoff is in-process time, so it is
|
|
450
|
+
* charged like an attempt.
|
|
451
|
+
* - `circuit_open` — the breaker fast-failed this attempt. Terminal for this
|
|
452
|
+
* call until the consumer re-attempts after cooldown.
|
|
453
|
+
* - `succeeded` — settled OK. `result` is the value the port produced.
|
|
454
|
+
* - `failed` — settled Err (out of retries, or no retry brick). `error`
|
|
455
|
+
* carries the last failure.
|
|
456
|
+
*/
|
|
457
|
+
type CallPhase<I, R> = {
|
|
458
|
+
readonly phase: "idle";
|
|
459
|
+
} | {
|
|
460
|
+
readonly phase: "running";
|
|
461
|
+
readonly input: I;
|
|
462
|
+
readonly budget: CallBudget;
|
|
463
|
+
} | {
|
|
464
|
+
readonly phase: "waiting_retry";
|
|
465
|
+
readonly input: I;
|
|
466
|
+
readonly retryAtMs: number;
|
|
467
|
+
readonly budget: CallBudget;
|
|
468
|
+
} | {
|
|
469
|
+
readonly phase: "circuit_open";
|
|
470
|
+
} | {
|
|
471
|
+
readonly phase: "succeeded";
|
|
472
|
+
readonly result: R;
|
|
473
|
+
} | {
|
|
474
|
+
readonly phase: "failed";
|
|
475
|
+
readonly error: unknown;
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* The slice. `circuit` / `bucket` are SHARED across keys (one downstream target
|
|
479
|
+
* → one breaker, one bucket). `retry` and `cache` are PER KEY (each logical call
|
|
480
|
+
* has its own backoff count + cached result), as is the per-call `CallPhase`.
|
|
481
|
+
* Every field is plain data → the whole slice serializes into a `Store<S>`.
|
|
482
|
+
*
|
|
483
|
+
* `retry` / `cache` keep a default brick value even when the corresponding
|
|
484
|
+
* config brick is omitted, so the slice shape is identical regardless of which
|
|
485
|
+
* bricks the consumer enabled — the verbs simply never consult the unused brick.
|
|
486
|
+
*/
|
|
487
|
+
interface ResilientState<I, R> {
|
|
488
|
+
readonly circuit: CircuitState;
|
|
489
|
+
readonly bucket: TokenBucket;
|
|
490
|
+
/**
|
|
491
|
+
* Per-key backoff counter. Entries minted by `backoff` are `TimedRetryState`s
|
|
492
|
+
* (they carry the streak's `firstFailureAtMs`, since every failure path holds
|
|
493
|
+
* the observation instant); the field is typed at the `RetryState` supertype
|
|
494
|
+
* because a key that has never failed has no streak, and a slice persisted
|
|
495
|
+
* before the origin existed rehydrates without one. Still plain data.
|
|
496
|
+
*/
|
|
497
|
+
readonly retry: Readonly<Record<string, RetryState>>;
|
|
498
|
+
readonly cache: TtlCache<R>;
|
|
499
|
+
readonly calls: Readonly<Record<string, CallPhase<I, R>>>;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The one effect this knob emits: "run the port for `key` with `input`". The
|
|
503
|
+
* consumer's `handlers(ports)` interprets it; it carries no closure — `input`
|
|
504
|
+
* is plain data (invariant 3).
|
|
505
|
+
*/
|
|
506
|
+
declare function runCmdDef<I, R, N extends string = DefaultResilientName>(name?: N): CmdDef<`${N}_run`, {
|
|
507
|
+
readonly key: string;
|
|
508
|
+
readonly input: I;
|
|
509
|
+
}, R, {
|
|
510
|
+
readonly [detail: string]: unknown;
|
|
511
|
+
readonly _tag: "deadline_exceeded";
|
|
512
|
+
} | {
|
|
513
|
+
readonly [detail: string]: unknown;
|
|
514
|
+
readonly _tag: "port_rejected";
|
|
515
|
+
}, unknown>;
|
|
516
|
+
type RunCmdDef<I, R, N extends string = DefaultResilientName> = ReturnType<typeof runCmdDef<I, R, N>>;
|
|
517
|
+
type RunCmd<I, N extends string = DefaultResilientName> = CmdOf<RunCmdDef<I, unknown, N>>;
|
|
518
|
+
/**
|
|
519
|
+
* Settle Msgs the `handlers` port dispatches back. `at` is stamped at the
|
|
520
|
+
* boundary. Both are generic in the knob's name family `N`, so two knobs named
|
|
521
|
+
* apart land in two `update` cells whose payloads are already narrowed — the
|
|
522
|
+
* `key` switch a single shared cell forces is gone.
|
|
523
|
+
*/
|
|
524
|
+
type SucceedMsg<R, N extends string = DefaultResilientName> = {
|
|
525
|
+
readonly type: ResilientOkType<N>;
|
|
526
|
+
readonly key: string;
|
|
527
|
+
readonly result: R;
|
|
528
|
+
readonly at: number;
|
|
529
|
+
};
|
|
530
|
+
type FailMsg<N extends string = DefaultResilientName> = {
|
|
531
|
+
readonly type: ResilientErrType<N>;
|
|
532
|
+
readonly key: string;
|
|
533
|
+
readonly error: unknown;
|
|
534
|
+
readonly at: number;
|
|
535
|
+
};
|
|
536
|
+
/**
|
|
537
|
+
* The deadline Msg tag this knob's timers dispatch, derived from its name the
|
|
538
|
+
* same way `<name>_ok` / `<name>_err` are. The DEFAULT family keeps the bare
|
|
539
|
+
* `"deadline_exceeded"` literal — that is the tag every machine wired before
|
|
540
|
+
* the name existed already handles, and `mountResilientCall` still returns a
|
|
541
|
+
* `deadline_exceeded` cell for an unnamed knob.
|
|
542
|
+
*/
|
|
543
|
+
type ResilientDeadlineType<N extends string = DefaultResilientName> = N extends DefaultResilientName ? "deadline_exceeded" : `${N}_deadline`;
|
|
544
|
+
/**
|
|
545
|
+
* The name the deadline Sub carries for the `N` family — `undefined` for the
|
|
546
|
+
* default family (no name at all, so the bare literal is dispatched), the name
|
|
547
|
+
* itself otherwise. One conditional, so the value and {@link
|
|
548
|
+
* ResilientDeadlineType} can never disagree about which family is unnamed.
|
|
549
|
+
*/
|
|
550
|
+
type DeadlineNameOf<N extends string = DefaultResilientName> = N extends DefaultResilientName ? undefined : N;
|
|
551
|
+
/**
|
|
552
|
+
* The retry / deadline timer Msg — a `DeadlineExceeded` whose tag is this
|
|
553
|
+
* knob's ({@link ResilientDeadlineType}), keyed by the call `key` through the
|
|
554
|
+
* Sub `id`. Bare `ResilientTimerMsg` is the default family's, so it is the same
|
|
555
|
+
* `DeadlineExceeded` it has always been.
|
|
556
|
+
*/
|
|
557
|
+
type ResilientTimerMsg<N extends string = DefaultResilientName> = DeadlineExceeded<DeadlineNameOf<N>>;
|
|
558
|
+
/**
|
|
559
|
+
* The plain-data error a deadline-failed call settles with. A `{_tag, ...}`
|
|
560
|
+
* sentinel — NEVER a `new Error(...)` — so the slice stays JSON-serializable
|
|
561
|
+
* (Error objects round-trip to `{}` and carry a stack trace, both of which break
|
|
562
|
+
* the slice's durability invariant). `id` / `atMs` echo the timer that fired so
|
|
563
|
+
* a consumer can attribute the failure to its deadline.
|
|
564
|
+
*/
|
|
565
|
+
type DeadlineExceededError = {
|
|
566
|
+
readonly _tag: "deadline_exceeded";
|
|
567
|
+
readonly id: string;
|
|
568
|
+
readonly atMs: number;
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* What `handlers(ports)` returns: the interpret cell for this knob's run Cmd,
|
|
572
|
+
* under that Cmd's own name. A named knob contributes `<name>_run`, so two
|
|
573
|
+
* knobs' handler records merge into one `interpret` without either shadowing
|
|
574
|
+
* the other.
|
|
575
|
+
*/
|
|
576
|
+
type ResilientHandlers<I, R, N extends string = DefaultResilientName> = {
|
|
577
|
+
readonly [K in ResilientRunType<N>]: (cmd: RunCmd<I, N>, ctx: NoCtx) => Promise<SucceedMsg<R, N> | FailMsg<N>>;
|
|
578
|
+
};
|
|
579
|
+
/** Ports the consumer supplies to `handlers`. */
|
|
580
|
+
interface ResilientPorts<I, R> {
|
|
581
|
+
/** The fallible work this knob wraps. Throws on failure → routed to `fail`. */
|
|
582
|
+
readonly run: (input: I, key: string) => Promise<R>;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Build a resilient-call knob from `config`. `rng` is injected for retry
|
|
586
|
+
* jitter — pass a fixed `() => 0.5` in tests to pin backoff; defaults to
|
|
587
|
+
* `Math.random` (read at the verb boundary, never inside a brick op). It is
|
|
588
|
+
* curried onto the factory rather than threaded through every verb so callers
|
|
589
|
+
* spell the determinism choice once.
|
|
590
|
+
*
|
|
591
|
+
* Returns the uniform L2 knob contract. `I` is the port input type, `R` the
|
|
592
|
+
* port result type. Consumers outside the package reach this through
|
|
593
|
+
* `withResilience` (`../with-resilience`) — see the migration map at the top
|
|
594
|
+
* of this module.
|
|
595
|
+
*/
|
|
596
|
+
declare function createResilientCall<I, R, N extends string = DefaultResilientName>(config: ResilientConfig<N>, rng?: () => number): {
|
|
597
|
+
name: N;
|
|
598
|
+
init: () => ResilientState<I, R>;
|
|
599
|
+
attempt: (s: ResilientState<I, R>, key: string, input: I, at: number) => readonly [ResilientState<I, R>, readonly RunCmd<I, N>[]];
|
|
600
|
+
resume: (s: ResilientState<I, R>, at: number) => ResilientState<I, R>;
|
|
601
|
+
succeed: (s: ResilientState<I, R>, key: string, msg: SucceedMsg<R, N>) => readonly [ResilientState<I, R>, readonly RunCmd<I, N>[]];
|
|
602
|
+
fail: (s: ResilientState<I, R>, key: string, msg: FailMsg<N>) => readonly [ResilientState<I, R>, readonly RunCmd<I, N>[]];
|
|
603
|
+
settleFailed: (s: ResilientState<I, R>, key: string, error: unknown) => readonly [ResilientState<I, R>, readonly RunCmd<I, N>[]];
|
|
604
|
+
onTimer: (s: ResilientState<I, R>, msg: ResilientTimerMsg) => readonly [ResilientState<I, R>, readonly RunCmd<I, N>[]];
|
|
605
|
+
subs: (s: ResilientState<I, R>) => readonly DeadlineSub<DeadlineNameOf<N>>[];
|
|
606
|
+
handlers: (ports: ResilientPorts<I, R>) => ResilientHandlers<I, R, N>;
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Lift a knob result `[slice, cmds]` into a host `[State, cmds]` where the
|
|
610
|
+
* slice lives at `state.resilience`. A convenience for the common single-slice
|
|
611
|
+
* host; consumers with a differently-named field spread by hand. Pure — a thin
|
|
612
|
+
* record rebuild, no clock / RNG. Under `withResilience` the wrapper owns
|
|
613
|
+
* `model.$resilience`, so there is nothing to lift; this is for the embedded
|
|
614
|
+
* slice consumers only.
|
|
615
|
+
*
|
|
616
|
+
* The record rebuild itself is `liftSlice` from the root door (#231) — this
|
|
617
|
+
* stays as the named, pre-keyed convenience for the `state.resilience` field,
|
|
618
|
+
* unchanged in name, signature and subpath.
|
|
619
|
+
*/
|
|
620
|
+
declare function liftResilience<S extends {
|
|
621
|
+
resilience: ResilientState<I, R>;
|
|
622
|
+
}, I, R, C extends Cmd>(state: S, result: readonly [ResilientState<I, R>, readonly C[]]): readonly [S, readonly C[]];
|
|
623
|
+
/** What every verb of a knob in this family hands back. */
|
|
624
|
+
type Settle<I, R> = readonly [
|
|
625
|
+
ResilientState<I, R>,
|
|
626
|
+
readonly RunCmd<I>[]
|
|
627
|
+
];
|
|
628
|
+
/**
|
|
629
|
+
* The part of a resilient-call knob {@link mountResilientCall} needs. This knob
|
|
630
|
+
* satisfies it, and so does every knob that delegates these verbs to it —
|
|
631
|
+
* `internal/jev/ask` and `internal/llm-call` both do, which is why the mount is
|
|
632
|
+
* written against the shape rather than against either door.
|
|
633
|
+
*
|
|
634
|
+
* `OkMsg` / `ErrMsg` are parameters rather than {@link SucceedMsg} /
|
|
635
|
+
* {@link FailMsg} because an inheriting knob narrows them: jev-ask's `fail`
|
|
636
|
+
* takes a `JevFailMsg` whose `error` is a typed `JevAskErr`, and a mount that
|
|
637
|
+
* fixed the supertype would hand that verb a widened Msg.
|
|
638
|
+
*/
|
|
639
|
+
interface MountableKnob<I, R, OkMsg, ErrMsg, Handlers, N extends string = DefaultResilientName> {
|
|
640
|
+
/**
|
|
641
|
+
* The Msg-name family this knob settles into — `<name>_ok` / `<name>_err`
|
|
642
|
+
* (#229). The mount reads it rather than assuming `resilient_*`, so a named
|
|
643
|
+
* knob mounts into the cells it actually emits; an unnamed one is
|
|
644
|
+
* `resilient`, so nothing a machine already spread changes.
|
|
645
|
+
*/
|
|
646
|
+
readonly name: N;
|
|
647
|
+
init(): ResilientState<I, R>;
|
|
648
|
+
succeed(s: ResilientState<I, R>, key: string, msg: OkMsg): Settle<I, R>;
|
|
649
|
+
fail(s: ResilientState<I, R>, key: string, msg: ErrMsg): Settle<I, R>;
|
|
650
|
+
onTimer(s: ResilientState<I, R>, msg: ResilientTimerMsg<N>): Settle<I, R>;
|
|
651
|
+
subs(s: ResilientState<I, R>): readonly DeadlineSub<DeadlineNameOf<N>>[];
|
|
652
|
+
handlers(): Handlers;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* The consumer's half of a settle cell: fold the settled answer into the
|
|
656
|
+
* machine's own Model.
|
|
657
|
+
*
|
|
658
|
+
* It is handed the Model the inherited verb ALREADY settled — the slice at
|
|
659
|
+
* `slice` is the post-`succeed` / post-`fail` one — so the ordering that wedges
|
|
660
|
+
* a call at `running` is not something this callback can express. It returns
|
|
661
|
+
* the repo's universal cell shape so a fold that needs to chain an effect
|
|
662
|
+
* (book the answer, then write it somewhere) returns that Cmd like any other
|
|
663
|
+
* reducer cell would.
|
|
664
|
+
*/
|
|
665
|
+
type SettleFold<Model, M, C extends Cmd> = (model: Model, msg: M) => readonly [Model, readonly C[]];
|
|
666
|
+
/** One cell of the update fragment {@link mountResilientCall} returns. */
|
|
667
|
+
type MountedCell<Model, M, I, C extends Cmd> = (model: Model, msg: M) => readonly [Model, readonly (RunCmd<I> | C)[]];
|
|
668
|
+
/**
|
|
669
|
+
* What to mount, and where. `slice` names the Model field the knob's state
|
|
670
|
+
* lives on — a plain, readable field, per
|
|
671
|
+
* [ADR 0015](../../../../.decisions/0015-hide-the-wiring-never-the-state.md):
|
|
672
|
+
* the mount absorbs the assembly and hides none of the durable state.
|
|
673
|
+
*/
|
|
674
|
+
interface MountConfig<Model, Slice extends string, I, R, AttemptType extends string, AttemptMsg, OkMsg, ErrMsg, C extends Cmd, N extends string = DefaultResilientName> {
|
|
675
|
+
/** The Model field carrying the knob's slice. */
|
|
676
|
+
readonly slice: Slice;
|
|
677
|
+
/**
|
|
678
|
+
* The cell that starts a call. Its shape is the one wiring point the mount
|
|
679
|
+
* cannot supply: each door's `attempt` takes its own arguments (jev-ask reads
|
|
680
|
+
* a key, a state and an instant; llm-call reads a request), and only the
|
|
681
|
+
* consumer knows which Msg field carries each. `run` is that one line.
|
|
682
|
+
*/
|
|
683
|
+
readonly attempt: {
|
|
684
|
+
/** The Msg type that starts a call — the key the cell lands on. */
|
|
685
|
+
readonly on: AttemptType;
|
|
686
|
+
readonly run: (slice: ResilientState<I, R>, msg: AttemptMsg) => Settle<I, R>;
|
|
687
|
+
};
|
|
688
|
+
/** Fold a settled success into the Model. Omit and only the slice advances. */
|
|
689
|
+
readonly onOk?: SettleFold<Model, OkMsg, C>;
|
|
690
|
+
/** Fold a settled failure into the Model. Omit and only the slice advances. */
|
|
691
|
+
readonly onErr?: SettleFold<Model, ErrMsg, C>;
|
|
692
|
+
/**
|
|
693
|
+
* Fold a call the TIMER settled into the Model. This is the third failure
|
|
694
|
+
* class, and it never reaches {@link MountConfig.onErr}: a deadline fire
|
|
695
|
+
* settles `failed` inside the slice and emits no settle Msg, so without this
|
|
696
|
+
* callback a call that dies on its budget advances the slice and folds
|
|
697
|
+
* nothing — the shape that used to be a documented caveat.
|
|
698
|
+
*
|
|
699
|
+
* It runs once per call the knob's deadline cell moved INTO `failed`:
|
|
700
|
+
* the deadline fire itself, and the resumed retry whose gate found the
|
|
701
|
+
* budget spent. A plain backoff tick, a stale fire and an already-`failed`
|
|
702
|
+
* call fold nothing. `error` is the slice's own settled error — a
|
|
703
|
+
* {@link DeadlineExceededError} on the deadline path.
|
|
704
|
+
*
|
|
705
|
+
* Omit and only the slice advances, exactly as the other two do.
|
|
706
|
+
*/
|
|
707
|
+
readonly onDeadline?: SettleFold<Model, DeadlineSettled<N>, C>;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* What {@link MountConfig.onDeadline} is handed: the one call the timer cell
|
|
711
|
+
* just settled `failed`, named by its `key`, carrying the error the slice
|
|
712
|
+
* settled with and the timer Msg that produced it. It is not a Msg the reducer
|
|
713
|
+
* ever sees — no settle Msg exists for this failure class, which is the whole
|
|
714
|
+
* reason the callback is here.
|
|
715
|
+
*/
|
|
716
|
+
interface DeadlineSettled<N extends string = DefaultResilientName> {
|
|
717
|
+
/** The call key that settled. */
|
|
718
|
+
readonly key: string;
|
|
719
|
+
/** The error now on the slice — a {@link DeadlineExceededError} on the deadline path. */
|
|
720
|
+
readonly error: unknown;
|
|
721
|
+
/**
|
|
722
|
+
* The timer Msg whose fire settled it — this knob's own tag, so a fold on a
|
|
723
|
+
* knob named `jev` is handed a `jev_deadline` and one on an unnamed knob a
|
|
724
|
+
* `deadline_exceeded`.
|
|
725
|
+
*/
|
|
726
|
+
readonly msg: ResilientTimerMsg<N>;
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* The four fragments a consumer spreads into `defineMachine`. Together with
|
|
730
|
+
* `init` they are the eight wiring points; none of them is optional at the type
|
|
731
|
+
* level, so a consumer that mounts cannot omit `subscribe` (a backed-off retry
|
|
732
|
+
* that never fires) or re-implement `interpret` as a dispatching handler.
|
|
733
|
+
*/
|
|
734
|
+
interface MountedResilientCall<Model, Slice extends string, I, R, AttemptType extends string, AttemptMsg, OkMsg, ErrMsg, C extends Cmd, Handlers, N extends string = DefaultResilientName> {
|
|
735
|
+
/** The starting slice under its field name — spread into the machine's `init`. */
|
|
736
|
+
init(): {
|
|
737
|
+
readonly [K in Slice]: ResilientState<I, R>;
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* The three settle cells plus the attempt cell, to spread into `update`.
|
|
741
|
+
*
|
|
742
|
+
* The two settle keys are the knob's OWN Msg names (#229), so a knob built as
|
|
743
|
+
* `name: "jev"` mounts into `jev_ok` / `jev_err` and two named knobs in one
|
|
744
|
+
* machine spread into four distinct cells instead of colliding on one. An
|
|
745
|
+
* unnamed knob is `resilient`, so the keys read `resilient_ok` /
|
|
746
|
+
* `resilient_err` exactly as they always have.
|
|
747
|
+
*
|
|
748
|
+
* The deadline cell is keyed the same way (#238). A knob's deadline Sub
|
|
749
|
+
* carries its name, so a knob built as `name: "jev"` dispatches
|
|
750
|
+
* `jev_deadline` and mounts into a `jev_deadline` cell; an unnamed knob still
|
|
751
|
+
* dispatches and mounts `deadline_exceeded`. Before that, both mounts wrote
|
|
752
|
+
* the one unqualified `deadline_exceeded` key and the last spread silently
|
|
753
|
+
* dropped the other knob's deadline fold. The cell folds through
|
|
754
|
+
* {@link MountConfig.onDeadline}, since a call the timer settles emits no
|
|
755
|
+
* settle Msg and so reaches no `onErr`.
|
|
756
|
+
*/
|
|
757
|
+
readonly update: Readonly<Record<AttemptType, MountedCell<Model, AttemptMsg, I, C>>> & {
|
|
758
|
+
readonly [K in ResilientOkType<N>]: MountedCell<Model, OkMsg, I, C>;
|
|
759
|
+
} & {
|
|
760
|
+
readonly [K in ResilientErrType<N>]: MountedCell<Model, ErrMsg, I, C>;
|
|
761
|
+
} & {
|
|
762
|
+
readonly [K in ResilientDeadlineType<N>]: MountedCell<Model, ResilientTimerMsg<N>, I, C>;
|
|
763
|
+
};
|
|
764
|
+
subscriptions(model: Model): readonly DeadlineSub<DeadlineNameOf<N>>[];
|
|
765
|
+
readonly subscribe: {
|
|
766
|
+
readonly deadline: typeof subscribeDeadline;
|
|
767
|
+
};
|
|
768
|
+
readonly interpret: Handlers;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Pre-assemble a resilient-call knob into the fragments a machine definition
|
|
772
|
+
* spreads, so mounting one is a spread instead of eight hand-spliced points.
|
|
773
|
+
*
|
|
774
|
+
* The three points that used to fail only at runtime are gone at the type
|
|
775
|
+
* level rather than documented:
|
|
776
|
+
*
|
|
777
|
+
* - The settle cells run the inherited `succeed` / `fail` verb and hand the
|
|
778
|
+
* already-settled Model to {@link SettleFold}. There is no cell for a
|
|
779
|
+
* consumer to write in the wrong order.
|
|
780
|
+
* - `interpret` is `knob.handlers()` — the form that RETURNS the settle Msg
|
|
781
|
+
* so it re-enters the reducer. A consumer that spreads the fragment cannot
|
|
782
|
+
* substitute a dispatching handler for it.
|
|
783
|
+
* - `subscribe` carries `subscribeDeadline`, so the retry timer is armed by
|
|
784
|
+
* construction rather than by remembering.
|
|
785
|
+
*
|
|
786
|
+
* A deadline-exceeded call settles inside the slice and emits no settle Msg, so
|
|
787
|
+
* it reaches no `onErr`. {@link MountConfig.onDeadline} is that failure class's
|
|
788
|
+
* fold — omit it and the slice still advances, exactly as omitting `onErr`
|
|
789
|
+
* does.
|
|
790
|
+
*
|
|
791
|
+
* Nothing is taken away. The slice stays a plain field at `slice` that the
|
|
792
|
+
* consumer reads, `replay` sees and the journal prints, and every verb the
|
|
793
|
+
* fragments call is still exported and callable by hand — a consumer that
|
|
794
|
+
* wants a settle cell this shape cannot express writes that one cell itself and
|
|
795
|
+
* spreads the rest. PURE: a record of closures over `knob` and `config`, no
|
|
796
|
+
* clock and no RNG.
|
|
797
|
+
*/
|
|
798
|
+
declare function mountResilientCall<Slice extends string, I, R, Model extends {
|
|
799
|
+
readonly [K in Slice]: ResilientState<I, R>;
|
|
800
|
+
}, AttemptType extends string, AttemptMsg, OkMsg extends {
|
|
801
|
+
readonly key: string;
|
|
802
|
+
}, ErrMsg extends {
|
|
803
|
+
readonly key: string;
|
|
804
|
+
}, Handlers, C extends Cmd = never, N extends string = DefaultResilientName>(knob: MountableKnob<I, R, OkMsg, ErrMsg, Handlers, N>, config: MountConfig<Model, Slice, I, R, AttemptType, AttemptMsg, OkMsg, ErrMsg, C, N>): MountedResilientCall<Model, Slice, I, R, AttemptType, AttemptMsg, OkMsg, ErrMsg, C, Handlers, N>;
|
|
805
|
+
|
|
806
|
+
export { type SettleFold as A, type SlidingWindow as B, type CircuitConfig as C, type DeadlineConfig as D, canPass as E, type FailMsg as F, createResilientCall as G, defaultCircuitPolicy as H, initBucket as I, initCircuit as J, initWindow as K, liftResilience as L, type MountConfig as M, onFailure as N, onSuccess as O, record as P, refill as Q, type RunCmd as R, type SucceedMsg as S, type TokenBucket as T, remaining as U, runCmdDef as V, tryConsume as W, type ResilientState as a, type RateLimitConfig as b, type ResilientPorts as c, type ResilientHandlers 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, DEFAULT_RESILIENT_NAME as l, mountResilientCall as m, type DeadlineExceededError as n, type DeadlineNameOf as o, type DeadlineSettled as p, type DefaultResilientName as q, type MountableKnob as r, type MountedCell as s, type MountedResilientCall as t, type ResilientDeadlineType as u, type ResilientErrType as v, type ResilientOkType as w, type ResilientRunType as x, type RunCmdDef as y, type Settle as z };
|