@graphrefly/graphrefly 0.28.0 → 0.30.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/dist/{cascading-D9WG1-9L.d.ts → cascading-BszPheHD.d.ts} +1 -1
- package/dist/{cascading-B-5zmAUv.d.cts → cascading-dNCtjW8j.d.cts} +1 -1
- package/dist/{chunk-OAWLCNJJ.js → chunk-2GQREQ6C.js} +1 -1
- package/dist/{chunk-DBGGMN3D.js → chunk-33FA6V4B.js} +1 -1
- package/dist/chunk-3NEPQO2E.js +43 -0
- package/dist/{chunk-UWJE5FQA.js → chunk-4C2OR2GH.js} +11 -11
- package/dist/chunk-4JJCCD5S.js +2 -0
- package/dist/{chunk-GHJJR5P4.js → chunk-4OFIQ66T.js} +1 -1
- package/dist/{chunk-PIOGHC63.js → chunk-567NWZ3T.js} +1 -1
- package/dist/chunk-5JDE5JHE.js +1 -0
- package/dist/{chunk-ETWTCCJI.js → chunk-5Z4HDCO6.js} +1 -1
- package/dist/{chunk-Y2EMPB3I.js → chunk-73Z3W2RN.js} +1 -1
- package/dist/{chunk-CRXTH3SH.js → chunk-7JDLFI6N.js} +1 -1
- package/dist/{chunk-DQA3UIQ2.js → chunk-7TDOES3L.js} +1 -1
- package/dist/{chunk-LBTDSCCO.js → chunk-AMBYCIOH.js} +1 -1
- package/dist/{chunk-D7A7DBE4.js → chunk-AUY2YKCO.js} +1 -1
- package/dist/{chunk-FNYWM6JC.js → chunk-AV3PIDFQ.js} +1 -1
- package/dist/{chunk-UMBIDLJ4.js → chunk-BA5URFYW.js} +1 -1
- package/dist/chunk-BKPLTBL5.js +1 -0
- package/dist/{chunk-UPXUCFMX.js → chunk-BZP5T4X6.js} +1 -1
- package/dist/{chunk-WQ2BN6X6.js → chunk-DDPYNMGG.js} +1 -1
- package/dist/{chunk-LQ3Y5NJS.js → chunk-GJR3P6JG.js} +1 -1
- package/dist/{chunk-3R5HFPX7.js → chunk-GLSM33ZM.js} +1 -1
- package/dist/{chunk-2FOAM3OR.js → chunk-GNCBXARM.js} +1 -1
- package/dist/{chunk-K2GNMCQT.js → chunk-ISCENNXS.js} +1 -1
- package/dist/{chunk-UPHHLMHE.js → chunk-IUK4EFCE.js} +1 -1
- package/dist/{chunk-ERLIRFPA.js → chunk-KA6MMXIY.js} +1 -1
- package/dist/{chunk-2PMCKKRK.js → chunk-KASHOCF5.js} +1 -1
- package/dist/chunk-LI3E75VE.js +64 -0
- package/dist/chunk-MGKAO4EK.js +7 -0
- package/dist/{chunk-ZV2DXV5A.js → chunk-NSG4C6BF.js} +1 -1
- package/dist/{chunk-4GKB4OUJ.js → chunk-OL33ZI6R.js} +1 -1
- package/dist/{chunk-76A3HVQE.js → chunk-P7JXGKDO.js} +1 -1
- package/dist/{chunk-U3AICJKU.js → chunk-RD52SNH2.js} +1 -1
- package/dist/{chunk-CWLN3X3N.js → chunk-SHYH5SXV.js} +1 -1
- package/dist/{chunk-VTPVOGHH.js → chunk-SLMYTGTU.js} +1 -1
- package/dist/{chunk-OYHGKYQM.js → chunk-T5SHIKJD.js} +1 -1
- package/dist/{chunk-VPYBOXVT.js → chunk-TWMEGG45.js} +1 -1
- package/dist/chunk-VIEUJSTT.js +1 -0
- package/dist/{chunk-SC3U7ETD.js → chunk-VWPRPPKR.js} +1 -1
- package/dist/chunk-W4TSQ6RJ.js +1 -0
- package/dist/{chunk-OBKQQA5I.js → chunk-WANIEEKV.js} +1 -1
- package/dist/{chunk-XAUNPIMX.js → chunk-XHVB6G6M.js} +1 -1
- package/dist/{chunk-MIQTDPY4.js → chunk-XQAXYVXX.js} +1 -1
- package/dist/{chunk-MTTAAPCK.js → chunk-Y32RJO24.js} +1 -1
- package/dist/{chunk-S35VARIR.js → chunk-Y36UZ5VS.js} +1 -1
- package/dist/compat/index.cjs +13 -12
- package/dist/compat/index.d.cts +14 -14
- package/dist/compat/index.d.ts +14 -14
- package/dist/compat/index.js +1 -1
- package/dist/compat/jotai/index.cjs +1 -1
- package/dist/compat/jotai/index.d.cts +2 -2
- package/dist/compat/jotai/index.d.ts +2 -2
- package/dist/compat/jotai/index.js +1 -1
- package/dist/compat/nanostores/index.cjs +1 -1
- package/dist/compat/nanostores/index.d.cts +2 -2
- package/dist/compat/nanostores/index.d.ts +2 -2
- package/dist/compat/nanostores/index.js +1 -1
- package/dist/compat/nestjs/index.cjs +13 -12
- package/dist/compat/nestjs/index.d.cts +6 -6
- package/dist/compat/nestjs/index.d.ts +6 -6
- package/dist/compat/nestjs/index.js +1 -1
- package/dist/compat/react/index.d.cts +2 -2
- package/dist/compat/react/index.d.ts +2 -2
- package/dist/compat/solid/index.d.cts +2 -2
- package/dist/compat/solid/index.d.ts +2 -2
- package/dist/compat/svelte/index.d.cts +2 -2
- package/dist/compat/svelte/index.d.ts +2 -2
- package/dist/compat/vue/index.d.cts +2 -2
- package/dist/compat/vue/index.d.ts +2 -2
- package/dist/compat/zustand/index.cjs +7 -6
- package/dist/compat/zustand/index.d.cts +4 -4
- package/dist/compat/zustand/index.d.ts +4 -4
- package/dist/compat/zustand/index.js +1 -1
- package/dist/{composite-BhbKHbOS.d.ts → composite-DGspwCqk.d.ts} +2 -2
- package/dist/{composite-B-xqw4Kk.d.cts → composite-nrRumJ7l.d.cts} +2 -2
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +1 -1
- package/dist/extra/browser.cjs +1 -1
- package/dist/extra/browser.d.cts +1 -1
- package/dist/extra/browser.d.ts +1 -1
- package/dist/extra/browser.js +1 -1
- package/dist/extra/index.cjs +20 -19
- package/dist/extra/index.d.cts +9 -9
- package/dist/extra/index.d.ts +9 -9
- package/dist/extra/index.js +1 -1
- package/dist/extra/node.cjs +3 -3
- package/dist/extra/node.d.cts +1 -1
- package/dist/extra/node.d.ts +1 -1
- package/dist/extra/node.js +1 -1
- package/dist/extra/operators.cjs +1 -1
- package/dist/extra/operators.d.cts +1 -1
- package/dist/extra/operators.d.ts +1 -1
- package/dist/extra/operators.js +1 -1
- package/dist/extra/reactive.cjs +1 -1
- package/dist/extra/reactive.d.cts +3 -3
- package/dist/extra/reactive.d.ts +3 -3
- package/dist/extra/reactive.js +1 -1
- package/dist/extra/sources.cjs +1 -1
- package/dist/extra/sources.d.cts +1 -1
- package/dist/extra/sources.d.ts +1 -1
- package/dist/extra/sources.js +1 -1
- package/dist/extra/storage-browser.cjs +1 -1
- package/dist/extra/storage-browser.d.cts +1 -1
- package/dist/extra/storage-browser.d.ts +1 -1
- package/dist/extra/storage-browser.js +1 -1
- package/dist/graph/index.cjs +7 -6
- package/dist/graph/index.d.cts +5 -5
- package/dist/graph/index.d.ts +5 -5
- package/dist/graph/index.js +1 -1
- package/dist/{graph-D48Qw9Cg.d.cts → graph-C4Uxwv0T.d.cts} +22 -6
- package/dist/{graph-BZGRXwOm.d.ts → graph-CWeI0aHd.d.ts} +22 -6
- package/dist/{index-u15meRxL.d.cts → index-9iguV3bF.d.cts} +2 -2
- package/dist/{index-DyxjtScX.d.cts → index-B-z8WaSd.d.cts} +2 -2
- package/dist/{index-BgyGlizc.d.ts → index-B2HBxvMb.d.ts} +4 -4
- package/dist/{index-CzobVSMr.d.ts → index-B5iVOD7w.d.ts} +2 -2
- package/dist/{index-rX8HBM5h.d.cts → index-B8Aj_z8S.d.cts} +2 -2
- package/dist/{index-D-YB-Vl3.d.ts → index-BANwzwBV.d.ts} +3 -3
- package/dist/{index-HDpJe9hX.d.ts → index-BBINVimG.d.ts} +3 -3
- package/dist/{index-8FSVk4Uf.d.ts → index-BEpRsvhg.d.ts} +4 -4
- package/dist/{index-CHEswufn.d.cts → index-BHu_Wba0.d.cts} +4 -4
- package/dist/{index-ZftwfxJM.d.ts → index-BJHQUCZx.d.ts} +7 -7
- package/dist/{index-DUqMOlKZ.d.cts → index-BS220yqj.d.cts} +7 -7
- package/dist/{index-BWJV63ti.d.ts → index-BX22kvjh.d.ts} +1 -1
- package/dist/{index-DfyOkTvs.d.ts → index-BXbQUn4n.d.ts} +2 -2
- package/dist/{index-O6TgGUBV.d.cts → index-BpFWP7Bq.d.cts} +3 -3
- package/dist/{index-BxJ86YZZ.d.cts → index-Bs3-LC83.d.cts} +3 -3
- package/dist/{index-DiOXyAwt.d.ts → index-Bvi5uJxX.d.ts} +1 -1
- package/dist/{index-Bqachn9_.d.ts → index-ByPnK85n.d.ts} +1 -1
- package/dist/{index-CRO83MmV.d.cts → index-BydMDMf7.d.cts} +1 -1
- package/dist/{index-ROpQmGjE.d.ts → index-C5Ghnp5B.d.ts} +3 -3
- package/dist/{index-umtoWT8K.d.ts → index-C6NBfXj-.d.ts} +6 -5
- package/dist/{index-pXrDMpRO.d.cts → index-C98oJsEs.d.cts} +2 -2
- package/dist/{index-B2pwesl9.d.cts → index-CDK5RsV5.d.cts} +1 -1
- package/dist/{index-Czq6ynh8.d.ts → index-CFW32Dy1.d.ts} +3 -3
- package/dist/{index-Cyojz0AE.d.cts → index-CIXaiYDE.d.cts} +1 -1
- package/dist/{index-Oi8d8w4R.d.cts → index-CRAkoq-y.d.cts} +1 -1
- package/dist/{index-CpgYhnrG.d.ts → index-Cc8VQIgL.d.ts} +2 -2
- package/dist/{index-vscRDkjW.d.cts → index-CcpEvuPl.d.cts} +2 -2
- package/dist/{index-BpA5c4G9.d.ts → index-CfFYyLR8.d.ts} +4 -4
- package/dist/{index-9oDeHH2u.d.cts → index-ClB7TCfL.d.cts} +2 -2
- package/dist/{index-BHvIquRZ.d.ts → index-ClgKmOHe.d.ts} +592 -492
- package/dist/{index-DpHe5e0Q.d.ts → index-CotRMjtJ.d.ts} +2 -2
- package/dist/{index-B1AmmSlb.d.ts → index-CrC7urhX.d.ts} +1 -1
- package/dist/{index-B0c4cmIO.d.ts → index-CvS9IuTG.d.ts} +2 -2
- package/dist/{index-rHJSKsU8.d.cts → index-Cy7eFeIX.d.cts} +2 -2
- package/dist/{index-BVHOrDwO.d.ts → index-D0C_USMR.d.ts} +1 -1
- package/dist/{index-DEwTb_fm.d.cts → index-D6ajK8Mh.d.cts} +592 -492
- package/dist/{index-DL-rYJrx.d.cts → index-D7XxY1Ff.d.cts} +1 -1
- package/dist/{index-DAlweici.d.ts → index-D9HrBx2J.d.ts} +2 -2
- package/dist/{index-fM6y00vT.d.cts → index-D9Y_u6BG.d.cts} +3 -3
- package/dist/{index-DcXZBF5a.d.cts → index-DBQUKh59.d.cts} +4 -4
- package/dist/{index-D_NwnRYS.d.cts → index-DDo-eqQ4.d.cts} +1 -1
- package/dist/{index-m-yHof5p.d.ts → index-DGb1awva.d.ts} +4 -4
- package/dist/{index-DxsnAMWD.d.cts → index-DR3gf_DG.d.cts} +9 -9
- package/dist/{index-dtN7YA2x.d.cts → index-DVNLe3pS.d.cts} +3 -3
- package/dist/{index-Btib9rsU.d.ts → index-Dljd76bC.d.ts} +275 -9
- package/dist/{index-DP4ZTkdw.d.ts → index-DnrZghBB.d.ts} +3 -3
- package/dist/{index-DaLJvH8Z.d.ts → index-Docdiu9a.d.ts} +3 -3
- package/dist/{index-BpIFjILY.d.cts → index-DylQCKEL.d.cts} +4 -4
- package/dist/{index-B_agccPe.d.cts → index-FBqTfL_S.d.cts} +1 -1
- package/dist/{index-DraikLjn.d.ts → index-FrYrV-Vf.d.ts} +2 -2
- package/dist/{index-sm373fsH.d.ts → index-IZ3l_vQ9.d.ts} +2 -2
- package/dist/{index-BwM9BEkt.d.ts → index-Ip3q9T9x.d.ts} +1 -1
- package/dist/{index-CloUk1kY.d.ts → index-RQg6lTrN.d.ts} +9 -9
- package/dist/{index-CEXXwWVH.d.cts → index-SSGqF8mI.d.cts} +2 -2
- package/dist/{index-rnwQly8X.d.cts → index-UZO988ox.d.cts} +6 -5
- package/dist/{index-C73n7lo-.d.cts → index-iBp74eGU.d.cts} +3 -3
- package/dist/{index-tbf2gKHd.d.cts → index-lKuLYmHO.d.cts} +3 -3
- package/dist/{index-CMn8S8Hw.d.ts → index-wIx1Jisk.d.ts} +1 -1
- package/dist/{index-cByzxQIC.d.cts → index-yIdWFo2b.d.cts} +4 -4
- package/dist/{index-RukJ4DLS.d.cts → index-ybtSyjWB.d.cts} +275 -9
- package/dist/index.cjs +53 -52
- package/dist/index.d.cts +42 -42
- package/dist/index.d.ts +42 -42
- package/dist/index.js +1 -1
- package/dist/{meta-CwesDrMD.d.ts → meta-BMwx3ExI.d.ts} +1 -1
- package/dist/{meta-Cgj6zeji.d.cts → meta-COtmHLwT.d.cts} +1 -1
- package/dist/{node-Cc1TniY8.d.ts → node-BVV7G1bq.d.cts} +59 -2
- package/dist/{node-Cc1TniY8.d.cts → node-BVV7G1bq.d.ts} +59 -2
- package/dist/{observable-glXQoGj2.d.cts → observable-BrUAPeH_.d.cts} +1 -1
- package/dist/{observable-Ct-gJ9jI.d.ts → observable-ITikPXz3.d.ts} +1 -1
- package/dist/patterns/ai/browser.d.cts +3 -3
- package/dist/patterns/ai/browser.d.ts +3 -3
- package/dist/patterns/ai/browser.js +1 -1
- package/dist/patterns/ai/index.cjs +25 -24
- package/dist/patterns/ai/index.d.cts +15 -15
- package/dist/patterns/ai/index.d.ts +15 -15
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/ai/node.d.cts +1 -1
- package/dist/patterns/ai/node.d.ts +1 -1
- package/dist/patterns/ai/node.js +1 -1
- package/dist/patterns/audit/index.cjs +7 -6
- package/dist/patterns/audit/index.d.cts +5 -5
- package/dist/patterns/audit/index.d.ts +5 -5
- package/dist/patterns/audit/index.js +1 -1
- package/dist/patterns/cqrs/index.cjs +7 -6
- package/dist/patterns/cqrs/index.d.cts +4 -4
- package/dist/patterns/cqrs/index.d.ts +4 -4
- package/dist/patterns/cqrs/index.js +1 -1
- package/dist/patterns/demo-shell/index.cjs +8 -7
- package/dist/patterns/demo-shell/index.d.cts +5 -5
- package/dist/patterns/demo-shell/index.d.ts +5 -5
- package/dist/patterns/demo-shell/index.js +1 -1
- package/dist/patterns/domain-templates/index.cjs +7 -6
- package/dist/patterns/domain-templates/index.d.cts +4 -4
- package/dist/patterns/domain-templates/index.d.ts +4 -4
- package/dist/patterns/domain-templates/index.js +1 -1
- package/dist/patterns/graphspec/index.cjs +26 -25
- package/dist/patterns/graphspec/index.d.cts +4 -4
- package/dist/patterns/graphspec/index.d.ts +4 -4
- package/dist/patterns/graphspec/index.js +1 -1
- package/dist/patterns/guarded-execution/index.cjs +7 -6
- package/dist/patterns/guarded-execution/index.d.cts +6 -6
- package/dist/patterns/guarded-execution/index.d.ts +6 -6
- package/dist/patterns/guarded-execution/index.js +1 -1
- package/dist/patterns/harness/index.cjs +11 -10
- package/dist/patterns/harness/index.d.cts +10 -7
- package/dist/patterns/harness/index.d.ts +10 -7
- package/dist/patterns/harness/index.js +1 -1
- package/dist/patterns/job-queue/index.cjs +7 -6
- package/dist/patterns/job-queue/index.d.cts +4 -4
- package/dist/patterns/job-queue/index.d.ts +4 -4
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/lens/index.cjs +7 -6
- package/dist/patterns/lens/index.d.cts +6 -6
- package/dist/patterns/lens/index.d.ts +6 -6
- package/dist/patterns/lens/index.js +1 -1
- package/dist/patterns/memory/index.cjs +7 -6
- package/dist/patterns/memory/index.d.cts +4 -4
- package/dist/patterns/memory/index.d.ts +4 -4
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.cjs +7 -6
- package/dist/patterns/messaging/index.d.cts +4 -4
- package/dist/patterns/messaging/index.d.ts +4 -4
- package/dist/patterns/messaging/index.js +1 -1
- package/dist/patterns/orchestration/index.cjs +7 -6
- package/dist/patterns/orchestration/index.d.cts +5 -5
- package/dist/patterns/orchestration/index.d.ts +5 -5
- package/dist/patterns/orchestration/index.js +1 -1
- package/dist/patterns/reactive-layout/index.cjs +8 -7
- package/dist/patterns/reactive-layout/index.d.cts +5 -5
- package/dist/patterns/reactive-layout/index.d.ts +5 -5
- package/dist/patterns/reactive-layout/index.js +1 -1
- package/dist/patterns/reduction/index.cjs +7 -6
- package/dist/patterns/reduction/index.d.cts +4 -4
- package/dist/patterns/reduction/index.d.ts +4 -4
- package/dist/patterns/reduction/index.js +1 -1
- package/dist/patterns/refine-loop/index.cjs +9 -8
- package/dist/patterns/refine-loop/index.d.cts +5 -5
- package/dist/patterns/refine-loop/index.d.ts +5 -5
- package/dist/patterns/refine-loop/index.js +1 -1
- package/dist/patterns/resilient-pipeline/index.cjs +1 -1
- package/dist/patterns/resilient-pipeline/index.d.cts +6 -6
- package/dist/patterns/resilient-pipeline/index.d.ts +6 -6
- package/dist/patterns/resilient-pipeline/index.js +1 -1
- package/dist/patterns/surface/index.cjs +14 -13
- package/dist/patterns/surface/index.d.cts +5 -5
- package/dist/patterns/surface/index.d.ts +5 -5
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{reactive-layout-CpYb5qLP.d.cts → reactive-layout-5oEn8lHM.d.cts} +2 -2
- package/dist/{reactive-layout-D8u4wuUR.d.ts → reactive-layout-BAr6-_o5.d.ts} +2 -2
- package/dist/{reactive-log-DPzuUDj5.d.cts → reactive-log-5jFeNRmd.d.cts} +1 -1
- package/dist/{reactive-log-YuH9VYN8.d.ts → reactive-log-BOJDCI5x.d.ts} +1 -1
- package/dist/{reactive-map-CdbNoSgP.d.ts → reactive-map-BvDrRuwt.d.ts} +1 -1
- package/dist/{reactive-map-DUeRmb9d.d.cts → reactive-map-CmlPPKHN.d.cts} +1 -1
- package/dist/{resilience-CGRzhnD3.d.ts → resilience-CludlzcP.d.ts} +1 -1
- package/dist/{resilience-Ba5-b4WD.d.cts → resilience-Q6Bt_7y0.d.cts} +1 -1
- package/dist/{resilience-QAHKANT5.js → resilience-XRUF267O.js} +1 -1
- package/dist/{sugar-BV0htudb.d.cts → sugar-BHbAACDG.d.ts} +10 -12
- package/dist/{sugar-Dtyrq2_q.d.ts → sugar-CqR6DJ7v.d.cts} +10 -12
- package/dist/{topology-tree-DROUdq5B.d.cts → topology-tree-CVREibAc.d.cts} +1 -1
- package/dist/{topology-tree-CYHOwQZ_.d.ts → topology-tree-CkjojcB6.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-6V3SEX2I.js +0 -1
- package/dist/chunk-7H6LGFUG.js +0 -64
- package/dist/chunk-CKCSDI7T.js +0 -6
- package/dist/chunk-QWAPKG3O.js +0 -2
- package/dist/chunk-RHESUC3V.js +0 -43
- package/dist/chunk-V6YQICXZ.js +0 -1
- package/dist/chunk-Z4HDAS2Q.js +0 -1
- package/dist/chunk-ZB5EHBIO.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as Node } from './node-
|
|
2
|
-
import { G as Graph } from './graph-
|
|
1
|
+
import { a as Node } from './node-BVV7G1bq.cjs';
|
|
2
|
+
import { G as Graph } from './graph-C4Uxwv0T.cjs';
|
|
3
3
|
|
|
4
4
|
/** Pluggable measurement backend. */
|
|
5
5
|
interface MeasurementAdapter {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as Node } from './node-
|
|
2
|
-
import { G as Graph } from './graph-
|
|
1
|
+
import { a as Node } from './node-BVV7G1bq.js';
|
|
2
|
+
import { G as Graph } from './graph-CWeI0aHd.js';
|
|
3
3
|
|
|
4
4
|
/** Pluggable measurement backend. */
|
|
5
5
|
interface MeasurementAdapter {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Node, V as VersioningLevel, N as NodeOptions } from './node-
|
|
1
|
+
import { a as Node, V as VersioningLevel, N as NodeOptions } from './node-BVV7G1bq.js';
|
|
2
2
|
|
|
3
3
|
type ReactiveMapOptions<K, V> = {
|
|
4
4
|
/** Optional registry name for `describe()` / debugging. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Node, V as VersioningLevel, N as NodeOptions } from './node-
|
|
1
|
+
import { a as Node, V as VersioningLevel, N as NodeOptions } from './node-BVV7G1bq.cjs';
|
|
2
2
|
|
|
3
3
|
type ReactiveMapOptions<K, V> = {
|
|
4
4
|
/** Optional registry name for `describe()` / debugging. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-OL33ZI6R.js";import"./chunk-ESMPEKEV.js";import"./chunk-4VVTGLXJ.js";import"./chunk-KASHOCF5.js";import"./chunk-W4TSQ6RJ.js";import"./chunk-CK2E7BTU.js";import"./chunk-QYADASLV.js";export{c as CircuitOpenError,g as RateLimiterOverflowError,j as TimeoutError,d as circuitBreaker,k as fallback,h as rateLimiter,a as retry,b as retrySource,l as timeout,f as tokenBucket,e as withBreaker,i as withStatus};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeOptions, F as FnCtx, a as Node, c as NodeActions, d as NodeFnCleanup } from './node-
|
|
1
|
+
import { N as NodeOptions, F as FnCtx, a as Node, c as NodeActions, d as NodeFnCleanup } from './node-BVV7G1bq.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Sugar constructors over the raw `node()` primitive.
|
|
@@ -75,9 +75,7 @@ type DerivedFn<T> = (data: readonly unknown[], ctx: FnCtx) => T | undefined | nu
|
|
|
75
75
|
* const b = derived([a], ([x]) => (x as number) * 2);
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
declare function derived<T = unknown>(deps: readonly Node[], fn: DerivedFn<T>, opts?: NodeOptions<T>
|
|
79
|
-
partial?: boolean;
|
|
80
|
-
}): Node<T>;
|
|
78
|
+
declare function derived<T = unknown>(deps: readonly Node[], fn: DerivedFn<T>, opts?: NodeOptions<T>): Node<T>;
|
|
81
79
|
/**
|
|
82
80
|
* User-level effect compute: fires when deps settle. Return value is NOT
|
|
83
81
|
* auto-emitted — use `actions.emit(v)` / `actions.down(msgs)` explicitly if
|
|
@@ -97,9 +95,7 @@ type EffectFn = (data: readonly unknown[], actions: NodeActions, ctx: FnCtx) =>
|
|
|
97
95
|
* });
|
|
98
96
|
* ```
|
|
99
97
|
*/
|
|
100
|
-
declare function effect(deps: readonly Node[], fn: EffectFn, opts?: NodeOptions<unknown>
|
|
101
|
-
partial?: boolean;
|
|
102
|
-
}): Node<unknown>;
|
|
98
|
+
declare function effect(deps: readonly Node[], fn: EffectFn, opts?: NodeOptions<unknown>): Node<unknown>;
|
|
103
99
|
/**
|
|
104
100
|
* Proxy handed to a {@link DynamicFn}. `track(dep)` returns the dep's
|
|
105
101
|
* latest DATA payload, as delivered through the protocol. Reading from
|
|
@@ -175,11 +171,13 @@ interface AutoTrackOptions<T> extends NodeOptions<T> {
|
|
|
175
171
|
* primary computation should continue while a secondary dep is still
|
|
176
172
|
* initialising.
|
|
177
173
|
*
|
|
178
|
-
* When `false` (default), fn is held until every
|
|
179
|
-
* least one DATA value —
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
174
|
+
* When `false` (default), fn is held until every declared dep has delivered
|
|
175
|
+
* at least one DATA value — core's first-run gate (spec §2.7) handles this.
|
|
176
|
+
* Delegates to {@link NodeOptions.partial}; both semantics are aligned: the
|
|
177
|
+
* gate is first-run-only (`_hasCalledFnOnce`), so INVALIDATE on a dep does
|
|
178
|
+
* NOT re-gate after fn has fired once. Pull-based compat layers (Signals,
|
|
179
|
+
* Jotai) that rely on "consistent compute across INVALIDATE" should
|
|
180
|
+
* explicitly wrap their dep reads with null/undefined handling in fn.
|
|
183
181
|
*
|
|
184
182
|
* @default false
|
|
185
183
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeOptions, F as FnCtx, a as Node, c as NodeActions, d as NodeFnCleanup } from './node-
|
|
1
|
+
import { N as NodeOptions, F as FnCtx, a as Node, c as NodeActions, d as NodeFnCleanup } from './node-BVV7G1bq.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Sugar constructors over the raw `node()` primitive.
|
|
@@ -75,9 +75,7 @@ type DerivedFn<T> = (data: readonly unknown[], ctx: FnCtx) => T | undefined | nu
|
|
|
75
75
|
* const b = derived([a], ([x]) => (x as number) * 2);
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
declare function derived<T = unknown>(deps: readonly Node[], fn: DerivedFn<T>, opts?: NodeOptions<T>
|
|
79
|
-
partial?: boolean;
|
|
80
|
-
}): Node<T>;
|
|
78
|
+
declare function derived<T = unknown>(deps: readonly Node[], fn: DerivedFn<T>, opts?: NodeOptions<T>): Node<T>;
|
|
81
79
|
/**
|
|
82
80
|
* User-level effect compute: fires when deps settle. Return value is NOT
|
|
83
81
|
* auto-emitted — use `actions.emit(v)` / `actions.down(msgs)` explicitly if
|
|
@@ -97,9 +95,7 @@ type EffectFn = (data: readonly unknown[], actions: NodeActions, ctx: FnCtx) =>
|
|
|
97
95
|
* });
|
|
98
96
|
* ```
|
|
99
97
|
*/
|
|
100
|
-
declare function effect(deps: readonly Node[], fn: EffectFn, opts?: NodeOptions<unknown>
|
|
101
|
-
partial?: boolean;
|
|
102
|
-
}): Node<unknown>;
|
|
98
|
+
declare function effect(deps: readonly Node[], fn: EffectFn, opts?: NodeOptions<unknown>): Node<unknown>;
|
|
103
99
|
/**
|
|
104
100
|
* Proxy handed to a {@link DynamicFn}. `track(dep)` returns the dep's
|
|
105
101
|
* latest DATA payload, as delivered through the protocol. Reading from
|
|
@@ -175,11 +171,13 @@ interface AutoTrackOptions<T> extends NodeOptions<T> {
|
|
|
175
171
|
* primary computation should continue while a secondary dep is still
|
|
176
172
|
* initialising.
|
|
177
173
|
*
|
|
178
|
-
* When `false` (default), fn is held until every
|
|
179
|
-
* least one DATA value —
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
174
|
+
* When `false` (default), fn is held until every declared dep has delivered
|
|
175
|
+
* at least one DATA value — core's first-run gate (spec §2.7) handles this.
|
|
176
|
+
* Delegates to {@link NodeOptions.partial}; both semantics are aligned: the
|
|
177
|
+
* gate is first-run-only (`_hasCalledFnOnce`), so INVALIDATE on a dep does
|
|
178
|
+
* NOT re-gate after fn has fired once. Pull-based compat layers (Signals,
|
|
179
|
+
* Jotai) that rely on "consistent compute across INVALIDATE" should
|
|
180
|
+
* explicitly wrap their dep reads with null/undefined handling in fn.
|
|
183
181
|
*
|
|
184
182
|
* @default false
|
|
185
183
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphrefly/graphrefly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
|
|
5
5
|
"description": "Reactive harness layer for agent workflows. Describe automations in plain language, trace every decision, enforce policies, persist checkpoints. Zero dependencies.",
|
|
6
6
|
"repository": {
|
package/dist/chunk-6V3SEX2I.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as R}from"./chunk-ETWTCCJI.js";import{j as k}from"./chunk-CKCSDI7T.js";import{b as N}from"./chunk-D7A7DBE4.js";import{A as g}from"./chunk-2PMCKKRK.js";import{D as T,E as S,G as y,m as q,p as w,t as u}from"./chunk-ZB5EHBIO.js";import{b as A}from"./chunk-QYADASLV.js";var P={};A(P,{CqrsGraph:()=>h,MemoryEventStore:()=>_,cqrs:()=>O});var j=u((i,e)=>{i("write"),i("signal"),e("observe")}),D=u((i,e)=>{i("observe"),i("signal"),e("write")}),H=u((i,e)=>{i("observe"),i("signal"),e("write")});function m(i,e){return R("cqrs",i,e)}var _=class{_store=new Map;persist(e){let t=this._store.get(e.type);t||(t=[],this._store.set(e.type,t)),t.push(e)}loadEvents(e,t){let n=this._store.get(e)??[],r=t?.timestampNs,s=t?.seq,o=r==null?[...n]:n.filter(d=>d.timestampNs>r||d.timestampNs===r&&d.seq>(s??-1)),a=o.length>0?o[o.length-1]:void 0;return{events:o,cursor:a?{timestampNs:a.timestampNs,seq:a.seq}:t}}clear(){this._store.clear()}},h=class extends k{_eventLogs=new Map;_commandHandlers=new Map;_projections=new Set;_sagas=new Set;_keepaliveDisposers=[];_eventStore;_seq=0;constructor(e,t={}){super(e,t.graph)}destroy(){for(let e of this._keepaliveDisposers)e();this._keepaliveDisposers.length=0,super.destroy()}event(e){let t=this._eventLogs.get(e);if(t)return t.node;let n=N([],{name:e,versioning:0}),r=n.entries,s=y([r],([o])=>o,{name:e,describeKind:"state",meta:m("event",{event_name:e}),guard:H,initial:r.cache});return this.add(s,{name:e}),this._keepaliveDisposers.push(g(s)),this._eventLogs.set(e,{log:n,node:s}),s}_appendEvent(e,t){let n=this._eventLogs.get(e);if(n||(this.event(e),n=this._eventLogs.get(e)),n.node.status==="completed"||n.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${n.node.status}).`);let r=n.log.entries.v,s={type:e,payload:t,timestampNs:w(),seq:++this._seq,...r!=null?{v0:{id:r.id,version:r.version}}:{}};n.log.append(s),this._eventStore&&this._eventStore.persist(s)}command(e,t){let n=S(void 0,{name:e,describeKind:"state",meta:{...m("command",{command_name:e}),error:null},guard:j});return this.add(n,{name:e}),this._commandHandlers.set(e,t),n}dispatch(e,t){let n=this._commandHandlers.get(e);if(!n)throw new Error(`Unknown command: "${e}". Register with .command() first.`);let r=this.resolve(e);q(()=>{r.emit(t,{internal:!0});try{n(t,{emit:(s,o)=>this._appendEvent(s,o)}),r.meta.error.emit(null,{internal:!0})}catch(s){throw r.meta.error.emit(s,{internal:!0}),s}})}projection(e,t,n,r){let s=t.map(a=>(this._eventLogs.has(a)||this.event(a),this._eventLogs.get(a).node)),o=y(s,a=>{let d=[];for(let v of a){let p=v;d.push(...p)}return d.sort((v,p)=>v.timestampNs-p.timestampNs||v.seq-p.seq),n(r,d)},{name:e,describeKind:"derived",meta:m("projection",{projection_name:e,source_events:t}),guard:D,initial:r});return this.add(o,{name:e}),this._keepaliveDisposers.push(g(o)),this._projections.add(e),o}saga(e,t,n){let r=t.map(d=>(this._eventLogs.has(d)||this.event(d),this._eventLogs.get(d).node)),s=new Map,o={},a=T(r,(d,v)=>{let p=o.n.meta.error;for(let c=0;c<d.length;c++){let E=d[c];if(E==null||E.length===0)continue;let l=E.at(-1);if(!l)continue;let f=t[c],C=s.get(f)??0;if(l.length>C){let b=l.slice(C);for(let L of b)try{n(L),p.emit(null,{internal:!0})}catch(x){p.emit(x,{internal:!0})}s.set(f,l.length)}}},{name:e,describeKind:"effect",meta:{...m("saga",{saga_name:e,source_events:t}),error:null}});return o.n=a,this.add(a,{name:e}),this._keepaliveDisposers.push(g(a)),this._sagas.add(e),a}useEventStore(e){this._eventStore=e}async rebuildProjection(e,t,n){if(!this._eventStore)throw new Error("No event store wired. Call useEventStore() first.");let r=[];for(let s of e){let o=await this._eventStore.loadEvents(s);r.push(...o.events)}return r.sort((s,o)=>s.timestampNs-o.timestampNs||s.seq-o.seq),t(n,r)}};function O(i,e){return new h(i,e)}export{_ as a,h as b,O as c,P as d};
|
package/dist/chunk-7H6LGFUG.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import{a as ot,b as at,d as st,e as it}from"./chunk-GHJJR5P4.js";import{e as lt}from"./chunk-SC3U7ETD.js";import{e as De}from"./chunk-DBGGMN3D.js";import{a as Nt,b as Ot,c as Pt,d as _t,e as Dt,f as Fe}from"./chunk-ZV2DXV5A.js";import{a as be,b as Ct,c as St,d as At,e as Et,f as It}from"./chunk-CRXTH3SH.js";import{c as tt}from"./chunk-ETWTCCJI.js";import{b as rt}from"./chunk-UPHHLMHE.js";import{b as Ye,c as ve,d as Qe,f as _e}from"./chunk-4GKB4OUJ.js";import{j as me}from"./chunk-CKCSDI7T.js";import{a as Q}from"./chunk-ESMPEKEV.js";import{P as nt,v as ee}from"./chunk-Z4HDAS2Q.js";import{b as pe}from"./chunk-D7A7DBE4.js";import{A as q,f as Xe,m as w,w as Ze,y as et}from"./chunk-2PMCKKRK.js";import{D as de,E as x,F as Pe,G as N,H as ce,m as ue,o as W,p as he}from"./chunk-ZB5EHBIO.js";import{b as z,d as le,i as ne,j as Y}from"./chunk-CK2E7BTU.js";import{b as wt}from"./chunk-QYADASLV.js";var Fn={};wt(Fn,{AgentLoopGraph:()=>Ee,AllTiersExhaustedError:()=>Dt,BudgetExhaustedError:()=>Le,ChatStreamGraph:()=>Se,CircuitOpenError:()=>ve,FallbackMissError:()=>Et,LLMTimeoutError:()=>ge,ReplayCacheMissError:()=>Ct,ToolRegistryGraph:()=>Ae,admissionFilter3D:()=>wn,agentLoop:()=>An,agentMemory:()=>Cn,anthropicAdapter:()=>Nt,canonicalJson:()=>At,cascadingLlmAdapter:()=>Fe,chatStream:()=>Mt,composePricing:()=>Wt,computePrice:()=>dt,contentGate:()=>bn,costMeterExtractor:()=>yn,createAdapter:()=>_t,createCapabilitiesRegistry:()=>Ft,createPricingRegistry:()=>jt,dryRunAdapter:()=>be,dryRunPreset:()=>tn,fallbackAdapter:()=>It,fromLLM:()=>ln,frozenContext:()=>sn,gatedStream:()=>Tn,gaugesAsContext:()=>On,googleAdapter:()=>Ot,graphFromSpec:()=>Pn,handoff:()=>vn,keywordFlagExtractor:()=>mn,knobsAsTools:()=>In,llmConsolidator:()=>Rt,llmExtractor:()=>vt,observableAdapter:()=>Bt,openAICompatAdapter:()=>Pt,parseRateLimitFromError:()=>Ke,promptNode:()=>kn,redactor:()=>hn,registryPricing:()=>$t,resilientAdapter:()=>en,streamExtractor:()=>dn,streamingPromptNode:()=>un,suggestStrategy:()=>Dn,systemPromptBuilder:()=>xn,toolCallExtractor:()=>fn,toolRegistry:()=>kt,toolSelector:()=>Rn,validateGraphDef:()=>xt,withBreaker:()=>je,withBudgetGate:()=>We,withDryRun:()=>Ut,withRateLimiter:()=>Ve,withReplayCache:()=>St,withRetry:()=>qe,withTimeout:()=>He,zeroPrice:()=>Ge});function Re(t,e){return`${t}::${e}`}function Ft(t){let e=new Map,n=new Map,o=r=>{e.set(Re(r.provider,r.id),r);let a=n.get(r.provider);a||(a=new Set,n.set(r.provider,a)),a.add(r.id)};if(t)for(let r of t)o(r);return{register:o,lookup(r,a){let s=e.get(Re(r,a));if(s)return s;let i=n.get(r);if(!i)return;let l;for(let c of i)if(a.startsWith(c)&&(!l||c.length>l.key.length)){let d=e.get(Re(r,c));d&&(l={key:c,cap:d})}return l?.cap},remove(r,a){let s=e.delete(Re(r,a));if(s){let i=n.get(r);i?.delete(a),i&&i.size===0&&n.delete(r)}return s},entries(){return e.values()}}}function te(t){let e=t.input,n=e.regular+(e.cacheRead??0)+(e.cacheWrite5m??0)+(e.cacheWrite1h??0)+(e.cacheWriteOther??0)+(e.audio??0)+(e.image??0)+(e.video??0)+(e.toolUse??0);if(!e.extensions)return n;let o=0;for(let r of Object.values(e.extensions))o+=r;return n+o}function oe(t){let e=t.output,n=e.regular+(e.reasoning??0)+(e.audio??0)+(e.predictionAccepted??0)+(e.predictionRejected??0);if(!e.extensions)return n;let o=0;for(let r of Object.values(e.extensions))o+=r;return n+o}function ut(){return{input:{regular:0},output:{regular:0}}}function Bt(t,e){let n=e?.logMax??1e3,o=pe(void 0,{name:e?.name?`${e.name}/stats`:"adapterStats",maxSize:n}),r=x(null,{name:"adapterStats/lastCall"}),a=x(0,{name:"adapterStats/totalCalls"}),s=x(0,{name:"adapterStats/totalInputTokens"}),i=x(0,{name:"adapterStats/totalOutputTokens"}),l=p=>{o.append(p),r.emit(p),a.emit((a.cache??0)+1),s.emit((s.cache??0)+te(p.usage)),i.emit((i.cache??0)+oe(p.usage))},c=()=>{o.clear(),r.emit(null),a.emit(0),s.emit(0),i.emit(0)};return{adapter:{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),invoke(p,m){let f=W(),y=he(),g=t.invoke(p,m),T=b=>{let C=W();return l({timestamp:C,wallClock:y,provider:t.provider,model:t.model??m?.model??b.model??"",tier:m?.tier??b.tier,usage:b.usage??Be(),latencyMs:Math.max(0,(C-f)/1e6),method:"invoke"}),b};if(g!=null&&typeof g.then=="function")return g.then(T);if(g!=null&&typeof g=="object"&&"content"in g)return T(g);let L=!1;return N([w(g)],([b])=>b==null||L?b:(L=!0,T(b)),{name:"adapterStats/invokeTap"})},async*stream(p,m){let f=W(),y=he(),g;try{for await(let L of t.stream(p,m))L.type==="usage"&&(g=L.usage),yield L;let T=W();l({timestamp:T,wallClock:y,provider:t.provider,model:t.model??m?.model??"",tier:m?.tier,usage:g??Be(),latencyMs:Math.max(0,(T-f)/1e6),method:"stream"})}catch(T){let L=W(),b=T;throw l({timestamp:L,wallClock:y,provider:t.provider,model:t.model??m?.model??"",tier:m?.tier,usage:g??Be(),latencyMs:Math.max(0,(L-f)/1e6),method:"stream",error:{type:b?.name??"Error",message:b?.message??String(T)}}),T}}},stats:{lastCall:r,allCalls:o,totalCalls:a,totalInputTokens:s,totalOutputTokens:i,reset:c}}}function Be(){return{input:{regular:0},output:{regular:0}}}function Gt(t,e){return t==null?0:typeof t=="number"?t:t.thresholdTokens!=null&&t.pricePerMillionAbove!=null&&e>t.thresholdTokens?t.pricePerMillionAbove:t.pricePerMillion}function Ge(t="USD"){return{total:0,currency:t}}function dt(t,e,n){let o=te(t),r=e.currency??"USD",a=n?.withBreakdown===!0,s=a?{}:null,i=0,l=(g,T,L)=>{if(!T||L==null)return;let b=Gt(L,o),C=T*b/1e6;i+=C,a&&(s[g]=(s[g]??0)+C)},c=t.input,d=e.input;if(d&&(l("input.regular",c.regular,d.regular),l("input.cacheRead",c.cacheRead??0,d.cacheRead),l("input.cacheWrite5m",c.cacheWrite5m??0,d.cacheWrite5m),l("input.cacheWrite1h",c.cacheWrite1h??0,d.cacheWrite1h),l("input.cacheWriteOther",c.cacheWriteOther??0,d.cacheWriteOther),l("input.audio",c.audio??0,d.audio),l("input.image",c.image??0,d.image),l("input.video",c.video??0,d.video),l("input.toolUse",c.toolUse??0,d.toolUse),c.extensions&&d.extensions))for(let[g,T]of Object.entries(c.extensions))l(`input.ext.${g}`,T,d.extensions[g]);let u=t.output,p=e.output;if(p&&(l("output.regular",u.regular,p.regular),l("output.reasoning",u.reasoning??0,p.reasoning),l("output.audio",u.audio??0,p.audio),l("output.predictionAccepted",u.predictionAccepted??0,p.predictionAccepted),l("output.predictionRejected",u.predictionRejected??0,p.predictionRejected),u.extensions&&p.extensions))for(let[g,T]of Object.entries(u.extensions))l(`output.ext.${g}`,T,p.extensions[g]);let m=n?.tier;if(m&&e.tierMultipliers){let g=e.tierMultipliers[m];if(g!=null&&(i*=g,a))for(let T of Object.keys(s))s[T]*=g}let f=t.auxiliary,y=e.auxiliary;if(f&&y)for(let[g,T]of Object.entries(f)){let L=y[g];if(L==null||!T)continue;let b=T*L;i+=b,a&&(s[`auxiliary.${g}`]=b)}return a?{total:i,currency:r,breakdown:s}:{total:i,currency:r}}function xe(t,e){return`${t}::${e}`}function jt(t){let e=new Map,n=new Map,o=(r,a,s)=>{e.set(xe(r,a),{provider:r,model:a,pricing:s});let i=n.get(r);i||(i=new Set,n.set(r,i)),i.add(a)};if(t)for(let[r,a,s]of t)o(r,a,s);return{register:o,lookup(r,a){let s=e.get(xe(r,a));if(s)return s.pricing;let i=n.get(r);if(!i)return;let l;for(let c of i)if(a.startsWith(c)&&(!l||c.length>l.key.length)){let d=e.get(xe(r,c));d&&(l={key:c,pricing:d.pricing})}return l?.pricing},remove(r,a){let s=e.delete(xe(r,a));if(s){let i=n.get(r);i?.delete(a),i&&i.size===0&&n.delete(r)}return s},entries(){let r=e.values();return(function*(){for(let{provider:a,model:s,pricing:i}of r)yield[a,s,i]})()}}}function $t(t,e="USD"){return(n,o)=>{let r=t.lookup(o.provider,o.model);return r?dt(n,r,{tier:o.tier,withBreakdown:o.withBreakdown}):Ge(e)}}function Wt(...t){return(e,n)=>{for(let o of t){let r=o(e,n);if(r.total!==0)return r}return t.length>0?t[0](e,n):Ge()}}function je(t,e={}){let n=e.breaker??Qe(e);return{adapter:{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),async invoke(r,a){if(!n.canExecute())throw new ve;try{let s=await Promise.resolve(t.invoke(r,a));return n.recordSuccess(),s}catch(s){throw n.recordFailure(s),s}},async*stream(r,a){if(!n.canExecute())throw new ve;try{for await(let s of t.stream(r,a))yield s;n.recordSuccess()}catch(s){throw n.recordFailure(s),s}}},breaker:n}}var Le=class extends Error{constructor(n,o,r){super(`Budget exhausted: ${n} (limit=${o}, observed=${r})`);this.which=n;this.limit=o;this.observed=r}name="BudgetExhaustedError"},$e=Object.freeze({calls:0,inputTokens:0,outputTokens:0,usd:0}),ct=()=>({calls:0,inputTokens:0,outputTokens:0,usd:0});function We(t,e){let n=pe(void 0,{name:e.name?`${e.name}/log`:"budgetGate/log",maxSize:e.logMax??1e3}),o=x(ct(),{name:e.name?`${e.name}/totals`:"budgetGate/totals"}),r=N([o],([d])=>{let u=d;return!(e.caps.calls!=null&&u.calls>=e.caps.calls||e.caps.inputTokens!=null&&u.inputTokens>=e.caps.inputTokens||e.caps.outputTokens!=null&&u.outputTokens>=e.caps.outputTokens||e.caps.usd!=null&&u.usd>=e.caps.usd)},{name:e.name?`${e.name}/isOpen`:"budgetGate/isOpen",initial:!0});if(q(r),e.onExhausted!=null){let d=e.onExhausted,u=!1,p=!0;r.subscribe(m=>{for(let f of m)if(f[0]===z){let y=f[1];if(u&&p&&y===!1){let g=mt(o.cache??$e,e.caps);g&&d(g)}p=y,u=!0}})}let a=()=>{if(r.cache===!1){let d=o.cache??$e,u=mt(d,e.caps);return new Le(u??"budget",e.caps[u??"calls"]??0,Kt(d,u??"calls"))}},s=(d,u)=>{let p=t.provider,m={timestamp:W(),wallClock:he(),provider:p,model:u.model,tier:u.tier,usage:d,latencyMs:u.latencyMs,method:u.method,...u.error?{error:u.error}:{}};n.append(m);let f=o.cache??$e,y=e.pricingFn?f.usd+e.pricingFn(d,{model:u.model,provider:p,tier:u.tier}).total:f.usd;o.emit({calls:f.calls+1,inputTokens:f.inputTokens+te(d),outputTokens:f.outputTokens+oe(d),usd:y})},i=()=>{n.clear(),o.emit(ct())},l=()=>({input:{regular:0},output:{regular:0}});return{adapter:{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),invoke(d,u){let p=a();if(p)return Promise.reject(p);let m=W(),f=t.invoke(d,u),y=T=>{let L=Math.max(0,(W()-m)/1e6);return s(T.usage??l(),{model:t.model??u?.model??T.model??"",tier:u?.tier??T.tier,latencyMs:L,method:"invoke"}),T};if(f!=null&&typeof f.then=="function")return f.then(y);if(f!=null&&typeof f=="object"&&"content"in f)return y(f);let g=!1;return N([w(f)],([T])=>T==null||g?T:(g=!0,y(T)),{name:"budgetGate/invokeTap"})},async*stream(d,u){let p=a();if(p)throw p;let m=W(),f;try{for await(let y of t.stream(d,u))y.type==="usage"&&(f=y.usage),yield y;s(f??l(),{model:t.model??u?.model??"",tier:u?.tier,latencyMs:Math.max(0,(W()-m)/1e6),method:"stream"})}catch(y){let g=y;throw s(f??l(),{model:t.model??u?.model??"",tier:u?.tier,latencyMs:Math.max(0,(W()-m)/1e6),method:"stream",error:{type:g?.name??"Error",message:g?.message??String(y)}}),y}}},budget:{totals:o,isOpen:r,log:n,reset:i}}}function mt(t,e){if(e.calls!=null&&t.calls>=e.calls)return"calls";if(e.inputTokens!=null&&t.inputTokens>=e.inputTokens)return"inputTokens";if(e.outputTokens!=null&&t.outputTokens>=e.outputTokens)return"outputTokens";if(e.usd!=null&&t.usd>=e.usd)return"usd"}function Kt(t,e){switch(e){case"calls":return t.calls;case"inputTokens":return t.inputTokens;case"outputTokens":return t.outputTokens;case"usd":return t.usd}}function Ut(t,e){let n=e.mock??be({provider:t.provider,model:t.model}),o=typeof e.enabled=="boolean"?e.enabled:void 0,r=o===void 0?w(e.enabled):void 0,a;r&&(a=q(r));let s=()=>o!==void 0?o:!!r?.cache;return{adapter:{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),invoke(c,d){return s()?n.invoke(c,d):t.invoke(c,d)},stream(c,d){return s()?n.stream(c,d):t.stream(c,d)}},dispose:()=>{a&&(a(),a=void 0)}}}function Ke(t){if(t==null||typeof t!="object")return;let e=t,n=e.status,o=Vt(e.headers);if(n!==429&&n!==503&&!Qt(e.message))return;let r={},a=o("retry-after"),s=Ht(a);s!=null&&(r.retryAfterMs=s);let i=o("anthropic-ratelimit-requests-reset");if(i){let m=pt(i);m!=null&&(r.retryAfterMs=Math.max(r.retryAfterMs??0,m))}let l=o("anthropic-ratelimit-tokens-reset");if(l){let m=pt(l);m!=null&&(r.retryAfterMs=Math.max(r.retryAfterMs??0,m))}let c=we(o,"x-ratelimit-limit-requests");c!=null&&(r.rpmCap=c);let d=we(o,"x-ratelimit-limit-tokens");d!=null&&(r.tpmCap=d);let u=we(o,"x-ratelimit-remaining-requests"),p=we(o,"x-ratelimit-remaining-tokens");if(u!=null&&c!=null&&c>0&&(r.usageHint??={},r.usageHint.rpm=1-u/c),p!=null&&d!=null&&d>0&&(r.usageHint??={},r.usageHint.tpm=1-p/d),r.retryAfterMs==null&&e.message){let m=Jt(e.message);m!=null&&(r.retryAfterMs=m)}return e.headers&&(r.metadata={headers:qt(e.headers)}),r.retryAfterMs==null&&r.rpmCap==null&&r.tpmCap==null&&r.usageHint==null?r.metadata?r:void 0:r}function Vt(t){if(!t)return()=>{};if(typeof t.get=="function"){let o=t;return r=>o.get(r)??o.get(r.toLowerCase())??void 0}let e=t,n={};for(let[o,r]of Object.entries(e)){let a=Array.isArray(r)?r.join(", "):r;a!=null&&(n[o.toLowerCase()]=a)}return o=>n[o.toLowerCase()]}function qt(t){let e={};if(typeof t.forEach=="function")return t.forEach((n,o)=>{e[o]=n}),e;for(let[n,o]of Object.entries(t))o!=null&&(e[n]=Array.isArray(o)?o.join(", "):o);return e}function we(t,e){let n=t(e);if(n==null)return;let o=Number(n);return Number.isFinite(o)?o:void 0}function Ht(t){if(!t)return;let e=t.trim(),n=Number(e);if(Number.isFinite(n)&&n>=0)return n*1e3;let o=Date.parse(e);if(Number.isFinite(o)){let r=o-Date.now();if(r>0)return r}}function pt(t){if(!t)return;let e=Date.parse(t);if(Number.isFinite(e))return Math.max(0,e-Date.now())}var zt=/retry\s+(?:in|after)\s+(\d+(?:\.\d+)?)\s*(ms|s|sec|seconds?|m|min|minutes?)/i;function Jt(t){let e=zt.exec(t);if(!e)return;let n=Number(e[1]);if(!Number.isFinite(n))return;let o=(e[2]??"s").toLowerCase();if(o==="ms")return n;if(o.startsWith("s"))return n*1e3;if(o.startsWith("m"))return n*6e4}var Yt=/rate\s*limit|too\s*many\s*requests|quota|429/i;function Qt(t){return!!t&&Yt.test(t)}function Ue(t){let e=new Error(t);return e.name="AbortError",e}function gt(t={}){let e=Math.max(1,t.burstMultiplier??1),n=t.clampCooldownMs??6e4,o=t.rpm!=null?w(t.rpm):x(Number.POSITIVE_INFINITY),r=t.tpm!=null?w(t.tpm):x(Number.POSITIVE_INFINITY),a=x(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/signalRpmCap"}),s=x(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/signalTpmCap"}),i=x({},{name:"adaptiveRateLimiter/lastSignal"}),l=N([o,a],([R,A])=>Math.min(Number(R??1/0),Number(A??1/0)),{name:"adaptiveRateLimiter/effectiveRpm"}),c=N([r,s],([R,A])=>Math.min(Number(R??1/0),Number(A??1/0)),{name:"adaptiveRateLimiter/effectiveTpm"}),d=fe(Number(o.cache??Number.POSITIVE_INFINITY),e),u=fe(Number(r.cache??Number.POSITIVE_INFINITY),e),p=!1,m=!1,f=l.subscribe(R=>{for(let A of R)if(A[0]===z){let O=Number(A[1]);Number.isFinite(O)&&O>0?(d=fe(O,e),p=!1):O===1/0?(d=fe(1/0,e),p=!1):O<=0&&(p=!0)}}),y=c.subscribe(R=>{for(let A of R)if(A[0]===z){let O=Number(A[1]);Number.isFinite(O)&&O>0?(u=fe(O,e),m=!1):O===1/0?(u=fe(1/0,e),m=!1):O<=0&&(m=!0)}}),g=0,T=new Q,L=new Q,b;t.adaptation!=null&&(b=w(t.adaptation).subscribe(A=>{for(let O of A)O[0]===z&&C(O[1])}));function C(R){if(i.emit(R),R.rpmCap!=null&&Number.isFinite(R.rpmCap)&&R.rpmCap>=0&&(a.emit(R.rpmCap),Number.isFinite(n)&&n>0&&T.start(n,()=>a.emit(Number.POSITIVE_INFINITY))),R.tpmCap!=null&&Number.isFinite(R.tpmCap)&&R.tpmCap>=0&&(s.emit(R.tpmCap),Number.isFinite(n)&&n>0&&L.start(n,()=>s.emit(Number.POSITIVE_INFINITY))),R.retryAfterMs!=null&&R.retryAfterMs>0){let A=W()+R.retryAfterMs*1e6;A>g&&(g=A)}}let I=x(0,{name:"adaptiveRateLimiter/pending"}),K=x(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/rpmAvailable"}),j=x(Number.POSITIVE_INFINITY,{name:"adaptiveRateLimiter/tpmAvailable"}),U=R=>{I.emit((I.cache??0)+R)},D=()=>{K.emit(d.available()),j.emit(u.available())};async function V(R={}){let A=R.requestCost??1,O=R.tokenCost??0,M=R.signal;U(1);try{for(;;){if(M?.aborted)throw Ue("AdaptiveRateLimiter.acquire aborted");let h=W();if(g>h){let X=Math.ceil((g-h)/1e6);await Ne(X,M);continue}if(A>0&&p||O>0&&m){await Ne(250,M);continue}let k=d,v=u;if(!k.tryConsume(A)){await Ne(ft(k,A),M);continue}if(!(O>0?v.tryConsume(O):!0)){k.putBack(A),await Ne(ft(v,O),M);continue}D();return}}finally{U(-1)}}function $(R){R>0?u.tryConsume(R):R<0&&u.putBack(-R),D()}function B(){f(),y(),b?.(),T.cancel(),L.cancel()}return{effectiveRpm:l,effectiveTpm:c,lastSignal:i,pending:I,rpmAvailable:K,tpmAvailable:j,acquire:V,recordUsage:$,recordSignal:C,dispose:B}}function fe(t,e){if(!Number.isFinite(t)||t===1/0)return _e(Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER);let n=Math.max(1,t*e),o=t/60;return _e(n,o)}function ft(t,e){let n=t.available(),o=Math.max(0,e-n);return o<=0?25:Math.min(5e3,Math.max(50,o*100))}function Ne(t,e){return t<=0?Promise.resolve():e?.aborted?Promise.reject(Ue("AdaptiveRateLimiter.acquire aborted")):new Promise((n,o)=>{let r=new Q,a,s=()=>{r.cancel(),e&&a&&e.removeEventListener("abort",a)};r.start(t,()=>{s(),n()}),e&&(a=()=>{s(),o(Ue("AdaptiveRateLimiter.acquire aborted"))},e.addEventListener("abort",a,{once:!0}))})}function Ve(t,e={}){let n=e.limiter??gt({name:e.name??"rateLimiter",rpm:e.rpm,tpm:e.tpm,adaptation:e.adaptation,burstMultiplier:e.burstMultiplier}),o=(s,i)=>e.costFn?e.costFn(s,i):0,r=s=>{let i=Ke(s);i&&n.recordSignal(i)};return{adapter:{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),async invoke(s,i){let l=o(s,i);await n.acquire({requestCost:1,tokenCost:l,signal:i?.signal});try{let c=t.invoke(s,i),d=await Xt(c),u=d.usage??ut(),m=te(u)+oe(u)-l;return m>0&&n.recordUsage(m),d}catch(c){throw r(c),c}},async*stream(s,i){let l=o(s,i);await n.acquire({requestCost:1,tokenCost:l,signal:i?.signal});try{let c=0;for await(let u of t.stream(s,i))u.type==="usage"&&(c=te(u.usage)+oe(u.usage)),yield u;let d=c-l;d>0&&n.recordUsage(d)}catch(c){throw r(c),c}}},limiter:n}}async function Xt(t){return t!=null&&typeof t.then=="function"?await t:t&&typeof t=="object"&&"content"in t?t:await Ze(w(t))}function Ce(t="aborted"){let e=new Error(t);return e.name="AbortError",e}function yt(t,e){return t<=0?Promise.resolve():e?.aborted?Promise.reject(Ce()):new Promise((n,o)=>{let r=new Q,a,s=()=>{r.cancel(),e&&a&&e.removeEventListener("abort",a)};r.start(t,()=>{s(),n()}),e&&(a=()=>{s(),o(Ce())},e.addEventListener("abort",a,{once:!0}))})}function qe(t,e={}){let n=e.attempts??3,o=e.baseDelayMs??500,r=e.maxDelayMs??1e4,a=e.strategy??"decorrelated",s=e.jitter??!0,i=e.shouldRetry??Zt,l=e.retryStreaming??!0,c=(d,u)=>{if(a==="decorrelated"){let y=Math.min(r,Math.max(o,u*3));return o+Math.random()*(y-o)}let p=a==="exp"?o*2**(d-1):o*d,m=Math.min(r,p);if(!s)return m;let f=m*(.5+Math.random());return Math.min(r,f)};return{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),async invoke(d,u){if(u?.signal?.aborted)throw Ce();let p,m=o;for(let f=1;f<=n;f++)try{return await Promise.resolve(t.invoke(d,u))}catch(y){if(p=y,f>=n||!i(y,f))throw y;let g=c(f,m);m=g,await yt(g,u?.signal)}throw p},async*stream(d,u){if(u?.signal?.aborted)throw Ce();if(!l){for await(let f of t.stream(d,u))yield f;return}let p,m=o;for(let f=1;f<=n;f++){let y=!1;try{for await(let g of t.stream(d,u))y=!0,yield g;return}catch(g){if(p=g,y||f>=n||!i(g,f))throw g;let T=c(f,m);m=T,await yt(T,u?.signal)}}throw p}}}function Zt(t,e){if(t==null)return!1;let n=t;return n.name==="LLMTimeoutError"?!0:n.name==="AbortError"||n.message==="aborted"||n.name==="DOMException"&&n.code!=null&&Number(n.code)===20||n.name==="BudgetExhaustedError"||n.name==="CircuitOpenError"?!1:n.status!=null?n.status===429||n.status>=500&&n.status<600:n.code&&typeof n.code=="string"&&/^E[A-Z]+$/.test(n.code)?!0:n.message?/network|timeout|socket|fetch|econn|eai_/i.test(n.message):!1}var ge=class extends Error{constructor(n){super(`LLM call timed out after ${n}ms`);this.ms=n}name="LLMTimeoutError"};function He(t,e){if(e<=0)throw new RangeError("withTimeout: ms must be > 0");let n=r=>{let a=new AbortController,s=!1,i;r&&(r.aborted?a.abort(r.reason):(i=()=>a.abort(r.reason),r.addEventListener("abort",i,{once:!0})));let l=new Q;return l.start(e,()=>{s=!0,a.abort(new ge(e))}),{signal:a.signal,cancel:()=>{l.cancel(),r&&i&&r.removeEventListener("abort",i)},timedOut:()=>s}},o=(r,a)=>{if(!a||r instanceof ge)throw r;let s=r;if(s?.name==="AbortError"||s?.name==="DOMException"&&Number(s.code)===20||r?.message==="aborted"){let l=new ge(e);throw l.cause=r,l}throw r};return{provider:t.provider,model:t.model,capabilities:t.capabilities?.bind(t),async invoke(r,a){let{signal:s,cancel:i,timedOut:l}=n(a?.signal);try{return await Promise.resolve(t.invoke(r,{...a,signal:s}))}catch(c){return o(c,l())}finally{i()}},async*stream(r,a){let{signal:s,cancel:i,timedOut:l}=n(a?.signal);try{for await(let c of t.stream(r,{...a,signal:s}))yield c}catch(c){o(c,l())}finally{i()}}}}function en(t,e={}){let n={adapter:t},o=t;if(e.rateLimit){let r=Ve(o,e.rateLimit);o=r.adapter,n.rateLimiter=r.limiter}if(e.budget){let r=We(o,e.budget);o=r.adapter,n.budget=r.budget}if(e.breaker){let r=je(o,e.breaker);o=r.adapter,n.breaker=r.breaker}if(e.timeoutMs!=null&&(o=He(o,e.timeoutMs)),e.retry&&(o=qe(o,e.retry)),e.fallback){if(e.name==="fallback")throw new RangeError('resilientAdapter: `name` cannot be "fallback" \u2014 collides with the secondary tier label.');let r={};e.onFallback&&(r.onFallback=e.onFallback),e.onExhausted&&(r.onExhausted=e.onExhausted),o=Fe([{name:e.name??"primary",adapter:o},{name:"fallback",adapter:e.fallback}],r)}return n.adapter=o,n}function tn(){return be()}function _(t,e){return tt("ai",t,e)}function nn(t){return t!=null&&typeof t.then=="function"}function rn(t){return typeof t=="object"&&t!==null&&"subscribe"in t&&typeof t.subscribe=="function"&&"cache"in t}function on(t){return t!=null&&typeof t=="object"&&Symbol.asyncIterator in t&&typeof t[Symbol.asyncIterator]=="function"}var an=3e4;function ht(t,e){if(t.status==="settled"){let o=t.cache;if(o!==void 0)return Promise.resolve(o)}let n=e?.timeoutMs??an;return new Promise((o,r)=>{let a=new Q,s=t.subscribe(i=>{for(let l of i){if(l[0]===z){a.cancel(),s(),o(l[1]);return}if(l[0]===Y){a.cancel(),s(),r(l[1]);return}if(l[0]===ne){a.cancel(),s(),r(new Error("firstDataFromNode: completed without producing a value"));return}}});a.start(n,()=>{s(),r(new Error(`firstDataFromNode: timed out after ${n}ms`))})})}async function Ie(t){return nn(t)?Ie(await t):rn(t)?ht(t):on(t)?ht(w(t)):t}function sn(t,e){let n=w(t),o=e?.refreshTrigger!=null?w(e.refreshTrigger):null;return o==null?de([n],(r,a,s)=>{if(s.store.emitted===!0)return;let l=r[0],c=l!=null&&l.length>0?l.at(-1):s.prevData[0];if(c!==void 0)return s.store.emitted=!0,a.emit(c),{invalidate:()=>{s.store.emitted=!1}}},{name:e?.name??"frozenContext",describeKind:"derived",initial:null,meta:_("frozen_context")}):de([n,o],(r,a,s)=>{let i=r[1];if(!(i!=null&&i.length>0))return;let c=r[0],d=c!=null&&c.length>0?c.at(-1):s.prevData[0];a.emit(d)},{name:e?.name??"frozenContext",describeKind:"derived",initial:null,meta:_("frozen_context")})}function ln(t,e,n){let o=w(e);return ee(o,a=>{if(!a||a.length===0)return x(null);let s=n?.tools;return t.invoke(a,{model:n?.model,temperature:n?.temperature,maxTokens:n?.maxTokens,tools:s,systemPrompt:n?.systemPrompt})})}function un(t,e,n,o){let r=o?.name??"llm",a=o?.format??"text",s=De(`${r}/stream`),i=N(e,d=>{if(d.some(m=>m==null))return[];let u=typeof n=="string"?n:n(...d);if(!u)return[];let p=[];return o?.systemPrompt&&p.push({role:"system",content:o.systemPrompt}),p.push({role:"user",content:u}),p}),l=ee(i,d=>{let u=d;if(!u||u.length===0)return x(null);let p=new AbortController;async function*m(){let f="",y=0;try{for await(let T of t.stream(u,{model:o?.model,temperature:o?.temperature,maxTokens:o?.maxTokens,systemPrompt:o?.systemPrompt,signal:p.signal})){if(T.type!=="token")continue;let L=T.delta;f+=L,s.publish({source:r,token:L,accumulated:f,index:y++})}let g;if(a==="json")try{g=JSON.parse(Oe(f))}catch{g=null}else g=f;yield g}finally{p.abort()}}return w(m())}),c=q(l);return{output:l,stream:s,dispose:()=>{c(),s.destroy()}}}function dn(t,e,n){return N([t.latest],([o])=>o==null?null:e(o.accumulated),{name:n?.name??"extractor",describeKind:"derived",initial:null,meta:_("stream_extractor"),...n?.equals?{equals:n.equals}:{}})}var cn=(t,e)=>{if(t===e)return!0;if(t==null||e==null)return t===e;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++){let o=t[n],r=e[n];if(o.label!==r.label||o.pattern!==r.pattern||o.match!==r.match||o.position!==r.position)return!1}return!0};function mn(t,e){let n=e.maxPatternLength??128;return N([t.latest],([o],r)=>{if(o==null)return[];let a=o.accumulated;"flags"in r.store||(r.store.flags=[],r.store.scannedTo=0);let s=r.store.flags,i=r.store.scannedTo,l=Math.max(0,i-n),c=a.slice(l),d=!1;for(let{pattern:u,label:p}of e.patterns){let m=new RegExp(u.source,`${u.flags.replace("g","")}g`);for(let f of c.matchAll(m)){let y=l+f.index;y+f[0].length<=i||(s.push({label:p,pattern:u,match:f[0],position:y}),d=!0)}}return r.store.scannedTo=a.length,d?[...s]:s.slice()},{name:e.name??"keyword-flag-extractor",describeKind:"derived",initial:[],meta:_("keyword_flag_extractor"),equals:cn})}var pn=(t,e)=>{if(t===e)return!0;if(t==null||e==null)return t===e;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++){let o=t[n],r=e[n];if(o.startIndex!==r.startIndex||o.name!==r.name||o.raw!==r.raw)return!1}return!0};function fn(t,e){return N([t.latest],([n],o)=>{if(n==null)return[];let r=n.accumulated;"calls"in o.store||(o.store.calls=[],o.store.scanFrom=0);let a=o.store.calls,s=o.store.scanFrom,i=!1;for(;s<r.length;){let l=r.indexOf("{",s);if(l===-1){o.store.scanFrom=r.length;break}let c=0,d=-1,u=!1;for(let m=l;m<r.length;m++){let f=r[m];if(u)f==="\\"&&m+1<r.length?m++:f==='"'&&(u=!1);else if(f==='"')u=!0;else if(f==="{")c++;else if(f==="}"&&(c--,c===0)){d=m;break}}if(d===-1){o.store.scanFrom=l;break}let p=r.slice(l,d+1);try{let m=JSON.parse(p);typeof m.name=="string"&&m.arguments!=null&&typeof m.arguments=="object"&&(a.push({name:m.name,arguments:m.arguments,raw:p,startIndex:l}),i=!0)}catch{}s=d+1,o.store.scanFrom=s}return i?[...a]:a.slice()},{name:e?.name??"tool-call-extractor",describeKind:"derived",initial:[],meta:_("tool_call_extractor"),equals:pn})}var gn=(t,e)=>t===e?!0:t.chunkCount===e.chunkCount&&t.charCount===e.charCount&&t.estimatedTokens===e.estimatedTokens;function yn(t,e){let n=e?.charsPerToken??4;return N([t.latest],([o])=>{if(o==null)return{chunkCount:0,charCount:0,estimatedTokens:0};let r=o,a=r.accumulated.length;return{chunkCount:r.index+1,charCount:a,estimatedTokens:Math.ceil(a/n)}},{name:e?.name??"cost-meter",describeKind:"derived",initial:{chunkCount:0,charCount:0,estimatedTokens:0},meta:_("cost_meter_extractor"),equals:gn})}function hn(t,e,n,o){let r=n??(()=>"[REDACTED]");function a(s){let i=s;for(let l of e){let c=l.global?l:new RegExp(l.source,`${l.flags}g`);i=i.replace(c,d=>r(d,l))}return i}return N([t.latest],([s])=>{if(s==null)return{source:"",token:"",accumulated:"",index:-1};let i=s,l=a(i.accumulated),c=a(i.token);return{source:i.source,token:c,accumulated:l,index:i.index}},{name:o?.name??"redactor"})}function bn(t,e,n,o){let r=n*(o?.hardMultiplier??1.5),a=typeof e!="function",s=[t.latest];return a&&s.push(e),N(s,i=>{let l=i[0];if(l==null)return"allow";let c=a?i[1]??0:e(l.accumulated);return c>=r?"block":c>=n?"review":"allow"},{name:o?.name??"content-gate",initial:"allow"})}function Tn(t,e,n,o,r,a){let s=x(0,{name:`${e}/cancel`}),i=0,l=[...o,s],c=a?.name??e,d=a?.format??"text",u=De(`${c}/stream`),p=N(l,b=>{let C=b.slice(0,-1);if(C.some(j=>j==null))return[];let I=typeof r=="string"?r:r(...C);if(!I)return[];let K=[];return a?.systemPrompt&&K.push({role:"system",content:a.systemPrompt}),K.push({role:"user",content:I}),K}),m=ee(p,b=>{let C=b;if(!C||C.length===0)return x(null);let I=new AbortController;async function*K(){let j="",U=0;try{for await(let V of n.stream(C,{model:a?.model,temperature:a?.temperature,maxTokens:a?.maxTokens,systemPrompt:a?.systemPrompt,signal:I.signal})){if(V.type!=="token")continue;let $=V.delta;j+=$,u.publish({source:c,token:$,accumulated:j,index:U++})}let D;if(d==="json")try{D=JSON.parse(Oe(j))}catch{D=null}else D=j;yield D}finally{I.abort()}}return w(K())}),f=q(m),y=N([m],([b])=>{if(b!=null)return b},{name:`${e}/filter`});t.add(y,{name:`${e}/raw`});let g=lt(t,`${e}/gate`,`${e}/raw`,a?.gate),T=g.reject.bind(g),L={...g,reject(b=1){T(b),s.emit(++i)}};return{output:g.node,stream:u,gate:L,dispose:()=>{f(),u.destroy()}}}function Mn(t){return t!=null&&typeof t=="object"&&"content"in t?String(t.content):typeof t=="string"?t:String(t)}function kn(t,e,n,o){let r=o?.format??"text",a=o?.retries??0,s=o?.cache??!1,i=s?new Map:null,l=N(e,d=>{if(d.some(m=>m==null))return[];let u=typeof n=="string"?n:n(...d);if(!u)return[];let p=[];return o?.systemPrompt&&p.push({role:"system",content:o.systemPrompt}),p.push({role:"user",content:u}),p},{name:o?.name?`${o.name}::messages`:"prompt_node::messages",meta:_("prompt_node"),initial:[]});return ee(l,d=>{if(!d||d.length===0)return x(null);let u=s?JSON.stringify(d.map(m=>[m.role,m.content])):"";if(i?.has(u))return x(i.get(u));async function p(m){try{let f=await new Promise((T,L)=>{let b=t.invoke(d,{model:o?.model,temperature:o?.temperature,maxTokens:o?.maxTokens,systemPrompt:o?.systemPrompt});b&&typeof b.then=="function"?b.then(T,L):b&&typeof b.subscribe=="function"?T(b.cache):T(b)}),y=Mn(f),g;return r==="json"?g=JSON.parse(Oe(y)):g=y,i?.set(u,g),g}catch(f){if(m>0)return p(m-1);throw f}}return p(a)})}function vn(t,e,n){let o=w(t),r=n?.condition!=null?w(n.condition):null,a=x(null,{name:n?.name?`${n.name}::null`:"handoff::null"});if(r==null)return ee(o,i=>{if(i==null)return a;let l=x(i);return e(l)});let s=N([o,r],([i,l])=>({v:i,open:l===!0}),{name:n?.name?`${n.name}::router`:"handoff::router",describeKind:"derived"});return ee(s,({v:i,open:l})=>{if(i==null)return a;if(!l)return x(i);let c=x(i);return e(c)})}var Se=class extends me{_log;messages;latest;messageCount;constructor(e,n={}){super(e,n.graph),this._log=pe([],{name:"messages",maxSize:n.maxMessages}),this.messages=this._log.entries,this.add(this.messages,{name:"messages"}),this.latest=N([this.messages],([o])=>{let r=o;return r.length===0?null:r[r.length-1]},{name:"latest",describeKind:"derived",meta:_("chat_latest")}),this.add(this.latest,{name:"latest"}),this.addDisposer(q(this.latest)),this.messageCount=N([this.messages],([o])=>o.length,{name:"messageCount",describeKind:"derived",meta:_("chat_message_count"),initial:0}),this.add(this.messageCount,{name:"messageCount"}),this.addDisposer(q(this.messageCount))}append(e,n,o){this._log.append({role:e,content:n,...o})}appendToolResult(e,n){this._log.append({role:"tool",content:n,toolCallId:e})}clear(){this._log.clear()}allMessages(){return this.messages.cache}};function Mt(t,e){return new Se(t,e)}var Ae=class extends me{definitions;schemas;constructor(e,n={}){super(e,n.graph),this.definitions=x(new Map,{name:"definitions",describeKind:"state",meta:_("tool_definitions")}),this.add(this.definitions,{name:"definitions"}),this.schemas=N([this.definitions],([o])=>[...(o??new Map).values()],{name:"schemas",describeKind:"derived",meta:_("tool_schemas"),initial:[]}),this.add(this.schemas,{name:"schemas"}),this.addDisposer(q(this.schemas))}register(e){let n=this.definitions.cache,o=new Map(n);o.set(e.name,e),this.definitions.emit(o)}unregister(e){let n=this.definitions.cache;if(!n.has(e))return;let o=new Map(n);o.delete(e),this.definitions.emit(o)}async execute(e,n){let r=this.definitions.cache.get(e);if(!r)throw new Error(`toolRegistry: unknown tool "${e}"`);let a=r.handler(n);return Ie(a)}getDefinition(e){return this.definitions.cache?.get(e)}};function kt(t,e){return new Ae(t,e)}function Rn(t,e,n){let o=w(t),r=e.map(s=>w(s)),a=[o,...r];return N(a,s=>{let i=s[0]??[],l=s.slice(1);return i.filter(c=>{for(let d of l)if(d!=null&&!d(c))return!1;return!0})},{name:n?.name??"tool-selector",describeKind:"derived",meta:_("tool_selector"),equals:(s,i)=>{let l=s,c=i;if(l.length!==c.length)return!1;for(let d=0;d<l.length;d++)if(l[d]!==c[d])return!1;return!0}})}function xn(t,e){let n=e?.separator??`
|
|
2
|
-
|
|
3
|
-
`,o=t.map(s=>typeof s=="string"?x(s):w(s)),r=N(o,s=>s.filter(i=>i!=null&&i!=="").join(n),{name:e?.name??"systemPrompt",describeKind:"derived",meta:_("system_prompt"),initial:""}),a=q(r);return Object.assign(r,{dispose:a})}function vt(t,e){return(n,o)=>{let r=[...o.keys()].slice(0,100),a=[{role:"system",content:t},{role:"user",content:JSON.stringify({input:n,existingKeys:r})}];return Pe(s=>{let i=!0,l=e.adapter.invoke(a,{model:e.model,temperature:e.temperature??0,maxTokens:e.maxTokens}),d=w(l).subscribe(u=>{if(!i)return;let p=!1;for(let m of u){if(p)break;if(m[0]===z){let f=m[1];try{let y=JSON.parse(f.content);s.emit(y),s.down([[ne]])}catch{s.down([[Y,new Error("llmExtractor: failed to parse LLM response as JSON")]])}p=!0}else m[0]===Y?(s.down([[Y,m[1]]]),p=!0):m[0]===ne?(s.down([[ne]]),p=!0):s.down([[m[0],m[1]]])}});return()=>{d(),i=!1}})}}function Rt(t,e){return n=>{let o=[...n.entries()].map(([a,s])=>({key:a,value:s})),r=[{role:"system",content:t},{role:"user",content:JSON.stringify({memories:o})}];return Pe(a=>{let s=!0,i=e.adapter.invoke(r,{model:e.model,temperature:e.temperature??0,maxTokens:e.maxTokens}),c=w(i).subscribe(d=>{if(!s)return;let u=!1;for(let p of d){if(u)break;if(p[0]===z){let m=p[1];try{let f=JSON.parse(m.content);a.emit(f),a.down([[ne]])}catch{a.down([[Y,new Error("llmConsolidator: failed to parse LLM response as JSON")]])}u=!0}else p[0]===Y?(a.down([[Y,p[1]]]),u=!0):p[0]===ne?(a.down([[ne]]),u=!0):a.down([[p[0],p[1]]])}});return()=>{c(),s=!1}})}}function Ln(t){return{persistence:.5,structure:.5,personalValue:.5}}function wn(t={}){let e=t.scoreFn??Ln,n=t.persistenceThreshold??.3,o=t.personalValueThreshold??.3,r=t.requireStructured??!1;return a=>{let s=e(a);return!(s.persistence<n||s.personalValue<o||r&&s.structure<=0)}}var Nn=Math.LN2/(7*86400);function Te(t){return t instanceof Map?t:new Map}function Cn(t,e,n){let o=new me(t,n.graph),r=[],a;if(n.extractFn)a=n.extractFn;else if(n.adapter&&n.extractPrompt)a=vt(n.extractPrompt,{adapter:n.adapter});else throw new Error("agentMemory: provide either extractFn or adapter + extractPrompt");let s=(b,C)=>b==null?{upsert:[]}:a(b,C),i=e;if(n.admissionFilter){let b=w(e),C=n.admissionFilter;i=N([b],([I])=>{if(C(I))return I},{name:"admissionFilter",describeKind:"derived"})}let l;n.consolidateFn?l=n.consolidateFn:n.adapter&&n.consolidatePrompt&&(l=Rt(n.consolidatePrompt,{adapter:n.adapter}));let c=n.consolidateTrigger;if(!c&&l&&n.reflection?.enabled!==!1){let b=n.reflection?.interval??3e5;c=Xe(b,{period:b})}let d={score:n.score,cost:n.cost,budget:n.budget??2e3,context:n.context,consolidate:l,consolidateTrigger:c},u=rt(i,s,d);o.add(u.store.entries,{name:"store"}),o.add(u.compact,{name:"compact"}),o.add(u.size,{name:"size"});let p=null;n.vectorDimensions&&n.vectorDimensions>0&&n.embedFn&&(p=st({dimension:n.vectorDimensions}),o.add(p.entries,{name:"vectorIndex"}));let m=null;n.enableKnowledgeGraph&&(m=it(`${t}-kg`),o.mount("kg",m));let f=null;if(n.tiers){let b=n.tiers,C=b.decayRate??Nn,I=b.maxActive??1e3,K=b.archiveThreshold??.1,j=b.permanentFilter??(()=>!1),U=at({name:"permanent"});o.add(U.entries,{name:"permanent"});let D=new Set,V=h=>D.has(h)?"permanent":Te(u.store.entries.cache).has(h)?"active":"archived",$=(h,k)=>{D.add(h),U.upsert(h,k)},B=new Map,R=u.store.entries,A=n.context?w(n.context):x(null),O=ce([R,A],([h,k])=>{let v=Te(h),E=W(),S=[],X=[];for(let[F,J]of v){if(B.has(F)||B.set(F,E),j(F,J)){X.push({key:F,value:J});continue}let H=n.score(J,k),P=B.get(F)??E,G=Number(E-P)/1e9;ot(H,G,C)<K&&S.push(F)}for(let F of B.keys())v.has(F)||B.delete(F);for(let{key:F,value:J}of X)D.has(F)||$(F,J);let Z=v.size-D.size;if(Z>I){let F=[...v.entries()].filter(([H])=>!D.has(H)).map(([H,P])=>({key:H,score:n.score(P,k)})).sort((H,P)=>H.score-P.score),J=Z-I;for(let H=0;H<J&&H<F.length;H++){let P=F[H].key;S.includes(P)||S.push(P)}}S.length>0&&ue(()=>{for(let F of S)u.store.delete(F)})});r.push(O.subscribe(()=>{}));let M=null;b.archiveTier&&(M=o.attachStorage([b.archiveTier],b.archiveStorageOptions??{})),f={permanent:U,activeEntries:R,archiveHandle:M,tierOf:V,markPermanent:$}}if(p||m){let b=n.embedFn,C=n.entityFn,I=u.store.entries,K=ce([I],([j])=>{let U=Te(j);for(let[D,V]of U){if(p&&b){let $=b(V);$&&p.upsert(D,$,V)}if(m&&C){let $=C(D,V);if($){for(let B of $.entities??[])m.upsertEntity(B.id,B.value);for(let B of $.relations??[])m.link(B.from,B.to,B.relation,B.weight)}}}});r.push(K.subscribe(()=>{}))}let y=null,g=null,T=null,L=null;if(p||m){let b=n.retrieval?.topK??20,C=n.retrieval?.graphDepth??1,I=n.budget??2e3,K=n.cost,j=n.score,U=n.contextOf,D=n.contextWeight??0,V=n.context?w(n.context):x(null),$=(M,h)=>{if(!M||!h)return 0;let k=Math.min(M.length,h.length),v=0;for(;v<k&&M[v]===h[v];)v++;return v},B=(M,h,k)=>{let v=new Map,E=[];if(p&&k.vector){E=p.search(k.vector,b);for(let P of E){let G=M.get(P.id);G&&v.set(P.id,{value:G,sources:new Set(["vector"])})}}let S=[];if(m){let P=[...k.entityIds??[],...v.keys()],G=new Set,ae=P;for(let se=0;se<C;se++){let re=[];for(let ye of ae){if(G.has(ye))continue;G.add(ye);let ke=m.related(ye);for(let Lt of ke){let ie=Lt.to;if(!G.has(ie)){re.push(ie);let ze=M.get(ie);if(ze){let Je=v.get(ie);Je?Je.sources.add("graph"):v.set(ie,{value:ze,sources:new Set(["graph"])}),S.push(ie)}}}}ae=re}}for(let[P,G]of M)v.has(P)||v.set(P,{value:G,sources:new Set(["store"])});let X=k.context?.length??0,Z=[];for(let[P,{value:G,sources:ae}]of v){let se=U?U(G):void 0,re=j(G,h);if(D>0&&X>0){let ke=$(k.context,se);ke>0&&(re=re*(1+D*ke/X))}let ye=se?{key:P,value:G,score:re,sources:[...ae],context:se}:{key:P,value:G,score:re,sources:[...ae]};Z.push(ye)}Z.sort((P,G)=>G.score-P.score);let F=[],J=0;for(let P of Z){let G=K(P.value);if(J+G>I&&F.length>0)break;F.push(P),J+=G}return{packed:F,trace:{vectorCandidates:E,graphExpanded:S,ranked:Z,packed:F}}},R=x([],{name:"retrieval",describeKind:"state",meta:_("retrieval_pipeline")});o.add(R,{name:"retrieval"}),y=R;let A=x(null,{name:"retrievalTrace",describeKind:"state",meta:_("retrieval_trace")});o.add(A,{name:"retrievalTrace"}),g=A,T=M=>{let h=Te(u.store.entries.cache),{packed:k,trace:v}=B(h,V.cache,M);return ue(()=>{R.emit(k),A.emit(v)}),k},L=M=>{let h=w(M);return N([u.store.entries,V,h],([k,v,E])=>{if(E==null)return[];let S=Te(k);return B(S,v,E).packed},{name:"retrievalReactive",describeKind:"derived",meta:_("retrieval_reactive"),initial:[]})}}return o.addDisposer(()=>{for(let b of r)b();r.length=0}),Object.assign(o,{distillBundle:u,compact:u.compact,size:u.size,vectors:p,kg:m,memoryTiers:f,retrieval:y,retrievalTrace:g,retrieve:T,retrieveReactive:L})}var Ee=class extends me{chat;tools;status;turn;aborted;lastResponse;toolCalls;toolResults;turnCount;_terminalResult;_disposeRunWiring;_runVersion=0;_running=!1;_currentAbortController=null;constructor(e,n){if(super(e,n.graph),this.chat=Mt(`${e}-chat`,{maxMessages:n.maxMessages}),this.mount("chat",this.chat),this.tools=kt(`${e}-tools`),this.mount("tools",this.tools),n.tools)for(let M of n.tools)this.tools.register(M);this.status=x("idle",{name:"status",describeKind:"state",meta:_("agent_status")}),this.add(this.status,{name:"status"}),this.turn=x(0,{name:"turn",describeKind:"state",meta:_("agent_turn_count")}),this.add(this.turn,{name:"turn"}),this.turnCount=this.turn,this.aborted=x(!1,{name:"aborted",describeKind:"state",meta:_("agent_aborted")}),this.add(this.aborted,{name:"aborted"});let o=0,r=this.turn.subscribe(M=>{for(let h of M)h[0]===z&&(o=h[1])}),a=!1,s=this.aborted.subscribe(M=>{for(let h of M)h[0]===z&&(a=h[1])}),i=n.adapter,l=n.systemPrompt,c=n.model,d=n.temperature,u=n.maxTokens,p=n.maxTurns??10,m=n.stopWhen,f=this.chat,y=this.tools,g=this.status,T=this.turn,L=this.aborted,b=de([g],(M,h,k)=>{if(Me(M,k.prevData,0,"idle")!=="thinking"||a||o>=p){h.down([[le]]);return}let E=f.allMessages();if(E.length===0){h.down([[le]]);return}let S=y.schemas.cache??[];h.emit({messages:E,tools:S})},{name:"promptInput",describeKind:"derived",meta:_("agent_prompt_input")}),C=ee(b,M=>{let h=new AbortController;return this._currentAbortController=h,a&&h.abort(new Error("agentLoop: aborted")),w(Promise.resolve(i.invoke(M.messages,{tools:M.tools.length>0?M.tools:void 0,systemPrompt:l,model:c,temperature:d,maxTokens:u,signal:h.signal})),{signal:h.signal})},{equals:()=>!1}),I=x(null,{name:"lastResponse",describeKind:"state",meta:_("agent_last_response")});this.lastResponse=I;let K=de([I,g],(M,h,k)=>{let v=Me(M,k.prevData,0,null);if(Me(M,k.prevData,1,"idle")!=="acting"){h.down([[le]]);return}let S=v?.toolCalls;if(S==null||S.length===0){h.down([[le]]);return}h.emit(S)},{name:"toolCalls",describeKind:"derived",meta:_("agent_tool_calls")}),j=n.interceptToolCalls?n.interceptToolCalls(K):K;this.toolCalls=j;let U=(M,h)=>{if(M===h)return!0;if(M.length!==h.length)return!1;for(let k=0;k<M.length;k++){let v=M[k],E=h[k];if(v?.id!==E?.id||v?.content!==E?.content)return!1}return!0},D=ee(j,M=>{if(M==null||M.length===0)throw new Error("agentLoop: toolResultsNode received an empty tool-call batch as DATA \u2014 toolCallsNode gating invariant broken (should emit RESOLVED for empty). Audit toolCallsNode.");let h=M.map(k=>Sn(k,y));return N(h,k=>k.map((v,E)=>{let S=v;return S!=null&&typeof S=="object"&&"id"in S&&"content"in S?S:{id:M[E].id,content:JSON.stringify(v??null)}}),{name:"toolResults_batch",equals:U})});this.toolResults=D;let V=ce([C],([M])=>{if(a)return;let h=M,k=o+1,v=h.toolCalls!=null&&h.toolCalls.length>0,E=h.finishReason==="end_turn"&&(!h.toolCalls||h.toolCalls.length===0),S=m?.(h)===!0,X=k>=p,Z=S||E||!v||X?"done":"acting";ue(()=>{I.emit(h),g.emit(Z),T.emit(k),f.append("assistant",h.content,{toolCalls:h.toolCalls})})}),$=ce([D],([M])=>{if(a)return;let h=M;if(h.length===0)return;let k=o>=p?"done":"thinking";ue(()=>{g.emit(k);for(let v of h)f.appendToolResult(v.id,v.content)})}),B=ce([L],([M])=>{M===!0&&(this._currentAbortController?.abort(new Error("agentLoop: aborted")),g.emit("done"))}),R=q(V),A=q($),O=q(B);this._terminalResult=de([g,I],(M,h,k)=>{let v=Me(M,k.prevData,0,"idle"),E=Me(M,k.prevData,1,null);if(v==="done"){if(E!=null){h.emit({response:E,runVersion:this._runVersion});return}let S=new Error("agentLoop: aborted");S.name="AbortError",h.down([[Y,S]]);return}if(v==="error"){h.down([[Y,new Error("agentLoop: errored")]]);return}h.down([[le]])},{name:"terminalResult",describeKind:"derived",meta:_("agent_terminal_result")}),this.addDisposer(r),this.addDisposer(s),this.addDisposer(R),this.addDisposer(A),this.addDisposer(O),this._disposeRunWiring=()=>{}}async run(e,n){if(this._running)throw new RangeError(`agentLoop "${this.name}": run() called while a previous run() is still pending \u2014 await the previous run before starting another, or call abort() first`);this._running=!0;let o=++this._runVersion;ue(()=>{this.turn.emit(0),this.aborted.emit(!1),this.status.emit("idle")}),e!=null&&this.chat.append("user",e),this.status.emit("thinking");let r;if(n!=null)if(n.aborted)this.aborted.emit(!0);else{let a=()=>this.aborted.emit(!0);n.addEventListener("abort",a,{once:!0}),r=()=>n.removeEventListener("abort",a)}try{return(await et(this._terminalResult,{predicate:s=>s!=null&&typeof s=="object"&&s.runVersion===o})).response}finally{r?.(),this._running=!1,this._currentAbortController=null}}abort(){this.aborted.emit(!0)}destroy(){try{this._disposeRunWiring()}catch{}super.destroy()}};function Sn(t,e){let n=Ye(()=>w(Promise.resolve().then(()=>e.execute(t.name,t.arguments))),{count:1}),o=N([n],([r])=>({id:t.id,content:typeof r=="string"?r:JSON.stringify(r)}));return nt(o,r=>({id:t.id,content:JSON.stringify({error:String(r)})}))}function Me(t,e,n,o){let r=t[n];if(r!=null&&r.length>0)return r[r.length-1];let a=e[n];return a!==void 0?a:o}function An(t,e){return new Ee(t,e)}function En(t){let e={},n=t.type;return n==="enum"&&Array.isArray(t.values)?(e.type="string",e.enum=t.values):n==="integer"?e.type="integer":n==="number"?e.type="number":n==="boolean"?e.type="boolean":n==="string"?e.type="string":e.type=["string","number","boolean"],Array.isArray(t.range)&&t.range.length===2&&(e.minimum=t.range[0],e.maximum=t.range[1]),typeof t.format=="string"&&(e.description=`Format: ${t.format}`),typeof t.unit=="string"&&(e.description?e.description+=` (${t.unit})`:e.description=`Unit: ${t.unit}`),e}function In(t,e){let n=t.describe({actor:e,detail:"full"}),o=[],r=[],a=[];for(let[s,i]of Object.entries(n.nodes)){if(i.type!=="state"||s.includes("::__meta__::")||i.status==="completed"||i.status==="errored")continue;let l=i.meta??{},c=l.access;if(c==="human"||c==="system")continue;let d=l.description??`Set the value of ${s}`,u=En(l),p={type:"object",required:["value"],properties:{value:u},additionalProperties:!1},m=s.replace(/::/g,"__");o.push({type:"function",function:{name:m,description:d,parameters:p}}),r.push({name:s,description:d,inputSchema:p});let f=t,y=e,g=i.v;a.push({name:s,description:d,parameters:p,handler(T){return f.set(s,T.value,y?{actor:y}:void 0),T.value},...g!=null?{version:{id:g.id,version:g.version}}:{}})}return{openai:o,mcp:r,definitions:a}}function On(t,e,n){let o=t.describe({actor:e,detail:"full"}),r=n?.groupByTags??!0,a=n?.separator??`
|
|
4
|
-
`,s=[],i=n?.sinceVersion;for(let[l,c]of Object.entries(o.nodes)){let d=c.meta??{},u=d.description,p=d.format;if(!u&&!p)continue;if(i!=null&&c.v!=null){let T=i.get(l);if(T!=null&&T.id===c.v.id&&c.v.version<=T.version)continue}let m=u??l,f=c.value,y=d.unit,g;p==="currency"&&typeof f=="number"?g=`$${f.toFixed(2)}`:p==="percentage"&&typeof f=="number"?g=`${(f*100).toFixed(1)}%`:f==null?g="(no value)":g=String(f),y&&p!=="currency"&&p!=="percentage"&&(g=`${g} ${y}`),s.push({path:l,description:m,formatted:g})}if(s.length===0)return"";if(r){let l=new Map,c=[];for(let u of s){let m=o.nodes[u.path].meta?.tags;if(m&&m.length>0){let f=m[0],y=l.get(f);y||(y=[],l.set(f,y)),y.push(u)}else c.push(u)}if(l.size===0)return s.map(u=>`- ${u.description}: ${u.formatted}`).join(a);let d=[];for(let[u,p]of[...l.entries()].sort((m,f)=>m[0].localeCompare(f[0])))d.push(`[${u}]${a}${p.map(m=>`- ${m.description}: ${m.formatted}`).join(a)}`);return c.length>0&&d.push(c.map(u=>`- ${u.description}: ${u.formatted}`).join(a)),d.join(a+a)}return s.map(l=>`- ${l.description}: ${l.formatted}`).join(a)}var bt=new Set(["state","derived","producer","operator","effect"]);function xt(t){let e=[];if(t==null||typeof t!="object")return{valid:!1,errors:["Definition must be a non-null object"]};let n=t;if((typeof n.name!="string"||n.name.length===0)&&e.push("Missing or empty 'name' field"),n.nodes==null||typeof n.nodes!="object"||Array.isArray(n.nodes))return e.push("Missing or invalid 'nodes' field (must be an object)"),{valid:!1,errors:e};let o=new Set(Object.keys(n.nodes));for(let[r,a]of Object.entries(n.nodes)){if(a==null||typeof a!="object"){e.push(`Node "${r}": must be an object`);continue}let s=a;if((typeof s.type!="string"||!bt.has(s.type))&&e.push(`Node "${r}": invalid type "${String(s.type)}" (expected: ${[...bt].join(", ")})`),Array.isArray(s.deps))for(let i of s.deps)typeof i=="string"&&!o.has(i)&&e.push(`Node "${r}": dep "${i}" does not reference an existing node`)}if(!Array.isArray(n.edges))n.edges!==void 0&&e.push("'edges' must be an array");else{let r=new Set;for(let a=0;a<n.edges.length;a++){let s=n.edges[a];if(s==null||typeof s!="object"){e.push(`Edge [${a}]: must be an object`);continue}let i=s;(typeof i.from!="string"||!o.has(i.from))&&e.push(`Edge [${a}]: 'from' "${String(i.from)}" does not reference an existing node`),(typeof i.to!="string"||!o.has(i.to))&&e.push(`Edge [${a}]: 'to' "${String(i.to)}" does not reference an existing node`);let l=`${i.from}->${i.to}`;r.has(l)&&e.push(`Edge [${a}]: duplicate edge ${l}`),r.add(l)}}return{valid:e.length===0,errors:e}}function Oe(t){let e=t.match(/^```(?:json)?\s*([\s\S]*?)\s*```[\s\S]*$/);return e?e[1]:t}var Tt=`You are a graph architect for GraphReFly, a reactive graph protocol.
|
|
5
|
-
|
|
6
|
-
Given a natural-language description, produce a JSON graph definition with this structure:
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
"name": "<graph_name>",
|
|
10
|
-
"nodes": {
|
|
11
|
-
"<node_name>": {
|
|
12
|
-
"type": "state" | "derived" | "producer" | "operator" | "effect",
|
|
13
|
-
"value": <initial_value_or_null>,
|
|
14
|
-
"deps": ["<dep_node_name>", ...],
|
|
15
|
-
"meta": {
|
|
16
|
-
"description": "<human-readable purpose>",
|
|
17
|
-
"type": "string" | "number" | "boolean" | "integer" | "enum",
|
|
18
|
-
"range": [min, max],
|
|
19
|
-
"values": ["a", "b"],
|
|
20
|
-
"format": "currency" | "percentage" | "status",
|
|
21
|
-
"access": "human" | "llm" | "both" | "system",
|
|
22
|
-
"unit": "<unit>",
|
|
23
|
-
"tags": ["<tag>"]
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"edges": [
|
|
28
|
-
{ "from": "<source_node>", "to": "<target_node>" }
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
Rules:
|
|
33
|
-
- "state" nodes have no deps and hold user/LLM-writable values (knobs).
|
|
34
|
-
- "derived" nodes have deps and compute from them.
|
|
35
|
-
- "effect" nodes have deps but produce side effects (no return value).
|
|
36
|
-
- "producer" nodes have no deps but generate values asynchronously.
|
|
37
|
-
- Edges wire output of one node as input to another. They must match deps.
|
|
38
|
-
- meta.description is required for every node.
|
|
39
|
-
- Return ONLY valid JSON, no markdown fences or commentary.`;async function Pn(t,e,n){let r=[{role:"system",content:n?.systemPromptExtra?`${Tt}
|
|
40
|
-
|
|
41
|
-
${n.systemPromptExtra}`:Tt},{role:"user",content:t}],a=e.invoke(r,{model:n?.model,temperature:n?.temperature??0,maxTokens:n?.maxTokens}),i=(await Ie(a)).content.trim();i.startsWith("```")&&(i=Oe(i));let l;try{l=JSON.parse(i)}catch{throw new Error(`graphFromSpec: LLM response is not valid JSON: ${i.slice(0,200)}`)}let c=xt(l);if(!c.valid)throw new Error(`graphFromSpec: invalid graph definition:
|
|
42
|
-
${c.errors.join(`
|
|
43
|
-
`)}`);let d=l;return d.version===void 0&&(d.version=1),Array.isArray(d.subgraphs)||(d.subgraphs=[]),me.fromSnapshot(d,n?.build)}var _n=`You are a reactive graph optimizer for GraphReFly.
|
|
44
|
-
|
|
45
|
-
Given a graph's current structure (from describe()) and a problem statement, suggest topology and parameter changes to solve the problem.
|
|
46
|
-
|
|
47
|
-
Return ONLY valid JSON with this structure:
|
|
48
|
-
{
|
|
49
|
-
"summary": "<one-line summary of the strategy>",
|
|
50
|
-
"reasoning": "<explanation of why these changes help>",
|
|
51
|
-
"operations": [
|
|
52
|
-
{ "type": "add_node", "name": "<name>", "nodeType": "state|derived|effect|producer|operator", "meta": {...}, "initial": <value> },
|
|
53
|
-
{ "type": "remove_node", "name": "<name>" },
|
|
54
|
-
{ "type": "connect", "from": "<source>", "to": "<target>" },
|
|
55
|
-
{ "type": "disconnect", "from": "<source>", "to": "<target>" },
|
|
56
|
-
{ "type": "set_value", "name": "<name>", "value": <new_value> },
|
|
57
|
-
{ "type": "update_meta", "name": "<name>", "key": "<meta_key>", "value": <new_value> }
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
Rules:
|
|
62
|
-
- Only suggest operations that reference existing nodes (for remove/disconnect/set_value/update_meta) or new nodes you define (for add_node).
|
|
63
|
-
- Keep changes minimal \u2014 prefer the smallest set of operations that solves the problem.
|
|
64
|
-
- Return ONLY valid JSON, no markdown fences or commentary.`;async function Dn(t,e,n,o){let{expand:r,...a}=t.describe({actor:o?.actor,detail:"standard"}),s=[{role:"system",content:_n},{role:"user",content:JSON.stringify({graph:a,problem:e})}],i=n.invoke(s,{model:o?.model,temperature:o?.temperature??0,maxTokens:o?.maxTokens}),c=(await Ie(i)).content.trim();c.startsWith("```")&&(c=c.replace(/^```(?:json)?\s*/,"").replace(/\s*```$/,""));let d;try{d=JSON.parse(c)}catch{throw new Error(`suggestStrategy: LLM response is not valid JSON: ${c.slice(0,200)}`)}let u=d;if(typeof u.summary!="string")throw new Error("suggestStrategy: missing 'summary' in response");if(typeof u.reasoning!="string")throw new Error("suggestStrategy: missing 'reasoning' in response");if(!Array.isArray(u.operations))throw new Error("suggestStrategy: missing 'operations' array in response");return{summary:u.summary,reasoning:u.reasoning,operations:u.operations}}export{Ft as a,Bt as b,Ge as c,dt as d,jt as e,$t as f,Wt as g,je as h,Le as i,We as j,Ut as k,Ke as l,Ve as m,qe as n,ge as o,He as p,en as q,tn as r,sn as s,ln as t,un as u,dn as v,mn as w,fn as x,yn as y,hn as z,bn as A,Tn as B,kn as C,vn as D,Se as E,Mt as F,Ae as G,kt as H,Rn as I,xn as J,vt as K,Rt as L,wn as M,Cn as N,Ee as O,An as P,In as Q,On as R,xt as S,Pn as T,Dn as U,Fn as V};
|
package/dist/chunk-CKCSDI7T.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{a as Ne}from"./chunk-ESMPEKEV.js";import{a as ne,b as we}from"./chunk-VPYBOXVT.js";import{A as ve}from"./chunk-2PMCKKRK.js";import{A as be,C as M,E as te,F as Ce,G as ye,e as De,f as Re,i as U,k as Ge,l as me,m as $e,o as q,p as xe,s as K}from"./chunk-ZB5EHBIO.js";import{b as Q,c as pe,d as fe,e as Z,f as he,g as ge,h as V,i as X,j as ee}from"./chunk-CK2E7BTU.js";function Te(o,e,t,n={}){let s=e in o.nodes,r=t in o.nodes;if(!s)return re(e,t,"no-such-from");if(!r)return re(e,t,"no-such-to");let i=n.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(n.findCycle===!0){let u=He(o,e,n);if(u!=null)return u}let d=se(e,o.nodes[e],0,n);return oe(e,t,[d])}if(i===0)return re(e,t,"no-path");let a=Ae(o,e,t,i);return a.found?oe(e,t,Pe(o,a.pathOrder,n)):re(e,t,a.truncated?"max-depth-exceeded":"no-path")}function Ae(o,e,t,n){let s=new Map,r=[{path:t,depth:0}],i=new Set([t]),a=0,d=!1;for(;a<r.length;){let h=r[a++];if(h.path===e)break;if(n!=null&&h.depth>=n){let g=o.nodes[h.path];g?.deps&&g.deps.length>0&&(d=!0);continue}let f=o.nodes[h.path];if(f==null)continue;let l=f.deps??[],c=new Map;for(let g=0;g<l.length;g++){let y=l[g];if(!y)continue;let O=c.get(y);O==null&&(O=[],c.set(y,O)),O.push(g)}for(let[g,y]of c)i.has(g)||(i.add(g),s.set(g,{from:h.path,depIndices:y}),r.push({path:g,depth:h.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:d};let u=[{path:e}],p=e;for(;p!==t;){let h=s.get(p);if(h==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=h.depIndices,u.push({path:h.from}),p=h.from}return{found:!0,pathOrder:u,truncated:!1}}function He(o,e,t){let n=o.nodes[e];if(n==null)return null;let s=n.deps??[],r=[];for(let a=0;a<s.length;a++)s[a]===e&&r.push(a);if(r.length>0){let a=se(e,n,0,t);a.dep_index=r[0];let d=se(e,n,1,t);return oe(e,e,[a,d])}let i=null;for(let a=0;a<s.length;a++){let d=s[a];if(!d||d===e)continue;let u=Ae(o,d,e,t.maxDepth);u.found&&(i==null||u.pathOrder.length<i.pathOrder.length)&&(i=u,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...u.pathOrder],truncated:!1})}return i==null?null:oe(e,e,Pe(o,i.pathOrder,t))}function Pe(o,e,t){return e.map((n,s)=>{let r=o.nodes[n.path],i=se(n.path,r,s,t);return n.depIndices!=null&&n.depIndices.length>0&&(i.dep_index=n.depIndices[0],n.depIndices.length>1&&(i.dep_indices=[...n.depIndices])),i})}function se(o,e,t,n){let s={path:o,type:e.type,hop:t};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let r=n.annotations?.get(o)??e.annotation;r!=null&&(s.annotation=r);let i=n.lastMutations?.get(o)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function oe(o,e,t){return Me(o,e,!0,"ok",t)}function re(o,e,t){return Me(o,e,!1,t,[])}function Me(o,e,t,n,s){let r=Ue(o,e,t,n,s);return{from:o,to:e,found:t,reason:n,steps:s,text:r,toJSON(){return{from:o,to:e,found:t,reason:n,steps:s}}}}function Ue(o,e,t,n,s){if(!t)switch(n){case"no-such-from":return`explainPath: no node named "${o}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${o}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${o}" to "${e}"`}let r=[`Causal path: ${o} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let d=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(r.push(d),"value"in i&&r.push(` value: ${Je(i.value)}`),i.annotation!=null&&r.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let u=i.lastMutation.actor;r.push(` actor: ${u.type}${u.id?`:${u.id}`:""}`)}}return r.join(`
|
|
2
|
-
`)}function Je(o){if(o===void 0)return"<sentinel>";if(o===null)return"null";if(typeof o=="string")return JSON.stringify(o);if(typeof o=="number"||typeof o=="boolean"||typeof o=="bigint")return String(o);try{let e=JSON.stringify(o);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(o)}}var N={object:56,array:64,string:40,number:8,boolean:4,null:0,undefined:0,symbol:40,bigint:16,function:120,map:72,set:72,mapEntry:40,setEntry:24,date:24,regexp:48,error:64,url:80,promise:48,weakmap:40,weakset:40},Ye=Symbol.for("sizeof");function je(o){let e=new WeakSet,t=new WeakSet,n=[o],s=0;for(;n.length>0;){let r=n.pop();s+=Qe(r,e,t,n)}return s}function Qe(o,e,t,n){if(o==null)return 0;switch(typeof o){case"number":return N.number;case"boolean":return N.boolean;case"string":return N.string+o.length*2;case"bigint":return N.bigint+Ze(o);case"symbol":return N.symbol;case"function":return e.has(o)?0:(e.add(o),N.function);case"undefined":return 0}let r=o;if(e.has(r))return 0;e.add(r);let i=r[Ye];if(typeof i=="function")try{let u=i.call(r);if(typeof u=="number"&&Number.isFinite(u))return u}catch{}if(r instanceof Date)return N.date;if(r instanceof RegExp)return N.regexp+r.source.length*2;if(r instanceof Error){let u=r.message?r.message.length*2:0,p=r.stack?r.stack.length*2:0;return N.error+u+p}if(typeof URL<"u"&&r instanceof URL)return N.url+r.href.length*2;if(typeof Promise<"u"&&r instanceof Promise)return N.promise;if(r instanceof WeakMap)return N.weakmap;if(r instanceof WeakSet)return N.weakset;if(r instanceof Map){let u=N.map;for(let[p,h]of r)u+=N.mapEntry,n.push(p),n.push(h);return u}if(r instanceof Set){let u=N.set;for(let p of r)u+=N.setEntry,n.push(p);return u}if(Array.isArray(r)){let u=N.array+r.length*8;for(let p of r)n.push(p);return u}if(r instanceof ArrayBuffer)return t.has(r)?0:(t.add(r),r.byteLength);if(ArrayBuffer.isView(r)){let u=r;return t.has(u.buffer)?48:(t.add(u.buffer),u.buffer.byteLength+48)}let a=N.object,d=Object.keys(r);for(let u of d){a+=N.string+u.length*2;try{n.push(r[u])}catch{}}return a}function Ze(o){let e=o<0n?-o:o;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}function Ie(o,e){let t=e?.topN??10,n=o.describe({detail:"standard"}),s=[],r=o._collectObserveTargets;typeof r=="function"&&r.call(o,"",s);let i=new Map;for(let[f,l]of s)i.set(f,l);let a=[];for(let[f,l]of Object.entries(n.nodes)){let c=i.get(f),g=c instanceof M?c:null,y=g?je(g.cache):0,O=g?g._sinkCount:0,_=l.deps?.length??0,m=l.type==="effect"&&O===0,b=O===0?l.type==="effect"?"orphan-effect":l.type==="derived"?"idle-derived":l.type==="producer"?"idle-producer":null:null;a.push({path:f,type:l.type,status:l.status??"unknown",valueSizeBytes:y,subscriberCount:O,depCount:_,isOrphanEffect:m,orphanKind:b})}let d=a.reduce((f,l)=>f+l.valueSizeBytes,0),u=(f,l)=>[...a].sort(l??((c,g)=>g[f]-c[f])).slice(0,t),p=a.filter(f=>f.orphanKind!=null),h=a.filter(f=>f.isOrphanEffect);return{nodeCount:a.length,edgeCount:n.edges.length,subgraphCount:n.subgraphs.length,nodes:a,totalValueSizeBytes:d,hotspots:{byValueSize:u("valueSizeBytes"),bySubscriberCount:u("subscriberCount"),byDepCount:u("depCount")},orphans:p,orphanEffects:h}}var J=class{constructor(e){this.capacity=e;if(!Number.isInteger(e)||e<=0)throw new Error(`RingBuffer capacity must be a positive integer (got ${e})`);this.buf=new Array(e)}buf;head=0;_size=0;get size(){return this._size}get maxSize(){return this.capacity}push(e){let t=(this.head+this._size)%this.capacity;this.buf[t]=e,this._size<this.capacity?this._size++:this.head=(this.head+1)%this.capacity}shift(){if(this._size===0)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head=(this.head+1)%this.capacity,this._size--,e}at(e){if(this._size===0)return;let t=e<0?this._size+e:e;if(!(t<0||t>=this._size))return this.buf[(this.head+t)%this.capacity]}toArray(){let e=new Array(this._size);for(let t=0;t<this._size;t++)e[t]=this.buf[(this.head+t)%this.capacity];return e}clear(){for(let e=0;e<this._size;e++)this.buf[(this.head+e)%this.capacity]=void 0;this.head=0,this._size=0}};var x="::",B="__meta__",W=1;function Be(o,e){let t=Math.max(16,o.size*4),n=0;for(;o.size>0;){if(n++>=t){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${t}); ${o.size} disposer(s) discarded`),o.clear();return}let s=o.values().next();if(s.done)return;let r=s.value;o.delete(r);try{r()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function Xe(o){let e=[];for(let t of Object.keys(o).sort()){let n=o[t].v;n!=null&&e.push(`${t} ${n.id} ${n.version}`)}return e.join(`
|
|
3
|
-
`)}function Fe(o){if(o.version!==W)throw new Error(`unsupported snapshot version ${String(o.version)} (expected ${W})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in o))throw new Error(`snapshot missing required key "${e}"`);if(typeof o.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof o.nodes!="object"||o.nodes===null||Array.isArray(o.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(o.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(o.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function et(o,e){let t=new WeakMap,n=(s,r)=>{if(Object.is(s,r))return!0;if(s==null||r==null||typeof s!="object"||typeof r!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(r))return!0;i.add(r);let a=s.constructor,d=r.constructor;if(a!==d)return!1;if(s instanceof Date)return s.getTime()===r.getTime();if(s instanceof RegExp)return s.source===r.source&&s.flags===r.flags;if(Array.isArray(s)){let f=r;if(s.length!==f.length)return!1;for(let l=0;l<s.length;l++)if(!n(s[l],f[l]))return!1;return!0}if(s instanceof Map){let f=r;if(s.size!==f.size)return!1;for(let[l,c]of s)if(!f.has(l)||!n(c,f.get(l)))return!1;return!0}if(s instanceof Set){let f=r;if(s.size!==f.size)return!1;for(let l of s){let c=!1;for(let g of f)if(n(l,g)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(s)){let f=s,l=r;if(f.length!==l.length)return!1;for(let c=0;c<f.length;c++)if(f[c]!==l[c])return!1;return!0}let u=Object.keys(s),p=Object.keys(r);if(u.length!==p.length)return!1;let h=new Set(p);for(let f of u)if(!h.has(f)||!n(s[f],r[f]))return!1;return!0};return n(o,e)}function _e(o){if(o===null||typeof o!="object")return o;if(Array.isArray(o))return o.map(_e);let e=o,t=Object.keys(e).sort(),n={};for(let s of t)n[s]=_e(e[s]);return n}function tt(o){return o.replaceAll("\\","\\\\").replaceAll('"','\\"')}function nt(o){return o.replaceAll("\\","\\\\").replaceAll('"','\\"')}function rt(o){return o==="TD"?"down":o==="BT"?"up":o==="RL"?"left":"right"}function Ve(o){let e=new Set,t=[];function n(s,r){let i=`${s}\0${r}`;e.has(i)||(e.add(i),t.push([s,r]))}for(let[s,r]of Object.entries(o.nodes)){let i=r.deps;if(i)for(let a of i)n(a,s)}for(let s of o.edges)n(s.from,s.to);return t}function qe(o){if(o===void 0)return"LR";if(o==="TD"||o==="LR"||o==="BT"||o==="RL")return o;throw new Error(`invalid diagram direction ${String(o)}; expected one of: TD, LR, BT, RL`)}function st(o,e){let t=e.includeEdges??!0,n=e.includeSubgraphs??!0,{expand:s,...r}=o,i={...r,edges:t?o.edges:[],subgraphs:n?o.subgraphs:[]},a=JSON.stringify(_e(i),null,e.indent??2);return e.logger?.(a),a}function ot(o,e){let t=e.includeEdges??!0,n=e.includeSubgraphs??!0,s=[];s.push(`Graph ${o.name}`),s.push("Nodes:");for(let i of Object.keys(o.nodes).sort()){let a=o.nodes[i];s.push(`- ${i} (${a.type}/${a.status}): ${ae(a.value)}`)}if(t){s.push("Edges:");for(let i of o.edges)s.push(`- ${i.from} -> ${i.to}`)}if(n){s.push("Subgraphs:");for(let i of o.subgraphs)s.push(`- ${i}`)}let r=s.join(`
|
|
4
|
-
`);return e.logger?.(r),r}function Ke(o,e){let t=qe(e.direction),n=Object.keys(o.nodes).sort(),s=new Map;for(let i=0;i<n.length;i+=1)s.set(n[i],`n${i}`);let r=[`flowchart ${t}`];for(let i of n){let a=s.get(i);r.push(` ${a}["${tt(i)}"]`)}for(let[i,a]of Ve(o)){let d=s.get(i),u=s.get(a);!d||!u||r.push(` ${d} --> ${u}`)}return r.join(`
|
|
5
|
-
`)}function it(o,e){let t=Ke(o,e);return at(t)}function at(o,e){let t=e?.theme??"default",n=e?.autoSync??!0,r=JSON.stringify({code:o,mermaid:{theme:t},autoSync:n}),i=new TextEncoder().encode(r),a="";for(let u=0;u<i.length;u++)a+=String.fromCharCode(i[u]);return`https://mermaid.live/edit#base64:${globalThis.btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}`}function ut(o,e){let t=qe(e.direction),n=Object.keys(o.nodes).sort(),s=new Map;for(let i=0;i<n.length;i+=1)s.set(n[i],`n${i}`);let r=[`direction: ${rt(t)}`];for(let i of n){let a=s.get(i);r.push(`${a}: "${nt(i)}"`)}for(let[i,a]of Ve(o)){let d=s.get(i),u=s.get(a);!d||!u||r.push(`${d} -> ${u}`)}return r.join(`
|
|
6
|
-
`)}function ct(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ie(o){let e="^";for(let t=0;t<o.length;t+=1){let n=o[t];if(n==="*"){e+=".*";continue}if(n==="?"){e+=".";continue}if(n==="["){let s=o.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let r=o.slice(t+1,s);r.startsWith("!")&&(r=`^${r.slice(1)}`),r=r.replace(/\\/g,"\\\\"),e+=`[${r}]`,t=s;continue}e+=ct(n)}return e+="$",new RegExp(e)}var dt={data:"\x1B[32m",dirty:"\x1B[33m",resolved:"\x1B[36m",invalidate:"\x1B[93m",pause:"\x1B[90m",resume:"\x1B[96m",complete:"\x1B[34m",error:"\x1B[31m",teardown:"\x1B[91m",derived:"\x1B[35m",path:"\x1B[90m",reset:"\x1B[0m"},lt={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function ae(o){if(typeof o=="string")return JSON.stringify(o);if(typeof o=="number"||typeof o=="boolean"||o==null)return String(o);try{return JSON.stringify(o)}catch{return"[unserializable]"}}function pt(o){return o==="none"?lt:o==="ansi"||o==null?dt:{data:o.data??"",dirty:o.dirty??"",resolved:o.resolved??"",invalidate:o.invalidate??"",pause:o.pause??"",resume:o.resume??"",complete:o.complete??"",error:o.error??"",teardown:o.teardown??"",derived:o.derived??"",path:o.path??"",reset:o.reset??""}}function ze(o){if(o==null)return{};let e=o.detail;return e==="full"?{...o,structured:o.structured??!0,timeline:o.timeline??!0,causal:o.causal??!0,derived:o.derived??!0}:e==="minimal"?{...o,structured:o.structured??!0}:o.format==="stage-log"?{...o,structured:o.structured??!0,timeline:o.timeline??!0}:o}function ft(o,e,t){for(let n=0;n<o.length;n++){let s=o.charCodeAt(n);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${o}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function Oe(o,e,t){if(o==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(o.includes(x))throw new Error(`Graph "${e}": ${t} "${o}" must not contain '${x}' (path separator)`);if(o===B)throw new Error(`Graph "${e}": ${t} name "${B}" is reserved for meta companion paths`);ft(o,e,t)}function ht(o,e){if(o==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=o.split(x);for(let n of t)if(n==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function gt(o,e){let t=!1;for(let s of o)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?o.filter(s=>e.isMetaPassthrough(s[0])):o}function We(o){for(let e of o._mounts.values())We(e);for(let e of o._nodes.values())try{e.down([[V]],{internal:!0})}catch{}}var Ee=class o{name;opts;config;_nodes=new Map;_nodeToName=new WeakMap;_mounts=new Map;_parent=void 0;_storageDisposers=new Set;_disposers=new Set;_topology;_topologyEmitters=new Set;constructor(e,t){if(e==="")throw new Error("Graph name must be non-empty");if(e.includes(x))throw new Error(`Graph name must not contain '${x}' (got "${e}")`);if(e===B)throw new Error(`Graph name "${B}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??be,this._traceRing=new J(t?.traceCapacity??1e3),t?.versioning!=null&&this.setVersioning(t.versioning)}ancestors(e=!0){let t=[],n=e?this:this._parent;for(;n!=null;)t.push(n),n=n._parent;return t}get topology(){return this._topology==null&&(this._topology=Ce(e=>{let t=n=>{e.emit(n)};return this._topologyEmitters.add(t),()=>{this._topologyEmitters.delete(t)}},{name:`${this.name}_topology`})),this._topology}_emitTopology(e){if(!(this._topology==null||this._topologyEmitters.size===0))for(let t of this._topologyEmitters)t(e)}add(e,t){let n=e.name,s=t?.name??n;if(s==null||s==="")throw new Error(`Graph "${this.name}": graph.add requires a non-empty name \u2014 pass via opts.name or set it on the node (e.g. state(0, { name: "x" }))`);let r=s,i=t?.annotation;if(Oe(r,this.name,"add"),this._mounts.has(r))throw new Error(`Graph "${this.name}": name "${r}" is already a mount point`);if(this._nodes.has(r))throw new Error(`Graph "${this.name}": node "${r}" already exists`);let a=this._nodeToName.get(e);if(a!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${a}"`);return this._nodes.set(r,e),this._nodeToName.set(e,r),this._emitTopology({kind:"added",name:r,nodeKind:"node"}),i!=null&&(this._annotations.set(r,i),this.config.inspectorEnabled&&this._traceRing.push({path:r,annotation:i,timestamp_ns:q()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof M&&t._applyVersioning(e)}remove(e){Oe(e,this.name,"remove");let t=this._mounts.get(e);if(t){let r={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,d]of i)a.includes(`${x}${B}${x}`)||r.nodes.push(a);return r.nodes.sort(),r.mounts.push(e),r.mounts.push(...t._collectSubgraphs(`${e}${x}`)),this._mounts.delete(e),t._parent=void 0,We(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:r}),r}let n=this._nodes.get(e);if(!n)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(n),n.down([[V]],{internal:!0});let s={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:s}),s}removeAll(e){let t=typeof e=="function"?e:(()=>{let r=ie(e);return i=>r.test(i)})(),n={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(r=>t(r));for(let r of s){let i=this.remove(r);n.nodes.push(...i.nodes),n.mounts.push(...i.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=e.length)return{value:void 0,done:!0};let s=e[n++];return{value:[s,t.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(x))return this.resolve(e);let t=this._nodes.get(e);if(!t)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return t}get(e){return this.node(e).cache}set(e,t,n){let s=n?.internal===!0;this.node(e).down([[Q,t]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);$e(()=>{for(let[s,r]of n)this.set(s,r,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[Z]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let s=n?.internal===!0;this.node(e).down([[ee,t]],{actor:n?.actor,internal:s,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[X]],{actor:t?.actor,internal:n,delivery:"write"})}edges(e){let t=e?.recursive===!0,n=new Map;if(!t){for(let[d,u]of this._nodes)n.set(u,d);let a=[];for(let[d,u]of this._nodes)if(u instanceof M)for(let p of u._deps){let h=n.get(p.node);h!=null&&a.push([h,d])}return a.sort((d,u)=>d[0]<u[0]?-1:d[0]>u[0]?1:d[1]<u[1]?-1:d[1]>u[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let r=new Map;for(let[a,d]of s)r.set(d,a);let i=[];for(let[a,d]of s)if(d instanceof M)for(let u of d._deps){let p=r.get(u.node);p!=null&&i.push([p,a])}return i.sort((a,d)=>a[0]<d[0]?-1:a[0]>d[0]?1:a[1]<d[1]?-1:a[1]>d[1]?1:0),i}mount(e,t){if(Oe(e,this.name,"mount"),this._nodes.has(e))throw new Error(`Graph "${this.name}": cannot mount at "${e}" \u2014 node with that name exists`);if(this._mounts.has(e))throw new Error(`Graph "${this.name}": mount "${e}" already exists`);if(t===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(t._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${t._parent.name}"`);for(let n=this;n!=null;n=n._parent)if(n===t)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,t),t._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),t}resolve(e){let t=ht(e,this.name);return this._resolveFromSegments(t)}tryResolve(e){try{return this.resolve(e)}catch{return}}_resolveFromSegments(e){let t=e;if(t[0]===this.name&&(t=t.slice(1),t.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let n=t[0],s=t.slice(1);if(s.length===0){let a=this._nodes.get(n);if(a)return a;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let r=this._nodes.get(n);if(r&&s.length>0&&s[0]===B)return this._resolveMetaChainFromNode(r,s,t.join(x));let i=this._mounts.get(n);if(!i)throw this._nodes.has(n)?new Error(`Graph "${this.name}": "${n}" is a node; trailing path "${s.join(x)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return i.resolve(s.join(x))}_resolveMetaChainFromNode(e,t,n){let s=e,r=0,i=[...t];for(;r<i.length;){if(i[r]!==B)throw new Error(`Graph "${this.name}": expected ${B} segment in meta path "${n}"`);if(r+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${B} in "${n}"`);let a=i[r+1],d=s.meta[a];if(!d)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${n}"`);s=d,r+=2}return s}signal(e,t){if(t?.internal!==!0){for(let s of e)if(this.config.messageTier(s[0])===3)throw new Error(`Graph "${this.name}": Graph.signal() rejects tier-3 messages (DATA / RESOLVED). Broadcast is for control-plane tiers (START / DIRTY / INVALIDATE / PAUSE / RESUME / COMPLETE / ERROR / TEARDOWN). For per-node value writes, use Graph.set or graph.node(name).down(...).`)}let n=[];if(this._signalDeliver(e,t??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(e,t,n,s){for(let d of this._mounts.values())d._signalDeliver(e,t,n,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=gt(e,this.config);for(let d of[...this._nodes.keys()].sort()){let u=this._nodes.get(d);if(!n.has(u)){n.add(u);try{u.down(e,i)}catch(p){if(p instanceof K)throw p;s.push(p)}a.length!==0&&this._signalMetaSubtree(u,a,n,i,s)}}}_signalMetaSubtree(e,t,n,s,r){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!n.has(a)){n.add(a);try{a.down(t,s)}catch(d){if(d instanceof K)throw d;r.push(d)}this._signalMetaSubtree(a,t,n,s,r)}}}describe(e){if(e?.reactive===!0)return this._describeReactive(e);let t=e?.actor,n=e?.filter,s=ne(e?.detail,e?.fields),r=e?.format==="spec",i=r?ne("minimal"):s,a=[];this._collectObserveTargets("",a);let d=new Map;for(let[v,E]of a)d.set(E,v);let u=[];{let v=a.map(([,R])=>R),E=new Set(d.values()),k=0;for(;v.length>0;){let R=v.shift();if(R instanceof M)for(let A of R._deps){let T=A.node;if(d.has(T))continue;let C=T.name??"",G=C;if(!G||E.has(G))if(C){let F=2;for(;E.has(`${C}#${F}`);)F++;G=`${C}#${F}`}else for(G=`__internal__/${k++}`;E.has(G);)G=`__internal__/${k++}`;d.set(T,G),E.add(G),u.push([G,T]),v.push(T)}}}let p=[...a,...u],h={};for(let[v,E]of p){if(t!=null&&!E.allowsObserve(t))continue;let k=we(E,i),R=E instanceof M?E._deps.map(G=>d.get(G.node)??G.node.name??""):[],{name:A,...T}=k,C={...T,deps:R};if(!r){let G=this._annotations.get(v);G!=null&&(C.annotation=G)}if(n!=null)if(typeof n=="function"){let G=n;if(!(G.length>=2?G(v,C):G(C)))continue}else{let G=!0;for(let[F,z]of Object.entries(n)){let L=F==="deps_includes"?"depsIncludes":F==="meta_has"?"metaHas":F;if(L==="depsIncludes"){if(!C.deps.includes(String(z))){G=!1;break}continue}if(L==="metaHas"){if(!Object.hasOwn(C.meta??{},String(z))){G=!1;break}continue}if(C[L]!==z){G=!1;break}}if(!G)continue}h[v]=C}let f=new Set(Object.keys(h)),l=[];for(let[v,E]of p)if(E instanceof M)for(let k of E._deps){let R=d.get(k.node);R!=null&&l.push([R,v])}l.sort((v,E)=>v[0]<E[0]?-1:v[0]>E[0]?1:v[1]<E[1]?-1:v[1]>E[1]?1:0);let c=l.map(([v,E])=>({from:v,to:E}));(t!=null||n!=null)&&(c=c.filter(v=>f.has(v.from)&&f.has(v.to)));let g=this._collectSubgraphs(""),y=t!=null||n!=null?g.filter(v=>{let E=`${v}${x}`;return[...f].some(k=>k===v||k.startsWith(E))}):g,O=this,_=e,m={name:this.name,nodes:h,edges:c,subgraphs:y,expand(v){let E={..._,format:void 0};return Array.isArray(v)?(E.fields=v,E.detail=void 0):(E.detail=v,E.fields=void 0),O.describe(E)}},b=e??{},S=b.format;return S==="json"?st(m,b):S==="pretty"?ot(m,b):S==="mermaid"?Ke(m,b):S==="mermaid-url"?it(m,b):S==="d2"?ut(m,b):m}_collectSubgraphs(e){let t=[];for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${n}`;t.push(s),t.push(...this._mounts.get(n)._collectSubgraphs(`${s}${x}`))}return t}resourceProfile(e){return Ie(this,e)}reachable(e,t,n={}){return n.withDetail===!0?Le(this.describe(),e,t,{...n,withDetail:!0}):Le(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(e,t,n)}_explainStatic(e,t,n){let s=this.describe({detail:"full"}),r=new Map(this._annotations),i=new Map;for(let[a,d]of Object.entries(s.nodes))d.lastMutation!=null&&i.set(a,d.lastMutation);return Te(s,e,t,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:r,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},n=e.reactiveName??"describe",s=0,r=te(s,{name:`${n}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=()=>{a||d||(a=!0,me(()=>{a=!1,!d&&(s+=1,r.emit(s))}))},p=i.onEvent(y=>{let O=y.type;O!=="data"&&O!=="error"&&O!=="complete"&&O!=="teardown"||u()}),h=[],f=new WeakSet,l=y=>{if(f.has(y)||d)return;f.add(y);let O=y.topology.subscribe(_=>{for(let m of _){if(m[0]!==Q)continue;let b=m[1];if(u(),b.kind==="added"&&b.nodeKind==="mount"){let S=y._mounts.get(b.name);S!=null&&l(S)}}});h.push(O);for(let _ of y._mounts.keys()){let m=y._mounts.get(_);m!=null&&l(m)}};l(this);let c;try{c=ye([r],()=>this.describe(t),{name:n,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(y,O)=>y===O})}catch(y){p();for(let O of h)O();throw i.dispose(),y}let g=ve(c);return{node:c,dispose(){d=!0,p();for(let y of h)y();h.length=0,i.dispose(),g()}}}_explainReactive(e,t,n){let s=0,r=te(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=i.onEvent(l=>{let c=l.type;c!=="data"&&c!=="error"&&c!=="complete"&&c!=="teardown"||a||d||(a=!0,me(()=>{a=!1,!d&&(s+=1,r.emit(s))}))}),p={...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{}},h;try{h=ye([r],()=>this._explainStatic(e,t,p),{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:e,to:t},equals:(l,c)=>l.found===c.found&&l.reason===c.reason&&l.steps.length===c.steps.length&&bt(l.steps,c.steps)})}catch(l){throw u(),i.dispose(),l}let f=ve(h);return{node:h,dispose(){d=!0,u(),i.dispose(),f()}}}_pathsMatching(e){let t=ie(e),n=[];return this._collectObserveTargets("",n),n.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${x}${n}`;this._mounts.get(n)._collectObserveTargets(s,t)}for(let n of[...this._nodes.keys()].sort()){let s=this._nodes.get(n),r=e===""?n:`${e}${x}${n}`;t.push([r,s]),this._appendMetaObserveTargets(r,s,t)}}_appendMetaObserveTargets(e,t,n){for(let s of Object.keys(t.meta).sort()){let r=t.meta[s],i=`${e}${x}${B}${x}${s}`;n.push([i,r]),this._appendMetaObserveTargets(i,r,n)}}observe(e,t){let n=typeof e=="string",r=ze(n?t:e),i=r.structured===!0||r.timeline===!0||r.causal===!0||r.derived===!0||r.detail==="minimal"||r.detail==="full"||r.format!=null,a=r.actor;if(n){let p=e,h=this.resolve(p);if(a!=null&&!h.allowsObserve(a))throw new K({actor:a,action:"observe",nodeName:p});return i?this._buildStructuredObserver([[p,h]],r,"one"):{subscribe(f){return h.subscribe(f)},up(f){try{h.up?.(f)}catch(l){if(l instanceof K)return;throw l}}}}let d=[];this._collectObserveTargets("",d),d.sort((p,h)=>p[0]<h[0]?-1:p[0]>h[0]?1:0);let u=a==null?d:d.filter(([,p])=>p.allowsObserve(a));return i?this._buildStructuredObserver(u,r,"all"):{subscribe:p=>{let h=u.map(([f,l])=>l.subscribe(c=>{p(f,c)}));return()=>{for(let f of h)f()}},up:(p,h)=>{try{this.resolve(p).up?.(h)}catch(f){if(f instanceof K)return;throw f}}}}_buildStructuredObserver(e,t,n){let s=n==="one"?e[0]?.[0]:void 0,r=i=>{if(n==="one"&&s!=null){let p=this.resolve(s);return this._buildStructuredObserver([[s,p]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((p,h)=>p[0]<h[0]?-1:p[0]>h[0]?1:0);let d=i.actor,u=d==null?a:a.filter(([,p])=>p.allowsObserve(d));return this._buildStructuredObserver(u,i,"all")};return this._createObserveResult(e,t,r)}_createObserveResult(e,t,n){let s=t.timeline===!0,r=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",d=this.config.inspectorEnabled,u=(r||i)&&d,p=t.maxEvents,h=p!=null&&p>0?new J(p):null,f=[],l=new Set,c={},g=new Set,y=0,O=0,_=0,m=0,b=0,S=0,v=!1,E=!1,k=0,R=new Map,A=new Map,T=new Map,C=w=>{h?h.push(w):f.push(w);for(let $ of l)$(w)},G=()=>s?{timestamp_ns:q(),in_batch:Ge(),batch_id:k}:{},F=(w,$)=>{if(!(!u||!(w instanceof M)))return w._setInspectorHook(j=>{if(j.kind==="dep_message")R.set(w,j.depIndex);else if(j.kind==="run"){let H=j.batchData.map((D,P)=>D!=null&&D.length>0?D.at(-1):j.prevData[P]);A.set(w,H);let I=j.batchData.map(D=>D!=null?[...D]:void 0);T.set(w,I),i&&C({type:"derived",path:$,dep_values:H,dep_batches:I,...G()})}})},z=w=>{let $=R.get(w),j=A.get(w);if(!r||j==null)return{};let I=($!=null&&$>=0&&w instanceof M?w._deps[$]:void 0)?.node,D=I?.v,P=T.get(w);return{trigger_dep_index:$,trigger_dep_name:I?.name,...D!=null?{trigger_version:{id:D.id,version:D.version}}:{},dep_values:[...j],...P!=null?{dep_batches:P}:{}}},L=[],Se=[];for(let[w,$]of e){let j=F($,w);j&&L.push(j),Se.push($.subscribe(H=>{k++;for(let I of H){let D=I[0],P=G();if(D===Q){c[w]=I[1];let le=$ instanceof M?$.lastMutation?.actor??U:U;C({type:"data",path:w,data:I[1],actor:le,...P,...z($)})}else if(a)D===pe?y++:D===fe?O++:D===Z?_++:D===he?m++:D===ge?b++:D===V?S++:D===X&&!g.has(w)?v=!0:D===ee&&(E=!0,g.add(w));else if(D===pe)y++,C({type:"dirty",path:w,...P});else if(D===fe)O++,C({type:"resolved",path:w,...P,...z($)});else if(D===Z)_++,C({type:"invalidate",path:w,...P});else if(D===he)m++,C({type:"pause",path:w,lockId:I[1],...P});else if(D===ge)b++,C({type:"resume",path:w,lockId:I[1],...P});else if(D===X)g.has(w)||(v=!0),C({type:"complete",path:w,...P});else if(D===ee){E=!0,g.add(w);let le=$ instanceof M?$.lastMutation?.actor??U:U;C({type:"error",path:w,data:I[1],actor:le,...P})}else D===V&&(S++,C({type:"teardown",path:w,...P}))}}))}let ue=!1,ce=()=>{if(!ue){ue=!0;for(let w of Se)w();for(let w of L)w();for(let w of Y)w({value:void 0,done:!0});Y.length=0}},de=[],Y=[];l.add(w=>{let $=Y.shift();$?$({value:w,done:!1}):de.push(w)});let ke={get values(){return c},get dirtyCount(){return y},get resolvedCount(){return O},get invalidateCount(){return _},get pauseCount(){return m},get resumeCount(){return b},get teardownCount(){return S},get events(){return h?h.toArray():[...f]},get anyCompletedCleanly(){return v},get anyErrored(){return E},get completedWithoutErrors(){return v&&!E},onEvent(w){return l.add(w),()=>l.delete(w)},dispose:ce,expand(w){ce();let $={...t};return typeof w=="string"?$.detail=w:Object.assign($,w),n(ze($))},[Symbol.asyncIterator](){return{next(){return de.length>0?Promise.resolve({value:de.shift(),done:!1}):ue?Promise.resolve({value:void 0,done:!0}):new Promise(w=>Y.push(w))},return(){return ce(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(ke,t),ke}_attachFormatLogger(e,t){let n=t.format;if(n==null)return;let s=t.logger??(c=>console.log(c)),r=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=r==null&&i==null?()=>!0:c=>(r==null||r.has(c))&&(i==null||!i.has(c)),d=pt(t.theme),u=n==="stage-log"?q():0,p=c=>c==null?"":t.stageLabels?.[c]??c,h=(c,g)=>c.length>g?`${c.slice(0,g-1)}\u2026`:c,f=c=>c.type==="data"||c.type==="error"?h(ae(c.data),120):"",l=c=>{if(n==="stage-log"){let E=(q()-u)/1e9,k=p(c.path).padEnd(9);if(c.type==="data"){let R=f(c);return`[${E.toFixed(3)}s] ${k} \u2190${R?` ${R}`:""}`}if(c.type==="error"){let R=f(c);return`[${E.toFixed(3)}s] ${k} \u2717${R?` ${R}`:""}`}return c.type==="complete"?`[${E.toFixed(3)}s] ${k} \u25A0 complete`:`[${E.toFixed(3)}s] ${k} ${c.type}`}if(n==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let g=d[c.type]??"",y=c.path?`${d.path}${c.path}${d.reset} `:"",O=c.type==="data"||c.type==="error",_=c.type==="pause"||c.type==="resume",m=O?` ${ae(c.data)}`:_?` ${ae(c.lockId)}`:"",b=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,S=b?.trigger_dep_name!=null?` <- ${b.trigger_dep_name}`:b?.trigger_dep_index!=null?` <- #${b.trigger_dep_index}`:"",v=c.in_batch?" [batch]":"";return`${y}${g}${c.type.toUpperCase()}${d.reset}${m}${S}${v}`};e.onEvent(c=>{a(c.type)&&s(l(c),c)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){Be(this._disposers,this.name),this.signal([[V]],{internal:!0}),Be(this._storageDisposers,this.name);for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0}_destroyClearOnly(){for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0}snapshot(e){let{expand:t,...n}=this.describe({detail:"full"}),s={};for(let a of Object.keys(n.nodes).sort()){let{lastMutation:d,guard:u,...p}=n.nodes[a];s[a]=p}let r=[...n.subgraphs].sort(),i={...n,version:1,nodes:s,subgraphs:r};if(e?.format==null)return i;if(e.format==="json-string")return JSON.stringify(i);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let a=this.config.lookupCodec(e.codec);if(a==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return De(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??be,{codec:s,codecVersion:r,payload:i}=Re(e,n);return s.decode(i,r)}restore(e,t){if(Fe(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let n=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(r=>ie(r)),s=t?.includeProducers===!0;for(let r of Object.keys(e.nodes).sort()){if(n!==null&&!n.some(a=>a.test(r)))continue;let i=e.nodes[r];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(r,new Error(`restore: slice.value is undefined for "${r}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!s)){if(i.v!=null){let d=this.tryResolve(r)?.v;if(d!=null&&d.id===i.v.id&&d.version===i.v.version)continue}try{this.set(r,i.value)}catch(a){t?.onError?.(r,a)}}}}}static fromSnapshot(e,t){Fe(e);let n=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,r=new o(e.name);if(n)return n(r),r.restore(e),r;for(let l of[...e.subgraphs].sort((c,g)=>{let y=c.split(x).length,O=g.split(x).length;return y!==O?y-O:c<g?-1:c>g?1:0})){let c=l.split(x),g=r;for(let y of c)g._mounts.has(y)||g.mount(y,new o(y)),g=g._mounts.get(y)}let i=s?Object.entries(s).map(([l,c])=>({re:ie(l),factory:c})):[],a=l=>{for(let c of i)if(c.re.test(l))return c.factory},d=l=>{let c=l.split(x),g=c.pop();if(g==null||g.length===0)throw new Error(`invalid snapshot path "${l}"`);let y=r;for(let O of c){let _=y._mounts.get(O);if(!_)throw new Error(`unknown mount "${O}" in path "${l}"`);y=_}return[y,g]},u=Object.entries(e.nodes).filter(([l])=>!l.includes(`${x}${B}${x}`)).sort((l,c)=>l[0]<c[0]?-1:l[0]>c[0]?1:0),p=new Map(u),h=new Map,f=!0;for(;p.size>0&&f;){f=!1;for(let[l,c]of[...p.entries()]){let g=c?.deps??[];if(!g.every(S=>h.has(S)))continue;let[y,O]=d(l),_={...c?.meta??{}},m=a(l),b;if(c?.type==="state")b=te(c.value,{meta:_});else{if(m==null)continue;b=m(O,{path:l,type:c.type,value:c.value,meta:_,deps:g,resolvedDeps:g.map(S=>h.get(S))})}y.add(b,{name:O}),h.set(l,b),p.delete(l),f=!0}}if(p.size>0){let l=[...p.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${l}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return r.restore(e),r}toJSON(){return this.snapshot()}attachStorage(e,t={}){let n=e.map(u=>({tier:u,debounceMs:Math.max(0,u.debounceMs??0),compactEvery:Math.max(1,u.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));t.autoRestore===!0&&this._cascadeRestore(e,t.onError);let s=(u,p)=>{if(u.disposed)return;let h=Xe(p.nodes);if(u.lastSnapshot!=null&&h!==""&&h===u.lastFingerprint)return;let f=u.seq+1,l=xe(),y=u.lastSnapshot==null||f%u.compactEvery===0?{mode:"full",snapshot:p,seq:f,timestamp_ns:l,format_version:W}:{mode:"diff",diff:mt(u.lastSnapshot,p),seq:f,timestamp_ns:l,format_version:W};if(u.tier.filter&&!u.tier.filter(this.name,y))return;let O;try{O=u.tier.save(this.name,y)}catch(_){t.onError?.(_,u.tier);return}if(O&&typeof O.then=="function"){let b=(u.savePending??Promise.resolve()).then(()=>O,()=>O).then(()=>{u.disposed||(u.seq=f,u.lastSnapshot=p,u.lastFingerprint=h)},S=>{t.onError?.(S,u.tier)});u.savePending=b.finally(()=>{u.savePending===b&&(u.savePending=void 0)})}else u.seq=f,u.lastSnapshot=p,u.lastFingerprint=h},r=(u,p)=>{try{s(u,p)}catch(h){t.onError?.(h,u.tier)}},i=(u,p)=>{if(!p.some(c=>{let g=this.config.messageTier(c[0]);return g>=3&&g<5}))return;if(t.filter){let c=this.tryResolve(u);if(c==null)return;let g=we(c,ne("standard"));if(!t.filter(u,g))return}let f,l=()=>(f==null&&(f=this.snapshot()),f);for(let c of n)c.disposed||(c.debounceMs===0?r(c,l()):(c.timer==null&&(c.timer=new Ne),c.timer.start(c.debounceMs,()=>{c.disposed||r(c,this.snapshot())})))},a;if(t.paths!=null){let p=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(h=>{let f=this.tryResolve(h);return f==null?()=>{}:f.subscribe(l=>i(h,l))});a=()=>{for(let h of p)h()}}else a=this.observe().subscribe((u,p)=>i(u,p));let d=()=>{a();for(let u of n)u.disposed=!0,u.timer?.cancel();this._storageDisposers.delete(d)};return this._storageDisposers.add(d),{dispose:d}}async _cascadeRestore(e,t){for(let n of e){let s;try{s=await n.load(this.name)}catch(i){t?.(i,n);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let r=s;try{if(r.mode==="full"&&r.snapshot!=null)return this.restore(r.snapshot),!0;if(r.version===W&&r.nodes!=null)return this.restore(r),!0}catch(i){t?.(i,n)}}return!1}static async fromStorage(e,t,n){for(let s of t){let r;try{r=await s.load(e)}catch(d){n?.onError?.(d,s);continue}if(r==null||typeof r!="object"||Array.isArray(r))continue;let i=r,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===W&&i.nodes!=null?i:void 0;if(a!=null)try{return o.fromSnapshot(a,n)}catch(d){n?.onError?.(d,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${t.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,t,n){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let s={path:e,annotation:t,timestamp_ns:q(),...n?.actor!=null?{actor:n.actor}:{}};this._traceRing.push(s)}return}return e!=null?this.config.inspectorEnabled?this._annotations.get(e):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(e){return this._annotations.get(e)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(e){let t=this._traceRing.toArray().filter(s=>!e(s)),n=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return n}static diff(e,t){let n=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),r=[...s].filter(_=>!n.has(_)).sort(),i=[...n].filter(_=>!s.has(_)).sort(),a=[],d=[];for(let _ of n){if(!s.has(_))continue;let m=e.nodes[_],b=t.nodes[_],S=m.v,v=b.v;S!=null&&v!=null&&S.id===v.id&&S.version!==v.version&&d.push({path:_,id:S.id,from:S.version,to:v.version});let E=S!=null&&v!=null&&S.id===v.id&&S.version===v.version;for(let k of["type","status","sentinel"]){let R=m[k],A=b[k];R!==A&&a.push({path:_,field:k,from:R,to:A})}if(!E)for(let k of["value","meta"]){let R=m[k],A=b[k];et(R,A)||a.push({path:_,field:k,from:R,to:A})}}let u=_=>`${_.from} ${_.to}`,p=new Set(e.edges.map(u)),h=new Set(t.edges.map(u)),f=t.edges.filter(_=>!p.has(u(_))),l=e.edges.filter(_=>!h.has(u(_))),c=new Set(e.subgraphs),g=new Set(t.subgraphs),y=[...g].filter(_=>!c.has(_)).sort(),O=[...c].filter(_=>!g.has(_)).sort();return{nodesAdded:r,nodesRemoved:i,nodesChanged:a,versionChanges:d,edgesAdded:f,edgesRemoved:l,subgraphsAdded:y,subgraphsRemoved:O}}};function mt(o,e){let t=Ee.diff(o,e),n={};for(let s of t.nodesAdded){let r=e.nodes[s];r!=null&&(n[s]=r)}return{...t,nodesAddedFull:n}}function Le(o,e,t,n={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return n.withDetail?s:[];if(!n.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let r=n.maxDepth;if(r!=null&&(!Number.isInteger(r)||r<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(r===0)return n.withDetail?s:[];let i=new Map,a=new Map,d=new Map,u=new Map,p=new Set;for(let[m,b]of Object.entries(o.nodes)){if(!m)continue;p.add(m);let S=b.deps??[];i.set(m,S);for(let v of S)v&&(p.add(v),a.has(v)||a.set(v,new Set),a.get(v).add(m))}for(let m of o.edges){if(m==null||typeof m!="object")continue;let b=typeof m.from=="string"?m.from:"",S=typeof m.to=="string"?m.to:"";!b||!S||(p.add(b),p.add(S),u.has(b)||u.set(b,new Set),u.get(b).add(S),d.has(S)||d.set(S,new Set),d.get(S).add(b))}if(!p.has(e))return n.withDetail?s:[];let h=n.both===!0,f=m=>{if(h){let E=i.get(m)??[],k=d.get(m),R=a.get(m),A=u.get(m),T=[...E];return k&&T.push(...k),R&&T.push(...R),A&&T.push(...A),T}if(t==="upstream"){let E=i.get(m)??[],k=d.get(m);return k?[...E,...k]:E}let b=a.get(m),S=u.get(m),v=b?[...b]:[];return S&&v.push(...S),v},l=new Set([e]),c=new Map,g=[{path:e,depth:0}],y=0,O=!1;for(;y<g.length;){let m=g[y++];if(r!=null&&m.depth>=r){f(m.path).length>0&&(O=!0);continue}for(let b of f(m.path))!b||l.has(b)||(l.add(b),c.set(b,m.depth+1),g.push({path:b,depth:m.depth+1}))}let _=[...c.keys()].sort((m,b)=>m<b?-1:m>b?1:0);return n.withDetail?{paths:_,depths:c,truncated:O}:_}function bt(o,e){if(o.length!==e.length)return!1;for(let t=0;t<o.length;t++){let n=o[t],s=e[t];if(n.path!==s.path||n.type!==s.type||n.status!==s.status||n.hop!==s.hop||n.dep_index!==s.dep_index||n.annotation!==s.annotation||n.value!==s.value||n.lastMutation!==s.lastMutation)return!1;let r=n.v,i=s.v;if(r!==i&&(r==null||i==null||r.id!==i.id||r.version!==i.version))return!1}return!0}export{J as a,Te as b,N as c,Ye as d,je as e,Ie as f,B as g,W as h,at as i,Ee as j,mt as k,Le as l};
|
package/dist/chunk-QWAPKG3O.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as G}from"./chunk-ETWTCCJI.js";import{j as z}from"./chunk-CKCSDI7T.js";import{D as H,E as M,G as N,o as R}from"./chunk-ZB5EHBIO.js";function q(t){for(let c of t){let m=c.codePointAt(0);if(m>=19968&&m<=40959||m>=13312&&m<=19903||m>=12288&&m<=12351||m>=12352&&m<=12447||m>=12448&&m<=12543||m>=44032&&m<=55215||m>=65280&&m<=65519)return!0}return!1}var E=new Set(["\uFF0C","\uFF0E","\uFF01","\uFF1A","\uFF1B","\uFF1F","\u3001","\u3002","\u30FB","\uFF09","\u3015","\u3009","\u300B","\u300D","\u300F","\u3011"]),F=new Set([".",",","!","?",":",";",")","]","}","%",'"',"\u201D","\u2019","\xBB","\u203A","\u2026"]);function D(t){return t.replace(/[\t\n\r\f ]+/g," ").replace(/^ | $/g,"")}function O(t){let c=new Intl.Segmenter(void 0,{granularity:"word"}),m=[];for(let f of c.segment(t)){let h=f.segment,w=f.isWordLike??!1,u=[],s=[],r=[],p="",n=null;for(let i of h){let S;i===" "?S="space":i==="\u200B"?S="zero-width-break":i==="\xAD"?S="soft-hyphen":i===`
|
|
2
|
-
`?S="hard-break":S="text",n!==null&&S===n?p+=i:(n!==null&&(u.push(p),s.push(n==="text"&&w),r.push(n)),p=i,n=S)}n!==null&&(u.push(p),s.push(n==="text"&&w),r.push(n)),m.push({texts:u,isWordLike:s,kinds:r})}return m}function V(t,c,m,f,h){let w=D(t);if(w.length===0)return[];let u=O(w),s=new Intl.Segmenter(void 0,{granularity:"grapheme"}),r=[],p=[],n=[];for(let g of u)for(let o=0;o<g.texts.length;o++)r.push(g.texts[o]),p.push(g.kinds[o]),n.push(g.isWordLike[o]);let i=[],S=[],B=[];for(let g=0;g<r.length;g++){let o=r[g],y=p[g],I=n[g];if(y==="text"&&!I&&i.length>0&&S[S.length-1]==="text"&&o.length===1&&(F.has(o)||E.has(o))){i[i.length-1]+=o;continue}if(o==="-"&&i.length>0&&S[S.length-1]==="text"&&B[B.length-1]){i[i.length-1]+=o;continue}i.push(o),S.push(y),B.push(I)}let l=f.get(c);l||(l=new Map,f.set(c,l));function b(g){let o=l.get(g);if(o===void 0){h&&(h.misses+=1);let y=m.measureSegment(g,c).width;o=Number.isFinite(y)&&y>=0?y:0,l.set(g,o)}else h&&(h.hits+=1);return o}let d=[];for(let g=0;g<i.length;g++){let o=i[g],y=S[g];if(y!=="text"){d.push({text:o,width:y==="space"?b(" ")*o.length:0,kind:y,graphemeWidths:null});continue}if(q(o)){let a="";for(let x of s.segment(o)){let k=x.segment;if(a.length>0&&E.has(k)){a+=k;continue}if(a.length>0){let L=b(a);d.push({text:a,width:L,kind:"text",graphemeWidths:null})}a=k}if(a.length>0){let x=b(a);d.push({text:a,width:x,kind:"text",graphemeWidths:null})}continue}let I=b(o),e=null;if(B[g]&&o.length>1){let a=[];for(let x of s.segment(o))a.push(b(x.segment));a.length>1&&(e=a)}d.push({text:o,width:I,kind:"text",graphemeWidths:e})}return d}function J(t,c,m,f,h){if(t.length===0)return{lines:[],lineCount:0};let w=[],u=0,s=!1,r=0,p=0,n=0,i=0,S=-1,B=0,l=h.get(f);l||(l=new Map,h.set(f,l));let b=l.get("-");b===void 0&&(b=m.measureSegment("-",f).width,l.set("-",b));function d(e=n,a=i,x=u){let k="";for(let L=r;L<e;L++){let W=t[L];if(!(W.kind==="soft-hyphen"||W.kind==="hard-break"))if(L===r&&p>0&&W.graphemeWidths){let P=[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(W.text)].map(K=>K.segment);k+=P.slice(p).join("")}else k+=W.text}if(a>0&&e<t.length){let L=t[e],v=[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(L.text)].map(K=>K.segment),P=r===e?p:0;k+=v.slice(P,a).join("")}e>0&&t[e-1]?.kind==="soft-hyphen"&&!(r===e&&p>0)&&(k+="-"),w.push({text:k,width:x,startSegment:r,startGrapheme:p,endSegment:e,endGrapheme:a}),u=0,s=!1,S=-1,B=0}function g(e){return e==="space"||e==="zero-width-break"||e==="soft-hyphen"}function o(e,a,x){s=!0,r=e,p=a,n=e+1,i=0,u=x}function y(e,a,x){s=!0,r=e,p=a,n=e,i=a+1,u=x}for(let e=0;e<t.length;e++){let a=t[e];if(a.kind==="hard-break"){s?d():w.push({text:"",width:0,startSegment:e,startGrapheme:0,endSegment:e,endGrapheme:0}),r=e+1,p=0;continue}let x=a.width;if(!s){x>c&&a.graphemeWidths?I(e,0,a.graphemeWidths):o(e,0,x),g(a.kind)&&(S=e+1,B=a.kind==="space"?u-x:u);continue}let k=u+x;if(k>c+.005){if(g(a.kind)){u+=x,n=e+1,i=0,d(e+1,0,a.kind==="space"?u-x:u);continue}if(S>=0){d(S,0,B),e--;continue}if(x>c&&a.graphemeWidths){d(),I(e,0,a.graphemeWidths);continue}d(),e--;continue}u=k,n=e+1,i=0,g(a.kind)&&(S=e+1,B=a.kind==="space"?u-x:u)}return s&&d(),{lines:w,lineCount:w.length};function I(e,a,x){for(let k=a;k<x.length;k++){let L=x[k];if(!s){y(e,k,L);continue}u+L>c+.005?(d(),y(e,k,L)):(u+=L,n=e,i=k+1)}s&&n===e&&i===x.length&&(n=e+1,i=0)}}function A(t){return t==="space"||t==="zero-width-break"||t==="soft-hyphen"}var T=null;function _(){return T===null&&(T=new Intl.Segmenter(void 0,{granularity:"grapheme"})),T}function j(t,c,m){if(c===0&&m<0)return t.text;let f=[..._().segment(t.text)].map(w=>w.segment),h=m<0?f.length:m;return f.slice(c,h).join("")}function C(t,c,m,f,h,w){let u="";for(let s=c;s<f;s++){let r=t[s];r.kind==="soft-hyphen"||r.kind==="hard-break"||(s===c&&m>0?u+=j(r,m,-1):u+=r.text)}if(h>0&&f<t.length){let s=t[f];u+=j(s,c===f?m:0,h)}return w&&(u+="-"),u}function $(t){if(!t||!t.adapter||!t.font)return 0;let c=t.cache;if(c){let m=c.get(t.font);m||(m=new Map,c.set(t.font,m));let f=m.get("-");return f===void 0&&(f=t.adapter.measureSegment("-",t.font).width,m.set("-",f)),f}return t.adapter.measureSegment("-",t.font).width}function te(t,c,m,f){let h=c.segmentIndex,w=c.graphemeIndex;if(h>=t.length)return null;if(w===0){for(;h<t.length;){let e=t[h];if(e.kind==="hard-break")return{text:"",width:0,start:{segmentIndex:c.segmentIndex,graphemeIndex:0},end:{segmentIndex:h+1,graphemeIndex:0}};if(e.kind==="space"||e.kind==="zero-width-break"||e.kind==="soft-hyphen"){h+=1;continue}break}if(h>=t.length)return null}let u=$(f),s=h,r=h===c.segmentIndex?w:0,p=0,n=s,i=0,S=!1,B=-1,l=0,b=0,d=!1,g=(e,a,x,k)=>{B=e,l=a,b=x,d=k==="soft-hyphen"},o=(e,a,x)=>{for(let k=a;k<x.length;k++){let L=x[k];if(!S){p=L,n=e,i=k+1,S=!0;continue}if(p+L>m+.005)return!0;p+=L,n=e,i=k+1}return n===e&&i===x.length&&(n=e+1,i=0),!1};if(r>0&&s<t.length){let e=t[s];if(e.graphemeWidths){if(o(s,r,e.graphemeWidths))return{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}};h=n}}for(;h<t.length;){let e=t[h];if(e.kind==="hard-break"){if(S){let k=n>0&&t[n-1]?.kind==="soft-hyphen";return{text:C(t,s,r,n,i,k),width:p+(k?u:0),start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}return{text:"",width:0,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:h+1,graphemeIndex:0}}}let a=e.width;if(!S){if(a>m&&e.graphemeWidths){if(o(h,0,e.graphemeWidths))return{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}};h=n;continue}p=a,n=h+1,i=0,S=!0,A(e.kind)&&g(h+1,0,e.kind==="space"?p-a:p,e.kind),h+=1;continue}let x=p+a;if(x>m+.005){if(A(e.kind)){n=h+1,i=0;let L=e.kind==="soft-hyphen",W=e.kind==="space"?p:p+(L?u:0);return{text:C(t,s,r,n,i,L),width:W,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}return B>=0?{text:C(t,s,r,B,l,d),width:b+(d?u:0),start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:B,graphemeIndex:l}}:a>m&&e.graphemeWidths?{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}:{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}p=x,n=h+1,i=0,A(e.kind)&&g(h+1,0,e.kind==="space"?p-a:p,e.kind),h+=1}if(!S)return null;let y=n>0&&t[n-1]?.kind==="soft-hyphen";return{text:C(t,s,r,n,i,y),width:p+(y?u:0),start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}function ne(t,c,m=0){let f=[t];for(let h=0;h<c.length;h++){let w=c[h],u=[];for(let s=0;s<f.length;s++){let r=f[s];if(w.right<=r.left||w.left>=r.right){u.push(r);continue}w.left>r.left&&u.push({left:r.left,right:w.left}),w.right<r.right&&u.push({left:w.right,right:r.right})}f=u}return m>0?f.filter(h=>h.right-h.left>=m):f}function Q(t,c,m){let f=[],h=new Intl.Segmenter(void 0,{granularity:"grapheme"});for(let w=0;w<t.lines.length;w++){let u=t.lines[w],s=w*m,r=0;for(let p=u.startSegment;p<c.length;p++){let n=c[p];if(n.kind==="soft-hyphen"||n.kind==="hard-break"){if(p>=u.endSegment&&u.endGrapheme===0)break;continue}let i=[...h.segment(n.text)].map(l=>l.segment);if(i.length===0)continue;let S=p===u.startSegment?u.startGrapheme:0,B;if(p<u.endSegment)B=i.length;else if(p===u.endSegment&&u.endGrapheme>0)B=u.endGrapheme;else break;for(let l=S;l<B;l++){let b=n.graphemeWidths?n.graphemeWidths[l]:n.width/i.length;f.push({x:r,y:s,width:b,height:m,line:w}),r+=b}}}return f}function re(t){let{adapter:c,name:m="reactive-layout"}=t,f=new z(m),h=new Map,w=M(t.text??"",{name:"text"}),u=M(t.font??"16px sans-serif",{name:"font"}),s=M(t.lineHeight??20,{name:"line-height"}),r=M(Math.max(0,t.maxWidth??800),{name:"max-width"});function p(l,b){if(l===null||b===null)return l===b;if(l.length!==b.length)return!1;for(let d=0;d<l.length;d++)if(l[d]!==b[d])return!1;return!0}let n=H([w,u],(l,b,d)=>{let g=l[0],o=g!=null&&g.length>0?g.at(-1):d.prevData[0],y=l[1],I=y!=null&&y.length>0?y.at(-1):d.prevData[1],e=R(),a={hits:0,misses:0},x=V(o,I,c,h,a),k=R()-e,L=a.hits+a.misses,W=L===0?1:a.hits/L,v=n.meta;v&&(G(v["cache-hit-rate"],W),G(v["segment-count"],x.length),G(v["layout-time-ns"],k)),b.emit(x);let P=()=>{h.clear(),c.clearCache?.()};return{deactivate:P,invalidate:P}},{name:"segments",describeKind:"derived",meta:{"cache-hit-rate":0,"segment-count":0,"layout-time-ns":0},equals:(l,b)=>{let d=l,g=b;if(d==null||g==null)return d===g;if(d.length!==g.length)return!1;for(let o=0;o<d.length;o++){let y=d[o],I=g[o];if(y.text!==I.text||y.width!==I.width||y.kind!==I.kind||!p(y.graphemeWidths??null,I.graphemeWidths??null))return!1}return!0}}),i=N([n,r,u],([l,b,d])=>J(l,b,c,d,h),{name:"line-breaks",equals:(l,b)=>{let d=l,g=b;if(d==null||g==null)return d===g;if(d.lineCount!==g.lineCount)return!1;for(let o=0;o<d.lines.length;o++){let y=d.lines[o],I=g.lines[o];if(y.text!==I.text||y.width!==I.width||y.startSegment!==I.startSegment||y.startGrapheme!==I.startGrapheme||y.endSegment!==I.endSegment||y.endGrapheme!==I.endGrapheme)return!1}return!0}}),S=N([i,s],([l,b])=>l.lineCount*b,{name:"height"}),B=N([i,n,s],([l,b,d])=>Q(l,b,d),{name:"char-positions",equals:(l,b)=>{let d=l,g=b;if(d==null||g==null)return d===g;if(d.length!==g.length)return!1;for(let o=0;o<d.length;o++)if(d[o].x!==g[o].x||d[o].y!==g[o].y||d[o].width!==g[o].width)return!1;return!0}});return f.add(w,{name:"text"}),f.add(u,{name:"font"}),f.add(s,{name:"line-height"}),f.add(r,{name:"max-width"}),f.add(n,{name:"segments"}),f.add(i,{name:"line-breaks"}),f.add(S,{name:"height"}),f.add(B,{name:"char-positions"}),{graph:f,setText:l=>f.set("text",l),setFont:l=>f.set("font",l),setLineHeight:l=>f.set("line-height",l),setMaxWidth:l=>f.set("max-width",Math.max(0,l)),segments:n,lineBreaks:i,height:S,charPositions:B}}export{V as a,J as b,te as c,ne as d,Q as e,re as f};
|