@graphrefly/graphrefly 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cascading-g2_rhhaM.d.ts → cascading-BNfxffgc.d.ts} +1 -1
- package/dist/{cascading-BzuxW0_w.d.cts → cascading-Cxs1eztH.d.cts} +1 -1
- package/dist/chunk-2W553JJC.js +1 -0
- package/dist/{chunk-5LK7XMEV.js → chunk-33N4TU3X.js} +1 -1
- package/dist/chunk-4MKL6Q3K.js +1 -0
- package/dist/chunk-5B3JDG5F.js +1 -0
- package/dist/chunk-5QSXEMXG.js +1 -0
- package/dist/{chunk-R75BMDLA.js → chunk-5TEFC2ZX.js} +1 -1
- package/dist/chunk-5TOPVRN6.js +1 -0
- package/dist/{chunk-INHC33EH.js → chunk-5VEZLQFN.js} +1 -1
- package/dist/{chunk-NQI2C36M.js → chunk-7PQLZMOG.js} +1 -1
- package/dist/{chunk-7NZMZJMW.js → chunk-AI7QC7J6.js} +1 -1
- package/dist/{chunk-L7WY6TZS.js → chunk-AK5RHMC5.js} +1 -1
- package/dist/{chunk-ZOX3LBRV.js → chunk-CGNOWGV6.js} +1 -1
- package/dist/{chunk-INH6FS2G.js → chunk-CYOSWFT2.js} +1 -1
- package/dist/{chunk-GX5LSSRE.js → chunk-EC2WNSZ7.js} +1 -1
- package/dist/{chunk-HAWKGIXM.js → chunk-ELAASRBT.js} +1 -1
- package/dist/{chunk-7QFRK3N3.js → chunk-F7VUYPP6.js} +1 -1
- package/dist/{chunk-LQNOXGET.js → chunk-G3M3IMEV.js} +1 -1
- package/dist/{chunk-HX3EGQ5Z.js → chunk-GI4Q7PNY.js} +1 -1
- package/dist/{chunk-XQ55HO5N.js → chunk-H5SCWHWP.js} +1 -1
- package/dist/{chunk-CGDMTXSY.js → chunk-KNVCCBIU.js} +1 -1
- package/dist/{chunk-IA7DUNGB.js → chunk-L77I47VU.js} +1 -1
- package/dist/{chunk-JNMC2WJ6.js → chunk-M3FQSXEW.js} +1 -1
- package/dist/{chunk-D47YVDR5.js → chunk-OLIKJUKI.js} +1 -1
- package/dist/{chunk-SC7BQDNP.js → chunk-OV5AA6HJ.js} +1 -1
- package/dist/{chunk-7JRF5YEK.js → chunk-POXANAJ6.js} +1 -1
- package/dist/chunk-RSMEXK53.js +43 -0
- package/dist/{chunk-KD4NHLMU.js → chunk-SC27WTSG.js} +1 -1
- package/dist/chunk-TSOYJ743.js +1 -0
- package/dist/{chunk-AU7YTQX7.js → chunk-TT4C7DXW.js} +1 -1
- package/dist/{chunk-TFPZLQ5H.js → chunk-UISPDFJ3.js} +1 -1
- package/dist/{chunk-N7UIBZCW.js → chunk-URJ2VFNC.js} +1 -1
- package/dist/{chunk-GEAO3TL3.js → chunk-VV62MIG4.js} +1 -1
- package/dist/{chunk-VJJLIEAL.js → chunk-VXPLLA4P.js} +1 -1
- package/dist/{chunk-WHIZM6JV.js → chunk-WZYB3JQS.js} +1 -1
- package/dist/{chunk-S2U57TFC.js → chunk-X7QKTXXC.js} +1 -1
- package/dist/{chunk-7SD73DS6.js → chunk-YQRN4CIV.js} +1 -1
- package/dist/chunk-Z6X7B6A4.js +61 -0
- package/dist/{chunk-RF3QZP6D.js → chunk-ZAJ7J7TO.js} +1 -1
- package/dist/compat/index.d.cts +6 -6
- package/dist/compat/index.d.ts +6 -6
- package/dist/compat/index.js +1 -1
- package/dist/compat/nestjs/index.d.cts +4 -4
- package/dist/compat/nestjs/index.d.ts +4 -4
- package/dist/compat/nestjs/index.js +1 -1
- package/dist/compat/zustand/index.d.cts +2 -2
- package/dist/compat/zustand/index.d.ts +2 -2
- package/dist/compat/zustand/index.js +1 -1
- package/dist/{composite-DGatA-JK.d.ts → decay-BnrlbxSv.d.ts} +38 -2
- package/dist/{composite-CKd0e2vz.d.cts → decay-C25AyNAj.d.cts} +38 -2
- package/dist/extra/index.cjs +15 -15
- package/dist/extra/index.d.cts +6 -6
- package/dist/extra/index.d.ts +6 -6
- 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.d.cts +1 -1
- package/dist/extra/reactive.d.ts +1 -1
- package/dist/extra/reactive.js +1 -1
- package/dist/extra/render/index.d.cts +1 -1
- package/dist/extra/render/index.d.ts +1 -1
- package/dist/extra/sources.cjs +1 -1
- package/dist/extra/sources.js +1 -1
- package/dist/graph/index.d.cts +3 -3
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/index.js +1 -1
- package/dist/{graph-30XSgtVX.d.ts → graph-BkIkog4h.d.ts} +1 -1
- package/dist/{graph-BUwMAxJI.d.cts → graph-E6likq7w.d.cts} +1 -1
- package/dist/{index-BXd6OMEy.d.ts → index-3k4Gg6-n.d.ts} +2 -2
- package/dist/{index-DszPlZzK.d.ts → index-40ZT4MHj.d.ts} +1 -1
- package/dist/index-8s-Qm-gz.d.ts +218 -0
- package/dist/{index-K-vl_c6A.d.cts → index-A3U3CSve.d.cts} +1 -1
- package/dist/{index-jKLph6cu.d.ts → index-B6iTqKtJ.d.ts} +1 -1
- package/dist/{index-WyFKER-c.d.ts → index-B72TQQHd.d.cts} +3 -3
- package/dist/{index-CmqiJZKM.d.ts → index-BAQrjuZF.d.ts} +64 -6
- package/dist/{index-CusEP3Sv.d.ts → index-BQ1fR4li.d.ts} +1 -1
- package/dist/{index-jr6PuSBt.d.ts → index-BaA-xpSw.d.ts} +2 -2
- package/dist/{index-FVoPvhAu.d.cts → index-Bd91Nmf4.d.cts} +2 -2
- package/dist/{index-PqbnoScQ.d.ts → index-BgjS2b8N.d.ts} +2 -2
- package/dist/{index-DCbE8fFM.d.cts → index-BiHUBEKq.d.cts} +2 -2
- package/dist/{index-DlgHqQxW.d.cts → index-BilOa6AE.d.cts} +6 -32
- package/dist/{index-DoYc8BWK.d.cts → index-BmSQLAZo.d.cts} +2 -2
- package/dist/{index-DlrWu9Hs.d.cts → index-C-dkXOpB.d.cts} +1 -1
- package/dist/{index-C7VV_qOs.d.ts → index-C5cQ7Gfx.d.ts} +2 -2
- package/dist/{index-CPhBvRJU.d.ts → index-C6ZUaos7.d.ts} +1 -1
- package/dist/{index-PlJ3MraE.d.ts → index-CAP3UGsq.d.ts} +1 -1
- package/dist/{index-B41Asm7D.d.ts → index-CD2dBMet.d.ts} +2 -2
- package/dist/{index-C19qqa38.d.ts → index-CG33HeBW.d.ts} +19 -4
- package/dist/index-CGhMJNHb.d.cts +128 -0
- package/dist/{index-BAlaVimV.d.ts → index-CQtWm7jS.d.ts} +2 -2
- package/dist/{index-8R1vzNOx.d.cts → index-CRm0YIzC.d.cts} +2 -2
- package/dist/index-CUIkE1l9.d.cts +230 -0
- package/dist/{index-KlZ_ZUip.d.cts → index-Cczxgd2D.d.ts} +3 -3
- package/dist/{index-DIHcMLr6.d.cts → index-CgnCFhr2.d.cts} +1 -1
- package/dist/{index-BC9VybQs.d.ts → index-Ck35nA-T.d.ts} +2 -2
- package/dist/{index-BndG0cpK.d.cts → index-Cnr1WrlX.d.cts} +1 -1
- package/dist/{index-H_I66pav.d.cts → index-CtFNGe-m.d.cts} +2 -2
- package/dist/index-CuPUehFa.d.cts +218 -0
- package/dist/index-D1Gc7wV5.d.ts +230 -0
- package/dist/{index-CWHtYmSh.d.cts → index-D4uimgee.d.cts} +1 -1
- package/dist/{index-xZYcDqFH.d.cts → index-DGD4_fj6.d.cts} +19 -4
- package/dist/{index-CwP_KAMS.d.cts → index-DGTo1yka.d.cts} +64 -6
- package/dist/{index-BUPVld1w.d.ts → index-DH4fm2Ck.d.ts} +2 -2
- package/dist/{index-DyM4tFAe.d.cts → index-DQQCOIt8.d.cts} +2 -2
- package/dist/{index-BJ26eEjs.d.cts → index-DVAlsmEU.d.cts} +2 -2
- package/dist/{index-DINuaZlJ.d.cts → index-DVDapw2k.d.cts} +1 -1
- package/dist/{index-iTX5IqSP.d.ts → index-DfOK_oL5.d.ts} +208 -203
- package/dist/{index-DTtBpuQy.d.cts → index-DgJc8Zgc.d.cts} +5 -3
- package/dist/{index-BKMdnYnk.d.ts → index-DhLyOHYZ.d.ts} +1 -1
- package/dist/{index-89FczVZ_.d.ts → index-DhnsQfa3.d.ts} +77 -51
- package/dist/{index-L8XI8Zql.d.cts → index-DktLSZOc.d.cts} +2 -2
- package/dist/{index-pVDQcbar.d.cts → index-DpiGqtrs.d.cts} +77 -51
- package/dist/{index-mNwgxC21.d.cts → index-DuRsN9ae.d.cts} +208 -203
- package/dist/{index-B9fmw5n2.d.ts → index-I1cCY3ZI.d.ts} +5 -3
- package/dist/index-N2MAxt7_.d.ts +128 -0
- package/dist/{index-Br3WnqEn.d.ts → index-WSlcjhQF.d.ts} +6 -32
- package/dist/{index-DQUVq1_d.d.ts → index-bXXLSvor.d.ts} +2 -2
- package/dist/{index-BhUaMYm_.d.ts → index-da2V5vPy.d.ts} +1 -1
- package/dist/{index-PsVHpPwP.d.cts → index-t6L2qpHh.d.cts} +2 -2
- package/dist/{index-IwFqHxCs.d.cts → index-tV3AA9hI.d.cts} +1 -1
- package/dist/index.cjs +48 -48
- package/dist/index.d.cts +33 -33
- package/dist/index.d.ts +33 -33
- package/dist/index.js +1 -1
- package/dist/patterns/ai/browser.cjs +5 -5
- package/dist/patterns/ai/browser.d.cts +2 -2
- package/dist/patterns/ai/browser.d.ts +2 -2
- package/dist/patterns/ai/browser.js +1 -1
- package/dist/patterns/ai/index.cjs +14 -14
- package/dist/patterns/ai/index.d.cts +11 -11
- package/dist/patterns/ai/index.d.ts +11 -11
- package/dist/patterns/ai/index.js +1 -1
- package/dist/patterns/ai/node.js +1 -1
- package/dist/patterns/audit/index.d.cts +3 -3
- package/dist/patterns/audit/index.d.ts +3 -3
- package/dist/patterns/audit/index.js +1 -1
- package/dist/patterns/cqrs/index.d.cts +3 -3
- package/dist/patterns/cqrs/index.d.ts +3 -3
- package/dist/patterns/cqrs/index.js +1 -1
- package/dist/patterns/demo-shell/index.d.cts +3 -3
- package/dist/patterns/demo-shell/index.d.ts +3 -3
- package/dist/patterns/demo-shell/index.js +1 -1
- package/dist/patterns/domain-templates/index.d.cts +2 -2
- package/dist/patterns/domain-templates/index.d.ts +2 -2
- package/dist/patterns/domain-templates/index.js +1 -1
- package/dist/patterns/graphspec/index.d.cts +2 -2
- package/dist/patterns/graphspec/index.d.ts +2 -2
- package/dist/patterns/graphspec/index.js +1 -1
- package/dist/patterns/guarded-execution/index.cjs +3 -3
- package/dist/patterns/guarded-execution/index.d.cts +4 -4
- package/dist/patterns/guarded-execution/index.d.ts +4 -4
- package/dist/patterns/guarded-execution/index.js +1 -1
- package/dist/patterns/harness/index.cjs +8 -8
- package/dist/patterns/harness/index.d.cts +7 -7
- package/dist/patterns/harness/index.d.ts +7 -7
- package/dist/patterns/harness/index.js +1 -1
- package/dist/patterns/job-queue/index.cjs +3 -3
- package/dist/patterns/job-queue/index.d.cts +3 -3
- package/dist/patterns/job-queue/index.d.ts +3 -3
- package/dist/patterns/job-queue/index.js +1 -1
- package/dist/patterns/lens/index.cjs +3 -3
- package/dist/patterns/lens/index.d.cts +3 -4
- package/dist/patterns/lens/index.d.ts +3 -4
- package/dist/patterns/lens/index.js +1 -1
- package/dist/patterns/memory/index.cjs +1 -1
- package/dist/patterns/memory/index.d.cts +3 -3
- package/dist/patterns/memory/index.d.ts +3 -3
- package/dist/patterns/memory/index.js +1 -1
- package/dist/patterns/messaging/index.d.cts +2 -2
- package/dist/patterns/messaging/index.d.ts +2 -2
- package/dist/patterns/messaging/index.js +1 -1
- 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.d.cts +4 -4
- package/dist/patterns/process/index.d.ts +4 -4
- package/dist/patterns/process/index.js +1 -1
- package/dist/patterns/reactive-layout/index.d.cts +3 -3
- package/dist/patterns/reactive-layout/index.d.ts +3 -3
- package/dist/patterns/reactive-layout/index.js +1 -1
- package/dist/patterns/reduction/index.d.cts +2 -2
- package/dist/patterns/reduction/index.d.ts +2 -2
- package/dist/patterns/reduction/index.js +1 -1
- package/dist/patterns/refine-loop/index.d.cts +3 -3
- package/dist/patterns/refine-loop/index.d.ts +3 -3
- package/dist/patterns/refine-loop/index.js +1 -1
- package/dist/patterns/resilient-pipeline/index.cjs +3 -1
- package/dist/patterns/resilient-pipeline/index.d.cts +7 -3
- package/dist/patterns/resilient-pipeline/index.d.ts +7 -3
- package/dist/patterns/resilient-pipeline/index.js +1 -1
- package/dist/patterns/surface/index.d.cts +3 -3
- package/dist/patterns/surface/index.d.ts +3 -3
- package/dist/patterns/surface/index.js +1 -1
- package/dist/{pipeline-graph-D8vKcO_p.d.ts → pipeline-graph-CB4La-UW.d.ts} +2 -2
- package/dist/{pipeline-graph-BQPr2Lqs.d.cts → pipeline-graph-MWrQZXCq.d.cts} +2 -2
- package/dist/{reactive-layout-8CSc0tiA.d.cts → reactive-layout-BtZfUKuL.d.cts} +1 -1
- package/dist/{reactive-layout-DkTXxtSy.d.ts → reactive-layout-KJj4E2dT.d.ts} +1 -1
- package/dist/{reactive-map-B2qfD3hb.d.cts → reactive-map-6P_k3AQM.d.cts} +1 -1
- package/dist/{reactive-map-jFIsE6Kt.d.ts → reactive-map-CjXByDV-.d.ts} +1 -1
- package/dist/{resilience-HTF2LBRS.js → resilience-JISHQD2F.js} +1 -1
- package/dist/{topology-tree-B5Ngw3j0.d.cts → topology-tree-3LBKFsUo.d.cts} +1 -1
- package/dist/{topology-tree-BtvbgMXJ.d.ts → topology-tree-mF7Emqzm.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-5XRI6RM3.js +0 -1
- package/dist/chunk-73PBQNST.js +0 -1
- package/dist/chunk-A6ZSKGUG.js +0 -1
- package/dist/chunk-EWF7KCDJ.js +0 -61
- package/dist/chunk-IUB4NYI2.js +0 -1
- package/dist/chunk-MC4UYY2X.js +0 -1
- package/dist/chunk-XEUANKBO.js +0 -43
- package/dist/chunk-ZJ7SM3G2.js +0 -1
- package/dist/index-BEHmxORq.d.ts +0 -135
- package/dist/index-BM9szD8n.d.cts +0 -113
- package/dist/index-BskfDoZ_.d.ts +0 -113
- package/dist/index-CIRG8Hxp.d.cts +0 -135
- package/dist/index-Cey6VTnX.d.ts +0 -166
- package/dist/index-CpLpJb6A.d.cts +0 -166
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as M,h as oe,i as ae}from"./chunk-VJJLIEAL.js";import{a as ne}from"./chunk-L6NSJVJZ.js";import{i as se}from"./chunk-7JRF5YEK.js";import{b as re}from"./chunk-35JTVPOX.js";import{b as J}from"./chunk-AU7YTQX7.js";import{C as z}from"./chunk-IA7DUNGB.js";import{D as ee,E as te,G as j,m as Y,p as R,t as D}from"./chunk-LYCLF26R.js";import{b as X}from"./chunk-CK2E7BTU.js";import{b as ce}from"./chunk-QYADASLV.js";var me={};ce(me,{CqrsGraph:()=>G,cqrs:()=>fe,cqrsEventKeyOf:()=>pe,dispatchKeyOf:()=>he,sagaInvocationKeyOf:()=>ve});var k=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},B=class extends k{constructor(n,t){super(`Duplicate ${n} registration: "${t}"`);this.kind=n;this.registrationName=t}},N=class extends k{constructor(n,t,r){super(`Command "${n}" emitted undeclared event "${t}". Declared emits: [${r.join(", ")}]`);this.commandName=n;this.eventName=t;this.declaredEmits=r}},K=class extends k{constructor(n,t,r){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${t}, got ${r}`);this.aggregateId=n;this.expected=t;this.actual=r}},H=class extends k{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},O=class extends k{constructor(n,t){super(`Command handler "${n}" threw: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.commandName=n}};var P=class extends k{constructor(n,t){super(`Projection "${n}" rebuild failed: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.projectionName=n}};var le=D((o,e)=>{o("write"),o("signal"),e("observe")}),ue=D((o,e)=>{o("observe"),o("signal"),e("write")}),ie=D((o,e)=>{o("observe"),o("signal"),e("write")});function $(o,e){return ne("cqrs",o,e)}function Z(o){if(o===null||typeof o!="object"||Object.isFrozen(o))return o;for(let e of Object.keys(o))Z(o[e]);return Object.freeze(o)}var pe=o=>`${o.type}::${o.aggregateId??"__default__"}`,he=o=>o.commandName,ve=o=>o.eventType,G=class extends se{_eventLogs=new Map;_eventLogsByAggregate=new Map;_aggregateVersions=new Map;_aggregateLru=new Map;_commandRegs=new Map;_projections=new Set;_sagas=new Set;_keepaliveDisposers=[];_seq=0;_retainedLimit;_freezeCommandPayload;_freezeEventPayload;_maxAggregates;_dispatchSeqCursor;dispatches;audit;aggregateEvictions;constructor(e,n={}){super(e,n.graph),this._retainedLimit=n.retainedLimit??1024,this._freezeCommandPayload=n.freezeCommandPayload??!0,this._freezeEventPayload=n.freezeEventPayload??!0,this._maxAggregates=n.maxAggregates??1e4,this.dispatches=M({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=M({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=oe(this,"dispatch_seq",0)}aggregateVersion(e,n){return this._aggregateVersions.get(`${e}::${n}`)??0}_touchAggregate(e){this._aggregateLru.delete(e),this._aggregateLru.set(e,!0)}_enforceAggregateLru(){for(;this._aggregateLru.size>this._maxAggregates;){let e=this._aggregateLru.keys().next();if(e.done)break;let n=e.value;this._aggregateLru.delete(n);let t=n.indexOf("::");if(t<0)continue;let r=n.slice(0,t),s=n.slice(t+2),a=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let i=this._eventLogsByAggregate.get(r);i&&(i.delete(s),i.size===0&&this._eventLogsByAggregate.delete(r)),this.aggregateEvictions.append({aggregateId:s,type:r,lastVersion:a,t_ns:R()})}}destroy(){for(let e of this._keepaliveDisposers)e();this._keepaliveDisposers.length=0,super.destroy()}_attachedEventTiers=[];_attachedTierDisposers=new Map;attachEventStorage(e){this._attachedEventTiers.push(e);for(let[n,t]of this._eventLogs){let r=t.log.attachStorage(e),s=this._attachedTierDisposers.get(n);s||(s=[],this._attachedTierDisposers.set(n,s)),s.push(r)}for(let[n,t]of this._eventLogsByAggregate)for(let[r,s]of t){let a=`${n}::${r}`,i=s.log.attachStorage(e),c=this._attachedTierDisposers.get(a);c||(c=[],this._attachedTierDisposers.set(a,c)),c.push(i)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let t=this._attachedTierDisposers.get(e);t||(t=[],this._attachedTierDisposers.set(e,t));for(let r of this._attachedEventTiers)t.push(n.attachStorage(r))}_bumpDispatchSeq(){let n=(this._dispatchSeqCursor.cache??0)+1;return this._dispatchSeqCursor.emit(n),n}event(e,n){if(n!==void 0)return this._ensureAggregateStream(e,n).node;let t=this._eventLogs.get(e);if(t)return t.node;let r=J([],{name:e,versioning:0,maxSize:this._retainedLimit});r.withLatest();let s=r.entries,a=j([s],([i])=>i,{name:e,describeKind:"state",meta:$("event",{event_name:e}),guard:ie,initial:s.cache});return this.add(a,{name:e}),this._keepaliveDisposers.push(z(a)),this._eventLogs.set(e,{log:r,node:a}),this._autoWireStreamStorage(e,r),a}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let t=this._eventLogsByAggregate.get(e);t||(t=new Map,this._eventLogsByAggregate.set(e,t));let r=`${e}::${n}`;this._touchAggregate(r);let s=t.get(n);if(s)return s;let a=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,i=J([],{name:a,versioning:0,maxSize:this._retainedLimit});i.withLatest();let c=i.entries,h=j([c],([p])=>p,{name:a,describeKind:"state",meta:$("event_aggregate",{event_name:e,aggregate_id:n}),guard:ie,initial:c.cache}),l=a,m=0;for(;this.nameOf(this.resolveOptional(l)??h)===l&&(m+=1,l=`${a}_${m}`,this.resolveOptional(l)!==void 0););try{this.add(h,{name:l})}catch{}this._keepaliveDisposers.push(z(h));let u={log:i,node:h};return t.set(n,u),this._autoWireStreamStorage(`${e}::${n}`,i),this._enforceAggregateLru(),u}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,t){let r=this._eventLogs.get(e);if(r||(this.event(e),r=this._eventLogs.get(e)),r.node.status==="completed"||r.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${r.node.status}).`);let s,a;if(t?.aggregateId!==void 0){let l=`${e}::${t.aggregateId}`;s=(this._aggregateVersions.get(l)??0)+1,this._aggregateVersions.set(l,s),a=this._ensureAggregateStream(e,t.aggregateId)}let i=r.log.entries.v,c=this._freezeEventPayload?Z(n):n,h={type:e,payload:c,timestampNs:R(),seq:++this._seq,...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...s!==void 0?{aggregateVersion:s}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...t?.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{},...i!=null?{v0:{id:i.id,version:i.version}}:{}};return r.log.append(h),a&&a.log.append(h),h}command(e,n){if(this._commandRegs.has(e))throw new B("command",e);let t=typeof n=="function"?{handler:n}:n,r=te(void 0,{name:e,describeKind:"state",meta:{...$("command",{command_name:e}),error:null},guard:le});if(this.add(r,{name:e}),this._commandRegs.set(e,{handler:t.handler,...t.emits!==void 0?{emits:t.emits}:{},...t.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{}}),t.emits)for(let s of t.emits)this._eventLogs.has(s)||this.event(s);return r}dispatch(e,n,t){let r=this._commandRegs.get(e);if(!r)throw new H(e);if(t?.aggregateId!==void 0&&t.expectedAggregateVersion!==void 0&&r.emits!==void 0){let u=0;for(let p of r.emits){let _=this._aggregateVersions.get(`${p}::${t.aggregateId}`);_!==void 0&&_>u&&(u=_)}if(u!==t.expectedAggregateVersion)throw new K(t.aggregateId,t.expectedAggregateVersion,u)}let s=this.resolve(e),a=this._freezeCommandPayload?Z(n):n,i=[],c=R(),h=0,l,m=!1;try{Y(()=>{h=this._bumpDispatchSeq(),s.emit(a,{internal:!0});try{r.handler(a,{emit:(u,p)=>{if(r.emits!==void 0&&!r.emits.includes(u))throw new N(e,u,r.emits);i.push(u),this._appendEvent(u,p,{...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}}),s.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:a,outcome:"success",emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}catch(u){throw l=u,m=!0,u}})}catch(u){if(m){s.meta.error.emit(l,{internal:!0});let p=l instanceof Error?l.name:typeof l,_=l instanceof O?l:new O(e,l);this.dispatches.append({commandName:e,payload:a,outcome:"failure",error:_,errorType:p,emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}throw m?l:u}}projection(e){let{name:n,events:t,reducer:r,initial:s}=e,a=e.mode??"scan",i=e.freezeInputs??!0,c=e.snapshot,h=t.map(d=>(this._eventLogs.has(d)||this.event(d),this._eventLogs.get(d).node));function l(d){d.sort((g,v)=>g.timestampNs-v.timestampNs||g.seq-v.seq||(g.aggregateId??"").localeCompare(v.aggregateId??""))}function m(d){let g=[];for(let v of d)g.push(...v);return l(g),g}let u=h.map(d=>d.cache??[]),p=m(u),_=i?Object.freeze(p):p,C=0,y=s;a==="scan"&&p.length>0&&(y=r(s,_),C=p.length);let q=a==="replay"?r(s,_):y,V=c?.saveDebounceMs??1e3,A=c?.saveEvery??1e3,E,L=0;function F(d){if(c?.save){if(L+=1,L>=A){L=0,E!==void 0&&(clearTimeout(E),E=void 0);let g=c.save(d);g instanceof Promise&&g.catch(()=>{});return}E!==void 0&&clearTimeout(E),E=setTimeout(()=>{E=void 0,L=0;let g=c.save(d);g instanceof Promise&&g.catch(()=>{})},V)}}let S=j(h,d=>{let g=m(d),v;if(a==="replay"){let w=i?Object.freeze(g):g;v=r(s,w)}else{let w=g.slice(C);C=g.length;let f=i?Object.freeze(w):w;v=r(y,f),y=v}return F(v),v},{name:n,describeKind:"derived",meta:$("projection",{projection_name:n,source_events:t}),guard:ue,initial:q});return this.add(S,{name:n}),this._keepaliveDisposers.push(z(S)),this._keepaliveDisposers.push(()=>{E!==void 0&&(clearTimeout(E),E=void 0)}),this._projections.add(n),{node:S,rebuild:async d=>{try{let g=d?.pageSize??1e3,v=d?.fromTier??this._attachedEventTiers[0]?.[0],w=m(h.map(T=>T.cache??[])).length,f=s;if(c?.load){let T=await c.load();T!==void 0&&(f=T)}if(!v||!v.loadEntries){let T=m(h.map(I=>I.cache??[])),b=i?Object.freeze(T):T;f=r(f,b)}else{let T=new Set(t),b,I=!1;for(;!I;){let U=await v.loadEntries({cursor:b,pageSize:g}),W=[...U.entries].filter(ge=>T.has(ge.type));l(W);let de=i?Object.freeze(W):W;f=r(f,de),b=U.cursor,I=!b||U.entries.length===0}}if(a==="scan"){let T=m(h.map(I=>I.cache??[])),b=T.slice(w);if(b.length>0){let I=i?Object.freeze(b):b;f=r(f,I)}y=f,C=T.length}return S.emit(f,{internal:!0}),f}catch(g){throw new P(n,g)}},reset:async()=>{try{let d=s;if(c?.load){let f=await c.load();f!==void 0&&(d=f)}let g=m(h.map(f=>f.cache??[])),v=i?Object.freeze(g):g,w=r(d,v);return a==="scan"&&(y=w,C=g.length),S.emit(w,{internal:!0}),w}catch(d){throw new P(n,d)}}}}saga(e,n,t,r={}){let s=n.map(p=>(this._eventLogs.has(p)||this.event(p),this._eventLogs.get(p).node)),a=ae(this,`${e}_cursor`,n,0),i=M({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),c=r.aggregateId,h=r.errorPolicy??"advance",l=new Map;for(let p of n){let _=a[p];l.set(p,_.cache??0);let C=_.subscribe(y=>{for(let q of y)q[0]===X&&l.set(p,q[1])});this._keepaliveDisposers.push(C)}let m={},u=ee(s,(p,_)=>{let C=m.n.meta.error;for(let y=0;y<p.length;y++){let q=p[y];if(q==null||q.length===0)continue;let V=q.at(-1);if(!V)continue;let A=n[y],E=a[A],L=l.get(A)??0;if(V.length>L){let F=V.slice(L),S=L;for(let Q of F){let x=Q;if(c!==void 0&&x.aggregateId!==c){S+=1;continue}try{t(x),C.emit(null,{internal:!0}),i.append({eventType:A,outcome:"success",aggregateId:x.aggregateId,event:x,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),S+=1}catch(d){if(C.emit(d,{internal:!0}),i.append({eventType:A,outcome:"failure",error:d,errorType:d instanceof Error?d.name:typeof d,aggregateId:x.aggregateId,event:x,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),h==="hold")break;S+=1}}E.emit(S)}}},{name:e,describeKind:"effect",meta:{...$("saga",{saga_name:e,source_events:n}),error:null}});return m.n=u,this.add(u,{name:e}),this._keepaliveDisposers.push(z(u)),this._sagas.add(e),{node:u,invocations:i,audit:i,cursors:a}}};function fe(o,e){let n=new G(o,e),{factory:t,factoryArgs:r,...s}=e??{};return n.tagFactory("cqrs",re(s)),n}export{pe as a,he as b,ve as c,G as d,fe as e,me as f};
|
|
1
|
+
import{c as M,h as oe,i as ae}from"./chunk-VXPLLA4P.js";import{a as ne}from"./chunk-L6NSJVJZ.js";import{b as J}from"./chunk-TT4C7DXW.js";import{i as se}from"./chunk-POXANAJ6.js";import{C as z}from"./chunk-L77I47VU.js";import{b as re}from"./chunk-35JTVPOX.js";import{D as ee,E as te,G as j,m as Y,p as R,t as D}from"./chunk-LYCLF26R.js";import{b as X}from"./chunk-CK2E7BTU.js";import{b as ce}from"./chunk-QYADASLV.js";var me={};ce(me,{CqrsGraph:()=>G,cqrs:()=>fe,cqrsEventKeyOf:()=>pe,dispatchKeyOf:()=>he,sagaInvocationKeyOf:()=>ve});var k=class extends Error{constructor(e,n){super(e,n),this.name=this.constructor.name}},B=class extends k{constructor(n,t){super(`Duplicate ${n} registration: "${t}"`);this.kind=n;this.registrationName=t}},N=class extends k{constructor(n,t,r){super(`Command "${n}" emitted undeclared event "${t}". Declared emits: [${r.join(", ")}]`);this.commandName=n;this.eventName=t;this.declaredEmits=r}},K=class extends k{constructor(n,t,r){super(`Optimistic concurrency conflict on aggregate "${n}": expected version ${t}, got ${r}`);this.aggregateId=n;this.expected=t;this.actual=r}},H=class extends k{constructor(n){super(`Unknown command: "${n}". Register with command() first.`);this.commandName=n}},O=class extends k{constructor(n,t){super(`Command handler "${n}" threw: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.commandName=n}};var P=class extends k{constructor(n,t){super(`Projection "${n}" rebuild failed: ${t instanceof Error?t.message:String(t)}`,{cause:t});this.projectionName=n}};var le=D((o,e)=>{o("write"),o("signal"),e("observe")}),ue=D((o,e)=>{o("observe"),o("signal"),e("write")}),ie=D((o,e)=>{o("observe"),o("signal"),e("write")});function $(o,e){return ne("cqrs",o,e)}function Z(o){if(o===null||typeof o!="object"||Object.isFrozen(o))return o;for(let e of Object.keys(o))Z(o[e]);return Object.freeze(o)}var pe=o=>`${o.type}::${o.aggregateId??"__default__"}`,he=o=>o.commandName,ve=o=>o.eventType,G=class extends se{_eventLogs=new Map;_eventLogsByAggregate=new Map;_aggregateVersions=new Map;_aggregateLru=new Map;_commandRegs=new Map;_projections=new Set;_sagas=new Set;_keepaliveDisposers=[];_seq=0;_retainedLimit;_freezeCommandPayload;_freezeEventPayload;_maxAggregates;_dispatchSeqCursor;dispatches;audit;aggregateEvictions;constructor(e,n={}){super(e,n.graph),this._retainedLimit=n.retainedLimit??1024,this._freezeCommandPayload=n.freezeCommandPayload??!0,this._freezeEventPayload=n.freezeEventPayload??!0,this._maxAggregates=n.maxAggregates??1e4,this.dispatches=M({name:"dispatches",retainedLimit:this._retainedLimit,graph:this}),this.audit=this.dispatches,this.aggregateEvictions=M({name:"aggregateEvictions",retainedLimit:this._retainedLimit,graph:this}),this._dispatchSeqCursor=oe(this,"dispatch_seq",0)}aggregateVersion(e,n){return this._aggregateVersions.get(`${e}::${n}`)??0}_touchAggregate(e){this._aggregateLru.delete(e),this._aggregateLru.set(e,!0)}_enforceAggregateLru(){for(;this._aggregateLru.size>this._maxAggregates;){let e=this._aggregateLru.keys().next();if(e.done)break;let n=e.value;this._aggregateLru.delete(n);let t=n.indexOf("::");if(t<0)continue;let r=n.slice(0,t),s=n.slice(t+2),a=this._aggregateVersions.get(n)??0;this._aggregateVersions.delete(n);let i=this._eventLogsByAggregate.get(r);i&&(i.delete(s),i.size===0&&this._eventLogsByAggregate.delete(r)),this.aggregateEvictions.append({aggregateId:s,type:r,lastVersion:a,t_ns:R()})}}destroy(){for(let e of this._keepaliveDisposers)e();this._keepaliveDisposers.length=0,super.destroy()}_attachedEventTiers=[];_attachedTierDisposers=new Map;attachEventStorage(e){this._attachedEventTiers.push(e);for(let[n,t]of this._eventLogs){let r=t.log.attachStorage(e),s=this._attachedTierDisposers.get(n);s||(s=[],this._attachedTierDisposers.set(n,s)),s.push(r)}for(let[n,t]of this._eventLogsByAggregate)for(let[r,s]of t){let a=`${n}::${r}`,i=s.log.attachStorage(e),c=this._attachedTierDisposers.get(a);c||(c=[],this._attachedTierDisposers.set(a,c)),c.push(i)}return()=>{let n=this._attachedEventTiers.indexOf(e);n>=0&&this._attachedEventTiers.splice(n,1)}}_autoWireStreamStorage(e,n){if(this._attachedEventTiers.length===0)return;let t=this._attachedTierDisposers.get(e);t||(t=[],this._attachedTierDisposers.set(e,t));for(let r of this._attachedEventTiers)t.push(n.attachStorage(r))}_bumpDispatchSeq(){let n=(this._dispatchSeqCursor.cache??0)+1;return this._dispatchSeqCursor.emit(n),n}event(e,n){if(n!==void 0)return this._ensureAggregateStream(e,n).node;let t=this._eventLogs.get(e);if(t)return t.node;let r=J([],{name:e,versioning:0,maxSize:this._retainedLimit});r.withLatest();let s=r.entries,a=j([s],([i])=>i,{name:e,describeKind:"state",meta:$("event",{event_name:e}),guard:ie,initial:s.cache});return this.add(a,{name:e}),this._keepaliveDisposers.push(z(a)),this._eventLogs.set(e,{log:r,node:a}),this._autoWireStreamStorage(e,r),a}_ensureAggregateStream(e,n){this._eventLogs.has(e)||this.event(e);let t=this._eventLogsByAggregate.get(e);t||(t=new Map,this._eventLogsByAggregate.set(e,t));let r=`${e}::${n}`;this._touchAggregate(r);let s=t.get(n);if(s)return s;let a=`${e}_${n.replace(/[^a-zA-Z0-9_-]/g,"_")}`,i=J([],{name:a,versioning:0,maxSize:this._retainedLimit});i.withLatest();let c=i.entries,h=j([c],([p])=>p,{name:a,describeKind:"state",meta:$("event_aggregate",{event_name:e,aggregate_id:n}),guard:ie,initial:c.cache}),l=a,m=0;for(;this.nameOf(this.resolveOptional(l)??h)===l&&(m+=1,l=`${a}_${m}`,this.resolveOptional(l)!==void 0););try{this.add(h,{name:l})}catch{}this._keepaliveDisposers.push(z(h));let u={log:i,node:h};return t.set(n,u),this._autoWireStreamStorage(`${e}::${n}`,i),this._enforceAggregateLru(),u}resolveOptional(e){try{return this.resolve(e)}catch{return}}_appendEvent(e,n,t){let r=this._eventLogs.get(e);if(r||(this.event(e),r=this._eventLogs.get(e)),r.node.status==="completed"||r.node.status==="errored")throw new Error(`Cannot dispatch to terminated event stream "${e}" (status: ${r.node.status}).`);let s,a;if(t?.aggregateId!==void 0){let l=`${e}::${t.aggregateId}`;s=(this._aggregateVersions.get(l)??0)+1,this._aggregateVersions.set(l,s),a=this._ensureAggregateStream(e,t.aggregateId)}let i=r.log.entries.v,c=this._freezeEventPayload?Z(n):n,h={type:e,payload:c,timestampNs:R(),seq:++this._seq,...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...s!==void 0?{aggregateVersion:s}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...t?.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{},...i!=null?{v0:{id:i.id,version:i.version}}:{}};return r.log.append(h),a&&a.log.append(h),h}command(e,n){if(this._commandRegs.has(e))throw new B("command",e);let t=typeof n=="function"?{handler:n}:n,r=te(void 0,{name:e,describeKind:"state",meta:{...$("command",{command_name:e}),error:null},guard:le});if(this.add(r,{name:e}),this._commandRegs.set(e,{handler:t.handler,...t.emits!==void 0?{emits:t.emits}:{},...t.handlerVersion!==void 0?{handlerVersion:t.handlerVersion}:{}}),t.emits)for(let s of t.emits)this._eventLogs.has(s)||this.event(s);return r}dispatch(e,n,t){let r=this._commandRegs.get(e);if(!r)throw new H(e);if(t?.aggregateId!==void 0&&t.expectedAggregateVersion!==void 0&&r.emits!==void 0){let u=0;for(let p of r.emits){let _=this._aggregateVersions.get(`${p}::${t.aggregateId}`);_!==void 0&&_>u&&(u=_)}if(u!==t.expectedAggregateVersion)throw new K(t.aggregateId,t.expectedAggregateVersion,u)}let s=this.resolve(e),a=this._freezeCommandPayload?Z(n):n,i=[],c=R(),h=0,l,m=!1;try{Y(()=>{h=this._bumpDispatchSeq(),s.emit(a,{internal:!0});try{r.handler(a,{emit:(u,p)=>{if(r.emits!==void 0&&!r.emits.includes(u))throw new N(e,u,r.emits);i.push(u),this._appendEvent(u,p,{...t?.aggregateId!==void 0?{aggregateId:t.aggregateId}:{},...t?.correlationId!==void 0?{correlationId:t.correlationId}:{},...t?.causationId!==void 0?{causationId:t.causationId}:{},...t?.metadata!==void 0?{metadata:Object.freeze({...t.metadata})}:{},...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}}),s.meta.error.emit(null,{internal:!0}),this.dispatches.append({commandName:e,payload:a,outcome:"success",emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}catch(u){throw l=u,m=!0,u}})}catch(u){if(m){s.meta.error.emit(l,{internal:!0});let p=l instanceof Error?l.name:typeof l,_=l instanceof O?l:new O(e,l);this.dispatches.append({commandName:e,payload:a,outcome:"failure",error:_,errorType:p,emittedEvents:[...i],t_ns:c,seq:h,...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}})}throw m?l:u}}projection(e){let{name:n,events:t,reducer:r,initial:s}=e,a=e.mode??"scan",i=e.freezeInputs??!0,c=e.snapshot,h=t.map(d=>(this._eventLogs.has(d)||this.event(d),this._eventLogs.get(d).node));function l(d){d.sort((g,v)=>g.timestampNs-v.timestampNs||g.seq-v.seq||(g.aggregateId??"").localeCompare(v.aggregateId??""))}function m(d){let g=[];for(let v of d)g.push(...v);return l(g),g}let u=h.map(d=>d.cache??[]),p=m(u),_=i?Object.freeze(p):p,C=0,y=s;a==="scan"&&p.length>0&&(y=r(s,_),C=p.length);let q=a==="replay"?r(s,_):y,V=c?.saveDebounceMs??1e3,A=c?.saveEvery??1e3,E,L=0;function F(d){if(c?.save){if(L+=1,L>=A){L=0,E!==void 0&&(clearTimeout(E),E=void 0);let g=c.save(d);g instanceof Promise&&g.catch(()=>{});return}E!==void 0&&clearTimeout(E),E=setTimeout(()=>{E=void 0,L=0;let g=c.save(d);g instanceof Promise&&g.catch(()=>{})},V)}}let S=j(h,d=>{let g=m(d),v;if(a==="replay"){let w=i?Object.freeze(g):g;v=r(s,w)}else{let w=g.slice(C);C=g.length;let f=i?Object.freeze(w):w;v=r(y,f),y=v}return F(v),v},{name:n,describeKind:"derived",meta:$("projection",{projection_name:n,source_events:t}),guard:ue,initial:q});return this.add(S,{name:n}),this._keepaliveDisposers.push(z(S)),this._keepaliveDisposers.push(()=>{E!==void 0&&(clearTimeout(E),E=void 0)}),this._projections.add(n),{node:S,rebuild:async d=>{try{let g=d?.pageSize??1e3,v=d?.fromTier??this._attachedEventTiers[0]?.[0],w=m(h.map(T=>T.cache??[])).length,f=s;if(c?.load){let T=await c.load();T!==void 0&&(f=T)}if(!v||!v.loadEntries){let T=m(h.map(I=>I.cache??[])),b=i?Object.freeze(T):T;f=r(f,b)}else{let T=new Set(t),b,I=!1;for(;!I;){let U=await v.loadEntries({cursor:b,pageSize:g}),W=[...U.entries].filter(ge=>T.has(ge.type));l(W);let de=i?Object.freeze(W):W;f=r(f,de),b=U.cursor,I=!b||U.entries.length===0}}if(a==="scan"){let T=m(h.map(I=>I.cache??[])),b=T.slice(w);if(b.length>0){let I=i?Object.freeze(b):b;f=r(f,I)}y=f,C=T.length}return S.emit(f,{internal:!0}),f}catch(g){throw new P(n,g)}},reset:async()=>{try{let d=s;if(c?.load){let f=await c.load();f!==void 0&&(d=f)}let g=m(h.map(f=>f.cache??[])),v=i?Object.freeze(g):g,w=r(d,v);return a==="scan"&&(y=w,C=g.length),S.emit(w,{internal:!0}),w}catch(d){throw new P(n,d)}}}}saga(e,n,t,r={}){let s=n.map(p=>(this._eventLogs.has(p)||this.event(p),this._eventLogs.get(p).node)),a=ae(this,`${e}_cursor`,n,0),i=M({name:`${e}_invocations`,retainedLimit:this._retainedLimit,graph:this}),c=r.aggregateId,h=r.errorPolicy??"advance",l=new Map;for(let p of n){let _=a[p];l.set(p,_.cache??0);let C=_.subscribe(y=>{for(let q of y)q[0]===X&&l.set(p,q[1])});this._keepaliveDisposers.push(C)}let m={},u=ee(s,(p,_)=>{let C=m.n.meta.error;for(let y=0;y<p.length;y++){let q=p[y];if(q==null||q.length===0)continue;let V=q.at(-1);if(!V)continue;let A=n[y],E=a[A],L=l.get(A)??0;if(V.length>L){let F=V.slice(L),S=L;for(let Q of F){let x=Q;if(c!==void 0&&x.aggregateId!==c){S+=1;continue}try{t(x),C.emit(null,{internal:!0}),i.append({eventType:A,outcome:"success",aggregateId:x.aggregateId,event:x,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),S+=1}catch(d){if(C.emit(d,{internal:!0}),i.append({eventType:A,outcome:"failure",error:d,errorType:d instanceof Error?d.name:typeof d,aggregateId:x.aggregateId,event:x,t_ns:R(),...r.handlerVersion!==void 0?{handlerVersion:r.handlerVersion}:{}}),h==="hold")break;S+=1}}E.emit(S)}}},{name:e,describeKind:"effect",meta:{...$("saga",{saga_name:e,source_events:n}),error:null}});return m.n=u,this.add(u,{name:e}),this._keepaliveDisposers.push(z(u)),this._sagas.add(e),{node:u,invocations:i,audit:i,cursors:a}}};function fe(o,e){let n=new G(o,e),{factory:t,factoryArgs:r,...s}=e??{};return n.tagFactory("cqrs",re(s)),n}export{pe as a,he as b,ve as c,G as d,fe as e,me as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{m as x,x as w}from"./chunk-
|
|
1
|
+
import{m as x,x as w}from"./chunk-L77I47VU.js";import{i as g,j as p}from"./chunk-CK2E7BTU.js";async function k(o){let i=typeof o=="string"?new TextEncoder().encode(o):o,c=await globalThis.crypto.subtle.digest("SHA-256",i),t=new Uint8Array(c),n="";for(let r=0;r<t.length;r++)n+=b[t[r]];return n}var b=new Array(256);for(let o=0;o<256;o++)b[o]=o.toString(16).padStart(2,"0");var m=class extends Error{constructor(c,t){super(`content-addressed lookup miss in read-strict mode: ${c}`);this.key=c;this.context=t;this.name="ContentAddressedMissError"}};function T(o){let i=new Set,c=t=>{if(t===null||typeof t!="object")return t;let n=t;if(i.has(n))return{__cycle:!0};i.add(n);try{if(Array.isArray(t))return t.map(c);let r={};for(let d of Object.keys(t).sort())r[d]=c(t[d]);return r}finally{i.delete(n)}};return JSON.stringify(c(o))}function P(o){let{storage:i,keyContext:c,keyPrefix:t,mode:n="read-write"}=o,r=c??(e=>e);async function d(e){let s=T(r(e)),a=await k(s);return t?`${t}:${a}`:a}return{keyFor:d,async lookup(e){if(n==="write")return;let s=await d(e),a=await i.load(s);if(a===void 0){if(n==="read-strict")throw new m(s,e);return}return a},async store(e,s){if(n==="read")return;let a=await d(e);await i.save(a,s)},async forget(e){if(n==="read"||n==="write"||!i.delete)return;let s=await d(e);await i.delete(s)}}}function K(o,i={}){let c=i.keyFn??(n=>String(n)),t=new Map;return n=>{let r=c(n),d=t.get(r);if(d)return d;let e=o(n),s;e!=null&&typeof e.then=="function"?s=Promise.resolve(e):e!=null&&typeof e=="object"&&"subscribe"in e&&"cache"in e?s=w(e):e!=null&&typeof e=="object"&&Symbol.asyncIterator in e?s=(async()=>{let u=e[Symbol.asyncIterator]();try{let{value:l,done:f}=await u.next();if(f)throw new Error("singleFromAny: factory returned empty async iterable");return l}finally{await u.return?.()}})():e!=null&&typeof e=="object"&&Symbol.iterator in e?s=(async()=>{let u=e[Symbol.iterator]();try{let{value:l,done:f}=u.next();if(f)throw new Error("singleFromAny: factory returned empty iterable");return l}finally{u.return?.()}})():s=Promise.resolve(e);let a,y=()=>{t.get(r)===a&&t.delete(r)};return a=s.then(u=>(y(),u),u=>{throw y(),u}),t.set(r,a),a}}function j(o,i={}){let c=i.keyFn??(n=>String(n)),t=new Map;return n=>{let r=c(n),d=t.get(r);if(d)return d;let e=x(o(n));t.set(r,e);let s=e.subscribe(a=>{for(let y of a)if(y[0]===p||y[0]===g){t.get(r)===e&&t.delete(r),s();return}});return e}}export{k as a,m as b,T as c,P as d,K as e,j as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as w,E as I,F as b,p as C}from"./chunk-LYCLF26R.js";import{a as S,b as h,c as A,d as x,i as T,j as p}from"./chunk-CK2E7BTU.js";function y(e,n,t){let u=new Set;for(let o of e.split(",")){let[r,i]=o.split("/"),s=i?Number.parseInt(i,10):1;if(Number.isNaN(s)||s<1)throw new Error(`Invalid cron step: ${o}`);let a,d;if(r==="*")a=n,d=t;else if(r.includes("-")){let[f,c]=r.split("-");a=Number.parseInt(f,10),d=Number.parseInt(c,10)}else a=Number.parseInt(r,10),d=a;if(Number.isNaN(a)||Number.isNaN(d))throw new Error(`Invalid cron field: ${e}`);if(a<n||d>t)throw new Error(`Cron field out of range: ${e} (${n}-${t})`);if(a>d)throw new Error(`Invalid cron range: ${a}-${d} in ${e}`);for(let f=a;f<=d;f+=s)u.add(f)}return u}function L(e){let n=e.trim().split(/\s+/);if(n.length!==5)throw new Error(`Invalid cron: expected 5 fields, got ${n.length}`);return{minutes:y(n[0],0,59),hours:y(n[1],0,23),daysOfMonth:y(n[2],1,31),months:y(n[3],1,12),daysOfWeek:y(n[4],0,6)}}function P(e,n){return e.minutes.has(n.getMinutes())&&e.hours.has(n.getHours())&&e.daysOfMonth.has(n.getDate())&&e.months.has(n.getMonth()+1)&&e.daysOfWeek.has(n.getDay())}function m(e){return{describeKind:"producer",...e}}function $(e){return/[\\^$+?.()|[\]{}]/.test(e)?`\\${e}`:e}function X(e){let n="^";for(let t=0;t<e.length;t+=1){let u=e[t];if(u==="*"){e[t+1]==="*"?(n+=".*",t+=1):n+="[^/]*";continue}n+=$(u)}return n+="$",new RegExp(n)}function Z(e,n){for(let t of n)if(t.test(e))return!0;return!1}function K(e,n){let t=w([e],(o,r)=>{let i=o[0];if(i==null||i.length===0){r.down([[x]]);return}for(let s of i)r.emit(s)},{describeKind:"derived",initial:e.cache}),u=t.subscribe.bind(t);return t.subscribe=(o,r)=>(n(o),u(o,r)),t}function ee(e,n){let{signal:t,period:u,...o}=n??{};return b(r=>{let i=!1,s=0,a,d,f=()=>{i=!0,a!==void 0&&clearTimeout(a),d!==void 0&&clearInterval(d),t?.removeEventListener("abort",l)},c=()=>{i||(u!=null?(r.emit(s++),d=setInterval(()=>{i||r.emit(s++)},u)):(i=!0,t?.removeEventListener("abort",l),r.emit(s++),r.down([[T]])))},l=()=>{i||(f(),r.down([[p,t.reason]]))};if(t?.aborted){l();return}return a=setTimeout(c,e),t?.addEventListener("abort",l,{once:!0}),f},m(o))}function ne(e){let{signal:n,...t}=e??{};return b(u=>{let o=!1,r,i,s=!1,a=!1,d=typeof requestAnimationFrame=="function"?requestAnimationFrame:void 0,f=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:void 0,c=typeof document<"u"?document:void 0,l=()=>{r!==void 0&&f&&f(r),i!==void 0&&clearTimeout(i),r=void 0,i=void 0},v=()=>{o=!0,l(),s&&(n?.removeEventListener("abort",N),s=!1),a&&c&&(c.removeEventListener("visibilitychange",k),a=!1)},N=()=>{o||(v(),u.down([[p,n.reason]]))},O=_=>{o||(u.emit(_),g())},g=()=>{o||(d&&(!c||c.visibilityState!=="hidden")?r=d(O):i=setTimeout(()=>O(performance.now()),16))},k=()=>{o||(l(),g())};return n?.aborted?(N(),v):(n?.addEventListener("abort",N,{once:!0}),s=n!==void 0,c&&d&&(c.addEventListener("visibilitychange",k),a=!0),g(),v)},m(t))}function te(e,n){let t=L(e),{tickMs:u,output:o,...r}=n??{},i=u??6e4,s=o==="date";return b(a=>{let d=-1,f=()=>{let l=new Date,v=l.getFullYear()*1e8+(l.getMonth()+1)*1e6+l.getDate()*1e4+l.getHours()*100+l.getMinutes();v!==d&&P(t,l)&&(d=v,a.emit(s?l:C()))};f();let c=setInterval(f,i);return()=>clearInterval(c)},{...m(r),name:r.name??`cron:${e}`})}function re(e,n,t){let{capture:u,passive:o,once:r,...i}=t??{};return b(s=>{let a=f=>{s.emit(f)},d={capture:u,passive:o,once:r};return e.addEventListener(n,a,d),()=>e.removeEventListener(n,a,d)},m(i))}function D(e,n){return b(t=>{let u=!1;try{for(let o of e){if(u)return;t.emit(o)}u||t.down([[T]])}catch(o){u||t.down([[p,o]])}return()=>{u=!0}},m(n))}function W(e){return e!=null&&typeof e.then=="function"}function q(e,n){let{signal:t,...u}=n??{};return b(o=>{let r=!1,i=()=>{r||(r=!0,o.down([[p,t.reason]]))};if(t?.aborted){i();return}return t?.addEventListener("abort",i,{once:!0}),Promise.resolve(e).then(s=>{r||(r=!0,t?.removeEventListener("abort",i),o.emit(s),o.down([[T]]))},s=>{r||(r=!0,t?.removeEventListener("abort",i),o.down([[p,s]]))}),()=>{r=!0,t?.removeEventListener("abort",i)}},m(u))}function H(e,n){let{signal:t,...u}=n??{};return b(o=>{let r=new AbortController,i=()=>r.abort(t?.reason);t?.aborted?r.abort(t.reason):t?.addEventListener("abort",i,{once:!0});let s=t??r.signal,a=!1,d=e[Symbol.asyncIterator](),f=()=>{a||s.aborted||Promise.resolve(d.next()).then(c=>{if(!(a||s.aborted)){if(c.done){o.down([[T]]);return}o.emit(c.value),f()}},c=>{!a&&!s.aborted&&o.down([[p,c]])})};return f(),()=>{a=!0,t?.removeEventListener("abort",i),r.abort(),Promise.resolve(d.return?.()).catch(()=>{})}},m(u))}function U(e){return e!=null&&typeof e=="object"&&"cache"in e&&typeof e.subscribe=="function"}function V(e,n){if(U(e))return e;if(W(e))return q(e,n);if(e!=null){let t=e;if(typeof t[Symbol.asyncIterator]=="function")return H(e,n);if(typeof t[Symbol.iterator]=="function")return D(e,n)}return B(e)}function B(...e){return D(e,void 0)}function oe(e){return b(n=>{n.down([[T]])},m(e))}function ie(e){return b(()=>{},m(e))}function se(e,n){return b(t=>{t.down([[p,e]])},m(n))}function ue(e,n){let{signal:t,...u}=n??{},o=m(u),r=o.resubscribable===void 0?{...o,resubscribable:!0}:o;return b(i=>{let s,a=!1;try{let d=e();s=V(d,n).subscribe(c=>{if(!a)for(let l of c){let v=l[0];if(v!==S)if(v===h)i.emit(l[1]);else if(v===T){a=!0,i.down([[T]]);break}else if(v===p){a=!0,i.down([[p,l[1]]]);break}else i.down([l])}})}catch(d){let f=d===void 0?new Error("defer: thunk threw undefined"):d;i.down([[p,f]])}return()=>{a=!0,s?.()}},r)}function ae(e,n,t){return w([e],(o,r)=>{let i=o[0];if(i!=null&&i.length>0)for(let s of i)n(s)},{describeKind:"effect",...t}).subscribe(()=>{})}function de(e,n){return w([e],(t,u,o)=>{o.store.buf||(o.store.buf=[]);let r=o.store.buf,i=t[0];if(i!=null&&i.length>0)for(let s of i)r.push(s);if(o.terminalDeps[0]===!0){u.emit([...r]),u.down([[T]]);return}(i==null||i.length===0)&&u.down([[x]])},{describeKind:"derived",completeWhenDepsComplete:!1,...n})}function fe(e,n){return b(t=>e.subscribe(u=>{t.down(u)}),{...m(n),initial:e.cache})}function F(e,n,t){if(n<1)throw new RangeError("replay expects bufferSize >= 1");let u=[],o=b(r=>e.subscribe(i=>{for(let s of i)s[0]===h&&(u.push(s[1]),u.length>n&&u.shift());r.down(i)}),{...m(t),initial:e.cache});return K(o,r=>{for(let i of u)r([[h,i]])})}function ce(e,n){return F(e,1,n)}function le(e){return new Promise((n,t)=>{let u=!1,o=!1,r;r=e.subscribe(i=>{for(let s of i){if(u)return;if(s[0]===h){u=!0,n(s[1]),r?(r(),r=void 0):o=!0;return}if(s[0]===p){u=!0,t(s[1]),r?(r(),r=void 0):o=!0;return}if(s[0]===T){u=!0,t(new Error("completed without DATA")),r?(r(),r=void 0):o=!0;return}}}),o&&(r?.(),r=void 0)})}function R(e,n,t){return new Promise((u,o)=>{let r=!1,i=!1,s,a=t?.skipCurrent===!0;s=e.subscribe(d=>{for(let f of d){if(r)return;if(!(a&&f[0]===h)){if(f[0]===h){let c=f[1];if(n(c)){r=!0,u(c),s?(s(),s=void 0):i=!0;return}}if(f[0]===p){r=!0,o(f[1]),s?(s(),s=void 0):i=!0;return}if(f[0]===T){r=!0,o(new Error("completed without matching value")),s?(s(),s=void 0):i=!0;return}}}}),a=!1,i&&(s?.(),s=void 0)})}var E,M;async function pe(e,n){let t=n?.predicate??(r=>r!=null),u=n?.skipCurrent;if(n?.timeoutMs==null||n.timeoutMs<=0)return await R(e,t,{skipCurrent:u});if(E===void 0){let[r,i]=await Promise.all([import("./resilience-
|
|
1
|
+
import{D as w,E as I,F as b,p as C}from"./chunk-LYCLF26R.js";import{a as S,b as h,c as A,d as x,i as T,j as p}from"./chunk-CK2E7BTU.js";function y(e,n,t){let u=new Set;for(let o of e.split(",")){let[r,i]=o.split("/"),s=i?Number.parseInt(i,10):1;if(Number.isNaN(s)||s<1)throw new Error(`Invalid cron step: ${o}`);let a,d;if(r==="*")a=n,d=t;else if(r.includes("-")){let[f,c]=r.split("-");a=Number.parseInt(f,10),d=Number.parseInt(c,10)}else a=Number.parseInt(r,10),d=a;if(Number.isNaN(a)||Number.isNaN(d))throw new Error(`Invalid cron field: ${e}`);if(a<n||d>t)throw new Error(`Cron field out of range: ${e} (${n}-${t})`);if(a>d)throw new Error(`Invalid cron range: ${a}-${d} in ${e}`);for(let f=a;f<=d;f+=s)u.add(f)}return u}function L(e){let n=e.trim().split(/\s+/);if(n.length!==5)throw new Error(`Invalid cron: expected 5 fields, got ${n.length}`);return{minutes:y(n[0],0,59),hours:y(n[1],0,23),daysOfMonth:y(n[2],1,31),months:y(n[3],1,12),daysOfWeek:y(n[4],0,6)}}function P(e,n){return e.minutes.has(n.getMinutes())&&e.hours.has(n.getHours())&&e.daysOfMonth.has(n.getDate())&&e.months.has(n.getMonth()+1)&&e.daysOfWeek.has(n.getDay())}function m(e){return{describeKind:"producer",...e}}function $(e){return/[\\^$+?.()|[\]{}]/.test(e)?`\\${e}`:e}function X(e){let n="^";for(let t=0;t<e.length;t+=1){let u=e[t];if(u==="*"){e[t+1]==="*"?(n+=".*",t+=1):n+="[^/]*";continue}n+=$(u)}return n+="$",new RegExp(n)}function Z(e,n){for(let t of n)if(t.test(e))return!0;return!1}function K(e,n){let t=w([e],(o,r)=>{let i=o[0];if(i==null||i.length===0){r.down([[x]]);return}for(let s of i)r.emit(s)},{describeKind:"derived",initial:e.cache}),u=t.subscribe.bind(t);return t.subscribe=(o,r)=>(n(o),u(o,r)),t}function ee(e,n){let{signal:t,period:u,...o}=n??{};return b(r=>{let i=!1,s=0,a,d,f=()=>{i=!0,a!==void 0&&clearTimeout(a),d!==void 0&&clearInterval(d),t?.removeEventListener("abort",l)},c=()=>{i||(u!=null?(r.emit(s++),d=setInterval(()=>{i||r.emit(s++)},u)):(i=!0,t?.removeEventListener("abort",l),r.emit(s++),r.down([[T]])))},l=()=>{i||(f(),r.down([[p,t.reason]]))};if(t?.aborted){l();return}return a=setTimeout(c,e),t?.addEventListener("abort",l,{once:!0}),f},m(o))}function ne(e){let{signal:n,...t}=e??{};return b(u=>{let o=!1,r,i,s=!1,a=!1,d=typeof requestAnimationFrame=="function"?requestAnimationFrame:void 0,f=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:void 0,c=typeof document<"u"?document:void 0,l=()=>{r!==void 0&&f&&f(r),i!==void 0&&clearTimeout(i),r=void 0,i=void 0},v=()=>{o=!0,l(),s&&(n?.removeEventListener("abort",N),s=!1),a&&c&&(c.removeEventListener("visibilitychange",k),a=!1)},N=()=>{o||(v(),u.down([[p,n.reason]]))},O=_=>{o||(u.emit(_),g())},g=()=>{o||(d&&(!c||c.visibilityState!=="hidden")?r=d(O):i=setTimeout(()=>O(performance.now()),16))},k=()=>{o||(l(),g())};return n?.aborted?(N(),v):(n?.addEventListener("abort",N,{once:!0}),s=n!==void 0,c&&d&&(c.addEventListener("visibilitychange",k),a=!0),g(),v)},m(t))}function te(e,n){let t=L(e),{tickMs:u,output:o,...r}=n??{},i=u??6e4,s=o==="date";return b(a=>{let d=-1,f=()=>{let l=new Date,v=l.getFullYear()*1e8+(l.getMonth()+1)*1e6+l.getDate()*1e4+l.getHours()*100+l.getMinutes();v!==d&&P(t,l)&&(d=v,a.emit(s?l:C()))};f();let c=setInterval(f,i);return()=>clearInterval(c)},{...m(r),name:r.name??`cron:${e}`})}function re(e,n,t){let{capture:u,passive:o,once:r,...i}=t??{};return b(s=>{let a=f=>{s.emit(f)},d={capture:u,passive:o,once:r};return e.addEventListener(n,a,d),()=>e.removeEventListener(n,a,d)},m(i))}function D(e,n){return b(t=>{let u=!1;try{for(let o of e){if(u)return;t.emit(o)}u||t.down([[T]])}catch(o){u||t.down([[p,o]])}return()=>{u=!0}},m(n))}function W(e){return e!=null&&typeof e.then=="function"}function q(e,n){let{signal:t,...u}=n??{};return b(o=>{let r=!1,i=()=>{r||(r=!0,o.down([[p,t.reason]]))};if(t?.aborted){i();return}return t?.addEventListener("abort",i,{once:!0}),Promise.resolve(e).then(s=>{r||(r=!0,t?.removeEventListener("abort",i),o.emit(s),o.down([[T]]))},s=>{r||(r=!0,t?.removeEventListener("abort",i),o.down([[p,s]]))}),()=>{r=!0,t?.removeEventListener("abort",i)}},m(u))}function H(e,n){let{signal:t,...u}=n??{};return b(o=>{let r=new AbortController,i=()=>r.abort(t?.reason);t?.aborted?r.abort(t.reason):t?.addEventListener("abort",i,{once:!0});let s=t??r.signal,a=!1,d=e[Symbol.asyncIterator](),f=()=>{a||s.aborted||Promise.resolve(d.next()).then(c=>{if(!(a||s.aborted)){if(c.done){o.down([[T]]);return}o.emit(c.value),f()}},c=>{!a&&!s.aborted&&o.down([[p,c]])})};return f(),()=>{a=!0,t?.removeEventListener("abort",i),r.abort(),Promise.resolve(d.return?.()).catch(()=>{})}},m(u))}function U(e){return e!=null&&typeof e=="object"&&"cache"in e&&typeof e.subscribe=="function"}function V(e,n){if(U(e))return e;if(W(e))return q(e,n);if(e!=null){let t=e;if(typeof t[Symbol.asyncIterator]=="function")return H(e,n);if(typeof t[Symbol.iterator]=="function")return D(e,n)}return B(e)}function B(...e){return D(e,void 0)}function oe(e){return b(n=>{n.down([[T]])},m(e))}function ie(e){return b(()=>{},m(e))}function se(e,n){return b(t=>{t.down([[p,e]])},m(n))}function ue(e,n){let{signal:t,...u}=n??{},o=m(u),r=o.resubscribable===void 0?{...o,resubscribable:!0}:o;return b(i=>{let s,a=!1;try{let d=e();s=V(d,n).subscribe(c=>{if(!a)for(let l of c){let v=l[0];if(v!==S)if(v===h)i.emit(l[1]);else if(v===T){a=!0,i.down([[T]]);break}else if(v===p){a=!0,i.down([[p,l[1]]]);break}else i.down([l])}})}catch(d){let f=d===void 0?new Error("defer: thunk threw undefined"):d;i.down([[p,f]])}return()=>{a=!0,s?.()}},r)}function ae(e,n,t){return w([e],(o,r)=>{let i=o[0];if(i!=null&&i.length>0)for(let s of i)n(s)},{describeKind:"effect",...t}).subscribe(()=>{})}function de(e,n){return w([e],(t,u,o)=>{o.store.buf||(o.store.buf=[]);let r=o.store.buf,i=t[0];if(i!=null&&i.length>0)for(let s of i)r.push(s);if(o.terminalDeps[0]===!0){u.emit([...r]),u.down([[T]]);return}(i==null||i.length===0)&&u.down([[x]])},{describeKind:"derived",completeWhenDepsComplete:!1,...n})}function fe(e,n){return b(t=>e.subscribe(u=>{t.down(u)}),{...m(n),initial:e.cache})}function F(e,n,t){if(n<1)throw new RangeError("replay expects bufferSize >= 1");let u=[],o=b(r=>e.subscribe(i=>{for(let s of i)s[0]===h&&(u.push(s[1]),u.length>n&&u.shift());r.down(i)}),{...m(t),initial:e.cache});return K(o,r=>{for(let i of u)r([[h,i]])})}function ce(e,n){return F(e,1,n)}function le(e){return new Promise((n,t)=>{let u=!1,o=!1,r;r=e.subscribe(i=>{for(let s of i){if(u)return;if(s[0]===h){u=!0,n(s[1]),r?(r(),r=void 0):o=!0;return}if(s[0]===p){u=!0,t(s[1]),r?(r(),r=void 0):o=!0;return}if(s[0]===T){u=!0,t(new Error("completed without DATA")),r?(r(),r=void 0):o=!0;return}}}),o&&(r?.(),r=void 0)})}function R(e,n,t){return new Promise((u,o)=>{let r=!1,i=!1,s,a=t?.skipCurrent===!0;s=e.subscribe(d=>{for(let f of d){if(r)return;if(!(a&&f[0]===h)){if(f[0]===h){let c=f[1];if(n(c)){r=!0,u(c),s?(s(),s=void 0):i=!0;return}}if(f[0]===p){r=!0,o(f[1]),s?(s(),s=void 0):i=!0;return}if(f[0]===T){r=!0,o(new Error("completed without matching value")),s?(s(),s=void 0):i=!0;return}}}}),a=!1,i&&(s?.(),s=void 0)})}var E,M;async function pe(e,n){let t=n?.predicate??(r=>r!=null),u=n?.skipCurrent;if(n?.timeoutMs==null||n.timeoutMs<=0)return await R(e,t,{skipCurrent:u});if(E===void 0){let[r,i]=await Promise.all([import("./resilience-JISHQD2F.js"),import("./backoff-HPZMEZNF.js")]);E=r.timeout,M=i.NS_PER_MS}let o=E(e,n.timeoutMs*M);return await R(o,t,{skipCurrent:u})}function be(e,n){let t=new AbortController,u=n?.reason??new Error("cancelled via nodeSignal"),o,r=!1,i=()=>{o?(o(),o=void 0):r=!0};return o=e.subscribe(s=>{if(!t.signal.aborted)for(let a of s){if(a[0]===h&&a[1]===!0){t.abort(u),i();return}if(a[0]===p){t.abort(a[1]),i();return}if(a[0]===T){i();return}}}),r&&(o?.(),o=void 0),{signal:t.signal,dispose:()=>{o&&(o(),o=void 0)}}}var me=F;function Te(e){return e.subscribe(()=>{})}function ve(e){let n=I(0);return{node:n,increment(){let t=n.cache??0;return t>=e?!1:(n.down([[A],[h,t+1]]),!0)},get(){return n.cache??0},atCap(){return(n.cache??0)>=e}}}export{L as a,P as b,$ as c,X as d,Z as e,ee as f,ne as g,te as h,re as i,D as j,q as k,H as l,V as m,B as n,oe as o,ie as p,se as q,ue as r,ae as s,de as t,fe as u,F as v,ce as w,le as x,R as y,pe as z,be as A,me as B,Te as C,ve as D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as v}from"./chunk-KRH66M4O.js";import{i as y}from"./chunk-CLD3F4R5.js";import{G as x}from"./chunk-
|
|
1
|
+
import{b as v}from"./chunk-KRH66M4O.js";import{i as y}from"./chunk-CLD3F4R5.js";import{G as x}from"./chunk-X7QKTXXC.js";import{d as S}from"./chunk-VJLMUKOI.js";import{d as O}from"./chunk-VIMF6LGM.js";import{d as k}from"./chunk-6QZNQS5B.js";import{d as A}from"./chunk-GPW2V3RE.js";import{b as N}from"./chunk-CGNOWGV6.js";import{E as b,J as g,m as _}from"./chunk-LYCLF26R.js";import{b as a,c as p,i as h,j as m}from"./chunk-CK2E7BTU.js";import{b as f}from"./chunk-QYADASLV.js";var j={};f(j,{jotai:()=>v,nanostores:()=>y,nestjs:()=>x,react:()=>S,signals:()=>T,solid:()=>O,svelte:()=>k,vue:()=>A,zustand:()=>N});var T={};f(T,{Signal:()=>q});var s=[];function i(n){let e=n.cache;return n.subscribe(o=>{for(let[d,r]of o)d===a&&(e=r)})(),e}var u=class{_node;_equals;constructor(e,t){this._equals=t?.equals??Object.is,this._node=b(e,{...t,resubscribable:!0,resetOnTeardown:!0})}get(){let e=s[s.length-1];return e?(this._node.status==="sentinel"&&i(this._node),e(this._node)):this._node.status==="sentinel"?i(this._node):this._node.cache}set(e){this._equals(this.get(),e)||_(()=>{this._node.down([[p],[a,e]])})}},l=class{_node;constructor(e,t){this._node=g(o=>{s.push(o);try{return e()}finally{s.pop()}},{...t,describeKind:"derived",resubscribable:!0,resetOnTeardown:!0})}get(){let e=s[s.length-1];return e?(this._node.status==="sentinel"&&i(this._node),e(this._node)):this._node.status==="sentinel"?i(this._node):this._node.cache}},q={State:u,Computed:l,sub:(n,e)=>{let t=typeof e=="function"?{data:e,error:void 0,complete:void 0}:e,o=!0;return n._node.subscribe(d=>{for(let[r,c]of d){if(r===a){if(o){o=!1;continue}t.data?.(c)}r===m&&t.error?.(c),r===h&&t.complete?.()}})}};export{T as a,j as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as O}from"./chunk-
|
|
1
|
+
import{c as O}from"./chunk-VXPLLA4P.js";import{f as B,m as K}from"./chunk-L77I47VU.js";import{p as b}from"./chunk-LYCLF26R.js";import{b as M,i as A,j as L}from"./chunk-CK2E7BTU.js";import{b as H}from"./chunk-QYADASLV.js";var Y={};H(Y,{processInstanceKeyOf:()=>J,processManager:()=>X});var J=i=>i.correlationId;function V(i){if(i==null)return Promise.resolve(void 0);let y=K(i);return new Promise((s,v)=>{let u=!1,f,r=()=>{f&&f()};f=y.subscribe(a=>{if(!u)for(let o of a){if(o[0]===M){u=!0,Promise.resolve().then(r),s(o[1]);return}if(o[0]===L){u=!0,Promise.resolve().then(r),v(o[1]);return}if(o[0]===A){u=!0,Promise.resolve().then(r),s(void 0);return}}})})}async function Q(i,y,s,v,u){let f;for(let r=0;r<=v;r++){if(r>0){let a=u[Math.min(r-1,u.length-1)]??0;a>0&&await new Promise(o=>setTimeout(o,a))}try{return await V(i(y,s))}catch(a){f=a}}return{outcome:"failure",error:f}}function X(i,y,s){let v=s.retryMax??0,u=s.backoffMs??[0],f=1024,r=new Map,a=new Set,o=new Map,k=O({name:`${y}_process_instances`,retainedLimit:f,graph:i}),j=0;function $(){return++j}function S(e,t,n){C(e,t,n,void 0)}function C(e,t,n,c){let d=b(),g={correlationId:e,state:t,status:n,startedAt:o.get(e)??d,updatedAt:d,t_ns:d,seq:$(),...s.handlerVersion!==void 0?{handlerVersion:s.handlerVersion}:{},...c!==void 0?{reason:c}:{}};k.append(g)}let _=`_process_${y}_started`;i.event(_),s.persistence?.eventStorage&&i.attachEventStorage(s.persistence.eventStorage);async function x(e,t,n,c){if(a.delete(e),r.delete(e),o.delete(e),s.compensate)try{await V(s.compensate(t,n)),C(e,t,"compensated",c)}catch{S(e,t,"errored")}else S(e,t,"errored")}async function D(e,t){if(a.has(e)){if(t.outcome==="failure"){let n=r.get(e)??s.initial;await x(e,n,t.error);return}if(t.outcome==="success"){if(r.set(e,t.state),t.emit)for(let n of t.emit)try{i._appendEvent(n.type,n.payload,{correlationId:e,aggregateId:e})}catch{}if(S(e,t.state,"running"),s.isTerminal?.(t.state)){a.delete(e),r.delete(e),o.delete(e),S(e,t.state,"terminated");return}if(t.schedule){let{afterMs:n,eventType:c}=t.schedule,d,g=B(n),m=p=>{for(let T of p)if(T[0]===M){if(d?d():queueMicrotask(()=>d?.()),!a.has(e))return;let E=r.get(e);if(E===void 0)return;let l=s.steps[c];if(!l)return;let w={type:c,payload:null,timestampNs:b(),seq:Number.NaN,correlationId:e,aggregateId:e};q(e,l,E,w)}};d=g.subscribe(m)}return}if(t.outcome==="terminate"){if(r.set(e,t.state),t.emit)for(let n of t.emit)try{i._appendEvent(n.type,n.payload,{correlationId:e,aggregateId:e})}catch{}a.delete(e),r.delete(e),o.delete(e),S(e,t.state,"terminated")}}}let h=new Map;function q(e,t,n,c){let g=(h.get(e)??Promise.resolve()).then(async()=>{let m=r.get(e);if(m===void 0||!a.has(e))return;let p;try{p=await Q(t,m,c,v,u)}catch(T){await x(e,r.get(e)??s.initial,T);return}await D(e,p)});h.set(e,g),g.finally(()=>{h.get(e)===g&&h.delete(e)})}let P=!1,R=[];for(let e of s.watching){let t=i.event(e),n=0;n=(t.cache??[]).length;let d=t.subscribe(g=>{for(let m of g){if(m[0]!==M)continue;let p=m[1];if(p.length<=n)continue;let T=p.slice(n);n=p.length;for(let E of T){let l=E.correlationId;if(l===void 0||!a.has(l))continue;let w=s.steps[e];if(!w)continue;let N=r.get(l);N!==void 0&&q(l,w,N,E)}}});R.push(d)}function W(e,t){if(P||a.has(e))return;let n=b();o.set(e,n),r.set(e,s.initial),a.add(e);try{i._appendEvent(_,t??null,{correlationId:e,aggregateId:e})}catch{}S(e,s.initial,"running")}function F(e,t){if(P||!a.has(e))return;let n=r.get(e)??s.initial;x(e,n,new Error(`cancelled: ${t??"no reason given"}`),t)}function U(e){return r.get(e)}function z(){if(!P){P=!0;for(let e of R)try{e()}catch{}R.length=0}}return{instances:k,audit:k,start:W,cancel:F,getState:U,dispose:z}}export{J as a,X as b,Y as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as G}from"./chunk-D27JNOLZ.js";import{i as z}from"./chunk-
|
|
1
|
+
import{a as G}from"./chunk-D27JNOLZ.js";import{i as z}from"./chunk-POXANAJ6.js";import{D as H,E as M,G as N,o as R}from"./chunk-LYCLF26R.js";function q(t){for(let c of t){let m=c.codePointAt(0);if(m>=19968&&m<=40959||m>=13312&&m<=19903||m>=12288&&m<=12351||m>=12352&&m<=12447||m>=12448&&m<=12543||m>=44032&&m<=55215||m>=65280&&m<=65519)return!0}return!1}var E=new Set(["\uFF0C","\uFF0E","\uFF01","\uFF1A","\uFF1B","\uFF1F","\u3001","\u3002","\u30FB","\uFF09","\u3015","\u3009","\u300B","\u300D","\u300F","\u3011"]),F=new Set([".",",","!","?",":",";",")","]","}","%",'"',"\u201D","\u2019","\xBB","\u203A","\u2026"]);function D(t){return t.replace(/[\t\n\r\f ]+/g," ").replace(/^ | $/g,"")}function O(t){let c=new Intl.Segmenter(void 0,{granularity:"word"}),m=[];for(let f of c.segment(t)){let h=f.segment,w=f.isWordLike??!1,u=[],s=[],r=[],p="",n=null;for(let i of h){let S;i===" "?S="space":i==="\u200B"?S="zero-width-break":i==="\xAD"?S="soft-hyphen":i===`
|
|
2
2
|
`?S="hard-break":S="text",n!==null&&S===n?p+=i:(n!==null&&(u.push(p),s.push(n==="text"&&w),r.push(n)),p=i,n=S)}n!==null&&(u.push(p),s.push(n==="text"&&w),r.push(n)),m.push({texts:u,isWordLike:s,kinds:r})}return m}function V(t,c,m,f,h){let w=D(t);if(w.length===0)return[];let u=O(w),s=new Intl.Segmenter(void 0,{granularity:"grapheme"}),r=[],p=[],n=[];for(let g of u)for(let o=0;o<g.texts.length;o++)r.push(g.texts[o]),p.push(g.kinds[o]),n.push(g.isWordLike[o]);let i=[],S=[],B=[];for(let g=0;g<r.length;g++){let o=r[g],y=p[g],I=n[g];if(y==="text"&&!I&&i.length>0&&S[S.length-1]==="text"&&o.length===1&&(F.has(o)||E.has(o))){i[i.length-1]+=o;continue}if(o==="-"&&i.length>0&&S[S.length-1]==="text"&&B[B.length-1]){i[i.length-1]+=o;continue}i.push(o),S.push(y),B.push(I)}let l=f.get(c);l||(l=new Map,f.set(c,l));function b(g){let o=l.get(g);if(o===void 0){h&&(h.misses+=1);let y=m.measureSegment(g,c).width;o=Number.isFinite(y)&&y>=0?y:0,l.set(g,o)}else h&&(h.hits+=1);return o}let d=[];for(let g=0;g<i.length;g++){let o=i[g],y=S[g];if(y!=="text"){d.push({text:o,width:y==="space"?b(" ")*o.length:0,kind:y,graphemeWidths:null});continue}if(q(o)){let a="";for(let x of s.segment(o)){let k=x.segment;if(a.length>0&&E.has(k)){a+=k;continue}if(a.length>0){let L=b(a);d.push({text:a,width:L,kind:"text",graphemeWidths:null})}a=k}if(a.length>0){let x=b(a);d.push({text:a,width:x,kind:"text",graphemeWidths:null})}continue}let I=b(o),e=null;if(B[g]&&o.length>1){let a=[];for(let x of s.segment(o))a.push(b(x.segment));a.length>1&&(e=a)}d.push({text:o,width:I,kind:"text",graphemeWidths:e})}return d}function J(t,c,m,f,h){if(t.length===0)return{lines:[],lineCount:0};let w=[],u=0,s=!1,r=0,p=0,n=0,i=0,S=-1,B=0,l=h.get(f);l||(l=new Map,h.set(f,l));let b=l.get("-");b===void 0&&(b=m.measureSegment("-",f).width,l.set("-",b));function d(e=n,a=i,x=u){let k="";for(let L=r;L<e;L++){let W=t[L];if(!(W.kind==="soft-hyphen"||W.kind==="hard-break"))if(L===r&&p>0&&W.graphemeWidths){let P=[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(W.text)].map(K=>K.segment);k+=P.slice(p).join("")}else k+=W.text}if(a>0&&e<t.length){let L=t[e],v=[...new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(L.text)].map(K=>K.segment),P=r===e?p:0;k+=v.slice(P,a).join("")}e>0&&t[e-1]?.kind==="soft-hyphen"&&!(r===e&&p>0)&&(k+="-"),w.push({text:k,width:x,startSegment:r,startGrapheme:p,endSegment:e,endGrapheme:a}),u=0,s=!1,S=-1,B=0}function g(e){return e==="space"||e==="zero-width-break"||e==="soft-hyphen"}function o(e,a,x){s=!0,r=e,p=a,n=e+1,i=0,u=x}function y(e,a,x){s=!0,r=e,p=a,n=e,i=a+1,u=x}for(let e=0;e<t.length;e++){let a=t[e];if(a.kind==="hard-break"){s?d():w.push({text:"",width:0,startSegment:e,startGrapheme:0,endSegment:e,endGrapheme:0}),r=e+1,p=0;continue}let x=a.width;if(!s){x>c&&a.graphemeWidths?I(e,0,a.graphemeWidths):o(e,0,x),g(a.kind)&&(S=e+1,B=a.kind==="space"?u-x:u);continue}let k=u+x;if(k>c+.005){if(g(a.kind)){u+=x,n=e+1,i=0,d(e+1,0,a.kind==="space"?u-x:u);continue}if(S>=0){d(S,0,B),e--;continue}if(x>c&&a.graphemeWidths){d(),I(e,0,a.graphemeWidths);continue}d(),e--;continue}u=k,n=e+1,i=0,g(a.kind)&&(S=e+1,B=a.kind==="space"?u-x:u)}return s&&d(),{lines:w,lineCount:w.length};function I(e,a,x){for(let k=a;k<x.length;k++){let L=x[k];if(!s){y(e,k,L);continue}u+L>c+.005?(d(),y(e,k,L)):(u+=L,n=e,i=k+1)}s&&n===e&&i===x.length&&(n=e+1,i=0)}}function A(t){return t==="space"||t==="zero-width-break"||t==="soft-hyphen"}var T=null;function _(){return T===null&&(T=new Intl.Segmenter(void 0,{granularity:"grapheme"})),T}function j(t,c,m){if(c===0&&m<0)return t.text;let f=[..._().segment(t.text)].map(w=>w.segment),h=m<0?f.length:m;return f.slice(c,h).join("")}function C(t,c,m,f,h,w){let u="";for(let s=c;s<f;s++){let r=t[s];r.kind==="soft-hyphen"||r.kind==="hard-break"||(s===c&&m>0?u+=j(r,m,-1):u+=r.text)}if(h>0&&f<t.length){let s=t[f];u+=j(s,c===f?m:0,h)}return w&&(u+="-"),u}function $(t){if(!t?.adapter||!t.font)return 0;let c=t.cache;if(c){let m=c.get(t.font);m||(m=new Map,c.set(t.font,m));let f=m.get("-");return f===void 0&&(f=t.adapter.measureSegment("-",t.font).width,m.set("-",f)),f}return t.adapter.measureSegment("-",t.font).width}function te(t,c,m,f){let h=c.segmentIndex,w=c.graphemeIndex;if(h>=t.length)return null;if(w===0){for(;h<t.length;){let e=t[h];if(e.kind==="hard-break")return{text:"",width:0,start:{segmentIndex:c.segmentIndex,graphemeIndex:0},end:{segmentIndex:h+1,graphemeIndex:0}};if(e.kind==="space"||e.kind==="zero-width-break"||e.kind==="soft-hyphen"){h+=1;continue}break}if(h>=t.length)return null}let u=$(f),s=h,r=h===c.segmentIndex?w:0,p=0,n=s,i=0,S=!1,B=-1,l=0,b=0,d=!1,g=(e,a,x,k)=>{B=e,l=a,b=x,d=k==="soft-hyphen"},o=(e,a,x)=>{for(let k=a;k<x.length;k++){let L=x[k];if(!S){p=L,n=e,i=k+1,S=!0;continue}if(p+L>m+.005)return!0;p+=L,n=e,i=k+1}return n===e&&i===x.length&&(n=e+1,i=0),!1};if(r>0&&s<t.length){let e=t[s];if(e.graphemeWidths){if(o(s,r,e.graphemeWidths))return{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}};h=n}}for(;h<t.length;){let e=t[h];if(e.kind==="hard-break"){if(S){let k=n>0&&t[n-1]?.kind==="soft-hyphen";return{text:C(t,s,r,n,i,k),width:p+(k?u:0),start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}return{text:"",width:0,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:h+1,graphemeIndex:0}}}let a=e.width;if(!S){if(a>m&&e.graphemeWidths){if(o(h,0,e.graphemeWidths))return{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}};h=n;continue}p=a,n=h+1,i=0,S=!0,A(e.kind)&&g(h+1,0,e.kind==="space"?p-a:p,e.kind),h+=1;continue}let x=p+a;if(x>m+.005){if(A(e.kind)){n=h+1,i=0;let L=e.kind==="soft-hyphen",W=e.kind==="space"?p:p+(L?u:0);return{text:C(t,s,r,n,i,L),width:W,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}return B>=0?{text:C(t,s,r,B,l,d),width:b+(d?u:0),start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:B,graphemeIndex:l}}:a>m&&e.graphemeWidths?{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}:{text:C(t,s,r,n,i,!1),width:p,start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}p=x,n=h+1,i=0,A(e.kind)&&g(h+1,0,e.kind==="space"?p-a:p,e.kind),h+=1}if(!S)return null;let y=n>0&&t[n-1]?.kind==="soft-hyphen";return{text:C(t,s,r,n,i,y),width:p+(y?u:0),start:{segmentIndex:s,graphemeIndex:r},end:{segmentIndex:n,graphemeIndex:i}}}function ne(t,c,m=0){let f=[t];for(let h=0;h<c.length;h++){let w=c[h],u=[];for(let s=0;s<f.length;s++){let r=f[s];if(w.right<=r.left||w.left>=r.right){u.push(r);continue}w.left>r.left&&u.push({left:r.left,right:w.left}),w.right<r.right&&u.push({left:w.right,right:r.right})}f=u}return m>0?f.filter(h=>h.right-h.left>=m):f}function Q(t,c,m){let f=[],h=new Intl.Segmenter(void 0,{granularity:"grapheme"});for(let w=0;w<t.lines.length;w++){let u=t.lines[w],s=w*m,r=0;for(let p=u.startSegment;p<c.length;p++){let n=c[p];if(n.kind==="soft-hyphen"||n.kind==="hard-break"){if(p>=u.endSegment&&u.endGrapheme===0)break;continue}let i=[...h.segment(n.text)].map(l=>l.segment);if(i.length===0)continue;let S=p===u.startSegment?u.startGrapheme:0,B;if(p<u.endSegment)B=i.length;else if(p===u.endSegment&&u.endGrapheme>0)B=u.endGrapheme;else break;for(let l=S;l<B;l++){let b=n.graphemeWidths?n.graphemeWidths[l]:n.width/i.length;f.push({x:r,y:s,width:b,height:m,line:w}),r+=b}}}return f}function re(t){let{adapter:c,name:m="reactive-layout"}=t,f=new z(m),h=new Map,w=M(t.text??"",{name:"text"}),u=M(t.font??"16px sans-serif",{name:"font"}),s=M(t.lineHeight??20,{name:"line-height"}),r=M(Math.max(0,t.maxWidth??800),{name:"max-width"});function p(l,b){if(l===null||b===null)return l===b;if(l.length!==b.length)return!1;for(let d=0;d<l.length;d++)if(l[d]!==b[d])return!1;return!0}let n=H([w,u],(l,b,d)=>{let g=l[0],o=g!=null&&g.length>0?g.at(-1):d.prevData[0],y=l[1],I=y!=null&&y.length>0?y.at(-1):d.prevData[1],e=R(),a={hits:0,misses:0},x=V(o,I,c,h,a),k=R()-e,L=a.hits+a.misses,W=L===0?1:a.hits/L,v=n.meta;v&&(G(v["cache-hit-rate"],W),G(v["segment-count"],x.length),G(v["layout-time-ns"],k)),b.emit(x);let P=()=>{h.clear(),c.clearCache?.()};return{deactivate:P,invalidate:P}},{name:"segments",describeKind:"derived",meta:{"cache-hit-rate":0,"segment-count":0,"layout-time-ns":0},equals:(l,b)=>{let d=l,g=b;if(d==null||g==null)return d===g;if(d.length!==g.length)return!1;for(let o=0;o<d.length;o++){let y=d[o],I=g[o];if(y.text!==I.text||y.width!==I.width||y.kind!==I.kind||!p(y.graphemeWidths??null,I.graphemeWidths??null))return!1}return!0}}),i=N([n,r,u],([l,b,d])=>J(l,b,c,d,h),{name:"line-breaks",equals:(l,b)=>{let d=l,g=b;if(d==null||g==null)return d===g;if(d.lineCount!==g.lineCount)return!1;for(let o=0;o<d.lines.length;o++){let y=d.lines[o],I=g.lines[o];if(y.text!==I.text||y.width!==I.width||y.startSegment!==I.startSegment||y.startGrapheme!==I.startGrapheme||y.endSegment!==I.endSegment||y.endGrapheme!==I.endGrapheme)return!1}return!0}}),S=N([i,s],([l,b])=>l.lineCount*b,{name:"height"}),B=N([i,n,s],([l,b,d])=>Q(l,b,d),{name:"char-positions",equals:(l,b)=>{let d=l,g=b;if(d==null||g==null)return d===g;if(d.length!==g.length)return!1;for(let o=0;o<d.length;o++)if(d[o].x!==g[o].x||d[o].y!==g[o].y||d[o].width!==g[o].width)return!1;return!0}});return f.add(w,{name:"text"}),f.add(u,{name:"font"}),f.add(s,{name:"line-height"}),f.add(r,{name:"max-width"}),f.add(n,{name:"segments"}),f.add(i,{name:"line-breaks"}),f.add(S,{name:"height"}),f.add(B,{name:"char-positions"}),{graph:f,setText:l=>f.set("text",l),setFont:l=>f.set("font",l),setLineHeight:l=>f.set("line-height",l),setMaxWidth:l=>f.set("max-width",Math.max(0,l)),segments:n,lineBreaks:i,height:S,charPositions:B}}export{V as a,J as b,te as c,ne as d,Q as e,re as f};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as we}from"./chunk-SGS4OJGS.js";import{a as Me}from"./chunk-ESMPEKEV.js";import{
|
|
1
|
+
import{a as we}from"./chunk-SGS4OJGS.js";import{a as Me}from"./chunk-ESMPEKEV.js";import{C as ne}from"./chunk-L77I47VU.js";import{a as ve,d as ye}from"./chunk-35JTVPOX.js";import{A as ge,C as M,E as Z,F as me,G as be,e as $e,f as xe,i as Q,k as Ae,l as te,m as Te,o as z,p as Pe,s as U}from"./chunk-LYCLF26R.js";import{b as q,c as le,d as pe,e as ee,f as fe,g as he,h as L,i as H,j as W}from"./chunk-CK2E7BTU.js";function Oe(o,e){if(Object.is(o,e))return!0;if(o==null||e==null||typeof o!="object"||typeof e!="object")return!1;if(Array.isArray(o)){if(!Array.isArray(e)||o.length!==e.length)return!1;for(let r=0;r<o.length;r++)if(!Oe(o[r],e[r]))return!1;return!0}if(Array.isArray(e))return!1;let t=Object.keys(o),n=Object.keys(e);if(t.length!==n.length)return!1;let s=new Set(n);for(let r of t)if(!s.has(r)||!Oe(o[r],e[r]))return!1;return!0}function je(o,e){return`${o}\0${e}`}function _e(o,e){let t=[],n=new Set(o.subgraphs),s=new Set(e.subgraphs),r=[];for(let l of s)n.has(l)||r.push(l);r.sort();for(let l of r)t.push({type:"subgraph-mounted",path:l});let i=new Set(Object.keys(o.nodes)),c=new Set(Object.keys(e.nodes)),d=[];for(let l of c)i.has(l)||d.push(l);d.sort();for(let l of d)t.push({type:"node-added",path:l,node:{...e.nodes[l]}});let a=[];for(let l of c){if(!i.has(l))continue;let O=o.nodes[l]?.meta,m=e.nodes[l]?.meta;O==null&&m==null||Oe(O??{},m??{})||a.push(l)}a.sort();for(let l of a)t.push({type:"node-meta-changed",path:l,prevMeta:o.nodes[l]?.meta??{},nextMeta:e.nodes[l]?.meta??{}});let p=new Map;for(let l of o.edges)p.set(je(l.from,l.to),l);let g=new Map;for(let l of e.edges)g.set(je(l.from,l.to),l);let h=[];for(let[l,O]of g)p.has(l)||h.push(O);h.sort((l,O)=>l.from<O.from?-1:l.from>O.from?1:l.to<O.to?-1:l.to>O.to?1:0);for(let l of h)t.push({type:"edge-added",from:l.from,to:l.to});let f=[];for(let[l,O]of p)g.has(l)||f.push(O);f.sort((l,O)=>l.from<O.from?-1:l.from>O.from?1:l.to<O.to?-1:l.to>O.to?1:0);for(let l of f)t.push({type:"edge-removed",from:l.from,to:l.to});let u=[];for(let l of i)c.has(l)||u.push(l);u.sort();for(let l of u)t.push({type:"node-removed",path:l});let y=[];for(let l of n)s.has(l)||y.push(l);y.sort();for(let l of y)t.push({type:"subgraph-unmounted",path:l});return{events:t,flushedAt_ns:z()}}function Fe(o,e,t,n={}){let s=e in o.nodes,r=t in o.nodes;if(!s)return re(e,t,"no-such-from");if(!r)return re(e,t,"no-such-to");let i=n.maxDepth;if(i!=null&&(!Number.isInteger(i)||i<0))throw new Error("explainPath: maxDepth must be an integer >= 0");if(e===t){if(n.findCycle===!0){let a=Xe(o,e,n);if(a!=null)return a}let d=se(e,o.nodes[e],0,n);return oe(e,t,[d])}if(i===0)return re(e,t,"no-path");let c=Ie(o,e,t,i);return c.found?oe(e,t,Be(o,c.pathOrder,n)):re(e,t,c.truncated?"max-depth-exceeded":"no-path")}function Ie(o,e,t,n){let s=new Map,r=[{path:t,depth:0}],i=new Set([t]),c=0,d=!1;for(;c<r.length;){let g=r[c++];if(g.path===e)break;if(n!=null&&g.depth>=n){let y=o.nodes[g.path];y?.deps&&y.deps.length>0&&(d=!0);continue}let h=o.nodes[g.path];if(h==null)continue;let f=h.deps??[],u=new Map;for(let y=0;y<f.length;y++){let l=f[y];if(!l)continue;let O=u.get(l);O==null&&(O=[],u.set(l,O)),O.push(y)}for(let[y,l]of u)i.has(y)||(i.add(y),s.set(y,{from:g.path,depIndices:l}),r.push({path:y,depth:g.depth+1}))}if(!s.has(e))return{found:!1,pathOrder:[],truncated:d};let a=[{path:e}],p=e;for(;p!==t;){let g=s.get(p);if(g==null)return{found:!1,pathOrder:[],truncated:!1};a[a.length-1].depIndices=g.depIndices,a.push({path:g.from}),p=g.from}return{found:!0,pathOrder:a,truncated:!1}}function Xe(o,e,t){let n=o.nodes[e];if(n==null)return null;let s=n.deps??[],r=[];for(let c=0;c<s.length;c++)s[c]===e&&r.push(c);if(r.length>0){let c=se(e,n,0,t);c.dep_index=r[0];let d=se(e,n,1,t);return oe(e,e,[c,d])}let i=null;for(let c=0;c<s.length;c++){let d=s[c];if(!d||d===e)continue;let a=Ie(o,d,e,t.maxDepth);a.found&&(i==null||a.pathOrder.length<i.pathOrder.length)&&(i=a,i={found:!0,pathOrder:[{path:e,depIndices:[c]},...a.pathOrder],truncated:!1})}return i==null?null:oe(e,e,Be(o,i.pathOrder,t))}function Be(o,e,t){return e.map((n,s)=>{let r=o.nodes[n.path],i=se(n.path,r,s,t);return n.depIndices!=null&&n.depIndices.length>0&&(i.dep_index=n.depIndices[0],n.depIndices.length>1&&(i.dep_indices=[...n.depIndices])),i})}function se(o,e,t,n){let s={path:o,type:e.type,hop:t};e.status!==void 0&&(s.status=e.status),"value"in e&&(s.value=e.value),e.v!=null&&(s.v=e.v);let r=n.annotations?.get(o)??e.annotation;r!=null&&(s.annotation=r);let i=n.lastMutations?.get(o)??e.lastMutation;return i!=null&&(s.lastMutation=i),s}function oe(o,e,t){return Le(o,e,!0,"ok",t)}function re(o,e,t){return Le(o,e,!1,t,[])}function Le(o,e,t,n,s){let r=et(o,e,t,n,s);return{from:o,to:e,found:t,reason:n,steps:s,text:r,toJSON(){return{from:o,to:e,found:t,reason:n,steps:s}}}}function et(o,e,t,n,s){if(!t)switch(n){case"no-such-from":return`explainPath: no node named "${o}"`;case"no-such-to":return`explainPath: no node named "${e}"`;case"max-depth-exceeded":return`explainPath: no path from "${o}" to "${e}" within maxDepth`;default:return`explainPath: no path from "${o}" to "${e}"`}let r=[`Causal path: ${o} \u2192 ${e} (${s.length} step(s))`];for(let i of s){let d=` ${i.hop===0?"\xB7":"\u2193"} ${i.path} (${i.type}${i.status?`/${i.status}`:""})`;if(r.push(d),"value"in i&&r.push(` value: ${tt(i.value)}`),i.annotation!=null&&r.push(` annotation: ${i.annotation}`),i.lastMutation!=null){let a=i.lastMutation.actor;r.push(` actor: ${a.type}${a.id?`:${a.id}`:""}`)}}return r.join(`
|
|
2
2
|
`)}function tt(o){if(o===void 0)return"<sentinel>";if(o===null)return"null";if(typeof o=="string")return JSON.stringify(o);if(typeof o=="number"||typeof o=="boolean"||typeof o=="bigint")return String(o);try{let e=JSON.stringify(o);return e.length>80?`${e.slice(0,77)}...`:e}catch{return String(o)}}var A={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},nt=Symbol.for("sizeof");function ze(o){let e=new WeakSet,t=new WeakSet,n=[o],s=0;for(;n.length>0;){let r=n.pop();s+=rt(r,e,t,n)}return s}function rt(o,e,t,n){if(o==null)return 0;switch(typeof o){case"number":return A.number;case"boolean":return A.boolean;case"string":return A.string+o.length*2;case"bigint":return A.bigint+st(o);case"symbol":return A.symbol;case"function":return e.has(o)?0:(e.add(o),A.function);case"undefined":return 0}let r=o;if(e.has(r))return 0;e.add(r);let i=r[nt];if(typeof i=="function")try{let a=i.call(r);if(typeof a=="number"&&Number.isFinite(a))return a}catch{}if(r instanceof Date)return A.date;if(r instanceof RegExp)return A.regexp+r.source.length*2;if(r instanceof Error){let a=r.message?r.message.length*2:0,p=r.stack?r.stack.length*2:0;return A.error+a+p}if(typeof URL<"u"&&r instanceof URL)return A.url+r.href.length*2;if(typeof Promise<"u"&&r instanceof Promise)return A.promise;if(r instanceof WeakMap)return A.weakmap;if(r instanceof WeakSet)return A.weakset;if(r instanceof Map){let a=A.map;for(let[p,g]of r)a+=A.mapEntry,n.push(p),n.push(g);return a}if(r instanceof Set){let a=A.set;for(let p of r)a+=A.setEntry,n.push(p);return a}if(Array.isArray(r)){let a=A.array+r.length*8;for(let p of r)n.push(p);return a}if(r instanceof ArrayBuffer)return t.has(r)?0:(t.add(r),r.byteLength);if(ArrayBuffer.isView(r)){let a=r;return t.has(a.buffer)?48:(t.add(a.buffer),a.buffer.byteLength+48)}let c=A.object,d=Object.keys(r);for(let a of d){c+=A.string+a.length*2;try{n.push(r[a])}catch{}}return c}function st(o){let e=o<0n?-o:o;if(e===0n)return 0;let t=e.toString(2).length;return Math.ceil(t/32)*8}function Ve(o,e){let t=e?.topN??10,n=o.describe({detail:"standard"}),s=[],r=o._collectObserveTargets;typeof r=="function"&&r.call(o,"",s);let i=new Map;for(let[h,f]of s)i.set(h,f);let c=[];for(let[h,f]of Object.entries(n.nodes)){let u=i.get(h),y=u instanceof M?u:null,l=y?ze(y.cache):0,O=y?y._sinkCount:0,m=f.deps?.length??0,b=f.type==="effect"&&O===0,v=O===0?f.type==="effect"?"orphan-effect":f.type==="derived"?"idle-derived":f.type==="producer"?"idle-producer":null:null;c.push({path:h,type:f.type,status:f.status??"unknown",valueSizeBytes:l,subscriberCount:O,depCount:m,isOrphanEffect:b,orphanKind:v})}let d=c.reduce((h,f)=>h+f.valueSizeBytes,0),a=(h,f)=>[...c].sort(f??((u,y)=>y[h]-u[h])).slice(0,t),p=c.filter(h=>h.orphanKind!=null),g=c.filter(h=>h.isOrphanEffect);return{nodeCount:c.length,edgeCount:n.edges.length,subgraphCount:n.subgraphs.length,nodes:c,totalValueSizeBytes:d,hotspots:{byValueSize:a("valueSizeBytes"),bySubscriberCount:a("subscriberCount"),byDepCount:a("depCount")},orphans:p,orphanEffects:g}}var $="::",B="__meta__",J=1;function qe(o,e){let t=Math.max(16,o.size*4),n=0;for(;o.size>0;){if(n++>=t){console.error(`[Graph "${e}".destroy] disposer drain exceeded cap (${t}); ${o.size} disposer(s) discarded`),o.clear();return}let s=o.values().next();if(s.done)return;let r=s.value;o.delete(r);try{r()}catch(i){console.error(`[Graph "${e}".destroy] disposer threw:`,i)}}}function Ye(o){return o!=null&&typeof o=="object"&&"cache"in o&&typeof o.subscribe=="function"&&typeof o.down=="function"}function ot(o){if(o!=null)return Ye(o)?o.cache:o}function K(o){return o!=null&&typeof o=="object"&&"cache"in o&&typeof o.subscribe=="function"&&typeof o.down=="function"}function V(o){return K(o)?o.cache??"":o}function Ke(o){return K(o)?o.cache??0:o}function He(o){return K(o)?o.cache??!1:o}function it(o){let e=[];for(let t of Object.keys(o).sort()){let n=o[t].v;n!=null&&e.push(`${t} ${n.id} ${n.version}`)}return e.join(`
|
|
3
3
|
`)}function We(o){if(o.version!==J)throw new Error(`unsupported snapshot version ${String(o.version)} (expected ${J})`);for(let e of["name","nodes","edges","subgraphs"])if(!(e in o))throw new Error(`snapshot missing required key "${e}"`);if(typeof o.name!="string")throw new TypeError("snapshot 'name' must be a string");if(typeof o.nodes!="object"||o.nodes===null||Array.isArray(o.nodes))throw new TypeError("snapshot 'nodes' must be an object");if(!Array.isArray(o.edges))throw new TypeError("snapshot 'edges' must be an array");if(!Array.isArray(o.subgraphs))throw new TypeError("snapshot 'subgraphs' must be an array")}function at(o,e){let t=new WeakMap,n=(s,r)=>{if(Object.is(s,r))return!0;if(s==null||r==null||typeof s!="object"||typeof r!="object")return!1;let i=t.get(s);if(i==null&&(i=new WeakSet,t.set(s,i)),i.has(r))return!0;i.add(r);let c=s.constructor,d=r.constructor;if(c!==d)return!1;if(s instanceof Date)return s.getTime()===r.getTime();if(s instanceof RegExp)return s.source===r.source&&s.flags===r.flags;if(Array.isArray(s)){let h=r;if(s.length!==h.length)return!1;for(let f=0;f<s.length;f++)if(!n(s[f],h[f]))return!1;return!0}if(s instanceof Map){let h=r;if(s.size!==h.size)return!1;for(let[f,u]of s)if(!h.has(f)||!n(u,h.get(f)))return!1;return!0}if(s instanceof Set){let h=r;if(s.size!==h.size)return!1;for(let f of s){let u=!1;for(let y of h)if(n(f,y)){u=!0;break}if(!u)return!1}return!0}if(ArrayBuffer.isView(s)){let h=s,f=r;if(h.length!==f.length)return!1;for(let u=0;u<h.length;u++)if(h[u]!==f[u])return!1;return!0}let a=Object.keys(s),p=Object.keys(r);if(a.length!==p.length)return!1;let g=new Set(p);for(let h of a)if(!g.has(h)||!n(s[h],r[h]))return!1;return!0};return n(o,e)}function ut(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ie(o){let e="^";for(let t=0;t<o.length;t+=1){let n=o[t];if(n==="*"){e+=".*";continue}if(n==="?"){e+=".";continue}if(n==="["){let s=o.indexOf("]",t+1);if(s<=t+1){e+="\\[";continue}let r=o.slice(t+1,s);r.startsWith("!")&&(r=`^${r.slice(1)}`),r=r.replace(/\\/g,"\\\\"),e+=`[${r}]`,t=s;continue}e+=ut(n)}return e+="$",new RegExp(e)}var ct={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"},dt={data:"",dirty:"",resolved:"",invalidate:"",pause:"",resume:"",complete:"",error:"",teardown:"",derived:"",path:"",reset:""};function Ee(o){if(typeof o=="string")return JSON.stringify(o);if(typeof o=="number"||typeof o=="boolean"||o==null)return String(o);try{return JSON.stringify(o)}catch{return"[unserializable]"}}function lt(o){return o==="none"?dt:o==="ansi"||o==null?ct:{data:o.data??"",dirty:o.dirty??"",resolved:o.resolved??"",invalidate:o.invalidate??"",pause:o.pause??"",resume:o.resume??"",complete:o.complete??"",error:o.error??"",teardown:o.teardown??"",derived:o.derived??"",path:o.path??"",reset:o.reset??""}}function Ue(o){if(o==null)return{};let e=o.detail;return e==="full"?{...o,structured:o.structured??!0,timeline:o.timeline??!0,causal:o.causal??!0,derived:o.derived??!0}:e==="minimal"?{...o,structured:o.structured??!0}:o.format==="stage-log"?{...o,structured:o.structured??!0,timeline:o.timeline??!0}:o}function pt(o,e,t){for(let n=0;n<o.length;n++){let s=o.charCodeAt(n);if(s<32||s===127)throw new Error(`Graph "${e}": ${t} "${o}" must not contain control character (U+${s.toString(16).padStart(4,"0").toUpperCase()} at index ${n})`)}}function ke(o,e,t){if(o==="")throw new Error(`Graph "${e}": ${t} name must be non-empty`);if(o.includes($))throw new Error(`Graph "${e}": ${t} "${o}" must not contain '${$}' (path separator)`);if(o===B)throw new Error(`Graph "${e}": ${t} name "${B}" is reserved for meta companion paths`);pt(o,e,t)}function ft(o,e){if(o==="")throw new Error(`Graph "${e}": resolve path must be non-empty`);let t=o.split($);for(let n of t)if(n==="")throw new Error(`Graph "${e}": resolve path has empty segment`);return t}function ht(o,e){let t=!1;for(let s of o)if(!e.isMetaPassthrough(s[0])){t=!0;break}return t?o.filter(s=>e.isMetaPassthrough(s[0])):o}function Qe(o){for(let e of o._mounts.values())Qe(e);for(let e of o._nodes.values())try{e.down([[L]],{internal:!0})}catch{}}var Se=class o{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($))throw new Error(`Graph name must not contain '${$}' (got "${e}")`);if(e===B)throw new Error(`Graph name "${B}" is reserved for meta companion paths`);this.name=e,this.opts=Object.freeze({...t??{}}),this.config=t?.config??ge,this._traceRing=new we(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=me(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 r=s,i=t?.annotation;if(ke(r,this.name,"add"),this._mounts.has(r))throw new Error(`Graph "${this.name}": name "${r}" is already a mount point`);if(this._nodes.has(r))throw new Error(`Graph "${this.name}": node "${r}" already exists`);let c=this._nodeToName.get(e);if(c!==void 0)throw new Error(`Graph "${this.name}": node instance already registered as "${c}"`);return this._nodes.set(r,e),this._nodeToName.set(e,r),this._emitTopology({kind:"added",name:r,nodeKind:"node"}),i!=null&&(this._annotations.set(r,i),this.config.inspectorEnabled&&this._traceRing.push({path:r,annotation:i,timestamp_ns:z()})),e}setVersioning(e){if(e!=null)for(let t of this._nodes.values())t instanceof M&&t._applyVersioning(e)}remove(e){ke(e,this.name,"remove");let t=this._mounts.get(e);if(t){let r={kind:"mount",nodes:[],mounts:[]},i=[];t._collectObserveTargets("",i);for(let[c,d]of i)c.includes(`${$}${B}${$}`)||r.nodes.push(c);return r.nodes.sort(),r.mounts.push(e),r.mounts.push(...t._collectSubgraphs(`${e}${$}`)),this._mounts.delete(e),t._parent=void 0,Qe(t),this._emitTopology({kind:"removed",name:e,nodeKind:"mount",audit:r}),r}let n=this._nodes.get(e);if(!n)throw new Error(`Graph "${this.name}": unknown node or mount "${e}"`);this._nodes.delete(e),this._nodeToName.delete(n),n.down([[L]],{internal:!0});let s={kind:"node",nodes:[e],mounts:[]};return this._emitTopology({kind:"removed",name:e,nodeKind:"node",audit:s}),s}removeAll(e){let t=typeof e=="function"?e:(()=>{let r=ie(e);return i=>r.test(i)})(),n={kind:"mount",nodes:[],mounts:[]},s=[...this._nodes.keys(),...this._mounts.keys()].filter(r=>t(r));for(let r of s){let i=this.remove(r);n.nodes.push(...i.nodes),n.mounts.push(...i.mounts)}return n.nodes.sort(),n.mounts.sort(),n}[Symbol.iterator](){let e=[...this._nodes.keys()].sort(),t=this._nodes,n=0;return{[Symbol.iterator](){return this},next(){if(n>=e.length)return{value:void 0,done:!0};let s=e[n++];return{value:[s,t.get(s)],done:!1}}}}node(e){if(e==="")throw new Error(`Graph "${this.name}": node name must be non-empty`);if(e.includes($))return this.resolve(e);let t=this._nodes.get(e);if(!t)throw new Error(`Graph "${this.name}": unknown node "${e}"`);return t}get(e){return this.node(e).cache}set(e,t,n){let s=n?.internal===!0;this.node(e).down([[q,t]],{actor:n?.actor,internal:s,delivery:"write"})}setAll(e,t){let n=Symbol.iterator in e?e:Object.entries(e);Te(()=>{for(let[s,r]of n)this.set(s,r,t)})}invalidate(e,t){let n=t?.internal===!0;this.node(e).down([[ee]],{actor:t?.actor,internal:n,delivery:"write"})}error(e,t,n){let s=n?.internal===!0;this.node(e).down([[W,t]],{actor:n?.actor,internal:s,delivery:"write"})}complete(e,t){let n=t?.internal===!0;this.node(e).down([[H]],{actor:t?.actor,internal:n,delivery:"write"})}edges(e){let t=e?.recursive===!0,n=new Map;if(!t){for(let[d,a]of this._nodes)n.set(a,d);let c=[];for(let[d,a]of this._nodes)if(a instanceof M)for(let p of a._deps){let g=n.get(p.node);g!=null&&c.push([g,d])}return c.sort((d,a)=>d[0]<a[0]?-1:d[0]>a[0]?1:d[1]<a[1]?-1:d[1]>a[1]?1:0),c}let s=[];this._collectObserveTargets("",s);let r=new Map;for(let[c,d]of s)r.set(d,c);let i=[];for(let[c,d]of s)if(d instanceof M)for(let a of d._deps){let p=r.get(a.node);p!=null&&i.push([p,c])}return i.sort((c,d)=>c[0]<d[0]?-1:c[0]>d[0]?1:c[1]<d[1]?-1:c[1]>d[1]?1:0),i}mount(e,t){if(t===void 0){let s=new o(e);return this.mount(e,s)}if(typeof t=="function"){let s=new o(e);return t(s),this.mount(e,s)}let n=t;if(ke(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=ft(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 c=this._nodes.get(n);if(c)return c;throw this._mounts.has(n)?new Error(`Graph "${this.name}": path ends at subgraph "${n}" \u2014 not a node (GRAPHREFLY-SPEC \xA73.5)`):new Error(`Graph "${this.name}": unknown name "${n}"`)}let r=this._nodes.get(n);if(r&&s.length>0&&s[0]===B)return this._resolveMetaChainFromNode(r,s,t.join($));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($)}" is invalid`):new Error(`Graph "${this.name}": unknown mount or node "${n}"`);return i.resolve(s.join($))}_resolveMetaChainFromNode(e,t,n){let s=e,r=0,i=[...t];for(;r<i.length;){if(i[r]!==B)throw new Error(`Graph "${this.name}": expected ${B} segment in meta path "${n}"`);if(r+1>=i.length)throw new Error(`Graph "${this.name}": meta path requires a key after ${B} in "${n}"`);let c=i[r+1],d=s.meta[c];if(!d)throw new Error(`Graph "${this.name}": unknown meta "${c}" in path "${n}"`);s=d,r+=2}return s}signal(e,t){if(t?.internal!==!0){for(let s of e)if(this.config.messageTier(s[0])===3)throw new Error(`Graph "${this.name}": Graph.signal() rejects tier-3 messages (DATA / RESOLVED). Broadcast is for control-plane tiers (START / DIRTY / INVALIDATE / PAUSE / RESUME / COMPLETE / ERROR / TEARDOWN). For per-node value writes, use Graph.set or graph.node(name).down(...).`)}let n=[];if(this._signalDeliver(e,t??{},new Set,n),n.length>0)throw n[0]}_signalDeliver(e,t,n,s){for(let d of this._mounts.values())d._signalDeliver(e,t,n,s);let i=t.internal===!0?{internal:!0}:{actor:t.actor,delivery:"signal"},c=ht(e,this.config);for(let d of[...this._nodes.keys()].sort()){let a=this._nodes.get(d);if(!n.has(a)){n.add(a);try{a.down(e,i)}catch(p){if(p instanceof U)throw p;s.push(p)}c.length!==0&&this._signalMetaSubtree(a,c,n,i,s)}}}_signalMetaSubtree(e,t,n,s,r){for(let i of Object.keys(e.meta).sort()){let c=e.meta[i];if(!n.has(c)){n.add(c);try{c.down(t,s)}catch(d){if(d instanceof U)throw d;r.push(d)}this._signalMetaSubtree(c,t,n,s,r)}}}describe(e){if(e?.reactive==="diff")return this._describeReactiveDiff(e);if(e?.reactive===!0)return this._describeReactive(e);let t=ot(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=ve(e?.detail,e?.fields),r=e?.detail==="spec",i=s,c=[];this._collectObserveTargets("",c);let d=new Map;for(let[v,w]of c)d.set(w,v);let a=[];{let v=c.map(([,S])=>S),w=new Set(d.values()),E=0;for(;v.length>0;){let S=v.shift();if(S instanceof M)for(let R of S._deps){let G=R.node;if(d.has(G))continue;let D=G.name??"",k=D;if(!k||w.has(k))if(D){let I=2;for(;w.has(`${D}#${I}`);)I++;k=`${D}#${I}`}else for(k=`__internal__/${E++}`;w.has(k);)k=`__internal__/${E++}`;d.set(G,k),w.add(k),a.push([k,G]),v.push(G)}}}let p=[...c,...a],g={};for(let[v,w]of p){if(t!=null&&!w.allowsObserve(t))continue;let E=ye(w,i,r),S=w instanceof M?w._deps.map(k=>d.get(k.node)??k.node.name??""):[],{name:R,...G}=E,D={...G,deps:S};if(!r){let k=this._annotations.get(v);k!=null&&(D.annotation=k)}if(n!=null)if(typeof n=="function"){let k=n;if(!(k.length>=2?k(v,D):k(D)))continue}else{let k=!0;for(let[I,T]of Object.entries(n)){let x=I==="deps_includes"?"depsIncludes":I==="meta_has"?"metaHas":I;if(x==="depsIncludes"){if(!D.deps.includes(String(T))){k=!1;break}continue}if(x==="metaHas"){if(!Object.hasOwn(D.meta??{},String(T))){k=!1;break}continue}if(D[x]!==T){k=!1;break}}if(!k)continue}g[v]=D}let h=new Set(Object.keys(g)),f=[];for(let[v,w]of p)if(w instanceof M)for(let E of w._deps){let S=d.get(E.node);S!=null&&f.push([S,v])}f.sort((v,w)=>v[0]<w[0]?-1:v[0]>w[0]?1:v[1]<w[1]?-1:v[1]>w[1]?1:0);let u=f.map(([v,w])=>({from:v,to:w}));(t!=null||n!=null)&&(u=u.filter(v=>h.has(v.from)&&h.has(v.to)));let y=this._collectSubgraphs(""),l=t!=null||n!=null?y.filter(v=>{let w=`${v}${$}`;return[...h].some(E=>E===v||E.startsWith(w))}):y,O=this,m=e;return{name:this.name,nodes:g,edges:u,subgraphs:l,...this._factory!==void 0?{factory:this._factory}:{},...this._factoryArgs!==void 0?{factoryArgs:this._factoryArgs}:{},expand(v){let w={...m};return Array.isArray(v)?(w.fields=v,w.detail=void 0):(w.detail=v,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}${$}`))}return t}resourceProfile(e){return Ve(this,e)}reachable(e,t,n={}){return n.withDetail===!0?Je(this.describe(),e,t,{...n,withDetail:!0}):Je(this.describe(),e,t,n)}explain(e,t,n){return n?.reactive===!0?this._explainReactive(e,t,n):this._explainStatic(V(e),V(t),{...n?.maxDepth!==void 0?{maxDepth:Ke(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:He(n.findCycle)}:{}})}_explainStatic(e,t,n){let s=this.describe({detail:"full"}),r=new Map(this._annotations),i=new Map;for(let[c,d]of Object.entries(s.nodes))d.lastMutation!=null&&i.set(c,d.lastMutation);return Fe(s,e,t,{...n?.maxDepth!=null?{maxDepth:n.maxDepth}:{},...n?.findCycle===!0?{findCycle:!0}:{},annotations:r,lastMutations:i})}_describeReactive(e){let t={...e,reactive:!1},n=e.reactiveName??"describe",s=0,r=Z(s,{name:`${n}_version`}),i=this.observe({timeline:!0,structured:!0}),c=!1,d=!1,a=()=>{c||d||(c=!0,te(()=>{c=!1,!d&&(s+=1,r.emit(s))}))},p=i.onEvent(m=>{let b=m.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||a()}),g=[],h=new WeakSet,f=m=>{if(h.has(m)||d)return;h.add(m);let b=m.topology.subscribe(v=>{for(let w of v){if(w[0]!==q)continue;let E=w[1];if(a(),E.kind==="added"&&E.nodeKind==="mount"){let S=m._mounts.get(E.name);S!=null&&f(S)}}});g.push(b);for(let v of m._mounts.keys()){let w=m._mounts.get(v);w!=null&&f(w)}};f(this);let u,y=e.actor;Ye(y)&&(u=y.subscribe(m=>{let b=!1,v=!1;for(let w of m){let E=w[0];E===q?b=!0:(E===H||E===W||E===L)&&(v=!0)}b&&a(),v&&(u?.(),u=void 0,a())}));let l;try{l=be([r],()=>this.describe(t),{name:n,describeKind:"derived",meta:{domain:"audit",kind:"describe"},equals:(m,b)=>m===b})}catch(m){p(),u?.();for(let b of g)b();throw i.dispose(),m}let O=ne(l);return{node:l,dispose(){d=!0,p(),u?.();for(let m of g)m();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:[]},r=this.describe(t),i=_e(s,r),c=Z(i,{name:n,meta:{domain:"audit",kind:"describe-diff"},equals:(h,f)=>h===f}),d=this._describeReactive({...e,reactiveName:void 0}),a=!1,p=d.node.subscribe(h=>{if(!a)for(let f of h){if(f[0]!==q)continue;let u=f[1],y=_e(r,u);r=u,y.events.length!==0&&c.emit(y)}}),g=ne(c);return{node:c,dispose(){a=!0,p(),d.dispose(),c.down([[L,"describe-diff disposed"]]),g()}}}_explainReactive(e,t,n){let s=0,r=Z(s,{name:"explain_version"}),i=this.observe({timeline:!0,structured:!0}),c=!1,d=!1,a=()=>{c||d||(c=!0,te(()=>{c=!1,!d&&(s+=1,r.emit(s))}))},p=i.onEvent(m=>{let b=m.type;b!=="data"&&b!=="error"&&b!=="complete"&&b!=="teardown"||a()}),g=[];e!=null&&K(e)&&g.push(e),t!=null&&K(t)&&g.push(t),n?.maxDepth!=null&&K(n.maxDepth)&&g.push(n.maxDepth),n?.findCycle!=null&&K(n.findCycle)&&g.push(n.findCycle);let h=()=>{for(let m of g)if(m.cache===void 0)return!1;return!0},f=()=>{let m=V(e),b=V(t);return{from:m,to:b,found:!1,reason:"pending",steps:[],text:"(awaiting reactive args)",toJSON:()=>({from:m,to:b,found:!1,reason:"pending",steps:[]})}},u;try{u=be([r],()=>{if(!h())return f();let m=V(e),b=V(t),v={...n?.maxDepth!==void 0?{maxDepth:Ke(n.maxDepth)}:{},...n?.findCycle!==void 0?{findCycle:He(n.findCycle)}:{}};return this._explainStatic(m,b,v)},{name:n?.name??"explain",describeKind:"derived",meta:{domain:"audit",kind:"explain_path",from:V(e),to:V(t)},equals:(m,b)=>m.found===b.found&&m.reason===b.reason&&m.steps.length===b.steps.length&&mt(m.steps,b.steps)})}catch(m){throw p(),i.dispose(),m}let y=ne(u),l=[],O=m=>{let b;return b=m.subscribe(v=>{let w=!1,E=!1;for(let S of v){let R=S[0];R===q?w=!0:(R===H||R===W||R===L)&&(E=!0)}(w||E)&&a(),E&&b&&(b(),b=void 0)}),()=>{b&&(b(),b=void 0)}};for(let m of g)l.push(O(m));return{node:u,dispose(){d=!0,p();for(let m of l)m?.();l.length=0,i.dispose(),y()}}}_pathsMatching(e){let t=ie(e),n=[];return this._collectObserveTargets("",n),n.map(([s])=>s).filter(s=>t.test(s))}_collectObserveTargets(e,t){for(let n of[...this._mounts.keys()].sort()){let s=e===""?n:`${e}${$}${n}`;this._mounts.get(n)._collectObserveTargets(s,t)}for(let n of[...this._nodes.keys()].sort()){let s=this._nodes.get(n),r=e===""?n:`${e}${$}${n}`;t.push([r,s]),this._appendMetaObserveTargets(r,s,t)}}_appendMetaObserveTargets(e,t,n){for(let s of Object.keys(t.meta).sort()){let r=t.meta[s],i=`${e}${$}${B}${$}${s}`;n.push([i,r]),this._appendMetaObserveTargets(i,r,n)}}observe(e,t){let n=typeof e=="string",r=Ue(n?t:e);if(r.reactive===!0)return this._observeReactive(n?e:void 0,r);let i=r.structured===!0||r.timeline===!0||r.causal===!0||r.derived===!0||r.detail==="minimal"||r.detail==="full"||r.format!=null,c=r.actor;if(n){let p=e,g=this.resolve(p);if(c!=null&&!g.allowsObserve(c))throw new U({actor:c,action:"observe",nodeName:p});return i?this._buildStructuredObserver([[p,g]],r,"one"):{subscribe(h){return g.subscribe(h)},up(h){try{g.up?.(h)}catch(f){if(f instanceof U)return;throw f}}}}let d=[];this._collectObserveTargets("",d),d.sort((p,g)=>p[0]<g[0]?-1:p[0]>g[0]?1:0);let a=c==null?d:d.filter(([,p])=>p.allowsObserve(c));return i?this._buildStructuredObserver(a,r,"all"):{subscribe:p=>{let g=a.map(([h,f])=>f.subscribe(u=>{p(h,u)}));return()=>{for(let h of g)h()}},up:(p,g)=>{try{this.resolve(p).up?.(g)}catch(h){if(h instanceof U)return;throw h}}}}_observeReactive(e,t){let n=t.tiers,s=n!=null?new Set(n):null,r=t.reactiveName??"observe";return me(i=>{let c=[],d=!1,a=!1,p=()=>{if(c.length===0||a)return;let y={events:c.slice(),flushedAt_ns:z()};c.length=0,i.emit(y)},g={...t,reactive:!1,structured:!0,timeline:!0},h=e!=null?this.observe(e,g):this.observe(g),f=y=>{a||(c.push(y),!d&&(d=!0,te(()=>{d=!1,p()})))};for(let y of h.events)f(y);let u=h.onEvent(f);return()=>{a=!0,u(),h.dispose()}},{name:r,meta:{domain:"audit",kind:"observe-reactive"}})}_buildStructuredObserver(e,t,n){let s=n==="one"?e[0]?.[0]:void 0,r=i=>{if(n==="one"&&s!=null){let p=this.resolve(s);return this._buildStructuredObserver([[s,p]],i,"one")}let c=[];this._collectObserveTargets("",c),c.sort((p,g)=>p[0]<g[0]?-1:p[0]>g[0]?1:0);let d=i.actor,a=d==null?c:c.filter(([,p])=>p.allowsObserve(d));return this._buildStructuredObserver(a,i,"all")};return this._createObserveResult(e,t,r)}_createObserveResult(e,t,n){let s=t.timeline===!0,r=t.causal===!0,i=t.derived===!0,c=t.detail==="minimal",d=this.config.inspectorEnabled,a=(r||i)&&d,p=t.maxEvents,g=p!=null&&p>0?new we(p):null,h=[],f=new Set,u=t.tiers!=null?new Set(t.tiers):null,y={},l=new Set,O=0,m=0,b=0,v=0,w=0,E=0,S=!1,R=!1,G=0,D=new Map,k=new Map,I=new Map,T=_=>{if(!(u!=null&&!u.has(_.type))){g?g.push(_):h.push(_);for(let C of f)C(_)}},x=_=>u==null||u.has(_),Re=()=>s?{timestamp_ns:z(),in_batch:Ae(),batch_id:G}:{},Ze=(_,C)=>{if(!(!a||!(_ instanceof M)))return _._setInspectorHook(j=>{if(j.kind==="dep_message")D.set(_,j.depIndex);else if(j.kind==="run"){let Y=j.batchData.map((N,P)=>N!=null&&N.length>0?N.at(-1):j.prevData[P]);k.set(_,Y);let F=j.batchData.map(N=>N!=null?[...N]:void 0);I.set(_,F),i&&T({type:"derived",path:C,dep_values:Y,dep_batches:F,...Re()})}})},Ne=_=>{let C=D.get(_),j=k.get(_);if(!r||j==null)return{};let F=(C!=null&&C>=0&&_ instanceof M?_._deps[C]:void 0)?.node,N=F?.v,P=I.get(_);return{trigger_dep_index:C,trigger_dep_name:F?.name,...N!=null?{trigger_version:{id:N.id,version:N.version}}:{},dep_values:[...j],...P!=null?{dep_batches:P}:{}}},Ge=[],De=[];for(let[_,C]of e){let j=Ze(C,_);j&&Ge.push(j),De.push(C.subscribe(Y=>{G++;for(let F of Y){let N=F[0],P=Re();if(N===q){y[_]=F[1];let de=C instanceof M?C.lastMutation?.actor??Q:Q;T({type:"data",path:_,data:F[1],actor:de,...P,...Ne(C)})}else if(c)N===le?x("dirty")&&O++:N===pe?x("resolved")&&m++:N===ee?x("invalidate")&&b++:N===fe?x("pause")&&v++:N===he?x("resume")&&w++:N===L?x("teardown")&&E++:N===H&&!l.has(_)?x("complete")&&(S=!0):N===W&&x("error")&&(R=!0,l.add(_));else if(N===le)x("dirty")&&O++,T({type:"dirty",path:_,...P});else if(N===pe)x("resolved")&&m++,T({type:"resolved",path:_,...P,...Ne(C)});else if(N===ee)x("invalidate")&&b++,T({type:"invalidate",path:_,...P});else if(N===fe)x("pause")&&v++,T({type:"pause",path:_,lockId:F[1],...P});else if(N===he)x("resume")&&w++,T({type:"resume",path:_,lockId:F[1],...P});else if(N===H)x("complete")&&!l.has(_)&&(S=!0),T({type:"complete",path:_,...P});else if(N===W){x("error")&&(R=!0,l.add(_));let de=C instanceof M?C.lastMutation?.actor??Q:Q;T({type:"error",path:_,data:F[1],actor:de,...P})}else N===L&&(x("teardown")&&E++,T({type:"teardown",path:_,...P}))}}))}let ae=!1,ue=()=>{if(!ae){ae=!0;for(let _ of De)_();for(let _ of Ge)_();for(let _ of X)_({value:void 0,done:!0});X.length=0}},ce=[],X=[];f.add(_=>{let C=X.shift();C?C({value:_,done:!1}):ce.push(_)});let Ce={get values(){return y},get dirtyCount(){return O},get resolvedCount(){return m},get invalidateCount(){return b},get pauseCount(){return v},get resumeCount(){return w},get teardownCount(){return E},get events(){return g?g.toArray():[...h]},get anyCompletedCleanly(){return S},get anyErrored(){return R},get completedWithoutErrors(){return S&&!R},onEvent(_){return f.add(_),()=>f.delete(_)},dispose:ue,expand(_){ue();let C={...t};return typeof _=="string"?C.detail=_:Object.assign(C,_),n(Ue(C))},[Symbol.asyncIterator](){return{next(){return ce.length>0?Promise.resolve({value:ce.shift(),done:!1}):ae?Promise.resolve({value:void 0,done:!0}):new Promise(_=>X.push(_))},return(){return ue(),Promise.resolve({value:void 0,done:!0})}}}};return t.format!=null&&this._attachFormatLogger(Ce,t),Ce}_attachFormatLogger(e,t){let n=t.format;if(n==null)return;let s=t.logger??(u=>console.log(u)),r=t.includeTypes?new Set(t.includeTypes):null,i=t.excludeTypes?new Set(t.excludeTypes):null,c=r==null&&i==null?()=>!0:u=>(r==null||r.has(u))&&(i==null||!i.has(u)),d=lt(t.theme),a=n==="stage-log"?z():0,p=u=>u==null?"":t.stageLabels?.[u]??u,g=(u,y)=>u.length>y?`${u.slice(0,y-1)}\u2026`:u,h=u=>u.type==="data"||u.type==="error"?g(Ee(u.data),120):"",f=u=>{if(n==="stage-log"){let S=(z()-a)/1e9,R=p(u.path).padEnd(9);if(u.type==="data"){let G=h(u);return`[${S.toFixed(3)}s] ${R} \u2190${G?` ${G}`:""}`}if(u.type==="error"){let G=h(u);return`[${S.toFixed(3)}s] ${R} \u2717${G?` ${G}`:""}`}return u.type==="complete"?`[${S.toFixed(3)}s] ${R} \u25A0 complete`:`[${S.toFixed(3)}s] ${R} ${u.type}`}if(n==="json")try{return JSON.stringify(u)}catch{return JSON.stringify({type:u.type,path:u.path,data:"[unserializable]"})}let y=d[u.type]??"",l=u.path?`${d.path}${u.path}${d.reset} `:"",O=u.type==="data"||u.type==="error",m=u.type==="pause"||u.type==="resume",b=O?` ${Ee(u.data)}`:m?` ${Ee(u.lockId)}`:"",v=u.type==="data"||u.type==="resolved"||u.type==="derived"?u:void 0,w=v?.trigger_dep_name!=null?` <- ${v.trigger_dep_name}`:v?.trigger_dep_index!=null?` <- #${v.trigger_dep_index}`:"",E=u.in_batch?" [batch]":"";return`${l}${y}${u.type.toUpperCase()}${d.reset}${b}${w}${E}`};e.onEvent(u=>{c(u.type)&&s(f(u),u)})}addDisposer(e){return this._disposers.add(e),()=>{this._disposers.delete(e)}}destroy(){qe(this._disposers,this.name),this.signal([[L]],{internal:!0}),qe(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 c of Object.keys(n.nodes).sort()){let{lastMutation:d,guard:a,...p}=n.nodes[c];s[c]=p}let r=[...n.subgraphs].sort(),i={...n,version:1,nodes:s,subgraphs:r};if(e?.format==null)return i;if(e.format==="json-string")return JSON.stringify(i);if(e.format==="bytes"){if(e.codec==null)throw new Error("snapshot({format: 'bytes'}) requires a `codec` name");let c=this.config.lookupCodec(e.codec);if(c==null)throw new Error(`snapshot: codec "${e.codec}" is not registered on this graph's config. Call config.registerCodec(...) before creating nodes.`);return $e(c,c.encode(i))}throw new Error(`snapshot: unknown format "${String(e.format)}"`)}static decode(e,t){let n=t?.config??ge,{codec:s,codecVersion:r,payload:i}=xe(e,n);return s.decode(i,r)}restore(e,t){if(We(e),e.name!==this.name)throw new Error(`Graph "${this.name}": restore snapshot name "${e.name}" does not match this graph`);let n=t?.only==null?null:(Array.isArray(t.only)?t.only:[t.only]).map(r=>ie(r)),s=t?.includeProducers===!0;for(let r of Object.keys(e.nodes).sort()){if(n!==null&&!n.some(c=>c.test(r)))continue;let i=e.nodes[r];if(i!==void 0){if(!("value"in i)||i.value===void 0){"value"in i&&i.value===void 0&&t?.onError?.(r,new Error(`restore: slice.value is undefined for "${r}" (undefined is the global SENTINEL; not valid DATA)`));continue}if(!(i.type==="derived"||i.type==="effect")&&!(i.type==="producer"&&!s)){if(i.v!=null){let d=this.tryResolve(r)?.v;if(d!=null&&d.id===i.v.id&&d.version===i.v.version)continue}try{this.set(r,i.value)}catch(c){t?.onError?.(r,c)}}}}}static fromSnapshot(e,t){We(e);let n=typeof t=="function"?t:t?.build,s=typeof t=="function"?void 0:t?.factories,r=new o(e.name);if(n)return n(r),r.restore(e),r;for(let f of[...e.subgraphs].sort((u,y)=>{let l=u.split($).length,O=y.split($).length;return l!==O?l-O:u<y?-1:u>y?1:0})){let u=f.split($),y=r;for(let l of u)y._mounts.has(l)||y.mount(l,new o(l)),y=y._mounts.get(l)}let i=s?Object.entries(s).map(([f,u])=>({re:ie(f),factory:u})):[],c=f=>{for(let u of i)if(u.re.test(f))return u.factory},d=f=>{let u=f.split($),y=u.pop();if(y==null||y.length===0)throw new Error(`invalid snapshot path "${f}"`);let l=r;for(let O of u){let m=l._mounts.get(O);if(!m)throw new Error(`unknown mount "${O}" in path "${f}"`);l=m}return[l,y]},a=Object.entries(e.nodes).filter(([f])=>!f.includes(`${$}${B}${$}`)).sort((f,u)=>f[0]<u[0]?-1:f[0]>u[0]?1:0),p=new Map(a),g=new Map,h=!0;for(;p.size>0&&h;){h=!1;for(let[f,u]of[...p.entries()]){let y=u?.deps??[];if(!y.every(w=>g.has(w)))continue;let[l,O]=d(f),m={...u?.meta??{}},b=c(f),v;if(u?.type==="state")v=Z(u.value,{meta:m});else{if(b==null)continue;v=b(O,{path:f,type:u.type,value:u.value,meta:m,deps:y,resolvedDeps:y.map(w=>g.get(w))})}l.add(v,{name:O}),g.set(f,v),p.delete(f),h=!0}}if(p.size>0){let f=[...p.keys()].sort().join(", ");throw new Error(`Graph.fromSnapshot could not reconstruct nodes without build callback: ${f}. Pass matching factories via fromSnapshot(data, { factories: { pattern: factoryFn } }).`)}return r.restore(e),r}toJSON(){return this.snapshot()}attachSnapshotStorage(e,t={}){let n=e.map(a=>({tier:a,debounceMs:Math.max(0,a.debounceMs??0),compactEvery:Math.max(1,a.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=(a,p)=>{if(a.disposed)return;let g=it(p.nodes);if(a.lastSnapshot!=null&&g!==""&&g===a.lastFingerprint)return;let h=a.seq+1,f=Pe(),l=a.lastSnapshot==null||h%a.compactEvery===0?{name:this.name,mode:"full",snapshot:p,seq:h,timestamp_ns:f,format_version:J}:{name:this.name,mode:"diff",diff:gt(a.lastSnapshot,p),seq:h,timestamp_ns:f,format_version:J};if(a.tier.filter&&!a.tier.filter(l))return;let O;try{O=a.tier.save(l)}catch(m){t.onError?.(m,a.tier);return}if(O&&typeof O.then=="function"){let v=(a.savePending??Promise.resolve()).then(()=>O,()=>O).then(()=>{a.disposed||(a.seq=h,a.lastSnapshot=p,a.lastFingerprint=g)},w=>{t.onError?.(w,a.tier)});a.savePending=v.finally(()=>{a.savePending===v&&(a.savePending=void 0)})}else a.seq=h,a.lastSnapshot=p,a.lastFingerprint=g},r=(a,p)=>{try{s(a,p)}catch(g){t.onError?.(g,a.tier)}},i=(a,p)=>{if(!p.some(u=>{let y=this.config.messageTier(u[0]);return y>=3&&y<5}))return;if(t.filter){let u=this.tryResolve(a);if(u==null)return;let y=ye(u,ve("standard"));if(!t.filter(a,y))return}let h,f=()=>(h==null&&(h=this.snapshot()),h);for(let u of n)u.disposed||(u.debounceMs===0?r(u,f()):(u.timer==null&&(u.timer=new Me),u.timer.start(u.debounceMs,()=>{u.disposed||r(u,this.snapshot())})))},c;if(t.paths!=null){let p=(typeof t.paths=="string"?this._pathsMatching(t.paths):t.paths).map(g=>{let h=this.tryResolve(g);return h==null?()=>{}:h.subscribe(f=>i(g,f))});c=()=>{for(let g of p)g()}}else c=this.observe().subscribe((a,p)=>i(a,p));let d=()=>{c();for(let a of n)a.disposed=!0,a.timer?.cancel();this._storageDisposers.delete(d)};return this._storageDisposers.add(d),{dispose:d}}async _cascadeRestore(e,t){for(let n of e){let s;try{s=await n.load?.()}catch(i){t?.(i,n);continue}if(s==null||typeof s!="object"||Array.isArray(s))continue;let r=s;try{if(r.mode==="full"&&r.snapshot!=null)return this.restore(r.snapshot),!0;if(r.version===J&&r.nodes!=null)return this.restore(r),!0}catch(i){t?.(i,n)}}return!1}static async fromStorage(e,t,n){for(let s of t){let r;try{r=await s.load?.()}catch(d){n?.onError?.(d,s);continue}if(r==null||typeof r!="object"||Array.isArray(r))continue;let i=r,c=i.mode==="full"&&i.snapshot!=null?i.snapshot:i.version===J&&i.nodes!=null?i:void 0;if(c!=null)try{return o.fromSnapshot(c,n)}catch(d){n?.onError?.(d,s)}}throw new Error(`Graph.fromStorage: no tier held a restorable record for "${e}" across ${t.length} tier(s)`)}_annotations=new Map;_traceRing;trace(e,t,n){if(e!=null&&t!=null){if(this.tryResolve(e)==null)return;if(this._annotations.set(e,t),this.config.inspectorEnabled){let s={path:e,annotation:t,timestamp_ns:z(),...n?.actor!=null?{actor:n.actor}:{}};this._traceRing.push(s)}return}return e!=null?this.config.inspectorEnabled?this._annotations.get(e):void 0:this.config.inspectorEnabled?this._traceRing.toArray():[]}annotation(e){return this._annotations.get(e)}clearTrace(){this._annotations.clear(),this._traceRing.clear()}pruneTrace(e){let t=this._traceRing.toArray().filter(s=>!e(s)),n=this._traceRing.size-t.length;this._traceRing.clear();for(let s of t)this._traceRing.push(s);return n}static diff(e,t){let n=new Set(Object.keys(e.nodes)),s=new Set(Object.keys(t.nodes)),r=[...s].filter(m=>!n.has(m)).sort(),i=[...n].filter(m=>!s.has(m)).sort(),c=[],d=[];for(let m of n){if(!s.has(m))continue;let b=e.nodes[m],v=t.nodes[m],w=b.v,E=v.v;w!=null&&E!=null&&w.id===E.id&&w.version!==E.version&&d.push({path:m,id:w.id,from:w.version,to:E.version});let S=w!=null&&E!=null&&w.id===E.id&&w.version===E.version;for(let R of["type","status","sentinel"]){let G=b[R],D=v[R];G!==D&&c.push({path:m,field:R,from:G,to:D})}if(!S)for(let R of["value","meta"]){let G=b[R],D=v[R];at(G,D)||c.push({path:m,field:R,from:G,to:D})}}let a=m=>`${m.from} ${m.to}`,p=new Set(e.edges.map(a)),g=new Set(t.edges.map(a)),h=t.edges.filter(m=>!p.has(a(m))),f=e.edges.filter(m=>!g.has(a(m))),u=new Set(e.subgraphs),y=new Set(t.subgraphs),l=[...y].filter(m=>!u.has(m)).sort(),O=[...u].filter(m=>!y.has(m)).sort();return{nodesAdded:r,nodesRemoved:i,nodesChanged:c,versionChanges:d,edgesAdded:h,edgesRemoved:f,subgraphsAdded:l,subgraphsRemoved:O}}};function gt(o,e){let t=Se.diff(o,e),n={};for(let s of t.nodesAdded){let r=e.nodes[s];r!=null&&(n[s]=r)}return{...t,nodesAddedFull:n}}function Je(o,e,t,n={}){let s={paths:[],depths:new Map,truncated:!1};if(!e)return n.withDetail?s:[];if(!n.both&&t!=="upstream"&&t!=="downstream")throw new Error('reachable: direction must be "upstream" or "downstream"');let r=n.maxDepth;if(r!=null&&(!Number.isInteger(r)||r<0))throw new Error("reachable: maxDepth must be an integer >= 0");if(r===0)return n.withDetail?s:[];let i=new Map,c=new Map,d=new Map,a=new Map,p=new Set;for(let[b,v]of Object.entries(o.nodes)){if(!b)continue;p.add(b);let w=v.deps??[];i.set(b,w);for(let E of w)E&&(p.add(E),c.has(E)||c.set(E,new Set),c.get(E).add(b))}for(let b of o.edges){if(b==null||typeof b!="object")continue;let v=typeof b.from=="string"?b.from:"",w=typeof b.to=="string"?b.to:"";!v||!w||(p.add(v),p.add(w),a.has(v)||a.set(v,new Set),a.get(v).add(w),d.has(w)||d.set(w,new Set),d.get(w).add(v))}if(!p.has(e))return n.withDetail?s:[];let g=n.both===!0,h=b=>{if(g){let S=i.get(b)??[],R=d.get(b),G=c.get(b),D=a.get(b),k=[...S];return R&&k.push(...R),G&&k.push(...G),D&&k.push(...D),k}if(t==="upstream"){let S=i.get(b)??[],R=d.get(b);return R?[...S,...R]:S}let v=c.get(b),w=a.get(b),E=v?[...v]:[];return w&&E.push(...w),E},f=new Set([e]),u=new Map,y=[{path:e,depth:0}],l=0,O=!1;for(;l<y.length;){let b=y[l++];if(r!=null&&b.depth>=r){h(b.path).length>0&&(O=!0);continue}for(let v of h(b.path))!v||f.has(v)||(f.add(v),u.set(v,b.depth+1),y.push({path:v,depth:b.depth+1}))}let m=[...u.keys()].sort((b,v)=>b<v?-1:b>v?1:0);return n.withDetail?{paths:m,depths:u,truncated:O}:m}function mt(o,e){if(o.length!==e.length)return!1;for(let t=0;t<o.length;t++){let n=o[t],s=e[t];if(n.path!==s.path||n.type!==s.type||n.status!==s.status||n.hop!==s.hop||n.dep_index!==s.dep_index||n.annotation!==s.annotation||n.value!==s.value||n.lastMutation!==s.lastMutation)return!1;let r=n.v,i=s.v;if(r!==i&&(r==null||i==null||r.id!==i.id||r.version!==i.version))return!1}return!0}export{_e as a,Fe as b,A as c,nt as d,ze as e,Ve as f,B as g,J as h,Se as i,gt as j,Je as k};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import{a as $e}from"./chunk-ELAASRBT.js";import{d as _e,e as He}from"./chunk-5B3JDG5F.js";import{s as ie,t as ue,v as Oe}from"./chunk-Z6X7B6A4.js";import{c as Me}from"./chunk-7PQLZMOG.js";import{g as Fe,i as ce}from"./chunk-URJ2VFNC.js";import{b as V}from"./chunk-D27JNOLZ.js";import{b as Pe}from"./chunk-TSOYJ743.js";import{b as Z}from"./chunk-TZQPPQEQ.js";import{a as se}from"./chunk-VXPLLA4P.js";import{f as Se,i as Ne}from"./chunk-POXANAJ6.js";import{b as X,s as ae,t as we,x as Ce}from"./chunk-AK5RHMC5.js";import{C as Ae,m as z}from"./chunk-L77I47VU.js";import{b as ke}from"./chunk-35JTVPOX.js";import{E as C,F as W,G as b,H as k,m as Ie,o as F}from"./chunk-LYCLF26R.js";import{b as $,i as _,j as K}from"./chunk-CK2E7BTU.js";import{b as ut}from"./chunk-QYADASLV.js";var Ht={};ut(Ht,{DEFAULT_DECAY_RATE:()=>L,DEFAULT_EXECUTE_PROMPT:()=>de,DEFAULT_QUEUE_CONFIGS:()=>ee,DEFAULT_SEVERITY_WEIGHTS:()=>H,DEFAULT_TRIAGE_PROMPT:()=>le,DEFAULT_VERIFY_PROMPT:()=>pe,HarnessGraph:()=>re,QUEUE_NAMES:()=>h,actuatorExecutor:()=>Le,affectedTaskFilter:()=>Et,autoSolidify:()=>mt,beforeAfterCompare:()=>Tt,codeChangeBridge:()=>bt,createIntakeBridge:()=>gt,defaultErrorClassifier:()=>te,defaultLlmExecutor:()=>Qe,defaultLlmVerifier:()=>Ue,dispatchActuator:()=>ft,effectivenessTracker:()=>xt,evalIntakeBridge:()=>yt,evalSource:()=>vt,evalVerifier:()=>De,harnessEvalPair:()=>Nt,harnessLoop:()=>Pt,harnessProfile:()=>Ft,harnessTrace:()=>$t,notifyEffect:()=>Rt,priorityScore:()=>wt,refineExecutor:()=>fe,resolvePromptFn:()=>Q,strategyKey:()=>D,strategyModel:()=>me});function ct(e,t){return{outcome:"success",detail:`actuator applied ${t.intervention} for ${pt(t.summary)}`,artifact:e}}function lt(e,t){let a=e instanceof Error?e.message:String(e);return{outcome:"failure",detail:`actuator threw on ${t.intervention}: ${a}`}}function dt(e){return`actuator skipped ${e.intervention} (shouldApply returned false)`}function pt(e,t=80){return e.length<=t?e:`${e.slice(0,t-1)}\u2026`}function Le(e){let t=e.name??"actuator-executor",a=e.toOutput??ct,o=e.onError??lt,n=e.skipDetail??dt;return c=>{let r=c.payload.item;return e.shouldApply&&!e.shouldApply(r)?{...c.payload,execution:{item:r,outcome:"failure",detail:n(r)}}:W(s=>{let u=new AbortController,i=!1,l=null,m=g=>{i||(i=!0,s.down([[$,{...c.payload,execution:{item:r,...g}}],[_]]),l?.(),l=null)},p;try{let g=e.apply(r,{signal:u.signal});p=z(g,{signal:u.signal})}catch(g){return m(o(g,r)),()=>{u.abort()}}return l=p.subscribe(g=>{for(let y of g){if(i)return;if(y[0]===$){m(a(y[1],r));return}if(y[0]===K){m(o(y[1],r));return}if(y[0]===_){m(o(new Error("actuator inner completed without emitting DATA"),r));return}}}),i&&l&&(l(),l=null),()=>{u.abort(),l?.(),l=null}},{name:`${t}/inner`})}}function ft(e){let t=e.name??"dispatch-actuator",a=e.default??null,o=a!=null;return Le({apply:(n,c)=>{let r=Object.hasOwn(e.routes,n.intervention)?e.routes[n.intervention]:a;if(!r)throw new Error(`dispatchActuator: no route for intervention '${n.intervention}'`);return r(n,c)},shouldApply:n=>Object.hasOwn(e.routes,n.intervention)||o,skipDetail:n=>`no route for intervention '${n.intervention}'`,name:t})}function mt(e){let t=e.name??"auto-solidify",a=e.extract??(n=>n.execution.artifact??null),o=e.predicate??(()=>!0);return W(n=>{let c=null,r=!1,s=()=>{r||(r=!0,c?.(),c=null)},u=i=>{r||(n.down([[K,i]]),s())};return c=e.verifyResults.subscribe(i=>{if(!r)for(let l of i){if(r)return;if(l[0]!==$){if(l[0]===_){n.down([[_]]),s();return}continue}let m=l[1];if(m==null||!m.verified)continue;let p;try{p=o(m)}catch(y){u(y);return}if(!p)continue;let g;try{g=a(m)}catch(y){u(y);return}if(g!=null){try{e.write(g,m)}catch(y){u(y);return}n.down([[$,g]])}}}),r&&c&&(c(),c=null),()=>{s()}},{name:t})}function gt(e,t,a,o){return k([e],([n])=>{if(n==null)return;let c=a(n);for(let r of c)t.publish(r)},{name:o?.name??"intake-bridge"})}function yt(e,t,a){let o=a?.defaultSeverity??"medium";return k([e],([n])=>{if(n==null)return;let c=Array.isArray(n)?n:[n];for(let r of c)for(let s of r.tasks)if(!(s.valid&&s.judge_scores?.every(u=>u.pass))){if(!s.valid&&(!s.judge_scores||s.judge_scores.length===0)){t.publish({source:"eval",summary:`Task ${s.task_id} invalid (model: ${r.model})`,evidence:`Run ${r.run_id}: task produced invalid output`,affectsAreas:["graphspec"],affectsEvalTasks:[s.task_id],severity:o});continue}if(s.judge_scores)for(let u of s.judge_scores)u.pass||t.publish({source:"eval",summary:`${s.task_id}: ${u.claim} (model: ${r.model})`,evidence:u.reasoning,affectsAreas:["graphspec"],affectsEvalTasks:[s.task_id],severity:o})}},{name:a?.name??"eval-intake-bridge"})}function vt(e,t){return Ce(e,()=>z(t()))}function Tt(e,t){return b([e,t],([a,o])=>{let n=a,c=o,r=new Map(n.tasks.map(p=>[p.task_id,p])),s=new Map(c.tasks.map(p=>[p.task_id,p])),u=new Set([...r.keys(),...s.keys()]),i=[],l=[],m=[];for(let p of u){let g=r.get(p),y=s.get(p),x=g?.valid??!1,I=y?.valid??!1,R=g?.judge_scores?g.judge_scores.filter(N=>N.pass).length:void 0,A=y?.judge_scores?y.judge_scores.filter(N=>N.pass).length:void 0,M=R!==void 0&&A!==void 0?A-R:void 0;i.push({taskId:p,before:x,after:I,scoreDiff:M}),x&&!I&&l.push(p),!x&&I&&m.push(p)}return{newFailures:l,resolved:m,taskDeltas:i,overallImproved:m.length>l.length}},{name:"eval-delta"})}function Et(e,t){let a=t==null?null:Array.isArray(t)?C(t):t,o=[e];return a&&o.push(a),b(o,n=>{let c=n[0],r=a?new Set(n[1]):null,s=new Set;for(let u of c)for(let i of u.affectsEvalTasks??[])(r==null||r.has(i))&&s.add(i);return[...s].sort()},{name:"affected-task-filter"})}function bt(e,t,a,o){let n=o?.defaultSeverity??"high";function c(s){let u=[];for(let i of s.lintErrors??[])u.push({source:"code-change",summary:`Lint: ${i.rule} in ${i.file}:${i.line}`,evidence:i.message,affectsAreas:[i.file],severity:n});for(let i of s.testFailures??[])u.push({source:"test",summary:`Test failure: ${i.testId}`,evidence:i.message,affectsAreas:[i.file],affectsEvalTasks:[i.testId],severity:n});return u}let r=a??c;return k([e],([s])=>{if(s!=null)for(let u of r(s))t.publish(u)},{name:o?.name??"code-change-bridge"})}function Rt(e,t,a){return k([e.latest],([o])=>{o!=null&&t(o)},{name:a?.name??"notify-effect"})}var h=["auto-fix","needs-decision","investigation","backlog"],ee={"auto-fix":{gated:!1},"needs-decision":{gated:!0},investigation:{gated:!0},backlog:{gated:!1}},H={critical:100,high:70,medium:40,low:10},L=Math.LN2/(168*3600);function D(e,t){return`${e}\u2192${t}`}var ht=/\b(parse|json|config|validation|syntax)\b/i,te=e=>ht.test(e.detail)?"self-correctable":"structural",le=`You are a triage classifier for a reactive collaboration harness.
|
|
2
|
+
|
|
3
|
+
Given an intake item, classify it and output JSON:
|
|
4
|
+
{
|
|
5
|
+
"rootCause": "composition" | "missing-fn" | "bad-docs" | "schema-gap" | "regression" | "unknown",
|
|
6
|
+
"intervention": "template" | "catalog-fn" | "docs" | "wrapper" | "schema-change" | "investigate",
|
|
7
|
+
"route": "auto-fix" | "needs-decision" | "investigation" | "backlog",
|
|
8
|
+
"priority": <number 0-100>,
|
|
9
|
+
"triageReasoning": "<one sentence>"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Strategy model (past effectiveness):
|
|
13
|
+
{{strategy}}
|
|
14
|
+
|
|
15
|
+
Intake item:
|
|
16
|
+
{{item}}`,de=`You are an implementation agent.
|
|
17
|
+
|
|
18
|
+
Given a triaged issue with root cause and intervention type, produce a fix.
|
|
19
|
+
|
|
20
|
+
Issue:
|
|
21
|
+
{{item}}
|
|
22
|
+
|
|
23
|
+
Output JSON:
|
|
24
|
+
{
|
|
25
|
+
"outcome": "success" | "failure" | "partial",
|
|
26
|
+
"detail": "<description of what was done or what failed>"
|
|
27
|
+
}`,pe=`You are a QA reviewer.
|
|
28
|
+
|
|
29
|
+
Given an execution result, verify whether the fix is correct.
|
|
30
|
+
|
|
31
|
+
Execution:
|
|
32
|
+
{{execution}}
|
|
33
|
+
|
|
34
|
+
Original issue:
|
|
35
|
+
{{item}}
|
|
36
|
+
|
|
37
|
+
Output JSON:
|
|
38
|
+
{
|
|
39
|
+
"verified": true/false,
|
|
40
|
+
"findings": ["<finding1>", ...],
|
|
41
|
+
"errorClass": "self-correctable" | "structural" // only if verified=false
|
|
42
|
+
}`;function Q(e,t,a){if(typeof e=="function")return e;let o=e??t;return n=>a(o,n)}function xt(e){let t=Z({name:e?.name??"effectiveness-entries"}),a=b([t.entries],([r])=>new Map(r),{name:`${e?.name??"effectiveness"}-snapshot`,equals:(r,s)=>{let u=r,i=s;if(u.size!==i.size)return!1;for(let[l,m]of u){let p=i.get(l);if(!p||m.attempts!==p.attempts||m.successes!==p.successes)return!1}return!0}});function o(r,s){let u=t.get(r),i=(u?.attempts??0)+1,l=(u?.successes??0)+(s?1:0);t.set(r,{key:r,attempts:i,successes:l,successRate:l/i})}function n(r){return t.get(r)}let c=Ae(a);return{node:a,record:o,lookup:n,dispose:()=>{c(),t.dispose()}}}function It(e){let{best:t,score:a,status:o}=e,n=Number.isFinite(a)?a.toFixed(3):String(a),c=t??void 0;return o==="converged"?{outcome:"success",detail:`refineLoop converged at score ${n}`,artifact:c}:o==="budget"?{outcome:"partial",detail:`refineLoop hit budget at score ${n}`,artifact:c}:{outcome:"failure",detail:`refineLoop errored (status=${o})`,artifact:c}}function fe(e){let t=e.name??"refine-executor",a=e.toOutput??It;return o=>{let n=o.payload.item,c=$e(e.seedFrom(n),e.evaluator,e.strategy,{...e.refine,dataset:e.datasetFor(n),name:`${t}/inner`}),r=b([c.status,c.best,c.score],([s,u,i])=>{let l=s;if(l!=="converged"&&l!=="budget"&&l!=="errored")return null;let m=a({best:u,score:i,status:l});return{...o.payload,execution:{item:n,...m}}},{name:`${t}/output`});return X(r,s=>s!=null,{name:`${t}/gate-out`})}}function kt(e){if(e.length===0)return Number.NEGATIVE_INFINITY;let t=0;for(let a of e)t+=a.score;return t/e.length}function At(e){let{passCount:t,total:a,meanScore:o,threshold:n,missingArtifact:c}=e,r=Number.isFinite(o)?o.toFixed(3):String(o),s=!c&&a>0&&o>=n,u=c?["EXECUTE stage did not emit an artifact; cannot verify reactively"]:s?[`${t}/${a} eval tasks passed; mean score ${r} \u2265 ${n}`]:a===0?["No eval tasks were selected for this item \u2014 cannot verify"]:[`${t}/${a} eval tasks passed; mean score ${r} < threshold ${n}`];return s?{verified:!0,findings:u}:{verified:!1,findings:u,errorClass:"structural"}}function St(e){return e.artifact??null}function De(e){let t=e.name??"eval-verifier",a=e.threshold??.5,o=e.toOutput??At,n=e.extractArtifact??St;return c=>{let{item:r,execution:s}=c.payload;if(s==null)return{...c.payload,verify:{verified:!1,findings:["evalVerifier: prior execute stage produced no execution"],errorClass:"structural"}};let u=n(s,r);if(u==null)return{...c.payload,verify:o({scores:[],meanScore:Number.NEGATIVE_INFINITY,passCount:0,total:0,threshold:a,missingArtifact:!0})};let i=C([u],{name:`${t}/candidates`}),l=C(e.datasetFor(r),{name:`${t}/dataset`}),m;Ie(()=>{m=e.evaluator(i,l)});let p=b([m],([g])=>{let y=g;if(y==null)return null;let x=kt(y),I=y.filter(R=>R.score>=a).length;return{...c.payload,verify:o({scores:y,meanScore:x,passCount:I,total:y.length,threshold:a})}},{name:`${t}/output`});return X(p,g=>g!=null,{name:`${t}/gate-out`})}}function Nt(e){let t=e.name??"harness-pair",a=fe({name:`${t}-exec`,seedFrom:e.seedFrom,evaluator:e.evaluator,strategy:e.strategy,datasetFor:e.datasetFor,refine:e.refine}),o=De({name:`${t}-verify`,evaluator:e.evaluator,datasetFor:e.datasetFor,threshold:e.threshold});return{executor:a,verifier:o}}function me(){let e=Z({name:"strategy-entries"}),t=b([e.entries],([r])=>{let s=r;return new Map(s)},{name:"strategy-model",equals:(r,s)=>{let u=r,i=s;if(u.size!==i.size)return!1;for(let[l,m]of u){let p=i.get(l);if(!p||m.attempts!==p.attempts||m.successes!==p.successes)return!1}return!0}});function a(r,s,u){let i=D(r,s),l=e.get(i),m=(l?.attempts??0)+1,p=(l?.successes??0)+(u?1:0);e.set(i,{rootCause:r,intervention:s,attempts:m,successes:p,successRate:p/m})}function o(r,s){return e.get(D(r,s))}let n=t.subscribe(()=>{});function c(){n()}return{node:t,record:a,lookup:o,dispose:c}}function wt(e,t,a,o,n){let c={...H,...n?.severityWeights},r=n?.decayRate??L,s=n?.effectivenessThreshold??.7,u=n?.effectivenessBoost??15,i=[e,t,a];return o&&i.push(o),b(i,l=>{let m=l[0],p=l[1],g=l[2],y=o?l[3]:0,x=c[m.severity??"medium"],I=(F()-g)/1e9,R=Pe(x,I,r,0),A=D(m.rootCause,m.intervention),M=p.get(A);return M&&M.successRate>=s&&(R+=u),R+=y*20,R},{name:"priority-score"})}var Je="intake",Ct="triage-output",je="retry",Ge="verify-results",Ve="__unrouted";function Qe(e,t){let a=Q(t,de,(o,n)=>o.replace("{{item}}",JSON.stringify(n)));return o=>{let n=o.payload.item,c=[{role:"user",content:a(n)}],r=u=>({...o.payload,execution:{item:n,outcome:"failure",detail:u}}),s=u=>u instanceof Error?u.message:String(u);return ue(e,c,{onSuccess:u=>{let i;try{i=JSON.parse(ie(String(u.content)))}catch(m){return r(`execute parse error: ${s(m)}`)}if(i==null||typeof i!="object"||Array.isArray(i))return r(`execute parse error: non-object response: ${JSON.stringify(i)}`);let l=i;return{...o.payload,execution:{item:n,outcome:l.outcome??"failure",detail:l.detail??"unknown",artifact:l.artifact}}},onFailure:(u,i)=>r(u==="complete"?"adapter completed without emitting DATA":`executor failed: ${s(i)}`)})}}function Ue(e,t){let a=Q(t,pe,(o,n)=>{let[c,r]=n;return o.replace("{{execution}}",JSON.stringify(c)).replace("{{item}}",JSON.stringify(r))});return o=>{let{item:n,execution:c}=o.payload;if(c==null)return{...o.payload,verify:{verified:!1,findings:["verifier: prior execute stage produced no execution"],errorClass:"structural"}};let r=[{role:"user",content:a([c,n])}],s=i=>({...o.payload,verify:{verified:!1,findings:[i],errorClass:"self-correctable"}}),u=i=>i instanceof Error?i.message:String(i);return ue(e,r,{onSuccess:i=>{let l;try{l=JSON.parse(ie(String(i.content)))}catch(p){return s(`verify parse error: ${u(p)}`)}if(l==null||typeof l!="object"||Array.isArray(l))return s(`verify parse error: non-object response: ${JSON.stringify(l)}`);let m=l;return{...o.payload,verify:{verified:m.verified===!0,findings:m.findings??[],errorClass:m.errorClass}}},onFailure:(i,l)=>s(i==="complete"?"verifier completed without emitting DATA":`verifier failed: ${u(l)}`)})}}var re=class extends Ne{queues;executeFlow;jobs;gates;queueTopics;strategy;totalRetries;totalReingestions;priorityScores;constructor(t,a,o,n,c,r,s,u,i,l){super(t),this.queues=a,this.executeFlow=o,this.queueTopics=n,this.jobs=c,this.gates=r,this.strategy=s,this.totalRetries=u,this.totalReingestions=i,this.priorityScores=l}get intake(){return this.queues.topic(Je)}get verifyResults(){return this.queues.topic(Ge)}get retry(){return this.queues.topic(je)}get unrouted(){return this.queues.topic(Ve)}stageNodes(){let t=this.queues,a=r=>t.has(r)?`queues::${r}::latest`:null,o=r=>r==null?[]:[r],n=h.flatMap(r=>o(a(r))),c=[];for(let[r]of this.gates)c.push(`gates::${r}/gate`);return[{label:"INTAKE",paths:o(a("intake"))},{label:"TRIAGE",paths:["triage"]},{label:"QUEUE",paths:n},{label:"GATE",paths:c},{label:"EXECUTE",paths:["executeFlow::execute::events"]},{label:"VERIFY",paths:["executeFlow::verify::events"]},{label:"REFLECT",paths:["reflect"]},{label:"STRATEGY",paths:["strategy"]}]}};function Pt(e,t){let a=t.adapter,o=t.maxRetries??2,n=t.retainedLimit??1e3,c=t.errorClassifier??te,r=new Map;for(let d of h)r.set(d,{...ee[d],...t.queues?.[d]});let s=Fe(`${e}/queues`,{defaultTopicOptions:{retainedLimit:n}}),u=s.topic(Je),i=s.topic(Ct),l=s.topic(je),m=s.topic(Ge),p=new Map;for(let d of h)p.set(d,s.topic(d));let g=s.topic(Ve),y=me(),x=ae(u.latest,y.node),I=Q(t.triagePrompt,le,(d,f)=>{let[T,E]=f;return d.replace("{{strategy}}",JSON.stringify(Array.from(E.entries()))).replace("{{item}}",JSON.stringify(T))}),R=Oe(a,[x],d=>{let f=d;return!f||!f[0]?"":I(f)},{name:"triage",format:"json"}),A=ae(R,x),N=k([A],([d])=>{if(d==null)return;let[f,T]=d;if(!f?.route)return;let E=T?.[0],P={...f,...E};i.publish(P)}).subscribe(()=>{}),Be=new Set(h);for(let d of h)ce(`bridge/${d}`,i,p.get(d),{map:f=>f.route===d?f:void 0});ce("bridge/__unrouted",i,g,{map:d=>Be.has(d.route)?void 0:d});let J=new Map,ne=new Map;for(let d of h)J.set(d,_e(`jobs/${d}`));let ge=[];for(let d of h){let f=p.get(d),T=J.get(d),E=new WeakSet,P=k([f.events],([S])=>{let G=S??[];for(let O of G){if(E.has(O))continue;E.add(O);let w=T.enqueue(O);ne.set(V(O),{route:d,id:w})}},{name:`jobs/${d}-mirror`});ge.push(P.subscribe(()=>{}))}function oe(d){let f=V(d),T=ne.get(f);T&&(J.get(T.route)?.removeById(T.id),ne.delete(f))}let ye=Me("gates"),U=new Map;for(let d of h){let f=r.get(d);if(!f.gated)continue;let T=p.get(d),E=ye.approvalGate(`${d}/gate`,T.latest,{maxPending:f.maxPending,startOpen:f.startOpen});U.set(d,E)}let q=[];for(let d of h)r.get(d).gated&&U.has(d)?q.push(U.get(d).node):q.push(p.get(d).latest);q.push(l.latest);let ve=we(...q),Ye=t.executor??Qe(a,t.executePrompt),Ke=t.verifier??Ue(a,t.verifyPrompt),We=t.executeMaxPerPump??Number.MAX_SAFE_INTEGER,ze=t.verifyMaxPerPump??Number.MAX_SAFE_INTEGER,j=He(`${e}/executeFlow`,{stages:[{name:"execute",work:d=>Ye(d),maxPerPump:We},{name:"verify",work:d=>Ke(d),maxPerPump:ze}]}),Te=k([ve],([d])=>{d!=null&&j.enqueue({item:d})},{name:"execute-enqueue"}),Xe=Te.subscribe(()=>{}),Ee=t.maxReingestions??1,Ze=Math.min(t.maxTotalRetries??o*10,100),et=Math.min(t.maxTotalReingestions??Ee*10,100),be=C(0),Re=C(0);function tt(d,f,T){return{item:T,execution:d,verified:f.verified,findings:f.findings??[],errorClass:f.errorClass}}function rt(d,f){y.record(f.rootCause,f.intervention,!0),m.publish(d),oe(f)}function nt(d,f){let T=V(f),E=f.$retries??0,P={...f,$retries:E+1,summary:`[RETRY ${E+1}/${o}] ${T} \u2014 Previous attempt failed: ${d.findings.join("; ")}`,relatedTo:[T]};l.publish(P)}function ot(d,f){y.record(f.rootCause,f.intervention,!1),m.publish(d),oe(f);let T=V(f),E=f.$reingestions??0;E<Ee&&se(Re,et)&&u.publish({source:f.source,summary:`Verification failed for: ${T}`,evidence:d.findings.join(`
|
|
43
|
+
`),affectsAreas:f.affectsAreas,affectsEvalTasks:f.affectsEvalTasks,severity:f.severity??"high",relatedTo:[T],$reingestions:E+1})}let B=0,he=k([j.completed],([d])=>{let f=d??[];B>f.length&&(B=f.length);let T=B;B=f.length;for(let E=T;E<f.length;E++){let P=f[E],{item:S,execution:G,verify:O}=P.payload;if(G==null||O==null){oe(S);continue}let w=tt(G,O,S);if(w.verified){rt(w,S);continue}let at=w.errorClass??c({item:S,outcome:G.outcome,detail:w.findings.join("; ")}),it=S.$retries??0;at==="self-correctable"&&it<o&&se(be,Ze)?nt(w,S):ot(w,S)}},{name:"verify-dispatch"}),st=he.subscribe(()=>{}),xe=b([j.completed],()=>null,{name:"reflect",equals:()=>!1}),Y;t.priority&&(Y=Ot(p,y,t));let v=new re(e,s,j,p,J,U,y,be,Re,Y);v.addDisposer(N),v.addDisposer(Xe),v.addDisposer(st),v.addDisposer(y.dispose);for(let d of ge)v.addDisposer(d);if(v.add(x,{name:"triage-input"}),v.add(R,{name:"triage"}),v.add(A,{name:"router-input"}),v.add(ve,{name:"execute-input"}),v.add(Te,{name:"execute-enqueue"}),v.add(he,{name:"verify-dispatch"}),v.add(xe,{name:"reflect"}),v.add(y.node,{name:"strategy"}),v.addDisposer(xe.subscribe(()=>{})),Y)for(let[d,f]of Y)v.add(f,{name:`priority/${d}`}),v.addDisposer(f.subscribe(()=>{}));v.mount("queues",s),v.mount("gates",ye),v.mount("executeFlow",j);for(let[d,f]of J)v.mount(`jobs/${d}`,f);return v.tagFactory("harnessLoop",ke(t)),v}function Ot(e,t,a){if(!a.lastInteractionNs)throw new Error("harnessLoop: `opts.priority` requires `opts.lastInteractionNs` \u2014 pass a Node<number> (e.g. `fromTimer(60_000)` or a `state(monotonicNs())` you bump on human interaction). Priority scores only decay when this node settles; an internal default would freeze age at construction time.");let o=a.lastInteractionNs,n=a.priority??{},c={...H,...n.severityWeights},r=n.decayRate??L,s=n.effectivenessThreshold??.7,u=n.effectivenessBoost??15,i=new Map;for(let[l,m]of e){let p=b([m.latest,t.node,o],g=>{let y=g[0];if(y==null)return 0;let x=c[y.severity??"medium"]??40,I=(F()-g[2])/1e9,R=x*Math.exp(-r*Math.max(0,I)),A=`${y.rootCause}\u2192${y.intervention}`,N=g[1]?.get(A);return N&&N.successRate>=s&&(R+=u),R},{name:`priority/${l}`});i.set(l,p)}return i}function Ft(e,t){let a=Se(e,t),o={};for(let n of h){let c=e.queues.has(n)?e.queues.topic(n):null;o[n]=c?.retained().length??0}return{...a,queueDepths:o,strategyEntries:e.strategy.node.cache?.size??0,totalRetries:e.totalRetries.cache??0,totalReingestions:e.totalReingestions.cache??0}}function Mt(e){let t={};for(let{label:a,paths:o}of e.stageNodes())for(let n of o)t[n]=a;return t}function $t(e,t){let a=t?.logger===null?null:t?.logger??console.log,o=t?.detail??"summary",n=F(),c=[],r=[],s=Mt(e);function u(){return(F()-n)/1e9}function i(l,m,p){let g={elapsed:u(),stage:l,type:m};o!=="summary"&&(g.summary=_t(p)),o==="full"&&(g.data=p),r.push(g)}for(let[l,m]of Object.entries(s))try{let p=e.observe(l,{format:"stage-log",stageLabels:s,logger:a?g=>a(g):()=>{},includeTypes:["data","error","complete"]});p.onEvent(g=>{g.type==="data"?i(m,"data",g.data):g.type==="error"?i(m,"error",g.data):g.type==="complete"&&i(m,"complete",void 0)}),c.push(p)}catch(p){let g=p instanceof Error?p.message:String(p);i(m,"error",`observe-unavailable: ${l} \u2014 ${g}`),a&&a(`[${u().toFixed(3)}s] ${m.padEnd(9)} \u2717 observe-unavailable: ${g}`)}return{get events(){return r},dispose(){for(let l of c)l.dispose();c.length=0}}}function _t(e){if(e==null)return"null";if(typeof e=="string")return qe(e,80);if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return String(e);try{let t=JSON.stringify(e);return qe(t,120)}catch{return String(e)}}function qe(e,t){return e.length>t?`${e.slice(0,t-1)}\u2026`:e}export{Le as a,ft as b,mt as c,gt as d,yt as e,vt as f,Tt as g,Et as h,bt as i,Rt as j,h as k,ee as l,H as m,L as n,D as o,te as p,le as q,de as r,pe as s,Q as t,xt as u,fe as v,De as w,Nt as x,me as y,wt as z,Qe as A,Ue as B,re as C,Pt as D,Ft as E,$t as F,Ht as G};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{f as F,g as j,h as A}from"./chunk-
|
|
1
|
+
import{f as F,g as j,h as A}from"./chunk-F7VUYPP6.js";import{h as b,i as x}from"./chunk-POXANAJ6.js";import{p as _}from"./chunk-LYCLF26R.js";import{b as C,d as $,i as T,j as N}from"./chunk-CK2E7BTU.js";import{b as J}from"./chunk-QYADASLV.js";var Y={};J(Y,{SNAPSHOT_WIRE_VERSION:()=>v,SurfaceError:()=>o,asSurfaceError:()=>K,createGraph:()=>R,deleteSnapshot:()=>L,diffSnapshots:()=>V,listSnapshots:()=>W,restoreSnapshot:()=>U,runReduction:()=>D,saveSnapshot:()=>M});var o=class extends Error{code;details;constructor(t,r,n){super(r),this.name="SurfaceError",this.code=t,n!==void 0&&(this.details=n)}toJSON(){let t={code:this.code,message:this.message};if(this.details!==void 0){let r=q(this.details);r!==void 0&&(t.details=r)}return t}};function q(e){try{return JSON.parse(JSON.stringify(e))}catch{return}}function K(e,t="internal-error"){if(e instanceof o)return e;let r=e instanceof Error?e.message:String(e);return new o(t,r)}function R(e,t){let r=j(e);if(!r.valid)throw new o("invalid-spec",`GraphSpec validation failed:
|
|
2
2
|
${r.errors.join(`
|
|
3
3
|
`)}`,{errors:r.errors});let n=t?.catalog??{},s=F(e,n);if(!s.valid)throw new o("catalog-error",`Catalog validation failed:
|
|
4
4
|
${s.errors.join(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=Math.LN2/604800;function x(t,i,n,u=0){if(!Number.isFinite(t))return u;if(!Number.isFinite(i)||i<=0||!Number.isFinite(n)||n<=0)return Math.max(u,t);let m=t*Math.exp(-n*i);return Math.max(u,m)}export{r as a,x as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as O}from"./chunk-
|
|
1
|
+
import{C as O}from"./chunk-L77I47VU.js";import{D as H,E as A,G as k,m as D}from"./chunk-LYCLF26R.js";import{b as N,c as $,d as K,i as B,j as E}from"./chunk-CK2E7BTU.js";var C=class{_version=0;_maxSize;_buf;_head=0;_size=0;constructor(n,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),n&&n.length>0){let s=Math.min(n.length,t),h=n.length-s;for(let o=0;o<s;o++)this._buf[o]=n[h+o];this._size=s}}else this._buf=n?[...n]:[],this._size=this._buf.length}get version(){return this._version}get size(){return this._size}at(n){if(!Number.isInteger(n))return;let t=n>=0?n:this._size+n;if(!(t<0||t>=this._size))return this._maxSize!==void 0?this._buf[(this._head+t)%this._maxSize]:this._buf[t]}append(n){this._rawAppend(n),this._version+=1}appendMany(n){if(n.length===0)return;let t=this._maxSize!==void 0&&n.length>this._maxSize?n.length-this._maxSize:0;for(let s=t;s<n.length;s++)this._rawAppend(n[s]);this._version+=1}clear(){if(this._size===0)return 0;let n=this._size;if(this._maxSize===void 0)this._buf.length=0;else for(let t=0;t<n;t++)this._buf[(this._head+t)%this._maxSize]=void 0;return this._head=0,this._size=0,this._version+=1,n}trimHead(n){if(!Number.isInteger(n)||n<0)throw new RangeError(`trimHead: n must be a non-negative integer (got ${n})`);if(n===0||this._size===0)return 0;let t=Math.min(n,this._size);if(this._maxSize===void 0)this._buf.splice(0,t);else{for(let s=0;s<t;s++)this._buf[(this._head+s)%this._maxSize]=void 0;this._head=(this._head+t)%this._maxSize}return this._size-=t,this._version+=1,t}slice(n,t){if(!Number.isInteger(n)||n<0)throw new RangeError(`slice: start must be a non-negative integer (got ${n})`);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 s=t===void 0?this._size:Math.min(Math.max(t,0),this._size),h=Math.min(n,this._size);if(h>=s)return[];let o=s-h;if(this._maxSize===void 0)return this._buf.slice(h,s);let b=new Array(o);for(let r=0;r<o;r++)b[r]=this._buf[(this._head+h+r)%this._maxSize];return b}tail(n){if(!Number.isInteger(n)||n<0)throw new RangeError(`tail: n must be a non-negative integer (got ${n})`);if(n===0||this._size===0)return[];let t=Math.min(n,this._size);return this.slice(this._size-t,this._size)}toArray(){if(this._maxSize===void 0)return[...this._buf];let n=new Array(this._size);for(let t=0;t<this._size;t++)n[t]=this._buf[(this._head+t)%this._maxSize];return n}snapshot(){return this.toArray()}restore(n){if(this._maxSize===void 0){this._buf.length=0;for(let t=0;t<n.length;t++)this._buf.push(n[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 s=Math.min(n.length,t),h=n.length-s;for(let o=0;o<s;o++)this._buf[o]=n[h+o];this._size=s}this._version+=1}_rawAppend(n){if(this._maxSize===void 0){this._buf.push(n),this._size=this._buf.length;return}this._size<this._maxSize?(this._buf[(this._head+this._size)%this._maxSize]=n,this._size+=1):(this._buf[this._head]=n,this._head=(this._head+1)%this._maxSize)}};function x(g){return g.subscribe(()=>{})}var G=64;function Q(g,n={}){let{name:t,maxSize:s,versioning:h,guard:o,backend:b}=n,r=b??new C(g,s),m=A(r.toArray(),{name:t,describeKind:"state",equals:(e,i)=>e===i,...h!=null?{versioning:h}:{},...o!=null?{guard:o}:{}});function w(){let e=r.toArray();D(()=>{m.down([[$]],{internal:!0}),m.down([[N,e]],{internal:!0})})}let u=new Map,l=new Map,_=new Map;function M(e,i){return`${e}:${i===void 0?"END":i}`}function y(e){if(e.size<G)return;let i=e.keys().next();if(i.done)return;let d=e.get(i.value);d!==void 0&&d.dispose(),e.delete(i.value)}function v(e){let i=r.version;try{return e()}finally{r.version!==i&&w()}}function P(e){if(!Number.isInteger(e)||e<0)throw new RangeError(`tail: n must be a non-negative integer (got ${e})`);let i=u.get(e);if(i!==void 0)return u.delete(e),u.set(e,i),i.node;y(u);let d=k([m],([f])=>{let c=f;return e===0||c.length===0?[]:c.slice(Math.max(0,c.length-e))},{initial:r.tail(e),describeKind:"derived"}),a=x(d);return u.set(e,{node:d,dispose:a}),d}function j(e,i){if(!Number.isInteger(e)||e<0)throw new RangeError(`slice: start must be a non-negative integer (got ${e})`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw new RangeError(`slice: stop must be a non-negative integer or undefined (got ${i})`);let d=M(e,i),a=l.get(d);if(a!==void 0)return l.delete(d),l.set(d,a),a.node;y(l);let f=k([m],([p])=>{let T=p;return i===void 0?T.slice(e):T.slice(e,i)},{initial:r.slice(e,i),describeKind:"derived"}),c=x(f);return l.set(d,{node:f,dispose:c}),f}function q(e){let i=_.get(e);if(i!==void 0)return i.node;let d=k([m,e],([f,c])=>{let p=f,T=Math.max(0,Math.trunc(c??0));return p.slice(T)},{initial:[],describeKind:"derived"}),a=x(d);return _.set(e,{node:d,dispose:a}),d}let L,S;function R(){L===void 0&&(L=H([m],(e,i,d)=>{let a=e[0],c=a!=null&&a.length>0?a.at(-1):d.prevData[0];if(c==null||c.length===0){i.down([[K]]);return}i.emit(c[c.length-1])},{name:t!=null?`${t}::lastValue`:"lastValue",describeKind:"derived",initial:r.size===0?void 0:r.at(r.size-1)}),S=k([m],([e])=>e.length>0,{name:t!=null?`${t}::hasLatest`:"hasLatest",describeKind:"derived",initial:r.size>0}),x(L),x(S))}let I={entries:m,get size(){return r.size},at(e){return r.at(e)},append(e){v(()=>r.append(e))},appendMany(e){e.length!==0&&v(()=>r.appendMany(e))},clear(){v(()=>r.clear())},trimHead(e){v(()=>r.trimHead(e))},withLatest(){return R(),m},get lastValue(){return R(),L},get hasLatest(){return R(),S},view(e){switch(e.kind){case"tail":return P(e.n);case"slice":return j(e.start,e.stop);case"fromCursor":return q(e.cursor)}},attach(e){let i=e.subscribe(d=>{for(let a of d)a[0]===N&&I.append(a[1])});return()=>i()},attachStorage(e){if(e.length===0)return()=>{};let i=new Map;for(let a of e)i.set(a,r.size);(async()=>{for(let a of e)if(typeof a.loadEntries=="function")try{let f=await Promise.resolve(a.loadEntries());f.entries.length>0&&r.size===0&&(r.restore(f.entries),i.set(a,f.entries.length),w());break}catch{}})();let d=m.subscribe(a=>{for(let f of a){if(f[0]!==N)continue;let c=f[1];for(let p of e){let T=i.get(p)??0;if(c.length<T){try{let z=p.appendEntries(c);z instanceof Promise&&z.catch(()=>{})}catch{}i.set(p,c.length);continue}if(c.length===T)continue;let F=c.slice(T);i.set(p,c.length);try{let z=p.appendEntries(F);z instanceof Promise&&z.catch(()=>{})}catch{}}}});return()=>d()},disposeAllViews(){for(let e of u.values())e.dispose();u.clear();for(let e of l.values())e.dispose();l.clear();for(let e of _.values())e.dispose();_.clear()},dispose(){for(let e of u.values())e.dispose();u.clear();for(let e of l.values())e.dispose();l.clear();for(let e of _.values())e.dispose();_.clear()}};return I}var V=new WeakMap;function Z(g){let n=V.get(g);if(n)return n;let t=g.map(u=>u.cache??[]),s=t.flat(),h=A(s,{name:"mergeReactiveLogs",describeKind:"state",equals:(u,l)=>u===l}),o=g.map((u,l)=>[...t[l]??[]]),b=[];for(let u=0;u<g.length;u++){let l=u,_=g[l].subscribe(M=>{for(let y of M)if(y[0]===N)o[l]=[...y[1]],h.emit(o.flat());else if(y[0]===B){o[l]=[];let v=b[l];v!==void 0&&(b[l]=void 0,v())}else y[0]===E&&h.down([[E,y[1]]])});b.push(_)}let r=O(h),m=!1,w={node:h,dispose(){if(!m){m=!0;for(let u of b)u?.();b.length=0,r(),V.delete(g)}}};return V.set(g,w),w}export{C as a,Q as b,Z as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as D,c as j,d as V,e as $}from"./chunk-
|
|
1
|
+
import{a as D,c as j,d as V,e as $}from"./chunk-KNVCCBIU.js";import{a as v}from"./chunk-ESMPEKEV.js";import{i as S}from"./chunk-D5RFJOZ2.js";import{n as T}from"./chunk-AK5RHMC5.js";import{m as R,x as N}from"./chunk-L77I47VU.js";import{G as K,o as b,p as L}from"./chunk-LYCLF26R.js";import{j as O}from"./chunk-CK2E7BTU.js";function w(){let e=new Error("aborted");return e.name="AbortError",e}function W(e,r){return e<=0?Promise.resolve():r?.aborted?Promise.reject(w()):new Promise((t,s)=>{let p=new v,u,y=()=>{p.cancel(),r&&u&&r.removeEventListener("abort",u)};p.start(e,()=>{y(),t()}),r&&(u=()=>{y(),s(w())},r.addEventListener("abort",u,{once:!0}))})}function U(e={}){let r=e.provider??"dry-run",t=e.model??"dry-run-v1",s=e.latencyMs??0,p=Math.max(1,e.streamChunkSize??16),u=e.respond??(d=>{let o=[...d].reverse().find(n=>n.role==="user");return o?`echo: ${o.content}`:"dry-run: no user message"}),y=e.usage??((d,o)=>{let n=d.reduce((a,l)=>a+l.content.length,0);return{input:{regular:Math.ceil(n/4)},output:{regular:Math.ceil(o.length/4)}}});return{provider:r,model:t,async invoke(d,o){if(await W(s,o?.signal),o?.signal?.aborted)throw w();let n=u(d,o),a=y(d,n);return{content:n,usage:a,finishReason:"stop",model:o?.model??t,provider:r,tier:o?.tier,metadata:{dryRun:!0}}},async*stream(d,o){let n=u(d,o),a=y(d,n),l=Math.ceil(n.length/p)||1,i=s>0?s/l:0;for(let c=0;c<n.length;c+=p){if(o?.signal?.aborted)throw w();await W(i,o?.signal),yield{type:"token",delta:n.slice(c,c+p)}}yield{type:"usage",usage:a},yield{type:"finish",reason:"stop"}}}}function _(e){let{storage:r,mode:t="read-write",keyFn:s,keyPrefix:p="llm-replay"}=e,y=V({storage:r,keyPrefix:p,mode:t==="read-strict"?"read":t,keyContext:({messages:o,opts:n})=>{let{signal:a,keyContext:l,...i}=n??{};return{messages:o,opts:i}}});async function d(o,n){if(s){if(s.length<=1){let l={messages:o,opts:n,context:n?.keyContext},i=await s(l);return`${p}:${i}`}let a=await s(o,n);return`${p}:${a}`}return y.keyFor({messages:o,opts:n})}return{keyFor:d,async lookup(o,n){if(t!=="write"){if(s){let a=await d(o,n),l=await r.load(a);return l===void 0?void 0:l}return y.lookup({messages:o,opts:n})}},async store(o,n,a){if(t!=="read"){if(s){let l=await d(o,n);await r.save(l,a);return}await y.store({messages:o,opts:n},a)}},async forget(o,n){if(!(t==="read"||t==="write")&&r.delete){if(s){let a=await d(o,n);await r.delete(a);return}await y.forget({messages:o,opts:n})}}}}function z(e,r,t){return{provider:t?.provider??e.provider,model:t?.model??e.model,capabilities:t?.capabilities??e.capabilities?.bind(e),invoke:r.invoke,stream:r.stream}}function ce(e,r){let{onResp:t,onError:s,name:p}=r;if(e!=null&&typeof e.then=="function"){let n=e;return s?n.then(t).catch(a=>{throw s(a),a}):n.then(t)}if(e!=null&&typeof e=="object"&&"content"in e)return t(e);let u=R(e);if(s){let n=!1;u.subscribe(a=>{for(let l of a){if(n)return;l[0]===O&&(n=!0,s(l[1]))}})}let y,d=!1,o=T(u,n=>{y=t(n),d=!0});return K([o],([n])=>n==null?null:d?y:t(n),{name:p??"adapt/invokeTap"})}function pe(e){let r=e.endNs??b();return{timestamp:r,wallClock:e.startWallClockNs??L(),provider:e.provider,model:e.model,tier:e.tier,usage:e.usage,latencyMs:Math.max(0,(r-e.startNs)/1e6),method:e.method,...e.error?{error:e.error}:{}}}function ye(){return{input:{regular:0},output:{regular:0}}}var G=Symbol.for("graphrefly.adapter.middlewareLayers");function J(e,r,t){let p=[...t?Q(t):[],r];return Object.defineProperty(e,G,{value:Object.freeze(p),enumerable:!1,writable:!1,configurable:!1}),e}function Q(e){let r=e[G];return Array.isArray(r)?r:[]}var M=class extends Error{constructor(t,s){super(`withReplayCache: no cached response for ${s} (key=${t}, mode=read-strict)`);this.key=t;this.method=s}name="ReplayCacheMissError"};function q(e,r){let t=r.mode??"read-write",s=r.cacheStreaming??!1,p=r.captureStreamCadence??!1,u=r.replaySpeed??1,y=r.keyPrefix??"llm-replay",d=t==="read"||t==="read-strict",o=_({storage:r.storage,mode:t==="write-only"?"write":t,keyFn:r.keyFn,keyPrefix:y}),n=i=>i<=0?Promise.resolve():new Promise(c=>{new v().start(i,()=>c())}),a=$(async({messages:i,invokeOpts:c})=>await N(R(e.invoke(i,c))),{keyFn:({_precomputedKey:i})=>i}),l=z(e,{async invoke(i,c){let C=await o.keyFor(i,c),f=await o.lookup(i,c);if(f?.response){let k=f.response;return{...k,metadata:{...k.metadata??{},replayCache:"hit"}}}if(t==="read-strict")throw new M(C,"invoke");let h=await a({messages:i,invokeOpts:c,_precomputedKey:C});return d||await o.store(i,c,{response:h,storedAtNs:L()}),h},async*stream(i,c){if(!s){for await(let m of e.stream(i,c))yield m;return}let C=await o.keyFor(i,c),f=await o.lookup(i,c);if(f){let m=f.response;if(f.streamChunks&&f.streamCadenceMs)for(let g=0;g<f.streamChunks.length;g++){let A=f.streamCadenceMs[g]??0,E=u>0?A/u:0;E>0&&await n(E),yield{type:"token",delta:f.streamChunks[g]?.delta??""}}else m.content&&(yield{type:"token",delta:m.content});m.usage&&(yield{type:"usage",usage:m.usage}),yield{type:"finish",reason:m.finishReason??"stop"};return}if(t==="read-strict")throw new M(C,"stream");let h="",k,P,F=[],I=[],x;for await(let m of e.stream(i,c)){if(m.type==="token"&&(h+=m.delta,p)){let g=b(),A=x===void 0?0:(g-x)/1e6;I.push(A),x=g,F.push({delta:m.delta})}m.type==="usage"&&(k=m.usage),m.type==="finish"&&(P=m.reason),yield m}if((h||k)&&!d){let g={response:{content:h,usage:k??{input:{regular:0},output:{regular:0}},finishReason:P,model:e.model??c?.model??"",provider:e.provider},storedAtNs:L(),...p?{streamChunks:F,streamCadenceMs:I}:{}};await o.store(i,c,g)}}});return J(l,"withReplayCache",e),l}var B=j;var Ae=M;function H(e,r){return{content:"[fallback: no cached response available for this request]",usage:{input:{regular:0},output:{regular:0}},finishReason:"stop",model:r,provider:e,metadata:{degraded:!0,reason:"no-fixture"}}}function Y(e,r,t){return typeof e=="string"?{content:e,usage:{input:{regular:0},output:{regular:0}},finishReason:"stop",model:t,provider:r,metadata:{degraded:!0,reason:"respond"}}:e}async function X(e,r){if("key"in e)return e.key;let t=B({messages:e.messages,opts:e.invokeOpts??{}}),s=await D(t);return`${r}:${s}`}function Z(e){let r={response:e.response,storedAtNs:L()};if("key"in e&&e.stream){let t=e.stream.chunks.filter(s=>s.type==="token");return{...r,streamChunks:t.map(s=>({delta:s.delta})),streamCadenceMs:e.stream.delaysMs??t.map(()=>0)}}return r}function ee(e,r){let t=[];if(e.fixtures!=null&&t.push("fixtures"),e.fixturesStorage!=null&&t.push("fixturesStorage"),t.length>1)throw new TypeError(`fallbackAdapter: \`fixtures\` and \`fixturesStorage\` are mutually exclusive; got both ${t.join(" and ")}. Pick one source. For filesystem directories use the node subpath's \`fallbackAdapter\`.`);if(e.fixtures){let s=S(),p=e.fixtures,u=(async()=>{for(let y of p){let d=await X(y,r);await s.save(d,Z(y))}})();return u.catch(()=>{}),{tier:s,seedReady:u}}return e.fixturesStorage?{tier:e.fixturesStorage,seedReady:Promise.resolve()}:{tier:void 0,seedReady:Promise.resolve()}}function Se(e={}){let r=e.provider??"fallback",t=e.model??"fallback",s=e.onMiss??"respond",p=e.keyPrefix??"fallback",u=e.record?e.record.adapter:s==="throw"?U({provider:r,model:t,respond:()=>"[unreachable: read-strict mode throws on miss]"}):{provider:r,model:t,async invoke(a,l){let i=e.respond?e.respond(a,l):H(r,t);return Y(i,r,t)},async*stream(a,l){let i=e.respond?e.respond(a,l):H(r,t),c=Y(i,r,t);yield{type:"token",delta:c.content},c.usage&&(yield{type:"usage",usage:c.usage}),yield{type:"finish",reason:c.finishReason??"stop"}}},y,d=Promise.resolve();if(e.record){if(!e.record.storage)throw new TypeError("fallbackAdapter: `record.storage` is required in record mode. For filesystem `record.dir` convenience, use the node subpath's `fallbackAdapter`.");y=e.record.storage}else{let a=ee(e,p);y=a.tier??S(),d=a.seedReady}let o=e.record?"read-write":s==="throw"?"read-strict":"read",n=q(u,{storage:y,mode:o,keyPrefix:p,cacheStreaming:!0,captureStreamCadence:!0,replaySpeed:e.replaySpeed,...e.keyFn?{keyFn:e.keyFn}:{}});return{provider:r,model:t,capabilities:n.capabilities?.bind(n),async invoke(a,l){return await d,n.invoke(a,l)},async*stream(a,l){await d;for await(let i of n.stream(a,l))yield i}}}export{U as a,z as b,ce as c,pe as d,ye as e,J as f,M as g,q as h,B as i,Ae as j,Se as k};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as M}from"./chunk-L6NSJVJZ.js";import{
|
|
1
|
+
import{a as M}from"./chunk-L6NSJVJZ.js";import{b as S}from"./chunk-TT4C7DXW.js";import{i as l}from"./chunk-POXANAJ6.js";import{C as o}from"./chunk-L77I47VU.js";import{D as P,E as v,G as _,m as N}from"./chunk-LYCLF26R.js";import{b as L,i as I}from"./chunk-CK2E7BTU.js";import{b as C}from"./chunk-QYADASLV.js";var U={};C(U,{MessagingHubGraph:()=>w,SubscriptionGraph:()=>T,TopicBridgeGraph:()=>y,TopicGraph:()=>m,TopicRegistry:()=>O,messagingHub:()=>H,subscription:()=>D,topic:()=>z,topicBridge:()=>F});var R=256;function c(i,e){if(!Number.isFinite(i)||!Number.isInteger(i)||i<0)throw new Error(`${e} must be a non-negative integer`);return i}function a(i,e){return M("messaging",i,e)}var B=1024,m=class extends l{_log;events;latest;hasLatest;constructor(e,s={}){super(e,s.graph),this._log=S([],{name:"events",maxSize:s.retainedLimit??B}),this._log.withLatest(),this.events=this._log.entries,this.add(this.events,{name:"events"}),this.latest=_([this.events],([t])=>{let n=t;return n.length===0?null:n[n.length-1]},{name:"latest",describeKind:"derived",meta:a("topic_latest")}),this.add(this.latest,{name:"latest"}),this.addDisposer(o(this.latest)),this.hasLatest=_([this.events],([t])=>t.length>0,{name:"hasLatest",describeKind:"derived",meta:a("topic_has_latest")}),this.add(this.hasLatest,{name:"hasLatest"}),this.addDisposer(o(this.hasLatest)),this.addDisposer(()=>{this.events.down([[I]])}),this.addDisposer(()=>this._log.disposeAllViews())}publish(e){if(e===void 0)throw new TypeError(`TopicGraph "${this.name}": publish(undefined) is not allowed (spec \xA75.12 SENTINEL).`);this._log.append(e)}attachEventStorage(e){return this._log.attachStorage(e)}retained(){return this.events.cache}get _logBundle(){return this._log}},T=class extends l{cursor;available;topic;_disposed=!1;constructor(e,s,t={}){super(e,t.graph),this.topic=s;let n;if(t.from!==void 0?t.from==="retained"?n=0:t.from==="now"?n=s.events.cache.length:n=c(t.from,"subscription from"):n=c(t.cursor??0,"subscription cursor"),this.cursor=v(n,{name:"cursor",describeKind:"state",meta:a("subscription_cursor")}),this.add(this.cursor,{name:"cursor"}),this.available=s._logBundle.view({kind:"fromCursor",cursor:this.cursor}),this.add(this.available,{name:"available"}),this.addDisposer(o(this.available)),t.advanceOn!==void 0){let r=t.advanceOn,b=!1,d=P([r],()=>{if(!b){b=!0;return}if(this._disposed)return;let p=this.available.cache;if(p.length===0)return;let g=this.cursor.cache+p.length;this.cursor.emit(g)},{name:"advancePump",describeKind:"effect",meta:a("subscription_advance_pump")});this.add(d,{name:"advancePump"}),this.addDisposer(o(d))}}ack(e){if(this._disposed)return this.cursor.cache;let s=this.available.cache,t=e===void 0?s.length:c(e,"subscription ack count"),n=Math.min(t,s.length);if(n<=0)return this.cursor.cache;let r=this.cursor.cache+n;return this.cursor.emit(r),r}pull(e){if(this._disposed)return[];let s=this.available.cache,t=e===void 0?s.length:c(e,"subscription pull limit");return s.slice(0,t)}pullAndAck(e){if(this._disposed)return{items:[],cursor:this.cursor.cache};let s=this.available.cache,t=e===void 0?s.length:c(e,"subscription pullAndAck limit"),n=s.slice(0,t);if(n.length===0)return{items:n,cursor:this.cursor.cache};let r=this.cursor.cache+n.length;return this.cursor.emit(r),{items:n,cursor:r}}dispose(){this._disposed||(this._disposed=!0,this.cursor.down([[I]]),this.destroy())}},y=class extends l{_sourceSub;bridgedCount;output;constructor(e,s,t,n={}){super(e,n.graph),this._sourceSub=D(`${e}-subscription`,s,{cursor:n.cursor}),this.mount("subscription",this._sourceSub);let r=Math.max(1,c(n.maxPerPump??R,"topic bridge maxPerPump")),b=n.map??(u=>u);this.output=_([this._sourceSub.available],([u])=>{let f=u,h=[],k=Math.min(f.length,r);for(let x=0;x<k;x++){let A=b(f[x]);A!==void 0&&h.push(A)}return h},{name:"output",describeKind:"derived",meta:a("topic_bridge_output",{targetRef:t.name}),initial:[]}),this.add(this.output,{name:"output"}),this.addDisposer(o(this.output)),this.bridgedCount=v(0,{name:"bridgedCount",describeKind:"state",meta:a("topic_bridge_count")}),this.add(this.bridgedCount,{name:"bridgedCount"}),this.addDisposer(o(this.bridgedCount));let d=this.output,p=this._sourceSub,g=this.bridgedCount,G=P([d],()=>{let u=d.cache;if(u.length===0)return;let f=p.available.cache.length,h=Math.min(f,r);if(h>0){p.ack(h);let k=g.cache??0;g.emit(k+u.length)}},{name:"ackPump",describeKind:"effect",meta:a("topic_bridge_ack_pump")});this.add(G,{name:"ackPump"}),this.addDisposer(o(G));let E=K(this.output,t);this.addDisposer(E)}};function K(i,e){return i.subscribe(s=>{for(let t of s){if(t[0]!==L)continue;let n=t[1];n.length!==0&&N(()=>{for(let r of n)e.publish(r)})}})}var O=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,s){this._map.set(e,s)}delete(e){return this._map.delete(e)}keys(){return this._map.keys()}},w=class extends l{_registry;version;_defaultTopicOptions;constructor(e,s={}){super(e,s.graph);let t=v(0,{name:"version",describeKind:"state",meta:a("hub_version")});this.add(t,{name:"version"}),this.version=t,this._registry=new O(t),this._defaultTopicOptions={...s.defaultTopicOptions??{}}}get size(){return this._registry.size}has(e){return this._registry.has(e)}topicNames(){return this._registry.keys()}topic(e,s){let t=this._registry.get(e);if(t===void 0){let n={...this._defaultTopicOptions,...s??{}};t=new m(e,n),this._registry.set(e,t),this.mount(e,t);let r=this.version.cache??0;this.version.emit(r+1)}return t}publish(e,s){this.topic(e).publish(s)}publishMany(e){N(()=>{for(let[s,t]of e)this.topic(s).publish(t)})}subscribe(e,s,t){let n=this.topic(s);return new T(e,n,t)}removeTopic(e){if(!this._registry.has(e))return!1;try{this.remove(e)}finally{this._registry.delete(e);let s=this.version.cache??0;this.version.emit(s+1)}return!0}};function z(i,e){return new m(i,e)}function H(i,e){return new w(i,e)}function D(i,e,s){return new T(i,e,s)}function F(i,e,s,t){return new y(i,e,s,t)}export{m as a,T as b,y as c,O as d,w as e,z as f,H as g,D as h,F as i,U as j};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as O,f as v,k as P}from"./chunk-
|
|
1
|
+
import{a as O,f as v,k as P}from"./chunk-UISPDFJ3.js";import{ba as _,k as A}from"./chunk-CYOSWFT2.js";import{d as E}from"./chunk-4MKL6Q3K.js";import{m as U,x as T}from"./chunk-L77I47VU.js";import{o as y}from"./chunk-LYCLF26R.js";function G(e={}){return e.sdk?V(e):H(e)}function b(e,t,o,r){let s=t?.model??o;if(!s)throw new Error("anthropicAdapter: model must be set via options.model or invokeOpts.model");let{system:n,chat:i}=J(e,t?.systemPrompt),a={model:s,messages:i.map(F),max_tokens:t?.maxTokens??4096};return n&&(a.system=n),t?.temperature!=null&&(a.temperature=t.temperature),t?.tools&&t.tools.length>0&&(a.tools=t.tools.map(Y)),t?.maxReasoningTokens!=null&&(a.thinking={type:"enabled",budget_tokens:t.maxReasoningTokens}),t?.cacheHint,r&&(a.stream=!0),t?.providerExtras&&Object.assign(a,t.providerExtras),a}function J(e,t){let o=[];t&&o.push(t);let r=[];for(let s of e)s.role==="system"?o.push(s.content):r.push(s);return{system:o.length>0?o.join(`
|
|
2
2
|
|
|
3
3
|
`):void 0,chat:r}}function F(e){if(e.role==="tool")return{role:"user",content:[{type:"tool_result",tool_use_id:e.toolCallId,content:e.content}]};if(e.role==="assistant"&&e.toolCalls&&e.toolCalls.length>0){let t=[];e.content&&t.push({type:"text",text:e.content});for(let o of e.toolCalls)t.push({type:"tool_use",id:o.id,name:o.name,input:o.arguments});return{role:"assistant",content:t}}return{role:e.role,content:e.content}}function Y(e){return{name:e.name,description:e.description,input_schema:e.parameters}}function R(e,t){if(!e)return{...t};let o={...e};return t.input_tokens!=null&&(o.input_tokens=t.input_tokens),t.output_tokens!=null&&(o.output_tokens=t.output_tokens),t.cache_read_input_tokens!=null&&(o.cache_read_input_tokens=t.cache_read_input_tokens),t.cache_creation_input_tokens!=null&&(o.cache_creation_input_tokens=t.cache_creation_input_tokens),t.cache_creation&&(o.cache_creation={...e.cache_creation??{},...t.cache_creation}),t.server_tool_use&&(o.server_tool_use={...e.server_tool_use??{},...t.server_tool_use}),o}function x(e){let t={input:{regular:e?.input_tokens??0},output:{regular:e?.output_tokens??0},raw:e};return e?.cache_read_input_tokens&&(t.input.cacheRead=e.cache_read_input_tokens),e?.cache_creation?(e.cache_creation.ephemeral_5m_input_tokens&&(t.input.cacheWrite5m=e.cache_creation.ephemeral_5m_input_tokens),e.cache_creation.ephemeral_1h_input_tokens&&(t.input.cacheWrite1h=e.cache_creation.ephemeral_1h_input_tokens)):e?.cache_creation_input_tokens&&(t.input.cacheWrite5m=e.cache_creation_input_tokens),e?.server_tool_use?.web_search_requests&&(t.auxiliary={webSearchRequests:e.server_tool_use.web_search_requests}),t}function K(e,t){let o=[],r=[];for(let s of e.content)if(s.type==="text"&&typeof s.text=="string")o.push(s.text);else if(s.type==="tool_use"){let n=s;r.push({id:n.id,name:n.name,arguments:n.input??{}})}return{content:o.join(""),toolCalls:r.length>0?r:void 0,usage:x(e.usage),finishReason:e.stop_reason,latencyMs:t,model:e.model,provider:"anthropic"}}function H(e){let t=e.apiKey??globalThis.process?.env?.ANTHROPIC_API_KEY,o=e.baseURL??"https://api.anthropic.com",r=e.anthropicVersion??"2023-06-01",s=e.fetchImpl??fetch,n=()=>{if(!t)throw new Error("anthropicAdapter: apiKey required for invoke/stream (or provide opts.sdk)");return{"x-api-key":t,"anthropic-version":r,"content-type":"application/json",...e.headers??{}}};return{provider:"anthropic",model:e.model,async invoke(i,a){let d=b(i,a,e.model,!1),g=y(),l=await s(`${o}/v1/messages`,{method:"POST",headers:n(),body:JSON.stringify(d),signal:a?.signal});if(!l.ok)throw await _(l,"Anthropic");let c=await l.json(),p=Math.max(0,(y()-g)/1e6);return K(c,p)},async*stream(i,a){let d=b(i,a,e.model,!0),g=await s(`${o}/v1/messages`,{method:"POST",headers:{...n(),accept:"text/event-stream"},body:JSON.stringify(d),signal:a?.signal});if(!g.ok)throw await _(g,"Anthropic");if(!g.body)throw new Error("anthropicAdapter: streaming response has no body");let l,c,p=new Map;for await(let m of A(g.body,{signal:a?.signal})){let h=m.data;if(!h)continue;let k;try{k=JSON.parse(h)}catch{continue}switch(k.type){case"message_start":{l=R(l,k.message.usage);break}case"content_block_start":{let u=k,f=u.content_block;f.type==="tool_use"&&(p.set(u.index,{id:String(f.id??""),name:String(f.name??""),argBuf:""}),yield{type:"tool-call-delta",delta:{id:String(f.id??""),name:String(f.name??"")}});break}case"content_block_delta":{let u=k,f=u.delta;if(f.type==="text_delta"&&typeof f.text=="string")yield{type:"token",delta:f.text};else if(f.type==="input_json_delta"&&typeof f.partial_json=="string"){let S=p.get(u.index);S&&(S.argBuf+=f.partial_json),yield{type:"tool-call-delta",delta:{argumentsDelta:f.partial_json}}}else f.type==="thinking_delta"&&typeof f.thinking=="string"&&(yield{type:"thinking",delta:f.thinking});break}case"message_delta":{let u=k;u.delta.stop_reason&&(c=u.delta.stop_reason),u.delta.usage&&(l=R(l,u.delta.usage));break}case"message_stop":break}}l&&(yield{type:"usage",usage:x(l)}),yield{type:"finish",reason:c??"stop"}}}}function V(e){let t=e.sdk;if(!t)throw new Error("sdkBackedAnthropic: sdk instance required");return{provider:"anthropic",model:e.model,async invoke(o,r){let s=b(o,r,e.model,!1),n=y(),i=await t.messages.create(s,{signal:r?.signal}),a=Math.max(0,(y()-n)/1e6);return K(i,a)},async*stream(o,r){if(!t.messages.stream)throw new Error("sdkBackedAnthropic: SDK instance does not expose .messages.stream");let s=b(o,r,e.model,!0),n,i;for await(let a of t.messages.stream(s,{signal:r?.signal}))switch(a.type){case"message_start":n=R(n,a.message.usage);break;case"content_block_delta":{let d=a.delta;d?.type==="text_delta"&&typeof d.text=="string"?yield{type:"token",delta:d.text}:d?.type==="input_json_delta"&&typeof d.partial_json=="string"?yield{type:"tool-call-delta",delta:{argumentsDelta:d.partial_json}}:d?.type==="thinking_delta"&&typeof d.thinking=="string"&&(yield{type:"thinking",delta:d.thinking});break}case"message_delta":{let d=a;d.delta.stop_reason&&(i=d.delta.stop_reason),d.delta.usage&&(n=R(n,d.delta.usage));break}}n&&(yield{type:"usage",usage:x(n)}),yield{type:"finish",reason:i??"stop"}}}}function D(e={}){return e.sdk?X(e):Q(e)}function w(e,t){let o=[],r=[];t?.systemPrompt&&o.push(t.systemPrompt);for(let i of e){if(i.role==="system"){o.push(i.content);continue}if(i.role==="tool"){r.push({role:"user",parts:[{functionResponse:{name:i.name??i.toolCallId??"tool",response:{result:i.content}}}]});continue}if(i.role==="assistant"&&i.toolCalls&&i.toolCalls.length>0){let a=[];i.content&&a.push({text:i.content});for(let d of i.toolCalls)a.push({functionCall:{name:d.name,args:d.arguments}});r.push({role:"model",parts:a});continue}r.push({role:i.role==="assistant"?"model":"user",parts:[{text:i.content}]})}let s={contents:r};o.length>0&&(s.systemInstruction={role:"system",parts:[{text:o.join(`
|
|
4
4
|
|