@callbag-recharge/callbag-recharge 0.23.0 → 0.24.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/README.md +11 -3
- package/dist/adapters/index.cjs +10 -11
- package/dist/adapters/index.d.cts +0 -1
- package/dist/adapters/index.d.ts +0 -1
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/sse.cjs +2 -2
- package/dist/adapters/sse.js +1 -1
- package/dist/adapters/webhook.cjs +3 -3
- package/dist/adapters/webhook.js +1 -1
- package/dist/ai/agentLoop/index.cjs +4 -0
- package/dist/{patterns → ai}/agentLoop/index.d.cts +2 -2
- package/dist/{patterns → ai}/agentLoop/index.d.ts +2 -2
- package/dist/ai/agentLoop/index.js +1 -0
- package/dist/{patterns → ai}/chatStream/index.d.cts +2 -2
- package/dist/{patterns → ai}/chatStream/index.d.ts +2 -2
- package/dist/ai/chatStream/index.js +1 -0
- package/dist/ai/conversationSummary/index.cjs +7 -0
- package/dist/ai/conversationSummary/index.d.cts +56 -0
- package/dist/ai/conversationSummary/index.d.ts +56 -0
- package/dist/ai/conversationSummary/index.js +1 -0
- package/dist/ai/docIndex/index.cjs +4 -0
- package/dist/ai/docIndex/index.d.cts +56 -0
- package/dist/ai/docIndex/index.d.ts +56 -0
- package/dist/ai/docIndex/index.js +1 -0
- package/dist/ai/embeddingIndex/index.cjs +4 -0
- package/dist/ai/embeddingIndex/index.d.cts +80 -0
- package/dist/ai/embeddingIndex/index.d.ts +80 -0
- package/dist/ai/embeddingIndex/index.js +1 -0
- package/dist/{adapters/llm.d.cts → ai/fromLLM.d.cts} +2 -2
- package/dist/{adapters/llm.d.ts → ai/fromLLM.d.ts} +2 -2
- package/dist/{adapters/llm.js → ai/fromLLM.js} +1 -1
- package/dist/{patterns → ai}/hybridRoute/index.d.cts +2 -2
- package/dist/{patterns → ai}/hybridRoute/index.d.ts +2 -2
- package/dist/ai/hybridRoute/index.js +1 -0
- package/dist/ai/index.cjs +17 -0
- package/dist/ai/index.d.cts +20 -0
- package/dist/ai/index.d.ts +20 -0
- package/dist/ai/index.js +1 -0
- package/dist/ai/memoryStore/index.cjs +4 -0
- package/dist/{patterns → ai}/memoryStore/index.d.cts +10 -4
- package/dist/{patterns → ai}/memoryStore/index.d.ts +10 -4
- package/dist/ai/memoryStore/index.js +1 -0
- package/dist/ai/ragPipeline/index.cjs +13 -0
- package/dist/ai/ragPipeline/index.d.cts +98 -0
- package/dist/ai/ragPipeline/index.d.ts +98 -0
- package/dist/ai/ragPipeline/index.js +1 -0
- package/dist/{patterns → ai}/toolCallState/index.d.cts +2 -2
- package/dist/{patterns → ai}/toolCallState/index.d.ts +2 -2
- package/dist/ai/toolCallState/index.js +1 -0
- package/dist/{checkpoint-DYPJl1rB.d.ts → checkpoint-Bycg2nWZ.d.ts} +1 -1
- package/dist/{checkpoint-Dy-WJA3r.d.cts → checkpoint-pDVUAV4-.d.cts} +1 -1
- package/dist/chunk-2BP7Z7ZL.js +1 -0
- package/dist/chunk-2PBFMNE3.js +10 -0
- package/dist/chunk-4ILN4V4C.js +1 -0
- package/dist/chunk-4VPAGOLZ.js +1 -0
- package/dist/chunk-6SUM4DCC.js +4 -0
- package/dist/{chunk-JLWDE534.js → chunk-7B4DHRG6.js} +1 -1
- package/dist/chunk-EPTXIJMZ.js +1 -0
- package/dist/chunk-F7IHZH7D.js +1 -0
- package/dist/chunk-GGTHKVOX.js +1 -0
- package/dist/chunk-GMHR7NSQ.js +1 -0
- package/dist/chunk-K56FIBDL.js +1 -0
- package/dist/{chunk-VCD3MXHY.js → chunk-LCCRCFKU.js} +1 -1
- package/dist/chunk-LJ4NZDHS.js +1 -0
- package/dist/chunk-OLSVNROW.js +1 -0
- package/dist/chunk-OZKWHUA6.js +1 -0
- package/dist/{chunk-NYLNL2Y5.js → chunk-PLIRVTP4.js} +1 -1
- package/dist/chunk-Q3HIBGHR.js +1 -0
- package/dist/chunk-QWMRZMRN.js +1 -0
- package/dist/chunk-RC3JWVKF.js +1 -0
- package/dist/chunk-USLFDJX2.js +1 -0
- package/dist/chunk-WQAE4SFB.js +1 -0
- package/dist/chunk-XH7BHK7V.js +1 -0
- package/dist/chunk-YOXJZ2O5.js +1 -0
- package/dist/data/index.js +1 -1
- package/dist/extra/fromPromise.cjs +4 -4
- package/dist/extra/fromPromise.d.cts +1 -1
- package/dist/extra/fromPromise.d.ts +1 -1
- package/dist/extra/fromPromise.js +1 -1
- package/dist/extra/index.cjs +4 -4
- package/dist/extra/index.js +1 -1
- package/dist/memory/index.js +1 -1
- 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 +1 -1
- package/dist/orchestrate/executionLogAdapters.node.cjs +6 -6
- package/dist/orchestrate/executionLogAdapters.node.js +1 -1
- package/dist/orchestrate/index.cjs +1 -1
- package/dist/orchestrate/index.js +2 -2
- package/dist/tokenTracker-BYan5lb-.d.ts +140 -0
- package/dist/tokenTracker-DGkjfZtH.d.cts +140 -0
- package/dist/utils/checkpointAdapters.node.d.cts +1 -1
- package/dist/utils/checkpointAdapters.node.d.ts +1 -1
- package/dist/utils/index.cjs +8 -8
- package/dist/utils/index.d.cts +4 -139
- package/dist/utils/index.d.ts +4 -139
- package/dist/utils/index.js +6 -6
- package/package.json +101 -51
- package/dist/chunk-2QHNHL5Y.js +0 -1
- package/dist/chunk-5PWKJDS3.js +0 -1
- package/dist/chunk-LHEDPW3C.js +0 -1
- package/dist/chunk-LLARZ7J7.js +0 -1
- package/dist/chunk-QSFTSBDR.js +0 -1
- package/dist/patterns/agentLoop/index.cjs +0 -4
- package/dist/patterns/agentLoop/index.js +0 -1
- package/dist/patterns/chatStream/index.js +0 -1
- package/dist/patterns/hybridRoute/index.js +0 -1
- package/dist/patterns/memoryStore/index.cjs +0 -4
- package/dist/patterns/memoryStore/index.js +0 -1
- package/dist/patterns/toolCallState/index.js +0 -1
- /package/dist/{patterns → ai}/chatStream/index.cjs +0 -0
- /package/dist/{adapters/llm.cjs → ai/fromLLM.cjs} +0 -0
- /package/dist/{patterns → ai}/hybridRoute/index.cjs +0 -0
- /package/dist/{patterns → ai}/toolCallState/index.cjs +0 -0
- /package/dist/{chunk-7WPMCM7F.js → chunk-VESAQ43T.js} +0 -0
package/README.md
CHANGED
|
@@ -273,15 +273,23 @@ self.expose('count', countStore)
|
|
|
273
273
|
|
|
274
274
|
## Patterns
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
Ten composed patterns on the primitives — import via `callbag-recharge/patterns/<name>`.
|
|
277
277
|
|
|
278
|
-
`createStore` · `
|
|
278
|
+
`createStore` · `commandBus` · `focusManager` · `formField` · `pagination` · `rateLimiter` · `selection` · `textBuffer` · `textEditor` · `undoRedo`
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## AI surface
|
|
283
|
+
|
|
284
|
+
LLM and agent primitives (Tier 5) — `callbag-recharge/ai` or `callbag-recharge/ai/<name>`.
|
|
285
|
+
|
|
286
|
+
`chatStream` · `agentLoop` · `toolCallState` · `memoryStore` · `hybridRoute` · `fromLLM` — plus re-exports: `checkpoint`, `indexedDBAdapter`, `tokenTracker`
|
|
279
287
|
|
|
280
288
|
---
|
|
281
289
|
|
|
282
290
|
## Adapters & compatibility
|
|
283
291
|
|
|
284
|
-
**Adapters** (`callbag-recharge/adapters`) — `
|
|
292
|
+
**Adapters** (`callbag-recharge/adapters`) — `fromWebSocket` · `fromSSE` · `fromWebhook` · `fromHTTP` · `fromMCP`
|
|
285
293
|
|
|
286
294
|
**Framework bindings** (`callbag-recharge/compat/*`) — Vue · React · Svelte · Solid · Zustand · Jotai · Nanostores · TC39 Signals
|
|
287
295
|
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}static _signalLabel(e){return e===
|
|
3
|
-
`)}static toD2(e){let
|
|
4
|
-
`)}static annotate(e,r){if(!t.enabled)return;t._annotations.set(e,r);let n={node:t._resolveKey(e),reason:r,timestamp:Date.now()},o=t.maxTraceEntries;o<=0||(t._traceLog.length<o?t._traceLog.push(n):(t._traceLog[t._traceHead]=n,t._traceFull=!0),t._traceHead=(t._traceHead+1)%o)}static getAnnotation(e){return t._annotations.get(e)}static traceLog(){return t._traceFull?[...t._traceLog.slice(t._traceHead),...t._traceLog.slice(0,t._traceHead)]:t._traceLog.slice(0,t._traceHead||t._traceLog.length)}static clearTrace(){t._traceLog=[],t._traceHead=0,t._traceFull=!1}static timeline(e){let r=null,n=[];return e.source(D,(o,s)=>{if(o===D){r=s;return}let u={timestamp:Date.now(),type:o===W?"data":o===M?"signal":"end",data:s,inBatch:z()};n.push(u),o===x&&(r=null)}),{entries:n,dispose:()=>r?.(x)}}static observeDerived(e){let r=[],n=e,o=n._fn;if(typeof o!="function"||!Array.isArray(n._deps))return{...t.observe(e),evaluations:r};n._fn=()=>{let c=n._deps.map(i=>i.get()),f=o();return r.push({result:f,depValues:c,timestamp:Date.now()}),f};let s=t._observe(e),u=s.dispose;return{...s,evaluations:r,dispose:()=>{n._fn=o,u()},reconnect:()=>(n._fn=o,u(),t.observeDerived(e))}}static observeTaskState(e){let r=e.status.get(),n=[],o=null;return e.status.source(D,(s,u)=>{if(s===D){o=u;return}if(s===W){let a=u;if(a!==r){let c={from:r,to:a,timestamp:Date.now()};a==="error"&&(c.error=e.error.get()),n.push(c),r=a}}s===x&&(o=null)}),{transitions:n,get currentStatus(){return e.status.get()},dispose:()=>{o?.(x)}}}static causalityTrace(e){let r=[],n=e,o=n._fn;if(typeof o!="function"||!Array.isArray(n._deps))return{...t.observe(e),causality:r};let s=n._deps,u=s.map(i=>i.get());n._fn=()=>{let i=s.map(m=>m.get()),l=o(),g=-1;for(let m=0;m<s.length;m++)if(!Object.is(i[m],u[m])){g=m;break}return r.push({result:l,triggerDepIndex:g,triggerDepName:g>=0?t.getName(s[g]):void 0,depValues:i,timestamp:Date.now()}),u=i,l};let a=t._observe(e),c=a.dispose;return{...a,causality:r,dispose:()=>{n._fn=o,c()},reconnect:()=>(n._fn=o,c(),t.causalityTrace(e))}}static _reset(){t._names=new WeakMap,t._kinds=new WeakMap,t._keys=new WeakMap,t._stores=new Set,t._edges=new Map,t._usedKeys=new Set,t._nextId=0,t._explicitEnabled=null,t._cachedDefault=null,t._annotations=new WeakMap,t._traceLog=[],t._traceHead=0,t._traceFull=!1,t.maxTraceEntries=1e3}};var ce=1,I=64,N=2,J=4,Oe=8,Pe=16,H=32,U=1024,L=he,G=ve<<B,ee=ke<<B,fe=_e<<B,Ge=we<<B,Qe=xe<<B,Ze=Ee<<B,te=class{_value;_output=null;_flags;get _status(){return Re(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(e,r){this._value=r?.initial,this._fn=e,this._eqFn=r?.equals,this._getterFn=r?.getter,this._initial=r?.initial;let n=0;r?.autoDirty!==!1&&(n|=J),r?.resetOnTeardown&&(n|=Oe),r?.resubscribable&&(n|=Pe),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||P.register(this,{kind:"producer",...r})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(e,r){let n=this._output;if(n)if(this._flags&I)for(let o of n)o(e,r);else n(e,r)}emit(e){this._flags&N||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(z()?this._flags&H||(this._flags|=H,this._flags&J&&(this._flags=this._flags&~L|G,this._dispatch(M,j)),le(()=>{this._flags&=~H,this._flags=this._flags&~L|ee,this._dispatch(W,this._value)})):(this._flags&J&&!(this._flags&U)&&(this._flags=this._flags&~L|G,this._dispatch(M,j)),this._flags=this._flags&~L|ee,this._dispatch(W,this._value))))}signal(e){this._flags&N||!this._output||(e===j?this._flags=this._flags&~L|G:e===X&&(this._flags=this._flags&~L|Ze),this._dispatch(M,e))}complete(){if(this._flags&N)return;this._flags=(this._flags|N)&~L|Ge;let e=this._output,r=this._flags&I;if(this._output=null,this._flags&=~(I|U),this._singleDepCount=0,this._stop(),e)if(r)for(let n of e)n(x);else e(x)}error(e){if(this._flags&N)return;this._flags=(this._flags|N)&~L|Qe;let r=this._output,n=this._flags&I;if(this._output=null,this._flags&=~(I|U),this._singleDepCount=0,this._stop(),r)if(n)for(let o of r)o(x,e);else r(x,e)}_start(){if(this._flags&ce||!this._fn)return;this._flags|=ce,this._onLifecycleSignal=void 0;let e=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 e=="function"?e:void 0}_stop(){this._flags&ce&&(this._flags&=~ce,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Oe&&(this._value=this._initial),this._flags&N||(this._flags=this._flags&~L|fe))}_handleLifecycleSignal(e){if(!(this._flags&N)){if(e===me){this._onLifecycleSignal?.(e),this.complete();return}e===F&&(this._value=this._initial,this._flags&=~H),this._onLifecycleSignal?.(e),e===F&&this.emit(this._initial)}}source(e,r){if(e===D){let n=r;if(this._flags&N)if(this._flags&Pe&&this._output===null)this._flags=this._flags&~(N|L)|fe;else{n(D,s=>{}),n(x);return}if(this._output===null)this._output=n;else if(this._flags&I)this._output.add(n);else{let s=new Set;s.add(this._output),s.add(n),this._output=s,this._flags=(this._flags|I)&~U}let o=!1;n(D,(s,u)=>{if(s===W&&n(W,this._value),s===M){u===be&&!o?(o=!0,this._singleDepCount++,this._flags&I||(this._flags|=U)):ye(u)&&this._handleLifecycleSignal(u);return}if(s===x){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&I){let a=this._output;a.delete(n),a.size===1?(this._output=a.values().next().value,this._flags&=~I,this._singleDepCount>0&&(this._flags|=U)):a.size===0&&(this._output=null,this._flags&=~(I|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 V(t,e){return new te(t,e)}var Se=class extends te{constructor(e,r){super(void 0,{initial:e,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),P.register(this,{kind:"state",...r})}get(){return this._value}set(e){this._flags&N||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(z()?this._flags&H||(this._flags|=H,this._flags&J&&(this._flags=this._flags&~L|G,this._dispatch(M,j)),le(()=>{this._flags&=~H,this._flags=this._flags&~L|ee,this._dispatch(W,this._value)})):(this._flags&J&&!(this._flags&U)&&(this._flags=this._flags&~L|G,this._dispatch(M,j)),this._flags=this._flags&~L|ee,this._dispatch(W,this._value))))}update(e){this.set(e(this._value))}};function k(t,e){return new Se(t,e)}function Q(t,e,r){let n=null;De(),t.source(D,(s,u)=>{if(s===D&&(n=u),s===x){n=null,r?.onEnd?.(u);return}if(s===1){let a=u,c=o;o=a,e(a,c)}});let o;try{o=t.get()}catch{}return Le(),{unsubscribe(){n?.(x),n=null},signal(s){n?.(M,s)}}}function Z(t,e){let r=e?.initialStatus??"pending",n=k(r,{name:"withStatus:status",equals:Object.is}),o=k(void 0,{name:"withStatus:error",equals:Object.is}),s=V(({emit:a,complete:c,error:f})=>{n.set(r),o.set(void 0);let i=Q(t,l=>{n.get()==="errored"?O(()=>{o.set(void 0),n.set("active")}):n.set("active"),a(l)},{onEnd:l=>{if(l!==void 0){let g=l instanceof Error?l:new Error(String(l));O(()=>{o.set(g),n.set("errored")}),f(l)}else n.set("completed"),c()}});return()=>{i.unsubscribe()}},{initial:t.get(),resubscribable:!0}),u={get:()=>t.get(),source:(a,c)=>s.source(a,c),get _status(){return s._status},status:n,error:o};return P.register(u,{kind:"withStatus"}),u}function Ae(t,e){let r=e?.name??"http",n=e?.method??"GET",o=e?.headers,s=e?.body,u=e?.poll??0,a=e?.transform??(w=>w.json()),c=e?.timeout??3e4,f=k(0,{name:`${r}:fetchCount`}),i=null,l=null,g=null,m=null,b=null,T=!1;async function R(){if(!T||!i)return;b=new AbortController;let w=[b.signal];e?.signal&&w.push(e.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,C=await fetch(t,{method:n,headers:o,body:E,signal:_.signal});if(!T)return;if(!C.ok)throw new Error(`HTTP ${C.status}: ${C.statusText}`);let $=await a(C);if(!T)return;O(()=>{f.update(A=>A+1),i?.($)})}catch(E){if(!T||E?.name==="AbortError")return;l?.(E)}finally{clearTimeout(v),b=null}}function h(){!T||p||u<=0||(m=setTimeout(()=>{m=null,R().then(()=>{T&&!p&&h()}).catch(()=>{})},u))}let d=null,p=!1,S=V(({emit:w,error:_,complete:v,onSignal:E})=>(i=w,l=_,g=v,T=!0,p=!1,d=()=>{R()},E(C=>{C===q?(p=!0,m!==null&&(clearTimeout(m),m=null)):C===K?(p=!1,h()):C===F&&(b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null),f.set(0),p=!1,R().then(()=>{T&&!p&&h()}))}),R().then(()=>{T&&!p&&h()}),()=>{T=!1,p=!1,i=null,l=null,g=null,d=null,b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null)}),{name:r,kind:"http"}),y=Z(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(t){switch(t){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function et(t,e){switch(t){case"openai":case"custom":return`${e}/chat/completions`;case"ollama":return`${e}/api/chat`;default:return`${e}/chat/completions`}}function tt(t,e,r,n){let o={model:e,messages:r,stream:!0};return n?.temperature!==void 0&&(o.temperature=n.temperature),n?.maxTokens!==void 0&&(t==="ollama"?o.options={num_predict:n.maxTokens}:o.max_tokens=n.maxTokens),n?.stop&&(o.stop=n.stop),o}function nt(t,e){let r={"Content-Type":"application/json"};return e&&(r.Authorization=`Bearer ${e}`),r}function Me(t){let e=t.name??"llm",r=t.provider,n=t.baseURL??Xe(r),o=t.model??"",s=t.fetch??globalThis.fetch,u=k("",{name:`${e}.store`}),a=k({},{name:`${e}.tokens`}),c=k("pending",{name:`${e}.status`}),f=k(void 0,{name:`${e}.error`}),i=null;function l(){i&&(i.abort(),i=null),c.get()==="active"&&O(()=>{u.set(""),c.set("pending")})}function g(b,T){l(),i=new AbortController;let R=T?.signal?st(i.signal,T.signal):i.signal;O(()=>{u.set(""),a.set({}),f.set(void 0),c.set("active")});let h=et(r,n),d=tt(r,o,b,T),p=nt(r,t.apiKey);m(h,p,d,R).catch(()=>{})}async function m(b,T,R,h){try{let d=await s(b,{method:"POST",headers:T,body:JSON.stringify(R),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
|
-
`)
|
|
6
|
-
|
|
7
|
-
data: ${p}
|
|
1
|
+
"use strict";var Fe=Object.create;var te=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty;var Ue=(t,e)=>{for(var o in e)te(t,o,{get:e[o],enumerable:!0})},he=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Be(e))!qe.call(t,r)&&r!==o&&te(t,r,{get:()=>e[r],enumerable:!(n=He(e,r))||n.enumerable});return t};var Ke=(t,e,o)=>(o=t!=null?Fe(Ve(t)):{},he(e||!t||!t.__esModule?te(o,"default",{value:t,enumerable:!0}):o,t)),ze=t=>he(te({},"__esModule",{value:!0}),t);var Ze={};Ue(Ze,{fromHTTP:()=>Pe,fromMCP:()=>Ae,fromWebSocket:()=>$e,fromWebhook:()=>Ie,toSSE:()=>We,toWebSocket:()=>Me});module.exports=ze(Ze);var M=Symbol("DIRTY"),Z=Symbol("RESOLVED"),Se=Symbol("SINGLE_DEP"),N=Symbol("RESET"),U=Symbol("PAUSE"),K=Symbol("RESUME"),pe=Symbol("TEARDOWN");function Te(t){return t===N||t===U||t===K||t===pe}var ye=0,be=1,_e=2,ve=3,Ee=4,ke=5,H=7,ge=7<<H,Ye=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function we(t){return Ye[(t&ge)>>>H]}var D=0,L=1,E=2,A=3,ne=0,re=[],de=!1;function j(t){ne++;try{return t()}finally{if(ne--,ne===0&&!de){de=!0;for(let e=0;e<re.length;e++)re[e]();re.length=0,de=!1}}}function z(){return ne>0}function ie(t){re.push(t)}var se=0,oe=[];function xe(){se++}function De(){if(se--,se===0){for(let t=0;t<oe.length;t++)oe[t]();oe.length=0}}function Re(t){se>0?oe.push(t):t()}var P=class t{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(t._explicitEnabled!==null)return t._explicitEnabled;if(t._cachedDefault!==null)return t._cachedDefault;try{t._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{t._cachedDefault=!0}return t._cachedDefault}static set enabled(e){t._explicitEnabled=e}static _depSuffix(e){if(!e?.length)return;let n=e.map(r=>t._names.get(r)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(e){let o=t._keys.get(e)??t._names.get(e);if(o)return o;let n=`anonymous_${t._nextId++}`;return t._keys.set(e,n),n}static register(e,o){if(!t.enabled)return;o?.name&&t._names.set(e,o.name),o?.kind&&t._kinds.set(e,o.kind);let n=t._nextId++,r=o?.name;if(!(r&&!t._usedKeys.has(r)))if(r){let s=t._depSuffix(o?.deps);r=s?`${r}(${s})`:`${r}_${n}`,t._usedKeys.has(r)&&(r=`${r}_${n}`)}else{let s=o?.kind??"store",u=t._depSuffix(o?.deps);r=u?`${s}(${u})`:`${s}_${n}`,t._usedKeys.has(r)&&(r=`${r}_${n}`)}t._usedKeys.add(r),t._keys.set(e,r),t._stores.add(new WeakRef(e))}static registerEdge(e,o){if(!t.enabled)return;let n=t._resolveKey(e),r=t._resolveKey(o),s=t._edges.get(n);s?s.includes(r)||s.push(r):t._edges.set(n,[r])}static getEdges(){return new Map(t._edges)}static getName(e){if(t.enabled)return t._names.get(e)}static getKind(e){return t._kinds.get(e)}static inspect(e){return{name:t._names.get(e),kind:t._kinds.get(e)??"unknown",value:typeof e.get=="function"?e.get():void 0,status:e._status}}static graph(){let e=new Map,o=new Set;for(let n of t._stores){let r=n.deref();if(!r){t._stores.delete(n);continue}let s=t._resolveKey(r);o.add(s),e.set(s,t.inspect(r))}for(let[n,r]of t._edges){if(!o.has(n)){t._edges.delete(n),t._usedKeys.delete(n);continue}let s=r.filter(u=>o.has(u));s.length===0?t._edges.delete(n):s.length!==r.length&&t._edges.set(n,s)}return e}static trace(e,o){let n=null,r=e.get();return e.source(D,(s,u)=>{if(s===D&&(n=u),s===E){n=null;return}if(s===1){let a=u;if(!Object.is(a,r)){let c=r;r=a,o(a,c)}}}),()=>n?.(E)}static dumpGraph(){let e=t.graph(),o=t.getEdges(),n=new Map;for(let[u,a]of o)for(let c of a){let f=n.get(c);f?f.includes(u)||f.push(u):n.set(c,[u])}let r=[];for(let[u,a]of e){let c=n.get(u),f=o.get(u),i=c?.length?` \u2190 [${c.join(", ")}]`:"",l=f?.length?` \u2192 [${f.join(", ")}]`:"";r.push(` ${u} (${a.kind}) = ${JSON.stringify(a.value)} [${a.status??"?"}]${i}${l}`)}return[`Store Graph (${e.size} nodes):`,...r].join(`
|
|
2
|
+
`)}static _signalLabel(e){return e===M?"DIRTY":e===Z?"RESOLVED":typeof e=="symbol"?e.description??String(e):String(e)}static _observe(e,o,n){let r=null,s=!1,u=o??t.getName(e),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:u,get eventLog(){return a},dispose:()=>r?.(E),reconnect:()=>(r?.(E),t._observe(e,o,n))};return e.source(D,(f,i)=>{if(f===D){r=i;return}let l=z();f===L?(c.values.push(i),c.events.push({type:"data",data:i,inBatch:l}),a.push(i),n&&n(`[${u}] DATA:`,i)):f===A?(c.signals.push(i),c.events.push({type:"signal",data:i,inBatch:l}),a.push(t._signalLabel(i)),i===M?c.dirtyCount++:i===Z&&c.resolvedCount++,n&&n(`[${u}] STATE:`,i)):f===E&&(c.ended=!0,c.endError=i,s=i!==void 0,c.events.push({type:"end",data:i,inBatch:l}),a.push(s?["END",i]:"END"),n&&n(`[${u}] END`,i!==void 0?i:""),r=null)}),c}static observe(e){return t._observe(e)}static activate(e){let o=null;return e.source(D,(n,r)=>{n===D&&(o=r),n===E&&(o=null)}),()=>o?.(E)}static tap(e,o){let n=o??`tap(${t.getName(e)??"anon"})`,r={get:()=>e.get(),source:e.source};return t.register(r,{name:n,kind:"tap"}),t.registerEdge(e,r),r}static spy(e,o){let n=o?.name??t.getName(e)??"spy",r=o?.log??console.log;return t._observe(e,n,r)}static snapshot(){let e=t.graph(),o=t.getEdges(),n=new Map;for(let u of t._stores){let a=u.deref();if(!a)continue;let c=t._annotations.get(a);c!==void 0&&n.set(t._resolveKey(a),c)}let r=[];for(let[u,a]of e){let c={name:u,kind:a.kind,value:a.value,status:a.status},f=n.get(u);f!==void 0&&(c.annotation=f),r.push(c)}let s=[];for(let[u,a]of o)for(let c of a)s.push({from:u,to:c});return{nodes:r,edges:s,trace:t.traceLog()}}static toMermaid(e){let o=e?.direction??"TD",n=t.snapshot(),r=[`graph ${o}`],s={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},u=new Map;function a(i){let l=i.replace(/[^a-zA-Z0-9_]/g,"_"),d=u.get(l);return d===void 0?(u.set(l,1),l):(u.set(l,d+1),`${l}__${d}`)}let c=new Map;function f(i){let l=JSON.stringify(i);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let i of n.nodes){let l=a(i.name);c.set(i.name,l);let d=`${i.name} (${i.kind}) = ${f(i.value)}`,m=s[i.status??""]??"";r.push(` ${l}["${d}"]${m}`)}for(let i of n.edges){let l=c.get(i.from)??a(i.from),d=c.get(i.to)??a(i.to);r.push(` ${l} --> ${d}`)}return r.push(""),r.push(" classDef settled fill:#d4edda,stroke:#28a745"),r.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),r.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),r.push(" classDef completed fill:#cce5ff,stroke:#007bff"),r.join(`
|
|
3
|
+
`)}static toD2(e){let o=e?.direction??"down",n=t.snapshot(),r=[`direction: ${o}`,""],s={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},u=new Map;function a(i){let l=i.replace(/[^a-zA-Z0-9_]/g,"_"),d=u.get(l);return d===void 0?(u.set(l,1),l):(u.set(l,d+1),`${l}__${d}`)}let c=new Map;function f(i){let l=JSON.stringify(i);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let i of n.nodes){let l=a(i.name);c.set(i.name,l);let d=s[i.kind]??"rectangle",m=`${i.name} (${i.kind}) = ${f(i.value)}`,b=i.status?` [${i.status}]`:"";r.push(`${l}: "${m}${b}" { shape: ${d} }`)}n.edges.length>0&&r.push("");for(let i of n.edges){let l=c.get(i.from)??a(i.from),d=c.get(i.to)??a(i.to);r.push(`${l} -> ${d}`)}return r.join(`
|
|
4
|
+
`)}static annotate(e,o){if(!t.enabled)return;t._annotations.set(e,o);let n={node:t._resolveKey(e),reason:o,timestamp:Date.now()},r=t.maxTraceEntries;r<=0||(t._traceLog.length<r?t._traceLog.push(n):(t._traceLog[t._traceHead]=n,t._traceFull=!0),t._traceHead=(t._traceHead+1)%r)}static getAnnotation(e){return t._annotations.get(e)}static traceLog(){return t._traceFull?[...t._traceLog.slice(t._traceHead),...t._traceLog.slice(0,t._traceHead)]:t._traceLog.slice(0,t._traceHead||t._traceLog.length)}static clearTrace(){t._traceLog=[],t._traceHead=0,t._traceFull=!1}static timeline(e){let o=null,n=[];return e.source(D,(r,s)=>{if(r===D){o=s;return}let u={timestamp:Date.now(),type:r===L?"data":r===A?"signal":"end",data:s,inBatch:z()};n.push(u),r===E&&(o=null)}),{entries:n,dispose:()=>o?.(E)}}static observeDerived(e){let o=[],n=e,r=n._fn;if(typeof r!="function"||!Array.isArray(n._deps))return{...t.observe(e),evaluations:o};n._fn=()=>{let c=n._deps.map(i=>i.get()),f=r();return o.push({result:f,depValues:c,timestamp:Date.now()}),f};let s=t._observe(e),u=s.dispose;return{...s,evaluations:o,dispose:()=>{n._fn=r,u()},reconnect:()=>(n._fn=r,u(),t.observeDerived(e))}}static observeTaskState(e){let o=e.status.get(),n=[],r=null;return e.status.source(D,(s,u)=>{if(s===D){r=u;return}if(s===L){let a=u;if(a!==o){let c={from:o,to:a,timestamp:Date.now()};a==="error"&&(c.error=e.error.get()),n.push(c),o=a}}s===E&&(r=null)}),{transitions:n,get currentStatus(){return e.status.get()},dispose:()=>{r?.(E)}}}static causalityTrace(e){let o=[],n=e,r=n._fn;if(typeof r!="function"||!Array.isArray(n._deps))return{...t.observe(e),causality:o};let s=n._deps,u=s.map(i=>i.get());n._fn=()=>{let i=s.map(m=>m.get()),l=r(),d=-1;for(let m=0;m<s.length;m++)if(!Object.is(i[m],u[m])){d=m;break}return o.push({result:l,triggerDepIndex:d,triggerDepName:d>=0?t.getName(s[d]):void 0,depValues:i,timestamp:Date.now()}),u=i,l};let a=t._observe(e),c=a.dispose;return{...a,causality:o,dispose:()=>{n._fn=r,c()},reconnect:()=>(n._fn=r,c(),t.causalityTrace(e))}}static _reset(){t._names=new WeakMap,t._kinds=new WeakMap,t._keys=new WeakMap,t._stores=new Set,t._edges=new Map,t._usedKeys=new Set,t._nextId=0,t._explicitEnabled=null,t._cachedDefault=null,t._annotations=new WeakMap,t._traceLog=[],t._traceHead=0,t._traceFull=!1,t.maxTraceEntries=1e3}};var ae=1,I=64,W=2,Y=4,Ce=8,Oe=16,B=32,F=1024,R=ge,J=be<<H,X=_e<<H,ue=ye<<H,Je=Ee<<H,Ge=ke<<H,Qe=ve<<H,ee=class{_value;_output=null;_flags;get _status(){return we(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(e,o){this._value=o?.initial,this._fn=e,this._eqFn=o?.equals,this._getterFn=o?.getter,this._initial=o?.initial;let n=0;o?.autoDirty!==!1&&(n|=Y),o?.resetOnTeardown&&(n|=Ce),o?.resubscribable&&(n|=Oe),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),o?._skipInspect||P.register(this,{kind:"producer",...o})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(e,o){let n=this._output;if(n)if(this._flags&I)for(let r of n)r(e,o);else n(e,o)}emit(e){this._flags&W||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(z()?this._flags&B||(this._flags|=B,this._flags&Y&&(this._flags=this._flags&~R|J,this._dispatch(A,M)),ie(()=>{this._flags&=~B,this._flags=this._flags&~R|X,this._dispatch(L,this._value)})):(this._flags&Y&&!(this._flags&F)&&(this._flags=this._flags&~R|J,this._dispatch(A,M)),this._flags=this._flags&~R|X,this._dispatch(L,this._value))))}signal(e){this._flags&W||!this._output||(e===M?this._flags=this._flags&~R|J:e===Z&&(this._flags=this._flags&~R|Qe),this._dispatch(A,e))}complete(){if(this._flags&W)return;this._flags=(this._flags|W)&~R|Je;let e=this._output,o=this._flags&I;if(this._output=null,this._flags&=~(I|F),this._singleDepCount=0,this._stop(),e)if(o)for(let n of e)n(E);else e(E)}error(e){if(this._flags&W)return;this._flags=(this._flags|W)&~R|Ge;let o=this._output,n=this._flags&I;if(this._output=null,this._flags&=~(I|F),this._singleDepCount=0,this._stop(),o)if(n)for(let r of o)r(E,e);else o(E,e)}_start(){if(this._flags&ae||!this._fn)return;this._flags|=ae,this._onLifecycleSignal=void 0;let e=this._fn({emit:this.emit,signal:o=>this.signal(o),complete:()=>this.complete(),error:o=>this.error(o),onSignal:o=>{this._onLifecycleSignal=o}});this._cleanup=typeof e=="function"?e:void 0}_stop(){this._flags&ae&&(this._flags&=~ae,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Ce&&(this._value=this._initial),this._flags&W||(this._flags=this._flags&~R|ue))}_handleLifecycleSignal(e){if(!(this._flags&W)){if(e===pe){this._onLifecycleSignal?.(e),this.complete();return}e===N&&(this._value=this._initial,this._flags&=~B),this._onLifecycleSignal?.(e),e===N&&this.emit(this._initial)}}source(e,o){if(e===D){let n=o;if(this._flags&W)if(this._flags&Oe&&this._output===null)this._flags=this._flags&~(W|R)|ue;else{n(D,s=>{}),n(E);return}if(this._output===null)this._output=n;else if(this._flags&I)this._output.add(n);else{let s=new Set;s.add(this._output),s.add(n),this._output=s,this._flags=(this._flags|I)&~F}let r=!1;n(D,(s,u)=>{if(s===L&&n(L,this._value),s===A){u===Se&&!r?(r=!0,this._singleDepCount++,this._flags&I||(this._flags|=F)):Te(u)&&this._handleLifecycleSignal(u);return}if(s===E){if(r&&(r=!1,this._singleDepCount--),this._output===null)return;if(this._flags&I){let a=this._output;a.delete(n),a.size===1?(this._output=a.values().next().value,this._flags&=~I,this._singleDepCount>0&&(this._flags|=F)):a.size===0&&(this._output=null,this._flags&=~(I|F),this._singleDepCount=0,this._flags=this._flags&~R|ue,this._stop())}else this._output===n&&(this._output=null,this._flags&=~F,this._singleDepCount=0,this._flags=this._flags&~R|ue,this._stop())}}),Re(()=>this._start())}}};function V(t,e){return new ee(t,e)}var me=class extends ee{constructor(e,o){super(void 0,{initial:e,autoDirty:!0,equals:o?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),P.register(this,{kind:"state",...o})}get(){return this._value}set(e){this._flags&W||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(z()?this._flags&B||(this._flags|=B,this._flags&Y&&(this._flags=this._flags&~R|J,this._dispatch(A,M)),ie(()=>{this._flags&=~B,this._flags=this._flags&~R|X,this._dispatch(L,this._value)})):(this._flags&Y&&!(this._flags&F)&&(this._flags=this._flags&~R|J,this._dispatch(A,M)),this._flags=this._flags&~R|X,this._dispatch(L,this._value))))}update(e){this.set(e(this._value))}};function w(t,e){return new me(t,e)}function G(t,e,o){let n=null;xe(),t.source(D,(s,u)=>{if(s===D&&(n=u),s===E){n=null,o?.onEnd?.(u);return}if(s===1){let a=u,c=r;r=a,e(a,c)}});let r;try{r=t.get()}catch{}return De(),{unsubscribe(){n?.(E),n=null},signal(s){n?.(A,s)}}}function Q(t,e){let o=e?.initialStatus??"pending",n=w(o,{name:"withStatus:status",equals:Object.is}),r=w(void 0,{name:"withStatus:error",equals:Object.is}),s=V(({emit:a,complete:c,error:f})=>{n.set(o),r.set(void 0);let i=G(t,l=>{n.get()==="errored"?j(()=>{r.set(void 0),n.set("active")}):n.set("active"),a(l)},{onEnd:l=>{if(l!==void 0){let d=l instanceof Error?l:new Error(String(l));j(()=>{r.set(d),n.set("errored")}),f(l)}else n.set("completed"),c()}});return()=>{i.unsubscribe()}},{initial:t.get(),resubscribable:!0}),u={get:()=>t.get(),source:(a,c)=>s.source(a,c),get _status(){return s._status},status:n,error:r};return P.register(u,{kind:"withStatus"}),u}function Pe(t,e){let o=e?.name??"http",n=e?.method??"GET",r=e?.headers,s=e?.body,u=e?.poll??0,a=e?.transform??(x=>x.json()),c=e?.timeout??3e4,f=w(0,{name:`${o}:fetchCount`}),i=null,l=null,d=null,m=null,b=null,T=!1;async function C(){if(!T||!i)return;b=new AbortController;let x=[b.signal];e?.signal&&x.push(e.signal);let _=new AbortController;for(let k of x){if(k.aborted){_.abort(k.reason);break}k.addEventListener("abort",()=>_.abort(k.reason),{once:!0})}let v=setTimeout(()=>_.abort(new Error("Request timeout")),c);try{let k=s!==void 0?typeof s=="string"?s:JSON.stringify(s):void 0,O=await fetch(t,{method:n,headers:r,body:k,signal:_.signal});if(!T)return;if(!O.ok)throw new Error(`HTTP ${O.status}: ${O.statusText}`);let q=await a(O);if(!T)return;j(()=>{f.update($=>$+1),i?.(q)})}catch(k){if(!T||k?.name==="AbortError")return;l?.(k)}finally{clearTimeout(v),b=null}}function S(){!T||g||u<=0||(m=setTimeout(()=>{m=null,C().then(()=>{T&&!g&&S()}).catch(()=>{})},u))}let p=null,g=!1,h=V(({emit:x,error:_,complete:v,onSignal:k})=>(i=x,l=_,d=v,T=!0,g=!1,p=()=>{C()},k(O=>{O===U?(g=!0,m!==null&&(clearTimeout(m),m=null)):O===K?(g=!1,S()):O===N&&(b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null),f.set(0),g=!1,C().then(()=>{T&&!g&&S()}))}),C().then(()=>{T&&!g&&S()}),()=>{T=!1,g=!1,i=null,l=null,d=null,p=null,b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null)}),{name:o,kind:"http"}),y=Q(h);return{get:()=>y.get(),source:(x,_)=>y.source(x,_),status:y.status,error:y.error,fetchCount:f,refetch(){p?.()},stop(){T=!1,b?.abort(),b=null,m!==null&&(clearTimeout(m),m=null),d?.()}}}function Ae(t){let e=t.name??"mcp",o=t.client,n=w([],{name:`${e}.tools`}),r=w([],{name:`${e}.resources`}),s=w(void 0,{name:`${e}.refreshError`});function u(f){s.set(f);let i=t.onRefreshError;if(i==="warn")console.warn(`[${e}] refresh error:`,f);else{if(i==="error")throw f;typeof i=="function"&&i(f)}}async function a(){if(s.set(void 0),o.listTools)try{let f=await o.listTools();n.set(f.tools)}catch(f){u(f)}if(o.listResources)try{let f=await o.listResources();r.set(f.resources)}catch(f){u(f)}}function c(f){let i=`${e}:${f}`,l=w(void 0,{name:`${i}.result`}),d=w("idle",{name:`${i}.status`}),m=w(void 0,{name:`${i}.error`}),b=w(void 0,{name:`${i}.lastArgs`}),T=w(void 0,{name:`${i}.duration`}),C=!1;async function S(p){if(C)return;C=!0,j(()=>{b.set(p),m.set(void 0),d.set("active")});let g=Date.now();try{let h=await o.callTool({name:f,arguments:p}),y=Date.now()-g;if(h.isError){let v=h.content.filter(O=>O.type==="text").map(O=>O.text??"").join(`
|
|
5
|
+
`),k=new Error(v||"MCP tool returned error");j(()=>{T.set(y),m.set(k),d.set("errored")});return}let x=h.content.filter(v=>v.type==="text"),_;if(x.length===1){let v=x[0].text;if(v!==void 0)try{_=JSON.parse(v)}catch{_=v}}else x.length>1?_=x.map(v=>v.text??""):_=h.content;j(()=>{T.set(y),l.set(_),d.set("completed")})}catch(h){let y=Date.now()-g;j(()=>{T.set(y),m.set(h),d.set("errored")})}finally{C=!1}}return{get:()=>l.get(),source:(p,g)=>l.source(p,g),status:d,error:m,call:S,lastArgs:b,duration:T}}return{tool:c,tools:n,resources:r,refresh:a,refreshError:s}}function Le(t,e,o){let n=null;return t(0,(r,s)=>{if(r===0){n=s;return}if(r===2){n=null,o?.onEnd?.(s);return}r===1&&e(s)}),{unsubscribe(){n?.(2),n=null}}}function le(t,e){let o=e?.predicate,n=e?.signal;return new Promise((r,s)=>{if(n?.aborted){s(n.reason??new DOMException("The operation was aborted.","AbortError"));return}let u=!1,a=Le(t,i=>{(!o||o(i))&&(u=!0,f(),a.unsubscribe(),r(i))},{onEnd:i=>{u||(u=!0,f(),s(i??new Error("source completed without matching value")))}});function c(){u||(u=!0,f(),a.unsubscribe(),s(n.reason??new DOMException("The operation was aborted.","AbortError")))}function f(){n?.removeEventListener("abort",c)}n?.addEventListener("abort",c)})}function ce(t){return(e,o)=>{if(e!==0)return;let n=!1,r;o(0,s=>{s===2&&!n&&(n=!0,r?.())});try{r=t(s=>{n||(n=!0,o(1,s),o(2))},s=>{n||(n=!0,o(2,s))})}catch(s){n||(n=!0,o(2,s))}}}function We(t,e){let o=e?.path??"/",n=e?.name??"sse",r=e?.hostname??"0.0.0.0",s=e?.serialize??JSON.stringify,u=e?.eventName??"message",a=e?.pingInterval??3e4,c=w(0,{name:`${n}:connections`}),f=new Set,i=new Map,l=null;function d(){l||(l=G(t,p=>{let g=s(p),h=`event: ${u}
|
|
6
|
+
data: ${g}
|
|
8
7
|
|
|
9
|
-
`;for(let y of f)try{y.write(
|
|
8
|
+
`;for(let y of f)try{y.write(h)}catch{m(y)}}))}function m(p){f.delete(p);let g=i.get(p);g&&(clearInterval(g),i.delete(p)),c.set(f.size),f.size===0&&l&&(l.unsubscribe(),l=null)}function b(p,g){let h=p.method?.toUpperCase();if((p.url??"/").split("?")[0]!==o){g.writeHead(404,{"Content-Type":"text/plain"}),g.end("Not found");return}if(h==="OPTIONS"){g.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),g.end();return}if(h!=="GET"){g.writeHead(405,{"Content-Type":"text/plain"}),g.end("Method not allowed");return}g.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),g.write(`:ok
|
|
10
9
|
|
|
11
|
-
`),f.add(
|
|
10
|
+
`),f.add(g),c.set(f.size);try{let _=t.get();if(_!==void 0){let v=s(_);g.write(`event: ${u}
|
|
12
11
|
data: ${v}
|
|
13
12
|
|
|
14
|
-
`)}}catch{}if(a>0){let _=setInterval(()=>{try{
|
|
13
|
+
`)}}catch{}if(a>0){let _=setInterval(()=>{try{g.write(`:ping
|
|
15
14
|
|
|
16
|
-
`)}catch{m(
|
|
15
|
+
`)}catch{m(g)}},a);i.set(g,_)}p.on("close",()=>m(g)),d()}let T=null;async function C(){if(!e?.port)throw new Error("toSSE: port is required for listen()");if(T)throw new Error("toSSE: already listening. Call close() first.");let p=await import("http");return le(ce((g,h)=>{T=p.createServer(b),T.once("listening",()=>g()),T.once("error",y=>{T=null,h(y)}),T.listen(e.port,r)}))}function S(){for(let p of f)try{p.end()}catch{}f.clear();for(let p of i.values())clearInterval(p);i.clear(),c.set(0),l?.unsubscribe(),l=null,T?.close(),T=null}return P.register(c,{kind:"sse"}),{connectionCount:c,handler:b,listen:C,close:S}}function Ie(t){let e=t?.path??"/",o=t?.parse??JSON.parse,n=t?.name??"webhook",r=t?.hostname??"0.0.0.0",s=t?.maxBodySize??1024*1024,u=t?.responseTimeout??3e4,a=w(0,{name:`${n}:count`}),c=null,f=!1,i=V(({emit:S,onSignal:p})=>(c=S,f=!1,p(g=>{g===U?f=!0:g===K?f=!1:g===N&&(f=!1,a.set(0))}),()=>{c=null,f=!1}),{name:n,kind:"webhook"});P.register(i,{kind:"webhook"});let l=Q(i),d=null,m=new Set;function b(S,p){let g=S.method?.toUpperCase(),y=(S.url??"/").split("?")[0];if(g!=="POST"||y!==e){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 x=[],_=0,v=!1;S.on("error",()=>{v=!0,p.headersSent||(p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Request aborted"})))}),S.on("data",k=>{if(!v){if(_+=k.length,_>s){v=!0,p.writeHead(413,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Payload too large"})),S.destroy?.();return}x.push(k)}}),S.on("end",()=>{if(!v)try{let k=Buffer.concat(x).toString("utf-8"),O=k.length>0?o(k):void 0;a.update(fe=>fe+1);let q=!1,$=null,Ne={body:O,get responded(){return q},respond(fe,je=200){q||(q=!0,$!==null&&(clearTimeout($),m.delete($),$=null),p.writeHead(je,{"Content-Type":"application/json"}),p.end(JSON.stringify(fe)))}};$=setTimeout(()=>{m.delete($),$=null,q||(q=!0,p.writeHead(504,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Response timeout"})))},u),m.add($),c?.(Ne)}catch(k){p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:k?.message??"Parse error"}))}})}function T(){return t?.port?d?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):le(ce((S,p)=>{try{d=require("http").createServer(b),d.once("listening",()=>S()),d.once("error",h=>{d=null,p(h)}),d.listen(t.port,r);return}catch(g){p(g);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function C(){for(let S of m)clearTimeout(S);m.clear(),d?.close(),d=null}return{get:()=>l.get(),source:(S,p)=>l.source(S,p),status:l.status,error:l.error,requestCount:a,handler:b,listen:T,close:C}}function $e(t,e){let o=e?.name??"websocket",n=e?.parse??(h=>h),r=e?.reconnect??!1,s=e?.onParseError??"warn",u=w("connecting",{name:`${o}:connectionState`,equals:()=>!1}),a=null,c=null,f=null,i=null,l=null,d=!1,m=null,b=[];function T(){for(;b.length>0&&a?.readyState===WebSocket.OPEN;)a.send(b.shift())}function C(){d=!1,u.set("connecting");try{a=new WebSocket(t,e?.protocols)}catch(h){u.set("closed"),f?.(h);return}a.onopen=()=>{u.set("open"),T()},a.onmessage=h=>{if(!S)try{let y=n(h.data);c?.(y)}catch(y){s==="error"?f?.(y):s==="warn"&&console.warn(`[${o}] parse error:`,y)}},a.onerror=()=>{m=new Error(`WebSocket error on ${t}`)},a.onclose=()=>{u.set("closed"),a=null;let h=m;m=null,!d&&r!==!1?l=setTimeout(()=>{l=null,c&&C()},r):h&&!d?f?.(h):i?.()}}let S=!1,p=V(({emit:h,error:y,complete:x,onSignal:_})=>(c=h,f=y,i=x,S=!1,C(),_(v=>{v===U?S=!0:v===K?S=!1:v===N&&(S=!1,b.length=0,l!==null&&(clearTimeout(l),l=null),a&&(d=!0,a.onopen=null,a.onmessage=null,a.onerror=null,a.onclose=null,a.close(),a=null),u.set("closed"),C())}),()=>{c=null,f=null,i=null,S=!1,d=!0,b.length=0,l!==null&&(clearTimeout(l),l=null),a&&(a.onopen=null,a.onmessage=null,a.onerror=null,a.onclose=null,a.close(),a=null),u.set("closed")}),{name:o,kind:"websocket"});P.register(p,{kind:"websocket"});let g=Q(p);return{get:()=>g.get(),source:(h,y)=>g.source(h,y),status:g.status,error:g.error,connectionState:u,send(h){a?.readyState===WebSocket.OPEN?a.send(h):b.push(h)},close(h,y){d=!0,b.length=0,l!==null&&(clearTimeout(l),l=null),a?.close(h,y)}}}function Me(t,e,o){let n=u=>typeof u=="string"?u:JSON.stringify(u),r=o?.serialize??n,s="send"in t&&typeof t.send=="function"?t.send.bind(t):null;if(!s)throw new Error("toWebSocket: invalid WebSocket target");return G(e,u=>{try{let a=r(u);s(a)}catch{}})}0&&(module.exports={fromHTTP,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { FromHTTPOptions, HTTPStore, fromHTTP } from './http.cjs';
|
|
2
|
-
export { GenerateOptions, LLMMessage, LLMOptions, LLMStore, LLMTokenUsage, fromLLM } from './llm.cjs';
|
|
3
2
|
export { MCPClientLike, MCPOptions, MCPResource, MCPResult, MCPToolInfo, MCPToolStore, fromMCP } from './mcp.cjs';
|
|
4
3
|
export { SSEOptions, SSEStore, toSSE } from './sse.cjs';
|
|
5
4
|
export { WebhookOptions, WebhookRequest, WebhookStore, fromWebhook } from './webhook.cjs';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { FromHTTPOptions, HTTPStore, fromHTTP } from './http.js';
|
|
2
|
-
export { GenerateOptions, LLMMessage, LLMOptions, LLMStore, LLMTokenUsage, fromLLM } from './llm.js';
|
|
3
2
|
export { MCPClientLike, MCPOptions, MCPResource, MCPResult, MCPToolInfo, MCPToolStore, fromMCP } from './mcp.js';
|
|
4
3
|
export { SSEOptions, SSEStore, toSSE } from './sse.js';
|
|
5
4
|
export { WebhookOptions, WebhookRequest, WebhookStore, fromWebhook } from './webhook.js';
|
package/dist/adapters/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"../chunk-ZDGVUX5G.js";import{a as e}from"../chunk-
|
|
1
|
+
import{a as o}from"../chunk-ZDGVUX5G.js";import{a as e}from"../chunk-Q5DHO5II.js";import{a as t}from"../chunk-PLIRVTP4.js";import{a as r}from"../chunk-7B4DHRG6.js";import"../chunk-XEU7KSEO.js";import"../chunk-4VPAGOLZ.js";import"../chunk-4ILN4V4C.js";import{a as p,b as S}from"../chunk-U3FGSR3I.js";import"../chunk-5LLYKN4X.js";import"../chunk-GMLWTZFM.js";import"../chunk-EAK2HKAD.js";import"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{o as fromHTTP,e as fromMCP,p as fromWebSocket,r as fromWebhook,t as toSSE,S as toWebSocket};
|
package/dist/adapters/sse.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var Se=Object.create;var j=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var Se=Object.create;var j=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var i in t)j(e,i,{get:t[i],enumerable:!0})},G=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ye(t))!ve.call(e,s)&&s!==i&&j(e,s,{get:()=>t[s],enumerable:!(n=me(t,s))||n.enumerable});return e};var De=(e,t,i)=>(i=e!=null?Se(be(e)):{},G(t||!e||!e.__esModule?j(i,"default",{value:e,enumerable:!0}):i,e)),ke=e=>G(j({},"__esModule",{value:!0}),e);var Ne={};Ee(Ne,{toSSE:()=>$e});module.exports=ke(Ne);var E=Symbol("DIRTY"),$=Symbol("RESOLVED"),J=Symbol("SINGLE_DEP"),V=Symbol("RESET"),xe=Symbol("PAUSE"),we=Symbol("RESUME"),z=Symbol("TEARDOWN");function Z(e){return e===V||e===xe||e===we||e===z}var Q=0,X=1,ee=2,te=3,ne=4,se=5,k=7,B=7<<k,Re=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ie(e){return Re[(e&B)>>>k]}var h=0,y=1,p=2,m=3,Oe=0,Le=[];function O(){return Oe>0}function U(e){Le.push(e)}var K=0,F=[];function re(){K++}function oe(){if(K--,K===0){for(let e=0;e<F.length;e++)F[e]();F.length=0}}function ae(e){K>0?F.push(e):e()}var w=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(h,(r,a)=>{if(r===h&&(n=a),r===p){n=null;return}if(r===1){let u=a;if(!Object.is(u,s)){let l=s;s=u,i(u,l)}}}),()=>n?.(p)}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
2
|
`)}static _signalLabel(t){return t===E?"DIRTY":t===$?"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?.(p),reconnect:()=>(s?.(p),e._observe(t,i,n))};return t.source(h,(f,o)=>{if(f===h){s=o;return}let c=O();f===y?(l.values.push(o),l.events.push({type:"data",data:o,inBatch:c}),u.push(o),n&&n(`[${a}] DATA:`,o)):f===m?(l.signals.push(o),l.events.push({type:"signal",data:o,inBatch:c}),u.push(e._signalLabel(o)),o===E?l.dirtyCount++:o===$&&l.resolvedCount++,n&&n(`[${a}] STATE:`,o)):f===p&&(l.ended=!0,l.endError=o,r=o!==void 0,l.events.push({type:"end",data:o,inBatch:c}),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(h,(n,s)=>{n===h&&(i=s),n===p&&(i=null)}),()=>i?.(p)}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)}`,_=r[o.status??""]??"";s.push(` ${c}["${d}"]${_}`)}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
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",_=`${o.name} (${o.kind}) = ${f(o.value)}`,P=o.status?` [${o.status}]`:"";s.push(`${c}: "${_}${P}" { 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 timeline(t){let i=null,n=[];return t.source(h,(s,r)=>{if(s===h){i=r;return}let a={timestamp:Date.now(),type:s===y?"data":s===m?"signal":"end",data:r,inBatch:O()};n.push(a),s===p&&(i=null)}),{entries:n,dispose:()=>i?.(p)}}static observeDerived(t){let i=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:i};n._fn=()=>{let l=n._deps.map(o=>o.get()),f=s();return i.push({result:f,depValues:l,timestamp:Date.now()}),f};let r=e._observe(t),a=r.dispose;return{...r,evaluations:i,dispose:()=>{n._fn=s,a()},reconnect:()=>(n._fn=s,a(),e.observeDerived(t))}}static observeTaskState(t){let i=t.status.get(),n=[],s=null;return t.status.source(h,(r,a)=>{if(r===h){s=a;return}if(r===y){let u=a;if(u!==i){let l={from:i,to:u,timestamp:Date.now()};u==="error"&&(l.error=t.error.get()),n.push(l),i=u}}r===p&&(s=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{s?.(p)}}}static causalityTrace(t){let i=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:i};let r=n._deps,a=r.map(o=>o.get());n._fn=()=>{let o=r.map(_=>_.get()),c=s(),d=-1;for(let _=0;_<r.length;_++)if(!Object.is(o[_],a[_])){d=_;break}return i.push({result:c,triggerDepIndex:d,triggerDepName:d>=0?e.getName(r[d]):void 0,depValues:o,timestamp:Date.now()}),a=o,c};let u=e._observe(t),l=u.dispose;return{...u,causality:i,dispose:()=>{n._fn=s,l()},reconnect:()=>(n._fn=s,l(),e.causalityTrace(t))}}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var Y=1,
|
|
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 timeline(t){let i=null,n=[];return t.source(h,(s,r)=>{if(s===h){i=r;return}let a={timestamp:Date.now(),type:s===y?"data":s===m?"signal":"end",data:r,inBatch:O()};n.push(a),s===p&&(i=null)}),{entries:n,dispose:()=>i?.(p)}}static observeDerived(t){let i=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:i};n._fn=()=>{let l=n._deps.map(o=>o.get()),f=s();return i.push({result:f,depValues:l,timestamp:Date.now()}),f};let r=e._observe(t),a=r.dispose;return{...r,evaluations:i,dispose:()=>{n._fn=s,a()},reconnect:()=>(n._fn=s,a(),e.observeDerived(t))}}static observeTaskState(t){let i=t.status.get(),n=[],s=null;return t.status.source(h,(r,a)=>{if(r===h){s=a;return}if(r===y){let u=a;if(u!==i){let l={from:i,to:u,timestamp:Date.now()};u==="error"&&(l.error=t.error.get()),n.push(l),i=u}}r===p&&(s=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{s?.(p)}}}static causalityTrace(t){let i=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:i};let r=n._deps,a=r.map(o=>o.get());n._fn=()=>{let o=r.map(_=>_.get()),c=s(),d=-1;for(let _=0;_<r.length;_++)if(!Object.is(o[_],a[_])){d=_;break}return i.push({result:c,triggerDepIndex:d,triggerDepName:d>=0?e.getName(r[d]):void 0,depValues:o,timestamp:Date.now()}),a=o,c};let u=e._observe(t),l=u.dispose;return{...u,causality:i,dispose:()=>{n._fn=s,l()},reconnect:()=>(n._fn=s,l(),e.causalityTrace(t))}}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var Y=1,v=64,b=2,A=4,le=8,ue=16,R=32,D=1024,T=B,I=X<<k,N=ee<<k,W=Q<<k,Ae=ne<<k,Ie=se<<k,Ce=te<<k,H=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|=A),i?.resetOnTeardown&&(n|=le),i?.resubscribable&&(n|=ue),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||w.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&v)for(let s of n)s(t,i);else n(t,i)}emit(t){this._flags&b||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(O()?this._flags&R||(this._flags|=R,this._flags&A&&(this._flags=this._flags&~T|I,this._dispatch(m,E)),U(()=>{this._flags&=~R,this._flags=this._flags&~T|N,this._dispatch(y,this._value)})):(this._flags&A&&!(this._flags&D)&&(this._flags=this._flags&~T|I,this._dispatch(m,E)),this._flags=this._flags&~T|N,this._dispatch(y,this._value))))}signal(t){this._flags&b||!this._output||(t===E?this._flags=this._flags&~T|I:t===$&&(this._flags=this._flags&~T|Ce),this._dispatch(m,t))}complete(){if(this._flags&b)return;this._flags=(this._flags|b)&~T|Ae;let t=this._output,i=this._flags&v;if(this._output=null,this._flags&=~(v|D),this._singleDepCount=0,this._stop(),t)if(i)for(let n of t)n(p);else t(p)}error(t){if(this._flags&b)return;this._flags=(this._flags|b)&~T|Ie;let i=this._output,n=this._flags&v;if(this._output=null,this._flags&=~(v|D),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(p,t);else i(p,t)}_start(){if(this._flags&Y||!this._fn)return;this._flags|=Y,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&Y&&(this._flags&=~Y,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&le&&(this._value=this._initial),this._flags&b||(this._flags=this._flags&~T|W))}_handleLifecycleSignal(t){if(!(this._flags&b)){if(t===z){this._onLifecycleSignal?.(t),this.complete();return}t===V&&(this._value=this._initial,this._flags&=~R),this._onLifecycleSignal?.(t),t===V&&this.emit(this._initial)}}source(t,i){if(t===h){let n=i;if(this._flags&b)if(this._flags&ue&&this._output===null)this._flags=this._flags&~(b|T)|W;else{n(h,r=>{}),n(p);return}if(this._output===null)this._output=n;else if(this._flags&v)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|v)&~D}let s=!1;n(h,(r,a)=>{if(r===y&&n(y,this._value),r===m){a===J&&!s?(s=!0,this._singleDepCount++,this._flags&v||(this._flags|=D)):Z(a)&&this._handleLifecycleSignal(a);return}if(r===p){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&v){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~v,this._singleDepCount>0&&(this._flags|=D)):u.size===0&&(this._output=null,this._flags&=~(v|D),this._singleDepCount=0,this._flags=this._flags&~T|W,this._stop())}else this._output===n&&(this._output=null,this._flags&=~D,this._singleDepCount=0,this._flags=this._flags&~T|W,this._stop())}}),ae(()=>this._start())}}};var q=class extends H{constructor(t,i){super(void 0,{initial:t,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),w.register(this,{kind:"state",...i})}get(){return this._value}set(t){this._flags&b||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(O()?this._flags&R||(this._flags|=R,this._flags&A&&(this._flags=this._flags&~T|I,this._dispatch(m,E)),U(()=>{this._flags&=~R,this._flags=this._flags&~T|N,this._dispatch(y,this._value)})):(this._flags&A&&!(this._flags&D)&&(this._flags=this._flags&~T|I,this._dispatch(m,E)),this._flags=this._flags&~T|N,this._dispatch(y,this._value))))}update(t){this.set(t(this._value))}};function ce(e,t){return new q(e,t)}function fe(e,t,i){let n=null;re(),e.source(h,(r,a)=>{if(r===h&&(n=a),r===p){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 oe(),{unsubscribe(){n?.(p),n=null},signal(r){n?.(m,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 pe(e,t){let i=t?.predicate,n=t?.signal;return new Promise((s,r)=>{if(n?.aborted){r(n.reason??new DOMException("The operation was aborted.","AbortError"));return}let a=!1,u=de(e,o=>{(!i||i(o))&&(a=!0,f(),u.unsubscribe(),s(o))},{onEnd:o=>{a||(a=!0,f(),r(o??new Error("source completed without matching value")))}});function l(){a||(a=!0,f(),u.unsubscribe(),r(n.reason??new DOMException("The operation was aborted.","AbortError")))}function f(){n?.removeEventListener("abort",l)}n?.addEventListener("abort",l)})}function ge(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",u=t?.pingInterval??3e4,l=ce(0,{name:`${n}:connections`}),f=new Set,o=new Map,c=null;function d(){c||(c=fe(e,S=>{let g=r(S),L=`event: ${a}
|
|
5
5
|
data: ${g}
|
|
6
6
|
|
|
7
7
|
`;for(let C of f)try{C.write(L)}catch{_(C)}}))}function _(S){f.delete(S);let g=o.get(S);g&&(clearInterval(g),o.delete(S)),l.set(f.size),f.size===0&&c&&(c.unsubscribe(),c=null)}function P(S,g){let L=S.method?.toUpperCase();if((S.url??"/").split("?")[0]!==i){g.writeHead(404,{"Content-Type":"text/plain"}),g.end("Not found");return}if(L==="OPTIONS"){g.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),g.end();return}if(L!=="GET"){g.writeHead(405,{"Content-Type":"text/plain"}),g.end("Method not allowed");return}g.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),g.write(`:ok
|
package/dist/adapters/sse.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-PLIRVTP4.js";import"../chunk-XEU7KSEO.js";import"../chunk-4VPAGOLZ.js";import"../chunk-4ILN4V4C.js";import"../chunk-GMLWTZFM.js";import"../chunk-EAK2HKAD.js";import"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.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===E?"DIRTY":t===$?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,r,n){let s=null,i=!1,a=r??e.getName(t),u=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!i},get errored(){return l.ended&&i},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return u},dispose:()=>s?.(g),reconnect:()=>(s?.(g),e._observe(t,r,n))};return t.source(h,(d,o)=>{if(d===h){s=o;return}let c=
|
|
1
|
+
"use strict";var Z=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var $e=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},Me=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ne(t))!Pe.call(e,s)&&s!==r&&Z(e,s,{get:()=>t[s],enumerable:!(n=Ie(t,s))||n.enumerable});return e};var We=e=>Me(Z({},"__esModule",{value:!0}),e);var Ue={};$e(Ue,{fromWebhook:()=>qe});module.exports=We(Ue);var E=Symbol("DIRTY"),$=Symbol("RESOLVED"),ue=Symbol("SINGLE_DEP"),C=Symbol("RESET"),X=Symbol("PAUSE"),ee=Symbol("RESUME"),te=Symbol("TEARDOWN");function le(e){return e===C||e===X||e===ee||e===te}var ce=0,de=1,fe=2,pe=3,ge=4,he=5,x=7,ne=7<<x,je=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function Te(e){return je[(e&ne)>>>x]}var h=0,y=1,g=2,_=3,V=0,q=[],Q=!1;function se(e){V++;try{return e()}finally{if(V--,V===0&&!Q){Q=!0;for(let t=0;t<q.length;t++)q[t]();q.length=0,Q=!1}}}function A(){return V>0}function H(e){q.push(e)}var B=0,U=[];function Se(){B++}function me(){if(B--,B===0){for(let e=0;e<U.length;e++)U[e]();U.length=0}}function _e(e){B>0?U.push(e):e()}var D=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 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++,s=r?.name;if(!(s&&!e._usedKeys.has(s)))if(s){let i=e._depSuffix(r?.deps);s=i?`${s}(${i})`:`${s}_${n}`,e._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let i=r?.kind??"store",a=e._depSuffix(r?.deps);s=a?`${i}(${a})`:`${i}_${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,r){if(!e.enabled)return;let n=e._resolveKey(t),s=e._resolveKey(r),i=e._edges.get(n);i?i.includes(s)||i.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,r=new Set;for(let n of e._stores){let s=n.deref();if(!s){e._stores.delete(n);continue}let i=e._resolveKey(s);r.add(i),t.set(i,e.inspect(s))}for(let[n,s]of e._edges){if(!r.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let i=s.filter(a=>r.has(a));i.length===0?e._edges.delete(n):i.length!==s.length&&e._edges.set(n,i)}return t}static trace(t,r){let n=null,s=t.get();return t.source(h,(i,a)=>{if(i===h&&(n=a),i===g){n=null;return}if(i===1){let u=a;if(!Object.is(u,s)){let l=s;s=u,r(u,l)}}}),()=>n?.(g)}static dumpGraph(){let t=e.graph(),r=e.getEdges(),n=new Map;for(let[a,u]of r)for(let l of u){let d=n.get(l);d?d.includes(a)||d.push(a):n.set(l,[a])}let s=[];for(let[a,u]of t){let l=n.get(a),d=r.get(a),o=l?.length?` \u2190 [${l.join(", ")}]`:"",c=d?.length?` \u2192 [${d.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===E?"DIRTY":t===$?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,r,n){let s=null,i=!1,a=r??e.getName(t),u=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!i},get errored(){return l.ended&&i},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return u},dispose:()=>s?.(g),reconnect:()=>(s?.(g),e._observe(t,r,n))};return t.source(h,(d,o)=>{if(d===h){s=o;return}let c=A();d===y?(l.values.push(o),l.events.push({type:"data",data:o,inBatch:c}),u.push(o),n&&n(`[${a}] DATA:`,o)):d===_?(l.signals.push(o),l.events.push({type:"signal",data:o,inBatch:c}),u.push(e._signalLabel(o)),o===E?l.dirtyCount++:o===$&&l.resolvedCount++,n&&n(`[${a}] STATE:`,o)):d===g&&(l.ended=!0,l.endError=o,i=o!==void 0,l.events.push({type:"end",data:o,inBatch:c}),u.push(i?["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 r=null;return t.source(h,(n,s)=>{n===h&&(r=s),n===g&&(r=null)}),()=>r?.(g)}static tap(t,r){let n=r??`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,r){let n=r?.name??e.getName(t)??"spy",s=r?.log??console.log;return e._observe(t,n,s)}static snapshot(){let t=e.graph(),r=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},d=n.get(a);d!==void 0&&(l.annotation=d),s.push(l)}let i=[];for(let[a,u]of r)for(let l of u)i.push({from:a,to:l});return{nodes:s,edges:i,trace:e.traceLog()}}static toMermaid(t){let r=t?.direction??"TD",n=e.snapshot(),s=[`graph ${r}`],i={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},a=new Map;function u(o){let c=o.replace(/[^a-zA-Z0-9_]/g,"_"),f=a.get(c);return f===void 0?(a.set(c,1),c):(a.set(c,f+1),`${c}__${f}`)}let l=new Map;function d(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 f=`${o.name} (${o.kind}) = ${d(o.value)}`,T=i[o.status??""]??"";s.push(` ${c}["${f}"]${T}`)}for(let o of n.edges){let c=l.get(o.from)??u(o.from),f=l.get(o.to)??u(o.to);s.push(` ${c} --> ${f}`)}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
3
|
`)}static toD2(t){let r=t?.direction??"down",n=e.snapshot(),s=[`direction: ${r}`,""],i={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,"_"),f=a.get(c);return f===void 0?(a.set(c,1),c):(a.set(c,f+1),`${c}__${f}`)}let l=new Map;function d(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 f=i[o.kind]??"rectangle",T=`${o.name} (${o.kind}) = ${d(o.value)}`,F=o.status?` [${o.status}]`:"";s.push(`${c}: "${T}${F}" { shape: ${f} }`)}n.edges.length>0&&s.push("");for(let o of n.edges){let c=l.get(o.from)??u(o.from),f=l.get(o.to)??u(o.to);s.push(`${c} -> ${f}`)}return s.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()},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 timeline(t){let r=null,n=[];return t.source(h,(s,i)=>{if(s===h){r=i;return}let a={timestamp:Date.now(),type:s===y?"data":s===_?"signal":"end",data:i,inBatch:C()};n.push(a),s===g&&(r=null)}),{entries:n,dispose:()=>r?.(g)}}static observeDerived(t){let r=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:r};n._fn=()=>{let l=n._deps.map(o=>o.get()),d=s();return r.push({result:d,depValues:l,timestamp:Date.now()}),d};let i=e._observe(t),a=i.dispose;return{...i,evaluations:r,dispose:()=>{n._fn=s,a()},reconnect:()=>(n._fn=s,a(),e.observeDerived(t))}}static observeTaskState(t){let r=t.status.get(),n=[],s=null;return t.status.source(h,(i,a)=>{if(i===h){s=a;return}if(i===y){let u=a;if(u!==r){let l={from:r,to:u,timestamp:Date.now()};u==="error"&&(l.error=t.error.get()),n.push(l),r=u}}i===g&&(s=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{s?.(g)}}}static causalityTrace(t){let r=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:r};let i=n._deps,a=i.map(o=>o.get());n._fn=()=>{let o=i.map(T=>T.get()),c=s(),f=-1;for(let T=0;T<i.length;T++)if(!Object.is(o[T],a[T])){f=T;break}return r.push({result:c,triggerDepIndex:f,triggerDepName:f>=0?e.getName(i[f]):void 0,depValues:o,timestamp:Date.now()}),a=o,c};let u=e._observe(t),l=u.dispose;return{...u,causality:r,dispose:()=>{n._fn=s,l()},reconnect:()=>(n._fn=s,l(),e.causalityTrace(t))}}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var Y=1,v=64,b=2,A=4,ye=8,be=16,O=32,k=1024,S=ne,N=de<<x,j=fe<<x,z=ce<<x,Fe=ge<<x,Ke=he<<x,Ve=pe<<x,M=class{_value;_output=null;_flags;get _status(){return Te(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|=A),r?.resetOnTeardown&&(n|=ye),r?.resubscribable&&(n|=be),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||D.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&v)for(let s of n)s(t,r);else n(t,r)}emit(t){this._flags&b||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(C()?this._flags&O||(this._flags|=O,this._flags&A&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),H(()=>{this._flags&=~O,this._flags=this._flags&~S|j,this._dispatch(y,this._value)})):(this._flags&A&&!(this._flags&k)&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),this._flags=this._flags&~S|j,this._dispatch(y,this._value))))}signal(t){this._flags&b||!this._output||(t===E?this._flags=this._flags&~S|N:t===$&&(this._flags=this._flags&~S|Ve),this._dispatch(_,t))}complete(){if(this._flags&b)return;this._flags=(this._flags|b)&~S|Fe;let t=this._output,r=this._flags&v;if(this._output=null,this._flags&=~(v|k),this._singleDepCount=0,this._stop(),t)if(r)for(let n of t)n(g);else t(g)}error(t){if(this._flags&b)return;this._flags=(this._flags|b)&~S|Ke;let r=this._output,n=this._flags&v;if(this._output=null,this._flags&=~(v|k),this._singleDepCount=0,this._stop(),r)if(n)for(let s of r)s(g,t);else r(g,t)}_start(){if(this._flags&Y||!this._fn)return;this._flags|=Y,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&Y&&(this._flags&=~Y,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&ye&&(this._value=this._initial),this._flags&b||(this._flags=this._flags&~S|z))}_handleLifecycleSignal(t){if(!(this._flags&b)){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,r){if(t===h){let n=r;if(this._flags&b)if(this._flags&be&&this._output===null)this._flags=this._flags&~(b|S)|z;else{n(h,i=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&v)this._output.add(n);else{let i=new Set;i.add(this._output),i.add(n),this._output=i,this._flags=(this._flags|v)&~k}let s=!1;n(h,(i,a)=>{if(i===y&&n(y,this._value),i===_){a===ue&&!s?(s=!0,this._singleDepCount++,this._flags&v||(this._flags|=k)):le(a)&&this._handleLifecycleSignal(a);return}if(i===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&v){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~v,this._singleDepCount>0&&(this._flags|=k)):u.size===0&&(this._output=null,this._flags&=~(v|k),this._singleDepCount=0,this._flags=this._flags&~S|z,this._stop())}else this._output===n&&(this._output=null,this._flags&=~k,this._singleDepCount=0,this._flags=this._flags&~S|z,this._stop())}}),_e(()=>this._start())}}};function J(e,t){return new M(e,t)}var re=class extends M{constructor(t,r){super(void 0,{initial:t,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),D.register(this,{kind:"state",...r})}get(){return this._value}set(t){this._flags&b||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(C()?this._flags&O||(this._flags|=O,this._flags&A&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),H(()=>{this._flags&=~O,this._flags=this._flags&~S|j,this._dispatch(y,this._value)})):(this._flags&A&&!(this._flags&k)&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),this._flags=this._flags&~S|j,this._dispatch(y,this._value))))}update(t){this.set(t(this._value))}};function W(e,t){return new re(e,t)}function ve(e,t,r){let n=null;return e(0,(s,i)=>{if(s===0){n=i;return}if(s===2){n=null,r?.onEnd?.(i);return}s===1&&t(i)}),{unsubscribe(){n?.(2),n=null}}}function Ee(e,t){return new Promise((r,n)=>{let s=ve(e,i=>{(!t||t(i))&&(s.unsubscribe(),r(i))},{onEnd:i=>{n(i??new Error("source completed without matching value"))}})})}function De(e){return(t,r)=>{if(t!==0)return;let n=!1,s;r(0,i=>{i===2&&!n&&(n=!0,s?.())});try{s=e(i=>{n||(n=!0,r(1,i),r(2))},i=>{n||(n=!0,r(2,i))})}catch(i){n||(n=!0,r(2,i))}}}function ke(e,t,r){let n=null;Se(),e.source(h,(i,a)=>{if(i===h&&(n=a),i===g){n=null,r?.onEnd?.(a);return}if(i===1){let u=a,l=s;s=u,t(u,l)}});let s;try{s=e.get()}catch{}return me(),{unsubscribe(){n?.(g),n=null},signal(i){n?.(_,i)}}}function xe(e,t){let r=t?.initialStatus??"pending",n=W(r,{name:"withStatus:status",equals:Object.is}),s=W(void 0,{name:"withStatus:error",equals:Object.is}),i=J(({emit:u,complete:l,error:d})=>{n.set(r),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 f=c instanceof Error?c:new Error(String(c));se(()=>{s.set(f),n.set("errored")}),d(c)}else n.set("completed"),l()}});return()=>{o.unsubscribe()}},{initial:e.get(),resubscribable:!0}),a={get:()=>e.get(),source:(u,l)=>i.source(u,l),get _status(){return i._status},status:n,error:s};return D.register(a,{kind:"withStatus"}),a}function qe(e){let t=e?.path??"/",r=e?.parse??JSON.parse,n=e?.name??"webhook",s=e?.hostname??"0.0.0.0",i=e?.maxBodySize??1024*1024,a=e?.responseTimeout??3e4,u=W(0,{name:`${n}:count`}),l=null,d=!1,o=J(({emit:m,onSignal:p})=>(l=m,d=!1,p(w=>{w===X?d=!0:w===ee?d=!1:w===I&&(d=!1,u.set(0))}),()=>{l=null,d=!1}),{name:n,kind:"webhook"});D.register(o,{kind:"webhook"});let c=xe(o),f=null,T=new Set;function F(m,p){let w=m.method?.toUpperCase(),Oe=(m.url??"/").split("?")[0];if(w!=="POST"||Oe!==t){p.writeHead(404,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Not found"}));return}if(d){p.writeHead(503,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Service paused"}));return}let oe=[],ae=0,K=!1;m.on("error",()=>{K=!0,p.headersSent||(p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Request aborted"})))}),m.on("data",L=>{if(!K){if(ae+=L.length,ae>i){K=!0,p.writeHead(413,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Payload too large"})),m.destroy?.();return}oe.push(L)}}),m.on("end",()=>{if(!K)try{let L=Buffer.concat(oe).toString("utf-8"),Le=L.length>0?r(L):void 0;u.update(G=>G+1);let P=!1,R=null,Ce={body:Le,get responded(){return P},respond(G,Ie=200){P||(P=!0,R!==null&&(clearTimeout(R),T.delete(R),R=null),p.writeHead(Ie,{"Content-Type":"application/json"}),p.end(JSON.stringify(G)))}};R=setTimeout(()=>{T.delete(R),R=null,P||(P=!0,p.writeHead(504,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Response timeout"})))},a),T.add(R),l?.(Ce)}catch(L){p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:L?.message??"Parse error"}))}})}function we(){return e?.port?f?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):Ee(De((m,p)=>{try{f=require("http").createServer(F),f.once("listening",()=>m()),f.once("error",ie=>{f=null,p(ie)}),f.listen(e.port,s);return}catch(w){p(w);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function Re(){for(let m of T)clearTimeout(m);T.clear(),f?.close(),f=null}return{get:()=>c.get(),source:(m,p)=>c.source(m,p),status:c.status,error:c.error,requestCount:u,handler:F,listen:we,close:Re}}0&&(module.exports={fromWebhook});
|
|
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()},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 timeline(t){let r=null,n=[];return t.source(h,(s,i)=>{if(s===h){r=i;return}let a={timestamp:Date.now(),type:s===y?"data":s===_?"signal":"end",data:i,inBatch:A()};n.push(a),s===g&&(r=null)}),{entries:n,dispose:()=>r?.(g)}}static observeDerived(t){let r=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:r};n._fn=()=>{let l=n._deps.map(o=>o.get()),d=s();return r.push({result:d,depValues:l,timestamp:Date.now()}),d};let i=e._observe(t),a=i.dispose;return{...i,evaluations:r,dispose:()=>{n._fn=s,a()},reconnect:()=>(n._fn=s,a(),e.observeDerived(t))}}static observeTaskState(t){let r=t.status.get(),n=[],s=null;return t.status.source(h,(i,a)=>{if(i===h){s=a;return}if(i===y){let u=a;if(u!==r){let l={from:r,to:u,timestamp:Date.now()};u==="error"&&(l.error=t.error.get()),n.push(l),r=u}}i===g&&(s=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{s?.(g)}}}static causalityTrace(t){let r=[],n=t,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:r};let i=n._deps,a=i.map(o=>o.get());n._fn=()=>{let o=i.map(T=>T.get()),c=s(),f=-1;for(let T=0;T<i.length;T++)if(!Object.is(o[T],a[T])){f=T;break}return r.push({result:c,triggerDepIndex:f,triggerDepName:f>=0?e.getName(i[f]):void 0,depValues:o,timestamp:Date.now()}),a=o,c};let u=e._observe(t),l=u.dispose;return{...u,causality:r,dispose:()=>{n._fn=s,l()},reconnect:()=>(n._fn=s,l(),e.causalityTrace(t))}}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var Y=1,v=64,b=2,I=4,ye=8,be=16,O=32,k=1024,S=ne,N=de<<x,M=fe<<x,z=ce<<x,Fe=ge<<x,Ke=he<<x,Ve=pe<<x,W=class{_value;_output=null;_flags;get _status(){return Te(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|=I),r?.resetOnTeardown&&(n|=ye),r?.resubscribable&&(n|=be),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||D.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&v)for(let s of n)s(t,r);else n(t,r)}emit(t){this._flags&b||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(A()?this._flags&O||(this._flags|=O,this._flags&I&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),H(()=>{this._flags&=~O,this._flags=this._flags&~S|M,this._dispatch(y,this._value)})):(this._flags&I&&!(this._flags&k)&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),this._flags=this._flags&~S|M,this._dispatch(y,this._value))))}signal(t){this._flags&b||!this._output||(t===E?this._flags=this._flags&~S|N:t===$&&(this._flags=this._flags&~S|Ve),this._dispatch(_,t))}complete(){if(this._flags&b)return;this._flags=(this._flags|b)&~S|Fe;let t=this._output,r=this._flags&v;if(this._output=null,this._flags&=~(v|k),this._singleDepCount=0,this._stop(),t)if(r)for(let n of t)n(g);else t(g)}error(t){if(this._flags&b)return;this._flags=(this._flags|b)&~S|Ke;let r=this._output,n=this._flags&v;if(this._output=null,this._flags&=~(v|k),this._singleDepCount=0,this._stop(),r)if(n)for(let s of r)s(g,t);else r(g,t)}_start(){if(this._flags&Y||!this._fn)return;this._flags|=Y,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&Y&&(this._flags&=~Y,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&ye&&(this._value=this._initial),this._flags&b||(this._flags=this._flags&~S|z))}_handleLifecycleSignal(t){if(!(this._flags&b)){if(t===te){this._onLifecycleSignal?.(t),this.complete();return}t===C&&(this._value=this._initial,this._flags&=~O),this._onLifecycleSignal?.(t),t===C&&this.emit(this._initial)}}source(t,r){if(t===h){let n=r;if(this._flags&b)if(this._flags&be&&this._output===null)this._flags=this._flags&~(b|S)|z;else{n(h,i=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&v)this._output.add(n);else{let i=new Set;i.add(this._output),i.add(n),this._output=i,this._flags=(this._flags|v)&~k}let s=!1;n(h,(i,a)=>{if(i===y&&n(y,this._value),i===_){a===ue&&!s?(s=!0,this._singleDepCount++,this._flags&v||(this._flags|=k)):le(a)&&this._handleLifecycleSignal(a);return}if(i===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&v){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~v,this._singleDepCount>0&&(this._flags|=k)):u.size===0&&(this._output=null,this._flags&=~(v|k),this._singleDepCount=0,this._flags=this._flags&~S|z,this._stop())}else this._output===n&&(this._output=null,this._flags&=~k,this._singleDepCount=0,this._flags=this._flags&~S|z,this._stop())}}),_e(()=>this._start())}}};function J(e,t){return new W(e,t)}var re=class extends W{constructor(t,r){super(void 0,{initial:t,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),D.register(this,{kind:"state",...r})}get(){return this._value}set(t){this._flags&b||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(A()?this._flags&O||(this._flags|=O,this._flags&I&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),H(()=>{this._flags&=~O,this._flags=this._flags&~S|M,this._dispatch(y,this._value)})):(this._flags&I&&!(this._flags&k)&&(this._flags=this._flags&~S|N,this._dispatch(_,E)),this._flags=this._flags&~S|M,this._dispatch(y,this._value))))}update(t){this.set(t(this._value))}};function j(e,t){return new re(e,t)}function ve(e,t,r){let n=null;return e(0,(s,i)=>{if(s===0){n=i;return}if(s===2){n=null,r?.onEnd?.(i);return}s===1&&t(i)}),{unsubscribe(){n?.(2),n=null}}}function Ee(e,t){let r=t?.predicate,n=t?.signal;return new Promise((s,i)=>{if(n?.aborted){i(n.reason??new DOMException("The operation was aborted.","AbortError"));return}let a=!1,u=ve(e,o=>{(!r||r(o))&&(a=!0,d(),u.unsubscribe(),s(o))},{onEnd:o=>{a||(a=!0,d(),i(o??new Error("source completed without matching value")))}});function l(){a||(a=!0,d(),u.unsubscribe(),i(n.reason??new DOMException("The operation was aborted.","AbortError")))}function d(){n?.removeEventListener("abort",l)}n?.addEventListener("abort",l)})}function De(e){return(t,r)=>{if(t!==0)return;let n=!1,s;r(0,i=>{i===2&&!n&&(n=!0,s?.())});try{s=e(i=>{n||(n=!0,r(1,i),r(2))},i=>{n||(n=!0,r(2,i))})}catch(i){n||(n=!0,r(2,i))}}}function ke(e,t,r){let n=null;Se(),e.source(h,(i,a)=>{if(i===h&&(n=a),i===g){n=null,r?.onEnd?.(a);return}if(i===1){let u=a,l=s;s=u,t(u,l)}});let s;try{s=e.get()}catch{}return me(),{unsubscribe(){n?.(g),n=null},signal(i){n?.(_,i)}}}function xe(e,t){let r=t?.initialStatus??"pending",n=j(r,{name:"withStatus:status",equals:Object.is}),s=j(void 0,{name:"withStatus:error",equals:Object.is}),i=J(({emit:u,complete:l,error:d})=>{n.set(r),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 f=c instanceof Error?c:new Error(String(c));se(()=>{s.set(f),n.set("errored")}),d(c)}else n.set("completed"),l()}});return()=>{o.unsubscribe()}},{initial:e.get(),resubscribable:!0}),a={get:()=>e.get(),source:(u,l)=>i.source(u,l),get _status(){return i._status},status:n,error:s};return D.register(a,{kind:"withStatus"}),a}function qe(e){let t=e?.path??"/",r=e?.parse??JSON.parse,n=e?.name??"webhook",s=e?.hostname??"0.0.0.0",i=e?.maxBodySize??1024*1024,a=e?.responseTimeout??3e4,u=j(0,{name:`${n}:count`}),l=null,d=!1,o=J(({emit:m,onSignal:p})=>(l=m,d=!1,p(w=>{w===X?d=!0:w===ee?d=!1:w===C&&(d=!1,u.set(0))}),()=>{l=null,d=!1}),{name:n,kind:"webhook"});D.register(o,{kind:"webhook"});let c=xe(o),f=null,T=new Set;function F(m,p){let w=m.method?.toUpperCase(),Oe=(m.url??"/").split("?")[0];if(w!=="POST"||Oe!==t){p.writeHead(404,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Not found"}));return}if(d){p.writeHead(503,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Service paused"}));return}let oe=[],ae=0,K=!1;m.on("error",()=>{K=!0,p.headersSent||(p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Request aborted"})))}),m.on("data",L=>{if(!K){if(ae+=L.length,ae>i){K=!0,p.writeHead(413,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Payload too large"})),m.destroy?.();return}oe.push(L)}}),m.on("end",()=>{if(!K)try{let L=Buffer.concat(oe).toString("utf-8"),Le=L.length>0?r(L):void 0;u.update(G=>G+1);let P=!1,R=null,Ae={body:Le,get responded(){return P},respond(G,Ce=200){P||(P=!0,R!==null&&(clearTimeout(R),T.delete(R),R=null),p.writeHead(Ce,{"Content-Type":"application/json"}),p.end(JSON.stringify(G)))}};R=setTimeout(()=>{T.delete(R),R=null,P||(P=!0,p.writeHead(504,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Response timeout"})))},a),T.add(R),l?.(Ae)}catch(L){p.writeHead(400,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:L?.message??"Parse error"}))}})}function we(){return e?.port?f?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):Ee(De((m,p)=>{try{f=require("http").createServer(F),f.once("listening",()=>m()),f.once("error",ie=>{f=null,p(ie)}),f.listen(e.port,s);return}catch(w){p(w);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function Re(){for(let m of T)clearTimeout(m);T.clear(),f?.close(),f=null}return{get:()=>c.get(),source:(m,p)=>c.source(m,p),status:c.status,error:c.error,requestCount:u,handler:F,listen:we,close:Re}}0&&(module.exports={fromWebhook});
|
package/dist/adapters/webhook.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-7B4DHRG6.js";import"../chunk-XEU7KSEO.js";import"../chunk-4VPAGOLZ.js";import"../chunk-4ILN4V4C.js";import"../chunk-5LLYKN4X.js";import"../chunk-GMLWTZFM.js";import"../chunk-EAK2HKAD.js";import"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromWebhook};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var te=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var ke=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var i in e)te(t,i,{get:e[i],enumerable:!0})},Le=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ae(e))!ke.call(t,s)&&s!==i&&te(t,s,{get:()=>e[s],enumerable:!(n=De(e,s))||n.enumerable});return t};var we=t=>Le(te({},"__esModule",{value:!0}),t);var Ge={};Re(Ge,{agentLoop:()=>Ve});module.exports=we(Ge);var R=Symbol("DIRTY"),Y=Symbol("RESOLVED"),re=Symbol("SINGLE_DEP"),H=Symbol("RESET"),Ce=Symbol("PAUSE"),Oe=Symbol("RESUME"),ne=Symbol("TEARDOWN");function ae(t){return t===H||t===Ce||t===Oe||t===ne}var ce=0,le=1,ue=2,fe=3,de=4,pe=5,w=7,se=7<<w,Pe=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ge(t){return Pe[(t&se)>>>w]}var S=0,b=1,T=2,D=3,Ie=0,$e=[];function N(){return Ie>0}function q(t){$e.push(t)}var Ne=0,Me=[];function Te(t){Ne>0?Me.push(t):t()}var F=class t{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(t._explicitEnabled!==null)return t._explicitEnabled;if(t._cachedDefault!==null)return t._cachedDefault;try{t._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{t._cachedDefault=!0}return t._cachedDefault}static set enabled(e){t._explicitEnabled=e}static _depSuffix(e){if(!e?.length)return;let n=e.map(s=>t._names.get(s)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(e){let i=t._keys.get(e)??t._names.get(e);if(i)return i;let n=`anonymous_${t._nextId++}`;return t._keys.set(e,n),n}static register(e,i){if(!t.enabled)return;i?.name&&t._names.set(e,i.name),i?.kind&&t._kinds.set(e,i.kind);let n=t._nextId++,s=i?.name;if(!(s&&!t._usedKeys.has(s)))if(s){let o=t._depSuffix(i?.deps);s=o?`${s}(${o})`:`${s}_${n}`,t._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let o=i?.kind??"store",a=t._depSuffix(i?.deps);s=a?`${o}(${a})`:`${o}_${n}`,t._usedKeys.has(s)&&(s=`${s}_${n}`)}t._usedKeys.add(s),t._keys.set(e,s),t._stores.add(new WeakRef(e))}static registerEdge(e,i){if(!t.enabled)return;let n=t._resolveKey(e),s=t._resolveKey(i),o=t._edges.get(n);o?o.includes(s)||o.push(s):t._edges.set(n,[s])}static getEdges(){return new Map(t._edges)}static getName(e){if(t.enabled)return t._names.get(e)}static getKind(e){return t._kinds.get(e)}static inspect(e){return{name:t._names.get(e),kind:t._kinds.get(e)??"unknown",value:typeof e.get=="function"?e.get():void 0,status:e._status}}static graph(){let e=new Map,i=new Set;for(let n of t._stores){let s=n.deref();if(!s){t._stores.delete(n);continue}let o=t._resolveKey(s);i.add(o),e.set(o,t.inspect(s))}for(let[n,s]of t._edges){if(!i.has(n)){t._edges.delete(n),t._usedKeys.delete(n);continue}let o=s.filter(a=>i.has(a));o.length===0?t._edges.delete(n):o.length!==s.length&&t._edges.set(n,o)}return e}static trace(e,i){let n=null,s=e.get();return e.source(S,(o,a)=>{if(o===S&&(n=a),o===T){n=null;return}if(o===1){let c=a;if(!Object.is(c,s)){let l=s;s=c,i(c,l)}}}),()=>n?.(T)}static dumpGraph(){let e=t.graph(),i=t.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 e){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 (${e.size} nodes):`,...s].join(`
|
|
2
|
+
`)}static _signalLabel(e){return e===R?"DIRTY":e===Y?"RESOLVED":typeof e=="symbol"?e.description??String(e):String(e)}static _observe(e,i,n){let s=null,o=!1,a=i??t.getName(e),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?.(T),reconnect:()=>(s?.(T),t._observe(e,i,n))};return e.source(S,(f,r)=>{if(f===S){s=r;return}let u=N();f===b?(l.values.push(r),l.events.push({type:"data",data:r,inBatch:u}),c.push(r),n&&n(`[${a}] DATA:`,r)):f===D?(l.signals.push(r),l.events.push({type:"signal",data:r,inBatch:u}),c.push(t._signalLabel(r)),r===R?l.dirtyCount++:r===Y&&l.resolvedCount++,n&&n(`[${a}] STATE:`,r)):f===T&&(l.ended=!0,l.endError=r,o=r!==void 0,l.events.push({type:"end",data:r,inBatch:u}),c.push(o?["END",r]:"END"),n&&n(`[${a}] END`,r!==void 0?r:""),s=null)}),l}static observe(e){return t._observe(e)}static activate(e){let i=null;return e.source(S,(n,s)=>{n===S&&(i=s),n===T&&(i=null)}),()=>i?.(T)}static tap(e,i){let n=i??`tap(${t.getName(e)??"anon"})`,s={get:()=>e.get(),source:e.source};return t.register(s,{name:n,kind:"tap"}),t.registerEdge(e,s),s}static spy(e,i){let n=i?.name??t.getName(e)??"spy",s=i?.log??console.log;return t._observe(e,n,s)}static snapshot(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let a of t._stores){let c=a.deref();if(!c)continue;let l=t._annotations.get(c);l!==void 0&&n.set(t._resolveKey(c),l)}let s=[];for(let[a,c]of e){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:t.traceLog()}}static toMermaid(e){let i=e?.direction??"TD",n=t.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,"_"),d=a.get(u);return d===void 0?(a.set(u,1),u):(a.set(u,d+1),`${u}__${d}`)}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 d=`${r.name} (${r.kind}) = ${f(r.value)}`,h=o[r.status??""]??"";s.push(` ${u}["${d}"]${h}`)}for(let r of n.edges){let u=l.get(r.from)??c(r.from),d=l.get(r.to)??c(r.to);s.push(` ${u} --> ${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(e){let i=e?.direction??"down",n=t.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,"_"),d=a.get(u);return d===void 0?(a.set(u,1),u):(a.set(u,d+1),`${u}__${d}`)}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 d=o[r.kind]??"rectangle",h=`${r.name} (${r.kind}) = ${f(r.value)}`,M=r.status?` [${r.status}]`:"";s.push(`${u}: "${h}${M}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let r of n.edges){let u=l.get(r.from)??c(r.from),d=l.get(r.to)??c(r.to);s.push(`${u} -> ${d}`)}return s.join(`
|
|
4
|
+
`)}static annotate(e,i){if(!t.enabled)return;t._annotations.set(e,i);let n={node:t._resolveKey(e),reason:i,timestamp:Date.now()},s=t.maxTraceEntries;s<=0||(t._traceLog.length<s?t._traceLog.push(n):(t._traceLog[t._traceHead]=n,t._traceFull=!0),t._traceHead=(t._traceHead+1)%s)}static getAnnotation(e){return t._annotations.get(e)}static traceLog(){return t._traceFull?[...t._traceLog.slice(t._traceHead),...t._traceLog.slice(0,t._traceHead)]:t._traceLog.slice(0,t._traceHead||t._traceLog.length)}static clearTrace(){t._traceLog=[],t._traceHead=0,t._traceFull=!1}static timeline(e){let i=null,n=[];return e.source(S,(s,o)=>{if(s===S){i=o;return}let a={timestamp:Date.now(),type:s===b?"data":s===D?"signal":"end",data:o,inBatch:N()};n.push(a),s===T&&(i=null)}),{entries:n,dispose:()=>i?.(T)}}static observeDerived(e){let i=[],n=e,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...t.observe(e),evaluations:i};n._fn=()=>{let l=n._deps.map(r=>r.get()),f=s();return i.push({result:f,depValues:l,timestamp:Date.now()}),f};let o=t._observe(e),a=o.dispose;return{...o,evaluations:i,dispose:()=>{n._fn=s,a()},reconnect:()=>(n._fn=s,a(),t.observeDerived(e))}}static observeTaskState(e){let i=e.status.get(),n=[],s=null;return e.status.source(S,(o,a)=>{if(o===S){s=a;return}if(o===b){let c=a;if(c!==i){let l={from:i,to:c,timestamp:Date.now()};c==="error"&&(l.error=e.error.get()),n.push(l),i=c}}o===T&&(s=null)}),{transitions:n,get currentStatus(){return e.status.get()},dispose:()=>{s?.(T)}}}static causalityTrace(e){let i=[],n=e,s=n._fn;if(typeof s!="function"||!Array.isArray(n._deps))return{...t.observe(e),causality:i};let o=n._deps,a=o.map(r=>r.get());n._fn=()=>{let r=o.map(h=>h.get()),u=s(),d=-1;for(let h=0;h<o.length;h++)if(!Object.is(r[h],a[h])){d=h;break}return i.push({result:u,triggerDepIndex:d,triggerDepName:d>=0?t.getName(o[d]):void 0,depValues:r,timestamp:Date.now()}),a=r,u};let c=t._observe(e),l=c.dispose;return{...c,causality:i,dispose:()=>{n._fn=s,l()},reconnect:()=>(n._fn=s,l(),t.causalityTrace(e))}}static _reset(){t._names=new WeakMap,t._kinds=new WeakMap,t._keys=new WeakMap,t._stores=new Set,t._edges=new Map,t._usedKeys=new Set,t._nextId=0,t._explicitEnabled=null,t._cachedDefault=null,t._annotations=new WeakMap,t._traceLog=[],t._traceHead=0,t._traceFull=!1,t.maxTraceEntries=1e3}};var z=1,A=64,v=2,K=4,he=8,_e=16,I=32,L=1024,_=se,V=le<<w,B=ue<<w,J=ce<<w,je=de<<w,Fe=pe<<w,Ke=fe<<w,U=class{_value;_output=null;_flags;get _status(){return ge(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(e,i){this._value=i?.initial,this._fn=e,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=K),i?.resetOnTeardown&&(n|=he),i?.resubscribable&&(n|=_e),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||F.register(this,{kind:"producer",...i})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(e,i){let n=this._output;if(n)if(this._flags&A)for(let s of n)s(e,i);else n(e,i)}emit(e){this._flags&v||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(N()?this._flags&I||(this._flags|=I,this._flags&K&&(this._flags=this._flags&~_|V,this._dispatch(D,R)),q(()=>{this._flags&=~I,this._flags=this._flags&~_|B,this._dispatch(b,this._value)})):(this._flags&K&&!(this._flags&L)&&(this._flags=this._flags&~_|V,this._dispatch(D,R)),this._flags=this._flags&~_|B,this._dispatch(b,this._value))))}signal(e){this._flags&v||!this._output||(e===R?this._flags=this._flags&~_|V:e===Y&&(this._flags=this._flags&~_|Ke),this._dispatch(D,e))}complete(){if(this._flags&v)return;this._flags=(this._flags|v)&~_|je;let e=this._output,i=this._flags&A;if(this._output=null,this._flags&=~(A|L),this._singleDepCount=0,this._stop(),e)if(i)for(let n of e)n(T);else e(T)}error(e){if(this._flags&v)return;this._flags=(this._flags|v)&~_|Fe;let i=this._output,n=this._flags&A;if(this._output=null,this._flags&=~(A|L),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(T,e);else i(T,e)}_start(){if(this._flags&z||!this._fn)return;this._flags|=z,this._onLifecycleSignal=void 0;let e=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 e=="function"?e:void 0}_stop(){this._flags&z&&(this._flags&=~z,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&he&&(this._value=this._initial),this._flags&v||(this._flags=this._flags&~_|J))}_handleLifecycleSignal(e){if(!(this._flags&v)){if(e===ne){this._onLifecycleSignal?.(e),this.complete();return}e===H&&(this._value=this._initial,this._flags&=~I),this._onLifecycleSignal?.(e),e===H&&this.emit(this._initial)}}source(e,i){if(e===S){let n=i;if(this._flags&v)if(this._flags&_e&&this._output===null)this._flags=this._flags&~(v|_)|J;else{n(S,o=>{}),n(T);return}if(this._output===null)this._output=n;else if(this._flags&A)this._output.add(n);else{let o=new Set;o.add(this._output),o.add(n),this._output=o,this._flags=(this._flags|A)&~L}let s=!1;n(S,(o,a)=>{if(o===b&&n(b,this._value),o===D){a===re&&!s?(s=!0,this._singleDepCount++,this._flags&A||(this._flags|=L)):ae(a)&&this._handleLifecycleSignal(a);return}if(o===T){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&A){let c=this._output;c.delete(n),c.size===1?(this._output=c.values().next().value,this._flags&=~A,this._singleDepCount>0&&(this._flags|=L)):c.size===0&&(this._output=null,this._flags&=~(A|L),this._singleDepCount=0,this._flags=this._flags&~_|J,this._stop())}else this._output===n&&(this._output=null,this._flags&=~L,this._singleDepCount=0,this._flags=this._flags&~_|J,this._stop())}}),Te(()=>this._start())}}};function me(t,e){return new U(t,e)}var ie=class extends U{constructor(e,i){super(void 0,{initial:e,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),F.register(this,{kind:"state",...i})}get(){return this._value}set(e){this._flags&v||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(N()?this._flags&I||(this._flags|=I,this._flags&K&&(this._flags=this._flags&~_|V,this._dispatch(D,R)),q(()=>{this._flags&=~I,this._flags=this._flags&~_|B,this._dispatch(b,this._value)})):(this._flags&K&&!(this._flags&L)&&(this._flags=this._flags&~_|V,this._dispatch(D,R)),this._flags=this._flags&~_|B,this._dispatch(b,this._value))))}update(e){this.set(e(this._value))}};function C(t,e){return new ie(t,e)}function Se(t,e,i){let n=null;return t(0,(s,o)=>{if(s===0){n=o;return}if(s===2){n=null,i?.onEnd?.(o);return}s===1&&e(o)}),{unsubscribe(){n?.(2),n=null}}}function ye(t,e){let i=e?.predicate,n=e?.signal;return new Promise((s,o)=>{if(n?.aborted){o(n.reason??new DOMException("The operation was aborted.","AbortError"));return}let a=!1,c=Se(t,r=>{(!i||i(r))&&(a=!0,f(),c.unsubscribe(),s(r))},{onEnd:r=>{a||(a=!0,f(),o(r??new Error("source completed without matching value")))}});function l(){a||(a=!0,f(),c.unsubscribe(),o(n.reason??new DOMException("The operation was aborted.","AbortError")))}function f(){n?.removeEventListener("abort",l)}n?.addEventListener("abort",l)})}var Z=class extends Error{constructor(){super("Gate: action rejected")}};function Ve(t){let e=t.name??"agentLoop",i=t.maxIterations??10,n=t.shouldContinue??(()=>!1),s=!!t.gate,o=C("idle",{name:`${e}.phase`}),a=C(void 0,{name:`${e}.context`}),c=C(void 0,{name:`${e}.lastAction`}),l=C(0,{name:`${e}.iteration`}),f=C(void 0,{name:`${e}.error`}),r=C([],{name:`${e}.history`}),u=typeof t.gate=="object"?t.gate:{},d=u.maxPending??1/0,h=s?C([],{name:`${e}.pending`,equals:()=>!1}):void 0,M=s?C(u.startOpen??!1,{name:`${e}.isOpen`}):void 0,k=[],y=null,G=null,E=!1,Q=!1,X=0,ee=null;function $(g,m,p){r.update(P=>[...P,{phase:g,context:m,action:p,iteration:l.get()}])}function be(g){if(!s||!h||E||M.get())return Promise.resolve(g);k.push(g),k.length>d&&k.shift(),h.set([...k]);let m=me(({emit:p,complete:P,error:x})=>(y=j=>{p(j),P()},G=j=>{x(j)},()=>{y=null,G=null}),{_skipInspect:!0});return ye(m.source)}function W(g){let m=k.splice(0,g);return h?.set([...k]),m}async function ve(g,m){if(ee&&(E=!0,y&&y(k[0]??void 0),await ee),m!==X)return;Q=!0,E=!1,k=[],y=null,G=null,h?.set([]);let p=g,P=0;a.set(p),l.set(0),f.set(void 0),c.set(void 0);try{for(;!E;){if(P>=i){o.set("completed"),$("completed",p);break}if(P++,l.set(P),o.set("observe"),$("observe",p),p=await t.observe(p),a.set(p),E)break;o.set("plan"),$("plan",p);let x=await t.plan(p);if(c.set(x),E)break;if(s){o.set("awaiting_approval"),$("awaiting_approval",p,x);try{x=await be(x)}catch(j){if(j instanceof Z&&!E)continue;throw j}if(c.set(x),E)break}if(o.set("act"),$("act",p,x),p=await t.act(x,p),a.set(p),E)break;if(!n(p,P)){o.set("completed"),$("completed",p);break}}}catch(x){E||(f.set(x),o.set("errored"),$("errored",p))}finally{Q=!1}}function Ee(g){X++;let m=X;r.set([]),ee=ve(g,m).catch(()=>{})}function xe(){E=!0,y&&y(k[0]??void 0),Q&&o.set("completed")}let oe={phase:o,context:a,lastAction:c,iteration:l,error:f,start:Ee,stop:xe,history:r};if(!s)return oe;let O=oe;return O.pending=h,O.isOpen=M,O.approve=(g=1)=>{let m=W(1);m.length>0&&y&&y(m[0])},O.reject=(g=1)=>{W(1),G&&G(new Z)},O.modify=g=>{let m=W(1);m.length>0&&y&&y(g(m[0]))},O.open=()=>{M.set(!0);let g=W(k.length);g.length>0&&y&&y(g[0])},O.close=()=>{M.set(!1)},O}0&&(module.exports={agentLoop});
|
|
@@ -64,7 +64,7 @@ type AgentLoopResult<TContext, TAction> = AgentLoopResultBase<TContext, TAction>
|
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```ts
|
|
67
|
-
* import { agentLoop } from 'callbag-recharge/
|
|
67
|
+
* import { agentLoop } from 'callbag-recharge/ai/agentLoop';
|
|
68
68
|
*
|
|
69
69
|
* const agent = agentLoop({
|
|
70
70
|
* observe: (ctx) => ({ ...ctx, data: 'observed' }),
|
|
@@ -94,7 +94,7 @@ type AgentLoopResult<TContext, TAction> = AgentLoopResultBase<TContext, TAction>
|
|
|
94
94
|
*
|
|
95
95
|
* @seeAlso [gate](/api/gate) — human-in-the-loop operator, [chatStream](/api/chatStream) — LLM streaming
|
|
96
96
|
*
|
|
97
|
-
* @category
|
|
97
|
+
* @category ai
|
|
98
98
|
*/
|
|
99
99
|
declare function agentLoop<TContext, TAction>(opts: AgentLoopOptions<TContext, TAction> & {
|
|
100
100
|
gate: true | Omit<GateOptions, "name">;
|
|
@@ -64,7 +64,7 @@ type AgentLoopResult<TContext, TAction> = AgentLoopResultBase<TContext, TAction>
|
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```ts
|
|
67
|
-
* import { agentLoop } from 'callbag-recharge/
|
|
67
|
+
* import { agentLoop } from 'callbag-recharge/ai/agentLoop';
|
|
68
68
|
*
|
|
69
69
|
* const agent = agentLoop({
|
|
70
70
|
* observe: (ctx) => ({ ...ctx, data: 'observed' }),
|
|
@@ -94,7 +94,7 @@ type AgentLoopResult<TContext, TAction> = AgentLoopResultBase<TContext, TAction>
|
|
|
94
94
|
*
|
|
95
95
|
* @seeAlso [gate](/api/gate) — human-in-the-loop operator, [chatStream](/api/chatStream) — LLM streaming
|
|
96
96
|
*
|
|
97
|
-
* @category
|
|
97
|
+
* @category ai
|
|
98
98
|
*/
|
|
99
99
|
declare function agentLoop<TContext, TAction>(opts: AgentLoopOptions<TContext, TAction> & {
|
|
100
100
|
gate: true | Omit<GateOptions, "name">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../../chunk-RC3JWVKF.js";import"../../chunk-4VPAGOLZ.js";import"../../chunk-4ILN4V4C.js";import"../../chunk-EAK2HKAD.js";import"../../chunk-2F6QWERG.js";import"../../chunk-2L6223KN.js";import"../../chunk-TUPD47IE.js";import"../../chunk-I7AUKTXE.js";export{a as agentLoop};
|
|
@@ -53,7 +53,7 @@ interface ChatStreamResult {
|
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
|
-
* import { chatStream } from 'callbag-recharge/
|
|
56
|
+
* import { chatStream } from 'callbag-recharge/ai/chatStream';
|
|
57
57
|
*
|
|
58
58
|
* const chat = chatStream(async function* (messages, signal) {
|
|
59
59
|
* const res = await fetch('/api/chat', {
|
|
@@ -76,7 +76,7 @@ interface ChatStreamResult {
|
|
|
76
76
|
* // chat.streaming.get() → true
|
|
77
77
|
* ```
|
|
78
78
|
*
|
|
79
|
-
* @category
|
|
79
|
+
* @category ai
|
|
80
80
|
*/
|
|
81
81
|
declare function chatStream(factory: ChatStreamFactory, opts?: ChatStreamOptions): ChatStreamResult;
|
|
82
82
|
|
|
@@ -53,7 +53,7 @@ interface ChatStreamResult {
|
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
|
-
* import { chatStream } from 'callbag-recharge/
|
|
56
|
+
* import { chatStream } from 'callbag-recharge/ai/chatStream';
|
|
57
57
|
*
|
|
58
58
|
* const chat = chatStream(async function* (messages, signal) {
|
|
59
59
|
* const res = await fetch('/api/chat', {
|
|
@@ -76,7 +76,7 @@ interface ChatStreamResult {
|
|
|
76
76
|
* // chat.streaming.get() → true
|
|
77
77
|
* ```
|
|
78
78
|
*
|
|
79
|
-
* @category
|
|
79
|
+
* @category ai
|
|
80
80
|
*/
|
|
81
81
|
declare function chatStream(factory: ChatStreamFactory, opts?: ChatStreamOptions): ChatStreamResult;
|
|
82
82
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../../chunk-WQAE4SFB.js";import"../../chunk-EAK2HKAD.js";import"../../chunk-2F6QWERG.js";import"../../chunk-2L6223KN.js";import"../../chunk-TUPD47IE.js";import"../../chunk-I7AUKTXE.js";export{a as chatStream};
|