@callbag-recharge/callbag-recharge 0.16.0 → 0.17.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.
Files changed (40) hide show
  1. package/dist/adapters/index.cjs +11 -11
  2. package/dist/adapters/index.js +1 -1
  3. package/dist/adapters/sse.cjs +8 -8
  4. package/dist/adapters/sse.js +1 -1
  5. package/dist/adapters/webhook.cjs +4 -4
  6. package/dist/adapters/webhook.js +1 -1
  7. package/dist/chunk-4AGPQIMR.js +1 -0
  8. package/dist/chunk-JEZ26E63.js +1 -0
  9. package/dist/chunk-LLARZ7J7.js +1 -0
  10. package/dist/chunk-N7Y355ED.js +1 -0
  11. package/dist/chunk-PQPV3OXB.js +1 -0
  12. package/dist/chunk-QSFTSBDR.js +1 -0
  13. package/dist/chunk-VN3XFROF.js +11 -0
  14. package/dist/chunk-XEU7KSEO.js +1 -0
  15. package/dist/extra/index.cjs +4 -4
  16. package/dist/extra/index.d.cts +37 -1
  17. package/dist/extra/index.d.ts +37 -1
  18. package/dist/extra/index.js +1 -1
  19. package/dist/extra/interval.cjs +4 -4
  20. package/dist/extra/interval.d.cts +7 -2
  21. package/dist/extra/interval.d.ts +7 -2
  22. package/dist/extra/interval.js +1 -1
  23. package/dist/extra/subscribe.d.cts +5 -4
  24. package/dist/extra/subscribe.d.ts +5 -4
  25. package/dist/messaging/index.cjs +6 -6
  26. package/dist/messaging/index.d.cts +1 -1
  27. package/dist/messaging/index.d.ts +1 -1
  28. package/dist/messaging/index.js +3 -3
  29. package/dist/orchestrate/index.cjs +8 -8
  30. package/dist/orchestrate/index.js +5 -5
  31. package/dist/utils/index.cjs +4 -4
  32. package/dist/utils/index.d.cts +48 -1
  33. package/dist/utils/index.d.ts +48 -1
  34. package/dist/utils/index.js +1 -1
  35. package/package.json +1 -1
  36. package/dist/chunk-BR63MTNP.js +0 -1
  37. package/dist/chunk-EXDWEL6X.js +0 -11
  38. package/dist/chunk-GO4JTIJI.js +0 -1
  39. package/dist/chunk-T2RGZ54Y.js +0 -1
  40. package/dist/chunk-UA3L7KUP.js +0 -1
@@ -1,16 +1,16 @@
1
- "use strict";var Ne=Object.create;var re=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty;var qe=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},he=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ue(t))!Fe.call(e,o)&&o!==n&&re(e,o,{get:()=>t[o],enumerable:!(r=je(t,o))||r.enumerable});return e};var Be=(e,t,n)=>(n=e!=null?Ne(He(e)):{},he(t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n,e)),Ke=e=>he(re({},"__esModule",{value:!0}),e);var rt={};qe(rt,{fromHTTP:()=>Ce,fromLLM:()=>Ae,fromMCP:()=>Oe,fromWebSocket:()=>We,fromWebhook:()=>$e,toSSE:()=>Me,toWebSocket:()=>Ie});module.exports=Ke(rt);var N=Symbol("DIRTY"),Z=Symbol("RESOLVED"),Se=Symbol("SINGLE_DEP"),j=Symbol("RESET"),K=Symbol("PAUSE"),z=Symbol("RESUME"),pe=Symbol("TEARDOWN");function Te(e){return e===j||e===K||e===z||e===pe}var ye=0,be=1,_e=2,ke=3,ve=4,Ee=5,F=7,ge=7<<F,ze=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function we(e){return ze[(e&ge)>>>F]}var P=0,U=1,R=2,$=3,oe=0,se=[],de=!1;function C(e){oe++;try{return e()}finally{if(oe--,oe===0&&!de){de=!0;for(let t=0;t<se.length;t++)se[t]();se.length=0,de=!1}}}function le(){return oe>0}function ue(e){se.push(e)}var ae=0,ie=[];function xe(){ae++}function Re(){if(ae--,ae===0){for(let e=0;e<ie.length;e++)ie[e]();ie.length=0}}function Le(e){ae>0?ie.push(e):e()}var A=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 r=t.map(o=>e._names.get(o)??"?").join(",");return r.length>40?`${r.slice(0,37)}...`:r}static _resolveKey(t){let n=e._keys.get(t)??e._names.get(t);if(n)return n;let r=`anonymous_${e._nextId++}`;return e._keys.set(t,r),r}static register(t,n){if(!e.enabled)return;n?.name&&e._names.set(t,n.name),n?.kind&&e._kinds.set(t,n.kind);let r=e._nextId++,o=n?.name;if(!(o&&!e._usedKeys.has(o)))if(o){let a=e._depSuffix(n?.deps);o=a?`${o}(${a})`:`${o}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}else{let a=n?.kind??"store",l=e._depSuffix(n?.deps);o=l?`${a}(${l})`:`${a}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}e._usedKeys.add(o),e._keys.set(t,o),e._stores.add(new WeakRef(t))}static registerEdge(t,n){if(!e.enabled)return;let r=e._resolveKey(t),o=e._resolveKey(n),a=e._edges.get(r);a?a.includes(o)||a.push(o):e._edges.set(r,[o])}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,n=new Set;for(let r of e._stores){let o=r.deref();if(!o){e._stores.delete(r);continue}let a=e._resolveKey(o);n.add(a),t.set(a,e.inspect(o))}for(let[r,o]of e._edges){if(!n.has(r)){e._edges.delete(r),e._usedKeys.delete(r);continue}let a=o.filter(l=>n.has(l));a.length===0?e._edges.delete(r):a.length!==o.length&&e._edges.set(r,a)}return t}static trace(t,n){let r=null,o=t.get();return t.source(P,(a,l)=>{if(a===P&&(r=l),a===R){r=null;return}if(a===1){let i=l;if(!Object.is(i,o)){let c=o;o=i,n(i,c)}}}),()=>r?.(R)}static dumpGraph(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let[l,i]of n)for(let c of i){let f=r.get(c);f?f.includes(l)||f.push(l):r.set(c,[l])}let o=[];for(let[l,i]of t){let c=r.get(l),f=n.get(l),s=c?.length?` \u2190 [${c.join(", ")}]`:"",u=f?.length?` \u2192 [${f.join(", ")}]`:"";o.push(` ${l} (${i.kind}) = ${JSON.stringify(i.value)} [${i.status??"?"}]${s}${u}`)}return[`Store Graph (${t.size} nodes):`,...o].join(`
2
- `)}static _signalLabel(t){return t===N?"DIRTY":t===Z?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,n,r){let o=null,a=!1,l=n??e.getName(t),i=[],c={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return c.ended&&!a},get errored(){return c.ended&&a},dirtyCount:0,resolvedCount:0,name:l,get eventLog(){return i},dispose:()=>o?.(R),reconnect:()=>(o?.(R),e._observe(t,n,r))};return t.source(P,(f,s)=>{if(f===P){o=s;return}f===U?(c.values.push(s),c.events.push({type:"data",data:s}),i.push(s),r&&r(`[${l}] DATA:`,s)):f===$?(c.signals.push(s),c.events.push({type:"signal",data:s}),i.push(e._signalLabel(s)),s===N?c.dirtyCount++:s===Z&&c.resolvedCount++,r&&r(`[${l}] STATE:`,s)):f===R&&(c.ended=!0,c.endError=s,a=s!==void 0,c.events.push({type:"end",data:s}),i.push(a?["END",s]:"END"),r&&r(`[${l}] END`,s!==void 0?s:""),o=null)}),c}static observe(t){return e._observe(t)}static activate(t){let n=null;return t.source(P,(r,o)=>{r===P&&(n=o),r===R&&(n=null)}),()=>n?.(R)}static tap(t,n){let r=n??`tap(${e.getName(t)??"anon"})`,o={get:()=>t.get(),source:t.source};return e.register(o,{name:r,kind:"tap"}),e.registerEdge(t,o),o}static spy(t,n){let r=n?.name??e.getName(t)??"spy",o=n?.log??console.log;return e._observe(t,r,o)}static snapshot(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let l of e._stores){let i=l.deref();if(!i)continue;let c=e._annotations.get(i);c!==void 0&&r.set(e._resolveKey(i),c)}let o=[];for(let[l,i]of t){let c={name:l,kind:i.kind,value:i.value,status:i.status},f=r.get(l);f!==void 0&&(c.annotation=f),o.push(c)}let a=[];for(let[l,i]of n)for(let c of i)a.push({from:l,to:c});return{nodes:o,edges:a,trace:e.traceLog()}}static toMermaid(t){let n=t?.direction??"TD",r=e.snapshot(),o=[`graph ${n}`],a={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},l=new Map;function i(s){let u=s.replace(/[^a-zA-Z0-9_]/g,"_"),g=l.get(u);return g===void 0?(l.set(u,1),u):(l.set(u,g+1),`${u}__${g}`)}let c=new Map;function f(s){let u=JSON.stringify(s);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let s of r.nodes){let u=i(s.name);c.set(s.name,u);let g=`${s.name} (${s.kind}) = ${f(s.value)}`,m=a[s.status??""]??"";o.push(` ${u}["${g}"]${m}`)}for(let s of r.edges){let u=c.get(s.from)??i(s.from),g=c.get(s.to)??i(s.to);o.push(` ${u} --> ${g}`)}return o.push(""),o.push(" classDef settled fill:#d4edda,stroke:#28a745"),o.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),o.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),o.push(" classDef completed fill:#cce5ff,stroke:#007bff"),o.join(`
3
- `)}static toD2(t){let n=t?.direction??"down",r=e.snapshot(),o=[`direction: ${n}`,""],a={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},l=new Map;function i(s){let u=s.replace(/[^a-zA-Z0-9_]/g,"_"),g=l.get(u);return g===void 0?(l.set(u,1),u):(l.set(u,g+1),`${u}__${g}`)}let c=new Map;function f(s){let u=JSON.stringify(s);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let s of r.nodes){let u=i(s.name);c.set(s.name,u);let g=a[s.kind]??"rectangle",m=`${s.name} (${s.kind}) = ${f(s.value)}`,y=s.status?` [${s.status}]`:"";o.push(`${u}: "${m}${y}" { shape: ${g} }`)}r.edges.length>0&&o.push("");for(let s of r.edges){let u=c.get(s.from)??i(s.from),g=c.get(s.to)??i(s.to);o.push(`${u} -> ${g}`)}return o.join(`
4
- `)}static annotate(t,n){if(!e.enabled)return;e._annotations.set(t,n);let r={node:e._resolveKey(t),reason:n,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(r):(e._traceLog[e._traceHead]=r,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}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 _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 ce=1,I=64,W=2,Y=4,De=8,Pe=16,q=32,H=1024,L=ge,J=be<<F,X=_e<<F,fe=ye<<F,Ve=ve<<F,Ye=Ee<<F,Je=ke<<F,ee=class{_value;_output=null;_flags;get _status(){return we(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,n){this._value=n?.initial,this._fn=t,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let r=0;n?.autoDirty!==!1&&(r|=Y),n?.resetOnTeardown&&(r|=De),n?.resubscribable&&(r|=Pe),this._flags=r,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||A.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,n){let r=this._output;if(r)if(this._flags&I)for(let o of r)o(t,n);else r(t,n)}emit(t){this._flags&W||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(le()?this._flags&q||(this._flags|=q,this._flags&Y&&(this._flags=this._flags&~L|J,this._dispatch($,N)),ue(()=>{this._flags&=~q,this._flags=this._flags&~L|X,this._dispatch(U,this._value)})):(this._flags&Y&&!(this._flags&H)&&(this._flags=this._flags&~L|J,this._dispatch($,N)),this._flags=this._flags&~L|X,this._dispatch(U,this._value))))}signal(t){this._flags&W||!this._output||(t===N?this._flags=this._flags&~L|J:t===Z&&(this._flags=this._flags&~L|Je),this._dispatch($,t))}complete(){if(this._flags&W)return;this._flags=(this._flags|W)&~L|Ve;let t=this._output,n=this._flags&I;if(this._output=null,this._flags&=~(I|H),this._singleDepCount=0,this._stop(),t)if(n)for(let r of t)r(R);else t(R)}error(t){if(this._flags&W)return;this._flags=(this._flags|W)&~L|Ye;let n=this._output,r=this._flags&I;if(this._output=null,this._flags&=~(I|H),this._singleDepCount=0,this._stop(),n)if(r)for(let o of n)o(R,t);else n(R,t)}_start(){if(this._flags&ce||!this._fn)return;this._flags|=ce,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n),onSignal:n=>{this._onLifecycleSignal=n}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ce&&(this._flags&=~ce,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&De&&(this._value=this._initial),this._flags&W||(this._flags=this._flags&~L|fe))}_handleLifecycleSignal(t){if(!(this._flags&W)){if(t===pe){this._onLifecycleSignal?.(t),this.complete();return}t===j&&(this._value=this._initial,this._flags&=~q),this._onLifecycleSignal?.(t),t===j&&this.emit(this._initial)}}source(t,n){if(t===P){let r=n;if(this._flags&W)if(this._flags&Pe&&this._output===null)this._flags=this._flags&~(W|L)|fe;else{r(P,a=>{}),r(R);return}if(this._output===null)this._output=r;else if(this._flags&I)this._output.add(r);else{let a=new Set;a.add(this._output),a.add(r),this._output=a,this._flags=(this._flags|I)&~H}let o=!1;r(P,(a,l)=>{if(a===U&&r(U,this._value),a===$){l===Se&&!o?(o=!0,this._singleDepCount++,this._flags&I||(this._flags|=H)):Te(l)&&this._handleLifecycleSignal(l);return}if(a===R){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&I){let i=this._output;i.delete(r),i.size===1?(this._output=i.values().next().value,this._flags&=~I,this._singleDepCount>0&&(this._flags|=H)):i.size===0&&(this._output=null,this._flags&=~(I|H),this._singleDepCount=0,this._flags=this._flags&~L|fe,this._stop())}else this._output===r&&(this._output=null,this._flags&=~H,this._singleDepCount=0,this._flags=this._flags&~L|fe,this._stop())}}),Le(()=>this._start())}}};function B(e,t){return new ee(e,t)}var me=class extends ee{constructor(t,n){super(void 0,{initial:t,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),A.register(this,{kind:"state",...n})}get(){return this._value}set(t){this._flags&W||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(le()?this._flags&q||(this._flags|=q,this._flags&Y&&(this._flags=this._flags&~L|J,this._dispatch($,N)),ue(()=>{this._flags&=~q,this._flags=this._flags&~L|X,this._dispatch(U,this._value)})):(this._flags&Y&&!(this._flags&H)&&(this._flags=this._flags&~L|J,this._dispatch($,N)),this._flags=this._flags&~L|X,this._dispatch(U,this._value))))}update(t){this.set(t(this._value))}};function v(e,t){return new me(e,t)}function G(e,t,n){let r=null;xe(),e.source(P,(a,l)=>{if(a===P&&(r=l),a===R){r=null,n?.onEnd?.(l);return}if(a===1){let i=l,c=o;o=i,t(i,c)}});let o;try{o=e.get()}catch{}return Re(),{unsubscribe(){r?.(R),r=null},signal(a){r?.($,a)}}}function Q(e,t){let n=t?.initialStatus??"pending",r=v(n,{name:"withStatus:status",equals:Object.is}),o=v(void 0,{name:"withStatus:error",equals:Object.is}),a=B(({emit:i,complete:c,error:f})=>{r.set(n),o.set(void 0);let s=G(e,u=>{r.get()==="errored"?C(()=>{o.set(void 0),r.set("active")}):r.set("active"),i(u)},{onEnd:u=>{if(u!==void 0){let g=u instanceof Error?u:new Error(String(u));C(()=>{o.set(g),r.set("errored")}),f(u)}else r.set("completed"),c()}});return()=>{s.unsubscribe()}},{initial:e.get(),resubscribable:!0}),l={get:()=>e.get(),source:(i,c)=>a.source(i,c),get _status(){return a._status},status:r,error:o};return A.register(l,{kind:"withStatus"}),l}function Ce(e,t){let n=t?.name??"http",r=t?.method??"GET",o=t?.headers,a=t?.body,l=t?.poll??0,i=t?.transform??(w=>w.json()),c=t?.timeout??3e4,f=v(0,{name:`${n}:fetchCount`}),s=null,u=null,g=null,m=null,y=null,T=!1;async function x(){if(!T||!s)return;y=new AbortController;let w=[y.signal];t?.signal&&w.push(t.signal);let _=new AbortController;for(let E of w){if(E.aborted){_.abort(E.reason);break}E.addEventListener("abort",()=>_.abort(E.reason),{once:!0})}let k=setTimeout(()=>_.abort(new Error("Request timeout")),c);try{let E=a!==void 0?typeof a=="string"?a:JSON.stringify(a):void 0,D=await fetch(e,{method:r,headers:o,body:E,signal:_.signal});if(!T)return;if(!D.ok)throw new Error(`HTTP ${D.status}: ${D.statusText}`);let M=await i(D);if(!T)return;C(()=>{f.update(O=>O+1),s?.(M)})}catch(E){if(!T||E?.name==="AbortError")return;u?.(E)}finally{clearTimeout(k),y=null}}function h(){!T||p||l<=0||(m=setTimeout(()=>{m=null,x().then(()=>{T&&!p&&h()}).catch(()=>{})},l))}let d=null,p=!1,S=B(({emit:w,error:_,complete:k,onSignal:E})=>(s=w,u=_,g=k,T=!0,p=!1,d=()=>{x()},E(D=>{D===K?(p=!0,m!==null&&(clearTimeout(m),m=null)):D===z?(p=!1,h()):D===j&&(y?.abort(),y=null,m!==null&&(clearTimeout(m),m=null),f.set(0),p=!1,x().then(()=>{T&&!p&&h()}))}),x().then(()=>{T&&!p&&h()}),()=>{T=!1,p=!1,s=null,u=null,g=null,d=null,y?.abort(),y=null,m!==null&&(clearTimeout(m),m=null)}),{name:n,kind:"http"}),b=Q(S);return{get:()=>b.get(),source:(w,_)=>b.source(w,_),status:b.status,error:b.error,fetchCount:f,refetch(){d?.()},stop(){T=!1,y?.abort(),y=null,m!==null&&(clearTimeout(m),m=null),g?.()}}}function Ge(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function Qe(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function Ze(e,t,n,r){let o={model:t,messages:n,stream:!0};return r?.temperature!==void 0&&(o.temperature=r.temperature),r?.maxTokens!==void 0&&(e==="ollama"?o.options={num_predict:r.maxTokens}:o.max_tokens=r.maxTokens),r?.stop&&(o.stop=r.stop),o}function Xe(e,t){let n={"Content-Type":"application/json"};return t&&(n.Authorization=`Bearer ${t}`),n}function Ae(e){let t=e.name??"llm",n=e.provider,r=e.baseURL??Ge(n),o=e.model??"",a=e.fetch??globalThis.fetch,l=v("",{name:`${t}.store`}),i=v({},{name:`${t}.tokens`}),c=v("pending",{name:`${t}.status`}),f=v(void 0,{name:`${t}.error`}),s=null;function u(){s&&(s.abort(),s=null),c.get()==="active"&&C(()=>{l.set(""),c.set("pending")})}function g(y,T){u(),s=new AbortController;let x=T?.signal?nt(s.signal,T.signal):s.signal;C(()=>{l.set(""),i.set({}),f.set(void 0),c.set("active")});let h=Qe(n,r),d=Ze(n,o,y,T),p=Xe(n,e.apiKey);m(h,p,d,x).catch(()=>{})}async function m(y,T,x,h){try{let d=await a(y,{method:"POST",headers:T,body:JSON.stringify(x),signal:h});if(!d.ok){let _=await d.text().catch(()=>"");throw new Error(`LLM API error ${d.status}: ${_}`)}let p=d.body?.getReader();if(!p)throw new Error("No response body");let S=new TextDecoder,b="",w="";for(;;){if(h.aborted)return;let{done:_,value:k}=await p.read();if(_)break;w+=S.decode(k,{stream:!0});let E=w.split(`
5
- `);w=E.pop()??"";for(let D of E){if(h.aborted)return;let M=D.trim();if(!M||M.startsWith(":")||!M.startsWith("data: "))continue;let O=M.slice(6);if(O!=="[DONE]")try{let te=JSON.parse(O),V=et(n,te);V&&(b+=V,l.set(b));let ne=tt(n,te);ne&&i.set(ne)}catch{}}}if(S.decode(),h.aborted)return;c.set("completed"),s=null}catch(d){if(h.aborted)return;C(()=>{f.set(d),c.set("errored")}),s=null}finally{h._cleanup?.()}}return{get:()=>l.get(),source:(y,T)=>l.source(y,T),tokens:i,status:c,error:f,generate:g,abort:u}}function et(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function tt(e,t){let n=e==="ollama"?t:t?.usage;if(n){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(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function nt(e,t){let n=new AbortController,r=()=>{e.removeEventListener("abort",o),t.removeEventListener("abort",o)},o=()=>{n.abort(),r()};e.addEventListener("abort",o,{once:!0}),t.addEventListener("abort",o,{once:!0});let a=n.signal;return a._cleanup=r,a}function Oe(e){let t=e.name??"mcp",n=e.client,r=v([],{name:`${t}.tools`}),o=v([],{name:`${t}.resources`}),a=v(void 0,{name:`${t}.refreshError`});function l(f){a.set(f);let s=e.onRefreshError;if(s==="warn")console.warn(`[${t}] refresh error:`,f);else{if(s==="error")throw f;typeof s=="function"&&s(f)}}async function i(){if(a.set(void 0),n.listTools)try{let f=await n.listTools();r.set(f.tools)}catch(f){l(f)}if(n.listResources)try{let f=await n.listResources();o.set(f.resources)}catch(f){l(f)}}function c(f){let s=`${t}:${f}`,u=v(void 0,{name:`${s}.result`}),g=v("idle",{name:`${s}.status`}),m=v(void 0,{name:`${s}.error`}),y=v(void 0,{name:`${s}.lastArgs`}),T=v(void 0,{name:`${s}.duration`}),x=!1;async function h(d){if(x)return;x=!0,C(()=>{y.set(d),m.set(void 0),g.set("active")});let p=Date.now();try{let S=await n.callTool({name:f,arguments:d}),b=Date.now()-p;if(S.isError){let k=S.content.filter(D=>D.type==="text").map(D=>D.text??"").join(`
6
- `),E=new Error(k||"MCP tool returned error");C(()=>{T.set(b),m.set(E),g.set("errored")});return}let w=S.content.filter(k=>k.type==="text"),_;if(w.length===1){let k=w[0].text;if(k!==void 0)try{_=JSON.parse(k)}catch{_=k}}else w.length>1?_=w.map(k=>k.text??""):_=S.content;C(()=>{T.set(b),u.set(_),g.set("completed")})}catch(S){let b=Date.now()-p;C(()=>{T.set(b),m.set(S),g.set("errored")})}finally{x=!1}}return{get:()=>u.get(),source:(d,p)=>u.source(d,p),status:g,error:m,call:h,lastArgs:y,duration:T}}return{tool:c,tools:r,resources:o,refresh:i,refreshError:a}}function Me(e,t){let n=t?.path??"/",r=t?.name??"sse",o=t?.hostname??"0.0.0.0",a=t?.serialize??JSON.stringify,l=t?.eventName??"message",i=t?.pingInterval??3e4,c=v(0,{name:`${r}:connections`}),f=new Set,s=new Map,u=null;function g(){u||(u=G(e,d=>{let p=a(d),S=`event: ${l}
1
+ "use strict";var Ue=Object.create;var re=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var ze=(e,t)=>{for(var r in t)re(e,r,{get:t[r],enumerable:!0})},Te=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of qe(t))!Ke.call(e,o)&&o!==r&&re(e,o,{get:()=>t[o],enumerable:!(n=He(t,o))||n.enumerable});return e};var Ve=(e,t,r)=>(r=e!=null?Ue(Be(e)):{},Te(t||!e||!e.__esModule?re(r,"default",{value:e,enumerable:!0}):r,e)),Ye=e=>Te(re({},"__esModule",{value:!0}),e);var it={};ze(it,{fromHTTP:()=>Oe,fromLLM:()=>Me,fromMCP:()=>$e,fromWebSocket:()=>je,fromWebhook:()=>Ie,toSSE:()=>Ne,toWebSocket:()=>Fe});module.exports=Ye(it);var I=Symbol("DIRTY"),Z=Symbol("RESOLVED"),be=Symbol("SINGLE_DEP"),j=Symbol("RESET"),K=Symbol("PAUSE"),z=Symbol("RESUME"),me=Symbol("TEARDOWN");function ye(e){return e===j||e===K||e===z||e===me}var _e=0,ve=1,ke=2,Ee=3,we=4,xe=5,H=7,he=7<<H,Je=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function Re(e){return Je[(e&he)>>>H]}var C=0,F=1,R=2,$=3,oe=0,se=[],ge=!1;function P(e){oe++;try{return e()}finally{if(oe--,oe===0&&!ge){ge=!0;for(let t=0;t<se.length;t++)se[t]();se.length=0,ge=!1}}}function le(){return oe>0}function ue(e){se.push(e)}var ae=0,ie=[];function Le(){ae++}function De(){if(ae--,ae===0){for(let e=0;e<ie.length;e++)ie[e]();ie.length=0}}function Ce(e){ae>0?ie.push(e):e()}var A=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(o=>e._names.get(o)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let r=e._keys.get(t)??e._names.get(t);if(r)return r;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,r){if(!e.enabled)return;r?.name&&e._names.set(t,r.name),r?.kind&&e._kinds.set(t,r.kind);let n=e._nextId++,o=r?.name;if(!(o&&!e._usedKeys.has(o)))if(o){let s=e._depSuffix(r?.deps);o=s?`${o}(${s})`:`${o}_${n}`,e._usedKeys.has(o)&&(o=`${o}_${n}`)}else{let s=r?.kind??"store",l=e._depSuffix(r?.deps);o=l?`${s}(${l})`:`${s}_${n}`,e._usedKeys.has(o)&&(o=`${o}_${n}`)}e._usedKeys.add(o),e._keys.set(t,o),e._stores.add(new WeakRef(t))}static registerEdge(t,r){if(!e.enabled)return;let n=e._resolveKey(t),o=e._resolveKey(r),s=e._edges.get(n);s?s.includes(o)||s.push(o):e._edges.set(n,[o])}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,r=new Set;for(let n of e._stores){let o=n.deref();if(!o){e._stores.delete(n);continue}let s=e._resolveKey(o);r.add(s),t.set(s,e.inspect(o))}for(let[n,o]of e._edges){if(!r.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let s=o.filter(l=>r.has(l));s.length===0?e._edges.delete(n):s.length!==o.length&&e._edges.set(n,s)}return t}static trace(t,r){let n=null,o=t.get();return t.source(C,(s,l)=>{if(s===C&&(n=l),s===R){n=null;return}if(s===1){let a=l;if(!Object.is(a,o)){let c=o;o=a,r(a,c)}}}),()=>n?.(R)}static dumpGraph(){let t=e.graph(),r=e.getEdges(),n=new Map;for(let[l,a]of r)for(let c of a){let f=n.get(c);f?f.includes(l)||f.push(l):n.set(c,[l])}let o=[];for(let[l,a]of t){let c=n.get(l),f=r.get(l),i=c?.length?` \u2190 [${c.join(", ")}]`:"",u=f?.length?` \u2192 [${f.join(", ")}]`:"";o.push(` ${l} (${a.kind}) = ${JSON.stringify(a.value)} [${a.status??"?"}]${i}${u}`)}return[`Store Graph (${t.size} nodes):`,...o].join(`
2
+ `)}static _signalLabel(t){return t===I?"DIRTY":t===Z?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,r,n){let o=null,s=!1,l=r??e.getName(t),a=[],c={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return c.ended&&!s},get errored(){return c.ended&&s},dirtyCount:0,resolvedCount:0,name:l,get eventLog(){return a},dispose:()=>o?.(R),reconnect:()=>(o?.(R),e._observe(t,r,n))};return t.source(C,(f,i)=>{if(f===C){o=i;return}f===F?(c.values.push(i),c.events.push({type:"data",data:i}),a.push(i),n&&n(`[${l}] DATA:`,i)):f===$?(c.signals.push(i),c.events.push({type:"signal",data:i}),a.push(e._signalLabel(i)),i===I?c.dirtyCount++:i===Z&&c.resolvedCount++,n&&n(`[${l}] STATE:`,i)):f===R&&(c.ended=!0,c.endError=i,s=i!==void 0,c.events.push({type:"end",data:i}),a.push(s?["END",i]:"END"),n&&n(`[${l}] END`,i!==void 0?i:""),o=null)}),c}static observe(t){return e._observe(t)}static activate(t){let r=null;return t.source(C,(n,o)=>{n===C&&(r=o),n===R&&(r=null)}),()=>r?.(R)}static tap(t,r){let n=r??`tap(${e.getName(t)??"anon"})`,o={get:()=>t.get(),source:t.source};return e.register(o,{name:n,kind:"tap"}),e.registerEdge(t,o),o}static spy(t,r){let n=r?.name??e.getName(t)??"spy",o=r?.log??console.log;return e._observe(t,n,o)}static snapshot(){let t=e.graph(),r=e.getEdges(),n=new Map;for(let l of e._stores){let a=l.deref();if(!a)continue;let c=e._annotations.get(a);c!==void 0&&n.set(e._resolveKey(a),c)}let o=[];for(let[l,a]of t){let c={name:l,kind:a.kind,value:a.value,status:a.status},f=n.get(l);f!==void 0&&(c.annotation=f),o.push(c)}let s=[];for(let[l,a]of r)for(let c of a)s.push({from:l,to:c});return{nodes:o,edges:s,trace:e.traceLog()}}static toMermaid(t){let r=t?.direction??"TD",n=e.snapshot(),o=[`graph ${r}`],s={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},l=new Map;function a(i){let u=i.replace(/[^a-zA-Z0-9_]/g,"_"),g=l.get(u);return g===void 0?(l.set(u,1),u):(l.set(u,g+1),`${u}__${g}`)}let c=new Map;function f(i){let u=JSON.stringify(i);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let i of n.nodes){let u=a(i.name);c.set(i.name,u);let g=`${i.name} (${i.kind}) = ${f(i.value)}`,m=s[i.status??""]??"";o.push(` ${u}["${g}"]${m}`)}for(let i of n.edges){let u=c.get(i.from)??a(i.from),g=c.get(i.to)??a(i.to);o.push(` ${u} --> ${g}`)}return o.push(""),o.push(" classDef settled fill:#d4edda,stroke:#28a745"),o.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),o.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),o.push(" classDef completed fill:#cce5ff,stroke:#007bff"),o.join(`
3
+ `)}static toD2(t){let r=t?.direction??"down",n=e.snapshot(),o=[`direction: ${r}`,""],s={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},l=new Map;function a(i){let u=i.replace(/[^a-zA-Z0-9_]/g,"_"),g=l.get(u);return g===void 0?(l.set(u,1),u):(l.set(u,g+1),`${u}__${g}`)}let c=new Map;function f(i){let u=JSON.stringify(i);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let i of n.nodes){let u=a(i.name);c.set(i.name,u);let g=s[i.kind]??"rectangle",m=`${i.name} (${i.kind}) = ${f(i.value)}`,b=i.status?` [${i.status}]`:"";o.push(`${u}: "${m}${b}" { shape: ${g} }`)}n.edges.length>0&&o.push("");for(let i of n.edges){let u=c.get(i.from)??a(i.from),g=c.get(i.to)??a(i.to);o.push(`${u} -> ${g}`)}return o.join(`
4
+ `)}static annotate(t,r){if(!e.enabled)return;e._annotations.set(t,r);let n={node:e._resolveKey(t),reason:r,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}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 _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 ce=1,N=64,W=2,Y=4,Pe=8,Ae=16,q=32,U=1024,L=he,J=ve<<H,X=ke<<H,fe=_e<<H,Ge=we<<H,Qe=xe<<H,Ze=Ee<<H,ee=class{_value;_output=null;_flags;get _status(){return Re(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,r){this._value=r?.initial,this._fn=t,this._eqFn=r?.equals,this._getterFn=r?.getter,this._initial=r?.initial;let n=0;r?.autoDirty!==!1&&(n|=Y),r?.resetOnTeardown&&(n|=Pe),r?.resubscribable&&(n|=Ae),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||A.register(this,{kind:"producer",...r})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,r){let n=this._output;if(n)if(this._flags&N)for(let o of n)o(t,r);else n(t,r)}emit(t){this._flags&W||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(le()?this._flags&q||(this._flags|=q,this._flags&Y&&(this._flags=this._flags&~L|J,this._dispatch($,I)),ue(()=>{this._flags&=~q,this._flags=this._flags&~L|X,this._dispatch(F,this._value)})):(this._flags&Y&&!(this._flags&U)&&(this._flags=this._flags&~L|J,this._dispatch($,I)),this._flags=this._flags&~L|X,this._dispatch(F,this._value))))}signal(t){this._flags&W||!this._output||(t===I?this._flags=this._flags&~L|J:t===Z&&(this._flags=this._flags&~L|Ze),this._dispatch($,t))}complete(){if(this._flags&W)return;this._flags=(this._flags|W)&~L|Ge;let t=this._output,r=this._flags&N;if(this._output=null,this._flags&=~(N|U),this._singleDepCount=0,this._stop(),t)if(r)for(let n of t)n(R);else t(R)}error(t){if(this._flags&W)return;this._flags=(this._flags|W)&~L|Qe;let r=this._output,n=this._flags&N;if(this._output=null,this._flags&=~(N|U),this._singleDepCount=0,this._stop(),r)if(n)for(let o of r)o(R,t);else r(R,t)}_start(){if(this._flags&ce||!this._fn)return;this._flags|=ce,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:r=>this.signal(r),complete:()=>this.complete(),error:r=>this.error(r),onSignal:r=>{this._onLifecycleSignal=r}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ce&&(this._flags&=~ce,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Pe&&(this._value=this._initial),this._flags&W||(this._flags=this._flags&~L|fe))}_handleLifecycleSignal(t){if(!(this._flags&W)){if(t===me){this._onLifecycleSignal?.(t),this.complete();return}t===j&&(this._value=this._initial,this._flags&=~q),this._onLifecycleSignal?.(t),t===j&&this.emit(this._initial)}}source(t,r){if(t===C){let n=r;if(this._flags&W)if(this._flags&Ae&&this._output===null)this._flags=this._flags&~(W|L)|fe;else{n(C,s=>{}),n(R);return}if(this._output===null)this._output=n;else if(this._flags&N)this._output.add(n);else{let s=new Set;s.add(this._output),s.add(n),this._output=s,this._flags=(this._flags|N)&~U}let o=!1;n(C,(s,l)=>{if(s===F&&n(F,this._value),s===$){l===be&&!o?(o=!0,this._singleDepCount++,this._flags&N||(this._flags|=U)):ye(l)&&this._handleLifecycleSignal(l);return}if(s===R){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&N){let a=this._output;a.delete(n),a.size===1?(this._output=a.values().next().value,this._flags&=~N,this._singleDepCount>0&&(this._flags|=U)):a.size===0&&(this._output=null,this._flags&=~(N|U),this._singleDepCount=0,this._flags=this._flags&~L|fe,this._stop())}else this._output===n&&(this._output=null,this._flags&=~U,this._singleDepCount=0,this._flags=this._flags&~L|fe,this._stop())}}),Ce(()=>this._start())}}};function B(e,t){return new ee(e,t)}var Se=class extends ee{constructor(t,r){super(void 0,{initial:t,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),A.register(this,{kind:"state",...r})}get(){return this._value}set(t){this._flags&W||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(le()?this._flags&q||(this._flags|=q,this._flags&Y&&(this._flags=this._flags&~L|J,this._dispatch($,I)),ue(()=>{this._flags&=~q,this._flags=this._flags&~L|X,this._dispatch(F,this._value)})):(this._flags&Y&&!(this._flags&U)&&(this._flags=this._flags&~L|J,this._dispatch($,I)),this._flags=this._flags&~L|X,this._dispatch(F,this._value))))}update(t){this.set(t(this._value))}};function k(e,t){return new Se(e,t)}function G(e,t,r){let n=null;Le(),e.source(C,(s,l)=>{if(s===C&&(n=l),s===R){n=null,r?.onEnd?.(l);return}if(s===1){let a=l,c=o;o=a,t(a,c)}});let o;try{o=e.get()}catch{}return De(),{unsubscribe(){n?.(R),n=null},signal(s){n?.($,s)}}}function Q(e,t){let r=t?.initialStatus??"pending",n=k(r,{name:"withStatus:status",equals:Object.is}),o=k(void 0,{name:"withStatus:error",equals:Object.is}),s=B(({emit:a,complete:c,error:f})=>{n.set(r),o.set(void 0);let i=G(e,u=>{n.get()==="errored"?P(()=>{o.set(void 0),n.set("active")}):n.set("active"),a(u)},{onEnd:u=>{if(u!==void 0){let g=u instanceof Error?u:new Error(String(u));P(()=>{o.set(g),n.set("errored")}),f(u)}else n.set("completed"),c()}});return()=>{i.unsubscribe()}},{initial:e.get(),resubscribable:!0}),l={get:()=>e.get(),source:(a,c)=>s.source(a,c),get _status(){return s._status},status:n,error:o};return A.register(l,{kind:"withStatus"}),l}function Oe(e,t){let r=t?.name??"http",n=t?.method??"GET",o=t?.headers,s=t?.body,l=t?.poll??0,a=t?.transform??(w=>w.json()),c=t?.timeout??3e4,f=k(0,{name:`${r}:fetchCount`}),i=null,u=null,g=null,m=null,b=null,T=!1;async function x(){if(!T||!i)return;b=new AbortController;let w=[b.signal];t?.signal&&w.push(t.signal);let _=new AbortController;for(let E of w){if(E.aborted){_.abort(E.reason);break}E.addEventListener("abort",()=>_.abort(E.reason),{once:!0})}let v=setTimeout(()=>_.abort(new Error("Request timeout")),c);try{let E=s!==void 0?typeof s=="string"?s:JSON.stringify(s):void 0,D=await fetch(e,{method:n,headers:o,body:E,signal:_.signal});if(!T)return;if(!D.ok)throw new Error(`HTTP ${D.status}: ${D.statusText}`);let M=await a(D);if(!T)return;P(()=>{f.update(O=>O+1),i?.(M)})}catch(E){if(!T||E?.name==="AbortError")return;u?.(E)}finally{clearTimeout(v),b=null}}function h(){!T||p||l<=0||(m=setTimeout(()=>{m=null,x().then(()=>{T&&!p&&h()}).catch(()=>{})},l))}let d=null,p=!1,S=B(({emit:w,error:_,complete:v,onSignal:E})=>(i=w,u=_,g=v,T=!0,p=!1,d=()=>{x()},E(D=>{D===K?(p=!0,m!==null&&(clearTimeout(m),m=null)):D===z?(p=!1,h()):D===j&&(b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null),f.set(0),p=!1,x().then(()=>{T&&!p&&h()}))}),x().then(()=>{T&&!p&&h()}),()=>{T=!1,p=!1,i=null,u=null,g=null,d=null,b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null)}),{name:r,kind:"http"}),y=Q(S);return{get:()=>y.get(),source:(w,_)=>y.source(w,_),status:y.status,error:y.error,fetchCount:f,refetch(){d?.()},stop(){T=!1,b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null),g?.()}}}function Xe(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function et(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function tt(e,t,r,n){let o={model:t,messages:r,stream:!0};return n?.temperature!==void 0&&(o.temperature=n.temperature),n?.maxTokens!==void 0&&(e==="ollama"?o.options={num_predict:n.maxTokens}:o.max_tokens=n.maxTokens),n?.stop&&(o.stop=n.stop),o}function nt(e,t){let r={"Content-Type":"application/json"};return t&&(r.Authorization=`Bearer ${t}`),r}function Me(e){let t=e.name??"llm",r=e.provider,n=e.baseURL??Xe(r),o=e.model??"",s=e.fetch??globalThis.fetch,l=k("",{name:`${t}.store`}),a=k({},{name:`${t}.tokens`}),c=k("pending",{name:`${t}.status`}),f=k(void 0,{name:`${t}.error`}),i=null;function u(){i&&(i.abort(),i=null),c.get()==="active"&&P(()=>{l.set(""),c.set("pending")})}function g(b,T){u(),i=new AbortController;let x=T?.signal?st(i.signal,T.signal):i.signal;P(()=>{l.set(""),a.set({}),f.set(void 0),c.set("active")});let h=et(r,n),d=tt(r,o,b,T),p=nt(r,e.apiKey);m(h,p,d,x).catch(()=>{})}async function m(b,T,x,h){try{let d=await s(b,{method:"POST",headers:T,body:JSON.stringify(x),signal:h});if(!d.ok){let _=await d.text().catch(()=>"");throw new Error(`LLM API error ${d.status}: ${_}`)}let p=d.body?.getReader();if(!p)throw new Error("No response body");let S=new TextDecoder,y="",w="";for(;;){if(h.aborted)return;let{done:_,value:v}=await p.read();if(_)break;w+=S.decode(v,{stream:!0});let E=w.split(`
5
+ `);w=E.pop()??"";for(let D of E){if(h.aborted)return;let M=D.trim();if(!M||M.startsWith(":")||!M.startsWith("data: "))continue;let O=M.slice(6);if(O!=="[DONE]")try{let te=JSON.parse(O),V=rt(r,te);V&&(y+=V,l.set(y));let ne=ot(r,te);ne&&a.set(ne)}catch{}}}if(S.decode(),h.aborted)return;c.set("completed"),i=null}catch(d){if(h.aborted)return;P(()=>{f.set(d),c.set("errored")}),i=null}finally{h._cleanup?.()}}return{get:()=>l.get(),source:(b,T)=>l.source(b,T),tokens:a,status:c,error:f,generate:g,abort:u}}function rt(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function ot(e,t){let r=e==="ollama"?t:t?.usage;if(r){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(r.prompt_tokens!==void 0||r.completion_tokens!==void 0)return{promptTokens:r.prompt_tokens,completionTokens:r.completion_tokens,totalTokens:r.total_tokens}}}function st(e,t){let r=new AbortController,n=()=>{e.removeEventListener("abort",o),t.removeEventListener("abort",o)},o=()=>{r.abort(),n()};e.addEventListener("abort",o,{once:!0}),t.addEventListener("abort",o,{once:!0});let s=r.signal;return s._cleanup=n,s}function $e(e){let t=e.name??"mcp",r=e.client,n=k([],{name:`${t}.tools`}),o=k([],{name:`${t}.resources`}),s=k(void 0,{name:`${t}.refreshError`});function l(f){s.set(f);let i=e.onRefreshError;if(i==="warn")console.warn(`[${t}] refresh error:`,f);else{if(i==="error")throw f;typeof i=="function"&&i(f)}}async function a(){if(s.set(void 0),r.listTools)try{let f=await r.listTools();n.set(f.tools)}catch(f){l(f)}if(r.listResources)try{let f=await r.listResources();o.set(f.resources)}catch(f){l(f)}}function c(f){let i=`${t}:${f}`,u=k(void 0,{name:`${i}.result`}),g=k("idle",{name:`${i}.status`}),m=k(void 0,{name:`${i}.error`}),b=k(void 0,{name:`${i}.lastArgs`}),T=k(void 0,{name:`${i}.duration`}),x=!1;async function h(d){if(x)return;x=!0,P(()=>{b.set(d),m.set(void 0),g.set("active")});let p=Date.now();try{let S=await r.callTool({name:f,arguments:d}),y=Date.now()-p;if(S.isError){let v=S.content.filter(D=>D.type==="text").map(D=>D.text??"").join(`
6
+ `),E=new Error(v||"MCP tool returned error");P(()=>{T.set(y),m.set(E),g.set("errored")});return}let w=S.content.filter(v=>v.type==="text"),_;if(w.length===1){let v=w[0].text;if(v!==void 0)try{_=JSON.parse(v)}catch{_=v}}else w.length>1?_=w.map(v=>v.text??""):_=S.content;P(()=>{T.set(y),u.set(_),g.set("completed")})}catch(S){let y=Date.now()-p;P(()=>{T.set(y),m.set(S),g.set("errored")})}finally{x=!1}}return{get:()=>u.get(),source:(d,p)=>u.source(d,p),status:g,error:m,call:h,lastArgs:b,duration:T}}return{tool:c,tools:n,resources:o,refresh:a,refreshError:s}}function We(e,t,r){let n=null;return e(0,(o,s)=>{if(o===0){n=s;return}if(o===2){n=null,r?.onEnd?.(s);return}o===1&&t(s)}),{unsubscribe(){n?.(2),n=null}}}function de(e,t){return new Promise((r,n)=>{let o=We(e,s=>{(!t||t(s))&&(o.unsubscribe(),r(s))},{onEnd:s=>{n(s??new Error("source completed without matching value"))}})})}function pe(e){return(t,r)=>{if(t!==0)return;let n=!1,o;r(0,s=>{s===2&&!n&&(n=!0,o?.())});try{o=e(s=>{n||(n=!0,r(1,s),r(2))},s=>{n||(n=!0,r(2,s))})}catch(s){n||(n=!0,r(2,s))}}}function Ne(e,t){let r=t?.path??"/",n=t?.name??"sse",o=t?.hostname??"0.0.0.0",s=t?.serialize??JSON.stringify,l=t?.eventName??"message",a=t?.pingInterval??3e4,c=k(0,{name:`${n}:connections`}),f=new Set,i=new Map,u=null;function g(){u||(u=G(e,d=>{let p=s(d),S=`event: ${l}
7
7
  data: ${p}
8
8
 
9
- `;for(let b of f)try{b.write(S)}catch{m(b)}}))}function m(d){f.delete(d);let p=s.get(d);p&&(clearInterval(p),s.delete(d)),c.set(f.size),f.size===0&&u&&(u.unsubscribe(),u=null)}function y(d,p){let S=d.method?.toUpperCase();if((d.url??"/").split("?")[0]!==n){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}if(S==="OPTIONS"){p.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),p.end();return}if(S!=="GET"){p.writeHead(405,{"Content-Type":"text/plain"}),p.end("Method not allowed");return}p.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),p.write(`:ok
9
+ `;for(let y of f)try{y.write(S)}catch{m(y)}}))}function m(d){f.delete(d);let p=i.get(d);p&&(clearInterval(p),i.delete(d)),c.set(f.size),f.size===0&&u&&(u.unsubscribe(),u=null)}function b(d,p){let S=d.method?.toUpperCase();if((d.url??"/").split("?")[0]!==r){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}if(S==="OPTIONS"){p.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),p.end();return}if(S!=="GET"){p.writeHead(405,{"Content-Type":"text/plain"}),p.end("Method not allowed");return}p.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),p.write(`:ok
10
10
 
11
- `),f.add(p),c.set(f.size);try{let _=e.get();if(_!==void 0){let k=a(_);p.write(`event: ${l}
12
- data: ${k}
11
+ `),f.add(p),c.set(f.size);try{let _=e.get();if(_!==void 0){let v=s(_);p.write(`event: ${l}
12
+ data: ${v}
13
13
 
14
- `)}}catch{}if(i>0){let _=setInterval(()=>{try{p.write(`:ping
14
+ `)}}catch{}if(a>0){let _=setInterval(()=>{try{p.write(`:ping
15
15
 
16
- `)}catch{m(p)}},i);s.set(p,_)}d.on("close",()=>m(p)),g()}let T=null;async function x(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(T)throw new Error("toSSE: already listening. Call close() first.");let d=await import("http");return new Promise((p,S)=>{T=d.createServer(y),T.once("listening",()=>p()),T.once("error",b=>{T=null,S(b)}),T.listen(t.port,o)})}function h(){for(let d of f)try{d.end()}catch{}f.clear();for(let d of s.values())clearInterval(d);s.clear(),c.set(0),u?.unsubscribe(),u=null,T?.close(),T=null}return A.register(c,{kind:"sse"}),{connectionCount:c,handler:y,listen:x,close:h}}function $e(e){let t=e?.path??"/",n=e?.parse??JSON.parse,r=e?.name??"webhook",o=e?.hostname??"0.0.0.0",a=e?.maxBodySize??1024*1024,l=e?.responseTimeout??3e4,i=v(0,{name:`${r}:count`}),c=null,f=!1,s=B(({emit:h,onSignal:d})=>(c=h,f=!1,d(p=>{p===K?f=!0:p===z?f=!1:p===j&&(f=!1,i.set(0))}),()=>{c=null,f=!1}),{name:r,kind:"webhook"});A.register(s,{kind:"webhook"});let u=Q(s),g=null,m=new Set;function y(h,d){let p=h.method?.toUpperCase(),b=(h.url??"/").split("?")[0];if(p!=="POST"||b!==t){d.writeHead(404,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Not found"}));return}if(f){d.writeHead(503,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Service paused"}));return}let w=[],_=0,k=!1;h.on("error",()=>{k=!0,d.headersSent||(d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Request aborted"})))}),h.on("data",E=>{if(!k){if(_+=E.length,_>a){k=!0,d.writeHead(413,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Payload too large"})),h.destroy?.();return}w.push(E)}}),h.on("end",()=>{if(!k)try{let E=Buffer.concat(w).toString("utf-8"),D=E.length>0?n(E):void 0;i.update(V=>V+1);let M=!1,O=null,te={body:D,get responded(){return M},respond(V,ne=200){M||(M=!0,O!==null&&(clearTimeout(O),m.delete(O),O=null),d.writeHead(ne,{"Content-Type":"application/json"}),d.end(JSON.stringify(V)))}};O=setTimeout(()=>{m.delete(O),O=null,M||(M=!0,d.writeHead(504,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Response timeout"})))},l),m.add(O),c?.(te)}catch(E){d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:E?.message??"Parse error"}))}})}function T(){return e?.port?g?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):new Promise((h,d)=>{try{g=require("http").createServer(y),g.once("listening",()=>h()),g.once("error",S=>{g=null,d(S)}),g.listen(e.port,o)}catch(p){d(p)}}):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function x(){for(let h of m)clearTimeout(h);m.clear(),g?.close(),g=null}return{get:()=>u.get(),source:(h,d)=>u.source(h,d),status:u.status,error:u.error,requestCount:i,handler:y,listen:T,close:x}}function We(e,t){let n=t?.name??"websocket",r=t?.parse??(S=>S),o=t?.reconnect??!1,a=t?.onParseError??"warn",l=v("connecting",{name:`${n}:connectionState`,equals:()=>!1}),i=null,c=null,f=null,s=null,u=null,g=!1,m=null,y=[];function T(){for(;y.length>0&&i?.readyState===WebSocket.OPEN;)i.send(y.shift())}function x(){g=!1,l.set("connecting");try{i=new WebSocket(e,t?.protocols)}catch(S){l.set("closed"),f?.(S);return}i.onopen=()=>{l.set("open"),T()},i.onmessage=S=>{if(!h)try{let b=r(S.data);c?.(b)}catch(b){a==="error"?f?.(b):a==="warn"&&console.warn(`[${n}] parse error:`,b)}},i.onerror=()=>{m=new Error(`WebSocket error on ${e}`)},i.onclose=()=>{l.set("closed"),i=null;let S=m;m=null,!g&&o!==!1?u=setTimeout(()=>{u=null,c&&x()},o):S&&!g?f?.(S):s?.()}}let h=!1,d=B(({emit:S,error:b,complete:w,onSignal:_})=>(c=S,f=b,s=w,h=!1,x(),_(k=>{k===K?h=!0:k===z?h=!1:k===j&&(h=!1,y.length=0,u!==null&&(clearTimeout(u),u=null),i&&(g=!0,i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(),i=null),l.set("closed"),x())}),()=>{c=null,f=null,s=null,h=!1,g=!0,y.length=0,u!==null&&(clearTimeout(u),u=null),i&&(i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(),i=null),l.set("closed")}),{name:n,kind:"websocket"});A.register(d,{kind:"websocket"});let p=Q(d);return{get:()=>p.get(),source:(S,b)=>p.source(S,b),status:p.status,error:p.error,connectionState:l,send(S){i?.readyState===WebSocket.OPEN?i.send(S):y.push(S)},close(S,b){g=!0,y.length=0,u!==null&&(clearTimeout(u),u=null),i?.close(S,b)}}}function Ie(e,t,n){let r=l=>typeof l=="string"?l:JSON.stringify(l),o=n?.serialize??r,a="send"in e&&typeof e.send=="function"?e.send.bind(e):null;if(!a)throw new Error("toWebSocket: invalid WebSocket target");return G(t,l=>{try{let i=o(l);a(i)}catch{}})}0&&(module.exports={fromHTTP,fromLLM,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
16
+ `)}catch{m(p)}},a);i.set(p,_)}d.on("close",()=>m(p)),g()}let T=null;async function x(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(T)throw new Error("toSSE: already listening. Call close() first.");let d=await import("http");return de(pe((p,S)=>{T=d.createServer(b),T.once("listening",()=>p()),T.once("error",y=>{T=null,S(y)}),T.listen(t.port,o)}))}function h(){for(let d of f)try{d.end()}catch{}f.clear();for(let d of i.values())clearInterval(d);i.clear(),c.set(0),u?.unsubscribe(),u=null,T?.close(),T=null}return A.register(c,{kind:"sse"}),{connectionCount:c,handler:b,listen:x,close:h}}function Ie(e){let t=e?.path??"/",r=e?.parse??JSON.parse,n=e?.name??"webhook",o=e?.hostname??"0.0.0.0",s=e?.maxBodySize??1024*1024,l=e?.responseTimeout??3e4,a=k(0,{name:`${n}:count`}),c=null,f=!1,i=B(({emit:h,onSignal:d})=>(c=h,f=!1,d(p=>{p===K?f=!0:p===z?f=!1:p===j&&(f=!1,a.set(0))}),()=>{c=null,f=!1}),{name:n,kind:"webhook"});A.register(i,{kind:"webhook"});let u=Q(i),g=null,m=new Set;function b(h,d){let p=h.method?.toUpperCase(),y=(h.url??"/").split("?")[0];if(p!=="POST"||y!==t){d.writeHead(404,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Not found"}));return}if(f){d.writeHead(503,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Service paused"}));return}let w=[],_=0,v=!1;h.on("error",()=>{v=!0,d.headersSent||(d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Request aborted"})))}),h.on("data",E=>{if(!v){if(_+=E.length,_>s){v=!0,d.writeHead(413,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Payload too large"})),h.destroy?.();return}w.push(E)}}),h.on("end",()=>{if(!v)try{let E=Buffer.concat(w).toString("utf-8"),D=E.length>0?r(E):void 0;a.update(V=>V+1);let M=!1,O=null,te={body:D,get responded(){return M},respond(V,ne=200){M||(M=!0,O!==null&&(clearTimeout(O),m.delete(O),O=null),d.writeHead(ne,{"Content-Type":"application/json"}),d.end(JSON.stringify(V)))}};O=setTimeout(()=>{m.delete(O),O=null,M||(M=!0,d.writeHead(504,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Response timeout"})))},l),m.add(O),c?.(te)}catch(E){d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:E?.message??"Parse error"}))}})}function T(){return e?.port?g?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):de(pe((h,d)=>{try{g=require("http").createServer(b),g.once("listening",()=>h()),g.once("error",S=>{g=null,d(S)}),g.listen(e.port,o);return}catch(p){d(p);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function x(){for(let h of m)clearTimeout(h);m.clear(),g?.close(),g=null}return{get:()=>u.get(),source:(h,d)=>u.source(h,d),status:u.status,error:u.error,requestCount:a,handler:b,listen:T,close:x}}function je(e,t){let r=t?.name??"websocket",n=t?.parse??(S=>S),o=t?.reconnect??!1,s=t?.onParseError??"warn",l=k("connecting",{name:`${r}:connectionState`,equals:()=>!1}),a=null,c=null,f=null,i=null,u=null,g=!1,m=null,b=[];function T(){for(;b.length>0&&a?.readyState===WebSocket.OPEN;)a.send(b.shift())}function x(){g=!1,l.set("connecting");try{a=new WebSocket(e,t?.protocols)}catch(S){l.set("closed"),f?.(S);return}a.onopen=()=>{l.set("open"),T()},a.onmessage=S=>{if(!h)try{let y=n(S.data);c?.(y)}catch(y){s==="error"?f?.(y):s==="warn"&&console.warn(`[${r}] parse error:`,y)}},a.onerror=()=>{m=new Error(`WebSocket error on ${e}`)},a.onclose=()=>{l.set("closed"),a=null;let S=m;m=null,!g&&o!==!1?u=setTimeout(()=>{u=null,c&&x()},o):S&&!g?f?.(S):i?.()}}let h=!1,d=B(({emit:S,error:y,complete:w,onSignal:_})=>(c=S,f=y,i=w,h=!1,x(),_(v=>{v===K?h=!0:v===z?h=!1:v===j&&(h=!1,b.length=0,u!==null&&(clearTimeout(u),u=null),a&&(g=!0,a.onopen=null,a.onmessage=null,a.onerror=null,a.onclose=null,a.close(),a=null),l.set("closed"),x())}),()=>{c=null,f=null,i=null,h=!1,g=!0,b.length=0,u!==null&&(clearTimeout(u),u=null),a&&(a.onopen=null,a.onmessage=null,a.onerror=null,a.onclose=null,a.close(),a=null),l.set("closed")}),{name:r,kind:"websocket"});A.register(d,{kind:"websocket"});let p=Q(d);return{get:()=>p.get(),source:(S,y)=>p.source(S,y),status:p.status,error:p.error,connectionState:l,send(S){a?.readyState===WebSocket.OPEN?a.send(S):b.push(S)},close(S,y){g=!0,b.length=0,u!==null&&(clearTimeout(u),u=null),a?.close(S,y)}}}function Fe(e,t,r){let n=l=>typeof l=="string"?l:JSON.stringify(l),o=r?.serialize??n,s="send"in e&&typeof e.send=="function"?e.send.bind(e):null;if(!s)throw new Error("toWebSocket: invalid WebSocket target");return G(t,l=>{try{let a=o(l);s(a)}catch{}})}0&&(module.exports={fromHTTP,fromLLM,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
@@ -1 +1 @@
1
- import{a as o}from"../chunk-RWZ3CCF6.js";import{a as e}from"../chunk-U5WIJOXK.js";import{a as t}from"../chunk-RX4JY356.js";import{a as r}from"../chunk-EXDWEL6X.js";import{a as p}from"../chunk-UA3L7KUP.js";import{a as m,b as S}from"../chunk-CZBLKO6T.js";import"../chunk-S2U5T7BO.js";import"../chunk-GMLWTZFM.js";import"../chunk-7FX2AO6N.js";import"../chunk-VFN2CV32.js";import"../chunk-SOIVZBGE.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{o as fromHTTP,e as fromLLM,t as fromMCP,m as fromWebSocket,p as fromWebhook,r as toSSE,S as toWebSocket};
1
+ import{a as o}from"../chunk-RWZ3CCF6.js";import{a as e}from"../chunk-U5WIJOXK.js";import{a as t}from"../chunk-RX4JY356.js";import{a as r}from"../chunk-VN3XFROF.js";import{a as p}from"../chunk-N7Y355ED.js";import"../chunk-XEU7KSEO.js";import"../chunk-LLARZ7J7.js";import{a as m,b as S}from"../chunk-CZBLKO6T.js";import"../chunk-S2U5T7BO.js";import"../chunk-GMLWTZFM.js";import"../chunk-7FX2AO6N.js";import"../chunk-VFN2CV32.js";import"../chunk-SOIVZBGE.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{o as fromHTTP,e as fromLLM,t as fromMCP,m as fromWebSocket,p as fromWebhook,r as toSSE,S as toWebSocket};
@@ -1,14 +1,14 @@
1
- "use strict";var he=Object.create;var M=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var me=(e,t)=>{for(var i in t)M(e,i,{get:t[i],enumerable:!0})},B=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Se(t))!ye.call(e,s)&&s!==i&&M(e,s,{get:()=>t[s],enumerable:!(n=_e(t,s))||n.enumerable});return e};var ve=(e,t,i)=>(i=e!=null?he(Te(e)):{},B(t||!e||!e.__esModule?M(i,"default",{value:e,enumerable:!0}):i,e)),Ee=e=>B(M({},"__esModule",{value:!0}),e);var Ae={};me(Ae,{toSSE:()=>Ie});module.exports=Ee(Ae);var v=Symbol("DIRTY"),$=Symbol("RESOLVED"),J=Symbol("SINGLE_DEP"),F=Symbol("RESET"),be=Symbol("PAUSE"),De=Symbol("RESUME"),z=Symbol("TEARDOWN");function Z(e){return e===F||e===be||e===De||e===z}var Q=0,X=1,ee=2,te=3,ne=4,se=5,D=7,q=7<<D,ke=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ie(e){return ke[(e&q)>>>D]}var S=0,E=1,g=2,T=3,xe=0,Re=[];function U(){return xe>0}function Y(e){Re.push(e)}var K=0,j=[];function re(){K++}function oe(){if(K--,K===0){for(let e=0;e<j.length;e++)j[e]();j.length=0}}function ae(e){K>0?j.push(e):e()}var x=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(s=>e._names.get(s)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let i=e._keys.get(t)??e._names.get(t);if(i)return i;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,i){if(!e.enabled)return;i?.name&&e._names.set(t,i.name),i?.kind&&e._kinds.set(t,i.kind);let n=e._nextId++,s=i?.name;if(!(s&&!e._usedKeys.has(s)))if(s){let o=e._depSuffix(i?.deps);s=o?`${s}(${o})`:`${s}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let o=i?.kind??"store",a=e._depSuffix(i?.deps);s=a?`${o}(${a})`:`${o}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}e._usedKeys.add(s),e._keys.set(t,s),e._stores.add(new WeakRef(t))}static registerEdge(t,i){if(!e.enabled)return;let n=e._resolveKey(t),s=e._resolveKey(i),o=e._edges.get(n);o?o.includes(s)||o.push(s):e._edges.set(n,[s])}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,i=new Set;for(let n of e._stores){let s=n.deref();if(!s){e._stores.delete(n);continue}let o=e._resolveKey(s);i.add(o),t.set(o,e.inspect(s))}for(let[n,s]of e._edges){if(!i.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let o=s.filter(a=>i.has(a));o.length===0?e._edges.delete(n):o.length!==s.length&&e._edges.set(n,o)}return t}static trace(t,i){let n=null,s=t.get();return t.source(S,(o,a)=>{if(o===S&&(n=a),o===g){n=null;return}if(o===1){let c=a;if(!Object.is(c,s)){let l=s;s=c,i(c,l)}}}),()=>n?.(g)}static dumpGraph(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let[a,c]of i)for(let l of c){let f=n.get(l);f?f.includes(a)||f.push(a):n.set(l,[a])}let s=[];for(let[a,c]of t){let l=n.get(a),f=i.get(a),r=l?.length?` \u2190 [${l.join(", ")}]`:"",u=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${c.kind}) = ${JSON.stringify(c.value)} [${c.status??"?"}]${r}${u}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
2
- `)}static _signalLabel(t){return t===v?"DIRTY":t===$?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,i,n){let s=null,o=!1,a=i??e.getName(t),c=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!o},get errored(){return l.ended&&o},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return c},dispose:()=>s?.(g),reconnect:()=>(s?.(g),e._observe(t,i,n))};return t.source(S,(f,r)=>{if(f===S){s=r;return}f===E?(l.values.push(r),l.events.push({type:"data",data:r}),c.push(r),n&&n(`[${a}] DATA:`,r)):f===T?(l.signals.push(r),l.events.push({type:"signal",data:r}),c.push(e._signalLabel(r)),r===v?l.dirtyCount++:r===$&&l.resolvedCount++,n&&n(`[${a}] STATE:`,r)):f===g&&(l.ended=!0,l.endError=r,o=r!==void 0,l.events.push({type:"end",data:r}),c.push(o?["END",r]:"END"),n&&n(`[${a}] END`,r!==void 0?r:""),s=null)}),l}static observe(t){return e._observe(t)}static activate(t){let i=null;return t.source(S,(n,s)=>{n===S&&(i=s),n===g&&(i=null)}),()=>i?.(g)}static tap(t,i){let n=i??`tap(${e.getName(t)??"anon"})`,s={get:()=>t.get(),source:t.source};return e.register(s,{name:n,kind:"tap"}),e.registerEdge(t,s),s}static spy(t,i){let n=i?.name??e.getName(t)??"spy",s=i?.log??console.log;return e._observe(t,n,s)}static snapshot(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let a of e._stores){let c=a.deref();if(!c)continue;let l=e._annotations.get(c);l!==void 0&&n.set(e._resolveKey(c),l)}let s=[];for(let[a,c]of t){let l={name:a,kind:c.kind,value:c.value,status:c.status},f=n.get(a);f!==void 0&&(l.annotation=f),s.push(l)}let o=[];for(let[a,c]of i)for(let l of c)o.push({from:a,to:l});return{nodes:s,edges:o,trace:e.traceLog()}}static toMermaid(t){let i=t?.direction??"TD",n=e.snapshot(),s=[`graph ${i}`],o={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},a=new Map;function c(r){let u=r.replace(/[^a-zA-Z0-9_]/g,"_"),p=a.get(u);return p===void 0?(a.set(u,1),u):(a.set(u,p+1),`${u}__${p}`)}let l=new Map;function f(r){let u=JSON.stringify(r);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let r of n.nodes){let u=c(r.name);l.set(r.name,u);let p=`${r.name} (${r.kind}) = ${f(r.value)}`,w=o[r.status??""]??"";s.push(` ${u}["${p}"]${w}`)}for(let r of n.edges){let u=l.get(r.from)??c(r.from),p=l.get(r.to)??c(r.to);s.push(` ${u} --> ${p}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
- `)}static toD2(t){let i=t?.direction??"down",n=e.snapshot(),s=[`direction: ${i}`,""],o={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},a=new Map;function c(r){let u=r.replace(/[^a-zA-Z0-9_]/g,"_"),p=a.get(u);return p===void 0?(a.set(u,1),u):(a.set(u,p+1),`${u}__${p}`)}let l=new Map;function f(r){let u=JSON.stringify(r);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let r of n.nodes){let u=c(r.name);l.set(r.name,u);let p=o[r.kind]??"rectangle",w=`${r.name} (${r.kind}) = ${f(r.value)}`,N=r.status?` [${r.status}]`:"";s.push(`${u}: "${w}${N}" { shape: ${p} }`)}n.edges.length>0&&s.push("");for(let r of n.edges){let u=l.get(r.from)??c(r.from),p=l.get(r.to)??c(r.to);s.push(`${u} -> ${p}`)}return s.join(`
4
- `)}static annotate(t,i){if(!e.enabled)return;e._annotations.set(t,i);let n={node:e._resolveKey(t),reason:i,timestamp:Date.now()},s=e.maxTraceEntries;s<=0||(e._traceLog.length<s?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%s)}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 _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 W=1,m=64,y=2,O=4,le=8,ce=16,R=32,b=1024,h=q,I=X<<D,C=ee<<D,H=Q<<D,we=ne<<D,Le=se<<D,Oe=te<<D,V=class{_value;_output=null;_flags;get _status(){return ie(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,i){this._value=i?.initial,this._fn=t,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=O),i?.resetOnTeardown&&(n|=le),i?.resubscribable&&(n|=ce),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||x.register(this,{kind:"producer",...i})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,i){let n=this._output;if(n)if(this._flags&m)for(let s of n)s(t,i);else n(t,i)}emit(t){this._flags&y||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(U()?this._flags&R||(this._flags|=R,this._flags&O&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),Y(()=>{this._flags&=~R,this._flags=this._flags&~h|C,this._dispatch(E,this._value)})):(this._flags&O&&!(this._flags&b)&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),this._flags=this._flags&~h|C,this._dispatch(E,this._value))))}signal(t){this._flags&y||!this._output||(t===v?this._flags=this._flags&~h|I:t===$&&(this._flags=this._flags&~h|Oe),this._dispatch(T,t))}complete(){if(this._flags&y)return;this._flags=(this._flags|y)&~h|we;let t=this._output,i=this._flags&m;if(this._output=null,this._flags&=~(m|b),this._singleDepCount=0,this._stop(),t)if(i)for(let n of t)n(g);else t(g)}error(t){if(this._flags&y)return;this._flags=(this._flags|y)&~h|Le;let i=this._output,n=this._flags&m;if(this._output=null,this._flags&=~(m|b),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,t);else i(g,t)}_start(){if(this._flags&W||!this._fn)return;this._flags|=W,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i),onSignal:i=>{this._onLifecycleSignal=i}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&W&&(this._flags&=~W,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&le&&(this._value=this._initial),this._flags&y||(this._flags=this._flags&~h|H))}_handleLifecycleSignal(t){if(!(this._flags&y)){if(t===z){this._onLifecycleSignal?.(t),this.complete();return}t===F&&(this._value=this._initial,this._flags&=~R),this._onLifecycleSignal?.(t),t===F&&this.emit(this._initial)}}source(t,i){if(t===S){let n=i;if(this._flags&y)if(this._flags&ce&&this._output===null)this._flags=this._flags&~(y|h)|H;else{n(S,o=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&m)this._output.add(n);else{let o=new Set;o.add(this._output),o.add(n),this._output=o,this._flags=(this._flags|m)&~b}let s=!1;n(S,(o,a)=>{if(o===E&&n(E,this._value),o===T){a===J&&!s?(s=!0,this._singleDepCount++,this._flags&m||(this._flags|=b)):Z(a)&&this._handleLifecycleSignal(a);return}if(o===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&m){let c=this._output;c.delete(n),c.size===1?(this._output=c.values().next().value,this._flags&=~m,this._singleDepCount>0&&(this._flags|=b)):c.size===0&&(this._output=null,this._flags&=~(m|b),this._singleDepCount=0,this._flags=this._flags&~h|H,this._stop())}else this._output===n&&(this._output=null,this._flags&=~b,this._singleDepCount=0,this._flags=this._flags&~h|H,this._stop())}}),ae(()=>this._start())}}};var G=class extends V{constructor(t,i){super(void 0,{initial:t,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),x.register(this,{kind:"state",...i})}get(){return this._value}set(t){this._flags&y||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(U()?this._flags&R||(this._flags|=R,this._flags&O&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),Y(()=>{this._flags&=~R,this._flags=this._flags&~h|C,this._dispatch(E,this._value)})):(this._flags&O&&!(this._flags&b)&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),this._flags=this._flags&~h|C,this._dispatch(E,this._value))))}update(t){this.set(t(this._value))}};function ue(e,t){return new G(e,t)}function fe(e,t,i){let n=null;re(),e.source(S,(o,a)=>{if(o===S&&(n=a),o===g){n=null,i?.onEnd?.(a);return}if(o===1){let c=a,l=s;s=c,t(c,l)}});let s;try{s=e.get()}catch{}return oe(),{unsubscribe(){n?.(g),n=null},signal(o){n?.(T,o)}}}function Ie(e,t){let i=t?.path??"/",n=t?.name??"sse",s=t?.hostname??"0.0.0.0",o=t?.serialize??JSON.stringify,a=t?.eventName??"message",c=t?.pingInterval??3e4,l=ue(0,{name:`${n}:connections`}),f=new Set,r=new Map,u=null;function p(){u||(u=fe(e,_=>{let d=o(_),L=`event: ${a}
1
+ "use strict";var Te=Object.create;var M=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var i in t)M(e,i,{get:t[i],enumerable:!0})},B=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ye(t))!be.call(e,s)&&s!==i&&M(e,s,{get:()=>t[s],enumerable:!(n=me(t,s))||n.enumerable});return e};var De=(e,t,i)=>(i=e!=null?Te(ve(e)):{},B(t||!e||!e.__esModule?M(i,"default",{value:e,enumerable:!0}):i,e)),ke=e=>B(M({},"__esModule",{value:!0}),e);var Ne={};Ee(Ne,{toSSE:()=>$e});module.exports=ke(Ne);var v=Symbol("DIRTY"),C=Symbol("RESOLVED"),J=Symbol("SINGLE_DEP"),K=Symbol("RESET"),xe=Symbol("PAUSE"),we=Symbol("RESUME"),z=Symbol("TEARDOWN");function Z(e){return e===K||e===xe||e===we||e===z}var Q=0,X=1,ee=2,te=3,ne=4,se=5,D=7,q=7<<D,Re=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ie(e){return Re[(e&q)>>>D]}var S=0,b=1,g=2,T=3,Le=0,Oe=[];function U(){return Le>0}function Y(e){Oe.push(e)}var F=0,j=[];function re(){F++}function oe(){if(F--,F===0){for(let e=0;e<j.length;e++)j[e]();j.length=0}}function ae(e){F>0?j.push(e):e()}var x=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(s=>e._names.get(s)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let i=e._keys.get(t)??e._names.get(t);if(i)return i;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,i){if(!e.enabled)return;i?.name&&e._names.set(t,i.name),i?.kind&&e._kinds.set(t,i.kind);let n=e._nextId++,s=i?.name;if(!(s&&!e._usedKeys.has(s)))if(s){let r=e._depSuffix(i?.deps);s=r?`${s}(${r})`:`${s}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let r=i?.kind??"store",a=e._depSuffix(i?.deps);s=a?`${r}(${a})`:`${r}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}e._usedKeys.add(s),e._keys.set(t,s),e._stores.add(new WeakRef(t))}static registerEdge(t,i){if(!e.enabled)return;let n=e._resolveKey(t),s=e._resolveKey(i),r=e._edges.get(n);r?r.includes(s)||r.push(s):e._edges.set(n,[s])}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,i=new Set;for(let n of e._stores){let s=n.deref();if(!s){e._stores.delete(n);continue}let r=e._resolveKey(s);i.add(r),t.set(r,e.inspect(s))}for(let[n,s]of e._edges){if(!i.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let r=s.filter(a=>i.has(a));r.length===0?e._edges.delete(n):r.length!==s.length&&e._edges.set(n,r)}return t}static trace(t,i){let n=null,s=t.get();return t.source(S,(r,a)=>{if(r===S&&(n=a),r===g){n=null;return}if(r===1){let c=a;if(!Object.is(c,s)){let l=s;s=c,i(c,l)}}}),()=>n?.(g)}static dumpGraph(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let[a,c]of i)for(let l of c){let f=n.get(l);f?f.includes(a)||f.push(a):n.set(l,[a])}let s=[];for(let[a,c]of t){let l=n.get(a),f=i.get(a),o=l?.length?` \u2190 [${l.join(", ")}]`:"",u=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${c.kind}) = ${JSON.stringify(c.value)} [${c.status??"?"}]${o}${u}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
2
+ `)}static _signalLabel(t){return t===v?"DIRTY":t===C?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,i,n){let s=null,r=!1,a=i??e.getName(t),c=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!r},get errored(){return l.ended&&r},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return c},dispose:()=>s?.(g),reconnect:()=>(s?.(g),e._observe(t,i,n))};return t.source(S,(f,o)=>{if(f===S){s=o;return}f===b?(l.values.push(o),l.events.push({type:"data",data:o}),c.push(o),n&&n(`[${a}] DATA:`,o)):f===T?(l.signals.push(o),l.events.push({type:"signal",data:o}),c.push(e._signalLabel(o)),o===v?l.dirtyCount++:o===C&&l.resolvedCount++,n&&n(`[${a}] STATE:`,o)):f===g&&(l.ended=!0,l.endError=o,r=o!==void 0,l.events.push({type:"end",data:o}),c.push(r?["END",o]:"END"),n&&n(`[${a}] END`,o!==void 0?o:""),s=null)}),l}static observe(t){return e._observe(t)}static activate(t){let i=null;return t.source(S,(n,s)=>{n===S&&(i=s),n===g&&(i=null)}),()=>i?.(g)}static tap(t,i){let n=i??`tap(${e.getName(t)??"anon"})`,s={get:()=>t.get(),source:t.source};return e.register(s,{name:n,kind:"tap"}),e.registerEdge(t,s),s}static spy(t,i){let n=i?.name??e.getName(t)??"spy",s=i?.log??console.log;return e._observe(t,n,s)}static snapshot(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let a of e._stores){let c=a.deref();if(!c)continue;let l=e._annotations.get(c);l!==void 0&&n.set(e._resolveKey(c),l)}let s=[];for(let[a,c]of t){let l={name:a,kind:c.kind,value:c.value,status:c.status},f=n.get(a);f!==void 0&&(l.annotation=f),s.push(l)}let r=[];for(let[a,c]of i)for(let l of c)r.push({from:a,to:l});return{nodes:s,edges:r,trace:e.traceLog()}}static toMermaid(t){let i=t?.direction??"TD",n=e.snapshot(),s=[`graph ${i}`],r={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},a=new Map;function c(o){let u=o.replace(/[^a-zA-Z0-9_]/g,"_"),p=a.get(u);return p===void 0?(a.set(u,1),u):(a.set(u,p+1),`${u}__${p}`)}let l=new Map;function f(o){let u=JSON.stringify(o);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let o of n.nodes){let u=c(o.name);l.set(o.name,u);let p=`${o.name} (${o.kind}) = ${f(o.value)}`,R=r[o.status??""]??"";s.push(` ${u}["${p}"]${R}`)}for(let o of n.edges){let u=l.get(o.from)??c(o.from),p=l.get(o.to)??c(o.to);s.push(` ${u} --> ${p}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
+ `)}static toD2(t){let i=t?.direction??"down",n=e.snapshot(),s=[`direction: ${i}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},a=new Map;function c(o){let u=o.replace(/[^a-zA-Z0-9_]/g,"_"),p=a.get(u);return p===void 0?(a.set(u,1),u):(a.set(u,p+1),`${u}__${p}`)}let l=new Map;function f(o){let u=JSON.stringify(o);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let o of n.nodes){let u=c(o.name);l.set(o.name,u);let p=r[o.kind]??"rectangle",R=`${o.name} (${o.kind}) = ${f(o.value)}`,N=o.status?` [${o.status}]`:"";s.push(`${u}: "${R}${N}" { shape: ${p} }`)}n.edges.length>0&&s.push("");for(let o of n.edges){let u=l.get(o.from)??c(o.from),p=l.get(o.to)??c(o.to);s.push(`${u} -> ${p}`)}return s.join(`
4
+ `)}static annotate(t,i){if(!e.enabled)return;e._annotations.set(t,i);let n={node:e._resolveKey(t),reason:i,timestamp:Date.now()},s=e.maxTraceEntries;s<=0||(e._traceLog.length<s?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%s)}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 _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 W=1,y=64,m=2,O=4,le=8,ce=16,w=32,E=1024,h=q,I=X<<D,$=ee<<D,H=Q<<D,Ie=ne<<D,Ae=se<<D,Ce=te<<D,V=class{_value;_output=null;_flags;get _status(){return ie(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,i){this._value=i?.initial,this._fn=t,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=O),i?.resetOnTeardown&&(n|=le),i?.resubscribable&&(n|=ce),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||x.register(this,{kind:"producer",...i})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,i){let n=this._output;if(n)if(this._flags&y)for(let s of n)s(t,i);else n(t,i)}emit(t){this._flags&m||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(U()?this._flags&w||(this._flags|=w,this._flags&O&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),Y(()=>{this._flags&=~w,this._flags=this._flags&~h|$,this._dispatch(b,this._value)})):(this._flags&O&&!(this._flags&E)&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),this._flags=this._flags&~h|$,this._dispatch(b,this._value))))}signal(t){this._flags&m||!this._output||(t===v?this._flags=this._flags&~h|I:t===C&&(this._flags=this._flags&~h|Ce),this._dispatch(T,t))}complete(){if(this._flags&m)return;this._flags=(this._flags|m)&~h|Ie;let t=this._output,i=this._flags&y;if(this._output=null,this._flags&=~(y|E),this._singleDepCount=0,this._stop(),t)if(i)for(let n of t)n(g);else t(g)}error(t){if(this._flags&m)return;this._flags=(this._flags|m)&~h|Ae;let i=this._output,n=this._flags&y;if(this._output=null,this._flags&=~(y|E),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,t);else i(g,t)}_start(){if(this._flags&W||!this._fn)return;this._flags|=W,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i),onSignal:i=>{this._onLifecycleSignal=i}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&W&&(this._flags&=~W,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&le&&(this._value=this._initial),this._flags&m||(this._flags=this._flags&~h|H))}_handleLifecycleSignal(t){if(!(this._flags&m)){if(t===z){this._onLifecycleSignal?.(t),this.complete();return}t===K&&(this._value=this._initial,this._flags&=~w),this._onLifecycleSignal?.(t),t===K&&this.emit(this._initial)}}source(t,i){if(t===S){let n=i;if(this._flags&m)if(this._flags&ce&&this._output===null)this._flags=this._flags&~(m|h)|H;else{n(S,r=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&y)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|y)&~E}let s=!1;n(S,(r,a)=>{if(r===b&&n(b,this._value),r===T){a===J&&!s?(s=!0,this._singleDepCount++,this._flags&y||(this._flags|=E)):Z(a)&&this._handleLifecycleSignal(a);return}if(r===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&y){let c=this._output;c.delete(n),c.size===1?(this._output=c.values().next().value,this._flags&=~y,this._singleDepCount>0&&(this._flags|=E)):c.size===0&&(this._output=null,this._flags&=~(y|E),this._singleDepCount=0,this._flags=this._flags&~h|H,this._stop())}else this._output===n&&(this._output=null,this._flags&=~E,this._singleDepCount=0,this._flags=this._flags&~h|H,this._stop())}}),ae(()=>this._start())}}};var G=class extends V{constructor(t,i){super(void 0,{initial:t,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),x.register(this,{kind:"state",...i})}get(){return this._value}set(t){this._flags&m||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(U()?this._flags&w||(this._flags|=w,this._flags&O&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),Y(()=>{this._flags&=~w,this._flags=this._flags&~h|$,this._dispatch(b,this._value)})):(this._flags&O&&!(this._flags&E)&&(this._flags=this._flags&~h|I,this._dispatch(T,v)),this._flags=this._flags&~h|$,this._dispatch(b,this._value))))}update(t){this.set(t(this._value))}};function ue(e,t){return new G(e,t)}function fe(e,t,i){let n=null;re(),e.source(S,(r,a)=>{if(r===S&&(n=a),r===g){n=null,i?.onEnd?.(a);return}if(r===1){let c=a,l=s;s=c,t(c,l)}});let s;try{s=e.get()}catch{}return oe(),{unsubscribe(){n?.(g),n=null},signal(r){n?.(T,r)}}}function de(e,t,i){let n=null;return e(0,(s,r)=>{if(s===0){n=r;return}if(s===2){n=null,i?.onEnd?.(r);return}s===1&&t(r)}),{unsubscribe(){n?.(2),n=null}}}function ge(e,t){return new Promise((i,n)=>{let s=de(e,r=>{(!t||t(r))&&(s.unsubscribe(),i(r))},{onEnd:r=>{n(r??new Error("source completed without matching value"))}})})}function pe(e){return(t,i)=>{if(t!==0)return;let n=!1,s;i(0,r=>{r===2&&!n&&(n=!0,s?.())});try{s=e(r=>{n||(n=!0,i(1,r),i(2))},r=>{n||(n=!0,i(2,r))})}catch(r){n||(n=!0,i(2,r))}}}function $e(e,t){let i=t?.path??"/",n=t?.name??"sse",s=t?.hostname??"0.0.0.0",r=t?.serialize??JSON.stringify,a=t?.eventName??"message",c=t?.pingInterval??3e4,l=ue(0,{name:`${n}:connections`}),f=new Set,o=new Map,u=null;function p(){u||(u=fe(e,_=>{let d=r(_),L=`event: ${a}
5
5
  data: ${d}
6
6
 
7
- `;for(let A of f)try{A.write(L)}catch{w(A)}}))}function w(_){f.delete(_);let d=r.get(_);d&&(clearInterval(d),r.delete(_)),l.set(f.size),f.size===0&&u&&(u.unsubscribe(),u=null)}function N(_,d){let L=_.method?.toUpperCase();if((_.url??"/").split("?")[0]!==i){d.writeHead(404,{"Content-Type":"text/plain"}),d.end("Not found");return}if(L==="OPTIONS"){d.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),d.end();return}if(L!=="GET"){d.writeHead(405,{"Content-Type":"text/plain"}),d.end("Method not allowed");return}d.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),d.write(`:ok
7
+ `;for(let A of f)try{A.write(L)}catch{R(A)}}))}function R(_){f.delete(_);let d=o.get(_);d&&(clearInterval(d),o.delete(_)),l.set(f.size),f.size===0&&u&&(u.unsubscribe(),u=null)}function N(_,d){let L=_.method?.toUpperCase();if((_.url??"/").split("?")[0]!==i){d.writeHead(404,{"Content-Type":"text/plain"}),d.end("Not found");return}if(L==="OPTIONS"){d.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),d.end();return}if(L!=="GET"){d.writeHead(405,{"Content-Type":"text/plain"}),d.end("Method not allowed");return}d.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),d.write(`:ok
8
8
 
9
- `),f.add(d),l.set(f.size);try{let P=e.get();if(P!==void 0){let pe=o(P);d.write(`event: ${a}
10
- data: ${pe}
9
+ `),f.add(d),l.set(f.size);try{let P=e.get();if(P!==void 0){let Se=r(P);d.write(`event: ${a}
10
+ data: ${Se}
11
11
 
12
12
  `)}}catch{}if(c>0){let P=setInterval(()=>{try{d.write(`:ping
13
13
 
14
- `)}catch{w(d)}},c);r.set(d,P)}_.on("close",()=>w(d)),p()}let k=null;async function de(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(k)throw new Error("toSSE: already listening. Call close() first.");let _=await import("http");return new Promise((d,L)=>{k=_.createServer(N),k.once("listening",()=>d()),k.once("error",A=>{k=null,L(A)}),k.listen(t.port,s)})}function ge(){for(let _ of f)try{_.end()}catch{}f.clear();for(let _ of r.values())clearInterval(_);r.clear(),l.set(0),u?.unsubscribe(),u=null,k?.close(),k=null}return x.register(l,{kind:"sse"}),{connectionCount:l,handler:N,listen:de,close:ge}}0&&(module.exports={toSSE});
14
+ `)}catch{R(d)}},c);o.set(d,P)}_.on("close",()=>R(d)),p()}let k=null;async function he(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(k)throw new Error("toSSE: already listening. Call close() first.");let _=await import("http");return ge(pe((d,L)=>{k=_.createServer(N),k.once("listening",()=>d()),k.once("error",A=>{k=null,L(A)}),k.listen(t.port,s)}))}function _e(){for(let _ of f)try{_.end()}catch{}f.clear();for(let _ of o.values())clearInterval(_);o.clear(),l.set(0),u?.unsubscribe(),u=null,k?.close(),k=null}return x.register(l,{kind:"sse"}),{connectionCount:l,handler:N,listen:he,close:_e}}0&&(module.exports={toSSE});
@@ -1 +1 @@
1
- import{a}from"../chunk-EXDWEL6X.js";import"../chunk-GMLWTZFM.js";import"../chunk-7FX2AO6N.js";import"../chunk-VFN2CV32.js";import"../chunk-SOIVZBGE.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as toSSE};
1
+ import{a}from"../chunk-VN3XFROF.js";import"../chunk-XEU7KSEO.js";import"../chunk-LLARZ7J7.js";import"../chunk-GMLWTZFM.js";import"../chunk-7FX2AO6N.js";import"../chunk-VFN2CV32.js";import"../chunk-SOIVZBGE.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as toSSE};
@@ -1,4 +1,4 @@
1
- "use strict";var Z=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Ae=(e,t)=>{for(var i in t)Z(e,i,{get:t[i],enumerable:!0})},Ne=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ie(t))!Pe.call(e,s)&&s!==i&&Z(e,s,{get:()=>t[s],enumerable:!(n=Le(t,s))||n.enumerable});return e};var $e=e=>Ne(Z({},"__esModule",{value:!0}),e);var Fe={};Ae(Fe,{fromWebhook:()=>Ke});module.exports=$e(Fe);var b=Symbol("DIRTY"),$=Symbol("RESOLVED"),ue=Symbol("SINGLE_DEP"),I=Symbol("RESET"),X=Symbol("PAUSE"),ee=Symbol("RESUME"),te=Symbol("TEARDOWN");function le(e){return e===I||e===X||e===ee||e===te}var ce=0,fe=1,de=2,pe=3,ge=4,he=5,x=7,ne=7<<x,Ce=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function Se(e){return Ce[(e&ne)>>>x]}var _=0,E=1,g=2,T=3,F=0,q=[],Q=!1;function se(e){F++;try{return e()}finally{if(F--,F===0&&!Q){Q=!0;for(let t=0;t<q.length;t++)q[t]();q.length=0,Q=!1}}}function Y(){return F>0}function V(e){q.push(e)}var H=0,U=[];function _e(){H++}function Te(){if(H--,H===0){for(let e=0;e<U.length;e++)U[e]();U.length=0}}function me(e){H>0?U.push(e):e()}var v=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(s=>e._names.get(s)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let i=e._keys.get(t)??e._names.get(t);if(i)return i;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,i){if(!e.enabled)return;i?.name&&e._names.set(t,i.name),i?.kind&&e._kinds.set(t,i.kind);let n=e._nextId++,s=i?.name;if(!(s&&!e._usedKeys.has(s)))if(s){let o=e._depSuffix(i?.deps);s=o?`${s}(${o})`:`${s}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let o=i?.kind??"store",a=e._depSuffix(i?.deps);s=a?`${o}(${a})`:`${o}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}e._usedKeys.add(s),e._keys.set(t,s),e._stores.add(new WeakRef(t))}static registerEdge(t,i){if(!e.enabled)return;let n=e._resolveKey(t),s=e._resolveKey(i),o=e._edges.get(n);o?o.includes(s)||o.push(s):e._edges.set(n,[s])}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,i=new Set;for(let n of e._stores){let s=n.deref();if(!s){e._stores.delete(n);continue}let o=e._resolveKey(s);i.add(o),t.set(o,e.inspect(s))}for(let[n,s]of e._edges){if(!i.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let o=s.filter(a=>i.has(a));o.length===0?e._edges.delete(n):o.length!==s.length&&e._edges.set(n,o)}return t}static trace(t,i){let n=null,s=t.get();return t.source(_,(o,a)=>{if(o===_&&(n=a),o===g){n=null;return}if(o===1){let u=a;if(!Object.is(u,s)){let l=s;s=u,i(u,l)}}}),()=>n?.(g)}static dumpGraph(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let[a,u]of i)for(let l of u){let f=n.get(l);f?f.includes(a)||f.push(a):n.set(l,[a])}let s=[];for(let[a,u]of t){let l=n.get(a),f=i.get(a),r=l?.length?` \u2190 [${l.join(", ")}]`:"",c=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${r}${c}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
2
- `)}static _signalLabel(t){return t===b?"DIRTY":t===$?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,i,n){let s=null,o=!1,a=i??e.getName(t),u=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!o},get errored(){return l.ended&&o},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return u},dispose:()=>s?.(g),reconnect:()=>(s?.(g),e._observe(t,i,n))};return t.source(_,(f,r)=>{if(f===_){s=r;return}f===E?(l.values.push(r),l.events.push({type:"data",data:r}),u.push(r),n&&n(`[${a}] DATA:`,r)):f===T?(l.signals.push(r),l.events.push({type:"signal",data:r}),u.push(e._signalLabel(r)),r===b?l.dirtyCount++:r===$&&l.resolvedCount++,n&&n(`[${a}] STATE:`,r)):f===g&&(l.ended=!0,l.endError=r,o=r!==void 0,l.events.push({type:"end",data:r}),u.push(o?["END",r]:"END"),n&&n(`[${a}] END`,r!==void 0?r:""),s=null)}),l}static observe(t){return e._observe(t)}static activate(t){let i=null;return t.source(_,(n,s)=>{n===_&&(i=s),n===g&&(i=null)}),()=>i?.(g)}static tap(t,i){let n=i??`tap(${e.getName(t)??"anon"})`,s={get:()=>t.get(),source:t.source};return e.register(s,{name:n,kind:"tap"}),e.registerEdge(t,s),s}static spy(t,i){let n=i?.name??e.getName(t)??"spy",s=i?.log??console.log;return e._observe(t,n,s)}static snapshot(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let a of e._stores){let u=a.deref();if(!u)continue;let l=e._annotations.get(u);l!==void 0&&n.set(e._resolveKey(u),l)}let s=[];for(let[a,u]of t){let l={name:a,kind:u.kind,value:u.value,status:u.status},f=n.get(a);f!==void 0&&(l.annotation=f),s.push(l)}let o=[];for(let[a,u]of i)for(let l of u)o.push({from:a,to:l});return{nodes:s,edges:o,trace:e.traceLog()}}static toMermaid(t){let i=t?.direction??"TD",n=e.snapshot(),s=[`graph ${i}`],o={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},a=new Map;function u(r){let c=r.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(c);return d===void 0?(a.set(c,1),c):(a.set(c,d+1),`${c}__${d}`)}let l=new Map;function f(r){let c=JSON.stringify(r);return c&&c.length>30?`${c.slice(0,27)}...`:c??"undefined"}for(let r of n.nodes){let c=u(r.name);l.set(r.name,c);let d=`${r.name} (${r.kind}) = ${f(r.value)}`,k=o[r.status??""]??"";s.push(` ${c}["${d}"]${k}`)}for(let r of n.edges){let c=l.get(r.from)??u(r.from),d=l.get(r.to)??u(r.to);s.push(` ${c} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
- `)}static toD2(t){let i=t?.direction??"down",n=e.snapshot(),s=[`direction: ${i}`,""],o={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},a=new Map;function u(r){let c=r.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(c);return d===void 0?(a.set(c,1),c):(a.set(c,d+1),`${c}__${d}`)}let l=new Map;function f(r){let c=JSON.stringify(r);return c&&c.length>30?`${c.slice(0,27)}...`:c??"undefined"}for(let r of n.nodes){let c=u(r.name);l.set(r.name,c);let d=o[r.kind]??"rectangle",k=`${r.name} (${r.kind}) = ${f(r.value)}`,j=r.status?` [${r.status}]`:"";s.push(`${c}: "${k}${j}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let r of n.edges){let c=l.get(r.from)??u(r.from),d=l.get(r.to)??u(r.to);s.push(`${c} -> ${d}`)}return s.join(`
4
- `)}static annotate(t,i){if(!e.enabled)return;e._annotations.set(t,i);let n={node:e._resolveKey(t),reason:i,timestamp:Date.now()},s=e.maxTraceEntries;s<=0||(e._traceLog.length<s?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%s)}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 _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 z=1,y=64,m=2,P=4,ye=8,be=16,O=32,D=1024,h=ne,A=fe<<x,C=de<<x,B=ce<<x,Me=ge<<x,We=he<<x,je=pe<<x,M=class{_value;_output=null;_flags;get _status(){return Se(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,i){this._value=i?.initial,this._fn=t,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=P),i?.resetOnTeardown&&(n|=ye),i?.resubscribable&&(n|=be),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||v.register(this,{kind:"producer",...i})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,i){let n=this._output;if(n)if(this._flags&y)for(let s of n)s(t,i);else n(t,i)}emit(t){this._flags&m||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(Y()?this._flags&O||(this._flags|=O,this._flags&P&&(this._flags=this._flags&~h|A,this._dispatch(T,b)),V(()=>{this._flags&=~O,this._flags=this._flags&~h|C,this._dispatch(E,this._value)})):(this._flags&P&&!(this._flags&D)&&(this._flags=this._flags&~h|A,this._dispatch(T,b)),this._flags=this._flags&~h|C,this._dispatch(E,this._value))))}signal(t){this._flags&m||!this._output||(t===b?this._flags=this._flags&~h|A:t===$&&(this._flags=this._flags&~h|je),this._dispatch(T,t))}complete(){if(this._flags&m)return;this._flags=(this._flags|m)&~h|Me;let t=this._output,i=this._flags&y;if(this._output=null,this._flags&=~(y|D),this._singleDepCount=0,this._stop(),t)if(i)for(let n of t)n(g);else t(g)}error(t){if(this._flags&m)return;this._flags=(this._flags|m)&~h|We;let i=this._output,n=this._flags&y;if(this._output=null,this._flags&=~(y|D),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,t);else i(g,t)}_start(){if(this._flags&z||!this._fn)return;this._flags|=z,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i),onSignal:i=>{this._onLifecycleSignal=i}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&z&&(this._flags&=~z,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&ye&&(this._value=this._initial),this._flags&m||(this._flags=this._flags&~h|B))}_handleLifecycleSignal(t){if(!(this._flags&m)){if(t===te){this._onLifecycleSignal?.(t),this.complete();return}t===I&&(this._value=this._initial,this._flags&=~O),this._onLifecycleSignal?.(t),t===I&&this.emit(this._initial)}}source(t,i){if(t===_){let n=i;if(this._flags&m)if(this._flags&be&&this._output===null)this._flags=this._flags&~(m|h)|B;else{n(_,o=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&y)this._output.add(n);else{let o=new Set;o.add(this._output),o.add(n),this._output=o,this._flags=(this._flags|y)&~D}let s=!1;n(_,(o,a)=>{if(o===E&&n(E,this._value),o===T){a===ue&&!s?(s=!0,this._singleDepCount++,this._flags&y||(this._flags|=D)):le(a)&&this._handleLifecycleSignal(a);return}if(o===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&y){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~y,this._singleDepCount>0&&(this._flags|=D)):u.size===0&&(this._output=null,this._flags&=~(y|D),this._singleDepCount=0,this._flags=this._flags&~h|B,this._stop())}else this._output===n&&(this._output=null,this._flags&=~D,this._singleDepCount=0,this._flags=this._flags&~h|B,this._stop())}}),me(()=>this._start())}}};function J(e,t){return new M(e,t)}var ie=class extends M{constructor(t,i){super(void 0,{initial:t,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),v.register(this,{kind:"state",...i})}get(){return this._value}set(t){this._flags&m||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(Y()?this._flags&O||(this._flags|=O,this._flags&P&&(this._flags=this._flags&~h|A,this._dispatch(T,b)),V(()=>{this._flags&=~O,this._flags=this._flags&~h|C,this._dispatch(E,this._value)})):(this._flags&P&&!(this._flags&D)&&(this._flags=this._flags&~h|A,this._dispatch(T,b)),this._flags=this._flags&~h|C,this._dispatch(E,this._value))))}update(t){this.set(t(this._value))}};function W(e,t){return new ie(e,t)}function Ee(e,t,i){let n=null;_e(),e.source(_,(o,a)=>{if(o===_&&(n=a),o===g){n=null,i?.onEnd?.(a);return}if(o===1){let u=a,l=s;s=u,t(u,l)}});let s;try{s=e.get()}catch{}return Te(),{unsubscribe(){n?.(g),n=null},signal(o){n?.(T,o)}}}function ve(e,t){let i=t?.initialStatus??"pending",n=W(i,{name:"withStatus:status",equals:Object.is}),s=W(void 0,{name:"withStatus:error",equals:Object.is}),o=J(({emit:u,complete:l,error:f})=>{n.set(i),s.set(void 0);let r=Ee(e,c=>{n.get()==="errored"?se(()=>{s.set(void 0),n.set("active")}):n.set("active"),u(c)},{onEnd:c=>{if(c!==void 0){let d=c instanceof Error?c:new Error(String(c));se(()=>{s.set(d),n.set("errored")}),f(c)}else n.set("completed"),l()}});return()=>{r.unsubscribe()}},{initial:e.get(),resubscribable:!0}),a={get:()=>e.get(),source:(u,l)=>o.source(u,l),get _status(){return o._status},status:n,error:s};return v.register(a,{kind:"withStatus"}),a}function Ke(e){let t=e?.path??"/",i=e?.parse??JSON.parse,n=e?.name??"webhook",s=e?.hostname??"0.0.0.0",o=e?.maxBodySize??1024*1024,a=e?.responseTimeout??3e4,u=W(0,{name:`${n}:count`}),l=null,f=!1,r=J(({emit:S,onSignal:p})=>(l=S,f=!1,p(R=>{R===X?f=!0:R===ee?f=!1:R===I&&(f=!1,u.set(0))}),()=>{l=null,f=!1}),{name:n,kind:"webhook"});v.register(r,{kind:"webhook"});let c=ve(r),d=null,k=new Set;function j(S,p){let R=S.method?.toUpperCase(),xe=(S.url??"/").split("?")[0];if(R!=="POST"||xe!==t){p.writeHead(404,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Not found"}));return}if(f){p.writeHead(503,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Service paused"}));return}let oe=[],ae=0,K=!1;S.on("error",()=>{K=!0,p.headersSent||(p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Request aborted"})))}),S.on("data",L=>{if(!K){if(ae+=L.length,ae>o){K=!0,p.writeHead(413,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Payload too large"})),S.destroy?.();return}oe.push(L)}}),S.on("end",()=>{if(!K)try{let L=Buffer.concat(oe).toString("utf-8"),Re=L.length>0?i(L):void 0;u.update(G=>G+1);let N=!1,w=null,we={body:Re,get responded(){return N},respond(G,Oe=200){N||(N=!0,w!==null&&(clearTimeout(w),k.delete(w),w=null),p.writeHead(Oe,{"Content-Type":"application/json"}),p.end(JSON.stringify(G)))}};w=setTimeout(()=>{k.delete(w),w=null,N||(N=!0,p.writeHead(504,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Response timeout"})))},a),k.add(w),l?.(we)}catch(L){p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:L?.message??"Parse error"}))}})}function De(){return e?.port?d?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):new Promise((S,p)=>{try{d=require("http").createServer(j),d.once("listening",()=>S()),d.once("error",re=>{d=null,p(re)}),d.listen(e.port,s)}catch(R){p(R)}}):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function ke(){for(let S of k)clearTimeout(S);k.clear(),d?.close(),d=null}return{get:()=>c.get(),source:(S,p)=>c.source(S,p),status:c.status,error:c.error,requestCount:u,handler:j,listen:De,close:ke}}0&&(module.exports={fromWebhook});
1
+ "use strict";var Z=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var $e=(e,t)=>{for(var i in t)Z(e,i,{get:t[i],enumerable:!0})},Me=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ae(t))!Ce.call(e,s)&&s!==i&&Z(e,s,{get:()=>t[s],enumerable:!(n=Ne(t,s))||n.enumerable});return e};var je=e=>Me(Z({},"__esModule",{value:!0}),e);var He={};$e(He,{fromWebhook:()=>Ue});module.exports=je(He);var b=Symbol("DIRTY"),C=Symbol("RESOLVED"),ue=Symbol("SINGLE_DEP"),I=Symbol("RESET"),X=Symbol("PAUSE"),ee=Symbol("RESUME"),te=Symbol("TEARDOWN");function le(e){return e===I||e===X||e===ee||e===te}var ce=0,fe=1,de=2,pe=3,ge=4,he=5,x=7,ne=7<<x,We=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function Se(e){return We[(e&ne)>>>x]}var T=0,v=1,g=2,_=3,K=0,q=[],Q=!1;function se(e){K++;try{return e()}finally{if(K--,K===0&&!Q){Q=!0;for(let t=0;t<q.length;t++)q[t]();q.length=0,Q=!1}}}function Y(){return K>0}function V(e){q.push(e)}var H=0,U=[];function Te(){H++}function _e(){if(H--,H===0){for(let e=0;e<U.length;e++)U[e]();U.length=0}}function me(e){H>0?U.push(e):e()}var E=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(s=>e._names.get(s)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let i=e._keys.get(t)??e._names.get(t);if(i)return i;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,i){if(!e.enabled)return;i?.name&&e._names.set(t,i.name),i?.kind&&e._kinds.set(t,i.kind);let n=e._nextId++,s=i?.name;if(!(s&&!e._usedKeys.has(s)))if(s){let r=e._depSuffix(i?.deps);s=r?`${s}(${r})`:`${s}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let r=i?.kind??"store",a=e._depSuffix(i?.deps);s=a?`${r}(${a})`:`${r}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}e._usedKeys.add(s),e._keys.set(t,s),e._stores.add(new WeakRef(t))}static registerEdge(t,i){if(!e.enabled)return;let n=e._resolveKey(t),s=e._resolveKey(i),r=e._edges.get(n);r?r.includes(s)||r.push(s):e._edges.set(n,[s])}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,i=new Set;for(let n of e._stores){let s=n.deref();if(!s){e._stores.delete(n);continue}let r=e._resolveKey(s);i.add(r),t.set(r,e.inspect(s))}for(let[n,s]of e._edges){if(!i.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let r=s.filter(a=>i.has(a));r.length===0?e._edges.delete(n):r.length!==s.length&&e._edges.set(n,r)}return t}static trace(t,i){let n=null,s=t.get();return t.source(T,(r,a)=>{if(r===T&&(n=a),r===g){n=null;return}if(r===1){let u=a;if(!Object.is(u,s)){let l=s;s=u,i(u,l)}}}),()=>n?.(g)}static dumpGraph(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let[a,u]of i)for(let l of u){let f=n.get(l);f?f.includes(a)||f.push(a):n.set(l,[a])}let s=[];for(let[a,u]of t){let l=n.get(a),f=i.get(a),o=l?.length?` \u2190 [${l.join(", ")}]`:"",c=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${o}${c}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
2
+ `)}static _signalLabel(t){return t===b?"DIRTY":t===C?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,i,n){let s=null,r=!1,a=i??e.getName(t),u=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!r},get errored(){return l.ended&&r},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return u},dispose:()=>s?.(g),reconnect:()=>(s?.(g),e._observe(t,i,n))};return t.source(T,(f,o)=>{if(f===T){s=o;return}f===v?(l.values.push(o),l.events.push({type:"data",data:o}),u.push(o),n&&n(`[${a}] DATA:`,o)):f===_?(l.signals.push(o),l.events.push({type:"signal",data:o}),u.push(e._signalLabel(o)),o===b?l.dirtyCount++:o===C&&l.resolvedCount++,n&&n(`[${a}] STATE:`,o)):f===g&&(l.ended=!0,l.endError=o,r=o!==void 0,l.events.push({type:"end",data:o}),u.push(r?["END",o]:"END"),n&&n(`[${a}] END`,o!==void 0?o:""),s=null)}),l}static observe(t){return e._observe(t)}static activate(t){let i=null;return t.source(T,(n,s)=>{n===T&&(i=s),n===g&&(i=null)}),()=>i?.(g)}static tap(t,i){let n=i??`tap(${e.getName(t)??"anon"})`,s={get:()=>t.get(),source:t.source};return e.register(s,{name:n,kind:"tap"}),e.registerEdge(t,s),s}static spy(t,i){let n=i?.name??e.getName(t)??"spy",s=i?.log??console.log;return e._observe(t,n,s)}static snapshot(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let a of e._stores){let u=a.deref();if(!u)continue;let l=e._annotations.get(u);l!==void 0&&n.set(e._resolveKey(u),l)}let s=[];for(let[a,u]of t){let l={name:a,kind:u.kind,value:u.value,status:u.status},f=n.get(a);f!==void 0&&(l.annotation=f),s.push(l)}let r=[];for(let[a,u]of i)for(let l of u)r.push({from:a,to:l});return{nodes:s,edges:r,trace:e.traceLog()}}static toMermaid(t){let i=t?.direction??"TD",n=e.snapshot(),s=[`graph ${i}`],r={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},a=new Map;function u(o){let c=o.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(c);return d===void 0?(a.set(c,1),c):(a.set(c,d+1),`${c}__${d}`)}let l=new Map;function f(o){let c=JSON.stringify(o);return c&&c.length>30?`${c.slice(0,27)}...`:c??"undefined"}for(let o of n.nodes){let c=u(o.name);l.set(o.name,c);let d=`${o.name} (${o.kind}) = ${f(o.value)}`,k=r[o.status??""]??"";s.push(` ${c}["${d}"]${k}`)}for(let o of n.edges){let c=l.get(o.from)??u(o.from),d=l.get(o.to)??u(o.to);s.push(` ${c} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
+ `)}static toD2(t){let i=t?.direction??"down",n=e.snapshot(),s=[`direction: ${i}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},a=new Map;function u(o){let c=o.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(c);return d===void 0?(a.set(c,1),c):(a.set(c,d+1),`${c}__${d}`)}let l=new Map;function f(o){let c=JSON.stringify(o);return c&&c.length>30?`${c.slice(0,27)}...`:c??"undefined"}for(let o of n.nodes){let c=u(o.name);l.set(o.name,c);let d=r[o.kind]??"rectangle",k=`${o.name} (${o.kind}) = ${f(o.value)}`,W=o.status?` [${o.status}]`:"";s.push(`${c}: "${k}${W}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let o of n.edges){let c=l.get(o.from)??u(o.from),d=l.get(o.to)??u(o.to);s.push(`${c} -> ${d}`)}return s.join(`
4
+ `)}static annotate(t,i){if(!e.enabled)return;e._annotations.set(t,i);let n={node:e._resolveKey(t),reason:i,timestamp:Date.now()},s=e.maxTraceEntries;s<=0||(e._traceLog.length<s?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%s)}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 _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 z=1,y=64,m=2,P=4,ye=8,be=16,O=32,D=1024,h=ne,N=fe<<x,$=de<<x,B=ce<<x,Fe=ge<<x,Ke=he<<x,qe=pe<<x,M=class{_value;_output=null;_flags;get _status(){return Se(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,i){this._value=i?.initial,this._fn=t,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=P),i?.resetOnTeardown&&(n|=ye),i?.resubscribable&&(n|=be),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||E.register(this,{kind:"producer",...i})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,i){let n=this._output;if(n)if(this._flags&y)for(let s of n)s(t,i);else n(t,i)}emit(t){this._flags&m||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(Y()?this._flags&O||(this._flags|=O,this._flags&P&&(this._flags=this._flags&~h|N,this._dispatch(_,b)),V(()=>{this._flags&=~O,this._flags=this._flags&~h|$,this._dispatch(v,this._value)})):(this._flags&P&&!(this._flags&D)&&(this._flags=this._flags&~h|N,this._dispatch(_,b)),this._flags=this._flags&~h|$,this._dispatch(v,this._value))))}signal(t){this._flags&m||!this._output||(t===b?this._flags=this._flags&~h|N:t===C&&(this._flags=this._flags&~h|qe),this._dispatch(_,t))}complete(){if(this._flags&m)return;this._flags=(this._flags|m)&~h|Fe;let t=this._output,i=this._flags&y;if(this._output=null,this._flags&=~(y|D),this._singleDepCount=0,this._stop(),t)if(i)for(let n of t)n(g);else t(g)}error(t){if(this._flags&m)return;this._flags=(this._flags|m)&~h|Ke;let i=this._output,n=this._flags&y;if(this._output=null,this._flags&=~(y|D),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,t);else i(g,t)}_start(){if(this._flags&z||!this._fn)return;this._flags|=z,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i),onSignal:i=>{this._onLifecycleSignal=i}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&z&&(this._flags&=~z,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&ye&&(this._value=this._initial),this._flags&m||(this._flags=this._flags&~h|B))}_handleLifecycleSignal(t){if(!(this._flags&m)){if(t===te){this._onLifecycleSignal?.(t),this.complete();return}t===I&&(this._value=this._initial,this._flags&=~O),this._onLifecycleSignal?.(t),t===I&&this.emit(this._initial)}}source(t,i){if(t===T){let n=i;if(this._flags&m)if(this._flags&be&&this._output===null)this._flags=this._flags&~(m|h)|B;else{n(T,r=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&y)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|y)&~D}let s=!1;n(T,(r,a)=>{if(r===v&&n(v,this._value),r===_){a===ue&&!s?(s=!0,this._singleDepCount++,this._flags&y||(this._flags|=D)):le(a)&&this._handleLifecycleSignal(a);return}if(r===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&y){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~y,this._singleDepCount>0&&(this._flags|=D)):u.size===0&&(this._output=null,this._flags&=~(y|D),this._singleDepCount=0,this._flags=this._flags&~h|B,this._stop())}else this._output===n&&(this._output=null,this._flags&=~D,this._singleDepCount=0,this._flags=this._flags&~h|B,this._stop())}}),me(()=>this._start())}}};function J(e,t){return new M(e,t)}var ie=class extends M{constructor(t,i){super(void 0,{initial:t,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),E.register(this,{kind:"state",...i})}get(){return this._value}set(t){this._flags&m||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(Y()?this._flags&O||(this._flags|=O,this._flags&P&&(this._flags=this._flags&~h|N,this._dispatch(_,b)),V(()=>{this._flags&=~O,this._flags=this._flags&~h|$,this._dispatch(v,this._value)})):(this._flags&P&&!(this._flags&D)&&(this._flags=this._flags&~h|N,this._dispatch(_,b)),this._flags=this._flags&~h|$,this._dispatch(v,this._value))))}update(t){this.set(t(this._value))}};function j(e,t){return new ie(e,t)}function ve(e,t,i){let n=null;return e(0,(s,r)=>{if(s===0){n=r;return}if(s===2){n=null,i?.onEnd?.(r);return}s===1&&t(r)}),{unsubscribe(){n?.(2),n=null}}}function Ee(e,t){return new Promise((i,n)=>{let s=ve(e,r=>{(!t||t(r))&&(s.unsubscribe(),i(r))},{onEnd:r=>{n(r??new Error("source completed without matching value"))}})})}function De(e){return(t,i)=>{if(t!==0)return;let n=!1,s;i(0,r=>{r===2&&!n&&(n=!0,s?.())});try{s=e(r=>{n||(n=!0,i(1,r),i(2))},r=>{n||(n=!0,i(2,r))})}catch(r){n||(n=!0,i(2,r))}}}function ke(e,t,i){let n=null;Te(),e.source(T,(r,a)=>{if(r===T&&(n=a),r===g){n=null,i?.onEnd?.(a);return}if(r===1){let u=a,l=s;s=u,t(u,l)}});let s;try{s=e.get()}catch{}return _e(),{unsubscribe(){n?.(g),n=null},signal(r){n?.(_,r)}}}function xe(e,t){let i=t?.initialStatus??"pending",n=j(i,{name:"withStatus:status",equals:Object.is}),s=j(void 0,{name:"withStatus:error",equals:Object.is}),r=J(({emit:u,complete:l,error:f})=>{n.set(i),s.set(void 0);let o=ke(e,c=>{n.get()==="errored"?se(()=>{s.set(void 0),n.set("active")}):n.set("active"),u(c)},{onEnd:c=>{if(c!==void 0){let d=c instanceof Error?c:new Error(String(c));se(()=>{s.set(d),n.set("errored")}),f(c)}else n.set("completed"),l()}});return()=>{o.unsubscribe()}},{initial:e.get(),resubscribable:!0}),a={get:()=>e.get(),source:(u,l)=>r.source(u,l),get _status(){return r._status},status:n,error:s};return E.register(a,{kind:"withStatus"}),a}function Ue(e){let t=e?.path??"/",i=e?.parse??JSON.parse,n=e?.name??"webhook",s=e?.hostname??"0.0.0.0",r=e?.maxBodySize??1024*1024,a=e?.responseTimeout??3e4,u=j(0,{name:`${n}:count`}),l=null,f=!1,o=J(({emit:S,onSignal:p})=>(l=S,f=!1,p(R=>{R===X?f=!0:R===ee?f=!1:R===I&&(f=!1,u.set(0))}),()=>{l=null,f=!1}),{name:n,kind:"webhook"});E.register(o,{kind:"webhook"});let c=xe(o),d=null,k=new Set;function W(S,p){let R=S.method?.toUpperCase(),Oe=(S.url??"/").split("?")[0];if(R!=="POST"||Oe!==t){p.writeHead(404,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Not found"}));return}if(f){p.writeHead(503,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Service paused"}));return}let oe=[],ae=0,F=!1;S.on("error",()=>{F=!0,p.headersSent||(p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Request aborted"})))}),S.on("data",L=>{if(!F){if(ae+=L.length,ae>r){F=!0,p.writeHead(413,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Payload too large"})),S.destroy?.();return}oe.push(L)}}),S.on("end",()=>{if(!F)try{let L=Buffer.concat(oe).toString("utf-8"),Le=L.length>0?i(L):void 0;u.update(G=>G+1);let A=!1,w=null,Ie={body:Le,get responded(){return A},respond(G,Pe=200){A||(A=!0,w!==null&&(clearTimeout(w),k.delete(w),w=null),p.writeHead(Pe,{"Content-Type":"application/json"}),p.end(JSON.stringify(G)))}};w=setTimeout(()=>{k.delete(w),w=null,A||(A=!0,p.writeHead(504,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Response timeout"})))},a),k.add(w),l?.(Ie)}catch(L){p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:L?.message??"Parse error"}))}})}function Re(){return e?.port?d?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):Ee(De((S,p)=>{try{d=require("http").createServer(W),d.once("listening",()=>S()),d.once("error",re=>{d=null,p(re)}),d.listen(e.port,s);return}catch(R){p(R);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function we(){for(let S of k)clearTimeout(S);k.clear(),d?.close(),d=null}return{get:()=>c.get(),source:(S,p)=>c.source(S,p),status:c.status,error:c.error,requestCount:u,handler:W,listen:Re,close:we}}0&&(module.exports={fromWebhook});
@@ -1 +1 @@
1
- import{a}from"../chunk-UA3L7KUP.js";import"../chunk-S2U5T7BO.js";import"../chunk-GMLWTZFM.js";import"../chunk-7FX2AO6N.js";import"../chunk-VFN2CV32.js";import"../chunk-SOIVZBGE.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromWebhook};
1
+ import{a}from"../chunk-N7Y355ED.js";import"../chunk-XEU7KSEO.js";import"../chunk-LLARZ7J7.js";import"../chunk-S2U5T7BO.js";import"../chunk-GMLWTZFM.js";import"../chunk-7FX2AO6N.js";import"../chunk-VFN2CV32.js";import"../chunk-SOIVZBGE.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromWebhook};
@@ -0,0 +1 @@
1
+ function b(e){return()=>e}function l(e,t=e){return o=>e+t*o}function p(e){let t=e?.base??100,o=e?.factor??2,n=e?.maxDelay??3e4,r=e?.jitter??"none";return u=>{let a=Math.min(t*o**u,n);return m(a,r)}}function s(e=100,t=3e4){return o=>{let n=1,r=1;for(let u=0;u<o;u++){let a=n+r;n=r,r=a}return Math.min(n*e,t)}}function x(e=100,t=3e4){return(o,n,r)=>{let a=Math.min(t,(r??e)*3);return i(e,a)}}function y(e,t){return(o,n,r)=>o>=t?null:e(o,n,r)}function m(e,t){switch(t){case"none":return e;case"full":return i(0,e);case"equal":return e/2+i(0,e/2)}}function i(e,t){return e+Math.random()*(t-e)}function d(e,t){return(o,n)=>{if(o!==0)return;let r=!1;function u(){r||(r=!0,clearTimeout(c),t?.removeEventListener("abort",a),n(1,void 0),n(2))}function a(){u()}if(n(0,f=>{f===2&&!r&&(r=!0,clearTimeout(c),t?.removeEventListener("abort",a))}),t?.aborted){u();return}let c=setTimeout(u,e);t?.addEventListener("abort",a,{once:!0})}}export{d as a,b,l as c,p as d,s as e,x as f,y as g};
@@ -0,0 +1 @@
1
+ import{a as h}from"./chunk-QSFTSBDR.js";import{a as i}from"./chunk-7FX2AO6N.js";import{B as R}from"./chunk-TUPD47IE.js";function A(a,f){let c=Math.max(1,f?.concurrency??1),u=f?.strategy??"fifo",t=f?.name??"asyncQueue",m=i(0,{name:`${t}.size`}),d=i(0,{name:`${t}.running`}),b=i(0,{name:`${t}.completed`}),k=i(0,{name:`${t}.failed`}),p=i(!1,{name:`${t}.paused`}),o=[],s=0,l=!1;function T(r,e){l||(s--,d.set(s),b.update(n=>n+1),r.done$.set({ok:!0,result:e}),y())}function g(r,e){l||(s--,d.set(s),k.update(n=>n+1),r.done$.set({ok:!1,error:e}),y())}function y(){if(!(l||p.get()))for(;s<c&&o.length>0;){let r=u==="lifo"?o.pop():o.shift();m.set(o.length),s++,d.set(s);try{a(r.task).then(e=>T(r,e),e=>g(r,e))}catch(e){g(r,e)}}}function Q(r){if(l)return Promise.reject(new Error("Queue is disposed"));let e=i(null,{name:`${t}.task`});return o.push({task:r,done$:e}),m.set(o.length),y(),h(e,n=>n!==null).then(n=>{if(R(e),n.ok)return n.result;throw n.error},n=>{throw R(e),n})}function w(){p.set(!0)}function $(){p.set(!1),y()}function S(){let r=o.splice(0,o.length);m.set(0);for(let e of r)e.done$.set({ok:!1,error:new Error("Queue cleared")})}function v(){l||(l=!0,S())}return{enqueue:Q,size:m,running:d,completed:b,failed:k,pause:w,resume:$,paused:p,clear:S,dispose:v}}function C(a){return(f,c)=>{if(f!==0)return;let u=!1;c(0,t=>{t===2&&(u=!0)}),a.onsuccess=()=>{u||(u=!0,c(1,a.result),c(2))},a.onerror=()=>{u||(u=!0,c(2,a.error))}}}export{A as a,C as b};
@@ -0,0 +1 @@
1
+ function i(u,e,l){let n=null;return u(0,(o,r)=>{if(o===0){n=r;return}if(o===2){n=null,l?.onEnd?.(r);return}o===1&&e(r)}),{unsubscribe(){n?.(2),n=null}}}function t(u,e){return new Promise((l,n)=>{let o=i(u,r=>{(!e||e(r))&&(o.unsubscribe(),l(r))},{onEnd:r=>{n(r??new Error("source completed without matching value"))}})})}export{t as a};
@@ -0,0 +1 @@
1
+ import{a as q}from"./chunk-XEU7KSEO.js";import{a as O}from"./chunk-LLARZ7J7.js";import{a as N}from"./chunk-S2U5T7BO.js";import{a as v}from"./chunk-7FX2AO6N.js";import{i as R}from"./chunk-VFN2CV32.js";import{a as C}from"./chunk-SOIVZBGE.js";import{d as g,e as w,f as W}from"./chunk-TUPD47IE.js";import{a as A}from"./chunk-I7AUKTXE.js";function K(o){let P=o?.path??"/",j=o?.parse??JSON.parse,y=o?.name??"webhook",x=o?.hostname??"0.0.0.0",E=o?.maxBodySize??1024*1024,J=o?.responseTimeout??3e4,p=v(0,{name:`${y}:count`}),c=null,a=!1,h=R(({emit:t,onSignal:e})=>(c=t,a=!1,e(n=>{n===w?a=!0:n===W?a=!1:n===g&&(a=!1,p.set(0))}),()=>{c=null,a=!1}),{name:y,kind:"webhook"});C.register(h,{kind:"webhook"});let d=N(h),r=null,u=new Set;function S(t,e){let n=t.method?.toUpperCase(),z=(t.url??"/").split("?")[0];if(n!=="POST"||z!==P){e.writeHead(404,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"Not found"}));return}if(a){e.writeHead(503,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"Service paused"}));return}let T=[],k=0,f=!1;t.on("error",()=>{f=!0,e.headersSent||(e.writeHead(400,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"Request aborted"})))}),t.on("data",s=>{if(!f){if(k+=s.length,k>E){f=!0,e.writeHead(413,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"Payload too large"})),t.destroy?.();return}T.push(s)}}),t.on("end",()=>{if(!f)try{let s=Buffer.concat(T).toString("utf-8"),U=s.length>0?j(s):void 0;p.update(m=>m+1);let l=!1,i=null,_={body:U,get responded(){return l},respond(m,L=200){l||(l=!0,i!==null&&(clearTimeout(i),u.delete(i),i=null),e.writeHead(L,{"Content-Type":"application/json"}),e.end(JSON.stringify(m)))}};i=setTimeout(()=>{u.delete(i),i=null,l||(l=!0,e.writeHead(504,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"Response timeout"})))},J),u.add(i),c?.(_)}catch(s){e.writeHead(400,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:s?.message??"Parse error"}))}})}function H(){return o?.port?r?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):O(q((t,e)=>{try{r=A("http").createServer(S),r.once("listening",()=>t()),r.once("error",b=>{r=null,e(b)}),r.listen(o.port,x);return}catch(n){e(n);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function B(){for(let t of u)clearTimeout(t);u.clear(),r?.close(),r=null}return{get:()=>d.get(),source:(t,e)=>d.source(t,e),status:d.status,error:d.error,requestCount:p,handler:S,listen:H,close:B}}export{K as a};
@@ -0,0 +1 @@
1
+ import{i as e}from"./chunk-VFN2CV32.js";function f(t,n){return e(({emit:o})=>{let u=0,r=setInterval(()=>o(u++),t);return n?.unref&&typeof r=="object"&&"unref"in r&&r.unref(),()=>clearInterval(r)})}export{f as a};
@@ -0,0 +1 @@
1
+ import{a as t}from"./chunk-LLARZ7J7.js";function s(e,r){try{let o=e.get();if(!r||r(o))return Promise.resolve(o)}catch{}return t(e.source,r)}export{s as a};
@@ -0,0 +1,11 @@
1
+ import{a as C}from"./chunk-XEU7KSEO.js";import{a as g}from"./chunk-LLARZ7J7.js";import{a as y}from"./chunk-GMLWTZFM.js";import{a as w}from"./chunk-7FX2AO6N.js";import{a as v}from"./chunk-SOIVZBGE.js";function M(f,t){let b=t?.path??"/",E=t?.name??"sse",T=t?.hostname??"0.0.0.0",d=t?.serialize??JSON.stringify,p=t?.eventName??"message",S=t?.pingInterval??3e4,s=w(0,{name:`${E}:connections`}),o=new Set,c=new Map,i=null;function I(){i||(i=y(f,n=>{let e=d(n),a=`event: ${p}
2
+ data: ${e}
3
+
4
+ `;for(let l of o)try{l.write(a)}catch{m(l)}}))}function m(n){o.delete(n);let e=c.get(n);e&&(clearInterval(e),c.delete(n)),s.set(o.size),o.size===0&&i&&(i.unsubscribe(),i=null)}function h(n,e){let a=n.method?.toUpperCase();if((n.url??"/").split("?")[0]!==b){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Not found");return}if(a==="OPTIONS"){e.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),e.end();return}if(a!=="GET"){e.writeHead(405,{"Content-Type":"text/plain"}),e.end("Method not allowed");return}e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),e.write(`:ok
5
+
6
+ `),o.add(e),s.set(o.size);try{let u=f.get();if(u!==void 0){let O=d(u);e.write(`event: ${p}
7
+ data: ${O}
8
+
9
+ `)}}catch{}if(S>0){let u=setInterval(()=>{try{e.write(`:ping
10
+
11
+ `)}catch{m(e)}},S);c.set(e,u)}n.on("close",()=>m(e)),I()}let r=null;async function A(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(r)throw new Error("toSSE: already listening. Call close() first.");let n=await import("http");return g(C((e,a)=>{r=n.createServer(h),r.once("listening",()=>e()),r.once("error",l=>{r=null,a(l)}),r.listen(t.port,T)}))}function N(){for(let n of o)try{n.end()}catch{}o.clear();for(let n of c.values())clearInterval(n);c.clear(),s.set(0),i?.unsubscribe(),i=null,r?.close(),r=null}return v.register(s,{kind:"sse"}),{connectionCount:s,handler:h,listen:A,close:N}}export{M as a};
@@ -0,0 +1 @@
1
+ function d(t){return(n,o)=>{if(n!==0)return;let e=!1,u;o(0,r=>{r===2&&!e&&(e=!0,u?.())});try{u=t(r=>{e||(e=!0,o(1,r),o(2))},r=>{e||(e=!0,o(2,r))})}catch(r){e||(e=!0,o(2,r))}}}export{d as a};