@demlik/tea 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +11 -9
  2. package/dist/agent/index.d.ts +638 -45
  3. package/dist/agent/index.js +9 -19
  4. package/dist/{chunk-RH5EFRVJ.js → chunk-22POWGFA.js} +31 -5
  5. package/dist/chunk-22POWGFA.js.map +1 -0
  6. package/dist/{chunk-DMYGQB4O.js → chunk-3B5X7SBB.js} +23 -6
  7. package/dist/chunk-3B5X7SBB.js.map +1 -0
  8. package/dist/chunk-66PY5WYF.js +1816 -0
  9. package/dist/chunk-66PY5WYF.js.map +1 -0
  10. package/dist/{chunk-25LBDCBC.js → chunk-6IQPODUF.js} +2 -2
  11. package/dist/{chunk-25LBDCBC.js.map → chunk-6IQPODUF.js.map} +1 -1
  12. package/dist/chunk-AYS5N6WY.js +505 -0
  13. package/dist/chunk-AYS5N6WY.js.map +1 -0
  14. package/dist/{chunk-EWJP3YYP.js → chunk-HWVW4AXC.js} +3 -3
  15. package/dist/chunk-HWVW4AXC.js.map +1 -0
  16. package/dist/{chunk-O4MVQTEJ.js → chunk-L3TND7LA.js} +20 -16
  17. package/dist/chunk-L3TND7LA.js.map +1 -0
  18. package/dist/{chunk-J6527VRQ.js → chunk-LFZUK6J2.js} +3 -3
  19. package/dist/chunk-LFZUK6J2.js.map +1 -0
  20. package/dist/{chunk-D736QUGF.js → chunk-MYXFNWAJ.js} +4 -5
  21. package/dist/chunk-MYXFNWAJ.js.map +1 -0
  22. package/dist/{chunk-K575PT4S.js → chunk-PR6TB3BL.js} +15 -4
  23. package/dist/chunk-PR6TB3BL.js.map +1 -0
  24. package/dist/{chunk-YUXP55T2.js → chunk-Q5CQTBFA.js} +57 -7
  25. package/dist/chunk-Q5CQTBFA.js.map +1 -0
  26. package/dist/{batch-window/index.js → chunk-QPEVCJ5Q.js} +4 -8
  27. package/dist/chunk-QPEVCJ5Q.js.map +1 -0
  28. package/dist/chunk-TCLBCERH.js +1480 -0
  29. package/dist/chunk-TCLBCERH.js.map +1 -0
  30. package/dist/{chunk-FV3Z5MBE.js → chunk-TXN2KFHF.js} +14 -4
  31. package/dist/chunk-TXN2KFHF.js.map +1 -0
  32. package/dist/{chunk-MUUROGIH.js → chunk-V46HSVCK.js} +62 -12
  33. package/dist/chunk-V46HSVCK.js.map +1 -0
  34. package/dist/{chunk-Q2UM7BXU.js → chunk-VBDU4JL6.js} +2 -2
  35. package/dist/chunk-VBDU4JL6.js.map +1 -0
  36. package/dist/{chunk-ZVJZ72HY.js → chunk-VTQI2NHP.js} +25 -11
  37. package/dist/chunk-VTQI2NHP.js.map +1 -0
  38. package/dist/{core-Co0LWkIA.d.ts → core-DnzqWy6u.d.ts} +72 -23
  39. package/dist/devtools/index.d.ts +2 -2
  40. package/dist/devtools/index.js +207 -2
  41. package/dist/devtools/index.js.map +1 -1
  42. package/dist/do/index.d.ts +43 -29
  43. package/dist/do/index.js +36 -25
  44. package/dist/do/index.js.map +1 -1
  45. package/dist/{durable-effects-C6uwzjb5.d.ts → durable-effects-CWzA-o2B.d.ts} +2 -2
  46. package/dist/extension/index.d.ts +300 -3
  47. package/dist/extension/index.js +596 -5
  48. package/dist/extension/index.js.map +1 -1
  49. package/dist/flow/index.d.ts +1284 -0
  50. package/dist/flow/index.js +732 -0
  51. package/dist/flow/index.js.map +1 -0
  52. package/dist/idempotency/index.d.ts +90 -116
  53. package/dist/idempotency/index.js +4 -1
  54. package/dist/index-Bc40JWVl.d.ts +131 -0
  55. package/dist/{batch-window/index.d.ts → index-C2DwkjlP.d.ts} +7 -12
  56. package/dist/index-CA_7I5g9.d.ts +806 -0
  57. package/dist/index-CSyMYDAB.d.ts +69 -0
  58. package/dist/{fan-out/index.d.ts → index-CuNO9m8i.d.ts} +7 -9
  59. package/dist/{debounce/index.d.ts → index-DHSUmQTR.d.ts} +7 -7
  60. package/dist/{recorder/index.d.ts → index-DrIRb_Ch.d.ts} +4 -7
  61. package/dist/index-HSYgG2Yt.d.ts +380 -0
  62. package/dist/{monitored-run/index.d.ts → index-KXqTRJyb.d.ts} +37 -13
  63. package/dist/{snapshot/index.d.ts → index-ZCMhnVKN.d.ts} +15 -78
  64. package/dist/index.d.ts +771 -6
  65. package/dist/index.js +1 -2
  66. package/dist/jev/index.d.ts +646 -0
  67. package/dist/jev/index.js +485 -0
  68. package/dist/jev/index.js.map +1 -0
  69. package/dist/machine-DGlPWCWI.d.ts +1781 -0
  70. package/dist/machine-viz/index.d.ts +1 -1
  71. package/dist/machine-viz/index.js +12 -5
  72. package/dist/machine-viz/index.js.map +1 -1
  73. package/dist/mem/index.d.ts +18 -3
  74. package/dist/mem/index.js +22 -2
  75. package/dist/mem/index.js.map +1 -1
  76. package/dist/node/index.d.ts +104 -6
  77. package/dist/node/index.js +132 -9
  78. package/dist/node/index.js.map +1 -1
  79. package/dist/{paginator → paginate}/index.d.ts +140 -6
  80. package/dist/paginate/index.js +7 -0
  81. package/dist/parity/index.d.ts +4 -10
  82. package/dist/parity/index.js +4 -7
  83. package/dist/parity/index.js.map +1 -1
  84. package/dist/pbt/index.d.ts +247 -5
  85. package/dist/pbt/index.js +124 -5
  86. package/dist/pbt/index.js.map +1 -1
  87. package/dist/{trace-replay → persistence}/index.d.ts +7 -5
  88. package/dist/persistence/index.js +6 -0
  89. package/dist/{protocol-B5YmJr0d.d.ts → protocol-D8VbH-VH.d.ts} +10 -1
  90. package/dist/react/index.d.ts +2 -2
  91. package/dist/react/index.js +1 -2
  92. package/dist/react/index.js.map +1 -1
  93. package/dist/resilience/index.d.ts +744 -0
  94. package/dist/resilience/index.js +657 -0
  95. package/dist/resilience/index.js.map +1 -0
  96. package/dist/retry-backoff/index.d.ts +3 -2
  97. package/dist/retry-backoff/index.js +1 -1
  98. package/dist/runtime-types-CMF13BBh.d.ts +998 -0
  99. package/dist/testing/index.d.ts +147 -3
  100. package/dist/testing/index.js +95 -3
  101. package/dist/testing/index.js.map +1 -1
  102. package/dist/{throttled-input → timing}/index.d.ts +143 -12
  103. package/dist/{throttled-input → timing}/index.js +57 -12
  104. package/dist/timing/index.js.map +1 -0
  105. package/dist/{types-XS_miRnB.d.ts → types-BseNPIhr.d.ts} +1 -1
  106. package/dist/work-queue/index.d.ts +130 -54
  107. package/dist/work-queue/index.js +3 -2
  108. package/dist/work-queue/index.js.map +1 -1
  109. package/package.json +45 -218
  110. package/dist/authed-call/index.d.ts +0 -120
  111. package/dist/authed-call/index.js +0 -134
  112. package/dist/authed-call/index.js.map +0 -1
  113. package/dist/await-terminal/index.d.ts +0 -101
  114. package/dist/await-terminal/index.js +0 -76
  115. package/dist/await-terminal/index.js.map +0 -1
  116. package/dist/batch-window/index.js.map +0 -1
  117. package/dist/cache/index.d.ts +0 -152
  118. package/dist/cache/index.js +0 -8
  119. package/dist/chart/index.d.ts +0 -218
  120. package/dist/chart/index.js +0 -16
  121. package/dist/chart/index.js.map +0 -1
  122. package/dist/chart/inspect/index.d.ts +0 -86
  123. package/dist/chart/inspect/index.js +0 -5
  124. package/dist/chart/inspect/react.d.ts +0 -113
  125. package/dist/chart/inspect/react.js +0 -11
  126. package/dist/chart/inspect/react.js.map +0 -1
  127. package/dist/chart/inspect/styles.css +0 -286
  128. package/dist/chart/lane/index.d.ts +0 -362
  129. package/dist/chart/lane/index.js +0 -9
  130. package/dist/chart/lane/index.js.map +0 -1
  131. package/dist/chart/lane/react.d.ts +0 -84
  132. package/dist/chart/lane/react.js +0 -559
  133. package/dist/chart/lane/react.js.map +0 -1
  134. package/dist/chart/lane/server.d.ts +0 -148
  135. package/dist/chart/lane/server.js +0 -209
  136. package/dist/chart/lane/server.js.map +0 -1
  137. package/dist/chart/lane/styles.css +0 -498
  138. package/dist/chart/lane/viewer/assets/abnfDiagram-N423BO3Z-C729LI31.js +0 -1
  139. package/dist/chart/lane/viewer/assets/architectureDiagram-T3A2C74G-C729LI31.js +0 -1
  140. package/dist/chart/lane/viewer/assets/blockDiagram-VBNYF7ZC-C729LI31.js +0 -1
  141. package/dist/chart/lane/viewer/assets/c4Diagram-5PPSVZJV-C729LI31.js +0 -1
  142. package/dist/chart/lane/viewer/assets/chunk-2GRJ4B5K-HdDf8SI3.js +0 -1
  143. package/dist/chart/lane/viewer/assets/chunk-5RXB4S5H-CcNtpUd7.js +0 -231
  144. package/dist/chart/lane/viewer/assets/chunk-5VM5RSS4-BP4fRS_5.js +0 -15
  145. package/dist/chart/lane/viewer/assets/chunk-KBJHAD2P-DZOw7xU6.js +0 -1
  146. package/dist/chart/lane/viewer/assets/chunk-NSK5VX7P-CBCyTZMs.js +0 -128
  147. package/dist/chart/lane/viewer/assets/classDiagram-JCYQIIEL-C729LI31.js +0 -1
  148. package/dist/chart/lane/viewer/assets/classDiagram-v2-OCEON4UE-D4uAiFr8.js +0 -206
  149. package/dist/chart/lane/viewer/assets/cose-bilkent-JH36ORCC-DOwCrGXH.js +0 -1
  150. package/dist/chart/lane/viewer/assets/cynefinDiagram-MW4NZA55-C729LI31.js +0 -1
  151. package/dist/chart/lane/viewer/assets/dagre-K_PewWfS.js +0 -1
  152. package/dist/chart/lane/viewer/assets/dagre-VZM6K2ZE-831qZcA8.js +0 -4
  153. package/dist/chart/lane/viewer/assets/diagram-7IWD3JNH-C729LI31.js +0 -1
  154. package/dist/chart/lane/viewer/assets/diagram-B4RE2ZJO-C729LI31.js +0 -1
  155. package/dist/chart/lane/viewer/assets/diagram-LBJQPF4R-C729LI31.js +0 -1
  156. package/dist/chart/lane/viewer/assets/diagram-Q27KOJAE-C729LI31.js +0 -1
  157. package/dist/chart/lane/viewer/assets/diagram-UB23O5K3-C729LI31.js +0 -1
  158. package/dist/chart/lane/viewer/assets/ebnfDiagram-BXEA7PRR-C729LI31.js +0 -1
  159. package/dist/chart/lane/viewer/assets/erDiagram-JOGREHBK-C729LI31.js +0 -1
  160. package/dist/chart/lane/viewer/assets/flowDiagram-UKHOOZJN-C729LI31.js +0 -1
  161. package/dist/chart/lane/viewer/assets/ganttDiagram-PKOTCBZU-C729LI31.js +0 -1
  162. package/dist/chart/lane/viewer/assets/gitGraphDiagram-DS77QQ5N-C729LI31.js +0 -1
  163. package/dist/chart/lane/viewer/assets/index-9SkH5NA3.css +0 -1
  164. package/dist/chart/lane/viewer/assets/index-Bgt4sXpW.js +0 -195
  165. package/dist/chart/lane/viewer/assets/infoDiagram-6WML65LV-C729LI31.js +0 -1
  166. package/dist/chart/lane/viewer/assets/ishikawaDiagram-WSZJBQD7-C729LI31.js +0 -1
  167. package/dist/chart/lane/viewer/assets/journeyDiagram-NVQOT4AX-C729LI31.js +0 -1
  168. package/dist/chart/lane/viewer/assets/kanban-definition-27J2QSJJ-G7PaPzy-.js +0 -89
  169. package/dist/chart/lane/viewer/assets/katex-DOwCrGXH.js +0 -1
  170. package/dist/chart/lane/viewer/assets/mindmap-definition-FAOFIHXS-CGj9nrVk.js +0 -96
  171. package/dist/chart/lane/viewer/assets/path-fybaL0A-.js +0 -1
  172. package/dist/chart/lane/viewer/assets/pegDiagram-VL7TDLO6-C729LI31.js +0 -1
  173. package/dist/chart/lane/viewer/assets/pieDiagram-7S7Q4E2Y-C729LI31.js +0 -1
  174. package/dist/chart/lane/viewer/assets/quadrantDiagram-CIZ2JOQS-C729LI31.js +0 -1
  175. package/dist/chart/lane/viewer/assets/railroadDiagram-AXF67PYL-C729LI31.js +0 -1
  176. package/dist/chart/lane/viewer/assets/requirementDiagram-LRYGKXZP-C729LI31.js +0 -1
  177. package/dist/chart/lane/viewer/assets/sankeyDiagram-W5VNT64P-C729LI31.js +0 -1
  178. package/dist/chart/lane/viewer/assets/sequenceDiagram-SI44F4Z6-C729LI31.js +0 -1
  179. package/dist/chart/lane/viewer/assets/stateDiagram-OKZ733FA-B_88AzBS.js +0 -1
  180. package/dist/chart/lane/viewer/assets/stateDiagram-v2-UEYNNEHI-CR5gcgq6.js +0 -1
  181. package/dist/chart/lane/viewer/assets/swimlanes-SLNWSIFB-B4xK-rwg.js +0 -1
  182. package/dist/chart/lane/viewer/assets/swimlanesDiagram-ULZ7WXOC-C729LI31.js +0 -1
  183. package/dist/chart/lane/viewer/assets/timeline-definition-Z64GVDOM-CCv52MfY.js +0 -120
  184. package/dist/chart/lane/viewer/assets/vennDiagram-T6HMQDX7-C729LI31.js +0 -1
  185. package/dist/chart/lane/viewer/assets/wardleyDiagram-T6FBY63Y-C729LI31.js +0 -1
  186. package/dist/chart/lane/viewer/assets/xychartDiagram-ELKLHX3M-C729LI31.js +0 -1
  187. package/dist/chart/lane/viewer/index.html +0 -15
  188. package/dist/chart/report/index.d.ts +0 -117
  189. package/dist/chart/report/index.js +0 -32
  190. package/dist/chart/report/index.js.map +0 -1
  191. package/dist/chunk-2YFLOCWX.js +0 -15
  192. package/dist/chunk-2YFLOCWX.js.map +0 -1
  193. package/dist/chunk-3I52QZZ5.js +0 -519
  194. package/dist/chunk-3I52QZZ5.js.map +0 -1
  195. package/dist/chunk-3ZAFFRRB.js +0 -457
  196. package/dist/chunk-3ZAFFRRB.js.map +0 -1
  197. package/dist/chunk-4EQZ76JC.js +0 -33
  198. package/dist/chunk-4EQZ76JC.js.map +0 -1
  199. package/dist/chunk-4KLG43GY.js +0 -223
  200. package/dist/chunk-4KLG43GY.js.map +0 -1
  201. package/dist/chunk-7FRZ2CT2.js +0 -424
  202. package/dist/chunk-7FRZ2CT2.js.map +0 -1
  203. package/dist/chunk-AZZLE7XR.js +0 -62
  204. package/dist/chunk-AZZLE7XR.js.map +0 -1
  205. package/dist/chunk-BYQUGDD3.js +0 -16
  206. package/dist/chunk-BYQUGDD3.js.map +0 -1
  207. package/dist/chunk-CIQG5L42.js +0 -685
  208. package/dist/chunk-CIQG5L42.js.map +0 -1
  209. package/dist/chunk-CLM6ERNO.js +0 -61
  210. package/dist/chunk-CLM6ERNO.js.map +0 -1
  211. package/dist/chunk-COS5MSTO.js +0 -88
  212. package/dist/chunk-COS5MSTO.js.map +0 -1
  213. package/dist/chunk-CRPZJVD2.js +0 -71
  214. package/dist/chunk-CRPZJVD2.js.map +0 -1
  215. package/dist/chunk-D62FDQKE.js +0 -53
  216. package/dist/chunk-D62FDQKE.js.map +0 -1
  217. package/dist/chunk-D736QUGF.js.map +0 -1
  218. package/dist/chunk-DGE4PV4A.js +0 -26
  219. package/dist/chunk-DGE4PV4A.js.map +0 -1
  220. package/dist/chunk-DMYGQB4O.js.map +0 -1
  221. package/dist/chunk-EWJP3YYP.js.map +0 -1
  222. package/dist/chunk-FV3Z5MBE.js.map +0 -1
  223. package/dist/chunk-HCEVHFJ7.js +0 -54
  224. package/dist/chunk-HCEVHFJ7.js.map +0 -1
  225. package/dist/chunk-J6527VRQ.js.map +0 -1
  226. package/dist/chunk-JELSZN25.js +0 -47
  227. package/dist/chunk-JELSZN25.js.map +0 -1
  228. package/dist/chunk-K575PT4S.js.map +0 -1
  229. package/dist/chunk-L57ZOT5K.js +0 -184
  230. package/dist/chunk-L57ZOT5K.js.map +0 -1
  231. package/dist/chunk-MU6MCIAC.js +0 -15
  232. package/dist/chunk-MU6MCIAC.js.map +0 -1
  233. package/dist/chunk-MUUROGIH.js.map +0 -1
  234. package/dist/chunk-NR7BU22N.js +0 -758
  235. package/dist/chunk-NR7BU22N.js.map +0 -1
  236. package/dist/chunk-O4MVQTEJ.js.map +0 -1
  237. package/dist/chunk-OOYD44JI.js +0 -317
  238. package/dist/chunk-OOYD44JI.js.map +0 -1
  239. package/dist/chunk-Q2UM7BXU.js.map +0 -1
  240. package/dist/chunk-RH5EFRVJ.js.map +0 -1
  241. package/dist/chunk-S2EGRPCM.js +0 -47
  242. package/dist/chunk-S2EGRPCM.js.map +0 -1
  243. package/dist/chunk-SINXE47Y.js +0 -55
  244. package/dist/chunk-SINXE47Y.js.map +0 -1
  245. package/dist/chunk-UF4MZSLT.js +0 -53
  246. package/dist/chunk-UF4MZSLT.js.map +0 -1
  247. package/dist/chunk-UOC2PL46.js +0 -13
  248. package/dist/chunk-UOC2PL46.js.map +0 -1
  249. package/dist/chunk-VYFAZN3F.js +0 -372
  250. package/dist/chunk-VYFAZN3F.js.map +0 -1
  251. package/dist/chunk-WRAA7GVZ.js +0 -209
  252. package/dist/chunk-WRAA7GVZ.js.map +0 -1
  253. package/dist/chunk-XGELA764.js +0 -163
  254. package/dist/chunk-XGELA764.js.map +0 -1
  255. package/dist/chunk-YUXP55T2.js.map +0 -1
  256. package/dist/chunk-YWIKDKHY.js +0 -307
  257. package/dist/chunk-YWIKDKHY.js.map +0 -1
  258. package/dist/chunk-ZJ5AOYBH.js +0 -8
  259. package/dist/chunk-ZJ5AOYBH.js.map +0 -1
  260. package/dist/chunk-ZSUUOEPL.js +0 -731
  261. package/dist/chunk-ZSUUOEPL.js.map +0 -1
  262. package/dist/chunk-ZVJZ72HY.js.map +0 -1
  263. package/dist/circuit-breaker/index.d.ts +0 -197
  264. package/dist/circuit-breaker/index.js +0 -3
  265. package/dist/circuit-breaker/index.js.map +0 -1
  266. package/dist/deadline/index.d.ts +0 -199
  267. package/dist/deadline/index.js +0 -6
  268. package/dist/deadline/index.js.map +0 -1
  269. package/dist/debounce/index.js +0 -3
  270. package/dist/debounce/index.js.map +0 -1
  271. package/dist/extension/react.d.ts +0 -121
  272. package/dist/extension/react.js +0 -75
  273. package/dist/extension/react.js.map +0 -1
  274. package/dist/extension/subs/index.d.ts +0 -45
  275. package/dist/extension/subs/index.js +0 -80
  276. package/dist/extension/subs/index.js.map +0 -1
  277. package/dist/extension/test-utils.d.ts +0 -128
  278. package/dist/extension/test-utils.js +0 -277
  279. package/dist/extension/test-utils.js.map +0 -1
  280. package/dist/fan-out/index.js +0 -5
  281. package/dist/fan-out/index.js.map +0 -1
  282. package/dist/fold-BJPdjc9w.d.ts +0 -435
  283. package/dist/graph-B3L5e0N1.d.ts +0 -923
  284. package/dist/idempotency/adapter.d.ts +0 -62
  285. package/dist/idempotency/adapter.js +0 -4
  286. package/dist/idempotency/adapter.js.map +0 -1
  287. package/dist/idempotent-intake/index.d.ts +0 -188
  288. package/dist/idempotent-intake/index.js +0 -7
  289. package/dist/idempotent-intake/index.js.map +0 -1
  290. package/dist/journal/index.d.ts +0 -373
  291. package/dist/journal/index.js +0 -3
  292. package/dist/journal/index.js.map +0 -1
  293. package/dist/llm-call/index.d.ts +0 -311
  294. package/dist/llm-call/index.js +0 -16
  295. package/dist/llm-call/index.js.map +0 -1
  296. package/dist/machine-BtFWQmmq.d.ts +0 -804
  297. package/dist/monitored-run/index.js +0 -10
  298. package/dist/monitored-run/index.js.map +0 -1
  299. package/dist/paginated-walk/index.d.ts +0 -235
  300. package/dist/paginated-walk/index.js +0 -16
  301. package/dist/paginated-walk/index.js.map +0 -1
  302. package/dist/paginator/index.js +0 -3
  303. package/dist/paginator/index.js.map +0 -1
  304. package/dist/pbt/arbitraries/index.d.ts +0 -136
  305. package/dist/pbt/arbitraries/index.js +0 -3
  306. package/dist/pbt/arbitraries/index.js.map +0 -1
  307. package/dist/pbt/runners/index.d.ts +0 -118
  308. package/dist/pbt/runners/index.js +0 -5
  309. package/dist/pbt/runners/index.js.map +0 -1
  310. package/dist/poller/index.d.ts +0 -352
  311. package/dist/poller/index.js +0 -115
  312. package/dist/poller/index.js.map +0 -1
  313. package/dist/prediction/index.d.ts +0 -131
  314. package/dist/prediction/index.js +0 -4
  315. package/dist/prediction/index.js.map +0 -1
  316. package/dist/pure/index.d.ts +0 -3
  317. package/dist/pure/index.js +0 -4
  318. package/dist/pure/index.js.map +0 -1
  319. package/dist/rate-limit/index.d.ts +0 -115
  320. package/dist/rate-limit/index.js +0 -3
  321. package/dist/rate-limit/index.js.map +0 -1
  322. package/dist/reconciler/index.d.ts +0 -193
  323. package/dist/reconciler/index.js +0 -164
  324. package/dist/reconciler/index.js.map +0 -1
  325. package/dist/recorder/index.js +0 -3
  326. package/dist/recorder/index.js.map +0 -1
  327. package/dist/reducer-4GNR6b8B.d.ts +0 -447
  328. package/dist/resilient-call/index.d.ts +0 -320
  329. package/dist/resilient-call/index.js +0 -14
  330. package/dist/resilient-call/index.js.map +0 -1
  331. package/dist/retry-to-success/index.d.ts +0 -109
  332. package/dist/retry-to-success/index.js +0 -37
  333. package/dist/retry-to-success/index.js.map +0 -1
  334. package/dist/run-pAcmBpah.d.ts +0 -713
  335. package/dist/runtime-types-CNLmhWif.d.ts +0 -517
  336. package/dist/saga/index.d.ts +0 -241
  337. package/dist/saga/index.js +0 -150
  338. package/dist/saga/index.js.map +0 -1
  339. package/dist/samples-B3My5oh2.d.ts +0 -59
  340. package/dist/snapshot/index.js +0 -5
  341. package/dist/snapshot/index.js.map +0 -1
  342. package/dist/subs/index.d.ts +0 -472
  343. package/dist/subs/index.js +0 -7
  344. package/dist/subs/index.js.map +0 -1
  345. package/dist/throttle/index.d.ts +0 -134
  346. package/dist/throttle/index.js +0 -3
  347. package/dist/throttle/index.js.map +0 -1
  348. package/dist/throttled-input/index.js.map +0 -1
  349. package/dist/token-refresh/index.d.ts +0 -216
  350. package/dist/token-refresh/index.js +0 -6
  351. package/dist/token-refresh/index.js.map +0 -1
  352. package/dist/trace-replay/index.js +0 -6
  353. package/dist/trace-replay/index.js.map +0 -1
  354. package/dist/with-deadline/index.d.ts +0 -197
  355. package/dist/with-deadline/index.js +0 -111
  356. package/dist/with-deadline/index.js.map +0 -1
  357. package/dist/with-resilience/index.d.ts +0 -225
  358. package/dist/with-resilience/index.js +0 -240
  359. package/dist/with-resilience/index.js.map +0 -1
  360. package/dist/with-telemetry/index.d.ts +0 -150
  361. package/dist/with-telemetry/index.js +0 -70
  362. package/dist/with-telemetry/index.js.map +0 -1
  363. package/dist/work-queue/adapter.d.ts +0 -84
  364. package/dist/work-queue/adapter.js +0 -4
  365. package/dist/work-queue/adapter.js.map +0 -1
  366. package/dist/work-queue/ops.d.ts +0 -71
  367. package/dist/work-queue/ops.js +0 -3
  368. package/dist/work-queue/ops.js.map +0 -1
  369. package/dist/workflow/index.d.ts +0 -485
  370. package/dist/workflow/index.js +0 -244
  371. package/dist/workflow/index.js.map +0 -1
  372. /package/dist/{cache → paginate}/index.js.map +0 -0
  373. /package/dist/{chart/inspect → persistence}/index.js.map +0 -0
@@ -62,5 +62,5 @@ function pendingEffectsLedger(restore) {
62
62
  }
63
63
 
64
64
  export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects };
65
- //# sourceMappingURL=chunk-25LBDCBC.js.map
66
- //# sourceMappingURL=chunk-25LBDCBC.js.map
65
+ //# sourceMappingURL=chunk-6IQPODUF.js.map
66
+ //# sourceMappingURL=chunk-6IQPODUF.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/do/durable-effects.ts"],"names":[],"mappings":"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","file":"chunk-25LBDCBC.js","sourcesContent":["/**\n * @demlik/tea/do — the durable pending-effects ledger (substrate primitive #1).\n *\n * Durable *state* and durable *effects* are different problems. An\n * event-sourced actor rebuilds its STATE by folding the event log\n * (`doEventSourcedStore`, sibling file). But an outbound side effect — a tool\n * round-trip, a message to a sibling grain — is fire-and-forget: if the actor\n * interprets the `Cmd` inside an activation that hibernates mid-flight, the\n * effect is lost, yet nothing in the replayed state records that it is still\n * OWED. This is the one real tax of the event-sourced-virtual-actor target\n * (ADR 0003 primitive #1): \"I owe this effect\" must itself be part of the\n * folded state.\n *\n * Akka's classic `AtLeastOnceDelivery` solves it with a ledger of unconfirmed\n * deliveries kept AS PART OF the persisted state: each `deliver` adds an entry\n * keyed by a monotonic `deliveryId`; each `confirmDelivery` removes it. On\n * recovery the ledger is rebuilt from the SAME events, and any surviving entry\n * is re-sent. At-least-once ⇒ a confirmed-but-not-yet-persisted delivery WILL\n * be re-sent after a crash, so the receiver must deduplicate by id.\n *\n * ## The load-bearing rule (do not violate)\n *\n * The ledger is a PURE FOLD over the same kind of event stream the actor\n * already replays — it is **NOT** a separately-persisted side table:\n *\n * - `effect_owed` — `{ id, effect }` ADDS an entry to the ledger.\n * - `effect_confirmed`— `{ id }` REMOVES the entry.\n *\n * `foldLedger(events)` is `events.reduce(applyEffectEvent, empty())` — the same\n * fold shape `replay` / `foldEvents` / the recorder use. Persist these two\n * events into the SAME log `doEventSourcedStore` already appends (they are just\n * Msg variants), and the ledger is rebuilt for free on the next activation:\n * `foldLedger(log)` after eviction equals `foldLedger(log)` never-evicted, by\n * construction (a pure fold over identical input).\n *\n * On activation (replay completion), `survivingEffects(ledger)` returns the\n * owed-but-unconfirmed entries to re-fire, ordered by their monotonic id. The\n * re-fire is a SIDE EFFECT DERIVED from the surviving ledger — never stored\n * separately, never fired during replay (recovery.md: add to the ledger during\n * recovery; let recovery-END re-emit the survivors).\n *\n * Anti-patterns this file refuses (mirroring durable-effects.md):\n * - A side-table ledger persisted apart from the events. The events ARE the\n * ledger; the Map is rebuilt by folding them.\n * - Re-firing every historical effect during replay. Only `survivingEffects`\n * (post-fold) re-emits.\n * - Assuming the receiver gets each effect exactly once. At-least-once: dedup\n * by `id` at the receiver (`isOwed` here is the sender's view; the receiver\n * owns its own dedup).\n */\n\nimport type { Cmd } from \"../index\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// The two events the ledger folds. These are ordinary Msg variants — persist\n// them into the same event log `doEventSourcedStore` appends, and the ledger\n// rebuilds itself on the next activation with no extra storage.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** Monotonic, gap-free delivery id — the single correlation + dedup key. */\nexport type DeliveryId = number;\n\n/**\n * An effect is now OWED: it has been decided but its delivery is not yet\n * confirmed. Adds `{ id → effect }` to the ledger when folded.\n *\n * Persist this BEFORE interpreting the effect (durable-effects.md rule:\n * \"persist the intent before deliver\"). A crash between persist and deliver is\n * fine — the surviving entry re-fires on activation. A crash before the persist\n * means the effect was never owed, so nothing is lost that the actor promised.\n */\nexport interface EffectOwed<E> extends Cmd<\"effect_owed\"> {\n readonly id: DeliveryId;\n readonly effect: E;\n}\n\n/**\n * An owed effect has been CONFIRMED delivered. Removes its entry from the\n * ledger when folded. Persist this BEFORE acting on the confirmation\n * (\"persist the confirmation before confirmDelivery\").\n */\nexport interface EffectConfirmed extends Cmd<\"effect_confirmed\"> {\n readonly id: DeliveryId;\n}\n\n/** The event union the ledger folds over. `E` is the consumer's effect type. */\nexport type EffectLedgerEvent<E> = EffectOwed<E> | EffectConfirmed;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// The ledger itself — a pure value. Insertion-ordered by monotonic id, so\n// `survivingEffects` re-emits in owed-order without a sort.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * The pending-effects ledger: owed-but-unconfirmed effects keyed by their\n * monotonic delivery id. A pure value reconstructed by `foldLedger` — it is\n * never persisted on its own; the events are.\n *\n * `ReadonlyMap` preserves insertion order, which (because ids are appended\n * monotonically) is exactly id order — so iteration yields the survivors\n * oldest-first with no sort.\n */\nexport type PendingEffectsLedger<E> = ReadonlyMap<DeliveryId, E>;\n\n/** A single surviving entry to re-emit: its id and the effect it owes. */\nexport interface OwedEffect<E> {\n readonly id: DeliveryId;\n readonly effect: E;\n}\n\n/** The empty ledger — the fold's seed (a fresh actor owes nothing). */\nexport function emptyLedger<E>(): PendingEffectsLedger<E> {\n return new Map<DeliveryId, E>();\n}\n\n/**\n * Apply ONE ledger event — the reducer at the heart of the fold.\n *\n * - `effect_owed` → add `{ id → effect }`.\n * - `effect_confirmed` → remove `id` (no-op if already absent: a duplicate\n * confirm, or a confirm for an id evicted with the actor — at-least-once\n * tolerates both).\n *\n * Pure: returns a NEW ledger, never mutates the input — so folding the same\n * events twice (live and post-eviction) yields equal results, and a caller may\n * keep the prior ledger value.\n */\nexport function applyEffectEvent<E>(\n ledger: PendingEffectsLedger<E>,\n event: EffectLedgerEvent<E>,\n): PendingEffectsLedger<E> {\n const next = new Map(ledger);\n switch (event.type) {\n case \"effect_owed\":\n next.set(event.id, event.effect);\n return next;\n case \"effect_confirmed\":\n next.delete(event.id);\n return next;\n }\n}\n\n/**\n * THE FOLD. Rebuild the ledger from an event stream — the same fold shape\n * `replay` uses for state. After a simulated eviction this is called over the\n * persisted log and yields a ledger byte-for-byte equal to the never-evicted\n * one, because a pure fold over identical input is identical.\n *\n * This is the function that proves \"no side table\": the ledger is `events`\n * reduced, nothing more.\n */\nexport function foldLedger<E>(\n events: Iterable<EffectLedgerEvent<E>>,\n): PendingEffectsLedger<E> {\n let ledger = emptyLedger<E>();\n for (const event of events) ledger = applyEffectEvent(ledger, event);\n return ledger;\n}\n\n/**\n * RE-EMIT ON ACTIVATION. Given the rebuilt ledger, the owed-but-unconfirmed\n * effects to re-fire — ordered oldest-first by monotonic id. On a fresh /\n * fully-confirmed actor this is empty (nothing re-emitted).\n *\n * Idempotency is the RECEIVER's job: it must dedup by `id`, because\n * at-least-once means a re-emitted already-handled id WILL arrive again\n * (e.g. an effect confirmed in the activation that hibernated before the\n * `effect_confirmed` event was persisted). Re-firing the same id is therefore\n * a no-op AT THE RECEIVER, not here.\n */\nexport function survivingEffects<E>(\n ledger: PendingEffectsLedger<E>,\n): readonly OwedEffect<E>[] {\n const out: OwedEffect<E>[] = [];\n for (const [id, effect] of ledger) out.push({ id, effect });\n return out;\n}\n\n/** Is this id still owed (unconfirmed) in the ledger? Sender-side view. */\nexport function isOwed<E>(\n ledger: PendingEffectsLedger<E>,\n id: DeliveryId,\n): boolean {\n return ledger.has(id);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// pendingEffectsLedger — the stateful, monotonic-id-issuing recorder.\n//\n// The pure `foldLedger` is the contract; this is the ergonomic driver a host\n// uses live. It owns the monotonic `deliveryId` (gap-free, shared across all\n// destinations — durable-effects.md), emits the `effect_owed` / `effect_confirmed`\n// events for the caller to PERSIST, and keeps an in-memory mirror folded from\n// those same events so `survivingEffects` is available without a re-read.\n//\n// Mirrors `deferredGateway`'s factory shape: no clock / RNG captured; pure\n// bookkeeping. The caller is responsible for persisting each returned event\n// into the log (so the ledger survives eviction) and for actually interpreting\n// the effect after the owed event is durable.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * A live, monotonic-id-issuing ledger recorder.\n *\n * - `owe(effect)` — allocate the next `deliveryId`, return the\n * `effect_owed` event to PERSIST plus the allocated `id`. Folding the event\n * into the recorder's mirror is done for you; the caller persists it.\n * - `confirm(id)` — return the `effect_confirmed` event to PERSIST, and `true`\n * iff the id was owed (a duplicate confirm returns `false` — the boolean is\n * itself a dedup signal, exactly Akka `confirmDelivery`).\n * - `surviving()` — the current owed-but-unconfirmed effects (for re-emit on\n * activation).\n * - `ledger()` — the current folded ledger value.\n * - `lastId()` — the highest id issued (so a host can seed the counter from a\n * rebuilt ledger after eviction; see `restore`).\n */\nexport interface PendingEffectsRecorder<E> {\n owe(effect: E): { id: DeliveryId; event: EffectOwed<E> };\n confirm(id: DeliveryId): { confirmed: boolean; event: EffectConfirmed };\n surviving(): readonly OwedEffect<E>[];\n ledger(): PendingEffectsLedger<E>;\n lastId(): DeliveryId;\n}\n\n/**\n * Build a live recorder. `restore` rehydrates it after an eviction: pass the\n * events read back from the log (or the rebuilt ledger's survivors) so the\n * monotonic counter resumes WITHOUT gaps and the mirror reflects the surviving\n * owed set. Omit `restore` for a fresh actor.\n *\n * Counter seeding rule: the next id is `max(seen ids) + 1`. Restoring only the\n * survivors is sufficient for correctness of re-emit, but to keep ids gap-free\n * across confirmed-and-pruned entries the host should pass `lastId` explicitly\n * when it has it (e.g. persisted alongside the snapshot). When only survivors\n * are known, the counter resumes from the highest surviving id — a confirmed id\n * higher than every survivor could in principle be reissued, so a host that\n * needs strict global monotonicity persists `lastId`.\n */\nexport function pendingEffectsLedger<E>(restore?: {\n readonly events?: Iterable<EffectLedgerEvent<E>>;\n readonly lastId?: DeliveryId;\n}): PendingEffectsRecorder<E> {\n // Materialize the restore events ONCE — `restore.events` is only an\n // `Iterable`, so a single-use generator would be exhausted by `foldLedger`\n // and yield nothing on a second walk (seeding the counter to 0 and reissuing\n // colliding ids). Folding and counter-seeding both read this array.\n const events = restore?.events ? [...restore.events] : undefined;\n let mirror: PendingEffectsLedger<E> = events\n ? foldLedger(events)\n : emptyLedger<E>();\n\n // Seed the monotonic counter. Prefer an explicit `lastId` (gap-free across\n // pruned ids); else the highest id observed in the restore events; else the\n // highest surviving id; else 0 (fresh).\n let counter = restore?.lastId ?? 0;\n if (restore?.lastId === undefined && events) {\n for (const e of events) if (e.id > counter) counter = e.id;\n } else if (restore?.lastId === undefined) {\n for (const id of mirror.keys()) if (id > counter) counter = id;\n }\n\n return {\n owe(effect) {\n counter += 1;\n const id = counter;\n const event: EffectOwed<E> = { type: \"effect_owed\", id, effect };\n mirror = applyEffectEvent(mirror, event);\n return { id, event };\n },\n confirm(id) {\n const confirmed = mirror.has(id);\n const event: EffectConfirmed = { type: \"effect_confirmed\", id };\n mirror = applyEffectEvent(mirror, event);\n return { confirmed, event };\n },\n surviving() {\n return survivingEffects(mirror);\n },\n ledger() {\n return mirror;\n },\n lastId() {\n return counter;\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/do/durable-effects.ts"],"names":[],"mappings":"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","file":"chunk-6IQPODUF.js","sourcesContent":["/**\n * @demlik/tea/do — the durable pending-effects ledger (substrate primitive #1).\n *\n * Durable *state* and durable *effects* are different problems. An\n * event-sourced actor rebuilds its STATE by folding the event log\n * (`doEventSourcedStore`, sibling file). But an outbound side effect — a tool\n * round-trip, a message to a sibling grain — is fire-and-forget: if the actor\n * interprets the `Cmd` inside an activation that hibernates mid-flight, the\n * effect is lost, yet nothing in the replayed state records that it is still\n * OWED. This is the one real tax of the event-sourced-virtual-actor target\n * (ADR 0003 primitive #1): \"I owe this effect\" must itself be part of the\n * folded state.\n *\n * Akka's classic `AtLeastOnceDelivery` solves it with a ledger of unconfirmed\n * deliveries kept AS PART OF the persisted state: each `deliver` adds an entry\n * keyed by a monotonic `deliveryId`; each `confirmDelivery` removes it. On\n * recovery the ledger is rebuilt from the SAME events, and any surviving entry\n * is re-sent. At-least-once ⇒ a confirmed-but-not-yet-persisted delivery WILL\n * be re-sent after a crash, so the receiver must deduplicate by id.\n *\n * ## The load-bearing rule (do not violate)\n *\n * The ledger is a PURE FOLD over the same kind of event stream the actor\n * already replays — it is **NOT** a separately-persisted side table:\n *\n * - `effect_owed` — `{ id, effect }` ADDS an entry to the ledger.\n * - `effect_confirmed`— `{ id }` REMOVES the entry.\n *\n * `foldLedger(events)` is `events.reduce(applyEffectEvent, empty())` — the same\n * fold shape `replay` / `foldEvents` / the recorder use. Persist these two\n * events into the SAME log `doEventSourcedStore` already appends (they are just\n * Msg variants), and the ledger is rebuilt for free on the next activation:\n * `foldLedger(log)` after eviction equals `foldLedger(log)` never-evicted, by\n * construction (a pure fold over identical input).\n *\n * On activation (replay completion), `survivingEffects(ledger)` returns the\n * owed-but-unconfirmed entries to re-fire, ordered by their monotonic id. The\n * re-fire is a SIDE EFFECT DERIVED from the surviving ledger — never stored\n * separately, never fired during replay (recovery.md: add to the ledger during\n * recovery; let recovery-END re-emit the survivors).\n *\n * Anti-patterns this file refuses (mirroring durable-effects.md):\n * - A side-table ledger persisted apart from the events. The events ARE the\n * ledger; the Map is rebuilt by folding them.\n * - Re-firing every historical effect during replay. Only `survivingEffects`\n * (post-fold) re-emits.\n * - Assuming the receiver gets each effect exactly once. At-least-once: dedup\n * by `id` at the receiver (`isOwed` here is the sender's view; the receiver\n * owns its own dedup).\n */\n\nimport type { Cmd } from \"../index\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// The two events the ledger folds. These are ordinary Msg variants — persist\n// them into the same event log `doEventSourcedStore` appends, and the ledger\n// rebuilds itself on the next activation with no extra storage.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** Monotonic, gap-free delivery id — the single correlation + dedup key. */\nexport type DeliveryId = number;\n\n/**\n * An effect is now OWED: it has been decided but its delivery is not yet\n * confirmed. Adds `{ id → effect }` to the ledger when folded.\n *\n * Persist this BEFORE interpreting the effect (durable-effects.md rule:\n * \"persist the intent before deliver\"). A crash between persist and deliver is\n * fine — the surviving entry re-fires on activation. A crash before the persist\n * means the effect was never owed, so nothing is lost that the actor promised.\n */\nexport interface EffectOwed<E> extends Cmd<\"effect_owed\"> {\n readonly id: DeliveryId;\n readonly effect: E;\n}\n\n/**\n * An owed effect has been CONFIRMED delivered. Removes its entry from the\n * ledger when folded. Persist this BEFORE acting on the confirmation\n * (\"persist the confirmation before confirmDelivery\").\n */\nexport interface EffectConfirmed extends Cmd<\"effect_confirmed\"> {\n readonly id: DeliveryId;\n}\n\n/** The event union the ledger folds over. `E` is the consumer's effect type. */\nexport type EffectLedgerEvent<E> = EffectOwed<E> | EffectConfirmed;\n\n// ─────────────────────────────────────────────────────────────────────────────\n// The ledger itself — a pure value. Insertion-ordered by monotonic id, so\n// `survivingEffects` re-emits in owed-order without a sort.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * The pending-effects ledger: owed-but-unconfirmed effects keyed by their\n * monotonic delivery id. A pure value reconstructed by `foldLedger` — it is\n * never persisted on its own; the events are.\n *\n * `ReadonlyMap` preserves insertion order, which (because ids are appended\n * monotonically) is exactly id order — so iteration yields the survivors\n * oldest-first with no sort.\n */\nexport type PendingEffectsLedger<E> = ReadonlyMap<DeliveryId, E>;\n\n/** A single surviving entry to re-emit: its id and the effect it owes. */\nexport interface OwedEffect<E> {\n readonly id: DeliveryId;\n readonly effect: E;\n}\n\n/** The empty ledger — the fold's starting value (a fresh actor owes nothing). */\nexport function emptyLedger<E>(): PendingEffectsLedger<E> {\n return new Map<DeliveryId, E>();\n}\n\n/**\n * Apply ONE ledger event — the reducer at the heart of the fold.\n *\n * - `effect_owed` → add `{ id → effect }`.\n * - `effect_confirmed` → remove `id` (no-op if already absent: a duplicate\n * confirm, or a confirm for an id evicted with the actor — at-least-once\n * tolerates both).\n *\n * Pure: returns a NEW ledger, never mutates the input — so folding the same\n * events twice (live and post-eviction) yields equal results, and a caller may\n * keep the prior ledger value.\n */\nexport function applyEffectEvent<E>(\n ledger: PendingEffectsLedger<E>,\n event: EffectLedgerEvent<E>,\n): PendingEffectsLedger<E> {\n const next = new Map(ledger);\n switch (event.type) {\n case \"effect_owed\":\n next.set(event.id, event.effect);\n return next;\n case \"effect_confirmed\":\n next.delete(event.id);\n return next;\n }\n}\n\n/**\n * THE FOLD. Rebuild the ledger from an event stream — the same fold shape\n * `replay` uses for state. After a simulated eviction this is called over the\n * persisted log and yields a ledger byte-for-byte equal to the never-evicted\n * one, because a pure fold over identical input is identical.\n *\n * This is the function that proves \"no side table\": the ledger is `events`\n * reduced, nothing more.\n */\nexport function foldLedger<E>(\n events: Iterable<EffectLedgerEvent<E>>,\n): PendingEffectsLedger<E> {\n let ledger = emptyLedger<E>();\n for (const event of events) ledger = applyEffectEvent(ledger, event);\n return ledger;\n}\n\n/**\n * RE-EMIT ON ACTIVATION. Given the rebuilt ledger, the owed-but-unconfirmed\n * effects to re-fire — ordered oldest-first by monotonic id. On a fresh /\n * fully-confirmed actor this is empty (nothing re-emitted).\n *\n * Idempotency is the RECEIVER's job: it must dedup by `id`, because\n * at-least-once means a re-emitted already-handled id WILL arrive again\n * (e.g. an effect confirmed in the activation that hibernated before the\n * `effect_confirmed` event was persisted). Re-firing the same id is therefore\n * a no-op AT THE RECEIVER, not here.\n */\nexport function survivingEffects<E>(\n ledger: PendingEffectsLedger<E>,\n): readonly OwedEffect<E>[] {\n const out: OwedEffect<E>[] = [];\n for (const [id, effect] of ledger) out.push({ id, effect });\n return out;\n}\n\n/** Is this id still owed (unconfirmed) in the ledger? Sender-side view. */\nexport function isOwed<E>(\n ledger: PendingEffectsLedger<E>,\n id: DeliveryId,\n): boolean {\n return ledger.has(id);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// pendingEffectsLedger — the stateful, monotonic-id-issuing recorder.\n//\n// The pure `foldLedger` is the contract; this is the ergonomic driver a host\n// uses live. It owns the monotonic `deliveryId` (gap-free, shared across all\n// destinations — durable-effects.md), emits the `effect_owed` / `effect_confirmed`\n// events for the caller to PERSIST, and keeps an in-memory mirror folded from\n// those same events so `survivingEffects` is available without a re-read.\n//\n// Mirrors `deferredGateway`'s factory shape: no clock / RNG captured; pure\n// bookkeeping. The caller is responsible for persisting each returned event\n// into the log (so the ledger survives eviction) and for actually interpreting\n// the effect after the owed event is durable.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * A live, monotonic-id-issuing ledger recorder.\n *\n * - `owe(effect)` — allocate the next `deliveryId`, return the\n * `effect_owed` event to PERSIST plus the allocated `id`. Folding the event\n * into the recorder's mirror is done for you; the caller persists it.\n * - `confirm(id)` — return the `effect_confirmed` event to PERSIST, and `true`\n * iff the id was owed (a duplicate confirm returns `false` — the boolean is\n * itself a dedup signal, exactly Akka `confirmDelivery`).\n * - `surviving()` — the current owed-but-unconfirmed effects (for re-emit on\n * activation).\n * - `ledger()` — the current folded ledger value.\n * - `lastId()` — the highest id issued (so a host can seed the counter from a\n * rebuilt ledger after eviction; see `restore`).\n */\nexport interface PendingEffectsRecorder<E> {\n owe(effect: E): { id: DeliveryId; event: EffectOwed<E> };\n confirm(id: DeliveryId): { confirmed: boolean; event: EffectConfirmed };\n surviving(): readonly OwedEffect<E>[];\n ledger(): PendingEffectsLedger<E>;\n lastId(): DeliveryId;\n}\n\n/**\n * Build a live recorder. `restore` rehydrates it after an eviction: pass the\n * events read back from the log (or the rebuilt ledger's survivors) so the\n * monotonic counter resumes WITHOUT gaps and the mirror reflects the surviving\n * owed set. Omit `restore` for a fresh actor.\n *\n * Counter seeding rule: the next id is `max(seen ids) + 1`. Restoring only the\n * survivors is sufficient for correctness of re-emit, but to keep ids gap-free\n * across confirmed-and-pruned entries the host should pass `lastId` explicitly\n * when it has it (e.g. persisted alongside the snapshot). When only survivors\n * are known, the counter resumes from the highest surviving id — a confirmed id\n * higher than every survivor could in principle be reissued, so a host that\n * needs strict global monotonicity persists `lastId`.\n */\nexport function pendingEffectsLedger<E>(restore?: {\n readonly events?: Iterable<EffectLedgerEvent<E>>;\n readonly lastId?: DeliveryId;\n}): PendingEffectsRecorder<E> {\n // Materialize the restore events ONCE — `restore.events` is only an\n // `Iterable`, so a single-use generator would be exhausted by `foldLedger`\n // and yield nothing on a second walk (seeding the counter to 0 and reissuing\n // colliding ids). Folding and counter-seeding both read this array.\n const events = restore?.events ? [...restore.events] : undefined;\n let mirror: PendingEffectsLedger<E> = events\n ? foldLedger(events)\n : emptyLedger<E>();\n\n // Seed the monotonic counter. Prefer an explicit `lastId` (gap-free across\n // pruned ids); else the highest id observed in the restore events; else the\n // highest surviving id; else 0 (fresh).\n let counter = restore?.lastId ?? 0;\n if (restore?.lastId === undefined && events) {\n for (const e of events) if (e.id > counter) counter = e.id;\n } else if (restore?.lastId === undefined) {\n for (const id of mirror.keys()) if (id > counter) counter = id;\n }\n\n return {\n owe(effect) {\n counter += 1;\n const id = counter;\n const event: EffectOwed<E> = { type: \"effect_owed\", id, effect };\n mirror = applyEffectEvent(mirror, event);\n return { id, event };\n },\n confirm(id) {\n const confirmed = mirror.has(id);\n const event: EffectConfirmed = { type: \"effect_confirmed\", id };\n mirror = applyEffectEvent(mirror, event);\n return { confirmed, event };\n },\n surviving() {\n return survivingEffects(mirror);\n },\n ledger() {\n return mirror;\n },\n lastId() {\n return counter;\n },\n };\n}\n"]}
@@ -0,0 +1,505 @@
1
+ import { asRng, recordFailure, shouldRetry, nextDelayMs, initRetry } from './chunk-VBDU4JL6.js';
2
+ import { deadlineMsgType, subscribeDeadline, initCache, set, deadlineSub, get } from './chunk-22POWGFA.js';
3
+ import { Cmd, liftSlice, without, tryInterpret } from './chunk-66PY5WYF.js';
4
+ import { z } from 'zod';
5
+
6
+ // src/protocol.ts
7
+ var MsgType = {
8
+ // --- resilient-call: the run Cmd + its two settle Msgs -------------------
9
+ /** The "run the port for `key`" effect Cmd resilient-call emits. */
10
+ ResilientRun: "resilient_run",
11
+ /** PRIVATE success settle Msg (read only by `agentEvents`, #47). */
12
+ ResilientOk: "resilient_ok",
13
+ /** Failure settle Msg — routed to the `fail` verb (back off via retry). */
14
+ ResilientErr: "resilient_err",
15
+ // --- agent: the wired machine's own entry-point Msgs ---------------------
16
+ /** Begin a run. */
17
+ AgentStart: "agent_start",
18
+ /** PRIVATE tool-fan-out success settle Msg (read only by `agentEvents`, #47). */
19
+ AgentToolOk: "agent_tool_ok",
20
+ /** Tool-fan-out failure settle Msg. */
21
+ AgentToolErr: "agent_tool_err",
22
+ /**
23
+ * Re-fire the one outstanding effect on rehydrate (the do↔agent seam). Fired
24
+ * by `do/host`'s `autoBoot` via the typed `agentBootMsg` constructor, matched
25
+ * by the agent reducer — see `AgentBootPort` in `../agent`.
26
+ */
27
+ AgentBoot: "agent_boot",
28
+ /**
29
+ * Stop the run from outside and settle it `cancelled` — what an `AbortSignal`
30
+ * handed to `driveToDone` / a defined agent's `run` dispatches on abort. A
31
+ * transition, never a throw: the outcome lands in the Model, so a reload reads
32
+ * a run that ended rather than one to resume.
33
+ */
34
+ AgentCancel: "agent_cancel",
35
+ // --- agent: the context-compaction round-trip (#85) ----------------------
36
+ /**
37
+ * The "summarize the oldest N turns" effect Cmd the agent emits when its
38
+ * `CompactionPolicy` asks to compact before a brain call. A DEDICATED
39
+ * round-trip (design B1), distinct from the brain call's `resilient_run`, so
40
+ * compaction is its own honest `Awaiting` state — see `../agent`.
41
+ */
42
+ CompactRun: "compact_run",
43
+ /** Compaction round-trip resolved — carries the summary text the fold-back folds. */
44
+ CompactOk: "compact_ok",
45
+ /** Compaction round-trip failed (exhausted retry) — surfaced as data, not a stall. */
46
+ CompactErr: "compact_err",
47
+ // --- token-refresh: the two refresh-result Msgs --------------------------
48
+ /** Refresh port resolved — carries the fresh `Token`. */
49
+ TokenRefreshed: "token_refreshed",
50
+ /** Refresh port rejected — carries the rejection (errors are data). */
51
+ TokenRefreshFailed: "token_refresh_failed",
52
+ // --- authed-call: the 401 trigger ----------------------------------------
53
+ /** The 401 the consumer dispatches when a guarded call comes back unauthorized. */
54
+ Unauthorized: "unauthorized"
55
+ };
56
+
57
+ // src/internal/resilience/circuit-breaker/index.ts
58
+ var defaultCircuitPolicy = {
59
+ failureThreshold: 5,
60
+ cooldownMs: 3e4,
61
+ halfOpenMaxProbes: 1
62
+ };
63
+ function initCircuit() {
64
+ return { phase: "closed", failures: 0 };
65
+ }
66
+ function onSuccess(state, _policy) {
67
+ switch (state.phase) {
68
+ case "closed":
69
+ return state.failures === 0 ? state : { phase: "closed", failures: 0 };
70
+ case "half_open":
71
+ return { phase: "closed", failures: 0 };
72
+ case "open":
73
+ return state;
74
+ }
75
+ }
76
+ function onFailure(state, policy, nowMs) {
77
+ switch (state.phase) {
78
+ case "closed": {
79
+ const failures = state.failures + 1;
80
+ return failures >= policy.failureThreshold ? { phase: "open", openedAtMs: nowMs } : { phase: "closed", failures };
81
+ }
82
+ case "half_open":
83
+ return { phase: "open", openedAtMs: nowMs };
84
+ case "open":
85
+ return state;
86
+ }
87
+ }
88
+ function canPass(state, policy, nowMs) {
89
+ switch (state.phase) {
90
+ case "closed":
91
+ return [state, true];
92
+ case "open": {
93
+ const elapsed = nowMs - state.openedAtMs;
94
+ if (elapsed >= policy.cooldownMs) {
95
+ return [{ phase: "half_open", probes: 1 }, true];
96
+ }
97
+ return [state, false];
98
+ }
99
+ case "half_open":
100
+ if (state.probes < policy.halfOpenMaxProbes) {
101
+ return [{ phase: "half_open", probes: state.probes + 1 }, true];
102
+ }
103
+ return [state, false];
104
+ }
105
+ }
106
+
107
+ // src/internal/resilience/rate-limit/index.ts
108
+ function initBucket(capacity, refillPerSec, nowMs) {
109
+ return {
110
+ tokens: capacity,
111
+ capacity,
112
+ refillPerSec,
113
+ lastRefillMs: nowMs
114
+ };
115
+ }
116
+ function refill(bucket, nowMs) {
117
+ const elapsedSec = Math.max(0, nowMs - bucket.lastRefillMs) / 1e3;
118
+ const replenished = bucket.tokens + elapsedSec * bucket.refillPerSec;
119
+ return {
120
+ ...bucket,
121
+ tokens: Math.min(bucket.capacity, replenished),
122
+ lastRefillMs: nowMs
123
+ };
124
+ }
125
+ function tryConsume(bucket, nowMs, n = 1) {
126
+ const refilled = refill(bucket, nowMs);
127
+ if (refilled.tokens >= n) {
128
+ return [{ ...refilled, tokens: refilled.tokens - n }, true];
129
+ }
130
+ return [refilled, false];
131
+ }
132
+ function initWindow(windowMs, limit) {
133
+ return { hits: [], windowMs, limit };
134
+ }
135
+ function prune(window, nowMs) {
136
+ const cutoff = nowMs - window.windowMs;
137
+ return window.hits.filter((t) => t > cutoff);
138
+ }
139
+ function record(window, nowMs) {
140
+ const pruned = prune(window, nowMs);
141
+ if (pruned.length < window.limit) {
142
+ return [{ ...window, hits: [...pruned, nowMs] }, true];
143
+ }
144
+ return [{ ...window, hits: pruned }, false];
145
+ }
146
+ function remaining(window, nowMs) {
147
+ const live = prune(window, nowMs).length;
148
+ return Math.max(0, window.limit - live);
149
+ }
150
+ var DEFAULT_RESILIENT_NAME = "resilient";
151
+ function runCmdDef(name = DEFAULT_RESILIENT_NAME) {
152
+ return Cmd.define(`${name}_run`, {
153
+ input: z.custom(),
154
+ ok: z.custom(),
155
+ err: ["port_rejected", "deadline_exceeded"]
156
+ });
157
+ }
158
+ function circuitPolicy(config) {
159
+ if (config.circuit === void 0) return null;
160
+ return {
161
+ failureThreshold: config.circuit.threshold,
162
+ cooldownMs: config.circuit.cooldownMs,
163
+ halfOpenMaxProbes: config.circuit.halfOpenMaxProbes ?? 1
164
+ };
165
+ }
166
+ function charge(budget, at) {
167
+ if (budget.remainingMs <= 0) return { ...budget, chargingSinceMs: at };
168
+ const elapsed = Math.max(0, at - budget.chargingSinceMs);
169
+ return { remainingMs: budget.remainingMs - elapsed, chargingSinceMs: at };
170
+ }
171
+ function retryTimerId(name, key) {
172
+ return `${name}:retry:${key}`;
173
+ }
174
+ function deadlineTimerId(name, key) {
175
+ return `${name}:deadline:${key}`;
176
+ }
177
+ function deadlineNameOf(name) {
178
+ return name === DEFAULT_RESILIENT_NAME ? void 0 : name;
179
+ }
180
+ function createResilientCall(config, rng = Math.random) {
181
+ const name = config.name ?? DEFAULT_RESILIENT_NAME;
182
+ const cPolicy = circuitPolicy(config);
183
+ const rngBranded = asRng(rng);
184
+ const runCmd = runCmdDef(name);
185
+ const okType = `${name}_ok`;
186
+ const errType = `${name}_err`;
187
+ const deadlineName = deadlineNameOf(name);
188
+ function init() {
189
+ return {
190
+ circuit: initCircuit(),
191
+ // The bucket carries a default value even without the rateLimit brick so
192
+ // the slice shape is uniform, but the rate-limit GATE is skipped entirely
193
+ // when the brick is absent (see `gate`) — the bucket is simply never
194
+ // consulted. A `0/0` placeholder bucket would be touched by `tryConsume`;
195
+ // a `1-cap` default is harmless because the gate never calls it.
196
+ bucket: config.rateLimit ? initBucket(
197
+ config.rateLimit.capacity,
198
+ config.rateLimit.refillPerSec,
199
+ 0
200
+ ) : initBucket(1, 1, 0),
201
+ retry: {},
202
+ cache: initCache(),
203
+ calls: {}
204
+ };
205
+ }
206
+ function retryOf(s, key) {
207
+ return s.retry[key] ?? initRetry();
208
+ }
209
+ function freshBudget(at) {
210
+ return {
211
+ remainingMs: config.deadline ? config.deadline.ms : 0,
212
+ chargingSinceMs: at
213
+ };
214
+ }
215
+ function budgetFor(s, key, at) {
216
+ const call = s.calls[key];
217
+ if (call?.phase === "running" || call?.phase === "waiting_retry") {
218
+ return charge(call.budget, at);
219
+ }
220
+ return freshBudget(at);
221
+ }
222
+ function gate(s, key, input, at, budget) {
223
+ if (config.deadline !== void 0 && budget.remainingMs <= 0) {
224
+ return [
225
+ setCall(s, key, {
226
+ phase: "failed",
227
+ error: {
228
+ _tag: "deadline_exceeded",
229
+ id: deadlineTimerId(name, key),
230
+ atMs: at
231
+ }
232
+ }),
233
+ []
234
+ ];
235
+ }
236
+ if (config.cache !== void 0) {
237
+ const cached = get(s.cache, key, at);
238
+ if (cached !== void 0) {
239
+ return [setCall(s, key, { phase: "succeeded", result: cached }), []];
240
+ }
241
+ }
242
+ let bucket = s.bucket;
243
+ if (config.rateLimit !== void 0) {
244
+ const [next, hasToken] = tryConsume(bucket, at);
245
+ bucket = next;
246
+ if (!hasToken) {
247
+ return backoff(
248
+ { ...s, bucket },
249
+ key,
250
+ input,
251
+ "rate_limited",
252
+ at,
253
+ budget
254
+ );
255
+ }
256
+ }
257
+ let circuit = s.circuit;
258
+ if (cPolicy !== null) {
259
+ const [next, ok] = canPass(circuit, cPolicy, at);
260
+ circuit = next;
261
+ if (!ok) {
262
+ return [
263
+ { ...setCall(s, key, { phase: "circuit_open" }), bucket, circuit },
264
+ []
265
+ ];
266
+ }
267
+ }
268
+ return [
269
+ {
270
+ ...setCall(s, key, { phase: "running", input, budget }),
271
+ circuit,
272
+ bucket
273
+ },
274
+ [runCmd({ key, input })]
275
+ ];
276
+ }
277
+ function backoff(s, key, input, error, at, budget) {
278
+ if (config.retry === void 0) {
279
+ return [setCall(s, key, { phase: "failed", error }), []];
280
+ }
281
+ const retry = recordFailure(retryOf(s, key), error, at);
282
+ const withRetry = { ...s, retry: { ...s.retry, [key]: retry } };
283
+ if (!shouldRetry(retry, config.retry, at)) {
284
+ return [setCall(withRetry, key, { phase: "failed", error }), []];
285
+ }
286
+ const retryAtMs = at + nextDelayMs(retry, config.retry, rngBranded);
287
+ return [
288
+ setCall(withRetry, key, {
289
+ phase: "waiting_retry",
290
+ input,
291
+ retryAtMs,
292
+ budget
293
+ }),
294
+ []
295
+ ];
296
+ }
297
+ function setCall(s, key, phase) {
298
+ return { ...s, calls: { ...s.calls, [key]: phase } };
299
+ }
300
+ function attempt(s, key, input, at) {
301
+ return gate(s, key, input, at, budgetFor(s, key, at));
302
+ }
303
+ function resume(s, at) {
304
+ const calls = { ...s.calls };
305
+ for (const [key, call] of Object.entries(calls)) {
306
+ if (call.phase !== "running" && call.phase !== "waiting_retry") continue;
307
+ calls[key] = {
308
+ ...call,
309
+ budget: { ...call.budget, chargingSinceMs: at }
310
+ };
311
+ }
312
+ return { ...s, calls };
313
+ }
314
+ function succeed(s, key, msg) {
315
+ const circuit = cPolicy !== null ? onSuccess(s.circuit) : s.circuit;
316
+ const cache = config.cache !== void 0 ? set(s.cache, key, msg.result, msg.at, config.cache.ttlMs) : s.cache;
317
+ const retry = without(s.retry, key);
318
+ return [
319
+ {
320
+ ...setCall(s, key, { phase: "succeeded", result: msg.result }),
321
+ circuit,
322
+ cache,
323
+ retry
324
+ },
325
+ []
326
+ ];
327
+ }
328
+ function fail(s, key, msg) {
329
+ const circuit = cPolicy !== null ? onFailure(s.circuit, cPolicy, msg.at) : s.circuit;
330
+ const withCircuit = { ...s, circuit };
331
+ const call = s.calls[key];
332
+ const input = call?.phase === "running" ? call.input : void 0;
333
+ const budget = budgetFor(s, key, msg.at);
334
+ if (input === void 0) {
335
+ return [
336
+ setCall(withCircuit, key, { phase: "failed", error: msg.error }),
337
+ []
338
+ ];
339
+ }
340
+ return backoff(withCircuit, key, input, msg.error, msg.at, budget);
341
+ }
342
+ function settleFailed(s, key, error) {
343
+ return [setCall(s, key, { phase: "failed", error }), []];
344
+ }
345
+ function onTimer(s, msg) {
346
+ for (const [key, call] of Object.entries(s.calls)) {
347
+ if (msg.id === retryTimerId(name, key)) {
348
+ if (call.phase !== "waiting_retry") return [s, []];
349
+ return gate(
350
+ s,
351
+ key,
352
+ call.input,
353
+ msg.atMs,
354
+ charge(call.budget, msg.atMs)
355
+ );
356
+ }
357
+ if (msg.id === deadlineTimerId(name, key)) {
358
+ if (call.phase !== "running" && call.phase !== "waiting_retry")
359
+ return [s, []];
360
+ return [
361
+ setCall(s, key, {
362
+ phase: "failed",
363
+ error: {
364
+ _tag: "deadline_exceeded",
365
+ id: msg.id,
366
+ atMs: msg.atMs
367
+ }
368
+ }),
369
+ []
370
+ ];
371
+ }
372
+ }
373
+ return [s, []];
374
+ }
375
+ function subs(s) {
376
+ const out = [];
377
+ for (const [key, call] of Object.entries(s.calls)) {
378
+ if (call.phase === "waiting_retry") {
379
+ out.push(
380
+ deadlineSub(retryTimerId(name, key), call.retryAtMs, {
381
+ name: deadlineName
382
+ })
383
+ );
384
+ }
385
+ if (config.deadline !== void 0 && (call.phase === "running" || call.phase === "waiting_retry") && call.budget.remainingMs > 0) {
386
+ out.push(
387
+ deadlineSub(
388
+ deadlineTimerId(name, key),
389
+ call.budget.chargingSinceMs + call.budget.remainingMs,
390
+ { name: deadlineName }
391
+ )
392
+ );
393
+ }
394
+ }
395
+ return out;
396
+ }
397
+ function handlers(ports) {
398
+ const handle = tryInterpret(
399
+ (cmd) => ports.run(cmd.input, cmd.key),
400
+ (result, cmd) => ({
401
+ type: okType,
402
+ key: cmd.key,
403
+ result,
404
+ at: Date.now()
405
+ }),
406
+ (error, cmd) => ({
407
+ type: errType,
408
+ key: cmd.key,
409
+ error,
410
+ at: Date.now()
411
+ })
412
+ );
413
+ return { [runCmd.cmdType]: handle };
414
+ }
415
+ return {
416
+ // The Msg-name family this knob speaks, as a VALUE typed at `N`. `mount`
417
+ // keys its settle cells off this rather than off the `resilient_*`
418
+ // literals, so a named knob mounts into its own cells (#229) and the Cmd,
419
+ // the Msgs, the Sub ids and the mounted cells all derive from one name.
420
+ name,
421
+ init,
422
+ attempt,
423
+ resume,
424
+ succeed,
425
+ fail,
426
+ settleFailed,
427
+ onTimer,
428
+ subs,
429
+ handlers
430
+ };
431
+ }
432
+ function liftResilience(state, result) {
433
+ return liftSlice("resilience", state, result);
434
+ }
435
+ function mountResilientCall(knob, config) {
436
+ const { slice, attempt, onOk, onErr, onDeadline } = config;
437
+ function put(model, next) {
438
+ return {
439
+ ...model,
440
+ ...{ [slice]: next }
441
+ };
442
+ }
443
+ function settle(verb, fold) {
444
+ return (model, msg) => {
445
+ const [next, cmds] = verb(model[slice], msg.key, msg);
446
+ const settled = put(model, next);
447
+ if (fold === void 0) return [settled, cmds];
448
+ const [folded, extra] = fold(settled, msg);
449
+ return [folded, [...cmds, ...extra]];
450
+ };
451
+ }
452
+ const update = {
453
+ [attempt.on]: (model, msg) => {
454
+ const [next, cmds] = attempt.run(model[slice], msg);
455
+ return [put(model, next), cmds];
456
+ },
457
+ // Keyed off the knob's own name, not the `resilient_*` literals: a knob
458
+ // built with `name: "jev"` emits `jev_ok` / `jev_err`, and a mount that
459
+ // spelled the literals would spread cells nothing ever dispatches to.
460
+ [`${knob.name}_ok`]: settle(
461
+ (s, key, msg) => knob.succeed(s, key, msg),
462
+ onOk
463
+ ),
464
+ [`${knob.name}_err`]: settle(
465
+ (s, key, msg) => knob.fail(s, key, msg),
466
+ onErr
467
+ ),
468
+ // The one settle path that carries no settle Msg: `onTimer` writes
469
+ // `failed` straight into the slice, so a mounted `onErr` never sees it. The
470
+ // cell reads the transition off the two slices instead of inventing a Msg —
471
+ // whichever key moved INTO `failed` is the call that just died.
472
+ //
473
+ // Keyed off the knob's name for the same reason the two settle cells are
474
+ // (#238): the knob's deadline Sub dispatches `<name>_deadline`, so a cell
475
+ // spelling the bare literal would be one two named knobs both claim — and
476
+ // the second spread into `defineMachine` would silently win.
477
+ [deadlineMsgType(deadlineNameOf(knob.name))]: (model, msg) => {
478
+ const before = model[slice];
479
+ const [next, cmds] = knob.onTimer(before, msg);
480
+ const advanced = put(model, next);
481
+ if (onDeadline === void 0) return [advanced, cmds];
482
+ let folded = advanced;
483
+ const extra = [];
484
+ for (const [key, call] of Object.entries(next.calls)) {
485
+ if (call.phase !== "failed") continue;
486
+ if (before.calls[key]?.phase === "failed") continue;
487
+ const [m, c] = onDeadline(folded, { key, error: call.error, msg });
488
+ folded = m;
489
+ extra.push(...c);
490
+ }
491
+ return [folded, [...cmds, ...extra]];
492
+ }
493
+ };
494
+ return {
495
+ init: () => ({ [slice]: knob.init() }),
496
+ update,
497
+ subscriptions: (model) => knob.subs(model[slice]),
498
+ subscribe: { deadline: subscribeDeadline },
499
+ interpret: knob.handlers()
500
+ };
501
+ }
502
+
503
+ export { DEFAULT_RESILIENT_NAME, MsgType, canPass, createResilientCall, defaultCircuitPolicy, initBucket, initCircuit, initWindow, liftResilience, mountResilientCall, onFailure, onSuccess, record, refill, remaining, runCmdDef, tryConsume };
504
+ //# sourceMappingURL=chunk-AYS5N6WY.js.map
505
+ //# sourceMappingURL=chunk-AYS5N6WY.js.map