@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.
- package/README.md +1 -2
- package/dist/_internal-B23BagFd.d.cts +33 -0
- package/dist/_internal-B23BagFd.d.ts +33 -0
- package/dist/adaptive-rate-limiter-Dch_xYIi.d.cts +111 -0
- package/dist/adaptive-rate-limiter-Dch_xYIi.d.ts +111 -0
- package/dist/agents-C0Ji9ldU.d.cts +629 -0
- package/dist/agents-C9zexT7I.d.ts +629 -0
- package/dist/audit-BAXb3VOg.d.ts +246 -0
- package/dist/audit-C_bPfkqS.d.cts +246 -0
- package/dist/backoff-7KIK3WQW.js +24 -0
- package/dist/backoff-7KIK3WQW.js.map +1 -0
- package/dist/backoff-Bnb9OoPh.d.cts +6 -0
- package/dist/backoff-Bnb9OoPh.d.ts +6 -0
- package/dist/base/composition/index.cjs +865 -0
- package/dist/base/composition/index.cjs.map +1 -0
- package/dist/base/composition/index.d.cts +468 -0
- package/dist/base/composition/index.d.ts +468 -0
- package/dist/base/composition/index.js +40 -0
- package/dist/base/composition/index.js.map +1 -0
- package/dist/base/index.cjs +6390 -0
- package/dist/base/index.cjs.map +1 -0
- package/dist/base/index.d.cts +21 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +259 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/io/index.cjs +3270 -0
- package/dist/base/io/index.cjs.map +1 -0
- package/dist/base/io/index.d.cts +2245 -0
- package/dist/base/io/index.d.ts +2245 -0
- package/dist/base/io/index.js +117 -0
- package/dist/base/io/index.js.map +1 -0
- package/dist/base/meta/index.cjs +43 -0
- package/dist/base/meta/index.cjs.map +1 -0
- package/dist/base/meta/index.d.cts +45 -0
- package/dist/base/meta/index.d.ts +45 -0
- package/dist/base/meta/index.js +13 -0
- package/dist/base/meta/index.js.map +1 -0
- package/dist/base/mutation/index.cjs +200 -0
- package/dist/base/mutation/index.cjs.map +1 -0
- package/dist/base/mutation/index.d.cts +177 -0
- package/dist/base/mutation/index.d.ts +177 -0
- package/dist/base/mutation/index.js +22 -0
- package/dist/base/mutation/index.js.map +1 -0
- package/dist/base/render/index.cjs +1120 -0
- package/dist/base/render/index.cjs.map +1 -0
- package/dist/base/render/index.d.cts +227 -0
- package/dist/base/render/index.d.ts +227 -0
- package/dist/base/render/index.js +24 -0
- package/dist/base/render/index.js.map +1 -0
- package/dist/base/sources/browser/index.cjs +172 -0
- package/dist/base/sources/browser/index.cjs.map +1 -0
- package/dist/base/sources/browser/index.d.cts +84 -0
- package/dist/base/sources/browser/index.d.ts +84 -0
- package/dist/base/sources/browser/index.js +151 -0
- package/dist/base/sources/browser/index.js.map +1 -0
- package/dist/base/sources/event/index.cjs +98 -0
- package/dist/base/sources/event/index.cjs.map +1 -0
- package/dist/base/sources/event/index.d.cts +91 -0
- package/dist/base/sources/event/index.d.ts +91 -0
- package/dist/base/sources/event/index.js +13 -0
- package/dist/base/sources/event/index.js.map +1 -0
- package/dist/base/sources/index.cjs +755 -0
- package/dist/base/sources/index.cjs.map +1 -0
- package/dist/base/sources/index.d.cts +357 -0
- package/dist/base/sources/index.d.ts +357 -0
- package/dist/base/sources/index.js +42 -0
- package/dist/base/sources/index.js.map +1 -0
- package/dist/base/sources/node/index.cjs +320 -0
- package/dist/base/sources/node/index.cjs.map +1 -0
- package/dist/base/sources/node/index.d.cts +185 -0
- package/dist/base/sources/node/index.d.ts +185 -0
- package/dist/base/sources/node/index.js +306 -0
- package/dist/base/sources/node/index.js.map +1 -0
- package/dist/base/utils/index.cjs +37 -0
- package/dist/base/utils/index.cjs.map +1 -0
- package/dist/base/utils/index.d.cts +37 -0
- package/dist/base/utils/index.d.ts +37 -0
- package/dist/base/utils/index.js +11 -0
- package/dist/base/utils/index.js.map +1 -0
- package/dist/base/worker/index.cjs +548 -0
- package/dist/base/worker/index.cjs.map +1 -0
- package/dist/base/worker/index.d.cts +207 -0
- package/dist/base/worker/index.d.ts +207 -0
- package/dist/base/worker/index.js +20 -0
- package/dist/base/worker/index.js.map +1 -0
- package/dist/breaker-C9skL3d8.d.ts +175 -0
- package/dist/breaker-ugSdq54q.d.cts +175 -0
- package/dist/cascading-CSSbKGrJ.d.ts +199 -0
- package/dist/cascading-baGkiihI.d.cts +199 -0
- package/dist/chunk-22SG74BD.js +207 -0
- package/dist/chunk-22SG74BD.js.map +1 -0
- package/dist/chunk-255UCBG4.js +58 -0
- package/dist/chunk-255UCBG4.js.map +1 -0
- package/dist/chunk-2LO3EL4W.js +1 -0
- package/dist/chunk-2LO3EL4W.js.map +1 -0
- package/dist/chunk-2OB3CEJS.js +1065 -0
- package/dist/chunk-2OB3CEJS.js.map +1 -0
- package/dist/chunk-36NMM65U.js +144 -0
- package/dist/chunk-36NMM65U.js.map +1 -0
- package/dist/chunk-3CEXCBN6.js +1 -0
- package/dist/chunk-3CEXCBN6.js.map +1 -0
- package/dist/chunk-3MUSLI6E.js +105 -0
- package/dist/chunk-3MUSLI6E.js.map +1 -0
- package/dist/chunk-3PSLNJDU.js +884 -0
- package/dist/chunk-3PSLNJDU.js.map +1 -0
- package/dist/chunk-42FQ27MQ.js +594 -0
- package/dist/chunk-42FQ27MQ.js.map +1 -0
- package/dist/chunk-4GYMCUDZ.js +1085 -0
- package/dist/chunk-4GYMCUDZ.js.map +1 -0
- package/dist/chunk-4S53H2KR.js +382 -0
- package/dist/chunk-4S53H2KR.js.map +1 -0
- package/dist/chunk-4XCHZRUJ.js +128 -0
- package/dist/chunk-4XCHZRUJ.js.map +1 -0
- package/dist/chunk-5IMMNARC.js +1153 -0
- package/dist/chunk-5IMMNARC.js.map +1 -0
- package/dist/chunk-6XZYT4SW.js +256 -0
- package/dist/chunk-6XZYT4SW.js.map +1 -0
- package/dist/chunk-7EGRP2VX.js +76 -0
- package/dist/chunk-7EGRP2VX.js.map +1 -0
- package/dist/chunk-A7KV5UK4.js +150 -0
- package/dist/chunk-A7KV5UK4.js.map +1 -0
- package/dist/chunk-APY2SS5X.js +156 -0
- package/dist/chunk-APY2SS5X.js.map +1 -0
- package/dist/chunk-AZDQPQ3V.js +66 -0
- package/dist/chunk-AZDQPQ3V.js.map +1 -0
- package/dist/chunk-BU3SEFA5.js +90 -0
- package/dist/chunk-BU3SEFA5.js.map +1 -0
- package/dist/chunk-BXGZFGZ4.js +189 -0
- package/dist/chunk-BXGZFGZ4.js.map +1 -0
- package/dist/chunk-CGHORL6G.js +579 -0
- package/dist/chunk-CGHORL6G.js.map +1 -0
- package/dist/chunk-CXANAIZU.js +530 -0
- package/dist/chunk-CXANAIZU.js.map +1 -0
- package/dist/chunk-CZQHCKKG.js +1 -0
- package/dist/chunk-CZQHCKKG.js.map +1 -0
- package/dist/chunk-DKNHAICT.js +133 -0
- package/dist/chunk-DKNHAICT.js.map +1 -0
- package/dist/chunk-DM4OMPWK.js +584 -0
- package/dist/chunk-DM4OMPWK.js.map +1 -0
- package/dist/chunk-DMSNO6ZB.js +452 -0
- package/dist/chunk-DMSNO6ZB.js.map +1 -0
- package/dist/chunk-E5OZPDIW.js +229 -0
- package/dist/chunk-E5OZPDIW.js.map +1 -0
- package/dist/chunk-EHRRQ4IC.js +211 -0
- package/dist/chunk-EHRRQ4IC.js.map +1 -0
- package/dist/chunk-EVYY4X5A.js +509 -0
- package/dist/chunk-EVYY4X5A.js.map +1 -0
- package/dist/chunk-FDFD67UO.js +1 -0
- package/dist/chunk-FDFD67UO.js.map +1 -0
- package/dist/chunk-FMPF42Q4.js +13 -0
- package/dist/chunk-FMPF42Q4.js.map +1 -0
- package/dist/chunk-FW23JYNQ.js +454 -0
- package/dist/chunk-FW23JYNQ.js.map +1 -0
- package/dist/chunk-GWRNLJNW.js +2508 -0
- package/dist/chunk-GWRNLJNW.js.map +1 -0
- package/dist/chunk-HL7HUJIX.js +1 -0
- package/dist/chunk-HL7HUJIX.js.map +1 -0
- package/dist/chunk-IHTWQEDR.js +169 -0
- package/dist/chunk-IHTWQEDR.js.map +1 -0
- package/dist/chunk-IJRR6YAI.js +128 -0
- package/dist/chunk-IJRR6YAI.js.map +1 -0
- package/dist/chunk-JGFRAFDL.js +221 -0
- package/dist/chunk-JGFRAFDL.js.map +1 -0
- package/dist/chunk-JKTC747G.js +725 -0
- package/dist/chunk-JKTC747G.js.map +1 -0
- package/dist/chunk-KN3H5CNT.js +11 -0
- package/dist/chunk-KN3H5CNT.js.map +1 -0
- package/dist/chunk-KPG3DGLA.js +1 -0
- package/dist/chunk-KPG3DGLA.js.map +1 -0
- package/dist/chunk-KRNQ6RGQ.js +1 -0
- package/dist/chunk-KRNQ6RGQ.js.map +1 -0
- package/dist/chunk-MLTPJMH6.js +417 -0
- package/dist/chunk-MLTPJMH6.js.map +1 -0
- package/dist/chunk-N3SZ7BMH.js +95 -0
- package/dist/chunk-N3SZ7BMH.js.map +1 -0
- package/dist/chunk-NDUD3IMO.js +540 -0
- package/dist/chunk-NDUD3IMO.js.map +1 -0
- package/dist/chunk-NY2PYHNC.js +873 -0
- package/dist/chunk-NY2PYHNC.js.map +1 -0
- package/dist/chunk-O3MT7DYI.js +225 -0
- package/dist/chunk-O3MT7DYI.js.map +1 -0
- package/dist/chunk-OCUDSN63.js +2386 -0
- package/dist/chunk-OCUDSN63.js.map +1 -0
- package/dist/chunk-OIWU3NYV.js +199 -0
- package/dist/chunk-OIWU3NYV.js.map +1 -0
- package/dist/chunk-OQUIJT7A.js +1 -0
- package/dist/chunk-OQUIJT7A.js.map +1 -0
- package/dist/chunk-P5LBT622.js +105 -0
- package/dist/chunk-P5LBT622.js.map +1 -0
- package/dist/chunk-PKGQG5QQ.js +519 -0
- package/dist/chunk-PKGQG5QQ.js.map +1 -0
- package/dist/chunk-PKPO3JTZ.js +561 -0
- package/dist/chunk-PKPO3JTZ.js.map +1 -0
- package/dist/chunk-PL5UDIQ5.js +118 -0
- package/dist/chunk-PL5UDIQ5.js.map +1 -0
- package/dist/chunk-PZWISPIQ.js +432 -0
- package/dist/chunk-PZWISPIQ.js.map +1 -0
- package/dist/chunk-Q3EYOCZB.js +510 -0
- package/dist/chunk-Q3EYOCZB.js.map +1 -0
- package/dist/chunk-QMBYUVRL.js +15 -0
- package/dist/chunk-QMBYUVRL.js.map +1 -0
- package/dist/chunk-RAGGHLCV.js +200 -0
- package/dist/chunk-RAGGHLCV.js.map +1 -0
- package/dist/chunk-RJOG4IJU.js +1039 -0
- package/dist/chunk-RJOG4IJU.js.map +1 -0
- package/dist/chunk-SOOKUYVM.js +403 -0
- package/dist/chunk-SOOKUYVM.js.map +1 -0
- package/dist/chunk-T5BN5KG7.js +1 -0
- package/dist/chunk-T5BN5KG7.js.map +1 -0
- package/dist/chunk-TNX5ZGDJ.js +574 -0
- package/dist/chunk-TNX5ZGDJ.js.map +1 -0
- package/dist/chunk-TP7244Y6.js +207 -0
- package/dist/chunk-TP7244Y6.js.map +1 -0
- package/dist/chunk-TSBFTJKM.js +57 -0
- package/dist/chunk-TSBFTJKM.js.map +1 -0
- package/dist/chunk-URQ2CBBF.js +143 -0
- package/dist/chunk-URQ2CBBF.js.map +1 -0
- package/dist/chunk-VLAGJZSL.js +1079 -0
- package/dist/chunk-VLAGJZSL.js.map +1 -0
- package/dist/chunk-W2BOPXTI.js +1 -0
- package/dist/chunk-W2BOPXTI.js.map +1 -0
- package/dist/chunk-Y52CS6YA.js +88 -0
- package/dist/chunk-Y52CS6YA.js.map +1 -0
- package/dist/chunk-YCBUWK77.js +92 -0
- package/dist/chunk-YCBUWK77.js.map +1 -0
- package/dist/chunk-YJ4U2D2C.js +314 -0
- package/dist/chunk-YJ4U2D2C.js.map +1 -0
- package/dist/chunk-Z4YXAUDN.js +239 -0
- package/dist/chunk-Z4YXAUDN.js.map +1 -0
- package/dist/chunk-Z65DVDEQ.js +146 -0
- package/dist/chunk-Z65DVDEQ.js.map +1 -0
- package/dist/chunk-Z6EGP5D7.js +92 -0
- package/dist/chunk-Z6EGP5D7.js.map +1 -0
- package/dist/chunk-ZT4WMQW4.js +1575 -0
- package/dist/chunk-ZT4WMQW4.js.map +1 -0
- package/dist/chunk-ZVXXDWIB.js +1282 -0
- package/dist/chunk-ZVXXDWIB.js.map +1 -0
- package/dist/compat/index.cjs +3150 -6
- package/dist/compat/index.cjs.map +1 -1
- package/dist/compat/index.d.cts +116 -1
- package/dist/compat/index.d.ts +116 -1
- package/dist/compat/index.js +175 -2
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/jotai/index.cjs +130 -2
- package/dist/compat/jotai/index.cjs.map +1 -1
- package/dist/compat/jotai/index.d.cts +2 -1
- package/dist/compat/jotai/index.d.ts +2 -1
- package/dist/compat/jotai/index.js +7 -2
- package/dist/compat/jotai/index.js.map +1 -1
- package/dist/compat/nanostores/index.cjs +186 -2
- package/dist/compat/nanostores/index.cjs.map +1 -1
- package/dist/compat/nanostores/index.d.cts +2 -1
- package/dist/compat/nanostores/index.d.ts +2 -1
- package/dist/compat/nanostores/index.js +21 -2
- package/dist/compat/nanostores/index.js.map +1 -1
- package/dist/compat/nestjs/index.cjs +2291 -6
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.d.cts +10 -1
- package/dist/compat/nestjs/index.d.ts +10 -1
- package/dist/compat/nestjs/index.js +76 -2
- package/dist/compat/nestjs/index.js.map +1 -1
- package/dist/compat/react/index.cjs +95 -2
- package/dist/compat/react/index.cjs.map +1 -1
- package/dist/compat/react/index.d.cts +2 -1
- package/dist/compat/react/index.d.ts +2 -1
- package/dist/compat/react/index.js +11 -2
- package/dist/compat/react/index.js.map +1 -1
- package/dist/compat/solid/index.cjs +82 -2
- package/dist/compat/solid/index.cjs.map +1 -1
- package/dist/compat/solid/index.d.cts +2 -1
- package/dist/compat/solid/index.d.ts +2 -1
- package/dist/compat/solid/index.js +11 -2
- package/dist/compat/solid/index.js.map +1 -1
- package/dist/compat/svelte/index.cjs +85 -2
- package/dist/compat/svelte/index.cjs.map +1 -1
- package/dist/compat/svelte/index.d.cts +2 -1
- package/dist/compat/svelte/index.d.ts +2 -1
- package/dist/compat/svelte/index.js +11 -2
- package/dist/compat/svelte/index.js.map +1 -1
- package/dist/compat/vue/index.cjs +100 -2
- package/dist/compat/vue/index.cjs.map +1 -1
- package/dist/compat/vue/index.d.cts +3 -1
- package/dist/compat/vue/index.d.ts +3 -1
- package/dist/compat/vue/index.js +11 -2
- package/dist/compat/vue/index.js.map +1 -1
- package/dist/compat/zustand/index.cjs +50 -2
- package/dist/compat/zustand/index.cjs.map +1 -1
- package/dist/compat/zustand/index.d.cts +2 -1
- package/dist/compat/zustand/index.d.ts +2 -1
- package/dist/compat/zustand/index.js +7 -2
- package/dist/compat/zustand/index.js.map +1 -1
- package/dist/distill-De6Rnn15.d.cts +48 -0
- package/dist/distill-De6Rnn15.d.ts +48 -0
- package/dist/external-register-CWyroXb_.d.cts +138 -0
- package/dist/external-register-CWyroXb_.d.ts +138 -0
- package/dist/fallback-Bx46zqky.d.cts +243 -0
- package/dist/fallback-pIWW8A2d.d.ts +243 -0
- package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
- package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
- package/dist/index-B6pxYJzO.d.cts +36 -0
- package/dist/index-B6pxYJzO.d.ts +36 -0
- package/dist/index-BFsng6v1.d.cts +44 -0
- package/dist/index-BFsng6v1.d.ts +44 -0
- package/dist/index-B_p8tnvf.d.cts +770 -0
- package/dist/index-Bg-LwEt-.d.cts +45 -0
- package/dist/index-Bg-LwEt-.d.ts +45 -0
- package/dist/index-Brp888t0.d.cts +127 -0
- package/dist/index-Brp888t0.d.ts +127 -0
- package/dist/index-CDfk6jHN.d.cts +37 -0
- package/dist/index-CDfk6jHN.d.ts +37 -0
- package/dist/index-DLAxYaN5.d.cts +169 -0
- package/dist/index-DLAxYaN5.d.ts +169 -0
- package/dist/index-DeWbQzMe.d.cts +34 -0
- package/dist/index-DeWbQzMe.d.ts +34 -0
- package/dist/index-_HDSmPyp.d.ts +770 -0
- package/dist/index-dX9IzPqj.d.cts +86 -0
- package/dist/index-dX9IzPqj.d.ts +86 -0
- package/dist/index.cjs +26009 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -42
- package/dist/index.d.ts +55 -42
- package/dist/index.js +849 -0
- package/dist/index.js.map +1 -1
- package/dist/layout-types-B5aiHYgk.d.cts +72 -0
- package/dist/layout-types-B5aiHYgk.d.ts +72 -0
- package/dist/memory-composers-BryDrRBX.d.cts +529 -0
- package/dist/memory-composers-CVQqPYEV.d.ts +529 -0
- package/dist/observable-B25XqCbZ.d.cts +59 -0
- package/dist/observable-B25XqCbZ.d.ts +59 -0
- package/dist/pipeline-graph-Ce47CB6Y.d.cts +145 -0
- package/dist/pipeline-graph-DXCwY9vG.d.ts +145 -0
- package/dist/presets/ai/index.cjs +4377 -0
- package/dist/presets/ai/index.cjs.map +1 -0
- package/dist/presets/ai/index.d.cts +98 -0
- package/dist/presets/ai/index.d.ts +98 -0
- package/dist/presets/ai/index.js +54 -0
- package/dist/presets/ai/index.js.map +1 -0
- package/dist/presets/harness/index.cjs +5929 -0
- package/dist/presets/harness/index.cjs.map +1 -0
- package/dist/presets/harness/index.d.cts +566 -0
- package/dist/presets/harness/index.d.ts +566 -0
- package/dist/presets/harness/index.js +71 -0
- package/dist/presets/harness/index.js.map +1 -0
- package/dist/presets/index.cjs +9782 -0
- package/dist/presets/index.cjs.map +1 -0
- package/dist/presets/index.d.cts +28 -0
- package/dist/presets/index.d.ts +28 -0
- package/dist/presets/index.js +129 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/inspect/index.cjs +1087 -0
- package/dist/presets/inspect/index.cjs.map +1 -0
- package/dist/presets/inspect/index.d.cts +172 -0
- package/dist/presets/inspect/index.d.ts +172 -0
- package/dist/presets/inspect/index.js +21 -0
- package/dist/presets/inspect/index.js.map +1 -0
- package/dist/presets/resilience/index.cjs +1593 -0
- package/dist/presets/resilience/index.cjs.map +1 -0
- package/dist/presets/resilience/index.d.cts +205 -0
- package/dist/presets/resilience/index.d.ts +205 -0
- package/dist/presets/resilience/index.js +18 -0
- package/dist/presets/resilience/index.js.map +1 -0
- package/dist/rate-limiter-CEALq4N1.d.ts +559 -0
- package/dist/rate-limiter-DpVbSYdH.d.cts +559 -0
- package/dist/reactive-layout-fswlBUvX.d.cts +195 -0
- package/dist/reactive-layout-fswlBUvX.d.ts +195 -0
- package/dist/retry-BDbRZ_gx.d.ts +125 -0
- package/dist/retry-DWuhjvsA.d.cts +125 -0
- package/dist/solutions/index.cjs +8200 -0
- package/dist/solutions/index.cjs.map +1 -0
- package/dist/solutions/index.d.cts +23 -0
- package/dist/solutions/index.d.ts +23 -0
- package/dist/solutions/index.js +55 -0
- package/dist/solutions/index.js.map +1 -0
- package/dist/spawnable-5mDY501F.d.cts +746 -0
- package/dist/spawnable-D3lR0oQu.d.ts +746 -0
- package/dist/status-U-rUI79b.d.cts +84 -0
- package/dist/status-U-rUI79b.d.ts +84 -0
- package/dist/timeout-U5O4ESK3.js +12 -0
- package/dist/timeout-U5O4ESK3.js.map +1 -0
- package/dist/types-BB5Lw-pB.d.cts +442 -0
- package/dist/types-BB5Lw-pB.d.ts +442 -0
- package/dist/types-CJWIMJiZ.d.ts +548 -0
- package/dist/types-vCq7ShIm.d.cts +548 -0
- package/dist/utils/ai/browser.cjs +2169 -0
- package/dist/utils/ai/browser.cjs.map +1 -0
- package/dist/utils/ai/browser.d.cts +129 -0
- package/dist/utils/ai/browser.d.ts +129 -0
- package/dist/utils/ai/browser.js +255 -0
- package/dist/utils/ai/browser.js.map +1 -0
- package/dist/utils/ai/index.cjs +8468 -0
- package/dist/utils/ai/index.cjs.map +1 -0
- package/dist/utils/ai/index.d.cts +1777 -0
- package/dist/utils/ai/index.d.ts +1777 -0
- package/dist/utils/ai/index.js +173 -0
- package/dist/utils/ai/index.js.map +1 -0
- package/dist/utils/ai/node.cjs +648 -0
- package/dist/utils/ai/node.cjs.map +1 -0
- package/dist/utils/ai/node.d.cts +57 -0
- package/dist/utils/ai/node.d.ts +57 -0
- package/dist/utils/ai/node.js +84 -0
- package/dist/utils/ai/node.js.map +1 -0
- package/dist/utils/cqrs/index.cjs +1036 -0
- package/dist/utils/cqrs/index.cjs.map +1 -0
- package/dist/utils/cqrs/index.d.cts +438 -0
- package/dist/utils/cqrs/index.d.ts +438 -0
- package/dist/utils/cqrs/index.js +18 -0
- package/dist/utils/cqrs/index.js.map +1 -0
- package/dist/utils/demo-shell/index.cjs +865 -0
- package/dist/utils/demo-shell/index.cjs.map +1 -0
- package/dist/utils/demo-shell/index.d.cts +90 -0
- package/dist/utils/demo-shell/index.d.ts +90 -0
- package/dist/utils/demo-shell/index.js +13 -0
- package/dist/utils/demo-shell/index.js.map +1 -0
- package/dist/utils/domain-templates/index.cjs +732 -0
- package/dist/utils/domain-templates/index.cjs.map +1 -0
- package/dist/utils/domain-templates/index.d.cts +214 -0
- package/dist/utils/domain-templates/index.d.ts +214 -0
- package/dist/utils/domain-templates/index.js +17 -0
- package/dist/utils/domain-templates/index.js.map +1 -0
- package/dist/utils/graphspec/index.cjs +1174 -0
- package/dist/utils/graphspec/index.cjs.map +1 -0
- package/dist/utils/graphspec/index.d.cts +449 -0
- package/dist/utils/graphspec/index.d.ts +449 -0
- package/dist/utils/graphspec/index.js +35 -0
- package/dist/utils/graphspec/index.js.map +1 -0
- package/dist/utils/harness/index.cjs +656 -0
- package/dist/utils/harness/index.cjs.map +1 -0
- package/dist/utils/harness/index.d.cts +542 -0
- package/dist/utils/harness/index.d.ts +542 -0
- package/dist/utils/harness/index.js +56 -0
- package/dist/utils/harness/index.js.map +1 -0
- package/dist/utils/index.cjs +17614 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +96 -0
- package/dist/utils/index.d.ts +96 -0
- package/dist/utils/index.js +514 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/inspect/index.cjs +807 -0
- package/dist/utils/inspect/index.cjs.map +1 -0
- package/dist/utils/inspect/index.d.cts +123 -0
- package/dist/utils/inspect/index.d.ts +123 -0
- package/dist/utils/inspect/index.js +30 -0
- package/dist/utils/inspect/index.js.map +1 -0
- package/dist/utils/job-queue/index.cjs +717 -0
- package/dist/utils/job-queue/index.cjs.map +1 -0
- package/dist/utils/job-queue/index.d.cts +200 -0
- package/dist/utils/job-queue/index.d.ts +200 -0
- package/dist/utils/job-queue/index.js +18 -0
- package/dist/utils/job-queue/index.js.map +1 -0
- package/dist/utils/memory/index.cjs +1456 -0
- package/dist/utils/memory/index.cjs.map +1 -0
- package/dist/utils/memory/index.d.cts +660 -0
- package/dist/utils/memory/index.d.ts +660 -0
- package/dist/utils/memory/index.js +19 -0
- package/dist/utils/memory/index.js.map +1 -0
- package/dist/utils/messaging/index.cjs +666 -0
- package/dist/utils/messaging/index.cjs.map +1 -0
- package/dist/utils/messaging/index.d.cts +562 -0
- package/dist/utils/messaging/index.d.ts +562 -0
- package/dist/utils/messaging/index.js +50 -0
- package/dist/utils/messaging/index.js.map +1 -0
- package/dist/utils/orchestration/index.cjs +876 -0
- package/dist/utils/orchestration/index.cjs.map +1 -0
- package/dist/utils/orchestration/index.d.cts +233 -0
- package/dist/utils/orchestration/index.d.ts +233 -0
- package/dist/utils/orchestration/index.js +19 -0
- package/dist/utils/orchestration/index.js.map +1 -0
- package/dist/utils/process/index.cjs +743 -0
- package/dist/utils/process/index.cjs.map +1 -0
- package/dist/utils/process/index.d.cts +411 -0
- package/dist/utils/process/index.d.ts +411 -0
- package/dist/utils/process/index.js +14 -0
- package/dist/utils/process/index.js.map +1 -0
- package/dist/utils/reactive-layout/index.cjs +1607 -0
- package/dist/utils/reactive-layout/index.cjs.map +1 -0
- package/dist/utils/reactive-layout/index.d.cts +492 -0
- package/dist/utils/reactive-layout/index.d.ts +492 -0
- package/dist/utils/reactive-layout/index.js +52 -0
- package/dist/utils/reactive-layout/index.js.map +1 -0
- package/dist/utils/reduction/index.cjs +203 -0
- package/dist/utils/reduction/index.cjs.map +1 -0
- package/dist/utils/reduction/index.d.cts +102 -0
- package/dist/utils/reduction/index.d.ts +102 -0
- package/dist/utils/reduction/index.js +14 -0
- package/dist/utils/reduction/index.js.map +1 -0
- package/dist/utils/resilience/index.cjs +1617 -0
- package/dist/utils/resilience/index.cjs.map +1 -0
- package/dist/utils/resilience/index.d.cts +9 -0
- package/dist/utils/resilience/index.d.ts +9 -0
- package/dist/utils/resilience/index.js +44 -0
- package/dist/utils/resilience/index.js.map +1 -0
- package/dist/utils/surface/index.cjs +1070 -0
- package/dist/utils/surface/index.cjs.map +1 -0
- package/dist/utils/surface/index.d.cts +240 -0
- package/dist/utils/surface/index.d.ts +240 -0
- package/dist/utils/surface/index.js +30 -0
- package/dist/utils/surface/index.js.map +1 -0
- package/dist/utils/topology-view/index.cjs +620 -0
- package/dist/utils/topology-view/index.cjs.map +1 -0
- package/dist/utils/topology-view/index.d.cts +68 -0
- package/dist/utils/topology-view/index.d.ts +68 -0
- package/dist/utils/topology-view/index.js +11 -0
- package/dist/utils/topology-view/index.js.map +1 -0
- package/package.json +293 -241
- package/dist/core/index.cjs +0 -21
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -3
- package/dist/core/index.js.map +0 -1
- package/dist/extra/browser.cjs +0 -21
- package/dist/extra/browser.cjs.map +0 -1
- package/dist/extra/browser.d.cts +0 -1
- package/dist/extra/browser.d.ts +0 -1
- package/dist/extra/browser.js +0 -3
- package/dist/extra/browser.js.map +0 -1
- package/dist/extra/index.cjs +0 -21
- package/dist/extra/index.cjs.map +0 -1
- package/dist/extra/index.d.cts +0 -1
- package/dist/extra/index.d.ts +0 -1
- package/dist/extra/index.js +0 -3
- package/dist/extra/index.js.map +0 -1
- package/dist/extra/node.cjs +0 -21
- package/dist/extra/node.cjs.map +0 -1
- package/dist/extra/node.d.cts +0 -1
- package/dist/extra/node.d.ts +0 -1
- package/dist/extra/node.js +0 -3
- package/dist/extra/node.js.map +0 -1
- package/dist/extra/operators.cjs +0 -21
- package/dist/extra/operators.cjs.map +0 -1
- package/dist/extra/operators.d.cts +0 -1
- package/dist/extra/operators.d.ts +0 -1
- package/dist/extra/operators.js +0 -3
- package/dist/extra/operators.js.map +0 -1
- package/dist/extra/reactive.cjs +0 -21
- package/dist/extra/reactive.cjs.map +0 -1
- package/dist/extra/reactive.d.cts +0 -1
- package/dist/extra/reactive.d.ts +0 -1
- package/dist/extra/reactive.js +0 -3
- package/dist/extra/reactive.js.map +0 -1
- package/dist/extra/render/index.cjs +0 -21
- package/dist/extra/render/index.cjs.map +0 -1
- package/dist/extra/render/index.d.cts +0 -1
- package/dist/extra/render/index.d.ts +0 -1
- package/dist/extra/render/index.js +0 -3
- package/dist/extra/render/index.js.map +0 -1
- package/dist/extra/sources.cjs +0 -21
- package/dist/extra/sources.cjs.map +0 -1
- package/dist/extra/sources.d.cts +0 -1
- package/dist/extra/sources.d.ts +0 -1
- package/dist/extra/sources.js +0 -3
- package/dist/extra/sources.js.map +0 -1
- package/dist/extra/storage-browser.cjs +0 -21
- package/dist/extra/storage-browser.cjs.map +0 -1
- package/dist/extra/storage-browser.d.cts +0 -1
- package/dist/extra/storage-browser.d.ts +0 -1
- package/dist/extra/storage-browser.js +0 -3
- package/dist/extra/storage-browser.js.map +0 -1
- package/dist/extra/storage-core.cjs +0 -21
- package/dist/extra/storage-core.cjs.map +0 -1
- package/dist/extra/storage-core.d.cts +0 -1
- package/dist/extra/storage-core.d.ts +0 -1
- package/dist/extra/storage-core.js +0 -3
- package/dist/extra/storage-core.js.map +0 -1
- package/dist/extra/storage-node.cjs +0 -21
- package/dist/extra/storage-node.cjs.map +0 -1
- package/dist/extra/storage-node.d.cts +0 -1
- package/dist/extra/storage-node.d.ts +0 -1
- package/dist/extra/storage-node.js +0 -3
- package/dist/extra/storage-node.js.map +0 -1
- package/dist/extra/storage-tiers-browser.cjs +0 -21
- package/dist/extra/storage-tiers-browser.cjs.map +0 -1
- package/dist/extra/storage-tiers-browser.d.cts +0 -1
- package/dist/extra/storage-tiers-browser.d.ts +0 -1
- package/dist/extra/storage-tiers-browser.js +0 -3
- package/dist/extra/storage-tiers-browser.js.map +0 -1
- package/dist/extra/storage-tiers-node.cjs +0 -21
- package/dist/extra/storage-tiers-node.cjs.map +0 -1
- package/dist/extra/storage-tiers-node.d.cts +0 -1
- package/dist/extra/storage-tiers-node.d.ts +0 -1
- package/dist/extra/storage-tiers-node.js +0 -3
- package/dist/extra/storage-tiers-node.js.map +0 -1
- package/dist/extra/storage-tiers.cjs +0 -21
- package/dist/extra/storage-tiers.cjs.map +0 -1
- package/dist/extra/storage-tiers.d.cts +0 -1
- package/dist/extra/storage-tiers.d.ts +0 -1
- package/dist/extra/storage-tiers.js +0 -3
- package/dist/extra/storage-tiers.js.map +0 -1
- package/dist/extra/storage-wal.cjs +0 -21
- package/dist/extra/storage-wal.cjs.map +0 -1
- package/dist/extra/storage-wal.d.cts +0 -1
- package/dist/extra/storage-wal.d.ts +0 -1
- package/dist/extra/storage-wal.js +0 -3
- package/dist/extra/storage-wal.js.map +0 -1
- package/dist/graph/index.cjs +0 -21
- package/dist/graph/index.cjs.map +0 -1
- package/dist/graph/index.d.cts +0 -1
- package/dist/graph/index.d.ts +0 -1
- package/dist/graph/index.js +0 -3
- package/dist/graph/index.js.map +0 -1
- package/dist/patterns/ai/browser.cjs +0 -21
- package/dist/patterns/ai/browser.cjs.map +0 -1
- package/dist/patterns/ai/browser.d.cts +0 -1
- package/dist/patterns/ai/browser.d.ts +0 -1
- package/dist/patterns/ai/browser.js +0 -3
- package/dist/patterns/ai/browser.js.map +0 -1
- package/dist/patterns/ai/index.cjs +0 -21
- package/dist/patterns/ai/index.cjs.map +0 -1
- package/dist/patterns/ai/index.d.cts +0 -1
- package/dist/patterns/ai/index.d.ts +0 -1
- package/dist/patterns/ai/index.js +0 -3
- package/dist/patterns/ai/index.js.map +0 -1
- package/dist/patterns/ai/node.cjs +0 -21
- package/dist/patterns/ai/node.cjs.map +0 -1
- package/dist/patterns/ai/node.d.cts +0 -1
- package/dist/patterns/ai/node.d.ts +0 -1
- package/dist/patterns/ai/node.js +0 -3
- package/dist/patterns/ai/node.js.map +0 -1
- package/dist/patterns/cqrs/index.cjs +0 -21
- package/dist/patterns/cqrs/index.cjs.map +0 -1
- package/dist/patterns/cqrs/index.d.cts +0 -1
- package/dist/patterns/cqrs/index.d.ts +0 -1
- package/dist/patterns/cqrs/index.js +0 -3
- package/dist/patterns/cqrs/index.js.map +0 -1
- package/dist/patterns/demo-shell/index.cjs +0 -21
- package/dist/patterns/demo-shell/index.cjs.map +0 -1
- package/dist/patterns/demo-shell/index.d.cts +0 -1
- package/dist/patterns/demo-shell/index.d.ts +0 -1
- package/dist/patterns/demo-shell/index.js +0 -3
- package/dist/patterns/demo-shell/index.js.map +0 -1
- package/dist/patterns/domain-templates/index.cjs +0 -21
- package/dist/patterns/domain-templates/index.cjs.map +0 -1
- package/dist/patterns/domain-templates/index.d.cts +0 -1
- package/dist/patterns/domain-templates/index.d.ts +0 -1
- package/dist/patterns/domain-templates/index.js +0 -3
- package/dist/patterns/domain-templates/index.js.map +0 -1
- package/dist/patterns/graphspec/index.cjs +0 -21
- package/dist/patterns/graphspec/index.cjs.map +0 -1
- package/dist/patterns/graphspec/index.d.cts +0 -1
- package/dist/patterns/graphspec/index.d.ts +0 -1
- package/dist/patterns/graphspec/index.js +0 -3
- package/dist/patterns/graphspec/index.js.map +0 -1
- package/dist/patterns/harness/index.cjs +0 -21
- package/dist/patterns/harness/index.cjs.map +0 -1
- package/dist/patterns/harness/index.d.cts +0 -1
- package/dist/patterns/harness/index.d.ts +0 -1
- package/dist/patterns/harness/index.js +0 -3
- package/dist/patterns/harness/index.js.map +0 -1
- package/dist/patterns/inspect/index.cjs +0 -21
- package/dist/patterns/inspect/index.cjs.map +0 -1
- package/dist/patterns/inspect/index.d.cts +0 -1
- package/dist/patterns/inspect/index.d.ts +0 -1
- package/dist/patterns/inspect/index.js +0 -3
- package/dist/patterns/inspect/index.js.map +0 -1
- package/dist/patterns/job-queue/index.cjs +0 -21
- package/dist/patterns/job-queue/index.cjs.map +0 -1
- package/dist/patterns/job-queue/index.d.cts +0 -1
- package/dist/patterns/job-queue/index.d.ts +0 -1
- package/dist/patterns/job-queue/index.js +0 -3
- package/dist/patterns/job-queue/index.js.map +0 -1
- package/dist/patterns/memory/index.cjs +0 -21
- package/dist/patterns/memory/index.cjs.map +0 -1
- package/dist/patterns/memory/index.d.cts +0 -1
- package/dist/patterns/memory/index.d.ts +0 -1
- package/dist/patterns/memory/index.js +0 -3
- package/dist/patterns/memory/index.js.map +0 -1
- package/dist/patterns/messaging/index.cjs +0 -21
- package/dist/patterns/messaging/index.cjs.map +0 -1
- package/dist/patterns/messaging/index.d.cts +0 -1
- package/dist/patterns/messaging/index.d.ts +0 -1
- package/dist/patterns/messaging/index.js +0 -3
- package/dist/patterns/messaging/index.js.map +0 -1
- package/dist/patterns/orchestration/index.cjs +0 -21
- package/dist/patterns/orchestration/index.cjs.map +0 -1
- package/dist/patterns/orchestration/index.d.cts +0 -1
- package/dist/patterns/orchestration/index.d.ts +0 -1
- package/dist/patterns/orchestration/index.js +0 -3
- package/dist/patterns/orchestration/index.js.map +0 -1
- package/dist/patterns/process/index.cjs +0 -21
- package/dist/patterns/process/index.cjs.map +0 -1
- package/dist/patterns/process/index.d.cts +0 -1
- package/dist/patterns/process/index.d.ts +0 -1
- package/dist/patterns/process/index.js +0 -3
- package/dist/patterns/process/index.js.map +0 -1
- package/dist/patterns/reactive-layout/index.cjs +0 -21
- package/dist/patterns/reactive-layout/index.cjs.map +0 -1
- package/dist/patterns/reactive-layout/index.d.cts +0 -1
- package/dist/patterns/reactive-layout/index.d.ts +0 -1
- package/dist/patterns/reactive-layout/index.js +0 -3
- package/dist/patterns/reactive-layout/index.js.map +0 -1
- package/dist/patterns/reduction/index.cjs +0 -21
- package/dist/patterns/reduction/index.cjs.map +0 -1
- package/dist/patterns/reduction/index.d.cts +0 -1
- package/dist/patterns/reduction/index.d.ts +0 -1
- package/dist/patterns/reduction/index.js +0 -3
- package/dist/patterns/reduction/index.js.map +0 -1
- package/dist/patterns/surface/index.cjs +0 -21
- package/dist/patterns/surface/index.cjs.map +0 -1
- package/dist/patterns/surface/index.d.cts +0 -1
- package/dist/patterns/surface/index.d.ts +0 -1
- package/dist/patterns/surface/index.js +0 -3
- package/dist/patterns/surface/index.js.map +0 -1
- package/dist/patterns/topology-view/index.cjs +0 -21
- package/dist/patterns/topology-view/index.cjs.map +0 -1
- package/dist/patterns/topology-view/index.d.cts +0 -1
- package/dist/patterns/topology-view/index.d.ts +0 -1
- package/dist/patterns/topology-view/index.js +0 -3
- package/dist/patterns/topology-view/index.js.map +0 -1
- package/dist/testing/index.cjs +0 -21
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -3
- package/dist/testing/index.js.map +0 -1
|
@@ -0,0 +1,1153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collection,
|
|
3
|
+
cosineSimilarity,
|
|
4
|
+
knowledgeGraph,
|
|
5
|
+
vectorIndex
|
|
6
|
+
} from "./chunk-ZVXXDWIB.js";
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_DECAY_RATE,
|
|
9
|
+
decay
|
|
10
|
+
} from "./chunk-QMBYUVRL.js";
|
|
11
|
+
import {
|
|
12
|
+
domainMeta
|
|
13
|
+
} from "./chunk-FMPF42Q4.js";
|
|
14
|
+
import {
|
|
15
|
+
distill
|
|
16
|
+
} from "./chunk-A7KV5UK4.js";
|
|
17
|
+
import {
|
|
18
|
+
nodeSignal
|
|
19
|
+
} from "./chunk-O3MT7DYI.js";
|
|
20
|
+
import {
|
|
21
|
+
retry
|
|
22
|
+
} from "./chunk-Z4YXAUDN.js";
|
|
23
|
+
|
|
24
|
+
// src/utils/ai/agents/chat-stream.ts
|
|
25
|
+
import { node as node2, RESOLVED } from "@graphrefly/pure-ts/core";
|
|
26
|
+
import { keepalive, reactiveLog } from "@graphrefly/pure-ts/extra";
|
|
27
|
+
import { Graph } from "@graphrefly/pure-ts/graph";
|
|
28
|
+
|
|
29
|
+
// src/utils/ai/_internal.ts
|
|
30
|
+
import {
|
|
31
|
+
COMPLETE,
|
|
32
|
+
DATA,
|
|
33
|
+
ERROR,
|
|
34
|
+
node,
|
|
35
|
+
ResettableTimer
|
|
36
|
+
} from "@graphrefly/pure-ts/core";
|
|
37
|
+
import { fromAny } from "@graphrefly/pure-ts/extra";
|
|
38
|
+
function aiMeta(kind, extra) {
|
|
39
|
+
return domainMeta("ai", kind, extra);
|
|
40
|
+
}
|
|
41
|
+
function isPromiseLike(x) {
|
|
42
|
+
return x != null && typeof x.then === "function";
|
|
43
|
+
}
|
|
44
|
+
function isNodeLike(x) {
|
|
45
|
+
return typeof x === "object" && x !== null && "subscribe" in x && typeof x.subscribe === "function" && "cache" in x;
|
|
46
|
+
}
|
|
47
|
+
function isAsyncIterableLike(x) {
|
|
48
|
+
return x != null && typeof x === "object" && Symbol.asyncIterator in x && typeof x[Symbol.asyncIterator] === "function";
|
|
49
|
+
}
|
|
50
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
51
|
+
function firstDataFromNode(resolved, opts) {
|
|
52
|
+
if (resolved.status === "settled") {
|
|
53
|
+
const immediate = resolved.cache;
|
|
54
|
+
if (immediate !== void 0) {
|
|
55
|
+
return Promise.resolve(immediate);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const timer = new ResettableTimer();
|
|
61
|
+
const unsub = resolved.subscribe((messages) => {
|
|
62
|
+
for (const msg of messages) {
|
|
63
|
+
if (msg[0] === DATA) {
|
|
64
|
+
timer.cancel();
|
|
65
|
+
unsub();
|
|
66
|
+
resolve(msg[1]);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (msg[0] === ERROR) {
|
|
70
|
+
timer.cancel();
|
|
71
|
+
unsub();
|
|
72
|
+
reject(msg[1]);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (msg[0] === COMPLETE) {
|
|
76
|
+
timer.cancel();
|
|
77
|
+
unsub();
|
|
78
|
+
reject(new Error("firstDataFromNode: completed without producing a value"));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
timer.start(timeoutMs, () => {
|
|
84
|
+
unsub();
|
|
85
|
+
reject(new Error(`firstDataFromNode: timed out after ${timeoutMs}ms`));
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function resolveToolHandlerResult(value) {
|
|
90
|
+
if (isPromiseLike(value)) {
|
|
91
|
+
return resolveToolHandlerResult(await value);
|
|
92
|
+
}
|
|
93
|
+
if (isNodeLike(value)) {
|
|
94
|
+
return firstDataFromNode(value);
|
|
95
|
+
}
|
|
96
|
+
if (isAsyncIterableLike(value)) {
|
|
97
|
+
return firstDataFromNode(fromAny(value));
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
function stripFences(text) {
|
|
102
|
+
const match = text.match(/^```(?:json)?\s*([\s\S]*?)\s*```[\s\S]*$/);
|
|
103
|
+
return match ? match[1] : text;
|
|
104
|
+
}
|
|
105
|
+
function _oneShotLlmCall(adapter, messages, config) {
|
|
106
|
+
return node(
|
|
107
|
+
(_data, actions) => {
|
|
108
|
+
const ac = new AbortController();
|
|
109
|
+
const parentSignal = config.parentSignal;
|
|
110
|
+
let unlinkParent = () => void 0;
|
|
111
|
+
if (parentSignal) {
|
|
112
|
+
if (parentSignal.aborted) {
|
|
113
|
+
ac.abort();
|
|
114
|
+
} else {
|
|
115
|
+
const onParentAbort = () => ac.abort();
|
|
116
|
+
parentSignal.addEventListener("abort", onParentAbort, { once: true });
|
|
117
|
+
unlinkParent = () => parentSignal.removeEventListener("abort", onParentAbort);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let captured = false;
|
|
121
|
+
let unsub = null;
|
|
122
|
+
const emitOnce = (value) => {
|
|
123
|
+
if (captured) return;
|
|
124
|
+
captured = true;
|
|
125
|
+
actions.down([[DATA, value], [COMPLETE]]);
|
|
126
|
+
unsub?.();
|
|
127
|
+
unsub = null;
|
|
128
|
+
};
|
|
129
|
+
let invokeResult;
|
|
130
|
+
try {
|
|
131
|
+
invokeResult = adapter.invoke(messages, { ...config.invokeOpts, signal: ac.signal });
|
|
132
|
+
} catch (err) {
|
|
133
|
+
emitOnce(config.onFailure("throw", err));
|
|
134
|
+
return () => {
|
|
135
|
+
unlinkParent();
|
|
136
|
+
ac.abort();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const callNode = fromAny(invokeResult, { signal: ac.signal });
|
|
140
|
+
unsub = callNode.subscribe((batch2) => {
|
|
141
|
+
for (const m of batch2) {
|
|
142
|
+
if (captured) return;
|
|
143
|
+
if (m[0] === DATA) {
|
|
144
|
+
try {
|
|
145
|
+
emitOnce(config.onSuccess(m[1]));
|
|
146
|
+
} catch (err) {
|
|
147
|
+
emitOnce(config.onFailure("onSuccess-threw", err));
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (m[0] === ERROR) {
|
|
152
|
+
emitOnce(config.onFailure("error", m[1]));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (m[0] === COMPLETE) {
|
|
156
|
+
emitOnce(config.onFailure("complete", void 0));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
if (captured && unsub) {
|
|
162
|
+
unsub();
|
|
163
|
+
unsub = null;
|
|
164
|
+
}
|
|
165
|
+
return () => {
|
|
166
|
+
unlinkParent();
|
|
167
|
+
ac.abort();
|
|
168
|
+
unsub?.();
|
|
169
|
+
unsub = null;
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
{ describeKind: "producer" }
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/utils/ai/agents/chat-stream.ts
|
|
177
|
+
var ChatStreamGraph = class extends Graph {
|
|
178
|
+
_log;
|
|
179
|
+
messages;
|
|
180
|
+
/**
|
|
181
|
+
* Most recently appended message. Stays in the protocol SENTINEL state
|
|
182
|
+
* (`cache === undefined`, no DATA emitted) until the first append, then
|
|
183
|
+
* tracks the latest entry. Per COMPOSITION-GUIDE §1a, the SENTINEL is
|
|
184
|
+
* the canonical "no value yet" signal — consumers detect empty via
|
|
185
|
+
* `data[i] === undefined` inside reactive fns or `latest.cache === undefined`
|
|
186
|
+
* outside. No `T | null` placeholder, no `hasLatest` companion.
|
|
187
|
+
*/
|
|
188
|
+
latest;
|
|
189
|
+
messageCount;
|
|
190
|
+
constructor(name, opts = {}) {
|
|
191
|
+
super(name, opts.graph);
|
|
192
|
+
this._log = reactiveLog([], {
|
|
193
|
+
name: "messages",
|
|
194
|
+
maxSize: opts.maxMessages
|
|
195
|
+
});
|
|
196
|
+
this.messages = this._log.entries;
|
|
197
|
+
this.add(this.messages, { name: "messages" });
|
|
198
|
+
this.latest = node2(
|
|
199
|
+
[this.messages],
|
|
200
|
+
(batchData, actions, ctx) => {
|
|
201
|
+
const data = batchData.map(
|
|
202
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
203
|
+
);
|
|
204
|
+
const entries = data[0];
|
|
205
|
+
if (entries.length === 0) {
|
|
206
|
+
actions.down([[RESOLVED]]);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
actions.emit(entries[entries.length - 1]);
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "latest",
|
|
213
|
+
describeKind: "derived",
|
|
214
|
+
meta: aiMeta("chat_latest")
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
this.add(this.latest, { name: "latest" });
|
|
218
|
+
this.addDisposer(keepalive(this.latest));
|
|
219
|
+
this.messageCount = node2(
|
|
220
|
+
[this.messages],
|
|
221
|
+
(batchData, actions, ctx) => {
|
|
222
|
+
const data = batchData.map(
|
|
223
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
224
|
+
);
|
|
225
|
+
actions.emit(data[0].length);
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "messageCount",
|
|
229
|
+
describeKind: "derived",
|
|
230
|
+
meta: aiMeta("chat_message_count"),
|
|
231
|
+
initial: 0
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
this.add(this.messageCount, { name: "messageCount" });
|
|
235
|
+
this.addDisposer(keepalive(this.messageCount));
|
|
236
|
+
}
|
|
237
|
+
append(role, content, extra) {
|
|
238
|
+
this._log.append({ role, content, ...extra });
|
|
239
|
+
}
|
|
240
|
+
appendToolResult(callId, content) {
|
|
241
|
+
this._log.append({ role: "tool", content, toolCallId: callId });
|
|
242
|
+
}
|
|
243
|
+
clear() {
|
|
244
|
+
this._log.clear();
|
|
245
|
+
}
|
|
246
|
+
allMessages() {
|
|
247
|
+
return this.messages.cache;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
function chatStream(name, opts) {
|
|
251
|
+
return new ChatStreamGraph(name, opts);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/utils/ai/agents/tool-execution.ts
|
|
255
|
+
import { node as node3 } from "@graphrefly/pure-ts/core";
|
|
256
|
+
import { rescue, switchMap } from "@graphrefly/pure-ts/extra";
|
|
257
|
+
function toolExecution(opts) {
|
|
258
|
+
const { toolCalls, tools } = opts;
|
|
259
|
+
const retryCount = opts.retryCount ?? 1;
|
|
260
|
+
const onError = opts.onError ?? "rescue";
|
|
261
|
+
const batchEquals = (a, b) => {
|
|
262
|
+
if (a === b) return true;
|
|
263
|
+
if (a.length !== b.length) return false;
|
|
264
|
+
for (let i = 0; i < a.length; i++) {
|
|
265
|
+
const ai = a[i];
|
|
266
|
+
const bi = b[i];
|
|
267
|
+
if (ai?.id !== bi?.id) return false;
|
|
268
|
+
if (ai?.content !== bi?.content) return false;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
};
|
|
272
|
+
return switchMap(toolCalls, (calls) => {
|
|
273
|
+
if (calls == null || calls.length === 0) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
"toolExecution: received an empty tool-call batch as DATA \u2014 callers must upstream-filter empty batches (emit RESOLVED) so switchMap is only dispatched for non-empty batches."
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
const perCall = calls.map((call) => executeOne(call, tools, retryCount, onError));
|
|
279
|
+
return node3(
|
|
280
|
+
perCall,
|
|
281
|
+
(batchData, actions, ctx) => {
|
|
282
|
+
const data = batchData.map(
|
|
283
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
284
|
+
);
|
|
285
|
+
actions.emit(data);
|
|
286
|
+
},
|
|
287
|
+
{ describeKind: "derived", name: "toolExecution::batch", equals: batchEquals }
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
function executeOne(call, tools, retryCount, onError) {
|
|
292
|
+
const attempted = retry(() => tools.executeReactive(call.name, call.arguments), {
|
|
293
|
+
count: retryCount
|
|
294
|
+
}).node;
|
|
295
|
+
const onSuccess = node3(
|
|
296
|
+
[attempted],
|
|
297
|
+
(batchData, actions, ctx) => {
|
|
298
|
+
const data = batchData.map(
|
|
299
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
300
|
+
);
|
|
301
|
+
const val = data[0];
|
|
302
|
+
actions.emit({
|
|
303
|
+
id: call.id,
|
|
304
|
+
content: typeof val === "string" ? val : JSON.stringify(val)
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
{ describeKind: "derived" }
|
|
308
|
+
);
|
|
309
|
+
if (onError === "propagate") return onSuccess;
|
|
310
|
+
return rescue(onSuccess, (err) => ({
|
|
311
|
+
id: call.id,
|
|
312
|
+
content: JSON.stringify({ error: String(err) })
|
|
313
|
+
}));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/utils/ai/agents/tool-registry.ts
|
|
317
|
+
import { ERROR as ERROR2, node as node4 } from "@graphrefly/pure-ts/core";
|
|
318
|
+
import { fromAsyncIter, fromPromise, keepalive as keepalive2, reactiveMap } from "@graphrefly/pure-ts/extra";
|
|
319
|
+
import { Graph as Graph2 } from "@graphrefly/pure-ts/graph";
|
|
320
|
+
var ToolRegistryGraph = class extends Graph2 {
|
|
321
|
+
definitions;
|
|
322
|
+
schemas;
|
|
323
|
+
_bundle;
|
|
324
|
+
constructor(name, opts = {}) {
|
|
325
|
+
super(name, opts.graph);
|
|
326
|
+
this._bundle = reactiveMap({
|
|
327
|
+
name: "definitions"
|
|
328
|
+
});
|
|
329
|
+
this.definitions = this._bundle.entries;
|
|
330
|
+
this.add(this.definitions, { name: "definitions" });
|
|
331
|
+
this.schemas = node4(
|
|
332
|
+
[this.definitions],
|
|
333
|
+
(batchData, actions, ctx) => {
|
|
334
|
+
const data = batchData.map(
|
|
335
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
336
|
+
);
|
|
337
|
+
const defs = data[0];
|
|
338
|
+
actions.emit([...(defs ?? /* @__PURE__ */ new Map()).values()]);
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: "schemas",
|
|
342
|
+
describeKind: "derived",
|
|
343
|
+
meta: aiMeta("tool_schemas"),
|
|
344
|
+
initial: []
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
this.add(this.schemas, { name: "schemas" });
|
|
348
|
+
this.addDisposer(keepalive2(this.schemas));
|
|
349
|
+
}
|
|
350
|
+
register(tool) {
|
|
351
|
+
this._bundle.set(tool.name, tool);
|
|
352
|
+
}
|
|
353
|
+
unregister(name) {
|
|
354
|
+
this._bundle.delete(name);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Reactive execution — returns a `Node<unknown>` that emits the handler
|
|
358
|
+
* result. The returned node is a `producer` that:
|
|
359
|
+
*
|
|
360
|
+
* 1. Mints a per-call `AbortController` whose `signal` is threaded into
|
|
361
|
+
* the handler call AND into `fromAny` (so a `fromPromise` /
|
|
362
|
+
* `fromAsyncIter` inner abandons cleanly when the consumer
|
|
363
|
+
* unsubscribes).
|
|
364
|
+
* 2. Runs `tool.handler(args, {signal})` inside a try/catch — a
|
|
365
|
+
* synchronous throw surfaces as `[[ERROR, err]]` downstream instead
|
|
366
|
+
* of escaping the producer.
|
|
367
|
+
* 3. Forwards every message from the inner `fromAny` chain to the
|
|
368
|
+
* producer's outputs.
|
|
369
|
+
* 4. On teardown (subscriber count drops to zero, e.g. `switchMap`
|
|
370
|
+
* supersede) calls `ac.abort()` and unsubscribes the inner.
|
|
371
|
+
* Signal-aware handlers (e.g. `fetch(url, {signal})`) actually stop.
|
|
372
|
+
*
|
|
373
|
+
* Each call mints a fresh node tied to a fresh `handler(args, ...)`
|
|
374
|
+
* invocation — call `executeReactive` again for repeated invocations.
|
|
375
|
+
*
|
|
376
|
+
* @throws `Error` synchronously when `name` is not registered (no node is
|
|
377
|
+
* constructed — the caller gets a pre-wiring failure rather than a
|
|
378
|
+
* silent ERROR wave on an empty graph).
|
|
379
|
+
*/
|
|
380
|
+
executeReactive(name, args) {
|
|
381
|
+
const tool = this._bundle.get(name);
|
|
382
|
+
if (!tool) throw new Error(`toolRegistry: unknown tool "${name}"`);
|
|
383
|
+
return node4(
|
|
384
|
+
[],
|
|
385
|
+
(_data, actions) => {
|
|
386
|
+
const ac = new AbortController();
|
|
387
|
+
let inner;
|
|
388
|
+
try {
|
|
389
|
+
const raw = tool.handler(args, { signal: ac.signal });
|
|
390
|
+
inner = handlerResultToNode(raw, ac.signal);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
actions.down([[ERROR2, err]]);
|
|
393
|
+
return () => {
|
|
394
|
+
ac.abort();
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const unsub = inner.subscribe((batch2) => {
|
|
398
|
+
actions.down(batch2);
|
|
399
|
+
});
|
|
400
|
+
return () => {
|
|
401
|
+
ac.abort();
|
|
402
|
+
unsub();
|
|
403
|
+
};
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: `executeReactive::${name}`,
|
|
407
|
+
describeKind: "producer",
|
|
408
|
+
meta: aiMeta("tool_execute_reactive")
|
|
409
|
+
}
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
getDefinition(name) {
|
|
413
|
+
return this._bundle.entries.cache?.get(name);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
function toolRegistry(name, opts) {
|
|
417
|
+
return new ToolRegistryGraph(name, opts);
|
|
418
|
+
}
|
|
419
|
+
function handlerResultToNode(raw, signal) {
|
|
420
|
+
if (isNodeLike(raw)) {
|
|
421
|
+
return raw;
|
|
422
|
+
}
|
|
423
|
+
if (raw != null && typeof raw.then === "function") {
|
|
424
|
+
return fromPromise(raw, { signal });
|
|
425
|
+
}
|
|
426
|
+
if (raw != null && typeof raw === "object" && Symbol.asyncIterator in raw) {
|
|
427
|
+
return fromAsyncIter(raw, { signal });
|
|
428
|
+
}
|
|
429
|
+
return fromPromise(Promise.resolve(raw), { signal });
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// src/utils/ai/memory/memory-composers.ts
|
|
433
|
+
import { batch, DATA as DATA2, monotonicNs, node as node5 } from "@graphrefly/pure-ts/core";
|
|
434
|
+
import {
|
|
435
|
+
fromAny as fromAny2,
|
|
436
|
+
keepalive as keepalive3,
|
|
437
|
+
reactiveMap as reactiveMap2
|
|
438
|
+
} from "@graphrefly/pure-ts/extra";
|
|
439
|
+
import { Graph as Graph3 } from "@graphrefly/pure-ts/graph";
|
|
440
|
+
var MemoryWithVectorsGraph = class extends Graph3 {
|
|
441
|
+
vectors;
|
|
442
|
+
constructor(opts) {
|
|
443
|
+
super(opts.name ?? "memory-vectors", opts.graph);
|
|
444
|
+
this.vectors = vectorIndex({ dimension: opts.dimension });
|
|
445
|
+
this.mount("vectorIndex", this.vectors);
|
|
446
|
+
const embedFn = opts.embedFn;
|
|
447
|
+
const vectorsRef = this.vectors;
|
|
448
|
+
const indexer = node5(
|
|
449
|
+
[opts.store.store.entries],
|
|
450
|
+
(batchData, _actions, ctx) => {
|
|
451
|
+
const data = batchData.map(
|
|
452
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
453
|
+
);
|
|
454
|
+
const storeMap = data[0] ?? /* @__PURE__ */ new Map();
|
|
455
|
+
for (const [key, mem] of storeMap) {
|
|
456
|
+
const vec = embedFn(mem);
|
|
457
|
+
if (vec) vectorsRef.upsert(key, vec, mem);
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
{ name: "indexer", describeKind: "effect" }
|
|
461
|
+
);
|
|
462
|
+
this.add(indexer, { name: "indexer" });
|
|
463
|
+
this.addDisposer(keepalive3(indexer));
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
function memoryWithVectors(opts) {
|
|
467
|
+
return new MemoryWithVectorsGraph(opts);
|
|
468
|
+
}
|
|
469
|
+
var MemoryWithKGGraph = class extends Graph3 {
|
|
470
|
+
kg;
|
|
471
|
+
constructor(opts) {
|
|
472
|
+
const name = opts.name ?? "memory-kg";
|
|
473
|
+
super(name, opts.graph);
|
|
474
|
+
const kgName = opts.kgName ?? `${name}-kg`;
|
|
475
|
+
const mountPath = opts.mountPath ?? "knowledge-kg";
|
|
476
|
+
this.kg = knowledgeGraph(kgName);
|
|
477
|
+
this.mount(mountPath, this.kg);
|
|
478
|
+
if (!opts.entityFn) return;
|
|
479
|
+
const entityFn = opts.entityFn;
|
|
480
|
+
const kgRef = this.kg;
|
|
481
|
+
const indexer = node5(
|
|
482
|
+
[opts.store.store.entries],
|
|
483
|
+
(batchData, _actions, ctx) => {
|
|
484
|
+
const data = batchData.map(
|
|
485
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
486
|
+
);
|
|
487
|
+
const storeMap = data[0] ?? /* @__PURE__ */ new Map();
|
|
488
|
+
for (const [key, mem] of storeMap) {
|
|
489
|
+
const extracted = entityFn(key, mem);
|
|
490
|
+
if (!extracted) continue;
|
|
491
|
+
for (const ent of extracted.entities ?? []) {
|
|
492
|
+
kgRef.upsertEntity(ent.id, ent.value);
|
|
493
|
+
}
|
|
494
|
+
for (const rel of extracted.relations ?? []) {
|
|
495
|
+
kgRef.link(rel.from, rel.to, rel.relation, rel.weight);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
{ name: "indexer", describeKind: "effect" }
|
|
500
|
+
);
|
|
501
|
+
this.add(indexer, { name: "indexer" });
|
|
502
|
+
this.addDisposer(keepalive3(indexer));
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
function memoryWithKG(opts) {
|
|
506
|
+
return new MemoryWithKGGraph(opts);
|
|
507
|
+
}
|
|
508
|
+
var MemoryWithTiersGraph = class extends Graph3 {
|
|
509
|
+
store;
|
|
510
|
+
tiers;
|
|
511
|
+
compact;
|
|
512
|
+
size;
|
|
513
|
+
permanent;
|
|
514
|
+
permanentKeys;
|
|
515
|
+
entryCreatedAtNs;
|
|
516
|
+
constructor(opts) {
|
|
517
|
+
super(opts.name ?? "memory-tiers", opts.graph);
|
|
518
|
+
const decayRate = opts.decayRate ?? DEFAULT_DECAY_RATE;
|
|
519
|
+
const maxActive = opts.maxActive ?? 1e3;
|
|
520
|
+
const archiveThreshold = opts.archiveThreshold ?? 0.1;
|
|
521
|
+
const permanentFilter = opts.permanentFilter ?? (() => false);
|
|
522
|
+
this.permanent = collection("permanent", { ranked: false });
|
|
523
|
+
this.mount("permanent", this.permanent);
|
|
524
|
+
this.permanentKeys = reactiveMap2({ name: "permanentKeys" });
|
|
525
|
+
this.add(this.permanentKeys.entries, { name: "permanentKeys" });
|
|
526
|
+
this.entryCreatedAtNs = reactiveMap2({ name: "entryCreatedAtNs" });
|
|
527
|
+
this.add(this.entryCreatedAtNs.entries, { name: "entryCreatedAtNs" });
|
|
528
|
+
let contextNode;
|
|
529
|
+
if (opts.context) {
|
|
530
|
+
contextNode = fromAny2(opts.context);
|
|
531
|
+
} else {
|
|
532
|
+
contextNode = node5([], { initial: null });
|
|
533
|
+
this.add(contextNode, { name: "context" });
|
|
534
|
+
}
|
|
535
|
+
let latestCtx = contextNode.cache;
|
|
536
|
+
const ctxUnsub = contextNode.subscribe((msgs) => {
|
|
537
|
+
for (const m of msgs) if (m[0] === DATA2) latestCtx = m[1];
|
|
538
|
+
});
|
|
539
|
+
this.addDisposer(ctxUnsub);
|
|
540
|
+
const permanentKeysRef = this.permanentKeys;
|
|
541
|
+
const entryCreatedAtNsRef = this.entryCreatedAtNs;
|
|
542
|
+
const score = opts.score;
|
|
543
|
+
const retention = {
|
|
544
|
+
score: (key, value) => {
|
|
545
|
+
if (permanentFilter(key, value)) return Number.POSITIVE_INFINITY;
|
|
546
|
+
if (permanentKeysRef.has(key)) return Number.POSITIVE_INFINITY;
|
|
547
|
+
const nowNs = monotonicNs();
|
|
548
|
+
const createdNs = entryCreatedAtNsRef.get(key) ?? nowNs;
|
|
549
|
+
const ageSeconds = Number(nowNs - createdNs) / 1e9;
|
|
550
|
+
return decay(score(value, latestCtx), ageSeconds, decayRate);
|
|
551
|
+
},
|
|
552
|
+
archiveThreshold,
|
|
553
|
+
maxSize: maxActive
|
|
554
|
+
};
|
|
555
|
+
this.store = distill(opts.source, opts.extractFn, {
|
|
556
|
+
score: opts.score,
|
|
557
|
+
cost: opts.cost,
|
|
558
|
+
...opts.budget !== void 0 ? { budget: opts.budget } : {},
|
|
559
|
+
...opts.evict !== void 0 ? { evict: opts.evict } : {},
|
|
560
|
+
...opts.consolidate !== void 0 ? { consolidate: opts.consolidate } : {},
|
|
561
|
+
...opts.consolidateTrigger !== void 0 ? { consolidateTrigger: opts.consolidateTrigger } : {},
|
|
562
|
+
...opts.context !== void 0 ? { context: opts.context } : {},
|
|
563
|
+
mapOptions: { retention }
|
|
564
|
+
});
|
|
565
|
+
this.add(this.store.store.entries, { name: "store" });
|
|
566
|
+
this.compact = this.store.compact;
|
|
567
|
+
this.add(this.compact, { name: "compact" });
|
|
568
|
+
this.size = this.store.size;
|
|
569
|
+
this.add(this.size, { name: "size" });
|
|
570
|
+
const storeRef = this.store;
|
|
571
|
+
const tierOf = (key) => {
|
|
572
|
+
if (permanentKeysRef.has(key)) return "permanent";
|
|
573
|
+
const m = storeRef.store.entries.cache ?? /* @__PURE__ */ new Map();
|
|
574
|
+
if (m.has(key)) return "active";
|
|
575
|
+
return "archived";
|
|
576
|
+
};
|
|
577
|
+
const permanentRef = this.permanent;
|
|
578
|
+
const markPermanent = (key, value) => {
|
|
579
|
+
permanentKeysRef.set(key, true);
|
|
580
|
+
permanentRef.upsert(key, value);
|
|
581
|
+
};
|
|
582
|
+
const syncCreatedAt = node5(
|
|
583
|
+
[this.store.store.entries],
|
|
584
|
+
(batchData, _actions, ctx) => {
|
|
585
|
+
const data = batchData.map(
|
|
586
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
587
|
+
);
|
|
588
|
+
const map = data[0] ?? /* @__PURE__ */ new Map();
|
|
589
|
+
const nowNs = monotonicNs();
|
|
590
|
+
const toAdd = [];
|
|
591
|
+
for (const key of map.keys()) {
|
|
592
|
+
if (!entryCreatedAtNsRef.has(key)) toAdd.push(key);
|
|
593
|
+
}
|
|
594
|
+
if (toAdd.length > 0) {
|
|
595
|
+
batch(() => {
|
|
596
|
+
for (const key of toAdd) entryCreatedAtNsRef.set(key, nowNs);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
{ name: "entryCreatedAtNs/sync", describeKind: "effect" }
|
|
601
|
+
);
|
|
602
|
+
this.add(syncCreatedAt, { name: "entryCreatedAtNs/sync" });
|
|
603
|
+
this.addDisposer(keepalive3(syncCreatedAt));
|
|
604
|
+
const entriesUnsub = this.store.store.entries.subscribe((msgs) => {
|
|
605
|
+
for (const m of msgs) {
|
|
606
|
+
if (m[0] !== DATA2) continue;
|
|
607
|
+
const map = m[1];
|
|
608
|
+
const created = entryCreatedAtNsRef.entries.cache;
|
|
609
|
+
if (created == null) continue;
|
|
610
|
+
const toDelete = [];
|
|
611
|
+
for (const key of created.keys()) {
|
|
612
|
+
if (!map.has(key)) toDelete.push(key);
|
|
613
|
+
}
|
|
614
|
+
if (toDelete.length > 0) {
|
|
615
|
+
batch(() => {
|
|
616
|
+
for (const key of toDelete) entryCreatedAtNsRef.delete(key);
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
this.addDisposer(entriesUnsub);
|
|
622
|
+
const promoter = node5(
|
|
623
|
+
[this.store.store.entries],
|
|
624
|
+
(batchData, _actions, ctx) => {
|
|
625
|
+
const data = batchData.map(
|
|
626
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
627
|
+
);
|
|
628
|
+
const map = data[0] ?? /* @__PURE__ */ new Map();
|
|
629
|
+
for (const [key, mem] of map) {
|
|
630
|
+
if (permanentKeysRef.has(key)) continue;
|
|
631
|
+
if (permanentFilter(key, mem)) {
|
|
632
|
+
batch(() => {
|
|
633
|
+
markPermanent(key, mem);
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
{ name: "promoter", describeKind: "effect" }
|
|
639
|
+
);
|
|
640
|
+
this.add(promoter, { name: "promoter" });
|
|
641
|
+
this.addDisposer(keepalive3(promoter));
|
|
642
|
+
let archiveHandle = null;
|
|
643
|
+
if (opts.archiveTier) {
|
|
644
|
+
archiveHandle = this.attachSnapshotStorage(
|
|
645
|
+
[{ snapshot: opts.archiveTier }],
|
|
646
|
+
opts.archiveStorageOptions ?? {}
|
|
647
|
+
);
|
|
648
|
+
this.addDisposer(() => archiveHandle?.dispose());
|
|
649
|
+
}
|
|
650
|
+
this.tiers = {
|
|
651
|
+
permanent: this.permanent,
|
|
652
|
+
activeEntries: this.store.store.entries,
|
|
653
|
+
archiveHandle,
|
|
654
|
+
tierOf,
|
|
655
|
+
markPermanent
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
function memoryWithTiers(opts) {
|
|
660
|
+
return new MemoryWithTiersGraph(opts);
|
|
661
|
+
}
|
|
662
|
+
function sharedPrefixDepth(q, e) {
|
|
663
|
+
if (!q || !e) return 0;
|
|
664
|
+
const n = Math.min(q.length, e.length);
|
|
665
|
+
let i = 0;
|
|
666
|
+
while (i < n && q[i] === e[i]) i++;
|
|
667
|
+
return i;
|
|
668
|
+
}
|
|
669
|
+
var packedEquals = (a, b) => {
|
|
670
|
+
if (a === b) return true;
|
|
671
|
+
if (a.length !== b.length) return false;
|
|
672
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
673
|
+
return true;
|
|
674
|
+
};
|
|
675
|
+
var MemoryRetrievalGraph = class extends Graph3 {
|
|
676
|
+
_store;
|
|
677
|
+
_vectors;
|
|
678
|
+
_kg;
|
|
679
|
+
_opts;
|
|
680
|
+
_contextNode;
|
|
681
|
+
_topK;
|
|
682
|
+
_graphDepth;
|
|
683
|
+
_budget;
|
|
684
|
+
_contextWeight;
|
|
685
|
+
_retrieveSeq = 0;
|
|
686
|
+
constructor(opts) {
|
|
687
|
+
super(opts.name ?? "memory-retrieval", opts.graph);
|
|
688
|
+
this._store = opts.store;
|
|
689
|
+
this._vectors = opts.vectors ?? null;
|
|
690
|
+
this._kg = opts.kg ?? null;
|
|
691
|
+
this._opts = opts;
|
|
692
|
+
this._topK = opts.topK ?? 20;
|
|
693
|
+
this._graphDepth = opts.graphDepth ?? 1;
|
|
694
|
+
this._budget = opts.budget ?? 2e3;
|
|
695
|
+
this._contextWeight = opts.contextWeight ?? 0;
|
|
696
|
+
if (opts.context) {
|
|
697
|
+
this._contextNode = fromAny2(opts.context);
|
|
698
|
+
} else {
|
|
699
|
+
this._contextNode = this.state("_context", null);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
_runRetrieval(storeMap, ctx, query) {
|
|
703
|
+
const opts = this._opts;
|
|
704
|
+
const candidateMap = /* @__PURE__ */ new Map();
|
|
705
|
+
let vectorCandidates = [];
|
|
706
|
+
if (this._vectors && query.vector) {
|
|
707
|
+
const q = query.vector;
|
|
708
|
+
const snapshot = this._vectors.entries.cache;
|
|
709
|
+
if (snapshot && snapshot.size > 0 && this._topK > 0) {
|
|
710
|
+
const scored = [...snapshot.values()].map(
|
|
711
|
+
(row) => ({
|
|
712
|
+
id: row.id,
|
|
713
|
+
score: cosineSimilarity(q, row.vector),
|
|
714
|
+
...row.meta !== void 0 ? { meta: row.meta } : {}
|
|
715
|
+
})
|
|
716
|
+
).sort((a, b) => b.score - a.score).slice(0, this._topK);
|
|
717
|
+
vectorCandidates = scored;
|
|
718
|
+
for (const vc of vectorCandidates) {
|
|
719
|
+
const mem = storeMap.get(vc.id);
|
|
720
|
+
if (mem) candidateMap.set(vc.id, { value: mem, sources: /* @__PURE__ */ new Set(["vector"]) });
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
const graphExpanded = [];
|
|
725
|
+
if (this._kg) {
|
|
726
|
+
const adjOut = this._kg.adjacencyOut.cache;
|
|
727
|
+
const adjIn = this._kg.adjacencyIn.cache;
|
|
728
|
+
const seedIds = [...query.entityIds ?? [], ...[...candidateMap.keys()]];
|
|
729
|
+
const visited = /* @__PURE__ */ new Set();
|
|
730
|
+
let frontier = seedIds;
|
|
731
|
+
for (let depth = 0; depth < this._graphDepth; depth++) {
|
|
732
|
+
const nextFrontier = [];
|
|
733
|
+
for (const id of frontier) {
|
|
734
|
+
if (visited.has(id)) continue;
|
|
735
|
+
visited.add(id);
|
|
736
|
+
const outEdges = adjOut?.get(id) ?? [];
|
|
737
|
+
const inEdges = adjIn?.get(id) ?? [];
|
|
738
|
+
for (const edge of outEdges) {
|
|
739
|
+
const targetId = edge.to;
|
|
740
|
+
if (!visited.has(targetId)) {
|
|
741
|
+
nextFrontier.push(targetId);
|
|
742
|
+
const mem = storeMap.get(targetId);
|
|
743
|
+
if (mem) {
|
|
744
|
+
const existing = candidateMap.get(targetId);
|
|
745
|
+
if (existing) existing.sources.add("graph");
|
|
746
|
+
else candidateMap.set(targetId, { value: mem, sources: /* @__PURE__ */ new Set(["graph"]) });
|
|
747
|
+
graphExpanded.push(targetId);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
for (const edge of inEdges) {
|
|
752
|
+
const targetId = edge.from;
|
|
753
|
+
if (!visited.has(targetId)) {
|
|
754
|
+
nextFrontier.push(targetId);
|
|
755
|
+
const mem = storeMap.get(targetId);
|
|
756
|
+
if (mem) {
|
|
757
|
+
const existing = candidateMap.get(targetId);
|
|
758
|
+
if (existing) existing.sources.add("graph");
|
|
759
|
+
else candidateMap.set(targetId, { value: mem, sources: /* @__PURE__ */ new Set(["graph"]) });
|
|
760
|
+
graphExpanded.push(targetId);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
frontier = nextFrontier;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
for (const [key, mem] of storeMap) {
|
|
769
|
+
if (!candidateMap.has(key)) {
|
|
770
|
+
candidateMap.set(key, { value: mem, sources: /* @__PURE__ */ new Set(["store"]) });
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const qDepth = query.context?.length ?? 0;
|
|
774
|
+
const ranked = [];
|
|
775
|
+
for (const [key, { value, sources }] of candidateMap) {
|
|
776
|
+
const entryContext = opts.contextOf ? opts.contextOf(value) : void 0;
|
|
777
|
+
let score = opts.score(value, ctx);
|
|
778
|
+
if (this._contextWeight > 0 && qDepth > 0) {
|
|
779
|
+
const shared = sharedPrefixDepth(query.context, entryContext);
|
|
780
|
+
if (shared > 0) score = score * (1 + this._contextWeight * shared / qDepth);
|
|
781
|
+
}
|
|
782
|
+
const entry = entryContext ? { key, value, score, sources: [...sources], context: entryContext } : { key, value, score, sources: [...sources] };
|
|
783
|
+
ranked.push(entry);
|
|
784
|
+
}
|
|
785
|
+
ranked.sort((a, b) => b.score - a.score);
|
|
786
|
+
const packed = [];
|
|
787
|
+
let usedBudget = 0;
|
|
788
|
+
for (const entry of ranked) {
|
|
789
|
+
const c = opts.cost(entry.value);
|
|
790
|
+
if (usedBudget + c > this._budget && packed.length > 0) break;
|
|
791
|
+
packed.push(entry);
|
|
792
|
+
usedBudget += c;
|
|
793
|
+
}
|
|
794
|
+
return { packed, trace: { vectorCandidates, graphExpanded, ranked, packed } };
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Reactive consumer API — chain into the graph.
|
|
798
|
+
*
|
|
799
|
+
* Each call constructs its own per-input subgraph mounted at
|
|
800
|
+
* `retrieve_${id}` (auto-incrementing within this MemoryRetrievalGraph
|
|
801
|
+
* instance) with named nodes:
|
|
802
|
+
*
|
|
803
|
+
* - `context` — `fromAny(queryInput)` projection (so the input node is
|
|
804
|
+
* visible to `describe()` even when callers pass a raw value).
|
|
805
|
+
* - `result` — pure derived `{ packed, trace }`.
|
|
806
|
+
* - `projection` — the packed-array node returned to the caller.
|
|
807
|
+
*
|
|
808
|
+
* `result` declares the substrate's `store.entries`, the optional
|
|
809
|
+
* `context` Node, the local `context` projection, and (when configured)
|
|
810
|
+
* `vectors.entries` / `kg.adjacencyOut` / `kg.adjacencyIn` as deps —
|
|
811
|
+
* so vector upserts and KG mutations re-trigger retrieval even when
|
|
812
|
+
* the input is unchanged.
|
|
813
|
+
*
|
|
814
|
+
* **Lifecycle contract (DS-13.5.C, 2026-05-01).** The per-call subgraph
|
|
815
|
+
* stays mounted while the returned `projection` has at least one
|
|
816
|
+
* subscriber. When the last subscriber unsubscribes, projection's
|
|
817
|
+
* `deactivate` cleanup hook fires (canonical "last unsubscribe" signal
|
|
818
|
+
* via the existing `NodeFnCleanup.onDeactivation` protocol), which calls
|
|
819
|
+
* `parent.remove(retrieve_${id})` and tears the per-call topology
|
|
820
|
+
* down via TEARDOWN cascade (post-DS-13.5.A Q16, COMPLETE auto-precedes).
|
|
821
|
+
*
|
|
822
|
+
* **Single-shot lifecycle.** This auto-unmount is keyed to the FIRST
|
|
823
|
+
* last-unsubscribe event — projection is non-resubscribable from the
|
|
824
|
+
* caller's perspective. Callers who need to subscribe / unsubscribe /
|
|
825
|
+
* re-subscribe should hold a long-lived subscription externally (e.g.
|
|
826
|
+
* `keepalive(projection)`) or call `retrieveReactive(...)` again to
|
|
827
|
+
* mount a fresh per-call subgraph.
|
|
828
|
+
*
|
|
829
|
+
* **Caller obligation.** Either subscribe to `projection` (and
|
|
830
|
+
* eventually unsubscribe to trigger cleanup) OR drop the returned
|
|
831
|
+
* reference without subscribing — in the no-subscribe case the
|
|
832
|
+
* subgraph is dormant (no compute fires) and a parent `destroy()`
|
|
833
|
+
* cascade reclaims it. Holding `projection` without subscribing AND
|
|
834
|
+
* without ever destroying the parent is the leak case the JSDoc above
|
|
835
|
+
* the C1 rework covers.
|
|
836
|
+
*
|
|
837
|
+
* One-shot callers use `awaitSettled(retrieveReactive(input))`.
|
|
838
|
+
*/
|
|
839
|
+
retrieveReactive(queryInput) {
|
|
840
|
+
const id = ++this._retrieveSeq;
|
|
841
|
+
const segment = `retrieve_${id}`;
|
|
842
|
+
const sub = new Graph3(segment);
|
|
843
|
+
const inputNode = fromAny2(queryInput);
|
|
844
|
+
const localContext = sub.derived(
|
|
845
|
+
"context",
|
|
846
|
+
[inputNode],
|
|
847
|
+
(batchData, ctx) => {
|
|
848
|
+
const data = batchData.map(
|
|
849
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
850
|
+
);
|
|
851
|
+
return [data[0] ?? null];
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
meta: aiMeta("retrieval_query_input"),
|
|
855
|
+
initial: null
|
|
856
|
+
}
|
|
857
|
+
);
|
|
858
|
+
const resultDeps = [
|
|
859
|
+
this._store.store.entries,
|
|
860
|
+
this._contextNode,
|
|
861
|
+
localContext
|
|
862
|
+
];
|
|
863
|
+
if (this._vectors) resultDeps.push(this._vectors.entries);
|
|
864
|
+
if (this._kg) {
|
|
865
|
+
resultDeps.push(this._kg.adjacencyOut);
|
|
866
|
+
resultDeps.push(this._kg.adjacencyIn);
|
|
867
|
+
}
|
|
868
|
+
const result = sub.derived(
|
|
869
|
+
"result",
|
|
870
|
+
resultDeps,
|
|
871
|
+
(batchData, ctx) => {
|
|
872
|
+
const data = batchData.map(
|
|
873
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
874
|
+
);
|
|
875
|
+
const query = data[2];
|
|
876
|
+
if (query == null) {
|
|
877
|
+
return [{ packed: [], trace: null }];
|
|
878
|
+
}
|
|
879
|
+
const storeMap = data[0] ?? /* @__PURE__ */ new Map();
|
|
880
|
+
const { packed, trace } = this._runRetrieval(storeMap, data[1], query);
|
|
881
|
+
return [{ packed, trace }];
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
meta: aiMeta("retrieval_reactive_result"),
|
|
885
|
+
initial: { packed: [], trace: null }
|
|
886
|
+
}
|
|
887
|
+
);
|
|
888
|
+
const projection = node5(
|
|
889
|
+
[result],
|
|
890
|
+
(batchData, actions, ctx) => {
|
|
891
|
+
const data = batchData.map(
|
|
892
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
893
|
+
);
|
|
894
|
+
actions.emit(data[0].packed);
|
|
895
|
+
return {
|
|
896
|
+
onDeactivation: () => {
|
|
897
|
+
try {
|
|
898
|
+
this.remove(segment);
|
|
899
|
+
} catch {
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
name: "projection",
|
|
906
|
+
describeKind: "derived",
|
|
907
|
+
meta: aiMeta("retrieval_reactive"),
|
|
908
|
+
initial: [],
|
|
909
|
+
equals: packedEquals
|
|
910
|
+
}
|
|
911
|
+
);
|
|
912
|
+
sub.add(projection, { name: "projection" });
|
|
913
|
+
this.mount(segment, sub);
|
|
914
|
+
return projection;
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
function memoryRetrieval(opts) {
|
|
918
|
+
return new MemoryRetrievalGraph(opts);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/utils/ai/prompts/prompt-node.ts
|
|
922
|
+
import { COMPLETE as COMPLETE2, DATA as DATA3, ERROR as ERROR3, node as node6 } from "@graphrefly/pure-ts/core";
|
|
923
|
+
import { fromAny as fromAny3, switchMap as switchMap2 } from "@graphrefly/pure-ts/extra";
|
|
924
|
+
function extractContent(resp) {
|
|
925
|
+
if (resp != null && typeof resp === "object" && "content" in resp) {
|
|
926
|
+
return String(resp.content);
|
|
927
|
+
}
|
|
928
|
+
if (typeof resp === "string") return resp;
|
|
929
|
+
return String(resp);
|
|
930
|
+
}
|
|
931
|
+
function previewContent(text, max = 200) {
|
|
932
|
+
if (text.length <= max) return text;
|
|
933
|
+
return `${text.slice(0, max)}\u2026`;
|
|
934
|
+
}
|
|
935
|
+
function promptNode(adapter, deps, prompt, opts) {
|
|
936
|
+
const format = opts?.format ?? "text";
|
|
937
|
+
const baseName = opts?.name ?? "prompt_node";
|
|
938
|
+
if (opts?.tools !== void 0 && format !== "raw") {
|
|
939
|
+
console.warn(
|
|
940
|
+
"promptNode: `tools` is set but `format !== 'raw'`. Tool calls in the response will be silently dropped \u2014 set `format: 'raw'` to receive the full LLMResponse with `toolCalls`."
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
const userDepsLength = deps.length;
|
|
944
|
+
const allDeps = opts?.tools !== void 0 ? [...deps, opts.tools] : deps;
|
|
945
|
+
const messagesNode = node6(
|
|
946
|
+
allDeps,
|
|
947
|
+
(batchData, actions, ctx) => {
|
|
948
|
+
const data = batchData.map(
|
|
949
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
950
|
+
);
|
|
951
|
+
const userValues = data.slice(0, userDepsLength);
|
|
952
|
+
const toolsValue = opts?.tools !== void 0 ? data[userDepsLength] : void 0;
|
|
953
|
+
if (userValues.some((v) => v == null)) {
|
|
954
|
+
actions.emit({ messages: [], tools: toolsValue });
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const text = typeof prompt === "string" ? prompt : prompt(...userValues);
|
|
958
|
+
if (!text) {
|
|
959
|
+
actions.emit({ messages: [], tools: toolsValue });
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
actions.emit({
|
|
963
|
+
messages: [{ role: "user", content: text }],
|
|
964
|
+
tools: toolsValue
|
|
965
|
+
});
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
name: `${baseName}::messages`,
|
|
969
|
+
meta: aiMeta("prompt_node::messages")
|
|
970
|
+
}
|
|
971
|
+
);
|
|
972
|
+
const result = switchMap2(
|
|
973
|
+
messagesNode,
|
|
974
|
+
(envelope) => {
|
|
975
|
+
const { messages: msgs, tools } = envelope;
|
|
976
|
+
if (!msgs || msgs.length === 0) {
|
|
977
|
+
return node6([], { initial: null });
|
|
978
|
+
}
|
|
979
|
+
return node6(
|
|
980
|
+
(_data, actions) => {
|
|
981
|
+
let done = false;
|
|
982
|
+
let cancelled = false;
|
|
983
|
+
let abortDispose;
|
|
984
|
+
const invokeOpts = {
|
|
985
|
+
model: opts?.model,
|
|
986
|
+
temperature: opts?.temperature,
|
|
987
|
+
maxTokens: opts?.maxTokens,
|
|
988
|
+
systemPrompt: opts?.systemPrompt,
|
|
989
|
+
...tools !== void 0 ? { tools } : {}
|
|
990
|
+
};
|
|
991
|
+
if (opts?.abort) {
|
|
992
|
+
const sig = nodeSignal(opts.abort);
|
|
993
|
+
invokeOpts.signal = sig.signal;
|
|
994
|
+
abortDispose = sig.dispose;
|
|
995
|
+
}
|
|
996
|
+
let invokeResult;
|
|
997
|
+
try {
|
|
998
|
+
invokeResult = adapter.invoke(msgs, invokeOpts);
|
|
999
|
+
} catch (err) {
|
|
1000
|
+
done = true;
|
|
1001
|
+
actions.down([[ERROR3, err]]);
|
|
1002
|
+
return () => {
|
|
1003
|
+
abortDispose?.();
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
const callNode = fromAny3(invokeResult);
|
|
1007
|
+
const sub = callNode.subscribe((batch2) => {
|
|
1008
|
+
if (cancelled || done) return;
|
|
1009
|
+
for (const msg of batch2) {
|
|
1010
|
+
if (cancelled || done) return;
|
|
1011
|
+
if (msg[0] === DATA3) {
|
|
1012
|
+
const resp = msg[1];
|
|
1013
|
+
if (format === "raw") {
|
|
1014
|
+
actions.emit(resp);
|
|
1015
|
+
} else {
|
|
1016
|
+
let content;
|
|
1017
|
+
try {
|
|
1018
|
+
content = extractContent(resp);
|
|
1019
|
+
} catch (err) {
|
|
1020
|
+
const wrapped = new Error(
|
|
1021
|
+
`promptNode: failed to extract content from LLM response: ${err.message}`
|
|
1022
|
+
);
|
|
1023
|
+
abortDispose?.();
|
|
1024
|
+
abortDispose = void 0;
|
|
1025
|
+
done = true;
|
|
1026
|
+
actions.down([[ERROR3, wrapped]]);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
try {
|
|
1030
|
+
const parsed = format === "json" ? JSON.parse(stripFences(content)) : content;
|
|
1031
|
+
actions.emit(parsed);
|
|
1032
|
+
} catch (err) {
|
|
1033
|
+
const wrapped = new Error(
|
|
1034
|
+
`promptNode: failed to parse LLM response as JSON: ${err.message}
|
|
1035
|
+
Raw content (first 200 chars): ${previewContent(content)}`
|
|
1036
|
+
);
|
|
1037
|
+
abortDispose?.();
|
|
1038
|
+
abortDispose = void 0;
|
|
1039
|
+
done = true;
|
|
1040
|
+
actions.down([[ERROR3, wrapped]]);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
} else if (msg[0] === ERROR3) {
|
|
1045
|
+
abortDispose?.();
|
|
1046
|
+
abortDispose = void 0;
|
|
1047
|
+
done = true;
|
|
1048
|
+
actions.down([[ERROR3, msg[1]]]);
|
|
1049
|
+
return;
|
|
1050
|
+
} else if (msg[0] === COMPLETE2) {
|
|
1051
|
+
abortDispose?.();
|
|
1052
|
+
abortDispose = void 0;
|
|
1053
|
+
done = true;
|
|
1054
|
+
actions.down([[COMPLETE2]]);
|
|
1055
|
+
return;
|
|
1056
|
+
} else {
|
|
1057
|
+
actions.down([msg]);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
return () => {
|
|
1062
|
+
cancelled = true;
|
|
1063
|
+
sub();
|
|
1064
|
+
abortDispose?.();
|
|
1065
|
+
abortDispose = void 0;
|
|
1066
|
+
};
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
describeKind: "producer",
|
|
1070
|
+
name: `${baseName}::response`,
|
|
1071
|
+
meta: aiMeta("prompt_node::response")
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
name: `${baseName}::output`,
|
|
1077
|
+
meta: opts?.meta ? { ...aiMeta("prompt_node::output"), ...opts.meta } : aiMeta("prompt_node::output")
|
|
1078
|
+
}
|
|
1079
|
+
);
|
|
1080
|
+
return result;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// src/utils/ai/prompts/prompt-call.ts
|
|
1084
|
+
import { node as node7 } from "@graphrefly/pure-ts/core";
|
|
1085
|
+
function promptCall(systemPrompt, buildUserContent, opts, defaultName) {
|
|
1086
|
+
const name = opts.name ?? defaultName;
|
|
1087
|
+
return (input) => {
|
|
1088
|
+
const inputState = node7([], { initial: input });
|
|
1089
|
+
return promptNode(
|
|
1090
|
+
opts.adapter,
|
|
1091
|
+
[inputState],
|
|
1092
|
+
(value) => buildUserContent(value),
|
|
1093
|
+
{
|
|
1094
|
+
name,
|
|
1095
|
+
format: "json",
|
|
1096
|
+
systemPrompt,
|
|
1097
|
+
model: opts.model,
|
|
1098
|
+
temperature: opts.temperature ?? 0,
|
|
1099
|
+
maxTokens: opts.maxTokens
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
function llmExtractor(systemPrompt, opts) {
|
|
1105
|
+
const cap = opts.maxExistingKeys ?? 100;
|
|
1106
|
+
const call = promptCall(
|
|
1107
|
+
systemPrompt,
|
|
1108
|
+
(input) => JSON.stringify({ input: input.raw, existingKeys: input.existingKeys }),
|
|
1109
|
+
opts,
|
|
1110
|
+
"llmExtractor"
|
|
1111
|
+
);
|
|
1112
|
+
return (raw, existing) => {
|
|
1113
|
+
const existingKeys = cap === Number.POSITIVE_INFINITY ? [...existing.keys()] : [...existing.keys()].slice(0, cap);
|
|
1114
|
+
return call({ raw, existingKeys });
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
function llmConsolidator(systemPrompt, opts) {
|
|
1118
|
+
const call = promptCall(
|
|
1119
|
+
systemPrompt,
|
|
1120
|
+
(memories) => JSON.stringify({ memories }),
|
|
1121
|
+
opts,
|
|
1122
|
+
"llmConsolidator"
|
|
1123
|
+
);
|
|
1124
|
+
return (entries) => {
|
|
1125
|
+
const memories = [...entries.entries()].map(([key, value]) => ({ key, value }));
|
|
1126
|
+
return call(memories);
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
export {
|
|
1131
|
+
aiMeta,
|
|
1132
|
+
resolveToolHandlerResult,
|
|
1133
|
+
stripFences,
|
|
1134
|
+
_oneShotLlmCall,
|
|
1135
|
+
ChatStreamGraph,
|
|
1136
|
+
chatStream,
|
|
1137
|
+
toolExecution,
|
|
1138
|
+
ToolRegistryGraph,
|
|
1139
|
+
toolRegistry,
|
|
1140
|
+
MemoryWithVectorsGraph,
|
|
1141
|
+
memoryWithVectors,
|
|
1142
|
+
MemoryWithKGGraph,
|
|
1143
|
+
memoryWithKG,
|
|
1144
|
+
MemoryWithTiersGraph,
|
|
1145
|
+
memoryWithTiers,
|
|
1146
|
+
MemoryRetrievalGraph,
|
|
1147
|
+
memoryRetrieval,
|
|
1148
|
+
promptNode,
|
|
1149
|
+
promptCall,
|
|
1150
|
+
llmExtractor,
|
|
1151
|
+
llmConsolidator
|
|
1152
|
+
};
|
|
1153
|
+
//# sourceMappingURL=chunk-5IMMNARC.js.map
|