@callbag-recharge/callbag-recharge 0.12.0 → 0.14.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 (436) hide show
  1. package/dist/adapters/http.cjs +4 -4
  2. package/dist/adapters/http.d.cts +3 -3
  3. package/dist/adapters/http.d.ts +3 -3
  4. package/dist/adapters/http.js +1 -1
  5. package/dist/adapters/index.cjs +12 -12
  6. package/dist/adapters/index.d.cts +3 -3
  7. package/dist/adapters/index.d.ts +3 -3
  8. package/dist/adapters/index.js +1 -1
  9. package/dist/adapters/llm.cjs +5 -5
  10. package/dist/adapters/llm.d.cts +3 -3
  11. package/dist/adapters/llm.d.ts +3 -3
  12. package/dist/adapters/llm.js +1 -1
  13. package/dist/adapters/mcp.cjs +5 -5
  14. package/dist/adapters/mcp.d.cts +3 -3
  15. package/dist/adapters/mcp.d.ts +3 -3
  16. package/dist/adapters/mcp.js +1 -1
  17. package/dist/adapters/sse.cjs +10 -10
  18. package/dist/adapters/sse.d.cts +2 -2
  19. package/dist/adapters/sse.d.ts +2 -2
  20. package/dist/adapters/sse.js +1 -1
  21. package/dist/adapters/webhook.cjs +4 -4
  22. package/dist/adapters/webhook.d.cts +3 -3
  23. package/dist/adapters/webhook.d.ts +3 -3
  24. package/dist/adapters/webhook.js +1 -1
  25. package/dist/adapters/websocket.cjs +4 -4
  26. package/dist/adapters/websocket.d.cts +5 -5
  27. package/dist/adapters/websocket.d.ts +5 -5
  28. package/dist/adapters/websocket.js +1 -1
  29. package/dist/chunk-3AE6AS32.js +1 -0
  30. package/dist/chunk-3CHC2PEC.js +1 -0
  31. package/dist/chunk-4CRFPOTP.js +1 -0
  32. package/dist/chunk-5WFSQQDI.js +1 -0
  33. package/dist/chunk-6AITKURG.js +1 -0
  34. package/dist/chunk-6HLLZVDR.js +1 -0
  35. package/dist/chunk-6L3J4GGT.js +1 -0
  36. package/dist/{chunk-LDYBNZRJ.js → chunk-6ZKDN5EW.js} +1 -1
  37. package/dist/{chunk-SMRLX65A.js → chunk-7D7FHBCO.js} +1 -1
  38. package/dist/{chunk-FMVP37XC.js → chunk-7IW7ADDI.js} +1 -1
  39. package/dist/{chunk-M76W372U.js → chunk-7MY7DDET.js} +1 -1
  40. package/dist/chunk-A3YLDNEZ.js +1 -0
  41. package/dist/chunk-AJJTUL2L.js +1 -0
  42. package/dist/chunk-AQFWFFHP.js +1 -0
  43. package/dist/chunk-ATMRBZH2.js +1 -0
  44. package/dist/{chunk-WJ324SEE.js → chunk-BERYVZLY.js} +1 -1
  45. package/dist/chunk-BO6RJZ2Z.js +1 -0
  46. package/dist/{chunk-2IPYZVLQ.js → chunk-BQOJYKJT.js} +1 -1
  47. package/dist/{chunk-JR7AWDIG.js → chunk-C45X5AKN.js} +1 -1
  48. package/dist/chunk-CCB7OSCT.js +1 -0
  49. package/dist/{chunk-PUJBUJ22.js → chunk-CV6GBX5N.js} +1 -1
  50. package/dist/chunk-D6NMIIMQ.js +1 -0
  51. package/dist/chunk-EE6I3ASX.js +1 -0
  52. package/dist/{chunk-H2YDDQLL.js → chunk-EGJGBVCR.js} +1 -1
  53. package/dist/{chunk-GIXPYYX7.js → chunk-ER32MJVM.js} +1 -1
  54. package/dist/{chunk-QVJVAMYW.js → chunk-F4CU5CTA.js} +1 -1
  55. package/dist/{chunk-3AKMJ3CZ.js → chunk-FCEJOYU4.js} +1 -1
  56. package/dist/{chunk-LMOUWL76.js → chunk-FJNLQSK3.js} +1 -1
  57. package/dist/{chunk-KWTA2EOH.js → chunk-FV76ERZO.js} +1 -1
  58. package/dist/chunk-G7XILF6J.js +1 -0
  59. package/dist/chunk-GMLWTZFM.js +1 -0
  60. package/dist/chunk-GPHUNLET.js +1 -0
  61. package/dist/{chunk-HE2JY76U.js → chunk-GWRUTGV5.js} +1 -1
  62. package/dist/{chunk-HZW5L62J.js → chunk-HDPUS5OO.js} +1 -1
  63. package/dist/{chunk-SAJ7SY4Z.js → chunk-HILO5AS5.js} +1 -1
  64. package/dist/{chunk-V7QCYGUL.js → chunk-I2PZF4K6.js} +1 -1
  65. package/dist/chunk-I3BXIZVS.js +1 -0
  66. package/dist/{chunk-IVMTQFPB.js → chunk-IDTXL7PH.js} +1 -1
  67. package/dist/{chunk-E4AFG53N.js → chunk-KQDEYS2F.js} +1 -1
  68. package/dist/{chunk-LLLQTXBH.js → chunk-KUPHN4EE.js} +1 -1
  69. package/dist/{chunk-P5MXN4AF.js → chunk-KYY5ZPIG.js} +1 -1
  70. package/dist/chunk-LJNELNJP.js +1 -0
  71. package/dist/chunk-LUIHMMPZ.js +1 -0
  72. package/dist/{chunk-R7KF4ZVM.js → chunk-LXMAXJR5.js} +1 -1
  73. package/dist/{chunk-2OD7DSKQ.js → chunk-N2NDQCQO.js} +1 -1
  74. package/dist/chunk-NJEXVXD4.js +11 -0
  75. package/dist/{chunk-ZNFMGI2B.js → chunk-O2MPU5AE.js} +1 -1
  76. package/dist/{chunk-HMTVETW3.js → chunk-O3PSGN2O.js} +1 -1
  77. package/dist/{chunk-HGQF7SDJ.js → chunk-O6DCBOUE.js} +1 -1
  78. package/dist/{chunk-V347V3CS.js → chunk-ODY2WVV5.js} +1 -1
  79. package/dist/chunk-PP6QV2U4.js +1 -0
  80. package/dist/{chunk-VK3KSIWC.js → chunk-R363TL2A.js} +1 -1
  81. package/dist/{chunk-HP3Y5P4H.js → chunk-RQAJX7IG.js} +1 -1
  82. package/dist/{chunk-6EGOWDWF.js → chunk-S7ZMYSVO.js} +1 -1
  83. package/dist/chunk-SD5J4GZV.js +1 -0
  84. package/dist/chunk-SVCEBPU2.js +1 -0
  85. package/dist/{chunk-UMEIL4ZR.js → chunk-T4VDAIVN.js} +1 -1
  86. package/dist/chunk-TUPD47IE.js +1 -0
  87. package/dist/chunk-UC4T2SXM.js +1 -0
  88. package/dist/{chunk-6QYIOJBL.js → chunk-UEV5KYZK.js} +1 -1
  89. package/dist/chunk-ULFYO3TG.js +1 -0
  90. package/dist/chunk-UMSWDYDW.js +1 -0
  91. package/dist/{chunk-POETNQZ3.js → chunk-UQF6RSKP.js} +1 -1
  92. package/dist/{chunk-ULBRGC4X.js → chunk-UQTRJP46.js} +1 -1
  93. package/dist/{chunk-UGLHK25A.js → chunk-UY6CC6LO.js} +1 -1
  94. package/dist/{chunk-6HF3HFK2.js → chunk-UZUDFSE5.js} +1 -1
  95. package/dist/chunk-VO7NNLTJ.js +1 -0
  96. package/dist/chunk-VZ5VR7ON.js +1 -0
  97. package/dist/chunk-WUG5FVJK.js +1 -0
  98. package/dist/{chunk-CZ7UWY4Z.js → chunk-WWRDVOBH.js} +1 -1
  99. package/dist/{chunk-WGPBJVHE.js → chunk-XUYHR7J6.js} +1 -1
  100. package/dist/chunk-Z47453CJ.js +1 -0
  101. package/dist/chunk-ZOWERC3D.js +1 -0
  102. package/dist/compat/jotai/index.cjs +4 -4
  103. package/dist/compat/jotai/index.d.cts +2 -2
  104. package/dist/compat/jotai/index.d.ts +2 -2
  105. package/dist/compat/jotai/index.js +1 -1
  106. package/dist/compat/nanostores/index.cjs +4 -4
  107. package/dist/compat/nanostores/index.d.cts +2 -2
  108. package/dist/compat/nanostores/index.d.ts +2 -2
  109. package/dist/compat/nanostores/index.js +1 -1
  110. package/dist/compat/react/index.cjs +1 -1
  111. package/dist/compat/react/index.d.cts +2 -2
  112. package/dist/compat/react/index.d.ts +2 -2
  113. package/dist/compat/react/index.js +1 -1
  114. package/dist/compat/signals/index.cjs +4 -4
  115. package/dist/compat/signals/index.d.cts +6 -2
  116. package/dist/compat/signals/index.d.ts +6 -2
  117. package/dist/compat/signals/index.js +1 -1
  118. package/dist/compat/vue/index.cjs +1 -1
  119. package/dist/compat/vue/index.d.cts +2 -2
  120. package/dist/compat/vue/index.d.ts +2 -2
  121. package/dist/compat/vue/index.js +1 -1
  122. package/dist/compat/zustand/index.cjs +4 -4
  123. package/dist/compat/zustand/index.d.cts +1 -1
  124. package/dist/compat/zustand/index.d.ts +1 -1
  125. package/dist/compat/zustand/index.js +1 -1
  126. package/dist/data/index.cjs +4 -4
  127. package/dist/data/index.d.cts +4 -4
  128. package/dist/data/index.d.ts +4 -4
  129. package/dist/data/index.js +1 -1
  130. package/dist/extra/buffer.cjs +4 -4
  131. package/dist/extra/buffer.d.cts +2 -2
  132. package/dist/extra/buffer.d.ts +2 -2
  133. package/dist/extra/buffer.js +1 -1
  134. package/dist/extra/bufferTime.cjs +4 -4
  135. package/dist/extra/bufferTime.d.cts +2 -2
  136. package/dist/extra/bufferTime.d.ts +2 -2
  137. package/dist/extra/bufferTime.js +1 -1
  138. package/dist/extra/combine.cjs +4 -4
  139. package/dist/extra/combine.d.cts +2 -2
  140. package/dist/extra/combine.d.ts +2 -2
  141. package/dist/extra/combine.js +1 -1
  142. package/dist/extra/concat.cjs +4 -4
  143. package/dist/extra/concat.d.cts +2 -2
  144. package/dist/extra/concat.d.ts +2 -2
  145. package/dist/extra/concat.js +1 -1
  146. package/dist/extra/concatMap.cjs +4 -4
  147. package/dist/extra/concatMap.d.cts +2 -2
  148. package/dist/extra/concatMap.d.ts +2 -2
  149. package/dist/extra/concatMap.js +1 -1
  150. package/dist/extra/debounce.cjs +4 -4
  151. package/dist/extra/debounce.d.cts +2 -2
  152. package/dist/extra/debounce.d.ts +2 -2
  153. package/dist/extra/debounce.js +1 -1
  154. package/dist/extra/delay.cjs +4 -4
  155. package/dist/extra/delay.d.cts +2 -2
  156. package/dist/extra/delay.d.ts +2 -2
  157. package/dist/extra/delay.js +1 -1
  158. package/dist/extra/distinctUntilChanged.cjs +4 -4
  159. package/dist/extra/distinctUntilChanged.d.cts +2 -2
  160. package/dist/extra/distinctUntilChanged.d.ts +2 -2
  161. package/dist/extra/distinctUntilChanged.js +1 -1
  162. package/dist/extra/elementAt.cjs +4 -4
  163. package/dist/extra/elementAt.d.cts +2 -2
  164. package/dist/extra/elementAt.d.ts +2 -2
  165. package/dist/extra/elementAt.js +1 -1
  166. package/dist/extra/empty.cjs +4 -4
  167. package/dist/extra/empty.d.cts +2 -2
  168. package/dist/extra/empty.d.ts +2 -2
  169. package/dist/extra/empty.js +1 -1
  170. package/dist/extra/exhaustMap.cjs +4 -4
  171. package/dist/extra/exhaustMap.d.cts +2 -2
  172. package/dist/extra/exhaustMap.d.ts +2 -2
  173. package/dist/extra/exhaustMap.js +1 -1
  174. package/dist/extra/filter.cjs +4 -4
  175. package/dist/extra/filter.d.cts +2 -2
  176. package/dist/extra/filter.d.ts +2 -2
  177. package/dist/extra/filter.js +1 -1
  178. package/dist/extra/find.cjs +4 -4
  179. package/dist/extra/find.d.cts +2 -2
  180. package/dist/extra/find.d.ts +2 -2
  181. package/dist/extra/find.js +1 -1
  182. package/dist/extra/first.cjs +4 -4
  183. package/dist/extra/first.d.cts +2 -2
  184. package/dist/extra/first.d.ts +2 -2
  185. package/dist/extra/first.js +1 -1
  186. package/dist/extra/flat.cjs +4 -4
  187. package/dist/extra/flat.d.cts +2 -2
  188. package/dist/extra/flat.d.ts +2 -2
  189. package/dist/extra/flat.js +1 -1
  190. package/dist/extra/forEach.cjs +1 -1
  191. package/dist/extra/forEach.d.cts +5 -5
  192. package/dist/extra/forEach.d.ts +5 -5
  193. package/dist/extra/forEach.js +1 -1
  194. package/dist/extra/fromEvent.cjs +4 -4
  195. package/dist/extra/fromEvent.d.cts +2 -2
  196. package/dist/extra/fromEvent.d.ts +2 -2
  197. package/dist/extra/fromEvent.js +1 -1
  198. package/dist/extra/fromIter.cjs +4 -4
  199. package/dist/extra/fromIter.d.cts +2 -2
  200. package/dist/extra/fromIter.d.ts +2 -2
  201. package/dist/extra/fromIter.js +1 -1
  202. package/dist/extra/fromObs.cjs +4 -4
  203. package/dist/extra/fromObs.d.cts +2 -2
  204. package/dist/extra/fromObs.d.ts +2 -2
  205. package/dist/extra/fromObs.js +1 -1
  206. package/dist/extra/fromPromise.cjs +4 -4
  207. package/dist/extra/fromPromise.d.cts +2 -2
  208. package/dist/extra/fromPromise.d.ts +2 -2
  209. package/dist/extra/fromPromise.js +1 -1
  210. package/dist/extra/index.cjs +4 -4
  211. package/dist/extra/index.d.cts +2 -2
  212. package/dist/extra/index.d.ts +2 -2
  213. package/dist/extra/index.js +1 -1
  214. package/dist/extra/interval.cjs +4 -4
  215. package/dist/extra/interval.d.cts +2 -2
  216. package/dist/extra/interval.d.ts +2 -2
  217. package/dist/extra/interval.js +1 -1
  218. package/dist/extra/last.cjs +4 -4
  219. package/dist/extra/last.d.cts +2 -2
  220. package/dist/extra/last.d.ts +2 -2
  221. package/dist/extra/last.js +1 -1
  222. package/dist/extra/map.cjs +4 -4
  223. package/dist/extra/map.d.cts +2 -2
  224. package/dist/extra/map.d.ts +2 -2
  225. package/dist/extra/map.js +1 -1
  226. package/dist/extra/merge.cjs +4 -4
  227. package/dist/extra/merge.d.cts +2 -2
  228. package/dist/extra/merge.d.ts +2 -2
  229. package/dist/extra/merge.js +1 -1
  230. package/dist/extra/never.cjs +4 -4
  231. package/dist/extra/never.d.cts +2 -2
  232. package/dist/extra/never.d.ts +2 -2
  233. package/dist/extra/never.js +1 -1
  234. package/dist/extra/of.cjs +4 -4
  235. package/dist/extra/of.d.cts +2 -2
  236. package/dist/extra/of.d.ts +2 -2
  237. package/dist/extra/of.js +1 -1
  238. package/dist/extra/pairwise.cjs +4 -4
  239. package/dist/extra/pairwise.d.cts +2 -2
  240. package/dist/extra/pairwise.d.ts +2 -2
  241. package/dist/extra/pairwise.js +1 -1
  242. package/dist/extra/partition.cjs +4 -4
  243. package/dist/extra/partition.d.cts +2 -2
  244. package/dist/extra/partition.d.ts +2 -2
  245. package/dist/extra/partition.js +1 -1
  246. package/dist/extra/pipeRaw.cjs +4 -4
  247. package/dist/extra/pipeRaw.d.cts +2 -2
  248. package/dist/extra/pipeRaw.d.ts +2 -2
  249. package/dist/extra/pipeRaw.js +1 -1
  250. package/dist/extra/remember.cjs +4 -4
  251. package/dist/extra/remember.d.cts +2 -2
  252. package/dist/extra/remember.d.ts +2 -2
  253. package/dist/extra/remember.js +1 -1
  254. package/dist/extra/repeat.cjs +4 -4
  255. package/dist/extra/repeat.d.cts +2 -2
  256. package/dist/extra/repeat.d.ts +2 -2
  257. package/dist/extra/repeat.js +1 -1
  258. package/dist/extra/rescue.cjs +4 -4
  259. package/dist/extra/rescue.d.cts +2 -2
  260. package/dist/extra/rescue.d.ts +2 -2
  261. package/dist/extra/rescue.js +1 -1
  262. package/dist/extra/sample.cjs +4 -4
  263. package/dist/extra/sample.d.cts +2 -2
  264. package/dist/extra/sample.d.ts +2 -2
  265. package/dist/extra/sample.js +1 -1
  266. package/dist/extra/scan.cjs +4 -4
  267. package/dist/extra/scan.d.cts +2 -2
  268. package/dist/extra/scan.d.ts +2 -2
  269. package/dist/extra/scan.js +1 -1
  270. package/dist/extra/share.d.cts +2 -2
  271. package/dist/extra/share.d.ts +2 -2
  272. package/dist/extra/skip.cjs +4 -4
  273. package/dist/extra/skip.d.cts +2 -2
  274. package/dist/extra/skip.d.ts +2 -2
  275. package/dist/extra/skip.js +1 -1
  276. package/dist/extra/startWith.cjs +4 -4
  277. package/dist/extra/startWith.d.cts +2 -2
  278. package/dist/extra/startWith.d.ts +2 -2
  279. package/dist/extra/startWith.js +1 -1
  280. package/dist/extra/streamParse.cjs +4 -4
  281. package/dist/extra/streamParse.d.cts +2 -2
  282. package/dist/extra/streamParse.d.ts +2 -2
  283. package/dist/extra/streamParse.js +1 -1
  284. package/dist/extra/subject.cjs +4 -4
  285. package/dist/extra/subject.d.cts +2 -2
  286. package/dist/extra/subject.d.ts +2 -2
  287. package/dist/extra/subject.js +1 -1
  288. package/dist/extra/subscribe.cjs +1 -1
  289. package/dist/extra/subscribe.d.cts +14 -17
  290. package/dist/extra/subscribe.d.ts +14 -17
  291. package/dist/extra/subscribe.js +1 -1
  292. package/dist/extra/switchMap.cjs +4 -4
  293. package/dist/extra/switchMap.d.cts +2 -2
  294. package/dist/extra/switchMap.d.ts +2 -2
  295. package/dist/extra/switchMap.js +1 -1
  296. package/dist/extra/take.cjs +4 -4
  297. package/dist/extra/take.d.cts +2 -2
  298. package/dist/extra/take.d.ts +2 -2
  299. package/dist/extra/take.js +1 -1
  300. package/dist/extra/takeUntil.cjs +4 -4
  301. package/dist/extra/takeUntil.d.cts +2 -2
  302. package/dist/extra/takeUntil.d.ts +2 -2
  303. package/dist/extra/takeUntil.js +1 -1
  304. package/dist/extra/takeWhile.cjs +4 -4
  305. package/dist/extra/takeWhile.d.cts +2 -2
  306. package/dist/extra/takeWhile.d.ts +2 -2
  307. package/dist/extra/takeWhile.js +1 -1
  308. package/dist/extra/tap.cjs +4 -4
  309. package/dist/extra/tap.d.cts +2 -2
  310. package/dist/extra/tap.d.ts +2 -2
  311. package/dist/extra/tap.js +1 -1
  312. package/dist/extra/throttle.cjs +4 -4
  313. package/dist/extra/throttle.d.cts +2 -2
  314. package/dist/extra/throttle.d.ts +2 -2
  315. package/dist/extra/throttle.js +1 -1
  316. package/dist/extra/throwError.cjs +4 -4
  317. package/dist/extra/throwError.d.cts +2 -2
  318. package/dist/extra/throwError.d.ts +2 -2
  319. package/dist/extra/throwError.js +1 -1
  320. package/dist/extra/timeout.cjs +4 -4
  321. package/dist/extra/timeout.d.cts +2 -2
  322. package/dist/extra/timeout.d.ts +2 -2
  323. package/dist/extra/timeout.js +1 -1
  324. package/dist/index.cjs +4 -4
  325. package/dist/index.d.cts +7 -4
  326. package/dist/index.d.ts +7 -4
  327. package/dist/index.js +1 -1
  328. package/dist/memory/index.cjs +4 -4
  329. package/dist/memory/index.d.cts +4 -4
  330. package/dist/memory/index.d.ts +4 -4
  331. package/dist/memory/index.js +1 -1
  332. package/dist/orchestrate/index.cjs +8 -6
  333. package/dist/orchestrate/index.d.cts +375 -18
  334. package/dist/orchestrate/index.d.ts +375 -18
  335. package/dist/orchestrate/index.js +5 -3
  336. package/dist/patterns/agentLoop/index.cjs +4 -4
  337. package/dist/patterns/agentLoop/index.d.cts +2 -2
  338. package/dist/patterns/agentLoop/index.d.ts +2 -2
  339. package/dist/patterns/agentLoop/index.js +1 -1
  340. package/dist/patterns/chatStream/index.cjs +4 -4
  341. package/dist/patterns/chatStream/index.d.cts +2 -2
  342. package/dist/patterns/chatStream/index.d.ts +2 -2
  343. package/dist/patterns/chatStream/index.js +1 -1
  344. package/dist/patterns/createStore/index.cjs +4 -4
  345. package/dist/patterns/createStore/index.d.cts +4 -3
  346. package/dist/patterns/createStore/index.d.ts +4 -3
  347. package/dist/patterns/createStore/index.js +1 -1
  348. package/dist/patterns/formField/index.cjs +4 -4
  349. package/dist/patterns/formField/index.d.cts +2 -2
  350. package/dist/patterns/formField/index.d.ts +2 -2
  351. package/dist/patterns/formField/index.js +1 -1
  352. package/dist/patterns/hybridRoute/index.cjs +4 -4
  353. package/dist/patterns/hybridRoute/index.d.cts +2 -2
  354. package/dist/patterns/hybridRoute/index.d.ts +2 -2
  355. package/dist/patterns/hybridRoute/index.js +1 -1
  356. package/dist/patterns/memoryStore/index.cjs +4 -4
  357. package/dist/patterns/memoryStore/index.d.cts +4 -4
  358. package/dist/patterns/memoryStore/index.d.ts +4 -4
  359. package/dist/patterns/memoryStore/index.js +1 -1
  360. package/dist/patterns/pagination/index.cjs +4 -4
  361. package/dist/patterns/pagination/index.d.cts +2 -2
  362. package/dist/patterns/pagination/index.d.ts +2 -2
  363. package/dist/patterns/pagination/index.js +1 -1
  364. package/dist/patterns/rateLimiter/index.cjs +4 -4
  365. package/dist/patterns/rateLimiter/index.d.cts +2 -2
  366. package/dist/patterns/rateLimiter/index.d.ts +2 -2
  367. package/dist/patterns/rateLimiter/index.js +1 -1
  368. package/dist/patterns/textBuffer/index.cjs +7 -7
  369. package/dist/patterns/textBuffer/index.d.cts +2 -2
  370. package/dist/patterns/textBuffer/index.d.ts +2 -2
  371. package/dist/patterns/textBuffer/index.js +1 -1
  372. package/dist/patterns/textEditor/index.cjs +15 -15
  373. package/dist/patterns/textEditor/index.d.cts +3 -3
  374. package/dist/patterns/textEditor/index.d.ts +3 -3
  375. package/dist/patterns/textEditor/index.js +9 -9
  376. package/dist/patterns/toolCallState/index.cjs +4 -4
  377. package/dist/patterns/toolCallState/index.d.cts +2 -2
  378. package/dist/patterns/toolCallState/index.d.ts +2 -2
  379. package/dist/patterns/toolCallState/index.js +1 -1
  380. package/dist/patterns/undoRedo/index.cjs +4 -4
  381. package/dist/patterns/undoRedo/index.d.cts +2 -2
  382. package/dist/patterns/undoRedo/index.d.ts +2 -2
  383. package/dist/patterns/undoRedo/index.js +1 -1
  384. package/dist/{protocol-BVxRx57r.d.cts → protocol-fwiQ1TAS.d.cts} +20 -2
  385. package/dist/{protocol-BVxRx57r.d.ts → protocol-fwiQ1TAS.d.ts} +20 -2
  386. package/dist/{retry-dPqizArs.d.cts → retry-BLWpwKES.d.cts} +2 -2
  387. package/dist/{retry-CzvIREKf.d.ts → retry-KAgppYVn.d.ts} +2 -2
  388. package/dist/{types-CxUi8apg.d.cts → types-BHpdU2-O.d.cts} +2 -2
  389. package/dist/{types-BwU0Zcuz.d.cts → types-BohB8jJr.d.cts} +1 -1
  390. package/dist/{types-DGII6w5S.d.ts → types-CB1htCM8.d.ts} +1 -1
  391. package/dist/{types-BgibwR4K.d.cts → types-CrTRz6Oy.d.cts} +1 -1
  392. package/dist/{types-CuaRJ4Jz.d.ts → types-DETBg0QM.d.ts} +2 -2
  393. package/dist/{types-C46oZpWV.d.ts → types-Ds0-O16t.d.ts} +1 -1
  394. package/dist/utils/index.cjs +4 -4
  395. package/dist/utils/index.d.cts +33 -52
  396. package/dist/utils/index.d.ts +33 -52
  397. package/dist/utils/index.js +1 -1
  398. package/dist/{validationPipeline-DWE3jF8O.d.cts → validationPipeline-BI_SE3Cz.d.cts} +1 -1
  399. package/dist/{validationPipeline-U1qQHWFh.d.ts → validationPipeline-JPHJzW3f.d.ts} +1 -1
  400. package/dist/{withStatus-BJI4TOZV.d.ts → withStatus---CFNir7.d.ts} +1 -1
  401. package/dist/{withStatus-BQCWdfrH.d.cts → withStatus-ByT_R2Rz.d.cts} +1 -1
  402. package/package.json +1 -1
  403. package/dist/chunk-246NHV2C.js +0 -1
  404. package/dist/chunk-27ALPEGS.js +0 -1
  405. package/dist/chunk-2DSZBUDC.js +0 -1
  406. package/dist/chunk-2SUJFXLJ.js +0 -1
  407. package/dist/chunk-4QMLJ5NF.js +0 -1
  408. package/dist/chunk-57POOBOS.js +0 -1
  409. package/dist/chunk-7OBLM7WJ.js +0 -1
  410. package/dist/chunk-AHPGP6IY.js +0 -1
  411. package/dist/chunk-AWNDBSWN.js +0 -1
  412. package/dist/chunk-BXJY72NZ.js +0 -1
  413. package/dist/chunk-CWP55MPE.js +0 -1
  414. package/dist/chunk-CXF5XC6M.js +0 -1
  415. package/dist/chunk-DKV5ERLQ.js +0 -1
  416. package/dist/chunk-EJWPOQ3M.js +0 -1
  417. package/dist/chunk-G6E4ECVJ.js +0 -1
  418. package/dist/chunk-HIHLITY7.js +0 -1
  419. package/dist/chunk-J3QF6BR6.js +0 -1
  420. package/dist/chunk-JESACHQB.js +0 -1
  421. package/dist/chunk-JZEPFPK5.js +0 -1
  422. package/dist/chunk-K3CTYYBO.js +0 -1
  423. package/dist/chunk-LEK3WMVM.js +0 -1
  424. package/dist/chunk-N67ZXLEF.js +0 -1
  425. package/dist/chunk-PHO4NMDP.js +0 -1
  426. package/dist/chunk-Q6BCSEZ2.js +0 -1
  427. package/dist/chunk-T2XJDIOR.js +0 -1
  428. package/dist/chunk-TTLPYOAV.js +0 -1
  429. package/dist/chunk-UNEFE3LZ.js +0 -1
  430. package/dist/chunk-UVLBN37H.js +0 -1
  431. package/dist/chunk-VTOKDWUK.js +0 -1
  432. package/dist/chunk-X6RLUCXO.js +0 -11
  433. package/dist/chunk-XZV5OCPF.js +0 -1
  434. package/dist/chunk-YJXCVG35.js +0 -1
  435. package/dist/chunk-YN4VWXAF.js +0 -1
  436. package/dist/chunk-YOAFIOPU.js +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";var Q=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var vt=Object.getOwnPropertyNames;var Et=Object.prototype.hasOwnProperty;var Dt=(t,e)=>{for(var i in e)Q(t,i,{get:e[i],enumerable:!0})},kt=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of vt(e))!Et.call(t,s)&&s!==i&&Q(t,s,{get:()=>e[s],enumerable:!(n=bt(e,s))||n.enumerable});return t};var xt=t=>kt(Q({},"__esModule",{value:!0}),t);var At={};Dt(At,{fromHTTP:()=>$t});module.exports=xt(At);var k=Symbol("DIRTY"),Y=Symbol("RESOLVED"),st=Symbol("SINGLE_DEP"),it=0,rt=1,ot=2,at=3,ut=4,lt=5,x=7,tt=7<<x,Rt=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ct(t){return Rt[(t&tt)>>>x]}var _=0,y=1,g=2,b=3,F=0,W=[],X=!1;function P(t){F++;try{return t()}finally{if(F--,F===0&&!X){X=!0;for(let e=0;e<W.length;e++)W[e]();W.length=0,X=!1}}}function V(){return F>0}function q(t){W.push(t)}var H=0,K=[];function dt(){H++}function ft(){if(H--,H===0){for(let t=0;t<K.length;t++)K[t]();K.length=0}}function pt(t){H>0?K.push(t):t()}var O=class t{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(t._explicitEnabled!==null)return t._explicitEnabled;if(t._cachedDefault!==null)return t._cachedDefault;try{t._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{t._cachedDefault=!0}return t._cachedDefault}static set enabled(e){t._explicitEnabled=e}static _depSuffix(e){if(!e?.length)return;let n=e.map(s=>t._names.get(s)??"?").join(",");return n.length>40?`${n.slice(0,37)}...`:n}static _resolveKey(e){let i=t._keys.get(e)??t._names.get(e);if(i)return i;let n=`anonymous_${t._nextId++}`;return t._keys.set(e,n),n}static register(e,i){if(!t.enabled)return;i?.name&&t._names.set(e,i.name),i?.kind&&t._kinds.set(e,i.kind);let n=t._nextId++,s=i?.name;if(!(s&&!t._usedKeys.has(s)))if(s){let r=t._depSuffix(i?.deps);s=r?`${s}(${r})`:`${s}_${n}`,t._usedKeys.has(s)&&(s=`${s}_${n}`)}else{let r=i?.kind??"store",o=t._depSuffix(i?.deps);s=o?`${r}(${o})`:`${r}_${n}`,t._usedKeys.has(s)&&(s=`${s}_${n}`)}t._usedKeys.add(s),t._keys.set(e,s),t._stores.add(new WeakRef(e))}static registerEdge(e,i){if(!t.enabled)return;let n=t._resolveKey(e),s=t._resolveKey(i),r=t._edges.get(n);r?r.includes(s)||r.push(s):t._edges.set(n,[s])}static getEdges(){return new Map(t._edges)}static getName(e){if(t.enabled)return t._names.get(e)}static getKind(e){return t._kinds.get(e)}static inspect(e){return{name:t._names.get(e),kind:t._kinds.get(e)??"unknown",value:typeof e.get=="function"?e.get():void 0,status:e._status}}static graph(){let e=new Map,i=new Set;for(let n of t._stores){let s=n.deref();if(!s){t._stores.delete(n);continue}let r=t._resolveKey(s);i.add(r),e.set(r,t.inspect(s))}for(let[n,s]of t._edges){if(!i.has(n)){t._edges.delete(n),t._usedKeys.delete(n);continue}let r=s.filter(o=>i.has(o));r.length===0?t._edges.delete(n):r.length!==s.length&&t._edges.set(n,r)}return e}static trace(e,i){let n=null,s=e.get();return e.source(_,(r,o)=>{if(r===_&&(n=o),r===g){n=null;return}if(r===1){let a=o;if(!Object.is(a,s)){let u=s;s=a,i(a,u)}}}),()=>n?.(g)}static dumpGraph(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let[o,a]of i)for(let u of a){let f=n.get(u);f?f.includes(o)||f.push(o):n.set(u,[o])}let s=[];for(let[o,a]of e){let u=n.get(o),f=i.get(o),c=u?.length?` \u2190 [${u.join(", ")}]`:"",l=f?.length?` \u2192 [${f.join(", ")}]`:"";s.push(` ${o} (${a.kind}) = ${JSON.stringify(a.value)} [${a.status??"?"}]${c}${l}`)}return[`Store Graph (${e.size} nodes):`,...s].join(`
2
- `)}static _observe(e,i,n){let s=null,r=i??t.getName(e),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>s?.(g)};return e.source(_,(a,u)=>{if(a===_){s=u;return}a===y?(o.values.push(u),o.events.push({type:"data",data:u}),n&&n(`[${r}] DATA:`,u)):a===b?(o.signals.push(u),o.events.push({type:"signal",data:u}),u===k?o.dirtyCount++:u===Y&&o.resolvedCount++,n&&n(`[${r}] STATE:`,u)):a===g&&(o.ended=!0,o.endError=u,o.events.push({type:"end",data:u}),n&&n(`[${r}] END`,u!==void 0?u:""),s=null)}),o}static observe(e){return t._observe(e)}static tap(e,i){let n=i??`tap(${t.getName(e)??"anon"})`,s={get:()=>e.get(),source:e.source};return t.register(s,{name:n,kind:"tap"}),t.registerEdge(e,s),s}static spy(e,i){let n=i?.name??t.getName(e)??"spy",s=i?.log??console.log;return t._observe(e,n,s)}static snapshot(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let o of t._stores){let a=o.deref();if(!a)continue;let u=t._annotations.get(a);u!==void 0&&n.set(t._resolveKey(a),u)}let s=[];for(let[o,a]of e){let u={name:o,kind:a.kind,value:a.value,status:a.status},f=n.get(o);f!==void 0&&(u.annotation=f),s.push(u)}let r=[];for(let[o,a]of i)for(let u of a)r.push({from:o,to:u});return{nodes:s,edges:r,trace:t.traceLog()}}static toMermaid(e){let i=e?.direction??"TD",n=t.snapshot(),s=[`graph ${i}`],r={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},o=new Map;function a(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),d=o.get(l);return d===void 0?(o.set(l,1),l):(o.set(l,d+1),`${l}__${d}`)}let u=new Map;function f(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of n.nodes){let l=a(c.name);u.set(c.name,l);let d=`${c.name} (${c.kind}) = ${f(c.value)}`,h=r[c.status??""]??"";s.push(` ${l}["${d}"]${h}`)}for(let c of n.edges){let l=u.get(c.from)??a(c.from),d=u.get(c.to)??a(c.to);s.push(` ${l} --> ${d}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
- `)}static toD2(e){let i=e?.direction??"down",n=t.snapshot(),s=[`direction: ${i}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},o=new Map;function a(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),d=o.get(l);return d===void 0?(o.set(l,1),l):(o.set(l,d+1),`${l}__${d}`)}let u=new Map;function f(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of n.nodes){let l=a(c.name);u.set(c.name,l);let d=r[c.kind]??"rectangle",h=`${c.name} (${c.kind}) = ${f(c.value)}`,E=c.status?` [${c.status}]`:"";s.push(`${l}: "${h}${E}" { shape: ${d} }`)}n.edges.length>0&&s.push("");for(let c of n.edges){let l=u.get(c.from)??a(c.from),d=u.get(c.to)??a(c.to);s.push(`${l} -> ${d}`)}return s.join(`
4
- `)}static annotate(e,i){if(!t.enabled)return;t._annotations.set(e,i);let n={node:t._resolveKey(e),reason:i,timestamp:Date.now()},s=t.maxTraceEntries;s<=0||(t._traceLog.length<s?t._traceLog.push(n):(t._traceLog[t._traceHead]=n,t._traceFull=!0),t._traceHead=(t._traceHead+1)%s)}static getAnnotation(e){return t._annotations.get(e)}static traceLog(){return t._traceFull?[...t._traceLog.slice(t._traceHead),...t._traceLog.slice(0,t._traceHead)]:t._traceLog.slice(0,t._traceHead||t._traceLog.length)}static clearTrace(){t._traceLog=[],t._traceHead=0,t._traceFull=!1}static _reset(){t._names=new WeakMap,t._kinds=new WeakMap,t._keys=new WeakMap,t._stores=new Set,t._edges=new Map,t._usedKeys=new Set,t._nextId=0,t._explicitEnabled=null,t._cachedDefault=null,t._annotations=new WeakMap,t._traceLog=[],t._traceHead=0,t._traceFull=!1,t.maxTraceEntries=1e3}};var U=1,T=64,S=2,$=4,gt=8,ht=16,I=32,v=1024,p=tt,A=rt<<x,L=ot<<x,G=it<<x,wt=ut<<x,Ot=lt<<x,It=at<<x,N=class{_value;_output=null;_flags;get _status(){return ct(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;constructor(e,i){this._value=i?.initial,this._fn=e,this._eqFn=i?.equals,this._getterFn=i?.getter,this._initial=i?.initial;let n=0;i?.autoDirty!==!1&&(n|=$),i?.resetOnTeardown&&(n|=gt),i?.resubscribable&&(n|=ht),this._flags=n,this.source=this.source.bind(this),this.emit=this.emit.bind(this),i?._skipInspect||O.register(this,{kind:"producer",...i})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(e,i){let n=this._output;if(n)if(this._flags&T)for(let s of n)s(e,i);else n(e,i)}emit(e){this._flags&S||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(V()?this._flags&I||(this._flags|=I,this._flags&$&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),q(()=>{this._flags&=~I,this._flags=this._flags&~p|L,this._dispatch(y,this._value)})):(this._flags&$&&!(this._flags&v)&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),this._flags=this._flags&~p|L,this._dispatch(y,this._value))))}signal(e){this._flags&S||!this._output||(e===k?this._flags=this._flags&~p|A:e===Y&&(this._flags=this._flags&~p|It),this._dispatch(b,e))}complete(){if(this._flags&S)return;this._flags=(this._flags|S)&~p|wt;let e=this._output,i=this._flags&T;if(this._output=null,this._flags&=~(T|v),this._singleDepCount=0,this._stop(),e)if(i)for(let n of e)n(g);else e(g)}error(e){if(this._flags&S)return;this._flags=(this._flags|S)&~p|Ot;let i=this._output,n=this._flags&T;if(this._output=null,this._flags&=~(T|v),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(g,e);else i(g,e)}_start(){if(this._flags&U||!this._fn)return;this._flags|=U;let e=this._fn({emit:this.emit,signal:i=>this.signal(i),complete:()=>this.complete(),error:i=>this.error(i)});this._cleanup=typeof e=="function"?e:void 0}_stop(){this._flags&U&&(this._flags&=~U,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&gt&&(this._value=this._initial),this._flags&S||(this._flags=this._flags&~p|G))}source(e,i){if(e===_){let n=i;if(this._flags&S)if(this._flags&ht&&this._output===null)this._flags=this._flags&~(S|p)|G;else{n(_,r=>{}),n(g);return}if(this._output===null)this._output=n;else if(this._flags&T)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|T)&~v}let s=!1;n(_,(r,o)=>{if(r===y&&n(y,this._value),r===b&&o===st&&!s&&(s=!0,this._singleDepCount++,this._flags&T||(this._flags|=v)),r===g){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&T){let a=this._output;a.delete(n),a.size===1?(this._output=a.values().next().value,this._flags&=~T,this._singleDepCount>0&&(this._flags|=v)):a.size===0&&(this._output=null,this._flags&=~(T|v),this._singleDepCount=0,this._flags=this._flags&~p|G,this._stop())}else this._output===n&&(this._output=null,this._flags&=~v,this._singleDepCount=0,this._flags=this._flags&~p|G,this._stop())}}),pt(()=>this._start())}}};function z(t,e){return new N(t,e)}var et=class extends N{constructor(e,i){super(void 0,{initial:e,autoDirty:!0,equals:i?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),O.register(this,{kind:"state",...i})}get(){return this._value}set(e){this._flags&S||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(V()?this._flags&I||(this._flags|=I,this._flags&$&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),q(()=>{this._flags&=~I,this._flags=this._flags&~p|L,this._dispatch(y,this._value)})):(this._flags&$&&!(this._flags&v)&&(this._flags=this._flags&~p|A,this._dispatch(b,k)),this._flags=this._flags&~p|L,this._dispatch(y,this._value))))}update(e){this.set(e(this._value))}};function C(t,e){return new et(t,e)}function _t(t,e,i){let n=null;dt(),t.source(_,(r,o)=>{if(r===_&&(n=o),r===g){n=null,i?.onEnd?.(o);return}if(r===1){let a=o,u=s;s=a,e(a,u)}});let s;try{s=t.get()}catch{}return ft(),()=>n?.(g)}function Tt(t,e){let i=e?.initialStatus??"pending",n=C(i,{name:"withStatus:status",equals:Object.is}),s=C(void 0,{name:"withStatus:error",equals:Object.is}),r=z(({emit:a,complete:u,error:f})=>{n.set(i),s.set(void 0);let c=_t(t,l=>{n.get()==="errored"?P(()=>{s.set(void 0),n.set("active")}):n.set("active"),a(l)},{onEnd:l=>{if(l!==void 0){let d=l instanceof Error?l:new Error(String(l));P(()=>{s.set(d),n.set("errored")}),f(l)}else n.set("completed"),u()}});return()=>{c()}},{initial:t.get(),resubscribable:!0}),o={get:()=>t.get(),source:(a,u)=>r.source(a,u),get _status(){return r._status},status:n,error:s};return O.register(o,{kind:"withStatus"}),o}function $t(t,e){let i=e?.name??"http",n=e?.method??"GET",s=e?.headers,r=e?.body,o=e?.poll??0,a=e?.transform??(R=>R.json()),u=e?.timeout??3e4,f=C(0,{name:`${i}:fetchCount`}),c=null,l=null,d=null,h=null,E=null,m=!1;async function B(){if(!m||!c)return;E=new AbortController;let R=[E.signal];e?.signal&&R.push(e.signal);let w=new AbortController;for(let D of R){if(D.aborted){w.abort(D.reason);break}D.addEventListener("abort",()=>w.abort(D.reason),{once:!0})}let Z=setTimeout(()=>w.abort(new Error("Request timeout")),u);try{let D=r!==void 0?typeof r=="string"?r:JSON.stringify(r):void 0,j=await fetch(t,{method:n,headers:s,body:D,signal:w.signal});if(!m)return;if(!j.ok)throw new Error(`HTTP ${j.status}: ${j.statusText}`);let mt=await a(j);if(!m)return;P(()=>{f.update(yt=>yt+1),c?.(mt)})}catch(D){if(!m||D?.name==="AbortError")return;l?.(D)}finally{clearTimeout(Z),E=null}}function nt(){!m||o<=0||(h=setTimeout(()=>{h=null,B().then(()=>{m&&nt()}).catch(()=>{})},o))}let J=null,St=z(({emit:R,error:w,complete:Z})=>(c=R,l=w,d=Z,m=!0,J=()=>{B()},B().then(()=>{m&&nt()}),()=>{m=!1,c=null,l=null,d=null,J=null,E?.abort(),E=null,h!==null&&(clearTimeout(h),h=null)}),{name:i,kind:"http"}),M=Tt(St);return{get:()=>M.get(),source:(R,w)=>M.source(R,w),status:M.status,error:M.error,fetchCount:f,refetch(){J?.()},stop(){m=!1,E?.abort(),E=null,h!==null&&(clearTimeout(h),h=null),d?.()}}}0&&(module.exports={fromHTTP});
1
+ "use strict";var et=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var Lt=Object.prototype.hasOwnProperty;var Ot=(t,e)=>{for(var i in e)et(t,i,{get:e[i],enumerable:!0})},At=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of wt(e))!Lt.call(t,s)&&s!==i&&et(t,s,{get:()=>e[s],enumerable:!(n=Rt(e,s))||n.enumerable});return t};var It=t=>At(et({},"__esModule",{value:!0}),t);var jt={};Ot(jt,{fromHTTP:()=>Ct});module.exports=It(jt);var k=Symbol("DIRTY"),G=Symbol("RESOLVED"),lt=Symbol("SINGLE_DEP"),$=Symbol("RESET"),st=Symbol("PAUSE"),it=Symbol("RESUME"),rt=Symbol("TEARDOWN");function ut(t){return t===$||t===st||t===it||t===rt}var ct=0,ft=1,dt=2,pt=3,gt=4,ht=5,R=7,ot=7<<R,$t=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function _t(t){return $t[(t&ot)>>>R]}var _=0,v=1,h=2,S=3,H=0,Y=[],nt=!1;function M(t){H++;try{return t()}finally{if(H--,H===0&&!nt){nt=!0;for(let e=0;e<Y.length;e++)Y[e]();Y.length=0,nt=!1}}}function z(){return H>0}function B(t){Y.push(t)}var q=0,V=[];function St(){q++}function Tt(){if(q--,q===0){for(let t=0;t<V.length;t++)V[t]();V.length=0}}function mt(t){q>0?V.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",o=t._depSuffix(i?.deps);s=o?`${r}(${o})`:`${r}_${n}`,t._usedKeys.has(s)&&(s=`${s}_${n}`)}t._usedKeys.add(s),t._keys.set(e,s),t._stores.add(new WeakRef(e))}static registerEdge(e,i){if(!t.enabled)return;let n=t._resolveKey(e),s=t._resolveKey(i),r=t._edges.get(n);r?r.includes(s)||r.push(s):t._edges.set(n,[s])}static getEdges(){return new Map(t._edges)}static getName(e){if(t.enabled)return t._names.get(e)}static getKind(e){return t._kinds.get(e)}static inspect(e){return{name:t._names.get(e),kind:t._kinds.get(e)??"unknown",value:typeof e.get=="function"?e.get():void 0,status:e._status}}static graph(){let e=new Map,i=new Set;for(let n of t._stores){let s=n.deref();if(!s){t._stores.delete(n);continue}let r=t._resolveKey(s);i.add(r),e.set(r,t.inspect(s))}for(let[n,s]of t._edges){if(!i.has(n)){t._edges.delete(n),t._usedKeys.delete(n);continue}let r=s.filter(o=>i.has(o));r.length===0?t._edges.delete(n):r.length!==s.length&&t._edges.set(n,r)}return e}static trace(e,i){let n=null,s=e.get();return e.source(_,(r,o)=>{if(r===_&&(n=o),r===h){n=null;return}if(r===1){let a=o;if(!Object.is(a,s)){let l=s;s=a,i(a,l)}}}),()=>n?.(h)}static dumpGraph(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let[o,a]of i)for(let l of a){let d=n.get(l);d?d.includes(o)||d.push(o):n.set(l,[o])}let s=[];for(let[o,a]of e){let l=n.get(o),d=i.get(o),c=l?.length?` \u2190 [${l.join(", ")}]`:"",u=d?.length?` \u2192 [${d.join(", ")}]`:"";s.push(` ${o} (${a.kind}) = ${JSON.stringify(a.value)} [${a.status??"?"}]${c}${u}`)}return[`Store Graph (${e.size} nodes):`,...s].join(`
2
+ `)}static _observe(e,i,n){let s=null,r=i??t.getName(e),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>s?.(h)};return e.source(_,(a,l)=>{if(a===_){s=l;return}a===v?(o.values.push(l),o.events.push({type:"data",data:l}),n&&n(`[${r}] DATA:`,l)):a===S?(o.signals.push(l),o.events.push({type:"signal",data:l}),l===k?o.dirtyCount++:l===G&&o.resolvedCount++,n&&n(`[${r}] STATE:`,l)):a===h&&(o.ended=!0,o.endError=l,o.events.push({type:"end",data:l}),n&&n(`[${r}] END`,l!==void 0?l:""),s=null)}),o}static observe(e){return t._observe(e)}static tap(e,i){let n=i??`tap(${t.getName(e)??"anon"})`,s={get:()=>e.get(),source:e.source};return t.register(s,{name:n,kind:"tap"}),t.registerEdge(e,s),s}static spy(e,i){let n=i?.name??t.getName(e)??"spy",s=i?.log??console.log;return t._observe(e,n,s)}static snapshot(){let e=t.graph(),i=t.getEdges(),n=new Map;for(let o of t._stores){let a=o.deref();if(!a)continue;let l=t._annotations.get(a);l!==void 0&&n.set(t._resolveKey(a),l)}let s=[];for(let[o,a]of e){let l={name:o,kind:a.kind,value:a.value,status:a.status},d=n.get(o);d!==void 0&&(l.annotation=d),s.push(l)}let r=[];for(let[o,a]of i)for(let l of a)r.push({from:o,to:l});return{nodes:s,edges:r,trace:t.traceLog()}}static toMermaid(e){let i=e?.direction??"TD",n=t.snapshot(),s=[`graph ${i}`],r={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},o=new Map;function a(c){let u=c.replace(/[^a-zA-Z0-9_]/g,"_"),f=o.get(u);return f===void 0?(o.set(u,1),u):(o.set(u,f+1),`${u}__${f}`)}let l=new Map;function d(c){let u=JSON.stringify(c);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let c of n.nodes){let u=a(c.name);l.set(c.name,u);let f=`${c.name} (${c.kind}) = ${d(c.value)}`,p=r[c.status??""]??"";s.push(` ${u}["${f}"]${p}`)}for(let c of n.edges){let u=l.get(c.from)??a(c.from),f=l.get(c.to)??a(c.to);s.push(` ${u} --> ${f}`)}return s.push(""),s.push(" classDef settled fill:#d4edda,stroke:#28a745"),s.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),s.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),s.push(" classDef completed fill:#cce5ff,stroke:#007bff"),s.join(`
3
+ `)}static toD2(e){let i=e?.direction??"down",n=t.snapshot(),s=[`direction: ${i}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},o=new Map;function a(c){let u=c.replace(/[^a-zA-Z0-9_]/g,"_"),f=o.get(u);return f===void 0?(o.set(u,1),u):(o.set(u,f+1),`${u}__${f}`)}let l=new Map;function d(c){let u=JSON.stringify(c);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let c of n.nodes){let u=a(c.name);l.set(c.name,u);let f=r[c.kind]??"rectangle",p=`${c.name} (${c.kind}) = ${d(c.value)}`,m=c.status?` [${c.status}]`:"";s.push(`${u}: "${p}${m}" { shape: ${f} }`)}n.edges.length>0&&s.push("");for(let c of n.edges){let u=l.get(c.from)??a(c.from),f=l.get(c.to)??a(c.to);s.push(`${u} -> ${f}`)}return s.join(`
4
+ `)}static annotate(e,i){if(!t.enabled)return;t._annotations.set(e,i);let n={node:t._resolveKey(e),reason:i,timestamp:Date.now()},s=t.maxTraceEntries;s<=0||(t._traceLog.length<s?t._traceLog.push(n):(t._traceLog[t._traceHead]=n,t._traceFull=!0),t._traceHead=(t._traceHead+1)%s)}static getAnnotation(e){return t._annotations.get(e)}static traceLog(){return t._traceFull?[...t._traceLog.slice(t._traceHead),...t._traceLog.slice(0,t._traceHead)]:t._traceLog.slice(0,t._traceHead||t._traceLog.length)}static clearTrace(){t._traceLog=[],t._traceHead=0,t._traceFull=!1}static _reset(){t._names=new WeakMap,t._kinds=new WeakMap,t._keys=new WeakMap,t._stores=new Set,t._edges=new Map,t._usedKeys=new Set,t._nextId=0,t._explicitEnabled=null,t._cachedDefault=null,t._annotations=new WeakMap,t._traceLog=[],t._traceHead=0,t._traceFull=!1,t.maxTraceEntries=1e3}};var J=1,b=64,T=2,P=4,yt=8,Et=16,I=32,D=1024,g=ot,N=ft<<R,C=dt<<R,Z=ct<<R,Pt=gt<<R,Nt=ht<<R,Mt=pt<<R,j=class{_value;_output=null;_flags;get _status(){return _t(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|=P),i?.resetOnTeardown&&(n|=yt),i?.resubscribable&&(n|=Et),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&b)for(let s of n)s(e,i);else n(e,i)}emit(e){this._flags&T||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(z()?this._flags&I||(this._flags|=I,this._flags&P&&(this._flags=this._flags&~g|N,this._dispatch(S,k)),B(()=>{this._flags&=~I,this._flags=this._flags&~g|C,this._dispatch(v,this._value)})):(this._flags&P&&!(this._flags&D)&&(this._flags=this._flags&~g|N,this._dispatch(S,k)),this._flags=this._flags&~g|C,this._dispatch(v,this._value))))}signal(e){this._flags&T||!this._output||(e===k?this._flags=this._flags&~g|N:e===G&&(this._flags=this._flags&~g|Mt),this._dispatch(S,e))}complete(){if(this._flags&T)return;this._flags=(this._flags|T)&~g|Pt;let e=this._output,i=this._flags&b;if(this._output=null,this._flags&=~(b|D),this._singleDepCount=0,this._stop(),e)if(i)for(let n of e)n(h);else e(h)}error(e){if(this._flags&T)return;this._flags=(this._flags|T)&~g|Nt;let i=this._output,n=this._flags&b;if(this._output=null,this._flags&=~(b|D),this._singleDepCount=0,this._stop(),i)if(n)for(let s of i)s(h,e);else i(h,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&yt&&(this._value=this._initial),this._flags&T||(this._flags=this._flags&~g|Z))}_handleLifecycleSignal(e){if(!(this._flags&T)){if(e===rt){this._onLifecycleSignal?.(e),this.complete();return}e===$&&(this._value=this._initial,this._flags&=~I),this._onLifecycleSignal?.(e),e===$&&this.emit(this._initial)}}source(e,i){if(e===_){let n=i;if(this._flags&T)if(this._flags&Et&&this._output===null)this._flags=this._flags&~(T|g)|Z;else{n(_,r=>{}),n(h);return}if(this._output===null)this._output=n;else if(this._flags&b)this._output.add(n);else{let r=new Set;r.add(this._output),r.add(n),this._output=r,this._flags=(this._flags|b)&~D}let s=!1;n(_,(r,o)=>{if(r===v&&n(v,this._value),r===S){o===lt&&!s?(s=!0,this._singleDepCount++,this._flags&b||(this._flags|=D)):ut(o)&&this._handleLifecycleSignal(o);return}if(r===h){if(s&&(s=!1,this._singleDepCount--),this._output===null)return;if(this._flags&b){let a=this._output;a.delete(n),a.size===1?(this._output=a.values().next().value,this._flags&=~b,this._singleDepCount>0&&(this._flags|=D)):a.size===0&&(this._output=null,this._flags&=~(b|D),this._singleDepCount=0,this._flags=this._flags&~g|Z,this._stop())}else this._output===n&&(this._output=null,this._flags&=~D,this._singleDepCount=0,this._flags=this._flags&~g|Z,this._stop())}}),mt(()=>this._start())}}};function Q(t,e){return new j(t,e)}var at=class extends j{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&T||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(z()?this._flags&I||(this._flags|=I,this._flags&P&&(this._flags=this._flags&~g|N,this._dispatch(S,k)),B(()=>{this._flags&=~I,this._flags=this._flags&~g|C,this._dispatch(v,this._value)})):(this._flags&P&&!(this._flags&D)&&(this._flags=this._flags&~g|N,this._dispatch(S,k)),this._flags=this._flags&~g|C,this._dispatch(v,this._value))))}update(e){this.set(e(this._value))}};function W(t,e){return new at(t,e)}function bt(t,e,i){let n=null;St(),t.source(_,(r,o)=>{if(r===_&&(n=o),r===h){n=null,i?.onEnd?.(o);return}if(r===1){let a=o,l=s;s=a,e(a,l)}});let s;try{s=t.get()}catch{}return Tt(),{unsubscribe(){n?.(h),n=null},signal(r){n?.(S,r)}}}function vt(t,e){let i=e?.initialStatus??"pending",n=W(i,{name:"withStatus:status",equals:Object.is}),s=W(void 0,{name:"withStatus:error",equals:Object.is}),r=Q(({emit:a,complete:l,error:d})=>{n.set(i),s.set(void 0);let c=bt(t,u=>{n.get()==="errored"?M(()=>{s.set(void 0),n.set("active")}):n.set("active"),a(u)},{onEnd:u=>{if(u!==void 0){let f=u instanceof Error?u:new Error(String(u));M(()=>{s.set(f),n.set("errored")}),d(u)}else n.set("completed"),l()}});return()=>{c.unsubscribe()}},{initial:t.get(),resubscribable:!0}),o={get:()=>t.get(),source:(a,l)=>r.source(a,l),get _status(){return r._status},status:n,error:s};return A.register(o,{kind:"withStatus"}),o}function Ct(t,e){let i=e?.name??"http",n=e?.method??"GET",s=e?.headers,r=e?.body,o=e?.poll??0,a=e?.transform??(w=>w.json()),l=e?.timeout??3e4,d=W(0,{name:`${i}:fetchCount`}),c=null,u=null,f=null,p=null,m=null,y=!1;async function F(){if(!y||!c)return;m=new AbortController;let w=[m.signal];e?.signal&&w.push(e.signal);let L=new AbortController;for(let E of w){if(E.aborted){L.abort(E.reason);break}E.addEventListener("abort",()=>L.abort(E.reason),{once:!0})}let tt=setTimeout(()=>L.abort(new Error("Request timeout")),l);try{let E=r!==void 0?typeof r=="string"?r:JSON.stringify(r):void 0,O=await fetch(t,{method:n,headers:s,body:E,signal:L.signal});if(!y)return;if(!O.ok)throw new Error(`HTTP ${O.status}: ${O.statusText}`);let xt=await a(O);if(!y)return;M(()=>{d.update(kt=>kt+1),c?.(xt)})}catch(E){if(!y||E?.name==="AbortError")return;u?.(E)}finally{clearTimeout(tt),m=null}}function K(){!y||x||o<=0||(p=setTimeout(()=>{p=null,F().then(()=>{y&&!x&&K()}).catch(()=>{})},o))}let X=null,x=!1,Dt=Q(({emit:w,error:L,complete:tt,onSignal:E})=>(c=w,u=L,f=tt,y=!0,x=!1,X=()=>{F()},E(O=>{O===st?(x=!0,p!==null&&(clearTimeout(p),p=null)):O===it?(x=!1,K()):O===$&&(m?.abort(),m=null,p!==null&&(clearTimeout(p),p=null),d.set(0),x=!1,F().then(()=>{y&&!x&&K()}))}),F().then(()=>{y&&!x&&K()}),()=>{y=!1,x=!1,c=null,u=null,f=null,X=null,m?.abort(),m=null,p!==null&&(clearTimeout(p),p=null)}),{name:i,kind:"http"}),U=vt(Dt);return{get:()=>U.get(),source:(w,L)=>U.source(w,L),status:U.status,error:U.error,fetchCount:d,refetch(){X?.()},stop(){y=!1,m?.abort(),m=null,p!==null&&(clearTimeout(p),p=null),f?.()}}}0&&(module.exports={fromHTTP});
@@ -1,6 +1,6 @@
1
- import { S as Store } from '../types-BwU0Zcuz.cjs';
2
- import { W as WithStatusStatus } from '../withStatus-BQCWdfrH.cjs';
3
- import '../protocol-BVxRx57r.cjs';
1
+ import { S as Store } from '../types-BohB8jJr.cjs';
2
+ import { W as WithStatusStatus } from '../withStatus-ByT_R2Rz.cjs';
3
+ import '../protocol-fwiQ1TAS.cjs';
4
4
 
5
5
  interface FromHTTPOptions {
6
6
  /** HTTP method. Default: "GET". */
@@ -1,6 +1,6 @@
1
- import { S as Store } from '../types-DGII6w5S.js';
2
- import { W as WithStatusStatus } from '../withStatus-BJI4TOZV.js';
3
- import '../protocol-BVxRx57r.js';
1
+ import { S as Store } from '../types-CB1htCM8.js';
2
+ import { W as WithStatusStatus } from '../withStatus---CFNir7.js';
3
+ import '../protocol-fwiQ1TAS.js';
4
4
 
5
5
  interface FromHTTPOptions {
6
6
  /** HTTP method. Default: "GET". */
@@ -1 +1 @@
1
- import{a}from"../chunk-27ALPEGS.js";import"../chunk-HE2JY76U.js";import"../chunk-YJXCVG35.js";import"../chunk-P5MXN4AF.js";import"../chunk-YN4VWXAF.js";import"../chunk-M76W372U.js";import"../chunk-CWP55MPE.js";import"../chunk-I7AUKTXE.js";export{a as fromHTTP};
1
+ import{a}from"../chunk-3AE6AS32.js";import"../chunk-GWRUTGV5.js";import"../chunk-GMLWTZFM.js";import"../chunk-KYY5ZPIG.js";import"../chunk-3CHC2PEC.js";import"../chunk-7MY7DDET.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromHTTP};
@@ -1,16 +1,16 @@
1
- "use strict";var Ae=Object.create;var Z=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var We=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty;var Ne=(e,t)=>{for(var n in t)Z(e,n,{get:t[n],enumerable:!0})},de=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $e(t))!Ie.call(e,o)&&o!==n&&Z(e,o,{get:()=>t[o],enumerable:!(r=Me(t,o))||r.enumerable});return e};var je=(e,t,n)=>(n=e!=null?Ae(We(e)):{},de(t||!e||!e.__esModule?Z(n,"default",{value:e,enumerable:!0}):n,e)),He=e=>de(Z({},"__esModule",{value:!0}),e);var Ze={};Ne(Ze,{fromHTTP:()=>xe,fromLLM:()=>Re,fromMCP:()=>De,fromWebSocket:()=>Oe,fromWebhook:()=>Pe,toSSE:()=>Ce,toWebSocket:()=>Le});module.exports=He(Ze);var j=Symbol("DIRTY"),re=Symbol("RESOLVED"),pe=Symbol("SINGLE_DEP"),ge=0,me=1,he=2,Se=3,Te=4,be=5,H=7,ce=7<<H,Fe=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ye(e){return Fe[(e&ce)>>>H]}var L=0,W=1,D=2,I=3,X=0,ee=[],ue=!1;function C(e){X++;try{return e()}finally{if(X--,X===0&&!ue){ue=!0;for(let t=0;t<ee.length;t++)ee[t]();ee.length=0,ue=!1}}}function oe(){return X>0}function se(e){ee.push(e)}var ne=0,te=[];function _e(){ne++}function ke(){if(ne--,ne===0){for(let e=0;e<te.length;e++)te[e]();te.length=0}}function ve(e){ne>0?te.push(e):e()}var P=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let r=t.map(o=>e._names.get(o)??"?").join(",");return r.length>40?`${r.slice(0,37)}...`:r}static _resolveKey(t){let n=e._keys.get(t)??e._names.get(t);if(n)return n;let r=`anonymous_${e._nextId++}`;return e._keys.set(t,r),r}static register(t,n){if(!e.enabled)return;n?.name&&e._names.set(t,n.name),n?.kind&&e._kinds.set(t,n.kind);let r=e._nextId++,o=n?.name;if(!(o&&!e._usedKeys.has(o)))if(o){let c=e._depSuffix(n?.deps);o=c?`${o}(${c})`:`${o}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}else{let c=n?.kind??"store",s=e._depSuffix(n?.deps);o=s?`${c}(${s})`:`${c}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}e._usedKeys.add(o),e._keys.set(t,o),e._stores.add(new WeakRef(t))}static registerEdge(t,n){if(!e.enabled)return;let r=e._resolveKey(t),o=e._resolveKey(n),c=e._edges.get(r);c?c.includes(o)||c.push(o):e._edges.set(r,[o])}static getEdges(){return new Map(e._edges)}static getName(t){if(e.enabled)return e._names.get(t)}static getKind(t){return e._kinds.get(t)}static inspect(t){return{name:e._names.get(t),kind:e._kinds.get(t)??"unknown",value:typeof t.get=="function"?t.get():void 0,status:t._status}}static graph(){let t=new Map,n=new Set;for(let r of e._stores){let o=r.deref();if(!o){e._stores.delete(r);continue}let c=e._resolveKey(o);n.add(c),t.set(c,e.inspect(o))}for(let[r,o]of e._edges){if(!n.has(r)){e._edges.delete(r),e._usedKeys.delete(r);continue}let c=o.filter(s=>n.has(s));c.length===0?e._edges.delete(r):c.length!==o.length&&e._edges.set(r,c)}return t}static trace(t,n){let r=null,o=t.get();return t.source(L,(c,s)=>{if(c===L&&(r=s),c===D){r=null;return}if(c===1){let i=s;if(!Object.is(i,o)){let l=o;o=i,n(i,l)}}}),()=>r?.(D)}static dumpGraph(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let[s,i]of n)for(let l of i){let f=r.get(l);f?f.includes(s)||f.push(s):r.set(l,[s])}let o=[];for(let[s,i]of t){let l=r.get(s),f=n.get(s),u=l?.length?` \u2190 [${l.join(", ")}]`:"",a=f?.length?` \u2192 [${f.join(", ")}]`:"";o.push(` ${s} (${i.kind}) = ${JSON.stringify(i.value)} [${i.status??"?"}]${u}${a}`)}return[`Store Graph (${t.size} nodes):`,...o].join(`
2
- `)}static _observe(t,n,r){let o=null,c=n??e.getName(t),s={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:c,dispose:()=>o?.(D)};return t.source(L,(i,l)=>{if(i===L){o=l;return}i===W?(s.values.push(l),s.events.push({type:"data",data:l}),r&&r(`[${c}] DATA:`,l)):i===I?(s.signals.push(l),s.events.push({type:"signal",data:l}),l===j?s.dirtyCount++:l===re&&s.resolvedCount++,r&&r(`[${c}] STATE:`,l)):i===D&&(s.ended=!0,s.endError=l,s.events.push({type:"end",data:l}),r&&r(`[${c}] END`,l!==void 0?l:""),o=null)}),s}static observe(t){return e._observe(t)}static tap(t,n){let r=n??`tap(${e.getName(t)??"anon"})`,o={get:()=>t.get(),source:t.source};return e.register(o,{name:r,kind:"tap"}),e.registerEdge(t,o),o}static spy(t,n){let r=n?.name??e.getName(t)??"spy",o=n?.log??console.log;return e._observe(t,r,o)}static snapshot(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let s of e._stores){let i=s.deref();if(!i)continue;let l=e._annotations.get(i);l!==void 0&&r.set(e._resolveKey(i),l)}let o=[];for(let[s,i]of t){let l={name:s,kind:i.kind,value:i.value,status:i.status},f=r.get(s);f!==void 0&&(l.annotation=f),o.push(l)}let c=[];for(let[s,i]of n)for(let l of i)c.push({from:s,to:l});return{nodes:o,edges:c,trace:e.traceLog()}}static toMermaid(t){let n=t?.direction??"TD",r=e.snapshot(),o=[`graph ${n}`],c={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},s=new Map;function i(u){let a=u.replace(/[^a-zA-Z0-9_]/g,"_"),p=s.get(a);return p===void 0?(s.set(a,1),a):(s.set(a,p+1),`${a}__${p}`)}let l=new Map;function f(u){let a=JSON.stringify(u);return a&&a.length>30?`${a.slice(0,27)}...`:a??"undefined"}for(let u of r.nodes){let a=i(u.name);l.set(u.name,a);let p=`${u.name} (${u.kind}) = ${f(u.value)}`,y=c[u.status??""]??"";o.push(` ${a}["${p}"]${y}`)}for(let u of r.edges){let a=l.get(u.from)??i(u.from),p=l.get(u.to)??i(u.to);o.push(` ${a} --> ${p}`)}return o.push(""),o.push(" classDef settled fill:#d4edda,stroke:#28a745"),o.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),o.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),o.push(" classDef completed fill:#cce5ff,stroke:#007bff"),o.join(`
3
- `)}static toD2(t){let n=t?.direction??"down",r=e.snapshot(),o=[`direction: ${n}`,""],c={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},s=new Map;function i(u){let a=u.replace(/[^a-zA-Z0-9_]/g,"_"),p=s.get(a);return p===void 0?(s.set(a,1),a):(s.set(a,p+1),`${a}__${p}`)}let l=new Map;function f(u){let a=JSON.stringify(u);return a&&a.length>30?`${a.slice(0,27)}...`:a??"undefined"}for(let u of r.nodes){let a=i(u.name);l.set(u.name,a);let p=c[u.kind]??"rectangle",y=`${u.name} (${u.kind}) = ${f(u.value)}`,_=u.status?` [${u.status}]`:"";o.push(`${a}: "${y}${_}" { shape: ${p} }`)}r.edges.length>0&&o.push("");for(let u of r.edges){let a=l.get(u.from)??i(u.from),p=l.get(u.to)??i(u.to);o.push(`${a} -> ${p}`)}return o.join(`
4
- `)}static annotate(t,n){if(!e.enabled)return;e._annotations.set(t,n);let r={node:e._resolveKey(t),reason:n,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(r):(e._traceLog[e._traceHead]=r,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var ie=1,M=64,$=2,K=4,we=8,Ee=16,q=32,N=1024,x=ce,U=me<<H,Y=he<<H,ae=ge<<H,qe=Te<<H,Be=be<<H,Ke=Se<<H,G=class{_value;_output=null;_flags;get _status(){return ye(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;constructor(t,n){this._value=n?.initial,this._fn=t,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let r=0;n?.autoDirty!==!1&&(r|=K),n?.resetOnTeardown&&(r|=we),n?.resubscribable&&(r|=Ee),this._flags=r,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||P.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,n){let r=this._output;if(r)if(this._flags&M)for(let o of r)o(t,n);else r(t,n)}emit(t){this._flags&$||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(oe()?this._flags&q||(this._flags|=q,this._flags&K&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),se(()=>{this._flags&=~q,this._flags=this._flags&~x|Y,this._dispatch(W,this._value)})):(this._flags&K&&!(this._flags&N)&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),this._flags=this._flags&~x|Y,this._dispatch(W,this._value))))}signal(t){this._flags&$||!this._output||(t===j?this._flags=this._flags&~x|U:t===re&&(this._flags=this._flags&~x|Ke),this._dispatch(I,t))}complete(){if(this._flags&$)return;this._flags=(this._flags|$)&~x|qe;let t=this._output,n=this._flags&M;if(this._output=null,this._flags&=~(M|N),this._singleDepCount=0,this._stop(),t)if(n)for(let r of t)r(D);else t(D)}error(t){if(this._flags&$)return;this._flags=(this._flags|$)&~x|Be;let n=this._output,r=this._flags&M;if(this._output=null,this._flags&=~(M|N),this._singleDepCount=0,this._stop(),n)if(r)for(let o of n)o(D,t);else n(D,t)}_start(){if(this._flags&ie||!this._fn)return;this._flags|=ie;let t=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n)});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ie&&(this._flags&=~ie,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&we&&(this._value=this._initial),this._flags&$||(this._flags=this._flags&~x|ae))}source(t,n){if(t===L){let r=n;if(this._flags&$)if(this._flags&Ee&&this._output===null)this._flags=this._flags&~($|x)|ae;else{r(L,c=>{}),r(D);return}if(this._output===null)this._output=r;else if(this._flags&M)this._output.add(r);else{let c=new Set;c.add(this._output),c.add(r),this._output=c,this._flags=(this._flags|M)&~N}let o=!1;r(L,(c,s)=>{if(c===W&&r(W,this._value),c===I&&s===pe&&!o&&(o=!0,this._singleDepCount++,this._flags&M||(this._flags|=N)),c===D){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&M){let i=this._output;i.delete(r),i.size===1?(this._output=i.values().next().value,this._flags&=~M,this._singleDepCount>0&&(this._flags|=N)):i.size===0&&(this._output=null,this._flags&=~(M|N),this._singleDepCount=0,this._flags=this._flags&~x|ae,this._stop())}else this._output===r&&(this._output=null,this._flags&=~N,this._singleDepCount=0,this._flags=this._flags&~x|ae,this._stop())}}),ve(()=>this._start())}}};function F(e,t){return new G(e,t)}var le=class extends G{constructor(t,n){super(void 0,{initial:t,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),P.register(this,{kind:"state",...n})}get(){return this._value}set(t){this._flags&$||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(oe()?this._flags&q||(this._flags|=q,this._flags&K&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),se(()=>{this._flags&=~q,this._flags=this._flags&~x|Y,this._dispatch(W,this._value)})):(this._flags&K&&!(this._flags&N)&&(this._flags=this._flags&~x|U,this._dispatch(I,j)),this._flags=this._flags&~x|Y,this._dispatch(W,this._value))))}update(t){this.set(t(this._value))}};function v(e,t){return new le(e,t)}function z(e,t,n){let r=null;_e(),e.source(L,(c,s)=>{if(c===L&&(r=s),c===D){r=null,n?.onEnd?.(s);return}if(c===1){let i=s,l=o;o=i,t(i,l)}});let o;try{o=e.get()}catch{}return ke(),()=>r?.(D)}function V(e,t){let n=t?.initialStatus??"pending",r=v(n,{name:"withStatus:status",equals:Object.is}),o=v(void 0,{name:"withStatus:error",equals:Object.is}),c=F(({emit:i,complete:l,error:f})=>{r.set(n),o.set(void 0);let u=z(e,a=>{r.get()==="errored"?C(()=>{o.set(void 0),r.set("active")}):r.set("active"),i(a)},{onEnd:a=>{if(a!==void 0){let p=a instanceof Error?a:new Error(String(a));C(()=>{o.set(p),r.set("errored")}),f(a)}else r.set("completed"),l()}});return()=>{u()}},{initial:e.get(),resubscribable:!0}),s={get:()=>e.get(),source:(i,l)=>c.source(i,l),get _status(){return c._status},status:r,error:o};return P.register(s,{kind:"withStatus"}),s}function xe(e,t){let n=t?.name??"http",r=t?.method??"GET",o=t?.headers,c=t?.body,s=t?.poll??0,i=t?.transform??(k=>k.json()),l=t?.timeout??3e4,f=v(0,{name:`${n}:fetchCount`}),u=null,a=null,p=null,y=null,_=null,h=!1;async function T(){if(!h||!u)return;_=new AbortController;let k=[_.signal];t?.signal&&k.push(t.signal);let E=new AbortController;for(let b of k){if(b.aborted){E.abort(b.reason);break}b.addEventListener("abort",()=>E.abort(b.reason),{once:!0})}let w=setTimeout(()=>E.abort(new Error("Request timeout")),l);try{let b=c!==void 0?typeof c=="string"?c:JSON.stringify(c):void 0,A=await fetch(e,{method:r,headers:o,body:b,signal:E.signal});if(!h)return;if(!A.ok)throw new Error(`HTTP ${A.status}: ${A.statusText}`);let O=await i(A);if(!h)return;C(()=>{f.update(R=>R+1),u?.(O)})}catch(b){if(!h||b?.name==="AbortError")return;a?.(b)}finally{clearTimeout(w),_=null}}function m(){!h||s<=0||(y=setTimeout(()=>{y=null,T().then(()=>{h&&m()}).catch(()=>{})},s))}let g=null,d=F(({emit:k,error:E,complete:w})=>(u=k,a=E,p=w,h=!0,g=()=>{T()},T().then(()=>{h&&m()}),()=>{h=!1,u=null,a=null,p=null,g=null,_?.abort(),_=null,y!==null&&(clearTimeout(y),y=null)}),{name:n,kind:"http"}),S=V(d);return{get:()=>S.get(),source:(k,E)=>S.source(k,E),status:S.status,error:S.error,fetchCount:f,refetch(){g?.()},stop(){h=!1,_?.abort(),_=null,y!==null&&(clearTimeout(y),y=null),p?.()}}}function Ue(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function ze(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function Ve(e,t,n,r){let o={model:t,messages:n,stream:!0};return r?.temperature!==void 0&&(o.temperature=r.temperature),r?.maxTokens!==void 0&&(e==="ollama"?o.options={num_predict:r.maxTokens}:o.max_tokens=r.maxTokens),r?.stop&&(o.stop=r.stop),o}function Ye(e,t){let n={"Content-Type":"application/json"};return t&&(n.Authorization=`Bearer ${t}`),n}function Re(e){let t=e.name??"llm",n=e.provider,r=e.baseURL??Ue(n),o=e.model??"",c=e.fetch??globalThis.fetch,s=v("",{name:`${t}.store`}),i=v({},{name:`${t}.tokens`}),l=v("pending",{name:`${t}.status`}),f=v(void 0,{name:`${t}.error`}),u=null;function a(){u&&(u.abort(),u=null),l.get()==="active"&&C(()=>{s.set(""),l.set("pending")})}function p(_,h){a(),u=new AbortController;let T=h?.signal?Qe(u.signal,h.signal):u.signal;C(()=>{s.set(""),i.set({}),f.set(void 0),l.set("active")});let m=ze(n,r),g=Ve(n,o,_,h),d=Ye(n,e.apiKey);y(m,d,g,T).catch(()=>{})}async function y(_,h,T,m){try{let g=await c(_,{method:"POST",headers:h,body:JSON.stringify(T),signal:m});if(!g.ok){let w=await g.text().catch(()=>"");throw new Error(`LLM API error ${g.status}: ${w}`)}let d=g.body?.getReader();if(!d)throw new Error("No response body");let S=new TextDecoder,k="",E="";for(;;){if(m.aborted)return;let{done:w,value:b}=await d.read();if(w)break;E+=S.decode(b,{stream:!0});let A=E.split(`
5
- `);E=A.pop()??"";for(let O of A){if(m.aborted)return;let R=O.trim();if(!R||R.startsWith(":")||!R.startsWith("data: "))continue;let J=R.slice(6);if(J!=="[DONE]")try{let B=JSON.parse(J),Q=Ge(n,B);Q&&(k+=Q,s.set(k));let fe=Je(n,B);fe&&i.set(fe)}catch{}}}if(S.decode(),m.aborted)return;l.set("completed"),u=null}catch(g){if(m.aborted)return;C(()=>{f.set(g),l.set("errored")}),u=null}finally{m._cleanup?.()}}return{get:()=>s.get(),source:(_,h)=>s.source(_,h),tokens:i,status:l,error:f,generate:p,abort:a}}function Ge(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function Je(e,t){let n=e==="ollama"?t:t?.usage;if(n){if(e==="ollama")return t.eval_count!==void 0||t.prompt_eval_count!==void 0?{promptTokens:t.prompt_eval_count,completionTokens:t.eval_count,totalTokens:(t.prompt_eval_count??0)+(t.eval_count??0)}:void 0;if(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function Qe(e,t){let n=new AbortController,r=()=>{e.removeEventListener("abort",o),t.removeEventListener("abort",o)},o=()=>{n.abort(),r()};e.addEventListener("abort",o,{once:!0}),t.addEventListener("abort",o,{once:!0});let c=n.signal;return c._cleanup=r,c}function De(e){let t=e.name??"mcp",n=e.client,r=v([],{name:`${t}.tools`}),o=v([],{name:`${t}.resources`}),c=v(void 0,{name:`${t}.refreshError`});function s(f){c.set(f);let u=e.onRefreshError;if(u==="warn")console.warn(`[${t}] refresh error:`,f);else{if(u==="error")throw f;typeof u=="function"&&u(f)}}async function i(){if(c.set(void 0),n.listTools)try{let f=await n.listTools();r.set(f.tools)}catch(f){s(f)}if(n.listResources)try{let f=await n.listResources();o.set(f.resources)}catch(f){s(f)}}function l(f){let u=`${t}:${f}`,a=v(void 0,{name:`${u}.result`}),p=v("idle",{name:`${u}.status`}),y=v(void 0,{name:`${u}.error`}),_=v(void 0,{name:`${u}.lastArgs`}),h=v(void 0,{name:`${u}.duration`}),T=!1;async function m(g){if(T)return;T=!0,C(()=>{_.set(g),y.set(void 0),p.set("active")});let d=Date.now();try{let S=await n.callTool({name:f,arguments:g}),k=Date.now()-d;if(S.isError){let b=S.content.filter(O=>O.type==="text").map(O=>O.text??"").join(`
6
- `),A=new Error(b||"MCP tool returned error");C(()=>{h.set(k),y.set(A),p.set("errored")});return}let E=S.content.filter(b=>b.type==="text"),w;if(E.length===1){let b=E[0].text;if(b!==void 0)try{w=JSON.parse(b)}catch{w=b}}else E.length>1?w=E.map(b=>b.text??""):w=S.content;C(()=>{h.set(k),a.set(w),p.set("completed")})}catch(S){let k=Date.now()-d;C(()=>{h.set(k),y.set(S),p.set("errored")})}finally{T=!1}}return{get:()=>a.get(),source:(g,d)=>a.source(g,d),status:p,error:y,call:m,lastArgs:_,duration:h}}return{tool:l,tools:r,resources:o,refresh:i,refreshError:c}}function Ce(e,t){let n=t?.path??"/",r=t?.name??"sse",o=t?.hostname??"0.0.0.0",c=t?.serialize??JSON.stringify,s=t?.eventName??"message",i=t?.pingInterval??3e4,l=v(0,{name:`${r}:connections`}),f=new Set,u=new Map,a=null;function p(){a||(a=z(e,g=>{let d=c(g),S=`event: ${s}
7
- data: ${d}
1
+ "use strict";var Ne=Object.create;var ne=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty;var qe=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},he=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ue(t))!Fe.call(e,o)&&o!==n&&ne(e,o,{get:()=>t[o],enumerable:!(r=je(t,o))||r.enumerable});return e};var Be=(e,t,n)=>(n=e!=null?Ne(He(e)):{},he(t||!e||!e.__esModule?ne(n,"default",{value:e,enumerable:!0}):n,e)),Ke=e=>he(ne({},"__esModule",{value:!0}),e);var rt={};qe(rt,{fromHTTP:()=>Ce,fromLLM:()=>Ae,fromMCP:()=>Oe,fromWebSocket:()=>We,fromWebhook:()=>$e,toSSE:()=>Me,toWebSocket:()=>Ie});module.exports=Ke(rt);var H=Symbol("DIRTY"),ae=Symbol("RESOLVED"),Se=Symbol("SINGLE_DEP"),N=Symbol("RESET"),K=Symbol("PAUSE"),z=Symbol("RESUME"),pe=Symbol("TEARDOWN");function Te(e){return e===N||e===K||e===z||e===pe}var ye=0,be=1,_e=2,ke=3,ve=4,Ee=5,F=7,ge=7<<F,ze=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function we(e){return ze[(e&ge)>>>F]}var M=0,j=1,D=2,$=3,re=0,oe=[],de=!1;function P(e){re++;try{return e()}finally{if(re--,re===0&&!de){de=!0;for(let t=0;t<oe.length;t++)oe[t]();oe.length=0,de=!1}}}function le(){return re>0}function ue(e){oe.push(e)}var ie=0,se=[];function xe(){ie++}function Re(){if(ie--,ie===0){for(let e=0;e<se.length;e++)se[e]();se.length=0}}function Le(e){ie>0?se.push(e):e()}var C=class e{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(e._explicitEnabled!==null)return e._explicitEnabled;if(e._cachedDefault!==null)return e._cachedDefault;try{e._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{e._cachedDefault=!0}return e._cachedDefault}static set enabled(t){e._explicitEnabled=t}static _depSuffix(t){if(!t?.length)return;let r=t.map(o=>e._names.get(o)??"?").join(",");return r.length>40?`${r.slice(0,37)}...`:r}static _resolveKey(t){let n=e._keys.get(t)??e._names.get(t);if(n)return n;let r=`anonymous_${e._nextId++}`;return e._keys.set(t,r),r}static register(t,n){if(!e.enabled)return;n?.name&&e._names.set(t,n.name),n?.kind&&e._kinds.set(t,n.kind);let r=e._nextId++,o=n?.name;if(!(o&&!e._usedKeys.has(o)))if(o){let a=e._depSuffix(n?.deps);o=a?`${o}(${a})`:`${o}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}else{let a=n?.kind??"store",i=e._depSuffix(n?.deps);o=i?`${a}(${i})`:`${a}_${r}`,e._usedKeys.has(o)&&(o=`${o}_${r}`)}e._usedKeys.add(o),e._keys.set(t,o),e._stores.add(new WeakRef(t))}static registerEdge(t,n){if(!e.enabled)return;let r=e._resolveKey(t),o=e._resolveKey(n),a=e._edges.get(r);a?a.includes(o)||a.push(o):e._edges.set(r,[o])}static getEdges(){return new Map(e._edges)}static getName(t){if(e.enabled)return e._names.get(t)}static getKind(t){return e._kinds.get(t)}static inspect(t){return{name:e._names.get(t),kind:e._kinds.get(t)??"unknown",value:typeof t.get=="function"?t.get():void 0,status:t._status}}static graph(){let t=new Map,n=new Set;for(let r of e._stores){let o=r.deref();if(!o){e._stores.delete(r);continue}let a=e._resolveKey(o);n.add(a),t.set(a,e.inspect(o))}for(let[r,o]of e._edges){if(!n.has(r)){e._edges.delete(r),e._usedKeys.delete(r);continue}let a=o.filter(i=>n.has(i));a.length===0?e._edges.delete(r):a.length!==o.length&&e._edges.set(r,a)}return t}static trace(t,n){let r=null,o=t.get();return t.source(M,(a,i)=>{if(a===M&&(r=i),a===D){r=null;return}if(a===1){let s=i;if(!Object.is(s,o)){let c=o;o=s,n(s,c)}}}),()=>r?.(D)}static dumpGraph(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let[i,s]of n)for(let c of s){let f=r.get(c);f?f.includes(i)||f.push(i):r.set(c,[i])}let o=[];for(let[i,s]of t){let c=r.get(i),f=n.get(i),u=c?.length?` \u2190 [${c.join(", ")}]`:"",l=f?.length?` \u2192 [${f.join(", ")}]`:"";o.push(` ${i} (${s.kind}) = ${JSON.stringify(s.value)} [${s.status??"?"}]${u}${l}`)}return[`Store Graph (${t.size} nodes):`,...o].join(`
2
+ `)}static _observe(t,n,r){let o=null,a=n??e.getName(t),i={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:a,dispose:()=>o?.(D)};return t.source(M,(s,c)=>{if(s===M){o=c;return}s===j?(i.values.push(c),i.events.push({type:"data",data:c}),r&&r(`[${a}] DATA:`,c)):s===$?(i.signals.push(c),i.events.push({type:"signal",data:c}),c===H?i.dirtyCount++:c===ae&&i.resolvedCount++,r&&r(`[${a}] STATE:`,c)):s===D&&(i.ended=!0,i.endError=c,i.events.push({type:"end",data:c}),r&&r(`[${a}] END`,c!==void 0?c:""),o=null)}),i}static observe(t){return e._observe(t)}static tap(t,n){let r=n??`tap(${e.getName(t)??"anon"})`,o={get:()=>t.get(),source:t.source};return e.register(o,{name:r,kind:"tap"}),e.registerEdge(t,o),o}static spy(t,n){let r=n?.name??e.getName(t)??"spy",o=n?.log??console.log;return e._observe(t,r,o)}static snapshot(){let t=e.graph(),n=e.getEdges(),r=new Map;for(let i of e._stores){let s=i.deref();if(!s)continue;let c=e._annotations.get(s);c!==void 0&&r.set(e._resolveKey(s),c)}let o=[];for(let[i,s]of t){let c={name:i,kind:s.kind,value:s.value,status:s.status},f=r.get(i);f!==void 0&&(c.annotation=f),o.push(c)}let a=[];for(let[i,s]of n)for(let c of s)a.push({from:i,to:c});return{nodes:o,edges:a,trace:e.traceLog()}}static toMermaid(t){let n=t?.direction??"TD",r=e.snapshot(),o=[`graph ${n}`],a={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},i=new Map;function s(u){let l=u.replace(/[^a-zA-Z0-9_]/g,"_"),g=i.get(l);return g===void 0?(i.set(l,1),l):(i.set(l,g+1),`${l}__${g}`)}let c=new Map;function f(u){let l=JSON.stringify(u);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let u of r.nodes){let l=s(u.name);c.set(u.name,l);let g=`${u.name} (${u.kind}) = ${f(u.value)}`,m=a[u.status??""]??"";o.push(` ${l}["${g}"]${m}`)}for(let u of r.edges){let l=c.get(u.from)??s(u.from),g=c.get(u.to)??s(u.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 n=t?.direction??"down",r=e.snapshot(),o=[`direction: ${n}`,""],a={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},i=new Map;function s(u){let l=u.replace(/[^a-zA-Z0-9_]/g,"_"),g=i.get(l);return g===void 0?(i.set(l,1),l):(i.set(l,g+1),`${l}__${g}`)}let c=new Map;function f(u){let l=JSON.stringify(u);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let u of r.nodes){let l=s(u.name);c.set(u.name,l);let g=a[u.kind]??"rectangle",m=`${u.name} (${u.kind}) = ${f(u.value)}`,y=u.status?` [${u.status}]`:"";o.push(`${l}: "${m}${y}" { shape: ${g} }`)}r.edges.length>0&&o.push("");for(let u of r.edges){let l=c.get(u.from)??s(u.from),g=c.get(u.to)??s(u.to);o.push(`${l} -> ${g}`)}return o.join(`
4
+ `)}static annotate(t,n){if(!e.enabled)return;e._annotations.set(t,n);let r={node:e._resolveKey(t),reason:n,timestamp:Date.now()},o=e.maxTraceEntries;o<=0||(e._traceLog.length<o?e._traceLog.push(r):(e._traceLog[e._traceHead]=r,e._traceFull=!0),e._traceHead=(e._traceHead+1)%o)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var ce=1,I=64,W=2,V=4,De=8,Pe=16,q=32,U=1024,R=ge,Y=be<<F,Z=_e<<F,fe=ye<<F,Je=ve<<F,Ve=Ee<<F,Ye=ke<<F,X=class{_value;_output=null;_flags;get _status(){return we(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,n){this._value=n?.initial,this._fn=t,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let r=0;n?.autoDirty!==!1&&(r|=V),n?.resetOnTeardown&&(r|=De),n?.resubscribable&&(r|=Pe),this._flags=r,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||C.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,n){let r=this._output;if(r)if(this._flags&I)for(let o of r)o(t,n);else r(t,n)}emit(t){this._flags&W||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(le()?this._flags&q||(this._flags|=q,this._flags&V&&(this._flags=this._flags&~R|Y,this._dispatch($,H)),ue(()=>{this._flags&=~q,this._flags=this._flags&~R|Z,this._dispatch(j,this._value)})):(this._flags&V&&!(this._flags&U)&&(this._flags=this._flags&~R|Y,this._dispatch($,H)),this._flags=this._flags&~R|Z,this._dispatch(j,this._value))))}signal(t){this._flags&W||!this._output||(t===H?this._flags=this._flags&~R|Y:t===ae&&(this._flags=this._flags&~R|Ye),this._dispatch($,t))}complete(){if(this._flags&W)return;this._flags=(this._flags|W)&~R|Je;let t=this._output,n=this._flags&I;if(this._output=null,this._flags&=~(I|U),this._singleDepCount=0,this._stop(),t)if(n)for(let r of t)r(D);else t(D)}error(t){if(this._flags&W)return;this._flags=(this._flags|W)&~R|Ve;let n=this._output,r=this._flags&I;if(this._output=null,this._flags&=~(I|U),this._singleDepCount=0,this._stop(),n)if(r)for(let o of n)o(D,t);else n(D,t)}_start(){if(this._flags&ce||!this._fn)return;this._flags|=ce,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n),onSignal:n=>{this._onLifecycleSignal=n}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&ce&&(this._flags&=~ce,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&De&&(this._value=this._initial),this._flags&W||(this._flags=this._flags&~R|fe))}_handleLifecycleSignal(t){if(!(this._flags&W)){if(t===pe){this._onLifecycleSignal?.(t),this.complete();return}t===N&&(this._value=this._initial,this._flags&=~q),this._onLifecycleSignal?.(t),t===N&&this.emit(this._initial)}}source(t,n){if(t===M){let r=n;if(this._flags&W)if(this._flags&Pe&&this._output===null)this._flags=this._flags&~(W|R)|fe;else{r(M,a=>{}),r(D);return}if(this._output===null)this._output=r;else if(this._flags&I)this._output.add(r);else{let a=new Set;a.add(this._output),a.add(r),this._output=a,this._flags=(this._flags|I)&~U}let o=!1;r(M,(a,i)=>{if(a===j&&r(j,this._value),a===$){i===Se&&!o?(o=!0,this._singleDepCount++,this._flags&I||(this._flags|=U)):Te(i)&&this._handleLifecycleSignal(i);return}if(a===D){if(o&&(o=!1,this._singleDepCount--),this._output===null)return;if(this._flags&I){let s=this._output;s.delete(r),s.size===1?(this._output=s.values().next().value,this._flags&=~I,this._singleDepCount>0&&(this._flags|=U)):s.size===0&&(this._output=null,this._flags&=~(I|U),this._singleDepCount=0,this._flags=this._flags&~R|fe,this._stop())}else this._output===r&&(this._output=null,this._flags&=~U,this._singleDepCount=0,this._flags=this._flags&~R|fe,this._stop())}}),Le(()=>this._start())}}};function B(e,t){return new X(e,t)}var me=class extends X{constructor(t,n){super(void 0,{initial:t,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),C.register(this,{kind:"state",...n})}get(){return this._value}set(t){this._flags&W||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(le()?this._flags&q||(this._flags|=q,this._flags&V&&(this._flags=this._flags&~R|Y,this._dispatch($,H)),ue(()=>{this._flags&=~q,this._flags=this._flags&~R|Z,this._dispatch(j,this._value)})):(this._flags&V&&!(this._flags&U)&&(this._flags=this._flags&~R|Y,this._dispatch($,H)),this._flags=this._flags&~R|Z,this._dispatch(j,this._value))))}update(t){this.set(t(this._value))}};function v(e,t){return new me(e,t)}function G(e,t,n){let r=null;xe(),e.source(M,(a,i)=>{if(a===M&&(r=i),a===D){r=null,n?.onEnd?.(i);return}if(a===1){let s=i,c=o;o=s,t(s,c)}});let o;try{o=e.get()}catch{}return Re(),{unsubscribe(){r?.(D),r=null},signal(a){r?.($,a)}}}function Q(e,t){let n=t?.initialStatus??"pending",r=v(n,{name:"withStatus:status",equals:Object.is}),o=v(void 0,{name:"withStatus:error",equals:Object.is}),a=B(({emit:s,complete:c,error:f})=>{r.set(n),o.set(void 0);let u=G(e,l=>{r.get()==="errored"?P(()=>{o.set(void 0),r.set("active")}):r.set("active"),s(l)},{onEnd:l=>{if(l!==void 0){let g=l instanceof Error?l:new Error(String(l));P(()=>{o.set(g),r.set("errored")}),f(l)}else r.set("completed"),c()}});return()=>{u.unsubscribe()}},{initial:e.get(),resubscribable:!0}),i={get:()=>e.get(),source:(s,c)=>a.source(s,c),get _status(){return a._status},status:r,error:o};return C.register(i,{kind:"withStatus"}),i}function Ce(e,t){let n=t?.name??"http",r=t?.method??"GET",o=t?.headers,a=t?.body,i=t?.poll??0,s=t?.transform??(w=>w.json()),c=t?.timeout??3e4,f=v(0,{name:`${n}:fetchCount`}),u=null,l=null,g=null,m=null,y=null,T=!1;async function x(){if(!T||!u)return;y=new AbortController;let w=[y.signal];t?.signal&&w.push(t.signal);let _=new AbortController;for(let E of w){if(E.aborted){_.abort(E.reason);break}E.addEventListener("abort",()=>_.abort(E.reason),{once:!0})}let k=setTimeout(()=>_.abort(new Error("Request timeout")),c);try{let E=a!==void 0?typeof a=="string"?a:JSON.stringify(a):void 0,L=await fetch(e,{method:r,headers:o,body:E,signal:_.signal});if(!T)return;if(!L.ok)throw new Error(`HTTP ${L.status}: ${L.statusText}`);let O=await s(L);if(!T)return;P(()=>{f.update(A=>A+1),u?.(O)})}catch(E){if(!T||E?.name==="AbortError")return;l?.(E)}finally{clearTimeout(k),y=null}}function h(){!T||p||i<=0||(m=setTimeout(()=>{m=null,x().then(()=>{T&&!p&&h()}).catch(()=>{})},i))}let d=null,p=!1,S=B(({emit:w,error:_,complete:k,onSignal:E})=>(u=w,l=_,g=k,T=!0,p=!1,d=()=>{x()},E(L=>{L===K?(p=!0,m!==null&&(clearTimeout(m),m=null)):L===z?(p=!1,h()):L===N&&(y?.abort(),y=null,m!==null&&(clearTimeout(m),m=null),f.set(0),p=!1,x().then(()=>{T&&!p&&h()}))}),x().then(()=>{T&&!p&&h()}),()=>{T=!1,p=!1,u=null,l=null,g=null,d=null,y?.abort(),y=null,m!==null&&(clearTimeout(m),m=null)}),{name:n,kind:"http"}),b=Q(S);return{get:()=>b.get(),source:(w,_)=>b.source(w,_),status:b.status,error:b.error,fetchCount:f,refetch(){d?.()},stop(){T=!1,y?.abort(),y=null,m!==null&&(clearTimeout(m),m=null),g?.()}}}function Ge(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function Qe(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function Ze(e,t,n,r){let o={model:t,messages:n,stream:!0};return r?.temperature!==void 0&&(o.temperature=r.temperature),r?.maxTokens!==void 0&&(e==="ollama"?o.options={num_predict:r.maxTokens}:o.max_tokens=r.maxTokens),r?.stop&&(o.stop=r.stop),o}function Xe(e,t){let n={"Content-Type":"application/json"};return t&&(n.Authorization=`Bearer ${t}`),n}function Ae(e){let t=e.name??"llm",n=e.provider,r=e.baseURL??Ge(n),o=e.model??"",a=e.fetch??globalThis.fetch,i=v("",{name:`${t}.store`}),s=v({},{name:`${t}.tokens`}),c=v("pending",{name:`${t}.status`}),f=v(void 0,{name:`${t}.error`}),u=null;function l(){u&&(u.abort(),u=null),c.get()==="active"&&P(()=>{i.set(""),c.set("pending")})}function g(y,T){l(),u=new AbortController;let x=T?.signal?nt(u.signal,T.signal):u.signal;P(()=>{i.set(""),s.set({}),f.set(void 0),c.set("active")});let h=Qe(n,r),d=Ze(n,o,y,T),p=Xe(n,e.apiKey);m(h,p,d,x).catch(()=>{})}async function m(y,T,x,h){try{let d=await a(y,{method:"POST",headers:T,body:JSON.stringify(x),signal:h});if(!d.ok){let _=await d.text().catch(()=>"");throw new Error(`LLM API error ${d.status}: ${_}`)}let p=d.body?.getReader();if(!p)throw new Error("No response body");let S=new TextDecoder,b="",w="";for(;;){if(h.aborted)return;let{done:_,value:k}=await p.read();if(_)break;w+=S.decode(k,{stream:!0});let E=w.split(`
5
+ `);w=E.pop()??"";for(let L of E){if(h.aborted)return;let O=L.trim();if(!O||O.startsWith(":")||!O.startsWith("data: "))continue;let A=O.slice(6);if(A!=="[DONE]")try{let ee=JSON.parse(A),J=et(n,ee);J&&(b+=J,i.set(b));let te=tt(n,ee);te&&s.set(te)}catch{}}}if(S.decode(),h.aborted)return;c.set("completed"),u=null}catch(d){if(h.aborted)return;P(()=>{f.set(d),c.set("errored")}),u=null}finally{h._cleanup?.()}}return{get:()=>i.get(),source:(y,T)=>i.source(y,T),tokens:s,status:c,error:f,generate:g,abort:l}}function et(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function tt(e,t){let n=e==="ollama"?t:t?.usage;if(n){if(e==="ollama")return t.eval_count!==void 0||t.prompt_eval_count!==void 0?{promptTokens:t.prompt_eval_count,completionTokens:t.eval_count,totalTokens:(t.prompt_eval_count??0)+(t.eval_count??0)}:void 0;if(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function nt(e,t){let n=new AbortController,r=()=>{e.removeEventListener("abort",o),t.removeEventListener("abort",o)},o=()=>{n.abort(),r()};e.addEventListener("abort",o,{once:!0}),t.addEventListener("abort",o,{once:!0});let a=n.signal;return a._cleanup=r,a}function Oe(e){let t=e.name??"mcp",n=e.client,r=v([],{name:`${t}.tools`}),o=v([],{name:`${t}.resources`}),a=v(void 0,{name:`${t}.refreshError`});function i(f){a.set(f);let u=e.onRefreshError;if(u==="warn")console.warn(`[${t}] refresh error:`,f);else{if(u==="error")throw f;typeof u=="function"&&u(f)}}async function s(){if(a.set(void 0),n.listTools)try{let f=await n.listTools();r.set(f.tools)}catch(f){i(f)}if(n.listResources)try{let f=await n.listResources();o.set(f.resources)}catch(f){i(f)}}function c(f){let u=`${t}:${f}`,l=v(void 0,{name:`${u}.result`}),g=v("idle",{name:`${u}.status`}),m=v(void 0,{name:`${u}.error`}),y=v(void 0,{name:`${u}.lastArgs`}),T=v(void 0,{name:`${u}.duration`}),x=!1;async function h(d){if(x)return;x=!0,P(()=>{y.set(d),m.set(void 0),g.set("active")});let p=Date.now();try{let S=await n.callTool({name:f,arguments:d}),b=Date.now()-p;if(S.isError){let k=S.content.filter(L=>L.type==="text").map(L=>L.text??"").join(`
6
+ `),E=new Error(k||"MCP tool returned error");P(()=>{T.set(b),m.set(E),g.set("errored")});return}let w=S.content.filter(k=>k.type==="text"),_;if(w.length===1){let k=w[0].text;if(k!==void 0)try{_=JSON.parse(k)}catch{_=k}}else w.length>1?_=w.map(k=>k.text??""):_=S.content;P(()=>{T.set(b),l.set(_),g.set("completed")})}catch(S){let b=Date.now()-p;P(()=>{T.set(b),m.set(S),g.set("errored")})}finally{x=!1}}return{get:()=>l.get(),source:(d,p)=>l.source(d,p),status:g,error:m,call:h,lastArgs:y,duration:T}}return{tool:c,tools:r,resources:o,refresh:s,refreshError:a}}function Me(e,t){let n=t?.path??"/",r=t?.name??"sse",o=t?.hostname??"0.0.0.0",a=t?.serialize??JSON.stringify,i=t?.eventName??"message",s=t?.pingInterval??3e4,c=v(0,{name:`${r}:connections`}),f=new Set,u=new Map,l=null;function g(){l||(l=G(e,d=>{let p=a(d),S=`event: ${i}
7
+ data: ${p}
8
8
 
9
- `;for(let k of f)try{k.write(S)}catch{y(k)}}))}function y(g){f.delete(g);let d=u.get(g);d&&(clearInterval(d),u.delete(g)),l.set(f.size),f.size===0&&a&&(a(),a=null)}function _(g,d){let S=g.method?.toUpperCase();if((g.url??"/").split("?")[0]!==n){d.writeHead(404,{"Content-Type":"text/plain"}),d.end("Not found");return}if(S==="OPTIONS"){d.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),d.end();return}if(S!=="GET"){d.writeHead(405,{"Content-Type":"text/plain"}),d.end("Method not allowed");return}d.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),d.write(`:ok
9
+ `;for(let b of f)try{b.write(S)}catch{m(b)}}))}function m(d){f.delete(d);let p=u.get(d);p&&(clearInterval(p),u.delete(d)),c.set(f.size),f.size===0&&l&&(l.unsubscribe(),l=null)}function y(d,p){let S=d.method?.toUpperCase();if((d.url??"/").split("?")[0]!==n){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}if(S==="OPTIONS"){p.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET","Access-Control-Allow-Headers":"Cache-Control"}),p.end();return}if(S!=="GET"){p.writeHead(405,{"Content-Type":"text/plain"}),p.end("Method not allowed");return}p.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Access-Control-Allow-Origin":"*"}),p.write(`:ok
10
10
 
11
- `),f.add(d),l.set(f.size);try{let w=e.get();if(w!==void 0){let b=c(w);d.write(`event: ${s}
12
- data: ${b}
11
+ `),f.add(p),c.set(f.size);try{let _=e.get();if(_!==void 0){let k=a(_);p.write(`event: ${i}
12
+ data: ${k}
13
13
 
14
- `)}}catch{}if(i>0){let w=setInterval(()=>{try{d.write(`:ping
14
+ `)}}catch{}if(s>0){let _=setInterval(()=>{try{p.write(`:ping
15
15
 
16
- `)}catch{y(d)}},i);u.set(d,w)}g.on("close",()=>y(d)),p()}let h=null;async function T(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(h)throw new Error("toSSE: already listening. Call close() first.");let g=await import("http");return new Promise((d,S)=>{h=g.createServer(_),h.once("listening",()=>d()),h.once("error",k=>{h=null,S(k)}),h.listen(t.port,o)})}function m(){for(let g of f)try{g.end()}catch{}f.clear();for(let g of u.values())clearInterval(g);u.clear(),l.set(0),a?.(),a=null,h?.close(),h=null}return P.register(l,{kind:"sse"}),{connectionCount:l,handler:_,listen:T,close:m}}function Pe(e){let t=e?.path??"/",n=e?.parse??JSON.parse,r=e?.name??"webhook",o=e?.hostname??"0.0.0.0",c=e?.maxBodySize??1024*1024,s=e?.responseTimeout??3e4,i=v(0,{name:`${r}:count`}),l=null,f=F(({emit:T})=>(l=T,()=>{l=null}),{name:r,kind:"webhook"});P.register(f,{kind:"webhook"});let u=V(f),a=null,p=new Set;function y(T,m){let g=T.method?.toUpperCase(),S=(T.url??"/").split("?")[0];if(g!=="POST"||S!==t){m.writeHead(404,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Not found"}));return}let k=[],E=0,w=!1;T.on("error",()=>{w=!0,m.headersSent||(m.writeHead(400,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Request aborted"})))}),T.on("data",b=>{if(!w){if(E+=b.length,E>c){w=!0,m.writeHead(413,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Payload too large"})),T.destroy?.();return}k.push(b)}}),T.on("end",()=>{if(!w)try{let b=Buffer.concat(k).toString("utf-8"),A=b.length>0?n(b):void 0;i.update(B=>B+1);let O=!1,R=null,J={body:A,get responded(){return O},respond(B,Q=200){O||(O=!0,R!==null&&(clearTimeout(R),p.delete(R),R=null),m.writeHead(Q,{"Content-Type":"application/json"}),m.end(JSON.stringify(B)))}};R=setTimeout(()=>{p.delete(R),R=null,O||(O=!0,m.writeHead(504,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:"Response timeout"})))},s),p.add(R),l?.(J)}catch(b){m.writeHead(400,{"Content-Type":"application/json"}),m.end(JSON.stringify({error:b?.message??"Parse error"}))}})}function _(){return e?.port?a?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):new Promise((T,m)=>{try{a=require("http").createServer(y),a.once("listening",()=>T()),a.once("error",d=>{a=null,m(d)}),a.listen(e.port,o)}catch(g){m(g)}}):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function h(){for(let T of p)clearTimeout(T);p.clear(),a?.close(),a=null}return{get:()=>u.get(),source:(T,m)=>u.source(T,m),status:u.status,error:u.error,requestCount:i,handler:y,listen:_,close:h}}function Oe(e,t){let n=t?.name??"websocket",r=t?.parse??(d=>d),o=t?.reconnect??!1,c=t?.onParseError??"warn",s=v("connecting",{name:`${n}:connectionState`,equals:()=>!1}),i=null,l=null,f=null,u=null,a=null,p=!1,y=null,_=[];function h(){for(;_.length>0&&i?.readyState===WebSocket.OPEN;)i.send(_.shift())}function T(){p=!1,s.set("connecting");try{i=new WebSocket(e,t?.protocols)}catch(d){s.set("closed"),f?.(d);return}i.onopen=()=>{s.set("open"),h()},i.onmessage=d=>{try{let S=r(d.data);l?.(S)}catch(S){c==="error"?f?.(S):c==="warn"&&console.warn(`[${n}] parse error:`,S)}},i.onerror=()=>{y=new Error(`WebSocket error on ${e}`)},i.onclose=()=>{s.set("closed"),i=null;let d=y;y=null,!p&&o!==!1?a=setTimeout(()=>{a=null,l&&T()},o):d&&!p?f?.(d):u?.()}}let m=F(({emit:d,error:S,complete:k})=>(l=d,f=S,u=k,T(),()=>{l=null,f=null,u=null,p=!0,_.length=0,a!==null&&(clearTimeout(a),a=null),i&&(i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(),i=null),s.set("closed")}),{name:n,kind:"websocket"});P.register(m,{kind:"websocket"});let g=V(m);return{get:()=>g.get(),source:(d,S)=>g.source(d,S),status:g.status,error:g.error,connectionState:s,send(d){i?.readyState===WebSocket.OPEN?i.send(d):_.push(d)},close(d,S){p=!0,_.length=0,a!==null&&(clearTimeout(a),a=null),i?.close(d,S)}}}function Le(e,t,n){let r=s=>typeof s=="string"?s:JSON.stringify(s),o=n?.serialize??r,c="send"in e&&typeof e.send=="function"?e.send.bind(e):null;if(!c)throw new Error("toWebSocket: invalid WebSocket target");return z(t,s=>{try{let i=o(s);c(i)}catch{}})}0&&(module.exports={fromHTTP,fromLLM,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
16
+ `)}catch{m(p)}},s);u.set(p,_)}d.on("close",()=>m(p)),g()}let T=null;async function x(){if(!t?.port)throw new Error("toSSE: port is required for listen()");if(T)throw new Error("toSSE: already listening. Call close() first.");let d=await import("http");return new Promise((p,S)=>{T=d.createServer(y),T.once("listening",()=>p()),T.once("error",b=>{T=null,S(b)}),T.listen(t.port,o)})}function h(){for(let d of f)try{d.end()}catch{}f.clear();for(let d of u.values())clearInterval(d);u.clear(),c.set(0),l?.unsubscribe(),l=null,T?.close(),T=null}return C.register(c,{kind:"sse"}),{connectionCount:c,handler:y,listen:x,close:h}}function $e(e){let t=e?.path??"/",n=e?.parse??JSON.parse,r=e?.name??"webhook",o=e?.hostname??"0.0.0.0",a=e?.maxBodySize??1024*1024,i=e?.responseTimeout??3e4,s=v(0,{name:`${r}:count`}),c=null,f=!1,u=B(({emit:h,onSignal:d})=>(c=h,f=!1,d(p=>{p===K?f=!0:p===z?f=!1:p===N&&(f=!1,s.set(0))}),()=>{c=null,f=!1}),{name:r,kind:"webhook"});C.register(u,{kind:"webhook"});let l=Q(u),g=null,m=new Set;function y(h,d){let p=h.method?.toUpperCase(),b=(h.url??"/").split("?")[0];if(p!=="POST"||b!==t){d.writeHead(404,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Not found"}));return}if(f){d.writeHead(503,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Service paused"}));return}let w=[],_=0,k=!1;h.on("error",()=>{k=!0,d.headersSent||(d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Request aborted"})))}),h.on("data",E=>{if(!k){if(_+=E.length,_>a){k=!0,d.writeHead(413,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Payload too large"})),h.destroy?.();return}w.push(E)}}),h.on("end",()=>{if(!k)try{let E=Buffer.concat(w).toString("utf-8"),L=E.length>0?n(E):void 0;s.update(J=>J+1);let O=!1,A=null,ee={body:L,get responded(){return O},respond(J,te=200){O||(O=!0,A!==null&&(clearTimeout(A),m.delete(A),A=null),d.writeHead(te,{"Content-Type":"application/json"}),d.end(JSON.stringify(J)))}};A=setTimeout(()=>{m.delete(A),A=null,O||(O=!0,d.writeHead(504,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:"Response timeout"})))},i),m.add(A),c?.(ee)}catch(E){d.writeHead(400,{"Content-Type":"application/json"}),d.end(JSON.stringify({error:E?.message??"Parse error"}))}})}function T(){return e?.port?g?Promise.reject(new Error("fromWebhook: already listening. Call close() first.")):new Promise((h,d)=>{try{g=require("http").createServer(y),g.once("listening",()=>h()),g.once("error",S=>{g=null,d(S)}),g.listen(e.port,o)}catch(p){d(p)}}):Promise.reject(new Error("fromWebhook: port is required for listen()"))}function x(){for(let h of m)clearTimeout(h);m.clear(),g?.close(),g=null}return{get:()=>l.get(),source:(h,d)=>l.source(h,d),status:l.status,error:l.error,requestCount:s,handler:y,listen:T,close:x}}function We(e,t){let n=t?.name??"websocket",r=t?.parse??(S=>S),o=t?.reconnect??!1,a=t?.onParseError??"warn",i=v("connecting",{name:`${n}:connectionState`,equals:()=>!1}),s=null,c=null,f=null,u=null,l=null,g=!1,m=null,y=[];function T(){for(;y.length>0&&s?.readyState===WebSocket.OPEN;)s.send(y.shift())}function x(){g=!1,i.set("connecting");try{s=new WebSocket(e,t?.protocols)}catch(S){i.set("closed"),f?.(S);return}s.onopen=()=>{i.set("open"),T()},s.onmessage=S=>{if(!h)try{let b=r(S.data);c?.(b)}catch(b){a==="error"?f?.(b):a==="warn"&&console.warn(`[${n}] parse error:`,b)}},s.onerror=()=>{m=new Error(`WebSocket error on ${e}`)},s.onclose=()=>{i.set("closed"),s=null;let S=m;m=null,!g&&o!==!1?l=setTimeout(()=>{l=null,c&&x()},o):S&&!g?f?.(S):u?.()}}let h=!1,d=B(({emit:S,error:b,complete:w,onSignal:_})=>(c=S,f=b,u=w,h=!1,x(),_(k=>{k===K?h=!0:k===z?h=!1:k===N&&(h=!1,y.length=0,l!==null&&(clearTimeout(l),l=null),s&&(g=!0,s.onopen=null,s.onmessage=null,s.onerror=null,s.onclose=null,s.close(),s=null),i.set("closed"),x())}),()=>{c=null,f=null,u=null,h=!1,g=!0,y.length=0,l!==null&&(clearTimeout(l),l=null),s&&(s.onopen=null,s.onmessage=null,s.onerror=null,s.onclose=null,s.close(),s=null),i.set("closed")}),{name:n,kind:"websocket"});C.register(d,{kind:"websocket"});let p=Q(d);return{get:()=>p.get(),source:(S,b)=>p.source(S,b),status:p.status,error:p.error,connectionState:i,send(S){s?.readyState===WebSocket.OPEN?s.send(S):y.push(S)},close(S,b){g=!0,y.length=0,l!==null&&(clearTimeout(l),l=null),s?.close(S,b)}}}function Ie(e,t,n){let r=i=>typeof i=="string"?i:JSON.stringify(i),o=n?.serialize??r,a="send"in e&&typeof e.send=="function"?e.send.bind(e):null;if(!a)throw new Error("toWebSocket: invalid WebSocket target");return G(t,i=>{try{let s=o(i);a(s)}catch{}})}0&&(module.exports={fromHTTP,fromLLM,fromMCP,fromWebSocket,fromWebhook,toSSE,toWebSocket});
@@ -4,6 +4,6 @@ export { MCPClientLike, MCPOptions, MCPResource, MCPResult, MCPToolInfo, MCPTool
4
4
  export { SSEOptions, SSEStore, toSSE } from './sse.cjs';
5
5
  export { WebhookOptions, WebhookRequest, WebhookStore, fromWebhook } from './webhook.cjs';
6
6
  export { FromWebSocketOptions, ToWebSocketOptions, WebSocketConnectionState, WebSocketStore, fromWebSocket, toWebSocket } from './websocket.cjs';
7
- import '../types-BwU0Zcuz.cjs';
8
- import '../protocol-BVxRx57r.cjs';
9
- import '../withStatus-BQCWdfrH.cjs';
7
+ import '../types-BohB8jJr.cjs';
8
+ import '../protocol-fwiQ1TAS.cjs';
9
+ import '../withStatus-ByT_R2Rz.cjs';
@@ -4,6 +4,6 @@ export { MCPClientLike, MCPOptions, MCPResource, MCPResult, MCPToolInfo, MCPTool
4
4
  export { SSEOptions, SSEStore, toSSE } from './sse.js';
5
5
  export { WebhookOptions, WebhookRequest, WebhookStore, fromWebhook } from './webhook.js';
6
6
  export { FromWebSocketOptions, ToWebSocketOptions, WebSocketConnectionState, WebSocketStore, fromWebSocket, toWebSocket } from './websocket.js';
7
- import '../types-DGII6w5S.js';
8
- import '../protocol-BVxRx57r.js';
9
- import '../withStatus-BJI4TOZV.js';
7
+ import '../types-CB1htCM8.js';
8
+ import '../protocol-fwiQ1TAS.js';
9
+ import '../withStatus---CFNir7.js';
@@ -1 +1 @@
1
- import{a as o}from"../chunk-27ALPEGS.js";import{a as e}from"../chunk-KWTA2EOH.js";import{a as t}from"../chunk-PUJBUJ22.js";import{a as r}from"../chunk-X6RLUCXO.js";import{a as p}from"../chunk-HIHLITY7.js";import{a as m,b as S}from"../chunk-G6E4ECVJ.js";import"../chunk-HE2JY76U.js";import"../chunk-YJXCVG35.js";import"../chunk-P5MXN4AF.js";import"../chunk-YN4VWXAF.js";import"../chunk-M76W372U.js";import"../chunk-CWP55MPE.js";import"../chunk-I7AUKTXE.js";export{o as fromHTTP,e as fromLLM,t as fromMCP,m as fromWebSocket,p as fromWebhook,r as toSSE,S as toWebSocket};
1
+ import{a as o}from"../chunk-3AE6AS32.js";import{a as e}from"../chunk-FV76ERZO.js";import{a as t}from"../chunk-CV6GBX5N.js";import{a as r}from"../chunk-NJEXVXD4.js";import{a as p}from"../chunk-D6NMIIMQ.js";import{a as m,b as S}from"../chunk-LJNELNJP.js";import"../chunk-GWRUTGV5.js";import"../chunk-GMLWTZFM.js";import"../chunk-KYY5ZPIG.js";import"../chunk-3CHC2PEC.js";import"../chunk-7MY7DDET.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,5 +1,5 @@
1
- "use strict";var z=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var yt=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},bt=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of St(e))!vt.call(t,i)&&i!==n&&z(t,i,{get:()=>e[i],enumerable:!(s=mt(e,i))||s.enumerable});return t};var Et=t=>bt(z({},"__esModule",{value:!0}),t);var jt={};yt(jt,{fromLLM:()=>At});module.exports=Et(jt);var v=Symbol("DIRTY"),j=Symbol("RESOLVED"),rt=Symbol("SINGLE_DEP"),ot=0,at=1,ct=2,ut=3,lt=4,dt=5,y=7,J=7<<y,kt=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function ft(t){return kt[(t&J)>>>y]}var b=0,T=1,p=2,m=3,N=0,C=[],B=!1;function K(t){N++;try{return t()}finally{if(N--,N===0&&!B){B=!0;for(let e=0;e<C.length;e++)C[e]();C.length=0,B=!1}}}function F(){return N>0}function U(t){C.push(t)}var Dt=0,xt=[];function gt(t){Dt>0?xt.push(t):t()}var R=class t{static _names=new WeakMap;static _kinds=new WeakMap;static _keys=new WeakMap;static _stores=new Set;static _edges=new Map;static _nextId=0;static _usedKeys=new Set;static _explicitEnabled=null;static _cachedDefault=null;static _annotations=new WeakMap;static _traceLog=[];static _traceHead=0;static _traceFull=!1;static maxTraceEntries=1e3;static get enabled(){if(t._explicitEnabled!==null)return t._explicitEnabled;if(t._cachedDefault!==null)return t._cachedDefault;try{t._cachedDefault=globalThis.process?.env?.NODE_ENV!=="production"}catch{t._cachedDefault=!0}return t._cachedDefault}static set enabled(e){t._explicitEnabled=e}static _depSuffix(e){if(!e?.length)return;let s=e.map(i=>t._names.get(i)??"?").join(",");return s.length>40?`${s.slice(0,37)}...`:s}static _resolveKey(e){let n=t._keys.get(e)??t._names.get(e);if(n)return n;let s=`anonymous_${t._nextId++}`;return t._keys.set(e,s),s}static register(e,n){if(!t.enabled)return;n?.name&&t._names.set(e,n.name),n?.kind&&t._kinds.set(e,n.kind);let s=t._nextId++,i=n?.name;if(!(i&&!t._usedKeys.has(i)))if(i){let o=t._depSuffix(n?.deps);i=o?`${i}(${o})`:`${i}_${s}`,t._usedKeys.has(i)&&(i=`${i}_${s}`)}else{let o=n?.kind??"store",r=t._depSuffix(n?.deps);i=r?`${o}(${r})`:`${o}_${s}`,t._usedKeys.has(i)&&(i=`${i}_${s}`)}t._usedKeys.add(i),t._keys.set(e,i),t._stores.add(new WeakRef(e))}static registerEdge(e,n){if(!t.enabled)return;let s=t._resolveKey(e),i=t._resolveKey(n),o=t._edges.get(s);o?o.includes(i)||o.push(i):t._edges.set(s,[i])}static getEdges(){return new Map(t._edges)}static getName(e){if(t.enabled)return t._names.get(e)}static getKind(e){return t._kinds.get(e)}static inspect(e){return{name:t._names.get(e),kind:t._kinds.get(e)??"unknown",value:typeof e.get=="function"?e.get():void 0,status:e._status}}static graph(){let e=new Map,n=new Set;for(let s of t._stores){let i=s.deref();if(!i){t._stores.delete(s);continue}let o=t._resolveKey(i);n.add(o),e.set(o,t.inspect(i))}for(let[s,i]of t._edges){if(!n.has(s)){t._edges.delete(s),t._usedKeys.delete(s);continue}let o=i.filter(r=>n.has(r));o.length===0?t._edges.delete(s):o.length!==i.length&&t._edges.set(s,o)}return e}static trace(e,n){let s=null,i=e.get();return e.source(b,(o,r)=>{if(o===b&&(s=r),o===p){s=null;return}if(o===1){let u=r;if(!Object.is(u,i)){let a=i;i=u,n(u,a)}}}),()=>s?.(p)}static dumpGraph(){let e=t.graph(),n=t.getEdges(),s=new Map;for(let[r,u]of n)for(let a of u){let d=s.get(a);d?d.includes(r)||d.push(r):s.set(a,[r])}let i=[];for(let[r,u]of e){let a=s.get(r),d=n.get(r),c=a?.length?` \u2190 [${a.join(", ")}]`:"",l=d?.length?` \u2192 [${d.join(", ")}]`:"";i.push(` ${r} (${u.kind}) = ${JSON.stringify(u.value)} [${u.status??"?"}]${c}${l}`)}return[`Store Graph (${e.size} nodes):`,...i].join(`
2
- `)}static _observe(e,n,s){let i=null,o=n??t.getName(e),r={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:o,dispose:()=>i?.(p)};return e.source(b,(u,a)=>{if(u===b){i=a;return}u===T?(r.values.push(a),r.events.push({type:"data",data:a}),s&&s(`[${o}] DATA:`,a)):u===m?(r.signals.push(a),r.events.push({type:"signal",data:a}),a===v?r.dirtyCount++:a===j&&r.resolvedCount++,s&&s(`[${o}] STATE:`,a)):u===p&&(r.ended=!0,r.endError=a,r.events.push({type:"end",data:a}),s&&s(`[${o}] END`,a!==void 0?a:""),i=null)}),r}static observe(e){return t._observe(e)}static tap(e,n){let s=n??`tap(${t.getName(e)??"anon"})`,i={get:()=>e.get(),source:e.source};return t.register(i,{name:s,kind:"tap"}),t.registerEdge(e,i),i}static spy(e,n){let s=n?.name??t.getName(e)??"spy",i=n?.log??console.log;return t._observe(e,s,i)}static snapshot(){let e=t.graph(),n=t.getEdges(),s=new Map;for(let r of t._stores){let u=r.deref();if(!u)continue;let a=t._annotations.get(u);a!==void 0&&s.set(t._resolveKey(u),a)}let i=[];for(let[r,u]of e){let a={name:r,kind:u.kind,value:u.value,status:u.status},d=s.get(r);d!==void 0&&(a.annotation=d),i.push(a)}let o=[];for(let[r,u]of n)for(let a of u)o.push({from:r,to:a});return{nodes:i,edges:o,trace:t.traceLog()}}static toMermaid(e){let n=e?.direction??"TD",s=t.snapshot(),i=[`graph ${n}`],o={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},r=new Map;function u(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),f=r.get(l);return f===void 0?(r.set(l,1),l):(r.set(l,f+1),`${l}__${f}`)}let a=new Map;function d(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of s.nodes){let l=u(c.name);a.set(c.name,l);let f=`${c.name} (${c.kind}) = ${d(c.value)}`,M=o[c.status??""]??"";i.push(` ${l}["${f}"]${M}`)}for(let c of s.edges){let l=a.get(c.from)??u(c.from),f=a.get(c.to)??u(c.to);i.push(` ${l} --> ${f}`)}return i.push(""),i.push(" classDef settled fill:#d4edda,stroke:#28a745"),i.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),i.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),i.push(" classDef completed fill:#cce5ff,stroke:#007bff"),i.join(`
3
- `)}static toD2(e){let n=e?.direction??"down",s=t.snapshot(),i=[`direction: ${n}`,""],o={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},r=new Map;function u(c){let l=c.replace(/[^a-zA-Z0-9_]/g,"_"),f=r.get(l);return f===void 0?(r.set(l,1),l):(r.set(l,f+1),`${l}__${f}`)}let a=new Map;function d(c){let l=JSON.stringify(c);return l&&l.length>30?`${l.slice(0,27)}...`:l??"undefined"}for(let c of s.nodes){let l=u(c.name);a.set(c.name,l);let f=o[c.kind]??"rectangle",M=`${c.name} (${c.kind}) = ${d(c.value)}`,D=c.status?` [${c.status}]`:"";i.push(`${l}: "${M}${D}" { shape: ${f} }`)}s.edges.length>0&&i.push("");for(let c of s.edges){let l=a.get(c.from)??u(c.from),f=a.get(c.to)??u(c.to);i.push(`${l} -> ${f}`)}return i.join(`
4
- `)}static annotate(e,n){if(!t.enabled)return;t._annotations.set(e,n);let s={node:t._resolveKey(e),reason:n,timestamp:Date.now()},i=t.maxTraceEntries;i<=0||(t._traceLog.length<i?t._traceLog.push(s):(t._traceLog[t._traceHead]=s,t._traceFull=!0),t._traceHead=(t._traceHead+1)%i)}static getAnnotation(e){return t._annotations.get(e)}static traceLog(){return t._traceFull?[...t._traceLog.slice(t._traceHead),...t._traceLog.slice(0,t._traceHead)]:t._traceLog.slice(0,t._traceHead||t._traceLog.length)}static clearTrace(){t._traceLog=[],t._traceHead=0,t._traceFull=!1}static _reset(){t._names=new WeakMap,t._kinds=new WeakMap,t._keys=new WeakMap,t._stores=new Set,t._edges=new Map,t._usedKeys=new Set,t._nextId=0,t._explicitEnabled=null,t._cachedDefault=null,t._annotations=new WeakMap,t._traceLog=[],t._traceHead=0,t._traceFull=!1,t.maxTraceEntries=1e3}};var W=1,h=64,_=2,w=4,pt=8,ht=16,L=32,S=1024,g=J,$=at<<y,I=ct<<y,Y=ot<<y,Lt=lt<<y,Rt=dt<<y,wt=ut<<y,V=class{_value;_output=null;_flags;get _status(){return ft(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;constructor(e,n){this._value=n?.initial,this._fn=e,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let s=0;n?.autoDirty!==!1&&(s|=w),n?.resetOnTeardown&&(s|=pt),n?.resubscribable&&(s|=ht),this._flags=s,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||R.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(e,n){let s=this._output;if(s)if(this._flags&h)for(let i of s)i(e,n);else s(e,n)}emit(e){this._flags&_||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(F()?this._flags&L||(this._flags|=L,this._flags&w&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),U(()=>{this._flags&=~L,this._flags=this._flags&~g|I,this._dispatch(T,this._value)})):(this._flags&w&&!(this._flags&S)&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),this._flags=this._flags&~g|I,this._dispatch(T,this._value))))}signal(e){this._flags&_||!this._output||(e===v?this._flags=this._flags&~g|$:e===j&&(this._flags=this._flags&~g|wt),this._dispatch(m,e))}complete(){if(this._flags&_)return;this._flags=(this._flags|_)&~g|Lt;let e=this._output,n=this._flags&h;if(this._output=null,this._flags&=~(h|S),this._singleDepCount=0,this._stop(),e)if(n)for(let s of e)s(p);else e(p)}error(e){if(this._flags&_)return;this._flags=(this._flags|_)&~g|Rt;let n=this._output,s=this._flags&h;if(this._output=null,this._flags&=~(h|S),this._singleDepCount=0,this._stop(),n)if(s)for(let i of n)i(p,e);else n(p,e)}_start(){if(this._flags&W||!this._fn)return;this._flags|=W;let e=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n)});this._cleanup=typeof e=="function"?e:void 0}_stop(){this._flags&W&&(this._flags&=~W,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&pt&&(this._value=this._initial),this._flags&_||(this._flags=this._flags&~g|Y))}source(e,n){if(e===b){let s=n;if(this._flags&_)if(this._flags&ht&&this._output===null)this._flags=this._flags&~(_|g)|Y;else{s(b,o=>{}),s(p);return}if(this._output===null)this._output=s;else if(this._flags&h)this._output.add(s);else{let o=new Set;o.add(this._output),o.add(s),this._output=o,this._flags=(this._flags|h)&~S}let i=!1;s(b,(o,r)=>{if(o===T&&s(T,this._value),o===m&&r===rt&&!i&&(i=!0,this._singleDepCount++,this._flags&h||(this._flags|=S)),o===p){if(i&&(i=!1,this._singleDepCount--),this._output===null)return;if(this._flags&h){let u=this._output;u.delete(s),u.size===1?(this._output=u.values().next().value,this._flags&=~h,this._singleDepCount>0&&(this._flags|=S)):u.size===0&&(this._output=null,this._flags&=~(h|S),this._singleDepCount=0,this._flags=this._flags&~g|Y,this._stop())}else this._output===s&&(this._output=null,this._flags&=~S,this._singleDepCount=0,this._flags=this._flags&~g|Y,this._stop())}}),gt(()=>this._start())}}};var Z=class extends V{constructor(e,n){super(void 0,{initial:e,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),R.register(this,{kind:"state",...n})}get(){return this._value}set(e){this._flags&_||this._value!==void 0&&this._eqFn(this._value,e)||(this._value=e,this._output&&(F()?this._flags&L||(this._flags|=L,this._flags&w&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),U(()=>{this._flags&=~L,this._flags=this._flags&~g|I,this._dispatch(T,this._value)})):(this._flags&w&&!(this._flags&S)&&(this._flags=this._flags&~g|$,this._dispatch(m,v)),this._flags=this._flags&~g|I,this._dispatch(T,this._value))))}update(e){this.set(e(this._value))}};function O(t,e){return new Z(t,e)}function $t(t){switch(t){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function Mt(t,e){switch(t){case"openai":case"custom":return`${e}/chat/completions`;case"ollama":return`${e}/api/chat`;default:return`${e}/chat/completions`}}function It(t,e,n,s){let i={model:e,messages:n,stream:!0};return s?.temperature!==void 0&&(i.temperature=s.temperature),s?.maxTokens!==void 0&&(t==="ollama"?i.options={num_predict:s.maxTokens}:i.max_tokens=s.maxTokens),s?.stop&&(i.stop=s.stop),i}function Ot(t,e){let n={"Content-Type":"application/json"};return e&&(n.Authorization=`Bearer ${e}`),n}function At(t){let e=t.name??"llm",n=t.provider,s=t.baseURL??$t(n),i=t.model??"",o=t.fetch??globalThis.fetch,r=O("",{name:`${e}.store`}),u=O({},{name:`${e}.tokens`}),a=O("pending",{name:`${e}.status`}),d=O(void 0,{name:`${e}.error`}),c=null;function l(){c&&(c.abort(),c=null),a.get()==="active"&&K(()=>{r.set(""),a.set("pending")})}function f(D,x){l(),c=new AbortController;let G=x?.signal?Ct(c.signal,x.signal):c.signal;K(()=>{r.set(""),u.set({}),d.set(void 0),a.set("active")});let E=Mt(n,s),k=It(n,i,D,x),A=Ot(n,t.apiKey);M(E,A,k,G).catch(()=>{})}async function M(D,x,G,E){try{let k=await o(D,{method:"POST",headers:x,body:JSON.stringify(G),signal:E});if(!k.ok){let q=await k.text().catch(()=>"");throw new Error(`LLM API error ${k.status}: ${q}`)}let A=k.body?.getReader();if(!A)throw new Error("No response body");let Q=new TextDecoder,X="",H="";for(;;){if(E.aborted)return;let{done:q,value:_t}=await A.read();if(q)break;H+=Q.decode(_t,{stream:!0});let tt=H.split(`
5
- `);H=tt.pop()??"";for(let Tt of tt){if(E.aborted)return;let P=Tt.trim();if(!P||P.startsWith(":")||!P.startsWith("data: "))continue;let et=P.slice(6);if(et!=="[DONE]")try{let nt=JSON.parse(et),st=Pt(n,nt);st&&(X+=st,r.set(X));let it=Nt(n,nt);it&&u.set(it)}catch{}}}if(Q.decode(),E.aborted)return;a.set("completed"),c=null}catch(k){if(E.aborted)return;K(()=>{d.set(k),a.set("errored")}),c=null}finally{E._cleanup?.()}}return{get:()=>r.get(),source:(D,x)=>r.source(D,x),tokens:u,status:a,error:d,generate:f,abort:l}}function Pt(t,e){return t==="ollama"?e?.message?.content:e?.choices?.[0]?.delta?.content}function Nt(t,e){let n=t==="ollama"?e:e?.usage;if(n){if(t==="ollama")return e.eval_count!==void 0||e.prompt_eval_count!==void 0?{promptTokens:e.prompt_eval_count,completionTokens:e.eval_count,totalTokens:(e.prompt_eval_count??0)+(e.eval_count??0)}:void 0;if(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function Ct(t,e){let n=new AbortController,s=()=>{t.removeEventListener("abort",i),e.removeEventListener("abort",i)},i=()=>{n.abort(),s()};t.addEventListener("abort",i,{once:!0}),e.addEventListener("abort",i,{once:!0});let o=n.signal;return o._cleanup=s,o}0&&(module.exports={fromLLM});
1
+ "use strict";var B=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var be=Object.prototype.hasOwnProperty;var De=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},ke=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ee(t))!be.call(e,i)&&i!==n&&B(e,i,{get:()=>t[i],enumerable:!(s=ve(t,i))||s.enumerable});return e};var Le=e=>ke(B({},"__esModule",{value:!0}),e);var Ye={};De(Ye,{fromLLM:()=>Ue});module.exports=Le(Ye);var y=Symbol("DIRTY"),j=Symbol("RESOLVED"),ae=Symbol("SINGLE_DEP"),U=Symbol("RESET"),xe=Symbol("PAUSE"),Re=Symbol("RESUME"),Z=Symbol("TEARDOWN");function ce(e){return e===U||e===xe||e===Re||e===Z}var le=0,ue=1,fe=2,de=3,ge=4,pe=5,v=7,Q=7<<v,we=["DISCONNECTED","DIRTY","SETTLED","RESOLVED","COMPLETED","ERRORED"];function he(e){return we[(e&Q)>>>v]}var E=0,S=1,p=2,T=3,N=0,C=[],J=!1;function K(e){N++;try{return e()}finally{if(N--,N===0&&!J){J=!0;for(let t=0;t<C.length;t++)C[t]();C.length=0,J=!1}}}function F(){return N>0}function W(e){C.push(e)}var $e=0,Ae=[];function _e(e){$e>0?Ae.push(e):e()}var R=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 s=t.map(i=>e._names.get(i)??"?").join(",");return s.length>40?`${s.slice(0,37)}...`:s}static _resolveKey(t){let n=e._keys.get(t)??e._names.get(t);if(n)return n;let s=`anonymous_${e._nextId++}`;return e._keys.set(t,s),s}static register(t,n){if(!e.enabled)return;n?.name&&e._names.set(t,n.name),n?.kind&&e._kinds.set(t,n.kind);let s=e._nextId++,i=n?.name;if(!(i&&!e._usedKeys.has(i)))if(i){let r=e._depSuffix(n?.deps);i=r?`${i}(${r})`:`${i}_${s}`,e._usedKeys.has(i)&&(i=`${i}_${s}`)}else{let r=n?.kind??"store",o=e._depSuffix(n?.deps);i=o?`${r}(${o})`:`${r}_${s}`,e._usedKeys.has(i)&&(i=`${i}_${s}`)}e._usedKeys.add(i),e._keys.set(t,i),e._stores.add(new WeakRef(t))}static registerEdge(t,n){if(!e.enabled)return;let s=e._resolveKey(t),i=e._resolveKey(n),r=e._edges.get(s);r?r.includes(i)||r.push(i):e._edges.set(s,[i])}static getEdges(){return new Map(e._edges)}static getName(t){if(e.enabled)return e._names.get(t)}static getKind(t){return e._kinds.get(t)}static inspect(t){return{name:e._names.get(t),kind:e._kinds.get(t)??"unknown",value:typeof t.get=="function"?t.get():void 0,status:t._status}}static graph(){let t=new Map,n=new Set;for(let s of e._stores){let i=s.deref();if(!i){e._stores.delete(s);continue}let r=e._resolveKey(i);n.add(r),t.set(r,e.inspect(i))}for(let[s,i]of e._edges){if(!n.has(s)){e._edges.delete(s),e._usedKeys.delete(s);continue}let r=i.filter(o=>n.has(o));r.length===0?e._edges.delete(s):r.length!==i.length&&e._edges.set(s,r)}return t}static trace(t,n){let s=null,i=t.get();return t.source(E,(r,o)=>{if(r===E&&(s=o),r===p){s=null;return}if(r===1){let l=o;if(!Object.is(l,i)){let a=i;i=l,n(l,a)}}}),()=>s?.(p)}static dumpGraph(){let t=e.graph(),n=e.getEdges(),s=new Map;for(let[o,l]of n)for(let a of l){let f=s.get(a);f?f.includes(o)||f.push(o):s.set(a,[o])}let i=[];for(let[o,l]of t){let a=s.get(o),f=n.get(o),c=a?.length?` \u2190 [${a.join(", ")}]`:"",u=f?.length?` \u2192 [${f.join(", ")}]`:"";i.push(` ${o} (${l.kind}) = ${JSON.stringify(l.value)} [${l.status??"?"}]${c}${u}`)}return[`Store Graph (${t.size} nodes):`,...i].join(`
2
+ `)}static _observe(t,n,s){let i=null,r=n??e.getName(t),o={values:[],signals:[],events:[],ended:!1,endError:void 0,dirtyCount:0,resolvedCount:0,name:r,dispose:()=>i?.(p)};return t.source(E,(l,a)=>{if(l===E){i=a;return}l===S?(o.values.push(a),o.events.push({type:"data",data:a}),s&&s(`[${r}] DATA:`,a)):l===T?(o.signals.push(a),o.events.push({type:"signal",data:a}),a===y?o.dirtyCount++:a===j&&o.resolvedCount++,s&&s(`[${r}] STATE:`,a)):l===p&&(o.ended=!0,o.endError=a,o.events.push({type:"end",data:a}),s&&s(`[${r}] END`,a!==void 0?a:""),i=null)}),o}static observe(t){return e._observe(t)}static tap(t,n){let s=n??`tap(${e.getName(t)??"anon"})`,i={get:()=>t.get(),source:t.source};return e.register(i,{name:s,kind:"tap"}),e.registerEdge(t,i),i}static spy(t,n){let s=n?.name??e.getName(t)??"spy",i=n?.log??console.log;return e._observe(t,s,i)}static snapshot(){let t=e.graph(),n=e.getEdges(),s=new Map;for(let o of e._stores){let l=o.deref();if(!l)continue;let a=e._annotations.get(l);a!==void 0&&s.set(e._resolveKey(l),a)}let i=[];for(let[o,l]of t){let a={name:o,kind:l.kind,value:l.value,status:l.status},f=s.get(o);f!==void 0&&(a.annotation=f),i.push(a)}let r=[];for(let[o,l]of n)for(let a of l)r.push({from:o,to:a});return{nodes:i,edges:r,trace:e.traceLog()}}static toMermaid(t){let n=t?.direction??"TD",s=e.snapshot(),i=[`graph ${n}`],r={SETTLED:":::settled",DIRTY:":::dirty",ERRORED:":::errored",COMPLETED:":::completed"},o=new Map;function l(c){let u=c.replace(/[^a-zA-Z0-9_]/g,"_"),d=o.get(u);return d===void 0?(o.set(u,1),u):(o.set(u,d+1),`${u}__${d}`)}let a=new Map;function f(c){let u=JSON.stringify(c);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let c of s.nodes){let u=l(c.name);a.set(c.name,u);let d=`${c.name} (${c.kind}) = ${f(c.value)}`,A=r[c.status??""]??"";i.push(` ${u}["${d}"]${A}`)}for(let c of s.edges){let u=a.get(c.from)??l(c.from),d=a.get(c.to)??l(c.to);i.push(` ${u} --> ${d}`)}return i.push(""),i.push(" classDef settled fill:#d4edda,stroke:#28a745"),i.push(" classDef dirty fill:#fff3cd,stroke:#ffc107"),i.push(" classDef errored fill:#f8d7da,stroke:#dc3545"),i.push(" classDef completed fill:#cce5ff,stroke:#007bff"),i.join(`
3
+ `)}static toD2(t){let n=t?.direction??"down",s=e.snapshot(),i=[`direction: ${n}`,""],r={state:"rectangle",derived:"hexagon",effect:"oval",producer:"rectangle",operator:"parallelogram","pipeline-step":"rectangle","pipeline-status":"diamond",checkpoint:"cylinder"},o=new Map;function l(c){let u=c.replace(/[^a-zA-Z0-9_]/g,"_"),d=o.get(u);return d===void 0?(o.set(u,1),u):(o.set(u,d+1),`${u}__${d}`)}let a=new Map;function f(c){let u=JSON.stringify(c);return u&&u.length>30?`${u.slice(0,27)}...`:u??"undefined"}for(let c of s.nodes){let u=l(c.name);a.set(c.name,u);let d=r[c.kind]??"rectangle",A=`${c.name} (${c.kind}) = ${f(c.value)}`,L=c.status?` [${c.status}]`:"";i.push(`${u}: "${A}${L}" { shape: ${d} }`)}s.edges.length>0&&i.push("");for(let c of s.edges){let u=a.get(c.from)??l(c.from),d=a.get(c.to)??l(c.to);i.push(`${u} -> ${d}`)}return i.join(`
4
+ `)}static annotate(t,n){if(!e.enabled)return;e._annotations.set(t,n);let s={node:e._resolveKey(t),reason:n,timestamp:Date.now()},i=e.maxTraceEntries;i<=0||(e._traceLog.length<i?e._traceLog.push(s):(e._traceLog[e._traceHead]=s,e._traceFull=!0),e._traceHead=(e._traceHead+1)%i)}static getAnnotation(t){return e._annotations.get(t)}static traceLog(){return e._traceFull?[...e._traceLog.slice(e._traceHead),...e._traceLog.slice(0,e._traceHead)]:e._traceLog.slice(0,e._traceHead||e._traceLog.length)}static clearTrace(){e._traceLog=[],e._traceHead=0,e._traceFull=!1}static _reset(){e._names=new WeakMap,e._kinds=new WeakMap,e._keys=new WeakMap,e._stores=new Set,e._edges=new Map,e._usedKeys=new Set,e._nextId=0,e._explicitEnabled=null,e._cachedDefault=null,e._annotations=new WeakMap,e._traceLog=[],e._traceHead=0,e._traceFull=!1,e.maxTraceEntries=1e3}};var Y=1,_=64,h=2,w=4,Se=8,Te=16,k=32,m=1024,g=Q,$=ue<<v,M=fe<<v,V=le<<v,Me=ge<<v,Oe=pe<<v,Ie=de<<v,G=class{_value;_output=null;_flags;get _status(){return he(this._flags)}_cleanup;_fn;_eqFn;_getterFn;_initial;_singleDepCount=0;_onLifecycleSignal;constructor(t,n){this._value=n?.initial,this._fn=t,this._eqFn=n?.equals,this._getterFn=n?.getter,this._initial=n?.initial;let s=0;n?.autoDirty!==!1&&(s|=w),n?.resetOnTeardown&&(s|=Se),n?.resubscribable&&(s|=Te),this._flags=s,this.source=this.source.bind(this),this.emit=this.emit.bind(this),n?._skipInspect||R.register(this,{kind:"producer",...n})}get(){return this._getterFn?this._getterFn(this._value):this._value}_dispatch(t,n){let s=this._output;if(s)if(this._flags&_)for(let i of s)i(t,n);else s(t,n)}emit(t){this._flags&h||this._eqFn&&this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(F()?this._flags&k||(this._flags|=k,this._flags&w&&(this._flags=this._flags&~g|$,this._dispatch(T,y)),W(()=>{this._flags&=~k,this._flags=this._flags&~g|M,this._dispatch(S,this._value)})):(this._flags&w&&!(this._flags&m)&&(this._flags=this._flags&~g|$,this._dispatch(T,y)),this._flags=this._flags&~g|M,this._dispatch(S,this._value))))}signal(t){this._flags&h||!this._output||(t===y?this._flags=this._flags&~g|$:t===j&&(this._flags=this._flags&~g|Ie),this._dispatch(T,t))}complete(){if(this._flags&h)return;this._flags=(this._flags|h)&~g|Me;let t=this._output,n=this._flags&_;if(this._output=null,this._flags&=~(_|m),this._singleDepCount=0,this._stop(),t)if(n)for(let s of t)s(p);else t(p)}error(t){if(this._flags&h)return;this._flags=(this._flags|h)&~g|Oe;let n=this._output,s=this._flags&_;if(this._output=null,this._flags&=~(_|m),this._singleDepCount=0,this._stop(),n)if(s)for(let i of n)i(p,t);else n(p,t)}_start(){if(this._flags&Y||!this._fn)return;this._flags|=Y,this._onLifecycleSignal=void 0;let t=this._fn({emit:this.emit,signal:n=>this.signal(n),complete:()=>this.complete(),error:n=>this.error(n),onSignal:n=>{this._onLifecycleSignal=n}});this._cleanup=typeof t=="function"?t:void 0}_stop(){this._flags&Y&&(this._flags&=~Y,this._onLifecycleSignal=void 0,this._cleanup&&this._cleanup(),this._cleanup=void 0,this._flags&Se&&(this._value=this._initial),this._flags&h||(this._flags=this._flags&~g|V))}_handleLifecycleSignal(t){if(!(this._flags&h)){if(t===Z){this._onLifecycleSignal?.(t),this.complete();return}t===U&&(this._value=this._initial,this._flags&=~k),this._onLifecycleSignal?.(t),t===U&&this.emit(this._initial)}}source(t,n){if(t===E){let s=n;if(this._flags&h)if(this._flags&Te&&this._output===null)this._flags=this._flags&~(h|g)|V;else{s(E,r=>{}),s(p);return}if(this._output===null)this._output=s;else if(this._flags&_)this._output.add(s);else{let r=new Set;r.add(this._output),r.add(s),this._output=r,this._flags=(this._flags|_)&~m}let i=!1;s(E,(r,o)=>{if(r===S&&s(S,this._value),r===T){o===ae&&!i?(i=!0,this._singleDepCount++,this._flags&_||(this._flags|=m)):ce(o)&&this._handleLifecycleSignal(o);return}if(r===p){if(i&&(i=!1,this._singleDepCount--),this._output===null)return;if(this._flags&_){let l=this._output;l.delete(s),l.size===1?(this._output=l.values().next().value,this._flags&=~_,this._singleDepCount>0&&(this._flags|=m)):l.size===0&&(this._output=null,this._flags&=~(_|m),this._singleDepCount=0,this._flags=this._flags&~g|V,this._stop())}else this._output===s&&(this._output=null,this._flags&=~m,this._singleDepCount=0,this._flags=this._flags&~g|V,this._stop())}}),_e(()=>this._start())}}};var X=class extends G{constructor(t,n){super(void 0,{initial:t,autoDirty:!0,equals:n?.equals??Object.is,_skipInspect:!0}),this.set=this.set.bind(this),R.register(this,{kind:"state",...n})}get(){return this._value}set(t){this._flags&h||this._value!==void 0&&this._eqFn(this._value,t)||(this._value=t,this._output&&(F()?this._flags&k||(this._flags|=k,this._flags&w&&(this._flags=this._flags&~g|$,this._dispatch(T,y)),W(()=>{this._flags&=~k,this._flags=this._flags&~g|M,this._dispatch(S,this._value)})):(this._flags&w&&!(this._flags&m)&&(this._flags=this._flags&~g|$,this._dispatch(T,y)),this._flags=this._flags&~g|M,this._dispatch(S,this._value))))}update(t){this.set(t(this._value))}};function O(e,t){return new X(e,t)}function Pe(e){switch(e){case"openai":return"https://api.openai.com/v1";case"ollama":return"http://localhost:11434";default:return""}}function Ne(e,t){switch(e){case"openai":case"custom":return`${t}/chat/completions`;case"ollama":return`${t}/api/chat`;default:return`${t}/chat/completions`}}function Ce(e,t,n,s){let i={model:t,messages:n,stream:!0};return s?.temperature!==void 0&&(i.temperature=s.temperature),s?.maxTokens!==void 0&&(e==="ollama"?i.options={num_predict:s.maxTokens}:i.max_tokens=s.maxTokens),s?.stop&&(i.stop=s.stop),i}function je(e,t){let n={"Content-Type":"application/json"};return t&&(n.Authorization=`Bearer ${t}`),n}function Ue(e){let t=e.name??"llm",n=e.provider,s=e.baseURL??Pe(n),i=e.model??"",r=e.fetch??globalThis.fetch,o=O("",{name:`${t}.store`}),l=O({},{name:`${t}.tokens`}),a=O("pending",{name:`${t}.status`}),f=O(void 0,{name:`${t}.error`}),c=null;function u(){c&&(c.abort(),c=null),a.get()==="active"&&K(()=>{o.set(""),a.set("pending")})}function d(L,x){u(),c=new AbortController;let H=x?.signal?We(c.signal,x.signal):c.signal;K(()=>{o.set(""),l.set({}),f.set(void 0),a.set("active")});let b=Ne(n,s),D=Ce(n,i,L,x),I=je(n,e.apiKey);A(b,I,D,H).catch(()=>{})}async function A(L,x,H,b){try{let D=await r(L,{method:"POST",headers:x,body:JSON.stringify(H),signal:b});if(!D.ok){let z=await D.text().catch(()=>"");throw new Error(`LLM API error ${D.status}: ${z}`)}let I=D.body?.getReader();if(!I)throw new Error("No response body");let ee=new TextDecoder,te="",q="";for(;;){if(b.aborted)return;let{done:z,value:me}=await I.read();if(z)break;q+=ee.decode(me,{stream:!0});let ne=q.split(`
5
+ `);q=ne.pop()??"";for(let ye of ne){if(b.aborted)return;let P=ye.trim();if(!P||P.startsWith(":")||!P.startsWith("data: "))continue;let se=P.slice(6);if(se!=="[DONE]")try{let ie=JSON.parse(se),oe=Ke(n,ie);oe&&(te+=oe,o.set(te));let re=Fe(n,ie);re&&l.set(re)}catch{}}}if(ee.decode(),b.aborted)return;a.set("completed"),c=null}catch(D){if(b.aborted)return;K(()=>{f.set(D),a.set("errored")}),c=null}finally{b._cleanup?.()}}return{get:()=>o.get(),source:(L,x)=>o.source(L,x),tokens:l,status:a,error:f,generate:d,abort:u}}function Ke(e,t){return e==="ollama"?t?.message?.content:t?.choices?.[0]?.delta?.content}function Fe(e,t){let n=e==="ollama"?t:t?.usage;if(n){if(e==="ollama")return t.eval_count!==void 0||t.prompt_eval_count!==void 0?{promptTokens:t.prompt_eval_count,completionTokens:t.eval_count,totalTokens:(t.prompt_eval_count??0)+(t.eval_count??0)}:void 0;if(n.prompt_tokens!==void 0||n.completion_tokens!==void 0)return{promptTokens:n.prompt_tokens,completionTokens:n.completion_tokens,totalTokens:n.total_tokens}}}function We(e,t){let n=new AbortController,s=()=>{e.removeEventListener("abort",i),t.removeEventListener("abort",i)},i=()=>{n.abort(),s()};e.addEventListener("abort",i,{once:!0}),t.addEventListener("abort",i,{once:!0});let r=n.signal;return r._cleanup=s,r}0&&(module.exports={fromLLM});
@@ -1,6 +1,6 @@
1
- import { S as Store } from '../types-BwU0Zcuz.cjs';
2
- import { W as WithStatusStatus } from '../withStatus-BQCWdfrH.cjs';
3
- import '../protocol-BVxRx57r.cjs';
1
+ import { S as Store } from '../types-BohB8jJr.cjs';
2
+ import { W as WithStatusStatus } from '../withStatus-ByT_R2Rz.cjs';
3
+ import '../protocol-fwiQ1TAS.cjs';
4
4
 
5
5
  interface LLMMessage {
6
6
  role: "user" | "assistant" | "system";
@@ -1,6 +1,6 @@
1
- import { S as Store } from '../types-DGII6w5S.js';
2
- import { W as WithStatusStatus } from '../withStatus-BJI4TOZV.js';
3
- import '../protocol-BVxRx57r.js';
1
+ import { S as Store } from '../types-CB1htCM8.js';
2
+ import { W as WithStatusStatus } from '../withStatus---CFNir7.js';
3
+ import '../protocol-fwiQ1TAS.js';
4
4
 
5
5
  interface LLMMessage {
6
6
  role: "user" | "assistant" | "system";
@@ -1 +1 @@
1
- import{a}from"../chunk-KWTA2EOH.js";import"../chunk-P5MXN4AF.js";import"../chunk-YN4VWXAF.js";import"../chunk-M76W372U.js";import"../chunk-CWP55MPE.js";import"../chunk-I7AUKTXE.js";export{a as fromLLM};
1
+ import{a}from"../chunk-FV76ERZO.js";import"../chunk-KYY5ZPIG.js";import"../chunk-3CHC2PEC.js";import"../chunk-7MY7DDET.js";import"../chunk-TUPD47IE.js";import"../chunk-I7AUKTXE.js";export{a as fromLLM};