@callbag-recharge/callbag-recharge 0.26.0 → 0.27.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/ai/index.cjs +16 -16
- package/dist/ai/index.d.cts +4 -4
- package/dist/ai/index.d.ts +4 -4
- package/dist/ai/index.js +1 -1
- package/dist/ai/memoryStore/index.d.cts +2 -2
- package/dist/ai/memoryStore/index.d.ts +2 -2
- package/dist/ai/ragPipeline/index.d.cts +2 -2
- package/dist/ai/ragPipeline/index.d.ts +2 -2
- package/dist/{backoff-BXsH2Ago.d.cts → backoff-DTxCwT6Y.d.cts} +5 -1
- package/dist/{backoff-BXsH2Ago.d.ts → backoff-DTxCwT6Y.d.ts} +5 -1
- package/dist/chunk-D3D4V5KM.js +1 -0
- package/dist/chunk-RAMDA42C.js +1 -0
- package/dist/chunk-ULLWFMTO.js +1 -0
- package/dist/{circuitBreaker--CJqUJ4u.d.cts → circuitBreaker-D_6HSct4.d.cts} +7 -1
- package/dist/{circuitBreaker-eEj1lt8U.d.ts → circuitBreaker-Ne3hUw3t.d.ts} +7 -1
- package/dist/data/index.cjs +3 -3
- package/dist/data/index.d.cts +2 -2
- package/dist/data/index.d.ts +2 -2
- package/dist/data/index.js +1 -1
- package/dist/{executionLog-EPbLbbSd.d.ts → executionLog-CTa3GpdO.d.ts} +1 -1
- package/dist/{executionLog-BIdo4sqy.d.cts → executionLog-DTmkFVng.d.cts} +1 -1
- package/dist/memory/index.d.cts +3 -3
- package/dist/memory/index.d.ts +3 -3
- package/dist/messaging/index.cjs +9 -6
- package/dist/messaging/index.d.cts +260 -7
- package/dist/messaging/index.d.ts +260 -7
- package/dist/messaging/index.js +6 -3
- package/dist/orchestrate/executionLogAdapters.node.d.cts +2 -2
- package/dist/orchestrate/executionLogAdapters.node.d.ts +2 -2
- package/dist/orchestrate/index.cjs +6 -6
- package/dist/orchestrate/index.d.cts +131 -10
- package/dist/orchestrate/index.d.ts +131 -10
- package/dist/orchestrate/index.js +3 -3
- package/dist/{types-DbCdOVbw.d.cts → types-Ba0jr02y.d.cts} +1 -1
- package/dist/{types-ClmMSIr-.d.ts → types-ClFiOUXg.d.ts} +1 -1
- package/dist/{types-BRnNQbJn.d.cts → types-DYpaJ7gP.d.cts} +3 -1
- package/dist/{types-XRfOHCPC.d.cts → types-ibw_KZuI.d.cts} +9 -3
- package/dist/{types-n54oEEx_.d.ts → types-kbaGU2yR.d.ts} +3 -1
- package/dist/{types-CJKW4Ae9.d.ts → types-kdj4VxGp.d.ts} +9 -3
- package/dist/utils/index.cjs +9 -9
- package/dist/utils/index.d.cts +3 -3
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +6 -6
- package/package.json +1 -1
- package/dist/chunk-2HSHE2EI.js +0 -1
- package/dist/chunk-5UIA6BIQ.js +0 -1
- package/dist/chunk-IB56FLRE.js +0 -1
package/dist/ai/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}static _signalLabel(t){return t===
|
|
3
|
-
`)}static toD2(t){let o=t?.direction??"down",n=e.snapshot(),r=[`direction: ${o}`,""],i={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},s=new Map;function u(c){let d=c.replace(/[^a-zA-Z0-9_]/g,"_"),
|
|
4
|
-
`)}static annotate(t,o){if(!e.enabled)return;e._annotations.set(t,o);let n={node:e._resolveKey(t),reason:o,timestamp:Date.now()},r=e.maxTraceEntries;r<=0||(e._traceLog.length<r?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%r)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static timeline(t){let o=null,n=[];return t.source(W,(r,i)=>{if(r===W){o=i;return}let s={timestamp:Date.now(),type:r===Z?"data":r===U?"signal":"end",data:i,inBatch:ve()};n.push(s),r===j&&(o=null)}),{entries:n,dispose:()=>o?.(j)}}static observeDerived(t){let o=[],n=t,r=n._fn;if(typeof r!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:o};n._fn=()=>{let a=n._deps.map(c=>c.get()),l=r();return o.push({result:l,depValues:a,timestamp:Date.now()}),l};let i=e._observe(t),s=i.dispose;return{...i,evaluations:o,dispose:()=>{n._fn=r,s()},reconnect:()=>(n._fn=r,s(),e.observeDerived(t))}}static observeTaskState(t){let o=t.status.get(),n=[],r=null;return t.status.source(W,(i,s)=>{if(i===W){r=s;return}if(i===Z){let u=s;if(u!==o){let a={from:o,to:u,timestamp:Date.now()};u==="error"&&(a.error=t.error.get()),n.push(a),o=u}}i===j&&(r=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{r?.(j)}}}static causalityTrace(t){let o=[],n=t,r=n._fn;if(typeof r!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:o};let i=n._deps,s=i.map(c=>c.get());n._fn=()=>{let c=i.map(T=>T.get()),d=r(),h=-1;for(let T=0;T<i.length;T++)if(!Object.is(c[T],s[T])){h=T;break}return o.push({result:d,triggerDepIndex:h,triggerDepName:h>=0?e.getName(i[h]):void 0,depValues:c,timestamp:Date.now()}),s=c,d};let u=e._observe(t),a=u.dispose;return{...u,causality:o,dispose:()=>{n._fn=r,a()},reconnect:()=>(n._fn=r,a(),e.causalityTrace(t))}}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var ot=1,le=64,ce=2,Re=4,It=8,Ot=16,he=32,fe=1024,ne=Fe,Me=Qe<<oe,qe=Xe<<oe,st=Ye<<oe,On=et<<oe,$n=tt<<oe,Pn=Ze<<oe,Ve=class{_value;_output=null;_flags;get _status(){return nt(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,o){this._value=o?.initial,this._fn=t,this._eqFn=o?.equals,this._getterFn=o?.getter,this._initial=o?.initial;let n=0;o?.autoDirty!==!1&&(n|=Re),o?.resetOnTeardown&&(n|=It),o?.resubscribable&&(n|=Ot),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),o?._skipInspect||se.register(this,{kind:"producer",...o})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,o){let n=this._output;if(n)if(this._flags&le)for(let r of n)r(t,o);else n(t,o)}emit(t){this._flags&ce||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(ve()?this._flags&he||(this._flags|=he,this._flags&Re&&(this._flags=this._flags&~ne|Me,this._dispatch(U,X)),rt(()=>{this._flags&=~he,this._flags=this._flags&~ne|qe,this._dispatch(Z,this._value)})):(this._flags&Re&&!(this._flags&fe)&&(this._flags=this._flags&~ne|Me,this._dispatch(U,X)),this._flags=this._flags&~ne|qe,this._dispatch(Z,this._value))))}signal(t){this._flags&ce||!this._output||(t===X?this._flags=this._flags&~ne|Me:t===re&&(this._flags=this._flags&~ne|Pn),this._dispatch(U,t))}complete(){if(this._flags&ce)return;this._flags=(this._flags|ce)&~ne|On;let t=this._output,o=this._flags≤if(this._output=null,this._flags&=~(le|fe),this._singleDepCount=0,this._stop(),t)if(o)for(let n of t)n(j);else t(j)}error(t){if(this._flags&ce)return;this._flags=(this._flags|ce)&~ne|$n;let o=this._output,n=this._flags≤if(this._output=null,this._flags&=~(le|fe),this._singleDepCount=0,this._stop(),o)if(n)for(let r of o)r(j,t);else o(j,t)}_start(){if(this._flags&ot||!this._fn)return;this._flags|=ot,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:o=>this.signal(o),complete:()=>this.complete(),error:o=>this.error(o),onSignal:o=>{this._onLifecycleSignal=o}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ot&&(this._flags&=~ot,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&It&&(this._value=this._initial),this._flags&ce||(this._flags=this._flags&~ne|st))}_handleLifecycleSignal(t){if(!(this._flags&ce)){if(t===pe){this._onLifecycleSignal?.(t),this.complete();return}t===ge&&(this._value=this._initial,this._flags&=~he),this._onLifecycleSignal?.(t),t===ge&&this.emit(this._initial)}}source(t,o){if(t===W){let n=o;if(this._flags&ce)if(this._flags&Ot&&this._output===null)this._flags=this._flags&~(ce|ne)|st;else{n(W,i=>{}),n(j);return}if(this._output===null)this._output=n;else if(this._flags&le)this._output.add(n);else{let i=new Set;i.add(this._output),i.add(n),this._output=i,this._flags=(this._flags|le)&~fe}let r=!1;n(W,(i,s)=>{if(i===Z&&n(Z,this._value),i===U){s===Te&&!r?(r=!0,this._singleDepCount++,this._flags&le||(this._flags|=fe)):Ee(s)&&this._handleLifecycleSignal(s);return}if(i===j){if(r&&(r=!1,this._singleDepCount--),this._output===null)return;if(this._flags&le){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~le,this._singleDepCount>0&&(this._flags|=fe)):u.size===0&&(this._output=null,this._flags&=~(le|fe),this._singleDepCount=0,this._flags=this._flags&~ne|st,this._stop())}else this._output===n&&(this._output=null,this._flags&=~fe,this._singleDepCount=0,this._flags=this._flags&~ne|st,this._stop())}}),Dt(()=>this._start())}}};function ie(e,t){return new Ve(e,t)}var St=class extends Ve{constructor(t,o){super(void 0,{initial:t,autoDirty:!0,equals:o?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),se.register(this,{kind:"state",...o})}get(){return this._value}set(t){this._flags&ce||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(ve()?this._flags&he||(this._flags|=he,this._flags&Re&&(this._flags=this._flags&~ne|Me,this._dispatch(U,X)),rt(()=>{this._flags&=~he,this._flags=this._flags&~ne|qe,this._dispatch(Z,this._value)})):(this._flags&Re&&!(this._flags&fe)&&(this._flags=this._flags&~ne|Me,this._dispatch(U,X)),this._flags=this._flags&~ne|qe,this._dispatch(Z,this._value))))}update(t){this.set(t(this._value))}};function D(e,t){return new St(e,t)}function B(e,t,o){let n=null;return e(0,(r,i)=>{if(r===0){n=i;return}if(r===2){n=null,o?.onEnd?.(i);return}r===1&&t(i)}),{unsubscribe(){n?.(2),n=null}}}function _t(e){typeof e=="function"&&B(e,()=>{})}function $t(e,t,o){return n=>{let r=o?.name??`checkpoint:${e}`,i=D({recovered:!1,persistCount:0,id:e},{name:`${r}:meta`,equals:()=>!1}),s=ie(({emit:a,error:l,complete:c})=>{let d=0,h=!0,T=!1,k=[],E=null,w=B(n.source,p=>{if(!T){k.push(p);return}d++,i.set({recovered:i.get().recovered,persistCount:d,id:e}),_t(t.save(e,p)),a(p)},{onEnd:p=>{if(!T){E={err:p};return}p!==void 0?l(p):c()}});function b(p){if(h){T=!0,i.set({recovered:p,persistCount:d,id:e});for(let f of k){if(!h)break;d++,i.set({recovered:p,persistCount:d,id:e}),_t(t.save(e,f)),a(f)}k.length=0,E&&(E.err!==void 0?l(E.err):c())}}let m=t.load(e);return typeof m=="function"?B(m,p=>{!h||T||(p!==void 0?(a(p),b(!0)):b(!1))},{onEnd:p=>{h&&(p!==void 0||!T)&&b(!1)}}):m!==void 0?(a(m),b(!0)):b(!1),()=>{h=!1,k.length=0,w.unsubscribe()}},{name:r,kind:"checkpoint"});se.register(s,{kind:"checkpoint"});let u=s;return Object.defineProperties(u,{meta:{value:i,enumerable:!0},clear:{value(){_t(t.clear(e))},enumerable:!0}}),u}}function Pt(){let e=new Map;return{save(t,o){e.set(t,o)},load(t){return e.has(t)?e.get(t):void 0},clear(t){e.delete(t)}}}function Ce(e,t){let o=t?.predicate,n=t?.signal;return new Promise((r,i)=>{if(n?.aborted){i(n.reason??new DOMException("The operation was aborted.","AbortError"));return}let s=!1,u;u=B(e,c=>{(!o||o(c))&&(s=!0,l(),u?.unsubscribe(),r(c))},{onEnd:c=>{s||(s=!0,l(),i(c??new Error("source completed without matching value")))}});function a(){s||(s=!0,l(),u?.unsubscribe(),i(n.reason??new DOMException("The operation was aborted.","AbortError")))}function l(){n?.removeEventListener("abort",a)}n?.addEventListener("abort",a)})}function Le(e){return(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)}),e.then(r=>{n||(o(1,r),n||o(2))},r=>{n||o(2,r)})}}function it(e){return(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)}),e.onsuccess=()=>{n||(n=!0,o(1,e.result),o(2))},e.onerror=()=>{n||(n=!0,o(2,e.error))}}}function Nt(e){let t=e?.dbName??"callbag-checkpoints",o=e?.storeName??"checkpoints",n=null,r=null;function i(){if(n)return Promise.resolve(n);if(r)return r;let a=indexedDB.open(t,1);return a.onupgradeneeded=()=>{let l=a.result;l.objectStoreNames.contains(o)||l.createObjectStore(o)},r=Ce(it(a)).then(l=>(n=l,n.onversionchange=()=>{n?.close(),n=null,r=null},n)),r.catch(()=>{r=null}),r}function s(a){return i().then(l=>{let c=l.transaction(o,a);return{store:c.objectStore(o),tx:c}})}async function u(a,l){try{let{store:c}=await s(a);return await Ce(it(l(c)))}catch(c){if(c?.name==="InvalidStateError"||n===null){n=null,r=null;let{store:d}=await s(a);return Ce(it(l(d)))}throw c}}return{save(a,l){return Le(u("readwrite",c=>c.put(l,a)).then(()=>{}))},load(a){return Le(u("readonly",l=>l.get(a)).then(l=>l??void 0))},clear(a){return Le(u("readwrite",l=>l.delete(a)).then(()=>{}))}}}function Q(e,t,o){let n=null;we(),e.source(W,(i,s)=>{if(i===W&&(n=s),i===j){n=null,o?.onEnd?.(s);return}if(i===1){let u=s,a=r;r=u,t(u,a)}});let r;try{r=e.get()}catch{}return ke(),{unsubscribe(){n?.(j),n=null},signal(i){n?.(U,i)}}}var Ft=Object.freeze({promptTokens:0,completionTokens:0,totalTokens:0,cost:0,count:0});function qt(e,t){return o=>{let n=t?.name??"tokenTracker",r=u=>u==null||!Number.isFinite(u)?0:u,i=D({...Ft},{name:`${n}:tokens`,equals:()=>!1}),s=ie(({emit:u,error:a,complete:l})=>{let c=0,d=0,h=0,T=0,k=0;i.set({...Ft});let E=Q(o,w=>{try{let b=e(w),m=r(b.promptTokens),p=r(b.completionTokens),f=r(b.totalTokens)||m+p,y=r(b.cost);c+=m,d+=p,h+=f,T+=y,k++,i.set({promptTokens:c,completionTokens:d,totalTokens:h,cost:T,count:k})}catch{k++,i.set({promptTokens:c,completionTokens:d,totalTokens:h,cost:T,count:k})}u(w)},{onEnd:w=>{w!==void 0?a(w):l()}});return()=>{E.unsubscribe()}},{initial:o.get()});return se.register(s,{kind:"tokenTracker",name:n}),s.tokens=i,s}}function De(e){return(t,o)=>{if(t!==0)return;let n=new AbortController,r=n.signal,i=!1,s,u;try{s=typeof e=="function"?e():e,u=s[Symbol.asyncIterator]()}catch(l){o(0,()=>{}),o(2,l);return}o(0,l=>{l===2&&!i&&(i=!0,n.abort(),Promise.resolve(u.return?.()).catch(()=>{}))});async function a(){try{for(;!i&&!r.aborted;){let l=await u.next();if(i||r.aborted)break;if(l.done){i=!0,o(2);return}o(1,l.value)}}catch(l){!i&&!r.aborted&&(i=!0,o(2,l))}}a()}}function Nn(e){return e!=null&&typeof e.then=="function"}function Fn(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function qn(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function G(e){return Nn(e)?Le(e):Fn(e)?De(e):typeof e!="string"&&qn(e)?(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)});for(let r of e){if(n)return;o(1,r)}n||o(2)}:(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)}),n||o(1,e),n||o(2)}}var at=class extends Error{constructor(){super("Gate: action rejected")}};function Vt(e){let t=e.name??"agentLoop",o=e.maxIterations??10,n=e.shouldContinue??(()=>!1),r=!!e.gate,i=D("idle",{name:`${t}.phase`}),s=D(void 0,{name:`${t}.context`}),u=D(void 0,{name:`${t}.lastAction`}),a=D(0,{name:`${t}.iteration`}),l=D(void 0,{name:`${t}.error`}),c=D([],{name:`${t}.history`}),d=typeof e.gate=="object"?e.gate:{},h=d.maxPending??1/0,T=r?D([],{name:`${t}.pending`,equals:()=>!1}):void 0,k=r?D(d.startOpen??!1,{name:`${t}.isOpen`}):void 0,E=[],w=null,b=null,m=!1,p=!1,f=0,y=null;function _(A,M,F){c.update(H=>[...H,{phase:A,context:M,action:F,iteration:a.get()}])}function R(A,M,F){if(!r||!T||m){M(A);return}if(k.get()){M(A);return}E.push(A),E.length>h&&E.shift(),T.set([...E]);let H=ie(({emit:J,complete:I,error:q})=>{let z=Y=>{J(Y),I()},ee=Y=>{q(Y)};return w=z,b=ee,()=>{w===z&&(w=null),b===ee&&(b=null)}},{_skipInspect:!0});B(H.source,J=>{M(J)},{onEnd:J=>{J!==void 0&&F(J)}})}function L(A){let M=E.splice(0,A);return T?.set([...E]),M}function v(){p=!1;let A=y;y=null,A?.()}function g(A,M){m||(l.set(A),i.set("errored"),_("errored",M)),v()}function x(A,M,F){if(m||F!==f){v();return}if(M>=o){i.set("completed"),_("completed",A),v();return}let H=M+1;a.set(H),i.set("observe"),_("observe",A);let J;try{J=e.observe(A)}catch(I){g(I,A);return}B(G(J),I=>{if(s.set(I),m||F!==f){v();return}i.set("plan"),_("plan",I);let q;try{q=e.plan(I)}catch(z){g(z,I);return}B(G(q),z=>{if(u.set(z),m||F!==f){v();return}let ee=Y=>{if(u.set(Y),m||F!==f){v();return}i.set("act"),_("act",I,Y);let be;try{be=e.act(Y,I)}catch(ae){g(ae,I);return}B(G(be),ae=>{if(s.set(ae),m||F!==f){v();return}n(ae,H)?x(ae,H,F):(i.set("completed"),_("completed",ae),v())},{onEnd:ae=>{ae!==void 0&&g(ae,I)}})};r?(i.set("awaiting_approval"),_("awaiting_approval",I,z),R(z,Y=>{ee(Y)},Y=>{Y instanceof at&&!m?x(I,H,F):g(Y,I)})):ee(z)},{onEnd:z=>{z!==void 0&&g(z,I)}})},{onEnd:I=>{I!==void 0&&g(I,A)}})}function C(A,M){M===f&&(p=!0,m=!1,E=[],w=null,b=null,T?.set([]),s.set(A),a.set(0),l.set(void 0),u.set(void 0),x(A,0,M))}function O(A){f++;let M=f;c.set([]),p?(m=!0,y=()=>{M===f&&C(A,M)},w&&w(E[0]??void 0)):C(A,M)}function $(){m=!0,p&&i.set("completed"),w&&w(E[0]??void 0)}let V={phase:i,context:s,lastAction:u,iteration:a,error:l,start:O,stop:$,history:c};if(!r)return V;let S=V;return S.pending=T,S.isOpen=k,S.approve=(A=1)=>{let M=L(1);M.length>0&&w&&w(M[0])},S.reject=(A=1)=>{L(1),b&&b(new at)},S.modify=A=>{let M=L(1);M.length>0&&w&&w(A(M[0]))},S.open=()=>{k.set(!0);let A=L(E.length);A.length>0&&w&&w(A[0])},S.close=()=>{k.set(!1)},S}var Ie=class{_v;_w;constructor(t){this._v=0,this._w=t>32?new Uint32Array((t-1>>>5)+1):null}set(t){let o=this._w;if(o===null)this._v|=1<<t;else{let n=t>>>5,r=1<<(t&31);o[n]&r||(o[n]|=r,this._v++)}}clear(t){let o=this._w;if(o===null)this._v&=~(1<<t);else{let n=t>>>5,r=1<<(t&31);o[n]&r&&(o[n]&=~r,this._v--)}}test(t){let o=this._w;return o===null?(this._v&1<<t)!==0:(o[t>>>5]&1<<(t&31))!==0}empty(){return this._v===0}reset(){this._v=0,this._w?.fill(0)}};var xe=1,Oe=2,$e=4,ue=8,ye=32,Bt=64,Vn=Ye<<oe,Pe=Qe<<oe,vt=Xe<<oe,Be=Ze<<oe,Bn=et<<oe,ct=tt<<oe,te=Fe,ut=class{_output=null;_upstreamTalkbacks=[];_cachedValue;_flags;_dirtyDeps;_eqFn;_deps;_fn;get _status(){return nt(this._flags)}constructor(t,o,n,r){this._deps=t,this._fn=o,this._eqFn=n?.equals,this._flags=r?Bt:0,this._dirtyDeps=new Ie(t.length),this.source=this.source.bind(this),se.register(this,{kind:"derived",...n,deps:t});for(let i of t)se.registerEdge(i,this)}_dispatch(t,o){let n=this._output;if(n)if(this._flags&ye)for(let r of n)r(t,o);else n(t,o)}_recompute(){let t;try{t=this._fn()}catch(o){this._handleEnd(o);return}if(this._eqFn&&this._flags&xe&&this._eqFn(this._cachedValue,t)){this._flags=this._flags&~te|Be,this._dispatch(U,re);return}this._cachedValue=t,this._flags=(this._flags|xe)&~te|vt,this._dispatch(Z,this._cachedValue)}_recomputeIdentity(t){if(!(this._flags&ue)){if(this._eqFn&&this._flags&xe&&this._eqFn(this._cachedValue,t)){this._flags=this._flags&~te|Be,this._dispatch(U,re);return}this._cachedValue=t,this._flags=(this._flags|xe)&~te|vt,this._dispatch(Z,t)}}_lazyConnect(){if(!(this._flags&(Oe|ue))){try{this._cachedValue=this._fn()}catch(t){this._handleEnd(t);return}this._flags=(this._flags|xe)&~te|vt,we(),this._connectUpstream(),this._flags&ue||(this._flags|=Oe),ke()}}_connectUpstream(){this._upstreamTalkbacks.length=0,this._deps.length===1?this._flags&Bt?this._connectSingleDepIdentity():this._connectSingleDep():this._connectMultiDep()}_connectSingleDep(){let t=!1;this._deps[0].source(W,(o,n)=>{if(o===W){this._upstreamTalkbacks.push(n),n(U,Te);return}if(!(this._flags&ue))if(o===U)if(n===X){if(t)return;t=!0,this._flags=this._flags&~te|Pe,this._dispatch(U,X)}else n===re?t&&(t=!1,this._flags=this._flags&~te|Be,this._dispatch(U,re)):this._dispatch(U,n);else o===Z?t?(t=!1,this._recompute()):(this._flags=this._flags&~te|Pe,this._dispatch(U,X),this._recompute()):o===j&&this._handleEnd(n)})}_connectSingleDepIdentity(){let t=!1;this._deps[0].source(W,(o,n)=>{if(o===W){this._upstreamTalkbacks.push(n),n(U,Te);return}this._flags&ue||(o===U?n===X?(t=!0,this._flags=this._flags&~te|Pe,this._dispatch(U,X)):n===re?t&&(t=!1,this._flags=this._flags&~te|Be,this._dispatch(U,re)):this._dispatch(U,n):o===Z?t?(t=!1,this._recomputeIdentity(n)):(this._flags=this._flags&~te|Pe,this._dispatch(U,X),this._recomputeIdentity(n)):o===j&&this._handleEnd(n))})}_connectMultiDep(){for(let t=0;t<this._deps.length&&!(this._flags&ue);t++){let o=t;this._deps[o].source(W,(n,r)=>{if(n===W){this._upstreamTalkbacks.push(r);return}if(!(this._flags&ue))if(n===U)if(r===X){let i=this._dirtyDeps.empty();this._dirtyDeps.set(o),i&&(this._flags&=~$e,this._flags=this._flags&~te|Pe,this._dispatch(U,X))}else r===re?this._dirtyDeps.test(o)&&(this._dirtyDeps.clear(o),this._dirtyDeps.empty()&&(this._flags&$e?this._recompute():(this._flags=this._flags&~te|Be,this._dispatch(U,re)))):this._dispatch(U,r);else n===Z?this._dirtyDeps.test(o)?(this._dirtyDeps.clear(o),this._flags|=$e,this._dirtyDeps.empty()&&this._recompute()):this._dirtyDeps.empty()?(this._flags=this._flags&~te|Pe,this._dispatch(U,X),this._recompute()):this._flags|=$e:n===j&&this._handleEnd(r)})}}_handleEnd(t){this._flags|=ue,this._flags=this._flags&~te|(t!==void 0?ct:Bn),t!==void 0&&(this._cachedValue=t);for(let r of this._upstreamTalkbacks)r(j);this._upstreamTalkbacks=[],this._flags&=~Oe,this._dirtyDeps.reset();let o=this._output,n=this._flags&ye;if(this._output=null,this._flags&=~ye,o)if(n)for(let r of o)try{t!==void 0?r(j,t):r(j)}catch{}else t!==void 0?o(j,t):o(j)}_disconnectUpstream(){for(let t of this._upstreamTalkbacks)t(j);this._upstreamTalkbacks.length=0,this._flags&=~(Oe|$e),this._flags=this._flags&~te|Vn,this._dirtyDeps.reset()}_handleLifecycleSignal(t){if(!(this._flags&ue)){if(t===pe){for(let o of this._upstreamTalkbacks)o(U,pe);this._handleEnd(void 0);return}t===ge&&(this._flags&=~(xe|$e),this._dirtyDeps.reset());for(let o of this._upstreamTalkbacks)o(U,t)}}get(){if(this._flags&Oe)return this._cachedValue;if(this._flags&ue){if((this._flags&te)===ct)throw this._cachedValue;return this._cachedValue}let t=this._fn();return this._cachedValue=t,this._flags|=xe,t}source(t,o){if(t===W){let n=o;if(this._flags&ue){let r=(this._flags&te)===ct;n(W,i=>{}),r?n(j,this._cachedValue):n(j);return}if(!(this._flags&Oe)&&(this._lazyConnect(),this._flags&ue)){let r=(this._flags&te)===ct;n(W,i=>{}),r?n(j,this._cachedValue):n(j);return}if(this._output===null)this._output=n;else if(this._flags&ye)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags|=ye}n(W,(r,i)=>{if(r===Z&&n(Z,this._cachedValue),r===U&&Ee(i)){this._handleLifecycleSignal(i);return}if(r===j){if(this._output===null)return;if(this._flags&ye){let s=this._output;s.delete(n),s.size===1?(this._output=s.values().next().value,this._flags&=~ye):s.size===0&&(this._output=null,this._flags&=~ye,this._disconnectUpstream())}else this._output===n&&(this._output=null,this._disconnectUpstream())}})}}};function K(e,t,o){return new ut(e,t,o)}(t=>{function e(o,n){return new ut([o],()=>o.get(),n,!0)}t.from=e})(K||={});var zn=0;lt.from=function(t){let o=lt({id:t.id});for(let[n,r]of Object.entries(t.index))for(let i of r)o.add(i,[n]);return o};function lt(e){let t=++zn,o=e?.id??`ridx-${t}`,n=new Map,r=new Map,i=new Map,s=new Map,u=D(0,{name:`${o}:ver`}),a=K([u],()=>Array.from(n.keys()),{name:`${o}:keys`}),l=K([u],()=>n.size,{name:`${o}:size`}),c=!1,d=Object.freeze(new Set);function h(b){let m=i.get(b);return m||(m=D(n.get(b)??new Set,{name:`${o}:${b}`,equals:()=>!1}),i.set(b,m)),m}function T(b){let m=i.get(b);if(m){let p=n.get(b);m.set(p?new Set(p):new Set)}}function k(b,m){let p=n.get(m),f=!p;return p||(p=new Set,n.set(m,p)),p.add(b),f}function E(b,m){let p=n.get(m);return p?(p.delete(b),p.size===0?(n.delete(m),!0):!1):!1}return{get id(){return o},get version(){return u.get()},get(b){let m=n.get(b);return m?Object.freeze(new Set(m)):d},has(b){let m=n.get(b);return m!==void 0&&m.size>0},keys(){return Array.from(n.keys())},get size(){return n.size},select(b){let m=s.get(b);if(m)return m;let p=h(b);return m=K([p],()=>p.get(),{name:`${o}:${b}:select`}),s.set(b,m),m},keysStore:a,sizeStore:l,add(b,m){if(c||m.length===0)return;let p=r.get(b);p||(p=new Set,r.set(b,p)),P(()=>{let f=!1;for(let y of m)p.add(y),k(b,y)&&(f=!0),T(y);f&&u.update(y=>y+1)})},remove(b){if(c)return;let m=r.get(b);m&&P(()=>{let p=!1;for(let f of m)E(b,f)&&(p=!0),T(f);r.delete(b),p&&u.update(f=>f+1)})},update(b,m){if(c)return;let p=r.get(b),f=new Set(m);P(()=>{let y=!1;if(p)for(let R of p)f.has(R)||(E(b,R)&&(y=!0),T(R));let _=r.get(b);_||(_=new Set,r.set(b,_)),_.clear();for(let R of m)_.add(R),k(b,R)&&(y=!0),T(R);y&&u.update(R=>R+1)})},clear(){n.size!==0&&P(()=>{n.clear(),r.clear();for(let b of i.values())b.set(new Set);u.update(b=>b+1)})},snapshot(){let b={};for(let[m,p]of n)b[m]=Array.from(p);return{type:"reactiveIndex",id:o,version:u.get(),index:b}},destroy(){if(!c){c=!0,n.clear(),r.clear();for(let b of i.values())N(b);i.clear();for(let b of s.values())N(b);s.clear(),N(u)}}}}function zt(e,t=o=>o){let o=[],n=new Map,r=new Map;function i(l,c){let d=o[l],h=o[c];o[l]=h,o[c]=d,d.index=c,h.index=l}function s(l){for(;l>0;){let c=l-1>>>1;if(o[c].score<=o[l].score)break;i(l,c),l=c}}function u(l){let c=o.length;for(;;){let d=l,h=2*l+1,T=h+1;if(h<c&&o[h].score<o[d].score&&(d=h),T<c&&o[T].score<o[d].score&&(d=T),d===l)break;i(l,d),l=d}}function a(l){let c=o.length-1;if(l===c){o.pop();return}i(l,c),o.pop(),s(l),u(l)}return{touch(){},insert(l){if(n.has(l))return;let c=e(l),d={key:l,score:t(c.get()),index:o.length};o.push(d),n.set(l,d),s(d.index);let h=Q(c,T=>{let k=n.get(l);if(!k)return;let E=k.score;k.score=t(T),k.score<E?s(k.index):k.score>E&&u(k.index)});r.set(l,()=>h.unsubscribe())},delete(l){let c=n.get(l);if(!c)return;let d=r.get(l);d&&(d(),r.delete(l)),a(c.index),n.delete(l)},evict(l=1){let c=[];for(;c.length<l&&o.length>0;){let{key:d}=o[0];c.push(d);let h=r.get(d);h&&(h(),r.delete(d)),a(0),n.delete(d)}return c},size:()=>n.size,clear(){for(let l of r.values())l();r.clear(),n.clear(),o.length=0}}}function Ne(e,t,o){let n=t?.halfLife??864e5,r=t?.recency??1,i=t?.importance??1,s=t?.frequency??.5,u=(o??Date.now())-e.accessedAt,a=Math.exp(-Math.LN2/n*u),l=1-1/(1+e.accessCount);return r*a+i*e.importance+s*l}var jn=0;function Un(){return`mem-${++jn}`}function xt(e,t){let o=t?.id??Un(),n=Date.now(),r={id:o,createdAt:t?.createdAt??n,updatedAt:t?.updatedAt??n,accessedAt:t?.accessedAt??n,accessCount:0,importance:t?.importance??.5,tags:new Set(t?.tags)},i=D(e,{name:`mem:${o}:content`}),s=D(r,{name:`mem:${o}:meta`,equals:()=>!1}),u={},a=K([s],()=>Ne(s.get(),u),{name:`mem:${o}:score`});return{id:o,content:i,meta:s,scoreStore:a,touch(){let c=Date.now();s.update(d=>({...d,accessedAt:c,accessCount:d.accessCount+1}))},tag(...c){s.update(d=>{let h=new Set(d.tags);for(let T of c)h.add(T);return{...d,tags:h,updatedAt:Date.now()}})},untag(...c){s.update(d=>{let h=new Set(d.tags);for(let T of c)h.delete(T);return{...d,tags:h,updatedAt:Date.now()}})},setImportance(c){s.update(d=>({...d,importance:Math.max(0,Math.min(1,c)),updatedAt:Date.now()}))},update(c){P(()=>{i.set(c),s.update(d=>({...d,updatedAt:Date.now()}))})},score(c){return Ne(s.get(),c??u)},destroy(){N(i),N(s)}}}var Hn=0;function Ae(e){let t=++Hn,o=e?.maxSize??1/0,n=e?.weights??{},r=e?.admissionPolicy,i=e?.forgetPolicy,s=new Map,u=lt(),a=new Map,l=o<1/0?zt(f=>s.get(f).meta,f=>Ne(f,n)):null,c=D(0,{name:`collection-${t}:ver`}),d=K([c],()=>Array.from(s.values()),{name:`collection-${t}:nodes`}),h=K([c],()=>s.size,{name:`collection-${t}:size`}),T=!1;function k(){c.update(f=>f+1)}function E(f){let y=Array.from(f.meta.get().tags);u.update(f.id,y);let _=Q(f.meta,R=>{let L=Array.from(R.tags);u.update(f.id,L)});a.set(f.id,()=>_.unsubscribe())}function w(f){let y=a.get(f);y&&(y(),a.delete(f)),u.remove(f)}function b(){if(!l||s.size<=o)return;let f=l.evict(s.size-o);for(let y of f){let _=s.get(y);_&&(w(y),_.destroy(),s.delete(y))}}function m(){if(!i)return 0;let f=[];for(let y of s.values())i(y)&&f.push(y.id);for(let y of f){let _=s.get(y);_&&(w(y),l?.delete(y),_.destroy(),s.delete(y))}return f.length}return{add(f,y){if(T)throw new Error("Collection is destroyed");if(r){let R=Array.from(s.values()),L=r(f,R);switch(L.action){case"reject":return;case"update":{let v=s.get(L.targetId);if(!v)throw new Error(`Admission update target "${L.targetId}" not found`);return v.update(L.content),v}case"merge":{let v=s.get(L.targetId);if(!v)throw new Error(`Admission merge target "${L.targetId}" not found`);let g=L.reducer(v.content.get(),f);return v.update(g),v}default:break}}i&&m();let _=xt(f,y);return s.set(_.id,_),E(_),l?.insert(_.id),b(),k(),_},remove(f){let y=typeof f=="string"?f:f.id,_=s.get(y);return _?(w(y),l?.delete(y),_.destroy(),s.delete(y),k(),!0):!1},get(f){return s.get(f)},has(f){return s.has(f)},nodes:d,size:h,tagIndex:u,query(f){let y=[];for(let _ of s.values())f(_)&&y.push(_);return y},byTag(f){let y=u.get(f),_=[];for(let R of y){let L=s.get(R);L&&_.push(L)}return _},topK(f,y){let _=y??n,R=Date.now(),L=Array.from(s.values()).map(v=>({node:v,score:Ne(v.meta.get(),_,R)}));return L.sort((v,g)=>g.score-v.score),L.slice(0,f).map(v=>v.node)},summarize(f,y,_){if(T)throw new Error("Collection is destroyed");let R=Array.from(new Set(f)),L=[];for(let x of R){let C=s.get(x);C&&L.push(C)}if(L.length===0)throw new Error("No valid nodes to summarize");let v=y(L),g;return P(()=>{for(let x of L)w(x.id),l?.delete(x.id),x.destroy(),s.delete(x.id);i&&m(),g=xt(v,_),s.set(g.id,g),E(g),l?.insert(g.id),b(),k()}),g},gc(){if(T)throw new Error("Collection is destroyed");let f=m();return f>0&&k(),f},destroy(){if(!T){T=!0,l?.clear();for(let f of a.values())f();a.clear(),u.destroy(),P(()=>{for(let f of s.values())f.destroy();s.clear()}),N(c)}}}}function Jn(e,t){let o=0,n=0,r=0;for(let s=0;s<e.length;s++)o+=e[s]*t[s],n+=e[s]*e[s],r+=t[s]*t[s];let i=Math.sqrt(n)*Math.sqrt(r);return i===0?1:1-o/i}function Wn(e,t){let o=0;for(let n=0;n<e.length;n++){let r=e[n]-t[n];o+=r*r}return Math.sqrt(o)}function Gn(e,t){let o=0;for(let n=0;n<e.length;n++)o+=e[n]*t[n];return-o}var Kn={cosine:Jn,euclidean:Wn,dotProduct:Gn};function At(e,t){e.push(t);let o=e.length-1;for(;o>0;){let n=o-1>>1;if(e[n].dist<=e[o].dist)break;let r=e[n];e[n]=e[o],e[o]=r,o=n}}function Yn(e){let t=e[0],o=e.pop();if(e.length>0){e[0]=o;let n=0;for(;;){let r=n,i=2*n+1,s=2*n+2;if(i<e.length&&e[i].dist<e[r].dist&&(r=i),s<e.length&&e[s].dist<e[r].dist&&(r=s),r===n)break;let u=e[r];e[r]=e[n],e[n]=u,n=r}}return t}function jt(e,t){if(e.length!==t)throw new Error(`Expected ${t} dimensions, got ${e.length}`);return new Float32Array(e)}function Qn(e){for(let t=0;t<e.length;t++)if(!Number.isFinite(e[t]))throw new Error("Vector contains non-finite values")}function dt(e){let t=e.dimensions;if(!t||t<=0)throw new Error("dimensions must be a positive integer");let o=e.m??16,n=o*2,r=e.efConstruction??200,i=e.efSearch??50,s=Kn[e.distance??"cosine"];if(!s)throw new Error(`Unknown distance metric: ${e.distance}`);let u=1/Math.log(o),a=[],l=new Map,c=-1,d=-1,h=0,T=D(0);function k(){let g=Math.random();return g===0&&(g=Number.EPSILON),Math.floor(-Math.log(g)*u)}function E(g,x,C,O){let $=new Set;$.add(x);let V=s(g,a[x].vector),S=[];At(S,{idx:x,dist:V});let A=[{idx:x,dist:V}];for(;S.length>0;){let M=Yn(S);if(A.length>=C){let J=-1/0;for(let I=0;I<A.length;I++)A[I].dist>J&&(J=A[I].dist);if(M.dist>J)break}let H=a[M.idx].neighbors[O];if(H)for(let J of H){if($.has(J))continue;$.add(J);let I=a[J];if(I.deleted)continue;let q=s(g,I.vector);if(A.length<C)At(S,{idx:J,dist:q}),A.push({idx:J,dist:q});else{let z=0,ee=A[0].dist;for(let Y=1;Y<A.length;Y++)A[Y].dist>ee&&(ee=A[Y].dist,z=Y);q<ee&&(At(S,{idx:J,dist:q}),A[z]={idx:J,dist:q})}}}return A}function w(g,x,C){let O=x,$=s(g,a[O].vector),V=!0;for(;V;){V=!1;let S=a[O].neighbors[C];if(!S)break;for(let A of S){let M=a[A];if(M.deleted)continue;let F=s(g,M.vector);F<$&&(O=A,$=F,V=!0)}}return O}function b(g,x){g.sort((O,$)=>O.dist-$.dist);let C=[];for(let O=0;O<Math.min(g.length,x);O++)C.push(g[O].idx);return C}function m(g,x,C){let O=C===0?n:o;a[g].neighbors[C].add(x),a[x].neighbors[C].add(g),a[g].neighbors[C].size>O&&p(g,C,O),a[x].neighbors[C].size>O&&p(x,C,O)}function p(g,x,C){let O=a[g],$=[];for(let S of O.neighbors[x])a[S].deleted||$.push({idx:S,dist:s(O.vector,a[S].vector)});let V=b($,C);O.neighbors[x]=new Set(V)}function f(g,x){let C=jt(x,t);if(Qn(C),l.has(g)){let M=l.get(g),F=a[M];if(F.deleted){if(F.deleted=!1,F.vector=C,h++,c===-1)c=M,d=F.layer;else{for(let H=F.layer;H>=0;H--)F.neighbors[H]=new Set,y(M,H);F.layer>d&&(c=M,d=F.layer)}T.set(h)}else{F.vector=C;for(let H=F.layer;H>=0;H--){for(let J of F.neighbors[H])a[J].neighbors[H].delete(M);F.neighbors[H]=new Set,y(M,H)}}return}let O=k(),$=a.length,V=[];for(let M=0;M<=O;M++)V.push(new Set);let S={id:g,vector:C,layer:O,neighbors:V,deleted:!1};if(a.push(S),l.set(g,$),h++,c===-1){c=$,d=O,T.set(h);return}let A=c;for(let M=d;M>O;M--)A=w(C,A,M);for(let M=Math.min(O,d);M>=0;M--){let F=E(C,A,r,M),J=b(F,M===0?n:o);for(let I of J)I!==$&&m($,I,M);F.length>0&&(F.sort((I,q)=>I.dist-q.dist),A=F[0].idx)}O>d&&(c=$,d=O),T.set(h)}function y(g,x){let C=c;if(C===g){let S=-1;for(let A=0;A<a.length;A++)if(A!==g&&!a[A].deleted&&a[A].layer>=x){S=A;break}if(S===-1)return;C=S}for(let S=Math.min(d,a[C].layer);S>x;S--)C=w(a[g].vector,C,S);let O=E(a[g].vector,C,r,x),V=b(O,x===0?n:o);for(let S of V)S!==g&&m(g,S,x)}function _(g){let x=l.get(g);if(x===void 0)return!1;let C=a[x];if(C.deleted)return!1;if(C.deleted=!0,h--,T.set(h),x===c){let O=-1;for(let $=0;$<a.length;$++)a[$].deleted||(O===-1||a[$].layer>a[O].layer)&&(O=$);c=O,d=O===-1?-1:a[O].layer}return!0}function R(g,x=10){if(h===0)return[];let C=jt(g,t),O=Math.min(x,h),$=Math.max(i,O),V=c;for(let M=d;M>0;M--)V=w(C,V,M);let S=E(C,V,$,0);S.sort((M,F)=>M.dist-F.dist);let A=[];for(let M=0;M<S.length&&A.length<O;M++){let F=a[S[M].idx];F.deleted||A.push({id:F.id,distance:S[M].dist})}return A}function L(g){let x=l.get(g);return x===void 0?!1:!a[x].deleted}function v(){a.length=0,l.clear(),c=-1,d=-1,h=0,T.set(0),N(T)}return{add:f,remove:_,search:R,has:L,size:T,destroy:v}}function Ut(e,t,o){if(e.size.get()===0)return{isDuplicate:!1,similarity:0};let n=e.search(t,1);if(n.length===0)return{isDuplicate:!1,similarity:0};let r=n[0],i=1-r.distance;return i>=o?{isDuplicate:!0,existingId:r.id,similarity:i}:{isDuplicate:!1,similarity:i}}var Xn=`You are a memory extraction system. Given a conversation, extract discrete factual statements worth remembering for future conversations.
|
|
1
|
+
"use strict";var Rn=Object.create;var He=Object.defineProperty;var Mn=Object.getOwnPropertyDescriptor;var Cn=Object.getOwnPropertyNames;var Ln=Object.getPrototypeOf,Dn=Object.prototype.hasOwnProperty;var In=(e,t)=>{for(var o in t)He(e,o,{get:t[o],enumerable:!0})},It=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Cn(t))!Dn.call(e,r)&&r!==o&&He(e,r,{get:()=>t[r],enumerable:!(n=Mn(t,r))||n.enumerable});return e};var Ot=(e,t,o)=>(o=e!=null?Rn(Ln(e)):{},It(t||!e||!e.__esModule?He(o,"default",{value:e,enumerable:!0}):o,e)),On=e=>It(He({},"__esModule",{value:!0}),e);var Sr={};In(Sr,{agentLoop:()=>jt,agentMemory:()=>Zt,chatStream:()=>ft,checkpoint:()=>Ft,conversationSummary:()=>en,conversationThread:()=>tn,docIndex:()=>nn,embeddingIndex:()=>rn,fromLLM:()=>un,hybridRoute:()=>ln,indexedDBAdapter:()=>Bt,memoryAdapter:()=>qt,memoryStore:()=>dn,ragPipeline:()=>mn,systemPromptBuilder:()=>gn,toToolCallRequests:()=>cn,tokenTracker:()=>zt,toolCallState:()=>hn,toolRegistry:()=>En});module.exports=On(Sr);var Z=Symbol("DIRTY"),re=Symbol("RESOLVED"),Te=Symbol("SINGLE_DEP"),he=Symbol("RESET"),Se=Symbol("PAUSE"),_e=Symbol("RESUME"),ge=Symbol("TEARDOWN");function Ee(e){return e===he||e===Se||e===_e||e===ge}var Ye=0,Qe=1,Xe=2,Ze=3,et=4,tt=5,oe=7,Fe=7<<oe,$n=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function nt(e){return $n[(e&Fe)>>>oe]}var K=0,ee=1,U=2,H=3,Je=0,We=[],Tt=!1;function $(e){Je++;try{return e()}finally{if(Je--,Je===0&&!Tt){Tt=!0;for(let t=0;t<We.length;t++)We[t]();We.length=0,Tt=!1}}}function ve(){return Je>0}function rt(e){We.push(e)}var Ke=0,Ge=[];function we(){Ke++}function ke(){if(Ke--,Ke===0){for(let e=0;e<Ge.length;e++)Ge[e]();Ge.length=0}}function $t(e){Ke>0?Ge.push(e):e()}function N(e){let t=e;typeof t.complete=="function"?t.complete():typeof t._handleEnd=="function"&&t._handleEnd(void 0)}var se=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let n=t.map(r=>e._names.get(r)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let o=e._keys.get(t)??e._names.get(t);if(o)return o;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,o){if(!e.enabled)return;o?.name&&e._names.set(t,o.name),o?.kind&&e._kinds.set(t,o.kind);let n=e._nextId++,r=o?.name;if(!(r&&!e._usedKeys.has(r)))if(r){let i=e._depSuffix(o?.deps);r=i?`${r}(${i})`:`${r}_${n}`,e._usedKeys.has(r)&&(r=`${r}_${n}`)}else{let i=o?.kind??"store",s=e._depSuffix(o?.deps);r=s?`${i}(${s})`:`${i}_${n}`,e._usedKeys.has(r)&&(r=`${r}_${n}`)}e._usedKeys.add(r),e._keys.set(t,r),e._stores.add(new WeakRef(t))}static registerEdge(t,o){if(!e.enabled)return;let n=e._resolveKey(t),r=e._resolveKey(o),i=e._edges.get(n);i?i.includes(r)||i.push(r):e._edges.set(n,[r])}static getEdges(){return new Map(e._edges)}static getName(t){if(e.enabled)return e._names.get(t)}static getKind(t){return e._kinds.get(t)}static inspect(t){return{name:e._names.get(t),kind:e._kinds.get(t)??"unknown",value:typeof t.get=="function"?t.get():void 0,status:t._status}}static graph(){let t=new Map,o=new Set;for(let n of e._stores){let r=n.deref();if(!r){e._stores.delete(n);continue}let i=e._resolveKey(r);o.add(i),t.set(i,e.inspect(r))}for(let[n,r]of e._edges){if(!o.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let i=r.filter(s=>o.has(s));i.length===0?e._edges.delete(n):i.length!==r.length&&e._edges.set(n,i)}return t}static trace(t,o){let n=null,r=t.get();return t.source(K,(i,s)=>{if(i===K&&(n=s),i===U){n=null;return}if(i===1){let u=s;if(!Object.is(u,r)){let a=r;r=u,o(u,a)}}}),()=>n?.(U)}static dumpGraph(){let t=e.graph(),o=e.getEdges(),n=new Map;for(let[s,u]of o)for(let a of u){let l=n.get(a);l?l.includes(s)||l.push(s):n.set(a,[s])}let r=[];for(let[s,u]of t){let a=n.get(s),l=o.get(s),c=a?.length?` \u2190 [${a.join(", ")}]`:"",d=l?.length?` \u2192 [${l.join(", ")}]`:"";r.push(` ${s} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${c}${d}`)}return[`Store Graph (${t.size} nodes):`,...r].join(`
|
|
2
|
+
`)}static _signalLabel(t){return t===Z?"DIRTY":t===re?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,o,n){let r=null,i=!1,s=o??e.getName(t),u=[],a={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return a.ended&&!i},get errored(){return a.ended&&i},dirtyCount:0,resolvedCount:0,name:s,get eventLog(){return u},dispose:()=>r?.(U),reconnect:()=>(r?.(U),e._observe(t,o,n))};return t.source(K,(l,c)=>{if(l===K){r=c;return}let d=ve();l===ee?(a.values.push(c),a.events.push({type:"data",data:c,inBatch:d}),u.push(c),n&&n(`[${s}] DATA:`,c)):l===H?(a.signals.push(c),a.events.push({type:"signal",data:c,inBatch:d}),u.push(e._signalLabel(c)),c===Z?a.dirtyCount++:c===re&&a.resolvedCount++,n&&n(`[${s}] STATE:`,c)):l===U&&(a.ended=!0,a.endError=c,i=c!==void 0,a.events.push({type:"end",data:c,inBatch:d}),u.push(i?["END",c]:"END"),n&&n(`[${s}] END`,c!==void 0?c:""),r=null)}),a}static observe(t){return e._observe(t)}static activate(t){let o=null;return t.source(K,(n,r)=>{n===K&&(o=r),n===U&&(o=null)}),()=>o?.(U)}static tap(t,o){let n=o??`tap(${e.getName(t)??"anon"})`,r={get:()=>t.get(),source:t.source};return e.register(r,{name:n,kind:"tap"}),e.registerEdge(t,r),r}static spy(t,o){let n=o?.name??e.getName(t)??"spy",r=o?.log??console.log;return e._observe(t,n,r)}static snapshot(){let t=e.graph(),o=e.getEdges(),n=new Map;for(let s of e._stores){let u=s.deref();if(!u)continue;let a=e._annotations.get(u);a!==void 0&&n.set(e._resolveKey(u),a)}let r=[];for(let[s,u]of t){let a={name:s,kind:u.kind,value:u.value,status:u.status},l=n.get(s);l!==void 0&&(a.annotation=l),r.push(a)}let i=[];for(let[s,u]of o)for(let a of u)i.push({from:s,to:a});return{nodes:r,edges:i,trace:e.traceLog()}}static toMermaid(t){let o=t?.direction??"TD",n=e.snapshot(),r=[`graph ${o}`],i={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},s=new Map;function u(c){let d=c.replace(/[^a-zA-Z0-9_]/g,"_"),y=s.get(d);return y===void 0?(s.set(d,1),d):(s.set(d,y+1),`${d}__${y}`)}let a=new Map;function l(c){let d=JSON.stringify(c);return d&&d.length>30?`${d.slice(0,27)}...`:d??"undefined"}for(let c of n.nodes){let d=u(c.name);a.set(c.name,d);let y=`${c.name} (${c.kind}) = ${l(c.value)}`,b=i[c.status??""]??"";r.push(` ${d}["${y}"]${b}`)}for(let c of n.edges){let d=a.get(c.from)??u(c.from),y=a.get(c.to)??u(c.to);r.push(` ${d} --> ${y}`)}return r.push(""),r.push(" classDef settled fill:#d4edda,stroke:#28a745"),r.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),r.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),r.push(" classDef completed fill:#cce5ff,stroke:#007bff"),r.join(`
|
|
3
|
+
`)}static toD2(t){let o=t?.direction??"down",n=e.snapshot(),r=[`direction: ${o}`,""],i={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},s=new Map;function u(c){let d=c.replace(/[^a-zA-Z0-9_]/g,"_"),y=s.get(d);return y===void 0?(s.set(d,1),d):(s.set(d,y+1),`${d}__${y}`)}let a=new Map;function l(c){let d=JSON.stringify(c);return d&&d.length>30?`${d.slice(0,27)}...`:d??"undefined"}for(let c of n.nodes){let d=u(c.name);a.set(c.name,d);let y=i[c.kind]??"rectangle",b=`${c.name} (${c.kind}) = ${l(c.value)}`,C=c.status?` [${c.status}]`:"";r.push(`${d}: "${b}${C}" { shape: ${y} }`)}n.edges.length>0&&r.push("");for(let c of n.edges){let d=a.get(c.from)??u(c.from),y=a.get(c.to)??u(c.to);r.push(`${d} -> ${y}`)}return r.join(`
|
|
4
|
+
`)}static annotate(t,o){if(!e.enabled)return;e._annotations.set(t,o);let n={node:e._resolveKey(t),reason:o,timestamp:Date.now()},r=e.maxTraceEntries;r<=0||(e._traceLog.length<r?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%r)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static timeline(t){let o=null,n=[];return t.source(K,(r,i)=>{if(r===K){o=i;return}let s={timestamp:Date.now(),type:r===ee?"data":r===H?"signal":"end",data:i,inBatch:ve()};n.push(s),r===U&&(o=null)}),{entries:n,dispose:()=>o?.(U)}}static observeDerived(t){let o=[],n=t,r=n._fn;if(typeof r!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:o};n._fn=()=>{let a=n._deps.map(c=>c.get()),l=r();return o.push({result:l,depValues:a,timestamp:Date.now()}),l};let i=e._observe(t),s=i.dispose;return{...i,evaluations:o,dispose:()=>{n._fn=r,s()},reconnect:()=>(n._fn=r,s(),e.observeDerived(t))}}static observeTaskState(t){let o=t.status.get(),n=[],r=null;return t.status.source(K,(i,s)=>{if(i===K){r=s;return}if(i===ee){let u=s;if(u!==o){let a={from:o,to:u,timestamp:Date.now()};u==="error"&&(a.error=t.error.get()),n.push(a),o=u}}i===U&&(r=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{r?.(U)}}}static causalityTrace(t){let o=[],n=t,r=n._fn;if(typeof r!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:o};let i=n._deps,s=i.map(c=>c.get());n._fn=()=>{let c=i.map(b=>b.get()),d=r(),y=-1;for(let b=0;b<i.length;b++)if(!Object.is(c[b],s[b])){y=b;break}return o.push({result:d,triggerDepIndex:y,triggerDepName:y>=0?e.getName(i[y]):void 0,depValues:c,timestamp:Date.now()}),s=c,d};let u=e._observe(t),a=u.dispose;return{...u,causality:o,dispose:()=>{n._fn=r,a()},reconnect:()=>(n._fn=r,a(),e.causalityTrace(t))}}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var ot=1,de=64,ce=2,Re=4,Pt=8,Nt=16,ye=32,me=1024,ne=Fe,Me=Qe<<oe,qe=Xe<<oe,st=Ye<<oe,Pn=et<<oe,Nn=tt<<oe,Fn=Ze<<oe,Be=class{_value;_output=null;_flags;get _status(){return nt(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,o){this._value=o?.initial,this._fn=t,this._eqFn=o?.equals,this._getterFn=o?.getter,this._initial=o?.initial;let n=0;o?.autoDirty!==!1&&(n|=Re),o?.resetOnTeardown&&(n|=Pt),o?.resubscribable&&(n|=Nt),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),o?._skipInspect||se.register(this,{kind:"producer",...o})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,o){let n=this._output;if(n)if(this._flags&de)for(let r of n)r(t,o);else n(t,o)}emit(t){this._flags&ce||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(ve()?this._flags&ye||(this._flags|=ye,this._flags&Re&&(this._flags=this._flags&~ne|Me,this._dispatch(H,Z)),rt(()=>{this._flags&=~ye,this._flags=this._flags&~ne|qe,this._dispatch(ee,this._value)})):(this._flags&Re&&!(this._flags&me)&&(this._flags=this._flags&~ne|Me,this._dispatch(H,Z)),this._flags=this._flags&~ne|qe,this._dispatch(ee,this._value))))}signal(t){this._flags&ce||!this._output||(t===Z?this._flags=this._flags&~ne|Me:t===re&&(this._flags=this._flags&~ne|Fn),this._dispatch(H,t))}complete(){if(this._flags&ce)return;this._flags=(this._flags|ce)&~ne|Pn;let t=this._output,o=this._flags&de;if(this._output=null,this._flags&=~(de|me),this._singleDepCount=0,this._stop(),t)if(o)for(let n of t)n(U);else t(U)}error(t){if(this._flags&ce)return;this._flags=(this._flags|ce)&~ne|Nn;let o=this._output,n=this._flags&de;if(this._output=null,this._flags&=~(de|me),this._singleDepCount=0,this._stop(),o)if(n)for(let r of o)r(U,t);else o(U,t)}_start(){if(this._flags&ot||!this._fn)return;this._flags|=ot,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:o=>this.signal(o),complete:()=>this.complete(),error:o=>this.error(o),onSignal:o=>{this._onLifecycleSignal=o}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ot&&(this._flags&=~ot,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Pt&&(this._value=this._initial),this._flags&ce||(this._flags=this._flags&~ne|st))}_handleLifecycleSignal(t){if(!(this._flags&ce)){if(t===ge){this._onLifecycleSignal?.(t),this.complete();return}t===he&&(this._value=this._initial,this._flags&=~ye),this._onLifecycleSignal?.(t),t===he&&this.emit(this._initial)}}source(t,o){if(t===K){let n=o;if(this._flags&ce)if(this._flags&Nt&&this._output===null)this._flags=this._flags&~(ce|ne)|st;else{n(K,i=>{}),n(U);return}if(this._output===null)this._output=n;else if(this._flags&de)this._output.add(n);else{let i=new Set;i.add(this._output),i.add(n),this._output=i,this._flags=(this._flags|de)&~me}let r=!1;n(K,(i,s)=>{if(i===ee&&n(ee,this._value),i===H){s===Te&&!r?(r=!0,this._singleDepCount++,this._flags&de||(this._flags|=me)):Ee(s)&&this._handleLifecycleSignal(s);return}if(i===U){if(r&&(r=!1,this._singleDepCount--),this._output===null)return;if(this._flags&de){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~de,this._singleDepCount>0&&(this._flags|=me)):u.size===0&&(this._output=null,this._flags&=~(de|me),this._singleDepCount=0,this._flags=this._flags&~ne|st,this._stop())}else this._output===n&&(this._output=null,this._flags&=~me,this._singleDepCount=0,this._flags=this._flags&~ne|st,this._stop())}}),$t(()=>this._start())}}};function ae(e,t){return new Be(e,t)}var St=class extends Be{constructor(t,o){super(void 0,{initial:t,autoDirty:!0,equals:o?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),se.register(this,{kind:"state",...o})}get(){return this._value}set(t){this._flags&ce||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(ve()?this._flags&ye||(this._flags|=ye,this._flags&Re&&(this._flags=this._flags&~ne|Me,this._dispatch(H,Z)),rt(()=>{this._flags&=~ye,this._flags=this._flags&~ne|qe,this._dispatch(ee,this._value)})):(this._flags&Re&&!(this._flags&me)&&(this._flags=this._flags&~ne|Me,this._dispatch(H,Z)),this._flags=this._flags&~ne|qe,this._dispatch(ee,this._value))))}update(t){this.set(t(this._value))}};function I(e,t){return new St(e,t)}function V(e,t,o){let n=null;return e(0,(r,i)=>{if(r===0){n=i;return}if(r===2){n=null,o?.onEnd?.(i);return}r===1&&t(i)}),{unsubscribe(){n?.(2),n=null}}}function _t(e){typeof e=="function"&&V(e,()=>{})}function Ft(e,t,o){return n=>{let r=o?.name??`checkpoint:${e}`,i=I({recovered:!1,persistCount:0,id:e},{name:`${r}:meta`,equals:()=>!1}),s=ae(({emit:a,error:l,complete:c})=>{let d=0,y=!0,b=!1,C=[],E=null,k=V(n.source,p=>{if(!b){C.push(p);return}d++,i.set({recovered:i.get().recovered,persistCount:d,id:e}),_t(t.save(e,p)),a(p)},{onEnd:p=>{if(!b){E={err:p};return}p!==void 0?l(p):c()}});function h(p){if(y){b=!0,i.set({recovered:p,persistCount:d,id:e});for(let f of C){if(!y)break;d++,i.set({recovered:p,persistCount:d,id:e}),_t(t.save(e,f)),a(f)}C.length=0,E&&(E.err!==void 0?l(E.err):c())}}let m=t.load(e);return typeof m=="function"?V(m,p=>{!y||b||(p!==void 0?(a(p),h(!0)):h(!1))},{onEnd:p=>{y&&(p!==void 0||!b)&&h(!1)}}):m!==void 0?(a(m),h(!0)):h(!1),()=>{y=!1,C.length=0,k.unsubscribe()}},{name:r,kind:"checkpoint"});se.register(s,{kind:"checkpoint"});let u=s;return Object.defineProperties(u,{meta:{value:i,enumerable:!0},clear:{value(){_t(t.clear(e))},enumerable:!0}}),u}}function qt(){let e=new Map;return{save(t,o){e.set(t,o)},load(t){return e.has(t)?e.get(t):void 0},clear(t){e.delete(t)}}}function Ce(e,t){let o=t?.predicate,n=t?.signal;return new Promise((r,i)=>{if(n?.aborted){i(n.reason??new DOMException("The operation was aborted.","AbortError"));return}let s=!1,u;u=V(e,c=>{(!o||o(c))&&(s=!0,l(),u?.unsubscribe(),r(c))},{onEnd:c=>{s||(s=!0,l(),i(c??new Error("source completed without matching value")))}});function a(){s||(s=!0,l(),u?.unsubscribe(),i(n.reason??new DOMException("The operation was aborted.","AbortError")))}function l(){n?.removeEventListener("abort",a)}n?.addEventListener("abort",a)})}function Le(e){return(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)}),e.then(r=>{n||(o(1,r),n||o(2))},r=>{n||o(2,r)})}}function it(e){return(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)}),e.onsuccess=()=>{n||(n=!0,o(1,e.result),o(2))},e.onerror=()=>{n||(n=!0,o(2,e.error))}}}function Bt(e){let t=e?.dbName??"callbag-checkpoints",o=e?.storeName??"checkpoints",n=null,r=null;function i(){if(n)return Promise.resolve(n);if(r)return r;let a=indexedDB.open(t,1);return a.onupgradeneeded=()=>{let l=a.result;l.objectStoreNames.contains(o)||l.createObjectStore(o)},r=Ce(it(a)).then(l=>(n=l,n.onversionchange=()=>{n?.close(),n=null,r=null},n)),r.catch(()=>{r=null}),r}function s(a){return i().then(l=>{let c=l.transaction(o,a);return{store:c.objectStore(o),tx:c}})}async function u(a,l){try{let{store:c}=await s(a);return await Ce(it(l(c)))}catch(c){if(c?.name==="InvalidStateError"||n===null){n=null,r=null;let{store:d}=await s(a);return Ce(it(l(d)))}throw c}}return{save(a,l){return Le(u("readwrite",c=>c.put(l,a)).then(()=>{}))},load(a){return Le(u("readonly",l=>l.get(a)).then(l=>l??void 0))},clear(a){return Le(u("readwrite",l=>l.delete(a)).then(()=>{}))}}}function X(e,t,o){let n=null;we(),e.source(K,(i,s)=>{if(i===K&&(n=s),i===U){n=null,o?.onEnd?.(s);return}if(i===1){let u=s,a=r;r=u,t(u,a)}});let r;try{r=e.get()}catch{}return ke(),{unsubscribe(){n?.(U),n=null},signal(i){n?.(H,i)}}}var Vt=Object.freeze({promptTokens:0,completionTokens:0,totalTokens:0,cost:0,count:0});function zt(e,t){return o=>{let n=t?.name??"tokenTracker",r=u=>u==null||!Number.isFinite(u)?0:u,i=I({...Vt},{name:`${n}:tokens`,equals:()=>!1}),s=ae(({emit:u,error:a,complete:l})=>{let c=0,d=0,y=0,b=0,C=0;i.set({...Vt});let E=X(o,k=>{try{let h=e(k),m=r(h.promptTokens),p=r(h.completionTokens),f=r(h.totalTokens)||m+p,g=r(h.cost);c+=m,d+=p,y+=f,b+=g,C++,i.set({promptTokens:c,completionTokens:d,totalTokens:y,cost:b,count:C})}catch{C++,i.set({promptTokens:c,completionTokens:d,totalTokens:y,cost:b,count:C})}u(k)},{onEnd:k=>{k!==void 0?a(k):l()}});return()=>{E.unsubscribe()}},{initial:o.get()});return se.register(s,{kind:"tokenTracker",name:n}),s.tokens=i,s}}function De(e){return(t,o)=>{if(t!==0)return;let n=new AbortController,r=n.signal,i=!1,s,u;try{s=typeof e=="function"?e():e,u=s[Symbol.asyncIterator]()}catch(l){o(0,()=>{}),o(2,l);return}o(0,l=>{l===2&&!i&&(i=!0,n.abort(),Promise.resolve(u.return?.()).catch(()=>{}))});async function a(){try{for(;!i&&!r.aborted;){let l=await u.next();if(i||r.aborted)break;if(l.done){i=!0,o(2);return}o(1,l.value)}}catch(l){!i&&!r.aborted&&(i=!0,o(2,l))}}a()}}function qn(e){return e!=null&&typeof e.then=="function"}function Bn(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function Vn(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function Y(e){return qn(e)?Le(e):Bn(e)?De(e):typeof e!="string"&&Vn(e)?(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)});for(let r of e){if(n)return;o(1,r)}n||o(2)}:(t,o)=>{if(t!==0)return;let n=!1;o(0,r=>{r===2&&(n=!0)}),n||o(1,e),n||o(2)}}var at=class extends Error{constructor(){super("Gate: action rejected")}};function jt(e){let t=e.name??"agentLoop",o=e.maxIterations??10,n=e.shouldContinue??(()=>!1),r=!!e.gate,i=I("idle",{name:`${t}.phase`}),s=I(void 0,{name:`${t}.context`}),u=I(void 0,{name:`${t}.lastAction`}),a=I(0,{name:`${t}.iteration`}),l=I(void 0,{name:`${t}.error`}),c=I([],{name:`${t}.history`}),d=typeof e.gate=="object"?e.gate:{},y=d.maxPending??1/0,b=r?I([],{name:`${t}.pending`,equals:()=>!1}):void 0,C=r?I(d.startOpen??!1,{name:`${t}.isOpen`}):void 0,E=[],k=null,h=null,m=!1,p=!1,f=0,g=null;function S(v,w,q){c.update(J=>[...J,{phase:v,context:w,action:q,iteration:a.get()}])}function R(v,w,q){if(!r||!b||m){w(v);return}if(C.get()){w(v);return}E.push(v),E.length>y&&E.shift(),b.set([...E]);let J=ae(({emit:W,complete:z,error:P})=>{let F=G=>{W(G),z()},j=G=>{P(G)};return k=F,h=j,()=>{k===F&&(k=null),h===j&&(h=null)}},{_skipInspect:!0});V(J.source,W=>{w(W)},{onEnd:W=>{W!==void 0&&q(W)}})}function D(v){let w=E.splice(0,v);return b?.set([...E]),w}function x(){p=!1;let v=g;g=null,v?.()}function T(v,w){m||(l.set(v),i.set("errored"),S("errored",w)),x()}function L(v,w,q){if(m||q!==f){x();return}if(w>=o){i.set("completed"),S("completed",v),x();return}let J=w+1;a.set(J),i.set("observe"),S("observe",v);let W;try{W=e.observe(v)}catch(z){T(z,v);return}V(Y(W),z=>{if(s.set(z),m||q!==f){x();return}i.set("plan"),S("plan",z);let P;try{P=e.plan(z)}catch(F){T(F,z);return}V(Y(P),F=>{if(u.set(F),m||q!==f){x();return}let j=G=>{if(u.set(G),m||q!==f){x();return}i.set("act"),S("act",z,G);let le;try{le=e.act(G,z)}catch(ie){T(ie,z);return}V(Y(le),ie=>{if(s.set(ie),m||q!==f){x();return}n(ie,J)?L(ie,J,q):(i.set("completed"),S("completed",ie),x())},{onEnd:ie=>{ie!==void 0&&T(ie,z)}})};r?(i.set("awaiting_approval"),S("awaiting_approval",z,F),R(F,G=>{j(G)},G=>{G instanceof at&&!m?L(z,J,q):T(G,z)})):j(F)},{onEnd:F=>{F!==void 0&&T(F,z)}})},{onEnd:z=>{z!==void 0&&T(z,v)}})}function A(v,w){w===f&&(p=!0,m=!1,E=[],k=null,h=null,b?.set([]),s.set(v),a.set(0),l.set(void 0),u.set(void 0),L(v,0,w))}function M(v){f++;let w=f;c.set([]),p?(m=!0,g=()=>{w===f&&A(v,w)},k&&k(E[0]??void 0)):A(v,w)}function O(){m=!0,p&&i.set("completed"),k&&k(E[0]??void 0)}let B={phase:i,context:s,lastAction:u,iteration:a,error:l,start:M,stop:O,history:c};if(!r)return B;let _=B;return _.pending=b,_.isOpen=C,_.approve=(v=1)=>{let w=D(1);w.length>0&&k&&k(w[0])},_.reject=(v=1)=>{D(1),h&&h(new at)},_.modify=v=>{let w=D(1);w.length>0&&k&&k(v(w[0]))},_.open=()=>{C.set(!0);let v=D(E.length);v.length>0&&k&&k(v[0])},_.close=()=>{C.set(!1)},_}var Ie=class{_v;_w;constructor(t){this._v=0,this._w=t>32?new Uint32Array((t-1>>>5)+1):null}set(t){let o=this._w;if(o===null)this._v|=1<<t;else{let n=t>>>5,r=1<<(t&31);o[n]&r||(o[n]|=r,this._v++)}}clear(t){let o=this._w;if(o===null)this._v&=~(1<<t);else{let n=t>>>5,r=1<<(t&31);o[n]&r&&(o[n]&=~r,this._v--)}}test(t){let o=this._w;return o===null?(this._v&1<<t)!==0:(o[t>>>5]&1<<(t&31))!==0}empty(){return this._v===0}reset(){this._v=0,this._w?.fill(0)}};var xe=1,Oe=2,$e=4,ue=8,be=32,Ut=64,zn=Ye<<oe,Pe=Qe<<oe,vt=Xe<<oe,Ve=Ze<<oe,jn=et<<oe,ct=tt<<oe,te=Fe,ut=class{_output=null;_upstreamTalkbacks=[];_cachedValue;_flags;_dirtyDeps;_eqFn;_deps;_fn;get _status(){return nt(this._flags)}constructor(t,o,n,r){this._deps=t,this._fn=o,this._eqFn=n?.equals,this._flags=r?Ut:0,this._dirtyDeps=new Ie(t.length),this.source=this.source.bind(this),se.register(this,{kind:"derived",...n,deps:t});for(let i of t)se.registerEdge(i,this)}_dispatch(t,o){let n=this._output;if(n)if(this._flags&be)for(let r of n)r(t,o);else n(t,o)}_recompute(){let t;try{t=this._fn()}catch(o){this._handleEnd(o);return}if(this._eqFn&&this._flags&xe&&this._eqFn(this._cachedValue,t)){this._flags=this._flags&~te|Ve,this._dispatch(H,re);return}this._cachedValue=t,this._flags=(this._flags|xe)&~te|vt,this._dispatch(ee,this._cachedValue)}_recomputeIdentity(t){if(!(this._flags&ue)){if(this._eqFn&&this._flags&xe&&this._eqFn(this._cachedValue,t)){this._flags=this._flags&~te|Ve,this._dispatch(H,re);return}this._cachedValue=t,this._flags=(this._flags|xe)&~te|vt,this._dispatch(ee,t)}}_lazyConnect(){if(!(this._flags&(Oe|ue))){try{this._cachedValue=this._fn()}catch(t){this._handleEnd(t);return}this._flags=(this._flags|xe)&~te|vt,we(),this._connectUpstream(),this._flags&ue||(this._flags|=Oe),ke()}}_connectUpstream(){this._upstreamTalkbacks.length=0,this._deps.length===1?this._flags&Ut?this._connectSingleDepIdentity():this._connectSingleDep():this._connectMultiDep()}_connectSingleDep(){let t=!1;this._deps[0].source(K,(o,n)=>{if(o===K){this._upstreamTalkbacks.push(n),n(H,Te);return}if(!(this._flags&ue))if(o===H)if(n===Z){if(t)return;t=!0,this._flags=this._flags&~te|Pe,this._dispatch(H,Z)}else n===re?t&&(t=!1,this._flags=this._flags&~te|Ve,this._dispatch(H,re)):this._dispatch(H,n);else o===ee?t?(t=!1,this._recompute()):(this._flags=this._flags&~te|Pe,this._dispatch(H,Z),this._recompute()):o===U&&this._handleEnd(n)})}_connectSingleDepIdentity(){let t=!1;this._deps[0].source(K,(o,n)=>{if(o===K){this._upstreamTalkbacks.push(n),n(H,Te);return}this._flags&ue||(o===H?n===Z?(t=!0,this._flags=this._flags&~te|Pe,this._dispatch(H,Z)):n===re?t&&(t=!1,this._flags=this._flags&~te|Ve,this._dispatch(H,re)):this._dispatch(H,n):o===ee?t?(t=!1,this._recomputeIdentity(n)):(this._flags=this._flags&~te|Pe,this._dispatch(H,Z),this._recomputeIdentity(n)):o===U&&this._handleEnd(n))})}_connectMultiDep(){for(let t=0;t<this._deps.length&&!(this._flags&ue);t++){let o=t;this._deps[o].source(K,(n,r)=>{if(n===K){this._upstreamTalkbacks.push(r);return}if(!(this._flags&ue))if(n===H)if(r===Z){let i=this._dirtyDeps.empty();this._dirtyDeps.set(o),i&&(this._flags&=~$e,this._flags=this._flags&~te|Pe,this._dispatch(H,Z))}else r===re?this._dirtyDeps.test(o)&&(this._dirtyDeps.clear(o),this._dirtyDeps.empty()&&(this._flags&$e?this._recompute():(this._flags=this._flags&~te|Ve,this._dispatch(H,re)))):this._dispatch(H,r);else n===ee?this._dirtyDeps.test(o)?(this._dirtyDeps.clear(o),this._flags|=$e,this._dirtyDeps.empty()&&this._recompute()):this._dirtyDeps.empty()?(this._flags=this._flags&~te|Pe,this._dispatch(H,Z),this._recompute()):this._flags|=$e:n===U&&this._handleEnd(r)})}}_handleEnd(t){this._flags|=ue,this._flags=this._flags&~te|(t!==void 0?ct:jn),t!==void 0&&(this._cachedValue=t);for(let r of this._upstreamTalkbacks)r(U);this._upstreamTalkbacks=[],this._flags&=~Oe,this._dirtyDeps.reset();let o=this._output,n=this._flags&be;if(this._output=null,this._flags&=~be,o)if(n)for(let r of o)try{t!==void 0?r(U,t):r(U)}catch{}else t!==void 0?o(U,t):o(U)}_disconnectUpstream(){for(let t of this._upstreamTalkbacks)t(U);this._upstreamTalkbacks.length=0,this._flags&=~(Oe|$e),this._flags=this._flags&~te|zn,this._dirtyDeps.reset()}_handleLifecycleSignal(t){if(!(this._flags&ue)){if(t===ge){for(let o of this._upstreamTalkbacks)o(H,ge);this._handleEnd(void 0);return}t===he&&(this._flags&=~(xe|$e),this._dirtyDeps.reset());for(let o of this._upstreamTalkbacks)o(H,t)}}get(){if(this._flags&Oe)return this._cachedValue;if(this._flags&ue){if((this._flags&te)===ct)throw this._cachedValue;return this._cachedValue}let t=this._fn();return this._cachedValue=t,this._flags|=xe,t}source(t,o){if(t===K){let n=o;if(this._flags&ue){let r=(this._flags&te)===ct;n(K,i=>{}),r?n(U,this._cachedValue):n(U);return}if(!(this._flags&Oe)&&(this._lazyConnect(),this._flags&ue)){let r=(this._flags&te)===ct;n(K,i=>{}),r?n(U,this._cachedValue):n(U);return}if(this._output===null)this._output=n;else if(this._flags&be)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags|=be}n(K,(r,i)=>{if(r===ee&&n(ee,this._cachedValue),r===H&&Ee(i)){this._handleLifecycleSignal(i);return}if(r===U){if(this._output===null)return;if(this._flags&be){let s=this._output;s.delete(n),s.size===1?(this._output=s.values().next().value,this._flags&=~be):s.size===0&&(this._output=null,this._flags&=~be,this._disconnectUpstream())}else this._output===n&&(this._output=null,this._disconnectUpstream())}})}}};function Q(e,t,o){return new ut(e,t,o)}(t=>{function e(o,n){return new ut([o],()=>o.get(),n,!0)}t.from=e})(Q||={});var Un=0;lt.from=function(t){let o=lt({id:t.id});for(let[n,r]of Object.entries(t.index))for(let i of r)o.add(i,[n]);return o};function lt(e){let t=++Un,o=e?.id??`ridx-${t}`,n=new Map,r=new Map,i=new Map,s=new Map,u=I(0,{name:`${o}:ver`}),a=Q([u],()=>Array.from(n.keys()),{name:`${o}:keys`}),l=Q([u],()=>n.size,{name:`${o}:size`}),c=!1,d=Object.freeze(new Set);function y(h){let m=i.get(h);return m||(m=I(n.get(h)??new Set,{name:`${o}:${h}`,equals:()=>!1}),i.set(h,m)),m}function b(h){let m=i.get(h);if(m){let p=n.get(h);m.set(p?new Set(p):new Set)}}function C(h,m){let p=n.get(m),f=!p;return p||(p=new Set,n.set(m,p)),p.add(h),f}function E(h,m){let p=n.get(m);return p?(p.delete(h),p.size===0?(n.delete(m),!0):!1):!1}return{get id(){return o},get version(){return u.get()},get(h){let m=n.get(h);return m?Object.freeze(new Set(m)):d},has(h){let m=n.get(h);return m!==void 0&&m.size>0},keys(){return Array.from(n.keys())},get size(){return n.size},select(h){let m=s.get(h);if(m)return m;let p=y(h);return m=Q([p],()=>p.get(),{name:`${o}:${h}:select`}),s.set(h,m),m},keysStore:a,sizeStore:l,add(h,m){if(c||m.length===0)return;let p=r.get(h);p||(p=new Set,r.set(h,p)),$(()=>{let f=!1;for(let g of m)p.add(g),C(h,g)&&(f=!0),b(g);f&&u.update(g=>g+1)})},remove(h){if(c)return;let m=r.get(h);m&&$(()=>{let p=!1;for(let f of m)E(h,f)&&(p=!0),b(f);r.delete(h),p&&u.update(f=>f+1)})},update(h,m){if(c)return;let p=r.get(h),f=new Set(m);$(()=>{let g=!1;if(p)for(let R of p)f.has(R)||(E(h,R)&&(g=!0),b(R));let S=r.get(h);S||(S=new Set,r.set(h,S)),S.clear();for(let R of m)S.add(R),C(h,R)&&(g=!0),b(R);g&&u.update(R=>R+1)})},clear(){n.size!==0&&$(()=>{n.clear(),r.clear();for(let h of i.values())h.set(new Set);u.update(h=>h+1)})},snapshot(){let h={};for(let[m,p]of n)h[m]=Array.from(p);return{type:"reactiveIndex",id:o,version:u.get(),index:h}},destroy(){if(!c){c=!0,n.clear(),r.clear();for(let h of i.values())N(h);i.clear();for(let h of s.values())N(h);s.clear(),N(u)}}}}function Ht(e,t=o=>o){let o=[],n=new Map,r=new Map;function i(l,c){let d=o[l],y=o[c];o[l]=y,o[c]=d,d.index=c,y.index=l}function s(l){for(;l>0;){let c=l-1>>>1;if(o[c].score<=o[l].score)break;i(l,c),l=c}}function u(l){let c=o.length;for(;;){let d=l,y=2*l+1,b=y+1;if(y<c&&o[y].score<o[d].score&&(d=y),b<c&&o[b].score<o[d].score&&(d=b),d===l)break;i(l,d),l=d}}function a(l){let c=o.length-1;if(l===c){o.pop();return}i(l,c),o.pop(),s(l),u(l)}return{touch(){},insert(l){if(n.has(l))return;let c=e(l),d={key:l,score:t(c.get()),index:o.length};o.push(d),n.set(l,d),s(d.index);let y=X(c,b=>{let C=n.get(l);if(!C)return;let E=C.score;C.score=t(b),C.score<E?s(C.index):C.score>E&&u(C.index)});r.set(l,()=>y.unsubscribe())},delete(l){let c=n.get(l);if(!c)return;let d=r.get(l);d&&(d(),r.delete(l)),a(c.index),n.delete(l)},evict(l=1){let c=[];for(;c.length<l&&o.length>0;){let{key:d}=o[0];c.push(d);let y=r.get(d);y&&(y(),r.delete(d)),a(0),n.delete(d)}return c},size:()=>n.size,clear(){for(let l of r.values())l();r.clear(),n.clear(),o.length=0}}}function Ne(e,t,o){let n=t?.halfLife??864e5,r=t?.recency??1,i=t?.importance??1,s=t?.frequency??.5,u=(o??Date.now())-e.accessedAt,a=Math.exp(-Math.LN2/n*u),l=1-1/(1+e.accessCount);return r*a+i*e.importance+s*l}var Hn=0;function Jn(){return`mem-${++Hn}`}function xt(e,t){let o=t?.id??Jn(),n=Date.now(),r={id:o,createdAt:t?.createdAt??n,updatedAt:t?.updatedAt??n,accessedAt:t?.accessedAt??n,accessCount:0,importance:t?.importance??.5,tags:new Set(t?.tags)},i=I(e,{name:`mem:${o}:content`}),s=I(r,{name:`mem:${o}:meta`,equals:()=>!1}),u={},a=Q([s],()=>Ne(s.get(),u),{name:`mem:${o}:score`});return{id:o,content:i,meta:s,scoreStore:a,touch(){let c=Date.now();s.update(d=>({...d,accessedAt:c,accessCount:d.accessCount+1}))},tag(...c){s.update(d=>{let y=new Set(d.tags);for(let b of c)y.add(b);return{...d,tags:y,updatedAt:Date.now()}})},untag(...c){s.update(d=>{let y=new Set(d.tags);for(let b of c)y.delete(b);return{...d,tags:y,updatedAt:Date.now()}})},setImportance(c){s.update(d=>({...d,importance:Math.max(0,Math.min(1,c)),updatedAt:Date.now()}))},update(c){$(()=>{i.set(c),s.update(d=>({...d,updatedAt:Date.now()}))})},score(c){return Ne(s.get(),c??u)},destroy(){N(i),N(s)}}}var Wn=0;function Ae(e){let t=++Wn,o=e?.maxSize??1/0,n=e?.weights??{},r=e?.admissionPolicy,i=e?.forgetPolicy,s=new Map,u=lt(),a=new Map,l=o<1/0?Ht(f=>s.get(f).meta,f=>Ne(f,n)):null,c=I(0,{name:`collection-${t}:ver`}),d=Q([c],()=>Array.from(s.values()),{name:`collection-${t}:nodes`}),y=Q([c],()=>s.size,{name:`collection-${t}:size`}),b=!1;function C(){c.update(f=>f+1)}function E(f){let g=Array.from(f.meta.get().tags);u.update(f.id,g);let S=X(f.meta,R=>{let D=Array.from(R.tags);u.update(f.id,D)});a.set(f.id,()=>S.unsubscribe())}function k(f){let g=a.get(f);g&&(g(),a.delete(f)),u.remove(f)}function h(){if(!l||s.size<=o)return;let f=l.evict(s.size-o);for(let g of f){let S=s.get(g);S&&(k(g),S.destroy(),s.delete(g))}}function m(){if(!i)return 0;let f=[];for(let g of s.values())i(g)&&f.push(g.id);for(let g of f){let S=s.get(g);S&&(k(g),l?.delete(g),S.destroy(),s.delete(g))}return f.length}return{add(f,g){if(b)throw new Error("Collection is destroyed");if(r){let R=Array.from(s.values()),D=r(f,R);switch(D.action){case"reject":return;case"update":{let x=s.get(D.targetId);if(!x)throw new Error(`Admission update target "${D.targetId}" not found`);return x.update(D.content),x}case"merge":{let x=s.get(D.targetId);if(!x)throw new Error(`Admission merge target "${D.targetId}" not found`);let T=D.reducer(x.content.get(),f);return x.update(T),x}default:break}}i&&m();let S=xt(f,g);return s.set(S.id,S),E(S),l?.insert(S.id),h(),C(),S},remove(f){let g=typeof f=="string"?f:f.id,S=s.get(g);return S?(k(g),l?.delete(g),S.destroy(),s.delete(g),C(),!0):!1},get(f){return s.get(f)},has(f){return s.has(f)},nodes:d,size:y,tagIndex:u,query(f){let g=[];for(let S of s.values())f(S)&&g.push(S);return g},byTag(f){let g=u.get(f),S=[];for(let R of g){let D=s.get(R);D&&S.push(D)}return S},topK(f,g){let S=g??n,R=Date.now(),D=Array.from(s.values()).map(x=>({node:x,score:Ne(x.meta.get(),S,R)}));return D.sort((x,T)=>T.score-x.score),D.slice(0,f).map(x=>x.node)},summarize(f,g,S){if(b)throw new Error("Collection is destroyed");let R=Array.from(new Set(f)),D=[];for(let L of R){let A=s.get(L);A&&D.push(A)}if(D.length===0)throw new Error("No valid nodes to summarize");let x=g(D),T;return $(()=>{for(let L of D)k(L.id),l?.delete(L.id),L.destroy(),s.delete(L.id);i&&m(),T=xt(x,S),s.set(T.id,T),E(T),l?.insert(T.id),h(),C()}),T},gc(){if(b)throw new Error("Collection is destroyed");let f=m();return f>0&&C(),f},destroy(){if(!b){b=!0,l?.clear();for(let f of a.values())f();a.clear(),u.destroy(),$(()=>{for(let f of s.values())f.destroy();s.clear()}),N(c)}}}}function Gn(e,t){let o=0,n=0,r=0;for(let s=0;s<e.length;s++)o+=e[s]*t[s],n+=e[s]*e[s],r+=t[s]*t[s];let i=Math.sqrt(n)*Math.sqrt(r);return i===0?1:1-o/i}function Kn(e,t){let o=0;for(let n=0;n<e.length;n++){let r=e[n]-t[n];o+=r*r}return Math.sqrt(o)}function Yn(e,t){let o=0;for(let n=0;n<e.length;n++)o+=e[n]*t[n];return-o}var Qn={cosine:Gn,euclidean:Kn,dotProduct:Yn};function At(e,t){e.push(t);let o=e.length-1;for(;o>0;){let n=o-1>>1;if(e[n].dist<=e[o].dist)break;let r=e[n];e[n]=e[o],e[o]=r,o=n}}function Xn(e){let t=e[0],o=e.pop();if(e.length>0){e[0]=o;let n=0;for(;;){let r=n,i=2*n+1,s=2*n+2;if(i<e.length&&e[i].dist<e[r].dist&&(r=i),s<e.length&&e[s].dist<e[r].dist&&(r=s),r===n)break;let u=e[r];e[r]=e[n],e[n]=u,n=r}}return t}function Jt(e,t){if(e.length!==t)throw new Error(`Expected ${t} dimensions, got ${e.length}`);return new Float32Array(e)}function Zn(e){for(let t=0;t<e.length;t++)if(!Number.isFinite(e[t]))throw new Error("Vector contains non-finite values")}function dt(e){let t=e.dimensions;if(!t||t<=0)throw new Error("dimensions must be a positive integer");let o=e.m??16,n=o*2,r=e.efConstruction??200,i=e.efSearch??50,s=Qn[e.distance??"cosine"];if(!s)throw new Error(`Unknown distance metric: ${e.distance}`);let u=1/Math.log(o),a=[],l=new Map,c=-1,d=-1,y=0,b=I(0);function C(){let T=Math.random();return T===0&&(T=Number.EPSILON),Math.floor(-Math.log(T)*u)}function E(T,L,A,M){let O=new Set;O.add(L);let B=s(T,a[L].vector),_=[];At(_,{idx:L,dist:B});let v=[{idx:L,dist:B}];for(;_.length>0;){let w=Xn(_);if(v.length>=A){let W=-1/0;for(let z=0;z<v.length;z++)v[z].dist>W&&(W=v[z].dist);if(w.dist>W)break}let J=a[w.idx].neighbors[M];if(J)for(let W of J){if(O.has(W))continue;O.add(W);let z=a[W];if(z.deleted)continue;let P=s(T,z.vector);if(v.length<A)At(_,{idx:W,dist:P}),v.push({idx:W,dist:P});else{let F=0,j=v[0].dist;for(let G=1;G<v.length;G++)v[G].dist>j&&(j=v[G].dist,F=G);P<j&&(At(_,{idx:W,dist:P}),v[F]={idx:W,dist:P})}}}return v}function k(T,L,A){let M=L,O=s(T,a[M].vector),B=!0;for(;B;){B=!1;let _=a[M].neighbors[A];if(!_)break;for(let v of _){let w=a[v];if(w.deleted)continue;let q=s(T,w.vector);q<O&&(M=v,O=q,B=!0)}}return M}function h(T,L){T.sort((M,O)=>M.dist-O.dist);let A=[];for(let M=0;M<Math.min(T.length,L);M++)A.push(T[M].idx);return A}function m(T,L,A){let M=A===0?n:o;a[T].neighbors[A].add(L),a[L].neighbors[A].add(T),a[T].neighbors[A].size>M&&p(T,A,M),a[L].neighbors[A].size>M&&p(L,A,M)}function p(T,L,A){let M=a[T],O=[];for(let _ of M.neighbors[L])a[_].deleted||O.push({idx:_,dist:s(M.vector,a[_].vector)});let B=h(O,A);M.neighbors[L]=new Set(B)}function f(T,L){let A=Jt(L,t);if(Zn(A),l.has(T)){let w=l.get(T),q=a[w];if(q.deleted){if(q.deleted=!1,q.vector=A,y++,c===-1)c=w,d=q.layer;else{for(let J=q.layer;J>=0;J--)q.neighbors[J]=new Set,g(w,J);q.layer>d&&(c=w,d=q.layer)}b.set(y)}else{q.vector=A;for(let J=q.layer;J>=0;J--){for(let W of q.neighbors[J])a[W].neighbors[J].delete(w);q.neighbors[J]=new Set,g(w,J)}}return}let M=C(),O=a.length,B=[];for(let w=0;w<=M;w++)B.push(new Set);let _={id:T,vector:A,layer:M,neighbors:B,deleted:!1};if(a.push(_),l.set(T,O),y++,c===-1){c=O,d=M,b.set(y);return}let v=c;for(let w=d;w>M;w--)v=k(A,v,w);for(let w=Math.min(M,d);w>=0;w--){let q=E(A,v,r,w),W=h(q,w===0?n:o);for(let z of W)z!==O&&m(O,z,w);q.length>0&&(q.sort((z,P)=>z.dist-P.dist),v=q[0].idx)}M>d&&(c=O,d=M),b.set(y)}function g(T,L){let A=c;if(A===T){let _=-1;for(let v=0;v<a.length;v++)if(v!==T&&!a[v].deleted&&a[v].layer>=L){_=v;break}if(_===-1)return;A=_}for(let _=Math.min(d,a[A].layer);_>L;_--)A=k(a[T].vector,A,_);let M=E(a[T].vector,A,r,L),B=h(M,L===0?n:o);for(let _ of B)_!==T&&m(T,_,L)}function S(T){let L=l.get(T);if(L===void 0)return!1;let A=a[L];if(A.deleted)return!1;if(A.deleted=!0,y--,b.set(y),L===c){let M=-1;for(let O=0;O<a.length;O++)a[O].deleted||(M===-1||a[O].layer>a[M].layer)&&(M=O);c=M,d=M===-1?-1:a[M].layer}return!0}function R(T,L=10){if(y===0)return[];let A=Jt(T,t),M=Math.min(L,y),O=Math.max(i,M),B=c;for(let w=d;w>0;w--)B=k(A,B,w);let _=E(A,B,O,0);_.sort((w,q)=>w.dist-q.dist);let v=[];for(let w=0;w<_.length&&v.length<M;w++){let q=a[_[w].idx];q.deleted||v.push({id:q.id,distance:_[w].dist})}return v}function D(T){let L=l.get(T);return L===void 0?!1:!a[L].deleted}function x(){a.length=0,l.clear(),c=-1,d=-1,y=0,b.set(0),N(b)}return{add:f,remove:S,search:R,has:D,size:b,destroy:x}}function Wt(e,t,o){if(e.size.get()===0)return{isDuplicate:!1,similarity:0};let n=e.search(t,1);if(n.length===0)return{isDuplicate:!1,similarity:0};let r=n[0],i=1-r.distance;return i>=o?{isDuplicate:!0,existingId:r.id,similarity:i}:{isDuplicate:!1,similarity:i}}var er=`You are a memory extraction system. Given a conversation, extract discrete factual statements worth remembering for future conversations.
|
|
5
5
|
|
|
6
6
|
Output ONLY a JSON array. Each element has:
|
|
7
7
|
- "content": concise factual statement (1-2 sentences)
|
|
@@ -19,16 +19,16 @@ Example output:
|
|
|
19
19
|
[
|
|
20
20
|
{"content": "User prefers TypeScript over JavaScript", "importance": 0.8, "tags": ["preference", "technical"]},
|
|
21
21
|
{"content": "User is building a state management library", "importance": 0.9, "tags": ["project", "technical"]}
|
|
22
|
-
]`;function
|
|
23
|
-
`);return[{role:"system",content:o},{role:"user",content:n}]}function
|
|
24
|
-
`).filter(r=>r.trim()),n=[];for(let r of o)try{let i=JSON.parse(r.trim().replace(/^[-*]\s*/,"")),s=Et(i);s&&n.push(s)}catch{}return n}function Et(e){if(!e||typeof e!="object")return null;let t=e,o=typeof t.content=="string"?t.content.trim():"";if(!o)return null;let n=typeof t.importance=="number"?Math.max(0,Math.min(1,t.importance)):.5,r=Array.isArray(t.tags)?t.tags.filter(i=>typeof i=="string"):[];return{content:o,importance:n,tags:r}}function
|
|
22
|
+
]`;function Gt(e,t){let o=t??er,n=e.map(r=>`${r.role}: ${r.content}`).join(`
|
|
23
|
+
`);return[{role:"system",content:o},{role:"user",content:n}]}function Kt(e){let t=e.trim();if(!t)return[];try{let r=JSON.parse(t);if(Array.isArray(r))return r.map(Et).filter(i=>i!==null)}catch{}try{let r=t.indexOf("["),i=t.lastIndexOf("]");if(r!==-1&&i>r){let s=JSON.parse(t.slice(r,i+1));if(Array.isArray(s))return s.map(Et).filter(u=>u!==null)}}catch{}let o=t.split(`
|
|
24
|
+
`).filter(r=>r.trim()),n=[];for(let r of o)try{let i=JSON.parse(r.trim().replace(/^[-*]\s*/,"")),s=Et(i);s&&n.push(s)}catch{}return n}function Et(e){if(!e||typeof e!="object")return null;let t=e,o=typeof t.content=="string"?t.content.trim():"";if(!o)return null;let n=typeof t.importance=="number"?Math.max(0,Math.min(1,t.importance)):.5,r=Array.isArray(t.tags)?t.tags.filter(i=>typeof i=="string"):[];return{content:o,importance:n,tags:r}}function tr(e){let t=e.meta.get();return{id:t.id,createdAt:t.createdAt,updatedAt:t.updatedAt,accessedAt:t.accessedAt,accessCount:t.accessCount,importance:t.importance,tags:Array.from(t.tags)}}function nr(e,t){let o=e.nodes.get().map(r=>({id:r.id,content:r.content.get(),meta:tr(r)})),n={};for(let[r,i]of t)n[r]=Array.from(i);return{nodes:o,embeddings:n}}function Qt(e,t,o,n,r){let i=!1,s=!1,u=X(e.nodes,()=>{if(i||s)return;let c=nr(e,o),d=n.save(r,c);d!==void 0&&V(d,()=>{},{onEnd:y=>{}})});function a(){let c=n.load(r);if(c!=null){if(typeof c!="function"){s=!0,Yt(c,e,t,o),s=!1;return}s=!0,V(Y(c),d=>{d&&typeof d=="object"&&Yt(d,e,t,o),s=!1})}}function l(){i=!0,u.unsubscribe()}return{dispose:l,restore:a}}function Yt(e,t,o,n){if(!(!e.nodes||!Array.isArray(e.nodes))){for(let r of e.nodes){let i=t.add(r.content,{id:r.id,importance:r.meta.importance,tags:r.meta.tags,createdAt:r.meta.createdAt,updatedAt:r.meta.updatedAt,accessedAt:r.meta.accessedAt});if(i)for(let s=0;s<r.meta.accessCount;s++)i.touch()}if(e.embeddings)for(let[r,i]of Object.entries(e.embeddings)){let s=new Float32Array(i);o.add(r,s),n.set(r,s)}}}var wt="scope:";function kt(e){if(!e)return[];let t=[];if(e.userId&&t.push(`${wt}user:${e.userId}`),e.agentId&&t.push(`${wt}agent:${e.agentId}`),e.tags)for(let o of e.tags)t.push(`${wt}${o}`);return t}function Xt(e,t){for(let o of t)if(!e.has(o))return!1;return!0}function Zt(e){let t=e.name??"agentMemory",o=e.maxSize??1e4,n=e.dedupThreshold??.85,r=e.llm,i=e.embed,s=Ae({maxSize:o,weights:e.weights}),u=dt({dimensions:e.dimensions}),a=new Map,l=I("idle",{name:`${t}.status`}),c=I(void 0,{name:`${t}.error`}),d=I([],{name:`${t}.results`}),y=I([],{name:`${t}.lastExtracted`}),b=e.adapter?Qt(s,u,a,e.adapter,t):null;b?.restore();let C=null,E=null,k=null,h=0;function m(x,T){C?.abort(),C=new AbortController;let L=C.signal,A=kt(T),M=++h;$(()=>{l.set("extracting"),c.set(void 0)}),k?.unsubscribe();let O=Gt(x,e.extractionPrompt);r.generate(O),k=X(r.status,B=>{if(!(L.aborted||M!==h))if(B==="completed"){let _=r.get(),v=Kt(_);if(v.length===0){$(()=>{l.set("idle"),y.set([])});return}l.set("embedding"),p(v,A,L)}else B==="errored"&&$(()=>{c.set(r.error.get()),l.set("error")})})}function p(x,T,L){let A=0;for(let M of x){if(L.aborted)return;V(Y(i(M.content)),O=>{if(L.aborted)return;let B=Wt(u,O,n);if(B.isDuplicate&&B.existingId){let _=s.get(B.existingId);if(_){_.update(M.content),_.setImportance(Math.max(_.meta.get().importance,M.importance));for(let v of M.tags)_.tag(v);for(let v of T)_.tag(v)}u.add(B.existingId,O),a.set(B.existingId,O)}else{let _=[...M.tags,...T],v=s.add(M.content,{importance:M.importance,tags:_});v&&(u.add(v.id,O),a.set(v.id,O))}A++,A===x.length&&$(()=>{l.set("idle"),y.set(x)})},{onEnd:O=>{L.aborted||(A++,O!==void 0?$(()=>{c.set(O),l.set("error")}):A===x.length&&$(()=>{l.set("idle"),y.set(x)}))}})}}function f(x,T,L=10){E?.abort(),E=new AbortController;let A=E.signal,M=kt(T);$(()=>{l.set("searching"),c.set(void 0)}),V(Y(i(x)),O=>{if(A.aborted)return;let B=u.search(O,L*2),_=[];for(let v of B){if(_.length>=L)break;let w=s.get(v.id);w&&(M.length>0&&!Xt(w.meta.get().tags,M)||(_.push({node:w,score:Math.max(0,1-v.distance)}),w.touch()))}$(()=>{d.set(_),l.set("idle")})},{onEnd:O=>{O!==void 0&&!A.aborted&&$(()=>{c.set(O),l.set("error")})}})}function g(x){let T=kt(x);if(T.length===0)return s.nodes.get();let L=s.byTag(T[0]);return T.length===1?L:L.filter(A=>Xt(A.meta.get().tags,T))}function S(x,T){let L=s.get(x);L&&(L.update(T),V(Y(i(T)),A=>{u.add(x,A),a.set(x,A)},{onEnd:A=>{A!==void 0&&c.set(A)}}))}function R(x){return u.remove(x),a.delete(x),s.remove(x)}function D(){C?.abort(),E?.abort(),k?.unsubscribe(),b?.dispose(),s.destroy(),u.destroy(),a.clear(),N(l),N(c),N(d),N(y)}return{add:m,search:f,results:d,getAll:g,update:S,delete:R,status:l,error:c,size:s.size,lastExtracted:y,inner:{collection:s,vectorIndex:u},destroy:D}}function ft(e,t){let o=t?.name??"chatStream",n=I([],{name:`${o}.messages`}),r=I("",{name:`${o}.partial`}),i=I(!1,{name:`${o}.streaming`}),s=I(void 0,{name:`${o}.error`}),u=null,a=null,l=!1,c=!1;function d(){u&&(u.abort(),u=null),i.set(!1)}function y(m){l=!1,i.set(!0),r.set(""),s.set(void 0);function p(){let f=n.get(),g="",S;try{S=e(m,f)}catch(R){r.set(""),i.set(!1),s.set(R),u=null,t?.onError?.(R);return}V(De(S),R=>{m.aborted||(g+=R,r.set(g))},{onEnd:R=>{if(!(m.aborted||l))if(R!==void 0){if(g.length>0){let D={role:"assistant",content:g};n.update(x=>[...x,D])}r.set(""),i.set(!1),s.set(R),u=null,t?.onError?.(R)}else{let D={role:"assistant",content:g};n.update(x=>[...x,D]),r.set(""),i.set(!1),u=null,t?.onComplete?.(g)}}})}if(t?.rateLimiter){if(!t.rateLimiter.tryAcquire()){V(t.rateLimiter.acquire(m,1),()=>{m.aborted||p()},{onEnd:g=>{if(g!==void 0){if(m.aborted)return;r.set(""),i.set(!1),s.set(g),u=null}}});return}if(m.aborted)return}p()}function b(m){a=m,t?.systemPrompt&&!c&&(c=!0,n.update(g=>[{role:"system",content:t.systemPrompt},...g]));let p={role:"user",content:m};n.update(g=>[...g,p]),d(),u=new AbortController;let f=u.signal;y(f)}function C(){if(!i.get())return;l=!0;let m=r.get();if(d(),m.length>0){let p={role:"assistant",content:m};n.update(f=>[...f,p])}r.set("")}function E(){if(a===null)return;let p=[...n.get()];p.length>0&&p[p.length-1].role==="assistant"&&(p=p.slice(0,-1)),p.length>0&&p[p.length-1].role==="user"&&(p=p.slice(0,-1)),n.set(p),b(a)}function k(){d(),n.set([]),r.set(""),s.set(void 0),a=null,c=!1}function h(m){n.set(m),m.length>0&&m[0].role==="system"&&(c=!0)}return{send:b,stop:C,retry:E,clear:k,messages:n,partial:r,streaming:i,error:s,setMessages:h}}function rr(e){let t=0;for(let o of e)t+=Math.ceil(o.content.split(/\s+/).filter(Boolean).length*1.3);return t}var or="Summarize the following conversation concisely, preserving key facts, decisions, and context. Output only the summary, no preamble.";function en(e){let t=e.maxTokens??2e3,o=e.summaryPrompt??or,n=I("",{name:e.name??"conversationSummary"}),r=!1,i=X(e.llm.status,a=>{if(r)if(a==="completed"){r=!1;let l=e.llm.get();l&&n.set(l)}else(a==="errored"||a==="pending")&&(r=!1)}),s=X(e.chat.messages,a=>{if(r||a.length===0||a[a.length-1].role!=="assistant"||e.llm.status.get()==="active"||rr(a)<=t)return;r=!0;let l=a.map(d=>`${d.role}: ${d.content}`).join(`
|
|
25
25
|
`),c=[{role:"user",content:`${o}
|
|
26
26
|
|
|
27
|
-
${l}`}];try{e.llm.generate(c)}catch{r=!1}});function u(){s.unsubscribe(),i.unsubscribe(),N(n)}return{get:()=>n.get(),source:(a,l)=>n.source(a,l),destroy:u}}function
|
|
28
|
-
${p}`}),e.factory(
|
|
29
|
-
`);if(!E)return;let
|
|
30
|
-
${E}`}),
|
|
31
|
-
`);
|
|
27
|
+
${l}`}];try{e.llm.generate(c)}catch{r=!1}});function u(){s.unsubscribe(),i.unsubscribe(),N(n)}return{get:()=>n.get(),source:(a,l)=>n.source(a,l),destroy:u}}function tn(e){let t=e.name??"conversationThread",o=new Map,n=I("",{name:`${t}.shared`}),r=I(0,{name:`${t}.threadCount`});function i(y,b){if(o.has(y))throw new Error(`Thread "${y}" already exists`);let E=ft((h,m)=>{let p=n.get();if(p){let f=m.findIndex(R=>R.role!=="system"),g=f===-1?m.length:f,S=[...m];return S.splice(g,0,{role:"system",content:`[Shared Context]
|
|
28
|
+
${p}`}),e.factory(h,S)}return e.factory(h,m)},{name:`${t}.${y}`,systemPrompt:b?.systemPrompt,rateLimiter:b?.rateLimiter??e.defaults?.rateLimiter,onComplete:b?.onComplete??e.defaults?.onComplete,onError:b?.onError??e.defaults?.onError}),k={id:y,send:E.send,stop:E.stop,retry:E.retry,clear:E.clear,messages:E.messages,partial:E.partial,streaming:E.streaming,error:E.error,setMessages:E.setMessages};return o.set(y,k),r.set(o.size),k}function s(y){return o.get(y)}function u(y){return o.has(y)}function a(){return Array.from(o.keys())}function l(y,b){let C=o.get(y);if(!C)throw new Error(`Thread "${y}" not found`);let E=b.filter(f=>f.role!=="system").map(f=>`[${f.role}]: ${f.content}`).join(`
|
|
29
|
+
`);if(!E)return;let k=C.messages.get(),h=k.findIndex(f=>f.role!=="system"),m=h===-1?k.length:h,p=[...k];p.splice(m,0,{role:"system",content:`[Cross-Thread Context]
|
|
30
|
+
${E}`}),C.setMessages(p)}function c(y){let b=o.get(y);b&&(b.clear(),o.delete(y),r.set(o.size))}function d(){for(let[y]of o)c(y)}return{create:i,get:s,has:u,list:a,shared:n,inject:l,destroyThread:c,destroy:d,threadCount:r}}function nn(e){let t=typeof e.db=="string"?e.db:e.db.href,o=e.limit??10,n=e.fetch??globalThis.fetch,r=I([],{name:e.name?`${e.name}.results`:void 0}),i=I(!1,{name:e.name?`${e.name}.loaded`:void 0}),s=I(void 0,{name:e.name?`${e.name}.error`:void 0}),u=null,a=null,l=!1;e._sqlite?(u=e._sqlite,c()):d();function c(){V(Y(n(t)),C=>{if(!C.ok){l||$(()=>{i.set(!1),s.set(new Error(`Failed to fetch DB: ${C.status} ${C.statusText}`))});return}l||(a=u.open_v2("docs.db"),$(()=>{i.set(!0),s.set(void 0)}))},{onEnd:C=>{C!==void 0&&!l&&$(()=>{i.set(!1),s.set(C)})}})}function d(){let C=null,E=null,k=null,h=2,m=!1;function p(g){m||(m=!0,l||$(()=>{i.set(!1),s.set(g)}))}function f(){if(h--,h>0||m||l)return;let{SQLiteAPI:g}=C;u=g(E);let S=E.vfs;S&&typeof S.writeFile=="function"&&S.writeFile("docs.db",new Uint8Array(k)),a=u.open_v2("docs.db"),$(()=>{i.set(!0),s.set(void 0)})}V(Y(import("@aspect-build/wa-sqlite")),g=>{C=g;let S=g.default??g;V(Y(typeof S=="function"?S():S),R=>{E=R,f()},{onEnd:R=>{R!==void 0&&p(R)}})},{onEnd:g=>{g!==void 0&&p(g)}}),V(Y(n(t).then(g=>{if(!g.ok)throw new Error(`Failed to fetch DB: ${g.status} ${g.statusText}`);return g.arrayBuffer()})),g=>{k=g,f()},{onEnd:g=>{g!==void 0&&p(g)}})}function y(C){if(!u||a===null||l){r.set([]);return}if(!C.trim()){r.set([]);return}try{let E=[],h=`SELECT rowid as id, title, snippet(docs, 1, '<mark>', '</mark>', '\u2026', 32) as excerpt, rank, source, tags FROM docs WHERE docs MATCH '"${C.replace(/"/g,'""')}"' ORDER BY rank LIMIT ${o}`;u.exec(a,h,(m,p)=>{let f=p.indexOf("id"),g=p.indexOf("title"),S=p.indexOf("excerpt"),R=p.indexOf("rank"),D=p.indexOf("source"),x=p.indexOf("tags");E.push({id:String(m[f]??""),title:String(m[g]??""),excerpt:String(m[S]??""),score:Number(m[R]??0),source:String(m[D]??""),tags:m[x]?String(m[x]).split(",").map(T=>T.trim()).filter(Boolean):[]})}),$(()=>{r.set(E),s.set(void 0)})}catch(E){$(()=>{r.set([]),s.set(E)})}}function b(){if(!l){if(l=!0,u&&a!==null)try{u.close(a)}catch{}u=null,a=null,$(()=>{i.set(!1),r.set([]),s.set(void 0)}),N(r),N(i),N(s)}}return{search:y,results:r,loaded:i,error:s,destroy:b}}function mt(e){let t=0,o=null;return{call(n,r,i){o?.abort(),o=new AbortController;let s=++t,u=o.signal;e(n,u).then(a=>{s===t&&r(a)},a=>{s===t&&i?.(a)})},cancel(){t++,o?.abort(),o=null}}}function rn(e){let t=e.model??"Xenova/all-MiniLM-L6-v2",o=typeof e.vectors=="string"?e.vectors:e.vectors.href,n=typeof e.manifest=="string"?e.manifest:e.manifest.href,r=e.limit??10,i=e.fetch??globalThis.fetch,s=I([],{name:e.name?`${e.name}.results`:void 0}),u=I(!1,{name:e.name?`${e.name}.loaded`:void 0}),a=I(void 0,{name:e.name?`${e.name}.error`:void 0}),l=e._embedFn??null,c=null,d=null,y=!1,b=mt(({query:p,embedder:f})=>f(p,{pooling:"mean",normalize:!0}));e._embedFn?C():E();function C(){let p=null,f=null,g=2,S=!1;function R(x){S||(S=!0,y||$(()=>{u.set(!1),a.set(x)}))}function D(){if(g--,!(g>0||S||y)){c=p;try{k(f)}catch(x){R(x)}}}V(Y(i(n).then(x=>{if(!x.ok)throw new Error(`Failed to fetch manifest: ${x.status} ${x.statusText}`);return x.json()})),x=>{p=x,D()},{onEnd:x=>{x!==void 0&&R(x)}}),V(Y(i(o).then(x=>{if(!x.ok)throw new Error(`Failed to fetch vectors: ${x.status} ${x.statusText}`);return x.arrayBuffer()})),x=>{f=x,D()},{onEnd:x=>{x!==void 0&&R(x)}})}function E(){let p=null,f=null,g=null,S=3,R=!1;function D(T){R||(R=!0,y||$(()=>{u.set(!1),a.set(T)}))}function x(){if(S--,!(S>0||R||y)){c=p,l=g;try{k(f)}catch(T){D(T)}}}V(Y(i(n).then(T=>{if(!T.ok)throw new Error(`Failed to fetch manifest: ${T.status} ${T.statusText}`);return T.json()})),T=>{p=T,x()},{onEnd:T=>{T!==void 0&&D(T)}}),V(Y(i(o).then(T=>{if(!T.ok)throw new Error(`Failed to fetch vectors: ${T.status} ${T.statusText}`);return T.arrayBuffer()})),T=>{f=T,x()},{onEnd:T=>{T!==void 0&&D(T)}}),V(Y(import("@huggingface/transformers").then(T=>{let L=T.pipeline??T.default?.pipeline;if(!L)throw new Error("Could not find pipeline export from @huggingface/transformers");return L("feature-extraction",t)})),T=>{g=T,x()},{onEnd:T=>{T!==void 0&&D(T)}})}function k(p){let f=e.dimensions??c.dimensions??384,g=new Float32Array(p),S=c.count*f;if(g.length!==S)throw new Error(`Vector binary size mismatch: expected ${S} floats (${c.count} \xD7 ${f}), got ${g.length}`);d=dt({dimensions:f,distance:"cosine"});for(let R=0;R<c.count;R++){let D=c.ids[R],x=g.subarray(R*f,(R+1)*f);d.add(D,x)}$(()=>{u.set(!0),a.set(void 0)})}function h(p,f){if(!l||!d||!c||y){s.set([]);return}if(!p.trim()){$(()=>{s.set([]),a.set(void 0)});return}let g=f??r,S=d,R=c;b.call({query:p,embedder:l},D=>{if(y)return;let T=S.search(D.data,g).map(L=>({id:L.id,score:Math.max(0,Math.min(1,1-L.distance)),metadata:R.entries[L.id]??{}}));$(()=>{s.set(T),a.set(void 0)})},D=>{y||$(()=>{s.set([]),a.set(D)})})}function m(){y=!0,b.cancel(),d&&(d.destroy(),d=null),l=null,c=null,$(()=>{u.set(!1),s.set([]),a.set(void 0)}),N(s),N(u),N(a)}return{search:h,results:s,loaded:u,error:a,destroy:m}}function cn(e){return e.map(t=>{let o;try{o=JSON.parse(t.arguments)}catch{o=t.arguments}return{id:t.id,tool:t.name,args:o}})}function sr(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function ir(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function ar(e,t,o,n){let r={model:t,messages:o.map(i=>cr(e,i)),stream:!0};return n?.temperature!==void 0&&(r.temperature=n.temperature),n?.maxTokens!==void 0&&(e==="ollama"?r.options={num_predict:n.maxTokens}:r.max_tokens=n.maxTokens),n?.stop&&(r.stop=n.stop),n?.tools&&n.tools.length>0&&(r.tools=n.tools),r}function cr(e,t){let o={role:t.role,content:t.content};return t.tool_calls&&t.tool_calls.length>0&&(e==="ollama"?o.tool_calls=t.tool_calls.map(n=>{let r;try{r=JSON.parse(n.arguments)}catch{r={}}return{function:{name:n.name,arguments:r}}}):o.tool_calls=t.tool_calls.map(n=>({id:n.id,type:"function",function:{name:n.name,arguments:n.arguments}}))),t.tool_call_id&&(o.tool_call_id=t.tool_call_id),o}function ur(e,t){let o={"Content-Type":"application/json"};return t&&(o.Authorization=`Bearer ${t}`),o}function un(e){let t=e.name??"llm",o=e.provider,n=e.baseURL??sr(o),r=e.model??"",i=e.fetch??globalThis.fetch,s=I("",{name:`${t}.store`}),u=I({},{name:`${t}.tokens`}),a=I("pending",{name:`${t}.status`}),l=I(void 0,{name:`${t}.error`}),c=I([],{name:`${t}.toolCalls`}),d=null,y=0,b=0;function C(){d&&(d.abort(),d=null),a.get()==="active"&&$(()=>{s.set(""),c.set([]),a.set("pending")})}function E(h,m){C(),d=new AbortController;let p=m?.signal?lr(d.signal,m.signal):d.signal;$(()=>{s.set(""),u.set({}),l.set(void 0),c.set([]),a.set("active")});let f=++y;try{let g=ir(o,n),S=ar(o,r,h,m),R=ur(o,e.apiKey);k(g,R,S,p,f)}catch(g){$(()=>{l.set(g),a.set("errored")}),y===f&&(d=null),p._cleanup?.()}}function k(h,m,p,f,g){let S=()=>{y===g&&(d=null)};V(Y(i(h,{method:"POST",headers:m,body:JSON.stringify(p),signal:f})),R=>{if(!R.ok){V(Y(R.text().catch(()=>"")),O=>{f.aborted||($(()=>{l.set(new Error(`LLM API error ${R.status}: ${O}`)),a.set("errored")}),S(),f._cleanup?.())});return}let D=R.body?.getReader();if(!D){if(f.aborted){f._cleanup?.();return}$(()=>{l.set(new Error("No response body")),a.set("errored")}),S(),f._cleanup?.();return}let x=new TextDecoder,T="",L="",A=new Map;V(De({[Symbol.asyncIterator](){return{next(){return D.read()},return(){return D.cancel(),Promise.resolve({done:!0,value:void 0})}}}}),O=>{if(f.aborted)return;L+=x.decode(O,{stream:!0});let B=L.split(`
|
|
31
|
+
`);L=B.pop()??"";for(let _ of B){if(f.aborted)return;let v=_.trim();if(!v||v.startsWith(":")||!v.startsWith("data: "))continue;let w=v.slice(6);if(w!=="[DONE]")try{let q=JSON.parse(w),J=on(o,q);if(J&&(T+=J,s.set(T)),sn(o,q,A,()=>`call_${b++}`)){let z=[];for(let[,P]of A)z.push({id:P.id,name:P.name,arguments:P.arguments});c.set(z)}let W=an(o,q);W&&u.set(W)}catch{}}},{onEnd:O=>{let B=x.decode();if(B&&(L+=B),L.trim()){let _=L.trim();if(_.startsWith("data: ")){let v=_.slice(6);if(v!=="[DONE]")try{let w=JSON.parse(v),q=on(o,w);if(q&&(T+=q,s.set(T)),sn(o,w,A,()=>`call_${b++}`)){let W=[];for(let[,z]of A)W.push({id:z.id,name:z.name,arguments:z.arguments});c.set(W)}let J=an(o,w);J&&u.set(J)}catch{}}}if(f.aborted){f._cleanup?.();return}O!==void 0?$(()=>{l.set(O),a.set("errored")}):a.set("completed"),S(),f._cleanup?.()}})},{onEnd:R=>{if(R!==void 0){if(f.aborted){f._cleanup?.();return}$(()=>{l.set(R),a.set("errored")}),S()}f._cleanup?.()}})}return{get:()=>s.get(),source:(h,m)=>s.source(h,m),tokens:u,status:a,error:l,toolCalls:c,generate:E,abort:C}}function on(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function sn(e,t,o,n){if(e==="ollama"){let s=t?.message?.tool_calls;if(!Array.isArray(s))return!1;let u=!1;for(let a=0;a<s.length;a++){let c=s[a]?.function;c&&(o.set(a,{id:n?n():`call_${a}`,name:c.name??"",arguments:typeof c.arguments=="string"?c.arguments:JSON.stringify(c.arguments??{})}),u=!0)}return u}let r=t?.choices?.[0]?.delta?.tool_calls;if(!Array.isArray(r))return!1;let i=!1;for(let s of r){let u=s.index??0,a=o.get(u);a||(a={id:"",name:"",arguments:""},o.set(u,a)),s.id&&(a.id=s.id,i=!0),s.function?.name&&(a.name=s.function.name,i=!0),s.function?.arguments&&(a.arguments+=s.function.arguments,i=!0)}return i}function an(e,t){let o=e==="ollama"?t:t?.usage;if(o){if(e==="ollama")return t.eval_count!==void 0||t.prompt_eval_count!==void 0?{promptTokens:t.prompt_eval_count,completionTokens:t.eval_count,totalTokens:(t.prompt_eval_count??0)+(t.eval_count??0)}:void 0;if(o.prompt_tokens!==void 0||o.completion_tokens!==void 0)return{promptTokens:o.prompt_tokens,completionTokens:o.completion_tokens,totalTokens:o.total_tokens}}}function lr(e,t){let o=new AbortController,n=o.signal;if(e.aborted||t.aborted)return o.abort(),n._cleanup=()=>{},n;let r=()=>{e.removeEventListener("abort",i),t.removeEventListener("abort",i)},i=()=>{o.abort(),r()};return e.addEventListener("abort",i,{once:!0}),t.addEventListener("abort",i,{once:!0}),n._cleanup=r,n}function ln(e){let t=e.name??"hybridRoute",o=e.fallbackOnError??!0,n=e.shouldRoute??(()=>"local"),r=I(void 0,{name:`${t}.result`}),i=I("idle",{name:`${t}.route`}),s=I(0,{name:`${t}.localCount`}),u=I(0,{name:`${t}.cloudCount`}),a=I(void 0,{name:`${t}.error`}),l=null;function c(){l&&(l.unsubscribe(),l=null)}function d(b,C,E){c(),r.set(b.get()),l=X(b,k=>{r.set(k)},{onEnd:k=>{if(k!==void 0)if(C==="local"&&o){a.set(k),i.set("cloud"),u.update(h=>h+1);try{let h=e.cloud(E);d(h,"cloud",E)}catch(h){a.set(h)}}else a.set(k)}})}function y(b){c(),a.set(void 0);let C=n(b);if(i.set(C),C==="local"){s.update(E=>E+1);try{let E=e.local(b);d(E,"local",b)}catch(E){if(a.set(E),o){i.set("cloud"),u.update(k=>k+1);try{let k=e.cloud(b);d(k,"cloud",b)}catch(k){a.set(k)}}}}else{u.update(E=>E+1);try{let E=e.cloud(b);d(E,"cloud",b)}catch(E){a.set(E)}}}return{store:r,route:i,localCount:s,cloudCount:u,error:a,process:y,dispose:c}}function dn(e){let t=e?.workingCapacity??20,o=e?.longTermCapacity??1e3,n=e?.weights??{},r=Ae(),i=Ae({maxSize:t}),s=Ae({maxSize:o,weights:n}),u=I(0),a=Q([u,i.size,s.size],()=>(u.get(),r.size.get()+i.size.get()+s.size.get()));function l(f,g){return r.add(f,g)}function c(f,g){return i.add(f,g)}function d(f,g){return s.add(f,g)}function y(f){let g=null,S=r.get(f);if(S?g=r:(S=i.get(f),S&&(g=i)),!S||!g)return!1;let R=S.meta.get(),D=s.add(S.content.get(),{id:R.id,importance:R.importance,tags:Array.from(R.tags)});for(let x=0;x<R.accessCount;x++)D.touch();return g.remove(f),!0}function b(f,g){let S=g??n,R=[...r.topK(f,S),...i.topK(f,S),...s.topK(f,S)];R.sort((x,T)=>T.score(S)-x.score(S));let D=R.slice(0,f);for(let x of D)x.touch();return D}function C(f,g){let S=g??n,R=[...r.topK(f,S),...i.topK(f,S),...s.topK(f,S)];return R.sort((D,x)=>x.score(S)-D.score(S)),R.slice(0,f)}function E(f){return[...r.byTag(f),...i.byTag(f),...s.byTag(f)]}function k(f){return[...r.query(f),...i.query(f),...s.query(f)]}function h(){r.destroy(),r=Ae(),u.update(f=>f+1)}function m(){r.destroy(),i.destroy(),s.destroy(),N(u)}let p=Q([u],()=>(u.get(),r.nodes.get()));return{remember:l,session:p,focus:c,working:i.nodes,store:d,longTerm:s.nodes,promote:y,recall:b,query:C,recallByTag:E,search:k,resetSession:h,destroy:m,totalSize:a}}function fn(e){if(!Number.isFinite(e)||e<0)throw new RangeError("rawSkip: n must be a non-negative finite number");return t=>(o,n)=>{if(o!==0)return;let r=0,i=null;t(0,(s,u)=>{if(s===0){i=u,n(0,(a,l)=>{i?.(a,l)});return}if(s===1){r++,r>e&&n(1,u);return}n(s,u)})}}function dr(e,t,o){let n=new Set,r=[];for(let i of e.slice(0,o))n.has(i.id)||(n.add(i.id),r.push({id:i.id,title:i.title,excerpt:i.excerpt,score:i.score,source:i.source}));for(let i of t.slice(0,o))n.has(i.id)||(n.add(i.id),r.push({id:i.id,title:String(i.metadata.title??i.id),excerpt:String(i.metadata.excerpt??""),score:i.score,source:String(i.metadata.source??"")}));return r}function fr(e,t,o,n){let r=[];if(n&&r.push(n),o&&r.push(`SUMMARY:
|
|
32
32
|
${o}`),t&&r.push(`USER CONTEXT:
|
|
33
33
|
${t}`),e.length>0){let i=e.map((s,u)=>`[${u+1}] ${s.title}
|
|
34
34
|
${s.excerpt}`).join(`
|
|
@@ -36,11 +36,11 @@ ${s.excerpt}`).join(`
|
|
|
36
36
|
`);r.push(`SEARCH RESULTS:
|
|
37
37
|
${i}`)}return r.join(`
|
|
38
38
|
|
|
39
|
-
`)}function
|
|
40
|
-
`)??"",
|
|
39
|
+
`)}function mn(e){let t=e.maxResults??5,o=[e.docSearch.results];e.semanticSearch&&o.push(e.semanticSearch.results);let n=Q(o,()=>dr(e.docSearch.results.get(),e.semanticSearch?.results.get()??[],t)),r=[n];e.summary&&r.push(e.summary),e.memory&&r.push(e.memory.session);let i=Q(r,()=>{let c=n.get(),d=e.memory?.query(3).map(b=>String(b.content.get())).join(`
|
|
40
|
+
`)??"",y=e.summary?.get()??"";return fr(c,d,y,e.systemPrompt)}),s=Q([e.llm.status],()=>e.llm.status.get()==="active"),u=mt(async(c,d)=>{e.docSearch.search(c),e.semanticSearch?.search(c),e.semanticSearch?.loaded.get()&&await Ce(fn(1)(e.semanticSearch.results.source),{signal:d})}),a=X(e.query,c=>{let d=c.trim();if(!d){e.llm.abort();return}u.call(d,()=>{let y=[{role:"system",content:i.get()},{role:"user",content:d}];e.llm.generate(y)},()=>{let y=[{role:"system",content:i.get()},{role:"user",content:d}];e.llm.generate(y)})});function l(){u.cancel(),a.unsubscribe(),e.llm.abort(),N(s),N(i),N(n)}return{context:i,docs:n,generating:s,error:e.llm.error,destroy:l}}function Rt(e){let t=e.split(/\s+/).filter(Boolean).length;return Math.ceil(t*1.3)}function pn(e,t){let o=e.split(/\s+/).filter(Boolean),n=0;for(let r=0;r<o.length;r++)if(n+=1.3,n>t)return o.slice(0,r).join(" ");return e}function gn(e){let t=e.sections.map(i=>i.content),o=e.name??"systemPromptBuilder",n=Q(t,()=>{let i=[];for(let s of e.sections){let u=s.content.get();u&&(s.maxTokens!==void 0&&(u=pn(u,s.maxTokens)),u&&i.push({name:s.name,text:u}))}if(e.maxTotalTokens!==void 0){let s=0;for(let u of i)s+=Rt(`## ${u.name}
|
|
41
41
|
${u.text}`);for(let u=i.length-1;u>=0&&s>e.maxTotalTokens;u--){let a=Rt(`## ${i[u].name}
|
|
42
42
|
${i[u].text}`),l=s-e.maxTotalTokens;if(l>=a)s-=a,i.splice(u,1);else{let c=Rt(`## ${i[u].name}
|
|
43
|
-
`),d=Math.max(0,a-l-c);i[u].text=
|
|
43
|
+
`),d=Math.max(0,a-l-c);i[u].text=pn(i[u].text,d),i[u].text?s=e.maxTotalTokens:(s-=a,i.splice(u,1))}}}return i.map(s=>`## ${s.name}
|
|
44
44
|
${s.text}`).join(`
|
|
45
45
|
|
|
46
|
-
`)},{name:o});function r(){N(n)}return Object.assign(n,{destroy:r})}function mn(e){let t=e?.name??"toolCall",o=e?.maxHistory??100,n=D("idle",{name:`${t}.status`}),r=D(void 0,{name:`${t}.toolName`}),i=D(void 0,{name:`${t}.args`}),s=D(void 0,{name:`${t}.result`}),u=D(void 0,{name:`${t}.error`}),a=D(void 0,{name:`${t}.duration`}),l=D([],{name:`${t}.history`}),c=null;function d(k,E){n.get()!=="executing"&&(r.set(k),i.set(E),s.set(void 0),u.set(void 0),a.set(void 0),n.set("pending"),c={toolName:k,args:E,status:"pending",requestedAt:Date.now()})}function h(k){if(n.get()!=="pending"||c===null)return;let E=c.args,w=c;n.set("executing"),w.status="executing";let b=Date.now(),m=()=>{c===w&&(c=null);let p={...w};l.update(f=>{let y=[...f,p];return y.length>o?y.slice(-o):y})};B(G(k(E)),p=>{let f=Date.now()-b;s.set(p),a.set(f),n.set("completed"),w.result=p,w.status="completed",w.duration=f,m()},{onEnd:p=>{if(p===void 0)return;let f=Date.now()-b;u.set(p),a.set(f),n.set("errored"),w.error=p,w.status="errored",w.duration=f,m()}})}function T(){n.set("idle"),r.set(void 0),i.set(void 0),s.set(void 0),u.set(void 0),a.set(void 0),c=null}return{status:n,toolName:r,args:i,result:s,error:u,duration:a,request:d,execute:h,reset:T,history:l}}function pn(e,t){return ie(({emit:o})=>{let n=0,r=setInterval(()=>o(n++),e);return t?.unref&&typeof r=="object"&&"unref"in r&&r.unref(),()=>clearInterval(r)})}function pt(e,t){return(o,n)=>{if(o!==0)return;let r=!1;function i(){r||(r=!0,clearTimeout(u),t?.removeEventListener("abort",s),n(1,void 0),n(2))}function s(){r||(r=!0,clearTimeout(u),t?.removeEventListener("abort",s),n(2,t.reason))}if(n(0,a=>{a===2&&!r&&(r=!0,clearTimeout(u),t?.removeEventListener("abort",s))}),t?.aborted){s();return}let u=setTimeout(i,e);t?.addEventListener("abort",s,{once:!0})}}function gt(e){let t=e?.base??100,o=e?.factor??2,n=e?.maxDelay??3e4,r=e?.jitter??"none";return i=>{let s=Math.min(t*o**i,n);return dr(s,r)}}function dr(e,t){switch(t){case"none":return e;case"full":return gn(0,e);case"equal":return e/2+gn(0,e/2)}}function gn(e,t){return e+Math.random()*(t-e)}function hn(e,t,o){let n,r=[],i=!1,s=new Ie(e.length),u=!1;function a(){i||(n&&n(),n=t())}let l=0;function c(h){if(!i){if(h===pe){for(let T of r)T(U,pe);r.length=0,i=!0,n&&n(),n=void 0;return}h===ge&&(l++,s.reset(),u=!1,a());for(let T of r)T(U,h)}}we(),a();for(let h=0;h<e.length&&!i;h++){let T=h,k=l;e[T].source(W,(E,w)=>{if(E===W){r.push(w),e.length===1&&w(U,Te);return}if(!i){if(E===U){if(Ee(w)){c(w),k=l;return}if(k!==l)return;w===X?(s.empty()&&(u=!1),s.set(T)):w===re&&s.test(T)&&(s.clear(T),s.empty()&&u&&a())}if(E===Z){if(k!==l)return;s.test(T)?(s.clear(T),u=!0,s.empty()&&a()):s.empty()?a():u=!0}if(E===j){i=!0,n&&n(),n=void 0;for(let b of r)b(j);r.length=0}}})}ke();let d=()=>{if(!i){i=!0,n&&n(),n=void 0;for(let h of r)h(j);r.length=0}};d.signal=h=>c(h),se.register(d,{kind:"effect",...o,deps:e});for(let h of e)se.registerEdge(h,d);return d}function fr(e){return e!=null&&typeof e.subscribe=="function"}function yn(e){return fr(e)?ie(({emit:t,complete:o,error:n})=>{let r=!1,i=e.subscribe({next:s=>{r||t(s)},error:s=>{r||n(s)},complete:()=>{r||o()}});return()=>{r=!0,i.unsubscribe()}}):ie(({emit:t,complete:o,error:n})=>{let r=B(G(e),i=>t(i),{onEnd:i=>i!==void 0?n(i):o()});return()=>r.unsubscribe()},{resubscribable:!0})}var mr=Symbol.for("callbag-recharge:topic-internal"),pr=Symbol.for("callbag-recharge:topic-log"),gr=0;function bn(e){return{seq:e.seq,value:e.value.value,timestamp:e.value.timestamp,key:e.value.key,priority:e.value.priority,headers:e.value.headers}}function Tn(e,t){let o=`sub-${++gr}`,n=t?.name??o,r=t?.mode??"exclusive",i=t?.batchSize??1,s=t?.ackTimeout??3e4,u=e[mr],a=e[pr],l,c=r==="shared"||r==="failover"||r==="key_shared",d;c?(d=u.getOrCreateGroup(n),d.consumers.add(o),d.consumers.size===1&&(d.cursor=h()),l=d.cursor):l=h();function h(){return t?.initialPosition==="earliest"?a.headSeq>0?a.headSeq:1:typeof t?.initialPosition=="number"?t.initialPosition:a.tailSeq+1}let T=new Map,k=new Map,E=[],w=t?.retry?.maxRetries??3,b=t?.retry?.backoff??gt(),m=t?.deadLetterTopic,p=!1,f=!1,y=D(l,{name:`${n}:pos`}),_=D(0,{name:`${n}:pending`}),R=K([a.lengthStore,a.events,y],()=>{let I=a.tailSeq,q=y.get(),z=a.headSeq,ee=z>0?Math.max(q,z):q;return Math.max(0,I-ee+1)},{name:`${n}:backlog`}),L=t?.persistence;function v(){L&&Promise.resolve(L.save(`${n}:cursor`,l)).catch(()=>{})}function g(){return r!=="failover"||!d?!0:d.consumers.values().next().value===o}function x(I){let q=0;for(let z=0;z<I.length;z++)q=(q<<5)-q+I.charCodeAt(z)|0;return Math.abs(q)}function C(I){if(r!=="key_shared"||!d||!I)return!0;let q=Array.from(d.consumers),z=x(I)%q.length;return q[z]===o}function O(I){if(p||f)return[];if(!g())return[];let q=I??i,z=[],ee=Date.now(),Y=[],be=[];for(let de of E)de.readyAt<=ee&&Y.length<q?Y.push(de):be.push(de);E.length=0,E.push(...be);for(let de of Y){let je=a.get(de.seq);if(je){let Ue=bn(je);z.push(Ue),$(de.seq)}}let ae=q-z.length,ze=-1;if(ae>0){let de=c&&d?d.cursor:l,je=a.tailSeq,Ue=0;for(let me=de;me<=je&&Ue<ae;me++){let bt=a.get(me);if(!bt||r==="key_shared"&&!C(bt.value.key))continue;if(r==="shared"&&d&&d.consumers.size>1){let Mt=Array.from(d.consumers),En=d.roundRobinIndex%Mt.length;if(Mt[En]!==o)continue;d.roundRobinIndex++}let An=bn(bt);z.push(An),$(me),me>ze&&(ze=me),Ue++}if(ze>=0){let me=ze+1;c&&d&&(d.cursor=Math.max(d.cursor,me)),l=c&&d?d.cursor:me}}return z.length>0&&P(()=>{y.set(l),_.update(de=>de+z.length)}),z}function $(I){let q;s>0&&(q=setTimeout(()=>{T.has(I)&&A(I)},s)),T.set(I,{timer:q})}function V(I){let q=T.get(I);q&&(q.timer&&clearTimeout(q.timer),T.delete(I),k.delete(I),_.update(z=>Math.max(0,z-1)),v())}function S(I,q){if(m){let z=a.get(I);z&&m.publish(z.value.value,{key:z.value.key,headers:{...z.value.headers,"x-original-topic":e.name,"x-retry-count":String(q),"x-original-seq":String(I)}})}k.delete(I)}function A(I){let q=T.get(I);if(!q)return;q.timer&&clearTimeout(q.timer),T.delete(I),_.update(be=>Math.max(0,be-1));let z=k.get(I)??{attempts:0},ee=z.attempts+1;if(ee>w){S(I,ee);return}let Y=b(ee-1,void 0,z.prevDelay);if(Y===null){S(I,ee);return}k.set(I,{attempts:ee,prevDelay:Y}),E.push({seq:I,readyAt:Date.now()+Y})}function M(I){if(f)return;let q;I==="earliest"?q=a.headSeq>0?a.headSeq:1:I==="latest"?q=a.tailSeq+1:q=I,l=q,c&&d&&(d.cursor=q),y.set(q);for(let z of T.values())z.timer&&clearTimeout(z.timer);T.clear(),_.set(0),E.length=0,k.clear(),v()}let F,H;if(L){let I=yn(L.load(`${n}:cursor`));H=I,F=hn([I],()=>{let q=I.get();typeof q=="number"&&M(q)})}function J(){if(!f){f=!0,F?.(),H&&N(H);for(let I of T.values())I.timer&&clearTimeout(I.timer);T.clear(),E.length=0,k.clear(),d&&(d.consumers.delete(o),d.consumers.size===0&&u.removeGroup(n)),P(()=>{N(y),N(_),N(R)})}}return{get name(){return n},get mode(){return r},pull:O,ack:V,nack:A,seek:M,position:y,backlog:R,pending:_,pause(){p||(p=!0,y.signal(Se),_.signal(Se))},resume(){p&&(p=!1,y.signal(_e),_.signal(_e))},get isPaused(){return p},destroy:J}}function Sn(e,t,o){let n=o?.threshold??0,r=null,i=!1;function s(){if(i)return 0;let u=e.toArray();if(u.length===0)return 0;let a=new Map,l=[];for(let h of u){let T=t(h.value);a.has(T)||l.push(T),a.set(T,h.value)}let c=l.map(h=>a.get(h)),d=u.length-c.length;if(d===0)return 0;i=!0;try{e.clear(),e.appendMany(c)}finally{i=!1}return d}return n>0&&(r=Q(e.events,u=>{u?.type==="append"&&e.length>=n&&s()})),{compact:s,destroy(){r?.unsubscribe(),r=null}}}var hr=0;ht.from=function(t,o){let n=ht({...o,id:t.id});for(let r of t.entries)n.append(r.value);return n};function ht(e){let t=++hr,o=e?.id??`rlog-${t}`,n=e?.maxSize??0,r=n>0,i=[],s=0,u=0,a=0,l=1,c=D(0,{name:`${o}:ver`}),d=D(void 0,{name:`${o}:events`,equals:()=>!1}),h=new Map,T=!1;function k(){if(!r)return i.slice();if(u===0)return[];let b=new Array(u);for(let m=0;m<u;m++)b[m]=i[(s+m)%n];return b}function E(b){if(!r)return i[b];if(!(b<0||b>=u))return i[(s+b)%n]}let w={get id(){return o},get version(){return c.get()},append(b){if(T)return-1;let m=++a,p={seq:m,value:b};return r?(u<n?(i[(s+u)%n]=p,u++):(i[s]=p,s=(s+1)%n),l=a-u+1):(i.push(p),l=i.length>0?i[0].seq:1),c.update(f=>f+1),d.set({type:"append",seq:m,value:b}),m},appendMany(b){if(T||b.length===0)return[];let m=[];return P(()=>{for(let p of b)m.push(w.append(p))}),m},get(b){if(r)return b<l||b>a||u===0?void 0:E(b-l);let m=b-l;if(!(m<0||m>=i.length))return i[m]},slice(b,m){let p=b??l,f=m??a;if((r?u:i.length)===0)return[];let _=Math.max(p,l),R=Math.min(f,a);if(_>R)return[];let L=_-l,v=R-l;if(!r)return i.slice(L,v+1);let g=[];for(let x=L;x<=v;x++)g.push(i[(s+x)%n]);return g},toArray(){return k()},get length(){return r?u:i.length},get headSeq(){return(r?u:i.length)>0?l:0},get tailSeq(){return a},clear(){(r?u:i.length)!==0&&P(()=>{r?(u=0,s=0):i.length=0,l=a+1,c.update(m=>m+1),d.set({type:"clear"})})},lengthStore:K([c],()=>r?u:i.length,{name:`${o}:length`}),latest:K([c],()=>{if((r?u:i.length)!==0)return r?i[(s+u-1)%n]:i[i.length-1]},{name:`${o}:latest`}),tail(b){let m=h.get(b);return m||(m=K([c],()=>{let p=k();return b===void 0||b>=p.length?p:p.slice(-b)},{name:`${o}:tail${b??""}`}),h.set(b,m),m)},events:d,snapshot(){return{type:"reactiveLog",id:o,version:c.get(),entries:k().map(b=>({seq:b.seq,value:b.value})),headSeq:(r?u:i.length)>0?l:0,tailSeq:a}},destroy(){T||(T=!0,P(()=>{for(let b of h.values())N(b);h.clear(),N(w.lengthStore),N(w.latest),N(d),N(c),i.length=0,u=0}))}};return w}var yr=0;function yt(e){return{seq:e.seq,value:e.value.value,timestamp:e.value.timestamp,key:e.value.key,priority:e.value.priority,headers:e.value.headers}}function _n(e,t){let o=++yr,n=t?.namespace,r=n?n.prefix(e):e,i=`topic-${r}-${o}`,s=ht({id:`${i}:log`,maxSize:t?.maxSize}),u;if(t?.compaction){let g=t.compaction.keyFn;u=Sn(s,x=>g(x.value),{threshold:t.compaction.threshold})}let a=t?.dedup?.windowMs??6e4,l=new Map,c;a>0&&(c=setInterval(()=>{let g=Date.now();for(let[x,C]of l)g-C>=a&&l.delete(x)},Math.min(a,3e4)),c&&typeof c=="object"&&"unref"in c&&c.unref());let d=!1,h=!1,T=new Set,k=new Map,E=D(0,{name:`${i}:pubCount`}),w=D(0,{name:`${i}:ver`}),b=s.lengthStore,m=K([s.latest],()=>{let g=s.latest.get();return g?yt(g):void 0},{name:`${i}:latest`}),p=t?.schema,f=t?.persistence?n?n.checkpoint(t.persistence):t.persistence:void 0,y={getOrCreateGroup(g){let x=k.get(g);return x||(x={cursor:s.tailSeq+1,roundRobinIndex:0,consumers:new Set},k.set(g,x)),x},removeGroup(g){k.delete(g)}};function _(g,x){if(h||d)return-1;p&&(g=p.parse(g));let C=x?.dedupKey;if(C){let V=Date.now(),S=l.get(C);if(S!==void 0&&V-S<a)return-1;l.set(C,V)}let O={value:g,timestamp:Date.now(),key:x?.key,priority:x?.priority,headers:x?.headers};if(x?.delay&&x.delay>0){let V=setTimeout(()=>{T.delete(V),!h&&!d&&P(()=>{s.append(O),E.update(S=>S+1),w.update(S=>S+1)})},x.delay);return T.add(V),-1}return P(()=>{let V=s.append(O);return E.update(S=>S+1),w.update(S=>S+1),V})}function R(g){let x=s.get(g);return x?yt(x):void 0}function L(g,x){return s.slice(g,x).map(yt)}let v={get id(){return i},get version(){return w.get()},get name(){return r},publish:_,get(g){return R(g)},slice(g,x){return L(g,x)},get headSeq(){return s.headSeq},get tailSeq(){return s.tailSeq},depth:b,latest:m,publishCount:E,peek(){if(s.length===0)return;let g=s.get(s.headSeq);return g?yt(g):void 0},pause(){if(!d){d=!0;for(let g of T)clearTimeout(g);T.clear(),E.signal(Se),w.signal(Se)}},resume(){d&&(d=!1,E.signal(_e),w.signal(_e))},get paused(){return d},destroy(){if(!h){h=!0;for(let g of T)clearTimeout(g);T.clear(),c&&clearInterval(c),l.clear(),u?.destroy(),P(()=>{N(E),N(w),N(m),s.destroy()}),k.clear()}}};return v[Symbol.for("callbag-recharge:topic-internal")]=y,v[Symbol.for("callbag-recharge:topic-log")]=s,v}function vn(e,t,o){let n=o?.concurrency??1,r=o?.ackTimeout??3e4,i=o?.stallInterval??5e3,s=o?.stalledJobAction??"none",u=o?.retry?.maxRetries??3,a=o?.retry?.backoff??gt(),l=D(!1,{name:`${e}:paused`}),c=!1,d=0,h=new AbortController,T=new Map,k={completed:new Set,failed:new Set,stalled:new Set},E=D(0,{name:`${e}:active`}),w=D(0,{name:`${e}:completed`}),b=D(0,{name:`${e}:failed`}),m=D(0,{name:`${e}:waiting`}),p=_n(`${e}:jobs`,o?.topicOptions),f=Tn(p,{name:`${e}:worker`,mode:"shared",initialPosition:"earliest",ackTimeout:0});function y(){let S=new AbortController;return h.signal.addEventListener("abort",()=>S.abort(),{once:!0}),S}function _(S){return{seq:S.seq,data:S.data,status:S.status,result:S.result,error:S.error,duration:S.duration,attempts:S.attempts}}function R(S,A){let M=_(A);for(let F of k[S])try{F(M)}catch{}}function L(){c||m.set(Math.max(0,f.backlog.get()))}function v(S){if(c){g(S);return}S.status="active",S.startTime=Date.now(),S.attempts++,d++,P(()=>{E.update(A=>A+1),L()}),B(G(t(S.abort.signal,S.data)),A=>{if(c){g(S);return}S.status="completed",S.result=A,S.duration=Date.now()-S.startTime,d--,f.ack(S.seq),P(()=>{E.update(M=>Math.max(0,M-1)),w.update(M=>M+1),L()}),R("completed",S),g(S)},{onEnd:A=>{if(A!==void 0){if(c){g(S);return}if(S.duration=Date.now()-S.startTime,d--,P(()=>{E.update(M=>Math.max(0,M-1))}),S.attempts<u){let M=a(S.attempts-1,A,void 0);if(M===null){x(S,A),g(S);return}let F=()=>{if(l.get()){let H=Q(l,J=>{if(!J){if(H.unsubscribe(),c){g(S);return}S.abort=y(),v(S)}});return}if(c){g(S);return}S.abort=y(),v(S)};M>0?B(pt(M,S.abort.signal),()=>{F()},{onEnd:H=>{H!==void 0&&g(S)}}):F();return}x(S,A),g(S)}}})}function g(S){T.delete(S.seq),c||C()}function x(S,A){if(S.status="failed",S.error=A,f.ack(S.seq),P(()=>{b.update(M=>M+1),L()}),o?.deadLetterTopic)try{o.deadLetterTopic.publish(S.data,{headers:{"x-original-queue":e,"x-retry-count":String(S.attempts),"x-original-seq":String(S.seq)}})}catch{}R("failed",S)}function C(){if(l.get()||c)return;let S=n-d;if(S<=0)return;let A=f.pull(S);if(A.length!==0){L();for(let M of A){let F={seq:M.seq,data:M.value,status:"waiting",attempts:0,abort:y()};T.set(M.seq,F),v(F)}}}let O=Q(p.depth,()=>{!l.get()&&!c&&(L(),C())}),$=pn(i),V=Q($,()=>{if(c)return;let S=Date.now();for(let A of T.values())A.status==="active"&&A.startTime&&S-A.startTime>r&&(A.status="stalled",R("stalled",A),(s==="cancel"||s==="retry")&&(A.abort.abort(),s==="cancel"&&(A.attempts=u)))});return L(),C(),{get name(){return e},add(S,A){let M=p.publish(S,A);return L(),queueMicrotask(()=>C()),M},active:E,completed:w,failed:b,waiting:m,on(S,A){return k[S].add(A),()=>{k[S].delete(A)}},pause(){l.get()||(l.set(!0),f.pause())},resume(){l.get()&&(l.set(!1),f.resume(),C())},get isPaused(){return l.get()},destroy(){c||(c=!0,h.abort(),O.unsubscribe(),V.unsubscribe(),f.destroy(),p.destroy(),T.clear(),P(()=>{N(l),N(E),N(w),N(b),N(m)}))}}}function xn(e){let t=e.name??"toolRegistry",o=e.maxHistory??200,n=e.tools,r=!1,i=new AbortController,s=D(0,{name:`${t}.active`}),u=D([],{name:`${t}.history`}),a=D([],{name:`${t}.lastResults`}),l=new Map;for(let[m,p]of Object.entries(n))if(p.queue){let f={...p.queue};e.deadLetterTopic&&(f.deadLetterTopic=e.deadLetterTopic);let y=vn(`${t}:${m}`,(_,R)=>p.handler(_,R.args),f);l.set(m,y)}function c(m){u.update(p=>{let f=[...p,m];return f.length>o?f.slice(-o):f})}function d(m){let p=new AbortController,f=()=>p.abort();i.signal.addEventListener("abort",f,{once:!0});let y;if(m&&m>0){let _=B(pt(m,p.signal),()=>{p.signal.aborted||p.abort()},{onEnd:()=>{}});y=()=>_.unsubscribe()}return{signal:p.signal,cleanup:()=>{i.signal.removeEventListener("abort",f),y?.()}}}function h(m,p){let f=n[m.tool];if(!f){let L={id:m.id,tool:m.tool,args:m.args,error:new Error(`Unknown tool: ${m.tool}`),status:"errored",duration:0};c(L),p(L);return}let y=m.args;if(f.schema)try{y=f.schema.parse(m.args)}catch(L){let v={id:m.id,tool:m.tool,args:m.args,error:L,status:"errored",duration:0};c(v),p(v);return}s.update(L=>L+1);let _=Date.now(),R=l.get(m.tool);if(R){let L=R.add({args:y,callId:m.id}),v=R.on("completed",C=>{if(C.seq!==L)return;x();let O={id:m.id,tool:m.tool,args:m.args,result:C.result,status:"completed",duration:Date.now()-_};s.update($=>Math.max(0,$-1)),c(O),p(O)}),g=R.on("failed",C=>{if(C.seq!==L)return;x();let O={id:m.id,tool:m.tool,args:m.args,error:C.error,status:"errored",duration:Date.now()-_};s.update($=>Math.max(0,$-1)),c(O),p(O)}),x=()=>{v(),g()}}else{let{signal:L,cleanup:v}=d(f.timeout),g;try{g=f.handler(L,y)}catch(x){v();let C={id:m.id,tool:m.tool,args:m.args,error:x,status:"errored",duration:Date.now()-_};s.update(O=>Math.max(0,O-1)),c(C),p(C);return}B(G(g),x=>{v();let C=Date.now()-_,O={id:m.id,tool:m.tool,args:m.args,result:x,status:"completed",duration:C};s.update($=>Math.max(0,$-1)),c(O),p(O)},{onEnd:x=>{if(x===void 0)return;v();let C=Date.now()-_,O={id:m.id,tool:m.tool,args:m.args,error:x,status:"errored",duration:C};s.update($=>Math.max(0,$-1)),c(O),p(O)}})}}function T(m,p,f){r||h({id:f,tool:m,args:p},()=>{})}function k(m,p){if(m.length===0){let f=p!==void 0?p:[];return ie(({emit:y,complete:_})=>{y(f),_()},{_skipInspect:!0}).source}return ie(({emit:f,complete:y})=>{if(r){f(p!==void 0?p:[]),y();return}let _=[],R=m.length;for(let L of m)h(L,v=>{_.push(v),R--,R===0&&(P(()=>{a.set(_)}),f(p!==void 0?p:_),y())})},{_skipInspect:!0}).source}function E(){return Object.entries(n).map(([m,p])=>({type:"function",function:{name:m,description:p.description,...p.parameters?{parameters:p.parameters}:{}}}))}function w(m){return m in n}function b(){if(!r){r=!0,i.abort();for(let m of l.values())m.destroy();l.clear(),P(()=>{N(s),N(u),N(a)})}}return{dispatch:T,execute:k,active:s,history:u,lastResults:a,definitions:E,has:w,destroy:b}}0&&(module.exports={agentLoop,agentMemory,chatStream,checkpoint,conversationSummary,conversationThread,docIndex,embeddingIndex,fromLLM,hybridRoute,indexedDBAdapter,memoryAdapter,memoryStore,ragPipeline,systemPromptBuilder,toToolCallRequests,tokenTracker,toolCallState,toolRegistry});
|
|
46
|
+
`)},{name:o});function r(){N(n)}return Object.assign(n,{destroy:r})}function hn(e){let t=e?.name??"toolCall",o=e?.maxHistory??100,n=I("idle",{name:`${t}.status`}),r=I(void 0,{name:`${t}.toolName`}),i=I(void 0,{name:`${t}.args`}),s=I(void 0,{name:`${t}.result`}),u=I(void 0,{name:`${t}.error`}),a=I(void 0,{name:`${t}.duration`}),l=I([],{name:`${t}.history`}),c=null;function d(C,E){n.get()!=="executing"&&(r.set(C),i.set(E),s.set(void 0),u.set(void 0),a.set(void 0),n.set("pending"),c={toolName:C,args:E,status:"pending",requestedAt:Date.now()})}function y(C){if(n.get()!=="pending"||c===null)return;let E=c.args,k=c;n.set("executing"),k.status="executing";let h=Date.now(),m=()=>{c===k&&(c=null);let p={...k};l.update(f=>{let g=[...f,p];return g.length>o?g.slice(-o):g})};V(Y(C(E)),p=>{let f=Date.now()-h;s.set(p),a.set(f),n.set("completed"),k.result=p,k.status="completed",k.duration=f,m()},{onEnd:p=>{if(p===void 0)return;let f=Date.now()-h;u.set(p),a.set(f),n.set("errored"),k.error=p,k.status="errored",k.duration=f,m()}})}function b(){n.set("idle"),r.set(void 0),i.set(void 0),s.set(void 0),u.set(void 0),a.set(void 0),c=null}return{status:n,toolName:r,args:i,result:s,error:u,duration:a,request:d,execute:y,reset:b,history:l}}function yn(e,t){return ae(({emit:o})=>{let n=0,r=setInterval(()=>o(n++),e);return t?.unref&&typeof r=="object"&&"unref"in r&&r.unref(),()=>clearInterval(r)})}function pt(e,t){return(o,n)=>{if(o!==0)return;let r=!1;function i(){r||(r=!0,clearTimeout(u),t?.removeEventListener("abort",s),n(1,void 0),n(2))}function s(){r||(r=!0,clearTimeout(u),t?.removeEventListener("abort",s),n(2,t.reason))}if(n(0,a=>{a===2&&!r&&(r=!0,clearTimeout(u),t?.removeEventListener("abort",s))}),t?.aborted){s();return}let u=setTimeout(i,e);t?.addEventListener("abort",s,{once:!0})}}function gt(e){let t=e?.base??100,o=e?.factor??2,n=e?.maxDelay??3e4,r=e?.jitter??"none";return i=>{let s=Math.min(t*o**i,n);return mr(s,r)}}function mr(e,t){switch(t){case"none":return e;case"full":return bn(0,e);case"equal":return e/2+bn(0,e/2)}}function bn(e,t){return e+Math.random()*(t-e)}function Tn(e,t,o){let n,r=[],i=!1,s=new Ie(e.length),u=!1;function a(){i||(n&&n(),n=t())}let l=0;function c(y){if(!i){if(y===ge){for(let b of r)b(H,ge);r.length=0,i=!0,n&&n(),n=void 0;return}y===he&&(l++,s.reset(),u=!1,a());for(let b of r)b(H,y)}}we(),a();for(let y=0;y<e.length&&!i;y++){let b=y,C=l;e[b].source(K,(E,k)=>{if(E===K){r.push(k),e.length===1&&k(H,Te);return}if(!i){if(E===H){if(Ee(k)){c(k),C=l;return}if(C!==l)return;k===Z?(s.empty()&&(u=!1),s.set(b)):k===re&&s.test(b)&&(s.clear(b),s.empty()&&u&&a())}if(E===ee){if(C!==l)return;s.test(b)?(s.clear(b),u=!0,s.empty()&&a()):s.empty()?a():u=!0}if(E===U){i=!0,n&&n(),n=void 0;for(let h of r)h(U);r.length=0}}})}ke();let d=()=>{if(!i){i=!0,n&&n(),n=void 0;for(let y of r)y(U);r.length=0}};d.signal=y=>c(y),se.register(d,{kind:"effect",...o,deps:e});for(let y of e)se.registerEdge(y,d);return d}function pr(e){return e!=null&&typeof e.subscribe=="function"}function Mt(e){return pr(e)?ae(({emit:t,complete:o,error:n})=>{let r=!1,i=e.subscribe({next:s=>{r||t(s)},error:s=>{r||n(s)},complete:()=>{r||o()}});return()=>{r=!0,i.unsubscribe()}}):ae(({emit:t,complete:o,error:n})=>{let r=V(Y(e),i=>t(i),{onEnd:i=>i!==void 0?n(i):o()});return()=>r.unsubscribe()},{resubscribable:!0})}var gr=Symbol.for("callbag-recharge:topic-internal"),hr=Symbol.for("callbag-recharge:topic-log"),yr=0;function Sn(e){return{seq:e.seq,value:e.value.value,timestamp:e.value.timestamp,key:e.value.key,priority:e.value.priority,headers:e.value.headers}}function _n(e,t){let o=`sub-${++yr}`,n=t?.name??o,r=t?.mode??"exclusive",i=t?.batchSize??1,s=t?.ackTimeout??3e4,u=e[gr],a=e[hr],l,c=r==="shared"||r==="failover"||r==="key_shared",d;c?(d=u.getOrCreateGroup(n),d.consumers.add(o),d.consumers.size===1&&(d.cursor=y()),l=d.cursor):l=y();function y(){return t?.initialPosition==="earliest"?a.headSeq>0?a.headSeq:1:typeof t?.initialPosition=="number"?t.initialPosition:a.tailSeq+1}let b=new Map,C=new Map,E=[],k=t?.retry?.maxRetries??3,h=t?.retry?.backoff??gt(),m=t?.deadLetterTopic,p=!1,f=!1,g=I(l,{name:`${n}:pos`}),S=I(0,{name:`${n}:pending`}),R=Q([a.lengthStore,a.events,g],()=>{let P=a.tailSeq,F=g.get(),j=a.headSeq,G=j>0?Math.max(F,j):F;return Math.max(0,P-G+1)},{name:`${n}:backlog`}),D=Q([R,a.events,g],()=>{if(R.get()<=0)return 0;let F=g.get(),j=a.headSeq,G=j>0?Math.max(F,j):F,le=a.get(G);return le?Math.max(0,Date.now()-le.value.timestamp):0},{name:`${n}:lag`}),x=t?.persistence;function T(){if(!x)return;let P=Mt(x.save(`${n}:cursor`,l)),F=X(P,()=>{});setTimeout(()=>F.unsubscribe(),0)}function L(){return r!=="failover"||!d?!0:d.consumers.values().next().value===o}function A(P){let F=0;for(let j=0;j<P.length;j++)F=(F<<5)-F+P.charCodeAt(j)|0;return Math.abs(F)}function M(P){if(r!=="key_shared"||!d||!P)return!0;let F=Array.from(d.consumers),j=A(P)%F.length;return F[j]===o}function O(P){if(p||f)return[];if(!L())return[];let F=P??i,j=[],G=a.headSeq;G>0&&l<G&&(l=G,c&&d&&(d.cursor=Math.max(d.cursor,G)));let le=Date.now(),ie=[],Ct=[];for(let fe of E)fe.readyAt<=le&&ie.length<F?ie.push(fe):Ct.push(fe);E.length=0,E.push(...Ct);for(let fe of ie){let je=a.get(fe.seq);if(je){let Ue=Sn(je);j.push(Ue),B(fe.seq)}}let Lt=F-j.length,ze=-1;if(Lt>0){let fe=c&&d?d.cursor:l,je=a.tailSeq,Ue=0;for(let pe=fe;pe<=je&&Ue<Lt;pe++){let bt=a.get(pe);if(!bt||r==="key_shared"&&!M(bt.value.key))continue;if(r==="shared"&&d&&d.consumers.size>1){let Dt=Array.from(d.consumers),kn=d.roundRobinIndex%Dt.length;if(Dt[kn]!==o)continue;d.roundRobinIndex++}let wn=Sn(bt);j.push(wn),B(pe),pe>ze&&(ze=pe),Ue++}if(ze>=0){let pe=ze+1;c&&d&&(d.cursor=Math.max(d.cursor,pe)),l=c&&d?d.cursor:pe}}return j.length>0&&$(()=>{g.set(l),S.update(fe=>fe+j.length)}),j}function B(P){let F;s>0&&(F=setTimeout(()=>{b.has(P)&&w(P)},s)),b.set(P,{timer:F})}function _(P){let F=b.get(P);F&&(F.timer&&clearTimeout(F.timer),b.delete(P),C.delete(P),S.update(j=>Math.max(0,j-1)),T())}function v(P,F){if(m){let j=a.get(P);j&&m.publish(j.value.value,{key:j.value.key,headers:{...j.value.headers,"x-original-topic":e.name,"x-retry-count":String(F),"x-original-seq":String(P)}})}C.delete(P)}function w(P){let F=b.get(P);if(!F)return;F.timer&&clearTimeout(F.timer),b.delete(P),S.update(ie=>Math.max(0,ie-1));let j=C.get(P)??{attempts:0},G=j.attempts+1;if(G>k){v(P,G);return}let le=h(G-1,void 0,j.prevDelay);if(le===null){v(P,G);return}C.set(P,{attempts:G,prevDelay:le}),E.push({seq:P,readyAt:Date.now()+le})}function q(P){if(f)return;let F;P==="earliest"?F=a.headSeq>0?a.headSeq:1:P==="latest"?F=a.tailSeq+1:F=P,l=F,c&&d&&(d.cursor=F),g.set(F);for(let j of b.values())j.timer&&clearTimeout(j.timer);b.clear(),S.set(0),E.length=0,C.clear(),T()}let J,W;if(x){let P=Mt(x.load(`${n}:cursor`));W=P,J=Tn([P],()=>{let F=P.get();typeof F=="number"&&q(F)})}function z(){if(!f){f=!0,J?.(),W&&N(W);for(let P of b.values())P.timer&&clearTimeout(P.timer);b.clear(),E.length=0,C.clear(),d&&(d.consumers.delete(o),d.consumers.size===0&&u.removeGroup(n)),$(()=>{N(g),N(S),N(R),N(D)})}}return{get name(){return n},get mode(){return r},pull:O,ack:_,nack:w,seek:q,position:g,backlog:R,pending:S,lag:D,pause(){p||(p=!0,g.signal(Se),S.signal(Se))},resume(){p&&(p=!1,g.signal(_e),S.signal(_e))},get isPaused(){return p},destroy:z}}function vn(e,t,o){let n=o?.threshold??0,r=null,i=!1;function s(){if(i)return 0;let u=e.toArray();if(u.length===0)return 0;let a=new Map,l=[];for(let y of u){let b=t(y.value);a.has(b)||l.push(b),a.set(b,y.value)}let c=l.map(y=>a.get(y)),d=u.length-c.length;if(d===0)return 0;i=!0;try{e.clear(),e.appendMany(c)}finally{i=!1}return d}return n>0&&(r=X(e.events,u=>{u?.type==="append"&&e.length>=n&&s()})),{compact:s,destroy(){r?.unsubscribe(),r=null}}}var br=0;ht.from=function(t,o){let n=ht({...o,id:t.id});for(let r of t.entries)n.append(r.value);return n};function ht(e){let t=++br,o=e?.id??`rlog-${t}`,n=e?.maxSize??0,r=n>0,i=[],s=0,u=0,a=0,l=1,c=I(0,{name:`${o}:ver`}),d=I(void 0,{name:`${o}:events`,equals:()=>!1}),y=new Map,b=!1;function C(){if(!r)return i.slice();if(u===0)return[];let h=new Array(u);for(let m=0;m<u;m++)h[m]=i[(s+m)%n];return h}function E(h){if(!r)return i[h];if(!(h<0||h>=u))return i[(s+h)%n]}let k={get id(){return o},get version(){return c.get()},append(h){if(b)return-1;let m=++a,p={seq:m,value:h};return r?(u<n?(i[(s+u)%n]=p,u++):(i[s]=p,s=(s+1)%n),l=a-u+1):(i.push(p),l=i.length>0?i[0].seq:1),c.update(f=>f+1),d.set({type:"append",seq:m,value:h}),m},appendMany(h){if(b||h.length===0)return[];let m=[];return $(()=>{for(let p of h)m.push(k.append(p))}),m},get(h){if(r)return h<l||h>a||u===0?void 0:E(h-l);let m=h-l;if(!(m<0||m>=i.length))return i[m]},slice(h,m){let p=h??l,f=m??a;if((r?u:i.length)===0)return[];let S=Math.max(p,l),R=Math.min(f,a);if(S>R)return[];let D=S-l,x=R-l;if(!r)return i.slice(D,x+1);let T=[];for(let L=D;L<=x;L++)T.push(i[(s+L)%n]);return T},toArray(){return C()},get length(){return r?u:i.length},get headSeq(){return(r?u:i.length)>0?l:0},get tailSeq(){return a},trimHead(h){let m=r?u:i.length;if(m===0||h<=0)return 0;let p=Math.min(h,m);return $(()=>{r?(s=(s+p)%n,u-=p):i.splice(0,p),l+=p,c.update(f=>f+1),d.set({type:"trim"})}),p},clear(){(r?u:i.length)!==0&&$(()=>{r?(u=0,s=0):i.length=0,l=a+1,c.update(m=>m+1),d.set({type:"clear"})})},lengthStore:Q([c],()=>r?u:i.length,{name:`${o}:length`}),latest:Q([c],()=>{if((r?u:i.length)!==0)return r?i[(s+u-1)%n]:i[i.length-1]},{name:`${o}:latest`}),tail(h){let m=y.get(h);return m||(m=Q([c],()=>{let p=C();return h===void 0||h>=p.length?p:p.slice(-h)},{name:`${o}:tail${h??""}`}),y.set(h,m),m)},events:d,snapshot(){return{type:"reactiveLog",id:o,version:c.get(),entries:C().map(h=>({seq:h.seq,value:h.value})),headSeq:(r?u:i.length)>0?l:0,tailSeq:a}},destroy(){b||(b=!0,$(()=>{for(let h of y.values())N(h);y.clear(),N(k.lengthStore),N(k.latest),N(d),N(c),i.length=0,u=0}))}};return k}var Tr=0;function yt(e){return{seq:e.seq,value:e.value.value,timestamp:e.value.timestamp,key:e.value.key,priority:e.value.priority,headers:e.value.headers}}function xn(e,t){let o=++Tr,n=t?.namespace,r=n?n.prefix(e):e,i=`topic-${r}-${o}`,s=ht({id:`${i}:log`,maxSize:t?.maxSize}),u;if(t?.compaction){let A=t.compaction.keyFn;u=vn(s,M=>A(M.value),{threshold:t.compaction.threshold})}let a=t?.dedup?.windowMs??6e4,l=new Map,c;a>0&&(c=setInterval(()=>{let A=Date.now();for(let[M,O]of l)A-O>=a&&l.delete(M)},Math.min(a,3e4)),c&&typeof c=="object"&&"unref"in c&&c.unref());let d=t?.ttl??0;function y(){if(d<=0||s.length===0)return 0;let A=Date.now()-d,M=0,O=s.toArray();for(let B of O)if(B.value.timestamp<A)M++;else break;return M>0&&s.trimHead(M),M}let b=!1,C=!1,E=new Set,k=new Map,h=I(0,{name:`${i}:pubCount`}),m=I(0,{name:`${i}:ver`}),p=s.lengthStore,f=Q([s.latest],()=>{let A=s.latest.get();return A?yt(A):void 0},{name:`${i}:latest`}),g=t?.schema,S=t?.persistence?n?n.checkpoint(t.persistence):t.persistence:void 0,R={getOrCreateGroup(A){let M=k.get(A);return M||(M={cursor:s.tailSeq+1,roundRobinIndex:0,consumers:new Set},k.set(A,M)),M},removeGroup(A){k.delete(A)}};function D(A,M){if(C||b)return-1;d>0&&y(),g&&(A=g.parse(A));let O=M?.dedupKey;if(O){let v=Date.now(),w=l.get(O);if(w!==void 0&&v-w<a)return-1;l.set(O,v)}let B={value:A,timestamp:Date.now(),key:M?.key,priority:M?.priority,headers:M?.headers};if(M?.delay&&M.delay>0){let v=setTimeout(()=>{E.delete(v),!C&&!b&&$(()=>{s.append(B),h.update(w=>w+1),m.update(w=>w+1)})},M.delay);return E.add(v),-1}return $(()=>{let v=s.append(B);return h.update(w=>w+1),m.update(w=>w+1),v})}function x(A){let M=s.get(A);return M?yt(M):void 0}function T(A,M){return s.slice(A,M).map(yt)}let L={get id(){return i},get version(){return m.get()},get name(){return r},publish:D,get(A){return x(A)},slice(A,M){return T(A,M)},get headSeq(){return s.headSeq},get tailSeq(){return s.tailSeq},depth:p,latest:f,publishCount:h,peek(){if(s.length===0)return;let A=s.get(s.headSeq);return A?yt(A):void 0},expireMessages(){return y()},pause(){if(!b){b=!0;for(let A of E)clearTimeout(A);E.clear(),h.signal(Se),m.signal(Se)}},resume(){b&&(b=!1,h.signal(_e),m.signal(_e))},get paused(){return b},destroy(){if(!C){C=!0;for(let A of E)clearTimeout(A);E.clear(),c&&clearInterval(c),l.clear(),u?.destroy(),$(()=>{N(h),N(m),N(f),s.destroy()}),k.clear()}}};return L[Symbol.for("callbag-recharge:topic-internal")]=R,L[Symbol.for("callbag-recharge:topic-log")]=s,L}function An(e,t,o){let n=o?.concurrency??1,r=o?.ackTimeout??3e4,i=o?.stallInterval??5e3,s=o?.stalledJobAction??"none",u=o?.retry?.maxRetries??3,a=o?.retry?.backoff??gt(),l=I(!1,{name:`${e}:paused`}),c=!1,d=0,y=new AbortController,b=new Map,C={completed:new Set,failed:new Set,stalled:new Set},E=I(0,{name:`${e}:active`}),k=I(0,{name:`${e}:completed`}),h=I(0,{name:`${e}:failed`}),m=I(0,{name:`${e}:waiting`}),p=xn(`${e}:jobs`,o?.topicOptions),f=_n(p,{name:`${e}:worker`,mode:"shared",initialPosition:"earliest",ackTimeout:0});function g(){let _=new AbortController;return y.signal.addEventListener("abort",()=>_.abort(),{once:!0}),_}function S(_){return{seq:_.seq,data:_.data,status:_.status,result:_.result,error:_.error,duration:_.duration,attempts:_.attempts}}function R(_,v){let w=S(v);for(let q of C[_])try{q(w)}catch{}}function D(){c||m.set(Math.max(0,f.backlog.get()))}function x(_){if(c){T(_);return}_.status="active",_.startTime=Date.now(),_.attempts++,d++,$(()=>{E.update(v=>v+1),D()}),V(Y(t(_.abort.signal,_.data)),v=>{if(c){T(_);return}_.status="completed",_.result=v,_.duration=Date.now()-_.startTime,d--,f.ack(_.seq),$(()=>{E.update(w=>Math.max(0,w-1)),k.update(w=>w+1),D()}),R("completed",_),T(_)},{onEnd:v=>{if(v!==void 0){if(c){T(_);return}if(_.duration=Date.now()-_.startTime,d--,$(()=>{E.update(w=>Math.max(0,w-1))}),_.attempts<u){let w=a(_.attempts-1,v,void 0);if(w===null){L(_,v),T(_);return}let q=()=>{if(l.get()){let J=X(l,W=>{if(!W){if(J.unsubscribe(),c){T(_);return}_.abort=g(),x(_)}});return}if(c){T(_);return}_.abort=g(),x(_)};w>0?V(pt(w,_.abort.signal),()=>{q()},{onEnd:J=>{J!==void 0&&T(_)}}):q();return}L(_,v),T(_)}}})}function T(_){b.delete(_.seq),c||A()}function L(_,v){if(_.status="failed",_.error=v,f.ack(_.seq),$(()=>{h.update(w=>w+1),D()}),o?.deadLetterTopic)try{o.deadLetterTopic.publish(_.data,{headers:{"x-original-queue":e,"x-retry-count":String(_.attempts),"x-original-seq":String(_.seq)}})}catch{}R("failed",_)}function A(){if(l.get()||c)return;let _=n-d;if(_<=0)return;let v=f.pull(_);if(v.length!==0){D();for(let w of v){let q={seq:w.seq,data:w.value,status:"waiting",attempts:0,abort:g()};b.set(w.seq,q),x(q)}}}let M=X(p.depth,()=>{!l.get()&&!c&&(D(),A())}),O=yn(i),B=X(O,()=>{if(c)return;let _=Date.now();for(let v of b.values())v.status==="active"&&v.startTime&&_-v.startTime>r&&(v.status="stalled",R("stalled",v),(s==="cancel"||s==="retry")&&(v.abort.abort(),s==="cancel"&&(v.attempts=u)))});return D(),A(),{get name(){return e},add(_,v){let w=p.publish(_,v);return D(),queueMicrotask(()=>A()),w},active:E,completed:k,failed:h,waiting:m,on(_,v){return C[_].add(v),()=>{C[_].delete(v)}},pause(){l.get()||(l.set(!0),f.pause())},resume(){l.get()&&(l.set(!1),f.resume(),A())},get isPaused(){return l.get()},destroy(){c||(c=!0,y.abort(),M.unsubscribe(),B.unsubscribe(),f.destroy(),p.destroy(),b.clear(),$(()=>{N(l),N(E),N(k),N(h),N(m)}))}}}function En(e){let t=e.name??"toolRegistry",o=e.maxHistory??200,n=e.tools,r=!1,i=new AbortController,s=I(0,{name:`${t}.active`}),u=I([],{name:`${t}.history`}),a=I([],{name:`${t}.lastResults`}),l=new Map;for(let[m,p]of Object.entries(n))if(p.queue){let f={...p.queue};e.deadLetterTopic&&(f.deadLetterTopic=e.deadLetterTopic);let g=An(`${t}:${m}`,(S,R)=>p.handler(S,R.args),f);l.set(m,g)}function c(m){u.update(p=>{let f=[...p,m];return f.length>o?f.slice(-o):f})}function d(m){let p=new AbortController,f=()=>p.abort();i.signal.addEventListener("abort",f,{once:!0});let g;if(m&&m>0){let S=V(pt(m,p.signal),()=>{p.signal.aborted||p.abort()},{onEnd:()=>{}});g=()=>S.unsubscribe()}return{signal:p.signal,cleanup:()=>{i.signal.removeEventListener("abort",f),g?.()}}}function y(m,p){let f=n[m.tool];if(!f){let D={id:m.id,tool:m.tool,args:m.args,error:new Error(`Unknown tool: ${m.tool}`),status:"errored",duration:0};c(D),p(D);return}let g=m.args;if(f.schema)try{g=f.schema.parse(m.args)}catch(D){let x={id:m.id,tool:m.tool,args:m.args,error:D,status:"errored",duration:0};c(x),p(x);return}s.update(D=>D+1);let S=Date.now(),R=l.get(m.tool);if(R){let D=R.add({args:g,callId:m.id}),x=R.on("completed",A=>{if(A.seq!==D)return;L();let M={id:m.id,tool:m.tool,args:m.args,result:A.result,status:"completed",duration:Date.now()-S};s.update(O=>Math.max(0,O-1)),c(M),p(M)}),T=R.on("failed",A=>{if(A.seq!==D)return;L();let M={id:m.id,tool:m.tool,args:m.args,error:A.error,status:"errored",duration:Date.now()-S};s.update(O=>Math.max(0,O-1)),c(M),p(M)}),L=()=>{x(),T()}}else{let{signal:D,cleanup:x}=d(f.timeout),T;try{T=f.handler(D,g)}catch(L){x();let A={id:m.id,tool:m.tool,args:m.args,error:L,status:"errored",duration:Date.now()-S};s.update(M=>Math.max(0,M-1)),c(A),p(A);return}V(Y(T),L=>{x();let A=Date.now()-S,M={id:m.id,tool:m.tool,args:m.args,result:L,status:"completed",duration:A};s.update(O=>Math.max(0,O-1)),c(M),p(M)},{onEnd:L=>{if(L===void 0)return;x();let A=Date.now()-S,M={id:m.id,tool:m.tool,args:m.args,error:L,status:"errored",duration:A};s.update(O=>Math.max(0,O-1)),c(M),p(M)}})}}function b(m,p,f){r||y({id:f,tool:m,args:p},()=>{})}function C(m,p){if(m.length===0){let f=p!==void 0?p:[];return ae(({emit:g,complete:S})=>{g(f),S()},{_skipInspect:!0}).source}return ae(({emit:f,complete:g})=>{if(r){f(p!==void 0?p:[]),g();return}let S=[],R=m.length;for(let D of m)y(D,x=>{S.push(x),R--,R===0&&($(()=>{a.set(S)}),f(p!==void 0?p:S),g())})},{_skipInspect:!0}).source}function E(){return Object.entries(n).map(([m,p])=>({type:"function",function:{name:m,description:p.description,...p.parameters?{parameters:p.parameters}:{}}}))}function k(m){return m in n}function h(){if(!r){r=!0,i.abort();for(let m of l.values())m.destroy();l.clear(),$(()=>{N(s),N(u),N(a)})}}return{dispatch:b,execute:C,active:s,history:u,lastResults:a,definitions:E,has:k,destroy:h}}0&&(module.exports={agentLoop,agentMemory,chatStream,checkpoint,conversationSummary,conversationThread,docIndex,embeddingIndex,fromLLM,hybridRoute,indexedDBAdapter,memoryAdapter,memoryStore,ragPipeline,systemPromptBuilder,toToolCallRequests,tokenTracker,toolCallState,toolRegistry});
|
package/dist/ai/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ export { a as CheckpointMeta, b as CheckpointedStore, c as checkpoint, m as memo
|
|
|
3
3
|
export { I as IndexedDBAdapterOptions, T as TokenMeta, a as TokenTrackedStore, b as TokenUsage, i as indexedDBAdapter, t as tokenTracker } from '../tokenTracker-C1y5zB38.cjs';
|
|
4
4
|
export { AgentLoopEntry, AgentLoopOptions, AgentLoopResult, AgentLoopResultBase, AgentPhase, GatedAgentLoopResult, agentLoop } from './agentLoop/index.cjs';
|
|
5
5
|
import { S as Store } from '../types-BohB8jJr.cjs';
|
|
6
|
-
import { S as ScoreWeights, a as MemoryNode, C as Collection, V as VectorIndex } from '../types-
|
|
6
|
+
import { S as ScoreWeights, a as MemoryNode, C as Collection, V as VectorIndex } from '../types-Ba0jr02y.cjs';
|
|
7
7
|
import { LLMStore } from './fromLLM.cjs';
|
|
8
8
|
export { GenerateOptions, LLMMessage, LLMOptions, LLMRole, LLMTokenUsage, LLMToolCall, LLMToolDefinition, fromLLM, toToolCallRequests } from './fromLLM.cjs';
|
|
9
9
|
import { ChatStreamFactory, ChatStreamOptions, ChatStreamResult, ChatMessage } from './chatStream/index.cjs';
|
|
@@ -15,15 +15,15 @@ export { HybridRouteOptions, HybridRouteResult, RouteTarget, hybridRoute } from
|
|
|
15
15
|
export { MemoryStoreOptions, MemoryStoreResult, memoryStore } from './memoryStore/index.cjs';
|
|
16
16
|
export { RagDoc, RagPipelineOptions, RagPipelineResult, ragPipeline } from './ragPipeline/index.cjs';
|
|
17
17
|
export { ToolCallEntry, ToolCallStateOptions, ToolCallStateResult, ToolCallStatus, toolCallState } from './toolCallState/index.cjs';
|
|
18
|
-
import { J as JobQueueOptions, T as Topic } from '../types-
|
|
18
|
+
import { J as JobQueueOptions, T as Topic } from '../types-ibw_KZuI.cjs';
|
|
19
19
|
import { C as CallbagSource } from '../subscribe-BHH8VVDm.cjs';
|
|
20
20
|
import '../gate-mtVc8Lmp.cjs';
|
|
21
21
|
import '../protocol-fwiQ1TAS.cjs';
|
|
22
|
-
import '../types-
|
|
22
|
+
import '../types-DYpaJ7gP.cjs';
|
|
23
23
|
import '../eviction-DGPP1vHP.cjs';
|
|
24
24
|
import '../withStatus-ByT_R2Rz.cjs';
|
|
25
25
|
import '../rateLimiter-C9FDu1n0.cjs';
|
|
26
|
-
import '../backoff-
|
|
26
|
+
import '../backoff-DTxCwT6Y.cjs';
|
|
27
27
|
|
|
28
28
|
/** Scope for user/agent isolation. Maps to tag-based namespace prefixes. */
|
|
29
29
|
interface AgentMemoryScope {
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { a as CheckpointMeta, b as CheckpointedStore, c as checkpoint, m as memo
|
|
|
3
3
|
export { I as IndexedDBAdapterOptions, T as TokenMeta, a as TokenTrackedStore, b as TokenUsage, i as indexedDBAdapter, t as tokenTracker } from '../tokenTracker-BRFP4C1K.js';
|
|
4
4
|
export { AgentLoopEntry, AgentLoopOptions, AgentLoopResult, AgentLoopResultBase, AgentPhase, GatedAgentLoopResult, agentLoop } from './agentLoop/index.js';
|
|
5
5
|
import { S as Store } from '../types-CB1htCM8.js';
|
|
6
|
-
import { S as ScoreWeights, a as MemoryNode, C as Collection, V as VectorIndex } from '../types-
|
|
6
|
+
import { S as ScoreWeights, a as MemoryNode, C as Collection, V as VectorIndex } from '../types-ClFiOUXg.js';
|
|
7
7
|
import { LLMStore } from './fromLLM.js';
|
|
8
8
|
export { GenerateOptions, LLMMessage, LLMOptions, LLMRole, LLMTokenUsage, LLMToolCall, LLMToolDefinition, fromLLM, toToolCallRequests } from './fromLLM.js';
|
|
9
9
|
import { ChatStreamFactory, ChatStreamOptions, ChatStreamResult, ChatMessage } from './chatStream/index.js';
|
|
@@ -15,15 +15,15 @@ export { HybridRouteOptions, HybridRouteResult, RouteTarget, hybridRoute } from
|
|
|
15
15
|
export { MemoryStoreOptions, MemoryStoreResult, memoryStore } from './memoryStore/index.js';
|
|
16
16
|
export { RagDoc, RagPipelineOptions, RagPipelineResult, ragPipeline } from './ragPipeline/index.js';
|
|
17
17
|
export { ToolCallEntry, ToolCallStateOptions, ToolCallStateResult, ToolCallStatus, toolCallState } from './toolCallState/index.js';
|
|
18
|
-
import { J as JobQueueOptions, T as Topic } from '../types-
|
|
18
|
+
import { J as JobQueueOptions, T as Topic } from '../types-kdj4VxGp.js';
|
|
19
19
|
import { C as CallbagSource } from '../subscribe-BHH8VVDm.js';
|
|
20
20
|
import '../gate-DyykYri7.js';
|
|
21
21
|
import '../protocol-fwiQ1TAS.js';
|
|
22
|
-
import '../types-
|
|
22
|
+
import '../types-kbaGU2yR.js';
|
|
23
23
|
import '../eviction-DGPP1vHP.js';
|
|
24
24
|
import '../withStatus---CFNir7.js';
|
|
25
25
|
import '../rateLimiter-nMWFRXZi.js';
|
|
26
|
-
import '../backoff-
|
|
26
|
+
import '../backoff-DTxCwT6Y.js';
|
|
27
27
|
|
|
28
28
|
/** Scope for user/agent isolation. Maps to tag-based namespace prefixes. */
|
|
29
29
|
interface AgentMemoryScope {
|
package/dist/ai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ht}from"../chunk-S67PXKAL.js";import{a as xt}from"../chunk-VHVYJSLE.js";import{a as it,b as ct,d as lt,e as ut}from"../chunk-XD4BHZSL.js";import{a as dt}from"../chunk-LMR6RVT4.js";import{a as N}from"../chunk-4PAUY5AJ.js";import{a as mt}from"../chunk-6SUM4DCC.js";import{a as pt}from"../chunk-DTTBQCH3.js";import{a as ft}from"../chunk-X2LL44CL.js";import"../chunk-F7IHZH7D.js";import{a as gt}from"../chunk-QWMRZMRN.js";import{a as yt}from"../chunk-Z6NJHBGT.js";import{a as X}from"../chunk-OZKWHUA6.js";import{d as Y}from"../chunk-Y72LPOTS.js";import"../chunk-JCENQEPP.js";import{c as W}from"../chunk-
|
|
1
|
+
import{a as ht}from"../chunk-S67PXKAL.js";import{a as xt}from"../chunk-VHVYJSLE.js";import{a as it,b as ct,d as lt,e as ut}from"../chunk-XD4BHZSL.js";import{a as dt}from"../chunk-LMR6RVT4.js";import{a as N}from"../chunk-4PAUY5AJ.js";import{a as mt}from"../chunk-6SUM4DCC.js";import{a as pt}from"../chunk-DTTBQCH3.js";import{a as ft}from"../chunk-X2LL44CL.js";import"../chunk-F7IHZH7D.js";import{a as gt}from"../chunk-QWMRZMRN.js";import{a as yt}from"../chunk-Z6NJHBGT.js";import{a as X}from"../chunk-OZKWHUA6.js";import{d as Y}from"../chunk-Y72LPOTS.js";import"../chunk-JCENQEPP.js";import{c as W}from"../chunk-ULLWFMTO.js";import"../chunk-2BP7Z7ZL.js";import{a as K}from"../chunk-RAMDA42C.js";import"../chunk-AA2V6B63.js";import"../chunk-FJMF46AF.js";import"../chunk-JW2KZLSD.js";import"../chunk-ZJCF5NYF.js";import"../chunk-D3D4V5KM.js";import"../chunk-XFA2D6KP.js";import"../chunk-2ZFSL4MA.js";import{a as G}from"../chunk-PV347CGV.js";import"../chunk-HK7DRUNM.js";import{a as z}from"../chunk-GMLWTZFM.js";import{a as st,b as at}from"../chunk-QAHR7EMX.js";import{a as B}from"../chunk-O2PONDZT.js";import"../chunk-J2E7GAMR.js";import{a as D}from"../chunk-4ILN4V4C.js";import"../chunk-Q3HIBGHR.js";import{a as I}from"../chunk-EAK2HKAD.js";import{i as J}from"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.js";import{B as F,v as E}from"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";function Z(t,e,a){if(t.size.get()===0)return{isDuplicate:!1,similarity:0};let u=t.search(e,1);if(u.length===0)return{isDuplicate:!1,similarity:0};let r=u[0],s=1-r.distance;return s>=a?{isDuplicate:!0,existingId:r.id,similarity:s}:{isDuplicate:!1,similarity:s}}var Tt=`You are a memory extraction system. Given a conversation, extract discrete factual statements worth remembering for future conversations.
|
|
2
2
|
|
|
3
3
|
Output ONLY a JSON array. Each element has:
|
|
4
4
|
- "content": concise factual statement (1-2 sentences)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as Store } from '../../types-BohB8jJr.cjs';
|
|
2
|
-
import { S as ScoreWeights, M as MemoryNodeOptions, a as MemoryNode } from '../../types-
|
|
2
|
+
import { S as ScoreWeights, M as MemoryNodeOptions, a as MemoryNode } from '../../types-Ba0jr02y.cjs';
|
|
3
3
|
import '../../protocol-fwiQ1TAS.cjs';
|
|
4
|
-
import '../../types-
|
|
4
|
+
import '../../types-DYpaJ7gP.cjs';
|
|
5
5
|
import '../../eviction-DGPP1vHP.cjs';
|
|
6
6
|
|
|
7
7
|
interface MemoryStoreOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as Store } from '../../types-CB1htCM8.js';
|
|
2
|
-
import { S as ScoreWeights, M as MemoryNodeOptions, a as MemoryNode } from '../../types-
|
|
2
|
+
import { S as ScoreWeights, M as MemoryNodeOptions, a as MemoryNode } from '../../types-ClFiOUXg.js';
|
|
3
3
|
import '../../protocol-fwiQ1TAS.js';
|
|
4
|
-
import '../../types-
|
|
4
|
+
import '../../types-kbaGU2yR.js';
|
|
5
5
|
import '../../eviction-DGPP1vHP.js';
|
|
6
6
|
|
|
7
7
|
interface MemoryStoreOptions {
|