thursday-agent 0.1.2 → 0.3.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 (573) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +5 -1
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/prerender-manifest.json +5 -5
  5. package/.next/routes-manifest.json +27 -3
  6. package/.next/server/app/_global-error/page.js +2 -2
  7. package/.next/server/app/_global-error/page.js.nft.json +1 -1
  8. package/.next/server/app/_global-error.html +1 -1
  9. package/.next/server/app/_global-error.rsc +2 -2
  10. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_full.segment.rsc +2 -2
  12. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  13. package/.next/server/app/_not-found/page.js +2 -2
  14. package/.next/server/app/_not-found/page.js.nft.json +1 -1
  15. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  16. package/.next/server/app/_not-found.html +1 -1
  17. package/.next/server/app/_not-found.rsc +14 -14
  18. package/.next/server/app/_not-found.segments/_full.segment.rsc +14 -14
  19. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +12 -12
  20. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  21. package/.next/server/app/api/artifact/route.js +3 -3
  22. package/.next/server/app/api/artifact/route.js.nft.json +1 -1
  23. package/.next/server/app/api/bot/memory/files/route/app-paths-manifest.json +3 -0
  24. package/.next/server/app/api/bot/memory/files/route.js +10 -0
  25. package/.next/server/app/api/bot/memory/files/route.js.nft.json +1 -0
  26. package/.next/server/app/api/bot/memory/files/route_client-reference-manifest.js +3 -0
  27. package/.next/server/app/api/bot/memory/route/app-paths-manifest.json +3 -0
  28. package/.next/server/app/api/bot/memory/route/build-manifest.json +12 -0
  29. package/.next/server/app/api/bot/memory/route/server-reference-manifest.json +4 -0
  30. package/.next/server/app/api/bot/memory/route.js +14 -0
  31. package/.next/server/app/api/bot/memory/route.js.map +5 -0
  32. package/.next/server/app/api/bot/memory/route.js.nft.json +1 -0
  33. package/.next/server/app/api/bot/memory/route_client-reference-manifest.js +3 -0
  34. package/.next/server/app/api/bot/route.js +7 -7
  35. package/.next/server/app/api/bot/route.js.nft.json +1 -1
  36. package/.next/server/app/api/bot/task/[id]/route.js +9 -9
  37. package/.next/server/app/api/bot/task/[id]/route.js.nft.json +1 -1
  38. package/.next/server/app/api/bot/task/route.js +8 -8
  39. package/.next/server/app/api/bot/task/route.js.nft.json +1 -1
  40. package/.next/server/app/api/config/route.js +6 -6
  41. package/.next/server/app/api/config/route.js.nft.json +1 -1
  42. package/.next/server/app/api/events/route.js +4 -5
  43. package/.next/server/app/api/events/route.js.nft.json +1 -1
  44. package/.next/server/app/api/file/[...path]/route.js +3 -3
  45. package/.next/server/app/api/file/[...path]/route.js.nft.json +1 -1
  46. package/.next/server/app/api/llm-model/catalog/route.js +10 -9
  47. package/.next/server/app/api/llm-model/catalog/route.js.nft.json +1 -1
  48. package/.next/server/app/api/llm-model/credits/route/app-paths-manifest.json +3 -0
  49. package/.next/server/app/api/llm-model/credits/route/build-manifest.json +12 -0
  50. package/.next/server/app/api/llm-model/credits/route/server-reference-manifest.json +4 -0
  51. package/.next/server/app/api/llm-model/credits/route.js +16 -0
  52. package/.next/server/app/api/llm-model/credits/route.js.map +5 -0
  53. package/.next/server/app/api/llm-model/credits/route.js.nft.json +1 -0
  54. package/.next/server/app/api/llm-model/credits/route_client-reference-manifest.js +3 -0
  55. package/.next/server/app/api/llm-model/route.js +10 -8
  56. package/.next/server/app/api/llm-model/route.js.nft.json +1 -1
  57. package/.next/server/app/api/llm-model/subscription/route/app-paths-manifest.json +3 -0
  58. package/.next/server/app/api/llm-model/subscription/route/build-manifest.json +12 -0
  59. package/.next/server/app/api/llm-model/subscription/route/server-reference-manifest.json +4 -0
  60. package/.next/server/app/api/llm-model/subscription/route.js +15 -0
  61. package/.next/server/app/api/llm-model/subscription/route.js.map +5 -0
  62. package/.next/server/app/api/llm-model/subscription/route.js.nft.json +1 -0
  63. package/.next/server/app/api/llm-model/subscription/route_client-reference-manifest.js +3 -0
  64. package/.next/server/app/api/mcp/[name]/route.js +5 -5
  65. package/.next/server/app/api/mcp/[name]/route.js.nft.json +1 -1
  66. package/.next/server/app/api/mcp/oauth/callback/route.js +6 -6
  67. package/.next/server/app/api/mcp/oauth/callback/route.js.nft.json +1 -1
  68. package/.next/server/app/api/mcp/route.js +5 -5
  69. package/.next/server/app/api/mcp/route.js.nft.json +1 -1
  70. package/.next/server/app/api/mcp/tools/route.js +5 -5
  71. package/.next/server/app/api/mcp/tools/route.js.nft.json +1 -1
  72. package/.next/server/app/api/memory/edit/route/app-paths-manifest.json +3 -0
  73. package/.next/server/app/api/memory/edit/route/build-manifest.json +12 -0
  74. package/.next/server/app/api/memory/edit/route/server-reference-manifest.json +4 -0
  75. package/.next/server/app/api/memory/edit/route.js +24 -0
  76. package/.next/server/app/api/memory/edit/route.js.map +5 -0
  77. package/.next/server/app/api/memory/edit/route.js.nft.json +1 -0
  78. package/.next/server/app/api/memory/{tidy → edit}/route_client-reference-manifest.js +1 -1
  79. package/.next/server/app/api/memory/route.js +7 -8
  80. package/.next/server/app/api/memory/route.js.nft.json +1 -1
  81. package/.next/server/app/api/skills/[source]/[name]/route.js +3 -3
  82. package/.next/server/app/api/skills/[source]/[name]/route.js.nft.json +1 -1
  83. package/.next/server/app/api/skills/route.js +3 -3
  84. package/.next/server/app/api/skills/route.js.nft.json +1 -1
  85. package/.next/server/app/api/thursday/call/route.js +9 -7
  86. package/.next/server/app/api/thursday/call/route.js.nft.json +1 -1
  87. package/.next/server/app/api/thursday/skills/route.js +9 -7
  88. package/.next/server/app/api/thursday/skills/route.js.nft.json +1 -1
  89. package/.next/server/app/api/thursday/tool-call/route.js +16 -15
  90. package/.next/server/app/api/thursday/tool-call/route.js.nft.json +1 -1
  91. package/.next/server/app/api/workspace/route.js +4 -5
  92. package/.next/server/app/api/workspace/route.js.nft.json +1 -1
  93. package/.next/server/app/artifact/[...path]/page/server-reference-manifest.json +1 -1
  94. package/.next/server/app/artifact/[...path]/page.js +5 -6
  95. package/.next/server/app/artifact/[...path]/page.js.nft.json +1 -1
  96. package/.next/server/app/artifact/[...path]/page_client-reference-manifest.js +1 -1
  97. package/.next/server/app/favicon.ico/route.js +3 -4
  98. package/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  99. package/.next/server/app/favicon.ico.body +0 -0
  100. package/.next/server/app/page/server-reference-manifest.json +66 -77
  101. package/.next/server/app/page.js +11 -11
  102. package/.next/server/app/page.js.nft.json +1 -1
  103. package/.next/server/app/page_client-reference-manifest.js +1 -1
  104. package/.next/server/app-paths-manifest.json +5 -1
  105. package/.next/server/chunks/[externals]__0dzuk6_._.js +3 -0
  106. package/.next/server/chunks/[root-of-the-server]__01dkp4a._.js +3 -0
  107. package/.next/server/chunks/[root-of-the-server]__02va5wz._.js +3 -0
  108. package/.next/server/chunks/[root-of-the-server]__02xjoto._.js +3 -0
  109. package/.next/server/chunks/[root-of-the-server]__04q--0f._.js +8 -0
  110. package/.next/server/chunks/[root-of-the-server]__0bl-e63._.js +3 -0
  111. package/.next/server/chunks/[root-of-the-server]__0ce8nf8._.js +5 -0
  112. package/.next/server/chunks/[root-of-the-server]__0ffbg85._.js +3 -0
  113. package/.next/server/chunks/[root-of-the-server]__0j7z0r3._.js +12 -0
  114. package/.next/server/chunks/[root-of-the-server]__0jq4ohy._.js +8 -0
  115. package/.next/server/chunks/[root-of-the-server]__0ls6_8y._.js +8 -0
  116. package/.next/server/chunks/[root-of-the-server]__0ncs9uu._.js +3 -0
  117. package/.next/server/chunks/[root-of-the-server]__0pa2n68._.js +3 -0
  118. package/.next/server/chunks/[root-of-the-server]__0q0vvt2._.js +5 -0
  119. package/.next/server/chunks/[root-of-the-server]__1-ga0kh._.js +5 -0
  120. package/.next/server/chunks/[root-of-the-server]__11n256_._.js +5 -0
  121. package/.next/server/chunks/[root-of-the-server]__12cabg9._.js +3 -0
  122. package/.next/server/chunks/[root-of-the-server]__1339jnv._.js +8 -0
  123. package/.next/server/chunks/[root-of-the-server]__15bjnu5._.js +5 -0
  124. package/.next/server/chunks/[root-of-the-server]__18_teo8._.js +8 -0
  125. package/.next/server/chunks/[root-of-the-server]__1_04mcf._.js +5 -0
  126. package/.next/server/chunks/[root-of-the-server]__1anc1p9._.js +3 -0
  127. package/.next/server/chunks/[root-of-the-server]__1ccon1w._.js +10 -0
  128. package/.next/server/chunks/[root-of-the-server]__1fizn31._.js +3 -0
  129. package/.next/server/chunks/[root-of-the-server]__1llj3-b._.js +3 -0
  130. package/.next/server/chunks/[root-of-the-server]__1orn-5b._.js +11 -0
  131. package/.next/server/chunks/[root-of-the-server]__1p8m3f4._.js +3 -0
  132. package/.next/server/chunks/[root-of-the-server]__1wa1k7r._.js +8 -0
  133. package/.next/server/chunks/{_1hzrsvg._.js → _0-73of8._.js} +6 -6
  134. package/.next/server/chunks/{_1cbk7ms._.js → _0-fjql4._.js} +10 -10
  135. package/.next/server/chunks/_00xh_q0._.js +27 -0
  136. package/.next/server/chunks/{_0y8is-s._.js → _03a0897._.js} +1 -1
  137. package/.next/server/chunks/{_0pppbb5._.js → _03kp0jp._.js} +166 -35
  138. package/.next/server/chunks/_051qh8u._.js +3 -0
  139. package/.next/server/chunks/{node_modules_next_04q-o58._.js → _05dla15._.js} +2 -2
  140. package/.next/server/chunks/_05h2cii._.js +1 -1
  141. package/.next/server/chunks/_0c9j6rb._.js +49 -0
  142. package/.next/server/chunks/_0fzqt2y._.js +74 -44
  143. package/.next/server/chunks/{_0kl37zl._.js → _0ioz3nd._.js} +1 -1
  144. package/.next/server/chunks/_0iwfby5._.js +3 -0
  145. package/.next/server/chunks/{_0hin38_._.js → _0khihjk._.js} +5 -5
  146. package/.next/server/chunks/_0mecv0f._.js +26 -0
  147. package/.next/server/chunks/_0mh8j4m._.js +3 -0
  148. package/.next/server/chunks/{_1icgbi8._.js → _0n74zsf._.js} +2 -2
  149. package/.next/server/chunks/_0obojvv._.js +3 -0
  150. package/.next/server/chunks/_0recufk._.js +49 -0
  151. package/.next/server/chunks/{_1t8fv7b._.js → _0rnf-6n._.js} +2 -2
  152. package/.next/server/chunks/_0sb7tlz._.js +3 -0
  153. package/.next/server/chunks/{_0jgm3b8._.js → _0u10wmw._.js} +6 -6
  154. package/.next/server/chunks/{_12nr4xc._.js → _0u4aiy2._.js} +2 -2
  155. package/.next/server/chunks/_0wp4le3._.js +1 -1
  156. package/.next/server/chunks/_0y5fg-x._.js +1 -1
  157. package/.next/server/chunks/_1230wbx._.js +10 -0
  158. package/.next/server/chunks/_12nheja._.js +3 -0
  159. package/.next/server/chunks/_13510xh._.js +3 -0
  160. package/.next/server/chunks/_15hq89o._.js +1 -1
  161. package/.next/server/chunks/_17l5ygt._.js +49 -0
  162. package/.next/server/chunks/{_0ks6_sg._.js → _18-1wcc._.js} +6 -6
  163. package/.next/server/chunks/_1_5mnq4._.js +18 -0
  164. package/.next/server/chunks/{_0tzfesa._.js → _1_9mjx-._.js} +1 -1
  165. package/.next/server/chunks/_1d0j961._.js +6 -0
  166. package/.next/server/chunks/_1d5zmy8._.js +1 -1
  167. package/.next/server/chunks/_1drgfx4._.js +18 -0
  168. package/.next/server/chunks/{_1skgy7b._.js → _1e48czp._.js} +5 -5
  169. package/.next/server/chunks/_1f46eie._.js +3 -0
  170. package/.next/server/chunks/_1h5_8sk._.js +3 -0
  171. package/.next/server/chunks/_1hdnxb7._.js +3 -0
  172. package/.next/server/chunks/_1j8k_j5._.js +3 -0
  173. package/.next/server/chunks/{_10qam6o._.js → _1kg70wc._.js} +5 -5
  174. package/.next/server/chunks/_1krd9rf._.js +3 -0
  175. package/.next/server/chunks/_1nc0eui._.js +11 -0
  176. package/.next/server/chunks/_1nula3v._.js +3 -0
  177. package/.next/server/chunks/_1pf4qe-._.js +3 -0
  178. package/.next/server/chunks/_1php4eq._.js +1 -1
  179. package/.next/server/chunks/_1qxheoa._.js +3 -0
  180. package/.next/server/chunks/_1x6kd1r._.js +3 -0
  181. package/.next/server/chunks/_1yuv4vp._.js +1 -1
  182. package/.next/server/chunks/_1zjrdag._.js +3 -0
  183. package/.next/server/chunks/_next-internal_server_app_api_bot_memory_files_route_actions_1_xd_8f.js +3 -0
  184. package/.next/server/chunks/_next-internal_server_app_api_bot_memory_route_actions_1a8xfr7.js +3 -0
  185. package/.next/server/chunks/_next-internal_server_app_api_llm-model_credits_route_actions_0v424pb.js +3 -0
  186. package/.next/server/chunks/_next-internal_server_app_api_llm-model_subscription_route_actions_0-udcm5.js +3 -0
  187. package/.next/server/chunks/_next-internal_server_app_api_memory_edit_route_actions_02sfnmr.js +3 -0
  188. package/.next/server/chunks/config_ts_1g4sz5o._.js +1 -1
  189. package/.next/server/chunks/features_0rpfxbk._.js +3 -0
  190. package/.next/server/chunks/features_1qf3cei._.js +3 -0
  191. package/.next/server/chunks/features_bot_0zt92oh._.js +3 -0
  192. package/.next/server/chunks/features_bot_bot_query_ts_12mgkl2._.js +1 -1
  193. package/.next/server/chunks/features_memory_1uqvksn._.js +6 -0
  194. package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0tf290y._.js → node_modules_consola_dist_chunks_prompt_mjs_0i7cvml._.js} +1 -1
  195. package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0228f43._.js → node_modules_consola_dist_chunks_prompt_mjs_0icqaqw._.js} +1 -1
  196. package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0ir-vo2._.js → node_modules_consola_dist_chunks_prompt_mjs_0j61-ma._.js} +1 -1
  197. package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0otw8ef._.js → node_modules_consola_dist_chunks_prompt_mjs_0r28-sm._.js} +1 -1
  198. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0v_7drq._.js +3 -0
  199. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_11zjo-1._.js +3 -0
  200. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1pycqsq._.js +3 -0
  201. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1xoq2rl._.js +3 -0
  202. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js +3 -0
  203. package/.next/server/chunks/ssr/[externals]__0dizgek._.js +3 -0
  204. package/.next/server/chunks/ssr/[root-of-the-server]__09q9med._.js +1 -1
  205. package/.next/server/chunks/ssr/[root-of-the-server]__0_69wqr._.js +3 -0
  206. package/.next/server/chunks/ssr/[root-of-the-server]__0hg5gib._.js +1 -1
  207. package/.next/server/chunks/ssr/[root-of-the-server]__0i8ie7f._.js +3 -0
  208. package/.next/server/chunks/ssr/{[root-of-the-server]__0jsmmb-._.js → [root-of-the-server]__0mz33a7._.js} +1 -1
  209. package/.next/server/chunks/ssr/[root-of-the-server]__0tbkdlx._.js +3 -0
  210. package/.next/server/chunks/ssr/[root-of-the-server]__0vnmv-s._.js +3 -0
  211. package/.next/server/chunks/ssr/{[root-of-the-server]__0f6s48x._.js → [root-of-the-server]__0xpcv9w._.js} +3 -3
  212. package/.next/server/chunks/ssr/[root-of-the-server]__0xtssj3._.js +1 -1
  213. package/.next/server/chunks/ssr/[root-of-the-server]__0zkv7z_._.js +3 -0
  214. package/.next/server/chunks/ssr/[root-of-the-server]__10-dz5o._.js +57 -0
  215. package/.next/server/chunks/ssr/[root-of-the-server]__15_uhip._.js +3 -0
  216. package/.next/server/chunks/ssr/[root-of-the-server]__16jc196._.js +1 -1
  217. package/.next/server/chunks/ssr/[root-of-the-server]__1cyjywu._.js +3 -0
  218. package/.next/server/chunks/ssr/[root-of-the-server]__1eh7hid._.js +3 -0
  219. package/.next/server/chunks/ssr/[root-of-the-server]__1gtlw6v._.js +43 -0
  220. package/.next/server/chunks/ssr/[root-of-the-server]__1mzi-ju._.js +1 -1
  221. package/.next/server/chunks/ssr/[root-of-the-server]__1ox7hbk._.js +4 -0
  222. package/.next/server/chunks/ssr/[root-of-the-server]__1pduf5n._.js +3 -0
  223. package/.next/server/chunks/ssr/{_1mznrxk._.js → _001_ms1._.js} +3 -3
  224. package/.next/server/chunks/ssr/_01_6m32._.js +3 -0
  225. package/.next/server/chunks/ssr/_01n3o0m._.js +3 -0
  226. package/.next/server/chunks/ssr/_07uchnc._.js +3 -0
  227. package/.next/server/chunks/ssr/_0ap2fzn._.js +3 -0
  228. package/.next/server/chunks/ssr/_0c-ql2m._.js +3 -0
  229. package/.next/server/chunks/ssr/_0h42fze._.js +3 -0
  230. package/.next/server/chunks/ssr/_0h7zdni._.js +1 -1
  231. package/.next/server/chunks/ssr/_0i_6q1w._.js +41 -0
  232. package/.next/server/chunks/ssr/_0kbkmar._.js +3 -0
  233. package/.next/server/chunks/ssr/_0lu1n_x._.js +3 -0
  234. package/.next/server/chunks/ssr/{_077-g6s._.js → _0mb8zc8._.js} +3 -3
  235. package/.next/server/chunks/ssr/_0mo2w06._.js +3 -0
  236. package/.next/server/chunks/ssr/{_13punpm._.js → _0q0zan6._.js} +2 -2
  237. package/.next/server/chunks/ssr/{_0gd4vaa._.js → _0u2jv_x._.js} +94 -58
  238. package/.next/server/chunks/ssr/_0y0tiht._.js +4 -0
  239. package/.next/server/chunks/ssr/_0zhoc3r._.js +3 -0
  240. package/.next/server/chunks/ssr/_1-teee5._.js +3 -3
  241. package/.next/server/chunks/ssr/_13fke0x._.js +3 -0
  242. package/.next/server/chunks/ssr/{_0q_2f2x._.js → _13z3f85._.js} +2 -2
  243. package/.next/server/chunks/ssr/_14_lw10._.js +3 -0
  244. package/.next/server/chunks/ssr/_15j2_8f._.js +3 -0
  245. package/.next/server/chunks/ssr/{_0lc_7c8._.js → _1eoqg_g._.js} +2 -2
  246. package/.next/server/chunks/ssr/_1sji22n._.js +3 -0
  247. package/.next/server/chunks/ssr/_1spzm8z._.js +3 -0
  248. package/.next/server/chunks/ssr/{_19_o9d-._.js → _1vi_uo7._.js} +2 -2
  249. package/.next/server/chunks/ssr/_1vyd1ji._.js +3 -0
  250. package/.next/server/chunks/ssr/_1xvgn77._.js +3 -0
  251. package/.next/server/chunks/ssr/_20kd_n0._.js +42 -0
  252. package/.next/server/chunks/ssr/features_bot_1s_-2vj._.js +3 -0
  253. package/.next/server/chunks/ssr/features_config_components_config-setting_tsx_0xfwqdg._.js +1 -1
  254. package/.next/server/chunks/ssr/features_connectors_components_mcp-setting_tsx_0jmbgvp._.js +1 -1
  255. package/.next/server/chunks/ssr/lib_date-like_ts_02is0pw._.js +3 -0
  256. package/.next/server/chunks/ssr/lib_realtime_12wg_dd._.js +27 -0
  257. package/.next/server/chunks/ssr/lib_realtime_15h_v1v._.js +27 -0
  258. package/.next/server/chunks/ssr/{node_modules_1d-is1o._.js → node_modules_063xwpp._.js} +1 -1
  259. package/.next/server/chunks/ssr/{node_modules_1ub40gk._.js → node_modules_0bvraul._.js} +1 -1
  260. package/.next/server/chunks/ssr/{node_modules_1nhw9qg._.js → node_modules_0eu1va6._.js} +1 -1
  261. package/.next/server/chunks/ssr/{node_modules_0xwx4u-._.js → node_modules_0h50b8n._.js} +1 -1
  262. package/.next/server/chunks/ssr/{node_modules_043-236._.js → node_modules_0h5hnr1._.js} +1 -1
  263. package/.next/server/chunks/ssr/{node_modules_1t0y5jt._.js → node_modules_0h7u60n._.js} +1 -1
  264. package/.next/server/chunks/ssr/{node_modules_1k29j1j._.js → node_modules_0lm7_vm._.js} +1 -1
  265. package/.next/server/chunks/ssr/{node_modules_16i4o_3._.js → node_modules_0mwym0g._.js} +1 -1
  266. package/.next/server/chunks/ssr/{node_modules_1y8_3vg._.js → node_modules_0rjg6t1._.js} +1 -1
  267. package/.next/server/chunks/ssr/node_modules_0x3-ply._.js +3 -0
  268. package/.next/server/chunks/ssr/{node_modules_108wd2o._.js → node_modules_0y_cded._.js} +1 -1
  269. package/.next/server/chunks/ssr/{node_modules_1jatz7w._.js → node_modules_0z5tsu8._.js} +1 -1
  270. package/.next/server/chunks/ssr/{node_modules_0ls96je._.js → node_modules_0zp9r92._.js} +1 -1
  271. package/.next/server/chunks/ssr/{node_modules_06kvvuo._.js → node_modules_1-hc6uv._.js} +1 -1
  272. package/.next/server/chunks/ssr/{node_modules_1_588_4._.js → node_modules_113tz0l._.js} +1 -1
  273. package/.next/server/chunks/ssr/{node_modules_0ipn1ho._.js → node_modules_124bue5._.js} +1 -1
  274. package/.next/server/chunks/ssr/node_modules_17bwo43._.js +55 -0
  275. package/.next/server/chunks/ssr/{node_modules_0_j7-g4._.js → node_modules_1_n3ztw._.js} +1 -1
  276. package/.next/server/chunks/ssr/{node_modules_20ynonm._.js → node_modules_1bc7gu8._.js} +1 -1
  277. package/.next/server/chunks/ssr/{node_modules_1hn_sd5._.js → node_modules_1bgb6-f._.js} +1 -1
  278. package/.next/server/chunks/ssr/{node_modules_0bue6gy._.js → node_modules_1h4a4pp._.js} +1 -1
  279. package/.next/server/chunks/ssr/{node_modules_0fbw5-u._.js → node_modules_1i7u1ia._.js} +1 -1
  280. package/.next/server/chunks/ssr/{node_modules_1ee8gav._.js → node_modules_1juq3hs._.js} +1 -1
  281. package/.next/server/chunks/ssr/{node_modules_0_fvxnt._.js → node_modules_1l0qtdu._.js} +1 -1
  282. package/.next/server/chunks/ssr/{node_modules_13f2md6._.js → node_modules_1t9cyee._.js} +1 -1
  283. package/.next/server/chunks/ssr/{node_modules_0y2-av4._.js → node_modules_1uuj9x1._.js} +1 -1
  284. package/.next/server/chunks/ssr/{node_modules_00d6675._.js → node_modules_1vqb6po._.js} +1 -1
  285. package/.next/server/chunks/ssr/{node_modules_1v0077l._.js → node_modules_1xx28h1._.js} +1 -1
  286. package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_092s8nx._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0d3skpl._.js} +1 -1
  287. package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1nvexgu._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0i44kk5._.js} +1 -1
  288. package/.next/server/chunks/ssr/node_modules_@vercel_oidc_dist_0qe30a_._.js +3 -0
  289. package/.next/server/chunks/ssr/node_modules_consola_dist_chunks_prompt_mjs_05cwqv2._.js +47 -0
  290. package/.next/server/chunks/ssr/{node_modules_next_dist_0w6mzq5._.js → node_modules_next_dist_0drixxt._.js} +4 -4
  291. package/.next/server/chunks/ssr/node_modules_next_dist_1n3w9lb._.js +2 -2
  292. package/.next/server/instrumentation.js +1 -1
  293. package/.next/server/middleware-build-manifest.js +3 -3
  294. package/.next/server/pages/404.html +1 -1
  295. package/.next/server/pages/500.html +1 -1
  296. package/.next/server/server-reference-manifest.js +1 -1
  297. package/.next/server/server-reference-manifest.json +67 -78
  298. package/.next/static/chunks/{31ttnjt6g35a0.js → 0ev4hyghq0mbb.js} +1 -1
  299. package/.next/static/chunks/0r5qcctujhxli.js +1 -0
  300. package/.next/static/chunks/0tmgrnlje14-s.js +3 -0
  301. package/.next/static/chunks/0x79tx04dxbpp.js +1 -0
  302. package/.next/static/chunks/0xzgvc0fkdb6t.js +1 -0
  303. package/.next/static/chunks/10teww7wt-f6h.js +1 -0
  304. package/.next/static/chunks/14hgtsjg-kael.css +1 -0
  305. package/.next/static/chunks/17donp69y4do7.js +40 -0
  306. package/.next/static/chunks/1dkjg87pxk0n9.js +28 -0
  307. package/.next/static/chunks/1ekc7ul556kbl.js +1 -0
  308. package/.next/static/chunks/{1khakdu_iuedc.js → 1grhjo7a5a0_-.js} +1 -1
  309. package/.next/static/chunks/1kq8h8wi_e0bc.js +53 -0
  310. package/.next/static/chunks/1okqiww3pnwka.js +1 -0
  311. package/.next/static/chunks/26-pr2c9ro222.js +1 -0
  312. package/.next/static/chunks/{2ihkf6l2jowo9.js → 280t0_e99i276.js} +3 -3
  313. package/.next/static/chunks/28cizcdaabd4h.js +1 -0
  314. package/.next/static/chunks/2a0k6jlq0_v1u.js +2 -0
  315. package/.next/static/chunks/2fzs9fm8yarvq.js +1 -0
  316. package/.next/static/chunks/2h0sd2vumhb15.js +1 -0
  317. package/.next/static/chunks/2hw2f6zmt7fmt.js +1 -0
  318. package/.next/static/chunks/2t4vhi3m8ahya.js +1 -0
  319. package/.next/static/chunks/2tigdtz3dpcy8.js +1 -0
  320. package/.next/static/chunks/3111pj5wnjgos.js +1 -0
  321. package/.next/static/chunks/3786h5vayt80-.js +28 -0
  322. package/.next/static/chunks/{3aquirz5h71da.js → 3agpgkwaa321p.js} +1 -1
  323. package/.next/static/chunks/3cfi_q6d_wtci.js +1 -0
  324. package/.next/static/chunks/3ok9_x74rip3v.js +1 -0
  325. package/.next/static/chunks/3xk7yqgomx7yq.js +1 -0
  326. package/.next/static/chunks/3xpbkl66ssib5.js +38 -0
  327. package/.next/static/media/favicon.37o1pjldwi2uc.ico +0 -0
  328. package/README.md +6 -4
  329. package/app/api/bot/memory/files/route.ts +14 -0
  330. package/app/api/bot/memory/route.ts +5 -0
  331. package/app/api/events/app-event.client.ts +24 -0
  332. package/app/api/events/app-event.server.ts +45 -0
  333. package/app/api/events/app-event.ts +42 -0
  334. package/app/api/llm-model/catalog/route.ts +12 -0
  335. package/app/api/llm-model/credits/route.ts +11 -0
  336. package/app/api/llm-model/route.ts +26 -0
  337. package/app/api/llm-model/subscription/route.ts +11 -0
  338. package/app/api/memory/edit/route.ts +7 -0
  339. package/app/api/memory/route.ts +21 -0
  340. package/app/api/query-key.ts +159 -0
  341. package/app/api/thursday/tool-call/route.ts +67 -0
  342. package/bin/thursday.mjs +3 -0
  343. package/components/ui/button-group.tsx +45 -0
  344. package/components/ui/custom-icon.tsx +259 -0
  345. package/components/ui/dropdown-menu.tsx +271 -0
  346. package/components/ui/folded-text.tsx +68 -0
  347. package/components/ui/input-group.tsx +157 -0
  348. package/components/ui/json-view.tsx +240 -0
  349. package/components/ui/shiny-text.tsx +55 -0
  350. package/components/ui/text-type.tsx +213 -0
  351. package/components/ui/theme-sync.tsx +9 -0
  352. package/database/migrations/{20260908030742_rainy_marvel_zombies → 20260910173049_numerous_spirit}/migration.sql +30 -33
  353. package/database/migrations/{20260908030742_rainy_marvel_zombies → 20260910173049_numerous_spirit}/snapshot.json +124 -145
  354. package/database/migrations/20260911030320_opposite_jack_power/migration.sql +1 -0
  355. package/database/migrations/20260911030320_opposite_jack_power/snapshot.json +1158 -0
  356. package/docs/how-it-works.md +59 -0
  357. package/docs/images/keeps-going.png +0 -0
  358. package/docs/images/task-thread.png +0 -0
  359. package/docs/images/two-minds.png +0 -0
  360. package/features/ai/chatgpt.ts +617 -0
  361. package/features/ai/components/chatgpt-sign-in.tsx +66 -0
  362. package/features/ai/components/model-picker.tsx +17 -1
  363. package/features/ai/components/provider-icon.tsx +1 -0
  364. package/features/ai/load-tools.ts +105 -39
  365. package/features/ai/model.schema.ts +232 -34
  366. package/features/ai/model.ts +169 -24
  367. package/features/ai/prompts/bot.prompt.ts +245 -59
  368. package/features/ai/prompts/memory-edit.prompt.ts +33 -0
  369. package/features/ai/prompts/prompt-helper.ts +75 -30
  370. package/features/ai/prompts/thursday.prompt.ts +42 -17
  371. package/features/ai/tools/bot.tool.ts +32 -30
  372. package/features/ai/tools/connected.ts +17 -4
  373. package/features/ai/tools/mcp.tool.ts +5 -5
  374. package/features/ai/tools/memory.tool.ts +142 -74
  375. package/features/ai/tools/search.tool.ts +136 -47
  376. package/features/ai/tools/studio.tool.ts +5 -5
  377. package/features/ai/tools/tool-name.ts +2 -3
  378. package/features/ai/tools/workspace.tool.ts +33 -4
  379. package/features/bot/bot.action.ts +24 -7
  380. package/features/bot/bot.memory.ts +89 -0
  381. package/features/bot/bot.query.ts +41 -6
  382. package/features/bot/bot.run.ts +516 -210
  383. package/features/bot/bot.runner.ts +463 -93
  384. package/features/bot/bot.schema.ts +84 -7
  385. package/features/bot/bot.seed.ts +89 -16
  386. package/features/bot/components/bot-mark.tsx +122 -20
  387. package/features/bot/components/bot-room.tsx +519 -391
  388. package/features/bot/components/bot-setting.tsx +832 -341
  389. package/features/bot/components/bot-tool.tsx +2 -6
  390. package/features/bot/components/mark-palette.tsx +54 -0
  391. package/features/bot/components/path-chips.tsx +1 -1
  392. package/features/bot/components/task-badge.tsx +26 -6
  393. package/features/bot/components/task-reply.tsx +22 -33
  394. package/features/bot/components/task-setting.tsx +20 -17
  395. package/features/bot/task.query.ts +233 -33
  396. package/features/bot/task.store.ts +53 -9
  397. package/features/config/components/config-setting.tsx +265 -34
  398. package/features/config/components/models-badge.tsx +42 -0
  399. package/features/config/config.action.ts +12 -0
  400. package/features/config/config.const.ts +38 -2
  401. package/features/connectors/mcp.manager.ts +10 -2
  402. package/features/intro/components/intro.tsx +47 -46
  403. package/features/memory/components/memory-edit.tsx +338 -0
  404. package/features/memory/components/memory-setting.tsx +86 -79
  405. package/features/memory/memory.action.ts +3 -43
  406. package/features/memory/memory.edit.ts +87 -0
  407. package/features/memory/memory.query.ts +33 -44
  408. package/features/memory/memory.schema.ts +50 -97
  409. package/features/settings/components/settings.tsx +2 -0
  410. package/features/settings/settings.alert.ts +3 -1
  411. package/features/skills/components/skills-setting.tsx +9 -1
  412. package/features/thursday/components/ascii-orb.tsx +106 -90
  413. package/features/thursday/components/boot.tsx +7 -0
  414. package/features/thursday/components/call-log.tsx +219 -92
  415. package/features/thursday/components/face.tsx +6 -4
  416. package/features/thursday/components/tab-state.tsx +97 -0
  417. package/features/thursday/components/thursday-mark.tsx +4 -1
  418. package/features/thursday/components/thursday-setting.tsx +17 -47
  419. package/features/thursday/components/thursday.tsx +208 -95
  420. package/features/thursday/thursday.action.ts +12 -17
  421. package/features/thursday/thursday.query.ts +61 -70
  422. package/features/thursday/thursday.schema.ts +20 -7
  423. package/features/thursday/tool-line.ts +85 -11
  424. package/features/thursday/use-thursday.ts +86 -59
  425. package/features/workspace/components/file-view.tsx +4 -2
  426. package/features/workspace/workspace.ts +230 -13
  427. package/hooks/use-draft.ts +37 -0
  428. package/hooks/use-hotkey.ts +105 -0
  429. package/hooks/use-object-state.ts +51 -0
  430. package/hooks/use-on-visible.ts +72 -0
  431. package/hooks/use-theme.ts +106 -0
  432. package/hooks/use-wake-word.ts +262 -0
  433. package/lib/limits.ts +1 -1
  434. package/lib/oauth-page.ts +27 -0
  435. package/lib/realtime/openai.ts +2 -2
  436. package/lib/realtime/realtime.driver.ts +34 -1
  437. package/lib/realtime/realtime.protocol.ts +7 -1
  438. package/lib/realtime/realtime.tap.ts +122 -0
  439. package/lib/sandbox.ts +60 -29
  440. package/lib/tokens.ts +19 -0
  441. package/package.json +1 -1
  442. package/skills/browser/SKILL.md +55 -34
  443. package/.next/server/app/api/memory/tidy/route/app-paths-manifest.json +0 -3
  444. package/.next/server/app/api/memory/tidy/route.js +0 -23
  445. package/.next/server/app/api/memory/tidy/route.js.nft.json +0 -1
  446. package/.next/server/chunks/[root-of-the-server]__019dx9f._.js +0 -5
  447. package/.next/server/chunks/[root-of-the-server]__02_2sm-._.js +0 -5
  448. package/.next/server/chunks/[root-of-the-server]__02kt8yn._.js +0 -10
  449. package/.next/server/chunks/[root-of-the-server]__05luceg._.js +0 -3
  450. package/.next/server/chunks/[root-of-the-server]__06t77t4._.js +0 -11
  451. package/.next/server/chunks/[root-of-the-server]__0bed6hu._.js +0 -8
  452. package/.next/server/chunks/[root-of-the-server]__0dupqt7._.js +0 -5
  453. package/.next/server/chunks/[root-of-the-server]__0h59di-._.js +0 -5
  454. package/.next/server/chunks/[root-of-the-server]__0j_n5l3._.js +0 -3
  455. package/.next/server/chunks/[root-of-the-server]__0le4d-p._.js +0 -3
  456. package/.next/server/chunks/[root-of-the-server]__0m8ywyo._.js +0 -10
  457. package/.next/server/chunks/[root-of-the-server]__0nfuugi._.js +0 -5
  458. package/.next/server/chunks/[root-of-the-server]__0phdgco._.js +0 -8
  459. package/.next/server/chunks/[root-of-the-server]__0qjqtwo._.js +0 -5
  460. package/.next/server/chunks/[root-of-the-server]__0t_dqaj._.js +0 -3
  461. package/.next/server/chunks/[root-of-the-server]__0wvgrsl._.js +0 -3
  462. package/.next/server/chunks/[root-of-the-server]__0yk6s3w._.js +0 -5
  463. package/.next/server/chunks/[root-of-the-server]__0z3gelv._.js +0 -3
  464. package/.next/server/chunks/[root-of-the-server]__10qshki._.js +0 -3
  465. package/.next/server/chunks/[root-of-the-server]__113fqg5._.js +0 -12
  466. package/.next/server/chunks/[root-of-the-server]__11w_7_3._.js +0 -3
  467. package/.next/server/chunks/[root-of-the-server]__16thabu._.js +0 -3
  468. package/.next/server/chunks/[root-of-the-server]__173nhwf._.js +0 -8
  469. package/.next/server/chunks/[root-of-the-server]__1_0q_9w._.js +0 -3
  470. package/.next/server/chunks/[root-of-the-server]__1_aoyr9._.js +0 -3
  471. package/.next/server/chunks/[root-of-the-server]__1bqhuh9._.js +0 -8
  472. package/.next/server/chunks/[root-of-the-server]__1cqizfq._.js +0 -5
  473. package/.next/server/chunks/[root-of-the-server]__1dow0bz._.js +0 -3
  474. package/.next/server/chunks/[root-of-the-server]__1e-ci13._.js +0 -3
  475. package/.next/server/chunks/[root-of-the-server]__1gmn1cs._.js +0 -10
  476. package/.next/server/chunks/[root-of-the-server]__1lr7j9t._.js +0 -5
  477. package/.next/server/chunks/[root-of-the-server]__1mzp_el._.js +0 -3
  478. package/.next/server/chunks/[root-of-the-server]__1txedx6._.js +0 -8
  479. package/.next/server/chunks/[root-of-the-server]__1u_qvc7._.js +0 -3
  480. package/.next/server/chunks/[root-of-the-server]__1zgpz1w._.js +0 -3
  481. package/.next/server/chunks/_012yhfm._.js +0 -39
  482. package/.next/server/chunks/_06mxlgn._.js +0 -3
  483. package/.next/server/chunks/_07rtlxv._.js +0 -3
  484. package/.next/server/chunks/_0a351g7._.js +0 -6
  485. package/.next/server/chunks/_0kjjmag._.js +0 -3
  486. package/.next/server/chunks/_0zmestz._.js +0 -55
  487. package/.next/server/chunks/_0zuzmt_._.js +0 -39
  488. package/.next/server/chunks/_12bbv5i._.js +0 -96
  489. package/.next/server/chunks/_15q1pig._.js +0 -3
  490. package/.next/server/chunks/_1drv2et._.js +0 -36
  491. package/.next/server/chunks/_1ic3bew._.js +0 -5
  492. package/.next/server/chunks/_1mxn_lb._.js +0 -3
  493. package/.next/server/chunks/_1uj4_io._.js +0 -10
  494. package/.next/server/chunks/_1x7p319._.js +0 -6
  495. package/.next/server/chunks/_1yldgo4._.js +0 -55
  496. package/.next/server/chunks/_2050gwn._.js +0 -255
  497. package/.next/server/chunks/_next-internal_server_app_api_memory_tidy_route_actions_0_cfuom.js +0 -3
  498. package/.next/server/chunks/features_0scmr4i._.js +0 -3
  499. package/.next/server/chunks/features_bot_task_query_ts_11xuzl3._.js +0 -3
  500. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0vorg6w._.js +0 -3
  501. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0ykklj0._.js +0 -3
  502. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1ryg3wh._.js +0 -3
  503. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1vmaq9f._.js +0 -3
  504. package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1vwbnq_._.js +0 -3
  505. package/.next/server/chunks/ssr/[externals]_node_crypto_1kn79-7._.js +0 -3
  506. package/.next/server/chunks/ssr/[root-of-the-server]__01id-v3._.js +0 -3
  507. package/.next/server/chunks/ssr/[root-of-the-server]__0b-0i32._.js +0 -3
  508. package/.next/server/chunks/ssr/[root-of-the-server]__0dfwvr4._.js +0 -4
  509. package/.next/server/chunks/ssr/[root-of-the-server]__0iuoa-r._.js +0 -3
  510. package/.next/server/chunks/ssr/[root-of-the-server]__1-mnhyd._.js +0 -90
  511. package/.next/server/chunks/ssr/[root-of-the-server]__185grso._.js +0 -3
  512. package/.next/server/chunks/ssr/[root-of-the-server]__1minz8_._.js +0 -3
  513. package/.next/server/chunks/ssr/_0-mc7ro._.js +0 -3
  514. package/.next/server/chunks/ssr/_01p5r6-._.js +0 -3
  515. package/.next/server/chunks/ssr/_09-0k3z._.js +0 -3
  516. package/.next/server/chunks/ssr/_0ay6b01._.js +0 -3
  517. package/.next/server/chunks/ssr/_0cvjbuz._.js +0 -3
  518. package/.next/server/chunks/ssr/_0fafgvl._.js +0 -3
  519. package/.next/server/chunks/ssr/_0j4v8of._.js +0 -3
  520. package/.next/server/chunks/ssr/_0l81bzy._.js +0 -3
  521. package/.next/server/chunks/ssr/_0nso8tp._.js +0 -3
  522. package/.next/server/chunks/ssr/_0sf1isi._.js +0 -3
  523. package/.next/server/chunks/ssr/_0ti51xc._.js +0 -3
  524. package/.next/server/chunks/ssr/_0y84qo6._.js +0 -3
  525. package/.next/server/chunks/ssr/_10uvw3l._.js +0 -3
  526. package/.next/server/chunks/ssr/_1dcxzqe._.js +0 -3
  527. package/.next/server/chunks/ssr/_1e-dgz0._.js +0 -4
  528. package/.next/server/chunks/ssr/_1fq7zgb._.js +0 -3
  529. package/.next/server/chunks/ssr/_1jbv7m1._.js +0 -3
  530. package/.next/server/chunks/ssr/features_bot_components_bot-setting_tsx_01ajft6._.js +0 -4
  531. package/.next/server/chunks/ssr/features_config_components_14jqgy4._.js +0 -3
  532. package/.next/server/chunks/ssr/features_memory_components_memory-setting_tsx_0oa43sw._.js +0 -4
  533. package/.next/server/chunks/ssr/lib_realtime_0aetuyp._.js +0 -24
  534. package/.next/server/chunks/ssr/lib_realtime_18k_aj-._.js +0 -24
  535. package/.next/server/chunks/ssr/node_modules_zod_v4_classic_errors_05xv7vp.js +0 -3
  536. package/.next/server/chunks/ssr/node_modules_zod_v4_classic_external_15fmmz3.js +0 -55
  537. package/.next/static/chunks/0f9sq-7q_yxyl.js +0 -1
  538. package/.next/static/chunks/0tydnn2kybibk.js +0 -1
  539. package/.next/static/chunks/0yysv1gzin17t.js +0 -1
  540. package/.next/static/chunks/1fr5m75pwtyic.js +0 -1
  541. package/.next/static/chunks/1gy3bbv7usnjo.js +0 -1
  542. package/.next/static/chunks/1keib_gt066gc.js +0 -1
  543. package/.next/static/chunks/1ytnip8wdng93.js +0 -1
  544. package/.next/static/chunks/21rk8w7bda-su.js +0 -1
  545. package/.next/static/chunks/247d-r95j8xs0.js +0 -1
  546. package/.next/static/chunks/28g42tw8tsvhd.js +0 -1
  547. package/.next/static/chunks/29gyb3nubj51j.js +0 -53
  548. package/.next/static/chunks/2cwjgkt_hoyhj.js +0 -22
  549. package/.next/static/chunks/2fq_86jvq9ymq.js +0 -2
  550. package/.next/static/chunks/2rbf1fpd8n80-.js +0 -22
  551. package/.next/static/chunks/2ukj8k69y89um.js +0 -1
  552. package/.next/static/chunks/2uxum7qbyeyxd.js +0 -1
  553. package/.next/static/chunks/2wngeetfnzxkp.js +0 -2
  554. package/.next/static/chunks/388-t2v72jh39.css +0 -1
  555. package/.next/static/chunks/3fqvc0cg-atq_.js +0 -1
  556. package/.next/static/chunks/3p4egvfjxpatb.js +0 -1
  557. package/.next/static/chunks/3qe1w1ei-huhl.js +0 -1
  558. package/.next/static/chunks/3xxa2j56-f3nm.js +0 -3
  559. package/.next/static/chunks/3y40riycdip-i.js +0 -1
  560. package/.next/static/chunks/45a6zbtkelph9.js +0 -1
  561. package/.next/static/media/favicon.2vob68tjqpejf.ico +0 -0
  562. package/features/ai/prompts/memory-tidy.prompt.ts +0 -123
  563. package/features/ai/tools/tidy.tool.ts +0 -22
  564. package/features/memory/components/memory-tidy.tsx +0 -395
  565. package/features/memory/memory.tidy.ts +0 -332
  566. package/features/memory/tidy.query.ts +0 -135
  567. package/features/thursday/use-call-title.ts +0 -31
  568. /package/.next/server/app/api/{memory/tidy → bot/memory/files}/route/build-manifest.json +0 -0
  569. /package/.next/server/app/api/{memory/tidy → bot/memory/files}/route/server-reference-manifest.json +0 -0
  570. /package/.next/server/app/api/{memory/tidy → bot/memory/files}/route.js.map +0 -0
  571. /package/.next/static/{X34BUd9bfdH27ripuwwBm → x1cCqY0kWpR_VcYx_lWO5}/_buildManifest.js +0 -0
  572. /package/.next/static/{X34BUd9bfdH27ripuwwBm → x1cCqY0kWpR_VcYx_lWO5}/_clientMiddlewareManifest.js +0 -0
  573. /package/.next/static/{X34BUd9bfdH27ripuwwBm → x1cCqY0kWpR_VcYx_lWO5}/_ssgManifest.js +0 -0
@@ -1,3 +1,3 @@
1
- module.exports=[105303,t=>t.a(async(e,r)=>{try{var o,n=t.i(361164),i=t.i(958560),s=t.i(687388),a=t.i(640911),l=t.i(41444),c=t.i(148831),u=t.i(441963),p=e([c]);[c]=p.then?(await p)():p;class h extends Error{serverName;authorizationUrl;constructor(t,e){super(`MCP server "${t}" requires authorization`),this.serverName=t,this.authorizationUrl=e,this.name="McpAuthRequiredError"}}class d{store;serverName;oauth;callbackUrl;clientName;staticClient;lastAuthorizationUrl;constructor(t,e,r,o,n,i){this.store=t,this.serverName=e,this.oauth=r,this.callbackUrl=o,this.clientName=n,this.staticClient=i}get redirectUrl(){return this.callbackUrl}get clientMetadata(){return{client_name:this.clientName,redirect_uris:[this.callbackUrl],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"client_secret_post"}}async persist(t){this.oauth={...this.oauth,...t},await this.store.saveOAuth(this.serverName,this.oauth)}clientInformation(){return this.staticClient??this.oauth.clientInformation}async saveClientInformation(t){await this.persist({clientInformation:t})}tokens(){return this.oauth.tokens}async saveTokens(t){await this.persist({tokens:t})}authorizationServerInformation(){return this.oauth.authorizationServer}async saveAuthorizationServerInformation(t){await this.persist({authorizationServer:t})}codeVerifier(){if(!this.oauth.codeVerifier)throw Error("No code verifier saved");return this.oauth.codeVerifier}async saveCodeVerifier(t){await this.persist({codeVerifier:t})}state(){return crypto.randomUUID()}async saveState(t){await this.persist({state:t})}storedState(){return this.oauth.state}redirectToAuthorization(t){this.lastAuthorizationUrl=t}async invalidateCredentials(t){let e={...this.oauth};("all"===t||"client"===t)&&(e.clientInformation=void 0),("all"===t||"tokens"===t)&&(e.tokens=void 0),("all"===t||"verifier"===t)&&(e.codeVerifier=void 0),this.oauth=e,await this.store.saveOAuth(this.serverName,e)}}let m=globalThis;m.__thursdayMcpManager&&m.__thursdayMcpManager.dispose(),o={callbackUrl:new URL("/api/mcp/oauth/callback",s.APP_URL).href,clientName:s.APP_NAME},m.__thursdayMcpManager=new class t{store;sessions;connecting;idleTtlMs;callbackUrl;clientName;constructor(t,e){this.store=t,this.sessions=new Map,this.connecting=new Map,this.callbackUrl=e.callbackUrl,this.idleTtlMs=e.idleTtlMs??18e5,this.clientName=e.clientName??s.APP_NAME}async connect(t){let e=this.connecting.get(t);if(e)return e;let r=this.doConnect(t).finally(()=>this.connecting.delete(t));return this.connecting.set(t,r),r}async callTool(t,e,r){let o=await this.ensureClient(t);try{let n=await o.callTool({name:e,arguments:r});return this.touch(t),n}catch(e){if(e instanceof n.UnauthorizedError)throw await this.closeSession(t),new h(t);throw e}}async finishAuthorization(t){let e=t.get("state"),r=t.get("code");if(!e||!r)throw Error("OAuth callback is missing code or state");let o=await this.store.findByOAuthState(e);if(!o||!(0,u.isRemoteConfig)(o.config))throw Error("No server is waiting for this authorization");let i=this.providerFor(o),s=await (0,n.auth)(i,{serverUrl:o.config.url,authorizationCode:r,callbackState:e});if("AUTHORIZED"!==s)throw Error(`Token exchange ended in "${s}"`);return await i.invalidateCredentials("verifier"),await this.connect(o.name),o.name}async disconnect(t){await this.closeSession(t)}async dispose(){await Promise.all([...this.sessions.keys()].map(t=>this.closeSession(t)))}async doConnect(t){await this.closeSession(t);let e=await this.store.load(t);if(!e)throw Error(`Unknown MCP server "${t}"`);let r={};try{let o=await this.openClient(e,r),n=(await o.listTools()).tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema}));return this.adopt(t,o),await this.store.saveConnectionResult(t,{toolInfo:n,lastError:null}),a.logger.info(`mcp "${t}" connected — ${n.length} tools`),{status:"connected",tools:n}}catch(p){var o,i;let s;if(p instanceof n.UnauthorizedError||p?.cause instanceof n.UnauthorizedError){let e=r.href;if(e)return await this.store.saveConnectionResult(t,{toolInfo:[],lastError:"Authorization required — finish sign-in in the opened tab"}),{status:"auth_required",authorizationUrl:e}}let c=(o=p,i=e,s=(0,l.errorToString)(o),/\b40[13]\b/.test(s)&&/OAuth|register/i.test(s)&&(0,u.isRemoteConfig)(i.config)&&!i.config.oauthClient?"This server does not allow automatic client registration. Register an OAuth app with the provider and add its client ID and secret.":s);throw await this.store.saveConnectionResult(t,{toolInfo:[],lastError:c}),a.logger.warn(`mcp "${t}" failed — ${c}`),Error(c,{cause:p})}}async openClient(t,e={}){if((0,u.isRemoteConfig)(t.config)){let r=this.providerFor(t);try{return await (0,n.createMCPClient)({name:this.clientName,transport:{type:"http",url:t.config.url,headers:t.config.headers,authProvider:r,redirect:"follow"}})}finally{e.href=r.lastAuthorizationUrl?.href}}return(0,n.createMCPClient)({name:this.clientName,transport:new i.Experimental_StdioMCPTransport({command:t.config.command,args:t.config.args,env:t.config.env})})}providerFor(t){let e=(0,u.isRemoteConfig)(t.config)?t.config.oauthClient:void 0;return new d(this.store,t.name,t.oauth??{},this.callbackUrl,this.clientName,e&&{client_id:e.clientId,client_secret:e.clientSecret})}async ensureClient(t){let e=this.sessions.get(t);if(e)return e.client;let r=await this.connect(t);if("auth_required"===r.status)throw new h(t,r.authorizationUrl);let o=this.sessions.get(t);if(!o)throw Error(`Session for "${t}" vanished mid-connect`);return o.client}adopt(t,e){this.sessions.set(t,{client:e,idleTimer:this.armIdleTimer(t)})}touch(t){let e=this.sessions.get(t);e&&(clearTimeout(e.idleTimer),e.idleTimer=this.armIdleTimer(t))}armIdleTimer(t){let e=setTimeout(()=>{this.closeSession(t)},this.idleTtlMs);return e.unref?.(),e}async closeSession(t){let e=this.sessions.get(t);e&&(this.sessions.delete(t),clearTimeout(e.idleTimer),await e.client.close().catch(()=>{}))}}({load:t=>(0,c.findServer)(t),saveOAuth:(t,e)=>(0,c.saveOAuthData)(t,e),saveConnectionResult:(t,e)=>null===e.lastError?(0,c.syncServerTools)(t,e.toolInfo):(0,c.saveConnectionError)(t,e.lastError),findByOAuthState:t=>(0,c.findServerByOAuthState)(t)},o);let f=m.__thursdayMcpManager;t.s(["McpAuthRequiredError",0,h,"mcpManager",0,f]),r()}catch(t){r(t)}},!1),361164,t=>{"use strict";let e;var r,o,n,i,s=t.i(847841),a=t.i(469719),l=t.i(376261),c=t.i(36040);async function u(t){return(await e).getRandomValues(new Uint8Array(t))}async function p(t){let e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~",r=256-256%e.length,o="";for(;o.length<t;)for(let n of(await u(t-o.length)))n<r&&(o+=e[n%e.length]);return o}async function h(t){return await p(t)}async function d(t){return btoa(String.fromCharCode(...new Uint8Array(await (await e).subtle.digest("SHA-256",new TextEncoder().encode(t))))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}async function m(t){if(t||(t=43),t<43||t>128)throw`Expected a length between 43 and 128. Received ${t}.`;let e=await h(t),r=await d(e);return{code_verifier:e,code_challenge:r}}e=globalThis.crypto?.webcrypto??globalThis.crypto??t.A(70729).then(t=>t.webcrypto);var f=t.i(907855),z="2026-07-28",g="2025-11-25",v=[z,g,"2025-06-18","2025-03-26","2024-11-05"],w=a.z.optional(a.z.record(a.z.string(),a.z.unknown())),y=a.z.looseObject({name:a.z.string(),version:a.z.string(),title:a.z.optional(a.z.string())}),b=a.z.looseObject({_meta:a.z.optional(a.z.object({}).loose())}),_=b.extend({resultType:a.z.optional(a.z.string())}),E=a.z.object({method:a.z.string(),params:a.z.optional(b)}),S=a.z.object({applyDefaults:a.z.optional(a.z.boolean())}).loose(),C=a.z.looseObject({experimental:a.z.optional(a.z.object({}).loose()),logging:a.z.optional(a.z.object({}).loose()),completions:a.z.optional(a.z.object({}).loose()),prompts:a.z.optional(a.z.looseObject({listChanged:a.z.optional(a.z.boolean())})),resources:a.z.optional(a.z.looseObject({subscribe:a.z.optional(a.z.boolean()),listChanged:a.z.optional(a.z.boolean())})),tools:a.z.optional(a.z.looseObject({listChanged:a.z.optional(a.z.boolean())})),elicitation:a.z.optional(S)});a.z.object({elicitation:a.z.optional(S)}).loose();var T=_.extend({supportedVersions:a.z.array(a.z.string()),capabilities:C,instructions:a.z.optional(a.z.string()),ttlMs:a.z.optional(a.z.number()),cacheScope:a.z.optional(a.z.union([a.z.literal("public"),a.z.literal("private")]))}),x=_.extend({protocolVersion:a.z.string(),capabilities:C,serverInfo:y,instructions:a.z.optional(a.z.string())}),P=_.extend({nextCursor:a.z.optional(a.z.string())}),R=a.z.object({name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),inputSchema:a.z.looseObject({type:a.z.optional(a.z.unknown()),properties:a.z.optional(a.z.object({}).loose())}),outputSchema:a.z.optional(a.z.object({}).loose()),annotations:a.z.optional(a.z.object({title:a.z.optional(a.z.string()),readOnlyHint:a.z.optional(a.z.boolean()),destructiveHint:a.z.optional(a.z.boolean()),idempotentHint:a.z.optional(a.z.boolean()),openWorldHint:a.z.optional(a.z.boolean())}).loose()),_meta:w}).loose(),I=P.extend({tools:a.z.array(R)}),A=a.z.object({type:a.z.literal("text"),text:a.z.string()}).loose(),j=a.z.object({type:a.z.literal("image"),data:a.z.base64(),mimeType:a.z.string()}).loose(),k=a.z.object({uri:a.z.string(),name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string()),size:a.z.optional(a.z.number())}).loose(),U=P.extend({resources:a.z.array(k)}),O=a.z.object({uri:a.z.string(),name:a.z.optional(a.z.string()),title:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string())}).loose(),M=O.extend({text:a.z.string()}),$=O.extend({blob:a.z.base64()}),H=a.z.object({type:a.z.literal("resource"),resource:a.z.union([M,$])}).loose(),N=a.z.object({type:a.z.literal("resource_link"),uri:a.z.string(),name:a.z.string(),description:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string())}).loose(),V=a.z.object({type:a.z.string()}).loose().refine(t=>!["text","image","resource","resource_link"].includes(t.type),{message:"Known content types must match their schema"}),L=_.extend({content:a.z.array(a.z.union([A,j,H,N,V])),structuredContent:a.z.optional(a.z.unknown()),isError:a.z.boolean().default(!1).optional()}),q=_.extend({content:a.z.never().optional(),structuredContent:a.z.json(),isError:a.z.boolean().default(!1).optional()}).transform(t=>({...t,content:[{type:"text",text:JSON.stringify(t.structuredContent)}]})).pipe(L),D=L.or(q).or(_.extend({toolResult:a.z.unknown().nonoptional()})),F=a.z.object({uriTemplate:a.z.string(),name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string())}).loose(),B=_.extend({resourceTemplates:a.z.array(F)}),W=_.extend({contents:a.z.array(a.z.union([M,$]))}),J=a.z.object({type:a.z.literal("ref/prompt"),name:a.z.string()}).loose(),K=a.z.object({type:a.z.literal("ref/resource"),uri:a.z.string()}).loose(),Z=a.z.object({name:a.z.string(),value:a.z.string()}).loose();b.extend({ref:a.z.union([J,K]),argument:Z,context:a.z.optional(a.z.object({arguments:a.z.record(a.z.string(),a.z.string())}).loose())});var G=_.extend({completion:a.z.object({values:a.z.array(a.z.string()).max(100),total:a.z.optional(a.z.number().int()),hasMore:a.z.optional(a.z.boolean())}).loose()}),Y=a.z.object({name:a.z.string(),description:a.z.optional(a.z.string()),required:a.z.optional(a.z.boolean())}).loose(),X=a.z.object({name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),arguments:a.z.optional(a.z.array(Y))}).loose(),Q=P.extend({prompts:a.z.array(X)}),tt=a.z.object({role:a.z.union([a.z.literal("user"),a.z.literal("assistant")]),content:a.z.union([A,j,H,N])}).loose(),te=_.extend({description:a.z.optional(a.z.string()),messages:a.z.array(tt)}),tr=b.extend({message:a.z.string(),requestedSchema:a.z.unknown()}),to=E.extend({method:a.z.literal("elicitation/create"),params:tr}),tn=_.extend({action:a.z.union([a.z.literal("accept"),a.z.literal("decline"),a.z.literal("cancel")]),content:a.z.optional(a.z.record(a.z.string(),a.z.unknown()))}),ti=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.union([a.z.string(),a.z.number().int()])}).merge(E).strict(),ts=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.union([a.z.string(),a.z.number().int()]),result:_}).strict(),ta=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.optional(a.z.union([a.z.string(),a.z.number().int()])),error:a.z.object({code:a.z.number().int(),message:a.z.string(),data:a.z.optional(a.z.unknown())})}).strict(),tl=a.z.object({jsonrpc:a.z.literal("2.0")}).merge(a.z.object({method:a.z.string(),params:a.z.optional(b)})).strict(),tc=a.z.union([ti,tl,ts,ta]);function tu(t){return tc.parse(t)}async function tp(t){return tu(await (0,s.parseJSON)({text:t}))}var th="vercel.ai.error.AI_MCPClientError",td=Symbol.for(th),tm=class extends(o=l.AISDKError,r=td,o){constructor({name:t="MCPClientError",message:e,cause:o,data:n,code:i,statusCode:s,url:a,responseBody:l}){super({name:t,message:e,cause:o}),this[r]=!0,this.data=n,this.code=i,this.statusCode=s,this.url=a,this.responseBody=l}static isInstance(t){return l.AISDKError.hasMarker(t,th)}},tf="u">typeof __PACKAGE_VERSION__?__PACKAGE_VERSION__:"0.0.0-test",tz=a.z.string().url().superRefine((t,e)=>{if(!URL.canParse(t))return e.addIssue({code:a.z.ZodIssueCode.custom,message:"URL must be parseable",fatal:!0}),a.z.NEVER}).refine(t=>{let e=new URL(t);return"javascript:"!==e.protocol&&"data:"!==e.protocol&&"vbscript:"!==e.protocol},{message:"URL cannot use javascript:, data:, or vbscript: scheme"}),tg=a.z.object({access_token:a.z.string(),id_token:a.z.string().optional(),token_type:a.z.string(),expires_in:a.z.number().optional(),scope:a.z.string().optional(),refresh_token:a.z.string().optional(),issuer:tz.optional(),authorization_server:tz.optional(),token_endpoint:tz.optional()}).strip(),tv=a.z.looseObject({resource:a.z.string().url(),authorization_servers:a.z.array(tz).optional(),jwks_uri:a.z.string().url().optional(),scopes_supported:a.z.array(a.z.string()).optional(),bearer_methods_supported:a.z.array(a.z.string()).optional(),resource_signing_alg_values_supported:a.z.array(a.z.string()).optional(),resource_name:a.z.string().optional(),resource_documentation:a.z.string().optional(),resource_policy_uri:a.z.string().url().optional(),resource_tos_uri:a.z.string().url().optional(),tls_client_certificate_bound_access_tokens:a.z.boolean().optional(),authorization_details_types_supported:a.z.array(a.z.string()).optional(),dpop_signing_alg_values_supported:a.z.array(a.z.string()).optional(),dpop_bound_access_tokens_required:a.z.boolean().optional()}),tw=a.z.looseObject({issuer:a.z.string(),authorization_endpoint:tz,token_endpoint:tz,registration_endpoint:tz.optional(),authorization_response_iss_parameter_supported:a.z.boolean().optional(),client_id_metadata_document_supported:a.z.boolean().optional(),scopes_supported:a.z.array(a.z.string()).optional(),response_types_supported:a.z.array(a.z.string()),grant_types_supported:a.z.array(a.z.string()).optional(),code_challenge_methods_supported:a.z.array(a.z.string()).optional(),token_endpoint_auth_methods_supported:a.z.array(a.z.string()).optional(),token_endpoint_auth_signing_alg_values_supported:a.z.array(a.z.string()).optional()}),ty=a.z.looseObject({issuer:a.z.string(),authorization_endpoint:tz,token_endpoint:tz,userinfo_endpoint:tz.optional(),jwks_uri:tz,registration_endpoint:tz.optional(),authorization_response_iss_parameter_supported:a.z.boolean().optional(),client_id_metadata_document_supported:a.z.boolean().optional(),scopes_supported:a.z.array(a.z.string()).optional(),response_types_supported:a.z.array(a.z.string()),grant_types_supported:a.z.array(a.z.string()).optional(),subject_types_supported:a.z.array(a.z.string()),id_token_signing_alg_values_supported:a.z.array(a.z.string()),claims_supported:a.z.array(a.z.string()).optional(),token_endpoint_auth_methods_supported:a.z.array(a.z.string()).optional()}).merge(tw.pick({code_challenge_methods_supported:!0})),tb=a.z.object({client_id:a.z.string(),client_secret:a.z.string().optional(),client_id_issued_at:a.z.number().optional(),client_secret_expires_at:a.z.number().optional(),issuer:tz.optional(),authorization_server:tz.optional(),token_endpoint:tz.optional()}).strip(),t_=a.z.object({redirect_uris:a.z.array(tz),application_type:a.z.union([a.z.literal("native"),a.z.literal("web")]).optional(),token_endpoint_auth_method:a.z.string().optional(),grant_types:a.z.array(a.z.string()).optional(),response_types:a.z.array(a.z.string()).optional(),client_name:a.z.string().optional(),client_uri:tz.optional(),logo_uri:tz.optional(),scope:a.z.string().optional(),contacts:a.z.array(a.z.string()).optional(),tos_uri:tz.optional(),policy_uri:a.z.string().optional(),jwks_uri:tz.optional(),jwks:a.z.any().optional(),software_id:a.z.string().optional(),software_version:a.z.string().optional(),software_statement:a.z.string().optional()}).strip(),tE=a.z.object({error:a.z.string(),error_description:a.z.string().optional(),error_uri:a.z.string().optional()}),tS=t_.merge(tb),tC="vercel.ai.error.AI_MCPClientOAuthError",tT=Symbol.for(tC),tx=class extends(i=l.AISDKError,n=tT,i){constructor({name:t="MCPClientOAuthError",message:e,cause:r}){super({name:t,message:e,cause:r}),this[n]=!0}static isInstance(t){return l.AISDKError.hasMarker(t,tC)}},tP=class extends tx{};tP.errorCode="server_error";var tR=class extends tx{};tR.errorCode="invalid_client";var tI=class extends tx{};tI.errorCode="invalid_grant";var tA=class extends tx{};tA.errorCode="unauthorized_client";var tj={[tP.errorCode]:tP,[tR.errorCode]:tR,[tI.errorCode]:tI,[tA.errorCode]:tA};function tk(t){let e=t.href;return"/"===t.pathname&&e.endsWith("/")?e.slice(0,-1):e}var tU=class extends Error{constructor(t="Unauthorized"){super(t),this.name="UnauthorizedError"}};function tO(t){return new URL(t).href}function tM(t){let e=t.toLowerCase().replace(/\.+$/,"");return"localhost"===e||e.endsWith(".localhost")||"127.0.0.1"===e||"[::1]"===e||"::1"===e}function t$(t){if(!(("http:"===t.protocol||"https:"===t.protocol)&&tM(t.hostname)))try{(0,s.validateDownloadUrl)(t.href)}catch(e){throw new tx({message:`OAuth endpoint URL is not allowed: ${t.href}`,cause:e})}}function tH(t,e){return{...t,issuer:e.issuer,authorization_server:e.authorizationServerUrl,token_endpoint:e.tokenEndpoint}}function tN(t,e){return{...t,issuer:e.issuer,authorization_server:e.authorizationServerUrl,token_endpoint:e.tokenEndpoint}}function tV(t){if((null==t?void 0:t.authorization_server)&&t.token_endpoint)return{issuer:t.issuer,authorizationServerUrl:tO(t.authorization_server),tokenEndpoint:tO(t.token_endpoint)}}async function tL({provider:t,clientInformation:e,tokens:r}){var o;let n=tV(r);if(n)return n;let i=await (null==(o=t.authorizationServerInformation)?void 0:o.call(t));return i?{issuer:i.issuer,authorizationServerUrl:tO(i.authorizationServerUrl),tokenEndpoint:tO(i.tokenEndpoint)}:tV(e)}async function tq({provider:t,clientInformation:e,authorizationServerInformation:r}){return t.saveAuthorizationServerInformation?(await t.saveAuthorizationServerInformation(r),!0):!!t.saveClientInformation&&(await t.saveClientInformation(tN(e,r)),!0)}function tD({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:e}){if(null!=t.issuer&&null!=e.issuer&&t.issuer!==e.issuer||t.authorizationServerUrl!==e.authorizationServerUrl||t.tokenEndpoint!==e.tokenEndpoint)throw new tx({message:"OAuth authorization server metadata does not match the metadata that issued the stored credentials"})}function tF(t){var e,r;let o,n=null!=(e=t.headers.get("www-authenticate"))?e:t.headers.get("WWW-Authenticate");if(!n)return{};let[i,s]=n.split(" ");if("bearer"!==i.toLowerCase()||!s)return{};let a=n.match(/(?:^|[,\s])resource_metadata="([^"]*)"/i),l=null==(r=n.match(/(?:^|[,\s])scope="([^"]*)"/i))?void 0:r[1];try{o=a?new URL(a[1]):void 0}catch(t){}return{resourceMetadataUrl:o,scope:l}}async function tB(t,e,r=fetch){try{return await r(t,{headers:e})}catch(o){if(o instanceof TypeError)if(e)return tB(t,void 0,r);else return;throw o}}async function tW(t,e,r=fetch){return await tB(t,{"MCP-Protocol-Version":e},r)}async function tJ(t,e,r,o){var n,i,s,a;let l,c=new URL(t),u=null!=(n=null==o?void 0:o.protocolVersion)?n:z;(null==o?void 0:o.metadataUrl)?l=new URL(o.metadataUrl):(l=new URL(function(t,e="",r={}){return e.endsWith("/")&&(e=e.slice(0,-1)),r.prependPathname?`${e}/.well-known/${t}`:`/.well-known/${t}${e}`}(e,c.pathname),null!=(i=null==o?void 0:o.metadataServerUrl)?i:c)).search=c.search;let p=await tW(l,u,r);if(!(null==o?void 0:o.metadataUrl)&&(s=p,a=c.pathname,!s||s.status>=400&&s.status<500&&"/"!==a)){let t=new URL(`/.well-known/${e}`,c);p=await tW(t,u,r)}return p}async function tK(t,e,r=fetch){let o=await tJ(t,"oauth-protected-resource",r,{protocolVersion:null==e?void 0:e.protocolVersion,metadataUrl:null==e?void 0:e.resourceMetadataUrl});if(!o||404===o.status)throw Error("Resource server does not implement OAuth 2.0 Protected Resource Metadata.");if(!o.ok)throw Error(`HTTP ${o.status} trying to load well-known OAuth protected resource metadata.`);return tv.parse(await o.json())}function tZ(t,e){if(t.issuer!==e&&(e!==new URL(e).origin||t.issuer!==`${e}/`))throw new tx({message:`OAuth authorization server metadata issuer ${t.issuer} does not match expected issuer ${e}`})}async function tG(t,{fetchFn:e=fetch,protocolVersion:r=z}={}){var o;let n={"MCP-Protocol-Version":r};for(let{url:r,type:i,expectedIssuer:s}of function(t){let e="string"==typeof t?new URL(t):t,r="/"!==e.pathname,o=e.origin,n=[];if(!r)return n.push({url:new URL("/.well-known/oauth-authorization-server",e.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL("/.well-known/openid-configuration",e.origin),type:"oidc",expectedIssuer:o}),n;let i=e.pathname;i.endsWith("/")&&(i=i.slice(0,-1));let s=`${e.origin}${i}`;return n.push({url:new URL(`/.well-known/oauth-authorization-server${i}`,e.origin),type:"oauth",expectedIssuer:s}),n.push({url:new URL("/.well-known/oauth-authorization-server",e.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL(`/.well-known/openid-configuration${i}`,e.origin),type:"oidc",expectedIssuer:s}),n.push({url:new URL(`${i}/.well-known/openid-configuration`,e.origin),type:"oidc",expectedIssuer:s}),n}(t)){let t=await tB(r,n,e);if(t){if(!t.ok){if(t.status>=400&&t.status<500)continue;throw Error(`HTTP ${t.status} trying to load ${"oauth"===i?"OAuth":"OpenID provider"} metadata from ${r}`)}if("oauth"===i){let e=tw.parse(await t.json());return tZ(e,s),e}{let e=ty.parse(await t.json());if(tZ(e,s),!(null==(o=e.code_challenge_methods_supported)?void 0:o.includes("S256")))throw Error(`Incompatible OIDC provider at ${r}: does not support S256 code challenge method required by MCP specification`);return e}}}}async function tY(t,{metadata:e,clientInformation:r,redirectUrl:o,scope:n,state:i,resource:s}){let a,l="code",c="S256";if(e){if(a=new URL(e.authorization_endpoint),!e.response_types_supported.includes(l))throw Error(`Incompatible auth server: does not support response type ${l}`);if(!e.code_challenge_methods_supported||!e.code_challenge_methods_supported.includes(c))throw Error(`Incompatible auth server: does not support code challenge method ${c}`)}else a=new URL("/authorize",t);let u=await m(),p=u.code_verifier,h=u.code_challenge;return a.searchParams.set("response_type",l),a.searchParams.set("client_id",r.client_id),a.searchParams.set("code_challenge",h),a.searchParams.set("code_challenge_method",c),a.searchParams.set("redirect_uri",String(o)),i&&a.searchParams.set("state",i),n&&a.searchParams.set("scope",n),(null==n?void 0:n.includes("offline_access"))&&a.searchParams.append("prompt","consent"),s&&a.searchParams.set("resource",tk(s)),{authorizationUrl:a,codeVerifier:p}}function tX(t,e){let r=void 0!==t.client_secret;return 0===e.length?r?"client_secret_post":"none":r&&e.includes("client_secret_basic")?"client_secret_basic":r&&e.includes("client_secret_post")?"client_secret_post":e.includes("none")?"none":r?"client_secret_post":"none"}function tQ(t,e,r,o){let{client_id:n,client_secret:i}=e;switch(t){case"client_secret_basic":var s,a,l,c,u=n,p=i,h=r;if(!p)throw Error("client_secret_basic authentication requires a client_secret");let d=btoa(`${u}:${p}`);h.set("Authorization",`Basic ${d}`);return;case"client_secret_post":s=n,a=i,(l=o).set("client_id",s),a&&l.set("client_secret",a);return;case"none":c=n,o.set("client_id",c);return;default:throw Error(`Unsupported client authentication method: ${t}`)}}async function t0(t){let e=t instanceof Response?t.status:void 0,r=t instanceof Response?await t.text():t;try{let{error:t,error_description:e,error_uri:o}=tE.parse(await (0,s.parseJSON)({text:r}));return new(tj[t]||tP)({message:e||"",cause:o})}catch(t){return new tP({message:`${e?`HTTP ${e}: `:""}Invalid OAuth error response: ${t}. Raw body: ${r}`})}}async function t1(t,{metadata:e,clientInformation:r,authorizationCode:o,codeVerifier:n,redirectUri:i,resource:s,addClientAuthentication:a,fetchFn:l}){var c;let u="authorization_code",p=(null==e?void 0:e.token_endpoint)?new URL(e.token_endpoint):new URL("/token",t);if(t$(p),(null==e?void 0:e.grant_types_supported)&&!e.grant_types_supported.includes(u))throw Error(`Incompatible auth server: does not support grant type ${u}`);let h=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),d=new URLSearchParams({grant_type:u,code:o,code_verifier:n,redirect_uri:String(i)});a?await a(h,d,t,e):tQ(tX(r,null!=(c=null==e?void 0:e.token_endpoint_auth_methods_supported)?c:[]),r,h,d),s&&d.set("resource",tk(s));let m=await (null!=l?l:fetch)(p,{method:"POST",headers:h,body:d,redirect:"error"});if(!m.ok)throw await t0(m);return tg.parse(await m.json())}async function t2(t,{metadata:e,clientInformation:r,refreshToken:o,resource:n,addClientAuthentication:i,fetchFn:s}){var a;let l,c="refresh_token";if(e){if(l=new URL(e.token_endpoint),e.grant_types_supported&&!e.grant_types_supported.includes(c))throw Error(`Incompatible auth server: does not support grant type ${c}`)}else l=new URL("/token",t);t$(l);let u=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),p=new URLSearchParams({grant_type:c,refresh_token:o});i?await i(u,p,t,e):tQ(tX(r,null!=(a=null==e?void 0:e.token_endpoint_auth_methods_supported)?a:[]),r,u,p),n&&p.set("resource",tk(n));let h=await (null!=s?s:fetch)(l,{method:"POST",headers:u,body:p,redirect:"error"});if(!h.ok)throw await t0(h);return tg.parse({refresh_token:o,...await h.json()})}async function t4(t,{metadata:e,clientMetadata:r,fetchFn:o}){var n;let i;if(e){if(!e.registration_endpoint)throw Error("Incompatible auth server: does not support dynamic client registration");i=new URL(e.registration_endpoint)}else i=new URL("/register",t);t$(i);let s=null!=(n=r.application_type)?n:r.redirect_uris.every(t=>{let e=new URL(t);return("http:"===e.protocol||"https:"===e.protocol)&&tM(e.hostname)||"http:"!==e.protocol&&"https:"!==e.protocol})?"native":"web",a=await (null!=o?o:fetch)(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,application_type:s}),redirect:"error"});if(!a.ok)throw await t0(a);return tS.parse(await a.json())}async function t3(t,e){var r,o;try{return await t6(t,e)}catch(n){if(n instanceof tR||n instanceof tA)return await (null==(r=t.invalidateCredentials)?void 0:r.call(t,"all")),await t6(t,e);if(n instanceof tI)return await (null==(o=t.invalidateCredentials)?void 0:o.call(t,"tokens")),await t6(t,e);throw n}}async function t5(t,e,r){let o,n=((o=new URL("string"==typeof t?t:t.href)).hash="",o);if(e.validateResourceURL)return await e.validateResourceURL(n,null==r?void 0:r.resource);if(r){if(!function({requestedResource:t,configuredResource:e}){let r=new URL("string"==typeof t?t:t.href),o=new URL("string"==typeof e?e:e.href);if(r.origin!==o.origin||r.pathname.length<o.pathname.length)return!1;let n=r.pathname.endsWith("/")?r.pathname:r.pathname+"/",i=o.pathname.endsWith("/")?o.pathname:o.pathname+"/";return n.startsWith(i)}({requestedResource:n,configuredResource:r.resource}))throw Error(`Protected resource ${r.resource} does not match expected ${n} (or origin)`);return new URL(r.resource)}}async function t6(t,{serverUrl:e,authorizationCode:r,callbackState:o,callbackIssuer:n,scope:i,resourceMetadataUrl:s,fetchFn:a}){var l,c,u,p,h,d;let m,f;!function(t,e){if(!e)return;let r=new URL(t).origin;if(e.origin!==r)throw new tx({message:`OAuth protected resource metadata URL ${e.href} must have the same origin as the MCP server URL ${r}`})}(e,s);try{(m=await tK(e,{resourceMetadataUrl:s},a)).authorization_servers&&m.authorization_servers.length>0&&(f=m.authorization_servers[0])}catch(t){}f||(f=e);let z=await t5(e,t,m);await (null==(l=t.validateAuthorizationServerURL)?void 0:l.call(t,e,f));let g=await tG(f,{fetchFn:a}),v=(h=f,{issuer:null!=(d=null==g?void 0:g.issuer)?d:String(h),authorizationServerUrl:tO(h),tokenEndpoint:tO((null==g?void 0:g.token_endpoint)?new URL(g.token_endpoint):new URL("/token",h))}),w=t.clientMetadata,y=function({scope:t,resourceMetadata:e,clientMetadata:r}){var o;if(t)return t;let n=null==(o=null==e?void 0:e.scopes_supported)?void 0:o.join(" ");return n||r.scope}({scope:i,resourceMetadata:m,clientMetadata:w}),b=await Promise.resolve(t.clientInformation());if((null==b?void 0:b.issuer)!=null){let e=await tL({provider:t,clientInformation:b});e&&tD({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:v})}if(!b){if(void 0!==r)throw Error("Existing OAuth client information is required when exchanging an authorization code");if(!t.saveClientInformation)throw Error("OAuth client information must be saveable for dynamic registration");b=tN(await t4(f,{metadata:g,clientMetadata:{...w,scope:y},fetchFn:a}),v),await t.saveClientInformation(b)}if(void 0!==r){if(t.storedState){let e=await t.storedState();if(void 0!==e&&e!==o)throw Error("OAuth state parameter mismatch - possible CSRF attack")}let e=await tL({provider:t,clientInformation:b});if(!e)throw new tx({message:"Stored OAuth authorization server metadata is required when exchanging an authorization code"});!function({callbackIssuer:t,expectedIssuer:e}){if(null!=t&&t!==e)throw new tx({message:`OAuth authorization response issuer ${t} does not match expected issuer ${e}`})}({callbackIssuer:n,expectedIssuer:null!=(u=null!=(c=e.issuer)?c:null==g?void 0:g.issuer)?u:String(f)}),tD({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:v});let i=await t.codeVerifier(),s=await t1(f,{metadata:g,clientInformation:b,authorizationCode:r,codeVerifier:i,redirectUri:t.redirectUrl,resource:z,addClientAuthentication:t.addClientAuthentication,fetchFn:a});return await t.saveTokens(tH(s,v)),"AUTHORIZED"}let _=await t.tokens();if(null==_?void 0:_.refresh_token){let e=await tL({provider:t,clientInformation:b,tokens:_});e?tD({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:v}):await (null==(p=t.invalidateCredentials)?void 0:p.call(t,"tokens"));try{if(e){let e=await t2(f,{metadata:g,clientInformation:b,refreshToken:_.refresh_token,resource:z,addClientAuthentication:t.addClientAuthentication,fetchFn:a});return await t.saveTokens(tH(e,v)),"AUTHORIZED"}}catch(t){if(!(t instanceof tx)||t instanceof tP);else throw t}}let E=t.state?await t.state():void 0;E&&t.saveState&&await t.saveState(E);let{authorizationUrl:S,codeVerifier:C}=await tY(f,{metadata:g,clientInformation:b,state:E,redirectUrl:t.redirectUrl,scope:y,resource:z});if(!await tq({provider:t,clientInformation:b,authorizationServerInformation:v}))throw new tx({message:"OAuth authorization server metadata must be saveable before starting authorization"});return await t.saveCodeVerifier(C),await t.redirectToAuthorization(S),"REDIRECT"}var t8=class{constructor({url:t,headers:e,authProvider:r,redirect:o="error",fetch:n}){this.connected=!1,this.url=new URL(t),this.headers=e,this.authProvider=r,this.redirectMode=o,this.fetchFn=null!=n?n:globalThis.fetch}setProtocolVersion(t){this.protocolVersion=t}async commonHeaders(t){var e;let r={...this.headers,...t,"mcp-protocol-version":null!=(e=this.protocolVersion)?e:g};if(this.authProvider){let t=await this.authProvider.tokens();(null==t?void 0:t.access_token)&&(r.Authorization=`Bearer ${t.access_token}`)}return(0,s.withUserAgentSuffix)(r,`ai-sdk/${tf}`,(0,s.getRuntimeEnvironmentUserAgent)())}async start(){return new Promise((t,e)=>{if(this.connected)return t();this.abortController=new AbortController;let r=async(o=!1)=>{var n,i,s,a,l;try{let l=await this.commonHeaders({Accept:"text/event-stream"}),u=await this.fetchFn(this.url.href,{headers:l,signal:null==(n=this.abortController)?void 0:n.signal,redirect:this.redirectMode});if(401===u.status&&this.authProvider&&!o){let{resourceMetadataUrl:t,scope:o}=tF(u);this.resourceMetadataUrl=t;try{let t=await t3(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,scope:o,fetchFn:this.fetchFn});if("AUTHORIZED"!==t){let t=new tU;return null==(i=this.onerror)||i.call(this,t),e(t)}}catch(t){return null==(s=this.onerror)||s.call(this,t),e(t)}return r(!0)}if(!u.ok||!u.body){let t=`MCP SSE Transport Error: ${u.status} ${u.statusText}`;405===u.status&&(t+=". This server does not support SSE transport. Try using `http` transport instead");let r=new tm({message:t});return null==(a=this.onerror)||a.call(this,r),e(r)}let p=u.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader(),h=async()=>{var r,o,n,i,s;try{for(;;){let{done:e,value:s}=await p.read();if(e){if(this.connected)throw this.connected=!1,new tm({message:"MCP SSE Transport Error: Connection closed unexpectedly"});return}let{event:a,data:l}=s;if("endpoint"===a){if(this.endpoint)continue;let e=new URL(l,this.url);if(e.origin!==this.url.origin)throw this.connected=!1,this.endpoint=void 0,null==(r=this.sseConnection)||r.close(),null==(o=this.abortController)||o.abort(),new tm({message:`MCP SSE Transport Error: Endpoint origin does not match connection origin: ${e.origin}`});this.endpoint=e,this.connected=!0,t()}else if(void 0===a||"message"===a)try{let t=await tp(l);null==(n=this.onmessage)||n.call(this,t)}catch(e){let t=new tm({message:"MCP SSE Transport Error: Failed to parse message",cause:e});null==(i=this.onerror)||i.call(this,t)}}}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(s=this.onerror)||s.call(this,t),e(t)}};this.sseConnection={close:()=>p.cancel()},h()}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(l=this.onerror)||l.call(this,t),e(t)}};r()})}async close(){var t,e,r;this.connected=!1,this.endpoint=void 0,null==(t=this.sseConnection)||t.close(),null==(e=this.abortController)||e.abort(),null==(r=this.onclose)||r.call(this)}async send(t,e){var r,o;if(null==(r=null==e?void 0:e.signal)||r.throwIfAborted(),!this.endpoint||!this.connected)throw new tm({message:"MCP SSE Transport Error: Not connected"});let n=this.endpoint,i=null==(o=this.abortController)?void 0:o.signal,s=(null==e?void 0:e.signal)==null?i:null==i?e.signal:AbortSignal.any([i,e.signal]),a=async(r=!1)=>{var o,i;try{let e=await this.commonHeaders({"Content-Type":"application/json"}),o={method:"POST",headers:e,body:JSON.stringify(t),signal:s,redirect:this.redirectMode},i=await this.fetchFn(n.href,o);if(401===i.status&&this.authProvider&&!r){let{resourceMetadataUrl:t,scope:e}=tF(i);this.resourceMetadataUrl=t;let r=await t3(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,scope:e,fetchFn:this.fetchFn});if("AUTHORIZED"!==r)throw new tU;return a(!0)}if(!i.ok){let t=await i.text().catch(()=>null);throw new tm({message:`MCP SSE Transport Error: POSTing to endpoint (HTTP ${i.status}): ${t}`,statusCode:i.status,url:n.href,responseBody:null!=t?t:void 0})}}catch(t){if(null==(o=null==e?void 0:e.signal)?void 0:o.aborted)throw t;throw null==(i=this.onerror)||i.call(this,t),t}};await a()}},t7=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,t9=/^=\?base64\?.*\?=$/;function et(t){return[...t].every(t=>{let e=t.charCodeAt(0);return 9===e||e>=32&&e<=126})&&t.trim()===t&&!t9.test(t)?t:`=?base64?${(0,s.convertUint8ArrayToBase64)(new TextEncoder().encode(t))}?=`}function ee(t){return void 0===t||"message"===t}var er=class{constructor({url:t,headers:e,authProvider:r,redirect:o="error",initialSessionId:n,initialProtocolVersion:i,onSessionIdChange:s,onSessionExpired:a,terminateSessionOnClose:l=!0,fetch:c}){this.supportsProtocolVersionDiscovery=!0,this.supportsMcpToolParameterHeaders=!0,this.inboundReconnectAttempts=0,this.reconnectionOptions={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},this.url=new URL(t),this.headers=e,this.authProvider=r,this.redirectMode=o,this.sessionId=n,this.protocolVersion=null!=i?i:g,this.onSessionIdChange=s,this.onSessionExpired=a,this.terminateSessionOnClose=l,this.fetchFn=null!=c?c:globalThis.fetch}setProtocolVersion(t){var e;if(this.protocolVersion=t,this.abortController){if(this.isModernProtocol()){null==(e=this.inboundSseConnection)||e.close(),this.inboundSseConnection=void 0;return}this.inboundSseConnection||this.startInboundSse()}}isModernProtocol(){var t;return(null!=(t=this.protocolVersion)?t:z)===z}async commonHeaders({base:t,includeSessionId:e=!0}){var r;let o={...this.headers,...t,"mcp-protocol-version":null!=(r=this.protocolVersion)?r:g};if(!this.isModernProtocol()&&e&&this.sessionId&&(o["mcp-session-id"]=this.sessionId),this.authProvider){let t=await this.authProvider.tokens();(null==t?void 0:t.access_token)&&(o.Authorization=`Bearer ${t.access_token}`)}return(0,s.withUserAgentSuffix)(o,`ai-sdk/${tf}`,(0,s.getRuntimeEnvironmentUserAgent)())}setSessionId(t){var e;this.sessionId!==t&&(this.sessionId=t,null==(e=this.onSessionIdChange)||e.call(this,t))}applySessionIdFromResponse(t){if(this.isModernProtocol())return;let e=t.headers.get("mcp-session-id");e&&this.setSessionId(e)}expireSessionId(t){var e;this.sessionId===t&&this.setSessionId(void 0),null==(e=this.onSessionExpired)||e.call(this,t)}authorizeOnce(t,e){return this.authProvider?(this.authPromise||(this.authPromise=t3(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:t,scope:e,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0})),this.authPromise):Promise.resolve("REDIRECT")}async start(){if(this.abortController)throw new tm({message:"MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."});this.abortController=new AbortController,null!=this.protocolVersion&&this.protocolVersion!==z&&this.startInboundSse()}async close(t){var e,r,o,n,i;null==(e=this.inboundSseConnection)||e.close(),null==(r=this.abortController)||r.abort();try{if(!this.isModernProtocol()&&this.sessionId&&this.terminateSessionOnClose&&this.abortController){null==(o=null==t?void 0:t.signal)||o.throwIfAborted();let e=await this.commonHeaders({base:{}});null==(n=null==t?void 0:t.signal)||n.throwIfAborted(),await this.fetchFn(this.url.href,{method:"DELETE",headers:e,signal:null==t?void 0:t.signal,redirect:this.redirectMode}).catch(()=>void 0)}}catch(t){}null==(i=this.onclose)||i.call(this)}async send(t,e){var r,o;null==(r=null==e?void 0:e.signal)||r.throwIfAborted();let n=null==(o=this.abortController)?void 0:o.signal,i=(null==e?void 0:e.signal)==null?n:null==n?e.signal:AbortSignal.any([n,e.signal]),s=async(r=!1)=>{var o,n,a,l,u,p,h,d;try{let h="method"in t&&"initialize"===t.method,d=h?void 0:this.sessionId,m=await this.commonHeaders({base:{"Content-Type":"application/json",Accept:"application/json, text/event-stream",...this.isModernProtocol()?null==e?void 0:e.headers:{},...this.isModernProtocol()&&"method"in t&&"id"in t?this.getStandardRequestHeaders(t):{}},includeSessionId:!h}),f={method:"POST",headers:m,body:JSON.stringify(t),signal:i,redirect:this.redirectMode},z=await this.fetchFn(this.url.href,f);if(this.applySessionIdFromResponse(z),401===z.status&&this.authProvider&&!r){let{resourceMetadataUrl:t,scope:e}=tF(z);this.resourceMetadataUrl=t;try{let t=await this.authorizeOnce(this.resourceMetadataUrl,e);if("AUTHORIZED"!==t)throw new tU}catch(t){throw null==(o=this.onerror)||o.call(this,t),t}return s(!0)}if(202===z.status){this.isModernProtocol()||this.inboundSseConnection||this.startInboundSse();return}if(!z.ok){let e=await z.text().catch(()=>null);if("id"in t&&null!=e){let r=await tp(e).catch(()=>void 0);if(null!=r&&"error"in r){null==(n=this.onmessage)||n.call(this,null==r.id?{...r,id:t.id}:r);return}}let r=`MCP HTTP Transport Error: POSTing to endpoint (HTTP ${z.status}): ${e}`;404===z.status&&(!this.isModernProtocol()&&d?(this.expireSessionId(d),r+=". The MCP session expired. Create a new client without `initialSessionId` to start a fresh session"):this.isModernProtocol()||(r+=". This server does not support HTTP transport. Try using `sse` transport instead"));let o=new tm({message:r,statusCode:z.status,url:this.url.href,responseBody:null!=e?e:void 0});throw null==(a=this.onerror)||a.call(this,o),o}if(!("id"in t))return;let g=z.headers.get("content-type")||"";if(g.includes("application/json")){let t=await z.json();for(let e of Array.isArray(t)?t.map(t=>tu(t)):[tu(t)])null==(l=this.onmessage)||l.call(this,e);return}if(g.includes("text/event-stream")){if(!z.body){let t=new tm({message:"MCP HTTP Transport Error: text/event-stream response without body",statusCode:z.status,url:this.url.href});throw null==(u=this.onerror)||u.call(this,t),t}let t=z.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader();(async()=>{var r,o,n,i;try{for(;;){let{done:e,value:n}=await t.read();if(e)return;let{event:i,data:s}=n;if(ee(i))try{let t=await tp(s);null==(r=this.onmessage)||r.call(this,t)}catch(e){let t=new tm({message:"MCP HTTP Transport Error: Failed to parse message",cause:e});null==(o=this.onerror)||o.call(this,t)}}}catch(t){if((null==(n=null==e?void 0:e.signal)?void 0:n.aborted)||t instanceof Error&&"AbortError"===t.name)return;null==(i=this.onerror)||i.call(this,t)}})().catch(t=>{var r,o;null!=(r=null==e?void 0:e.signal)&&r.aborted||t instanceof Error&&"AbortError"===t.name||null==(o=this.onerror)||o.call(this,t)});return}let v=new tm({message:`MCP HTTP Transport Error: Unexpected content type: ${g}`,statusCode:z.status,url:this.url.href});throw null==(p=this.onerror)||p.call(this,v),v}catch(t){if(null==(h=null==e?void 0:e.signal)?void 0:h.aborted)throw t;throw null==(d=this.onerror)||d.call(this,t),t}};await s()}getStandardRequestHeaders(t){let e={"Mcp-Method":t.method},r=t.params,o="resources/read"===t.method?null==r?void 0:r.uri:"tools/call"===t.method||"prompts/get"===t.method?null==r?void 0:r.name:void 0;return"string"==typeof o&&(e["Mcp-Name"]=et(o)),e}getNextReconnectionDelay(t){let{initialReconnectionDelay:e,reconnectionDelayGrowFactor:r,maxReconnectionDelay:o}=this.reconnectionOptions;return Math.min(e*Math.pow(r,t),o)}scheduleInboundSseReconnection(){var t;let{maxRetries:e}=this.reconnectionOptions;if(e>0&&this.inboundReconnectAttempts>=e){null==(t=this.onerror)||t.call(this,new tm({message:`MCP HTTP Transport Error: Maximum reconnection attempts (${e}) exceeded.`}));return}let r=this.getNextReconnectionDelay(this.inboundReconnectAttempts);this.inboundReconnectAttempts+=1,setTimeout(()=>{var t;null!=(t=this.abortController)&&t.signal.aborted||this.startInboundSse(!1,this.lastInboundEventId)},r)}startInboundSse(t=!1,e){this.isModernProtocol()||this.openInboundSse(t,e).catch(t=>{var e;t instanceof Error&&"AbortError"===t.name||null==(e=this.onerror)||e.call(this,t)})}async openInboundSse(t=!1,e){var r,o,n,i,s,a;if(!this.isModernProtocol())try{let s=this.sessionId,a=await this.commonHeaders({base:{Accept:"text/event-stream"}});e&&(a["last-event-id"]=e);let l=await this.fetchFn(this.url.href,{method:"GET",headers:a,signal:null==(r=this.abortController)?void 0:r.signal,redirect:this.redirectMode});if(this.applySessionIdFromResponse(l),401===l.status&&this.authProvider&&!t){let{resourceMetadataUrl:t,scope:r}=tF(l);this.resourceMetadataUrl=t;try{let t=await this.authorizeOnce(this.resourceMetadataUrl,r);if("AUTHORIZED"!==t){let t=new tU;null==(o=this.onerror)||o.call(this,t);return}}catch(t){null==(n=this.onerror)||n.call(this,t);return}return this.openInboundSse(!0,e)}if(405===l.status)return;if(!l.ok||!l.body){404===l.status&&s&&this.expireSessionId(s);let t=new tm({message:`MCP HTTP Transport Error: GET SSE failed: ${l.status} ${l.statusText}`,statusCode:l.status,url:this.url.href});null==(i=this.onerror)||i.call(this,t);return}let u=l.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader(),p=async()=>{var t,e,r,o;try{for(;;){let{done:r,value:o}=await u.read();if(r)return;let{event:n,data:i,id:s}=o;if(s&&(this.lastInboundEventId=s),ee(n))try{let e=await tp(i);null==(t=this.onmessage)||t.call(this,e)}catch(r){let t=new tm({message:"MCP HTTP Transport Error: Failed to parse message",cause:r});null==(e=this.onerror)||e.call(this,t)}}}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(r=this.onerror)||r.call(this,t),(null==(o=this.abortController)?void 0:o.signal.aborted)||this.scheduleInboundSseReconnection()}};this.inboundSseConnection={close:()=>{u.cancel().catch(t=>{var e;t instanceof Error&&"AbortError"===t.name||null==(e=this.onerror)||e.call(this,t)})}},this.inboundReconnectAttempts=0,p().catch(t=>{var e,r;t instanceof Error&&"AbortError"===t.name||(null==(e=this.onerror)||e.call(this,t),(null==(r=this.abortController)?void 0:r.signal.aborted)||this.scheduleInboundSseReconnection())})}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(s=this.onerror)||s.call(this,t),(null==(a=this.abortController)?void 0:a.signal.aborted)||this.scheduleInboundSseReconnection()}}},eo=f.array(f.unknown()).transform(t=>t.filter(t=>"string"==typeof t)).optional().catch(void 0),en=f.looseObject({connectDomains:eo,resourceDomains:eo,frameDomains:eo});f.looseObject({prefersBorder:f.boolean().optional().catch(void 0),csp:en.optional().catch(void 0),permissions:f.record(f.string(),f.unknown()).optional().catch(void 0)});var ei=[-32020,-32021,-32022],es=["ConnectionRefused","ConnectionClosed","FailedToOpenSocket","ECONNRESET","ECONNREFUSED","ETIMEDOUT","EPIPE"];function ea(t){let e=function(t){if(null!=t&&"object"==typeof t&&"statusCode"in t&&"number"==typeof t.statusCode)return t.statusCode}(t);if(null!=e)return 408===e||409===e||429===e||e>=500;if(tm.isInstance(t)&&null!=t.code)return!1;let r=function(t){if(null!=t&&"object"==typeof t&&"code"in t&&"string"==typeof t.code)return t.code}(t);return null!=r&&es.includes(r)}function el({timeout:t,maxTotalTimeout:e}){return null==t?e:null==e?t:Math.min(t,e)}function ec(t,e){return null==e?t:new Promise((r,o)=>{let n=()=>{e.removeEventListener("abort",i)},i=()=>{n(),o(e.reason)};e.aborted?i():(e.addEventListener("abort",i,{once:!0}),t.then(t=>{n(),r(t)}).catch(t=>{n(),o(t)}))})}function eu({output:t}){return"content"in t&&Array.isArray(t.content)?{type:"content",value:t.content.map(t=>"text"===t.type&&"text"in t?{type:"text",text:t.text}:"image"===t.type&&"data"in t&&"mimeType"in t?{type:"file",mediaType:t.mimeType,data:{type:"data",data:t.data}}:{type:"text",text:JSON.stringify(t)})}:{type:"json",value:t}}async function ep(t){let e=new eh(t);return await e.init(),e}var eh=class{constructor({transport:t,name:e,clientName:r=null!=e?e:"ai-sdk-mcp-client",version:o="1.0.0",onUncaughtError:n,maxRetries:i,capabilities:s,initialInitializeResult:a,initializationOptions:l,protocolVersionDiscovery:c=!0}){this.requestMessageId=0,this.responseHandlers=new Map,this.serverCapabilities={},this._serverInfo={name:"",version:""},this._initializeResult={protocolVersion:g,capabilities:{},serverInfo:this._serverInfo},this.protocolEra="legacy",this.protocolVersion=g,this.toolHeaderBindings=new Map,this.isClosed=!0,this.onUncaughtError=n,this.maxRetries=function(t){if(null==t)return 0;if(!Number.isInteger(t))throw new tm({message:"maxRetries must be an integer"});if(t<0)throw new tm({message:"maxRetries must be >= 0"});return t}(i),this.clientCapabilities=null!=s?s:{},this.initialInitializeResult=a,this.initializationOptions=l,this.protocolVersionDiscovery=c,function(t){return"start"in t&&"function"==typeof t.start&&"send"in t&&"function"==typeof t.send&&"close"in t&&"function"==typeof t.close}(t)?this.transport=t:this.transport=function(t){var e;switch(t.type){case"sse":return new t8(t);case"http":return new er({...t,initialProtocolVersion:null!=(e=t.initialProtocolVersion)?e:z});default:throw new tm({message:"Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."})}}(t),this.transport.onclose=()=>this.onClose(),this.transport.onerror=t=>this.onError(t),this.transport.onmessage=t=>{"method"in t?"id"in t?this.onRequestMessage(t):this.onError(new tm({message:"Unsupported message type"})):this.onResponse(t)},this.clientInfo={name:r,version:o}}get serverInfo(){return this._serverInfo}get initializeResult(){return this._initializeResult}get instructions(){return this._serverInstructions}async init(){var t;let e,r,o=null==(t=this.initializationOptions)?void 0:t.signal,n=this.initializationOptions?el(this.initializationOptions):void 0,i=null==n?void 0:new AbortController,s=null==o?null==i?void 0:i.signal:null==i?o:AbortSignal.any([o,i.signal]);null!=n&&(e=setTimeout(()=>{r=new tm({message:`MCP client initialization timed out after ${n}ms`}),null==i||i.abort(r)},n));try{if(this.isClosed=!1,null==s||s.throwIfAborted(),await ec(this.transport.start(),s),this.initialInitializeResult){let t=x.parse(this.initialInitializeResult);return this.applyInitializeResult(t),this}if(this.protocolVersionDiscovery&&this.transport.supportsProtocolVersionDiscovery&&await this.tryProtocolDiscovery(s))return this;this.protocolEra="legacy",this.protocolVersion=g,this.setTransportProtocolVersion(this.protocolVersion);let t=await this.request({request:{method:"initialize",params:{protocolVersion:g,capabilities:this.clientCapabilities,clientInfo:this.clientInfo}},resultSchema:x,options:{signal:s}});if(void 0===t)throw new tm({message:"Server sent invalid initialize result"});return this.applyInitializeResult(t),await this.notification({method:"notifications/initialized"},{signal:s}),this}catch(t){try{await ec(this.transport.close({signal:s}),s)}catch(t){}if(this.onClose(),null!=r)throw r;if(null==o?void 0:o.aborted)throw new tm({message:"MCP client initialization was aborted",cause:o.reason});throw t}finally{null!=e&&clearTimeout(e)}}async tryProtocolDiscovery(t){this.protocolEra="modern",this.protocolVersion=z,this.setTransportProtocolVersion(this.protocolVersion);try{let e=await this.request({request:{method:"server/discover"},resultSchema:T,options:{signal:t,timeout:1e3}});return this.applyDiscoverResult(e),!0}catch(t){if(tm.isInstance(t)&&null!=t.code&&ei.includes(t.code))throw t;return!1}}applyDiscoverResult(t){var e;if(!t.supportedVersions.includes(this.protocolVersion))throw new tm({message:`Server does not support the requested protocol version: ${this.protocolVersion}`});let r=null==(e=t._meta)?void 0:e["io.modelcontextprotocol/serverInfo"];null!=r&&"object"==typeof r&&"name"in r&&"string"==typeof r.name&&"version"in r&&"string"==typeof r.version&&(this._serverInfo=r),this.serverCapabilities=t.capabilities,this._serverInstructions=t.instructions,this._initializeResult={protocolVersion:this.protocolVersion,capabilities:t.capabilities,serverInfo:this._serverInfo,instructions:t.instructions}}setTransportProtocolVersion(t){this.transport.setProtocolVersion?this.transport.setProtocolVersion(t):this.transport.protocolVersion=t}applyInitializeResult(t){if(!v.includes(t.protocolVersion))throw new tm({message:`Server's protocol version is not supported: ${t.protocolVersion}`});this.serverCapabilities=t.capabilities,this.protocolEra="legacy",this.protocolVersion=t.protocolVersion,this._serverInfo=t.serverInfo,this._initializeResult=t,this.setTransportProtocolVersion(t.protocolVersion),this._serverInstructions=t.instructions}async close(){var t;this.isClosed||(await (null==(t=this.transport)?void 0:t.close()),this.onClose())}send(t,e){return null==e?this.transport.send(t):this.transport.send(t,e)}assertCapability(t){switch(t){case"initialize":case"server/discover":break;case"completion/complete":if(!this.serverCapabilities.completions)throw new tm({message:"Server does not support completions"});break;case"tools/list":case"tools/call":if(!this.serverCapabilities.tools)throw new tm({message:"Server does not support tools"});break;case"resources/list":case"resources/read":case"resources/templates/list":if(!this.serverCapabilities.resources)throw new tm({message:"Server does not support resources"});break;case"prompts/list":case"prompts/get":if(!this.serverCapabilities.prompts)throw new tm({message:"Server does not support prompts"});break;default:throw new tm({message:`Unsupported method: ${t}`})}}async request({request:t,resultSchema:e,options:r}){return new Promise((o,n)=>{var i;let s;if(this.isClosed)return n(new tm({message:"Attempted to send a request from a closed client"}));this.assertCapability(t.method);let a=null==r?void 0:r.signal;null==a||a.throwIfAborted();let l=null==r?void 0:el(r),c=null==l?void 0:new AbortController,u=null==a?null==c?void 0:c.signal:null==c?a:AbortSignal.any([a,c.signal]),p=this.requestMessageId++,h="modern"===this.protocolEra?{...t,params:{...t.params,_meta:{...null==(i=t.params)?void 0:i._meta,"io.modelcontextprotocol/protocolVersion":this.protocolVersion,"io.modelcontextprotocol/clientCapabilities":this.clientCapabilities,"io.modelcontextprotocol/clientInfo":this.clientInfo}}}:t,d={...h,jsonrpc:"2.0",id:p},m=this.getToolRequestHeaders(h),f=()=>{n(new tm({message:"Request was aborted",cause:null==a?void 0:a.reason}))},z=()=>{this.responseHandlers.delete(p),null==a||a.removeEventListener("abort",v),null!=s&&clearTimeout(s)},g=t=>{z(),n(t)},v=()=>{z(),f()};this.responseHandlers.set(p,t=>{if(null==a?void 0:a.aborted)return z(),f();if(t instanceof Error)return g(t);try{if("modern"===this.protocolEra&&null==t.result.resultType)throw new tm({message:"Modern MCP result is missing resultType"});if("input_required"===t.result.resultType)throw new tm({message:"Server requested additional input, but multi round-trip requests are not supported yet"});let r=e.parse(t.result);z(),o(r)}catch(t){g(tm.isInstance(t)?t:new tm({message:"Failed to parse server response",cause:t}))}}),null==a||a.addEventListener("abort",v,{once:!0}),null!=l&&(s=setTimeout(()=>{let t=new tm({message:`Request timed out after ${l}ms`});null==c||c.abort(t),g(t)},l));let w={...null==u?{}:{signal:u},...null==m?{}:{headers:m}};(0===Object.keys(w).length?this.send(d):this.send(d,w)).catch(t=>{g(t)})})}async listTools({params:t,options:e}={}){let r=await this.request({request:{method:"tools/list",params:t},resultSchema:I,options:e});return this.prepareToolDefinitions(r,(null==t?void 0:t.cursor)==null)}prepareToolDefinitions(t,e=!1){if("modern"!==this.protocolEra||!this.transport.supportsMcpToolParameterHeaders)return t;e&&this.toolHeaderBindings.clear();let r=t.tools.filter(t=>{let e=function(t){let e;if(!(0,s.isRecord)(t))return{success:!1,error:"inputSchema must be a JSON Schema object"};let r=[],o=new Set,n=(t,i,a)=>{if(null==e&&(0,s.isRecord)(t)){if("x-mcp-header"in t){if(!a||0===i.length){e="x-mcp-header is not on a statically reachable property";return}let n=t["x-mcp-header"];if("string"!=typeof n||!t7.test(n)){e="x-mcp-header must be a non-empty HTTP token";return}let s=n.toLowerCase();if(o.has(s)){e=`x-mcp-header value "${n}" is not unique`;return}let l=t.type;if("boolean"!==l&&"integer"!==l&&"string"!==l){e="x-mcp-header can only annotate boolean, integer, or string properties";return}o.add(s),r.push({headerName:n,path:i,valueType:l})}for(let[e,r]of Object.entries(t))if("x-mcp-header"!==e)if("properties"===e&&(0,s.isRecord)(r))for(let[t,e]of Object.entries(r))n(e,[...i,t],a);else n(r,i,!1)}};return n(t,[],!0),null==e?{success:!0,bindings:r}:{success:!1,error:e}}(t.inputSchema);return e.success?(this.toolHeaderBindings.set(t.name,e.bindings),!0):(this.onError(new tm({message:`Ignoring MCP tool "${t.name}": ${e.error}`})),!1)});return{...t,tools:r}}getToolRequestHeaders(t){var e;if("modern"!==this.protocolEra||"tools/call"!==t.method||"string"!=typeof(null==(e=t.params)?void 0:e.name))return;let r=this.toolHeaderBindings.get(t.params.name);if(null==r||0===r.length)return;let o=t.params.arguments;if(!(null==o||"object"!=typeof o||Array.isArray(o)))try{return function({bindings:t,args:e}){let r={};for(let o of t){let t=function(t,e){let r=t;for(let t of e){if(!(0,s.isRecord)(r))return;r=r[t]}return r}(e,o.path);if(null!=t){if("string"===o.valueType&&"string"!=typeof t||"boolean"===o.valueType&&"boolean"!=typeof t||"integer"===o.valueType&&!Number.isSafeInteger(t))throw TypeError(`Tool argument "${o.path.join(".")}" does not match its x-mcp-header type`);r[`Mcp-Param-${o.headerName}`]=et(String(t))}}return r}({bindings:r,args:o})}catch(e){throw new tm({message:`Failed to create MCP headers for tool "${t.params.name}"`,cause:e})}}async callToolWithRetry({options:t,execute:e}){return 0===this.maxRetries?e():(0,s.retryWithExponentialBackoff)({maxRetries:this.maxRetries,abortSignal:null==t?void 0:t.signal,shouldRetry:ea,createRetryError:({message:t,errors:e})=>new tm({message:t,cause:e[e.length-1]})})(e)}async callTool({name:t,arguments:e={},options:r}){try{return this.callToolWithRetry({options:r,execute:()=>this.request({request:{method:"tools/call",params:{name:t,arguments:e}},resultSchema:D,options:r})})}catch(t){throw t}}async listResourcesInternal({params:t,options:e}={}){try{return this.request({request:{method:"resources/list",params:t},resultSchema:U,options:e})}catch(t){throw t}}async readResourceInternal({uri:t,options:e}){try{return this.request({request:{method:"resources/read",params:{uri:t}},resultSchema:W,options:e})}catch(t){throw t}}async listResourceTemplatesInternal({options:t}={}){try{return this.request({request:{method:"resources/templates/list"},resultSchema:B,options:t})}catch(t){throw t}}async listPromptsInternal({params:t,options:e}={}){try{return this.request({request:{method:"prompts/list",params:t},resultSchema:Q,options:e})}catch(t){throw t}}async getPromptInternal({name:t,args:e,options:r}){try{return this.request({request:{method:"prompts/get",params:{name:t,arguments:e}},resultSchema:te,options:r})}catch(t){throw t}}async completeInternal({options:t,...e}){return this.request({request:{method:"completion/complete",params:e},resultSchema:G,options:t})}async notification(t,e){let r={...t,jsonrpc:"2.0"};await ec(this.send(r,(null==e?void 0:e.signal)==null?void 0:{signal:e.signal}),null==e?void 0:e.signal)}async tools({schemas:t="automatic"}={}){let e=await this.listTools(),r=[...e.tools];for(;null!=e.nextCursor;)e=await this.listTools({params:{cursor:e.nextCursor}}),r.push(...e.tools);return this.toolsFromDefinitions({...e,tools:r},{schemas:t})}toolsFromDefinitions(t,{schemas:e="automatic"}={}){var r,o;t=this.prepareToolDefinitions(t);let n={};for(let{name:i,title:a,description:c,inputSchema:u,annotations:p,_meta:h}of t.tools){let t=null!=a?a:null==p?void 0:p.title;if("automatic"!==e&&!Object.prototype.hasOwnProperty.call(e,i))continue;let d=this,m="automatic"!==e?null==(r=e[i])?void 0:r.outputSchema:void 0,f=function(t){var e,r,o,n;let i,s=(i=null==(o=t._meta)?void 0:o.ui,(0,l.isJSONObject)(i)?i:void 0),a=null!=(r=null==s?void 0:s.resourceUri)?r:null==(e=t._meta)?void 0:e["ui/resourceUri"],c=Array.isArray(n=null==s?void 0:s.visibility)?n.filter(t=>"model"===t||"app"===t):void 0;if(void 0!==a){if("string"!=typeof a||!a.startsWith("ui://"))throw Error(`Invalid MCP App resource URI: ${JSON.stringify(a)}`)}else if(null==s)return;return{...s,...null!=a?{resourceUri:a}:{},...null!=c?{visibility:c}:{}}}({_meta:h}),z={clientName:this.clientInfo.name,toolName:i,...null!=t?{title:t}:{},...null!=p?{annotations:{...null!=p.title?{title:p.title}:{},...null!=p.readOnlyHint?{readOnlyHint:p.readOnlyHint}:{},...null!=p.destructiveHint?{destructiveHint:p.destructiveHint}:{},...null!=p.idempotentHint?{idempotentHint:p.idempotentHint}:{},...null!=p.openWorldHint?{openWorldHint:p.openWorldHint}:{}}}:{},...(null==f?void 0:f.resourceUri)!=null?{app:{...f,mimeType:"text/html;profile=mcp-app"}}:{}},g=async(t,e)=>{var r;null==(r=null==e?void 0:e.abortSignal)||r.throwIfAborted();let o=await d.callTool({name:i,arguments:t,options:{signal:null==e?void 0:e.abortSignal}});return o.isError?o:null!=m?d.extractStructuredContent(o,m,i):o},v="automatic"===e?(0,s.dynamicTool)({description:c,title:t,metadata:z,inputSchema:(0,s.jsonSchema)({...u,properties:null!=(o=u.properties)?o:{},additionalProperties:!1}),execute:g,toModelOutput:eu}):(0,s.tool)({description:c,title:t,metadata:z,inputSchema:e[i].inputSchema,...null!=m?{outputSchema:m}:{},execute:g,toModelOutput:eu});n[i]={...v,_meta:h}}return n}async extractStructuredContent(t,e,r){if("structuredContent"in t&&null!=t.structuredContent){let o=await (0,s.safeValidateTypes)({value:t.structuredContent,schema:(0,s.asSchema)(e)});if(!o.success)throw new tm({message:`Tool "${r}" returned structuredContent that does not match the expected outputSchema`,cause:o.error});return o.value}if("content"in t&&Array.isArray(t.content)){let o=t.content.find(t=>"text"===t.type);if(o&&"text"in o){let t=await (0,s.safeParseJSON)({text:o.text,schema:e});if(!t.success)throw new tm({message:`Tool "${r}" returned content that does not match the expected outputSchema`,cause:t.error});return t.value}}throw new tm({message:`Tool "${r}" did not return structuredContent or parseable text content`})}listResources({params:t,options:e}={}){return this.listResourcesInternal({params:t,options:e})}readResource({uri:t,options:e}){return this.readResourceInternal({uri:t,options:e})}listResourceTemplates({options:t}={}){return this.listResourceTemplatesInternal({options:t})}experimental_listPrompts({params:t,options:e}={}){return this.listPromptsInternal({params:t,options:e})}experimental_getPrompt({name:t,arguments:e,options:r}){return this.getPromptInternal({name:t,args:e,options:r})}complete(t){return this.completeInternal(t)}onElicitationRequest(t,e){if(t!==to)throw new tm({message:"Unsupported request schema. Only ElicitationRequestSchema is supported."});this.elicitationRequestHandler=e}async onRequestMessage(t){try{if("ping"===t.method)return void await this.transport.send({jsonrpc:"2.0",id:t.id,result:{}});if("elicitation/create"!==t.method)return void await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32601,message:`Unsupported request method: ${t.method}`}});if(!this.elicitationRequestHandler)return void await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32601,message:"No elicitation handler registered on client"}});let e=to.safeParse({method:t.method,params:t.params});if(!e.success)return void await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32602,message:`Invalid elicitation request: ${e.error.message}`,data:e.error.issues}});try{let r=await this.elicitationRequestHandler(e.data),o=tn.parse(r);await this.transport.send({jsonrpc:"2.0",id:t.id,result:o})}catch(e){await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32603,message:e instanceof Error?e.message:"Failed to handle elicitation request"}}),this.onError(e)}}catch(t){this.onError(t)}}onClose(){if(this.isClosed)return;this.isClosed=!0;let t=new tm({message:"Connection closed"});for(let e of this.responseHandlers.values())e(t);this.responseHandlers.clear()}onError(t){this.onUncaughtError&&this.onUncaughtError(t)}onResponse(t){if(null==t.id)return void this.onError(new tm({message:`Protocol error: Received a response without a message ID: ${JSON.stringify(t)}`}));let e=Number(t.id),r=this.responseHandlers.get(e);if(void 0===r)throw new tm({message:`Protocol error: Received a response for an unknown message ID: ${JSON.stringify(t)}`});this.responseHandlers.delete(e),r("result"in t?t:new tm({message:t.error.message,code:t.error.code,data:t.error.data,cause:t.error}))}};new TextEncoder,t.s(["UnauthorizedError",0,tU,"auth",0,t3,"createMCPClient",0,ep],361164)},202058,(t,e,r)=>{e.exports=n,n.sync=function(t,e){return i(o.statSync(t),e)};var o=t.r(522734);function n(t,e,r){o.stat(t,function(t,o){r(t,!t&&i(o,e))})}function i(t,e){var r,o,n,i,s,a,l,c,u;return t.isFile()&&(r=t,o=e,n=r.mode,i=r.uid,s=r.gid,a=void 0!==o.uid?o.uid:process.getuid&&process.getuid(),l=void 0!==o.gid?o.gid:process.getgid&&process.getgid(),c=parseInt("100",8),u=parseInt("010",8),n&parseInt("001",8)||n&u&&s===l||n&c&&i===a||n&(c|u)&&0===a)}},129507,(t,e,r)=>{e.exports=i,i.sync=function(t,e){return n(o.statSync(t),t,e)};var o=t.r(522734);function n(t,e,r){if(!t.isSymbolicLink()&&!t.isFile())return!1;var o=void 0!==r.pathExt?r.pathExt:process.env.PATHEXT;if(!o||-1!==(o=o.split(";")).indexOf(""))return!0;for(var n=0;n<o.length;n++){var i=o[n].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(t,e,r){o.stat(t,function(o,i){r(o,!o&&n(i,t,e))})}},24214,(t,e,r)=>{var o;function n(t,e,r){if("function"==typeof e&&(r=e,e={}),!r){if("function"!=typeof Promise)throw TypeError("callback not provided");return new Promise(function(r,o){n(t,e||{},function(t,e){t?o(t):r(e)})})}o(t,e||{},function(t,o){t&&("EACCES"===t.code||e&&e.ignoreErrors)&&(t=null,o=!1),r(t,o)})}t.r(522734),o="win32"===process.platform||t.g.TESTING_WINDOWS?t.r(129507):t.r(202058),e.exports=n,n.sync=function(t,e){try{return o.sync(t,e||{})}catch(t){if(e&&e.ignoreErrors||"EACCES"===t.code)return!1;throw t}}},319932,(t,e,r)=>{let o="win32"===process.platform||"cygwin"===process.env.OSTYPE||"msys"===process.env.OSTYPE,n=t.r(814747),i=o?";":":",s=t.r(24214),a=t=>Object.assign(Error(`not found: ${t}`),{code:"ENOENT"}),l=(t,e)=>{let r=e.colon||i,n=t.match(/\//)||o&&t.match(/\\/)?[""]:[...o?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(r)],s=o?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",a=o?s.split(r):[""];return o&&-1!==t.indexOf(".")&&""!==a[0]&&a.unshift(""),{pathEnv:n,pathExt:a,pathExtExe:s}},c=(t,e,r)=>{"function"==typeof e&&(r=e,e={}),e||(e={});let{pathEnv:o,pathExt:i,pathExtExe:c}=l(t,e),u=[],p=r=>new Promise((i,s)=>{if(r===o.length)return e.all&&u.length?i(u):s(a(t));let l=o[r],c=/^".*"$/.test(l)?l.slice(1,-1):l,p=n.join(c,t);i(h(!c&&/^\.[\\\/]/.test(t)?t.slice(0,2)+p:p,r,0))}),h=(t,r,o)=>new Promise((n,a)=>{if(o===i.length)return n(p(r+1));let l=i[o];s(t+l,{pathExt:c},(i,s)=>{if(!i&&s)if(!e.all)return n(t+l);else u.push(t+l);return n(h(t,r,o+1))})});return r?p(0).then(t=>r(null,t),r):p(0)};e.exports=c,c.sync=(t,e)=>{let{pathEnv:r,pathExt:o,pathExtExe:i}=l(t,e=e||{}),c=[];for(let a=0;a<r.length;a++){let l=r[a],u=/^".*"$/.test(l)?l.slice(1,-1):l,p=n.join(u,t),h=!u&&/^\.[\\\/]/.test(t)?t.slice(0,2)+p:p;for(let t=0;t<o.length;t++){let r=h+o[t];try{if(s.sync(r,{pathExt:i}))if(!e.all)return r;else c.push(r)}catch(t){}}}if(e.all&&c.length)return c;if(e.nothrow)return null;throw a(t)}},625881,(t,e,r)=>{"use strict";let o=(t={})=>{let e=t.env||process.env;return"win32"!==(t.platform||process.platform)?"PATH":Object.keys(e).reverse().find(t=>"PATH"===t.toUpperCase())||"Path"};e.exports=o,e.exports.default=o},81463,(t,e,r)=>{"use strict";let o=t.r(814747),n=t.r(319932),i=t.r(625881);function s(t,e){let r,s=t.options.env||process.env,a=process.cwd(),l=null!=t.options.cwd,c=l&&void 0!==process.chdir&&!process.chdir.disabled;if(c)try{process.chdir(t.options.cwd)}catch(t){}try{r=n.sync(t.command,{path:s[i({env:s})],pathExt:e?o.delimiter:void 0})}catch(t){}finally{c&&process.chdir(a)}return r&&(r=o.resolve(l?t.options.cwd:"",r)),r}e.exports=function(t){return s(t)||s(t,!0)}},502977,(t,e,r)=>{"use strict";let o=/([()\][%!^"`<>&|;, *?])/g;e.exports.command=function(t){return t.replace(o,"^$1")},e.exports.argument=function(t,e){return t=(t=(t=`${t}`).replace(/(?=(\\+?)?)\1"/g,'$1$1\\"')).replace(/(?=(\\+?)?)\1$/,"$1$1"),t=(t=`"${t}"`).replace(o,"^$1"),e&&(t=t.replace(o,"^$1")),t}},831804,(t,e,r)=>{"use strict";e.exports=/^#!(.*)/},469231,(t,e,r)=>{"use strict";let o=t.r(831804);e.exports=(t="")=>{let e=t.match(o);if(!e)return null;let[r,n]=e[0].replace(/#! ?/,"").split(" "),i=r.split("/").pop();return"env"===i?n:n?`${i} ${n}`:i}},385328,(t,e,r)=>{"use strict";let o=t.r(522734),n=t.r(469231);e.exports=function(t){let e,r=Buffer.alloc(150);try{e=o.openSync(t,"r"),o.readSync(e,r,0,150,0),o.closeSync(e)}catch(t){}return n(r.toString())}},207546,(t,e,r)=>{"use strict";t.r(814747),t.r(81463),t.r(502977),t.r(385328),process.platform,e.exports=function(t,e,r){e&&!Array.isArray(e)&&(r=e,e=null);let o={command:t,args:e=e?e.slice(0):[],options:r=Object.assign({},r),file:void 0,original:{command:t,args:e}};return r.shell,o}},245750,(t,e,r)=>{"use strict";process.platform,e.exports={hookChildProcess:function(t,e){},verifyENOENT:function(t,e){return null},verifyENOENTSync:function(t,e){return null},notFoundError:function(t,e){return Object.assign(Error(`${e} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${e} ${t.command}`,path:t.command,spawnargs:t.args})}}},465887,(t,e,r)=>{"use strict";let o=t.r(233405),n=t.r(207546),i=t.r(245750);function s(t,e,r){let s=n(t,e,r),a=o.spawn(s.command,s.args,s.options);return i.hookChildProcess(a,s),a}e.exports=s,e.exports.spawn=s,e.exports.sync=function(t,e,r){let s=n(t,e,r),a=o.spawnSync(s.command,s.args,s.options);return a.error=a.error||i.verifyENOENTSync(a.status,s),a},e.exports._parse=n,e.exports._enoent=i},958560,t=>{"use strict";var e,r,o=t.i(847841),n=t.i(469719),i=t.i(376261),s=t.i(465887),a=n.z.optional(n.z.record(n.z.string(),n.z.unknown())),l=n.z.looseObject({name:n.z.string(),version:n.z.string(),title:n.z.optional(n.z.string())}),c=n.z.looseObject({_meta:n.z.optional(n.z.object({}).loose())}),u=c.extend({resultType:n.z.optional(n.z.string())}),p=n.z.object({method:n.z.string(),params:n.z.optional(c)}),h=n.z.object({applyDefaults:n.z.optional(n.z.boolean())}).loose(),d=n.z.looseObject({experimental:n.z.optional(n.z.object({}).loose()),logging:n.z.optional(n.z.object({}).loose()),completions:n.z.optional(n.z.object({}).loose()),prompts:n.z.optional(n.z.looseObject({listChanged:n.z.optional(n.z.boolean())})),resources:n.z.optional(n.z.looseObject({subscribe:n.z.optional(n.z.boolean()),listChanged:n.z.optional(n.z.boolean())})),tools:n.z.optional(n.z.looseObject({listChanged:n.z.optional(n.z.boolean())})),elicitation:n.z.optional(h)});n.z.object({elicitation:n.z.optional(h)}).loose(),u.extend({supportedVersions:n.z.array(n.z.string()),capabilities:d,instructions:n.z.optional(n.z.string()),ttlMs:n.z.optional(n.z.number()),cacheScope:n.z.optional(n.z.union([n.z.literal("public"),n.z.literal("private")]))}),u.extend({protocolVersion:n.z.string(),capabilities:d,serverInfo:l,instructions:n.z.optional(n.z.string())});var m=u.extend({nextCursor:n.z.optional(n.z.string())}),f=n.z.object({name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),inputSchema:n.z.looseObject({type:n.z.optional(n.z.unknown()),properties:n.z.optional(n.z.object({}).loose())}),outputSchema:n.z.optional(n.z.object({}).loose()),annotations:n.z.optional(n.z.object({title:n.z.optional(n.z.string()),readOnlyHint:n.z.optional(n.z.boolean()),destructiveHint:n.z.optional(n.z.boolean()),idempotentHint:n.z.optional(n.z.boolean()),openWorldHint:n.z.optional(n.z.boolean())}).loose()),_meta:a}).loose();m.extend({tools:n.z.array(f)});var z=n.z.object({type:n.z.literal("text"),text:n.z.string()}).loose(),g=n.z.object({type:n.z.literal("image"),data:n.z.base64(),mimeType:n.z.string()}).loose(),v=n.z.object({uri:n.z.string(),name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string()),size:n.z.optional(n.z.number())}).loose();m.extend({resources:n.z.array(v)});var w=n.z.object({uri:n.z.string(),name:n.z.optional(n.z.string()),title:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).loose(),y=w.extend({text:n.z.string()}),b=w.extend({blob:n.z.base64()}),_=n.z.object({type:n.z.literal("resource"),resource:n.z.union([y,b])}).loose(),E=n.z.object({type:n.z.literal("resource_link"),uri:n.z.string(),name:n.z.string(),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).loose(),S=n.z.object({type:n.z.string()}).loose().refine(t=>!["text","image","resource","resource_link"].includes(t.type),{message:"Known content types must match their schema"}),C=u.extend({content:n.z.array(n.z.union([z,g,_,E,S])),structuredContent:n.z.optional(n.z.unknown()),isError:n.z.boolean().default(!1).optional()}),T=u.extend({content:n.z.never().optional(),structuredContent:n.z.json(),isError:n.z.boolean().default(!1).optional()}).transform(t=>({...t,content:[{type:"text",text:JSON.stringify(t.structuredContent)}]})).pipe(C);C.or(T).or(u.extend({toolResult:n.z.unknown().nonoptional()}));var x=n.z.object({uriTemplate:n.z.string(),name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).loose();u.extend({resourceTemplates:n.z.array(x)}),u.extend({contents:n.z.array(n.z.union([y,b]))});var P=n.z.object({type:n.z.literal("ref/prompt"),name:n.z.string()}).loose(),R=n.z.object({type:n.z.literal("ref/resource"),uri:n.z.string()}).loose(),I=n.z.object({name:n.z.string(),value:n.z.string()}).loose();c.extend({ref:n.z.union([P,R]),argument:I,context:n.z.optional(n.z.object({arguments:n.z.record(n.z.string(),n.z.string())}).loose())}),u.extend({completion:n.z.object({values:n.z.array(n.z.string()).max(100),total:n.z.optional(n.z.number().int()),hasMore:n.z.optional(n.z.boolean())}).loose()});var A=n.z.object({name:n.z.string(),description:n.z.optional(n.z.string()),required:n.z.optional(n.z.boolean())}).loose(),j=n.z.object({name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),arguments:n.z.optional(n.z.array(A))}).loose();m.extend({prompts:n.z.array(j)});var k=n.z.object({role:n.z.union([n.z.literal("user"),n.z.literal("assistant")]),content:n.z.union([z,g,_,E])}).loose();u.extend({description:n.z.optional(n.z.string()),messages:n.z.array(k)});var U=c.extend({message:n.z.string(),requestedSchema:n.z.unknown()});p.extend({method:n.z.literal("elicitation/create"),params:U}),u.extend({action:n.z.union([n.z.literal("accept"),n.z.literal("decline"),n.z.literal("cancel")]),content:n.z.optional(n.z.record(n.z.string(),n.z.unknown()))});var O=n.z.object({jsonrpc:n.z.literal("2.0"),id:n.z.union([n.z.string(),n.z.number().int()])}).merge(p).strict(),M=n.z.object({jsonrpc:n.z.literal("2.0"),id:n.z.union([n.z.string(),n.z.number().int()]),result:u}).strict(),$=n.z.object({jsonrpc:n.z.literal("2.0"),id:n.z.optional(n.z.union([n.z.string(),n.z.number().int()])),error:n.z.object({code:n.z.number().int(),message:n.z.string(),data:n.z.optional(n.z.unknown())})}).strict(),H=n.z.object({jsonrpc:n.z.literal("2.0")}).merge(n.z.object({method:n.z.string(),params:n.z.optional(c)})).strict(),N=n.z.union([O,H,M,$]);async function V(t){var e;return e=await (0,o.parseJSON)({text:t}),N.parse(e)}var L="vercel.ai.error.AI_MCPClientError",q=Symbol.for(L),D=class extends(r=i.AISDKError,e=q,r){constructor({name:t="MCPClientError",message:r,cause:o,data:n,code:i,statusCode:s,url:a,responseBody:l}){super({name:t,message:r,cause:o}),this[e]=!0,this.data=n,this.code=i,this.statusCode=s,this.url=a,this.responseBody=l}static isInstance(t){return i.AISDKError.hasMarker(t,L)}},F=class{constructor(t){this.supportsProtocolVersionDiscovery=!0,this.abortController=new AbortController,this.readBuffer=new B,this.serverParams=t}async start(){if(this.process)throw new D({message:"StdioMCPTransport already started."});return new Promise((t,e)=>{var r,o,n,i;try{let i=function(t,e){var r,o,n;if("win32"===globalThis.process.platform&&[t.command,...null!=(r=t.args)?r:[]].some(t=>/[\r\n]/.test(t)))throw TypeError("Stdio MCP commands and arguments must not contain line breaks on Windows.");return(0,s.default)(t.command,null!=(o=t.args)?o:[],{env:function(t){let e="win32"===globalThis.process.platform?["APPDATA","HOMEDRIVE","HOMEPATH","LOCALAPPDATA","PATH","PROCESSOR_ARCHITECTURE","SYSTEMDRIVE","SYSTEMROOT","TEMP","USERNAME","USERPROFILE"]:["HOME","LOGNAME","PATH","SHELL","TERM","USER"],r=t?{...t}:{};for(let t of e){let e=globalThis.process.env[t];void 0!==e&&(e.startsWith("()")||(r[t]=e))}return r}(t.env),stdio:["pipe","pipe",null!=(n=t.stderr)?n:"inherit"],shell:!1,signal:e,windowsHide:"win32"===globalThis.process.platform&&"type"in globalThis.process,cwd:t.cwd})}(this.serverParams,this.abortController.signal);this.process=i,this.process.on("error",t=>{var r,o;if("AbortError"===t.name){null==(r=this.onclose)||r.call(this);return}e(t),null==(o=this.onerror)||o.call(this,t)}),this.process.on("spawn",()=>{t()}),this.process.on("close",t=>{var e;this.process=void 0,null==(e=this.onclose)||e.call(this)}),null==(r=this.process.stdin)||r.on("error",t=>{var e;null==(e=this.onerror)||e.call(this,t)}),null==(o=this.process.stdout)||o.on("data",t=>{this.readBuffer.append(t),this.processReadBuffer()}),null==(n=this.process.stdout)||n.on("error",t=>{var e;null==(e=this.onerror)||e.call(this,t)})}catch(t){e(t),null==(i=this.onerror)||i.call(this,t)}})}async processReadBuffer(){for(var t,e;;){let r=this.readBuffer.readLine();if(null===r)break;try{let e=await W(r);null==(t=this.onmessage)||t.call(this,e)}catch(t){null==(e=this.onerror)||e.call(this,t)}}}async close(){this.abortController.abort(),this.process=void 0,this.readBuffer.clear()}send(t){return new Promise(e=>{var r;if(!(null==(r=this.process)?void 0:r.stdin))throw new D({message:"StdioClientTransport not connected"});let o=JSON.stringify(t)+"\n";this.process.stdin.write(o)?e():this.process.stdin.once("drain",e)})}},B=class{append(t){this.buffer=this.buffer?Buffer.concat([this.buffer,t]):t}readLine(){if(!this.buffer)return null;let t=this.buffer.indexOf("\n");if(-1===t)return null;let e=this.buffer.toString("utf8",0,t);return this.buffer=this.buffer.subarray(t+1),e}clear(){this.buffer=void 0}};async function W(t){return V(t)}t.s(["Experimental_StdioMCPTransport",0,F])}];
1
+ module.exports=[105303,t=>t.a(async(e,r)=>{try{var o,n=t.i(361164),i=t.i(958560),s=t.i(687388),a=t.i(640911),l=t.i(41444),c=t.i(148831),u=t.i(441963),p=e([c]);[c]=p.then?(await p)():p;class h extends Error{serverName;authorizationUrl;constructor(t,e){super(`MCP server "${t}" requires authorization`),this.serverName=t,this.authorizationUrl=e,this.name="McpAuthRequiredError"}}class d{store;serverName;oauth;callbackUrl;clientName;staticClient;lastAuthorizationUrl;constructor(t,e,r,o,n,i){this.store=t,this.serverName=e,this.oauth=r,this.callbackUrl=o,this.clientName=n,this.staticClient=i}get redirectUrl(){return this.callbackUrl}get clientMetadata(){return{client_name:this.clientName,redirect_uris:[this.callbackUrl],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"client_secret_post"}}async persist(t){this.oauth={...this.oauth,...t},await this.store.saveOAuth(this.serverName,this.oauth)}clientInformation(){return this.staticClient??this.oauth.clientInformation}async saveClientInformation(t){await this.persist({clientInformation:t})}tokens(){return this.oauth.tokens}async saveTokens(t){await this.persist({tokens:t})}authorizationServerInformation(){return this.oauth.authorizationServer}async saveAuthorizationServerInformation(t){await this.persist({authorizationServer:t})}codeVerifier(){if(!this.oauth.codeVerifier)throw Error("No code verifier saved");return this.oauth.codeVerifier}async saveCodeVerifier(t){await this.persist({codeVerifier:t})}state(){return crypto.randomUUID()}async saveState(t){await this.persist({state:t})}storedState(){return this.oauth.state}redirectToAuthorization(t){this.lastAuthorizationUrl=t}async invalidateCredentials(t){let e={...this.oauth};("all"===t||"client"===t)&&(e.clientInformation=void 0),("all"===t||"tokens"===t)&&(e.tokens=void 0),("all"===t||"verifier"===t)&&(e.codeVerifier=void 0),this.oauth=e,await this.store.saveOAuth(this.serverName,e)}}let m=globalThis;m.__thursdayMcpManager&&m.__thursdayMcpManager.dispose(),o={callbackUrl:new URL("/api/mcp/oauth/callback",s.APP_URL).href,clientName:s.APP_NAME},m.__thursdayMcpManager=new class t{store;sessions;connecting;idleTtlMs;callbackUrl;clientName;constructor(t,e){this.store=t,this.sessions=new Map,this.connecting=new Map,this.callbackUrl=e.callbackUrl,this.idleTtlMs=e.idleTtlMs??18e5,this.clientName=e.clientName??s.APP_NAME}async connect(t){let e=this.connecting.get(t);if(e)return e;let r=this.doConnect(t).finally(()=>this.connecting.delete(t));return this.connecting.set(t,r),r}async callTool(t,e,r,o){let i=await this.ensureClient(t);try{let n=await i.callTool({name:e,arguments:r,options:o?{signal:o}:void 0});return this.touch(t),n}catch(e){if(e instanceof n.UnauthorizedError)throw await this.closeSession(t),new h(t);throw e}}async finishAuthorization(t){let e=t.get("state"),r=t.get("code");if(!e||!r)throw Error("OAuth callback is missing code or state");let o=await this.store.findByOAuthState(e);if(!o||!(0,u.isRemoteConfig)(o.config))throw Error("No server is waiting for this authorization");let i=this.providerFor(o),s=await (0,n.auth)(i,{serverUrl:o.config.url,authorizationCode:r,callbackState:e});if("AUTHORIZED"!==s)throw Error(`Token exchange ended in "${s}"`);return await i.invalidateCredentials("verifier"),await this.connect(o.name),o.name}async disconnect(t){await this.closeSession(t)}async dispose(){await Promise.all([...this.sessions.keys()].map(t=>this.closeSession(t)))}async doConnect(t){await this.closeSession(t);let e=await this.store.load(t);if(!e)throw Error(`Unknown MCP server "${t}"`);let r={};try{let o=await this.openClient(e,r),n=(await o.listTools()).tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema}));return this.adopt(t,o),await this.store.saveConnectionResult(t,{toolInfo:n,lastError:null}),a.logger.info(`mcp "${t}" connected — ${n.length} tools`),{status:"connected",tools:n}}catch(p){var o,i;let s;if(p instanceof n.UnauthorizedError||p?.cause instanceof n.UnauthorizedError){let e=r.href;if(e)return await this.store.saveConnectionResult(t,{toolInfo:[],lastError:"Authorization required — finish sign-in in the opened tab"}),{status:"auth_required",authorizationUrl:e}}let c=(o=p,i=e,s=(0,l.errorToString)(o),/\b40[13]\b/.test(s)&&/OAuth|register/i.test(s)&&(0,u.isRemoteConfig)(i.config)&&!i.config.oauthClient?"This server does not allow automatic client registration. Register an OAuth app with the provider and add its client ID and secret.":s);throw await this.store.saveConnectionResult(t,{toolInfo:[],lastError:c}),a.logger.warn(`mcp "${t}" failed — ${c}`),Error(c,{cause:p})}}async openClient(t,e={}){if((0,u.isRemoteConfig)(t.config)){let r=this.providerFor(t);try{return await (0,n.createMCPClient)({name:this.clientName,transport:{type:"http",url:t.config.url,headers:t.config.headers,authProvider:r,redirect:"follow"}})}finally{e.href=r.lastAuthorizationUrl?.href}}return(0,n.createMCPClient)({name:this.clientName,transport:new i.Experimental_StdioMCPTransport({command:t.config.command,args:t.config.args,env:t.config.env})})}providerFor(t){let e=(0,u.isRemoteConfig)(t.config)?t.config.oauthClient:void 0;return new d(this.store,t.name,t.oauth??{},this.callbackUrl,this.clientName,e&&{client_id:e.clientId,client_secret:e.clientSecret})}async ensureClient(t){let e=this.sessions.get(t);if(e)return e.client;let r=await this.connect(t);if("auth_required"===r.status)throw new h(t,r.authorizationUrl);let o=this.sessions.get(t);if(!o)throw Error(`Session for "${t}" vanished mid-connect`);return o.client}adopt(t,e){this.sessions.set(t,{client:e,idleTimer:this.armIdleTimer(t)})}touch(t){let e=this.sessions.get(t);e&&(clearTimeout(e.idleTimer),e.idleTimer=this.armIdleTimer(t))}armIdleTimer(t){let e=setTimeout(()=>{this.closeSession(t)},this.idleTtlMs);return e.unref?.(),e}async closeSession(t){let e=this.sessions.get(t);e&&(this.sessions.delete(t),clearTimeout(e.idleTimer),await e.client.close().catch(()=>{}))}}({load:t=>(0,c.findServer)(t),saveOAuth:(t,e)=>(0,c.saveOAuthData)(t,e),saveConnectionResult:(t,e)=>null===e.lastError?(0,c.syncServerTools)(t,e.toolInfo):(0,c.saveConnectionError)(t,e.lastError),findByOAuthState:t=>(0,c.findServerByOAuthState)(t)},o);let f=m.__thursdayMcpManager;t.s(["McpAuthRequiredError",0,h,"mcpManager",0,f]),r()}catch(t){r(t)}},!1),361164,t=>{"use strict";let e;var r,o,n,i,s=t.i(847841),a=t.i(469719),l=t.i(376261),c=t.i(36040);async function u(t){return(await e).getRandomValues(new Uint8Array(t))}async function p(t){let e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~",r=256-256%e.length,o="";for(;o.length<t;)for(let n of(await u(t-o.length)))n<r&&(o+=e[n%e.length]);return o}async function h(t){return await p(t)}async function d(t){return btoa(String.fromCharCode(...new Uint8Array(await (await e).subtle.digest("SHA-256",new TextEncoder().encode(t))))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}async function m(t){if(t||(t=43),t<43||t>128)throw`Expected a length between 43 and 128. Received ${t}.`;let e=await h(t),r=await d(e);return{code_verifier:e,code_challenge:r}}e=globalThis.crypto?.webcrypto??globalThis.crypto??t.A(70729).then(t=>t.webcrypto);var f=t.i(907855),z="2026-07-28",g="2025-11-25",v=[z,g,"2025-06-18","2025-03-26","2024-11-05"],w=a.z.optional(a.z.record(a.z.string(),a.z.unknown())),y=a.z.looseObject({name:a.z.string(),version:a.z.string(),title:a.z.optional(a.z.string())}),b=a.z.looseObject({_meta:a.z.optional(a.z.object({}).loose())}),_=b.extend({resultType:a.z.optional(a.z.string())}),E=a.z.object({method:a.z.string(),params:a.z.optional(b)}),S=a.z.object({applyDefaults:a.z.optional(a.z.boolean())}).loose(),C=a.z.looseObject({experimental:a.z.optional(a.z.object({}).loose()),logging:a.z.optional(a.z.object({}).loose()),completions:a.z.optional(a.z.object({}).loose()),prompts:a.z.optional(a.z.looseObject({listChanged:a.z.optional(a.z.boolean())})),resources:a.z.optional(a.z.looseObject({subscribe:a.z.optional(a.z.boolean()),listChanged:a.z.optional(a.z.boolean())})),tools:a.z.optional(a.z.looseObject({listChanged:a.z.optional(a.z.boolean())})),elicitation:a.z.optional(S)});a.z.object({elicitation:a.z.optional(S)}).loose();var T=_.extend({supportedVersions:a.z.array(a.z.string()),capabilities:C,instructions:a.z.optional(a.z.string()),ttlMs:a.z.optional(a.z.number()),cacheScope:a.z.optional(a.z.union([a.z.literal("public"),a.z.literal("private")]))}),x=_.extend({protocolVersion:a.z.string(),capabilities:C,serverInfo:y,instructions:a.z.optional(a.z.string())}),P=_.extend({nextCursor:a.z.optional(a.z.string())}),R=a.z.object({name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),inputSchema:a.z.looseObject({type:a.z.optional(a.z.unknown()),properties:a.z.optional(a.z.object({}).loose())}),outputSchema:a.z.optional(a.z.object({}).loose()),annotations:a.z.optional(a.z.object({title:a.z.optional(a.z.string()),readOnlyHint:a.z.optional(a.z.boolean()),destructiveHint:a.z.optional(a.z.boolean()),idempotentHint:a.z.optional(a.z.boolean()),openWorldHint:a.z.optional(a.z.boolean())}).loose()),_meta:w}).loose(),I=P.extend({tools:a.z.array(R)}),A=a.z.object({type:a.z.literal("text"),text:a.z.string()}).loose(),j=a.z.object({type:a.z.literal("image"),data:a.z.base64(),mimeType:a.z.string()}).loose(),k=a.z.object({uri:a.z.string(),name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string()),size:a.z.optional(a.z.number())}).loose(),U=P.extend({resources:a.z.array(k)}),O=a.z.object({uri:a.z.string(),name:a.z.optional(a.z.string()),title:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string())}).loose(),M=O.extend({text:a.z.string()}),$=O.extend({blob:a.z.base64()}),H=a.z.object({type:a.z.literal("resource"),resource:a.z.union([M,$])}).loose(),N=a.z.object({type:a.z.literal("resource_link"),uri:a.z.string(),name:a.z.string(),description:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string())}).loose(),V=a.z.object({type:a.z.string()}).loose().refine(t=>!["text","image","resource","resource_link"].includes(t.type),{message:"Known content types must match their schema"}),L=_.extend({content:a.z.array(a.z.union([A,j,H,N,V])),structuredContent:a.z.optional(a.z.unknown()),isError:a.z.boolean().default(!1).optional()}),q=_.extend({content:a.z.never().optional(),structuredContent:a.z.json(),isError:a.z.boolean().default(!1).optional()}).transform(t=>({...t,content:[{type:"text",text:JSON.stringify(t.structuredContent)}]})).pipe(L),D=L.or(q).or(_.extend({toolResult:a.z.unknown().nonoptional()})),F=a.z.object({uriTemplate:a.z.string(),name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),mimeType:a.z.optional(a.z.string())}).loose(),B=_.extend({resourceTemplates:a.z.array(F)}),W=_.extend({contents:a.z.array(a.z.union([M,$]))}),J=a.z.object({type:a.z.literal("ref/prompt"),name:a.z.string()}).loose(),K=a.z.object({type:a.z.literal("ref/resource"),uri:a.z.string()}).loose(),Z=a.z.object({name:a.z.string(),value:a.z.string()}).loose();b.extend({ref:a.z.union([J,K]),argument:Z,context:a.z.optional(a.z.object({arguments:a.z.record(a.z.string(),a.z.string())}).loose())});var G=_.extend({completion:a.z.object({values:a.z.array(a.z.string()).max(100),total:a.z.optional(a.z.number().int()),hasMore:a.z.optional(a.z.boolean())}).loose()}),Y=a.z.object({name:a.z.string(),description:a.z.optional(a.z.string()),required:a.z.optional(a.z.boolean())}).loose(),X=a.z.object({name:a.z.string(),title:a.z.optional(a.z.string()),description:a.z.optional(a.z.string()),arguments:a.z.optional(a.z.array(Y))}).loose(),Q=P.extend({prompts:a.z.array(X)}),tt=a.z.object({role:a.z.union([a.z.literal("user"),a.z.literal("assistant")]),content:a.z.union([A,j,H,N])}).loose(),te=_.extend({description:a.z.optional(a.z.string()),messages:a.z.array(tt)}),tr=b.extend({message:a.z.string(),requestedSchema:a.z.unknown()}),to=E.extend({method:a.z.literal("elicitation/create"),params:tr}),tn=_.extend({action:a.z.union([a.z.literal("accept"),a.z.literal("decline"),a.z.literal("cancel")]),content:a.z.optional(a.z.record(a.z.string(),a.z.unknown()))}),ti=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.union([a.z.string(),a.z.number().int()])}).merge(E).strict(),ts=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.union([a.z.string(),a.z.number().int()]),result:_}).strict(),ta=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.optional(a.z.union([a.z.string(),a.z.number().int()])),error:a.z.object({code:a.z.number().int(),message:a.z.string(),data:a.z.optional(a.z.unknown())})}).strict(),tl=a.z.object({jsonrpc:a.z.literal("2.0")}).merge(a.z.object({method:a.z.string(),params:a.z.optional(b)})).strict(),tc=a.z.union([ti,tl,ts,ta]);function tu(t){return tc.parse(t)}async function tp(t){return tu(await (0,s.parseJSON)({text:t}))}var th="vercel.ai.error.AI_MCPClientError",td=Symbol.for(th),tm=class extends(o=l.AISDKError,r=td,o){constructor({name:t="MCPClientError",message:e,cause:o,data:n,code:i,statusCode:s,url:a,responseBody:l}){super({name:t,message:e,cause:o}),this[r]=!0,this.data=n,this.code=i,this.statusCode=s,this.url=a,this.responseBody=l}static isInstance(t){return l.AISDKError.hasMarker(t,th)}},tf="u">typeof __PACKAGE_VERSION__?__PACKAGE_VERSION__:"0.0.0-test",tz=a.z.string().url().superRefine((t,e)=>{if(!URL.canParse(t))return e.addIssue({code:a.z.ZodIssueCode.custom,message:"URL must be parseable",fatal:!0}),a.z.NEVER}).refine(t=>{let e=new URL(t);return"javascript:"!==e.protocol&&"data:"!==e.protocol&&"vbscript:"!==e.protocol},{message:"URL cannot use javascript:, data:, or vbscript: scheme"}),tg=a.z.object({access_token:a.z.string(),id_token:a.z.string().optional(),token_type:a.z.string(),expires_in:a.z.number().optional(),scope:a.z.string().optional(),refresh_token:a.z.string().optional(),issuer:tz.optional(),authorization_server:tz.optional(),token_endpoint:tz.optional()}).strip(),tv=a.z.looseObject({resource:a.z.string().url(),authorization_servers:a.z.array(tz).optional(),jwks_uri:a.z.string().url().optional(),scopes_supported:a.z.array(a.z.string()).optional(),bearer_methods_supported:a.z.array(a.z.string()).optional(),resource_signing_alg_values_supported:a.z.array(a.z.string()).optional(),resource_name:a.z.string().optional(),resource_documentation:a.z.string().optional(),resource_policy_uri:a.z.string().url().optional(),resource_tos_uri:a.z.string().url().optional(),tls_client_certificate_bound_access_tokens:a.z.boolean().optional(),authorization_details_types_supported:a.z.array(a.z.string()).optional(),dpop_signing_alg_values_supported:a.z.array(a.z.string()).optional(),dpop_bound_access_tokens_required:a.z.boolean().optional()}),tw=a.z.looseObject({issuer:a.z.string(),authorization_endpoint:tz,token_endpoint:tz,registration_endpoint:tz.optional(),authorization_response_iss_parameter_supported:a.z.boolean().optional(),client_id_metadata_document_supported:a.z.boolean().optional(),scopes_supported:a.z.array(a.z.string()).optional(),response_types_supported:a.z.array(a.z.string()),grant_types_supported:a.z.array(a.z.string()).optional(),code_challenge_methods_supported:a.z.array(a.z.string()).optional(),token_endpoint_auth_methods_supported:a.z.array(a.z.string()).optional(),token_endpoint_auth_signing_alg_values_supported:a.z.array(a.z.string()).optional()}),ty=a.z.looseObject({issuer:a.z.string(),authorization_endpoint:tz,token_endpoint:tz,userinfo_endpoint:tz.optional(),jwks_uri:tz,registration_endpoint:tz.optional(),authorization_response_iss_parameter_supported:a.z.boolean().optional(),client_id_metadata_document_supported:a.z.boolean().optional(),scopes_supported:a.z.array(a.z.string()).optional(),response_types_supported:a.z.array(a.z.string()),grant_types_supported:a.z.array(a.z.string()).optional(),subject_types_supported:a.z.array(a.z.string()),id_token_signing_alg_values_supported:a.z.array(a.z.string()),claims_supported:a.z.array(a.z.string()).optional(),token_endpoint_auth_methods_supported:a.z.array(a.z.string()).optional()}).merge(tw.pick({code_challenge_methods_supported:!0})),tb=a.z.object({client_id:a.z.string(),client_secret:a.z.string().optional(),client_id_issued_at:a.z.number().optional(),client_secret_expires_at:a.z.number().optional(),issuer:tz.optional(),authorization_server:tz.optional(),token_endpoint:tz.optional()}).strip(),t_=a.z.object({redirect_uris:a.z.array(tz),application_type:a.z.union([a.z.literal("native"),a.z.literal("web")]).optional(),token_endpoint_auth_method:a.z.string().optional(),grant_types:a.z.array(a.z.string()).optional(),response_types:a.z.array(a.z.string()).optional(),client_name:a.z.string().optional(),client_uri:tz.optional(),logo_uri:tz.optional(),scope:a.z.string().optional(),contacts:a.z.array(a.z.string()).optional(),tos_uri:tz.optional(),policy_uri:a.z.string().optional(),jwks_uri:tz.optional(),jwks:a.z.any().optional(),software_id:a.z.string().optional(),software_version:a.z.string().optional(),software_statement:a.z.string().optional()}).strip(),tE=a.z.object({error:a.z.string(),error_description:a.z.string().optional(),error_uri:a.z.string().optional()}),tS=t_.merge(tb),tC="vercel.ai.error.AI_MCPClientOAuthError",tT=Symbol.for(tC),tx=class extends(i=l.AISDKError,n=tT,i){constructor({name:t="MCPClientOAuthError",message:e,cause:r}){super({name:t,message:e,cause:r}),this[n]=!0}static isInstance(t){return l.AISDKError.hasMarker(t,tC)}},tP=class extends tx{};tP.errorCode="server_error";var tR=class extends tx{};tR.errorCode="invalid_client";var tI=class extends tx{};tI.errorCode="invalid_grant";var tA=class extends tx{};tA.errorCode="unauthorized_client";var tj={[tP.errorCode]:tP,[tR.errorCode]:tR,[tI.errorCode]:tI,[tA.errorCode]:tA};function tk(t){let e=t.href;return"/"===t.pathname&&e.endsWith("/")?e.slice(0,-1):e}var tU=class extends Error{constructor(t="Unauthorized"){super(t),this.name="UnauthorizedError"}};function tO(t){return new URL(t).href}function tM(t){let e=t.toLowerCase().replace(/\.+$/,"");return"localhost"===e||e.endsWith(".localhost")||"127.0.0.1"===e||"[::1]"===e||"::1"===e}function t$(t){if(!(("http:"===t.protocol||"https:"===t.protocol)&&tM(t.hostname)))try{(0,s.validateDownloadUrl)(t.href)}catch(e){throw new tx({message:`OAuth endpoint URL is not allowed: ${t.href}`,cause:e})}}function tH(t,e){return{...t,issuer:e.issuer,authorization_server:e.authorizationServerUrl,token_endpoint:e.tokenEndpoint}}function tN(t,e){return{...t,issuer:e.issuer,authorization_server:e.authorizationServerUrl,token_endpoint:e.tokenEndpoint}}function tV(t){if((null==t?void 0:t.authorization_server)&&t.token_endpoint)return{issuer:t.issuer,authorizationServerUrl:tO(t.authorization_server),tokenEndpoint:tO(t.token_endpoint)}}async function tL({provider:t,clientInformation:e,tokens:r}){var o;let n=tV(r);if(n)return n;let i=await (null==(o=t.authorizationServerInformation)?void 0:o.call(t));return i?{issuer:i.issuer,authorizationServerUrl:tO(i.authorizationServerUrl),tokenEndpoint:tO(i.tokenEndpoint)}:tV(e)}async function tq({provider:t,clientInformation:e,authorizationServerInformation:r}){return t.saveAuthorizationServerInformation?(await t.saveAuthorizationServerInformation(r),!0):!!t.saveClientInformation&&(await t.saveClientInformation(tN(e,r)),!0)}function tD({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:e}){if(null!=t.issuer&&null!=e.issuer&&t.issuer!==e.issuer||t.authorizationServerUrl!==e.authorizationServerUrl||t.tokenEndpoint!==e.tokenEndpoint)throw new tx({message:"OAuth authorization server metadata does not match the metadata that issued the stored credentials"})}function tF(t){var e,r;let o,n=null!=(e=t.headers.get("www-authenticate"))?e:t.headers.get("WWW-Authenticate");if(!n)return{};let[i,s]=n.split(" ");if("bearer"!==i.toLowerCase()||!s)return{};let a=n.match(/(?:^|[,\s])resource_metadata="([^"]*)"/i),l=null==(r=n.match(/(?:^|[,\s])scope="([^"]*)"/i))?void 0:r[1];try{o=a?new URL(a[1]):void 0}catch(t){}return{resourceMetadataUrl:o,scope:l}}async function tB(t,e,r=fetch){try{return await r(t,{headers:e})}catch(o){if(o instanceof TypeError)if(e)return tB(t,void 0,r);else return;throw o}}async function tW(t,e,r=fetch){return await tB(t,{"MCP-Protocol-Version":e},r)}async function tJ(t,e,r,o){var n,i,s,a;let l,c=new URL(t),u=null!=(n=null==o?void 0:o.protocolVersion)?n:z;(null==o?void 0:o.metadataUrl)?l=new URL(o.metadataUrl):(l=new URL(function(t,e="",r={}){return e.endsWith("/")&&(e=e.slice(0,-1)),r.prependPathname?`${e}/.well-known/${t}`:`/.well-known/${t}${e}`}(e,c.pathname),null!=(i=null==o?void 0:o.metadataServerUrl)?i:c)).search=c.search;let p=await tW(l,u,r);if(!(null==o?void 0:o.metadataUrl)&&(s=p,a=c.pathname,!s||s.status>=400&&s.status<500&&"/"!==a)){let t=new URL(`/.well-known/${e}`,c);p=await tW(t,u,r)}return p}async function tK(t,e,r=fetch){let o=await tJ(t,"oauth-protected-resource",r,{protocolVersion:null==e?void 0:e.protocolVersion,metadataUrl:null==e?void 0:e.resourceMetadataUrl});if(!o||404===o.status)throw Error("Resource server does not implement OAuth 2.0 Protected Resource Metadata.");if(!o.ok)throw Error(`HTTP ${o.status} trying to load well-known OAuth protected resource metadata.`);return tv.parse(await o.json())}function tZ(t,e){if(t.issuer!==e&&(e!==new URL(e).origin||t.issuer!==`${e}/`))throw new tx({message:`OAuth authorization server metadata issuer ${t.issuer} does not match expected issuer ${e}`})}async function tG(t,{fetchFn:e=fetch,protocolVersion:r=z}={}){var o;let n={"MCP-Protocol-Version":r};for(let{url:r,type:i,expectedIssuer:s}of function(t){let e="string"==typeof t?new URL(t):t,r="/"!==e.pathname,o=e.origin,n=[];if(!r)return n.push({url:new URL("/.well-known/oauth-authorization-server",e.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL("/.well-known/openid-configuration",e.origin),type:"oidc",expectedIssuer:o}),n;let i=e.pathname;i.endsWith("/")&&(i=i.slice(0,-1));let s=`${e.origin}${i}`;return n.push({url:new URL(`/.well-known/oauth-authorization-server${i}`,e.origin),type:"oauth",expectedIssuer:s}),n.push({url:new URL("/.well-known/oauth-authorization-server",e.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL(`/.well-known/openid-configuration${i}`,e.origin),type:"oidc",expectedIssuer:s}),n.push({url:new URL(`${i}/.well-known/openid-configuration`,e.origin),type:"oidc",expectedIssuer:s}),n}(t)){let t=await tB(r,n,e);if(t){if(!t.ok){if(t.status>=400&&t.status<500)continue;throw Error(`HTTP ${t.status} trying to load ${"oauth"===i?"OAuth":"OpenID provider"} metadata from ${r}`)}if("oauth"===i){let e=tw.parse(await t.json());return tZ(e,s),e}{let e=ty.parse(await t.json());if(tZ(e,s),!(null==(o=e.code_challenge_methods_supported)?void 0:o.includes("S256")))throw Error(`Incompatible OIDC provider at ${r}: does not support S256 code challenge method required by MCP specification`);return e}}}}async function tY(t,{metadata:e,clientInformation:r,redirectUrl:o,scope:n,state:i,resource:s}){let a,l="code",c="S256";if(e){if(a=new URL(e.authorization_endpoint),!e.response_types_supported.includes(l))throw Error(`Incompatible auth server: does not support response type ${l}`);if(!e.code_challenge_methods_supported||!e.code_challenge_methods_supported.includes(c))throw Error(`Incompatible auth server: does not support code challenge method ${c}`)}else a=new URL("/authorize",t);let u=await m(),p=u.code_verifier,h=u.code_challenge;return a.searchParams.set("response_type",l),a.searchParams.set("client_id",r.client_id),a.searchParams.set("code_challenge",h),a.searchParams.set("code_challenge_method",c),a.searchParams.set("redirect_uri",String(o)),i&&a.searchParams.set("state",i),n&&a.searchParams.set("scope",n),(null==n?void 0:n.includes("offline_access"))&&a.searchParams.append("prompt","consent"),s&&a.searchParams.set("resource",tk(s)),{authorizationUrl:a,codeVerifier:p}}function tX(t,e){let r=void 0!==t.client_secret;return 0===e.length?r?"client_secret_post":"none":r&&e.includes("client_secret_basic")?"client_secret_basic":r&&e.includes("client_secret_post")?"client_secret_post":e.includes("none")?"none":r?"client_secret_post":"none"}function tQ(t,e,r,o){let{client_id:n,client_secret:i}=e;switch(t){case"client_secret_basic":var s,a,l,c,u=n,p=i,h=r;if(!p)throw Error("client_secret_basic authentication requires a client_secret");let d=btoa(`${u}:${p}`);h.set("Authorization",`Basic ${d}`);return;case"client_secret_post":s=n,a=i,(l=o).set("client_id",s),a&&l.set("client_secret",a);return;case"none":c=n,o.set("client_id",c);return;default:throw Error(`Unsupported client authentication method: ${t}`)}}async function t0(t){let e=t instanceof Response?t.status:void 0,r=t instanceof Response?await t.text():t;try{let{error:t,error_description:e,error_uri:o}=tE.parse(await (0,s.parseJSON)({text:r}));return new(tj[t]||tP)({message:e||"",cause:o})}catch(t){return new tP({message:`${e?`HTTP ${e}: `:""}Invalid OAuth error response: ${t}. Raw body: ${r}`})}}async function t1(t,{metadata:e,clientInformation:r,authorizationCode:o,codeVerifier:n,redirectUri:i,resource:s,addClientAuthentication:a,fetchFn:l}){var c;let u="authorization_code",p=(null==e?void 0:e.token_endpoint)?new URL(e.token_endpoint):new URL("/token",t);if(t$(p),(null==e?void 0:e.grant_types_supported)&&!e.grant_types_supported.includes(u))throw Error(`Incompatible auth server: does not support grant type ${u}`);let h=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),d=new URLSearchParams({grant_type:u,code:o,code_verifier:n,redirect_uri:String(i)});a?await a(h,d,t,e):tQ(tX(r,null!=(c=null==e?void 0:e.token_endpoint_auth_methods_supported)?c:[]),r,h,d),s&&d.set("resource",tk(s));let m=await (null!=l?l:fetch)(p,{method:"POST",headers:h,body:d,redirect:"error"});if(!m.ok)throw await t0(m);return tg.parse(await m.json())}async function t2(t,{metadata:e,clientInformation:r,refreshToken:o,resource:n,addClientAuthentication:i,fetchFn:s}){var a;let l,c="refresh_token";if(e){if(l=new URL(e.token_endpoint),e.grant_types_supported&&!e.grant_types_supported.includes(c))throw Error(`Incompatible auth server: does not support grant type ${c}`)}else l=new URL("/token",t);t$(l);let u=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),p=new URLSearchParams({grant_type:c,refresh_token:o});i?await i(u,p,t,e):tQ(tX(r,null!=(a=null==e?void 0:e.token_endpoint_auth_methods_supported)?a:[]),r,u,p),n&&p.set("resource",tk(n));let h=await (null!=s?s:fetch)(l,{method:"POST",headers:u,body:p,redirect:"error"});if(!h.ok)throw await t0(h);return tg.parse({refresh_token:o,...await h.json()})}async function t4(t,{metadata:e,clientMetadata:r,fetchFn:o}){var n;let i;if(e){if(!e.registration_endpoint)throw Error("Incompatible auth server: does not support dynamic client registration");i=new URL(e.registration_endpoint)}else i=new URL("/register",t);t$(i);let s=null!=(n=r.application_type)?n:r.redirect_uris.every(t=>{let e=new URL(t);return("http:"===e.protocol||"https:"===e.protocol)&&tM(e.hostname)||"http:"!==e.protocol&&"https:"!==e.protocol})?"native":"web",a=await (null!=o?o:fetch)(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,application_type:s}),redirect:"error"});if(!a.ok)throw await t0(a);return tS.parse(await a.json())}async function t3(t,e){var r,o;try{return await t6(t,e)}catch(n){if(n instanceof tR||n instanceof tA)return await (null==(r=t.invalidateCredentials)?void 0:r.call(t,"all")),await t6(t,e);if(n instanceof tI)return await (null==(o=t.invalidateCredentials)?void 0:o.call(t,"tokens")),await t6(t,e);throw n}}async function t5(t,e,r){let o,n=((o=new URL("string"==typeof t?t:t.href)).hash="",o);if(e.validateResourceURL)return await e.validateResourceURL(n,null==r?void 0:r.resource);if(r){if(!function({requestedResource:t,configuredResource:e}){let r=new URL("string"==typeof t?t:t.href),o=new URL("string"==typeof e?e:e.href);if(r.origin!==o.origin||r.pathname.length<o.pathname.length)return!1;let n=r.pathname.endsWith("/")?r.pathname:r.pathname+"/",i=o.pathname.endsWith("/")?o.pathname:o.pathname+"/";return n.startsWith(i)}({requestedResource:n,configuredResource:r.resource}))throw Error(`Protected resource ${r.resource} does not match expected ${n} (or origin)`);return new URL(r.resource)}}async function t6(t,{serverUrl:e,authorizationCode:r,callbackState:o,callbackIssuer:n,scope:i,resourceMetadataUrl:s,fetchFn:a}){var l,c,u,p,h,d;let m,f;!function(t,e){if(!e)return;let r=new URL(t).origin;if(e.origin!==r)throw new tx({message:`OAuth protected resource metadata URL ${e.href} must have the same origin as the MCP server URL ${r}`})}(e,s);try{(m=await tK(e,{resourceMetadataUrl:s},a)).authorization_servers&&m.authorization_servers.length>0&&(f=m.authorization_servers[0])}catch(t){}f||(f=e);let z=await t5(e,t,m);await (null==(l=t.validateAuthorizationServerURL)?void 0:l.call(t,e,f));let g=await tG(f,{fetchFn:a}),v=(h=f,{issuer:null!=(d=null==g?void 0:g.issuer)?d:String(h),authorizationServerUrl:tO(h),tokenEndpoint:tO((null==g?void 0:g.token_endpoint)?new URL(g.token_endpoint):new URL("/token",h))}),w=t.clientMetadata,y=function({scope:t,resourceMetadata:e,clientMetadata:r}){var o;if(t)return t;let n=null==(o=null==e?void 0:e.scopes_supported)?void 0:o.join(" ");return n||r.scope}({scope:i,resourceMetadata:m,clientMetadata:w}),b=await Promise.resolve(t.clientInformation());if((null==b?void 0:b.issuer)!=null){let e=await tL({provider:t,clientInformation:b});e&&tD({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:v})}if(!b){if(void 0!==r)throw Error("Existing OAuth client information is required when exchanging an authorization code");if(!t.saveClientInformation)throw Error("OAuth client information must be saveable for dynamic registration");b=tN(await t4(f,{metadata:g,clientMetadata:{...w,scope:y},fetchFn:a}),v),await t.saveClientInformation(b)}if(void 0!==r){if(t.storedState){let e=await t.storedState();if(void 0!==e&&e!==o)throw Error("OAuth state parameter mismatch - possible CSRF attack")}let e=await tL({provider:t,clientInformation:b});if(!e)throw new tx({message:"Stored OAuth authorization server metadata is required when exchanging an authorization code"});!function({callbackIssuer:t,expectedIssuer:e}){if(null!=t&&t!==e)throw new tx({message:`OAuth authorization response issuer ${t} does not match expected issuer ${e}`})}({callbackIssuer:n,expectedIssuer:null!=(u=null!=(c=e.issuer)?c:null==g?void 0:g.issuer)?u:String(f)}),tD({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:v});let i=await t.codeVerifier(),s=await t1(f,{metadata:g,clientInformation:b,authorizationCode:r,codeVerifier:i,redirectUri:t.redirectUrl,resource:z,addClientAuthentication:t.addClientAuthentication,fetchFn:a});return await t.saveTokens(tH(s,v)),"AUTHORIZED"}let _=await t.tokens();if(null==_?void 0:_.refresh_token){let e=await tL({provider:t,clientInformation:b,tokens:_});e?tD({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:v}):await (null==(p=t.invalidateCredentials)?void 0:p.call(t,"tokens"));try{if(e){let e=await t2(f,{metadata:g,clientInformation:b,refreshToken:_.refresh_token,resource:z,addClientAuthentication:t.addClientAuthentication,fetchFn:a});return await t.saveTokens(tH(e,v)),"AUTHORIZED"}}catch(t){if(!(t instanceof tx)||t instanceof tP);else throw t}}let E=t.state?await t.state():void 0;E&&t.saveState&&await t.saveState(E);let{authorizationUrl:S,codeVerifier:C}=await tY(f,{metadata:g,clientInformation:b,state:E,redirectUrl:t.redirectUrl,scope:y,resource:z});if(!await tq({provider:t,clientInformation:b,authorizationServerInformation:v}))throw new tx({message:"OAuth authorization server metadata must be saveable before starting authorization"});return await t.saveCodeVerifier(C),await t.redirectToAuthorization(S),"REDIRECT"}var t8=class{constructor({url:t,headers:e,authProvider:r,redirect:o="error",fetch:n}){this.connected=!1,this.url=new URL(t),this.headers=e,this.authProvider=r,this.redirectMode=o,this.fetchFn=null!=n?n:globalThis.fetch}setProtocolVersion(t){this.protocolVersion=t}async commonHeaders(t){var e;let r={...this.headers,...t,"mcp-protocol-version":null!=(e=this.protocolVersion)?e:g};if(this.authProvider){let t=await this.authProvider.tokens();(null==t?void 0:t.access_token)&&(r.Authorization=`Bearer ${t.access_token}`)}return(0,s.withUserAgentSuffix)(r,`ai-sdk/${tf}`,(0,s.getRuntimeEnvironmentUserAgent)())}async start(){return new Promise((t,e)=>{if(this.connected)return t();this.abortController=new AbortController;let r=async(o=!1)=>{var n,i,s,a,l;try{let l=await this.commonHeaders({Accept:"text/event-stream"}),u=await this.fetchFn(this.url.href,{headers:l,signal:null==(n=this.abortController)?void 0:n.signal,redirect:this.redirectMode});if(401===u.status&&this.authProvider&&!o){let{resourceMetadataUrl:t,scope:o}=tF(u);this.resourceMetadataUrl=t;try{let t=await t3(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,scope:o,fetchFn:this.fetchFn});if("AUTHORIZED"!==t){let t=new tU;return null==(i=this.onerror)||i.call(this,t),e(t)}}catch(t){return null==(s=this.onerror)||s.call(this,t),e(t)}return r(!0)}if(!u.ok||!u.body){let t=`MCP SSE Transport Error: ${u.status} ${u.statusText}`;405===u.status&&(t+=". This server does not support SSE transport. Try using `http` transport instead");let r=new tm({message:t});return null==(a=this.onerror)||a.call(this,r),e(r)}let p=u.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader(),h=async()=>{var r,o,n,i,s;try{for(;;){let{done:e,value:s}=await p.read();if(e){if(this.connected)throw this.connected=!1,new tm({message:"MCP SSE Transport Error: Connection closed unexpectedly"});return}let{event:a,data:l}=s;if("endpoint"===a){if(this.endpoint)continue;let e=new URL(l,this.url);if(e.origin!==this.url.origin)throw this.connected=!1,this.endpoint=void 0,null==(r=this.sseConnection)||r.close(),null==(o=this.abortController)||o.abort(),new tm({message:`MCP SSE Transport Error: Endpoint origin does not match connection origin: ${e.origin}`});this.endpoint=e,this.connected=!0,t()}else if(void 0===a||"message"===a)try{let t=await tp(l);null==(n=this.onmessage)||n.call(this,t)}catch(e){let t=new tm({message:"MCP SSE Transport Error: Failed to parse message",cause:e});null==(i=this.onerror)||i.call(this,t)}}}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(s=this.onerror)||s.call(this,t),e(t)}};this.sseConnection={close:()=>p.cancel()},h()}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(l=this.onerror)||l.call(this,t),e(t)}};r()})}async close(){var t,e,r;this.connected=!1,this.endpoint=void 0,null==(t=this.sseConnection)||t.close(),null==(e=this.abortController)||e.abort(),null==(r=this.onclose)||r.call(this)}async send(t,e){var r,o;if(null==(r=null==e?void 0:e.signal)||r.throwIfAborted(),!this.endpoint||!this.connected)throw new tm({message:"MCP SSE Transport Error: Not connected"});let n=this.endpoint,i=null==(o=this.abortController)?void 0:o.signal,s=(null==e?void 0:e.signal)==null?i:null==i?e.signal:AbortSignal.any([i,e.signal]),a=async(r=!1)=>{var o,i;try{let e=await this.commonHeaders({"Content-Type":"application/json"}),o={method:"POST",headers:e,body:JSON.stringify(t),signal:s,redirect:this.redirectMode},i=await this.fetchFn(n.href,o);if(401===i.status&&this.authProvider&&!r){let{resourceMetadataUrl:t,scope:e}=tF(i);this.resourceMetadataUrl=t;let r=await t3(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,scope:e,fetchFn:this.fetchFn});if("AUTHORIZED"!==r)throw new tU;return a(!0)}if(!i.ok){let t=await i.text().catch(()=>null);throw new tm({message:`MCP SSE Transport Error: POSTing to endpoint (HTTP ${i.status}): ${t}`,statusCode:i.status,url:n.href,responseBody:null!=t?t:void 0})}}catch(t){if(null==(o=null==e?void 0:e.signal)?void 0:o.aborted)throw t;throw null==(i=this.onerror)||i.call(this,t),t}};await a()}},t7=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,t9=/^=\?base64\?.*\?=$/;function et(t){return[...t].every(t=>{let e=t.charCodeAt(0);return 9===e||e>=32&&e<=126})&&t.trim()===t&&!t9.test(t)?t:`=?base64?${(0,s.convertUint8ArrayToBase64)(new TextEncoder().encode(t))}?=`}function ee(t){return void 0===t||"message"===t}var er=class{constructor({url:t,headers:e,authProvider:r,redirect:o="error",initialSessionId:n,initialProtocolVersion:i,onSessionIdChange:s,onSessionExpired:a,terminateSessionOnClose:l=!0,fetch:c}){this.supportsProtocolVersionDiscovery=!0,this.supportsMcpToolParameterHeaders=!0,this.inboundReconnectAttempts=0,this.reconnectionOptions={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},this.url=new URL(t),this.headers=e,this.authProvider=r,this.redirectMode=o,this.sessionId=n,this.protocolVersion=null!=i?i:g,this.onSessionIdChange=s,this.onSessionExpired=a,this.terminateSessionOnClose=l,this.fetchFn=null!=c?c:globalThis.fetch}setProtocolVersion(t){var e;if(this.protocolVersion=t,this.abortController){if(this.isModernProtocol()){null==(e=this.inboundSseConnection)||e.close(),this.inboundSseConnection=void 0;return}this.inboundSseConnection||this.startInboundSse()}}isModernProtocol(){var t;return(null!=(t=this.protocolVersion)?t:z)===z}async commonHeaders({base:t,includeSessionId:e=!0}){var r;let o={...this.headers,...t,"mcp-protocol-version":null!=(r=this.protocolVersion)?r:g};if(!this.isModernProtocol()&&e&&this.sessionId&&(o["mcp-session-id"]=this.sessionId),this.authProvider){let t=await this.authProvider.tokens();(null==t?void 0:t.access_token)&&(o.Authorization=`Bearer ${t.access_token}`)}return(0,s.withUserAgentSuffix)(o,`ai-sdk/${tf}`,(0,s.getRuntimeEnvironmentUserAgent)())}setSessionId(t){var e;this.sessionId!==t&&(this.sessionId=t,null==(e=this.onSessionIdChange)||e.call(this,t))}applySessionIdFromResponse(t){if(this.isModernProtocol())return;let e=t.headers.get("mcp-session-id");e&&this.setSessionId(e)}expireSessionId(t){var e;this.sessionId===t&&this.setSessionId(void 0),null==(e=this.onSessionExpired)||e.call(this,t)}authorizeOnce(t,e){return this.authProvider?(this.authPromise||(this.authPromise=t3(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:t,scope:e,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0})),this.authPromise):Promise.resolve("REDIRECT")}async start(){if(this.abortController)throw new tm({message:"MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."});this.abortController=new AbortController,null!=this.protocolVersion&&this.protocolVersion!==z&&this.startInboundSse()}async close(t){var e,r,o,n,i;null==(e=this.inboundSseConnection)||e.close(),null==(r=this.abortController)||r.abort();try{if(!this.isModernProtocol()&&this.sessionId&&this.terminateSessionOnClose&&this.abortController){null==(o=null==t?void 0:t.signal)||o.throwIfAborted();let e=await this.commonHeaders({base:{}});null==(n=null==t?void 0:t.signal)||n.throwIfAborted(),await this.fetchFn(this.url.href,{method:"DELETE",headers:e,signal:null==t?void 0:t.signal,redirect:this.redirectMode}).catch(()=>void 0)}}catch(t){}null==(i=this.onclose)||i.call(this)}async send(t,e){var r,o;null==(r=null==e?void 0:e.signal)||r.throwIfAborted();let n=null==(o=this.abortController)?void 0:o.signal,i=(null==e?void 0:e.signal)==null?n:null==n?e.signal:AbortSignal.any([n,e.signal]),s=async(r=!1)=>{var o,n,a,l,u,p,h,d;try{let h="method"in t&&"initialize"===t.method,d=h?void 0:this.sessionId,m=await this.commonHeaders({base:{"Content-Type":"application/json",Accept:"application/json, text/event-stream",...this.isModernProtocol()?null==e?void 0:e.headers:{},...this.isModernProtocol()&&"method"in t&&"id"in t?this.getStandardRequestHeaders(t):{}},includeSessionId:!h}),f={method:"POST",headers:m,body:JSON.stringify(t),signal:i,redirect:this.redirectMode},z=await this.fetchFn(this.url.href,f);if(this.applySessionIdFromResponse(z),401===z.status&&this.authProvider&&!r){let{resourceMetadataUrl:t,scope:e}=tF(z);this.resourceMetadataUrl=t;try{let t=await this.authorizeOnce(this.resourceMetadataUrl,e);if("AUTHORIZED"!==t)throw new tU}catch(t){throw null==(o=this.onerror)||o.call(this,t),t}return s(!0)}if(202===z.status){this.isModernProtocol()||this.inboundSseConnection||this.startInboundSse();return}if(!z.ok){let e=await z.text().catch(()=>null);if("id"in t&&null!=e){let r=await tp(e).catch(()=>void 0);if(null!=r&&"error"in r){null==(n=this.onmessage)||n.call(this,null==r.id?{...r,id:t.id}:r);return}}let r=`MCP HTTP Transport Error: POSTing to endpoint (HTTP ${z.status}): ${e}`;404===z.status&&(!this.isModernProtocol()&&d?(this.expireSessionId(d),r+=". The MCP session expired. Create a new client without `initialSessionId` to start a fresh session"):this.isModernProtocol()||(r+=". This server does not support HTTP transport. Try using `sse` transport instead"));let o=new tm({message:r,statusCode:z.status,url:this.url.href,responseBody:null!=e?e:void 0});throw null==(a=this.onerror)||a.call(this,o),o}if(!("id"in t))return;let g=z.headers.get("content-type")||"";if(g.includes("application/json")){let t=await z.json();for(let e of Array.isArray(t)?t.map(t=>tu(t)):[tu(t)])null==(l=this.onmessage)||l.call(this,e);return}if(g.includes("text/event-stream")){if(!z.body){let t=new tm({message:"MCP HTTP Transport Error: text/event-stream response without body",statusCode:z.status,url:this.url.href});throw null==(u=this.onerror)||u.call(this,t),t}let t=z.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader();(async()=>{var r,o,n,i;try{for(;;){let{done:e,value:n}=await t.read();if(e)return;let{event:i,data:s}=n;if(ee(i))try{let t=await tp(s);null==(r=this.onmessage)||r.call(this,t)}catch(e){let t=new tm({message:"MCP HTTP Transport Error: Failed to parse message",cause:e});null==(o=this.onerror)||o.call(this,t)}}}catch(t){if((null==(n=null==e?void 0:e.signal)?void 0:n.aborted)||t instanceof Error&&"AbortError"===t.name)return;null==(i=this.onerror)||i.call(this,t)}})().catch(t=>{var r,o;null!=(r=null==e?void 0:e.signal)&&r.aborted||t instanceof Error&&"AbortError"===t.name||null==(o=this.onerror)||o.call(this,t)});return}let v=new tm({message:`MCP HTTP Transport Error: Unexpected content type: ${g}`,statusCode:z.status,url:this.url.href});throw null==(p=this.onerror)||p.call(this,v),v}catch(t){if(null==(h=null==e?void 0:e.signal)?void 0:h.aborted)throw t;throw null==(d=this.onerror)||d.call(this,t),t}};await s()}getStandardRequestHeaders(t){let e={"Mcp-Method":t.method},r=t.params,o="resources/read"===t.method?null==r?void 0:r.uri:"tools/call"===t.method||"prompts/get"===t.method?null==r?void 0:r.name:void 0;return"string"==typeof o&&(e["Mcp-Name"]=et(o)),e}getNextReconnectionDelay(t){let{initialReconnectionDelay:e,reconnectionDelayGrowFactor:r,maxReconnectionDelay:o}=this.reconnectionOptions;return Math.min(e*Math.pow(r,t),o)}scheduleInboundSseReconnection(){var t;let{maxRetries:e}=this.reconnectionOptions;if(e>0&&this.inboundReconnectAttempts>=e){null==(t=this.onerror)||t.call(this,new tm({message:`MCP HTTP Transport Error: Maximum reconnection attempts (${e}) exceeded.`}));return}let r=this.getNextReconnectionDelay(this.inboundReconnectAttempts);this.inboundReconnectAttempts+=1,setTimeout(()=>{var t;null!=(t=this.abortController)&&t.signal.aborted||this.startInboundSse(!1,this.lastInboundEventId)},r)}startInboundSse(t=!1,e){this.isModernProtocol()||this.openInboundSse(t,e).catch(t=>{var e;t instanceof Error&&"AbortError"===t.name||null==(e=this.onerror)||e.call(this,t)})}async openInboundSse(t=!1,e){var r,o,n,i,s,a;if(!this.isModernProtocol())try{let s=this.sessionId,a=await this.commonHeaders({base:{Accept:"text/event-stream"}});e&&(a["last-event-id"]=e);let l=await this.fetchFn(this.url.href,{method:"GET",headers:a,signal:null==(r=this.abortController)?void 0:r.signal,redirect:this.redirectMode});if(this.applySessionIdFromResponse(l),401===l.status&&this.authProvider&&!t){let{resourceMetadataUrl:t,scope:r}=tF(l);this.resourceMetadataUrl=t;try{let t=await this.authorizeOnce(this.resourceMetadataUrl,r);if("AUTHORIZED"!==t){let t=new tU;null==(o=this.onerror)||o.call(this,t);return}}catch(t){null==(n=this.onerror)||n.call(this,t);return}return this.openInboundSse(!0,e)}if(405===l.status)return;if(!l.ok||!l.body){404===l.status&&s&&this.expireSessionId(s);let t=new tm({message:`MCP HTTP Transport Error: GET SSE failed: ${l.status} ${l.statusText}`,statusCode:l.status,url:this.url.href});null==(i=this.onerror)||i.call(this,t);return}let u=l.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader(),p=async()=>{var t,e,r,o;try{for(;;){let{done:r,value:o}=await u.read();if(r)return;let{event:n,data:i,id:s}=o;if(s&&(this.lastInboundEventId=s),ee(n))try{let e=await tp(i);null==(t=this.onmessage)||t.call(this,e)}catch(r){let t=new tm({message:"MCP HTTP Transport Error: Failed to parse message",cause:r});null==(e=this.onerror)||e.call(this,t)}}}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(r=this.onerror)||r.call(this,t),(null==(o=this.abortController)?void 0:o.signal.aborted)||this.scheduleInboundSseReconnection()}};this.inboundSseConnection={close:()=>{u.cancel().catch(t=>{var e;t instanceof Error&&"AbortError"===t.name||null==(e=this.onerror)||e.call(this,t)})}},this.inboundReconnectAttempts=0,p().catch(t=>{var e,r;t instanceof Error&&"AbortError"===t.name||(null==(e=this.onerror)||e.call(this,t),(null==(r=this.abortController)?void 0:r.signal.aborted)||this.scheduleInboundSseReconnection())})}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;null==(s=this.onerror)||s.call(this,t),(null==(a=this.abortController)?void 0:a.signal.aborted)||this.scheduleInboundSseReconnection()}}},eo=f.array(f.unknown()).transform(t=>t.filter(t=>"string"==typeof t)).optional().catch(void 0),en=f.looseObject({connectDomains:eo,resourceDomains:eo,frameDomains:eo});f.looseObject({prefersBorder:f.boolean().optional().catch(void 0),csp:en.optional().catch(void 0),permissions:f.record(f.string(),f.unknown()).optional().catch(void 0)});var ei=[-32020,-32021,-32022],es=["ConnectionRefused","ConnectionClosed","FailedToOpenSocket","ECONNRESET","ECONNREFUSED","ETIMEDOUT","EPIPE"];function ea(t){let e=function(t){if(null!=t&&"object"==typeof t&&"statusCode"in t&&"number"==typeof t.statusCode)return t.statusCode}(t);if(null!=e)return 408===e||409===e||429===e||e>=500;if(tm.isInstance(t)&&null!=t.code)return!1;let r=function(t){if(null!=t&&"object"==typeof t&&"code"in t&&"string"==typeof t.code)return t.code}(t);return null!=r&&es.includes(r)}function el({timeout:t,maxTotalTimeout:e}){return null==t?e:null==e?t:Math.min(t,e)}function ec(t,e){return null==e?t:new Promise((r,o)=>{let n=()=>{e.removeEventListener("abort",i)},i=()=>{n(),o(e.reason)};e.aborted?i():(e.addEventListener("abort",i,{once:!0}),t.then(t=>{n(),r(t)}).catch(t=>{n(),o(t)}))})}function eu({output:t}){return"content"in t&&Array.isArray(t.content)?{type:"content",value:t.content.map(t=>"text"===t.type&&"text"in t?{type:"text",text:t.text}:"image"===t.type&&"data"in t&&"mimeType"in t?{type:"file",mediaType:t.mimeType,data:{type:"data",data:t.data}}:{type:"text",text:JSON.stringify(t)})}:{type:"json",value:t}}async function ep(t){let e=new eh(t);return await e.init(),e}var eh=class{constructor({transport:t,name:e,clientName:r=null!=e?e:"ai-sdk-mcp-client",version:o="1.0.0",onUncaughtError:n,maxRetries:i,capabilities:s,initialInitializeResult:a,initializationOptions:l,protocolVersionDiscovery:c=!0}){this.requestMessageId=0,this.responseHandlers=new Map,this.serverCapabilities={},this._serverInfo={name:"",version:""},this._initializeResult={protocolVersion:g,capabilities:{},serverInfo:this._serverInfo},this.protocolEra="legacy",this.protocolVersion=g,this.toolHeaderBindings=new Map,this.isClosed=!0,this.onUncaughtError=n,this.maxRetries=function(t){if(null==t)return 0;if(!Number.isInteger(t))throw new tm({message:"maxRetries must be an integer"});if(t<0)throw new tm({message:"maxRetries must be >= 0"});return t}(i),this.clientCapabilities=null!=s?s:{},this.initialInitializeResult=a,this.initializationOptions=l,this.protocolVersionDiscovery=c,function(t){return"start"in t&&"function"==typeof t.start&&"send"in t&&"function"==typeof t.send&&"close"in t&&"function"==typeof t.close}(t)?this.transport=t:this.transport=function(t){var e;switch(t.type){case"sse":return new t8(t);case"http":return new er({...t,initialProtocolVersion:null!=(e=t.initialProtocolVersion)?e:z});default:throw new tm({message:"Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."})}}(t),this.transport.onclose=()=>this.onClose(),this.transport.onerror=t=>this.onError(t),this.transport.onmessage=t=>{"method"in t?"id"in t?this.onRequestMessage(t):this.onError(new tm({message:"Unsupported message type"})):this.onResponse(t)},this.clientInfo={name:r,version:o}}get serverInfo(){return this._serverInfo}get initializeResult(){return this._initializeResult}get instructions(){return this._serverInstructions}async init(){var t;let e,r,o=null==(t=this.initializationOptions)?void 0:t.signal,n=this.initializationOptions?el(this.initializationOptions):void 0,i=null==n?void 0:new AbortController,s=null==o?null==i?void 0:i.signal:null==i?o:AbortSignal.any([o,i.signal]);null!=n&&(e=setTimeout(()=>{r=new tm({message:`MCP client initialization timed out after ${n}ms`}),null==i||i.abort(r)},n));try{if(this.isClosed=!1,null==s||s.throwIfAborted(),await ec(this.transport.start(),s),this.initialInitializeResult){let t=x.parse(this.initialInitializeResult);return this.applyInitializeResult(t),this}if(this.protocolVersionDiscovery&&this.transport.supportsProtocolVersionDiscovery&&await this.tryProtocolDiscovery(s))return this;this.protocolEra="legacy",this.protocolVersion=g,this.setTransportProtocolVersion(this.protocolVersion);let t=await this.request({request:{method:"initialize",params:{protocolVersion:g,capabilities:this.clientCapabilities,clientInfo:this.clientInfo}},resultSchema:x,options:{signal:s}});if(void 0===t)throw new tm({message:"Server sent invalid initialize result"});return this.applyInitializeResult(t),await this.notification({method:"notifications/initialized"},{signal:s}),this}catch(t){try{await ec(this.transport.close({signal:s}),s)}catch(t){}if(this.onClose(),null!=r)throw r;if(null==o?void 0:o.aborted)throw new tm({message:"MCP client initialization was aborted",cause:o.reason});throw t}finally{null!=e&&clearTimeout(e)}}async tryProtocolDiscovery(t){this.protocolEra="modern",this.protocolVersion=z,this.setTransportProtocolVersion(this.protocolVersion);try{let e=await this.request({request:{method:"server/discover"},resultSchema:T,options:{signal:t,timeout:1e3}});return this.applyDiscoverResult(e),!0}catch(t){if(tm.isInstance(t)&&null!=t.code&&ei.includes(t.code))throw t;return!1}}applyDiscoverResult(t){var e;if(!t.supportedVersions.includes(this.protocolVersion))throw new tm({message:`Server does not support the requested protocol version: ${this.protocolVersion}`});let r=null==(e=t._meta)?void 0:e["io.modelcontextprotocol/serverInfo"];null!=r&&"object"==typeof r&&"name"in r&&"string"==typeof r.name&&"version"in r&&"string"==typeof r.version&&(this._serverInfo=r),this.serverCapabilities=t.capabilities,this._serverInstructions=t.instructions,this._initializeResult={protocolVersion:this.protocolVersion,capabilities:t.capabilities,serverInfo:this._serverInfo,instructions:t.instructions}}setTransportProtocolVersion(t){this.transport.setProtocolVersion?this.transport.setProtocolVersion(t):this.transport.protocolVersion=t}applyInitializeResult(t){if(!v.includes(t.protocolVersion))throw new tm({message:`Server's protocol version is not supported: ${t.protocolVersion}`});this.serverCapabilities=t.capabilities,this.protocolEra="legacy",this.protocolVersion=t.protocolVersion,this._serverInfo=t.serverInfo,this._initializeResult=t,this.setTransportProtocolVersion(t.protocolVersion),this._serverInstructions=t.instructions}async close(){var t;this.isClosed||(await (null==(t=this.transport)?void 0:t.close()),this.onClose())}send(t,e){return null==e?this.transport.send(t):this.transport.send(t,e)}assertCapability(t){switch(t){case"initialize":case"server/discover":break;case"completion/complete":if(!this.serverCapabilities.completions)throw new tm({message:"Server does not support completions"});break;case"tools/list":case"tools/call":if(!this.serverCapabilities.tools)throw new tm({message:"Server does not support tools"});break;case"resources/list":case"resources/read":case"resources/templates/list":if(!this.serverCapabilities.resources)throw new tm({message:"Server does not support resources"});break;case"prompts/list":case"prompts/get":if(!this.serverCapabilities.prompts)throw new tm({message:"Server does not support prompts"});break;default:throw new tm({message:`Unsupported method: ${t}`})}}async request({request:t,resultSchema:e,options:r}){return new Promise((o,n)=>{var i;let s;if(this.isClosed)return n(new tm({message:"Attempted to send a request from a closed client"}));this.assertCapability(t.method);let a=null==r?void 0:r.signal;null==a||a.throwIfAborted();let l=null==r?void 0:el(r),c=null==l?void 0:new AbortController,u=null==a?null==c?void 0:c.signal:null==c?a:AbortSignal.any([a,c.signal]),p=this.requestMessageId++,h="modern"===this.protocolEra?{...t,params:{...t.params,_meta:{...null==(i=t.params)?void 0:i._meta,"io.modelcontextprotocol/protocolVersion":this.protocolVersion,"io.modelcontextprotocol/clientCapabilities":this.clientCapabilities,"io.modelcontextprotocol/clientInfo":this.clientInfo}}}:t,d={...h,jsonrpc:"2.0",id:p},m=this.getToolRequestHeaders(h),f=()=>{n(new tm({message:"Request was aborted",cause:null==a?void 0:a.reason}))},z=()=>{this.responseHandlers.delete(p),null==a||a.removeEventListener("abort",v),null!=s&&clearTimeout(s)},g=t=>{z(),n(t)},v=()=>{z(),f()};this.responseHandlers.set(p,t=>{if(null==a?void 0:a.aborted)return z(),f();if(t instanceof Error)return g(t);try{if("modern"===this.protocolEra&&null==t.result.resultType)throw new tm({message:"Modern MCP result is missing resultType"});if("input_required"===t.result.resultType)throw new tm({message:"Server requested additional input, but multi round-trip requests are not supported yet"});let r=e.parse(t.result);z(),o(r)}catch(t){g(tm.isInstance(t)?t:new tm({message:"Failed to parse server response",cause:t}))}}),null==a||a.addEventListener("abort",v,{once:!0}),null!=l&&(s=setTimeout(()=>{let t=new tm({message:`Request timed out after ${l}ms`});null==c||c.abort(t),g(t)},l));let w={...null==u?{}:{signal:u},...null==m?{}:{headers:m}};(0===Object.keys(w).length?this.send(d):this.send(d,w)).catch(t=>{g(t)})})}async listTools({params:t,options:e}={}){let r=await this.request({request:{method:"tools/list",params:t},resultSchema:I,options:e});return this.prepareToolDefinitions(r,(null==t?void 0:t.cursor)==null)}prepareToolDefinitions(t,e=!1){if("modern"!==this.protocolEra||!this.transport.supportsMcpToolParameterHeaders)return t;e&&this.toolHeaderBindings.clear();let r=t.tools.filter(t=>{let e=function(t){let e;if(!(0,s.isRecord)(t))return{success:!1,error:"inputSchema must be a JSON Schema object"};let r=[],o=new Set,n=(t,i,a)=>{if(null==e&&(0,s.isRecord)(t)){if("x-mcp-header"in t){if(!a||0===i.length){e="x-mcp-header is not on a statically reachable property";return}let n=t["x-mcp-header"];if("string"!=typeof n||!t7.test(n)){e="x-mcp-header must be a non-empty HTTP token";return}let s=n.toLowerCase();if(o.has(s)){e=`x-mcp-header value "${n}" is not unique`;return}let l=t.type;if("boolean"!==l&&"integer"!==l&&"string"!==l){e="x-mcp-header can only annotate boolean, integer, or string properties";return}o.add(s),r.push({headerName:n,path:i,valueType:l})}for(let[e,r]of Object.entries(t))if("x-mcp-header"!==e)if("properties"===e&&(0,s.isRecord)(r))for(let[t,e]of Object.entries(r))n(e,[...i,t],a);else n(r,i,!1)}};return n(t,[],!0),null==e?{success:!0,bindings:r}:{success:!1,error:e}}(t.inputSchema);return e.success?(this.toolHeaderBindings.set(t.name,e.bindings),!0):(this.onError(new tm({message:`Ignoring MCP tool "${t.name}": ${e.error}`})),!1)});return{...t,tools:r}}getToolRequestHeaders(t){var e;if("modern"!==this.protocolEra||"tools/call"!==t.method||"string"!=typeof(null==(e=t.params)?void 0:e.name))return;let r=this.toolHeaderBindings.get(t.params.name);if(null==r||0===r.length)return;let o=t.params.arguments;if(!(null==o||"object"!=typeof o||Array.isArray(o)))try{return function({bindings:t,args:e}){let r={};for(let o of t){let t=function(t,e){let r=t;for(let t of e){if(!(0,s.isRecord)(r))return;r=r[t]}return r}(e,o.path);if(null!=t){if("string"===o.valueType&&"string"!=typeof t||"boolean"===o.valueType&&"boolean"!=typeof t||"integer"===o.valueType&&!Number.isSafeInteger(t))throw TypeError(`Tool argument "${o.path.join(".")}" does not match its x-mcp-header type`);r[`Mcp-Param-${o.headerName}`]=et(String(t))}}return r}({bindings:r,args:o})}catch(e){throw new tm({message:`Failed to create MCP headers for tool "${t.params.name}"`,cause:e})}}async callToolWithRetry({options:t,execute:e}){return 0===this.maxRetries?e():(0,s.retryWithExponentialBackoff)({maxRetries:this.maxRetries,abortSignal:null==t?void 0:t.signal,shouldRetry:ea,createRetryError:({message:t,errors:e})=>new tm({message:t,cause:e[e.length-1]})})(e)}async callTool({name:t,arguments:e={},options:r}){try{return this.callToolWithRetry({options:r,execute:()=>this.request({request:{method:"tools/call",params:{name:t,arguments:e}},resultSchema:D,options:r})})}catch(t){throw t}}async listResourcesInternal({params:t,options:e}={}){try{return this.request({request:{method:"resources/list",params:t},resultSchema:U,options:e})}catch(t){throw t}}async readResourceInternal({uri:t,options:e}){try{return this.request({request:{method:"resources/read",params:{uri:t}},resultSchema:W,options:e})}catch(t){throw t}}async listResourceTemplatesInternal({options:t}={}){try{return this.request({request:{method:"resources/templates/list"},resultSchema:B,options:t})}catch(t){throw t}}async listPromptsInternal({params:t,options:e}={}){try{return this.request({request:{method:"prompts/list",params:t},resultSchema:Q,options:e})}catch(t){throw t}}async getPromptInternal({name:t,args:e,options:r}){try{return this.request({request:{method:"prompts/get",params:{name:t,arguments:e}},resultSchema:te,options:r})}catch(t){throw t}}async completeInternal({options:t,...e}){return this.request({request:{method:"completion/complete",params:e},resultSchema:G,options:t})}async notification(t,e){let r={...t,jsonrpc:"2.0"};await ec(this.send(r,(null==e?void 0:e.signal)==null?void 0:{signal:e.signal}),null==e?void 0:e.signal)}async tools({schemas:t="automatic"}={}){let e=await this.listTools(),r=[...e.tools];for(;null!=e.nextCursor;)e=await this.listTools({params:{cursor:e.nextCursor}}),r.push(...e.tools);return this.toolsFromDefinitions({...e,tools:r},{schemas:t})}toolsFromDefinitions(t,{schemas:e="automatic"}={}){var r,o;t=this.prepareToolDefinitions(t);let n={};for(let{name:i,title:a,description:c,inputSchema:u,annotations:p,_meta:h}of t.tools){let t=null!=a?a:null==p?void 0:p.title;if("automatic"!==e&&!Object.prototype.hasOwnProperty.call(e,i))continue;let d=this,m="automatic"!==e?null==(r=e[i])?void 0:r.outputSchema:void 0,f=function(t){var e,r,o,n;let i,s=(i=null==(o=t._meta)?void 0:o.ui,(0,l.isJSONObject)(i)?i:void 0),a=null!=(r=null==s?void 0:s.resourceUri)?r:null==(e=t._meta)?void 0:e["ui/resourceUri"],c=Array.isArray(n=null==s?void 0:s.visibility)?n.filter(t=>"model"===t||"app"===t):void 0;if(void 0!==a){if("string"!=typeof a||!a.startsWith("ui://"))throw Error(`Invalid MCP App resource URI: ${JSON.stringify(a)}`)}else if(null==s)return;return{...s,...null!=a?{resourceUri:a}:{},...null!=c?{visibility:c}:{}}}({_meta:h}),z={clientName:this.clientInfo.name,toolName:i,...null!=t?{title:t}:{},...null!=p?{annotations:{...null!=p.title?{title:p.title}:{},...null!=p.readOnlyHint?{readOnlyHint:p.readOnlyHint}:{},...null!=p.destructiveHint?{destructiveHint:p.destructiveHint}:{},...null!=p.idempotentHint?{idempotentHint:p.idempotentHint}:{},...null!=p.openWorldHint?{openWorldHint:p.openWorldHint}:{}}}:{},...(null==f?void 0:f.resourceUri)!=null?{app:{...f,mimeType:"text/html;profile=mcp-app"}}:{}},g=async(t,e)=>{var r;null==(r=null==e?void 0:e.abortSignal)||r.throwIfAborted();let o=await d.callTool({name:i,arguments:t,options:{signal:null==e?void 0:e.abortSignal}});return o.isError?o:null!=m?d.extractStructuredContent(o,m,i):o},v="automatic"===e?(0,s.dynamicTool)({description:c,title:t,metadata:z,inputSchema:(0,s.jsonSchema)({...u,properties:null!=(o=u.properties)?o:{},additionalProperties:!1}),execute:g,toModelOutput:eu}):(0,s.tool)({description:c,title:t,metadata:z,inputSchema:e[i].inputSchema,...null!=m?{outputSchema:m}:{},execute:g,toModelOutput:eu});n[i]={...v,_meta:h}}return n}async extractStructuredContent(t,e,r){if("structuredContent"in t&&null!=t.structuredContent){let o=await (0,s.safeValidateTypes)({value:t.structuredContent,schema:(0,s.asSchema)(e)});if(!o.success)throw new tm({message:`Tool "${r}" returned structuredContent that does not match the expected outputSchema`,cause:o.error});return o.value}if("content"in t&&Array.isArray(t.content)){let o=t.content.find(t=>"text"===t.type);if(o&&"text"in o){let t=await (0,s.safeParseJSON)({text:o.text,schema:e});if(!t.success)throw new tm({message:`Tool "${r}" returned content that does not match the expected outputSchema`,cause:t.error});return t.value}}throw new tm({message:`Tool "${r}" did not return structuredContent or parseable text content`})}listResources({params:t,options:e}={}){return this.listResourcesInternal({params:t,options:e})}readResource({uri:t,options:e}){return this.readResourceInternal({uri:t,options:e})}listResourceTemplates({options:t}={}){return this.listResourceTemplatesInternal({options:t})}experimental_listPrompts({params:t,options:e}={}){return this.listPromptsInternal({params:t,options:e})}experimental_getPrompt({name:t,arguments:e,options:r}){return this.getPromptInternal({name:t,args:e,options:r})}complete(t){return this.completeInternal(t)}onElicitationRequest(t,e){if(t!==to)throw new tm({message:"Unsupported request schema. Only ElicitationRequestSchema is supported."});this.elicitationRequestHandler=e}async onRequestMessage(t){try{if("ping"===t.method)return void await this.transport.send({jsonrpc:"2.0",id:t.id,result:{}});if("elicitation/create"!==t.method)return void await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32601,message:`Unsupported request method: ${t.method}`}});if(!this.elicitationRequestHandler)return void await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32601,message:"No elicitation handler registered on client"}});let e=to.safeParse({method:t.method,params:t.params});if(!e.success)return void await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32602,message:`Invalid elicitation request: ${e.error.message}`,data:e.error.issues}});try{let r=await this.elicitationRequestHandler(e.data),o=tn.parse(r);await this.transport.send({jsonrpc:"2.0",id:t.id,result:o})}catch(e){await this.transport.send({jsonrpc:"2.0",id:t.id,error:{code:-32603,message:e instanceof Error?e.message:"Failed to handle elicitation request"}}),this.onError(e)}}catch(t){this.onError(t)}}onClose(){if(this.isClosed)return;this.isClosed=!0;let t=new tm({message:"Connection closed"});for(let e of this.responseHandlers.values())e(t);this.responseHandlers.clear()}onError(t){this.onUncaughtError&&this.onUncaughtError(t)}onResponse(t){if(null==t.id)return void this.onError(new tm({message:`Protocol error: Received a response without a message ID: ${JSON.stringify(t)}`}));let e=Number(t.id),r=this.responseHandlers.get(e);if(void 0===r)throw new tm({message:`Protocol error: Received a response for an unknown message ID: ${JSON.stringify(t)}`});this.responseHandlers.delete(e),r("result"in t?t:new tm({message:t.error.message,code:t.error.code,data:t.error.data,cause:t.error}))}};new TextEncoder,t.s(["UnauthorizedError",0,tU,"auth",0,t3,"createMCPClient",0,ep],361164)},202058,(t,e,r)=>{e.exports=n,n.sync=function(t,e){return i(o.statSync(t),e)};var o=t.r(522734);function n(t,e,r){o.stat(t,function(t,o){r(t,!t&&i(o,e))})}function i(t,e){var r,o,n,i,s,a,l,c,u;return t.isFile()&&(r=t,o=e,n=r.mode,i=r.uid,s=r.gid,a=void 0!==o.uid?o.uid:process.getuid&&process.getuid(),l=void 0!==o.gid?o.gid:process.getgid&&process.getgid(),c=parseInt("100",8),u=parseInt("010",8),n&parseInt("001",8)||n&u&&s===l||n&c&&i===a||n&(c|u)&&0===a)}},129507,(t,e,r)=>{e.exports=i,i.sync=function(t,e){return n(o.statSync(t),t,e)};var o=t.r(522734);function n(t,e,r){if(!t.isSymbolicLink()&&!t.isFile())return!1;var o=void 0!==r.pathExt?r.pathExt:process.env.PATHEXT;if(!o||-1!==(o=o.split(";")).indexOf(""))return!0;for(var n=0;n<o.length;n++){var i=o[n].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(t,e,r){o.stat(t,function(o,i){r(o,!o&&n(i,t,e))})}},24214,(t,e,r)=>{var o;function n(t,e,r){if("function"==typeof e&&(r=e,e={}),!r){if("function"!=typeof Promise)throw TypeError("callback not provided");return new Promise(function(r,o){n(t,e||{},function(t,e){t?o(t):r(e)})})}o(t,e||{},function(t,o){t&&("EACCES"===t.code||e&&e.ignoreErrors)&&(t=null,o=!1),r(t,o)})}t.r(522734),o="win32"===process.platform||t.g.TESTING_WINDOWS?t.r(129507):t.r(202058),e.exports=n,n.sync=function(t,e){try{return o.sync(t,e||{})}catch(t){if(e&&e.ignoreErrors||"EACCES"===t.code)return!1;throw t}}},319932,(t,e,r)=>{let o="win32"===process.platform||"cygwin"===process.env.OSTYPE||"msys"===process.env.OSTYPE,n=t.r(814747),i=o?";":":",s=t.r(24214),a=t=>Object.assign(Error(`not found: ${t}`),{code:"ENOENT"}),l=(t,e)=>{let r=e.colon||i,n=t.match(/\//)||o&&t.match(/\\/)?[""]:[...o?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(r)],s=o?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",a=o?s.split(r):[""];return o&&-1!==t.indexOf(".")&&""!==a[0]&&a.unshift(""),{pathEnv:n,pathExt:a,pathExtExe:s}},c=(t,e,r)=>{"function"==typeof e&&(r=e,e={}),e||(e={});let{pathEnv:o,pathExt:i,pathExtExe:c}=l(t,e),u=[],p=r=>new Promise((i,s)=>{if(r===o.length)return e.all&&u.length?i(u):s(a(t));let l=o[r],c=/^".*"$/.test(l)?l.slice(1,-1):l,p=n.join(c,t);i(h(!c&&/^\.[\\\/]/.test(t)?t.slice(0,2)+p:p,r,0))}),h=(t,r,o)=>new Promise((n,a)=>{if(o===i.length)return n(p(r+1));let l=i[o];s(t+l,{pathExt:c},(i,s)=>{if(!i&&s)if(!e.all)return n(t+l);else u.push(t+l);return n(h(t,r,o+1))})});return r?p(0).then(t=>r(null,t),r):p(0)};e.exports=c,c.sync=(t,e)=>{let{pathEnv:r,pathExt:o,pathExtExe:i}=l(t,e=e||{}),c=[];for(let a=0;a<r.length;a++){let l=r[a],u=/^".*"$/.test(l)?l.slice(1,-1):l,p=n.join(u,t),h=!u&&/^\.[\\\/]/.test(t)?t.slice(0,2)+p:p;for(let t=0;t<o.length;t++){let r=h+o[t];try{if(s.sync(r,{pathExt:i}))if(!e.all)return r;else c.push(r)}catch(t){}}}if(e.all&&c.length)return c;if(e.nothrow)return null;throw a(t)}},625881,(t,e,r)=>{"use strict";let o=(t={})=>{let e=t.env||process.env;return"win32"!==(t.platform||process.platform)?"PATH":Object.keys(e).reverse().find(t=>"PATH"===t.toUpperCase())||"Path"};e.exports=o,e.exports.default=o},81463,(t,e,r)=>{"use strict";let o=t.r(814747),n=t.r(319932),i=t.r(625881);function s(t,e){let r,s=t.options.env||process.env,a=process.cwd(),l=null!=t.options.cwd,c=l&&void 0!==process.chdir&&!process.chdir.disabled;if(c)try{process.chdir(t.options.cwd)}catch(t){}try{r=n.sync(t.command,{path:s[i({env:s})],pathExt:e?o.delimiter:void 0})}catch(t){}finally{c&&process.chdir(a)}return r&&(r=o.resolve(l?t.options.cwd:"",r)),r}e.exports=function(t){return s(t)||s(t,!0)}},502977,(t,e,r)=>{"use strict";let o=/([()\][%!^"`<>&|;, *?])/g;e.exports.command=function(t){return t.replace(o,"^$1")},e.exports.argument=function(t,e){return t=(t=(t=`${t}`).replace(/(?=(\\+?)?)\1"/g,'$1$1\\"')).replace(/(?=(\\+?)?)\1$/,"$1$1"),t=(t=`"${t}"`).replace(o,"^$1"),e&&(t=t.replace(o,"^$1")),t}},831804,(t,e,r)=>{"use strict";e.exports=/^#!(.*)/},469231,(t,e,r)=>{"use strict";let o=t.r(831804);e.exports=(t="")=>{let e=t.match(o);if(!e)return null;let[r,n]=e[0].replace(/#! ?/,"").split(" "),i=r.split("/").pop();return"env"===i?n:n?`${i} ${n}`:i}},385328,(t,e,r)=>{"use strict";let o=t.r(522734),n=t.r(469231);e.exports=function(t){let e,r=Buffer.alloc(150);try{e=o.openSync(t,"r"),o.readSync(e,r,0,150,0),o.closeSync(e)}catch(t){}return n(r.toString())}},207546,(t,e,r)=>{"use strict";t.r(814747),t.r(81463),t.r(502977),t.r(385328),process.platform,e.exports=function(t,e,r){e&&!Array.isArray(e)&&(r=e,e=null);let o={command:t,args:e=e?e.slice(0):[],options:r=Object.assign({},r),file:void 0,original:{command:t,args:e}};return r.shell,o}},245750,(t,e,r)=>{"use strict";process.platform,e.exports={hookChildProcess:function(t,e){},verifyENOENT:function(t,e){return null},verifyENOENTSync:function(t,e){return null},notFoundError:function(t,e){return Object.assign(Error(`${e} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${e} ${t.command}`,path:t.command,spawnargs:t.args})}}},465887,(t,e,r)=>{"use strict";let o=t.r(233405),n=t.r(207546),i=t.r(245750);function s(t,e,r){let s=n(t,e,r),a=o.spawn(s.command,s.args,s.options);return i.hookChildProcess(a,s),a}e.exports=s,e.exports.spawn=s,e.exports.sync=function(t,e,r){let s=n(t,e,r),a=o.spawnSync(s.command,s.args,s.options);return a.error=a.error||i.verifyENOENTSync(a.status,s),a},e.exports._parse=n,e.exports._enoent=i},958560,t=>{"use strict";var e,r,o=t.i(847841),n=t.i(469719),i=t.i(376261),s=t.i(465887),a=n.z.optional(n.z.record(n.z.string(),n.z.unknown())),l=n.z.looseObject({name:n.z.string(),version:n.z.string(),title:n.z.optional(n.z.string())}),c=n.z.looseObject({_meta:n.z.optional(n.z.object({}).loose())}),u=c.extend({resultType:n.z.optional(n.z.string())}),p=n.z.object({method:n.z.string(),params:n.z.optional(c)}),h=n.z.object({applyDefaults:n.z.optional(n.z.boolean())}).loose(),d=n.z.looseObject({experimental:n.z.optional(n.z.object({}).loose()),logging:n.z.optional(n.z.object({}).loose()),completions:n.z.optional(n.z.object({}).loose()),prompts:n.z.optional(n.z.looseObject({listChanged:n.z.optional(n.z.boolean())})),resources:n.z.optional(n.z.looseObject({subscribe:n.z.optional(n.z.boolean()),listChanged:n.z.optional(n.z.boolean())})),tools:n.z.optional(n.z.looseObject({listChanged:n.z.optional(n.z.boolean())})),elicitation:n.z.optional(h)});n.z.object({elicitation:n.z.optional(h)}).loose(),u.extend({supportedVersions:n.z.array(n.z.string()),capabilities:d,instructions:n.z.optional(n.z.string()),ttlMs:n.z.optional(n.z.number()),cacheScope:n.z.optional(n.z.union([n.z.literal("public"),n.z.literal("private")]))}),u.extend({protocolVersion:n.z.string(),capabilities:d,serverInfo:l,instructions:n.z.optional(n.z.string())});var m=u.extend({nextCursor:n.z.optional(n.z.string())}),f=n.z.object({name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),inputSchema:n.z.looseObject({type:n.z.optional(n.z.unknown()),properties:n.z.optional(n.z.object({}).loose())}),outputSchema:n.z.optional(n.z.object({}).loose()),annotations:n.z.optional(n.z.object({title:n.z.optional(n.z.string()),readOnlyHint:n.z.optional(n.z.boolean()),destructiveHint:n.z.optional(n.z.boolean()),idempotentHint:n.z.optional(n.z.boolean()),openWorldHint:n.z.optional(n.z.boolean())}).loose()),_meta:a}).loose();m.extend({tools:n.z.array(f)});var z=n.z.object({type:n.z.literal("text"),text:n.z.string()}).loose(),g=n.z.object({type:n.z.literal("image"),data:n.z.base64(),mimeType:n.z.string()}).loose(),v=n.z.object({uri:n.z.string(),name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string()),size:n.z.optional(n.z.number())}).loose();m.extend({resources:n.z.array(v)});var w=n.z.object({uri:n.z.string(),name:n.z.optional(n.z.string()),title:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).loose(),y=w.extend({text:n.z.string()}),b=w.extend({blob:n.z.base64()}),_=n.z.object({type:n.z.literal("resource"),resource:n.z.union([y,b])}).loose(),E=n.z.object({type:n.z.literal("resource_link"),uri:n.z.string(),name:n.z.string(),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).loose(),S=n.z.object({type:n.z.string()}).loose().refine(t=>!["text","image","resource","resource_link"].includes(t.type),{message:"Known content types must match their schema"}),C=u.extend({content:n.z.array(n.z.union([z,g,_,E,S])),structuredContent:n.z.optional(n.z.unknown()),isError:n.z.boolean().default(!1).optional()}),T=u.extend({content:n.z.never().optional(),structuredContent:n.z.json(),isError:n.z.boolean().default(!1).optional()}).transform(t=>({...t,content:[{type:"text",text:JSON.stringify(t.structuredContent)}]})).pipe(C);C.or(T).or(u.extend({toolResult:n.z.unknown().nonoptional()}));var x=n.z.object({uriTemplate:n.z.string(),name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).loose();u.extend({resourceTemplates:n.z.array(x)}),u.extend({contents:n.z.array(n.z.union([y,b]))});var P=n.z.object({type:n.z.literal("ref/prompt"),name:n.z.string()}).loose(),R=n.z.object({type:n.z.literal("ref/resource"),uri:n.z.string()}).loose(),I=n.z.object({name:n.z.string(),value:n.z.string()}).loose();c.extend({ref:n.z.union([P,R]),argument:I,context:n.z.optional(n.z.object({arguments:n.z.record(n.z.string(),n.z.string())}).loose())}),u.extend({completion:n.z.object({values:n.z.array(n.z.string()).max(100),total:n.z.optional(n.z.number().int()),hasMore:n.z.optional(n.z.boolean())}).loose()});var A=n.z.object({name:n.z.string(),description:n.z.optional(n.z.string()),required:n.z.optional(n.z.boolean())}).loose(),j=n.z.object({name:n.z.string(),title:n.z.optional(n.z.string()),description:n.z.optional(n.z.string()),arguments:n.z.optional(n.z.array(A))}).loose();m.extend({prompts:n.z.array(j)});var k=n.z.object({role:n.z.union([n.z.literal("user"),n.z.literal("assistant")]),content:n.z.union([z,g,_,E])}).loose();u.extend({description:n.z.optional(n.z.string()),messages:n.z.array(k)});var U=c.extend({message:n.z.string(),requestedSchema:n.z.unknown()});p.extend({method:n.z.literal("elicitation/create"),params:U}),u.extend({action:n.z.union([n.z.literal("accept"),n.z.literal("decline"),n.z.literal("cancel")]),content:n.z.optional(n.z.record(n.z.string(),n.z.unknown()))});var O=n.z.object({jsonrpc:n.z.literal("2.0"),id:n.z.union([n.z.string(),n.z.number().int()])}).merge(p).strict(),M=n.z.object({jsonrpc:n.z.literal("2.0"),id:n.z.union([n.z.string(),n.z.number().int()]),result:u}).strict(),$=n.z.object({jsonrpc:n.z.literal("2.0"),id:n.z.optional(n.z.union([n.z.string(),n.z.number().int()])),error:n.z.object({code:n.z.number().int(),message:n.z.string(),data:n.z.optional(n.z.unknown())})}).strict(),H=n.z.object({jsonrpc:n.z.literal("2.0")}).merge(n.z.object({method:n.z.string(),params:n.z.optional(c)})).strict(),N=n.z.union([O,H,M,$]);async function V(t){var e;return e=await (0,o.parseJSON)({text:t}),N.parse(e)}var L="vercel.ai.error.AI_MCPClientError",q=Symbol.for(L),D=class extends(r=i.AISDKError,e=q,r){constructor({name:t="MCPClientError",message:r,cause:o,data:n,code:i,statusCode:s,url:a,responseBody:l}){super({name:t,message:r,cause:o}),this[e]=!0,this.data=n,this.code=i,this.statusCode=s,this.url=a,this.responseBody=l}static isInstance(t){return i.AISDKError.hasMarker(t,L)}},F=class{constructor(t){this.supportsProtocolVersionDiscovery=!0,this.abortController=new AbortController,this.readBuffer=new B,this.serverParams=t}async start(){if(this.process)throw new D({message:"StdioMCPTransport already started."});return new Promise((t,e)=>{var r,o,n,i;try{let i=function(t,e){var r,o,n;if("win32"===globalThis.process.platform&&[t.command,...null!=(r=t.args)?r:[]].some(t=>/[\r\n]/.test(t)))throw TypeError("Stdio MCP commands and arguments must not contain line breaks on Windows.");return(0,s.default)(t.command,null!=(o=t.args)?o:[],{env:function(t){let e="win32"===globalThis.process.platform?["APPDATA","HOMEDRIVE","HOMEPATH","LOCALAPPDATA","PATH","PROCESSOR_ARCHITECTURE","SYSTEMDRIVE","SYSTEMROOT","TEMP","USERNAME","USERPROFILE"]:["HOME","LOGNAME","PATH","SHELL","TERM","USER"],r=t?{...t}:{};for(let t of e){let e=globalThis.process.env[t];void 0!==e&&(e.startsWith("()")||(r[t]=e))}return r}(t.env),stdio:["pipe","pipe",null!=(n=t.stderr)?n:"inherit"],shell:!1,signal:e,windowsHide:"win32"===globalThis.process.platform&&"type"in globalThis.process,cwd:t.cwd})}(this.serverParams,this.abortController.signal);this.process=i,this.process.on("error",t=>{var r,o;if("AbortError"===t.name){null==(r=this.onclose)||r.call(this);return}e(t),null==(o=this.onerror)||o.call(this,t)}),this.process.on("spawn",()=>{t()}),this.process.on("close",t=>{var e;this.process=void 0,null==(e=this.onclose)||e.call(this)}),null==(r=this.process.stdin)||r.on("error",t=>{var e;null==(e=this.onerror)||e.call(this,t)}),null==(o=this.process.stdout)||o.on("data",t=>{this.readBuffer.append(t),this.processReadBuffer()}),null==(n=this.process.stdout)||n.on("error",t=>{var e;null==(e=this.onerror)||e.call(this,t)})}catch(t){e(t),null==(i=this.onerror)||i.call(this,t)}})}async processReadBuffer(){for(var t,e;;){let r=this.readBuffer.readLine();if(null===r)break;try{let e=await W(r);null==(t=this.onmessage)||t.call(this,e)}catch(t){null==(e=this.onerror)||e.call(this,t)}}}async close(){this.abortController.abort(),this.process=void 0,this.readBuffer.clear()}send(t){return new Promise(e=>{var r;if(!(null==(r=this.process)?void 0:r.stdin))throw new D({message:"StdioClientTransport not connected"});let o=JSON.stringify(t)+"\n";this.process.stdin.write(o)?e():this.process.stdin.once("drain",e)})}},B=class{append(t){this.buffer=this.buffer?Buffer.concat([this.buffer,t]):t}readLine(){if(!this.buffer)return null;let t=this.buffer.indexOf("\n");if(-1===t)return null;let e=this.buffer.toString("utf8",0,t);return this.buffer=this.buffer.subarray(t+1),e}clear(){this.buffer=void 0}};async function W(t){return V(t)}t.s(["Experimental_StdioMCPTransport",0,F])}];
2
2
 
3
3
  //# sourceMappingURL=_1d5zmy8._.js.map