@callbag-recharge/callbag-recharge 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +11 -3
  2. package/dist/adapters/http.cjs +4 -4
  3. package/dist/adapters/http.js +1 -1
  4. package/dist/adapters/index.cjs +10 -11
  5. package/dist/adapters/index.d.cts +1 -1
  6. package/dist/adapters/index.d.ts +1 -1
  7. package/dist/adapters/index.js +1 -1
  8. package/dist/adapters/mcp.cjs +5 -5
  9. package/dist/adapters/mcp.d.cts +4 -4
  10. package/dist/adapters/mcp.d.ts +4 -4
  11. package/dist/adapters/mcp.js +1 -1
  12. package/dist/adapters/sse.cjs +10 -10
  13. package/dist/adapters/sse.d.cts +3 -2
  14. package/dist/adapters/sse.d.ts +3 -2
  15. package/dist/adapters/sse.js +1 -1
  16. package/dist/adapters/webhook.cjs +4 -4
  17. package/dist/adapters/webhook.d.cts +3 -2
  18. package/dist/adapters/webhook.d.ts +3 -2
  19. package/dist/adapters/webhook.js +1 -1
  20. package/dist/ai/agentLoop/index.cjs +4 -0
  21. package/dist/{patterns → ai}/agentLoop/index.d.cts +2 -2
  22. package/dist/{patterns → ai}/agentLoop/index.d.ts +2 -2
  23. package/dist/ai/agentLoop/index.js +1 -0
  24. package/dist/ai/chatStream/index.cjs +4 -0
  25. package/dist/{patterns → ai}/chatStream/index.d.cts +6 -5
  26. package/dist/{patterns → ai}/chatStream/index.d.ts +6 -5
  27. package/dist/ai/chatStream/index.js +1 -0
  28. package/dist/ai/conversationSummary/index.cjs +7 -0
  29. package/dist/ai/conversationSummary/index.d.cts +57 -0
  30. package/dist/ai/conversationSummary/index.d.ts +57 -0
  31. package/dist/ai/conversationSummary/index.js +1 -0
  32. package/dist/ai/docIndex/index.cjs +4 -0
  33. package/dist/ai/docIndex/index.d.cts +56 -0
  34. package/dist/ai/docIndex/index.d.ts +56 -0
  35. package/dist/ai/docIndex/index.js +1 -0
  36. package/dist/ai/embeddingIndex/index.cjs +4 -0
  37. package/dist/ai/embeddingIndex/index.d.cts +80 -0
  38. package/dist/ai/embeddingIndex/index.d.ts +80 -0
  39. package/dist/ai/embeddingIndex/index.js +1 -0
  40. package/dist/ai/fromLLM.cjs +5 -0
  41. package/dist/{adapters/llm.d.cts → ai/fromLLM.d.cts} +2 -2
  42. package/dist/{adapters/llm.d.ts → ai/fromLLM.d.ts} +2 -2
  43. package/dist/ai/fromLLM.js +1 -0
  44. package/dist/{patterns → ai}/hybridRoute/index.d.cts +2 -2
  45. package/dist/{patterns → ai}/hybridRoute/index.d.ts +2 -2
  46. package/dist/ai/hybridRoute/index.js +1 -0
  47. package/dist/ai/index.cjs +43 -0
  48. package/dist/ai/index.d.cts +402 -0
  49. package/dist/ai/index.d.ts +402 -0
  50. package/dist/ai/index.js +27 -0
  51. package/dist/ai/memoryStore/index.cjs +4 -0
  52. package/dist/{patterns → ai}/memoryStore/index.d.cts +11 -5
  53. package/dist/{patterns → ai}/memoryStore/index.d.ts +11 -5
  54. package/dist/ai/memoryStore/index.js +1 -0
  55. package/dist/ai/ragPipeline/index.cjs +13 -0
  56. package/dist/ai/ragPipeline/index.d.cts +98 -0
  57. package/dist/ai/ragPipeline/index.d.ts +98 -0
  58. package/dist/ai/ragPipeline/index.js +1 -0
  59. package/dist/ai/toolCallState/index.cjs +4 -0
  60. package/dist/{patterns → ai}/toolCallState/index.d.cts +3 -3
  61. package/dist/{patterns → ai}/toolCallState/index.d.ts +3 -3
  62. package/dist/ai/toolCallState/index.js +1 -0
  63. package/dist/{checkpoint-DYPJl1rB.d.ts → checkpoint-CC4tKs36.d.ts} +8 -7
  64. package/dist/{checkpoint-Dy-WJA3r.d.cts → checkpoint-uaYS0fN4.d.cts} +8 -7
  65. package/dist/chunk-2BP7Z7ZL.js +1 -0
  66. package/dist/chunk-2DNXE5W2.js +1 -0
  67. package/dist/chunk-3ORARRVS.js +1 -0
  68. package/dist/chunk-4ILN4V4C.js +1 -0
  69. package/dist/chunk-4PAUY5AJ.js +1 -0
  70. package/dist/chunk-565W67EU.js +11 -0
  71. package/dist/chunk-5UIA6BIQ.js +1 -0
  72. package/dist/chunk-6SUM4DCC.js +4 -0
  73. package/dist/chunk-6WZQIJIW.js +2 -0
  74. package/dist/chunk-AA2V6B63.js +1 -0
  75. package/dist/chunk-BBWZHYCT.js +1 -0
  76. package/dist/chunk-CDEQNFFU.js +1 -0
  77. package/dist/chunk-DTYSGTF4.js +1 -0
  78. package/dist/chunk-F7IHZH7D.js +1 -0
  79. package/dist/chunk-FJ2VN2O3.js +1 -0
  80. package/dist/chunk-FJMF46AF.js +1 -0
  81. package/dist/chunk-IB56FLRE.js +1 -0
  82. package/dist/chunk-J2E7GAMR.js +1 -0
  83. package/dist/chunk-JWQFJJJB.js +2 -0
  84. package/dist/chunk-LMR6RVT4.js +1 -0
  85. package/dist/chunk-O2PONDZT.js +1 -0
  86. package/dist/chunk-OZKWHUA6.js +1 -0
  87. package/dist/chunk-Q3HIBGHR.js +1 -0
  88. package/dist/chunk-QWMRZMRN.js +1 -0
  89. package/dist/chunk-S67PXKAL.js +10 -0
  90. package/dist/chunk-T5LUMTB7.js +1 -0
  91. package/dist/chunk-VHVYJSLE.js +1 -0
  92. package/dist/chunk-X2LL44CL.js +1 -0
  93. package/dist/chunk-XD4BHZSL.js +1 -0
  94. package/dist/chunk-XH7BHK7V.js +1 -0
  95. package/dist/chunk-Y72LPOTS.js +1 -0
  96. package/dist/chunk-YCYCWSXF.js +1 -0
  97. package/dist/chunk-Z6NJHBGT.js +1 -0
  98. package/dist/data/index.js +1 -1
  99. package/dist/{executionLog-CREljpYk.d.cts → executionLog-BIdo4sqy.d.cts} +7 -6
  100. package/dist/{executionLog-cGvVp5Ha.d.ts → executionLog-EPbLbbSd.d.ts} +7 -6
  101. package/dist/extra/fromPromise.cjs +4 -4
  102. package/dist/extra/fromPromise.d.cts +1 -1
  103. package/dist/extra/fromPromise.d.ts +1 -1
  104. package/dist/extra/fromPromise.js +1 -1
  105. package/dist/extra/index.cjs +4 -4
  106. package/dist/extra/index.d.cts +2 -1
  107. package/dist/extra/index.d.ts +2 -1
  108. package/dist/extra/index.js +1 -1
  109. package/dist/index.js +1 -1
  110. package/dist/memory/index.cjs +1 -1
  111. package/dist/memory/index.d.cts +2 -2
  112. package/dist/memory/index.d.ts +2 -2
  113. package/dist/memory/index.js +1 -1
  114. package/dist/messaging/index.cjs +6 -6
  115. package/dist/messaging/index.d.cts +8 -297
  116. package/dist/messaging/index.d.ts +8 -297
  117. package/dist/messaging/index.js +3 -3
  118. package/dist/orchestrate/executionLogAdapters.node.cjs +6 -6
  119. package/dist/orchestrate/executionLogAdapters.node.d.cts +3 -2
  120. package/dist/orchestrate/executionLogAdapters.node.d.ts +3 -2
  121. package/dist/orchestrate/executionLogAdapters.node.js +3 -3
  122. package/dist/orchestrate/index.cjs +6 -6
  123. package/dist/orchestrate/index.d.cts +14 -10
  124. package/dist/orchestrate/index.d.ts +14 -10
  125. package/dist/orchestrate/index.js +3 -3
  126. package/dist/patterns/pagination/index.cjs +4 -4
  127. package/dist/patterns/pagination/index.js +1 -1
  128. package/dist/patterns/textEditor/index.cjs +15 -15
  129. package/dist/patterns/textEditor/index.d.cts +5 -3
  130. package/dist/patterns/textEditor/index.d.ts +5 -3
  131. package/dist/patterns/textEditor/index.js +7 -7
  132. package/dist/{rateLimiter-DMeuSBxF.d.ts → rateLimiter-C9FDu1n0.d.cts} +4 -2
  133. package/dist/{rateLimiter-DMeuSBxF.d.cts → rateLimiter-nMWFRXZi.d.ts} +4 -2
  134. package/dist/subscribe-BHH8VVDm.d.cts +4 -0
  135. package/dist/subscribe-BHH8VVDm.d.ts +4 -0
  136. package/dist/tokenTracker-BRFP4C1K.d.ts +140 -0
  137. package/dist/tokenTracker-C1y5zB38.d.cts +140 -0
  138. package/dist/types-CJKW4Ae9.d.ts +298 -0
  139. package/dist/{types-DtkjWIED.d.ts → types-ClmMSIr-.d.ts} +7 -1
  140. package/dist/{types-BwBbIZux.d.cts → types-DbCdOVbw.d.cts} +7 -1
  141. package/dist/types-XRfOHCPC.d.cts +298 -0
  142. package/dist/utils/checkpointAdapters.node.cjs +1 -1
  143. package/dist/utils/checkpointAdapters.node.d.cts +3 -2
  144. package/dist/utils/checkpointAdapters.node.d.ts +3 -2
  145. package/dist/utils/checkpointAdapters.node.js +1 -1
  146. package/dist/utils/index.cjs +9 -9
  147. package/dist/utils/index.d.cts +29 -166
  148. package/dist/utils/index.d.ts +29 -166
  149. package/dist/utils/index.js +6 -6
  150. package/package.json +101 -51
  151. package/dist/adapters/llm.cjs +0 -5
  152. package/dist/adapters/llm.js +0 -1
  153. package/dist/chunk-2QHNHL5Y.js +0 -1
  154. package/dist/chunk-4AGPQIMR.js +0 -1
  155. package/dist/chunk-5PWKJDS3.js +0 -1
  156. package/dist/chunk-7LEA46F2.js +0 -1
  157. package/dist/chunk-7WPMCM7F.js +0 -2
  158. package/dist/chunk-F5EXEEZL.js +0 -1
  159. package/dist/chunk-I3EB4ACM.js +0 -1
  160. package/dist/chunk-JLWDE534.js +0 -1
  161. package/dist/chunk-LHEDPW3C.js +0 -1
  162. package/dist/chunk-LLARZ7J7.js +0 -1
  163. package/dist/chunk-NYLNL2Y5.js +0 -11
  164. package/dist/chunk-Q5DHO5II.js +0 -2
  165. package/dist/chunk-QSFTSBDR.js +0 -1
  166. package/dist/chunk-VCD3MXHY.js +0 -1
  167. package/dist/chunk-ZDGVUX5G.js +0 -1
  168. package/dist/patterns/agentLoop/index.cjs +0 -4
  169. package/dist/patterns/agentLoop/index.js +0 -1
  170. package/dist/patterns/chatStream/index.cjs +0 -4
  171. package/dist/patterns/chatStream/index.js +0 -1
  172. package/dist/patterns/hybridRoute/index.js +0 -1
  173. package/dist/patterns/memoryStore/index.cjs +0 -4
  174. package/dist/patterns/memoryStore/index.js +0 -1
  175. package/dist/patterns/toolCallState/index.cjs +0 -4
  176. package/dist/patterns/toolCallState/index.js +0 -1
  177. /package/dist/{patterns → ai}/hybridRoute/index.cjs +0 -0
package/README.md CHANGED
@@ -273,15 +273,23 @@ self.expose('count', countStore)
273
273
 
274
274
  ## Patterns
275
275
 
276
- 16 ready-made patterns built on the primitives — import and go.
276
+ Ten composed patterns on the primitives — import via `callbag-recharge/patterns/<name>`.
277
277
 
278
- `createStore` · `chatStream` · `commandBus` · `focusManager` · `formField` · `hybridRoute` · `memoryStore` · `pagination` · `rateLimiter` · `selection` · `textBuffer` · `textEditor` · `toolCallState` · `undoRedo` · `agentLoop`
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`) — `fromLLM` · `fromWebSocket` · `fromSSE` · `fromWebhook` · `fromHTTP` · `fromMCP`
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
 
@@ -1,4 +1,4 @@
1
- "use strict";var te=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var Le=(t,e)=>{for(var i in e)te(t,i,{get:e[i],enumerable:!0})},Ae=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of we(e))!Oe.call(t,s)&&s!==i&&te(t,s,{get:()=>e[s],enumerable:!(n=Re(e,s))||n.enumerable});return t};var Ie=t=>Ae(te({},"__esModule",{value:!0}),t);var je={};Le(je,{fromHTTP:()=>Me});module.exports=Ie(je);var D=Symbol("DIRTY"),M=Symbol("RESOLVED"),le=Symbol("SINGLE_DEP"),P=Symbol("RESET"),se=Symbol("PAUSE"),ie=Symbol("RESUME"),re=Symbol("TEARDOWN");function ue(t){return t===P||t===se||t===ie||t===re}var ce=0,fe=1,de=2,pe=3,ge=4,he=5,R=7,oe=7<<R,$e=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function Te(t){return $e[(t&oe)>>>R]}var h=0,_=1,g=2,S=3,H=0,q=[],ne=!1;function j(t){H++;try{return t()}finally{if(H--,H===0&&!ne){ne=!0;for(let e=0;e<q.length;e++)q[e]();q.length=0,ne=!1}}}function $(){return H>0}function z(t){q.push(t)}var G=0,B=[];function Se(){G++}function _e(){if(G--,G===0){for(let t=0;t<B.length;t++)B[t]();B.length=0}}function me(t){G>0?B.push(t):t()}var A=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",a=t._depSuffix(i?.deps);s=a?`${r}(${a})`:`${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(a=>i.has(a));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(h,(r,a)=>{if(r===h&&(n=a),r===g){n=null;return}if(r===1){let l=a;if(!Object.is(l,s)){let u=s;s=l,i(l,u)}}}),()=>n?.(g)}static dumpGraph(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let[a,l]of i)for(let u of l){let f=n.get(u);f?f.includes(a)||f.push(a):n.set(u,[a])}let s=[];for(let[a,l]of e){let u=n.get(a),f=i.get(a),o=u?.length?` \u2190 [${u.join(", ")}]`:"",c=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${l.kind}) = ${JSON.stringify(l.value)} [${l.status??"?"}]${o}${c}`)}return[`Store Graph (${e.size} nodes):`,...s].join(`
2
- `)}static _signalLabel(e){return e===D?"DIRTY":e===M?"RESOLVED":typeof e=="symbol"?e.description??String(e):String(e)}static _observe(e,i,n){let s=null,r=!1,a=i??t.getName(e),l=[],u={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return u.ended&&!r},get errored(){return u.ended&&r},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return l},dispose:()=>s?.(g),reconnect:()=>(s?.(g),t._observe(e,i,n))};return e.source(h,(f,o)=>{if(f===h){s=o;return}let c=$();f===_?(u.values.push(o),u.events.push({type:"data",data:o,inBatch:c}),l.push(o),n&&n(`[${a}] DATA:`,o)):f===S?(u.signals.push(o),u.events.push({type:"signal",data:o,inBatch:c}),l.push(t._signalLabel(o)),o===D?u.dirtyCount++:o===M&&u.resolvedCount++,n&&n(`[${a}] STATE:`,o)):f===g&&(u.ended=!0,u.endError=o,r=o!==void 0,u.events.push({type:"end",data:o,inBatch:c}),l.push(r?["END",o]:"END"),n&&n(`[${a}] END`,o!==void 0?o:""),s=null)}),u}static observe(e){return t._observe(e)}static activate(e){let i=null;return e.source(h,(n,s)=>{n===h&&(i=s),n===g&&(i=null)}),()=>i?.(g)}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 l=a.deref();if(!l)continue;let u=t._annotations.get(l);u!==void 0&&n.set(t._resolveKey(l),u)}let s=[];for(let[a,l]of e){let u={name:a,kind:l.kind,value:l.value,status:l.status},f=n.get(a);f!==void 0&&(u.annotation=f),s.push(u)}let r=[];for(let[a,l]of i)for(let u of l)r.push({from:a,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"},a=new Map;function l(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 u=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=l(o.name);u.set(o.name,c);let d=`${o.name} (${o.kind}) = ${f(o.value)}`,p=r[o.status??""]??"";s.push(` ${c}["${d}"]${p}`)}for(let o of n.edges){let c=u.get(o.from)??l(o.from),d=u.get(o.to)??l(o.to);s.push(` ${c} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
- `)}static toD2(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"},a=new Map;function l(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 u=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=l(o.name);u.set(o.name,c);let d=r[o.kind]??"rectangle",p=`${o.name} (${o.kind}) = ${f(o.value)}`,y=o.status?` [${o.status}]`:"";s.push(`${c}: "${p}${y}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let o of n.edges){let c=u.get(o.from)??l(o.from),d=u.get(o.to)??l(o.to);s.push(`${c} -> ${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(h,(s,r)=>{if(s===h){i=r;return}let a={timestamp:Date.now(),type:s===_?"data":s===S?"signal":"end",data:r,inBatch:$()};n.push(a),s===g&&(i=null)}),{entries:n,dispose:()=>i?.(g)}}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 u=n._deps.map(o=>o.get()),f=s();return i.push({result:f,depValues:u,timestamp:Date.now()}),f};let r=t._observe(e),a=r.dispose;return{...r,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(h,(r,a)=>{if(r===h){s=a;return}if(r===_){let l=a;if(l!==i){let u={from:i,to:l,timestamp:Date.now()};l==="error"&&(u.error=e.error.get()),n.push(u),i=l}}r===g&&(s=null)}),{transitions:n,get currentStatus(){return e.status.get()},dispose:()=>{s?.(g)}}}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 r=n._deps,a=r.map(o=>o.get());n._fn=()=>{let o=r.map(p=>p.get()),c=s(),d=-1;for(let p=0;p<r.length;p++)if(!Object.is(o[p],a[p])){d=p;break}return i.push({result:c,triggerDepIndex:d,triggerDepName:d>=0?t.getName(r[d]):void 0,depValues:o,timestamp:Date.now()}),a=o,c};let l=t._observe(e),u=l.dispose;return{...l,causality:i,dispose:()=>{n._fn=s,u()},reconnect:()=>(n._fn=s,u(),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 J=1,E=64,m=2,N=4,ye=8,be=16,I=32,k=1024,T=oe,C=fe<<R,W=de<<R,Z=ce<<R,Pe=ge<<R,Ne=he<<R,Ce=pe<<R,F=class{_value;_output=null;_flags;get _status(){return Te(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|=N),i?.resetOnTeardown&&(n|=ye),i?.resubscribable&&(n|=be),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||A.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&E)for(let s of n)s(e,i);else n(e,i)}emit(e){this._flags&m||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&($()?this._flags&I||(this._flags|=I,this._flags&N&&(this._flags=this._flags&~T|C,this._dispatch(S,D)),z(()=>{this._flags&=~I,this._flags=this._flags&~T|W,this._dispatch(_,this._value)})):(this._flags&N&&!(this._flags&k)&&(this._flags=this._flags&~T|C,this._dispatch(S,D)),this._flags=this._flags&~T|W,this._dispatch(_,this._value))))}signal(e){this._flags&m||!this._output||(e===D?this._flags=this._flags&~T|C:e===M&&(this._flags=this._flags&~T|Ce),this._dispatch(S,e))}complete(){if(this._flags&m)return;this._flags=(this._flags|m)&~T|Pe;let e=this._output,i=this._flags&E;if(this._output=null,this._flags&=~(E|k),this._singleDepCount=0,this._stop(),e)if(i)for(let n of e)n(g);else e(g)}error(e){if(this._flags&m)return;this._flags=(this._flags|m)&~T|Ne;let i=this._output,n=this._flags&E;if(this._output=null,this._flags&=~(E|k),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,e);else i(g,e)}_start(){if(this._flags&J||!this._fn)return;this._flags|=J,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&J&&(this._flags&=~J,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&ye&&(this._value=this._initial),this._flags&m||(this._flags=this._flags&~T|Z))}_handleLifecycleSignal(e){if(!(this._flags&m)){if(e===re){this._onLifecycleSignal?.(e),this.complete();return}e===P&&(this._value=this._initial,this._flags&=~I),this._onLifecycleSignal?.(e),e===P&&this.emit(this._initial)}}source(e,i){if(e===h){let n=i;if(this._flags&m)if(this._flags&be&&this._output===null)this._flags=this._flags&~(m|T)|Z;else{n(h,r=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&E)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|E)&~k}let s=!1;n(h,(r,a)=>{if(r===_&&n(_,this._value),r===S){a===le&&!s?(s=!0,this._singleDepCount++,this._flags&E||(this._flags|=k)):ue(a)&&this._handleLifecycleSignal(a);return}if(r===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&E){let l=this._output;l.delete(n),l.size===1?(this._output=l.values().next().value,this._flags&=~E,this._singleDepCount>0&&(this._flags|=k)):l.size===0&&(this._output=null,this._flags&=~(E|k),this._singleDepCount=0,this._flags=this._flags&~T|Z,this._stop())}else this._output===n&&(this._output=null,this._flags&=~k,this._singleDepCount=0,this._flags=this._flags&~T|Z,this._stop())}}),me(()=>this._start())}}};function Q(t,e){return new F(t,e)}var ae=class extends F{constructor(e,i){super(void 0,{initial:e,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),A.register(this,{kind:"state",...i})}get(){return this._value}set(e){this._flags&m||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&($()?this._flags&I||(this._flags|=I,this._flags&N&&(this._flags=this._flags&~T|C,this._dispatch(S,D)),z(()=>{this._flags&=~I,this._flags=this._flags&~T|W,this._dispatch(_,this._value)})):(this._flags&N&&!(this._flags&k)&&(this._flags=this._flags&~T|C,this._dispatch(S,D)),this._flags=this._flags&~T|W,this._dispatch(_,this._value))))}update(e){this.set(e(this._value))}};function K(t,e){return new ae(t,e)}function ve(t,e,i){let n=null;Se(),t.source(h,(r,a)=>{if(r===h&&(n=a),r===g){n=null,i?.onEnd?.(a);return}if(r===1){let l=a,u=s;s=l,e(l,u)}});let s;try{s=t.get()}catch{}return _e(),{unsubscribe(){n?.(g),n=null},signal(r){n?.(S,r)}}}function Ee(t,e){let i=e?.initialStatus??"pending",n=K(i,{name:"withStatus:status",equals:Object.is}),s=K(void 0,{name:"withStatus:error",equals:Object.is}),r=Q(({emit:l,complete:u,error:f})=>{n.set(i),s.set(void 0);let o=ve(t,c=>{n.get()==="errored"?j(()=>{s.set(void 0),n.set("active")}):n.set("active"),l(c)},{onEnd:c=>{if(c!==void 0){let d=c instanceof Error?c:new Error(String(c));j(()=>{s.set(d),n.set("errored")}),f(c)}else n.set("completed"),u()}});return()=>{o.unsubscribe()}},{initial:t.get(),resubscribable:!0}),a={get:()=>t.get(),source:(l,u)=>r.source(l,u),get _status(){return r._status},status:n,error:s};return A.register(a,{kind:"withStatus"}),a}function Me(t,e){let i=e?.name??"http",n=e?.method??"GET",s=e?.headers,r=e?.body,a=e?.poll??0,l=e?.transform??(w=>w.json()),u=e?.timeout??3e4,f=K(0,{name:`${i}:fetchCount`}),o=null,c=null,d=null,p=null,y=null,b=!1;async function V(){if(!b||!o)return;y=new AbortController;let w=[y.signal];e?.signal&&w.push(e.signal);let O=new AbortController;for(let v of w){if(v.aborted){O.abort(v.reason);break}v.addEventListener("abort",()=>O.abort(v.reason),{once:!0})}let ee=setTimeout(()=>O.abort(new Error("Request timeout")),u);try{let v=r!==void 0?typeof r=="string"?r:JSON.stringify(r):void 0,L=await fetch(t,{method:n,headers:s,body:v,signal:O.signal});if(!b)return;if(!L.ok)throw new Error(`HTTP ${L.status}: ${L.statusText}`);let ke=await l(L);if(!b)return;j(()=>{f.update(xe=>xe+1),o?.(ke)})}catch(v){if(!b||v?.name==="AbortError")return;c?.(v)}finally{clearTimeout(ee),y=null}}function U(){!b||x||a<=0||(p=setTimeout(()=>{p=null,V().then(()=>{b&&!x&&U()}).catch(()=>{})},a))}let X=null,x=!1,De=Q(({emit:w,error:O,complete:ee,onSignal:v})=>(o=w,c=O,d=ee,b=!0,x=!1,X=()=>{V()},v(L=>{L===se?(x=!0,p!==null&&(clearTimeout(p),p=null)):L===ie?(x=!1,U()):L===P&&(y?.abort(),y=null,p!==null&&(clearTimeout(p),p=null),f.set(0),x=!1,V().then(()=>{b&&!x&&U()}))}),V().then(()=>{b&&!x&&U()}),()=>{b=!1,x=!1,o=null,c=null,d=null,X=null,y?.abort(),y=null,p!==null&&(clearTimeout(p),p=null)}),{name:i,kind:"http"}),Y=Ee(De);return{get:()=>Y.get(),source:(w,O)=>Y.source(w,O),status:Y.status,error:Y.error,fetchCount:f,refetch(){X?.()},stop(){b=!1,y?.abort(),y=null,p!==null&&(clearTimeout(p),p=null),d?.()}}}0&&(module.exports={fromHTTP});
1
+ "use strict";var te=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Ce=(e,t)=>{for(var r in t)te(e,r,{get:t[r],enumerable:!0})},$e=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oe(t))!Pe.call(e,s)&&s!==r&&te(e,s,{get:()=>t[s],enumerable:!(n=Ie(t,s))||n.enumerable});return e};var Ne=e=>$e(te({},"__esModule",{value:!0}),e);var He={};Ce(He,{fromHTTP:()=>Ye});module.exports=Ne(He);var E=Symbol("DIRTY"),j=Symbol("RESOLVED"),fe=Symbol("SINGLE_DEP"),C=Symbol("RESET"),se=Symbol("PAUSE"),re=Symbol("RESUME"),ie=Symbol("TEARDOWN");function de(e){return e===C||e===se||e===re||e===ie}var pe=0,ge=1,he=2,Te=3,me=4,Se=5,x=7,oe=7<<x,Me=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function _e(e){return Me[(e&oe)>>>x]}var h=0,y=1,g=2,_=3,H=0,q=[],ne=!1;function F(e){H++;try{return e()}finally{if(H--,H===0&&!ne){ne=!0;for(let t=0;t<q.length;t++)q[t]();q.length=0,ne=!1}}}function O(){return H>0}function z(e){q.push(e)}var G=0,B=[];function ye(){G++}function be(){if(G--,G===0){for(let e=0;e<B.length;e++)B[e]();B.length=0}}function ve(e){G>0?B.push(e):e()}var A=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let n=t.map(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 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=r.get(a),o=l?.length?` \u2190 [${l.join(", ")}]`:"",c=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${o}${c}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
2
+ `)}static _signalLabel(t){return t===E?"DIRTY":t===j?"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,(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===_?(l.signals.push(o),l.events.push({type:"signal",data:o,inBatch:c}),u.push(e._signalLabel(o)),o===E?l.dirtyCount++:o===j&&l.resolvedCount++,n&&n(`[${a}] STATE:`,o)):f===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},f=n.get(a);f!==void 0&&(l.annotation=f),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,"_"),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)}`,p=i[o.status??""]??"";s.push(` ${c}["${d}"]${p}`)}for(let o of n.edges){let c=l.get(o.from)??u(o.from),d=l.get(o.to)??u(o.to);s.push(` ${c} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
+ `)}static toD2(t){let 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,"_"),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=i[o.kind]??"rectangle",p=`${o.name} (${o.kind}) = ${f(o.value)}`,S=o.status?` [${o.status}]`:"";s.push(`${c}: "${p}${S}" { 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,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:O()};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()),f=s();return r.push({result:f,depValues:l,timestamp:Date.now()}),f};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(p=>p.get()),c=s(),d=-1;for(let p=0;p<i.length;p++)if(!Object.is(o[p],a[p])){d=p;break}return r.push({result:c,triggerDepIndex:d,triggerDepName:d>=0?e.getName(i[d]):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 J=1,v=64,b=2,$=4,Ee=8,De=16,L=32,D=1024,m=oe,N=ge<<x,W=he<<x,Z=pe<<x,je=me<<x,Fe=Se<<x,We=Te<<x,K=class{_value;_output=null;_flags;get _status(){return _e(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|=$),r?.resetOnTeardown&&(n|=Ee),r?.resubscribable&&(n|=De),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||A.register(this,{kind:"producer",...r})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,r){let n=this._output;if(n)if(this._flags&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&&(O()?this._flags&L||(this._flags|=L,this._flags&$&&(this._flags=this._flags&~m|N,this._dispatch(_,E)),z(()=>{this._flags&=~L,this._flags=this._flags&~m|W,this._dispatch(y,this._value)})):(this._flags&$&&!(this._flags&D)&&(this._flags=this._flags&~m|N,this._dispatch(_,E)),this._flags=this._flags&~m|W,this._dispatch(y,this._value))))}signal(t){this._flags&b||!this._output||(t===E?this._flags=this._flags&~m|N:t===j&&(this._flags=this._flags&~m|We),this._dispatch(_,t))}complete(){if(this._flags&b)return;this._flags=(this._flags|b)&~m|je;let t=this._output,r=this._flags&v;if(this._output=null,this._flags&=~(v|D),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)&~m|Fe;let r=this._output,n=this._flags&v;if(this._output=null,this._flags&=~(v|D),this._singleDepCount=0,this._stop(),r)if(n)for(let s of r)s(g,t);else r(g,t)}_start(){if(this._flags&J||!this._fn)return;this._flags|=J,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&J&&(this._flags&=~J,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Ee&&(this._value=this._initial),this._flags&b||(this._flags=this._flags&~m|Z))}_handleLifecycleSignal(t){if(!(this._flags&b)){if(t===ie){this._onLifecycleSignal?.(t),this.complete();return}t===C&&(this._value=this._initial,this._flags&=~L),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&De&&this._output===null)this._flags=this._flags&~(b|m)|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)&~D}let s=!1;n(h,(i,a)=>{if(i===y&&n(y,this._value),i===_){a===fe&&!s?(s=!0,this._singleDepCount++,this._flags&v||(this._flags|=D)):de(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|=D)):u.size===0&&(this._output=null,this._flags&=~(v|D),this._singleDepCount=0,this._flags=this._flags&~m|Z,this._stop())}else this._output===n&&(this._output=null,this._flags&=~D,this._singleDepCount=0,this._flags=this._flags&~m|Z,this._stop())}}),ve(()=>this._start())}}};function Q(e,t){return new K(e,t)}var ae=class extends K{constructor(t,r){super(void 0,{initial:t,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),A.register(this,{kind:"state",...r})}get(){return this._value}set(t){this._flags&b||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(O()?this._flags&L||(this._flags|=L,this._flags&$&&(this._flags=this._flags&~m|N,this._dispatch(_,E)),z(()=>{this._flags&=~L,this._flags=this._flags&~m|W,this._dispatch(y,this._value)})):(this._flags&$&&!(this._flags&D)&&(this._flags=this._flags&~m|N,this._dispatch(_,E)),this._flags=this._flags&~m|W,this._dispatch(y,this._value))))}update(t){this.set(t(this._value))}};function V(e,t){return new ae(e,t)}function ke(e){return(t,r)=>{if(t!==0)return;let n=new AbortController,s=n.signal,i=!1,a,u;try{a=typeof e=="function"?e():e,u=a[Symbol.asyncIterator]()}catch(f){r(0,()=>{}),r(2,f);return}r(0,f=>{f===2&&!i&&(i=!0,n.abort(),Promise.resolve(u.return?.()).catch(()=>{}))});async function l(){try{for(;!i&&!s.aborted;){let f=await u.next();if(i||s.aborted)break;if(f.done){i=!0,r(2);return}r(1,f.value)}}catch(f){!i&&!s.aborted&&(i=!0,r(2,f))}}l()}}function xe(e){return(t,r)=>{if(t!==0)return;let n=!1;r(0,s=>{s===2&&(n=!0)}),e.then(s=>{n||(r(1,s),n||r(2))},s=>{n||r(2,s)})}}function Ke(e){return e!=null&&typeof e.then=="function"}function Ve(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function Ue(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function ue(e){return Ke(e)?xe(e):Ve(e)?ke(e):typeof e!="string"&&Ue(e)?(t,r)=>{if(t!==0)return;let n=!1;r(0,s=>{s===2&&(n=!0)});for(let s of e){if(n)return;r(1,s)}n||r(2)}:(t,r)=>{if(t!==0)return;let n=!1;r(0,s=>{s===2&&(n=!0)}),n||r(1,e),n||r(2)}}function le(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 we(e,t,r){let n=null;ye(),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 be(),{unsubscribe(){n?.(g),n=null},signal(i){n?.(_,i)}}}function Re(e,t){let r=t?.initialStatus??"pending",n=V(r,{name:"withStatus:status",equals:Object.is}),s=V(void 0,{name:"withStatus:error",equals:Object.is}),i=Q(({emit:u,complete:l,error:f})=>{n.set(r),s.set(void 0);let o=we(e,c=>{n.get()==="errored"?F(()=>{s.set(void 0),n.set("active")}):n.set("active"),u(c)},{onEnd:c=>{if(c!==void 0){let d=c instanceof Error?c:new Error(String(c));F(()=>{s.set(d),n.set("errored")}),f(c)}else n.set("completed"),l()}});return()=>{o.unsubscribe()}},{initial:e.get(),resubscribable:!0}),a={get:()=>e.get(),source:(u,l)=>i.source(u,l),get _status(){return i._status},status:n,error:s};return A.register(a,{kind:"withStatus"}),a}function Ye(e,t){let r=t?.name??"http",n=t?.method??"GET",s=t?.headers,i=t?.body,a=t?.poll??0,u=t?.transform??(w=>w.json()),l=t?.timeout??3e4,f=V(0,{name:`${r}:fetchCount`}),o=null,c=null,d=null,p=null,S=null,k=!1;function U(){if(!k||!o)return;S=new AbortController;let w=[S.signal];t?.signal&&w.push(t.signal);let R=new AbortController;for(let T of w){if(T.aborted){R.abort(T.reason);break}T.addEventListener("abort",()=>R.abort(T.reason),{once:!0})}let I=setTimeout(()=>R.abort(new Error("Request timeout")),l),ee=i!==void 0?typeof i=="string"?i:JSON.stringify(i):void 0;le(ue(fetch(e,{method:n,headers:s,body:ee,signal:R.signal})),T=>{if(!k){clearTimeout(I),S=null;return}if(!T.ok){clearTimeout(I),S=null,c?.(new Error(`HTTP ${T.status}: ${T.statusText}`));return}le(ue(u(T)),M=>{clearTimeout(I),S=null,k&&(F(()=>{f.update(Le=>Le+1),o?.(M)}),ce())},{onEnd:M=>{if(clearTimeout(I),S=null,M!==void 0){if(!k||M?.name==="AbortError")return;c?.(M)}}})},{onEnd:T=>{if(clearTimeout(I),S=null,T!==void 0){if(!k||T?.name==="AbortError")return;c?.(T)}}})}function ce(){!k||P||a<=0||(p=setTimeout(()=>{p=null,U()},a))}let X=null,P=!1,Ae=Q(({emit:w,error:R,complete:I,onSignal:ee})=>(o=w,c=R,d=I,k=!0,P=!1,X=()=>{U()},ee(T=>{T===se?(P=!0,p!==null&&(clearTimeout(p),p=null)):T===re?(P=!1,ce()):T===C&&(S?.abort(),S=null,p!==null&&(clearTimeout(p),p=null),f.set(0),P=!1,U())}),U(),()=>{k=!1,P=!1,o=null,c=null,d=null,X=null,S?.abort(),S=null,p!==null&&(clearTimeout(p),p=null)}),{name:r,kind:"http"}),Y=Re(Ae);return{get:()=>Y.get(),source:(w,R)=>Y.source(w,R),status:Y.status,error:Y.error,fetchCount:f,refetch(){X?.()},stop(){k=!1,S?.abort(),S=null,p!==null&&(clearTimeout(p),p=null),d?.()}}}0&&(module.exports={fromHTTP});
@@ -1 +1 @@
1
- import{a}from"../chunk-ZDGVUX5G.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 fromHTTP};
1
+ import{a}from"../chunk-FJ2VN2O3.js";import"../chunk-5LLYKN4X.js";import"../chunk-GMLWTZFM.js";import"../chunk-O2PONDZT.js";import"../chunk-J2E7GAMR.js";import"../chunk-4ILN4V4C.js";import"../chunk-Q3HIBGHR.js";import"../chunk-EAK2HKAD.js";import"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromHTTP};
@@ -1,16 +1,15 @@
1
- "use strict";var Ue=Object.create;var oe=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty;var Ke=(t,e)=>{for(var r in e)oe(t,r,{get:e[r],enumerable:!0})},Te=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of He(e))!qe.call(t,o)&&o!==r&&oe(t,o,{get:()=>e[o],enumerable:!(n=Be(e,o))||n.enumerable});return t};var ze=(t,e,r)=>(r=t!=null?Ue(Ve(t)):{},Te(e||!t||!t.__esModule?oe(r,"default",{value:t,enumerable:!0}):r,t)),Ye=t=>Te(oe({},"__esModule",{value:!0}),t);var it={};Ke(it,{fromHTTP:()=>Ae,fromLLM:()=>Me,fromMCP:()=>$e,fromWebSocket:()=>je,fromWebhook:()=>Ie,toSSE:()=>Ne,toWebSocket:()=>Fe});module.exports=Ye(it);var j=Symbol("DIRTY"),X=Symbol("RESOLVED"),be=Symbol("SINGLE_DEP"),F=Symbol("RESET"),q=Symbol("PAUSE"),K=Symbol("RESUME"),me=Symbol("TEARDOWN");function ye(t){return t===F||t===q||t===K||t===me}var _e=0,ve=1,ke=2,Ee=3,we=4,xe=5,B=7,he=7<<B,Je=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function Re(t){return Je[(t&he)>>>B]}var D=0,W=1,x=2,M=3,se=0,ie=[],ge=!1;function O(t){se++;try{return t()}finally{if(se--,se===0&&!ge){ge=!0;for(let e=0;e<ie.length;e++)ie[e]();ie.length=0,ge=!1}}}function z(){return se>0}function le(t){ie.push(t)}var ue=0,ae=[];function De(){ue++}function Le(){if(ue--,ue===0){for(let t=0;t<ae.length;t++)ae[t]();ae.length=0}}function Ce(t){ue>0?ae.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(o=>t._names.get(o)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(e){let r=t._keys.get(e)??t._names.get(e);if(r)return r;let n=`anonymous_${t._nextId++}`;return t._keys.set(e,n),n}static register(e,r){if(!t.enabled)return;r?.name&&t._names.set(e,r.name),r?.kind&&t._kinds.set(e,r.kind);let n=t._nextId++,o=r?.name;if(!(o&&!t._usedKeys.has(o)))if(o){let s=t._depSuffix(r?.deps);o=s?`${o}(${s})`:`${o}_${n}`,t._usedKeys.has(o)&&(o=`${o}_${n}`)}else{let s=r?.kind??"store",u=t._depSuffix(r?.deps);o=u?`${s}(${u})`:`${s}_${n}`,t._usedKeys.has(o)&&(o=`${o}_${n}`)}t._usedKeys.add(o),t._keys.set(e,o),t._stores.add(new WeakRef(e))}static registerEdge(e,r){if(!t.enabled)return;let n=t._resolveKey(e),o=t._resolveKey(r),s=t._edges.get(n);s?s.includes(o)||s.push(o):t._edges.set(n,[o])}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,r=new Set;for(let n of t._stores){let o=n.deref();if(!o){t._stores.delete(n);continue}let s=t._resolveKey(o);r.add(s),e.set(s,t.inspect(o))}for(let[n,o]of t._edges){if(!r.has(n)){t._edges.delete(n),t._usedKeys.delete(n);continue}let s=o.filter(u=>r.has(u));s.length===0?t._edges.delete(n):s.length!==o.length&&t._edges.set(n,s)}return e}static trace(e,r){let n=null,o=e.get();return e.source(D,(s,u)=>{if(s===D&&(n=u),s===x){n=null;return}if(s===1){let a=u;if(!Object.is(a,o)){let c=o;o=a,r(a,c)}}}),()=>n?.(x)}static dumpGraph(){let e=t.graph(),r=t.getEdges(),n=new Map;for(let[u,a]of r)for(let c of a){let f=n.get(c);f?f.includes(u)||f.push(u):n.set(c,[u])}let o=[];for(let[u,a]of e){let c=n.get(u),f=r.get(u),i=c?.length?` \u2190 [${c.join(", ")}]`:"",l=f?.length?` \u2192 [${f.join(", ")}]`:"";o.push(` ${u} (${a.kind}) = ${JSON.stringify(a.value)} [${a.status??"?"}]${i}${l}`)}return[`Store Graph (${e.size} nodes):`,...o].join(`
2
- `)}static _signalLabel(e){return e===j?"DIRTY":e===X?"RESOLVED":typeof e=="symbol"?e.description??String(e):String(e)}static _observe(e,r,n){let o=null,s=!1,u=r??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:()=>o?.(x),reconnect:()=>(o?.(x),t._observe(e,r,n))};return e.source(D,(f,i)=>{if(f===D){o=i;return}let l=z();f===W?(c.values.push(i),c.events.push({type:"data",data:i,inBatch:l}),a.push(i),n&&n(`[${u}] DATA:`,i)):f===M?(c.signals.push(i),c.events.push({type:"signal",data:i,inBatch:l}),a.push(t._signalLabel(i)),i===j?c.dirtyCount++:i===X&&c.resolvedCount++,n&&n(`[${u}] STATE:`,i)):f===x&&(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:""),o=null)}),c}static observe(e){return t._observe(e)}static activate(e){let r=null;return e.source(D,(n,o)=>{n===D&&(r=o),n===x&&(r=null)}),()=>r?.(x)}static tap(e,r){let n=r??`tap(${t.getName(e)??"anon"})`,o={get:()=>e.get(),source:e.source};return t.register(o,{name:n,kind:"tap"}),t.registerEdge(e,o),o}static spy(e,r){let n=r?.name??t.getName(e)??"spy",o=r?.log??console.log;return t._observe(e,n,o)}static snapshot(){let e=t.graph(),r=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 o=[];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),o.push(c)}let s=[];for(let[u,a]of r)for(let c of a)s.push({from:u,to:c});return{nodes:o,edges:s,trace:t.traceLog()}}static toMermaid(e){let r=e?.direction??"TD",n=t.snapshot(),o=[`graph ${r}`],s={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},u=new Map;function a(i){let l=i.replace(/[^a-zA-Z0-9_]/g,"_"),g=u.get(l);return g===void 0?(u.set(l,1),l):(u.set(l,g+1),`${l}__${g}`)}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 g=`${i.name} (${i.kind}) = ${f(i.value)}`,m=s[i.status??""]??"";o.push(` ${l}["${g}"]${m}`)}for(let i of n.edges){let l=c.get(i.from)??a(i.from),g=c.get(i.to)??a(i.to);o.push(` ${l} --> ${g}`)}return o.push(""),o.push(" classDef settled fill:#d4edda,stroke:#28a745"),o.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),o.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),o.push(" classDef completed fill:#cce5ff,stroke:#007bff"),o.join(`
3
- `)}static toD2(e){let r=e?.direction??"down",n=t.snapshot(),o=[`direction: ${r}`,""],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,"_"),g=u.get(l);return g===void 0?(u.set(l,1),l):(u.set(l,g+1),`${l}__${g}`)}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 g=s[i.kind]??"rectangle",m=`${i.name} (${i.kind}) = ${f(i.value)}`,b=i.status?` [${i.status}]`:"";o.push(`${l}: "${m}${b}" { shape: ${g} }`)}n.edges.length>0&&o.push("");for(let i of n.edges){let l=c.get(i.from)??a(i.from),g=c.get(i.to)??a(i.to);o.push(`${l} -> ${g}`)}return o.join(`
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
- `);w=E.pop()??"";for(let C of E){if(h.aborted)return;let $=C.trim();if(!$||$.startsWith(":")||!$.startsWith("data: "))continue;let A=$.slice(6);if(A!=="[DONE]")try{let ne=JSON.parse(A),Y=rt(r,ne);Y&&(y+=Y,u.set(y));let re=ot(r,ne);re&&a.set(re)}catch{}}}if(S.decode(),h.aborted)return;c.set("completed"),i=null}catch(d){if(h.aborted)return;O(()=>{f.set(d),c.set("errored")}),i=null}finally{h._cleanup?.()}}return{get:()=>u.get(),source:(b,T)=>u.source(b,T),tokens:a,status:c,error:f,generate:g,abort:l}}function rt(t,e){return t==="ollama"?e?.message?.content:e?.choices?.[0]?.delta?.content}function ot(t,e){let r=t==="ollama"?e:e?.usage;if(r){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(r.prompt_tokens!==void 0||r.completion_tokens!==void 0)return{promptTokens:r.prompt_tokens,completionTokens:r.completion_tokens,totalTokens:r.total_tokens}}}function st(t,e){let r=new AbortController,n=()=>{t.removeEventListener("abort",o),e.removeEventListener("abort",o)},o=()=>{r.abort(),n()};t.addEventListener("abort",o,{once:!0}),e.addEventListener("abort",o,{once:!0});let s=r.signal;return s._cleanup=n,s}function $e(t){let e=t.name??"mcp",r=t.client,n=k([],{name:`${e}.tools`}),o=k([],{name:`${e}.resources`}),s=k(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),r.listTools)try{let f=await r.listTools();n.set(f.tools)}catch(f){u(f)}if(r.listResources)try{let f=await r.listResources();o.set(f.resources)}catch(f){u(f)}}function c(f){let i=`${e}:${f}`,l=k(void 0,{name:`${i}.result`}),g=k("idle",{name:`${i}.status`}),m=k(void 0,{name:`${i}.error`}),b=k(void 0,{name:`${i}.lastArgs`}),T=k(void 0,{name:`${i}.duration`}),R=!1;async function h(d){if(R)return;R=!0,O(()=>{b.set(d),m.set(void 0),g.set("active")});let p=Date.now();try{let S=await r.callTool({name:f,arguments:d}),y=Date.now()-p;if(S.isError){let v=S.content.filter(C=>C.type==="text").map(C=>C.text??"").join(`
6
- `),E=new Error(v||"MCP tool returned error");O(()=>{T.set(y),m.set(E),g.set("errored")});return}let w=S.content.filter(v=>v.type==="text"),_;if(w.length===1){let v=w[0].text;if(v!==void 0)try{_=JSON.parse(v)}catch{_=v}}else w.length>1?_=w.map(v=>v.text??""):_=S.content;O(()=>{T.set(y),l.set(_),g.set("completed")})}catch(S){let y=Date.now()-p;O(()=>{T.set(y),m.set(S),g.set("errored")})}finally{R=!1}}return{get:()=>l.get(),source:(d,p)=>l.source(d,p),status:g,error:m,call:h,lastArgs:b,duration:T}}return{tool:c,tools:n,resources:o,refresh:a,refreshError:s}}function We(t,e,r){let n=null;return t(0,(o,s)=>{if(o===0){n=s;return}if(o===2){n=null,r?.onEnd?.(s);return}o===1&&e(s)}),{unsubscribe(){n?.(2),n=null}}}function de(t,e){return new Promise((r,n)=>{let o=We(t,s=>{(!e||e(s))&&(o.unsubscribe(),r(s))},{onEnd:s=>{n(s??new Error("source completed without matching value"))}})})}function pe(t){return(e,r)=>{if(e!==0)return;let n=!1,o;r(0,s=>{s===2&&!n&&(n=!0,o?.())});try{o=t(s=>{n||(n=!0,r(1,s),r(2))},s=>{n||(n=!0,r(2,s))})}catch(s){n||(n=!0,r(2,s))}}}function Ne(t,e){let r=e?.path??"/",n=e?.name??"sse",o=e?.hostname??"0.0.0.0",s=e?.serialize??JSON.stringify,u=e?.eventName??"message",a=e?.pingInterval??3e4,c=k(0,{name:`${n}:connections`}),f=new Set,i=new Map,l=null;function g(){l||(l=Q(t,d=>{let p=s(d),S=`event: ${u}
1
+ "use strict";var Be=Object.create;var re=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var ze=(e,t)=>{for(var r in t)re(e,r,{get:t[r],enumerable:!0})},he=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ue(t))!Ke.call(e,o)&&o!==r&&re(e,o,{get:()=>t[o],enumerable:!(n=qe(t,o))||n.enumerable});return e};var Ye=(e,t,r)=>(r=e!=null?Be(Ve(e)):{},he(t||!e||!e.__esModule?re(r,"default",{value:e,enumerable:!0}):r,e)),Je=e=>he(re({},"__esModule",{value:!0}),e);var rt={};ze(rt,{fromHTTP:()=>Le,fromMCP:()=>We,fromWebSocket:()=>Me,fromWebhook:()=>Ne,toSSE:()=>$e,toWebSocket:()=>je});module.exports=Je(rt);var M=Symbol("DIRTY"),ee=Symbol("RESOLVED"),Te=Symbol("SINGLE_DEP"),j=Symbol("RESET"),z=Symbol("PAUSE"),Y=Symbol("RESUME"),ge=Symbol("TEARDOWN");function be(e){return e===j||e===z||e===Y||e===ge}var ye=0,_e=1,ve=2,Ee=3,ke=4,we=5,q=7,me=7<<q,Ge=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function xe(e){return Ge[(e&me)>>>q]}var R=0,I=1,w=2,P=3,oe=0,se=[],pe=!1;function F(e){oe++;try{return e()}finally{if(oe--,oe===0&&!pe){pe=!0;for(let t=0;t<se.length;t++)se[t]();se.length=0,pe=!1}}}function J(){return oe>0}function ue(e){se.push(e)}var ae=0,ie=[];function Re(){ae++}function De(){if(ae--,ae===0){for(let e=0;e<ie.length;e++)ie[e]();ie.length=0}}function Ce(e){ae>0?ie.push(e):e()}var A=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let n=t.map(o=>e._names.get(o)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(t){let r=e._keys.get(t)??e._names.get(t);if(r)return r;let n=`anonymous_${e._nextId++}`;return e._keys.set(t,n),n}static register(t,r){if(!e.enabled)return;r?.name&&e._names.set(t,r.name),r?.kind&&e._kinds.set(t,r.kind);let n=e._nextId++,o=r?.name;if(!(o&&!e._usedKeys.has(o)))if(o){let s=e._depSuffix(r?.deps);o=s?`${o}(${s})`:`${o}_${n}`,e._usedKeys.has(o)&&(o=`${o}_${n}`)}else{let s=r?.kind??"store",u=e._depSuffix(r?.deps);o=u?`${s}(${u})`:`${s}_${n}`,e._usedKeys.has(o)&&(o=`${o}_${n}`)}e._usedKeys.add(o),e._keys.set(t,o),e._stores.add(new WeakRef(t))}static registerEdge(t,r){if(!e.enabled)return;let n=e._resolveKey(t),o=e._resolveKey(r),s=e._edges.get(n);s?s.includes(o)||s.push(o):e._edges.set(n,[o])}static getEdges(){return new Map(e._edges)}static getName(t){if(e.enabled)return e._names.get(t)}static getKind(t){return e._kinds.get(t)}static inspect(t){return{name:e._names.get(t),kind:e._kinds.get(t)??"unknown",value:typeof t.get=="function"?t.get():void 0,status:t._status}}static graph(){let t=new Map,r=new Set;for(let n of e._stores){let o=n.deref();if(!o){e._stores.delete(n);continue}let s=e._resolveKey(o);r.add(s),t.set(s,e.inspect(o))}for(let[n,o]of e._edges){if(!r.has(n)){e._edges.delete(n),e._usedKeys.delete(n);continue}let s=o.filter(u=>r.has(u));s.length===0?e._edges.delete(n):s.length!==o.length&&e._edges.set(n,s)}return t}static trace(t,r){let n=null,o=t.get();return t.source(R,(s,u)=>{if(s===R&&(n=u),s===w){n=null;return}if(s===1){let i=u;if(!Object.is(i,o)){let f=o;o=i,r(i,f)}}}),()=>n?.(w)}static dumpGraph(){let t=e.graph(),r=e.getEdges(),n=new Map;for(let[u,i]of r)for(let f of i){let c=n.get(f);c?c.includes(u)||c.push(u):n.set(f,[u])}let o=[];for(let[u,i]of t){let f=n.get(u),c=r.get(u),a=f?.length?` \u2190 [${f.join(", ")}]`:"",l=c?.length?` \u2192 [${c.join(", ")}]`:"";o.push(` ${u} (${i.kind}) = ${JSON.stringify(i.value)} [${i.status??"?"}]${a}${l}`)}return[`Store Graph (${t.size} nodes):`,...o].join(`
2
+ `)}static _signalLabel(t){return t===M?"DIRTY":t===ee?"RESOLVED":typeof t=="symbol"?t.description??String(t):String(t)}static _observe(t,r,n){let o=null,s=!1,u=r??e.getName(t),i=[],f={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return f.ended&&!s},get errored(){return f.ended&&s},dirtyCount:0,resolvedCount:0,name:u,get eventLog(){return i},dispose:()=>o?.(w),reconnect:()=>(o?.(w),e._observe(t,r,n))};return t.source(R,(c,a)=>{if(c===R){o=a;return}let l=J();c===I?(f.values.push(a),f.events.push({type:"data",data:a,inBatch:l}),i.push(a),n&&n(`[${u}] DATA:`,a)):c===P?(f.signals.push(a),f.events.push({type:"signal",data:a,inBatch:l}),i.push(e._signalLabel(a)),a===M?f.dirtyCount++:a===ee&&f.resolvedCount++,n&&n(`[${u}] STATE:`,a)):c===w&&(f.ended=!0,f.endError=a,s=a!==void 0,f.events.push({type:"end",data:a,inBatch:l}),i.push(s?["END",a]:"END"),n&&n(`[${u}] END`,a!==void 0?a:""),o=null)}),f}static observe(t){return e._observe(t)}static activate(t){let r=null;return t.source(R,(n,o)=>{n===R&&(r=o),n===w&&(r=null)}),()=>r?.(w)}static tap(t,r){let n=r??`tap(${e.getName(t)??"anon"})`,o={get:()=>t.get(),source:t.source};return e.register(o,{name:n,kind:"tap"}),e.registerEdge(t,o),o}static spy(t,r){let n=r?.name??e.getName(t)??"spy",o=r?.log??console.log;return e._observe(t,n,o)}static snapshot(){let t=e.graph(),r=e.getEdges(),n=new Map;for(let u of e._stores){let i=u.deref();if(!i)continue;let f=e._annotations.get(i);f!==void 0&&n.set(e._resolveKey(i),f)}let o=[];for(let[u,i]of t){let f={name:u,kind:i.kind,value:i.value,status:i.status},c=n.get(u);c!==void 0&&(f.annotation=c),o.push(f)}let s=[];for(let[u,i]of r)for(let f of i)s.push({from:u,to:f});return{nodes:o,edges:s,trace:e.traceLog()}}static toMermaid(t){let r=t?.direction??"TD",n=e.snapshot(),o=[`graph ${r}`],s={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},u=new Map;function i(a){let l=a.replace(/[^a-zA-Z0-9_]/g,"_"),g=u.get(l);return g===void 0?(u.set(l,1),l):(u.set(l,g+1),`${l}__${g}`)}let f=new Map;function c(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=i(a.name);f.set(a.name,l);let g=`${a.name} (${a.kind}) = ${c(a.value)}`,m=s[a.status??""]??"";o.push(` ${l}["${g}"]${m}`)}for(let a of n.edges){let l=f.get(a.from)??i(a.from),g=f.get(a.to)??i(a.to);o.push(` ${l} --> ${g}`)}return o.push(""),o.push(" classDef settled fill:#d4edda,stroke:#28a745"),o.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),o.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),o.push(" classDef completed fill:#cce5ff,stroke:#007bff"),o.join(`
3
+ `)}static toD2(t){let r=t?.direction??"down",n=e.snapshot(),o=[`direction: ${r}`,""],s={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},u=new Map;function i(a){let l=a.replace(/[^a-zA-Z0-9_]/g,"_"),g=u.get(l);return g===void 0?(u.set(l,1),l):(u.set(l,g+1),`${l}__${g}`)}let f=new Map;function c(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=i(a.name);f.set(a.name,l);let g=s[a.kind]??"rectangle",m=`${a.name} (${a.kind}) = ${c(a.value)}`,T=a.status?` [${a.status}]`:"";o.push(`${l}: "${m}${T}" { shape: ${g} }`)}n.edges.length>0&&o.push("");for(let a of n.edges){let l=f.get(a.from)??i(a.from),g=f.get(a.to)??i(a.to);o.push(`${l} -> ${g}`)}return o.join(`
4
+ `)}static annotate(t,r){if(!e.enabled)return;e._annotations.set(t,r);let n={node:e._resolveKey(t),reason:r,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(n):(e._traceLog[e._traceHead]=n,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static timeline(t){let r=null,n=[];return t.source(R,(o,s)=>{if(o===R){r=s;return}let u={timestamp:Date.now(),type:o===I?"data":o===P?"signal":"end",data:s,inBatch:J()};n.push(u),o===w&&(r=null)}),{entries:n,dispose:()=>r?.(w)}}static observeDerived(t){let r=[],n=t,o=n._fn;if(typeof o!="function"||!Array.isArray(n._deps))return{...e.observe(t),evaluations:r};n._fn=()=>{let f=n._deps.map(a=>a.get()),c=o();return r.push({result:c,depValues:f,timestamp:Date.now()}),c};let s=e._observe(t),u=s.dispose;return{...s,evaluations:r,dispose:()=>{n._fn=o,u()},reconnect:()=>(n._fn=o,u(),e.observeDerived(t))}}static observeTaskState(t){let r=t.status.get(),n=[],o=null;return t.status.source(R,(s,u)=>{if(s===R){o=u;return}if(s===I){let i=u;if(i!==r){let f={from:r,to:i,timestamp:Date.now()};i==="error"&&(f.error=t.error.get()),n.push(f),r=i}}s===w&&(o=null)}),{transitions:n,get currentStatus(){return t.status.get()},dispose:()=>{o?.(w)}}}static causalityTrace(t){let r=[],n=t,o=n._fn;if(typeof o!="function"||!Array.isArray(n._deps))return{...e.observe(t),causality:r};let s=n._deps,u=s.map(a=>a.get());n._fn=()=>{let a=s.map(m=>m.get()),l=o(),g=-1;for(let m=0;m<s.length;m++)if(!Object.is(a[m],u[m])){g=m;break}return r.push({result:l,triggerDepIndex:g,triggerDepName:g>=0?e.getName(s[g]):void 0,depValues:a,timestamp:Date.now()}),u=a,l};let i=e._observe(t),f=i.dispose;return{...i,causality:r,dispose:()=>{n._fn=o,f()},reconnect:()=>(n._fn=o,f(),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 le=1,$=64,L=2,G=4,Ae=8,Oe=16,V=32,H=1024,C=me,Q=_e<<q,te=ve<<q,ce=ye<<q,Qe=ke<<q,Ze=we<<q,Xe=Ee<<q,ne=class{_value;_output=null;_flags;get _status(){return xe(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|=G),r?.resetOnTeardown&&(n|=Ae),r?.resubscribable&&(n|=Oe),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||A.register(this,{kind:"producer",...r})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,r){let n=this._output;if(n)if(this._flags&$)for(let o of n)o(t,r);else n(t,r)}emit(t){this._flags&L||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(J()?this._flags&V||(this._flags|=V,this._flags&G&&(this._flags=this._flags&~C|Q,this._dispatch(P,M)),ue(()=>{this._flags&=~V,this._flags=this._flags&~C|te,this._dispatch(I,this._value)})):(this._flags&G&&!(this._flags&H)&&(this._flags=this._flags&~C|Q,this._dispatch(P,M)),this._flags=this._flags&~C|te,this._dispatch(I,this._value))))}signal(t){this._flags&L||!this._output||(t===M?this._flags=this._flags&~C|Q:t===ee&&(this._flags=this._flags&~C|Xe),this._dispatch(P,t))}complete(){if(this._flags&L)return;this._flags=(this._flags|L)&~C|Qe;let t=this._output,r=this._flags&$;if(this._output=null,this._flags&=~($|H),this._singleDepCount=0,this._stop(),t)if(r)for(let n of t)n(w);else t(w)}error(t){if(this._flags&L)return;this._flags=(this._flags|L)&~C|Ze;let r=this._output,n=this._flags&$;if(this._output=null,this._flags&=~($|H),this._singleDepCount=0,this._stop(),r)if(n)for(let o of r)o(w,t);else r(w,t)}_start(){if(this._flags&le||!this._fn)return;this._flags|=le,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&le&&(this._flags&=~le,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Ae&&(this._value=this._initial),this._flags&L||(this._flags=this._flags&~C|ce))}_handleLifecycleSignal(t){if(!(this._flags&L)){if(t===ge){this._onLifecycleSignal?.(t),this.complete();return}t===j&&(this._value=this._initial,this._flags&=~V),this._onLifecycleSignal?.(t),t===j&&this.emit(this._initial)}}source(t,r){if(t===R){let n=r;if(this._flags&L)if(this._flags&Oe&&this._output===null)this._flags=this._flags&~(L|C)|ce;else{n(R,s=>{}),n(w);return}if(this._output===null)this._output=n;else if(this._flags&$)this._output.add(n);else{let s=new Set;s.add(this._output),s.add(n),this._output=s,this._flags=(this._flags|$)&~H}let o=!1;n(R,(s,u)=>{if(s===I&&n(I,this._value),s===P){u===Te&&!o?(o=!0,this._singleDepCount++,this._flags&$||(this._flags|=H)):be(u)&&this._handleLifecycleSignal(u);return}if(s===w){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&$){let i=this._output;i.delete(n),i.size===1?(this._output=i.values().next().value,this._flags&=~$,this._singleDepCount>0&&(this._flags|=H)):i.size===0&&(this._output=null,this._flags&=~($|H),this._singleDepCount=0,this._flags=this._flags&~C|ce,this._stop())}else this._output===n&&(this._output=null,this._flags&=~H,this._singleDepCount=0,this._flags=this._flags&~C|ce,this._stop())}}),Ce(()=>this._start())}}};function K(e,t){return new ne(e,t)}var Se=class extends ne{constructor(t,r){super(void 0,{initial:t,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),A.register(this,{kind:"state",...r})}get(){return this._value}set(t){this._flags&L||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(J()?this._flags&V||(this._flags|=V,this._flags&G&&(this._flags=this._flags&~C|Q,this._dispatch(P,M)),ue(()=>{this._flags&=~V,this._flags=this._flags&~C|te,this._dispatch(I,this._value)})):(this._flags&G&&!(this._flags&H)&&(this._flags=this._flags&~C|Q,this._dispatch(P,M)),this._flags=this._flags&~C|te,this._dispatch(I,this._value))))}update(t){this.set(t(this._value))}};function x(e,t){return new Se(e,t)}function Pe(e){return(t,r)=>{if(t!==0)return;let n=new AbortController,o=n.signal,s=!1,u,i;try{u=typeof e=="function"?e():e,i=u[Symbol.asyncIterator]()}catch(c){r(0,()=>{}),r(2,c);return}r(0,c=>{c===2&&!s&&(s=!0,n.abort(),Promise.resolve(i.return?.()).catch(()=>{}))});async function f(){try{for(;!s&&!o.aborted;){let c=await i.next();if(s||o.aborted)break;if(c.done){s=!0,r(2);return}r(1,c.value)}}catch(c){!s&&!o.aborted&&(s=!0,r(2,c))}}f()}}function Ie(e){return(t,r)=>{if(t!==0)return;let n=!1;r(0,o=>{o===2&&(n=!0)}),e.then(o=>{n||(r(1,o),n||r(2))},o=>{n||r(2,o)})}}function et(e){return e!=null&&typeof e.then=="function"}function tt(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function nt(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function U(e){return et(e)?Ie(e):tt(e)?Pe(e):typeof e!="string"&&nt(e)?(t,r)=>{if(t!==0)return;let n=!1;r(0,o=>{o===2&&(n=!0)});for(let o of e){if(n)return;r(1,o)}n||r(2)}:(t,r)=>{if(t!==0)return;let n=!1;r(0,o=>{o===2&&(n=!0)}),n||r(1,e),n||r(2)}}function B(e,t,r){let n=null;return e(0,(o,s)=>{if(o===0){n=s;return}if(o===2){n=null,r?.onEnd?.(s);return}o===1&&t(s)}),{unsubscribe(){n?.(2),n=null}}}function Z(e,t,r){let n=null;Re(),e.source(R,(s,u)=>{if(s===R&&(n=u),s===w){n=null,r?.onEnd?.(u);return}if(s===1){let i=u,f=o;o=i,t(i,f)}});let o;try{o=e.get()}catch{}return De(),{unsubscribe(){n?.(w),n=null},signal(s){n?.(P,s)}}}function X(e,t){let r=t?.initialStatus??"pending",n=x(r,{name:"withStatus:status",equals:Object.is}),o=x(void 0,{name:"withStatus:error",equals:Object.is}),s=K(({emit:i,complete:f,error:c})=>{n.set(r),o.set(void 0);let a=Z(e,l=>{n.get()==="errored"?F(()=>{o.set(void 0),n.set("active")}):n.set("active"),i(l)},{onEnd:l=>{if(l!==void 0){let g=l instanceof Error?l:new Error(String(l));F(()=>{o.set(g),n.set("errored")}),c(l)}else n.set("completed"),f()}});return()=>{a.unsubscribe()}},{initial:e.get(),resubscribable:!0}),u={get:()=>e.get(),source:(i,f)=>s.source(i,f),get _status(){return s._status},status:n,error:o};return A.register(u,{kind:"withStatus"}),u}function Le(e,t){let r=t?.name??"http",n=t?.method??"GET",o=t?.headers,s=t?.body,u=t?.poll??0,i=t?.transform??(E=>E.json()),f=t?.timeout??3e4,c=x(0,{name:`${r}:fetchCount`}),a=null,l=null,g=null,m=null,T=null,_=!1;function D(){if(!_||!a)return;T=new AbortController;let E=[T.signal];t?.signal&&E.push(t.signal);let v=new AbortController;for(let k of E){if(k.aborted){v.abort(k.reason);break}k.addEventListener("abort",()=>v.abort(k.reason),{once:!0})}let y=setTimeout(()=>v.abort(new Error("Request timeout")),f),O=s!==void 0?typeof s=="string"?s:JSON.stringify(s):void 0;B(U(fetch(e,{method:n,headers:o,body:O,signal:v.signal})),k=>{if(!_){clearTimeout(y),T=null;return}if(!k.ok){clearTimeout(y),T=null,l?.(new Error(`HTTP ${k.status}: ${k.statusText}`));return}B(U(i(k)),W=>{clearTimeout(y),T=null,_&&(F(()=>{c.update(N=>N+1),a?.(W)}),h())},{onEnd:W=>{if(clearTimeout(y),T=null,W!==void 0){if(!_||W?.name==="AbortError")return;l?.(W)}}})},{onEnd:k=>{if(clearTimeout(y),T=null,k!==void 0){if(!_||k?.name==="AbortError")return;l?.(k)}}})}function h(){!_||p||u<=0||(m=setTimeout(()=>{m=null,D()},u))}let d=null,p=!1,S=K(({emit:E,error:v,complete:y,onSignal:O})=>(a=E,l=v,g=y,_=!0,p=!1,d=()=>{D()},O(k=>{k===z?(p=!0,m!==null&&(clearTimeout(m),m=null)):k===Y?(p=!1,h()):k===j&&(T?.abort(),T=null,m!==null&&(clearTimeout(m),m=null),c.set(0),p=!1,D())}),D(),()=>{_=!1,p=!1,a=null,l=null,g=null,d=null,T?.abort(),T=null,m!==null&&(clearTimeout(m),m=null)}),{name:r,kind:"http"}),b=X(S);return{get:()=>b.get(),source:(E,v)=>b.source(E,v),status:b.status,error:b.error,fetchCount:c,refetch(){d?.()},stop(){_=!1,T?.abort(),T=null,m!==null&&(clearTimeout(m),m=null),g?.()}}}function We(e){let t=e.name??"mcp",r=e.client,n=x([],{name:`${t}.tools`}),o=x([],{name:`${t}.resources`}),s=x(void 0,{name:`${t}.refreshError`});function u(c){s.set(c);let a=e.onRefreshError;if(a==="warn")console.warn(`[${t}] refresh error:`,c);else{if(a==="error")throw c;typeof a=="function"&&a(c)}}function i(){s.set(void 0),r.listTools&&B(U(r.listTools()),c=>{n.set(c.tools)},{onEnd:c=>{c!==void 0&&u(c)}}),r.listResources&&B(U(r.listResources()),c=>{o.set(c.resources)},{onEnd:c=>{c!==void 0&&u(c)}})}function f(c){let a=`${t}:${c}`,l=x(void 0,{name:`${a}.result`}),g=x("idle",{name:`${a}.status`}),m=x(void 0,{name:`${a}.error`}),T=x(void 0,{name:`${a}.lastArgs`}),_=x(void 0,{name:`${a}.duration`}),D=!1;function h(d){if(D)return;D=!0,F(()=>{T.set(d),m.set(void 0),g.set("active")});let p=Date.now();B(U(r.callTool({name:c,arguments:d})),S=>{D=!1;let b=Date.now()-p;if(S.isError){let y=S.content.filter(k=>k.type==="text").map(k=>k.text??"").join(`
5
+ `),O=new Error(y||"MCP tool returned error");F(()=>{_.set(b),m.set(O),g.set("errored")});return}let E=S.content.filter(y=>y.type==="text"),v;if(E.length===1){let y=E[0].text;if(y!==void 0)try{v=JSON.parse(y)}catch{v=y}}else E.length>1?v=E.map(y=>y.text??""):v=S.content;F(()=>{_.set(b),l.set(v),g.set("completed")})},{onEnd:S=>{if(D=!1,S===void 0)return;let b=Date.now()-p;F(()=>{_.set(b),m.set(S),g.set("errored")})}})}return{get:()=>l.get(),source:(d,p)=>l.source(d,p),status:g,error:m,call:h,lastArgs:T,duration:_}}return{tool:f,tools:n,resources:o,refresh:i,refreshError:s}}function fe(e){return(t,r)=>{if(t!==0)return;let n=!1,o;r(0,s=>{s===2&&!n&&(n=!0,o?.())});try{o=e(s=>{n||(n=!0,r(1,s),r(2))},s=>{n||(n=!0,r(2,s))})}catch(s){n||(n=!0,r(2,s))}}}function $e(e,t){let r=t?.path??"/",n=t?.name??"sse",o=t?.hostname??"0.0.0.0",s=t?.serialize??JSON.stringify,u=t?.eventName??"message",i=t?.pingInterval??3e4,f=x(0,{name:`${n}:connections`}),c=new Set,a=new Map,l=null;function g(){l||(l=Z(e,d=>{let p=s(d),S=`event: ${u}
7
6
  data: ${p}
8
7
 
9
- `;for(let y of f)try{y.write(S)}catch{m(y)}}))}function m(d){f.delete(d);let p=i.get(d);p&&(clearInterval(p),i.delete(d)),c.set(f.size),f.size===0&&l&&(l.unsubscribe(),l=null)}function b(d,p){let S=d.method?.toUpperCase();if((d.url??"/").split("?")[0]!==r){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}if(S==="OPTIONS"){p.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),p.end();return}if(S!=="GET"){p.writeHead(405,{"Content-Type":"text/plain"}),p.end("Method not allowed");return}p.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),p.write(`:ok
8
+ `;for(let b of c)try{b.write(S)}catch{m(b)}}))}function m(d){c.delete(d);let p=a.get(d);p&&(clearInterval(p),a.delete(d)),f.set(c.size),c.size===0&&l&&(l.unsubscribe(),l=null)}function T(d,p){let S=d.method?.toUpperCase();if((d.url??"/").split("?")[0]!==r){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}if(S==="OPTIONS"){p.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),p.end();return}if(S!=="GET"){p.writeHead(405,{"Content-Type":"text/plain"}),p.end("Method not allowed");return}p.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),p.write(`:ok
10
9
 
11
- `),f.add(p),c.set(f.size);try{let _=t.get();if(_!==void 0){let v=s(_);p.write(`event: ${u}
12
- data: ${v}
10
+ `),c.add(p),f.set(c.size);try{let v=e.get();if(v!==void 0){let y=s(v);p.write(`event: ${u}
11
+ data: ${y}
13
12
 
14
- `)}}catch{}if(a>0){let _=setInterval(()=>{try{p.write(`:ping
13
+ `)}}catch{}if(i>0){let v=setInterval(()=>{try{p.write(`:ping
15
14
 
16
- `)}catch{m(p)}},a);i.set(p,_)}d.on("close",()=>m(p)),g()}let T=null;async function R(){if(!e?.port)throw new Error("toSSE: port is required for listen()");if(T)throw new Error("toSSE: already listening. Call close() first.");let d=await import("http");return de(pe((p,S)=>{T=d.createServer(b),T.once("listening",()=>p()),T.once("error",y=>{T=null,S(y)}),T.listen(e.port,o)}))}function h(){for(let d of f)try{d.end()}catch{}f.clear();for(let d of i.values())clearInterval(d);i.clear(),c.set(0),l?.unsubscribe(),l=null,T?.close(),T=null}return P.register(c,{kind:"sse"}),{connectionCount:c,handler:b,listen:R,close:h}}function Ie(t){let e=t?.path??"/",r=t?.parse??JSON.parse,n=t?.name??"webhook",o=t?.hostname??"0.0.0.0",s=t?.maxBodySize??1024*1024,u=t?.responseTimeout??3e4,a=k(0,{name:`${n}:count`}),c=null,f=!1,i=V(({emit:h,onSignal:d})=>(c=h,f=!1,d(p=>{p===q?f=!0:p===K?f=!1:p===F&&(f=!1,a.set(0))}),()=>{c=null,f=!1}),{name:n,kind:"webhook"});P.register(i,{kind:"webhook"});let l=Z(i),g=null,m=new Set;function b(h,d){let p=h.method?.toUpperCase(),y=(h.url??"/").split("?")[0];if(p!=="POST"||y!==e){d.writeHead(404,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Not found"}));return}if(f){d.writeHead(503,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Service paused"}));return}let w=[],_=0,v=!1;h.on("error",()=>{v=!0,d.headersSent||(d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Request aborted"})))}),h.on("data",E=>{if(!v){if(_+=E.length,_>s){v=!0,d.writeHead(413,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Payload too large"})),h.destroy?.();return}w.push(E)}}),h.on("end",()=>{if(!v)try{let E=Buffer.concat(w).toString("utf-8"),C=E.length>0?r(E):void 0;a.update(Y=>Y+1);let $=!1,A=null,ne={body:C,get responded(){return $},respond(Y,re=200){$||($=!0,A!==null&&(clearTimeout(A),m.delete(A),A=null),d.writeHead(re,{"Content-Type":"application/json"}),d.end(JSON.stringify(Y)))}};A=setTimeout(()=>{m.delete(A),A=null,$||($=!0,d.writeHead(504,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Response timeout"})))},u),m.add(A),c?.(ne)}catch(E){d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:E?.message??"Parse error"}))}})}function T(){return t?.port?g?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):de(pe((h,d)=>{try{g=require("http").createServer(b),g.once("listening",()=>h()),g.once("error",S=>{g=null,d(S)}),g.listen(t.port,o);return}catch(p){d(p);return}})):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function R(){for(let h of m)clearTimeout(h);m.clear(),g?.close(),g=null}return{get:()=>l.get(),source:(h,d)=>l.source(h,d),status:l.status,error:l.error,requestCount:a,handler:b,listen:T,close:R}}function je(t,e){let r=e?.name??"websocket",n=e?.parse??(S=>S),o=e?.reconnect??!1,s=e?.onParseError??"warn",u=k("connecting",{name:`${r}:connectionState`,equals:()=>!1}),a=null,c=null,f=null,i=null,l=null,g=!1,m=null,b=[];function T(){for(;b.length>0&&a?.readyState===WebSocket.OPEN;)a.send(b.shift())}function R(){g=!1,u.set("connecting");try{a=new WebSocket(t,e?.protocols)}catch(S){u.set("closed"),f?.(S);return}a.onopen=()=>{u.set("open"),T()},a.onmessage=S=>{if(!h)try{let y=n(S.data);c?.(y)}catch(y){s==="error"?f?.(y):s==="warn"&&console.warn(`[${r}] parse error:`,y)}},a.onerror=()=>{m=new Error(`WebSocket error on ${t}`)},a.onclose=()=>{u.set("closed"),a=null;let S=m;m=null,!g&&o!==!1?l=setTimeout(()=>{l=null,c&&R()},o):S&&!g?f?.(S):i?.()}}let h=!1,d=V(({emit:S,error:y,complete:w,onSignal:_})=>(c=S,f=y,i=w,h=!1,R(),_(v=>{v===q?h=!0:v===K?h=!1:v===F&&(h=!1,b.length=0,l!==null&&(clearTimeout(l),l=null),a&&(g=!0,a.onopen=null,a.onmessage=null,a.onerror=null,a.onclose=null,a.close(),a=null),u.set("closed"),R())}),()=>{c=null,f=null,i=null,h=!1,g=!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:r,kind:"websocket"});P.register(d,{kind:"websocket"});let p=Z(d);return{get:()=>p.get(),source:(S,y)=>p.source(S,y),status:p.status,error:p.error,connectionState:u,send(S){a?.readyState===WebSocket.OPEN?a.send(S):b.push(S)},close(S,y){g=!0,b.length=0,l!==null&&(clearTimeout(l),l=null),a?.close(S,y)}}}function Fe(t,e,r){let n=u=>typeof u=="string"?u:JSON.stringify(u),o=r?.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 Q(e,u=>{try{let a=o(u);s(a)}catch{}})}0&&(module.exports={fromHTTP,fromLLM,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
15
+ `)}catch{m(p)}},i);a.set(p,v)}d.on("close",()=>m(p)),g()}let _=null;function D(){return t?.port?_?(d,p)=>{d===0&&(p(0,()=>{}),p(2,new Error("toSSE: already listening. Call close() first.")))}:(d,p)=>{if(d!==0)return;let S=!1;p(0,b=>{b===2&&(S=!0)}),B(U(import("http")),b=>{S||B(fe((E,v)=>{_=b.createServer(T),_.once("listening",()=>E()),_.once("error",y=>{_=null,v(y)}),_.listen(t.port,o)}),()=>{S||(p(1,void 0),p(2))},{onEnd:E=>{E!==void 0&&!S&&p(2,E)}})})}:(d,p)=>{d===0&&(p(0,()=>{}),p(2,new Error("toSSE: port is required for listen()")))}}function h(){for(let d of c)try{d.end()}catch{}c.clear();for(let d of a.values())clearInterval(d);a.clear(),f.set(0),l?.unsubscribe(),l=null,_?.close(),_=null}return A.register(f,{kind:"sse"}),{connectionCount:f,handler:T,listen:D,close:h}}function Ne(e){let t=e?.path??"/",r=e?.parse??JSON.parse,n=e?.name??"webhook",o=e?.hostname??"0.0.0.0",s=e?.maxBodySize??1024*1024,u=e?.responseTimeout??3e4,i=x(0,{name:`${n}:count`}),f=null,c=!1,a=K(({emit:h,onSignal:d})=>(f=h,c=!1,d(p=>{p===z?c=!0:p===Y?c=!1:p===j&&(c=!1,i.set(0))}),()=>{f=null,c=!1}),{name:n,kind:"webhook"});A.register(a,{kind:"webhook"});let l=X(a),g=null,m=new Set;function T(h,d){let p=h.method?.toUpperCase(),b=(h.url??"/").split("?")[0];if(p!=="POST"||b!==t){d.writeHead(404,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Not found"}));return}if(c){d.writeHead(503,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Service paused"}));return}let E=[],v=0,y=!1;h.on("error",()=>{y=!0,d.headersSent||(d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Request aborted"})))}),h.on("data",O=>{if(!y){if(v+=O.length,v>s){y=!0,d.writeHead(413,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Payload too large"})),h.destroy?.();return}E.push(O)}}),h.on("end",()=>{if(!y)try{let O=Buffer.concat(E).toString("utf-8"),k=O.length>0?r(O):void 0;i.update(de=>de+1);let W=!1,N=null,Fe={body:k,get responded(){return W},respond(de,He=200){W||(W=!0,N!==null&&(clearTimeout(N),m.delete(N),N=null),d.writeHead(He,{"Content-Type":"application/json"}),d.end(JSON.stringify(de)))}};N=setTimeout(()=>{m.delete(N),N=null,W||(W=!0,d.writeHead(504,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Response timeout"})))},u),m.add(N),f?.(Fe)}catch(O){d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:O?.message??"Parse error"}))}})}function _(){return e?.port?g?(h,d)=>{h===0&&(d(0,()=>{}),d(2,new Error("fromWebhook: already listening. Call close() first.")))}:fe((h,d)=>{try{g=require("http").createServer(T),g.once("listening",()=>h()),g.once("error",S=>{g=null,d(S)}),g.listen(e.port,o);return}catch(p){d(p);return}}):(h,d)=>{h===0&&(d(0,()=>{}),d(2,new Error("fromWebhook: port is required for listen()")))}}function D(){for(let h of m)clearTimeout(h);m.clear(),g?.close(),g=null}return{get:()=>l.get(),source:(h,d)=>l.source(h,d),status:l.status,error:l.error,requestCount:i,handler:T,listen:_,close:D}}function Me(e,t){let r=t?.name??"websocket",n=t?.parse??(S=>S),o=t?.reconnect??!1,s=t?.onParseError??"warn",u=x("connecting",{name:`${r}:connectionState`,equals:()=>!1}),i=null,f=null,c=null,a=null,l=null,g=!1,m=null,T=[];function _(){for(;T.length>0&&i?.readyState===WebSocket.OPEN;)i.send(T.shift())}function D(){g=!1,u.set("connecting");try{i=new WebSocket(e,t?.protocols)}catch(S){u.set("closed"),c?.(S);return}i.onopen=()=>{u.set("open"),_()},i.onmessage=S=>{if(!h)try{let b=n(S.data);f?.(b)}catch(b){s==="error"?c?.(b):s==="warn"&&console.warn(`[${r}] parse error:`,b)}},i.onerror=()=>{m=new Error(`WebSocket error on ${e}`)},i.onclose=()=>{u.set("closed"),i=null;let S=m;m=null,!g&&o!==!1?l=setTimeout(()=>{l=null,f&&D()},o):S&&!g?c?.(S):a?.()}}let h=!1,d=K(({emit:S,error:b,complete:E,onSignal:v})=>(f=S,c=b,a=E,h=!1,D(),v(y=>{y===z?h=!0:y===Y?h=!1:y===j&&(h=!1,T.length=0,l!==null&&(clearTimeout(l),l=null),i&&(g=!0,i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(),i=null),u.set("closed"),D())}),()=>{f=null,c=null,a=null,h=!1,g=!0,T.length=0,l!==null&&(clearTimeout(l),l=null),i&&(i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(),i=null),u.set("closed")}),{name:r,kind:"websocket"});A.register(d,{kind:"websocket"});let p=X(d);return{get:()=>p.get(),source:(S,b)=>p.source(S,b),status:p.status,error:p.error,connectionState:u,send(S){i?.readyState===WebSocket.OPEN?i.send(S):T.push(S)},close(S,b){g=!0,T.length=0,l!==null&&(clearTimeout(l),l=null),i?.close(S,b)}}}function je(e,t,r){let n=u=>typeof u=="string"?u:JSON.stringify(u),o=r?.serialize??n,s="send"in e&&typeof e.send=="function"?e.send.bind(e):null;if(!s)throw new Error("toWebSocket: invalid WebSocket target");return Z(t,u=>{try{let i=o(u);s(i)}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';
@@ -7,3 +6,4 @@ export { FromWebSocketOptions, ToWebSocketOptions, WebSocketConnectionState, Web
7
6
  import '../types-BohB8jJr.cjs';
8
7
  import '../protocol-fwiQ1TAS.cjs';
9
8
  import '../withStatus-ByT_R2Rz.cjs';
9
+ import '../subscribe-BHH8VVDm.cjs';
@@ -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';
@@ -7,3 +6,4 @@ export { FromWebSocketOptions, ToWebSocketOptions, WebSocketConnectionState, Web
7
6
  import '../types-CB1htCM8.js';
8
7
  import '../protocol-fwiQ1TAS.js';
9
8
  import '../withStatus---CFNir7.js';
9
+ import '../subscribe-BHH8VVDm.js';
@@ -1 +1 @@
1
- import{a as o}from"../chunk-ZDGVUX5G.js";import{a as e}from"../chunk-7WPMCM7F.js";import{a as t}from"../chunk-Q5DHO5II.js";import{a as r}from"../chunk-NYLNL2Y5.js";import{a as p}from"../chunk-JLWDE534.js";import"../chunk-XEU7KSEO.js";import"../chunk-LLARZ7J7.js";import{a as m,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 fromLLM,t as fromMCP,m as fromWebSocket,p as fromWebhook,r as toSSE,S as toWebSocket};
1
+ import{a as o}from"../chunk-FJ2VN2O3.js";import{a as e}from"../chunk-6WZQIJIW.js";import{a as t}from"../chunk-565W67EU.js";import{a as r}from"../chunk-YCYCWSXF.js";import"../chunk-XEU7KSEO.js";import{a as p,b as S}from"../chunk-U3FGSR3I.js";import"../chunk-5LLYKN4X.js";import"../chunk-GMLWTZFM.js";import"../chunk-O2PONDZT.js";import"../chunk-J2E7GAMR.js";import"../chunk-4ILN4V4C.js";import"../chunk-Q3HIBGHR.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};
@@ -1,5 +1,5 @@
1
- "use strict";var Z=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var me=(t,e)=>{for(var i in e)Z(t,i,{get:e[i],enumerable:!0})},ye=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _e(e))!Se.call(t,s)&&s!==i&&Z(t,s,{get:()=>e[s],enumerable:!(n=Te(e,s))||n.enumerable});return t};var ve=t=>ye(Z({},"__esModule",{value:!0}),t);var Le={};me(Le,{fromMCP:()=>Ae});module.exports=ve(Le);var v=Symbol("DIRTY"),$=Symbol("RESOLVED"),ne=Symbol("SINGLE_DEP"),U=Symbol("RESET"),Ee=Symbol("PAUSE"),be=Symbol("RESUME"),X=Symbol("TEARDOWN");function se(t){return t===U||t===Ee||t===be||t===X}var ie=0,re=1,oe=2,ae=3,ue=4,le=5,D=7,ee=7<<D,De=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ce(t){return De[(t&ee)>>>D]}var T=0,_=1,g=2,m=3,W=0,Y=[],Q=!1;function I(t){W++;try{return t()}finally{if(W--,W===0&&!Q){Q=!0;for(let e=0;e<Y.length;e++)Y[e]();Y.length=0,Q=!1}}}function x(){return W>0}function B(t){Y.push(t)}var ke=0,Re=[];function fe(t){ke>0?Re.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 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(T,(o,a)=>{if(o===T&&(n=a),o===g){n=null;return}if(o===1){let u=a;if(!Object.is(u,s)){let l=s;s=u,i(u,l)}}}),()=>n?.(g)}static dumpGraph(){let e=t.graph(),i=t.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 e){let l=n.get(a),f=i.get(a),r=l?.length?` \u2190 [${l.join(", ")}]`:"",c=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${a} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${r}${c}`)}return[`Store Graph (${e.size} nodes):`,...s].join(`
2
- `)}static _signalLabel(e){return e===v?"DIRTY":e===$?"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),u=[],l={values:[],signals:[],events:[],ended:!1,endError:void 0,get completedCleanly(){return l.ended&&!o},get errored(){return l.ended&&o},dirtyCount:0,resolvedCount:0,name:a,get eventLog(){return u},dispose:()=>s?.(g),reconnect:()=>(s?.(g),t._observe(e,i,n))};return e.source(T,(f,r)=>{if(f===T){s=r;return}let c=x();f===_?(l.values.push(r),l.events.push({type:"data",data:r,inBatch:c}),u.push(r),n&&n(`[${a}] DATA:`,r)):f===m?(l.signals.push(r),l.events.push({type:"signal",data:r,inBatch:c}),u.push(t._signalLabel(r)),r===v?l.dirtyCount++:r===$&&l.resolvedCount++,n&&n(`[${a}] STATE:`,r)):f===g&&(l.ended=!0,l.endError=r,o=r!==void 0,l.events.push({type:"end",data:r,inBatch:c}),u.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(T,(n,s)=>{n===T&&(i=s),n===g&&(i=null)}),()=>i?.(g)}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 u=a.deref();if(!u)continue;let l=t._annotations.get(u);l!==void 0&&n.set(t._resolveKey(u),l)}let s=[];for(let[a,u]of e){let l={name:a,kind:u.kind,value:u.value,status:u.status},f=n.get(a);f!==void 0&&(l.annotation=f),s.push(l)}let o=[];for(let[a,u]of i)for(let l of u)o.push({from:a,to:l});return{nodes:s,edges:o,trace: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 u(r){let c=r.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(c);return d===void 0?(a.set(c,1),c):(a.set(c,d+1),`${c}__${d}`)}let l=new Map;function f(r){let c=JSON.stringify(r);return c&&c.length>30?`${c.slice(0,27)}...`:c??"undefined"}for(let r of n.nodes){let c=u(r.name);l.set(r.name,c);let d=`${r.name} (${r.kind}) = ${f(r.value)}`,h=o[r.status??""]??"";s.push(` ${c}["${d}"]${h}`)}for(let r of n.edges){let c=l.get(r.from)??u(r.from),d=l.get(r.to)??u(r.to);s.push(` ${c} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
- `)}static toD2(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 u(r){let c=r.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(c);return d===void 0?(a.set(c,1),c):(a.set(c,d+1),`${c}__${d}`)}let l=new Map;function f(r){let c=JSON.stringify(r);return c&&c.length>30?`${c.slice(0,27)}...`:c??"undefined"}for(let r of n.nodes){let c=u(r.name);l.set(r.name,c);let d=o[r.kind]??"rectangle",h=`${r.name} (${r.kind}) = ${f(r.value)}`,M=r.status?` [${r.status}]`:"";s.push(`${c}: "${h}${M}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let r of n.edges){let c=l.get(r.from)??u(r.from),d=l.get(r.to)??u(r.to);s.push(`${c} -> ${d}`)}return s.join(`
4
- `)}static annotate(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(T,(s,o)=>{if(s===T){i=o;return}let a={timestamp:Date.now(),type:s===_?"data":s===m?"signal":"end",data:o,inBatch:x()};n.push(a),s===g&&(i=null)}),{entries:n,dispose:()=>i?.(g)}}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(T,(o,a)=>{if(o===T){s=a;return}if(o===_){let u=a;if(u!==i){let l={from:i,to:u,timestamp:Date.now()};u==="error"&&(l.error=e.error.get()),n.push(l),i=u}}o===g&&(s=null)}),{transitions:n,get currentStatus(){return e.status.get()},dispose:()=>{s?.(g)}}}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()),c=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:c,triggerDepIndex:d,triggerDepName:d>=0?t.getName(o[d]):void 0,depValues:r,timestamp:Date.now()}),a=r,c};let u=t._observe(e),l=u.dispose;return{...u,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 H=1,y=64,S=2,A=4,de=8,ge=16,R=32,E=1024,p=ee,L=re<<D,C=oe<<D,q=ie<<D,xe=ue<<D,we=le<<D,Oe=ae<<D,G=class{_value;_output=null;_flags;get _status(){return ce(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|=A),i?.resetOnTeardown&&(n|=de),i?.resubscribable&&(n|=ge),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&y)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&&(x()?this._flags&R||(this._flags|=R,this._flags&A&&(this._flags=this._flags&~p|L,this._dispatch(m,v)),B(()=>{this._flags&=~R,this._flags=this._flags&~p|C,this._dispatch(_,this._value)})):(this._flags&A&&!(this._flags&E)&&(this._flags=this._flags&~p|L,this._dispatch(m,v)),this._flags=this._flags&~p|C,this._dispatch(_,this._value))))}signal(e){this._flags&S||!this._output||(e===v?this._flags=this._flags&~p|L:e===$&&(this._flags=this._flags&~p|Oe),this._dispatch(m,e))}complete(){if(this._flags&S)return;this._flags=(this._flags|S)&~p|xe;let e=this._output,i=this._flags&y;if(this._output=null,this._flags&=~(y|E),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|we;let i=this._output,n=this._flags&y;if(this._output=null,this._flags&=~(y|E),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,e);else i(g,e)}_start(){if(this._flags&H||!this._fn)return;this._flags|=H,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&H&&(this._flags&=~H,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&de&&(this._value=this._initial),this._flags&S||(this._flags=this._flags&~p|q))}_handleLifecycleSignal(e){if(!(this._flags&S)){if(e===X){this._onLifecycleSignal?.(e),this.complete();return}e===U&&(this._value=this._initial,this._flags&=~R),this._onLifecycleSignal?.(e),e===U&&this.emit(this._initial)}}source(e,i){if(e===T){let n=i;if(this._flags&S)if(this._flags&ge&&this._output===null)this._flags=this._flags&~(S|p)|q;else{n(T,o=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&y)this._output.add(n);else{let o=new Set;o.add(this._output),o.add(n),this._output=o,this._flags=(this._flags|y)&~E}let s=!1;n(T,(o,a)=>{if(o===_&&n(_,this._value),o===m){a===ne&&!s?(s=!0,this._singleDepCount++,this._flags&y||(this._flags|=E)):se(a)&&this._handleLifecycleSignal(a);return}if(o===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&y){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~y,this._singleDepCount>0&&(this._flags|=E)):u.size===0&&(this._output=null,this._flags&=~(y|E),this._singleDepCount=0,this._flags=this._flags&~p|q,this._stop())}else this._output===n&&(this._output=null,this._flags&=~E,this._singleDepCount=0,this._flags=this._flags&~p|q,this._stop())}}),fe(()=>this._start())}}};var te=class extends G{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&&(x()?this._flags&R||(this._flags|=R,this._flags&A&&(this._flags=this._flags&~p|L,this._dispatch(m,v)),B(()=>{this._flags&=~R,this._flags=this._flags&~p|C,this._dispatch(_,this._value)})):(this._flags&A&&!(this._flags&E)&&(this._flags=this._flags&~p|L,this._dispatch(m,v)),this._flags=this._flags&~p|C,this._dispatch(_,this._value))))}update(e){this.set(e(this._value))}};function k(t,e){return new te(t,e)}function Ae(t){let e=t.name??"mcp",i=t.client,n=k([],{name:`${e}.tools`}),s=k([],{name:`${e}.resources`}),o=k(void 0,{name:`${e}.refreshError`});function a(f){o.set(f);let r=t.onRefreshError;if(r==="warn")console.warn(`[${e}] refresh error:`,f);else{if(r==="error")throw f;typeof r=="function"&&r(f)}}async function u(){if(o.set(void 0),i.listTools)try{let f=await i.listTools();n.set(f.tools)}catch(f){a(f)}if(i.listResources)try{let f=await i.listResources();s.set(f.resources)}catch(f){a(f)}}function l(f){let r=`${e}:${f}`,c=k(void 0,{name:`${r}.result`}),d=k("idle",{name:`${r}.status`}),h=k(void 0,{name:`${r}.error`}),M=k(void 0,{name:`${r}.lastArgs`}),N=k(void 0,{name:`${r}.duration`}),z=!1;async function pe(j){if(z)return;z=!0,I(()=>{M.set(j),h.set(void 0),d.set("active")});let F=Date.now();try{let w=await i.callTool({name:f,arguments:j}),K=Date.now()-F;if(w.isError){let b=w.content.filter(J=>J.type==="text").map(J=>J.text??"").join(`
5
- `),he=new Error(b||"MCP tool returned error");I(()=>{N.set(K),h.set(he),d.set("errored")});return}let V=w.content.filter(b=>b.type==="text"),P;if(V.length===1){let b=V[0].text;if(b!==void 0)try{P=JSON.parse(b)}catch{P=b}}else V.length>1?P=V.map(b=>b.text??""):P=w.content;I(()=>{N.set(K),c.set(P),d.set("completed")})}catch(w){let K=Date.now()-F;I(()=>{N.set(K),h.set(w),d.set("errored")})}finally{z=!1}}return{get:()=>c.get(),source:(j,F)=>c.source(j,F),status:d,error:h,call:pe,lastArgs:M,duration:N}}return{tool:l,tools:n,resources:s,refresh:u,refreshError:o}}0&&(module.exports={fromMCP});
1
+ "use strict";var X=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var r in t)X(e,r,{get:t[r],enumerable:!0})},De=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of be(t))!ve.call(e,s)&&s!==r&&X(e,s,{get:()=>t[s],enumerable:!(n=ye(t,s))||n.enumerable});return e};var ke=e=>De(X({},"__esModule",{value:!0}),e);var je={};Ee(je,{fromMCP:()=>Ne});module.exports=ke(je);var b=Symbol("DIRTY"),O=Symbol("RESOLVED"),re=Symbol("SINGLE_DEP"),B=Symbol("RESET"),xe=Symbol("PAUSE"),Re=Symbol("RESUME"),te=Symbol("TEARDOWN");function ie(e){return e===B||e===xe||e===Re||e===te}var oe=0,ae=1,ue=2,le=3,ce=4,fe=5,D=7,ne=7<<D,we=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function de(e){return we[(e&ne)>>>D]}var T=0,m=1,g=2,S=3,Y=0,U=[],ee=!1;function C(e){Y++;try{return e()}finally{if(Y--,Y===0&&!ee){ee=!0;for(let t=0;t<U.length;t++)U[t]();U.length=0,ee=!1}}}function w(){return Y>0}function H(e){U.push(e)}var Ae=0,Ie=[];function ge(e){Ae>0?Ie.push(e):e()}var A=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let n=t.map(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(T,(i,a)=>{if(i===T&&(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 c=n.get(l);c?c.includes(a)||c.push(a):n.set(l,[a])}let s=[];for(let[a,u]of t){let l=n.get(a),c=r.get(a),o=l?.length?` \u2190 [${l.join(", ")}]`:"",f=c?.length?` \u2192 [${c.join(", ")}]`:"";s.push(` ${a} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${o}${f}`)}return[`Store Graph (${t.size} nodes):`,...s].join(`
2
+ `)}static _signalLabel(t){return t===b?"DIRTY":t===O?"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(T,(c,o)=>{if(c===T){s=o;return}let f=w();c===m?(l.values.push(o),l.events.push({type:"data",data:o,inBatch:f}),u.push(o),n&&n(`[${a}] DATA:`,o)):c===S?(l.signals.push(o),l.events.push({type:"signal",data:o,inBatch:f}),u.push(e._signalLabel(o)),o===b?l.dirtyCount++:o===O&&l.resolvedCount++,n&&n(`[${a}] STATE:`,o)):c===g&&(l.ended=!0,l.endError=o,i=o!==void 0,l.events.push({type:"end",data:o,inBatch:f}),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(T,(n,s)=>{n===T&&(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},c=n.get(a);c!==void 0&&(l.annotation=c),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 f=o.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(f);return d===void 0?(a.set(f,1),f):(a.set(f,d+1),`${f}__${d}`)}let l=new Map;function c(o){let f=JSON.stringify(o);return f&&f.length>30?`${f.slice(0,27)}...`:f??"undefined"}for(let o of n.nodes){let f=u(o.name);l.set(o.name,f);let d=`${o.name} (${o.kind}) = ${c(o.value)}`,h=i[o.status??""]??"";s.push(` ${f}["${d}"]${h}`)}for(let o of n.edges){let f=l.get(o.from)??u(o.from),d=l.get(o.to)??u(o.to);s.push(` ${f} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
+ `)}static toD2(t){let 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 f=o.replace(/[^a-zA-Z0-9_]/g,"_"),d=a.get(f);return d===void 0?(a.set(f,1),f):(a.set(f,d+1),`${f}__${d}`)}let l=new Map;function c(o){let f=JSON.stringify(o);return f&&f.length>30?`${f.slice(0,27)}...`:f??"undefined"}for(let o of n.nodes){let f=u(o.name);l.set(o.name,f);let d=i[o.kind]??"rectangle",h=`${o.name} (${o.kind}) = ${c(o.value)}`,M=o.status?` [${o.status}]`:"";s.push(`${f}: "${h}${M}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let o of n.edges){let f=l.get(o.from)??u(o.from),d=l.get(o.to)??u(o.to);s.push(`${f} -> ${d}`)}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(T,(s,i)=>{if(s===T){r=i;return}let a={timestamp:Date.now(),type:s===m?"data":s===S?"signal":"end",data:i,inBatch:w()};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()),c=s();return r.push({result:c,depValues:l,timestamp:Date.now()}),c};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(T,(i,a)=>{if(i===T){s=a;return}if(i===m){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(h=>h.get()),f=s(),d=-1;for(let h=0;h<i.length;h++)if(!Object.is(o[h],a[h])){d=h;break}return r.push({result:f,triggerDepIndex:d,triggerDepName:d>=0?e.getName(i[d]):void 0,depValues:o,timestamp:Date.now()}),a=o,f};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 q=1,y=64,_=2,I=4,pe=8,he=16,x=32,v=1024,p=ne,L=ae<<D,$=ue<<D,G=oe<<D,Le=ce<<D,Pe=fe<<D,Oe=le<<D,z=class{_value;_output=null;_flags;get _status(){return de(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|=pe),r?.resubscribable&&(n|=he),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),r?._skipInspect||A.register(this,{kind:"producer",...r})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,r){let n=this._output;if(n)if(this._flags&y)for(let s of n)s(t,r);else n(t,r)}emit(t){this._flags&_||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(w()?this._flags&x||(this._flags|=x,this._flags&I&&(this._flags=this._flags&~p|L,this._dispatch(S,b)),H(()=>{this._flags&=~x,this._flags=this._flags&~p|$,this._dispatch(m,this._value)})):(this._flags&I&&!(this._flags&v)&&(this._flags=this._flags&~p|L,this._dispatch(S,b)),this._flags=this._flags&~p|$,this._dispatch(m,this._value))))}signal(t){this._flags&_||!this._output||(t===b?this._flags=this._flags&~p|L:t===O&&(this._flags=this._flags&~p|Oe),this._dispatch(S,t))}complete(){if(this._flags&_)return;this._flags=(this._flags|_)&~p|Le;let t=this._output,r=this._flags&y;if(this._output=null,this._flags&=~(y|v),this._singleDepCount=0,this._stop(),t)if(r)for(let n of t)n(g);else t(g)}error(t){if(this._flags&_)return;this._flags=(this._flags|_)&~p|Pe;let r=this._output,n=this._flags&y;if(this._output=null,this._flags&=~(y|v),this._singleDepCount=0,this._stop(),r)if(n)for(let s of r)s(g,t);else r(g,t)}_start(){if(this._flags&q||!this._fn)return;this._flags|=q,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&q&&(this._flags&=~q,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&pe&&(this._value=this._initial),this._flags&_||(this._flags=this._flags&~p|G))}_handleLifecycleSignal(t){if(!(this._flags&_)){if(t===te){this._onLifecycleSignal?.(t),this.complete();return}t===B&&(this._value=this._initial,this._flags&=~x),this._onLifecycleSignal?.(t),t===B&&this.emit(this._initial)}}source(t,r){if(t===T){let n=r;if(this._flags&_)if(this._flags&he&&this._output===null)this._flags=this._flags&~(_|p)|G;else{n(T,i=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&y)this._output.add(n);else{let i=new Set;i.add(this._output),i.add(n),this._output=i,this._flags=(this._flags|y)&~v}let s=!1;n(T,(i,a)=>{if(i===m&&n(m,this._value),i===S){a===re&&!s?(s=!0,this._singleDepCount++,this._flags&y||(this._flags|=v)):ie(a)&&this._handleLifecycleSignal(a);return}if(i===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&y){let u=this._output;u.delete(n),u.size===1?(this._output=u.values().next().value,this._flags&=~y,this._singleDepCount>0&&(this._flags|=v)):u.size===0&&(this._output=null,this._flags&=~(y|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())}}),ge(()=>this._start())}}};var se=class extends z{constructor(t,r){super(void 0,{initial:t,autoDirty:!0,equals:r?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),A.register(this,{kind:"state",...r})}get(){return this._value}set(t){this._flags&_||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(w()?this._flags&x||(this._flags|=x,this._flags&I&&(this._flags=this._flags&~p|L,this._dispatch(S,b)),H(()=>{this._flags&=~x,this._flags=this._flags&~p|$,this._dispatch(m,this._value)})):(this._flags&I&&!(this._flags&v)&&(this._flags=this._flags&~p|L,this._dispatch(S,b)),this._flags=this._flags&~p|$,this._dispatch(m,this._value))))}update(t){this.set(t(this._value))}};function k(e,t){return new se(e,t)}function Te(e){return(t,r)=>{if(t!==0)return;let n=new AbortController,s=n.signal,i=!1,a,u;try{a=typeof e=="function"?e():e,u=a[Symbol.asyncIterator]()}catch(c){r(0,()=>{}),r(2,c);return}r(0,c=>{c===2&&!i&&(i=!0,n.abort(),Promise.resolve(u.return?.()).catch(()=>{}))});async function l(){try{for(;!i&&!s.aborted;){let c=await u.next();if(i||s.aborted)break;if(c.done){i=!0,r(2);return}r(1,c.value)}}catch(c){!i&&!s.aborted&&(i=!0,r(2,c))}}l()}}function me(e){return(t,r)=>{if(t!==0)return;let n=!1;r(0,s=>{s===2&&(n=!0)}),e.then(s=>{n||(r(1,s),n||r(2))},s=>{n||r(2,s)})}}function Ce(e){return e!=null&&typeof e.then=="function"}function $e(e){return e!=null&&typeof e[Symbol.asyncIterator]=="function"}function Me(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function J(e){return Ce(e)?me(e):$e(e)?Te(e):typeof e!="string"&&Me(e)?(t,r)=>{if(t!==0)return;let n=!1;r(0,s=>{s===2&&(n=!0)});for(let s of e){if(n)return;r(1,s)}n||r(2)}:(t,r)=>{if(t!==0)return;let n=!1;r(0,s=>{s===2&&(n=!0)}),n||r(1,e),n||r(2)}}function Z(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 Ne(e){let t=e.name??"mcp",r=e.client,n=k([],{name:`${t}.tools`}),s=k([],{name:`${t}.resources`}),i=k(void 0,{name:`${t}.refreshError`});function a(c){i.set(c);let o=e.onRefreshError;if(o==="warn")console.warn(`[${t}] refresh error:`,c);else{if(o==="error")throw c;typeof o=="function"&&o(c)}}function u(){i.set(void 0),r.listTools&&Z(J(r.listTools()),c=>{n.set(c.tools)},{onEnd:c=>{c!==void 0&&a(c)}}),r.listResources&&Z(J(r.listResources()),c=>{s.set(c.resources)},{onEnd:c=>{c!==void 0&&a(c)}})}function l(c){let o=`${t}:${c}`,f=k(void 0,{name:`${o}.result`}),d=k("idle",{name:`${o}.status`}),h=k(void 0,{name:`${o}.error`}),M=k(void 0,{name:`${o}.lastArgs`}),N=k(void 0,{name:`${o}.duration`}),j=!1;function _e(F){if(j)return;j=!0,C(()=>{M.set(F),h.set(void 0),d.set("active")});let K=Date.now();Z(J(r.callTool({name:c,arguments:F})),R=>{j=!1;let V=Date.now()-K;if(R.isError){let E=R.content.filter(Q=>Q.type==="text").map(Q=>Q.text??"").join(`
5
+ `),Se=new Error(E||"MCP tool returned error");C(()=>{N.set(V),h.set(Se),d.set("errored")});return}let W=R.content.filter(E=>E.type==="text"),P;if(W.length===1){let E=W[0].text;if(E!==void 0)try{P=JSON.parse(E)}catch{P=E}}else W.length>1?P=W.map(E=>E.text??""):P=R.content;C(()=>{N.set(V),f.set(P),d.set("completed")})},{onEnd:R=>{if(j=!1,R===void 0)return;let V=Date.now()-K;C(()=>{N.set(V),h.set(R),d.set("errored")})}})}return{get:()=>f.get(),source:(F,K)=>f.source(F,K),status:d,error:h,call:_e,lastArgs:M,duration:N}}return{tool:l,tools:n,resources:s,refresh:u,refreshError:i}}0&&(module.exports={fromMCP});
@@ -53,8 +53,8 @@ interface MCPToolStore<TArgs = Record<string, unknown>, TResult = unknown> exten
53
53
  status: Store<WithStatusStatus>;
54
54
  /** Last error, if any. */
55
55
  error: Store<unknown | undefined>;
56
- /** Call the tool with arguments. */
57
- call: (args: TArgs) => Promise<void>;
56
+ /** Call the tool with arguments. Results tracked via stores. */
57
+ call: (args: TArgs) => void;
58
58
  /** Last arguments passed to call(). */
59
59
  lastArgs: Store<TArgs | undefined>;
60
60
  /** Duration of last call in ms. */
@@ -75,8 +75,8 @@ interface MCPResult {
75
75
  tools: Store<MCPToolInfo[]>;
76
76
  /** Available resources (populated after refresh). */
77
77
  resources: Store<MCPResource[]>;
78
- /** Refresh the tools and resources lists. */
79
- refresh: () => Promise<void>;
78
+ /** Refresh the tools and resources lists. Results tracked via stores. */
79
+ refresh: () => void;
80
80
  /** Last refresh error, if any. */
81
81
  refreshError: Store<unknown | undefined>;
82
82
  }
@@ -53,8 +53,8 @@ interface MCPToolStore<TArgs = Record<string, unknown>, TResult = unknown> exten
53
53
  status: Store<WithStatusStatus>;
54
54
  /** Last error, if any. */
55
55
  error: Store<unknown | undefined>;
56
- /** Call the tool with arguments. */
57
- call: (args: TArgs) => Promise<void>;
56
+ /** Call the tool with arguments. Results tracked via stores. */
57
+ call: (args: TArgs) => void;
58
58
  /** Last arguments passed to call(). */
59
59
  lastArgs: Store<TArgs | undefined>;
60
60
  /** Duration of last call in ms. */
@@ -75,8 +75,8 @@ interface MCPResult {
75
75
  tools: Store<MCPToolInfo[]>;
76
76
  /** Available resources (populated after refresh). */
77
77
  resources: Store<MCPResource[]>;
78
- /** Refresh the tools and resources lists. */
79
- refresh: () => Promise<void>;
78
+ /** Refresh the tools and resources lists. Results tracked via stores. */
79
+ refresh: () => void;
80
80
  /** Last refresh error, if any. */
81
81
  refreshError: Store<unknown | undefined>;
82
82
  }
@@ -1 +1 @@
1
- import{a}from"../chunk-Q5DHO5II.js";import"../chunk-EAK2HKAD.js";import"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromMCP};
1
+ import{a}from"../chunk-6WZQIJIW.js";import"../chunk-O2PONDZT.js";import"../chunk-J2E7GAMR.js";import"../chunk-4ILN4V4C.js";import"../chunk-Q3HIBGHR.js";import"../chunk-EAK2HKAD.js";import"../chunk-2F6QWERG.js";import"../chunk-2L6223KN.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromMCP};