@graphrefly/graphrefly 0.41.0 → 0.42.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-Cxs1eztH.d.cts → cascading-CH-_VwG9.d.cts} +2 -2
- package/dist/{cascading-BNfxffgc.d.ts → cascading-OgKQZjsa.d.ts} +2 -2
- package/dist/{chunk-L77I47VU.js → chunk-2K5RXLAH.js} +1 -1
- package/dist/chunk-3ERTUW2J.js +45 -0
- package/dist/chunk-3K7HA4Y6.js +1 -0
- package/dist/chunk-3ZZX7M25.js +1 -0
- package/dist/chunk-4QH6VJF4.js +1 -0
- package/dist/{chunk-M3FQSXEW.js → chunk-5QRRKBUT.js} +1 -1
- package/dist/chunk-5ST42ESJ.js +1 -0
- package/dist/{chunk-AK5RHMC5.js → chunk-6YFZMUMR.js} +1 -1
- package/dist/{chunk-SC27WTSG.js → chunk-7ARY3Y3T.js} +1 -1
- package/dist/chunk-7B7ELAT2.js +1 -0
- package/dist/{chunk-F7VUYPP6.js → chunk-7VKFXLZQ.js} +1 -1
- package/dist/chunk-ACMJ2ZPS.js +3 -0
- package/dist/{chunk-7PQLZMOG.js → chunk-AGNM6RS6.js} +1 -1
- package/dist/chunk-AS3TV2TV.js +1 -0
- package/dist/{chunk-CGNOWGV6.js → chunk-CISGGAIF.js} +1 -1
- package/dist/{chunk-ZAJ7J7TO.js → chunk-DEJTNNQC.js} +1 -1
- package/dist/{chunk-AI7QC7J6.js → chunk-FDZAZNRO.js} +1 -1
- package/dist/{chunk-OV5AA6HJ.js → chunk-FUZ6S2DY.js} +1 -1
- package/dist/{chunk-G3M3IMEV.js → chunk-G5VBJ5K6.js} +1 -1
- package/dist/{chunk-KNVCCBIU.js → chunk-HZKW2AAB.js} +1 -1
- package/dist/{chunk-CYOSWFT2.js → chunk-IZM3UEH3.js} +3 -3
- package/dist/{chunk-UISPDFJ3.js → chunk-KCACBSJH.js} +1 -1
- package/dist/{chunk-GI4Q7PNY.js → chunk-KT5DTRBP.js} +1 -1
- package/dist/{chunk-33N4TU3X.js → chunk-KY2LMAXU.js} +1 -1
- package/dist/{chunk-TT4C7DXW.js → chunk-LDQ3IUIP.js} +1 -1
- package/dist/chunk-LPRWATHB.js +61 -0
- package/dist/{chunk-X7QKTXXC.js → chunk-NWXQIOIB.js} +3 -3
- package/dist/{chunk-VV62MIG4.js → chunk-Q7QQQA3I.js} +1 -1
- package/dist/chunk-VE5SIZEM.js +1 -0
- package/dist/chunk-VRALOYRD.js +1 -0
- package/dist/{chunk-5VEZLQFN.js → chunk-WHMUB5QB.js} +1 -1
- package/dist/chunk-XLQPNNIC.js +1 -0
- package/dist/{chunk-YQRN4CIV.js → chunk-YGL7FPVQ.js} +1 -1
- package/dist/compat/index.cjs +5 -5
- package/dist/compat/index.d.cts +16 -16
- package/dist/compat/index.d.ts +16 -16
- package/dist/compat/index.js +1 -1
- package/dist/compat/jotai/index.d.cts +2 -2
- package/dist/compat/jotai/index.d.ts +2 -2
- package/dist/compat/nanostores/index.d.cts +2 -2
- package/dist/compat/nanostores/index.d.ts +2 -2
- package/dist/compat/nestjs/index.cjs +5 -5
- package/dist/compat/nestjs/index.d.cts +8 -8
- package/dist/compat/nestjs/index.d.ts +8 -8
- 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 +3 -3
- 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/core/index.d.cts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/{decay-C25AyNAj.d.cts → decay-2ZukgQ4o.d.cts} +2 -2
- package/dist/{decay-BnrlbxSv.d.ts → decay-CdEBmDIs.d.ts} +2 -2
- package/dist/extra/browser.d.cts +1 -1
- package/dist/extra/browser.d.ts +1 -1
- package/dist/extra/index.cjs +14 -14
- package/dist/extra/index.d.cts +10 -11
- package/dist/extra/index.d.ts +10 -11
- package/dist/extra/index.js +1 -1
- package/dist/extra/node.cjs +2 -2
- 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.d.cts +3 -3
- package/dist/extra/reactive.d.ts +3 -3
- package/dist/extra/reactive.js +1 -1
- package/dist/extra/render/index.d.cts +3 -3
- package/dist/extra/render/index.d.ts +3 -3
- package/dist/extra/sources.cjs +3 -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.d.cts +1 -1
- package/dist/extra/storage-browser.d.ts +1 -1
- package/dist/{fallback-CMZl39L5.d.ts → fallback-CqYVLL6X.d.ts} +1 -1
- package/dist/{fallback-8JYU8tlT.d.cts → fallback-Ctlj2tMY.d.cts} +1 -1
- package/dist/graph/index.cjs +7 -7
- 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-BkIkog4h.d.ts → graph-7VguS7a4.d.ts} +3 -3
- package/dist/{graph-E6likq7w.d.cts → graph-C4SHb3Ly.d.cts} +3 -3
- package/dist/{index-DktLSZOc.d.cts → index-2B7u2pVn.d.cts} +4 -4
- package/dist/{index-DGD4_fj6.d.cts → index-3NmAfcH0.d.cts} +8 -5
- package/dist/{index-DfOK_oL5.d.ts → index-4Uz-e_fL.d.ts} +372 -17
- package/dist/{index-BAQrjuZF.d.ts → index-B-i4_g3k.d.ts} +2 -2
- package/dist/{index-DpiGqtrs.d.cts → index-B11anra4.d.cts} +441 -381
- package/dist/{index-WSlcjhQF.d.ts → index-B3OTH1dV.d.ts} +124 -13
- package/dist/{index-2n8Eai6M.d.ts → index-BG0BN3PB.d.ts} +1 -1
- package/dist/{index-z8WFPVI8.d.cts → index-BJX94aud.d.cts} +1 -1
- package/dist/{index-DhLyOHYZ.d.ts → index-BP8a88zx.d.ts} +11 -4
- package/dist/{index-Cnr1WrlX.d.cts → index-BTQtTb_H.d.cts} +14 -3
- package/dist/{index-BaA-xpSw.d.ts → index-BUYXac2c.d.ts} +3 -3
- package/dist/{index-DOBLxOti.d.cts → index-BVpm6noz.d.cts} +1 -1
- package/dist/{index-DhnsQfa3.d.ts → index-Bbkgpt5t.d.ts} +441 -381
- package/dist/{index-Cczxgd2D.d.ts → index-Bc41FuHp.d.cts} +3 -3
- package/dist/{index-BiHUBEKq.d.cts → index-BdGtBX-X.d.cts} +3 -3
- package/dist/index-BeT2r7sk.d.ts +760 -0
- package/dist/{index-da2V5vPy.d.ts → index-Bf7eqeSF.d.ts} +2 -2
- package/dist/{index-bXXLSvor.d.ts → index-Bn4zHYLj.d.ts} +4 -4
- package/dist/{index-DGTo1yka.d.cts → index-BoLv_OfD.d.cts} +2 -2
- package/dist/{index-B72TQQHd.d.cts → index-BsT7F2et.d.ts} +3 -3
- package/dist/{index-Bd91Nmf4.d.cts → index-BtAsBp8K.d.cts} +4 -4
- package/dist/{index-DgJc8Zgc.d.cts → index-C0-Jv1kP.d.cts} +81 -5
- package/dist/{index-C6ZUaos7.d.ts → index-C7O6r5fV.d.ts} +1 -1
- package/dist/{index-CL7oilfm.d.cts → index-C9kSENB4.d.cts} +1 -1
- package/dist/{index-yLt-aPMp.d.ts → index-CCq87F7t.d.ts} +1 -1
- package/dist/{index-DQQCOIt8.d.cts → index-CEMx8n40.d.cts} +10 -5
- package/dist/{index-BilOa6AE.d.cts → index-CJIuLu2f.d.cts} +124 -13
- package/dist/{index-B2RUoIUz.d.ts → index-CJK1JkYy.d.ts} +1 -1
- package/dist/{index-CG33HeBW.d.ts → index-CJQm0g38.d.ts} +8 -5
- package/dist/index-CPNSy-U0.d.cts +760 -0
- package/dist/{index-A3U3CSve.d.cts → index-CZjOhcBy.d.cts} +2 -2
- package/dist/{index-CAP3UGsq.d.ts → index-CZmcDtFn.d.ts} +1 -1
- package/dist/{index-DYTBbF8T.d.cts → index-ChOyVLKm.d.cts} +1 -1
- package/dist/{index-eaQuGJnv.d.ts → index-CpyNFqkB.d.ts} +3 -3
- package/dist/{index-BJSZxSFX.d.ts → index-CvrqGfNS.d.ts} +1 -1
- package/dist/{index-DuRsN9ae.d.cts → index-D-Xs74HZ.d.cts} +372 -17
- package/dist/{index-C5cQ7Gfx.d.ts → index-D6egPFAL.d.ts} +4 -4
- package/dist/{index-CD2dBMet.d.ts → index-D8l8hNXn.d.ts} +10 -5
- package/dist/{index-40ZT4MHj.d.ts → index-DBHK8O6H.d.ts} +14 -3
- package/dist/{index-DVDapw2k.d.cts → index-DBIqYS43.d.cts} +35 -21
- package/dist/{index-3k4Gg6-n.d.ts → index-DBevwHj_.d.ts} +3 -3
- package/dist/{index-Ctb7_2sG.d.ts → index-DIOoAZUX.d.ts} +1 -1
- package/dist/{index-BQ1fR4li.d.ts → index-DO9XxMzS.d.ts} +35 -21
- package/dist/{index-CQtWm7jS.d.ts → index-DQo8xBgd.d.ts} +9 -9
- package/dist/{index-DH4fm2Ck.d.ts → index-Dgs8zcj7.d.ts} +2 -2
- package/dist/{index-CtFNGe-m.d.cts → index-Dhc7a7Xo.d.cts} +2 -2
- package/dist/{index-MxYuWOrf.d.cts → index-DmAgG5CI.d.cts} +3 -3
- package/dist/{index-CoM4rzyB.d.ts → index-Dmqp7KjD.d.ts} +1 -1
- package/dist/{index-B6iTqKtJ.d.ts → index-Dn-wI9g4.d.ts} +2 -2
- package/dist/{index-C-dkXOpB.d.cts → index-Du7u1lSf.d.cts} +11 -4
- package/dist/{index-DVAlsmEU.d.cts → index-HoU88d5U.d.cts} +3 -3
- package/dist/{index-CRm0YIzC.d.cts → index-LIpQQE9f.d.cts} +9 -9
- package/dist/{index-CgnCFhr2.d.cts → index-f5IivDUX.d.cts} +1 -1
- package/dist/{index-PgwvGWa1.d.cts → index-hHcaFlJX.d.cts} +1 -1
- package/dist/{index-I1cCY3ZI.d.ts → index-pT8sCpOJ.d.ts} +81 -5
- package/dist/{index-D4uimgee.d.cts → index-sl4NyzQx.d.cts} +1 -1
- package/dist/{index-tV3AA9hI.d.cts → index-tJoTcnHh.d.cts} +2 -2
- package/dist/{index-D3ayz3hy.d.cts → index-z96luz5O.d.cts} +1 -1
- package/dist/index.cjs +48 -48
- package/dist/index.d.cts +45 -50
- package/dist/index.d.ts +45 -50
- package/dist/index.js +1 -1
- package/dist/{meta-D8OyedKp.d.ts → meta-BgVAsg9j.d.ts} +1 -1
- package/dist/{meta-Ct9nqQS5.d.cts → meta-vE8bxW1E.d.cts} +1 -1
- package/dist/{node-BYInONRr.d.cts → node-ClS5yC-B.d.cts} +1 -1
- package/dist/{node-BYInONRr.d.ts → node-ClS5yC-B.d.ts} +1 -1
- package/dist/{observable-DO8DDEzv.d.ts → observable-BsBzUrcI.d.ts} +1 -1
- package/dist/{observable-DMIlYJV1.d.cts → observable-DLGPPtb8.d.cts} +1 -1
- package/dist/patterns/ai/browser.d.cts +4 -4
- package/dist/patterns/ai/browser.d.ts +4 -4
- package/dist/patterns/ai/browser.js +1 -1
- package/dist/patterns/ai/index.cjs +17 -17
- package/dist/patterns/ai/index.d.cts +17 -17
- package/dist/patterns/ai/index.d.ts +17 -17
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/ai/node.d.cts +4 -4
- package/dist/patterns/ai/node.d.ts +4 -4
- package/dist/patterns/ai/node.js +1 -1
- package/dist/patterns/cqrs/index.cjs +3 -3
- package/dist/patterns/cqrs/index.d.cts +6 -6
- package/dist/patterns/cqrs/index.d.ts +6 -6
- package/dist/patterns/cqrs/index.js +1 -1
- package/dist/patterns/demo-shell/index.cjs +5 -5
- 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 +3 -3
- 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 +12 -12
- package/dist/patterns/graphspec/index.d.cts +5 -5
- package/dist/patterns/graphspec/index.d.ts +5 -5
- package/dist/patterns/graphspec/index.js +1 -1
- package/dist/patterns/harness/index.cjs +10 -8
- package/dist/patterns/harness/index.d.cts +11 -12
- package/dist/patterns/harness/index.d.ts +11 -12
- package/dist/patterns/harness/index.js +1 -1
- package/dist/patterns/inspect/index.cjs +3 -0
- package/dist/patterns/inspect/index.d.cts +9 -0
- package/dist/patterns/inspect/index.d.ts +9 -0
- package/dist/patterns/inspect/index.js +1 -0
- package/dist/patterns/job-queue/index.cjs +3 -3
- package/dist/patterns/job-queue/index.d.cts +6 -6
- package/dist/patterns/job-queue/index.d.ts +6 -6
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/memory/index.cjs +3 -3
- package/dist/patterns/memory/index.d.cts +6 -6
- package/dist/patterns/memory/index.d.ts +6 -6
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.cjs +3 -3
- package/dist/patterns/messaging/index.d.cts +5 -5
- package/dist/patterns/messaging/index.d.ts +5 -5
- package/dist/patterns/messaging/index.js +1 -1
- package/dist/patterns/orchestration/index.cjs +3 -3
- package/dist/patterns/orchestration/index.d.cts +7 -7
- package/dist/patterns/orchestration/index.d.ts +7 -7
- package/dist/patterns/orchestration/index.js +1 -1
- package/dist/patterns/process/index.cjs +1 -1
- package/dist/patterns/process/index.d.cts +7 -7
- package/dist/patterns/process/index.d.ts +7 -7
- package/dist/patterns/process/index.js +1 -1
- package/dist/patterns/reactive-layout/index.cjs +4 -4
- 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 +3 -3
- 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/surface/index.cjs +8 -8
- package/dist/patterns/surface/index.d.cts +6 -6
- package/dist/patterns/surface/index.d.ts +6 -6
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{pipeline-graph-MWrQZXCq.d.cts → pipeline-graph-WBlobVhU.d.cts} +5 -5
- package/dist/{pipeline-graph-CB4La-UW.d.ts → pipeline-graph-v8fMvqNk.d.ts} +5 -5
- package/dist/{reactive-layout-BtZfUKuL.d.cts → reactive-layout-Dsvob4zD.d.cts} +2 -2
- package/dist/{reactive-layout-KJj4E2dT.d.ts → reactive-layout-v7KPvxoc.d.ts} +2 -2
- package/dist/{reactive-log-_zeEnB9H.d.cts → reactive-log-B00laMSQ.d.cts} +1 -1
- package/dist/{reactive-log-BlAsPLl2.d.ts → reactive-log-BezYsbA_.d.ts} +1 -1
- package/dist/{reactive-map-6P_k3AQM.d.cts → reactive-map-48mnZ-nu.d.cts} +1 -1
- package/dist/{reactive-map-CjXByDV-.d.ts → reactive-map-BVVPdvmi.d.ts} +1 -1
- package/dist/resilience-445VFFXQ.js +1 -0
- package/dist/{sugar-BhfjgetH.d.ts → sugar-CH-2ZY90.d.ts} +1 -1
- package/dist/{sugar-DzePN5-g.d.cts → sugar-DStZfUEK.d.cts} +1 -1
- package/dist/{topology-tree-mF7Emqzm.d.ts → topology-tree-BNGvuG82.d.ts} +1 -1
- package/dist/{topology-tree-3LBKFsUo.d.cts → topology-tree-BSdfSwMi.d.cts} +1 -1
- package/dist/{types-1Dhoi7HM.d.cts → types-B1jDWVsM.d.cts} +1 -1
- package/dist/{types-39jk0kaV.d.ts → types-DkzUUs0H.d.ts} +1 -1
- package/package.json +11 -51
- package/dist/budget-gate-CmmVtasH.d.ts +0 -115
- package/dist/budget-gate-DiP_nK0n.d.cts +0 -115
- package/dist/chunk-2W553JJC.js +0 -1
- package/dist/chunk-4MKL6Q3K.js +0 -1
- package/dist/chunk-5B3JDG5F.js +0 -1
- package/dist/chunk-5QSXEMXG.js +0 -1
- package/dist/chunk-5TEFC2ZX.js +0 -1
- package/dist/chunk-5TOPVRN6.js +0 -1
- package/dist/chunk-EC2WNSZ7.js +0 -1
- package/dist/chunk-ELAASRBT.js +0 -3
- package/dist/chunk-H5SCWHWP.js +0 -1
- package/dist/chunk-OLIKJUKI.js +0 -1
- package/dist/chunk-POXANAJ6.js +0 -3
- package/dist/chunk-RSMEXK53.js +0 -43
- package/dist/chunk-SGS4OJGS.js +0 -1
- package/dist/chunk-URJ2VFNC.js +0 -1
- package/dist/chunk-VXPLLA4P.js +0 -1
- package/dist/chunk-WZYB3JQS.js +0 -1
- package/dist/chunk-Z6X7B6A4.js +0 -61
- package/dist/index-8s-Qm-gz.d.ts +0 -218
- package/dist/index-BgjS2b8N.d.ts +0 -366
- package/dist/index-BmSQLAZo.d.cts +0 -244
- package/dist/index-CGhMJNHb.d.cts +0 -128
- package/dist/index-CUIkE1l9.d.cts +0 -230
- package/dist/index-Ck35nA-T.d.ts +0 -244
- package/dist/index-CuPUehFa.d.cts +0 -218
- package/dist/index-D1Gc7wV5.d.ts +0 -230
- package/dist/index-N2MAxt7_.d.ts +0 -128
- package/dist/index-t6L2qpHh.d.cts +0 -366
- package/dist/patterns/audit/index.cjs +0 -3
- package/dist/patterns/audit/index.d.cts +0 -8
- package/dist/patterns/audit/index.d.ts +0 -8
- package/dist/patterns/audit/index.js +0 -1
- package/dist/patterns/guarded-execution/index.cjs +0 -3
- package/dist/patterns/guarded-execution/index.d.cts +0 -9
- package/dist/patterns/guarded-execution/index.d.ts +0 -9
- package/dist/patterns/guarded-execution/index.js +0 -1
- package/dist/patterns/lens/index.cjs +0 -3
- package/dist/patterns/lens/index.d.cts +0 -7
- package/dist/patterns/lens/index.d.ts +0 -7
- package/dist/patterns/lens/index.js +0 -1
- package/dist/patterns/refine-loop/index.cjs +0 -5
- package/dist/patterns/refine-loop/index.d.cts +0 -9
- package/dist/patterns/refine-loop/index.d.ts +0 -9
- package/dist/patterns/refine-loop/index.js +0 -1
- package/dist/patterns/resilient-pipeline/index.cjs +0 -3
- package/dist/patterns/resilient-pipeline/index.d.cts +0 -8
- package/dist/patterns/resilient-pipeline/index.d.ts +0 -8
- package/dist/patterns/resilient-pipeline/index.js +0 -1
- package/dist/resilience-JISHQD2F.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var qe=Object.defineProperty;var dn=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var ln=Object.prototype.hasOwnProperty;var V=(n,e)=>()=>(n&&(e=n(n=0)),e);var fn=(n,e)=>{for(var t in e)qe(n,t,{get:e[t],enumerable:!0})},pn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of cn(e))!ln.call(n,s)&&s!==t&&qe(n,s,{get:()=>e[s],enumerable:!(r=dn(e,s))||r.enumerable});return n};var hn=n=>pn(qe({},"__esModule",{value:!0}),n);function Ee(){return ue>0||_e}function wt(){return ue>0}function ce(n){ue>0?Te.push(n):n()}function Re(n){ue+=1;let e=!1;try{n()}catch(t){throw e=!0,t}finally{if(ue-=1,ue===0)if(e){if(!_e){let t=Te.splice(0);for(let r of t)try{r()}catch{}ee.length=0,te.length=0,de.length=0}}else gn()}}function gn(){let n=!_e;n&&(_e=!0);let e=[],t=0;try{for(;ee.length>0||te.length>0||de.length>0||n&&Te.length>0;){if(n&&Te.length>0){let o=Te.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw ee.length=0,te.length=0,de.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(ee.length>0?ee:te.length>0?te:de).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{n&&(_e=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function Ae(n,e,t){if(e.length===0)return;if(e.length===1){let d=t(e[0][0]);if(d<3||!Ee()){n(e);return}(d>=5?de:d===4?te:ee).push(()=>n(e));return}let r=e.length,s=r,o=r,i=r,a=0;for(;a<r&&t(e[a][0])<3;)a++;for(s=a;a<r&&t(e[a][0])===3;)a++;for(o=a;a<r&&t(e[a][0])===4;)a++;i=a;let u=Ee();if(s>0){let d=e.slice(0,s);n(d)}if(o>s){let d=e.slice(s,o);u?ee.push(()=>n(d)):n(d)}if(i>o){let d=e.slice(o,i);u?te.push(()=>n(d)):n(d)}if(r>i){let d=e.slice(i,r);u?de.push(()=>n(d)):n(d)}}var ue,_e,ee,te,de,Te,Se=V(()=>{"use strict";ue=0,_e=!1,ee=[],te=[],de=[],Te=[]});var le,G,U,q,K,J,Z,j,F,S,fe,Ke,mn,Ye,bn,yn,Je,_t,Tt,Nt,Xe,ne=V(()=>{"use strict";le=Symbol.for("graphrefly/START"),G=Symbol.for("graphrefly/DATA"),U=Symbol.for("graphrefly/DIRTY"),q=Symbol.for("graphrefly/RESOLVED"),K=Symbol.for("graphrefly/INVALIDATE"),J=Symbol.for("graphrefly/PAUSE"),Z=Symbol.for("graphrefly/RESUME"),j=Symbol.for("graphrefly/TEARDOWN"),F=Symbol.for("graphrefly/COMPLETE"),S=Symbol.for("graphrefly/ERROR"),fe=Object.freeze([U]),Ke=Object.freeze([q]),mn=Object.freeze([K]),Ye=Object.freeze([le]),bn=Object.freeze([F]),yn=Object.freeze([j]),Je=Object.freeze([fe]),_t=Object.freeze([Ke]),Tt=Object.freeze([mn]),Nt=Object.freeze([bn]),Xe=Object.freeze([yn])});function xt(n,e){let t=new TextEncoder().encode(n.name);if(t.length===0||t.length>255)throw new Error(`encodeEnvelope: codec name "${n.name}" encodes to ${t.length} bytes (must be 1\u2013255)`);let r=n.version;if(!Number.isInteger(r)||r<0||r>65535)throw new Error(`encodeEnvelope: codec.version ${r} out of u16 range (expected integer 0\u201365535)`);let s=2+t.length+2+e.length;if(s>4294967295)throw new Error(`encodeEnvelope: total envelope size ${s} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let o=new Uint8Array(s),i=0;return o[i++]=Ze,o[i++]=t.length,o.set(t,i),i+=t.length,o[i++]=r>>>8&255,o[i++]=r&255,o.set(e,i),o}function kt(n,e){if(n.length<Ot)throw new Error(`decodeEnvelope: bytes too short (${n.length} < ${Ot})`);let t=0,r=n[t++];if(r!==Ze)throw new Error(`decodeEnvelope: unsupported envelope version ${r} (expected ${Ze})`);let s=n[t++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+s+2>n.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+s+2} bytes, have ${n.length})`);let o=new TextDecoder().decode(n.subarray(t,t+s));t+=s;let i=(n[t]<<8|n[t+1])>>>0;t+=2;let a=n.subarray(t),u=e.lookupCodec(o);if(u==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:u,codecVersion:i,payload:a}}function Et(n){n.registerCodec(vn)}var vn,Ze,Ot,Qe=V(()=>{"use strict";vn={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}},Ze=1,Ot=4});function De(n){if(n==null)return pe;let{type:e,id:t,...r}=n;return{type:e??"system",id:t??"",...r}}var pe,et=V(()=>{"use strict";pe={type:"system",id:""}});function X(){return Math.trunc(performance.now()*1e6)}function Ce(){return Date.now()*1e6}var Me=V(()=>{"use strict"});function Rt(n){n.registerMessageType(le,{tier:0,wireCrossing:!1}),n.registerMessageType(U,{tier:1,wireCrossing:!1}),n.registerMessageType(K,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(J,{tier:2,wireCrossing:!1}),n.registerMessageType(Z,{tier:2,wireCrossing:!1}),n.registerMessageType(G,{tier:3,wireCrossing:!0}),n.registerMessageType(q,{tier:3,wireCrossing:!0}),n.registerMessageType(F,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(S,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(j,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var Ge,At=V(()=>{"use strict";ne();Ge=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_rigorRecorder;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=t=>{let r=this._messageTypes.get(t);return r!=null?r.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}get rigorRecorder(){return this._rigorRecorder}set rigorRecorder(e){this._rigorRecorder=e}registerMessageType(e,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}}});function St(n){return Array.isArray(n)?[...n]:[n]}function wn(n,e){return n.has(e)||n.has("*")}function Dt(n){let e=[];return n((s,o)=>{e.push({kind:"allow",actions:new Set(St(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(St(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let u of e)wn(u.actions,o)&&u.where(s)&&(u.kind==="deny"?i=!0:a=!0);return i?!1:a}}function tt(n){let e=_n.filter(t=>n({type:t,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(t=>t==="human"||t==="llm"||t==="system")?"both":e.length===1?e[0]:e.join("+")}var W,_n,Ne=V(()=>{"use strict";W=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};_n=["human","llm","wallet","system"]});function nt(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(nt);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=nt(n[t]);return e}return null}function On(n){let e=Nn.encode(n),t=e.length,r=t*8,s=t+9+63&-64,o=new Uint8Array(s);o.set(e),o[t]=128;let i=new DataView(o.buffer);i.setUint32(s-4,r>>>0,!1),i.setUint32(s-8,Math.floor(r/4294967296)>>>0,!1);let a=1779033703,u=3144134277,d=1013904242,l=2773480762,g=1359893119,h=2600822924,f=528734635,c=1541459225,m=new Uint32Array(64),p=(y,b)=>y>>>b|y<<32-b;for(let y=0;y<s;y+=64){for(let N=0;N<16;N++)m[N]=i.getUint32(y+N*4,!1);for(let N=16;N<64;N++){let L=m[N-15],P=m[N-2],D=p(L,7)^p(L,18)^L>>>3,ae=p(P,17)^p(P,19)^P>>>10;m[N]=m[N-16]+D+m[N-7]+ae>>>0}let b=a,v=u,w=d,O=l,x=g,k=h,E=f,R=c;for(let N=0;N<64;N++){let L=p(x,6)^p(x,11)^p(x,25),P=x&k^~x&E,D=R+L+P+Tn[N]+m[N]>>>0,ae=p(b,2)^p(b,13)^p(b,22),Be=b&v^b&w^v&w,xe=ae+Be>>>0;R=E,E=k,k=x,x=O+D>>>0,O=w,w=v,v=b,b=D+xe>>>0}a=a+b>>>0,u=u+v>>>0,d=d+w>>>0,l=l+O>>>0,g=g+x>>>0,h=h+k>>>0,f=f+E>>>0,c=c+R>>>0}let _=y=>y.toString(16).padStart(8,"0");return _(a)+_(u)+_(d)+_(l)+_(g)+_(h)+_(f)+_(c)}function rt(n){let e=nt(n??null),t=JSON.stringify(e);return On(t).slice(0,16)}function xn(){let n=globalThis.crypto;if(n?.randomUUID)return n.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function st(n,e,t){let r=t?.id??xn();if(n===0)return{id:r,version:0};let o=(t?.hash??rt)(e);return{id:r,version:0,cid:o,prev:null}}function Ct(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}var Tn,Nn,Mt=V(()=>{"use strict";Tn=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Nn=new TextEncoder});function $t(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function ot(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function Pe(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}function re(n,e,t){let r=It(n)?n:[],s=typeof n=="function"?n:typeof e=="function"?e:void 0,o={};return It(n)?o=(it(e)?e:t)??{}:it(n)?o=n:o=(it(e)?e:t)??{},new $(r,s,o)}var Gt,Pt,kn,En,he,$,It,it,ge=V(()=>{"use strict";Qe();et();Se();Me();At();Ne();ne();Mt();Gt=()=>{},Pt=100;kn=(n,e,t,r)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},En=(n,e,t,r)=>{let s=n;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Ye]:[Ye,[G,o]];s._status==="dirty"&&i.push(fe),Ae(e,i,s._config.tierOf)},he=new Ge({onMessage:kn,onSubscribe:En});Rt(he);Et(he);$=class n{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,t,r){this._config=r.config??he,this._config.onMessage,this._optsName=r.name,this._describeKind=r.describeKind,this._equals=r.equals??Object.is,this._resubscribable=r.resubscribable??!1,this._resetOnTeardown=r.resetOnTeardown??!1,this._autoComplete=r.completeWhenDepsComplete??!0,this._autoError=r.errorWhenDepsError??!0,this._pausable=r.pausable??!0,this._guard=r.guard,this._fn=t,this._partial=r.partial??!1,this._cached=r.initial!==void 0?r.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=r.versioningHash??this._config.defaultHashFn??rt;let s=r.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?st(s,this._cached===void 0?void 0:this._cached,{id:r.versioningId,hash:this._hashFn}):void 0,this._deps=e.map($t);let o={};for(let[a,u]of Object.entries(r.meta??{})){let d={initial:u,name:`${r.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};r.guard!=null&&(d.guard=r.guard),o[a]=new n([],void 0,d)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[G,a]])},down(a){i._emit(Pe(a))},up(a){i._emitUp(Pe(a))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,t){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let r=this._versioningLevel;if(r!=null&&e<=r)return;let s=t?.hash??this._hashFn;s!==this._hashFn&&(this._hashFn=s);let o=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??t?.id,u=i?.version??0,d=st(e,o,{id:a,hash:s});d.version=u,this._versioning=d,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=De(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let r of this._extraGuards)if(!r(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,r=e?.actor!=null;if(!t&&!r)return;let s=De(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new W({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new W({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:Ce()}}down(e,t){let r=Pe(e);r.length!==0&&(this._checkGuard(t),this._emit(r))}emit(e,t){this._checkGuard(t),this._emit([[G,e]])}up(e,t){if(this._deps.length===0)return;let r=Pe(e);if(r.length===0)return;this._checkGuard(t);let s=t??{internal:!0};this._validateUpTiers(r);for(let o of this._deps)o.node.up?.(r,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let r of e){let s=t(r[0]);if(s===3||s===4)throw new Error(`Node "${this.name}": tier-${s} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let u=De(t);if(!this._guard(u,"observe"))throw new W({actor:u,action:"observe",nodeName:this.name})}let s=this._isTerminal&&this._resubscribable;if(s){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let u of this._deps)ot(u);if(this._partial===!1){for(let u of this._deps)if(u.prevData!==void 0||u.dataBatch.length!==0||u.terminal!==void 0||u.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:s},this._actions)}catch(u){throw this._sinkCount-=1,u}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let i=this._isTerminal;if(this._sinkCount===1&&!i)try{this._activate()}catch(u){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw u}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let r=0;r<e;r++){let s=r,o=this._deps[r];o.unsub=Gt,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,u=!1;for(let d of i)a(d[0])>=3&&(u=!0),this._config.onMessage(this,d,{direction:"down-in",depIndex:s},this._actions);u&&this._maybeRunFnOnSettlement()}),t++}}catch(r){this._deps[t].unsub=null;for(let s=0;s<t;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}ot(o)}}throw this._dirtyDepCount=0,r}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let t=this._deps.length,r=$t(e);if(this._deps.push(r),this._sinks==null)return t;r.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Je),r.unsub=Gt;try{r.unsub=e.subscribe(s=>{if(r.unsub===null)return;let o=this._config.tierOf,i=!1;for(let a of s)o(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw r.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(r){this._emit([[S,this._wrapFnError("cleanup threw",r)]])}else if(t!=null&&typeof t=="object"){let r=t.deactivate;if(typeof r=="function")try{r()}catch(s){this._emit([[S,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let r of this._deps){if(r.unsub!=null){let s=r.unsub;r.unsub=null;try{s()}catch{}}ot(r)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,t){let r=this._deps[e],s=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(o)}if(s!==le){if(s===U){this._depDirtied(r);return}if(s===K){if(this._depInvalidated(r),this._cached===void 0)return;this._emit(Tt);return}if(s===J||s===Z){this._emit([t]);return}if(s===j){this._emit(Xe);return}if(s===G)this._depSettledAsData(r,t[1]);else if(s===q)this._depSettledAsResolved(r);else if(s===F)this._depSettledAsTerminal(r,!0);else if(s===S)this._depSettledAsTerminal(r,t[1]);else{this._emit([t]);return}if(!this._fn){(s===G||s===q)&&this._emit([t]),(s===F||s===S)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Je))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(_t),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[S,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(Nt)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(i){this._emit([[S,this._wrapFnError("cleanup threw",i)]]);return}}else if(e!=null&&typeof e=="object"){let i=e.beforeRun;if(typeof i=="function"){e.beforeRun=void 0;try{i()}catch(a){this._emit([[S,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let t=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),r=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=t[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:r,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:r};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(t,this._actions,o);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let a=i;(typeof a.beforeRun=="function"||typeof a.deactivate=="function"||typeof a.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[S,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Pt?(this._rerunDepth=0,this._emit([[S,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Pt} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,t){let r=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${r}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[fe,e[0]]:e;let r=!0,s=!1,o=!1,i=-1;for(let u of e){let d=t(u[0]);d<i&&(r=!1),d===3&&(s=!0),u[0]===U&&(o=!0),i=d}let a=e;if(!r){let u=e.map((d,l)=>({m:d,i:l,tier:t(d[0])}));u.sort((d,l)=>d.tier-l.tier||d.i-l.i),a=u.map(d=>d.m)}if(s&&!o&&this._status!=="dirty"){let u=0;for(;u<a.length&&t(a[u][0])===0;)u++;return u===0?[fe,...a]:[...a.slice(0,u),fe,...a.slice(u)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let u=e[a];if(u[0]===S&&u[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(u=>u[0]===j||u[0]===K);if(a.length===0)return;t=a}t=this._frameBatch(t);let s=null;for(let a=0;a<t.length;a++){let u=t[a],d=u[0];if(d!==J&&d!==Z){s?.push(u);continue}if(u.length<2)throw new Error(`Node "${this.name}": [[${d===J?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let l=!0;if(this._pausable!==!1){let g=u[1];if(d===J)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(g),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(g))l=!1;else if(this._pauseLocks.delete(g),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let h=this._pauseBuffer;this._pauseBuffer=[],this._emit(h)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}l?s?.push(u):s==null&&(s=t.slice(0,a))}if(s!=null){if(s.length===0)return;t=s}if(this._hasMeta&&t.some(a=>a[0]===j))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(Xe)}catch{}let{finalMessages:o,equalsError:i}=this._updateState(t);if(o.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,u=[];for(let d of o)a(d[0])===3?this._pauseBuffer.push(d):u.push(d);u.length>0&&this._dispatchOrAccumulate(u)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[S,i]])}_updateState(e){let t=this._config.tierOf,r,s,o=-1,i=0;for(let l of e)t(l[0])===3&&i++;let a=i<=1,u=-1;if(this._versioning!=null&&i>1){for(let l=e.length-1;l>=0;l--)if(e[l][0]===G){u=l;break}}for(let l=0;l<e.length;l++){let g=e[l],h=g[0];if(h===G){if(g.length>=2){let f=!1;if(a&&this._cached!==void 0)try{f=this._equals(this._cached,g[1])}catch(c){s=this._wrapFnError("equals threw",c),o=l;break}if(f){r==null&&(r=e.slice(0,l)),r.push(Ke),this._status="resolved";continue}this._cached=g[1],this._versioning!=null&&(u<0||l===u)&&Ct(this._versioning,g[1],this._hashFn)}this._status="settled",r?.push(g)}else if(r?.push(g),h===U)this._status="dirty";else if(h===q)this._status="resolved";else if(h===F){this._status="completed";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(h===S){this._status="errored";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(h===K){if(this._cached!==void 0){let c=this._config.rigorRecorder;if(c!=null)try{c.onNonVacuousInvalidate(this,this._cached)}catch{}}this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let c=f.invalidate;if(typeof c=="function")try{c()}catch{}}}else h===j&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let d=o>=0?r??e.slice(0,o):r??e;return s!=null?{finalMessages:d,equalsError:s}:{finalMessages:d}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let r of t)r(e)};_dispatchOrAccumulate(e){if(wt()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],ce(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}Ae(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);Ae(this._deliverToSinks,t,this._config.tierOf)}},It=n=>Array.isArray(n),it=n=>typeof n=="object"&&n!=null&&!Array.isArray(n)});function se(n,e){return re([],{...e,initial:n})}function me(n,e){return re((r,s,o)=>n(s,o)??void 0,{describeKind:"producer",...e})}function be(n,e,t){return re(n,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);o.emit(e(a,i))},{describeKind:"derived",...t})}function Ft(n,e,t){return re(n,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);return e(a,o,i)??void 0},{describeKind:"effect",...t})}var $e=V(()=>{"use strict";ge()});function at(n,e){if(e!=null&&e.length>0)return new Set(e);switch(n){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;case"spec":return new Set(["type","deps","meta","value"]);default:return new Set(["type","deps"])}}function Rn(n){return n._describeKind!=null?n._describeKind:n._deps.length>0?"derived":n._fn!=null?"producer":"state"}function ut(n,e){let t={factory:n};return e!==void 0&&(t.factoryArgs=e),t}function An(n){let e={};for(let[t,r]of Object.entries(n.meta))try{e[t]=r.cache}catch{}return e}function dt(n,e,t){let r=e==null,s=!r&&e!=null?[...e].filter(l=>l.startsWith("meta.")).map(l=>l.slice(5)):null,o=r||e.has("meta")||s!=null&&s.length>0,i="state",a=[];n instanceof $&&(i=Rn(n),a=n._deps.map(l=>l.node.name??""));let u={type:i,deps:a};(r||e.has("status"))&&(u.status=n.status);let d=n instanceof $?n._guard:void 0;if(o){let l={...An(n)};if(d!=null&&l.access===void 0&&(l.access=tt(d)),s!=null&&s.length>0&&!e.has("meta")){let g={};for(let h of s)h in l&&(g[h]=l[h]);u.meta=g}else u.meta=l}if(n.name!=null&&(u.name=n.name),(r||e.has("value"))&&(!t||i==="state")){n.status==="sentinel"&&(u.sentinel=!0);try{u.value=n.cache}catch{}}if((r||e.has("v"))&&n.v!=null){let l={id:n.v.id,version:n.v.version};"cid"in n.v&&(l.cid=n.v.cid,l.prev=n.v.prev),u.v=l}return(r||e.has("guard"))&&d!=null&&(u.guard=tt(d)),(r||e.has("lastMutation"))&&n.lastMutation!=null&&(u.lastMutation=n.lastMutation),u}var ct=V(()=>{"use strict";Ne();ge()});function oe(n){return n.subscribe(()=>{})}var Lt=V(()=>{"use strict"});var lt=V(()=>{"use strict";Lt()});var Ie,Ut=V(()=>{"use strict";Ie=class{_timer;_gen=0;start(e,t){this.cancel(),this._gen+=1;let r=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,r===this._gen&&t()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var Oe,Ht=V(()=>{"use strict";Oe=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}}});function on(n,e,t){return{[n]:!0,[`${n}_type`]:e,...t??{}}}var an=V(()=>{"use strict"});var Xn={};fn(Xn,{feedback:()=>Yn,funnel:()=>Kn,scorer:()=>Jn});module.exports=hn(Xn);Se();ne();ge();$e();ne();ct();$e();function jt(n){return{describeKind:"derived",...n}}function Vt(...n){return n.length===0?me(e=>{e.down([[F]])},{...jt(),meta:{...ut("merge")}}):me(e=>{let t=n.length,r=0,s=[];for(let o of n){let i=o.subscribe(a=>{for(let u of a)u[0]===G?e.emit(u[1]):u[0]===F?(r+=1,r>=t&&e.down([[F]])):u[0]===S&&e.down([u])});s.push(i)}return()=>{for(let o of s)o()}},{...jt(),meta:{...ut("merge")}})}et();Se();Me();Ne();ne();ct();ge();$e();Me();function ft(n,e){if(Object.is(n,e))return!0;if(n==null||e==null||typeof n!="object"||typeof e!="object")return!1;if(Array.isArray(n)){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let o=0;o<n.length;o++)if(!ft(n[o],e[o]))return!1;return!0}if(Array.isArray(e))return!1;let t=Object.keys(n),r=Object.keys(e);if(t.length!==r.length)return!1;let s=new Set(r);for(let o of t)if(!s.has(o)||!ft(n[o],e[o]))return!1;return!0}function Bt(n,e){return`${n}\0${e}`}function pt(n,e){let t=[],r=new Set(n.subgraphs),s=new Set(e.subgraphs),o=[];for(let p of s)r.has(p)||o.push(p);o.sort();for(let p of o)t.push({type:"subgraph-mounted",path:p});let i=new Set(Object.keys(n.nodes)),a=new Set(Object.keys(e.nodes)),u=[];for(let p of a)i.has(p)||u.push(p);u.sort();for(let p of u)t.push({type:"node-added",path:p,node:{...e.nodes[p]}});let d=[];for(let p of a){if(!i.has(p))continue;let _=n.nodes[p]?.meta,y=e.nodes[p]?.meta;_==null&&y==null||ft(_??{},y??{})||d.push(p)}d.sort();for(let p of d)t.push({type:"node-meta-changed",path:p,prevMeta:n.nodes[p]?.meta??{},nextMeta:e.nodes[p]?.meta??{}});let l=new Map;for(let p of n.edges)l.set(Bt(p.from,p.to),p);let g=new Map;for(let p of e.edges)g.set(Bt(p.from,p.to),p);let h=[];for(let[p,_]of g)l.has(p)||h.push(_);h.sort((p,_)=>p.from<_.from?-1:p.from>_.from?1:p.to<_.to?-1:p.to>_.to?1:0);for(let p of h)t.push({type:"edge-added",from:p.from,to:p.to});let f=[];for(let[p,_]of l)g.has(p)||f.push(_);f.sort((p,_)=>p.from<_.from?-1:p.from>_.from?1:p.to<_.to?-1:p.to>_.to?1:0);for(let p of f)t.push({type:"edge-removed",from:p.from,to:p.to});let c=[];for(let p of i)a.has(p)||c.push(p);c.sort();for(let p of c)t.push({type:"node-removed",path:p});let m=[];for(let p of r)s.has(p)||m.push(p);m.sort();for(let p of m)t.push({type:"subgraph-unmounted",path:p});return{events:t,flushedAt_ns:X()}}lt();Ut();Ht();Qe();function zt(n,e,t,r={}){let s=e in n.nodes,o=t in n.nodes;if(!s)return Fe(e,t,"no-such-from");if(!o)return Fe(e,t,"no-such-to");let i=r.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(r.findCycle===!0){let d=Sn(n,e,r);if(d!=null)return d}let u=Le(e,n.nodes[e],0,r);return je(e,t,[u])}if(i===0)return Fe(e,t,"no-path");let a=Wt(n,e,t,i);return a.found?je(e,t,qt(n,a.pathOrder,r)):Fe(e,t,a.truncated?"max-depth-exceeded":"no-path")}function Wt(n,e,t,r){let s=new Map,o=[{path:t,depth:0}],i=new Set([t]),a=0,u=!1;for(;a<o.length;){let g=o[a++];if(g.path===e)break;if(r!=null&&g.depth>=r){let m=n.nodes[g.path];m?.deps&&m.deps.length>0&&(u=!0);continue}let h=n.nodes[g.path];if(h==null)continue;let f=h.deps??[],c=new Map;for(let m=0;m<f.length;m++){let p=f[m];if(!p)continue;let _=c.get(p);_==null&&(_=[],c.set(p,_)),_.push(m)}for(let[m,p]of c)i.has(m)||(i.add(m),s.set(m,{from:g.path,depIndices:p}),o.push({path:m,depth:g.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:u};let d=[{path:e}],l=e;for(;l!==t;){let g=s.get(l);if(g==null)return{found:!1,pathOrder:[],truncated:!1};d[d.length-1].depIndices=g.depIndices,d.push({path:g.from}),l=g.from}return{found:!0,pathOrder:d,truncated:!1}}function Sn(n,e,t){let r=n.nodes[e];if(r==null)return null;let s=r.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=Le(e,r,0,t);a.dep_index=o[0];let u=Le(e,r,1,t);return je(e,e,[a,u])}let i=null;for(let a=0;a<s.length;a++){let u=s[a];if(!u||u===e)continue;let d=Wt(n,u,e,t.maxDepth);d.found&&(i==null||d.pathOrder.length<i.pathOrder.length)&&(i=d,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...d.pathOrder],truncated:!1})}return i==null?null:je(e,e,qt(n,i.pathOrder,t))}function qt(n,e,t){return e.map((r,s)=>{let o=n.nodes[r.path],i=Le(r.path,o,s,t);return r.depIndices!=null&&r.depIndices.length>0&&(i.dep_index=r.depIndices[0],r.depIndices.length>1&&(i.dep_indices=[...r.depIndices])),i})}function Le(n,e,t,r){let s={path:n,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 o=r.annotations?.get(n)??e.annotation;o!=null&&(s.annotation=o);let i=r.lastMutations?.get(n)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function je(n,e,t){return Kt(n,e,!0,"ok",t)}function Fe(n,e,t){return Kt(n,e,!1,t,[])}function Kt(n,e,t,r,s){let o=Dn(n,e,t,r,s);return{from:n,to:e,found:t,reason:r,steps:s,text:o,toJSON(){return{from:n,to:e,found:t,reason:r,steps:s}}}}function Dn(n,e,t,r,s){if(!t)switch(r){case"no-such-from":return`explainPath: no node named "${n}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${n}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${n}" to "${e}"`}let o=[`Causal path: ${n} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let u=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(u),"value"in i&&o.push(` value: ${Cn(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let d=i.lastMutation.actor;o.push(` actor: ${d.type}${d.id?`:${d.id}`:""}`)}}return o.join(`
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function en(n){if(n.version!==ye)throw new Error(`unsupported snapshot version ${String(n.version)} (expected ${ye})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in n))throw new Error(`snapshot missing required key "${e}"`);if(typeof n.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof n.nodes!="object"||n.nodes===null||Array.isArray(n.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(n.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(n.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function Fn(n,e){let t=new WeakMap,r=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,u=o.constructor;if(a!==u)return!1;if(s instanceof Date)return s.getTime()===o.getTime();if(s instanceof RegExp)return s.source===o.source&&s.flags===o.flags;if(Array.isArray(s)){let h=o;if(s.length!==h.length)return!1;for(let f=0;f<s.length;f++)if(!r(s[f],h[f]))return!1;return!0}if(s instanceof Map){let h=o;if(s.size!==h.size)return!1;for(let[f,c]of s)if(!h.has(f)||!r(c,h.get(f)))return!1;return!0}if(s instanceof Set){let h=o;if(s.size!==h.size)return!1;for(let f of s){let c=!1;for(let m of h)if(r(f,m)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(s)){let h=s,f=o;if(h.length!==f.length)return!1;for(let c=0;c<h.length;c++)if(h[c]!==f[c])return!1;return!0}let d=Object.keys(s),l=Object.keys(o);if(d.length!==l.length)return!1;let g=new Set(l);for(let h of d)if(!g.has(h)||!r(s[h],o[h]))return!1;return!0};return r(n,e)}function Ln(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ve(n){let e="^";for(let t=0;t<n.length;t+=1){let r=n[t];if(r==="*"){e+=".*";continue}if(r==="?"){e+=".";continue}if(r==="["){let s=n.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let o=n.slice(t+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,t=s;continue}e+=Ln(r)}return e+="$",new RegExp(e)}var jn={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"},Vn={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function ht(n){if(typeof n=="string")return JSON.stringify(n);if(typeof n=="number"||typeof n=="boolean"||n==null)return String(n);try{return JSON.stringify(n)}catch{return"[unserializable]"}}function Bn(n){return n==="none"?Vn:n==="ansi"||n==null?jn:{data:n.data??"",dirty:n.dirty??"",resolved:n.resolved??"",invalidate:n.invalidate??"",pause:n.pause??"",resume:n.resume??"",complete:n.complete??"",error:n.error??"",teardown:n.teardown??"",derived:n.derived??"",path:n.path??"",reset:n.reset??""}}function tn(n){if(n==null)return{};let e=n.detail;return e==="full"?{...n,structured:n.structured??!0,timeline:n.timeline??!0,causal:n.causal??!0,derived:n.derived??!0}:e==="minimal"?{...n,structured:n.structured??!0}:n.format==="stage-log"?{...n,structured:n.structured??!0,timeline:n.timeline??!0}:n}function Un(n,e,t){for(let r=0;r<n.length;r++){let s=n.charCodeAt(r);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${n}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${r})`)}}function gt(n,e,t){if(n==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(n.includes(M))throw new Error(`Graph "${e}": ${t} "${n}" must not contain '${M}' (path separator)`);if(n===Y)throw new Error(`Graph "${e}": ${t} name "${Y}" is reserved for meta companion paths`);Un(n,e,t)}function Hn(n,e){if(n==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=n.split(M);for(let r of t)if(r==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function zn(n,e){let t=!1;for(let s of n)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?n.filter(s=>e.isMetaPassthrough(s[0])):n}function sn(n){for(let e of n._mounts.values())sn(e);for(let e of n._nodes.values())try{e.down([[j]],{internal:!0})}catch{}}var ve=class n{name;opts;config;_nodes=new Map;_nodeToName=new WeakMap;_mounts=new Map;_parent=void 0;_storageDisposers=new Set;_disposers=new Set;_destroyed=!1;_topology;_topologyEmitters=new Set;_factory;_factoryArgs;constructor(e,t){if(e==="")throw new Error("Graph name must be non-empty");if(e.includes(M))throw new Error(`Graph name must not contain '${M}' (got "${e}")`);if(e===Y)throw new Error(`Graph name "${Y}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??he,this._traceRing=new Oe(t?.traceCapacity??1e3),t?.versioning!=null&&this.setVersioning(t.versioning),typeof t?.factory=="string"&&(this._factory=t.factory,t.factoryArgs!==void 0&&(this._factoryArgs=t.factoryArgs))}tagFactory(e,t){return this._factory=e,this._factoryArgs=t,this}ancestors(e=!0){let t=[],r=e?this:this._parent;for(;r!=null;)t.push(r),r=r._parent;return t}get topology(){return this._topology==null&&(this._topology=me(e=>{let t=r=>{e.emit(r)};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)}nameOf(e){return this._nodeToName.get(e)}add(e,t){let r=e.name,s=t?.name??r;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 o=s,i=t?.annotation;if(gt(o,this.name,"add"),this._mounts.has(o))throw new Error(`Graph "${this.name}": name "${o}" is already a mount point`);if(this._nodes.has(o))throw new Error(`Graph "${this.name}": node "${o}" 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(o,e),this._nodeToName.set(e,o),this._emitTopology({kind:"added",name:o,nodeKind:"node"}),i!=null&&(this._annotations.set(o,i),this.config.inspectorEnabled&&this._traceRing.push({path:o,annotation:i,timestamp_ns:X()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof $&&t._applyVersioning(e)}remove(e){gt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let o={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,u]of i)a.includes(`${M}${Y}${M}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...t._collectSubgraphs(`${e}${M}`)),this._mounts.delete(e),t._parent=void 0,sn(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}let r=this._nodes.get(e);if(!r)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(r),r.down([[j]],{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 o=Ve(e);return i=>o.test(i)})(),r={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>t(o));for(let o of s){let i=this.remove(o);r.nodes.push(...i.nodes),r.mounts.push(...i.mounts)}return r.nodes.sort(),r.mounts.sort(),r}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,r=0;return{[Symbol.iterator](){return this},next(){if(r>=e.length)return{value:void 0,done:!0};let s=e[r++];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(M))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,r){let s=r?.internal===!0;this.node(e).down([[G,t]],{actor:r?.actor,internal:s,delivery:"write"})}setAll(e,t){let r=Symbol.iterator in e?e:Object.entries(e);Re(()=>{for(let[s,o]of r)this.set(s,o,t)})}invalidate(e,t){let r=t?.internal===!0;this.node(e).down([[K]],{actor:t?.actor,internal:r,delivery:"write"})}error(e,t,r){let s=r?.internal===!0;this.node(e).down([[S,t]],{actor:r?.actor,internal:s,delivery:"write"})}complete(e,t){let r=t?.internal===!0;this.node(e).down([[F]],{actor:t?.actor,internal:r,delivery:"write"})}edges(e){let t=e?.recursive===!0,r=new Map;if(!t){for(let[u,d]of this._nodes)r.set(d,u);let a=[];for(let[u,d]of this._nodes)if(d instanceof $)for(let l of d._deps){let g=r.get(l.node);g!=null&&a.push([g,u])}return a.sort((u,d)=>u[0]<d[0]?-1:u[0]>d[0]?1:u[1]<d[1]?-1:u[1]>d[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,u]of s)o.set(u,a);let i=[];for(let[a,u]of s)if(u instanceof $)for(let d of u._deps){let l=o.get(d.node);l!=null&&i.push([l,a])}return i.sort((a,u)=>a[0]<u[0]?-1:a[0]>u[0]?1:a[1]<u[1]?-1:a[1]>u[1]?1:0),i}mount(e,t){if(t===void 0){let s=new n(e);return this.mount(e,s)}if(typeof t=="function"){let s=new n(e);return t(s),this.mount(e,s)}let r=t;if(gt(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(r===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(r._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${r._parent.name}"`);for(let s=this;s!=null;s=s._parent)if(s===r)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,r),r._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),r}resolve(e){let t=Hn(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 r=t[0],s=t.slice(1);if(s.length===0){let a=this._nodes.get(r);if(a)return a;throw this._mounts.has(r)?new Error(`Graph "${this.name}": path ends at subgraph "${r}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${r}"`)}let o=this._nodes.get(r);if(o&&s.length>0&&s[0]===Y)return this._resolveMetaChainFromNode(o,s,t.join(M));let i=this._mounts.get(r);if(!i)throw this._nodes.has(r)?new Error(`Graph "${this.name}": "${r}" is a node; trailing path "${s.join(M)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${r}"`);return i.resolve(s.join(M))}_resolveMetaChainFromNode(e,t,r){let s=e,o=0,i=[...t];for(;o<i.length;){if(i[o]!==Y)throw new Error(`Graph "${this.name}": expected ${Y} segment in meta path "${r}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${Y} in "${r}"`);let a=i[o+1],u=s.meta[a];if(!u)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${r}"`);s=u,o+=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 r=[];if(this._signalDeliver(e,t??{},new Set,r),r.length>0)throw r[0]}_signalDeliver(e,t,r,s){for(let u of this._mounts.values())u._signalDeliver(e,t,r,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=zn(e,this.config);for(let u of[...this._nodes.keys()].sort()){let d=this._nodes.get(u);if(!r.has(d)){r.add(d);try{d.down(e,i)}catch(l){if(l instanceof W)throw l;s.push(l)}a.length!==0&&this._signalMetaSubtree(d,a,r,i,s)}}}_signalMetaSubtree(e,t,r,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!r.has(a)){r.add(a);try{a.down(t,s)}catch(u){if(u instanceof W)throw u;o.push(u)}this._signalMetaSubtree(a,t,r,s,o)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=$n(e?.actor),r=e?.filter;if(e?.detail!=null&&e?.fields!=null)throw new TypeError("Graph.describe(): pass either `detail` or `fields`, not both. `detail: 'spec'` is the canonical spec projection; use `fields` only when you need a custom subset.");let s=at(e?.detail,e?.fields),o=e?.detail==="spec",i=s,a=[];this._collectObserveTargets("",a);let u=new Map;for(let[v,w]of a)u.set(w,v);let d=[];{let v=a.map(([,x])=>x),w=new Set(u.values()),O=0;for(;v.length>0;){let x=v.shift();if(x instanceof $)for(let k of x._deps){let E=k.node;if(u.has(E))continue;let R=E.name??"",N=R;if(!N||w.has(N))if(R){let L=2;for(;w.has(`${R}#${L}`);)L++;N=`${R}#${L}`}else for(N=`__internal__/${O++}`;w.has(N);)N=`__internal__/${O++}`;u.set(E,N),w.add(N),d.push([N,E]),v.push(E)}}}let l=[...a,...d],g={};for(let[v,w]of l){if(t!=null&&!w.allowsObserve(t))continue;let O=dt(w,i,o),x=w instanceof $?w._deps.map(N=>u.get(N.node)??N.node.name??""):[],{name:k,...E}=O,R={...E,deps:x};if(!o){let N=this._annotations.get(v);N!=null&&(R.annotation=N)}if(r!=null)if(typeof r=="function"){let N=r;if(!(N.length>=2?N(v,R):N(R)))continue}else{let N=!0;for(let[L,P]of Object.entries(r)){let D=L==="deps_includes"?"depsIncludes":L==="meta_has"?"metaHas":L;if(D==="depsIncludes"){if(!R.deps.includes(String(P))){N=!1;break}continue}if(D==="metaHas"){if(!Object.hasOwn(R.meta??{},String(P))){N=!1;break}continue}if(R[D]!==P){N=!1;break}}if(!N)continue}g[v]=R}let h=new Set(Object.keys(g)),f=[];for(let[v,w]of l)if(w instanceof $)for(let O of w._deps){let x=u.get(O.node);x!=null&&f.push([x,v])}f.sort((v,w)=>v[0]<w[0]?-1:v[0]>w[0]?1:v[1]<w[1]?-1:v[1]>w[1]?1:0);let c=f.map(([v,w])=>({from:v,to:w}));(t!=null||r!=null)&&(c=c.filter(v=>h.has(v.from)&&h.has(v.to)));let m=this._collectSubgraphs(""),p=t!=null||r!=null?m.filter(v=>{let w=`${v}${M}`;return[...h].some(O=>O===v||O.startsWith(w))}):m,_=this,y=e;return{name:this.name,nodes:g,edges:c,subgraphs:p,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(v){let w={...y};return Array.isArray(v)?(w.fields=v,w.detail=void 0):(w.detail=v,w.fields=void 0),_.describe(w)}}}_collectSubgraphs(e){let t=[];for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${r}`;t.push(s),t.push(...this._mounts.get(r)._collectSubgraphs(`${s}${M}`))}return t}resourceProfile(e){return Jt(this,e)}reachable(e,t,r={}){return r.withDetail===!0?nn(this.describe(),e,t,{...r,withDetail:!0}):nn(this.describe(),e,t,r)}explain(e,t,r){return r?.reactive===!0?this._explainReactive(e,t,r):this._explainStatic(Q(e),Q(t),{...r?.maxDepth!==void 0?{maxDepth:Zt(r.maxDepth)}:{},...r?.findCycle!==void 0?{findCycle:Qt(r.findCycle)}:{}})}_explainStatic(e,t,r){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,u]of Object.entries(s.nodes))u.lastMutation!=null&&i.set(a,u.lastMutation);return zt(s,e,t,{...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},r=e.reactiveName??"describe",s=0,o=se(s,{name:`${r}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ce(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(y=>{let b=y.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[],h=new WeakSet,f=y=>{if(h.has(y)||u)return;h.add(y);let b=y.topology.subscribe(v=>{for(let w of v){if(w[0]!==G)continue;let O=w[1];if(d(),O.kind==="added"&&O.nodeKind==="mount"){let x=y._mounts.get(O.name);x!=null&&f(x)}}});g.push(b);for(let v of y._mounts.keys()){let w=y._mounts.get(v);w!=null&&f(w)}};f(this);let c,m=e.actor;rn(m)&&(c=m.subscribe(y=>{let b=!1,v=!1;for(let w of y){let O=w[0];O===G?b=!0:(O===F||O===S||O===j)&&(v=!0)}b&&d(),v&&(c?.(),c=void 0,d())}));let p;try{p=be([o],()=>this.describe(t),{name:r,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(y,b)=>y===b})}catch(y){l(),c?.();for(let b of g)b();throw i.dispose(),y}let _=oe(p);return{node:p,dispose(){u=!0,l(),c?.();for(let y of g)y();g.length=0,i.dispose(),_()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},r=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(t),i=pt(s,o),a=se(i,{name:r,meta:{domain:"audit",kind:"describe-diff"},equals:(h,f)=>h===f}),u=this._describeReactive({...e,reactiveName:void 0}),d=!1,l=u.node.subscribe(h=>{if(!d)for(let f of h){if(f[0]!==G)continue;let c=f[1],m=pt(o,c);o=c,m.events.length!==0&&a.emit(m)}}),g=oe(a);return{node:a,dispose(){d=!0,l(),u.dispose(),a.down([[j,"describe-diff disposed"]]),g()}}}_explainReactive(e,t,r){let s=0,o=se(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ce(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(y=>{let b=y.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[];e!=null&&ie(e)&&g.push(e),t!=null&&ie(t)&&g.push(t),r?.maxDepth!=null&&ie(r.maxDepth)&&g.push(r.maxDepth),r?.findCycle!=null&&ie(r.findCycle)&&g.push(r.findCycle);let h=()=>{for(let y of g)if(y.cache===void 0)return!1;return!0},f=()=>{let y=Q(e),b=Q(t);return{from:y,to:b,found:!1,reason:"pending",steps:[],text:"(awaiting reactive args)",toJSON:()=>({from:y,to:b,found:!1,reason:"pending",steps:[]})}},c;try{c=be([o],()=>{if(!h())return f();let y=Q(e),b=Q(t),v={...r?.maxDepth!==void 0?{maxDepth:Zt(r.maxDepth)}:{},...r?.findCycle!==void 0?{findCycle:Qt(r.findCycle)}:{}};return this._explainStatic(y,b,v)},{name:r?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:Q(e),to:Q(t)},equals:(y,b)=>y.found===b.found&&y.reason===b.reason&&y.steps.length===b.steps.length&&qn(y.steps,b.steps)})}catch(y){throw l(),i.dispose(),y}let m=oe(c),p=[],_=y=>{let b;return b=y.subscribe(v=>{let w=!1,O=!1;for(let x of v){let k=x[0];k===G?w=!0:(k===F||k===S||k===j)&&(O=!0)}(w||O)&&d(),O&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let y of g)p.push(_(y));return{node:c,dispose(){u=!0,l();for(let y of p)y?.();p.length=0,i.dispose(),m()}}}_pathsMatching(e){let t=Ve(e),r=[];return this._collectObserveTargets("",r),r.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${M}${r}`;this._mounts.get(r)._collectObserveTargets(s,t)}for(let r of[...this._nodes.keys()].sort()){let s=this._nodes.get(r),o=e===""?r:`${e}${M}${r}`;t.push([o,s]),this._appendMetaObserveTargets(o,s,t)}}_appendMetaObserveTargets(e,t,r){for(let s of Object.keys(t.meta).sort()){let o=t.meta[s],i=`${e}${M}${Y}${M}${s}`;r.push([i,o]),this._appendMetaObserveTargets(i,o,r)}}observe(e,t){let r=typeof e=="string",o=tn(r?t:e);if(o.reactive===!0)return this._observeReactive(r?e:void 0,o);let i=o.structured===!0||o.timeline===!0||o.causal===!0||o.derived===!0||o.detail==="minimal"||o.detail==="full"||o.format!=null,a=o.actor;if(r){let l=e,g=this.resolve(l);if(a!=null&&!g.allowsObserve(a))throw new W({actor:a,action:"observe",nodeName:l});return i?this._buildStructuredObserver([[l,g]],o,"one"):{subscribe(h){return g.subscribe(h)},up(h){try{g.up?.(h)}catch(f){if(f instanceof W)return;throw f}}}}let u=[];this._collectObserveTargets("",u),u.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let d=a==null?u:u.filter(([,l])=>l.allowsObserve(a));return i?this._buildStructuredObserver(d,o,"all"):{subscribe:l=>{let g=d.map(([h,f])=>f.subscribe(c=>{l(h,c)}));return()=>{for(let h of g)h()}},up:(l,g)=>{try{this.resolve(l).up?.(g)}catch(h){if(h instanceof W)return;throw h}}}}_observeReactive(e,t){let r=t.tiers,s=r!=null?new Set(r):null,o=t.reactiveName??"observe";return me(i=>{let a=[],u=!1,d=!1,l=()=>{if(a.length===0||d)return;let m={events:a.slice(),flushedAt_ns:X()};a.length=0,i.emit(m)},g={...t,reactive:!1,structured:!0,timeline:!0},h=e!=null?this.observe(e,g):this.observe(g),f=m=>{d||(a.push(m),!u&&(u=!0,ce(()=>{u=!1,l()})))};for(let m of h.events)f(m);let c=h.onEvent(f);return()=>{d=!0,c(),h.dispose()}},{name:o,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,r){let s=r==="one"?e[0]?.[0]:void 0,o=i=>{if(r==="one"&&s!=null){let l=this.resolve(s);return this._buildStructuredObserver([[s,l]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let u=i.actor,d=u==null?a:a.filter(([,l])=>l.allowsObserve(u));return this._buildStructuredObserver(d,i,"all")};return this._createObserveResult(e,t,o)}_createObserveResult(e,t,r){let s=t.timeline===!0,o=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",u=this.config.inspectorEnabled,d=(o||i)&&u,l=t.maxEvents,g=l!=null&&l>0?new Oe(l):null,h=[],f=new Set,c=t.tiers!=null?new Set(t.tiers):null,m={},p=new Set,_=0,y=0,b=0,v=0,w=0,O=0,x=!1,k=!1,E=0,R=new Map,N=new Map,L=new Map,P=T=>{if(!(c!=null&&!c.has(T.type))){g?g.push(T):h.push(T);for(let C of f)C(T)}},D=T=>c==null||c.has(T),ae=()=>s?{timestamp_ns:X(),in_batch:Ee(),batch_id:E}:{},Be=(T,C)=>{if(!(!d||!(T instanceof $)))return T._setInspectorHook(H=>{if(H.kind==="dep_message")R.set(T,H.depIndex);else if(H.kind==="run"){let we=H.batchData.map((A,B)=>A!=null&&A.length>0?A.at(-1):H.prevData[B]);N.set(T,we);let z=H.batchData.map(A=>A!=null?[...A]:void 0);L.set(T,z),i&&P({type:"derived",path:C,dep_values:we,dep_batches:z,...ae()})}})},xe=T=>{let C=R.get(T),H=N.get(T);if(!o||H==null)return{};let z=(C!=null&&C>=0&&T instanceof $?T._deps[C]:void 0)?.node,A=z?.v,B=L.get(T);return{trigger_dep_index:C,trigger_dep_name:z?.name,...A!=null?{trigger_version:{id:A.id,version:A.version}}:{},dep_values:[...H],...B!=null?{dep_batches:B}:{}}},bt=[],yt=[];for(let[T,C]of e){let H=Be(C,T);H&&bt.push(H),yt.push(C.subscribe(we=>{E++;for(let z of we){let A=z[0],B=ae();if(A===G){m[T]=z[1];let We=C instanceof $?C.lastMutation?.actor??pe:pe;P({type:"data",path:T,data:z[1],actor:We,...B,...xe(C)})}else if(a)A===U?D("dirty")&&_++:A===q?D("resolved")&&y++:A===K?D("invalidate")&&b++:A===J?D("pause")&&v++:A===Z?D("resume")&&w++:A===j?D("teardown")&&O++:A===F&&!p.has(T)?D("complete")&&(x=!0):A===S&&D("error")&&(k=!0,p.add(T));else if(A===U)D("dirty")&&_++,P({type:"dirty",path:T,...B});else if(A===q)D("resolved")&&y++,P({type:"resolved",path:T,...B,...xe(C)});else if(A===K)D("invalidate")&&b++,P({type:"invalidate",path:T,...B});else if(A===J)D("pause")&&v++,P({type:"pause",path:T,lockId:z[1],...B});else if(A===Z)D("resume")&&w++,P({type:"resume",path:T,lockId:z[1],...B});else if(A===F)D("complete")&&!p.has(T)&&(x=!0),P({type:"complete",path:T,...B});else if(A===S){D("error")&&(k=!0,p.add(T));let We=C instanceof $?C.lastMutation?.actor??pe:pe;P({type:"error",path:T,data:z[1],actor:We,...B})}else A===j&&(D("teardown")&&O++,P({type:"teardown",path:T,...B}))}}))}let Ue=!1,He=()=>{if(!Ue){Ue=!0;for(let T of yt)T();for(let T of bt)T();for(let T of ke)T({value:void 0,done:!0});ke.length=0}},ze=[],ke=[];f.add(T=>{let C=ke.shift();C?C({value:T,done:!1}):ze.push(T)});let vt={get values(){return m},get dirtyCount(){return _},get resolvedCount(){return y},get invalidateCount(){return b},get pauseCount(){return v},get resumeCount(){return w},get teardownCount(){return O},get events(){return g?g.toArray():[...h]},get anyCompletedCleanly(){return x},get anyErrored(){return k},get completedWithoutErrors(){return x&&!k},onEvent(T){return f.add(T),()=>f.delete(T)},dispose:He,expand(T){He();let C={...t};return typeof T=="string"?C.detail=T:Object.assign(C,T),r(tn(C))},[Symbol.asyncIterator](){return{next(){return ze.length>0?Promise.resolve({value:ze.shift(),done:!1}):Ue?Promise.resolve({value:void 0,done:!0}):new Promise(T=>ke.push(T))},return(){return He(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(vt,t),vt}_attachFormatLogger(e,t){let r=t.format;if(r==null)return;let s=t.logger??(c=>console.log(c)),o=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=o==null&&i==null?()=>!0:c=>(o==null||o.has(c))&&(i==null||!i.has(c)),u=Bn(t.theme),d=r==="stage-log"?X():0,l=c=>c==null?"":t.stageLabels?.[c]??c,g=(c,m)=>c.length>m?`${c.slice(0,m-1)}\u2026`:c,h=c=>c.type==="data"||c.type==="error"?g(ht(c.data),120):"",f=c=>{if(r==="stage-log"){let x=(X()-d)/1e9,k=l(c.path).padEnd(9);if(c.type==="data"){let E=h(c);return`[${x.toFixed(3)}s] ${k} \u2190${E?` ${E}`:""}`}if(c.type==="error"){let E=h(c);return`[${x.toFixed(3)}s] ${k} \u2717${E?` ${E}`:""}`}return c.type==="complete"?`[${x.toFixed(3)}s] ${k} \u25A0 complete`:`[${x.toFixed(3)}s] ${k} ${c.type}`}if(r==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let m=u[c.type]??"",p=c.path?`${u.path}${c.path}${u.reset} `:"",_=c.type==="data"||c.type==="error",y=c.type==="pause"||c.type==="resume",b=_?` ${ht(c.data)}`:y?` ${ht(c.lockId)}`:"",v=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,w=v?.trigger_dep_name!=null?` <- ${v.trigger_dep_name}`:v?.trigger_dep_index!=null?` <- #${v.trigger_dep_index}`:"",O=c.in_batch?" [batch]":"";return`${p}${m}${c.type.toUpperCase()}${u.reset}${b}${w}${O}`};e.onEvent(c=>{a(c.type)&&s(f(c),c)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){Xt(this._disposers,this.name),this.signal([[j]],{internal:!0}),Xt(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,this._destroyed=!0}get destroyed(){return this._destroyed}_destroyClearOnly(){for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}snapshot(e){let{expand:t,...r}=this.describe({detail:"full"}),s={};for(let a of Object.keys(r.nodes).sort()){let{lastMutation:u,guard:d,...l}=r.nodes[a];s[a]=l}let o=[...r.subgraphs].sort(),i={...r,version:1,nodes:s,subgraphs:o};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 xt(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let r=t?.config??he,{codec:s,codecVersion:o,payload:i}=kt(e,r);return s.decode(i,o)}restore(e,t){if(en(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let r=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(o=>Ve(o)),s=t?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(r!==null&&!r.some(a=>a.test(o)))continue;let i=e.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(o,new Error(`restore: slice.value is undefined for "${o}" (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 u=this.tryResolve(o)?.v;if(u!=null&&u.id===i.v.id&&u.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){t?.onError?.(o,a)}}}}}static fromSnapshot(e,t){en(e);let r=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,o=new n(e.name);if(r)return r(o),o.restore(e),o;for(let f of[...e.subgraphs].sort((c,m)=>{let p=c.split(M).length,_=m.split(M).length;return p!==_?p-_:c<m?-1:c>m?1:0})){let c=f.split(M),m=o;for(let p of c)m._mounts.has(p)||m.mount(p,new n(p)),m=m._mounts.get(p)}let i=s?Object.entries(s).map(([f,c])=>({re:Ve(f),factory:c})):[],a=f=>{for(let c of i)if(c.re.test(f))return c.factory},u=f=>{let c=f.split(M),m=c.pop();if(m==null||m.length===0)throw new Error(`invalid snapshot path "${f}"`);let p=o;for(let _ of c){let y=p._mounts.get(_);if(!y)throw new Error(`unknown mount "${_}" in path "${f}"`);p=y}return[p,m]},d=Object.entries(e.nodes).filter(([f])=>!f.includes(`${M}${Y}${M}`)).sort((f,c)=>f[0]<c[0]?-1:f[0]>c[0]?1:0),l=new Map(d),g=new Map,h=!0;for(;l.size>0&&h;){h=!1;for(let[f,c]of[...l.entries()]){let m=c?.deps??[];if(!m.every(w=>g.has(w)))continue;let[p,_]=u(f),y={...c?.meta??{}},b=a(f),v;if(c?.type==="state")v=se(c.value,{meta:y});else{if(b==null)continue;v=b(_,{path:f,type:c.type,value:c.value,meta:y,deps:m,resolvedDeps:m.map(w=>g.get(w))})}p.add(v,{name:_}),g.set(f,v),l.delete(f),h=!0}}if(l.size>0){let f=[...l.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${f}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return o.restore(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let r=e.map(d=>({tier:d,debounceMs:Math.max(0,d.debounceMs??0),compactEvery:Math.max(1,d.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=(d,l)=>{if(d.disposed)return;let g=In(l.nodes);if(d.lastSnapshot!=null&&g!==""&&g===d.lastFingerprint)return;let h=d.seq+1,f=Ce(),p=d.lastSnapshot==null||h%d.compactEvery===0?{name:this.name,mode:"full",snapshot:l,seq:h,timestamp_ns:f,format_version:ye}:{name:this.name,mode:"diff",diff:Wn(d.lastSnapshot,l),seq:h,timestamp_ns:f,format_version:ye};if(d.tier.filter&&!d.tier.filter(p))return;let _;try{_=d.tier.save(p)}catch(y){t.onError?.(y,d.tier);return}if(_&&typeof _.then=="function"){let v=(d.savePending??Promise.resolve()).then(()=>_,()=>_).then(()=>{d.disposed||(d.seq=h,d.lastSnapshot=l,d.lastFingerprint=g)},w=>{t.onError?.(w,d.tier)});d.savePending=v.finally(()=>{d.savePending===v&&(d.savePending=void 0)})}else d.seq=h,d.lastSnapshot=l,d.lastFingerprint=g},o=(d,l)=>{try{s(d,l)}catch(g){t.onError?.(g,d.tier)}},i=(d,l)=>{if(!l.some(c=>{let m=this.config.messageTier(c[0]);return m>=3&&m<5}))return;if(t.filter){let c=this.tryResolve(d);if(c==null)return;let m=dt(c,at("standard"));if(!t.filter(d,m))return}let h,f=()=>(h==null&&(h=this.snapshot()),h);for(let c of r)c.disposed||(c.debounceMs===0?o(c,f()):(c.timer==null&&(c.timer=new Ie),c.timer.start(c.debounceMs,()=>{c.disposed||o(c,this.snapshot())})))},a;if(t.paths!=null){let l=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(g=>{let h=this.tryResolve(g);return h==null?()=>{}:h.subscribe(f=>i(g,f))});a=()=>{for(let g of l)g()}}else a=this.observe().subscribe((d,l)=>i(d,l));let u=()=>{a();for(let d of r)d.disposed=!0,d.timer?.cancel();this._storageDisposers.delete(u)};return this._storageDisposers.add(u),{dispose:u}}async _cascadeRestore(e,t){for(let r of e){let s;try{s=await r.load?.()}catch(i){t?.(i,r);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let o=s;try{if(o.mode==="full"&&o.snapshot!=null)return this.restore(o.snapshot),!0;if(o.version===ye&&o.nodes!=null)return this.restore(o),!0}catch(i){t?.(i,r)}}return!1}static async fromStorage(e,t,r){for(let s of t){let o;try{o=await s.load?.()}catch(u){r?.onError?.(u,s);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let i=o,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===ye&&i.nodes!=null?i:void 0;if(a!=null)try{return n.fromSnapshot(a,r)}catch(u){r?.onError?.(u,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,r){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:X(),...r?.actor!=null?{actor:r.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)),r=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return r}static diff(e,t){let r=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),o=[...s].filter(y=>!r.has(y)).sort(),i=[...r].filter(y=>!s.has(y)).sort(),a=[],u=[];for(let y of r){if(!s.has(y))continue;let b=e.nodes[y],v=t.nodes[y],w=b.v,O=v.v;w!=null&&O!=null&&w.id===O.id&&w.version!==O.version&&u.push({path:y,id:w.id,from:w.version,to:O.version});let x=w!=null&&O!=null&&w.id===O.id&&w.version===O.version;for(let k of["type","status","sentinel"]){let E=b[k],R=v[k];E!==R&&a.push({path:y,field:k,from:E,to:R})}if(!x)for(let k of["value","meta"]){let E=b[k],R=v[k];Fn(E,R)||a.push({path:y,field:k,from:E,to:R})}}let d=y=>`${y.from} ${y.to}`,l=new Set(e.edges.map(d)),g=new Set(t.edges.map(d)),h=t.edges.filter(y=>!l.has(d(y))),f=e.edges.filter(y=>!g.has(d(y))),c=new Set(e.subgraphs),m=new Set(t.subgraphs),p=[...m].filter(y=>!c.has(y)).sort(),_=[...c].filter(y=>!m.has(y)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:u,edgesAdded:h,edgesRemoved:f,subgraphsAdded:p,subgraphsRemoved:_}}};function Wn(n,e){let t=ve.diff(n,e),r={};for(let s of t.nodesAdded){let o=e.nodes[s];o!=null&&(r[s]=o)}return{...t,nodesAddedFull:r}}function nn(n,e,t,r={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return r.withDetail?s:[];if(!r.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=r.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return r.withDetail?s:[];let i=new Map,a=new Map,u=new Map,d=new Map,l=new Set;for(let[b,v]of Object.entries(n.nodes)){if(!b)continue;l.add(b);let w=v.deps??[];i.set(b,w);for(let O of w)O&&(l.add(O),a.has(O)||a.set(O,new Set),a.get(O).add(b))}for(let b of n.edges){if(b==null||typeof b!="object")continue;let v=typeof b.from=="string"?b.from:"",w=typeof b.to=="string"?b.to:"";!v||!w||(l.add(v),l.add(w),d.has(v)||d.set(v,new Set),d.get(v).add(w),u.has(w)||u.set(w,new Set),u.get(w).add(v))}if(!l.has(e))return r.withDetail?s:[];let g=r.both===!0,h=b=>{if(g){let x=i.get(b)??[],k=u.get(b),E=a.get(b),R=d.get(b),N=[...x];return k&&N.push(...k),E&&N.push(...E),R&&N.push(...R),N}if(t==="upstream"){let x=i.get(b)??[],k=u.get(b);return k?[...x,...k]:x}let v=a.get(b),w=d.get(b),O=v?[...v]:[];return w&&O.push(...w),O},f=new Set([e]),c=new Map,m=[{path:e,depth:0}],p=0,_=!1;for(;p<m.length;){let b=m[p++];if(o!=null&&b.depth>=o){h(b.path).length>0&&(_=!0);continue}for(let v of h(b.path))!v||f.has(v)||(f.add(v),c.set(v,b.depth+1),m.push({path:v,depth:b.depth+1}))}let y=[...c.keys()].sort((b,v)=>b<v?-1:b>v?1:0);return r.withDetail?{paths:y,depths:c,truncated:_}:y}function qn(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],s=e[t];if(r.path!==s.path||r.type!==s.type||r.status!==s.status||r.hop!==s.hop||r.dep_index!==s.dep_index||r.annotation!==s.annotation||r.value!==s.value||r.lastMutation!==s.lastMutation)return!1;let o=r.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}an();Ne();ne();function un(n,e){let t=n.cache??0;return t>=e?!1:(n.down([[U],[G,t+1]]),!0)}var rs=Dt((n,e)=>{n("observe"),n("signal"),e("write")});lt();function mt(n,e){return on("reduction",n,e)}function Kn(n,e,t,r){if(e.length===0)throw new RangeError("funnel requires at least one source");if(t.length===0)throw new RangeError("funnel requires at least one stage");let s=new ve(n,r),o=e.length===1?e[0]:Vt(...e);s.add(o,{name:"merged"});let i="merged";for(let a=0;a<t.length;a++){let u=t[a],d=new ve(u.name);u.build(d);try{d.resolve("input")}catch{throw new Error(`funnel stage "${u.name}" must define an "input" node`)}try{d.resolve("output")}catch{throw new Error(`funnel stage "${u.name}" must define an "output" node`)}s.mount(u.name,d);let l=s.resolve(i),g=`${u.name}::input`,h=s.resolve(g),f=`__bridge_${i}\u2192${u.name}_input`,c=Ft([l],([m])=>{h.emit(m)},{name:f});s.add(c,{name:f}),s.addDisposer(oe(c)),i=`${u.name}::output`}return s}function Yn(n,e,t,r){let s=r?.maxIterations??10,o=`__feedback_${e}`,i=se(0,{meta:mt("feedback_counter",{maxIterations:s,feedbackFrom:e,feedbackTo:t})});n.add(i,{name:o});let a=n.resolve(e),u=n.resolve(t),d=`__feedback_effect_${e}`,l=re([],(g,h)=>{let f=a.subscribe(c=>{for(let m of c){let p=m[0];if(p===G){let _=m[1];if(_==null)return;Re(()=>{un(i,s)&&u.emit(_)})}else if(p===F||p===S){let _=p===S&&m.length>1?[S,m[1]]:[p];i.down([_])}}});return()=>f()},{name:d,describeKind:"effect",meta:{...mt("feedback_effect",{feedbackFrom:e,feedbackTo:t}),_internal:!0}});return n.add(l,{name:d}),n.addDisposer(oe(l)),n}function Jn(n,e,t){if(n.length===0)throw new RangeError("scorer requires at least one source");if(n.length!==e.length)throw new RangeError("scorer requires the same number of sources and weights");let r=[...n,...e],s=n.length,o=t?.scoreFns;return be(r,i=>{let a=i.slice(0,s),u=i.slice(s),d=[],l=0;for(let g=0;g<s;g++){let h=a[g]??0,f=u[g]??0,m=(o?.[g]?o[g](h):h)*f;d.push(m),l+=m}return{value:a,score:l,breakdown:d}},{...t?{equals:t.equals,resubscribable:t.resubscribable,resetOnTeardown:t.resetOnTeardown}:{},describeKind:"derived",meta:mt("scorer",t?.meta)})}0&&(module.exports={feedback,funnel,scorer});
|
|
1
|
+
"use strict";var qe=Object.defineProperty;var mn=Object.getOwnPropertyDescriptor;var bn=Object.getOwnPropertyNames;var yn=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(n&&(e=n(n=0)),e);var vn=(n,e)=>{for(var t in e)qe(n,t,{get:e[t],enumerable:!0})},wn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of bn(e))!yn.call(n,s)&&s!==t&&qe(n,s,{get:()=>e[s],enumerable:!(r=mn(e,s))||r.enumerable});return n};var _n=n=>wn(qe({},"__esModule",{value:!0}),n);function Ee(){return ue>0||_e}function wt(){return ue>0}function ce(n){ue>0?Te.push(n):n()}function Re(n){ue+=1;let e=!1;try{n()}catch(t){throw e=!0,t}finally{if(ue-=1,ue===0)if(e){if(!_e){let t=Te.splice(0);for(let r of t)try{r()}catch{}ee.length=0,te.length=0,de.length=0}}else Tn()}}function Tn(){let n=!_e;n&&(_e=!0);let e=[],t=0;try{for(;ee.length>0||te.length>0||de.length>0||n&&Te.length>0;){if(n&&Te.length>0){let o=Te.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw ee.length=0,te.length=0,de.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(ee.length>0?ee:te.length>0?te:de).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{n&&(_e=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function Ae(n,e,t){if(e.length===0)return;if(e.length===1){let d=t(e[0][0]);if(d<3||!Ee()){n(e);return}(d>=5?de:d===4?te:ee).push(()=>n(e));return}let r=e.length,s=r,o=r,i=r,a=0;for(;a<r&&t(e[a][0])<3;)a++;for(s=a;a<r&&t(e[a][0])===3;)a++;for(o=a;a<r&&t(e[a][0])===4;)a++;i=a;let u=Ee();if(s>0){let d=e.slice(0,s);n(d)}if(o>s){let d=e.slice(s,o);u?ee.push(()=>n(d)):n(d)}if(i>o){let d=e.slice(o,i);u?te.push(()=>n(d)):n(d)}if(r>i){let d=e.slice(i,r);u?de.push(()=>n(d)):n(d)}}var ue,_e,ee,te,de,Te,Se=G(()=>{"use strict";ue=0,_e=!1,ee=[],te=[],de=[],Te=[]});var le,P,U,q,K,J,Z,V,L,S,fe,Ke,Nn,Ye,On,xn,Je,_t,Tt,Nt,Xe,ne=G(()=>{"use strict";le=Symbol.for("graphrefly/START"),P=Symbol.for("graphrefly/DATA"),U=Symbol.for("graphrefly/DIRTY"),q=Symbol.for("graphrefly/RESOLVED"),K=Symbol.for("graphrefly/INVALIDATE"),J=Symbol.for("graphrefly/PAUSE"),Z=Symbol.for("graphrefly/RESUME"),V=Symbol.for("graphrefly/TEARDOWN"),L=Symbol.for("graphrefly/COMPLETE"),S=Symbol.for("graphrefly/ERROR"),fe=Object.freeze([U]),Ke=Object.freeze([q]),Nn=Object.freeze([K]),Ye=Object.freeze([le]),On=Object.freeze([L]),xn=Object.freeze([V]),Je=Object.freeze([fe]),_t=Object.freeze([Ke]),Tt=Object.freeze([Nn]),Nt=Object.freeze([On]),Xe=Object.freeze([xn])});function xt(n,e){let t=new TextEncoder().encode(n.name);if(t.length===0||t.length>255)throw new Error(`encodeEnvelope: codec name "${n.name}" encodes to ${t.length} bytes (must be 1\u2013255)`);let r=n.version;if(!Number.isInteger(r)||r<0||r>65535)throw new Error(`encodeEnvelope: codec.version ${r} out of u16 range (expected integer 0\u201365535)`);let s=2+t.length+2+e.length;if(s>4294967295)throw new Error(`encodeEnvelope: total envelope size ${s} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let o=new Uint8Array(s),i=0;return o[i++]=Ze,o[i++]=t.length,o.set(t,i),i+=t.length,o[i++]=r>>>8&255,o[i++]=r&255,o.set(e,i),o}function kt(n,e){if(n.length<Ot)throw new Error(`decodeEnvelope: bytes too short (${n.length} < ${Ot})`);let t=0,r=n[t++];if(r!==Ze)throw new Error(`decodeEnvelope: unsupported envelope version ${r} (expected ${Ze})`);let s=n[t++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+s+2>n.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+s+2} bytes, have ${n.length})`);let o=new TextDecoder().decode(n.subarray(t,t+s));t+=s;let i=(n[t]<<8|n[t+1])>>>0;t+=2;let a=n.subarray(t),u=e.lookupCodec(o);if(u==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:u,codecVersion:i,payload:a}}function Et(n){n.registerCodec(kn)}var kn,Ze,Ot,Qe=G(()=>{"use strict";kn={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}},Ze=1,Ot=4});function De(n){if(n==null)return pe;let{type:e,id:t,...r}=n;return{type:e??"system",id:t??"",...r}}var pe,et=G(()=>{"use strict";pe={type:"system",id:""}});function X(){return Math.trunc(performance.now()*1e6)}function Ce(){return Date.now()*1e6}var Me=G(()=>{"use strict"});function Rt(n){n.registerMessageType(le,{tier:0,wireCrossing:!1}),n.registerMessageType(U,{tier:1,wireCrossing:!1}),n.registerMessageType(K,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(J,{tier:2,wireCrossing:!1}),n.registerMessageType(Z,{tier:2,wireCrossing:!1}),n.registerMessageType(P,{tier:3,wireCrossing:!0}),n.registerMessageType(q,{tier:3,wireCrossing:!0}),n.registerMessageType(L,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(S,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(V,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var Ge,At=G(()=>{"use strict";ne();Ge=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_rigorRecorder;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=t=>{let r=this._messageTypes.get(t);return r!=null?r.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}get rigorRecorder(){return this._rigorRecorder}set rigorRecorder(e){this._rigorRecorder=e}registerMessageType(e,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}}});function St(n){return Array.isArray(n)?[...n]:[n]}function En(n,e){return n.has(e)||n.has("*")}function Dt(n){let e=[];return n((s,o)=>{e.push({kind:"allow",actions:new Set(St(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(St(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let u of e)En(u.actions,o)&&u.where(s)&&(u.kind==="deny"?i=!0:a=!0);return i?!1:a}}function tt(n){let e=Rn.filter(t=>n({type:t,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(t=>t==="human"||t==="llm"||t==="system")?"both":e.length===1?e[0]:e.join("+")}var W,Rn,Ne=G(()=>{"use strict";W=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};Rn=["human","llm","wallet","system"]});function nt(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(nt);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=nt(n[t]);return e}return null}function Dn(n){let e=Sn.encode(n),t=e.length,r=t*8,s=t+9+63&-64,o=new Uint8Array(s);o.set(e),o[t]=128;let i=new DataView(o.buffer);i.setUint32(s-4,r>>>0,!1),i.setUint32(s-8,Math.floor(r/4294967296)>>>0,!1);let a=1779033703,u=3144134277,d=1013904242,l=2773480762,g=1359893119,h=2600822924,f=528734635,c=1541459225,m=new Uint32Array(64),p=(y,b)=>y>>>b|y<<32-b;for(let y=0;y<s;y+=64){for(let N=0;N<16;N++)m[N]=i.getUint32(y+N*4,!1);for(let N=16;N<64;N++){let j=m[N-15],$=m[N-2],D=p(j,7)^p(j,18)^j>>>3,ae=p($,17)^p($,19)^$>>>10;m[N]=m[N-16]+D+m[N-7]+ae>>>0}let b=a,v=u,w=d,O=l,x=g,k=h,E=f,R=c;for(let N=0;N<64;N++){let j=p(x,6)^p(x,11)^p(x,25),$=x&k^~x&E,D=R+j+$+An[N]+m[N]>>>0,ae=p(b,2)^p(b,13)^p(b,22),Be=b&v^b&w^v&w,xe=ae+Be>>>0;R=E,E=k,k=x,x=O+D>>>0,O=w,w=v,v=b,b=D+xe>>>0}a=a+b>>>0,u=u+v>>>0,d=d+w>>>0,l=l+O>>>0,g=g+x>>>0,h=h+k>>>0,f=f+E>>>0,c=c+R>>>0}let _=y=>y.toString(16).padStart(8,"0");return _(a)+_(u)+_(d)+_(l)+_(g)+_(h)+_(f)+_(c)}function rt(n){let e=nt(n??null),t=JSON.stringify(e);return Dn(t).slice(0,16)}function Cn(){let n=globalThis.crypto;if(n?.randomUUID)return n.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function st(n,e,t){let r=t?.id??Cn();if(n===0)return{id:r,version:0};let o=(t?.hash??rt)(e);return{id:r,version:0,cid:o,prev:null}}function Ct(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}var An,Sn,Mt=G(()=>{"use strict";An=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Sn=new TextEncoder});function $t(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function ot(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function Pe(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}function re(n,e,t){let r=It(n)?n:[],s=typeof n=="function"?n:typeof e=="function"?e:void 0,o={};return It(n)?o=(it(e)?e:t)??{}:it(n)?o=n:o=(it(e)?e:t)??{},new I(r,s,o)}var Gt,Pt,Mn,Gn,he,I,It,it,ge=G(()=>{"use strict";Qe();et();Se();Me();At();Ne();ne();Mt();Gt=()=>{},Pt=100;Mn=(n,e,t,r)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},Gn=(n,e,t,r)=>{let s=n;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Ye]:[Ye,[P,o]];s._status==="dirty"&&i.push(fe),Ae(e,i,s._config.tierOf)},he=new Ge({onMessage:Mn,onSubscribe:Gn});Rt(he);Et(he);I=class n{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,t,r){this._config=r.config??he,this._config.onMessage,this._optsName=r.name,this._describeKind=r.describeKind,this._equals=r.equals??Object.is,this._resubscribable=r.resubscribable??!1,this._resetOnTeardown=r.resetOnTeardown??!1,this._autoComplete=r.completeWhenDepsComplete??!0,this._autoError=r.errorWhenDepsError??!0,this._pausable=r.pausable??!0,this._guard=r.guard,this._fn=t,this._partial=r.partial??!1,this._cached=r.initial!==void 0?r.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=r.versioningHash??this._config.defaultHashFn??rt;let s=r.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?st(s,this._cached===void 0?void 0:this._cached,{id:r.versioningId,hash:this._hashFn}):void 0,this._deps=e.map($t);let o={};for(let[a,u]of Object.entries(r.meta??{})){let d={initial:u,name:`${r.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};r.guard!=null&&(d.guard=r.guard),o[a]=new n([],void 0,d)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[P,a]])},down(a){i._emit(Pe(a))},up(a){i._emitUp(Pe(a))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,t){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let r=this._versioningLevel;if(r!=null&&e<=r)return;let s=t?.hash??this._hashFn;s!==this._hashFn&&(this._hashFn=s);let o=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??t?.id,u=i?.version??0,d=st(e,o,{id:a,hash:s});d.version=u,this._versioning=d,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=De(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let r of this._extraGuards)if(!r(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,r=e?.actor!=null;if(!t&&!r)return;let s=De(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new W({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new W({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:Ce()}}down(e,t){let r=Pe(e);r.length!==0&&(this._checkGuard(t),this._emit(r))}emit(e,t){this._checkGuard(t),this._emit([[P,e]])}up(e,t){if(this._deps.length===0)return;let r=Pe(e);if(r.length===0)return;this._checkGuard(t);let s=t??{internal:!0};this._validateUpTiers(r);for(let o of this._deps)o.node.up?.(r,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let r of e){let s=t(r[0]);if(s===3||s===4)throw new Error(`Node "${this.name}": tier-${s} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let u=De(t);if(!this._guard(u,"observe"))throw new W({actor:u,action:"observe",nodeName:this.name})}let s=this._isTerminal&&this._resubscribable;if(s){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let u of this._deps)ot(u);if(this._partial===!1){for(let u of this._deps)if(u.prevData!==void 0||u.dataBatch.length!==0||u.terminal!==void 0||u.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:s},this._actions)}catch(u){throw this._sinkCount-=1,u}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let i=this._isTerminal;if(this._sinkCount===1&&!i)try{this._activate()}catch(u){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw u}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let r=0;r<e;r++){let s=r,o=this._deps[r];o.unsub=Gt,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,u=!1;for(let d of i)a(d[0])>=3&&(u=!0),this._config.onMessage(this,d,{direction:"down-in",depIndex:s},this._actions);u&&this._maybeRunFnOnSettlement()}),t++}}catch(r){this._deps[t].unsub=null;for(let s=0;s<t;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}ot(o)}}throw this._dirtyDepCount=0,r}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let t=this._deps.length,r=$t(e);if(this._deps.push(r),this._sinks==null)return t;r.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Je),r.unsub=Gt;try{r.unsub=e.subscribe(s=>{if(r.unsub===null)return;let o=this._config.tierOf,i=!1;for(let a of s)o(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw r.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(r){this._emit([[S,this._wrapFnError("cleanup threw",r)]])}else if(t!=null&&typeof t=="object"){let r=t.deactivate;if(typeof r=="function")try{r()}catch(s){this._emit([[S,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let r of this._deps){if(r.unsub!=null){let s=r.unsub;r.unsub=null;try{s()}catch{}}ot(r)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,t){let r=this._deps[e],s=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(o)}if(s!==le){if(s===U){this._depDirtied(r);return}if(s===K){if(this._depInvalidated(r),this._cached===void 0)return;this._emit(Tt);return}if(s===J||s===Z){this._emit([t]);return}if(s===V){this._emit(Xe);return}if(s===P)this._depSettledAsData(r,t[1]);else if(s===q)this._depSettledAsResolved(r);else if(s===L)this._depSettledAsTerminal(r,!0);else if(s===S)this._depSettledAsTerminal(r,t[1]);else{this._emit([t]);return}if(!this._fn){(s===P||s===q)&&this._emit([t]),(s===L||s===S)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Je))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(_t),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[S,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(Nt)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(i){this._emit([[S,this._wrapFnError("cleanup threw",i)]]);return}}else if(e!=null&&typeof e=="object"){let i=e.beforeRun;if(typeof i=="function"){e.beforeRun=void 0;try{i()}catch(a){this._emit([[S,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let t=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),r=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=t[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:r,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:r};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(t,this._actions,o);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let a=i;(typeof a.beforeRun=="function"||typeof a.deactivate=="function"||typeof a.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[S,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Pt?(this._rerunDepth=0,this._emit([[S,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Pt} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,t){let r=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${r}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[fe,e[0]]:e;let r=!0,s=!1,o=!1,i=-1;for(let u of e){let d=t(u[0]);d<i&&(r=!1),d===3&&(s=!0),u[0]===U&&(o=!0),i=d}let a=e;if(!r){let u=e.map((d,l)=>({m:d,i:l,tier:t(d[0])}));u.sort((d,l)=>d.tier-l.tier||d.i-l.i),a=u.map(d=>d.m)}if(s&&!o&&this._status!=="dirty"){let u=0;for(;u<a.length&&t(a[u][0])===0;)u++;return u===0?[fe,...a]:[...a.slice(0,u),fe,...a.slice(u)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let u=e[a];if(u[0]===S&&u[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(u=>u[0]===V||u[0]===K);if(a.length===0)return;t=a}t=this._frameBatch(t);let s=null;for(let a=0;a<t.length;a++){let u=t[a],d=u[0];if(d!==J&&d!==Z){s?.push(u);continue}if(u.length<2)throw new Error(`Node "${this.name}": [[${d===J?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let l=!0;if(this._pausable!==!1){let g=u[1];if(d===J)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(g),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(g))l=!1;else if(this._pauseLocks.delete(g),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let h=this._pauseBuffer;this._pauseBuffer=[],this._emit(h)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}l?s?.push(u):s==null&&(s=t.slice(0,a))}if(s!=null){if(s.length===0)return;t=s}if(this._hasMeta&&t.some(a=>a[0]===V))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(Xe)}catch{}let{finalMessages:o,equalsError:i}=this._updateState(t);if(o.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,u=[];for(let d of o)a(d[0])===3?this._pauseBuffer.push(d):u.push(d);u.length>0&&this._dispatchOrAccumulate(u)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[S,i]])}_updateState(e){let t=this._config.tierOf,r,s,o=-1,i=0;for(let l of e)t(l[0])===3&&i++;let a=i<=1,u=-1;if(this._versioning!=null&&i>1){for(let l=e.length-1;l>=0;l--)if(e[l][0]===P){u=l;break}}for(let l=0;l<e.length;l++){let g=e[l],h=g[0];if(h===P){if(g.length>=2){let f=!1;if(a&&this._cached!==void 0)try{f=this._equals(this._cached,g[1])}catch(c){s=this._wrapFnError("equals threw",c),o=l;break}if(f){r==null&&(r=e.slice(0,l)),r.push(Ke),this._status="resolved";continue}this._cached=g[1],this._versioning!=null&&(u<0||l===u)&&Ct(this._versioning,g[1],this._hashFn)}this._status="settled",r?.push(g)}else if(r?.push(g),h===U)this._status="dirty";else if(h===q)this._status="resolved";else if(h===L){this._status="completed";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(h===S){this._status="errored";{let f=this._config.rigorRecorder;if(f!=null)try{f.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(h===K){if(this._cached!==void 0){let c=this._config.rigorRecorder;if(c!=null)try{c.onNonVacuousInvalidate(this,this._cached)}catch{}}this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let c=f.invalidate;if(typeof c=="function")try{c()}catch{}}}else h===V&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let d=o>=0?r??e.slice(0,o):r??e;return s!=null?{finalMessages:d,equalsError:s}:{finalMessages:d}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let r of t)r(e)};_dispatchOrAccumulate(e){if(wt()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],ce(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}Ae(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);Ae(this._deliverToSinks,t,this._config.tierOf)}},It=n=>Array.isArray(n),it=n=>typeof n=="object"&&n!=null&&!Array.isArray(n)});function se(n,e){return re([],{...e,initial:n})}function me(n,e){return re((r,s,o)=>n(s,o)??void 0,{describeKind:"producer",...e})}function be(n,e,t){return re(n,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);o.emit(e(a,i))},{describeKind:"derived",...t})}function Ft(n,e,t){return re(n,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);return e(a,o,i)??void 0},{describeKind:"effect",...t})}var $e=G(()=>{"use strict";ge()});function at(n,e){if(e!=null&&e.length>0)return new Set(e);switch(n){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;case"spec":return new Set(["type","deps","meta","value"]);default:return new Set(["type","deps"])}}function Pn(n){return n._describeKind!=null?n._describeKind:n._deps.length>0?"derived":n._fn!=null?"producer":"state"}function ut(n,e){let t={factory:n};return e!==void 0&&(t.factoryArgs=e),t}function $n(n){let e={};for(let[t,r]of Object.entries(n.meta))try{e[t]=r.cache}catch{}return e}function dt(n,e,t){let r=e==null,s=!r&&e!=null?[...e].filter(l=>l.startsWith("meta.")).map(l=>l.slice(5)):null,o=r||e.has("meta")||s!=null&&s.length>0,i="state",a=[];n instanceof I&&(i=Pn(n),a=n._deps.map(l=>l.node.name??""));let u={type:i,deps:a};(r||e.has("status"))&&(u.status=n.status);let d=n instanceof I?n._guard:void 0;if(o){let l={...$n(n)};if(d!=null&&l.access===void 0&&(l.access=tt(d)),s!=null&&s.length>0&&!e.has("meta")){let g={};for(let h of s)h in l&&(g[h]=l[h]);u.meta=g}else u.meta=l}if(n.name!=null&&(u.name=n.name),(r||e.has("value"))&&(!t||i==="state")){n.status==="sentinel"&&(u.sentinel=!0);try{u.value=n.cache}catch{}}if((r||e.has("v"))&&n.v!=null){let l={id:n.v.id,version:n.v.version};"cid"in n.v&&(l.cid=n.v.cid,l.prev=n.v.prev),u.v=l}return(r||e.has("guard"))&&d!=null&&(u.guard=tt(d)),(r||e.has("lastMutation"))&&n.lastMutation!=null&&(u.lastMutation=n.lastMutation),u}var ct=G(()=>{"use strict";Ne();ge()});function oe(n){return n.subscribe(()=>{})}var Lt=G(()=>{"use strict"});var lt=G(()=>{"use strict";Lt()});function jt(n){return{describeKind:"derived",...n}}function Vt(...n){return n.length===0?me(e=>{e.down([[L]])},{...jt(),meta:{...ut("merge")}}):me(e=>{let t=n.length,r=0,s=[];for(let o of n){let i=o.subscribe(a=>{for(let u of a)u[0]===P?e.emit(u[1]):u[0]===L?(r+=1,r>=t&&e.down([[L]])):u[0]===S&&e.down([u])});s.push(i)}return()=>{for(let o of s)o()}},{...jt(),meta:{...ut("merge")}})}var Bt=G(()=>{"use strict";ne();ct();$e()});var Ut=G(()=>{"use strict";Bt()});function ft(n,e){if(Object.is(n,e))return!0;if(n==null||e==null||typeof n!="object"||typeof e!="object")return!1;if(Array.isArray(n)){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let o=0;o<n.length;o++)if(!ft(n[o],e[o]))return!1;return!0}if(Array.isArray(e))return!1;let t=Object.keys(n),r=Object.keys(e);if(t.length!==r.length)return!1;let s=new Set(r);for(let o of t)if(!s.has(o)||!ft(n[o],e[o]))return!1;return!0}function Ht(n,e){return`${n}\0${e}`}function pt(n,e){let t=[],r=new Set(n.subgraphs),s=new Set(e.subgraphs),o=[];for(let p of s)r.has(p)||o.push(p);o.sort();for(let p of o)t.push({type:"subgraph-mounted",path:p});let i=new Set(Object.keys(n.nodes)),a=new Set(Object.keys(e.nodes)),u=[];for(let p of a)i.has(p)||u.push(p);u.sort();for(let p of u)t.push({type:"node-added",path:p,node:{...e.nodes[p]}});let d=[];for(let p of a){if(!i.has(p))continue;let _=n.nodes[p]?.meta,y=e.nodes[p]?.meta;_==null&&y==null||ft(_??{},y??{})||d.push(p)}d.sort();for(let p of d)t.push({type:"node-meta-changed",path:p,prevMeta:n.nodes[p]?.meta??{},nextMeta:e.nodes[p]?.meta??{}});let l=new Map;for(let p of n.edges)l.set(Ht(p.from,p.to),p);let g=new Map;for(let p of e.edges)g.set(Ht(p.from,p.to),p);let h=[];for(let[p,_]of g)l.has(p)||h.push(_);h.sort((p,_)=>p.from<_.from?-1:p.from>_.from?1:p.to<_.to?-1:p.to>_.to?1:0);for(let p of h)t.push({type:"edge-added",from:p.from,to:p.to});let f=[];for(let[p,_]of l)g.has(p)||f.push(_);f.sort((p,_)=>p.from<_.from?-1:p.from>_.from?1:p.to<_.to?-1:p.to>_.to?1:0);for(let p of f)t.push({type:"edge-removed",from:p.from,to:p.to});let c=[];for(let p of i)a.has(p)||c.push(p);c.sort();for(let p of c)t.push({type:"node-removed",path:p});let m=[];for(let p of r)s.has(p)||m.push(p);m.sort();for(let p of m)t.push({type:"subgraph-unmounted",path:p});return{events:t,flushedAt_ns:X()}}var zt=G(()=>{"use strict";Me()});var Ie,Wt=G(()=>{"use strict";Ie=class{_timer;_gen=0;start(e,t){this.cancel(),this._gen+=1;let r=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,r===this._gen&&t()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var Oe,qt=G(()=>{"use strict";Oe=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}}});function Kt(n,e,t,r={}){let s=e in n.nodes,o=t in n.nodes;if(!s)return Fe(e,t,"no-such-from");if(!o)return Fe(e,t,"no-such-to");let i=r.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(r.findCycle===!0){let d=In(n,e,r);if(d!=null)return d}let u=Le(e,n.nodes[e],0,r);return je(e,t,[u])}if(i===0)return Fe(e,t,"no-path");let a=Yt(n,e,t,i);return a.found?je(e,t,Jt(n,a.pathOrder,r)):Fe(e,t,a.truncated?"max-depth-exceeded":"no-path")}function Yt(n,e,t,r){let s=new Map,o=[{path:t,depth:0}],i=new Set([t]),a=0,u=!1;for(;a<o.length;){let g=o[a++];if(g.path===e)break;if(r!=null&&g.depth>=r){let m=n.nodes[g.path];m?.deps&&m.deps.length>0&&(u=!0);continue}let h=n.nodes[g.path];if(h==null)continue;let f=h.deps??[],c=new Map;for(let m=0;m<f.length;m++){let p=f[m];if(!p)continue;let _=c.get(p);_==null&&(_=[],c.set(p,_)),_.push(m)}for(let[m,p]of c)i.has(m)||(i.add(m),s.set(m,{from:g.path,depIndices:p}),o.push({path:m,depth:g.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:u};let d=[{path:e}],l=e;for(;l!==t;){let g=s.get(l);if(g==null)return{found:!1,pathOrder:[],truncated:!1};d[d.length-1].depIndices=g.depIndices,d.push({path:g.from}),l=g.from}return{found:!0,pathOrder:d,truncated:!1}}function In(n,e,t){let r=n.nodes[e];if(r==null)return null;let s=r.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=Le(e,r,0,t);a.dep_index=o[0];let u=Le(e,r,1,t);return je(e,e,[a,u])}let i=null;for(let a=0;a<s.length;a++){let u=s[a];if(!u||u===e)continue;let d=Yt(n,u,e,t.maxDepth);d.found&&(i==null||d.pathOrder.length<i.pathOrder.length)&&(i=d,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...d.pathOrder],truncated:!1})}return i==null?null:je(e,e,Jt(n,i.pathOrder,t))}function Jt(n,e,t){return e.map((r,s)=>{let o=n.nodes[r.path],i=Le(r.path,o,s,t);return r.depIndices!=null&&r.depIndices.length>0&&(i.dep_index=r.depIndices[0],r.depIndices.length>1&&(i.dep_indices=[...r.depIndices])),i})}function Le(n,e,t,r){let s={path:n,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 o=r.annotations?.get(n)??e.annotation;o!=null&&(s.annotation=o);let i=r.lastMutations?.get(n)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function je(n,e,t){return Xt(n,e,!0,"ok",t)}function Fe(n,e,t){return Xt(n,e,!1,t,[])}function Xt(n,e,t,r,s){let o=Fn(n,e,t,r,s);return{from:n,to:e,found:t,reason:r,steps:s,text:o,toJSON(){return{from:n,to:e,found:t,reason:r,steps:s}}}}function Fn(n,e,t,r,s){if(!t)switch(r){case"no-such-from":return`explainPath: no node named "${n}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${n}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${n}" to "${e}"`}let o=[`Causal path: ${n} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let u=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(u),"value"in i&&o.push(` value: ${Ln(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let d=i.lastMutation.actor;o.push(` actor: ${d.type}${d.id?`:${d.id}`:""}`)}}return o.join(`
|
|
2
|
+
`)}function Ln(n){if(n===void 0)return"<sentinel>";if(n===null)return"null";if(typeof n=="string")return JSON.stringify(n);if(typeof n=="number"||typeof n=="boolean"||typeof n=="bigint")return String(n);try{let e=JSON.stringify(n);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(n)}}var Zt=G(()=>{"use strict"});function Qt(n){let e=new WeakSet,t=new WeakSet,r=[n],s=0;for(;r.length>0;){let o=r.pop();s+=Vn(o,e,t,r)}return s}function Vn(n,e,t,r){if(n==null)return 0;switch(typeof n){case"number":return F.number;case"boolean":return F.boolean;case"string":return F.string+n.length*2;case"bigint":return F.bigint+Bn(n);case"symbol":return F.symbol;case"function":return e.has(n)?0:(e.add(n),F.function);case"undefined":return 0}let o=n;if(e.has(o))return 0;e.add(o);let i=o[jn];if(typeof i=="function")try{let d=i.call(o);if(typeof d=="number"&&Number.isFinite(d))return d}catch{}if(o instanceof Date)return F.date;if(o instanceof RegExp)return F.regexp+o.source.length*2;if(o instanceof Error){let d=o.message?o.message.length*2:0,l=o.stack?o.stack.length*2:0;return F.error+d+l}if(typeof URL<"u"&&o instanceof URL)return F.url+o.href.length*2;if(typeof Promise<"u"&&o instanceof Promise)return F.promise;if(o instanceof WeakMap)return F.weakmap;if(o instanceof WeakSet)return F.weakset;if(o instanceof Map){let d=F.map;for(let[l,g]of o)d+=F.mapEntry,r.push(l),r.push(g);return d}if(o instanceof Set){let d=F.set;for(let l of o)d+=F.setEntry,r.push(l);return d}if(Array.isArray(o)){let d=F.array+o.length*8;for(let l of o)r.push(l);return d}if(o instanceof ArrayBuffer)return t.has(o)?0:(t.add(o),o.byteLength);if(ArrayBuffer.isView(o)){let d=o;return t.has(d.buffer)?48:(t.add(d.buffer),d.buffer.byteLength+48)}let a=F.object,u=Object.keys(o);for(let d of u){a+=F.string+d.length*2;try{r.push(o[d])}catch{}}return a}function Bn(n){let e=n<0n?-n:n;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}var F,jn,en=G(()=>{"use strict";F={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},jn=Symbol.for("sizeof")});function tn(n,e){let t=e?.topN??10,r=n.describe({detail:"standard"}),s=[],o=n._collectObserveTargets;typeof o=="function"&&o.call(n,"",s);let i=new Map;for(let[h,f]of s)i.set(h,f);let a=[];for(let[h,f]of Object.entries(r.nodes)){let c=i.get(h),m=c instanceof I?c:null,p=m?Qt(m.cache):0,_=m?m._sinkCount:0,y=f.deps?.length??0,b=f.type==="effect"&&_===0,v=_===0?f.type==="effect"?"orphan-effect":f.type==="derived"?"idle-derived":f.type==="producer"?"idle-producer":null:null;a.push({path:h,type:f.type,status:f.status??"unknown",valueSizeBytes:p,subscriberCount:_,depCount:y,isOrphanEffect:b,orphanKind:v})}let u=a.reduce((h,f)=>h+f.valueSizeBytes,0),d=(h,f)=>[...a].sort(f??((c,m)=>m[h]-c[h])).slice(0,t),l=a.filter(h=>h.orphanKind!=null),g=a.filter(h=>h.isOrphanEffect);return{nodeCount:a.length,edgeCount:r.edges.length,subgraphCount:r.subgraphs.length,nodes:a,totalValueSizeBytes:u,hotspots:{byValueSize:d("valueSizeBytes"),bySubscriberCount:d("subscriberCount"),byDepCount:d("depCount")},orphans:l,orphanEffects:g}}var nn=G(()=>{"use strict";ge();en()});function rn(n,e){let t=Math.max(16,n.size*4),r=0;for(;n.size>0;){if(r++>=t){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${t}); ${n.size} disposer(s) discarded`),n.clear();return}let s=n.values().next();if(s.done)return;let o=s.value;n.delete(o);try{o()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function cn(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"&&typeof n.down=="function"}function Un(n){if(n!=null)return cn(n)?n.cache:n}function ie(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"&&typeof n.down=="function"}function Q(n){return ie(n)?n.cache??"":n}function sn(n){return ie(n)?n.cache??0:n}function on(n){return ie(n)?n.cache??!1:n}function Hn(n){let e=[];for(let t of Object.keys(n).sort()){let r=n[t].v;r!=null&&e.push(`${t} ${r.id} ${r.version}`)}return e.join(`
|
|
3
|
+
`)}function an(n){if(n.version!==ye)throw new Error(`unsupported snapshot version ${String(n.version)} (expected ${ye})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in n))throw new Error(`snapshot missing required key "${e}"`);if(typeof n.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof n.nodes!="object"||n.nodes===null||Array.isArray(n.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(n.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(n.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function zn(n,e){let t=new WeakMap,r=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,u=o.constructor;if(a!==u)return!1;if(s instanceof Date)return s.getTime()===o.getTime();if(s instanceof RegExp)return s.source===o.source&&s.flags===o.flags;if(Array.isArray(s)){let h=o;if(s.length!==h.length)return!1;for(let f=0;f<s.length;f++)if(!r(s[f],h[f]))return!1;return!0}if(s instanceof Map){let h=o;if(s.size!==h.size)return!1;for(let[f,c]of s)if(!h.has(f)||!r(c,h.get(f)))return!1;return!0}if(s instanceof Set){let h=o;if(s.size!==h.size)return!1;for(let f of s){let c=!1;for(let m of h)if(r(f,m)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(s)){let h=s,f=o;if(h.length!==f.length)return!1;for(let c=0;c<h.length;c++)if(h[c]!==f[c])return!1;return!0}let d=Object.keys(s),l=Object.keys(o);if(d.length!==l.length)return!1;let g=new Set(l);for(let h of d)if(!g.has(h)||!r(s[h],o[h]))return!1;return!0};return r(n,e)}function Wn(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ve(n){let e="^";for(let t=0;t<n.length;t+=1){let r=n[t];if(r==="*"){e+=".*";continue}if(r==="?"){e+=".";continue}if(r==="["){let s=n.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let o=n.slice(t+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,t=s;continue}e+=Wn(r)}return e+="$",new RegExp(e)}function ht(n){if(typeof n=="string")return JSON.stringify(n);if(typeof n=="number"||typeof n=="boolean"||n==null)return String(n);try{return JSON.stringify(n)}catch{return"[unserializable]"}}function Yn(n){return n==="none"?Kn:n==="ansi"||n==null?qn:{data:n.data??"",dirty:n.dirty??"",resolved:n.resolved??"",invalidate:n.invalidate??"",pause:n.pause??"",resume:n.resume??"",complete:n.complete??"",error:n.error??"",teardown:n.teardown??"",derived:n.derived??"",path:n.path??"",reset:n.reset??""}}function un(n){if(n==null)return{};let e=n.detail;return e==="full"?{...n,structured:n.structured??!0,timeline:n.timeline??!0,causal:n.causal??!0,derived:n.derived??!0}:e==="minimal"?{...n,structured:n.structured??!0}:n.format==="stage-log"?{...n,structured:n.structured??!0,timeline:n.timeline??!0}:n}function Jn(n,e,t){for(let r=0;r<n.length;r++){let s=n.charCodeAt(r);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${n}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${r})`)}}function gt(n,e,t){if(n==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(n.includes(M))throw new Error(`Graph "${e}": ${t} "${n}" must not contain '${M}' (path separator)`);if(n===Y)throw new Error(`Graph "${e}": ${t} name "${Y}" is reserved for meta companion paths`);Jn(n,e,t)}function Xn(n,e){if(n==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=n.split(M);for(let r of t)if(r==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function Zn(n,e){let t=!1;for(let s of n)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?n.filter(s=>e.isMetaPassthrough(s[0])):n}function ln(n){for(let e of n._mounts.values())ln(e);for(let e of n._nodes.values())try{e.down([[V]],{internal:!0})}catch{}}function Qn(n,e){let t=ve.diff(n,e),r={};for(let s of t.nodesAdded){let o=e.nodes[s];o!=null&&(r[s]=o)}return{...t,nodesAddedFull:r}}function dn(n,e,t,r={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return r.withDetail?s:[];if(!r.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=r.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return r.withDetail?s:[];let i=new Map,a=new Map,u=new Map,d=new Map,l=new Set;for(let[b,v]of Object.entries(n.nodes)){if(!b)continue;l.add(b);let w=v.deps??[];i.set(b,w);for(let O of w)O&&(l.add(O),a.has(O)||a.set(O,new Set),a.get(O).add(b))}for(let b of n.edges){if(b==null||typeof b!="object")continue;let v=typeof b.from=="string"?b.from:"",w=typeof b.to=="string"?b.to:"";!v||!w||(l.add(v),l.add(w),d.has(v)||d.set(v,new Set),d.get(v).add(w),u.has(w)||u.set(w,new Set),u.get(w).add(v))}if(!l.has(e))return r.withDetail?s:[];let g=r.both===!0,h=b=>{if(g){let x=i.get(b)??[],k=u.get(b),E=a.get(b),R=d.get(b),N=[...x];return k&&N.push(...k),E&&N.push(...E),R&&N.push(...R),N}if(t==="upstream"){let x=i.get(b)??[],k=u.get(b);return k?[...x,...k]:x}let v=a.get(b),w=d.get(b),O=v?[...v]:[];return w&&O.push(...w),O},f=new Set([e]),c=new Map,m=[{path:e,depth:0}],p=0,_=!1;for(;p<m.length;){let b=m[p++];if(o!=null&&b.depth>=o){h(b.path).length>0&&(_=!0);continue}for(let v of h(b.path))!v||f.has(v)||(f.add(v),c.set(v,b.depth+1),m.push({path:v,depth:b.depth+1}))}let y=[...c.keys()].sort((b,v)=>b<v?-1:b>v?1:0);return r.withDetail?{paths:y,depths:c,truncated:_}:y}function er(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],s=e[t];if(r.path!==s.path||r.type!==s.type||r.status!==s.status||r.hop!==s.hop||r.dep_index!==s.dep_index||r.annotation!==s.annotation||r.value!==s.value||r.lastMutation!==s.lastMutation)return!1;let o=r.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}var M,Y,ye,qn,Kn,ve,fn=G(()=>{"use strict";et();Se();Me();Ne();ne();ct();ge();$e();zt();lt();Wt();qt();Qe();Zt();nn();M="::",Y="__meta__",ye=1;qn={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"},Kn={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};ve=class n{name;opts;config;_nodes=new Map;_nodeToName=new WeakMap;_mounts=new Map;_parent=void 0;_storageDisposers=new Set;_disposers=new Set;_destroyed=!1;_topology;_topologyEmitters=new Set;_factory;_factoryArgs;constructor(e,t){if(e==="")throw new Error("Graph name must be non-empty");if(e.includes(M))throw new Error(`Graph name must not contain '${M}' (got "${e}")`);if(e===Y)throw new Error(`Graph name "${Y}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??he,this._traceRing=new Oe(t?.traceCapacity??1e3),t?.versioning!=null&&this.setVersioning(t.versioning),typeof t?.factory=="string"&&(this._factory=t.factory,t.factoryArgs!==void 0&&(this._factoryArgs=t.factoryArgs))}tagFactory(e,t){return this._factory=e,this._factoryArgs=t,this}ancestors(e=!0){let t=[],r=e?this:this._parent;for(;r!=null;)t.push(r),r=r._parent;return t}get topology(){return this._topology==null&&(this._topology=me(e=>{let t=r=>{e.emit(r)};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)}nameOf(e){return this._nodeToName.get(e)}add(e,t){let r=e.name,s=t?.name??r;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 o=s,i=t?.annotation;if(gt(o,this.name,"add"),this._mounts.has(o))throw new Error(`Graph "${this.name}": name "${o}" is already a mount point`);if(this._nodes.has(o))throw new Error(`Graph "${this.name}": node "${o}" 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(o,e),this._nodeToName.set(e,o),this._emitTopology({kind:"added",name:o,nodeKind:"node"}),i!=null&&(this._annotations.set(o,i),this.config.inspectorEnabled&&this._traceRing.push({path:o,annotation:i,timestamp_ns:X()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof I&&t._applyVersioning(e)}remove(e){gt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let o={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,u]of i)a.includes(`${M}${Y}${M}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...t._collectSubgraphs(`${e}${M}`)),this._mounts.delete(e),t._parent=void 0,ln(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}let r=this._nodes.get(e);if(!r)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(r),r.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 o=Ve(e);return i=>o.test(i)})(),r={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>t(o));for(let o of s){let i=this.remove(o);r.nodes.push(...i.nodes),r.mounts.push(...i.mounts)}return r.nodes.sort(),r.mounts.sort(),r}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,r=0;return{[Symbol.iterator](){return this},next(){if(r>=e.length)return{value:void 0,done:!0};let s=e[r++];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(M))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,r){let s=r?.internal===!0;this.node(e).down([[P,t]],{actor:r?.actor,internal:s,delivery:"write"})}setAll(e,t){let r=Symbol.iterator in e?e:Object.entries(e);Re(()=>{for(let[s,o]of r)this.set(s,o,t)})}invalidate(e,t){let r=t?.internal===!0;this.node(e).down([[K]],{actor:t?.actor,internal:r,delivery:"write"})}error(e,t,r){let s=r?.internal===!0;this.node(e).down([[S,t]],{actor:r?.actor,internal:s,delivery:"write"})}complete(e,t){let r=t?.internal===!0;this.node(e).down([[L]],{actor:t?.actor,internal:r,delivery:"write"})}edges(e){let t=e?.recursive===!0,r=new Map;if(!t){for(let[u,d]of this._nodes)r.set(d,u);let a=[];for(let[u,d]of this._nodes)if(d instanceof I)for(let l of d._deps){let g=r.get(l.node);g!=null&&a.push([g,u])}return a.sort((u,d)=>u[0]<d[0]?-1:u[0]>d[0]?1:u[1]<d[1]?-1:u[1]>d[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,u]of s)o.set(u,a);let i=[];for(let[a,u]of s)if(u instanceof I)for(let d of u._deps){let l=o.get(d.node);l!=null&&i.push([l,a])}return i.sort((a,u)=>a[0]<u[0]?-1:a[0]>u[0]?1:a[1]<u[1]?-1:a[1]>u[1]?1:0),i}mount(e,t){if(t===void 0){let s=new n(e);return this.mount(e,s)}if(typeof t=="function"){let s=new n(e);return t(s),this.mount(e,s)}let r=t;if(gt(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(r===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(r._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${r._parent.name}"`);for(let s=this;s!=null;s=s._parent)if(s===r)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,r),r._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),r}resolve(e){let t=Xn(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 r=t[0],s=t.slice(1);if(s.length===0){let a=this._nodes.get(r);if(a)return a;throw this._mounts.has(r)?new Error(`Graph "${this.name}": path ends at subgraph "${r}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${r}"`)}let o=this._nodes.get(r);if(o&&s.length>0&&s[0]===Y)return this._resolveMetaChainFromNode(o,s,t.join(M));let i=this._mounts.get(r);if(!i)throw this._nodes.has(r)?new Error(`Graph "${this.name}": "${r}" is a node; trailing path "${s.join(M)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${r}"`);return i.resolve(s.join(M))}_resolveMetaChainFromNode(e,t,r){let s=e,o=0,i=[...t];for(;o<i.length;){if(i[o]!==Y)throw new Error(`Graph "${this.name}": expected ${Y} segment in meta path "${r}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${Y} in "${r}"`);let a=i[o+1],u=s.meta[a];if(!u)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${r}"`);s=u,o+=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 r=[];if(this._signalDeliver(e,t??{},new Set,r),r.length>0)throw r[0]}_signalDeliver(e,t,r,s){for(let u of this._mounts.values())u._signalDeliver(e,t,r,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=Zn(e,this.config);for(let u of[...this._nodes.keys()].sort()){let d=this._nodes.get(u);if(!r.has(d)){r.add(d);try{d.down(e,i)}catch(l){if(l instanceof W)throw l;s.push(l)}a.length!==0&&this._signalMetaSubtree(d,a,r,i,s)}}}_signalMetaSubtree(e,t,r,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!r.has(a)){r.add(a);try{a.down(t,s)}catch(u){if(u instanceof W)throw u;o.push(u)}this._signalMetaSubtree(a,t,r,s,o)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=Un(e?.actor),r=e?.filter;if(e?.detail!=null&&e?.fields!=null)throw new TypeError("Graph.describe(): pass either `detail` or `fields`, not both. `detail: 'spec'` is the canonical spec projection; use `fields` only when you need a custom subset.");let s=at(e?.detail,e?.fields),o=e?.detail==="spec",i=s,a=[];this._collectObserveTargets("",a);let u=new Map;for(let[v,w]of a)u.set(w,v);let d=[];{let v=a.map(([,x])=>x),w=new Set(u.values()),O=0;for(;v.length>0;){let x=v.shift();if(x instanceof I)for(let k of x._deps){let E=k.node;if(u.has(E))continue;let R=E.name??"",N=R;if(!N||w.has(N))if(R){let j=2;for(;w.has(`${R}#${j}`);)j++;N=`${R}#${j}`}else for(N=`__internal__/${O++}`;w.has(N);)N=`__internal__/${O++}`;u.set(E,N),w.add(N),d.push([N,E]),v.push(E)}}}let l=[...a,...d],g={};for(let[v,w]of l){if(t!=null&&!w.allowsObserve(t))continue;let O=dt(w,i,o),x=w instanceof I?w._deps.map(N=>u.get(N.node)??N.node.name??""):[],{name:k,...E}=O,R={...E,deps:x};if(!o){let N=this._annotations.get(v);N!=null&&(R.annotation=N)}if(r!=null)if(typeof r=="function"){let N=r;if(!(N.length>=2?N(v,R):N(R)))continue}else{let N=!0;for(let[j,$]of Object.entries(r)){let D=j==="deps_includes"?"depsIncludes":j==="meta_has"?"metaHas":j;if(D==="depsIncludes"){if(!R.deps.includes(String($))){N=!1;break}continue}if(D==="metaHas"){if(!Object.hasOwn(R.meta??{},String($))){N=!1;break}continue}if(R[D]!==$){N=!1;break}}if(!N)continue}g[v]=R}let h=new Set(Object.keys(g)),f=[];for(let[v,w]of l)if(w instanceof I)for(let O of w._deps){let x=u.get(O.node);x!=null&&f.push([x,v])}f.sort((v,w)=>v[0]<w[0]?-1:v[0]>w[0]?1:v[1]<w[1]?-1:v[1]>w[1]?1:0);let c=f.map(([v,w])=>({from:v,to:w}));(t!=null||r!=null)&&(c=c.filter(v=>h.has(v.from)&&h.has(v.to)));let m=this._collectSubgraphs(""),p=t!=null||r!=null?m.filter(v=>{let w=`${v}${M}`;return[...h].some(O=>O===v||O.startsWith(w))}):m,_=this,y=e;return{name:this.name,nodes:g,edges:c,subgraphs:p,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(v){let w={...y};return Array.isArray(v)?(w.fields=v,w.detail=void 0):(w.detail=v,w.fields=void 0),_.describe(w)}}}_collectSubgraphs(e){let t=[];for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${r}`;t.push(s),t.push(...this._mounts.get(r)._collectSubgraphs(`${s}${M}`))}return t}resourceProfile(e){return tn(this,e)}reachable(e,t,r={}){return r.withDetail===!0?dn(this.describe(),e,t,{...r,withDetail:!0}):dn(this.describe(),e,t,r)}explain(e,t,r){return r?.reactive===!0?this._explainReactive(e,t,r):this._explainStatic(Q(e),Q(t),{...r?.maxDepth!==void 0?{maxDepth:sn(r.maxDepth)}:{},...r?.findCycle!==void 0?{findCycle:on(r.findCycle)}:{}})}_explainStatic(e,t,r){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,u]of Object.entries(s.nodes))u.lastMutation!=null&&i.set(a,u.lastMutation);return Kt(s,e,t,{...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},r=e.reactiveName??"describe",s=0,o=se(s,{name:`${r}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ce(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(y=>{let b=y.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[],h=new WeakSet,f=y=>{if(h.has(y)||u)return;h.add(y);let b=y.topology.subscribe(v=>{for(let w of v){if(w[0]!==P)continue;let O=w[1];if(d(),O.kind==="added"&&O.nodeKind==="mount"){let x=y._mounts.get(O.name);x!=null&&f(x)}}});g.push(b);for(let v of y._mounts.keys()){let w=y._mounts.get(v);w!=null&&f(w)}};f(this);let c,m=e.actor;cn(m)&&(c=m.subscribe(y=>{let b=!1,v=!1;for(let w of y){let O=w[0];O===P?b=!0:(O===L||O===S||O===V)&&(v=!0)}b&&d(),v&&(c?.(),c=void 0,d())}));let p;try{p=be([o],()=>this.describe(t),{name:r,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(y,b)=>y===b})}catch(y){l(),c?.();for(let b of g)b();throw i.dispose(),y}let _=oe(p);return{node:p,dispose(){u=!0,l(),c?.();for(let y of g)y();g.length=0,i.dispose(),_()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},r=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(t),i=pt(s,o),a=se(i,{name:r,meta:{domain:"audit",kind:"describe-diff"},equals:(h,f)=>h===f}),u=this._describeReactive({...e,reactiveName:void 0}),d=!1,l=u.node.subscribe(h=>{if(!d)for(let f of h){if(f[0]!==P)continue;let c=f[1],m=pt(o,c);o=c,m.events.length!==0&&a.emit(m)}}),g=oe(a);return{node:a,dispose(){d=!0,l(),u.dispose(),a.down([[V,"describe-diff disposed"]]),g()}}}_explainReactive(e,t,r){let s=0,o=se(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ce(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(y=>{let b=y.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[];e!=null&&ie(e)&&g.push(e),t!=null&&ie(t)&&g.push(t),r?.maxDepth!=null&&ie(r.maxDepth)&&g.push(r.maxDepth),r?.findCycle!=null&&ie(r.findCycle)&&g.push(r.findCycle);let h=()=>{for(let y of g)if(y.cache===void 0)return!1;return!0},f=()=>{let y=Q(e),b=Q(t);return{from:y,to:b,found:!1,reason:"pending",steps:[],text:"(awaiting reactive args)",toJSON:()=>({from:y,to:b,found:!1,reason:"pending",steps:[]})}},c;try{c=be([o],()=>{if(!h())return f();let y=Q(e),b=Q(t),v={...r?.maxDepth!==void 0?{maxDepth:sn(r.maxDepth)}:{},...r?.findCycle!==void 0?{findCycle:on(r.findCycle)}:{}};return this._explainStatic(y,b,v)},{name:r?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:Q(e),to:Q(t)},equals:(y,b)=>y.found===b.found&&y.reason===b.reason&&y.steps.length===b.steps.length&&er(y.steps,b.steps)})}catch(y){throw l(),i.dispose(),y}let m=oe(c),p=[],_=y=>{let b;return b=y.subscribe(v=>{let w=!1,O=!1;for(let x of v){let k=x[0];k===P?w=!0:(k===L||k===S||k===V)&&(O=!0)}(w||O)&&d(),O&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let y of g)p.push(_(y));return{node:c,dispose(){u=!0,l();for(let y of p)y?.();p.length=0,i.dispose(),m()}}}_pathsMatching(e){let t=Ve(e),r=[];return this._collectObserveTargets("",r),r.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let r of[...this._mounts.keys()].sort()){let s=e===""?r:`${e}${M}${r}`;this._mounts.get(r)._collectObserveTargets(s,t)}for(let r of[...this._nodes.keys()].sort()){let s=this._nodes.get(r),o=e===""?r:`${e}${M}${r}`;t.push([o,s]),this._appendMetaObserveTargets(o,s,t)}}_appendMetaObserveTargets(e,t,r){for(let s of Object.keys(t.meta).sort()){let o=t.meta[s],i=`${e}${M}${Y}${M}${s}`;r.push([i,o]),this._appendMetaObserveTargets(i,o,r)}}observe(e,t){let r=typeof e=="string",o=un(r?t:e);if(o.reactive===!0)return this._observeReactive(r?e:void 0,o);let i=o.structured===!0||o.timeline===!0||o.causal===!0||o.derived===!0||o.detail==="minimal"||o.detail==="full"||o.format!=null,a=o.actor;if(r){let l=e,g=this.resolve(l);if(a!=null&&!g.allowsObserve(a))throw new W({actor:a,action:"observe",nodeName:l});return i?this._buildStructuredObserver([[l,g]],o,"one"):{subscribe(h){return g.subscribe(h)},up(h){try{g.up?.(h)}catch(f){if(f instanceof W)return;throw f}}}}let u=[];this._collectObserveTargets("",u),u.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let d=a==null?u:u.filter(([,l])=>l.allowsObserve(a));return i?this._buildStructuredObserver(d,o,"all"):{subscribe:l=>{let g=d.map(([h,f])=>f.subscribe(c=>{l(h,c)}));return()=>{for(let h of g)h()}},up:(l,g)=>{try{this.resolve(l).up?.(g)}catch(h){if(h instanceof W)return;throw h}}}}_observeReactive(e,t){let r=t.tiers,s=r!=null?new Set(r):null,o=t.reactiveName??"observe";return me(i=>{let a=[],u=!1,d=!1,l=()=>{if(a.length===0||d)return;let m={events:a.slice(),flushedAt_ns:X()};a.length=0,i.emit(m)},g={...t,reactive:!1,structured:!0,timeline:!0},h=e!=null?this.observe(e,g):this.observe(g),f=m=>{d||(a.push(m),!u&&(u=!0,ce(()=>{u=!1,l()})))};for(let m of h.events)f(m);let c=h.onEvent(f);return()=>{d=!0,c(),h.dispose()}},{name:o,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,r){let s=r==="one"?e[0]?.[0]:void 0,o=i=>{if(r==="one"&&s!=null){let l=this.resolve(s);return this._buildStructuredObserver([[s,l]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let u=i.actor,d=u==null?a:a.filter(([,l])=>l.allowsObserve(u));return this._buildStructuredObserver(d,i,"all")};return this._createObserveResult(e,t,o)}_createObserveResult(e,t,r){let s=t.timeline===!0,o=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",u=this.config.inspectorEnabled,d=(o||i)&&u,l=t.maxEvents,g=l!=null&&l>0?new Oe(l):null,h=[],f=new Set,c=t.tiers!=null?new Set(t.tiers):null,m={},p=new Set,_=0,y=0,b=0,v=0,w=0,O=0,x=!1,k=!1,E=0,R=new Map,N=new Map,j=new Map,$=T=>{if(!(c!=null&&!c.has(T.type))){g?g.push(T):h.push(T);for(let C of f)C(T)}},D=T=>c==null||c.has(T),ae=()=>s?{timestamp_ns:X(),in_batch:Ee(),batch_id:E}:{},Be=(T,C)=>{if(!(!d||!(T instanceof I)))return T._setInspectorHook(H=>{if(H.kind==="dep_message")R.set(T,H.depIndex);else if(H.kind==="run"){let we=H.batchData.map((A,B)=>A!=null&&A.length>0?A.at(-1):H.prevData[B]);N.set(T,we);let z=H.batchData.map(A=>A!=null?[...A]:void 0);j.set(T,z),i&&$({type:"derived",path:C,dep_values:we,dep_batches:z,...ae()})}})},xe=T=>{let C=R.get(T),H=N.get(T);if(!o||H==null)return{};let z=(C!=null&&C>=0&&T instanceof I?T._deps[C]:void 0)?.node,A=z?.v,B=j.get(T);return{trigger_dep_index:C,trigger_dep_name:z?.name,...A!=null?{trigger_version:{id:A.id,version:A.version}}:{},dep_values:[...H],...B!=null?{dep_batches:B}:{}}},bt=[],yt=[];for(let[T,C]of e){let H=Be(C,T);H&&bt.push(H),yt.push(C.subscribe(we=>{E++;for(let z of we){let A=z[0],B=ae();if(A===P){m[T]=z[1];let We=C instanceof I?C.lastMutation?.actor??pe:pe;$({type:"data",path:T,data:z[1],actor:We,...B,...xe(C)})}else if(a)A===U?D("dirty")&&_++:A===q?D("resolved")&&y++:A===K?D("invalidate")&&b++:A===J?D("pause")&&v++:A===Z?D("resume")&&w++:A===V?D("teardown")&&O++:A===L&&!p.has(T)?D("complete")&&(x=!0):A===S&&D("error")&&(k=!0,p.add(T));else if(A===U)D("dirty")&&_++,$({type:"dirty",path:T,...B});else if(A===q)D("resolved")&&y++,$({type:"resolved",path:T,...B,...xe(C)});else if(A===K)D("invalidate")&&b++,$({type:"invalidate",path:T,...B});else if(A===J)D("pause")&&v++,$({type:"pause",path:T,lockId:z[1],...B});else if(A===Z)D("resume")&&w++,$({type:"resume",path:T,lockId:z[1],...B});else if(A===L)D("complete")&&!p.has(T)&&(x=!0),$({type:"complete",path:T,...B});else if(A===S){D("error")&&(k=!0,p.add(T));let We=C instanceof I?C.lastMutation?.actor??pe:pe;$({type:"error",path:T,data:z[1],actor:We,...B})}else A===V&&(D("teardown")&&O++,$({type:"teardown",path:T,...B}))}}))}let Ue=!1,He=()=>{if(!Ue){Ue=!0;for(let T of yt)T();for(let T of bt)T();for(let T of ke)T({value:void 0,done:!0});ke.length=0}},ze=[],ke=[];f.add(T=>{let C=ke.shift();C?C({value:T,done:!1}):ze.push(T)});let vt={get values(){return m},get dirtyCount(){return _},get resolvedCount(){return y},get invalidateCount(){return b},get pauseCount(){return v},get resumeCount(){return w},get teardownCount(){return O},get events(){return g?g.toArray():[...h]},get anyCompletedCleanly(){return x},get anyErrored(){return k},get completedWithoutErrors(){return x&&!k},onEvent(T){return f.add(T),()=>f.delete(T)},dispose:He,expand(T){He();let C={...t};return typeof T=="string"?C.detail=T:Object.assign(C,T),r(un(C))},[Symbol.asyncIterator](){return{next(){return ze.length>0?Promise.resolve({value:ze.shift(),done:!1}):Ue?Promise.resolve({value:void 0,done:!0}):new Promise(T=>ke.push(T))},return(){return He(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(vt,t),vt}_attachFormatLogger(e,t){let r=t.format;if(r==null)return;let s=t.logger??(c=>console.log(c)),o=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=o==null&&i==null?()=>!0:c=>(o==null||o.has(c))&&(i==null||!i.has(c)),u=Yn(t.theme),d=r==="stage-log"?X():0,l=c=>c==null?"":t.stageLabels?.[c]??c,g=(c,m)=>c.length>m?`${c.slice(0,m-1)}\u2026`:c,h=c=>c.type==="data"||c.type==="error"?g(ht(c.data),120):"",f=c=>{if(r==="stage-log"){let x=(X()-d)/1e9,k=l(c.path).padEnd(9);if(c.type==="data"){let E=h(c);return`[${x.toFixed(3)}s] ${k} \u2190${E?` ${E}`:""}`}if(c.type==="error"){let E=h(c);return`[${x.toFixed(3)}s] ${k} \u2717${E?` ${E}`:""}`}return c.type==="complete"?`[${x.toFixed(3)}s] ${k} \u25A0 complete`:`[${x.toFixed(3)}s] ${k} ${c.type}`}if(r==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let m=u[c.type]??"",p=c.path?`${u.path}${c.path}${u.reset} `:"",_=c.type==="data"||c.type==="error",y=c.type==="pause"||c.type==="resume",b=_?` ${ht(c.data)}`:y?` ${ht(c.lockId)}`:"",v=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,w=v?.trigger_dep_name!=null?` <- ${v.trigger_dep_name}`:v?.trigger_dep_index!=null?` <- #${v.trigger_dep_index}`:"",O=c.in_batch?" [batch]":"";return`${p}${m}${c.type.toUpperCase()}${u.reset}${b}${w}${O}`};e.onEvent(c=>{a(c.type)&&s(f(c),c)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){rn(this._disposers,this.name),this.signal([[V]],{internal:!0}),rn(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,this._destroyed=!0}get destroyed(){return this._destroyed}_destroyClearOnly(){for(let e of[...this._mounts.values()])e._parent=void 0,e._destroyClearOnly();this._mounts.clear(),this._nodes.clear(),this._parent=void 0,this._destroyed=!0}snapshot(e){let{expand:t,...r}=this.describe({detail:"full"}),s={};for(let a of Object.keys(r.nodes).sort()){let{lastMutation:u,guard:d,...l}=r.nodes[a];s[a]=l}let o=[...r.subgraphs].sort(),i={...r,version:1,nodes:s,subgraphs:o};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 xt(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let r=t?.config??he,{codec:s,codecVersion:o,payload:i}=kt(e,r);return s.decode(i,o)}restore(e,t){if(an(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let r=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(o=>Ve(o)),s=t?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(r!==null&&!r.some(a=>a.test(o)))continue;let i=e.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(o,new Error(`restore: slice.value is undefined for "${o}" (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 u=this.tryResolve(o)?.v;if(u!=null&&u.id===i.v.id&&u.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){t?.onError?.(o,a)}}}}}static fromSnapshot(e,t){an(e);let r=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,o=new n(e.name);if(r)return r(o),o.restore(e),o;for(let f of[...e.subgraphs].sort((c,m)=>{let p=c.split(M).length,_=m.split(M).length;return p!==_?p-_:c<m?-1:c>m?1:0})){let c=f.split(M),m=o;for(let p of c)m._mounts.has(p)||m.mount(p,new n(p)),m=m._mounts.get(p)}let i=s?Object.entries(s).map(([f,c])=>({re:Ve(f),factory:c})):[],a=f=>{for(let c of i)if(c.re.test(f))return c.factory},u=f=>{let c=f.split(M),m=c.pop();if(m==null||m.length===0)throw new Error(`invalid snapshot path "${f}"`);let p=o;for(let _ of c){let y=p._mounts.get(_);if(!y)throw new Error(`unknown mount "${_}" in path "${f}"`);p=y}return[p,m]},d=Object.entries(e.nodes).filter(([f])=>!f.includes(`${M}${Y}${M}`)).sort((f,c)=>f[0]<c[0]?-1:f[0]>c[0]?1:0),l=new Map(d),g=new Map,h=!0;for(;l.size>0&&h;){h=!1;for(let[f,c]of[...l.entries()]){let m=c?.deps??[];if(!m.every(w=>g.has(w)))continue;let[p,_]=u(f),y={...c?.meta??{}},b=a(f),v;if(c?.type==="state")v=se(c.value,{meta:y});else{if(b==null)continue;v=b(_,{path:f,type:c.type,value:c.value,meta:y,deps:m,resolvedDeps:m.map(w=>g.get(w))})}p.add(v,{name:_}),g.set(f,v),l.delete(f),h=!0}}if(l.size>0){let f=[...l.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${f}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return o.restore(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let r=e.map(d=>({tier:d,debounceMs:Math.max(0,d.debounceMs??0),compactEvery:Math.max(1,d.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=(d,l)=>{if(d.disposed)return;let g=Hn(l.nodes);if(d.lastSnapshot!=null&&g!==""&&g===d.lastFingerprint)return;let h=d.seq+1,f=Ce(),p=d.lastSnapshot==null||h%d.compactEvery===0?{name:this.name,mode:"full",snapshot:l,seq:h,timestamp_ns:f,format_version:ye}:{name:this.name,mode:"diff",diff:Qn(d.lastSnapshot,l),seq:h,timestamp_ns:f,format_version:ye};if(d.tier.filter&&!d.tier.filter(p))return;let _;try{_=d.tier.save(p)}catch(y){t.onError?.(y,d.tier);return}if(_&&typeof _.then=="function"){let v=(d.savePending??Promise.resolve()).then(()=>_,()=>_).then(()=>{d.disposed||(d.seq=h,d.lastSnapshot=l,d.lastFingerprint=g)},w=>{t.onError?.(w,d.tier)});d.savePending=v.finally(()=>{d.savePending===v&&(d.savePending=void 0)})}else d.seq=h,d.lastSnapshot=l,d.lastFingerprint=g},o=(d,l)=>{try{s(d,l)}catch(g){t.onError?.(g,d.tier)}},i=(d,l)=>{if(!l.some(c=>{let m=this.config.messageTier(c[0]);return m>=3&&m<5}))return;if(t.filter){let c=this.tryResolve(d);if(c==null)return;let m=dt(c,at("standard"));if(!t.filter(d,m))return}let h,f=()=>(h==null&&(h=this.snapshot()),h);for(let c of r)c.disposed||(c.debounceMs===0?o(c,f()):(c.timer==null&&(c.timer=new Ie),c.timer.start(c.debounceMs,()=>{c.disposed||o(c,this.snapshot())})))},a;if(t.paths!=null){let l=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(g=>{let h=this.tryResolve(g);return h==null?()=>{}:h.subscribe(f=>i(g,f))});a=()=>{for(let g of l)g()}}else a=this.observe().subscribe((d,l)=>i(d,l));let u=()=>{a();for(let d of r)d.disposed=!0,d.timer?.cancel();this._storageDisposers.delete(u)};return this._storageDisposers.add(u),{dispose:u}}async _cascadeRestore(e,t){for(let r of e){let s;try{s=await r.load?.()}catch(i){t?.(i,r);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let o=s;try{if(o.mode==="full"&&o.snapshot!=null)return this.restore(o.snapshot),!0;if(o.version===ye&&o.nodes!=null)return this.restore(o),!0}catch(i){t?.(i,r)}}return!1}static async fromStorage(e,t,r){for(let s of t){let o;try{o=await s.load?.()}catch(u){r?.onError?.(u,s);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let i=o,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===ye&&i.nodes!=null?i:void 0;if(a!=null)try{return n.fromSnapshot(a,r)}catch(u){r?.onError?.(u,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,r){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:X(),...r?.actor!=null?{actor:r.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)),r=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return r}static diff(e,t){let r=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),o=[...s].filter(y=>!r.has(y)).sort(),i=[...r].filter(y=>!s.has(y)).sort(),a=[],u=[];for(let y of r){if(!s.has(y))continue;let b=e.nodes[y],v=t.nodes[y],w=b.v,O=v.v;w!=null&&O!=null&&w.id===O.id&&w.version!==O.version&&u.push({path:y,id:w.id,from:w.version,to:O.version});let x=w!=null&&O!=null&&w.id===O.id&&w.version===O.version;for(let k of["type","status","sentinel"]){let E=b[k],R=v[k];E!==R&&a.push({path:y,field:k,from:E,to:R})}if(!x)for(let k of["value","meta"]){let E=b[k],R=v[k];zn(E,R)||a.push({path:y,field:k,from:E,to:R})}}let d=y=>`${y.from} ${y.to}`,l=new Set(e.edges.map(d)),g=new Set(t.edges.map(d)),h=t.edges.filter(y=>!l.has(d(y))),f=e.edges.filter(y=>!g.has(d(y))),c=new Set(e.subgraphs),m=new Set(t.subgraphs),p=[...m].filter(y=>!c.has(y)).sort(),_=[...c].filter(y=>!m.has(y)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:u,edgesAdded:h,edgesRemoved:f,subgraphsAdded:p,subgraphsRemoved:_}}}});function pn(n,e,t){return{[n]:!0,[`${n}_type`]:e,...t??{}}}var hn=G(()=>{"use strict"});var sr={};vn(sr,{feedback:()=>nr,funnel:()=>tr,scorer:()=>rr});module.exports=_n(sr);Se();ne();ge();$e();Ut();fn();hn();Ne();ne();function gn(n,e){let t=n.cache??0;return t>=e?!1:(n.down([[U],[P,t+1]]),!0)}var fs=Dt((n,e)=>{n("observe"),n("signal"),e("write")});lt();function mt(n,e){return pn("reduction",n,e)}function tr(n,e,t,r){if(e.length===0)throw new RangeError("funnel requires at least one source");if(t.length===0)throw new RangeError("funnel requires at least one stage");let s=new ve(n,r),o=e.length===1?e[0]:Vt(...e);s.add(o,{name:"merged"});let i="merged";for(let a=0;a<t.length;a++){let u=t[a],d=new ve(u.name);u.build(d);try{d.resolve("input")}catch{throw new Error(`funnel stage "${u.name}" must define an "input" node`)}try{d.resolve("output")}catch{throw new Error(`funnel stage "${u.name}" must define an "output" node`)}s.mount(u.name,d);let l=s.resolve(i),g=`${u.name}::input`,h=s.resolve(g),f=`__bridge_${i}\u2192${u.name}_input`,c=Ft([l],([m])=>{h.emit(m)},{name:f});s.add(c,{name:f}),s.addDisposer(oe(c)),i=`${u.name}::output`}return s}function nr(n,e,t,r){let s=r?.maxIterations??10,o=`__feedback_${e}`,i=se(0,{meta:mt("feedback_counter",{maxIterations:s,feedbackFrom:e,feedbackTo:t})});n.add(i,{name:o});let a=n.resolve(e),u=n.resolve(t),d=`__feedback_effect_${e}`,l=re([],(g,h)=>{let f=a.subscribe(c=>{for(let m of c){let p=m[0];if(p===P){let _=m[1];if(_==null)return;Re(()=>{gn(i,s)&&u.emit(_)})}else if(p===L||p===S){let _=p===S&&m.length>1?[S,m[1]]:[p];i.down([_])}}});return()=>f()},{name:d,describeKind:"effect",meta:{...mt("feedback_effect",{feedbackFrom:e,feedbackTo:t}),_internal:!0}});return n.add(l,{name:d}),n.addDisposer(oe(l)),n}function rr(n,e,t){if(n.length===0)throw new RangeError("scorer requires at least one source");if(n.length!==e.length)throw new RangeError("scorer requires the same number of sources and weights");let r=[...n,...e],s=n.length,o=t?.scoreFns;return be(r,i=>{let a=i.slice(0,s),u=i.slice(s),d=[],l=0;for(let g=0;g<s;g++){let h=a[g]??0,f=u[g]??0,m=(o?.[g]?o[g](h):h)*f;d.push(m),l+=m}return{value:a,score:l,breakdown:d}},{...t?{equals:t.equals,resubscribable:t.resubscribable,resetOnTeardown:t.resetOnTeardown}:{},describeKind:"derived",meta:mt("scorer",t?.meta)})}0&&(module.exports={feedback,funnel,scorer});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import '../../node-
|
|
2
|
-
import '../../graph-
|
|
3
|
-
export { F as FeedbackOptions, a as FunnelOptions, b as FunnelStage, S as ScoredItem, c as ScorerOptions, d as StepRef, f as feedback, e as funnel, s as scorer } from '../../index-
|
|
4
|
-
import '../../meta-
|
|
1
|
+
import '../../node-ClS5yC-B.cjs';
|
|
2
|
+
import '../../graph-C4SHb3Ly.cjs';
|
|
3
|
+
export { F as FeedbackOptions, a as FunnelOptions, b as FunnelStage, S as ScoredItem, c as ScorerOptions, d as StepRef, f as feedback, e as funnel, s as scorer } from '../../index-CZjOhcBy.cjs';
|
|
4
|
+
import '../../meta-vE8bxW1E.cjs';
|
|
5
5
|
import '../../extra/storage-core.cjs';
|
|
6
6
|
import '../../extra/storage-tiers.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import '../../node-
|
|
2
|
-
import '../../graph-
|
|
3
|
-
export { F as FeedbackOptions, a as FunnelOptions, b as FunnelStage, S as ScoredItem, c as ScorerOptions, d as StepRef, f as feedback, e as funnel, s as scorer } from '../../index-
|
|
4
|
-
import '../../meta-
|
|
1
|
+
import '../../node-ClS5yC-B.js';
|
|
2
|
+
import '../../graph-7VguS7a4.js';
|
|
3
|
+
export { F as FeedbackOptions, a as FunnelOptions, b as FunnelStage, S as ScoredItem, c as ScorerOptions, d as StepRef, f as feedback, e as funnel, s as scorer } from '../../index-Bf7eqeSF.js';
|
|
4
|
+
import '../../meta-BgVAsg9j.js';
|
|
5
5
|
import '../../extra/storage-core.js';
|
|
6
6
|
import '../../extra/storage-tiers.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c}from"../../chunk-
|
|
1
|
+
import{a,b,c}from"../../chunk-G5VBJ5K6.js";import"../../chunk-3ZZX7M25.js";import"../../chunk-L6NSJVJZ.js";import"../../chunk-LDQ3IUIP.js";import"../../chunk-ACMJ2ZPS.js";import"../../chunk-ESMPEKEV.js";import"../../chunk-6YFZMUMR.js";import"../../chunk-4VVTGLXJ.js";import"../../chunk-2K5RXLAH.js";import"../../chunk-35JTVPOX.js";import"../../chunk-LYCLF26R.js";import"../../chunk-CK2E7BTU.js";import"../../chunk-QYADASLV.js";export{b as feedback,a as funnel,c as scorer};
|