@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,1777 @@
|
|
|
1
|
+
import { i as TokenUsage, L as LLMAdapter, g as PricingFn, a as ChatMessage, b as LLMInvokeOptions, k as ToolDefinition, c as LLMResponse, S as StreamDelta } from '../../types-BB5Lw-pB.js';
|
|
2
|
+
export { C as CapabilitiesRegistry, M as ModelCapabilities, d as ModelFeatures, e as ModelLimits, f as ModelPricing, P as PriceBreakdown, h as PricingRegistry, R as Rate, T as TieredRate, j as ToolCall, l as composePricing, m as computePrice, n as createCapabilitiesRegistry, o as createPricingRegistry, p as pricingFor, r as registryPricing, z as zeroPrice } from '../../types-BB5Lw-pB.js';
|
|
3
|
+
import { C as CascadeExhaustionReport } from '../../cascading-CSSbKGrJ.js';
|
|
4
|
+
export { A as AdapterProvider, a as AdapterTier, b as AllTiersExhaustedError, c as CascadingLlmAdapterOptions, d as CreateAdapterOptions, O as OpenAICompatAdapterOptions, e as OpenAICompatPreset, f as OpenAISdkLike, g as cascadingLlmAdapter, h as createAdapter, o as openAICompatAdapter, t as tier } from '../../cascading-CSSbKGrJ.js';
|
|
5
|
+
import { Node, Actor } from '@graphrefly/pure-ts/core';
|
|
6
|
+
import { ReactiveLogBundle, NodeInput } from '@graphrefly/pure-ts/extra';
|
|
7
|
+
import { a as CircuitBreakerOptions, C as CircuitBreaker } from '../../breaker-C9skL3d8.js';
|
|
8
|
+
export { b as CircuitOpenError } from '../../breaker-C9skL3d8.js';
|
|
9
|
+
import { R as RateLimitSignal, A as AdaptiveRateLimiterBundle } from '../../adaptive-rate-limiter-Dch_xYIi.js';
|
|
10
|
+
import { W as WithReplayCacheOptions } from '../../fallback-pIWW8A2d.js';
|
|
11
|
+
export { F as FallbackAdapterOptions, a as FallbackFixture, b as FallbackMissError, c as FallbackMissPolicy, R as ReplayCacheKeyContext, d as ReplayCacheMissError, e as ReplayCacheMode, f as fallbackAdapter, w as withReplayCache } from '../../fallback-pIWW8A2d.js';
|
|
12
|
+
import { E as Extraction } from '../../distill-De6Rnn15.js';
|
|
13
|
+
import { Graph } from '@graphrefly/pure-ts/graph';
|
|
14
|
+
import { TopicGraph } from '../messaging/index.js';
|
|
15
|
+
import { G as GateController, c as GateOptions } from '../../pipeline-graph-DXCwY9vG.js';
|
|
16
|
+
export { C as ChatStreamGraph, a as ChatStreamOptions, M as MemoryRetrievalGraph, b as MemoryRetrievalOptions, c as MemoryTier, d as MemoryTiersBundle, e as MemoryTiersOptions, f as MemoryWithKGGraph, g as MemoryWithKGOptions, h as MemoryWithTiersGraph, i as MemoryWithTiersOptions, j as MemoryWithVectorsGraph, k as MemoryWithVectorsOptions, R as RetrievalEntry, l as RetrievalPipelineOptions, m as RetrievalQuery, n as RetrievalTrace, T as ToolExecutionOptions, o as ToolRegistryGraph, p as ToolRegistryOptions, q as ToolResult, r as chatStream, s as memoryRetrieval, t as memoryWithKG, u as memoryWithTiers, v as memoryWithVectors, w as toolExecution, x as toolRegistry } from '../../memory-composers-CVQqPYEV.js';
|
|
17
|
+
import { GraphSpecCatalog } from '../graphspec/index.js';
|
|
18
|
+
export { DEFAULT_DECAY_RATE } from '../../base/utils/index.js';
|
|
19
|
+
import '../../_internal-B23BagFd.js';
|
|
20
|
+
import '../../backoff-Bnb9OoPh.js';
|
|
21
|
+
import '../../base/mutation/index.js';
|
|
22
|
+
import '../memory/index.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Observable adapter wrapper — the "inverted statistics" surface.
|
|
26
|
+
*
|
|
27
|
+
* The library emits structured facts (token counts, latency, timestamps)
|
|
28
|
+
* as reactive nodes. Users compose interpretation (pricing, dashboards,
|
|
29
|
+
* telemetry, budget breakers) as derived layers on top.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** One call's structured statistics — emitted after `invoke()` / `stream()` settles. */
|
|
33
|
+
interface CallStatsEvent {
|
|
34
|
+
/** `monotonicNs()` at call completion — use for event ordering. */
|
|
35
|
+
readonly timestamp: number;
|
|
36
|
+
/** `wallClockNs()` at call start — use for human-readable attribution. */
|
|
37
|
+
readonly wallClock: number;
|
|
38
|
+
readonly provider: string;
|
|
39
|
+
readonly model: string;
|
|
40
|
+
readonly tier?: string;
|
|
41
|
+
readonly usage: TokenUsage;
|
|
42
|
+
readonly latencyMs: number;
|
|
43
|
+
/** `"invoke"` or `"stream"`. */
|
|
44
|
+
readonly method: "invoke" | "stream";
|
|
45
|
+
/** Populated when the call errored — usage may be zero or partial. */
|
|
46
|
+
readonly error?: {
|
|
47
|
+
readonly type: string;
|
|
48
|
+
readonly message: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface AdapterStats {
|
|
52
|
+
/**
|
|
53
|
+
* Reactive node for the most-recent call event. Emits `null` initially
|
|
54
|
+
* (no calls yet); emits a {@link CallStatsEvent} after each call. Subscribe
|
|
55
|
+
* and filter `!= null` if you want a `Node<CallStatsEvent>`.
|
|
56
|
+
*/
|
|
57
|
+
readonly lastCall: Node<CallStatsEvent | null>;
|
|
58
|
+
/** Full event log (bounded by `opts.logMax`, default 1000). */
|
|
59
|
+
readonly allCalls: ReactiveLogBundle<CallStatsEvent>;
|
|
60
|
+
/** Total calls observed since last reset. */
|
|
61
|
+
readonly totalCalls: Node<number>;
|
|
62
|
+
/** Sum of every input-token class across observed calls. */
|
|
63
|
+
readonly totalInputTokens: Node<number>;
|
|
64
|
+
/** Sum of every output-token class across observed calls. */
|
|
65
|
+
readonly totalOutputTokens: Node<number>;
|
|
66
|
+
/** Reset all counters + clear the log. */
|
|
67
|
+
reset(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Release the internal keepalive subscriptions on the three counter
|
|
70
|
+
* derives (`totalCalls` / `totalInputTokens` / `totalOutputTokens`) so the
|
|
71
|
+
* bundle can be GC'd when the caller discards it. Idempotent. Long-lived
|
|
72
|
+
* adapter bundles (module-level singletons) can ignore; transient bundles
|
|
73
|
+
* (per-request / per-user) should call on teardown.
|
|
74
|
+
*/
|
|
75
|
+
dispose(): void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wrap any {@link LLMAdapter} with a reactive stats bundle.
|
|
79
|
+
*
|
|
80
|
+
* Implementation (Unit 10 B):
|
|
81
|
+
* - `stats.lastCall` is a `state<CallStatsEvent | null>`.
|
|
82
|
+
* - Counters (`totalCalls` / `totalInputTokens` / `totalOutputTokens`) are
|
|
83
|
+
* **derived views** over `allCalls.entries` — self-maintaining, no manual
|
|
84
|
+
* `.cache + 1 + emit` pattern, visible topology in `describe()`.
|
|
85
|
+
* - `stats.allCalls` is a `reactiveLog<CallStatsEvent>` — bounded, supports
|
|
86
|
+
* `tail(n)` / `slice(start, stop)` for dashboard views.
|
|
87
|
+
* - The wrapped adapter passes DATA through via `adaptInvokeResult`, which
|
|
88
|
+
* uses `onFirstData` internally to guard against re-subscription double-fire
|
|
89
|
+
* and wires `.catch` for Promise-path error recording (Unit 10 A).
|
|
90
|
+
*/
|
|
91
|
+
declare function observableAdapter(inner: LLMAdapter, opts?: {
|
|
92
|
+
logMax?: number;
|
|
93
|
+
name?: string;
|
|
94
|
+
}): {
|
|
95
|
+
adapter: LLMAdapter;
|
|
96
|
+
stats: AdapterStats;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* `withBreaker` — circuit-breaker middleware for LLM adapters.
|
|
101
|
+
*
|
|
102
|
+
* Reuses the library's existing `circuitBreaker` primitive from
|
|
103
|
+
* `extra/resilience.ts`. When the breaker is open, calls throw
|
|
104
|
+
* `CircuitOpenError` instead of hitting the provider.
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
interface WithBreakerOptions extends CircuitBreakerOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Optional external breaker — pass a shared instance to wire the same
|
|
110
|
+
* breaker across multiple adapters (e.g. all tiers of a `cascadingLlmAdapter`).
|
|
111
|
+
*/
|
|
112
|
+
breaker?: CircuitBreaker;
|
|
113
|
+
}
|
|
114
|
+
declare function withLLMBreaker(inner: LLMAdapter, opts?: WithBreakerOptions): {
|
|
115
|
+
adapter: LLMAdapter;
|
|
116
|
+
breaker: CircuitBreaker;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* `withBudgetGate` — cap an adapter by calls / tokens / USD.
|
|
121
|
+
*
|
|
122
|
+
* Totals are an O(1)-per-event running accumulator (a `state<BudgetTotals>`
|
|
123
|
+
* updated imperatively inside `record()`), not a derived reduce over the
|
|
124
|
+
* full log — avoids the quadratic cost at sustained traffic while preserving
|
|
125
|
+
* the reactive surface. The full log is still exposed via the bundle for
|
|
126
|
+
* dashboards / auditors.
|
|
127
|
+
*
|
|
128
|
+
* Budgets are enforced imperatively at `invoke()` / `stream()` entry — the
|
|
129
|
+
* running totals + `isOpen.cache` are read; if closed, the call rejects /
|
|
130
|
+
* throws `BudgetExhaustedError` without hitting the wrapped adapter. On
|
|
131
|
+
* success, the call's usage is appended to the log AND debits the running
|
|
132
|
+
* totals in a single synchronous update.
|
|
133
|
+
*
|
|
134
|
+
* Wave A Unit 11 Q4: rejected-Promise path now wires `.catch` (via
|
|
135
|
+
* `adaptInvokeResult.onError`) so failed invoke calls record a CallStatsEvent
|
|
136
|
+
* with `error` populated. Prior code silently dropped rejection from the
|
|
137
|
+
* `totals` / `log` surface.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
declare class BudgetExhaustedError extends Error {
|
|
141
|
+
readonly which: string;
|
|
142
|
+
readonly limit: number;
|
|
143
|
+
readonly observed: number;
|
|
144
|
+
name: string;
|
|
145
|
+
constructor(which: string, limit: number, observed: number);
|
|
146
|
+
}
|
|
147
|
+
interface BudgetCaps {
|
|
148
|
+
calls?: number;
|
|
149
|
+
inputTokens?: number;
|
|
150
|
+
outputTokens?: number;
|
|
151
|
+
usd?: number;
|
|
152
|
+
}
|
|
153
|
+
interface BudgetTotals {
|
|
154
|
+
calls: number;
|
|
155
|
+
inputTokens: number;
|
|
156
|
+
outputTokens: number;
|
|
157
|
+
usd: number;
|
|
158
|
+
}
|
|
159
|
+
interface LLMBudgetGateBundle {
|
|
160
|
+
totals: Node<BudgetTotals>;
|
|
161
|
+
isOpen: Node<boolean>;
|
|
162
|
+
log: ReactiveLogBundle<CallStatsEvent>;
|
|
163
|
+
reset(): void;
|
|
164
|
+
/**
|
|
165
|
+
* QA D2 (Phase 13.6.B QA pass): release every long-lived
|
|
166
|
+
* subscription this gate holds — `keepalive(isOpen)`, the optional
|
|
167
|
+
* `onExhausted` subscription, and the Lock 3.C abort fan-out
|
|
168
|
+
* subscription on `isOpen`. Aborts any in-flight controllers as a
|
|
169
|
+
* defensive last gasp so callers waiting on a soon-to-be-disposed
|
|
170
|
+
* adapter don't hang.
|
|
171
|
+
*
|
|
172
|
+
* Idempotent: subsequent calls are no-ops. After `dispose()` the
|
|
173
|
+
* adapter wrapper continues to wrap `inner.invoke` / `inner.stream`
|
|
174
|
+
* but the budget machinery is best-effort: `record()` no longer
|
|
175
|
+
* emits `totals` updates, abort fan-out no longer fires. Treat the
|
|
176
|
+
* bundle as terminated once disposed; long-running apps should
|
|
177
|
+
* `dispose()` per gate instance to avoid the sub-leak documented
|
|
178
|
+
* in `docs/optimizations.md`.
|
|
179
|
+
*/
|
|
180
|
+
dispose(): void;
|
|
181
|
+
}
|
|
182
|
+
interface WithBudgetGateOptions {
|
|
183
|
+
caps: BudgetCaps;
|
|
184
|
+
/**
|
|
185
|
+
* Optional pricing function for USD gating. If omitted, `caps.usd` is
|
|
186
|
+
* ignored (caps.calls / caps.inputTokens / caps.outputTokens still apply).
|
|
187
|
+
*/
|
|
188
|
+
pricingFn?: PricingFn;
|
|
189
|
+
/**
|
|
190
|
+
* Edge-triggered: fires exactly once when the gate transitions from
|
|
191
|
+
* open to closed. Subsequent invoke/stream attempts against a closed
|
|
192
|
+
* gate do NOT re-fire `onExhausted` — use the reactive `isOpen` node
|
|
193
|
+
* if you need per-attempt notifications. Receives the cap key that
|
|
194
|
+
* triggered the transition.
|
|
195
|
+
*/
|
|
196
|
+
onExhausted?: (which: keyof BudgetCaps) => void;
|
|
197
|
+
/** Name for logs / describe output. */
|
|
198
|
+
name?: string;
|
|
199
|
+
/** Max events retained in the log (default 1000). */
|
|
200
|
+
logMax?: number;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Wrap an adapter with budget enforcement. Returns `{adapter, budget}` so
|
|
204
|
+
* callers can subscribe to the bundle for dashboards.
|
|
205
|
+
*/
|
|
206
|
+
declare function withBudgetGate(inner: LLMAdapter, opts: WithBudgetGateOptions): {
|
|
207
|
+
adapter: LLMAdapter;
|
|
208
|
+
budget: LLMBudgetGateBundle;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* `withDryRun` — short-circuit to a fake adapter when a flag is on.
|
|
213
|
+
*
|
|
214
|
+
* Useful for CI / preflight / cost-safety pipelines: wrap a real adapter,
|
|
215
|
+
* pass `enabled: true` (or a reactive flag) to bypass the wire call. Default
|
|
216
|
+
* shim is {@link dryRunAdapter}; callers can supply their own.
|
|
217
|
+
*
|
|
218
|
+
* **Returns `{adapter, dispose}`** — call `dispose()` to release the internal
|
|
219
|
+
* keepalive on the reactive `enabled` input. Long-lived adapter instances
|
|
220
|
+
* (module-level singletons) can ignore dispose; transient adapters (per-
|
|
221
|
+
* request or per-user) should call it on teardown to allow the source to
|
|
222
|
+
* be GC'd.
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
interface WithDryRunOptions {
|
|
226
|
+
/**
|
|
227
|
+
* Toggle — `true` always dry-runs; `false` always passes through; a
|
|
228
|
+
* `NodeInput<boolean>` reads the current value at call time (factory-time
|
|
229
|
+
* seed pattern, live-tunable).
|
|
230
|
+
*/
|
|
231
|
+
enabled: NodeInput<boolean>;
|
|
232
|
+
/** Dry-run adapter override. Default: `dryRunAdapter({ provider: inner.provider, model: inner.model })`. */
|
|
233
|
+
mock?: LLMAdapter;
|
|
234
|
+
}
|
|
235
|
+
interface WithDryRunBundle {
|
|
236
|
+
adapter: LLMAdapter;
|
|
237
|
+
/**
|
|
238
|
+
* Release the internal keepalive subscription on the reactive `enabled`
|
|
239
|
+
* input. Idempotent. Safe to ignore on long-lived adapters.
|
|
240
|
+
*/
|
|
241
|
+
dispose(): void;
|
|
242
|
+
}
|
|
243
|
+
declare function withDryRun(inner: LLMAdapter, opts: WithDryRunOptions): WithDryRunBundle;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* HTTP 429 / rate-limit parser.
|
|
247
|
+
*
|
|
248
|
+
* Produces a {@link RateLimitSignal} from provider HTTP errors so adaptive
|
|
249
|
+
* rate limiters can tighten effective limits. Normalizes:
|
|
250
|
+
* - `Retry-After` (seconds or HTTP-date)
|
|
251
|
+
* - `x-ratelimit-reset` / `x-ratelimit-reset-tokens` (epoch secs or duration)
|
|
252
|
+
* - `x-ratelimit-remaining-{requests,tokens}` + `x-ratelimit-limit-*`
|
|
253
|
+
* - Anthropic `anthropic-ratelimit-*` headers
|
|
254
|
+
* - OpenAI / OpenRouter / Groq headers (same family)
|
|
255
|
+
* - Error message regex fallbacks for providers without structured headers
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
interface HttpErrorLike {
|
|
259
|
+
status?: number;
|
|
260
|
+
headers?: Headers | Record<string, string | string[] | undefined>;
|
|
261
|
+
message?: string;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Extract a {@link RateLimitSignal} from a fetch-style error object, a Response,
|
|
265
|
+
* or any object exposing `.status` + `.headers` + `.message`.
|
|
266
|
+
*
|
|
267
|
+
* Returns `undefined` if no rate-limit information can be extracted.
|
|
268
|
+
*/
|
|
269
|
+
declare function parseRateLimitFromError(err: unknown): RateLimitSignal | undefined;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* `withRateLimiter` — adapter middleware bridging to the reactive
|
|
273
|
+
* `adaptiveRateLimiter` primitive.
|
|
274
|
+
*
|
|
275
|
+
* - Consumes live `rpm`/`tpm` caps as reactive `NodeInput<number>` so
|
|
276
|
+
* callers can retune at runtime (e.g. from a `ModelLimits.rpm` node).
|
|
277
|
+
* - Adapts to provider 429 responses via `http429Parser` fed into the
|
|
278
|
+
* limiter's `adaptation` signal.
|
|
279
|
+
* - `costFn` estimates token cost pre-call (e.g. char-based approximation);
|
|
280
|
+
* the post-call actual usage is fed back via `limiter.recordUsage()`.
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
interface WithRateLimiterOptions {
|
|
284
|
+
/** Live rpm cap (defaults to `Infinity`). */
|
|
285
|
+
rpm?: NodeInput<number>;
|
|
286
|
+
/** Live tpm cap (defaults to `Infinity`). */
|
|
287
|
+
tpm?: NodeInput<number>;
|
|
288
|
+
/**
|
|
289
|
+
* Pre-call token-cost estimate. Default: 0 (only rpm gates). Override with
|
|
290
|
+
* e.g. a char-based heuristic:
|
|
291
|
+
* `(msgs) => Math.ceil(msgs.reduce((s, m) => s + m.content.length, 0) / 4)`.
|
|
292
|
+
*/
|
|
293
|
+
costFn?: (messages: readonly ChatMessage[], opts?: LLMInvokeOptions) => number;
|
|
294
|
+
/**
|
|
295
|
+
* Manual adaptation signal source. Defaults to a signal derived from
|
|
296
|
+
* provider errors via `parseRateLimitFromError` — users can supply a
|
|
297
|
+
* custom signal chain if they route errors elsewhere.
|
|
298
|
+
*/
|
|
299
|
+
adaptation?: NodeInput<RateLimitSignal>;
|
|
300
|
+
burstMultiplier?: number;
|
|
301
|
+
name?: string;
|
|
302
|
+
/**
|
|
303
|
+
* Share an existing {@link AdaptiveRateLimiterBundle} across multiple
|
|
304
|
+
* adapter wraps. When provided, `withRateLimiter` reuses this bundle
|
|
305
|
+
* instead of constructing a new one — useful when the RPM/TPM cap is
|
|
306
|
+
* logically per-provider but the caller wants to harden multiple adapters
|
|
307
|
+
* (e.g. primary + fallback of the same vendor) against the shared cap.
|
|
308
|
+
*
|
|
309
|
+
* When `limiter` is set, `rpm` / `tpm` / `adaptation` / `burstMultiplier`
|
|
310
|
+
* / `name` are ignored (the supplied bundle owns those). `costFn` is still
|
|
311
|
+
* used per-wrap — each wrap supplies its own cost estimator.
|
|
312
|
+
*/
|
|
313
|
+
limiter?: AdaptiveRateLimiterBundle;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Wrap an adapter with adaptive rate limiting. Returns `{adapter, limiter}`
|
|
317
|
+
* so callers can subscribe to limiter internals (rpmAvailable, pending, etc.)
|
|
318
|
+
* for dashboards.
|
|
319
|
+
*/
|
|
320
|
+
declare function withRateLimiter(inner: LLMAdapter, opts?: WithRateLimiterOptions): {
|
|
321
|
+
adapter: LLMAdapter;
|
|
322
|
+
limiter: AdaptiveRateLimiterBundle;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* `withRetry` — retry `invoke()` / `stream()` on transient errors.
|
|
327
|
+
*
|
|
328
|
+
* Streaming retry is tricky: we retry only if the stream fails before
|
|
329
|
+
* yielding any tokens. Once tokens have started flowing, we surface the
|
|
330
|
+
* error to avoid replaying from scratch (which would double-bill and
|
|
331
|
+
* confuse consumers). Opt out of streaming retry via `opts.retryStreaming = false`.
|
|
332
|
+
*
|
|
333
|
+
* Uses `ResettableTimer` for backoff sleeps (spec §5.10 escape hatch, same
|
|
334
|
+
* pattern as `extra/resilience.ts`). Abort-aware — early-aborts before the
|
|
335
|
+
* first attempt and cleans up the abort listener on both the timer-fires
|
|
336
|
+
* and abort paths.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
interface WithRetryOptions {
|
|
340
|
+
/** Max total attempts (including the first). Default 3. */
|
|
341
|
+
attempts?: number;
|
|
342
|
+
/** Base delay in ms. Default 500. */
|
|
343
|
+
baseDelayMs?: number;
|
|
344
|
+
/** Max delay in ms. Default 10_000. */
|
|
345
|
+
maxDelayMs?: number;
|
|
346
|
+
/**
|
|
347
|
+
* Delay strategy. Default `"decorrelated"` — AWS-style `random(baseDelay,
|
|
348
|
+
* min(maxDelay, prev * 3))` which smooths retry storms and matches common
|
|
349
|
+
* SDK expectations. `"exp"` and `"linear"` produce deterministic schedules
|
|
350
|
+
* when `jitter: false`.
|
|
351
|
+
*/
|
|
352
|
+
strategy?: "exp" | "linear" | "decorrelated";
|
|
353
|
+
/**
|
|
354
|
+
* Add randomized jitter. Ignored for `strategy: "decorrelated"` (which is
|
|
355
|
+
* inherently jittered). For `exp`/`linear`, symmetric jitter in `[0.5x,
|
|
356
|
+
* 1.5x]` of the nominal delay.
|
|
357
|
+
*/
|
|
358
|
+
jitter?: boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Predicate: should this error trigger a retry? Default retries network /
|
|
361
|
+
* 5xx / 429 / transient errors, but not 4xx (other than 429), aborts, or
|
|
362
|
+
* `BudgetExhaustedError` from upstream middleware.
|
|
363
|
+
*/
|
|
364
|
+
shouldRetry?: (err: unknown, attempt: number) => boolean;
|
|
365
|
+
/** Retry streaming calls if they fail pre-first-token. Default true. */
|
|
366
|
+
retryStreaming?: boolean;
|
|
367
|
+
}
|
|
368
|
+
declare function withRetry(inner: LLMAdapter, opts?: WithRetryOptions): LLMAdapter;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* `resilientAdapter` — compose `withRateLimiter` + `withBudgetGate` +
|
|
372
|
+
* `withLLMBreaker` + `withLLMTimeout` + `withRetry` + fallback over an {@link LLMAdapter}.
|
|
373
|
+
*
|
|
374
|
+
* Call-path peer of {@link resilientPipeline} (which operates on a reactive
|
|
375
|
+
* `Node<T>` chain). Use `resilientPipeline` when composing graph sources; use
|
|
376
|
+
* `resilientAdapter` when wrapping an adapter so downstream users see a
|
|
377
|
+
* single hardened `invoke`/`stream` surface.
|
|
378
|
+
*
|
|
379
|
+
* Composition order (innermost to outermost, mirrors `resilientPipeline`):
|
|
380
|
+
*
|
|
381
|
+
* ```text
|
|
382
|
+
* rateLimit → budget → breaker → timeout → retry → fallback
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
385
|
+
* Rationale:
|
|
386
|
+
* - **rateLimit innermost** — each attempt acquires a fresh slot; a retry
|
|
387
|
+
* after a 429 waits for admission rather than bursting past the cap.
|
|
388
|
+
* - **budget next** — per-attempt gate close short-circuits retries once a
|
|
389
|
+
* cap trips.
|
|
390
|
+
* - **breaker next** — each attempt observes circuit health; open breaker
|
|
391
|
+
* fast-fails retries into fallback.
|
|
392
|
+
* - **timeout before retry** — each retry re-arms a fresh per-attempt
|
|
393
|
+
* deadline. If `timeout` wrapped `retry`, a single deadline would cover
|
|
394
|
+
* the entire retry chain — surprising for callers.
|
|
395
|
+
* - **retry before fallback** — fallback is entered only after the primary
|
|
396
|
+
* exhausts its retry budget (or immediately fails in a way the predicate
|
|
397
|
+
* doesn't retry).
|
|
398
|
+
*
|
|
399
|
+
* Every option is optional — omit the field and that layer is skipped. The
|
|
400
|
+
* returned bundle exposes the primary adapter plus the internal bundles
|
|
401
|
+
* (`rateLimiter`, `budget`, `breaker`) so callers can wire them into
|
|
402
|
+
* dashboards, alerts, or `graphLens`.
|
|
403
|
+
*
|
|
404
|
+
* Fallback is implemented via {@link cascadingLlmAdapter}: when `fallback`
|
|
405
|
+
* is provided, the wrapped primary adapter is placed at tier 0 and the
|
|
406
|
+
* fallback adapter at tier 1. For N-tier cascades, use `cascadingLlmAdapter`
|
|
407
|
+
* directly and wrap each tier with `resilientAdapter`.
|
|
408
|
+
*
|
|
409
|
+
* @module
|
|
410
|
+
*/
|
|
411
|
+
|
|
412
|
+
/** Options for {@link resilientAdapter}. Every field is optional — omit to skip that layer. */
|
|
413
|
+
interface ResilientAdapterOptions {
|
|
414
|
+
/** Admission control. See {@link withRateLimiter}. */
|
|
415
|
+
rateLimit?: WithRateLimiterOptions;
|
|
416
|
+
/** Cost/cap gate. See {@link withBudgetGate}. */
|
|
417
|
+
budget?: WithBudgetGateOptions;
|
|
418
|
+
/** Circuit breaker. See {@link withBreaker}. */
|
|
419
|
+
breaker?: WithBreakerOptions;
|
|
420
|
+
/** Per-attempt deadline in milliseconds. Omit to skip the timeout wrap. */
|
|
421
|
+
timeoutMs?: number;
|
|
422
|
+
/** Retry policy on transient errors. See {@link withRetry}. */
|
|
423
|
+
retry?: WithRetryOptions;
|
|
424
|
+
/**
|
|
425
|
+
* Fallback adapter engaged when the primary (post-retry) fails. Implemented
|
|
426
|
+
* via {@link cascadingLlmAdapter} — the primary becomes tier 0, the
|
|
427
|
+
* fallback becomes tier 1. For N-tier cascades, use `cascadingLlmAdapter`
|
|
428
|
+
* directly and wrap each tier with `resilientAdapter` as needed.
|
|
429
|
+
*/
|
|
430
|
+
fallback?: LLMAdapter;
|
|
431
|
+
/** Name used as the primary tier name in the fallback cascade. Default `"primary"`. */
|
|
432
|
+
name?: string;
|
|
433
|
+
/**
|
|
434
|
+
* Called when the cascade switches from one tier to the next after a
|
|
435
|
+
* failure. Only fires when `fallback` is set. Threaded directly to the
|
|
436
|
+
* inner {@link cascadingLlmAdapter}.
|
|
437
|
+
*/
|
|
438
|
+
onFallback?: (from: string, to: string, error: unknown) => void;
|
|
439
|
+
/**
|
|
440
|
+
* Called when every tier in the cascade has been exhausted (all failed,
|
|
441
|
+
* skipped by filter, or skipped by breaker). Only fires when `fallback`
|
|
442
|
+
* is set. Threaded directly to the inner {@link cascadingLlmAdapter}.
|
|
443
|
+
*/
|
|
444
|
+
onExhausted?: (report: CascadeExhaustionReport) => void;
|
|
445
|
+
/**
|
|
446
|
+
* Content-addressed replay cache wrapped OUTERMOST — a cache HIT short-
|
|
447
|
+
* circuits the entire stack (rate-limit / budget / breaker / retry /
|
|
448
|
+
* fallback), saving money and latency. Cache MISSes flow through the
|
|
449
|
+
* normal stack; the successful result is stored on success. See
|
|
450
|
+
* {@link withReplayCache}.
|
|
451
|
+
*/
|
|
452
|
+
cache?: WithReplayCacheOptions;
|
|
453
|
+
}
|
|
454
|
+
/** Output bundle of {@link resilientAdapter}. */
|
|
455
|
+
interface ResilientAdapterBundle {
|
|
456
|
+
/** The final hardened adapter. */
|
|
457
|
+
adapter: LLMAdapter;
|
|
458
|
+
/** Rate-limiter internals (for dashboards). Present only when `opts.rateLimit` was set. */
|
|
459
|
+
rateLimiter?: AdaptiveRateLimiterBundle;
|
|
460
|
+
/** Budget gate internals (for dashboards). Present only when `opts.budget` was set. */
|
|
461
|
+
budget?: LLMBudgetGateBundle;
|
|
462
|
+
/** Circuit breaker (for dashboards). Present only when `opts.breaker` was set. */
|
|
463
|
+
breaker?: CircuitBreaker;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Wrap `inner` with the standard resilience stack. See module docs for the
|
|
467
|
+
* composition order and rationale.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```ts
|
|
471
|
+
* const { adapter, budget, breaker } = resilientAdapter(openai, {
|
|
472
|
+
* rateLimit: { rpm: 60, tpm: 90_000 },
|
|
473
|
+
* budget: { caps: { usd: 5 } },
|
|
474
|
+
* breaker: { failureThreshold: 5, resetTimeoutMs: 30_000 },
|
|
475
|
+
* timeoutMs: 30_000,
|
|
476
|
+
* retry: { attempts: 3 },
|
|
477
|
+
* fallback: webllm, // cascades to local on exhaustion
|
|
478
|
+
* });
|
|
479
|
+
*
|
|
480
|
+
* // `adapter` is drop-in for anything expecting LLMAdapter.
|
|
481
|
+
* // Subscribe to `budget.totals`, `breaker.state`, etc. for dashboards.
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
declare function resilientAdapter(inner: LLMAdapter, opts?: ResilientAdapterOptions): ResilientAdapterBundle;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* `withLLMTimeout` — cancel `invoke()` / `stream()` after `ms` elapse.
|
|
488
|
+
*
|
|
489
|
+
* Wires a child AbortSignal so provider adapters can honor the cancellation
|
|
490
|
+
* (all shipped adapters forward `signal` through to their fetch / SDK call).
|
|
491
|
+
*
|
|
492
|
+
* Uses `ResettableTimer` rather than raw `setTimeout` — same pattern as
|
|
493
|
+
* `extra/resilience.ts` (spec §5.10 escape hatch documented on the class).
|
|
494
|
+
*/
|
|
495
|
+
|
|
496
|
+
declare class LLMTimeoutError extends Error {
|
|
497
|
+
readonly ms: number;
|
|
498
|
+
name: string;
|
|
499
|
+
constructor(ms: number);
|
|
500
|
+
}
|
|
501
|
+
declare function withLLMTimeout(inner: LLMAdapter, ms: number): LLMAdapter;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* AnthropicAdapter — default fetch-backed, optional SDK-backed.
|
|
505
|
+
*
|
|
506
|
+
* - `anthropicAdapter({ apiKey })` uses native `fetch` + SSE parsing.
|
|
507
|
+
* - `anthropicAdapter({ sdk })` delegates to a user-provided `@anthropic-ai/sdk` instance.
|
|
508
|
+
*
|
|
509
|
+
* Token usage mapping:
|
|
510
|
+
* - `input_tokens` → `input.regular`
|
|
511
|
+
* - `cache_read_input_tokens` → `input.cacheRead`
|
|
512
|
+
* - `cache_creation.ephemeral_5m_input_tokens` → `input.cacheWrite5m`
|
|
513
|
+
* - `cache_creation.ephemeral_1h_input_tokens` → `input.cacheWrite1h`
|
|
514
|
+
* - `cache_creation_input_tokens` (legacy) → `input.cacheWrite5m` (default TTL)
|
|
515
|
+
* - `output_tokens` → `output.regular`
|
|
516
|
+
* - `server_tool_use.web_search_requests` → `auxiliary.webSearchRequests`
|
|
517
|
+
*/
|
|
518
|
+
|
|
519
|
+
interface AnthropicAdapterOptions {
|
|
520
|
+
/** API key. Falls back to `process.env.ANTHROPIC_API_KEY` on Node. */
|
|
521
|
+
apiKey?: string;
|
|
522
|
+
/** Default model (overridable per-call via `LLMInvokeOptions.model`). */
|
|
523
|
+
model?: string;
|
|
524
|
+
/** Override the base URL. Default `https://api.anthropic.com`. */
|
|
525
|
+
baseURL?: string;
|
|
526
|
+
/** API version header. Default `"2023-06-01"`. */
|
|
527
|
+
anthropicVersion?: string;
|
|
528
|
+
/** Additional headers to send on every request (overridden by per-call). */
|
|
529
|
+
headers?: Record<string, string>;
|
|
530
|
+
/**
|
|
531
|
+
* User-provided SDK instance. When present, the adapter delegates to it
|
|
532
|
+
* (uses `.messages.create`) instead of native fetch.
|
|
533
|
+
* Shape matches `@anthropic-ai/sdk` `.messages` API; any object with a
|
|
534
|
+
* compatible `create`/`stream` contract works.
|
|
535
|
+
*/
|
|
536
|
+
sdk?: AnthropicSdkLike;
|
|
537
|
+
/** Custom fetch (useful for tests). Default `globalThis.fetch`. */
|
|
538
|
+
fetchImpl?: typeof fetch;
|
|
539
|
+
}
|
|
540
|
+
/** Minimal SDK shape we interoperate with. */
|
|
541
|
+
interface AnthropicSdkLike {
|
|
542
|
+
messages: {
|
|
543
|
+
create(params: Record<string, unknown>, opts?: {
|
|
544
|
+
signal?: AbortSignal;
|
|
545
|
+
}): Promise<AnthropicMessageResponse>;
|
|
546
|
+
stream?(params: Record<string, unknown>, opts?: {
|
|
547
|
+
signal?: AbortSignal;
|
|
548
|
+
}): AsyncIterable<AnthropicStreamEvent>;
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
interface AnthropicMessageResponse {
|
|
552
|
+
id: string;
|
|
553
|
+
content: ReadonlyArray<{
|
|
554
|
+
type: "text";
|
|
555
|
+
text: string;
|
|
556
|
+
} | {
|
|
557
|
+
type: "tool_use";
|
|
558
|
+
id: string;
|
|
559
|
+
name: string;
|
|
560
|
+
input: Record<string, unknown>;
|
|
561
|
+
} | {
|
|
562
|
+
type: "thinking";
|
|
563
|
+
thinking: string;
|
|
564
|
+
} | {
|
|
565
|
+
type: string;
|
|
566
|
+
[key: string]: unknown;
|
|
567
|
+
}>;
|
|
568
|
+
stop_reason?: string;
|
|
569
|
+
usage: AnthropicUsage;
|
|
570
|
+
model?: string;
|
|
571
|
+
}
|
|
572
|
+
interface AnthropicUsage {
|
|
573
|
+
input_tokens?: number;
|
|
574
|
+
output_tokens?: number;
|
|
575
|
+
cache_read_input_tokens?: number;
|
|
576
|
+
cache_creation_input_tokens?: number;
|
|
577
|
+
cache_creation?: {
|
|
578
|
+
ephemeral_5m_input_tokens?: number;
|
|
579
|
+
ephemeral_1h_input_tokens?: number;
|
|
580
|
+
};
|
|
581
|
+
server_tool_use?: {
|
|
582
|
+
web_search_requests?: number;
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
type AnthropicStreamEvent = {
|
|
586
|
+
type: "message_start";
|
|
587
|
+
message: {
|
|
588
|
+
usage: AnthropicUsage;
|
|
589
|
+
};
|
|
590
|
+
} | {
|
|
591
|
+
type: "content_block_start";
|
|
592
|
+
index: number;
|
|
593
|
+
content_block: Record<string, unknown>;
|
|
594
|
+
} | {
|
|
595
|
+
type: "content_block_delta";
|
|
596
|
+
index: number;
|
|
597
|
+
delta: Record<string, unknown>;
|
|
598
|
+
} | {
|
|
599
|
+
type: "content_block_stop";
|
|
600
|
+
index: number;
|
|
601
|
+
} | {
|
|
602
|
+
type: "message_delta";
|
|
603
|
+
delta: {
|
|
604
|
+
stop_reason?: string;
|
|
605
|
+
usage?: AnthropicUsage;
|
|
606
|
+
};
|
|
607
|
+
} | {
|
|
608
|
+
type: "message_stop";
|
|
609
|
+
} | {
|
|
610
|
+
type: string;
|
|
611
|
+
[key: string]: unknown;
|
|
612
|
+
};
|
|
613
|
+
declare function anthropicAdapter(opts?: AnthropicAdapterOptions): LLMAdapter;
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* DryRunAdapter — zero-cost mock provider.
|
|
617
|
+
*
|
|
618
|
+
* Returns a deterministic fake response (plus a configurable hook for
|
|
619
|
+
* customization). Useful for: pipeline smoke tests, CI without API keys,
|
|
620
|
+
* local development, and as the leaf of a `cascadingLlmAdapter` when every
|
|
621
|
+
* real tier fails.
|
|
622
|
+
*
|
|
623
|
+
* The library ships a minimal implementation only — richer scenario-
|
|
624
|
+
* scripted mocks (per-stage responses, call recording) belong at the test
|
|
625
|
+
* harness layer, not in the shipped library.
|
|
626
|
+
*
|
|
627
|
+
* Uses `ResettableTimer` for simulated latency (spec §5.10 escape hatch
|
|
628
|
+
* documented on the class), and throws an `AbortError`-named Error on
|
|
629
|
+
* abort so retry/timeout middleware can classify it.
|
|
630
|
+
*/
|
|
631
|
+
|
|
632
|
+
interface DryRunAdapterOptions {
|
|
633
|
+
provider?: string;
|
|
634
|
+
model?: string;
|
|
635
|
+
/** Generate the fake response. Defaults to echoing the last user message. */
|
|
636
|
+
respond?: (messages: readonly ChatMessage[], opts?: LLMInvokeOptions) => string;
|
|
637
|
+
/**
|
|
638
|
+
* Generate a fake usage object. Defaults to a simple character-count
|
|
639
|
+
* heuristic (`input = sum(messages) / 4`, `output = content / 4`).
|
|
640
|
+
*/
|
|
641
|
+
usage?: (messages: readonly ChatMessage[], content: string) => TokenUsage;
|
|
642
|
+
/** Simulated latency in milliseconds (applied to both invoke and stream). */
|
|
643
|
+
latencyMs?: number;
|
|
644
|
+
/** Stream chunk size in characters. Default 16. */
|
|
645
|
+
streamChunkSize?: number;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Create a DryRun adapter.
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```ts
|
|
652
|
+
* const adapter = dryRunAdapter({ respond: (msgs) => "hello from dry-run" });
|
|
653
|
+
* const resp = await Promise.resolve(adapter.invoke([{ role: "user", content: "hi" }]));
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
declare function dryRunAdapter(opts?: DryRunAdapterOptions): LLMAdapter;
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* GoogleAdapter — default fetch-backed, optional SDK-backed.
|
|
660
|
+
*
|
|
661
|
+
* The SDK-backed path targets the `@google/genai` SDK shape:
|
|
662
|
+
* `client.models.generateContent({ model, contents, config })` — single
|
|
663
|
+
* param, with generation params and `abortSignal` under `config`. The
|
|
664
|
+
* legacy `@google/generative-ai` two-arg `(params, {signal})` shape is no
|
|
665
|
+
* longer accepted; pass a `GoogleGenAI` instance via `opts.sdk`.
|
|
666
|
+
*
|
|
667
|
+
* Maps Gemini `usageMetadata`:
|
|
668
|
+
* - `promptTokenCount` minus `cachedContentTokenCount` → `input.regular`
|
|
669
|
+
* - `cachedContentTokenCount` → `input.cacheRead`
|
|
670
|
+
* - `candidatesTokenCount` → `output.regular`
|
|
671
|
+
* - `thoughtsTokenCount` → `output.reasoning`
|
|
672
|
+
* - `toolUsePromptTokenCount` → `input.toolUse`
|
|
673
|
+
* - `promptTokensDetails[]` → `input.{image,audio,video}` per modality
|
|
674
|
+
*/
|
|
675
|
+
|
|
676
|
+
interface GoogleAdapterOptions {
|
|
677
|
+
/** API key. Falls back to `process.env.GOOGLE_API_KEY` / `GEMINI_API_KEY` on Node. */
|
|
678
|
+
apiKey?: string;
|
|
679
|
+
model?: string;
|
|
680
|
+
baseURL?: string;
|
|
681
|
+
/** Extra headers on every request. */
|
|
682
|
+
headers?: Record<string, string>;
|
|
683
|
+
/**
|
|
684
|
+
* Optional `@google/genai` SDK instance (e.g. `new GoogleGenAI({apiKey})`).
|
|
685
|
+
* When omitted, the adapter uses the fetch-backed path against the
|
|
686
|
+
* Generative Language REST API.
|
|
687
|
+
*/
|
|
688
|
+
sdk?: GoogleSdkLike;
|
|
689
|
+
fetchImpl?: typeof fetch;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Duck-type matching the `@google/genai` (`GoogleGenAI`) SDK shape:
|
|
693
|
+
* single-param `generateContent({ model, contents, config })` where
|
|
694
|
+
* generation parameters and `abortSignal` live under `config`.
|
|
695
|
+
*
|
|
696
|
+
* The `@google/generative-ai` predecessor's two-arg `(params, {signal})`
|
|
697
|
+
* shape is no longer accepted.
|
|
698
|
+
*/
|
|
699
|
+
interface GoogleSdkLike {
|
|
700
|
+
models: {
|
|
701
|
+
generateContent(params: GoogleSdkRequestParams): Promise<GeminiResponse>;
|
|
702
|
+
generateContentStream?(params: GoogleSdkRequestParams): Promise<AsyncIterable<GeminiResponse>> | AsyncIterable<GeminiResponse>;
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
/** Single-param request shape consumed by `@google/genai`'s `models.generateContent`. */
|
|
706
|
+
interface GoogleSdkRequestParams {
|
|
707
|
+
model: string;
|
|
708
|
+
contents: unknown;
|
|
709
|
+
config?: GoogleSdkRequestConfig;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Generation config under the new SDK. `abortSignal` is the cancellation
|
|
713
|
+
* channel — there is no second-arg `{signal}`.
|
|
714
|
+
*/
|
|
715
|
+
interface GoogleSdkRequestConfig {
|
|
716
|
+
abortSignal?: AbortSignal;
|
|
717
|
+
temperature?: number;
|
|
718
|
+
maxOutputTokens?: number;
|
|
719
|
+
systemInstruction?: unknown;
|
|
720
|
+
tools?: unknown;
|
|
721
|
+
thinkingConfig?: unknown;
|
|
722
|
+
[extra: string]: unknown;
|
|
723
|
+
}
|
|
724
|
+
interface GeminiResponse {
|
|
725
|
+
candidates?: ReadonlyArray<{
|
|
726
|
+
content?: {
|
|
727
|
+
role?: string;
|
|
728
|
+
parts?: ReadonlyArray<{
|
|
729
|
+
text?: string;
|
|
730
|
+
thought?: boolean;
|
|
731
|
+
functionCall?: {
|
|
732
|
+
name: string;
|
|
733
|
+
args: Record<string, unknown>;
|
|
734
|
+
};
|
|
735
|
+
}>;
|
|
736
|
+
};
|
|
737
|
+
finishReason?: string;
|
|
738
|
+
}>;
|
|
739
|
+
usageMetadata?: GeminiUsage;
|
|
740
|
+
modelVersion?: string;
|
|
741
|
+
}
|
|
742
|
+
interface GeminiUsage {
|
|
743
|
+
promptTokenCount?: number;
|
|
744
|
+
candidatesTokenCount?: number;
|
|
745
|
+
totalTokenCount?: number;
|
|
746
|
+
thoughtsTokenCount?: number;
|
|
747
|
+
cachedContentTokenCount?: number;
|
|
748
|
+
toolUsePromptTokenCount?: number;
|
|
749
|
+
promptTokensDetails?: ReadonlyArray<{
|
|
750
|
+
modality: string;
|
|
751
|
+
tokenCount: number;
|
|
752
|
+
}>;
|
|
753
|
+
candidatesTokensDetails?: ReadonlyArray<{
|
|
754
|
+
modality: string;
|
|
755
|
+
tokenCount: number;
|
|
756
|
+
}>;
|
|
757
|
+
cacheTokensDetails?: ReadonlyArray<{
|
|
758
|
+
modality: string;
|
|
759
|
+
tokenCount: number;
|
|
760
|
+
}>;
|
|
761
|
+
}
|
|
762
|
+
declare function googleAdapter(opts?: GoogleAdapterOptions): LLMAdapter;
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* `frozenContext` — prefix-cache-friendly snapshot of upstream context.
|
|
766
|
+
*
|
|
767
|
+
* @module
|
|
768
|
+
*/
|
|
769
|
+
|
|
770
|
+
type FrozenContextOptions = {
|
|
771
|
+
/**
|
|
772
|
+
* Reactive signal that triggers re-materialization. Each `DATA` emission
|
|
773
|
+
* from this node re-reads the source and refreshes the frozen value.
|
|
774
|
+
* Typical shapes: `fromTimer(ms)` for periodic refresh, a stage-transition
|
|
775
|
+
* node for event-driven refresh, or a manual `state<number>` the caller
|
|
776
|
+
* increments via `setState(n + 1)`.
|
|
777
|
+
*
|
|
778
|
+
* When omitted, the frozen value is materialized exactly once (on first
|
|
779
|
+
* subscribe) and never refreshes for the lifetime of the activation —
|
|
780
|
+
* use this for session-start snapshots that must stay stable. The
|
|
781
|
+
* single-shot latch IS reset on `INVALIDATE` (graph-wide flush via
|
|
782
|
+
* `graph.signal([[INVALIDATE]])`), so callers who need an "evict and
|
|
783
|
+
* re-materialize" escape hatch get one through the standard graph
|
|
784
|
+
* lifecycle without having to wire a `refreshTrigger`.
|
|
785
|
+
*/
|
|
786
|
+
refreshTrigger?: NodeInput<unknown>;
|
|
787
|
+
name?: string;
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Freeze a reactive source into a stable snapshot that only re-materializes
|
|
791
|
+
* on explicit trigger. Built for long-running harness loops where system
|
|
792
|
+
* prompts include `agentMemory` / stage context — every reactive change to
|
|
793
|
+
* the source invalidates the LLM provider's prefix cache, so re-rendering
|
|
794
|
+
* the prompt every turn is expensive.
|
|
795
|
+
*
|
|
796
|
+
* `frozenContext(source)` reads the source once and caches the value;
|
|
797
|
+
* downstream `promptNode` compositions see a stable reference until the
|
|
798
|
+
* optional `refreshTrigger` fires.
|
|
799
|
+
*
|
|
800
|
+
* Trade-off: slightly stale context vs. prefix cache hit rate. For most
|
|
801
|
+
* harness apps, the memory snapshot at session start is "good enough" —
|
|
802
|
+
* refreshing on a coarse-grained trigger (`fromCron("*\/30min")`, stage
|
|
803
|
+
* transition) preserves 90%+ prefix cache hits while keeping context useful.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* // Freeze agent memory for the duration of a stage.
|
|
808
|
+
* const frozen = frozenContext(memory.context, {
|
|
809
|
+
* refreshTrigger: stage, // re-materialize on stage change
|
|
810
|
+
* });
|
|
811
|
+
* const reply = promptNode({ context: frozen, ... });
|
|
812
|
+
* ```
|
|
813
|
+
*
|
|
814
|
+
* @category patterns.ai
|
|
815
|
+
*/
|
|
816
|
+
declare function frozenContext<T>(source: NodeInput<T>, opts?: FrozenContextOptions): Node<T | null>;
|
|
817
|
+
|
|
818
|
+
/** Options accepted by {@link promptCall}, {@link llmExtractor}, and {@link llmConsolidator}. */
|
|
819
|
+
type PromptCallOptions = {
|
|
820
|
+
adapter: LLMAdapter;
|
|
821
|
+
model?: string;
|
|
822
|
+
temperature?: number;
|
|
823
|
+
maxTokens?: number;
|
|
824
|
+
/**
|
|
825
|
+
* Optional name forwarded to the underlying `promptNode` (used as the
|
|
826
|
+
* `<name>::messages` / `<name>::response` / `<name>::output` path prefix).
|
|
827
|
+
* Defaults differ per call site so multiple `promptCall`s wired into the
|
|
828
|
+
* same graph don't collide on `prompt_node::output`.
|
|
829
|
+
*/
|
|
830
|
+
name?: string;
|
|
831
|
+
};
|
|
832
|
+
/**
|
|
833
|
+
* Build a one-shot LLM JSON-call factory: each invocation wraps `input` in a
|
|
834
|
+
* fresh `node([], { initial: input })`, delegates to `promptNode({format: "json"})`, and
|
|
835
|
+
* returns a `NodeInput<TOut>` that the caller plugs into `distill` /
|
|
836
|
+
* `agentLoop` / any reactive composition that accepts `NodeInput`.
|
|
837
|
+
*
|
|
838
|
+
* **Per-call lifecycle.** The returned `NodeInput<TOut>` is a producer that
|
|
839
|
+
* emits exactly one `DATA` per upstream input (per Tier 1.2 Session C lock —
|
|
840
|
+
* `promptNode` guarantees one DATA per wave). When the consumer's switchMap
|
|
841
|
+
* supersedes it, the per-call `node([], { initial: input })` and the inner `prompt_node::response`
|
|
842
|
+
* tear down together.
|
|
843
|
+
*
|
|
844
|
+
* @param systemPrompt - System message sent on every call.
|
|
845
|
+
* @param buildUserContent - Per-input user-content builder (must be JSON-stringifiable).
|
|
846
|
+
* @param opts - Adapter + model/temperature/maxTokens + optional name prefix.
|
|
847
|
+
* @param defaultName - Path-prefix fallback when `opts.name` is omitted.
|
|
848
|
+
* @returns Factory `(input: TIn) => NodeInput<TOut>`.
|
|
849
|
+
*
|
|
850
|
+
* @category patterns
|
|
851
|
+
*/
|
|
852
|
+
declare function promptCall<TIn, TOut>(systemPrompt: string, buildUserContent: (input: TIn) => string, opts: PromptCallOptions, defaultName: string): (input: TIn) => NodeInput<TOut>;
|
|
853
|
+
/** Options accepted by {@link llmExtractor} and {@link llmConsolidator}. */
|
|
854
|
+
type LLMExtractorOptions = PromptCallOptions & {
|
|
855
|
+
/**
|
|
856
|
+
* Cap the dedup-hint slice of `existingKeys` passed to the LLM. Larger
|
|
857
|
+
* stores ship more keys (better dedup recall) at the cost of prompt size.
|
|
858
|
+
* Default 100. Set to `Infinity` to forward every key.
|
|
859
|
+
*/
|
|
860
|
+
maxExistingKeys?: number;
|
|
861
|
+
};
|
|
862
|
+
/** Alias for backward compatibility. */
|
|
863
|
+
type LLMConsolidatorOptions = LLMExtractorOptions;
|
|
864
|
+
/**
|
|
865
|
+
* Returns an `extractFn` callback for `distill()` that invokes an LLM to
|
|
866
|
+
* extract structured memories from raw input.
|
|
867
|
+
*
|
|
868
|
+
* The system prompt should instruct the LLM to return JSON matching
|
|
869
|
+
* `Extraction<TMem>` shape: `{ upsert: [{ key, value }], remove?: [key] }`.
|
|
870
|
+
*
|
|
871
|
+
* Built on `promptNode({format: "json"})` — inherits markdown-fence stripping
|
|
872
|
+
* and content-preview parse errors. Stack `withRetry` on the adapter for
|
|
873
|
+
* transient-error tolerance (see `patterns/ai/adapters/middleware/retry.ts`).
|
|
874
|
+
*/
|
|
875
|
+
declare function llmExtractor<TRaw, TMem>(systemPrompt: string, opts: LLMExtractorOptions): (raw: TRaw, existing: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
876
|
+
/**
|
|
877
|
+
* Returns a `consolidateFn` callback for `distill()` that invokes an LLM to
|
|
878
|
+
* cluster and merge related memories.
|
|
879
|
+
*/
|
|
880
|
+
declare function llmConsolidator<TMem>(systemPrompt: string, opts: LLMConsolidatorOptions): (entries: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* `promptNode` — universal LLM transform as a reactive derived node.
|
|
884
|
+
*
|
|
885
|
+
* The shape: `deps → messagesNode (derived) → switchMap → response (producer) → output`.
|
|
886
|
+
* Each upstream wave is one LLM call; superseding waves cancel the in-flight
|
|
887
|
+
* call via the abort signal threaded through `nodeSignal(opts.abort)`.
|
|
888
|
+
*
|
|
889
|
+
* The producer-shape on the inner is load-bearing: it emits exactly one DATA
|
|
890
|
+
* + COMPLETE per wave, so the outer switchMap sees one DATA per wave (matches
|
|
891
|
+
* the `HarnessExecutor` contract). A `node([response], (batchData, actions, ctx) => {
|
|
892
|
+
* const data = ...; actions.emit(parse(data[0]));
|
|
893
|
+
* }, { describeKind: "derived" })` would have its
|
|
894
|
+
* own first-run / push-on-subscribe semantics that can leak a transient null
|
|
895
|
+
* before the real response arrives — observed and reverted in an earlier
|
|
896
|
+
* attempt; see SESSION-ai-harness-module-review.md line 3654 for context.
|
|
897
|
+
* Locked as path (b) producer-based by Session C (2026-04-27); inner-node
|
|
898
|
+
* naming aligned to `prompt_node::response` per the C+D widening (2026-04-30).
|
|
899
|
+
*
|
|
900
|
+
* **Retry / replay-cache.** Stack middleware on the adapter:
|
|
901
|
+
*
|
|
902
|
+
* ```ts
|
|
903
|
+
* import { withRetry, withReplayCache } from "@graphrefly/graphrefly/patterns/ai";
|
|
904
|
+
*
|
|
905
|
+
* const adapter = withRetry(
|
|
906
|
+
* withReplayCache(baseAdapter, { keyFn: (ctx) => ctx.messages[0].content }),
|
|
907
|
+
* { count: 3, backoff: 200 },
|
|
908
|
+
* );
|
|
909
|
+
* const result = promptNode(adapter, [input], (q) => q);
|
|
910
|
+
* ```
|
|
911
|
+
*
|
|
912
|
+
* `promptNode` no longer ships `retries` / `cache` options — they duplicated
|
|
913
|
+
* middleware already at the adapter layer.
|
|
914
|
+
*
|
|
915
|
+
* **Cross-wave cache (COMPOSITION-GUIDE §32).** The switchMap output cache
|
|
916
|
+
* survives across new outer DATAs — `promptNode`'s cached value persists
|
|
917
|
+
* until the next wave fully resolves. Consumers that need to distinguish
|
|
918
|
+
* "fresh value for THIS session" from "stale cache from a prior session"
|
|
919
|
+
* (e.g. `agentLoop` resetting on new `run()`) must add a `node([])` mirror
|
|
920
|
+
* at their session boundary and depend on the mirror, not the `promptNode`
|
|
921
|
+
* output directly. `promptNode` itself stays primitive — it does not
|
|
922
|
+
* embed a state-mirror.
|
|
923
|
+
*
|
|
924
|
+
* @module
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
type PromptNodeOptions = {
|
|
928
|
+
name?: string;
|
|
929
|
+
model?: string;
|
|
930
|
+
temperature?: number;
|
|
931
|
+
maxTokens?: number;
|
|
932
|
+
/**
|
|
933
|
+
* Output format:
|
|
934
|
+
* - `"text"` (default) — emit the response content as a string.
|
|
935
|
+
* - `"json"` — `JSON.parse` the content (markdown fences stripped).
|
|
936
|
+
* - `"raw"` — emit the full {@link LLMResponse} object (subsumes the
|
|
937
|
+
* pre-Tier-2.3 `fromLLM` shape; use this when you need `usage` /
|
|
938
|
+
* `toolCalls` / `finishReason` alongside `content`).
|
|
939
|
+
*/
|
|
940
|
+
format?: "text" | "json" | "raw";
|
|
941
|
+
/**
|
|
942
|
+
* Reactive tool definitions forwarded to the adapter. Pair with
|
|
943
|
+
* `format: "raw"` (or read `toolCalls` from a downstream parser) when
|
|
944
|
+
* tool-calling is in scope.
|
|
945
|
+
*
|
|
946
|
+
* **Reactive declared edge** (DF12, Tier 7): `tools` is a `Node` so the
|
|
947
|
+
* tools list participates in `describe()` topology and `explain()` causal
|
|
948
|
+
* chains. The tools Node is added to `messagesNode`'s declared deps —
|
|
949
|
+
* tools changes re-invoke the LLM (treated as a new call envelope).
|
|
950
|
+
* Wrap with `distinctUntilChanged` upstream if your tool selector emits
|
|
951
|
+
* noisy duplicates that would otherwise spam the adapter. See
|
|
952
|
+
* COMPOSITION-GUIDE §31 (Dynamic tool selection) for the canonical
|
|
953
|
+
* `toolSelector` pattern that produces this Node.
|
|
954
|
+
*
|
|
955
|
+
* **Activation note:** since `tools` is a real declared dep, `messagesNode`
|
|
956
|
+
* waits for the tools Node to DATA at least once before firing
|
|
957
|
+
* (push-on-subscribe SENTINEL gate). Pass a `node<ToolDefinition[]>([], { initial: [] })`
|
|
958
|
+
* if you want immediate activation with no tools, or the latest published
|
|
959
|
+
* `toolSelector.tools` Node.
|
|
960
|
+
*/
|
|
961
|
+
tools?: Node<readonly ToolDefinition[]>;
|
|
962
|
+
/**
|
|
963
|
+
* Optional system prompt. Forwarded via `opts.systemPrompt` to the adapter
|
|
964
|
+
* only — never pushed as a `{role:"system"}` message (avoiding the
|
|
965
|
+
* double-send class of bug where adapters that normalize both shapes end
|
|
966
|
+
* up with two system entries).
|
|
967
|
+
*/
|
|
968
|
+
systemPrompt?: string;
|
|
969
|
+
/**
|
|
970
|
+
* Optional reactive abort signal. When the node emits `true`, the in-flight
|
|
971
|
+
* `adapter.invoke()` call is cancelled via `AbortController.abort()`.
|
|
972
|
+
* Threaded through `nodeSignal(abort)` — a one-shot bridge. Useful inside
|
|
973
|
+
* agent state machines where a separate `aborted` state should cancel the
|
|
974
|
+
* current LLM call without superseding via switchMap.
|
|
975
|
+
*/
|
|
976
|
+
abort?: Node<boolean>;
|
|
977
|
+
meta?: Record<string, unknown>;
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Universal LLM transform: wraps a prompt template + model adapter into a reactive derived node.
|
|
981
|
+
* Re-invokes the LLM whenever any dep changes. Suitable for triage, QA, hypothesis, parity, etc.
|
|
982
|
+
*
|
|
983
|
+
* **Topology** (visible in `describe()`):
|
|
984
|
+
* ```
|
|
985
|
+
* <deps...>, [tools?] → <name>::messages (derived, meta.ai = prompt_node::messages)
|
|
986
|
+
* <name>::messages → <name>::output (switchMap product, meta.ai = prompt_node::output)
|
|
987
|
+
* per-wave inner: <name>::response (producer, meta.ai = prompt_node::response)
|
|
988
|
+
* ```
|
|
989
|
+
* When `opts.tools` is supplied, the tools `Node` is appended to
|
|
990
|
+
* `messagesNode`'s declared deps so it appears as a real edge in `describe()`
|
|
991
|
+
* / `explain()` (DF12, Tier 7).
|
|
992
|
+
*
|
|
993
|
+
* **No-input semantics** (matches the codebase-wide SENTINEL convention):
|
|
994
|
+
* - **Initial no-input** (no real input has ever arrived) — emits nothing.
|
|
995
|
+
* Outer cache stays `undefined`; `subscribe` consumers see no DATA event.
|
|
996
|
+
* Use this to keep downstream gating clean: a `withLatestFrom`-paired
|
|
997
|
+
* trigger won't fire until the LLM has actually produced something.
|
|
998
|
+
* - **Mid-flow no-input** (input dropped to nullish after at least one
|
|
999
|
+
* real LLM call) — emits `null` as a domain "input went away" signal.
|
|
1000
|
+
* Downstream consumers can distinguish "haven't started" from "input
|
|
1001
|
+
* gone."
|
|
1002
|
+
*
|
|
1003
|
+
* **Retries / caching:** stack `withRetry` / `withReplayCache` middleware on the
|
|
1004
|
+
* `adapter` argument — `promptNode` no longer ships its own duplicated retry /
|
|
1005
|
+
* cache loops (pre-1.0 cleanup, see review session 1).
|
|
1006
|
+
*
|
|
1007
|
+
* @param adapter - LLM adapter (provider-agnostic). Wrap with `withRetry` /
|
|
1008
|
+
* `withReplayCache` middleware for transient-error tolerance
|
|
1009
|
+
* or replay caching.
|
|
1010
|
+
* @param deps - Input nodes whose values feed the prompt.
|
|
1011
|
+
* @param prompt - Static string or template function receiving dep values.
|
|
1012
|
+
* @param opts - Optional configuration.
|
|
1013
|
+
* @returns `Node` emitting LLM responses (string or parsed JSON).
|
|
1014
|
+
*/
|
|
1015
|
+
declare function promptNode(adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts: PromptNodeOptions & {
|
|
1016
|
+
format: "raw";
|
|
1017
|
+
}): Node<LLMResponse | null>;
|
|
1018
|
+
declare function promptNode<T = string>(adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts?: Omit<PromptNodeOptions, "format"> & {
|
|
1019
|
+
format?: "text" | "json";
|
|
1020
|
+
}): Node<T | null>;
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* `streamingPromptNode` + `gatedStream` — streaming LLM transforms.
|
|
1024
|
+
*
|
|
1025
|
+
* **Wave A Unit 2 rewrite:**
|
|
1026
|
+
* - `StreamChunk` retired. The live stream surface is now `deltaTopic:
|
|
1027
|
+
* TopicGraph<StreamDelta & {seq, ts}>` — every adapter delta (token,
|
|
1028
|
+
* thinking, tool-call, usage, finish) is published in order. The previous
|
|
1029
|
+
* shape retained the accumulated text per-chunk, producing O(N²) memory;
|
|
1030
|
+
* the new shape stores only per-delta payloads (O(N)).
|
|
1031
|
+
* - New `accumulatedText: Node<string>` on the bundle — lazy-built via
|
|
1032
|
+
* `ctx.store` over token-type deltas. Text-only extractors (`streamExtractor`,
|
|
1033
|
+
* `keywordFlagExtractor`, `toolCallExtractor`) consume this node.
|
|
1034
|
+
* - `retainedLimit?: number` option exposed for the delta topic (no default —
|
|
1035
|
+
* session scale is domain-specific per Unit 2 Q2).
|
|
1036
|
+
* - Unconditional `keepalive(output)` removed — callers subscribe as needed.
|
|
1037
|
+
* - System-prompt double-send fixed (matches promptNode Unit 1 fix).
|
|
1038
|
+
* - `format: "json"` throws on parse error with a content-preview diagnostic
|
|
1039
|
+
* (parity with `promptNode`).
|
|
1040
|
+
* - Shared body between `streamingPromptNode` and `gatedStream` extracted
|
|
1041
|
+
* into `streamingInvoke` per Unit 2 locked scope.
|
|
1042
|
+
*
|
|
1043
|
+
* @module
|
|
1044
|
+
*/
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* A single delta published to the `deltaTopic`. Every adapter emission is
|
|
1048
|
+
* forwarded — not just token deltas — so consumers see the full event log
|
|
1049
|
+
* (thinking, tool-call-delta, usage, finish).
|
|
1050
|
+
*/
|
|
1051
|
+
type StampedDelta = StreamDelta & {
|
|
1052
|
+
/** Monotonic per-stream counter starting at 0. */
|
|
1053
|
+
readonly seq: number;
|
|
1054
|
+
/** Wall-clock nanoseconds at publish time (spec §5.11 central timer). */
|
|
1055
|
+
readonly ts: number;
|
|
1056
|
+
};
|
|
1057
|
+
type StreamingPromptNodeOptions = {
|
|
1058
|
+
name?: string;
|
|
1059
|
+
model?: string;
|
|
1060
|
+
temperature?: number;
|
|
1061
|
+
maxTokens?: number;
|
|
1062
|
+
/** Output format — `"json"` attempts JSON.parse on accumulated text. Throws on parse failure. Default: `"text"`. */
|
|
1063
|
+
format?: "text" | "json";
|
|
1064
|
+
systemPrompt?: string;
|
|
1065
|
+
meta?: Record<string, unknown>;
|
|
1066
|
+
/**
|
|
1067
|
+
* Optional retention cap on the delta topic. Omit for unbounded retention
|
|
1068
|
+
* (the topic grows until `dispose()`). Recommended values: `8_192` for
|
|
1069
|
+
* single-shot 8K-token responses, `1_000_000` for persistent session
|
|
1070
|
+
* topics, or explicit `dispose()` for worker-pool patterns.
|
|
1071
|
+
*/
|
|
1072
|
+
retainedLimit?: number;
|
|
1073
|
+
};
|
|
1074
|
+
/**
|
|
1075
|
+
* Bundle returned by {@link streamingPromptNode}.
|
|
1076
|
+
*/
|
|
1077
|
+
type StreamingPromptNodeHandle<T> = {
|
|
1078
|
+
/** Final parsed result (emits once per invocation, after stream completes). */
|
|
1079
|
+
output: Node<T | null>;
|
|
1080
|
+
/** Live delta topic — every adapter delta in order, stamped with `seq` + `ts`. */
|
|
1081
|
+
deltaTopic: TopicGraph<StampedDelta>;
|
|
1082
|
+
/**
|
|
1083
|
+
* Reactive accumulated-text view — lazy-built over `deltaTopic.latest`
|
|
1084
|
+
* filtered on `type === "token"`. Text-only extractors compose on this.
|
|
1085
|
+
* Emits the empty string before any token arrives.
|
|
1086
|
+
*/
|
|
1087
|
+
accumulatedText: Node<string>;
|
|
1088
|
+
/** Tear down the delta topic and release resources. */
|
|
1089
|
+
dispose: () => void;
|
|
1090
|
+
};
|
|
1091
|
+
/**
|
|
1092
|
+
* Streaming LLM transform: wraps a prompt template + adapter into a reactive
|
|
1093
|
+
* streaming pipeline. Re-invokes the LLM whenever any dep changes; the
|
|
1094
|
+
* previous in-flight stream is canceled automatically via `switchMap`.
|
|
1095
|
+
*
|
|
1096
|
+
* Every adapter delta is published to `deltaTopic` stamped with `seq` + `ts`.
|
|
1097
|
+
* Text consumers subscribe to `accumulatedText` (auto-maintained). Delta-
|
|
1098
|
+
* specific consumers (`costMeterExtractor` on `usage` deltas) subscribe to
|
|
1099
|
+
* `deltaTopic` directly and filter by `delta.type`.
|
|
1100
|
+
*
|
|
1101
|
+
* The async boundary is handled by `fromAny(asyncGenerator)` (spec §5.10).
|
|
1102
|
+
*/
|
|
1103
|
+
declare function streamingPromptNode<T = string>(adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts?: StreamingPromptNodeOptions): StreamingPromptNodeHandle<T>;
|
|
1104
|
+
type GatedStreamOptions = StreamingPromptNodeOptions & {
|
|
1105
|
+
/** Gate options (maxPending, startOpen). */
|
|
1106
|
+
gate?: Omit<GateOptions, "meta">;
|
|
1107
|
+
};
|
|
1108
|
+
/**
|
|
1109
|
+
* Bundle returned by {@link gatedStream}.
|
|
1110
|
+
*/
|
|
1111
|
+
type GatedStreamHandle<T> = {
|
|
1112
|
+
/** Final parsed result (after gate approval). */
|
|
1113
|
+
output: Node<T | null>;
|
|
1114
|
+
/** Live delta topic — every adapter delta in order, stamped with `seq` + `ts`. */
|
|
1115
|
+
deltaTopic: TopicGraph<StampedDelta>;
|
|
1116
|
+
/** Reactive accumulated-text view. */
|
|
1117
|
+
accumulatedText: Node<string>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Gate controller — approve, reject (aborts in-flight stream), modify.
|
|
1120
|
+
* The gate's DATA domain is `T` (not `T | null`): the pre-gate `filter`
|
|
1121
|
+
* drops nulls, so the pending queue never holds a null. The controller's
|
|
1122
|
+
* `node` output type stays `T | null` only because `gate.approve()` on an
|
|
1123
|
+
* empty queue would surface `null` — callers should treat `null` as "no
|
|
1124
|
+
* value" rather than as a modeled null signal.
|
|
1125
|
+
*/
|
|
1126
|
+
gate: GateController<T>;
|
|
1127
|
+
/** Tear down the delta topic + gate keepalive. */
|
|
1128
|
+
dispose: () => void;
|
|
1129
|
+
};
|
|
1130
|
+
/**
|
|
1131
|
+
* Streaming LLM transform with human-in-the-loop gate integration.
|
|
1132
|
+
*
|
|
1133
|
+
* Composes {@link streamingPromptNode} with `gate` so that:
|
|
1134
|
+
* - `gate.reject()` discards the pending value **and** aborts the in-flight
|
|
1135
|
+
* stream (toggles an internal cancel signal → switchMap restart → abort).
|
|
1136
|
+
* - `gate.modify()` transforms the pending value before forwarding downstream.
|
|
1137
|
+
* - `gate.approve()` forwards the final result as normal.
|
|
1138
|
+
*
|
|
1139
|
+
* Wave A Unit 2 defers full `gatedStream` review to Wave B Unit 17 (the
|
|
1140
|
+
* `gate()` primitive itself is reviewed there). This implementation retains
|
|
1141
|
+
* the existing gate API while adopting the Unit 2 delta-topic shape.
|
|
1142
|
+
*/
|
|
1143
|
+
declare function gatedStream<T = string>(graph: Graph, name: string, adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts?: GatedStreamOptions): GatedStreamHandle<T>;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* `systemPromptBuilder` — assembles a reactive system prompt from sections.
|
|
1147
|
+
*
|
|
1148
|
+
* @module
|
|
1149
|
+
*/
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Assembles a system prompt from reactive sections. Each section is a
|
|
1153
|
+
* `NodeInput<string>` — the prompt updates when any section changes.
|
|
1154
|
+
*/
|
|
1155
|
+
type SystemPromptHandle = Node<string> & {
|
|
1156
|
+
dispose: () => void;
|
|
1157
|
+
};
|
|
1158
|
+
declare function systemPromptBuilder(sections: readonly NodeInput<string>[], opts?: {
|
|
1159
|
+
separator?: string;
|
|
1160
|
+
name?: string;
|
|
1161
|
+
}): SystemPromptHandle;
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* Cost meter extractor — derives live cost readings from the delta topic.
|
|
1165
|
+
*
|
|
1166
|
+
* **Wave A Unit 3 rewrite:** signature takes `deltaTopic: TopicGraph<StampedDelta>`
|
|
1167
|
+
* instead of the old `TopicGraph<StreamChunk>`. The meter prefers real
|
|
1168
|
+
* `usage` deltas from the adapter; when no `usage` has been seen yet it
|
|
1169
|
+
* falls back to a char-based estimate over token deltas and stamps
|
|
1170
|
+
* `estimated: true` on the reading. Chunk count is the count of
|
|
1171
|
+
* token-type deltas seen (was `chunk.index + 1`).
|
|
1172
|
+
*
|
|
1173
|
+
* @module
|
|
1174
|
+
*/
|
|
1175
|
+
|
|
1176
|
+
/** A cost meter reading from the stream. */
|
|
1177
|
+
type CostMeterReading = {
|
|
1178
|
+
readonly chunkCount: number;
|
|
1179
|
+
readonly charCount: number;
|
|
1180
|
+
readonly estimatedTokens: number;
|
|
1181
|
+
/**
|
|
1182
|
+
* `true` when no adapter `usage` delta has been observed yet —
|
|
1183
|
+
* `estimatedTokens` is a char-based heuristic and should be treated as an
|
|
1184
|
+
* approximation. Flips to `false` once a real `usage` delta arrives.
|
|
1185
|
+
*/
|
|
1186
|
+
readonly estimated: boolean;
|
|
1187
|
+
};
|
|
1188
|
+
type CostMeterOptions = {
|
|
1189
|
+
/** Characters per token approximation. Default: 4 (GPT-family). */
|
|
1190
|
+
charsPerToken?: number;
|
|
1191
|
+
name?: string;
|
|
1192
|
+
};
|
|
1193
|
+
/**
|
|
1194
|
+
* Mounts a cost meter on the delta topic. Prefers real `usage` deltas from
|
|
1195
|
+
* the provider; falls back to char-based estimation on token deltas alone
|
|
1196
|
+
* (with `meta.estimated: true` on the reading).
|
|
1197
|
+
*
|
|
1198
|
+
* Default structural equals suppresses DATA emission when two consecutive
|
|
1199
|
+
* readings are identical.
|
|
1200
|
+
*/
|
|
1201
|
+
declare function costMeterExtractor(deltaTopic: TopicGraph<StampedDelta>, opts?: CostMeterOptions): Node<CostMeterReading>;
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Keyword-flag extractor — scans accumulated stream text for configured patterns.
|
|
1205
|
+
* @module
|
|
1206
|
+
*/
|
|
1207
|
+
|
|
1208
|
+
/** A keyword match detected in the stream. */
|
|
1209
|
+
type KeywordFlag = {
|
|
1210
|
+
readonly label: string;
|
|
1211
|
+
readonly pattern: RegExp;
|
|
1212
|
+
readonly match: string;
|
|
1213
|
+
readonly position: number;
|
|
1214
|
+
};
|
|
1215
|
+
type KeywordFlagExtractorOptions = {
|
|
1216
|
+
patterns: readonly {
|
|
1217
|
+
pattern: RegExp;
|
|
1218
|
+
label: string;
|
|
1219
|
+
}[];
|
|
1220
|
+
name?: string;
|
|
1221
|
+
/**
|
|
1222
|
+
* Maximum length of any pattern's literal text. Used as an overlap window
|
|
1223
|
+
* when cursoring through the accumulated stream so matches that span
|
|
1224
|
+
* chunk boundaries aren't missed. Default: 128.
|
|
1225
|
+
*/
|
|
1226
|
+
maxPatternLength?: number;
|
|
1227
|
+
};
|
|
1228
|
+
/**
|
|
1229
|
+
* Mounts a keyword-flag extractor on accumulated text. Scans for all
|
|
1230
|
+
* configured patterns and emits an array of matches.
|
|
1231
|
+
*
|
|
1232
|
+
* **Wave A Unit 3 rewrite:** signature takes `accumulatedText: Node<string>`
|
|
1233
|
+
* instead of the old `TopicGraph<StreamChunk>`. Patterns are compiled once
|
|
1234
|
+
* at factory time (was per-chunk). `maxPatternLength` is validated at
|
|
1235
|
+
* factory time — any pattern whose source exceeds the window throws
|
|
1236
|
+
* immediately.
|
|
1237
|
+
*
|
|
1238
|
+
* Use cases: design invariant violations (`setTimeout`, `EventEmitter`), PII
|
|
1239
|
+
* detection (SSN, email, phone), toxicity keywords, off-track reasoning.
|
|
1240
|
+
*
|
|
1241
|
+
* **Streaming optimization.** Maintains a cursor across waves in `ctx.store`
|
|
1242
|
+
* so each emission scans only the delta region `accumulated.slice(scannedTo -
|
|
1243
|
+
* maxPatternLength)` — not the full string. Reactivation clears `ctx.store`
|
|
1244
|
+
* and resumes from offset 0 (COMPOSITION-GUIDE §20 RAM semantics).
|
|
1245
|
+
*
|
|
1246
|
+
* Default structural equals suppresses DATA emission when no new flags were
|
|
1247
|
+
* found this wave.
|
|
1248
|
+
*/
|
|
1249
|
+
declare function keywordFlagExtractor(accumulatedText: Node<string>, opts: KeywordFlagExtractorOptions): Node<readonly KeywordFlag[]>;
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* Generic stream extractor — mounts an extract function on accumulated text.
|
|
1253
|
+
*
|
|
1254
|
+
* **Wave A Unit 3 rewrite:** signature changed from
|
|
1255
|
+
* `streamExtractor(topic: TopicGraph<StreamChunk>, fn)` to
|
|
1256
|
+
* `streamExtractor(accumulatedText: Node<string>, fn)`. The Unit 2 delta-
|
|
1257
|
+
* topic redesign removed the per-chunk `accumulated` field; callers pass
|
|
1258
|
+
* `streamingPromptNode(...).accumulatedText` (or any other `Node<string>`
|
|
1259
|
+
* source of accumulated text). Source-agnostic — the extractor doesn't care
|
|
1260
|
+
* whether the text came from an LLM, WebSocket, SSE tail, or file reader.
|
|
1261
|
+
*
|
|
1262
|
+
* @module
|
|
1263
|
+
*/
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Mounts an extractor function on a reactive accumulated-text source. Returns
|
|
1267
|
+
* a derived node that emits extracted values as the text grows.
|
|
1268
|
+
*
|
|
1269
|
+
* @param accumulatedText - Reactive `Node<string>` of accumulated text.
|
|
1270
|
+
* @param extractFn - `(accumulated: string) => T | null`.
|
|
1271
|
+
* @param opts - Optional name + structural equals.
|
|
1272
|
+
* @returns Derived node emitting extracted values.
|
|
1273
|
+
*/
|
|
1274
|
+
declare function streamExtractor<T>(accumulatedText: Node<string>, extractFn: (accumulated: string) => T | null, opts?: {
|
|
1275
|
+
name?: string;
|
|
1276
|
+
/**
|
|
1277
|
+
* Optional structural equals for the extractor output. When two
|
|
1278
|
+
* consecutive chunks produce structurally-equal outputs, the framework
|
|
1279
|
+
* emits `RESOLVED` instead of `DATA`, saving downstream work. Default:
|
|
1280
|
+
* reference equality (`Object.is`). The library cannot know your
|
|
1281
|
+
* output shape — supply this when your `extractFn` returns structured
|
|
1282
|
+
* objects or arrays.
|
|
1283
|
+
*/
|
|
1284
|
+
equals?: (a: T | null, b: T | null) => boolean;
|
|
1285
|
+
}): Node<T | null>;
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Tool-call extractor — scans accumulated stream text for complete JSON tool call objects.
|
|
1289
|
+
* @module
|
|
1290
|
+
*/
|
|
1291
|
+
|
|
1292
|
+
/** A tool call detected in the stream. */
|
|
1293
|
+
type ExtractedToolCall = {
|
|
1294
|
+
readonly name: string;
|
|
1295
|
+
readonly arguments: Record<string, unknown>;
|
|
1296
|
+
readonly raw: string;
|
|
1297
|
+
readonly startIndex: number;
|
|
1298
|
+
};
|
|
1299
|
+
/**
|
|
1300
|
+
* Mounts a tool-call extractor on a streaming topic. Scans accumulated text
|
|
1301
|
+
* for complete JSON objects containing `"name"` and `"arguments"` keys (the
|
|
1302
|
+
* standard tool_call shape). Partial JSON is ignored until the closing brace.
|
|
1303
|
+
*
|
|
1304
|
+
* Feeds into the tool interception chain for reactive tool gating mid-stream.
|
|
1305
|
+
*
|
|
1306
|
+
* **Streaming optimization.** Maintains a cursor (`scanFrom`) in `ctx.store`
|
|
1307
|
+
* so each chunk resumes brace-scanning from the position after the last
|
|
1308
|
+
* complete parse (or the last incomplete open brace). Already-parsed objects
|
|
1309
|
+
* are not re-parsed. Default structural equals suppresses DATA emission when
|
|
1310
|
+
* no new tool call completed this chunk.
|
|
1311
|
+
*/
|
|
1312
|
+
declare function toolCallExtractor(accumulatedText: Node<string>, opts?: {
|
|
1313
|
+
name?: string;
|
|
1314
|
+
}): Node<readonly ExtractedToolCall[]>;
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* Content gate — classifies accumulated stream text as allow / review / block.
|
|
1318
|
+
* @module
|
|
1319
|
+
*/
|
|
1320
|
+
|
|
1321
|
+
/** Content safety decision. */
|
|
1322
|
+
type ContentDecision = "allow" | "block" | "review";
|
|
1323
|
+
/** Options for {@link contentGate}. */
|
|
1324
|
+
type ContentGateOptions = {
|
|
1325
|
+
/**
|
|
1326
|
+
* Hard-block threshold multiplier (default 1.5).
|
|
1327
|
+
* Scores above `threshold * hardMultiplier` emit `"block"`.
|
|
1328
|
+
* Scores between `threshold` and that emit `"review"`.
|
|
1329
|
+
*/
|
|
1330
|
+
hardMultiplier?: number;
|
|
1331
|
+
name?: string;
|
|
1332
|
+
};
|
|
1333
|
+
/**
|
|
1334
|
+
* Derived node that classifies accumulated stream text as `"allow"`,
|
|
1335
|
+
* `"review"`, or `"block"` based on a classifier score.
|
|
1336
|
+
*
|
|
1337
|
+
* **Wave A Unit 3 rewrite:** signature now takes `accumulatedText: Node<string>`
|
|
1338
|
+
* instead of a `TopicGraph<StreamChunk>` (the `StreamChunk` shape was retired
|
|
1339
|
+
* when the delta topic replaced the per-chunk accumulated-text shape).
|
|
1340
|
+
*
|
|
1341
|
+
* Emits a three-way decision on every text change:
|
|
1342
|
+
* - `"allow"` — score below `threshold`
|
|
1343
|
+
* - `"review"` — score in `[threshold, threshold × hardMultiplier)`
|
|
1344
|
+
* - `"block"` — score at or above `threshold × hardMultiplier`
|
|
1345
|
+
*
|
|
1346
|
+
* @param accumulatedText - Reactive accumulated-text source
|
|
1347
|
+
* (`streamingPromptNode(...).accumulatedText`).
|
|
1348
|
+
* @param classifier - `(accumulated: string) => number` scoring function, or
|
|
1349
|
+
* a `Node<number>` for live scores.
|
|
1350
|
+
* @param threshold - Score at which output becomes `"review"` or `"block"`.
|
|
1351
|
+
*/
|
|
1352
|
+
declare function contentGate(accumulatedText: Node<string>, classifier: ((accumulated: string) => number) | Node<number>, threshold: number, opts?: ContentGateOptions): Node<ContentDecision>;
|
|
1353
|
+
|
|
1354
|
+
/**
|
|
1355
|
+
* Redactor — stream extractor that replaces matched patterns in accumulated text.
|
|
1356
|
+
*
|
|
1357
|
+
* **Wave A Unit 3 rewrite:** signature now takes `accumulatedText: Node<string>`
|
|
1358
|
+
* instead of the retired `TopicGraph<StreamChunk>`. The output is a
|
|
1359
|
+
* `Node<string>` carrying the sanitized accumulated text — compose with
|
|
1360
|
+
* `contentGate` or downstream UI directly.
|
|
1361
|
+
*
|
|
1362
|
+
* @module
|
|
1363
|
+
*/
|
|
1364
|
+
|
|
1365
|
+
/** Options for {@link redactor}. */
|
|
1366
|
+
type RedactorOptions = {
|
|
1367
|
+
name?: string;
|
|
1368
|
+
};
|
|
1369
|
+
/**
|
|
1370
|
+
* Derived node that replaces matched patterns in accumulated text.
|
|
1371
|
+
*
|
|
1372
|
+
* @param accumulatedText - Reactive accumulated-text source.
|
|
1373
|
+
* @param patterns - Array of RegExps to match against the text.
|
|
1374
|
+
* @param replaceFn - Replacement producer (default: always `"[REDACTED]"`).
|
|
1375
|
+
* @returns `Node<string>` emitting the sanitized accumulated text.
|
|
1376
|
+
*/
|
|
1377
|
+
declare function redactor(accumulatedText: Node<string>, patterns: RegExp[], replaceFn?: (match: string, pattern: RegExp) => string, opts?: RedactorOptions): Node<string>;
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Options for {@link handoff}.
|
|
1381
|
+
*/
|
|
1382
|
+
type HandoffOptions = {
|
|
1383
|
+
/**
|
|
1384
|
+
* Reactive gate: when this node's value is `true`, output flows from
|
|
1385
|
+
* `from` to the `to` specialist; when `false`, `from`'s output flows
|
|
1386
|
+
* through unchanged and `to` stays dormant. Omit to always hand off —
|
|
1387
|
+
* useful when `from` is itself a router whose output shape already
|
|
1388
|
+
* encodes routing intent.
|
|
1389
|
+
*/
|
|
1390
|
+
condition?: NodeInput<boolean>;
|
|
1391
|
+
name?: string;
|
|
1392
|
+
};
|
|
1393
|
+
/**
|
|
1394
|
+
* Multi-agent handoff recipe — route `from`'s output into a specialist
|
|
1395
|
+
* agent `toFactory` when `condition` is open. Thin composition over
|
|
1396
|
+
* `switchMap` + gate; not a new primitive, just a named shape.
|
|
1397
|
+
*
|
|
1398
|
+
* The "handoff" pattern (popularized by the OpenAI Agents SDK) covers two
|
|
1399
|
+
* idioms:
|
|
1400
|
+
*
|
|
1401
|
+
* 1. **Full handoff** — a triage agent routes the conversation to a
|
|
1402
|
+
* specialist, and the specialist becomes the active agent for the rest
|
|
1403
|
+
* of the turn. Accumulated context (memory, tool definitions) can travel
|
|
1404
|
+
* along by threading the same `agentMemory` bundle into both.
|
|
1405
|
+
* 2. **Agents-as-tools** — the manager keeps control and calls the
|
|
1406
|
+
* specialist like a tool for a bounded subtask. Build this by registering
|
|
1407
|
+
* a `promptNode` instance as a `ToolDefinition` on the parent via
|
|
1408
|
+
* `toolRegistry`.
|
|
1409
|
+
*
|
|
1410
|
+
* This sugar covers (1) — a reactive route from one agent's output into a
|
|
1411
|
+
* specialist factory. For (2) wire a tool registry manually; the pattern is
|
|
1412
|
+
* additive with this one.
|
|
1413
|
+
*
|
|
1414
|
+
* @example Full handoff on a triage signal.
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* import { handoff, promptNode } from "@graphrefly/graphrefly/patterns/ai";
|
|
1417
|
+
*
|
|
1418
|
+
* const triage = promptNode(adapter, [userMessage], (msg) =>
|
|
1419
|
+
* `Classify urgency of: ${msg}. Reply "high" or "normal".`);
|
|
1420
|
+
* const isUrgent = derived([triage], ([v]) => v === "high");
|
|
1421
|
+
*
|
|
1422
|
+
* const specialist = handoff(
|
|
1423
|
+
* userMessage,
|
|
1424
|
+
* (input) => promptNode(specialistAdapter, [input], (m) => `Respond urgently: ${m}`),
|
|
1425
|
+
* { condition: isUrgent },
|
|
1426
|
+
* );
|
|
1427
|
+
* ```
|
|
1428
|
+
*
|
|
1429
|
+
* @param from - Source node whose value is threaded into the specialist.
|
|
1430
|
+
* @param toFactory - Factory that takes `from` (as a reactive source) and
|
|
1431
|
+
* returns the specialist node. Called once, lazily, when the first
|
|
1432
|
+
* subscriber activates.
|
|
1433
|
+
* @param opts - Optional reactive `condition` gate + name.
|
|
1434
|
+
* @returns Node emitting the specialist's output when the gate is open, or
|
|
1435
|
+
* `from`'s value when the gate is closed. Null when `from` is null.
|
|
1436
|
+
*
|
|
1437
|
+
* **Performance caveat (Wave A Unit 5):** the specialist is mounted per
|
|
1438
|
+
* source emission — each `v != null` DATA on `from` allocates a fresh
|
|
1439
|
+
* `state<T>(v)` + invokes `toFactory`, and switchMap cancels the prior
|
|
1440
|
+
* branch. For per-turn routing (≤1 emit/sec) this is negligible. For
|
|
1441
|
+
* high-frequency sources (per-token routing, tight event loops), batch
|
|
1442
|
+
* upstream (e.g. via `audit`, `throttle`, or `distinctUntilChanged`) before
|
|
1443
|
+
* handing off — each mount/unmount cycle spins up full subgraphs
|
|
1444
|
+
* (`messagesNode` + adapter bridge + output for a `promptNode` specialist).
|
|
1445
|
+
*
|
|
1446
|
+
* @category patterns.ai
|
|
1447
|
+
*/
|
|
1448
|
+
declare function handoff<T>(from: NodeInput<T | null>, toFactory: (input: Node<T>) => Node<T | null>, opts?: HandoffOptions): Node<T | null>;
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Options for {@link toolSelector}.
|
|
1452
|
+
*/
|
|
1453
|
+
interface ToolSelectorOptions {
|
|
1454
|
+
readonly name?: string;
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Reactive tool availability (COMPOSITION-GUIDE §31). Given a base tool set
|
|
1458
|
+
* (reactive or static) and one or more reactive predicates, emit the filtered
|
|
1459
|
+
* subset of tools currently allowed. Feeds into `promptNode({ tools: Node<...> })`
|
|
1460
|
+
* so the LLM sees a reactive menu instead of a frozen config.
|
|
1461
|
+
*
|
|
1462
|
+
* Each predicate is a `NodeInput<(tool) => boolean>`. A tool is included iff
|
|
1463
|
+
* **every** predicate returns `true`. When any predicate value is `null` /
|
|
1464
|
+
* `undefined` (e.g. upstream not yet ready) that predicate is treated as a
|
|
1465
|
+
* pass-through — the tool isn't excluded on its basis. Predicate updates
|
|
1466
|
+
* recompute the selected set.
|
|
1467
|
+
*
|
|
1468
|
+
* Pairs with `toolInterceptor` (§D9 / §31): **selection** controls what's
|
|
1469
|
+
* offered to the LLM (pre-generation UX); **interception** gates what's
|
|
1470
|
+
* executed after the LLM chooses (post-generation security). Tool selection
|
|
1471
|
+
* is NOT a security boundary — an LLM can hallucinate tool calls outside
|
|
1472
|
+
* its offered set; always pair with `toolInterceptor` for enforcement.
|
|
1473
|
+
*
|
|
1474
|
+
* @example
|
|
1475
|
+
* ```ts
|
|
1476
|
+
* const hasBudget = node([costMeter], (batchData, actions, ctx) => {
|
|
1477
|
+
* const data = batchData.map((batch, i) => batch != null && batch.length > 0 ? batch.at(-1) : ctx.prevData[i]);
|
|
1478
|
+
* actions.emit((data[0] as CostMeter).total < BUDGET);
|
|
1479
|
+
* }, { describeKind: "derived" });
|
|
1480
|
+
* const canDestroy = state(false, { name: "destructive-allowed" });
|
|
1481
|
+
* const tools = toolSelector(registry.schemas, [
|
|
1482
|
+
* node([hasBudget], (batchData, actions, ctx) => {
|
|
1483
|
+
* const data = batchData.map((batch, i) => batch != null && batch.length > 0 ? batch.at(-1) : ctx.prevData[i]);
|
|
1484
|
+
* actions.emit((t) => !t.meta?.expensive || data[0] === true);
|
|
1485
|
+
* }, { describeKind: "derived" }),
|
|
1486
|
+
* node([canDestroy], (batchData, actions, ctx) => {
|
|
1487
|
+
* const data = batchData.map((batch, i) => batch != null && batch.length > 0 ? batch.at(-1) : ctx.prevData[i]);
|
|
1488
|
+
* actions.emit((t) => !t.meta?.destructive || data[0] === true);
|
|
1489
|
+
* }, { describeKind: "derived" }),
|
|
1490
|
+
* ]);
|
|
1491
|
+
* const agent = promptNode(graph, "agent", { ..., tools });
|
|
1492
|
+
* ```
|
|
1493
|
+
*/
|
|
1494
|
+
declare function toolSelector(allTools: NodeInput<readonly ToolDefinition[]>, constraints: readonly NodeInput<(tool: ToolDefinition) => boolean>[], opts?: ToolSelectorOptions): Node<readonly ToolDefinition[]>;
|
|
1495
|
+
|
|
1496
|
+
/** Generic per-dimension thresholds. Any dim below its threshold → reject. */
|
|
1497
|
+
type AdmissionThresholds<Dims extends string> = Partial<Record<Dims, number>>;
|
|
1498
|
+
type AdmissionScoredOptions<Dims extends string, TRaw = unknown> = {
|
|
1499
|
+
/** Score function — must return a finite number for every dimension named in `thresholds`. */
|
|
1500
|
+
scoreFn: (raw: TRaw) => Readonly<Record<Dims, number>>;
|
|
1501
|
+
/** Per-dim minimums. Dims absent here are scored but not gated. */
|
|
1502
|
+
thresholds?: AdmissionThresholds<Dims>;
|
|
1503
|
+
};
|
|
1504
|
+
/**
|
|
1505
|
+
* Generic N-dimension admission filter. Rejects any input where one of the
|
|
1506
|
+
* configured threshold dimensions scores below its minimum. Missing scores
|
|
1507
|
+
* (`undefined` / `null`) AND non-finite values (`NaN`, `±Infinity`) are
|
|
1508
|
+
* treated as below all thresholds — reject by default rather than admit.
|
|
1509
|
+
*
|
|
1510
|
+
* @example
|
|
1511
|
+
* ```ts
|
|
1512
|
+
* const filter = admissionScored({
|
|
1513
|
+
* scoreFn: (raw: Note) => ({ relevance: scoreRelevance(raw), age: ageScore(raw) }),
|
|
1514
|
+
* thresholds: { relevance: 0.4 }, // age scored but ungated
|
|
1515
|
+
* });
|
|
1516
|
+
* ```
|
|
1517
|
+
*/
|
|
1518
|
+
declare function admissionScored<Dims extends string, TRaw = unknown>(opts: AdmissionScoredOptions<Dims, TRaw>): (raw: TRaw) => boolean;
|
|
1519
|
+
/** Scores for the three admission dimensions. Each 0–1. */
|
|
1520
|
+
type AdmissionScores = {
|
|
1521
|
+
readonly persistence: number;
|
|
1522
|
+
readonly structure: number;
|
|
1523
|
+
readonly personalValue: number;
|
|
1524
|
+
};
|
|
1525
|
+
type AdmissionScore3DOptions = {
|
|
1526
|
+
/** Custom scoring function. Required — the previous always-0.5 default was misleading. */
|
|
1527
|
+
scoreFn: (raw: unknown) => AdmissionScores;
|
|
1528
|
+
/** Minimum persistence score to admit (default 0.3). */
|
|
1529
|
+
persistenceThreshold?: number;
|
|
1530
|
+
/** Minimum personalValue score to admit (default 0.3). */
|
|
1531
|
+
personalValueThreshold?: number;
|
|
1532
|
+
/** Require structure score > 0 to admit (default false). */
|
|
1533
|
+
requireStructured?: boolean;
|
|
1534
|
+
};
|
|
1535
|
+
/**
|
|
1536
|
+
* 3D admission sugar — the persistence / structure / personalValue triple
|
|
1537
|
+
* commonly used in agent-memory literature. Composes `admissionScored`
|
|
1538
|
+
* with thresholds derived from the option fields. Use directly when those
|
|
1539
|
+
* three named dimensions match your domain, or use `admissionScored` with
|
|
1540
|
+
* an arbitrary dimension set instead.
|
|
1541
|
+
*
|
|
1542
|
+
* `requireStructured: true` rejects entries where `structure <= 0` (matches
|
|
1543
|
+
* the pre-Unit-8 `requireStructured && scores.structure <= 0` check).
|
|
1544
|
+
* Implemented as a final-step predicate around `admissionScored` rather
|
|
1545
|
+
* than a `Number.MIN_VALUE` threshold, which would have been a footgun for
|
|
1546
|
+
* future readers.
|
|
1547
|
+
*/
|
|
1548
|
+
declare function admissionFilter3D(opts: AdmissionScore3DOptions): (raw: unknown) => boolean;
|
|
1549
|
+
|
|
1550
|
+
type GaugesAsContextOptions = {
|
|
1551
|
+
/** Group gauges by `meta.tags` (default true). */
|
|
1552
|
+
groupByTags?: boolean;
|
|
1553
|
+
/** Separator between gauge lines (default "\n"). */
|
|
1554
|
+
separator?: string;
|
|
1555
|
+
/**
|
|
1556
|
+
* V0 delta mode (§6.0b): only include nodes whose `v.version` exceeds
|
|
1557
|
+
* the corresponding entry in this map. Nodes without V0 or not in the
|
|
1558
|
+
* map are always included. Callers maintain this map across calls.
|
|
1559
|
+
*
|
|
1560
|
+
* The `id` field guards against node replacement: if a node is removed
|
|
1561
|
+
* and re-added under the same name (new id), it is always included.
|
|
1562
|
+
*/
|
|
1563
|
+
sinceVersion?: ReadonlyMap<string, {
|
|
1564
|
+
id: string;
|
|
1565
|
+
version: number;
|
|
1566
|
+
}>;
|
|
1567
|
+
};
|
|
1568
|
+
/**
|
|
1569
|
+
* Format a graph's readable (gauge) nodes as a context string for LLM
|
|
1570
|
+
* system prompts.
|
|
1571
|
+
*
|
|
1572
|
+
* Gauges are nodes with `meta.description` or `meta.format`. Values are
|
|
1573
|
+
* formatted using `meta.format` and `meta.unit` hints.
|
|
1574
|
+
*
|
|
1575
|
+
* @param graph - The graph to introspect.
|
|
1576
|
+
* @param actor - Optional actor for guard-scoped describe.
|
|
1577
|
+
* @param options - Formatting options.
|
|
1578
|
+
* @returns A formatted string ready for system prompt injection.
|
|
1579
|
+
*/
|
|
1580
|
+
declare function gaugesAsContext(graph: Graph, actor?: Actor, options?: GaugesAsContextOptions): string;
|
|
1581
|
+
|
|
1582
|
+
type GraphFromSpecOptions = {
|
|
1583
|
+
model?: string;
|
|
1584
|
+
temperature?: number;
|
|
1585
|
+
maxTokens?: number;
|
|
1586
|
+
/** Fn/source catalog for resolving named node factories from the LLM-generated spec. */
|
|
1587
|
+
catalog?: GraphSpecCatalog;
|
|
1588
|
+
/** Extra instructions appended to the system prompt. */
|
|
1589
|
+
systemPromptExtra?: string;
|
|
1590
|
+
/**
|
|
1591
|
+
* Optional AbortSignal forwarded to `adapter.invoke({ signal })`. Lets
|
|
1592
|
+
* callers cancel the in-flight LLM call (e.g. when the reactive variant
|
|
1593
|
+
* supersedes mid-flight). When the signal aborts, the underlying call
|
|
1594
|
+
* propagates the abort and `graphFromSpec` rejects with the abort reason.
|
|
1595
|
+
*/
|
|
1596
|
+
signal?: AbortSignal;
|
|
1597
|
+
};
|
|
1598
|
+
/**
|
|
1599
|
+
* Ask an LLM to compose a Graph from a natural-language description.
|
|
1600
|
+
*
|
|
1601
|
+
* The LLM returns a JSON {@link GraphSpec} which is validated, catalog-expanded,
|
|
1602
|
+
* and instantiated via {@link compileSpec} (gains catalog validation, template
|
|
1603
|
+
* expansion, and feedback wiring that `Graph.fromSnapshot` bypasses).
|
|
1604
|
+
*
|
|
1605
|
+
* @param naturalLanguage - The problem/use-case description.
|
|
1606
|
+
* @param adapter - LLM adapter for the generation call.
|
|
1607
|
+
* @param opts - Model options and optional catalog for named node factories.
|
|
1608
|
+
* @returns A constructed Graph.
|
|
1609
|
+
* @throws On invalid LLM output, validation failure, or unresolvable deps.
|
|
1610
|
+
*/
|
|
1611
|
+
declare function graphFromSpec(naturalLanguage: string, adapter: LLMAdapter, opts?: GraphFromSpecOptions): Promise<Graph>;
|
|
1612
|
+
/**
|
|
1613
|
+
* Reactive variant of {@link graphFromSpec}: re-invokes the LLM and
|
|
1614
|
+
* recompiles the graph whenever `input` emits a new natural-language
|
|
1615
|
+
* description. Useful inside the harness or refine loop when the spec text
|
|
1616
|
+
* itself is a reactive value (e.g. fed by a `node([], { initial: ... })` knob, a memory
|
|
1617
|
+
* snapshot, or an upstream `promptNode` output).
|
|
1618
|
+
*
|
|
1619
|
+
* **Supersede:** when the input changes mid-flight, switchMap tears the
|
|
1620
|
+
* inner producer down. The producer's cleanup aborts the in-flight LLM
|
|
1621
|
+
* call via an internal `AbortController` (threaded into `graphFromSpec`'s
|
|
1622
|
+
* new `signal` option) AND destroys any Graph that lands after cancel —
|
|
1623
|
+
* no token leak, no unreferenced compiled graphs. If the user's input
|
|
1624
|
+
* already changed by the time the LLM responds, the about-to-be-discarded
|
|
1625
|
+
* Graph is freed instead of orphaned.
|
|
1626
|
+
*
|
|
1627
|
+
* **Lifetime of the latest emitted Graph:** the caller owns each Graph
|
|
1628
|
+
* that actually reaches them. If you keep multiple historical values, call
|
|
1629
|
+
* `prev?.destroy()` before storing the new one.
|
|
1630
|
+
*
|
|
1631
|
+
* @param input - Reactive source of natural-language descriptions.
|
|
1632
|
+
* @param adapter - LLM adapter for the generation call.
|
|
1633
|
+
* @param opts - Model options and optional catalog for named node factories.
|
|
1634
|
+
* @returns `Node<Graph | null>` — emits the latest compiled graph, or `null`
|
|
1635
|
+
* while the input is empty / unsettled.
|
|
1636
|
+
*/
|
|
1637
|
+
declare function graphFromSpecReactive(input: NodeInput<string>, adapter: LLMAdapter, opts?: GraphFromSpecOptions): Node<Graph | null>;
|
|
1638
|
+
|
|
1639
|
+
/** OpenAI function-calling tool schema. */
|
|
1640
|
+
type OpenAIToolSchema = {
|
|
1641
|
+
readonly type: "function";
|
|
1642
|
+
readonly function: {
|
|
1643
|
+
readonly name: string;
|
|
1644
|
+
readonly description: string;
|
|
1645
|
+
readonly parameters: Record<string, unknown>;
|
|
1646
|
+
};
|
|
1647
|
+
};
|
|
1648
|
+
/** MCP (Model Context Protocol) tool schema. */
|
|
1649
|
+
type McpToolSchema = {
|
|
1650
|
+
readonly name: string;
|
|
1651
|
+
readonly description: string;
|
|
1652
|
+
readonly inputSchema: Record<string, unknown>;
|
|
1653
|
+
};
|
|
1654
|
+
/** Result of {@link knobsAsTools}. */
|
|
1655
|
+
type KnobsAsToolsResult = {
|
|
1656
|
+
/** OpenAI function-calling tool schemas. */
|
|
1657
|
+
readonly openai: readonly OpenAIToolSchema[];
|
|
1658
|
+
/** MCP tool schemas. */
|
|
1659
|
+
readonly mcp: readonly McpToolSchema[];
|
|
1660
|
+
/** GraphReFly ToolDefinitions with handlers that call `graph.set()`. */
|
|
1661
|
+
readonly definitions: readonly ToolDefinition[];
|
|
1662
|
+
};
|
|
1663
|
+
/**
|
|
1664
|
+
* Derive tool schemas from a graph's writable (knob) nodes.
|
|
1665
|
+
*
|
|
1666
|
+
* Knobs are state nodes whose `meta.access` is `"llm"`, `"both"`, or absent
|
|
1667
|
+
* (default: writable). Each knob becomes a tool that calls `graph.set()`.
|
|
1668
|
+
*
|
|
1669
|
+
* Speaks **domain language** (spec §5.4): the returned schemas use node names
|
|
1670
|
+
* and meta descriptions — no protocol internals exposed.
|
|
1671
|
+
*
|
|
1672
|
+
* @param graph - The graph to introspect.
|
|
1673
|
+
* @param actor - Optional actor for guard-scoped describe.
|
|
1674
|
+
* @returns OpenAI, MCP, and GraphReFly tool schemas.
|
|
1675
|
+
*/
|
|
1676
|
+
declare function knobsAsTools(graph: Graph, actor?: Actor): KnobsAsToolsResult;
|
|
1677
|
+
|
|
1678
|
+
/** A single operation in a strategy plan. */
|
|
1679
|
+
type StrategyOperation = {
|
|
1680
|
+
readonly type: "add_node";
|
|
1681
|
+
readonly name: string;
|
|
1682
|
+
readonly nodeType: string;
|
|
1683
|
+
readonly meta?: Record<string, unknown>;
|
|
1684
|
+
readonly initial?: unknown;
|
|
1685
|
+
} | {
|
|
1686
|
+
readonly type: "remove_node";
|
|
1687
|
+
readonly name: string;
|
|
1688
|
+
} | {
|
|
1689
|
+
readonly type: "connect";
|
|
1690
|
+
readonly from: string;
|
|
1691
|
+
readonly to: string;
|
|
1692
|
+
} | {
|
|
1693
|
+
readonly type: "disconnect";
|
|
1694
|
+
readonly from: string;
|
|
1695
|
+
readonly to: string;
|
|
1696
|
+
} | {
|
|
1697
|
+
readonly type: "set_value";
|
|
1698
|
+
readonly name: string;
|
|
1699
|
+
readonly value: unknown;
|
|
1700
|
+
} | {
|
|
1701
|
+
readonly type: "update_meta";
|
|
1702
|
+
readonly name: string;
|
|
1703
|
+
readonly key: string;
|
|
1704
|
+
readonly value: unknown;
|
|
1705
|
+
};
|
|
1706
|
+
/** Structured strategy plan returned by {@link suggestStrategy}. */
|
|
1707
|
+
type StrategyPlan = {
|
|
1708
|
+
readonly summary: string;
|
|
1709
|
+
readonly operations: readonly StrategyOperation[];
|
|
1710
|
+
readonly reasoning: string;
|
|
1711
|
+
};
|
|
1712
|
+
type SuggestStrategyOptions = {
|
|
1713
|
+
model?: string;
|
|
1714
|
+
temperature?: number;
|
|
1715
|
+
maxTokens?: number;
|
|
1716
|
+
actor?: Actor;
|
|
1717
|
+
/**
|
|
1718
|
+
* Optional AbortSignal forwarded to `adapter.invoke({ signal })`. Lets
|
|
1719
|
+
* callers cancel the in-flight LLM call (e.g. when the reactive variant
|
|
1720
|
+
* supersedes mid-flight). When the signal aborts, the underlying call
|
|
1721
|
+
* propagates the abort and `suggestStrategy` rejects with the abort reason.
|
|
1722
|
+
*/
|
|
1723
|
+
signal?: AbortSignal;
|
|
1724
|
+
};
|
|
1725
|
+
/**
|
|
1726
|
+
* Ask an LLM to analyze a graph and suggest topology/parameter changes
|
|
1727
|
+
* to solve a stated problem.
|
|
1728
|
+
*
|
|
1729
|
+
* Returns a structured plan — does NOT auto-apply. The caller reviews
|
|
1730
|
+
* and selectively applies operations.
|
|
1731
|
+
*
|
|
1732
|
+
* @param graph - The graph to analyze.
|
|
1733
|
+
* @param problem - Natural-language problem statement.
|
|
1734
|
+
* @param adapter - LLM adapter for the analysis call.
|
|
1735
|
+
* @param opts - Model and actor options.
|
|
1736
|
+
* @returns A structured strategy plan.
|
|
1737
|
+
* @throws On invalid LLM output.
|
|
1738
|
+
*/
|
|
1739
|
+
declare function suggestStrategy(graph: Graph, problem: string, adapter: LLMAdapter, opts?: SuggestStrategyOptions): Promise<StrategyPlan>;
|
|
1740
|
+
/**
|
|
1741
|
+
* Reactive variant of {@link suggestStrategy}: re-invokes the LLM whenever
|
|
1742
|
+
* the `problem` source emits, sampling the latest `graph` value (via
|
|
1743
|
+
* `withLatestFrom`) to describe. The graph is the *secondary* dep — only
|
|
1744
|
+
* problem changes re-trigger analysis. This breaks the feedback cycle that
|
|
1745
|
+
* would otherwise arise if downstream consumers wired `apply(plan)` back
|
|
1746
|
+
* into the same graph node (graph mutation must not auto-fire a re-analysis).
|
|
1747
|
+
*
|
|
1748
|
+
* @param graph - Reactive source of graphs to analyze.
|
|
1749
|
+
* @param problem - Reactive source of natural-language problem statements.
|
|
1750
|
+
* @param adapter - LLM adapter for the analysis call.
|
|
1751
|
+
* @param opts - Model and actor options.
|
|
1752
|
+
* @returns `Node<StrategyPlan | null>` — emits the latest plan, or `null`
|
|
1753
|
+
* while inputs are unsettled.
|
|
1754
|
+
*/
|
|
1755
|
+
declare function suggestStrategyReactive(graph: Node<Graph | null>, problem: NodeInput<string>, adapter: LLMAdapter, opts?: SuggestStrategyOptions): Node<StrategyPlan | null>;
|
|
1756
|
+
|
|
1757
|
+
/** Validation result from {@link validateGraphDef}. */
|
|
1758
|
+
type GraphDefValidation = {
|
|
1759
|
+
readonly valid: boolean;
|
|
1760
|
+
readonly errors: readonly string[];
|
|
1761
|
+
};
|
|
1762
|
+
/**
|
|
1763
|
+
* Validate an LLM-generated graph definition before passing to
|
|
1764
|
+
* `Graph.fromSnapshot()`.
|
|
1765
|
+
*
|
|
1766
|
+
* Checks:
|
|
1767
|
+
* - Required fields: `name`, `nodes`, `edges`
|
|
1768
|
+
* - Node types are valid enum values
|
|
1769
|
+
* - Edge `from`/`to` reference existing nodes
|
|
1770
|
+
* - No duplicate edge entries
|
|
1771
|
+
*
|
|
1772
|
+
* @param def - The graph definition to validate (parsed JSON).
|
|
1773
|
+
* @returns Validation result with errors array.
|
|
1774
|
+
*/
|
|
1775
|
+
declare function validateGraphDef(def: unknown): GraphDefValidation;
|
|
1776
|
+
|
|
1777
|
+
export { type AdapterStats, type AdmissionScore3DOptions, type AdmissionScoredOptions, type AdmissionScores, type AdmissionThresholds, type AnthropicAdapterOptions, type AnthropicSdkLike, type BudgetCaps, BudgetExhaustedError, type BudgetTotals, type CallStatsEvent, CascadeExhaustionReport, ChatMessage, type ContentDecision, type ContentGateOptions, type CostMeterOptions, type CostMeterReading, type DryRunAdapterOptions, type ExtractedToolCall, type FrozenContextOptions, type GatedStreamHandle, type GatedStreamOptions, type GaugesAsContextOptions, type GoogleAdapterOptions, type GoogleSdkLike, type GoogleSdkRequestConfig, type GoogleSdkRequestParams, type GraphDefValidation, type GraphFromSpecOptions, type HandoffOptions, type HttpErrorLike, type KeywordFlag, type KeywordFlagExtractorOptions, type KnobsAsToolsResult, LLMAdapter, type LLMBudgetGateBundle, type LLMConsolidatorOptions, type LLMExtractorOptions, LLMInvokeOptions, LLMResponse, LLMTimeoutError, type McpToolSchema, type OpenAIToolSchema, PricingFn, type PromptCallOptions, type PromptNodeOptions, type RedactorOptions, type ResilientAdapterBundle, type ResilientAdapterOptions, type StampedDelta, type StrategyOperation, type StrategyPlan, StreamDelta, type StreamingPromptNodeHandle, type StreamingPromptNodeOptions, type SuggestStrategyOptions, type SystemPromptHandle, TokenUsage, ToolDefinition, type ToolSelectorOptions, type WithBreakerOptions, type WithBudgetGateOptions, type WithDryRunBundle, type WithDryRunOptions, type WithRateLimiterOptions, WithReplayCacheOptions, type WithRetryOptions, admissionFilter3D, admissionScored, anthropicAdapter, contentGate, costMeterExtractor, dryRunAdapter, frozenContext, gatedStream, gaugesAsContext, googleAdapter, graphFromSpec, graphFromSpecReactive, handoff, keywordFlagExtractor, knobsAsTools, llmConsolidator, llmExtractor, observableAdapter, parseRateLimitFromError, promptCall, promptNode, redactor, resilientAdapter, streamExtractor, streamingPromptNode, suggestStrategy, suggestStrategyReactive, systemPromptBuilder, toolCallExtractor, toolSelector, validateGraphDef, withBudgetGate, withDryRun, withLLMBreaker, withLLMTimeout, withRateLimiter, withRetry };
|