@callbag-recharge/callbag-recharge 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/http.cjs +4 -4
- package/dist/adapters/http.js +1 -1
- package/dist/adapters/index.cjs +11 -11
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/llm.cjs +5 -5
- package/dist/adapters/llm.d.cts +6 -7
- package/dist/adapters/llm.d.ts +6 -7
- package/dist/adapters/llm.js +1 -1
- package/dist/adapters/mcp.cjs +4 -4
- package/dist/adapters/mcp.d.cts +3 -4
- package/dist/adapters/mcp.d.ts +3 -4
- package/dist/adapters/mcp.js +1 -1
- package/dist/adapters/webhook.cjs +4 -4
- package/dist/adapters/webhook.d.cts +40 -4
- package/dist/adapters/webhook.d.ts +40 -4
- package/dist/adapters/webhook.js +1 -1
- package/dist/adapters/websocket.cjs +4 -4
- package/dist/adapters/websocket.js +1 -1
- package/dist/{chunk-EEKTY7JA.js → chunk-27ALPEGS.js} +1 -1
- package/dist/chunk-CXF5XC6M.js +1 -0
- package/dist/chunk-DIXN33QZ.js +1 -0
- package/dist/{chunk-OHNEQFSD.js → chunk-G6E4ECVJ.js} +1 -1
- package/dist/chunk-HE2JY76U.js +1 -0
- package/dist/chunk-HIHLITY7.js +1 -0
- package/dist/chunk-KWTA2EOH.js +2 -0
- package/dist/chunk-PUJBUJ22.js +2 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/orchestrate/index.cjs +6 -4
- package/dist/orchestrate/index.d.cts +328 -2
- package/dist/orchestrate/index.d.ts +328 -2
- package/dist/orchestrate/index.js +3 -1
- package/dist/utils/index.cjs +2 -2
- package/dist/utils/index.d.cts +7 -3
- package/dist/utils/index.d.ts +7 -3
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-OGRJOWHP.js +0 -1
- package/dist/chunk-OI3FTHH3.js +0 -1
- package/dist/chunk-OXIEM5ZP.js +0 -2
- package/dist/chunk-RX5LWE4X.js +0 -1
- package/dist/chunk-W74KQTWL.js +0 -2
package/dist/adapters/http.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Q=Object.defineProperty;var
|
|
2
|
-
`)}static _observe(e,i,n){let s=null,r=i??t.getName(e),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>s?.(g)};return e.source(_,(u
|
|
3
|
-
`)}static toD2(e){let i=e?.direction??"down",n=t.snapshot(),s=[`direction: ${i}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},o=new Map;function
|
|
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 _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 U=1,T=64,S=2,$=4,gt=8,ht=16,I=32,v=1024,p=tt,A=rt<<x,L=ot<<x,G=it<<x,wt=ut<<x,Ot=lt<<x,It=at<<x,N=class{_value;_output=null;_flags;get _status(){return ct(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;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|=$),i?.resetOnTeardown&&(n|=gt),i?.resubscribable&&(n|=ht),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||O.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&T)for(let s of n)s(e,i);else n(e,i)}emit(e){this._flags&S||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(V()?this._flags&I||(this._flags|=I,this._flags&$&&(this._flags=this._flags&~p|A,this._dispatch(
|
|
1
|
+
"use strict";var Q=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var vt=Object.getOwnPropertyNames;var Et=Object.prototype.hasOwnProperty;var Dt=(t,e)=>{for(var i in e)Q(t,i,{get:e[i],enumerable:!0})},kt=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of vt(e))!Et.call(t,s)&&s!==i&&Q(t,s,{get:()=>e[s],enumerable:!(n=bt(e,s))||n.enumerable});return t};var xt=t=>kt(Q({},"__esModule",{value:!0}),t);var At={};Dt(At,{fromHTTP:()=>$t});module.exports=xt(At);var k=Symbol("DIRTY"),Y=Symbol("RESOLVED"),st=Symbol("SINGLE_DEP"),it=0,rt=1,ot=2,at=3,ut=4,lt=5,x=7,tt=7<<x,Rt=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ct(t){return Rt[(t&tt)>>>x]}var _=0,y=1,g=2,b=3,F=0,W=[],X=!1;function P(t){F++;try{return t()}finally{if(F--,F===0&&!X){X=!0;for(let e=0;e<W.length;e++)W[e]();W.length=0,X=!1}}}function V(){return F>0}function q(t){W.push(t)}var H=0,K=[];function dt(){H++}function ft(){if(H--,H===0){for(let t=0;t<K.length;t++)K[t]();K.length=0}}function pt(t){H>0?K.push(t):t()}var O=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 r=t._depSuffix(i?.deps);s=r?`${s}(${r})`:`${s}_${n}`,t._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let r=i?.kind??"store",o=t._depSuffix(i?.deps);s=o?`${r}(${o})`:`${r}_${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),r=t._edges.get(n);r?r.includes(s)||r.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 r=t._resolveKey(s);i.add(r),e.set(r,t.inspect(s))}for(let[n,s]of t._edges){if(!i.has(n)){t._edges.delete(n),t._usedKeys.delete(n);continue}let r=s.filter(o=>i.has(o));r.length===0?t._edges.delete(n):r.length!==s.length&&t._edges.set(n,r)}return e}static trace(e,i){let n=null,s=e.get();return e.source(_,(r,o)=>{if(r===_&&(n=o),r===g){n=null;return}if(r===1){let a=o;if(!Object.is(a,s)){let u=s;s=a,i(a,u)}}}),()=>n?.(g)}static dumpGraph(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let[o,a]of i)for(let u of a){let f=n.get(u);f?f.includes(o)||f.push(o):n.set(u,[o])}let s=[];for(let[o,a]of e){let u=n.get(o),f=i.get(o),c=u?.length?` \u2190 [${u.join(", ")}]`:"",l=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${o} (${a.kind}) = ${JSON.stringify(a.value)} [${a.status??"?"}]${c}${l}`)}return[`Store Graph (${e.size} nodes):`,...s].join(`
|
|
2
|
+
`)}static _observe(e,i,n){let s=null,r=i??t.getName(e),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>s?.(g)};return e.source(_,(a,u)=>{if(a===_){s=u;return}a===y?(o.values.push(u),o.events.push({type:"data",data:u}),n&&n(`[${r}] DATA:`,u)):a===b?(o.signals.push(u),o.events.push({type:"signal",data:u}),u===k?o.dirtyCount++:u===Y&&o.resolvedCount++,n&&n(`[${r}] STATE:`,u)):a===g&&(o.ended=!0,o.endError=u,o.events.push({type:"end",data:u}),n&&n(`[${r}] END`,u!==void 0?u:""),s=null)}),o}static observe(e){return t._observe(e)}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 o of t._stores){let a=o.deref();if(!a)continue;let u=t._annotations.get(a);u!==void 0&&n.set(t._resolveKey(a),u)}let s=[];for(let[o,a]of e){let u={name:o,kind:a.kind,value:a.value,status:a.status},f=n.get(o);f!==void 0&&(u.annotation=f),s.push(u)}let r=[];for(let[o,a]of i)for(let u of a)r.push({from:o,to:u});return{nodes:s,edges:r,trace:t.traceLog()}}static toMermaid(e){let i=e?.direction??"TD",n=t.snapshot(),s=[`graph ${i}`],r={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},o=new Map;function a(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),d=o.get(l);return d===void 0?(o.set(l,1),l):(o.set(l,d+1),`${l}__${d}`)}let u=new Map;function f(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of n.nodes){let l=a(c.name);u.set(c.name,l);let d=`${c.name} (${c.kind}) = ${f(c.value)}`,h=r[c.status??""]??"";s.push(` ${l}["${d}"]${h}`)}for(let c of n.edges){let l=u.get(c.from)??a(c.from),d=u.get(c.to)??a(c.to);s.push(` ${l} --> ${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}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},o=new Map;function a(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),d=o.get(l);return d===void 0?(o.set(l,1),l):(o.set(l,d+1),`${l}__${d}`)}let u=new Map;function f(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of n.nodes){let l=a(c.name);u.set(c.name,l);let d=r[c.kind]??"rectangle",h=`${c.name} (${c.kind}) = ${f(c.value)}`,E=c.status?` [${c.status}]`:"";s.push(`${l}: "${h}${E}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let c of n.edges){let l=u.get(c.from)??a(c.from),d=u.get(c.to)??a(c.to);s.push(`${l} -> ${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 _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 U=1,T=64,S=2,$=4,gt=8,ht=16,I=32,v=1024,p=tt,A=rt<<x,L=ot<<x,G=it<<x,wt=ut<<x,Ot=lt<<x,It=at<<x,N=class{_value;_output=null;_flags;get _status(){return ct(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;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|=$),i?.resetOnTeardown&&(n|=gt),i?.resubscribable&&(n|=ht),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||O.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&T)for(let s of n)s(e,i);else n(e,i)}emit(e){this._flags&S||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(V()?this._flags&I||(this._flags|=I,this._flags&$&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),q(()=>{this._flags&=~I,this._flags=this._flags&~p|L,this._dispatch(y,this._value)})):(this._flags&$&&!(this._flags&v)&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),this._flags=this._flags&~p|L,this._dispatch(y,this._value))))}signal(e){this._flags&S||!this._output||(e===k?this._flags=this._flags&~p|A:e===Y&&(this._flags=this._flags&~p|It),this._dispatch(b,e))}complete(){if(this._flags&S)return;this._flags=(this._flags|S)&~p|wt;let e=this._output,i=this._flags&T;if(this._output=null,this._flags&=~(T|v),this._singleDepCount=0,this._stop(),e)if(i)for(let n of e)n(g);else e(g)}error(e){if(this._flags&S)return;this._flags=(this._flags|S)&~p|Ot;let i=this._output,n=this._flags&T;if(this._output=null,this._flags&=~(T|v),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,e);else i(g,e)}_start(){if(this._flags&U||!this._fn)return;this._flags|=U;let e=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i)});this._cleanup=typeof e=="function"?e:void 0}_stop(){this._flags&U&&(this._flags&=~U,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags>&&(this._value=this._initial),this._flags&S||(this._flags=this._flags&~p|G))}source(e,i){if(e===_){let n=i;if(this._flags&S)if(this._flags&ht&&this._output===null)this._flags=this._flags&~(S|p)|G;else{n(_,r=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&T)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|T)&~v}let s=!1;n(_,(r,o)=>{if(r===y&&n(y,this._value),r===b&&o===st&&!s&&(s=!0,this._singleDepCount++,this._flags&T||(this._flags|=v)),r===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&T){let a=this._output;a.delete(n),a.size===1?(this._output=a.values().next().value,this._flags&=~T,this._singleDepCount>0&&(this._flags|=v)):a.size===0&&(this._output=null,this._flags&=~(T|v),this._singleDepCount=0,this._flags=this._flags&~p|G,this._stop())}else this._output===n&&(this._output=null,this._flags&=~v,this._singleDepCount=0,this._flags=this._flags&~p|G,this._stop())}}),pt(()=>this._start())}}};function z(t,e){return new N(t,e)}var et=class extends N{constructor(e,i){super(void 0,{initial:e,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),O.register(this,{kind:"state",...i})}get(){return this._value}set(e){this._flags&S||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(V()?this._flags&I||(this._flags|=I,this._flags&$&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),q(()=>{this._flags&=~I,this._flags=this._flags&~p|L,this._dispatch(y,this._value)})):(this._flags&$&&!(this._flags&v)&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),this._flags=this._flags&~p|L,this._dispatch(y,this._value))))}update(e){this.set(e(this._value))}};function C(t,e){return new et(t,e)}function _t(t,e,i){let n=null;dt(),t.source(_,(r,o)=>{if(r===_&&(n=o),r===g){n=null,i?.onEnd?.(o);return}if(r===1){let a=o,u=s;s=a,e(a,u)}});let s;try{s=t.get()}catch{}return ft(),()=>n?.(g)}function Tt(t,e){let i=e?.initialStatus??"pending",n=C(i,{name:"withStatus:status",equals:Object.is}),s=C(void 0,{name:"withStatus:error",equals:Object.is}),r=z(({emit:a,complete:u,error:f})=>{n.set(i),s.set(void 0);let c=_t(t,l=>{n.get()==="errored"?P(()=>{s.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));P(()=>{s.set(d),n.set("errored")}),f(l)}else n.set("completed"),u()}});return()=>{c()}},{initial:t.get(),resubscribable:!0}),o={get:()=>t.get(),source:(a,u)=>r.source(a,u),get _status(){return r._status},status:n,error:s};return O.register(o,{kind:"withStatus"}),o}function $t(t,e){let i=e?.name??"http",n=e?.method??"GET",s=e?.headers,r=e?.body,o=e?.poll??0,a=e?.transform??(R=>R.json()),u=e?.timeout??3e4,f=C(0,{name:`${i}:fetchCount`}),c=null,l=null,d=null,h=null,E=null,m=!1;async function B(){if(!m||!c)return;E=new AbortController;let R=[E.signal];e?.signal&&R.push(e.signal);let w=new AbortController;for(let D of R){if(D.aborted){w.abort(D.reason);break}D.addEventListener("abort",()=>w.abort(D.reason),{once:!0})}let Z=setTimeout(()=>w.abort(new Error("Request timeout")),u);try{let D=r!==void 0?typeof r=="string"?r:JSON.stringify(r):void 0,j=await fetch(t,{method:n,headers:s,body:D,signal:w.signal});if(!m)return;if(!j.ok)throw new Error(`HTTP ${j.status}: ${j.statusText}`);let mt=await a(j);if(!m)return;P(()=>{f.update(yt=>yt+1),c?.(mt)})}catch(D){if(!m||D?.name==="AbortError")return;l?.(D)}finally{clearTimeout(Z),E=null}}function nt(){!m||o<=0||(h=setTimeout(()=>{h=null,B().then(()=>{m&&nt()}).catch(()=>{})},o))}let J=null,St=z(({emit:R,error:w,complete:Z})=>(c=R,l=w,d=Z,m=!0,J=()=>{B()},B().then(()=>{m&&nt()}),()=>{m=!1,c=null,l=null,d=null,J=null,E?.abort(),E=null,h!==null&&(clearTimeout(h),h=null)}),{name:i,kind:"http"}),M=Tt(St);return{get:()=>M.get(),source:(R,w)=>M.source(R,w),status:M.status,error:M.error,fetchCount:f,refetch(){J?.()},stop(){m=!1,E?.abort(),E=null,h!==null&&(clearTimeout(h),h=null),d?.()}}}0&&(module.exports={fromHTTP});
|
package/dist/adapters/http.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-27ALPEGS.js";import"../chunk-HE2JY76U.js";import"../chunk-YJXCVG35.js";import"../chunk-P5MXN4AF.js";import"../chunk-YN4VWXAF.js";import"../chunk-M76W372U.js";import"../chunk-CWP55MPE.js";import"../chunk-I7AUKTXE.js";export{a as fromHTTP};
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";var Ae=Object.create;var
|
|
2
|
-
`)}static _observe(t,n,r){let o=null,
|
|
3
|
-
`)}static toD2(t){let n=t?.direction??"down",r=e.snapshot(),o=[`direction: ${n}`,""],
|
|
4
|
-
`)}static annotate(t,n){if(!e.enabled)return;e._annotations.set(t,n);let r={node:e._resolveKey(t),reason:n,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(r):(e._traceLog[e._traceHead]=r,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var
|
|
5
|
-
`);
|
|
6
|
-
`),
|
|
1
|
+
"use strict";var Ae=Object.create;var Z=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var We=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty;var Ne=(e,t)=>{for(var n in t)Z(e,n,{get:t[n],enumerable:!0})},de=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $e(t))!Ie.call(e,o)&&o!==n&&Z(e,o,{get:()=>t[o],enumerable:!(r=Me(t,o))||r.enumerable});return e};var je=(e,t,n)=>(n=e!=null?Ae(We(e)):{},de(t||!e||!e.__esModule?Z(n,"default",{value:e,enumerable:!0}):n,e)),He=e=>de(Z({},"__esModule",{value:!0}),e);var Ze={};Ne(Ze,{fromHTTP:()=>xe,fromLLM:()=>Re,fromMCP:()=>De,fromWebSocket:()=>Oe,fromWebhook:()=>Pe,toSSE:()=>Ce,toWebSocket:()=>Le});module.exports=He(Ze);var j=Symbol("DIRTY"),re=Symbol("RESOLVED"),pe=Symbol("SINGLE_DEP"),ge=0,me=1,he=2,Se=3,Te=4,be=5,H=7,ce=7<<H,Fe=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ye(e){return Fe[(e&ce)>>>H]}var L=0,W=1,D=2,I=3,X=0,ee=[],ue=!1;function C(e){X++;try{return e()}finally{if(X--,X===0&&!ue){ue=!0;for(let t=0;t<ee.length;t++)ee[t]();ee.length=0,ue=!1}}}function oe(){return X>0}function se(e){ee.push(e)}var ne=0,te=[];function _e(){ne++}function ke(){if(ne--,ne===0){for(let e=0;e<te.length;e++)te[e]();te.length=0}}function ve(e){ne>0?te.push(e):e()}var P=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let r=t.map(o=>e._names.get(o)??"?").join(",");return r.length>40?`${r.slice(0,37)}...`:r}static _resolveKey(t){let n=e._keys.get(t)??e._names.get(t);if(n)return n;let r=`anonymous_${e._nextId++}`;return e._keys.set(t,r),r}static register(t,n){if(!e.enabled)return;n?.name&&e._names.set(t,n.name),n?.kind&&e._kinds.set(t,n.kind);let r=e._nextId++,o=n?.name;if(!(o&&!e._usedKeys.has(o)))if(o){let c=e._depSuffix(n?.deps);o=c?`${o}(${c})`:`${o}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}else{let c=n?.kind??"store",s=e._depSuffix(n?.deps);o=s?`${c}(${s})`:`${c}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}e._usedKeys.add(o),e._keys.set(t,o),e._stores.add(new WeakRef(t))}static registerEdge(t,n){if(!e.enabled)return;let r=e._resolveKey(t),o=e._resolveKey(n),c=e._edges.get(r);c?c.includes(o)||c.push(o):e._edges.set(r,[o])}static getEdges(){return new Map(e._edges)}static getName(t){if(e.enabled)return e._names.get(t)}static getKind(t){return e._kinds.get(t)}static inspect(t){return{name:e._names.get(t),kind:e._kinds.get(t)??"unknown",value:typeof t.get=="function"?t.get():void 0,status:t._status}}static graph(){let t=new Map,n=new Set;for(let r of e._stores){let o=r.deref();if(!o){e._stores.delete(r);continue}let c=e._resolveKey(o);n.add(c),t.set(c,e.inspect(o))}for(let[r,o]of e._edges){if(!n.has(r)){e._edges.delete(r),e._usedKeys.delete(r);continue}let c=o.filter(s=>n.has(s));c.length===0?e._edges.delete(r):c.length!==o.length&&e._edges.set(r,c)}return t}static trace(t,n){let r=null,o=t.get();return t.source(L,(c,s)=>{if(c===L&&(r=s),c===D){r=null;return}if(c===1){let i=s;if(!Object.is(i,o)){let l=o;o=i,n(i,l)}}}),()=>r?.(D)}static dumpGraph(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let[s,i]of n)for(let l of i){let f=r.get(l);f?f.includes(s)||f.push(s):r.set(l,[s])}let o=[];for(let[s,i]of t){let l=r.get(s),f=n.get(s),u=l?.length?` \u2190 [${l.join(", ")}]`:"",a=f?.length?` \u2192 [${f.join(", ")}]`:"";o.push(` ${s} (${i.kind}) = ${JSON.stringify(i.value)} [${i.status??"?"}]${u}${a}`)}return[`Store Graph (${t.size} nodes):`,...o].join(`
|
|
2
|
+
`)}static _observe(t,n,r){let o=null,c=n??e.getName(t),s={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:c,dispose:()=>o?.(D)};return t.source(L,(i,l)=>{if(i===L){o=l;return}i===W?(s.values.push(l),s.events.push({type:"data",data:l}),r&&r(`[${c}] DATA:`,l)):i===I?(s.signals.push(l),s.events.push({type:"signal",data:l}),l===j?s.dirtyCount++:l===re&&s.resolvedCount++,r&&r(`[${c}] STATE:`,l)):i===D&&(s.ended=!0,s.endError=l,s.events.push({type:"end",data:l}),r&&r(`[${c}] END`,l!==void 0?l:""),o=null)}),s}static observe(t){return e._observe(t)}static tap(t,n){let r=n??`tap(${e.getName(t)??"anon"})`,o={get:()=>t.get(),source:t.source};return e.register(o,{name:r,kind:"tap"}),e.registerEdge(t,o),o}static spy(t,n){let r=n?.name??e.getName(t)??"spy",o=n?.log??console.log;return e._observe(t,r,o)}static snapshot(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let s of e._stores){let i=s.deref();if(!i)continue;let l=e._annotations.get(i);l!==void 0&&r.set(e._resolveKey(i),l)}let o=[];for(let[s,i]of t){let l={name:s,kind:i.kind,value:i.value,status:i.status},f=r.get(s);f!==void 0&&(l.annotation=f),o.push(l)}let c=[];for(let[s,i]of n)for(let l of i)c.push({from:s,to:l});return{nodes:o,edges:c,trace:e.traceLog()}}static toMermaid(t){let n=t?.direction??"TD",r=e.snapshot(),o=[`graph ${n}`],c={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},s=new Map;function i(u){let a=u.replace(/[^a-zA-Z0-9_]/g,"_"),p=s.get(a);return p===void 0?(s.set(a,1),a):(s.set(a,p+1),`${a}__${p}`)}let l=new Map;function f(u){let a=JSON.stringify(u);return a&&a.length>30?`${a.slice(0,27)}...`:a??"undefined"}for(let u of r.nodes){let a=i(u.name);l.set(u.name,a);let p=`${u.name} (${u.kind}) = ${f(u.value)}`,y=c[u.status??""]??"";o.push(` ${a}["${p}"]${y}`)}for(let u of r.edges){let a=l.get(u.from)??i(u.from),p=l.get(u.to)??i(u.to);o.push(` ${a} --> ${p}`)}return o.push(""),o.push(" classDef settled fill:#d4edda,stroke:#28a745"),o.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),o.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),o.push(" classDef completed fill:#cce5ff,stroke:#007bff"),o.join(`
|
|
3
|
+
`)}static toD2(t){let n=t?.direction??"down",r=e.snapshot(),o=[`direction: ${n}`,""],c={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},s=new Map;function i(u){let a=u.replace(/[^a-zA-Z0-9_]/g,"_"),p=s.get(a);return p===void 0?(s.set(a,1),a):(s.set(a,p+1),`${a}__${p}`)}let l=new Map;function f(u){let a=JSON.stringify(u);return a&&a.length>30?`${a.slice(0,27)}...`:a??"undefined"}for(let u of r.nodes){let a=i(u.name);l.set(u.name,a);let p=c[u.kind]??"rectangle",y=`${u.name} (${u.kind}) = ${f(u.value)}`,_=u.status?` [${u.status}]`:"";o.push(`${a}: "${y}${_}" { shape: ${p} }`)}r.edges.length>0&&o.push("");for(let u of r.edges){let a=l.get(u.from)??i(u.from),p=l.get(u.to)??i(u.to);o.push(`${a} -> ${p}`)}return o.join(`
|
|
4
|
+
`)}static annotate(t,n){if(!e.enabled)return;e._annotations.set(t,n);let r={node:e._resolveKey(t),reason:n,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(r):(e._traceLog[e._traceHead]=r,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var ie=1,M=64,$=2,K=4,we=8,Ee=16,q=32,N=1024,x=ce,U=me<<H,Y=he<<H,ae=ge<<H,qe=Te<<H,Be=be<<H,Ke=Se<<H,G=class{_value;_output=null;_flags;get _status(){return ye(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;constructor(t,n){this._value=n?.initial,this._fn=t,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let r=0;n?.autoDirty!==!1&&(r|=K),n?.resetOnTeardown&&(r|=we),n?.resubscribable&&(r|=Ee),this._flags=r,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||P.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,n){let r=this._output;if(r)if(this._flags&M)for(let o of r)o(t,n);else r(t,n)}emit(t){this._flags&$||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(oe()?this._flags&q||(this._flags|=q,this._flags&K&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),se(()=>{this._flags&=~q,this._flags=this._flags&~x|Y,this._dispatch(W,this._value)})):(this._flags&K&&!(this._flags&N)&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),this._flags=this._flags&~x|Y,this._dispatch(W,this._value))))}signal(t){this._flags&$||!this._output||(t===j?this._flags=this._flags&~x|U:t===re&&(this._flags=this._flags&~x|Ke),this._dispatch(I,t))}complete(){if(this._flags&$)return;this._flags=(this._flags|$)&~x|qe;let t=this._output,n=this._flags&M;if(this._output=null,this._flags&=~(M|N),this._singleDepCount=0,this._stop(),t)if(n)for(let r of t)r(D);else t(D)}error(t){if(this._flags&$)return;this._flags=(this._flags|$)&~x|Be;let n=this._output,r=this._flags&M;if(this._output=null,this._flags&=~(M|N),this._singleDepCount=0,this._stop(),n)if(r)for(let o of n)o(D,t);else n(D,t)}_start(){if(this._flags&ie||!this._fn)return;this._flags|=ie;let t=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n)});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ie&&(this._flags&=~ie,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&we&&(this._value=this._initial),this._flags&$||(this._flags=this._flags&~x|ae))}source(t,n){if(t===L){let r=n;if(this._flags&$)if(this._flags&Ee&&this._output===null)this._flags=this._flags&~($|x)|ae;else{r(L,c=>{}),r(D);return}if(this._output===null)this._output=r;else if(this._flags&M)this._output.add(r);else{let c=new Set;c.add(this._output),c.add(r),this._output=c,this._flags=(this._flags|M)&~N}let o=!1;r(L,(c,s)=>{if(c===W&&r(W,this._value),c===I&&s===pe&&!o&&(o=!0,this._singleDepCount++,this._flags&M||(this._flags|=N)),c===D){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&M){let i=this._output;i.delete(r),i.size===1?(this._output=i.values().next().value,this._flags&=~M,this._singleDepCount>0&&(this._flags|=N)):i.size===0&&(this._output=null,this._flags&=~(M|N),this._singleDepCount=0,this._flags=this._flags&~x|ae,this._stop())}else this._output===r&&(this._output=null,this._flags&=~N,this._singleDepCount=0,this._flags=this._flags&~x|ae,this._stop())}}),ve(()=>this._start())}}};function F(e,t){return new G(e,t)}var le=class extends G{constructor(t,n){super(void 0,{initial:t,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),P.register(this,{kind:"state",...n})}get(){return this._value}set(t){this._flags&$||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(oe()?this._flags&q||(this._flags|=q,this._flags&K&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),se(()=>{this._flags&=~q,this._flags=this._flags&~x|Y,this._dispatch(W,this._value)})):(this._flags&K&&!(this._flags&N)&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),this._flags=this._flags&~x|Y,this._dispatch(W,this._value))))}update(t){this.set(t(this._value))}};function v(e,t){return new le(e,t)}function z(e,t,n){let r=null;_e(),e.source(L,(c,s)=>{if(c===L&&(r=s),c===D){r=null,n?.onEnd?.(s);return}if(c===1){let i=s,l=o;o=i,t(i,l)}});let o;try{o=e.get()}catch{}return ke(),()=>r?.(D)}function V(e,t){let n=t?.initialStatus??"pending",r=v(n,{name:"withStatus:status",equals:Object.is}),o=v(void 0,{name:"withStatus:error",equals:Object.is}),c=F(({emit:i,complete:l,error:f})=>{r.set(n),o.set(void 0);let u=z(e,a=>{r.get()==="errored"?C(()=>{o.set(void 0),r.set("active")}):r.set("active"),i(a)},{onEnd:a=>{if(a!==void 0){let p=a instanceof Error?a:new Error(String(a));C(()=>{o.set(p),r.set("errored")}),f(a)}else r.set("completed"),l()}});return()=>{u()}},{initial:e.get(),resubscribable:!0}),s={get:()=>e.get(),source:(i,l)=>c.source(i,l),get _status(){return c._status},status:r,error:o};return P.register(s,{kind:"withStatus"}),s}function xe(e,t){let n=t?.name??"http",r=t?.method??"GET",o=t?.headers,c=t?.body,s=t?.poll??0,i=t?.transform??(k=>k.json()),l=t?.timeout??3e4,f=v(0,{name:`${n}:fetchCount`}),u=null,a=null,p=null,y=null,_=null,h=!1;async function T(){if(!h||!u)return;_=new AbortController;let k=[_.signal];t?.signal&&k.push(t.signal);let E=new AbortController;for(let b of k){if(b.aborted){E.abort(b.reason);break}b.addEventListener("abort",()=>E.abort(b.reason),{once:!0})}let w=setTimeout(()=>E.abort(new Error("Request timeout")),l);try{let b=c!==void 0?typeof c=="string"?c:JSON.stringify(c):void 0,A=await fetch(e,{method:r,headers:o,body:b,signal:E.signal});if(!h)return;if(!A.ok)throw new Error(`HTTP ${A.status}: ${A.statusText}`);let O=await i(A);if(!h)return;C(()=>{f.update(R=>R+1),u?.(O)})}catch(b){if(!h||b?.name==="AbortError")return;a?.(b)}finally{clearTimeout(w),_=null}}function m(){!h||s<=0||(y=setTimeout(()=>{y=null,T().then(()=>{h&&m()}).catch(()=>{})},s))}let g=null,d=F(({emit:k,error:E,complete:w})=>(u=k,a=E,p=w,h=!0,g=()=>{T()},T().then(()=>{h&&m()}),()=>{h=!1,u=null,a=null,p=null,g=null,_?.abort(),_=null,y!==null&&(clearTimeout(y),y=null)}),{name:n,kind:"http"}),S=V(d);return{get:()=>S.get(),source:(k,E)=>S.source(k,E),status:S.status,error:S.error,fetchCount:f,refetch(){g?.()},stop(){h=!1,_?.abort(),_=null,y!==null&&(clearTimeout(y),y=null),p?.()}}}function Ue(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function ze(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function Ve(e,t,n,r){let o={model:t,messages:n,stream:!0};return r?.temperature!==void 0&&(o.temperature=r.temperature),r?.maxTokens!==void 0&&(e==="ollama"?o.options={num_predict:r.maxTokens}:o.max_tokens=r.maxTokens),r?.stop&&(o.stop=r.stop),o}function Ye(e,t){let n={"Content-Type":"application/json"};return t&&(n.Authorization=`Bearer ${t}`),n}function Re(e){let t=e.name??"llm",n=e.provider,r=e.baseURL??Ue(n),o=e.model??"",c=e.fetch??globalThis.fetch,s=v("",{name:`${t}.store`}),i=v({},{name:`${t}.tokens`}),l=v("pending",{name:`${t}.status`}),f=v(void 0,{name:`${t}.error`}),u=null;function a(){u&&(u.abort(),u=null),l.get()==="active"&&C(()=>{s.set(""),l.set("pending")})}function p(_,h){a(),u=new AbortController;let T=h?.signal?Qe(u.signal,h.signal):u.signal;C(()=>{s.set(""),i.set({}),f.set(void 0),l.set("active")});let m=ze(n,r),g=Ve(n,o,_,h),d=Ye(n,e.apiKey);y(m,d,g,T).catch(()=>{})}async function y(_,h,T,m){try{let g=await c(_,{method:"POST",headers:h,body:JSON.stringify(T),signal:m});if(!g.ok){let w=await g.text().catch(()=>"");throw new Error(`LLM API error ${g.status}: ${w}`)}let d=g.body?.getReader();if(!d)throw new Error("No response body");let S=new TextDecoder,k="",E="";for(;;){if(m.aborted)return;let{done:w,value:b}=await d.read();if(w)break;E+=S.decode(b,{stream:!0});let A=E.split(`
|
|
5
|
+
`);E=A.pop()??"";for(let O of A){if(m.aborted)return;let R=O.trim();if(!R||R.startsWith(":")||!R.startsWith("data: "))continue;let J=R.slice(6);if(J!=="[DONE]")try{let B=JSON.parse(J),Q=Ge(n,B);Q&&(k+=Q,s.set(k));let fe=Je(n,B);fe&&i.set(fe)}catch{}}}if(S.decode(),m.aborted)return;l.set("completed"),u=null}catch(g){if(m.aborted)return;C(()=>{f.set(g),l.set("errored")}),u=null}finally{m._cleanup?.()}}return{get:()=>s.get(),source:(_,h)=>s.source(_,h),tokens:i,status:l,error:f,generate:p,abort:a}}function Ge(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function Je(e,t){let n=e==="ollama"?t:t?.usage;if(n){if(e==="ollama")return t.eval_count!==void 0||t.prompt_eval_count!==void 0?{promptTokens:t.prompt_eval_count,completionTokens:t.eval_count,totalTokens:(t.prompt_eval_count??0)+(t.eval_count??0)}:void 0;if(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function Qe(e,t){let n=new AbortController,r=()=>{e.removeEventListener("abort",o),t.removeEventListener("abort",o)},o=()=>{n.abort(),r()};e.addEventListener("abort",o,{once:!0}),t.addEventListener("abort",o,{once:!0});let c=n.signal;return c._cleanup=r,c}function De(e){let t=e.name??"mcp",n=e.client,r=v([],{name:`${t}.tools`}),o=v([],{name:`${t}.resources`}),c=v(void 0,{name:`${t}.refreshError`});function s(f){c.set(f);let u=e.onRefreshError;if(u==="warn")console.warn(`[${t}] refresh error:`,f);else{if(u==="error")throw f;typeof u=="function"&&u(f)}}async function i(){if(c.set(void 0),n.listTools)try{let f=await n.listTools();r.set(f.tools)}catch(f){s(f)}if(n.listResources)try{let f=await n.listResources();o.set(f.resources)}catch(f){s(f)}}function l(f){let u=`${t}:${f}`,a=v(void 0,{name:`${u}.result`}),p=v("idle",{name:`${u}.status`}),y=v(void 0,{name:`${u}.error`}),_=v(void 0,{name:`${u}.lastArgs`}),h=v(void 0,{name:`${u}.duration`}),T=!1;async function m(g){if(T)return;T=!0,C(()=>{_.set(g),y.set(void 0),p.set("active")});let d=Date.now();try{let S=await n.callTool({name:f,arguments:g}),k=Date.now()-d;if(S.isError){let b=S.content.filter(O=>O.type==="text").map(O=>O.text??"").join(`
|
|
6
|
+
`),A=new Error(b||"MCP tool returned error");C(()=>{h.set(k),y.set(A),p.set("errored")});return}let E=S.content.filter(b=>b.type==="text"),w;if(E.length===1){let b=E[0].text;if(b!==void 0)try{w=JSON.parse(b)}catch{w=b}}else E.length>1?w=E.map(b=>b.text??""):w=S.content;C(()=>{h.set(k),a.set(w),p.set("completed")})}catch(S){let k=Date.now()-d;C(()=>{h.set(k),y.set(S),p.set("errored")})}finally{T=!1}}return{get:()=>a.get(),source:(g,d)=>a.source(g,d),status:p,error:y,call:m,lastArgs:_,duration:h}}return{tool:l,tools:r,resources:o,refresh:i,refreshError:c}}function Ce(e,t){let n=t?.path??"/",r=t?.name??"sse",o=t?.hostname??"0.0.0.0",c=t?.serialize??JSON.stringify,s=t?.eventName??"message",i=t?.pingInterval??3e4,l=v(0,{name:`${r}:connections`}),f=new Set,u=new Map,a=null;function p(){a||(a=z(e,g=>{let d=c(g),S=`event: ${s}
|
|
7
7
|
data: ${d}
|
|
8
8
|
|
|
9
|
-
`;for(let
|
|
9
|
+
`;for(let k of f)try{k.write(S)}catch{y(k)}}))}function y(g){f.delete(g);let d=u.get(g);d&&(clearInterval(d),u.delete(g)),l.set(f.size),f.size===0&&a&&(a(),a=null)}function _(g,d){let S=g.method?.toUpperCase();if((g.url??"/").split("?")[0]!==n){d.writeHead(404,{"Content-Type":"text/plain"}),d.end("Not found");return}if(S==="OPTIONS"){d.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),d.end();return}if(S!=="GET"){d.writeHead(405,{"Content-Type":"text/plain"}),d.end("Method not allowed");return}d.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),d.write(`:ok
|
|
10
10
|
|
|
11
|
-
`),f.add(d),
|
|
12
|
-
data: ${
|
|
11
|
+
`),f.add(d),l.set(f.size);try{let w=e.get();if(w!==void 0){let b=c(w);d.write(`event: ${s}
|
|
12
|
+
data: ${b}
|
|
13
13
|
|
|
14
|
-
`)}}catch{}if(i>0){let
|
|
14
|
+
`)}}catch{}if(i>0){let w=setInterval(()=>{try{d.write(`:ping
|
|
15
15
|
|
|
16
|
-
`)}catch{
|
|
16
|
+
`)}catch{y(d)}},i);u.set(d,w)}g.on("close",()=>y(d)),p()}let h=null;async function T(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(h)throw new Error("toSSE: already listening. Call close() first.");let g=await import("http");return new Promise((d,S)=>{h=g.createServer(_),h.once("listening",()=>d()),h.once("error",k=>{h=null,S(k)}),h.listen(t.port,o)})}function m(){for(let g of f)try{g.end()}catch{}f.clear();for(let g of u.values())clearInterval(g);u.clear(),l.set(0),a?.(),a=null,h?.close(),h=null}return P.register(l,{kind:"sse"}),{connectionCount:l,handler:_,listen:T,close:m}}function Pe(e){let t=e?.path??"/",n=e?.parse??JSON.parse,r=e?.name??"webhook",o=e?.hostname??"0.0.0.0",c=e?.maxBodySize??1024*1024,s=e?.responseTimeout??3e4,i=v(0,{name:`${r}:count`}),l=null,f=F(({emit:T})=>(l=T,()=>{l=null}),{name:r,kind:"webhook"});P.register(f,{kind:"webhook"});let u=V(f),a=null,p=new Set;function y(T,m){let g=T.method?.toUpperCase(),S=(T.url??"/").split("?")[0];if(g!=="POST"||S!==t){m.writeHead(404,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Not found"}));return}let k=[],E=0,w=!1;T.on("error",()=>{w=!0,m.headersSent||(m.writeHead(400,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Request aborted"})))}),T.on("data",b=>{if(!w){if(E+=b.length,E>c){w=!0,m.writeHead(413,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Payload too large"})),T.destroy?.();return}k.push(b)}}),T.on("end",()=>{if(!w)try{let b=Buffer.concat(k).toString("utf-8"),A=b.length>0?n(b):void 0;i.update(B=>B+1);let O=!1,R=null,J={body:A,get responded(){return O},respond(B,Q=200){O||(O=!0,R!==null&&(clearTimeout(R),p.delete(R),R=null),m.writeHead(Q,{"Content-Type":"application/json"}),m.end(JSON.stringify(B)))}};R=setTimeout(()=>{p.delete(R),R=null,O||(O=!0,m.writeHead(504,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Response timeout"})))},s),p.add(R),l?.(J)}catch(b){m.writeHead(400,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:b?.message??"Parse error"}))}})}function _(){return e?.port?a?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):new Promise((T,m)=>{try{a=require("http").createServer(y),a.once("listening",()=>T()),a.once("error",d=>{a=null,m(d)}),a.listen(e.port,o)}catch(g){m(g)}}):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function h(){for(let T of p)clearTimeout(T);p.clear(),a?.close(),a=null}return{get:()=>u.get(),source:(T,m)=>u.source(T,m),status:u.status,error:u.error,requestCount:i,handler:y,listen:_,close:h}}function Oe(e,t){let n=t?.name??"websocket",r=t?.parse??(d=>d),o=t?.reconnect??!1,c=t?.onParseError??"warn",s=v("connecting",{name:`${n}:connectionState`,equals:()=>!1}),i=null,l=null,f=null,u=null,a=null,p=!1,y=null,_=[];function h(){for(;_.length>0&&i?.readyState===WebSocket.OPEN;)i.send(_.shift())}function T(){p=!1,s.set("connecting");try{i=new WebSocket(e,t?.protocols)}catch(d){s.set("closed"),f?.(d);return}i.onopen=()=>{s.set("open"),h()},i.onmessage=d=>{try{let S=r(d.data);l?.(S)}catch(S){c==="error"?f?.(S):c==="warn"&&console.warn(`[${n}] parse error:`,S)}},i.onerror=()=>{y=new Error(`WebSocket error on ${e}`)},i.onclose=()=>{s.set("closed"),i=null;let d=y;y=null,!p&&o!==!1?a=setTimeout(()=>{a=null,l&&T()},o):d&&!p?f?.(d):u?.()}}let m=F(({emit:d,error:S,complete:k})=>(l=d,f=S,u=k,T(),()=>{l=null,f=null,u=null,p=!0,_.length=0,a!==null&&(clearTimeout(a),a=null),i&&(i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(),i=null),s.set("closed")}),{name:n,kind:"websocket"});P.register(m,{kind:"websocket"});let g=V(m);return{get:()=>g.get(),source:(d,S)=>g.source(d,S),status:g.status,error:g.error,connectionState:s,send(d){i?.readyState===WebSocket.OPEN?i.send(d):_.push(d)},close(d,S){p=!0,_.length=0,a!==null&&(clearTimeout(a),a=null),i?.close(d,S)}}}function Le(e,t,n){let r=s=>typeof s=="string"?s:JSON.stringify(s),o=n?.serialize??r,c="send"in e&&typeof e.send=="function"?e.send.bind(e):null;if(!c)throw new Error("toWebSocket: invalid WebSocket target");return z(t,s=>{try{let i=o(s);c(i)}catch{}})}0&&(module.exports={fromHTTP,fromLLM,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
|
|
@@ -2,7 +2,7 @@ export { FromHTTPOptions, HTTPStore, fromHTTP } from './http.cjs';
|
|
|
2
2
|
export { GenerateOptions, LLMMessage, LLMOptions, LLMStore, LLMTokenUsage, fromLLM } from './llm.cjs';
|
|
3
3
|
export { MCPClientLike, MCPOptions, MCPResource, MCPResult, MCPToolInfo, MCPToolStore, fromMCP } from './mcp.cjs';
|
|
4
4
|
export { SSEOptions, SSEStore, toSSE } from './sse.cjs';
|
|
5
|
-
export { WebhookOptions, WebhookStore, fromWebhook } from './webhook.cjs';
|
|
5
|
+
export { WebhookOptions, WebhookRequest, WebhookStore, fromWebhook } from './webhook.cjs';
|
|
6
6
|
export { FromWebSocketOptions, ToWebSocketOptions, WebSocketConnectionState, WebSocketStore, fromWebSocket, toWebSocket } from './websocket.cjs';
|
|
7
7
|
import '../types-BwU0Zcuz.cjs';
|
|
8
8
|
import '../protocol-BVxRx57r.cjs';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { FromHTTPOptions, HTTPStore, fromHTTP } from './http.js';
|
|
|
2
2
|
export { GenerateOptions, LLMMessage, LLMOptions, LLMStore, LLMTokenUsage, fromLLM } from './llm.js';
|
|
3
3
|
export { MCPClientLike, MCPOptions, MCPResource, MCPResult, MCPToolInfo, MCPToolStore, fromMCP } from './mcp.js';
|
|
4
4
|
export { SSEOptions, SSEStore, toSSE } from './sse.js';
|
|
5
|
-
export { WebhookOptions, WebhookStore, fromWebhook } from './webhook.js';
|
|
5
|
+
export { WebhookOptions, WebhookRequest, WebhookStore, fromWebhook } from './webhook.js';
|
|
6
6
|
export { FromWebSocketOptions, ToWebSocketOptions, WebSocketConnectionState, WebSocketStore, fromWebSocket, toWebSocket } from './websocket.js';
|
|
7
7
|
import '../types-DGII6w5S.js';
|
|
8
8
|
import '../protocol-BVxRx57r.js';
|
package/dist/adapters/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"../chunk-
|
|
1
|
+
import{a as o}from"../chunk-27ALPEGS.js";import{a as e}from"../chunk-KWTA2EOH.js";import{a as t}from"../chunk-PUJBUJ22.js";import{a as r}from"../chunk-X6RLUCXO.js";import{a as p}from"../chunk-HIHLITY7.js";import{a as m,b as S}from"../chunk-G6E4ECVJ.js";import"../chunk-HE2JY76U.js";import"../chunk-YJXCVG35.js";import"../chunk-P5MXN4AF.js";import"../chunk-YN4VWXAF.js";import"../chunk-M76W372U.js";import"../chunk-CWP55MPE.js";import"../chunk-I7AUKTXE.js";export{o as fromHTTP,e as fromLLM,t as fromMCP,m as fromWebSocket,p as fromWebhook,r as toSSE,S as toWebSocket};
|
package/dist/adapters/llm.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}static _observe(e,n,s){let i=null,
|
|
3
|
-
`)}static toD2(e){let n=e?.direction??"down",s=t.snapshot(),i=[`direction: ${n}`,""],
|
|
4
|
-
`)}static annotate(e,n){if(!t.enabled)return;t._annotations.set(e,n);let s={node:t._resolveKey(e),reason:n,timestamp:Date.now()},i=t.maxTraceEntries;i<=0||(t._traceLog.length<i?t._traceLog.push(s):(t._traceLog[t._traceHead]=s,t._traceFull=!0),t._traceHead=(t._traceHead+1)%i)}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 _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
|
|
5
|
-
`);
|
|
1
|
+
"use strict";var z=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var yt=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},bt=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of St(e))!vt.call(t,i)&&i!==n&&z(t,i,{get:()=>e[i],enumerable:!(s=mt(e,i))||s.enumerable});return t};var Et=t=>bt(z({},"__esModule",{value:!0}),t);var jt={};yt(jt,{fromLLM:()=>At});module.exports=Et(jt);var v=Symbol("DIRTY"),j=Symbol("RESOLVED"),rt=Symbol("SINGLE_DEP"),ot=0,at=1,ct=2,ut=3,lt=4,dt=5,y=7,J=7<<y,kt=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ft(t){return kt[(t&J)>>>y]}var b=0,T=1,p=2,m=3,N=0,C=[],B=!1;function K(t){N++;try{return t()}finally{if(N--,N===0&&!B){B=!0;for(let e=0;e<C.length;e++)C[e]();C.length=0,B=!1}}}function F(){return N>0}function U(t){C.push(t)}var Dt=0,xt=[];function gt(t){Dt>0?xt.push(t):t()}var R=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 s=e.map(i=>t._names.get(i)??"?").join(",");return s.length>40?`${s.slice(0,37)}...`:s}static _resolveKey(e){let n=t._keys.get(e)??t._names.get(e);if(n)return n;let s=`anonymous_${t._nextId++}`;return t._keys.set(e,s),s}static register(e,n){if(!t.enabled)return;n?.name&&t._names.set(e,n.name),n?.kind&&t._kinds.set(e,n.kind);let s=t._nextId++,i=n?.name;if(!(i&&!t._usedKeys.has(i)))if(i){let o=t._depSuffix(n?.deps);i=o?`${i}(${o})`:`${i}_${s}`,t._usedKeys.has(i)&&(i=`${i}_${s}`)}else{let o=n?.kind??"store",r=t._depSuffix(n?.deps);i=r?`${o}(${r})`:`${o}_${s}`,t._usedKeys.has(i)&&(i=`${i}_${s}`)}t._usedKeys.add(i),t._keys.set(e,i),t._stores.add(new WeakRef(e))}static registerEdge(e,n){if(!t.enabled)return;let s=t._resolveKey(e),i=t._resolveKey(n),o=t._edges.get(s);o?o.includes(i)||o.push(i):t._edges.set(s,[i])}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,n=new Set;for(let s of t._stores){let i=s.deref();if(!i){t._stores.delete(s);continue}let o=t._resolveKey(i);n.add(o),e.set(o,t.inspect(i))}for(let[s,i]of t._edges){if(!n.has(s)){t._edges.delete(s),t._usedKeys.delete(s);continue}let o=i.filter(r=>n.has(r));o.length===0?t._edges.delete(s):o.length!==i.length&&t._edges.set(s,o)}return e}static trace(e,n){let s=null,i=e.get();return e.source(b,(o,r)=>{if(o===b&&(s=r),o===p){s=null;return}if(o===1){let u=r;if(!Object.is(u,i)){let a=i;i=u,n(u,a)}}}),()=>s?.(p)}static dumpGraph(){let e=t.graph(),n=t.getEdges(),s=new Map;for(let[r,u]of n)for(let a of u){let d=s.get(a);d?d.includes(r)||d.push(r):s.set(a,[r])}let i=[];for(let[r,u]of e){let a=s.get(r),d=n.get(r),c=a?.length?` \u2190 [${a.join(", ")}]`:"",l=d?.length?` \u2192 [${d.join(", ")}]`:"";i.push(` ${r} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${c}${l}`)}return[`Store Graph (${e.size} nodes):`,...i].join(`
|
|
2
|
+
`)}static _observe(e,n,s){let i=null,o=n??t.getName(e),r={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:o,dispose:()=>i?.(p)};return e.source(b,(u,a)=>{if(u===b){i=a;return}u===T?(r.values.push(a),r.events.push({type:"data",data:a}),s&&s(`[${o}] DATA:`,a)):u===m?(r.signals.push(a),r.events.push({type:"signal",data:a}),a===v?r.dirtyCount++:a===j&&r.resolvedCount++,s&&s(`[${o}] STATE:`,a)):u===p&&(r.ended=!0,r.endError=a,r.events.push({type:"end",data:a}),s&&s(`[${o}] END`,a!==void 0?a:""),i=null)}),r}static observe(e){return t._observe(e)}static tap(e,n){let s=n??`tap(${t.getName(e)??"anon"})`,i={get:()=>e.get(),source:e.source};return t.register(i,{name:s,kind:"tap"}),t.registerEdge(e,i),i}static spy(e,n){let s=n?.name??t.getName(e)??"spy",i=n?.log??console.log;return t._observe(e,s,i)}static snapshot(){let e=t.graph(),n=t.getEdges(),s=new Map;for(let r of t._stores){let u=r.deref();if(!u)continue;let a=t._annotations.get(u);a!==void 0&&s.set(t._resolveKey(u),a)}let i=[];for(let[r,u]of e){let a={name:r,kind:u.kind,value:u.value,status:u.status},d=s.get(r);d!==void 0&&(a.annotation=d),i.push(a)}let o=[];for(let[r,u]of n)for(let a of u)o.push({from:r,to:a});return{nodes:i,edges:o,trace:t.traceLog()}}static toMermaid(e){let n=e?.direction??"TD",s=t.snapshot(),i=[`graph ${n}`],o={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},r=new Map;function u(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),f=r.get(l);return f===void 0?(r.set(l,1),l):(r.set(l,f+1),`${l}__${f}`)}let a=new Map;function d(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of s.nodes){let l=u(c.name);a.set(c.name,l);let f=`${c.name} (${c.kind}) = ${d(c.value)}`,M=o[c.status??""]??"";i.push(` ${l}["${f}"]${M}`)}for(let c of s.edges){let l=a.get(c.from)??u(c.from),f=a.get(c.to)??u(c.to);i.push(` ${l} --> ${f}`)}return i.push(""),i.push(" classDef settled fill:#d4edda,stroke:#28a745"),i.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),i.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),i.push(" classDef completed fill:#cce5ff,stroke:#007bff"),i.join(`
|
|
3
|
+
`)}static toD2(e){let n=e?.direction??"down",s=t.snapshot(),i=[`direction: ${n}`,""],o={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},r=new Map;function u(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),f=r.get(l);return f===void 0?(r.set(l,1),l):(r.set(l,f+1),`${l}__${f}`)}let a=new Map;function d(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of s.nodes){let l=u(c.name);a.set(c.name,l);let f=o[c.kind]??"rectangle",M=`${c.name} (${c.kind}) = ${d(c.value)}`,D=c.status?` [${c.status}]`:"";i.push(`${l}: "${M}${D}" { shape: ${f} }`)}s.edges.length>0&&i.push("");for(let c of s.edges){let l=a.get(c.from)??u(c.from),f=a.get(c.to)??u(c.to);i.push(`${l} -> ${f}`)}return i.join(`
|
|
4
|
+
`)}static annotate(e,n){if(!t.enabled)return;t._annotations.set(e,n);let s={node:t._resolveKey(e),reason:n,timestamp:Date.now()},i=t.maxTraceEntries;i<=0||(t._traceLog.length<i?t._traceLog.push(s):(t._traceLog[t._traceHead]=s,t._traceFull=!0),t._traceHead=(t._traceHead+1)%i)}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 _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 W=1,h=64,_=2,w=4,pt=8,ht=16,L=32,S=1024,g=J,$=at<<y,I=ct<<y,Y=ot<<y,Lt=lt<<y,Rt=dt<<y,wt=ut<<y,V=class{_value;_output=null;_flags;get _status(){return ft(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;constructor(e,n){this._value=n?.initial,this._fn=e,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let s=0;n?.autoDirty!==!1&&(s|=w),n?.resetOnTeardown&&(s|=pt),n?.resubscribable&&(s|=ht),this._flags=s,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||R.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(e,n){let s=this._output;if(s)if(this._flags&h)for(let i of s)i(e,n);else s(e,n)}emit(e){this._flags&_||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(F()?this._flags&L||(this._flags|=L,this._flags&w&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),U(()=>{this._flags&=~L,this._flags=this._flags&~g|I,this._dispatch(T,this._value)})):(this._flags&w&&!(this._flags&S)&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),this._flags=this._flags&~g|I,this._dispatch(T,this._value))))}signal(e){this._flags&_||!this._output||(e===v?this._flags=this._flags&~g|$:e===j&&(this._flags=this._flags&~g|wt),this._dispatch(m,e))}complete(){if(this._flags&_)return;this._flags=(this._flags|_)&~g|Lt;let e=this._output,n=this._flags&h;if(this._output=null,this._flags&=~(h|S),this._singleDepCount=0,this._stop(),e)if(n)for(let s of e)s(p);else e(p)}error(e){if(this._flags&_)return;this._flags=(this._flags|_)&~g|Rt;let n=this._output,s=this._flags&h;if(this._output=null,this._flags&=~(h|S),this._singleDepCount=0,this._stop(),n)if(s)for(let i of n)i(p,e);else n(p,e)}_start(){if(this._flags&W||!this._fn)return;this._flags|=W;let e=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n)});this._cleanup=typeof e=="function"?e:void 0}_stop(){this._flags&W&&(this._flags&=~W,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&pt&&(this._value=this._initial),this._flags&_||(this._flags=this._flags&~g|Y))}source(e,n){if(e===b){let s=n;if(this._flags&_)if(this._flags&ht&&this._output===null)this._flags=this._flags&~(_|g)|Y;else{s(b,o=>{}),s(p);return}if(this._output===null)this._output=s;else if(this._flags&h)this._output.add(s);else{let o=new Set;o.add(this._output),o.add(s),this._output=o,this._flags=(this._flags|h)&~S}let i=!1;s(b,(o,r)=>{if(o===T&&s(T,this._value),o===m&&r===rt&&!i&&(i=!0,this._singleDepCount++,this._flags&h||(this._flags|=S)),o===p){if(i&&(i=!1,this._singleDepCount--),this._output===null)return;if(this._flags&h){let u=this._output;u.delete(s),u.size===1?(this._output=u.values().next().value,this._flags&=~h,this._singleDepCount>0&&(this._flags|=S)):u.size===0&&(this._output=null,this._flags&=~(h|S),this._singleDepCount=0,this._flags=this._flags&~g|Y,this._stop())}else this._output===s&&(this._output=null,this._flags&=~S,this._singleDepCount=0,this._flags=this._flags&~g|Y,this._stop())}}),gt(()=>this._start())}}};var Z=class extends V{constructor(e,n){super(void 0,{initial:e,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),R.register(this,{kind:"state",...n})}get(){return this._value}set(e){this._flags&_||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(F()?this._flags&L||(this._flags|=L,this._flags&w&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),U(()=>{this._flags&=~L,this._flags=this._flags&~g|I,this._dispatch(T,this._value)})):(this._flags&w&&!(this._flags&S)&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),this._flags=this._flags&~g|I,this._dispatch(T,this._value))))}update(e){this.set(e(this._value))}};function O(t,e){return new Z(t,e)}function $t(t){switch(t){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function Mt(t,e){switch(t){case"openai":case"custom":return`${e}/chat/completions`;case"ollama":return`${e}/api/chat`;default:return`${e}/chat/completions`}}function It(t,e,n,s){let i={model:e,messages:n,stream:!0};return s?.temperature!==void 0&&(i.temperature=s.temperature),s?.maxTokens!==void 0&&(t==="ollama"?i.options={num_predict:s.maxTokens}:i.max_tokens=s.maxTokens),s?.stop&&(i.stop=s.stop),i}function Ot(t,e){let n={"Content-Type":"application/json"};return e&&(n.Authorization=`Bearer ${e}`),n}function At(t){let e=t.name??"llm",n=t.provider,s=t.baseURL??$t(n),i=t.model??"",o=t.fetch??globalThis.fetch,r=O("",{name:`${e}.store`}),u=O({},{name:`${e}.tokens`}),a=O("pending",{name:`${e}.status`}),d=O(void 0,{name:`${e}.error`}),c=null;function l(){c&&(c.abort(),c=null),a.get()==="active"&&K(()=>{r.set(""),a.set("pending")})}function f(D,x){l(),c=new AbortController;let G=x?.signal?Ct(c.signal,x.signal):c.signal;K(()=>{r.set(""),u.set({}),d.set(void 0),a.set("active")});let E=Mt(n,s),k=It(n,i,D,x),A=Ot(n,t.apiKey);M(E,A,k,G).catch(()=>{})}async function M(D,x,G,E){try{let k=await o(D,{method:"POST",headers:x,body:JSON.stringify(G),signal:E});if(!k.ok){let q=await k.text().catch(()=>"");throw new Error(`LLM API error ${k.status}: ${q}`)}let A=k.body?.getReader();if(!A)throw new Error("No response body");let Q=new TextDecoder,X="",H="";for(;;){if(E.aborted)return;let{done:q,value:_t}=await A.read();if(q)break;H+=Q.decode(_t,{stream:!0});let tt=H.split(`
|
|
5
|
+
`);H=tt.pop()??"";for(let Tt of tt){if(E.aborted)return;let P=Tt.trim();if(!P||P.startsWith(":")||!P.startsWith("data: "))continue;let et=P.slice(6);if(et!=="[DONE]")try{let nt=JSON.parse(et),st=Pt(n,nt);st&&(X+=st,r.set(X));let it=Nt(n,nt);it&&u.set(it)}catch{}}}if(Q.decode(),E.aborted)return;a.set("completed"),c=null}catch(k){if(E.aborted)return;K(()=>{d.set(k),a.set("errored")}),c=null}finally{E._cleanup?.()}}return{get:()=>r.get(),source:(D,x)=>r.source(D,x),tokens:u,status:a,error:d,generate:f,abort:l}}function Pt(t,e){return t==="ollama"?e?.message?.content:e?.choices?.[0]?.delta?.content}function Nt(t,e){let n=t==="ollama"?e:e?.usage;if(n){if(t==="ollama")return e.eval_count!==void 0||e.prompt_eval_count!==void 0?{promptTokens:e.prompt_eval_count,completionTokens:e.eval_count,totalTokens:(e.prompt_eval_count??0)+(e.eval_count??0)}:void 0;if(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function Ct(t,e){let n=new AbortController,s=()=>{t.removeEventListener("abort",i),e.removeEventListener("abort",i)},i=()=>{n.abort(),s()};t.addEventListener("abort",i,{once:!0}),e.addEventListener("abort",i,{once:!0});let o=n.signal;return o._cleanup=s,o}0&&(module.exports={fromLLM});
|
package/dist/adapters/llm.d.cts
CHANGED
|
@@ -35,9 +35,7 @@ interface GenerateOptions {
|
|
|
35
35
|
/** AbortSignal for cancellation. */
|
|
36
36
|
signal?: AbortSignal;
|
|
37
37
|
}
|
|
38
|
-
interface LLMStore {
|
|
39
|
-
/** Accumulated response text (reactive). */
|
|
40
|
-
store: Store<string>;
|
|
38
|
+
interface LLMStore extends Store<string> {
|
|
41
39
|
/** Token usage from the last generation (reactive, populated on completion). */
|
|
42
40
|
tokens: Store<LLMTokenUsage>;
|
|
43
41
|
/** Lifecycle status: pending → active → completed/errored. */
|
|
@@ -54,13 +52,14 @@ interface LLMStore {
|
|
|
54
52
|
*
|
|
55
53
|
* @param opts - Provider configuration (provider, baseURL, apiKey, model).
|
|
56
54
|
*
|
|
57
|
-
* @returns `LLMStore` —
|
|
55
|
+
* @returns `LLMStore` — `Store<string>` with `status`, `error`, `tokens` companion stores, plus `generate()` and `abort()`.
|
|
58
56
|
*
|
|
59
57
|
* @remarks **Provider-agnostic:** Works with OpenAI, Ollama, Anthropic (via proxy), Vercel AI SDK, or any OpenAI-compatible endpoint.
|
|
60
58
|
* @remarks **No hard deps:** Uses fetch + SSE line parsing. No SDK imports required.
|
|
61
59
|
* @remarks **Auto-cancel:** Calling `generate()` while streaming aborts the previous generation.
|
|
62
60
|
* @remarks **Token tracking:** `tokens` store populated on stream completion (when usage data is available).
|
|
63
61
|
* @remarks **Status:** Uses WithStatusStatus enum (pending → active → completed/errored) for consistent lifecycle tracking.
|
|
62
|
+
* @remarks **Persistent source:** This is a long-lived store backed by `state()`. It does not send callbag END — lifecycle is managed imperatively via `generate()`/`abort()`, not via stream completion. Do not wrap with `withStatus()` or `retry()` — use the built-in `.status` and `.error` companions instead.
|
|
64
63
|
*
|
|
65
64
|
* @example
|
|
66
65
|
* ```ts
|
|
@@ -69,13 +68,13 @@ interface LLMStore {
|
|
|
69
68
|
*
|
|
70
69
|
* const llm = fromLLM({ provider: 'ollama', model: 'llama4' });
|
|
71
70
|
*
|
|
72
|
-
* effect([llm
|
|
73
|
-
* console.log(llm.
|
|
71
|
+
* effect([llm], () => {
|
|
72
|
+
* console.log(llm.get()); // accumulating response...
|
|
74
73
|
* });
|
|
75
74
|
*
|
|
76
75
|
* llm.generate([{ role: 'user', content: 'What is TypeScript?' }]);
|
|
77
76
|
* // llm.status.get() → "active"
|
|
78
|
-
* // llm.
|
|
77
|
+
* // llm.get() → "TypeScript is..."
|
|
79
78
|
* ```
|
|
80
79
|
*
|
|
81
80
|
* @category adapters
|
package/dist/adapters/llm.d.ts
CHANGED
|
@@ -35,9 +35,7 @@ interface GenerateOptions {
|
|
|
35
35
|
/** AbortSignal for cancellation. */
|
|
36
36
|
signal?: AbortSignal;
|
|
37
37
|
}
|
|
38
|
-
interface LLMStore {
|
|
39
|
-
/** Accumulated response text (reactive). */
|
|
40
|
-
store: Store<string>;
|
|
38
|
+
interface LLMStore extends Store<string> {
|
|
41
39
|
/** Token usage from the last generation (reactive, populated on completion). */
|
|
42
40
|
tokens: Store<LLMTokenUsage>;
|
|
43
41
|
/** Lifecycle status: pending → active → completed/errored. */
|
|
@@ -54,13 +52,14 @@ interface LLMStore {
|
|
|
54
52
|
*
|
|
55
53
|
* @param opts - Provider configuration (provider, baseURL, apiKey, model).
|
|
56
54
|
*
|
|
57
|
-
* @returns `LLMStore` —
|
|
55
|
+
* @returns `LLMStore` — `Store<string>` with `status`, `error`, `tokens` companion stores, plus `generate()` and `abort()`.
|
|
58
56
|
*
|
|
59
57
|
* @remarks **Provider-agnostic:** Works with OpenAI, Ollama, Anthropic (via proxy), Vercel AI SDK, or any OpenAI-compatible endpoint.
|
|
60
58
|
* @remarks **No hard deps:** Uses fetch + SSE line parsing. No SDK imports required.
|
|
61
59
|
* @remarks **Auto-cancel:** Calling `generate()` while streaming aborts the previous generation.
|
|
62
60
|
* @remarks **Token tracking:** `tokens` store populated on stream completion (when usage data is available).
|
|
63
61
|
* @remarks **Status:** Uses WithStatusStatus enum (pending → active → completed/errored) for consistent lifecycle tracking.
|
|
62
|
+
* @remarks **Persistent source:** This is a long-lived store backed by `state()`. It does not send callbag END — lifecycle is managed imperatively via `generate()`/`abort()`, not via stream completion. Do not wrap with `withStatus()` or `retry()` — use the built-in `.status` and `.error` companions instead.
|
|
64
63
|
*
|
|
65
64
|
* @example
|
|
66
65
|
* ```ts
|
|
@@ -69,13 +68,13 @@ interface LLMStore {
|
|
|
69
68
|
*
|
|
70
69
|
* const llm = fromLLM({ provider: 'ollama', model: 'llama4' });
|
|
71
70
|
*
|
|
72
|
-
* effect([llm
|
|
73
|
-
* console.log(llm.
|
|
71
|
+
* effect([llm], () => {
|
|
72
|
+
* console.log(llm.get()); // accumulating response...
|
|
74
73
|
* });
|
|
75
74
|
*
|
|
76
75
|
* llm.generate([{ role: 'user', content: 'What is TypeScript?' }]);
|
|
77
76
|
* // llm.status.get() → "active"
|
|
78
|
-
* // llm.
|
|
77
|
+
* // llm.get() → "TypeScript is..."
|
|
79
78
|
* ```
|
|
80
79
|
*
|
|
81
80
|
* @category adapters
|
package/dist/adapters/llm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-KWTA2EOH.js";import"../chunk-P5MXN4AF.js";import"../chunk-YN4VWXAF.js";import"../chunk-M76W372U.js";import"../chunk-CWP55MPE.js";import"../chunk-I7AUKTXE.js";export{a as fromLLM};
|
package/dist/adapters/mcp.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}static _observe(t,i,n){let s=null,r=i??e.getName(t),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>s?.(p)};return t.source(D,(u,c)=>{if(u===D){s=c;return}u===T?(o.values.push(c),o.events.push({type:"data",data:c}),n&&n(`[${r}] DATA:`,c)):u===S?(o.signals.push(c),o.events.push({type:"signal",data:c}),c===E?o.dirtyCount++:c===
|
|
1
|
+
"use strict";var J=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var i in t)J(e,i,{get:t[i],enumerable:!0})},Te=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of pe(t))!he.call(e,s)&&s!==i&&J(e,s,{get:()=>t[s],enumerable:!(n=ge(t,s))||n.enumerable});return e};var Se=e=>Te(J({},"__esModule",{value:!0}),e);var xe={};_e(xe,{fromMCP:()=>ke});module.exports=Se(xe);var E=Symbol("DIRTY"),W=Symbol("RESOLVED"),ee=Symbol("SINGLE_DEP"),te=0,ne=1,se=2,ie=3,re=4,oe=5,v=7,Q=7<<v,me=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ae(e){return me[(e&Q)>>>v]}var D=0,T=1,p=2,S=3,F=0,Y=[],Z=!1;function I(e){F++;try{return e()}finally{if(F--,F===0&&!Z){Z=!0;for(let t=0;t<Y.length;t++)Y[t]();Y.length=0,Z=!1}}}function V(){return F>0}function H(e){Y.push(e)}var ye=0,Ee=[];function ue(e){ye>0?Ee.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",o=e._depSuffix(i?.deps);s=o?`${r}(${o})`:`${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(o=>i.has(o));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(D,(r,o)=>{if(r===D&&(n=o),r===p){n=null;return}if(r===1){let u=o;if(!Object.is(u,s)){let c=s;s=u,i(u,c)}}}),()=>n?.(p)}static dumpGraph(){let t=e.graph(),i=e.getEdges(),n=new Map;for(let[o,u]of i)for(let c of u){let d=n.get(c);d?d.includes(o)||d.push(o):n.set(c,[o])}let s=[];for(let[o,u]of t){let c=n.get(o),d=i.get(o),a=c?.length?` \u2190 [${c.join(", ")}]`:"",l=d?.length?` \u2192 [${d.join(", ")}]`:"";s.push(` ${o} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${a}${l}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
|
|
2
|
+
`)}static _observe(t,i,n){let s=null,r=i??e.getName(t),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>s?.(p)};return t.source(D,(u,c)=>{if(u===D){s=c;return}u===T?(o.values.push(c),o.events.push({type:"data",data:c}),n&&n(`[${r}] DATA:`,c)):u===S?(o.signals.push(c),o.events.push({type:"signal",data:c}),c===E?o.dirtyCount++:c===W&&o.resolvedCount++,n&&n(`[${r}] STATE:`,c)):u===p&&(o.ended=!0,o.endError=c,o.events.push({type:"end",data:c}),n&&n(`[${r}] END`,c!==void 0?c:""),s=null)}),o}static observe(t){return e._observe(t)}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 o of e._stores){let u=o.deref();if(!u)continue;let c=e._annotations.get(u);c!==void 0&&n.set(e._resolveKey(u),c)}let s=[];for(let[o,u]of t){let c={name:o,kind:u.kind,value:u.value,status:u.status},d=n.get(o);d!==void 0&&(c.annotation=d),s.push(c)}let r=[];for(let[o,u]of i)for(let c of u)r.push({from:o,to:c});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"},o=new Map;function u(a){let l=a.replace(/[^a-zA-Z0-9_]/g,"_"),f=o.get(l);return f===void 0?(o.set(l,1),l):(o.set(l,f+1),`${l}__${f}`)}let c=new Map;function d(a){let l=JSON.stringify(a);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let a of n.nodes){let l=u(a.name);c.set(a.name,l);let f=`${a.name} (${a.kind}) = ${d(a.value)}`,k=r[a.status??""]??"";s.push(` ${l}["${f}"]${k}`)}for(let a of n.edges){let l=c.get(a.from)??u(a.from),f=c.get(a.to)??u(a.to);s.push(` ${l} --> ${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 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"},o=new Map;function u(a){let l=a.replace(/[^a-zA-Z0-9_]/g,"_"),f=o.get(l);return f===void 0?(o.set(l,1),l):(o.set(l,f+1),`${l}__${f}`)}let c=new Map;function d(a){let l=JSON.stringify(a);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let a of n.nodes){let l=u(a.name);c.set(a.name,l);let f=r[a.kind]??"rectangle",k=`${a.name} (${a.kind}) = ${d(a.value)}`,M=a.status?` [${a.status}]`:"";s.push(`${l}: "${k}${M}" { shape: ${f} }`)}n.edges.length>0&&s.push("");for(let a of n.edges){let l=c.get(a.from)??u(a.from),f=c.get(a.to)??u(a.to);s.push(`${l} -> ${f}`)}return s.join(`
|
|
4
|
-
`)}static annotate(t,i){if(!e.enabled)return;e._annotations.set(t,i);let n={node:e._resolveKey(t),reason:i,timestamp:Date.now()},s=e.maxTraceEntries;s<=0||(e._traceLog.length<s?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%s)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var
|
|
5
|
-
`),fe=new Error(y||"MCP tool returned error");I(()=>{C.set(
|
|
4
|
+
`)}static annotate(t,i){if(!e.enabled)return;e._annotations.set(t,i);let n={node:e._resolveKey(t),reason:i,timestamp:Date.now()},s=e.maxTraceEntries;s<=0||(e._traceLog.length<s?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%s)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var U=1,h=64,_=2,P=4,ce=8,le=16,x=32,m=1024,g=Q,$=ne<<v,O=se<<v,q=te<<v,ve=re<<v,De=oe<<v,be=ie<<v,G=class{_value;_output=null;_flags;get _status(){return ae(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;constructor(t,i){this._value=i?.initial,this._fn=t,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=P),i?.resetOnTeardown&&(n|=ce),i?.resubscribable&&(n|=le),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&h)for(let s of n)s(t,i);else n(t,i)}emit(t){this._flags&_||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(V()?this._flags&x||(this._flags|=x,this._flags&P&&(this._flags=this._flags&~g|$,this._dispatch(S,E)),H(()=>{this._flags&=~x,this._flags=this._flags&~g|O,this._dispatch(T,this._value)})):(this._flags&P&&!(this._flags&m)&&(this._flags=this._flags&~g|$,this._dispatch(S,E)),this._flags=this._flags&~g|O,this._dispatch(T,this._value))))}signal(t){this._flags&_||!this._output||(t===E?this._flags=this._flags&~g|$:t===W&&(this._flags=this._flags&~g|be),this._dispatch(S,t))}complete(){if(this._flags&_)return;this._flags=(this._flags|_)&~g|ve;let t=this._output,i=this._flags&h;if(this._output=null,this._flags&=~(h|m),this._singleDepCount=0,this._stop(),t)if(i)for(let n of t)n(p);else t(p)}error(t){if(this._flags&_)return;this._flags=(this._flags|_)&~g|De;let i=this._output,n=this._flags&h;if(this._output=null,this._flags&=~(h|m),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(p,t);else i(p,t)}_start(){if(this._flags&U||!this._fn)return;this._flags|=U;let t=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i)});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&U&&(this._flags&=~U,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&ce&&(this._value=this._initial),this._flags&_||(this._flags=this._flags&~g|q))}source(t,i){if(t===D){let n=i;if(this._flags&_)if(this._flags&le&&this._output===null)this._flags=this._flags&~(_|g)|q;else{n(D,r=>{}),n(p);return}if(this._output===null)this._output=n;else if(this._flags&h)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|h)&~m}let s=!1;n(D,(r,o)=>{if(r===T&&n(T,this._value),r===S&&o===ee&&!s&&(s=!0,this._singleDepCount++,this._flags&h||(this._flags|=m)),r===p){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&h){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~h,this._singleDepCount>0&&(this._flags|=m)):u.size===0&&(this._output=null,this._flags&=~(h|m),this._singleDepCount=0,this._flags=this._flags&~g|q,this._stop())}else this._output===n&&(this._output=null,this._flags&=~m,this._singleDepCount=0,this._flags=this._flags&~g|q,this._stop())}}),ue(()=>this._start())}}};var X=class extends G{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&_||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(V()?this._flags&x||(this._flags|=x,this._flags&P&&(this._flags=this._flags&~g|$,this._dispatch(S,E)),H(()=>{this._flags&=~x,this._flags=this._flags&~g|O,this._dispatch(T,this._value)})):(this._flags&P&&!(this._flags&m)&&(this._flags=this._flags&~g|$,this._dispatch(S,E)),this._flags=this._flags&~g|O,this._dispatch(T,this._value))))}update(t){this.set(t(this._value))}};function b(e,t){return new X(e,t)}function ke(e){let t=e.name??"mcp",i=e.client,n=b([],{name:`${t}.tools`}),s=b([],{name:`${t}.resources`}),r=b(void 0,{name:`${t}.refreshError`});function o(d){r.set(d);let a=e.onRefreshError;if(a==="warn")console.warn(`[${t}] refresh error:`,d);else{if(a==="error")throw d;typeof a=="function"&&a(d)}}async function u(){if(r.set(void 0),i.listTools)try{let d=await i.listTools();n.set(d.tools)}catch(d){o(d)}if(i.listResources)try{let d=await i.listResources();s.set(d.resources)}catch(d){o(d)}}function c(d){let a=`${t}:${d}`,l=b(void 0,{name:`${a}.result`}),f=b("idle",{name:`${a}.status`}),k=b(void 0,{name:`${a}.error`}),M=b(void 0,{name:`${a}.lastArgs`}),C=b(void 0,{name:`${a}.duration`}),z=!1;async function de(L){if(z)return;z=!0,I(()=>{M.set(L),k.set(void 0),f.set("active")});let N=Date.now();try{let R=await i.callTool({name:d,arguments:L}),j=Date.now()-N;if(R.isError){let y=R.content.filter(B=>B.type==="text").map(B=>B.text??"").join(`
|
|
5
|
+
`),fe=new Error(y||"MCP tool returned error");I(()=>{C.set(j),k.set(fe),f.set("errored")});return}let K=R.content.filter(y=>y.type==="text"),A;if(K.length===1){let y=K[0].text;if(y!==void 0)try{A=JSON.parse(y)}catch{A=y}}else K.length>1?A=K.map(y=>y.text??""):A=R.content;I(()=>{C.set(j),l.set(A),f.set("completed")})}catch(R){let j=Date.now()-N;I(()=>{C.set(j),k.set(R),f.set("errored")})}finally{z=!1}}return{get:()=>l.get(),source:(L,N)=>l.source(L,N),status:f,error:k,call:de,lastArgs:M,duration:C}}return{tool:c,tools:n,resources:s,refresh:u,refreshError:r}}0&&(module.exports={fromMCP});
|