@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,1289 @@
1
+ import {
2
+ canonicalPublicSourceRefs,
3
+ dataIssue,
4
+ isRecord,
5
+ projectRuntimeFact,
6
+ ref,
7
+ sanitizeGraphVisibleRecord,
8
+ stableJsonStringify,
9
+ stableStringHash,
10
+ uniqueSourceRefs
11
+ } from "../chunk-TQPCAIQI.js";
12
+ import {
13
+ depBatch
14
+ } from "../chunk-WQIA3GFB.js";
15
+ import "../chunk-S6HXABGL.js";
16
+ import "../chunk-DGUM43GV.js";
17
+
18
+ // src/orchestration/work-queue-scheduled-readiness.ts
19
+ var MAX_PUBLIC_COORDINATE_ID_CHARS = 160;
20
+ var MAX_COPIED_PUBLIC_REFS = 16;
21
+ var PRIVATE_COORDINATE_PATTERN = /(api[_-]?key|authorization|bearer|credential|oauth|password|private[_-]?key|secret|session[_-]?cookie|token)/i;
22
+ function workQueueScheduledReadinessProjector(graph, opts) {
23
+ const name = opts.name ?? "workQueueScheduledReadiness";
24
+ const runtime = graph.node(
25
+ [opts.records],
26
+ (ctx) => {
27
+ const state = ctx.state.get() ?? initialState();
28
+ for (const raw of depBatch(ctx, 0) ?? []) {
29
+ const translated = translateRecord(raw);
30
+ if (translated.kind === "none") continue;
31
+ if (translated.kind === "issue") {
32
+ emitIssue(ctx, state, translated.issue);
33
+ emitStatus(ctx, state, translated.status);
34
+ continue;
35
+ }
36
+ const identity = scheduleIdentity(translated.schedule);
37
+ const recordKey = `${translated.record.queueId}:${translated.record.recordSeq}`;
38
+ const existingRecordIdentity = state.recordScheduleIdentityByKey.get(recordKey);
39
+ if (existingRecordIdentity !== void 0) {
40
+ if (existingRecordIdentity !== identity) emitScheduleConflict(ctx, state, translated);
41
+ continue;
42
+ }
43
+ state.recordScheduleIdentityByKey.set(recordKey, identity);
44
+ const existing = state.schedulesById.get(translated.schedule.scheduleId);
45
+ if (existing !== void 0) {
46
+ if (scheduleIdentity(existing) !== identity) {
47
+ emitScheduleConflict(ctx, state, translated, existing);
48
+ }
49
+ continue;
50
+ }
51
+ state.schedulesById.set(translated.schedule.scheduleId, translated.schedule);
52
+ emitSchedule(ctx, state, translated.schedule);
53
+ emitStatus(ctx, state, translated.status);
54
+ emitAudit(ctx, state, "work-queue-scheduled-readiness-translated", {
55
+ subjectId: translated.schedule.scheduleId,
56
+ sourceRefs: translated.schedule.sourceRefs,
57
+ metadata: {
58
+ queueId: publicCoordinateId(translated.record.queueId),
59
+ workId: publicCoordinateId(translated.record.workId),
60
+ recordSeq: translated.record.recordSeq,
61
+ recordKind: translated.record.kind,
62
+ readyAtMs: translated.schedule.readyAtMs
63
+ }
64
+ });
65
+ }
66
+ ctx.down([["DATA", { kind: "views", views: buildViews(state) }]]);
67
+ ctx.state.set(state);
68
+ },
69
+ {
70
+ name: `${name}/runtime`,
71
+ factory: "workQueueScheduledReadinessProjector",
72
+ partial: true,
73
+ completeWhenDepsComplete: false,
74
+ errorWhenDepsError: false
75
+ }
76
+ );
77
+ return {
78
+ readinessSchedules: projectRuntimeFact(
79
+ graph,
80
+ runtime,
81
+ `${name}/readinessSchedules`,
82
+ "workQueueScheduledReadinessSchedules",
83
+ (fact) => fact.kind === "readiness-schedule" ? fact.schedule : void 0
84
+ ),
85
+ status: projectRuntimeFact(
86
+ graph,
87
+ runtime,
88
+ `${name}/status`,
89
+ "workQueueScheduledReadinessStatus",
90
+ (fact) => fact.kind === "status" ? fact.status : void 0
91
+ ),
92
+ issues: projectRuntimeFact(
93
+ graph,
94
+ runtime,
95
+ `${name}/issues`,
96
+ "workQueueScheduledReadinessIssues",
97
+ (fact) => fact.kind === "issue" ? fact.issue : void 0
98
+ ),
99
+ audit: projectRuntimeFact(
100
+ graph,
101
+ runtime,
102
+ `${name}/audit`,
103
+ "workQueueScheduledReadinessAudit",
104
+ (fact) => fact.kind === "audit" ? fact.audit : void 0
105
+ ),
106
+ views: projectRuntimeFact(
107
+ graph,
108
+ runtime,
109
+ `${name}/views`,
110
+ "workQueueScheduledReadinessViews",
111
+ (fact) => fact.kind === "views" ? fact.views : void 0
112
+ )
113
+ };
114
+ }
115
+ function workQueueReadinessHandoffProjector(graph, opts) {
116
+ const name = opts.name ?? "workQueueReadinessHandoff";
117
+ const deps = opts.overdue === void 0 ? [opts.records, opts.ready] : [opts.records, opts.ready, opts.overdue];
118
+ const runtime = graph.node(
119
+ deps,
120
+ (ctx) => {
121
+ const state = ctx.state.get() ?? handoffState();
122
+ for (const raw of depBatch(ctx, 0) ?? []) {
123
+ const record = raw;
124
+ ingestWorkQueueRecord(state, record);
125
+ }
126
+ for (const raw of depBatch(ctx, 1) ?? []) {
127
+ const ready = raw;
128
+ state.readyByScheduleId.set(ready.scheduleId, ready);
129
+ }
130
+ if (opts.overdue !== void 0) {
131
+ for (const raw of depBatch(ctx, 2) ?? []) {
132
+ emitOverdueHandoffStatus(ctx, state, raw);
133
+ }
134
+ }
135
+ evaluateReadyHandoffs(ctx, state);
136
+ ctx.down([["DATA", { kind: "views", views: buildHandoffViews(state) }]]);
137
+ ctx.state.set(state);
138
+ },
139
+ {
140
+ name: `${name}/runtime`,
141
+ factory: "workQueueReadinessHandoffProjector",
142
+ partial: true,
143
+ completeWhenDepsComplete: false,
144
+ errorWhenDepsError: false
145
+ }
146
+ );
147
+ return {
148
+ candidates: projectRuntimeFact(
149
+ graph,
150
+ runtime,
151
+ `${name}/candidates`,
152
+ "workQueueReadinessHandoffCandidates",
153
+ (fact) => fact.kind === "candidate" ? fact.candidate : void 0
154
+ ),
155
+ status: projectRuntimeFact(
156
+ graph,
157
+ runtime,
158
+ `${name}/status`,
159
+ "workQueueReadinessHandoffStatus",
160
+ (fact) => fact.kind === "status" ? fact.status : void 0
161
+ ),
162
+ issues: projectRuntimeFact(
163
+ graph,
164
+ runtime,
165
+ `${name}/issues`,
166
+ "workQueueReadinessHandoffIssues",
167
+ (fact) => fact.kind === "issue" ? fact.issue : void 0
168
+ ),
169
+ audit: projectRuntimeFact(
170
+ graph,
171
+ runtime,
172
+ `${name}/audit`,
173
+ "workQueueReadinessHandoffAudit",
174
+ (fact) => fact.kind === "audit" ? fact.audit : void 0
175
+ ),
176
+ views: projectRuntimeFact(
177
+ graph,
178
+ runtime,
179
+ `${name}/views`,
180
+ "workQueueReadinessHandoffViews",
181
+ (fact) => fact.kind === "views" ? fact.views : void 0
182
+ )
183
+ };
184
+ }
185
+ function workQueueLeaseExpirationCommandProjector(graph, opts) {
186
+ const name = opts.name ?? "workQueueLeaseExpirationCommands";
187
+ const runtime = graph.node(
188
+ [opts.candidates],
189
+ (ctx) => {
190
+ const state = ctx.state.get() ?? leaseExpirationCommandState();
191
+ for (const raw of depBatch(ctx, 0) ?? []) {
192
+ const candidate = raw;
193
+ if (candidate.candidateKind !== "lease-expiration-eligible") continue;
194
+ if (state.commandByCandidateId.has(candidate.candidateId)) continue;
195
+ const command = Object.freeze({
196
+ kind: "expire-leases",
197
+ commandId: `${candidate.candidateId}:expire-leases`,
198
+ queueId: candidate.queueId,
199
+ workIds: [candidate.workId],
200
+ limit: 1,
201
+ nowMs: candidate.nowMs,
202
+ causationId: candidate.scheduleId,
203
+ ...sourceRefStrings(candidate.sourceRefs) === void 0 ? {} : { sourceRefs: sourceRefStrings(candidate.sourceRefs) }
204
+ });
205
+ state.commandByCandidateId.set(candidate.candidateId, command);
206
+ ctx.down([["DATA", { kind: "command", command }]]);
207
+ emitLeaseCommandStatus(ctx, state, command, candidate);
208
+ }
209
+ ctx.down([["DATA", { kind: "views", views: buildLeaseCommandViews(state) }]]);
210
+ ctx.state.set(state);
211
+ },
212
+ {
213
+ name: `${name}/runtime`,
214
+ factory: "workQueueLeaseExpirationCommandProjector",
215
+ partial: true,
216
+ completeWhenDepsComplete: false,
217
+ errorWhenDepsError: false
218
+ }
219
+ );
220
+ return {
221
+ commands: projectRuntimeFact(
222
+ graph,
223
+ runtime,
224
+ `${name}/commands`,
225
+ "workQueueLeaseExpirationCommands",
226
+ (fact) => fact.kind === "command" ? fact.command : void 0
227
+ ),
228
+ status: projectRuntimeFact(
229
+ graph,
230
+ runtime,
231
+ `${name}/status`,
232
+ "workQueueLeaseExpirationCommandStatus",
233
+ (fact) => fact.kind === "status" ? fact.status : void 0
234
+ ),
235
+ views: projectRuntimeFact(
236
+ graph,
237
+ runtime,
238
+ `${name}/views`,
239
+ "workQueueLeaseExpirationCommandViews",
240
+ (fact) => fact.kind === "views" ? fact.views : void 0
241
+ )
242
+ };
243
+ }
244
+ function initialState() {
245
+ return {
246
+ recordScheduleIdentityByKey: /* @__PURE__ */ new Map(),
247
+ schedulesById: /* @__PURE__ */ new Map(),
248
+ statusById: /* @__PURE__ */ new Map(),
249
+ emittedKeys: /* @__PURE__ */ new Set(),
250
+ issueKeys: /* @__PURE__ */ new Set(),
251
+ auditSeq: 0
252
+ };
253
+ }
254
+ function handoffState() {
255
+ return {
256
+ originsByScheduleId: /* @__PURE__ */ new Map(),
257
+ worksById: /* @__PURE__ */ new Map(),
258
+ readyByScheduleId: /* @__PURE__ */ new Map(),
259
+ candidatesById: /* @__PURE__ */ new Map(),
260
+ statusById: /* @__PURE__ */ new Map(),
261
+ emittedKeys: /* @__PURE__ */ new Set(),
262
+ issueKeys: /* @__PURE__ */ new Set(),
263
+ auditSeq: 0
264
+ };
265
+ }
266
+ function leaseExpirationCommandState() {
267
+ return {
268
+ commandByCandidateId: /* @__PURE__ */ new Map(),
269
+ statusById: /* @__PURE__ */ new Map(),
270
+ emittedKeys: /* @__PURE__ */ new Set()
271
+ };
272
+ }
273
+ function ingestWorkQueueRecord(state, record) {
274
+ const translated = translateRecord(record);
275
+ if (translated.kind === "translated") {
276
+ state.originsByScheduleId.set(translated.schedule.scheduleId, {
277
+ record: translated.record,
278
+ schedule: translated.schedule,
279
+ scheduleKind: translated.status.scheduleKind
280
+ });
281
+ }
282
+ if (record.workId === void 0) return;
283
+ const recordWithWorkId = record;
284
+ const existing = state.worksById.get(
285
+ handoffWorkKey(recordWithWorkId.queueId, recordWithWorkId.workId)
286
+ );
287
+ if (existing !== void 0 && recordWithWorkId.recordSeq < existing.latestRecordSeq) return;
288
+ const work = ensureHandoffWorkState(state, recordWithWorkId);
289
+ work.latestRecordSeq = Math.max(work.latestRecordSeq, recordWithWorkId.recordSeq);
290
+ switch (recordWithWorkId.kind) {
291
+ case "work-admitted":
292
+ work.state = recordWithWorkId.notBeforeMs === void 0 ? "ready" : "scheduled";
293
+ work.notBeforeMs = recordWithWorkId.notBeforeMs;
294
+ work.retryAtMs = void 0;
295
+ work.deadlineMs = recordWithWorkId.deadlineMs;
296
+ clearHandoffLease(work);
297
+ break;
298
+ case "work-scheduled":
299
+ work.state = "scheduled";
300
+ work.notBeforeMs = recordWithWorkId.notBeforeMs;
301
+ work.deadlineMs = recordWithWorkId.deadlineMs;
302
+ break;
303
+ case "retry-scheduled":
304
+ work.state = recordWithWorkId.retryAtMs <= recordWithWorkId.recordedAtMs ? "ready" : "retry-wait";
305
+ work.retryAtMs = recordWithWorkId.retryAtMs;
306
+ work.notBeforeMs = void 0;
307
+ break;
308
+ case "work-claimed":
309
+ work.state = "leased";
310
+ work.leaseId = recordWithWorkId.leaseId;
311
+ work.attempt = recordWithWorkId.attempt;
312
+ work.workerId = recordWithWorkId.workerId;
313
+ work.leaseExpiresAtMs = recordWithWorkId.leaseExpiresAtMs;
314
+ break;
315
+ case "lease-renewed":
316
+ work.state = "leased";
317
+ work.leaseId = recordWithWorkId.leaseId;
318
+ work.attempt = recordWithWorkId.attempt;
319
+ work.workerId = recordWithWorkId.workerId;
320
+ work.leaseExpiresAtMs = recordWithWorkId.leaseExpiresAtMs;
321
+ break;
322
+ case "work-released":
323
+ case "lease-expired":
324
+ work.state = "ready";
325
+ clearHandoffLease(work);
326
+ break;
327
+ case "work-completed":
328
+ work.state = "completed";
329
+ clearHandoffLease(work);
330
+ break;
331
+ case "work-canceled":
332
+ work.state = "canceled";
333
+ clearHandoffLease(work);
334
+ break;
335
+ case "work-dead-lettered":
336
+ work.state = "dead-lettered";
337
+ clearHandoffLease(work);
338
+ break;
339
+ }
340
+ }
341
+ function ensureHandoffWorkState(state, record) {
342
+ const key = handoffWorkKey(record.queueId, record.workId);
343
+ const existing = state.worksById.get(key);
344
+ if (existing !== void 0) return existing;
345
+ const next = {
346
+ queueId: record.queueId,
347
+ workId: record.workId,
348
+ state: "ready",
349
+ latestRecordSeq: record.recordSeq
350
+ };
351
+ state.worksById.set(key, next);
352
+ return next;
353
+ }
354
+ function handoffWorkKey(queueId, workId) {
355
+ return stableJsonStringify([queueId, workId]);
356
+ }
357
+ function clearHandoffLease(work) {
358
+ work.leaseId = void 0;
359
+ work.attempt = void 0;
360
+ work.workerId = void 0;
361
+ work.leaseExpiresAtMs = void 0;
362
+ }
363
+ function evaluateReadyHandoffs(ctx, state) {
364
+ for (const ready of state.readyByScheduleId.values()) {
365
+ const origin = state.originsByScheduleId.get(ready.scheduleId);
366
+ if (origin === void 0) {
367
+ emitHandoffStatus(
368
+ ctx,
369
+ state,
370
+ handoffStatus("pending-origin", {
371
+ scheduleId: ready.scheduleId,
372
+ readyAtMs: ready.readyAtMs,
373
+ nowMs: ready.nowMs,
374
+ sourceRefs: ready.sourceRefs
375
+ })
376
+ );
377
+ continue;
378
+ }
379
+ const work = state.worksById.get(handoffWorkKey(origin.record.queueId, origin.record.workId));
380
+ if (work === void 0) {
381
+ emitHandoffStatus(
382
+ ctx,
383
+ state,
384
+ handoffStatus("pending-origin", {
385
+ queueId: origin.record.queueId,
386
+ workId: origin.record.workId,
387
+ scheduleId: ready.scheduleId,
388
+ readyAtMs: ready.readyAtMs,
389
+ nowMs: ready.nowMs,
390
+ sourceRefs: ready.sourceRefs
391
+ })
392
+ );
393
+ continue;
394
+ }
395
+ if (origin.record.recordSeq < work.latestRecordSeq) {
396
+ emitSuperseded(ctx, state, origin, work, ready, {
397
+ latestRecordSeq: work.latestRecordSeq
398
+ });
399
+ continue;
400
+ }
401
+ const terminal = terminalHandoffState(work.state);
402
+ if (terminal) {
403
+ emitHandoffStatus(
404
+ ctx,
405
+ state,
406
+ handoffStatus("ignored-terminal", {
407
+ queueId: work.queueId,
408
+ workId: work.workId,
409
+ scheduleId: ready.scheduleId,
410
+ readyAtMs: ready.readyAtMs,
411
+ nowMs: ready.nowMs,
412
+ currentState: work.state,
413
+ sourceRefs: ready.sourceRefs
414
+ })
415
+ );
416
+ continue;
417
+ }
418
+ if (origin.scheduleKind === "lease-expiration") {
419
+ evaluateLeaseExpirationReady(ctx, state, origin, work, ready);
420
+ continue;
421
+ }
422
+ evaluateClaimEligibilityReady(ctx, state, origin, work, ready);
423
+ }
424
+ }
425
+ function evaluateClaimEligibilityReady(ctx, state, origin, work, ready) {
426
+ if (work.state === "leased") {
427
+ emitHandoffStatus(
428
+ ctx,
429
+ state,
430
+ handoffStatus("ignored-stale", {
431
+ queueId: work.queueId,
432
+ workId: work.workId,
433
+ scheduleId: ready.scheduleId,
434
+ readyAtMs: ready.readyAtMs,
435
+ nowMs: ready.nowMs,
436
+ currentState: work.state,
437
+ sourceRefs: ready.sourceRefs
438
+ })
439
+ );
440
+ return;
441
+ }
442
+ if (work.notBeforeMs !== void 0 && work.notBeforeMs > ready.nowMs) {
443
+ emitSuperseded(ctx, state, origin, work, ready, { notBeforeMs: work.notBeforeMs });
444
+ return;
445
+ }
446
+ if (work.retryAtMs !== void 0 && work.retryAtMs > ready.nowMs) {
447
+ emitSuperseded(ctx, state, origin, work, ready, { retryAtMs: work.retryAtMs });
448
+ return;
449
+ }
450
+ emitCandidate(ctx, state, candidateFor(origin, ready, "claim-eligible"));
451
+ }
452
+ function evaluateLeaseExpirationReady(ctx, state, origin, work, ready) {
453
+ if (origin.record.kind !== "work-claimed" && origin.record.kind !== "lease-renewed") {
454
+ emitHandoffIssue(
455
+ ctx,
456
+ state,
457
+ dataIssue(
458
+ "work-queue-readiness-handoff-malformed-origin",
459
+ "Lease-expiration readiness must originate from a lease-bearing workQueue record.",
460
+ { subjectId: ready.scheduleId, refs: ready.sourceRefs }
461
+ )
462
+ );
463
+ return;
464
+ }
465
+ if (work.state !== "leased" || work.leaseId !== origin.record.leaseId || work.attempt !== origin.record.attempt || work.workerId !== origin.record.workerId) {
466
+ emitHandoffStatus(
467
+ ctx,
468
+ state,
469
+ handoffStatus("ignored-stale", {
470
+ queueId: work.queueId,
471
+ workId: work.workId,
472
+ scheduleId: ready.scheduleId,
473
+ readyAtMs: ready.readyAtMs,
474
+ nowMs: ready.nowMs,
475
+ currentState: work.state,
476
+ sourceRefs: ready.sourceRefs
477
+ })
478
+ );
479
+ return;
480
+ }
481
+ if (work.leaseExpiresAtMs !== origin.record.leaseExpiresAtMs) {
482
+ emitSuperseded(ctx, state, origin, work, ready, {
483
+ leaseExpiresAtMs: work.leaseExpiresAtMs
484
+ });
485
+ return;
486
+ }
487
+ if (work.leaseExpiresAtMs !== void 0 && work.leaseExpiresAtMs > ready.nowMs) {
488
+ emitSuperseded(ctx, state, origin, work, ready, {
489
+ leaseExpiresAtMs: work.leaseExpiresAtMs
490
+ });
491
+ return;
492
+ }
493
+ emitCandidate(ctx, state, candidateFor(origin, ready, "lease-expiration-eligible"));
494
+ }
495
+ function emitSuperseded(ctx, state, origin, work, ready, metadata) {
496
+ emitHandoffStatus(
497
+ ctx,
498
+ state,
499
+ handoffStatus("ignored-superseded", {
500
+ queueId: work.queueId,
501
+ workId: work.workId,
502
+ scheduleId: ready.scheduleId,
503
+ readyAtMs: ready.readyAtMs,
504
+ nowMs: ready.nowMs,
505
+ currentState: work.state,
506
+ sourceRefs: ready.sourceRefs,
507
+ metadata: {
508
+ originRecordSeq: origin.record.recordSeq,
509
+ originRecordKind: origin.record.kind,
510
+ ...metadata
511
+ }
512
+ })
513
+ );
514
+ }
515
+ function candidateFor(origin, ready, candidateKind) {
516
+ const lease = origin.record.kind === "work-claimed" || origin.record.kind === "lease-renewed" ? {
517
+ leaseId: origin.record.leaseId,
518
+ attempt: origin.record.attempt,
519
+ workerId: origin.record.workerId,
520
+ leaseExpiresAtMs: origin.record.leaseExpiresAtMs
521
+ } : {};
522
+ const metadata = sanitizeGraphVisibleRecord({
523
+ originRecordSeq: origin.record.recordSeq,
524
+ originRecordKind: origin.record.kind,
525
+ scheduleKind: origin.scheduleKind
526
+ });
527
+ return Object.freeze({
528
+ kind: "work-queue-readiness-candidate",
529
+ candidateId: `${ready.scheduleId}:work-queue:${candidateKind}`,
530
+ candidateKind,
531
+ queueId: origin.record.queueId,
532
+ workId: origin.record.workId,
533
+ scheduleId: ready.scheduleId,
534
+ readyAtMs: ready.readyAtMs,
535
+ nowMs: ready.nowMs,
536
+ originRecordSeq: origin.record.recordSeq,
537
+ originRecordKind: origin.record.kind,
538
+ ...lease,
539
+ sourceRefs: canonicalPublicSourceRefs(
540
+ uniqueSourceRefs([
541
+ ...ready.sourceRefs ?? [],
542
+ ref("work-queue-record", String(origin.record.recordSeq)),
543
+ ref("scheduled-readiness-ready", ready.scheduleId)
544
+ ])
545
+ ),
546
+ ...metadata === void 0 ? {} : { metadata }
547
+ });
548
+ }
549
+ function emitCandidate(ctx, state, candidate) {
550
+ const key = `candidate:${candidate.candidateId}`;
551
+ if (!state.emittedKeys.has(key)) {
552
+ state.emittedKeys.add(key);
553
+ state.candidatesById.set(candidate.candidateId, candidate);
554
+ ctx.down([["DATA", { kind: "candidate", candidate }]]);
555
+ emitHandoffAudit(ctx, state, "work-queue-readiness-candidate", {
556
+ subjectId: candidate.candidateId,
557
+ sourceRefs: candidate.sourceRefs,
558
+ metadata: {
559
+ candidateKind: candidate.candidateKind,
560
+ queueId: candidate.queueId,
561
+ workId: candidate.workId,
562
+ readyAtMs: candidate.readyAtMs,
563
+ nowMs: candidate.nowMs
564
+ }
565
+ });
566
+ } else {
567
+ state.candidatesById.set(candidate.candidateId, candidate);
568
+ }
569
+ emitHandoffStatus(
570
+ ctx,
571
+ state,
572
+ handoffStatus("candidate", {
573
+ queueId: candidate.queueId,
574
+ workId: candidate.workId,
575
+ scheduleId: candidate.scheduleId,
576
+ candidateId: candidate.candidateId,
577
+ candidateKind: candidate.candidateKind,
578
+ readyAtMs: candidate.readyAtMs,
579
+ nowMs: candidate.nowMs,
580
+ sourceRefs: candidate.sourceRefs
581
+ })
582
+ );
583
+ }
584
+ function emitOverdueHandoffStatus(ctx, state, overdue) {
585
+ const origin = state.originsByScheduleId.get(overdue.scheduleId);
586
+ emitHandoffStatus(
587
+ ctx,
588
+ state,
589
+ handoffStatus("overdue", {
590
+ queueId: origin?.record.queueId,
591
+ workId: origin?.record.workId,
592
+ scheduleId: overdue.scheduleId,
593
+ readyAtMs: overdue.readyAtMs,
594
+ nowMs: overdue.nowMs,
595
+ sourceRefs: overdue.sourceRefs,
596
+ metadata: {
597
+ deadlineMs: overdue.deadlineMs,
598
+ ...origin === void 0 ? {} : { originRecordSeq: origin.record.recordSeq, originRecordKind: origin.record.kind }
599
+ }
600
+ })
601
+ );
602
+ }
603
+ function handoffStatus(state, opts) {
604
+ const subject = opts.candidateId ?? opts.scheduleId ?? "unknown-work-queue-readiness";
605
+ const metadata = sanitizeGraphVisibleRecord(opts.metadata);
606
+ return Object.freeze({
607
+ kind: "work-queue-readiness-handoff-status",
608
+ statusId: `${subject}:work-queue-readiness-handoff-status:${state}`,
609
+ state,
610
+ ...opts.queueId === void 0 ? {} : { queueId: opts.queueId },
611
+ ...opts.workId === void 0 ? {} : { workId: opts.workId },
612
+ ...opts.scheduleId === void 0 ? {} : { scheduleId: opts.scheduleId },
613
+ ...opts.candidateId === void 0 ? {} : { candidateId: opts.candidateId },
614
+ ...opts.candidateKind === void 0 ? {} : { candidateKind: opts.candidateKind },
615
+ ...opts.readyAtMs === void 0 ? {} : { readyAtMs: opts.readyAtMs },
616
+ ...opts.nowMs === void 0 ? {} : { nowMs: opts.nowMs },
617
+ ...opts.currentState === void 0 ? {} : { currentState: opts.currentState },
618
+ ...opts.sourceRefs === void 0 ? {} : { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) },
619
+ ...opts.issueCodes === void 0 ? {} : { issueCodes: opts.issueCodes },
620
+ ...metadata === void 0 ? {} : { metadata }
621
+ });
622
+ }
623
+ function emitHandoffStatus(ctx, state, status) {
624
+ state.statusById.set(status.statusId, status);
625
+ const key = `handoff-status:${status.statusId}:${stableJsonStringify(status)}`;
626
+ if (state.emittedKeys.has(key)) return;
627
+ state.emittedKeys.add(key);
628
+ ctx.down([["DATA", { kind: "status", status }]]);
629
+ }
630
+ function emitHandoffIssue(ctx, state, issue) {
631
+ const key = `${issue.code}:${issue.subjectId ?? ""}:${JSON.stringify(issue.details ?? {})}`;
632
+ if (state.issueKeys.has(key)) return;
633
+ state.issueKeys.add(key);
634
+ ctx.down([["DATA", { kind: "issue", issue }]]);
635
+ emitHandoffStatus(
636
+ ctx,
637
+ state,
638
+ handoffStatus("issue", {
639
+ scheduleId: issue.subjectId,
640
+ sourceRefs: issue.refs?.map(sourceRefFromIssueRef),
641
+ issueCodes: [issue.code]
642
+ })
643
+ );
644
+ }
645
+ function emitHandoffAudit(ctx, state, kind, opts) {
646
+ state.auditSeq += 1;
647
+ const metadata = sanitizeGraphVisibleRecord(opts.metadata);
648
+ ctx.down([
649
+ [
650
+ "DATA",
651
+ {
652
+ kind: "audit",
653
+ audit: Object.freeze({
654
+ id: `work-queue-readiness-handoff-audit-${state.auditSeq}`,
655
+ kind,
656
+ subjectId: opts.subjectId,
657
+ ...opts.sourceRefs === void 0 ? {} : { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) },
658
+ ...metadata === void 0 ? {} : { metadata }
659
+ })
660
+ }
661
+ ]
662
+ ]);
663
+ }
664
+ function buildHandoffViews(state) {
665
+ return Object.freeze({
666
+ candidatesById: new Map(state.candidatesById),
667
+ statusById: new Map(state.statusById)
668
+ });
669
+ }
670
+ function emitLeaseCommandStatus(ctx, state, command, candidate) {
671
+ const status = handoffStatus("candidate", {
672
+ queueId: candidate.queueId,
673
+ workId: candidate.workId,
674
+ scheduleId: candidate.scheduleId,
675
+ candidateId: candidate.candidateId,
676
+ candidateKind: candidate.candidateKind,
677
+ readyAtMs: candidate.readyAtMs,
678
+ nowMs: candidate.nowMs,
679
+ sourceRefs: candidate.sourceRefs,
680
+ metadata: {
681
+ commandId: command.commandId,
682
+ commandKind: command.kind
683
+ }
684
+ });
685
+ state.statusById.set(status.statusId, status);
686
+ const key = `lease-command-status:${status.statusId}`;
687
+ if (state.emittedKeys.has(key)) return;
688
+ state.emittedKeys.add(key);
689
+ ctx.down([["DATA", { kind: "status", status }]]);
690
+ }
691
+ function buildLeaseCommandViews(state) {
692
+ return Object.freeze({
693
+ candidatesById: /* @__PURE__ */ new Map(),
694
+ statusById: new Map(state.statusById)
695
+ });
696
+ }
697
+ function sourceRefStrings(sourceRefs) {
698
+ if (sourceRefs === void 0 || sourceRefs.length === 0) return void 0;
699
+ return sourceRefs.map((sourceRef) => `${sourceRef.kind}:${sourceRef.id}`);
700
+ }
701
+ function sourceRefFromIssueRef(issueRef) {
702
+ const [kind, ...rest] = issueRef.split(":");
703
+ return ref(kind || "issue-ref", rest.join(":") || issueRef);
704
+ }
705
+ function terminalHandoffState(state) {
706
+ return state === "completed" || state === "canceled" || state === "dead-lettered";
707
+ }
708
+ function hasWorkRecordCoordinates(record) {
709
+ return typeof record.queueId === "string" && typeof record.workId === "string" && typeof record.recordSeq === "number" && Number.isFinite(record.recordSeq);
710
+ }
711
+ function hasLeaseRecordCoordinates(record) {
712
+ return hasWorkRecordCoordinates(record) && typeof record.leaseId === "string" && typeof record.attempt === "number" && Number.isFinite(record.attempt) && typeof record.workerId === "string";
713
+ }
714
+ function malformedRecord(record, message) {
715
+ const subjectId = typeof record.kind === "string" ? `work-queue-record:${publicCoordinateId(record.kind)}` : "unknown-work-queue-record";
716
+ const issue = dataIssue("work-queue-scheduled-readiness-malformed-record", message, {
717
+ subjectId,
718
+ refs: [],
719
+ details: sanitizeGraphVisibleRecord({
720
+ recordKind: typeof record.kind === "string" ? record.kind : void 0,
721
+ queueId: typeof record.queueId === "string" ? publicCoordinateId(record.queueId) : void 0,
722
+ workId: typeof record.workId === "string" ? publicCoordinateId(record.workId) : void 0,
723
+ recordSeq: typeof record.recordSeq === "number" && Number.isFinite(record.recordSeq) ? record.recordSeq : void 0
724
+ })
725
+ });
726
+ return {
727
+ kind: "issue",
728
+ issue,
729
+ status: issueStatus(subjectId, [issue])
730
+ };
731
+ }
732
+ function translateRecord(raw) {
733
+ if (!isRecord(raw)) {
734
+ const issue = dataIssue(
735
+ "work-queue-scheduled-readiness-malformed-record",
736
+ "WorkQueue scheduled readiness requires a graph-visible workQueue record.",
737
+ { subjectId: "unknown-work-queue-record", refs: [] }
738
+ );
739
+ return {
740
+ kind: "issue",
741
+ issue,
742
+ status: issueStatus("unknown-work-queue-record", [issue])
743
+ };
744
+ }
745
+ const unknownRecord = raw;
746
+ const rawRecord = unknownRecord;
747
+ switch (rawRecord.kind) {
748
+ case "work-admitted": {
749
+ const notBeforeMs = rawRecord.notBeforeMs;
750
+ if (notBeforeMs === void 0) return { kind: "none" };
751
+ if (typeof notBeforeMs !== "number") {
752
+ return malformedRecord(rawRecord, "Delayed work-admitted notBeforeMs must be a number.");
753
+ }
754
+ if (!hasWorkRecordCoordinates(rawRecord)) {
755
+ return malformedRecord(
756
+ rawRecord,
757
+ "Delayed work-admitted records require queueId, workId, and recordSeq."
758
+ );
759
+ }
760
+ const admitted = rawRecord;
761
+ return scheduleFromRecord(admitted, {
762
+ scheduleKind: "work-admitted",
763
+ scheduleId: workQueueScheduleId(admitted, "admission", admitted.recordSeq),
764
+ readyAtMs: notBeforeMs,
765
+ deadlineMs: admitted.deadlineMs,
766
+ reason: "work-queue-delayed-admission"
767
+ });
768
+ }
769
+ case "work-scheduled": {
770
+ if (!hasWorkRecordCoordinates(rawRecord)) {
771
+ return malformedRecord(
772
+ rawRecord,
773
+ "work-scheduled records require queueId, workId, and recordSeq."
774
+ );
775
+ }
776
+ const scheduled = rawRecord;
777
+ return scheduleFromRecord(scheduled, {
778
+ scheduleKind: "work-scheduled",
779
+ scheduleId: workQueueScheduleId(
780
+ scheduled,
781
+ "schedule",
782
+ scheduled.scheduleId ?? scheduled.commandId ?? scheduled.recordSeq
783
+ ),
784
+ readyAtMs: scheduled.notBeforeMs,
785
+ deadlineMs: scheduled.deadlineMs,
786
+ reason: scheduled.reason ?? "work-queue-schedule"
787
+ });
788
+ }
789
+ case "retry-scheduled": {
790
+ if (!hasWorkRecordCoordinates(rawRecord)) {
791
+ return malformedRecord(
792
+ rawRecord,
793
+ "retry-scheduled records require queueId, workId, and recordSeq."
794
+ );
795
+ }
796
+ const retry = rawRecord;
797
+ return scheduleFromRecord(retry, {
798
+ scheduleKind: "retry-scheduled",
799
+ scheduleId: workQueueScheduleId(retry, "retry", retry.commandId ?? retry.recordSeq),
800
+ readyAtMs: retry.retryAtMs,
801
+ reason: retry.reason ?? "work-queue-retry",
802
+ metadata: { delayMs: retry.delayMs }
803
+ });
804
+ }
805
+ case "work-claimed": {
806
+ if (!hasLeaseRecordCoordinates(rawRecord)) {
807
+ return malformedRecord(
808
+ rawRecord,
809
+ "work-claimed records require queueId, workId, recordSeq, leaseId, attempt, and workerId."
810
+ );
811
+ }
812
+ const claimed = rawRecord;
813
+ return scheduleFromRecord(claimed, {
814
+ scheduleKind: "lease-expiration",
815
+ scheduleId: workQueueLeaseScheduleId(claimed),
816
+ readyAtMs: claimed.leaseExpiresAtMs,
817
+ reason: "work-queue-lease-expiration",
818
+ leaseId: claimed.leaseId,
819
+ metadata: { attempt: claimed.attempt }
820
+ });
821
+ }
822
+ case "lease-renewed": {
823
+ if (!hasLeaseRecordCoordinates(rawRecord)) {
824
+ return malformedRecord(
825
+ rawRecord,
826
+ "lease-renewed records require queueId, workId, recordSeq, leaseId, attempt, and workerId."
827
+ );
828
+ }
829
+ const renewed = rawRecord;
830
+ return scheduleFromRecord(renewed, {
831
+ scheduleKind: "lease-expiration",
832
+ scheduleId: workQueueLeaseScheduleId(renewed),
833
+ readyAtMs: renewed.leaseExpiresAtMs,
834
+ reason: "work-queue-lease-expiration",
835
+ leaseId: renewed.leaseId,
836
+ metadata: {
837
+ attempt: renewed.attempt,
838
+ previousLeaseExpiresAtMs: renewed.previousLeaseExpiresAtMs
839
+ }
840
+ });
841
+ }
842
+ default:
843
+ return { kind: "none" };
844
+ }
845
+ }
846
+ function scheduleFromRecord(record, opts) {
847
+ if (!Number.isFinite(opts.readyAtMs) || !finiteOrUndefined(opts.deadlineMs)) {
848
+ const refs = recordSourceRefs(record, opts.leaseId);
849
+ const issue = dataIssue(
850
+ "work-queue-scheduled-readiness-malformed-record",
851
+ "WorkQueue delayed eligibility record must carry finite readiness and deadline coordinates.",
852
+ {
853
+ subjectId: workQueueRecordSubjectId(record),
854
+ refs,
855
+ details: {
856
+ recordKind: record.kind,
857
+ readyAtMs: opts.readyAtMs,
858
+ deadlineMs: opts.deadlineMs
859
+ }
860
+ }
861
+ );
862
+ return {
863
+ kind: "issue",
864
+ issue,
865
+ status: issueStatus(opts.scheduleId, [issue], record, refs)
866
+ };
867
+ }
868
+ const subjectRefs = recordSubjectRefs(record, opts.leaseId);
869
+ const sourceRefs = recordSourceRefs(record, opts.leaseId);
870
+ const recordPolicyRefs = policyRefs(record);
871
+ const metadata = sanitizeGraphVisibleRecord({
872
+ queueId: publicCoordinateId(record.queueId),
873
+ workId: publicCoordinateId(record.workId),
874
+ recordSeq: record.recordSeq,
875
+ recordKind: record.kind,
876
+ scheduleKind: opts.scheduleKind,
877
+ ...record.commandId === void 0 ? {} : { commandId: publicCoordinateId(record.commandId) },
878
+ ...opts.leaseId === void 0 ? {} : { leaseId: publicCoordinateId(opts.leaseId) },
879
+ ...opts.metadata ?? {}
880
+ });
881
+ const schedule = Object.freeze({
882
+ kind: "scheduled-readiness-requested",
883
+ scheduleId: opts.scheduleId,
884
+ subjectRefs,
885
+ readyAtMs: opts.readyAtMs,
886
+ ...opts.deadlineMs === void 0 ? {} : { deadlineMs: opts.deadlineMs },
887
+ reason: opts.reason,
888
+ ...recordPolicyRefs === void 0 ? {} : { policyRefs: recordPolicyRefs },
889
+ sourceRefs,
890
+ ...metadata === void 0 ? {} : { metadata }
891
+ });
892
+ return {
893
+ kind: "translated",
894
+ record,
895
+ schedule,
896
+ status: Object.freeze({
897
+ kind: "work-queue-scheduled-readiness-status",
898
+ statusId: `${opts.scheduleId}:work-queue-scheduled-readiness-status:translated`,
899
+ queueId: publicCoordinateId(record.queueId),
900
+ workId: publicCoordinateId(record.workId),
901
+ recordSeq: record.recordSeq,
902
+ state: "translated",
903
+ scheduleKind: opts.scheduleKind,
904
+ scheduleId: opts.scheduleId,
905
+ readyAtMs: opts.readyAtMs,
906
+ ...opts.deadlineMs === void 0 ? {} : { deadlineMs: opts.deadlineMs },
907
+ sourceRefs,
908
+ ...metadata === void 0 ? {} : { metadata }
909
+ })
910
+ };
911
+ }
912
+ function recordSubjectRefs(record, leaseId) {
913
+ return canonicalPublicSourceRefs(
914
+ uniqueSourceRefs([
915
+ ref("work-queue", publicCoordinateId(record.queueId)),
916
+ ref("work-queue-work", publicCoordinateId(record.workId)),
917
+ ref("work-queue-record", String(record.recordSeq)),
918
+ ...record.commandId === void 0 ? [] : [ref("work-queue-command", publicCoordinateId(record.commandId))],
919
+ ...leaseId === void 0 ? [] : [ref("work-queue-lease", publicCoordinateId(leaseId))]
920
+ ])
921
+ );
922
+ }
923
+ function recordSourceRefs(record, leaseId) {
924
+ return canonicalPublicSourceRefs(
925
+ uniqueSourceRefs([
926
+ ref("work-queue", publicCoordinateId(record.queueId)),
927
+ ref("work-queue-record", String(record.recordSeq)),
928
+ ...record.workId === void 0 ? [] : [ref("work-queue-work", publicCoordinateId(record.workId))],
929
+ ...record.commandId === void 0 ? [] : [ref("work-queue-command", publicCoordinateId(record.commandId))],
930
+ ...leaseId === void 0 ? [] : [ref("work-queue-lease", publicCoordinateId(leaseId))],
931
+ ...copiedPublicRefs(record.sourceRefs, "work-queue-source-ref")
932
+ ])
933
+ );
934
+ }
935
+ function policyRefs(record) {
936
+ if (record.policyRefs === void 0 || record.policyRefs.length === 0) return void 0;
937
+ return canonicalPublicSourceRefs(copiedPublicRefs(record.policyRefs, "work-queue-policy-ref"));
938
+ }
939
+ function workQueueScheduleId(record, part, id) {
940
+ return `workQueue:${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:${part}:${publicCoordinateId(String(id))}`;
941
+ }
942
+ function workQueueLeaseScheduleId(record) {
943
+ return `workQueue:${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:lease:${publicCoordinateId(record.leaseId)}:expires:${record.recordSeq}`;
944
+ }
945
+ function workQueueRecordSubjectId(record) {
946
+ return `${publicCoordinateId(record.queueId)}:${publicCoordinateId(record.workId)}:${record.recordSeq}`;
947
+ }
948
+ function copiedPublicRefs(ids, kind) {
949
+ if (ids === void 0 || ids.length === 0) return [];
950
+ const copied = ids.slice(0, MAX_COPIED_PUBLIC_REFS).map((id) => ref(kind, publicCoordinateId(id)));
951
+ if (ids.length <= MAX_COPIED_PUBLIC_REFS) return copied;
952
+ return [
953
+ ...copied,
954
+ ref(
955
+ `${kind}-overflow`,
956
+ `count:${ids.length}:hash:${stableStringHash(stableJsonStringify(ids))}`
957
+ )
958
+ ];
959
+ }
960
+ function publicCoordinateId(id) {
961
+ if (id.length <= MAX_PUBLIC_COORDINATE_ID_CHARS && !PRIVATE_COORDINATE_PATTERN.test(id)) {
962
+ return id;
963
+ }
964
+ return `bounded:${stableStringHash(id)}:${id.length}`;
965
+ }
966
+ function issueStatus(statusId, issues, record, sourceRefs) {
967
+ return Object.freeze({
968
+ kind: "work-queue-scheduled-readiness-status",
969
+ statusId: `${statusId}:work-queue-scheduled-readiness-status:issue`,
970
+ ...record?.queueId === void 0 ? {} : { queueId: publicCoordinateId(record.queueId) },
971
+ ...record?.workId === void 0 ? {} : { workId: publicCoordinateId(record.workId) },
972
+ ...record?.recordSeq === void 0 ? {} : { recordSeq: record.recordSeq },
973
+ state: "issue",
974
+ ...sourceRefs === void 0 ? {} : { sourceRefs },
975
+ issueCodes: issues.map((issue) => issue.code)
976
+ });
977
+ }
978
+ function finiteOrUndefined(value) {
979
+ return value === void 0 || Number.isFinite(value);
980
+ }
981
+ function scheduleIdentity(schedule) {
982
+ return stableJsonStringify({
983
+ scheduleId: schedule.scheduleId,
984
+ subjectRefs: schedule.subjectRefs,
985
+ readyAtMs: schedule.readyAtMs,
986
+ deadlineMs: schedule.deadlineMs,
987
+ reason: schedule.reason,
988
+ policyRefs: schedule.policyRefs,
989
+ sourceRefs: schedule.sourceRefs,
990
+ metadata: schedule.metadata
991
+ });
992
+ }
993
+ function emitScheduleConflict(ctx, state, translated, existing) {
994
+ const issue = dataIssue(
995
+ "work-queue-scheduled-readiness-schedule-conflict",
996
+ "WorkQueue delayed eligibility replayed with conflicting scheduled-readiness material; the first schedule was retained.",
997
+ {
998
+ subjectId: translated.schedule.scheduleId,
999
+ refs: translated.schedule.sourceRefs,
1000
+ details: {
1001
+ existingReadyAtMs: existing?.readyAtMs,
1002
+ incomingReadyAtMs: translated.schedule.readyAtMs,
1003
+ existingDeadlineMs: existing?.deadlineMs,
1004
+ incomingDeadlineMs: translated.schedule.deadlineMs,
1005
+ recordSeq: translated.record.recordSeq,
1006
+ recordKind: translated.record.kind
1007
+ }
1008
+ }
1009
+ );
1010
+ emitIssue(ctx, state, issue);
1011
+ emitStatus(
1012
+ ctx,
1013
+ state,
1014
+ issueStatus(
1015
+ `${translated.schedule.scheduleId}:conflict:${translated.record.recordSeq}`,
1016
+ [issue],
1017
+ translated.record,
1018
+ translated.schedule.sourceRefs
1019
+ )
1020
+ );
1021
+ }
1022
+ function emitSchedule(ctx, state, schedule) {
1023
+ const key = `schedule:${schedule.scheduleId}`;
1024
+ if (state.emittedKeys.has(key)) return;
1025
+ state.emittedKeys.add(key);
1026
+ ctx.down([["DATA", { kind: "readiness-schedule", schedule }]]);
1027
+ }
1028
+ function emitStatus(ctx, state, status) {
1029
+ state.statusById.set(status.statusId, status);
1030
+ const key = `status:${status.statusId}:${(status.issueCodes ?? []).join(",")}`;
1031
+ if (state.emittedKeys.has(key)) return;
1032
+ state.emittedKeys.add(key);
1033
+ ctx.down([["DATA", { kind: "status", status }]]);
1034
+ }
1035
+ function emitIssue(ctx, state, issue) {
1036
+ const key = `${issue.code}:${issue.subjectId ?? ""}:${JSON.stringify(issue.details ?? {})}`;
1037
+ if (state.issueKeys.has(key)) return;
1038
+ state.issueKeys.add(key);
1039
+ ctx.down([["DATA", { kind: "issue", issue }]]);
1040
+ }
1041
+ function emitAudit(ctx, state, kind, opts) {
1042
+ state.auditSeq += 1;
1043
+ const metadata = sanitizeGraphVisibleRecord(opts.metadata);
1044
+ ctx.down([
1045
+ [
1046
+ "DATA",
1047
+ {
1048
+ kind: "audit",
1049
+ audit: Object.freeze({
1050
+ id: `work-queue-scheduled-readiness-audit-${state.auditSeq}`,
1051
+ kind,
1052
+ subjectId: opts.subjectId,
1053
+ ...opts.sourceRefs === void 0 ? {} : { sourceRefs: canonicalPublicSourceRefs(opts.sourceRefs) },
1054
+ ...metadata === void 0 ? {} : { metadata }
1055
+ })
1056
+ }
1057
+ ]
1058
+ ]);
1059
+ }
1060
+ function buildViews(state) {
1061
+ return Object.freeze({
1062
+ schedulesById: new Map(state.schedulesById),
1063
+ statusById: new Map(state.statusById)
1064
+ });
1065
+ }
1066
+
1067
+ // src/orchestration/work-queue.ts
1068
+ function orchestrationWorkQueueRecipe(graph, opts) {
1069
+ const name = opts.name ?? "orchestrationWorkQueue";
1070
+ const submitCommands = opts.effectRequests === void 0 ? void 0 : graph.node(
1071
+ [opts.effectRequests],
1072
+ (ctx) => {
1073
+ for (const raw of depBatch(ctx, 0) ?? []) {
1074
+ ctx.down([
1075
+ ["DATA", processEffectSubmitCommand(raw)]
1076
+ ]);
1077
+ }
1078
+ },
1079
+ {
1080
+ name: `${name}/submitCommands`,
1081
+ factory: "orchestrationWorkQueueSubmitCommands",
1082
+ completeWhenDepsComplete: false,
1083
+ errorWhenDepsError: false
1084
+ }
1085
+ );
1086
+ const runtime = graph.node(
1087
+ [opts.records],
1088
+ (ctx) => {
1089
+ const state = ctx.state.get() ?? {
1090
+ payloads: /* @__PURE__ */ new Map(),
1091
+ terminalRecords: /* @__PURE__ */ new Set(),
1092
+ auditSeq: 0
1093
+ };
1094
+ for (const raw of depBatch(ctx, 0) ?? []) {
1095
+ reduceRecord(ctx, state, raw);
1096
+ }
1097
+ ctx.state.set(state);
1098
+ },
1099
+ {
1100
+ name: `${name}/runtime`,
1101
+ factory: "orchestrationWorkQueueRuntime",
1102
+ partial: true,
1103
+ completeWhenDepsComplete: false,
1104
+ errorWhenDepsError: false
1105
+ }
1106
+ );
1107
+ return {
1108
+ ...submitCommands === void 0 ? {} : { submitCommands },
1109
+ evidence: project(
1110
+ graph,
1111
+ runtime,
1112
+ `${name}/evidence`,
1113
+ "orchestrationWorkQueueEvidence",
1114
+ (fact) => fact.kind === "evidence" ? fact.evidence : void 0
1115
+ ),
1116
+ status: project(
1117
+ graph,
1118
+ runtime,
1119
+ `${name}/status`,
1120
+ "orchestrationWorkQueueStatus",
1121
+ (fact) => fact.kind === "status" ? fact.status : void 0
1122
+ ),
1123
+ issues: project(
1124
+ graph,
1125
+ runtime,
1126
+ `${name}/issues`,
1127
+ "orchestrationWorkQueueIssues",
1128
+ (fact) => fact.kind === "issue" ? fact.issue : void 0
1129
+ ),
1130
+ audit: project(
1131
+ graph,
1132
+ runtime,
1133
+ `${name}/audit`,
1134
+ "orchestrationWorkQueueAudit",
1135
+ (fact) => fact.kind === "audit" ? fact.audit : void 0
1136
+ )
1137
+ };
1138
+ }
1139
+ function processEffectSubmitCommand(effect, opts = {}) {
1140
+ const payload = {
1141
+ kind: "orchestration-queued-effect",
1142
+ effect,
1143
+ idempotencyKey: opts.idempotencyKey ?? effect.id,
1144
+ sourceRefs: opts.sourceRefs,
1145
+ policyRefs: opts.policyRefs,
1146
+ metadata: opts.metadata
1147
+ };
1148
+ return {
1149
+ kind: "submit",
1150
+ commandId: opts.commandId ?? `${effect.id}:orchestration-work-queue-submit`,
1151
+ workId: opts.workId ?? `process-effect:${effect.id}`,
1152
+ payload,
1153
+ idempotencyKey: opts.idempotencyKey ?? effect.id,
1154
+ sourceRefs: opts.sourceRefs,
1155
+ policyRefs: opts.policyRefs
1156
+ };
1157
+ }
1158
+ function reduceRecord(ctx, state, record) {
1159
+ if (record.kind === "work-admitted") {
1160
+ if (isQueuedEffectPayload(record.payload)) {
1161
+ state.payloads.set(record.workId, record.payload);
1162
+ } else {
1163
+ emitIssue2(ctx, state, record, "orchestration-queue-malformed-payload");
1164
+ }
1165
+ return;
1166
+ }
1167
+ if (!isTerminalEvidenceRecord(record)) return;
1168
+ const key = `${record.kind}:${record.recordSeq}`;
1169
+ if (state.terminalRecords.has(key)) return;
1170
+ state.terminalRecords.add(key);
1171
+ const payload = record.workId === void 0 ? void 0 : state.payloads.get(record.workId);
1172
+ if (payload === void 0) {
1173
+ emitIssue2(ctx, state, record, "orchestration-queue-record-without-payload");
1174
+ return;
1175
+ }
1176
+ const evidence = evidenceFromRecord(record, payload);
1177
+ emit(ctx, { kind: "evidence", evidence });
1178
+ emit(ctx, { kind: "status", status: statusFromEvidence(evidence, payload) });
1179
+ state.auditSeq += 1;
1180
+ emit(ctx, { kind: "audit", audit: auditFromEvidence(state.auditSeq, evidence, payload) });
1181
+ }
1182
+ function isTerminalEvidenceRecord(record) {
1183
+ return record.kind === "work-completed" || record.kind === "attempt-completed" || record.kind === "work-canceled" || record.kind === "work-dead-lettered" || record.kind === "attempt-failed";
1184
+ }
1185
+ function evidenceFromRecord(record, payload) {
1186
+ return {
1187
+ kind: "orchestration-queue-evidence",
1188
+ evidenceId: `work-queue:${record.recordSeq}`,
1189
+ effectId: payload.effect.id,
1190
+ effectType: payload.effect.type,
1191
+ workId: record.workId ?? `unknown:${record.recordSeq}`,
1192
+ queueRecordKind: record.kind,
1193
+ result: "result" in record ? record.result : void 0,
1194
+ error: "error" in record ? record.error : void 0,
1195
+ recordedAtMs: record.recordedAtMs
1196
+ };
1197
+ }
1198
+ function statusFromEvidence(evidence, payload) {
1199
+ return {
1200
+ kind: "orchestration-queue-status",
1201
+ state: "evidence-recorded",
1202
+ effectId: payload.effect.id,
1203
+ effectType: payload.effect.type,
1204
+ workId: evidence.workId,
1205
+ queueRecordKind: evidence.queueRecordKind,
1206
+ evidenceId: evidence.evidenceId
1207
+ };
1208
+ }
1209
+ function auditFromEvidence(seq, evidence, payload) {
1210
+ return {
1211
+ kind: "orchestration-queue-audit",
1212
+ seq,
1213
+ outcome: "mapped",
1214
+ effectId: payload.effect.id,
1215
+ effectType: payload.effect.type,
1216
+ workId: evidence.workId,
1217
+ queueRecordKind: evidence.queueRecordKind,
1218
+ evidenceId: evidence.evidenceId
1219
+ };
1220
+ }
1221
+ function auditFromIssue(seq, record) {
1222
+ return {
1223
+ kind: "orchestration-queue-audit",
1224
+ seq,
1225
+ outcome: "issue",
1226
+ workId: record.workId,
1227
+ queueRecordKind: record.kind
1228
+ };
1229
+ }
1230
+ function project(graph, runtime, name, factory, pick) {
1231
+ return graph.node(
1232
+ [runtime],
1233
+ (ctx) => {
1234
+ for (const fact of depBatch(ctx, 0) ?? []) {
1235
+ const value = pick(fact);
1236
+ if (value !== void 0) ctx.down([["DATA", value]]);
1237
+ }
1238
+ },
1239
+ { name, factory, partial: true, completeWhenDepsComplete: false, errorWhenDepsError: false }
1240
+ );
1241
+ }
1242
+ function emit(ctx, fact) {
1243
+ ctx.down([["DATA", fact]]);
1244
+ }
1245
+ function emitIssue2(ctx, state, record, code) {
1246
+ const issue = queueIssue(record, code);
1247
+ emit(ctx, { kind: "issue", issue });
1248
+ state.auditSeq += 1;
1249
+ emit(ctx, {
1250
+ kind: "status",
1251
+ status: {
1252
+ kind: "orchestration-queue-status",
1253
+ state: "mapping-issue",
1254
+ workId: record.workId,
1255
+ queueRecordKind: record.kind,
1256
+ issues: [issue]
1257
+ }
1258
+ });
1259
+ emit(ctx, {
1260
+ kind: "audit",
1261
+ audit: auditFromIssue(state.auditSeq, record)
1262
+ });
1263
+ }
1264
+ function queueIssue(record, code) {
1265
+ return {
1266
+ kind: "issue",
1267
+ code,
1268
+ message: `Orchestration workQueue recipe could not map record '${record.kind}'`,
1269
+ severity: "error",
1270
+ source: "orchestration.workQueue",
1271
+ details: record
1272
+ };
1273
+ }
1274
+ function isQueuedEffectPayload(value) {
1275
+ if (!isObjectRecord(value) || value.kind !== "orchestration-queued-effect") return false;
1276
+ const effect = value.effect;
1277
+ return isObjectRecord(effect) && typeof effect.id === "string" && typeof effect.type === "string";
1278
+ }
1279
+ function isObjectRecord(value) {
1280
+ return typeof value === "object" && value !== null;
1281
+ }
1282
+ export {
1283
+ orchestrationWorkQueueRecipe,
1284
+ processEffectSubmitCommand,
1285
+ workQueueLeaseExpirationCommandProjector,
1286
+ workQueueReadinessHandoffProjector,
1287
+ workQueueScheduledReadinessProjector
1288
+ };
1289
+ //# sourceMappingURL=work-queue.js.map