@graphrefly/graphrefly 0.40.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-CKFQS2CJ.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-I2DEVPMU.js → chunk-5QRRKBUT.js} +1 -1
- package/dist/chunk-5ST42ESJ.js +1 -0
- package/dist/{chunk-FHRBBHJN.js → chunk-6YFZMUMR.js} +1 -1
- package/dist/{chunk-MNZIKXK4.js → chunk-7ARY3Y3T.js} +1 -1
- package/dist/chunk-7B7ELAT2.js +1 -0
- package/dist/{chunk-Z4F3DOWS.js → chunk-7VKFXLZQ.js} +1 -1
- package/dist/chunk-ACMJ2ZPS.js +3 -0
- package/dist/{chunk-32N3JALT.js → chunk-AGNM6RS6.js} +1 -1
- package/dist/chunk-AS3TV2TV.js +1 -0
- package/dist/{chunk-B7LCDQEV.js → chunk-CISGGAIF.js} +1 -1
- package/dist/{chunk-N43XM7BM.js → chunk-DEJTNNQC.js} +1 -1
- package/dist/{chunk-2QXRYP7Q.js → chunk-FDZAZNRO.js} +1 -1
- package/dist/{chunk-QSK3RRII.js → chunk-FUZ6S2DY.js} +1 -1
- package/dist/{chunk-LYM4PBMV.js → chunk-G5VBJ5K6.js} +1 -1
- package/dist/{chunk-6I726LZU.js → chunk-HZKW2AAB.js} +1 -1
- package/dist/{chunk-LCGAVGGV.js → chunk-IZM3UEH3.js} +3 -3
- package/dist/{chunk-2DMKW2AD.js → chunk-KCACBSJH.js} +1 -1
- package/dist/{chunk-SSCGRYJ2.js → chunk-KT5DTRBP.js} +1 -1
- package/dist/{chunk-WL6LFPJB.js → chunk-KY2LMAXU.js} +1 -1
- package/dist/{chunk-YXDRGKXP.js → chunk-LDQ3IUIP.js} +1 -1
- package/dist/chunk-LPRWATHB.js +61 -0
- package/dist/{chunk-6VWBPSSY.js → chunk-NWXQIOIB.js} +3 -3
- package/dist/{chunk-XW4YDF6G.js → chunk-Q7QQQA3I.js} +1 -1
- package/dist/chunk-VE5SIZEM.js +1 -0
- package/dist/chunk-VRALOYRD.js +1 -0
- package/dist/{chunk-XJLYLLIJ.js → chunk-WHMUB5QB.js} +1 -1
- package/dist/chunk-XLQPNNIC.js +1 -0
- package/dist/{chunk-JKBOIJ22.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-BTHOTC0Q.d.cts → index-3NmAfcH0.d.cts} +25 -7
- package/dist/{index-D1IEZUsj.d.ts → index-4Uz-e_fL.d.ts} +573 -213
- 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-IUCY0OFN.d.ts → index-CJQm0g38.d.ts} +25 -7
- 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-DJ_MPOJ5.d.cts → index-D-Xs74HZ.d.cts} +573 -213
- 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-2BX4NB34.js +0 -3
- package/dist/chunk-6XVD5TZV.js +0 -1
- package/dist/chunk-756D5TFD.js +0 -1
- package/dist/chunk-7Q4ZD3YW.js +0 -1
- package/dist/chunk-ECQRP2UT.js +0 -1
- package/dist/chunk-INQFTVZA.js +0 -61
- package/dist/chunk-J63M5U46.js +0 -1
- package/dist/chunk-K2Z7UENB.js +0 -1
- package/dist/chunk-OSZ22J7O.js +0 -1
- package/dist/chunk-PPUYQ66A.js +0 -1
- package/dist/chunk-RZJDIV2G.js +0 -1
- package/dist/chunk-SGS4OJGS.js +0 -1
- package/dist/chunk-SVFKHUCW.js +0 -1
- package/dist/chunk-UWA6D7UF.js +0 -3
- package/dist/chunk-VMF23LGB.js +0 -1
- package/dist/chunk-WUT362QV.js +0 -1
- package/dist/chunk-YKD7WUYJ.js +0 -43
- 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-S33JV6XC.js +0 -1
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";var bt=Object.defineProperty;var Vn=Object.getOwnPropertyDescriptor;var zn=Object.getOwnPropertyNames;var Bn=Object.prototype.hasOwnProperty;var W=(r,e)=>()=>(r&&(e=r(r=0)),e);var jn=(r,e)=>{for(var t in e)bt(r,t,{get:e[t],enumerable:!0})},Hn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of zn(e))!Bn.call(r,o)&&o!==t&&bt(r,o,{get:()=>e[o],enumerable:!(n=Vn(e,o))||n.enumerable});return r};var Un=r=>Hn(bt({},"__esModule",{value:!0}),r);function Ue(){return Ie>0||je}function Ht(){return Ie>0}function Fe(r){Ie>0?He.push(r):r()}function ae(r){Ie+=1;let e=!1;try{r()}catch(t){throw e=!0,t}finally{if(Ie-=1,Ie===0)if(e){if(!je){let t=He.splice(0);for(let n of t)try{n()}catch{}ke.length=0,Re.length=0,Pe.length=0}}else Wn()}}function Wn(){let r=!je;r&&(je=!0);let e=[],t=0;try{for(;ke.length>0||Re.length>0||Pe.length>0||r&&He.length>0;){if(r&&He.length>0){let s=He.splice(0);for(let a of s)try{a()}catch(i){e.push(i)}continue}if(t+=1,t>1e3)throw ke.length=0,Re.length=0,Pe.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let o=(ke.length>0?ke:Re.length>0?Re:Pe).splice(0);for(let s of o)try{s()}catch(a){e.push(a)}}}finally{r&&(je=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function We(r,e,t){if(e.length===0)return;if(e.length===1){let u=t(e[0][0]);if(u<3||!Ue()){r(e);return}(u>=5?Pe:u===4?Re:ke).push(()=>r(e));return}let n=e.length,o=n,s=n,a=n,i=0;for(;i<n&&t(e[i][0])<3;)i++;for(o=i;i<n&&t(e[i][0])===3;)i++;for(s=i;i<n&&t(e[i][0])===4;)i++;a=i;let d=Ue();if(o>0){let u=e.slice(0,o);r(u)}if(s>o){let u=e.slice(o,s);d?ke.push(()=>r(u)):r(u)}if(a>s){let u=e.slice(s,a);d?Re.push(()=>r(u)):r(u)}if(n>a){let u=e.slice(a,n);d?Pe.push(()=>r(u)):r(u)}}var Ie,je,ke,Re,Pe,He,$e=W(()=>{"use strict";Ie=0,je=!1,ke=[],Re=[],Pe=[],He=[]});function J(){return Math.trunc(performance.now()*1e6)}function et(){return Date.now()*1e6}var qe=W(()=>{"use strict"});var ue,I,q,K,re,ie,ce,H,F,G,Se,tt,Ut,nt,Wt,qt,rt,yt,vt,Tt,st,le=W(()=>{"use strict";ue=Symbol.for("graphrefly/START"),I=Symbol.for("graphrefly/DATA"),q=Symbol.for("graphrefly/DIRTY"),K=Symbol.for("graphrefly/RESOLVED"),re=Symbol.for("graphrefly/INVALIDATE"),ie=Symbol.for("graphrefly/PAUSE"),ce=Symbol.for("graphrefly/RESUME"),H=Symbol.for("graphrefly/TEARDOWN"),F=Symbol.for("graphrefly/COMPLETE"),G=Symbol.for("graphrefly/ERROR"),Se=Object.freeze([q]),tt=Object.freeze([K]),Ut=Object.freeze([re]),nt=Object.freeze([ue]),Wt=Object.freeze([F]),qt=Object.freeze([H]),rt=Object.freeze([Se]),yt=Object.freeze([tt]),vt=Object.freeze([Ut]),Tt=Object.freeze([Wt]),st=Object.freeze([qt])});function Yt(r,e){let t=new TextEncoder().encode(r.name);if(t.length===0||t.length>255)throw new Error(`encodeEnvelope: codec name "${r.name}" encodes to ${t.length} bytes (must be 1\u2013255)`);let n=r.version;if(!Number.isInteger(n)||n<0||n>65535)throw new Error(`encodeEnvelope: codec.version ${n} out of u16 range (expected integer 0\u201365535)`);let o=2+t.length+2+e.length;if(o>4294967295)throw new Error(`encodeEnvelope: total envelope size ${o} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let s=new Uint8Array(o),a=0;return s[a++]=_t,s[a++]=t.length,s.set(t,a),a+=t.length,s[a++]=n>>>8&255,s[a++]=n&255,s.set(e,a),s}function Jt(r,e){if(r.length<Kt)throw new Error(`decodeEnvelope: bytes too short (${r.length} < ${Kt})`);let t=0,n=r[t++];if(n!==_t)throw new Error(`decodeEnvelope: unsupported envelope version ${n} (expected ${_t})`);let o=r[t++];if(o===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+o+2>r.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+o+2} bytes, have ${r.length})`);let s=new TextDecoder().decode(r.subarray(t,t+o));t+=o;let a=(r[t]<<8|r[t+1])>>>0;t+=2;let i=r.subarray(t),d=e.lookupCodec(s);if(d==null)throw new Error(`decodeEnvelope: codec "${s}" not registered (envelope codec_v=${a})`);return{codec:d,codecVersion:a,payload:i}}function Xt(r){r.registerCodec(qn)}var qn,_t,Kt,wt=W(()=>{"use strict";qn={name:"json",version:1,contentType:"application/json",encode(r){let e=JSON.stringify(r);return new TextEncoder().encode(e)},decode(r,e){let t=new TextDecoder().decode(r);return JSON.parse(t)}},_t=1,Kt=4});function ot(r){if(r==null)return Le;let{type:e,id:t,...n}=r;return{type:e??"system",id:t??"",...n}}var Le,it=W(()=>{"use strict";Le={type:"system",id:""}});function Zt(r){r.registerMessageType(ue,{tier:0,wireCrossing:!1}),r.registerMessageType(q,{tier:1,wireCrossing:!1}),r.registerMessageType(re,{tier:1,wireCrossing:!1,metaPassthrough:!1}),r.registerMessageType(ie,{tier:2,wireCrossing:!1}),r.registerMessageType(ce,{tier:2,wireCrossing:!1}),r.registerMessageType(I,{tier:3,wireCrossing:!0}),r.registerMessageType(K,{tier:3,wireCrossing:!0}),r.registerMessageType(F,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(G,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(H,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var at,Qt=W(()=>{"use strict";le();at=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 n=this._messageTypes.get(t);return n!=null?n.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 Nt(r){let e=Kn.filter(t=>r({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 se,Kn,Ke=W(()=>{"use strict";se=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}},Kn=["human","llm","wallet","system"]});function Ot(r){if(r===void 0)return null;if(typeof r=="number"){if(!Number.isFinite(r))throw new TypeError(`Cannot hash non-finite number: ${r}`);if(Number.isInteger(r)&&!Number.isSafeInteger(r))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${r}. Cross-language cid parity is not guaranteed for unsafe integers.`);return r}if(typeof r=="string"||typeof r=="boolean"||r===null)return r;if(Array.isArray(r))return r.map(Ot);if(typeof r=="object"&&r!==null){let e={};for(let t of Object.keys(r).sort())e[t]=Ot(r[t]);return e}return null}function Xn(r){let e=Jn.encode(r),t=e.length,n=t*8,o=t+9+63&-64,s=new Uint8Array(o);s.set(e),s[t]=128;let a=new DataView(s.buffer);a.setUint32(o-4,n>>>0,!1),a.setUint32(o-8,Math.floor(n/4294967296)>>>0,!1);let i=1779033703,d=3144134277,u=1013904242,l=2773480762,f=1359893119,p=2600822924,h=528734635,c=1541459225,y=new Uint32Array(64),m=(v,b)=>v>>>b|v<<32-b;for(let v=0;v<o;v+=64){for(let x=0;x<16;x++)y[x]=a.getUint32(v+x*4,!1);for(let x=16;x<64;x++){let A=y[x-15],M=y[x-2],C=m(A,7)^m(A,18)^A>>>3,ee=m(M,17)^m(M,19)^M>>>10;y[x]=y[x-16]+C+y[x-7]+ee>>>0}let b=i,T=d,_=u,k=l,g=f,w=p,E=h,S=c;for(let x=0;x<64;x++){let A=m(g,6)^m(g,11)^m(g,25),M=g&w^~g&E,C=S+A+M+Yn[x]+y[x]>>>0,ee=m(b,2)^m(b,13)^m(b,22),te=b&T^b&_^T&_,he=ee+te>>>0;S=E,E=w,w=g,g=k+C>>>0,k=_,_=T,T=b,b=C+he>>>0}i=i+b>>>0,d=d+T>>>0,u=u+_>>>0,l=l+k>>>0,f=f+g>>>0,p=p+w>>>0,h=h+E>>>0,c=c+S>>>0}let N=v=>v.toString(16).padStart(8,"0");return N(i)+N(d)+N(u)+N(l)+N(f)+N(p)+N(h)+N(c)}function xt(r){let e=Ot(r??null),t=JSON.stringify(e);return Xn(t).slice(0,16)}function Zn(){let r=globalThis.crypto;if(r?.randomUUID)return r.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 Et(r,e,t){let n=t?.id??Zn();if(r===0)return{id:n,version:0};let s=(t?.hash??xt)(e);return{id:n,version:0,cid:s,prev:null}}function en(r,e,t){r.version+=1,"cid"in r&&(r.prev=r.cid,r.cid=t(e))}var Yn,Jn,tn=W(()=>{"use strict";Yn=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]),Jn=new TextEncoder});function sn(r){return{node:r,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function kt(r){r.prevData=void 0,r.dirty=!1,r.involvedThisWave=!1,r.dataBatch.length=0,r.terminal=void 0}function dt(r){return r.length===0?r:typeof r[0]=="symbol"?[r]:r}function Q(r,e,t){let n=on(r)?r:[],o=typeof r=="function"?r:typeof e=="function"?e:void 0,s={};return on(r)?s=(Rt(e)?e:t)??{}:Rt(r)?s=r:s=(Rt(e)?e:t)??{},new B(n,o,s)}var nn,rn,Qn,er,Ve,B,on,Rt,fe=W(()=>{"use strict";wt();it();$e();qe();Qt();Ke();le();tn();nn=()=>{},rn=100;Qn=(r,e,t,n)=>{t.direction==="down-in"&&r._onDepMessage(t.depIndex,e)},er=(r,e,t,n)=>{let o=r;if(o._status==="completed"||o._status==="errored")return;let s=o._cached,a=s===void 0?[nt]:[nt,[I,s]];o._status==="dirty"&&a.push(Se),We(e,a,o._config.tierOf)},Ve=new at({onMessage:Qn,onSubscribe:er});Zt(Ve);Xt(Ve);B=class r{_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,n){this._config=n.config??Ve,this._config.onMessage,this._optsName=n.name,this._describeKind=n.describeKind,this._equals=n.equals??Object.is,this._resubscribable=n.resubscribable??!1,this._resetOnTeardown=n.resetOnTeardown??!1,this._autoComplete=n.completeWhenDepsComplete??!0,this._autoError=n.errorWhenDepsError??!0,this._pausable=n.pausable??!0,this._guard=n.guard,this._fn=t,this._partial=n.partial??!1,this._cached=n.initial!==void 0?n.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=n.versioningHash??this._config.defaultHashFn??xt;let o=n.versioning??this._config.defaultVersioning;this._versioningLevel=o,this._versioning=o!=null?Et(o,this._cached===void 0?void 0:this._cached,{id:n.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(sn);let s={};for(let[i,d]of Object.entries(n.meta??{})){let u={initial:d,name:`${n.name??"node"}:meta:${i}`,describeKind:"state",config:this._config};n.guard!=null&&(u.guard=n.guard),s[i]=new r([],void 0,u)}Object.freeze(s),this.meta=s,this._hasMeta=Object.keys(s).length>0;let a=this;this._actions={emit(i){a._emit([[I,i]])},down(i){a._emit(dt(i))},up(i){a._emitUp(dt(i))}},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 n=this._versioningLevel;if(n!=null&&e<=n)return;let o=t?.hash??this._hashFn;o!==this._hashFn&&(this._hashFn=o);let s=this._cached===void 0?void 0:this._cached,a=this._versioning,i=a?.id??t?.id,d=a?.version??0,u=Et(e,s,{id:i,hash:o});u.version=d,this._versioning=u,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=ot(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let n of this._extraGuards)if(!n(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,n=e?.actor!=null;if(!t&&!n)return;let o=ot(e?.actor),s=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(o,s))throw new se({actor:o,action:s,nodeName:this.name});if(this._extraGuards!=null){for(let a of this._extraGuards)if(!a(o,s))throw new se({actor:o,action:s,nodeName:this.name})}this._lastMutation={actor:o,timestamp_ns:et()}}down(e,t){let n=dt(e);n.length!==0&&(this._checkGuard(t),this._emit(n))}emit(e,t){this._checkGuard(t),this._emit([[I,e]])}up(e,t){if(this._deps.length===0)return;let n=dt(e);if(n.length===0)return;this._checkGuard(t);let o=t??{internal:!0};this._validateUpTiers(n);for(let s of this._deps)s.node.up?.(n,o)}_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 n of e){let o=t(n[0]);if(o===3||o===4)throw new Error(`Node "${this.name}": tier-${o} 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 d=ot(t);if(!this._guard(d,"observe"))throw new se({actor:d,action:"observe",nodeName:this.name})}let o=this._isTerminal&&this._resubscribable;if(o){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 d of this._deps)kt(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let s;try{s=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:o},this._actions)}catch(d){throw this._sinkCount-=1,d}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let a=this._isTerminal;if(this._sinkCount===1&&!a)try{this._activate()}catch(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof s=="function")try{s()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let i=!1;return()=>{i||(i=!0,this._sinkCount-=1,this._removeSink(e),typeof s=="function"&&s(),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 n=0;n<e;n++){let o=n,s=this._deps[n];s.unsub=nn,s.unsub=s.node.subscribe(a=>{if(s.unsub===null)return;let i=this._config.tierOf,d=!1;for(let u of a)i(u[0])>=3&&(d=!0),this._config.onMessage(this,u,{direction:"down-in",depIndex:o},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(n){this._deps[t].unsub=null;for(let o=0;o<t;o++){let s=this._deps[o];if(s.unsub!=null){let a=s.unsub;s.unsub=null;try{a()}catch{}kt(s)}}throw this._dirtyDepCount=0,n}}_addDep(e){for(let o=0;o<this._deps.length;o++)if(this._deps[o].node===e)return o;let t=this._deps.length,n=sn(e);if(this._deps.push(n),this._sinks==null)return t;n.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(rt),n.unsub=nn;try{n.unsub=e.subscribe(o=>{if(n.unsub===null)return;let s=this._config.tierOf,a=!1;for(let i of o)s(i[0])>=3&&(a=!0),this._config.onMessage(this,i,{direction:"down-in",depIndex:t},this._actions);a&&this._maybeRunFnOnSettlement()})}catch(o){throw n.unsub=null,this._deps.pop(),this._dirtyDepCount--,o}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(n){this._emit([[G,this._wrapFnError("cleanup threw",n)]])}else if(t!=null&&typeof t=="object"){let n=t.deactivate;if(typeof n=="function")try{n()}catch(o){this._emit([[G,this._wrapFnError("cleanup.deactivate threw",o)]])}}for(let n of this._deps){if(n.unsub!=null){let o=n.unsub;n.unsub=null;try{o()}catch{}}kt(n)}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 n=this._deps[e],o=t[0];if(this._inspectorHooks!=null){let s={kind:"dep_message",depIndex:e,message:t};for(let a of this._inspectorHooks)a(s)}if(o!==ue){if(o===q){this._depDirtied(n);return}if(o===re){if(this._depInvalidated(n),this._cached===void 0)return;this._emit(vt);return}if(o===ie||o===ce){this._emit([t]);return}if(o===H){this._emit(st);return}if(o===I)this._depSettledAsData(n,t[1]);else if(o===K)this._depSettledAsResolved(n);else if(o===F)this._depSettledAsTerminal(n,!0);else if(o===G)this._depSettledAsTerminal(n,t[1]);else{this._emit([t]);return}if(!this._fn){(o===I||o===K)&&this._emit([t]),(o===F||o===G)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(rt))}_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(yt),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([[G,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(Tt)}_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(a){this._emit([[G,this._wrapFnError("cleanup threw",a)]]);return}}else if(e!=null&&typeof e=="object"){let a=e.beforeRun;if(typeof a=="function"){e.beforeRun=void 0;try{a()}catch(i){this._emit([[G,this._wrapFnError("cleanup.beforeRun threw",i)]]);return}}}let t=this._deps.map(a=>a.involvedThisWave?a.dataBatch.length>0?[...a.dataBatch]:[]:void 0),n=this._deps.map(a=>a.prevData);for(let a=0;a<this._deps.length;a++){let i=t[a];i!=null&&i.length>0&&(this._deps[a].prevData=i[i.length-1])}let o=this._deps.map(a=>a.terminal),s={prevData:n,terminalDeps:o,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let a={kind:"run",batchData:t,prevData:n};for(let i of this._inspectorHooks)i(a)}this._isExecutingFn=!0;try{let a=this._fn(t,this._actions,s);if(typeof a=="function")this._cleanup=a;else if(a!=null&&typeof a=="object"){let i=a;(typeof i.beforeRun=="function"||typeof i.deactivate=="function"||typeof i.invalidate=="function")&&(this._cleanup=a)}}catch(a){this._emit([[G,this._wrapFnError("fn threw",a)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>rn?(this._rerunDepth=0,this._emit([[G,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${rn} \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 n=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${n}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[Se,e[0]]:e;let n=!0,o=!1,s=!1,a=-1;for(let d of e){let u=t(d[0]);u<a&&(n=!1),u===3&&(o=!0),d[0]===q&&(s=!0),a=u}let i=e;if(!n){let d=e.map((u,l)=>({m:u,i:l,tier:t(u[0])}));d.sort((u,l)=>u.tier-l.tier||u.i-l.i),i=d.map(u=>u.m)}if(o&&!s&&this._status!=="dirty"){let d=0;for(;d<i.length&&t(i[d][0])===0;)d++;return d===0?[Se,...i]:[...i.slice(0,d),Se,...i.slice(d)]}return i}_emit(e){if(e.length===0)return;for(let i=0;i<e.length;i++){let d=e[i];if(d[0]===G&&d[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 i=e.filter(d=>d[0]===H||d[0]===re);if(i.length===0)return;t=i}t=this._frameBatch(t);let o=null;for(let i=0;i<t.length;i++){let d=t[i],u=d[0];if(u!==ie&&u!==ce){o?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${u===ie?"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 f=d[1];if(u===ie)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(f),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(f))l=!1;else if(this._pauseLocks.delete(f),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let p=this._pauseBuffer;this._pauseBuffer=[],this._emit(p)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}l?o?.push(d):o==null&&(o=t.slice(0,i))}if(o!=null){if(o.length===0)return;t=o}if(this._hasMeta&&t.some(i=>i[0]===H))for(let i of Object.keys(this.meta))try{this.meta[i]._emit(st)}catch{}let{finalMessages:s,equalsError:a}=this._updateState(t);if(s.length>0&&this._config.inspectorEnabled){let i=this._config.globalInspector;if(i!=null)try{i({kind:"emit",node:this,messages:s})}catch{}}if(s.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let i=this._config.tierOf,d=[];for(let u of s)i(u[0])===3?this._pauseBuffer.push(u):d.push(u);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(s);a!=null&&this._emit([[G,a]])}_updateState(e){let t=this._config.tierOf,n,o,s=-1,a=0;for(let l of e)t(l[0])===3&&a++;let i=a<=1,d=-1;if(this._versioning!=null&&a>1){for(let l=e.length-1;l>=0;l--)if(e[l][0]===I){d=l;break}}for(let l=0;l<e.length;l++){let f=e[l],p=f[0];if(p===I){if(f.length>=2){let h=!1;if(i&&this._cached!==void 0)try{h=this._equals(this._cached,f[1])}catch(c){o=this._wrapFnError("equals threw",c),s=l;break}if(h){n==null&&(n=e.slice(0,l)),n.push(tt),this._status="resolved";continue}this._cached=f[1],this._versioning!=null&&(d<0||l===d)&&en(this._versioning,f[1],this._hashFn)}this._status="settled",n?.push(f)}else if(n?.push(f),p===q)this._status="dirty";else if(p===K)this._status="resolved";else if(p===F){this._status="completed";{let h=this._config.rigorRecorder;if(h!=null)try{h.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===G){this._status="errored";{let h=this._config.rigorRecorder;if(h!=null)try{h.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(p===re){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 h=this._cleanup;if(typeof h=="function"){this._cleanup=void 0;try{h()}catch{}}else if(h!=null&&typeof h=="object"){let c=h.invalidate;if(typeof c=="function")try{c()}catch{}}}else p===H&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let u=s>=0?n??e.slice(0,s):n??e;return o!=null?{finalMessages:u,equalsError:o}:{finalMessages:u}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let n of t)n(e)};_dispatchOrAccumulate(e){if(Ht()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Fe(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}We(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);We(this._deliverToSinks,t,this._config.tierOf)}},on=r=>Array.isArray(r),Rt=r=>typeof r=="object"&&r!=null&&!Array.isArray(r)});function $(r,e){return Q([],{...e,initial:r})}function Te(r,e){return Q((n,o,s)=>r(o,s)??void 0,{describeKind:"producer",...e})}function L(r,e,t){return Q(r,(o,s,a)=>{let i=o.map((d,u)=>d!=null&&d.length>0?d.at(-1):a.prevData[u]);s.emit(e(i,a))},{describeKind:"derived",...t})}function _e(r,e,t){return Q(r,(o,s,a)=>{let i=o.map((d,u)=>d!=null&&d.length>0?d.at(-1):a.prevData[u]);return e(i,s,a)??void 0},{describeKind:"effect",...t})}var ze=W(()=>{"use strict";fe()});function St(r,e){if(e!=null&&e.length>0)return new Set(e);switch(r){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 tr(r){return r._describeKind!=null?r._describeKind:r._deps.length>0?"derived":r._fn!=null?"producer":"state"}function an(r,e){let t={factory:r};return e!==void 0&&(t.factoryArgs=e),t}function nr(r){let e={};for(let[t,n]of Object.entries(r.meta))try{e[t]=n.cache}catch{}return e}function Dt(r,e,t){let n=e==null,o=!n&&e!=null?[...e].filter(l=>l.startsWith("meta.")).map(l=>l.slice(5)):null,s=n||e.has("meta")||o!=null&&o.length>0,a="state",i=[];r instanceof B&&(a=tr(r),i=r._deps.map(l=>l.node.name??""));let d={type:a,deps:i};(n||e.has("status"))&&(d.status=r.status);let u=r instanceof B?r._guard:void 0;if(s){let l={...nr(r)};if(u!=null&&l.access===void 0&&(l.access=Nt(u)),o!=null&&o.length>0&&!e.has("meta")){let f={};for(let p of o)p in l&&(f[p]=l[p]);d.meta=f}else d.meta=l}if(r.name!=null&&(d.name=r.name),(n||e.has("value"))&&(!t||a==="state")){r.status==="sentinel"&&(d.sentinel=!0);try{d.value=r.cache}catch{}}if((n||e.has("v"))&&r.v!=null){let l={id:r.v.id,version:r.v.version};"cid"in r.v&&(l.cid=r.v.cid,l.prev=r.v.prev),d.v=l}return(n||e.has("guard"))&&u!=null&&(d.guard=Nt(u)),(n||e.has("lastMutation"))&&r.lastMutation!=null&&(d.lastMutation=r.lastMutation),d}var At=W(()=>{"use strict";Ke();fe()});function Ct(r){return{describeKind:"producer",...r}}function dn(r,e){return Te(t=>{let n=!1;try{for(let o of r){if(n)return;t.emit(o)}n||t.down([[F]])}catch(o){n||t.down([[G,o]])}return()=>{n=!0}},Ct(e))}function rr(r){return r!=null&&typeof r.then=="function"}function sr(r,e){let{signal:t,...n}=e??{};return Te(o=>{let s=!1,a=()=>{s||(s=!0,o.down([[G,t.reason]]))};if(t?.aborted){a();return}return t?.addEventListener("abort",a,{once:!0}),Promise.resolve(r).then(i=>{s||(s=!0,t?.removeEventListener("abort",a),o.emit(i),o.down([[F]]))},i=>{s||(s=!0,t?.removeEventListener("abort",a),o.down([[G,i]]))}),()=>{s=!0,t?.removeEventListener("abort",a)}},Ct(n))}function or(r,e){let{signal:t,...n}=e??{};return Te(o=>{let s=new AbortController,a=()=>s.abort(t?.reason);t?.aborted?s.abort(t.reason):t?.addEventListener("abort",a,{once:!0});let i=t??s.signal,d=!1,u=r[Symbol.asyncIterator](),l=()=>{d||i.aborted||Promise.resolve(u.next()).then(f=>{if(!(d||i.aborted)){if(f.done){o.down([[F]]);return}o.emit(f.value),l()}},f=>{!d&&!i.aborted&&o.down([[G,f]])})};return l(),()=>{d=!0,t?.removeEventListener("abort",a),s.abort(),Promise.resolve(u.return?.()).catch(()=>{})}},Ct(n))}function ir(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"}function un(r,e){if(ir(r))return r;if(rr(r))return sr(r,e);if(r!=null){let t=r;if(typeof t[Symbol.asyncIterator]=="function")return or(r,e);if(typeof t[Symbol.iterator]=="function")return dn(r,e)}return ar(r)}function ar(...r){return dn(r,void 0)}function pe(r){return r.subscribe(()=>{})}var cn=W(()=>{"use strict";le();ze()});var ut=W(()=>{"use strict";cn()});var ct,pn=W(()=>{"use strict";ct=class{_timer;_gen=0;start(e,t){this.cancel(),this._gen+=1;let n=this._gen;this._timer=setTimeout(()=>{this._timer=void 0,n===this._gen&&t()},e)}cancel(){this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0)}get pending(){return this._timer!==void 0}}});var Ye,hn=W(()=>{"use strict";Ye=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 Sn(r,e,t){return{[r]:!0,[`${r}_type`]:e,...t??{}}}var Dn=W(()=>{"use strict"});var Ir={};jn(Ir,{blindVariation:()=>Ar,errorCritique:()=>Gr,refineLoop:()=>Dr});module.exports=Un(Ir);$e();qe();le();fe();ze();le();At();fe();ut();function dr(r){return{describeKind:"derived",...r}}function ur(r,e,t){let n,o=!1,s=()=>{o||(o=!0,t())};return n=r.subscribe(a=>{let i=!1,d=!1;for(let u of a)u[0]!==ue&&(u[0]===I?e.emit(u[1]):u[0]===F?i=!0:u[0]===G?(d=!0,e.down([u])):(u[0]===q||u[0]===K)&&e.down([u]));d?(n?.(),n=void 0,s()):i&&s()}),()=>{n?.(),n=void 0}}function ln(r,e,t){let n,o=!1;function s(){n?.(),n=void 0}return Q([r],(a,i,d)=>{if(d.terminalDeps[0]!=null&&d.terminalDeps[0]!==!0){s();return}if(d.terminalDeps[0]===!0){o=!0,n||i.down([[F]]);return}let u=a[0];if(!(u==null||u.length===0))return s(),n=ur(un(e(u[u.length-1])),i,()=>{s(),o&&i.down([[F]])}),{deactivate:()=>{s(),o=!1}}},{...dr(t),completeWhenDepsComplete:!1,meta:{...an("switchMap"),...t?.meta??{}}})}it();$e();qe();Ke();le();At();fe();ze();qe();function Mt(r,e){if(Object.is(r,e))return!0;if(r==null||e==null||typeof r!="object"||typeof e!="object")return!1;if(Array.isArray(r)){if(!Array.isArray(e)||r.length!==e.length)return!1;for(let s=0;s<r.length;s++)if(!Mt(r[s],e[s]))return!1;return!0}if(Array.isArray(e))return!1;let t=Object.keys(r),n=Object.keys(e);if(t.length!==n.length)return!1;let o=new Set(n);for(let s of t)if(!o.has(s)||!Mt(r[s],e[s]))return!1;return!0}function fn(r,e){return`${r}\0${e}`}function Gt(r,e){let t=[],n=new Set(r.subgraphs),o=new Set(e.subgraphs),s=[];for(let m of o)n.has(m)||s.push(m);s.sort();for(let m of s)t.push({type:"subgraph-mounted",path:m});let a=new Set(Object.keys(r.nodes)),i=new Set(Object.keys(e.nodes)),d=[];for(let m of i)a.has(m)||d.push(m);d.sort();for(let m of d)t.push({type:"node-added",path:m,node:{...e.nodes[m]}});let u=[];for(let m of i){if(!a.has(m))continue;let N=r.nodes[m]?.meta,v=e.nodes[m]?.meta;N==null&&v==null||Mt(N??{},v??{})||u.push(m)}u.sort();for(let m of u)t.push({type:"node-meta-changed",path:m,prevMeta:r.nodes[m]?.meta??{},nextMeta:e.nodes[m]?.meta??{}});let l=new Map;for(let m of r.edges)l.set(fn(m.from,m.to),m);let f=new Map;for(let m of e.edges)f.set(fn(m.from,m.to),m);let p=[];for(let[m,N]of f)l.has(m)||p.push(N);p.sort((m,N)=>m.from<N.from?-1:m.from>N.from?1:m.to<N.to?-1:m.to>N.to?1:0);for(let m of p)t.push({type:"edge-added",from:m.from,to:m.to});let h=[];for(let[m,N]of l)f.has(m)||h.push(N);h.sort((m,N)=>m.from<N.from?-1:m.from>N.from?1:m.to<N.to?-1:m.to>N.to?1:0);for(let m of h)t.push({type:"edge-removed",from:m.from,to:m.to});let c=[];for(let m of a)i.has(m)||c.push(m);c.sort();for(let m of c)t.push({type:"node-removed",path:m});let y=[];for(let m of n)o.has(m)||y.push(m);y.sort();for(let m of y)t.push({type:"subgraph-unmounted",path:m});return{events:t,flushedAt_ns:J()}}ut();pn();hn();wt();function mn(r,e,t,n={}){let o=e in r.nodes,s=t in r.nodes;if(!o)return lt(e,t,"no-such-from");if(!s)return lt(e,t,"no-such-to");let a=n.maxDepth;if(a!=null&&(!Number.isInteger(a)||a<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(n.findCycle===!0){let u=cr(r,e,n);if(u!=null)return u}let d=ft(e,r.nodes[e],0,n);return pt(e,t,[d])}if(a===0)return lt(e,t,"no-path");let i=gn(r,e,t,a);return i.found?pt(e,t,bn(r,i.pathOrder,n)):lt(e,t,i.truncated?"max-depth-exceeded":"no-path")}function gn(r,e,t,n){let o=new Map,s=[{path:t,depth:0}],a=new Set([t]),i=0,d=!1;for(;i<s.length;){let f=s[i++];if(f.path===e)break;if(n!=null&&f.depth>=n){let y=r.nodes[f.path];y?.deps&&y.deps.length>0&&(d=!0);continue}let p=r.nodes[f.path];if(p==null)continue;let h=p.deps??[],c=new Map;for(let y=0;y<h.length;y++){let m=h[y];if(!m)continue;let N=c.get(m);N==null&&(N=[],c.set(m,N)),N.push(y)}for(let[y,m]of c)a.has(y)||(a.add(y),o.set(y,{from:f.path,depIndices:m}),s.push({path:y,depth:f.depth+1}))}if(!o.has(e))return{found:!1,pathOrder:[],truncated:d};let u=[{path:e}],l=e;for(;l!==t;){let f=o.get(l);if(f==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=f.depIndices,u.push({path:f.from}),l=f.from}return{found:!0,pathOrder:u,truncated:!1}}function cr(r,e,t){let n=r.nodes[e];if(n==null)return null;let o=n.deps??[],s=[];for(let i=0;i<o.length;i++)o[i]===e&&s.push(i);if(s.length>0){let i=ft(e,n,0,t);i.dep_index=s[0];let d=ft(e,n,1,t);return pt(e,e,[i,d])}let a=null;for(let i=0;i<o.length;i++){let d=o[i];if(!d||d===e)continue;let u=gn(r,d,e,t.maxDepth);u.found&&(a==null||u.pathOrder.length<a.pathOrder.length)&&(a=u,a={found:!0,pathOrder:[{path:e,depIndices:[i]},...u.pathOrder],truncated:!1})}return a==null?null:pt(e,e,bn(r,a.pathOrder,t))}function bn(r,e,t){return e.map((n,o)=>{let s=r.nodes[n.path],a=ft(n.path,s,o,t);return n.depIndices!=null&&n.depIndices.length>0&&(a.dep_index=n.depIndices[0],n.depIndices.length>1&&(a.dep_indices=[...n.depIndices])),a})}function ft(r,e,t,n){let o={path:r,type:e.type,hop:t};e.status!==void 0&&(o.status=e.status),"value"in e&&(o.value=e.value),e.v!=null&&(o.v=e.v);let s=n.annotations?.get(r)??e.annotation;s!=null&&(o.annotation=s);let a=n.lastMutations?.get(r)??e.lastMutation;return a!=null&&(o.lastMutation=a),o}function pt(r,e,t){return yn(r,e,!0,"ok",t)}function lt(r,e,t){return yn(r,e,!1,t,[])}function yn(r,e,t,n,o){let s=lr(r,e,t,n,o);return{from:r,to:e,found:t,reason:n,steps:o,text:s,toJSON(){return{from:r,to:e,found:t,reason:n,steps:o}}}}function lr(r,e,t,n,o){if(!t)switch(n){case"no-such-from":return`explainPath: no node named "${r}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${r}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${r}" to "${e}"`}let s=[`Causal path: ${r} \u2192 ${e} (${o.length} step(s))`];for(let a of o){let d=` ${a.hop===0?"\xB7":"\u2193"} ${a.path} (${a.type}${a.status?`/${a.status}`:""})`;if(s.push(d),"value"in a&&s.push(` value: ${fr(a.value)}`),a.annotation!=null&&s.push(` annotation: ${a.annotation}`),a.lastMutation!=null){let u=a.lastMutation.actor;s.push(` actor: ${u.type}${u.id?`:${u.id}`:""}`)}}return s.join(`
|
|
2
|
-
`)}function fr(r){if(r===void 0)return"<sentinel>";if(r===null)return"null";if(typeof r=="string")return JSON.stringify(r);if(typeof r=="number"||typeof r=="boolean"||typeof r=="bigint")return String(r);try{let e=JSON.stringify(r);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(r)}}fe();var j={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},pr=Symbol.for("sizeof");function vn(r){let e=new WeakSet,t=new WeakSet,n=[r],o=0;for(;n.length>0;){let s=n.pop();o+=hr(s,e,t,n)}return o}function hr(r,e,t,n){if(r==null)return 0;switch(typeof r){case"number":return j.number;case"boolean":return j.boolean;case"string":return j.string+r.length*2;case"bigint":return j.bigint+mr(r);case"symbol":return j.symbol;case"function":return e.has(r)?0:(e.add(r),j.function);case"undefined":return 0}let s=r;if(e.has(s))return 0;e.add(s);let a=s[pr];if(typeof a=="function")try{let u=a.call(s);if(typeof u=="number"&&Number.isFinite(u))return u}catch{}if(s instanceof Date)return j.date;if(s instanceof RegExp)return j.regexp+s.source.length*2;if(s instanceof Error){let u=s.message?s.message.length*2:0,l=s.stack?s.stack.length*2:0;return j.error+u+l}if(typeof URL<"u"&&s instanceof URL)return j.url+s.href.length*2;if(typeof Promise<"u"&&s instanceof Promise)return j.promise;if(s instanceof WeakMap)return j.weakmap;if(s instanceof WeakSet)return j.weakset;if(s instanceof Map){let u=j.map;for(let[l,f]of s)u+=j.mapEntry,n.push(l),n.push(f);return u}if(s instanceof Set){let u=j.set;for(let l of s)u+=j.setEntry,n.push(l);return u}if(Array.isArray(s)){let u=j.array+s.length*8;for(let l of s)n.push(l);return u}if(s instanceof ArrayBuffer)return t.has(s)?0:(t.add(s),s.byteLength);if(ArrayBuffer.isView(s)){let u=s;return t.has(u.buffer)?48:(t.add(u.buffer),u.buffer.byteLength+48)}let i=j.object,d=Object.keys(s);for(let u of d){i+=j.string+u.length*2;try{n.push(s[u])}catch{}}return i}function mr(r){let e=r<0n?-r:r;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}function Tn(r,e){let t=e?.topN??10,n=r.describe({detail:"standard"}),o=[],s=r._collectObserveTargets;typeof s=="function"&&s.call(r,"",o);let a=new Map;for(let[p,h]of o)a.set(p,h);let i=[];for(let[p,h]of Object.entries(n.nodes)){let c=a.get(p),y=c instanceof B?c:null,m=y?vn(y.cache):0,N=y?y._sinkCount:0,v=h.deps?.length??0,b=h.type==="effect"&&N===0,T=N===0?h.type==="effect"?"orphan-effect":h.type==="derived"?"idle-derived":h.type==="producer"?"idle-producer":null:null;i.push({path:p,type:h.type,status:h.status??"unknown",valueSizeBytes:m,subscriberCount:N,depCount:v,isOrphanEffect:b,orphanKind:T})}let d=i.reduce((p,h)=>p+h.valueSizeBytes,0),u=(p,h)=>[...i].sort(h??((c,y)=>y[p]-c[p])).slice(0,t),l=i.filter(p=>p.orphanKind!=null),f=i.filter(p=>p.isOrphanEffect);return{nodeCount:i.length,edgeCount:n.edges.length,subgraphCount:n.subgraphs.length,nodes:i,totalValueSizeBytes:d,hotspots:{byValueSize:u("valueSizeBytes"),bySubscriberCount:u("subscriberCount"),byDepCount:u("depCount")},orphans:l,orphanEffects:f}}var V="::",oe="__meta__",De=1;function _n(r,e){let t=Math.max(16,r.size*4),n=0;for(;r.size>0;){if(n++>=t){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${t}); ${r.size} disposer(s) discarded`),r.clear();return}let o=r.values().next();if(o.done)return;let s=o.value;r.delete(s);try{s()}catch(a){console.error(`[Graph "${e}".destroy] disposer threw:`,a)}}}function En(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function gr(r){if(r!=null)return En(r)?r.cache:r}function Ae(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function we(r){return Ae(r)?r.cache??"":r}function wn(r){return Ae(r)?r.cache??0:r}function Nn(r){return Ae(r)?r.cache??!1:r}function br(r){let e=[];for(let t of Object.keys(r).sort()){let n=r[t].v;n!=null&&e.push(`${t} ${n.id} ${n.version}`)}return e.join(`
|
|
3
|
-
`)}function On(r){if(r.version!==De)throw new Error(`unsupported snapshot version ${String(r.version)} (expected ${De})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in r))throw new Error(`snapshot missing required key "${e}"`);if(typeof r.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof r.nodes!="object"||r.nodes===null||Array.isArray(r.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(r.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(r.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function yr(r,e){let t=new WeakMap,n=(o,s)=>{if(Object.is(o,s))return!0;if(o==null||s==null||typeof o!="object"||typeof s!="object")return!1;let a=t.get(o);if(a==null&&(a=new WeakSet,t.set(o,a)),a.has(s))return!0;a.add(s);let i=o.constructor,d=s.constructor;if(i!==d)return!1;if(o instanceof Date)return o.getTime()===s.getTime();if(o instanceof RegExp)return o.source===s.source&&o.flags===s.flags;if(Array.isArray(o)){let p=s;if(o.length!==p.length)return!1;for(let h=0;h<o.length;h++)if(!n(o[h],p[h]))return!1;return!0}if(o instanceof Map){let p=s;if(o.size!==p.size)return!1;for(let[h,c]of o)if(!p.has(h)||!n(c,p.get(h)))return!1;return!0}if(o instanceof Set){let p=s;if(o.size!==p.size)return!1;for(let h of o){let c=!1;for(let y of p)if(n(h,y)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(o)){let p=o,h=s;if(p.length!==h.length)return!1;for(let c=0;c<p.length;c++)if(p[c]!==h[c])return!1;return!0}let u=Object.keys(o),l=Object.keys(s);if(u.length!==l.length)return!1;let f=new Set(l);for(let p of u)if(!f.has(p)||!n(o[p],s[p]))return!1;return!0};return n(r,e)}function vr(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ht(r){let e="^";for(let t=0;t<r.length;t+=1){let n=r[t];if(n==="*"){e+=".*";continue}if(n==="?"){e+=".";continue}if(n==="["){let o=r.indexOf("]",t+1);if(o<=t+1){e+="\\[";continue}let s=r.slice(t+1,o);s.startsWith("!")&&(s=`^${s.slice(1)}`),s=s.replace(/\\/g,"\\\\"),e+=`[${s}]`,t=o;continue}e+=vr(n)}return e+="$",new RegExp(e)}var Tr={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"},_r={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function It(r){if(typeof r=="string")return JSON.stringify(r);if(typeof r=="number"||typeof r=="boolean"||r==null)return String(r);try{return JSON.stringify(r)}catch{return"[unserializable]"}}function wr(r){return r==="none"?_r:r==="ansi"||r==null?Tr:{data:r.data??"",dirty:r.dirty??"",resolved:r.resolved??"",invalidate:r.invalidate??"",pause:r.pause??"",resume:r.resume??"",complete:r.complete??"",error:r.error??"",teardown:r.teardown??"",derived:r.derived??"",path:r.path??"",reset:r.reset??""}}function xn(r){if(r==null)return{};let e=r.detail;return e==="full"?{...r,structured:r.structured??!0,timeline:r.timeline??!0,causal:r.causal??!0,derived:r.derived??!0}:e==="minimal"?{...r,structured:r.structured??!0}:r.format==="stage-log"?{...r,structured:r.structured??!0,timeline:r.timeline??!0}:r}function Nr(r,e,t){for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);if(o<32||o===127)throw new Error(`Graph "${e}": ${t} "${r}" must not contain control character (U+${o.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function Pt(r,e,t){if(r==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(r.includes(V))throw new Error(`Graph "${e}": ${t} "${r}" must not contain '${V}' (path separator)`);if(r===oe)throw new Error(`Graph "${e}": ${t} name "${oe}" is reserved for meta companion paths`);Nr(r,e,t)}function Or(r,e){if(r==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=r.split(V);for(let n of t)if(n==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function xr(r,e){let t=!1;for(let o of r)if(!e.isMetaPassthrough(o[0])){t=!0;break}return t?r.filter(o=>e.isMetaPassthrough(o[0])):r}function kn(r){for(let e of r._mounts.values())kn(e);for(let e of r._nodes.values())try{e.down([[H]],{internal:!0})}catch{}}var de=class r{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(V))throw new Error(`Graph name must not contain '${V}' (got "${e}")`);if(e===oe)throw new Error(`Graph name "${oe}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??Ve,this._traceRing=new Ye(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=[],n=e?this:this._parent;for(;n!=null;)t.push(n),n=n._parent;return t}get topology(){return this._topology==null&&(this._topology=Te(e=>{let t=n=>{e.emit(n)};return this._topologyEmitters.add(t),()=>{this._topologyEmitters.delete(t)}},{name:`${this.name}_topology`})),this._topology}_emitTopology(e){if(!(this._topology==null||this._topologyEmitters.size===0))for(let t of this._topologyEmitters)t(e)}nameOf(e){return this._nodeToName.get(e)}add(e,t){let n=e.name,o=t?.name??n;if(o==null||o==="")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 s=o,a=t?.annotation;if(Pt(s,this.name,"add"),this._mounts.has(s))throw new Error(`Graph "${this.name}": name "${s}" is already a mount point`);if(this._nodes.has(s))throw new Error(`Graph "${this.name}": node "${s}" already exists`);let i=this._nodeToName.get(e);if(i!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${i}"`);return this._nodes.set(s,e),this._nodeToName.set(e,s),this._emitTopology({kind:"added",name:s,nodeKind:"node"}),a!=null&&(this._annotations.set(s,a),this.config.inspectorEnabled&&this._traceRing.push({path:s,annotation:a,timestamp_ns:J()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof B&&t._applyVersioning(e)}remove(e){Pt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let s={kind:"mount",nodes:[],mounts:[]},a=[];t._collectObserveTargets("",a);for(let[i,d]of a)i.includes(`${V}${oe}${V}`)||s.nodes.push(i);return s.nodes.sort(),s.mounts.push(e),s.mounts.push(...t._collectSubgraphs(`${e}${V}`)),this._mounts.delete(e),t._parent=void 0,kn(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:s}),s}let n=this._nodes.get(e);if(!n)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(n),n.down([[H]],{internal:!0});let o={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:o}),o}removeAll(e){let t=typeof e=="function"?e:(()=>{let s=ht(e);return a=>s.test(a)})(),n={kind:"mount",nodes:[],mounts:[]},o=[...this._nodes.keys(),...this._mounts.keys()].filter(s=>t(s));for(let s of o){let a=this.remove(s);n.nodes.push(...a.nodes),n.mounts.push(...a.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=e.length)return{value:void 0,done:!0};let o=e[n++];return{value:[o,t.get(o)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(V))return this.resolve(e);let t=this._nodes.get(e);if(!t)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return t}get(e){return this.node(e).cache}set(e,t,n){let o=n?.internal===!0;this.node(e).down([[I,t]],{actor:n?.actor,internal:o,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);ae(()=>{for(let[o,s]of n)this.set(o,s,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[re]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let o=n?.internal===!0;this.node(e).down([[G,t]],{actor:n?.actor,internal:o,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[F]],{actor:t?.actor,internal:n,delivery:"write"})}edges(e){let t=e?.recursive===!0,n=new Map;if(!t){for(let[d,u]of this._nodes)n.set(u,d);let i=[];for(let[d,u]of this._nodes)if(u instanceof B)for(let l of u._deps){let f=n.get(l.node);f!=null&&i.push([f,d])}return i.sort((d,u)=>d[0]<u[0]?-1:d[0]>u[0]?1:d[1]<u[1]?-1:d[1]>u[1]?1:0),i}let o=[];this._collectObserveTargets("",o);let s=new Map;for(let[i,d]of o)s.set(d,i);let a=[];for(let[i,d]of o)if(d instanceof B)for(let u of d._deps){let l=s.get(u.node);l!=null&&a.push([l,i])}return a.sort((i,d)=>i[0]<d[0]?-1:i[0]>d[0]?1:i[1]<d[1]?-1:i[1]>d[1]?1:0),a}mount(e,t){if(t===void 0){let o=new r(e);return this.mount(e,o)}if(typeof t=="function"){let o=new r(e);return t(o),this.mount(e,o)}let n=t;if(Pt(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(n===this)throw new Error(`Graph "${this.name}": cannot mount a graph into itself`);if(n._parent!=null)throw new Error(`Graph "${this.name}": this child graph is already mounted on "${n._parent.name}"`);for(let o=this;o!=null;o=o._parent)if(o===n)throw new Error(`Graph "${this.name}": mount("${e}", \u2026) would create a mount cycle`);return this._mounts.set(e,n),n._parent=this,this._emitTopology({kind:"added",name:e,nodeKind:"mount"}),n}resolve(e){let t=Or(e,this.name);return this._resolveFromSegments(t)}tryResolve(e){try{return this.resolve(e)}catch{return}}_resolveFromSegments(e){let t=e;if(t[0]===this.name&&(t=t.slice(1),t.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let n=t[0],o=t.slice(1);if(o.length===0){let i=this._nodes.get(n);if(i)return i;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let s=this._nodes.get(n);if(s&&o.length>0&&o[0]===oe)return this._resolveMetaChainFromNode(s,o,t.join(V));let a=this._mounts.get(n);if(!a)throw this._nodes.has(n)?new Error(`Graph "${this.name}": "${n}" is a node; trailing path "${o.join(V)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return a.resolve(o.join(V))}_resolveMetaChainFromNode(e,t,n){let o=e,s=0,a=[...t];for(;s<a.length;){if(a[s]!==oe)throw new Error(`Graph "${this.name}": expected ${oe} segment in meta path "${n}"`);if(s+1>=a.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${oe} in "${n}"`);let i=a[s+1],d=o.meta[i];if(!d)throw new Error(`Graph "${this.name}": unknown meta "${i}" in path "${n}"`);o=d,s+=2}return o}signal(e,t){if(t?.internal!==!0){for(let o of e)if(this.config.messageTier(o[0])===3)throw new Error(`Graph "${this.name}": Graph.signal() rejects tier-3 messages (DATA / RESOLVED). Broadcast is for control-plane tiers (START / DIRTY / INVALIDATE / PAUSE / RESUME / COMPLETE / ERROR / TEARDOWN). For per-node value writes, use Graph.set or graph.node(name).down(...).`)}let n=[];if(this._signalDeliver(e,t??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(e,t,n,o){for(let d of this._mounts.values())d._signalDeliver(e,t,n,o);let a=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},i=xr(e,this.config);for(let d of[...this._nodes.keys()].sort()){let u=this._nodes.get(d);if(!n.has(u)){n.add(u);try{u.down(e,a)}catch(l){if(l instanceof se)throw l;o.push(l)}i.length!==0&&this._signalMetaSubtree(u,i,n,a,o)}}}_signalMetaSubtree(e,t,n,o,s){for(let a of Object.keys(e.meta).sort()){let i=e.meta[a];if(!n.has(i)){n.add(i);try{i.down(t,o)}catch(d){if(d instanceof se)throw d;s.push(d)}this._signalMetaSubtree(i,t,n,o,s)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=gr(e?.actor),n=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 o=St(e?.detail,e?.fields),s=e?.detail==="spec",a=o,i=[];this._collectObserveTargets("",i);let d=new Map;for(let[T,_]of i)d.set(_,T);let u=[];{let T=i.map(([,g])=>g),_=new Set(d.values()),k=0;for(;T.length>0;){let g=T.shift();if(g instanceof B)for(let w of g._deps){let E=w.node;if(d.has(E))continue;let S=E.name??"",x=S;if(!x||_.has(x))if(S){let A=2;for(;_.has(`${S}#${A}`);)A++;x=`${S}#${A}`}else for(x=`__internal__/${k++}`;_.has(x);)x=`__internal__/${k++}`;d.set(E,x),_.add(x),u.push([x,E]),T.push(E)}}}let l=[...i,...u],f={};for(let[T,_]of l){if(t!=null&&!_.allowsObserve(t))continue;let k=Dt(_,a,s),g=_ instanceof B?_._deps.map(x=>d.get(x.node)??x.node.name??""):[],{name:w,...E}=k,S={...E,deps:g};if(!s){let x=this._annotations.get(T);x!=null&&(S.annotation=x)}if(n!=null)if(typeof n=="function"){let x=n;if(!(x.length>=2?x(T,S):x(S)))continue}else{let x=!0;for(let[A,M]of Object.entries(n)){let C=A==="deps_includes"?"depsIncludes":A==="meta_has"?"metaHas":A;if(C==="depsIncludes"){if(!S.deps.includes(String(M))){x=!1;break}continue}if(C==="metaHas"){if(!Object.hasOwn(S.meta??{},String(M))){x=!1;break}continue}if(S[C]!==M){x=!1;break}}if(!x)continue}f[T]=S}let p=new Set(Object.keys(f)),h=[];for(let[T,_]of l)if(_ instanceof B)for(let k of _._deps){let g=d.get(k.node);g!=null&&h.push([g,T])}h.sort((T,_)=>T[0]<_[0]?-1:T[0]>_[0]?1:T[1]<_[1]?-1:T[1]>_[1]?1:0);let c=h.map(([T,_])=>({from:T,to:_}));(t!=null||n!=null)&&(c=c.filter(T=>p.has(T.from)&&p.has(T.to)));let y=this._collectSubgraphs(""),m=t!=null||n!=null?y.filter(T=>{let _=`${T}${V}`;return[...p].some(k=>k===T||k.startsWith(_))}):y,N=this,v=e;return{name:this.name,nodes:f,edges:c,subgraphs:m,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(T){let _={...v};return Array.isArray(T)?(_.fields=T,_.detail=void 0):(_.detail=T,_.fields=void 0),N.describe(_)}}}_collectSubgraphs(e){let t=[];for(let n of[...this._mounts.keys()].sort()){let o=e===""?n:`${e}${n}`;t.push(o),t.push(...this._mounts.get(n)._collectSubgraphs(`${o}${V}`))}return t}resourceProfile(e){return Tn(this,e)}reachable(e,t,n={}){return n.withDetail===!0?Ft(this.describe(),e,t,{...n,withDetail:!0}):Ft(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(we(e),we(t),{...n?.maxDepth!==void 0?{maxDepth:wn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:Nn(n.findCycle)}:{}})}_explainStatic(e,t,n){let o=this.describe({detail:"full"}),s=new Map(this._annotations),a=new Map;for(let[i,d]of Object.entries(o.nodes))d.lastMutation!=null&&a.set(i,d.lastMutation);return mn(o,e,t,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:s,lastMutations:a})}_describeReactive(e){let t={...e,reactive:!1},n=e.reactiveName??"describe",o=0,s=$(o,{name:`${n}_version`}),a=this.observe({timeline:!0,structured:!0}),i=!1,d=!1,u=()=>{i||d||(i=!0,Fe(()=>{i=!1,!d&&(o+=1,s.emit(o))}))},l=a.onEvent(v=>{let b=v.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||u()}),f=[],p=new WeakSet,h=v=>{if(p.has(v)||d)return;p.add(v);let b=v.topology.subscribe(T=>{for(let _ of T){if(_[0]!==I)continue;let k=_[1];if(u(),k.kind==="added"&&k.nodeKind==="mount"){let g=v._mounts.get(k.name);g!=null&&h(g)}}});f.push(b);for(let T of v._mounts.keys()){let _=v._mounts.get(T);_!=null&&h(_)}};h(this);let c,y=e.actor;En(y)&&(c=y.subscribe(v=>{let b=!1,T=!1;for(let _ of v){let k=_[0];k===I?b=!0:(k===F||k===G||k===H)&&(T=!0)}b&&u(),T&&(c?.(),c=void 0,u())}));let m;try{m=L([s],()=>this.describe(t),{name:n,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(v,b)=>v===b})}catch(v){l(),c?.();for(let b of f)b();throw a.dispose(),v}let N=pe(m);return{node:m,dispose(){d=!0,l(),c?.();for(let v of f)v();f.length=0,a.dispose(),N()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},n=e.reactiveName??"describe-diff",o={name:this.name,nodes:{},edges:[],subgraphs:[]},s=this.describe(t),a=Gt(o,s),i=$(a,{name:n,meta:{domain:"audit",kind:"describe-diff"},equals:(p,h)=>p===h}),d=this._describeReactive({...e,reactiveName:void 0}),u=!1,l=d.node.subscribe(p=>{if(!u)for(let h of p){if(h[0]!==I)continue;let c=h[1],y=Gt(s,c);s=c,y.events.length!==0&&i.emit(y)}}),f=pe(i);return{node:i,dispose(){u=!0,l(),d.dispose(),i.down([[H,"describe-diff disposed"]]),f()}}}_explainReactive(e,t,n){let o=0,s=$(o,{name:"explain_version"}),a=this.observe({timeline:!0,structured:!0}),i=!1,d=!1,u=()=>{i||d||(i=!0,Fe(()=>{i=!1,!d&&(o+=1,s.emit(o))}))},l=a.onEvent(v=>{let b=v.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||u()}),f=[];e!=null&&Ae(e)&&f.push(e),t!=null&&Ae(t)&&f.push(t),n?.maxDepth!=null&&Ae(n.maxDepth)&&f.push(n.maxDepth),n?.findCycle!=null&&Ae(n.findCycle)&&f.push(n.findCycle);let p=()=>{for(let v of f)if(v.cache===void 0)return!1;return!0},h=()=>{let v=we(e),b=we(t);return{from:v,to:b,found:!1,reason:"pending",steps:[],text:"(awaiting reactive args)",toJSON:()=>({from:v,to:b,found:!1,reason:"pending",steps:[]})}},c;try{c=L([s],()=>{if(!p())return h();let v=we(e),b=we(t),T={...n?.maxDepth!==void 0?{maxDepth:wn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:Nn(n.findCycle)}:{}};return this._explainStatic(v,b,T)},{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:we(e),to:we(t)},equals:(v,b)=>v.found===b.found&&v.reason===b.reason&&v.steps.length===b.steps.length&&Er(v.steps,b.steps)})}catch(v){throw l(),a.dispose(),v}let y=pe(c),m=[],N=v=>{let b;return b=v.subscribe(T=>{let _=!1,k=!1;for(let g of T){let w=g[0];w===I?_=!0:(w===F||w===G||w===H)&&(k=!0)}(_||k)&&u(),k&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let v of f)m.push(N(v));return{node:c,dispose(){d=!0,l();for(let v of m)v?.();m.length=0,a.dispose(),y()}}}_pathsMatching(e){let t=ht(e),n=[];return this._collectObserveTargets("",n),n.map(([o])=>o).filter(o=>t.test(o))}_collectObserveTargets(e,t){for(let n of[...this._mounts.keys()].sort()){let o=e===""?n:`${e}${V}${n}`;this._mounts.get(n)._collectObserveTargets(o,t)}for(let n of[...this._nodes.keys()].sort()){let o=this._nodes.get(n),s=e===""?n:`${e}${V}${n}`;t.push([s,o]),this._appendMetaObserveTargets(s,o,t)}}_appendMetaObserveTargets(e,t,n){for(let o of Object.keys(t.meta).sort()){let s=t.meta[o],a=`${e}${V}${oe}${V}${o}`;n.push([a,s]),this._appendMetaObserveTargets(a,s,n)}}observe(e,t){let n=typeof e=="string",s=xn(n?t:e);if(s.reactive===!0)return this._observeReactive(n?e:void 0,s);let a=s.structured===!0||s.timeline===!0||s.causal===!0||s.derived===!0||s.detail==="minimal"||s.detail==="full"||s.format!=null,i=s.actor;if(n){let l=e,f=this.resolve(l);if(i!=null&&!f.allowsObserve(i))throw new se({actor:i,action:"observe",nodeName:l});return a?this._buildStructuredObserver([[l,f]],s,"one"):{subscribe(p){return f.subscribe(p)},up(p){try{f.up?.(p)}catch(h){if(h instanceof se)return;throw h}}}}let d=[];this._collectObserveTargets("",d),d.sort((l,f)=>l[0]<f[0]?-1:l[0]>f[0]?1:0);let u=i==null?d:d.filter(([,l])=>l.allowsObserve(i));return a?this._buildStructuredObserver(u,s,"all"):{subscribe:l=>{let f=u.map(([p,h])=>h.subscribe(c=>{l(p,c)}));return()=>{for(let p of f)p()}},up:(l,f)=>{try{this.resolve(l).up?.(f)}catch(p){if(p instanceof se)return;throw p}}}}_observeReactive(e,t){let n=t.tiers,o=n!=null?new Set(n):null,s=t.reactiveName??"observe";return Te(a=>{let i=[],d=!1,u=!1,l=()=>{if(i.length===0||u)return;let y={events:i.slice(),flushedAt_ns:J()};i.length=0,a.emit(y)},f={...t,reactive:!1,structured:!0,timeline:!0},p=e!=null?this.observe(e,f):this.observe(f),h=y=>{u||(i.push(y),!d&&(d=!0,Fe(()=>{d=!1,l()})))};for(let y of p.events)h(y);let c=p.onEvent(h);return()=>{u=!0,c(),p.dispose()}},{name:s,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,n){let o=n==="one"?e[0]?.[0]:void 0,s=a=>{if(n==="one"&&o!=null){let l=this.resolve(o);return this._buildStructuredObserver([[o,l]],a,"one")}let i=[];this._collectObserveTargets("",i),i.sort((l,f)=>l[0]<f[0]?-1:l[0]>f[0]?1:0);let d=a.actor,u=d==null?i:i.filter(([,l])=>l.allowsObserve(d));return this._buildStructuredObserver(u,a,"all")};return this._createObserveResult(e,t,s)}_createObserveResult(e,t,n){let o=t.timeline===!0,s=t.causal===!0,a=t.derived===!0,i=t.detail==="minimal",d=this.config.inspectorEnabled,u=(s||a)&&d,l=t.maxEvents,f=l!=null&&l>0?new Ye(l):null,p=[],h=new Set,c=t.tiers!=null?new Set(t.tiers):null,y={},m=new Set,N=0,v=0,b=0,T=0,_=0,k=0,g=!1,w=!1,E=0,S=new Map,x=new Map,A=new Map,M=R=>{if(!(c!=null&&!c.has(R.type))){f?f.push(R):p.push(R);for(let P of h)P(R)}},C=R=>c==null||c.has(R),ee=()=>o?{timestamp_ns:J(),in_batch:Ue(),batch_id:E}:{},te=(R,P)=>{if(!(!u||!(R instanceof B)))return R._setInspectorHook(Y=>{if(Y.kind==="dep_message")S.set(R,Y.depIndex);else if(Y.kind==="run"){let ge=Y.batchData.map((O,D)=>O!=null&&O.length>0?O.at(-1):Y.prevData[D]);x.set(R,ge);let X=Y.batchData.map(O=>O!=null?[...O]:void 0);A.set(R,X),a&&M({type:"derived",path:P,dep_values:ge,dep_batches:X,...ee()})}})},he=R=>{let P=S.get(R),Y=x.get(R);if(!s||Y==null)return{};let X=(P!=null&&P>=0&&R instanceof B?R._deps[P]:void 0)?.node,O=X?.v,D=A.get(R);return{trigger_dep_index:P,trigger_dep_name:X?.name,...O!=null?{trigger_version:{id:O.id,version:O.version}}:{},dep_values:[...Y],...D!=null?{dep_batches:D}:{}}},Ce=[],Be=[];for(let[R,P]of e){let Y=te(P,R);Y&&Ce.push(Y),Be.push(P.subscribe(ge=>{E++;for(let X of ge){let O=X[0],D=ee();if(O===I){y[R]=X[1];let z=P instanceof B?P.lastMutation?.actor??Le:Le;M({type:"data",path:R,data:X[1],actor:z,...D,...he(P)})}else if(i)O===q?C("dirty")&&N++:O===K?C("resolved")&&v++:O===re?C("invalidate")&&b++:O===ie?C("pause")&&T++:O===ce?C("resume")&&_++:O===H?C("teardown")&&k++:O===F&&!m.has(R)?C("complete")&&(g=!0):O===G&&C("error")&&(w=!0,m.add(R));else if(O===q)C("dirty")&&N++,M({type:"dirty",path:R,...D});else if(O===K)C("resolved")&&v++,M({type:"resolved",path:R,...D,...he(P)});else if(O===re)C("invalidate")&&b++,M({type:"invalidate",path:R,...D});else if(O===ie)C("pause")&&T++,M({type:"pause",path:R,lockId:X[1],...D});else if(O===ce)C("resume")&&_++,M({type:"resume",path:R,lockId:X[1],...D});else if(O===F)C("complete")&&!m.has(R)&&(g=!0),M({type:"complete",path:R,...D});else if(O===G){C("error")&&(w=!0,m.add(R));let z=P instanceof B?P.lastMutation?.actor??Le:Le;M({type:"error",path:R,data:X[1],actor:z,...D})}else O===H&&(C("teardown")&&k++,M({type:"teardown",path:R,...D}))}}))}let Ne=!1,Oe=()=>{if(!Ne){Ne=!0;for(let R of Be)R();for(let R of Ce)R();for(let R of me)R({value:void 0,done:!0});me.length=0}},xe=[],me=[];h.add(R=>{let P=me.shift();P?P({value:R,done:!1}):xe.push(R)});let Me={get values(){return y},get dirtyCount(){return N},get resolvedCount(){return v},get invalidateCount(){return b},get pauseCount(){return T},get resumeCount(){return _},get teardownCount(){return k},get events(){return f?f.toArray():[...p]},get anyCompletedCleanly(){return g},get anyErrored(){return w},get completedWithoutErrors(){return g&&!w},onEvent(R){return h.add(R),()=>h.delete(R)},dispose:Oe,expand(R){Oe();let P={...t};return typeof R=="string"?P.detail=R:Object.assign(P,R),n(xn(P))},[Symbol.asyncIterator](){return{next(){return xe.length>0?Promise.resolve({value:xe.shift(),done:!1}):Ne?Promise.resolve({value:void 0,done:!0}):new Promise(R=>me.push(R))},return(){return Oe(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(Me,t),Me}_attachFormatLogger(e,t){let n=t.format;if(n==null)return;let o=t.logger??(c=>console.log(c)),s=t.includeTypes?new Set(t.includeTypes):null,a=t.excludeTypes?new Set(t.excludeTypes):null,i=s==null&&a==null?()=>!0:c=>(s==null||s.has(c))&&(a==null||!a.has(c)),d=wr(t.theme),u=n==="stage-log"?J():0,l=c=>c==null?"":t.stageLabels?.[c]??c,f=(c,y)=>c.length>y?`${c.slice(0,y-1)}\u2026`:c,p=c=>c.type==="data"||c.type==="error"?f(It(c.data),120):"",h=c=>{if(n==="stage-log"){let g=(J()-u)/1e9,w=l(c.path).padEnd(9);if(c.type==="data"){let E=p(c);return`[${g.toFixed(3)}s] ${w} \u2190${E?` ${E}`:""}`}if(c.type==="error"){let E=p(c);return`[${g.toFixed(3)}s] ${w} \u2717${E?` ${E}`:""}`}return c.type==="complete"?`[${g.toFixed(3)}s] ${w} \u25A0 complete`:`[${g.toFixed(3)}s] ${w} ${c.type}`}if(n==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let y=d[c.type]??"",m=c.path?`${d.path}${c.path}${d.reset} `:"",N=c.type==="data"||c.type==="error",v=c.type==="pause"||c.type==="resume",b=N?` ${It(c.data)}`:v?` ${It(c.lockId)}`:"",T=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,_=T?.trigger_dep_name!=null?` <- ${T.trigger_dep_name}`:T?.trigger_dep_index!=null?` <- #${T.trigger_dep_index}`:"",k=c.in_batch?" [batch]":"";return`${m}${y}${c.type.toUpperCase()}${d.reset}${b}${_}${k}`};e.onEvent(c=>{i(c.type)&&o(h(c),c)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){_n(this._disposers,this.name),this.signal([[H]],{internal:!0}),_n(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,...n}=this.describe({detail:"full"}),o={};for(let i of Object.keys(n.nodes).sort()){let{lastMutation:d,guard:u,...l}=n.nodes[i];o[i]=l}let s=[...n.subgraphs].sort(),a={...n,version:1,nodes:o,subgraphs:s};if(e?.format==null)return a;if(e.format==="json-string")return JSON.stringify(a);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let i=this.config.lookupCodec(e.codec);if(i==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return Yt(i,i.encode(a))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??Ve,{codec:o,codecVersion:s,payload:a}=Jt(e,n);return o.decode(a,s)}restore(e,t){if(On(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let n=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(s=>ht(s)),o=t?.includeProducers===!0;for(let s of Object.keys(e.nodes).sort()){if(n!==null&&!n.some(i=>i.test(s)))continue;let a=e.nodes[s];if(a!==void 0){if(!("value"in a)||a.value===void 0){"value"in a&&a.value===void 0&&t?.onError?.(s,new Error(`restore: slice.value is undefined for "${s}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(a.type==="derived"||a.type==="effect")&&!(a.type==="producer"&&!o)){if(a.v!=null){let d=this.tryResolve(s)?.v;if(d!=null&&d.id===a.v.id&&d.version===a.v.version)continue}try{this.set(s,a.value)}catch(i){t?.onError?.(s,i)}}}}}static fromSnapshot(e,t){On(e);let n=typeof t=="function"?t:t?.build,o=typeof t=="function"?void 0:t?.factories,s=new r(e.name);if(n)return n(s),s.restore(e),s;for(let h of[...e.subgraphs].sort((c,y)=>{let m=c.split(V).length,N=y.split(V).length;return m!==N?m-N:c<y?-1:c>y?1:0})){let c=h.split(V),y=s;for(let m of c)y._mounts.has(m)||y.mount(m,new r(m)),y=y._mounts.get(m)}let a=o?Object.entries(o).map(([h,c])=>({re:ht(h),factory:c})):[],i=h=>{for(let c of a)if(c.re.test(h))return c.factory},d=h=>{let c=h.split(V),y=c.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${h}"`);let m=s;for(let N of c){let v=m._mounts.get(N);if(!v)throw new Error(`unknown mount "${N}" in path "${h}"`);m=v}return[m,y]},u=Object.entries(e.nodes).filter(([h])=>!h.includes(`${V}${oe}${V}`)).sort((h,c)=>h[0]<c[0]?-1:h[0]>c[0]?1:0),l=new Map(u),f=new Map,p=!0;for(;l.size>0&&p;){p=!1;for(let[h,c]of[...l.entries()]){let y=c?.deps??[];if(!y.every(_=>f.has(_)))continue;let[m,N]=d(h),v={...c?.meta??{}},b=i(h),T;if(c?.type==="state")T=$(c.value,{meta:v});else{if(b==null)continue;T=b(N,{path:h,type:c.type,value:c.value,meta:v,deps:y,resolvedDeps:y.map(_=>f.get(_))})}m.add(T,{name:N}),f.set(h,T),l.delete(h),p=!0}}if(l.size>0){let h=[...l.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${h}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return s.restore(e),s}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let n=e.map(u=>({tier:u,debounceMs:Math.max(0,u.debounceMs??0),compactEvery:Math.max(1,u.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));t.autoRestore===!0&&this._cascadeRestore(e,t.onError);let o=(u,l)=>{if(u.disposed)return;let f=br(l.nodes);if(u.lastSnapshot!=null&&f!==""&&f===u.lastFingerprint)return;let p=u.seq+1,h=et(),m=u.lastSnapshot==null||p%u.compactEvery===0?{name:this.name,mode:"full",snapshot:l,seq:p,timestamp_ns:h,format_version:De}:{name:this.name,mode:"diff",diff:Rn(u.lastSnapshot,l),seq:p,timestamp_ns:h,format_version:De};if(u.tier.filter&&!u.tier.filter(m))return;let N;try{N=u.tier.save(m)}catch(v){t.onError?.(v,u.tier);return}if(N&&typeof N.then=="function"){let T=(u.savePending??Promise.resolve()).then(()=>N,()=>N).then(()=>{u.disposed||(u.seq=p,u.lastSnapshot=l,u.lastFingerprint=f)},_=>{t.onError?.(_,u.tier)});u.savePending=T.finally(()=>{u.savePending===T&&(u.savePending=void 0)})}else u.seq=p,u.lastSnapshot=l,u.lastFingerprint=f},s=(u,l)=>{try{o(u,l)}catch(f){t.onError?.(f,u.tier)}},a=(u,l)=>{if(!l.some(c=>{let y=this.config.messageTier(c[0]);return y>=3&&y<5}))return;if(t.filter){let c=this.tryResolve(u);if(c==null)return;let y=Dt(c,St("standard"));if(!t.filter(u,y))return}let p,h=()=>(p==null&&(p=this.snapshot()),p);for(let c of n)c.disposed||(c.debounceMs===0?s(c,h()):(c.timer==null&&(c.timer=new ct),c.timer.start(c.debounceMs,()=>{c.disposed||s(c,this.snapshot())})))},i;if(t.paths!=null){let l=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(f=>{let p=this.tryResolve(f);return p==null?()=>{}:p.subscribe(h=>a(f,h))});i=()=>{for(let f of l)f()}}else i=this.observe().subscribe((u,l)=>a(u,l));let d=()=>{i();for(let u of n)u.disposed=!0,u.timer?.cancel();this._storageDisposers.delete(d)};return this._storageDisposers.add(d),{dispose:d}}async _cascadeRestore(e,t){for(let n of e){let o;try{o=await n.load?.()}catch(a){t?.(a,n);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let s=o;try{if(s.mode==="full"&&s.snapshot!=null)return this.restore(s.snapshot),!0;if(s.version===De&&s.nodes!=null)return this.restore(s),!0}catch(a){t?.(a,n)}}return!1}static async fromStorage(e,t,n){for(let o of t){let s;try{s=await o.load?.()}catch(d){n?.onError?.(d,o);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let a=s,i=a.mode==="full"&&a.snapshot!=null?a.snapshot:a.version===De&&a.nodes!=null?a:void 0;if(i!=null)try{return r.fromSnapshot(i,n)}catch(d){n?.onError?.(d,o)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${t.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,t,n){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let o={path:e,annotation:t,timestamp_ns:J(),...n?.actor!=null?{actor:n.actor}:{}};this._traceRing.push(o)}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(o=>!e(o)),n=this._traceRing.size-t.length;this._traceRing.clear();for(let o of t)this._traceRing.push(o);return n}static diff(e,t){let n=new Set(Object.keys(e.nodes)),o=new Set(Object.keys(t.nodes)),s=[...o].filter(v=>!n.has(v)).sort(),a=[...n].filter(v=>!o.has(v)).sort(),i=[],d=[];for(let v of n){if(!o.has(v))continue;let b=e.nodes[v],T=t.nodes[v],_=b.v,k=T.v;_!=null&&k!=null&&_.id===k.id&&_.version!==k.version&&d.push({path:v,id:_.id,from:_.version,to:k.version});let g=_!=null&&k!=null&&_.id===k.id&&_.version===k.version;for(let w of["type","status","sentinel"]){let E=b[w],S=T[w];E!==S&&i.push({path:v,field:w,from:E,to:S})}if(!g)for(let w of["value","meta"]){let E=b[w],S=T[w];yr(E,S)||i.push({path:v,field:w,from:E,to:S})}}let u=v=>`${v.from} ${v.to}`,l=new Set(e.edges.map(u)),f=new Set(t.edges.map(u)),p=t.edges.filter(v=>!l.has(u(v))),h=e.edges.filter(v=>!f.has(u(v))),c=new Set(e.subgraphs),y=new Set(t.subgraphs),m=[...y].filter(v=>!c.has(v)).sort(),N=[...c].filter(v=>!y.has(v)).sort();return{nodesAdded:s,nodesRemoved:a,nodesChanged:i,versionChanges:d,edgesAdded:p,edgesRemoved:h,subgraphsAdded:m,subgraphsRemoved:N}}};function Rn(r,e){let t=de.diff(r,e),n={};for(let o of t.nodesAdded){let s=e.nodes[o];s!=null&&(n[o]=s)}return{...t,nodesAddedFull:n}}function Ft(r,e,t,n={}){let o={paths:[],depths:new Map,truncated:!1};if(!e)return n.withDetail?o:[];if(!n.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let s=n.maxDepth;if(s!=null&&(!Number.isInteger(s)||s<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(s===0)return n.withDetail?o:[];let a=new Map,i=new Map,d=new Map,u=new Map,l=new Set;for(let[b,T]of Object.entries(r.nodes)){if(!b)continue;l.add(b);let _=T.deps??[];a.set(b,_);for(let k of _)k&&(l.add(k),i.has(k)||i.set(k,new Set),i.get(k).add(b))}for(let b of r.edges){if(b==null||typeof b!="object")continue;let T=typeof b.from=="string"?b.from:"",_=typeof b.to=="string"?b.to:"";!T||!_||(l.add(T),l.add(_),u.has(T)||u.set(T,new Set),u.get(T).add(_),d.has(_)||d.set(_,new Set),d.get(_).add(T))}if(!l.has(e))return n.withDetail?o:[];let f=n.both===!0,p=b=>{if(f){let g=a.get(b)??[],w=d.get(b),E=i.get(b),S=u.get(b),x=[...g];return w&&x.push(...w),E&&x.push(...E),S&&x.push(...S),x}if(t==="upstream"){let g=a.get(b)??[],w=d.get(b);return w?[...g,...w]:g}let T=i.get(b),_=u.get(b),k=T?[...T]:[];return _&&k.push(..._),k},h=new Set([e]),c=new Map,y=[{path:e,depth:0}],m=0,N=!1;for(;m<y.length;){let b=y[m++];if(s!=null&&b.depth>=s){p(b.path).length>0&&(N=!0);continue}for(let T of p(b.path))!T||h.has(T)||(h.add(T),c.set(T,b.depth+1),y.push({path:T,depth:b.depth+1}))}let v=[...c.keys()].sort((b,T)=>b<T?-1:b>T?1:0);return n.withDetail?{paths:v,depths:c,truncated:N}:v}function Er(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++){let n=r[t],o=e[t];if(n.path!==o.path||n.type!==o.type||n.status!==o.status||n.hop!==o.hop||n.dep_index!==o.dep_index||n.annotation!==o.annotation||n.value!==o.value||n.lastMutation!==o.lastMutation)return!1;let s=n.v,a=o.v;if(s!==a&&(s==null||a==null||s.id!==a.id||s.version!==a.version))return!1}return!0}it();$e();Ke();le();ze();fe();Dn();$e();le();fe();ze();var $t=class{_version=0;_maxSize;_buf;_head=0;_size=0;constructor(e,t){if(t!==void 0&&t<1)throw new RangeError("maxSize must be >= 1");if(this._maxSize=t,t!==void 0){if(this._buf=new Array(t),e&&e.length>0){let n=Math.min(e.length,t),o=e.length-n;for(let s=0;s<n;s++)this._buf[s]=e[o+s];this._size=n}}else this._buf=e?[...e]:[],this._size=this._buf.length}get version(){return this._version}get size(){return this._size}at(e){if(!Number.isInteger(e))return;let t=e>=0?e:this._size+e;if(!(t<0||t>=this._size))return this._maxSize!==void 0?this._buf[(this._head+t)%this._maxSize]:this._buf[t]}append(e){this._rawAppend(e),this._version+=1}appendMany(e){if(e.length===0)return;let t=this._maxSize!==void 0&&e.length>this._maxSize?e.length-this._maxSize:0;for(let n=t;n<e.length;n++)this._rawAppend(e[n]);this._version+=1}clear(){if(this._size===0)return 0;let e=this._size;if(this._maxSize===void 0)this._buf.length=0;else for(let t=0;t<e;t++)this._buf[(this._head+t)%this._maxSize]=void 0;return this._head=0,this._size=0,this._version+=1,e}trimHead(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`trimHead: n must be a non-negative integer (got ${e})`);if(e===0||this._size===0)return 0;let t=Math.min(e,this._size);if(this._maxSize===void 0)this._buf.splice(0,t);else{for(let n=0;n<t;n++)this._buf[(this._head+n)%this._maxSize]=void 0;this._head=(this._head+t)%this._maxSize}return this._size-=t,this._version+=1,t}slice(e,t){if(!Number.isInteger(e)||e<0)throw new RangeError(`slice: start must be a non-negative integer (got ${e})`);if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${t})`);let n=t===void 0?this._size:Math.min(Math.max(t,0),this._size),o=Math.min(e,this._size);if(o>=n)return[];let s=n-o;if(this._maxSize===void 0)return this._buf.slice(o,n);let a=new Array(s);for(let i=0;i<s;i++)a[i]=this._buf[(this._head+o+i)%this._maxSize];return a}tail(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`tail: n must be a non-negative integer (got ${e})`);if(e===0||this._size===0)return[];let t=Math.min(e,this._size);return this.slice(this._size-t,this._size)}toArray(){if(this._maxSize===void 0)return[...this._buf];let e=new Array(this._size);for(let t=0;t<this._size;t++)e[t]=this._buf[(this._head+t)%this._maxSize];return e}snapshot(){return this.toArray()}restore(e){if(this._maxSize===void 0){this._buf.length=0;for(let t=0;t<e.length;t++)this._buf.push(e[t]);this._size=this._buf.length}else{let t=this._maxSize;for(let s=0;s<t;s++)this._buf[s]=void 0;this._head=0;let n=Math.min(e.length,t),o=e.length-n;for(let s=0;s<n;s++)this._buf[s]=e[o+s];this._size=n}this._version+=1}_rawAppend(e){if(this._maxSize===void 0){this._buf.push(e),this._size=this._buf.length;return}this._size<this._maxSize?(this._buf[(this._head+this._size)%this._maxSize]=e,this._size+=1):(this._buf[this._head]=e,this._head=(this._head+1)%this._maxSize)}};function Je(r){return r.subscribe(()=>{})}var kr=64;function An(r,e={}){let{name:t,maxSize:n,versioning:o,guard:s,backend:a}=e,i=a??new $t(r,n),d=$(i.toArray(),{name:t,describeKind:"state",equals:(g,w)=>g===w,...o!=null?{versioning:o}:{},...s!=null?{guard:s}:{}});function u(){let g=i.toArray();ae(()=>{d.down([[q]],{internal:!0}),d.down([[I,g]],{internal:!0})})}let l=new Map,f=new Map,p=new Map;function h(g,w){return`${g}:${w===void 0?"END":w}`}function c(g){if(g.size<kr)return;let w=g.keys().next();if(w.done)return;let E=g.get(w.value);E!==void 0&&E.dispose(),g.delete(w.value)}function y(g){let w=i.version;try{return g()}finally{i.version!==w&&u()}}function m(g){if(!Number.isInteger(g)||g<0)throw new RangeError(`tail: n must be a non-negative integer (got ${g})`);let w=l.get(g);if(w!==void 0)return l.delete(g),l.set(g,w),w.node;c(l);let E=L([d],([x])=>{let A=x;return g===0||A.length===0?[]:A.slice(Math.max(0,A.length-g))},{initial:i.tail(g),describeKind:"derived"}),S=Je(E);return l.set(g,{node:E,dispose:S}),E}function N(g,w){if(!Number.isInteger(g)||g<0)throw new RangeError(`slice: start must be a non-negative integer (got ${g})`);if(w!==void 0&&(!Number.isInteger(w)||w<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${w})`);let E=h(g,w),S=f.get(E);if(S!==void 0)return f.delete(E),f.set(E,S),S.node;c(f);let x=L([d],([M])=>{let C=M;return w===void 0?C.slice(g):C.slice(g,w)},{initial:i.slice(g,w),describeKind:"derived"}),A=Je(x);return f.set(E,{node:x,dispose:A}),x}function v(g){let w=p.get(g);if(w!==void 0)return w.node;let E=L([d,g],([x,A])=>{let M=x,C=Math.max(0,Math.trunc(A??0));return M.slice(C)},{initial:[],describeKind:"derived"}),S=Je(E);return p.set(g,{node:E,dispose:S}),E}let b,T;function _(){b===void 0&&(b=Q([d],(g,w,E)=>{let S=g[0],A=S!=null&&S.length>0?S.at(-1):E.prevData[0];if(A==null||A.length===0){w.down([[K]]);return}w.emit(A[A.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:i.size===0?void 0:i.at(i.size-1)}),T=L([d],([g])=>g.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:i.size>0}),Je(b),Je(T))}let k={entries:d,get size(){return i.size},at(g){return i.at(g)},append(g){y(()=>i.append(g))},appendMany(g){g.length!==0&&y(()=>i.appendMany(g))},clear(){y(()=>i.clear())},trimHead(g){y(()=>i.trimHead(g))},withLatest(){return _(),d},get lastValue(){return _(),b},get hasLatest(){return _(),T},view(g){switch(g.kind){case"tail":return m(g.n);case"slice":return N(g.start,g.stop);case"fromCursor":return v(g.cursor)}},attach(g){let w=g.subscribe(E=>{for(let S of E)S[0]===I&&k.append(S[1])});return()=>w()},attachStorage(g){if(g.length===0)return()=>{};let w=new Map;for(let S of g)w.set(S,i.size);(async()=>{for(let S of g)if(typeof S.loadEntries=="function")try{let x=await Promise.resolve(S.loadEntries());x.entries.length>0&&i.size===0&&(i.restore(x.entries),w.set(S,x.entries.length),u());break}catch{}})();let E=d.subscribe(S=>{for(let x of S){if(x[0]!==I)continue;let A=x[1];for(let M of g){let C=w.get(M)??0;if(A.length<C){try{let te=M.appendEntries(A);te instanceof Promise&&te.catch(()=>{})}catch{}w.set(M,A.length);continue}if(A.length===C)continue;let ee=A.slice(C);w.set(M,A.length);try{let te=M.appendEntries(ee);te instanceof Promise&&te.catch(()=>{})}catch{}}}});return()=>E()},disposeAllViews(){for(let g of l.values())g.dispose();l.clear();for(let g of f.values())g.dispose();f.clear();for(let g of p.values())g.dispose();p.clear()},dispose(){for(let g of l.values())g.dispose();l.clear();for(let g of f.values())g.dispose();f.clear();for(let g of p.values())g.dispose();p.clear()}};return k}ut();function Xe(r,e){if(!Number.isFinite(r)||!Number.isInteger(r)||r<0)throw new Error(`${e} must be a non-negative integer`);return r}function Ze(r,e){return Sn("messaging",r,e)}var Rr=1024,Lt=class extends de{_log;events;latest;hasLatest;constructor(e,t={}){super(e,t.graph),this._log=An([],{name:"events",maxSize:t.retainedLimit??Rr}),this._log.withLatest(),this.events=this._log.entries,this.add(this.events,{name:"events"}),this.latest=L([this.events],([n])=>{let o=n;return o.length===0?null:o[o.length-1]},{name:"latest",describeKind:"derived",meta:Ze("topic_latest")}),this.add(this.latest,{name:"latest"}),this.addDisposer(pe(this.latest)),this.hasLatest=L([this.events],([n])=>n.length>0,{name:"hasLatest",describeKind:"derived",meta:Ze("topic_has_latest")}),this.add(this.hasLatest,{name:"hasLatest"}),this.addDisposer(pe(this.hasLatest)),this.addDisposer(()=>{this.events.down([[F]])}),this.addDisposer(()=>this._log.disposeAllViews())}publish(e){if(e===void 0)throw new TypeError(`TopicGraph "${this.name}": publish(undefined) is not allowed (spec \xA75.12 SENTINEL).`);this._log.append(e)}attachEventStorage(e){return this._log.attachStorage(e)}retained(){return this.events.cache}get _logBundle(){return this._log}},Vt=class extends de{cursor;available;topic;_disposed=!1;constructor(e,t,n={}){super(e,n.graph),this.topic=t;let o;if(n.from!==void 0?n.from==="retained"?o=0:n.from==="now"?o=t.events.cache.length:o=Xe(n.from,"subscription from"):o=Xe(n.cursor??0,"subscription cursor"),this.cursor=$(o,{name:"cursor",describeKind:"state",meta:Ze("subscription_cursor")}),this.add(this.cursor,{name:"cursor"}),this.available=t._logBundle.view({kind:"fromCursor",cursor:this.cursor}),this.add(this.available,{name:"available"}),this.addDisposer(pe(this.available)),n.advanceOn!==void 0){let s=n.advanceOn,a=!1,i=Q([s],()=>{if(!a){a=!0;return}if(this._disposed)return;let d=this.available.cache;if(d.length===0)return;let u=this.cursor.cache+d.length;this.cursor.emit(u)},{name:"advancePump",describeKind:"effect",meta:Ze("subscription_advance_pump")});this.add(i,{name:"advancePump"}),this.addDisposer(pe(i))}}ack(e){if(this._disposed)return this.cursor.cache;let t=this.available.cache,n=e===void 0?t.length:Xe(e,"subscription ack count"),o=Math.min(n,t.length);if(o<=0)return this.cursor.cache;let s=this.cursor.cache+o;return this.cursor.emit(s),s}pull(e){if(this._disposed)return[];let t=this.available.cache,n=e===void 0?t.length:Xe(e,"subscription pull limit");return t.slice(0,n)}pullAndAck(e){if(this._disposed)return{items:[],cursor:this.cursor.cache};let t=this.available.cache,n=e===void 0?t.length:Xe(e,"subscription pullAndAck limit"),o=t.slice(0,n);if(o.length===0)return{items:o,cursor:this.cursor.cache};let s=this.cursor.cache+o.length;return this.cursor.emit(s),{items:o,cursor:s}}dispose(){this._disposed||(this._disposed=!0,this.cursor.down([[F]]),this.destroy())}};var zt=class{_map=new Map;version;constructor(e){this.version=e}get size(){return this._map.size}has(e){return this._map.has(e)}get(e){return this._map.get(e)}set(e,t){this._map.set(e,t)}delete(e){return this._map.delete(e)}keys(){return this._map.keys()}},Bt=class extends de{_registry;version;_defaultTopicOptions;constructor(e,t={}){super(e,t.graph);let n=$(0,{name:"version",describeKind:"state",meta:Ze("hub_version")});this.add(n,{name:"version"}),this.version=n,this._registry=new zt(n),this._defaultTopicOptions={...t.defaultTopicOptions??{}}}get size(){return this._registry.size}has(e){return this._registry.has(e)}topicNames(){return this._registry.keys()}topic(e,t){let n=this._registry.get(e);if(n===void 0){let o={...this._defaultTopicOptions,...t??{}};n=new Lt(e,o),this._registry.set(e,n),this.mount(e,n);let s=this.version.cache??0;this.version.emit(s+1)}return n}publish(e,t){this.topic(e).publish(t)}publishMany(e){ae(()=>{for(let[t,n]of e)this.topic(t).publish(n)})}subscribe(e,t,n){let o=this.topic(t);return new Vt(e,o,n)}removeTopic(e){if(!this._registry.has(e))return!1;try{this.remove(e)}finally{this._registry.delete(e);let t=this.version.cache??0;this.version.emit(t+1)}return!0}};function Cn(r,e){return new Bt(r,e)}function Sr(r){if(typeof r!="object"||r===null)return!1;let e=r;return typeof e.subscribe=="function"&&typeof e.down=="function"&&typeof e.emit=="function"}function Mn(r,e){if(r.length===0)return{best:null,bestScore:Number.NEGATIVE_INFINITY};if(r.length===1){let s=jt(e);return{best:r[0],bestScore:s}}if(e.some(s=>typeof s.candidateIndex=="number")){let s=new Array(r.length);for(let d=0;d<r.length;d++)s[d]={sum:0,count:0};for(let d of e){let u=d.candidateIndex;typeof u=="number"&&u>=0&&u<r.length&&(s[u].sum+=d.score,s[u].count+=1)}let a=r[0],i=s[0].count>0?s[0].sum/s[0].count:Number.NEGATIVE_INFINITY;for(let d=1;d<r.length;d++){let u=s[d].count>0?s[d].sum/s[d].count:Number.NEGATIVE_INFINITY;u>i&&(i=u,a=r[d])}return{best:a,bestScore:i}}let n=r[0],o=e[0]?.score??Number.NEGATIVE_INFINITY;for(let s=1;s<r.length;s++){let a=e[s]?.score??Number.NEGATIVE_INFINITY;a>o&&(o=a,n=r[s])}return{best:n,bestScore:o}}function jt(r){if(r.length===0)return Number.NEGATIVE_INFINITY;let e=0;for(let t of r)e+=t.score;return e/r.length}function Dr(r,e,t,n){let o=n.name??"refine-loop",s=new de(o,n.graph),a=Sr(n.dataset)?n.dataset:$(n.dataset,{name:"dataset"});s.add(a,{name:"dataset"});let i=$(0,{name:"iteration"});s.add(i,{name:"iteration"});let d=$(t,{name:"strategy",equals:()=>!1});s.add(d,{name:"strategy"});let u=$(null,{name:"lastFeedback"});s.add(u,{name:"lastFeedback"});let l=$([],{name:"prevCandidates"});s.add(l,{name:"prevCandidates"});let f=$(!1,{name:"paused"});s.add(f,{name:"paused"});let p=$("running",{name:"status"});s.add(p,{name:"status"});let h=$([],{name:"history",equals:()=>!1});s.add(h,{name:"history"});let c=$(null,{name:"best"});s.add(c,{name:"best"});let y=$(Number.NEGATIVE_INFINITY,{name:"score"});s.add(y,{name:"score"});let m=$(0,{name:"budget-used"});s.add(m,{name:"budget-used"});let N=Cn("stages");s.mount("stages",N);let v=N.topic("generate"),b=N.topic("evaluate"),T=N.topic("analyze"),_=N.topic("decide"),k=t,g=null,w=[];s.addDisposer(d.subscribe(O=>{for(let D of O)D[0]===I&&(k=D[1])})),s.addDisposer(u.subscribe(O=>{for(let D of O)D[0]===I&&(g=D[1])})),s.addDisposer(l.subscribe(O=>{for(let D of O)D[0]===I&&(w=D[1])}));let E=ln(i,O=>{let D=k,z=O===0||g==null;return Q([],(U,Z)=>{let be=!1;try{let ye=z?D.seed(r):D.generate(g,w);if(ye instanceof Promise)return ye.then(Ge=>{be||Z.emit(Ge)},Ge=>{be||Z.down([[G,Ge]])}),()=>{be=!0};Z.emit(ye)}catch(ye){be=!0,Z.down([[G,ye]])}},{describeKind:"producer"})},{name:"candidates"});s.add(E,{name:"candidates"});let S=_e([E],(O,D,z)=>{let U=z.terminalDeps[0];U!==void 0&&U!==!0&&p.emit("errored")},{name:"error-watcher",errorWhenDepsError:!1});s.add(S,{name:"error-watcher"}),s.addDisposer(S.subscribe(()=>{}));let x=L([E,i],([O,D])=>({iteration:D,candidates:O,timestamp_ns:J()}),{name:"generate-event"});s.add(x,{name:"generate-event"}),s.addDisposer(x.subscribe(()=>{}));let A=_e([x],([O])=>{v.publish(O)},{name:"generate-publish"});s.add(A,{name:"generate-publish"}),s.addDisposer(A.subscribe(()=>{}));let M=_e([E],([O])=>{l.emit(O)},{name:"generate-mirror"});s.add(M,{name:"generate-mirror"}),s.addDisposer(M.subscribe(()=>{}));let C=e(E,a);s.add(C,{name:"scores"});let ee=L([C,E,i],([O,D,z])=>({iteration:z,candidates:D,scores:O,timestamp_ns:J()}),{name:"evaluate-event"});s.add(ee,{name:"evaluate-event"}),s.addDisposer(ee.subscribe(()=>{}));let te=_e([ee],([O])=>{b.publish(O)},{name:"evaluate-publish"});s.add(te,{name:"evaluate-publish"}),s.addDisposer(te.subscribe(()=>{}));let he=L([C,E],([O,D])=>k.analyze(O,D),{name:"feedback"});s.add(he,{name:"feedback"});let Ce=L([he,E,i],([O,D,z])=>({iteration:z,candidates:D,feedback:O,timestamp_ns:J()}),{name:"analyze-event"});s.add(Ce,{name:"analyze-event"}),s.addDisposer(Ce.subscribe(()=>{}));let Be=_e([Ce],([O])=>{T.publish(O)},{name:"analyze-publish"});s.add(Be,{name:"analyze-publish"}),s.addDisposer(Be.subscribe(()=>{}));let Ne=L([h],([O])=>{let D=O;if(n.patience==null||D.length<=n.patience)return!1;let z=D.slice(-(n.patience+1)),U=z[0].bestScore;return z.slice(1).every(Z=>Z.bestScore<=U)},{name:"patience-check"});s.add(Ne,{name:"patience-check"});let Oe=L([y],([O])=>n.minScore!=null&&O>=n.minScore,{name:"min-score-check"});s.add(Oe,{name:"min-score-check"});let xe=L([h],([O])=>{let D=O;if(n.minDelta==null||D.length<2)return!1;let z=D[D.length-2].bestScore,U=D[D.length-1].bestScore;return Math.abs(U-z)<n.minDelta},{name:"min-delta-check"});s.add(xe,{name:"min-delta-check"});let me=L([m],([O])=>n.maxEvaluations!=null&&O>=n.maxEvaluations,{name:"max-evaluations-check"});s.add(me,{name:"max-evaluations-check"});let Me=L([i],([O])=>n.maxIterations!=null&&O>=n.maxIterations,{name:"max-iterations-check"});s.add(Me,{name:"max-iterations-check"});let R=L([m],([O])=>n.budget!=null&&O>=n.budget,{name:"budget-exhausted-check"});s.add(R,{name:"budget-exhausted-check"}),s.addDisposer(Ne.subscribe(()=>{})),s.addDisposer(Oe.subscribe(()=>{})),s.addDisposer(xe.subscribe(()=>{})),s.addDisposer(me.subscribe(()=>{})),s.addDisposer(Me.subscribe(()=>{})),s.addDisposer(R.subscribe(()=>{}));let P=L([Ne,Oe,xe,me,Me],([O,D,z,U,Z])=>O?{converged:!0,reason:"patience"}:D?{converged:!0,reason:"min-score"}:z?{converged:!0,reason:"min-delta"}:U?{converged:!0,reason:"max-evaluations"}:Z?{converged:!0,reason:"max-iterations"}:{converged:!1},{name:"converged"});s.add(P,{name:"converged"}),s.addDisposer(P.subscribe(()=>{}));let Y=-1,ge=_e([he,C,E],([O,D,z])=>{let U=i.cache,Z=O,be=z,ye=D;if(U<=Y)return;Y=U;let{best:Ge,bestScore:Gn}=Mn(be,ye),In=h.cache,Pn={n:U,candidates:be,scores:ye,feedback:Z,best:Ge,bestScore:Gn,timestamp_ns:J()},ve=[...In,Pn],mt=m.cache+be.length,ne="continue",Ee,Fn=n.budget!=null&&mt>=n.budget,$n=f.cache;if(Fn)ne="budget",Ee="budget";else if(n.minScore!=null&&Z.score>=n.minScore)ne="converged",Ee="min-score";else if(n.maxIterations!=null&&U>=n.maxIterations)ne="converged",Ee="max-iterations";else if(n.maxEvaluations!=null&&mt>=n.maxEvaluations)ne="converged",Ee="max-evaluations";else if(n.minDelta!=null&&ve.length>=2){let Qe=ve[ve.length-2].bestScore,gt=ve[ve.length-1].bestScore;Math.abs(gt-Qe)<n.minDelta&&(ne="converged",Ee="min-delta")}else if(n.patience!=null&&ve.length>n.patience){let Qe=ve.slice(-(n.patience+1)),gt=Qe[0].bestScore;Qe.slice(1).every(Ln=>Ln.bestScore<=gt)&&(ne="converged",Ee="patience")}ne==="continue"&&$n&&(ne="paused"),ae(()=>{c.emit(Ge),y.emit(Z.score),h.emit(ve),m.emit(mt),u.emit(Z),_.publish({iteration:U,decision:ne,reason:Ee,timestamp_ns:J()}),ne==="continue"?i.emit(U+1):p.emit(ne==="converged"?"converged":ne==="budget"?"budget":"paused")})},{name:"decide-bridge"});return s.add(ge,{name:"decide-bridge"}),s.addDisposer(ge.subscribe(()=>{})),Object.assign(s,{best:c,score:y,status:p,history:h,strategy:d,iteration:i,generate:v,evaluate:b,analyze:T,decide:_,setStrategy(O){d.emit(O)},pause(){f.emit(!0)},resume(){p.cache==="paused"&&ae(()=>{f.emit(!1),p.emit("running"),i.emit(i.cache+1)})}})}function Ar(r){let e=r.width??4;return{name:r.name??"blindVariation",seed(n){return[n]},analyze(n,o){let s=jt(n),a=null;for(let i of n)(!a||i.score<a.score)&&(a=i);return{summary:`blindVariation iteration: mean=${s.toFixed(3)}, n=${n.length}`,score:s,weakTasks:a?[a.taskId]:[]}},async generate(n,o){if(o.length===0)throw new Error("blindVariation.generate: empty candidate batch \u2014 cannot derive prior for teacher");let s=o[o.length-1],a=0,d={prior:s,reportCost:u=>{a+=u}};try{if(r.parallel!==!1)return await Promise.all(Array.from({length:e},()=>r.teacher(d)));let u=[];for(let l=0;l<e;l++)u.push(await r.teacher(d));return u}finally{if(r.tokens!=null&&a>0){let u=r.tokens.cache??0;r.tokens.emit(u+a)}}}}}function Cr(r){return typeof r=="object"&&r!==null&&r.kind==="errorCritique"}function Mr(r,e){return r.length===0?`No task scored below the batch mean (${e.score.toFixed(3)}). Reinforce the current direction.`:`Failures below threshold:
|
|
4
|
-
${r.map(n=>{let o=n.error!=null?` | error: ${n.error}`:"";return`- ${n.taskId} (score=${n.score.toFixed(3)})${o}`}).join(`
|
|
5
|
-
`)}`}function Gr(r){let e=r.width??4,t=r.name??"errorCritique",n=r.maxFailureSamples??5,o=r.formatCritique??Mr;return{name:t,seed(s){return[s]},analyze(s,a){let i=jt(s),d=typeof r.failureThreshold=="function"?r.failureThreshold(s):r.failureThreshold,u=d===void 0&&!Number.isFinite(i),l=d??i,f=u?[...s].sort((b,T)=>b.score-T.score):s.filter(b=>b.score<l).slice().sort((b,T)=>b.score-T.score),p=f.slice(0,n),{best:h,bestScore:c}=Mn(a,s),y={summary:"",score:i,weakTasks:p.map(b=>b.taskId)},m=o(p,y),N={kind:"errorCritique",best:h,failures:p,critiqueText:m},v=f.length>p.length?` (top ${p.length} retained)`:"";return{summary:`errorCritique iteration: mean=${i.toFixed(3)}, failures=${f.length}${v}/${s.length}, bestScore=${c.toFixed(3)}`,critique:N,weakTasks:p.map(b=>b.taskId),score:i}},async generate(s,a){if(a.length===0)throw new Error("errorCritique.generate: empty candidate batch \u2014 cannot derive prior for teacher");let i=Cr(s.critique)?s.critique:void 0,d=i!==void 0?i.best:a[a.length-1],u=i?.critiqueText??s.summary,l=i?.failures??[],f=0,h={prior:d,critique:u,failures:l,reportCost:c=>{f+=c}};try{if(r.parallel!==!1)return await Promise.all(Array.from({length:e},()=>r.teacher(h)));let c=[];for(let y=0;y<e;y++)c.push(await r.teacher(h));return c}finally{if(r.tokens!=null&&f>0){let c=r.tokens.cache??0;r.tokens.emit(c+f)}}}}}0&&(module.exports={blindVariation,errorCritique,refineLoop});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import '../../node-BYInONRr.cjs';
|
|
2
|
-
import '../../extra/sources.cjs';
|
|
3
|
-
import '../../graph-E6likq7w.cjs';
|
|
4
|
-
import '../../index-Cnr1WrlX.cjs';
|
|
5
|
-
export { A as AnalyzeEvent, B as BlindVariationContext, d as BlindVariationOptions, C as ConvergenceOptions, D as DatasetItem, e as DecideEvent, f as ErrorCritiqueContext, g as ErrorCritiqueOptions, a as EvalResult, h as EvaluateEvent, E as Evaluator, F as Feedback, G as GenerateEvent, I as Iteration, j as RefineLoopGraph, b as RefineLoopOptions, c as RefineStatus, R as RefineStrategy, k as blindVariation, l as errorCritique, r as refineLoop } from '../../index-t6L2qpHh.cjs';
|
|
6
|
-
import '../../meta-Ct9nqQS5.cjs';
|
|
7
|
-
import '../../extra/storage-core.cjs';
|
|
8
|
-
import '../../extra/storage-tiers.cjs';
|
|
9
|
-
import '../../reactive-log-_zeEnB9H.cjs';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import '../../node-BYInONRr.js';
|
|
2
|
-
import '../../extra/sources.js';
|
|
3
|
-
import '../../graph-BkIkog4h.js';
|
|
4
|
-
import '../../index-40ZT4MHj.js';
|
|
5
|
-
export { A as AnalyzeEvent, B as BlindVariationContext, d as BlindVariationOptions, C as ConvergenceOptions, D as DatasetItem, e as DecideEvent, f as ErrorCritiqueContext, g as ErrorCritiqueOptions, a as EvalResult, h as EvaluateEvent, E as Evaluator, F as Feedback, G as GenerateEvent, I as Iteration, j as RefineLoopGraph, b as RefineLoopOptions, c as RefineStatus, R as RefineStrategy, k as blindVariation, l as errorCritique, r as refineLoop } from '../../index-BgjS2b8N.js';
|
|
6
|
-
import '../../meta-D8OyedKp.js';
|
|
7
|
-
import '../../extra/storage-core.js';
|
|
8
|
-
import '../../extra/storage-tiers.js';
|
|
9
|
-
import '../../reactive-log-BlAsPLl2.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c}from"../../chunk-UWA6D7UF.js";import"../../chunk-J63M5U46.js";import"../../chunk-ECQRP2UT.js";import"../../chunk-3G5U5QNE.js";import"../../chunk-C72GO4IZ.js";import"../../chunk-4I45FVQS.js";import"../../chunk-L6NSJVJZ.js";import"../../chunk-2BX4NB34.js";import"../../chunk-SGS4OJGS.js";import"../../chunk-ESMPEKEV.js";import"../../chunk-FHRBBHJN.js";import"../../chunk-4VVTGLXJ.js";import"../../chunk-35JTVPOX.js";import"../../chunk-YXDRGKXP.js";import"../../chunk-CKFQS2CJ.js";import"../../chunk-LYCLF26R.js";import"../../chunk-CK2E7BTU.js";import"../../chunk-QYADASLV.js";export{b as blindVariation,c as errorCritique,a as refineLoop};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";var it=Object.defineProperty;var Fn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var Vn=Object.prototype.hasOwnProperty;var B=(n,e)=>()=>(n&&(e=n(n=0)),e);var jn=(n,e)=>{for(var t in e)it(n,t,{get:e[t],enumerable:!0})},zn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Bn(e))!Vn.call(n,o)&&o!==t&&it(n,o,{get:()=>e[o],enumerable:!(r=Fn(e,o))||r.enumerable});return n};var Un=n=>zn(it({},"__esModule",{value:!0}),n);function at(n){let e=Wn.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 J,Wn,Ie=B(()=>{"use strict";J=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}},Wn=["human","llm","wallet","system"]});function Yt(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 o=2+t.length+2+e.length;if(o>4294967295)throw new Error(`encodeEnvelope: total envelope size ${o} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let s=new Uint8Array(o),i=0;return s[i++]=ut,s[i++]=t.length,s.set(t,i),i+=t.length,s[i++]=r>>>8&255,s[i++]=r&255,s.set(e,i),s}function Jt(n,e){if(n.length<qt)throw new Error(`decodeEnvelope: bytes too short (${n.length} < ${qt})`);let t=0,r=n[t++];if(r!==ut)throw new Error(`decodeEnvelope: unsupported envelope version ${r} (expected ${ut})`);let o=n[t++];if(o===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+o+2>n.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+o+2} bytes, have ${n.length})`);let s=new TextDecoder().decode(n.subarray(t,t+o));t+=o;let i=(n[t]<<8|n[t+1])>>>0;t+=2;let a=n.subarray(t),d=e.lookupCodec(s);if(d==null)throw new Error(`decodeEnvelope: codec "${s}" not registered (envelope codec_v=${i})`);return{codec:d,codecVersion:i,payload:a}}function Zt(n){n.registerCodec(Hn)}var Hn,ut,qt,dt=B(()=>{"use strict";Hn={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)}},ut=1,qt=4});function Le(n){if(n==null)return ye;let{type:e,id:t,...r}=n;return{type:e??"system",id:t??"",...r}}var ye,ct=B(()=>{"use strict";ye={type:"system",id:""}});function $e(){return ve>0||Re}function Xt(){return ve>0}function Te(n){ve>0?Se.push(n):n()}function Ce(n){ve+=1;let e=!1;try{n()}catch(t){throw e=!0,t}finally{if(ve-=1,ve===0)if(e){if(!Re){let t=Se.splice(0);for(let r of t)try{r()}catch{}de.length=0,ce.length=0,we.length=0}}else Kn()}}function Kn(){let n=!Re;n&&(Re=!0);let e=[],t=0;try{for(;de.length>0||ce.length>0||we.length>0||n&&Se.length>0;){if(n&&Se.length>0){let s=Se.splice(0);for(let i of s)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw de.length=0,ce.length=0,we.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let o=(de.length>0?de:ce.length>0?ce:we).splice(0);for(let s of o)try{s()}catch(i){e.push(i)}}}finally{n&&(Re=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function Fe(n,e,t){if(e.length===0)return;if(e.length===1){let u=t(e[0][0]);if(u<3||!$e()){n(e);return}(u>=5?we:u===4?ce:de).push(()=>n(e));return}let r=e.length,o=r,s=r,i=r,a=0;for(;a<r&&t(e[a][0])<3;)a++;for(o=a;a<r&&t(e[a][0])===3;)a++;for(s=a;a<r&&t(e[a][0])===4;)a++;i=a;let d=$e();if(o>0){let u=e.slice(0,o);n(u)}if(s>o){let u=e.slice(o,s);d?de.push(()=>n(u)):n(u)}if(i>s){let u=e.slice(s,i);d?ce.push(()=>n(u)):n(u)}if(r>i){let u=e.slice(i,r);d?we.push(()=>n(u)):n(u)}}var ve,Re,de,ce,we,Se,Be=B(()=>{"use strict";ve=0,Re=!1,de=[],ce=[],we=[],Se=[]});function Z(){return Math.trunc(performance.now()*1e6)}function Ve(){return Date.now()*1e6}var Ae=B(()=>{"use strict"});var oe,R,M,D,ee,H,te,$,S,k,_e,lt,qn,ft,Yn,Jn,pt,Qt,en,tn,ht,se=B(()=>{"use strict";oe=Symbol.for("graphrefly/START"),R=Symbol.for("graphrefly/DATA"),M=Symbol.for("graphrefly/DIRTY"),D=Symbol.for("graphrefly/RESOLVED"),ee=Symbol.for("graphrefly/INVALIDATE"),H=Symbol.for("graphrefly/PAUSE"),te=Symbol.for("graphrefly/RESUME"),$=Symbol.for("graphrefly/TEARDOWN"),S=Symbol.for("graphrefly/COMPLETE"),k=Symbol.for("graphrefly/ERROR"),_e=Object.freeze([M]),lt=Object.freeze([D]),qn=Object.freeze([ee]),ft=Object.freeze([oe]),Yn=Object.freeze([S]),Jn=Object.freeze([$]),pt=Object.freeze([_e]),Qt=Object.freeze([lt]),en=Object.freeze([qn]),tn=Object.freeze([Yn]),ht=Object.freeze([Jn])});function nn(n){n.registerMessageType(oe,{tier:0,wireCrossing:!1}),n.registerMessageType(M,{tier:1,wireCrossing:!1}),n.registerMessageType(ee,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(H,{tier:2,wireCrossing:!1}),n.registerMessageType(te,{tier:2,wireCrossing:!1}),n.registerMessageType(R,{tier:3,wireCrossing:!0}),n.registerMessageType(D,{tier:3,wireCrossing:!0}),n.registerMessageType(S,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(k,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType($,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var je,rn=B(()=>{"use strict";se();je=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 mt(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(mt);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=mt(n[t]);return e}return null}function Qn(n){let e=Xn.encode(n),t=e.length,r=t*8,o=t+9+63&-64,s=new Uint8Array(o);s.set(e),s[t]=128;let i=new DataView(s.buffer);i.setUint32(o-4,r>>>0,!1),i.setUint32(o-8,Math.floor(r/4294967296)>>>0,!1);let a=1779033703,d=3144134277,u=1013904242,c=2773480762,f=1359893119,m=2600822924,p=528734635,l=1541459225,g=new Uint32Array(64),h=(y,b)=>y>>>b|y<<32-b;for(let y=0;y<o;y+=64){for(let O=0;O<16;O++)g[O]=i.getUint32(y+O*4,!1);for(let O=16;O<64;O++){let z=g[O-15],F=g[O-2],P=h(z,7)^h(z,18)^z>>>3,be=h(F,17)^h(F,19)^F>>>10;g[O]=g[O-16]+P+g[O-7]+be>>>0}let b=a,v=d,w=u,_=c,x=f,E=m,C=p,A=l;for(let O=0;O<64;O++){let z=h(x,6)^h(x,11)^h(x,25),F=x&E^~x&C,P=A+z+F+Zn[O]+g[O]>>>0,be=h(b,2)^h(b,13)^h(b,22),tt=b&v^b&w^v&w,Ge=be+tt>>>0;A=C,C=E,E=x,x=_+P>>>0,_=w,w=v,v=b,b=P+Ge>>>0}a=a+b>>>0,d=d+v>>>0,u=u+w>>>0,c=c+_>>>0,f=f+x>>>0,m=m+E>>>0,p=p+C>>>0,l=l+A>>>0}let T=y=>y.toString(16).padStart(8,"0");return T(a)+T(d)+T(u)+T(c)+T(f)+T(m)+T(p)+T(l)}function gt(n){let e=mt(n??null),t=JSON.stringify(e);return Qn(t).slice(0,16)}function er(){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 bt(n,e,t){let r=t?.id??er();if(n===0)return{id:r,version:0};let s=(t?.hash??gt)(e);return{id:r,version:0,cid:s,prev:null}}function on(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}var Zn,Xn,sn=B(()=>{"use strict";Zn=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]),Xn=new TextEncoder});function dn(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function yt(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function ze(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}function ne(n,e,t){let r=cn(n)?n:[],o=typeof n=="function"?n:typeof e=="function"?e:void 0,s={};return cn(n)?s=(vt(e)?e:t)??{}:vt(n)?s=n:s=(vt(e)?e:t)??{},new V(r,o,s)}var an,un,tr,nr,Ne,V,cn,vt,ie=B(()=>{"use strict";dt();ct();Be();Ae();rn();Ie();se();sn();an=()=>{},un=100;tr=(n,e,t,r)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},nr=(n,e,t,r)=>{let o=n;if(o._status==="completed"||o._status==="errored")return;let s=o._cached,i=s===void 0?[ft]:[ft,[R,s]];o._status==="dirty"&&i.push(_e),Fe(e,i,o._config.tierOf)},Ne=new je({onMessage:tr,onSubscribe:nr});nn(Ne);Zt(Ne);V=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??Ne,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??gt;let o=r.versioning??this._config.defaultVersioning;this._versioningLevel=o,this._versioning=o!=null?bt(o,this._cached===void 0?void 0:this._cached,{id:r.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(dn);let s={};for(let[a,d]of Object.entries(r.meta??{})){let u={initial:d,name:`${r.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};r.guard!=null&&(u.guard=r.guard),s[a]=new n([],void 0,u)}Object.freeze(s),this.meta=s,this._hasMeta=Object.keys(s).length>0;let i=this;this._actions={emit(a){i._emit([[R,a]])},down(a){i._emit(ze(a))},up(a){i._emitUp(ze(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 o=t?.hash??this._hashFn;o!==this._hashFn&&(this._hashFn=o);let s=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??t?.id,d=i?.version??0,u=bt(e,s,{id:a,hash:o});u.version=d,this._versioning=u,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=Le(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 o=Le(e?.actor),s=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(o,s))throw new J({actor:o,action:s,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(o,s))throw new J({actor:o,action:s,nodeName:this.name})}this._lastMutation={actor:o,timestamp_ns:Ve()}}down(e,t){let r=ze(e);r.length!==0&&(this._checkGuard(t),this._emit(r))}emit(e,t){this._checkGuard(t),this._emit([[R,e]])}up(e,t){if(this._deps.length===0)return;let r=ze(e);if(r.length===0)return;this._checkGuard(t);let o=t??{internal:!0};this._validateUpTiers(r);for(let s of this._deps)s.node.up?.(r,o)}_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 o=t(r[0]);if(o===3||o===4)throw new Error(`Node "${this.name}": tier-${o} 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 d=Le(t);if(!this._guard(d,"observe"))throw new J({actor:d,action:"observe",nodeName:this.name})}let o=this._isTerminal&&this._resubscribable;if(o){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 d of this._deps)yt(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let s;try{s=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:o},this._actions)}catch(d){throw this._sinkCount-=1,d}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(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof s=="function")try{s()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof s=="function"&&s(),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 o=r,s=this._deps[r];s.unsub=an,s.unsub=s.node.subscribe(i=>{if(s.unsub===null)return;let a=this._config.tierOf,d=!1;for(let u of i)a(u[0])>=3&&(d=!0),this._config.onMessage(this,u,{direction:"down-in",depIndex:o},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(r){this._deps[t].unsub=null;for(let o=0;o<t;o++){let s=this._deps[o];if(s.unsub!=null){let i=s.unsub;s.unsub=null;try{i()}catch{}yt(s)}}throw this._dirtyDepCount=0,r}}_addDep(e){for(let o=0;o<this._deps.length;o++)if(this._deps[o].node===e)return o;let t=this._deps.length,r=dn(e);if(this._deps.push(r),this._sinks==null)return t;r.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(pt),r.unsub=an;try{r.unsub=e.subscribe(o=>{if(r.unsub===null)return;let s=this._config.tierOf,i=!1;for(let a of o)s(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(o){throw r.unsub=null,this._deps.pop(),this._dirtyDepCount--,o}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(r){this._emit([[k,this._wrapFnError("cleanup threw",r)]])}else if(t!=null&&typeof t=="object"){let r=t.deactivate;if(typeof r=="function")try{r()}catch(o){this._emit([[k,this._wrapFnError("cleanup.deactivate threw",o)]])}}for(let r of this._deps){if(r.unsub!=null){let o=r.unsub;r.unsub=null;try{o()}catch{}}yt(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],o=t[0];if(this._inspectorHooks!=null){let s={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(s)}if(o!==oe){if(o===M){this._depDirtied(r);return}if(o===ee){if(this._depInvalidated(r),this._cached===void 0)return;this._emit(en);return}if(o===H||o===te){this._emit([t]);return}if(o===$){this._emit(ht);return}if(o===R)this._depSettledAsData(r,t[1]);else if(o===D)this._depSettledAsResolved(r);else if(o===S)this._depSettledAsTerminal(r,!0);else if(o===k)this._depSettledAsTerminal(r,t[1]);else{this._emit([t]);return}if(!this._fn){(o===R||o===D)&&this._emit([t]),(o===S||o===k)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(pt))}_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(Qt),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([[k,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(tn)}_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([[k,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([[k,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 o=this._deps.map(i=>i.terminal),s={prevData:r,terminalDeps:o,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,s);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([[k,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>un?(this._rerunDepth=0,this._emit([[k,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${un} \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"?[_e,e[0]]:e;let r=!0,o=!1,s=!1,i=-1;for(let d of e){let u=t(d[0]);u<i&&(r=!1),u===3&&(o=!0),d[0]===M&&(s=!0),i=u}let a=e;if(!r){let d=e.map((u,c)=>({m:u,i:c,tier:t(u[0])}));d.sort((u,c)=>u.tier-c.tier||u.i-c.i),a=d.map(u=>u.m)}if(o&&!s&&this._status!=="dirty"){let d=0;for(;d<a.length&&t(a[d][0])===0;)d++;return d===0?[_e,...a]:[...a.slice(0,d),_e,...a.slice(d)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let d=e[a];if(d[0]===k&&d[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(d=>d[0]===$||d[0]===ee);if(a.length===0)return;t=a}t=this._frameBatch(t);let o=null;for(let a=0;a<t.length;a++){let d=t[a],u=d[0];if(u!==H&&u!==te){o?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${u===H?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let f=d[1];if(u===H)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(f),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(f))c=!1;else if(this._pauseLocks.delete(f),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let m=this._pauseBuffer;this._pauseBuffer=[],this._emit(m)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?o?.push(d):o==null&&(o=t.slice(0,a))}if(o!=null){if(o.length===0)return;t=o}if(this._hasMeta&&t.some(a=>a[0]===$))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(ht)}catch{}let{finalMessages:s,equalsError:i}=this._updateState(t);if(s.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:s})}catch{}}if(s.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,d=[];for(let u of s)a(u[0])===3?this._pauseBuffer.push(u):d.push(u);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(s);i!=null&&this._emit([[k,i]])}_updateState(e){let t=this._config.tierOf,r,o,s=-1,i=0;for(let c of e)t(c[0])===3&&i++;let a=i<=1,d=-1;if(this._versioning!=null&&i>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===R){d=c;break}}for(let c=0;c<e.length;c++){let f=e[c],m=f[0];if(m===R){if(f.length>=2){let p=!1;if(a&&this._cached!==void 0)try{p=this._equals(this._cached,f[1])}catch(l){o=this._wrapFnError("equals threw",l),s=c;break}if(p){r==null&&(r=e.slice(0,c)),r.push(lt),this._status="resolved";continue}this._cached=f[1],this._versioning!=null&&(d<0||c===d)&&on(this._versioning,f[1],this._hashFn)}this._status="settled",r?.push(f)}else if(r?.push(f),m===M)this._status="dirty";else if(m===D)this._status="resolved";else if(m===S){this._status="completed";{let p=this._config.rigorRecorder;if(p!=null)try{p.onTerminalTransition(this,"completed",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(m===k){this._status="errored";{let p=this._config.rigorRecorder;if(p!=null)try{p.onTerminalTransition(this,"errored",this._autoComplete,this._autoError,this._deps.length>0)}catch{}}}else if(m===ee){if(this._cached!==void 0){let l=this._config.rigorRecorder;if(l!=null)try{l.onNonVacuousInvalidate(this,this._cached)}catch{}}this._cached=void 0,this._status="dirty";let p=this._cleanup;if(typeof p=="function"){this._cleanup=void 0;try{p()}catch{}}else if(p!=null&&typeof p=="object"){let l=p.invalidate;if(typeof l=="function")try{l()}catch{}}}else m===$&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let u=s>=0?r??e.slice(0,s):r??e;return o!=null?{finalMessages:u,equalsError:o}:{finalMessages:u}}_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(Xt()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Te(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}Fe(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);Fe(this._deliverToSinks,t,this._config.tierOf)}},cn=n=>Array.isArray(n),vt=n=>typeof n=="object"&&n!=null&&!Array.isArray(n)});function Tt(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 rr(n){return n._describeKind!=null?n._describeKind:n._deps.length>0?"derived":n._fn!=null?"producer":"state"}function _t(n){let e=new WeakSet,t={};for(let[r,o]of ln(n))t[r]=wt(o,e);return t}function wt(n,e){if(n==null)return n;let t=typeof n;if(t==="boolean"||t==="number"||t==="string")return n;if(t==="function")return"<function>";if(Array.isArray(n))return e.has(n)?"<cycle>":(e.add(n),n.map(r=>wt(r,e)));if(t==="object"){let r=n;if(e.has(r))return"<cycle>";e.add(r);try{if(typeof r.subscribe=="function"&&"cache"in r)return"<Node>"}catch{return"<unserializable>"}let o={};for(let[s,i]of ln(r))o[s]=wt(i,e);return o}return"<unserializable>"}function ln(n){let e=[],t;try{t=Object.keys(n)}catch{return e}for(let r of t)try{e.push([r,n[r]])}catch{e.push([r,"<unserializable>"])}return e}function X(n,e){let t={factory:n};return e!==void 0&&(t.factoryArgs=e),t}function or(n){let e={};for(let[t,r]of Object.entries(n.meta))try{e[t]=r.cache}catch{}return e}function Nt(n,e,t){let r=e==null,o=!r&&e!=null?[...e].filter(c=>c.startsWith("meta.")).map(c=>c.slice(5)):null,s=r||e.has("meta")||o!=null&&o.length>0,i="state",a=[];n instanceof V&&(i=rr(n),a=n._deps.map(c=>c.node.name??""));let d={type:i,deps:a};(r||e.has("status"))&&(d.status=n.status);let u=n instanceof V?n._guard:void 0;if(s){let c={...or(n)};if(u!=null&&c.access===void 0&&(c.access=at(u)),o!=null&&o.length>0&&!e.has("meta")){let f={};for(let m of o)m in c&&(f[m]=c[m]);d.meta=f}else d.meta=c}if(n.name!=null&&(d.name=n.name),(r||e.has("value"))&&(!t||i==="state")){n.status==="sentinel"&&(d.sentinel=!0);try{d.value=n.cache}catch{}}if((r||e.has("v"))&&n.v!=null){let c={id:n.v.id,version:n.v.version};"cid"in n.v&&(c.cid=n.v.cid,c.prev=n.v.prev),d.v=c}return(r||e.has("guard"))&&u!=null&&(d.guard=at(u)),(r||e.has("lastMutation"))&&n.lastMutation!=null&&(d.lastMutation=n.lastMutation),d}var De=B(()=>{"use strict";Ie();ie()});function le(n){return n<0?0:n}function sr(n,e){return e==="none"?n:e==="full"?Math.random()*n:n/2+Math.random()*(n/2)}function ir(n,e){return n+Math.random()*(e-n)}function ar(n){let e=le(n);return()=>e}function ur(n,e){let t=le(n),r=e===void 0?t:le(e);return o=>t+r*Math.max(0,o)}function dr(n){let e=le(n?.baseNs??1e8),t=n?.factor!==void 0&&n.factor<1?1:n?.factor??2,r=le(n?.maxDelayNs??30*1e9),o=n?.jitter??"none";return s=>{let i;if(e===0)i=0;else if(t===1)i=e;else{let a=r/e,d=1;for(let u=0;u<Math.max(0,s);u++){if(d>=a){d=a;break}d*=t}i=e*d,i>r&&(i=r)}return sr(i,o)}}function cr(n=100*1e6,e=30*1e9){let t=le(n),r=le(e);function o(s){if(s<=0)return 1;let i=1,a=2;for(let d=1;d<s;d++){let u=i+a;i=a,a=u}return a}return s=>{let i=o(s)*t;return i<=r?i:r}}function lr(n=100*1e6,e=30*1e9){return(t,r,o)=>{let i=Math.min(e,(o??n)*3);return ir(n,i)}}function fn(n){if(n==="constant")return ar(1*1e9);if(n==="linear")return ur(1*1e9);if(n==="exponential")return dr();if(n==="fibonacci")return cr();if(n==="decorrelatedJitter")return lr();throw new Error(`Unknown backoff preset: "${String(n)}". Use one of: constant, linear, exponential, fibonacci, decorrelatedJitter`)}var re,fe,Ot=B(()=>{"use strict";re=1e6,fe=1e9});function U(n,e,t){return{[n]:!0,[`${n}_type`]:e,...t??{}}}var kt=B(()=>{"use strict"});function Oe(n,e){return ne([],{...e,initial:n})}function K(n,e){return ne((r,o,s)=>n(o,s)??void 0,{describeKind:"producer",...e})}function xt(n,e,t){return ne(n,(o,s,i)=>{let a=o.map((d,u)=>d!=null&&d.length>0?d.at(-1):i.prevData[u]);s.emit(e(a,i))},{describeKind:"derived",...t})}var Ue=B(()=>{"use strict";ie()});function Et(n){return{describeKind:"producer",...n}}function pn(n,e){return K(t=>{let r=!1;try{for(let o of n){if(r)return;t.emit(o)}r||t.down([[S]])}catch(o){r||t.down([[k,o]])}return()=>{r=!0}},Et(e))}function fr(n){return n!=null&&typeof n.then=="function"}function pr(n,e){let{signal:t,...r}=e??{};return K(o=>{let s=!1,i=()=>{s||(s=!0,o.down([[k,t.reason]]))};if(t?.aborted){i();return}return t?.addEventListener("abort",i,{once:!0}),Promise.resolve(n).then(a=>{s||(s=!0,t?.removeEventListener("abort",i),o.emit(a),o.down([[S]]))},a=>{s||(s=!0,t?.removeEventListener("abort",i),o.down([[k,a]]))}),()=>{s=!0,t?.removeEventListener("abort",i)}},Et(r))}function hr(n,e){let{signal:t,...r}=e??{};return K(o=>{let s=new AbortController,i=()=>s.abort(t?.reason);t?.aborted?s.abort(t.reason):t?.addEventListener("abort",i,{once:!0});let a=t??s.signal,d=!1,u=n[Symbol.asyncIterator](),c=()=>{d||a.aborted||Promise.resolve(u.next()).then(f=>{if(!(d||a.aborted)){if(f.done){o.down([[S]]);return}o.emit(f.value),c()}},f=>{!d&&!a.aborted&&o.down([[k,f]])})};return c(),()=>{d=!0,t?.removeEventListener("abort",i),s.abort(),Promise.resolve(u.return?.()).catch(()=>{})}},Et(r))}function mr(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"}function We(n,e){if(mr(n))return n;if(fr(n))return pr(n,e);if(n!=null){let t=n;if(typeof t[Symbol.asyncIterator]=="function")return hr(n,e);if(typeof t[Symbol.iterator]=="function")return pn(n,e)}return gr(n)}function gr(...n){return pn(n,void 0)}function He(n){return n.subscribe(()=>{})}var hn=B(()=>{"use strict";se();Ue()});var Ke=B(()=>{"use strict";hn()});function qe(n,e,t){if(e.length===0)throw new RangeError("budgetGate requires at least one constraint");let r=e.map(p=>p.node),o=[n,...r],s=new Rt,i=!1,a=!1,d=Symbol("budget-gate"),u=new Array(e.length);function c(){return e.every((p,l)=>p.check(u[l]))}function f(p){for(;s.size>0&&c();){let l=s.shift();p.emit(l)}s.size===0&&a&&(a=!1,p.down([[D]]))}return ne([],(p,l)=>{for(let h=0;h<e.length;h++)u[h]=e[h].node.cache;let g=[];for(let h=0;h<o.length;h++){let T=o[h];g.push(T.subscribe(y=>{for(let b of y)m(b,h,l)}))}return()=>{for(let h of g)h()}},{...t,describeKind:"derived",meta:U("resilience","budget_gate",t?.meta)});function m(p,l,g){let h=p[0];if(l===0){if(h===R)return c()&&s.size===0?g.emit(p[1]):(s.push(p[1]),i||(i=!0,g.up([[H,d]]))),!0;if(h===M)return g.down([[M]]),!0;if(h===D)return s.size===0?g.down([[D]]):a=!0,!0;if(h===S||h===k){for(;s.size>0;)g.emit(s.shift());return a=!1,i&&(i=!1,g.up([[te,d]])),g.down([p]),!0}return!1}if(h===R&&(u[l-1]=p[1]),h===R||h===D){let T=c();return T&&s.size>0?(f(g),s.size===0&&i&&(i=!1,g.up([[te,d]]))):!T&&!i&&s.size>0&&(i=!0,g.up([[H,d]])),!0}return h===M?!0:h===k?(g.down([p]),!0):h===S}}var Rt,mn=B(()=>{"use strict";se();ie();kt();Rt=class{buf=[];head=0;get size(){return this.buf.length-this.head}push(e){this.buf.push(e)}shift(){if(this.head>=this.buf.length)return;let e=this.buf[this.head];return this.buf[this.head]=void 0,this.head++,this.head>32&&this.head*2>this.buf.length&&(this.buf=this.buf.slice(this.head),this.head=0),e}clear(){this.buf=[],this.head=0}}});var ae,St=B(()=>{"use strict";ae=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 pe,Ct=B(()=>{"use strict";pe=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 he(n){return{describeKind:"derived",...n}}function vr(n){return n<0?0:n}function Gt(n){return n[1]}function wr(n){if(typeof n!="number"||!Number.isFinite(n))throw new TypeError("backoff strategy must return a finite number");return n<0?0:n}function gn(n){let e=n?.count,t=n?.backoff;if(t!==void 0&&e===void 0)throw new RangeError("retry({ backoff }) requires explicit count to prevent unbounded retries; pass { count: <n>, backoff: ... }");let r=e!==void 0?e:0;if(r<0)throw new RangeError("retry count must be >= 0");let o=t===void 0?null:typeof t=="string"?fn(t):t;return{maxRetries:r,strategy:o}}function bn(n){let e={};return n?.count!==void 0&&(e.count=n.count),typeof n?.backoff=="string"&&(e.backoff=n.backoff),Object.keys(e).length>0?e:void 0}function yn(n,e,t){let r=0,o=!1,s=null,i,a=new ae;function d(){i?.(),i=void 0}function u(f){if(o)return;if(r>=n.maxRetries){d(),t.down([[k,f]]);return}let m=n.strategy===null?0:n.strategy(r,f,s);if(m==null){d(),t.down([[k,f]]);return}let p;try{p=wr(m)}catch{d(),t.down([[k,f]]);return}s=p,r+=1,d();let l=p>0?p/1e6:1;a.start(l,()=>{o||c()})}function c(){a.cancel(),d();let f;try{f=e()}catch(m){u(m);return}i=f.subscribe(m=>{if(!o)for(let p of m){let l=p[0];if(l===M)t.down([[M]]);else if(l===R)r=0,s=null,t.emit(p[1]);else if(l===D)t.down([[D]]);else if(l===S)d(),t.down([[S]]);else if(l===k){u(Gt(p));return}else t.down([p])}})}return c(),()=>{o=!0,a.cancel(),d()}}function Pt(n,e){return typeof n=="function"?_r(n,e):Tr(n,e)}function Tr(n,e){let t=gn(e);return K(r=>yn(t,()=>n,r),{...he(),initial:n.cache,meta:{...e?.meta??{},...X("retry",bn(e))}})}function _r(n,e){let t=gn(e);return K(r=>yn(t,n,r),{...he(),initial:e?.initial,meta:{...e?.meta??{},...X("retry",bn(e))}})}function It(n){let e=Math.max(1,n?.failureThreshold??5),t=vr(n?.cooldownNs??30*1e9),r=n?.cooldown??null,o=Math.max(1,n?.halfOpenMax??1),s=n?.now??Z,i="closed",a=0,d=0,u=0,c=t,f=0;function m(){if(!r)return t;let g=r(d);return g!==null?g:t}function p(){i="open",c=m(),u=s(),f=0}return{canExecute(){return i==="closed"?!0:i==="open"?s()-u>=c?(i="half-open",f=1,!0):!1:f<o?(f++,!0):!1},recordSuccess(){i==="half-open"?(i="closed",a=0,d=0):i==="closed"&&(a=0)},recordFailure(g){if(i==="half-open"){d++,p();return}i==="closed"&&(a++,a>=e&&p())},get state(){return i},get failureCount(){return a},reset(){i="closed",a=0,d=0,f=0}}}function Lt(n,e){let t=e?.onOpen??"skip",r=e?.meta;return o=>{let s=ne([],(i,a)=>{function d(){s.meta.breakerState.down([[R,n.state]])}let u=o.subscribe(c=>{for(let f of c){let m=f[0];m===M?a.down([[M]]):m===R?n.canExecute()?(d(),a.emit(f[1])):(d(),t==="error"?a.down([[k,new At]]):a.down([[D]])):m===D?a.down([[D]]):m===S?(n.recordSuccess(),d(),a.down([[S]])):m===k?(n.recordFailure(Gt(f)),d(),a.down([f])):a.down([f])}});return d(),u},{...he(),meta:{...r??{},breakerState:n.state,...X("withBreaker",{onOpen:t})},completeWhenDepsComplete:!1,initial:o.cache});return{node:s,breakerState:s.meta.breakerState}}}function Nr(n,e,t){if(n<=0)throw new RangeError("capacity must be > 0");if(e<0)throw new RangeError("refillPerSecond must be >= 0");let r=t?.clock??Z,o=n,s=r();function i(a){if(e>0){let d=a-s;o=Math.min(n,o+d/1e9*e)}s=a}return{available(){return i(r()),o},tryConsume(a=1){if(a<=0)return!0;let d=r();return i(d),o>=a?(o-=a,!0):!1},putBack(a=1){a<=0||(i(r()),o=Math.min(n,o+a))}}}function Or(n,e){return n.droppedCount===e.droppedCount&&n.pendingCount===e.pendingCount&&n.paused===e.paused}function $t(n,e){let{maxEvents:t,windowNs:r}=e;if(t<=0)throw new RangeError("maxEvents must be > 0");if(r<=0)throw new RangeError("windowNs must be > 0");let o=e.maxBuffer;if(o===void 0)throw new RangeError("rateLimiter requires explicit maxBuffer (use Infinity to opt in to unbounded)");let s=o===1/0;if(!s&&(!Number.isInteger(o)||o<1))throw new RangeError("maxBuffer must be a positive integer (or Infinity for unbounded)");let i=e.onOverflow??"drop-newest",a=t*1e9/r,d=K(u=>{let c=Nr(t,a),f=s?xr():kr(o),m=new ae,p=!1,l=0,g=1e9/a,h=d.meta.droppedCount,T=d.meta.rateLimitState,y=Ye;function b(){h.emit(l);let E={droppedCount:l,pendingCount:f.size,paused:f.size>0};Or(y,E)||(y=E,T.emit(E))}y=Ye,h.emit(0),T.emit(Ye);function v(){for(;f.size>0;)if(c.tryConsume(1))u.emit(f.shift()),b();else{m.start(Math.max(1,g/1e6),v);return}}function w(){l+=1,b()}function _(){for(p=!0,m.cancel();f.size>0;)f.shift();l=0}let x=n.subscribe(E=>{for(let C of E){if(p)return;let A=C[0];if(A===M)u.down([[M]]);else if(A===R){if(!s&&f.size>=o)if(i==="drop-newest")w();else if(i==="drop-oldest")f.shift(),f.push(C[1]),w();else{w(),_(),u.down([[k,new Dt(o)]]);return}else f.push(C[1]),b();v()}else if(A===D)u.down([[D]]);else if(A===S)_(),u.down([[S]]);else if(A===k)_(),u.down([C]);else if(A===$){_(),u.down([C]);return}else u.down([C])}});return()=>{p=!0,m.cancel(),x()}},{...he(),initial:n.cache,meta:{...e.meta??{},droppedCount:0,rateLimitState:Ye,...X("rateLimiter",e)}});return{node:d,droppedCount:d.meta.droppedCount,rateLimitState:d.meta.rateLimitState}}function kr(n){let e=new pe(n);return{push:t=>e.push(t),shift:()=>e.shift(),get size(){return e.size}}}function xr(){let n=[];return{push:e=>{n.push(e)},shift:()=>n.shift(),get size(){return n.length}}}function vn(n,e){let t=e?.initialStatus??"pending",r=e?.meta,o=ne([],(s,i)=>{let a=t;return o.meta.status.down([[R,t]]),o.meta.error.down([[R,null]]),n.subscribe(u=>{for(let c of u){let f=c[0];if(f===M)i.down([[M]]);else if(f===R)a==="errored"?Ce(()=>{o.meta.error.down([[R,null]]),o.meta.status.down([[R,"running"]])}):o.meta.status.down([[R,"running"]]),a="running",i.emit(c[1]);else if(f===D)i.down([[D]]);else if(f===S)o.meta.status.down([[R,"completed"]]),a="completed",i.down([[S]]);else if(f===k){let m=Gt(c);Ce(()=>{o.meta.error.down([[R,m]]),o.meta.status.down([[R,"errored"]])}),a="errored",i.down([c])}else i.down([c])}})},{...he(),meta:{...r??{},status:t,error:null,...X("withStatus",{initialStatus:t})},completeWhenDepsComplete:!1,resubscribable:!0,initial:n.cache});return{node:o,status:o.meta.status,error:o.meta.error}}function Er(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"}function Rr(n){return n!=null&&typeof n.then=="function"}function Sr(n){return n!=null&&typeof n=="object"&&typeof n[Symbol.asyncIterator]=="function"}function wn(n,e,t){let r=t?.meta;return K(o=>{let s,i;function a(){i?.(),i=void 0,Er(e)||Rr(e)||Sr(e)?s=We(e).subscribe(u=>{o.down(u);for(let c of u){let f=c[0];if(f===S||f===k||f===$){s=void 0;return}}}):(o.emit(e),o.down([[S]]))}return i=n.subscribe(d=>{for(let u of d){let c=u[0];if(c===M)o.down([[M]]);else if(c===R)o.emit(u[1]);else if(c===D)o.down([[D]]);else if(c===S)o.down([[S]]);else if(c===k){a();return}else if(c===$){s?.(),o.down([u]);return}else o.down([u])}}),()=>{i?.(),s?.()}},{...he(),initial:n.cache,meta:{...r??{},...X("fallback")}})}function Ft(n,e,t){if(e<=0)throw new RangeError("timeoutNs must be > 0");let r=t?.meta;return K(o=>{let s=!1,i=new ae;function a(){let u=e/1e6;i.start(u,()=>{s||(s=!0,d(),o.down([[k,new Mt(e)]]))})}let d=n.subscribe(u=>{for(let c of u){if(s)return;let f=c[0];if(f===M)o.down([[M]]);else if(f===R)a(),o.emit(c[1]);else if(f===D)o.down([[D]]);else if(f===S){i.cancel(),s=!0,o.down([[S]]);return}else if(f===k){i.cancel(),s=!0,o.down([c]);return}else if(f===$){i.cancel(),s=!0,o.down([c]);return}else o.down([c])}});return a(),()=>{s=!0,i.cancel(),d()}},{...he(),initial:n.cache,meta:{...r??{},...X("timeout",{timeoutNs:e})}})}var At,Dt,Ye,Mt,Tn=B(()=>{"use strict";mn();Be();Ae();se();De();ie();Ue();Ot();Ke();St();Ct();At=class extends Error{name="CircuitOpenError";constructor(){super("Circuit breaker is open")}};Dt=class extends Error{name="RateLimiterOverflowError";constructor(e){super(`rateLimiter buffer overflow (maxBuffer=${e})`)}};Ye=Object.freeze({droppedCount:0,pendingCount:0,paused:!1});Mt=class extends Error{name="TimeoutError";constructor(e){super(`Timed out after ${e/1e6}ms`)}}});var _n=B(()=>{"use strict";Tn()});var qr={};jn(qr,{NS_PER_MS:()=>re,NS_PER_SEC:()=>fe,ResilientPipelineGraph:()=>et,factoryTag:()=>X,placeholderArgs:()=>_t,resilientPipeline:()=>Kr});module.exports=Un(qr);De();Ot();kt();se();De();ie();Ke();function br(n){return{describeKind:"derived",...n}}function yr(n,e,t){let r,o=!1,s=()=>{o||(o=!0,t())};return r=n.subscribe(i=>{let a=!1,d=!1;for(let u of i)u[0]!==oe&&(u[0]===R?e.emit(u[1]):u[0]===S?a=!0:u[0]===k?(d=!0,e.down([u])):(u[0]===M||u[0]===D)&&e.down([u]));d?(r?.(),r=void 0,s()):a&&s()}),()=>{r?.(),r=void 0}}function ke(n,e,t){let r,o=!1;function s(){r?.(),r=void 0}return ne([n],(i,a,d)=>{if(d.terminalDeps[0]!=null&&d.terminalDeps[0]!==!0){s();return}if(d.terminalDeps[0]===!0){o=!0,r||a.down([[S]]);return}let u=i[0];if(!(u==null||u.length===0))return s(),r=yr(We(e(u[u.length-1])),a,()=>{s(),o&&a.down([[S]])}),{deactivate:()=>{s(),o=!1}}},{...br(t),completeWhenDepsComplete:!1,meta:{...X("switchMap"),...t?.meta??{}}})}_n();var j={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},Cr=Symbol.for("sizeof");function Nn(n){let e=new WeakSet,t=new WeakSet,r=[n],o=0;for(;r.length>0;){let s=r.pop();o+=Ar(s,e,t,r)}return o}function Ar(n,e,t,r){if(n==null)return 0;switch(typeof n){case"number":return j.number;case"boolean":return j.boolean;case"string":return j.string+n.length*2;case"bigint":return j.bigint+Dr(n);case"symbol":return j.symbol;case"function":return e.has(n)?0:(e.add(n),j.function);case"undefined":return 0}let s=n;if(e.has(s))return 0;e.add(s);let i=s[Cr];if(typeof i=="function")try{let u=i.call(s);if(typeof u=="number"&&Number.isFinite(u))return u}catch{}if(s instanceof Date)return j.date;if(s instanceof RegExp)return j.regexp+s.source.length*2;if(s instanceof Error){let u=s.message?s.message.length*2:0,c=s.stack?s.stack.length*2:0;return j.error+u+c}if(typeof URL<"u"&&s instanceof URL)return j.url+s.href.length*2;if(typeof Promise<"u"&&s instanceof Promise)return j.promise;if(s instanceof WeakMap)return j.weakmap;if(s instanceof WeakSet)return j.weakset;if(s instanceof Map){let u=j.map;for(let[c,f]of s)u+=j.mapEntry,r.push(c),r.push(f);return u}if(s instanceof Set){let u=j.set;for(let c of s)u+=j.setEntry,r.push(c);return u}if(Array.isArray(s)){let u=j.array+s.length*8;for(let c of s)r.push(c);return u}if(s instanceof ArrayBuffer)return t.has(s)?0:(t.add(s),s.byteLength);if(ArrayBuffer.isView(s)){let u=s;return t.has(u.buffer)?48:(t.add(u.buffer),u.buffer.byteLength+48)}let a=j.object,d=Object.keys(s);for(let u of d){a+=j.string+u.length*2;try{r.push(s[u])}catch{}}return a}function Dr(n){let e=n<0n?-n:n;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}function On(n,e,t,r={}){let o=e in n.nodes,s=t in n.nodes;if(!o)return Je(e,t,"no-such-from");if(!s)return Je(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 u=Mr(n,e,r);if(u!=null)return u}let d=Ze(e,n.nodes[e],0,r);return Xe(e,t,[d])}if(i===0)return Je(e,t,"no-path");let a=kn(n,e,t,i);return a.found?Xe(e,t,xn(n,a.pathOrder,r)):Je(e,t,a.truncated?"max-depth-exceeded":"no-path")}function kn(n,e,t,r){let o=new Map,s=[{path:t,depth:0}],i=new Set([t]),a=0,d=!1;for(;a<s.length;){let f=s[a++];if(f.path===e)break;if(r!=null&&f.depth>=r){let g=n.nodes[f.path];g?.deps&&g.deps.length>0&&(d=!0);continue}let m=n.nodes[f.path];if(m==null)continue;let p=m.deps??[],l=new Map;for(let g=0;g<p.length;g++){let h=p[g];if(!h)continue;let T=l.get(h);T==null&&(T=[],l.set(h,T)),T.push(g)}for(let[g,h]of l)i.has(g)||(i.add(g),o.set(g,{from:f.path,depIndices:h}),s.push({path:g,depth:f.depth+1}))}if(!o.has(e))return{found:!1,pathOrder:[],truncated:d};let u=[{path:e}],c=e;for(;c!==t;){let f=o.get(c);if(f==null)return{found:!1,pathOrder:[],truncated:!1};u[u.length-1].depIndices=f.depIndices,u.push({path:f.from}),c=f.from}return{found:!0,pathOrder:u,truncated:!1}}function Mr(n,e,t){let r=n.nodes[e];if(r==null)return null;let o=r.deps??[],s=[];for(let a=0;a<o.length;a++)o[a]===e&&s.push(a);if(s.length>0){let a=Ze(e,r,0,t);a.dep_index=s[0];let d=Ze(e,r,1,t);return Xe(e,e,[a,d])}let i=null;for(let a=0;a<o.length;a++){let d=o[a];if(!d||d===e)continue;let u=kn(n,d,e,t.maxDepth);u.found&&(i==null||u.pathOrder.length<i.pathOrder.length)&&(i=u,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...u.pathOrder],truncated:!1})}return i==null?null:Xe(e,e,xn(n,i.pathOrder,t))}function xn(n,e,t){return e.map((r,o)=>{let s=n.nodes[r.path],i=Ze(r.path,s,o,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 Ze(n,e,t,r){let o={path:n,type:e.type,hop:t};e.status!==void 0&&(o.status=e.status),"value"in e&&(o.value=e.value),e.v!=null&&(o.v=e.v);let s=r.annotations?.get(n)??e.annotation;s!=null&&(o.annotation=s);let i=r.lastMutations?.get(n)??e.lastMutation;return i!=null&&(o.lastMutation=i),o}function Xe(n,e,t){return En(n,e,!0,"ok",t)}function Je(n,e,t){return En(n,e,!1,t,[])}function En(n,e,t,r,o){let s=Gr(n,e,t,r,o);return{from:n,to:e,found:t,reason:r,steps:o,text:s,toJSON(){return{from:n,to:e,found:t,reason:r,steps:o}}}}function Gr(n,e,t,r,o){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 s=[`Causal path: ${n} \u2192 ${e} (${o.length} step(s))`];for(let i of o){let d=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(s.push(d),"value"in i&&s.push(` value: ${Pr(i.value)}`),i.annotation!=null&&s.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let u=i.lastMutation.actor;s.push(` actor: ${u.type}${u.id?`:${u.id}`:""}`)}}return s.join(`
|
|
2
|
-
`)}function Pr(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)}}ct();Be();Ae();Ie();se();De();ie();Ue();Ae();function Bt(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 s=0;s<n.length;s++)if(!Bt(n[s],e[s]))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 o=new Set(r);for(let s of t)if(!o.has(s)||!Bt(n[s],e[s]))return!1;return!0}function Rn(n,e){return`${n}\0${e}`}function Vt(n,e){let t=[],r=new Set(n.subgraphs),o=new Set(e.subgraphs),s=[];for(let h of o)r.has(h)||s.push(h);s.sort();for(let h of s)t.push({type:"subgraph-mounted",path:h});let i=new Set(Object.keys(n.nodes)),a=new Set(Object.keys(e.nodes)),d=[];for(let h of a)i.has(h)||d.push(h);d.sort();for(let h of d)t.push({type:"node-added",path:h,node:{...e.nodes[h]}});let u=[];for(let h of a){if(!i.has(h))continue;let T=n.nodes[h]?.meta,y=e.nodes[h]?.meta;T==null&&y==null||Bt(T??{},y??{})||u.push(h)}u.sort();for(let h of u)t.push({type:"node-meta-changed",path:h,prevMeta:n.nodes[h]?.meta??{},nextMeta:e.nodes[h]?.meta??{}});let c=new Map;for(let h of n.edges)c.set(Rn(h.from,h.to),h);let f=new Map;for(let h of e.edges)f.set(Rn(h.from,h.to),h);let m=[];for(let[h,T]of f)c.has(h)||m.push(T);m.sort((h,T)=>h.from<T.from?-1:h.from>T.from?1:h.to<T.to?-1:h.to>T.to?1:0);for(let h of m)t.push({type:"edge-added",from:h.from,to:h.to});let p=[];for(let[h,T]of c)f.has(h)||p.push(T);p.sort((h,T)=>h.from<T.from?-1:h.from>T.from?1:h.to<T.to?-1:h.to>T.to?1:0);for(let h of p)t.push({type:"edge-removed",from:h.from,to:h.to});let l=[];for(let h of i)a.has(h)||l.push(h);l.sort();for(let h of l)t.push({type:"node-removed",path:h});let g=[];for(let h of r)o.has(h)||g.push(h);g.sort();for(let h of g)t.push({type:"subgraph-unmounted",path:h});return{events:t,flushedAt_ns:Z()}}Ke();St();Ct();dt();ie();function Sn(n,e){let t=e?.topN??10,r=n.describe({detail:"standard"}),o=[],s=n._collectObserveTargets;typeof s=="function"&&s.call(n,"",o);let i=new Map;for(let[m,p]of o)i.set(m,p);let a=[];for(let[m,p]of Object.entries(r.nodes)){let l=i.get(m),g=l instanceof V?l:null,h=g?Nn(g.cache):0,T=g?g._sinkCount:0,y=p.deps?.length??0,b=p.type==="effect"&&T===0,v=T===0?p.type==="effect"?"orphan-effect":p.type==="derived"?"idle-derived":p.type==="producer"?"idle-producer":null:null;a.push({path:m,type:p.type,status:p.status??"unknown",valueSizeBytes:h,subscriberCount:T,depCount:y,isOrphanEffect:b,orphanKind:v})}let d=a.reduce((m,p)=>m+p.valueSizeBytes,0),u=(m,p)=>[...a].sort(p??((l,g)=>g[m]-l[m])).slice(0,t),c=a.filter(m=>m.orphanKind!=null),f=a.filter(m=>m.isOrphanEffect);return{nodeCount:a.length,edgeCount:r.edges.length,subgraphCount:r.subgraphs.length,nodes:a,totalValueSizeBytes:d,hotspots:{byValueSize:u("valueSizeBytes"),bySubscriberCount:u("subscriberCount"),byDepCount:u("depCount")},orphans:c,orphanEffects:f}}var L="::",Q="__meta__",me=1;function Cn(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 o=n.values().next();if(o.done)return;let s=o.value;n.delete(s);try{s()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function Pn(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"&&typeof n.down=="function"}function Ir(n){if(n!=null)return Pn(n)?n.cache:n}function ge(n){return n!=null&&typeof n=="object"&&"cache"in n&&typeof n.subscribe=="function"&&typeof n.down=="function"}function ue(n){return ge(n)?n.cache??"":n}function An(n){return ge(n)?n.cache??0:n}function Dn(n){return ge(n)?n.cache??!1:n}function Lr(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 Mn(n){if(n.version!==me)throw new Error(`unsupported snapshot version ${String(n.version)} (expected ${me})`);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 $r(n,e){let t=new WeakMap,r=(o,s)=>{if(Object.is(o,s))return!0;if(o==null||s==null||typeof o!="object"||typeof s!="object")return!1;let i=t.get(o);if(i==null&&(i=new WeakSet,t.set(o,i)),i.has(s))return!0;i.add(s);let a=o.constructor,d=s.constructor;if(a!==d)return!1;if(o instanceof Date)return o.getTime()===s.getTime();if(o instanceof RegExp)return o.source===s.source&&o.flags===s.flags;if(Array.isArray(o)){let m=s;if(o.length!==m.length)return!1;for(let p=0;p<o.length;p++)if(!r(o[p],m[p]))return!1;return!0}if(o instanceof Map){let m=s;if(o.size!==m.size)return!1;for(let[p,l]of o)if(!m.has(p)||!r(l,m.get(p)))return!1;return!0}if(o instanceof Set){let m=s;if(o.size!==m.size)return!1;for(let p of o){let l=!1;for(let g of m)if(r(p,g)){l=!0;break}if(!l)return!1}return!0}if(ArrayBuffer.isView(o)){let m=o,p=s;if(m.length!==p.length)return!1;for(let l=0;l<m.length;l++)if(m[l]!==p[l])return!1;return!0}let u=Object.keys(o),c=Object.keys(s);if(u.length!==c.length)return!1;let f=new Set(c);for(let m of u)if(!f.has(m)||!r(o[m],s[m]))return!1;return!0};return r(n,e)}function Fr(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qe(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 o=n.indexOf("]",t+1);if(o<=t+1){e+="\\[";continue}let s=n.slice(t+1,o);s.startsWith("!")&&(s=`^${s.slice(1)}`),s=s.replace(/\\/g,"\\\\"),e+=`[${s}]`,t=o;continue}e+=Fr(r)}return e+="$",new RegExp(e)}var Br={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"},Vr={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function jt(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 jr(n){return n==="none"?Vr:n==="ansi"||n==null?Br:{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 Gn(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 zr(n,e,t){for(let r=0;r<n.length;r++){let o=n.charCodeAt(r);if(o<32||o===127)throw new Error(`Graph "${e}": ${t} "${n}" must not contain control character (U+${o.toString(16).padStart(4,"0").toUpperCase()} at index ${r})`)}}function zt(n,e,t){if(n==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(n.includes(L))throw new Error(`Graph "${e}": ${t} "${n}" must not contain '${L}' (path separator)`);if(n===Q)throw new Error(`Graph "${e}": ${t} name "${Q}" is reserved for meta companion paths`);zr(n,e,t)}function Ur(n,e){if(n==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=n.split(L);for(let r of t)if(r==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function Wr(n,e){let t=!1;for(let o of n)if(!e.isMetaPassthrough(o[0])){t=!0;break}return t?n.filter(o=>e.isMetaPassthrough(o[0])):n}function In(n){for(let e of n._mounts.values())In(e);for(let e of n._nodes.values())try{e.down([[$]],{internal:!0})}catch{}}var xe=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(L))throw new Error(`Graph name must not contain '${L}' (got "${e}")`);if(e===Q)throw new Error(`Graph name "${Q}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??Ne,this._traceRing=new pe(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=K(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,o=t?.name??r;if(o==null||o==="")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 s=o,i=t?.annotation;if(zt(s,this.name,"add"),this._mounts.has(s))throw new Error(`Graph "${this.name}": name "${s}" is already a mount point`);if(this._nodes.has(s))throw new Error(`Graph "${this.name}": node "${s}" 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(s,e),this._nodeToName.set(e,s),this._emitTopology({kind:"added",name:s,nodeKind:"node"}),i!=null&&(this._annotations.set(s,i),this.config.inspectorEnabled&&this._traceRing.push({path:s,annotation:i,timestamp_ns:Z()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof V&&t._applyVersioning(e)}remove(e){zt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let s={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,d]of i)a.includes(`${L}${Q}${L}`)||s.nodes.push(a);return s.nodes.sort(),s.mounts.push(e),s.mounts.push(...t._collectSubgraphs(`${e}${L}`)),this._mounts.delete(e),t._parent=void 0,In(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:s}),s}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([[$]],{internal:!0});let o={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:o}),o}removeAll(e){let t=typeof e=="function"?e:(()=>{let s=Qe(e);return i=>s.test(i)})(),r={kind:"mount",nodes:[],mounts:[]},o=[...this._nodes.keys(),...this._mounts.keys()].filter(s=>t(s));for(let s of o){let i=this.remove(s);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 o=e[r++];return{value:[o,t.get(o)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(L))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 o=r?.internal===!0;this.node(e).down([[R,t]],{actor:r?.actor,internal:o,delivery:"write"})}setAll(e,t){let r=Symbol.iterator in e?e:Object.entries(e);Ce(()=>{for(let[o,s]of r)this.set(o,s,t)})}invalidate(e,t){let r=t?.internal===!0;this.node(e).down([[ee]],{actor:t?.actor,internal:r,delivery:"write"})}error(e,t,r){let o=r?.internal===!0;this.node(e).down([[k,t]],{actor:r?.actor,internal:o,delivery:"write"})}complete(e,t){let r=t?.internal===!0;this.node(e).down([[S]],{actor:t?.actor,internal:r,delivery:"write"})}edges(e){let t=e?.recursive===!0,r=new Map;if(!t){for(let[d,u]of this._nodes)r.set(u,d);let a=[];for(let[d,u]of this._nodes)if(u instanceof V)for(let c of u._deps){let f=r.get(c.node);f!=null&&a.push([f,d])}return a.sort((d,u)=>d[0]<u[0]?-1:d[0]>u[0]?1:d[1]<u[1]?-1:d[1]>u[1]?1:0),a}let o=[];this._collectObserveTargets("",o);let s=new Map;for(let[a,d]of o)s.set(d,a);let i=[];for(let[a,d]of o)if(d instanceof V)for(let u of d._deps){let c=s.get(u.node);c!=null&&i.push([c,a])}return i.sort((a,d)=>a[0]<d[0]?-1:a[0]>d[0]?1:a[1]<d[1]?-1:a[1]>d[1]?1:0),i}mount(e,t){if(t===void 0){let o=new n(e);return this.mount(e,o)}if(typeof t=="function"){let o=new n(e);return t(o),this.mount(e,o)}let r=t;if(zt(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 o=this;o!=null;o=o._parent)if(o===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=Ur(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],o=t.slice(1);if(o.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 s=this._nodes.get(r);if(s&&o.length>0&&o[0]===Q)return this._resolveMetaChainFromNode(s,o,t.join(L));let i=this._mounts.get(r);if(!i)throw this._nodes.has(r)?new Error(`Graph "${this.name}": "${r}" is a node; trailing path "${o.join(L)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${r}"`);return i.resolve(o.join(L))}_resolveMetaChainFromNode(e,t,r){let o=e,s=0,i=[...t];for(;s<i.length;){if(i[s]!==Q)throw new Error(`Graph "${this.name}": expected ${Q} segment in meta path "${r}"`);if(s+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${Q} in "${r}"`);let a=i[s+1],d=o.meta[a];if(!d)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${r}"`);o=d,s+=2}return o}signal(e,t){if(t?.internal!==!0){for(let o of e)if(this.config.messageTier(o[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,o){for(let d of this._mounts.values())d._signalDeliver(e,t,r,o);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=Wr(e,this.config);for(let d of[...this._nodes.keys()].sort()){let u=this._nodes.get(d);if(!r.has(u)){r.add(u);try{u.down(e,i)}catch(c){if(c instanceof J)throw c;o.push(c)}a.length!==0&&this._signalMetaSubtree(u,a,r,i,o)}}}_signalMetaSubtree(e,t,r,o,s){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,o)}catch(d){if(d instanceof J)throw d;s.push(d)}this._signalMetaSubtree(a,t,r,o,s)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=Ir(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 o=Tt(e?.detail,e?.fields),s=e?.detail==="spec",i=o,a=[];this._collectObserveTargets("",a);let d=new Map;for(let[v,w]of a)d.set(w,v);let u=[];{let v=a.map(([,x])=>x),w=new Set(d.values()),_=0;for(;v.length>0;){let x=v.shift();if(x instanceof V)for(let E of x._deps){let C=E.node;if(d.has(C))continue;let A=C.name??"",O=A;if(!O||w.has(O))if(A){let z=2;for(;w.has(`${A}#${z}`);)z++;O=`${A}#${z}`}else for(O=`__internal__/${_++}`;w.has(O);)O=`__internal__/${_++}`;d.set(C,O),w.add(O),u.push([O,C]),v.push(C)}}}let c=[...a,...u],f={};for(let[v,w]of c){if(t!=null&&!w.allowsObserve(t))continue;let _=Nt(w,i,s),x=w instanceof V?w._deps.map(O=>d.get(O.node)??O.node.name??""):[],{name:E,...C}=_,A={...C,deps:x};if(!s){let O=this._annotations.get(v);O!=null&&(A.annotation=O)}if(r!=null)if(typeof r=="function"){let O=r;if(!(O.length>=2?O(v,A):O(A)))continue}else{let O=!0;for(let[z,F]of Object.entries(r)){let P=z==="deps_includes"?"depsIncludes":z==="meta_has"?"metaHas":z;if(P==="depsIncludes"){if(!A.deps.includes(String(F))){O=!1;break}continue}if(P==="metaHas"){if(!Object.hasOwn(A.meta??{},String(F))){O=!1;break}continue}if(A[P]!==F){O=!1;break}}if(!O)continue}f[v]=A}let m=new Set(Object.keys(f)),p=[];for(let[v,w]of c)if(w instanceof V)for(let _ of w._deps){let x=d.get(_.node);x!=null&&p.push([x,v])}p.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 l=p.map(([v,w])=>({from:v,to:w}));(t!=null||r!=null)&&(l=l.filter(v=>m.has(v.from)&&m.has(v.to)));let g=this._collectSubgraphs(""),h=t!=null||r!=null?g.filter(v=>{let w=`${v}${L}`;return[...m].some(_=>_===v||_.startsWith(w))}):g,T=this,y=e;return{name:this.name,nodes:f,edges:l,subgraphs:h,...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),T.describe(w)}}}_collectSubgraphs(e){let t=[];for(let r of[...this._mounts.keys()].sort()){let o=e===""?r:`${e}${r}`;t.push(o),t.push(...this._mounts.get(r)._collectSubgraphs(`${o}${L}`))}return t}resourceProfile(e){return Sn(this,e)}reachable(e,t,r={}){return r.withDetail===!0?Ut(this.describe(),e,t,{...r,withDetail:!0}):Ut(this.describe(),e,t,r)}explain(e,t,r){return r?.reactive===!0?this._explainReactive(e,t,r):this._explainStatic(ue(e),ue(t),{...r?.maxDepth!==void 0?{maxDepth:An(r.maxDepth)}:{},...r?.findCycle!==void 0?{findCycle:Dn(r.findCycle)}:{}})}_explainStatic(e,t,r){let o=this.describe({detail:"full"}),s=new Map(this._annotations),i=new Map;for(let[a,d]of Object.entries(o.nodes))d.lastMutation!=null&&i.set(a,d.lastMutation);return On(o,e,t,{...r?.maxDepth!=null?{maxDepth:r.maxDepth}:{},...r?.findCycle===!0?{findCycle:!0}:{},annotations:s,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},r=e.reactiveName??"describe",o=0,s=Oe(o,{name:`${r}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=()=>{a||d||(a=!0,Te(()=>{a=!1,!d&&(o+=1,s.emit(o))}))},c=i.onEvent(y=>{let b=y.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||u()}),f=[],m=new WeakSet,p=y=>{if(m.has(y)||d)return;m.add(y);let b=y.topology.subscribe(v=>{for(let w of v){if(w[0]!==R)continue;let _=w[1];if(u(),_.kind==="added"&&_.nodeKind==="mount"){let x=y._mounts.get(_.name);x!=null&&p(x)}}});f.push(b);for(let v of y._mounts.keys()){let w=y._mounts.get(v);w!=null&&p(w)}};p(this);let l,g=e.actor;Pn(g)&&(l=g.subscribe(y=>{let b=!1,v=!1;for(let w of y){let _=w[0];_===R?b=!0:(_===S||_===k||_===$)&&(v=!0)}b&&u(),v&&(l?.(),l=void 0,u())}));let h;try{h=xt([s],()=>this.describe(t),{name:r,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(y,b)=>y===b})}catch(y){c(),l?.();for(let b of f)b();throw i.dispose(),y}let T=He(h);return{node:h,dispose(){d=!0,c(),l?.();for(let y of f)y();f.length=0,i.dispose(),T()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},r=e.reactiveName??"describe-diff",o={name:this.name,nodes:{},edges:[],subgraphs:[]},s=this.describe(t),i=Vt(o,s),a=Oe(i,{name:r,meta:{domain:"audit",kind:"describe-diff"},equals:(m,p)=>m===p}),d=this._describeReactive({...e,reactiveName:void 0}),u=!1,c=d.node.subscribe(m=>{if(!u)for(let p of m){if(p[0]!==R)continue;let l=p[1],g=Vt(s,l);s=l,g.events.length!==0&&a.emit(g)}}),f=He(a);return{node:a,dispose(){u=!0,c(),d.dispose(),a.down([[$,"describe-diff disposed"]]),f()}}}_explainReactive(e,t,r){let o=0,s=Oe(o,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,d=!1,u=()=>{a||d||(a=!0,Te(()=>{a=!1,!d&&(o+=1,s.emit(o))}))},c=i.onEvent(y=>{let b=y.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||u()}),f=[];e!=null&&ge(e)&&f.push(e),t!=null&&ge(t)&&f.push(t),r?.maxDepth!=null&&ge(r.maxDepth)&&f.push(r.maxDepth),r?.findCycle!=null&&ge(r.findCycle)&&f.push(r.findCycle);let m=()=>{for(let y of f)if(y.cache===void 0)return!1;return!0},p=()=>{let y=ue(e),b=ue(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:[]})}},l;try{l=xt([s],()=>{if(!m())return p();let y=ue(e),b=ue(t),v={...r?.maxDepth!==void 0?{maxDepth:An(r.maxDepth)}:{},...r?.findCycle!==void 0?{findCycle:Dn(r.findCycle)}:{}};return this._explainStatic(y,b,v)},{name:r?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:ue(e),to:ue(t)},equals:(y,b)=>y.found===b.found&&y.reason===b.reason&&y.steps.length===b.steps.length&&Hr(y.steps,b.steps)})}catch(y){throw c(),i.dispose(),y}let g=He(l),h=[],T=y=>{let b;return b=y.subscribe(v=>{let w=!1,_=!1;for(let x of v){let E=x[0];E===R?w=!0:(E===S||E===k||E===$)&&(_=!0)}(w||_)&&u(),_&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let y of f)h.push(T(y));return{node:l,dispose(){d=!0,c();for(let y of h)y?.();h.length=0,i.dispose(),g()}}}_pathsMatching(e){let t=Qe(e),r=[];return this._collectObserveTargets("",r),r.map(([o])=>o).filter(o=>t.test(o))}_collectObserveTargets(e,t){for(let r of[...this._mounts.keys()].sort()){let o=e===""?r:`${e}${L}${r}`;this._mounts.get(r)._collectObserveTargets(o,t)}for(let r of[...this._nodes.keys()].sort()){let o=this._nodes.get(r),s=e===""?r:`${e}${L}${r}`;t.push([s,o]),this._appendMetaObserveTargets(s,o,t)}}_appendMetaObserveTargets(e,t,r){for(let o of Object.keys(t.meta).sort()){let s=t.meta[o],i=`${e}${L}${Q}${L}${o}`;r.push([i,s]),this._appendMetaObserveTargets(i,s,r)}}observe(e,t){let r=typeof e=="string",s=Gn(r?t:e);if(s.reactive===!0)return this._observeReactive(r?e:void 0,s);let i=s.structured===!0||s.timeline===!0||s.causal===!0||s.derived===!0||s.detail==="minimal"||s.detail==="full"||s.format!=null,a=s.actor;if(r){let c=e,f=this.resolve(c);if(a!=null&&!f.allowsObserve(a))throw new J({actor:a,action:"observe",nodeName:c});return i?this._buildStructuredObserver([[c,f]],s,"one"):{subscribe(m){return f.subscribe(m)},up(m){try{f.up?.(m)}catch(p){if(p instanceof J)return;throw p}}}}let d=[];this._collectObserveTargets("",d),d.sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0);let u=a==null?d:d.filter(([,c])=>c.allowsObserve(a));return i?this._buildStructuredObserver(u,s,"all"):{subscribe:c=>{let f=u.map(([m,p])=>p.subscribe(l=>{c(m,l)}));return()=>{for(let m of f)m()}},up:(c,f)=>{try{this.resolve(c).up?.(f)}catch(m){if(m instanceof J)return;throw m}}}}_observeReactive(e,t){let r=t.tiers,o=r!=null?new Set(r):null,s=t.reactiveName??"observe";return K(i=>{let a=[],d=!1,u=!1,c=()=>{if(a.length===0||u)return;let g={events:a.slice(),flushedAt_ns:Z()};a.length=0,i.emit(g)},f={...t,reactive:!1,structured:!0,timeline:!0},m=e!=null?this.observe(e,f):this.observe(f),p=g=>{u||(a.push(g),!d&&(d=!0,Te(()=>{d=!1,c()})))};for(let g of m.events)p(g);let l=m.onEvent(p);return()=>{u=!0,l(),m.dispose()}},{name:s,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,r){let o=r==="one"?e[0]?.[0]:void 0,s=i=>{if(r==="one"&&o!=null){let c=this.resolve(o);return this._buildStructuredObserver([[o,c]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((c,f)=>c[0]<f[0]?-1:c[0]>f[0]?1:0);let d=i.actor,u=d==null?a:a.filter(([,c])=>c.allowsObserve(d));return this._buildStructuredObserver(u,i,"all")};return this._createObserveResult(e,t,s)}_createObserveResult(e,t,r){let o=t.timeline===!0,s=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",d=this.config.inspectorEnabled,u=(s||i)&&d,c=t.maxEvents,f=c!=null&&c>0?new pe(c):null,m=[],p=new Set,l=t.tiers!=null?new Set(t.tiers):null,g={},h=new Set,T=0,y=0,b=0,v=0,w=0,_=0,x=!1,E=!1,C=0,A=new Map,O=new Map,z=new Map,F=N=>{if(!(l!=null&&!l.has(N.type))){f?f.push(N):m.push(N);for(let I of p)I(N)}},P=N=>l==null||l.has(N),be=()=>o?{timestamp_ns:Z(),in_batch:$e(),batch_id:C}:{},tt=(N,I)=>{if(!(!u||!(N instanceof V)))return N._setInspectorHook(q=>{if(q.kind==="dep_message")A.set(N,q.depIndex);else if(q.kind==="run"){let Ee=q.batchData.map((G,W)=>G!=null&&G.length>0?G.at(-1):q.prevData[W]);O.set(N,Ee);let Y=q.batchData.map(G=>G!=null?[...G]:void 0);z.set(N,Y),i&&F({type:"derived",path:I,dep_values:Ee,dep_batches:Y,...be()})}})},Ge=N=>{let I=A.get(N),q=O.get(N);if(!s||q==null)return{};let Y=(I!=null&&I>=0&&N instanceof V?N._deps[I]:void 0)?.node,G=Y?.v,W=z.get(N);return{trigger_dep_index:I,trigger_dep_name:Y?.name,...G!=null?{trigger_version:{id:G.id,version:G.version}}:{},dep_values:[...q],...W!=null?{dep_batches:W}:{}}},Wt=[],Ht=[];for(let[N,I]of e){let q=tt(I,N);q&&Wt.push(q),Ht.push(I.subscribe(Ee=>{C++;for(let Y of Ee){let G=Y[0],W=be();if(G===R){g[N]=Y[1];let st=I instanceof V?I.lastMutation?.actor??ye:ye;F({type:"data",path:N,data:Y[1],actor:st,...W,...Ge(I)})}else if(a)G===M?P("dirty")&&T++:G===D?P("resolved")&&y++:G===ee?P("invalidate")&&b++:G===H?P("pause")&&v++:G===te?P("resume")&&w++:G===$?P("teardown")&&_++:G===S&&!h.has(N)?P("complete")&&(x=!0):G===k&&P("error")&&(E=!0,h.add(N));else if(G===M)P("dirty")&&T++,F({type:"dirty",path:N,...W});else if(G===D)P("resolved")&&y++,F({type:"resolved",path:N,...W,...Ge(I)});else if(G===ee)P("invalidate")&&b++,F({type:"invalidate",path:N,...W});else if(G===H)P("pause")&&v++,F({type:"pause",path:N,lockId:Y[1],...W});else if(G===te)P("resume")&&w++,F({type:"resume",path:N,lockId:Y[1],...W});else if(G===S)P("complete")&&!h.has(N)&&(x=!0),F({type:"complete",path:N,...W});else if(G===k){P("error")&&(E=!0,h.add(N));let st=I instanceof V?I.lastMutation?.actor??ye:ye;F({type:"error",path:N,data:Y[1],actor:st,...W})}else G===$&&(P("teardown")&&_++,F({type:"teardown",path:N,...W}))}}))}let nt=!1,rt=()=>{if(!nt){nt=!0;for(let N of Ht)N();for(let N of Wt)N();for(let N of Pe)N({value:void 0,done:!0});Pe.length=0}},ot=[],Pe=[];p.add(N=>{let I=Pe.shift();I?I({value:N,done:!1}):ot.push(N)});let Kt={get values(){return g},get dirtyCount(){return T},get resolvedCount(){return y},get invalidateCount(){return b},get pauseCount(){return v},get resumeCount(){return w},get teardownCount(){return _},get events(){return f?f.toArray():[...m]},get anyCompletedCleanly(){return x},get anyErrored(){return E},get completedWithoutErrors(){return x&&!E},onEvent(N){return p.add(N),()=>p.delete(N)},dispose:rt,expand(N){rt();let I={...t};return typeof N=="string"?I.detail=N:Object.assign(I,N),r(Gn(I))},[Symbol.asyncIterator](){return{next(){return ot.length>0?Promise.resolve({value:ot.shift(),done:!1}):nt?Promise.resolve({value:void 0,done:!0}):new Promise(N=>Pe.push(N))},return(){return rt(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(Kt,t),Kt}_attachFormatLogger(e,t){let r=t.format;if(r==null)return;let o=t.logger??(l=>console.log(l)),s=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=s==null&&i==null?()=>!0:l=>(s==null||s.has(l))&&(i==null||!i.has(l)),d=jr(t.theme),u=r==="stage-log"?Z():0,c=l=>l==null?"":t.stageLabels?.[l]??l,f=(l,g)=>l.length>g?`${l.slice(0,g-1)}\u2026`:l,m=l=>l.type==="data"||l.type==="error"?f(jt(l.data),120):"",p=l=>{if(r==="stage-log"){let x=(Z()-u)/1e9,E=c(l.path).padEnd(9);if(l.type==="data"){let C=m(l);return`[${x.toFixed(3)}s] ${E} \u2190${C?` ${C}`:""}`}if(l.type==="error"){let C=m(l);return`[${x.toFixed(3)}s] ${E} \u2717${C?` ${C}`:""}`}return l.type==="complete"?`[${x.toFixed(3)}s] ${E} \u25A0 complete`:`[${x.toFixed(3)}s] ${E} ${l.type}`}if(r==="json")try{return JSON.stringify(l)}catch{return JSON.stringify({type:l.type,path:l.path,data:"[unserializable]"})}let g=d[l.type]??"",h=l.path?`${d.path}${l.path}${d.reset} `:"",T=l.type==="data"||l.type==="error",y=l.type==="pause"||l.type==="resume",b=T?` ${jt(l.data)}`:y?` ${jt(l.lockId)}`:"",v=l.type==="data"||l.type==="resolved"||l.type==="derived"?l:void 0,w=v?.trigger_dep_name!=null?` <- ${v.trigger_dep_name}`:v?.trigger_dep_index!=null?` <- #${v.trigger_dep_index}`:"",_=l.in_batch?" [batch]":"";return`${h}${g}${l.type.toUpperCase()}${d.reset}${b}${w}${_}`};e.onEvent(l=>{a(l.type)&&o(p(l),l)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){Cn(this._disposers,this.name),this.signal([[$]],{internal:!0}),Cn(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"}),o={};for(let a of Object.keys(r.nodes).sort()){let{lastMutation:d,guard:u,...c}=r.nodes[a];o[a]=c}let s=[...r.subgraphs].sort(),i={...r,version:1,nodes:o,subgraphs:s};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 Yt(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let r=t?.config??Ne,{codec:o,codecVersion:s,payload:i}=Jt(e,r);return o.decode(i,s)}restore(e,t){if(Mn(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(s=>Qe(s)),o=t?.includeProducers===!0;for(let s of Object.keys(e.nodes).sort()){if(r!==null&&!r.some(a=>a.test(s)))continue;let i=e.nodes[s];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(s,new Error(`restore: slice.value is undefined for "${s}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!o)){if(i.v!=null){let d=this.tryResolve(s)?.v;if(d!=null&&d.id===i.v.id&&d.version===i.v.version)continue}try{this.set(s,i.value)}catch(a){t?.onError?.(s,a)}}}}}static fromSnapshot(e,t){Mn(e);let r=typeof t=="function"?t:t?.build,o=typeof t=="function"?void 0:t?.factories,s=new n(e.name);if(r)return r(s),s.restore(e),s;for(let p of[...e.subgraphs].sort((l,g)=>{let h=l.split(L).length,T=g.split(L).length;return h!==T?h-T:l<g?-1:l>g?1:0})){let l=p.split(L),g=s;for(let h of l)g._mounts.has(h)||g.mount(h,new n(h)),g=g._mounts.get(h)}let i=o?Object.entries(o).map(([p,l])=>({re:Qe(p),factory:l})):[],a=p=>{for(let l of i)if(l.re.test(p))return l.factory},d=p=>{let l=p.split(L),g=l.pop();if(g==null||g.length===0)throw new Error(`invalid snapshot path "${p}"`);let h=s;for(let T of l){let y=h._mounts.get(T);if(!y)throw new Error(`unknown mount "${T}" in path "${p}"`);h=y}return[h,g]},u=Object.entries(e.nodes).filter(([p])=>!p.includes(`${L}${Q}${L}`)).sort((p,l)=>p[0]<l[0]?-1:p[0]>l[0]?1:0),c=new Map(u),f=new Map,m=!0;for(;c.size>0&&m;){m=!1;for(let[p,l]of[...c.entries()]){let g=l?.deps??[];if(!g.every(w=>f.has(w)))continue;let[h,T]=d(p),y={...l?.meta??{}},b=a(p),v;if(l?.type==="state")v=Oe(l.value,{meta:y});else{if(b==null)continue;v=b(T,{path:p,type:l.type,value:l.value,meta:y,deps:g,resolvedDeps:g.map(w=>f.get(w))})}h.add(v,{name:T}),f.set(p,v),c.delete(p),m=!0}}if(c.size>0){let p=[...c.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${p}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return s.restore(e),s}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let r=e.map(u=>({tier:u,debounceMs:Math.max(0,u.debounceMs??0),compactEvery:Math.max(1,u.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));t.autoRestore===!0&&this._cascadeRestore(e,t.onError);let o=(u,c)=>{if(u.disposed)return;let f=Lr(c.nodes);if(u.lastSnapshot!=null&&f!==""&&f===u.lastFingerprint)return;let m=u.seq+1,p=Ve(),h=u.lastSnapshot==null||m%u.compactEvery===0?{name:this.name,mode:"full",snapshot:c,seq:m,timestamp_ns:p,format_version:me}:{name:this.name,mode:"diff",diff:Ln(u.lastSnapshot,c),seq:m,timestamp_ns:p,format_version:me};if(u.tier.filter&&!u.tier.filter(h))return;let T;try{T=u.tier.save(h)}catch(y){t.onError?.(y,u.tier);return}if(T&&typeof T.then=="function"){let v=(u.savePending??Promise.resolve()).then(()=>T,()=>T).then(()=>{u.disposed||(u.seq=m,u.lastSnapshot=c,u.lastFingerprint=f)},w=>{t.onError?.(w,u.tier)});u.savePending=v.finally(()=>{u.savePending===v&&(u.savePending=void 0)})}else u.seq=m,u.lastSnapshot=c,u.lastFingerprint=f},s=(u,c)=>{try{o(u,c)}catch(f){t.onError?.(f,u.tier)}},i=(u,c)=>{if(!c.some(l=>{let g=this.config.messageTier(l[0]);return g>=3&&g<5}))return;if(t.filter){let l=this.tryResolve(u);if(l==null)return;let g=Nt(l,Tt("standard"));if(!t.filter(u,g))return}let m,p=()=>(m==null&&(m=this.snapshot()),m);for(let l of r)l.disposed||(l.debounceMs===0?s(l,p()):(l.timer==null&&(l.timer=new ae),l.timer.start(l.debounceMs,()=>{l.disposed||s(l,this.snapshot())})))},a;if(t.paths!=null){let c=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(f=>{let m=this.tryResolve(f);return m==null?()=>{}:m.subscribe(p=>i(f,p))});a=()=>{for(let f of c)f()}}else a=this.observe().subscribe((u,c)=>i(u,c));let d=()=>{a();for(let u of r)u.disposed=!0,u.timer?.cancel();this._storageDisposers.delete(d)};return this._storageDisposers.add(d),{dispose:d}}async _cascadeRestore(e,t){for(let r of e){let o;try{o=await r.load?.()}catch(i){t?.(i,r);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let s=o;try{if(s.mode==="full"&&s.snapshot!=null)return this.restore(s.snapshot),!0;if(s.version===me&&s.nodes!=null)return this.restore(s),!0}catch(i){t?.(i,r)}}return!1}static async fromStorage(e,t,r){for(let o of t){let s;try{s=await o.load?.()}catch(d){r?.onError?.(d,o);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let i=s,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===me&&i.nodes!=null?i:void 0;if(a!=null)try{return n.fromSnapshot(a,r)}catch(d){r?.onError?.(d,o)}}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 o={path:e,annotation:t,timestamp_ns:Z(),...r?.actor!=null?{actor:r.actor}:{}};this._traceRing.push(o)}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(o=>!e(o)),r=this._traceRing.size-t.length;this._traceRing.clear();for(let o of t)this._traceRing.push(o);return r}static diff(e,t){let r=new Set(Object.keys(e.nodes)),o=new Set(Object.keys(t.nodes)),s=[...o].filter(y=>!r.has(y)).sort(),i=[...r].filter(y=>!o.has(y)).sort(),a=[],d=[];for(let y of r){if(!o.has(y))continue;let b=e.nodes[y],v=t.nodes[y],w=b.v,_=v.v;w!=null&&_!=null&&w.id===_.id&&w.version!==_.version&&d.push({path:y,id:w.id,from:w.version,to:_.version});let x=w!=null&&_!=null&&w.id===_.id&&w.version===_.version;for(let E of["type","status","sentinel"]){let C=b[E],A=v[E];C!==A&&a.push({path:y,field:E,from:C,to:A})}if(!x)for(let E of["value","meta"]){let C=b[E],A=v[E];$r(C,A)||a.push({path:y,field:E,from:C,to:A})}}let u=y=>`${y.from} ${y.to}`,c=new Set(e.edges.map(u)),f=new Set(t.edges.map(u)),m=t.edges.filter(y=>!c.has(u(y))),p=e.edges.filter(y=>!f.has(u(y))),l=new Set(e.subgraphs),g=new Set(t.subgraphs),h=[...g].filter(y=>!l.has(y)).sort(),T=[...l].filter(y=>!g.has(y)).sort();return{nodesAdded:s,nodesRemoved:i,nodesChanged:a,versionChanges:d,edgesAdded:m,edgesRemoved:p,subgraphsAdded:h,subgraphsRemoved:T}}};function Ln(n,e){let t=xe.diff(n,e),r={};for(let o of t.nodesAdded){let s=e.nodes[o];s!=null&&(r[o]=s)}return{...t,nodesAddedFull:r}}function Ut(n,e,t,r={}){let o={paths:[],depths:new Map,truncated:!1};if(!e)return r.withDetail?o:[];if(!r.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let s=r.maxDepth;if(s!=null&&(!Number.isInteger(s)||s<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(s===0)return r.withDetail?o:[];let i=new Map,a=new Map,d=new Map,u=new Map,c=new Set;for(let[b,v]of Object.entries(n.nodes)){if(!b)continue;c.add(b);let w=v.deps??[];i.set(b,w);for(let _ of w)_&&(c.add(_),a.has(_)||a.set(_,new Set),a.get(_).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||(c.add(v),c.add(w),u.has(v)||u.set(v,new Set),u.get(v).add(w),d.has(w)||d.set(w,new Set),d.get(w).add(v))}if(!c.has(e))return r.withDetail?o:[];let f=r.both===!0,m=b=>{if(f){let x=i.get(b)??[],E=d.get(b),C=a.get(b),A=u.get(b),O=[...x];return E&&O.push(...E),C&&O.push(...C),A&&O.push(...A),O}if(t==="upstream"){let x=i.get(b)??[],E=d.get(b);return E?[...x,...E]:x}let v=a.get(b),w=u.get(b),_=v?[...v]:[];return w&&_.push(...w),_},p=new Set([e]),l=new Map,g=[{path:e,depth:0}],h=0,T=!1;for(;h<g.length;){let b=g[h++];if(s!=null&&b.depth>=s){m(b.path).length>0&&(T=!0);continue}for(let v of m(b.path))!v||p.has(v)||(p.add(v),l.set(v,b.depth+1),g.push({path:v,depth:b.depth+1}))}let y=[...l.keys()].sort((b,v)=>b<v?-1:b>v?1:0);return r.withDetail?{paths:y,depths:l,truncated:T}:y}function Hr(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],o=e[t];if(r.path!==o.path||r.type!==o.type||r.status!==o.status||r.hop!==o.hop||r.dep_index!==o.dep_index||r.annotation!==o.annotation||r.value!==o.value||r.lastMutation!==o.lastMutation)return!1;let s=r.v,i=o.v;if(s!==i&&(s==null||i==null||s.id!==i.id||s.version!==i.version))return!1}return!0}function Me(n){return typeof n=="object"&&n!==null&&"subscribe"in n&&"down"in n}function $n(n){if(n<=0)throw new RangeError("timeoutMs must be > 0");if(n>9e6)throw new RangeError("timeoutMs must be <= 9_000_000 (\u22482.5h) to stay within safe ns arithmetic")}var et=class extends xe{output;status;lastError;breakerState;droppedCount;rateLimitState;constructor(e,t={}){super(t.name??"resilient_pipeline",t.graph);let r=e,o,s,i;if(t.rateLimit!=null)if(Me(t.rateLimit)){let d=r,u=t.rateLimit;r=ke(u,c=>{let f={...c,maxBuffer:c.maxBuffer??1/0,meta:U("resilient","rate-limit")};return $t(d,f).node}),this.add(r,{name:"rateLimited"})}else{let d={...t.rateLimit,maxBuffer:t.rateLimit.maxBuffer??1/0,meta:U("resilient","rate-limit")},u=$t(r,d);r=u.node,o=u.droppedCount,s=u.rateLimitState,this.add(r,{name:"rateLimited"}),this.add(o,{name:"droppedCount"}),this.add(s,{name:"rateLimitState"})}if(t.budget!=null)if(Me(t.budget)){let d=r,u=t.budget;r=ke(u,c=>c.length>0?qe(d,c,{meta:U("resilient","budget")}):d),this.add(r,{name:"budgetGated"})}else t.budget.length>0&&(r=qe(r,t.budget,{meta:U("resilient","budget")}),this.add(r,{name:"budgetGated"}));if(t.breaker!=null)if(Me(t.breaker)){let d=r,u=t.breaker,c=t.breakerOnOpen??"skip";r=ke(u,f=>{let m=It(f);return Lt(m,{onOpen:c,meta:U("resilient","breaker")})(d).node}),this.add(r,{name:"breakerWrapped"})}else{let d=It(t.breaker),u=t.breakerOnOpen??"skip",c=Lt(d,{onOpen:u,meta:U("resilient","breaker")})(r);r=c.node,i=c.breakerState,this.add(r,{name:"breakerWrapped"}),this.add(i,{name:"breakerState"})}if(t.timeoutMs!=null)if(Me(t.timeoutMs)){let d=r,u=t.timeoutMs;r=ke(u,c=>($n(c),Ft(d,c*1e6,{meta:U("resilient","timeout")}))),this.add(r,{name:"timeoutWrapped"})}else $n(t.timeoutMs),r=Ft(r,t.timeoutMs*1e6,{meta:U("resilient","timeout")}),this.add(r,{name:"timeoutWrapped"});if(t.retry!=null)if(Me(t.retry)){let d=r,u=t.retry;r=ke(u,c=>Pt(d,{...c,meta:U("resilient","retry")})),this.add(r,{name:"retryWrapped"})}else r=Pt(r,{...t.retry,meta:U("resilient","retry")}),this.add(r,{name:"retryWrapped"});t.fallback!==void 0&&(r=wn(r,t.fallback,{meta:U("resilient","fallback")}),this.add(r,{name:"fallbackWrapped"}));let a=vn(r,{initialStatus:t.initialStatus??"pending",meta:U("resilient","status")});this.output=a.node,this.status=a.status,this.lastError=a.error,this.breakerState=i,this.droppedCount=o,this.rateLimitState=s,this.add(this.output,{name:"output"}),this.add(this.status,{name:"status"}),this.add(this.lastError,{name:"lastError"})}};function Kr(n,e={}){let t=new et(n,e);return t.tagFactory("resilientPipeline",_t(e)),t}0&&(module.exports={NS_PER_MS,NS_PER_SEC,ResilientPipelineGraph,factoryTag,placeholderArgs,resilientPipeline});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { f as factoryTag, p as placeholderArgs } from '../../meta-Ct9nqQS5.cjs';
|
|
2
|
-
import '../../node-BYInONRr.cjs';
|
|
3
|
-
export { b as CircuitBreakerOptions, C as CircuitState, F as FallbackInput, N as NS_PER_MS, d as NS_PER_SEC, a as RateLimiterOptions, R as RateLimiterState, c as RetryOptions, S as StatusValue } from '../../index-DGTo1yka.cjs';
|
|
4
|
-
import '../../graph-E6likq7w.cjs';
|
|
5
|
-
export { B as BudgetConstraint } from '../../budget-gate-DiP_nK0n.cjs';
|
|
6
|
-
export { N as NodeOrValue, R as ResilientPipelineGraph, a as ResilientPipelineOptions, r as resilientPipeline } from '../../index-CUIkE1l9.cjs';
|
|
7
|
-
import '../../extra/storage-core.cjs';
|
|
8
|
-
import '../../extra/storage-tiers.cjs';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { f as factoryTag, p as placeholderArgs } from '../../meta-D8OyedKp.js';
|
|
2
|
-
import '../../node-BYInONRr.js';
|
|
3
|
-
export { b as CircuitBreakerOptions, C as CircuitState, F as FallbackInput, N as NS_PER_MS, d as NS_PER_SEC, a as RateLimiterOptions, R as RateLimiterState, c as RetryOptions, S as StatusValue } from '../../index-BAQrjuZF.js';
|
|
4
|
-
import '../../graph-BkIkog4h.js';
|
|
5
|
-
export { B as BudgetConstraint } from '../../budget-gate-CmmVtasH.js';
|
|
6
|
-
export { N as NodeOrValue, R as ResilientPipelineGraph, a as ResilientPipelineOptions, r as resilientPipeline } from '../../index-D1Gc7wV5.js';
|
|
7
|
-
import '../../extra/storage-core.js';
|
|
8
|
-
import '../../extra/storage-tiers.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,b as f}from"../../chunk-SVFKHUCW.js";import"../../chunk-ECQRP2UT.js";import"../../chunk-3G5U5QNE.js";import"../../chunk-C72GO4IZ.js";import"../../chunk-RZJDIV2G.js";import"../../chunk-L6NSJVJZ.js";import"../../chunk-2BX4NB34.js";import"../../chunk-SGS4OJGS.js";import"../../chunk-ESMPEKEV.js";import"../../chunk-FHRBBHJN.js";import{a as c,b as d}from"../../chunk-4VVTGLXJ.js";import{b as a,c as b}from"../../chunk-35JTVPOX.js";import"../../chunk-CKFQS2CJ.js";import"../../chunk-LYCLF26R.js";import"../../chunk-CK2E7BTU.js";import"../../chunk-QYADASLV.js";export{c as NS_PER_MS,d as NS_PER_SEC,e as ResilientPipelineGraph,b as factoryTag,a as placeholderArgs,f as resilientPipeline};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-RZJDIV2G.js";import"./chunk-L6NSJVJZ.js";import"./chunk-SGS4OJGS.js";import"./chunk-ESMPEKEV.js";import"./chunk-4VVTGLXJ.js";import"./chunk-35JTVPOX.js";import"./chunk-CKFQS2CJ.js";import"./chunk-LYCLF26R.js";import"./chunk-CK2E7BTU.js";import"./chunk-QYADASLV.js";export{c as CircuitOpenError,g as RateLimiterOverflowError,j as TimeoutError,a as budgetGate,d as circuitBreaker,k as fallback,h as rateLimiter,b as retry,l as timeout,f as tokenBucket,e as withBreaker,i as withStatus};
|