@graphrefly/graphrefly 0.42.0 → 0.43.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/{chunk-5ST42ESJ.js → chunk-3XDYJRYU.js} +1 -1
- package/dist/{chunk-FDZAZNRO.js → chunk-4YAN45KM.js} +1 -1
- package/dist/{chunk-ACMJ2ZPS.js → chunk-626TESAC.js} +1 -1
- package/dist/{chunk-7B7ELAT2.js → chunk-6HOSXQKF.js} +1 -1
- package/dist/{chunk-G5VBJ5K6.js → chunk-CUNIRONA.js} +1 -1
- package/dist/chunk-EBW4V6JN.js +1 -0
- package/dist/chunk-FDQGFWLF.js +1 -0
- package/dist/{chunk-KY2LMAXU.js → chunk-FG4TKHMC.js} +1 -1
- package/dist/{chunk-YGL7FPVQ.js → chunk-I7IGYPSL.js} +1 -1
- package/dist/{chunk-3K7HA4Y6.js → chunk-INQD2KRQ.js} +1 -1
- package/dist/{chunk-AGNM6RS6.js → chunk-JNWRYDJN.js} +1 -1
- package/dist/{chunk-LDQ3IUIP.js → chunk-JQFH2DV6.js} +1 -1
- package/dist/{chunk-5QRRKBUT.js → chunk-K2Q24F5T.js} +1 -1
- package/dist/chunk-KVV66NN2.js +1 -0
- package/dist/{chunk-3ERTUW2J.js → chunk-NON4NLIC.js} +4 -4
- package/dist/{chunk-IZM3UEH3.js → chunk-O2BLLH7M.js} +1 -1
- package/dist/{chunk-FUZ6S2DY.js → chunk-OCKEEPRJ.js} +1 -1
- package/dist/{chunk-NWXQIOIB.js → chunk-OFZG3TB3.js} +1 -1
- package/dist/{chunk-4QH6VJF4.js → chunk-OYJKFY7V.js} +1 -1
- package/dist/{chunk-7ARY3Y3T.js → chunk-P6C4WHZO.js} +1 -1
- package/dist/{chunk-Q7QQQA3I.js → chunk-PT7W5FCD.js} +1 -1
- package/dist/{chunk-KCACBSJH.js → chunk-Q4U3A3L5.js} +1 -1
- package/dist/{chunk-LPRWATHB.js → chunk-QE4IGY7I.js} +1 -1
- package/dist/{chunk-WHMUB5QB.js → chunk-QYVXF7GW.js} +1 -1
- package/dist/{chunk-DEJTNNQC.js → chunk-S3EEIPO7.js} +1 -1
- package/dist/{chunk-KT5DTRBP.js → chunk-SUWT3ZON.js} +1 -1
- package/dist/{chunk-CISGGAIF.js → chunk-TPKQW72B.js} +1 -1
- package/dist/{chunk-2K5RXLAH.js → chunk-V5A7M7RJ.js} +1 -1
- package/dist/{chunk-AS3TV2TV.js → chunk-VNC3TMVY.js} +1 -1
- package/dist/{chunk-6YFZMUMR.js → chunk-VOPGGIL7.js} +1 -1
- package/dist/{chunk-VRALOYRD.js → chunk-VQ4A6T2A.js} +1 -1
- package/dist/{chunk-HZKW2AAB.js → chunk-XG62INFA.js} +1 -1
- package/dist/{chunk-7VKFXLZQ.js → chunk-Y4NI3X7O.js} +1 -1
- package/dist/compat/index.cjs +5 -5
- package/dist/compat/index.d.cts +4 -4
- package/dist/compat/index.d.ts +4 -4
- package/dist/compat/index.js +1 -1
- package/dist/compat/nestjs/index.cjs +5 -5
- package/dist/compat/nestjs/index.d.cts +3 -3
- package/dist/compat/nestjs/index.d.ts +3 -3
- package/dist/compat/nestjs/index.js +1 -1
- package/dist/compat/zustand/index.js +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/extra/index.cjs +11 -11
- package/dist/extra/index.d.cts +2 -2
- package/dist/extra/index.d.ts +2 -2
- package/dist/extra/index.js +1 -1
- package/dist/extra/node.js +1 -1
- package/dist/extra/operators.js +1 -1
- package/dist/extra/reactive.js +1 -1
- package/dist/extra/sources.js +1 -1
- package/dist/graph/index.cjs +1 -1
- package/dist/graph/index.d.cts +1 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/{index-C0-Jv1kP.d.cts → index-0rKFCVFp.d.cts} +9 -0
- package/dist/{index-B11anra4.d.cts → index-B5iz82A3.d.cts} +2 -2
- package/dist/{index-BtAsBp8K.d.cts → index-BAOD98JD.d.cts} +1 -1
- package/dist/{index-D-Xs74HZ.d.cts → index-BiX1Nkgx.d.cts} +13 -3
- package/dist/{index-HoU88d5U.d.cts → index-BojK2fwH.d.cts} +2 -2
- package/dist/{index-3NmAfcH0.d.cts → index-BwLvVVsy.d.cts} +1 -1
- package/dist/{index-DQo8xBgd.d.ts → index-C59mYFKp.d.ts} +1 -1
- package/dist/{index-DBIqYS43.d.cts → index-C9pjcz3l.d.cts} +0 -15
- package/dist/{index-CJQm0g38.d.ts → index-CAC_rNzm.d.ts} +1 -1
- package/dist/{index-sl4NyzQx.d.cts → index-CDXc9zKM.d.cts} +1 -1
- package/dist/{index-2B7u2pVn.d.cts → index-CLon-IWF.d.cts} +1 -1
- package/dist/{index-CEMx8n40.d.cts → index-COD1kVoS.d.cts} +1 -1
- package/dist/{index-Bn4zHYLj.d.ts → index-CPT7C_f1.d.ts} +1 -1
- package/dist/{index-D8l8hNXn.d.ts → index-CQG3D1cp.d.ts} +1 -1
- package/dist/{index-DO9XxMzS.d.ts → index-CZQXo5tH.d.ts} +0 -15
- package/dist/{index-Bbkgpt5t.d.ts → index-D-AEQVLo.d.ts} +2 -2
- package/dist/{index-CZmcDtFn.d.ts → index-D4Y1cMG0.d.ts} +1 -1
- package/dist/{index-B3OTH1dV.d.ts → index-DSZ3ZCHF.d.ts} +1 -1
- package/dist/{index-BUYXac2c.d.ts → index-Dh_HJ82K.d.ts} +2 -2
- package/dist/{index-4Uz-e_fL.d.ts → index-DwigL4lY.d.ts} +13 -3
- package/dist/{index-CPNSy-U0.d.cts → index-DyR7eU5S.d.cts} +19 -0
- package/dist/{index-BeT2r7sk.d.ts → index-JZUPJIJy.d.ts} +19 -0
- package/dist/{index-pT8sCpOJ.d.ts → index-K0_0eR8g.d.ts} +9 -0
- package/dist/{index-CJIuLu2f.d.cts → index-O16yXPK4.d.cts} +1 -1
- package/dist/{index-LIpQQE9f.d.cts → index-O7fucFrU.d.cts} +1 -1
- package/dist/{index-DmAgG5CI.d.cts → index-RV_yDjOX.d.cts} +1 -1
- package/dist/{index-D6egPFAL.d.ts → index-cm1GNcWE.d.ts} +1 -1
- package/dist/{index-CpyNFqkB.d.ts → index-wAzD9yVj.d.ts} +1 -1
- package/dist/index.cjs +39 -39
- package/dist/index.d.cts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.js +1 -1
- package/dist/patterns/ai/browser.js +1 -1
- package/dist/patterns/ai/index.cjs +15 -15
- package/dist/patterns/ai/index.d.cts +5 -5
- package/dist/patterns/ai/index.d.ts +5 -5
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/ai/node.js +1 -1
- package/dist/patterns/cqrs/index.cjs +3 -3
- package/dist/patterns/cqrs/index.d.cts +2 -2
- package/dist/patterns/cqrs/index.d.ts +2 -2
- package/dist/patterns/cqrs/index.js +1 -1
- package/dist/patterns/demo-shell/index.js +1 -1
- package/dist/patterns/domain-templates/index.cjs +2 -2
- package/dist/patterns/domain-templates/index.js +1 -1
- package/dist/patterns/graphspec/index.cjs +4 -4
- package/dist/patterns/graphspec/index.js +1 -1
- package/dist/patterns/harness/index.cjs +7 -7
- package/dist/patterns/harness/index.d.cts +5 -5
- package/dist/patterns/harness/index.d.ts +5 -5
- package/dist/patterns/harness/index.js +1 -1
- package/dist/patterns/inspect/index.cjs +3 -3
- package/dist/patterns/inspect/index.d.cts +1 -1
- package/dist/patterns/inspect/index.d.ts +1 -1
- package/dist/patterns/inspect/index.js +1 -1
- package/dist/patterns/job-queue/index.cjs +3 -3
- package/dist/patterns/job-queue/index.d.cts +2 -2
- package/dist/patterns/job-queue/index.d.ts +2 -2
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/memory/index.cjs +3 -3
- package/dist/patterns/memory/index.d.cts +2 -2
- package/dist/patterns/memory/index.d.ts +2 -2
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.cjs +3 -3
- package/dist/patterns/messaging/index.js +1 -1
- package/dist/patterns/orchestration/index.cjs +3 -3
- package/dist/patterns/orchestration/index.d.cts +3 -3
- package/dist/patterns/orchestration/index.d.ts +3 -3
- package/dist/patterns/orchestration/index.js +1 -1
- package/dist/patterns/process/index.cjs +1 -1
- package/dist/patterns/process/index.d.cts +3 -3
- package/dist/patterns/process/index.d.ts +3 -3
- package/dist/patterns/process/index.js +1 -1
- package/dist/patterns/reactive-layout/index.js +1 -1
- package/dist/patterns/reduction/index.js +1 -1
- package/dist/patterns/surface/index.cjs +3 -3
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{pipeline-graph-WBlobVhU.d.cts → pipeline-graph-DPqKDk59.d.cts} +2 -2
- package/dist/{pipeline-graph-v8fMvqNk.d.ts → pipeline-graph-loP57TBA.d.ts} +2 -2
- package/dist/resilience-YIWPK4YC.js +1 -0
- package/dist/{sugar-CH-2ZY90.d.ts → sugar-DLwvMr3F.d.ts} +23 -3
- package/dist/{sugar-DStZfUEK.d.cts → sugar-DyVGtczU.d.cts} +23 -3
- package/package.json +1 -1
- package/dist/chunk-3ZZX7M25.js +0 -1
- package/dist/chunk-VE5SIZEM.js +0 -1
- package/dist/chunk-XLQPNNIC.js +0 -1
- package/dist/resilience-445VFFXQ.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var at=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var Rn=Object.getOwnPropertyNames;var An=Object.prototype.hasOwnProperty;var L=(r,e)=>()=>(r&&(e=r(r=0)),e);var Sn=(r,e)=>{for(var t in e)at(r,t,{get:e[t],enumerable:!0})},Dn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Rn(e))!An.call(r,s)&&s!==t&&at(r,s,{get:()=>e[s],enumerable:!(n=En(e,s))||n.enumerable});return r};var Cn=r=>Dn(at({},"__esModule",{value:!0}),r);function Fe(r){if(r==null)return me;let{type:e,id:t,...n}=r;return{type:e??"system",id:t??"",...n}}var me,ze=L(()=>{"use strict";me={type:"system",id:""}});function Re(){return be>0||ke}function Dt(){return be>0}function ve(r){be>0?Ee.push(r):r()}function ie(r){be+=1;let e=!1;try{r()}catch(t){throw e=!0,t}finally{if(be-=1,be===0)if(e){if(!ke){let t=Ee.splice(0);for(let n of t)try{n()}catch{}de.length=0,ce.length=0,ye.length=0}}else Mn()}}function Mn(){let r=!ke;r&&(ke=!0);let e=[],t=0;try{for(;de.length>0||ce.length>0||ye.length>0||r&&Ee.length>0;){if(r&&Ee.length>0){let o=Ee.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw de.length=0,ce.length=0,ye.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(de.length>0?de:ce.length>0?ce:ye).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{r&&(ke=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function Ae(r,e,t){if(e.length===0)return;if(e.length===1){let d=t(e[0][0]);if(d<3||!Re()){r(e);return}(d>=5?ye:d===4?ce:de).push(()=>r(e));return}let n=e.length,s=n,o=n,i=n,a=0;for(;a<n&&t(e[a][0])<3;)a++;for(s=a;a<n&&t(e[a][0])===3;)a++;for(o=a;a<n&&t(e[a][0])===4;)a++;i=a;let u=Re();if(s>0){let d=e.slice(0,s);r(d)}if(o>s){let d=e.slice(s,o);u?de.push(()=>r(d)):r(d)}if(i>o){let d=e.slice(o,i);u?ce.push(()=>r(d)):r(d)}if(n>i){let d=e.slice(i,n);u?ye.push(()=>r(d)):r(d)}}var be,ke,de,ce,ye,Ee,Se=L(()=>{"use strict";be=0,ke=!1,de=[],ce=[],ye=[],Ee=[]});function te(){return Math.trunc(performance.now()*1e6)}function _e(){return Date.now()*1e6}var De=L(()=>{"use strict"});var we,M,B,j,q,Q,ne,z,V,P,le,Ve,Ct,Be,Mt,Gt,He,ut,dt,ct,je,fe=L(()=>{"use strict";we=Symbol.for("graphrefly/START"),M=Symbol.for("graphrefly/DATA"),B=Symbol.for("graphrefly/DIRTY"),j=Symbol.for("graphrefly/RESOLVED"),q=Symbol.for("graphrefly/INVALIDATE"),Q=Symbol.for("graphrefly/PAUSE"),ne=Symbol.for("graphrefly/RESUME"),z=Symbol.for("graphrefly/TEARDOWN"),V=Symbol.for("graphrefly/COMPLETE"),P=Symbol.for("graphrefly/ERROR"),le=Object.freeze([B]),Ve=Object.freeze([j]),Ct=Object.freeze([q]),Be=Object.freeze([we]),Mt=Object.freeze([V]),Gt=Object.freeze([z]),He=Object.freeze([le]),ut=Object.freeze([Ve]),dt=Object.freeze([Ct]),ct=Object.freeze([Mt]),je=Object.freeze([Gt])});function It(r){r.registerMessageType(we,{tier:0,wireCrossing:!1}),r.registerMessageType(B,{tier:1,wireCrossing:!1}),r.registerMessageType(q,{tier:1,wireCrossing:!1,metaPassthrough:!1}),r.registerMessageType(Q,{tier:2,wireCrossing:!1}),r.registerMessageType(ne,{tier:2,wireCrossing:!1}),r.registerMessageType(M,{tier:3,wireCrossing:!0}),r.registerMessageType(j,{tier:3,wireCrossing:!0}),r.registerMessageType(V,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(P,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(z,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var Ue,Pt=L(()=>{"use strict";fe();Ue=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 Lt(r){return Array.isArray(r)?[...r]:[r]}function Gn(r,e){return r.has(e)||r.has("*")}function $t(r){let e=[];return r((s,o)=>{e.push({kind:"allow",actions:new Set(Lt(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(Lt(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let u of e)Gn(u.actions,o)&&u.where(s)&&(u.kind==="deny"?i=!0:a=!0);return i?!1:a}}function lt(r){let e=In.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 Y,In,Te=L(()=>{"use strict";Y=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}};In=["human","llm","wallet","system"]});function zt(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 s=2+t.length+2+e.length;if(s>4294967295)throw new Error(`encodeEnvelope: total envelope size ${s} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let o=new Uint8Array(s),i=0;return o[i++]=ft,o[i++]=t.length,o.set(t,i),i+=t.length,o[i++]=n>>>8&255,o[i++]=n&255,o.set(e,i),o}function Vt(r,e){if(r.length<Ft)throw new Error(`decodeEnvelope: bytes too short (${r.length} < ${Ft})`);let t=0,n=r[t++];if(n!==ft)throw new Error(`decodeEnvelope: unsupported envelope version ${n} (expected ${ft})`);let s=r[t++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+s+2>r.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+s+2} bytes, have ${r.length})`);let o=new TextDecoder().decode(r.subarray(t,t+s));t+=s;let i=(r[t]<<8|r[t+1])>>>0;t+=2;let a=r.subarray(t),u=e.lookupCodec(o);if(u==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:u,codecVersion:i,payload:a}}function Bt(r){r.registerCodec(Pn)}var Pn,ft,Ft,pt=L(()=>{"use strict";Pn={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)}},ft=1,Ft=4});function ht(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(ht);if(typeof r=="object"&&r!==null){let e={};for(let t of Object.keys(r).sort())e[t]=ht(r[t]);return e}return null}function Fn(r){let e=$n.encode(r),t=e.length,n=t*8,s=t+9+63&-64,o=new Uint8Array(s);o.set(e),o[t]=128;let i=new DataView(o.buffer);i.setUint32(s-4,n>>>0,!1),i.setUint32(s-8,Math.floor(n/4294967296)>>>0,!1);let a=1779033703,u=3144134277,d=1013904242,l=2773480762,g=1359893119,f=2600822924,p=528734635,c=1541459225,y=new Uint32Array(64),h=(v,b)=>v>>>b|v<<32-b;for(let v=0;v<s;v+=64){for(let x=0;x<16;x++)y[x]=i.getUint32(v+x*4,!1);for(let x=16;x<64;x++){let A=y[x-15],D=y[x-2],S=h(A,7)^h(A,18)^A>>>3,oe=h(D,17)^h(D,19)^D>>>10;y[x]=y[x-16]+S+y[x-7]+oe>>>0}let b=a,_=u,w=d,N=l,m=g,T=f,k=p,R=c;for(let x=0;x<64;x++){let A=h(m,6)^h(m,11)^h(m,25),D=m&T^~m&k,S=R+A+D+Ln[x]+y[x]>>>0,oe=h(b,2)^h(b,13)^h(b,22),ee=b&_^b&w^_&w,Le=oe+ee>>>0;R=k,k=T,T=m,m=N+S>>>0,N=w,w=_,_=b,b=S+Le>>>0}a=a+b>>>0,u=u+_>>>0,d=d+w>>>0,l=l+N>>>0,g=g+m>>>0,f=f+T>>>0,p=p+k>>>0,c=c+R>>>0}let O=v=>v.toString(16).padStart(8,"0");return O(a)+O(u)+O(d)+O(l)+O(g)+O(f)+O(p)+O(c)}function gt(r){let e=ht(r??null),t=JSON.stringify(e);return Fn(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 mt(r,e,t){let n=t?.id??zn();if(r===0)return{id:n,version:0};let o=(t?.hash??gt)(e);return{id:n,version:0,cid:o,prev:null}}function Ht(r,e,t){r.version+=1,"cid"in r&&(r.prev=r.cid,r.cid=t(e))}var Ln,$n,jt=L(()=>{"use strict";Ln=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]),$n=new TextEncoder});function Kt(r){return{node:r,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function bt(r){r.prevData=void 0,r.dirty=!1,r.involvedThisWave=!1,r.dataBatch.length=0,r.terminal=void 0}function We(r){return r.length===0?r:typeof r[0]=="symbol"?[r]:r}function re(r,e,t){let n=qt(r)?r:[],s=typeof r=="function"?r:typeof e=="function"?e:void 0,o={};return qt(r)?o=(yt(e)?e:t)??{}:yt(r)?o=r:o=(yt(e)?e:t)??{},new $(n,s,o)}var Ut,Wt,Vn,Bn,Oe,$,qt,yt,pe=L(()=>{"use strict";pt();ze();Se();De();Pt();Te();fe();jt();Ut=()=>{},Wt=100;Vn=(r,e,t,n)=>{t.direction==="down-in"&&r._onDepMessage(t.depIndex,e)},Bn=(r,e,t,n)=>{let s=r;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Be]:[Be,[M,o]];s._status==="dirty"&&i.push(le),Ae(e,i,s._config.tierOf)},Oe=new Ue({onMessage:Vn,onSubscribe:Bn});It(Oe);Bt(Oe);$=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??Oe,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??gt;let s=n.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?mt(s,this._cached===void 0?void 0:this._cached,{id:n.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Kt);let o={};for(let[a,u]of Object.entries(n.meta??{})){let d={initial:u,name:`${n.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};n.guard!=null&&(d.guard=n.guard),o[a]=new r([],void 0,d)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[M,a]])},down(a){i._emit(We(a))},up(a){i._emitUp(We(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 n=this._versioningLevel;if(n!=null&&e<=n)return;let s=t?.hash??this._hashFn;s!==this._hashFn&&(this._hashFn=s);let o=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??t?.id,u=i?.version??0,d=mt(e,o,{id:a,hash:s});d.version=u,this._versioning=d,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=Fe(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 s=Fe(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new Y({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new Y({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:_e()}}down(e,t){let n=We(e);n.length!==0&&(this._checkGuard(t),this._emit(n))}emit(e,t){this._checkGuard(t),this._emit([[M,e]])}up(e,t){if(this._deps.length===0)return;let n=We(e);if(n.length===0)return;this._checkGuard(t);let s=t??{internal:!0};this._validateUpTiers(n);for(let o of this._deps)o.node.up?.(n,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let n of e){let s=t(n[0]);if(s===3||s===4)throw new Error(`Node "${this.name}": tier-${s} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let u=Fe(t);if(!this._guard(u,"observe"))throw new Y({actor:u,action:"observe",nodeName:this.name})}let s=this._isTerminal&&this._resubscribable;if(s){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let u of this._deps)bt(u);if(this._partial===!1){for(let u of this._deps)if(u.prevData!==void 0||u.dataBatch.length!==0||u.terminal!==void 0||u.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:s},this._actions)}catch(u){throw this._sinkCount-=1,u}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let i=this._isTerminal;if(this._sinkCount===1&&!i)try{this._activate()}catch(u){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw u}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let n=0;n<e;n++){let s=n,o=this._deps[n];o.unsub=Ut,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,u=!1;for(let d of i)a(d[0])>=3&&(u=!0),this._config.onMessage(this,d,{direction:"down-in",depIndex:s},this._actions);u&&this._maybeRunFnOnSettlement()}),t++}}catch(n){this._deps[t].unsub=null;for(let s=0;s<t;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}bt(o)}}throw this._dirtyDepCount=0,n}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let t=this._deps.length,n=Kt(e);if(this._deps.push(n),this._sinks==null)return t;n.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(He),n.unsub=Ut;try{n.unsub=e.subscribe(s=>{if(n.unsub===null)return;let o=this._config.tierOf,i=!1;for(let a of s)o(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw n.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(n){this._emit([[P,this._wrapFnError("cleanup threw",n)]])}else if(t!=null&&typeof t=="object"){let n=t.deactivate;if(typeof n=="function")try{n()}catch(s){this._emit([[P,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let n of this._deps){if(n.unsub!=null){let s=n.unsub;n.unsub=null;try{s()}catch{}}bt(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],s=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(o)}if(s!==we){if(s===B){this._depDirtied(n);return}if(s===q){if(this._depInvalidated(n),this._cached===void 0)return;this._emit(dt);return}if(s===Q||s===ne){this._emit([t]);return}if(s===z){this._emit(je);return}if(s===M)this._depSettledAsData(n,t[1]);else if(s===j)this._depSettledAsResolved(n);else if(s===V)this._depSettledAsTerminal(n,!0);else if(s===P)this._depSettledAsTerminal(n,t[1]);else{this._emit([t]);return}if(!this._fn){(s===M||s===j)&&this._emit([t]),(s===V||s===P)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(He))}_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(ut),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([[P,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(ct)}_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([[P,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([[P,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let t=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),n=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=t[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:n,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:n};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(t,this._actions,o);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let a=i;(typeof a.beforeRun=="function"||typeof a.deactivate=="function"||typeof a.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[P,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Wt?(this._rerunDepth=0,this._emit([[P,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Wt} \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"?[le,e[0]]:e;let n=!0,s=!1,o=!1,i=-1;for(let u of e){let d=t(u[0]);d<i&&(n=!1),d===3&&(s=!0),u[0]===B&&(o=!0),i=d}let a=e;if(!n){let u=e.map((d,l)=>({m:d,i:l,tier:t(d[0])}));u.sort((d,l)=>d.tier-l.tier||d.i-l.i),a=u.map(d=>d.m)}if(s&&!o&&this._status!=="dirty"){let u=0;for(;u<a.length&&t(a[u][0])===0;)u++;return u===0?[le,...a]:[...a.slice(0,u),le,...a.slice(u)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let u=e[a];if(u[0]===P&&u[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(u=>u[0]===z||u[0]===q);if(a.length===0)return;t=a}t=this._frameBatch(t);let s=null;for(let a=0;a<t.length;a++){let u=t[a],d=u[0];if(d!==Q&&d!==ne){s?.push(u);continue}if(u.length<2)throw new Error(`Node "${this.name}": [[${d===Q?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let l=!0;if(this._pausable!==!1){let g=u[1];if(d===Q)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(g),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(g))l=!1;else if(this._pauseLocks.delete(g),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let f=this._pauseBuffer;this._pauseBuffer=[],this._emit(f)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}l?s?.push(u):s==null&&(s=t.slice(0,a))}if(s!=null){if(s.length===0)return;t=s}if(this._hasMeta&&t.some(a=>a[0]===z))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(je)}catch{}let{finalMessages:o,equalsError:i}=this._updateState(t);if(o.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,u=[];for(let d of o)a(d[0])===3?this._pauseBuffer.push(d):u.push(d);u.length>0&&this._dispatchOrAccumulate(u)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[P,i]])}_updateState(e){let t=this._config.tierOf,n,s,o=-1,i=0;for(let l of e)t(l[0])===3&&i++;let a=i<=1,u=-1;if(this._versioning!=null&&i>1){for(let l=e.length-1;l>=0;l--)if(e[l][0]===M){u=l;break}}for(let l=0;l<e.length;l++){let g=e[l],f=g[0];if(f===M){if(g.length>=2){let p=!1;if(a&&this._cached!==void 0)try{p=this._equals(this._cached,g[1])}catch(c){s=this._wrapFnError("equals threw",c),o=l;break}if(p){n==null&&(n=e.slice(0,l)),n.push(Ve),this._status="resolved";continue}this._cached=g[1],this._versioning!=null&&(u<0||l===u)&&Ht(this._versioning,g[1],this._hashFn)}this._status="settled",n?.push(g)}else if(n?.push(g),f===B)this._status="dirty";else if(f===j)this._status="resolved";else if(f===V){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(f===P){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(f===q){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 p=this._cleanup;if(typeof p=="function"){this._cleanup=void 0;try{p()}catch{}}else if(p!=null&&typeof p=="object"){let c=p.invalidate;if(typeof c=="function")try{c()}catch{}}}else f===z&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let d=o>=0?n??e.slice(0,o):n??e;return s!=null?{finalMessages:d,equalsError:s}:{finalMessages:d}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let n of t)n(e)};_dispatchOrAccumulate(e){if(Dt()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],ve(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}Ae(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);Ae(this._deliverToSinks,t,this._config.tierOf)}},qt=r=>Array.isArray(r),yt=r=>typeof r=="object"&&r!=null&&!Array.isArray(r)});function vt(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 Hn(r){return r._describeKind!=null?r._describeKind:r._deps.length>0?"derived":r._fn!=null?"producer":"state"}function jn(r){let e={};for(let[t,n]of Object.entries(r.meta))try{e[t]=n.cache}catch{}return e}function _t(r,e,t){let n=e==null,s=!n&&e!=null?[...e].filter(l=>l.startsWith("meta.")).map(l=>l.slice(5)):null,o=n||e.has("meta")||s!=null&&s.length>0,i="state",a=[];r instanceof $&&(i=Hn(r),a=r._deps.map(l=>l.node.name??""));let u={type:i,deps:a};(n||e.has("status"))&&(u.status=r.status);let d=r instanceof $?r._guard:void 0;if(o){let l={...jn(r)};if(d!=null&&l.access===void 0&&(l.access=lt(d)),s!=null&&s.length>0&&!e.has("meta")){let g={};for(let f of s)f in l&&(g[f]=l[f]);u.meta=g}else u.meta=l}if(r.name!=null&&(u.name=r.name),(n||e.has("value"))&&(!t||i==="state")){r.status==="sentinel"&&(u.sentinel=!0);try{u.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),u.v=l}return(n||e.has("guard"))&&d!=null&&(u.guard=lt(d)),(n||e.has("lastMutation"))&&r.lastMutation!=null&&(u.lastMutation=r.lastMutation),u}var Yt=L(()=>{"use strict";Te();pe()});function J(r,e){return re([],{...e,initial:r})}function Ke(r,e){return re((n,s,o)=>r(s,o)??void 0,{describeKind:"producer",...e})}function U(r,e,t){return re(r,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);o.emit(e(a,i))},{describeKind:"derived",...t})}var qe=L(()=>{"use strict";pe()});function Jt(r,e,t){return{[r]:!0,[`${r}_type`]:e,...t??{}}}var Xt=L(()=>{"use strict"});function wt(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 o=0;o<r.length;o++)if(!wt(r[o],e[o]))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 s=new Set(n);for(let o of t)if(!s.has(o)||!wt(r[o],e[o]))return!1;return!0}function Zt(r,e){return`${r}\0${e}`}function Tt(r,e){let t=[],n=new Set(r.subgraphs),s=new Set(e.subgraphs),o=[];for(let h of s)n.has(h)||o.push(h);o.sort();for(let h of o)t.push({type:"subgraph-mounted",path:h});let i=new Set(Object.keys(r.nodes)),a=new Set(Object.keys(e.nodes)),u=[];for(let h of a)i.has(h)||u.push(h);u.sort();for(let h of u)t.push({type:"node-added",path:h,node:{...e.nodes[h]}});let d=[];for(let h of a){if(!i.has(h))continue;let O=r.nodes[h]?.meta,v=e.nodes[h]?.meta;O==null&&v==null||wt(O??{},v??{})||d.push(h)}d.sort();for(let h of d)t.push({type:"node-meta-changed",path:h,prevMeta:r.nodes[h]?.meta??{},nextMeta:e.nodes[h]?.meta??{}});let l=new Map;for(let h of r.edges)l.set(Zt(h.from,h.to),h);let g=new Map;for(let h of e.edges)g.set(Zt(h.from,h.to),h);let f=[];for(let[h,O]of g)l.has(h)||f.push(O);f.sort((h,O)=>h.from<O.from?-1:h.from>O.from?1:h.to<O.to?-1:h.to>O.to?1:0);for(let h of f)t.push({type:"edge-added",from:h.from,to:h.to});let p=[];for(let[h,O]of l)g.has(h)||p.push(O);p.sort((h,O)=>h.from<O.from?-1:h.from>O.from?1:h.to<O.to?-1:h.to>O.to?1:0);for(let h of p)t.push({type:"edge-removed",from:h.from,to:h.to});let c=[];for(let h of i)a.has(h)||c.push(h);c.sort();for(let h of c)t.push({type:"node-removed",path:h});let y=[];for(let h of n)s.has(h)||y.push(h);y.sort();for(let h of y)t.push({type:"subgraph-unmounted",path:h});return{events:t,flushedAt_ns:te()}}var Qt=L(()=>{"use strict";De()});function X(r){return r.subscribe(()=>{})}var en=L(()=>{"use strict"});var Ot=L(()=>{"use strict";en()});var Ye,tn=L(()=>{"use strict";Ye=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 Ce,nn=L(()=>{"use strict";Ce=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 rn(r,e,t,n={}){let s=e in r.nodes,o=t in r.nodes;if(!s)return Je(e,t,"no-such-from");if(!o)return Je(e,t,"no-such-to");let i=n.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(n.findCycle===!0){let d=Un(r,e,n);if(d!=null)return d}let u=Xe(e,r.nodes[e],0,n);return Ze(e,t,[u])}if(i===0)return Je(e,t,"no-path");let a=sn(r,e,t,i);return a.found?Ze(e,t,on(r,a.pathOrder,n)):Je(e,t,a.truncated?"max-depth-exceeded":"no-path")}function sn(r,e,t,n){let s=new Map,o=[{path:t,depth:0}],i=new Set([t]),a=0,u=!1;for(;a<o.length;){let g=o[a++];if(g.path===e)break;if(n!=null&&g.depth>=n){let y=r.nodes[g.path];y?.deps&&y.deps.length>0&&(u=!0);continue}let f=r.nodes[g.path];if(f==null)continue;let p=f.deps??[],c=new Map;for(let y=0;y<p.length;y++){let h=p[y];if(!h)continue;let O=c.get(h);O==null&&(O=[],c.set(h,O)),O.push(y)}for(let[y,h]of c)i.has(y)||(i.add(y),s.set(y,{from:g.path,depIndices:h}),o.push({path:y,depth:g.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:u};let d=[{path:e}],l=e;for(;l!==t;){let g=s.get(l);if(g==null)return{found:!1,pathOrder:[],truncated:!1};d[d.length-1].depIndices=g.depIndices,d.push({path:g.from}),l=g.from}return{found:!0,pathOrder:d,truncated:!1}}function Un(r,e,t){let n=r.nodes[e];if(n==null)return null;let s=n.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=Xe(e,n,0,t);a.dep_index=o[0];let u=Xe(e,n,1,t);return Ze(e,e,[a,u])}let i=null;for(let a=0;a<s.length;a++){let u=s[a];if(!u||u===e)continue;let d=sn(r,u,e,t.maxDepth);d.found&&(i==null||d.pathOrder.length<i.pathOrder.length)&&(i=d,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...d.pathOrder],truncated:!1})}return i==null?null:Ze(e,e,on(r,i.pathOrder,t))}function on(r,e,t){return e.map((n,s)=>{let o=r.nodes[n.path],i=Xe(n.path,o,s,t);return n.depIndices!=null&&n.depIndices.length>0&&(i.dep_index=n.depIndices[0],n.depIndices.length>1&&(i.dep_indices=[...n.depIndices])),i})}function Xe(r,e,t,n){let s={path:r,type:e.type,hop:t};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let o=n.annotations?.get(r)??e.annotation;o!=null&&(s.annotation=o);let i=n.lastMutations?.get(r)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function Ze(r,e,t){return an(r,e,!0,"ok",t)}function Je(r,e,t){return an(r,e,!1,t,[])}function an(r,e,t,n,s){let o=Wn(r,e,t,n,s);return{from:r,to:e,found:t,reason:n,steps:s,text:o,toJSON(){return{from:r,to:e,found:t,reason:n,steps:s}}}}function Wn(r,e,t,n,s){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 o=[`Causal path: ${r} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let u=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(u),"value"in i&&o.push(` value: ${Kn(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let d=i.lastMutation.actor;o.push(` actor: ${d.type}${d.id?`:${d.id}`:""}`)}}return o.join(`
|
|
2
|
-
`)}function
|
|
3
|
-
`)}function mn(r){if(r.version!==he)throw new Error(`unsupported snapshot version ${String(r.version)} (expected ${he})`);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 Qn(r,e){let t=new WeakMap,n=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,u=o.constructor;if(a!==u)return!1;if(s instanceof Date)return s.getTime()===o.getTime();if(s instanceof RegExp)return s.source===o.source&&s.flags===o.flags;if(Array.isArray(s)){let f=o;if(s.length!==f.length)return!1;for(let p=0;p<s.length;p++)if(!n(s[p],f[p]))return!1;return!0}if(s instanceof Map){let f=o;if(s.size!==f.size)return!1;for(let[p,c]of s)if(!f.has(p)||!n(c,f.get(p)))return!1;return!0}if(s instanceof Set){let f=o;if(s.size!==f.size)return!1;for(let p of s){let c=!1;for(let y of f)if(n(p,y)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(s)){let f=s,p=o;if(f.length!==p.length)return!1;for(let c=0;c<f.length;c++)if(f[c]!==p[c])return!1;return!0}let d=Object.keys(s),l=Object.keys(o);if(d.length!==l.length)return!1;let g=new Set(l);for(let f of d)if(!g.has(f)||!n(s[f],o[f]))return!1;return!0};return n(r,e)}function er(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qe(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 s=r.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let o=r.slice(t+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,t=s;continue}e+=er(n)}return e+="$",new RegExp(e)}function xt(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 rr(r){return r==="none"?nr: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 bn(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 sr(r,e,t){for(let n=0;n<r.length;n++){let s=r.charCodeAt(n);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${r}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function Nt(r,e,t){if(r==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(r.includes(I))throw new Error(`Graph "${e}": ${t} "${r}" must not contain '${I}' (path separator)`);if(r===Z)throw new Error(`Graph "${e}": ${t} name "${Z}" is reserved for meta companion paths`);sr(r,e,t)}function or(r,e){if(r==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=r.split(I);for(let n of t)if(n==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function ir(r,e){let t=!1;for(let s of r)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?r.filter(s=>e.isMetaPassthrough(s[0])):r}function vn(r){for(let e of r._mounts.values())vn(e);for(let e of r._nodes.values())try{e.down([[z]],{internal:!0})}catch{}}function _n(r,e){let t=se.diff(r,e),n={};for(let s of t.nodesAdded){let o=e.nodes[s];o!=null&&(n[s]=o)}return{...t,nodesAddedFull:n}}function kt(r,e,t,n={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return n.withDetail?s:[];if(!n.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=n.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return n.withDetail?s:[];let i=new Map,a=new Map,u=new Map,d=new Map,l=new Set;for(let[b,_]of Object.entries(r.nodes)){if(!b)continue;l.add(b);let w=_.deps??[];i.set(b,w);for(let N of w)N&&(l.add(N),a.has(N)||a.set(N,new Set),a.get(N).add(b))}for(let b of r.edges){if(b==null||typeof b!="object")continue;let _=typeof b.from=="string"?b.from:"",w=typeof b.to=="string"?b.to:"";!_||!w||(l.add(_),l.add(w),d.has(_)||d.set(_,new Set),d.get(_).add(w),u.has(w)||u.set(w,new Set),u.get(w).add(_))}if(!l.has(e))return n.withDetail?s:[];let g=n.both===!0,f=b=>{if(g){let m=i.get(b)??[],T=u.get(b),k=a.get(b),R=d.get(b),x=[...m];return T&&x.push(...T),k&&x.push(...k),R&&x.push(...R),x}if(t==="upstream"){let m=i.get(b)??[],T=u.get(b);return T?[...m,...T]:m}let _=a.get(b),w=d.get(b),N=_?[..._]:[];return w&&N.push(...w),N},p=new Set([e]),c=new Map,y=[{path:e,depth:0}],h=0,O=!1;for(;h<y.length;){let b=y[h++];if(o!=null&&b.depth>=o){f(b.path).length>0&&(O=!0);continue}for(let _ of f(b.path))!_||p.has(_)||(p.add(_),c.set(_,b.depth+1),y.push({path:_,depth:b.depth+1}))}let v=[...c.keys()].sort((b,_)=>b<_?-1:b>_?1:0);return n.withDetail?{paths:v,depths:c,truncated:O}:v}function ar(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++){let n=r[t],s=e[t];if(n.path!==s.path||n.type!==s.type||n.status!==s.status||n.hop!==s.hop||n.dep_index!==s.dep_index||n.annotation!==s.annotation||n.value!==s.value||n.lastMutation!==s.lastMutation)return!1;let o=n.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}var I,Z,he,tr,nr,se,wn=L(()=>{"use strict";ze();Se();De();Te();fe();Yt();pe();qe();Qt();Ot();tn();nn();pt();un();fn();I="::",Z="__meta__",he=1;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"},nr={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};se=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(I))throw new Error(`Graph name must not contain '${I}' (got "${e}")`);if(e===Z)throw new Error(`Graph name "${Z}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??Oe,this._traceRing=new Ce(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=Ke(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,s=t?.name??n;if(s==null||s==="")throw new Error(`Graph "${this.name}": graph.add requires a non-empty name \u2014 pass via opts.name or set it on the node (e.g. state(0, { name: "x" }))`);let o=s,i=t?.annotation;if(Nt(o,this.name,"add"),this._mounts.has(o))throw new Error(`Graph "${this.name}": name "${o}" is already a mount point`);if(this._nodes.has(o))throw new Error(`Graph "${this.name}": node "${o}" already exists`);let a=this._nodeToName.get(e);if(a!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${a}"`);return this._nodes.set(o,e),this._nodeToName.set(e,o),this._emitTopology({kind:"added",name:o,nodeKind:"node"}),i!=null&&(this._annotations.set(o,i),this.config.inspectorEnabled&&this._traceRing.push({path:o,annotation:i,timestamp_ns:te()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof $&&t._applyVersioning(e)}remove(e){Nt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let o={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,u]of i)a.includes(`${I}${Z}${I}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...t._collectSubgraphs(`${e}${I}`)),this._mounts.delete(e),t._parent=void 0,vn(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}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([[z]],{internal:!0});let s={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:s}),s}removeAll(e){let t=typeof e=="function"?e:(()=>{let o=Qe(e);return i=>o.test(i)})(),n={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>t(o));for(let o of s){let i=this.remove(o);n.nodes.push(...i.nodes),n.mounts.push(...i.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=e.length)return{value:void 0,done:!0};let s=e[n++];return{value:[s,t.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(I))return this.resolve(e);let t=this._nodes.get(e);if(!t)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return t}get(e){return this.node(e).cache}set(e,t,n){let s=n?.internal===!0;this.node(e).down([[M,t]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);ie(()=>{for(let[s,o]of n)this.set(s,o,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[q]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let s=n?.internal===!0;this.node(e).down([[P,t]],{actor:n?.actor,internal:s,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[V]],{actor:t?.actor,internal:n,delivery:"write"})}edges(e){let t=e?.recursive===!0,n=new Map;if(!t){for(let[u,d]of this._nodes)n.set(d,u);let a=[];for(let[u,d]of this._nodes)if(d instanceof $)for(let l of d._deps){let g=n.get(l.node);g!=null&&a.push([g,u])}return a.sort((u,d)=>u[0]<d[0]?-1:u[0]>d[0]?1:u[1]<d[1]?-1:u[1]>d[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,u]of s)o.set(u,a);let i=[];for(let[a,u]of s)if(u instanceof $)for(let d of u._deps){let l=o.get(d.node);l!=null&&i.push([l,a])}return i.sort((a,u)=>a[0]<u[0]?-1:a[0]>u[0]?1:a[1]<u[1]?-1:a[1]>u[1]?1:0),i}mount(e,t){if(t===void 0){let s=new r(e);return this.mount(e,s)}if(typeof t=="function"){let s=new r(e);return t(s),this.mount(e,s)}let n=t;if(Nt(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 s=this;s!=null;s=s._parent)if(s===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],s=t.slice(1);if(s.length===0){let a=this._nodes.get(n);if(a)return a;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let o=this._nodes.get(n);if(o&&s.length>0&&s[0]===Z)return this._resolveMetaChainFromNode(o,s,t.join(I));let i=this._mounts.get(n);if(!i)throw this._nodes.has(n)?new Error(`Graph "${this.name}": "${n}" is a node; trailing path "${s.join(I)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return i.resolve(s.join(I))}_resolveMetaChainFromNode(e,t,n){let s=e,o=0,i=[...t];for(;o<i.length;){if(i[o]!==Z)throw new Error(`Graph "${this.name}": expected ${Z} segment in meta path "${n}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${Z} in "${n}"`);let a=i[o+1],u=s.meta[a];if(!u)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${n}"`);s=u,o+=2}return s}signal(e,t){if(t?.internal!==!0){for(let s of e)if(this.config.messageTier(s[0])===3)throw new Error(`Graph "${this.name}": Graph.signal() rejects tier-3 messages (DATA / RESOLVED). Broadcast is for control-plane tiers (START / DIRTY / INVALIDATE / PAUSE / RESUME / COMPLETE / ERROR / TEARDOWN). For per-node value writes, use Graph.set or graph.node(name).down(...).`)}let n=[];if(this._signalDeliver(e,t??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(e,t,n,s){for(let u of this._mounts.values())u._signalDeliver(e,t,n,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=ir(e,this.config);for(let u of[...this._nodes.keys()].sort()){let d=this._nodes.get(u);if(!n.has(d)){n.add(d);try{d.down(e,i)}catch(l){if(l instanceof Y)throw l;s.push(l)}a.length!==0&&this._signalMetaSubtree(d,a,n,i,s)}}}_signalMetaSubtree(e,t,n,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!n.has(a)){n.add(a);try{a.down(t,s)}catch(u){if(u instanceof Y)throw u;o.push(u)}this._signalMetaSubtree(a,t,n,s,o)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=Xn(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 s=vt(e?.detail,e?.fields),o=e?.detail==="spec",i=s,a=[];this._collectObserveTargets("",a);let u=new Map;for(let[_,w]of a)u.set(w,_);let d=[];{let _=a.map(([,m])=>m),w=new Set(u.values()),N=0;for(;_.length>0;){let m=_.shift();if(m instanceof $)for(let T of m._deps){let k=T.node;if(u.has(k))continue;let R=k.name??"",x=R;if(!x||w.has(x))if(R){let A=2;for(;w.has(`${R}#${A}`);)A++;x=`${R}#${A}`}else for(x=`__internal__/${N++}`;w.has(x);)x=`__internal__/${N++}`;u.set(k,x),w.add(x),d.push([x,k]),_.push(k)}}}let l=[...a,...d],g={};for(let[_,w]of l){if(t!=null&&!w.allowsObserve(t))continue;let N=_t(w,i,o),m=w instanceof $?w._deps.map(x=>u.get(x.node)??x.node.name??""):[],{name:T,...k}=N,R={...k,deps:m};if(!o){let x=this._annotations.get(_);x!=null&&(R.annotation=x)}if(n!=null)if(typeof n=="function"){let x=n;if(!(x.length>=2?x(_,R):x(R)))continue}else{let x=!0;for(let[A,D]of Object.entries(n)){let S=A==="deps_includes"?"depsIncludes":A==="meta_has"?"metaHas":A;if(S==="depsIncludes"){if(!R.deps.includes(String(D))){x=!1;break}continue}if(S==="metaHas"){if(!Object.hasOwn(R.meta??{},String(D))){x=!1;break}continue}if(R[S]!==D){x=!1;break}}if(!x)continue}g[_]=R}let f=new Set(Object.keys(g)),p=[];for(let[_,w]of l)if(w instanceof $)for(let N of w._deps){let m=u.get(N.node);m!=null&&p.push([m,_])}p.sort((_,w)=>_[0]<w[0]?-1:_[0]>w[0]?1:_[1]<w[1]?-1:_[1]>w[1]?1:0);let c=p.map(([_,w])=>({from:_,to:w}));(t!=null||n!=null)&&(c=c.filter(_=>f.has(_.from)&&f.has(_.to)));let y=this._collectSubgraphs(""),h=t!=null||n!=null?y.filter(_=>{let w=`${_}${I}`;return[...f].some(N=>N===_||N.startsWith(w))}):y,O=this,v=e;return{name:this.name,nodes:g,edges:c,subgraphs:h,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(_){let w={...v};return Array.isArray(_)?(w.fields=_,w.detail=void 0):(w.detail=_,w.fields=void 0),O.describe(w)}}}_collectSubgraphs(e){let t=[];for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${n}`;t.push(s),t.push(...this._mounts.get(n)._collectSubgraphs(`${s}${I}`))}return t}resourceProfile(e){return ln(this,e)}reachable(e,t,n={}){return n.withDetail===!0?kt(this.describe(),e,t,{...n,withDetail:!0}):kt(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(ae(e),ae(t),{...n?.maxDepth!==void 0?{maxDepth:hn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:gn(n.findCycle)}:{}})}_explainStatic(e,t,n){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,u]of Object.entries(s.nodes))u.lastMutation!=null&&i.set(a,u.lastMutation);return rn(s,e,t,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},n=e.reactiveName??"describe",s=0,o=J(s,{name:`${n}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ve(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(v=>{let b=v.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[],f=new WeakSet,p=v=>{if(f.has(v)||u)return;f.add(v);let b=v.topology.subscribe(_=>{for(let w of _){if(w[0]!==M)continue;let N=w[1];if(d(),N.kind==="added"&&N.nodeKind==="mount"){let m=v._mounts.get(N.name);m!=null&&p(m)}}});g.push(b);for(let _ of v._mounts.keys()){let w=v._mounts.get(_);w!=null&&p(w)}};p(this);let c,y=e.actor;yn(y)&&(c=y.subscribe(v=>{let b=!1,_=!1;for(let w of v){let N=w[0];N===M?b=!0:(N===V||N===P||N===z)&&(_=!0)}b&&d(),_&&(c?.(),c=void 0,d())}));let h;try{h=U([o],()=>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 g)b();throw i.dispose(),v}let O=X(h);return{node:h,dispose(){u=!0,l(),c?.();for(let v of g)v();g.length=0,i.dispose(),O()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},n=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(t),i=Tt(s,o),a=J(i,{name:n,meta:{domain:"audit",kind:"describe-diff"},equals:(f,p)=>f===p}),u=this._describeReactive({...e,reactiveName:void 0}),d=!1,l=u.node.subscribe(f=>{if(!d)for(let p of f){if(p[0]!==M)continue;let c=p[1],y=Tt(o,c);o=c,y.events.length!==0&&a.emit(y)}}),g=X(a);return{node:a,dispose(){d=!0,l(),u.dispose(),a.down([[z,"describe-diff disposed"]]),g()}}}_explainReactive(e,t,n){let s=0,o=J(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ve(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(v=>{let b=v.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[];e!=null&&ge(e)&&g.push(e),t!=null&&ge(t)&&g.push(t),n?.maxDepth!=null&&ge(n.maxDepth)&&g.push(n.maxDepth),n?.findCycle!=null&&ge(n.findCycle)&&g.push(n.findCycle);let f=()=>{for(let v of g)if(v.cache===void 0)return!1;return!0},p=()=>{let v=ae(e),b=ae(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=U([o],()=>{if(!f())return p();let v=ae(e),b=ae(t),_={...n?.maxDepth!==void 0?{maxDepth:hn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:gn(n.findCycle)}:{}};return this._explainStatic(v,b,_)},{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:ae(e),to:ae(t)},equals:(v,b)=>v.found===b.found&&v.reason===b.reason&&v.steps.length===b.steps.length&&ar(v.steps,b.steps)})}catch(v){throw l(),i.dispose(),v}let y=X(c),h=[],O=v=>{let b;return b=v.subscribe(_=>{let w=!1,N=!1;for(let m of _){let T=m[0];T===M?w=!0:(T===V||T===P||T===z)&&(N=!0)}(w||N)&&d(),N&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let v of g)h.push(O(v));return{node:c,dispose(){u=!0,l();for(let v of h)v?.();h.length=0,i.dispose(),y()}}}_pathsMatching(e){let t=Qe(e),n=[];return this._collectObserveTargets("",n),n.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${I}${n}`;this._mounts.get(n)._collectObserveTargets(s,t)}for(let n of[...this._nodes.keys()].sort()){let s=this._nodes.get(n),o=e===""?n:`${e}${I}${n}`;t.push([o,s]),this._appendMetaObserveTargets(o,s,t)}}_appendMetaObserveTargets(e,t,n){for(let s of Object.keys(t.meta).sort()){let o=t.meta[s],i=`${e}${I}${Z}${I}${s}`;n.push([i,o]),this._appendMetaObserveTargets(i,o,n)}}observe(e,t){let n=typeof e=="string",o=bn(n?t:e);if(o.reactive===!0)return this._observeReactive(n?e:void 0,o);let i=o.structured===!0||o.timeline===!0||o.causal===!0||o.derived===!0||o.detail==="minimal"||o.detail==="full"||o.format!=null,a=o.actor;if(n){let l=e,g=this.resolve(l);if(a!=null&&!g.allowsObserve(a))throw new Y({actor:a,action:"observe",nodeName:l});return i?this._buildStructuredObserver([[l,g]],o,"one"):{subscribe(f){return g.subscribe(f)},up(f){try{g.up?.(f)}catch(p){if(p instanceof Y)return;throw p}}}}let u=[];this._collectObserveTargets("",u),u.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let d=a==null?u:u.filter(([,l])=>l.allowsObserve(a));return i?this._buildStructuredObserver(d,o,"all"):{subscribe:l=>{let g=d.map(([f,p])=>p.subscribe(c=>{l(f,c)}));return()=>{for(let f of g)f()}},up:(l,g)=>{try{this.resolve(l).up?.(g)}catch(f){if(f instanceof Y)return;throw f}}}}_observeReactive(e,t){let n=t.tiers,s=n!=null?new Set(n):null,o=t.reactiveName??"observe";return Ke(i=>{let a=[],u=!1,d=!1,l=()=>{if(a.length===0||d)return;let y={events:a.slice(),flushedAt_ns:te()};a.length=0,i.emit(y)},g={...t,reactive:!1,structured:!0,timeline:!0},f=e!=null?this.observe(e,g):this.observe(g),p=y=>{d||(a.push(y),!u&&(u=!0,ve(()=>{u=!1,l()})))};for(let y of f.events)p(y);let c=f.onEvent(p);return()=>{d=!0,c(),f.dispose()}},{name:o,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,n){let s=n==="one"?e[0]?.[0]:void 0,o=i=>{if(n==="one"&&s!=null){let l=this.resolve(s);return this._buildStructuredObserver([[s,l]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let u=i.actor,d=u==null?a:a.filter(([,l])=>l.allowsObserve(u));return this._buildStructuredObserver(d,i,"all")};return this._createObserveResult(e,t,o)}_createObserveResult(e,t,n){let s=t.timeline===!0,o=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",u=this.config.inspectorEnabled,d=(o||i)&&u,l=t.maxEvents,g=l!=null&&l>0?new Ce(l):null,f=[],p=new Set,c=t.tiers!=null?new Set(t.tiers):null,y={},h=new Set,O=0,v=0,b=0,_=0,w=0,N=0,m=!1,T=!1,k=0,R=new Map,x=new Map,A=new Map,D=E=>{if(!(c!=null&&!c.has(E.type))){g?g.push(E):f.push(E);for(let G of p)G(E)}},S=E=>c==null||c.has(E),oe=()=>s?{timestamp_ns:te(),in_batch:Re(),batch_id:k}:{},ee=(E,G)=>{if(!(!d||!(E instanceof $)))return E._setInspectorHook(W=>{if(W.kind==="dep_message")R.set(E,W.depIndex);else if(W.kind==="run"){let Ne=W.batchData.map((C,H)=>C!=null&&C.length>0?C.at(-1):W.prevData[H]);x.set(E,Ne);let K=W.batchData.map(C=>C!=null?[...C]:void 0);A.set(E,K),i&&D({type:"derived",path:G,dep_values:Ne,dep_batches:K,...oe()})}})},Le=E=>{let G=R.get(E),W=x.get(E);if(!o||W==null)return{};let K=(G!=null&&G>=0&&E instanceof $?E._deps[G]:void 0)?.node,C=K?.v,H=A.get(E);return{trigger_dep_index:G,trigger_dep_name:K?.name,...C!=null?{trigger_version:{id:C.id,version:C.version}}:{},dep_values:[...W],...H!=null?{dep_batches:H}:{}}},Rt=[],At=[];for(let[E,G]of e){let W=ee(G,E);W&&Rt.push(W),At.push(G.subscribe(Ne=>{k++;for(let K of Ne){let C=K[0],H=oe();if(C===M){y[E]=K[1];let it=G instanceof $?G.lastMutation?.actor??me:me;D({type:"data",path:E,data:K[1],actor:it,...H,...Le(G)})}else if(a)C===B?S("dirty")&&O++:C===j?S("resolved")&&v++:C===q?S("invalidate")&&b++:C===Q?S("pause")&&_++:C===ne?S("resume")&&w++:C===z?S("teardown")&&N++:C===V&&!h.has(E)?S("complete")&&(m=!0):C===P&&S("error")&&(T=!0,h.add(E));else if(C===B)S("dirty")&&O++,D({type:"dirty",path:E,...H});else if(C===j)S("resolved")&&v++,D({type:"resolved",path:E,...H,...Le(G)});else if(C===q)S("invalidate")&&b++,D({type:"invalidate",path:E,...H});else if(C===Q)S("pause")&&_++,D({type:"pause",path:E,lockId:K[1],...H});else if(C===ne)S("resume")&&w++,D({type:"resume",path:E,lockId:K[1],...H});else if(C===V)S("complete")&&!h.has(E)&&(m=!0),D({type:"complete",path:E,...H});else if(C===P){S("error")&&(T=!0,h.add(E));let it=G instanceof $?G.lastMutation?.actor??me:me;D({type:"error",path:E,data:K[1],actor:it,...H})}else C===z&&(S("teardown")&&N++,D({type:"teardown",path:E,...H}))}}))}let rt=!1,st=()=>{if(!rt){rt=!0;for(let E of At)E();for(let E of Rt)E();for(let E of $e)E({value:void 0,done:!0});$e.length=0}},ot=[],$e=[];p.add(E=>{let G=$e.shift();G?G({value:E,done:!1}):ot.push(E)});let St={get values(){return y},get dirtyCount(){return O},get resolvedCount(){return v},get invalidateCount(){return b},get pauseCount(){return _},get resumeCount(){return w},get teardownCount(){return N},get events(){return g?g.toArray():[...f]},get anyCompletedCleanly(){return m},get anyErrored(){return T},get completedWithoutErrors(){return m&&!T},onEvent(E){return p.add(E),()=>p.delete(E)},dispose:st,expand(E){st();let G={...t};return typeof E=="string"?G.detail=E:Object.assign(G,E),n(bn(G))},[Symbol.asyncIterator](){return{next(){return ot.length>0?Promise.resolve({value:ot.shift(),done:!1}):rt?Promise.resolve({value:void 0,done:!0}):new Promise(E=>$e.push(E))},return(){return st(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(St,t),St}_attachFormatLogger(e,t){let n=t.format;if(n==null)return;let s=t.logger??(c=>console.log(c)),o=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=o==null&&i==null?()=>!0:c=>(o==null||o.has(c))&&(i==null||!i.has(c)),u=rr(t.theme),d=n==="stage-log"?te():0,l=c=>c==null?"":t.stageLabels?.[c]??c,g=(c,y)=>c.length>y?`${c.slice(0,y-1)}\u2026`:c,f=c=>c.type==="data"||c.type==="error"?g(xt(c.data),120):"",p=c=>{if(n==="stage-log"){let m=(te()-d)/1e9,T=l(c.path).padEnd(9);if(c.type==="data"){let k=f(c);return`[${m.toFixed(3)}s] ${T} \u2190${k?` ${k}`:""}`}if(c.type==="error"){let k=f(c);return`[${m.toFixed(3)}s] ${T} \u2717${k?` ${k}`:""}`}return c.type==="complete"?`[${m.toFixed(3)}s] ${T} \u25A0 complete`:`[${m.toFixed(3)}s] ${T} ${c.type}`}if(n==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let y=u[c.type]??"",h=c.path?`${u.path}${c.path}${u.reset} `:"",O=c.type==="data"||c.type==="error",v=c.type==="pause"||c.type==="resume",b=O?` ${xt(c.data)}`:v?` ${xt(c.lockId)}`:"",_=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,w=_?.trigger_dep_name!=null?` <- ${_.trigger_dep_name}`:_?.trigger_dep_index!=null?` <- #${_.trigger_dep_index}`:"",N=c.in_batch?" [batch]":"";return`${h}${y}${c.type.toUpperCase()}${u.reset}${b}${w}${N}`};e.onEvent(c=>{a(c.type)&&s(p(c),c)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){pn(this._disposers,this.name),this.signal([[z]],{internal:!0}),pn(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"}),s={};for(let a of Object.keys(n.nodes).sort()){let{lastMutation:u,guard:d,...l}=n.nodes[a];s[a]=l}let o=[...n.subgraphs].sort(),i={...n,version:1,nodes:s,subgraphs:o};if(e?.format==null)return i;if(e.format==="json-string")return JSON.stringify(i);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let a=this.config.lookupCodec(e.codec);if(a==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return zt(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??Oe,{codec:s,codecVersion:o,payload:i}=Vt(e,n);return s.decode(i,o)}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 n=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(o=>Qe(o)),s=t?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(n!==null&&!n.some(a=>a.test(o)))continue;let i=e.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(o,new Error(`restore: slice.value is undefined for "${o}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!s)){if(i.v!=null){let u=this.tryResolve(o)?.v;if(u!=null&&u.id===i.v.id&&u.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){t?.onError?.(o,a)}}}}}static fromSnapshot(e,t){mn(e);let n=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,o=new r(e.name);if(n)return n(o),o.restore(e),o;for(let p of[...e.subgraphs].sort((c,y)=>{let h=c.split(I).length,O=y.split(I).length;return h!==O?h-O:c<y?-1:c>y?1:0})){let c=p.split(I),y=o;for(let h of c)y._mounts.has(h)||y.mount(h,new r(h)),y=y._mounts.get(h)}let i=s?Object.entries(s).map(([p,c])=>({re:Qe(p),factory:c})):[],a=p=>{for(let c of i)if(c.re.test(p))return c.factory},u=p=>{let c=p.split(I),y=c.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${p}"`);let h=o;for(let O of c){let v=h._mounts.get(O);if(!v)throw new Error(`unknown mount "${O}" in path "${p}"`);h=v}return[h,y]},d=Object.entries(e.nodes).filter(([p])=>!p.includes(`${I}${Z}${I}`)).sort((p,c)=>p[0]<c[0]?-1:p[0]>c[0]?1:0),l=new Map(d),g=new Map,f=!0;for(;l.size>0&&f;){f=!1;for(let[p,c]of[...l.entries()]){let y=c?.deps??[];if(!y.every(w=>g.has(w)))continue;let[h,O]=u(p),v={...c?.meta??{}},b=a(p),_;if(c?.type==="state")_=J(c.value,{meta:v});else{if(b==null)continue;_=b(O,{path:p,type:c.type,value:c.value,meta:v,deps:y,resolvedDeps:y.map(w=>g.get(w))})}h.add(_,{name:O}),g.set(p,_),l.delete(p),f=!0}}if(l.size>0){let p=[...l.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 o.restore(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let n=e.map(d=>({tier:d,debounceMs:Math.max(0,d.debounceMs??0),compactEvery:Math.max(1,d.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));t.autoRestore===!0&&this._cascadeRestore(e,t.onError);let s=(d,l)=>{if(d.disposed)return;let g=Zn(l.nodes);if(d.lastSnapshot!=null&&g!==""&&g===d.lastFingerprint)return;let f=d.seq+1,p=_e(),h=d.lastSnapshot==null||f%d.compactEvery===0?{name:this.name,mode:"full",snapshot:l,seq:f,timestamp_ns:p,format_version:he}:{name:this.name,mode:"diff",diff:_n(d.lastSnapshot,l),seq:f,timestamp_ns:p,format_version:he};if(d.tier.filter&&!d.tier.filter(h))return;let O;try{O=d.tier.save(h)}catch(v){t.onError?.(v,d.tier);return}if(O&&typeof O.then=="function"){let _=(d.savePending??Promise.resolve()).then(()=>O,()=>O).then(()=>{d.disposed||(d.seq=f,d.lastSnapshot=l,d.lastFingerprint=g)},w=>{t.onError?.(w,d.tier)});d.savePending=_.finally(()=>{d.savePending===_&&(d.savePending=void 0)})}else d.seq=f,d.lastSnapshot=l,d.lastFingerprint=g},o=(d,l)=>{try{s(d,l)}catch(g){t.onError?.(g,d.tier)}},i=(d,l)=>{if(!l.some(c=>{let y=this.config.messageTier(c[0]);return y>=3&&y<5}))return;if(t.filter){let c=this.tryResolve(d);if(c==null)return;let y=_t(c,vt("standard"));if(!t.filter(d,y))return}let f,p=()=>(f==null&&(f=this.snapshot()),f);for(let c of n)c.disposed||(c.debounceMs===0?o(c,p()):(c.timer==null&&(c.timer=new Ye),c.timer.start(c.debounceMs,()=>{c.disposed||o(c,this.snapshot())})))},a;if(t.paths!=null){let l=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(g=>{let f=this.tryResolve(g);return f==null?()=>{}:f.subscribe(p=>i(g,p))});a=()=>{for(let g of l)g()}}else a=this.observe().subscribe((d,l)=>i(d,l));let u=()=>{a();for(let d of n)d.disposed=!0,d.timer?.cancel();this._storageDisposers.delete(u)};return this._storageDisposers.add(u),{dispose:u}}async _cascadeRestore(e,t){for(let n of e){let s;try{s=await n.load?.()}catch(i){t?.(i,n);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let o=s;try{if(o.mode==="full"&&o.snapshot!=null)return this.restore(o.snapshot),!0;if(o.version===he&&o.nodes!=null)return this.restore(o),!0}catch(i){t?.(i,n)}}return!1}static async fromStorage(e,t,n){for(let s of t){let o;try{o=await s.load?.()}catch(u){n?.onError?.(u,s);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let i=o,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===he&&i.nodes!=null?i:void 0;if(a!=null)try{return r.fromSnapshot(a,n)}catch(u){n?.onError?.(u,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${t.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,t,n){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let s={path:e,annotation:t,timestamp_ns:te(),...n?.actor!=null?{actor:n.actor}:{}};this._traceRing.push(s)}return}return e!=null?this.config.inspectorEnabled?this._annotations.get(e):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(e){return this._annotations.get(e)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(e){let t=this._traceRing.toArray().filter(s=>!e(s)),n=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return n}static diff(e,t){let n=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),o=[...s].filter(v=>!n.has(v)).sort(),i=[...n].filter(v=>!s.has(v)).sort(),a=[],u=[];for(let v of n){if(!s.has(v))continue;let b=e.nodes[v],_=t.nodes[v],w=b.v,N=_.v;w!=null&&N!=null&&w.id===N.id&&w.version!==N.version&&u.push({path:v,id:w.id,from:w.version,to:N.version});let m=w!=null&&N!=null&&w.id===N.id&&w.version===N.version;for(let T of["type","status","sentinel"]){let k=b[T],R=_[T];k!==R&&a.push({path:v,field:T,from:k,to:R})}if(!m)for(let T of["value","meta"]){let k=b[T],R=_[T];Qn(k,R)||a.push({path:v,field:T,from:k,to:R})}}let d=v=>`${v.from} ${v.to}`,l=new Set(e.edges.map(d)),g=new Set(t.edges.map(d)),f=t.edges.filter(v=>!l.has(d(v))),p=e.edges.filter(v=>!g.has(d(v))),c=new Set(e.subgraphs),y=new Set(t.subgraphs),h=[...y].filter(v=>!c.has(v)).sort(),O=[...c].filter(v=>!y.has(v)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:u,edgesAdded:f,edgesRemoved:p,subgraphsAdded:h,subgraphsRemoved:O}}}});var Nn=L(()=>{"use strict";wn()});var mr={};Sn(mr,{MessagingHubGraph:()=>nt,SubscriptionGraph:()=>Pe,TopicBridgeGraph:()=>et,TopicGraph:()=>Ie,TopicRegistry:()=>tt,messagingHub:()=>hr,subscription:()=>kn,topic:()=>pr,topicBridge:()=>gr});module.exports=Cn(mr);ze();Se();Te();fe();qe();pe();Xt();De();Te();fe();Se();fe();pe();qe();var Et=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),s=e.length-n;for(let o=0;o<n;o++)this._buf[o]=e[s+o];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),s=Math.min(e,this._size);if(s>=n)return[];let o=n-s;if(this._maxSize===void 0)return this._buf.slice(s,n);let i=new Array(o);for(let a=0;a<o;a++)i[a]=this._buf[(this._head+s+a)%this._maxSize];return i}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 o=0;o<t;o++)this._buf[o]=void 0;this._head=0;let n=Math.min(e.length,t),s=e.length-n;for(let o=0;o<n;o++)this._buf[o]=e[s+o];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 Me(r){return r.subscribe(()=>{})}var ur=64;function Tn(r,e={}){let{name:t,maxSize:n,versioning:s,guard:o,backend:i}=e,a=i??new Et(r,n),u=J(a.toArray(),{name:t,describeKind:"state",equals:(m,T)=>m===T,...s!=null?{versioning:s}:{},...o!=null?{guard:o}:{}});function d(){let m=a.toArray();ie(()=>{u.down([[B]],{internal:!0}),u.down([[M,m]],{internal:!0})})}let l=new Map,g=new Map,f=new Map;function p(m,T){return`${m}:${T===void 0?"END":T}`}function c(m){if(m.size<ur)return;let T=m.keys().next();if(T.done)return;let k=m.get(T.value);k!==void 0&&k.dispose(),m.delete(T.value)}function y(m){let T=a.version;try{return m()}finally{a.version!==T&&d()}}function h(m){if(!Number.isInteger(m)||m<0)throw new RangeError(`tail: n must be a non-negative integer (got ${m})`);let T=l.get(m);if(T!==void 0)return l.delete(m),l.set(m,T),T.node;c(l);let k=U([u],([x])=>{let A=x;return m===0||A.length===0?[]:A.slice(Math.max(0,A.length-m))},{initial:a.tail(m),describeKind:"derived"}),R=Me(k);return l.set(m,{node:k,dispose:R}),k}function O(m,T){if(!Number.isInteger(m)||m<0)throw new RangeError(`slice: start must be a non-negative integer (got ${m})`);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 k=p(m,T),R=g.get(k);if(R!==void 0)return g.delete(k),g.set(k,R),R.node;c(g);let x=U([u],([D])=>{let S=D;return T===void 0?S.slice(m):S.slice(m,T)},{initial:a.slice(m,T),describeKind:"derived"}),A=Me(x);return g.set(k,{node:x,dispose:A}),x}function v(m){let T=f.get(m);if(T!==void 0)return T.node;let k=U([u,m],([x,A])=>{let D=x,S=Math.max(0,Math.trunc(A??0));return D.slice(S)},{initial:[],describeKind:"derived"}),R=Me(k);return f.set(m,{node:k,dispose:R}),k}let b,_;function w(){b===void 0&&(b=re([u],(m,T,k)=>{let R=m[0],A=R!=null&&R.length>0?R.at(-1):k.prevData[0];if(A==null||A.length===0){T.down([[j]]);return}T.emit(A[A.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),_=U([u],([m])=>m.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),Me(b),Me(_))}let N={entries:u,get size(){return a.size},at(m){return a.at(m)},append(m){y(()=>a.append(m))},appendMany(m){m.length!==0&&y(()=>a.appendMany(m))},clear(){y(()=>a.clear())},trimHead(m){y(()=>a.trimHead(m))},withLatest(){return w(),u},get lastValue(){return w(),b},get hasLatest(){return w(),_},view(m){switch(m.kind){case"tail":return h(m.n);case"slice":return O(m.start,m.stop);case"fromCursor":return v(m.cursor)}},attach(m){let T=m.subscribe(k=>{for(let R of k)R[0]===M&&N.append(R[1])});return()=>T()},attachStorage(m){if(m.length===0)return()=>{};let T=new Map;for(let R of m)T.set(R,a.size);(async()=>{for(let R of m)if(typeof R.loadEntries=="function")try{let x=await Promise.resolve(R.loadEntries());x.entries.length>0&&a.size===0&&(a.restore(x.entries),T.set(R,x.entries.length),d());break}catch{}})();let k=u.subscribe(R=>{for(let x of R){if(x[0]!==M)continue;let A=x[1];for(let D of m){let S=T.get(D)??0;if(A.length<S){try{let ee=D.appendEntries(A);ee instanceof Promise&&ee.catch(()=>{})}catch{}T.set(D,A.length);continue}if(A.length===S)continue;let oe=A.slice(S);T.set(D,A.length);try{let ee=D.appendEntries(oe);ee instanceof Promise&&ee.catch(()=>{})}catch{}}}});return()=>k()},disposeAllViews(){for(let m of l.values())m.dispose();l.clear();for(let m of g.values())m.dispose();g.clear();for(let m of f.values())m.dispose();f.clear()},dispose(){for(let m of l.values())m.dispose();l.clear();for(let m of g.values())m.dispose();g.clear();for(let m of f.values())m.dispose();f.clear()}};return N}var Gs=$t((r,e)=>{r("observe"),r("signal"),e("write")});function xn(r){if(r===null||typeof r!="object"||Object.isFrozen(r))return r;for(let e of Object.keys(r))xn(r[e]);return Object.freeze(r)}function dr(r){let e=r.cache,n=(typeof e=="number"&&Number.isFinite(e)?e:0)+1;return r.down([[B],[M,n]]),n}function On(r,e,t,n,s,o){let i=e(t,n,s);if(i===void 0)return;let a=o!=null?{...i,handlerVersion:o}:i;r.append(a)}function Ge(r,e){let t=e.freeze??!0;return function(...s){let o=t?s.map(xn):s,i=_e(),a=e.seq?dr(e.seq):void 0;try{let u=r(...o);return e.audit&&e.onSuccess&&On(e.audit,e.onSuccess,o,u,{t_ns:i,seq:a},e.handlerVersion),u}catch(u){if(e.audit&&e.onFailure){let d=u instanceof Error?u.name:typeof u;On(e.audit,e.onFailure,o,u,{t_ns:i,seq:a,errorType:d},e.handlerVersion)}throw u}}}Ot();Nn();var cr=256;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 ue(r,e){return Jt("messaging",r,e)}var lr=1024,Ie=class extends se{_log;_publishImpl;events;latest;hasLatest;constructor(e,t={}){super(e,t.graph),this._log=Tn([],{name:"events",maxSize:t.retainedLimit??lr}),this._log.withLatest(),this.events=this._log.entries,this.add(this.events,{name:"events"}),this.latest=U([this.events],([n])=>{let s=n;return s.length===0?null:s[s.length-1]},{name:"latest",describeKind:"derived",meta:ue("topic_latest")}),this.add(this.latest,{name:"latest"}),this.addDisposer(X(this.latest)),this.hasLatest=U([this.events],([n])=>n.length>0,{name:"hasLatest",describeKind:"derived",meta:ue("topic_has_latest")}),this.add(this.hasLatest,{name:"hasLatest"}),this.addDisposer(X(this.hasLatest)),this.addDisposer(()=>{this.events.down([[V]])}),this.addDisposer(()=>this._log.disposeAllViews()),this._publishImpl=Ge(n=>{this._log.append(n)},{freeze:!1})}publish(e){if(e===void 0)throw new TypeError(`TopicGraph "${this.name}": publish(undefined) is not allowed (spec \xA75.12 SENTINEL).`);this._publishImpl(e)}attachEventStorage(e){return this._log.attachStorage(e)}retained(){return this.events.cache}get _logBundle(){return this._log}},Pe=class extends se{cursor;available;topic;_disposed=!1;_ackImpl;_pullAndAckImpl;constructor(e,t,n={}){super(e,n.graph),this.topic=t;let s;if(n.from!==void 0?n.from==="retained"?s=0:n.from==="now"?s=t.events.cache.length:s=xe(n.from,"subscription from"):s=xe(n.cursor??0,"subscription cursor"),this.cursor=J(s,{name:"cursor",describeKind:"state",meta:ue("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(X(this.available)),n.advanceOn!==void 0){let o=n.advanceOn,i=!1,a=re([o],()=>{if(!i){i=!0;return}if(this._disposed)return;let u=this.available.cache;if(u.length===0)return;let d=this.cursor.cache+u.length;this.cursor.emit(d)},{name:"advancePump",describeKind:"effect",meta:ue("subscription_advance_pump")});this.add(a,{name:"advancePump"}),this.addDisposer(X(a))}this._ackImpl=Ge(o=>{let i=this.available.cache,a=o===void 0?i.length:xe(o,"subscription ack count"),u=Math.min(a,i.length);if(u<=0)return this.cursor.cache;let d=this.cursor.cache+u;return this.cursor.emit(d),d},{freeze:!1}),this._pullAndAckImpl=Ge(o=>{let i=this.available.cache,a=o===void 0?i.length:xe(o,"subscription pullAndAck limit"),u=i.slice(0,a);if(u.length===0)return{items:u,cursor:this.cursor.cache};let d=this.cursor.cache+u.length;return this.cursor.emit(d),{items:u,cursor:d}},{freeze:!1})}ack(e){return this._disposed?this.cursor.cache:this._ackImpl(e)}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){return this._disposed?{items:[],cursor:this.cursor.cache}:this._pullAndAckImpl(e)}dispose(){this._disposed||(this._disposed=!0,this.cursor.down([[V]]),this.destroy())}},et=class extends se{_sourceSub;bridgedCount;output;constructor(e,t,n,s={}){super(e,s.graph),this._sourceSub=kn(`${e}-subscription`,t,{cursor:s.cursor}),this.mount("subscription",this._sourceSub);let o=Math.max(1,xe(s.maxPerPump??cr,"topic bridge maxPerPump")),i=s.map??(f=>f);this.output=U([this._sourceSub.available],([f])=>{let p=f,c=[],y=Math.min(p.length,o);for(let h=0;h<y;h++){let O=i(p[h]);O!==void 0&&c.push(O)}return c},{name:"output",describeKind:"derived",meta:ue("topic_bridge_output",{targetRef:n.name}),initial:[]}),this.add(this.output,{name:"output"}),this.addDisposer(X(this.output)),this.bridgedCount=J(0,{name:"bridgedCount",describeKind:"state",meta:ue("topic_bridge_count")}),this.add(this.bridgedCount,{name:"bridgedCount"}),this.addDisposer(X(this.bridgedCount));let a=this.output,u=this._sourceSub,d=this.bridgedCount,l=re([a],()=>{let f=a.cache;if(f.length===0)return;let p=u.available.cache.length,c=Math.min(p,o);if(c>0){u.ack(c);let y=d.cache??0;d.emit(y+f.length)}},{name:"ackPump",describeKind:"effect",meta:ue("topic_bridge_ack_pump")});this.add(l,{name:"ackPump"}),this.addDisposer(X(l));let g=fr(this.output,n);this.addDisposer(g)}};function fr(r,e){return r.subscribe(t=>{for(let n of t){if(n[0]!==M)continue;let s=n[1];s.length!==0&&ie(()=>{for(let o of s)e.publish(o)})}})}var tt=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()}},nt=class extends se{_registry;version;_defaultTopicOptions;_removeTopicImpl;constructor(e,t={}){super(e,t.graph);let n=J(0,{name:"version",describeKind:"state",meta:ue("hub_version")});this.add(n,{name:"version"}),this.version=n,this._registry=new tt(n),this._defaultTopicOptions={...t.defaultTopicOptions??{}},this._removeTopicImpl=Ge(s=>{try{this.remove(s)}finally{this._registry.delete(s);let o=this.version.cache??0;this.version.emit(o+1)}},{freeze:!1})}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 s={...this._defaultTopicOptions,...t??{}};n=new Ie(e,s),this._registry.set(e,n),this.mount(e,n);let o=this.version.cache??0;this.version.emit(o+1)}return n}publish(e,t){this.topic(e).publish(t)}publishMany(e){ie(()=>{for(let[t,n]of e)this.topic(t).publish(n)})}subscribe(e,t,n){let s=this.topic(t);return new Pe(e,s,n)}removeTopic(e){return this._registry.has(e)?(this._removeTopicImpl(e),!0):!1}};function pr(r,e){return new Ie(r,e)}function hr(r,e){return new nt(r,e)}function kn(r,e,t){return new Pe(r,e,t)}function gr(r,e,t,n){return new et(r,e,t,n)}0&&(module.exports={MessagingHubGraph,SubscriptionGraph,TopicBridgeGraph,TopicGraph,TopicRegistry,messagingHub,subscription,topic,topicBridge});
|
|
1
|
+
"use strict";var at=Object.defineProperty;var Rn=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var Sn=Object.prototype.hasOwnProperty;var L=(r,e)=>()=>(r&&(e=r(r=0)),e);var Dn=(r,e)=>{for(var t in e)at(r,t,{get:e[t],enumerable:!0})},Cn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of An(e))!Sn.call(r,s)&&s!==t&&at(r,s,{get:()=>e[s],enumerable:!(n=Rn(e,s))||n.enumerable});return r};var Mn=r=>Cn(at({},"__esModule",{value:!0}),r);function Fe(r){if(r==null)return me;let{type:e,id:t,...n}=r;return{type:e??"system",id:t??"",...n}}var me,ze=L(()=>{"use strict";me={type:"system",id:""}});function Re(){return be>0||ke}function Dt(){return be>0}function ve(r){be>0?Ee.push(r):r()}function ie(r){be+=1;let e=!1;try{r()}catch(t){throw e=!0,t}finally{if(be-=1,be===0)if(e){if(!ke){let t=Ee.splice(0);for(let n of t)try{n()}catch{}de.length=0,ce.length=0,ye.length=0}}else Gn()}}function Gn(){let r=!ke;r&&(ke=!0);let e=[],t=0;try{for(;de.length>0||ce.length>0||ye.length>0||r&&Ee.length>0;){if(r&&Ee.length>0){let o=Ee.splice(0);for(let i of o)try{i()}catch(a){e.push(a)}continue}if(t+=1,t>1e3)throw de.length=0,ce.length=0,ye.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let s=(de.length>0?de:ce.length>0?ce:ye).splice(0);for(let o of s)try{o()}catch(i){e.push(i)}}}finally{r&&(ke=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function Ae(r,e,t){if(e.length===0)return;if(e.length===1){let d=t(e[0][0]);if(d<3||!Re()){r(e);return}(d>=5?ye:d===4?ce:de).push(()=>r(e));return}let n=e.length,s=n,o=n,i=n,a=0;for(;a<n&&t(e[a][0])<3;)a++;for(s=a;a<n&&t(e[a][0])===3;)a++;for(o=a;a<n&&t(e[a][0])===4;)a++;i=a;let u=Re();if(s>0){let d=e.slice(0,s);r(d)}if(o>s){let d=e.slice(s,o);u?de.push(()=>r(d)):r(d)}if(i>o){let d=e.slice(o,i);u?ce.push(()=>r(d)):r(d)}if(n>i){let d=e.slice(i,n);u?ye.push(()=>r(d)):r(d)}}var be,ke,de,ce,ye,Ee,Se=L(()=>{"use strict";be=0,ke=!1,de=[],ce=[],ye=[],Ee=[]});function te(){return Math.trunc(performance.now()*1e6)}function _e(){return Date.now()*1e6}var De=L(()=>{"use strict"});var we,M,B,j,q,Q,ne,z,V,P,le,Ve,Ct,Be,Mt,Gt,He,ut,dt,ct,je,fe=L(()=>{"use strict";we=Symbol.for("graphrefly/START"),M=Symbol.for("graphrefly/DATA"),B=Symbol.for("graphrefly/DIRTY"),j=Symbol.for("graphrefly/RESOLVED"),q=Symbol.for("graphrefly/INVALIDATE"),Q=Symbol.for("graphrefly/PAUSE"),ne=Symbol.for("graphrefly/RESUME"),z=Symbol.for("graphrefly/TEARDOWN"),V=Symbol.for("graphrefly/COMPLETE"),P=Symbol.for("graphrefly/ERROR"),le=Object.freeze([B]),Ve=Object.freeze([j]),Ct=Object.freeze([q]),Be=Object.freeze([we]),Mt=Object.freeze([V]),Gt=Object.freeze([z]),He=Object.freeze([le]),ut=Object.freeze([Ve]),dt=Object.freeze([Ct]),ct=Object.freeze([Mt]),je=Object.freeze([Gt])});function It(r){r.registerMessageType(we,{tier:0,wireCrossing:!1}),r.registerMessageType(B,{tier:1,wireCrossing:!1}),r.registerMessageType(q,{tier:1,wireCrossing:!1,metaPassthrough:!1}),r.registerMessageType(Q,{tier:2,wireCrossing:!1}),r.registerMessageType(ne,{tier:2,wireCrossing:!1}),r.registerMessageType(M,{tier:3,wireCrossing:!0}),r.registerMessageType(j,{tier:3,wireCrossing:!0}),r.registerMessageType(V,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(P,{tier:4,wireCrossing:!0,metaPassthrough:!1}),r.registerMessageType(z,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var We,Pt=L(()=>{"use strict";fe();We=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 Lt(r){return Array.isArray(r)?[...r]:[r]}function In(r,e){return r.has(e)||r.has("*")}function $t(r){let e=[];return r((s,o)=>{e.push({kind:"allow",actions:new Set(Lt(s)),where:o?.where??(()=>!0)})},(s,o)=>{e.push({kind:"deny",actions:new Set(Lt(s)),where:o?.where??(()=>!0)})}),(s,o)=>{let i=!1,a=!1;for(let u of e)In(u.actions,o)&&u.where(s)&&(u.kind==="deny"?i=!0:a=!0);return i?!1:a}}function lt(r){let e=Pn.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 Y,Pn,Te=L(()=>{"use strict";Y=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}};Pn=["human","llm","wallet","system"]});function zt(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 s=2+t.length+2+e.length;if(s>4294967295)throw new Error(`encodeEnvelope: total envelope size ${s} exceeds 2^32-1 bytes (payload ${e.length} bytes)`);let o=new Uint8Array(s),i=0;return o[i++]=ft,o[i++]=t.length,o.set(t,i),i+=t.length,o[i++]=n>>>8&255,o[i++]=n&255,o.set(e,i),o}function Vt(r,e){if(r.length<Ft)throw new Error(`decodeEnvelope: bytes too short (${r.length} < ${Ft})`);let t=0,n=r[t++];if(n!==ft)throw new Error(`decodeEnvelope: unsupported envelope version ${n} (expected ${ft})`);let s=r[t++];if(s===0)throw new Error("decodeEnvelope: name_len must be >= 1");if(t+s+2>r.length)throw new Error(`decodeEnvelope: envelope truncated (need ${t+s+2} bytes, have ${r.length})`);let o=new TextDecoder().decode(r.subarray(t,t+s));t+=s;let i=(r[t]<<8|r[t+1])>>>0;t+=2;let a=r.subarray(t),u=e.lookupCodec(o);if(u==null)throw new Error(`decodeEnvelope: codec "${o}" not registered (envelope codec_v=${i})`);return{codec:u,codecVersion:i,payload:a}}function Bt(r){r.registerCodec(Ln)}var Ln,ft,Ft,pt=L(()=>{"use strict";Ln={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)}},ft=1,Ft=4});function ht(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(ht);if(typeof r=="object"&&r!==null){let e={};for(let t of Object.keys(r).sort())e[t]=ht(r[t]);return e}return null}function zn(r){let e=Fn.encode(r),t=e.length,n=t*8,s=t+9+63&-64,o=new Uint8Array(s);o.set(e),o[t]=128;let i=new DataView(o.buffer);i.setUint32(s-4,n>>>0,!1),i.setUint32(s-8,Math.floor(n/4294967296)>>>0,!1);let a=1779033703,u=3144134277,d=1013904242,l=2773480762,g=1359893119,f=2600822924,p=528734635,c=1541459225,y=new Uint32Array(64),h=(v,b)=>v>>>b|v<<32-b;for(let v=0;v<s;v+=64){for(let N=0;N<16;N++)y[N]=i.getUint32(v+N*4,!1);for(let N=16;N<64;N++){let A=y[N-15],D=y[N-2],S=h(A,7)^h(A,18)^A>>>3,oe=h(D,17)^h(D,19)^D>>>10;y[N]=y[N-16]+S+y[N-7]+oe>>>0}let b=a,_=u,w=d,x=l,m=g,T=f,k=p,R=c;for(let N=0;N<64;N++){let A=h(m,6)^h(m,11)^h(m,25),D=m&T^~m&k,S=R+A+D+$n[N]+y[N]>>>0,oe=h(b,2)^h(b,13)^h(b,22),ee=b&_^b&w^_&w,Le=oe+ee>>>0;R=k,k=T,T=m,m=x+S>>>0,x=w,w=_,_=b,b=S+Le>>>0}a=a+b>>>0,u=u+_>>>0,d=d+w>>>0,l=l+x>>>0,g=g+m>>>0,f=f+T>>>0,p=p+k>>>0,c=c+R>>>0}let O=v=>v.toString(16).padStart(8,"0");return O(a)+O(u)+O(d)+O(l)+O(g)+O(f)+O(p)+O(c)}function gt(r){let e=ht(r??null),t=JSON.stringify(e);return zn(t).slice(0,16)}function Vn(){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 mt(r,e,t){let n=t?.id??Vn();if(r===0)return{id:n,version:0};let o=(t?.hash??gt)(e);return{id:n,version:0,cid:o,prev:null}}function Ht(r,e,t){r.version+=1,"cid"in r&&(r.prev=r.cid,r.cid=t(e))}var $n,Fn,jt=L(()=>{"use strict";$n=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]),Fn=new TextEncoder});function Kt(r){return{node:r,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function bt(r){r.prevData=void 0,r.dirty=!1,r.involvedThisWave=!1,r.dataBatch.length=0,r.terminal=void 0}function Ue(r){return r.length===0?r:typeof r[0]=="symbol"?[r]:r}function re(r,e,t){let n=qt(r)?r:[],s=typeof r=="function"?r:typeof e=="function"?e:void 0,o={};return qt(r)?o=(yt(e)?e:t)??{}:yt(r)?o=r:o=(yt(e)?e:t)??{},new $(n,s,o)}var Wt,Ut,Bn,Hn,Oe,$,qt,yt,pe=L(()=>{"use strict";pt();ze();Se();De();Pt();Te();fe();jt();Wt=()=>{},Ut=100;Bn=(r,e,t,n)=>{t.direction==="down-in"&&r._onDepMessage(t.depIndex,e)},Hn=(r,e,t,n)=>{let s=r;if(s._status==="completed"||s._status==="errored")return;let o=s._cached,i=o===void 0?[Be]:[Be,[M,o]];s._status==="dirty"&&i.push(le),Ae(e,i,s._config.tierOf)},Oe=new We({onMessage:Bn,onSubscribe:Hn});It(Oe);Bt(Oe);$=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??Oe,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??gt;let s=n.versioning??this._config.defaultVersioning;this._versioningLevel=s,this._versioning=s!=null?mt(s,this._cached===void 0?void 0:this._cached,{id:n.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Kt);let o={};for(let[a,u]of Object.entries(n.meta??{})){let d={initial:u,name:`${n.name??"node"}:meta:${a}`,describeKind:"state",config:this._config};n.guard!=null&&(d.guard=n.guard),o[a]=new r([],void 0,d)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let i=this;this._actions={emit(a){i._emit([[M,a]])},down(a){i._emit(Ue(a))},up(a){i._emitUp(Ue(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 n=this._versioningLevel;if(n!=null&&e<=n)return;let s=t?.hash??this._hashFn;s!==this._hashFn&&(this._hashFn=s);let o=this._cached===void 0?void 0:this._cached,i=this._versioning,a=i?.id??t?.id,u=i?.version??0,d=mt(e,o,{id:a,hash:s});d.version=u,this._versioning=d,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=Fe(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 s=Fe(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(s,o))throw new Y({actor:s,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let i of this._extraGuards)if(!i(s,o))throw new Y({actor:s,action:o,nodeName:this.name})}this._lastMutation={actor:s,timestamp_ns:_e()}}down(e,t){let n=Ue(e);n.length!==0&&(this._checkGuard(t),this._emit(n))}emit(e,t){this._checkGuard(t),this._emit([[M,e]])}up(e,t){if(this._deps.length===0)return;let n=Ue(e);if(n.length===0)return;this._checkGuard(t);let s=t??{internal:!0};this._validateUpTiers(n);for(let o of this._deps)o.node.up?.(n,s)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let n of e){let s=t(n[0]);if(s===3||s===4)throw new Error(`Node "${this.name}": tier-${s} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let u=Fe(t);if(!this._guard(u,"observe"))throw new Y({actor:u,action:"observe",nodeName:this.name})}let s=this._isTerminal&&this._resubscribable;if(s){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let u of this._deps)bt(u);if(this._partial===!1){for(let u of this._deps)if(u.prevData!==void 0||u.dataBatch.length!==0||u.terminal!==void 0||u.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:s},this._actions)}catch(u){throw this._sinkCount-=1,u}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let i=this._isTerminal;if(this._sinkCount===1&&!i)try{this._activate()}catch(u){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw u}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let a=!1;return()=>{a||(a=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let n=0;n<e;n++){let s=n,o=this._deps[n];o.unsub=Wt,o.unsub=o.node.subscribe(i=>{if(o.unsub===null)return;let a=this._config.tierOf,u=!1;for(let d of i)a(d[0])>=3&&(u=!0),this._config.onMessage(this,d,{direction:"down-in",depIndex:s},this._actions);u&&this._maybeRunFnOnSettlement()}),t++}}catch(n){this._deps[t].unsub=null;for(let s=0;s<t;s++){let o=this._deps[s];if(o.unsub!=null){let i=o.unsub;o.unsub=null;try{i()}catch{}bt(o)}}throw this._dirtyDepCount=0,n}}_addDep(e){for(let s=0;s<this._deps.length;s++)if(this._deps[s].node===e)return s;let t=this._deps.length,n=Kt(e);if(this._deps.push(n),this._sinks==null)return t;n.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(He),n.unsub=Wt;try{n.unsub=e.subscribe(s=>{if(n.unsub===null)return;let o=this._config.tierOf,i=!1;for(let a of s)o(a[0])>=3&&(i=!0),this._config.onMessage(this,a,{direction:"down-in",depIndex:t},this._actions);i&&this._maybeRunFnOnSettlement()})}catch(s){throw n.unsub=null,this._deps.pop(),this._dirtyDepCount--,s}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(n){this._emit([[P,this._wrapFnError("cleanup threw",n)]])}else if(t!=null&&typeof t=="object"){let n=t.deactivate;if(typeof n=="function")try{n()}catch(s){this._emit([[P,this._wrapFnError("cleanup.deactivate threw",s)]])}}for(let n of this._deps){if(n.unsub!=null){let s=n.unsub;n.unsub=null;try{s()}catch{}}bt(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],s=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let i of this._inspectorHooks)i(o)}if(s!==we){if(s===B){this._depDirtied(n);return}if(s===q){if(this._depInvalidated(n),this._cached===void 0)return;this._emit(dt);return}if(s===Q||s===ne){this._emit([t]);return}if(s===z){this._emit(je);return}if(s===M)this._depSettledAsData(n,t[1]);else if(s===j)this._depSettledAsResolved(n);else if(s===V)this._depSettledAsTerminal(n,!0);else if(s===P)this._depSettledAsTerminal(n,t[1]);else{this._emit([t]);return}if(!this._fn){(s===M||s===j)&&this._emit([t]),(s===V||s===P)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(He))}_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(ut),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([[P,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(ct)}_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([[P,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([[P,this._wrapFnError("cleanup.beforeRun threw",a)]]);return}}}let t=this._deps.map(i=>i.involvedThisWave?i.dataBatch.length>0?[...i.dataBatch]:[]:void 0),n=this._deps.map(i=>i.prevData);for(let i=0;i<this._deps.length;i++){let a=t[i];a!=null&&a.length>0&&(this._deps[i].prevData=a[a.length-1])}let s=this._deps.map(i=>i.terminal),o={prevData:n,terminalDeps:s,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let i={kind:"run",batchData:t,prevData:n};for(let a of this._inspectorHooks)a(i)}this._isExecutingFn=!0;try{let i=this._fn(t,this._actions,o);if(typeof i=="function")this._cleanup=i;else if(i!=null&&typeof i=="object"){let a=i;(typeof a.beforeRun=="function"||typeof a.deactivate=="function"||typeof a.invalidate=="function")&&(this._cleanup=i)}}catch(i){this._emit([[P,this._wrapFnError("fn threw",i)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Ut?(this._rerunDepth=0,this._emit([[P,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Ut} \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"?[le,e[0]]:e;let n=!0,s=!1,o=!1,i=-1;for(let u of e){let d=t(u[0]);d<i&&(n=!1),d===3&&(s=!0),u[0]===B&&(o=!0),i=d}let a=e;if(!n){let u=e.map((d,l)=>({m:d,i:l,tier:t(d[0])}));u.sort((d,l)=>d.tier-l.tier||d.i-l.i),a=u.map(d=>d.m)}if(s&&!o&&this._status!=="dirty"){let u=0;for(;u<a.length&&t(a[u][0])===0;)u++;return u===0?[le,...a]:[...a.slice(0,u),le,...a.slice(u)]}return a}_emit(e){if(e.length===0)return;for(let a=0;a<e.length;a++){let u=e[a];if(u[0]===P&&u[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let a=e.filter(u=>u[0]===z||u[0]===q);if(a.length===0)return;t=a}t=this._frameBatch(t);let s=null;for(let a=0;a<t.length;a++){let u=t[a],d=u[0];if(d!==Q&&d!==ne){s?.push(u);continue}if(u.length<2)throw new Error(`Node "${this.name}": [[${d===Q?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let l=!0;if(this._pausable!==!1){let g=u[1];if(d===Q)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(g),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(g))l=!1;else if(this._pauseLocks.delete(g),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let f=this._pauseBuffer;this._pauseBuffer=[],this._emit(f)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}l?s?.push(u):s==null&&(s=t.slice(0,a))}if(s!=null){if(s.length===0)return;t=s}if(this._hasMeta&&t.some(a=>a[0]===z))for(let a of Object.keys(this.meta))try{this.meta[a]._emit(je)}catch{}let{finalMessages:o,equalsError:i}=this._updateState(t);if(o.length>0&&this._config.inspectorEnabled){let a=this._config.globalInspector;if(a!=null)try{a({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let a=this._config.tierOf,u=[];for(let d of o)a(d[0])===3?this._pauseBuffer.push(d):u.push(d);u.length>0&&this._dispatchOrAccumulate(u)}else this._dispatchOrAccumulate(o);i!=null&&this._emit([[P,i]])}_updateState(e){let t=this._config.tierOf,n,s,o=-1,i=0;for(let l of e)t(l[0])===3&&i++;let a=i<=1,u=-1;if(this._versioning!=null&&i>1){for(let l=e.length-1;l>=0;l--)if(e[l][0]===M){u=l;break}}for(let l=0;l<e.length;l++){let g=e[l],f=g[0];if(f===M){if(g.length>=2){let p=!1;if(a&&this._cached!==void 0)try{p=this._equals(this._cached,g[1])}catch(c){s=this._wrapFnError("equals threw",c),o=l;break}if(p){n==null&&(n=e.slice(0,l)),n.push(Ve),this._status="resolved";continue}this._cached=g[1],this._versioning!=null&&(u<0||l===u)&&Ht(this._versioning,g[1],this._hashFn)}this._status="settled",n?.push(g)}else if(n?.push(g),f===B)this._status="dirty";else if(f===j)this._status="resolved";else if(f===V){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(f===P){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(f===q){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 p=this._cleanup;if(typeof p=="function"){this._cleanup=void 0;try{p()}catch{}}else if(p!=null&&typeof p=="object"){let c=p.invalidate;if(typeof c=="function")try{c()}catch{}}}else f===z&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let d=o>=0?n??e.slice(0,o):n??e;return s!=null?{finalMessages:d,equalsError:s}:{finalMessages:d}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let n of t)n(e)};_dispatchOrAccumulate(e){if(Dt()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],ve(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}Ae(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);Ae(this._deliverToSinks,t,this._config.tierOf)}},qt=r=>Array.isArray(r),yt=r=>typeof r=="object"&&r!=null&&!Array.isArray(r)});function vt(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 jn(r){return r._describeKind!=null?r._describeKind:r._deps.length>0?"derived":r._fn!=null?"producer":"state"}function Wn(r){let e={};for(let[t,n]of Object.entries(r.meta))try{e[t]=n.cache}catch{}return e}function _t(r,e,t){let n=e==null,s=!n&&e!=null?[...e].filter(l=>l.startsWith("meta.")).map(l=>l.slice(5)):null,o=n||e.has("meta")||s!=null&&s.length>0,i="state",a=[];r instanceof $&&(i=jn(r),a=r._deps.map(l=>l.node.name??""));let u={type:i,deps:a};(n||e.has("status"))&&(u.status=r.status);let d=r instanceof $?r._guard:void 0;if(o){let l={...Wn(r)};if(d!=null&&l.access===void 0&&(l.access=lt(d)),s!=null&&s.length>0&&!e.has("meta")){let g={};for(let f of s)f in l&&(g[f]=l[f]);u.meta=g}else u.meta=l}if(r.name!=null&&(u.name=r.name),(n||e.has("value"))&&(!t||i==="state")){r.status==="sentinel"&&(u.sentinel=!0);try{u.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),u.v=l}return(n||e.has("guard"))&&d!=null&&(u.guard=lt(d)),(n||e.has("lastMutation"))&&r.lastMutation!=null&&(u.lastMutation=r.lastMutation),u}var Yt=L(()=>{"use strict";Te();pe()});function J(r,e){return re([],{...e,initial:r})}function Ke(r,e){return re((n,s,o)=>r(s,o)??void 0,{describeKind:"producer",...e})}function W(r,e,t){return re(r,(s,o,i)=>{let a=s.map((u,d)=>u!=null&&u.length>0?u.at(-1):i.prevData[d]);o.emit(e(a,i))},{describeKind:"derived",...t})}var qe=L(()=>{"use strict";pe()});function Jt(r,e,t){return{[r]:!0,[`${r}_type`]:e,...t??{}}}var Xt=L(()=>{"use strict"});function wt(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 o=0;o<r.length;o++)if(!wt(r[o],e[o]))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 s=new Set(n);for(let o of t)if(!s.has(o)||!wt(r[o],e[o]))return!1;return!0}function Zt(r,e){return`${r}\0${e}`}function Tt(r,e){let t=[],n=new Set(r.subgraphs),s=new Set(e.subgraphs),o=[];for(let h of s)n.has(h)||o.push(h);o.sort();for(let h of o)t.push({type:"subgraph-mounted",path:h});let i=new Set(Object.keys(r.nodes)),a=new Set(Object.keys(e.nodes)),u=[];for(let h of a)i.has(h)||u.push(h);u.sort();for(let h of u)t.push({type:"node-added",path:h,node:{...e.nodes[h]}});let d=[];for(let h of a){if(!i.has(h))continue;let O=r.nodes[h]?.meta,v=e.nodes[h]?.meta;O==null&&v==null||wt(O??{},v??{})||d.push(h)}d.sort();for(let h of d)t.push({type:"node-meta-changed",path:h,prevMeta:r.nodes[h]?.meta??{},nextMeta:e.nodes[h]?.meta??{}});let l=new Map;for(let h of r.edges)l.set(Zt(h.from,h.to),h);let g=new Map;for(let h of e.edges)g.set(Zt(h.from,h.to),h);let f=[];for(let[h,O]of g)l.has(h)||f.push(O);f.sort((h,O)=>h.from<O.from?-1:h.from>O.from?1:h.to<O.to?-1:h.to>O.to?1:0);for(let h of f)t.push({type:"edge-added",from:h.from,to:h.to});let p=[];for(let[h,O]of l)g.has(h)||p.push(O);p.sort((h,O)=>h.from<O.from?-1:h.from>O.from?1:h.to<O.to?-1:h.to>O.to?1:0);for(let h of p)t.push({type:"edge-removed",from:h.from,to:h.to});let c=[];for(let h of i)a.has(h)||c.push(h);c.sort();for(let h of c)t.push({type:"node-removed",path:h});let y=[];for(let h of n)s.has(h)||y.push(h);y.sort();for(let h of y)t.push({type:"subgraph-unmounted",path:h});return{events:t,flushedAt_ns:te()}}var Qt=L(()=>{"use strict";De()});function X(r){return r.subscribe(()=>{})}var en=L(()=>{"use strict"});var Ot=L(()=>{"use strict";en()});var Ye,tn=L(()=>{"use strict";Ye=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 Ce,nn=L(()=>{"use strict";Ce=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 rn(r,e,t,n={}){let s=e in r.nodes,o=t in r.nodes;if(!s)return Je(e,t,"no-such-from");if(!o)return Je(e,t,"no-such-to");let i=n.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(n.findCycle===!0){let d=Un(r,e,n);if(d!=null)return d}let u=Xe(e,r.nodes[e],0,n);return Ze(e,t,[u])}if(i===0)return Je(e,t,"no-path");let a=sn(r,e,t,i);return a.found?Ze(e,t,on(r,a.pathOrder,n)):Je(e,t,a.truncated?"max-depth-exceeded":"no-path")}function sn(r,e,t,n){let s=new Map,o=[{path:t,depth:0}],i=new Set([t]),a=0,u=!1;for(;a<o.length;){let g=o[a++];if(g.path===e)break;if(n!=null&&g.depth>=n){let y=r.nodes[g.path];y?.deps&&y.deps.length>0&&(u=!0);continue}let f=r.nodes[g.path];if(f==null)continue;let p=f.deps??[],c=new Map;for(let y=0;y<p.length;y++){let h=p[y];if(!h)continue;let O=c.get(h);O==null&&(O=[],c.set(h,O)),O.push(y)}for(let[y,h]of c)i.has(y)||(i.add(y),s.set(y,{from:g.path,depIndices:h}),o.push({path:y,depth:g.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:u};let d=[{path:e}],l=e;for(;l!==t;){let g=s.get(l);if(g==null)return{found:!1,pathOrder:[],truncated:!1};d[d.length-1].depIndices=g.depIndices,d.push({path:g.from}),l=g.from}return{found:!0,pathOrder:d,truncated:!1}}function Un(r,e,t){let n=r.nodes[e];if(n==null)return null;let s=n.deps??[],o=[];for(let a=0;a<s.length;a++)s[a]===e&&o.push(a);if(o.length>0){let a=Xe(e,n,0,t);a.dep_index=o[0];let u=Xe(e,n,1,t);return Ze(e,e,[a,u])}let i=null;for(let a=0;a<s.length;a++){let u=s[a];if(!u||u===e)continue;let d=sn(r,u,e,t.maxDepth);d.found&&(i==null||d.pathOrder.length<i.pathOrder.length)&&(i=d,i={found:!0,pathOrder:[{path:e,depIndices:[a]},...d.pathOrder],truncated:!1})}return i==null?null:Ze(e,e,on(r,i.pathOrder,t))}function on(r,e,t){return e.map((n,s)=>{let o=r.nodes[n.path],i=Xe(n.path,o,s,t);return n.depIndices!=null&&n.depIndices.length>0&&(i.dep_index=n.depIndices[0],n.depIndices.length>1&&(i.dep_indices=[...n.depIndices])),i})}function Xe(r,e,t,n){let s={path:r,type:e.type,hop:t};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let o=n.annotations?.get(r)??e.annotation;o!=null&&(s.annotation=o);let i=n.lastMutations?.get(r)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function Ze(r,e,t){return an(r,e,!0,"ok",t)}function Je(r,e,t){return an(r,e,!1,t,[])}function an(r,e,t,n,s){let o=Kn(r,e,t,n,s);return{from:r,to:e,found:t,reason:n,steps:s,text:o,toJSON(){return{from:r,to:e,found:t,reason:n,steps:s}}}}function Kn(r,e,t,n,s){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 o=[`Causal path: ${r} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let u=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(o.push(u),"value"in i&&o.push(` value: ${qn(i.value)}`),i.annotation!=null&&o.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let d=i.lastMutation.actor;o.push(` actor: ${d.type}${d.id?`:${d.id}`:""}`)}}return o.join(`
|
|
2
|
+
`)}function qn(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)}}var un=L(()=>{"use strict"});function dn(r){let e=new WeakSet,t=new WeakSet,n=[r],s=0;for(;n.length>0;){let o=n.pop();s+=Jn(o,e,t,n)}return s}function Jn(r,e,t,n){if(r==null)return 0;switch(typeof r){case"number":return F.number;case"boolean":return F.boolean;case"string":return F.string+r.length*2;case"bigint":return F.bigint+Xn(r);case"symbol":return F.symbol;case"function":return e.has(r)?0:(e.add(r),F.function);case"undefined":return 0}let o=r;if(e.has(o))return 0;e.add(o);let i=o[Yn];if(typeof i=="function")try{let d=i.call(o);if(typeof d=="number"&&Number.isFinite(d))return d}catch{}if(o instanceof Date)return F.date;if(o instanceof RegExp)return F.regexp+o.source.length*2;if(o instanceof Error){let d=o.message?o.message.length*2:0,l=o.stack?o.stack.length*2:0;return F.error+d+l}if(typeof URL<"u"&&o instanceof URL)return F.url+o.href.length*2;if(typeof Promise<"u"&&o instanceof Promise)return F.promise;if(o instanceof WeakMap)return F.weakmap;if(o instanceof WeakSet)return F.weakset;if(o instanceof Map){let d=F.map;for(let[l,g]of o)d+=F.mapEntry,n.push(l),n.push(g);return d}if(o instanceof Set){let d=F.set;for(let l of o)d+=F.setEntry,n.push(l);return d}if(Array.isArray(o)){let d=F.array+o.length*8;for(let l of o)n.push(l);return d}if(o instanceof ArrayBuffer)return t.has(o)?0:(t.add(o),o.byteLength);if(ArrayBuffer.isView(o)){let d=o;return t.has(d.buffer)?48:(t.add(d.buffer),d.buffer.byteLength+48)}let a=F.object,u=Object.keys(o);for(let d of u){a+=F.string+d.length*2;try{n.push(o[d])}catch{}}return a}function Xn(r){let e=r<0n?-r:r;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}var F,Yn,cn=L(()=>{"use strict";F={object:56,array:64,string:40,number:8,boolean:4,null:0,undefined:0,symbol:40,bigint:16,function:120,map:72,set:72,mapEntry:40,setEntry:24,date:24,regexp:48,error:64,url:80,promise:48,weakmap:40,weakset:40},Yn=Symbol.for("sizeof")});function ln(r,e){let t=e?.topN??10,n=r.describe({detail:"standard"}),s=[],o=r._collectObserveTargets;typeof o=="function"&&o.call(r,"",s);let i=new Map;for(let[f,p]of s)i.set(f,p);let a=[];for(let[f,p]of Object.entries(n.nodes)){let c=i.get(f),y=c instanceof $?c:null,h=y?dn(y.cache):0,O=y?y._sinkCount:0,v=p.deps?.length??0,b=p.type==="effect"&&O===0,_=O===0?p.type==="effect"?"orphan-effect":p.type==="derived"?"idle-derived":p.type==="producer"?"idle-producer":null:null;a.push({path:f,type:p.type,status:p.status??"unknown",valueSizeBytes:h,subscriberCount:O,depCount:v,isOrphanEffect:b,orphanKind:_})}let u=a.reduce((f,p)=>f+p.valueSizeBytes,0),d=(f,p)=>[...a].sort(p??((c,y)=>y[f]-c[f])).slice(0,t),l=a.filter(f=>f.orphanKind!=null),g=a.filter(f=>f.isOrphanEffect);return{nodeCount:a.length,edgeCount:n.edges.length,subgraphCount:n.subgraphs.length,nodes:a,totalValueSizeBytes:u,hotspots:{byValueSize:d("valueSizeBytes"),bySubscriberCount:d("subscriberCount"),byDepCount:d("depCount")},orphans:l,orphanEffects:g}}var fn=L(()=>{"use strict";pe();cn()});function pn(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 s=r.values().next();if(s.done)return;let o=s.value;r.delete(o);try{o()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function yn(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function Zn(r){if(r!=null)return yn(r)?r.cache:r}function ge(r){return r!=null&&typeof r=="object"&&"cache"in r&&typeof r.subscribe=="function"&&typeof r.down=="function"}function ae(r){return ge(r)?r.cache??"":r}function hn(r){return ge(r)?r.cache??0:r}function gn(r){return ge(r)?r.cache??!1:r}function Qn(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 mn(r){if(r.version!==he)throw new Error(`unsupported snapshot version ${String(r.version)} (expected ${he})`);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 er(r,e){let t=new WeakMap,n=(s,o)=>{if(Object.is(s,o))return!0;if(s==null||o==null||typeof s!="object"||typeof o!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(o))return!0;i.add(o);let a=s.constructor,u=o.constructor;if(a!==u)return!1;if(s instanceof Date)return s.getTime()===o.getTime();if(s instanceof RegExp)return s.source===o.source&&s.flags===o.flags;if(Array.isArray(s)){let f=o;if(s.length!==f.length)return!1;for(let p=0;p<s.length;p++)if(!n(s[p],f[p]))return!1;return!0}if(s instanceof Map){let f=o;if(s.size!==f.size)return!1;for(let[p,c]of s)if(!f.has(p)||!n(c,f.get(p)))return!1;return!0}if(s instanceof Set){let f=o;if(s.size!==f.size)return!1;for(let p of s){let c=!1;for(let y of f)if(n(p,y)){c=!0;break}if(!c)return!1}return!0}if(ArrayBuffer.isView(s)){let f=s,p=o;if(f.length!==p.length)return!1;for(let c=0;c<f.length;c++)if(f[c]!==p[c])return!1;return!0}let d=Object.keys(s),l=Object.keys(o);if(d.length!==l.length)return!1;let g=new Set(l);for(let f of d)if(!g.has(f)||!n(s[f],o[f]))return!1;return!0};return n(r,e)}function tr(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qe(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 s=r.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let o=r.slice(t+1,s);o.startsWith("!")&&(o=`^${o.slice(1)}`),o=o.replace(/\\/g,"\\\\"),e+=`[${o}]`,t=s;continue}e+=tr(n)}return e+="$",new RegExp(e)}function Nt(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 sr(r){return r==="none"?rr:r==="ansi"||r==null?nr:{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 bn(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 or(r,e,t){for(let n=0;n<r.length;n++){let s=r.charCodeAt(n);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${r}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function xt(r,e,t){if(r==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(r.includes(I))throw new Error(`Graph "${e}": ${t} "${r}" must not contain '${I}' (path separator)`);if(r===Z)throw new Error(`Graph "${e}": ${t} name "${Z}" is reserved for meta companion paths`);or(r,e,t)}function ir(r,e){if(r==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=r.split(I);for(let n of t)if(n==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function ar(r,e){let t=!1;for(let s of r)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?r.filter(s=>e.isMetaPassthrough(s[0])):r}function vn(r){for(let e of r._mounts.values())vn(e);for(let e of r._nodes.values())try{e.down([[z]],{internal:!0})}catch{}}function _n(r,e){let t=se.diff(r,e),n={};for(let s of t.nodesAdded){let o=e.nodes[s];o!=null&&(n[s]=o)}return{...t,nodesAddedFull:n}}function kt(r,e,t,n={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return n.withDetail?s:[];if(!n.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let o=n.maxDepth;if(o!=null&&(!Number.isInteger(o)||o<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(o===0)return n.withDetail?s:[];let i=new Map,a=new Map,u=new Map,d=new Map,l=new Set;for(let[b,_]of Object.entries(r.nodes)){if(!b)continue;l.add(b);let w=_.deps??[];i.set(b,w);for(let x of w)x&&(l.add(x),a.has(x)||a.set(x,new Set),a.get(x).add(b))}for(let b of r.edges){if(b==null||typeof b!="object")continue;let _=typeof b.from=="string"?b.from:"",w=typeof b.to=="string"?b.to:"";!_||!w||(l.add(_),l.add(w),d.has(_)||d.set(_,new Set),d.get(_).add(w),u.has(w)||u.set(w,new Set),u.get(w).add(_))}if(!l.has(e))return n.withDetail?s:[];let g=n.both===!0,f=b=>{if(g){let m=i.get(b)??[],T=u.get(b),k=a.get(b),R=d.get(b),N=[...m];return T&&N.push(...T),k&&N.push(...k),R&&N.push(...R),N}if(t==="upstream"){let m=i.get(b)??[],T=u.get(b);return T?[...m,...T]:m}let _=a.get(b),w=d.get(b),x=_?[..._]:[];return w&&x.push(...w),x},p=new Set([e]),c=new Map,y=[{path:e,depth:0}],h=0,O=!1;for(;h<y.length;){let b=y[h++];if(o!=null&&b.depth>=o){f(b.path).length>0&&(O=!0);continue}for(let _ of f(b.path))!_||p.has(_)||(p.add(_),c.set(_,b.depth+1),y.push({path:_,depth:b.depth+1}))}let v=[...c.keys()].sort((b,_)=>b<_?-1:b>_?1:0);return n.withDetail?{paths:v,depths:c,truncated:O}:v}function ur(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++){let n=r[t],s=e[t];if(n.path!==s.path||n.type!==s.type||n.status!==s.status||n.hop!==s.hop||n.dep_index!==s.dep_index||n.annotation!==s.annotation||n.value!==s.value||n.lastMutation!==s.lastMutation)return!1;let o=n.v,i=s.v;if(o!==i&&(o==null||i==null||o.id!==i.id||o.version!==i.version))return!1}return!0}var I,Z,he,nr,rr,se,wn=L(()=>{"use strict";ze();Se();De();Te();fe();Yt();pe();qe();Qt();Ot();tn();nn();pt();un();fn();I="::",Z="__meta__",he=1;nr={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"},rr={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};se=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(I))throw new Error(`Graph name must not contain '${I}' (got "${e}")`);if(e===Z)throw new Error(`Graph name "${Z}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??Oe,this._traceRing=new Ce(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=Ke(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,s=t?.name??n;if(s==null||s==="")throw new Error(`Graph "${this.name}": graph.add requires a non-empty name \u2014 pass via opts.name or set it on the node (e.g. state(0, { name: "x" }))`);let o=s,i=t?.annotation;if(xt(o,this.name,"add"),this._mounts.has(o))throw new Error(`Graph "${this.name}": name "${o}" is already a mount point`);if(this._nodes.has(o))throw new Error(`Graph "${this.name}": node "${o}" already exists`);let a=this._nodeToName.get(e);if(a!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${a}"`);return this._nodes.set(o,e),this._nodeToName.set(e,o),this._emitTopology({kind:"added",name:o,nodeKind:"node"}),i!=null&&(this._annotations.set(o,i),this.config.inspectorEnabled&&this._traceRing.push({path:o,annotation:i,timestamp_ns:te()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof $&&t._applyVersioning(e)}remove(e){xt(e,this.name,"remove");let t=this._mounts.get(e);if(t){let o={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[a,u]of i)a.includes(`${I}${Z}${I}`)||o.nodes.push(a);return o.nodes.sort(),o.mounts.push(e),o.mounts.push(...t._collectSubgraphs(`${e}${I}`)),this._mounts.delete(e),t._parent=void 0,vn(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:o}),o}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([[z]],{internal:!0});let s={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:s}),s}removeAll(e){let t=typeof e=="function"?e:(()=>{let o=Qe(e);return i=>o.test(i)})(),n={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(o=>t(o));for(let o of s){let i=this.remove(o);n.nodes.push(...i.nodes),n.mounts.push(...i.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=e.length)return{value:void 0,done:!0};let s=e[n++];return{value:[s,t.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes(I))return this.resolve(e);let t=this._nodes.get(e);if(!t)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return t}get(e){return this.node(e).cache}set(e,t,n){let s=n?.internal===!0;this.node(e).down([[M,t]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);ie(()=>{for(let[s,o]of n)this.set(s,o,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[q]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let s=n?.internal===!0;this.node(e).down([[P,t]],{actor:n?.actor,internal:s,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[V]],{actor:t?.actor,internal:n,delivery:"write"})}edges(e){let t=e?.recursive===!0,n=new Map;if(!t){for(let[u,d]of this._nodes)n.set(d,u);let a=[];for(let[u,d]of this._nodes)if(d instanceof $)for(let l of d._deps){let g=n.get(l.node);g!=null&&a.push([g,u])}return a.sort((u,d)=>u[0]<d[0]?-1:u[0]>d[0]?1:u[1]<d[1]?-1:u[1]>d[1]?1:0),a}let s=[];this._collectObserveTargets("",s);let o=new Map;for(let[a,u]of s)o.set(u,a);let i=[];for(let[a,u]of s)if(u instanceof $)for(let d of u._deps){let l=o.get(d.node);l!=null&&i.push([l,a])}return i.sort((a,u)=>a[0]<u[0]?-1:a[0]>u[0]?1:a[1]<u[1]?-1:a[1]>u[1]?1:0),i}mount(e,t){if(t===void 0){let s=new r(e);return this.mount(e,s)}if(typeof t=="function"){let s=new r(e);return t(s),this.mount(e,s)}let n=t;if(xt(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 s=this;s!=null;s=s._parent)if(s===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=ir(e,this.name);return this._resolveFromSegments(t)}tryResolve(e){try{return this.resolve(e)}catch{return}}_resolveFromSegments(e){let t=e;if(t[0]===this.name&&(t=t.slice(1),t.length===0))throw new Error(`Graph "${this.name}": resolve path ends at graph name only`);let n=t[0],s=t.slice(1);if(s.length===0){let a=this._nodes.get(n);if(a)return a;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let o=this._nodes.get(n);if(o&&s.length>0&&s[0]===Z)return this._resolveMetaChainFromNode(o,s,t.join(I));let i=this._mounts.get(n);if(!i)throw this._nodes.has(n)?new Error(`Graph "${this.name}": "${n}" is a node; trailing path "${s.join(I)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return i.resolve(s.join(I))}_resolveMetaChainFromNode(e,t,n){let s=e,o=0,i=[...t];for(;o<i.length;){if(i[o]!==Z)throw new Error(`Graph "${this.name}": expected ${Z} segment in meta path "${n}"`);if(o+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${Z} in "${n}"`);let a=i[o+1],u=s.meta[a];if(!u)throw new Error(`Graph "${this.name}": unknown meta "${a}" in path "${n}"`);s=u,o+=2}return s}signal(e,t){if(t?.internal!==!0){for(let s of e)if(this.config.messageTier(s[0])===3)throw new Error(`Graph "${this.name}": Graph.signal() rejects tier-3 messages (DATA / RESOLVED). Broadcast is for control-plane tiers (START / DIRTY / INVALIDATE / PAUSE / RESUME / COMPLETE / ERROR / TEARDOWN). For per-node value writes, use Graph.set or graph.node(name).down(...).`)}let n=[];if(this._signalDeliver(e,t??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(e,t,n,s){for(let u of this._mounts.values())u._signalDeliver(e,t,n,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},a=ar(e,this.config);for(let u of[...this._nodes.keys()].sort()){let d=this._nodes.get(u);if(!n.has(d)){n.add(d);try{d.down(e,i)}catch(l){if(l instanceof Y)throw l;s.push(l)}a.length!==0&&this._signalMetaSubtree(d,a,n,i,s)}}}_signalMetaSubtree(e,t,n,s,o){for(let i of Object.keys(e.meta).sort()){let a=e.meta[i];if(!n.has(a)){n.add(a);try{a.down(t,s)}catch(u){if(u instanceof Y)throw u;o.push(u)}this._signalMetaSubtree(a,t,n,s,o)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=Zn(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 s=vt(e?.detail,e?.fields),o=e?.detail==="spec",i=s,a=[];this._collectObserveTargets("",a);let u=new Map;for(let[_,w]of a)u.set(w,_);let d=[];{let _=a.map(([,m])=>m),w=new Set(u.values()),x=0;for(;_.length>0;){let m=_.shift();if(m instanceof $)for(let T of m._deps){let k=T.node;if(u.has(k))continue;let R=k.name??"",N=R;if(!N||w.has(N))if(R){let A=2;for(;w.has(`${R}#${A}`);)A++;N=`${R}#${A}`}else for(N=`__internal__/${x++}`;w.has(N);)N=`__internal__/${x++}`;u.set(k,N),w.add(N),d.push([N,k]),_.push(k)}}}let l=[...a,...d],g={};for(let[_,w]of l){if(t!=null&&!w.allowsObserve(t))continue;let x=_t(w,i,o),m=w instanceof $?w._deps.map(N=>u.get(N.node)??N.node.name??""):[],{name:T,...k}=x,R={...k,deps:m};if(!o){let N=this._annotations.get(_);N!=null&&(R.annotation=N)}if(n!=null)if(typeof n=="function"){let N=n;if(!(N.length>=2?N(_,R):N(R)))continue}else{let N=!0;for(let[A,D]of Object.entries(n)){let S=A==="deps_includes"?"depsIncludes":A==="meta_has"?"metaHas":A;if(S==="depsIncludes"){if(!R.deps.includes(String(D))){N=!1;break}continue}if(S==="metaHas"){if(!Object.hasOwn(R.meta??{},String(D))){N=!1;break}continue}if(R[S]!==D){N=!1;break}}if(!N)continue}g[_]=R}let f=new Set(Object.keys(g)),p=[];for(let[_,w]of l)if(w instanceof $)for(let x of w._deps){let m=u.get(x.node);m!=null&&p.push([m,_])}p.sort((_,w)=>_[0]<w[0]?-1:_[0]>w[0]?1:_[1]<w[1]?-1:_[1]>w[1]?1:0);let c=p.map(([_,w])=>({from:_,to:w}));(t!=null||n!=null)&&(c=c.filter(_=>f.has(_.from)&&f.has(_.to)));let y=this._collectSubgraphs(""),h=t!=null||n!=null?y.filter(_=>{let w=`${_}${I}`;return[...f].some(x=>x===_||x.startsWith(w))}):y,O=this,v=e;return{name:this.name,nodes:g,edges:c,subgraphs:h,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(_){let w={...v};return Array.isArray(_)?(w.fields=_,w.detail=void 0):(w.detail=_,w.fields=void 0),O.describe(w)}}}_collectSubgraphs(e){let t=[];for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${n}`;t.push(s),t.push(...this._mounts.get(n)._collectSubgraphs(`${s}${I}`))}return t}resourceProfile(e){return ln(this,e)}reachable(e,t,n={}){return n.withDetail===!0?kt(this.describe(),e,t,{...n,withDetail:!0}):kt(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(ae(e),ae(t),{...n?.maxDepth!==void 0?{maxDepth:hn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:gn(n.findCycle)}:{}})}_explainStatic(e,t,n){let s=this.describe({detail:"full"}),o=new Map(this._annotations),i=new Map;for(let[a,u]of Object.entries(s.nodes))u.lastMutation!=null&&i.set(a,u.lastMutation);return rn(s,e,t,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:o,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},n=e.reactiveName??"describe",s=0,o=J(s,{name:`${n}_version`}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ve(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(v=>{let b=v.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[],f=new WeakSet,p=v=>{if(f.has(v)||u)return;f.add(v);let b=v.topology.subscribe(_=>{for(let w of _){if(w[0]!==M)continue;let x=w[1];if(d(),x.kind==="added"&&x.nodeKind==="mount"){let m=v._mounts.get(x.name);m!=null&&p(m)}}});g.push(b);for(let _ of v._mounts.keys()){let w=v._mounts.get(_);w!=null&&p(w)}};p(this);let c,y=e.actor;yn(y)&&(c=y.subscribe(v=>{let b=!1,_=!1;for(let w of v){let x=w[0];x===M?b=!0:(x===V||x===P||x===z)&&(_=!0)}b&&d(),_&&(c?.(),c=void 0,d())}));let h;try{h=W([o],()=>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 g)b();throw i.dispose(),v}let O=X(h);return{node:h,dispose(){u=!0,l(),c?.();for(let v of g)v();g.length=0,i.dispose(),O()}}}_describeReactiveDiff(e){let t={...e,reactive:!1},n=e.reactiveName??"describe-diff",s={name:this.name,nodes:{},edges:[],subgraphs:[]},o=this.describe(t),i=Tt(s,o),a=J(i,{name:n,meta:{domain:"audit",kind:"describe-diff"},equals:(f,p)=>f===p}),u=this._describeReactive({...e,reactiveName:void 0}),d=!1,l=u.node.subscribe(f=>{if(!d)for(let p of f){if(p[0]!==M)continue;let c=p[1],y=Tt(o,c);o=c,y.events.length!==0&&a.emit(y)}}),g=X(a);return{node:a,dispose(){d=!0,l(),u.dispose(),a.down([[z,"describe-diff disposed"]]),g()}}}_explainReactive(e,t,n){let s=0,o=J(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),a=!1,u=!1,d=()=>{a||u||(a=!0,ve(()=>{a=!1,!u&&(s+=1,o.emit(s))}))},l=i.onEvent(v=>{let b=v.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||d()}),g=[];e!=null&&ge(e)&&g.push(e),t!=null&&ge(t)&&g.push(t),n?.maxDepth!=null&&ge(n.maxDepth)&&g.push(n.maxDepth),n?.findCycle!=null&&ge(n.findCycle)&&g.push(n.findCycle);let f=()=>{for(let v of g)if(v.cache===void 0)return!1;return!0},p=()=>{let v=ae(e),b=ae(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=W([o],()=>{if(!f())return p();let v=ae(e),b=ae(t),_={...n?.maxDepth!==void 0?{maxDepth:hn(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:gn(n.findCycle)}:{}};return this._explainStatic(v,b,_)},{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:ae(e),to:ae(t)},equals:(v,b)=>v.found===b.found&&v.reason===b.reason&&v.steps.length===b.steps.length&&ur(v.steps,b.steps)})}catch(v){throw l(),i.dispose(),v}let y=X(c),h=[],O=v=>{let b;return b=v.subscribe(_=>{let w=!1,x=!1;for(let m of _){let T=m[0];T===M?w=!0:(T===V||T===P||T===z)&&(x=!0)}(w||x)&&d(),x&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let v of g)h.push(O(v));return{node:c,dispose(){u=!0,l();for(let v of h)v?.();h.length=0,i.dispose(),y()}}}_pathsMatching(e){let t=Qe(e),n=[];return this._collectObserveTargets("",n),n.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${I}${n}`;this._mounts.get(n)._collectObserveTargets(s,t)}for(let n of[...this._nodes.keys()].sort()){let s=this._nodes.get(n),o=e===""?n:`${e}${I}${n}`;t.push([o,s]),this._appendMetaObserveTargets(o,s,t)}}_appendMetaObserveTargets(e,t,n){for(let s of Object.keys(t.meta).sort()){let o=t.meta[s],i=`${e}${I}${Z}${I}${s}`;n.push([i,o]),this._appendMetaObserveTargets(i,o,n)}}observe(e,t){let n=typeof e=="string",o=bn(n?t:e);if(o.reactive===!0)return this._observeReactive(n?e:void 0,o);let i=o.structured===!0||o.timeline===!0||o.causal===!0||o.derived===!0||o.detail==="minimal"||o.detail==="full"||o.format!=null,a=o.actor;if(n){let l=e,g=this.resolve(l);if(a!=null&&!g.allowsObserve(a))throw new Y({actor:a,action:"observe",nodeName:l});return i?this._buildStructuredObserver([[l,g]],o,"one"):{subscribe(f){return g.subscribe(f)},up(f){try{g.up?.(f)}catch(p){if(p instanceof Y)return;throw p}}}}let u=[];this._collectObserveTargets("",u),u.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let d=a==null?u:u.filter(([,l])=>l.allowsObserve(a));return i?this._buildStructuredObserver(d,o,"all"):{subscribe:l=>{let g=d.map(([f,p])=>p.subscribe(c=>{l(f,c)}));return()=>{for(let f of g)f()}},up:(l,g)=>{try{this.resolve(l).up?.(g)}catch(f){if(f instanceof Y)return;throw f}}}}_observeReactive(e,t){let n=t.tiers,s=n!=null?new Set(n):null,o=t.reactiveName??"observe";return Ke(i=>{let a=[],u=!1,d=!1,l=()=>{if(a.length===0||d)return;let y={events:a.slice(),flushedAt_ns:te()};a.length=0,i.emit(y)},g={...t,reactive:!1,structured:!0,timeline:!0},f=e!=null?this.observe(e,g):this.observe(g),p=y=>{d||(a.push(y),!u&&(u=!0,ve(()=>{u=!1,l()})))};for(let y of f.events)p(y);let c=f.onEvent(p);return()=>{d=!0,c(),f.dispose()}},{name:o,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,n){let s=n==="one"?e[0]?.[0]:void 0,o=i=>{if(n==="one"&&s!=null){let l=this.resolve(s);return this._buildStructuredObserver([[s,l]],i,"one")}let a=[];this._collectObserveTargets("",a),a.sort((l,g)=>l[0]<g[0]?-1:l[0]>g[0]?1:0);let u=i.actor,d=u==null?a:a.filter(([,l])=>l.allowsObserve(u));return this._buildStructuredObserver(d,i,"all")};return this._createObserveResult(e,t,o)}_createObserveResult(e,t,n){let s=t.timeline===!0,o=t.causal===!0,i=t.derived===!0,a=t.detail==="minimal",u=this.config.inspectorEnabled,d=(o||i)&&u,l=t.maxEvents,g=l!=null&&l>0?new Ce(l):null,f=[],p=new Set,c=t.tiers!=null?new Set(t.tiers):null,y={},h=new Set,O=0,v=0,b=0,_=0,w=0,x=0,m=!1,T=!1,k=0,R=new Map,N=new Map,A=new Map,D=E=>{if(!(c!=null&&!c.has(E.type))){g?g.push(E):f.push(E);for(let G of p)G(E)}},S=E=>c==null||c.has(E),oe=()=>s?{timestamp_ns:te(),in_batch:Re(),batch_id:k}:{},ee=(E,G)=>{if(!(!d||!(E instanceof $)))return E._setInspectorHook(U=>{if(U.kind==="dep_message")R.set(E,U.depIndex);else if(U.kind==="run"){let xe=U.batchData.map((C,H)=>C!=null&&C.length>0?C.at(-1):U.prevData[H]);N.set(E,xe);let K=U.batchData.map(C=>C!=null?[...C]:void 0);A.set(E,K),i&&D({type:"derived",path:G,dep_values:xe,dep_batches:K,...oe()})}})},Le=E=>{let G=R.get(E),U=N.get(E);if(!o||U==null)return{};let K=(G!=null&&G>=0&&E instanceof $?E._deps[G]:void 0)?.node,C=K?.v,H=A.get(E);return{trigger_dep_index:G,trigger_dep_name:K?.name,...C!=null?{trigger_version:{id:C.id,version:C.version}}:{},dep_values:[...U],...H!=null?{dep_batches:H}:{}}},Rt=[],At=[];for(let[E,G]of e){let U=ee(G,E);U&&Rt.push(U),At.push(G.subscribe(xe=>{k++;for(let K of xe){let C=K[0],H=oe();if(C===M){y[E]=K[1];let it=G instanceof $?G.lastMutation?.actor??me:me;D({type:"data",path:E,data:K[1],actor:it,...H,...Le(G)})}else if(a)C===B?S("dirty")&&O++:C===j?S("resolved")&&v++:C===q?S("invalidate")&&b++:C===Q?S("pause")&&_++:C===ne?S("resume")&&w++:C===z?S("teardown")&&x++:C===V&&!h.has(E)?S("complete")&&(m=!0):C===P&&S("error")&&(T=!0,h.add(E));else if(C===B)S("dirty")&&O++,D({type:"dirty",path:E,...H});else if(C===j)S("resolved")&&v++,D({type:"resolved",path:E,...H,...Le(G)});else if(C===q)S("invalidate")&&b++,D({type:"invalidate",path:E,...H});else if(C===Q)S("pause")&&_++,D({type:"pause",path:E,lockId:K[1],...H});else if(C===ne)S("resume")&&w++,D({type:"resume",path:E,lockId:K[1],...H});else if(C===V)S("complete")&&!h.has(E)&&(m=!0),D({type:"complete",path:E,...H});else if(C===P){S("error")&&(T=!0,h.add(E));let it=G instanceof $?G.lastMutation?.actor??me:me;D({type:"error",path:E,data:K[1],actor:it,...H})}else C===z&&(S("teardown")&&x++,D({type:"teardown",path:E,...H}))}}))}let rt=!1,st=()=>{if(!rt){rt=!0;for(let E of At)E();for(let E of Rt)E();for(let E of $e)E({value:void 0,done:!0});$e.length=0}},ot=[],$e=[];p.add(E=>{let G=$e.shift();G?G({value:E,done:!1}):ot.push(E)});let St={get values(){return y},get dirtyCount(){return O},get resolvedCount(){return v},get invalidateCount(){return b},get pauseCount(){return _},get resumeCount(){return w},get teardownCount(){return x},get events(){return g?g.toArray():[...f]},get anyCompletedCleanly(){return m},get anyErrored(){return T},get completedWithoutErrors(){return m&&!T},onEvent(E){return p.add(E),()=>p.delete(E)},dispose:st,expand(E){st();let G={...t};return typeof E=="string"?G.detail=E:Object.assign(G,E),n(bn(G))},[Symbol.asyncIterator](){return{next(){return ot.length>0?Promise.resolve({value:ot.shift(),done:!1}):rt?Promise.resolve({value:void 0,done:!0}):new Promise(E=>$e.push(E))},return(){return st(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(St,t),St}_attachFormatLogger(e,t){let n=t.format;if(n==null)return;let s=t.logger??(c=>console.log(c)),o=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,a=o==null&&i==null?()=>!0:c=>(o==null||o.has(c))&&(i==null||!i.has(c)),u=sr(t.theme),d=n==="stage-log"?te():0,l=c=>c==null?"":t.stageLabels?.[c]??c,g=(c,y)=>c.length>y?`${c.slice(0,y-1)}\u2026`:c,f=c=>c.type==="data"||c.type==="error"?g(Nt(c.data),120):"",p=c=>{if(n==="stage-log"){let m=(te()-d)/1e9,T=l(c.path).padEnd(9);if(c.type==="data"){let k=f(c);return`[${m.toFixed(3)}s] ${T} \u2190${k?` ${k}`:""}`}if(c.type==="error"){let k=f(c);return`[${m.toFixed(3)}s] ${T} \u2717${k?` ${k}`:""}`}return c.type==="complete"?`[${m.toFixed(3)}s] ${T} \u25A0 complete`:`[${m.toFixed(3)}s] ${T} ${c.type}`}if(n==="json")try{return JSON.stringify(c)}catch{return JSON.stringify({type:c.type,path:c.path,data:"[unserializable]"})}let y=u[c.type]??"",h=c.path?`${u.path}${c.path}${u.reset} `:"",O=c.type==="data"||c.type==="error",v=c.type==="pause"||c.type==="resume",b=O?` ${Nt(c.data)}`:v?` ${Nt(c.lockId)}`:"",_=c.type==="data"||c.type==="resolved"||c.type==="derived"?c:void 0,w=_?.trigger_dep_name!=null?` <- ${_.trigger_dep_name}`:_?.trigger_dep_index!=null?` <- #${_.trigger_dep_index}`:"",x=c.in_batch?" [batch]":"";return`${h}${y}${c.type.toUpperCase()}${u.reset}${b}${w}${x}`};e.onEvent(c=>{a(c.type)&&s(p(c),c)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){pn(this._disposers,this.name),this.signal([[z]],{internal:!0}),pn(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"}),s={};for(let a of Object.keys(n.nodes).sort()){let{lastMutation:u,guard:d,...l}=n.nodes[a];s[a]=l}let o=[...n.subgraphs].sort(),i={...n,version:1,nodes:s,subgraphs:o};if(e?.format==null)return i;if(e.format==="json-string")return JSON.stringify(i);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let a=this.config.lookupCodec(e.codec);if(a==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return zt(a,a.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??Oe,{codec:s,codecVersion:o,payload:i}=Vt(e,n);return s.decode(i,o)}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 n=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(o=>Qe(o)),s=t?.includeProducers===!0;for(let o of Object.keys(e.nodes).sort()){if(n!==null&&!n.some(a=>a.test(o)))continue;let i=e.nodes[o];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(o,new Error(`restore: slice.value is undefined for "${o}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!s)){if(i.v!=null){let u=this.tryResolve(o)?.v;if(u!=null&&u.id===i.v.id&&u.version===i.v.version)continue}try{this.set(o,i.value)}catch(a){t?.onError?.(o,a)}}}}}static fromSnapshot(e,t){mn(e);let n=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,o=new r(e.name);if(n)return n(o),o.restore(e),o;for(let p of[...e.subgraphs].sort((c,y)=>{let h=c.split(I).length,O=y.split(I).length;return h!==O?h-O:c<y?-1:c>y?1:0})){let c=p.split(I),y=o;for(let h of c)y._mounts.has(h)||y.mount(h,new r(h)),y=y._mounts.get(h)}let i=s?Object.entries(s).map(([p,c])=>({re:Qe(p),factory:c})):[],a=p=>{for(let c of i)if(c.re.test(p))return c.factory},u=p=>{let c=p.split(I),y=c.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${p}"`);let h=o;for(let O of c){let v=h._mounts.get(O);if(!v)throw new Error(`unknown mount "${O}" in path "${p}"`);h=v}return[h,y]},d=Object.entries(e.nodes).filter(([p])=>!p.includes(`${I}${Z}${I}`)).sort((p,c)=>p[0]<c[0]?-1:p[0]>c[0]?1:0),l=new Map(d),g=new Map,f=!0;for(;l.size>0&&f;){f=!1;for(let[p,c]of[...l.entries()]){let y=c?.deps??[];if(!y.every(w=>g.has(w)))continue;let[h,O]=u(p),v={...c?.meta??{}},b=a(p),_;if(c?.type==="state")_=J(c.value,{meta:v});else{if(b==null)continue;_=b(O,{path:p,type:c.type,value:c.value,meta:v,deps:y,resolvedDeps:y.map(w=>g.get(w))})}h.add(_,{name:O}),g.set(p,_),l.delete(p),f=!0}}if(l.size>0){let p=[...l.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 o.restore(e),o}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let n=e.map(d=>({tier:d,debounceMs:Math.max(0,d.debounceMs??0),compactEvery:Math.max(1,d.compactEvery??10),timer:void 0,seq:0,lastSnapshot:void 0,lastFingerprint:"",disposed:!1,savePending:void 0}));t.autoRestore===!0&&this._cascadeRestore(e,t.onError);let s=(d,l)=>{if(d.disposed)return;let g=Qn(l.nodes);if(d.lastSnapshot!=null&&g!==""&&g===d.lastFingerprint)return;let f=d.seq+1,p=_e(),h=d.lastSnapshot==null||f%d.compactEvery===0?{name:this.name,mode:"full",snapshot:l,seq:f,timestamp_ns:p,format_version:he}:{name:this.name,mode:"diff",diff:_n(d.lastSnapshot,l),seq:f,timestamp_ns:p,format_version:he};if(d.tier.filter&&!d.tier.filter(h))return;let O;try{O=d.tier.save(h)}catch(v){t.onError?.(v,d.tier);return}if(O&&typeof O.then=="function"){let _=(d.savePending??Promise.resolve()).then(()=>O,()=>O).then(()=>{d.disposed||(d.seq=f,d.lastSnapshot=l,d.lastFingerprint=g)},w=>{t.onError?.(w,d.tier)});d.savePending=_.finally(()=>{d.savePending===_&&(d.savePending=void 0)})}else d.seq=f,d.lastSnapshot=l,d.lastFingerprint=g},o=(d,l)=>{try{s(d,l)}catch(g){t.onError?.(g,d.tier)}},i=(d,l)=>{if(!l.some(c=>{let y=this.config.messageTier(c[0]);return y>=3&&y<5}))return;if(t.filter){let c=this.tryResolve(d);if(c==null)return;let y=_t(c,vt("standard"));if(!t.filter(d,y))return}let f,p=()=>(f==null&&(f=this.snapshot()),f);for(let c of n)c.disposed||(c.debounceMs===0?o(c,p()):(c.timer==null&&(c.timer=new Ye),c.timer.start(c.debounceMs,()=>{c.disposed||o(c,this.snapshot())})))},a;if(t.paths!=null){let l=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(g=>{let f=this.tryResolve(g);return f==null?()=>{}:f.subscribe(p=>i(g,p))});a=()=>{for(let g of l)g()}}else a=this.observe().subscribe((d,l)=>i(d,l));let u=()=>{a();for(let d of n)d.disposed=!0,d.timer?.cancel();this._storageDisposers.delete(u)};return this._storageDisposers.add(u),{dispose:u}}async _cascadeRestore(e,t){for(let n of e){let s;try{s=await n.load?.()}catch(i){t?.(i,n);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let o=s;try{if(o.mode==="full"&&o.snapshot!=null)return this.restore(o.snapshot),!0;if(o.version===he&&o.nodes!=null)return this.restore(o),!0}catch(i){t?.(i,n)}}return!1}static async fromStorage(e,t,n){for(let s of t){let o;try{o=await s.load?.()}catch(u){n?.onError?.(u,s);continue}if(o==null||typeof o!="object"||Array.isArray(o))continue;let i=o,a=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===he&&i.nodes!=null?i:void 0;if(a!=null)try{return r.fromSnapshot(a,n)}catch(u){n?.onError?.(u,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${t.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,t,n){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let s={path:e,annotation:t,timestamp_ns:te(),...n?.actor!=null?{actor:n.actor}:{}};this._traceRing.push(s)}return}return e!=null?this.config.inspectorEnabled?this._annotations.get(e):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(e){return this._annotations.get(e)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(e){let t=this._traceRing.toArray().filter(s=>!e(s)),n=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return n}static diff(e,t){let n=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),o=[...s].filter(v=>!n.has(v)).sort(),i=[...n].filter(v=>!s.has(v)).sort(),a=[],u=[];for(let v of n){if(!s.has(v))continue;let b=e.nodes[v],_=t.nodes[v],w=b.v,x=_.v;w!=null&&x!=null&&w.id===x.id&&w.version!==x.version&&u.push({path:v,id:w.id,from:w.version,to:x.version});let m=w!=null&&x!=null&&w.id===x.id&&w.version===x.version;for(let T of["type","status","sentinel"]){let k=b[T],R=_[T];k!==R&&a.push({path:v,field:T,from:k,to:R})}if(!m)for(let T of["value","meta"]){let k=b[T],R=_[T];er(k,R)||a.push({path:v,field:T,from:k,to:R})}}let d=v=>`${v.from} ${v.to}`,l=new Set(e.edges.map(d)),g=new Set(t.edges.map(d)),f=t.edges.filter(v=>!l.has(d(v))),p=e.edges.filter(v=>!g.has(d(v))),c=new Set(e.subgraphs),y=new Set(t.subgraphs),h=[...y].filter(v=>!c.has(v)).sort(),O=[...c].filter(v=>!y.has(v)).sort();return{nodesAdded:o,nodesRemoved:i,nodesChanged:a,versionChanges:u,edgesAdded:f,edgesRemoved:p,subgraphsAdded:h,subgraphsRemoved:O}}}});var kn=L(()=>{"use strict";wn()});var br={};Dn(br,{MessagingHubGraph:()=>nt,SubscriptionGraph:()=>Pe,TopicBridgeGraph:()=>et,TopicGraph:()=>Ie,TopicRegistry:()=>tt,messagingHub:()=>gr,subscription:()=>En,topic:()=>hr,topicBridge:()=>mr});module.exports=Mn(br);ze();Se();Te();fe();qe();pe();Xt();De();Te();fe();Se();fe();pe();qe();var Et=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),s=e.length-n;for(let o=0;o<n;o++)this._buf[o]=e[s+o];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),s=Math.min(e,this._size);if(s>=n)return[];let o=n-s;if(this._maxSize===void 0)return this._buf.slice(s,n);let i=new Array(o);for(let a=0;a<o;a++)i[a]=this._buf[(this._head+s+a)%this._maxSize];return i}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 o=0;o<t;o++)this._buf[o]=void 0;this._head=0;let n=Math.min(e.length,t),s=e.length-n;for(let o=0;o<n;o++)this._buf[o]=e[s+o];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 Me(r){return r.subscribe(()=>{})}var dr=64;function Tn(r,e={}){let{name:t,maxSize:n,versioning:s,guard:o,backend:i}=e,a=i??new Et(r,n),u=J(a.toArray(),{name:t,describeKind:"state",equals:(m,T)=>m===T,...s!=null?{versioning:s}:{},...o!=null?{guard:o}:{}});function d(){let m=a.toArray();ie(()=>{u.down([[B]],{internal:!0}),u.down([[M,m]],{internal:!0})})}let l=new Map,g=new Map,f=new Map;function p(m,T){return`${m}:${T===void 0?"END":T}`}function c(m){if(m.size<dr)return;let T=m.keys().next();if(T.done)return;let k=m.get(T.value);k!==void 0&&k.dispose(),m.delete(T.value)}function y(m){let T=a.version;try{return m()}finally{a.version!==T&&d()}}function h(m){if(!Number.isInteger(m)||m<0)throw new RangeError(`tail: n must be a non-negative integer (got ${m})`);let T=l.get(m);if(T!==void 0)return l.delete(m),l.set(m,T),T.node;c(l);let k=W([u],([N])=>{let A=N;return m===0||A.length===0?[]:A.slice(Math.max(0,A.length-m))},{initial:a.tail(m),describeKind:"derived"}),R=Me(k);return l.set(m,{node:k,dispose:R}),k}function O(m,T){if(!Number.isInteger(m)||m<0)throw new RangeError(`slice: start must be a non-negative integer (got ${m})`);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 k=p(m,T),R=g.get(k);if(R!==void 0)return g.delete(k),g.set(k,R),R.node;c(g);let N=W([u],([D])=>{let S=D;return T===void 0?S.slice(m):S.slice(m,T)},{initial:a.slice(m,T),describeKind:"derived"}),A=Me(N);return g.set(k,{node:N,dispose:A}),N}function v(m){let T=f.get(m);if(T!==void 0)return T.node;let k=W([u,m],([N,A])=>{let D=N,S=Math.max(0,Math.trunc(A??0));return D.slice(S)},{initial:[],describeKind:"derived"}),R=Me(k);return f.set(m,{node:k,dispose:R}),k}let b,_;function w(){b===void 0&&(b=re([u],(m,T,k)=>{let R=m[0],A=R!=null&&R.length>0?R.at(-1):k.prevData[0];if(A==null||A.length===0){T.down([[j]]);return}T.emit(A[A.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:a.size===0?void 0:a.at(a.size-1)}),_=W([u],([m])=>m.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:a.size>0}),Me(b),Me(_))}let x={entries:u,get size(){return a.size},at(m){return a.at(m)},append(m){y(()=>a.append(m))},appendMany(m){m.length!==0&&y(()=>a.appendMany(m))},clear(){y(()=>a.clear())},trimHead(m){y(()=>a.trimHead(m))},withLatest(){return w(),u},get lastValue(){return w(),b},get hasLatest(){return w(),_},view(m){switch(m.kind){case"tail":return h(m.n);case"slice":return O(m.start,m.stop);case"fromCursor":return v(m.cursor)}},attach(m){let T=m.subscribe(k=>{for(let R of k)R[0]===M&&x.append(R[1])});return()=>T()},attachStorage(m){if(m.length===0)return()=>{};let T=new Map;for(let R of m)T.set(R,a.size);(async()=>{for(let R of m)if(typeof R.loadEntries=="function")try{let N=await Promise.resolve(R.loadEntries());N.entries.length>0&&a.size===0&&(a.restore(N.entries),T.set(R,N.entries.length),d());break}catch{}})();let k=u.subscribe(R=>{for(let N of R){if(N[0]!==M)continue;let A=N[1];for(let D of m){let S=T.get(D)??0;if(A.length<S){try{let ee=D.appendEntries(A);ee instanceof Promise&&ee.catch(()=>{})}catch{}T.set(D,A.length);continue}if(A.length===S)continue;let oe=A.slice(S);T.set(D,A.length);try{let ee=D.appendEntries(oe);ee instanceof Promise&&ee.catch(()=>{})}catch{}}}});return()=>k()},disposeAllViews(){for(let m of l.values())m.dispose();l.clear();for(let m of g.values())m.dispose();g.clear();for(let m of f.values())m.dispose();f.clear()},dispose(){for(let m of l.values())m.dispose();l.clear();for(let m of g.values())m.dispose();g.clear();for(let m of f.values())m.dispose();f.clear()}};return x}var Is=$t((r,e)=>{r("observe"),r("signal"),e("write")});function xn(r){if(r===null||typeof r!="object"||Object.isFrozen(r))return r;for(let e of Object.keys(r))xn(r[e]);return Object.freeze(r)}var On=new WeakSet;function cr(r){let e=r.cache,t=typeof e=="number"&&Number.isFinite(e);!t&&e!==void 0&&!On.has(r)&&(On.add(r),console.warn(`bumpCursor: cursor cache held a non-numeric value (${String(e)}); resetting to 0. Causes include: a snapshot codec round-tripping the cursor as a string / null / NaN, OR a malformed initial seed (e.g. state<number>(NaN)). Audit consumers may see colliding seq values after this point.`));let s=(t?e:0)+1;return r.down([[B],[M,s]]),s}function Nn(r,e,t,n,s,o){let i=e(t,n,s);if(i===void 0)return;let a=o!=null?{...i,handlerVersion:o}:i;r.append(a)}function Ge(r,e){let t=e.freeze??!0;return function(...s){let o=t?s.map(xn):s,i=_e(),a=e.seq?cr(e.seq):void 0;try{let u=r(...o);return e.audit&&e.onSuccess&&Nn(e.audit,e.onSuccess,o,u,{t_ns:i,seq:a},e.handlerVersion),u}catch(u){if(e.audit&&e.onFailure){let d=u instanceof Error?u.name:typeof u;Nn(e.audit,e.onFailure,o,u,{t_ns:i,seq:a,errorType:d},e.handlerVersion)}throw u}}}Ot();kn();var lr=256;function Ne(r,e){if(!Number.isFinite(r)||!Number.isInteger(r)||r<0)throw new Error(`${e} must be a non-negative integer`);return r}function ue(r,e){return Jt("messaging",r,e)}var fr=1024,Ie=class extends se{_log;_publishImpl;events;latest;hasLatest;constructor(e,t={}){super(e,t.graph),this._log=Tn([],{name:"events",maxSize:t.retainedLimit??fr}),this._log.withLatest(),this.events=this._log.entries,this.add(this.events,{name:"events"}),this.latest=W([this.events],([n])=>{let s=n;return s.length===0?null:s[s.length-1]},{name:"latest",describeKind:"derived",meta:ue("topic_latest")}),this.add(this.latest,{name:"latest"}),this.addDisposer(X(this.latest)),this.hasLatest=W([this.events],([n])=>n.length>0,{name:"hasLatest",describeKind:"derived",meta:ue("topic_has_latest")}),this.add(this.hasLatest,{name:"hasLatest"}),this.addDisposer(X(this.hasLatest)),this.addDisposer(()=>{this.events.down([[V]])}),this.addDisposer(()=>this._log.disposeAllViews()),this._publishImpl=Ge(n=>{this._log.append(n)},{freeze:!1})}publish(e){if(e===void 0)throw new TypeError(`TopicGraph "${this.name}": publish(undefined) is not allowed (spec \xA75.12 SENTINEL).`);this._publishImpl(e)}attachEventStorage(e){return this._log.attachStorage(e)}retained(){return this.events.cache}get _logBundle(){return this._log}},Pe=class extends se{cursor;available;topic;_disposed=!1;_ackImpl;_pullAndAckImpl;constructor(e,t,n={}){super(e,n.graph),this.topic=t;let s;if(n.from!==void 0?n.from==="retained"?s=0:n.from==="now"?s=t.events.cache.length:s=Ne(n.from,"subscription from"):s=Ne(n.cursor??0,"subscription cursor"),this.cursor=J(s,{name:"cursor",describeKind:"state",meta:ue("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(X(this.available)),n.advanceOn!==void 0){let o=n.advanceOn,i=!1,a=re([o],()=>{if(!i){i=!0;return}if(this._disposed)return;let u=this.available.cache;if(u.length===0)return;let d=this.cursor.cache+u.length;this.cursor.emit(d)},{name:"advancePump",describeKind:"effect",meta:ue("subscription_advance_pump")});this.add(a,{name:"advancePump"}),this.addDisposer(X(a))}this._ackImpl=Ge(o=>{let i=this.available.cache,a=o===void 0?i.length:Ne(o,"subscription ack count"),u=Math.min(a,i.length);if(u<=0)return this.cursor.cache;let d=this.cursor.cache+u;return this.cursor.emit(d),d},{freeze:!1}),this._pullAndAckImpl=Ge(o=>{let i=this.available.cache,a=o===void 0?i.length:Ne(o,"subscription pullAndAck limit"),u=i.slice(0,a);if(u.length===0)return{items:u,cursor:this.cursor.cache};let d=this.cursor.cache+u.length;return this.cursor.emit(d),{items:u,cursor:d}},{freeze:!1})}ack(e){return this._disposed?this.cursor.cache:this._ackImpl(e)}pull(e){if(this._disposed)return[];let t=this.available.cache,n=e===void 0?t.length:Ne(e,"subscription pull limit");return t.slice(0,n)}pullAndAck(e){return this._disposed?{items:[],cursor:this.cursor.cache}:this._pullAndAckImpl(e)}dispose(){this._disposed||(this._disposed=!0,this.cursor.down([[V]]),this.destroy())}},et=class extends se{_sourceSub;bridgedCount;output;constructor(e,t,n,s={}){super(e,s.graph),this._sourceSub=En(`${e}-subscription`,t,{cursor:s.cursor}),this.mount("subscription",this._sourceSub);let o=Math.max(1,Ne(s.maxPerPump??lr,"topic bridge maxPerPump")),i=s.map??(f=>f);this.output=W([this._sourceSub.available],([f])=>{let p=f,c=[],y=Math.min(p.length,o);for(let h=0;h<y;h++){let O=i(p[h]);O!==void 0&&c.push(O)}return c},{name:"output",describeKind:"derived",meta:ue("topic_bridge_output",{targetRef:n.name}),initial:[]}),this.add(this.output,{name:"output"}),this.addDisposer(X(this.output)),this.bridgedCount=J(0,{name:"bridgedCount",describeKind:"state",meta:ue("topic_bridge_count")}),this.add(this.bridgedCount,{name:"bridgedCount"}),this.addDisposer(X(this.bridgedCount));let a=this.output,u=this._sourceSub,d=this.bridgedCount,l=re([a],()=>{let f=a.cache;if(f.length===0)return;let p=u.available.cache.length,c=Math.min(p,o);if(c>0){u.ack(c);let y=d.cache??0;d.emit(y+f.length)}},{name:"ackPump",describeKind:"effect",meta:ue("topic_bridge_ack_pump")});this.add(l,{name:"ackPump"}),this.addDisposer(X(l));let g=pr(this.output,n);this.addDisposer(g)}};function pr(r,e){return r.subscribe(t=>{for(let n of t){if(n[0]!==M)continue;let s=n[1];s.length!==0&&ie(()=>{for(let o of s)e.publish(o)})}})}var tt=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()}},nt=class extends se{_registry;version;_defaultTopicOptions;_removeTopicImpl;constructor(e,t={}){super(e,t.graph);let n=J(0,{name:"version",describeKind:"state",meta:ue("hub_version")});this.add(n,{name:"version"}),this.version=n,this._registry=new tt(n),this._defaultTopicOptions={...t.defaultTopicOptions??{}},this._removeTopicImpl=Ge(s=>{try{this.remove(s)}finally{this._registry.delete(s);let o=this.version.cache??0;this.version.emit(o+1)}},{freeze:!1})}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 s={...this._defaultTopicOptions,...t??{}};n=new Ie(e,s),this._registry.set(e,n),this.mount(e,n);let o=this.version.cache??0;this.version.emit(o+1)}return n}publish(e,t){this.topic(e).publish(t)}publishMany(e){ie(()=>{for(let[t,n]of e)this.topic(t).publish(n)})}subscribe(e,t,n){let s=this.topic(t);return new Pe(e,s,n)}removeTopic(e){return this._registry.has(e)?(this._removeTopicImpl(e),!0):!1}};function hr(r,e){return new Ie(r,e)}function gr(r,e){return new nt(r,e)}function En(r,e,t){return new Pe(r,e,t)}function mr(r,e,t,n){return new et(r,e,t,n)}0&&(module.exports={MessagingHubGraph,SubscriptionGraph,TopicBridgeGraph,TopicGraph,TopicRegistry,messagingHub,subscription,topic,topicBridge});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i}from"../../chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i}from"../../chunk-OYJKFY7V.js";import"../../chunk-4I45FVQS.js";import"../../chunk-FDQGFWLF.js";import"../../chunk-L6NSJVJZ.js";import"../../chunk-KVV66NN2.js";import"../../chunk-3G5U5QNE.js";import"../../chunk-C72GO4IZ.js";import"../../chunk-626TESAC.js";import"../../chunk-ESMPEKEV.js";import"../../chunk-35JTVPOX.js";import"../../chunk-JQFH2DV6.js";import"../../chunk-V5A7M7RJ.js";import"../../chunk-LYCLF26R.js";import"../../chunk-CK2E7BTU.js";import"../../chunk-QYADASLV.js";export{e as MessagingHubGraph,b as SubscriptionGraph,c as TopicBridgeGraph,a as TopicGraph,d as TopicRegistry,g as messagingHub,h as subscription,f as topic,i as topicBridge};
|