@graphrefly/graphrefly 0.47.2 → 0.48.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 (266) hide show
  1. package/dist/base/composition/index.cjs +4 -3
  2. package/dist/base/composition/index.cjs.map +1 -1
  3. package/dist/base/composition/index.d.cts +14 -5
  4. package/dist/base/composition/index.d.ts +14 -5
  5. package/dist/base/composition/index.js +8 -8
  6. package/dist/base/index.cjs +152 -78
  7. package/dist/base/index.cjs.map +1 -1
  8. package/dist/base/index.d.cts +2 -2
  9. package/dist/base/index.d.ts +2 -2
  10. package/dist/base/index.js +75 -70
  11. package/dist/base/io/index.cjs +31 -17
  12. package/dist/base/io/index.cjs.map +1 -1
  13. package/dist/base/io/index.d.cts +32 -5
  14. package/dist/base/io/index.d.ts +32 -5
  15. package/dist/base/io/index.js +1 -1
  16. package/dist/base/mutation/index.cjs +21 -0
  17. package/dist/base/mutation/index.cjs.map +1 -1
  18. package/dist/base/mutation/index.d.cts +23 -1
  19. package/dist/base/mutation/index.d.ts +23 -1
  20. package/dist/base/mutation/index.js +3 -1
  21. package/dist/base/sources/browser/index.cjs +5 -3
  22. package/dist/base/sources/browser/index.cjs.map +1 -1
  23. package/dist/base/sources/browser/index.d.cts +20 -2
  24. package/dist/base/sources/browser/index.d.ts +20 -2
  25. package/dist/base/sources/browser/index.js +5 -3
  26. package/dist/base/sources/browser/index.js.map +1 -1
  27. package/dist/base/sources/event/index.cjs +28 -0
  28. package/dist/base/sources/event/index.cjs.map +1 -1
  29. package/dist/base/sources/event/index.d.cts +67 -3
  30. package/dist/base/sources/event/index.d.ts +67 -3
  31. package/dist/base/sources/event/index.js +4 -1
  32. package/dist/base/sources/index.cjs +75 -37
  33. package/dist/base/sources/index.cjs.map +1 -1
  34. package/dist/base/sources/index.d.cts +1 -1
  35. package/dist/base/sources/index.d.ts +1 -1
  36. package/dist/base/sources/index.js +5 -2
  37. package/dist/{chunk-R6ZCSXKX.js → chunk-23MAWVOJ.js} +3 -3
  38. package/dist/{chunk-MS3WPRJR.js → chunk-3REMCHSS.js} +6 -6
  39. package/dist/chunk-3REMCHSS.js.map +1 -0
  40. package/dist/{chunk-CEVNQ74M.js → chunk-3YGXPUHW.js} +2 -2
  41. package/dist/{chunk-CEVNQ74M.js.map → chunk-3YGXPUHW.js.map} +1 -1
  42. package/dist/{chunk-6ZLCPUXS.js → chunk-46X2EFQH.js} +15 -4
  43. package/dist/chunk-46X2EFQH.js.map +1 -0
  44. package/dist/{chunk-NY2PYHNC.js → chunk-5UY3PNFY.js} +12 -5
  45. package/dist/chunk-5UY3PNFY.js.map +1 -0
  46. package/dist/{chunk-FQSQONOU.js → chunk-65OM4XLQ.js} +49 -3
  47. package/dist/chunk-65OM4XLQ.js.map +1 -0
  48. package/dist/{chunk-3PSLNJDU.js → chunk-6DQYBIHW.js} +314 -49
  49. package/dist/chunk-6DQYBIHW.js.map +1 -0
  50. package/dist/{chunk-LDCSZ72P.js → chunk-6YBER5UP.js} +3 -3
  51. package/dist/{chunk-LDCSZ72P.js.map → chunk-6YBER5UP.js.map} +1 -1
  52. package/dist/{chunk-3O3NKZJW.js → chunk-7T7WLEPM.js} +24 -3
  53. package/dist/chunk-7T7WLEPM.js.map +1 -0
  54. package/dist/{chunk-PKPO3JTZ.js → chunk-AQAKDE7F.js} +29 -11
  55. package/dist/chunk-AQAKDE7F.js.map +1 -0
  56. package/dist/{chunk-6MRSX3YK.js → chunk-B5Y5GPD5.js} +2 -2
  57. package/dist/{chunk-BXGZFGZ4.js → chunk-C5QD5DQX.js} +22 -1
  58. package/dist/chunk-C5QD5DQX.js.map +1 -0
  59. package/dist/{chunk-4XCHZRUJ.js → chunk-D5YGR4TP.js} +58 -7
  60. package/dist/chunk-D5YGR4TP.js.map +1 -0
  61. package/dist/{chunk-NPRP3MCV.js → chunk-DHDCOOJU.js} +2 -2
  62. package/dist/chunk-DHDCOOJU.js.map +1 -0
  63. package/dist/{chunk-VP3TIUDF.js → chunk-DVTDF5OI.js} +2 -2
  64. package/dist/{chunk-OXD5LFQP.js → chunk-G7H6PN7P.js} +2 -2
  65. package/dist/{chunk-EL5VHUGK.js → chunk-GGKHHG5Y.js} +32 -18
  66. package/dist/chunk-GGKHHG5Y.js.map +1 -0
  67. package/dist/{chunk-446I4EGD.js → chunk-J5TBZFBD.js} +2 -2
  68. package/dist/{chunk-7AVQIGF6.js → chunk-K4ZYJ4EM.js} +554 -460
  69. package/dist/chunk-K4ZYJ4EM.js.map +1 -0
  70. package/dist/{chunk-QFE5BQH7.js → chunk-LTSI7ULC.js} +2 -2
  71. package/dist/{chunk-5GVURVIG.js → chunk-MMHGYX44.js} +12 -2
  72. package/dist/{chunk-5GVURVIG.js.map → chunk-MMHGYX44.js.map} +1 -1
  73. package/dist/{chunk-KRFGO5QH.js → chunk-MQMTRKY3.js} +118 -43
  74. package/dist/chunk-MQMTRKY3.js.map +1 -0
  75. package/dist/{chunk-42FQ27MQ.js → chunk-MTODGQBR.js} +44 -179
  76. package/dist/chunk-MTODGQBR.js.map +1 -0
  77. package/dist/{chunk-FVINAAKA.js → chunk-NBK6QQMG.js} +14 -13
  78. package/dist/{chunk-FVINAAKA.js.map → chunk-NBK6QQMG.js.map} +1 -1
  79. package/dist/{chunk-KNU73RZW.js → chunk-NSA5K5G2.js} +2 -2
  80. package/dist/{chunk-MLTPJMH6.js → chunk-QQYULEZL.js} +2 -2
  81. package/dist/chunk-QSW4DFKE.js +31 -0
  82. package/dist/chunk-QSW4DFKE.js.map +1 -0
  83. package/dist/{chunk-VAZXUK6G.js → chunk-SUNCHMML.js} +2 -2
  84. package/dist/{chunk-EP4WVQLX.js → chunk-T2U6N3FV.js} +6 -6
  85. package/dist/{chunk-T7SP3EYR.js → chunk-T5URUIIY.js} +33 -24
  86. package/dist/chunk-T5URUIIY.js.map +1 -0
  87. package/dist/{chunk-VNXAF2KE.js → chunk-TPTZZV25.js} +6 -6
  88. package/dist/chunk-TPTZZV25.js.map +1 -0
  89. package/dist/{chunk-IOJDYUA7.js → chunk-V46JWFGV.js} +6 -5
  90. package/dist/chunk-V46JWFGV.js.map +1 -0
  91. package/dist/{chunk-WGDEBIP4.js → chunk-X6ESZDR6.js} +5 -6
  92. package/dist/chunk-X6ESZDR6.js.map +1 -0
  93. package/dist/{chunk-N65E26UL.js → chunk-XEWV254I.js} +2 -2
  94. package/dist/{chunk-N65E26UL.js.map → chunk-XEWV254I.js.map} +1 -1
  95. package/dist/{chunk-PTWADEH3.js → chunk-YBJVKMTM.js} +34 -14
  96. package/dist/chunk-YBJVKMTM.js.map +1 -0
  97. package/dist/{chunk-DDTS7F5O.js → chunk-ZW32BPXV.js} +12 -3
  98. package/dist/chunk-ZW32BPXV.js.map +1 -0
  99. package/dist/compat/index.cjs +51 -4
  100. package/dist/compat/index.cjs.map +1 -1
  101. package/dist/compat/index.d.cts +1 -1
  102. package/dist/compat/index.d.ts +1 -1
  103. package/dist/compat/index.js +6 -6
  104. package/dist/compat/nestjs/index.cjs +51 -4
  105. package/dist/compat/nestjs/index.cjs.map +1 -1
  106. package/dist/compat/nestjs/index.d.cts +1 -1
  107. package/dist/compat/nestjs/index.d.ts +1 -1
  108. package/dist/compat/nestjs/index.js +3 -3
  109. package/dist/{fallback-Bx46zqky.d.cts → fallback-BROR6ZhO.d.cts} +1 -1
  110. package/dist/{fallback-pIWW8A2d.d.ts → fallback-DO80aM_3.d.ts} +1 -1
  111. package/dist/{index-B_p8tnvf.d.cts → index-D1z3XcF9.d.cts} +1 -0
  112. package/dist/{index-_HDSmPyp.d.ts → index-DZ6yua0Q.d.ts} +1 -0
  113. package/dist/index.cjs +2215 -1676
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.cts +10 -10
  116. package/dist/index.d.ts +10 -10
  117. package/dist/index.js +169 -146
  118. package/dist/index.js.map +1 -1
  119. package/dist/presets/ai/index.cjs +46 -0
  120. package/dist/presets/ai/index.cjs.map +1 -1
  121. package/dist/presets/ai/index.js +12 -12
  122. package/dist/presets/harness/index.cjs +130 -18
  123. package/dist/presets/harness/index.cjs.map +1 -1
  124. package/dist/presets/harness/index.d.cts +15 -5
  125. package/dist/presets/harness/index.d.ts +15 -5
  126. package/dist/presets/harness/index.js +22 -22
  127. package/dist/presets/index.cjs +222 -53
  128. package/dist/presets/index.cjs.map +1 -1
  129. package/dist/presets/index.d.cts +2 -2
  130. package/dist/presets/index.d.ts +2 -2
  131. package/dist/presets/index.js +45 -45
  132. package/dist/presets/inspect/index.cjs +63 -14
  133. package/dist/presets/inspect/index.cjs.map +1 -1
  134. package/dist/presets/inspect/index.d.cts +1 -1
  135. package/dist/presets/inspect/index.d.ts +1 -1
  136. package/dist/presets/inspect/index.js +6 -6
  137. package/dist/presets/resilience/index.cjs +29 -21
  138. package/dist/presets/resilience/index.cjs.map +1 -1
  139. package/dist/presets/resilience/index.d.cts +12 -8
  140. package/dist/presets/resilience/index.d.ts +12 -8
  141. package/dist/presets/resilience/index.js +3 -3
  142. package/dist/{rate-limiter-DpVbSYdH.d.cts → rate-limiter-DC26FM8J.d.cts} +10 -1
  143. package/dist/{rate-limiter-CEALq4N1.d.ts → rate-limiter-DyWpwpQP.d.ts} +10 -1
  144. package/dist/{reactive-layout-fswlBUvX.d.ts → reactive-layout-BBBWH0V_.d.cts} +85 -4
  145. package/dist/{reactive-layout-fswlBUvX.d.cts → reactive-layout-BBBWH0V_.d.ts} +85 -4
  146. package/dist/solutions/index.cjs +168 -47
  147. package/dist/solutions/index.cjs.map +1 -1
  148. package/dist/solutions/index.d.cts +2 -2
  149. package/dist/solutions/index.d.ts +2 -2
  150. package/dist/solutions/index.js +28 -28
  151. package/dist/{spawnable-5mDY501F.d.cts → spawnable-B2IlW60f.d.cts} +23 -2
  152. package/dist/{spawnable-D3lR0oQu.d.ts → spawnable-tttFz2Nh.d.ts} +23 -2
  153. package/dist/testing/index.cjs +94 -0
  154. package/dist/testing/index.cjs.map +1 -0
  155. package/dist/testing/index.d.cts +59 -0
  156. package/dist/testing/index.d.ts +59 -0
  157. package/dist/testing/index.js +73 -0
  158. package/dist/testing/index.js.map +1 -0
  159. package/dist/utils/ai/browser.cjs.map +1 -1
  160. package/dist/utils/ai/browser.d.cts +2 -2
  161. package/dist/utils/ai/browser.d.ts +2 -2
  162. package/dist/utils/ai/browser.js +6 -6
  163. package/dist/utils/ai/browser.js.map +1 -1
  164. package/dist/utils/ai/index.cjs +250 -166
  165. package/dist/utils/ai/index.cjs.map +1 -1
  166. package/dist/utils/ai/index.d.cts +108 -12
  167. package/dist/utils/ai/index.d.ts +108 -12
  168. package/dist/utils/ai/index.js +21 -19
  169. package/dist/utils/ai/node.cjs.map +1 -1
  170. package/dist/utils/ai/node.d.cts +5 -5
  171. package/dist/utils/ai/node.d.ts +5 -5
  172. package/dist/utils/ai/node.js +2 -2
  173. package/dist/utils/ai/node.js.map +1 -1
  174. package/dist/utils/cqrs/index.cjs +29 -3
  175. package/dist/utils/cqrs/index.cjs.map +1 -1
  176. package/dist/utils/cqrs/index.d.cts +12 -7
  177. package/dist/utils/cqrs/index.d.ts +12 -7
  178. package/dist/utils/cqrs/index.js +2 -2
  179. package/dist/utils/demo-shell/index.cjs +45 -19
  180. package/dist/utils/demo-shell/index.cjs.map +1 -1
  181. package/dist/utils/demo-shell/index.d.cts +1 -1
  182. package/dist/utils/demo-shell/index.d.ts +1 -1
  183. package/dist/utils/demo-shell/index.js +2 -2
  184. package/dist/utils/domain-templates/index.cjs.map +1 -1
  185. package/dist/utils/domain-templates/index.js +3 -3
  186. package/dist/utils/graphspec/index.cjs.map +1 -1
  187. package/dist/utils/graphspec/index.js +3 -3
  188. package/dist/utils/index.cjs +1642 -1225
  189. package/dist/utils/index.cjs.map +1 -1
  190. package/dist/utils/index.d.cts +7 -7
  191. package/dist/utils/index.d.ts +7 -7
  192. package/dist/utils/index.js +72 -54
  193. package/dist/utils/inspect/index.cjs +52 -4
  194. package/dist/utils/inspect/index.cjs.map +1 -1
  195. package/dist/utils/inspect/index.d.cts +32 -3
  196. package/dist/utils/inspect/index.d.ts +32 -3
  197. package/dist/utils/inspect/index.js +4 -4
  198. package/dist/utils/job-queue/index.cjs +46 -9
  199. package/dist/utils/job-queue/index.cjs.map +1 -1
  200. package/dist/utils/job-queue/index.d.cts +33 -3
  201. package/dist/utils/job-queue/index.d.ts +33 -3
  202. package/dist/utils/job-queue/index.js +2 -2
  203. package/dist/utils/memory/index.cjs +556 -462
  204. package/dist/utils/memory/index.cjs.map +1 -1
  205. package/dist/utils/memory/index.d.cts +203 -24
  206. package/dist/utils/memory/index.d.ts +203 -24
  207. package/dist/utils/memory/index.js +10 -2
  208. package/dist/utils/messaging/index.cjs.map +1 -1
  209. package/dist/utils/messaging/index.d.cts +4 -3
  210. package/dist/utils/messaging/index.d.ts +4 -3
  211. package/dist/utils/messaging/index.js +2 -2
  212. package/dist/utils/orchestration/index.cjs +9 -0
  213. package/dist/utils/orchestration/index.cjs.map +1 -1
  214. package/dist/utils/orchestration/index.js +3 -3
  215. package/dist/utils/process/index.cjs +32 -2
  216. package/dist/utils/process/index.cjs.map +1 -1
  217. package/dist/utils/process/index.d.cts +4 -3
  218. package/dist/utils/process/index.d.ts +4 -3
  219. package/dist/utils/process/index.js +2 -2
  220. package/dist/utils/reactive-layout/index.cjs +184 -55
  221. package/dist/utils/reactive-layout/index.cjs.map +1 -1
  222. package/dist/utils/reactive-layout/index.d.cts +128 -3
  223. package/dist/utils/reactive-layout/index.d.ts +128 -3
  224. package/dist/utils/reactive-layout/index.js +16 -8
  225. package/dist/utils/reduction/index.cjs.map +1 -1
  226. package/dist/utils/reduction/index.js +2 -2
  227. package/dist/utils/resilience/index.cjs +29 -20
  228. package/dist/utils/resilience/index.cjs.map +1 -1
  229. package/dist/utils/resilience/index.d.cts +1 -1
  230. package/dist/utils/resilience/index.d.ts +1 -1
  231. package/dist/utils/resilience/index.js +2 -2
  232. package/dist/utils/surface/index.cjs.map +1 -1
  233. package/dist/utils/surface/index.js +4 -4
  234. package/package.json +15 -3
  235. package/dist/chunk-3O3NKZJW.js.map +0 -1
  236. package/dist/chunk-3PSLNJDU.js.map +0 -1
  237. package/dist/chunk-42FQ27MQ.js.map +0 -1
  238. package/dist/chunk-4XCHZRUJ.js.map +0 -1
  239. package/dist/chunk-6ZLCPUXS.js.map +0 -1
  240. package/dist/chunk-7AVQIGF6.js.map +0 -1
  241. package/dist/chunk-BXGZFGZ4.js.map +0 -1
  242. package/dist/chunk-DDTS7F5O.js.map +0 -1
  243. package/dist/chunk-EL5VHUGK.js.map +0 -1
  244. package/dist/chunk-FQSQONOU.js.map +0 -1
  245. package/dist/chunk-IOJDYUA7.js.map +0 -1
  246. package/dist/chunk-KRFGO5QH.js.map +0 -1
  247. package/dist/chunk-MS3WPRJR.js.map +0 -1
  248. package/dist/chunk-NPRP3MCV.js.map +0 -1
  249. package/dist/chunk-NY2PYHNC.js.map +0 -1
  250. package/dist/chunk-PKPO3JTZ.js.map +0 -1
  251. package/dist/chunk-PTWADEH3.js.map +0 -1
  252. package/dist/chunk-T7SP3EYR.js.map +0 -1
  253. package/dist/chunk-VNXAF2KE.js.map +0 -1
  254. package/dist/chunk-W2BOPXTI.js +0 -1
  255. package/dist/chunk-W2BOPXTI.js.map +0 -1
  256. package/dist/chunk-WGDEBIP4.js.map +0 -1
  257. /package/dist/{chunk-R6ZCSXKX.js.map → chunk-23MAWVOJ.js.map} +0 -0
  258. /package/dist/{chunk-6MRSX3YK.js.map → chunk-B5Y5GPD5.js.map} +0 -0
  259. /package/dist/{chunk-VP3TIUDF.js.map → chunk-DVTDF5OI.js.map} +0 -0
  260. /package/dist/{chunk-OXD5LFQP.js.map → chunk-G7H6PN7P.js.map} +0 -0
  261. /package/dist/{chunk-446I4EGD.js.map → chunk-J5TBZFBD.js.map} +0 -0
  262. /package/dist/{chunk-QFE5BQH7.js.map → chunk-LTSI7ULC.js.map} +0 -0
  263. /package/dist/{chunk-KNU73RZW.js.map → chunk-NSA5K5G2.js.map} +0 -0
  264. /package/dist/{chunk-MLTPJMH6.js.map → chunk-QQYULEZL.js.map} +0 -0
  265. /package/dist/{chunk-VAZXUK6G.js.map → chunk-SUNCHMML.js.map} +0 -0
  266. /package/dist/{chunk-EP4WVQLX.js.map → chunk-T2U6N3FV.js.map} +0 -0
@@ -202,6 +202,7 @@ __export(ai_exports, {
202
202
  tier: () => tier,
203
203
  toolCallExtractor: () => toolCallExtractor,
204
204
  toolExecution: () => toolExecution,
205
+ toolInterceptor: () => toolInterceptor,
205
206
  toolRegistry: () => toolRegistry,
206
207
  toolSelector: () => toolSelector,
207
208
  validateGraphDef: () => validateGraphDef,
@@ -4755,6 +4756,10 @@ var PipelineGraph = class extends import_graph3.Graph {
4755
4756
  {
4756
4757
  name,
4757
4758
  describeKind: "derived",
4759
+ // Spec §2.7 R2.7.1 (DS-2.7.A). fn must fire on
4760
+ // upstream-COMPLETE/ERROR-only-without-DATA so the
4761
+ // teardown-decision record + downstream terminal forward run.
4762
+ terminalAsRealInput: true,
4758
4763
  meta: meta("approval_gate", opts.meta)
4759
4764
  }
4760
4765
  );
@@ -4972,6 +4977,11 @@ var PipelineGraph = class extends import_graph3.Graph {
4972
4977
  describeKind: "derived",
4973
4978
  completeWhenDepsComplete: opts.completeWhenDepsComplete ?? !(mode === "completed" || mode === "terminal"),
4974
4979
  errorWhenDepsError: !(mode === "errored" || mode === "terminal"),
4980
+ // Spec §2.7 R2.7.1 (DS-2.7.A). `catch` exists to fire on a
4981
+ // source terminal — its whole job is `recover(cause, …)` on a
4982
+ // terminal-only wave. Without this opt-in the gate holds and
4983
+ // the recover branch never runs.
4984
+ terminalAsRealInput: true,
4975
4985
  meta: meta("catch", opts.meta)
4976
4986
  }
4977
4987
  );
@@ -5788,9 +5798,83 @@ function executeOne(call, tools, retryCount, onError) {
5788
5798
  }));
5789
5799
  }
5790
5800
 
5791
- // src/utils/ai/agents/tool-registry.ts
5801
+ // src/utils/ai/agents/tool-interceptor.ts
5792
5802
  var import_core39 = require("@graphrefly/pure-ts/core");
5793
5803
  var import_extra26 = require("@graphrefly/pure-ts/extra");
5804
+ function toolInterceptor(opts = {}) {
5805
+ return (calls) => {
5806
+ const enabledNode = opts.enabled != null ? (0, import_extra26.fromAny)(opts.enabled) : void 0;
5807
+ const predNodes = (opts.allow ?? []).map((p) => (0, import_extra26.fromAny)(p));
5808
+ const deps = [calls, ...enabledNode ? [enabledNode] : [], ...predNodes];
5809
+ return (0, import_core39.node)(
5810
+ deps,
5811
+ (batchData, actions, ctx) => {
5812
+ const callsBatch = batchData[0];
5813
+ if (callsBatch == null || callsBatch.length === 0) {
5814
+ actions.down([[import_core39.RESOLVED]]);
5815
+ return;
5816
+ }
5817
+ const data = batchData.map(
5818
+ (batch8, i) => batch8 != null && batch8.length > 0 ? batch8.at(-1) : ctx.prevData[i]
5819
+ );
5820
+ const incoming = data[0] ?? [];
5821
+ let cursor = 1;
5822
+ if (enabledNode) {
5823
+ const enabled = data[cursor++];
5824
+ if (enabled === false) {
5825
+ actions.down([[import_core39.RESOLVED]]);
5826
+ return;
5827
+ }
5828
+ }
5829
+ const preds = data.slice(cursor);
5830
+ const kept = incoming.filter((call) => {
5831
+ for (const pred of preds) {
5832
+ if (pred == null) continue;
5833
+ try {
5834
+ if (!pred(call)) return false;
5835
+ } catch {
5836
+ return false;
5837
+ }
5838
+ }
5839
+ return true;
5840
+ });
5841
+ if (kept.length === 0) {
5842
+ actions.down([[import_core39.RESOLVED]]);
5843
+ return;
5844
+ }
5845
+ actions.emit(kept);
5846
+ },
5847
+ {
5848
+ name: opts.name ?? "tool-interceptor",
5849
+ describeKind: "derived",
5850
+ // NON-partial (no `partial: true`) — deliberate. A seeded
5851
+ // `enabled`/predicate (with an `initial`) emits on activation,
5852
+ // so it is honoured before any tool call flows (the contract
5853
+ // callers must follow — see `allow` JSDoc). `partial: true`
5854
+ // was tried and REJECTED: it un-gates the node so `calls`
5855
+ // races ahead of a slower seeded policy dep on the activation
5856
+ // wave and leaks denied calls fail-OPEN. A *never-seeded*
5857
+ // (pure SENTINEL) policy has unspecified gating under either
5858
+ // setting — callers must seed an `initial`; not relied on.
5859
+ // Cross-ref `tool-selector.ts` (same non-partial shape).
5860
+ meta: { ...aiMeta("tool_interceptor"), ...(0, import_core39.factoryTag)("toolInterceptor") },
5861
+ equals: (a, b) => {
5862
+ const la = a;
5863
+ const lb = b;
5864
+ if (la.length !== lb.length) return false;
5865
+ for (let i = 0; i < la.length; i++) {
5866
+ if (la[i] !== lb[i]) return false;
5867
+ }
5868
+ return true;
5869
+ }
5870
+ }
5871
+ );
5872
+ };
5873
+ }
5874
+
5875
+ // src/utils/ai/agents/tool-registry.ts
5876
+ var import_core40 = require("@graphrefly/pure-ts/core");
5877
+ var import_extra27 = require("@graphrefly/pure-ts/extra");
5794
5878
  var import_graph5 = require("@graphrefly/pure-ts/graph");
5795
5879
  var ToolRegistryGraph = class extends import_graph5.Graph {
5796
5880
  definitions;
@@ -5798,12 +5882,12 @@ var ToolRegistryGraph = class extends import_graph5.Graph {
5798
5882
  _bundle;
5799
5883
  constructor(name, opts = {}) {
5800
5884
  super(name, opts.graph);
5801
- this._bundle = (0, import_extra26.reactiveMap)({
5885
+ this._bundle = (0, import_extra27.reactiveMap)({
5802
5886
  name: "definitions"
5803
5887
  });
5804
5888
  this.definitions = this._bundle.entries;
5805
5889
  this.add(this.definitions, { name: "definitions" });
5806
- this.schemas = (0, import_core39.node)(
5890
+ this.schemas = (0, import_core40.node)(
5807
5891
  [this.definitions],
5808
5892
  (batchData, actions, ctx) => {
5809
5893
  const data = batchData.map(
@@ -5820,7 +5904,7 @@ var ToolRegistryGraph = class extends import_graph5.Graph {
5820
5904
  }
5821
5905
  );
5822
5906
  this.add(this.schemas, { name: "schemas" });
5823
- this.addDisposer((0, import_extra26.keepalive)(this.schemas));
5907
+ this.addDisposer((0, import_extra27.keepalive)(this.schemas));
5824
5908
  }
5825
5909
  register(tool) {
5826
5910
  this._bundle.set(tool.name, tool);
@@ -5855,7 +5939,7 @@ var ToolRegistryGraph = class extends import_graph5.Graph {
5855
5939
  executeReactive(name, args) {
5856
5940
  const tool = this._bundle.get(name);
5857
5941
  if (!tool) throw new Error(`toolRegistry: unknown tool "${name}"`);
5858
- return (0, import_core39.node)(
5942
+ return (0, import_core40.node)(
5859
5943
  [],
5860
5944
  (_data, actions) => {
5861
5945
  const ac = new AbortController();
@@ -5864,7 +5948,7 @@ var ToolRegistryGraph = class extends import_graph5.Graph {
5864
5948
  const raw = tool.handler(args, { signal: ac.signal });
5865
5949
  inner = handlerResultToNode(raw, ac.signal);
5866
5950
  } catch (err) {
5867
- actions.down([[import_core39.ERROR, err]]);
5951
+ actions.down([[import_core40.ERROR, err]]);
5868
5952
  return {
5869
5953
  onDeactivation: () => {
5870
5954
  ac.abort();
@@ -5900,22 +5984,22 @@ function handlerResultToNode(raw, signal) {
5900
5984
  return raw;
5901
5985
  }
5902
5986
  if (raw != null && typeof raw.then === "function") {
5903
- return (0, import_extra26.fromPromise)(raw, { signal });
5987
+ return (0, import_extra27.fromPromise)(raw, { signal });
5904
5988
  }
5905
5989
  if (raw != null && typeof raw === "object" && Symbol.asyncIterator in raw) {
5906
- return (0, import_extra26.fromAsyncIter)(raw, { signal });
5990
+ return (0, import_extra27.fromAsyncIter)(raw, { signal });
5907
5991
  }
5908
- return (0, import_extra26.fromPromise)(Promise.resolve(raw), { signal });
5992
+ return (0, import_extra27.fromPromise)(Promise.resolve(raw), { signal });
5909
5993
  }
5910
5994
 
5911
5995
  // src/utils/ai/agents/tool-selector.ts
5912
- var import_core40 = require("@graphrefly/pure-ts/core");
5913
- var import_extra27 = require("@graphrefly/pure-ts/extra");
5996
+ var import_core41 = require("@graphrefly/pure-ts/core");
5997
+ var import_extra28 = require("@graphrefly/pure-ts/extra");
5914
5998
  function toolSelector(allTools, constraints, opts) {
5915
- const allToolsNode = (0, import_extra27.fromAny)(allTools);
5916
- const constraintNodes = constraints.map((c) => (0, import_extra27.fromAny)(c));
5999
+ const allToolsNode = (0, import_extra28.fromAny)(allTools);
6000
+ const constraintNodes = constraints.map((c) => (0, import_extra28.fromAny)(c));
5917
6001
  const deps = [allToolsNode, ...constraintNodes];
5918
- return (0, import_core40.node)(
6002
+ return (0, import_core41.node)(
5919
6003
  deps,
5920
6004
  (batchData, actions, ctx) => {
5921
6005
  const data = batchData.map(
@@ -5936,7 +6020,7 @@ function toolSelector(allTools, constraints, opts) {
5936
6020
  {
5937
6021
  name: opts?.name ?? "tool-selector",
5938
6022
  describeKind: "derived",
5939
- meta: { ...aiMeta("tool_selector"), ...(0, import_core40.factoryTag)("toolSelector") },
6023
+ meta: { ...aiMeta("tool_selector"), ...(0, import_core41.factoryTag)("toolSelector") },
5940
6024
  equals: (a, b) => {
5941
6025
  const la = a;
5942
6026
  const lb = b;
@@ -5983,20 +6067,20 @@ function admissionFilter3D(opts) {
5983
6067
  }
5984
6068
 
5985
6069
  // src/utils/ai/memory/memory-composers.ts
5986
- var import_core44 = require("@graphrefly/pure-ts/core");
5987
- var import_extra32 = require("@graphrefly/pure-ts/extra");
6070
+ var import_core45 = require("@graphrefly/pure-ts/core");
6071
+ var import_extra33 = require("@graphrefly/pure-ts/extra");
5988
6072
  var import_graph7 = require("@graphrefly/pure-ts/graph");
5989
6073
 
5990
6074
  // src/base/composition/distill.ts
5991
- var import_core42 = require("@graphrefly/pure-ts/core");
5992
- var import_extra30 = require("@graphrefly/pure-ts/extra");
6075
+ var import_core43 = require("@graphrefly/pure-ts/core");
6076
+ var import_extra31 = require("@graphrefly/pure-ts/extra");
5993
6077
 
5994
6078
  // src/base/sources/async.ts
5995
- var import_core41 = require("@graphrefly/pure-ts/core");
5996
- var import_extra28 = require("@graphrefly/pure-ts/extra");
6079
+ var import_core42 = require("@graphrefly/pure-ts/core");
5997
6080
  var import_extra29 = require("@graphrefly/pure-ts/extra");
6081
+ var import_extra30 = require("@graphrefly/pure-ts/extra");
5998
6082
  function forEach(source, fn, opts) {
5999
- const inner = (0, import_core41.node)(
6083
+ const inner = (0, import_core42.node)(
6000
6084
  [source],
6001
6085
  (data, _actions) => {
6002
6086
  const batch0 = data[0];
@@ -6014,8 +6098,8 @@ function forEach(source, fn, opts) {
6014
6098
  function isNodeLike2(value) {
6015
6099
  return typeof value === "object" && value !== null && "cache" in value && typeof value.subscribe === "function";
6016
6100
  }
6017
- function keepalive9(node38) {
6018
- node38.subscribe(() => void 0);
6101
+ function keepalive9(node39) {
6102
+ node39.subscribe(() => void 0);
6019
6103
  }
6020
6104
  function mapFromSnapshot(snapshot) {
6021
6105
  if (snapshot instanceof Map) return snapshot;
@@ -6025,7 +6109,7 @@ function applyExtraction(store, extraction) {
6025
6109
  if (!Array.isArray(extraction.upsert)) {
6026
6110
  throw new TypeError("distill extraction requires upsert: Array<{ key, value }>");
6027
6111
  }
6028
- (0, import_core42.batch)(() => {
6112
+ (0, import_core43.batch)(() => {
6029
6113
  for (const { key, value } of extraction.upsert) {
6030
6114
  store.set(key, value);
6031
6115
  }
@@ -6035,12 +6119,12 @@ function applyExtraction(store, extraction) {
6035
6119
  });
6036
6120
  }
6037
6121
  function distill(source, extractFn, opts) {
6038
- const sourceNode = (0, import_extra30.fromAny)(source);
6039
- const store = (0, import_extra30.reactiveMap)(opts.mapOptions ?? {});
6122
+ const sourceNode = (0, import_extra31.fromAny)(source);
6123
+ const store = (0, import_extra31.reactiveMap)(opts.mapOptions ?? {});
6040
6124
  const budget = opts.budget ?? 2e3;
6041
6125
  const hasContext = opts.context !== void 0 && opts.context !== null;
6042
- const contextNode = hasContext ? (0, import_extra30.fromAny)(opts.context) : (0, import_core42.node)([], { initial: null });
6043
- const extractionStream = (0, import_extra30.fromAny)(
6126
+ const contextNode = hasContext ? (0, import_extra31.fromAny)(opts.context) : (0, import_core43.node)([], { initial: null });
6127
+ const extractionStream = (0, import_extra31.fromAny)(
6044
6128
  extractFn(sourceNode, store.entries)
6045
6129
  );
6046
6130
  forEach(extractionStream, (extraction) => {
@@ -6048,7 +6132,7 @@ function distill(source, extractFn, opts) {
6048
6132
  });
6049
6133
  if (opts.evict) {
6050
6134
  const verdictUnsubs = /* @__PURE__ */ new Map();
6051
- const evictionKeys = (0, import_core42.node)(
6135
+ const evictionKeys = (0, import_core43.node)(
6052
6136
  [store.entries],
6053
6137
  (batchData, actions, ctx) => {
6054
6138
  const batch0 = batchData[0];
@@ -6090,12 +6174,12 @@ function distill(source, extractFn, opts) {
6090
6174
  }
6091
6175
  const hasConsolidateTrigger = opts.consolidateTrigger !== void 0 && opts.consolidateTrigger !== null;
6092
6176
  if (opts.consolidate && hasConsolidateTrigger) {
6093
- const consolidateTriggerNode = (0, import_extra30.fromAny)(opts.consolidateTrigger);
6094
- const consolidatePaired = (0, import_extra30.withLatestFrom)(
6177
+ const consolidateTriggerNode = (0, import_extra31.fromAny)(opts.consolidateTrigger);
6178
+ const consolidatePaired = (0, import_extra31.withLatestFrom)(
6095
6179
  consolidateTriggerNode,
6096
6180
  store.entries
6097
6181
  );
6098
- const consolidationStream = (0, import_extra30.switchMap)(
6182
+ const consolidationStream = (0, import_extra31.switchMap)(
6099
6183
  consolidatePaired,
6100
6184
  ([, entries]) => opts.consolidate(mapFromSnapshot(entries))
6101
6185
  );
@@ -6103,7 +6187,7 @@ function distill(source, extractFn, opts) {
6103
6187
  applyExtraction(store, extraction);
6104
6188
  });
6105
6189
  }
6106
- const compact = (0, import_core42.node)(
6190
+ const compact = (0, import_core43.node)(
6107
6191
  [store.entries, contextNode],
6108
6192
  (batchData, actions, ctx) => {
6109
6193
  const data = batchData.map(
@@ -6129,9 +6213,9 @@ function distill(source, extractFn, opts) {
6129
6213
  }
6130
6214
  actions.emit(packed);
6131
6215
  },
6132
- { describeKind: "derived", meta: { ...(0, import_core42.factoryTag)("distill", { budget }) } }
6216
+ { describeKind: "derived", meta: { ...(0, import_core43.factoryTag)("distill", { budget }) } }
6133
6217
  );
6134
- const size = (0, import_core42.node)(
6218
+ const size = (0, import_core43.node)(
6135
6219
  [store.entries],
6136
6220
  (batchData, actions, ctx) => {
6137
6221
  const batch0 = batchData[0];
@@ -6156,16 +6240,16 @@ function decay(baseScore, ageSeconds2, ratePerSecond, minScore = 0) {
6156
6240
  }
6157
6241
 
6158
6242
  // src/utils/memory/index.ts
6159
- var import_core43 = require("@graphrefly/pure-ts/core");
6160
- var import_extra31 = require("@graphrefly/pure-ts/extra");
6243
+ var import_core44 = require("@graphrefly/pure-ts/core");
6244
+ var import_extra32 = require("@graphrefly/pure-ts/extra");
6161
6245
  var import_graph6 = require("@graphrefly/pure-ts/graph");
6162
6246
  var NS_PER_SEC2 = 1e9;
6163
6247
  function memoryMeta(kind, extra) {
6164
6248
  return domainMeta("memory", kind, extra);
6165
6249
  }
6166
6250
  function toNode(v, name) {
6167
- if (v instanceof import_core43.NodeImpl) return v;
6168
- return (0, import_core43.node)([], { initial: v, ...name ? { name } : void 0 });
6251
+ if (v instanceof import_core44.NodeImpl) return v;
6252
+ return (0, import_core44.node)([], { initial: v, ...name ? { name } : void 0 });
6169
6253
  }
6170
6254
  function ageSeconds(now, lastNs) {
6171
6255
  return (now - lastNs) / NS_PER_SEC2;
@@ -6219,14 +6303,14 @@ function collection(name, opts = {}) {
6219
6303
  }
6220
6304
  const scoreFnDefault = () => ranked ? 1 : 0;
6221
6305
  const scoreInput = opts.score ?? scoreFnDefault;
6222
- const scoreNode = ranked && scoreInput instanceof import_core43.NodeImpl ? scoreInput : void 0;
6306
+ const scoreNode = ranked && scoreInput instanceof import_core44.NodeImpl ? scoreInput : void 0;
6223
6307
  const readScoreFn = () => {
6224
6308
  if (scoreNode) return scoreNode.cache ?? scoreFnDefault;
6225
6309
  return scoreInput;
6226
6310
  };
6227
6311
  const graph = new import_graph6.Graph(name);
6228
- const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0, import_core43.monotonicNs)(), v.lastAccessNs), decayRate, minScore) : v.lastAccessNs;
6229
- const items = (0, import_extra31.reactiveMap)({
6312
+ const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0, import_core44.monotonicNs)(), v.lastAccessNs), decayRate, minScore) : v.lastAccessNs;
6313
+ const items = (0, import_extra32.reactiveMap)({
6230
6314
  name: "items",
6231
6315
  ...maxSize !== void 0 ? { retention: { score: retentionScore, maxSize } } : {}
6232
6316
  });
@@ -6234,16 +6318,16 @@ function collection(name, opts = {}) {
6234
6318
  let refreshTick;
6235
6319
  if (ranked && decayRate > 0) {
6236
6320
  const intervalMs = opts.refreshIntervalMs ?? Math.max(1, 1e3 * Math.LN2 / (10 * decayRate));
6237
- const tickCounter = (0, import_extra31.fromTimer)(intervalMs, { period: intervalMs });
6238
- refreshTick = (0, import_core43.node)(
6321
+ const tickCounter = (0, import_extra32.fromTimer)(intervalMs, { period: intervalMs });
6322
+ refreshTick = (0, import_core44.node)(
6239
6323
  [tickCounter],
6240
6324
  (_batchData, actions) => {
6241
- actions.emit((0, import_core43.monotonicNs)());
6325
+ actions.emit((0, import_core44.monotonicNs)());
6242
6326
  },
6243
6327
  {
6244
6328
  name: "refresh_tick_ns",
6245
6329
  describeKind: "derived",
6246
- initial: (0, import_core43.monotonicNs)(),
6330
+ initial: (0, import_core44.monotonicNs)(),
6247
6331
  meta: memoryMeta("clock")
6248
6332
  }
6249
6333
  );
@@ -6254,7 +6338,7 @@ function collection(name, opts = {}) {
6254
6338
  const rankedDeps = [items.entries];
6255
6339
  if (refreshTick) rankedDeps.push(refreshTick);
6256
6340
  if (scoreNode) rankedDeps.push(scoreNode);
6257
- rankedNode = (0, import_core43.node)(
6341
+ rankedNode = (0, import_core44.node)(
6258
6342
  rankedDeps,
6259
6343
  (batchData, actions, ctx) => {
6260
6344
  const values = batchData.map(
@@ -6264,9 +6348,9 @@ function collection(name, opts = {}) {
6264
6348
  let now;
6265
6349
  if (refreshTick) {
6266
6350
  const tickValue = values[1];
6267
- now = typeof tickValue === "number" ? tickValue : (0, import_core43.monotonicNs)();
6351
+ now = typeof tickValue === "number" ? tickValue : (0, import_core44.monotonicNs)();
6268
6352
  } else {
6269
- now = (0, import_core43.monotonicNs)();
6353
+ now = (0, import_core44.monotonicNs)();
6270
6354
  }
6271
6355
  if (!snapshot || snapshot.size === 0) {
6272
6356
  actions.emit([]);
@@ -6291,7 +6375,7 @@ function collection(name, opts = {}) {
6291
6375
  );
6292
6376
  graph.add(rankedNode, { name: "ranked" });
6293
6377
  } else {
6294
- rankedNode = (0, import_core43.node)([], {
6378
+ rankedNode = (0, import_core44.node)([], {
6295
6379
  initial: [],
6296
6380
  name: "ranked",
6297
6381
  describeKind: "state",
@@ -6299,7 +6383,7 @@ function collection(name, opts = {}) {
6299
6383
  });
6300
6384
  graph.add(rankedNode, { name: "ranked" });
6301
6385
  }
6302
- const size = (0, import_core43.node)(
6386
+ const size = (0, import_core44.node)(
6303
6387
  [items.entries],
6304
6388
  (batchData, actions, ctx) => {
6305
6389
  const data = batchData.map(
@@ -6316,7 +6400,7 @@ function collection(name, opts = {}) {
6316
6400
  }
6317
6401
  );
6318
6402
  graph.add(size, { name: "size" });
6319
- graph.addDisposer((0, import_extra31.keepalive)(size));
6403
+ graph.addDisposer((0, import_extra32.keepalive)(size));
6320
6404
  const events = createAuditLog({
6321
6405
  name: "events",
6322
6406
  retainedLimit: 1024,
@@ -6324,7 +6408,7 @@ function collection(name, opts = {}) {
6324
6408
  });
6325
6409
  const seqCursor = registerCursor(graph, "seq", 0);
6326
6410
  const upsertImpl = (id, value, _opts) => {
6327
- const now = (0, import_core43.monotonicNs)();
6411
+ const now = (0, import_core44.monotonicNs)();
6328
6412
  const prev = items.get(id);
6329
6413
  const baseScore = _opts?.score ?? readScoreFn()(value);
6330
6414
  items.set(id, {
@@ -6380,7 +6464,7 @@ function collection(name, opts = {}) {
6380
6464
  });
6381
6465
  function itemNode(id) {
6382
6466
  const idN = toNode(id, "id");
6383
- return (0, import_core43.node)(
6467
+ return (0, import_core44.node)(
6384
6468
  [items.entries, idN],
6385
6469
  (batchData, actions, ctx) => {
6386
6470
  const data = batchData.map(
@@ -6398,7 +6482,7 @@ function collection(name, opts = {}) {
6398
6482
  }
6399
6483
  function hasNode(id) {
6400
6484
  const idN = toNode(id, "id");
6401
- return (0, import_core43.node)(
6485
+ return (0, import_core44.node)(
6402
6486
  [items.entries, idN],
6403
6487
  (batchData, actions, ctx) => {
6404
6488
  const data = batchData.map(
@@ -6473,7 +6557,7 @@ function vectorIndex(opts = {}) {
6473
6557
  graph
6474
6558
  });
6475
6559
  const seqCursor = registerCursor(graph, "seq", 0);
6476
- const entries = (0, import_extra31.reactiveMap)({
6560
+ const entries = (0, import_extra32.reactiveMap)({
6477
6561
  name: "entries",
6478
6562
  ...maxSize !== void 0 ? {
6479
6563
  retention: {
@@ -6485,7 +6569,7 @@ function vectorIndex(opts = {}) {
6485
6569
  events.append({
6486
6570
  action: "evict",
6487
6571
  id: key,
6488
- t_ns: (0, import_core43.wallClockNs)(),
6572
+ t_ns: (0, import_core44.wallClockNs)(),
6489
6573
  seq: bumpCursor(seqCursor)
6490
6574
  });
6491
6575
  }
@@ -6493,7 +6577,7 @@ function vectorIndex(opts = {}) {
6493
6577
  } : {}
6494
6578
  });
6495
6579
  graph.add(entries.entries, { name: "entries" });
6496
- graph.addDisposer((0, import_extra31.keepalive)(entries.entries));
6580
+ graph.addDisposer((0, import_extra32.keepalive)(entries.entries));
6497
6581
  if (hnsw?.dispose) {
6498
6582
  const disposeAdapter = hnsw.dispose.bind(hnsw);
6499
6583
  graph.addDisposer(() => disposeAdapter());
@@ -6510,7 +6594,7 @@ function vectorIndex(opts = {}) {
6510
6594
  id,
6511
6595
  vector: [...vector],
6512
6596
  ...copiedMeta !== void 0 ? { meta: copiedMeta } : {},
6513
- upsertedAtNs: (0, import_core43.monotonicNs)()
6597
+ upsertedAtNs: (0, import_core44.monotonicNs)()
6514
6598
  };
6515
6599
  entries.set(id, record);
6516
6600
  };
@@ -6566,7 +6650,7 @@ function vectorIndex(opts = {}) {
6566
6650
  });
6567
6651
  function searchNode(query, k = 5) {
6568
6652
  const kN = toNode(k, "k");
6569
- return (0, import_core43.node)(
6653
+ return (0, import_core44.node)(
6570
6654
  [entries.entries, query, kN],
6571
6655
  (batchData, actions, ctx) => {
6572
6656
  const values = batchData.map(
@@ -6672,17 +6756,17 @@ function knowledgeGraph(name, opts = {}) {
6672
6756
  throw new RangeError("knowledgeGraph: edgesMaxSize must be >= 1");
6673
6757
  }
6674
6758
  const graph = new import_graph6.Graph(name);
6675
- const entitiesMap = (0, import_extra31.reactiveMap)({
6759
+ const entitiesMap = (0, import_extra32.reactiveMap)({
6676
6760
  name: "entities",
6677
6761
  ...opts.entitiesMaxSize !== void 0 ? { maxSize: opts.entitiesMaxSize } : {}
6678
6762
  });
6679
- const edgesMap = (0, import_extra31.reactiveMap)({
6763
+ const edgesMap = (0, import_extra32.reactiveMap)({
6680
6764
  name: "edges",
6681
6765
  ...opts.edgesMaxSize !== void 0 ? { maxSize: opts.edgesMaxSize } : {}
6682
6766
  });
6683
6767
  graph.add(entitiesMap.entries, { name: "entities" });
6684
6768
  graph.add(edgesMap.entries, { name: "edges" });
6685
- const adjacencyOut = (0, import_core43.node)(
6769
+ const adjacencyOut = (0, import_core44.node)(
6686
6770
  [edgesMap.entries],
6687
6771
  (batchData, actions, ctx) => {
6688
6772
  const data = batchData.map(
@@ -6699,7 +6783,7 @@ function knowledgeGraph(name, opts = {}) {
6699
6783
  meta: memoryMeta("adjacency_out")
6700
6784
  }
6701
6785
  );
6702
- const adjacencyIn = (0, import_core43.node)(
6786
+ const adjacencyIn = (0, import_core44.node)(
6703
6787
  [edgesMap.entries],
6704
6788
  (batchData, actions, ctx) => {
6705
6789
  const data = batchData.map(
@@ -6718,9 +6802,9 @@ function knowledgeGraph(name, opts = {}) {
6718
6802
  );
6719
6803
  graph.add(adjacencyOut, { name: "adjacencyOut" });
6720
6804
  graph.add(adjacencyIn, { name: "adjacencyIn" });
6721
- graph.addDisposer((0, import_extra31.keepalive)(adjacencyOut));
6722
- graph.addDisposer((0, import_extra31.keepalive)(adjacencyIn));
6723
- const entityCount = (0, import_core43.node)(
6805
+ graph.addDisposer((0, import_extra32.keepalive)(adjacencyOut));
6806
+ graph.addDisposer((0, import_extra32.keepalive)(adjacencyIn));
6807
+ const entityCount = (0, import_core44.node)(
6724
6808
  [entitiesMap.entries],
6725
6809
  (batchData, actions, ctx) => {
6726
6810
  const data = batchData.map(
@@ -6731,7 +6815,7 @@ function knowledgeGraph(name, opts = {}) {
6731
6815
  },
6732
6816
  { name: "entityCount", describeKind: "derived", initial: 0, meta: memoryMeta("entity_count") }
6733
6817
  );
6734
- const edgeCount = (0, import_core43.node)(
6818
+ const edgeCount = (0, import_core44.node)(
6735
6819
  [edgesMap.entries],
6736
6820
  (batchData, actions, ctx) => {
6737
6821
  const data = batchData.map(
@@ -6744,8 +6828,8 @@ function knowledgeGraph(name, opts = {}) {
6744
6828
  );
6745
6829
  graph.add(entityCount, { name: "entityCount" });
6746
6830
  graph.add(edgeCount, { name: "edgeCount" });
6747
- graph.addDisposer((0, import_extra31.keepalive)(entityCount));
6748
- graph.addDisposer((0, import_extra31.keepalive)(edgeCount));
6831
+ graph.addDisposer((0, import_extra32.keepalive)(entityCount));
6832
+ graph.addDisposer((0, import_extra32.keepalive)(edgeCount));
6749
6833
  const events = createAuditLog({
6750
6834
  name: "events",
6751
6835
  retainedLimit: 1024,
@@ -6768,7 +6852,7 @@ function knowledgeGraph(name, opts = {}) {
6768
6852
  events.append({
6769
6853
  action: "orphanRemove",
6770
6854
  id: candidate,
6771
- t_ns: (0, import_core43.wallClockNs)(),
6855
+ t_ns: (0, import_core44.wallClockNs)(),
6772
6856
  seq: bumpCursor(seqCursor)
6773
6857
  });
6774
6858
  }
@@ -6863,7 +6947,7 @@ function knowledgeGraph(name, opts = {}) {
6863
6947
  const idN = toNode(id, "id");
6864
6948
  const relN = relation !== void 0 ? toNode(relation, "relation") : void 0;
6865
6949
  const deps = relN ? [adjacencyOut, adjacencyIn, idN, relN] : [adjacencyOut, adjacencyIn, idN];
6866
- return (0, import_core43.node)(
6950
+ return (0, import_core44.node)(
6867
6951
  deps,
6868
6952
  (batchData, actions, ctx) => {
6869
6953
  const values = batchData.map(
@@ -6939,7 +7023,7 @@ var MemoryWithVectorsGraph = class extends import_graph7.Graph {
6939
7023
  this.mount("vectorIndex", this.vectors);
6940
7024
  const embedFn = opts.embedFn;
6941
7025
  const vectorsRef = this.vectors;
6942
- const indexer = (0, import_core44.node)(
7026
+ const indexer = (0, import_core45.node)(
6943
7027
  [opts.store.store.entries],
6944
7028
  (batchData, _actions, ctx) => {
6945
7029
  const data = batchData.map(
@@ -6954,7 +7038,7 @@ var MemoryWithVectorsGraph = class extends import_graph7.Graph {
6954
7038
  { name: "indexer", describeKind: "effect" }
6955
7039
  );
6956
7040
  this.add(indexer, { name: "indexer" });
6957
- this.addDisposer((0, import_extra32.keepalive)(indexer));
7041
+ this.addDisposer((0, import_extra33.keepalive)(indexer));
6958
7042
  }
6959
7043
  };
6960
7044
  function memoryWithVectors(opts) {
@@ -6972,7 +7056,7 @@ var MemoryWithKGGraph = class extends import_graph7.Graph {
6972
7056
  if (!opts.entityFn) return;
6973
7057
  const entityFn = opts.entityFn;
6974
7058
  const kgRef = this.kg;
6975
- const indexer = (0, import_core44.node)(
7059
+ const indexer = (0, import_core45.node)(
6976
7060
  [opts.store.store.entries],
6977
7061
  (batchData, _actions, ctx) => {
6978
7062
  const data = batchData.map(
@@ -6993,7 +7077,7 @@ var MemoryWithKGGraph = class extends import_graph7.Graph {
6993
7077
  { name: "indexer", describeKind: "effect" }
6994
7078
  );
6995
7079
  this.add(indexer, { name: "indexer" });
6996
- this.addDisposer((0, import_extra32.keepalive)(indexer));
7080
+ this.addDisposer((0, import_extra33.keepalive)(indexer));
6997
7081
  }
6998
7082
  };
6999
7083
  function memoryWithKG(opts) {
@@ -7015,20 +7099,20 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7015
7099
  const permanentFilter = opts.permanentFilter ?? (() => false);
7016
7100
  this.permanent = collection("permanent", { ranked: false });
7017
7101
  this.mount("permanent", this.permanent);
7018
- this.permanentKeys = (0, import_extra32.reactiveMap)({ name: "permanentKeys" });
7102
+ this.permanentKeys = (0, import_extra33.reactiveMap)({ name: "permanentKeys" });
7019
7103
  this.add(this.permanentKeys.entries, { name: "permanentKeys" });
7020
- this.entryCreatedAtNs = (0, import_extra32.reactiveMap)({ name: "entryCreatedAtNs" });
7104
+ this.entryCreatedAtNs = (0, import_extra33.reactiveMap)({ name: "entryCreatedAtNs" });
7021
7105
  this.add(this.entryCreatedAtNs.entries, { name: "entryCreatedAtNs" });
7022
7106
  let contextNode;
7023
7107
  if (opts.context) {
7024
- contextNode = (0, import_extra32.fromAny)(opts.context);
7108
+ contextNode = (0, import_extra33.fromAny)(opts.context);
7025
7109
  } else {
7026
- contextNode = (0, import_core44.node)([], { initial: null });
7110
+ contextNode = (0, import_core45.node)([], { initial: null });
7027
7111
  this.add(contextNode, { name: "context" });
7028
7112
  }
7029
7113
  let latestCtx = contextNode.cache;
7030
7114
  const ctxUnsub = contextNode.subscribe((msgs) => {
7031
- for (const m of msgs) if (m[0] === import_core44.DATA) latestCtx = m[1];
7115
+ for (const m of msgs) if (m[0] === import_core45.DATA) latestCtx = m[1];
7032
7116
  });
7033
7117
  this.addDisposer(ctxUnsub);
7034
7118
  const permanentKeysRef = this.permanentKeys;
@@ -7038,7 +7122,7 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7038
7122
  score: (key, value) => {
7039
7123
  if (permanentFilter(key, value)) return Number.POSITIVE_INFINITY;
7040
7124
  if (permanentKeysRef.has(key)) return Number.POSITIVE_INFINITY;
7041
- const nowNs = (0, import_core44.monotonicNs)();
7125
+ const nowNs = (0, import_core45.monotonicNs)();
7042
7126
  const createdNs = entryCreatedAtNsRef.get(key) ?? nowNs;
7043
7127
  const ageSeconds2 = Number(nowNs - createdNs) / 1e9;
7044
7128
  return decay(score(value, latestCtx), ageSeconds2, decayRate);
@@ -7073,20 +7157,20 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7073
7157
  permanentKeysRef.set(key, true);
7074
7158
  permanentRef.upsert(key, value);
7075
7159
  };
7076
- const syncCreatedAt = (0, import_core44.node)(
7160
+ const syncCreatedAt = (0, import_core45.node)(
7077
7161
  [this.store.store.entries],
7078
7162
  (batchData, _actions, ctx) => {
7079
7163
  const data = batchData.map(
7080
7164
  (b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
7081
7165
  );
7082
7166
  const map = data[0] ?? /* @__PURE__ */ new Map();
7083
- const nowNs = (0, import_core44.monotonicNs)();
7167
+ const nowNs = (0, import_core45.monotonicNs)();
7084
7168
  const toAdd = [];
7085
7169
  for (const key of map.keys()) {
7086
7170
  if (!entryCreatedAtNsRef.has(key)) toAdd.push(key);
7087
7171
  }
7088
7172
  if (toAdd.length > 0) {
7089
- (0, import_core44.batch)(() => {
7173
+ (0, import_core45.batch)(() => {
7090
7174
  for (const key of toAdd) entryCreatedAtNsRef.set(key, nowNs);
7091
7175
  });
7092
7176
  }
@@ -7094,10 +7178,10 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7094
7178
  { name: "entryCreatedAtNs/sync", describeKind: "effect" }
7095
7179
  );
7096
7180
  this.add(syncCreatedAt, { name: "entryCreatedAtNs/sync" });
7097
- this.addDisposer((0, import_extra32.keepalive)(syncCreatedAt));
7181
+ this.addDisposer((0, import_extra33.keepalive)(syncCreatedAt));
7098
7182
  const entriesUnsub = this.store.store.entries.subscribe((msgs) => {
7099
7183
  for (const m of msgs) {
7100
- if (m[0] !== import_core44.DATA) continue;
7184
+ if (m[0] !== import_core45.DATA) continue;
7101
7185
  const map = m[1];
7102
7186
  const created = entryCreatedAtNsRef.entries.cache;
7103
7187
  if (created == null) continue;
@@ -7106,14 +7190,14 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7106
7190
  if (!map.has(key)) toDelete.push(key);
7107
7191
  }
7108
7192
  if (toDelete.length > 0) {
7109
- (0, import_core44.batch)(() => {
7193
+ (0, import_core45.batch)(() => {
7110
7194
  for (const key of toDelete) entryCreatedAtNsRef.delete(key);
7111
7195
  });
7112
7196
  }
7113
7197
  }
7114
7198
  });
7115
7199
  this.addDisposer(entriesUnsub);
7116
- const promoter = (0, import_core44.node)(
7200
+ const promoter = (0, import_core45.node)(
7117
7201
  [this.store.store.entries],
7118
7202
  (batchData, _actions, ctx) => {
7119
7203
  const data = batchData.map(
@@ -7123,7 +7207,7 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7123
7207
  for (const [key, mem] of map) {
7124
7208
  if (permanentKeysRef.has(key)) continue;
7125
7209
  if (permanentFilter(key, mem)) {
7126
- (0, import_core44.batch)(() => {
7210
+ (0, import_core45.batch)(() => {
7127
7211
  markPermanent(key, mem);
7128
7212
  });
7129
7213
  }
@@ -7132,7 +7216,7 @@ var MemoryWithTiersGraph = class extends import_graph7.Graph {
7132
7216
  { name: "promoter", describeKind: "effect" }
7133
7217
  );
7134
7218
  this.add(promoter, { name: "promoter" });
7135
- this.addDisposer((0, import_extra32.keepalive)(promoter));
7219
+ this.addDisposer((0, import_extra33.keepalive)(promoter));
7136
7220
  let archiveHandle = null;
7137
7221
  if (opts.archiveTier) {
7138
7222
  archiveHandle = this.attachSnapshotStorage(
@@ -7188,7 +7272,7 @@ var MemoryRetrievalGraph = class extends import_graph7.Graph {
7188
7272
  this._budget = opts.budget ?? 2e3;
7189
7273
  this._contextWeight = opts.contextWeight ?? 0;
7190
7274
  if (opts.context) {
7191
- this._contextNode = (0, import_extra32.fromAny)(opts.context);
7275
+ this._contextNode = (0, import_extra33.fromAny)(opts.context);
7192
7276
  } else {
7193
7277
  this._contextNode = this.state("_context", null);
7194
7278
  }
@@ -7334,7 +7418,7 @@ var MemoryRetrievalGraph = class extends import_graph7.Graph {
7334
7418
  const id = ++this._retrieveSeq;
7335
7419
  const segment = `retrieve_${id}`;
7336
7420
  const sub = new import_graph7.Graph(segment);
7337
- const inputNode = (0, import_extra32.fromAny)(queryInput);
7421
+ const inputNode = (0, import_extra33.fromAny)(queryInput);
7338
7422
  const localContext = sub.derived(
7339
7423
  "context",
7340
7424
  [inputNode],
@@ -7379,7 +7463,7 @@ var MemoryRetrievalGraph = class extends import_graph7.Graph {
7379
7463
  initial: { packed: [], trace: null }
7380
7464
  }
7381
7465
  );
7382
- const projection = (0, import_core44.node)(
7466
+ const projection = (0, import_core45.node)(
7383
7467
  [result],
7384
7468
  (batchData, actions, ctx) => {
7385
7469
  const data = batchData.map(
@@ -7419,18 +7503,18 @@ function gaugesAsContext(graph, actor, options) {
7419
7503
  const separator = options?.separator ?? "\n";
7420
7504
  const entries = [];
7421
7505
  const sinceVersion = options?.sinceVersion;
7422
- for (const [path, node38] of Object.entries(described.nodes)) {
7423
- const meta2 = node38.meta ?? {};
7506
+ for (const [path, node39] of Object.entries(described.nodes)) {
7507
+ const meta2 = node39.meta ?? {};
7424
7508
  const desc = meta2.description;
7425
7509
  const format = meta2.format;
7426
7510
  if (!desc && !format) continue;
7427
- if (sinceVersion != null && node38.v != null) {
7511
+ if (sinceVersion != null && node39.v != null) {
7428
7512
  const lastSeen = sinceVersion.get(path);
7429
- if (lastSeen != null && lastSeen.id === node38.v.id && node38.v.version <= lastSeen.version)
7513
+ if (lastSeen != null && lastSeen.id === node39.v.id && node39.v.version <= lastSeen.version)
7430
7514
  continue;
7431
7515
  }
7432
7516
  const label = desc ?? path;
7433
- const value = node38.value;
7517
+ const value = node39.value;
7434
7518
  const unit = meta2.unit;
7435
7519
  let formatted;
7436
7520
  if (format === "currency" && typeof value === "number") {
@@ -7452,8 +7536,8 @@ function gaugesAsContext(graph, actor, options) {
7452
7536
  const tagGroups = /* @__PURE__ */ new Map();
7453
7537
  const ungrouped = [];
7454
7538
  for (const entry of entries) {
7455
- const node38 = described.nodes[entry.path];
7456
- const tags = node38.meta?.tags;
7539
+ const node39 = described.nodes[entry.path];
7540
+ const tags = node39.meta?.tags;
7457
7541
  if (tags && tags.length > 0) {
7458
7542
  const tag = tags[0];
7459
7543
  let group = tagGroups.get(tag);
@@ -7484,25 +7568,25 @@ function gaugesAsContext(graph, actor, options) {
7484
7568
  }
7485
7569
 
7486
7570
  // src/utils/ai/graph-integration/graph-from-spec.ts
7487
- var import_core47 = require("@graphrefly/pure-ts/core");
7488
- var import_extra35 = require("@graphrefly/pure-ts/extra");
7571
+ var import_core48 = require("@graphrefly/pure-ts/core");
7572
+ var import_extra36 = require("@graphrefly/pure-ts/extra");
7489
7573
 
7490
7574
  // src/utils/graphspec/index.ts
7491
- var import_core46 = require("@graphrefly/pure-ts/core");
7575
+ var import_core47 = require("@graphrefly/pure-ts/core");
7492
7576
  var import_graph9 = require("@graphrefly/pure-ts/graph");
7493
7577
 
7494
7578
  // src/utils/reduction/index.ts
7495
- var import_core45 = require("@graphrefly/pure-ts/core");
7496
- var import_extra33 = require("@graphrefly/pure-ts/extra");
7497
- var import_graph8 = require("@graphrefly/pure-ts/graph");
7579
+ var import_core46 = require("@graphrefly/pure-ts/core");
7498
7580
  var import_extra34 = require("@graphrefly/pure-ts/extra");
7581
+ var import_graph8 = require("@graphrefly/pure-ts/graph");
7582
+ var import_extra35 = require("@graphrefly/pure-ts/extra");
7499
7583
  function baseMeta(kind, meta2) {
7500
7584
  return domainMeta("reduction", kind, meta2);
7501
7585
  }
7502
7586
  function feedback(graph, condition, reentry, opts) {
7503
7587
  const maxIter = opts?.maxIterations ?? 10;
7504
7588
  const counterName = `__feedback_${condition}`;
7505
- const counter = (0, import_core45.node)([], {
7589
+ const counter = (0, import_core46.node)([], {
7506
7590
  ...{
7507
7591
  meta: baseMeta("feedback_counter", {
7508
7592
  maxIterations: maxIter,
@@ -7516,22 +7600,22 @@ function feedback(graph, condition, reentry, opts) {
7516
7600
  const condNode = graph.resolve(condition);
7517
7601
  const reentryNode = graph.resolve(reentry);
7518
7602
  const feedbackEffectName = `__feedback_effect_${condition}`;
7519
- const feedbackEffect = (0, import_core45.node)(
7603
+ const feedbackEffect = (0, import_core46.node)(
7520
7604
  [],
7521
7605
  (_data, _feedbackActions) => {
7522
7606
  const unsub = condNode.subscribe((msgs) => {
7523
7607
  for (const msg of msgs) {
7524
7608
  const t = msg[0];
7525
- if (t === import_core45.DATA) {
7609
+ if (t === import_core46.DATA) {
7526
7610
  const condValue = msg[1];
7527
7611
  if (condValue == null) return;
7528
- (0, import_core45.batch)(() => {
7612
+ (0, import_core46.batch)(() => {
7529
7613
  if (tryIncrementBounded(counter, maxIter)) {
7530
7614
  reentryNode.emit(condValue);
7531
7615
  }
7532
7616
  });
7533
- } else if (t === import_core45.COMPLETE || t === import_core45.ERROR) {
7534
- const terminal = t === import_core45.ERROR && msg.length > 1 ? [import_core45.ERROR, msg[1]] : [t];
7617
+ } else if (t === import_core46.COMPLETE || t === import_core46.ERROR) {
7618
+ const terminal = t === import_core46.ERROR && msg.length > 1 ? [import_core46.ERROR, msg[1]] : [t];
7535
7619
  counter.down([terminal]);
7536
7620
  }
7537
7621
  }
@@ -7551,23 +7635,23 @@ function feedback(graph, condition, reentry, opts) {
7551
7635
  }
7552
7636
  );
7553
7637
  graph.add(feedbackEffect, { name: feedbackEffectName });
7554
- graph.addDisposer((0, import_extra34.keepalive)(feedbackEffect));
7638
+ graph.addDisposer((0, import_extra35.keepalive)(feedbackEffect));
7555
7639
  return graph;
7556
7640
  }
7557
7641
 
7558
7642
  // src/utils/graphspec/index.ts
7559
- function readFactory(node38) {
7560
- const f = node38.meta?.factory;
7643
+ function readFactory(node39) {
7644
+ const f = node39.meta?.factory;
7561
7645
  return typeof f === "string" ? f : void 0;
7562
7646
  }
7563
- function readFactoryArgs(node38) {
7564
- const a = node38.meta?.factoryArgs;
7647
+ function readFactoryArgs(node39) {
7648
+ const a = node39.meta?.factoryArgs;
7565
7649
  return a != null && typeof a === "object" ? a : {};
7566
7650
  }
7567
- function readStateInitial(node38) {
7568
- const args = readFactoryArgs(node38);
7651
+ function readStateInitial(node39) {
7652
+ const args = readFactoryArgs(node39);
7569
7653
  if ("initial" in args) return args.initial;
7570
- return node38.value;
7654
+ return node39.value;
7571
7655
  }
7572
7656
  function isRichFnEntry(entry) {
7573
7657
  return typeof entry === "object" && entry !== null && "factory" in entry;
@@ -7587,11 +7671,11 @@ function validateSpecAgainstCatalog(spec, catalog) {
7587
7671
  const sourceNames = new Set(Object.keys(catalog.sources ?? {}));
7588
7672
  for (const [nodeName, nodeRaw] of Object.entries(spec.nodes)) {
7589
7673
  if (nodeRaw.type === "template") continue;
7590
- const node38 = nodeRaw;
7591
- const factoryName = readFactory(node38);
7674
+ const node39 = nodeRaw;
7675
+ const factoryName = readFactory(node39);
7592
7676
  if (factoryName == null) continue;
7593
- const isProducer = node38.type === "producer";
7594
- if (node38.type === "state" && factoryName === "state") continue;
7677
+ const isProducer = node39.type === "producer";
7678
+ if (node39.type === "state" && factoryName === "state") continue;
7595
7679
  if (isProducer) {
7596
7680
  const inSources = sourceNames.has(factoryName);
7597
7681
  const inFns = fnNames.has(factoryName);
@@ -7615,7 +7699,7 @@ function validateSpecAgainstCatalog(spec, catalog) {
7615
7699
  }
7616
7700
  }
7617
7701
  }
7618
- const factoryArgs = readFactoryArgs(node38);
7702
+ const factoryArgs = readFactoryArgs(node39);
7619
7703
  if (!isProducer && catalog.fns?.[factoryName]) {
7620
7704
  const entry = catalog.fns[factoryName];
7621
7705
  if (isRichFnEntry(entry) && entry.configSchema) {
@@ -7655,11 +7739,11 @@ function validateSpecAgainstCatalog(spec, catalog) {
7655
7739
  }
7656
7740
  if (spec.templates) {
7657
7741
  for (const [tName, template] of Object.entries(spec.templates)) {
7658
- for (const [nodeName, node38] of Object.entries(template.nodes)) {
7659
- const factoryName = readFactory(node38);
7742
+ for (const [nodeName, node39] of Object.entries(template.nodes)) {
7743
+ const factoryName = readFactory(node39);
7660
7744
  if (factoryName == null) continue;
7661
- if (node38.type === "state" && factoryName === "state") continue;
7662
- if (node38.type === "producer") continue;
7745
+ if (node39.type === "state" && factoryName === "state") continue;
7746
+ if (node39.type === "producer") continue;
7663
7747
  if (fnNames.size > 0 && !fnNames.has(factoryName)) {
7664
7748
  const suggestion = findClosest(factoryName, fnNames);
7665
7749
  errors.push(
@@ -7927,7 +8011,7 @@ ${catalogValidation.errors.join("\n")}`
7927
8011
  const factoryArgs = readFactoryArgs(n);
7928
8012
  if (n.type === "state") {
7929
8013
  const initial = readStateInitial(n);
7930
- const nd = (0, import_core46.node)([], {
8014
+ const nd = (0, import_core47.node)([], {
7931
8015
  name,
7932
8016
  initial,
7933
8017
  meta: stripFactoryMeta(n.meta)
@@ -7947,7 +8031,7 @@ ${catalogValidation.errors.join("\n")}`
7947
8031
  created.set(name, nd);
7948
8032
  } else {
7949
8033
  if (factoryName) recordMissing(name, "source", factoryName);
7950
- const nd = (0, import_core46.node)([], () => {
8034
+ const nd = (0, import_core47.node)([], () => {
7951
8035
  }, {
7952
8036
  name,
7953
8037
  describeKind: "producer",
@@ -7976,11 +8060,11 @@ ${catalogValidation.errors.join("\n")}`
7976
8060
  nd = fnFactory(resolvedDeps, factoryArgs);
7977
8061
  } else if (n.type === "effect") {
7978
8062
  if (factoryName) recordMissing(name, "fn", factoryName);
7979
- nd = (0, import_core46.node)(resolvedDeps, () => {
8063
+ nd = (0, import_core47.node)(resolvedDeps, () => {
7980
8064
  }, { describeKind: "effect" });
7981
8065
  } else {
7982
8066
  if (factoryName) recordMissing(name, "fn", factoryName);
7983
- nd = (0, import_core46.node)(
8067
+ nd = (0, import_core47.node)(
7984
8068
  resolvedDeps,
7985
8069
  (batchData, actions, ctx) => {
7986
8070
  const data = batchData.map(
@@ -8020,7 +8104,7 @@ ${catalogValidation.errors.join("\n")}`
8020
8104
  const factoryArgs = readFactoryArgs(nSpec);
8021
8105
  if (nSpec.type === "state") {
8022
8106
  const initial = readStateInitial(nSpec);
8023
- const nd = (0, import_core46.node)([], {
8107
+ const nd = (0, import_core47.node)([], {
8024
8108
  name: nName,
8025
8109
  initial,
8026
8110
  meta: stripFactoryMeta(nSpec.meta)
@@ -8040,7 +8124,7 @@ ${catalogValidation.errors.join("\n")}`
8040
8124
  subCreated.set(nName, nd);
8041
8125
  } else {
8042
8126
  if (factoryName) recordMissing(`${name}.${nName}`, "source", factoryName);
8043
- const nd = (0, import_core46.node)([], () => {
8127
+ const nd = (0, import_core47.node)([], () => {
8044
8128
  }, {
8045
8129
  name: nName,
8046
8130
  describeKind: "producer",
@@ -8070,11 +8154,11 @@ ${catalogValidation.errors.join("\n")}`
8070
8154
  nd = fnFactory(resolvedDeps, factoryArgs);
8071
8155
  } else if (nSpec.type === "effect") {
8072
8156
  if (factoryName) recordMissing(`${name}.${nName}`, "fn", factoryName);
8073
- nd = (0, import_core46.node)(resolvedDeps, () => {
8157
+ nd = (0, import_core47.node)(resolvedDeps, () => {
8074
8158
  }, { describeKind: "effect" });
8075
8159
  } else {
8076
8160
  if (factoryName) recordMissing(`${name}.${nName}`, "fn", factoryName);
8077
- nd = (0, import_core46.node)(
8161
+ nd = (0, import_core47.node)(
8078
8162
  resolvedDeps,
8079
8163
  (batchData, actions, ctx) => {
8080
8164
  const data = batchData.map(
@@ -8195,12 +8279,12 @@ ${opts.systemPromptExtra}` : GRAPH_FROM_SPEC_SYSTEM_PROMPT;
8195
8279
  return compileSpec(parsed, { catalog: opts?.catalog });
8196
8280
  }
8197
8281
  function graphFromSpecReactive(input, adapter, opts) {
8198
- const inputNode = (0, import_extra35.fromAny)(input);
8199
- return (0, import_extra35.switchMap)(inputNode, (nl) => {
8282
+ const inputNode = (0, import_extra36.fromAny)(input);
8283
+ return (0, import_extra36.switchMap)(inputNode, (nl) => {
8200
8284
  if (!nl || typeof nl !== "string" || nl.trim().length === 0) {
8201
- return (0, import_core47.node)([], { initial: null });
8285
+ return (0, import_core48.node)([], { initial: null });
8202
8286
  }
8203
- return (0, import_core47.node)(
8287
+ return (0, import_core48.node)(
8204
8288
  (_data, actions) => {
8205
8289
  const controller = new AbortController();
8206
8290
  let cancelled = false;
@@ -8210,10 +8294,10 @@ function graphFromSpecReactive(input, adapter, opts) {
8210
8294
  return;
8211
8295
  }
8212
8296
  actions.emit(g);
8213
- actions.down([[import_core47.COMPLETE]]);
8297
+ actions.down([[import_core48.COMPLETE]]);
8214
8298
  }).catch((err) => {
8215
8299
  if (cancelled) return;
8216
- actions.down([[import_core47.ERROR, err]]);
8300
+ actions.down([[import_core48.ERROR, err]]);
8217
8301
  });
8218
8302
  return {
8219
8303
  onDeactivation: () => {
@@ -8266,11 +8350,11 @@ function knobsAsTools(graph, actor) {
8266
8350
  const openai = [];
8267
8351
  const mcp = [];
8268
8352
  const definitions = [];
8269
- for (const [path, node38] of Object.entries(described.nodes)) {
8270
- if (node38.type !== "state") continue;
8353
+ for (const [path, node39] of Object.entries(described.nodes)) {
8354
+ if (node39.type !== "state") continue;
8271
8355
  if (path.includes("::__meta__::")) continue;
8272
- if (node38.status === "completed" || node38.status === "errored") continue;
8273
- const meta2 = node38.meta ?? {};
8356
+ if (node39.status === "completed" || node39.status === "errored") continue;
8357
+ const meta2 = node39.meta ?? {};
8274
8358
  const access = meta2.access;
8275
8359
  if (access === "human" || access === "system") continue;
8276
8360
  const description = meta2.description ?? `Set the value of ${path}`;
@@ -8299,7 +8383,7 @@ function knobsAsTools(graph, actor) {
8299
8383
  });
8300
8384
  const graphRef = graph;
8301
8385
  const actorRef = actor;
8302
- const nv = node38.v;
8386
+ const nv = node39.v;
8303
8387
  definitions.push({
8304
8388
  name: path,
8305
8389
  description,
@@ -8315,8 +8399,8 @@ function knobsAsTools(graph, actor) {
8315
8399
  }
8316
8400
 
8317
8401
  // src/utils/ai/graph-integration/suggest-strategy.ts
8318
- var import_core48 = require("@graphrefly/pure-ts/core");
8319
- var import_extra36 = require("@graphrefly/pure-ts/extra");
8402
+ var import_core49 = require("@graphrefly/pure-ts/core");
8403
+ var import_extra37 = require("@graphrefly/pure-ts/extra");
8320
8404
  var SUGGEST_STRATEGY_SYSTEM_PROMPT = `You are a reactive graph optimizer for GraphReFly.
8321
8405
 
8322
8406
  Given a graph's current structure (from describe()) and a problem statement, suggest topology and parameter changes to solve the problem.
@@ -8385,26 +8469,26 @@ async function suggestStrategy(graph, problem, adapter, opts) {
8385
8469
  };
8386
8470
  }
8387
8471
  function suggestStrategyReactive(graph, problem, adapter, opts) {
8388
- const problemNode = (0, import_extra36.fromAny)(problem);
8389
- const paired = (0, import_extra36.withLatestFrom)(problemNode, graph);
8390
- return (0, import_extra36.switchMap)(paired, (pair) => {
8391
- if (pair == null) return (0, import_core48.node)([], { initial: null });
8472
+ const problemNode = (0, import_extra37.fromAny)(problem);
8473
+ const paired = (0, import_extra37.withLatestFrom)(problemNode, graph);
8474
+ return (0, import_extra37.switchMap)(paired, (pair) => {
8475
+ if (pair == null) return (0, import_core49.node)([], { initial: null });
8392
8476
  const [pText, g] = pair;
8393
8477
  if (!g || !pText || typeof pText !== "string" || pText.trim().length === 0) {
8394
- return (0, import_core48.node)([], { initial: null });
8478
+ return (0, import_core49.node)([], { initial: null });
8395
8479
  }
8396
- if (g.destroyed) return (0, import_core48.node)([], { initial: null });
8397
- return (0, import_core48.node)(
8480
+ if (g.destroyed) return (0, import_core49.node)([], { initial: null });
8481
+ return (0, import_core49.node)(
8398
8482
  (_data, actions) => {
8399
8483
  const controller = new AbortController();
8400
8484
  let cancelled = false;
8401
8485
  suggestStrategy(g, pText, adapter, { ...opts, signal: controller.signal }).then((plan) => {
8402
8486
  if (cancelled) return;
8403
8487
  actions.emit(plan);
8404
- actions.down([[import_core48.COMPLETE]]);
8488
+ actions.down([[import_core49.COMPLETE]]);
8405
8489
  }).catch((err) => {
8406
8490
  if (cancelled) return;
8407
- actions.down([[import_core48.ERROR, err]]);
8491
+ actions.down([[import_core49.ERROR, err]]);
8408
8492
  });
8409
8493
  return {
8410
8494
  onDeactivation: () => {
@@ -8439,14 +8523,14 @@ function validateGraphDef(def) {
8439
8523
  errors.push(`Node "${name}": must be an object`);
8440
8524
  continue;
8441
8525
  }
8442
- const node38 = raw;
8443
- if (typeof node38.type !== "string" || !VALID_NODE_TYPES2.has(node38.type)) {
8526
+ const node39 = raw;
8527
+ if (typeof node39.type !== "string" || !VALID_NODE_TYPES2.has(node39.type)) {
8444
8528
  errors.push(
8445
- `Node "${name}": invalid type "${String(node38.type)}" (expected: ${[...VALID_NODE_TYPES2].join(", ")})`
8529
+ `Node "${name}": invalid type "${String(node39.type)}" (expected: ${[...VALID_NODE_TYPES2].join(", ")})`
8446
8530
  );
8447
8531
  }
8448
- if (Array.isArray(node38.deps)) {
8449
- for (const dep of node38.deps) {
8532
+ if (Array.isArray(node39.deps)) {
8533
+ for (const dep of node39.deps) {
8450
8534
  if (typeof dep === "string" && !nodeNames.has(dep)) {
8451
8535
  errors.push(`Node "${name}": dep "${dep}" does not reference an existing node`);
8452
8536
  }