@demlik/tea 0.13.0 → 0.14.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 +637 -45
- package/dist/agent/index.js +9 -19
- 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-AQ6ZIMEA.js +421 -0
- package/dist/chunk-AQ6ZIMEA.js.map +1 -0
- package/dist/{chunk-MUUROGIH.js → chunk-BLJ2JQSH.js} +62 -12
- package/dist/chunk-BLJ2JQSH.js.map +1 -0
- package/dist/{chunk-RH5EFRVJ.js → chunk-F2US5BW6.js} +25 -5
- package/dist/chunk-F2US5BW6.js.map +1 -0
- package/dist/{batch-window/index.js → chunk-F7FMAWLA.js} +4 -8
- package/dist/chunk-F7FMAWLA.js.map +1 -0
- package/dist/{chunk-O4MVQTEJ.js → chunk-HUKZQX6U.js} +20 -16
- package/dist/chunk-HUKZQX6U.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-DMYGQB4O.js → chunk-HYDWG35Q.js} +23 -6
- package/dist/chunk-HYDWG35Q.js.map +1 -0
- package/dist/{chunk-YUXP55T2.js → chunk-I5MQMJDW.js} +57 -7
- package/dist/chunk-I5MQMJDW.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-ZVJZ72HY.js → chunk-LYLTKJWM.js} +25 -11
- package/dist/chunk-LYLTKJWM.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-RQULHGYH.js +1804 -0
- package/dist/chunk-RQULHGYH.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-Q2UM7BXU.js → chunk-VBDU4JL6.js} +2 -2
- package/dist/chunk-VBDU4JL6.js.map +1 -0
- package/dist/chunk-Z2L3LSNV.js +1470 -0
- package/dist/chunk-Z2L3LSNV.js.map +1 -0
- package/dist/{core-Co0LWkIA.d.ts → core-CTzMJ82M.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 +42 -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-B0-qGQDy.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 +1295 -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/{batch-window/index.d.ts → index-4vZzljCD.d.ts} +7 -12
- package/dist/{fan-out/index.d.ts → index-6A7dB8f6.d.ts} +7 -9
- package/dist/index-B5BZ-_cT.d.ts +616 -0
- package/dist/index-Bc40JWVl.d.ts +131 -0
- package/dist/{debounce/index.d.ts → index-DHSUmQTR.d.ts} +7 -7
- package/dist/index-DJWIER_3.d.ts +69 -0
- package/dist/{snapshot/index.d.ts → index-DMCeMPMJ.d.ts} +15 -78
- package/dist/{monitored-run/index.d.ts → index-NjrT3fL2.d.ts} +37 -13
- package/dist/{recorder/index.d.ts → index-TvRb1KVf.d.ts} +4 -7
- package/dist/{deadline/index.d.ts → index-q0hXFeZ0.d.ts} +155 -9
- package/dist/index.d.ts +711 -6
- package/dist/index.js +1 -2
- package/dist/jev/index.d.ts +634 -0
- package/dist/jev/index.js +433 -0
- package/dist/jev/index.js.map +1 -0
- package/dist/machine-CdIcN2Xm.d.ts +1773 -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 +151 -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/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 +743 -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-LWDoi943.d.ts +998 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +1 -2
- 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-DP3f5NIl.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.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/protocol-B5YmJr0d.d.ts +0 -45
- 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,616 @@
|
|
|
1
|
+
import { a as CmdOf, b as CmdDef, i as CmdValue, C as Cmd } from './core-CTzMJ82M.js';
|
|
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];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @packageDocumentation
|
|
60
|
+
* internal/resilience/circuit-breaker — per-target failure tracking as pure state + ops.
|
|
61
|
+
*
|
|
62
|
+
* Same shape as `../../work-queue/ops.ts`, `../rate-limit/`, and
|
|
63
|
+
* `../../idempotency/`: a state type plus pure transition functions.
|
|
64
|
+
* Host-agnostic by construction — no `Date.now()`, no timers, no I/O. The
|
|
65
|
+
* caller injects the clock (`nowMs`) and wires the result into its own reducer
|
|
66
|
+
* / interpret. This keeps the breaker inside TEA's invariant 2 (transitions are
|
|
67
|
+
* pure: same inputs → same outputs, no `Date.now`) so a consumer can fold it
|
|
68
|
+
* through `update` and exercise it with `replay` / the pbt fold without a fake
|
|
69
|
+
* clock.
|
|
70
|
+
*
|
|
71
|
+
* Every op returns a NEW state value and never mutates its input (invariant 1 —
|
|
72
|
+
* state is a value, not a place). `canPass` returns a `[next, allowed]` tuple so
|
|
73
|
+
* the caller branches on the decision while threading the advanced state forward
|
|
74
|
+
* — same convention as `rate-limit`'s `tryConsume` / `record`. `onSuccess` /
|
|
75
|
+
* `onFailure` are the outcome-recording transitions the caller folds in once the
|
|
76
|
+
* guarded call resolves.
|
|
77
|
+
*
|
|
78
|
+
* ## The phase machine
|
|
79
|
+
*
|
|
80
|
+
* A circuit breaker guards a fallible downstream target (an HTTP backend, a DB,
|
|
81
|
+
* a flaky tool call). Instead of hammering a target that is already failing, it
|
|
82
|
+
* trips OPEN after enough failures and fast-fails subsequent calls for a
|
|
83
|
+
* cooldown, then probes with a few trial calls before fully closing again.
|
|
84
|
+
* Three phases, each carrying ONLY its own data so impossible states are
|
|
85
|
+
* unrepresentable (pattern 11):
|
|
86
|
+
*
|
|
87
|
+
* - **closed** — the healthy steady state. Calls pass through. Carries
|
|
88
|
+
* `failures`: the count of *consecutive* failures since the last success.
|
|
89
|
+
* A success resets it to 0; the `failureThreshold`-th failure trips the
|
|
90
|
+
* breaker OPEN. Only `closed` has a failure counter — `open` and
|
|
91
|
+
* `half_open` don't, because in those phases the count is irrelevant
|
|
92
|
+
* (the breaker has already tripped / is already probing).
|
|
93
|
+
*
|
|
94
|
+
* - **open** — the tripped state. All calls fast-fail (no downstream load).
|
|
95
|
+
* Carries `openedAtMs`: the clock reading at which the breaker tripped.
|
|
96
|
+
* `canPass` compares `nowMs - openedAtMs` against `cooldownMs` to decide
|
|
97
|
+
* when to start probing. Only `open` carries a timestamp — neither other
|
|
98
|
+
* phase is timing anything.
|
|
99
|
+
*
|
|
100
|
+
* - **half_open** — the probing state. A limited number of trial calls are
|
|
101
|
+
* allowed through to test whether the target has recovered. Carries
|
|
102
|
+
* `probes`: the count of probes admitted so far this probing round.
|
|
103
|
+
* `canPass` admits while `probes < halfOpenMaxProbes`, then fast-fails the
|
|
104
|
+
* rest (so a slow target can't be flooded by every queued caller at once).
|
|
105
|
+
* A probe success closes the breaker; a probe failure re-opens it (and
|
|
106
|
+
* resets the cooldown clock). Only `half_open` counts in-flight probes.
|
|
107
|
+
*
|
|
108
|
+
* ### Transition table
|
|
109
|
+
*
|
|
110
|
+
* Rows are the current phase; columns are the event. `→` denotes the next
|
|
111
|
+
* phase; `self` means unchanged. `nowMs` is the injected clock.
|
|
112
|
+
*
|
|
113
|
+
* | from \ event | onSuccess | onFailure | canPass (→ allowed?) |
|
|
114
|
+
* | ------------ | -------------- | -------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
115
|
+
* | closed | closed(0) | failures+1; trip → open(nowMs) at thr. | self → true (always) |
|
|
116
|
+
* | open | self *(¹)* | self | elapsed ≥ cooldown → half_open(1), true; else self → false |
|
|
117
|
+
* | half_open | → closed(0) | → open(nowMs) (probe failed) | probes < max → half_open(probes+1), true; else self → false |
|
|
118
|
+
*
|
|
119
|
+
* *(¹)* `onSuccess` on `open` "shouldn't happen": no call was admitted while
|
|
120
|
+
* open, so no success can be reported for one. We leave the state unchanged
|
|
121
|
+
* rather than throw — the breaker is a coordination aid, not a correctness
|
|
122
|
+
* gate, and a spurious success report (e.g. a late-arriving result from before
|
|
123
|
+
* the trip) must not silently un-trip the breaker. `onFailure` on `open` is
|
|
124
|
+
* likewise a no-op: the breaker is already tripped; the `open` clock is anchored
|
|
125
|
+
* at the trip, not bumped by late failures.
|
|
126
|
+
*
|
|
127
|
+
* ### The probe-admission asymmetry
|
|
128
|
+
*
|
|
129
|
+
* Entering `half_open` happens inside `canPass`, not `onSuccess` / `onFailure`,
|
|
130
|
+
* because the cooldown is a *time* condition and only `canPass` reads the clock
|
|
131
|
+
* against `openedAtMs`. The first `canPass` after the cooldown elapses both
|
|
132
|
+
* transitions the phase AND admits the probe (`[half_open(1), true]`) — one
|
|
133
|
+
* caller drives the recovery attempt. Subsequent `canPass` calls in the same
|
|
134
|
+
* round admit up to `halfOpenMaxProbes` total, then fast-fail until a probe
|
|
135
|
+
* resolves and `onSuccess` / `onFailure` moves the phase out of `half_open`.
|
|
136
|
+
*
|
|
137
|
+
* This module is a textbook three-state machine — a clean `/machine-viz` demo.
|
|
138
|
+
*
|
|
139
|
+
* Internal to the package (`src/internal/resilience/`), not a published
|
|
140
|
+
* subpath (#46); same one-shape-per-module rule as `work-queue`, `rate-limit`,
|
|
141
|
+
* and `idempotency`.
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* Circuit-breaker policy — pure configuration, no mutable state. One policy is
|
|
145
|
+
* shared across all the calls guarded by one logical breaker (often a
|
|
146
|
+
* module-scope const). `CircuitState` carries the mutable counts; this carries
|
|
147
|
+
* the thresholds those counts are compared against.
|
|
148
|
+
*/
|
|
149
|
+
interface CircuitPolicy {
|
|
150
|
+
/**
|
|
151
|
+
* Consecutive failures in `closed` that trip the breaker `open`. The
|
|
152
|
+
* `failureThreshold`-th failure is the one that trips — with a threshold of
|
|
153
|
+
* 5, the breaker survives 4 failures and opens on the 5th.
|
|
154
|
+
*/
|
|
155
|
+
readonly failureThreshold: number;
|
|
156
|
+
/**
|
|
157
|
+
* How long the breaker stays `open` before `canPass` starts admitting
|
|
158
|
+
* probes, in milliseconds. Measured from `openedAtMs`; the cutoff is
|
|
159
|
+
* half-open (`elapsed >= cooldownMs` admits), matching `rate-limit` /
|
|
160
|
+
* `idempotency` window edges — a breaker opened at `t` first probes at
|
|
161
|
+
* `t + cooldownMs`.
|
|
162
|
+
*/
|
|
163
|
+
readonly cooldownMs: number;
|
|
164
|
+
/**
|
|
165
|
+
* How many probe calls `half_open` admits before fast-failing the rest of
|
|
166
|
+
* the round. Caps the load on a recovering target — a single slow probe
|
|
167
|
+
* can't be joined by every queued caller. The round ends when a probe
|
|
168
|
+
* resolves: success closes the breaker, failure re-opens it.
|
|
169
|
+
*/
|
|
170
|
+
readonly halfOpenMaxProbes: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Sensible defaults: trip after 5 consecutive failures, cool down for 30s,
|
|
174
|
+
* admit a single probe before deciding. Tuned for guarding a network backend;
|
|
175
|
+
* override per call site rather than mutating this shared const.
|
|
176
|
+
*/
|
|
177
|
+
declare const defaultCircuitPolicy: CircuitPolicy;
|
|
178
|
+
/**
|
|
179
|
+
* The breaker's phase. A discriminated union on `phase` so each phase carries
|
|
180
|
+
* ONLY its own data and impossible combinations are unrepresentable (pattern
|
|
181
|
+
* 11): there is no state with both a failure count AND an open timestamp,
|
|
182
|
+
* because such a state is meaningless. `phase` is the discriminant; every field
|
|
183
|
+
* is `readonly` so the whole value is trivially JSON-serializable into a
|
|
184
|
+
* consumer's `Store<S>` and safe to thread through a pure reducer.
|
|
185
|
+
*
|
|
186
|
+
* - `closed` carries `failures` — consecutive failures since last success.
|
|
187
|
+
* - `open` carries `openedAtMs` — clock reading when it tripped.
|
|
188
|
+
* - `half_open` carries `probes` — probes admitted this round.
|
|
189
|
+
*/
|
|
190
|
+
type CircuitState = {
|
|
191
|
+
readonly phase: "closed";
|
|
192
|
+
readonly failures: number;
|
|
193
|
+
} | {
|
|
194
|
+
readonly phase: "open";
|
|
195
|
+
readonly openedAtMs: number;
|
|
196
|
+
} | {
|
|
197
|
+
readonly phase: "half_open";
|
|
198
|
+
readonly probes: number;
|
|
199
|
+
};
|
|
200
|
+
/** The starting state: closed with zero recorded failures. */
|
|
201
|
+
declare function initCircuit(): CircuitState;
|
|
202
|
+
/**
|
|
203
|
+
* Record a successful guarded call. PURE — returns a new state; the input is
|
|
204
|
+
* never mutated.
|
|
205
|
+
*
|
|
206
|
+
* - `closed` → reset `failures` to 0 (a success breaks the consecutive run).
|
|
207
|
+
* - `half_open` → the probe succeeded; the target has recovered → `closed`.
|
|
208
|
+
* - `open` → unchanged. A success "shouldn't happen" while open (no call
|
|
209
|
+
* was admitted to produce one); a late/spurious success must
|
|
210
|
+
* not silently un-trip the breaker. See module header note ¹.
|
|
211
|
+
*/
|
|
212
|
+
declare function onSuccess(state: CircuitState, _policy: CircuitPolicy): CircuitState;
|
|
213
|
+
/**
|
|
214
|
+
* Record a failed guarded call. PURE — returns a new state; the input is never
|
|
215
|
+
* mutated. `nowMs` is the injected clock, stamped onto the `open` phase when the
|
|
216
|
+
* breaker trips so `canPass` can measure the cooldown later.
|
|
217
|
+
*
|
|
218
|
+
* - `closed` → `failures + 1`; if that reaches `failureThreshold`, trip to
|
|
219
|
+
* `open(nowMs)`. The threshold-th failure is the one that trips.
|
|
220
|
+
* - `half_open` → the probe failed; the target is still unhealthy →
|
|
221
|
+
* `open(nowMs)`, restarting the cooldown clock so a fresh
|
|
222
|
+
* cooldown elapses before the next probe round.
|
|
223
|
+
* - `open` → unchanged. The breaker is already tripped; the `open` clock
|
|
224
|
+
* is anchored at the original trip, not bumped by late
|
|
225
|
+
* failures. See module header note ¹.
|
|
226
|
+
*/
|
|
227
|
+
declare function onFailure(state: CircuitState, policy: CircuitPolicy, nowMs: number): CircuitState;
|
|
228
|
+
/**
|
|
229
|
+
* Decide whether a call may pass, advancing the phase as a side effect of the
|
|
230
|
+
* decision. PURE — returns `[next, allowed]`; the input is never mutated.
|
|
231
|
+
* Branch on the boolean, thread the state forward regardless:
|
|
232
|
+
*
|
|
233
|
+
* const [c1, allowed] = canPass(state.circuit, policy, nowMs);
|
|
234
|
+
* if (!allowed) return [{ ...state, circuit: c1 }, [fastFailCmd]];
|
|
235
|
+
* return [{ ...state, circuit: c1 }, [doGuardedCallCmd]];
|
|
236
|
+
*
|
|
237
|
+
* - `closed` → `[state, true]` — always passes; failures are recorded by
|
|
238
|
+
* `onFailure` once the call resolves, not gated here.
|
|
239
|
+
* - `open` → if `nowMs - openedAtMs >= cooldownMs` the cooldown has
|
|
240
|
+
* elapsed → enter `half_open` and admit this caller as the
|
|
241
|
+
* first probe: `[half_open(1), true]`. Otherwise still cooling
|
|
242
|
+
* down → `[state, false]` (fast-fail, no downstream load).
|
|
243
|
+
* - `half_open` → admit while `probes < halfOpenMaxProbes`, incrementing the
|
|
244
|
+
* count: `[half_open(probes+1), true]`. Once the cap is hit →
|
|
245
|
+
* `[state, false]` until a probe resolves and `onSuccess` /
|
|
246
|
+
* `onFailure` moves the phase out of `half_open`.
|
|
247
|
+
*
|
|
248
|
+
* Entering `half_open` lives here (not in `onSuccess` / `onFailure`) because the
|
|
249
|
+
* cooldown is a time condition and only `canPass` reads `nowMs` against
|
|
250
|
+
* `openedAtMs`. See the module header's probe-admission note.
|
|
251
|
+
*/
|
|
252
|
+
declare function canPass(state: CircuitState, policy: CircuitPolicy, nowMs: number): readonly [CircuitState, boolean];
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* internal/resilience/rate-limit — two rate limiters as pure state + ops.
|
|
256
|
+
*
|
|
257
|
+
* Same shape as `../../work-queue/ops.ts`: a state type plus pure
|
|
258
|
+
* transition functions. Host-agnostic by construction — no `Date.now()`, no
|
|
259
|
+
* timers, no I/O. The caller injects the clock (`nowMs`) and wires the result
|
|
260
|
+
* into its own reducer / interpret. This keeps the limiters inside TEA's
|
|
261
|
+
* invariant 2 (transitions are pure: same inputs → same outputs, no `Date.now`)
|
|
262
|
+
* so a consumer can fold them through `update` and exercise them with `replay`
|
|
263
|
+
* / the pbt fold without a fake clock.
|
|
264
|
+
*
|
|
265
|
+
* Every op returns a NEW state value and never mutates its input (invariant 1 —
|
|
266
|
+
* state is a value, not a place). The `tryConsume` / `record` ops return a
|
|
267
|
+
* `[next, ok]` tuple so the caller branches on the decision while threading the
|
|
268
|
+
* advanced state forward; `refill` / `remaining` are read-shaped helpers.
|
|
269
|
+
*
|
|
270
|
+
* Two complementary algorithms, picked by the cost the caller wants to pay:
|
|
271
|
+
*
|
|
272
|
+
* - **Token bucket** — O(1) state (four numbers), smooths bursts against a
|
|
273
|
+
* steady refill rate. Allows a burst up to `capacity`, then throttles to
|
|
274
|
+
* `refillPerSec`. Cheapest; the default choice.
|
|
275
|
+
* - **Sliding window log** — O(limit) state (one timestamp per in-window
|
|
276
|
+
* hit), exact "no more than `limit` events per `windowMs`". Pay the memory
|
|
277
|
+
* for precise window edges when a token bucket's continuous refill would
|
|
278
|
+
* let through too many at a boundary.
|
|
279
|
+
*
|
|
280
|
+
* Internal to the package (`src/internal/resilience/`), not a published
|
|
281
|
+
* subpath (#46); same one-shape-per-module rule as `work-queue` and `do`.
|
|
282
|
+
*/
|
|
283
|
+
/**
|
|
284
|
+
* A token bucket: `tokens` of `capacity` available now, replenished at
|
|
285
|
+
* `refillPerSec` tokens per second. `lastRefillMs` is the clock reading at
|
|
286
|
+
* which `tokens` was last computed — `refill` advances it. All four fields are
|
|
287
|
+
* plain numbers so the whole bucket is trivially JSON-serializable into a
|
|
288
|
+
* consumer's `Store<S>`.
|
|
289
|
+
*/
|
|
290
|
+
interface TokenBucket {
|
|
291
|
+
readonly tokens: number;
|
|
292
|
+
readonly capacity: number;
|
|
293
|
+
readonly refillPerSec: number;
|
|
294
|
+
readonly lastRefillMs: number;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Create a full bucket. Starts at `capacity` tokens (the conventional "a fresh
|
|
298
|
+
* limiter lets the first burst through" behavior) and stamps `lastRefillMs`
|
|
299
|
+
* with the caller's clock so the first `refill` measures elapsed time from
|
|
300
|
+
* boot, not from epoch 0.
|
|
301
|
+
*/
|
|
302
|
+
declare function initBucket(capacity: number, refillPerSec: number, nowMs: number): TokenBucket;
|
|
303
|
+
/**
|
|
304
|
+
* Add the tokens accrued since `lastRefillMs`, clamped to `capacity`, and
|
|
305
|
+
* advance `lastRefillMs` to `nowMs`. PURE — returns a new bucket; the input is
|
|
306
|
+
* untouched.
|
|
307
|
+
*
|
|
308
|
+
* A `nowMs` at or before `lastRefillMs` (clock not advanced, or skewed
|
|
309
|
+
* backwards) adds a non-positive amount; `Math.max(0, …)` floors the elapsed
|
|
310
|
+
* term so a backwards clock can never *remove* tokens. `lastRefillMs` still
|
|
311
|
+
* advances to `nowMs` so the bucket tracks the latest reading the caller
|
|
312
|
+
* presented — the next forward step measures from there, not from a stale
|
|
313
|
+
* future timestamp.
|
|
314
|
+
*/
|
|
315
|
+
declare function refill(bucket: TokenBucket, nowMs: number): TokenBucket;
|
|
316
|
+
/**
|
|
317
|
+
* Refill against `nowMs`, then attempt to take `n` tokens (default 1).
|
|
318
|
+
*
|
|
319
|
+
* On success returns `[next, true]` with `n` subtracted; on failure returns
|
|
320
|
+
* `[refilled, false]` — the refilled bucket (so the caller keeps the advanced
|
|
321
|
+
* clock + accrued tokens) with no tokens spent. Branch on the boolean, thread
|
|
322
|
+
* the bucket forward regardless:
|
|
323
|
+
*
|
|
324
|
+
* const [b1, ok] = tryConsume(bucket, nowMs);
|
|
325
|
+
* return ok ? [{ ...state, bucket: b1 }, [doWork]] : [{ ...state, bucket: b1 }, []];
|
|
326
|
+
*
|
|
327
|
+
* PURE — input bucket is never mutated.
|
|
328
|
+
*/
|
|
329
|
+
declare function tryConsume(bucket: TokenBucket, nowMs: number, n?: number): readonly [TokenBucket, boolean];
|
|
330
|
+
/**
|
|
331
|
+
* A sliding-window log: the timestamps of every hit still inside the trailing
|
|
332
|
+
* `windowMs`, capped at `limit` events per window. `hits` is `readonly` and
|
|
333
|
+
* kept oldest-first (pruning slices the stale prefix off the front, recording
|
|
334
|
+
* appends to the back), so the array is its own sorted index. Exact at the
|
|
335
|
+
* window edge — unlike a token bucket's continuous refill, a hit leaves the
|
|
336
|
+
* count the instant it ages past `windowMs`.
|
|
337
|
+
*/
|
|
338
|
+
interface SlidingWindow {
|
|
339
|
+
readonly hits: readonly number[];
|
|
340
|
+
readonly windowMs: number;
|
|
341
|
+
readonly limit: number;
|
|
342
|
+
}
|
|
343
|
+
/** Create an empty window. No hits recorded yet. */
|
|
344
|
+
declare function initWindow(windowMs: number, limit: number): SlidingWindow;
|
|
345
|
+
/**
|
|
346
|
+
* Prune hits older than `nowMs - windowMs`, then record `nowMs` if there is
|
|
347
|
+
* room. Returns `[next, true]` with the hit appended when `hits.length < limit`
|
|
348
|
+
* after pruning, else `[pruned, false]` — the pruned window (capacity recovers
|
|
349
|
+
* as old hits age out) with nothing appended.
|
|
350
|
+
*
|
|
351
|
+
* The cutoff is half-open (see {@link prune}): a hit exactly `windowMs` old is
|
|
352
|
+
* pruned, so a hit recorded at `t` no longer counts at `t + windowMs`. That
|
|
353
|
+
* makes the window's capacity fully recover `windowMs` after the last hit, the
|
|
354
|
+
* behavior tests pin.
|
|
355
|
+
*
|
|
356
|
+
* PURE — input window is never mutated; `hits` is rebuilt by `filter` +
|
|
357
|
+
* spread.
|
|
358
|
+
*/
|
|
359
|
+
declare function record(window: SlidingWindow, nowMs: number): readonly [SlidingWindow, boolean];
|
|
360
|
+
/**
|
|
361
|
+
* How many more hits `record` would accept at `nowMs` without blocking —
|
|
362
|
+
* `limit` minus the live (post-prune) hit count, floored at 0. Read-only: it
|
|
363
|
+
* prunes a local copy to answer but returns no new window. Use it to render a
|
|
364
|
+
* "N requests remaining" affordance without committing a hit.
|
|
365
|
+
*/
|
|
366
|
+
declare function remaining(window: SlidingWindow, nowMs: number): number;
|
|
367
|
+
|
|
368
|
+
/** Circuit-breaker knob — only the two numbers a consumer ever tunes. */
|
|
369
|
+
interface CircuitConfig {
|
|
370
|
+
/** Consecutive failures that trip the breaker open. */
|
|
371
|
+
readonly threshold: number;
|
|
372
|
+
/** How long the breaker stays open before admitting a probe, in ms. */
|
|
373
|
+
readonly cooldownMs: number;
|
|
374
|
+
/**
|
|
375
|
+
* Probes admitted in `half_open` before fast-failing the rest of the round.
|
|
376
|
+
* Defaults to 1 (a single probe decides recovery) — matches the circuit-
|
|
377
|
+
* breaker module's `defaultCircuitPolicy`.
|
|
378
|
+
*/
|
|
379
|
+
readonly halfOpenMaxProbes?: number;
|
|
380
|
+
}
|
|
381
|
+
/** Token-bucket rate-limit knob. */
|
|
382
|
+
interface RateLimitConfig {
|
|
383
|
+
/** Burst size — the bucket starts full at `capacity`. */
|
|
384
|
+
readonly capacity: number;
|
|
385
|
+
/** Steady-state refill rate, tokens per second. */
|
|
386
|
+
readonly refillPerSec: number;
|
|
387
|
+
}
|
|
388
|
+
/** Per-entry TTL cache knob. */
|
|
389
|
+
interface CacheConfig {
|
|
390
|
+
/** How long a cached success stays fresh, in ms. */
|
|
391
|
+
readonly ttlMs: number;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Overall deadline knob — a budget of IN-PROCESS time per in-flight call.
|
|
395
|
+
*
|
|
396
|
+
* The budget is charged in elapsed time this process actually observed, not by
|
|
397
|
+
* a position on the host's wall clock. Time in which no process exists — a DO
|
|
398
|
+
* eviction, a crash between attempts, a redeploy — is NOT charged: `resume`
|
|
399
|
+
* re-anchors every live call's charging clock, so downtime lands outside every
|
|
400
|
+
* segment. A timeout therefore means "the tool took too long", never "the host
|
|
401
|
+
* was away too long" (#144).
|
|
402
|
+
*/
|
|
403
|
+
interface DeadlineConfig {
|
|
404
|
+
/** Budget of in-process time from the moment a call starts, in ms. */
|
|
405
|
+
readonly ms: number;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* The resilience knob. EVERY field is optional: omit a brick and its gate is
|
|
409
|
+
* skipped entirely (the slice still carries a default brick state so the shape
|
|
410
|
+
* stays uniform across configs, but the gate is never consulted). An empty
|
|
411
|
+
* config `{}` is a valid pass-through — a bare effect with no resilience at all.
|
|
412
|
+
*/
|
|
413
|
+
interface ResilientConfig {
|
|
414
|
+
/**
|
|
415
|
+
* The backoff brick. Omit and a failure is terminal (no backoff, no timer).
|
|
416
|
+
*
|
|
417
|
+
* Any bound the `../retry-backoff` union admits: a count (`RetryPolicy`), a
|
|
418
|
+
* wall-clock outage budget (`DurationRetryPolicy`), or explicit
|
|
419
|
+
* `unbounded: true`. A duration bound needs no extra wiring: every path that
|
|
420
|
+
* 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`
|
|
422
|
+
* (the caller's `attempt` / the retry timer's `atMs`) — so the streak clock
|
|
423
|
+
* is fed from a Msg, never from a `Date.now()` inside a verb (invariant 2).
|
|
424
|
+
*/
|
|
425
|
+
readonly retry?: AnyRetryPolicy;
|
|
426
|
+
readonly circuit?: CircuitConfig;
|
|
427
|
+
readonly rateLimit?: RateLimitConfig;
|
|
428
|
+
readonly cache?: CacheConfig;
|
|
429
|
+
readonly deadline?: DeadlineConfig;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* What is left of one call's deadline budget, and where the currently open
|
|
433
|
+
* charging segment starts. Plain data, so it persists with the rest of the slice
|
|
434
|
+
* — but the DURABLE fact is `remainingMs`, a duration, never an instant.
|
|
435
|
+
*
|
|
436
|
+
* The accounting has one rule, applied at every transition that carries a clock
|
|
437
|
+
* (`attempt`'s `at`, a settle Msg's `at`, a timer's `atMs`): charge the segment
|
|
438
|
+
* that just closed and open a new one at the same instant —
|
|
439
|
+
* `remainingMs -= at - chargingSinceMs; chargingSinceMs = at`. See {@link charge}.
|
|
440
|
+
*
|
|
441
|
+
* `chargingSinceMs` is an IN-PROCESS anchor, not a persisted deadline. It is
|
|
442
|
+
* meaningful only while the process that wrote it is alive, and `resume` re-bases
|
|
443
|
+
* it on every live call before anything reads it after a reload — which is what
|
|
444
|
+
* keeps downtime out of the budget. Nothing derives a timeout from it across a
|
|
445
|
+
* resume; the only durable answer to "how much budget is left" is `remainingMs`.
|
|
446
|
+
*
|
|
447
|
+
* `remainingMs` is `0` when the `deadline` brick is absent, which is also the
|
|
448
|
+
* "no cap armed" reading `subs` uses — a call with a real budget always has
|
|
449
|
+
* `remainingMs > 0`, because `gate` settles a call whose budget reached zero
|
|
450
|
+
* rather than letting it enter `running`.
|
|
451
|
+
*/
|
|
452
|
+
interface CallBudget {
|
|
453
|
+
/** In-process ms left when the open segment started. `0` = no deadline brick. */
|
|
454
|
+
readonly remainingMs: number;
|
|
455
|
+
/** The instant the open segment started, on the clock of the process that opened it. */
|
|
456
|
+
readonly chargingSinceMs: number;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Per-key call phase. `key` indexes a logical call; several can be in flight at
|
|
460
|
+
* once (the generalization of the example's single `url`). Discriminated on
|
|
461
|
+
* `phase` so each phase carries only its own data (pattern 11):
|
|
462
|
+
*
|
|
463
|
+
* - `idle` — never attempted, or fully settled and forgotten.
|
|
464
|
+
* - `running` — the effect Cmd is out; awaiting `succeed` / `fail`.
|
|
465
|
+
* Carries the deadline budget ({@link CallBudget}) and the
|
|
466
|
+
* last `input` so a retry can re-issue it.
|
|
467
|
+
* - `waiting_retry` — a transient failure backed off; the retry timer is armed
|
|
468
|
+
* for `retryAtMs`. Carries `input` for the re-attempt, and
|
|
469
|
+
* the same budget — backoff is in-process time, so it is
|
|
470
|
+
* charged like an attempt.
|
|
471
|
+
* - `circuit_open` — the breaker fast-failed this attempt. Terminal for this
|
|
472
|
+
* call until the consumer re-attempts after cooldown.
|
|
473
|
+
* - `succeeded` — settled OK. `result` is the value the port produced.
|
|
474
|
+
* - `failed` — settled Err (out of retries, or no retry brick). `error`
|
|
475
|
+
* carries the last failure.
|
|
476
|
+
*/
|
|
477
|
+
type CallPhase<I, R> = {
|
|
478
|
+
readonly phase: "idle";
|
|
479
|
+
} | {
|
|
480
|
+
readonly phase: "running";
|
|
481
|
+
readonly input: I;
|
|
482
|
+
readonly budget: CallBudget;
|
|
483
|
+
} | {
|
|
484
|
+
readonly phase: "waiting_retry";
|
|
485
|
+
readonly input: I;
|
|
486
|
+
readonly retryAtMs: number;
|
|
487
|
+
readonly budget: CallBudget;
|
|
488
|
+
} | {
|
|
489
|
+
readonly phase: "circuit_open";
|
|
490
|
+
} | {
|
|
491
|
+
readonly phase: "succeeded";
|
|
492
|
+
readonly result: R;
|
|
493
|
+
} | {
|
|
494
|
+
readonly phase: "failed";
|
|
495
|
+
readonly error: unknown;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* The slice. `circuit` / `bucket` are SHARED across keys (one downstream target
|
|
499
|
+
* → one breaker, one bucket). `retry` and `cache` are PER KEY (each logical call
|
|
500
|
+
* has its own backoff count + cached result), as is the per-call `CallPhase`.
|
|
501
|
+
* Every field is plain data → the whole slice serializes into a `Store<S>`.
|
|
502
|
+
*
|
|
503
|
+
* `retry` / `cache` keep a default brick value even when the corresponding
|
|
504
|
+
* config brick is omitted, so the slice shape is identical regardless of which
|
|
505
|
+
* bricks the consumer enabled — the verbs simply never consult the unused brick.
|
|
506
|
+
*/
|
|
507
|
+
interface ResilientState<I, R> {
|
|
508
|
+
readonly circuit: CircuitState;
|
|
509
|
+
readonly bucket: TokenBucket;
|
|
510
|
+
/**
|
|
511
|
+
* Per-key backoff counter. Entries minted by `backoff` are `TimedRetryState`s
|
|
512
|
+
* (they carry the streak's `firstFailureAtMs`, since every failure path holds
|
|
513
|
+
* the observation instant); the field is typed at the `RetryState` supertype
|
|
514
|
+
* because a key that has never failed has no streak, and a slice persisted
|
|
515
|
+
* before the origin existed rehydrates without one. Still plain data.
|
|
516
|
+
*/
|
|
517
|
+
readonly retry: Readonly<Record<string, RetryState>>;
|
|
518
|
+
readonly cache: TtlCache<R>;
|
|
519
|
+
readonly calls: Readonly<Record<string, CallPhase<I, R>>>;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
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).
|
|
525
|
+
*/
|
|
526
|
+
declare function runCmdDef<I, R>(): CmdDef<"resilient_run", {
|
|
527
|
+
readonly key: string;
|
|
528
|
+
readonly input: I;
|
|
529
|
+
}, R, {
|
|
530
|
+
readonly [detail: string]: unknown;
|
|
531
|
+
readonly _tag: "deadline_exceeded";
|
|
532
|
+
} | {
|
|
533
|
+
readonly [detail: string]: unknown;
|
|
534
|
+
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;
|
|
543
|
+
readonly at: number;
|
|
544
|
+
};
|
|
545
|
+
type FailMsg = {
|
|
546
|
+
readonly type: typeof MsgType.ResilientErr;
|
|
547
|
+
readonly key: string;
|
|
548
|
+
readonly error: unknown;
|
|
549
|
+
readonly at: number;
|
|
550
|
+
};
|
|
551
|
+
/** The retry / deadline timer Msg — `DeadlineExceeded`, keyed by the call `key`. */
|
|
552
|
+
type ResilientTimerMsg = DeadlineExceeded;
|
|
553
|
+
/**
|
|
554
|
+
* The plain-data error a deadline-failed call settles with. A `{_tag, ...}`
|
|
555
|
+
* sentinel — NEVER a `new Error(...)` — so the slice stays JSON-serializable
|
|
556
|
+
* (Error objects round-trip to `{}` and carry a stack trace, both of which break
|
|
557
|
+
* the slice's durability invariant). `id` / `atMs` echo the timer that fired so
|
|
558
|
+
* a consumer can attribute the failure to its deadline.
|
|
559
|
+
*/
|
|
560
|
+
type DeadlineExceededError = {
|
|
561
|
+
readonly _tag: "deadline_exceeded";
|
|
562
|
+
readonly id: string;
|
|
563
|
+
readonly atMs: number;
|
|
564
|
+
};
|
|
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
|
+
/**
|
|
571
|
+
* Build a resilient-call knob from `config`. `rng` is injected for retry
|
|
572
|
+
* jitter — pass a fixed `() => 0.5` in tests to pin backoff; defaults to
|
|
573
|
+
* `Math.random` (read at the verb boundary, never inside a brick op). It is
|
|
574
|
+
* curried onto the factory rather than threaded through every verb so callers
|
|
575
|
+
* spell the determinism choice once.
|
|
576
|
+
*
|
|
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.
|
|
581
|
+
*/
|
|
582
|
+
declare function createResilientCall<I, R>(config: ResilientConfig, rng?: () => number): {
|
|
583
|
+
init: () => ResilientState<I, R>;
|
|
584
|
+
attempt: (s: ResilientState<I, R>, key: string, input: I, at: number) => readonly [ResilientState<I, R>, readonly RunCmd<I>[]];
|
|
585
|
+
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
|
+
};
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Lift a knob result `[slice, cmds]` into a host `[State, cmds]` where the
|
|
606
|
+
* slice lives at `state.resilience`. A convenience for the common single-slice
|
|
607
|
+
* 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.
|
|
611
|
+
*/
|
|
612
|
+
declare function liftResilience<S extends {
|
|
613
|
+
resilience: ResilientState<I, R>;
|
|
614
|
+
}, I, R, C extends Cmd>(state: S, [slice, cmds]: readonly [ResilientState<I, R>, readonly C[]]): readonly [S, readonly C[]];
|
|
615
|
+
|
|
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 };
|