thursday-agent 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +3 -3
- package/.next/prerender-manifest.json +3 -3
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/artifact/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/memory/files/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/memory/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/thread/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/thread/file/route.js +2 -2
- package/.next/server/app/api/bot/thread/file/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/thread/route.js.nft.json +1 -1
- package/.next/server/app/api/config/route.js.nft.json +1 -1
- package/.next/server/app/api/file/[...path]/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/automatic/route.js +2 -2
- package/.next/server/app/api/llm-model/automatic/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/catalog/[provider]/route.js +2 -2
- package/.next/server/app/api/llm-model/catalog/[provider]/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/credits/[provider]/route.js +2 -2
- package/.next/server/app/api/llm-model/credits/[provider]/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/route.js +2 -2
- package/.next/server/app/api/llm-model/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/subscription/route.js +2 -2
- package/.next/server/app/api/llm-model/subscription/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/[name]/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/oauth/callback/route.js +3 -3
- package/.next/server/app/api/mcp/oauth/callback/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/tools/route.js.nft.json +1 -1
- package/.next/server/app/api/memory/edit/route.js +2 -2
- package/.next/server/app/api/memory/edit/route.js.nft.json +1 -1
- package/.next/server/app/api/reach/route.js +2 -2
- package/.next/server/app/api/reach/route.js.nft.json +1 -1
- package/.next/server/app/api/routine/route.js.nft.json +1 -1
- package/.next/server/app/api/signins/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/[source]/[name]/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/call/end/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/call/plan/route.js +3 -3
- package/.next/server/app/api/thursday/call/plan/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/call/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/settings/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/text/route.js +2 -2
- package/.next/server/app/api/thursday/text/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/tool-call/route.js +3 -3
- package/.next/server/app/api/thursday/tool-call/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/files/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/route.js.nft.json +1 -1
- package/.next/server/app/artifact/[...path]/page/server-reference-manifest.json +11 -11
- package/.next/server/app/artifact/[...path]/page.js +2 -2
- package/.next/server/app/artifact/[...path]/page.js.nft.json +1 -1
- package/.next/server/app/artifact/[...path]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/page/react-loadable-manifest.json +1 -1
- package/.next/server/app/page/server-reference-manifest.json +63 -63
- package/.next/server/app/page.js +2 -2
- package/.next/server/app/page.js.nft.json +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0582p46._.js +1 -1
- package/.next/server/chunks/{[root-of-the-server]__0d00o4_._.js → [root-of-the-server]__06_ck92._.js} +1 -1
- package/.next/server/chunks/[root-of-the-server]__06kxzw-._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0d-dfqm._.js +1 -1
- package/.next/server/chunks/{[root-of-the-server]__1mowvzz._.js → [root-of-the-server]__0f8quhc._.js} +1 -1
- package/.next/server/chunks/[root-of-the-server]__0lg1fok._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0mh1tgg._.js +1 -1
- package/.next/server/chunks/{[root-of-the-server]__0eem_66._.js → [root-of-the-server]__0tsqr_i._.js} +1 -1
- package/.next/server/chunks/{[root-of-the-server]__1yiqjfx._.js → [root-of-the-server]__0z8s0g8._.js} +1 -1
- package/.next/server/chunks/[root-of-the-server]__11e22s7._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1478lu3._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__17kdjf6._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__17m7ag9._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__181zc_o._.js +1 -1
- package/.next/server/chunks/{[root-of-the-server]__1ivfglf._.js → [root-of-the-server]__1mwe6in._.js} +1 -1
- package/.next/server/chunks/{[root-of-the-server]__1r_d-gv._.js → [root-of-the-server]__1nzt9ia._.js} +1 -1
- package/.next/server/chunks/[root-of-the-server]__1v5jpk9._.js +1 -1
- package/.next/server/chunks/{[root-of-the-server]__0pp2355._.js → [root-of-the-server]__1vz_k4p._.js} +1 -1
- package/.next/server/chunks/_008vczq._.js +1 -1
- package/.next/server/chunks/_00aztuo._.js +1 -1
- package/.next/server/chunks/_021kabv._.js +20 -20
- package/.next/server/chunks/_05gl-xy._.js +48 -40
- package/.next/server/chunks/_07mczew._.js +1 -1
- package/.next/server/chunks/_0la8s6t._.js +1 -1
- package/.next/server/chunks/_0rn3c_0._.js +31 -31
- package/.next/server/chunks/_0wkhub3._.js +1 -1
- package/.next/server/chunks/{_0q2y48v._.js → _0z9l1-a._.js} +1 -1
- package/.next/server/chunks/_0zwjr-g._.js +1 -1
- package/.next/server/chunks/_12-7atf._.js +1 -1
- package/.next/server/chunks/_124q1p2._.js +1 -1
- package/.next/server/chunks/_13qoxq9._.js +31 -31
- package/.next/server/chunks/_15-_mie._.js +1 -1
- package/.next/server/chunks/_18sj4xf._.js +1 -1
- package/.next/server/chunks/_19kea1l._.js +46 -38
- package/.next/server/chunks/{_0-934yz._.js → _1ao-3d8._.js} +1 -1
- package/.next/server/chunks/{_0a09g1e._.js → _1cc2hkg._.js} +1 -1
- package/.next/server/chunks/_1chy-lk._.js +1 -1
- package/.next/server/chunks/_1cok9lj._.js +76 -0
- package/.next/server/chunks/_1d5zmy8._.js +1 -1
- package/.next/server/chunks/{_0ocmvv0._.js → _1h7ll0h._.js} +1 -1
- package/.next/server/chunks/_1hw1ujv._.js +20 -20
- package/.next/server/chunks/_1lg0lsu._.js +24 -24
- package/.next/server/chunks/_1mzdpal._.js +76 -0
- package/.next/server/chunks/_1q42187._.js +2 -2
- package/.next/server/chunks/_1u2plme._.js +3 -0
- package/.next/server/chunks/_1ufbxe1._.js +1 -1
- package/.next/server/chunks/_1unludv._.js +1 -1
- package/.next/server/chunks/_1v4id5q._.js +20 -20
- package/.next/server/chunks/_1v5qol2._.js +20 -20
- package/.next/server/chunks/_1wg0cqo._.js +1 -1
- package/.next/server/chunks/_1x2xiyw._.js +1 -1
- package/.next/server/chunks/_1znrlca._.js +1 -1
- package/.next/server/chunks/node_modules_09fdt86._.js +26 -0
- package/.next/server/chunks/node_modules_0u_q4-b._.js +26 -0
- package/.next/server/chunks/node_modules_1oo0z5r._.js +26 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__09u-n6y._.js +112 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__0glkz9k._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__0rpmgnt._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__0tgkj13._.js +3 -0
- package/.next/server/chunks/ssr/{[root-of-the-server]__203utm3._.js → [root-of-the-server]__0wrprhy._.js} +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__17yeveo._.js +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__1867koj._.js +1 -1
- package/.next/server/chunks/ssr/{[root-of-the-server]__0zt_au4._.js → [root-of-the-server]__1ft98nl._.js} +2 -2
- package/.next/server/chunks/ssr/[root-of-the-server]__1gv2nbd._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1kos36s._.js +6 -0
- package/.next/server/chunks/ssr/{[root-of-the-server]__0y03pu0._.js → [root-of-the-server]__1n2hycp._.js} +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__20floom._.js +2 -2
- package/.next/server/chunks/ssr/{_0eprrig._.js → _0-y517w._.js} +2 -2
- package/.next/server/chunks/ssr/{_03vw3u5._.js → _02sda-9._.js} +2 -2
- package/.next/server/chunks/ssr/_03n27qx._.js +85 -0
- package/.next/server/chunks/ssr/_04jb10a._.js +3 -0
- package/.next/server/chunks/ssr/_09a6bpd._.js +1 -1
- package/.next/server/chunks/ssr/_0akma_h._.js +3 -0
- package/.next/server/chunks/ssr/_0cd6g3l._.js +44 -36
- package/.next/server/chunks/ssr/_0fx7w0u._.js +3 -0
- package/.next/server/chunks/ssr/_0gfa_rb._.js +3 -0
- package/.next/server/chunks/ssr/_0ghdb00._.js +3 -0
- package/.next/server/chunks/ssr/_0ingto_._.js +3 -0
- package/.next/server/chunks/ssr/_0jgsxrg._.js +6 -0
- package/.next/server/chunks/ssr/{_0a_pedm._.js → _0ktd2qg._.js} +2 -2
- package/.next/server/chunks/ssr/{_0bt2e10._.js → _0kvhn--._.js} +2 -2
- package/.next/server/chunks/ssr/_0poypri._.js +3 -0
- package/.next/server/chunks/ssr/_0tg3o37._.js +1 -1
- package/.next/server/chunks/ssr/_0y0ubpl._.js +85 -0
- package/.next/server/chunks/ssr/_11l9kc0._.js +1 -1
- package/.next/server/chunks/ssr/_12-hlgn._.js +3 -0
- package/.next/server/chunks/ssr/_12_ail7._.js +1 -1
- package/.next/server/chunks/ssr/_12n2oxe._.js +3 -0
- package/.next/server/chunks/ssr/_16_7zeo._.js +1 -1
- package/.next/server/chunks/ssr/_1a_w_du._.js +3 -0
- package/.next/server/chunks/ssr/_1bfrntd._.js +2 -2
- package/.next/server/chunks/ssr/_1e_9qjr._.js +3 -0
- package/.next/server/chunks/ssr/{_0kmldic._.js → _1gqjgsr._.js} +2 -2
- package/.next/server/chunks/ssr/_1kyjimg._.js +162 -0
- package/.next/server/chunks/ssr/_1l-3enz._.js +5 -5
- package/.next/server/chunks/ssr/_1neoj22._.js +1 -1
- package/.next/server/chunks/ssr/{_0x9f717._.js → _1odlery._.js} +2 -2
- package/.next/server/chunks/ssr/_1soynbw._.js +2 -2
- package/.next/server/chunks/ssr/components_ui_markdown-body_tsx_0eaiq36._.js +3 -0
- package/.next/server/chunks/ssr/features_ai_components_model-picker_tsx_0ucb1y9._.js +1 -1
- package/.next/server/chunks/ssr/features_bot_components_01ye2wp._.js +3 -0
- package/.next/server/chunks/ssr/features_bot_components_bot-setting_tsx_01ajft6._.js +4 -0
- package/.next/server/chunks/ssr/features_bot_components_thread-setting_tsx_0yae7zy._.js +3 -0
- package/.next/server/chunks/ssr/features_config_components_config-setting_tsx_0xfwqdg._.js +20 -0
- package/.next/server/chunks/ssr/features_connectors_components_mcp-setting_tsx_0jmbgvp._.js +1 -1
- package/.next/server/chunks/ssr/features_memory_components_memory-setting_tsx_0oa43sw._.js +1 -1
- package/.next/server/chunks/ssr/features_routine_components_routine-setting_tsx_055fknz._.js +1 -1
- package/.next/server/chunks/ssr/features_skills_components_skills-setting_tsx_1wtuuip._.js +3 -0
- package/.next/server/chunks/ssr/features_thursday_0tni574._.js +3 -0
- package/.next/server/chunks/ssr/features_thursday_components_thursday-setting_tsx_1_6ydrc._.js +3 -0
- package/.next/server/chunks/ssr/lib_date-like_ts_02is0pw._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_017gqu8._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_01alue6._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_01htpr-._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_01pxb8b._.js +26 -0
- package/.next/server/chunks/ssr/node_modules_01tm_tp._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_02n9-pb._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_02pi0yq._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_03-o46i._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0ir6p7s._.js → node_modules_04aag9b._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_04si41m._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_d3-scale_src_1tr1qwb._.js → node_modules_05-8wqp._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_063ofsn._.js +64 -0
- package/.next/server/chunks/ssr/node_modules_0794bsw._.js +20 -20
- package/.next/server/chunks/ssr/node_modules_09zjj0q._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0_aoyhl._.js +24 -0
- package/.next/server/chunks/ssr/node_modules_0_nsswh._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0_ps6bu._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_0y_k4h5._.js → node_modules_0bxpl07._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_0bz_arm._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0dxcji9._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0f5_pdq._.js +40 -0
- package/.next/server/chunks/ssr/node_modules_0fibdri._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0gtb11b._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0hlr1-8._.js +24 -0
- package/.next/server/chunks/ssr/{node_modules_111pp7w._.js → node_modules_0klo3i5._.js} +2 -2
- package/.next/server/chunks/ssr/{node_modules_0xht9wg._.js → node_modules_0koo_87._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_0kyd5t1._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0kzqz7r._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0lf6itx._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0pejed0._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0pf0mdn._.js +43 -0
- package/.next/server/chunks/ssr/node_modules_0q3wqo6._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0qw862r._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0rr5bhc._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0u1te_7._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0udp97e._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_0v47nij._.js +43 -0
- package/.next/server/chunks/ssr/node_modules_0x7tjjt._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_0xhtcgd._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_0ayoorn._.js → node_modules_0xon57z._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_0z1zutp._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_0z7xnqk._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_11bryw1._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_00mh9o-._.js → node_modules_13eo1xw._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_13udj58._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_15vxln6._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_15yal8y._.js +17 -0
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1ejf5ye._.js → node_modules_17q6-cb._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_17sis9w._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_19v9p62._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_19xlry2._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1afgbir._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_1asq18n._.js +29 -0
- package/.next/server/chunks/ssr/node_modules_1bo15xl._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1crkt86._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_04f_uw2._.js → node_modules_1fpm85j._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_1gkjtk-._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1hj50tu._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1hv0kyf._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1i5fr0j._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1k3cymo._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1ki78ma._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_07udd3z._.js → node_modules_1lrg_ju._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_1lt565w._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1oxvn1l._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1qgcqvi._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1r_497y._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1thrjjl._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_1tsuh_o._.js +17 -0
- package/.next/server/chunks/ssr/node_modules_1vhpjvn._.js +3 -0
- package/.next/server/chunks/ssr/{node_modules_1b5rxw5._.js → node_modules_1xpa_a4._.js} +2 -2
- package/.next/server/chunks/ssr/node_modules_1xtyj97._.js +26 -0
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_0dlpxwr._.js → node_modules_@mermaid-js_parser_dist_066fcep._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_0eji647._.js → node_modules_@mermaid-js_parser_dist_0_301m2._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_0lct0v1._.js → node_modules_@mermaid-js_parser_dist_0it10w8._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_13hksv_._.js → node_modules_@mermaid-js_parser_dist_0m-ahsg._.js} +1 -1
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_0n8rqkj._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_0nb4v-i._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_0tdjo9s._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_12betp4._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_1mu01rb._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_1xda76v._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_1z2f7i3._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_katex_dist_katex_mjs_0gtpcr6._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_katex_dist_katex_mjs_0o4db0q._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_0e5n4p5._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_chunk-Y2CYZVJY_mjs_20i4m4_._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_streamdown_dist_0lptw6m._.js +3 -0
- package/.next/server/chunks/ssr/node_modules_streamdown_dist_1-e49om._.js +3 -0
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +64 -64
- package/.next/static/chunks/{1ettmta9iet7b.js → 03_uoxripq3nc.js} +1 -1
- package/.next/static/chunks/{396enq-m0sss5.js → 0776-hu4_eek7.js} +2 -2
- package/.next/static/chunks/0akv-2v88qow0.js +1 -0
- package/.next/static/chunks/{1oh4hbusfz97l.js → 0rq_fqeaz_bvd.js} +1 -1
- package/.next/static/chunks/0zardk7icrprd.js +4 -0
- package/.next/static/chunks/17rnkwd0nvzhn.js +1 -0
- package/.next/static/chunks/{0fklfoj8o_msg.js → 1cmwusx1ey_yw.js} +1 -1
- package/.next/static/chunks/{1j4rndg17wgfk.js → 1grvc88py7u6u.js} +1 -1
- package/.next/static/chunks/1ob3lsnuwfj-n.js +70 -0
- package/.next/static/chunks/{411uyd0is9u5s.js → 1qmqv6cr2nr5g.js} +1 -1
- package/.next/static/chunks/1yrz0aw09rjij.js +1 -0
- package/.next/static/chunks/1z2_9pl3nezly.js +3 -0
- package/.next/static/chunks/{1mpz4epyg-7pz.js → 2-zwoj9evpp_d.js} +2 -2
- package/.next/static/chunks/{11c3uijgqik4m.js → 20w8bgikzj9nl.js} +1 -1
- package/.next/static/chunks/{2sxclirl-c-um.js → 2abjsec0elgbx.js} +1 -1
- package/.next/static/chunks/{3_deesw_pbmkd.js → 2fxn-xltgy2un.js} +1 -1
- package/.next/static/chunks/2hq0xxr8bwwjx.js +1 -0
- package/.next/static/chunks/2jf2ckv1t70es.js +1 -0
- package/.next/static/chunks/2k8ou_gpe91k1.js +1 -0
- package/.next/static/chunks/{2zhiqxw61qowv.js → 2vk1rx8_abchj.js} +1 -1
- package/.next/static/chunks/{22jb4s3-8ckup.js → 2vz587tsy9sw-.js} +1 -1
- package/.next/static/chunks/33qtnlc00c9gq.js +1 -0
- package/.next/static/chunks/34ih-rod1rypo.js +1 -0
- package/.next/static/chunks/{3uf32hp_g9stz.js → 399la1vg4mefu.js} +1 -1
- package/.next/static/chunks/3b8uta6_6no_3.css +1 -0
- package/.next/static/chunks/3eeapb56_2bu2.js +2 -0
- package/.next/static/chunks/{081kl7k8r6f8z.js → 3h29tl1whfjs2.js} +1 -1
- package/.next/static/chunks/3l4m3_ojnhbav.js +1 -0
- package/.next/static/chunks/3pia1ryvrhyfr.js +1 -0
- package/.next/static/chunks/3qzf68zb5zlh8.js +1 -0
- package/.next/static/chunks/{3ph9u-51x6jhe.js → 3w6r10nihrl3l.js} +5 -5
- package/.next/static/chunks/3xloayc4c096r.js +1 -0
- package/README.md +10 -1
- package/guide/bots.md +35 -26
- package/node_modules/@types/ws/README.md +1 -1
- package/node_modules/@types/ws/index.d.mts +4 -0
- package/node_modules/@types/ws/index.d.ts +4 -0
- package/node_modules/@types/ws/package.json +3 -3
- package/package.json +2 -2
- package/.next/server/chunks/_1fn6cvh._.js +0 -3
- package/.next/server/chunks/_1jtvbp9._.js +0 -76
- package/.next/server/chunks/node_modules_@ai-sdk_1o5ydf6._.js +0 -26
- package/.next/server/chunks/ssr/[root-of-the-server]__0jjj49d._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__1qn0axo._.js +0 -6
- package/.next/server/chunks/ssr/[root-of-the-server]__1u42eh0._.js +0 -3
- package/.next/server/chunks/ssr/_0-s7ria._.js +0 -3
- package/.next/server/chunks/ssr/_088qe9a._.js +0 -162
- package/.next/server/chunks/ssr/_0ali_i8._.js +0 -3
- package/.next/server/chunks/ssr/_0flnog5._.js +0 -3
- package/.next/server/chunks/ssr/_0iuvjnw._.js +0 -3
- package/.next/server/chunks/ssr/_0k-gl8l._.js +0 -3
- package/.next/server/chunks/ssr/_0ks03l-._.js +0 -3
- package/.next/server/chunks/ssr/_0mng-y8._.js +0 -6
- package/.next/server/chunks/ssr/_0ugzm_0._.js +0 -3
- package/.next/server/chunks/ssr/_0wnv6c0._.js +0 -3
- package/.next/server/chunks/ssr/_0z9zkd-._.js +0 -3
- package/.next/server/chunks/ssr/_123y-ah._.js +0 -3
- package/.next/server/chunks/ssr/_14j205q._.js +0 -85
- package/.next/server/chunks/ssr/_16wjbs2._.js +0 -3
- package/.next/server/chunks/ssr/_18rmqqu._.js +0 -3
- package/.next/server/chunks/ssr/_1ckje8g._.js +0 -3
- package/.next/server/chunks/ssr/_1h3qetc._.js +0 -3
- package/.next/server/chunks/ssr/_1kpvfmn._.js +0 -4
- package/.next/server/chunks/ssr/_1pkw8wf._.js +0 -85
- package/.next/server/chunks/ssr/_1xwtbdz._.js +0 -3
- package/.next/server/chunks/ssr/features_bot_0-7flc-._.js +0 -3
- package/.next/server/chunks/ssr/features_config_10xs4l1._.js +0 -20
- package/.next/server/chunks/ssr/features_thursday_0cf9y0b._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_04f6p6a._.js +0 -24
- package/.next/server/chunks/ssr/node_modules_08-pj-2._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_098h6h5._.js +0 -29
- package/.next/server/chunks/ssr/node_modules_0_7yfem._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0bp3vfu._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0ch5hqr._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0e-hyim._.js +0 -64
- package/.next/server/chunks/ssr/node_modules_0ffm9w3._.js +0 -26
- package/.next/server/chunks/ssr/node_modules_0il0v7d._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0jzyuwk._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0ln4iwf._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0my2hph._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_0ql0igl._.js +0 -17
- package/.next/server/chunks/ssr/node_modules_0qwth-_._.js +0 -17
- package/.next/server/chunks/ssr/node_modules_0y9byl5._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_10bzndo._.js +0 -43
- package/.next/server/chunks/ssr/node_modules_19f7b4c._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1b_h09q._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1e83j9e._.js +0 -26
- package/.next/server/chunks/ssr/node_modules_1e9ugfy._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1hd66k0._.js +0 -64
- package/.next/server/chunks/ssr/node_modules_1inwr2m._.js +0 -43
- package/.next/server/chunks/ssr/node_modules_1j9xx1k._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1k8kypa._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1oeu85h._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1r2ghv5._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_1rg7lj4._.js +0 -40
- package/.next/server/chunks/ssr/node_modules_1ttpnib._.js +0 -29
- package/.next/server/chunks/ssr/node_modules_201yvda._.js +0 -17
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_17wxxyr._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_18pinup._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_1feyqvf._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_1ok0411._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_@mermaid-js_parser_dist_1sgfrma._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_d3-shape_src_arc_1-w13bo.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_0jkhu0x._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_0thh8pk._.js +0 -17
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_1o1kg4c._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_1rxlz7e._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_1turj0n._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_1v463pe._.js +0 -17
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_chunk-5VM5RSS4_mjs_0tg6kya._.js +0 -17
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_chunk-F27PBJKO_mjs_0ms0zmb._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_dagre-GXQ25YYZ_mjs_0k_lz8d._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_mermaid_dist_chunks_mermaid_core_sizeCapture-INFHLROL_mjs_179zv_p._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_streamdown_dist_highlighted-body-KPVGNVTW_1fnf894.js +0 -3
- package/.next/server/chunks/ssr/node_modules_streamdown_dist_mermaid-HWGCJPDP_093xi20.js +0 -3
- package/.next/static/chunks/02lze_e5sagjn.js +0 -1
- package/.next/static/chunks/0ve2gb0hw3wkq.js +0 -1
- package/.next/static/chunks/16np6727e61io.js +0 -1
- package/.next/static/chunks/18amidjlaqexf.js +0 -1
- package/.next/static/chunks/1u4jowlgjgeip.js +0 -70
- package/.next/static/chunks/236le5kv_yj6a.css +0 -1
- package/.next/static/chunks/24op50z6sqi_5.js +0 -1
- package/.next/static/chunks/2eczs-lporqt6.js +0 -1
- package/.next/static/chunks/2z4sodeldj_86.js +0 -1
- package/.next/static/chunks/3ezjz93yvzmop.js +0 -4
- package/.next/static/chunks/3h6rqjx92wva9.js +0 -1
- package/.next/static/chunks/3w7zt3xzyjn86.js +0 -3
- package/.next/static/chunks/3xkx7vqefm7on.js +0 -2
- package/.next/static/chunks/3ygk41pgsw7nv.js +0 -1
- package/.next/static/chunks/4384atd5zerir.js +0 -1
- /package/.next/static/{6tIYlzfG_5P4sIxxgmucO → WKQCaSVcySHM4bjkWJXEH}/_buildManifest.js +0 -0
- /package/.next/static/{6tIYlzfG_5P4sIxxgmucO → WKQCaSVcySHM4bjkWJXEH}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{6tIYlzfG_5P4sIxxgmucO → WKQCaSVcySHM4bjkWJXEH}/_ssgManifest.js +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[105303,e=>e.a(async(t,r)=>{try{var o,n=e.i(361164),i=e.i(958560),s=e.i(687388),a=e.i(640911),l=e.i(41444),c=e.i(148831),u=e.i(441963),p=t([c]);[c]=p.then?(await p)():p;class h extends Error{serverName;authorizationUrl;constructor(e,t){super(`MCP server "${e}" requires authorization`),this.serverName=e,this.authorizationUrl=t,this.name="McpAuthRequiredError"}}class d{store;serverName;oauth;callbackUrl;clientName;lastAuthorizationUrl;constructor(e,t,r,o,n){this.store=e,this.serverName=t,this.oauth=r,this.callbackUrl=o,this.clientName=n}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(e){this.oauth={...this.oauth,...e},await this.store.saveOAuth(this.serverName,this.oauth)}clientInformation(){return this.oauth.clientInformation}async saveClientInformation(e){await this.persist({clientInformation:e})}tokens(){return this.oauth.tokens}async saveTokens(e){await this.persist({tokens:e})}authorizationServerInformation(){return this.oauth.authorizationServer}async saveAuthorizationServerInformation(e){await this.persist({authorizationServer:e})}codeVerifier(){if(!this.oauth.codeVerifier)throw Error("No code verifier saved");return this.oauth.codeVerifier}async saveCodeVerifier(e){await this.persist({codeVerifier:e})}state(){return crypto.randomUUID()}async saveState(e){await this.persist({state:e})}storedState(){return this.oauth.state}redirectToAuthorization(e){this.lastAuthorizationUrl=e}async invalidateCredentials(e){let t={...this.oauth};("all"===e||"client"===e)&&(t.clientInformation=void 0),("all"===e||"tokens"===e)&&(t.tokens=void 0),("all"===e||"verifier"===e)&&(t.codeVerifier=void 0),this.oauth=t,await this.store.saveOAuth(this.serverName,t)}}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 e{store;sessions;connecting;callbackUrl;clientName;constructor(e,t){this.store=e,this.sessions=new Map,this.connecting=new Map,this.callbackUrl=t.callbackUrl,this.clientName=t.clientName??s.APP_NAME}async connect(e){let t=this.connecting.get(e);if(t)return t;let r=this.doConnect(e).finally(()=>this.connecting.delete(e));return this.connecting.set(e,r),r}async callTool(e,t,r,o){let i=await this.ensureClient(e);try{let n=await i.callTool({name:t,arguments:r,options:o?{signal:o}:void 0});return this.touch(e),n}catch(t){if(t instanceof n.UnauthorizedError)throw await this.closeSession(e),new h(e);throw t}}async finishAuthorization(e){let t=e.get("state"),r=e.get("code");if(!t||!r)throw Error("OAuth callback is missing code or state");let o=await this.store.findByOAuthState(t);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:t});if("AUTHORIZED"!==s)throw Error(`Token exchange ended in "${s}"`);return await i.invalidateCredentials("verifier"),await this.connect(o.name),o.name}async disconnect(e){await this.closeSession(e)}async dispose(){await Promise.all([...this.sessions.keys()].map(e=>this.closeSession(e)))}async doConnect(e){await this.closeSession(e);let t=await this.store.load(e);if(!t)throw Error(`Unknown MCP server "${e}"`);let r={};try{let o=await this.openClient(t,r),n=(await o.listTools()).tools.map(e=>({name:e.name,description:e.description,inputSchema:e.inputSchema,outputSchema:e.outputSchema}));return this.adopt(e,o),await this.store.saveConnectionResult(e,{toolInfo:n,lastError:null}),a.logger.info(`mcp "${e}" 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 t=r.href;if(t)return await this.store.saveConnectionResult(e,{toolInfo:[],lastError:"Authorization required — finish sign-in in the opened tab"}),{status:"auth_required",authorizationUrl:t}}let c=(o=p,i=t,s=(0,l.errorToString)(o),(0,u.isRemoteConfig)(i.config)&&!i.oauth?.clientInformation&&/Invalid OAuth error response/.test(s)?`This server does not let an app register itself for sign-in, so it cannot be connected here. It answered: ${s}`:s);throw await this.store.saveConnectionResult(e,{toolInfo:[],lastError:c}),a.logger.warn(`mcp "${e}" failed — ${c}`),Error(c,{cause:p})}}async openClient(e,t={}){if((0,u.isRemoteConfig)(e.config)){let r=this.providerFor(e);try{return await (0,n.createMCPClient)({name:this.clientName,transport:{type:"http",url:e.config.url,headers:e.config.headers,authProvider:r,redirect:"follow"}})}finally{t.href=r.lastAuthorizationUrl?.href}}return(0,n.createMCPClient)({name:this.clientName,transport:new i.Experimental_StdioMCPTransport({command:e.config.command,args:e.config.args,env:e.config.env})})}providerFor(e){return new d(this.store,e.name,e.oauth??{},this.callbackUrl,this.clientName)}async ensureClient(e){let t=this.sessions.get(e);if(t)return t.client;let r=await this.connect(e);if("auth_required"===r.status)throw new h(e,r.authorizationUrl);let o=this.sessions.get(e);if(!o)throw Error(`Session for "${e}" vanished mid-connect`);return o.client}adopt(e,t){this.sessions.set(e,{client:t,idleTimer:this.armIdleTimer(e)})}touch(e){let t=this.sessions.get(e);t&&(clearTimeout(t.idleTimer),t.idleTimer=this.armIdleTimer(e))}armIdleTimer(e){let t=setTimeout(()=>{this.closeSession(e)},s.MCP_IDLE_MS);return t.unref?.(),t}async closeSession(e){let t=this.sessions.get(e);t&&(this.sessions.delete(e),clearTimeout(t.idleTimer),await t.client.close().catch(()=>{}))}}({load:e=>(0,c.findServer)(e),saveOAuth:(e,t)=>(0,c.saveOAuthData)(e,t),saveConnectionResult:(e,t)=>null===t.lastError?(0,c.syncServerTools)(e,t.toolInfo):(0,c.saveConnectionError)(e,t.lastError),findByOAuthState:e=>(0,c.findServerByOAuthState)(e)},o);let f=m.__thursdayMcpManager;e.s(["McpAuthRequiredError",0,h,"mcpManager",0,f]),r()}catch(e){r(e)}},!1),361164,e=>{"use strict";let t;var r,o,n,i,s=e.i(847841),a=e.i(469719),l=e.i(376261),c=e.i(36040);async function u(e){return(await t).getRandomValues(new Uint8Array(e))}async function p(e){let t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~",r=256-256%t.length,o="";for(;o.length<e;)for(let n of(await u(e-o.length)))n<r&&(o+=t[n%t.length]);return o}async function h(e){return await p(e)}async function d(e){return btoa(String.fromCharCode(...new Uint8Array(await (await t).subtle.digest("SHA-256",new TextEncoder().encode(e))))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}async function m(e){if(e||(e=43),e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;let t=await h(e),r=await d(t);return{code_verifier:t,code_challenge:r}}t=globalThis.crypto?.webcrypto??globalThis.crypto??e.A(70729).then(e=>e.webcrypto);var f=e.i(907855),z="2026-07-28",g="2025-11-25",w=[z,g,"2025-06-18","2025-03-26","2024-11-05"],y=a.z.optional(a.z.record(a.z.string(),a.z.unknown())),b=a.z.looseObject({name:a.z.string(),version:a.z.string(),title:a.z.optional(a.z.string())}),v=a.z.looseObject({_meta:a.z.optional(a.z.object({}).loose())}),_=v.extend({resultType:a.z.optional(a.z.string())}),E=a.z.object({method:a.z.string(),params:a.z.optional(v)}),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")]))}),P=_.extend({protocolVersion:a.z.string(),capabilities:C,serverInfo:b,instructions:a.z.optional(a.z.string())}),x=_.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:y}).loose(),I=x.extend({tools:a.z.array(R)}),k=a.z.object({type:a.z.literal("text"),text:a.z.string()}).loose(),A=a.z.object({type:a.z.literal("image"),data:a.z.base64(),mimeType:a.z.string()}).loose(),j=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=x.extend({resources:a.z.array(j)}),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(),L=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(),N=a.z.object({type:a.z.string()}).loose().refine(e=>!["text","image","resource","resource_link"].includes(e.type),{message:"Known content types must match their schema"}),V=_.extend({content:a.z.array(a.z.union([k,A,H,L,N])),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(e=>({...e,content:[{type:"text",text:JSON.stringify(e.structuredContent)}]})).pipe(V),D=V.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();v.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=x.extend({prompts:a.z.array(X)}),ee=a.z.object({role:a.z.union([a.z.literal("user"),a.z.literal("assistant")]),content:a.z.union([k,A,H,L])}).loose(),et=_.extend({description:a.z.optional(a.z.string()),messages:a.z.array(ee)}),er=v.extend({message:a.z.string(),requestedSchema:a.z.unknown()}),eo=E.extend({method:a.z.literal("elicitation/create"),params:er}),en=_.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()))}),ei=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.union([a.z.string(),a.z.number().int()])}).merge(E).strict(),es=a.z.object({jsonrpc:a.z.literal("2.0"),id:a.z.union([a.z.string(),a.z.number().int()]),result:_}).strict(),ea=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(),el=a.z.object({jsonrpc:a.z.literal("2.0")}).merge(a.z.object({method:a.z.string(),params:a.z.optional(v)})).strict(),ec=a.z.union([ei,el,es,ea]);function eu(e){return ec.parse(e)}async function ep(e){return eu(await (0,s.parseJSON)({text:e}))}var eh="vercel.ai.error.AI_MCPClientError",ed=Symbol.for(eh),em=class extends(o=l.AISDKError,r=ed,o){constructor({name:e="MCPClientError",message:t,cause:o,data:n,code:i,statusCode:s,url:a,responseBody:l}){super({name:e,message:t,cause:o}),this[r]=!0,this.data=n,this.code=i,this.statusCode=s,this.url=a,this.responseBody=l}static isInstance(e){return l.AISDKError.hasMarker(e,eh)}},ef="u">typeof __PACKAGE_VERSION__?__PACKAGE_VERSION__:"0.0.0-test",ez=a.z.string().url().superRefine((e,t)=>{if(!URL.canParse(e))return t.addIssue({code:a.z.ZodIssueCode.custom,message:"URL must be parseable",fatal:!0}),a.z.NEVER}).refine(e=>{let t=new URL(e);return"javascript:"!==t.protocol&&"data:"!==t.protocol&&"vbscript:"!==t.protocol},{message:"URL cannot use javascript:, data:, or vbscript: scheme"}),eg=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:ez.optional(),authorization_server:ez.optional(),token_endpoint:ez.optional()}).strip(),ew=a.z.looseObject({resource:a.z.string().url(),authorization_servers:a.z.array(ez).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()}),ey=a.z.looseObject({issuer:a.z.string(),authorization_endpoint:ez,token_endpoint:ez,registration_endpoint:ez.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()}),eb=a.z.looseObject({issuer:a.z.string(),authorization_endpoint:ez,token_endpoint:ez,userinfo_endpoint:ez.optional(),jwks_uri:ez,registration_endpoint:ez.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(ey.pick({code_challenge_methods_supported:!0})),ev=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:ez.optional(),authorization_server:ez.optional(),token_endpoint:ez.optional()}).strip(),e_=a.z.object({redirect_uris:a.z.array(ez),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:ez.optional(),logo_uri:ez.optional(),scope:a.z.string().optional(),contacts:a.z.array(a.z.string()).optional(),tos_uri:ez.optional(),policy_uri:a.z.string().optional(),jwks_uri:ez.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(),eE=a.z.object({error:a.z.string(),error_description:a.z.string().optional(),error_uri:a.z.string().optional()}),eS=e_.merge(ev),eC="vercel.ai.error.AI_MCPClientOAuthError",eT=Symbol.for(eC),eP=class extends(i=l.AISDKError,n=eT,i){constructor({name:e="MCPClientOAuthError",message:t,cause:r}){super({name:e,message:t,cause:r}),this[n]=!0}static isInstance(e){return l.AISDKError.hasMarker(e,eC)}},ex=class extends eP{static{this.errorCode="server_error"}},eR=class extends eP{static{this.errorCode="invalid_client"}},eI=class extends eP{static{this.errorCode="invalid_grant"}},ek=class extends eP{static{this.errorCode="unauthorized_client"}},eA={[ex.errorCode]:ex,[eR.errorCode]:eR,[eI.errorCode]:eI,[ek.errorCode]:ek};function ej(e){let t=e.href;return"/"===e.pathname&&t.endsWith("/")?t.slice(0,-1):t}var eU=class extends Error{constructor(e="Unauthorized"){super(e),this.name="UnauthorizedError"}};function eO(e){return new URL(e).href}function eM(e){let t=e.toLowerCase().replace(/\.+$/,"");return"localhost"===t||t.endsWith(".localhost")||"127.0.0.1"===t||"[::1]"===t||"::1"===t}function e$(e,{allowLoopback:t=!1}={}){if(!(t&&("http:"===e.protocol||"https:"===e.protocol)&&eM(e.hostname)))try{(0,s.validateDownloadUrl)(e.href)}catch(t){throw new eP({message:`OAuth endpoint URL is not allowed: ${e.href}`,cause:t})}}function eH(e){let t=new URL(e);return eM(t.hostname)?t.origin:void 0}function eL(e,t){return{...e,issuer:t.issuer,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function eN(e,t){return{...e,issuer:t.issuer,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function eV(e){if(e?.authorization_server&&e.token_endpoint)return{issuer:e.issuer,authorizationServerUrl:eO(e.authorization_server),tokenEndpoint:eO(e.token_endpoint)}}async function eq({provider:e,clientInformation:t,tokens:r}){let o=eV(r);if(o)return o;let n=await e.authorizationServerInformation?.();return n?{issuer:n.issuer,authorizationServerUrl:eO(n.authorizationServerUrl),tokenEndpoint:eO(n.tokenEndpoint)}:eV(t)}async function eD({provider:e,clientInformation:t,authorizationServerInformation:r}){return e.saveAuthorizationServerInformation?(await e.saveAuthorizationServerInformation(r),!0):!!e.saveClientInformation&&(await e.saveClientInformation(eN(t,r)),!0)}function eF({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:t}){if(null!=e.issuer&&null!=t.issuer&&e.issuer!==t.issuer||e.authorizationServerUrl!==t.authorizationServerUrl||e.tokenEndpoint!==t.tokenEndpoint)throw new eP({message:"OAuth authorization server metadata does not match the metadata that issued the stored credentials"})}function eB(e){let t,r=e.headers.get("www-authenticate")??e.headers.get("WWW-Authenticate");if(!r)return{};let[o,n]=r.split(" ");if("bearer"!==o.toLowerCase()||!n)return{};let i=r.match(/(?:^|[,\s])resource_metadata="([^"]*)"/i),s=r.match(/(?:^|[,\s])scope="([^"]*)"/i)?.[1];try{t=i?new URL(i[1]):void 0}catch{}return{resourceMetadataUrl:t,scope:s}}async function eW(e,t,r=fetch,o){try{return await (0,s.fetchUntrustedUrl)({url:e.href,fetch:async(e,n)=>(0,s.fetchWithValidatedEndpoint)({url:e,init:{...n,headers:new Headers(n?.headers).has("MCP-Protocol-Version")?t:void 0},fetch:r,trustedOrigin:o,redirect:"manual"}),headers:t,trustedOrigin:o,untrustedFirstHopHeaders:["mcp-protocol-version"]})}catch(n){if(n instanceof TypeError)if(t)return eW(e,void 0,r,o);else return;throw n}}async function eJ(e,t,r=fetch,o){return await eW(e,{"MCP-Protocol-Version":t},r,o)}async function eK(e,t,r,o){var n,i;let s,a=new URL(e),l=o?.protocolVersion??z;o?.metadataUrl?s=new URL(o.metadataUrl):(s=new URL(function(e,t="",r={}){return t.endsWith("/")&&(t=t.slice(0,-1)),r.prependPathname?`${t}/.well-known/${e}`:`/.well-known/${e}${t}`}(t,a.pathname),o?.metadataServerUrl??a)).search=a.search;let c=await eJ(s,l,r,o?.trustedOrigin);if(!o?.metadataUrl&&(n=c,i=a.pathname,!n||n.status>=400&&n.status<500&&"/"!==i)){let e=new URL(`/.well-known/${t}`,a);c=await eJ(e,l,r,o?.trustedOrigin)}return c}async function eZ(e,t,r=fetch){let o=await eK(e,"oauth-protected-resource",r,{protocolVersion:t?.protocolVersion,metadataUrl:t?.resourceMetadataUrl,trustedOrigin:new URL(e).origin});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 ew.parse(await o.json())}function eG(e,t){if(e.issuer!==t&&(t!==new URL(t).origin||e.issuer!==`${t}/`))throw new eP({message:`OAuth authorization server metadata issuer ${e.issuer} does not match expected issuer ${t}`})}async function eY(e,{fetchFn:t=fetch,protocolVersion:r=z,trustedOrigin:o}={}){let n={"MCP-Protocol-Version":r};for(let{url:r,type:i,expectedIssuer:s}of function(e){let t="string"==typeof e?new URL(e):e,r="/"!==t.pathname,o=t.origin,n=[];if(!r)return n.push({url:new URL("/.well-known/oauth-authorization-server",t.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL("/.well-known/openid-configuration",t.origin),type:"oidc",expectedIssuer:o}),n;let i=t.pathname;i.endsWith("/")&&(i=i.slice(0,-1));let s=`${t.origin}${i}`;return n.push({url:new URL(`/.well-known/oauth-authorization-server${i}`,t.origin),type:"oauth",expectedIssuer:s}),n.push({url:new URL("/.well-known/oauth-authorization-server",t.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL(`/.well-known/openid-configuration${i}`,t.origin),type:"oidc",expectedIssuer:s}),n.push({url:new URL(`${i}/.well-known/openid-configuration`,t.origin),type:"oidc",expectedIssuer:s}),n}(e)){let e=await eW(r,n,t,o);if(e){if(!e.ok){if(e.status>=400&&e.status<500)continue;throw Error(`HTTP ${e.status} trying to load ${"oauth"===i?"OAuth":"OpenID provider"} metadata from ${r}`)}if("oauth"===i){let t=ey.parse(await e.json());return eG(t,s),t}{let t=eb.parse(await e.json());if(eG(t,s),!t.code_challenge_methods_supported?.includes("S256"))throw Error(`Incompatible OIDC provider at ${r}: does not support S256 code challenge method required by MCP specification`);return t}}}}async function eX(e,{metadata:t,clientInformation:r,redirectUrl:o,scope:n,state:i,resource:s}){let a,l="code",c="S256";if(t){if(a=new URL(t.authorization_endpoint),!t.response_types_supported.includes(l))throw Error(`Incompatible auth server: does not support response type ${l}`);if(!t.code_challenge_methods_supported||!t.code_challenge_methods_supported.includes(c))throw Error(`Incompatible auth server: does not support code challenge method ${c}`)}else a=new URL("/authorize",e);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),n?.includes("offline_access")&&a.searchParams.append("prompt","consent"),s&&a.searchParams.set("resource",ej(s)),{authorizationUrl:a,codeVerifier:p}}function eQ(e,t){let r=void 0!==e.client_secret;return 0===t.length?r?"client_secret_post":"none":r&&t.includes("client_secret_basic")?"client_secret_basic":r&&t.includes("client_secret_post")?"client_secret_post":t.includes("none")?"none":r?"client_secret_post":"none"}function e0(e,t,r,o){let{client_id:n,client_secret:i}=t;switch(e){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: ${e}`)}}async function e1(e){let t=e instanceof Response?e.status:void 0,r=e instanceof Response?await e.text():e;try{let{error:e,error_description:t,error_uri:o}=eE.parse(await (0,s.parseJSON)({text:r}));return new(eA[e]||ex)({message:t||"",cause:o})}catch(e){return new ex({message:`${t?`HTTP ${t}: `:""}Invalid OAuth error response: ${e}. Raw body: ${r}`})}}async function e2(e,{metadata:t,clientInformation:r,authorizationCode:o,codeVerifier:n,redirectUri:i,resource:a,addClientAuthentication:l,fetchFn:c}){let u="authorization_code",p=t?.token_endpoint?new URL(t.token_endpoint):new URL("/token",e),h=eH(e);if(e$(p,{allowLoopback:p.origin===h}),t?.grant_types_supported&&!t.grant_types_supported.includes(u))throw Error(`Incompatible auth server: does not support grant type ${u}`);let d=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),m=new URLSearchParams({grant_type:u,code:o,code_verifier:n,redirect_uri:String(i)});l?await l(d,m,e,t):e0(eQ(r,t?.token_endpoint_auth_methods_supported??[]),r,d,m),a&&m.set("resource",ej(a));let f=await (0,s.fetchWithValidatedEndpoint)({url:p,init:{method:"POST",headers:d,body:m},fetch:c,trustedOrigin:h});if(!f.ok)throw await e1(f);return eg.parse(await f.json())}async function e4(e,{metadata:t,clientInformation:r,refreshToken:o,resource:n,addClientAuthentication:i,fetchFn:a}){let l,c="refresh_token";if(t){if(l=new URL(t.token_endpoint),t.grant_types_supported&&!t.grant_types_supported.includes(c))throw Error(`Incompatible auth server: does not support grant type ${c}`)}else l=new URL("/token",e);let u=eH(e);e$(l,{allowLoopback:l.origin===u});let p=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),h=new URLSearchParams({grant_type:c,refresh_token:o});i?await i(p,h,e,t):e0(eQ(r,t?.token_endpoint_auth_methods_supported??[]),r,p,h),n&&h.set("resource",ej(n));let d=await (0,s.fetchWithValidatedEndpoint)({url:l,init:{method:"POST",headers:p,body:h},fetch:a,trustedOrigin:u});if(!d.ok)throw await e1(d);return eg.parse({refresh_token:o,...await d.json()})}async function e3(e,{metadata:t,clientMetadata:r,fetchFn:o}){let n;if(t){if(!t.registration_endpoint)throw Error("Incompatible auth server: does not support dynamic client registration");n=new URL(t.registration_endpoint)}else n=new URL("/register",e);let i=eH(e);e$(n,{allowLoopback:n.origin===i});let a=r.application_type??(r.redirect_uris.every(e=>{let t=new URL(e);return("http:"===t.protocol||"https:"===t.protocol)&&eM(t.hostname)||"http:"!==t.protocol&&"https:"!==t.protocol})?"native":"web"),l=await (0,s.fetchWithValidatedEndpoint)({url:n,init:{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,application_type:a})},fetch:o,trustedOrigin:i});if(!l.ok)throw await e1(l);return eS.parse(await l.json())}async function e5(e,t){try{return await e8(e,t)}catch(r){if(r instanceof eR||r instanceof ek){if(void 0!==t.authorizationCode||!await e.isClientInformationDynamicallyRegistered?.())throw r;return await e.invalidateCredentials?.("all"),await e8(e,t)}if(r instanceof eI)return await e.invalidateCredentials?.("tokens"),await e8(e,t);throw r}}async function e6(e,t,r){let o,n=((o=new URL("string"==typeof e?e:e.href)).hash="",o);if(t.validateResourceURL)return await t.validateResourceURL(n,r?.resource);if(r){if(!function({requestedResource:e,configuredResource:t}){let r=new URL("string"==typeof e?e:e.href),o=new URL("string"==typeof t?t:t.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 e8(e,{serverUrl:t,authorizationCode:r,callbackState:o,callbackIssuer:n,scope:i,resourceMetadataUrl:s,fetchFn:a}){var l;let c,u,p,h;!function(e,t){if(!t)return;let r=new URL(e).origin;if(t.origin!==r)throw new eP({message:`OAuth protected resource metadata URL ${t.href} must have the same origin as the MCP server URL ${r}`})}(t,s);try{(c=await eZ(t,{resourceMetadataUrl:s},a)).authorization_servers&&c.authorization_servers.length>0&&(u=c.authorization_servers[0])}catch{}void 0!==r&&(p=await Promise.resolve(e.clientInformation()))&&(h=await eq({provider:e,clientInformation:p})),u||(u=h?.authorizationServerUrl??t);let d=new URL(t),m=new URL(u),f=d.origin,z=m.origin,g=z===f||eM(d.hostname)&&eM(m.hostname)?z:void 0;g||e$(new URL(u));let w=await e6(t,e,c);await e.validateAuthorizationServerURL?.(t,u);let y=await eY(u,{fetchFn:a,trustedOrigin:g}),b=(l=u,{issuer:y?.issuer??String(l),authorizationServerUrl:eO(l),tokenEndpoint:eO(y?.token_endpoint?new URL(y.token_endpoint):new URL("/token",l))}),v=e.clientMetadata,_=function({scope:e,resourceMetadata:t,clientMetadata:r}){if(e)return e;let o=t?.scopes_supported?.join(" ");return o||r.scope}({scope:i,resourceMetadata:c,clientMetadata:v});if(void 0===r&&(p=await Promise.resolve(e.clientInformation())),p?.issuer!=null){let t=h??await eq({provider:e,clientInformation:p});t&&eF({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:b})}if(!p){if(void 0!==r)throw Error("Existing OAuth client information is required when exchanging an authorization code");if(!e.saveClientInformation)throw Error("OAuth client information must be saveable for dynamic registration");p=eN(await e3(u,{metadata:y,clientMetadata:{...v,scope:_},fetchFn:a}),b),await e.saveClientInformation(p)}if(void 0!==r){if(e.storedState){let t=await e.storedState();if(void 0!==t&&t!==o)throw Error("OAuth state parameter mismatch - possible CSRF attack")}let t=h??await eq({provider:e,clientInformation:p});if(!t)throw new eP({message:"Stored OAuth authorization server metadata is required when exchanging an authorization code"});!function({callbackIssuer:e,expectedIssuer:t}){if(null!=e&&e!==t)throw new eP({message:`OAuth authorization response issuer ${e} does not match expected issuer ${t}`})}({callbackIssuer:n,expectedIssuer:t.issuer??y?.issuer??String(u)}),eF({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:b});let i=await e.codeVerifier(),s=await e2(u,{metadata:y,clientInformation:p,authorizationCode:r,codeVerifier:i,redirectUri:e.redirectUrl,resource:w,addClientAuthentication:e.addClientAuthentication,fetchFn:a});return await e.saveTokens(eL(s,b)),"AUTHORIZED"}let E=await e.tokens();if(E?.refresh_token){let t=await eq({provider:e,clientInformation:p,tokens:E});t?eF({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:b}):await e.invalidateCredentials?.("tokens");try{if(t){let t=await e4(u,{metadata:y,clientInformation:p,refreshToken:E.refresh_token,resource:w,addClientAuthentication:e.addClientAuthentication,fetchFn:a});return await e.saveTokens(eL(t,b)),"AUTHORIZED"}}catch(e){if(!(e instanceof eP)||e instanceof ex);else throw e}}let S=e.state?await e.state():void 0;S&&e.saveState&&await e.saveState(S);let{authorizationUrl:C,codeVerifier:T}=await eX(u,{metadata:y,clientInformation:p,state:S,redirectUrl:e.redirectUrl,scope:_,resource:w});if(!await eD({provider:e,clientInformation:p,authorizationServerInformation:b}))throw new eP({message:"OAuth authorization server metadata must be saveable before starting authorization"});return await e.saveCodeVerifier(T),await e.redirectToAuthorization(C),"REDIRECT"}var e7=class{constructor({url:e,headers:t,authProvider:r,redirect:o="error",fetch:n}){this.connected=!1,this.url=new URL(e),this.headers=t,this.authProvider=r,this.redirectMode=o,this.fetchFn=n??globalThis.fetch}setProtocolVersion(e){this.protocolVersion=e}async commonHeaders(e){let t={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??g};if(this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(t.Authorization=`Bearer ${e.access_token}`)}return(0,s.withUserAgentSuffix)(t,`ai-sdk/${ef}`,(0,s.getRuntimeEnvironmentUserAgent)())}authorizeOnce(e,t){return this.authProvider?(this.authPromise||(this.authPromise=e5(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:e,scope:t,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0})),this.authPromise):Promise.resolve("REDIRECT")}async accessTokenChanged(e){let t=(await this.authProvider?.tokens())?.access_token;return null!=t&&e!==`Bearer ${t}`}async start(){return new Promise((e,t)=>{if(this.connected)return e();this.abortController=new AbortController;let r=async(o=!1)=>{try{let n=await this.commonHeaders({Accept:"text/event-stream"}),i=await this.fetchFn(this.url.href,{headers:n,signal:this.abortController?.signal,redirect:this.redirectMode});if(401===i.status&&this.authProvider&&!o){let{resourceMetadataUrl:e,scope:o}=eB(i);this.resourceMetadataUrl=e;try{let e=await this.authorizeOnce(this.resourceMetadataUrl,o);if("AUTHORIZED"!==e){let e=new eU;return this.onerror?.(e),t(e)}}catch(e){return this.onerror?.(e),t(e)}return r(!0)}if(!i.ok||!i.body){let e=`MCP SSE Transport Error: ${i.status} ${i.statusText}`;405===i.status&&(e+=". This server does not support SSE transport. Try using `http` transport instead");let r=new em({message:e});return this.onerror?.(r),t(r)}let s=i.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader(),a=async()=>{try{for(;;){let{done:t,value:r}=await s.read();if(t){if(this.connected)throw this.connected=!1,new em({message:"MCP SSE Transport Error: Connection closed unexpectedly"});return}let{event:o,data:n}=r;if("endpoint"===o){if(this.endpoint)continue;let t=new URL(n,this.url);if(t.origin!==this.url.origin)throw this.connected=!1,this.endpoint=void 0,this.sseConnection?.close(),this.abortController?.abort(),new em({message:`MCP SSE Transport Error: Endpoint origin does not match connection origin: ${t.origin}`});this.endpoint=t,this.connected=!0,e()}else if(void 0===o||"message"===o)try{let e=await ep(n);this.onmessage?.(e)}catch(t){let e=new em({message:"MCP SSE Transport Error: Failed to parse message",cause:t});this.onerror?.(e)}}}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),t(e)}};this.sseConnection={close:()=>s.cancel()},a()}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),t(e)}};r()})}async close(){this.connected=!1,this.endpoint=void 0,this.sseConnection?.close(),this.abortController?.abort(),this.onclose?.()}async send(e,t){if(t?.signal?.throwIfAborted(),!this.endpoint||!this.connected)throw new em({message:"MCP SSE Transport Error: Not connected"});let r=this.endpoint,o=this.abortController?.signal,n=t?.signal==null?o:null==o?t.signal:AbortSignal.any([o,t.signal]),i=async(o=!1)=>{try{let t=await this.commonHeaders({"Content-Type":"application/json"}),s={method:"POST",headers:t,body:JSON.stringify(e),signal:n,redirect:this.redirectMode},a=await this.fetchFn(r.href,s);if(401===a.status&&this.authProvider&&!o){if(await this.accessTokenChanged(new Headers(t).get("authorization")??void 0))return i(!0);let{resourceMetadataUrl:e,scope:r}=eB(a);this.resourceMetadataUrl=e;let o=await this.authorizeOnce(this.resourceMetadataUrl,r);if("AUTHORIZED"!==o)throw new eU;return i(!0)}if(!a.ok){let e=await a.text().catch(()=>null);throw new em({message:`MCP SSE Transport Error: POSTing to endpoint (HTTP ${a.status}): ${e}`,statusCode:a.status,url:r.href,responseBody:e??void 0})}}catch(e){if(t?.signal?.aborted)throw e;throw this.onerror?.(e),e}};await i()}},e9=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,te=/^=\?base64\?.*\?=$/;function tt(e){return[...e].every(e=>{let t=e.charCodeAt(0);return 9===t||t>=32&&t<=126})&&e.trim()===e&&!te.test(e)?e:`=?base64?${(0,s.convertUint8ArrayToBase64)(new TextEncoder().encode(e))}?=`}function tr(e){return void 0===e||"message"===e}var to=class{constructor({url:e,headers:t,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(e),this.headers=t,this.authProvider=r,this.redirectMode=o,this.sessionId=n,this.protocolVersion=i??g,this.onSessionIdChange=s,this.onSessionExpired=a,this.terminateSessionOnClose=l,this.fetchFn=c??globalThis.fetch}setProtocolVersion(e){if(this.protocolVersion=e,this.abortController){if(this.isModernProtocol()){this.inboundSseConnection?.close(),this.inboundSseConnection=void 0;return}this.inboundSseConnection||this.startInboundSse()}}isModernProtocol(){return(this.protocolVersion??z)===z}async commonHeaders({base:e,includeSessionId:t=!0}){let r={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??g};if(!this.isModernProtocol()&&t&&this.sessionId&&(r["mcp-session-id"]=this.sessionId),this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(r.Authorization=`Bearer ${e.access_token}`)}return(0,s.withUserAgentSuffix)(r,`ai-sdk/${ef}`,(0,s.getRuntimeEnvironmentUserAgent)())}setSessionId(e){this.sessionId!==e&&(this.sessionId=e,this.onSessionIdChange?.(e))}applySessionIdFromResponse(e){if(this.isModernProtocol())return;let t=e.headers.get("mcp-session-id");t&&this.setSessionId(t)}expireSessionId(e){this.sessionId===e&&this.setSessionId(void 0),this.onSessionExpired?.(e)}authorizeOnce(e,t){return this.authProvider?(this.authPromise||(this.authPromise=e5(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:e,scope:t,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0})),this.authPromise):Promise.resolve("REDIRECT")}async start(){if(this.abortController)throw new em({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(e){this.inboundSseConnection?.close(),this.abortController?.abort();try{if(!this.isModernProtocol()&&this.sessionId&&this.terminateSessionOnClose&&this.abortController){e?.signal?.throwIfAborted();let t=await this.commonHeaders({base:{}});e?.signal?.throwIfAborted(),await this.fetchFn(this.url.href,{method:"DELETE",headers:t,signal:e?.signal,redirect:this.redirectMode}).catch(()=>void 0)}}catch{}this.onclose?.()}async send(e,t){t?.signal?.throwIfAborted();let r=this.abortController?.signal,o=t?.signal==null?r:null==r?t.signal:AbortSignal.any([r,t.signal]),n=async(r=!1)=>{try{let i="method"in e&&"initialize"===e.method,s=i?void 0:this.sessionId,a=await this.commonHeaders({base:{"Content-Type":"application/json",Accept:"application/json, text/event-stream",...this.isModernProtocol()?t?.headers:{},...this.isModernProtocol()&&"method"in e&&"id"in e?this.getStandardRequestHeaders(e):{}},includeSessionId:!i}),l={method:"POST",headers:a,body:JSON.stringify(e),signal:o,redirect:this.redirectMode},u=await this.fetchFn(this.url.href,l);if(this.applySessionIdFromResponse(u),401===u.status&&this.authProvider&&!r){let{resourceMetadataUrl:e,scope:t}=eB(u);this.resourceMetadataUrl=e;try{let e=await this.authorizeOnce(this.resourceMetadataUrl,t);if("AUTHORIZED"!==e)throw new eU}catch(e){throw this.onerror?.(e),e}return n(!0)}if(202===u.status){this.isModernProtocol()||this.inboundSseConnection||this.startInboundSse();return}if(!u.ok){let t=await u.text().catch(()=>null);if("id"in e&&null!=t){let r=await ep(t).catch(()=>void 0);if(null!=r&&"error"in r)return void this.onmessage?.(null==r.id?{...r,id:e.id}:r)}let r=`MCP HTTP Transport Error: POSTing to endpoint (HTTP ${u.status}): ${t}`;404===u.status&&(!this.isModernProtocol()&&s?(this.expireSessionId(s),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 em({message:r,statusCode:u.status,url:this.url.href,responseBody:t??void 0});throw this.onerror?.(o),o}if(!("id"in e))return;let p=u.headers.get("content-type")||"";if(p.includes("application/json")){let e=await u.json();for(let t of Array.isArray(e)?e.map(e=>eu(e)):[eu(e)])this.onmessage?.(t);return}if(p.includes("text/event-stream")){if(!u.body){let e=new em({message:"MCP HTTP Transport Error: text/event-stream response without body",statusCode:u.status,url:this.url.href});throw this.onerror?.(e),e}let e=u.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader();(async()=>{try{for(;;){let{done:t,value:r}=await e.read();if(t)return;let{event:o,data:n}=r;if(tr(o))try{let e=await ep(n);this.onmessage?.(e)}catch(t){let e=new em({message:"MCP HTTP Transport Error: Failed to parse message",cause:t});this.onerror?.(e)}}}catch(e){if(t?.signal?.aborted||e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e)}})().catch(e=>{t?.signal?.aborted||e instanceof Error&&"AbortError"===e.name||this.onerror?.(e)});return}let h=new em({message:`MCP HTTP Transport Error: Unexpected content type: ${p}`,statusCode:u.status,url:this.url.href});throw this.onerror?.(h),h}catch(e){if(t?.signal?.aborted)throw e;throw this.onerror?.(e),e}};await n()}getStandardRequestHeaders(e){let t={"Mcp-Method":e.method},r=e.params,o="resources/read"===e.method?r?.uri:"tools/call"===e.method||"prompts/get"===e.method?r?.name:void 0;return"string"==typeof o&&(t["Mcp-Name"]=tt(o)),t}getNextReconnectionDelay(e){let{initialReconnectionDelay:t,reconnectionDelayGrowFactor:r,maxReconnectionDelay:o}=this.reconnectionOptions;return Math.min(t*Math.pow(r,e),o)}scheduleInboundSseReconnection(){let{maxRetries:e}=this.reconnectionOptions;if(e>0&&this.inboundReconnectAttempts>=e)return void this.onerror?.(new em({message:`MCP HTTP Transport Error: Maximum reconnection attempts (${e}) exceeded.`}));let t=this.getNextReconnectionDelay(this.inboundReconnectAttempts);this.inboundReconnectAttempts+=1,setTimeout(()=>{this.abortController?.signal.aborted||this.startInboundSse(!1,this.lastInboundEventId)},t)}startInboundSse(e=!1,t){this.isModernProtocol()||this.openInboundSse(e,t).catch(e=>{e instanceof Error&&"AbortError"===e.name||this.onerror?.(e)})}async openInboundSse(e=!1,t){if(!this.isModernProtocol())try{let r=this.sessionId,o=await this.commonHeaders({base:{Accept:"text/event-stream"}});t&&(o["last-event-id"]=t);let n=await this.fetchFn(this.url.href,{method:"GET",headers:o,signal:this.abortController?.signal,redirect:this.redirectMode});if(this.applySessionIdFromResponse(n),401===n.status&&this.authProvider&&!e){let{resourceMetadataUrl:e,scope:r}=eB(n);this.resourceMetadataUrl=e;try{let e=await this.authorizeOnce(this.resourceMetadataUrl,r);if("AUTHORIZED"!==e){let e=new eU;this.onerror?.(e);return}}catch(e){this.onerror?.(e);return}return this.openInboundSse(!0,t)}if(405===n.status)return;if(!n.ok||!n.body){404===n.status&&r&&this.expireSessionId(r);let e=new em({message:`MCP HTTP Transport Error: GET SSE failed: ${n.status} ${n.statusText}`,statusCode:n.status,url:this.url.href});this.onerror?.(e);return}let i=n.body.pipeThrough(new TextDecoderStream).pipeThrough(new c.EventSourceParserStream).getReader(),s=async()=>{try{for(;;){let{done:e,value:t}=await i.read();if(e)return;let{event:r,data:o,id:n}=t;if(n&&(this.lastInboundEventId=n),tr(r))try{let e=await ep(o);this.onmessage?.(e)}catch(t){let e=new em({message:"MCP HTTP Transport Error: Failed to parse message",cause:t});this.onerror?.(e)}}}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}};this.inboundSseConnection={close:()=>{i.cancel().catch(e=>{e instanceof Error&&"AbortError"===e.name||this.onerror?.(e)})}},this.inboundReconnectAttempts=0,s().catch(e=>{e instanceof Error&&"AbortError"===e.name||(this.onerror?.(e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection())})}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}}},tn=f.array(f.unknown()).transform(e=>e.filter(e=>"string"==typeof e)).optional().catch(void 0),ti=f.looseObject({connectDomains:tn,resourceDomains:tn,frameDomains:tn});f.looseObject({prefersBorder:f.boolean().optional().catch(void 0),csp:ti.optional().catch(void 0),permissions:f.record(f.string(),f.unknown()).optional().catch(void 0)});var ts=[-32020,-32021,-32022],ta=["ConnectionRefused","ConnectionClosed","FailedToOpenSocket","ECONNRESET","ECONNREFUSED","ETIMEDOUT","EPIPE"];function tl(e){let t=function(e){if(null!=e&&"object"==typeof e&&"statusCode"in e&&"number"==typeof e.statusCode)return e.statusCode}(e);if(null!=t)return 408===t||409===t||429===t||t>=500;if(em.isInstance(e)&&null!=e.code)return!1;let r=function(e){if(null!=e&&"object"==typeof e&&"code"in e&&"string"==typeof e.code)return e.code}(e);return null!=r&&ta.includes(r)}function tc({timeout:e,maxTotalTimeout:t}){return null==e?t:null==t?e:Math.min(e,t)}function tu(e,t){return null==t?e:new Promise((r,o)=>{let n=()=>{t.removeEventListener("abort",i)},i=()=>{n(),o(t.reason)};t.aborted?i():(t.addEventListener("abort",i,{once:!0}),e.then(e=>{n(),r(e)}).catch(e=>{n(),o(e)}))})}function tp({output:e}){return"content"in e&&Array.isArray(e.content)?{type:"content",value:e.content.map(e=>"text"===e.type&&"text"in e?{type:"text",text:e.text}:"image"===e.type&&"data"in e&&"mimeType"in e?{type:"file",mediaType:e.mimeType,data:{type:"data",data:e.data}}:{type:"text",text:JSON.stringify(e)})}:{type:"json",value:e}}async function th(e){let t=new td(e);return await t.init(),t}var td=class{constructor({transport:e,name:t,clientName:r=t??"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(e){if(null==e)return 0;if(!Number.isInteger(e))throw new em({message:"maxRetries must be an integer"});if(e<0)throw new em({message:"maxRetries must be >= 0"});return e}(i),this.clientCapabilities=s??{},this.initialInitializeResult=a,this.initializationOptions=l,this.protocolVersionDiscovery=c,function(e){return"start"in e&&"function"==typeof e.start&&"send"in e&&"function"==typeof e.send&&"close"in e&&"function"==typeof e.close}(e)?this.transport=e:this.transport=function(e){switch(e.type){case"sse":return new e7(e);case"http":return new to({...e,initialProtocolVersion:e.initialProtocolVersion??z});default:throw new em({message:"Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."})}}(e),this.transport.onclose=()=>this.onClose(),this.transport.onerror=e=>this.onError(e),this.transport.onmessage=e=>{"method"in e?"id"in e?this.onRequestMessage(e):this.onError(new em({message:"Unsupported message type"})):this.onResponse(e)},this.clientInfo={name:r,version:o}}get serverInfo(){return this._serverInfo}get initializeResult(){return this._initializeResult}get instructions(){return this._serverInstructions}async init(){let e,t,r=this.initializationOptions?.signal,o=this.initializationOptions?tc(this.initializationOptions):void 0,n=null==o?void 0:new AbortController,i=null==r?n?.signal:null==n?r:AbortSignal.any([r,n.signal]);null!=o&&(e=setTimeout(()=>{t=new em({message:`MCP client initialization timed out after ${o}ms`}),n?.abort(t)},o));try{if(this.isClosed=!1,i?.throwIfAborted(),await tu(this.transport.start(),i),this.initialInitializeResult){let e=P.parse(this.initialInitializeResult);return this.applyInitializeResult(e),this}if(this.protocolVersionDiscovery&&this.transport.supportsProtocolVersionDiscovery&&await this.tryProtocolDiscovery(i))return this;this.protocolEra="legacy",this.protocolVersion=g,this.setTransportProtocolVersion(this.protocolVersion);let e=await this.request({request:{method:"initialize",params:{protocolVersion:g,capabilities:this.clientCapabilities,clientInfo:this.clientInfo}},resultSchema:P,options:{signal:i}});if(void 0===e)throw new em({message:"Server sent invalid initialize result"});return this.applyInitializeResult(e),await this.notification({method:"notifications/initialized"},{signal:i}),this}catch(e){try{await tu(this.transport.close({signal:i}),i)}catch{}if(this.onClose(),null!=t)throw t;if(r?.aborted)throw new em({message:"MCP client initialization was aborted",cause:r.reason});throw e}finally{null!=e&&clearTimeout(e)}}async tryProtocolDiscovery(e){this.protocolEra="modern",this.protocolVersion=z,this.setTransportProtocolVersion(this.protocolVersion);try{let t=await this.request({request:{method:"server/discover"},resultSchema:T,options:{signal:e,timeout:1e3}});return this.applyDiscoverResult(t),!0}catch(e){if(em.isInstance(e)&&null!=e.code&&ts.includes(e.code))throw e;return!1}}applyDiscoverResult(e){if(!e.supportedVersions.includes(this.protocolVersion))throw new em({message:`Server does not support the requested protocol version: ${this.protocolVersion}`});let t=e._meta?.["io.modelcontextprotocol/serverInfo"];null!=t&&"object"==typeof t&&"name"in t&&"string"==typeof t.name&&"version"in t&&"string"==typeof t.version&&(this._serverInfo=t),this.serverCapabilities=e.capabilities,this._serverInstructions=e.instructions,this._initializeResult={protocolVersion:this.protocolVersion,capabilities:e.capabilities,serverInfo:this._serverInfo,instructions:e.instructions}}setTransportProtocolVersion(e){this.transport.setProtocolVersion?this.transport.setProtocolVersion(e):this.transport.protocolVersion=e}applyInitializeResult(e){if(!w.includes(e.protocolVersion))throw new em({message:`Server's protocol version is not supported: ${e.protocolVersion}`});this.serverCapabilities=e.capabilities,this.protocolEra="legacy",this.protocolVersion=e.protocolVersion,this._serverInfo=e.serverInfo,this._initializeResult=e,this.setTransportProtocolVersion(e.protocolVersion),this._serverInstructions=e.instructions}async close(){this.isClosed||(await this.transport?.close(),this.onClose())}send(e,t){return null==t?this.transport.send(e):this.transport.send(e,t)}assertCapability(e){switch(e){case"initialize":case"server/discover":break;case"completion/complete":if(!this.serverCapabilities.completions)throw new em({message:"Server does not support completions"});break;case"tools/list":case"tools/call":if(!this.serverCapabilities.tools)throw new em({message:"Server does not support tools"});break;case"resources/list":case"resources/read":case"resources/templates/list":if(!this.serverCapabilities.resources)throw new em({message:"Server does not support resources"});break;case"prompts/list":case"prompts/get":if(!this.serverCapabilities.prompts)throw new em({message:"Server does not support prompts"});break;default:throw new em({message:`Unsupported method: ${e}`})}}async request({request:e,resultSchema:t,options:r}){return new Promise((o,n)=>{let i;if(this.isClosed)return n(new em({message:"Attempted to send a request from a closed client"}));this.assertCapability(e.method);let s=r?.signal;s?.throwIfAborted();let a=null==r?void 0:tc(r),l=null==a?void 0:new AbortController,c=null==s?l?.signal:null==l?s:AbortSignal.any([s,l.signal]),u=this.requestMessageId++,p="modern"===this.protocolEra?{...e,params:{...e.params,_meta:{...e.params?._meta,"io.modelcontextprotocol/protocolVersion":this.protocolVersion,"io.modelcontextprotocol/clientCapabilities":this.clientCapabilities,"io.modelcontextprotocol/clientInfo":this.clientInfo}}}:e,h={...p,jsonrpc:"2.0",id:u},d=this.getToolRequestHeaders(p),m=()=>{n(new em({message:"Request was aborted",cause:s?.reason}))},f=()=>{this.responseHandlers.delete(u),s?.removeEventListener("abort",g),null!=i&&clearTimeout(i)},z=e=>{f(),n(e)},g=()=>{f(),m()};this.responseHandlers.set(u,e=>{if(s?.aborted)return f(),m();if(e instanceof Error)return z(e);try{if("modern"===this.protocolEra&&null==e.result.resultType)throw new em({message:"Modern MCP result is missing resultType"});if("input_required"===e.result.resultType)throw new em({message:"Server requested additional input, but multi round-trip requests are not supported yet"});let r=t.parse(e.result);f(),o(r)}catch(e){z(em.isInstance(e)?e:new em({message:"Failed to parse server response",cause:e}))}}),s?.addEventListener("abort",g,{once:!0}),null!=a&&(i=setTimeout(()=>{let e=new em({message:`Request timed out after ${a}ms`});l?.abort(e),z(e)},a));let w={...null==c?{}:{signal:c},...null==d?{}:{headers:d}};(0===Object.keys(w).length?this.send(h):this.send(h,w)).catch(e=>{z(e)})})}async listTools({params:e,options:t}={}){let r=await this.request({request:{method:"tools/list",params:e},resultSchema:I,options:t});return this.prepareToolDefinitions(r,e?.cursor==null)}prepareToolDefinitions(e,t=!1){if("modern"!==this.protocolEra||!this.transport.supportsMcpToolParameterHeaders)return e;t&&this.toolHeaderBindings.clear();let r=e.tools.filter(e=>{let t=function(e){let t;if(!(0,s.isRecord)(e))return{success:!1,error:"inputSchema must be a JSON Schema object"};let r=[],o=new Set,n=(e,i,a)=>{if(null==t&&(0,s.isRecord)(e)){if("x-mcp-header"in e){if(!a||0===i.length){t="x-mcp-header is not on a statically reachable property";return}let n=e["x-mcp-header"];if("string"!=typeof n||!e9.test(n)){t="x-mcp-header must be a non-empty HTTP token";return}let s=n.toLowerCase();if(o.has(s)){t=`x-mcp-header value "${n}" is not unique`;return}let l=e.type;if("boolean"!==l&&"integer"!==l&&"string"!==l){t="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[t,r]of Object.entries(e))if("x-mcp-header"!==t)if("properties"===t&&(0,s.isRecord)(r))for(let[e,t]of Object.entries(r))n(t,[...i,e],a);else n(r,i,!1)}};return n(e,[],!0),null==t?{success:!0,bindings:r}:{success:!1,error:t}}(e.inputSchema);return t.success?(this.toolHeaderBindings.set(e.name,t.bindings),!0):(this.onError(new em({message:`Ignoring MCP tool "${e.name}": ${t.error}`})),!1)});return{...e,tools:r}}getToolRequestHeaders(e){if("modern"!==this.protocolEra||"tools/call"!==e.method||"string"!=typeof e.params?.name)return;let t=this.toolHeaderBindings.get(e.params.name);if(null==t||0===t.length)return;let r=e.params.arguments;if(!(null==r||"object"!=typeof r||Array.isArray(r)))try{return function({bindings:e,args:t}){let r={};for(let o of e){let e=function(e,t){let r=e;for(let e of t){if(!(0,s.isRecord)(r))return;r=r[e]}return r}(t,o.path);if(null!=e){if("string"===o.valueType&&"string"!=typeof e||"boolean"===o.valueType&&"boolean"!=typeof e||"integer"===o.valueType&&!Number.isSafeInteger(e))throw TypeError(`Tool argument "${o.path.join(".")}" does not match its x-mcp-header type`);r[`Mcp-Param-${o.headerName}`]=tt(String(e))}}return r}({bindings:t,args:r})}catch(t){throw new em({message:`Failed to create MCP headers for tool "${e.params.name}"`,cause:t})}}async callToolWithRetry({options:e,execute:t}){return 0===this.maxRetries?t():(0,s.retryWithExponentialBackoff)({maxRetries:this.maxRetries,abortSignal:e?.signal,shouldRetry:tl,createRetryError:({message:e,errors:t})=>new em({message:e,cause:t[t.length-1]})})(t)}async callTool({name:e,arguments:t={},options:r}){return this.callToolWithRetry({options:r,execute:()=>this.request({request:{method:"tools/call",params:{name:e,arguments:t}},resultSchema:D,options:r})})}async listResourcesInternal({params:e,options:t}={}){return this.request({request:{method:"resources/list",params:e},resultSchema:U,options:t})}async readResourceInternal({uri:e,options:t}){return this.request({request:{method:"resources/read",params:{uri:e}},resultSchema:W,options:t})}async listResourceTemplatesInternal({options:e}={}){return this.request({request:{method:"resources/templates/list"},resultSchema:B,options:e})}async listPromptsInternal({params:e,options:t}={}){return this.request({request:{method:"prompts/list",params:e},resultSchema:Q,options:t})}async getPromptInternal({name:e,args:t,options:r}){return this.request({request:{method:"prompts/get",params:{name:e,arguments:t}},resultSchema:et,options:r})}async completeInternal({options:e,...t}){return this.request({request:{method:"completion/complete",params:t},resultSchema:G,options:e})}async notification(e,t){let r={...e,jsonrpc:"2.0"};await tu(this.send(r,t?.signal==null?void 0:{signal:t.signal}),t?.signal)}async tools({schemas:e="automatic"}={}){let t=await this.listTools(),r=[...t.tools];for(;null!=t.nextCursor;)t=await this.listTools({params:{cursor:t.nextCursor}}),r.push(...t.tools);return this.toolsFromDefinitions({...t,tools:r},{schemas:e})}toolsFromDefinitions(e,{schemas:t="automatic"}={}){e=this.prepareToolDefinitions(e);let r={};for(let{name:o,title:n,description:i,inputSchema:a,annotations:c,_meta:u}of e.tools){let e=n??c?.title;if("automatic"!==t&&!Object.prototype.hasOwnProperty.call(t,o))continue;let p=this,h="automatic"!==t?t[o]?.outputSchema:void 0,d=function(e){var t,r;let o,n=(t=e._meta,o=t?.ui,(0,l.isJSONObject)(o)?o:void 0),i=n?.resourceUri??e._meta?.["ui/resourceUri"],s=Array.isArray(r=n?.visibility)?r.filter(e=>"model"===e||"app"===e):void 0;if(void 0!==i){if("string"!=typeof i||!i.startsWith("ui://"))throw Error(`Invalid MCP App resource URI: ${JSON.stringify(i)}`)}else if(null==n)return;return{...n,...null!=i?{resourceUri:i}:{},...null!=s?{visibility:s}:{}}}({_meta:u}),m={clientName:this.clientInfo.name,toolName:o,...null!=e?{title:e}:{},...null!=c?{annotations:{...null!=c.title?{title:c.title}:{},...null!=c.readOnlyHint?{readOnlyHint:c.readOnlyHint}:{},...null!=c.destructiveHint?{destructiveHint:c.destructiveHint}:{},...null!=c.idempotentHint?{idempotentHint:c.idempotentHint}:{},...null!=c.openWorldHint?{openWorldHint:c.openWorldHint}:{}}}:{},...d?.resourceUri!=null?{app:{...d,mimeType:"text/html;profile=mcp-app"}}:{}},f=async(e,t)=>{t?.abortSignal?.throwIfAborted();let r=await p.callTool({name:o,arguments:e,options:{signal:t?.abortSignal}});return r.isError?r:null!=h?p.extractStructuredContent(r,h,o):r},z="automatic"===t?(0,s.dynamicTool)({description:i,title:e,metadata:m,inputSchema:(0,s.jsonSchema)({...a,properties:a.properties??{},additionalProperties:!1}),execute:f,toModelOutput:tp}):(0,s.tool)({description:i,title:e,metadata:m,inputSchema:t[o].inputSchema,...null!=h?{outputSchema:h}:{},execute:f,toModelOutput:tp});r[o]={...z,_meta:u}}return r}async extractStructuredContent(e,t,r){if("structuredContent"in e&&null!=e.structuredContent){let o=await (0,s.safeValidateTypes)({value:e.structuredContent,schema:(0,s.asSchema)(t)});if(!o.success)throw new em({message:`Tool "${r}" returned structuredContent that does not match the expected outputSchema`,cause:o.error});return o.value}if("content"in e&&Array.isArray(e.content)){let o=e.content.find(e=>"text"===e.type);if(o&&"text"in o){let e=await (0,s.safeParseJSON)({text:o.text,schema:t});if(!e.success)throw new em({message:`Tool "${r}" returned content that does not match the expected outputSchema`,cause:e.error});return e.value}}throw new em({message:`Tool "${r}" did not return structuredContent or parseable text content`})}listResources({params:e,options:t}={}){return this.listResourcesInternal({params:e,options:t})}readResource({uri:e,options:t}){return this.readResourceInternal({uri:e,options:t})}listResourceTemplates({options:e}={}){return this.listResourceTemplatesInternal({options:e})}experimental_listPrompts({params:e,options:t}={}){return this.listPromptsInternal({params:e,options:t})}experimental_getPrompt({name:e,arguments:t,options:r}){return this.getPromptInternal({name:e,args:t,options:r})}complete(e){return this.completeInternal(e)}onElicitationRequest(e,t){if(e!==eo)throw new em({message:"Unsupported request schema. Only ElicitationRequestSchema is supported."});this.elicitationRequestHandler=t}async onRequestMessage(e){try{if("ping"===e.method)return void await this.transport.send({jsonrpc:"2.0",id:e.id,result:{}});if("elicitation/create"!==e.method)return void await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32601,message:`Unsupported request method: ${e.method}`}});if(!this.elicitationRequestHandler)return void await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32601,message:"No elicitation handler registered on client"}});let t=eo.safeParse({method:e.method,params:e.params});if(!t.success)return void await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32602,message:`Invalid elicitation request: ${t.error.message}`,data:t.error.issues}});try{let r=await this.elicitationRequestHandler(t.data),o=en.parse(r);await this.transport.send({jsonrpc:"2.0",id:e.id,result:o})}catch(t){await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32603,message:t instanceof Error?t.message:"Failed to handle elicitation request"}}),this.onError(t)}}catch(e){this.onError(e)}}onClose(){if(this.isClosed)return;this.isClosed=!0;let e=new em({message:"Connection closed"});for(let t of this.responseHandlers.values())t(e);this.responseHandlers.clear()}onError(e){this.onUncaughtError&&this.onUncaughtError(e)}onResponse(e){if(null==e.id)return void this.onError(new em({message:`Protocol error: Received a response without a message ID: ${JSON.stringify(e)}`}));let t=Number(e.id),r=this.responseHandlers.get(t);if(void 0===r)throw new em({message:`Protocol error: Received a response for an unknown message ID: ${JSON.stringify(e)}`});this.responseHandlers.delete(t),r("result"in e?e:new em({message:e.error.message,code:e.error.code,data:e.error.data,cause:e.error}))}};new TextEncoder,e.s(["UnauthorizedError",0,eU,"auth",0,e5,"createMCPClient",0,th],361164)},202058,(e,t,r)=>{t.exports=n,n.sync=function(e,t){return i(o.statSync(e),t)};var o=e.r(522734);function n(e,t,r){o.stat(e,function(e,o){r(e,!e&&i(o,t))})}function i(e,t){var r,o,n,i,s,a,l,c,u;return e.isFile()&&(r=e,o=t,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,(e,t,r)=>{t.exports=i,i.sync=function(e,t){return n(o.statSync(e),e,t)};var o=e.r(522734);function n(e,t,r){if(!e.isSymbolicLink()&&!e.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&&t.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,r){o.stat(e,function(o,i){r(o,!o&&n(i,e,t))})}},24214,(e,t,r)=>{var o;function n(e,t,r){if("function"==typeof t&&(r=t,t={}),!r){if("function"!=typeof Promise)throw TypeError("callback not provided");return new Promise(function(r,o){n(e,t||{},function(e,t){e?o(e):r(t)})})}o(e,t||{},function(e,o){e&&("EACCES"===e.code||t&&t.ignoreErrors)&&(e=null,o=!1),r(e,o)})}e.r(522734),o="win32"===process.platform||e.g.TESTING_WINDOWS?e.r(129507):e.r(202058),t.exports=n,n.sync=function(e,t){try{return o.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||"EACCES"===e.code)return!1;throw e}}},319932,(e,t,r)=>{let o="win32"===process.platform||"cygwin"===process.env.OSTYPE||"msys"===process.env.OSTYPE,n=e.r(814747),i=o?";":":",s=e.r(24214),a=e=>Object.assign(Error(`not found: ${e}`),{code:"ENOENT"}),l=(e,t)=>{let r=t.colon||i,n=e.match(/\//)||o&&e.match(/\\/)?[""]:[...o?[process.cwd()]:[],...(t.path||process.env.PATH||"").split(r)],s=o?t.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",a=o?s.split(r):[""];return o&&-1!==e.indexOf(".")&&""!==a[0]&&a.unshift(""),{pathEnv:n,pathExt:a,pathExtExe:s}},c=(e,t,r)=>{"function"==typeof t&&(r=t,t={}),t||(t={});let{pathEnv:o,pathExt:i,pathExtExe:c}=l(e,t),u=[],p=r=>new Promise((i,s)=>{if(r===o.length)return t.all&&u.length?i(u):s(a(e));let l=o[r],c=/^".*"$/.test(l)?l.slice(1,-1):l,p=n.join(c,e);i(h(!c&&/^\.[\\\/]/.test(e)?e.slice(0,2)+p:p,r,0))}),h=(e,r,o)=>new Promise((n,a)=>{if(o===i.length)return n(p(r+1));let l=i[o];s(e+l,{pathExt:c},(i,s)=>{if(!i&&s)if(!t.all)return n(e+l);else u.push(e+l);return n(h(e,r,o+1))})});return r?p(0).then(e=>r(null,e),r):p(0)};t.exports=c,c.sync=(e,t)=>{let{pathEnv:r,pathExt:o,pathExtExe:i}=l(e,t=t||{}),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,e),h=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+p:p;for(let e=0;e<o.length;e++){let r=h+o[e];try{if(s.sync(r,{pathExt:i}))if(!t.all)return r;else c.push(r)}catch(e){}}}if(t.all&&c.length)return c;if(t.nothrow)return null;throw a(e)}},625881,(e,t,r)=>{"use strict";let o=(e={})=>{let t=e.env||process.env;return"win32"!==(e.platform||process.platform)?"PATH":Object.keys(t).reverse().find(e=>"PATH"===e.toUpperCase())||"Path"};t.exports=o,t.exports.default=o},81463,(e,t,r)=>{"use strict";let o=e.r(814747),n=e.r(319932),i=e.r(625881);function s(e,t){let r,s=e.options.env||process.env,a=process.cwd(),l=null!=e.options.cwd,c=l&&void 0!==process.chdir&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch(e){}try{r=n.sync(e.command,{path:s[i({env:s})],pathExt:t?o.delimiter:void 0})}catch(e){}finally{c&&process.chdir(a)}return r&&(r=o.resolve(l?e.options.cwd:"",r)),r}t.exports=function(e){return s(e)||s(e,!0)}},502977,(e,t,r)=>{"use strict";let o=/([()\][%!^"`<>&|;, *?])/g;t.exports.command=function(e){return e.replace(o,"^$1")},t.exports.argument=function(e,t){return e=(e=(e=`${e}`).replace(/(?=(\\+?)?)\1"/g,'$1$1\\"')).replace(/(?=(\\+?)?)\1$/,"$1$1"),e=(e=`"${e}"`).replace(o,"^$1"),t&&(e=e.replace(o,"^$1")),e}},831804,(e,t,r)=>{"use strict";t.exports=/^#!(.*)/},469231,(e,t,r)=>{"use strict";let o=e.r(831804);t.exports=(e="")=>{let t=e.match(o);if(!t)return null;let[r,n]=t[0].replace(/#! ?/,"").split(" "),i=r.split("/").pop();return"env"===i?n:n?`${i} ${n}`:i}},385328,(e,t,r)=>{"use strict";let o=e.r(522734),n=e.r(469231);t.exports=function(e){let t,r=Buffer.alloc(150);try{t=o.openSync(e,"r"),o.readSync(t,r,0,150,0),o.closeSync(t)}catch(e){}return n(r.toString())}},207546,(e,t,r)=>{"use strict";e.r(814747),e.r(81463),e.r(502977),e.r(385328),process.platform,t.exports=function(e,t,r){t&&!Array.isArray(t)&&(r=t,t=null);let o={command:e,args:t=t?t.slice(0):[],options:r=Object.assign({},r),file:void 0,original:{command:e,args:t}};return r.shell,o}},245750,(e,t,r)=>{"use strict";process.platform,t.exports={hookChildProcess:function(e,t){},verifyENOENT:function(e,t){return null},verifyENOENTSync:function(e,t){return null},notFoundError:function(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}}},465887,(e,t,r)=>{"use strict";let o=e.r(233405),n=e.r(207546),i=e.r(245750);function s(e,t,r){let s=n(e,t,r),a=o.spawn(s.command,s.args,s.options);return i.hookChildProcess(a,s),a}t.exports=s,t.exports.spawn=s,t.exports.sync=function(e,t,r){let s=n(e,t,r),a=o.spawnSync(s.command,s.args,s.options);return a.error=a.error||i.verifyENOENTSync(a.status,s),a},t.exports._parse=n,t.exports._enoent=i},958560,e=>{"use strict";var t,r,o=e.i(847841),n=e.i(469719),i=e.i(376261),s=e.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(),w=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(w)});var y=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(),b=y.extend({text:n.z.string()}),v=y.extend({blob:n.z.base64()}),_=n.z.object({type:n.z.literal("resource"),resource:n.z.union([b,v])}).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(e=>!["text","image","resource","resource_link"].includes(e.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(e=>({...e,content:[{type:"text",text:JSON.stringify(e.structuredContent)}]})).pipe(C);C.or(T).or(u.extend({toolResult:n.z.unknown().nonoptional()}));var P=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(P)}),u.extend({contents:n.z.array(n.z.union([b,v]))});var x=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([x,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 k=n.z.object({name:n.z.string(),description:n.z.optional(n.z.string()),required:n.z.optional(n.z.boolean())}).loose(),A=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(k))}).loose();m.extend({prompts:n.z.array(A)});var j=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(j)});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(),L=n.z.union([O,H,M,$]);async function N(e){var t;return t=await (0,o.parseJSON)({text:e}),L.parse(t)}var V="vercel.ai.error.AI_MCPClientError",q=Symbol.for(V),D=class extends(r=i.AISDKError,t=q,r){constructor({name:e="MCPClientError",message:r,cause:o,data:n,code:i,statusCode:s,url:a,responseBody:l}){super({name:e,message:r,cause:o}),this[t]=!0,this.data=n,this.code=i,this.statusCode=s,this.url=a,this.responseBody=l}static isInstance(e){return i.AISDKError.hasMarker(e,V)}},F=class{constructor(e){this.supportsProtocolVersionDiscovery=!0,this.abortController=new AbortController,this.readBuffer=new B,this.serverParams=e}async start(){if(this.process)throw new D({message:"StdioMCPTransport already started."});return new Promise((e,t)=>{try{let r=function(e,t){if("win32"===globalThis.process.platform&&[e.command,...e.args??[]].some(e=>/[\r\n]/.test(e)))throw TypeError("Stdio MCP commands and arguments must not contain line breaks on Windows.");return(0,s.default)(e.command,e.args??[],{env:function(e){let t="win32"===globalThis.process.platform,r=e?{...e}:{},o=new Set(Object.keys(r).map(e=>t?e.toUpperCase():e));for(let e of t?["APPDATA","HOMEDRIVE","HOMEPATH","LOCALAPPDATA","PATH","PROCESSOR_ARCHITECTURE","SYSTEMDRIVE","SYSTEMROOT","TEMP","USERNAME","USERPROFILE"]:["HOME","LOGNAME","PATH","SHELL","TERM","USER"]){if(o.has(e))continue;let t=globalThis.process.env[e];void 0!==t&&(t.startsWith("()")||(r[e]=t))}return r}(e.env),stdio:["pipe","pipe",e.stderr??"inherit"],shell:!1,signal:t,windowsHide:"win32"===globalThis.process.platform&&"type"in globalThis.process,cwd:e.cwd})}(this.serverParams,this.abortController.signal);this.process=r,this.process.on("error",e=>{"AbortError"===e.name?this.onclose?.():(t(e),this.onerror?.(e))}),this.process.on("spawn",()=>{e()}),this.process.on("close",e=>{this.process=void 0,this.onclose?.()}),this.process.stdin?.on("error",e=>{this.onerror?.(e)}),this.process.stdout?.on("data",e=>{this.readBuffer.append(e),this.processReadBuffer()}),this.process.stdout?.on("error",e=>{this.onerror?.(e)})}catch(e){t(e),this.onerror?.(e)}})}async processReadBuffer(){for(;;){let e=this.readBuffer.readLine();if(null===e)break;try{let t=await W(e);this.onmessage?.(t)}catch(e){this.onerror?.(e)}}}async close(){this.abortController.abort(),this.process=void 0,this.readBuffer.clear()}send(e){return new Promise(t=>{if(!this.process?.stdin)throw new D({message:"StdioClientTransport not connected"});let r=JSON.stringify(e)+"\n";this.process.stdin.write(r)?t():this.process.stdin.once("drain",t)})}},B=class{append(e){this.buffer=this.buffer?Buffer.concat([this.buffer,e]):e}readLine(){if(!this.buffer)return null;let e=this.buffer.indexOf("\n");if(-1===e)return null;let t=this.buffer.toString("utf8",0,e);return this.buffer=this.buffer.subarray(e+1),t}clear(){this.buffer=void 0}};async function W(e){return N(e)}e.s(["Experimental_StdioMCPTransport",0,F])}];
|
|
1
|
+
module.exports=[105303,e=>e.a(async(t,r)=>{try{var o,n=e.i(361164),i=e.i(958560),s=e.i(687388),a=e.i(640911),l=e.i(41444),c=e.i(148831),u=e.i(441963),p=t([c]);[c]=p.then?(await p)():p;class h extends Error{serverName;authorizationUrl;constructor(e,t){super(`MCP server "${e}" requires authorization`),this.serverName=e,this.authorizationUrl=t,this.name="McpAuthRequiredError"}}class d{store;serverName;oauth;callbackUrl;clientName;lastAuthorizationUrl;constructor(e,t,r,o,n){this.store=e,this.serverName=t,this.oauth=r,this.callbackUrl=o,this.clientName=n}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(e){this.oauth={...this.oauth,...e},await this.store.saveOAuth(this.serverName,this.oauth)}clientInformation(){return this.oauth.clientInformation}async saveClientInformation(e){await this.persist({clientInformation:e})}tokens(){return this.oauth.tokens}async saveTokens(e){await this.persist({tokens:e})}authorizationServerInformation(){return this.oauth.authorizationServer}async saveAuthorizationServerInformation(e){await this.persist({authorizationServer:e})}codeVerifier(){if(!this.oauth.codeVerifier)throw Error("No code verifier saved");return this.oauth.codeVerifier}async saveCodeVerifier(e){await this.persist({codeVerifier:e})}state(){return crypto.randomUUID()}async saveState(e){await this.persist({state:e})}storedState(){return this.oauth.state}redirectToAuthorization(e){this.lastAuthorizationUrl=e}async invalidateCredentials(e){let t={...this.oauth};("all"===e||"client"===e)&&(t.clientInformation=void 0),("all"===e||"tokens"===e)&&(t.tokens=void 0),("all"===e||"verifier"===e)&&(t.codeVerifier=void 0),this.oauth=t,await this.store.saveOAuth(this.serverName,t)}}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 e{store;sessions;connecting;callbackUrl;clientName;constructor(e,t){this.store=e,this.sessions=new Map,this.connecting=new Map,this.callbackUrl=t.callbackUrl,this.clientName=t.clientName??s.APP_NAME}async connect(e){let t=this.connecting.get(e);if(t)return t;let r=this.doConnect(e).finally(()=>this.connecting.delete(e));return this.connecting.set(e,r),r}async callTool(e,t,r,o){let i=await this.ensureClient(e);try{let n=await i.callTool({name:t,arguments:r,options:o?{signal:o}:void 0});return this.touch(e),n}catch(t){if(t instanceof n.UnauthorizedError)throw await this.closeSession(e),new h(e);throw t}}async finishAuthorization(e){let t=e.get("state"),r=e.get("code");if(!t||!r)throw Error("OAuth callback is missing code or state");let o=await this.store.findByOAuthState(t);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:t});if("AUTHORIZED"!==s)throw Error(`Token exchange ended in "${s}"`);return await i.invalidateCredentials("verifier"),await this.connect(o.name),o.name}async disconnect(e){await this.closeSession(e)}async dispose(){await Promise.all([...this.sessions.keys()].map(e=>this.closeSession(e)))}async doConnect(e){await this.closeSession(e);let t=await this.store.load(e);if(!t)throw Error(`Unknown MCP server "${e}"`);let r={};try{let o=await this.openClient(t,r),n=(await o.listTools()).tools.map(e=>({name:e.name,description:e.description,inputSchema:e.inputSchema,outputSchema:e.outputSchema}));return this.adopt(e,o),await this.store.saveConnectionResult(e,{toolInfo:n,lastError:null}),a.logger.info(`mcp "${e}" 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 t=r.href;if(t)return await this.store.saveConnectionResult(e,{toolInfo:[],lastError:"Authorization required — finish sign-in in the opened tab"}),{status:"auth_required",authorizationUrl:t}}let c=(o=p,i=t,s=(0,l.errorToString)(o),(0,u.isRemoteConfig)(i.config)&&!i.oauth?.clientInformation&&/Invalid OAuth error response/.test(s)?`This server does not let an app register itself for sign-in, so it cannot be connected here. It answered: ${s}`:s);throw await this.store.saveConnectionResult(e,{toolInfo:[],lastError:c}),a.logger.warn(`mcp "${e}" failed — ${c}`),Error(c,{cause:p})}}async openClient(e,t={}){if((0,u.isRemoteConfig)(e.config)){let r=this.providerFor(e);try{return await (0,n.createMCPClient)({name:this.clientName,transport:{type:"http",url:e.config.url,headers:e.config.headers,authProvider:r,redirect:"follow"}})}finally{t.href=r.lastAuthorizationUrl?.href}}return(0,n.createMCPClient)({name:this.clientName,transport:new i.Experimental_StdioMCPTransport({command:e.config.command,args:e.config.args,env:e.config.env})})}providerFor(e){return new d(this.store,e.name,e.oauth??{},this.callbackUrl,this.clientName)}async ensureClient(e){let t=this.sessions.get(e);if(t)return t.client;let r=await this.connect(e);if("auth_required"===r.status)throw new h(e,r.authorizationUrl);let o=this.sessions.get(e);if(!o)throw Error(`Session for "${e}" vanished mid-connect`);return o.client}adopt(e,t){this.sessions.set(e,{client:t,idleTimer:this.armIdleTimer(e)})}touch(e){let t=this.sessions.get(e);t&&(clearTimeout(t.idleTimer),t.idleTimer=this.armIdleTimer(e))}armIdleTimer(e){let t=setTimeout(()=>{this.closeSession(e)},s.MCP_IDLE_MS);return t.unref?.(),t}async closeSession(e){let t=this.sessions.get(e);t&&(this.sessions.delete(e),clearTimeout(t.idleTimer),await t.client.close().catch(()=>{}))}}({load:e=>(0,c.findServer)(e),saveOAuth:(e,t)=>(0,c.saveOAuthData)(e,t),saveConnectionResult:(e,t)=>null===t.lastError?(0,c.syncServerTools)(e,t.toolInfo):(0,c.saveConnectionError)(e,t.lastError),findByOAuthState:e=>(0,c.findServerByOAuthState)(e)},o);let f=m.__thursdayMcpManager;e.s(["McpAuthRequiredError",0,h,"mcpManager",0,f]),r()}catch(e){r(e)}},!1),361164,e=>{"use strict";let t;var r=e.i(36040),o=e.i(847841),n=e.i(907855),i=e.i(469719),s=e.i(376261);async function a(e){return(await t).getRandomValues(new Uint8Array(e))}async function l(e){let t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~",r=256-256%t.length,o="";for(;o.length<e;)for(let n of(await a(e-o.length)))n<r&&(o+=t[n%t.length]);return o}async function c(e){return await l(e)}async function u(e){return btoa(String.fromCharCode(...new Uint8Array(await (await t).subtle.digest("SHA-256",new TextEncoder().encode(e))))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}async function p(e){if(e||(e=43),e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;let t=await c(e),r=await u(t);return{code_verifier:t,code_challenge:r}}t=globalThis.crypto?.webcrypto??globalThis.crypto??e.A(70729).then(e=>e.webcrypto);let h="2026-07-28",d="2025-11-25",m=[h,d,"2025-06-18","2025-03-26","2024-11-05"],f=i.z.optional(i.z.record(i.z.string(),i.z.unknown())),z=i.z.looseObject({name:i.z.string(),version:i.z.string(),title:i.z.optional(i.z.string())}),g=i.z.looseObject({_meta:i.z.optional(i.z.object({}).loose())}),w=g.extend({resultType:i.z.optional(i.z.string())}),y=i.z.object({method:i.z.string(),params:i.z.optional(g)}),b=i.z.object({applyDefaults:i.z.optional(i.z.boolean())}).loose(),v=i.z.looseObject({experimental:i.z.optional(i.z.object({}).loose()),logging:i.z.optional(i.z.object({}).loose()),completions:i.z.optional(i.z.object({}).loose()),prompts:i.z.optional(i.z.looseObject({listChanged:i.z.optional(i.z.boolean())})),resources:i.z.optional(i.z.looseObject({subscribe:i.z.optional(i.z.boolean()),listChanged:i.z.optional(i.z.boolean())})),tools:i.z.optional(i.z.looseObject({listChanged:i.z.optional(i.z.boolean())})),elicitation:i.z.optional(b)});i.z.object({elicitation:i.z.optional(b)}).loose();let _=w.extend({supportedVersions:i.z.array(i.z.string()),capabilities:v,instructions:i.z.optional(i.z.string()),ttlMs:i.z.optional(i.z.number()),cacheScope:i.z.optional(i.z.union([i.z.literal("public"),i.z.literal("private")]))}),E=w.extend({protocolVersion:i.z.string(),capabilities:v,serverInfo:z,instructions:i.z.optional(i.z.string())}),S=w.extend({nextCursor:i.z.optional(i.z.string())}),C=i.z.object({name:i.z.string(),title:i.z.optional(i.z.string()),description:i.z.optional(i.z.string()),inputSchema:i.z.looseObject({type:i.z.optional(i.z.unknown()),properties:i.z.optional(i.z.object({}).loose())}),outputSchema:i.z.optional(i.z.object({}).loose()),annotations:i.z.optional(i.z.object({title:i.z.optional(i.z.string()),readOnlyHint:i.z.optional(i.z.boolean()),destructiveHint:i.z.optional(i.z.boolean()),idempotentHint:i.z.optional(i.z.boolean()),openWorldHint:i.z.optional(i.z.boolean())}).loose()),_meta:f}).loose(),T=S.extend({tools:i.z.array(C)}),P=i.z.object({type:i.z.literal("text"),text:i.z.string()}).loose(),x=i.z.object({type:i.z.literal("image"),data:i.z.base64(),mimeType:i.z.string()}).loose(),R=i.z.object({uri:i.z.string(),name:i.z.string(),title:i.z.optional(i.z.string()),description:i.z.optional(i.z.string()),mimeType:i.z.optional(i.z.string()),size:i.z.optional(i.z.number())}).loose(),I=S.extend({resources:i.z.array(R)}),k=i.z.object({uri:i.z.string(),name:i.z.optional(i.z.string()),title:i.z.optional(i.z.string()),mimeType:i.z.optional(i.z.string())}).loose(),j=k.extend({text:i.z.string()}),A=k.extend({blob:i.z.base64()}),U=i.z.object({type:i.z.literal("resource"),resource:i.z.union([j,A])}).loose(),O=i.z.object({type:i.z.literal("resource_link"),uri:i.z.string(),name:i.z.string(),description:i.z.optional(i.z.string()),mimeType:i.z.optional(i.z.string())}).loose(),M=i.z.object({type:i.z.string()}).loose().refine(e=>!["text","image","resource","resource_link"].includes(e.type),{message:"Known content types must match their schema"}),$=w.extend({content:i.z.array(i.z.union([P,x,U,O,M])),structuredContent:i.z.optional(i.z.unknown()),isError:i.z.boolean().default(!1).optional()}),H=w.extend({content:i.z.never().optional(),structuredContent:i.z.json(),isError:i.z.boolean().default(!1).optional()}).transform(e=>({...e,content:[{type:"text",text:JSON.stringify(e.structuredContent)}]})).pipe($),L=$.or(H).or(w.extend({toolResult:i.z.unknown().nonoptional()})),N=i.z.object({uriTemplate:i.z.string(),name:i.z.string(),title:i.z.optional(i.z.string()),description:i.z.optional(i.z.string()),mimeType:i.z.optional(i.z.string())}).loose(),V=w.extend({resourceTemplates:i.z.array(N)}),q=w.extend({contents:i.z.array(i.z.union([j,A]))}),D=i.z.object({type:i.z.literal("ref/prompt"),name:i.z.string()}).loose(),F=i.z.object({type:i.z.literal("ref/resource"),uri:i.z.string()}).loose(),B=i.z.object({name:i.z.string(),value:i.z.string()}).loose();g.extend({ref:i.z.union([D,F]),argument:B,context:i.z.optional(i.z.object({arguments:i.z.record(i.z.string(),i.z.string())}).loose())});let W=w.extend({completion:i.z.object({values:i.z.array(i.z.string()).max(100),total:i.z.optional(i.z.number().int()),hasMore:i.z.optional(i.z.boolean())}).loose()}),J=i.z.object({name:i.z.string(),description:i.z.optional(i.z.string()),required:i.z.optional(i.z.boolean())}).loose(),Z=i.z.object({name:i.z.string(),title:i.z.optional(i.z.string()),description:i.z.optional(i.z.string()),arguments:i.z.optional(i.z.array(J))}).loose(),K=S.extend({prompts:i.z.array(Z)}),G=i.z.object({role:i.z.union([i.z.literal("user"),i.z.literal("assistant")]),content:i.z.union([P,x,U,O])}).loose(),Y=w.extend({description:i.z.optional(i.z.string()),messages:i.z.array(G)}),X=g.extend({message:i.z.string(),requestedSchema:i.z.unknown()}),Q=y.extend({method:i.z.literal("elicitation/create"),params:X}),ee=w.extend({action:i.z.union([i.z.literal("accept"),i.z.literal("decline"),i.z.literal("cancel")]),content:i.z.optional(i.z.record(i.z.string(),i.z.unknown()))}),et=i.z.object({jsonrpc:i.z.literal("2.0"),id:i.z.union([i.z.string(),i.z.number().int()])}).merge(y).strict(),er=i.z.object({jsonrpc:i.z.literal("2.0"),id:i.z.union([i.z.string(),i.z.number().int()]),result:w}).strict(),eo=i.z.object({jsonrpc:i.z.literal("2.0"),id:i.z.optional(i.z.union([i.z.string(),i.z.number().int()])),error:i.z.object({code:i.z.number().int(),message:i.z.string(),data:i.z.optional(i.z.unknown())})}).strict(),en=i.z.object({jsonrpc:i.z.literal("2.0")}).merge(i.z.object({method:i.z.string(),params:i.z.optional(g)})).strict(),ei=i.z.union([et,en,er,eo]);function es(e){return ei.parse(e)}async function ea(e){return es(await (0,o.parseJSON)({text:e}))}let el="vercel.ai.error.AI_MCPClientError",ec=Symbol.for(el);var eu=class extends s.AISDKError{constructor({name:e="MCPClientError",message:t,cause:r,data:o,code:n,statusCode:i,url:s,responseBody:a}){super({name:e,message:t,cause:r}),this[ec]=!0,this.data=o,this.code=n,this.statusCode=i,this.url=s,this.responseBody=a}static isInstance(e){return s.AISDKError.hasMarker(e,el)}};let ep="2.0.63",eh=i.z.string().url().superRefine((e,t)=>{if(!URL.canParse(e))return t.addIssue({code:i.z.ZodIssueCode.custom,message:"URL must be parseable",fatal:!0}),i.z.NEVER}).refine(e=>{let t=new URL(e);return"javascript:"!==t.protocol&&"data:"!==t.protocol&&"vbscript:"!==t.protocol},{message:"URL cannot use javascript:, data:, or vbscript: scheme"}),ed=i.z.object({access_token:i.z.string(),id_token:i.z.string().optional(),token_type:i.z.string(),expires_in:i.z.number().optional(),scope:i.z.string().optional(),refresh_token:i.z.string().optional(),issuer:eh.optional(),authorization_server:eh.optional(),token_endpoint:eh.optional()}).strip(),em=i.z.looseObject({resource:i.z.string().url(),authorization_servers:i.z.array(eh).optional(),jwks_uri:i.z.string().url().optional(),scopes_supported:i.z.array(i.z.string()).optional(),bearer_methods_supported:i.z.array(i.z.string()).optional(),resource_signing_alg_values_supported:i.z.array(i.z.string()).optional(),resource_name:i.z.string().optional(),resource_documentation:i.z.string().optional(),resource_policy_uri:i.z.string().url().optional(),resource_tos_uri:i.z.string().url().optional(),tls_client_certificate_bound_access_tokens:i.z.boolean().optional(),authorization_details_types_supported:i.z.array(i.z.string()).optional(),dpop_signing_alg_values_supported:i.z.array(i.z.string()).optional(),dpop_bound_access_tokens_required:i.z.boolean().optional()}),ef=i.z.looseObject({issuer:i.z.string(),authorization_endpoint:eh,token_endpoint:eh,registration_endpoint:eh.optional(),authorization_response_iss_parameter_supported:i.z.boolean().optional(),client_id_metadata_document_supported:i.z.boolean().optional(),scopes_supported:i.z.array(i.z.string()).optional(),response_types_supported:i.z.array(i.z.string()),grant_types_supported:i.z.array(i.z.string()).optional(),code_challenge_methods_supported:i.z.array(i.z.string()).optional(),token_endpoint_auth_methods_supported:i.z.array(i.z.string()).optional(),token_endpoint_auth_signing_alg_values_supported:i.z.array(i.z.string()).optional()}),ez=i.z.looseObject({issuer:i.z.string(),authorization_endpoint:eh,token_endpoint:eh,userinfo_endpoint:eh.optional(),jwks_uri:eh,registration_endpoint:eh.optional(),authorization_response_iss_parameter_supported:i.z.boolean().optional(),client_id_metadata_document_supported:i.z.boolean().optional(),scopes_supported:i.z.array(i.z.string()).optional(),response_types_supported:i.z.array(i.z.string()),grant_types_supported:i.z.array(i.z.string()).optional(),subject_types_supported:i.z.array(i.z.string()),id_token_signing_alg_values_supported:i.z.array(i.z.string()),claims_supported:i.z.array(i.z.string()).optional(),token_endpoint_auth_methods_supported:i.z.array(i.z.string()).optional()}).merge(ef.pick({code_challenge_methods_supported:!0})),eg=i.z.object({client_id:i.z.string(),client_secret:i.z.string().optional(),client_id_issued_at:i.z.number().optional(),client_secret_expires_at:i.z.number().optional(),issuer:eh.optional(),authorization_server:eh.optional(),token_endpoint:eh.optional()}).strip(),ew=i.z.object({redirect_uris:i.z.array(eh),application_type:i.z.union([i.z.literal("native"),i.z.literal("web")]).optional(),token_endpoint_auth_method:i.z.string().optional(),grant_types:i.z.array(i.z.string()).optional(),response_types:i.z.array(i.z.string()).optional(),client_name:i.z.string().optional(),client_uri:eh.optional(),logo_uri:eh.optional(),scope:i.z.string().optional(),contacts:i.z.array(i.z.string()).optional(),tos_uri:eh.optional(),policy_uri:i.z.string().optional(),jwks_uri:eh.optional(),jwks:i.z.any().optional(),software_id:i.z.string().optional(),software_version:i.z.string().optional(),software_statement:i.z.string().optional()}).strip(),ey=i.z.object({error:i.z.string(),error_description:i.z.string().optional(),error_uri:i.z.string().optional()}),eb=ew.merge(eg),ev="vercel.ai.error.AI_MCPClientOAuthError",e_=Symbol.for(ev);var eE=class extends s.AISDKError{constructor({name:e="MCPClientOAuthError",message:t,cause:r}){super({name:e,message:t,cause:r}),this[e_]=!0}static isInstance(e){return s.AISDKError.hasMarker(e,ev)}},eS=class extends eE{static{this.errorCode="server_error"}},eC=class extends eE{static{this.errorCode="invalid_client"}},eT=class extends eE{static{this.errorCode="invalid_grant"}},eP=class extends eE{static{this.errorCode="unauthorized_client"}};let ex={[eS.errorCode]:eS,[eC.errorCode]:eC,[eT.errorCode]:eT,[eP.errorCode]:eP};function eR(e){let t=e.href;return"/"===e.pathname&&t.endsWith("/")?t.slice(0,-1):t}var eI=class extends Error{constructor(e="Unauthorized"){super(e),this.name="UnauthorizedError"}};function ek(e){return new URL(e).href}function ej(e){let t=e.toLowerCase().replace(/\.+$/,"");return"localhost"===t||t.endsWith(".localhost")||"127.0.0.1"===t||"[::1]"===t||"::1"===t}function eA(e,{allowLoopback:t=!1}={}){if(!(t&&("http:"===e.protocol||"https:"===e.protocol)&&ej(e.hostname)))try{(0,o.validateDownloadUrl)(e.href)}catch(t){throw new eE({message:`OAuth endpoint URL is not allowed: ${e.href}`,cause:t})}}function eU(e){let t=new URL(e);return ej(t.hostname)?t.origin:void 0}function eO(e,t){return{...e,issuer:t.issuer,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function eM(e,t){return{...e,issuer:t.issuer,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function e$(e){if(e?.authorization_server&&e.token_endpoint)return{issuer:e.issuer,authorizationServerUrl:ek(e.authorization_server),tokenEndpoint:ek(e.token_endpoint)}}async function eH({provider:e,clientInformation:t,tokens:r}){let o=e$(r);if(o)return o;let n=await e.authorizationServerInformation?.();return n?{issuer:n.issuer,authorizationServerUrl:ek(n.authorizationServerUrl),tokenEndpoint:ek(n.tokenEndpoint)}:e$(t)}async function eL({provider:e,clientInformation:t,authorizationServerInformation:r}){return e.saveAuthorizationServerInformation?(await e.saveAuthorizationServerInformation(r),!0):!!e.saveClientInformation&&(await e.saveClientInformation(eM(t,r)),!0)}function eN({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:t}){if(null!=e.issuer&&null!=t.issuer&&e.issuer!==t.issuer||e.authorizationServerUrl!==t.authorizationServerUrl||e.tokenEndpoint!==t.tokenEndpoint)throw new eE({message:"OAuth authorization server metadata does not match the metadata that issued the stored credentials"})}function eV(e){let t,r=e.headers.get("www-authenticate")??e.headers.get("WWW-Authenticate");if(!r)return{};let[o,n]=r.split(" ");if("bearer"!==o.toLowerCase()||!n)return{};let i=r.match(/(?:^|[,\s])resource_metadata="([^"]*)"/i),s=r.match(/(?:^|[,\s])scope="([^"]*)"/i)?.[1];try{t=i?new URL(i[1]):void 0}catch{}return{resourceMetadataUrl:t,scope:s}}async function eq(e,t,r=fetch,n){try{return await (0,o.fetchUntrustedUrl)({url:e.href,fetch:async(e,i)=>(0,o.fetchWithValidatedEndpoint)({url:e,init:{...i,headers:new Headers(i?.headers).has("MCP-Protocol-Version")?t:void 0},fetch:r,trustedOrigin:n,redirect:"manual"}),headers:t,trustedOrigin:n,untrustedFirstHopHeaders:["mcp-protocol-version"]})}catch(o){if(o instanceof TypeError)if(t)return eq(e,void 0,r,n);else return;throw o}}async function eD(e,t,r=fetch,o){return await eq(e,{"MCP-Protocol-Version":t},r,o)}async function eF(e,t,r,o){var n,i;let s,a=new URL(e),l=o?.protocolVersion??"2026-07-28";o?.metadataUrl?s=new URL(o.metadataUrl):(s=new URL(function(e,t="",r={}){return t.endsWith("/")&&(t=t.slice(0,-1)),r.prependPathname?`${t}/.well-known/${e}`:`/.well-known/${e}${t}`}(t,a.pathname),o?.metadataServerUrl??a)).search=a.search;let c=await eD(s,l,r,o?.trustedOrigin);return!o?.metadataUrl&&(n=c,i=a.pathname,!n||n.status>=400&&n.status<500&&"/"!==i)&&(c=await eD(new URL(`/.well-known/${t}`,a),l,r,o?.trustedOrigin)),c}async function eB(e,t,r=fetch){let o=await eF(e,"oauth-protected-resource",r,{protocolVersion:t?.protocolVersion,metadataUrl:t?.resourceMetadataUrl,trustedOrigin:new URL(e).origin});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 em.parse(await o.json())}function eW(e,t){if(e.issuer!==t&&(t!==new URL(t).origin||e.issuer!==`${t}/`))throw new eE({message:`OAuth authorization server metadata issuer ${e.issuer} does not match expected issuer ${t}`})}async function eJ(e,{fetchFn:t=fetch,protocolVersion:r=h,trustedOrigin:o}={}){let n={"MCP-Protocol-Version":r};for(let{url:r,type:i,expectedIssuer:s}of function(e){let t="string"==typeof e?new URL(e):e,r="/"!==t.pathname,o=t.origin,n=[];if(!r)return n.push({url:new URL("/.well-known/oauth-authorization-server",t.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL("/.well-known/openid-configuration",t.origin),type:"oidc",expectedIssuer:o}),n;let i=t.pathname;i.endsWith("/")&&(i=i.slice(0,-1));let s=`${t.origin}${i}`;return n.push({url:new URL(`/.well-known/oauth-authorization-server${i}`,t.origin),type:"oauth",expectedIssuer:s}),n.push({url:new URL("/.well-known/oauth-authorization-server",t.origin),type:"oauth",expectedIssuer:o}),n.push({url:new URL(`/.well-known/openid-configuration${i}`,t.origin),type:"oidc",expectedIssuer:s}),n.push({url:new URL(`${i}/.well-known/openid-configuration`,t.origin),type:"oidc",expectedIssuer:s}),n}(e)){let e=await eq(r,n,t,o);if(e){if(!e.ok){if(e.status>=400&&e.status<500)continue;throw Error(`HTTP ${e.status} trying to load ${"oauth"===i?"OAuth":"OpenID provider"} metadata from ${r}`)}if("oauth"===i){let t=ef.parse(await e.json());return eW(t,s),t}{let t=ez.parse(await e.json());if(eW(t,s),!t.code_challenge_methods_supported?.includes("S256"))throw Error(`Incompatible OIDC provider at ${r}: does not support S256 code challenge method required by MCP specification`);return t}}}}async function eZ(e,{metadata:t,clientInformation:r,redirectUrl:o,scope:n,state:i,resource:s}){let a,l="code",c="S256";if(t){if(a=new URL(t.authorization_endpoint),!t.response_types_supported.includes(l))throw Error(`Incompatible auth server: does not support response type ${l}`);if(!t.code_challenge_methods_supported||!t.code_challenge_methods_supported.includes(c))throw Error(`Incompatible auth server: does not support code challenge method ${c}`)}else a=new URL("/authorize",e);let u=await p(),h=u.code_verifier,d=u.code_challenge;return a.searchParams.set("response_type",l),a.searchParams.set("client_id",r.client_id),a.searchParams.set("code_challenge",d),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),n?.includes("offline_access")&&a.searchParams.append("prompt","consent"),s&&a.searchParams.set("resource",eR(s)),{authorizationUrl:a,codeVerifier:h}}function eK(e,t){let r=void 0!==e.client_secret;return 0===t.length?r?"client_secret_post":"none":r&&t.includes("client_secret_basic")?"client_secret_basic":r&&t.includes("client_secret_post")?"client_secret_post":t.includes("none")?"none":r?"client_secret_post":"none"}function eG(e,t,r,o){let{client_id:n,client_secret:i}=t;switch(e){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: ${e}`)}}async function eY(e){let t=e instanceof Response?e.status:void 0,r=e instanceof Response?await e.text():e;try{let{error:e,error_description:t,error_uri:n}=ey.parse(await (0,o.parseJSON)({text:r}));return new(ex[e]||eS)({message:t||"",cause:n})}catch(e){return new eS({message:`${t?`HTTP ${t}: `:""}Invalid OAuth error response: ${e}. Raw body: ${r}`})}}async function eX(e,{metadata:t,clientInformation:r,authorizationCode:n,codeVerifier:i,redirectUri:s,resource:a,addClientAuthentication:l,fetchFn:c}){let u="authorization_code",p=t?.token_endpoint?new URL(t.token_endpoint):new URL("/token",e),h=eU(e);if(eA(p,{allowLoopback:p.origin===h}),t?.grant_types_supported&&!t.grant_types_supported.includes(u))throw Error(`Incompatible auth server: does not support grant type ${u}`);let d=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),m=new URLSearchParams({grant_type:u,code:n,code_verifier:i,redirect_uri:String(s)});l?await l(d,m,e,t):eG(eK(r,t?.token_endpoint_auth_methods_supported??[]),r,d,m),a&&m.set("resource",eR(a));let f=await (0,o.fetchWithValidatedEndpoint)({url:p,init:{method:"POST",headers:d,body:m},fetch:c,trustedOrigin:h});if(!f.ok)throw await eY(f);return ed.parse(await f.json())}async function eQ(e,{metadata:t,clientInformation:r,refreshToken:n,resource:i,addClientAuthentication:s,fetchFn:a}){let l,c="refresh_token";if(t){if(l=new URL(t.token_endpoint),t.grant_types_supported&&!t.grant_types_supported.includes(c))throw Error(`Incompatible auth server: does not support grant type ${c}`)}else l=new URL("/token",e);let u=eU(e);eA(l,{allowLoopback:l.origin===u});let p=new Headers({"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}),h=new URLSearchParams({grant_type:c,refresh_token:n});s?await s(p,h,e,t):eG(eK(r,t?.token_endpoint_auth_methods_supported??[]),r,p,h),i&&h.set("resource",eR(i));let d=await (0,o.fetchWithValidatedEndpoint)({url:l,init:{method:"POST",headers:p,body:h},fetch:a,trustedOrigin:u});if(!d.ok)throw await eY(d);return ed.parse({refresh_token:n,...await d.json()})}async function e0(e,{metadata:t,clientMetadata:r,fetchFn:n}){let i;if(t){if(!t.registration_endpoint)throw Error("Incompatible auth server: does not support dynamic client registration");i=new URL(t.registration_endpoint)}else i=new URL("/register",e);let s=eU(e);eA(i,{allowLoopback:i.origin===s});let a=r.application_type??(r.redirect_uris.every(e=>{let t=new URL(e);return("http:"===t.protocol||"https:"===t.protocol)&&ej(t.hostname)||"http:"!==t.protocol&&"https:"!==t.protocol})?"native":"web"),l=await (0,o.fetchWithValidatedEndpoint)({url:i,init:{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,application_type:a})},fetch:n,trustedOrigin:s});if(!l.ok)throw await eY(l);return eb.parse(await l.json())}async function e1(e,t){try{return await e4(e,t)}catch(r){if(r instanceof eC||r instanceof eP){if(void 0!==t.authorizationCode||!await e.isClientInformationDynamicallyRegistered?.())throw r;return await e.invalidateCredentials?.("all"),await e4(e,t)}if(r instanceof eT)return await e.invalidateCredentials?.("tokens"),await e4(e,t);throw r}}async function e2(e,t,r){let o,n=((o=new URL("string"==typeof e?e:e.href)).hash="",o);if(t.validateResourceURL)return await t.validateResourceURL(n,r?.resource);if(r){if(!function({requestedResource:e,configuredResource:t}){let r=new URL("string"==typeof e?e:e.href),o=new URL("string"==typeof t?t:t.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 e4(e,{serverUrl:t,authorizationCode:r,callbackState:o,callbackIssuer:n,scope:i,resourceMetadataUrl:s,fetchFn:a}){var l;let c,u,p,h;!function(e,t){if(!t)return;let r=new URL(e).origin;if(t.origin!==r)throw new eE({message:`OAuth protected resource metadata URL ${t.href} must have the same origin as the MCP server URL ${r}`})}(t,s);try{(c=await eB(t,{resourceMetadataUrl:s},a)).authorization_servers&&c.authorization_servers.length>0&&(u=c.authorization_servers[0])}catch{}void 0!==r&&(p=await Promise.resolve(e.clientInformation()))&&(h=await eH({provider:e,clientInformation:p})),u||(u=h?.authorizationServerUrl??t);let d=new URL(t),m=new URL(u),f=d.origin,z=m.origin,g=z===f||ej(d.hostname)&&ej(m.hostname)?z:void 0;g||eA(new URL(u));let w=await e2(t,e,c);await e.validateAuthorizationServerURL?.(t,u);let y=await eJ(u,{fetchFn:a,trustedOrigin:g}),b=(l=u,{issuer:y?.issuer??String(l),authorizationServerUrl:ek(l),tokenEndpoint:ek(y?.token_endpoint?new URL(y.token_endpoint):new URL("/token",l))}),v=e.clientMetadata,_=function({scope:e,resourceMetadata:t,clientMetadata:r}){if(e)return e;let o=t?.scopes_supported?.join(" ");return o||r.scope}({scope:i,resourceMetadata:c,clientMetadata:v});if(void 0===r&&(p=await Promise.resolve(e.clientInformation())),p?.issuer!=null){let t=h??await eH({provider:e,clientInformation:p});t&&eN({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:b})}if(!p){if(void 0!==r)throw Error("Existing OAuth client information is required when exchanging an authorization code");if(!e.saveClientInformation)throw Error("OAuth client information must be saveable for dynamic registration");p=eM(await e0(u,{metadata:y,clientMetadata:{...v,scope:_},fetchFn:a}),b),await e.saveClientInformation(p)}if(void 0!==r){if(e.storedState){let t=await e.storedState();if(void 0!==t&&t!==o)throw Error("OAuth state parameter mismatch - possible CSRF attack")}let t=h??await eH({provider:e,clientInformation:p});if(!t)throw new eE({message:"Stored OAuth authorization server metadata is required when exchanging an authorization code"});!function({callbackIssuer:e,expectedIssuer:t}){if(null!=e&&e!==t)throw new eE({message:`OAuth authorization response issuer ${e} does not match expected issuer ${t}`})}({callbackIssuer:n,expectedIssuer:t.issuer??y?.issuer??String(u)}),eN({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:b});let i=await e.codeVerifier(),s=await eX(u,{metadata:y,clientInformation:p,authorizationCode:r,codeVerifier:i,redirectUri:e.redirectUrl,resource:w,addClientAuthentication:e.addClientAuthentication,fetchFn:a});return await e.saveTokens(eO(s,b)),"AUTHORIZED"}let E=await e.tokens();if(E?.refresh_token){let t=await eH({provider:e,clientInformation:p,tokens:E});t?eN({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:b}):await e.invalidateCredentials?.("tokens");try{if(t){let t=await eQ(u,{metadata:y,clientInformation:p,refreshToken:E.refresh_token,resource:w,addClientAuthentication:e.addClientAuthentication,fetchFn:a});return await e.saveTokens(eO(t,b)),"AUTHORIZED"}}catch(e){if(!(e instanceof eE)||e instanceof eS);else throw e}}let S=e.state?await e.state():void 0;S&&e.saveState&&await e.saveState(S);let{authorizationUrl:C,codeVerifier:T}=await eZ(u,{metadata:y,clientInformation:p,state:S,redirectUrl:e.redirectUrl,scope:_,resource:w});if(!await eL({provider:e,clientInformation:p,authorizationServerInformation:b}))throw new eE({message:"OAuth authorization server metadata must be saveable before starting authorization"});return await e.saveCodeVerifier(T),await e.redirectToAuthorization(C),"REDIRECT"}var e5=class{constructor({url:e,headers:t,authProvider:r,redirect:o="error",fetch:n}){this.connected=!1,this.url=new URL(e),this.headers=t,this.authProvider=r,this.redirectMode=o,this.fetchFn=n??globalThis.fetch}setProtocolVersion(e){this.protocolVersion=e}async commonHeaders(e){let t={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??"2025-11-25"};if(this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(t.Authorization=`Bearer ${e.access_token}`)}return(0,o.withUserAgentSuffix)(t,`ai-sdk/${ep}`,(0,o.getRuntimeEnvironmentUserAgent)())}authorizeOnce(e,t){return this.authProvider?(this.authPromise||(this.authPromise=e1(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:e,scope:t,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0})),this.authPromise):Promise.resolve("REDIRECT")}async accessTokenChanged(e){let t=(await this.authProvider?.tokens())?.access_token;return null!=t&&e!==`Bearer ${t}`}async start(){return new Promise((e,t)=>{if(this.connected)return e();this.abortController=new AbortController;let o=async(n=!1)=>{try{let i=await this.commonHeaders({Accept:"text/event-stream"}),s=await this.fetchFn(this.url.href,{headers:i,signal:this.abortController?.signal,redirect:this.redirectMode});if(401===s.status&&this.authProvider&&!n){let{resourceMetadataUrl:e,scope:r}=eV(s);this.resourceMetadataUrl=e;try{if(await this.authorizeOnce(this.resourceMetadataUrl,r)!=="AUTHORIZED"){let e=new eI;return this.onerror?.(e),t(e)}}catch(e){return this.onerror?.(e),t(e)}return o(!0)}if(!s.ok||!s.body){let e=`MCP SSE Transport Error: ${s.status} ${s.statusText}`;405===s.status&&(e+=". This server does not support SSE transport. Try using `http` transport instead");let r=new eu({message:e});return this.onerror?.(r),t(r)}let a=s.body.pipeThrough(new TextDecoderStream).pipeThrough(new r.EventSourceParserStream).getReader(),l=async()=>{try{for(;;){let{done:t,value:r}=await a.read();if(t){if(this.connected)throw this.connected=!1,new eu({message:"MCP SSE Transport Error: Connection closed unexpectedly"});return}let{event:o,data:n}=r;if("endpoint"===o){if(this.endpoint)continue;let t=new URL(n,this.url);if(t.origin!==this.url.origin)throw this.connected=!1,this.endpoint=void 0,this.sseConnection?.close(),this.abortController?.abort(),new eu({message:`MCP SSE Transport Error: Endpoint origin does not match connection origin: ${t.origin}`});this.endpoint=t,this.connected=!0,e()}else if(void 0===o||"message"===o)try{let e=await ea(n);this.onmessage?.(e)}catch(t){let e=new eu({message:"MCP SSE Transport Error: Failed to parse message",cause:t});this.onerror?.(e)}}}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),t(e)}};this.sseConnection={close:()=>a.cancel()},l()}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),t(e)}};o()})}async close(){this.connected=!1,this.endpoint=void 0,this.sseConnection?.close(),this.abortController?.abort(),this.onclose?.()}async send(e,t){if(t?.signal?.throwIfAborted(),!this.endpoint||!this.connected)throw new eu({message:"MCP SSE Transport Error: Not connected"});let r=this.endpoint,o=this.abortController?.signal,n=t?.signal==null?o:null==o?t.signal:AbortSignal.any([o,t.signal]),i=async(o=!1)=>{try{let t=await this.commonHeaders({"Content-Type":"application/json"}),s={method:"POST",headers:t,body:JSON.stringify(e),signal:n,redirect:this.redirectMode},a=await this.fetchFn(r.href,s);if(401===a.status&&this.authProvider&&!o){if(await this.accessTokenChanged(new Headers(t).get("authorization")??void 0))return i(!0);let{resourceMetadataUrl:e,scope:r}=eV(a);if(this.resourceMetadataUrl=e,await this.authorizeOnce(this.resourceMetadataUrl,r)!=="AUTHORIZED")throw new eI;return i(!0)}if(!a.ok){let e=await a.text().catch(()=>null);throw new eu({message:`MCP SSE Transport Error: POSTing to endpoint (HTTP ${a.status}): ${e}`,statusCode:a.status,url:r.href,responseBody:e??void 0})}}catch(e){if(t?.signal?.aborted)throw e;throw this.onerror?.(e),e}};await i()}};let e3=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,e6=/^=\?base64\?.*\?=$/;function e8(e){return[...e].every(e=>{let t=e.charCodeAt(0);return 9===t||t>=32&&t<=126})&&e.trim()===e&&!e6.test(e)?e:`=?base64?${(0,o.convertUint8ArrayToBase64)(new TextEncoder().encode(e))}?=`}function e7(e){return void 0===e||"message"===e}var e9=class{constructor({url:e,headers:t,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(e),this.headers=t,this.authProvider=r,this.redirectMode=o,this.sessionId=n,this.protocolVersion=i??"2025-11-25",this.onSessionIdChange=s,this.onSessionExpired=a,this.terminateSessionOnClose=l,this.fetchFn=c??globalThis.fetch}setProtocolVersion(e){if(this.protocolVersion=e,this.abortController){if(this.isModernProtocol()){this.inboundSseConnection?.close(),this.inboundSseConnection=void 0;return}this.inboundSseConnection||this.startInboundSse()}}isModernProtocol(){return(this.protocolVersion??"2026-07-28")===h}async commonHeaders({base:e,includeSessionId:t=!0}){let r={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??"2025-11-25"};if(!this.isModernProtocol()&&t&&this.sessionId&&(r["mcp-session-id"]=this.sessionId),this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(r.Authorization=`Bearer ${e.access_token}`)}return(0,o.withUserAgentSuffix)(r,`ai-sdk/${ep}`,(0,o.getRuntimeEnvironmentUserAgent)())}setSessionId(e){this.sessionId!==e&&(this.sessionId=e,this.onSessionIdChange?.(e))}applySessionIdFromResponse(e){if(this.isModernProtocol())return;let t=e.headers.get("mcp-session-id");t&&this.setSessionId(t)}expireSessionId(e){this.sessionId===e&&this.setSessionId(void 0),this.onSessionExpired?.(e)}authorizeOnce(e,t){return this.authProvider?(this.authPromise||(this.authPromise=e1(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:e,scope:t,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0})),this.authPromise):Promise.resolve("REDIRECT")}async start(){if(this.abortController)throw new eu({message:"MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."});this.abortController=new AbortController,null!=this.protocolVersion&&"2026-07-28"!==this.protocolVersion&&this.startInboundSse()}async close(e){this.inboundSseConnection?.close(),this.abortController?.abort();try{if(!this.isModernProtocol()&&this.sessionId&&this.terminateSessionOnClose&&this.abortController){e?.signal?.throwIfAborted();let t=await this.commonHeaders({base:{}});e?.signal?.throwIfAborted(),await this.fetchFn(this.url.href,{method:"DELETE",headers:t,signal:e?.signal,redirect:this.redirectMode}).catch(()=>void 0)}}catch{}this.onclose?.()}async send(e,t){t?.signal?.throwIfAborted();let o=this.abortController?.signal,n=t?.signal==null?o:null==o?t.signal:AbortSignal.any([o,t.signal]),i=async(o=!1)=>{try{let s="method"in e&&"initialize"===e.method,a=s?void 0:this.sessionId,l={method:"POST",headers:await this.commonHeaders({base:{"Content-Type":"application/json",Accept:"application/json, text/event-stream",...this.isModernProtocol()?t?.headers:{},...this.isModernProtocol()&&"method"in e&&"id"in e?this.getStandardRequestHeaders(e):{}},includeSessionId:!s}),body:JSON.stringify(e),signal:n,redirect:this.redirectMode},c=await this.fetchFn(this.url.href,l);if(this.applySessionIdFromResponse(c),401===c.status&&this.authProvider&&!o){let{resourceMetadataUrl:e,scope:t}=eV(c);this.resourceMetadataUrl=e;try{if(await this.authorizeOnce(this.resourceMetadataUrl,t)!=="AUTHORIZED")throw new eI}catch(e){throw this.onerror?.(e),e}return i(!0)}if(202===c.status){this.isModernProtocol()||this.inboundSseConnection||this.startInboundSse();return}if(!c.ok){let t=await c.text().catch(()=>null);if("id"in e&&null!=t){let r=await ea(t).catch(()=>void 0);if(null!=r&&"error"in r)return void this.onmessage?.(null==r.id?{...r,id:e.id}:r)}let r=`MCP HTTP Transport Error: POSTing to endpoint (HTTP ${c.status}): ${t}`;404===c.status&&(!this.isModernProtocol()&&a?(this.expireSessionId(a),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 eu({message:r,statusCode:c.status,url:this.url.href,responseBody:t??void 0});throw this.onerror?.(o),o}if(!("id"in e))return;let u=c.headers.get("content-type")||"";if(u.includes("application/json")){let e=await c.json();for(let t of Array.isArray(e)?e.map(e=>es(e)):[es(e)])this.onmessage?.(t);return}if(u.includes("text/event-stream")){if(!c.body){let e=new eu({message:"MCP HTTP Transport Error: text/event-stream response without body",statusCode:c.status,url:this.url.href});throw this.onerror?.(e),e}let e=c.body.pipeThrough(new TextDecoderStream).pipeThrough(new r.EventSourceParserStream).getReader();(async()=>{try{for(;;){let{done:t,value:r}=await e.read();if(t)return;let{event:o,data:n}=r;if(e7(o))try{let e=await ea(n);this.onmessage?.(e)}catch(t){let e=new eu({message:"MCP HTTP Transport Error: Failed to parse message",cause:t});this.onerror?.(e)}}}catch(e){if(t?.signal?.aborted||e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e)}})().catch(e=>{t?.signal?.aborted||e instanceof Error&&"AbortError"===e.name||this.onerror?.(e)});return}let p=new eu({message:`MCP HTTP Transport Error: Unexpected content type: ${u}`,statusCode:c.status,url:this.url.href});throw this.onerror?.(p),p}catch(e){if(t?.signal?.aborted)throw e;throw this.onerror?.(e),e}};await i()}getStandardRequestHeaders(e){let t={"Mcp-Method":e.method},r=e.params,o="resources/read"===e.method?r?.uri:"tools/call"===e.method||"prompts/get"===e.method?r?.name:void 0;return"string"==typeof o&&(t["Mcp-Name"]=e8(o)),t}getNextReconnectionDelay(e){let{initialReconnectionDelay:t,reconnectionDelayGrowFactor:r,maxReconnectionDelay:o}=this.reconnectionOptions;return Math.min(t*Math.pow(r,e),o)}scheduleInboundSseReconnection(){let{maxRetries:e}=this.reconnectionOptions;if(e>0&&this.inboundReconnectAttempts>=e)return void this.onerror?.(new eu({message:`MCP HTTP Transport Error: Maximum reconnection attempts (${e}) exceeded.`}));let t=this.getNextReconnectionDelay(this.inboundReconnectAttempts);this.inboundReconnectAttempts+=1,setTimeout(()=>{this.abortController?.signal.aborted||this.startInboundSse(!1,this.lastInboundEventId)},t)}startInboundSse(e=!1,t){this.isModernProtocol()||this.openInboundSse(e,t).catch(e=>{e instanceof Error&&"AbortError"===e.name||this.onerror?.(e)})}async openInboundSse(e=!1,t){if(!this.isModernProtocol())try{let o=this.sessionId,n=await this.commonHeaders({base:{Accept:"text/event-stream"}});t&&(n["last-event-id"]=t);let i=await this.fetchFn(this.url.href,{method:"GET",headers:n,signal:this.abortController?.signal,redirect:this.redirectMode});if(this.applySessionIdFromResponse(i),401===i.status&&this.authProvider&&!e){let{resourceMetadataUrl:e,scope:r}=eV(i);this.resourceMetadataUrl=e;try{if(await this.authorizeOnce(this.resourceMetadataUrl,r)!=="AUTHORIZED"){let e=new eI;this.onerror?.(e);return}}catch(e){this.onerror?.(e);return}return this.openInboundSse(!0,t)}if(405===i.status)return;if(!i.ok||!i.body){404===i.status&&o&&this.expireSessionId(o);let e=new eu({message:`MCP HTTP Transport Error: GET SSE failed: ${i.status} ${i.statusText}`,statusCode:i.status,url:this.url.href});this.onerror?.(e);return}let s=i.body.pipeThrough(new TextDecoderStream).pipeThrough(new r.EventSourceParserStream).getReader(),a=async()=>{try{for(;;){let{done:e,value:t}=await s.read();if(e)return;let{event:r,data:o,id:n}=t;if(n&&(this.lastInboundEventId=n),e7(r))try{let e=await ea(o);this.onmessage?.(e)}catch(t){let e=new eu({message:"MCP HTTP Transport Error: Failed to parse message",cause:t});this.onerror?.(e)}}}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}};this.inboundSseConnection={close:()=>{s.cancel().catch(e=>{e instanceof Error&&"AbortError"===e.name||this.onerror?.(e)})}},this.inboundReconnectAttempts=0,a().catch(e=>{e instanceof Error&&"AbortError"===e.name||(this.onerror?.(e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection())})}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;this.onerror?.(e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}}};let te=n.array(n.unknown()).transform(e=>e.filter(e=>"string"==typeof e)).optional().catch(void 0),tt=n.looseObject({connectDomains:te,resourceDomains:te,frameDomains:te});n.looseObject({prefersBorder:n.boolean().optional().catch(void 0),csp:tt.optional().catch(void 0),permissions:n.record(n.string(),n.unknown()).optional().catch(void 0)});let tr=[-32020,-32021,-32022],to=["ConnectionRefused","ConnectionClosed","FailedToOpenSocket","ECONNRESET","ECONNREFUSED","ETIMEDOUT","EPIPE"];function tn(e){let t=function(e){if(null!=e&&"object"==typeof e&&"statusCode"in e&&"number"==typeof e.statusCode)return e.statusCode}(e);if(null!=t)return 408===t||409===t||429===t||t>=500;if(eu.isInstance(e)&&null!=e.code)return!1;let r=function(e){if(null!=e&&"object"==typeof e&&"code"in e&&"string"==typeof e.code)return e.code}(e);return null!=r&&to.includes(r)}function ti({timeout:e,maxTotalTimeout:t}){return null==e?t:null==t?e:Math.min(e,t)}function ts(e,t){return null==t?e:new Promise((r,o)=>{let n=()=>{t.removeEventListener("abort",i)},i=()=>{n(),o(t.reason)};t.aborted?i():(t.addEventListener("abort",i,{once:!0}),e.then(e=>{n(),r(e)}).catch(e=>{n(),o(e)}))})}function ta({output:e}){return"content"in e&&Array.isArray(e.content)?{type:"content",value:e.content.map(e=>"text"===e.type&&"text"in e?{type:"text",text:e.text}:"image"===e.type&&"data"in e&&"mimeType"in e?{type:"file",mediaType:e.mimeType,data:{type:"data",data:e.data}}:{type:"text",text:JSON.stringify(e)})}:{type:"json",value:e}}async function tl(e){let t=new tc(e);return await t.init(),t}var tc=class{constructor({transport:e,name:t,clientName:r=t??"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:d,capabilities:{},serverInfo:this._serverInfo},this.protocolEra="legacy",this.protocolVersion=d,this.toolHeaderBindings=new Map,this.isClosed=!0,this.onUncaughtError=n,this.maxRetries=function(e){if(null==e)return 0;if(!Number.isInteger(e))throw new eu({message:"maxRetries must be an integer"});if(e<0)throw new eu({message:"maxRetries must be >= 0"});return e}(i),this.clientCapabilities=s??{},this.initialInitializeResult=a,this.initializationOptions=l,this.protocolVersionDiscovery=c,function(e){return"start"in e&&"function"==typeof e.start&&"send"in e&&"function"==typeof e.send&&"close"in e&&"function"==typeof e.close}(e)?this.transport=e:this.transport=function(e){switch(e.type){case"sse":return new e5(e);case"http":return new e9({...e,initialProtocolVersion:e.initialProtocolVersion??"2026-07-28"});default:throw new eu({message:"Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."})}}(e),this.transport.onclose=()=>this.onClose(),this.transport.onerror=e=>this.onError(e),this.transport.onmessage=e=>{"method"in e?"id"in e?this.onRequestMessage(e):this.onError(new eu({message:"Unsupported message type"})):this.onResponse(e)},this.clientInfo={name:r,version:o}}get serverInfo(){return this._serverInfo}get initializeResult(){return this._initializeResult}get instructions(){return this._serverInstructions}async init(){let e,t,r=this.initializationOptions?.signal,o=this.initializationOptions?ti(this.initializationOptions):void 0,n=null==o?void 0:new AbortController,i=null==r?n?.signal:null==n?r:AbortSignal.any([r,n.signal]);null!=o&&(e=setTimeout(()=>{t=new eu({message:`MCP client initialization timed out after ${o}ms`}),n?.abort(t)},o));try{if(this.isClosed=!1,i?.throwIfAborted(),await ts(this.transport.start(),i),this.initialInitializeResult){let e=E.parse(this.initialInitializeResult);return this.applyInitializeResult(e),this}if(this.protocolVersionDiscovery&&this.transport.supportsProtocolVersionDiscovery&&await this.tryProtocolDiscovery(i))return this;this.protocolEra="legacy",this.protocolVersion=d,this.setTransportProtocolVersion(this.protocolVersion);let e=await this.request({request:{method:"initialize",params:{protocolVersion:d,capabilities:this.clientCapabilities,clientInfo:this.clientInfo}},resultSchema:E,options:{signal:i}});if(void 0===e)throw new eu({message:"Server sent invalid initialize result"});return this.applyInitializeResult(e),await this.notification({method:"notifications/initialized"},{signal:i}),this}catch(e){try{await ts(this.transport.close({signal:i}),i)}catch{}if(this.onClose(),null!=t)throw t;if(r?.aborted)throw new eu({message:"MCP client initialization was aborted",cause:r.reason});throw e}finally{null!=e&&clearTimeout(e)}}async tryProtocolDiscovery(e){this.protocolEra="modern",this.protocolVersion=h,this.setTransportProtocolVersion(this.protocolVersion);try{let t=await this.request({request:{method:"server/discover"},resultSchema:_,options:{signal:e,timeout:1e3}});return this.applyDiscoverResult(t),!0}catch(e){if(eu.isInstance(e)&&null!=e.code&&tr.includes(e.code))throw e;return!1}}applyDiscoverResult(e){if(!e.supportedVersions.includes(this.protocolVersion))throw new eu({message:`Server does not support the requested protocol version: ${this.protocolVersion}`});let t=e._meta?.["io.modelcontextprotocol/serverInfo"];null!=t&&"object"==typeof t&&"name"in t&&"string"==typeof t.name&&"version"in t&&"string"==typeof t.version&&(this._serverInfo=t),this.serverCapabilities=e.capabilities,this._serverInstructions=e.instructions,this._initializeResult={protocolVersion:this.protocolVersion,capabilities:e.capabilities,serverInfo:this._serverInfo,instructions:e.instructions}}setTransportProtocolVersion(e){this.transport.setProtocolVersion?this.transport.setProtocolVersion(e):this.transport.protocolVersion=e}applyInitializeResult(e){if(!m.includes(e.protocolVersion))throw new eu({message:`Server's protocol version is not supported: ${e.protocolVersion}`});this.serverCapabilities=e.capabilities,this.protocolEra="legacy",this.protocolVersion=e.protocolVersion,this._serverInfo=e.serverInfo,this._initializeResult=e,this.setTransportProtocolVersion(e.protocolVersion),this._serverInstructions=e.instructions}async close(){this.isClosed||(await this.transport?.close(),this.onClose())}send(e,t){return null==t?this.transport.send(e):this.transport.send(e,t)}assertCapability(e){switch(e){case"initialize":case"server/discover":break;case"completion/complete":if(!this.serverCapabilities.completions)throw new eu({message:"Server does not support completions"});break;case"tools/list":case"tools/call":if(!this.serverCapabilities.tools)throw new eu({message:"Server does not support tools"});break;case"resources/list":case"resources/read":case"resources/templates/list":if(!this.serverCapabilities.resources)throw new eu({message:"Server does not support resources"});break;case"prompts/list":case"prompts/get":if(!this.serverCapabilities.prompts)throw new eu({message:"Server does not support prompts"});break;default:throw new eu({message:`Unsupported method: ${e}`})}}async request({request:e,resultSchema:t,options:r}){return new Promise((o,n)=>{let i;if(this.isClosed)return n(new eu({message:"Attempted to send a request from a closed client"}));this.assertCapability(e.method);let s=r?.signal;s?.throwIfAborted();let a=null==r?void 0:ti(r),l=null==a?void 0:new AbortController,c=null==s?l?.signal:null==l?s:AbortSignal.any([s,l.signal]),u=this.requestMessageId++,p="modern"===this.protocolEra?{...e,params:{...e.params,_meta:{...e.params?._meta,"io.modelcontextprotocol/protocolVersion":this.protocolVersion,"io.modelcontextprotocol/clientCapabilities":this.clientCapabilities,"io.modelcontextprotocol/clientInfo":this.clientInfo}}}:e,h={...p,jsonrpc:"2.0",id:u},d=this.getToolRequestHeaders(p),m=()=>{n(new eu({message:"Request was aborted",cause:s?.reason}))},f=()=>{this.responseHandlers.delete(u),s?.removeEventListener("abort",g),null!=i&&clearTimeout(i)},z=e=>{f(),n(e)},g=()=>{f(),m()};this.responseHandlers.set(u,e=>{if(s?.aborted)return f(),m();if(e instanceof Error)return z(e);try{if("modern"===this.protocolEra&&null==e.result.resultType)throw new eu({message:"Modern MCP result is missing resultType"});if("input_required"===e.result.resultType)throw new eu({message:"Server requested additional input, but multi round-trip requests are not supported yet"});let r=t.parse(e.result);f(),o(r)}catch(e){z(eu.isInstance(e)?e:new eu({message:"Failed to parse server response",cause:e}))}}),s?.addEventListener("abort",g,{once:!0}),null!=a&&(i=setTimeout(()=>{let e=new eu({message:`Request timed out after ${a}ms`});l?.abort(e),z(e)},a));let w={...null==c?{}:{signal:c},...null==d?{}:{headers:d}};(0===Object.keys(w).length?this.send(h):this.send(h,w)).catch(e=>{z(e)})})}async listTools({params:e,options:t}={}){let r=await this.request({request:{method:"tools/list",params:e},resultSchema:T,options:t});return this.prepareToolDefinitions(r,e?.cursor==null)}prepareToolDefinitions(e,t=!1){if("modern"!==this.protocolEra||!this.transport.supportsMcpToolParameterHeaders)return e;t&&this.toolHeaderBindings.clear();let r=e.tools.filter(e=>{let t=function(e){let t;if(!(0,o.isRecord)(e))return{success:!1,error:"inputSchema must be a JSON Schema object"};let r=[],n=new Set,i=(e,s,a)=>{if(null==t&&(0,o.isRecord)(e)){if("x-mcp-header"in e){if(!a||0===s.length){t="x-mcp-header is not on a statically reachable property";return}let o=e["x-mcp-header"];if("string"!=typeof o||!e3.test(o)){t="x-mcp-header must be a non-empty HTTP token";return}let i=o.toLowerCase();if(n.has(i)){t=`x-mcp-header value "${o}" is not unique`;return}let l=e.type;if("boolean"!==l&&"integer"!==l&&"string"!==l){t="x-mcp-header can only annotate boolean, integer, or string properties";return}n.add(i),r.push({headerName:o,path:s,valueType:l})}for(let[t,r]of Object.entries(e))if("x-mcp-header"!==t)if("properties"===t&&(0,o.isRecord)(r))for(let[e,t]of Object.entries(r))i(t,[...s,e],a);else i(r,s,!1)}};return i(e,[],!0),null==t?{success:!0,bindings:r}:{success:!1,error:t}}(e.inputSchema);return t.success?(this.toolHeaderBindings.set(e.name,t.bindings),!0):(this.onError(new eu({message:`Ignoring MCP tool "${e.name}": ${t.error}`})),!1)});return{...e,tools:r}}getToolRequestHeaders(e){if("modern"!==this.protocolEra||"tools/call"!==e.method||"string"!=typeof e.params?.name)return;let t=this.toolHeaderBindings.get(e.params.name);if(null==t||0===t.length)return;let r=e.params.arguments;if(!(null==r||"object"!=typeof r||Array.isArray(r)))try{return function({bindings:e,args:t}){let r={};for(let n of e){let e=function(e,t){let r=e;for(let e of t){if(!(0,o.isRecord)(r))return;r=r[e]}return r}(t,n.path);if(null!=e){if("string"===n.valueType&&"string"!=typeof e||"boolean"===n.valueType&&"boolean"!=typeof e||"integer"===n.valueType&&!Number.isSafeInteger(e))throw TypeError(`Tool argument "${n.path.join(".")}" does not match its x-mcp-header type`);r[`Mcp-Param-${n.headerName}`]=e8(String(e))}}return r}({bindings:t,args:r})}catch(t){throw new eu({message:`Failed to create MCP headers for tool "${e.params.name}"`,cause:t})}}async callToolWithRetry({options:e,execute:t}){return 0===this.maxRetries?t():(0,o.retryWithExponentialBackoff)({maxRetries:this.maxRetries,abortSignal:e?.signal,shouldRetry:tn,createRetryError:({message:e,errors:t})=>new eu({message:e,cause:t[t.length-1]})})(t)}async callTool({name:e,arguments:t={},options:r}){return this.callToolWithRetry({options:r,execute:()=>this.request({request:{method:"tools/call",params:{name:e,arguments:t}},resultSchema:L,options:r})})}async listResourcesInternal({params:e,options:t}={}){return this.request({request:{method:"resources/list",params:e},resultSchema:I,options:t})}async readResourceInternal({uri:e,options:t}){return this.request({request:{method:"resources/read",params:{uri:e}},resultSchema:q,options:t})}async listResourceTemplatesInternal({options:e}={}){return this.request({request:{method:"resources/templates/list"},resultSchema:V,options:e})}async listPromptsInternal({params:e,options:t}={}){return this.request({request:{method:"prompts/list",params:e},resultSchema:K,options:t})}async getPromptInternal({name:e,args:t,options:r}){return this.request({request:{method:"prompts/get",params:{name:e,arguments:t}},resultSchema:Y,options:r})}async completeInternal({options:e,...t}){return this.request({request:{method:"completion/complete",params:t},resultSchema:W,options:e})}async notification(e,t){let r={...e,jsonrpc:"2.0"};await ts(this.send(r,t?.signal==null?void 0:{signal:t.signal}),t?.signal)}async tools({schemas:e="automatic"}={}){let t=await this.listTools(),r=[...t.tools];for(;null!=t.nextCursor;)t=await this.listTools({params:{cursor:t.nextCursor}}),r.push(...t.tools);return this.toolsFromDefinitions({...t,tools:r},{schemas:e})}toolsFromDefinitions(e,{schemas:t="automatic"}={}){e=this.prepareToolDefinitions(e);let r=Object.create(null);for(let{name:n,title:i,description:a,inputSchema:l,annotations:c,_meta:u}of e.tools){let e=i??c?.title;if("automatic"!==t&&!Object.prototype.hasOwnProperty.call(t,n))continue;let p=this,h="automatic"!==t?t[n]?.outputSchema:void 0,d=function(e){var t,r;let o,n=(t=e._meta,o=t?.ui,(0,s.isJSONObject)(o)?o:void 0),i=n?.resourceUri??e._meta?.["ui/resourceUri"],a=Array.isArray(r=n?.visibility)?r.filter(e=>"model"===e||"app"===e):void 0;if(void 0!==i){if("string"!=typeof i||!i.startsWith("ui://"))throw Error(`Invalid MCP App resource URI: ${JSON.stringify(i)}`)}else if(null==n)return;return{...n,...null!=i?{resourceUri:i}:{},...null!=a?{visibility:a}:{}}}({_meta:u}),m={clientName:this.clientInfo.name,toolName:n,...null!=e?{title:e}:{},...null!=c?{annotations:{...null!=c.title?{title:c.title}:{},...null!=c.readOnlyHint?{readOnlyHint:c.readOnlyHint}:{},...null!=c.destructiveHint?{destructiveHint:c.destructiveHint}:{},...null!=c.idempotentHint?{idempotentHint:c.idempotentHint}:{},...null!=c.openWorldHint?{openWorldHint:c.openWorldHint}:{}}}:{},...d?.resourceUri!=null?{app:{...d,mimeType:"text/html;profile=mcp-app"}}:{}},f=async(e,t)=>{t?.abortSignal?.throwIfAborted();let r=await p.callTool({name:n,arguments:e,options:{signal:t?.abortSignal}});return r.isError?r:null!=h?p.extractStructuredContent(r,h,n):r};r[n]={..."automatic"===t?(0,o.dynamicTool)({description:a,title:e,metadata:m,inputSchema:(0,o.jsonSchema)({...l,properties:l.properties??{},additionalProperties:!1}),execute:f,toModelOutput:ta}):(0,o.tool)({description:a,title:e,metadata:m,inputSchema:t[n].inputSchema,...null!=h?{outputSchema:h}:{},execute:f,toModelOutput:ta}),_meta:u}}return r}async extractStructuredContent(e,t,r){if("structuredContent"in e&&null!=e.structuredContent){let n=await (0,o.safeValidateTypes)({value:e.structuredContent,schema:(0,o.asSchema)(t)});if(!n.success)throw new eu({message:`Tool "${r}" returned structuredContent that does not match the expected outputSchema`,cause:n.error});return n.value}if("content"in e&&Array.isArray(e.content)){let n=e.content.find(e=>"text"===e.type);if(n&&"text"in n){let e=await (0,o.safeParseJSON)({text:n.text,schema:t});if(!e.success)throw new eu({message:`Tool "${r}" returned content that does not match the expected outputSchema`,cause:e.error});return e.value}}throw new eu({message:`Tool "${r}" did not return structuredContent or parseable text content`})}listResources({params:e,options:t}={}){return this.listResourcesInternal({params:e,options:t})}readResource({uri:e,options:t}){return this.readResourceInternal({uri:e,options:t})}listResourceTemplates({options:e}={}){return this.listResourceTemplatesInternal({options:e})}experimental_listPrompts({params:e,options:t}={}){return this.listPromptsInternal({params:e,options:t})}experimental_getPrompt({name:e,arguments:t,options:r}){return this.getPromptInternal({name:e,args:t,options:r})}complete(e){return this.completeInternal(e)}onElicitationRequest(e,t){if(e!==Q)throw new eu({message:"Unsupported request schema. Only ElicitationRequestSchema is supported."});this.elicitationRequestHandler=t}async onRequestMessage(e){try{if("ping"===e.method)return void await this.transport.send({jsonrpc:"2.0",id:e.id,result:{}});if("elicitation/create"!==e.method)return void await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32601,message:`Unsupported request method: ${e.method}`}});if(!this.elicitationRequestHandler)return void await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32601,message:"No elicitation handler registered on client"}});let t=Q.safeParse({method:e.method,params:e.params});if(!t.success)return void await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32602,message:`Invalid elicitation request: ${t.error.message}`,data:t.error.issues}});try{let r=await this.elicitationRequestHandler(t.data),o=ee.parse(r);await this.transport.send({jsonrpc:"2.0",id:e.id,result:o})}catch(t){await this.transport.send({jsonrpc:"2.0",id:e.id,error:{code:-32603,message:t instanceof Error?t.message:"Failed to handle elicitation request"}}),this.onError(t)}}catch(e){this.onError(e)}}onClose(){if(this.isClosed)return;this.isClosed=!0;let e=new eu({message:"Connection closed"});for(let t of this.responseHandlers.values())t(e);this.responseHandlers.clear()}onError(e){this.onUncaughtError&&this.onUncaughtError(e)}onResponse(e){if(null==e.id)return void this.onError(new eu({message:`Protocol error: Received a response without a message ID: ${JSON.stringify(e)}`}));let t=Number(e.id),r=this.responseHandlers.get(t);if(void 0===r)throw new eu({message:`Protocol error: Received a response for an unknown message ID: ${JSON.stringify(e)}`});this.responseHandlers.delete(t),r("result"in e?e:new eu({message:e.error.message,code:e.error.code,data:e.error.data,cause:e.error}))}};new TextEncoder,e.s(["UnauthorizedError",0,eI,"auth",0,e1,"createMCPClient",0,tl],361164)},202058,(e,t,r)=>{t.exports=n,n.sync=function(e,t){return i(o.statSync(e),t)};var o=e.r(522734);function n(e,t,r){o.stat(e,function(e,o){r(e,!e&&i(o,t))})}function i(e,t){var r,o,n,i,s,a,l,c,u;return e.isFile()&&(r=e,o=t,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,(e,t,r)=>{t.exports=i,i.sync=function(e,t){return n(o.statSync(e),e,t)};var o=e.r(522734);function n(e,t,r){if(!e.isSymbolicLink()&&!e.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&&t.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,r){o.stat(e,function(o,i){r(o,!o&&n(i,e,t))})}},24214,(e,t,r)=>{var o;function n(e,t,r){if("function"==typeof t&&(r=t,t={}),!r){if("function"!=typeof Promise)throw TypeError("callback not provided");return new Promise(function(r,o){n(e,t||{},function(e,t){e?o(e):r(t)})})}o(e,t||{},function(e,o){e&&("EACCES"===e.code||t&&t.ignoreErrors)&&(e=null,o=!1),r(e,o)})}e.r(522734),o="win32"===process.platform||e.g.TESTING_WINDOWS?e.r(129507):e.r(202058),t.exports=n,n.sync=function(e,t){try{return o.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||"EACCES"===e.code)return!1;throw e}}},319932,(e,t,r)=>{let o="win32"===process.platform||"cygwin"===process.env.OSTYPE||"msys"===process.env.OSTYPE,n=e.r(814747),i=o?";":":",s=e.r(24214),a=e=>Object.assign(Error(`not found: ${e}`),{code:"ENOENT"}),l=(e,t)=>{let r=t.colon||i,n=e.match(/\//)||o&&e.match(/\\/)?[""]:[...o?[process.cwd()]:[],...(t.path||process.env.PATH||"").split(r)],s=o?t.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",a=o?s.split(r):[""];return o&&-1!==e.indexOf(".")&&""!==a[0]&&a.unshift(""),{pathEnv:n,pathExt:a,pathExtExe:s}},c=(e,t,r)=>{"function"==typeof t&&(r=t,t={}),t||(t={});let{pathEnv:o,pathExt:i,pathExtExe:c}=l(e,t),u=[],p=r=>new Promise((i,s)=>{if(r===o.length)return t.all&&u.length?i(u):s(a(e));let l=o[r],c=/^".*"$/.test(l)?l.slice(1,-1):l,p=n.join(c,e);i(h(!c&&/^\.[\\\/]/.test(e)?e.slice(0,2)+p:p,r,0))}),h=(e,r,o)=>new Promise((n,a)=>{if(o===i.length)return n(p(r+1));let l=i[o];s(e+l,{pathExt:c},(i,s)=>{if(!i&&s)if(!t.all)return n(e+l);else u.push(e+l);return n(h(e,r,o+1))})});return r?p(0).then(e=>r(null,e),r):p(0)};t.exports=c,c.sync=(e,t)=>{let{pathEnv:r,pathExt:o,pathExtExe:i}=l(e,t=t||{}),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,e),h=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+p:p;for(let e=0;e<o.length;e++){let r=h+o[e];try{if(s.sync(r,{pathExt:i}))if(!t.all)return r;else c.push(r)}catch(e){}}}if(t.all&&c.length)return c;if(t.nothrow)return null;throw a(e)}},625881,(e,t,r)=>{"use strict";let o=(e={})=>{let t=e.env||process.env;return"win32"!==(e.platform||process.platform)?"PATH":Object.keys(t).reverse().find(e=>"PATH"===e.toUpperCase())||"Path"};t.exports=o,t.exports.default=o},81463,(e,t,r)=>{"use strict";let o=e.r(814747),n=e.r(319932),i=e.r(625881);function s(e,t){let r,s=e.options.env||process.env,a=process.cwd(),l=null!=e.options.cwd,c=l&&void 0!==process.chdir&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch(e){}try{r=n.sync(e.command,{path:s[i({env:s})],pathExt:t?o.delimiter:void 0})}catch(e){}finally{c&&process.chdir(a)}return r&&(r=o.resolve(l?e.options.cwd:"",r)),r}t.exports=function(e){return s(e)||s(e,!0)}},502977,(e,t,r)=>{"use strict";let o=/([()\][%!^"`<>&|;, *?])/g;t.exports.command=function(e){return e.replace(o,"^$1")},t.exports.argument=function(e,t){return e=(e=(e=`${e}`).replace(/(?=(\\+?)?)\1"/g,'$1$1\\"')).replace(/(?=(\\+?)?)\1$/,"$1$1"),e=(e=`"${e}"`).replace(o,"^$1"),t&&(e=e.replace(o,"^$1")),e}},831804,(e,t,r)=>{"use strict";t.exports=/^#!(.*)/},469231,(e,t,r)=>{"use strict";let o=e.r(831804);t.exports=(e="")=>{let t=e.match(o);if(!t)return null;let[r,n]=t[0].replace(/#! ?/,"").split(" "),i=r.split("/").pop();return"env"===i?n:n?`${i} ${n}`:i}},385328,(e,t,r)=>{"use strict";let o=e.r(522734),n=e.r(469231);t.exports=function(e){let t,r=Buffer.alloc(150);try{t=o.openSync(e,"r"),o.readSync(t,r,0,150,0),o.closeSync(t)}catch(e){}return n(r.toString())}},207546,(e,t,r)=>{"use strict";e.r(814747),e.r(81463),e.r(502977),e.r(385328),process.platform,t.exports=function(e,t,r){t&&!Array.isArray(t)&&(r=t,t=null);let o={command:e,args:t=t?t.slice(0):[],options:r=Object.assign({},r),file:void 0,original:{command:e,args:t}};return r.shell,o}},245750,(e,t,r)=>{"use strict";process.platform,t.exports={hookChildProcess:function(e,t){},verifyENOENT:function(e,t){return null},verifyENOENTSync:function(e,t){return null},notFoundError:function(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}}},465887,(e,t,r)=>{"use strict";let o=e.r(233405),n=e.r(207546),i=e.r(245750);function s(e,t,r){let s=n(e,t,r),a=o.spawn(s.command,s.args,s.options);return i.hookChildProcess(a,s),a}t.exports=s,t.exports.spawn=s,t.exports.sync=function(e,t,r){let s=n(e,t,r),a=o.spawnSync(s.command,s.args,s.options);return a.error=a.error||i.verifyENOENTSync(a.status,s),a},t.exports._parse=n,t.exports._enoent=i},958560,e=>{"use strict";var t=e.i(847841),r=e.i(469719),o=e.i(376261),n=e.i(465887);let i=r.z.optional(r.z.record(r.z.string(),r.z.unknown())),s=r.z.looseObject({name:r.z.string(),version:r.z.string(),title:r.z.optional(r.z.string())}),a=r.z.looseObject({_meta:r.z.optional(r.z.object({}).loose())}),l=a.extend({resultType:r.z.optional(r.z.string())}),c=r.z.object({method:r.z.string(),params:r.z.optional(a)}),u=r.z.object({applyDefaults:r.z.optional(r.z.boolean())}).loose(),p=r.z.looseObject({experimental:r.z.optional(r.z.object({}).loose()),logging:r.z.optional(r.z.object({}).loose()),completions:r.z.optional(r.z.object({}).loose()),prompts:r.z.optional(r.z.looseObject({listChanged:r.z.optional(r.z.boolean())})),resources:r.z.optional(r.z.looseObject({subscribe:r.z.optional(r.z.boolean()),listChanged:r.z.optional(r.z.boolean())})),tools:r.z.optional(r.z.looseObject({listChanged:r.z.optional(r.z.boolean())})),elicitation:r.z.optional(u)});r.z.object({elicitation:r.z.optional(u)}).loose(),l.extend({supportedVersions:r.z.array(r.z.string()),capabilities:p,instructions:r.z.optional(r.z.string()),ttlMs:r.z.optional(r.z.number()),cacheScope:r.z.optional(r.z.union([r.z.literal("public"),r.z.literal("private")]))}),l.extend({protocolVersion:r.z.string(),capabilities:p,serverInfo:s,instructions:r.z.optional(r.z.string())});let h=l.extend({nextCursor:r.z.optional(r.z.string())}),d=r.z.object({name:r.z.string(),title:r.z.optional(r.z.string()),description:r.z.optional(r.z.string()),inputSchema:r.z.looseObject({type:r.z.optional(r.z.unknown()),properties:r.z.optional(r.z.object({}).loose())}),outputSchema:r.z.optional(r.z.object({}).loose()),annotations:r.z.optional(r.z.object({title:r.z.optional(r.z.string()),readOnlyHint:r.z.optional(r.z.boolean()),destructiveHint:r.z.optional(r.z.boolean()),idempotentHint:r.z.optional(r.z.boolean()),openWorldHint:r.z.optional(r.z.boolean())}).loose()),_meta:i}).loose();h.extend({tools:r.z.array(d)});let m=r.z.object({type:r.z.literal("text"),text:r.z.string()}).loose(),f=r.z.object({type:r.z.literal("image"),data:r.z.base64(),mimeType:r.z.string()}).loose(),z=r.z.object({uri:r.z.string(),name:r.z.string(),title:r.z.optional(r.z.string()),description:r.z.optional(r.z.string()),mimeType:r.z.optional(r.z.string()),size:r.z.optional(r.z.number())}).loose();h.extend({resources:r.z.array(z)});let g=r.z.object({uri:r.z.string(),name:r.z.optional(r.z.string()),title:r.z.optional(r.z.string()),mimeType:r.z.optional(r.z.string())}).loose(),w=g.extend({text:r.z.string()}),y=g.extend({blob:r.z.base64()}),b=r.z.object({type:r.z.literal("resource"),resource:r.z.union([w,y])}).loose(),v=r.z.object({type:r.z.literal("resource_link"),uri:r.z.string(),name:r.z.string(),description:r.z.optional(r.z.string()),mimeType:r.z.optional(r.z.string())}).loose(),_=r.z.object({type:r.z.string()}).loose().refine(e=>!["text","image","resource","resource_link"].includes(e.type),{message:"Known content types must match their schema"}),E=l.extend({content:r.z.array(r.z.union([m,f,b,v,_])),structuredContent:r.z.optional(r.z.unknown()),isError:r.z.boolean().default(!1).optional()}),S=l.extend({content:r.z.never().optional(),structuredContent:r.z.json(),isError:r.z.boolean().default(!1).optional()}).transform(e=>({...e,content:[{type:"text",text:JSON.stringify(e.structuredContent)}]})).pipe(E);E.or(S).or(l.extend({toolResult:r.z.unknown().nonoptional()}));let C=r.z.object({uriTemplate:r.z.string(),name:r.z.string(),title:r.z.optional(r.z.string()),description:r.z.optional(r.z.string()),mimeType:r.z.optional(r.z.string())}).loose();l.extend({resourceTemplates:r.z.array(C)}),l.extend({contents:r.z.array(r.z.union([w,y]))});let T=r.z.object({type:r.z.literal("ref/prompt"),name:r.z.string()}).loose(),P=r.z.object({type:r.z.literal("ref/resource"),uri:r.z.string()}).loose(),x=r.z.object({name:r.z.string(),value:r.z.string()}).loose();a.extend({ref:r.z.union([T,P]),argument:x,context:r.z.optional(r.z.object({arguments:r.z.record(r.z.string(),r.z.string())}).loose())}),l.extend({completion:r.z.object({values:r.z.array(r.z.string()).max(100),total:r.z.optional(r.z.number().int()),hasMore:r.z.optional(r.z.boolean())}).loose()});let R=r.z.object({name:r.z.string(),description:r.z.optional(r.z.string()),required:r.z.optional(r.z.boolean())}).loose(),I=r.z.object({name:r.z.string(),title:r.z.optional(r.z.string()),description:r.z.optional(r.z.string()),arguments:r.z.optional(r.z.array(R))}).loose();h.extend({prompts:r.z.array(I)});let k=r.z.object({role:r.z.union([r.z.literal("user"),r.z.literal("assistant")]),content:r.z.union([m,f,b,v])}).loose();l.extend({description:r.z.optional(r.z.string()),messages:r.z.array(k)});let j=a.extend({message:r.z.string(),requestedSchema:r.z.unknown()});c.extend({method:r.z.literal("elicitation/create"),params:j}),l.extend({action:r.z.union([r.z.literal("accept"),r.z.literal("decline"),r.z.literal("cancel")]),content:r.z.optional(r.z.record(r.z.string(),r.z.unknown()))});let A=r.z.object({jsonrpc:r.z.literal("2.0"),id:r.z.union([r.z.string(),r.z.number().int()])}).merge(c).strict(),U=r.z.object({jsonrpc:r.z.literal("2.0"),id:r.z.union([r.z.string(),r.z.number().int()]),result:l}).strict(),O=r.z.object({jsonrpc:r.z.literal("2.0"),id:r.z.optional(r.z.union([r.z.string(),r.z.number().int()])),error:r.z.object({code:r.z.number().int(),message:r.z.string(),data:r.z.optional(r.z.unknown())})}).strict(),M=r.z.object({jsonrpc:r.z.literal("2.0")}).merge(r.z.object({method:r.z.string(),params:r.z.optional(a)})).strict(),$=r.z.union([A,M,U,O]);async function H(e){var r;return r=await (0,t.parseJSON)({text:e}),$.parse(r)}let L="vercel.ai.error.AI_MCPClientError",N=Symbol.for(L);var V=class extends o.AISDKError{constructor({name:e="MCPClientError",message:t,cause:r,data:o,code:n,statusCode:i,url:s,responseBody:a}){super({name:e,message:t,cause:r}),this[N]=!0,this.data=o,this.code=n,this.statusCode=i,this.url=s,this.responseBody=a}static isInstance(e){return o.AISDKError.hasMarker(e,L)}},q=class{constructor(e){this.supportsProtocolVersionDiscovery=!0,this.abortController=new AbortController,this.readBuffer=new D,this.serverParams=e}async start(){if(this.process)throw new V({message:"StdioMCPTransport already started."});return new Promise((e,t)=>{try{let r=function(e,t){if("win32"===globalThis.process.platform&&[e.command,...e.args??[]].some(e=>/[\r\n]/.test(e)))throw TypeError("Stdio MCP commands and arguments must not contain line breaks on Windows.");return(0,n.default)(e.command,e.args??[],{env:function(e){let t="win32"===globalThis.process.platform,r=e?{...e}:{},o=new Set(Object.keys(r).map(e=>t?e.toUpperCase():e));for(let e of t?["APPDATA","HOMEDRIVE","HOMEPATH","LOCALAPPDATA","PATH","PROCESSOR_ARCHITECTURE","SYSTEMDRIVE","SYSTEMROOT","TEMP","USERNAME","USERPROFILE"]:["HOME","LOGNAME","PATH","SHELL","TERM","USER"]){if(o.has(e))continue;let t=globalThis.process.env[e];void 0!==t&&(t.startsWith("()")||(r[e]=t))}return r}(e.env),stdio:["pipe","pipe",e.stderr??"inherit"],shell:!1,signal:t,windowsHide:"win32"===globalThis.process.platform&&"type"in globalThis.process,cwd:e.cwd})}(this.serverParams,this.abortController.signal);this.process=r,this.process.on("error",e=>{"AbortError"===e.name?this.onclose?.():(t(e),this.onerror?.(e))}),this.process.on("spawn",()=>{e()}),this.process.on("close",e=>{this.process=void 0,this.onclose?.()}),this.process.stdin?.on("error",e=>{this.onerror?.(e)}),this.process.stdout?.on("data",e=>{this.readBuffer.append(e),this.processReadBuffer()}),this.process.stdout?.on("error",e=>{this.onerror?.(e)})}catch(e){t(e),this.onerror?.(e)}})}async processReadBuffer(){for(;;){let e=this.readBuffer.readLine();if(null===e)break;try{let t=await F(e);this.onmessage?.(t)}catch(e){this.onerror?.(e)}}}async close(){this.abortController.abort(),this.process=void 0,this.readBuffer.clear()}send(e){return new Promise(t=>{if(!this.process?.stdin)throw new V({message:"StdioClientTransport not connected"});let r=JSON.stringify(e)+"\n";this.process.stdin.write(r)?t():this.process.stdin.once("drain",t)})}},D=class{append(e){this.buffer=this.buffer?Buffer.concat([this.buffer,e]):e}readLine(){if(!this.buffer)return null;let e=this.buffer.indexOf("\n");if(-1===e)return null;let t=this.buffer.toString("utf8",0,e);return this.buffer=this.buffer.subarray(e+1),t}clear(){this.buffer=void 0}};async function F(e){return H(e)}e.s(["Experimental_StdioMCPTransport",0,q])}];
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=_1d5zmy8._.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module.exports=[720275,e=>{e.v(e=>Promise.resolve().then(()=>e(656446)))},967030,e=>{e.v(e=>Promise.resolve().then(()=>e(783697)))},683671,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_@vercel_oidc_dist_token_1o4m7ms.js"].map(s=>e.l(s))).then(()=>s(390391)))},329280,e=>{e.v(s=>Promise.all(["server/chunks/[externals]_node_readline_1u65a-m._.js","server/chunks/node_modules_consola_dist_chunks_prompt_mjs_02axwqv._.js"].map(s=>e.l(s))).then(()=>s(781937)))}];
|
|
2
2
|
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=_1h7ll0h._.js.map
|