@graphrefly/ts 0.0.0 → 0.0.2

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 (405) hide show
  1. package/README.md +135 -0
  2. package/dist/actions-types-CSC3NMDl.d.ts +657 -0
  3. package/dist/actions-types-wl9Mgkmr.d.cts +657 -0
  4. package/dist/adapters/index.cjs +5219 -2974
  5. package/dist/adapters/index.cjs.map +1 -1
  6. package/dist/adapters/index.d.cts +204 -192
  7. package/dist/adapters/index.d.ts +204 -192
  8. package/dist/adapters/index.js +3685 -1833
  9. package/dist/adapters/index.js.map +1 -1
  10. package/dist/adapters/nestjs/microservices.cjs +841 -0
  11. package/dist/adapters/nestjs/microservices.cjs.map +1 -0
  12. package/dist/adapters/nestjs/microservices.d.cts +45 -0
  13. package/dist/adapters/nestjs/microservices.d.ts +45 -0
  14. package/dist/adapters/nestjs/microservices.js +206 -0
  15. package/dist/adapters/nestjs/microservices.js.map +1 -0
  16. package/dist/adapters/nestjs/native.cjs +1391 -0
  17. package/dist/adapters/nestjs/native.cjs.map +1 -0
  18. package/dist/adapters/nestjs/native.d.cts +111 -0
  19. package/dist/adapters/nestjs/native.d.ts +111 -0
  20. package/dist/adapters/nestjs/native.js +577 -0
  21. package/dist/adapters/nestjs/native.js.map +1 -0
  22. package/dist/adapters/nestjs/websockets.cjs +924 -0
  23. package/dist/adapters/nestjs/websockets.cjs.map +1 -0
  24. package/dist/adapters/nestjs/websockets.d.cts +47 -0
  25. package/dist/adapters/nestjs/websockets.d.ts +47 -0
  26. package/dist/adapters/nestjs/websockets.js +286 -0
  27. package/dist/adapters/nestjs/websockets.js.map +1 -0
  28. package/dist/adapters/nestjs.cjs +1085 -0
  29. package/dist/adapters/nestjs.cjs.map +1 -0
  30. package/dist/adapters/nestjs.d.cts +385 -0
  31. package/dist/adapters/nestjs.d.ts +385 -0
  32. package/dist/adapters/nestjs.js +112 -0
  33. package/dist/adapters/nestjs.js.map +1 -0
  34. package/dist/adapters/observe-storage.d.cts +4 -4
  35. package/dist/adapters/observe-storage.d.ts +4 -4
  36. package/dist/adapters/observe-storage.js +5 -4
  37. package/dist/adapters/observe-storage.js.map +1 -1
  38. package/dist/adapters/react.cjs +166 -0
  39. package/dist/adapters/react.cjs.map +1 -0
  40. package/dist/adapters/react.d.cts +31 -0
  41. package/dist/adapters/react.d.ts +31 -0
  42. package/dist/adapters/react.js +51 -0
  43. package/dist/adapters/react.js.map +1 -0
  44. package/dist/adapters/solid.cjs +157 -0
  45. package/dist/adapters/solid.cjs.map +1 -0
  46. package/dist/adapters/solid.d.cts +26 -0
  47. package/dist/adapters/solid.d.ts +26 -0
  48. package/dist/adapters/solid.js +48 -0
  49. package/dist/adapters/solid.js.map +1 -0
  50. package/dist/adapters/svelte.cjs +148 -0
  51. package/dist/adapters/svelte.cjs.map +1 -0
  52. package/dist/adapters/svelte.d.cts +31 -0
  53. package/dist/adapters/svelte.d.ts +31 -0
  54. package/dist/adapters/svelte.js +46 -0
  55. package/dist/adapters/svelte.js.map +1 -0
  56. package/dist/adapters/vue.cjs +155 -0
  57. package/dist/adapters/vue.cjs.map +1 -0
  58. package/dist/adapters/vue.d.cts +26 -0
  59. package/dist/adapters/vue.d.ts +26 -0
  60. package/dist/adapters/vue.js +46 -0
  61. package/dist/adapters/vue.js.map +1 -0
  62. package/dist/agent-runtime-types-core-CaXfKNtY.d.cts +406 -0
  63. package/dist/agent-runtime-types-core-hU299uIC.d.ts +406 -0
  64. package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
  65. package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
  66. package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
  67. package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
  68. package/dist/agentic-memory-types-CVSUS6XR.d.ts +473 -0
  69. package/dist/agentic-memory-types-FnnYlVUs.d.cts +473 -0
  70. package/dist/capability-admission-BW2CziT6.d.ts +102 -0
  71. package/dist/capability-admission-lwSecxXs.d.cts +102 -0
  72. package/dist/chunk-2KUAG2GZ.js +9693 -0
  73. package/dist/chunk-2KUAG2GZ.js.map +1 -0
  74. package/dist/chunk-2NJP6GO4.js +1320 -0
  75. package/dist/chunk-2NJP6GO4.js.map +1 -0
  76. package/dist/{chunk-GDL26N2T.js → chunk-3KN7NJDR.js} +2 -2
  77. package/dist/{chunk-COHO25CZ.js → chunk-4NWSNI4K.js} +2232 -1672
  78. package/dist/chunk-4NWSNI4K.js.map +1 -0
  79. package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
  80. package/dist/chunk-6E76H4OU.js +132 -0
  81. package/dist/chunk-6E76H4OU.js.map +1 -0
  82. package/dist/chunk-7GOTIIQ7.js +819 -0
  83. package/dist/chunk-7GOTIIQ7.js.map +1 -0
  84. package/dist/{chunk-D6BG7U6A.js → chunk-7HZRJMN6.js} +3 -3
  85. package/dist/{chunk-SCRFRCGR.js → chunk-BSQGE5PS.js} +1 -1
  86. package/dist/{chunk-PKVBHGBM.js → chunk-CJIFGJQG.js} +7 -7
  87. package/dist/{chunk-G4M3NHRJ.js → chunk-CX6B6PO2.js} +93 -10
  88. package/dist/chunk-CX6B6PO2.js.map +1 -0
  89. package/dist/chunk-DGUM43GV.js +11 -0
  90. package/dist/chunk-DGUM43GV.js.map +1 -0
  91. package/dist/{chunk-JIMUDQN3.js → chunk-E4QCH32M.js} +449 -447
  92. package/dist/chunk-E4QCH32M.js.map +1 -0
  93. package/dist/{chunk-RIIOUTGM.js → chunk-ECURQ3HD.js} +19 -129
  94. package/dist/chunk-ECURQ3HD.js.map +1 -0
  95. package/dist/{chunk-2ILL7HQI.js → chunk-EOKT4QFF.js} +134 -128
  96. package/dist/chunk-EOKT4QFF.js.map +1 -0
  97. package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
  98. package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
  99. package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
  100. package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
  101. package/dist/chunk-K7FB3JTD.js.map +1 -0
  102. package/dist/chunk-L6LDXRWE.js +219 -0
  103. package/dist/chunk-L6LDXRWE.js.map +1 -0
  104. package/dist/chunk-M7J6Z4IJ.js +1930 -0
  105. package/dist/chunk-M7J6Z4IJ.js.map +1 -0
  106. package/dist/chunk-MQEQMS7B.js +1009 -0
  107. package/dist/chunk-MQEQMS7B.js.map +1 -0
  108. package/dist/chunk-MTELVIYR.js +1421 -0
  109. package/dist/chunk-MTELVIYR.js.map +1 -0
  110. package/dist/chunk-PVC7WDKI.js +885 -0
  111. package/dist/chunk-PVC7WDKI.js.map +1 -0
  112. package/dist/chunk-RAHNUYA5.js +368 -0
  113. package/dist/chunk-RAHNUYA5.js.map +1 -0
  114. package/dist/{chunk-DK554R7P.js → chunk-S6HXABGL.js} +2 -1
  115. package/dist/chunk-S6HXABGL.js.map +1 -0
  116. package/dist/{chunk-I3IHOHCJ.js → chunk-SHZDP2MQ.js} +1181 -1001
  117. package/dist/chunk-SHZDP2MQ.js.map +1 -0
  118. package/dist/{chunk-Y3ZLRGHC.js → chunk-SIDJO2T4.js} +16 -16
  119. package/dist/chunk-STXRMPW4.js +4131 -0
  120. package/dist/chunk-STXRMPW4.js.map +1 -0
  121. package/dist/{chunk-JR4IKCR2.js → chunk-TPND5MJS.js} +5 -5
  122. package/dist/chunk-TQPCAIQI.js +612 -0
  123. package/dist/chunk-TQPCAIQI.js.map +1 -0
  124. package/dist/chunk-UT3MHJCW.js +49 -0
  125. package/dist/chunk-UT3MHJCW.js.map +1 -0
  126. package/dist/{chunk-TEW47IVR.js → chunk-VPEFSDME.js} +2 -2
  127. package/dist/{chunk-SWTLEQL6.js → chunk-WQIA3GFB.js} +2 -2
  128. package/dist/chunk-WQIA3GFB.js.map +1 -0
  129. package/dist/{chunk-DJC4CHLQ.js → chunk-YDWBXXQZ.js} +5 -5
  130. package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
  131. package/dist/composition/index.cjs +1256 -1059
  132. package/dist/composition/index.cjs.map +1 -1
  133. package/dist/composition/index.d.cts +4 -4
  134. package/dist/composition/index.d.ts +4 -4
  135. package/dist/composition/index.js +7 -6
  136. package/dist/core/index.cjs +1218 -1021
  137. package/dist/core/index.cjs.map +1 -1
  138. package/dist/core/index.d.cts +2 -2
  139. package/dist/core/index.d.ts +2 -2
  140. package/dist/core/index.js +5 -4
  141. package/dist/cqrs/index.cjs.map +1 -1
  142. package/dist/cqrs/index.d.cts +4 -4
  143. package/dist/cqrs/index.d.ts +4 -4
  144. package/dist/cqrs/index.js +3 -2
  145. package/dist/cqrs/index.js.map +1 -1
  146. package/dist/cqrs/messaging.cjs +312 -0
  147. package/dist/cqrs/messaging.cjs.map +1 -0
  148. package/dist/cqrs/messaging.d.cts +57 -0
  149. package/dist/cqrs/messaging.d.ts +57 -0
  150. package/dist/cqrs/messaging.js +274 -0
  151. package/dist/cqrs/messaging.js.map +1 -0
  152. package/dist/cqrs/work-queue.cjs +329 -0
  153. package/dist/cqrs/work-queue.cjs.map +1 -0
  154. package/dist/cqrs/work-queue.d.cts +90 -0
  155. package/dist/cqrs/work-queue.d.ts +90 -0
  156. package/dist/cqrs/work-queue.js +292 -0
  157. package/dist/cqrs/work-queue.js.map +1 -0
  158. package/dist/data/index.cjs +19 -0
  159. package/dist/data/index.cjs.map +1 -0
  160. package/dist/data/index.d.cts +36 -0
  161. package/dist/data/index.d.ts +36 -0
  162. package/dist/data/index.js +1 -0
  163. package/dist/data/index.js.map +1 -0
  164. package/dist/data-structures/index.cjs +1252 -1052
  165. package/dist/data-structures/index.cjs.map +1 -1
  166. package/dist/data-structures/index.d.cts +9 -8
  167. package/dist/data-structures/index.d.ts +9 -8
  168. package/dist/data-structures/index.js +9 -7
  169. package/dist/{describe-BZb7AS2y.d.ts → describe-B_A5fbXH.d.ts} +1 -1
  170. package/dist/{describe-Ciu8SUnN.d.cts → describe-CQRrkv-Q.d.cts} +1 -1
  171. package/dist/executors/tool-provider-adapters.cjs +3091 -0
  172. package/dist/executors/tool-provider-adapters.cjs.map +1 -0
  173. package/dist/executors/tool-provider-adapters.d.cts +174 -0
  174. package/dist/executors/tool-provider-adapters.d.ts +174 -0
  175. package/dist/executors/tool-provider-adapters.js +1336 -0
  176. package/dist/executors/tool-provider-adapters.js.map +1 -0
  177. package/dist/executors/tool-provider-runtime.cjs +5178 -0
  178. package/dist/executors/tool-provider-runtime.cjs.map +1 -0
  179. package/dist/executors/tool-provider-runtime.d.cts +17 -0
  180. package/dist/executors/tool-provider-runtime.d.ts +17 -0
  181. package/dist/executors/tool-provider-runtime.js +15 -0
  182. package/dist/executors/tool-provider-runtime.js.map +1 -0
  183. package/dist/executors/tool-provider.cjs +6392 -0
  184. package/dist/executors/tool-provider.cjs.map +1 -0
  185. package/dist/executors/tool-provider.d.cts +60 -0
  186. package/dist/executors/tool-provider.d.ts +60 -0
  187. package/dist/executors/tool-provider.js +89 -0
  188. package/dist/executors/tool-provider.js.map +1 -0
  189. package/dist/executors/work-queue.cjs +342 -0
  190. package/dist/executors/work-queue.cjs.map +1 -0
  191. package/dist/executors/work-queue.d.cts +90 -0
  192. package/dist/executors/work-queue.d.ts +90 -0
  193. package/dist/executors/work-queue.js +306 -0
  194. package/dist/executors/work-queue.js.map +1 -0
  195. package/dist/graph/index.cjs +1536 -1324
  196. package/dist/graph/index.cjs.map +1 -1
  197. package/dist/graph/index.d.cts +10 -9
  198. package/dist/graph/index.d.ts +10 -9
  199. package/dist/graph/index.js +22 -20
  200. package/dist/{graph-s23RbbFO.d.cts → graph-CWK3HLPB.d.cts} +134 -132
  201. package/dist/{graph-DfdF9zy4.d.ts → graph-ho5sotHP.d.ts} +134 -132
  202. package/dist/{index-SnzZu3x7.d.ts → index-CQWcE0Dw.d.ts} +18 -4
  203. package/dist/{index-CAEmLCYF.d.cts → index-DHA1i67c.d.cts} +18 -4
  204. package/dist/index.cjs +3331 -3020
  205. package/dist/index.cjs.map +1 -1
  206. package/dist/index.d.cts +14 -10
  207. package/dist/index.d.ts +14 -10
  208. package/dist/index.js +114 -108
  209. package/dist/inspection/boundary.cjs +98 -0
  210. package/dist/inspection/boundary.cjs.map +1 -0
  211. package/dist/inspection/boundary.d.cts +61 -0
  212. package/dist/inspection/boundary.d.ts +61 -0
  213. package/dist/inspection/boundary.js +75 -0
  214. package/dist/inspection/boundary.js.map +1 -0
  215. package/dist/measurements-C0mAvWU1.d.cts +164 -0
  216. package/dist/measurements-OMpCeBwh.d.ts +164 -0
  217. package/dist/{messages-BZqrGGm1.d.ts → messages-CAzUPPJM.d.cts} +10 -5
  218. package/dist/{messages-BZqrGGm1.d.cts → messages-CAzUPPJM.d.ts} +10 -5
  219. package/dist/messaging/index.cjs +756 -619
  220. package/dist/messaging/index.cjs.map +1 -1
  221. package/dist/messaging/index.d.cts +17 -226
  222. package/dist/messaging/index.d.ts +17 -226
  223. package/dist/messaging/index.js +19 -749
  224. package/dist/messaging/index.js.map +1 -1
  225. package/dist/operators/index.cjs +1256 -1059
  226. package/dist/operators/index.cjs.map +1 -1
  227. package/dist/operators/index.d.cts +6 -6
  228. package/dist/operators/index.d.ts +6 -6
  229. package/dist/operators/index.js +9 -8
  230. package/dist/orchestration/index.cjs +8664 -2617
  231. package/dist/orchestration/index.cjs.map +1 -1
  232. package/dist/orchestration/index.d.cts +171 -221
  233. package/dist/orchestration/index.d.ts +171 -221
  234. package/dist/orchestration/index.js +74 -982
  235. package/dist/orchestration/index.js.map +1 -1
  236. package/dist/orchestration/messaging.cjs +314 -0
  237. package/dist/orchestration/messaging.cjs.map +1 -0
  238. package/dist/orchestration/messaging.d.cts +56 -0
  239. package/dist/orchestration/messaging.d.ts +56 -0
  240. package/dist/orchestration/messaging.js +276 -0
  241. package/dist/orchestration/messaging.js.map +1 -0
  242. package/dist/orchestration/work-queue.cjs +1500 -0
  243. package/dist/orchestration/work-queue.cjs.map +1 -0
  244. package/dist/orchestration/work-queue.d.cts +196 -0
  245. package/dist/orchestration/work-queue.d.ts +196 -0
  246. package/dist/orchestration/work-queue.js +1289 -0
  247. package/dist/orchestration/work-queue.js.map +1 -0
  248. package/dist/patterns/event-flow.cjs +433 -0
  249. package/dist/patterns/event-flow.cjs.map +1 -0
  250. package/dist/patterns/event-flow.d.cts +115 -0
  251. package/dist/patterns/event-flow.d.ts +115 -0
  252. package/dist/patterns/event-flow.js +14 -0
  253. package/dist/patterns/event-flow.js.map +1 -0
  254. package/dist/patterns/index.cjs +748 -355
  255. package/dist/patterns/index.cjs.map +1 -1
  256. package/dist/patterns/index.d.cts +9 -5
  257. package/dist/patterns/index.d.ts +9 -5
  258. package/dist/patterns/index.js +13 -4
  259. package/dist/process-types-C9uMYz3i.d.ts +200 -0
  260. package/dist/process-types-h3uRlzDc.d.cts +200 -0
  261. package/dist/{reactive-collection-BxBqtIOE.d.cts → reactive-collection-B9R0Bl1P.d.cts} +11 -41
  262. package/dist/{reactive-collection-Cb1II1Fi.d.ts → reactive-collection-BXFrH0U2.d.ts} +11 -41
  263. package/dist/{reactive-collection-storage-D-KmjE0J.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
  264. package/dist/{reactive-collection-storage-BNiEc-Gd.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
  265. package/dist/{reactive-map-BcB4KsQR.d.ts → reactive-map-C_8sOfdS.d.cts} +7 -6
  266. package/dist/{reactive-map-D-g3dv8I.d.cts → reactive-map-jle5dnok.d.ts} +7 -6
  267. package/dist/render/index.d.cts +3 -3
  268. package/dist/render/index.d.ts +3 -3
  269. package/dist/render/index.js +1 -0
  270. package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
  271. package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
  272. package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
  273. package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
  274. package/dist/{semantic-memory-graph-BYoIlP35.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
  275. package/dist/{semantic-memory-graph-CxyXLms3.d.ts → semantic-memory-graph-types-Ci-OtahO.d.ts} +2 -28
  276. package/dist/solutions/index.cjs +6788 -2128
  277. package/dist/solutions/index.cjs.map +1 -1
  278. package/dist/solutions/index.d.cts +15 -519
  279. package/dist/solutions/index.d.ts +15 -519
  280. package/dist/solutions/index.js +91 -7
  281. package/dist/solutions/reactive-layout/browser/index.cjs +457 -0
  282. package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -0
  283. package/dist/solutions/reactive-layout/browser/index.d.cts +44 -0
  284. package/dist/solutions/reactive-layout/browser/index.d.ts +44 -0
  285. package/dist/solutions/reactive-layout/browser/index.js +69 -0
  286. package/dist/solutions/reactive-layout/browser/index.js.map +1 -0
  287. package/dist/solutions/reactive-layout/index.cjs +4494 -0
  288. package/dist/solutions/reactive-layout/index.cjs.map +1 -0
  289. package/dist/solutions/reactive-layout/index.d.cts +37 -0
  290. package/dist/solutions/reactive-layout/index.d.ts +37 -0
  291. package/dist/solutions/reactive-layout/index.js +146 -0
  292. package/dist/solutions/reactive-layout/index.js.map +1 -0
  293. package/dist/solutions/reactive-layout/node-canvas/index.cjs +555 -0
  294. package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -0
  295. package/dist/solutions/reactive-layout/node-canvas/index.d.cts +54 -0
  296. package/dist/solutions/reactive-layout/node-canvas/index.d.ts +54 -0
  297. package/dist/solutions/reactive-layout/node-canvas/index.js +131 -0
  298. package/dist/solutions/reactive-layout/node-canvas/index.js.map +1 -0
  299. package/dist/solutions/reactive-layout/react-native/index.cjs +504 -0
  300. package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -0
  301. package/dist/solutions/reactive-layout/react-native/index.d.cts +51 -0
  302. package/dist/solutions/reactive-layout/react-native/index.d.ts +51 -0
  303. package/dist/solutions/reactive-layout/react-native/index.js +77 -0
  304. package/dist/solutions/reactive-layout/react-native/index.js.map +1 -0
  305. package/dist/solutions/reactive-layout/skia/index.cjs +557 -0
  306. package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -0
  307. package/dist/solutions/reactive-layout/skia/index.d.cts +64 -0
  308. package/dist/solutions/reactive-layout/skia/index.d.ts +64 -0
  309. package/dist/solutions/reactive-layout/skia/index.js +70 -0
  310. package/dist/solutions/reactive-layout/skia/index.js.map +1 -0
  311. package/dist/solutions/work-item/actions.cjs +2345 -0
  312. package/dist/solutions/work-item/actions.cjs.map +1 -0
  313. package/dist/solutions/work-item/actions.d.cts +40 -0
  314. package/dist/solutions/work-item/actions.d.ts +40 -0
  315. package/dist/solutions/work-item/actions.js +2078 -0
  316. package/dist/solutions/work-item/actions.js.map +1 -0
  317. package/dist/solutions/work-item/scheduling.cjs +9797 -0
  318. package/dist/solutions/work-item/scheduling.cjs.map +1 -0
  319. package/dist/solutions/work-item/scheduling.d.cts +1868 -0
  320. package/dist/solutions/work-item/scheduling.d.ts +1868 -0
  321. package/dist/solutions/work-item/scheduling.js +146 -0
  322. package/dist/solutions/work-item/scheduling.js.map +1 -0
  323. package/dist/solutions/work-item/work-queue.cjs +306 -0
  324. package/dist/solutions/work-item/work-queue.cjs.map +1 -0
  325. package/dist/solutions/work-item/work-queue.d.cts +71 -0
  326. package/dist/solutions/work-item/work-queue.d.ts +71 -0
  327. package/dist/solutions/work-item/work-queue.js +270 -0
  328. package/dist/solutions/work-item/work-queue.js.map +1 -0
  329. package/dist/sources/browser.cjs +1399 -1052
  330. package/dist/sources/browser.cjs.map +1 -1
  331. package/dist/sources/browser.d.cts +33 -6
  332. package/dist/sources/browser.d.ts +33 -6
  333. package/dist/sources/browser.js +73 -6
  334. package/dist/sources/browser.js.map +1 -1
  335. package/dist/sources/index.cjs +1345 -1065
  336. package/dist/sources/index.cjs.map +1 -1
  337. package/dist/sources/index.d.cts +5 -5
  338. package/dist/sources/index.d.ts +5 -5
  339. package/dist/sources/index.js +7 -6
  340. package/dist/sources/node.cjs.map +1 -1
  341. package/dist/sources/node.d.cts +4 -4
  342. package/dist/sources/node.d.ts +4 -4
  343. package/dist/sources/node.js +2 -1
  344. package/dist/sources/node.js.map +1 -1
  345. package/dist/storage/browser.cjs +16 -0
  346. package/dist/storage/browser.cjs.map +1 -1
  347. package/dist/storage/browser.js +4 -3
  348. package/dist/storage/browser.js.map +1 -1
  349. package/dist/storage/index.cjs +16 -0
  350. package/dist/storage/index.cjs.map +1 -1
  351. package/dist/storage/index.d.cts +6 -5
  352. package/dist/storage/index.d.ts +6 -5
  353. package/dist/storage/index.js +10 -9
  354. package/dist/storage/node.cjs +16 -0
  355. package/dist/storage/node.cjs.map +1 -1
  356. package/dist/storage/node.js +4 -3
  357. package/dist/storage/node.js.map +1 -1
  358. package/dist/store-BmtEs9mG.d.ts +123 -0
  359. package/dist/store-PAAsYvML.d.cts +123 -0
  360. package/dist/testing/index.cjs +1 -0
  361. package/dist/testing/index.cjs.map +1 -1
  362. package/dist/testing/index.d.cts +1 -1
  363. package/dist/testing/index.d.ts +1 -1
  364. package/dist/testing/index.js +3 -2
  365. package/dist/types-BRNKoFHj.d.ts +357 -0
  366. package/dist/{types-h12mNYbq.d.ts → types-BS6CyR-x.d.cts} +49 -130
  367. package/dist/types-BWK2ay3e.d.cts +457 -0
  368. package/dist/types-BXKSAoE1.d.cts +357 -0
  369. package/dist/types-BaPpZItj.d.ts +457 -0
  370. package/dist/types-BhveCMg5.d.cts +274 -0
  371. package/dist/{types-bNMSWKqF.d.cts → types-C9NOgNJw.d.ts} +49 -130
  372. package/dist/types-CTsQ8Ww4.d.ts +274 -0
  373. package/dist/types-DL_05n2M.d.ts +34 -0
  374. package/dist/types-XDoqxYO9.d.cts +34 -0
  375. package/dist/work-item-runtime-types-BqtWnSCS.d.ts +138 -0
  376. package/dist/work-item-runtime-types-CHO03AKh.d.cts +138 -0
  377. package/dist/work-queue/index.cjs +1136 -0
  378. package/dist/work-queue/index.cjs.map +1 -0
  379. package/dist/work-queue/index.d.cts +21 -0
  380. package/dist/work-queue/index.d.ts +21 -0
  381. package/dist/work-queue/index.js +1082 -0
  382. package/dist/work-queue/index.js.map +1 -0
  383. package/package.json +603 -249
  384. package/dist/chunk-2ILL7HQI.js.map +0 -1
  385. package/dist/chunk-4VLAQHZI.js.map +0 -1
  386. package/dist/chunk-COHO25CZ.js.map +0 -1
  387. package/dist/chunk-DK554R7P.js.map +0 -1
  388. package/dist/chunk-G4M3NHRJ.js.map +0 -1
  389. package/dist/chunk-I3IHOHCJ.js.map +0 -1
  390. package/dist/chunk-JIMUDQN3.js.map +0 -1
  391. package/dist/chunk-RIIOUTGM.js.map +0 -1
  392. package/dist/chunk-SWTLEQL6.js.map +0 -1
  393. /package/dist/{chunk-GDL26N2T.js.map → chunk-3KN7NJDR.js.map} +0 -0
  394. /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
  395. /package/dist/{chunk-D6BG7U6A.js.map → chunk-7HZRJMN6.js.map} +0 -0
  396. /package/dist/{chunk-SCRFRCGR.js.map → chunk-BSQGE5PS.js.map} +0 -0
  397. /package/dist/{chunk-PKVBHGBM.js.map → chunk-CJIFGJQG.js.map} +0 -0
  398. /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
  399. /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
  400. /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
  401. /package/dist/{chunk-Y3ZLRGHC.js.map → chunk-SIDJO2T4.js.map} +0 -0
  402. /package/dist/{chunk-JR4IKCR2.js.map → chunk-TPND5MJS.js.map} +0 -0
  403. /package/dist/{chunk-TEW47IVR.js.map → chunk-VPEFSDME.js.map} +0 -0
  404. /package/dist/{chunk-DJC4CHLQ.js.map → chunk-YDWBXXQZ.js.map} +0 -0
  405. /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
@@ -0,0 +1,1500 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/orchestration/work-queue.ts
21
+ var work_queue_exports = {};
22
+ __export(work_queue_exports, {
23
+ orchestrationWorkQueueRecipe: () => orchestrationWorkQueueRecipe,
24
+ processEffectSubmitCommand: () => processEffectSubmitCommand,
25
+ workQueueLeaseExpirationCommandProjector: () => workQueueLeaseExpirationCommandProjector,
26
+ workQueueReadinessHandoffProjector: () => workQueueReadinessHandoffProjector,
27
+ workQueueScheduledReadinessProjector: () => workQueueScheduledReadinessProjector
28
+ });
29
+ module.exports = __toCommonJS(work_queue_exports);
30
+
31
+ // src/protocol/messages.ts
32
+ var SENTINEL = void 0;
33
+
34
+ // src/ctx/types.ts
35
+ function depWaves(ctx, depIndex) {
36
+ return ctx.waveData[depIndex] ?? [];
37
+ }
38
+ function depBatch(ctx, depIndex) {
39
+ const waves = depWaves(ctx, depIndex);
40
+ if (waves.length === 0) return null;
41
+ const flattened = waves.flat().filter((v) => v !== SENTINEL);
42
+ return flattened.length === 0 ? [] : flattened;
43
+ }
44
+
45
+ // src/orchestration/agent-runtime-common.ts
46
+ function uniqueSourceRefs(sourceRefs) {
47
+ const seen = /* @__PURE__ */ new Set();
48
+ const unique = [];
49
+ for (const sourceRef of sourceRefs) {
50
+ const key = `${sourceRef.kind}:${sourceRef.id}:${JSON.stringify(sourceRef.metadata ?? {})}`;
51
+ if (seen.has(key)) continue;
52
+ seen.add(key);
53
+ unique.push(sourceRef);
54
+ }
55
+ return Object.freeze(unique);
56
+ }
57
+ function stableJsonStringify(value) {
58
+ const seen = /* @__PURE__ */ new WeakSet();
59
+ return JSON.stringify(value, (_key, child) => {
60
+ if (typeof child === "bigint") return child.toString();
61
+ if (typeof child === "function") return "[Function]";
62
+ if (!isRecord(child) && !Array.isArray(child)) return child;
63
+ if (seen.has(child)) return "[Circular]";
64
+ seen.add(child);
65
+ if (Array.isArray(child)) return child;
66
+ return Object.keys(child).sort().reduce((out, key) => {
67
+ out[key] = child[key];
68
+ return out;
69
+ }, {});
70
+ });
71
+ }
72
+ function stableStringHash(value) {
73
+ let hash = 2166136261;
74
+ for (let i = 0; i < value.length; i += 1) {
75
+ hash ^= value.charCodeAt(i);
76
+ hash = Math.imul(hash, 16777619);
77
+ }
78
+ return (hash >>> 0).toString(36);
79
+ }
80
+ function projectRuntimeFact(graph, runtime, name, factory, pick) {
81
+ return graph.node(
82
+ [runtime],
83
+ (ctx) => {
84
+ for (const fact of depBatch(ctx, 0) ?? []) {
85
+ const typed = fact;
86
+ const value = pick(typed);
87
+ if (value !== void 0) ctx.down([["DATA", value]]);
88
+ }
89
+ },
90
+ { name, factory }
91
+ );
92
+ }
93
+ function forbiddenDataKeys(value, path = [], seen = /* @__PURE__ */ new WeakSet()) {
94
+ if (typeof value === "function") return [{ path, reason: "function-value" }];
95
+ if (typeof value === "symbol" || typeof value === "bigint") {
96
+ return [{ path, reason: "non-graph-visible-primitive" }];
97
+ }
98
+ if (!isRecord(value) && !Array.isArray(value)) return [];
99
+ if (typeof value === "object" && value !== null) {
100
+ if (seen.has(value)) return [];
101
+ seen.add(value);
102
+ }
103
+ const issues = [];
104
+ if (Array.isArray(value)) {
105
+ value.forEach((item, index) => {
106
+ issues.push(...forbiddenDataKeys(item, [...path, index], seen));
107
+ });
108
+ return issues;
109
+ }
110
+ if (!isPlainRecord(value)) return [{ path, reason: "non-plain-runtime-object" }];
111
+ const symbolKeys = Object.getOwnPropertySymbols(value);
112
+ if (symbolKeys.length > 0) {
113
+ issues.push({ path, reason: "symbol-key" });
114
+ }
115
+ for (const [key, child] of Object.entries(value)) {
116
+ const nextPath = [...path, key];
117
+ if (/^(apiKey|api_key|secret|client|transport|subprocess|sdk|oauth|credential|credentials|accessToken|access_token|refreshToken|refresh_token|idToken|id_token|token|password|passphrase|authorization|authHeader|auth_header|bearer|privateKey|private_key|sessionCookie|session_cookie|cookie)$/i.test(
118
+ key
119
+ )) {
120
+ issues.push({ path: nextPath, reason: "forbidden-runtime-key" });
121
+ }
122
+ issues.push(...forbiddenDataKeys(child, nextPath, seen));
123
+ }
124
+ return issues;
125
+ }
126
+ function sanitizeGraphVisibleRecord(value, policy) {
127
+ return sanitizePublicRecord(value, { mode: "graph", policy });
128
+ }
129
+ function canonicalPublicSourceRefs(sourceRefs) {
130
+ return uniqueSourceRefs(
131
+ sourceRefs.map((sourceRef) => {
132
+ const metadata = sanitizePublicRecord(sourceRef.metadata, { mode: "provider" });
133
+ return metadata === void 0 ? { kind: sourceRef.kind, id: sourceRef.id } : { kind: sourceRef.kind, id: sourceRef.id, metadata };
134
+ })
135
+ );
136
+ }
137
+ function sanitizePublicRecord(value, opts) {
138
+ if (value === void 0 || publicMaterialForbiddenKeys(value, opts.mode).length > 0) {
139
+ return void 0;
140
+ }
141
+ return Object.freeze(boundRecordStrings(value, maxPublicMetadataStringChars(opts.policy)));
142
+ }
143
+ function publicMaterialForbiddenKeys(value, mode) {
144
+ const forbidden = [...forbiddenDataKeys(value)];
145
+ if (mode === "provider") forbidden.push(...forbiddenProviderRawMaterialKeys(value));
146
+ return forbidden;
147
+ }
148
+ function boundPublicText(text, limitChars) {
149
+ const limit = Math.max(0, limitChars);
150
+ if (text.length <= limit) {
151
+ return { text, truncated: false, originalChars: text.length, limitChars: limit };
152
+ }
153
+ const bounded = limit <= 1 ? text.slice(0, limit) : limit <= 3 ? text.slice(0, limit) : `${text.slice(0, limit - 3)}...`;
154
+ return { text: bounded, truncated: true, originalChars: text.length, limitChars: limit };
155
+ }
156
+ function boundRecordStrings(value, limitChars, seen = /* @__PURE__ */ new WeakSet()) {
157
+ if (seen.has(value)) return {};
158
+ seen.add(value);
159
+ return Object.entries(value).reduce((out, [key, child]) => {
160
+ if (typeof child === "string") {
161
+ out[key] = boundPublicText(child, limitChars).text;
162
+ } else if (Array.isArray(child)) {
163
+ out[key] = child.map(
164
+ (item) => typeof item === "string" ? boundPublicText(item, limitChars).text : isPlainRecord(item) ? boundRecordStrings(item, limitChars, seen) : item
165
+ );
166
+ } else if (isPlainRecord(child)) {
167
+ out[key] = boundRecordStrings(child, limitChars, seen);
168
+ } else {
169
+ out[key] = child;
170
+ }
171
+ return out;
172
+ }, {});
173
+ }
174
+ function maxPublicMetadataStringChars(policy) {
175
+ return normalizedPublicTextLimit(policy?.maxMetadataStringChars, 256);
176
+ }
177
+ function normalizedPublicTextLimit(value, fallback) {
178
+ if (value === void 0 || !Number.isFinite(value)) return fallback;
179
+ return Math.max(0, Math.floor(value));
180
+ }
181
+ function forbiddenProviderRawMaterialKeys(value, path = [], seen = /* @__PURE__ */ new WeakSet()) {
182
+ if (!isRecord(value) && !Array.isArray(value)) return [];
183
+ if (typeof value === "object" && value !== null) {
184
+ if (seen.has(value)) return [];
185
+ seen.add(value);
186
+ }
187
+ const issues = [];
188
+ if (Array.isArray(value)) {
189
+ value.forEach((item, index) => {
190
+ issues.push(...forbiddenProviderRawMaterialKeys(item, [...path, index], seen));
191
+ });
192
+ return issues;
193
+ }
194
+ for (const [key, child] of Object.entries(value)) {
195
+ const nextPath = [...path, key];
196
+ if (/^(stdout|stderr|stack|stackTrace|stack_trace|providerRaw|provider_raw|rawResponse|raw_response|diff|patch|fileContents|file_contents|binary|media)$/i.test(
197
+ key
198
+ )) {
199
+ issues.push({ path: nextPath, reason: "raw-provider-material" });
200
+ }
201
+ issues.push(...forbiddenProviderRawMaterialKeys(child, nextPath, seen));
202
+ }
203
+ return issues;
204
+ }
205
+ function dataIssue(code, message, opts = {}) {
206
+ return {
207
+ kind: "issue",
208
+ code,
209
+ message,
210
+ severity: opts.severity ?? "error",
211
+ subjectId: opts.subjectId,
212
+ refs: opts.refs?.map((r) => `${r.kind}:${r.id}`),
213
+ details: opts.details
214
+ };
215
+ }
216
+ function ref(kind, id) {
217
+ return { kind, id };
218
+ }
219
+ function isRecord(value) {
220
+ return typeof value === "object" && value !== null && !Array.isArray(value);
221
+ }
222
+ function isPlainRecord(value) {
223
+ if (!isRecord(value)) return false;
224
+ const proto = Object.getPrototypeOf(value);
225
+ return proto === Object.prototype || proto === null;
226
+ }
227
+
228
+ // src/orchestration/work-queue-scheduled-readiness.ts
229
+ var MAX_PUBLIC_COORDINATE_ID_CHARS = 160;
230
+ var MAX_COPIED_PUBLIC_REFS = 16;
231
+ var PRIVATE_COORDINATE_PATTERN = /(api[_-]?key|authorization|bearer|credential|oauth|password|private[_-]?key|secret|session[_-]?cookie|token)/i;
232
+ function workQueueScheduledReadinessProjector(graph, opts) {
233
+ const name = opts.name ?? "workQueueScheduledReadiness";
234
+ const runtime = graph.node(
235
+ [opts.records],
236
+ (ctx) => {
237
+ const state = ctx.state.get() ?? initialState();
238
+ for (const raw of depBatch(ctx, 0) ?? []) {
239
+ const translated = translateRecord(raw);
240
+ if (translated.kind === "none") continue;
241
+ if (translated.kind === "issue") {
242
+ emitIssue(ctx, state, translated.issue);
243
+ emitStatus(ctx, state, translated.status);
244
+ continue;
245
+ }
246
+ const identity = scheduleIdentity(translated.schedule);
247
+ const recordKey = `${translated.record.queueId}:${translated.record.recordSeq}`;
248
+ const existingRecordIdentity = state.recordScheduleIdentityByKey.get(recordKey);
249
+ if (existingRecordIdentity !== void 0) {
250
+ if (existingRecordIdentity !== identity) emitScheduleConflict(ctx, state, translated);
251
+ continue;
252
+ }
253
+ state.recordScheduleIdentityByKey.set(recordKey, identity);
254
+ const existing = state.schedulesById.get(translated.schedule.scheduleId);
255
+ if (existing !== void 0) {
256
+ if (scheduleIdentity(existing) !== identity) {
257
+ emitScheduleConflict(ctx, state, translated, existing);
258
+ }
259
+ continue;
260
+ }
261
+ state.schedulesById.set(translated.schedule.scheduleId, translated.schedule);
262
+ emitSchedule(ctx, state, translated.schedule);
263
+ emitStatus(ctx, state, translated.status);
264
+ emitAudit(ctx, state, "work-queue-scheduled-readiness-translated", {
265
+ subjectId: translated.schedule.scheduleId,
266
+ sourceRefs: translated.schedule.sourceRefs,
267
+ metadata: {
268
+ queueId: publicCoordinateId(translated.record.queueId),
269
+ workId: publicCoordinateId(translated.record.workId),
270
+ recordSeq: translated.record.recordSeq,
271
+ recordKind: translated.record.kind,
272
+ readyAtMs: translated.schedule.readyAtMs
273
+ }
274
+ });
275
+ }
276
+ ctx.down([["DATA", { kind: "views", views: buildViews(state) }]]);
277
+ ctx.state.set(state);
278
+ },
279
+ {
280
+ name: `${name}/runtime`,
281
+ factory: "workQueueScheduledReadinessProjector",
282
+ partial: true,
283
+ completeWhenDepsComplete: false,
284
+ errorWhenDepsError: false
285
+ }
286
+ );
287
+ return {
288
+ readinessSchedules: projectRuntimeFact(
289
+ graph,
290
+ runtime,
291
+ `${name}/readinessSchedules`,
292
+ "workQueueScheduledReadinessSchedules",
293
+ (fact) => fact.kind === "readiness-schedule" ? fact.schedule : void 0
294
+ ),
295
+ status: projectRuntimeFact(
296
+ graph,
297
+ runtime,
298
+ `${name}/status`,
299
+ "workQueueScheduledReadinessStatus",
300
+ (fact) => fact.kind === "status" ? fact.status : void 0
301
+ ),
302
+ issues: projectRuntimeFact(
303
+ graph,
304
+ runtime,
305
+ `${name}/issues`,
306
+ "workQueueScheduledReadinessIssues",
307
+ (fact) => fact.kind === "issue" ? fact.issue : void 0
308
+ ),
309
+ audit: projectRuntimeFact(
310
+ graph,
311
+ runtime,
312
+ `${name}/audit`,
313
+ "workQueueScheduledReadinessAudit",
314
+ (fact) => fact.kind === "audit" ? fact.audit : void 0
315
+ ),
316
+ views: projectRuntimeFact(
317
+ graph,
318
+ runtime,
319
+ `${name}/views`,
320
+ "workQueueScheduledReadinessViews",
321
+ (fact) => fact.kind === "views" ? fact.views : void 0
322
+ )
323
+ };
324
+ }
325
+ function workQueueReadinessHandoffProjector(graph, opts) {
326
+ const name = opts.name ?? "workQueueReadinessHandoff";
327
+ const deps = opts.overdue === void 0 ? [opts.records, opts.ready] : [opts.records, opts.ready, opts.overdue];
328
+ const runtime = graph.node(
329
+ deps,
330
+ (ctx) => {
331
+ const state = ctx.state.get() ?? handoffState();
332
+ for (const raw of depBatch(ctx, 0) ?? []) {
333
+ const record = raw;
334
+ ingestWorkQueueRecord(state, record);
335
+ }
336
+ for (const raw of depBatch(ctx, 1) ?? []) {
337
+ const ready = raw;
338
+ state.readyByScheduleId.set(ready.scheduleId, ready);
339
+ }
340
+ if (opts.overdue !== void 0) {
341
+ for (const raw of depBatch(ctx, 2) ?? []) {
342
+ emitOverdueHandoffStatus(ctx, state, raw);
343
+ }
344
+ }
345
+ evaluateReadyHandoffs(ctx, state);
346
+ ctx.down([["DATA", { kind: "views", views: buildHandoffViews(state) }]]);
347
+ ctx.state.set(state);
348
+ },
349
+ {
350
+ name: `${name}/runtime`,
351
+ factory: "workQueueReadinessHandoffProjector",
352
+ partial: true,
353
+ completeWhenDepsComplete: false,
354
+ errorWhenDepsError: false
355
+ }
356
+ );
357
+ return {
358
+ candidates: projectRuntimeFact(
359
+ graph,
360
+ runtime,
361
+ `${name}/candidates`,
362
+ "workQueueReadinessHandoffCandidates",
363
+ (fact) => fact.kind === "candidate" ? fact.candidate : void 0
364
+ ),
365
+ status: projectRuntimeFact(
366
+ graph,
367
+ runtime,
368
+ `${name}/status`,
369
+ "workQueueReadinessHandoffStatus",
370
+ (fact) => fact.kind === "status" ? fact.status : void 0
371
+ ),
372
+ issues: projectRuntimeFact(
373
+ graph,
374
+ runtime,
375
+ `${name}/issues`,
376
+ "workQueueReadinessHandoffIssues",
377
+ (fact) => fact.kind === "issue" ? fact.issue : void 0
378
+ ),
379
+ audit: projectRuntimeFact(
380
+ graph,
381
+ runtime,
382
+ `${name}/audit`,
383
+ "workQueueReadinessHandoffAudit",
384
+ (fact) => fact.kind === "audit" ? fact.audit : void 0
385
+ ),
386
+ views: projectRuntimeFact(
387
+ graph,
388
+ runtime,
389
+ `${name}/views`,
390
+ "workQueueReadinessHandoffViews",
391
+ (fact) => fact.kind === "views" ? fact.views : void 0
392
+ )
393
+ };
394
+ }
395
+ function workQueueLeaseExpirationCommandProjector(graph, opts) {
396
+ const name = opts.name ?? "workQueueLeaseExpirationCommands";
397
+ const runtime = graph.node(
398
+ [opts.candidates],
399
+ (ctx) => {
400
+ const state = ctx.state.get() ?? leaseExpirationCommandState();
401
+ for (const raw of depBatch(ctx, 0) ?? []) {
402
+ const candidate = raw;
403
+ if (candidate.candidateKind !== "lease-expiration-eligible") continue;
404
+ if (state.commandByCandidateId.has(candidate.candidateId)) continue;
405
+ const command = Object.freeze({
406
+ kind: "expire-leases",
407
+ commandId: `${candidate.candidateId}:expire-leases`,
408
+ queueId: candidate.queueId,
409
+ workIds: [candidate.workId],
410
+ limit: 1,
411
+ nowMs: candidate.nowMs,
412
+ causationId: candidate.scheduleId,
413
+ ...sourceRefStrings(candidate.sourceRefs) === void 0 ? {} : { sourceRefs: sourceRefStrings(candidate.sourceRefs) }
414
+ });
415
+ state.commandByCandidateId.set(candidate.candidateId, command);
416
+ ctx.down([["DATA", { kind: "command", command }]]);
417
+ emitLeaseCommandStatus(ctx, state, command, candidate);
418
+ }
419
+ ctx.down([["DATA", { kind: "views", views: buildLeaseCommandViews(state) }]]);
420
+ ctx.state.set(state);
421
+ },
422
+ {
423
+ name: `${name}/runtime`,
424
+ factory: "workQueueLeaseExpirationCommandProjector",
425
+ partial: true,
426
+ completeWhenDepsComplete: false,
427
+ errorWhenDepsError: false
428
+ }
429
+ );
430
+ return {
431
+ commands: projectRuntimeFact(
432
+ graph,
433
+ runtime,
434
+ `${name}/commands`,
435
+ "workQueueLeaseExpirationCommands",
436
+ (fact) => fact.kind === "command" ? fact.command : void 0
437
+ ),
438
+ status: projectRuntimeFact(
439
+ graph,
440
+ runtime,
441
+ `${name}/status`,
442
+ "workQueueLeaseExpirationCommandStatus",
443
+ (fact) => fact.kind === "status" ? fact.status : void 0
444
+ ),
445
+ views: projectRuntimeFact(
446
+ graph,
447
+ runtime,
448
+ `${name}/views`,
449
+ "workQueueLeaseExpirationCommandViews",
450
+ (fact) => fact.kind === "views" ? fact.views : void 0
451
+ )
452
+ };
453
+ }
454
+ function initialState() {
455
+ return {
456
+ recordScheduleIdentityByKey: /* @__PURE__ */ new Map(),
457
+ schedulesById: /* @__PURE__ */ new Map(),
458
+ statusById: /* @__PURE__ */ new Map(),
459
+ emittedKeys: /* @__PURE__ */ new Set(),
460
+ issueKeys: /* @__PURE__ */ new Set(),
461
+ auditSeq: 0
462
+ };
463
+ }
464
+ function handoffState() {
465
+ return {
466
+ originsByScheduleId: /* @__PURE__ */ new Map(),
467
+ worksById: /* @__PURE__ */ new Map(),
468
+ readyByScheduleId: /* @__PURE__ */ new Map(),
469
+ candidatesById: /* @__PURE__ */ new Map(),
470
+ statusById: /* @__PURE__ */ new Map(),
471
+ emittedKeys: /* @__PURE__ */ new Set(),
472
+ issueKeys: /* @__PURE__ */ new Set(),
473
+ auditSeq: 0
474
+ };
475
+ }
476
+ function leaseExpirationCommandState() {
477
+ return {
478
+ commandByCandidateId: /* @__PURE__ */ new Map(),
479
+ statusById: /* @__PURE__ */ new Map(),
480
+ emittedKeys: /* @__PURE__ */ new Set()
481
+ };
482
+ }
483
+ function ingestWorkQueueRecord(state, record) {
484
+ const translated = translateRecord(record);
485
+ if (translated.kind === "translated") {
486
+ state.originsByScheduleId.set(translated.schedule.scheduleId, {
487
+ record: translated.record,
488
+ schedule: translated.schedule,
489
+ scheduleKind: translated.status.scheduleKind
490
+ });
491
+ }
492
+ if (record.workId === void 0) return;
493
+ const recordWithWorkId = record;
494
+ const existing = state.worksById.get(
495
+ handoffWorkKey(recordWithWorkId.queueId, recordWithWorkId.workId)
496
+ );
497
+ if (existing !== void 0 && recordWithWorkId.recordSeq < existing.latestRecordSeq) return;
498
+ const work = ensureHandoffWorkState(state, recordWithWorkId);
499
+ work.latestRecordSeq = Math.max(work.latestRecordSeq, recordWithWorkId.recordSeq);
500
+ switch (recordWithWorkId.kind) {
501
+ case "work-admitted":
502
+ work.state = recordWithWorkId.notBeforeMs === void 0 ? "ready" : "scheduled";
503
+ work.notBeforeMs = recordWithWorkId.notBeforeMs;
504
+ work.retryAtMs = void 0;
505
+ work.deadlineMs = recordWithWorkId.deadlineMs;
506
+ clearHandoffLease(work);
507
+ break;
508
+ case "work-scheduled":
509
+ work.state = "scheduled";
510
+ work.notBeforeMs = recordWithWorkId.notBeforeMs;
511
+ work.deadlineMs = recordWithWorkId.deadlineMs;
512
+ break;
513
+ case "retry-scheduled":
514
+ work.state = recordWithWorkId.retryAtMs <= recordWithWorkId.recordedAtMs ? "ready" : "retry-wait";
515
+ work.retryAtMs = recordWithWorkId.retryAtMs;
516
+ work.notBeforeMs = void 0;
517
+ break;
518
+ case "work-claimed":
519
+ work.state = "leased";
520
+ work.leaseId = recordWithWorkId.leaseId;
521
+ work.attempt = recordWithWorkId.attempt;
522
+ work.workerId = recordWithWorkId.workerId;
523
+ work.leaseExpiresAtMs = recordWithWorkId.leaseExpiresAtMs;
524
+ break;
525
+ case "lease-renewed":
526
+ work.state = "leased";
527
+ work.leaseId = recordWithWorkId.leaseId;
528
+ work.attempt = recordWithWorkId.attempt;
529
+ work.workerId = recordWithWorkId.workerId;
530
+ work.leaseExpiresAtMs = recordWithWorkId.leaseExpiresAtMs;
531
+ break;
532
+ case "work-released":
533
+ case "lease-expired":
534
+ work.state = "ready";
535
+ clearHandoffLease(work);
536
+ break;
537
+ case "work-completed":
538
+ work.state = "completed";
539
+ clearHandoffLease(work);
540
+ break;
541
+ case "work-canceled":
542
+ work.state = "canceled";
543
+ clearHandoffLease(work);
544
+ break;
545
+ case "work-dead-lettered":
546
+ work.state = "dead-lettered";
547
+ clearHandoffLease(work);
548
+ break;
549
+ }
550
+ }
551
+ function ensureHandoffWorkState(state, record) {
552
+ const key = handoffWorkKey(record.queueId, record.workId);
553
+ const existing = state.worksById.get(key);
554
+ if (existing !== void 0) return existing;
555
+ const next = {
556
+ queueId: record.queueId,
557
+ workId: record.workId,
558
+ state: "ready",
559
+ latestRecordSeq: record.recordSeq
560
+ };
561
+ state.worksById.set(key, next);
562
+ return next;
563
+ }
564
+ function handoffWorkKey(queueId, workId) {
565
+ return stableJsonStringify([queueId, workId]);
566
+ }
567
+ function clearHandoffLease(work) {
568
+ work.leaseId = void 0;
569
+ work.attempt = void 0;
570
+ work.workerId = void 0;
571
+ work.leaseExpiresAtMs = void 0;
572
+ }
573
+ function evaluateReadyHandoffs(ctx, state) {
574
+ for (const ready of state.readyByScheduleId.values()) {
575
+ const origin = state.originsByScheduleId.get(ready.scheduleId);
576
+ if (origin === void 0) {
577
+ emitHandoffStatus(
578
+ ctx,
579
+ state,
580
+ handoffStatus("pending-origin", {
581
+ scheduleId: ready.scheduleId,
582
+ readyAtMs: ready.readyAtMs,
583
+ nowMs: ready.nowMs,
584
+ sourceRefs: ready.sourceRefs
585
+ })
586
+ );
587
+ continue;
588
+ }
589
+ const work = state.worksById.get(handoffWorkKey(origin.record.queueId, origin.record.workId));
590
+ if (work === void 0) {
591
+ emitHandoffStatus(
592
+ ctx,
593
+ state,
594
+ handoffStatus("pending-origin", {
595
+ queueId: origin.record.queueId,
596
+ workId: origin.record.workId,
597
+ scheduleId: ready.scheduleId,
598
+ readyAtMs: ready.readyAtMs,
599
+ nowMs: ready.nowMs,
600
+ sourceRefs: ready.sourceRefs
601
+ })
602
+ );
603
+ continue;
604
+ }
605
+ if (origin.record.recordSeq < work.latestRecordSeq) {
606
+ emitSuperseded(ctx, state, origin, work, ready, {
607
+ latestRecordSeq: work.latestRecordSeq
608
+ });
609
+ continue;
610
+ }
611
+ const terminal = terminalHandoffState(work.state);
612
+ if (terminal) {
613
+ emitHandoffStatus(
614
+ ctx,
615
+ state,
616
+ handoffStatus("ignored-terminal", {
617
+ queueId: work.queueId,
618
+ workId: work.workId,
619
+ scheduleId: ready.scheduleId,
620
+ readyAtMs: ready.readyAtMs,
621
+ nowMs: ready.nowMs,
622
+ currentState: work.state,
623
+ sourceRefs: ready.sourceRefs
624
+ })
625
+ );
626
+ continue;
627
+ }
628
+ if (origin.scheduleKind === "lease-expiration") {
629
+ evaluateLeaseExpirationReady(ctx, state, origin, work, ready);
630
+ continue;
631
+ }
632
+ evaluateClaimEligibilityReady(ctx, state, origin, work, ready);
633
+ }
634
+ }
635
+ function evaluateClaimEligibilityReady(ctx, state, origin, work, ready) {
636
+ if (work.state === "leased") {
637
+ emitHandoffStatus(
638
+ ctx,
639
+ state,
640
+ handoffStatus("ignored-stale", {
641
+ queueId: work.queueId,
642
+ workId: work.workId,
643
+ scheduleId: ready.scheduleId,
644
+ readyAtMs: ready.readyAtMs,
645
+ nowMs: ready.nowMs,
646
+ currentState: work.state,
647
+ sourceRefs: ready.sourceRefs
648
+ })
649
+ );
650
+ return;
651
+ }
652
+ if (work.notBeforeMs !== void 0 && work.notBeforeMs > ready.nowMs) {
653
+ emitSuperseded(ctx, state, origin, work, ready, { notBeforeMs: work.notBeforeMs });
654
+ return;
655
+ }
656
+ if (work.retryAtMs !== void 0 && work.retryAtMs > ready.nowMs) {
657
+ emitSuperseded(ctx, state, origin, work, ready, { retryAtMs: work.retryAtMs });
658
+ return;
659
+ }
660
+ emitCandidate(ctx, state, candidateFor(origin, ready, "claim-eligible"));
661
+ }
662
+ function evaluateLeaseExpirationReady(ctx, state, origin, work, ready) {
663
+ if (origin.record.kind !== "work-claimed" && origin.record.kind !== "lease-renewed") {
664
+ emitHandoffIssue(
665
+ ctx,
666
+ state,
667
+ dataIssue(
668
+ "work-queue-readiness-handoff-malformed-origin",
669
+ "Lease-expiration readiness must originate from a lease-bearing workQueue record.",
670
+ { subjectId: ready.scheduleId, refs: ready.sourceRefs }
671
+ )
672
+ );
673
+ return;
674
+ }
675
+ if (work.state !== "leased" || work.leaseId !== origin.record.leaseId || work.attempt !== origin.record.attempt || work.workerId !== origin.record.workerId) {
676
+ emitHandoffStatus(
677
+ ctx,
678
+ state,
679
+ handoffStatus("ignored-stale", {
680
+ queueId: work.queueId,
681
+ workId: work.workId,
682
+ scheduleId: ready.scheduleId,
683
+ readyAtMs: ready.readyAtMs,
684
+ nowMs: ready.nowMs,
685
+ currentState: work.state,
686
+ sourceRefs: ready.sourceRefs
687
+ })
688
+ );
689
+ return;
690
+ }
691
+ if (work.leaseExpiresAtMs !== origin.record.leaseExpiresAtMs) {
692
+ emitSuperseded(ctx, state, origin, work, ready, {
693
+ leaseExpiresAtMs: work.leaseExpiresAtMs
694
+ });
695
+ return;
696
+ }
697
+ if (work.leaseExpiresAtMs !== void 0 && work.leaseExpiresAtMs > ready.nowMs) {
698
+ emitSuperseded(ctx, state, origin, work, ready, {
699
+ leaseExpiresAtMs: work.leaseExpiresAtMs
700
+ });
701
+ return;
702
+ }
703
+ emitCandidate(ctx, state, candidateFor(origin, ready, "lease-expiration-eligible"));
704
+ }
705
+ function emitSuperseded(ctx, state, origin, work, ready, metadata) {
706
+ emitHandoffStatus(
707
+ ctx,
708
+ state,
709
+ handoffStatus("ignored-superseded", {
710
+ queueId: work.queueId,
711
+ workId: work.workId,
712
+ scheduleId: ready.scheduleId,
713
+ readyAtMs: ready.readyAtMs,
714
+ nowMs: ready.nowMs,
715
+ currentState: work.state,
716
+ sourceRefs: ready.sourceRefs,
717
+ metadata: {
718
+ originRecordSeq: origin.record.recordSeq,
719
+ originRecordKind: origin.record.kind,
720
+ ...metadata
721
+ }
722
+ })
723
+ );
724
+ }
725
+ function candidateFor(origin, ready, candidateKind) {
726
+ const lease = origin.record.kind === "work-claimed" || origin.record.kind === "lease-renewed" ? {
727
+ leaseId: origin.record.leaseId,
728
+ attempt: origin.record.attempt,
729
+ workerId: origin.record.workerId,
730
+ leaseExpiresAtMs: origin.record.leaseExpiresAtMs
731
+ } : {};
732
+ const metadata = sanitizeGraphVisibleRecord({
733
+ originRecordSeq: origin.record.recordSeq,
734
+ originRecordKind: origin.record.kind,
735
+ scheduleKind: origin.scheduleKind
736
+ });
737
+ return Object.freeze({
738
+ kind: "work-queue-readiness-candidate",
739
+ candidateId: `${ready.scheduleId}:work-queue:${candidateKind}`,
740
+ candidateKind,
741
+ queueId: origin.record.queueId,
742
+ workId: origin.record.workId,
743
+ scheduleId: ready.scheduleId,
744
+ readyAtMs: ready.readyAtMs,
745
+ nowMs: ready.nowMs,
746
+ originRecordSeq: origin.record.recordSeq,
747
+ originRecordKind: origin.record.kind,
748
+ ...lease,
749
+ sourceRefs: canonicalPublicSourceRefs(
750
+ uniqueSourceRefs([
751
+ ...ready.sourceRefs ?? [],
752
+ ref("work-queue-record", String(origin.record.recordSeq)),
753
+ ref("scheduled-readiness-ready", ready.scheduleId)
754
+ ])
755
+ ),
756
+ ...metadata === void 0 ? {} : { metadata }
757
+ });
758
+ }
759
+ function emitCandidate(ctx, state, candidate) {
760
+ const key = `candidate:${candidate.candidateId}`;
761
+ if (!state.emittedKeys.has(key)) {
762
+ state.emittedKeys.add(key);
763
+ state.candidatesById.set(candidate.candidateId, candidate);
764
+ ctx.down([["DATA", { kind: "candidate", candidate }]]);
765
+ emitHandoffAudit(ctx, state, "work-queue-readiness-candidate", {
766
+ subjectId: candidate.candidateId,
767
+ sourceRefs: candidate.sourceRefs,
768
+ metadata: {
769
+ candidateKind: candidate.candidateKind,
770
+ queueId: candidate.queueId,
771
+ workId: candidate.workId,
772
+ readyAtMs: candidate.readyAtMs,
773
+ nowMs: candidate.nowMs
774
+ }
775
+ });
776
+ } else {
777
+ state.candidatesById.set(candidate.candidateId, candidate);
778
+ }
779
+ emitHandoffStatus(
780
+ ctx,
781
+ state,
782
+ handoffStatus("candidate", {
783
+ queueId: candidate.queueId,
784
+ workId: candidate.workId,
785
+ scheduleId: candidate.scheduleId,
786
+ candidateId: candidate.candidateId,
787
+ candidateKind: candidate.candidateKind,
788
+ readyAtMs: candidate.readyAtMs,
789
+ nowMs: candidate.nowMs,
790
+ sourceRefs: candidate.sourceRefs
791
+ })
792
+ );
793
+ }
794
+ function emitOverdueHandoffStatus(ctx, state, overdue) {
795
+ const origin = state.originsByScheduleId.get(overdue.scheduleId);
796
+ emitHandoffStatus(
797
+ ctx,
798
+ state,
799
+ handoffStatus("overdue", {
800
+ queueId: origin?.record.queueId,
801
+ workId: origin?.record.workId,
802
+ scheduleId: overdue.scheduleId,
803
+ readyAtMs: overdue.readyAtMs,
804
+ nowMs: overdue.nowMs,
805
+ sourceRefs: overdue.sourceRefs,
806
+ metadata: {
807
+ deadlineMs: overdue.deadlineMs,
808
+ ...origin === void 0 ? {} : { originRecordSeq: origin.record.recordSeq, originRecordKind: origin.record.kind }
809
+ }
810
+ })
811
+ );
812
+ }
813
+ function handoffStatus(state, opts) {
814
+ const subject = opts.candidateId ?? opts.scheduleId ?? "unknown-work-queue-readiness";
815
+ const metadata = sanitizeGraphVisibleRecord(opts.metadata);
816
+ return Object.freeze({
817
+ kind: "work-queue-readiness-handoff-status",
818
+ statusId: `${subject}:work-queue-readiness-handoff-status:${state}`,
819
+ state,
820
+ ...opts.queueId === void 0 ? {} : { queueId: opts.queueId },
821
+ ...opts.workId === void 0 ? {} : { workId: opts.workId },
822
+ ...opts.scheduleId === void 0 ? {} : { scheduleId: opts.scheduleId },
823
+ ...opts.candidateId === void 0 ? {} : { candidateId: opts.candidateId },
824
+ ...opts.candidateKind === void 0 ? {} : { candidateKind: opts.candidateKind },
825
+ ...opts.readyAtMs === void 0 ? {} : { readyAtMs: opts.readyAtMs },
826
+ ...opts.nowMs === void 0 ? {} : { nowMs: opts.nowMs },
827
+ ...opts.currentState === void 0 ? {} : { currentState: opts.currentState },
828
+ ...opts.sourceRefs === void 0 ? {} : { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) },
829
+ ...opts.issueCodes === void 0 ? {} : { issueCodes: opts.issueCodes },
830
+ ...metadata === void 0 ? {} : { metadata }
831
+ });
832
+ }
833
+ function emitHandoffStatus(ctx, state, status) {
834
+ state.statusById.set(status.statusId, status);
835
+ const key = `handoff-status:${status.statusId}:${stableJsonStringify(status)}`;
836
+ if (state.emittedKeys.has(key)) return;
837
+ state.emittedKeys.add(key);
838
+ ctx.down([["DATA", { kind: "status", status }]]);
839
+ }
840
+ function emitHandoffIssue(ctx, state, issue) {
841
+ const key = `${issue.code}:${issue.subjectId ?? ""}:${JSON.stringify(issue.details ?? {})}`;
842
+ if (state.issueKeys.has(key)) return;
843
+ state.issueKeys.add(key);
844
+ ctx.down([["DATA", { kind: "issue", issue }]]);
845
+ emitHandoffStatus(
846
+ ctx,
847
+ state,
848
+ handoffStatus("issue", {
849
+ scheduleId: issue.subjectId,
850
+ sourceRefs: issue.refs?.map(sourceRefFromIssueRef),
851
+ issueCodes: [issue.code]
852
+ })
853
+ );
854
+ }
855
+ function emitHandoffAudit(ctx, state, kind, opts) {
856
+ state.auditSeq += 1;
857
+ const metadata = sanitizeGraphVisibleRecord(opts.metadata);
858
+ ctx.down([
859
+ [
860
+ "DATA",
861
+ {
862
+ kind: "audit",
863
+ audit: Object.freeze({
864
+ id: `work-queue-readiness-handoff-audit-${state.auditSeq}`,
865
+ kind,
866
+ subjectId: opts.subjectId,
867
+ ...opts.sourceRefs === void 0 ? {} : { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) },
868
+ ...metadata === void 0 ? {} : { metadata }
869
+ })
870
+ }
871
+ ]
872
+ ]);
873
+ }
874
+ function buildHandoffViews(state) {
875
+ return Object.freeze({
876
+ candidatesById: new Map(state.candidatesById),
877
+ statusById: new Map(state.statusById)
878
+ });
879
+ }
880
+ function emitLeaseCommandStatus(ctx, state, command, candidate) {
881
+ const status = handoffStatus("candidate", {
882
+ queueId: candidate.queueId,
883
+ workId: candidate.workId,
884
+ scheduleId: candidate.scheduleId,
885
+ candidateId: candidate.candidateId,
886
+ candidateKind: candidate.candidateKind,
887
+ readyAtMs: candidate.readyAtMs,
888
+ nowMs: candidate.nowMs,
889
+ sourceRefs: candidate.sourceRefs,
890
+ metadata: {
891
+ commandId: command.commandId,
892
+ commandKind: command.kind
893
+ }
894
+ });
895
+ state.statusById.set(status.statusId, status);
896
+ const key = `lease-command-status:${status.statusId}`;
897
+ if (state.emittedKeys.has(key)) return;
898
+ state.emittedKeys.add(key);
899
+ ctx.down([["DATA", { kind: "status", status }]]);
900
+ }
901
+ function buildLeaseCommandViews(state) {
902
+ return Object.freeze({
903
+ candidatesById: /* @__PURE__ */ new Map(),
904
+ statusById: new Map(state.statusById)
905
+ });
906
+ }
907
+ function sourceRefStrings(sourceRefs) {
908
+ if (sourceRefs === void 0 || sourceRefs.length === 0) return void 0;
909
+ return sourceRefs.map((sourceRef) => `${sourceRef.kind}:${sourceRef.id}`);
910
+ }
911
+ function sourceRefFromIssueRef(issueRef) {
912
+ const [kind, ...rest] = issueRef.split(":");
913
+ return ref(kind || "issue-ref", rest.join(":") || issueRef);
914
+ }
915
+ function terminalHandoffState(state) {
916
+ return state === "completed" || state === "canceled" || state === "dead-lettered";
917
+ }
918
+ function hasWorkRecordCoordinates(record) {
919
+ return typeof record.queueId === "string" && typeof record.workId === "string" && typeof record.recordSeq === "number" && Number.isFinite(record.recordSeq);
920
+ }
921
+ function hasLeaseRecordCoordinates(record) {
922
+ return hasWorkRecordCoordinates(record) && typeof record.leaseId === "string" && typeof record.attempt === "number" && Number.isFinite(record.attempt) && typeof record.workerId === "string";
923
+ }
924
+ function malformedRecord(record, message) {
925
+ const subjectId = typeof record.kind === "string" ? `work-queue-record:${publicCoordinateId(record.kind)}` : "unknown-work-queue-record";
926
+ const issue = dataIssue("work-queue-scheduled-readiness-malformed-record", message, {
927
+ subjectId,
928
+ refs: [],
929
+ details: sanitizeGraphVisibleRecord({
930
+ recordKind: typeof record.kind === "string" ? record.kind : void 0,
931
+ queueId: typeof record.queueId === "string" ? publicCoordinateId(record.queueId) : void 0,
932
+ workId: typeof record.workId === "string" ? publicCoordinateId(record.workId) : void 0,
933
+ recordSeq: typeof record.recordSeq === "number" && Number.isFinite(record.recordSeq) ? record.recordSeq : void 0
934
+ })
935
+ });
936
+ return {
937
+ kind: "issue",
938
+ issue,
939
+ status: issueStatus(subjectId, [issue])
940
+ };
941
+ }
942
+ function translateRecord(raw) {
943
+ if (!isRecord(raw)) {
944
+ const issue = dataIssue(
945
+ "work-queue-scheduled-readiness-malformed-record",
946
+ "WorkQueue scheduled readiness requires a graph-visible workQueue record.",
947
+ { subjectId: "unknown-work-queue-record", refs: [] }
948
+ );
949
+ return {
950
+ kind: "issue",
951
+ issue,
952
+ status: issueStatus("unknown-work-queue-record", [issue])
953
+ };
954
+ }
955
+ const unknownRecord = raw;
956
+ const rawRecord = unknownRecord;
957
+ switch (rawRecord.kind) {
958
+ case "work-admitted": {
959
+ const notBeforeMs = rawRecord.notBeforeMs;
960
+ if (notBeforeMs === void 0) return { kind: "none" };
961
+ if (typeof notBeforeMs !== "number") {
962
+ return malformedRecord(rawRecord, "Delayed work-admitted notBeforeMs must be a number.");
963
+ }
964
+ if (!hasWorkRecordCoordinates(rawRecord)) {
965
+ return malformedRecord(
966
+ rawRecord,
967
+ "Delayed work-admitted records require queueId, workId, and recordSeq."
968
+ );
969
+ }
970
+ const admitted = rawRecord;
971
+ return scheduleFromRecord(admitted, {
972
+ scheduleKind: "work-admitted",
973
+ scheduleId: workQueueScheduleId(admitted, "admission", admitted.recordSeq),
974
+ readyAtMs: notBeforeMs,
975
+ deadlineMs: admitted.deadlineMs,
976
+ reason: "work-queue-delayed-admission"
977
+ });
978
+ }
979
+ case "work-scheduled": {
980
+ if (!hasWorkRecordCoordinates(rawRecord)) {
981
+ return malformedRecord(
982
+ rawRecord,
983
+ "work-scheduled records require queueId, workId, and recordSeq."
984
+ );
985
+ }
986
+ const scheduled = rawRecord;
987
+ return scheduleFromRecord(scheduled, {
988
+ scheduleKind: "work-scheduled",
989
+ scheduleId: workQueueScheduleId(
990
+ scheduled,
991
+ "schedule",
992
+ scheduled.scheduleId ?? scheduled.commandId ?? scheduled.recordSeq
993
+ ),
994
+ readyAtMs: scheduled.notBeforeMs,
995
+ deadlineMs: scheduled.deadlineMs,
996
+ reason: scheduled.reason ?? "work-queue-schedule"
997
+ });
998
+ }
999
+ case "retry-scheduled": {
1000
+ if (!hasWorkRecordCoordinates(rawRecord)) {
1001
+ return malformedRecord(
1002
+ rawRecord,
1003
+ "retry-scheduled records require queueId, workId, and recordSeq."
1004
+ );
1005
+ }
1006
+ const retry = rawRecord;
1007
+ return scheduleFromRecord(retry, {
1008
+ scheduleKind: "retry-scheduled",
1009
+ scheduleId: workQueueScheduleId(retry, "retry", retry.commandId ?? retry.recordSeq),
1010
+ readyAtMs: retry.retryAtMs,
1011
+ reason: retry.reason ?? "work-queue-retry",
1012
+ metadata: { delayMs: retry.delayMs }
1013
+ });
1014
+ }
1015
+ case "work-claimed": {
1016
+ if (!hasLeaseRecordCoordinates(rawRecord)) {
1017
+ return malformedRecord(
1018
+ rawRecord,
1019
+ "work-claimed records require queueId, workId, recordSeq, leaseId, attempt, and workerId."
1020
+ );
1021
+ }
1022
+ const claimed = rawRecord;
1023
+ return scheduleFromRecord(claimed, {
1024
+ scheduleKind: "lease-expiration",
1025
+ scheduleId: workQueueLeaseScheduleId(claimed),
1026
+ readyAtMs: claimed.leaseExpiresAtMs,
1027
+ reason: "work-queue-lease-expiration",
1028
+ leaseId: claimed.leaseId,
1029
+ metadata: { attempt: claimed.attempt }
1030
+ });
1031
+ }
1032
+ case "lease-renewed": {
1033
+ if (!hasLeaseRecordCoordinates(rawRecord)) {
1034
+ return malformedRecord(
1035
+ rawRecord,
1036
+ "lease-renewed records require queueId, workId, recordSeq, leaseId, attempt, and workerId."
1037
+ );
1038
+ }
1039
+ const renewed = rawRecord;
1040
+ return scheduleFromRecord(renewed, {
1041
+ scheduleKind: "lease-expiration",
1042
+ scheduleId: workQueueLeaseScheduleId(renewed),
1043
+ readyAtMs: renewed.leaseExpiresAtMs,
1044
+ reason: "work-queue-lease-expiration",
1045
+ leaseId: renewed.leaseId,
1046
+ metadata: {
1047
+ attempt: renewed.attempt,
1048
+ previousLeaseExpiresAtMs: renewed.previousLeaseExpiresAtMs
1049
+ }
1050
+ });
1051
+ }
1052
+ default:
1053
+ return { kind: "none" };
1054
+ }
1055
+ }
1056
+ function scheduleFromRecord(record, opts) {
1057
+ if (!Number.isFinite(opts.readyAtMs) || !finiteOrUndefined(opts.deadlineMs)) {
1058
+ const refs = recordSourceRefs(record, opts.leaseId);
1059
+ const issue = dataIssue(
1060
+ "work-queue-scheduled-readiness-malformed-record",
1061
+ "WorkQueue delayed eligibility record must carry finite readiness and deadline coordinates.",
1062
+ {
1063
+ subjectId: workQueueRecordSubjectId(record),
1064
+ refs,
1065
+ details: {
1066
+ recordKind: record.kind,
1067
+ readyAtMs: opts.readyAtMs,
1068
+ deadlineMs: opts.deadlineMs
1069
+ }
1070
+ }
1071
+ );
1072
+ return {
1073
+ kind: "issue",
1074
+ issue,
1075
+ status: issueStatus(opts.scheduleId, [issue], record, refs)
1076
+ };
1077
+ }
1078
+ const subjectRefs = recordSubjectRefs(record, opts.leaseId);
1079
+ const sourceRefs = recordSourceRefs(record, opts.leaseId);
1080
+ const recordPolicyRefs = policyRefs(record);
1081
+ const metadata = sanitizeGraphVisibleRecord({
1082
+ queueId: publicCoordinateId(record.queueId),
1083
+ workId: publicCoordinateId(record.workId),
1084
+ recordSeq: record.recordSeq,
1085
+ recordKind: record.kind,
1086
+ scheduleKind: opts.scheduleKind,
1087
+ ...record.commandId === void 0 ? {} : { commandId: publicCoordinateId(record.commandId) },
1088
+ ...opts.leaseId === void 0 ? {} : { leaseId: publicCoordinateId(opts.leaseId) },
1089
+ ...opts.metadata ?? {}
1090
+ });
1091
+ const schedule = Object.freeze({
1092
+ kind: "scheduled-readiness-requested",
1093
+ scheduleId: opts.scheduleId,
1094
+ subjectRefs,
1095
+ readyAtMs: opts.readyAtMs,
1096
+ ...opts.deadlineMs === void 0 ? {} : { deadlineMs: opts.deadlineMs },
1097
+ reason: opts.reason,
1098
+ ...recordPolicyRefs === void 0 ? {} : { policyRefs: recordPolicyRefs },
1099
+ sourceRefs,
1100
+ ...metadata === void 0 ? {} : { metadata }
1101
+ });
1102
+ return {
1103
+ kind: "translated",
1104
+ record,
1105
+ schedule,
1106
+ status: Object.freeze({
1107
+ kind: "work-queue-scheduled-readiness-status",
1108
+ statusId: `${opts.scheduleId}:work-queue-scheduled-readiness-status:translated`,
1109
+ queueId: publicCoordinateId(record.queueId),
1110
+ workId: publicCoordinateId(record.workId),
1111
+ recordSeq: record.recordSeq,
1112
+ state: "translated",
1113
+ scheduleKind: opts.scheduleKind,
1114
+ scheduleId: opts.scheduleId,
1115
+ readyAtMs: opts.readyAtMs,
1116
+ ...opts.deadlineMs === void 0 ? {} : { deadlineMs: opts.deadlineMs },
1117
+ sourceRefs,
1118
+ ...metadata === void 0 ? {} : { metadata }
1119
+ })
1120
+ };
1121
+ }
1122
+ function recordSubjectRefs(record, leaseId) {
1123
+ return canonicalPublicSourceRefs(
1124
+ uniqueSourceRefs([
1125
+ ref("work-queue", publicCoordinateId(record.queueId)),
1126
+ ref("work-queue-work", publicCoordinateId(record.workId)),
1127
+ ref("work-queue-record", String(record.recordSeq)),
1128
+ ...record.commandId === void 0 ? [] : [ref("work-queue-command", publicCoordinateId(record.commandId))],
1129
+ ...leaseId === void 0 ? [] : [ref("work-queue-lease", publicCoordinateId(leaseId))]
1130
+ ])
1131
+ );
1132
+ }
1133
+ function recordSourceRefs(record, leaseId) {
1134
+ return canonicalPublicSourceRefs(
1135
+ uniqueSourceRefs([
1136
+ ref("work-queue", publicCoordinateId(record.queueId)),
1137
+ ref("work-queue-record", String(record.recordSeq)),
1138
+ ...record.workId === void 0 ? [] : [ref("work-queue-work", publicCoordinateId(record.workId))],
1139
+ ...record.commandId === void 0 ? [] : [ref("work-queue-command", publicCoordinateId(record.commandId))],
1140
+ ...leaseId === void 0 ? [] : [ref("work-queue-lease", publicCoordinateId(leaseId))],
1141
+ ...copiedPublicRefs(record.sourceRefs, "work-queue-source-ref")
1142
+ ])
1143
+ );
1144
+ }
1145
+ function policyRefs(record) {
1146
+ if (record.policyRefs === void 0 || record.policyRefs.length === 0) return void 0;
1147
+ return canonicalPublicSourceRefs(copiedPublicRefs(record.policyRefs, "work-queue-policy-ref"));
1148
+ }
1149
+ function workQueueScheduleId(record, part, id) {
1150
+ return `workQueue:${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:${part}:${publicCoordinateId(String(id))}`;
1151
+ }
1152
+ function workQueueLeaseScheduleId(record) {
1153
+ return `workQueue:${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:lease:${publicCoordinateId(record.leaseId)}:expires:${record.recordSeq}`;
1154
+ }
1155
+ function workQueueRecordSubjectId(record) {
1156
+ return `${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:${record.recordSeq}`;
1157
+ }
1158
+ function copiedPublicRefs(ids, kind) {
1159
+ if (ids === void 0 || ids.length === 0) return [];
1160
+ const copied = ids.slice(0, MAX_COPIED_PUBLIC_REFS).map((id) => ref(kind, publicCoordinateId(id)));
1161
+ if (ids.length <= MAX_COPIED_PUBLIC_REFS) return copied;
1162
+ return [
1163
+ ...copied,
1164
+ ref(
1165
+ `${kind}-overflow`,
1166
+ `count:${ids.length}:hash:${stableStringHash(stableJsonStringify(ids))}`
1167
+ )
1168
+ ];
1169
+ }
1170
+ function publicCoordinateId(id) {
1171
+ if (id.length <= MAX_PUBLIC_COORDINATE_ID_CHARS && !PRIVATE_COORDINATE_PATTERN.test(id)) {
1172
+ return id;
1173
+ }
1174
+ return `bounded:${stableStringHash(id)}:${id.length}`;
1175
+ }
1176
+ function issueStatus(statusId, issues, record, sourceRefs) {
1177
+ return Object.freeze({
1178
+ kind: "work-queue-scheduled-readiness-status",
1179
+ statusId: `${statusId}:work-queue-scheduled-readiness-status:issue`,
1180
+ ...record?.queueId === void 0 ? {} : { queueId: publicCoordinateId(record.queueId) },
1181
+ ...record?.workId === void 0 ? {} : { workId: publicCoordinateId(record.workId) },
1182
+ ...record?.recordSeq === void 0 ? {} : { recordSeq: record.recordSeq },
1183
+ state: "issue",
1184
+ ...sourceRefs === void 0 ? {} : { sourceRefs },
1185
+ issueCodes: issues.map((issue) => issue.code)
1186
+ });
1187
+ }
1188
+ function finiteOrUndefined(value) {
1189
+ return value === void 0 || Number.isFinite(value);
1190
+ }
1191
+ function scheduleIdentity(schedule) {
1192
+ return stableJsonStringify({
1193
+ scheduleId: schedule.scheduleId,
1194
+ subjectRefs: schedule.subjectRefs,
1195
+ readyAtMs: schedule.readyAtMs,
1196
+ deadlineMs: schedule.deadlineMs,
1197
+ reason: schedule.reason,
1198
+ policyRefs: schedule.policyRefs,
1199
+ sourceRefs: schedule.sourceRefs,
1200
+ metadata: schedule.metadata
1201
+ });
1202
+ }
1203
+ function emitScheduleConflict(ctx, state, translated, existing) {
1204
+ const issue = dataIssue(
1205
+ "work-queue-scheduled-readiness-schedule-conflict",
1206
+ "WorkQueue delayed eligibility replayed with conflicting scheduled-readiness material; the first schedule was retained.",
1207
+ {
1208
+ subjectId: translated.schedule.scheduleId,
1209
+ refs: translated.schedule.sourceRefs,
1210
+ details: {
1211
+ existingReadyAtMs: existing?.readyAtMs,
1212
+ incomingReadyAtMs: translated.schedule.readyAtMs,
1213
+ existingDeadlineMs: existing?.deadlineMs,
1214
+ incomingDeadlineMs: translated.schedule.deadlineMs,
1215
+ recordSeq: translated.record.recordSeq,
1216
+ recordKind: translated.record.kind
1217
+ }
1218
+ }
1219
+ );
1220
+ emitIssue(ctx, state, issue);
1221
+ emitStatus(
1222
+ ctx,
1223
+ state,
1224
+ issueStatus(
1225
+ `${translated.schedule.scheduleId}:conflict:${translated.record.recordSeq}`,
1226
+ [issue],
1227
+ translated.record,
1228
+ translated.schedule.sourceRefs
1229
+ )
1230
+ );
1231
+ }
1232
+ function emitSchedule(ctx, state, schedule) {
1233
+ const key = `schedule:${schedule.scheduleId}`;
1234
+ if (state.emittedKeys.has(key)) return;
1235
+ state.emittedKeys.add(key);
1236
+ ctx.down([["DATA", { kind: "readiness-schedule", schedule }]]);
1237
+ }
1238
+ function emitStatus(ctx, state, status) {
1239
+ state.statusById.set(status.statusId, status);
1240
+ const key = `status:${status.statusId}:${(status.issueCodes ?? []).join(",")}`;
1241
+ if (state.emittedKeys.has(key)) return;
1242
+ state.emittedKeys.add(key);
1243
+ ctx.down([["DATA", { kind: "status", status }]]);
1244
+ }
1245
+ function emitIssue(ctx, state, issue) {
1246
+ const key = `${issue.code}:${issue.subjectId ?? ""}:${JSON.stringify(issue.details ?? {})}`;
1247
+ if (state.issueKeys.has(key)) return;
1248
+ state.issueKeys.add(key);
1249
+ ctx.down([["DATA", { kind: "issue", issue }]]);
1250
+ }
1251
+ function emitAudit(ctx, state, kind, opts) {
1252
+ state.auditSeq += 1;
1253
+ const metadata = sanitizeGraphVisibleRecord(opts.metadata);
1254
+ ctx.down([
1255
+ [
1256
+ "DATA",
1257
+ {
1258
+ kind: "audit",
1259
+ audit: Object.freeze({
1260
+ id: `work-queue-scheduled-readiness-audit-${state.auditSeq}`,
1261
+ kind,
1262
+ subjectId: opts.subjectId,
1263
+ ...opts.sourceRefs === void 0 ? {} : { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) },
1264
+ ...metadata === void 0 ? {} : { metadata }
1265
+ })
1266
+ }
1267
+ ]
1268
+ ]);
1269
+ }
1270
+ function buildViews(state) {
1271
+ return Object.freeze({
1272
+ schedulesById: new Map(state.schedulesById),
1273
+ statusById: new Map(state.statusById)
1274
+ });
1275
+ }
1276
+
1277
+ // src/orchestration/work-queue.ts
1278
+ function orchestrationWorkQueueRecipe(graph, opts) {
1279
+ const name = opts.name ?? "orchestrationWorkQueue";
1280
+ const submitCommands = opts.effectRequests === void 0 ? void 0 : graph.node(
1281
+ [opts.effectRequests],
1282
+ (ctx) => {
1283
+ for (const raw of depBatch(ctx, 0) ?? []) {
1284
+ ctx.down([
1285
+ ["DATA", processEffectSubmitCommand(raw)]
1286
+ ]);
1287
+ }
1288
+ },
1289
+ {
1290
+ name: `${name}/submitCommands`,
1291
+ factory: "orchestrationWorkQueueSubmitCommands",
1292
+ completeWhenDepsComplete: false,
1293
+ errorWhenDepsError: false
1294
+ }
1295
+ );
1296
+ const runtime = graph.node(
1297
+ [opts.records],
1298
+ (ctx) => {
1299
+ const state = ctx.state.get() ?? {
1300
+ payloads: /* @__PURE__ */ new Map(),
1301
+ terminalRecords: /* @__PURE__ */ new Set(),
1302
+ auditSeq: 0
1303
+ };
1304
+ for (const raw of depBatch(ctx, 0) ?? []) {
1305
+ reduceRecord(ctx, state, raw);
1306
+ }
1307
+ ctx.state.set(state);
1308
+ },
1309
+ {
1310
+ name: `${name}/runtime`,
1311
+ factory: "orchestrationWorkQueueRuntime",
1312
+ partial: true,
1313
+ completeWhenDepsComplete: false,
1314
+ errorWhenDepsError: false
1315
+ }
1316
+ );
1317
+ return {
1318
+ ...submitCommands === void 0 ? {} : { submitCommands },
1319
+ evidence: project(
1320
+ graph,
1321
+ runtime,
1322
+ `${name}/evidence`,
1323
+ "orchestrationWorkQueueEvidence",
1324
+ (fact) => fact.kind === "evidence" ? fact.evidence : void 0
1325
+ ),
1326
+ status: project(
1327
+ graph,
1328
+ runtime,
1329
+ `${name}/status`,
1330
+ "orchestrationWorkQueueStatus",
1331
+ (fact) => fact.kind === "status" ? fact.status : void 0
1332
+ ),
1333
+ issues: project(
1334
+ graph,
1335
+ runtime,
1336
+ `${name}/issues`,
1337
+ "orchestrationWorkQueueIssues",
1338
+ (fact) => fact.kind === "issue" ? fact.issue : void 0
1339
+ ),
1340
+ audit: project(
1341
+ graph,
1342
+ runtime,
1343
+ `${name}/audit`,
1344
+ "orchestrationWorkQueueAudit",
1345
+ (fact) => fact.kind === "audit" ? fact.audit : void 0
1346
+ )
1347
+ };
1348
+ }
1349
+ function processEffectSubmitCommand(effect, opts = {}) {
1350
+ const payload = {
1351
+ kind: "orchestration-queued-effect",
1352
+ effect,
1353
+ idempotencyKey: opts.idempotencyKey ?? effect.id,
1354
+ sourceRefs: opts.sourceRefs,
1355
+ policyRefs: opts.policyRefs,
1356
+ metadata: opts.metadata
1357
+ };
1358
+ return {
1359
+ kind: "submit",
1360
+ commandId: opts.commandId ?? `${effect.id}:orchestration-work-queue-submit`,
1361
+ workId: opts.workId ?? `process-effect:${effect.id}`,
1362
+ payload,
1363
+ idempotencyKey: opts.idempotencyKey ?? effect.id,
1364
+ sourceRefs: opts.sourceRefs,
1365
+ policyRefs: opts.policyRefs
1366
+ };
1367
+ }
1368
+ function reduceRecord(ctx, state, record) {
1369
+ if (record.kind === "work-admitted") {
1370
+ if (isQueuedEffectPayload(record.payload)) {
1371
+ state.payloads.set(record.workId, record.payload);
1372
+ } else {
1373
+ emitIssue2(ctx, state, record, "orchestration-queue-malformed-payload");
1374
+ }
1375
+ return;
1376
+ }
1377
+ if (!isTerminalEvidenceRecord(record)) return;
1378
+ const key = `${record.kind}:${record.recordSeq}`;
1379
+ if (state.terminalRecords.has(key)) return;
1380
+ state.terminalRecords.add(key);
1381
+ const payload = record.workId === void 0 ? void 0 : state.payloads.get(record.workId);
1382
+ if (payload === void 0) {
1383
+ emitIssue2(ctx, state, record, "orchestration-queue-record-without-payload");
1384
+ return;
1385
+ }
1386
+ const evidence = evidenceFromRecord(record, payload);
1387
+ emit(ctx, { kind: "evidence", evidence });
1388
+ emit(ctx, { kind: "status", status: statusFromEvidence(evidence, payload) });
1389
+ state.auditSeq += 1;
1390
+ emit(ctx, { kind: "audit", audit: auditFromEvidence(state.auditSeq, evidence, payload) });
1391
+ }
1392
+ function isTerminalEvidenceRecord(record) {
1393
+ return record.kind === "work-completed" || record.kind === "attempt-completed" || record.kind === "work-canceled" || record.kind === "work-dead-lettered" || record.kind === "attempt-failed";
1394
+ }
1395
+ function evidenceFromRecord(record, payload) {
1396
+ return {
1397
+ kind: "orchestration-queue-evidence",
1398
+ evidenceId: `work-queue:${record.recordSeq}`,
1399
+ effectId: payload.effect.id,
1400
+ effectType: payload.effect.type,
1401
+ workId: record.workId ?? `unknown:${record.recordSeq}`,
1402
+ queueRecordKind: record.kind,
1403
+ result: "result" in record ? record.result : void 0,
1404
+ error: "error" in record ? record.error : void 0,
1405
+ recordedAtMs: record.recordedAtMs
1406
+ };
1407
+ }
1408
+ function statusFromEvidence(evidence, payload) {
1409
+ return {
1410
+ kind: "orchestration-queue-status",
1411
+ state: "evidence-recorded",
1412
+ effectId: payload.effect.id,
1413
+ effectType: payload.effect.type,
1414
+ workId: evidence.workId,
1415
+ queueRecordKind: evidence.queueRecordKind,
1416
+ evidenceId: evidence.evidenceId
1417
+ };
1418
+ }
1419
+ function auditFromEvidence(seq, evidence, payload) {
1420
+ return {
1421
+ kind: "orchestration-queue-audit",
1422
+ seq,
1423
+ outcome: "mapped",
1424
+ effectId: payload.effect.id,
1425
+ effectType: payload.effect.type,
1426
+ workId: evidence.workId,
1427
+ queueRecordKind: evidence.queueRecordKind,
1428
+ evidenceId: evidence.evidenceId
1429
+ };
1430
+ }
1431
+ function auditFromIssue(seq, record) {
1432
+ return {
1433
+ kind: "orchestration-queue-audit",
1434
+ seq,
1435
+ outcome: "issue",
1436
+ workId: record.workId,
1437
+ queueRecordKind: record.kind
1438
+ };
1439
+ }
1440
+ function project(graph, runtime, name, factory, pick) {
1441
+ return graph.node(
1442
+ [runtime],
1443
+ (ctx) => {
1444
+ for (const fact of depBatch(ctx, 0) ?? []) {
1445
+ const value = pick(fact);
1446
+ if (value !== void 0) ctx.down([["DATA", value]]);
1447
+ }
1448
+ },
1449
+ { name, factory, partial: true, completeWhenDepsComplete: false, errorWhenDepsError: false }
1450
+ );
1451
+ }
1452
+ function emit(ctx, fact) {
1453
+ ctx.down([["DATA", fact]]);
1454
+ }
1455
+ function emitIssue2(ctx, state, record, code) {
1456
+ const issue = queueIssue(record, code);
1457
+ emit(ctx, { kind: "issue", issue });
1458
+ state.auditSeq += 1;
1459
+ emit(ctx, {
1460
+ kind: "status",
1461
+ status: {
1462
+ kind: "orchestration-queue-status",
1463
+ state: "mapping-issue",
1464
+ workId: record.workId,
1465
+ queueRecordKind: record.kind,
1466
+ issues: [issue]
1467
+ }
1468
+ });
1469
+ emit(ctx, {
1470
+ kind: "audit",
1471
+ audit: auditFromIssue(state.auditSeq, record)
1472
+ });
1473
+ }
1474
+ function queueIssue(record, code) {
1475
+ return {
1476
+ kind: "issue",
1477
+ code,
1478
+ message: `Orchestration workQueue recipe could not map record '${record.kind}'`,
1479
+ severity: "error",
1480
+ source: "orchestration.workQueue",
1481
+ details: record
1482
+ };
1483
+ }
1484
+ function isQueuedEffectPayload(value) {
1485
+ if (!isObjectRecord(value) || value.kind !== "orchestration-queued-effect") return false;
1486
+ const effect = value.effect;
1487
+ return isObjectRecord(effect) && typeof effect.id === "string" && typeof effect.type === "string";
1488
+ }
1489
+ function isObjectRecord(value) {
1490
+ return typeof value === "object" && value !== null;
1491
+ }
1492
+ // Annotate the CommonJS export names for ESM import in node:
1493
+ 0 && (module.exports = {
1494
+ orchestrationWorkQueueRecipe,
1495
+ processEffectSubmitCommand,
1496
+ workQueueLeaseExpirationCommandProjector,
1497
+ workQueueReadinessHandoffProjector,
1498
+ workQueueScheduledReadinessProjector
1499
+ });
1500
+ //# sourceMappingURL=work-queue.cjs.map