@graphrefly/graphrefly 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/dist/{cascading-Cxs1eztH.d.cts → cascading-CH-_VwG9.d.cts} +2 -2
  2. package/dist/{cascading-BNfxffgc.d.ts → cascading-OgKQZjsa.d.ts} +2 -2
  3. package/dist/{chunk-L77I47VU.js → chunk-2K5RXLAH.js} +1 -1
  4. package/dist/chunk-3ERTUW2J.js +45 -0
  5. package/dist/chunk-3K7HA4Y6.js +1 -0
  6. package/dist/chunk-3ZZX7M25.js +1 -0
  7. package/dist/chunk-4QH6VJF4.js +1 -0
  8. package/dist/{chunk-M3FQSXEW.js → chunk-5QRRKBUT.js} +1 -1
  9. package/dist/chunk-5ST42ESJ.js +1 -0
  10. package/dist/{chunk-AK5RHMC5.js → chunk-6YFZMUMR.js} +1 -1
  11. package/dist/{chunk-SC27WTSG.js → chunk-7ARY3Y3T.js} +1 -1
  12. package/dist/chunk-7B7ELAT2.js +1 -0
  13. package/dist/{chunk-F7VUYPP6.js → chunk-7VKFXLZQ.js} +1 -1
  14. package/dist/chunk-ACMJ2ZPS.js +3 -0
  15. package/dist/{chunk-7PQLZMOG.js → chunk-AGNM6RS6.js} +1 -1
  16. package/dist/chunk-AS3TV2TV.js +1 -0
  17. package/dist/{chunk-CGNOWGV6.js → chunk-CISGGAIF.js} +1 -1
  18. package/dist/{chunk-ZAJ7J7TO.js → chunk-DEJTNNQC.js} +1 -1
  19. package/dist/{chunk-AI7QC7J6.js → chunk-FDZAZNRO.js} +1 -1
  20. package/dist/{chunk-OV5AA6HJ.js → chunk-FUZ6S2DY.js} +1 -1
  21. package/dist/{chunk-G3M3IMEV.js → chunk-G5VBJ5K6.js} +1 -1
  22. package/dist/{chunk-KNVCCBIU.js → chunk-HZKW2AAB.js} +1 -1
  23. package/dist/{chunk-CYOSWFT2.js → chunk-IZM3UEH3.js} +3 -3
  24. package/dist/{chunk-UISPDFJ3.js → chunk-KCACBSJH.js} +1 -1
  25. package/dist/{chunk-GI4Q7PNY.js → chunk-KT5DTRBP.js} +1 -1
  26. package/dist/{chunk-33N4TU3X.js → chunk-KY2LMAXU.js} +1 -1
  27. package/dist/{chunk-TT4C7DXW.js → chunk-LDQ3IUIP.js} +1 -1
  28. package/dist/chunk-LPRWATHB.js +61 -0
  29. package/dist/{chunk-X7QKTXXC.js → chunk-NWXQIOIB.js} +3 -3
  30. package/dist/{chunk-VV62MIG4.js → chunk-Q7QQQA3I.js} +1 -1
  31. package/dist/chunk-VE5SIZEM.js +1 -0
  32. package/dist/chunk-VRALOYRD.js +1 -0
  33. package/dist/{chunk-5VEZLQFN.js → chunk-WHMUB5QB.js} +1 -1
  34. package/dist/chunk-XLQPNNIC.js +1 -0
  35. package/dist/{chunk-YQRN4CIV.js → chunk-YGL7FPVQ.js} +1 -1
  36. package/dist/compat/index.cjs +5 -5
  37. package/dist/compat/index.d.cts +16 -16
  38. package/dist/compat/index.d.ts +16 -16
  39. package/dist/compat/index.js +1 -1
  40. package/dist/compat/jotai/index.d.cts +2 -2
  41. package/dist/compat/jotai/index.d.ts +2 -2
  42. package/dist/compat/nanostores/index.d.cts +2 -2
  43. package/dist/compat/nanostores/index.d.ts +2 -2
  44. package/dist/compat/nestjs/index.cjs +5 -5
  45. package/dist/compat/nestjs/index.d.cts +8 -8
  46. package/dist/compat/nestjs/index.d.ts +8 -8
  47. package/dist/compat/nestjs/index.js +1 -1
  48. package/dist/compat/react/index.d.cts +2 -2
  49. package/dist/compat/react/index.d.ts +2 -2
  50. package/dist/compat/solid/index.d.cts +2 -2
  51. package/dist/compat/solid/index.d.ts +2 -2
  52. package/dist/compat/svelte/index.d.cts +2 -2
  53. package/dist/compat/svelte/index.d.ts +2 -2
  54. package/dist/compat/vue/index.d.cts +2 -2
  55. package/dist/compat/vue/index.d.ts +2 -2
  56. package/dist/compat/zustand/index.cjs +3 -3
  57. package/dist/compat/zustand/index.d.cts +4 -4
  58. package/dist/compat/zustand/index.d.ts +4 -4
  59. package/dist/compat/zustand/index.js +1 -1
  60. package/dist/core/index.d.cts +4 -4
  61. package/dist/core/index.d.ts +4 -4
  62. package/dist/{decay-C25AyNAj.d.cts → decay-2ZukgQ4o.d.cts} +2 -2
  63. package/dist/{decay-BnrlbxSv.d.ts → decay-CdEBmDIs.d.ts} +2 -2
  64. package/dist/extra/browser.d.cts +1 -1
  65. package/dist/extra/browser.d.ts +1 -1
  66. package/dist/extra/index.cjs +14 -14
  67. package/dist/extra/index.d.cts +10 -11
  68. package/dist/extra/index.d.ts +10 -11
  69. package/dist/extra/index.js +1 -1
  70. package/dist/extra/node.cjs +2 -2
  71. package/dist/extra/node.d.cts +1 -1
  72. package/dist/extra/node.d.ts +1 -1
  73. package/dist/extra/node.js +1 -1
  74. package/dist/extra/operators.cjs +1 -1
  75. package/dist/extra/operators.d.cts +1 -1
  76. package/dist/extra/operators.d.ts +1 -1
  77. package/dist/extra/operators.js +1 -1
  78. package/dist/extra/reactive.d.cts +3 -3
  79. package/dist/extra/reactive.d.ts +3 -3
  80. package/dist/extra/reactive.js +1 -1
  81. package/dist/extra/render/index.d.cts +3 -3
  82. package/dist/extra/render/index.d.ts +3 -3
  83. package/dist/extra/sources.cjs +3 -1
  84. package/dist/extra/sources.d.cts +1 -1
  85. package/dist/extra/sources.d.ts +1 -1
  86. package/dist/extra/sources.js +1 -1
  87. package/dist/extra/storage-browser.d.cts +1 -1
  88. package/dist/extra/storage-browser.d.ts +1 -1
  89. package/dist/{fallback-CMZl39L5.d.ts → fallback-CqYVLL6X.d.ts} +1 -1
  90. package/dist/{fallback-8JYU8tlT.d.cts → fallback-Ctlj2tMY.d.cts} +1 -1
  91. package/dist/graph/index.cjs +7 -7
  92. package/dist/graph/index.d.cts +5 -5
  93. package/dist/graph/index.d.ts +5 -5
  94. package/dist/graph/index.js +1 -1
  95. package/dist/{graph-BkIkog4h.d.ts → graph-7VguS7a4.d.ts} +3 -3
  96. package/dist/{graph-E6likq7w.d.cts → graph-C4SHb3Ly.d.cts} +3 -3
  97. package/dist/{index-DktLSZOc.d.cts → index-2B7u2pVn.d.cts} +4 -4
  98. package/dist/{index-DGD4_fj6.d.cts → index-3NmAfcH0.d.cts} +8 -5
  99. package/dist/{index-DfOK_oL5.d.ts → index-4Uz-e_fL.d.ts} +372 -17
  100. package/dist/{index-BAQrjuZF.d.ts → index-B-i4_g3k.d.ts} +2 -2
  101. package/dist/{index-DpiGqtrs.d.cts → index-B11anra4.d.cts} +441 -381
  102. package/dist/{index-WSlcjhQF.d.ts → index-B3OTH1dV.d.ts} +124 -13
  103. package/dist/{index-2n8Eai6M.d.ts → index-BG0BN3PB.d.ts} +1 -1
  104. package/dist/{index-z8WFPVI8.d.cts → index-BJX94aud.d.cts} +1 -1
  105. package/dist/{index-DhLyOHYZ.d.ts → index-BP8a88zx.d.ts} +11 -4
  106. package/dist/{index-Cnr1WrlX.d.cts → index-BTQtTb_H.d.cts} +14 -3
  107. package/dist/{index-BaA-xpSw.d.ts → index-BUYXac2c.d.ts} +3 -3
  108. package/dist/{index-DOBLxOti.d.cts → index-BVpm6noz.d.cts} +1 -1
  109. package/dist/{index-DhnsQfa3.d.ts → index-Bbkgpt5t.d.ts} +441 -381
  110. package/dist/{index-Cczxgd2D.d.ts → index-Bc41FuHp.d.cts} +3 -3
  111. package/dist/{index-BiHUBEKq.d.cts → index-BdGtBX-X.d.cts} +3 -3
  112. package/dist/index-BeT2r7sk.d.ts +760 -0
  113. package/dist/{index-da2V5vPy.d.ts → index-Bf7eqeSF.d.ts} +2 -2
  114. package/dist/{index-bXXLSvor.d.ts → index-Bn4zHYLj.d.ts} +4 -4
  115. package/dist/{index-DGTo1yka.d.cts → index-BoLv_OfD.d.cts} +2 -2
  116. package/dist/{index-B72TQQHd.d.cts → index-BsT7F2et.d.ts} +3 -3
  117. package/dist/{index-Bd91Nmf4.d.cts → index-BtAsBp8K.d.cts} +4 -4
  118. package/dist/{index-DgJc8Zgc.d.cts → index-C0-Jv1kP.d.cts} +81 -5
  119. package/dist/{index-C6ZUaos7.d.ts → index-C7O6r5fV.d.ts} +1 -1
  120. package/dist/{index-CL7oilfm.d.cts → index-C9kSENB4.d.cts} +1 -1
  121. package/dist/{index-yLt-aPMp.d.ts → index-CCq87F7t.d.ts} +1 -1
  122. package/dist/{index-DQQCOIt8.d.cts → index-CEMx8n40.d.cts} +10 -5
  123. package/dist/{index-BilOa6AE.d.cts → index-CJIuLu2f.d.cts} +124 -13
  124. package/dist/{index-B2RUoIUz.d.ts → index-CJK1JkYy.d.ts} +1 -1
  125. package/dist/{index-CG33HeBW.d.ts → index-CJQm0g38.d.ts} +8 -5
  126. package/dist/index-CPNSy-U0.d.cts +760 -0
  127. package/dist/{index-A3U3CSve.d.cts → index-CZjOhcBy.d.cts} +2 -2
  128. package/dist/{index-CAP3UGsq.d.ts → index-CZmcDtFn.d.ts} +1 -1
  129. package/dist/{index-DYTBbF8T.d.cts → index-ChOyVLKm.d.cts} +1 -1
  130. package/dist/{index-eaQuGJnv.d.ts → index-CpyNFqkB.d.ts} +3 -3
  131. package/dist/{index-BJSZxSFX.d.ts → index-CvrqGfNS.d.ts} +1 -1
  132. package/dist/{index-DuRsN9ae.d.cts → index-D-Xs74HZ.d.cts} +372 -17
  133. package/dist/{index-C5cQ7Gfx.d.ts → index-D6egPFAL.d.ts} +4 -4
  134. package/dist/{index-CD2dBMet.d.ts → index-D8l8hNXn.d.ts} +10 -5
  135. package/dist/{index-40ZT4MHj.d.ts → index-DBHK8O6H.d.ts} +14 -3
  136. package/dist/{index-DVDapw2k.d.cts → index-DBIqYS43.d.cts} +35 -21
  137. package/dist/{index-3k4Gg6-n.d.ts → index-DBevwHj_.d.ts} +3 -3
  138. package/dist/{index-Ctb7_2sG.d.ts → index-DIOoAZUX.d.ts} +1 -1
  139. package/dist/{index-BQ1fR4li.d.ts → index-DO9XxMzS.d.ts} +35 -21
  140. package/dist/{index-CQtWm7jS.d.ts → index-DQo8xBgd.d.ts} +9 -9
  141. package/dist/{index-DH4fm2Ck.d.ts → index-Dgs8zcj7.d.ts} +2 -2
  142. package/dist/{index-CtFNGe-m.d.cts → index-Dhc7a7Xo.d.cts} +2 -2
  143. package/dist/{index-MxYuWOrf.d.cts → index-DmAgG5CI.d.cts} +3 -3
  144. package/dist/{index-CoM4rzyB.d.ts → index-Dmqp7KjD.d.ts} +1 -1
  145. package/dist/{index-B6iTqKtJ.d.ts → index-Dn-wI9g4.d.ts} +2 -2
  146. package/dist/{index-C-dkXOpB.d.cts → index-Du7u1lSf.d.cts} +11 -4
  147. package/dist/{index-DVAlsmEU.d.cts → index-HoU88d5U.d.cts} +3 -3
  148. package/dist/{index-CRm0YIzC.d.cts → index-LIpQQE9f.d.cts} +9 -9
  149. package/dist/{index-CgnCFhr2.d.cts → index-f5IivDUX.d.cts} +1 -1
  150. package/dist/{index-PgwvGWa1.d.cts → index-hHcaFlJX.d.cts} +1 -1
  151. package/dist/{index-I1cCY3ZI.d.ts → index-pT8sCpOJ.d.ts} +81 -5
  152. package/dist/{index-D4uimgee.d.cts → index-sl4NyzQx.d.cts} +1 -1
  153. package/dist/{index-tV3AA9hI.d.cts → index-tJoTcnHh.d.cts} +2 -2
  154. package/dist/{index-D3ayz3hy.d.cts → index-z96luz5O.d.cts} +1 -1
  155. package/dist/index.cjs +48 -48
  156. package/dist/index.d.cts +45 -50
  157. package/dist/index.d.ts +45 -50
  158. package/dist/index.js +1 -1
  159. package/dist/{meta-D8OyedKp.d.ts → meta-BgVAsg9j.d.ts} +1 -1
  160. package/dist/{meta-Ct9nqQS5.d.cts → meta-vE8bxW1E.d.cts} +1 -1
  161. package/dist/{node-BYInONRr.d.cts → node-ClS5yC-B.d.cts} +1 -1
  162. package/dist/{node-BYInONRr.d.ts → node-ClS5yC-B.d.ts} +1 -1
  163. package/dist/{observable-DO8DDEzv.d.ts → observable-BsBzUrcI.d.ts} +1 -1
  164. package/dist/{observable-DMIlYJV1.d.cts → observable-DLGPPtb8.d.cts} +1 -1
  165. package/dist/patterns/ai/browser.d.cts +4 -4
  166. package/dist/patterns/ai/browser.d.ts +4 -4
  167. package/dist/patterns/ai/browser.js +1 -1
  168. package/dist/patterns/ai/index.cjs +17 -17
  169. package/dist/patterns/ai/index.d.cts +17 -17
  170. package/dist/patterns/ai/index.d.ts +17 -17
  171. package/dist/patterns/ai/index.js +1 -1
  172. package/dist/patterns/ai/node.d.cts +4 -4
  173. package/dist/patterns/ai/node.d.ts +4 -4
  174. package/dist/patterns/ai/node.js +1 -1
  175. package/dist/patterns/cqrs/index.cjs +3 -3
  176. package/dist/patterns/cqrs/index.d.cts +6 -6
  177. package/dist/patterns/cqrs/index.d.ts +6 -6
  178. package/dist/patterns/cqrs/index.js +1 -1
  179. package/dist/patterns/demo-shell/index.cjs +5 -5
  180. package/dist/patterns/demo-shell/index.d.cts +5 -5
  181. package/dist/patterns/demo-shell/index.d.ts +5 -5
  182. package/dist/patterns/demo-shell/index.js +1 -1
  183. package/dist/patterns/domain-templates/index.cjs +3 -3
  184. package/dist/patterns/domain-templates/index.d.cts +4 -4
  185. package/dist/patterns/domain-templates/index.d.ts +4 -4
  186. package/dist/patterns/domain-templates/index.js +1 -1
  187. package/dist/patterns/graphspec/index.cjs +12 -12
  188. package/dist/patterns/graphspec/index.d.cts +5 -5
  189. package/dist/patterns/graphspec/index.d.ts +5 -5
  190. package/dist/patterns/graphspec/index.js +1 -1
  191. package/dist/patterns/harness/index.cjs +10 -8
  192. package/dist/patterns/harness/index.d.cts +11 -12
  193. package/dist/patterns/harness/index.d.ts +11 -12
  194. package/dist/patterns/harness/index.js +1 -1
  195. package/dist/patterns/inspect/index.cjs +3 -0
  196. package/dist/patterns/inspect/index.d.cts +9 -0
  197. package/dist/patterns/inspect/index.d.ts +9 -0
  198. package/dist/patterns/inspect/index.js +1 -0
  199. package/dist/patterns/job-queue/index.cjs +3 -3
  200. package/dist/patterns/job-queue/index.d.cts +6 -6
  201. package/dist/patterns/job-queue/index.d.ts +6 -6
  202. package/dist/patterns/job-queue/index.js +1 -1
  203. package/dist/patterns/memory/index.cjs +3 -3
  204. package/dist/patterns/memory/index.d.cts +6 -6
  205. package/dist/patterns/memory/index.d.ts +6 -6
  206. package/dist/patterns/memory/index.js +1 -1
  207. package/dist/patterns/messaging/index.cjs +3 -3
  208. package/dist/patterns/messaging/index.d.cts +5 -5
  209. package/dist/patterns/messaging/index.d.ts +5 -5
  210. package/dist/patterns/messaging/index.js +1 -1
  211. package/dist/patterns/orchestration/index.cjs +3 -3
  212. package/dist/patterns/orchestration/index.d.cts +7 -7
  213. package/dist/patterns/orchestration/index.d.ts +7 -7
  214. package/dist/patterns/orchestration/index.js +1 -1
  215. package/dist/patterns/process/index.cjs +1 -1
  216. package/dist/patterns/process/index.d.cts +7 -7
  217. package/dist/patterns/process/index.d.ts +7 -7
  218. package/dist/patterns/process/index.js +1 -1
  219. package/dist/patterns/reactive-layout/index.cjs +4 -4
  220. package/dist/patterns/reactive-layout/index.d.cts +5 -5
  221. package/dist/patterns/reactive-layout/index.d.ts +5 -5
  222. package/dist/patterns/reactive-layout/index.js +1 -1
  223. package/dist/patterns/reduction/index.cjs +3 -3
  224. package/dist/patterns/reduction/index.d.cts +4 -4
  225. package/dist/patterns/reduction/index.d.ts +4 -4
  226. package/dist/patterns/reduction/index.js +1 -1
  227. package/dist/patterns/surface/index.cjs +8 -8
  228. package/dist/patterns/surface/index.d.cts +6 -6
  229. package/dist/patterns/surface/index.d.ts +6 -6
  230. package/dist/patterns/surface/index.js +1 -1
  231. package/dist/{pipeline-graph-MWrQZXCq.d.cts → pipeline-graph-WBlobVhU.d.cts} +5 -5
  232. package/dist/{pipeline-graph-CB4La-UW.d.ts → pipeline-graph-v8fMvqNk.d.ts} +5 -5
  233. package/dist/{reactive-layout-BtZfUKuL.d.cts → reactive-layout-Dsvob4zD.d.cts} +2 -2
  234. package/dist/{reactive-layout-KJj4E2dT.d.ts → reactive-layout-v7KPvxoc.d.ts} +2 -2
  235. package/dist/{reactive-log-_zeEnB9H.d.cts → reactive-log-B00laMSQ.d.cts} +1 -1
  236. package/dist/{reactive-log-BlAsPLl2.d.ts → reactive-log-BezYsbA_.d.ts} +1 -1
  237. package/dist/{reactive-map-6P_k3AQM.d.cts → reactive-map-48mnZ-nu.d.cts} +1 -1
  238. package/dist/{reactive-map-CjXByDV-.d.ts → reactive-map-BVVPdvmi.d.ts} +1 -1
  239. package/dist/resilience-445VFFXQ.js +1 -0
  240. package/dist/{sugar-BhfjgetH.d.ts → sugar-CH-2ZY90.d.ts} +1 -1
  241. package/dist/{sugar-DzePN5-g.d.cts → sugar-DStZfUEK.d.cts} +1 -1
  242. package/dist/{topology-tree-mF7Emqzm.d.ts → topology-tree-BNGvuG82.d.ts} +1 -1
  243. package/dist/{topology-tree-3LBKFsUo.d.cts → topology-tree-BSdfSwMi.d.cts} +1 -1
  244. package/dist/{types-1Dhoi7HM.d.cts → types-B1jDWVsM.d.cts} +1 -1
  245. package/dist/{types-39jk0kaV.d.ts → types-DkzUUs0H.d.ts} +1 -1
  246. package/package.json +11 -51
  247. package/dist/budget-gate-CmmVtasH.d.ts +0 -115
  248. package/dist/budget-gate-DiP_nK0n.d.cts +0 -115
  249. package/dist/chunk-2W553JJC.js +0 -1
  250. package/dist/chunk-4MKL6Q3K.js +0 -1
  251. package/dist/chunk-5B3JDG5F.js +0 -1
  252. package/dist/chunk-5QSXEMXG.js +0 -1
  253. package/dist/chunk-5TEFC2ZX.js +0 -1
  254. package/dist/chunk-5TOPVRN6.js +0 -1
  255. package/dist/chunk-EC2WNSZ7.js +0 -1
  256. package/dist/chunk-ELAASRBT.js +0 -3
  257. package/dist/chunk-H5SCWHWP.js +0 -1
  258. package/dist/chunk-OLIKJUKI.js +0 -1
  259. package/dist/chunk-POXANAJ6.js +0 -3
  260. package/dist/chunk-RSMEXK53.js +0 -43
  261. package/dist/chunk-SGS4OJGS.js +0 -1
  262. package/dist/chunk-URJ2VFNC.js +0 -1
  263. package/dist/chunk-VXPLLA4P.js +0 -1
  264. package/dist/chunk-WZYB3JQS.js +0 -1
  265. package/dist/chunk-Z6X7B6A4.js +0 -61
  266. package/dist/index-8s-Qm-gz.d.ts +0 -218
  267. package/dist/index-BgjS2b8N.d.ts +0 -366
  268. package/dist/index-BmSQLAZo.d.cts +0 -244
  269. package/dist/index-CGhMJNHb.d.cts +0 -128
  270. package/dist/index-CUIkE1l9.d.cts +0 -230
  271. package/dist/index-Ck35nA-T.d.ts +0 -244
  272. package/dist/index-CuPUehFa.d.cts +0 -218
  273. package/dist/index-D1Gc7wV5.d.ts +0 -230
  274. package/dist/index-N2MAxt7_.d.ts +0 -128
  275. package/dist/index-t6L2qpHh.d.cts +0 -366
  276. package/dist/patterns/audit/index.cjs +0 -3
  277. package/dist/patterns/audit/index.d.cts +0 -8
  278. package/dist/patterns/audit/index.d.ts +0 -8
  279. package/dist/patterns/audit/index.js +0 -1
  280. package/dist/patterns/guarded-execution/index.cjs +0 -3
  281. package/dist/patterns/guarded-execution/index.d.cts +0 -9
  282. package/dist/patterns/guarded-execution/index.d.ts +0 -9
  283. package/dist/patterns/guarded-execution/index.js +0 -1
  284. package/dist/patterns/lens/index.cjs +0 -3
  285. package/dist/patterns/lens/index.d.cts +0 -7
  286. package/dist/patterns/lens/index.d.ts +0 -7
  287. package/dist/patterns/lens/index.js +0 -1
  288. package/dist/patterns/refine-loop/index.cjs +0 -5
  289. package/dist/patterns/refine-loop/index.d.cts +0 -9
  290. package/dist/patterns/refine-loop/index.d.ts +0 -9
  291. package/dist/patterns/refine-loop/index.js +0 -1
  292. package/dist/patterns/resilient-pipeline/index.cjs +0 -3
  293. package/dist/patterns/resilient-pipeline/index.d.cts +0 -8
  294. package/dist/patterns/resilient-pipeline/index.d.ts +0 -8
  295. package/dist/patterns/resilient-pipeline/index.js +0 -1
  296. package/dist/resilience-JISHQD2F.js +0 -1
@@ -0,0 +1,61 @@
1
+ import{a as kt,b as Rt,c as xt,d as wt}from"./chunk-KT5DTRBP.js";import{f as $e}from"./chunk-4QH6VJF4.js";import{c as vt}from"./chunk-AGNM6RS6.js";import{a as Ht,b as Xt,c as Zt,d as er,e as tr,f as Be,g as rr}from"./chunk-Q7QQQA3I.js";import{a as Fe,b as V,c as Le,d as de,e as ee,f as U,g as zt,h as Ge,i as Yt,j as Jt,k as Qt}from"./chunk-KCACBSJH.js";import{h as Lt}from"./chunk-7VKFXLZQ.js";import{b as Tt}from"./chunk-7B7ELAT2.js";import{a as we,b as Mt}from"./chunk-TSOYJ743.js";import{d as pt,e as Re,f as ft,h as _e}from"./chunk-AS3TV2TV.js";import{b as xe}from"./chunk-TZQPPQEQ.js";import{a as dt}from"./chunk-L6NSJVJZ.js";import{b as pe}from"./chunk-LDQ3IUIP.js";import{j as ae}from"./chunk-ACMJ2ZPS.js";import{a as Z}from"./chunk-ESMPEKEV.js";import{R as ct,b as ut,s as mt,x as $}from"./chunk-6YFZMUMR.js";import{A as bt,C as j,f as gt,k as je,l as yt,m as k,x as se,z as ht}from"./chunk-2K5RXLAH.js";import{b as ke,c as X}from"./chunk-35JTVPOX.js";import{D as le,E as w,F as Q,G as v,H as re,m as J,o as H,p as be}from"./chunk-LYCLF26R.js";import{b as G,d as ce,i as q,j as W}from"./chunk-CK2E7BTU.js";import{b as qt}from"./chunk-QYADASLV.js";var Zr={};qt(Zr,{AgentLoopGraph:()=>Pe,AllTiersExhaustedError:()=>tr,BudgetExhaustedError:()=>Ce,ChatStreamGraph:()=>Ie,CircuitOpenError:()=>Re,DEFAULT_DECAY_RATE:()=>we,FallbackMissError:()=>Jt,LLMTimeoutError:()=>ge,ReplayCacheMissError:()=>zt,ToolRegistryGraph:()=>De,admissionFilter3D:()=>Wr,admissionScored:()=>Gt,agentLoop:()=>Vr,agentMemory:()=>Ur,anthropicAdapter:()=>Ht,canonicalJson:()=>Yt,cascadingLlmAdapter:()=>Be,chatStream:()=>rt,composePricing:()=>lr,computePrice:()=>We,contentGate:()=>_r,costMeterExtractor:()=>Sr,createAdapter:()=>er,createCapabilitiesRegistry:()=>nr,createPricingRegistry:()=>sr,dryRunAdapter:()=>Fe,fallbackAdapter:()=>Qt,frozenContext:()=>xr,gatedStream:()=>Nr,gaugesAsContext:()=>qr,googleAdapter:()=>Xt,graphFromSpec:()=>$t,graphFromSpecReactive:()=>Hr,handoff:()=>Fr,keywordFlagExtractor:()=>Or,knobsAsTools:()=>Yr,llmConsolidator:()=>tt,llmExtractor:()=>et,memoryRetrieval:()=>lt,memoryWithKG:()=>st,memoryWithTiers:()=>it,memoryWithVectors:()=>at,observableAdapter:()=>or,openAICompatAdapter:()=>Zt,parseRateLimitFromError:()=>qe,pricingFor:()=>dr,promptCall:()=>Ze,promptNode:()=>Xe,redactor:()=>jr,registryPricing:()=>ir,resilientAdapter:()=>Mr,streamExtractor:()=>Ir,streamingPromptNode:()=>Lr,suggestStrategy:()=>Wt,suggestStrategyReactive:()=>Qr,systemPromptBuilder:()=>Ar,tier:()=>rr,toolCallExtractor:()=>Pr,toolExecution:()=>nt,toolRegistry:()=>ot,toolSelector:()=>$r,validateGraphDef:()=>Xr,withBreaker:()=>Ke,withBudgetGate:()=>Ue,withDryRun:()=>mr,withRateLimiter:()=>ze,withReplayCache:()=>Ge,withRetry:()=>Ye,withTimeout:()=>Je,zeroPrice:()=>Ae});function Te(t,e){return`${t}::${e}`}function nr(t){let e=xe({name:"capabilitiesRegistry"}),r=l=>{e.set(Te(l.provider,l.id),l)};if(t)for(let l of t)r(l);let n=(l,d)=>{let m=e.get(Te(l,d));if(m)return m;let p=e.entries.cache;if(!p)return;let c;for(let[,g]of p){if(g.provider!==l)continue;let y=g.id;d.startsWith(y)&&(!c||y.length>c.id.length)&&(c=g)}return c},o=128,a=new Map,s=new Map,i=(l,d,m,p)=>{for(l.has(d)&&l.delete(d),l.set(d,m);l.size>p;){let c=l.keys().next().value;if(c===void 0)break;l.delete(c)}},u=v([e.entries],([l])=>l instanceof Map?Array.from(l.values()):[],{name:"capabilitiesRegistry/entries",initial:[]});return{register:r,lookup:n,remove(l,d){let m=e.has(Te(l,d));return m&&e.delete(Te(l,d)),m},entries(){let l=e.entries.cache;return(function*(){if(l)for(let d of l.values())yield d})()},lookupNode(l,d){let m=Te(l,d),p=a.get(m);if(p)return a.delete(m),a.set(m,p),p;let c=v([e.entries],()=>n(l,d),{name:`capabilitiesRegistry/lookup/${l}::${d}`,initial:void 0});return i(a,m,c,o),c},entriesNode:u,byProvider(l){let d=s.get(l);if(d)return s.delete(l),s.set(l,d),d;let m=v([u],([p])=>p.filter(c=>c.provider===l),{name:`capabilitiesRegistry/byProvider/${l}`,initial:[]});return i(s,l,m,o),m}}}function z(t){let e=t.input,r=e.regular+(e.cacheRead??0)+(e.cacheWrite5m??0)+(e.cacheWrite1h??0)+(e.cacheWriteOther??0)+(e.audio??0)+(e.image??0)+(e.video??0)+(e.toolUse??0);if(!e.extensions)return r;let n=0;for(let o of Object.values(e.extensions))n+=o;return r+n}function ne(t){let e=t.output,r=e.regular+(e.reasoning??0)+(e.audio??0)+(e.predictionAccepted??0)+(e.predictionRejected??0);if(!e.extensions)return r;let n=0;for(let o of Object.values(e.extensions))n+=o;return r+n}function Nt(){return{input:{regular:0},output:{regular:0}}}function or(t,e){let r=e?.logMax??1e3,n=pe(void 0,{name:e?.name?`${e.name}/stats`:"adapterStats",maxSize:r}),o=w(null,{name:"adapterStats/lastCall"}),a=v([n.entries],([y])=>y.length,{name:"adapterStats/totalCalls",initial:0}),s=v([n.entries],([y])=>y.reduce((f,h)=>f+z(h.usage),0),{name:"adapterStats/totalInputTokens",initial:0}),i=v([n.entries],([y])=>y.reduce((f,h)=>f+ne(h.usage),0),{name:"adapterStats/totalOutputTokens",initial:0}),u=[j(a),j(s),j(i)],l=y=>{n.append(y),o.emit(y)},d=()=>{n.clear(),o.emit(null)},m=V(t,{invoke(y,f){let h=H(),b=be(),N=t.model??f?.model??"",A=R=>(l(de({provider:t.provider,model:t.model??f?.model??R.model??"",tier:f?.tier??R.tier,usage:R.usage??ee(),startNs:h,startWallClockNs:b,method:"invoke"})),R),C=R=>{let D=R;l(de({provider:t.provider,model:N,tier:f?.tier,usage:ee(),startNs:h,startWallClockNs:b,method:"invoke",error:{type:D?.name??"Error",message:D?.message??String(R)}}))};return Le(t.invoke(y,f),{onResp:A,onError:C,name:"adapterStats/invokeTap"})},async*stream(y,f){let h=H(),b=be(),N=t.model??f?.model??"",A;try{for await(let C of t.stream(y,f))C.type==="usage"&&(A=C.usage),yield C;l(de({provider:t.provider,model:N,tier:f?.tier,usage:A??ee(),startNs:h,startWallClockNs:b,method:"stream"}))}catch(C){let R=C;throw l(de({provider:t.provider,model:N,tier:f?.tier,usage:A??ee(),startNs:h,startWallClockNs:b,method:"stream",error:{type:R?.name??"Error",message:R?.message??String(C)}})),C}}});U(m,"observableAdapter",t);let p=!1;return{adapter:m,stats:{lastCall:o,allCalls:n,totalCalls:a,totalInputTokens:s,totalOutputTokens:i,reset:d,dispose:()=>{if(!p){p=!0;for(let y of u)y();u.length=0}}}}}function ar(t,e){return t==null?0:typeof t=="number"?t:t.thresholdTokens!=null&&t.pricePerMillionAbove!=null&&e>t.thresholdTokens?t.pricePerMillionAbove:t.pricePerMillion}function Ae(t="USD"){return{total:0,currency:t}}function We(t,e,r){let n=z(t),o=e.currency??"USD",a=r?.withBreakdown===!0,s=a?{}:null,i=0,u=(f,h,b)=>{if(!h||b==null)return;let N=ar(b,n),A=h*N/1e6;i+=A,a&&(s[f]=(s[f]??0)+A)},l=t.input,d=e.input;if(d&&(u("input.regular",l.regular,d.regular),u("input.cacheRead",l.cacheRead??0,d.cacheRead),u("input.cacheWrite5m",l.cacheWrite5m??0,d.cacheWrite5m),u("input.cacheWrite1h",l.cacheWrite1h??0,d.cacheWrite1h),u("input.cacheWriteOther",l.cacheWriteOther??0,d.cacheWriteOther),u("input.audio",l.audio??0,d.audio),u("input.image",l.image??0,d.image),u("input.video",l.video??0,d.video),u("input.toolUse",l.toolUse??0,d.toolUse),l.extensions&&d.extensions))for(let[f,h]of Object.entries(l.extensions))u(`input.ext.${f}`,h,d.extensions[f]);let m=t.output,p=e.output;if(p&&(u("output.regular",m.regular,p.regular),u("output.reasoning",m.reasoning??0,p.reasoning),u("output.audio",m.audio??0,p.audio),u("output.predictionAccepted",m.predictionAccepted??0,p.predictionAccepted),u("output.predictionRejected",m.predictionRejected??0,p.predictionRejected),m.extensions&&p.extensions))for(let[f,h]of Object.entries(m.extensions))u(`output.ext.${f}`,h,p.extensions[f]);let c=r?.tier;if(c&&e.tierMultipliers){let f=e.tierMultipliers[c];if(f!=null&&(i*=f,a))for(let h of Object.keys(s))s[h]*=f}let g=t.auxiliary,y=e.auxiliary;if(g&&y)for(let[f,h]of Object.entries(g)){let b=y[f];if(b==null||!h)continue;let N=h*b;i+=N,a&&(s[`auxiliary.${f}`]=N)}return a?{total:i,currency:o,breakdown:s}:{total:i,currency:o}}function Ne(t,e){return`${t}::${e}`}function sr(t){let e=new Map,r=new Map,n=(o,a,s)=>{e.set(Ne(o,a),{provider:o,model:a,pricing:s});let i=r.get(o);i||(i=new Set,r.set(o,i)),i.add(a)};if(t)for(let[o,a,s]of t)n(o,a,s);return{register:n,lookup(o,a){let s=e.get(Ne(o,a));if(s)return s.pricing;let i=r.get(o);if(!i)return;let u;for(let l of i)if(a.startsWith(l)&&(!u||l.length>u.key.length)){let d=e.get(Ne(o,l));d&&(u={key:l,pricing:d.pricing})}return u?.pricing},remove(o,a){let s=e.delete(Ne(o,a));if(s){let i=r.get(o);i?.delete(a),i&&i.size===0&&r.delete(o)}return s},entries(){let o=e.values();return(function*(){for(let{provider:a,model:s,pricing:i}of o)yield[a,s,i]})()}}}function ir(t,e="USD"){return(r,n)=>{let o=t.lookup(n.provider,n.model);return o?We(r,o,{tier:n.tier,withBreakdown:n.withBreakdown}):Ae(e)}}function lr(...t){return(e,r)=>{for(let n of t){let o=n(e,r);if(o.total!==0)return o}return t.length>0?t[0](e,r):Ae()}}function dr(t,e,r){return t?.pricing?We(e,t.pricing,r):Ae()}function Ke(t,e={}){let r=e.breaker??ft(e),n=V(t,{async invoke(o,a){if(!r.canExecute())throw new Re;try{let s=await se(k(t.invoke(o,a)));return r.recordSuccess(),s}catch(s){throw r.recordFailure(s),s}},async*stream(o,a){if(!r.canExecute())throw new Re;try{for await(let s of t.stream(o,a))yield s;r.recordSuccess()}catch(s){throw r.recordFailure(s),s}}});return U(n,"withBreaker",t),{adapter:n,breaker:r}}var Ce=class extends Error{constructor(r,n,o){super(`Budget exhausted: ${r} (limit=${n}, observed=${o})`);this.which=r;this.limit=n;this.observed=o}name="BudgetExhaustedError"},Ve=Object.freeze({calls:0,inputTokens:0,outputTokens:0,usd:0}),At=()=>({calls:0,inputTokens:0,outputTokens:0,usd:0});function Ue(t,e){let r=pe(void 0,{name:e.name?`${e.name}/log`:"budgetGate/log",maxSize:e.logMax??1e3}),n=w(At(),{name:e.name?`${e.name}/totals`:"budgetGate/totals"}),o=v([n],([l])=>{let d=l;return!(e.caps.calls!=null&&d.calls>=e.caps.calls||e.caps.inputTokens!=null&&d.inputTokens>=e.caps.inputTokens||e.caps.outputTokens!=null&&d.outputTokens>=e.caps.outputTokens||e.caps.usd!=null&&d.usd>=e.caps.usd)},{name:e.name?`${e.name}/isOpen`:"budgetGate/isOpen",initial:!0});if(j(o),e.onExhausted!=null){let l=e.onExhausted,d=!1,m=!0;o.subscribe(p=>{for(let c of p)if(c[0]===G){let g=c[1];if(d&&m&&g===!1){let y=Ct(n.cache??Ve,e.caps);y&&l(y)}m=g,d=!0}})}let a=()=>{if(o.cache===!1){let l=n.cache??Ve,d=Ct(l,e.caps);return new Ce(d??"budget",e.caps[d??"calls"]??0,ur(l,d??"calls"))}},s=(l,d)=>{let m=t.provider,p=de({provider:m,model:d.model,tier:d.tier,usage:l,startNs:d.startNs,method:d.method,...d.error?{error:d.error}:{}});r.append(p);let c=n.cache??Ve,g=e.pricingFn?c.usd+e.pricingFn(l,{model:d.model,provider:m,tier:d.tier}).total:c.usd;n.emit({calls:c.calls+1,inputTokens:c.inputTokens+z(l),outputTokens:c.outputTokens+ne(l),usd:g})},i=()=>{r.clear(),n.emit(At())},u=V(t,{invoke(l,d){let m=a();if(m)return Promise.reject(m);let p=H(),c=t.model??d?.model??"",g=f=>(s(f.usage??ee(),{model:t.model??d?.model??f.model??"",tier:d?.tier??f.tier,startNs:p,method:"invoke"}),f),y=f=>{let h=f;s(ee(),{model:c,tier:d?.tier,startNs:p,method:"invoke",error:{type:h?.name??"Error",message:h?.message??String(f)}})};return Le(t.invoke(l,d),{onResp:g,onError:y,name:"budgetGate/invokeTap"})},async*stream(l,d){let m=a();if(m)throw m;let p=H(),c;try{for await(let g of t.stream(l,d))g.type==="usage"&&(c=g.usage),yield g;s(c??ee(),{model:t.model??d?.model??"",tier:d?.tier,startNs:p,method:"stream"})}catch(g){let y=g;throw s(c??ee(),{model:t.model??d?.model??"",tier:d?.tier,startNs:p,method:"stream",error:{type:y?.name??"Error",message:y?.message??String(g)}}),g}}});return U(u,"withBudgetGate",t),{adapter:u,budget:{totals:n,isOpen:o,log:r,reset:i}}}function Ct(t,e){if(e.calls!=null&&t.calls>=e.calls)return"calls";if(e.inputTokens!=null&&t.inputTokens>=e.inputTokens)return"inputTokens";if(e.outputTokens!=null&&t.outputTokens>=e.outputTokens)return"outputTokens";if(e.usd!=null&&t.usd>=e.usd)return"usd"}function ur(t,e){switch(e){case"calls":return t.calls;case"inputTokens":return t.inputTokens;case"outputTokens":return t.outputTokens;case"usd":return t.usd}}function mr(t,e){let r=e.mock??Fe({provider:t.provider,model:t.model}),n=typeof e.enabled=="boolean"?e.enabled:void 0,o=n===void 0?k(e.enabled):void 0,a;o&&(a=j(o));let s=()=>n!==void 0?n:!!o?.cache,i=V(t,{invoke(l,d){return s()?r.invoke(l,d):t.invoke(l,d)},stream(l,d){return s()?r.stream(l,d):t.stream(l,d)}});return U(i,"withDryRun",t),{adapter:i,dispose:()=>{a&&(a(),a=void 0)}}}function qe(t){if(t==null||typeof t!="object")return;let e=t,r=e.status,n=cr(e.headers);if(r!==429&&r!==503&&!br(e.message))return;let o={},a=n("retry-after"),s=fr(a);s!=null&&(o.retryAfterMs=s);let i=n("anthropic-ratelimit-requests-reset");if(i){let c=St(i);c!=null&&(o.retryAfterMs=Math.max(o.retryAfterMs??0,c))}let u=n("anthropic-ratelimit-tokens-reset");if(u){let c=St(u);c!=null&&(o.retryAfterMs=Math.max(o.retryAfterMs??0,c))}let l=Se(n,"x-ratelimit-limit-requests");l!=null&&(o.rpmCap=l);let d=Se(n,"x-ratelimit-limit-tokens");d!=null&&(o.tpmCap=d);let m=Se(n,"x-ratelimit-remaining-requests"),p=Se(n,"x-ratelimit-remaining-tokens");if(m!=null&&l!=null&&l>0&&(o.usageHint??={},o.usageHint.rpm=1-m/l),p!=null&&d!=null&&d>0&&(o.usageHint??={},o.usageHint.tpm=1-p/d),o.retryAfterMs==null&&e.message){let c=yr(e.message);c!=null&&(o.retryAfterMs=c)}return e.headers&&(o.metadata={headers:pr(e.headers)}),o.retryAfterMs==null&&o.rpmCap==null&&o.tpmCap==null&&o.usageHint==null?o.metadata?o:void 0:o}function cr(t){if(!t)return()=>{};if(typeof t.get=="function"){let n=t;return o=>n.get(o)??n.get(o.toLowerCase())??void 0}let e=t,r={};for(let[n,o]of Object.entries(e)){let a=Array.isArray(o)?o.join(", "):o;a!=null&&(r[n.toLowerCase()]=a)}return n=>r[n.toLowerCase()]}function pr(t){let e={};if(typeof t.forEach=="function")return t.forEach((r,n)=>{e[n]=r}),e;for(let[r,n]of Object.entries(t))n!=null&&(e[r]=Array.isArray(n)?n.join(", "):n);return e}function Se(t,e){let r=t(e);if(r==null)return;let n=Number(r);return Number.isFinite(n)?n:void 0}function fr(t){if(!t)return;let e=t.trim(),r=Number(e);if(Number.isFinite(r)&&r>=0)return r*1e3;let n=Date.parse(e);if(Number.isFinite(n)){let o=n-Date.now();if(o>0)return o}}function St(t){if(!t)return;let e=Date.parse(t);if(Number.isFinite(e))return Math.max(0,e-Date.now())}var gr=/retry\s+(?:in|after)\s+(\d+(?:\.\d+)?)\s*(ms|s|sec|seconds?|m|min|minutes?)/i;function yr(t){let e=gr.exec(t);if(!e)return;let r=Number(e[1]);if(!Number.isFinite(r))return;let n=(e[2]??"s").toLowerCase();if(n==="ms")return r;if(n.startsWith("s"))return r*1e3;if(n.startsWith("m"))return r*6e4}var hr=/rate\s*limit|too\s*many\s*requests|quota|429/i;function br(t){return!!t&&hr.test(t)}function He(t){let e=new Error(t);return e.name="AbortError",e}function Ot(t={}){let e=Math.max(1,t.burstMultiplier??1),r=t.clampCooldownMs??6e4,n=t.rpm!=null?k(t.rpm):w(Number.POSITIVE_INFINITY),o=t.tpm!=null?k(t.tpm):w(Number.POSITIVE_INFINITY),a=w(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/signalRpmCap"}),s=w(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/signalTpmCap"}),i=w({},{name:"adaptiveRateLimiter/lastSignal"}),u=v([n,a],([T,I])=>Math.min(Number(T??1/0),Number(I??1/0)),{name:"adaptiveRateLimiter/effectiveRpm"}),l=v([o,s],([T,I])=>Math.min(Number(T??1/0),Number(I??1/0)),{name:"adaptiveRateLimiter/effectiveTpm"}),d=fe(Number(n.cache??Number.POSITIVE_INFINITY),e),m=fe(Number(o.cache??Number.POSITIVE_INFINITY),e),p=!1,c=!1,g=u.subscribe(T=>{for(let I of T)if(I[0]===G){let _=Number(I[1]);Number.isFinite(_)&&_>0?(d=fe(_,e),p=!1):_===1/0?(d=fe(1/0,e),p=!1):_<=0&&(p=!0)}}),y=l.subscribe(T=>{for(let I of T)if(I[0]===G){let _=Number(I[1]);Number.isFinite(_)&&_>0?(m=fe(_,e),c=!1):_===1/0?(m=fe(1/0,e),c=!1):_<=0&&(c=!0)}}),f=0,h=new Z,b=new Z,N;t.adaptation!=null&&(N=k(t.adaptation).subscribe(I=>{for(let _ of I)_[0]===G&&A(_[1])}));function A(T){if(i.emit(T),T.rpmCap!=null&&Number.isFinite(T.rpmCap)&&T.rpmCap>=0&&(a.emit(T.rpmCap),Number.isFinite(r)&&r>0&&h.start(r,()=>a.emit(Number.POSITIVE_INFINITY))),T.tpmCap!=null&&Number.isFinite(T.tpmCap)&&T.tpmCap>=0&&(s.emit(T.tpmCap),Number.isFinite(r)&&r>0&&b.start(r,()=>s.emit(Number.POSITIVE_INFINITY))),T.retryAfterMs!=null&&T.retryAfterMs>0){let I=H()+T.retryAfterMs*1e6;I>f&&(f=I)}}let C=w(0,{name:"adaptiveRateLimiter/pending"}),R=w(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/rpmAvailable"}),D=w(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/tpmAvailable"}),P=T=>{C.emit((C.cache??0)+T)},S=()=>{R.emit(d.available()),D.emit(m.available())};async function E(T={}){let I=T.requestCost??1,_=T.tokenCost??0,K=T.signal;P(1);try{for(;;){if(K?.aborted)throw He("AdaptiveRateLimiter.acquire aborted");let te=H();if(f>te){let M=Math.ceil((f-te)/1e6);await Ee(M,K);continue}if(I>0&&p||_>0&&c){await Ee(250,K);continue}let ie=d,ue=m;if(!ie.tryConsume(I)){await Ee(Et(ie,I),K);continue}if(!(_>0?ue.tryConsume(_):!0)){ie.putBack(I),await Ee(Et(ue,_),K);continue}S();return}}finally{P(-1)}}function O(T){T>0?m.tryConsume(T):T<0&&m.putBack(-T),S()}function F(){g(),y(),N?.(),h.cancel(),b.cancel()}return{effectiveRpm:u,effectiveTpm:l,lastSignal:i,pending:C,rpmAvailable:R,tpmAvailable:D,acquire:E,recordUsage:O,recordSignal:A,dispose:F}}function fe(t,e){if(!Number.isFinite(t)||t===1/0)return _e(Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER);let r=Math.max(1,t*e),n=t/60;return _e(r,n)}function Et(t,e){let r=t.available(),n=Math.max(0,e-r);return n<=0?25:Math.min(5e3,Math.max(50,n*100))}function Ee(t,e){return t<=0?Promise.resolve():e?.aborted?Promise.reject(He("AdaptiveRateLimiter.acquire aborted")):new Promise((r,n)=>{let o=new Z,a,s=()=>{o.cancel(),e&&a&&e.removeEventListener("abort",a)};o.start(t,()=>{s(),r()}),e&&(a=()=>{s(),n(He("AdaptiveRateLimiter.acquire aborted"))},e.addEventListener("abort",a,{once:!0}))})}function ze(t,e={}){let r=e.limiter??Ot({name:e.name??"rateLimiter",rpm:e.rpm,tpm:e.tpm,adaptation:e.adaptation,burstMultiplier:e.burstMultiplier}),n=(s,i)=>e.costFn?e.costFn(s,i):0,o=s=>{let i=qe(s);i&&r.recordSignal(i)},a=V(t,{async invoke(s,i){let u=n(s,i);await r.acquire({requestCost:1,tokenCost:u,signal:i?.signal});try{let l=await se(k(t.invoke(s,i))),d=l.usage??Nt(),p=z(d)+ne(d)-u;return p>0&&r.recordUsage(p),l}catch(l){throw o(l),l}},async*stream(s,i){let u=n(s,i);await r.acquire({requestCost:1,tokenCost:u,signal:i?.signal});try{let l=0;for await(let m of t.stream(s,i))m.type==="usage"&&(l=z(m.usage)+ne(m.usage)),yield m;let d=l-u;d>0&&r.recordUsage(d)}catch(l){throw o(l),l}}});return U(a,"withRateLimiter",t),{adapter:a,limiter:r}}function Oe(t="aborted"){let e=new Error(t);return e.name="AbortError",e}function It(t,e){return t<=0?Promise.resolve():e?.aborted?Promise.reject(Oe()):new Promise((r,n)=>{let o=new Z,a,s=()=>{o.cancel(),e&&a&&e.removeEventListener("abort",a)};o.start(t,()=>{s(),r()}),e&&(a=()=>{s(),n(Oe())},e.addEventListener("abort",a,{once:!0}))})}function Ye(t,e={}){let r=e.attempts??3,n=e.baseDelayMs??500,o=e.maxDelayMs??1e4,a=e.strategy??"decorrelated",s=e.jitter??!0,i=e.shouldRetry??Tr,u=e.retryStreaming??!0,l=(m,p)=>{if(a==="decorrelated"){let f=Math.min(o,Math.max(n,p*3));return n+Math.random()*(f-n)}let c=a==="exp"?n*2**(m-1):n*m,g=Math.min(o,c);if(!s)return g;let y=g*(.5+Math.random());return Math.min(o,y)},d=V(t,{async invoke(m,p){if(p?.signal?.aborted)throw Oe();let c,g=n;for(let y=1;y<=r;y++)try{return await se(k(t.invoke(m,p)))}catch(f){if(c=f,y>=r||!i(f,y))throw f;let h=l(y,g);g=h,await It(h,p?.signal)}throw c},async*stream(m,p){if(p?.signal?.aborted)throw Oe();if(!u){for await(let y of t.stream(m,p))yield y;return}let c,g=n;for(let y=1;y<=r;y++){let f=!1;try{for await(let h of t.stream(m,p))f=!0,yield h;return}catch(h){if(c=h,f||y>=r||!i(h,y))throw h;let b=l(y,g);g=b,await It(b,p?.signal)}}throw c}});return U(d,"withRetry",t),d}function Tr(t,e){if(t==null)return!1;let r=t;return r.name==="LLMTimeoutError"?!0:r.name==="AbortError"||r.message==="aborted"||r.name==="DOMException"&&r.code!=null&&Number(r.code)===20||r.name==="BudgetExhaustedError"||r.name==="CircuitOpenError"?!1:r.status!=null?r.status===429||r.status>=500&&r.status<600:r.code&&typeof r.code=="string"&&/^E[A-Z]+$/.test(r.code)?!0:r.message?/network|timeout|socket|fetch|econn|eai_/i.test(r.message):!1}var ge=class extends Error{constructor(r){super(`LLM call timed out after ${r}ms`);this.ms=r}name="LLMTimeoutError"};function Je(t,e){if(e<=0)throw new RangeError("withTimeout: ms must be > 0");let r=a=>{let s=new AbortController,i=!1,u,l=new Z;return a&&(a.aborted?s.abort(a.reason):(u=()=>{l.cancel(),s.abort(a.reason)},a.addEventListener("abort",u,{once:!0}))),l.start(e,()=>{i=!0,s.abort(new ge(e))}),{signal:s.signal,cancel:()=>{l.cancel(),a&&u&&a.removeEventListener("abort",u)},timedOut:()=>i}},n=(a,s)=>{if(!s||a instanceof ge)throw a;let i=a;if(i?.name==="AbortError"||i?.name==="DOMException"&&Number(i.code)===20||a?.message==="aborted"){let l=new ge(e);throw l.cause=a,l}throw a},o=V(t,{async invoke(a,s){let{signal:i,cancel:u,timedOut:l}=r(s?.signal);try{return await se(k(t.invoke(a,{...s,signal:i})))}catch(d){return n(d,l())}finally{u()}},async*stream(a,s){let{signal:i,cancel:u,timedOut:l}=r(s?.signal);try{for await(let d of t.stream(a,{...s,signal:i}))yield d}catch(d){n(d,l())}finally{u()}}});return U(o,"withTimeout",t),o}function Mr(t,e={}){let r={adapter:t},n=t;if(e.rateLimit){let o=ze(n,e.rateLimit);n=o.adapter,r.rateLimiter=o.limiter}if(e.budget){let o=Ue(n,e.budget);n=o.adapter,r.budget=o.budget}if(e.breaker){let o=Ke(n,e.breaker);n=o.adapter,r.breaker=o.breaker}if(e.timeoutMs!=null&&(n=Je(n,e.timeoutMs)),e.retry&&(n=Ye(n,e.retry)),e.fallback){if(e.name==="fallback")throw new RangeError('resilientAdapter: `name` cannot be "fallback" \u2014 collides with the secondary tier label.');let o={};e.onFallback&&(o.onFallback=e.onFallback),e.onExhausted&&(o.onExhausted=e.onExhausted),n=Be([{name:e.name??"primary",adapter:n},{name:"fallback",adapter:e.fallback}],o)}return e.cache&&(n=Ge(n,e.cache)),r.adapter=n,r}function L(t,e){return dt("ai",t,e)}function vr(t){return t!=null&&typeof t.then=="function"}function Qe(t){return typeof t=="object"&&t!==null&&"subscribe"in t&&typeof t.subscribe=="function"&&"cache"in t}function kr(t){return t!=null&&typeof t=="object"&&Symbol.asyncIterator in t&&typeof t[Symbol.asyncIterator]=="function"}var Rr=3e4;function Dt(t,e){if(t.status==="settled"){let n=t.cache;if(n!==void 0)return Promise.resolve(n)}let r=e?.timeoutMs??Rr;return new Promise((n,o)=>{let a=new Z,s=t.subscribe(i=>{for(let u of i){if(u[0]===G){a.cancel(),s(),n(u[1]);return}if(u[0]===W){a.cancel(),s(),o(u[1]);return}if(u[0]===q){a.cancel(),s(),o(new Error("firstDataFromNode: completed without producing a value"));return}}});a.start(r,()=>{s(),o(new Error(`firstDataFromNode: timed out after ${r}ms`))})})}async function Me(t){return vr(t)?Me(await t):Qe(t)?Dt(t):kr(t)?Dt(k(t)):t}function ye(t){let e=t.match(/^```(?:json)?\s*([\s\S]*?)\s*```[\s\S]*$/);return e?e[1]:t}function co(t,e,r){return Q(n=>{let o=new AbortController,a=!1,s=null,i=d=>{a||(a=!0,n.down([[G,d],[q]]),s?.(),s=null)},u;try{u=t.invoke(e,{...r.invokeOpts,signal:o.signal})}catch(d){return i(r.onFailure("throw",d)),()=>o.abort()}return s=k(u,{signal:o.signal}).subscribe(d=>{for(let m of d){if(a)return;if(m[0]===G){try{i(r.onSuccess(m[1]))}catch(p){i(r.onFailure("onSuccess-threw",p))}return}if(m[0]===W){i(r.onFailure("error",m[1]));return}if(m[0]===q){i(r.onFailure("complete",void 0));return}}}),a&&s&&(s(),s=null),()=>{o.abort(),s?.(),s=null}})}function xr(t,e){let r=k(t),n=e?.refreshTrigger!=null?k(e.refreshTrigger):null,o=e?.name!==void 0?{name:e.name}:void 0,a=X("frozenContext",o);return n==null?le([r],(s,i,u)=>{if(u.store.emitted===!0)return;let d=s[0],m=d!=null&&d.length>0?d.at(-1):u.prevData[0];if(m!==void 0)return u.store.emitted=!0,i.emit(m),{invalidate:()=>{u.store.emitted=!1}}},{name:e?.name??"frozenContext",describeKind:"derived",initial:null,meta:L("frozen_context",{...a})}):le([r,n],(s,i,u)=>{let l=s[1];if(!(l!=null&&l.length>0))return;let m=s[0],p=m!=null&&m.length>0?m.at(-1):u.prevData[0];i.emit(p)},{name:e?.name??"frozenContext",describeKind:"derived",initial:null,meta:L("frozen_context",{...a})})}function Pt(t){return t!=null&&typeof t=="object"&&"content"in t?String(t.content):typeof t=="string"?t:String(t)}function wr(t,e=200){return t.length<=e?t:`${t.slice(0,e)}\u2026`}function Xe(t,e,r,n){let o=n?.format??"text",a=n?.name??"prompt_node";n?.tools!==void 0&&o!=="raw"&&console.warn("promptNode: `tools` is set but `format !== 'raw'`. Tool calls in the response will be silently dropped \u2014 set `format: 'raw'` to receive the full LLMResponse with `toolCalls`.");let s=e.length,i=n?.tools!==void 0?[...e,n.tools]:e,u=v(i,d=>{let m=d.slice(0,s),p=n?.tools!==void 0?d[s]:void 0;if(m.some(g=>g==null))return{messages:[],tools:p};let c=typeof r=="string"?r:r(...m);return c?{messages:[{role:"user",content:c}],tools:p}:{messages:[],tools:p}},{name:`${a}::messages`,meta:L("prompt_node")});return $(u,d=>{let{messages:m,tools:p}=d;return!m||m.length===0?w(null):Q(c=>{let g=!1,y=!1,f,h={model:n?.model,temperature:n?.temperature,maxTokens:n?.maxTokens,systemPrompt:n?.systemPrompt,...p!==void 0?{tools:p}:{}};if(n?.abort){let C=bt(n.abort);h.signal=C.signal,f=C.dispose}let b;try{b=t.invoke(m,h)}catch(C){return g=!0,c.down([[W,C]]),()=>{f?.()}}let A=k(b).subscribe(C=>{if(!(y||g))for(let R of C){if(g)return;if(R[0]===G){let D=R[1];if(o==="raw")c.emit(D);else try{let P=Pt(D),S=o==="json"?JSON.parse(ye(P)):P;c.emit(S)}catch(P){let S=Pt(D),E=new Error(`promptNode: failed to parse LLM response as JSON: ${P.message}
2
+ Raw content (first 200 chars): ${wr(S)}`);g=!0,c.down([[W,E]]);return}}else if(R[0]===W){g=!0,c.down([[W,R[1]]]);return}else if(R[0]===q){g=!0,c.down([[q]]);return}else c.down([R])}});return()=>{y=!0,A(),f?.()}},{name:`${a}::call`,meta:L("prompt_node::call")})},{name:`${a}::output`,meta:n?.meta?{...L("prompt_node::output"),...n.meta}:L("prompt_node::output")})}function Ze(t,e,r,n){let o=r.name??n;return a=>{let s=w(a);return Xe(r.adapter,[s],i=>e(i),{name:o,format:"json",systemPrompt:t,model:r.model,temperature:r.temperature??0,maxTokens:r.maxTokens})}}function et(t,e){let r=e.maxExistingKeys??100,n=Ze(t,o=>JSON.stringify({input:o.raw,existingKeys:o.existingKeys}),e,"llmExtractor");return(o,a)=>{let s=r===Number.POSITIVE_INFINITY?[...a.keys()]:[...a.keys()].slice(0,r);return n({raw:o,existingKeys:s})}}function tt(t,e){let r=Ze(t,n=>JSON.stringify({memories:n}),e,"llmConsolidator");return n=>{let o=[...n.entries()].map(([a,s])=>({key:a,value:s}));return r(o)}}async function _t(t,e,r,n){let o="",a=0;for await(let s of t.stream(e,r))n.publish({...s,seq:a++,ts:be()}),s.type==="token"&&(o+=s.delta);return o}function jt(t,e){if(e==="json")try{return JSON.parse(ye(t))}catch(r){let n=t.slice(0,160);throw new Error(`streamingPromptNode: format:"json" \u2014 failed to parse accumulated text as JSON: ${r.message}; content preview: ${n}`)}return t}function Ft(t,e){return v([t.latest],([r],n)=>{let o=n.store;if(r==null)return o.acc??"";let a=r;return a.seq===0&&(o.acc=""),a.type==="token"&&(o.acc=(o.acc??"")+a.delta),o.acc??""},{name:e,meta:L("accumulated_text"),initial:""})}function Lr(t,e,r,n){let o=n?.name??"llm",a=n?.format??"text",s=$e(`${o}/stream`,{...n?.retainedLimit!=null?{retainedLimit:n.retainedLimit}:{}}),i=v(e,m=>{if(m.some(c=>c==null))return[];let p=typeof r=="string"?r:r(...m);return p?[{role:"user",content:p}]:[]},{name:`${o}::messages`,meta:L("prompt_node::messages"),initial:[]}),u=$(i,m=>{let p=m;if(!p||p.length===0)return w(null);let c=new AbortController;async function*g(){try{let y=await _t(t,p,{model:n?.model,temperature:n?.temperature,maxTokens:n?.maxTokens,systemPrompt:n?.systemPrompt,signal:c.signal},s);yield jt(y,a)}finally{c.abort()}}return k(g())},{meta:X("streamingPromptNode")}),l=Ft(s,`${o}::accumulatedText`),d=j(u);return{output:u,deltaTopic:s,accumulatedText:l,dispose:()=>{d(),s.destroy()}}}function Nr(t,e,r,n,o,a){let s=w(0,{name:`${e}/cancel`}),i=0,u=[...n,s],l=a?.name??e,d=a?.format??"text",m=$e(`${l}/stream`,{...a?.retainedLimit!=null?{retainedLimit:a.retainedLimit}:{}}),p=v(u,D=>{let P=D.slice(0,-1);if(P.some(E=>E==null))return[];let S=typeof o=="string"?o:o(...P);return S?[{role:"user",content:S}]:[]},{name:`${l}::messages`,meta:L("prompt_node::messages"),initial:[]}),c=$(p,D=>{let P=D;if(!P||P.length===0)return w(null);let S=new AbortController;async function*E(){try{let O=await _t(r,P,{model:a?.model,temperature:a?.temperature,maxTokens:a?.maxTokens,systemPrompt:a?.systemPrompt,signal:S.signal},m);yield jt(O,d)}finally{S.abort()}}return k(E())},{meta:X("gatedStream")}),g=Ft(m,`${l}::accumulatedText`),y=ut(c,D=>D!=null);t.add(y,{name:`${e}/raw`});let f=vt(`${e}/gate-graph`);t.mount(`${e}/gate-graph`,f),f.add(y,{name:`${e}/raw`});let h=f.approvalGate(`${e}/gate`,`${e}/raw`,a?.gate),b=j(c),N=j(h.node),A=j(g);t.addDisposer(b),t.addDisposer(N),t.addDisposer(A);let C=h.reject.bind(h),R={...h,reject(D=1){J(()=>{C(D),s.emit(++i)})}};return{output:h.node,deltaTopic:m,accumulatedText:g,gate:R,dispose:()=>{b(),N(),A(),m.destroy()}}}function Ar(t,e){let r=e?.separator??`
3
+
4
+ `,n=t.map(s=>typeof s=="string"?w(s):k(s)),o=v(n,s=>s.filter(i=>i!=null&&i!=="").join(r),{name:e?.name??"systemPrompt",describeKind:"derived",meta:L("system_prompt"),initial:""}),a=j(o);return Object.assign(o,{dispose:a})}var Cr=(t,e)=>t===e?!0:t.chunkCount===e.chunkCount&&t.charCount===e.charCount&&t.estimatedTokens===e.estimatedTokens&&t.estimated===e.estimated;function Sr(t,e){let r=e?.charsPerToken??4,n={chunkCount:0,charCount:0,estimatedTokens:0,estimated:!0};return v([t.latest],([o],a)=>{if(o==null)return n;let s=o;"chunkCount"in a.store||(a.store.chunkCount=0,a.store.charCount=0,a.store.usageTokens=0,a.store.sawUsage=!1);let i=a.store;s.type==="token"?(i.chunkCount+=1,i.charCount+=s.delta.length):s.type==="usage"&&(i.sawUsage=!0,i.usageTokens=z(s.usage)+ne(s.usage));let u=i.sawUsage?i.usageTokens:Math.ceil(i.charCount/r);return{chunkCount:i.chunkCount,charCount:i.charCount,estimatedTokens:u,estimated:!i.sawUsage}},{name:e?.name??"cost-meter",describeKind:"derived",initial:n,meta:L("cost_meter_extractor"),equals:Cr})}var Er=(t,e)=>{if(t===e)return!0;if(t==null||e==null)return t===e;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++){let n=t[r],o=e[r];if(n.label!==o.label||n.pattern!==o.pattern||n.match!==o.match||n.position!==o.position)return!1}return!0};function Or(t,e){let r=e.maxPatternLength??128;for(let o of e.patterns)if(o.pattern.source.length>r)throw new Error(`keywordFlagExtractor: pattern "${o.label}" literal exceeds maxPatternLength (${o.pattern.source.length} > ${r}); raise the option or shorten the pattern.`);let n=e.patterns.map(o=>({label:o.label,pattern:o.pattern,compiled:new RegExp(o.pattern.source,`${o.pattern.flags.replace("g","")}g`)}));return v([t],([o],a)=>{if(o==null)return[];let s=o;"flags"in a.store||(a.store.flags=[],a.store.scannedTo=0);let i=a.store.flags,u=a.store.scannedTo,l=Math.max(0,u-r),d=s.slice(l),m=!1;for(let{pattern:p,label:c,compiled:g}of n){g.lastIndex=0;for(let y of d.matchAll(g)){let f=l+(y.index??0);f+y[0].length<=u||(i.push({label:c,pattern:p,match:y[0],position:f}),m=!0)}}return a.store.scannedTo=s.length,m?[...i]:i.slice()},{name:e.name??"keyword-flag-extractor",describeKind:"derived",initial:[],meta:L("keyword_flag_extractor"),equals:Er})}function Ir(t,e,r){return v([t],([n])=>n==null?null:e(n),{name:r?.name??"extractor",describeKind:"derived",initial:null,meta:L("stream_extractor"),...r?.equals?{equals:r.equals}:{}})}var Dr=(t,e)=>{if(t===e)return!0;if(t==null||e==null)return t===e;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++){let n=t[r],o=e[r];if(n.startIndex!==o.startIndex||n.name!==o.name||n.raw!==o.raw)return!1}return!0};function Pr(t,e){return v([t],([r],n)=>{if(r==null)return[];let o=r;"calls"in n.store||(n.store.calls=[],n.store.scanFrom=0);let a=n.store.calls,s=n.store.scanFrom,i=!1;for(;s<o.length;){let u=o.indexOf("{",s);if(u===-1){n.store.scanFrom=o.length;break}let l=0,d=-1,m=!1;for(let c=u;c<o.length;c++){let g=o[c];if(m)g==="\\"&&c+1<o.length?c++:g==='"'&&(m=!1);else if(g==='"')m=!0;else if(g==="{")l++;else if(g==="}"&&(l--,l===0)){d=c;break}}if(d===-1){n.store.scanFrom=u;break}let p=o.slice(u,d+1);try{let c=JSON.parse(p);typeof c.name=="string"&&c.arguments!=null&&typeof c.arguments=="object"&&(a.push({name:c.name,arguments:c.arguments,raw:p,startIndex:u}),i=!0)}catch{}s=d+1,n.store.scanFrom=s}return i?[...a]:a.slice()},{name:e?.name??"tool-call-extractor",describeKind:"derived",initial:[],meta:L("tool_call_extractor"),equals:Dr})}function _r(t,e,r,n){let o=r*(n?.hardMultiplier??1.5),a=typeof e!="function",s=[t];return a&&s.push(e),v(s,i=>{let u=i[0]??"";if(u.length===0)return"allow";let l=a?i[1]??0:e(u);return l>=o?"block":l>=r?"review":"allow"},{name:n?.name??"content-gate",initial:"allow"})}function jr(t,e,r,n){let o=r??(()=>"[REDACTED]");function a(s){let i=s;for(let u of e){let l=u.global?u:new RegExp(u.source,`${u.flags}g`);i=i.replace(l,d=>o(d,u))}return i}return v([t],([s])=>a(s??""),{name:n?.name??"redactor",initial:""})}var Ie=class extends ae{_log;messages;latest;messageCount;constructor(e,r={}){super(e,r.graph),this._log=pe([],{name:"messages",maxSize:r.maxMessages}),this.messages=this._log.entries,this.add(this.messages,{name:"messages"}),this.latest=v([this.messages],([n])=>{let o=n;return o.length===0?null:o[o.length-1]},{name:"latest",describeKind:"derived",meta:L("chat_latest")}),this.add(this.latest,{name:"latest"}),this.addDisposer(j(this.latest)),this.messageCount=v([this.messages],([n])=>n.length,{name:"messageCount",describeKind:"derived",meta:L("chat_message_count"),initial:0}),this.add(this.messageCount,{name:"messageCount"}),this.addDisposer(j(this.messageCount))}append(e,r,n){this._log.append({role:e,content:r,...n})}appendToolResult(e,r){this._log.append({role:"tool",content:r,toolCallId:e})}clear(){this._log.clear()}allMessages(){return this.messages.cache}};function rt(t,e){return new Ie(t,e)}function Fr(t,e,r){let n=k(t),o=r?.condition!=null?k(r.condition):null,a=w(null,{name:r?.name?`${r.name}::null`:"handoff::null"});if(o==null)return $(n,i=>{if(i==null)return a;let u=w(i);return e(u)},{meta:X("handoff")});let s=v([n,o],([i,u])=>({v:i,open:u===!0}),{name:r?.name?`${r.name}::router`:"handoff::router",describeKind:"derived"});return $(s,({v:i,open:u})=>{if(i==null)return a;if(!u)return w(i);let l=w(i);return e(l)},{meta:X("handoff")})}function nt(t){let{toolCalls:e,tools:r}=t,n=t.retryCount??1,o=t.onError??"rescue",a=(s,i)=>{if(s===i)return!0;if(s.length!==i.length)return!1;for(let u=0;u<s.length;u++){let l=s[u],d=i[u];if(l?.id!==d?.id||l?.content!==d?.content)return!1}return!0};return $(e,s=>{if(s==null||s.length===0)throw new Error("toolExecution: received an empty tool-call batch as DATA \u2014 callers must upstream-filter empty batches (emit RESOLVED) so switchMap is only dispatched for non-empty batches.");let i=s.map(u=>Gr(u,r,n,o));return v(i,u=>u,{name:"toolExecution::batch",equals:a})})}function Gr(t,e,r,n){let o=pt(()=>e.executeReactive(t.name,t.arguments),{count:r}),a=v([o],([s])=>({id:t.id,content:typeof s=="string"?s:JSON.stringify(s)}));return n==="propagate"?a:ct(a,s=>({id:t.id,content:JSON.stringify({error:String(s)})}))}var De=class extends ae{definitions;schemas;_bundle;constructor(e,r={}){super(e,r.graph),this._bundle=xe({name:"definitions"}),this.definitions=this._bundle.entries,this.add(this.definitions,{name:"definitions"}),this.schemas=v([this.definitions],([n])=>[...(n??new Map).values()],{name:"schemas",describeKind:"derived",meta:L("tool_schemas"),initial:[]}),this.add(this.schemas,{name:"schemas"}),this.addDisposer(j(this.schemas))}register(e){this._bundle.set(e.name,e)}unregister(e){this._bundle.delete(e)}executeReactive(e,r){let n=this._bundle.get(e);if(!n)throw new Error(`toolRegistry: unknown tool "${e}"`);return Q(o=>{let a=new AbortController,s;try{let u=n.handler(r,{signal:a.signal});s=Br(u,a.signal)}catch(u){return o.down([[W,u]]),()=>{a.abort()}}let i=s.subscribe(u=>{o.down(u)});return()=>{a.abort(),i()}},{name:`executeReactive::${e}`,meta:L("tool_execute_reactive")})}getDefinition(e){return this._bundle.entries.cache?.get(e)}};function ot(t,e){return new De(t,e)}function Br(t,e){return Qe(t)?t:t!=null&&typeof t.then=="function"?je(t,{signal:e}):t!=null&&typeof t=="object"&&Symbol.asyncIterator in t?yt(t,{signal:e}):je(Promise.resolve(t),{signal:e})}function $r(t,e,r){let n=k(t),o=e.map(s=>k(s)),a=[n,...o];return v(a,s=>{let i=s[0]??[],u=s.slice(1);return i.filter(l=>{for(let d of u)if(d!=null&&!d(l))return!1;return!0})},{name:r?.name??"tool-selector",describeKind:"derived",meta:{...L("tool_selector"),...X("toolSelector")},equals:(s,i)=>{let u=s,l=i;if(u.length!==l.length)return!1;for(let d=0;d<u.length;d++)if(u[d]!==l[d])return!1;return!0}})}function Gt(t){let e=t.thresholds??{};return r=>{let n=t.scoreFn(r);for(let o of Object.keys(e)){let a=e[o];if(a===void 0)continue;let s=n[o];if((Number.isFinite(s)?s:Number.NEGATIVE_INFINITY)<a)return!1}return!0}}function Wr(t){let e={persistence:t.persistenceThreshold??.3,personalValue:t.personalValueThreshold??.3},r=Gt({scoreFn:t.scoreFn,thresholds:e});return t.requireStructured?n=>{if(!r(n))return!1;let o=t.scoreFn(n).structure;return Number.isFinite(o)&&o>0}:r}function at(t,e,r){let n=xt({dimension:r.dimension});t.add(n.entries,{name:"vectorIndex"});let a=re([e.store.entries],([s])=>{let i=s??new Map;for(let[u,l]of i){let d=r.embedFn(l);d&&n.upsert(u,d,l)}}).subscribe(()=>{});return t.addDisposer(a),{vectors:n,dispose:()=>a()}}function st(t,e,r,n){let o=n.mountPath??r,a=wt(`${r}-kg`);if(t.mount(o,a),!n.entityFn)return{kg:a,dispose:()=>{}};let s=n.entityFn,u=re([e.store.entries],([l])=>{let d=l??new Map;for(let[m,p]of d){let c=s(m,p);if(c){for(let g of c.entities??[])a.upsertEntity(g.id,g.value);for(let g of c.relations??[])a.link(g.from,g.to,g.relation,g.weight)}}}).subscribe(()=>{});return t.addDisposer(u),{kg:a,dispose:()=>u()}}function it(t,e,r){let n=r.decayRate??we,o=r.maxActive??1e3,a=r.archiveThreshold??.1,s=r.permanentFilter??(()=>!1),i=Rt("permanent",{ranked:!1});t.mount("permanent",i);let u=new Set,l=b=>u.has(b)?"permanent":(e.store.entries.cache??new Map).has(b)?"active":"archived",d=(b,N)=>{u.add(b),i.upsert(b,N)},m=new Map,p=e.store.entries,c=r.context?k(r.context):w(null),y=re([p,c],([b,N])=>{let A=b??new Map,C=H(),R=[],D=[];for(let[S,E]of A){if(m.has(S)||m.set(S,C),s(S,E)){D.push({key:S,value:E});continue}let O=r.score(E,N),F=m.get(S)??C,T=Number(C-F)/1e9;Mt(O,T,n)<a&&R.push(S)}for(let S of m.keys())A.has(S)||m.delete(S);for(let{key:S,value:E}of D)u.has(S)||d(S,E);let P=A.size-u.size;if(P>o){let S=[...A.entries()].filter(([O])=>!u.has(O)).map(([O,F])=>({key:O,score:r.score(F,N)})).sort((O,F)=>O.score-F.score),E=P-o;for(let O=0;O<E&&O<S.length;O++){let F=S[O].key;R.includes(F)||R.push(F)}}R.length>0&&J(()=>{for(let S of R)e.store.delete(S)})}).subscribe(()=>{}),f=null;r.archiveTier&&(f=t.attachSnapshotStorage([r.archiveTier],r.archiveStorageOptions??{}));let h=()=>{y(),f?.dispose()};return t.addDisposer(h),{tiers:{permanent:i,activeEntries:p,archiveHandle:f,tierOf:l,markPermanent:d},dispose:h}}function Kr(t,e){if(!t||!e)return 0;let r=Math.min(t.length,e.length),n=0;for(;n<r&&t[n]===e[n];)n++;return n}function lt(t,e,r,n,o){let a=o.topK??20,s=o.graphDepth??1,i=o.budget??2e3,u=o.contextWeight??0,l=o.context?k(o.context):w(null),d=(f,h,b)=>{let N=new Map,A=[];if(r&&b.vector){let E=b.vector,O=r.entries.cache;if(O&&O.size>0&&a>0){A=[...O.values()].map(T=>({id:T.id,score:kt(E,T.vector),...T.meta!==void 0?{meta:T.meta}:{}})).sort((T,I)=>I.score-T.score).slice(0,a);for(let T of A){let I=f.get(T.id);I&&N.set(T.id,{value:I,sources:new Set(["vector"])})}}}let C=[];if(n){let E=n.adjacencyOut.cache,O=n.adjacencyIn.cache,F=[...b.entityIds??[],...N.keys()],T=new Set,I=F;for(let _=0;_<s;_++){let K=[];for(let te of I){if(T.has(te))continue;T.add(te);let ie=E?.get(te)??[],ue=O?.get(te)??[];for(let me of ie){let x=me.to;if(!T.has(x)){K.push(x);let M=f.get(x);if(M){let B=N.get(x);B?B.sources.add("graph"):N.set(x,{value:M,sources:new Set(["graph"])}),C.push(x)}}}for(let me of ue){let x=me.from;if(!T.has(x)){K.push(x);let M=f.get(x);if(M){let B=N.get(x);B?B.sources.add("graph"):N.set(x,{value:M,sources:new Set(["graph"])}),C.push(x)}}}}I=K}}for(let[E,O]of f)N.has(E)||N.set(E,{value:O,sources:new Set(["store"])});let R=b.context?.length??0,D=[];for(let[E,{value:O,sources:F}]of N){let T=o.contextOf?o.contextOf(O):void 0,I=o.score(O,h);if(u>0&&R>0){let K=Kr(b.context,T);K>0&&(I=I*(1+u*K/R))}let _=T?{key:E,value:O,score:I,sources:[...F],context:T}:{key:E,value:O,score:I,sources:[...F]};D.push(_)}D.sort((E,O)=>O.score-E.score);let P=[],S=0;for(let E of D){let O=o.cost(E.value);if(S+O>i&&P.length>0)break;P.push(E),S+=O}return{packed:P,trace:{vectorCandidates:A,graphExpanded:C,ranked:D,packed:P}}},m=(f,h)=>{if(f===h)return!0;if(f.length!==h.length)return!1;for(let b=0;b<f.length;b++)if(f[b]!==h[b])return!1;return!0},p=w([],{name:"retrieval",describeKind:"state",meta:L("retrieval_pipeline"),equals:m});t.add(p,{name:"retrieval"});let c=w(null,{name:"retrievalTrace",describeKind:"state",meta:L("retrieval_trace")});return t.add(c,{name:"retrievalTrace"}),{retrieval:p,retrievalTrace:c,retrieve:f=>{let h=e.store.entries.cache??new Map,{packed:b,trace:N}=d(h,l.cache,f);return J(()=>{p.emit(b),c.emit(N)}),b},retrieveReactive:f=>{let h=k(f),b=v([e.store.entries,l,h],([C,R,D])=>{if(D==null)return{packed:[],trace:null};let P=C??new Map,{packed:S,trace:E}=d(P,R,D);return{packed:S,trace:E}},{name:"retrievalReactive::result",describeKind:"derived",meta:L("retrieval_reactive_result"),initial:{packed:[],trace:null}}),A=re([b],([C])=>{let R=C;J(()=>{p.emit(R.packed),R.trace&&c.emit(R.trace)})}).subscribe(()=>{});return t.addDisposer(A),v([b],([C])=>C.packed,{name:"retrievalReactive",describeKind:"derived",meta:L("retrieval_reactive"),initial:[],equals:m})}}}var Pe=class extends ae{chat;tools;status;turn;aborted;lastResponse;toolCalls;toolResults;_terminalResult;_disposeRunWiring;_running=!1;_currentAbortController=null;constructor(e,r){if(super(e,r.graph),this.chat=rt(`${e}-chat`,{maxMessages:r.maxMessages}),this.mount("chat",this.chat),this.tools=ot(`${e}-tools`),this.mount("tools",this.tools),r.tools)for(let x of r.tools)this.tools.register(x);this.status=w("idle",{name:"status",describeKind:"state",meta:L("agent_status")}),this.add(this.status,{name:"status"}),this.turn=w(0,{name:"turn",describeKind:"state",meta:L("agent_turn_count")}),this.add(this.turn,{name:"turn"}),this.aborted=w(!1,{name:"aborted",describeKind:"state",meta:L("agent_aborted")}),this.add(this.aborted,{name:"aborted"});let n=0,o=this.turn.subscribe(x=>{for(let M of x)M[0]===G&&(n=M[1])}),a=!1,s=this.aborted.subscribe(x=>{for(let M of x)M[0]===G&&(a=M[1])}),i=this.chat.messages.cache??[],u=this.chat.messages.subscribe(x=>{for(let M of x)M[0]===G&&(i=M[1])}),l=this.tools.schemas.cache??[],d=this.tools.schemas.subscribe(x=>{for(let M of x)M[0]===G&&(l=M[1])}),m=r.adapter,p=r.systemPrompt,c=r.model,g=r.temperature,y=r.maxTokens,f=r.maxTurns??10,h=r.stopWhen,b=this.chat,N=this.tools,A=this.status,C=this.turn,R=this.aborted,D=le([A],(x,M,B)=>{if(ve(x,B.prevData,0,"idle")!=="thinking"||a||n>=f){M.down([[ce]]);return}if(i.length===0){M.down([[ce]]);return}M.emit({messages:i,tools:l})},{name:"promptInput",describeKind:"derived",meta:L("agent_prompt_input",{closureReads:["aborted","turn","chat.messages","tools.schemas"]})}),P=$(D,x=>{let M=new AbortController;return this._currentAbortController=M,a&&M.abort(new Error("agentLoop: aborted")),k(m.invoke(x.messages,{tools:x.tools.length>0?x.tools:void 0,systemPrompt:p,model:c,temperature:g,maxTokens:y,signal:M.signal}),{signal:M.signal})},{equals:()=>!1}),S=w(null,{name:"lastResponse",describeKind:"state",meta:L("agent_last_response")});this.lastResponse=S;let E=le([S,A],(x,M,B)=>{let Y=ve(x,B.prevData,0,null);if(ve(x,B.prevData,1,"idle")!=="acting"){M.down([[ce]]);return}let oe=Y?.toolCalls;if(oe==null||oe.length===0){M.down([[ce]]);return}M.emit(oe)},{name:"toolCallsRaw",describeKind:"derived",meta:L("agent_tool_calls_raw")}),O=r.interceptToolCalls?r.interceptToolCalls(E):E;this.toolCalls=O;let F=nt({toolCalls:O,tools:N,retryCount:1});this.toolResults=F;let T=re([P],([x])=>{if(a)return;let M=x,B=n+1,Y=M.toolCalls!=null&&M.toolCalls.length>0,he=M.finishReason==="end_turn"&&(!M.toolCalls||M.toolCalls.length===0),oe=h?.(M)===!0,Vt=B>=f,Ut=oe||he||!Y||Vt?"done":"acting";J(()=>{S.emit(M),A.emit(Ut),C.emit(B),b.append("assistant",M.content,{toolCalls:M.toolCalls})})}),I=re([F],([x])=>{if(a)return;let M=x;if(M.length===0)return;let B=n>=f?"done":"thinking";J(()=>{A.emit(B);for(let Y of M)b.appendToolResult(Y.id,Y.content)})}),_=A.cache??"idle",K=A.subscribe(x=>{for(let M of x)M[0]===G&&(_=M[1])}),te=re([R],([x])=>{x===!0&&(this._currentAbortController?.abort(new Error("agentLoop: aborted")),_!=="done"&&A.emit("done"))}),ie=j(T),ue=j(I),me=j(te);this._terminalResult=le([A,S],(x,M,B)=>{let Y=ve(x,B.prevData,0,"idle"),he=ve(x,B.prevData,1,null);if(Y==="done"){if(he!=null){M.emit(he);return}let oe=new Error("agentLoop: aborted");oe.name="AbortError",M.down([[W,oe]]);return}if(Y==="error"){M.down([[W,new Error("agentLoop: errored")]]);return}M.down([[ce]])},{name:"terminalResult",describeKind:"derived",meta:L("agent_terminal_result")}),this.add(D,{name:"promptInput"}),this.add(P,{name:"llmResponse"}),this.add(this.lastResponse,{name:"lastResponse"}),this.toolCalls===E?this.add(this.toolCalls,{name:"toolCalls"}):(this.add(E,{name:"toolCallsRaw"}),this.add(this.toolCalls,{name:"toolCalls"})),this.add(F,{name:"toolResults"}),this.add(this._terminalResult,{name:"terminalResult"}),this.addDisposer(o),this.addDisposer(s),this.addDisposer(K),this.addDisposer(u),this.addDisposer(d),this.addDisposer(ie),this.addDisposer(ue),this.addDisposer(me),this._disposeRunWiring=()=>{}}async run(e,r){if(this._running)throw new RangeError(`agentLoop "${this.name}": run() called while a previous run() is still pending \u2014 await the previous run before starting another, or call abort() first`);this._running=!0;let n;try{J(()=>{this.turn.emit(0),this.aborted.emit(!1),this.status.emit("idle"),this.lastResponse.emit(null)}),e!=null&&this.chat.append("user",e);let o=ht(this._terminalResult,{skipCurrent:!0});if(r!=null)if(r.aborted)this.aborted.emit(!0);else{let a=()=>this.aborted.emit(!0);r.addEventListener("abort",a,{once:!0}),n=()=>r.removeEventListener("abort",a)}return r?.aborted!==!0&&this.status.emit("thinking"),await o}finally{n?.(),this._running=!1,this._currentAbortController=null}}abort(){this.aborted.emit(!0)}destroy(){try{this._disposeRunWiring()}catch{}super.destroy()}};function ve(t,e,r,n){let o=t[r];if(o!=null&&o.length>0)return o[o.length-1];let a=e[r];return a!==void 0?a:n}function Vr(t,e){let r=new Pe(t,e);return r.tagFactory("agentLoop",ke(e)),r}function Ur(t,e,r){let n=new ae(t,r.graph);n.tagFactory("agentMemory",ke(r));let o;if(r.extractFn)o=r.extractFn;else if(r.adapter&&r.extractPrompt)o=et(r.extractPrompt,{adapter:r.adapter});else throw new Error("agentMemory: provide either extractFn or adapter + extractPrompt");let a=(b,N)=>{let A=N.cache??new Map,C=N.subscribe(R=>{for(let D of R)D[0]===G&&(A=D[1])});return n.addDisposer(C),$(b,R=>R==null?{upsert:[]}:o(R,A))},s=e;if(r.admissionFilter){let b=k(e),N=r.admissionFilter;s=v([b],([A])=>{if(N(A))return A},{name:"admissionFilter",describeKind:"derived"})}let i;r.consolidateFn?i=r.consolidateFn:r.adapter&&r.consolidatePrompt&&(i=tt(r.consolidatePrompt,{adapter:r.adapter}));let u=r.consolidateTrigger;if(!u&&i&&r.reflection?.enabled!==!1){let b=r.reflection?.interval??3e5;u=gt(b,{period:b})}let l={score:r.score,cost:r.cost,budget:r.budget??2e3,context:r.context,consolidate:i,consolidateTrigger:u},d=Tt(s,a,l);n.add(d.store.entries,{name:"store"}),n.add(d.compact,{name:"compact"}),n.add(d.size,{name:"size"});let m=null;r.vectorDimensions&&r.vectorDimensions>0&&r.embedFn&&(m=at(n,d,{dimension:r.vectorDimensions,embedFn:r.embedFn}).vectors);let p=null;r.enableKnowledgeGraph&&(p=st(n,d,t,{mountPath:"kg",entityFn:r.entityFn}).kg);let c=null;r.tiers&&(c=it(n,d,{...r.tiers,score:r.score,context:r.context}).tiers);let g=null,y=null,f=null,h=null;if(m||p){let b=lt(n,d,m,p,{score:r.score,cost:r.cost,budget:r.budget,topK:r.retrieval?.topK,graphDepth:r.retrieval?.graphDepth,contextOf:r.contextOf,contextWeight:r.contextWeight,context:r.context});g=b.retrieval,y=b.retrievalTrace,f=b.retrieve,h=b.retrieveReactive}return Object.assign(n,{distillBundle:d,compact:d.compact,size:d.size,vectors:m,kg:p,memoryTiers:c,retrieval:g,retrievalTrace:y,retrieve:f,retrieveReactive:h})}function qr(t,e,r){let n=t.describe({actor:e,detail:"full"}),o=r?.groupByTags??!0,a=r?.separator??`
5
+ `,s=[],i=r?.sinceVersion;for(let[u,l]of Object.entries(n.nodes)){let d=l.meta??{},m=d.description,p=d.format;if(!m&&!p)continue;if(i!=null&&l.v!=null){let h=i.get(u);if(h!=null&&h.id===l.v.id&&l.v.version<=h.version)continue}let c=m??u,g=l.value,y=d.unit,f;p==="currency"&&typeof g=="number"?f=`$${g.toFixed(2)}`:p==="percentage"&&typeof g=="number"?f=`${(g*100).toFixed(1)}%`:g==null?f="(no value)":f=String(g),y&&p!=="currency"&&p!=="percentage"&&(f=`${f} ${y}`),s.push({path:u,description:c,formatted:f})}if(s.length===0)return"";if(o){let u=new Map,l=[];for(let m of s){let c=n.nodes[m.path].meta?.tags;if(c&&c.length>0){let g=c[0],y=u.get(g);y||(y=[],u.set(g,y)),y.push(m)}else l.push(m)}if(u.size===0)return s.map(m=>`- ${m.description}: ${m.formatted}`).join(a);let d=[];for(let[m,p]of[...u.entries()].sort((c,g)=>c[0].localeCompare(g[0])))d.push(`[${m}]${a}${p.map(c=>`- ${c.description}: ${c.formatted}`).join(a)}`);return l.length>0&&d.push(l.map(m=>`- ${m.description}: ${m.formatted}`).join(a)),d.join(a+a)}return s.map(u=>`- ${u.description}: ${u.formatted}`).join(a)}var Bt=`You are a graph architect for GraphReFly, a reactive graph protocol.
6
+
7
+ Given a natural-language description, produce a JSON graph specification with this structure:
8
+
9
+ {
10
+ "name": "<graph_name>",
11
+ "nodes": {
12
+ "<node_name>": {
13
+ "type": "state" | "derived" | "producer" | "effect" | "operator",
14
+ "initial": <initial_value_for_state_nodes>,
15
+ "deps": ["<dep_node_name>", ...],
16
+ "meta": {
17
+ "description": "<human-readable purpose>",
18
+ "type": "string" | "number" | "boolean" | "integer" | "enum",
19
+ "range": [min, max],
20
+ "values": ["a", "b"],
21
+ "format": "currency" | "percentage" | "status",
22
+ "access": "human" | "llm" | "both" | "system",
23
+ "unit": "<unit>",
24
+ "tags": ["<tag>"]
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ Rules:
31
+ - "state" nodes have no deps and hold user/LLM-writable values (knobs). Use "initial" for the starting value.
32
+ - "derived" nodes have deps and compute from them (pure, no side effects).
33
+ - "effect" nodes have deps but produce side effects (no return value).
34
+ - "producer" nodes have no deps but generate values asynchronously.
35
+ - "operator" nodes are parameterized transformations with deps.
36
+ - Use "deps" inside each node to declare dependencies \u2014 no separate "edges" array.
37
+ - meta.description is required for every node.
38
+ - Return ONLY valid JSON, no markdown fences or commentary.`;async function $t(t,e,r){let o=[{role:"system",content:r?.systemPromptExtra?`${Bt}
39
+
40
+ ${r.systemPromptExtra}`:Bt},{role:"user",content:t}],a=e.invoke(o,{model:r?.model,temperature:r?.temperature??0,maxTokens:r?.maxTokens,signal:r?.signal}),i=(await Me(a)).content.trim();i.startsWith("```")&&(i=ye(i));let u;try{u=JSON.parse(i)}catch{throw new Error(`graphFromSpec: LLM response is not valid JSON: ${i.slice(0,200)}`)}return Lt(u,{catalog:r?.catalog})}function Hr(t,e,r){let n=k(t);return $(n,o=>!o||typeof o!="string"||o.trim().length===0?w(null):Q(a=>{let s=new AbortController,i=!1;return $t(o,e,{...r,signal:s.signal}).then(u=>{if(i){u.destroy();return}a.emit(u),a.down([[q]])}).catch(u=>{i||a.down([[W,u]])}),()=>{i=!0,s.abort()}},{name:"graphFromSpec::call"}))}function zr(t){let e={},r=t.type;return r==="enum"&&Array.isArray(t.values)?(e.type="string",e.enum=t.values):r==="integer"?e.type="integer":r==="number"?e.type="number":r==="boolean"?e.type="boolean":r==="string"?e.type="string":e.type=["string","number","boolean"],Array.isArray(t.range)&&t.range.length===2&&(e.minimum=t.range[0],e.maximum=t.range[1]),typeof t.format=="string"&&(e.description=`Format: ${t.format}`),typeof t.unit=="string"&&(e.description?e.description+=` (${t.unit})`:e.description=`Unit: ${t.unit}`),e}function Yr(t,e){let r=t.describe({actor:e,detail:"full"}),n=[],o=[],a=[];for(let[s,i]of Object.entries(r.nodes)){if(i.type!=="state"||s.includes("::__meta__::")||i.status==="completed"||i.status==="errored")continue;let u=i.meta??{},l=u.access;if(l==="human"||l==="system")continue;let d=u.description??`Set the value of ${s}`,m=zr(u),p={type:"object",required:["value"],properties:{value:m},additionalProperties:!1},c=s.replace(/::/g,"__");n.push({type:"function",function:{name:c,description:d,parameters:p}}),o.push({name:s,description:d,inputSchema:p});let g=t,y=e,f=i.v;a.push({name:s,description:d,parameters:p,handler(h){return g.set(s,h.value,y?{actor:y}:void 0),h.value},...f!=null?{version:{id:f.id,version:f.version}}:{}})}return{openai:n,mcp:o,definitions:a}}var Jr=`You are a reactive graph optimizer for GraphReFly.
41
+
42
+ Given a graph's current structure (from describe()) and a problem statement, suggest topology and parameter changes to solve the problem.
43
+
44
+ Return ONLY valid JSON with this structure:
45
+ {
46
+ "summary": "<one-line summary of the strategy>",
47
+ "reasoning": "<explanation of why these changes help>",
48
+ "operations": [
49
+ { "type": "add_node", "name": "<name>", "nodeType": "state|derived|effect|producer|operator", "meta": {...}, "initial": <value> },
50
+ { "type": "remove_node", "name": "<name>" },
51
+ { "type": "connect", "from": "<source>", "to": "<target>" },
52
+ { "type": "disconnect", "from": "<source>", "to": "<target>" },
53
+ { "type": "set_value", "name": "<name>", "value": <new_value> },
54
+ { "type": "update_meta", "name": "<name>", "key": "<meta_key>", "value": <new_value> }
55
+ ]
56
+ }
57
+
58
+ Rules:
59
+ - Only suggest operations that reference existing nodes (for remove/disconnect/set_value/update_meta) or new nodes you define (for add_node).
60
+ - Keep changes minimal \u2014 prefer the smallest set of operations that solves the problem.
61
+ - Return ONLY valid JSON, no markdown fences or commentary.`;async function Wt(t,e,r,n){let{expand:o,...a}=t.describe({actor:n?.actor,detail:"standard"}),s=[{role:"system",content:Jr},{role:"user",content:JSON.stringify({graph:a,problem:e})}],i=r.invoke(s,{model:n?.model,temperature:n?.temperature??0,maxTokens:n?.maxTokens,signal:n?.signal}),l=(await Me(i)).content.trim();l.startsWith("```")&&(l=l.replace(/^```(?:json)?\s*/,"").replace(/\s*```$/,""));let d;try{d=JSON.parse(l)}catch{throw new Error(`suggestStrategy: LLM response is not valid JSON: ${l.slice(0,200)}`)}let m=d;if(typeof m.summary!="string")throw new Error("suggestStrategy: missing 'summary' in response");if(typeof m.reasoning!="string")throw new Error("suggestStrategy: missing 'reasoning' in response");if(!Array.isArray(m.operations))throw new Error("suggestStrategy: missing 'operations' array in response");return{summary:m.summary,reasoning:m.reasoning,operations:m.operations}}function Qr(t,e,r,n){let o=k(e),a=mt(o,t);return $(a,s=>{if(s==null)return w(null);let[i,u]=s;return!u||!i||typeof i!="string"||i.trim().length===0?w(null):u.destroyed?w(null):Q(l=>{let d=new AbortController,m=!1;return Wt(u,i,r,{...n,signal:d.signal}).then(p=>{m||(l.emit(p),l.down([[q]]))}).catch(p=>{m||l.down([[W,p]])}),()=>{m=!0,d.abort()}},{name:"suggestStrategy::call"})})}var Kt=new Set(["state","derived","producer","operator","effect"]);function Xr(t){let e=[];if(t==null||typeof t!="object")return{valid:!1,errors:["Definition must be a non-null object"]};let r=t;if((typeof r.name!="string"||r.name.length===0)&&e.push("Missing or empty 'name' field"),r.nodes==null||typeof r.nodes!="object"||Array.isArray(r.nodes))return e.push("Missing or invalid 'nodes' field (must be an object)"),{valid:!1,errors:e};let n=new Set(Object.keys(r.nodes));for(let[o,a]of Object.entries(r.nodes)){if(a==null||typeof a!="object"){e.push(`Node "${o}": must be an object`);continue}let s=a;if((typeof s.type!="string"||!Kt.has(s.type))&&e.push(`Node "${o}": invalid type "${String(s.type)}" (expected: ${[...Kt].join(", ")})`),Array.isArray(s.deps))for(let i of s.deps)typeof i=="string"&&!n.has(i)&&e.push(`Node "${o}": dep "${i}" does not reference an existing node`)}if(!Array.isArray(r.edges))r.edges!==void 0&&e.push("'edges' must be an array");else{let o=new Set;for(let a=0;a<r.edges.length;a++){let s=r.edges[a];if(s==null||typeof s!="object"){e.push(`Edge [${a}]: must be an object`);continue}let i=s;(typeof i.from!="string"||!n.has(i.from))&&e.push(`Edge [${a}]: 'from' "${String(i.from)}" does not reference an existing node`),(typeof i.to!="string"||!n.has(i.to))&&e.push(`Edge [${a}]: 'to' "${String(i.to)}" does not reference an existing node`);let u=`${i.from}->${i.to}`;o.has(u)&&e.push(`Edge [${a}]: duplicate edge ${u}`),o.add(u)}}return{valid:e.length===0,errors:e}}export{nr as a,or as b,Ae as c,We as d,sr as e,ir as f,lr as g,dr as h,Ke as i,Ce as j,Ue as k,mr as l,qe as m,ze as n,Ye as o,ge as p,Je as q,Mr as r,ye as s,co as t,xr as u,Xe as v,Ze as w,et as x,tt as y,Lr as z,Nr as A,Ar as B,Sr as C,Or as D,Ir as E,Pr as F,_r as G,jr as H,Ie as I,rt as J,Fr as K,nt as L,De as M,ot as N,$r as O,Gt as P,Wr as Q,at as R,st as S,it as T,lt as U,Pe as V,Vr as W,Ur as X,qr as Y,$t as Z,Hr as _,Yr as $,Wt as aa,Qr as ba,Xr as ca,Zr as da};
@@ -1,9 +1,9 @@
1
- import{e as ce}from"./chunk-H5SCWHWP.js";import{a as se,b as P}from"./chunk-5QDBSZBV.js";import{i as L}from"./chunk-POXANAJ6.js";import{f as ae,h as ie}from"./chunk-L77I47VU.js";import{i as ne,j as U}from"./chunk-LYCLF26R.js";import{b,h as _,i as T,j as W}from"./chunk-CK2E7BTU.js";import{b as Oe,c as re,d as te,e as oe}from"./chunk-QYADASLV.js";var ke={};Oe(ke,{ACTOR_KEY:()=>F,COMMAND_HANDLERS:()=>A,CQRS_EVENT_HANDLERS:()=>S,CRON_HANDLERS:()=>D,CommandHandler:()=>me,EVENT_HANDLERS:()=>G,EventHandler:()=>ve,GRAPHREFLY_REQUEST_GRAPH:()=>R,GRAPHREFLY_ROOT_GRAPH:()=>v,GraphCron:()=>fe,GraphInterval:()=>he,GraphReflyEventExplorer:()=>x,GraphReflyGuard:()=>Re,GraphReflyGuardImpl:()=>I,GraphReflyModule:()=>Q,INTERVAL_HANDLERS:()=>O,InjectCqrsGraph:()=>de,InjectGraph:()=>ue,InjectNode:()=>pe,ObserveGateway:()=>B,OnGraphEvent:()=>le,QUERY_HANDLERS:()=>H,QueryHandler:()=>ye,SAGA_HANDLERS:()=>N,SagaHandler:()=>ge,fromHeader:()=>Ee,fromJwtPayload:()=>V,getActor:()=>we,getGraphToken:()=>m,getNodeToken:()=>y,observeSSE:()=>Me,observeSubscription:()=>Ce,toObservable:()=>se});import{Inject as j}from"@nestjs/common";var v=Symbol.for("graphrefly:root-graph");var R=Symbol.for("graphrefly:request-graph");function m(s){return Symbol.for(`graphrefly:graph:${s}`)}function y(s){return Symbol.for(`graphrefly:node:${s}`)}var G=new Map,O=new Map,D=new Map,A=new Map,S=new Map,H=new Map,N=new Map;function ue(s){return s==="request"?j(R):j(s?m(s):v)}function de(s){return j(m(s))}function pe(s){return j(y(s))}function le(s){return(e,r)=>{let t=r.name;r.addInitializer(function(){let o=this.constructor,n=G.get(o)??[];n.push({nodeName:s,methodKey:t}),G.set(o,n)})}}function he(s){return(e,r)=>{let t=r.name;r.addInitializer(function(){let o=this.constructor,n=O.get(o)??[];n.push({ms:s,methodKey:t}),O.set(o,n)})}}function fe(s){return(e,r)=>{let t=r.name;r.addInitializer(function(){let o=this.constructor,n=D.get(o)??[];n.push({expr:s,methodKey:t}),D.set(o,n)})}}function me(s,e){return(r,t)=>{let o=t.name;t.addInitializer(function(){let n=this.constructor,a=A.get(n)??[];a.push({cqrsName:s,commandName:e,methodKey:o}),A.set(n,a)})}}function ve(s,e){return(r,t)=>{let o=t.name;t.addInitializer(function(){let n=this.constructor,a=S.get(n)??[];a.push({cqrsName:s,eventName:e,methodKey:o}),S.set(n,a)})}}function ye(s,e){return(r,t)=>{let o=t.name;t.addInitializer(function(){let n=this.constructor,a=H.get(n)??[];a.push({cqrsName:s,projectionName:e,methodKey:o}),H.set(n,a)})}}function ge(s,e,r){return(t,o)=>{let n=o.name;o.addInitializer(function(){let a=this.constructor,c=N.get(a)??[];c.push({cqrsName:s,eventNames:r,sagaName:e,methodKey:n}),N.set(a,c)})}}var be=0,x=class{constructor(e,r){this.graph=e;this.moduleRef=r}disposers=[];scheduleNodeNames=[];onModuleInit(){this.wireEvents(),this.wireIntervals(),this.wireCrons(),this.wireCqrsCommands(),this.wireCqrsEvents(),this.wireCqrsQueries(),this.wireCqrsSagas()}onModuleDestroy(){for(let e of this.disposers)e();this.disposers.length=0;for(let e of this.scheduleNodeNames)try{this.graph.remove(e)}catch{}this.scheduleNodeNames.length=0}wireEvents(){for(let[e,r]of G){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireEventHandler(t,o)}}wireEventHandler(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),a=this.observeNode(r.nodeName).subscribe(c=>{for(let l of c)l[0]===b&&o(l[1])});this.disposers.push(a)}wireIntervals(){for(let[e,r]of O){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireIntervalHandler(t,e,o)}}wireIntervalHandler(e,r,t){let o=e[t.methodKey];if(typeof o!="function")return;let n=o.bind(e),c=`__schedule__.${r.name??"anonymous"}.${String(t.methodKey)}.${be++}`,l=ae(t.ms,{period:t.ms,name:c});this.graph.add(l),this.scheduleNodeNames.push(c);let p=this.observeNode(c).subscribe(u=>{for(let d of u)d[0]===b&&n(d[1])});this.disposers.push(p)}wireCrons(){for(let[e,r]of D){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCronHandler(t,e,o)}}wireCronHandler(e,r,t){let o=e[t.methodKey];if(typeof o!="function")return;let n=o.bind(e),c=`__schedule__.${r.name??"anonymous"}.${String(t.methodKey)}.${be++}`,l=ie(t.expr,{name:c});this.graph.add(l),this.scheduleNodeNames.push(c);let p=this.observeNode(c).subscribe(u=>{for(let d of u)d[0]===b&&n(d[1])});this.disposers.push(p)}wireCqrsCommands(){for(let[e,r]of A){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsCommand(t,o)}}wireCqrsCommand(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);n&&n.command(r.commandName,o)}wireCqrsEvents(){for(let[e,r]of S){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsEventHandler(t,o)}}wireCqrsEventHandler(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);if(!n)return;n.event(r.eventName);let c=n.resolve(r.eventName).cache,l=c&&c.length>0?c[c.length-1].seq:0,p=this.observeNodeOn(n,r.eventName).subscribe(u=>{for(let d of u)if(d[0]===b){let g=d[1];for(let i of g)i.seq>l&&(o(i),l=i.seq)}});this.disposers.push(p)}wireCqrsQueries(){for(let[e,r]of H){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsQuery(t,o)}}wireCqrsQuery(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);if(!n)return;let c=this.observeNodeOn(n,r.projectionName).subscribe(l=>{for(let f of l)f[0]===b&&o(f[1])});this.disposers.push(c)}wireCqrsSagas(){for(let[e,r]of N){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsSaga(t,o)}}wireCqrsSaga(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);n&&n.saga(r.sagaName,r.eventNames,o)}observeNode(e){return this.graph.observe(e)}observeNodeOn(e,r){return e.observe(r)}resolveCqrsGraph(e){try{return this.moduleRef.get(m(e),{strict:!1})}catch{return console.warn(`[GraphReFly] CqrsGraph "${e}" not found in DI \u2014 did you import GraphReflyModule.forCqrs({ name: "${e}" })?`),null}}resolveInstance(e){try{return this.moduleRef.get(e,{strict:!1})}catch{return null}}};function Me(s,e,r){let{actor:t,serialize:o=De,keepAliveMs:n,signal:a}=r??{},c=new TextEncoder,l,f=r?.highWaterMark!=null,p,u,d=[],g=!1;return new ReadableStream({start(i){let h,w=()=>{},M=()=>{if(!g){g=!0,h!==void 0&&clearInterval(h),a?.removeEventListener("abort",K),w(),p?.dispose(),u?.(),u=void 0;for(let k of d)i.enqueue(k.frame);d.length=0,i.close()}};l=M;let K=()=>M(),ee=s.observe(e,{actor:t});f&&(p=P(k=>ee.up(k),{highWaterMark:r.highWaterMark,lowWaterMark:r.lowWaterMark??Math.floor(r.highWaterMark/2)})),w=ee.subscribe(k=>{for(let $ of k){if(g)return;let q=$[0];if(q===b){let C=c.encode(Y("data",o($[1])));f?(d.push({frame:C,counted:!0}),p.onEnqueue(),u?.(),u=void 0):i.enqueue(C)}else if(q===W){let C=c.encode(Y("error",o($[1])));f?(d.push({frame:C,counted:!1}),u?.(),u=void 0):i.enqueue(C),M();return}else if(q===T||q===_){if(q===T){let C=c.encode(Y("complete"));f?(d.push({frame:C,counted:!1}),u?.(),u=void 0):i.enqueue(C)}M();return}}}),n!==void 0&&n>0&&(h=setInterval(()=>{g||(f?(d.push({frame:c.encode(`: keepalive
1
+ import{e as ce}from"./chunk-VRALOYRD.js";import{a as se,b as L}from"./chunk-5QDBSZBV.js";import{j as P}from"./chunk-ACMJ2ZPS.js";import{f as ae,h as ie}from"./chunk-2K5RXLAH.js";import{i as ne,j as U}from"./chunk-LYCLF26R.js";import{b,h as _,i as T,j as W}from"./chunk-CK2E7BTU.js";import{b as Oe,c as re,d as te,e as oe}from"./chunk-QYADASLV.js";var ke={};Oe(ke,{ACTOR_KEY:()=>F,COMMAND_HANDLERS:()=>A,CQRS_EVENT_HANDLERS:()=>S,CRON_HANDLERS:()=>D,CommandHandler:()=>me,EVENT_HANDLERS:()=>G,EventHandler:()=>ve,GRAPHREFLY_REQUEST_GRAPH:()=>R,GRAPHREFLY_ROOT_GRAPH:()=>v,GraphCron:()=>fe,GraphInterval:()=>he,GraphReflyEventExplorer:()=>x,GraphReflyGuard:()=>Re,GraphReflyGuardImpl:()=>I,GraphReflyModule:()=>Q,INTERVAL_HANDLERS:()=>O,InjectCqrsGraph:()=>de,InjectGraph:()=>ue,InjectNode:()=>pe,ObserveGateway:()=>B,OnGraphEvent:()=>le,QUERY_HANDLERS:()=>H,QueryHandler:()=>ye,SAGA_HANDLERS:()=>N,SagaHandler:()=>ge,fromHeader:()=>Ee,fromJwtPayload:()=>V,getActor:()=>we,getGraphToken:()=>m,getNodeToken:()=>y,observeSSE:()=>Me,observeSubscription:()=>Ce,toObservable:()=>se});import{Inject as j}from"@nestjs/common";var v=Symbol.for("graphrefly:root-graph");var R=Symbol.for("graphrefly:request-graph");function m(s){return Symbol.for(`graphrefly:graph:${s}`)}function y(s){return Symbol.for(`graphrefly:node:${s}`)}var G=new Map,O=new Map,D=new Map,A=new Map,S=new Map,H=new Map,N=new Map;function ue(s){return s==="request"?j(R):j(s?m(s):v)}function de(s){return j(m(s))}function pe(s){return j(y(s))}function le(s){return(e,r)=>{let t=r.name;r.addInitializer(function(){let o=this.constructor,n=G.get(o)??[];n.push({nodeName:s,methodKey:t}),G.set(o,n)})}}function he(s){return(e,r)=>{let t=r.name;r.addInitializer(function(){let o=this.constructor,n=O.get(o)??[];n.push({ms:s,methodKey:t}),O.set(o,n)})}}function fe(s){return(e,r)=>{let t=r.name;r.addInitializer(function(){let o=this.constructor,n=D.get(o)??[];n.push({expr:s,methodKey:t}),D.set(o,n)})}}function me(s,e){return(r,t)=>{let o=t.name;t.addInitializer(function(){let n=this.constructor,a=A.get(n)??[];a.push({cqrsName:s,commandName:e,methodKey:o}),A.set(n,a)})}}function ve(s,e){return(r,t)=>{let o=t.name;t.addInitializer(function(){let n=this.constructor,a=S.get(n)??[];a.push({cqrsName:s,eventName:e,methodKey:o}),S.set(n,a)})}}function ye(s,e){return(r,t)=>{let o=t.name;t.addInitializer(function(){let n=this.constructor,a=H.get(n)??[];a.push({cqrsName:s,projectionName:e,methodKey:o}),H.set(n,a)})}}function ge(s,e,r){return(t,o)=>{let n=o.name;o.addInitializer(function(){let a=this.constructor,c=N.get(a)??[];c.push({cqrsName:s,eventNames:r,sagaName:e,methodKey:n}),N.set(a,c)})}}var be=0,x=class{constructor(e,r){this.graph=e;this.moduleRef=r}disposers=[];scheduleNodeNames=[];onModuleInit(){this.wireEvents(),this.wireIntervals(),this.wireCrons(),this.wireCqrsCommands(),this.wireCqrsEvents(),this.wireCqrsQueries(),this.wireCqrsSagas()}onModuleDestroy(){for(let e of this.disposers)e();this.disposers.length=0;for(let e of this.scheduleNodeNames)try{this.graph.remove(e)}catch{}this.scheduleNodeNames.length=0}wireEvents(){for(let[e,r]of G){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireEventHandler(t,o)}}wireEventHandler(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),a=this.observeNode(r.nodeName).subscribe(c=>{for(let l of c)l[0]===b&&o(l[1])});this.disposers.push(a)}wireIntervals(){for(let[e,r]of O){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireIntervalHandler(t,e,o)}}wireIntervalHandler(e,r,t){let o=e[t.methodKey];if(typeof o!="function")return;let n=o.bind(e),c=`__schedule__.${r.name??"anonymous"}.${String(t.methodKey)}.${be++}`,l=ae(t.ms,{period:t.ms,name:c});this.graph.add(l),this.scheduleNodeNames.push(c);let p=this.observeNode(c).subscribe(u=>{for(let d of u)d[0]===b&&n(d[1])});this.disposers.push(p)}wireCrons(){for(let[e,r]of D){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCronHandler(t,e,o)}}wireCronHandler(e,r,t){let o=e[t.methodKey];if(typeof o!="function")return;let n=o.bind(e),c=`__schedule__.${r.name??"anonymous"}.${String(t.methodKey)}.${be++}`,l=ie(t.expr,{name:c});this.graph.add(l),this.scheduleNodeNames.push(c);let p=this.observeNode(c).subscribe(u=>{for(let d of u)d[0]===b&&n(d[1])});this.disposers.push(p)}wireCqrsCommands(){for(let[e,r]of A){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsCommand(t,o)}}wireCqrsCommand(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);n&&n.command(r.commandName,o)}wireCqrsEvents(){for(let[e,r]of S){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsEventHandler(t,o)}}wireCqrsEventHandler(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);if(!n)return;n.event(r.eventName);let c=n.resolve(r.eventName).cache,l=c&&c.length>0?c[c.length-1].seq:0,p=this.observeNodeOn(n,r.eventName).subscribe(u=>{for(let d of u)if(d[0]===b){let g=d[1];for(let i of g)i.seq>l&&(o(i),l=i.seq)}});this.disposers.push(p)}wireCqrsQueries(){for(let[e,r]of H){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsQuery(t,o)}}wireCqrsQuery(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);if(!n)return;let c=this.observeNodeOn(n,r.projectionName).subscribe(l=>{for(let f of l)f[0]===b&&o(f[1])});this.disposers.push(c)}wireCqrsSagas(){for(let[e,r]of N){let t=this.resolveInstance(e);if(t)for(let o of r)this.wireCqrsSaga(t,o)}}wireCqrsSaga(e,r){let t=e[r.methodKey];if(typeof t!="function")return;let o=t.bind(e),n=this.resolveCqrsGraph(r.cqrsName);n&&n.saga(r.sagaName,r.eventNames,o)}observeNode(e){return this.graph.observe(e)}observeNodeOn(e,r){return e.observe(r)}resolveCqrsGraph(e){try{return this.moduleRef.get(m(e),{strict:!1})}catch{return console.warn(`[GraphReFly] CqrsGraph "${e}" not found in DI \u2014 did you import GraphReflyModule.forCqrs({ name: "${e}" })?`),null}}resolveInstance(e){try{return this.moduleRef.get(e,{strict:!1})}catch{return null}}};function Me(s,e,r){let{actor:t,serialize:o=De,keepAliveMs:n,signal:a}=r??{},c=new TextEncoder,l,f=r?.highWaterMark!=null,p,u,d=[],g=!1;return new ReadableStream({start(i){let h,w=()=>{},M=()=>{if(!g){g=!0,h!==void 0&&clearInterval(h),a?.removeEventListener("abort",K),w(),p?.dispose(),u?.(),u=void 0;for(let k of d)i.enqueue(k.frame);d.length=0,i.close()}};l=M;let K=()=>M(),ee=s.observe(e,{actor:t});f&&(p=L(k=>ee.up(k),{highWaterMark:r.highWaterMark,lowWaterMark:r.lowWaterMark??Math.floor(r.highWaterMark/2)})),w=ee.subscribe(k=>{for(let $ of k){if(g)return;let q=$[0];if(q===b){let C=c.encode(Y("data",o($[1])));f?(d.push({frame:C,counted:!0}),p.onEnqueue(),u?.(),u=void 0):i.enqueue(C)}else if(q===W){let C=c.encode(Y("error",o($[1])));f?(d.push({frame:C,counted:!1}),u?.(),u=void 0):i.enqueue(C),M();return}else if(q===T||q===_){if(q===T){let C=c.encode(Y("complete"));f?(d.push({frame:C,counted:!1}),u?.(),u=void 0):i.enqueue(C)}M();return}}}),n!==void 0&&n>0&&(h=setInterval(()=>{g||(f?(d.push({frame:c.encode(`: keepalive
2
2
 
3
3
  `),counted:!1}),u?.(),u=void 0):i.enqueue(c.encode(`: keepalive
4
4
 
5
- `)))},n)),a?.aborted?K():a?.addEventListener("abort",K,{once:!0})},pull(i){if(f&&!g){if(d.length>0){let h=d.shift();i.enqueue(h.frame),h.counted&&p.onDequeue();return}return new Promise(h=>{u=h})}},cancel(){try{l?.()}catch{}}})}function Ce(s,e,r){let{actor:t,filter:o}=r??{},n=[],a=[],c=!1,l=s.observe(e,{actor:t}),f=r?.highWaterMark!=null?P(i=>l.up(i),{highWaterMark:r.highWaterMark,lowWaterMark:r.lowWaterMark??Math.floor(r.highWaterMark/2)}):void 0,p=()=>{c||(c=!0,f?.dispose(),d())},u=i=>{if(!c)if(a.length>0){let h=a.shift();i.done&&i.error?h.reject(i.error):i.done?h.resolve({done:!0,value:void 0}):h.resolve({done:!1,value:i.value})}else n.push(i),i.done||f?.onEnqueue()},d=l.subscribe(i=>{for(let h of i){let w=h[0];if(w===b){let M=h[1];if(o&&!o(M))continue;u({done:!1,value:M})}else if(w===W){let M=h[1]instanceof Error?h[1]:new Error(String(h[1]));u({done:!0,error:M}),p();return}else if(w===T||w===_){u({done:!0}),p();return}}});return{next(){if(n.length>0){let i=n.shift();return i.done||f?.onDequeue(),i.done&&i.error?Promise.reject(i.error):Promise.resolve(i.done?{done:!0,value:void 0}:{done:!1,value:i.value})}return c?Promise.resolve({done:!0,value:void 0}):new Promise((i,h)=>{a.push({resolve:i,reject:h})})},return(){p();for(let i of a)i.resolve({done:!0,value:void 0});return a.length=0,Promise.resolve({done:!0,value:void 0})},throw(i){return p(),Promise.reject(i)},[Symbol.asyncIterator](){return this}}}var B=class{constructor(e,r){this.graph=e;this.extractActor=r?.extractActor??(()=>{}),this.parse=r?.parse??Ae,this.highWaterMark=r?.highWaterMark,this.lowWaterMark=r?.lowWaterMark}clients=new Map;extractActor;parse;highWaterMark;lowWaterMark;handleConnection(e){this.clients.has(e)||this.clients.set(e,new Map)}handleDisconnect(e){let r=this.clients.get(e);if(r){for(let t of r.values())t.wm?.dispose(),t.unsub();this.clients.delete(e)}}handleMessage(e,r,t){let o=t??Se.bind(null,e),n;try{n=typeof r=="string"?this.parse(r):r}catch{o({type:"err",message:"invalid command"});return}n.type==="subscribe"?this.subscribe(e,n.path,o):n.type==="unsubscribe"?this.unsubscribe(e,n.path,o):n.type==="ack"?this.ack(e,n.path,n.count??1):o({type:"err",message:`unknown command type: ${n.type}`})}subscriptionCount(e){return this.clients.get(e)?.size??0}destroy(){for(let[e]of this.clients)this.handleDisconnect(e)}subscribe(e,r,t){let o=this.clients.get(e);if(o||(o=new Map,this.clients.set(e,o)),o.has(r)){t({type:"subscribed",path:r});return}let n=this.extractActor(e),a;try{a=this.graph.observe(r,{actor:n})}catch(p){let u=p instanceof Error?p.message:String(p);t({type:"err",message:u});return}let c=this.highWaterMark!=null?P(p=>a.up(p),{highWaterMark:this.highWaterMark,lowWaterMark:this.lowWaterMark??Math.floor(this.highWaterMark/2)}):void 0,l=()=>{c?.dispose(),f(),o.delete(r)},f=a.subscribe(p=>{for(let u of p){let d=u[0];if(d===b)c?.onEnqueue(),z(t,{type:"data",path:r,value:u[1]});else if(d===W){let g=u[1]instanceof Error?u[1].message:String(u[1]);z(t,{type:"error",path:r,error:g}),l();return}else if(d===T||d===_){z(t,{type:"complete",path:r}),l();return}}});o.set(r,{unsub:f,wm:c}),t({type:"subscribed",path:r})}unsubscribe(e,r,t){let o=this.clients.get(e),n=o?.get(r);n&&(n.wm?.dispose(),n.unsub(),o.delete(r)),t({type:"unsubscribed",path:r})}ack(e,r,t){let o=this.clients.get(e)?.get(r);if(!o?.wm)return;let n=Math.min(Math.max(0,Math.floor(t)),1024);for(let a=0;a<n;a++)o.wm.onDequeue()}};function De(s){if(s instanceof Error)return s.message;try{return JSON.stringify(s)}catch{return String(s)}}function Y(s,e){let r=`event: ${s}
5
+ `)))},n)),a?.aborted?K():a?.addEventListener("abort",K,{once:!0})},pull(i){if(f&&!g){if(d.length>0){let h=d.shift();i.enqueue(h.frame),h.counted&&p.onDequeue();return}return new Promise(h=>{u=h})}},cancel(){try{l?.()}catch{}}})}function Ce(s,e,r){let{actor:t,filter:o}=r??{},n=[],a=[],c=!1,l=s.observe(e,{actor:t}),f=r?.highWaterMark!=null?L(i=>l.up(i),{highWaterMark:r.highWaterMark,lowWaterMark:r.lowWaterMark??Math.floor(r.highWaterMark/2)}):void 0,p=()=>{c||(c=!0,f?.dispose(),d())},u=i=>{if(!c)if(a.length>0){let h=a.shift();i.done&&i.error?h.reject(i.error):i.done?h.resolve({done:!0,value:void 0}):h.resolve({done:!1,value:i.value})}else n.push(i),i.done||f?.onEnqueue()},d=l.subscribe(i=>{for(let h of i){let w=h[0];if(w===b){let M=h[1];if(o&&!o(M))continue;u({done:!1,value:M})}else if(w===W){let M=h[1]instanceof Error?h[1]:new Error(String(h[1]));u({done:!0,error:M}),p();return}else if(w===T||w===_){u({done:!0}),p();return}}});return{next(){if(n.length>0){let i=n.shift();return i.done||f?.onDequeue(),i.done&&i.error?Promise.reject(i.error):Promise.resolve(i.done?{done:!0,value:void 0}:{done:!1,value:i.value})}return c?Promise.resolve({done:!0,value:void 0}):new Promise((i,h)=>{a.push({resolve:i,reject:h})})},return(){p();for(let i of a)i.resolve({done:!0,value:void 0});return a.length=0,Promise.resolve({done:!0,value:void 0})},throw(i){return p(),Promise.reject(i)},[Symbol.asyncIterator](){return this}}}var B=class{constructor(e,r){this.graph=e;this.extractActor=r?.extractActor??(()=>{}),this.parse=r?.parse??Ae,this.highWaterMark=r?.highWaterMark,this.lowWaterMark=r?.lowWaterMark}clients=new Map;extractActor;parse;highWaterMark;lowWaterMark;handleConnection(e){this.clients.has(e)||this.clients.set(e,new Map)}handleDisconnect(e){let r=this.clients.get(e);if(r){for(let t of r.values())t.wm?.dispose(),t.unsub();this.clients.delete(e)}}handleMessage(e,r,t){let o=t??Se.bind(null,e),n;try{n=typeof r=="string"?this.parse(r):r}catch{o({type:"err",message:"invalid command"});return}n.type==="subscribe"?this.subscribe(e,n.path,o):n.type==="unsubscribe"?this.unsubscribe(e,n.path,o):n.type==="ack"?this.ack(e,n.path,n.count??1):o({type:"err",message:`unknown command type: ${n.type}`})}subscriptionCount(e){return this.clients.get(e)?.size??0}destroy(){for(let[e]of this.clients)this.handleDisconnect(e)}subscribe(e,r,t){let o=this.clients.get(e);if(o||(o=new Map,this.clients.set(e,o)),o.has(r)){t({type:"subscribed",path:r});return}let n=this.extractActor(e),a;try{a=this.graph.observe(r,{actor:n})}catch(p){let u=p instanceof Error?p.message:String(p);t({type:"err",message:u});return}let c=this.highWaterMark!=null?L(p=>a.up(p),{highWaterMark:this.highWaterMark,lowWaterMark:this.lowWaterMark??Math.floor(this.highWaterMark/2)}):void 0,l=()=>{c?.dispose(),f(),o.delete(r)},f=a.subscribe(p=>{for(let u of p){let d=u[0];if(d===b)c?.onEnqueue(),z(t,{type:"data",path:r,value:u[1]});else if(d===W){let g=u[1]instanceof Error?u[1].message:String(u[1]);z(t,{type:"error",path:r,error:g}),l();return}else if(d===T||d===_){z(t,{type:"complete",path:r}),l();return}}});o.set(r,{unsub:f,wm:c}),t({type:"subscribed",path:r})}unsubscribe(e,r,t){let o=this.clients.get(e),n=o?.get(r);n&&(n.wm?.dispose(),n.unsub(),o.delete(r)),t({type:"unsubscribed",path:r})}ack(e,r,t){let o=this.clients.get(e)?.get(r);if(!o?.wm)return;let n=Math.min(Math.max(0,Math.floor(t)),1024);for(let a=0;a<n;a++)o.wm.onDequeue()}};function De(s){if(s instanceof Error)return s.message;try{return JSON.stringify(s)}catch{return String(s)}}function Y(s,e){let r=`event: ${s}
6
6
  `;if(e!==void 0)for(let t of e.split(`
7
7
  `))r+=`data: ${t}
8
8
  `;return r+=`
9
- `,r}function Ae(s){return JSON.parse(s)}function Se(s,e){try{s.send(JSON.stringify(e))}catch{}}function z(s,e){try{s(e)}catch{}}var F="graphReflyActor";function V(s){return e=>{let t=e.switchToHttp().getRequest()?.user;if(t!=null)return s?s(t):t}}function Ee(s="x-graphrefly-actor"){return e=>{let t=e.switchToHttp().getRequest()?.headers?.[s.toLowerCase()];if(!(typeof t!="string"||t.length===0))try{return JSON.parse(t)}catch{return}}}function we(s){let e=s?.[F];return e!=null?U(e):ne}var I=class{constructor(e){this.extractor=e}canActivate(e){let r=U(this.extractor(e)),t=e.switchToHttp().getRequest();return t!=null&&(t[F]=r),!0}};function Re(s){return new I(s??V())}import{Module as He,Scope as xe}from"@nestjs/common";import{ModuleRef as Ne}from"@nestjs/core";var X=class{constructor(e){this.graph=e}onModuleDestroy(){this.graph.destroy()}},Z=class{graph=new L("request");onModuleDestroy(){this.graph.destroy()}},Ge,J;Ge=[He({})];var E=class E{static forRoot(e){let r=e??{},t=r.name??"root",o=[{provide:v,useFactory:()=>{let n=new L(t);return r.build&&r.build(n),r.snapshot&&n.restore(r.snapshot),n}},{provide:Symbol.for("graphrefly:root-lifecycle"),useFactory:n=>new X(n),inject:[v]},{provide:x,useFactory:(n,a)=>new x(n,a),inject:[v,Ne]}];if(r.nodes)for(let n of r.nodes)o.push({provide:y(n),useFactory:a=>a.resolve(n),inject:[v]});return r.requestScope&&o.push({provide:Symbol.for("graphrefly:request-lifecycle"),useFactory:()=>new Z,scope:xe.REQUEST},{provide:R,useFactory:n=>n.graph,inject:[Symbol.for("graphrefly:request-lifecycle")],scope:xe.REQUEST}),{module:E,global:!0,providers:o,exports:[v,...(r.nodes??[]).map(y),...r.requestScope?[R]:[]]}}static forFeature(e){let r=[{provide:m(e.name),useFactory:t=>{let o=new L(e.name);return e.build&&e.build(o),e.snapshot&&o.restore(e.snapshot),t.mount(e.name,o),o},inject:[v]}];if(e.nodes)for(let t of e.nodes)r.push({provide:y(`${e.name}::${t}`),useFactory:o=>o.resolve(t),inject:[m(e.name)]});return{module:E,providers:r,exports:[m(e.name),...(e.nodes??[]).map(t=>y(`${e.name}::${t}`))]}}static forCqrs(e){let r=[{provide:m(e.name),useFactory:t=>{let o=ce(e.name,e.cqrs);return e.eventStorage&&o.attachEventStorage(e.eventStorage),e.build&&e.build(o),t.mount(e.name,o),o},inject:[v]}];if(e.nodes)for(let t of e.nodes)r.push({provide:y(`${e.name}::${t}`),useFactory:o=>o.resolve(t),inject:[m(e.name)]});return{module:E,providers:r,exports:[m(e.name),...(e.nodes??[]).map(t=>y(`${e.name}::${t}`))]}}};J=re(null),E=oe(J,0,"GraphReflyModule",Ge,E),te(J,1,E);var Q=E;export{v as a,R as b,m as c,y as d,G as e,O as f,D as g,A as h,S as i,H as j,N as k,ue as l,de as m,pe as n,le as o,he as p,fe as q,me as r,ve as s,ye as t,ge as u,x as v,Me as w,Ce as x,B as y,F as z,V as A,Ee as B,we as C,I as D,Re as E,Q as F,ke as G};
9
+ `,r}function Ae(s){return JSON.parse(s)}function Se(s,e){try{s.send(JSON.stringify(e))}catch{}}function z(s,e){try{s(e)}catch{}}var F="graphReflyActor";function V(s){return e=>{let t=e.switchToHttp().getRequest()?.user;if(t!=null)return s?s(t):t}}function Ee(s="x-graphrefly-actor"){return e=>{let t=e.switchToHttp().getRequest()?.headers?.[s.toLowerCase()];if(!(typeof t!="string"||t.length===0))try{return JSON.parse(t)}catch{return}}}function we(s){let e=s?.[F];return e!=null?U(e):ne}var I=class{constructor(e){this.extractor=e}canActivate(e){let r=U(this.extractor(e)),t=e.switchToHttp().getRequest();return t!=null&&(t[F]=r),!0}};function Re(s){return new I(s??V())}import{Module as He,Scope as xe}from"@nestjs/common";import{ModuleRef as Ne}from"@nestjs/core";var X=class{constructor(e){this.graph=e}onModuleDestroy(){this.graph.destroy()}},Z=class{graph=new P("request");onModuleDestroy(){this.graph.destroy()}},Ge,J;Ge=[He({})];var E=class E{static forRoot(e){let r=e??{},t=r.name??"root",o=[{provide:v,useFactory:()=>{let n=new P(t);return r.build&&r.build(n),r.snapshot&&n.restore(r.snapshot),n}},{provide:Symbol.for("graphrefly:root-lifecycle"),useFactory:n=>new X(n),inject:[v]},{provide:x,useFactory:(n,a)=>new x(n,a),inject:[v,Ne]}];if(r.nodes)for(let n of r.nodes)o.push({provide:y(n),useFactory:a=>a.resolve(n),inject:[v]});return r.requestScope&&o.push({provide:Symbol.for("graphrefly:request-lifecycle"),useFactory:()=>new Z,scope:xe.REQUEST},{provide:R,useFactory:n=>n.graph,inject:[Symbol.for("graphrefly:request-lifecycle")],scope:xe.REQUEST}),{module:E,global:!0,providers:o,exports:[v,...(r.nodes??[]).map(y),...r.requestScope?[R]:[]]}}static forFeature(e){let r=[{provide:m(e.name),useFactory:t=>{let o=new P(e.name);return e.build&&e.build(o),e.snapshot&&o.restore(e.snapshot),t.mount(e.name,o),o},inject:[v]}];if(e.nodes)for(let t of e.nodes)r.push({provide:y(`${e.name}::${t}`),useFactory:o=>o.resolve(t),inject:[m(e.name)]});return{module:E,providers:r,exports:[m(e.name),...(e.nodes??[]).map(t=>y(`${e.name}::${t}`))]}}static forCqrs(e){let r=[{provide:m(e.name),useFactory:t=>{let o=ce(e.name,e.cqrs);return e.eventStorage&&o.attachEventStorage(e.eventStorage),e.build&&e.build(o),t.mount(e.name,o),o},inject:[v]}];if(e.nodes)for(let t of e.nodes)r.push({provide:y(`${e.name}::${t}`),useFactory:o=>o.resolve(t),inject:[m(e.name)]});return{module:E,providers:r,exports:[m(e.name),...(e.nodes??[]).map(t=>y(`${e.name}::${t}`))]}}};J=re(null),E=oe(J,0,"GraphReflyModule",Ge,E),te(J,1,E);var Q=E;export{v as a,R as b,m as c,y as d,G as e,O as f,D as g,A as h,S as i,H as j,N as k,ue as l,de as m,pe as n,le as o,he as p,fe as q,me as r,ve as s,ye as t,ge as u,x as v,Me as w,Ce as x,B as y,F as z,V as A,Ee as B,we as C,I as D,Re as E,Q as F,ke as G};
@@ -1,4 +1,4 @@
1
- import{a as O,f as v,k as P}from"./chunk-UISPDFJ3.js";import{ba as _,k as A}from"./chunk-CYOSWFT2.js";import{d as E}from"./chunk-4MKL6Q3K.js";import{m as U,x as T}from"./chunk-L77I47VU.js";import{o as y}from"./chunk-LYCLF26R.js";function G(e={}){return e.sdk?V(e):H(e)}function b(e,t,o,r){let s=t?.model??o;if(!s)throw new Error("anthropicAdapter: model must be set via options.model or invokeOpts.model");let{system:n,chat:i}=J(e,t?.systemPrompt),a={model:s,messages:i.map(F),max_tokens:t?.maxTokens??4096};return n&&(a.system=n),t?.temperature!=null&&(a.temperature=t.temperature),t?.tools&&t.tools.length>0&&(a.tools=t.tools.map(Y)),t?.maxReasoningTokens!=null&&(a.thinking={type:"enabled",budget_tokens:t.maxReasoningTokens}),t?.cacheHint,r&&(a.stream=!0),t?.providerExtras&&Object.assign(a,t.providerExtras),a}function J(e,t){let o=[];t&&o.push(t);let r=[];for(let s of e)s.role==="system"?o.push(s.content):r.push(s);return{system:o.length>0?o.join(`
1
+ import{a as O,f as v,k as P}from"./chunk-KCACBSJH.js";import{ba as _,k as A}from"./chunk-IZM3UEH3.js";import{f as E}from"./chunk-AS3TV2TV.js";import{m as U,x as T}from"./chunk-2K5RXLAH.js";import{o as y}from"./chunk-LYCLF26R.js";function G(e={}){return e.sdk?V(e):H(e)}function b(e,t,o,r){let s=t?.model??o;if(!s)throw new Error("anthropicAdapter: model must be set via options.model or invokeOpts.model");let{system:n,chat:i}=J(e,t?.systemPrompt),a={model:s,messages:i.map(F),max_tokens:t?.maxTokens??4096};return n&&(a.system=n),t?.temperature!=null&&(a.temperature=t.temperature),t?.tools&&t.tools.length>0&&(a.tools=t.tools.map(Y)),t?.maxReasoningTokens!=null&&(a.thinking={type:"enabled",budget_tokens:t.maxReasoningTokens}),t?.cacheHint,r&&(a.stream=!0),t?.providerExtras&&Object.assign(a,t.providerExtras),a}function J(e,t){let o=[];t&&o.push(t);let r=[];for(let s of e)s.role==="system"?o.push(s.content):r.push(s);return{system:o.length>0?o.join(`
2
2
 
3
3
  `):void 0,chat:r}}function F(e){if(e.role==="tool")return{role:"user",content:[{type:"tool_result",tool_use_id:e.toolCallId,content:e.content}]};if(e.role==="assistant"&&e.toolCalls&&e.toolCalls.length>0){let t=[];e.content&&t.push({type:"text",text:e.content});for(let o of e.toolCalls)t.push({type:"tool_use",id:o.id,name:o.name,input:o.arguments});return{role:"assistant",content:t}}return{role:e.role,content:e.content}}function Y(e){return{name:e.name,description:e.description,input_schema:e.parameters}}function R(e,t){if(!e)return{...t};let o={...e};return t.input_tokens!=null&&(o.input_tokens=t.input_tokens),t.output_tokens!=null&&(o.output_tokens=t.output_tokens),t.cache_read_input_tokens!=null&&(o.cache_read_input_tokens=t.cache_read_input_tokens),t.cache_creation_input_tokens!=null&&(o.cache_creation_input_tokens=t.cache_creation_input_tokens),t.cache_creation&&(o.cache_creation={...e.cache_creation??{},...t.cache_creation}),t.server_tool_use&&(o.server_tool_use={...e.server_tool_use??{},...t.server_tool_use}),o}function x(e){let t={input:{regular:e?.input_tokens??0},output:{regular:e?.output_tokens??0},raw:e};return e?.cache_read_input_tokens&&(t.input.cacheRead=e.cache_read_input_tokens),e?.cache_creation?(e.cache_creation.ephemeral_5m_input_tokens&&(t.input.cacheWrite5m=e.cache_creation.ephemeral_5m_input_tokens),e.cache_creation.ephemeral_1h_input_tokens&&(t.input.cacheWrite1h=e.cache_creation.ephemeral_1h_input_tokens)):e?.cache_creation_input_tokens&&(t.input.cacheWrite5m=e.cache_creation_input_tokens),e?.server_tool_use?.web_search_requests&&(t.auxiliary={webSearchRequests:e.server_tool_use.web_search_requests}),t}function K(e,t){let o=[],r=[];for(let s of e.content)if(s.type==="text"&&typeof s.text=="string")o.push(s.text);else if(s.type==="tool_use"){let n=s;r.push({id:n.id,name:n.name,arguments:n.input??{}})}return{content:o.join(""),toolCalls:r.length>0?r:void 0,usage:x(e.usage),finishReason:e.stop_reason,latencyMs:t,model:e.model,provider:"anthropic"}}function H(e){let t=e.apiKey??globalThis.process?.env?.ANTHROPIC_API_KEY,o=e.baseURL??"https://api.anthropic.com",r=e.anthropicVersion??"2023-06-01",s=e.fetchImpl??fetch,n=()=>{if(!t)throw new Error("anthropicAdapter: apiKey required for invoke/stream (or provide opts.sdk)");return{"x-api-key":t,"anthropic-version":r,"content-type":"application/json",...e.headers??{}}};return{provider:"anthropic",model:e.model,async invoke(i,a){let d=b(i,a,e.model,!1),g=y(),l=await s(`${o}/v1/messages`,{method:"POST",headers:n(),body:JSON.stringify(d),signal:a?.signal});if(!l.ok)throw await _(l,"Anthropic");let c=await l.json(),p=Math.max(0,(y()-g)/1e6);return K(c,p)},async*stream(i,a){let d=b(i,a,e.model,!0),g=await s(`${o}/v1/messages`,{method:"POST",headers:{...n(),accept:"text/event-stream"},body:JSON.stringify(d),signal:a?.signal});if(!g.ok)throw await _(g,"Anthropic");if(!g.body)throw new Error("anthropicAdapter: streaming response has no body");let l,c,p=new Map;for await(let m of A(g.body,{signal:a?.signal})){let h=m.data;if(!h)continue;let k;try{k=JSON.parse(h)}catch{continue}switch(k.type){case"message_start":{l=R(l,k.message.usage);break}case"content_block_start":{let u=k,f=u.content_block;f.type==="tool_use"&&(p.set(u.index,{id:String(f.id??""),name:String(f.name??""),argBuf:""}),yield{type:"tool-call-delta",delta:{id:String(f.id??""),name:String(f.name??"")}});break}case"content_block_delta":{let u=k,f=u.delta;if(f.type==="text_delta"&&typeof f.text=="string")yield{type:"token",delta:f.text};else if(f.type==="input_json_delta"&&typeof f.partial_json=="string"){let S=p.get(u.index);S&&(S.argBuf+=f.partial_json),yield{type:"tool-call-delta",delta:{argumentsDelta:f.partial_json}}}else f.type==="thinking_delta"&&typeof f.thinking=="string"&&(yield{type:"thinking",delta:f.thinking});break}case"message_delta":{let u=k;u.delta.stop_reason&&(c=u.delta.stop_reason),u.delta.usage&&(l=R(l,u.delta.usage));break}case"message_stop":break}}l&&(yield{type:"usage",usage:x(l)}),yield{type:"finish",reason:c??"stop"}}}}function V(e){let t=e.sdk;if(!t)throw new Error("sdkBackedAnthropic: sdk instance required");return{provider:"anthropic",model:e.model,async invoke(o,r){let s=b(o,r,e.model,!1),n=y(),i=await t.messages.create(s,{signal:r?.signal}),a=Math.max(0,(y()-n)/1e6);return K(i,a)},async*stream(o,r){if(!t.messages.stream)throw new Error("sdkBackedAnthropic: SDK instance does not expose .messages.stream");let s=b(o,r,e.model,!0),n,i;for await(let a of t.messages.stream(s,{signal:r?.signal}))switch(a.type){case"message_start":n=R(n,a.message.usage);break;case"content_block_delta":{let d=a.delta;d?.type==="text_delta"&&typeof d.text=="string"?yield{type:"token",delta:d.text}:d?.type==="input_json_delta"&&typeof d.partial_json=="string"?yield{type:"tool-call-delta",delta:{argumentsDelta:d.partial_json}}:d?.type==="thinking_delta"&&typeof d.thinking=="string"&&(yield{type:"thinking",delta:d.thinking});break}case"message_delta":{let d=a;d.delta.stop_reason&&(i=d.delta.stop_reason),d.delta.usage&&(n=R(n,d.delta.usage));break}}n&&(yield{type:"usage",usage:x(n)}),yield{type:"finish",reason:i??"stop"}}}}function D(e={}){return e.sdk?X(e):Q(e)}function w(e,t){let o=[],r=[];t?.systemPrompt&&o.push(t.systemPrompt);for(let i of e){if(i.role==="system"){o.push(i.content);continue}if(i.role==="tool"){r.push({role:"user",parts:[{functionResponse:{name:i.name??i.toolCallId??"tool",response:{result:i.content}}}]});continue}if(i.role==="assistant"&&i.toolCalls&&i.toolCalls.length>0){let a=[];i.content&&a.push({text:i.content});for(let d of i.toolCalls)a.push({functionCall:{name:d.name,args:d.arguments}});r.push({role:"model",parts:a});continue}r.push({role:i.role==="assistant"?"model":"user",parts:[{text:i.content}]})}let s={contents:r};o.length>0&&(s.systemInstruction={role:"system",parts:[{text:o.join(`
4
4
 
@@ -0,0 +1 @@
1
+ import{a as T}from"./chunk-4QH6VJF4.js";import{a as k}from"./chunk-L6NSJVJZ.js";import{b as Y}from"./chunk-LDQ3IUIP.js";import{a as S}from"./chunk-XLQPNNIC.js";import{j as N,l as W}from"./chunk-ACMJ2ZPS.js";import{C as D}from"./chunk-2K5RXLAH.js";import{b as C}from"./chunk-35JTVPOX.js";import{C as Q,E,G as A,m as B,o as R,p as O,u as $,w as J}from"./chunk-LYCLF26R.js";import{b as P}from"./chunk-CK2E7BTU.js";import{b as ne}from"./chunk-QYADASLV.js";var ue={};ne(ue,{AuditTrailGraph:()=>L,GuardedExecutionGraph:()=>V,InspectGraph:()=>M,PolicyGateGraph:()=>j,auditTrail:()=>H,complianceSnapshot:()=>I,computeHealthReport:()=>te,graphLens:()=>z,guardedExecution:()=>de,healthReportEqual:()=>oe,inspect:()=>ce,policyGate:()=>K,watchTopologyTree:()=>S});function ee(o,e){return k("audit",o,e)}var ie=new Set(["data","error","complete","teardown"]),L=class extends N{entries;count;_log;_target;constructor(e,t){super(t.name??`${e.name}_audit`,t.graph),this._target=e,this._log=Y([],{name:"entries",...t.maxSize!=null?{maxSize:t.maxSize}:{}}),this.entries=this._log.entries,this.add(this.entries,{name:"entries"}),this.count=A([this.entries],([s])=>s.length,{name:"count",describeKind:"derived",meta:ee("count")}),this.add(this.count,{name:"count"}),this.addDisposer(D(this.count));let n=t.includeTypes!=null?new Set(t.includeTypes):ie,r=t.filter,i=0,u=e.observe({timeline:!0,structured:!0}),h=u.onEvent(s=>{if(s.type==="derived")return;let d=s.type;if(!n.has(d))return;let y=s.path??"",g={seq:i++,timestamp_ns:s.timestamp_ns??R(),wall_clock_ns:O(),path:y,type:d},b=(y?F(e,y):void 0)?.lastMutation;b!=null&&(g.actor=b.actor),d==="data"&&(g.value=s.data),d==="error"&&(g.error=s.data);let l=y?re(e,y):void 0;l!=null&&(g.annotation=l),!(r!=null&&!r(g))&&this._log.append(g)});this.addDisposer(()=>{h(),u.dispose()}),this.addDisposer(()=>this._log.disposeAllViews())}all(){return this.entries.cache??[]}byNode(e){return this.all().filter(t=>t.path===e)}byActor(e){return this.all().filter(t=>t.actor?.id===e)}byActorType(e){return this.all().filter(t=>t.actor?.type===e)}byTimeRange(e,t){return this.all().filter(n=>!(n.timestamp_ns<e||t!=null&&n.timestamp_ns>=t))}get target(){return this._target}};function H(o,e={}){return new L(o,e)}var j=class extends N{policies;violations;violationCount;_target;_mode;_currentGuard;constructor(e,t,n){super(n.name??`${e.name}_policy`,n.graph),this._target=e,this._mode=n.mode??"audit";let r=X(t)?t:E(t,{name:"policies"});this.policies=r,this.add(this.policies,{name:"policies"}),this.violations=new T("violations",{retainedLimit:n.violationsLimit??1e3}),this.mount("violations",this.violations),this.violationCount=A([this.violations.events],([l])=>l.length,{name:"violationCount",describeKind:"derived",meta:ee("policy_violation_count")}),this.add(this.violationCount,{name:"violationCount"}),this.addDisposer(D(this.violationCount));let u=r.cache??[];this._currentGuard=$(u);let h=r.subscribe(l=>{for(let m of l)m[0]===P&&(u=m[1]??[],this._currentGuard=$(u))});this.addDisposer(h);let s=n.paths,d=X(s)?s:void 0,y=s!=null,G=d!=null?d.cache??[]:y?[...s]:void 0,b=G??Z(e);if(this._mode!=="enforce"&&d!=null){let l=d.subscribe(m=>{for(let a of m)a[0]===P&&(G=a[1]??[])});this.addDisposer(l)}if(this._mode==="enforce"){let l=new Map,m=a=>{if(l.has(a))return;let c=F(e,a);if(!(c instanceof Q))return;let _=(p,f)=>{let w=this._currentGuard(p,f);return w||this._publishViolation(p,f,a,"blocked"),w};l.set(a,c._pushGuard(_))};for(let a of b)m(a);if(d!=null){let a=d.subscribe(c=>{for(let _ of c){if(_[0]!==P)continue;let p=_[1]??[],f=new Set(p),w=new Set(G??[]);B(()=>{for(let v of w){if(f.has(v))continue;let x=l.get(v);x!=null&&(x(),l.delete(v))}for(let v of f)w.has(v)||m(v);G=p})}});this.addDisposer(a)}if(y){let a=e.topology.subscribe(c=>{for(let _ of c){if(_[0]!==P)continue;let p=_[1];if(p.kind!=="removed"||p.nodeKind!=="node")continue;let f=l.get(p.name);f!=null&&(f(),l.delete(p.name))}});this.addDisposer(a)}else{let a=S(e,(c,_,p)=>{if(c.kind==="added")if(c.nodeKind==="node")m(`${p}${c.name}`);else{let f=_._mounts.get(c.name);if(!(f instanceof N))return;let w=`${p}${c.name}::`,v=Z(f);for(let x of v)m(x===""?`${p}${c.name}`:`${w}${x}`)}else if(c.kind==="removed")if(c.nodeKind==="node"){let f=`${p}${c.name}`,w=l.get(f);w!=null&&(w(),l.delete(f))}else{let f=`${p}${c.name}`,w=`${f}::`;for(let[v,x]of l)(v===f||v.startsWith(w))&&(x(),l.delete(v))}});this.addDisposer(a)}this.addDisposer(()=>{for(let a of l.values())a();l.clear()})}else{let l=e.observe({timeline:!0,structured:!0}),m=l.onEvent(a=>{if(a.type!=="data"&&a.type!=="error")return;let c=a.path??"";if(!c||G!=null&&!G.includes(c))return;let _=a.actor??F(e,c)?.lastMutation?.actor;if(_==null)return;let p="write";this._currentGuard(_,p)||this._publishViolation(_,p,c,"observed")});this.addDisposer(()=>{m(),l.dispose()})}}_publishViolation(e,t,n,r){this.violations.publish({timestamp_ns:R(),wall_clock_ns:O(),path:n,actor:e,action:t,mode:this._mode,result:r})}all(){return this.violations.retained()}get mode(){return this._mode}get target(){return this._target}};function K(o,e,t={}){let n=new j(o,e,t);return n.tagFactory("policyGate",C(t)),n}function I(o,e={}){let t={format_version:1,timestamp_ns:R(),wall_clock_ns:O(),graph:o.snapshot()};if(e.actor!=null&&(t.actor=e.actor),e.audit!=null){let r=[...e.audit.all()];t.audit={count:r.length,entries:r}}if(e.policies!=null){let r=e.policies.policies.cache??[];t.policies={mode:e.policies.mode,rules:r,violations:[...e.policies.all()]}}let n=ae(t);return{...t,fingerprint:n}}function X(o){return typeof o=="object"&&o!==null&&"subscribe"in o}function F(o,e){try{return o.node(e)}catch{return}}function re(o,e){try{return o.annotation(e)}catch{return}}function Z(o){let e=o.describe({detail:"minimal"});return Object.keys(e.nodes)}function ae(o){return J(JSON.stringify(se(o)))}function se(o){let e=new Set,t=n=>{if(n===void 0)return{__undefined:!0};if(n===null)return null;let r=typeof n;if(r==="bigint")return{__bigint:n.toString()};if(r!=="object")return n;let i=n;if(e.has(i))return{__circular:!0};e.add(i);try{if(Array.isArray(i))return i.map(t);if(i instanceof Date)return{__date:i.toISOString()};if(i instanceof RegExp)return{__regexp:{source:i.source,flags:i.flags}};if(i instanceof Map)return{__map:[...i.entries()].map(([s,d])=>[t(s),t(d)])};if(i instanceof Set)return{__set:[...i].map(t)};if(ArrayBuffer.isView(i)){let h=i,s=new Array(h.length);for(let d=0;d<h.length;d++)s[d]=h[d]??0;return{__typed_array:{ctor:i.constructor.name,data:s}}}let u={};for(let h of Object.keys(i).sort())u[h]=t(i[h]);return u}finally{e.delete(i)}};return t(o)}function q(o){return typeof o=="object"&&o!==null&&"subscribe"in o&&"down"in o}function le(o){return k("guarded",o)}var V=class extends N{enforcer;violations;lints;scope;scopedDescribe;_target;_actorNode;_mode;_firedLintKinds=new Set;constructor(e,t){super(t.name??`${e.name}_guarded`,t.graph),this._target=e,this._mode=t.mode??"enforce";let n=t.policies,r=q(n);if(!r&&this._mode==="enforce"&&n.length===0)throw new RangeError('guardedExecution: empty `policies` in `mode: "enforce"` denies every action. Pass at least `{ effect: "allow", action: "*" }` and layer deny rules on top.');this.lints=new T("lints",{retainedLimit:t.lintsLimit??64}),this.mount("lints",this.lints);let i=t.actor;i==null?this._actorNode=E(null,{name:"actor"}):q(i)?this._actorNode=A([i],([s])=>s??null,{name:"actor",initial:null}):this._actorNode=E(i,{name:"actor"});let u={mode:this._mode,name:"enforcer"};if(t.violationsLimit!=null&&(u.violationsLimit=t.violationsLimit),this.enforcer=K(e,t.policies,u),this.violations=this.enforcer.violations,this.mount("enforcer",this.enforcer),r&&this._mode==="enforce"){let s=n,d=s.cache;d!=null&&d.length===0&&this._fireLint("empty-policies",'`policies` Node cached an empty array in `mode: "enforce"` \u2014 every action will be denied. Add at least one allow rule.');let y=s.subscribe(g=>{for(let G of g){if(G[0]!==P)continue;let b=G[1];(b==null||b.length===0)&&this._fireLint("empty-policies",'`policies` Node emitted an empty array in `mode: "enforce"` \u2014 every action will be denied. Add at least one allow rule.')}});this.addDisposer(y)}if(this._mode==="audit"){let s=e.describe({detail:"full"});Object.values(s.nodes).some(y=>y.guard!=null)||this._fireLint("audit-no-effect",'`mode: "audit"` + target has no per-node guards \u2014 `scopedDescribeNode` filters by per-node guards only, so policy rules will not affect describe() visibility. Policies still populate the `violations` topic on writes.')}i==null&&this._fireLint("no-actor","no actor configured \u2014 `wrapper.scopedDescribe` and `scopedDescribeNode()` will return an unscoped describe (full visibility) unless a per-call actor is supplied."),this.scope=A([this._actorNode,this.enforcer.policies],([s,d])=>({actor:s??null,mode:this._mode,policiesCount:d.length}),{name:"scope",describeKind:"derived",meta:le("scope")}),this.add(this.scope,{name:"scope"}),this.addDisposer(D(this.scope));let h=e.describe({reactive:!0,actor:this._actorNode,reactiveName:"scopedDescribe"});this.scopedDescribe=h.node,this.add(this.scopedDescribe,{name:"scopedDescribe"}),this.addDisposer(h.dispose)}_fireLint(e,t){this._firedLintKinds.has(e)||(this._firedLintKinds.add(e),this.lints.publish({kind:e,message:t,timestamp_ns:R()}))}scopedDescribeNode(e,t){let n=e==null?this._actorNode:q(e)?e:E(e,{name:"actor_override"}),r=this._target.describe({reactive:!0,actor:n,...t??{}});return this.addDisposer(r.dispose),{node:r.node,dispose:r.dispose}}get target(){return this._target}};function de(o,e){return new V(o,e)}function te(o){let e=[];for(let[t,n]of Object.entries(o.nodes)){if(n.status!=="errored")continue;let r={path:t,status:"errored"},i=W(o,t,"upstream",{});for(let u of i)if(u!==t&&o.nodes[u]?.status==="errored"){r.upstreamCause=u;break}e.push(r)}return e.sort((t,n)=>t.path<n.path?-1:t.path>n.path?1:0),{ok:e.length===0,problems:e}}function oe(o,e){if(o.ok!==e.ok||o.problems.length!==e.problems.length)return!1;for(let t=0;t<o.problems.length;t++){let n=o.problems[t],r=e.problems[t];if(n.path!==r.path||n.status!==r.status||n.upstreamCause!==r.upstreamCause)return!1}return!0}function z(o){let e=o.describe({reactive:!0,detail:"standard",reactiveName:"graphLens.topology"}),t=e.node,n=A([t],([g])=>te(g),{name:"graphLens.health",describeKind:"derived",equals:oe,meta:k("lens","health")}),r=D(n),i=new Map,u=-1,h=o.observe({reactive:!0,tiers:["data"]}),s=A([h,t],([g,G])=>{let b=g,l=G;if(b!=null&&b.flushedAt_ns>u){u=b.flushedAt_ns;for(let m of b.events){if(m.type!=="data")continue;let a=m.path;if(a==null||a==="")continue;let c=i.get(a);i.set(a,{path:a,count:(c?.count??0)+1,lastUpdate_ns:b.flushedAt_ns})}}if(l!=null&&i.size>0){let m=new Set(Object.keys(l.nodes));for(let a of[...i.keys()])m.has(a)||i.delete(a)}return new Map(i)},{name:"graphLens.flow",describeKind:"derived",meta:k("lens","flow")}),d=D(s),y=!1;return{topology:t,health:n,flow:s,dispose(){y||(y=!0,d(),r(),e.dispose())}}}var U=class extends N{view;constructor(e){super("lens"),this.view=z(e),this.add(this.view.topology,{name:"topology"}),this.add(this.view.health,{name:"health"}),this.add(this.view.flow,{name:"flow"})}},M=class extends N{target;lens;audit;_defaultActor;_lensSubgraph;constructor(e,t={}){super(t.name??`inspect(${e.name})`),this.target=e,this._defaultActor=t.actor,this._lensSubgraph=new U(e),this.lens=this._lensSubgraph.view,this.mount("lens",this._lensSubgraph),this.audit=H(e,t.audit??{}),this.mount("audit",this.audit),this.addDisposer(()=>this.lens.dispose())}explainTarget(e,t,n){return this.target.explain(e,t,n)}complianceSnapshot(e){let t=e?.actor??this._defaultActor;return I(this.target,{audit:this.audit,...t!=null?{actor:t}:{},...e?.policies!=null?{policies:e.policies}:{}})}};function ce(o,e={}){let t=new M(o,e);return t.tagFactory("inspect",C(e)),t}export{L as a,H as b,j as c,K as d,I as e,V as f,de as g,te as h,oe as i,z as j,M as k,ce as l,ue as m};
@@ -0,0 +1 @@
1
+ import{c as M,f as re,g as se,h as oe,i as ae}from"./chunk-3ZZX7M25.js";import{a as ee}from"./chunk-L6NSJVJZ.js";import{b as J}from"./chunk-LDQ3IUIP.js";import{j as ne}from"./chunk-ACMJ2ZPS.js";import{C as V}from"./chunk-2K5RXLAH.js";import{b as te}from"./chunk-35JTVPOX.js";import{D as X,E as Y,G as j,p as W,t as D}from"./chunk-LYCLF26R.js";import{b as Q}from"./chunk-CK2E7BTU.js";import{b as le}from"./chunk-QYADASLV.js";var ye={};le(ye,{CqrsGraph:()=>F,cqrs:()=>me,cqrsEventKeyOf:()=>he,dispatchKeyOf:()=>ve,sagaInvocationKeyOf:()=>fe});var I=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},N=class extends I{constructor(n,t){super(`Duplicate ${n} registration: "${t}"`);this.kind=n;this.registrationName=t}},B=class extends I{constructor(n,t,r){super(`Command "${n}" emitted undeclared event "${t}". Declared emits: [${r.join(", ")}]`);this.commandName=n;this.eventName=t;this.declaredEmits=r}},K=class extends I{constructor(n,t,r){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${t}, got ${r}`);this.aggregateId=n;this.expected=t;this.actual=r}},H=class extends I{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},O=class extends I{constructor(n,t){super(`Command handler "${n}" threw: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.commandName=n}};var P=class extends I{constructor(n,t){super(`Projection "${n}" rebuild failed: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.projectionName=n}};var ue=D((o,e)=>{o("write"),o("signal"),e("observe")}),pe=D((o,e)=>{o("observe"),o("signal"),e("write")}),ie=D((o,e)=>{o("observe"),o("signal"),e("write")});function $(o,e){return ee("cqrs",o,e)}function de(o){if(o===null||typeof o!="object"||Object.isFrozen(o))return o;for(let e of Object.keys(o))de(o[e]);return Object.freeze(o)}var he=o=>`${o.type}::${o.aggregateId??"__default__"}`,ve=o=>o.commandName,fe=o=>o.eventType,F=class extends ne{_eventLogs=new Map;_eventLogsByAggregate=new Map;_aggregateVersions=new Map;_aggregateLru=new Map;_commandRegs=new Map;_projections=new Set;_sagas=new Set;_keepaliveDisposers=[];_seq=0;_retainedLimit;_freezeCommandPayload;_freezeEventPayload;_maxAggregates;_dispatchSeqCursor;dispatches;audit;aggregateEvictions;constructor(e,n={}){super(e,n.graph),this._retainedLimit=n.retainedLimit??1024,this._freezeCommandPayload=n.freezeCommandPayload??!0,this._freezeEventPayload=n.freezeEventPayload??!0,this._maxAggregates=n.maxAggregates??1e4,this.dispatches=M({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=M({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=oe(this,"dispatch_seq",0)}aggregateVersion(e,n){return this._aggregateVersions.get(`${e}::${n}`)??0}_touchAggregate(e){this._aggregateLru.delete(e),this._aggregateLru.set(e,!0)}_enforceAggregateLru(){for(;this._aggregateLru.size>this._maxAggregates;){let e=this._aggregateLru.keys().next();if(e.done)break;let n=e.value;this._aggregateLru.delete(n);let t=n.indexOf("::");if(t<0)continue;let r=n.slice(0,t),s=n.slice(t+2),a=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let d=this._eventLogsByAggregate.get(r);d&&(d.delete(s),d.size===0&&this._eventLogsByAggregate.delete(r)),this.aggregateEvictions.append({aggregateId:s,type:r,lastVersion:a,t_ns:W()})}}destroy(){for(let e of this._keepaliveDisposers)e();this._keepaliveDisposers.length=0,super.destroy()}_attachedEventTiers=[];_attachedTierDisposers=new Map;attachEventStorage(e){this._attachedEventTiers.push(e);for(let[n,t]of this._eventLogs){let r=t.log.attachStorage(e),s=this._attachedTierDisposers.get(n);s||(s=[],this._attachedTierDisposers.set(n,s)),s.push(r)}for(let[n,t]of this._eventLogsByAggregate)for(let[r,s]of t){let a=`${n}::${r}`,d=s.log.attachStorage(e),u=this._attachedTierDisposers.get(a);u||(u=[],this._attachedTierDisposers.set(a,u)),u.push(d)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let t=this._attachedTierDisposers.get(e);t||(t=[],this._attachedTierDisposers.set(e,t));for(let r of this._attachedEventTiers)t.push(n.attachStorage(r))}event(e,n){if(n!==void 0)return this._ensureAggregateStream(e,n).node;let t=this._eventLogs.get(e);if(t)return t.node;let r=J([],{name:e,versioning:0,maxSize:this._retainedLimit});r.withLatest();let s=r.entries,a=j([s],([d])=>d,{name:e,describeKind:"state",meta:$("event",{event_name:e}),guard:ie,initial:s.cache});return this.add(a,{name:e}),this._keepaliveDisposers.push(V(a)),this._eventLogs.set(e,{log:r,node:a}),this._autoWireStreamStorage(e,r),a}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let t=this._eventLogsByAggregate.get(e);t||(t=new Map,this._eventLogsByAggregate.set(e,t));let r=`${e}::${n}`;this._touchAggregate(r);let s=t.get(n);if(s)return s;let a=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,d=J([],{name:a,versioning:0,maxSize:this._retainedLimit});d.withLatest();let u=d.entries,i=j([u],([T])=>T,{name:a,describeKind:"state",meta:$("event_aggregate",{event_name:e,aggregate_id:n}),guard:ie,initial:u.cache}),g=a,h=0;for(;this.nameOf(this.resolveOptional(g)??i)===g&&(h+=1,g=`${a}_${h}`,this.resolveOptional(g)!==void 0););try{this.add(i,{name:g})}catch{}this._keepaliveDisposers.push(V(i));let w={log:d,node:i};return t.set(n,w),this._autoWireStreamStorage(`${e}::${n}`,d),this._enforceAggregateLru(),w}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,t){let r=this._eventLogs.get(e);if(r||(this.event(e),r=this._eventLogs.get(e)),r.node.status==="completed"||r.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${r.node.status}).`);let s,a;if(t?.aggregateId!==void 0){let g=`${e}::${t.aggregateId}`;s=(this._aggregateVersions.get(g)??0)+1,this._aggregateVersions.set(g,s),a=this._ensureAggregateStream(e,t.aggregateId)}let d=r.log.entries.v,u=this._freezeEventPayload?de(n):n,i={type:e,payload:u,timestampNs:W(),seq:++this._seq,...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...s!==void 0?{aggregateVersion:s}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...t?.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{},...d!=null?{v0:{id:d.id,version:d.version}}:{}};return r.log.append(i),a&&a.log.append(i),i}command(e,n){if(this._commandRegs.has(e))throw new N("command",e);let t=typeof n=="function"?{handler:n}:n,r=Y(void 0,{name:e,describeKind:"state",meta:{...$("command",{command_name:e}),error:null},guard:ue});if(this.add(r,{name:e}),this._commandRegs.set(e,{handler:t.handler,...t.emits!==void 0?{emits:t.emits}:{},...t.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{}}),t.emits)for(let s of t.emits)this._eventLogs.has(s)||this.event(s);return r}dispatch(e,n,t){let r=this._commandRegs.get(e);if(!r)throw new H(e);if(t?.aggregateId!==void 0&&t.expectedAggregateVersion!==void 0&&r.emits!==void 0){let i=0;for(let g of r.emits){let h=this._aggregateVersions.get(`${g}::${t.aggregateId}`);h!==void 0&&h>i&&(i=h)}if(i!==t.expectedAggregateVersion)throw new K(t.aggregateId,t.expectedAggregateVersion,i)}let s=this.resolve(e),a=[],d=!1,u=i=>{s.emit(i,{internal:!0});try{r.handler(i,{emit:(g,h)=>{if(r.emits!==void 0&&!r.emits.includes(g))throw new B(e,g,r.emits);a.push(g),this._appendEvent(g,h,{...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}}),s.meta.error.emit(null,{internal:!0})}catch(g){throw d=!0,g}};try{se(u,{audit:this.dispatches,seq:this._dispatchSeqCursor,freeze:this._freezeCommandPayload,onSuccess:([i],g,{t_ns:h,seq:w})=>({commandName:e,payload:i,outcome:"success",emittedEvents:[...a],t_ns:h,seq:w??0,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),onFailure:([i],g,{t_ns:h,seq:w,errorType:T})=>{let p=g instanceof O?g:new O(e,g);return{commandName:e,payload:i,outcome:"failure",error:p,errorType:T,emittedEvents:[...a],t_ns:h,seq:w??0,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}}})(n)}catch(i){throw d&&s.meta.error.emit(i,{internal:!0}),i}}projection(e){let{name:n,events:t,reducer:r,initial:s}=e,a=e.mode??"scan",d=e.freezeInputs??!0,u=e.snapshot,i=t.map(l=>(this._eventLogs.has(l)||this.event(l),this._eventLogs.get(l).node));function g(l){l.sort((c,v)=>c.timestampNs-v.timestampNs||c.seq-v.seq||(c.aggregateId??"").localeCompare(v.aggregateId??""))}function h(l){let c=[];for(let v of l)c.push(...v);return g(c),c}let w=i.map(l=>l.cache??[]),T=h(w),p=d?Object.freeze(T):T,m=0,y=s;a==="scan"&&T.length>0&&(y=r(s,p),m=T.length);let E=a==="replay"?r(s,p):y,S=u?.saveDebounceMs??1e3,A=u?.saveEvery??1e3,_,x=0;function R(l){if(u?.save){if(x+=1,x>=A){x=0,_!==void 0&&(clearTimeout(_),_=void 0);let c=u.save(l);c instanceof Promise&&c.catch(()=>{});return}_!==void 0&&clearTimeout(_),_=setTimeout(()=>{_=void 0,x=0;let c=u.save(l);c instanceof Promise&&c.catch(()=>{})},S)}}let k=j(i,l=>{let c=h(l),v;if(a==="replay"){let b=d?Object.freeze(c):c;v=r(s,b)}else{let b=c.slice(m);m=c.length;let f=d?Object.freeze(b):b;v=r(y,f),y=v}return R(v),v},{name:n,describeKind:"derived",meta:$("projection",{projection_name:n,source_events:t}),guard:pe,initial:E});return this.add(k,{name:n}),this._keepaliveDisposers.push(V(k)),this._keepaliveDisposers.push(()=>{_!==void 0&&(clearTimeout(_),_=void 0)}),this._projections.add(n),{node:k,rebuild:async l=>{try{let c=l?.pageSize??1e3,v=l?.fromTier??this._attachedEventTiers[0]?.[0],b=h(i.map(C=>C.cache??[])).length,f=s;if(u?.load){let C=await u.load();C!==void 0&&(f=C)}if(!v||!v.loadEntries){let C=h(i.map(L=>L.cache??[])),q=d?Object.freeze(C):C;f=r(f,q)}else{let C=new Set(t),q,L=!1;for(;!L;){let G=await v.loadEntries({cursor:q,pageSize:c}),U=[...G.entries].filter(ce=>C.has(ce.type));g(U);let ge=d?Object.freeze(U):U;f=r(f,ge),q=G.cursor,L=!q||G.entries.length===0}}if(a==="scan"){let C=h(i.map(L=>L.cache??[])),q=C.slice(b);if(q.length>0){let L=d?Object.freeze(q):q;f=r(f,L)}y=f,m=C.length}return k.emit(f,{internal:!0}),f}catch(c){throw new P(n,c)}},reset:async()=>{try{let l=s;if(u?.load){let f=await u.load();f!==void 0&&(l=f)}let c=h(i.map(f=>f.cache??[])),v=d?Object.freeze(c):c,b=r(l,v);return a==="scan"&&(y=b,m=c.length),k.emit(b,{internal:!0}),b}catch(l){throw new P(n,l)}}}}saga(e,n,t,r={}){let s=n.map(p=>(this._eventLogs.has(p)||this.event(p),this._eventLogs.get(p).node)),a=ae(this,`${e}_cursor`,n,0),d=M({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),u=r.aggregateId,i=r.errorPolicy??"advance",g=new Map;for(let p of n){let m=a[p];g.set(p,m.cache??0);let y=m.subscribe(E=>{for(let S of E)S[0]===Q&&g.set(p,S[1])});this._keepaliveDisposers.push(y)}let h=re((p,m)=>{t(p)},{audit:d,freeze:!1,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{},onSuccess:([p,m],y,{t_ns:E})=>({eventType:m,outcome:"success",aggregateId:p.aggregateId,event:p,t_ns:E}),onFailure:([p,m],y,{t_ns:E,errorType:S})=>({eventType:m,outcome:"failure",error:y,errorType:S,aggregateId:p.aggregateId,event:p,t_ns:E})}),w={},T=X(s,(p,m)=>{let y=w.n.meta.error;for(let E=0;E<p.length;E++){let S=p[E];if(S==null||S.length===0)continue;let A=S.at(-1);if(!A)continue;let _=n[E],x=a[_],R=g.get(_)??0;if(A.length>R){let k=A.slice(R),z=R;for(let Z of k){let l=Z;if(u!==void 0&&l.aggregateId!==u){z+=1;continue}try{h(l,_),y.emit(null,{internal:!0}),z+=1}catch(c){if(y.emit(c,{internal:!0}),i==="hold")break;z+=1}}x.emit(z)}}},{name:e,describeKind:"effect",meta:{...$("saga",{saga_name:e,source_events:n}),error:null}});return w.n=T,this.add(T,{name:e}),this._keepaliveDisposers.push(V(T)),this._sagas.add(e),{node:T,invocations:d,audit:d,cursors:a}}};function me(o,e){let n=new F(o,e),{factory:t,factoryArgs:r,...s}=e??{};return n.tagFactory("cqrs",te(s)),n}export{he as a,ve as b,fe as c,F as d,me as e,ye as f};
@@ -1 +1 @@
1
- import{a as O,b as H,c as j,d as E,e as W,f as ne}from"./chunk-OV5AA6HJ.js";import{a as N}from"./chunk-D27JNOLZ.js";import{a as X}from"./chunk-C72GO4IZ.js";import{i as T}from"./chunk-POXANAJ6.js";import{D as I,E as y,G as L,o as S}from"./chunk-LYCLF26R.js";import{b as te}from"./chunk-QYADASLV.js";var ie={};te(ie,{CanvasMeasureAdapter:()=>$,CliMeasureAdapter:()=>D,ImageSizeAdapter:()=>J,NodeCanvasMeasureAdapter:()=>q,PrecomputedAdapter:()=>V,SvgBoundsAdapter:()=>z,analyzeAndMeasure:()=>O,carveTextLineSlots:()=>E,circleIntervalForBand:()=>Q,computeBlockFlow:()=>_,computeCharPositions:()=>W,computeFlowLines:()=>ee,computeLineBreaks:()=>H,computeTotalHeight:()=>U,layoutNextLine:()=>j,measureBlock:()=>Y,measureBlocks:()=>K,reactiveBlockLayout:()=>re,reactiveFlowLayout:()=>se,reactiveLayout:()=>ne,rectIntervalForBand:()=>Z});var D=class{cellPx;constructor(t){this.cellPx=t?.cellPx??8}measureSegment(t,n){return{width:X(t)*this.cellPx}}},G=class extends Error{name="KeyError"},V=class{metrics;fallback;constructor(t){this.metrics=t.metrics;let n=t.fallback??"per-char";if(n!=="per-char"&&n!=="error")throw new Error(`fallback must be 'per-char' or 'error', got ${JSON.stringify(t.fallback)}`);this.fallback=n}measureSegment(t,n){let i=this.metrics[n];if(i){let o=i[t];if(o!==void 0)return{width:o}}if(this.fallback==="error")throw new G(`PrecomputedAdapter: no metrics for segment ${JSON.stringify(t)} in font ${JSON.stringify(n)}`);let r=0;if(i)for(let o of t){let l=i[o];l!==void 0&&(r+=l)}return{width:r}}},$=class{ctx=null;currentFont="";emojiCorrection;constructor(t){this.emojiCorrection=t?.emojiCorrection??1}getContext(){if(!this.ctx){if(typeof OffscreenCanvas>"u")throw new Error("CanvasMeasureAdapter requires a browser environment with OffscreenCanvas support. Use CliMeasureAdapter or NodeCanvasMeasureAdapter for Node.js.");let n=new OffscreenCanvas(0,0).getContext("2d");if(!n)throw new Error("CanvasMeasureAdapter: failed to get 2d context");this.ctx=n}return this.ctx}measureSegment(t,n){let i=this.getContext();n!==this.currentFont&&(i.font=n,this.currentFont=n);let r=i.measureText(t).width;return this.emojiCorrection!==1&&new RegExp("\\p{Emoji_Presentation}","u").test(t)&&(r*=this.emojiCorrection),{width:r}}clearCache(){this.currentFont=""}},q=class{ctx=null;currentFont="";canvasModule;constructor(t){this.canvasModule=t}getContext(){if(!this.ctx){let n=this.canvasModule.createCanvas(0,0).getContext("2d");if(!n)throw new Error("NodeCanvasMeasureAdapter: failed to get 2d context");this.ctx=n}return this.ctx}measureSegment(t,n){let i=this.getContext();return n!==this.currentFont&&(i.font=n,this.currentFont=n),{width:i.measureText(t).width}}clearCache(){this.currentFont=""}},z=class{measureSvg(t){let n=t.match(/viewBox\s*=\s*["']([^"']+)["']/);if(n){let o=n[1].trim().split(/[\s,]+/);if(o.length>=4){let l=Number.parseFloat(o[2]),a=Number.parseFloat(o[3]);if(Number.isFinite(l)&&Number.isFinite(a)&&l>0&&a>0)return{width:l,height:a};throw new Error("SvgBoundsAdapter: viewBox width/height are missing, non-finite, or not positive")}}let i=t.match(/<svg[^>]*\bwidth\s*=\s*["']?([\d.]+)/),r=t.match(/<svg[^>]*\bheight\s*=\s*["']?([\d.]+)/);if(i&&r){let o=Number.parseFloat(i[1]),l=Number.parseFloat(r[1]);if(Number.isFinite(o)&&Number.isFinite(l)&&o>0&&l>0)return{width:o,height:l};throw new Error("SvgBoundsAdapter: svg width/height attributes are non-finite or not positive")}throw new Error("SvgBoundsAdapter: cannot determine dimensions \u2014 SVG has no viewBox or width/height attributes")}},J=class{sizes;constructor(t){this.sizes=new Map(Object.entries(t))}measureImage(t){let n=this.sizes.get(t);if(!n)throw new Error(`ImageSizeAdapter: no dimensions registered for ${JSON.stringify(t)}`);return{width:n.width,height:n.height}}};function Y(e,t,n,i,r,o,l){switch(e.type){case"text":{let a=e.font??r,m=e.lineHeight??o,d=O(e.text,a,n.text,i),w=H(d,t,n.text,a,i),v=W(w,d,m),B=w.lineCount*m,c=0;for(let x of w.lines)x.width>c&&(c=x.width);return{index:l,type:"text",width:Math.min(c,t),height:B,textSegments:d,textLineBreaks:w,textCharPositions:v}}case"image":{let a,m;if(e.naturalWidth!=null&&e.naturalHeight!=null)a=e.naturalWidth,m=e.naturalHeight;else if(n.image){let d=n.image.measureImage(e.src);a=d.width,m=d.height}else throw new Error(`Image block at index ${l} has no naturalWidth/naturalHeight and no ImageMeasurer adapter`);return a>t&&(m=m*t/a,a=t),{index:l,type:"image",width:a,height:m}}case"svg":{let a,m;if(e.viewBox)a=e.viewBox.width,m=e.viewBox.height;else if(n.svg){let d=n.svg.measureSvg(e.content);a=d.width,m=d.height}else throw new Error(`SVG block at index ${l} has no viewBox and no SvgMeasurer adapter`);return a>t&&(m=m*t/a,a=t),{index:l,type:"svg",width:a,height:m}}}}function K(e,t,n,i,r,o){return e.map((l,a)=>Y(l,t,n,i,r,o,a))}function _(e,t){let n=[],i=0;for(let r=0;r<e.length;r++){let o=e[r];n.push({...o,x:0,y:i}),i+=o.height+(r<e.length-1?t:0)}return n}function U(e){if(e.length===0)return 0;let t=e[e.length-1];return t.y+t.height}function re(e){let{adapters:t,name:n="reactive-block-layout",defaultFont:i="16px sans-serif",defaultLineHeight:r=20}=e,o=new T(n),l=new Map,a=y(e.blocks??[],{name:"blocks"}),m=y(Math.max(0,e.maxWidth??800),{name:"max-width"}),d=y(e.gap??0,{name:"gap"}),w=I([a,m],(c,x,s)=>{let p=c[0]!=null&&c[0].length>0?c[0].at(-1):s.prevData[0],h=c[1]!=null&&c[1].length>0?c[1].at(-1):s.prevData[1],g=S(),u=K(p,h,t,l,i,r),f=S()-g,b=w.meta;b&&(N(b["block-count"],u.length),N(b["layout-time-ns"],f)),x.emit(u);let C=()=>{l.clear(),t.text.clearCache?.()};return{deactivate:C,invalidate:C}},{name:"measured-blocks",describeKind:"derived",meta:{"block-count":0,"layout-time-ns":0},equals:(c,x)=>{let s=c,p=x;if(s==null||p==null)return s===p;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++){let g=s[h],u=p[h];if(g.type!==u.type||g.width!==u.width||g.height!==u.height||g.index!==u.index)return!1}return!0}}),v=L([w,d],([c,x])=>_(c,x),{name:"block-flow",equals:(c,x)=>{let s=c,p=x;if(s==null||p==null)return s===p;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++){let g=s[h],u=p[h];if(g.x!==u.x||g.y!==u.y||g.width!==u.width||g.height!==u.height)return!1}return!0}}),B=L([v],([c])=>U(c),{name:"total-height"});return o.add(a,{name:"blocks"}),o.add(m,{name:"max-width"}),o.add(d,{name:"gap"}),o.add(w,{name:"measured-blocks"}),o.add(v,{name:"block-flow"}),o.add(B,{name:"total-height"}),{graph:o,setBlocks:c=>o.set("blocks",c),setMaxWidth:c=>o.set("max-width",Math.max(0,c)),setGap:c=>o.set("gap",c),measuredBlocks:w,blockFlow:v,totalHeight:B}}function Q(e,t,n){let i=e.hPad??0,r=e.vPad??0,o=t-r,l=n+r;if(o>=e.cy+e.r||l<=e.cy-e.r)return null;let a=e.cy>=o&&e.cy<=l?0:e.cy<o?o-e.cy:e.cy-l;if(a>=e.r)return null;let m=Math.sqrt(e.r*e.r-a*a);return{left:e.cx-m-i,right:e.cx+m+i}}function Z(e,t,n){let i=e.hPad??0,r=e.vPad??0;return n<=e.y-r||t>=e.y+e.h+r?null:{left:e.x-i,right:e.x+e.w+i}}function oe(e,t,n){return e.kind==="circle"?Q(e,t,n):Z(e,t,n)}function ee(e,t,n,i,r,o,l){let a=l?.paragraphSpacing??r,m=[],d={segmentIndex:0,graphemeIndex:0};if(e.length===0||n.count<=0||r<=0)return{lines:m,cursor:d};let w=t.paddingX??0,v=t.paddingY??0,B=Math.max(0,t.width-w*2),c=Math.max(0,t.height-v*2),x=n.gap*Math.max(0,n.count-1),s=Math.max(0,(B-x)/n.count);if(s<=0)return{lines:m,cursor:d};e:for(let p=0;p<n.count;p++){let h=w+p*(s+n.gap),g=h+s,u=v;for(;u+r<=v+c;){let f=u+r,b=[];for(let k=0;k<i.length;k++){let M=oe(i[k],u,f);M!==null&&b.push(M)}let C=E({left:h,right:g},b,o);if(C.length===0){u+=r;continue}let P=!1;for(let k=0;k<C.length;k++){let M=C[k],R=M.right-M.left,F=j(e,d,R);if(F===null)return{lines:m,cursor:d};if(F.text.length===0&&F.width===0){d=F.end,P=!0;break}m.push({x:M.left,y:u,width:F.width,slotWidth:R,text:F.text,columnIndex:p,flushToRight:M.right<g-.5}),d=F.end}if(P){u+=a;continue}if(u+=r,d.segmentIndex>=e.length)break e}if(d.segmentIndex>=e.length)break}return{lines:m,cursor:d}}function se(e){let{adapter:t,name:n="reactive-flow-layout",minSlotWidth:i=20}=e,r=new T(n),o=new Map,l=y(e.text??"",{name:"text"}),a=y(e.font??"16px sans-serif",{name:"font"}),m=y(e.lineHeight??20,{name:"line-height"}),d=y(e.container??{width:800,height:600,paddingX:0,paddingY:0},{name:"container"}),w=y(e.columns??{count:1,gap:0},{name:"columns"}),v=y(e.obstacles??[],{name:"obstacles"}),B=y(e.paragraphSpacing??null,{name:"paragraph-spacing"}),c=I([l,a],(s,p,h)=>{let g=s[0],u=g!=null&&g.length>0?g.at(-1):h.prevData[0],f=s[1],b=f!=null&&f.length>0?f.at(-1):h.prevData[1],C=O(u,b,t,o);p.emit(C);let P=()=>{o.clear(),t.clearCache?.()};return{deactivate:P,invalidate:P}},{name:"segments",describeKind:"derived"}),x=L([c,d,w,v,m,B],([s,p,h,g,u,f])=>{let b=s,C=S(),P=f??u,{lines:k,cursor:M}=ee(b,p,h,g,u,i,{paragraphSpacing:P}),R=S()-C,F=Math.max(0,b.length-M.segmentIndex),A=x.meta;return A&&(N(A["line-count"],k.length),N(A["layout-time-ns"],R),N(A["overflow-segments"],F)),k},{name:"flow-lines",meta:{"line-count":0,"layout-time-ns":0,"overflow-segments":0},equals:(s,p)=>{let h=s,g=p;if(h.length!==g.length)return!1;for(let u=0;u<h.length;u++){let f=h[u],b=g[u];if(f.x!==b.x||f.y!==b.y||f.width!==b.width||f.slotWidth!==b.slotWidth||f.text!==b.text||f.columnIndex!==b.columnIndex||f.flushToRight!==b.flushToRight)return!1}return!0}});return r.add(l,{name:"text"}),r.add(a,{name:"font"}),r.add(m,{name:"line-height"}),r.add(d,{name:"container"}),r.add(w,{name:"columns"}),r.add(v,{name:"obstacles"}),r.add(B,{name:"paragraph-spacing"}),r.add(c,{name:"segments"}),r.add(x,{name:"flow-lines"}),{graph:r,setText:s=>r.set("text",s),setFont:s=>r.set("font",s),setLineHeight:s=>r.set("line-height",s),setContainer:s=>r.set("container",s),setColumns:s=>r.set("columns",s),setObstacles:s=>r.set("obstacles",s),setParagraphSpacing:s=>r.set("paragraph-spacing",s),segments:c,flowLines:x}}export{D as a,V as b,$ as c,q as d,z as e,J as f,Y as g,K as h,_ as i,U as j,re as k,Q as l,Z as m,ee as n,se as o,ie as p};
1
+ import{a as O,b as H,c as j,d as E,e as W,f as ne}from"./chunk-FUZ6S2DY.js";import{a as N}from"./chunk-D27JNOLZ.js";import{a as X}from"./chunk-C72GO4IZ.js";import{j as T}from"./chunk-ACMJ2ZPS.js";import{D as I,E as y,G as L,o as S}from"./chunk-LYCLF26R.js";import{b as te}from"./chunk-QYADASLV.js";var ie={};te(ie,{CanvasMeasureAdapter:()=>$,CliMeasureAdapter:()=>D,ImageSizeAdapter:()=>J,NodeCanvasMeasureAdapter:()=>q,PrecomputedAdapter:()=>V,SvgBoundsAdapter:()=>z,analyzeAndMeasure:()=>O,carveTextLineSlots:()=>E,circleIntervalForBand:()=>Q,computeBlockFlow:()=>_,computeCharPositions:()=>W,computeFlowLines:()=>ee,computeLineBreaks:()=>H,computeTotalHeight:()=>U,layoutNextLine:()=>j,measureBlock:()=>Y,measureBlocks:()=>K,reactiveBlockLayout:()=>re,reactiveFlowLayout:()=>se,reactiveLayout:()=>ne,rectIntervalForBand:()=>Z});var D=class{cellPx;constructor(t){this.cellPx=t?.cellPx??8}measureSegment(t,n){return{width:X(t)*this.cellPx}}},G=class extends Error{name="KeyError"},V=class{metrics;fallback;constructor(t){this.metrics=t.metrics;let n=t.fallback??"per-char";if(n!=="per-char"&&n!=="error")throw new Error(`fallback must be 'per-char' or 'error', got ${JSON.stringify(t.fallback)}`);this.fallback=n}measureSegment(t,n){let i=this.metrics[n];if(i){let o=i[t];if(o!==void 0)return{width:o}}if(this.fallback==="error")throw new G(`PrecomputedAdapter: no metrics for segment ${JSON.stringify(t)} in font ${JSON.stringify(n)}`);let r=0;if(i)for(let o of t){let l=i[o];l!==void 0&&(r+=l)}return{width:r}}},$=class{ctx=null;currentFont="";emojiCorrection;constructor(t){this.emojiCorrection=t?.emojiCorrection??1}getContext(){if(!this.ctx){if(typeof OffscreenCanvas>"u")throw new Error("CanvasMeasureAdapter requires a browser environment with OffscreenCanvas support. Use CliMeasureAdapter or NodeCanvasMeasureAdapter for Node.js.");let n=new OffscreenCanvas(0,0).getContext("2d");if(!n)throw new Error("CanvasMeasureAdapter: failed to get 2d context");this.ctx=n}return this.ctx}measureSegment(t,n){let i=this.getContext();n!==this.currentFont&&(i.font=n,this.currentFont=n);let r=i.measureText(t).width;return this.emojiCorrection!==1&&new RegExp("\\p{Emoji_Presentation}","u").test(t)&&(r*=this.emojiCorrection),{width:r}}clearCache(){this.currentFont=""}},q=class{ctx=null;currentFont="";canvasModule;constructor(t){this.canvasModule=t}getContext(){if(!this.ctx){let n=this.canvasModule.createCanvas(0,0).getContext("2d");if(!n)throw new Error("NodeCanvasMeasureAdapter: failed to get 2d context");this.ctx=n}return this.ctx}measureSegment(t,n){let i=this.getContext();return n!==this.currentFont&&(i.font=n,this.currentFont=n),{width:i.measureText(t).width}}clearCache(){this.currentFont=""}},z=class{measureSvg(t){let n=t.match(/viewBox\s*=\s*["']([^"']+)["']/);if(n){let o=n[1].trim().split(/[\s,]+/);if(o.length>=4){let l=Number.parseFloat(o[2]),a=Number.parseFloat(o[3]);if(Number.isFinite(l)&&Number.isFinite(a)&&l>0&&a>0)return{width:l,height:a};throw new Error("SvgBoundsAdapter: viewBox width/height are missing, non-finite, or not positive")}}let i=t.match(/<svg[^>]*\bwidth\s*=\s*["']?([\d.]+)/),r=t.match(/<svg[^>]*\bheight\s*=\s*["']?([\d.]+)/);if(i&&r){let o=Number.parseFloat(i[1]),l=Number.parseFloat(r[1]);if(Number.isFinite(o)&&Number.isFinite(l)&&o>0&&l>0)return{width:o,height:l};throw new Error("SvgBoundsAdapter: svg width/height attributes are non-finite or not positive")}throw new Error("SvgBoundsAdapter: cannot determine dimensions \u2014 SVG has no viewBox or width/height attributes")}},J=class{sizes;constructor(t){this.sizes=new Map(Object.entries(t))}measureImage(t){let n=this.sizes.get(t);if(!n)throw new Error(`ImageSizeAdapter: no dimensions registered for ${JSON.stringify(t)}`);return{width:n.width,height:n.height}}};function Y(e,t,n,i,r,o,l){switch(e.type){case"text":{let a=e.font??r,m=e.lineHeight??o,d=O(e.text,a,n.text,i),w=H(d,t,n.text,a,i),v=W(w,d,m),B=w.lineCount*m,c=0;for(let x of w.lines)x.width>c&&(c=x.width);return{index:l,type:"text",width:Math.min(c,t),height:B,textSegments:d,textLineBreaks:w,textCharPositions:v}}case"image":{let a,m;if(e.naturalWidth!=null&&e.naturalHeight!=null)a=e.naturalWidth,m=e.naturalHeight;else if(n.image){let d=n.image.measureImage(e.src);a=d.width,m=d.height}else throw new Error(`Image block at index ${l} has no naturalWidth/naturalHeight and no ImageMeasurer adapter`);return a>t&&(m=m*t/a,a=t),{index:l,type:"image",width:a,height:m}}case"svg":{let a,m;if(e.viewBox)a=e.viewBox.width,m=e.viewBox.height;else if(n.svg){let d=n.svg.measureSvg(e.content);a=d.width,m=d.height}else throw new Error(`SVG block at index ${l} has no viewBox and no SvgMeasurer adapter`);return a>t&&(m=m*t/a,a=t),{index:l,type:"svg",width:a,height:m}}}}function K(e,t,n,i,r,o){return e.map((l,a)=>Y(l,t,n,i,r,o,a))}function _(e,t){let n=[],i=0;for(let r=0;r<e.length;r++){let o=e[r];n.push({...o,x:0,y:i}),i+=o.height+(r<e.length-1?t:0)}return n}function U(e){if(e.length===0)return 0;let t=e[e.length-1];return t.y+t.height}function re(e){let{adapters:t,name:n="reactive-block-layout",defaultFont:i="16px sans-serif",defaultLineHeight:r=20}=e,o=new T(n),l=new Map,a=y(e.blocks??[],{name:"blocks"}),m=y(Math.max(0,e.maxWidth??800),{name:"max-width"}),d=y(e.gap??0,{name:"gap"}),w=I([a,m],(c,x,s)=>{let p=c[0]!=null&&c[0].length>0?c[0].at(-1):s.prevData[0],h=c[1]!=null&&c[1].length>0?c[1].at(-1):s.prevData[1],g=S(),u=K(p,h,t,l,i,r),f=S()-g,b=w.meta;b&&(N(b["block-count"],u.length),N(b["layout-time-ns"],f)),x.emit(u);let C=()=>{l.clear(),t.text.clearCache?.()};return{deactivate:C,invalidate:C}},{name:"measured-blocks",describeKind:"derived",meta:{"block-count":0,"layout-time-ns":0},equals:(c,x)=>{let s=c,p=x;if(s==null||p==null)return s===p;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++){let g=s[h],u=p[h];if(g.type!==u.type||g.width!==u.width||g.height!==u.height||g.index!==u.index)return!1}return!0}}),v=L([w,d],([c,x])=>_(c,x),{name:"block-flow",equals:(c,x)=>{let s=c,p=x;if(s==null||p==null)return s===p;if(s.length!==p.length)return!1;for(let h=0;h<s.length;h++){let g=s[h],u=p[h];if(g.x!==u.x||g.y!==u.y||g.width!==u.width||g.height!==u.height)return!1}return!0}}),B=L([v],([c])=>U(c),{name:"total-height"});return o.add(a,{name:"blocks"}),o.add(m,{name:"max-width"}),o.add(d,{name:"gap"}),o.add(w,{name:"measured-blocks"}),o.add(v,{name:"block-flow"}),o.add(B,{name:"total-height"}),{graph:o,setBlocks:c=>o.set("blocks",c),setMaxWidth:c=>o.set("max-width",Math.max(0,c)),setGap:c=>o.set("gap",c),measuredBlocks:w,blockFlow:v,totalHeight:B}}function Q(e,t,n){let i=e.hPad??0,r=e.vPad??0,o=t-r,l=n+r;if(o>=e.cy+e.r||l<=e.cy-e.r)return null;let a=e.cy>=o&&e.cy<=l?0:e.cy<o?o-e.cy:e.cy-l;if(a>=e.r)return null;let m=Math.sqrt(e.r*e.r-a*a);return{left:e.cx-m-i,right:e.cx+m+i}}function Z(e,t,n){let i=e.hPad??0,r=e.vPad??0;return n<=e.y-r||t>=e.y+e.h+r?null:{left:e.x-i,right:e.x+e.w+i}}function oe(e,t,n){return e.kind==="circle"?Q(e,t,n):Z(e,t,n)}function ee(e,t,n,i,r,o,l){let a=l?.paragraphSpacing??r,m=[],d={segmentIndex:0,graphemeIndex:0};if(e.length===0||n.count<=0||r<=0)return{lines:m,cursor:d};let w=t.paddingX??0,v=t.paddingY??0,B=Math.max(0,t.width-w*2),c=Math.max(0,t.height-v*2),x=n.gap*Math.max(0,n.count-1),s=Math.max(0,(B-x)/n.count);if(s<=0)return{lines:m,cursor:d};e:for(let p=0;p<n.count;p++){let h=w+p*(s+n.gap),g=h+s,u=v;for(;u+r<=v+c;){let f=u+r,b=[];for(let k=0;k<i.length;k++){let M=oe(i[k],u,f);M!==null&&b.push(M)}let C=E({left:h,right:g},b,o);if(C.length===0){u+=r;continue}let P=!1;for(let k=0;k<C.length;k++){let M=C[k],R=M.right-M.left,F=j(e,d,R);if(F===null)return{lines:m,cursor:d};if(F.text.length===0&&F.width===0){d=F.end,P=!0;break}m.push({x:M.left,y:u,width:F.width,slotWidth:R,text:F.text,columnIndex:p,flushToRight:M.right<g-.5}),d=F.end}if(P){u+=a;continue}if(u+=r,d.segmentIndex>=e.length)break e}if(d.segmentIndex>=e.length)break}return{lines:m,cursor:d}}function se(e){let{adapter:t,name:n="reactive-flow-layout",minSlotWidth:i=20}=e,r=new T(n),o=new Map,l=y(e.text??"",{name:"text"}),a=y(e.font??"16px sans-serif",{name:"font"}),m=y(e.lineHeight??20,{name:"line-height"}),d=y(e.container??{width:800,height:600,paddingX:0,paddingY:0},{name:"container"}),w=y(e.columns??{count:1,gap:0},{name:"columns"}),v=y(e.obstacles??[],{name:"obstacles"}),B=y(e.paragraphSpacing??null,{name:"paragraph-spacing"}),c=I([l,a],(s,p,h)=>{let g=s[0],u=g!=null&&g.length>0?g.at(-1):h.prevData[0],f=s[1],b=f!=null&&f.length>0?f.at(-1):h.prevData[1],C=O(u,b,t,o);p.emit(C);let P=()=>{o.clear(),t.clearCache?.()};return{deactivate:P,invalidate:P}},{name:"segments",describeKind:"derived"}),x=L([c,d,w,v,m,B],([s,p,h,g,u,f])=>{let b=s,C=S(),P=f??u,{lines:k,cursor:M}=ee(b,p,h,g,u,i,{paragraphSpacing:P}),R=S()-C,F=Math.max(0,b.length-M.segmentIndex),A=x.meta;return A&&(N(A["line-count"],k.length),N(A["layout-time-ns"],R),N(A["overflow-segments"],F)),k},{name:"flow-lines",meta:{"line-count":0,"layout-time-ns":0,"overflow-segments":0},equals:(s,p)=>{let h=s,g=p;if(h.length!==g.length)return!1;for(let u=0;u<h.length;u++){let f=h[u],b=g[u];if(f.x!==b.x||f.y!==b.y||f.width!==b.width||f.slotWidth!==b.slotWidth||f.text!==b.text||f.columnIndex!==b.columnIndex||f.flushToRight!==b.flushToRight)return!1}return!0}});return r.add(l,{name:"text"}),r.add(a,{name:"font"}),r.add(m,{name:"line-height"}),r.add(d,{name:"container"}),r.add(w,{name:"columns"}),r.add(v,{name:"obstacles"}),r.add(B,{name:"paragraph-spacing"}),r.add(c,{name:"segments"}),r.add(x,{name:"flow-lines"}),{graph:r,setText:s=>r.set("text",s),setFont:s=>r.set("font",s),setLineHeight:s=>r.set("line-height",s),setContainer:s=>r.set("container",s),setColumns:s=>r.set("columns",s),setObstacles:s=>r.set("obstacles",s),setParagraphSpacing:s=>r.set("paragraph-spacing",s),segments:c,flowLines:x}}export{D as a,V as b,$ as c,q as d,z as e,J as f,Y as g,K as h,_ as i,U as j,re as k,Q as l,Z as m,ee as n,se as o,ie as p};
@@ -0,0 +1 @@
1
+ import{a as I,b as P,c as V,d as j,f as _,g as w}from"./chunk-3G5U5QNE.js";import{a as C,b as D,c as $,d as R,g as A,h as S,i as N,j as h,k as T,l as F}from"./chunk-ACMJ2ZPS.js";import{a as m,b as g,c as k,d as v,e as O,f as E,g as G,h as x}from"./chunk-LYCLF26R.js";import{b as u}from"./chunk-CK2E7BTU.js";import{b as H}from"./chunk-QYADASLV.js";var q={};H(q,{ENVELOPE_VERSION:()=>v,GRAPH_META_SEGMENT:()=>S,Graph:()=>h,JsonCodec:()=>m,SIZEOF_OVERHEAD:()=>C,SIZEOF_SYMBOL:()=>D,SNAPSHOT_VERSION:()=>N,createDagCborCodec:()=>g,createDagCborZstdCodec:()=>k,decodeEnvelope:()=>E,diffForWAL:()=>T,encodeEnvelope:()=>O,explainPath:()=>R,graphProfile:()=>A,reachable:()=>F,registerBuiltinCodecs:()=>G,replayWAL:()=>x,sizeof:()=>$,validateGraphObservability:()=>W,validateNoIslands:()=>M,watchTopologyTree:()=>L});function L(n,p){let o=new Map,c=(s,a)=>{if(o.has(s))return;let i={off:()=>{},prefix:a};o.set(s,i);let f=s.topology.subscribe(l=>{for(let t of l){if(t[0]!==u)continue;let e=t[1];if(p(e,s,a),e.kind==="added"&&e.nodeKind==="mount"){let r=s._mounts.get(e.name);if(r instanceof h){let d=`${a}${e.name}::`;c(r,d)}}else if(e.kind==="removed"&&e.nodeKind==="mount"){let r=`${a}${e.name}::`;for(let[d,y]of Array.from(o.entries()))d!==n&&y.prefix.startsWith(r)&&(y.off(),o.delete(d))}}});i.off=f;for(let[l,t]of s._mounts)if(t instanceof h){let e=`${a}${l}::`;c(t,e)}};return c(n,""),()=>{for(let s of o.values())s.off();o.clear()}}function M(n){let p=n.describe({detail:"minimal"}),o=Object.keys(p.nodes),c=new Set;for(let a of o){let i=p.nodes[a];if(!i)continue;let f=i.deps??[];for(let l of f)c.add(l)}let s=[];for(let a of o){let i=p.nodes[a];if(!i)continue;let l=(i.deps??[]).length,t=c.has(a);if(l===0&&!t){let e=i.type??"unknown";s.push({path:a,kind:e})}}return s.sort((a,i)=>a.path<i.path?-1:a.path>i.path?1:0),{ok:s.length===0,orphans:s,summary(){if(s.length===0)return"validateNoIslands: ok (no islands)";let a=s.slice(0,3).map(i=>`${i.path} (${i.kind})`).join(", ");return`validateNoIslands: ${s.length} island node(s) \u2014 ${a}${s.length>3?", \u2026":""}`}}}var K={json:n=>V(n),pretty:n=>w(n),mermaid:n=>j(n),"mermaid-url":n=>_(n),d2:n=>P(n),ascii:n=>I(n)};function W(n,p={}){let o=[],c=p.requireFound??!0;if(p.skipDescribe!==!0)try{let t=n.describe(),e=new Set(Object.keys(t.nodes)),r=[];for(let[d,y]of Object.entries(t.nodes))for(let b of y.deps)b!==""&&!e.has(b)&&r.push(`${d} \u2192 ${b}`);for(let d of t.edges)e.has(d.from)||r.push(`edge.from: ${d.from}`),e.has(d.to)||r.push(`edge.to: ${d.to}`);r.length>0?o.push({kind:"describe",ok:!1,reason:`describe() has ${r.length} dangling pointer(s); nodes \u2289 deps`,danglingDeps:r}):o.push({kind:"describe",ok:!0,nodeCount:e.size,edgeCount:t.edges.length})}catch(t){o.push({kind:"describe",ok:!1,reason:`describe() threw: ${t instanceof Error?t.message:String(t)}`})}if((p.formats?.length??0)>0){let t=n.describe();for(let e of p.formats)try{let r=K[e](t);typeof r!="string"||r.length===0?o.push({kind:"describe-format",ok:!1,format:e,reason:`${e} renderer returned empty or non-string output`}):o.push({kind:"describe-format",ok:!0,format:e,length:r.length})}catch(r){o.push({kind:"describe-format",ok:!1,format:e,reason:r instanceof Error?r.message:String(r)})}}for(let t of p.paths??[])try{n.resolve(t),o.push({kind:"observe",ok:!0,path:t})}catch(e){o.push({kind:"observe",ok:!1,path:t,reason:e instanceof Error?e.message:String(e)})}for(let[t,e]of p.pairs??[])try{let r=n.explain(t,e);c&&r.found===!1?o.push({kind:"explain",ok:!1,from:t,to:e,reason:`explain(${t} \u2192 ${e}) found no path${r.reason?`: ${r.reason}`:""}`}):o.push({kind:"explain",ok:!0,from:t,to:e,found:r.found,steps:r.steps.length})}catch(r){o.push({kind:"explain",ok:!1,from:t,to:e,reason:r instanceof Error?r.message:String(r)})}let s=o.filter(t=>!t.ok),a=s.length===0,i=p.paths?.length??0,f=p.pairs?.length??0,l=p.formats?.length??0;return{ok:a,checks:o,failures:s,summary(){let t=[p.skipDescribe===!0?null:"describe",l>0?`${l} format${l===1?"":"s"}`:null,i>0?`${i} observe path${i===1?"":"s"}`:null,f>0?`${f} explain pair${f===1?"":"s"}`:null].filter(r=>r!=null),e=t.length>0?t.join(", "):"describe-only";return a?`validateGraphObservability: OK (${e})`:`validateGraphObservability: ${s.length} failure(s) across ${e}`}}}export{L as a,M as b,W as c,q as d};
@@ -1 +1 @@
1
- import{b as G,c as F}from"./chunk-G3M3IMEV.js";import{a as A}from"./chunk-AI7QC7J6.js";import{a as q}from"./chunk-L6NSJVJZ.js";import{b as E}from"./chunk-TT4C7DXW.js";import{i as I}from"./chunk-POXANAJ6.js";import{C as M}from"./chunk-L77I47VU.js";import{E as d,G as o,H as O,m as S}from"./chunk-LYCLF26R.js";import{b as V}from"./chunk-QYADASLV.js";var $={};V($,{contentModerationGraph:()=>Q,dataQualityGraph:()=>T,issueTrackerGraph:()=>B,observabilityGraph:()=>D});function r(u,a){return q("domain_template",u,a)}function D(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=[{name:"errors",classify:e=>C(e,"error")},{name:"traces",classify:e=>C(e,"trace")},{name:"metrics",classify:e=>C(e,"metric")}],m=a.branches??h,y=m.map(e=>({name:e.name,classify:e.classify})),c=A("stratify",a.source,y);n.mount("stratify",c);let k=m.map(e=>{try{let i=n.resolve(`stratify::branch/${e.name}`);return o([i],([x])=>x,{initial:null})}catch{return d(null)}}),l=a.correlate??(e=>e),_=o(k,e=>l(e),{meta:r("observability",{stage:"correlate"})});n.add(_,{name:"correlate"});let N=a.sloCheck??(()=>({pass:!0})),w=o([_],e=>e[0],{meta:r("observability",{stage:"slo_value"})}),f=o([w],e=>N(e[0]),{meta:r("observability",{stage:"slo_verified"})});n.add(w,{name:"slo_value"}),n.add(f,{name:"slo_verified"});let v=a.weights??m.map(()=>1),b=k.map(e=>o([e],i=>i[0]!=null?1:0)),p=v.map(e=>d(e));for(let e=0;e<b.length;e++)n.add(b[e],{name:`__signal_${e}`}),n.add(p[e],{name:`__weight_${e}`});let t=F(b,p);n.add(t,{name:"alerts"});let g=o([t,f],e=>({scored:e[0],slo:e[1]}),{meta:r("observability",{stage:"output"})});n.add(g,{name:"output"});let R=d(null,{meta:r("observability",{stage:"feedback_reentry"})});n.add(R,{name:"feedback_reentry"});let s=o([f],e=>{let i=e[0];return i&&i.pass===!1?i:null},{meta:r("observability",{stage:"feedback_condition"})});return n.add(s,{name:"feedback_condition"}),G(n,"feedback_condition","feedback_reentry",{maxIterations:a.maxFeedbackIterations??5}),n}function B(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=0,m=e=>({id:`issue-${++h}`,title:String(e),severity:1,source:"unknown",raw:e}),y=a.extract??m,c=o([a.source],e=>y(e[0]),{meta:r("issue_tracker",{stage:"extract"})});n.add(c,{name:"extract"});let k=a.verify??(()=>({valid:!0})),l=o([c],e=>{let i=e[0];return{issue:i,verification:k(i)}},{meta:r("issue_tracker",{stage:"verify"})});n.add(l,{name:"verify"});let _=d([],{meta:r("issue_tracker",{stage:"known_patterns"})});n.add(_,{name:"known_patterns"});let N=a.detectRegression??(()=>({regression:!1})),w=o([c,_],e=>{let i=e[0],x=e[1];return{issue:i,regression:N(i,x)}},{meta:r("issue_tracker",{stage:"regression"})});n.add(w,{name:"regression"});let f=o([c],e=>e[0]?.severity??0),v=o([w],e=>e[0]?.regression?2:0);n.add(f,{name:"__severity_signal"}),n.add(v,{name:"__regression_signal"});let b=d(1),p=d(1.5);n.add(b,{name:"__severity_weight"}),n.add(p,{name:"__regression_weight"});let t=F([f,v],[b,p]);n.add(t,{name:"priority"});let g=o([l,w,t],e=>({verified:e[0],regression:e[1],priority:e[2]}),{meta:r("issue_tracker",{stage:"output"})});n.add(g,{name:"output"});let R=d(null,{meta:r("issue_tracker",{stage:"feedback_reentry"})});n.add(R,{name:"feedback_reentry"});let s=o([l],e=>{let i=e[0];if(i){let x=i.verification;if(x&&x.valid===!1)return i}return null},{meta:r("issue_tracker",{stage:"feedback_condition"})});return n.add(s,{name:"feedback_condition"}),G(n,"feedback_condition","feedback_reentry",{maxIterations:a.maxFeedbackIterations??3}),n}function Q(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=s=>({label:"review",confidence:.5,original:s}),m=a.classify??h,y=o([a.source],s=>m(s[0]),{meta:r("content_moderation",{stage:"classify"})});n.add(y,{name:"classify"});let c=A("stratify",y,[{name:"safe",classify:s=>s.label==="safe"},{name:"review",classify:s=>s.label==="review"},{name:"block",classify:s=>s.label==="block"}]);n.mount("stratify",c);let k=E([],{name:"review_queue",maxSize:a.maxQueueSize});n.add(k.entries,{name:"review_queue"});let l;try{l=n.resolve("stratify::branch/review")}catch{l=d(null),n.add(l,{name:"__review_fallback"})}let _=O([l],s=>{let e=s[0];e&&k.append(e)});n.add(_,{name:"__review_accumulator"}),n.addDisposer(M(_));let N=d({},{meta:r("content_moderation",{stage:"policy",access:"both",description:"Moderation policy rules \u2014 updated via feedback"})});n.add(N,{name:"policy"});let w=a.weights??[.1,1,2],f=o([y],s=>s[0]?.confidence??0),v=o([y],s=>{let e=s[0];return e?e.label==="block"?w[2]:e.label==="review"?w[1]:w[0]:0});n.add(f,{name:"__confidence_signal"}),n.add(v,{name:"__severity_signal"});let b=d(1),p=d(1);n.add(b,{name:"__w_confidence"}),n.add(p,{name:"__w_severity"});let t=F([f,v],[b,p]);n.add(t,{name:"priority"});let g=o([y,t],s=>({classification:s[0],priority:s[1]}),{meta:r("content_moderation",{stage:"output"})});n.add(g,{name:"output"});let R=o([k.entries,N],s=>{let e=s[0];if(e&&e.length>0){let i=e[e.length-1];if(i&&i.falsePositive)return i}return null},{meta:r("content_moderation",{stage:"feedback_condition"})});return n.add(R,{name:"feedback_condition"}),G(n,"feedback_condition","policy",{maxIterations:a.maxFeedbackIterations??5}),n}function T(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=a.validate??(t=>({valid:!0,errors:[],record:t})),m=o([a.source],t=>t[0]!=null?h(t[0]):void 0,{meta:r("data_quality",{stage:"validate"})});n.add(m,{name:"validate"});let y=a.detectAnomaly??(t=>({anomaly:!1,score:0,record:t})),c=o([a.source],t=>t[0]!=null?y(t[0]):void 0,{meta:r("data_quality",{stage:"anomaly"})});n.add(c,{name:"anomaly"});let k=d(null,{meta:r("data_quality",{stage:"baseline",description:"Rolling baseline for drift detection"})});n.add(k,{name:"baseline"});let l=O([m],t=>{let g=t[0];g?.valid&&S(()=>{k.emit(g.record)})});n.add(l,{name:"__baseline_updater"}),M(l);let _=a.detectDrift??(()=>({drift:!1})),N=o([a.source,k],t=>_(t[0],t[1]),{meta:r("data_quality",{stage:"drift"})});n.add(N,{name:"drift"});let w=a.suggest??(()=>null),f=o([m,c],t=>w({validation:t[0],anomaly:t[1]}),{meta:r("data_quality",{stage:"remediate"})});n.add(f,{name:"remediate"});let v=o([m,c,N,f],t=>({validation:t[0],anomaly:t[1],drift:t[2],remediation:t[3]}),{meta:r("data_quality",{stage:"output"})});n.add(v,{name:"output"});let b=d([],{meta:r("data_quality",{stage:"validation_rules"})});n.add(b,{name:"validation_rules"});let p=o([c],t=>{let g=t[0];return g?.anomaly?g:null},{meta:r("data_quality",{stage:"feedback_condition"})});return n.add(p,{name:"feedback_condition"}),G(n,"feedback_condition","validation_rules",{maxIterations:a.maxFeedbackIterations??3}),n}function C(u,a){if(u==null||typeof u!="object")return!1;let n=u;return n.type===a||n.kind===a}export{D as a,B as b,Q as c,T as d,$ as e};
1
+ import{b as G,c as F}from"./chunk-G5VBJ5K6.js";import{a as A}from"./chunk-FDZAZNRO.js";import{a as q}from"./chunk-L6NSJVJZ.js";import{b as E}from"./chunk-LDQ3IUIP.js";import{j as I}from"./chunk-ACMJ2ZPS.js";import{C as M}from"./chunk-2K5RXLAH.js";import{E as d,G as o,H as O,m as S}from"./chunk-LYCLF26R.js";import{b as V}from"./chunk-QYADASLV.js";var $={};V($,{contentModerationGraph:()=>Q,dataQualityGraph:()=>T,issueTrackerGraph:()=>B,observabilityGraph:()=>D});function r(u,a){return q("domain_template",u,a)}function D(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=[{name:"errors",classify:e=>C(e,"error")},{name:"traces",classify:e=>C(e,"trace")},{name:"metrics",classify:e=>C(e,"metric")}],m=a.branches??h,y=m.map(e=>({name:e.name,classify:e.classify})),c=A("stratify",a.source,y);n.mount("stratify",c);let k=m.map(e=>{try{let i=n.resolve(`stratify::branch/${e.name}`);return o([i],([x])=>x,{initial:null})}catch{return d(null)}}),l=a.correlate??(e=>e),_=o(k,e=>l(e),{meta:r("observability",{stage:"correlate"})});n.add(_,{name:"correlate"});let N=a.sloCheck??(()=>({pass:!0})),w=o([_],e=>e[0],{meta:r("observability",{stage:"slo_value"})}),f=o([w],e=>N(e[0]),{meta:r("observability",{stage:"slo_verified"})});n.add(w,{name:"slo_value"}),n.add(f,{name:"slo_verified"});let v=a.weights??m.map(()=>1),b=k.map(e=>o([e],i=>i[0]!=null?1:0)),p=v.map(e=>d(e));for(let e=0;e<b.length;e++)n.add(b[e],{name:`__signal_${e}`}),n.add(p[e],{name:`__weight_${e}`});let t=F(b,p);n.add(t,{name:"alerts"});let g=o([t,f],e=>({scored:e[0],slo:e[1]}),{meta:r("observability",{stage:"output"})});n.add(g,{name:"output"});let R=d(null,{meta:r("observability",{stage:"feedback_reentry"})});n.add(R,{name:"feedback_reentry"});let s=o([f],e=>{let i=e[0];return i&&i.pass===!1?i:null},{meta:r("observability",{stage:"feedback_condition"})});return n.add(s,{name:"feedback_condition"}),G(n,"feedback_condition","feedback_reentry",{maxIterations:a.maxFeedbackIterations??5}),n}function B(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=0,m=e=>({id:`issue-${++h}`,title:String(e),severity:1,source:"unknown",raw:e}),y=a.extract??m,c=o([a.source],e=>y(e[0]),{meta:r("issue_tracker",{stage:"extract"})});n.add(c,{name:"extract"});let k=a.verify??(()=>({valid:!0})),l=o([c],e=>{let i=e[0];return{issue:i,verification:k(i)}},{meta:r("issue_tracker",{stage:"verify"})});n.add(l,{name:"verify"});let _=d([],{meta:r("issue_tracker",{stage:"known_patterns"})});n.add(_,{name:"known_patterns"});let N=a.detectRegression??(()=>({regression:!1})),w=o([c,_],e=>{let i=e[0],x=e[1];return{issue:i,regression:N(i,x)}},{meta:r("issue_tracker",{stage:"regression"})});n.add(w,{name:"regression"});let f=o([c],e=>e[0]?.severity??0),v=o([w],e=>e[0]?.regression?2:0);n.add(f,{name:"__severity_signal"}),n.add(v,{name:"__regression_signal"});let b=d(1),p=d(1.5);n.add(b,{name:"__severity_weight"}),n.add(p,{name:"__regression_weight"});let t=F([f,v],[b,p]);n.add(t,{name:"priority"});let g=o([l,w,t],e=>({verified:e[0],regression:e[1],priority:e[2]}),{meta:r("issue_tracker",{stage:"output"})});n.add(g,{name:"output"});let R=d(null,{meta:r("issue_tracker",{stage:"feedback_reentry"})});n.add(R,{name:"feedback_reentry"});let s=o([l],e=>{let i=e[0];if(i){let x=i.verification;if(x&&x.valid===!1)return i}return null},{meta:r("issue_tracker",{stage:"feedback_condition"})});return n.add(s,{name:"feedback_condition"}),G(n,"feedback_condition","feedback_reentry",{maxIterations:a.maxFeedbackIterations??3}),n}function Q(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=s=>({label:"review",confidence:.5,original:s}),m=a.classify??h,y=o([a.source],s=>m(s[0]),{meta:r("content_moderation",{stage:"classify"})});n.add(y,{name:"classify"});let c=A("stratify",y,[{name:"safe",classify:s=>s.label==="safe"},{name:"review",classify:s=>s.label==="review"},{name:"block",classify:s=>s.label==="block"}]);n.mount("stratify",c);let k=E([],{name:"review_queue",maxSize:a.maxQueueSize});n.add(k.entries,{name:"review_queue"});let l;try{l=n.resolve("stratify::branch/review")}catch{l=d(null),n.add(l,{name:"__review_fallback"})}let _=O([l],s=>{let e=s[0];e&&k.append(e)});n.add(_,{name:"__review_accumulator"}),n.addDisposer(M(_));let N=d({},{meta:r("content_moderation",{stage:"policy",access:"both",description:"Moderation policy rules \u2014 updated via feedback"})});n.add(N,{name:"policy"});let w=a.weights??[.1,1,2],f=o([y],s=>s[0]?.confidence??0),v=o([y],s=>{let e=s[0];return e?e.label==="block"?w[2]:e.label==="review"?w[1]:w[0]:0});n.add(f,{name:"__confidence_signal"}),n.add(v,{name:"__severity_signal"});let b=d(1),p=d(1);n.add(b,{name:"__w_confidence"}),n.add(p,{name:"__w_severity"});let t=F([f,v],[b,p]);n.add(t,{name:"priority"});let g=o([y,t],s=>({classification:s[0],priority:s[1]}),{meta:r("content_moderation",{stage:"output"})});n.add(g,{name:"output"});let R=o([k.entries,N],s=>{let e=s[0];if(e&&e.length>0){let i=e[e.length-1];if(i&&i.falsePositive)return i}return null},{meta:r("content_moderation",{stage:"feedback_condition"})});return n.add(R,{name:"feedback_condition"}),G(n,"feedback_condition","policy",{maxIterations:a.maxFeedbackIterations??5}),n}function T(u,a){let n=new I(u,a);n.add(a.source,{name:"source"});let h=a.validate??(t=>({valid:!0,errors:[],record:t})),m=o([a.source],t=>t[0]!=null?h(t[0]):void 0,{meta:r("data_quality",{stage:"validate"})});n.add(m,{name:"validate"});let y=a.detectAnomaly??(t=>({anomaly:!1,score:0,record:t})),c=o([a.source],t=>t[0]!=null?y(t[0]):void 0,{meta:r("data_quality",{stage:"anomaly"})});n.add(c,{name:"anomaly"});let k=d(null,{meta:r("data_quality",{stage:"baseline",description:"Rolling baseline for drift detection"})});n.add(k,{name:"baseline"});let l=O([m],t=>{let g=t[0];g?.valid&&S(()=>{k.emit(g.record)})});n.add(l,{name:"__baseline_updater"}),M(l);let _=a.detectDrift??(()=>({drift:!1})),N=o([a.source,k],t=>_(t[0],t[1]),{meta:r("data_quality",{stage:"drift"})});n.add(N,{name:"drift"});let w=a.suggest??(()=>null),f=o([m,c],t=>w({validation:t[0],anomaly:t[1]}),{meta:r("data_quality",{stage:"remediate"})});n.add(f,{name:"remediate"});let v=o([m,c,N,f],t=>({validation:t[0],anomaly:t[1],drift:t[2],remediation:t[3]}),{meta:r("data_quality",{stage:"output"})});n.add(v,{name:"output"});let b=d([],{meta:r("data_quality",{stage:"validation_rules"})});n.add(b,{name:"validation_rules"});let p=o([c],t=>{let g=t[0];return g?.anomaly?g:null},{meta:r("data_quality",{stage:"feedback_condition"})});return n.add(p,{name:"feedback_condition"}),G(n,"feedback_condition","validation_rules",{maxIterations:a.maxFeedbackIterations??3}),n}function C(u,a){if(u==null||typeof u!="object")return!1;let n=u;return n.type===a||n.kind===a}export{D as a,B as b,Q as c,T as d,$ as e};