@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.
- package/dist/adapters/index.cjs +11 -11
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/sse.cjs +8 -8
- package/dist/adapters/sse.js +1 -1
- package/dist/adapters/webhook.cjs +4 -4
- package/dist/adapters/webhook.js +1 -1
- package/dist/chunk-4AGPQIMR.js +1 -0
- package/dist/chunk-JEZ26E63.js +1 -0
- package/dist/chunk-LLARZ7J7.js +1 -0
- package/dist/chunk-N7Y355ED.js +1 -0
- package/dist/chunk-PQPV3OXB.js +1 -0
- package/dist/chunk-QSFTSBDR.js +1 -0
- package/dist/chunk-VN3XFROF.js +11 -0
- package/dist/chunk-XEU7KSEO.js +1 -0
- package/dist/extra/index.cjs +4 -4
- package/dist/extra/index.d.cts +37 -1
- package/dist/extra/index.d.ts +37 -1
- package/dist/extra/index.js +1 -1
- package/dist/extra/interval.cjs +4 -4
- package/dist/extra/interval.d.cts +7 -2
- package/dist/extra/interval.d.ts +7 -2
- package/dist/extra/interval.js +1 -1
- package/dist/extra/subscribe.d.cts +5 -4
- package/dist/extra/subscribe.d.ts +5 -4
- package/dist/messaging/index.cjs +6 -6
- package/dist/messaging/index.d.cts +1 -1
- package/dist/messaging/index.d.ts +1 -1
- package/dist/messaging/index.js +3 -3
- package/dist/orchestrate/index.cjs +8 -8
- package/dist/orchestrate/index.js +5 -5
- package/dist/utils/index.cjs +4 -4
- package/dist/utils/index.d.cts +48 -1
- package/dist/utils/index.d.ts +48 -1
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BR63MTNP.js +0 -1
- package/dist/chunk-EXDWEL6X.js +0 -11
- package/dist/chunk-GO4JTIJI.js +0 -1
- package/dist/chunk-T2RGZ54Y.js +0 -1
- package/dist/chunk-UA3L7KUP.js +0 -1
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}static _signalLabel(t){return t===
|
|
3
|
-
`)}static toD2(t){let
|
|
4
|
-
`)}static annotate(t,
|
|
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=
|
|
6
|
-
`),E=new Error(
|
|
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
|
|
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
|
|
12
|
-
data: ${
|
|
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(
|
|
14
|
+
`)}}catch{}if(a>0){let _=setInterval(()=>{try{p.write(`:ping
|
|
15
15
|
|
|
16
|
-
`)}catch{m(p)}},
|
|
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});
|
package/dist/adapters/index.js
CHANGED
|
@@ -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-
|
|
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};
|
package/dist/adapters/sse.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}static _signalLabel(t){return t===v?"DIRTY":t
|
|
3
|
-
`)}static toD2(t){let i=t?.direction??"down",n=e.snapshot(),s=[`direction: ${i}`,""],
|
|
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,
|
|
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{
|
|
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
|
|
10
|
-
data: ${
|
|
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{
|
|
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});
|
package/dist/adapters/sse.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
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
|
|
2
|
-
`)}static _signalLabel(t){return t===b?"DIRTY":t
|
|
3
|
-
`)}static toD2(t){let i=t?.direction??"down",n=e.snapshot(),s=[`direction: ${i}`,""],
|
|
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,
|
|
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});
|
package/dist/adapters/webhook.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
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};
|