@graphrefly/graphrefly 0.45.0 → 0.47.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 (714) hide show
  1. package/README.md +1 -2
  2. package/dist/_internal-B23BagFd.d.cts +33 -0
  3. package/dist/_internal-B23BagFd.d.ts +33 -0
  4. package/dist/adaptive-rate-limiter-Dch_xYIi.d.cts +111 -0
  5. package/dist/adaptive-rate-limiter-Dch_xYIi.d.ts +111 -0
  6. package/dist/agents-C0Ji9ldU.d.cts +629 -0
  7. package/dist/agents-C9zexT7I.d.ts +629 -0
  8. package/dist/audit-BAXb3VOg.d.ts +246 -0
  9. package/dist/audit-C_bPfkqS.d.cts +246 -0
  10. package/dist/backoff-7KIK3WQW.js +24 -0
  11. package/dist/backoff-7KIK3WQW.js.map +1 -0
  12. package/dist/backoff-Bnb9OoPh.d.cts +6 -0
  13. package/dist/backoff-Bnb9OoPh.d.ts +6 -0
  14. package/dist/base/composition/index.cjs +865 -0
  15. package/dist/base/composition/index.cjs.map +1 -0
  16. package/dist/base/composition/index.d.cts +468 -0
  17. package/dist/base/composition/index.d.ts +468 -0
  18. package/dist/base/composition/index.js +40 -0
  19. package/dist/base/composition/index.js.map +1 -0
  20. package/dist/base/index.cjs +6390 -0
  21. package/dist/base/index.cjs.map +1 -0
  22. package/dist/base/index.d.cts +21 -0
  23. package/dist/base/index.d.ts +21 -0
  24. package/dist/base/index.js +259 -0
  25. package/dist/base/index.js.map +1 -0
  26. package/dist/base/io/index.cjs +3270 -0
  27. package/dist/base/io/index.cjs.map +1 -0
  28. package/dist/base/io/index.d.cts +2245 -0
  29. package/dist/base/io/index.d.ts +2245 -0
  30. package/dist/base/io/index.js +117 -0
  31. package/dist/base/io/index.js.map +1 -0
  32. package/dist/base/meta/index.cjs +43 -0
  33. package/dist/base/meta/index.cjs.map +1 -0
  34. package/dist/base/meta/index.d.cts +45 -0
  35. package/dist/base/meta/index.d.ts +45 -0
  36. package/dist/base/meta/index.js +13 -0
  37. package/dist/base/meta/index.js.map +1 -0
  38. package/dist/base/mutation/index.cjs +200 -0
  39. package/dist/base/mutation/index.cjs.map +1 -0
  40. package/dist/base/mutation/index.d.cts +177 -0
  41. package/dist/base/mutation/index.d.ts +177 -0
  42. package/dist/base/mutation/index.js +22 -0
  43. package/dist/base/mutation/index.js.map +1 -0
  44. package/dist/base/render/index.cjs +1120 -0
  45. package/dist/base/render/index.cjs.map +1 -0
  46. package/dist/base/render/index.d.cts +227 -0
  47. package/dist/base/render/index.d.ts +227 -0
  48. package/dist/base/render/index.js +24 -0
  49. package/dist/base/render/index.js.map +1 -0
  50. package/dist/base/sources/browser/index.cjs +172 -0
  51. package/dist/base/sources/browser/index.cjs.map +1 -0
  52. package/dist/base/sources/browser/index.d.cts +84 -0
  53. package/dist/base/sources/browser/index.d.ts +84 -0
  54. package/dist/base/sources/browser/index.js +151 -0
  55. package/dist/base/sources/browser/index.js.map +1 -0
  56. package/dist/base/sources/event/index.cjs +98 -0
  57. package/dist/base/sources/event/index.cjs.map +1 -0
  58. package/dist/base/sources/event/index.d.cts +91 -0
  59. package/dist/base/sources/event/index.d.ts +91 -0
  60. package/dist/base/sources/event/index.js +13 -0
  61. package/dist/base/sources/event/index.js.map +1 -0
  62. package/dist/base/sources/index.cjs +755 -0
  63. package/dist/base/sources/index.cjs.map +1 -0
  64. package/dist/base/sources/index.d.cts +357 -0
  65. package/dist/base/sources/index.d.ts +357 -0
  66. package/dist/base/sources/index.js +42 -0
  67. package/dist/base/sources/index.js.map +1 -0
  68. package/dist/base/sources/node/index.cjs +320 -0
  69. package/dist/base/sources/node/index.cjs.map +1 -0
  70. package/dist/base/sources/node/index.d.cts +185 -0
  71. package/dist/base/sources/node/index.d.ts +185 -0
  72. package/dist/base/sources/node/index.js +306 -0
  73. package/dist/base/sources/node/index.js.map +1 -0
  74. package/dist/base/utils/index.cjs +37 -0
  75. package/dist/base/utils/index.cjs.map +1 -0
  76. package/dist/base/utils/index.d.cts +37 -0
  77. package/dist/base/utils/index.d.ts +37 -0
  78. package/dist/base/utils/index.js +11 -0
  79. package/dist/base/utils/index.js.map +1 -0
  80. package/dist/base/worker/index.cjs +548 -0
  81. package/dist/base/worker/index.cjs.map +1 -0
  82. package/dist/base/worker/index.d.cts +207 -0
  83. package/dist/base/worker/index.d.ts +207 -0
  84. package/dist/base/worker/index.js +20 -0
  85. package/dist/base/worker/index.js.map +1 -0
  86. package/dist/breaker-C9skL3d8.d.ts +175 -0
  87. package/dist/breaker-ugSdq54q.d.cts +175 -0
  88. package/dist/cascading-CSSbKGrJ.d.ts +199 -0
  89. package/dist/cascading-baGkiihI.d.cts +199 -0
  90. package/dist/chunk-22SG74BD.js +207 -0
  91. package/dist/chunk-22SG74BD.js.map +1 -0
  92. package/dist/chunk-255UCBG4.js +58 -0
  93. package/dist/chunk-255UCBG4.js.map +1 -0
  94. package/dist/chunk-2LO3EL4W.js +1 -0
  95. package/dist/chunk-2LO3EL4W.js.map +1 -0
  96. package/dist/chunk-2OB3CEJS.js +1065 -0
  97. package/dist/chunk-2OB3CEJS.js.map +1 -0
  98. package/dist/chunk-36NMM65U.js +144 -0
  99. package/dist/chunk-36NMM65U.js.map +1 -0
  100. package/dist/chunk-3CEXCBN6.js +1 -0
  101. package/dist/chunk-3CEXCBN6.js.map +1 -0
  102. package/dist/chunk-3MUSLI6E.js +105 -0
  103. package/dist/chunk-3MUSLI6E.js.map +1 -0
  104. package/dist/chunk-3PSLNJDU.js +884 -0
  105. package/dist/chunk-3PSLNJDU.js.map +1 -0
  106. package/dist/chunk-42FQ27MQ.js +594 -0
  107. package/dist/chunk-42FQ27MQ.js.map +1 -0
  108. package/dist/chunk-4GYMCUDZ.js +1085 -0
  109. package/dist/chunk-4GYMCUDZ.js.map +1 -0
  110. package/dist/chunk-4S53H2KR.js +382 -0
  111. package/dist/chunk-4S53H2KR.js.map +1 -0
  112. package/dist/chunk-4XCHZRUJ.js +128 -0
  113. package/dist/chunk-4XCHZRUJ.js.map +1 -0
  114. package/dist/chunk-5IMMNARC.js +1153 -0
  115. package/dist/chunk-5IMMNARC.js.map +1 -0
  116. package/dist/chunk-6XZYT4SW.js +256 -0
  117. package/dist/chunk-6XZYT4SW.js.map +1 -0
  118. package/dist/chunk-7EGRP2VX.js +76 -0
  119. package/dist/chunk-7EGRP2VX.js.map +1 -0
  120. package/dist/chunk-A7KV5UK4.js +150 -0
  121. package/dist/chunk-A7KV5UK4.js.map +1 -0
  122. package/dist/chunk-APY2SS5X.js +156 -0
  123. package/dist/chunk-APY2SS5X.js.map +1 -0
  124. package/dist/chunk-AZDQPQ3V.js +66 -0
  125. package/dist/chunk-AZDQPQ3V.js.map +1 -0
  126. package/dist/chunk-BU3SEFA5.js +90 -0
  127. package/dist/chunk-BU3SEFA5.js.map +1 -0
  128. package/dist/chunk-BXGZFGZ4.js +189 -0
  129. package/dist/chunk-BXGZFGZ4.js.map +1 -0
  130. package/dist/chunk-CGHORL6G.js +579 -0
  131. package/dist/chunk-CGHORL6G.js.map +1 -0
  132. package/dist/chunk-CXANAIZU.js +530 -0
  133. package/dist/chunk-CXANAIZU.js.map +1 -0
  134. package/dist/chunk-CZQHCKKG.js +1 -0
  135. package/dist/chunk-CZQHCKKG.js.map +1 -0
  136. package/dist/chunk-DKNHAICT.js +133 -0
  137. package/dist/chunk-DKNHAICT.js.map +1 -0
  138. package/dist/chunk-DM4OMPWK.js +584 -0
  139. package/dist/chunk-DM4OMPWK.js.map +1 -0
  140. package/dist/chunk-DMSNO6ZB.js +452 -0
  141. package/dist/chunk-DMSNO6ZB.js.map +1 -0
  142. package/dist/chunk-E5OZPDIW.js +229 -0
  143. package/dist/chunk-E5OZPDIW.js.map +1 -0
  144. package/dist/chunk-EHRRQ4IC.js +211 -0
  145. package/dist/chunk-EHRRQ4IC.js.map +1 -0
  146. package/dist/chunk-EVYY4X5A.js +509 -0
  147. package/dist/chunk-EVYY4X5A.js.map +1 -0
  148. package/dist/chunk-FDFD67UO.js +1 -0
  149. package/dist/chunk-FDFD67UO.js.map +1 -0
  150. package/dist/chunk-FMPF42Q4.js +13 -0
  151. package/dist/chunk-FMPF42Q4.js.map +1 -0
  152. package/dist/chunk-FW23JYNQ.js +454 -0
  153. package/dist/chunk-FW23JYNQ.js.map +1 -0
  154. package/dist/chunk-GWRNLJNW.js +2508 -0
  155. package/dist/chunk-GWRNLJNW.js.map +1 -0
  156. package/dist/chunk-HL7HUJIX.js +1 -0
  157. package/dist/chunk-HL7HUJIX.js.map +1 -0
  158. package/dist/chunk-IHTWQEDR.js +169 -0
  159. package/dist/chunk-IHTWQEDR.js.map +1 -0
  160. package/dist/chunk-IJRR6YAI.js +128 -0
  161. package/dist/chunk-IJRR6YAI.js.map +1 -0
  162. package/dist/chunk-JGFRAFDL.js +221 -0
  163. package/dist/chunk-JGFRAFDL.js.map +1 -0
  164. package/dist/chunk-JKTC747G.js +725 -0
  165. package/dist/chunk-JKTC747G.js.map +1 -0
  166. package/dist/chunk-KN3H5CNT.js +11 -0
  167. package/dist/chunk-KN3H5CNT.js.map +1 -0
  168. package/dist/chunk-KPG3DGLA.js +1 -0
  169. package/dist/chunk-KPG3DGLA.js.map +1 -0
  170. package/dist/chunk-KRNQ6RGQ.js +1 -0
  171. package/dist/chunk-KRNQ6RGQ.js.map +1 -0
  172. package/dist/chunk-MLTPJMH6.js +417 -0
  173. package/dist/chunk-MLTPJMH6.js.map +1 -0
  174. package/dist/chunk-N3SZ7BMH.js +95 -0
  175. package/dist/chunk-N3SZ7BMH.js.map +1 -0
  176. package/dist/chunk-NDUD3IMO.js +540 -0
  177. package/dist/chunk-NDUD3IMO.js.map +1 -0
  178. package/dist/chunk-NY2PYHNC.js +873 -0
  179. package/dist/chunk-NY2PYHNC.js.map +1 -0
  180. package/dist/chunk-O3MT7DYI.js +225 -0
  181. package/dist/chunk-O3MT7DYI.js.map +1 -0
  182. package/dist/chunk-OCUDSN63.js +2386 -0
  183. package/dist/chunk-OCUDSN63.js.map +1 -0
  184. package/dist/chunk-OIWU3NYV.js +199 -0
  185. package/dist/chunk-OIWU3NYV.js.map +1 -0
  186. package/dist/chunk-OQUIJT7A.js +1 -0
  187. package/dist/chunk-OQUIJT7A.js.map +1 -0
  188. package/dist/chunk-P5LBT622.js +105 -0
  189. package/dist/chunk-P5LBT622.js.map +1 -0
  190. package/dist/chunk-PKGQG5QQ.js +519 -0
  191. package/dist/chunk-PKGQG5QQ.js.map +1 -0
  192. package/dist/chunk-PKPO3JTZ.js +561 -0
  193. package/dist/chunk-PKPO3JTZ.js.map +1 -0
  194. package/dist/chunk-PL5UDIQ5.js +118 -0
  195. package/dist/chunk-PL5UDIQ5.js.map +1 -0
  196. package/dist/chunk-PZWISPIQ.js +432 -0
  197. package/dist/chunk-PZWISPIQ.js.map +1 -0
  198. package/dist/chunk-Q3EYOCZB.js +510 -0
  199. package/dist/chunk-Q3EYOCZB.js.map +1 -0
  200. package/dist/chunk-QMBYUVRL.js +15 -0
  201. package/dist/chunk-QMBYUVRL.js.map +1 -0
  202. package/dist/chunk-RAGGHLCV.js +200 -0
  203. package/dist/chunk-RAGGHLCV.js.map +1 -0
  204. package/dist/chunk-RJOG4IJU.js +1039 -0
  205. package/dist/chunk-RJOG4IJU.js.map +1 -0
  206. package/dist/chunk-SOOKUYVM.js +403 -0
  207. package/dist/chunk-SOOKUYVM.js.map +1 -0
  208. package/dist/chunk-T5BN5KG7.js +1 -0
  209. package/dist/chunk-T5BN5KG7.js.map +1 -0
  210. package/dist/chunk-TNX5ZGDJ.js +574 -0
  211. package/dist/chunk-TNX5ZGDJ.js.map +1 -0
  212. package/dist/chunk-TP7244Y6.js +207 -0
  213. package/dist/chunk-TP7244Y6.js.map +1 -0
  214. package/dist/chunk-TSBFTJKM.js +57 -0
  215. package/dist/chunk-TSBFTJKM.js.map +1 -0
  216. package/dist/chunk-URQ2CBBF.js +143 -0
  217. package/dist/chunk-URQ2CBBF.js.map +1 -0
  218. package/dist/chunk-VLAGJZSL.js +1079 -0
  219. package/dist/chunk-VLAGJZSL.js.map +1 -0
  220. package/dist/chunk-W2BOPXTI.js +1 -0
  221. package/dist/chunk-W2BOPXTI.js.map +1 -0
  222. package/dist/chunk-Y52CS6YA.js +88 -0
  223. package/dist/chunk-Y52CS6YA.js.map +1 -0
  224. package/dist/chunk-YCBUWK77.js +92 -0
  225. package/dist/chunk-YCBUWK77.js.map +1 -0
  226. package/dist/chunk-YJ4U2D2C.js +314 -0
  227. package/dist/chunk-YJ4U2D2C.js.map +1 -0
  228. package/dist/chunk-Z4YXAUDN.js +239 -0
  229. package/dist/chunk-Z4YXAUDN.js.map +1 -0
  230. package/dist/chunk-Z65DVDEQ.js +146 -0
  231. package/dist/chunk-Z65DVDEQ.js.map +1 -0
  232. package/dist/chunk-Z6EGP5D7.js +92 -0
  233. package/dist/chunk-Z6EGP5D7.js.map +1 -0
  234. package/dist/chunk-ZT4WMQW4.js +1575 -0
  235. package/dist/chunk-ZT4WMQW4.js.map +1 -0
  236. package/dist/chunk-ZVXXDWIB.js +1282 -0
  237. package/dist/chunk-ZVXXDWIB.js.map +1 -0
  238. package/dist/compat/index.cjs +3150 -6
  239. package/dist/compat/index.cjs.map +1 -1
  240. package/dist/compat/index.d.cts +116 -1
  241. package/dist/compat/index.d.ts +116 -1
  242. package/dist/compat/index.js +175 -2
  243. package/dist/compat/index.js.map +1 -1
  244. package/dist/compat/jotai/index.cjs +130 -2
  245. package/dist/compat/jotai/index.cjs.map +1 -1
  246. package/dist/compat/jotai/index.d.cts +2 -1
  247. package/dist/compat/jotai/index.d.ts +2 -1
  248. package/dist/compat/jotai/index.js +7 -2
  249. package/dist/compat/jotai/index.js.map +1 -1
  250. package/dist/compat/nanostores/index.cjs +186 -2
  251. package/dist/compat/nanostores/index.cjs.map +1 -1
  252. package/dist/compat/nanostores/index.d.cts +2 -1
  253. package/dist/compat/nanostores/index.d.ts +2 -1
  254. package/dist/compat/nanostores/index.js +21 -2
  255. package/dist/compat/nanostores/index.js.map +1 -1
  256. package/dist/compat/nestjs/index.cjs +2291 -6
  257. package/dist/compat/nestjs/index.cjs.map +1 -1
  258. package/dist/compat/nestjs/index.d.cts +10 -1
  259. package/dist/compat/nestjs/index.d.ts +10 -1
  260. package/dist/compat/nestjs/index.js +76 -2
  261. package/dist/compat/nestjs/index.js.map +1 -1
  262. package/dist/compat/react/index.cjs +95 -2
  263. package/dist/compat/react/index.cjs.map +1 -1
  264. package/dist/compat/react/index.d.cts +2 -1
  265. package/dist/compat/react/index.d.ts +2 -1
  266. package/dist/compat/react/index.js +11 -2
  267. package/dist/compat/react/index.js.map +1 -1
  268. package/dist/compat/solid/index.cjs +82 -2
  269. package/dist/compat/solid/index.cjs.map +1 -1
  270. package/dist/compat/solid/index.d.cts +2 -1
  271. package/dist/compat/solid/index.d.ts +2 -1
  272. package/dist/compat/solid/index.js +11 -2
  273. package/dist/compat/solid/index.js.map +1 -1
  274. package/dist/compat/svelte/index.cjs +85 -2
  275. package/dist/compat/svelte/index.cjs.map +1 -1
  276. package/dist/compat/svelte/index.d.cts +2 -1
  277. package/dist/compat/svelte/index.d.ts +2 -1
  278. package/dist/compat/svelte/index.js +11 -2
  279. package/dist/compat/svelte/index.js.map +1 -1
  280. package/dist/compat/vue/index.cjs +100 -2
  281. package/dist/compat/vue/index.cjs.map +1 -1
  282. package/dist/compat/vue/index.d.cts +3 -1
  283. package/dist/compat/vue/index.d.ts +3 -1
  284. package/dist/compat/vue/index.js +11 -2
  285. package/dist/compat/vue/index.js.map +1 -1
  286. package/dist/compat/zustand/index.cjs +50 -2
  287. package/dist/compat/zustand/index.cjs.map +1 -1
  288. package/dist/compat/zustand/index.d.cts +2 -1
  289. package/dist/compat/zustand/index.d.ts +2 -1
  290. package/dist/compat/zustand/index.js +7 -2
  291. package/dist/compat/zustand/index.js.map +1 -1
  292. package/dist/distill-De6Rnn15.d.cts +48 -0
  293. package/dist/distill-De6Rnn15.d.ts +48 -0
  294. package/dist/external-register-CWyroXb_.d.cts +138 -0
  295. package/dist/external-register-CWyroXb_.d.ts +138 -0
  296. package/dist/fallback-Bx46zqky.d.cts +243 -0
  297. package/dist/fallback-pIWW8A2d.d.ts +243 -0
  298. package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
  299. package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
  300. package/dist/index-B6pxYJzO.d.cts +36 -0
  301. package/dist/index-B6pxYJzO.d.ts +36 -0
  302. package/dist/index-BFsng6v1.d.cts +44 -0
  303. package/dist/index-BFsng6v1.d.ts +44 -0
  304. package/dist/index-B_p8tnvf.d.cts +770 -0
  305. package/dist/index-Bg-LwEt-.d.cts +45 -0
  306. package/dist/index-Bg-LwEt-.d.ts +45 -0
  307. package/dist/index-Brp888t0.d.cts +127 -0
  308. package/dist/index-Brp888t0.d.ts +127 -0
  309. package/dist/index-CDfk6jHN.d.cts +37 -0
  310. package/dist/index-CDfk6jHN.d.ts +37 -0
  311. package/dist/index-DLAxYaN5.d.cts +169 -0
  312. package/dist/index-DLAxYaN5.d.ts +169 -0
  313. package/dist/index-DeWbQzMe.d.cts +34 -0
  314. package/dist/index-DeWbQzMe.d.ts +34 -0
  315. package/dist/index-_HDSmPyp.d.ts +770 -0
  316. package/dist/index-dX9IzPqj.d.cts +86 -0
  317. package/dist/index-dX9IzPqj.d.ts +86 -0
  318. package/dist/index.cjs +26009 -0
  319. package/dist/index.cjs.map +1 -1
  320. package/dist/index.d.cts +55 -42
  321. package/dist/index.d.ts +55 -42
  322. package/dist/index.js +849 -0
  323. package/dist/index.js.map +1 -1
  324. package/dist/layout-types-B5aiHYgk.d.cts +72 -0
  325. package/dist/layout-types-B5aiHYgk.d.ts +72 -0
  326. package/dist/memory-composers-BryDrRBX.d.cts +529 -0
  327. package/dist/memory-composers-CVQqPYEV.d.ts +529 -0
  328. package/dist/observable-B25XqCbZ.d.cts +59 -0
  329. package/dist/observable-B25XqCbZ.d.ts +59 -0
  330. package/dist/pipeline-graph-Ce47CB6Y.d.cts +145 -0
  331. package/dist/pipeline-graph-DXCwY9vG.d.ts +145 -0
  332. package/dist/presets/ai/index.cjs +4377 -0
  333. package/dist/presets/ai/index.cjs.map +1 -0
  334. package/dist/presets/ai/index.d.cts +98 -0
  335. package/dist/presets/ai/index.d.ts +98 -0
  336. package/dist/presets/ai/index.js +54 -0
  337. package/dist/presets/ai/index.js.map +1 -0
  338. package/dist/presets/harness/index.cjs +5929 -0
  339. package/dist/presets/harness/index.cjs.map +1 -0
  340. package/dist/presets/harness/index.d.cts +566 -0
  341. package/dist/presets/harness/index.d.ts +566 -0
  342. package/dist/presets/harness/index.js +71 -0
  343. package/dist/presets/harness/index.js.map +1 -0
  344. package/dist/presets/index.cjs +9782 -0
  345. package/dist/presets/index.cjs.map +1 -0
  346. package/dist/presets/index.d.cts +28 -0
  347. package/dist/presets/index.d.ts +28 -0
  348. package/dist/presets/index.js +129 -0
  349. package/dist/presets/index.js.map +1 -0
  350. package/dist/presets/inspect/index.cjs +1087 -0
  351. package/dist/presets/inspect/index.cjs.map +1 -0
  352. package/dist/presets/inspect/index.d.cts +172 -0
  353. package/dist/presets/inspect/index.d.ts +172 -0
  354. package/dist/presets/inspect/index.js +21 -0
  355. package/dist/presets/inspect/index.js.map +1 -0
  356. package/dist/presets/resilience/index.cjs +1593 -0
  357. package/dist/presets/resilience/index.cjs.map +1 -0
  358. package/dist/presets/resilience/index.d.cts +205 -0
  359. package/dist/presets/resilience/index.d.ts +205 -0
  360. package/dist/presets/resilience/index.js +18 -0
  361. package/dist/presets/resilience/index.js.map +1 -0
  362. package/dist/rate-limiter-CEALq4N1.d.ts +559 -0
  363. package/dist/rate-limiter-DpVbSYdH.d.cts +559 -0
  364. package/dist/reactive-layout-fswlBUvX.d.cts +195 -0
  365. package/dist/reactive-layout-fswlBUvX.d.ts +195 -0
  366. package/dist/retry-BDbRZ_gx.d.ts +125 -0
  367. package/dist/retry-DWuhjvsA.d.cts +125 -0
  368. package/dist/solutions/index.cjs +8200 -0
  369. package/dist/solutions/index.cjs.map +1 -0
  370. package/dist/solutions/index.d.cts +23 -0
  371. package/dist/solutions/index.d.ts +23 -0
  372. package/dist/solutions/index.js +55 -0
  373. package/dist/solutions/index.js.map +1 -0
  374. package/dist/spawnable-5mDY501F.d.cts +746 -0
  375. package/dist/spawnable-D3lR0oQu.d.ts +746 -0
  376. package/dist/status-U-rUI79b.d.cts +84 -0
  377. package/dist/status-U-rUI79b.d.ts +84 -0
  378. package/dist/timeout-U5O4ESK3.js +12 -0
  379. package/dist/timeout-U5O4ESK3.js.map +1 -0
  380. package/dist/types-BB5Lw-pB.d.cts +442 -0
  381. package/dist/types-BB5Lw-pB.d.ts +442 -0
  382. package/dist/types-CJWIMJiZ.d.ts +548 -0
  383. package/dist/types-vCq7ShIm.d.cts +548 -0
  384. package/dist/utils/ai/browser.cjs +2169 -0
  385. package/dist/utils/ai/browser.cjs.map +1 -0
  386. package/dist/utils/ai/browser.d.cts +129 -0
  387. package/dist/utils/ai/browser.d.ts +129 -0
  388. package/dist/utils/ai/browser.js +255 -0
  389. package/dist/utils/ai/browser.js.map +1 -0
  390. package/dist/utils/ai/index.cjs +8468 -0
  391. package/dist/utils/ai/index.cjs.map +1 -0
  392. package/dist/utils/ai/index.d.cts +1777 -0
  393. package/dist/utils/ai/index.d.ts +1777 -0
  394. package/dist/utils/ai/index.js +173 -0
  395. package/dist/utils/ai/index.js.map +1 -0
  396. package/dist/utils/ai/node.cjs +648 -0
  397. package/dist/utils/ai/node.cjs.map +1 -0
  398. package/dist/utils/ai/node.d.cts +57 -0
  399. package/dist/utils/ai/node.d.ts +57 -0
  400. package/dist/utils/ai/node.js +84 -0
  401. package/dist/utils/ai/node.js.map +1 -0
  402. package/dist/utils/cqrs/index.cjs +1036 -0
  403. package/dist/utils/cqrs/index.cjs.map +1 -0
  404. package/dist/utils/cqrs/index.d.cts +438 -0
  405. package/dist/utils/cqrs/index.d.ts +438 -0
  406. package/dist/utils/cqrs/index.js +18 -0
  407. package/dist/utils/cqrs/index.js.map +1 -0
  408. package/dist/utils/demo-shell/index.cjs +865 -0
  409. package/dist/utils/demo-shell/index.cjs.map +1 -0
  410. package/dist/utils/demo-shell/index.d.cts +90 -0
  411. package/dist/utils/demo-shell/index.d.ts +90 -0
  412. package/dist/utils/demo-shell/index.js +13 -0
  413. package/dist/utils/demo-shell/index.js.map +1 -0
  414. package/dist/utils/domain-templates/index.cjs +732 -0
  415. package/dist/utils/domain-templates/index.cjs.map +1 -0
  416. package/dist/utils/domain-templates/index.d.cts +214 -0
  417. package/dist/utils/domain-templates/index.d.ts +214 -0
  418. package/dist/utils/domain-templates/index.js +17 -0
  419. package/dist/utils/domain-templates/index.js.map +1 -0
  420. package/dist/utils/graphspec/index.cjs +1174 -0
  421. package/dist/utils/graphspec/index.cjs.map +1 -0
  422. package/dist/utils/graphspec/index.d.cts +449 -0
  423. package/dist/utils/graphspec/index.d.ts +449 -0
  424. package/dist/utils/graphspec/index.js +35 -0
  425. package/dist/utils/graphspec/index.js.map +1 -0
  426. package/dist/utils/harness/index.cjs +656 -0
  427. package/dist/utils/harness/index.cjs.map +1 -0
  428. package/dist/utils/harness/index.d.cts +542 -0
  429. package/dist/utils/harness/index.d.ts +542 -0
  430. package/dist/utils/harness/index.js +56 -0
  431. package/dist/utils/harness/index.js.map +1 -0
  432. package/dist/utils/index.cjs +17614 -0
  433. package/dist/utils/index.cjs.map +1 -0
  434. package/dist/utils/index.d.cts +96 -0
  435. package/dist/utils/index.d.ts +96 -0
  436. package/dist/utils/index.js +514 -0
  437. package/dist/utils/index.js.map +1 -0
  438. package/dist/utils/inspect/index.cjs +807 -0
  439. package/dist/utils/inspect/index.cjs.map +1 -0
  440. package/dist/utils/inspect/index.d.cts +123 -0
  441. package/dist/utils/inspect/index.d.ts +123 -0
  442. package/dist/utils/inspect/index.js +30 -0
  443. package/dist/utils/inspect/index.js.map +1 -0
  444. package/dist/utils/job-queue/index.cjs +717 -0
  445. package/dist/utils/job-queue/index.cjs.map +1 -0
  446. package/dist/utils/job-queue/index.d.cts +200 -0
  447. package/dist/utils/job-queue/index.d.ts +200 -0
  448. package/dist/utils/job-queue/index.js +18 -0
  449. package/dist/utils/job-queue/index.js.map +1 -0
  450. package/dist/utils/memory/index.cjs +1456 -0
  451. package/dist/utils/memory/index.cjs.map +1 -0
  452. package/dist/utils/memory/index.d.cts +660 -0
  453. package/dist/utils/memory/index.d.ts +660 -0
  454. package/dist/utils/memory/index.js +19 -0
  455. package/dist/utils/memory/index.js.map +1 -0
  456. package/dist/utils/messaging/index.cjs +666 -0
  457. package/dist/utils/messaging/index.cjs.map +1 -0
  458. package/dist/utils/messaging/index.d.cts +562 -0
  459. package/dist/utils/messaging/index.d.ts +562 -0
  460. package/dist/utils/messaging/index.js +50 -0
  461. package/dist/utils/messaging/index.js.map +1 -0
  462. package/dist/utils/orchestration/index.cjs +876 -0
  463. package/dist/utils/orchestration/index.cjs.map +1 -0
  464. package/dist/utils/orchestration/index.d.cts +233 -0
  465. package/dist/utils/orchestration/index.d.ts +233 -0
  466. package/dist/utils/orchestration/index.js +19 -0
  467. package/dist/utils/orchestration/index.js.map +1 -0
  468. package/dist/utils/process/index.cjs +743 -0
  469. package/dist/utils/process/index.cjs.map +1 -0
  470. package/dist/utils/process/index.d.cts +411 -0
  471. package/dist/utils/process/index.d.ts +411 -0
  472. package/dist/utils/process/index.js +14 -0
  473. package/dist/utils/process/index.js.map +1 -0
  474. package/dist/utils/reactive-layout/index.cjs +1607 -0
  475. package/dist/utils/reactive-layout/index.cjs.map +1 -0
  476. package/dist/utils/reactive-layout/index.d.cts +492 -0
  477. package/dist/utils/reactive-layout/index.d.ts +492 -0
  478. package/dist/utils/reactive-layout/index.js +52 -0
  479. package/dist/utils/reactive-layout/index.js.map +1 -0
  480. package/dist/utils/reduction/index.cjs +203 -0
  481. package/dist/utils/reduction/index.cjs.map +1 -0
  482. package/dist/utils/reduction/index.d.cts +102 -0
  483. package/dist/utils/reduction/index.d.ts +102 -0
  484. package/dist/utils/reduction/index.js +14 -0
  485. package/dist/utils/reduction/index.js.map +1 -0
  486. package/dist/utils/resilience/index.cjs +1617 -0
  487. package/dist/utils/resilience/index.cjs.map +1 -0
  488. package/dist/utils/resilience/index.d.cts +9 -0
  489. package/dist/utils/resilience/index.d.ts +9 -0
  490. package/dist/utils/resilience/index.js +44 -0
  491. package/dist/utils/resilience/index.js.map +1 -0
  492. package/dist/utils/surface/index.cjs +1070 -0
  493. package/dist/utils/surface/index.cjs.map +1 -0
  494. package/dist/utils/surface/index.d.cts +240 -0
  495. package/dist/utils/surface/index.d.ts +240 -0
  496. package/dist/utils/surface/index.js +30 -0
  497. package/dist/utils/surface/index.js.map +1 -0
  498. package/dist/utils/topology-view/index.cjs +620 -0
  499. package/dist/utils/topology-view/index.cjs.map +1 -0
  500. package/dist/utils/topology-view/index.d.cts +68 -0
  501. package/dist/utils/topology-view/index.d.ts +68 -0
  502. package/dist/utils/topology-view/index.js +11 -0
  503. package/dist/utils/topology-view/index.js.map +1 -0
  504. package/package.json +293 -241
  505. package/dist/core/index.cjs +0 -21
  506. package/dist/core/index.cjs.map +0 -1
  507. package/dist/core/index.d.cts +0 -1
  508. package/dist/core/index.d.ts +0 -1
  509. package/dist/core/index.js +0 -3
  510. package/dist/core/index.js.map +0 -1
  511. package/dist/extra/browser.cjs +0 -21
  512. package/dist/extra/browser.cjs.map +0 -1
  513. package/dist/extra/browser.d.cts +0 -1
  514. package/dist/extra/browser.d.ts +0 -1
  515. package/dist/extra/browser.js +0 -3
  516. package/dist/extra/browser.js.map +0 -1
  517. package/dist/extra/index.cjs +0 -21
  518. package/dist/extra/index.cjs.map +0 -1
  519. package/dist/extra/index.d.cts +0 -1
  520. package/dist/extra/index.d.ts +0 -1
  521. package/dist/extra/index.js +0 -3
  522. package/dist/extra/index.js.map +0 -1
  523. package/dist/extra/node.cjs +0 -21
  524. package/dist/extra/node.cjs.map +0 -1
  525. package/dist/extra/node.d.cts +0 -1
  526. package/dist/extra/node.d.ts +0 -1
  527. package/dist/extra/node.js +0 -3
  528. package/dist/extra/node.js.map +0 -1
  529. package/dist/extra/operators.cjs +0 -21
  530. package/dist/extra/operators.cjs.map +0 -1
  531. package/dist/extra/operators.d.cts +0 -1
  532. package/dist/extra/operators.d.ts +0 -1
  533. package/dist/extra/operators.js +0 -3
  534. package/dist/extra/operators.js.map +0 -1
  535. package/dist/extra/reactive.cjs +0 -21
  536. package/dist/extra/reactive.cjs.map +0 -1
  537. package/dist/extra/reactive.d.cts +0 -1
  538. package/dist/extra/reactive.d.ts +0 -1
  539. package/dist/extra/reactive.js +0 -3
  540. package/dist/extra/reactive.js.map +0 -1
  541. package/dist/extra/render/index.cjs +0 -21
  542. package/dist/extra/render/index.cjs.map +0 -1
  543. package/dist/extra/render/index.d.cts +0 -1
  544. package/dist/extra/render/index.d.ts +0 -1
  545. package/dist/extra/render/index.js +0 -3
  546. package/dist/extra/render/index.js.map +0 -1
  547. package/dist/extra/sources.cjs +0 -21
  548. package/dist/extra/sources.cjs.map +0 -1
  549. package/dist/extra/sources.d.cts +0 -1
  550. package/dist/extra/sources.d.ts +0 -1
  551. package/dist/extra/sources.js +0 -3
  552. package/dist/extra/sources.js.map +0 -1
  553. package/dist/extra/storage-browser.cjs +0 -21
  554. package/dist/extra/storage-browser.cjs.map +0 -1
  555. package/dist/extra/storage-browser.d.cts +0 -1
  556. package/dist/extra/storage-browser.d.ts +0 -1
  557. package/dist/extra/storage-browser.js +0 -3
  558. package/dist/extra/storage-browser.js.map +0 -1
  559. package/dist/extra/storage-core.cjs +0 -21
  560. package/dist/extra/storage-core.cjs.map +0 -1
  561. package/dist/extra/storage-core.d.cts +0 -1
  562. package/dist/extra/storage-core.d.ts +0 -1
  563. package/dist/extra/storage-core.js +0 -3
  564. package/dist/extra/storage-core.js.map +0 -1
  565. package/dist/extra/storage-node.cjs +0 -21
  566. package/dist/extra/storage-node.cjs.map +0 -1
  567. package/dist/extra/storage-node.d.cts +0 -1
  568. package/dist/extra/storage-node.d.ts +0 -1
  569. package/dist/extra/storage-node.js +0 -3
  570. package/dist/extra/storage-node.js.map +0 -1
  571. package/dist/extra/storage-tiers-browser.cjs +0 -21
  572. package/dist/extra/storage-tiers-browser.cjs.map +0 -1
  573. package/dist/extra/storage-tiers-browser.d.cts +0 -1
  574. package/dist/extra/storage-tiers-browser.d.ts +0 -1
  575. package/dist/extra/storage-tiers-browser.js +0 -3
  576. package/dist/extra/storage-tiers-browser.js.map +0 -1
  577. package/dist/extra/storage-tiers-node.cjs +0 -21
  578. package/dist/extra/storage-tiers-node.cjs.map +0 -1
  579. package/dist/extra/storage-tiers-node.d.cts +0 -1
  580. package/dist/extra/storage-tiers-node.d.ts +0 -1
  581. package/dist/extra/storage-tiers-node.js +0 -3
  582. package/dist/extra/storage-tiers-node.js.map +0 -1
  583. package/dist/extra/storage-tiers.cjs +0 -21
  584. package/dist/extra/storage-tiers.cjs.map +0 -1
  585. package/dist/extra/storage-tiers.d.cts +0 -1
  586. package/dist/extra/storage-tiers.d.ts +0 -1
  587. package/dist/extra/storage-tiers.js +0 -3
  588. package/dist/extra/storage-tiers.js.map +0 -1
  589. package/dist/extra/storage-wal.cjs +0 -21
  590. package/dist/extra/storage-wal.cjs.map +0 -1
  591. package/dist/extra/storage-wal.d.cts +0 -1
  592. package/dist/extra/storage-wal.d.ts +0 -1
  593. package/dist/extra/storage-wal.js +0 -3
  594. package/dist/extra/storage-wal.js.map +0 -1
  595. package/dist/graph/index.cjs +0 -21
  596. package/dist/graph/index.cjs.map +0 -1
  597. package/dist/graph/index.d.cts +0 -1
  598. package/dist/graph/index.d.ts +0 -1
  599. package/dist/graph/index.js +0 -3
  600. package/dist/graph/index.js.map +0 -1
  601. package/dist/patterns/ai/browser.cjs +0 -21
  602. package/dist/patterns/ai/browser.cjs.map +0 -1
  603. package/dist/patterns/ai/browser.d.cts +0 -1
  604. package/dist/patterns/ai/browser.d.ts +0 -1
  605. package/dist/patterns/ai/browser.js +0 -3
  606. package/dist/patterns/ai/browser.js.map +0 -1
  607. package/dist/patterns/ai/index.cjs +0 -21
  608. package/dist/patterns/ai/index.cjs.map +0 -1
  609. package/dist/patterns/ai/index.d.cts +0 -1
  610. package/dist/patterns/ai/index.d.ts +0 -1
  611. package/dist/patterns/ai/index.js +0 -3
  612. package/dist/patterns/ai/index.js.map +0 -1
  613. package/dist/patterns/ai/node.cjs +0 -21
  614. package/dist/patterns/ai/node.cjs.map +0 -1
  615. package/dist/patterns/ai/node.d.cts +0 -1
  616. package/dist/patterns/ai/node.d.ts +0 -1
  617. package/dist/patterns/ai/node.js +0 -3
  618. package/dist/patterns/ai/node.js.map +0 -1
  619. package/dist/patterns/cqrs/index.cjs +0 -21
  620. package/dist/patterns/cqrs/index.cjs.map +0 -1
  621. package/dist/patterns/cqrs/index.d.cts +0 -1
  622. package/dist/patterns/cqrs/index.d.ts +0 -1
  623. package/dist/patterns/cqrs/index.js +0 -3
  624. package/dist/patterns/cqrs/index.js.map +0 -1
  625. package/dist/patterns/demo-shell/index.cjs +0 -21
  626. package/dist/patterns/demo-shell/index.cjs.map +0 -1
  627. package/dist/patterns/demo-shell/index.d.cts +0 -1
  628. package/dist/patterns/demo-shell/index.d.ts +0 -1
  629. package/dist/patterns/demo-shell/index.js +0 -3
  630. package/dist/patterns/demo-shell/index.js.map +0 -1
  631. package/dist/patterns/domain-templates/index.cjs +0 -21
  632. package/dist/patterns/domain-templates/index.cjs.map +0 -1
  633. package/dist/patterns/domain-templates/index.d.cts +0 -1
  634. package/dist/patterns/domain-templates/index.d.ts +0 -1
  635. package/dist/patterns/domain-templates/index.js +0 -3
  636. package/dist/patterns/domain-templates/index.js.map +0 -1
  637. package/dist/patterns/graphspec/index.cjs +0 -21
  638. package/dist/patterns/graphspec/index.cjs.map +0 -1
  639. package/dist/patterns/graphspec/index.d.cts +0 -1
  640. package/dist/patterns/graphspec/index.d.ts +0 -1
  641. package/dist/patterns/graphspec/index.js +0 -3
  642. package/dist/patterns/graphspec/index.js.map +0 -1
  643. package/dist/patterns/harness/index.cjs +0 -21
  644. package/dist/patterns/harness/index.cjs.map +0 -1
  645. package/dist/patterns/harness/index.d.cts +0 -1
  646. package/dist/patterns/harness/index.d.ts +0 -1
  647. package/dist/patterns/harness/index.js +0 -3
  648. package/dist/patterns/harness/index.js.map +0 -1
  649. package/dist/patterns/inspect/index.cjs +0 -21
  650. package/dist/patterns/inspect/index.cjs.map +0 -1
  651. package/dist/patterns/inspect/index.d.cts +0 -1
  652. package/dist/patterns/inspect/index.d.ts +0 -1
  653. package/dist/patterns/inspect/index.js +0 -3
  654. package/dist/patterns/inspect/index.js.map +0 -1
  655. package/dist/patterns/job-queue/index.cjs +0 -21
  656. package/dist/patterns/job-queue/index.cjs.map +0 -1
  657. package/dist/patterns/job-queue/index.d.cts +0 -1
  658. package/dist/patterns/job-queue/index.d.ts +0 -1
  659. package/dist/patterns/job-queue/index.js +0 -3
  660. package/dist/patterns/job-queue/index.js.map +0 -1
  661. package/dist/patterns/memory/index.cjs +0 -21
  662. package/dist/patterns/memory/index.cjs.map +0 -1
  663. package/dist/patterns/memory/index.d.cts +0 -1
  664. package/dist/patterns/memory/index.d.ts +0 -1
  665. package/dist/patterns/memory/index.js +0 -3
  666. package/dist/patterns/memory/index.js.map +0 -1
  667. package/dist/patterns/messaging/index.cjs +0 -21
  668. package/dist/patterns/messaging/index.cjs.map +0 -1
  669. package/dist/patterns/messaging/index.d.cts +0 -1
  670. package/dist/patterns/messaging/index.d.ts +0 -1
  671. package/dist/patterns/messaging/index.js +0 -3
  672. package/dist/patterns/messaging/index.js.map +0 -1
  673. package/dist/patterns/orchestration/index.cjs +0 -21
  674. package/dist/patterns/orchestration/index.cjs.map +0 -1
  675. package/dist/patterns/orchestration/index.d.cts +0 -1
  676. package/dist/patterns/orchestration/index.d.ts +0 -1
  677. package/dist/patterns/orchestration/index.js +0 -3
  678. package/dist/patterns/orchestration/index.js.map +0 -1
  679. package/dist/patterns/process/index.cjs +0 -21
  680. package/dist/patterns/process/index.cjs.map +0 -1
  681. package/dist/patterns/process/index.d.cts +0 -1
  682. package/dist/patterns/process/index.d.ts +0 -1
  683. package/dist/patterns/process/index.js +0 -3
  684. package/dist/patterns/process/index.js.map +0 -1
  685. package/dist/patterns/reactive-layout/index.cjs +0 -21
  686. package/dist/patterns/reactive-layout/index.cjs.map +0 -1
  687. package/dist/patterns/reactive-layout/index.d.cts +0 -1
  688. package/dist/patterns/reactive-layout/index.d.ts +0 -1
  689. package/dist/patterns/reactive-layout/index.js +0 -3
  690. package/dist/patterns/reactive-layout/index.js.map +0 -1
  691. package/dist/patterns/reduction/index.cjs +0 -21
  692. package/dist/patterns/reduction/index.cjs.map +0 -1
  693. package/dist/patterns/reduction/index.d.cts +0 -1
  694. package/dist/patterns/reduction/index.d.ts +0 -1
  695. package/dist/patterns/reduction/index.js +0 -3
  696. package/dist/patterns/reduction/index.js.map +0 -1
  697. package/dist/patterns/surface/index.cjs +0 -21
  698. package/dist/patterns/surface/index.cjs.map +0 -1
  699. package/dist/patterns/surface/index.d.cts +0 -1
  700. package/dist/patterns/surface/index.d.ts +0 -1
  701. package/dist/patterns/surface/index.js +0 -3
  702. package/dist/patterns/surface/index.js.map +0 -1
  703. package/dist/patterns/topology-view/index.cjs +0 -21
  704. package/dist/patterns/topology-view/index.cjs.map +0 -1
  705. package/dist/patterns/topology-view/index.d.cts +0 -1
  706. package/dist/patterns/topology-view/index.d.ts +0 -1
  707. package/dist/patterns/topology-view/index.js +0 -3
  708. package/dist/patterns/topology-view/index.js.map +0 -1
  709. package/dist/testing/index.cjs +0 -21
  710. package/dist/testing/index.cjs.map +0 -1
  711. package/dist/testing/index.d.cts +0 -1
  712. package/dist/testing/index.d.ts +0 -1
  713. package/dist/testing/index.js +0 -3
  714. package/dist/testing/index.js.map +0 -1
@@ -0,0 +1,1456 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/memory/index.ts
21
+ var memory_exports = {};
22
+ __export(memory_exports, {
23
+ collection: () => collection,
24
+ cosineSimilarity: () => cosineSimilarity,
25
+ knowledgeGraph: () => knowledgeGraph,
26
+ reactiveFactStore: () => reactiveFactStore,
27
+ vectorIndex: () => vectorIndex
28
+ });
29
+ module.exports = __toCommonJS(memory_exports);
30
+ var import_core3 = require("@graphrefly/pure-ts/core");
31
+ var import_extra3 = require("@graphrefly/pure-ts/extra");
32
+ var import_graph3 = require("@graphrefly/pure-ts/graph");
33
+
34
+ // src/base/meta/domain-meta.ts
35
+ function domainMeta(domain, kind, extra) {
36
+ return {
37
+ [domain]: true,
38
+ [`${domain}_type`]: kind,
39
+ ...extra ?? {}
40
+ };
41
+ }
42
+
43
+ // src/base/mutation/index.ts
44
+ var import_core = require("@graphrefly/pure-ts/core");
45
+ var import_extra = require("@graphrefly/pure-ts/extra");
46
+ var import_graph = require("@graphrefly/pure-ts/graph");
47
+ var DEFAULT_AUDIT_GUARD = (0, import_core.policy)((allow, deny) => {
48
+ allow("observe");
49
+ allow("signal");
50
+ deny("write");
51
+ });
52
+ function createAuditLog(opts) {
53
+ const log = (0, import_extra.reactiveLog)([], {
54
+ name: opts.name,
55
+ maxSize: opts.retainedLimit ?? 1024,
56
+ guard: opts.guard ?? DEFAULT_AUDIT_GUARD,
57
+ ...opts.versioning != null ? { versioning: opts.versioning } : {}
58
+ });
59
+ log.withLatest();
60
+ if (opts.graph) {
61
+ opts.graph.add(log.entries, { name: opts.name });
62
+ }
63
+ return log;
64
+ }
65
+ function deepFreeze(value) {
66
+ if (value === null || typeof value !== "object" || Object.isFrozen(value)) return value;
67
+ for (const k of Object.keys(value)) {
68
+ deepFreeze(value[k]);
69
+ }
70
+ return Object.freeze(value);
71
+ }
72
+ function mutate(act, opts) {
73
+ const { up, down } = typeof act === "function" ? { up: act, down: void 0 } : act;
74
+ const freeze = opts.freeze ?? true;
75
+ if (opts.frame === "inline") {
76
+ return function wrapped(...args) {
77
+ const sealed = freeze ? args.map(deepFreeze) : args;
78
+ const t_ns = (0, import_core.wallClockNs)();
79
+ const seq = opts.seq ? bumpCursor(opts.seq) : void 0;
80
+ try {
81
+ const result = up(...sealed);
82
+ if (opts.log && opts.onSuccessRecord) {
83
+ appendAudit(
84
+ opts.log,
85
+ opts.onSuccessRecord,
86
+ sealed,
87
+ result,
88
+ { t_ns, seq },
89
+ opts.handlerVersion
90
+ );
91
+ }
92
+ return result;
93
+ } catch (err) {
94
+ if (opts.log && opts.onFailureRecord) {
95
+ const errorType = err instanceof Error ? err.name : typeof err;
96
+ appendAudit(
97
+ opts.log,
98
+ opts.onFailureRecord,
99
+ sealed,
100
+ err,
101
+ { t_ns, seq, errorType },
102
+ opts.handlerVersion
103
+ );
104
+ }
105
+ throw err;
106
+ }
107
+ };
108
+ }
109
+ return function wrapped(...args) {
110
+ const sealed = freeze ? args.map(deepFreeze) : args;
111
+ const t_ns = (0, import_core.wallClockNs)();
112
+ let result;
113
+ let captured;
114
+ let captureSet = false;
115
+ let seq;
116
+ try {
117
+ (0, import_core.batch)(() => {
118
+ if (opts.seq) seq = bumpCursor(opts.seq);
119
+ try {
120
+ result = up(...sealed);
121
+ if (opts.log && opts.onSuccessRecord) {
122
+ appendAudit(
123
+ opts.log,
124
+ opts.onSuccessRecord,
125
+ sealed,
126
+ result,
127
+ { t_ns, seq },
128
+ opts.handlerVersion
129
+ );
130
+ }
131
+ } catch (err) {
132
+ captured = err;
133
+ captureSet = true;
134
+ throw err;
135
+ }
136
+ });
137
+ } catch (outerErr) {
138
+ if (captureSet && down) {
139
+ try {
140
+ down(...sealed);
141
+ } catch (downErr) {
142
+ console.error(
143
+ `mutate: down hook threw \u2014 original action error preserved (${captured instanceof Error ? captured.name : typeof captured}). Down error:`,
144
+ downErr
145
+ );
146
+ }
147
+ }
148
+ if (captureSet && opts.log && opts.onFailureRecord) {
149
+ const errorType = captured instanceof Error ? captured.name : typeof captured;
150
+ appendAudit(
151
+ opts.log,
152
+ opts.onFailureRecord,
153
+ sealed,
154
+ captured,
155
+ { t_ns, seq, errorType },
156
+ opts.handlerVersion
157
+ );
158
+ }
159
+ throw captureSet ? captured : outerErr;
160
+ }
161
+ return result;
162
+ };
163
+ }
164
+ var _bumpCursorWarned = /* @__PURE__ */ new WeakSet();
165
+ function bumpCursor(seq) {
166
+ const raw = seq.cache;
167
+ const valid = typeof raw === "number" && Number.isFinite(raw);
168
+ if (!valid && raw !== void 0 && !_bumpCursorWarned.has(seq)) {
169
+ _bumpCursorWarned.add(seq);
170
+ console.warn(
171
+ `bumpCursor: cursor cache held a non-numeric value (${String(raw)}); resetting to 0. Causes include: a snapshot codec round-tripping the cursor as a string / null / NaN, OR a malformed initial seed (e.g. state<number>(NaN)). Audit consumers may see colliding seq values after this point.`
172
+ );
173
+ }
174
+ const cur = valid ? raw : 0;
175
+ const next = cur + 1;
176
+ seq.down([[import_core.DIRTY], [import_core.DATA, next]]);
177
+ return next;
178
+ }
179
+ function appendAudit(audit, builder, args, value, meta, handlerVersion) {
180
+ const record = builder(args, value, meta);
181
+ if (record === void 0) return;
182
+ const stamped = handlerVersion != null ? { ...record, handlerVersion } : record;
183
+ audit.append(stamped);
184
+ }
185
+ function registerCursor(graph, name, initial = 0) {
186
+ const cursor = (0, import_core.node)([], { initial, name, describeKind: "state" });
187
+ graph.add(cursor, { name });
188
+ return cursor;
189
+ }
190
+
191
+ // src/base/utils/decay.ts
192
+ var DEFAULT_DECAY_RATE = Math.LN2 / (7 * 86400);
193
+ function decay(baseScore, ageSeconds2, ratePerSecond, minScore = 0) {
194
+ if (!Number.isFinite(baseScore)) return minScore;
195
+ if (!Number.isFinite(ageSeconds2) || ageSeconds2 <= 0) return Math.max(minScore, baseScore);
196
+ if (!Number.isFinite(ratePerSecond) || ratePerSecond <= 0) return Math.max(minScore, baseScore);
197
+ const decayed = baseScore * Math.exp(-ratePerSecond * ageSeconds2);
198
+ return Math.max(minScore, decayed);
199
+ }
200
+
201
+ // src/utils/memory/fact-store.ts
202
+ var import_core2 = require("@graphrefly/pure-ts/core");
203
+ var import_extra2 = require("@graphrefly/pure-ts/extra");
204
+ var import_graph2 = require("@graphrefly/pure-ts/graph");
205
+ var OVERFLOW_SAMPLE_SIZE = 8;
206
+ function factMeta(kind, extra) {
207
+ return domainMeta("memory", kind, extra);
208
+ }
209
+ function fnv1a(s) {
210
+ let h = 2166136261;
211
+ for (let i = 0; i < s.length; i += 1) {
212
+ h ^= s.charCodeAt(i);
213
+ h = h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)) >>> 0;
214
+ }
215
+ return h >>> 0;
216
+ }
217
+ function makeReadHandle(byId) {
218
+ return {
219
+ get: (id) => byId.get(id),
220
+ has: (id) => byId.has(id),
221
+ get size() {
222
+ return byId.size;
223
+ },
224
+ values: () => byId.values()
225
+ };
226
+ }
227
+ function currentlyValid(f, asOf) {
228
+ if (asOf === void 0) return f.validTo === void 0;
229
+ if (f.validFrom !== void 0 && asOf < f.validFrom) return false;
230
+ if (f.validTo !== void 0 && asOf >= f.validTo) return false;
231
+ return true;
232
+ }
233
+ function lastOf(batch2, prev) {
234
+ return batch2 != null && batch2.length > 0 ? batch2.at(-1) : prev;
235
+ }
236
+ function reactiveFactStore(config) {
237
+ const shardCount = Math.max(1, config.shardCount ?? 4);
238
+ const maxIterations = Math.max(1, config.cascadeMaxIterations ?? 8);
239
+ const reviewThreshold = config.reviewThreshold ?? 0.3;
240
+ const shardBy = config.shardBy ?? ((f) => fnv1a(String(f.id)) % shardCount);
241
+ let cascadeIteration = 0;
242
+ const processedRoots = /* @__PURE__ */ new Set();
243
+ const graph = new import_graph2.Graph("reactive_fact_store");
244
+ const events = createAuditLog({
245
+ name: "events",
246
+ retainedLimit: 1024,
247
+ graph
248
+ });
249
+ const seqCursor = registerCursor(graph, "seq", 0);
250
+ const ingestLog = config.recordIngest ? (0, import_extra2.reactiveLog)([], { name: "ingest_log" }) : void 0;
251
+ if (ingestLog) graph.addDisposer(() => ingestLog.dispose());
252
+ const emptyStore = () => ({ byId: /* @__PURE__ */ new Map() });
253
+ const shards = [];
254
+ for (let s = 0; s < shardCount; s += 1) {
255
+ const shard = (0, import_core2.node)([], {
256
+ initial: emptyStore(),
257
+ name: `shard_${s}`,
258
+ describeKind: "state",
259
+ meta: factMeta("factstore", { shard: s })
260
+ });
261
+ graph.add(shard, { name: `shard_${s}` });
262
+ graph.addDisposer((0, import_extra2.keepalive)(shard));
263
+ shards.push(shard);
264
+ }
265
+ const shardIndexFor = (f) => {
266
+ const key = shardBy(f);
267
+ const n = typeof key === "number" ? key : fnv1a(String(key));
268
+ const idx = (n % shardCount + shardCount) % shardCount;
269
+ return idx;
270
+ };
271
+ const findShardOf = (id) => {
272
+ for (let s = 0; s < shardCount; s += 1) {
273
+ const fs = shards[s].cache;
274
+ if (fs?.byId.has(id)) return s;
275
+ }
276
+ return -1;
277
+ };
278
+ const allFacts = () => {
279
+ const out2 = /* @__PURE__ */ new Map();
280
+ for (const sh of shards) {
281
+ const fs = sh.cache;
282
+ if (!fs) continue;
283
+ for (const [k, v] of fs.byId) out2.set(k, v);
284
+ }
285
+ return out2;
286
+ };
287
+ const commitFragment = (f) => {
288
+ const idx = shardIndexFor(f);
289
+ const cur = shards[idx].cache ?? emptyStore();
290
+ const next = new Map(cur.byId);
291
+ next.set(f.id, f);
292
+ shards[idx].emit({ byId: next });
293
+ };
294
+ const replaceFragment = (id, mut) => {
295
+ const idx = findShardOf(id);
296
+ if (idx < 0) return false;
297
+ const cur = shards[idx].cache;
298
+ const prev = cur.byId.get(id);
299
+ if (!prev) return false;
300
+ const next = new Map(cur.byId);
301
+ next.set(id, mut(prev));
302
+ shards[idx].emit({ byId: next });
303
+ return true;
304
+ };
305
+ const dependentsIndex = (0, import_core2.node)([], {
306
+ initial: /* @__PURE__ */ new Map(),
307
+ name: "dependents_index",
308
+ describeKind: "state",
309
+ meta: factMeta("factstore", { role: "dependents_index" })
310
+ });
311
+ graph.add(dependentsIndex, { name: "dependents_index" });
312
+ graph.addDisposer((0, import_extra2.keepalive)(dependentsIndex));
313
+ const indexFragment = (f, deps) => {
314
+ const cur = dependentsIndex.cache;
315
+ const next = /* @__PURE__ */ new Map();
316
+ for (const [k, v] of cur) next.set(k, [...v]);
317
+ for (const src of deps) {
318
+ const bucket = next.get(src) ?? [];
319
+ if (!bucket.includes(f.id)) bucket.push(f.id);
320
+ next.set(src, bucket);
321
+ }
322
+ dependentsIndex.emit(next);
323
+ };
324
+ const factStore = (0, import_core2.node)(
325
+ shards,
326
+ (batchData, actions, ctx) => {
327
+ void batchData;
328
+ void ctx;
329
+ actions.emit({ byId: allFacts() });
330
+ },
331
+ {
332
+ name: "fact_store",
333
+ describeKind: "derived",
334
+ initial: emptyStore(),
335
+ meta: factMeta("factstore", { role: "read_view" }),
336
+ // F10a: `allFacts()` builds a fresh Map every detector retrigger.
337
+ // Fragments are immutable (replaced wholesale on mutation), so a
338
+ // same-size + per-key-identity check is a sound structural equality
339
+ // that stops `factStore` (and its `review` dependent) from re-firing
340
+ // every cascade wave when nothing actually changed.
341
+ equals: (a, b) => {
342
+ if (a === b) return true;
343
+ if (a.byId.size !== b.byId.size) return false;
344
+ for (const [k, v] of a.byId) {
345
+ if (b.byId.get(k) !== v) return false;
346
+ }
347
+ return true;
348
+ }
349
+ }
350
+ );
351
+ graph.add(factStore, { name: "fact_store" });
352
+ graph.addDisposer((0, import_extra2.keepalive)(factStore));
353
+ const extractOp = (0, import_core2.node)(
354
+ config.admissionFilter ? [config.ingest, config.admissionFilter] : [config.ingest],
355
+ (batchData, actions, ctx) => {
356
+ const f = lastOf(batchData[0], ctx.prevData[0]);
357
+ if (f == null) {
358
+ actions.emit(null);
359
+ return;
360
+ }
361
+ if (config.admissionFilter) {
362
+ const filter = lastOf(batchData[1], ctx.prevData[1]);
363
+ if (filter && !filter(f)) {
364
+ actions.emit(null);
365
+ return;
366
+ }
367
+ }
368
+ const deps = config.extractDependencies(f);
369
+ cascadeIteration = 0;
370
+ processedRoots.delete(f.id);
371
+ commitFragment(f);
372
+ indexFragment(f, deps);
373
+ actions.emit(f);
374
+ },
375
+ {
376
+ name: "extract_op",
377
+ describeKind: "derived",
378
+ meta: factMeta("extract")
379
+ }
380
+ );
381
+ graph.add(extractOp, { name: "extract_op" });
382
+ graph.addDisposer((0, import_extra2.keepalive)(extractOp));
383
+ const invalidationDetector = (0, import_core2.node)(
384
+ [...shards],
385
+ (batchData, actions, ctx) => {
386
+ void batchData;
387
+ void ctx;
388
+ const facts = allFacts();
389
+ const index = dependentsIndex.cache;
390
+ const out2 = [];
391
+ const seen = /* @__PURE__ */ new Set();
392
+ for (const f of facts.values()) {
393
+ const obsolete = f.validTo !== void 0;
394
+ if (!obsolete) continue;
395
+ if (processedRoots.has(f.id)) continue;
396
+ const dependents = index.get(f.id) ?? [];
397
+ for (const dep of dependents) {
398
+ const depFact = facts.get(dep);
399
+ if (!depFact || depFact.validTo !== void 0) continue;
400
+ const k = `${f.id}->${dep}`;
401
+ if (seen.has(k)) continue;
402
+ seen.add(k);
403
+ out2.push({
404
+ factId: dep,
405
+ rootFactId: f.id,
406
+ reason: "obsolete",
407
+ // `obsolete` guard above guarantees `f.validTo` is set.
408
+ rootValidTo: f.validTo,
409
+ iteration: cascadeIteration + 1,
410
+ causalReason: `dependentsIndex[${f.id}] \u2192 ${dep} (obsolete: validTo set)`
411
+ });
412
+ }
413
+ processedRoots.add(f.id);
414
+ }
415
+ if (out2.length === 0) {
416
+ cascadeIteration = 0;
417
+ }
418
+ actions.emit(out2);
419
+ },
420
+ {
421
+ name: "invalidation_detector",
422
+ describeKind: "derived",
423
+ initial: [],
424
+ meta: factMeta("invalidation", { cycle: "cascade" })
425
+ }
426
+ );
427
+ graph.add(invalidationDetector, { name: "invalidation_detector" });
428
+ graph.addDisposer((0, import_extra2.keepalive)(invalidationDetector));
429
+ const cascade = (0, import_core2.node)(
430
+ [invalidationDetector],
431
+ (batchData, actions, ctx) => {
432
+ const evts = lastOf(batchData[0], ctx.prevData[0]) ?? [];
433
+ actions.emit(evts);
434
+ },
435
+ {
436
+ name: "cascade",
437
+ describeKind: "derived",
438
+ initial: [],
439
+ meta: factMeta("cascade_topic", { cycle: "cascade" })
440
+ }
441
+ );
442
+ graph.add(cascade, { name: "cascade" });
443
+ graph.addDisposer((0, import_extra2.keepalive)(cascade));
444
+ const cascadeOverflow = (0, import_core2.node)([], {
445
+ initial: null,
446
+ name: "cascade_overflow",
447
+ describeKind: "state",
448
+ meta: factMeta("cascade_overflow")
449
+ });
450
+ graph.add(cascadeOverflow, { name: "cascade_overflow" });
451
+ graph.addDisposer((0, import_extra2.keepalive)(cascadeOverflow));
452
+ const cascadeProcessor = (0, import_core2.node)(
453
+ [cascade],
454
+ (batchData, actions, ctx) => {
455
+ const evts = lastOf(batchData[0], ctx.prevData[0]) ?? [];
456
+ if (evts.length === 0) {
457
+ actions.emit([]);
458
+ return;
459
+ }
460
+ const byId = /* @__PURE__ */ new Map();
461
+ for (const e of evts) if (!byId.has(e.factId)) byId.set(e.factId, e);
462
+ cascadeIteration += 1;
463
+ if (cascadeIteration > maxIterations) {
464
+ const sample = [...byId.keys()].slice(0, OVERFLOW_SAMPLE_SIZE);
465
+ const rootFactId = evts[0]?.rootFactId ?? "";
466
+ cascadeOverflow.emit({
467
+ droppedCount: byId.size,
468
+ sample,
469
+ rootFactId
470
+ });
471
+ events.append({
472
+ action: "overflow",
473
+ reason: "cascade",
474
+ id: rootFactId,
475
+ t_ns: (0, import_core2.wallClockNs)(),
476
+ seq: bumpCursor(seqCursor)
477
+ });
478
+ actions.emit([]);
479
+ return;
480
+ }
481
+ for (const [id, e] of byId) {
482
+ replaceFragment(
483
+ id,
484
+ (prev) => prev.validTo !== void 0 ? prev : { ...prev, validTo: e.rootValidTo }
485
+ );
486
+ }
487
+ actions.emit([...byId.values()]);
488
+ },
489
+ {
490
+ name: "cascade_processor",
491
+ describeKind: "derived",
492
+ initial: [],
493
+ meta: factMeta("cascade_processor", { cycle: "cascade" })
494
+ }
495
+ );
496
+ graph.add(cascadeProcessor, { name: "cascade_processor" });
497
+ graph.addDisposer((0, import_extra2.keepalive)(cascadeProcessor));
498
+ const review = (0, import_core2.node)(
499
+ [factStore],
500
+ (batchData, actions, ctx) => {
501
+ const fs = lastOf(batchData[0], ctx.prevData[0]);
502
+ if (fs == null) {
503
+ actions.emit(null);
504
+ return;
505
+ }
506
+ for (const f of fs.byId.values()) {
507
+ if (f.confidence < reviewThreshold && f.validTo === void 0) {
508
+ actions.emit({
509
+ factId: f.id,
510
+ confidence: f.confidence,
511
+ threshold: reviewThreshold
512
+ });
513
+ return;
514
+ }
515
+ }
516
+ actions.emit(null);
517
+ },
518
+ {
519
+ name: "review",
520
+ describeKind: "derived",
521
+ initial: null,
522
+ meta: factMeta("review"),
523
+ // F10a: dedupe on the requested factId (null === no request) so a
524
+ // stable low-confidence fact does not re-emit a review every wave.
525
+ equals: (a, b) => (a?.factId ?? null) === (b?.factId ?? null)
526
+ }
527
+ );
528
+ graph.add(review, { name: "review" });
529
+ graph.addDisposer((0, import_extra2.keepalive)(review));
530
+ if (config.outcome) {
531
+ const outcomeProcessor = (0, import_core2.node)(
532
+ config.scoring ? [config.outcome, config.scoring] : [config.outcome],
533
+ (batchData, actions, ctx) => {
534
+ const sig = lastOf(batchData[0], ctx.prevData[0]);
535
+ if (sig == null) {
536
+ actions.emit(null);
537
+ return;
538
+ }
539
+ replaceFragment(sig.factId, (prev) => {
540
+ let nextConf = prev.confidence;
541
+ if (config.scoring) {
542
+ const policy2 = lastOf(batchData[1], ctx.prevData[1]);
543
+ if (policy2) {
544
+ nextConf = policy2(prev, makeReadHandle(allFacts()));
545
+ }
546
+ } else {
547
+ nextConf = Math.max(0, Math.min(1, prev.confidence + sig.reward));
548
+ }
549
+ return { ...prev, confidence: nextConf };
550
+ });
551
+ actions.emit(sig);
552
+ },
553
+ {
554
+ name: "outcome_processor",
555
+ describeKind: "derived",
556
+ initial: null,
557
+ meta: factMeta("outcome")
558
+ }
559
+ );
560
+ graph.add(outcomeProcessor, { name: "outcome_processor" });
561
+ graph.addDisposer((0, import_extra2.keepalive)(outcomeProcessor));
562
+ }
563
+ const answer = (0, import_core2.node)(
564
+ config.query ? [config.query, factStore] : [factStore],
565
+ (batchData, actions, ctx) => {
566
+ if (!config.query) {
567
+ actions.emit(null);
568
+ return;
569
+ }
570
+ const q = lastOf(batchData[0], ctx.prevData[0]);
571
+ const fs = lastOf(batchData[1], ctx.prevData[1]);
572
+ if (q == null) {
573
+ actions.emit(null);
574
+ return;
575
+ }
576
+ const store = fs ?? emptyStore();
577
+ let results = [...store.byId.values()].filter((f) => {
578
+ if (q.tags && q.tags.length > 0 && !q.tags.some((t) => f.tags.includes(t))) {
579
+ return false;
580
+ }
581
+ if (q.minConfidence !== void 0 && f.confidence < q.minConfidence) return false;
582
+ if (!currentlyValid(f, q.asOf)) return false;
583
+ return true;
584
+ });
585
+ results.sort((a, b) => b.confidence - a.confidence || Number(b.t_ns - a.t_ns));
586
+ if (q.limit !== void 0) results = results.slice(0, Math.max(0, q.limit));
587
+ actions.emit({ query: q, results });
588
+ },
589
+ {
590
+ name: "answer",
591
+ describeKind: "derived",
592
+ initial: null,
593
+ meta: factMeta("query", { role: "output" })
594
+ }
595
+ );
596
+ graph.add(answer, { name: "answer" });
597
+ graph.addDisposer((0, import_extra2.keepalive)(answer));
598
+ const consolidated = (0, import_core2.node)(
599
+ config.consolidateTrigger ? [config.consolidateTrigger] : [],
600
+ (batchData, actions, ctx) => {
601
+ void batchData;
602
+ void ctx;
603
+ if (!config.consolidateTrigger || !config.consolidate) {
604
+ actions.emit([]);
605
+ return;
606
+ }
607
+ const fragments = config.consolidate(makeReadHandle(allFacts()));
608
+ for (const f of fragments) {
609
+ const deps = config.extractDependencies(f);
610
+ processedRoots.delete(f.id);
611
+ commitFragment(f);
612
+ indexFragment(f, deps);
613
+ events.append({
614
+ action: "consolidate",
615
+ id: f.id,
616
+ t_ns: (0, import_core2.wallClockNs)(),
617
+ seq: bumpCursor(seqCursor)
618
+ });
619
+ }
620
+ actions.emit(fragments);
621
+ },
622
+ {
623
+ name: "consolidated",
624
+ describeKind: "derived",
625
+ initial: [],
626
+ meta: factMeta("consolidator")
627
+ }
628
+ );
629
+ graph.add(consolidated, { name: "consolidated" });
630
+ graph.addDisposer((0, import_extra2.keepalive)(consolidated));
631
+ const ingestAudit = (0, import_core2.node)(
632
+ [extractOp],
633
+ (batchData, actions, ctx) => {
634
+ const f = lastOf(batchData[0], ctx.prevData[0]);
635
+ if (f != null) {
636
+ events.append({
637
+ action: "ingest",
638
+ id: f.id,
639
+ t_ns: (0, import_core2.wallClockNs)(),
640
+ seq: bumpCursor(seqCursor)
641
+ });
642
+ ingestLog?.append(f);
643
+ }
644
+ actions.emit(f ?? null);
645
+ },
646
+ {
647
+ name: "_ingest_audit",
648
+ describeKind: "derived",
649
+ initial: null,
650
+ meta: factMeta("audit")
651
+ }
652
+ );
653
+ graph.add(ingestAudit, { name: "_ingest_audit" });
654
+ graph.addDisposer((0, import_extra2.keepalive)(ingestAudit));
655
+ function itemNode(id) {
656
+ return (0, import_core2.node)(
657
+ [factStore],
658
+ (batchData, actions, ctx) => {
659
+ const fs = lastOf(batchData[0], ctx.prevData[0]);
660
+ actions.emit(fs?.byId.get(id));
661
+ },
662
+ {
663
+ name: `item_${id}`,
664
+ describeKind: "derived",
665
+ meta: factMeta("item")
666
+ }
667
+ );
668
+ }
669
+ const out = Object.assign(graph, {
670
+ shards,
671
+ factStore,
672
+ dependentsIndex,
673
+ answer,
674
+ cascade,
675
+ cascadeOverflow,
676
+ review,
677
+ consolidated,
678
+ events,
679
+ ...ingestLog ? { ingestLog } : {},
680
+ itemNode
681
+ });
682
+ return out;
683
+ }
684
+
685
+ // src/utils/memory/index.ts
686
+ var NS_PER_SEC = 1e9;
687
+ function memoryMeta(kind, extra) {
688
+ return domainMeta("memory", kind, extra);
689
+ }
690
+ function toNode(v, name) {
691
+ if (v instanceof import_core3.NodeImpl) return v;
692
+ return (0, import_core3.node)([], { initial: v, ...name ? { name } : void 0 });
693
+ }
694
+ function ageSeconds(now, lastNs) {
695
+ return (now - lastNs) / NS_PER_SEC;
696
+ }
697
+ function cosineSimilarity(a, b) {
698
+ const n = Math.max(a.length, b.length);
699
+ let dot = 0;
700
+ let na = 0;
701
+ let nb = 0;
702
+ for (let i = 0; i < n; i += 1) {
703
+ const av = a[i] ?? 0;
704
+ const bv = b[i] ?? 0;
705
+ dot += av * bv;
706
+ na += av * av;
707
+ nb += bv * bv;
708
+ }
709
+ if (na === 0 || nb === 0) return 0;
710
+ const score = dot / Math.sqrt(na * nb);
711
+ return Number.isFinite(score) ? score : 0;
712
+ }
713
+ function searchResultsEqual(a, b) {
714
+ if (a === b) return true;
715
+ if (a == null || b == null) return false;
716
+ if (a.length !== b.length) return false;
717
+ for (let i = 0; i < a.length; i += 1) {
718
+ const x = a[i];
719
+ const y = b[i];
720
+ if (x.id !== y.id || x.score !== y.score || x.meta !== y.meta) return false;
721
+ }
722
+ return true;
723
+ }
724
+ function rankedEqual(a, b) {
725
+ if (a === b) return true;
726
+ if (a == null || b == null) return false;
727
+ if (a.length !== b.length) return false;
728
+ for (let i = 0; i < a.length; i += 1) {
729
+ const x = a[i];
730
+ const y = b[i];
731
+ if (x.id !== y.id || x.score !== y.score || x.lastAccessNs !== y.lastAccessNs || x.value !== y.value)
732
+ return false;
733
+ }
734
+ return true;
735
+ }
736
+ function collection(name, opts = {}) {
737
+ const maxSize = opts.maxSize;
738
+ const ranked = opts.ranked ?? true;
739
+ const decayRate = ranked ? opts.decayRate ?? 0 : 0;
740
+ const minScore = opts.minScore ?? 0;
741
+ if (maxSize !== void 0 && maxSize < 1) {
742
+ throw new RangeError("collection: maxSize must be >= 1");
743
+ }
744
+ const scoreFnDefault = () => ranked ? 1 : 0;
745
+ const scoreInput = opts.score ?? scoreFnDefault;
746
+ const scoreNode = ranked && scoreInput instanceof import_core3.NodeImpl ? scoreInput : void 0;
747
+ const readScoreFn = () => {
748
+ if (scoreNode) return scoreNode.cache ?? scoreFnDefault;
749
+ return scoreInput;
750
+ };
751
+ const graph = new import_graph3.Graph(name);
752
+ const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0, import_core3.monotonicNs)(), v.lastAccessNs), decayRate, minScore) : v.lastAccessNs;
753
+ const items = (0, import_extra3.reactiveMap)({
754
+ name: "items",
755
+ ...maxSize !== void 0 ? { retention: { score: retentionScore, maxSize } } : {}
756
+ });
757
+ graph.add(items.entries, { name: "items" });
758
+ let refreshTick;
759
+ if (ranked && decayRate > 0) {
760
+ const intervalMs = opts.refreshIntervalMs ?? Math.max(1, 1e3 * Math.LN2 / (10 * decayRate));
761
+ const tickCounter = (0, import_extra3.fromTimer)(intervalMs, { period: intervalMs });
762
+ refreshTick = (0, import_core3.node)(
763
+ [tickCounter],
764
+ (_batchData, actions) => {
765
+ actions.emit((0, import_core3.monotonicNs)());
766
+ },
767
+ {
768
+ name: "refresh_tick_ns",
769
+ describeKind: "derived",
770
+ initial: (0, import_core3.monotonicNs)(),
771
+ meta: memoryMeta("clock")
772
+ }
773
+ );
774
+ graph.add(refreshTick, { name: "refresh_tick_ns" });
775
+ }
776
+ let rankedNode;
777
+ if (ranked) {
778
+ const rankedDeps = [items.entries];
779
+ if (refreshTick) rankedDeps.push(refreshTick);
780
+ if (scoreNode) rankedDeps.push(scoreNode);
781
+ rankedNode = (0, import_core3.node)(
782
+ rankedDeps,
783
+ (batchData, actions, ctx) => {
784
+ const values = batchData.map(
785
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
786
+ );
787
+ const snapshot = values[0];
788
+ let now;
789
+ if (refreshTick) {
790
+ const tickValue = values[1];
791
+ now = typeof tickValue === "number" ? tickValue : (0, import_core3.monotonicNs)();
792
+ } else {
793
+ now = (0, import_core3.monotonicNs)();
794
+ }
795
+ if (!snapshot || snapshot.size === 0) {
796
+ actions.emit([]);
797
+ return;
798
+ }
799
+ const out2 = [];
800
+ for (const entry of snapshot.values()) {
801
+ out2.push({
802
+ ...entry,
803
+ score: decay(entry.baseScore, ageSeconds(now, entry.lastAccessNs), decayRate, minScore)
804
+ });
805
+ }
806
+ out2.sort((a, b) => b.score - a.score || b.lastAccessNs - a.lastAccessNs);
807
+ actions.emit(out2);
808
+ },
809
+ {
810
+ name: "ranked",
811
+ describeKind: "derived",
812
+ equals: rankedEqual,
813
+ meta: memoryMeta("ranked")
814
+ }
815
+ );
816
+ graph.add(rankedNode, { name: "ranked" });
817
+ } else {
818
+ rankedNode = (0, import_core3.node)([], {
819
+ initial: [],
820
+ name: "ranked",
821
+ describeKind: "state",
822
+ meta: memoryMeta("ranked_disabled")
823
+ });
824
+ graph.add(rankedNode, { name: "ranked" });
825
+ }
826
+ const size = (0, import_core3.node)(
827
+ [items.entries],
828
+ (batchData, actions, ctx) => {
829
+ const data = batchData.map(
830
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
831
+ );
832
+ const snapshot = data[0];
833
+ actions.emit((snapshot ?? /* @__PURE__ */ new Map()).size);
834
+ },
835
+ {
836
+ name: "size",
837
+ describeKind: "derived",
838
+ initial: 0,
839
+ meta: memoryMeta("size")
840
+ }
841
+ );
842
+ graph.add(size, { name: "size" });
843
+ graph.addDisposer((0, import_extra3.keepalive)(size));
844
+ const events = createAuditLog({
845
+ name: "events",
846
+ retainedLimit: 1024,
847
+ graph
848
+ });
849
+ const seqCursor = registerCursor(graph, "seq", 0);
850
+ const upsertImpl = (id, value, _opts) => {
851
+ const now = (0, import_core3.monotonicNs)();
852
+ const prev = items.get(id);
853
+ const baseScore = _opts?.score ?? readScoreFn()(value);
854
+ items.set(id, {
855
+ id,
856
+ value,
857
+ baseScore,
858
+ createdAtNs: prev?.createdAtNs ?? now,
859
+ lastAccessNs: now
860
+ });
861
+ };
862
+ const removeImpl = (id) => {
863
+ if (!items.has(id)) return;
864
+ items.delete(id);
865
+ };
866
+ const clearImpl = () => {
867
+ if (items.size === 0) return;
868
+ items.clear();
869
+ };
870
+ const rescoreImpl = () => {
871
+ if (!ranked) return;
872
+ const fn = readScoreFn();
873
+ const snapshot = items.entries.cache;
874
+ if (!snapshot || snapshot.size === 0) return;
875
+ const updates = [];
876
+ for (const entry of snapshot.values()) {
877
+ updates.push([entry.id, { ...entry, baseScore: fn(entry.value) }]);
878
+ }
879
+ items.setMany(updates);
880
+ };
881
+ const upsert = mutate(upsertImpl, {
882
+ frame: "inline",
883
+ log: events,
884
+ seq: seqCursor,
885
+ onSuccessRecord: ([id], _r, m) => ({ action: "upsert", id, t_ns: m.t_ns, seq: m.seq })
886
+ });
887
+ const remove = mutate(removeImpl, {
888
+ frame: "inline",
889
+ log: events,
890
+ seq: seqCursor,
891
+ onSuccessRecord: ([id], _r, m) => ({ action: "remove", id, t_ns: m.t_ns, seq: m.seq })
892
+ });
893
+ const clear = mutate(clearImpl, {
894
+ frame: "inline",
895
+ log: events,
896
+ seq: seqCursor,
897
+ onSuccessRecord: (_args, _r, m) => ({ action: "clear", t_ns: m.t_ns, seq: m.seq })
898
+ });
899
+ const rescore = mutate(rescoreImpl, {
900
+ frame: "inline",
901
+ log: events,
902
+ seq: seqCursor,
903
+ onSuccessRecord: (_args, _r, m) => ({ action: "rescore", t_ns: m.t_ns, seq: m.seq })
904
+ });
905
+ function itemNode(id) {
906
+ const idN = toNode(id, "id");
907
+ return (0, import_core3.node)(
908
+ [items.entries, idN],
909
+ (batchData, actions, ctx) => {
910
+ const data = batchData.map(
911
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
912
+ );
913
+ const map = data[0];
914
+ const key = data[1];
915
+ actions.emit(map?.get(key));
916
+ },
917
+ {
918
+ describeKind: "derived",
919
+ meta: memoryMeta("collection_item")
920
+ }
921
+ );
922
+ }
923
+ function hasNode(id) {
924
+ const idN = toNode(id, "id");
925
+ return (0, import_core3.node)(
926
+ [items.entries, idN],
927
+ (batchData, actions, ctx) => {
928
+ const data = batchData.map(
929
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
930
+ );
931
+ const map = data[0];
932
+ const key = data[1];
933
+ actions.emit(map?.has(key) ?? false);
934
+ },
935
+ {
936
+ describeKind: "derived",
937
+ meta: memoryMeta("collection_has")
938
+ }
939
+ );
940
+ }
941
+ const out = Object.assign(graph, {
942
+ events,
943
+ items: items.entries,
944
+ ranked: rankedNode,
945
+ size,
946
+ upsert,
947
+ remove,
948
+ clear,
949
+ rescore,
950
+ itemNode,
951
+ hasNode
952
+ });
953
+ return out;
954
+ }
955
+ function vectorIndex(opts = {}) {
956
+ const backend = opts.backend ?? "flat";
957
+ const dimension = opts.dimension;
958
+ const strictDimension = opts.strictDimension ?? true;
959
+ const maxSize = opts.maxSize;
960
+ const userRetentionScore = opts.retentionScore;
961
+ let hnsw;
962
+ if (backend === "hnsw") {
963
+ hnsw = opts.hnswFactory?.();
964
+ if (!hnsw) {
965
+ throw new Error(
966
+ 'vectorIndex backend "hnsw" requires an optional dependency adapter; install your HNSW package and provide `hnswFactory`.'
967
+ );
968
+ }
969
+ }
970
+ const graph = new import_graph3.Graph(opts.name ?? "vector_index");
971
+ let inferredDimension;
972
+ function assertDimension(vector) {
973
+ if (dimension !== void 0) {
974
+ if (vector.length !== dimension) {
975
+ throw new RangeError(
976
+ `vector dimension mismatch: expected ${dimension}, got ${vector.length}`
977
+ );
978
+ }
979
+ return;
980
+ }
981
+ if (!strictDimension) return;
982
+ if (inferredDimension === void 0) {
983
+ inferredDimension = vector.length;
984
+ return;
985
+ }
986
+ if (vector.length !== inferredDimension) {
987
+ throw new RangeError(
988
+ `vector dimension mismatch: inferred ${inferredDimension} from first upsert, got ${vector.length}. Pass \`strictDimension: false\` to opt into zero-pad behavior, or set an explicit \`dimension\`.`
989
+ );
990
+ }
991
+ }
992
+ const baseRetentionScore = userRetentionScore ?? ((r) => r.upsertedAtNs);
993
+ let clearInProgress = false;
994
+ const events = createAuditLog({
995
+ name: "events",
996
+ retainedLimit: 1024,
997
+ graph
998
+ });
999
+ const seqCursor = registerCursor(graph, "seq", 0);
1000
+ const entries = (0, import_extra3.reactiveMap)({
1001
+ name: "entries",
1002
+ ...maxSize !== void 0 ? {
1003
+ retention: {
1004
+ score: (_k, v) => baseRetentionScore(v),
1005
+ maxSize,
1006
+ onArchive: (key) => {
1007
+ if (clearInProgress) return;
1008
+ if (backend === "hnsw") hnsw.remove(key);
1009
+ events.append({
1010
+ action: "evict",
1011
+ id: key,
1012
+ t_ns: (0, import_core3.wallClockNs)(),
1013
+ seq: bumpCursor(seqCursor)
1014
+ });
1015
+ }
1016
+ }
1017
+ } : {}
1018
+ });
1019
+ graph.add(entries.entries, { name: "entries" });
1020
+ graph.addDisposer((0, import_extra3.keepalive)(entries.entries));
1021
+ if (hnsw?.dispose) {
1022
+ const disposeAdapter = hnsw.dispose.bind(hnsw);
1023
+ graph.addDisposer(() => disposeAdapter());
1024
+ }
1025
+ const upsertImpl = (id, vector, meta) => {
1026
+ assertDimension(vector);
1027
+ if (backend === "hnsw") hnsw.upsert(id, vector, meta);
1028
+ const copiedMeta = (() => {
1029
+ if (meta === void 0) return void 0;
1030
+ if (meta === null || typeof meta !== "object") return meta;
1031
+ return Array.isArray(meta) ? [...meta] : { ...meta };
1032
+ })();
1033
+ const record = {
1034
+ id,
1035
+ vector: [...vector],
1036
+ ...copiedMeta !== void 0 ? { meta: copiedMeta } : {},
1037
+ upsertedAtNs: (0, import_core3.monotonicNs)()
1038
+ };
1039
+ entries.set(id, record);
1040
+ };
1041
+ const removeImpl = (id) => {
1042
+ if (!entries.has(id)) return;
1043
+ if (backend === "hnsw") hnsw.remove(id);
1044
+ entries.delete(id);
1045
+ };
1046
+ const clearImpl = () => {
1047
+ if (entries.size === 0) return;
1048
+ clearInProgress = true;
1049
+ try {
1050
+ entries.clear();
1051
+ if (backend === "hnsw") hnsw.clear();
1052
+ } finally {
1053
+ clearInProgress = false;
1054
+ }
1055
+ inferredDimension = void 0;
1056
+ };
1057
+ const reindexImpl = () => {
1058
+ if (backend !== "hnsw") return;
1059
+ const snapshot = entries.entries.cache;
1060
+ if (!snapshot) return;
1061
+ hnsw.clear();
1062
+ for (const r of snapshot.values()) {
1063
+ hnsw.upsert(r.id, r.vector, r.meta);
1064
+ }
1065
+ };
1066
+ const upsert = mutate(upsertImpl, {
1067
+ frame: "inline",
1068
+ log: events,
1069
+ freeze: false,
1070
+ seq: seqCursor,
1071
+ onSuccessRecord: ([id], _r, m) => ({ action: "upsert", id, t_ns: m.t_ns, seq: m.seq })
1072
+ });
1073
+ const remove = mutate(removeImpl, {
1074
+ frame: "inline",
1075
+ log: events,
1076
+ seq: seqCursor,
1077
+ onSuccessRecord: ([id], _r, m) => ({ action: "remove", id, t_ns: m.t_ns, seq: m.seq })
1078
+ });
1079
+ const clear = mutate(clearImpl, {
1080
+ frame: "inline",
1081
+ log: events,
1082
+ seq: seqCursor,
1083
+ onSuccessRecord: (_args, _r, m) => ({ action: "clear", t_ns: m.t_ns, seq: m.seq })
1084
+ });
1085
+ const reindex = mutate(reindexImpl, {
1086
+ frame: "inline",
1087
+ log: events,
1088
+ seq: seqCursor,
1089
+ onSuccessRecord: (_args, _r, m) => ({ action: "reindex", t_ns: m.t_ns, seq: m.seq })
1090
+ });
1091
+ function searchNode(query, k = 5) {
1092
+ const kN = toNode(k, "k");
1093
+ return (0, import_core3.node)(
1094
+ [entries.entries, query, kN],
1095
+ (batchData, actions, ctx) => {
1096
+ const values = batchData.map(
1097
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1098
+ );
1099
+ const snapshot = values[0];
1100
+ const q = values[1];
1101
+ const kRaw = values[2];
1102
+ const kVal = Number.isFinite(kRaw) ? Math.max(0, Math.floor(kRaw)) : 0;
1103
+ if (!snapshot || snapshot.size === 0 || kVal <= 0) {
1104
+ actions.emit([]);
1105
+ return;
1106
+ }
1107
+ if (q == null || q.length === 0) {
1108
+ actions.emit([]);
1109
+ return;
1110
+ }
1111
+ const expectedDim = dimension ?? (strictDimension ? inferredDimension : void 0);
1112
+ if (expectedDim !== void 0 && q.length !== expectedDim) {
1113
+ actions.emit([]);
1114
+ return;
1115
+ }
1116
+ if (backend === "hnsw") {
1117
+ const adapterResults = hnsw.search(q, kVal);
1118
+ actions.emit([...adapterResults]);
1119
+ return;
1120
+ }
1121
+ const ranked = [...snapshot.values()].map((row) => {
1122
+ const result = {
1123
+ id: row.id,
1124
+ score: cosineSimilarity(q, row.vector),
1125
+ ...row.meta !== void 0 ? { meta: row.meta } : {}
1126
+ };
1127
+ return result;
1128
+ }).sort((a, b) => b.score - a.score).slice(0, kVal);
1129
+ actions.emit(ranked);
1130
+ },
1131
+ {
1132
+ describeKind: "derived",
1133
+ // A1: include `score` in equality. The previous id-only
1134
+ // comparator suppressed re-emissions when the same set of
1135
+ // IDs/order had different scores (re-upsert with new
1136
+ // vector; query change preserving ranking order).
1137
+ equals: (a, b) => searchResultsEqual(a, b),
1138
+ meta: memoryMeta("vector_search")
1139
+ }
1140
+ );
1141
+ }
1142
+ const out = Object.assign(graph, {
1143
+ backend,
1144
+ events,
1145
+ entries: entries.entries,
1146
+ upsert,
1147
+ remove,
1148
+ clear,
1149
+ reindex,
1150
+ searchNode
1151
+ });
1152
+ return out;
1153
+ }
1154
+ var TRIPLE_SEP = "\0";
1155
+ function tripleKey(from, to, relation) {
1156
+ return `${from}${TRIPLE_SEP}${to}${TRIPLE_SEP}${relation}`;
1157
+ }
1158
+ function buildAdjacency(edges, side) {
1159
+ if (!edges || edges.size === 0) return /* @__PURE__ */ new Map();
1160
+ const buckets = /* @__PURE__ */ new Map();
1161
+ for (const edge of edges.values()) {
1162
+ const key = side === "from" ? edge.from : edge.to;
1163
+ let bucket = buckets.get(key);
1164
+ if (!bucket) {
1165
+ bucket = [];
1166
+ buckets.set(key, bucket);
1167
+ }
1168
+ bucket.push(edge);
1169
+ }
1170
+ const out = /* @__PURE__ */ new Map();
1171
+ for (const [key, bucket] of buckets) out.set(key, Object.freeze(bucket));
1172
+ return out;
1173
+ }
1174
+ function adjacencyEqual(a, b) {
1175
+ if (a === b) return true;
1176
+ if (a == null || b == null) return false;
1177
+ if (a.size !== b.size) return false;
1178
+ for (const [k, av] of a) {
1179
+ const bv = b.get(k);
1180
+ if (!bv || av.length !== bv.length) return false;
1181
+ for (let i = 0; i < av.length; i += 1) {
1182
+ const ae = av[i];
1183
+ const be = bv[i];
1184
+ if (ae.from !== be.from || ae.to !== be.to || ae.relation !== be.relation || ae.weight !== be.weight)
1185
+ return false;
1186
+ }
1187
+ }
1188
+ return true;
1189
+ }
1190
+ function knowledgeGraph(name, opts = {}) {
1191
+ const orphanGC = opts.orphanGC ?? "keep";
1192
+ if (opts.entitiesMaxSize !== void 0 && opts.entitiesMaxSize < 1) {
1193
+ throw new RangeError("knowledgeGraph: entitiesMaxSize must be >= 1");
1194
+ }
1195
+ if (opts.edgesMaxSize !== void 0 && opts.edgesMaxSize < 1) {
1196
+ throw new RangeError("knowledgeGraph: edgesMaxSize must be >= 1");
1197
+ }
1198
+ const graph = new import_graph3.Graph(name);
1199
+ const entitiesMap = (0, import_extra3.reactiveMap)({
1200
+ name: "entities",
1201
+ ...opts.entitiesMaxSize !== void 0 ? { maxSize: opts.entitiesMaxSize } : {}
1202
+ });
1203
+ const edgesMap = (0, import_extra3.reactiveMap)({
1204
+ name: "edges",
1205
+ ...opts.edgesMaxSize !== void 0 ? { maxSize: opts.edgesMaxSize } : {}
1206
+ });
1207
+ graph.add(entitiesMap.entries, { name: "entities" });
1208
+ graph.add(edgesMap.entries, { name: "edges" });
1209
+ const adjacencyOut = (0, import_core3.node)(
1210
+ [edgesMap.entries],
1211
+ (batchData, actions, ctx) => {
1212
+ const data = batchData.map(
1213
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1214
+ );
1215
+ const snapshot = data[0];
1216
+ actions.emit(buildAdjacency(snapshot, "from"));
1217
+ },
1218
+ {
1219
+ name: "adjacencyOut",
1220
+ describeKind: "derived",
1221
+ initial: /* @__PURE__ */ new Map(),
1222
+ equals: adjacencyEqual,
1223
+ meta: memoryMeta("adjacency_out")
1224
+ }
1225
+ );
1226
+ const adjacencyIn = (0, import_core3.node)(
1227
+ [edgesMap.entries],
1228
+ (batchData, actions, ctx) => {
1229
+ const data = batchData.map(
1230
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1231
+ );
1232
+ const snapshot = data[0];
1233
+ actions.emit(buildAdjacency(snapshot, "to"));
1234
+ },
1235
+ {
1236
+ name: "adjacencyIn",
1237
+ describeKind: "derived",
1238
+ initial: /* @__PURE__ */ new Map(),
1239
+ equals: adjacencyEqual,
1240
+ meta: memoryMeta("adjacency_in")
1241
+ }
1242
+ );
1243
+ graph.add(adjacencyOut, { name: "adjacencyOut" });
1244
+ graph.add(adjacencyIn, { name: "adjacencyIn" });
1245
+ graph.addDisposer((0, import_extra3.keepalive)(adjacencyOut));
1246
+ graph.addDisposer((0, import_extra3.keepalive)(adjacencyIn));
1247
+ const entityCount = (0, import_core3.node)(
1248
+ [entitiesMap.entries],
1249
+ (batchData, actions, ctx) => {
1250
+ const data = batchData.map(
1251
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1252
+ );
1253
+ const m = data[0];
1254
+ actions.emit((m ?? /* @__PURE__ */ new Map()).size);
1255
+ },
1256
+ { name: "entityCount", describeKind: "derived", initial: 0, meta: memoryMeta("entity_count") }
1257
+ );
1258
+ const edgeCount = (0, import_core3.node)(
1259
+ [edgesMap.entries],
1260
+ (batchData, actions, ctx) => {
1261
+ const data = batchData.map(
1262
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1263
+ );
1264
+ const m = data[0];
1265
+ actions.emit((m ?? /* @__PURE__ */ new Map()).size);
1266
+ },
1267
+ { name: "edgeCount", describeKind: "derived", initial: 0, meta: memoryMeta("edge_count") }
1268
+ );
1269
+ graph.add(entityCount, { name: "entityCount" });
1270
+ graph.add(edgeCount, { name: "edgeCount" });
1271
+ graph.addDisposer((0, import_extra3.keepalive)(entityCount));
1272
+ graph.addDisposer((0, import_extra3.keepalive)(edgeCount));
1273
+ const events = createAuditLog({
1274
+ name: "events",
1275
+ retainedLimit: 1024,
1276
+ graph
1277
+ });
1278
+ const seqCursor = registerCursor(graph, "seq", 0);
1279
+ function entityHasReferences(id) {
1280
+ const out2 = adjacencyOut.cache;
1281
+ const inb = adjacencyIn.cache;
1282
+ if ((out2?.get(id)?.length ?? 0) > 0) return true;
1283
+ if ((inb?.get(id)?.length ?? 0) > 0) return true;
1284
+ return false;
1285
+ }
1286
+ function applyOrphanGC(candidates) {
1287
+ if (orphanGC !== "remove") return;
1288
+ for (const candidate of candidates) {
1289
+ if (!entitiesMap.has(candidate)) continue;
1290
+ if (entityHasReferences(candidate)) continue;
1291
+ entitiesMap.delete(candidate);
1292
+ events.append({
1293
+ action: "orphanRemove",
1294
+ id: candidate,
1295
+ t_ns: (0, import_core3.wallClockNs)(),
1296
+ seq: bumpCursor(seqCursor)
1297
+ });
1298
+ }
1299
+ }
1300
+ const upsertEntityImpl = (id, value) => {
1301
+ entitiesMap.set(id, value);
1302
+ };
1303
+ const removeEntityImpl = (id) => {
1304
+ const snapshot = edgesMap.entries.cache;
1305
+ const cascadedNeighbors = /* @__PURE__ */ new Set();
1306
+ if (snapshot) {
1307
+ const toDrop = [];
1308
+ for (const [key, edge] of snapshot) {
1309
+ if (edge.from === id || edge.to === id) {
1310
+ toDrop.push(key);
1311
+ if (edge.from !== id) cascadedNeighbors.add(edge.from);
1312
+ if (edge.to !== id) cascadedNeighbors.add(edge.to);
1313
+ }
1314
+ }
1315
+ if (toDrop.length > 0) edgesMap.deleteMany(toDrop);
1316
+ }
1317
+ if (entitiesMap.has(id)) entitiesMap.delete(id);
1318
+ applyOrphanGC([...cascadedNeighbors]);
1319
+ };
1320
+ const linkImpl = (from, to, relation, weight = 1) => {
1321
+ edgesMap.set(tripleKey(from, to, relation), { from, to, relation, weight });
1322
+ };
1323
+ const unlinkImpl = (from, to, relation) => {
1324
+ if (relation !== void 0) {
1325
+ edgesMap.delete(tripleKey(from, to, relation));
1326
+ } else {
1327
+ const snapshot = edgesMap.entries.cache;
1328
+ if (!snapshot) return;
1329
+ const toDrop = [];
1330
+ for (const [key, edge] of snapshot) {
1331
+ if (edge.from === from && edge.to === to) toDrop.push(key);
1332
+ }
1333
+ if (toDrop.length > 0) edgesMap.deleteMany(toDrop);
1334
+ }
1335
+ applyOrphanGC([from, to]);
1336
+ };
1337
+ const upsertEntity = mutate(upsertEntityImpl, {
1338
+ frame: "inline",
1339
+ log: events,
1340
+ seq: seqCursor,
1341
+ onSuccessRecord: ([id], _r, m) => ({
1342
+ action: "upsertEntity",
1343
+ id,
1344
+ t_ns: m.t_ns,
1345
+ seq: m.seq
1346
+ })
1347
+ });
1348
+ const removeEntity = mutate(removeEntityImpl, {
1349
+ frame: "inline",
1350
+ log: events,
1351
+ seq: seqCursor,
1352
+ onSuccessRecord: ([id], _r, m) => ({
1353
+ action: "removeEntity",
1354
+ id,
1355
+ t_ns: m.t_ns,
1356
+ seq: m.seq
1357
+ })
1358
+ });
1359
+ const link = mutate(linkImpl, {
1360
+ frame: "inline",
1361
+ log: events,
1362
+ seq: seqCursor,
1363
+ onSuccessRecord: ([from, to, relation, weight], _r, m) => ({
1364
+ action: "link",
1365
+ from,
1366
+ to,
1367
+ relation,
1368
+ weight: weight ?? 1,
1369
+ t_ns: m.t_ns,
1370
+ seq: m.seq
1371
+ })
1372
+ });
1373
+ const unlink = mutate(unlinkImpl, {
1374
+ frame: "inline",
1375
+ log: events,
1376
+ seq: seqCursor,
1377
+ onSuccessRecord: ([from, to, relation], _r, m) => ({
1378
+ action: "unlink",
1379
+ from,
1380
+ to,
1381
+ ...relation !== void 0 ? { relation } : {},
1382
+ t_ns: m.t_ns,
1383
+ seq: m.seq
1384
+ })
1385
+ });
1386
+ function relatedNode(id, relation) {
1387
+ const idN = toNode(id, "id");
1388
+ const relN = relation !== void 0 ? toNode(relation, "relation") : void 0;
1389
+ const deps = relN ? [adjacencyOut, adjacencyIn, idN, relN] : [adjacencyOut, adjacencyIn, idN];
1390
+ return (0, import_core3.node)(
1391
+ deps,
1392
+ (batchData, actions, ctx) => {
1393
+ const values = batchData.map(
1394
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1395
+ );
1396
+ const out2 = values[0];
1397
+ const inb = values[1];
1398
+ const key = values[2];
1399
+ const rel = relN ? values[3] : void 0;
1400
+ const outE = out2?.get(key) ?? [];
1401
+ const inE = inb?.get(key) ?? [];
1402
+ const seen = /* @__PURE__ */ new Set();
1403
+ const acc = [];
1404
+ for (const edge of outE) {
1405
+ const k = tripleKey(edge.from, edge.to, edge.relation);
1406
+ if (seen.has(k)) continue;
1407
+ if (rel !== void 0 && edge.relation !== rel) continue;
1408
+ seen.add(k);
1409
+ acc.push(edge);
1410
+ }
1411
+ for (const edge of inE) {
1412
+ const k = tripleKey(edge.from, edge.to, edge.relation);
1413
+ if (seen.has(k)) continue;
1414
+ if (rel !== void 0 && edge.relation !== rel) continue;
1415
+ seen.add(k);
1416
+ acc.push(edge);
1417
+ }
1418
+ actions.emit(acc);
1419
+ },
1420
+ {
1421
+ describeKind: "derived",
1422
+ equals: (a, b) => {
1423
+ const av = a;
1424
+ const bv = b;
1425
+ if (av === bv) return true;
1426
+ if (av == null || bv == null) return false;
1427
+ if (av.length !== bv.length) return false;
1428
+ for (let i = 0; i < av.length; i += 1) {
1429
+ const x = av[i];
1430
+ const y = bv[i];
1431
+ if (x.from !== y.from || x.to !== y.to || x.relation !== y.relation || x.weight !== y.weight)
1432
+ return false;
1433
+ }
1434
+ return true;
1435
+ },
1436
+ meta: memoryMeta("related")
1437
+ }
1438
+ );
1439
+ }
1440
+ const out = Object.assign(graph, {
1441
+ events,
1442
+ entities: entitiesMap.entries,
1443
+ edges: edgesMap.entries,
1444
+ adjacencyOut,
1445
+ adjacencyIn,
1446
+ entityCount,
1447
+ edgeCount,
1448
+ upsertEntity,
1449
+ removeEntity,
1450
+ link,
1451
+ unlink,
1452
+ relatedNode
1453
+ });
1454
+ return out;
1455
+ }
1456
+ //# sourceMappingURL=index.cjs.map