@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
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { B as BootingRuntime,
|
|
2
|
-
export {
|
|
3
|
-
import { C as Cmd, S as Sub, M as Machine, R as RequiredCtx } from './core-
|
|
4
|
-
export { A as AnyCmdDef,
|
|
1
|
+
import { B as BootingRuntime, a as ScopedCtxArg, S as Store, O as OnError, b as Supervision, R as Runtime } from './runtime-types-LWDoi943.js';
|
|
2
|
+
export { c as Branded, C as CtxArg, D as DepToken, d as DepsOf, e as DispatchDiscardedError, f as DispatchSettle, g as DisposeTimeoutNotice, h as DriveFailedError, i as DriveStalledError, j as FencedRead, F as FencedStore, k as FoldRefusal, I as IdentityDropNotice, M as MachineTypes, l as OnReleaseError, P as PortNameCollisionError, m as ProvideFailedError, n as Provided, o as ProvidedCtx, p as Provider, q as ProviderCycleError, Q as QuiescenceTimeoutError, r as RuntimeDiscardNotice, s as RuntimeDiscardedError, t as RuntimeErrorContext, u as RuntimeErrorPhase, v as RuntimeRef, w as Schema, x as Scope, y as StoreConflictError, z as SubIdCollisionError, A as SupervisionStrategy, U as UnknownProviderError, _ as __resetPortRegistry, E as absurd, G as asReducer, H as defineMachine, J as definePort, K as dep, L as isFencedStore, N as isProvided, T as layer, V as noop, W as provide, X as replay, Y as schemaMigrate, Z as settle, $ as tryApplyCell, a0 as tryFoldMsgs, a1 as tryInterpret, a2 as value, a3 as wrapDetached } from './runtime-types-LWDoi943.js';
|
|
3
|
+
import { C as Cmd, S as Sub, M as Machine, R as RequiredCtx, P as Port, D as Dispose, o as DepKeyedSub, c as SubId } from './core-CTzMJ82M.js';
|
|
4
|
+
export { A as AnyCmdDef, b as CmdDef, p as CmdInput, a as CmdOf, i as CmdValue, E as ErrOf, q as ErrorsOf, r as ExhaustiveTransitions, s as Identity, I as Interpret, h as InterpretDetached, t as MachineShape, l as MalformedResult, N as NoCellError, k as NoCtx, O as OkOf, g as PortEmitter, d as Reducer, m as Requirements, f as RequirementsOf, e as Settled, u as SettledErr, v as SettledOk, w as Subscribe, x as SyncReturn, j as Tagged, n as TaggedError, T as Transitions, U as UpdateForm, y as acceptedTypes, z as acceptsOf, B as applyCell, F as applyCellChecked, G as describeMachine, H as detectUpdateForm, J as foldMsgs, K as foldUpdates, L as formOf, Q as msgKeysOf, V as structuralHash, W as subId } from './core-CTzMJ82M.js';
|
|
5
|
+
import { S as SubscribeHandler } from './types-DP3f5NIl.js';
|
|
5
6
|
import 'better-result';
|
|
6
7
|
import 'zod';
|
|
7
8
|
|
|
@@ -51,6 +52,135 @@ declare function historyTracker<S, M extends {
|
|
|
51
52
|
type: string;
|
|
52
53
|
}>(runtime: BootingRuntime<S, M>, size: number): HistoryTracker<S, M>;
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* internal/prediction — the client-prediction ack primitive (epic #186, facet 2).
|
|
57
|
+
* Internal since #49 — not published on any subpath of its own; the
|
|
58
|
+
* client-safe barrel `src/pure/` re-exports the public surface, and the root
|
|
59
|
+
* `@demlik/tea` door publishes it.
|
|
60
|
+
*
|
|
61
|
+
* The contract the Gambetta/Valve authoritative-server netcode loop needs:
|
|
62
|
+
* **command-seq-in → last-applied-seq-out.** A client tags each predicted
|
|
63
|
+
* command/`Msg` with a monotonic `seq`; the authoritative side replies with the
|
|
64
|
+
* `lastAppliedSeq` it has processed. `partitionByAck` then splits the client's
|
|
65
|
+
* pending buffer into the inputs the server has ACKED (`seq <= lastAppliedSeq`)
|
|
66
|
+
* and those still PENDING (`seq > lastAppliedSeq`) — the un-acked tail the
|
|
67
|
+
* reconciliation pass (#214) replays over the authoritative snapshot via
|
|
68
|
+
* `foldMsgs` (#211, the client-safe barrel `src/pure/`).
|
|
69
|
+
*
|
|
70
|
+
* Deliberately **Model-shape-agnostic** (ADR 0006): the ack is a standalone
|
|
71
|
+
* value, NOT a field this module requires on the consumer's `State`. It
|
|
72
|
+
* generalizes the `lastAckedSeq`-on-the-Model + `seq`-threaded-through-the-Msg
|
|
73
|
+
* pattern vortex hand-rolled (epic #186). It is a LEAF module — pure and
|
|
74
|
+
* runtime-free, importing nothing from the tea core or host, so it can never
|
|
75
|
+
* drag `run`/the host into a client bundle.
|
|
76
|
+
*
|
|
77
|
+
* This is the read/ack side of the primitive; `tagSeq`/`nextSeq` are the write
|
|
78
|
+
* side, letting a client mint monotonic seqs from its pending buffer alone —
|
|
79
|
+
* again with no counter field on the Model.
|
|
80
|
+
*
|
|
81
|
+
* `reconcile` (the read side's payoff, #214) composes this ack partition with
|
|
82
|
+
* the pure fold seam `foldMsgs` to perform the whole Gambetta/Valve
|
|
83
|
+
* reconciliation step in one call. The `foldMsgs` import is the ONLY dependency
|
|
84
|
+
* this leaf takes, and it reaches into the pure-core leaf (`../pure/core`) — NOT
|
|
85
|
+
* the runtime root — so the module stays runtime-free and the client-safe
|
|
86
|
+
* import-graph guard (ADR 0006, #213) still holds.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A monotonic, non-negative sequence number tagging one client-predicted
|
|
91
|
+
* command. Monotonicity is the client's contract (mint successive seqs with
|
|
92
|
+
* `nextSeq`); this module only ever *compares* seqs.
|
|
93
|
+
*/
|
|
94
|
+
type Seq = number;
|
|
95
|
+
/** A command (or `Msg`) tagged with the `seq` the client assigned it. */
|
|
96
|
+
interface SeqTagged<T> {
|
|
97
|
+
readonly seq: Seq;
|
|
98
|
+
readonly value: T;
|
|
99
|
+
}
|
|
100
|
+
/** Tag a command/`Msg` with its sequence number. */
|
|
101
|
+
declare const tagSeq: <T>(seq: Seq, value: T) => SeqTagged<T>;
|
|
102
|
+
/**
|
|
103
|
+
* The authoritative side's acknowledgement: the highest `seq` it has applied.
|
|
104
|
+
* Everything with `seq <= lastAppliedSeq` is settled; everything above is still
|
|
105
|
+
* in flight. This *is* the whole "ack from the authoritative side" — a value
|
|
106
|
+
* the consumer carries however it likes (a wire field, a message payload),
|
|
107
|
+
* never a shape this module imposes on the Model.
|
|
108
|
+
*/
|
|
109
|
+
interface Ack {
|
|
110
|
+
readonly lastAppliedSeq: Seq;
|
|
111
|
+
}
|
|
112
|
+
/** Construct an `Ack` for a last-applied sequence number. */
|
|
113
|
+
declare const ack: (lastAppliedSeq: Seq) => Ack;
|
|
114
|
+
/**
|
|
115
|
+
* The "nothing applied yet" cursor — the ack value for a server that has applied
|
|
116
|
+
* no client input at all. Because `nextSeq` mints **0-based** seqs and
|
|
117
|
+
* `partitionByAck` acks **inclusively** (`seq <= lastAppliedSeq`), the pre-first
|
|
118
|
+
* cursor must sit strictly *below* seq 0: `lastAppliedSeq = 0` would falsely ack
|
|
119
|
+
* the seq-0 input before the server ever saw it. `-1` is "before any seq", and
|
|
120
|
+
* `partitionByAck(buffer, NO_ACK)` therefore leaves the whole buffer PENDING.
|
|
121
|
+
*
|
|
122
|
+
* This names the boundary value on the seam so no consumer has to re-discover it
|
|
123
|
+
* as a magic number: it is the primitive's own design (0-based mint + inclusive
|
|
124
|
+
* partition) that creates the trap, so it is the primitive's job to name the
|
|
125
|
+
* escape. Pair with {@link initAck} when an {@link Ack} is wanted instead of the
|
|
126
|
+
* bare `Seq`.
|
|
127
|
+
*/
|
|
128
|
+
declare const NO_ACK: Seq;
|
|
129
|
+
/**
|
|
130
|
+
* The `Ack` for a server that has applied nothing yet — `ack(NO_ACK)`. The `Ack`
|
|
131
|
+
* counterpart to the {@link NO_ACK} `Seq` sentinel, for a consumer that carries
|
|
132
|
+
* an `Ack` rather than a bare `lastAppliedSeq`.
|
|
133
|
+
*/
|
|
134
|
+
declare const initAck: () => Ack;
|
|
135
|
+
/** The result of splitting a seq-tagged buffer against an ack. */
|
|
136
|
+
interface AckPartition<T> {
|
|
137
|
+
/** Inputs the authoritative side has applied (`seq <= lastAppliedSeq`). */
|
|
138
|
+
readonly acked: readonly SeqTagged<T>[];
|
|
139
|
+
/** Inputs still in flight / un-acked (`seq > lastAppliedSeq`) — the replay tail. */
|
|
140
|
+
readonly pending: readonly SeqTagged<T>[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Partition a buffer of seq-tagged commands into ACKED and PENDING against the
|
|
144
|
+
* authoritative `lastAppliedSeq`. Pure and total: every item lands in exactly
|
|
145
|
+
* one bucket, input order is preserved within each bucket, and the boundary
|
|
146
|
+
* `seq == lastAppliedSeq` is ACKED (inclusive `<=`). Routing is by `seq` value,
|
|
147
|
+
* not buffer position, so an out-of-order or duplicate-seq buffer partitions
|
|
148
|
+
* correctly. Accepts either an {@link Ack} or a bare `lastAppliedSeq` number, so
|
|
149
|
+
* a caller passes whichever it holds.
|
|
150
|
+
*/
|
|
151
|
+
declare const partitionByAck: <T>(buffer: readonly SeqTagged<T>[], ackOrSeq: Ack | Seq) => AckPartition<T>;
|
|
152
|
+
/**
|
|
153
|
+
* The next sequence number to assign: one past the highest `seq` in the buffer,
|
|
154
|
+
* or `0` for an empty buffer. Lets a client mint monotonic seqs from its pending
|
|
155
|
+
* buffer alone — no counter field on the Model — and is tolerant of an unordered
|
|
156
|
+
* buffer (it takes the max, not the last element).
|
|
157
|
+
*/
|
|
158
|
+
declare const nextSeq: <T>(buffer: readonly SeqTagged<T>[]) => Seq;
|
|
159
|
+
/**
|
|
160
|
+
* The client prediction/reconciliation helper — the Gambetta/Valve
|
|
161
|
+
* authoritative-server loop's reconcile step, generalized.
|
|
162
|
+
*
|
|
163
|
+
* Given the latest `authoritativeState` from the server, the server's
|
|
164
|
+
* `lastAppliedSeq` ack, and the client's `pending` buffer of seq-tagged inputs,
|
|
165
|
+
* it returns the corrected predicted state: drop the inputs the server has
|
|
166
|
+
* already applied (`seq <= lastAppliedSeq`) and replay ONLY the un-acked tail
|
|
167
|
+
* (`seq > lastAppliedSeq`) over the authoritative snapshot.
|
|
168
|
+
*
|
|
169
|
+
* It is **composed, not re-derived** (ADR 0006): the drop is {@link partitionByAck}
|
|
170
|
+
* (the ack primitive, #212) and the replay is `foldMsgs` (the pure fold seam,
|
|
171
|
+
* #211) — there is no second copy of the partition logic and no second copy of
|
|
172
|
+
* the fold. `lastAppliedSeq` accepts either an {@link Ack} or a bare `Seq`, so a
|
|
173
|
+
* caller passes whichever it holds, matching `partitionByAck`.
|
|
174
|
+
*
|
|
175
|
+
* Pure and host-agnostic: it takes the `machine` (which `foldMsgs` needs to
|
|
176
|
+
* dispatch `update`) but touches no `Store`, `interpret`, or subscription, and
|
|
177
|
+
* imports nothing from the runtime — so it ships through the client-safe
|
|
178
|
+
* umbrella without dragging `run` into a client bundle.
|
|
179
|
+
*/
|
|
180
|
+
declare function reconcile<S, M extends {
|
|
181
|
+
type: string;
|
|
182
|
+
}, C extends Cmd, U extends Sub, Ctx>(machine: Machine<S, M, C, U, Ctx>, authoritativeState: S, lastAppliedSeq: Ack | Seq, pending: readonly SeqTagged<M>[]): S;
|
|
183
|
+
|
|
54
184
|
/**
|
|
55
185
|
* @demlik/tea runtime — `run`: boot + the serial dispatch loop. The pure helpers
|
|
56
186
|
* that compose against a machine without running it (`replay`, `tryInterpret`)
|
|
@@ -61,7 +191,7 @@ declare function run<S, M extends {
|
|
|
61
191
|
type: string;
|
|
62
192
|
}, C extends Cmd, U extends Sub, Ctx, E extends {
|
|
63
193
|
type: string;
|
|
64
|
-
} = never>(machine: Machine<S, M, C, U, Ctx>, opts:
|
|
194
|
+
} = never>(machine: Machine<S, M, C, U, Ctx>, opts: ScopedCtxArg<Ctx & RequiredCtx<C>> & {
|
|
65
195
|
store?: Store<S>;
|
|
66
196
|
onError?: OnError;
|
|
67
197
|
/**
|
|
@@ -111,5 +241,580 @@ declare function run<S, M extends {
|
|
|
111
241
|
*/
|
|
112
242
|
__idleCap?: number;
|
|
113
243
|
}): BootingRuntime<S, M, E>;
|
|
244
|
+
/**
|
|
245
|
+
* The outside-in stop, as a PAIR. A signal is only cancellation if something can
|
|
246
|
+
* turn "aborted" into a transition this machine understands, and the kernel has
|
|
247
|
+
* no built-in cancel Msg any more than it has a built-in terminal set — so the
|
|
248
|
+
* `signal` and the `cancel` that reads it are one option, present together or
|
|
249
|
+
* absent together. A discriminated union rather than two optional fields, on the
|
|
250
|
+
* same reasoning as `AgentCompactionConfig`: a signal with no `cancel` is a stop
|
|
251
|
+
* button wired to nothing, and that is a state worth making unrepresentable
|
|
252
|
+
* rather than checking for.
|
|
253
|
+
*/
|
|
254
|
+
type DriveCancellation<S, M> = {
|
|
255
|
+
readonly signal?: undefined;
|
|
256
|
+
readonly cancel?: undefined;
|
|
257
|
+
} | {
|
|
258
|
+
/**
|
|
259
|
+
* Abort the run through this signal. On abort the drive dispatches
|
|
260
|
+
* `cancel`'s Msg and resolves on the State that lands — it does NOT reject,
|
|
261
|
+
* and a cancellation is never a `DriveFailedError`. Already aborted when
|
|
262
|
+
* the drive is called → the cancel Msg goes in place of `start`, so the
|
|
263
|
+
* run ends without the start's effects ever firing.
|
|
264
|
+
*/
|
|
265
|
+
readonly signal: AbortSignal;
|
|
266
|
+
/**
|
|
267
|
+
* The Msg that settles this machine as cancelled, chosen off the current
|
|
268
|
+
* State exactly as `start` is. PURE. It must land a State `isTerminal`
|
|
269
|
+
* holds for — the drive resolves on the terminal predicate, not on the
|
|
270
|
+
* abort — and that State should be DURABLE, or a reload resumes the run
|
|
271
|
+
* its caller stopped.
|
|
272
|
+
*/
|
|
273
|
+
readonly cancel: (state: S) => M;
|
|
274
|
+
};
|
|
275
|
+
/** Options for `driveToDone`. */
|
|
276
|
+
type DriveToDoneOptions<S, M extends {
|
|
277
|
+
type: string;
|
|
278
|
+
} = never> = DriveCancellation<S, M> & {
|
|
279
|
+
/**
|
|
280
|
+
* Marks a terminal State as a FAILURE. A State this holds for ends the drive
|
|
281
|
+
* like any terminal one — the runtime is stopped — but the drive REJECTS with
|
|
282
|
+
* `DriveFailedError` carrying it instead of resolving. A failed State is
|
|
283
|
+
* terminal by definition; it need not also satisfy `isTerminal`. Omit → the
|
|
284
|
+
* drive never rejects on State, only on a runtime error.
|
|
285
|
+
*/
|
|
286
|
+
readonly failed?: (state: S) => boolean;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Drive a machine from `start` to its terminal State in one call, then tear the
|
|
290
|
+
* runtime down. The one-shot shape every "run this machine to done" test and
|
|
291
|
+
* caller boundary otherwise hand-wires as six steps — `await ready`, `observe`,
|
|
292
|
+
* park a promise, `dispatch(start)`, `getState()`, `stop()` — with the observer
|
|
293
|
+
* leak and the forgotten `stop` those six steps invite.
|
|
294
|
+
*
|
|
295
|
+
* Takes the handle `run()` returns (a `Runtime` extends it, so a booted one is
|
|
296
|
+
* accepted too), awaits `ready`, dispatches `start`, and resolves with the first
|
|
297
|
+
* State for which `isTerminal` holds. A machine that boots already terminal (a
|
|
298
|
+
* rehydrated finished run) resolves on its boot State and `start` is never
|
|
299
|
+
* dispatched — a finished run has nothing to set in motion. `start` may be a
|
|
300
|
+
* function of the boot State instead of a Msg: a machine rehydrated MID-run
|
|
301
|
+
* needs its resume Msg, not its start Msg, and only the boot State says which
|
|
302
|
+
* (the agent's `agent_boot` vs `agent_start` is the case in point). The
|
|
303
|
+
* observer is detached and `stop()` awaited on EVERY exit: resolve, `failed`,
|
|
304
|
+
* a stall, a boot or dispatch throw, the quiescence cap.
|
|
305
|
+
*
|
|
306
|
+
* Rejections are typed, never silent:
|
|
307
|
+
* - `DriveFailedError<S>` when `opts.failed` marks the final State — the State
|
|
308
|
+
* rides on `error.state`.
|
|
309
|
+
* - `DriveStalledError<S>` when `start`'s follow-up chain quiesces on a State
|
|
310
|
+
* that is neither terminal nor `failed` and the runtime has no live Sub and
|
|
311
|
+
* no Cmd in flight — nothing inside it can deliver another transition, so
|
|
312
|
+
* waiting would be a hang with the runtime leaked. The stalled State rides
|
|
313
|
+
* on `error.state`. A machine that CAN still move is not stalled: a live Sub
|
|
314
|
+
* (manual or dep-keyed) that delivers the terminal Msg after the dispatch
|
|
315
|
+
* quiesces keeps the drive waiting, and it resolves on that State. What the
|
|
316
|
+
* runtime cannot see — a dispatch from outside it after quiescence — does
|
|
317
|
+
* not count as live; a machine that depends on one declares it as a Sub.
|
|
318
|
+
* - `QuiescenceTimeoutError` when `start`'s follow-up chain never settles —
|
|
319
|
+
* the SAME cap `dispatch` and `idle()` already reject on (invariant 6), not a
|
|
320
|
+
* second clock. A livelocking machine surfaces as its own failure class.
|
|
321
|
+
* - the boot error, or whatever `dispatch(start)` rejects with, otherwise.
|
|
322
|
+
*
|
|
323
|
+
* `isTerminal` is caller-supplied, exactly as `run()`'s `terminal` option is —
|
|
324
|
+
* the kernel has no built-in terminal-set concept and this does not add one.
|
|
325
|
+
*
|
|
326
|
+
* Cancellation is the same story: `{ signal, cancel }` stops the drive from
|
|
327
|
+
* outside, and it settles the run rather than escaping it. On abort the drive
|
|
328
|
+
* dispatches `cancel`'s Msg and RESOLVES on the terminal State that transition
|
|
329
|
+
* lands — no rejection, no `DriveFailedError`, no `AbortError`. That is the whole
|
|
330
|
+
* point of routing a stop through the Model: the outcome is durable, so a killed
|
|
331
|
+
* process resumes reading a run that ended instead of restarting one someone
|
|
332
|
+
* stopped. A cancel that THROWS is the one abort that rejects: it lands
|
|
333
|
+
* no State, so its error is what the drive has to report — and that holds
|
|
334
|
+
* whether the `cancel` function throws synchronously or the fold it produced
|
|
335
|
+
* throws later, since both leave the run with no State to settle on. A State the
|
|
336
|
+
* caller's `failed` predicate marks rejects on an abort exit exactly as it does
|
|
337
|
+
* anywhere else. In-flight effects are not recalled — a promise cannot be cancelled —
|
|
338
|
+
* so they settle to their own end and `stop()` drains them as it always did;
|
|
339
|
+
* keeping their results off the public channels is the machine's own business.
|
|
340
|
+
* Omit the pair and every path here behaves exactly as it did before.
|
|
341
|
+
*
|
|
342
|
+
* @param handle the handle `run(machine, opts)` returned.
|
|
343
|
+
* @param start the Msg that sets the run in motion, or a function choosing
|
|
344
|
+
* it off the boot State. PURE.
|
|
345
|
+
* @param isTerminal the terminal predicate over the machine's State. PURE.
|
|
346
|
+
* @param opts an optional `failed` predicate and an optional
|
|
347
|
+
* `{ signal, cancel }` pair (see {@link DriveToDoneOptions}).
|
|
348
|
+
*/
|
|
349
|
+
declare function driveToDone<S, M extends {
|
|
350
|
+
type: string;
|
|
351
|
+
}, E extends {
|
|
352
|
+
type: string;
|
|
353
|
+
} = never>(handle: BootingRuntime<S, M, E>, start: M | ((booted: S) => M), isTerminal: (state: S) => boolean, opts?: DriveToDoneOptions<S, M>): Promise<S>;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The imperative listener target, expressed as the `add`/`remove` pair the
|
|
357
|
+
* substrate pairs into a reconciled resource. Both halves receive the SAME
|
|
358
|
+
* `listener` reference — the substrate builds it once — so `remove` can never
|
|
359
|
+
* be handed a different function than `add` saw.
|
|
360
|
+
*
|
|
361
|
+
* `add`/`remove` also receive `(sub, ctx)` so the target may be resolved from
|
|
362
|
+
* `ctx` (a runtime, a port, a DOM node looked up lazily) or keyed on the Sub
|
|
363
|
+
* (an alarm name, a channel name). Resolving the target inside `add` and
|
|
364
|
+
* closing over nothing but the listener keeps a target swap from leaking the
|
|
365
|
+
* old target's listener — same rationale as `fromEventTarget`'s captured
|
|
366
|
+
* target.
|
|
367
|
+
*
|
|
368
|
+
* `Args` is the tuple the platform invokes the listener with — `[Alarm]` for
|
|
369
|
+
* `chrome.alarms.onAlarm`, `[message, sender, sendResponse]` for
|
|
370
|
+
* `chrome.runtime.onMessage`, `[changes, areaName]` for
|
|
371
|
+
* `chrome.storage.onChanged`. The substrate builds ONE function of this exact
|
|
372
|
+
* shape and threads the IDENTICAL reference to both `add` and `remove` — so a
|
|
373
|
+
* platform that matches `removeListener` by reference (every chrome surface)
|
|
374
|
+
* removes exactly what it added. A consumer that wrapped the listener inside
|
|
375
|
+
* `add` would break reference identity (leak #2 above); carrying the native
|
|
376
|
+
* `Args` on the listener itself removes the need for any wrapper.
|
|
377
|
+
*/
|
|
378
|
+
interface ListenerTarget<Args extends readonly unknown[], S extends Sub, Ctx> {
|
|
379
|
+
add: (listener: (...args: Args) => void, sub: S, ctx: Ctx) => void;
|
|
380
|
+
remove: (listener: (...args: Args) => void, sub: S, ctx: Ctx) => void;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Build a listener-backed Sub factory whose cleanup is mandatory and derived.
|
|
384
|
+
*
|
|
385
|
+
* `Args`, `S`, `Ctx` are fixed when the target is defined — they describe the
|
|
386
|
+
* one listener topology this factory owns (the platform arg tuple, which Sub
|
|
387
|
+
* shape it filters on, what context resolves it). `M` is supplied at the
|
|
388
|
+
* subscribe cell because the same listener feeds different Msgs in different
|
|
389
|
+
* machines. Pinning `S` here (rather than at the `msgFn` step) lets
|
|
390
|
+
* `add`/`remove` read the concrete Sub's fields — `sub.alarmName`,
|
|
391
|
+
* `sub.channel` — with NO cast at the substrate edge: the narrowing happens in
|
|
392
|
+
* author-land where the Sub shape is in scope.
|
|
393
|
+
*
|
|
394
|
+
* The returned function is a `SubscribeHandler` factory in the exact shape of
|
|
395
|
+
* every other Sub factory in `src/subs/`: supply the `msgFn` projection, get a
|
|
396
|
+
* `(sub, ctx, dispatch) => cleanup` handler assignable to `machine.subscribe`.
|
|
397
|
+
* The cleanup the author NEVER writes is `() => remove(listener, sub, ctx)`,
|
|
398
|
+
* with `listener` the identical reference passed to `add`.
|
|
399
|
+
*/
|
|
400
|
+
declare function defineListener<Args extends readonly unknown[], S extends Sub = Sub, Ctx = unknown>(target: ListenerTarget<Args, S, Ctx>): <M>(msgFn: (sub: S, ...args: Args) => M | null) => SubscribeHandler<S, M, Ctx>;
|
|
401
|
+
|
|
402
|
+
interface MinimalEvent {
|
|
403
|
+
readonly type: string;
|
|
404
|
+
}
|
|
405
|
+
interface MinimalMessageEvent extends MinimalEvent {
|
|
406
|
+
readonly data: unknown;
|
|
407
|
+
}
|
|
408
|
+
interface MinimalEventTarget {
|
|
409
|
+
addEventListener(type: string, listener: (event: MinimalEvent) => void): void;
|
|
410
|
+
removeEventListener(type: string, listener: (event: MinimalEvent) => void): void;
|
|
411
|
+
}
|
|
412
|
+
interface MinimalCloseEvent extends MinimalEvent {
|
|
413
|
+
readonly code: number;
|
|
414
|
+
readonly reason: string;
|
|
415
|
+
}
|
|
416
|
+
interface MinimalWebSocket {
|
|
417
|
+
close(code?: number, reason?: string): void;
|
|
418
|
+
onopen: ((event: MinimalEvent) => void) | null;
|
|
419
|
+
onmessage: ((event: MinimalMessageEvent) => void) | null;
|
|
420
|
+
onerror: ((event: MinimalEvent) => void) | null;
|
|
421
|
+
onclose: ((event: MinimalCloseEvent) => void) | null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
type BroadcastSubData = {
|
|
425
|
+
channelName: string;
|
|
426
|
+
};
|
|
427
|
+
declare function fromBroadcastChannel<S extends Sub & BroadcastSubData, M>(msgFn: (event: MinimalMessageEvent, sub: S) => M | null): SubscribeHandler<S, M, unknown>;
|
|
428
|
+
|
|
429
|
+
type EventSourceSubData = {
|
|
430
|
+
url: string;
|
|
431
|
+
};
|
|
432
|
+
interface EventSourceFactoryOpts<S, M> {
|
|
433
|
+
onMessage: (data: string, sub: S) => M | null;
|
|
434
|
+
onError?: (event: MinimalEvent, sub: S) => M | null;
|
|
435
|
+
onOpen?: (sub: S) => M | null;
|
|
436
|
+
}
|
|
437
|
+
declare function fromEventSource<S extends Sub & EventSourceSubData, M>(opts: EventSourceFactoryOpts<S, M>): SubscribeHandler<S, M, unknown>;
|
|
438
|
+
|
|
439
|
+
declare function fromEventTarget<S extends Sub, M>(getTarget: () => MinimalEventTarget, eventName: string, msgFn: (event: MinimalEvent, sub: S) => M | null): SubscribeHandler<S, M, unknown>;
|
|
440
|
+
|
|
441
|
+
type IntervalSubData = {
|
|
442
|
+
intervalMs: number;
|
|
443
|
+
};
|
|
444
|
+
declare function fromInterval<S extends Sub & IntervalSubData, M>(msgFn: (sub: S) => M): SubscribeHandler<S, M, unknown>;
|
|
445
|
+
|
|
446
|
+
declare function fromPort<S extends Sub, M, Ctx, T, RS = unknown, RM extends {
|
|
447
|
+
type: string;
|
|
448
|
+
} = {
|
|
449
|
+
type: string;
|
|
450
|
+
}>(selectRuntime: (ctx: Ctx) => Runtime<RS, RM>, port: Port<T>, msgFn: (value: T, sub: S) => M | null): SubscribeHandler<S, M, Ctx>;
|
|
451
|
+
|
|
452
|
+
type WebSocketSubData = {
|
|
453
|
+
wsUrl: string;
|
|
454
|
+
};
|
|
455
|
+
interface WebSocketFactoryOpts<S, M> {
|
|
456
|
+
onMessage: (data: unknown, sub: S) => M | null;
|
|
457
|
+
onOpen?: (sub: S) => M | null;
|
|
458
|
+
onError?: (event: MinimalEvent, sub: S) => M | null;
|
|
459
|
+
onClose?: (code: number, reason: string, sub: S) => M | null;
|
|
460
|
+
}
|
|
461
|
+
declare function fromWebSocket<S extends Sub & WebSocketSubData, M>(opts: WebSocketFactoryOpts<S, M>): SubscribeHandler<S, M, unknown>;
|
|
462
|
+
|
|
463
|
+
/** Cancels a scheduled reconnect timer (the inverse of `schedule`). */
|
|
464
|
+
type CancelTimer = () => void;
|
|
465
|
+
interface ReconnectingWebSocketFactoryOpts<S, M> {
|
|
466
|
+
onMessage: (data: unknown, sub: S) => M | null;
|
|
467
|
+
onOpen?: (sub: S) => M | null;
|
|
468
|
+
onError?: (event: MinimalEvent, sub: S) => M | null;
|
|
469
|
+
onClose?: (code: number, reason: string, sub: S) => M | null;
|
|
470
|
+
/**
|
|
471
|
+
* Fires when a reconnection (any open after the first) succeeds, carrying the
|
|
472
|
+
* 1-based reconnect count — the resync hook. Omitting drops reconnect events
|
|
473
|
+
* silently.
|
|
474
|
+
*/
|
|
475
|
+
onReconnect?: (attempt: number, sub: S) => M | null;
|
|
476
|
+
/** First backoff delay in ms (doubles each failed attempt). Default 250. */
|
|
477
|
+
backoffBaseMs?: number;
|
|
478
|
+
/** Backoff ceiling in ms. Default 5000. */
|
|
479
|
+
backoffMaxMs?: number;
|
|
480
|
+
/** Inject the socket constructor (defaults to the global `WebSocket`); the test seam. */
|
|
481
|
+
connect?: (url: string) => MinimalWebSocket;
|
|
482
|
+
/** Inject the timer (defaults to `setTimeout`/`clearTimeout`); the test seam. */
|
|
483
|
+
schedule?: (fn: () => void, ms: number) => CancelTimer;
|
|
484
|
+
}
|
|
485
|
+
declare function fromReconnectingWebSocket<S extends Sub & WebSocketSubData, M>(opts: ReconnectingWebSocketFactoryOpts<S, M>): SubscribeHandler<S, M, unknown>;
|
|
486
|
+
|
|
487
|
+
type TimeoutSubData = {
|
|
488
|
+
delayMs: number;
|
|
489
|
+
};
|
|
490
|
+
declare function fromTimeout<S extends Sub & TimeoutSubData, M>(msgFn: (sub: S) => M): SubscribeHandler<S, M, unknown>;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The Sub the battery builds. The consumer's `Sub` union includes
|
|
494
|
+
* `ManagedResourceSub<TKey>` directly — the substrate reconciles by `id` and
|
|
495
|
+
* `type` like any other Sub.
|
|
496
|
+
*/
|
|
497
|
+
interface ManagedResourceSub<TKey> extends Sub<"managed_resource"> {
|
|
498
|
+
/** The lifetime key. Stable while the resource should be held; a change
|
|
499
|
+
* retires the old resource (release) and acquires a fresh one. */
|
|
500
|
+
readonly key: TKey;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* A battery paired with a state-gate. Self-contained: it knows its `name`
|
|
504
|
+
* (for the unique-name assert), how to derive its live Sub from a state
|
|
505
|
+
* (`subFor`), how to handle its own `subscribe`, and whether it `owns` a given
|
|
506
|
+
* Sub id.
|
|
507
|
+
*
|
|
508
|
+
* Generic in the consumer state `S`, the shared lifetime key `TKey`, and the
|
|
509
|
+
* shared `Ctx`. `Handle` is the ONLY thing erased — each battery's handle type
|
|
510
|
+
* differs (a checkpoint saver vs. a tool-call bridge) but never crosses this
|
|
511
|
+
* interface, so a `combineManagedResources` array holds entries of
|
|
512
|
+
* heterogeneous handle types with no cast. The sub type stays
|
|
513
|
+
* `ManagedResourceSub<TKey>` end to end, so the substrate's narrowed Sub flows
|
|
514
|
+
* straight in.
|
|
515
|
+
*/
|
|
516
|
+
interface GatedManagedResource<S, TKey, Ctx> {
|
|
517
|
+
/** The owning battery's `name`. The combinator asserts these are unique. */
|
|
518
|
+
readonly name: string;
|
|
519
|
+
/**
|
|
520
|
+
* Derive this resource's live Sub for a given state: the battery's
|
|
521
|
+
* `.sub(key)` when `when(state)` returns a key, or `null` when it returns
|
|
522
|
+
* `null` (the resource should be torn down in that state).
|
|
523
|
+
*/
|
|
524
|
+
readonly subFor: (state: S) => ManagedResourceSub<TKey> | null;
|
|
525
|
+
/**
|
|
526
|
+
* This battery's own `.subscribe`. The combinator routes an incoming
|
|
527
|
+
* `managed_resource` Sub to the entry whose `owns(sub)` is true, then calls
|
|
528
|
+
* this.
|
|
529
|
+
*/
|
|
530
|
+
readonly subscribe: (sub: ManagedResourceSub<TKey>, ctx: Ctx, dispatch: (msg: never) => void) => Dispose;
|
|
531
|
+
/**
|
|
532
|
+
* Does this entry own the given Sub? `sub.id === subIdFor(sub.key)` encodes
|
|
533
|
+
* the battery `name`, so a match is unambiguous.
|
|
534
|
+
*/
|
|
535
|
+
readonly owns: (sub: ManagedResourceSub<TKey>) => boolean;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* What `combineManagedResources` returns: the single managed-resource
|
|
539
|
+
* `subscribe` handler for the machine's `subscribe` record, and a `subs(state)`
|
|
540
|
+
* builder for `subscriptions(state)`.
|
|
541
|
+
*/
|
|
542
|
+
interface CombinedManagedResources<S, TKey, Ctx> {
|
|
543
|
+
/**
|
|
544
|
+
* Map every entry through its `when(state)`, drop the `null`s, and build the
|
|
545
|
+
* live Subs. Spread into `subscriptions(state)`. The derived list and the
|
|
546
|
+
* `subscribe` routing share one source — the entries — so they never drift.
|
|
547
|
+
*/
|
|
548
|
+
readonly subs: (state: S) => ManagedResourceSub<TKey>[];
|
|
549
|
+
/**
|
|
550
|
+
* The SINGLE `subscribe.managed_resource` handler. Routes an incoming Sub to
|
|
551
|
+
* the owning battery by matching `sub.id === battery.subIdFor(sub.key)` (the
|
|
552
|
+
* id encodes the battery `name`). Throws loudly on an unrouted id — a wiring
|
|
553
|
+
* bug, never a silent no-op resource.
|
|
554
|
+
*/
|
|
555
|
+
readonly subscribe: (sub: ManagedResourceSub<TKey>, ctx: Ctx, dispatch: (msg: never) => void) => Dispose;
|
|
556
|
+
}
|
|
557
|
+
interface DefineManagedResourceOpts<TKey, Handle, Ctx> {
|
|
558
|
+
/**
|
|
559
|
+
* A short, stable name. The Sub id is `managed:${name}:${stringify(key)}`,
|
|
560
|
+
* so two managed resources in one machine never collide and neither
|
|
561
|
+
* collides with a `fromTransport` Sub keyed on the same identity.
|
|
562
|
+
*/
|
|
563
|
+
readonly name: string;
|
|
564
|
+
/**
|
|
565
|
+
* Build the resource. Runs when the Sub appears in `subscriptions(state)`.
|
|
566
|
+
* The returned Handle is the ONLY thing `release` receives — capture
|
|
567
|
+
* everything teardown needs into it. If `acquire` throws, the substrate's
|
|
568
|
+
* reconcile does NOT register the Sub and `release` is never called (no
|
|
569
|
+
* dangling half-built resource).
|
|
570
|
+
*/
|
|
571
|
+
readonly acquire: (key: TKey, ctx: Ctx) => Handle;
|
|
572
|
+
/**
|
|
573
|
+
* Tear the resource down. Runs when the Sub leaves the desired set (phase
|
|
574
|
+
* exited) or when its key changes. MANDATORY — the guaranteed teardown is
|
|
575
|
+
* the reason this battery exists.
|
|
576
|
+
*
|
|
577
|
+
* May be sync or async, and an async one is really awaited: the promise is
|
|
578
|
+
* returned to the substrate, which tracks it and drains it inside `stop()`
|
|
579
|
+
* (bounded by `run({ disposeTimeoutMs })`). So `await runtime.stop()` means
|
|
580
|
+
* the release finished — the reading a host evicting an isolate acts on.
|
|
581
|
+
* MID-RUN teardown (a phase exit, a key change) is still fire-and-forget
|
|
582
|
+
* (Rule 2): the reconcile pass is synchronous by construction, so it starts
|
|
583
|
+
* the release and moves on. A rejection is never a Msg — it reaches the
|
|
584
|
+
* runtime's `onError` sink under `phase: "sub-cleanup"`.
|
|
585
|
+
*/
|
|
586
|
+
readonly release: (handle: Handle) => void | Promise<void>;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* What the battery returns: a `.sub(key)` builder for `subscriptions`, the
|
|
590
|
+
* `.subscribe` handler for the machine's `subscribe` record, a `.get(key)`
|
|
591
|
+
* accessor so Cmd handlers can reach the live Handle while the resource is
|
|
592
|
+
* held, and a `.subIdFor(key)` for tests.
|
|
593
|
+
*/
|
|
594
|
+
interface ManagedResourceBattery<TKey, Handle, Ctx> {
|
|
595
|
+
/**
|
|
596
|
+
* Build the Sub for `subscriptions(state)`. The consumer calls this from
|
|
597
|
+
* inside their `subscriptions` cell for the phases where the resource
|
|
598
|
+
* should be live.
|
|
599
|
+
*/
|
|
600
|
+
readonly sub: (key: TKey) => ManagedResourceSub<TKey>;
|
|
601
|
+
/**
|
|
602
|
+
* Pair this battery with a state-gate, producing a self-contained entry for
|
|
603
|
+
* `combineManagedResources`. `when(state)` returns the resource's KEY when
|
|
604
|
+
* it should be live in that state, or `null` when it should be torn down.
|
|
605
|
+
*
|
|
606
|
+
* Folding "is it active?" and "what key?" into ONE declaration at the
|
|
607
|
+
* battery's own definition site is the point: a central `subscriptions(state)`
|
|
608
|
+
* list can silently forget to gate a new phase, but a per-resource gate
|
|
609
|
+
* travels with the resource. The combinator derives BOTH the active-sub list
|
|
610
|
+
* and the subscribe routing from these entries, so the two can never disagree.
|
|
611
|
+
*
|
|
612
|
+
* Generic in the consumer's state `S` (each `.gated` call binds its own `S`).
|
|
613
|
+
* The returned entry erases this battery's `Handle` — `combineManagedResources`
|
|
614
|
+
* holds entries of heterogeneous handle types with no cast — while keeping
|
|
615
|
+
* `TKey` and `Ctx` so the substrate's narrowed `ManagedResourceSub<TKey>`
|
|
616
|
+
* flows straight into the entry's `subscribe`.
|
|
617
|
+
*/
|
|
618
|
+
readonly gated: <S>(when: (state: S) => TKey | null) => GatedManagedResource<S, TKey, Ctx>;
|
|
619
|
+
/**
|
|
620
|
+
* Dep-keyed entry for the machine's `subs` array. `when(state)` returns the
|
|
621
|
+
* resource's KEY when it should be held, or `null` when it should be torn
|
|
622
|
+
* down — the exact gate `.gated` takes, now producing a `DepKeyedSub` the
|
|
623
|
+
* kernel folds directly instead of an entry the `combineManagedResources`
|
|
624
|
+
* router multiplexes.
|
|
625
|
+
*
|
|
626
|
+
* This is the simplification the dep-keyed kernel unlocks: two managed
|
|
627
|
+
* resources used to COLLIDE on the single `subscribe.managed_resource` key
|
|
628
|
+
* (both subs share `type: "managed_resource"`), forcing
|
|
629
|
+
* `combineManagedResources` to route by SubId. A dep-keyed Sub has its OWN
|
|
630
|
+
* reconcile slot (its array position), so there is no shared `type` to route
|
|
631
|
+
* — each resource is one `subs` entry, no combinator, no router. `acquire` /
|
|
632
|
+
* `release` still ride the kernel's dispose-on-change / dispose-on-null
|
|
633
|
+
* reconcile, now via the dep-keyed source's `Dispose` instead of the
|
|
634
|
+
* `subscribe` cell's cleanup.
|
|
635
|
+
*/
|
|
636
|
+
readonly depKeyed: <S>(when: (state: S) => TKey | null) => DepKeyedSub<S, never, Ctx>;
|
|
637
|
+
/**
|
|
638
|
+
* The `subscribe.managed_resource` handler. Drop straight into the
|
|
639
|
+
* machine's `subscribe` record. Runs `acquire` on install, holds the
|
|
640
|
+
* Handle in the battery's handle table, and returns a cleanup that runs
|
|
641
|
+
* `release` (and forgets the Handle) on reconcile-out.
|
|
642
|
+
*/
|
|
643
|
+
readonly subscribe: (sub: ManagedResourceSub<TKey>, ctx: Ctx, dispatch: (msg: never) => void) => Dispose;
|
|
644
|
+
/**
|
|
645
|
+
* Accessor for the live Handle, keyed on `key`. Returns `undefined` when
|
|
646
|
+
* the resource is not currently held (no active sub for that key) — the
|
|
647
|
+
* caller decides whether that is an error. A Cmd handler wires its
|
|
648
|
+
* `ctx.getX(key)` through this, so the handler reads the SAME owner the
|
|
649
|
+
* reconciler holds, never a hand-built duplicate.
|
|
650
|
+
*/
|
|
651
|
+
readonly get: (key: TKey) => Handle | undefined;
|
|
652
|
+
/** Pre-derived subId for `(key)` — handy for tests. */
|
|
653
|
+
readonly subIdFor: (key: TKey) => SubId;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Build the battery. One call per managed resource at the machine's host
|
|
657
|
+
* file.
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* const checkpointStore = defineManagedResource<RunId, CheckpointSaver, Ctx>({
|
|
661
|
+
* name: "checkpoint",
|
|
662
|
+
* acquire: (runId, ctx) =>
|
|
663
|
+
* new CheckpointSaver({ storage: ctx.storage, bucket: ctx.bucket, runId }),
|
|
664
|
+
* release: (saver) => saver.clear(),
|
|
665
|
+
* });
|
|
666
|
+
*
|
|
667
|
+
* // In the machine:
|
|
668
|
+
* subscriptions: (state) =>
|
|
669
|
+
* state.type === "running" ? [checkpointStore.sub(state.runId)] : [],
|
|
670
|
+
* subscribe: { managed_resource: checkpointStore.subscribe },
|
|
671
|
+
*
|
|
672
|
+
* // In interpret (read the live handle the reconciler holds):
|
|
673
|
+
* start_graph: async (cmd, ctx) => {
|
|
674
|
+
* const saver = checkpointStore.get(cmd.runId); // same owner, no rebuild
|
|
675
|
+
* ...
|
|
676
|
+
* }
|
|
677
|
+
*/
|
|
678
|
+
declare function defineManagedResource<TKey, Handle, Ctx>(opts: DefineManagedResourceOpts<TKey, Handle, Ctx>): ManagedResourceBattery<TKey, Handle, Ctx>;
|
|
679
|
+
declare function combineManagedResources<S, TKey, Ctx>(entries: readonly GatedManagedResource<S, TKey, Ctx>[]): CombinedManagedResources<S, TKey, Ctx>;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Duplex transport. The host (DO, worker thread, in-process bus) constructs
|
|
683
|
+
* one from whatever the platform offers. `fromTransport` does not know what
|
|
684
|
+
* a WebSocket is — it knows `send`, `onMessage`, `onClose`.
|
|
685
|
+
*/
|
|
686
|
+
interface Transport {
|
|
687
|
+
/** Send a string frame. Best-effort; failures are logged at the boundary. */
|
|
688
|
+
send(data: string): void;
|
|
689
|
+
/**
|
|
690
|
+
* Subscribe to inbound frames. Returns a cleanup that removes the listener.
|
|
691
|
+
* The battery wires this in its Sub's subscribe handler; cleanup runs when
|
|
692
|
+
* the phase exits (the substrate's reconcileSubs).
|
|
693
|
+
*/
|
|
694
|
+
onMessage(listener: (data: string) => void): () => void;
|
|
695
|
+
/**
|
|
696
|
+
* Subscribe to a one-shot close. Returns a cleanup that removes the
|
|
697
|
+
* listener. The battery dispatches `lostMsg` on close.
|
|
698
|
+
*/
|
|
699
|
+
onClose(listener: () => void): () => void;
|
|
700
|
+
/** Close the underlying channel cleanly. Called by the Sub cleanup. */
|
|
701
|
+
close(): void;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Factory the consumer wires to a platform-specific transport. The battery
|
|
705
|
+
* passes the runtime-derived key (`runId`, or whatever identity is on the
|
|
706
|
+
* phase) so per-run transports can be addressed.
|
|
707
|
+
*/
|
|
708
|
+
type TransportFactory<K> = (key: K) => Transport;
|
|
709
|
+
/**
|
|
710
|
+
* The Sub the battery builds. The consumer's `Sub` union includes
|
|
711
|
+
* `TransportSub<TKey>` directly — no wrapping needed, the substrate
|
|
712
|
+
* reconciles by `id` and `type` like any other Sub.
|
|
713
|
+
*/
|
|
714
|
+
interface TransportSub<TKey> extends Sub<"transport"> {
|
|
715
|
+
/** The phase / run identity. Stable for the lifetime of the seam. */
|
|
716
|
+
readonly key: TKey;
|
|
717
|
+
}
|
|
718
|
+
interface FromTransportOpts<TKey, Inbound, Outbound, M, Ctx> {
|
|
719
|
+
/**
|
|
720
|
+
* A short, stable name for this seam. The Sub id is derived from
|
|
721
|
+
* `${name}:${stringify(key)}` so two seams in the same machine (e.g.
|
|
722
|
+
* `hands` + `worker`) never collide.
|
|
723
|
+
*/
|
|
724
|
+
readonly name: string;
|
|
725
|
+
/**
|
|
726
|
+
* Build the transport. The battery owns the lifetime; the factory is the
|
|
727
|
+
* platform-specific constructor (`new WebSocket(...)` adapter on a DO,
|
|
728
|
+
* `MessagePort` adapter in a worker, in-memory stub in tests).
|
|
729
|
+
*/
|
|
730
|
+
readonly openTransport: (key: TKey, ctx: Ctx) => Transport;
|
|
731
|
+
/**
|
|
732
|
+
* Parse one inbound frame. The battery hands `unknown` through (boundary
|
|
733
|
+
* parse is the consumer's responsibility per invariant 8). Returning
|
|
734
|
+
* `null` drops the frame silently — useful for frames the seam doesn't
|
|
735
|
+
* recognize at this layer (e.g. transport-level keepalive).
|
|
736
|
+
*/
|
|
737
|
+
readonly parseInbound: (raw: string, key: TKey) => Inbound | null;
|
|
738
|
+
/**
|
|
739
|
+
* Map a parsed inbound to a domain Msg. Returning `null` drops the
|
|
740
|
+
* dispatch (e.g. a transport-level pong that doesn't change domain state).
|
|
741
|
+
*/
|
|
742
|
+
readonly onInbound: (inbound: Inbound, key: TKey) => M | null;
|
|
743
|
+
/**
|
|
744
|
+
* The Msg dispatched when the transport closes (peer gone, network
|
|
745
|
+
* dropped, normal close). ONE Msg arm, not a Sub, not a heartbeat-derived
|
|
746
|
+
* deadline — the transport's own close signal is the truth.
|
|
747
|
+
*/
|
|
748
|
+
readonly lostMsg: (key: TKey) => M;
|
|
749
|
+
/**
|
|
750
|
+
* Serialize an outbound. Called by the Cmd handler the battery wires.
|
|
751
|
+
* Pure data → string at the seam boundary.
|
|
752
|
+
*/
|
|
753
|
+
readonly serializeOutbound: (outbound: Outbound) => string;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* What the battery returns: a Sub builder (for `subscriptions`), the Sub's
|
|
757
|
+
* `subscribe` handler (for `subscribe.transport`), and a `send(key, outbound)`
|
|
758
|
+
* helper the consumer's Cmd handler calls. Plus a `subIdFor` factory the
|
|
759
|
+
* consumer can use when keying related Subs (e.g. a deadline) to the same seam
|
|
760
|
+
* identity.
|
|
761
|
+
*/
|
|
762
|
+
interface TransportBattery<TKey, Outbound, M, Ctx> {
|
|
763
|
+
/**
|
|
764
|
+
* Build the Sub for `subscriptions(state)`. The consumer calls this from
|
|
765
|
+
* inside their `subscriptions` cell when the seam should be open.
|
|
766
|
+
*/
|
|
767
|
+
readonly sub: (key: TKey) => TransportSub<TKey>;
|
|
768
|
+
/**
|
|
769
|
+
* The `subscribe.transport` handler. Drop straight into the machine's
|
|
770
|
+
* `subscribe` record — the battery wires inbound + close in one shot.
|
|
771
|
+
*/
|
|
772
|
+
readonly subscribe: (sub: TransportSub<TKey>, ctx: Ctx, dispatch: (msg: M) => void) => () => void;
|
|
773
|
+
/**
|
|
774
|
+
* Outbound send. The Cmd handler calls this; the battery's handle table
|
|
775
|
+
* (built when subscribe ran) routes to the live transport. If the seam
|
|
776
|
+
* is closed (no active sub), the send is dropped honestly (logged, not
|
|
777
|
+
* thrown — the reducer already moved past caring, same shape as Rule 2
|
|
778
|
+
* fire-and-forget Cmds).
|
|
779
|
+
*/
|
|
780
|
+
readonly send: (key: TKey, outbound: Outbound) => void;
|
|
781
|
+
/** Pre-derived subId for `(key)` — handy for deadline Subs keyed to the same seam. */
|
|
782
|
+
readonly subIdFor: (key: TKey) => SubId;
|
|
783
|
+
/**
|
|
784
|
+
* Pair this seam with a state-gate, producing a dep-keyed Sub for the
|
|
785
|
+
* machine's `subs` array. `when(state)` returns the seam's KEY when it
|
|
786
|
+
* should be open, or `null` when it should be torn down. The kernel derives
|
|
787
|
+
* the id from `structuralHash(key)` and reconciles the seam's lifetime — so
|
|
788
|
+
* the author neither lists this Sub in a central `subscriptions(state)` nor
|
|
789
|
+
* writes its id. Replaces `subscriptions: (s) => active(s) ? [hands.sub(...)] : []`
|
|
790
|
+
* + `subscribe: { transport: hands.subscribe }` with one `subs` entry.
|
|
791
|
+
*
|
|
792
|
+
* The `source` closes over the battery's own `subscribe` (open inbound +
|
|
793
|
+
* close, wire the handle table) using the same `ctx` the kernel passes every
|
|
794
|
+
* Sub source.
|
|
795
|
+
*/
|
|
796
|
+
readonly depKeyed: <S>(when: (state: S) => TKey | null) => DepKeyedSub<S, M, Ctx>;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Build the battery. One call per seam at the machine's host file.
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* const handsSeam = fromTransport<RunId, HandsInbound, HandsOutbound, Msg, Ctx>({
|
|
803
|
+
* name: "hands",
|
|
804
|
+
* openTransport: (runId, ctx) => ctx.openHandsWs(runId),
|
|
805
|
+
* parseInbound: (raw) => parseHandsInbound(JSON.parse(raw)),
|
|
806
|
+
* onInbound: (inbound, runId) => ({ type: "hands_said", runId, inbound }),
|
|
807
|
+
* lostMsg: (runId) => ({ type: "hands_lost", runId }),
|
|
808
|
+
* serializeOutbound: (out) => JSON.stringify(out),
|
|
809
|
+
* });
|
|
810
|
+
*
|
|
811
|
+
* // In the machine:
|
|
812
|
+
* subscriptions: (state) => state.type === "auditing" ? [handsSeam.sub(state.runId)] : [],
|
|
813
|
+
* subscribe: { transport: handsSeam.subscribe },
|
|
814
|
+
*
|
|
815
|
+
* // In interpret:
|
|
816
|
+
* send_hands: async (cmd) => { handsSeam.send(cmd.runId, cmd.outbound); },
|
|
817
|
+
*/
|
|
818
|
+
declare function fromTransport<TKey, Inbound, Outbound, M, Ctx>(opts: FromTransportOpts<TKey, Inbound, Outbound, M, Ctx>): TransportBattery<TKey, Outbound, M, Ctx>;
|
|
114
819
|
|
|
115
|
-
export { BootingRuntime, Cmd,
|
|
820
|
+
export { type Ack, type AckPartition, BootingRuntime, type CancelTimer, Cmd, type CombinedManagedResources, type DefineManagedResourceOpts, DepKeyedSub, Dispose, type DriveToDoneOptions, type EventSourceFactoryOpts, type FromTransportOpts, type GatedManagedResource, type HistoryTracker, type ListenerTarget, Machine, type ManagedResourceBattery, type ManagedResourceSub, NO_ACK, OnError, Port, type ReconnectingWebSocketFactoryOpts, RequiredCtx, Runtime, ScopedCtxArg, type Seq, type SeqTagged, Store, Sub, SubId, SubscribeHandler, Supervision, type Transport, type TransportBattery, type TransportFactory, type TransportSub, type WebSocketFactoryOpts, type WebSocketSubData, ack, combineManagedResources, defineListener, defineManagedResource, driveToDone, fromBroadcastChannel, fromEventSource, fromEventTarget, fromInterval, fromPort, fromReconnectingWebSocket, fromTimeout, fromTransport, fromWebSocket, historyTracker, initAck, nextSeq, partitionByAck, reconcile, run, tagSeq };
|