eve 0.47.5 → 0.47.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/NOTICE +72 -0
  3. package/dist/src/channel/adapter.js +1 -1
  4. package/dist/src/channel/session.js +1 -1
  5. package/dist/src/chunks/{use-eve-agent-DjYwFJF7.js → use-eve-agent-B5zw1dwj.js} +0 -1
  6. package/dist/src/chunks/{use-eve-agent-DkUB0Ok4.js → use-eve-agent-Dg5S44kG.js} +0 -1
  7. package/dist/src/cli/commands/registry-declared-setups.js +1 -1
  8. package/dist/src/cli/commands/registry-install-transaction.d.ts +23 -0
  9. package/dist/src/cli/commands/registry-install-transaction.js +1 -0
  10. package/dist/src/cli/commands/registry-package.js +1 -1
  11. package/dist/src/cli/commands/registry.js +1 -1
  12. package/dist/src/cli/commands/setup-headless.d.ts +6 -0
  13. package/dist/src/cli/commands/setup-headless.js +1 -1
  14. package/dist/src/cli/dev/run-interactive-ui.js +1 -1
  15. package/dist/src/cli/dev/tui/line-editor.d.ts +4 -0
  16. package/dist/src/cli/dev/tui/line-editor.js +3 -3
  17. package/dist/src/cli/dev/tui/runner.d.ts +2 -0
  18. package/dist/src/cli/dev/tui/runner.js +1 -1
  19. package/dist/src/cli/dev/tui/stream-format.d.ts +8 -0
  20. package/dist/src/cli/dev/tui/stream-format.js +2 -2
  21. package/dist/src/cli/dev/tui/subagent-pump.d.ts +3 -0
  22. package/dist/src/cli/dev/tui/subagent-pump.js +1 -1
  23. package/dist/src/cli/dev/tui/tui.js +1 -1
  24. package/dist/src/cli/dev/tui/vercel-trusted-sources.js +1 -1
  25. package/dist/src/cli/invoke/result.d.ts +1 -1
  26. package/dist/src/client/agent-info-schema.d.ts +0 -1
  27. package/dist/src/client/agent-info-schema.js +1 -1
  28. package/dist/src/compiled/.vendor-stamp.json +5 -5
  29. package/dist/src/compiled/@agentclientprotocol/sdk/index.js +29 -43
  30. package/dist/src/compiled/@ai-sdk/anthropic/index.js +4 -4
  31. package/dist/src/compiled/@ai-sdk/code-mode/LICENSE +13 -0
  32. package/dist/src/compiled/@ai-sdk/code-mode/_run.d.ts +1 -0
  33. package/dist/src/compiled/@ai-sdk/code-mode/index.d.ts +300 -0
  34. package/dist/src/compiled/@ai-sdk/code-mode/index.js +663 -0
  35. package/dist/src/compiled/@ai-sdk/google/index.js +6 -6
  36. package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
  37. package/dist/src/compiled/@ai-sdk/openai/index.js +8 -8
  38. package/dist/src/compiled/@ai-sdk/provider/index.d.ts +6 -0
  39. package/dist/src/compiled/@ai-sdk/provider-utils/index.d.ts +50 -2
  40. package/dist/src/compiled/@modelcontextprotocol/server/index.js +36 -50
  41. package/dist/src/compiled/@photon-ai/chat-adapter-imessage/index.js +55 -55
  42. package/dist/src/compiled/@vercel/sandbox/index.js +3 -3
  43. package/dist/src/compiled/@vercel/sandbox-delete/index.js +3 -3
  44. package/dist/src/compiled/_chunks/client/errors-BLhNglBt.js +2 -0
  45. package/dist/src/compiled/_chunks/node/auth-BSKyPAEP.js +2 -0
  46. package/dist/src/compiled/_chunks/node/auth-YpKlwhP1.js +2 -0
  47. package/dist/src/compiled/_chunks/node/schemas-cFtr4EoN.js +50 -0
  48. package/dist/src/compiled/_chunks/node/xdg-app-paths-Buj3-Svl.js +1 -0
  49. package/dist/src/compiled/_chunks/workflow/dist-Cz-ffHKC.js +65 -0
  50. package/dist/src/compiled/zod/index.js +32 -45
  51. package/dist/src/compiled/zod-validation-error/index.js +1 -1
  52. package/dist/src/compiler/extension-compatibility.d.ts +2 -2
  53. package/dist/src/compiler/extension-compatibility.js +1 -1
  54. package/dist/src/compiler/manifest.d.ts +7 -17
  55. package/dist/src/compiler/manifest.js +1 -1
  56. package/dist/src/compiler/normalize-manifest.js +1 -1
  57. package/dist/src/compiler/normalize-tool.d.ts +0 -1
  58. package/dist/src/compiler/normalize-tool.js +1 -1
  59. package/dist/src/context/build-dynamic-tools.d.ts +2 -2
  60. package/dist/src/context/build-dynamic-tools.js +1 -1
  61. package/dist/src/context/container.d.ts +7 -0
  62. package/dist/src/context/container.js +1 -1
  63. package/dist/src/context/dynamic-tool-lifecycle.d.ts +16 -9
  64. package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
  65. package/dist/src/context/dynamic-tool-metadata.d.ts +44 -0
  66. package/dist/src/context/dynamic-tool-metadata.js +1 -0
  67. package/dist/src/context/keys.d.ts +11 -14
  68. package/dist/src/context/keys.js +1 -1
  69. package/dist/src/eve-channel/index.js +1 -1
  70. package/dist/src/eve-channel/request.d.ts +0 -1
  71. package/dist/src/eve-channel/request.js +2 -2
  72. package/dist/src/execution/create-session-step.js +1 -1
  73. package/dist/src/execution/delegation-tool.d.ts +1 -2
  74. package/dist/src/execution/delegation-tool.js +1 -1
  75. package/dist/src/execution/dispatch-runtime-actions-shared.d.ts +8 -3
  76. package/dist/src/execution/dispatch-runtime-actions-shared.js +1 -1
  77. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  78. package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
  79. package/dist/src/execution/node-step.js +1 -1
  80. package/dist/src/execution/pending-turn-state.js +1 -1
  81. package/dist/src/execution/prepared-agent-action.d.ts +7 -0
  82. package/dist/src/execution/prepared-agent-action.js +1 -0
  83. package/dist/src/execution/subagent-start-local.d.ts +3 -0
  84. package/dist/src/execution/subagent-start-local.js +1 -1
  85. package/dist/src/execution/subagent-tool.d.ts +1 -0
  86. package/dist/src/execution/subagent-tool.js +1 -1
  87. package/dist/src/execution/tasks/child/update.d.ts +3 -2
  88. package/dist/src/execution/tasks/parent/control-shared.d.ts +5 -4
  89. package/dist/src/execution/tasks/parent/dispatch-task-step.js +1 -1
  90. package/dist/src/execution/tasks/parent/dispatch.d.ts +4 -3
  91. package/dist/src/execution/tasks/parent/dispatch.js +1 -1
  92. package/dist/src/execution/tools/subagent/local.d.ts +3 -4
  93. package/dist/src/execution/tools/subagent/local.js +1 -1
  94. package/dist/src/execution/tools/subagent/remote.d.ts +4 -1
  95. package/dist/src/execution/tools/subagent/remote.js +1 -1
  96. package/dist/src/execution/workflow-entry-finalization.d.ts +22 -0
  97. package/dist/src/execution/workflow-entry-finalization.js +1 -0
  98. package/dist/src/execution/workflow-entry.d.ts +1 -1
  99. package/dist/src/execution/workflow-entry.js +1 -1
  100. package/dist/src/execution/workflow-steps.js +1 -1
  101. package/dist/src/framework/sources/registry.js +1 -1
  102. package/dist/src/harness/advertised-tools.d.ts +3 -5
  103. package/dist/src/harness/advertised-tools.js +1 -1
  104. package/dist/src/harness/approval-delivery-coordinator.d.ts +6 -0
  105. package/dist/src/harness/approval-delivery-coordinator.js +1 -1
  106. package/dist/src/harness/background-tools.d.ts +2 -0
  107. package/dist/src/harness/execute-tool.d.ts +2 -28
  108. package/dist/src/harness/hitl/pending-input-resolution.js +1 -1
  109. package/dist/src/harness/input-extraction.d.ts +3 -0
  110. package/dist/src/harness/input-extraction.js +1 -1
  111. package/dist/src/harness/input-requests.js +1 -1
  112. package/dist/src/harness/messages.js +1 -1
  113. package/dist/src/harness/runtime-actions.d.ts +9 -3
  114. package/dist/src/harness/runtime-actions.js +1 -1
  115. package/dist/src/harness/stale-input-responses.d.ts +2 -1
  116. package/dist/src/harness/stale-input-responses.js +1 -1
  117. package/dist/src/harness/subagent-depth.d.ts +3 -4
  118. package/dist/src/harness/subagent-depth.js +1 -1
  119. package/dist/src/harness/tool-loop.js +2 -2
  120. package/dist/src/harness/tools.d.ts +0 -2
  121. package/dist/src/harness/tools.js +1 -1
  122. package/dist/src/harness/types.d.ts +6 -7
  123. package/dist/src/harness/workflow-interrupt-state.d.ts +6 -0
  124. package/dist/src/harness/workflow-interrupt-state.js +1 -1
  125. package/dist/src/harness/workflow-lifecycle.d.ts +15 -5
  126. package/dist/src/harness/workflow-lifecycle.js +1 -1
  127. package/dist/src/harness/workflow-runtime-action-state.d.ts +5 -5
  128. package/dist/src/harness/workflow-runtime-action-state.js +1 -1
  129. package/dist/src/harness/workflow-sandbox.d.ts +1 -2
  130. package/dist/src/harness/workflow-sandbox.js +2 -2
  131. package/dist/src/harness/workflow-subagent-limit.d.ts +7 -17
  132. package/dist/src/harness/workflow-subagent-limit.js +1 -1
  133. package/dist/src/instrumentation/ai-sdk-telemetry.d.ts +1 -0
  134. package/dist/src/instrumentation/ai-sdk-telemetry.js +1 -1
  135. package/dist/src/instrumentation/runtime.d.ts +3 -0
  136. package/dist/src/instrumentation/runtime.js +1 -1
  137. package/dist/src/internal/application/build-output-environment.d.ts +2 -0
  138. package/dist/src/internal/application/build-output-environment.js +1 -0
  139. package/dist/src/internal/application/package.js +1 -1
  140. package/dist/src/internal/application/paths.d.ts +1 -2
  141. package/dist/src/internal/application/paths.js +1 -1
  142. package/dist/src/internal/authored-definition/schema-backed.d.ts +6 -2
  143. package/dist/src/internal/authored-definition/schema-backed.js +1 -1
  144. package/dist/src/internal/client-context.d.ts +2 -0
  145. package/dist/src/internal/client-context.js +1 -0
  146. package/dist/src/internal/nitro/dev-client-address.d.ts +2 -0
  147. package/dist/src/internal/nitro/dev-client-address.js +1 -1
  148. package/dist/src/internal/nitro/host/dev-authored-source-watcher.d.ts +2 -2
  149. package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
  150. package/dist/src/internal/nitro/host/start-development-server.js +2 -2
  151. package/dist/src/internal/nitro/host/workflow-sandbox-runtime-plugin.js +1 -1
  152. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
  153. package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
  154. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/lib/schemas.js +1 -1
  155. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/models/aclaction.js +1 -1
  156. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/models/sdkvalidationerror.js +1 -1
  157. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/models/updateprojectblock.js +1 -1
  158. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/models/updateprojectprojectsbranchmatcher.js +1 -1
  159. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/types/primitives.js +1 -1
  160. package/dist/src/node_modules/.pnpm/@vercel_sdk@1.28.8/node_modules/@vercel/sdk/esm/types/smartUnion.js +1 -1
  161. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/index.js +1 -0
  162. package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/ZodError.js +1 -1
  163. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v3/types.js +1 -0
  164. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/checks.js +1 -0
  165. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/deep-partial.js +1 -0
  166. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/errors.js +1 -0
  167. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/external.js +1 -0
  168. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/from-json-schema.js +1 -0
  169. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/in-out.js +1 -0
  170. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/iso.js +1 -0
  171. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/parse.js +1 -0
  172. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/schemas.js +1 -0
  173. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/api.js +1 -0
  174. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/checks.js +1 -0
  175. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/compile.js +2 -0
  176. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/core.js +1 -0
  177. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/doc.js +3 -0
  178. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/errors.js +2 -0
  179. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/index.js +1 -0
  180. package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/core/json-schema-generator.js +1 -1
  181. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/json-schema-processors.js +1 -0
  182. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/memoizer.js +1 -0
  183. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/parse.js +1 -0
  184. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/regexes.js +1 -0
  185. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/schemas.js +46 -0
  186. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/to-json-schema.js +3 -0
  187. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/util.js +1 -0
  188. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/versions.js +1 -0
  189. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/core/visit.js +1 -0
  190. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ar.js +1 -0
  191. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/az.js +1 -0
  192. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/be.js +1 -0
  193. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/bg.js +1 -0
  194. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/bn.js +1 -0
  195. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ca.js +1 -0
  196. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ckb.js +1 -0
  197. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/cs.js +1 -0
  198. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/da.js +1 -0
  199. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/de.js +1 -0
  200. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/el.js +1 -0
  201. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/en.js +1 -0
  202. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/eo.js +1 -0
  203. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/es.js +1 -0
  204. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/fa.js +1 -0
  205. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/fi.js +1 -0
  206. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/fr-CA.js +1 -0
  207. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/fr.js +1 -0
  208. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/gu.js +1 -0
  209. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/he.js +1 -0
  210. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/hi.js +1 -0
  211. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/hr.js +1 -0
  212. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/hu.js +1 -0
  213. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/hy.js +1 -0
  214. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/id.js +1 -0
  215. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/index.js +1 -0
  216. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/is.js +1 -0
  217. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/it.js +1 -0
  218. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ja.js +1 -0
  219. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ka.js +1 -0
  220. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/km.js +1 -0
  221. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/kn.js +1 -0
  222. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ko.js +1 -0
  223. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/lt.js +1 -0
  224. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/mk.js +1 -0
  225. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ms.js +1 -0
  226. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ne.js +1 -0
  227. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/nl.js +1 -0
  228. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/nn.js +1 -0
  229. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/no.js +1 -0
  230. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ota.js +1 -0
  231. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/pl.js +1 -0
  232. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ps.js +1 -0
  233. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/pt-BR.js +1 -0
  234. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/pt.js +1 -0
  235. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ro.js +1 -0
  236. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ru.js +1 -0
  237. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/sk.js +1 -0
  238. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/sl.js +1 -0
  239. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/sv.js +1 -0
  240. package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/locales/ta.js +1 -1
  241. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/th.js +1 -0
  242. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/tk.js +1 -0
  243. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/tr.js +1 -0
  244. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/uk.js +1 -0
  245. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/ur.js +1 -0
  246. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/uz.js +1 -0
  247. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/vi.js +1 -0
  248. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/yo.js +1 -0
  249. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/zh-CN.js +1 -0
  250. package/dist/src/node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/locales/zh-TW.js +1 -0
  251. package/dist/src/packages/eve-catalog/src/index.js +1 -1
  252. package/dist/src/protocol/routes.d.ts +2 -2
  253. package/dist/src/public/local-dev.d.ts +9 -0
  254. package/dist/src/public/local-dev.js +1 -0
  255. package/dist/src/public/next/vercel-output-config.js +1 -1
  256. package/dist/src/runtime/actions/keys.d.ts +3 -0
  257. package/dist/src/runtime/actions/keys.js +1 -1
  258. package/dist/src/runtime/agent/bootstrap.js +1 -1
  259. package/dist/src/runtime/agent/mock-model-adapter.js +1 -1
  260. package/dist/src/runtime/loaders/bundled-artifacts.js +1 -1
  261. package/dist/src/runtime/local-dev-capability.d.ts +55 -0
  262. package/dist/src/runtime/local-dev-capability.js +1 -0
  263. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  264. package/dist/src/runtime/resolve-agent.js +1 -1
  265. package/dist/src/runtime/resolve-tool.js +1 -1
  266. package/dist/src/runtime/sessions/runtime-session.d.ts +1 -0
  267. package/dist/src/runtime/sessions/runtime-session.js +1 -1
  268. package/dist/src/runtime/sessions/turn.d.ts +3 -0
  269. package/dist/src/runtime/subagents/registry.js +1 -1
  270. package/dist/src/runtime/tools/registry.d.ts +1 -0
  271. package/dist/src/runtime/tools/registry.js +1 -1
  272. package/dist/src/runtime/types.d.ts +2 -2
  273. package/dist/src/services/dev-client/client-options.d.ts +1 -0
  274. package/dist/src/services/dev-client/client-options.js +1 -1
  275. package/dist/src/services/dev-client/request-headers.js +1 -1
  276. package/dist/src/services/dev-client/runtime-artifacts.d.ts +2 -0
  277. package/dist/src/services/dev-client/runtime-artifacts.js +1 -1
  278. package/dist/src/setup/integrations/discord/api.js +1 -1
  279. package/dist/src/setup/integrations/discord/connect.js +1 -1
  280. package/dist/src/setup/integrations/github/connect.js +1 -1
  281. package/dist/src/setup/integrations/linear/connect.js +1 -1
  282. package/dist/src/setup/integrations/linq/connect.js +1 -1
  283. package/dist/src/setup/integrations/photon/connect.js +1 -1
  284. package/dist/src/setup/project-resolution.js +1 -1
  285. package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
  286. package/dist/src/setup/scaffold/create/extension.js +1 -1
  287. package/dist/src/setup/scaffold/create/project.js +2 -2
  288. package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
  289. package/dist/src/setup/scaffold/create/web-template.js +1 -1
  290. package/dist/src/setup/scaffold/update/web-options.js +1 -1
  291. package/dist/src/setup/slack-connect.js +1 -1
  292. package/dist/src/setup/vercel-api-failure.js +1 -1
  293. package/dist/src/setup/vercel-deployment.js +1 -1
  294. package/dist/src/setup/vercel-project-api.js +1 -1
  295. package/dist/src/setup/vercel-project-framework.js +1 -1
  296. package/dist/src/setup/vercel-project.js +0 -0
  297. package/dist/src/shared/dispatch-action.d.ts +24 -0
  298. package/dist/src/shared/dispatch-action.js +1 -0
  299. package/dist/src/shared/input.js +1 -1
  300. package/dist/src/shared/workflow-sandbox.d.ts +11 -6
  301. package/dist/src/shared/workflow-sandbox.js +1 -1
  302. package/dist/src/svelte/index.js +1 -1
  303. package/dist/src/svelte/use-eve-agent.js +1 -1
  304. package/dist/src/tasks/json.js +1 -1
  305. package/dist/src/tools/behavior.d.ts +55 -0
  306. package/dist/src/tools/behavior.js +1 -0
  307. package/dist/src/tools/durable-callbacks.d.ts +1 -0
  308. package/dist/src/tools/framework/agent.d.ts +2 -11
  309. package/dist/src/tools/framework/agent.js +1 -1
  310. package/dist/src/tools/framework/ask-question.d.ts +2 -14
  311. package/dist/src/tools/framework/ask-question.js +1 -1
  312. package/dist/src/tools/framework/task-cancel.d.ts +2 -7
  313. package/dist/src/tools/framework/task-cancel.js +1 -1
  314. package/dist/src/tools/framework/task-contract.d.ts +0 -2
  315. package/dist/src/tools/framework/task-contract.js +1 -1
  316. package/dist/src/tools/framework/task-update.d.ts +2 -7
  317. package/dist/src/tools/framework/task-update.js +1 -1
  318. package/dist/src/tools/native-definition.d.ts +6 -0
  319. package/dist/src/tools/native-definition.js +1 -0
  320. package/dist/src/tools/provided/load-skill.js +1 -1
  321. package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
  322. package/dist/src/tracing/agent-channel-delivery-instrumentation.js +1 -1
  323. package/dist/src/tracing/agent-otel-provider.js +1 -1
  324. package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
  325. package/dist/src/tracing/install-instrumentation-runtime.js +1 -1
  326. package/dist/src/tracing/otel-registration.d.ts +2 -0
  327. package/dist/src/tracing/otel-registration.js +1 -1
  328. package/dist/src/vue/index.js +1 -1
  329. package/dist/src/vue/use-eve-agent.js +1 -1
  330. package/docs/reference/typescript-api.md +24 -0
  331. package/package.json +11 -5
  332. package/dist/src/compiled/_chunks/client/errors-C14fPFvs.js +0 -2
  333. package/dist/src/compiled/_chunks/node/auth-DpzFWvTn.js +0 -2
  334. package/dist/src/compiled/_chunks/node/auth-QgeX8nBM.js +0 -2
  335. package/dist/src/compiled/_chunks/node/compat-Dm2n85Mx.js +0 -1
  336. package/dist/src/compiled/_chunks/node/schemas-DtQwuPdM.js +0 -65
  337. package/dist/src/compiled/_chunks/node/xdg-app-paths-Bys8q02u.js +0 -1
  338. package/dist/src/compiled/_chunks/workflow/dist-eUxFublw.js +0 -77
  339. package/dist/src/compiled/experimental-ai-sdk-code-mode/LICENSE +0 -21
  340. package/dist/src/compiled/experimental-ai-sdk-code-mode/approval-continuation.d.ts +0 -71
  341. package/dist/src/compiled/experimental-ai-sdk-code-mode/approval.d.ts +0 -32
  342. package/dist/src/compiled/experimental-ai-sdk-code-mode/code-mode-tool.d.ts +0 -16
  343. package/dist/src/compiled/experimental-ai-sdk-code-mode/continuation-capability.d.ts +0 -44
  344. package/dist/src/compiled/experimental-ai-sdk-code-mode/errors.d.ts +0 -114
  345. package/dist/src/compiled/experimental-ai-sdk-code-mode/fetch-policy.d.ts +0 -21
  346. package/dist/src/compiled/experimental-ai-sdk-code-mode/host-interrupt.d.ts +0 -25
  347. package/dist/src/compiled/experimental-ai-sdk-code-mode/index.d.ts +0 -11
  348. package/dist/src/compiled/experimental-ai-sdk-code-mode/index.js +0 -419
  349. package/dist/src/compiled/experimental-ai-sdk-code-mode/interrupt-continuation.d.ts +0 -32
  350. package/dist/src/compiled/experimental-ai-sdk-code-mode/options.d.ts +0 -3
  351. package/dist/src/compiled/experimental-ai-sdk-code-mode/run-code-mode.d.ts +0 -12
  352. package/dist/src/compiled/experimental-ai-sdk-code-mode/runtime/guest-sources.d.ts +0 -3
  353. package/dist/src/compiled/experimental-ai-sdk-code-mode/runtime/manager.d.ts +0 -22
  354. package/dist/src/compiled/experimental-ai-sdk-code-mode/runtime/max-workers.d.ts +0 -20
  355. package/dist/src/compiled/experimental-ai-sdk-code-mode/runtime/protocol.d.ts +0 -60
  356. package/dist/src/compiled/experimental-ai-sdk-code-mode/runtime/worker-source.d.ts +0 -11
  357. package/dist/src/compiled/experimental-ai-sdk-code-mode/serialization.d.ts +0 -5
  358. package/dist/src/compiled/experimental-ai-sdk-code-mode/source-cache.d.ts +0 -11
  359. package/dist/src/compiled/experimental-ai-sdk-code-mode/telemetry.d.ts +0 -20
  360. package/dist/src/compiled/experimental-ai-sdk-code-mode/tool-invocation.d.ts +0 -24
  361. package/dist/src/compiled/experimental-ai-sdk-code-mode/tool-prompt.d.ts +0 -3
  362. package/dist/src/compiled/experimental-ai-sdk-code-mode/types.d.ts +0 -828
  363. package/dist/src/execution/tools/tasks.d.ts +0 -18
  364. package/dist/src/execution/tools/tasks.js +0 -1
  365. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/index.js +0 -1
  366. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/types.js +0 -1
  367. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/checks.js +0 -1
  368. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js +0 -1
  369. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js +0 -1
  370. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/from-json-schema.js +0 -1
  371. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.js +0 -1
  372. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.js +0 -1
  373. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.js +0 -1
  374. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.js +0 -1
  375. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.js +0 -1
  376. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js +0 -1
  377. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.js +0 -3
  378. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js +0 -2
  379. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/index.js +0 -1
  380. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js +0 -1
  381. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js +0 -1
  382. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.js +0 -1
  383. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.js +0 -60
  384. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js +0 -3
  385. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js +0 -1
  386. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js +0 -1
  387. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ar.js +0 -1
  388. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/az.js +0 -1
  389. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/be.js +0 -1
  390. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/bg.js +0 -1
  391. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ca.js +0 -1
  392. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/cs.js +0 -1
  393. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/da.js +0 -1
  394. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/de.js +0 -1
  395. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/el.js +0 -1
  396. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/en.js +0 -1
  397. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/eo.js +0 -1
  398. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/es.js +0 -1
  399. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/fa.js +0 -1
  400. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/fi.js +0 -1
  401. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/fr-CA.js +0 -1
  402. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/fr.js +0 -1
  403. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/he.js +0 -1
  404. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/hr.js +0 -1
  405. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/hu.js +0 -1
  406. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/hy.js +0 -1
  407. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/id.js +0 -1
  408. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/index.js +0 -1
  409. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/is.js +0 -1
  410. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/it.js +0 -1
  411. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ja.js +0 -1
  412. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ka.js +0 -1
  413. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/km.js +0 -1
  414. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ko.js +0 -1
  415. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/lt.js +0 -1
  416. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/mk.js +0 -1
  417. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ms.js +0 -1
  418. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/nl.js +0 -1
  419. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/no.js +0 -1
  420. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ota.js +0 -1
  421. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/pl.js +0 -1
  422. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ps.js +0 -1
  423. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/pt.js +0 -1
  424. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ro.js +0 -1
  425. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ru.js +0 -1
  426. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/sl.js +0 -1
  427. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/sv.js +0 -1
  428. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/th.js +0 -1
  429. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/tr.js +0 -1
  430. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/uk.js +0 -1
  431. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/ur.js +0 -1
  432. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/uz.js +0 -1
  433. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/vi.js +0 -1
  434. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/yo.js +0 -1
  435. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/zh-CN.js +0 -1
  436. package/dist/src/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/locales/zh-TW.js +0 -1
  437. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/errors.js +0 -0
  438. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/external.js +0 -0
  439. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/helpers/errorUtil.js +0 -0
  440. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/helpers/parseUtil.js +0 -0
  441. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/helpers/typeAliases.js +0 -0
  442. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/helpers/util.js +0 -0
  443. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/index.js +0 -0
  444. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v3/locales/en.js +0 -0
  445. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/classic/coerce.js +0 -0
  446. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/classic/compat.js +0 -0
  447. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/core/json-schema.js +0 -0
  448. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/core/registries.js +0 -0
  449. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/locales/kh.js +0 -0
  450. /package/dist/src/node_modules/.pnpm/{zod@4.4.3 → zod@4.5.4}/node_modules/zod/v4/locales/ua.js +0 -0
@@ -1 +1 @@
1
- import{AISDKError as e,isJSONObject as t}from"../provider/index.js";import{C as n,Ct as r,E as i,Et as a,H as o,Ot as s,P as c,Q as l,St as u,Tt as d,X as f,Z as p,_t as m,bt as h,gt as g,ht as _,jt as ee,kt as v,mt as te,n as ne,nt as re,o as ie,st as ae,u as oe,ut as y,wt as b,xt as x}from"../../_chunks/workflow/dist-eUxFublw.js";const se={invalid_type:`invalid_type`,too_big:`too_big`,too_small:`too_small`,invalid_format:`invalid_format`,not_multiple_of:`not_multiple_of`,unrecognized_keys:`unrecognized_keys`,invalid_union:`invalid_union`,invalid_key:`invalid_key`,invalid_element:`invalid_element`,invalid_value:`invalid_value`,custom:`custom`};var ce;ce||={};let S;S=globalThis.crypto?.webcrypto??globalThis.crypto??import(`node:crypto`).then(e=>e.webcrypto);async function le(e){return(await S).getRandomValues(new Uint8Array(e))}async function ue(e){let t=``;for(;t.length<e;){let n=await le(e-t.length);for(let e of n)e<198&&(t+=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~`[e%66])}return t}async function de(e){return await ue(e)}async function fe(e){let t=await(await S).subtle.digest(`SHA-256`,new TextEncoder().encode(e));return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g,`_`).replace(/\+/g,`-`).replace(/=/g,``)}async function pe(e){if(e||=43,e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;let t=await de(e);return{code_verifier:t,code_challenge:await fe(t)}}var C=`2025-11-25`,me=[C,`2025-06-18`,`2025-03-26`,`2024-11-05`],he=b(d(a(),v())),ge=x({name:a(),version:a(),title:b(a())}),w=x({_meta:b(r({}).loose())}),T=w,_e=r({method:a(),params:b(w)}),ve=r({applyDefaults:b(m())}).loose(),ye=x({experimental:b(r({}).loose()),logging:b(r({}).loose()),completions:b(r({}).loose()),prompts:b(x({listChanged:b(m())})),resources:b(x({subscribe:b(m()),listChanged:b(m())})),tools:b(x({listChanged:b(m())})),elicitation:b(ve)});r({elicitation:b(ve)}).loose();var be=T.extend({protocolVersion:a(),capabilities:ye,serverInfo:ge,instructions:b(a())}),E=T.extend({nextCursor:b(a())}),xe=r({name:a(),title:b(a()),description:b(a()),inputSchema:r({type:h(`object`),properties:b(r({}).loose())}).loose(),outputSchema:b(r({}).loose()),annotations:b(r({title:b(a())}).loose()),_meta:he}).loose(),Se=E.extend({tools:_(xe)}),Ce=r({type:h(`text`),text:a()}).loose(),we=r({type:h(`image`),data:g(),mimeType:a()}).loose(),Te=r({uri:a(),name:a(),title:b(a()),description:b(a()),mimeType:b(a()),size:b(u())}).loose(),Ee=E.extend({resources:_(Te)}),D=r({uri:a(),name:b(a()),title:b(a()),mimeType:b(a())}).loose(),O=D.extend({text:a()}),k=D.extend({blob:g()}),De=r({type:h(`resource`),resource:s([O,k])}).loose(),Oe=r({type:h(`resource_link`),uri:a(),name:a(),description:b(a()),mimeType:b(a())}).loose(),ke=T.extend({content:_(s([Ce,we,De,Oe])),structuredContent:b(v()),isError:m().default(!1).optional()}).or(T.extend({toolResult:v()})),Ae=r({uriTemplate:a(),name:a(),title:b(a()),description:b(a()),mimeType:b(a())}).loose(),je=T.extend({resourceTemplates:_(Ae)}),Me=T.extend({contents:_(s([O,k]))}),Ne=r({type:h(`ref/prompt`),name:a()}).loose(),Pe=r({type:h(`ref/resource`),uri:a()}).loose(),Fe=r({name:a(),value:a()}).loose();w.extend({ref:s([Ne,Pe]),argument:Fe,context:b(r({arguments:d(a(),a())}).loose())});var Ie=T.extend({completion:r({values:_(a()).max(100),total:b(u().int()),hasMore:b(m())}).loose()}),Le=r({name:a(),description:b(a()),required:b(m())}).loose(),Re=r({name:a(),title:b(a()),description:b(a()),arguments:b(_(Le))}).loose(),ze=E.extend({prompts:_(Re)}),Be=r({role:s([h(`user`),h(`assistant`)]),content:s([Ce,we,De,Oe])}).loose(),Ve=T.extend({description:b(a()),messages:_(Be)}),He=w.extend({message:a(),requestedSchema:v()}),A=_e.extend({method:h(`elicitation/create`),params:He}),Ue=T.extend({action:s([h(`accept`),h(`decline`),h(`cancel`)]),content:b(d(a(),v()))}),j=`2.0`,We=r({jsonrpc:h(j),id:s([a(),u().int()])}).merge(_e).strict(),Ge=r({jsonrpc:h(j),id:s([a(),u().int()]),result:T}).strict(),Ke=r({jsonrpc:h(j),id:s([a(),u().int()]),error:r({code:u().int(),message:a(),data:b(v())})}).strict(),qe=s([We,r({jsonrpc:h(j)}).merge(r({method:a(),params:b(w)})).strict(),Ge,Ke]);function M(e){return qe.parse(e)}async function N(e){return M(await o({text:e}))}var Je=`vercel.ai.error.AI_MCPClientError`,Ye=Symbol.for(Je),Xe,Ze,P=class extends (Ze=e,Xe=Ye,Ze){constructor({name:e=`MCPClientError`,message:t,cause:n,data:r,code:i,statusCode:a,url:o,responseBody:s}){super({name:e,message:t,cause:n}),this[Xe]=!0,this.data=r,this.code=i,this.statusCode=a,this.url=o,this.responseBody=s}static isInstance(t){return e.hasMarker(t,Je)}},Qe=typeof __PACKAGE_VERSION__<`u`?__PACKAGE_VERSION__:`0.0.0-test`,F=a().url().superRefine((e,t)=>{if(!URL.canParse(e))return t.addIssue({code:se.custom,message:`URL must be parseable`,fatal:!0}),ee}).refine(e=>{let t=new URL(e);return t.protocol!==`javascript:`&&t.protocol!==`data:`&&t.protocol!==`vbscript:`},{message:`URL cannot use javascript:, data:, or vbscript: scheme`}),$e=r({access_token:a(),id_token:a().optional(),token_type:a(),expires_in:u().optional(),scope:a().optional(),refresh_token:a().optional(),authorization_server:F.optional(),token_endpoint:F.optional()}).strip(),et=x({resource:a().url(),authorization_servers:_(F).optional(),jwks_uri:a().url().optional(),scopes_supported:_(a()).optional(),bearer_methods_supported:_(a()).optional(),resource_signing_alg_values_supported:_(a()).optional(),resource_name:a().optional(),resource_documentation:a().optional(),resource_policy_uri:a().url().optional(),resource_tos_uri:a().url().optional(),tls_client_certificate_bound_access_tokens:m().optional(),authorization_details_types_supported:_(a()).optional(),dpop_signing_alg_values_supported:_(a()).optional(),dpop_bound_access_tokens_required:m().optional()}),tt=x({issuer:a(),authorization_endpoint:F,token_endpoint:F,registration_endpoint:F.optional(),scopes_supported:_(a()).optional(),response_types_supported:_(a()),grant_types_supported:_(a()).optional(),code_challenge_methods_supported:_(a()).optional(),token_endpoint_auth_methods_supported:_(a()).optional(),token_endpoint_auth_signing_alg_values_supported:_(a()).optional()}),nt=x({issuer:a(),authorization_endpoint:F,token_endpoint:F,userinfo_endpoint:F.optional(),jwks_uri:F,registration_endpoint:F.optional(),scopes_supported:_(a()).optional(),response_types_supported:_(a()),grant_types_supported:_(a()).optional(),subject_types_supported:_(a()),id_token_signing_alg_values_supported:_(a()),claims_supported:_(a()).optional(),token_endpoint_auth_methods_supported:_(a()).optional()}).merge(tt.pick({code_challenge_methods_supported:!0})),rt=r({client_id:a(),client_secret:a().optional(),client_id_issued_at:u().optional(),client_secret_expires_at:u().optional(),authorization_server:F.optional(),token_endpoint:F.optional()}).strip(),it=r({redirect_uris:_(F),token_endpoint_auth_method:a().optional(),grant_types:_(a()).optional(),response_types:_(a()).optional(),client_name:a().optional(),client_uri:F.optional(),logo_uri:F.optional(),scope:a().optional(),contacts:_(a()).optional(),tos_uri:F.optional(),policy_uri:a().optional(),jwks_uri:F.optional(),jwks:te().optional(),software_id:a().optional(),software_version:a().optional(),software_statement:a().optional()}).strip(),at=r({error:a(),error_description:a().optional(),error_uri:a().optional()}),ot=it.merge(rt),st=`vercel.ai.error.AI_MCPClientOAuthError`,ct=Symbol.for(st),lt,ut,I=class extends (ut=e,lt=ct,ut){constructor({name:e=`MCPClientOAuthError`,message:t,cause:n}){super({name:e,message:t,cause:n}),this[lt]=!0}static isInstance(t){return e.hasMarker(t,st)}},L=class extends I{};L.errorCode=`server_error`;var R=class extends I{};R.errorCode=`invalid_client`;var z=class extends I{};z.errorCode=`invalid_grant`;var B=class extends I{};B.errorCode=`unauthorized_client`;var dt={[L.errorCode]:L,[R.errorCode]:R,[z.errorCode]:z,[B.errorCode]:B};function ft(e){let t=typeof e==`string`?new URL(e):new URL(e.href);return t.hash=``,t}function V(e){let t=e.href;return e.pathname===`/`&&t.endsWith(`/`)?t.slice(0,-1):t}function pt({requestedResource:e,configuredResource:t}){let n=typeof e==`string`?new URL(e):new URL(e.href),r=typeof t==`string`?new URL(t):new URL(t.href);if(n.origin!==r.origin||n.pathname.length<r.pathname.length)return!1;let i=n.pathname.endsWith(`/`)?n.pathname:n.pathname+`/`,a=r.pathname.endsWith(`/`)?r.pathname:r.pathname+`/`;return i.startsWith(a)}var H=class extends Error{constructor(e=`Unauthorized`){super(e),this.name=`UnauthorizedError`}};function U(e){return new URL(e).href}function mt(e,t){return{authorizationServerUrl:U(e),tokenEndpoint:U(t?.token_endpoint?new URL(t.token_endpoint):new URL(`/token`,e))}}function ht(e,t){return{...e,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function gt(e,t){return{...e,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function _t(e){if(!(!e?.authorization_server||!e.token_endpoint))return{authorizationServerUrl:U(e.authorization_server),tokenEndpoint:U(e.token_endpoint)}}async function W({provider:e,clientInformation:t,tokens:n}){let r=_t(n);if(r)return r;let i=await e.authorizationServerInformation?.call(e);return i?{authorizationServerUrl:U(i.authorizationServerUrl),tokenEndpoint:U(i.tokenEndpoint)}:_t(t)}async function vt({provider:e,clientInformation:t,authorizationServerInformation:n}){return e.saveAuthorizationServerInformation?(await e.saveAuthorizationServerInformation(n),!0):e.saveClientInformation?(await e.saveClientInformation(gt(t,n)),!0):!1}function yt(e,t){if(!t)return;let n=new URL(e).origin;if(t.origin!==n)throw new I({message:`OAuth protected resource metadata URL ${t.href} must have the same origin as the MCP server URL ${n}`})}function bt({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:t}){if(e.authorizationServerUrl!==t.authorizationServerUrl||e.tokenEndpoint!==t.tokenEndpoint)throw new I({message:`OAuth authorization server metadata does not match the metadata that issued the stored credentials`})}function G(e){let t=e.headers.get(`www-authenticate`)??e.headers.get(`WWW-Authenticate`);if(!t)return;let[n,r]=t.split(` `);if(n.toLowerCase()!==`bearer`||!r)return;let i=t.match(/resource_metadata="([^"]*)"/);if(i)try{return new URL(i[1])}catch{return}}function xt(e,t=``,n={}){return t.endsWith(`/`)&&(t=t.slice(0,-1)),n.prependPathname?`${t}/.well-known/${e}`:`/.well-known/${e}${t}`}async function K(e,t,n=fetch){try{return await n(e,{headers:t})}catch(r){if(r instanceof TypeError)return t?K(e,void 0,n):void 0;throw r}}async function St(e,t,n=fetch){return await K(e,{"MCP-Protocol-Version":t},n)}function Ct(e,t){return!e||e.status>=400&&e.status<500&&t!==`/`}async function wt(e,t,n,r){let i=new URL(e),a=r?.protocolVersion??C,o;if(r?.metadataUrl)o=new URL(r.metadataUrl);else{let e=xt(t,i.pathname);o=new URL(e,r?.metadataServerUrl??i),o.search=i.search}let s=await St(o,a,n);return!r?.metadataUrl&&Ct(s,i.pathname)&&(s=await St(new URL(`/.well-known/${t}`,i),a,n)),s}async function Tt(e,t,n=fetch){let r=await wt(e,`oauth-protected-resource`,n,{protocolVersion:t?.protocolVersion,metadataUrl:t?.resourceMetadataUrl});if(!r||r.status===404)throw Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);if(!r.ok)throw Error(`HTTP ${r.status} trying to load well-known OAuth protected resource metadata.`);return et.parse(await r.json())}function Et(e){let t=typeof e==`string`?new URL(e):e,n=t.pathname!==`/`,r=t.origin,i=[];if(!n)return i.push({url:new URL(`/.well-known/oauth-authorization-server`,t.origin),type:`oauth`,expectedIssuer:r}),i.push({url:new URL(`/.well-known/openid-configuration`,t.origin),type:`oidc`,expectedIssuer:r}),i;let a=t.pathname;a.endsWith(`/`)&&(a=a.slice(0,-1));let o=`${t.origin}${a}`;return i.push({url:new URL(`/.well-known/oauth-authorization-server${a}`,t.origin),type:`oauth`,expectedIssuer:o}),i.push({url:new URL(`/.well-known/oauth-authorization-server`,t.origin),type:`oauth`,expectedIssuer:r}),i.push({url:new URL(`/.well-known/openid-configuration${a}`,t.origin),type:`oidc`,expectedIssuer:o}),i.push({url:new URL(`${a}/.well-known/openid-configuration`,t.origin),type:`oidc`,expectedIssuer:o}),i}function Dt(e,t){if(e.issuer!==t)throw new I({message:`OAuth authorization server metadata issuer ${e.issuer} does not match expected issuer ${t}`})}async function Ot(e,{fetchFn:t=fetch,protocolVersion:n=C}={}){let r={"MCP-Protocol-Version":n},i=Et(e);for(let{url:e,type:n,expectedIssuer:a}of i){let i=await K(e,r,t);if(i){if(!i.ok){if(i.status>=400&&i.status<500)continue;throw Error(`HTTP ${i.status} trying to load ${n===`oauth`?`OAuth`:`OpenID provider`} metadata from ${e}`)}if(n===`oauth`){let e=tt.parse(await i.json());return Dt(e,a),e}else{let t=nt.parse(await i.json());if(Dt(t,a),!t.code_challenge_methods_supported?.includes(`S256`))throw Error(`Incompatible OIDC provider at ${e}: does not support S256 code challenge method required by MCP specification`);return t}}}}async function kt(e,{metadata:t,clientInformation:n,redirectUrl:r,scope:i,state:a,resource:o}){let s=`code`,c=`S256`,l;if(t){if(l=new URL(t.authorization_endpoint),!t.response_types_supported.includes(s))throw Error(`Incompatible auth server: does not support response type ${s}`);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 l=new URL(`/authorize`,e);let u=await pe(),d=u.code_verifier,f=u.code_challenge;return l.searchParams.set(`response_type`,s),l.searchParams.set(`client_id`,n.client_id),l.searchParams.set(`code_challenge`,f),l.searchParams.set(`code_challenge_method`,c),l.searchParams.set(`redirect_uri`,String(r)),a&&l.searchParams.set(`state`,a),i&&l.searchParams.set(`scope`,i),i?.includes(`offline_access`)&&l.searchParams.append(`prompt`,`consent`),o&&l.searchParams.set(`resource`,V(o)),{authorizationUrl:l,codeVerifier:d}}function At(e,t){let n=e.client_secret!==void 0;return t.length===0?n?`client_secret_post`:`none`:n&&t.includes(`client_secret_basic`)?`client_secret_basic`:n&&t.includes(`client_secret_post`)?`client_secret_post`:t.includes(`none`)?`none`:n?`client_secret_post`:`none`}function jt(e,t,n,r){let{client_id:i,client_secret:a}=t;switch(e){case`client_secret_basic`:Mt(i,a,n);return;case`client_secret_post`:Nt(i,a,r);return;case`none`:Pt(i,r);return;default:throw Error(`Unsupported client authentication method: ${e}`)}}function Mt(e,t,n){if(!t)throw Error(`client_secret_basic authentication requires a client_secret`);let r=btoa(`${e}:${t}`);n.set(`Authorization`,`Basic ${r}`)}function Nt(e,t,n){n.set(`client_id`,e),t&&n.set(`client_secret`,t)}function Pt(e,t){t.set(`client_id`,e)}async function q(e){let t=e instanceof Response?e.status:void 0,n=e instanceof Response?await e.text():e;try{let{error:e,error_description:t,error_uri:r}=at.parse(await o({text:n}));return new(dt[e]||L)({message:t||``,cause:r})}catch(e){return new L({message:`${t?`HTTP ${t}: `:``}Invalid OAuth error response: ${e}. Raw body: ${n}`})}}async function Ft(e,{metadata:t,clientInformation:n,authorizationCode:r,codeVerifier:i,redirectUri:a,resource:o,addClientAuthentication:s,fetchFn:c}){let l=`authorization_code`,u=t?.token_endpoint?new URL(t.token_endpoint):new URL(`/token`,e);if(t?.grant_types_supported&&!t.grant_types_supported.includes(l))throw Error(`Incompatible auth server: does not support grant type ${l}`);let d=new Headers({"Content-Type":`application/x-www-form-urlencoded`,Accept:`application/json`}),f=new URLSearchParams({grant_type:l,code:r,code_verifier:i,redirect_uri:String(a)});s?await s(d,f,e,t):jt(At(n,t?.token_endpoint_auth_methods_supported??[]),n,d,f),o&&f.set(`resource`,V(o));let p=await(c??fetch)(u,{method:`POST`,headers:d,body:f});if(!p.ok)throw await q(p);return $e.parse(await p.json())}async function It(e,{metadata:t,clientInformation:n,refreshToken:r,resource:i,addClientAuthentication:a,fetchFn:o}){let s=`refresh_token`,c;if(t){if(c=new URL(t.token_endpoint),t.grant_types_supported&&!t.grant_types_supported.includes(s))throw Error(`Incompatible auth server: does not support grant type ${s}`)}else c=new URL(`/token`,e);let l=new Headers({"Content-Type":`application/x-www-form-urlencoded`,Accept:`application/json`}),u=new URLSearchParams({grant_type:s,refresh_token:r});a?await a(l,u,e,t):jt(At(n,t?.token_endpoint_auth_methods_supported??[]),n,l,u),i&&u.set(`resource`,V(i));let d=await(o??fetch)(c,{method:`POST`,headers:l,body:u});if(!d.ok)throw await q(d);return $e.parse({refresh_token:r,...await d.json()})}async function Lt(e,{metadata:t,clientMetadata:n,fetchFn:r}){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 a=await(r??fetch)(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!a.ok)throw await q(a);return ot.parse(await a.json())}async function J(e,t){try{return await Y(e,t)}catch(n){if(n instanceof R||n instanceof B)return await e.invalidateCredentials?.call(e,`all`),await Y(e,t);if(n instanceof z)return await e.invalidateCredentials?.call(e,`tokens`),await Y(e,t);throw n}}async function Rt(e,t,n){let r=ft(e);if(t.validateResourceURL)return await t.validateResourceURL(r,n?.resource);if(n){if(!pt({requestedResource:r,configuredResource:n.resource}))throw Error(`Protected resource ${n.resource} does not match expected ${r} (or origin)`);return new URL(n.resource)}}async function Y(e,{serverUrl:t,authorizationCode:n,callbackState:r,scope:i,resourceMetadataUrl:a,fetchFn:o}){let s,c;yt(t,a);try{s=await Tt(t,{resourceMetadataUrl:a},o),s.authorization_servers&&s.authorization_servers.length>0&&(c=s.authorization_servers[0])}catch{}c||=t;let l=await Rt(t,e,s);await e.validateAuthorizationServerURL?.call(e,t,c);let u=await Ot(c,{fetchFn:o}),d=mt(c,u),f=await Promise.resolve(e.clientInformation());if(!f){if(n!==void 0)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`);f=gt(await Lt(c,{metadata:u,clientMetadata:e.clientMetadata,fetchFn:o}),d),await e.saveClientInformation(f)}if(n!==void 0){if(e.storedState){let t=await e.storedState();if(t!==void 0&&t!==r)throw Error(`OAuth state parameter mismatch - possible CSRF attack`)}let t=await W({provider:e,clientInformation:f});if(!t)throw new I({message:`Stored OAuth authorization server metadata is required when exchanging an authorization code`});bt({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:d});let i=await e.codeVerifier(),a=await Ft(c,{metadata:u,clientInformation:f,authorizationCode:n,codeVerifier:i,redirectUri:e.redirectUrl,resource:l,addClientAuthentication:e.addClientAuthentication,fetchFn:o});return await e.saveTokens(ht(a,d)),`AUTHORIZED`}let p=await e.tokens();if(p?.refresh_token){let t=await W({provider:e,clientInformation:f,tokens:p});t?bt({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:d}):await e.invalidateCredentials?.call(e,`tokens`);try{if(t){let t=await It(c,{metadata:u,clientInformation:f,refreshToken:p.refresh_token,resource:l,addClientAuthentication:e.addClientAuthentication,fetchFn:o});return await e.saveTokens(ht(t,d)),`AUTHORIZED`}}catch(e){if(!(!(e instanceof I)||e instanceof L))throw e}}let m=e.state?await e.state():void 0;m&&e.saveState&&await e.saveState(m);let{authorizationUrl:h,codeVerifier:g}=await kt(c,{metadata:u,clientInformation:f,state:m,redirectUrl:e.redirectUrl,scope:i||e.clientMetadata.scope,resource:l});if(!await vt({provider:e,clientInformation:f,authorizationServerInformation:d}))throw new I({message:`OAuth authorization server metadata must be saveable before starting authorization`});return await e.saveCodeVerifier(g),await e.redirectToAuthorization(h),`REDIRECT`}function zt(e){return e===void 0||e===`message`}var Bt=class{constructor({url:e,headers:t,authProvider:n,redirect:r=`error`,fetch:i}){this.connected=!1,this.url=new URL(e),this.headers=t,this.authProvider=n,this.redirectMode=r,this.fetchFn=i??globalThis.fetch}setProtocolVersion(e){this.protocolVersion=e}async commonHeaders(e){let t={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??C};if(this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(t.Authorization=`Bearer ${e.access_token}`)}return ae(t,`ai-sdk/${Qe}`,i())}async start(){return new Promise((e,t)=>{if(this.connected)return e();this.abortController=new AbortController;let n=async(r=!1)=>{var i,a,o,s;try{let s=await this.commonHeaders({Accept:`text/event-stream`}),c=await this.fetchFn(this.url.href,{headers:s,signal:this.abortController?.signal,redirect:this.redirectMode});if(c.status===401&&this.authProvider&&!r){this.resourceMetadataUrl=G(c);try{if(await J(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,fetchFn:this.fetchFn})!==`AUTHORIZED`){let e=new H;return(i=this.onerror)==null||i.call(this,e),t(e)}}catch(e){return(a=this.onerror)==null||a.call(this,e),t(e)}return n(!0)}if(!c.ok||!c.body){let e=`MCP SSE Transport Error: ${c.status} ${c.statusText}`;c.status===405&&(e+=". This server does not support SSE transport. Try using `http` transport instead");let n=new P({message:e});return(o=this.onerror)==null||o.call(this,n),t(n)}let l=c.body.pipeThrough(new TextDecoderStream).pipeThrough(new y).getReader(),u=async()=>{var n,r,i,a,o;try{for(;;){let{done:t,value:o}=await l.read();if(t){if(this.connected)throw this.connected=!1,new P({message:`MCP SSE Transport Error: Connection closed unexpectedly`});return}let{event:s,data:c}=o;if(s===`endpoint`){if(this.endpoint)continue;let t=new URL(c,this.url);if(t.origin!==this.url.origin)throw this.connected=!1,this.endpoint=void 0,(n=this.sseConnection)==null||n.close(),(r=this.abortController)==null||r.abort(),new P({message:`MCP SSE Transport Error: Endpoint origin does not match connection origin: ${t.origin}`});this.endpoint=t,this.connected=!0,e()}else if(zt(s))try{let e=await N(c);(i=this.onmessage)==null||i.call(this,e)}catch(e){let t=new P({message:`MCP SSE Transport Error: Failed to parse message`,cause:e});(a=this.onerror)==null||a.call(this,t)}}}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(o=this.onerror)==null||o.call(this,e),t(e)}};this.sseConnection={close:()=>l.cancel()},u()}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(s=this.onerror)==null||s.call(this,e),t(e)}};n()})}async close(){var e,t,n;this.connected=!1,this.endpoint=void 0,(e=this.sseConnection)==null||e.close(),(t=this.abortController)==null||t.abort(),(n=this.onclose)==null||n.call(this)}async send(e,t){var n;if((n=t?.signal)==null||n.throwIfAborted(),!this.endpoint||!this.connected)throw new P({message:`MCP SSE Transport Error: Not connected`});let r=this.endpoint,i=this.abortController?.signal,a=t?.signal==null?i:i==null?t.signal:AbortSignal.any([i,t.signal]),o=async(n=!1)=>{var i,s,c,l;try{let t={method:`POST`,headers:await this.commonHeaders({"Content-Type":`application/json`}),body:JSON.stringify(e),signal:a,redirect:this.redirectMode},l=await this.fetchFn(r.href,t);if(l.status===401&&this.authProvider&&!n){this.resourceMetadataUrl=G(l);try{if(await J(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,fetchFn:this.fetchFn})!==`AUTHORIZED`){let e=new H;(i=this.onerror)==null||i.call(this,e);return}}catch(e){(s=this.onerror)==null||s.call(this,e);return}return o(!0)}if(!l.ok){let e=await l.text().catch(()=>null),t=new P({message:`MCP SSE Transport Error: POSTing to endpoint (HTTP ${l.status}): ${e}`});(c=this.onerror)==null||c.call(this,t);return}}catch(e){if(t?.signal?.aborted)throw e;(l=this.onerror)==null||l.call(this,e);return}};await o()}};function Vt(e){return e===void 0||e===`message`}var Ht=class{constructor({url:e,headers:t,authProvider:n,redirect:r=`error`,initialSessionId:i,initialProtocolVersion:a,onSessionIdChange:o,onSessionExpired:s,terminateSessionOnClose:c=!0,fetch:l}){this.inboundReconnectAttempts=0,this.reconnectionOptions={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},this.url=new URL(e),this.headers=t,this.authProvider=n,this.redirectMode=r,this.sessionId=i,this.protocolVersion=a,this.onSessionIdChange=o,this.onSessionExpired=s,this.terminateSessionOnClose=c,this.fetchFn=l??globalThis.fetch}setProtocolVersion(e){this.protocolVersion=e}async commonHeaders({base:e,includeSessionId:t=!0}){let n={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??C};if(t&&this.sessionId&&(n[`mcp-session-id`]=this.sessionId),this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(n.Authorization=`Bearer ${e.access_token}`)}return ae(n,`ai-sdk/${Qe}`,i())}setSessionId(e){var t;this.sessionId!==e&&(this.sessionId=e,(t=this.onSessionIdChange)==null||t.call(this,e))}applySessionIdFromResponse(e){let t=e.headers.get(`mcp-session-id`);t&&this.setSessionId(t)}expireSessionId(e){var t;this.sessionId===e&&this.setSessionId(void 0),(t=this.onSessionExpired)==null||t.call(this,e)}authorizeOnce(e){return this.authProvider?(this.authPromise||=J(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:e,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0}),this.authPromise):Promise.resolve(`REDIRECT`)}async start(){if(this.abortController)throw new P({message:`MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically.`});this.abortController=new AbortController,this.startInboundSse()}async close(e){var t,n,r,i,a;(t=this.inboundSseConnection)==null||t.close(),(n=this.abortController)==null||n.abort();try{if(this.sessionId&&this.terminateSessionOnClose&&this.abortController){(r=e?.signal)==null||r.throwIfAborted();let t=await this.commonHeaders({base:{}});(i=e?.signal)==null||i.throwIfAborted(),await this.fetchFn(this.url.href,{method:`DELETE`,headers:t,signal:e?.signal,redirect:this.redirectMode}).catch(()=>void 0)}}catch{}(a=this.onclose)==null||a.call(this)}async send(e,t){var n;(n=t?.signal)==null||n.throwIfAborted();let r=this.abortController?.signal,i=t?.signal==null?r:r==null?t.signal:AbortSignal.any([r,t.signal]),a=async(n=!1)=>{var r,o,s,c,l,u;try{let u=`method`in e&&e.method===`initialize`,d=u?void 0:this.sessionId,f={method:`POST`,headers:await this.commonHeaders({base:{"Content-Type":`application/json`,Accept:`application/json, text/event-stream`},includeSessionId:!u}),body:JSON.stringify(e),signal:i,redirect:this.redirectMode},p=await this.fetchFn(this.url.href,f);if(this.applySessionIdFromResponse(p),p.status===401&&this.authProvider&&!n){this.resourceMetadataUrl=G(p);try{if(await this.authorizeOnce(this.resourceMetadataUrl)!==`AUTHORIZED`)throw new H}catch(e){throw(r=this.onerror)==null||r.call(this,e),e}return a(!0)}if(p.status===202){this.inboundSseConnection||this.startInboundSse();return}if(!p.ok){let e=await p.text().catch(()=>null),t=`MCP HTTP Transport Error: POSTing to endpoint (HTTP ${p.status}): ${e}`;p.status===404&&(d?(this.expireSessionId(d),t+=". The MCP session expired. Create a new client without `initialSessionId` to start a fresh session"):t+=". This server does not support HTTP transport. Try using `sse` transport instead");let n=new P({message:t,statusCode:p.status,url:this.url.href,responseBody:e??void 0});throw(o=this.onerror)==null||o.call(this,n),n}if(!(`id`in e))return;let m=p.headers.get(`content-type`)||``;if(m.includes(`application/json`)){let e=await p.json(),t=Array.isArray(e)?e.map(e=>M(e)):[M(e)];for(let e of t)(s=this.onmessage)==null||s.call(this,e);return}if(m.includes(`text/event-stream`)){if(!p.body){let e=new P({message:`MCP HTTP Transport Error: text/event-stream response without body`,statusCode:p.status,url:this.url.href});throw(c=this.onerror)==null||c.call(this,e),e}let e=p.body.pipeThrough(new TextDecoderStream).pipeThrough(new y).getReader();(async()=>{var n,r,i;try{for(;;){let{done:t,value:i}=await e.read();if(t)return;let{event:a,data:o}=i;if(Vt(a))try{let e=await N(o);(n=this.onmessage)==null||n.call(this,e)}catch(e){let t=new P({message:`MCP HTTP Transport Error: Failed to parse message`,cause:e});(r=this.onerror)==null||r.call(this,t)}}}catch(e){if(t?.signal?.aborted||e instanceof Error&&e.name===`AbortError`)return;(i=this.onerror)==null||i.call(this,e)}})().catch(e=>{var n;t?.signal?.aborted||e instanceof Error&&e.name===`AbortError`||(n=this.onerror)==null||n.call(this,e)});return}let h=new P({message:`MCP HTTP Transport Error: Unexpected content type: ${m}`,statusCode:p.status,url:this.url.href});throw(l=this.onerror)==null||l.call(this,h),h}catch(e){throw t?.signal?.aborted||(u=this.onerror)==null||u.call(this,e),e}};await a()}getNextReconnectionDelay(e){let{initialReconnectionDelay:t,reconnectionDelayGrowFactor:n,maxReconnectionDelay:r}=this.reconnectionOptions;return Math.min(t*n**+e,r)}scheduleInboundSseReconnection(){var e;let{maxRetries:t}=this.reconnectionOptions;if(t>0&&this.inboundReconnectAttempts>=t){(e=this.onerror)==null||e.call(this,new P({message:`MCP HTTP Transport Error: Maximum reconnection attempts (${t}) exceeded.`}));return}let n=this.getNextReconnectionDelay(this.inboundReconnectAttempts);this.inboundReconnectAttempts+=1,setTimeout(()=>{this.abortController?.signal.aborted||this.startInboundSse(!1,this.lastInboundEventId)},n)}startInboundSse(e=!1,t){this.openInboundSse(e,t).catch(e=>{var t;e instanceof Error&&e.name===`AbortError`||(t=this.onerror)==null||t.call(this,e)})}async openInboundSse(e=!1,t){var n,r,i,a;try{let a=this.sessionId,o=await this.commonHeaders({base:{Accept:`text/event-stream`}});t&&(o[`last-event-id`]=t);let s=await this.fetchFn(this.url.href,{method:`GET`,headers:o,signal:this.abortController?.signal,redirect:this.redirectMode});if(this.applySessionIdFromResponse(s),s.status===401&&this.authProvider&&!e){this.resourceMetadataUrl=G(s);try{if(await this.authorizeOnce(this.resourceMetadataUrl)!==`AUTHORIZED`){let e=new H;(n=this.onerror)==null||n.call(this,e);return}}catch(e){(r=this.onerror)==null||r.call(this,e);return}return this.openInboundSse(!0,t)}if(s.status===405)return;if(!s.ok||!s.body){s.status===404&&a&&this.expireSessionId(a);let e=new P({message:`MCP HTTP Transport Error: GET SSE failed: ${s.status} ${s.statusText}`,statusCode:s.status,url:this.url.href});(i=this.onerror)==null||i.call(this,e);return}let c=s.body.pipeThrough(new TextDecoderStream).pipeThrough(new y).getReader(),l=async()=>{var e,t,n;try{for(;;){let{done:n,value:r}=await c.read();if(n)return;let{event:i,data:a,id:o}=r;if(o&&(this.lastInboundEventId=o),Vt(i))try{let t=await N(a);(e=this.onmessage)==null||e.call(this,t)}catch(e){let n=new P({message:`MCP HTTP Transport Error: Failed to parse message`,cause:e});(t=this.onerror)==null||t.call(this,n)}}}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(n=this.onerror)==null||n.call(this,e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}};this.inboundSseConnection={close:()=>{c.cancel().catch(e=>{var t;e instanceof Error&&e.name===`AbortError`||(t=this.onerror)==null||t.call(this,e)})}},this.inboundReconnectAttempts=0,l().catch(e=>{var t;e instanceof Error&&e.name===`AbortError`||((t=this.onerror)==null||t.call(this,e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection())})}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(a=this.onerror)==null||a.call(this,e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}}};function Ut(e){switch(e.type){case`sse`:return new Bt(e);case`http`:return new Ht(e);default:throw new P({message:`Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface.`})}}function Wt(e){return`start`in e&&typeof e.start==`function`&&`send`in e&&typeof e.send==`function`&&`close`in e&&typeof e.close==`function`}var Gt=`io.modelcontextprotocol/ui`,X=`text/html;profile=mcp-app`,Kt=`ui/resourceUri`,qt={extensions:{[Gt]:{mimeTypes:[X]}}};function Jt(e){let n=e?.ui;return t(n)?n:void 0}var Z=_(v()).transform(e=>e.filter(e=>typeof e==`string`)).optional().catch(void 0),Yt=x({connectDomains:Z,resourceDomains:Z,frameDomains:Z}),Xt=x({prefersBorder:m().optional().catch(void 0),csp:Yt.optional().catch(void 0),permissions:d(a(),v()).optional().catch(void 0)});function Zt(e){let n=(t(e)?e:void 0)?.ui;if(!t(n))return;let r=Xt.safeParse(n);return r.success?r.data:void 0}function Qt(e){return Array.isArray(e)?e.filter(e=>e===`model`||e===`app`):void 0}function $t(e){let t=Jt(e._meta),n=t?.resourceUri??e._meta?.[Kt],r=Qt(t?.visibility);if(n!==void 0){if(typeof n!=`string`||!n.startsWith(`ui://`))throw Error(`Invalid MCP App resource URI: ${JSON.stringify(n)}`)}else if(t==null)return;return{...t,...n==null?{}:{resourceUri:n},...r==null?{}:{visibility:r}}}function en(e){let t=[],n=[];for(let r of e.tools){let e=$t(r)?.visibility;(e==null||e.includes(`model`))&&t.push(r),e?.includes(`app`)===!0&&n.push(r)}return{modelVisible:{...e,tools:t},appVisible:{...e,tools:n}}}function tn({uri:e,resource:t}){let n=t.contents.find(t=>t.uri===e);if(n==null)throw Error(`MCP App resource not found in read result: ${e}`);if(n.mimeType!==`text/html;profile=mcp-app`)throw Error(`Unsupported MCP App resource MIME type: ${n.mimeType}`);let r=`text`in n&&typeof n.text==`string`?n.text:`blob`in n&&typeof n.blob==`string`?new TextDecoder().decode(ie(n.blob)):void 0;if(r==null)throw Error(`Unsupported MCP App resource content format: ${e}`);return{uri:e,mimeType:X,html:r,meta:Zt(n._meta)}}async function nn({client:e,uri:t,options:n}){if(!t.startsWith(`ui://`))throw Error(`Unsupported MCP App resource URI: ${t}`);return tn({uri:t,resource:await e.readResource({uri:t,options:n})})}var rn=`1.0.0`,an=0,on=[`ConnectionRefused`,`ConnectionClosed`,`FailedToOpenSocket`,`ECONNRESET`,`ECONNREFUSED`,`ETIMEDOUT`,`EPIPE`];function sn(e){if(typeof e==`object`&&e&&`statusCode`in e&&typeof e.statusCode==`number`)return e.statusCode}function cn(e){if(typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`)return e.code}function ln(e){let t=sn(e);if(t!=null)return t===408||t===409||t===429||t>=500;if(P.isInstance(e)&&e.code!=null)return!1;let n=cn(e);return n!=null&&on.includes(n)}function un(e){if(e==null)return an;if(!Number.isInteger(e))throw new P({message:`maxRetries must be an integer`});if(e<0)throw new P({message:`maxRetries must be >= 0`});return e}function dn({timeout:e,maxTotalTimeout:t}){return e==null?t:t==null?e:Math.min(e,t)}function Q(e,t){return t==null?e:new Promise((n,r)=>{let i=()=>{t.removeEventListener(`abort`,a)},a=()=>{i(),r(t.reason)};if(t.aborted){a();return}t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{i(),n(e)}).catch(e=>{i(),r(e)})})}function fn({output:e}){let t=e;return!(`content`in t)||!Array.isArray(t.content)?{type:`json`,value:t}:{type:`content`,value:t.content.map(e=>e.type===`text`&&`text`in e?{type:`text`,text:e.text}:e.type===`image`&&`data`in e&&`mimeType`in e?{type:`file`,mediaType:e.mimeType,data:{type:`data`,data:e.data}}:{type:`text`,text:JSON.stringify(e)})}}async function pn(e){let t=new mn(e);return await t.init(),t}var mn=class{constructor({transport:e,name:t,clientName:n=t??`ai-sdk-mcp-client`,version:r=rn,onUncaughtError:i,maxRetries:a,capabilities:o,initialInitializeResult:s,initializationOptions:c}){this.requestMessageId=0,this.responseHandlers=new Map,this.serverCapabilities={},this._serverInfo={name:``,version:``},this._initializeResult={protocolVersion:C,capabilities:{},serverInfo:this._serverInfo},this.isClosed=!0,this.onUncaughtError=i,this.maxRetries=un(a),this.clientCapabilities=o??{},this.initialInitializeResult=s,this.initializationOptions=c,Wt(e)?this.transport=e:this.transport=Ut(e),this.transport.onclose=()=>this.onClose(),this.transport.onerror=e=>this.onError(e),this.transport.onmessage=e=>{if(`method`in e){`id`in e?this.onRequestMessage(e):this.onError(new P({message:`Unsupported message type`}));return}this.onResponse(e)},this.clientInfo={name:n,version:r}}get serverInfo(){return this._serverInfo}get initializeResult(){return this._initializeResult}get instructions(){return this._serverInstructions}async init(){let e=this.initializationOptions?.signal,t=this.initializationOptions?dn(this.initializationOptions):void 0,n=t==null?void 0:new AbortController,r=e==null?n?.signal:n==null?e:AbortSignal.any([e,n.signal]),i,a;t!=null&&(i=setTimeout(()=>{a=new P({message:`MCP client initialization timed out after ${t}ms`}),n?.abort(a)},t));try{if(this.isClosed=!1,r?.throwIfAborted(),await Q(this.transport.start(),r),this.initialInitializeResult){let e=be.parse(this.initialInitializeResult);return this.applyInitializeResult(e),this}let e=await this.request({request:{method:`initialize`,params:{protocolVersion:C,capabilities:this.clientCapabilities,clientInfo:this.clientInfo}},resultSchema:be,options:{signal:r}});if(e===void 0)throw new P({message:`Server sent invalid initialize result`});return this.applyInitializeResult(e),await this.notification({method:`notifications/initialized`},{signal:r}),this}catch(t){try{await Q(this.transport.close({signal:r}),r)}catch{}throw this.onClose(),a??(e?.aborted?new P({message:`MCP client initialization was aborted`,cause:e.reason}):t)}finally{i!=null&&clearTimeout(i)}}applyInitializeResult(e){if(!me.includes(e.protocolVersion))throw new P({message:`Server's protocol version is not supported: ${e.protocolVersion}`});this.serverCapabilities=e.capabilities,this._serverInfo=e.serverInfo,this._initializeResult=e,this.transport.setProtocolVersion?this.transport.setProtocolVersion(e.protocolVersion):this.transport.protocolVersion=e.protocolVersion,this._serverInstructions=e.instructions}async close(){this.isClosed||(await this.transport?.close(),this.onClose())}send(e,t){return this.transport.send(e,t==null?void 0:{signal:t})}assertCapability(e){switch(e){case`initialize`:break;case`completion/complete`:if(!this.serverCapabilities.completions)throw new P({message:`Server does not support completions`});break;case`tools/list`:case`tools/call`:if(!this.serverCapabilities.tools)throw new P({message:`Server does not support tools`});break;case`resources/list`:case`resources/read`:case`resources/templates/list`:if(!this.serverCapabilities.resources)throw new P({message:`Server does not support resources`});break;case`prompts/list`:case`prompts/get`:if(!this.serverCapabilities.prompts)throw new P({message:`Server does not support prompts`});break;default:throw new P({message:`Unsupported method: ${e}`})}}async request({request:e,resultSchema:t,options:n}){return new Promise((r,i)=>{if(this.isClosed)return i(new P({message:`Attempted to send a request from a closed client`}));this.assertCapability(e.method);let a=n?.signal;a?.throwIfAborted();let o=n==null?void 0:dn(n),s=o==null?void 0:new AbortController,c=a==null?s?.signal:s==null?a:AbortSignal.any([a,s.signal]),l,u=this.requestMessageId++,d={...e,jsonrpc:`2.0`,id:u},f=()=>{i(new P({message:`Request was aborted`,cause:a?.reason}))},p=()=>{this.responseHandlers.delete(u),a?.removeEventListener(`abort`,h),l!=null&&clearTimeout(l)},m=e=>{p(),i(e)},h=()=>{p(),f()};this.responseHandlers.set(u,e=>{if(a?.aborted)return p(),f();if(e instanceof Error)return m(e);try{let n=t.parse(e.result);p(),r(n)}catch(e){let t=new P({message:`Failed to parse server response`,cause:e});m(t)}}),a?.addEventListener(`abort`,h,{once:!0}),o!=null&&(l=setTimeout(()=>{let e=new P({message:`Request timed out after ${o}ms`});s?.abort(e),m(e)},o)),(c==null?this.transport.send(d):this.send(d,c)).catch(e=>{m(e)})})}async listTools({params:e,options:t}={}){return this.request({request:{method:`tools/list`,params:e},resultSchema:Se,options:t})}async callToolWithRetry({options:e,execute:t}){return this.maxRetries===0?t():f({maxRetries:this.maxRetries,abortSignal:e?.signal,shouldRetry:ln,createRetryError:({message:e,errors:t})=>new P({message:e,cause:t[t.length-1]})})(t)}async callTool({name:e,arguments:t={},options:n}){try{return this.callToolWithRetry({options:n,execute:()=>this.request({request:{method:`tools/call`,params:{name:e,arguments:t}},resultSchema:ke,options:n})})}catch(e){throw e}}async listResourcesInternal({params:e,options:t}={}){try{return this.request({request:{method:`resources/list`,params:e},resultSchema:Ee,options:t})}catch(e){throw e}}async readResourceInternal({uri:e,options:t}){try{return this.request({request:{method:`resources/read`,params:{uri:e}},resultSchema:Me,options:t})}catch(e){throw e}}async listResourceTemplatesInternal({options:e}={}){try{return this.request({request:{method:`resources/templates/list`},resultSchema:je,options:e})}catch(e){throw e}}async listPromptsInternal({params:e,options:t}={}){try{return this.request({request:{method:`prompts/list`,params:e},resultSchema:ze,options:t})}catch(e){throw e}}async getPromptInternal({name:e,args:t,options:n}){try{return this.request({request:{method:`prompts/get`,params:{name:e,arguments:t}},resultSchema:Ve,options:n})}catch(e){throw e}}async completeInternal({options:e,...t}){return this.request({request:{method:`completion/complete`,params:t},resultSchema:Ie,options:e})}async notification(e,t){let n={...e,jsonrpc:`2.0`};await Q(this.send(n,t?.signal),t?.signal)}async tools({schemas:e=`automatic`}={}){let t=await this.listTools();return this.toolsFromDefinitions(t,{schemas:e})}toolsFromDefinitions(e,{schemas:t=`automatic`}={}){let r={};for(let{name:i,title:a,description:o,inputSchema:s,annotations:l,_meta:u}of e.tools){let e=a??l?.title;if(t!==`automatic`&&!Object.prototype.hasOwnProperty.call(t,i))continue;let d=this,f=t===`automatic`?void 0:t[i]?.outputSchema,p=$t({_meta:u}),m={clientName:this.clientInfo.name,toolName:i,...e==null?{}:{title:e},...p?.resourceUri==null?{}:{app:{...p,mimeType:X}}},h=async(e,t)=>{var n;(n=t?.abortSignal)==null||n.throwIfAborted();let r=await d.callTool({name:i,arguments:e,options:{signal:t?.abortSignal}});return r.isError||f==null?r:d.extractStructuredContent(r,f,i)};r[i]={...t===`automatic`?n({description:o,title:e,metadata:m,inputSchema:c({...s,properties:s.properties??{},additionalProperties:!1}),execute:h,toModelOutput:fn}):re({description:o,title:e,metadata:m,inputSchema:t[i].inputSchema,...f==null?{}:{outputSchema:f},execute:h,toModelOutput:fn}),_meta:u}}return r}async extractStructuredContent(e,t,n){if(`structuredContent`in e&&e.structuredContent!=null){let r=await l({value:e.structuredContent,schema:ne(t)});if(!r.success)throw new P({message:`Tool "${n}" returned structuredContent that does not match the expected outputSchema`,cause:r.error});return r.value}if(`content`in e&&Array.isArray(e.content)){let r=e.content.find(e=>e.type===`text`);if(r&&`text`in r){let e=await p({text:r.text,schema:t});if(!e.success)throw new P({message:`Tool "${n}" returned content that does not match the expected outputSchema`,cause:e.error});return e.value}}throw new P({message:`Tool "${n}" 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:n}){return this.getPromptInternal({name:e,args:t,options:n})}complete(e){return this.completeInternal(e)}onElicitationRequest(e,t){if(e!==A)throw new P({message:`Unsupported request schema. Only ElicitationRequestSchema is supported.`});this.elicitationRequestHandler=t}async onRequestMessage(e){try{if(e.method===`ping`){await this.transport.send({jsonrpc:`2.0`,id:e.id,result:{}});return}if(e.method!==`elicitation/create`){await this.transport.send({jsonrpc:`2.0`,id:e.id,error:{code:-32601,message:`Unsupported request method: ${e.method}`}});return}if(!this.elicitationRequestHandler){await this.transport.send({jsonrpc:`2.0`,id:e.id,error:{code:-32601,message:`No elicitation handler registered on client`}});return}let t=A.safeParse({method:e.method,params:e.params});if(!t.success){await this.transport.send({jsonrpc:`2.0`,id:e.id,error:{code:-32602,message:`Invalid elicitation request: ${t.error.message}`,data:t.error.issues}});return}try{let n=await this.elicitationRequestHandler(t.data),r=Ue.parse(n);await this.transport.send({jsonrpc:`2.0`,id:e.id,result:r})}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 P({message:`Connection closed`});for(let t of this.responseHandlers.values())t(e);this.responseHandlers.clear()}onError(e){this.onUncaughtError&&this.onUncaughtError(e)}onResponse(e){let t=Number(e.id),n=this.responseHandlers.get(t);if(n===void 0)throw new P({message:`Protocol error: Received a response for an unknown message ID: ${JSON.stringify(e)}`});this.responseHandlers.delete(t),n(`result`in e?e:new P({message:e.error.message,code:e.error.code,data:e.error.data,cause:e.error}))}},hn=new TextEncoder;function $(e){if(typeof e!=`object`||!e)return JSON.stringify(e??null);if(Array.isArray(e))return`[${e.map($).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${$(t[e])}`).join(`,`)}}`}function gn(e){return oe(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}async function _n(e){let t=await crypto.subtle.digest(`SHA-256`,hn.encode($({html:e.html,csp:e.meta?.csp??null,permissions:e.meta?.permissions??null})));return gn(new Uint8Array(t))}function vn(e,t){return e!==t}export{Ue as ElicitResultSchema,A as ElicitationRequestSchema,X as MCP_APP_MIME_TYPE,H as UnauthorizedError,J as auth,pn as createMCPClient,pn as experimental_createMCPClient,vn as detectMCPAppResourceDrift,_n as fingerprintMCPAppResource,qt as mcpAppClientCapabilities,nn as readMCPAppResource,en as splitMCPAppTools,M as validateJSONRPCMessage};
1
+ import{C as e,Ct as t,E as n,Et as r,H as i,Mt as a,Ot as o,P as s,Q as c,St as l,Tt as u,Vt as d,X as f,Z as p,_t as m,bt as h,gt as g,ht as _,jt as ee,kt as v,mt as te,n as ne,nt as re,o as ie,st as ae,u as oe,ut as y,wt as b,xt as x}from"../../_chunks/workflow/dist-Cz-ffHKC.js";const se={invalid_type:`invalid_type`,too_big:`too_big`,too_small:`too_small`,invalid_format:`invalid_format`,not_multiple_of:`not_multiple_of`,unrecognized_keys:`unrecognized_keys`,invalid_union:`invalid_union`,invalid_key:`invalid_key`,invalid_element:`invalid_element`,invalid_value:`invalid_value`,custom:`custom`};var ce;ce||={};let S;S=globalThis.crypto?.webcrypto??globalThis.crypto??import(`node:crypto`).then(e=>e.webcrypto);async function le(e){return(await S).getRandomValues(new Uint8Array(e))}async function ue(e){let t=``;for(;t.length<e;){let n=await le(e-t.length);for(let e of n)e<198&&(t+=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~`[e%66])}return t}async function de(e){return await ue(e)}async function fe(e){let t=await(await S).subtle.digest(`SHA-256`,new TextEncoder().encode(e));return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g,`_`).replace(/\+/g,`-`).replace(/=/g,``)}async function pe(e){if(e||=43,e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;let t=await de(e);return{code_verifier:t,code_challenge:await fe(t)}}var C=`2025-11-25`,me=[C,`2025-06-18`,`2025-03-26`,`2024-11-05`],he=b(u(r(),v())),ge=x({name:r(),version:r(),title:b(r())}),w=x({_meta:b(t({}).loose())}),T=w,_e=t({method:r(),params:b(w)}),ve=t({applyDefaults:b(m())}).loose(),ye=x({experimental:b(t({}).loose()),logging:b(t({}).loose()),completions:b(t({}).loose()),prompts:b(x({listChanged:b(m())})),resources:b(x({subscribe:b(m()),listChanged:b(m())})),tools:b(x({listChanged:b(m())})),elicitation:b(ve)});t({elicitation:b(ve)}).loose();var be=T.extend({protocolVersion:r(),capabilities:ye,serverInfo:ge,instructions:b(r())}),E=T.extend({nextCursor:b(r())}),xe=t({name:r(),title:b(r()),description:b(r()),inputSchema:t({type:h(`object`),properties:b(t({}).loose())}).loose(),outputSchema:b(t({}).loose()),annotations:b(t({title:b(r())}).loose()),_meta:he}).loose(),Se=E.extend({tools:_(xe)}),Ce=t({type:h(`text`),text:r()}).loose(),we=t({type:h(`image`),data:g(),mimeType:r()}).loose(),Te=t({uri:r(),name:r(),title:b(r()),description:b(r()),mimeType:b(r()),size:b(l())}).loose(),Ee=E.extend({resources:_(Te)}),D=t({uri:r(),name:b(r()),title:b(r()),mimeType:b(r())}).loose(),O=D.extend({text:r()}),k=D.extend({blob:g()}),De=t({type:h(`resource`),resource:o([O,k])}).loose(),Oe=t({type:h(`resource_link`),uri:r(),name:r(),description:b(r()),mimeType:b(r())}).loose(),ke=T.extend({content:_(o([Ce,we,De,Oe])),structuredContent:b(v()),isError:m().default(!1).optional()}).or(T.extend({toolResult:v()})),Ae=t({uriTemplate:r(),name:r(),title:b(r()),description:b(r()),mimeType:b(r())}).loose(),je=T.extend({resourceTemplates:_(Ae)}),Me=T.extend({contents:_(o([O,k]))}),Ne=t({type:h(`ref/prompt`),name:r()}).loose(),Pe=t({type:h(`ref/resource`),uri:r()}).loose(),Fe=t({name:r(),value:r()}).loose();w.extend({ref:o([Ne,Pe]),argument:Fe,context:b(t({arguments:u(r(),r())}).loose())});var Ie=T.extend({completion:t({values:_(r()).max(100),total:b(l().int()),hasMore:b(m())}).loose()}),Le=t({name:r(),description:b(r()),required:b(m())}).loose(),Re=t({name:r(),title:b(r()),description:b(r()),arguments:b(_(Le))}).loose(),ze=E.extend({prompts:_(Re)}),Be=t({role:o([h(`user`),h(`assistant`)]),content:o([Ce,we,De,Oe])}).loose(),Ve=T.extend({description:b(r()),messages:_(Be)}),He=w.extend({message:r(),requestedSchema:v()}),A=_e.extend({method:h(`elicitation/create`),params:He}),Ue=T.extend({action:o([h(`accept`),h(`decline`),h(`cancel`)]),content:b(u(r(),v()))}),j=`2.0`,We=t({jsonrpc:h(j),id:o([r(),l().int()])}).merge(_e).strict(),Ge=t({jsonrpc:h(j),id:o([r(),l().int()]),result:T}).strict(),Ke=t({jsonrpc:h(j),id:o([r(),l().int()]),error:t({code:l().int(),message:r(),data:b(v())})}).strict(),qe=o([We,t({jsonrpc:h(j)}).merge(t({method:r(),params:b(w)})).strict(),Ge,Ke]);function M(e){return qe.parse(e)}async function N(e){return M(await i({text:e}))}var Je=`vercel.ai.error.AI_MCPClientError`,Ye=Symbol.for(Je),Xe,Ze,P=class extends (Ze=a,Xe=Ye,Ze){constructor({name:e=`MCPClientError`,message:t,cause:n,data:r,code:i,statusCode:a,url:o,responseBody:s}){super({name:e,message:t,cause:n}),this[Xe]=!0,this.data=r,this.code=i,this.statusCode=a,this.url=o,this.responseBody=s}static isInstance(e){return a.hasMarker(e,Je)}},Qe=typeof __PACKAGE_VERSION__<`u`?__PACKAGE_VERSION__:`0.0.0-test`,F=r().url().superRefine((e,t)=>{if(!URL.canParse(e))return t.addIssue({code:se.custom,message:`URL must be parseable`,fatal:!0}),ee}).refine(e=>{let t=new URL(e);return t.protocol!==`javascript:`&&t.protocol!==`data:`&&t.protocol!==`vbscript:`},{message:`URL cannot use javascript:, data:, or vbscript: scheme`}),$e=t({access_token:r(),id_token:r().optional(),token_type:r(),expires_in:l().optional(),scope:r().optional(),refresh_token:r().optional(),authorization_server:F.optional(),token_endpoint:F.optional()}).strip(),et=x({resource:r().url(),authorization_servers:_(F).optional(),jwks_uri:r().url().optional(),scopes_supported:_(r()).optional(),bearer_methods_supported:_(r()).optional(),resource_signing_alg_values_supported:_(r()).optional(),resource_name:r().optional(),resource_documentation:r().optional(),resource_policy_uri:r().url().optional(),resource_tos_uri:r().url().optional(),tls_client_certificate_bound_access_tokens:m().optional(),authorization_details_types_supported:_(r()).optional(),dpop_signing_alg_values_supported:_(r()).optional(),dpop_bound_access_tokens_required:m().optional()}),tt=x({issuer:r(),authorization_endpoint:F,token_endpoint:F,registration_endpoint:F.optional(),scopes_supported:_(r()).optional(),response_types_supported:_(r()),grant_types_supported:_(r()).optional(),code_challenge_methods_supported:_(r()).optional(),token_endpoint_auth_methods_supported:_(r()).optional(),token_endpoint_auth_signing_alg_values_supported:_(r()).optional()}),nt=x({issuer:r(),authorization_endpoint:F,token_endpoint:F,userinfo_endpoint:F.optional(),jwks_uri:F,registration_endpoint:F.optional(),scopes_supported:_(r()).optional(),response_types_supported:_(r()),grant_types_supported:_(r()).optional(),subject_types_supported:_(r()),id_token_signing_alg_values_supported:_(r()),claims_supported:_(r()).optional(),token_endpoint_auth_methods_supported:_(r()).optional()}).merge(tt.pick({code_challenge_methods_supported:!0})),rt=t({client_id:r(),client_secret:r().optional(),client_id_issued_at:l().optional(),client_secret_expires_at:l().optional(),authorization_server:F.optional(),token_endpoint:F.optional()}).strip(),it=t({redirect_uris:_(F),token_endpoint_auth_method:r().optional(),grant_types:_(r()).optional(),response_types:_(r()).optional(),client_name:r().optional(),client_uri:F.optional(),logo_uri:F.optional(),scope:r().optional(),contacts:_(r()).optional(),tos_uri:F.optional(),policy_uri:r().optional(),jwks_uri:F.optional(),jwks:te().optional(),software_id:r().optional(),software_version:r().optional(),software_statement:r().optional()}).strip(),at=t({error:r(),error_description:r().optional(),error_uri:r().optional()}),ot=it.merge(rt),st=`vercel.ai.error.AI_MCPClientOAuthError`,ct=Symbol.for(st),lt,ut,I=class extends (ut=a,lt=ct,ut){constructor({name:e=`MCPClientOAuthError`,message:t,cause:n}){super({name:e,message:t,cause:n}),this[lt]=!0}static isInstance(e){return a.hasMarker(e,st)}},L=class extends I{};L.errorCode=`server_error`;var R=class extends I{};R.errorCode=`invalid_client`;var z=class extends I{};z.errorCode=`invalid_grant`;var B=class extends I{};B.errorCode=`unauthorized_client`;var dt={[L.errorCode]:L,[R.errorCode]:R,[z.errorCode]:z,[B.errorCode]:B};function ft(e){let t=typeof e==`string`?new URL(e):new URL(e.href);return t.hash=``,t}function V(e){let t=e.href;return e.pathname===`/`&&t.endsWith(`/`)?t.slice(0,-1):t}function pt({requestedResource:e,configuredResource:t}){let n=typeof e==`string`?new URL(e):new URL(e.href),r=typeof t==`string`?new URL(t):new URL(t.href);if(n.origin!==r.origin||n.pathname.length<r.pathname.length)return!1;let i=n.pathname.endsWith(`/`)?n.pathname:n.pathname+`/`,a=r.pathname.endsWith(`/`)?r.pathname:r.pathname+`/`;return i.startsWith(a)}var H=class extends Error{constructor(e=`Unauthorized`){super(e),this.name=`UnauthorizedError`}};function U(e){return new URL(e).href}function mt(e,t){return{authorizationServerUrl:U(e),tokenEndpoint:U(t?.token_endpoint?new URL(t.token_endpoint):new URL(`/token`,e))}}function ht(e,t){return{...e,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function gt(e,t){return{...e,authorization_server:t.authorizationServerUrl,token_endpoint:t.tokenEndpoint}}function _t(e){if(!(!e?.authorization_server||!e.token_endpoint))return{authorizationServerUrl:U(e.authorization_server),tokenEndpoint:U(e.token_endpoint)}}async function W({provider:e,clientInformation:t,tokens:n}){let r=_t(n);if(r)return r;let i=await e.authorizationServerInformation?.call(e);return i?{authorizationServerUrl:U(i.authorizationServerUrl),tokenEndpoint:U(i.tokenEndpoint)}:_t(t)}async function vt({provider:e,clientInformation:t,authorizationServerInformation:n}){return e.saveAuthorizationServerInformation?(await e.saveAuthorizationServerInformation(n),!0):e.saveClientInformation?(await e.saveClientInformation(gt(t,n)),!0):!1}function yt(e,t){if(!t)return;let n=new URL(e).origin;if(t.origin!==n)throw new I({message:`OAuth protected resource metadata URL ${t.href} must have the same origin as the MCP server URL ${n}`})}function bt({storedAuthorizationServerInformation:e,currentAuthorizationServerInformation:t}){if(e.authorizationServerUrl!==t.authorizationServerUrl||e.tokenEndpoint!==t.tokenEndpoint)throw new I({message:`OAuth authorization server metadata does not match the metadata that issued the stored credentials`})}function G(e){let t=e.headers.get(`www-authenticate`)??e.headers.get(`WWW-Authenticate`);if(!t)return;let[n,r]=t.split(` `);if(n.toLowerCase()!==`bearer`||!r)return;let i=t.match(/resource_metadata="([^"]*)"/);if(i)try{return new URL(i[1])}catch{return}}function xt(e,t=``,n={}){return t.endsWith(`/`)&&(t=t.slice(0,-1)),n.prependPathname?`${t}/.well-known/${e}`:`/.well-known/${e}${t}`}async function K(e,t,n=fetch){try{return await n(e,{headers:t})}catch(r){if(r instanceof TypeError)return t?K(e,void 0,n):void 0;throw r}}async function St(e,t,n=fetch){return await K(e,{"MCP-Protocol-Version":t},n)}function Ct(e,t){return!e||e.status>=400&&e.status<500&&t!==`/`}async function wt(e,t,n,r){let i=new URL(e),a=r?.protocolVersion??C,o;if(r?.metadataUrl)o=new URL(r.metadataUrl);else{let e=xt(t,i.pathname);o=new URL(e,r?.metadataServerUrl??i),o.search=i.search}let s=await St(o,a,n);return!r?.metadataUrl&&Ct(s,i.pathname)&&(s=await St(new URL(`/.well-known/${t}`,i),a,n)),s}async function Tt(e,t,n=fetch){let r=await wt(e,`oauth-protected-resource`,n,{protocolVersion:t?.protocolVersion,metadataUrl:t?.resourceMetadataUrl});if(!r||r.status===404)throw Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);if(!r.ok)throw Error(`HTTP ${r.status} trying to load well-known OAuth protected resource metadata.`);return et.parse(await r.json())}function Et(e){let t=typeof e==`string`?new URL(e):e,n=t.pathname!==`/`,r=t.origin,i=[];if(!n)return i.push({url:new URL(`/.well-known/oauth-authorization-server`,t.origin),type:`oauth`,expectedIssuer:r}),i.push({url:new URL(`/.well-known/openid-configuration`,t.origin),type:`oidc`,expectedIssuer:r}),i;let a=t.pathname;a.endsWith(`/`)&&(a=a.slice(0,-1));let o=`${t.origin}${a}`;return i.push({url:new URL(`/.well-known/oauth-authorization-server${a}`,t.origin),type:`oauth`,expectedIssuer:o}),i.push({url:new URL(`/.well-known/oauth-authorization-server`,t.origin),type:`oauth`,expectedIssuer:r}),i.push({url:new URL(`/.well-known/openid-configuration${a}`,t.origin),type:`oidc`,expectedIssuer:o}),i.push({url:new URL(`${a}/.well-known/openid-configuration`,t.origin),type:`oidc`,expectedIssuer:o}),i}function Dt(e,t){if(e.issuer!==t)throw new I({message:`OAuth authorization server metadata issuer ${e.issuer} does not match expected issuer ${t}`})}async function Ot(e,{fetchFn:t=fetch,protocolVersion:n=C}={}){let r={"MCP-Protocol-Version":n},i=Et(e);for(let{url:e,type:n,expectedIssuer:a}of i){let i=await K(e,r,t);if(i){if(!i.ok){if(i.status>=400&&i.status<500)continue;throw Error(`HTTP ${i.status} trying to load ${n===`oauth`?`OAuth`:`OpenID provider`} metadata from ${e}`)}if(n===`oauth`){let e=tt.parse(await i.json());return Dt(e,a),e}else{let t=nt.parse(await i.json());if(Dt(t,a),!t.code_challenge_methods_supported?.includes(`S256`))throw Error(`Incompatible OIDC provider at ${e}: does not support S256 code challenge method required by MCP specification`);return t}}}}async function kt(e,{metadata:t,clientInformation:n,redirectUrl:r,scope:i,state:a,resource:o}){let s=`code`,c=`S256`,l;if(t){if(l=new URL(t.authorization_endpoint),!t.response_types_supported.includes(s))throw Error(`Incompatible auth server: does not support response type ${s}`);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 l=new URL(`/authorize`,e);let u=await pe(),d=u.code_verifier,f=u.code_challenge;return l.searchParams.set(`response_type`,s),l.searchParams.set(`client_id`,n.client_id),l.searchParams.set(`code_challenge`,f),l.searchParams.set(`code_challenge_method`,c),l.searchParams.set(`redirect_uri`,String(r)),a&&l.searchParams.set(`state`,a),i&&l.searchParams.set(`scope`,i),i?.includes(`offline_access`)&&l.searchParams.append(`prompt`,`consent`),o&&l.searchParams.set(`resource`,V(o)),{authorizationUrl:l,codeVerifier:d}}function At(e,t){let n=e.client_secret!==void 0;return t.length===0?n?`client_secret_post`:`none`:n&&t.includes(`client_secret_basic`)?`client_secret_basic`:n&&t.includes(`client_secret_post`)?`client_secret_post`:t.includes(`none`)?`none`:n?`client_secret_post`:`none`}function jt(e,t,n,r){let{client_id:i,client_secret:a}=t;switch(e){case`client_secret_basic`:Mt(i,a,n);return;case`client_secret_post`:Nt(i,a,r);return;case`none`:Pt(i,r);return;default:throw Error(`Unsupported client authentication method: ${e}`)}}function Mt(e,t,n){if(!t)throw Error(`client_secret_basic authentication requires a client_secret`);let r=btoa(`${e}:${t}`);n.set(`Authorization`,`Basic ${r}`)}function Nt(e,t,n){n.set(`client_id`,e),t&&n.set(`client_secret`,t)}function Pt(e,t){t.set(`client_id`,e)}async function q(e){let t=e instanceof Response?e.status:void 0,n=e instanceof Response?await e.text():e;try{let{error:e,error_description:t,error_uri:r}=at.parse(await i({text:n}));return new(dt[e]||L)({message:t||``,cause:r})}catch(e){return new L({message:`${t?`HTTP ${t}: `:``}Invalid OAuth error response: ${e}. Raw body: ${n}`})}}async function Ft(e,{metadata:t,clientInformation:n,authorizationCode:r,codeVerifier:i,redirectUri:a,resource:o,addClientAuthentication:s,fetchFn:c}){let l=`authorization_code`,u=t?.token_endpoint?new URL(t.token_endpoint):new URL(`/token`,e);if(t?.grant_types_supported&&!t.grant_types_supported.includes(l))throw Error(`Incompatible auth server: does not support grant type ${l}`);let d=new Headers({"Content-Type":`application/x-www-form-urlencoded`,Accept:`application/json`}),f=new URLSearchParams({grant_type:l,code:r,code_verifier:i,redirect_uri:String(a)});s?await s(d,f,e,t):jt(At(n,t?.token_endpoint_auth_methods_supported??[]),n,d,f),o&&f.set(`resource`,V(o));let p=await(c??fetch)(u,{method:`POST`,headers:d,body:f});if(!p.ok)throw await q(p);return $e.parse(await p.json())}async function It(e,{metadata:t,clientInformation:n,refreshToken:r,resource:i,addClientAuthentication:a,fetchFn:o}){let s=`refresh_token`,c;if(t){if(c=new URL(t.token_endpoint),t.grant_types_supported&&!t.grant_types_supported.includes(s))throw Error(`Incompatible auth server: does not support grant type ${s}`)}else c=new URL(`/token`,e);let l=new Headers({"Content-Type":`application/x-www-form-urlencoded`,Accept:`application/json`}),u=new URLSearchParams({grant_type:s,refresh_token:r});a?await a(l,u,e,t):jt(At(n,t?.token_endpoint_auth_methods_supported??[]),n,l,u),i&&u.set(`resource`,V(i));let d=await(o??fetch)(c,{method:`POST`,headers:l,body:u});if(!d.ok)throw await q(d);return $e.parse({refresh_token:r,...await d.json()})}async function Lt(e,{metadata:t,clientMetadata:n,fetchFn:r}){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 a=await(r??fetch)(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!a.ok)throw await q(a);return ot.parse(await a.json())}async function J(e,t){try{return await Y(e,t)}catch(n){if(n instanceof R||n instanceof B)return await e.invalidateCredentials?.call(e,`all`),await Y(e,t);if(n instanceof z)return await e.invalidateCredentials?.call(e,`tokens`),await Y(e,t);throw n}}async function Rt(e,t,n){let r=ft(e);if(t.validateResourceURL)return await t.validateResourceURL(r,n?.resource);if(n){if(!pt({requestedResource:r,configuredResource:n.resource}))throw Error(`Protected resource ${n.resource} does not match expected ${r} (or origin)`);return new URL(n.resource)}}async function Y(e,{serverUrl:t,authorizationCode:n,callbackState:r,scope:i,resourceMetadataUrl:a,fetchFn:o}){let s,c;yt(t,a);try{s=await Tt(t,{resourceMetadataUrl:a},o),s.authorization_servers&&s.authorization_servers.length>0&&(c=s.authorization_servers[0])}catch{}c||=t;let l=await Rt(t,e,s);await e.validateAuthorizationServerURL?.call(e,t,c);let u=await Ot(c,{fetchFn:o}),d=mt(c,u),f=await Promise.resolve(e.clientInformation());if(!f){if(n!==void 0)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`);f=gt(await Lt(c,{metadata:u,clientMetadata:e.clientMetadata,fetchFn:o}),d),await e.saveClientInformation(f)}if(n!==void 0){if(e.storedState){let t=await e.storedState();if(t!==void 0&&t!==r)throw Error(`OAuth state parameter mismatch - possible CSRF attack`)}let t=await W({provider:e,clientInformation:f});if(!t)throw new I({message:`Stored OAuth authorization server metadata is required when exchanging an authorization code`});bt({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:d});let i=await e.codeVerifier(),a=await Ft(c,{metadata:u,clientInformation:f,authorizationCode:n,codeVerifier:i,redirectUri:e.redirectUrl,resource:l,addClientAuthentication:e.addClientAuthentication,fetchFn:o});return await e.saveTokens(ht(a,d)),`AUTHORIZED`}let p=await e.tokens();if(p?.refresh_token){let t=await W({provider:e,clientInformation:f,tokens:p});t?bt({storedAuthorizationServerInformation:t,currentAuthorizationServerInformation:d}):await e.invalidateCredentials?.call(e,`tokens`);try{if(t){let t=await It(c,{metadata:u,clientInformation:f,refreshToken:p.refresh_token,resource:l,addClientAuthentication:e.addClientAuthentication,fetchFn:o});return await e.saveTokens(ht(t,d)),`AUTHORIZED`}}catch(e){if(!(!(e instanceof I)||e instanceof L))throw e}}let m=e.state?await e.state():void 0;m&&e.saveState&&await e.saveState(m);let{authorizationUrl:h,codeVerifier:g}=await kt(c,{metadata:u,clientInformation:f,state:m,redirectUrl:e.redirectUrl,scope:i||e.clientMetadata.scope,resource:l});if(!await vt({provider:e,clientInformation:f,authorizationServerInformation:d}))throw new I({message:`OAuth authorization server metadata must be saveable before starting authorization`});return await e.saveCodeVerifier(g),await e.redirectToAuthorization(h),`REDIRECT`}function zt(e){return e===void 0||e===`message`}var Bt=class{constructor({url:e,headers:t,authProvider:n,redirect:r=`error`,fetch:i}){this.connected=!1,this.url=new URL(e),this.headers=t,this.authProvider=n,this.redirectMode=r,this.fetchFn=i??globalThis.fetch}setProtocolVersion(e){this.protocolVersion=e}async commonHeaders(e){let t={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??C};if(this.authProvider){let e=await this.authProvider.tokens();e?.access_token&&(t.Authorization=`Bearer ${e.access_token}`)}return ae(t,`ai-sdk/${Qe}`,n())}async start(){return new Promise((e,t)=>{if(this.connected)return e();this.abortController=new AbortController;let n=async(r=!1)=>{var i,a,o,s;try{let s=await this.commonHeaders({Accept:`text/event-stream`}),c=await this.fetchFn(this.url.href,{headers:s,signal:this.abortController?.signal,redirect:this.redirectMode});if(c.status===401&&this.authProvider&&!r){this.resourceMetadataUrl=G(c);try{if(await J(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,fetchFn:this.fetchFn})!==`AUTHORIZED`){let e=new H;return(i=this.onerror)==null||i.call(this,e),t(e)}}catch(e){return(a=this.onerror)==null||a.call(this,e),t(e)}return n(!0)}if(!c.ok||!c.body){let e=`MCP SSE Transport Error: ${c.status} ${c.statusText}`;c.status===405&&(e+=". This server does not support SSE transport. Try using `http` transport instead");let n=new P({message:e});return(o=this.onerror)==null||o.call(this,n),t(n)}let l=c.body.pipeThrough(new TextDecoderStream).pipeThrough(new y).getReader(),u=async()=>{var n,r,i,a,o;try{for(;;){let{done:t,value:o}=await l.read();if(t){if(this.connected)throw this.connected=!1,new P({message:`MCP SSE Transport Error: Connection closed unexpectedly`});return}let{event:s,data:c}=o;if(s===`endpoint`){if(this.endpoint)continue;let t=new URL(c,this.url);if(t.origin!==this.url.origin)throw this.connected=!1,this.endpoint=void 0,(n=this.sseConnection)==null||n.close(),(r=this.abortController)==null||r.abort(),new P({message:`MCP SSE Transport Error: Endpoint origin does not match connection origin: ${t.origin}`});this.endpoint=t,this.connected=!0,e()}else if(zt(s))try{let e=await N(c);(i=this.onmessage)==null||i.call(this,e)}catch(e){let t=new P({message:`MCP SSE Transport Error: Failed to parse message`,cause:e});(a=this.onerror)==null||a.call(this,t)}}}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(o=this.onerror)==null||o.call(this,e),t(e)}};this.sseConnection={close:()=>l.cancel()},u()}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(s=this.onerror)==null||s.call(this,e),t(e)}};n()})}async close(){var e,t,n;this.connected=!1,this.endpoint=void 0,(e=this.sseConnection)==null||e.close(),(t=this.abortController)==null||t.abort(),(n=this.onclose)==null||n.call(this)}async send(e,t){var n;if((n=t?.signal)==null||n.throwIfAborted(),!this.endpoint||!this.connected)throw new P({message:`MCP SSE Transport Error: Not connected`});let r=this.endpoint,i=this.abortController?.signal,a=t?.signal==null?i:i==null?t.signal:AbortSignal.any([i,t.signal]),o=async(n=!1)=>{var i,s,c,l;try{let t={method:`POST`,headers:await this.commonHeaders({"Content-Type":`application/json`}),body:JSON.stringify(e),signal:a,redirect:this.redirectMode},l=await this.fetchFn(r.href,t);if(l.status===401&&this.authProvider&&!n){this.resourceMetadataUrl=G(l);try{if(await J(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:this.resourceMetadataUrl,fetchFn:this.fetchFn})!==`AUTHORIZED`){let e=new H;(i=this.onerror)==null||i.call(this,e);return}}catch(e){(s=this.onerror)==null||s.call(this,e);return}return o(!0)}if(!l.ok){let e=await l.text().catch(()=>null),t=new P({message:`MCP SSE Transport Error: POSTing to endpoint (HTTP ${l.status}): ${e}`});(c=this.onerror)==null||c.call(this,t);return}}catch(e){if(t?.signal?.aborted)throw e;(l=this.onerror)==null||l.call(this,e);return}};await o()}};function Vt(e){return e===void 0||e===`message`}var Ht=class{constructor({url:e,headers:t,authProvider:n,redirect:r=`error`,initialSessionId:i,initialProtocolVersion:a,onSessionIdChange:o,onSessionExpired:s,terminateSessionOnClose:c=!0,fetch:l}){this.inboundReconnectAttempts=0,this.reconnectionOptions={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},this.url=new URL(e),this.headers=t,this.authProvider=n,this.redirectMode=r,this.sessionId=i,this.protocolVersion=a,this.onSessionIdChange=o,this.onSessionExpired=s,this.terminateSessionOnClose=c,this.fetchFn=l??globalThis.fetch}setProtocolVersion(e){this.protocolVersion=e}async commonHeaders({base:e,includeSessionId:t=!0}){let r={...this.headers,...e,"mcp-protocol-version":this.protocolVersion??C};if(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 ae(r,`ai-sdk/${Qe}`,n())}setSessionId(e){var t;this.sessionId!==e&&(this.sessionId=e,(t=this.onSessionIdChange)==null||t.call(this,e))}applySessionIdFromResponse(e){let t=e.headers.get(`mcp-session-id`);t&&this.setSessionId(t)}expireSessionId(e){var t;this.sessionId===e&&this.setSessionId(void 0),(t=this.onSessionExpired)==null||t.call(this,e)}authorizeOnce(e){return this.authProvider?(this.authPromise||=J(this.authProvider,{serverUrl:this.url,resourceMetadataUrl:e,fetchFn:this.fetchFn}).finally(()=>{this.authPromise=void 0}),this.authPromise):Promise.resolve(`REDIRECT`)}async start(){if(this.abortController)throw new P({message:`MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically.`});this.abortController=new AbortController,this.startInboundSse()}async close(e){var t,n,r,i,a;(t=this.inboundSseConnection)==null||t.close(),(n=this.abortController)==null||n.abort();try{if(this.sessionId&&this.terminateSessionOnClose&&this.abortController){(r=e?.signal)==null||r.throwIfAborted();let t=await this.commonHeaders({base:{}});(i=e?.signal)==null||i.throwIfAborted(),await this.fetchFn(this.url.href,{method:`DELETE`,headers:t,signal:e?.signal,redirect:this.redirectMode}).catch(()=>void 0)}}catch{}(a=this.onclose)==null||a.call(this)}async send(e,t){var n;(n=t?.signal)==null||n.throwIfAborted();let r=this.abortController?.signal,i=t?.signal==null?r:r==null?t.signal:AbortSignal.any([r,t.signal]),a=async(n=!1)=>{var r,o,s,c,l,u;try{let u=`method`in e&&e.method===`initialize`,d=u?void 0:this.sessionId,f={method:`POST`,headers:await this.commonHeaders({base:{"Content-Type":`application/json`,Accept:`application/json, text/event-stream`},includeSessionId:!u}),body:JSON.stringify(e),signal:i,redirect:this.redirectMode},p=await this.fetchFn(this.url.href,f);if(this.applySessionIdFromResponse(p),p.status===401&&this.authProvider&&!n){this.resourceMetadataUrl=G(p);try{if(await this.authorizeOnce(this.resourceMetadataUrl)!==`AUTHORIZED`)throw new H}catch(e){throw(r=this.onerror)==null||r.call(this,e),e}return a(!0)}if(p.status===202){this.inboundSseConnection||this.startInboundSse();return}if(!p.ok){let e=await p.text().catch(()=>null),t=`MCP HTTP Transport Error: POSTing to endpoint (HTTP ${p.status}): ${e}`;p.status===404&&(d?(this.expireSessionId(d),t+=". The MCP session expired. Create a new client without `initialSessionId` to start a fresh session"):t+=". This server does not support HTTP transport. Try using `sse` transport instead");let n=new P({message:t,statusCode:p.status,url:this.url.href,responseBody:e??void 0});throw(o=this.onerror)==null||o.call(this,n),n}if(!(`id`in e))return;let m=p.headers.get(`content-type`)||``;if(m.includes(`application/json`)){let e=await p.json(),t=Array.isArray(e)?e.map(e=>M(e)):[M(e)];for(let e of t)(s=this.onmessage)==null||s.call(this,e);return}if(m.includes(`text/event-stream`)){if(!p.body){let e=new P({message:`MCP HTTP Transport Error: text/event-stream response without body`,statusCode:p.status,url:this.url.href});throw(c=this.onerror)==null||c.call(this,e),e}let e=p.body.pipeThrough(new TextDecoderStream).pipeThrough(new y).getReader();(async()=>{var n,r,i;try{for(;;){let{done:t,value:i}=await e.read();if(t)return;let{event:a,data:o}=i;if(Vt(a))try{let e=await N(o);(n=this.onmessage)==null||n.call(this,e)}catch(e){let t=new P({message:`MCP HTTP Transport Error: Failed to parse message`,cause:e});(r=this.onerror)==null||r.call(this,t)}}}catch(e){if(t?.signal?.aborted||e instanceof Error&&e.name===`AbortError`)return;(i=this.onerror)==null||i.call(this,e)}})().catch(e=>{var n;t?.signal?.aborted||e instanceof Error&&e.name===`AbortError`||(n=this.onerror)==null||n.call(this,e)});return}let h=new P({message:`MCP HTTP Transport Error: Unexpected content type: ${m}`,statusCode:p.status,url:this.url.href});throw(l=this.onerror)==null||l.call(this,h),h}catch(e){throw t?.signal?.aborted||(u=this.onerror)==null||u.call(this,e),e}};await a()}getNextReconnectionDelay(e){let{initialReconnectionDelay:t,reconnectionDelayGrowFactor:n,maxReconnectionDelay:r}=this.reconnectionOptions;return Math.min(t*n**+e,r)}scheduleInboundSseReconnection(){var e;let{maxRetries:t}=this.reconnectionOptions;if(t>0&&this.inboundReconnectAttempts>=t){(e=this.onerror)==null||e.call(this,new P({message:`MCP HTTP Transport Error: Maximum reconnection attempts (${t}) exceeded.`}));return}let n=this.getNextReconnectionDelay(this.inboundReconnectAttempts);this.inboundReconnectAttempts+=1,setTimeout(()=>{this.abortController?.signal.aborted||this.startInboundSse(!1,this.lastInboundEventId)},n)}startInboundSse(e=!1,t){this.openInboundSse(e,t).catch(e=>{var t;e instanceof Error&&e.name===`AbortError`||(t=this.onerror)==null||t.call(this,e)})}async openInboundSse(e=!1,t){var n,r,i,a;try{let a=this.sessionId,o=await this.commonHeaders({base:{Accept:`text/event-stream`}});t&&(o[`last-event-id`]=t);let s=await this.fetchFn(this.url.href,{method:`GET`,headers:o,signal:this.abortController?.signal,redirect:this.redirectMode});if(this.applySessionIdFromResponse(s),s.status===401&&this.authProvider&&!e){this.resourceMetadataUrl=G(s);try{if(await this.authorizeOnce(this.resourceMetadataUrl)!==`AUTHORIZED`){let e=new H;(n=this.onerror)==null||n.call(this,e);return}}catch(e){(r=this.onerror)==null||r.call(this,e);return}return this.openInboundSse(!0,t)}if(s.status===405)return;if(!s.ok||!s.body){s.status===404&&a&&this.expireSessionId(a);let e=new P({message:`MCP HTTP Transport Error: GET SSE failed: ${s.status} ${s.statusText}`,statusCode:s.status,url:this.url.href});(i=this.onerror)==null||i.call(this,e);return}let c=s.body.pipeThrough(new TextDecoderStream).pipeThrough(new y).getReader(),l=async()=>{var e,t,n;try{for(;;){let{done:n,value:r}=await c.read();if(n)return;let{event:i,data:a,id:o}=r;if(o&&(this.lastInboundEventId=o),Vt(i))try{let t=await N(a);(e=this.onmessage)==null||e.call(this,t)}catch(e){let n=new P({message:`MCP HTTP Transport Error: Failed to parse message`,cause:e});(t=this.onerror)==null||t.call(this,n)}}}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(n=this.onerror)==null||n.call(this,e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}};this.inboundSseConnection={close:()=>{c.cancel().catch(e=>{var t;e instanceof Error&&e.name===`AbortError`||(t=this.onerror)==null||t.call(this,e)})}},this.inboundReconnectAttempts=0,l().catch(e=>{var t;e instanceof Error&&e.name===`AbortError`||((t=this.onerror)==null||t.call(this,e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection())})}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;(a=this.onerror)==null||a.call(this,e),this.abortController?.signal.aborted||this.scheduleInboundSseReconnection()}}};function Ut(e){switch(e.type){case`sse`:return new Bt(e);case`http`:return new Ht(e);default:throw new P({message:`Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface.`})}}function Wt(e){return`start`in e&&typeof e.start==`function`&&`send`in e&&typeof e.send==`function`&&`close`in e&&typeof e.close==`function`}var Gt=`io.modelcontextprotocol/ui`,X=`text/html;profile=mcp-app`,Kt=`ui/resourceUri`,qt={extensions:{[Gt]:{mimeTypes:[X]}}};function Jt(e){let t=e?.ui;return d(t)?t:void 0}var Z=_(v()).transform(e=>e.filter(e=>typeof e==`string`)).optional().catch(void 0),Yt=x({connectDomains:Z,resourceDomains:Z,frameDomains:Z}),Xt=x({prefersBorder:m().optional().catch(void 0),csp:Yt.optional().catch(void 0),permissions:u(r(),v()).optional().catch(void 0)});function Zt(e){let t=(d(e)?e:void 0)?.ui;if(!d(t))return;let n=Xt.safeParse(t);return n.success?n.data:void 0}function Qt(e){return Array.isArray(e)?e.filter(e=>e===`model`||e===`app`):void 0}function $t(e){let t=Jt(e._meta),n=t?.resourceUri??e._meta?.[Kt],r=Qt(t?.visibility);if(n!==void 0){if(typeof n!=`string`||!n.startsWith(`ui://`))throw Error(`Invalid MCP App resource URI: ${JSON.stringify(n)}`)}else if(t==null)return;return{...t,...n==null?{}:{resourceUri:n},...r==null?{}:{visibility:r}}}function en(e){let t=[],n=[];for(let r of e.tools){let e=$t(r)?.visibility;(e==null||e.includes(`model`))&&t.push(r),e?.includes(`app`)===!0&&n.push(r)}return{modelVisible:{...e,tools:t},appVisible:{...e,tools:n}}}function tn({uri:e,resource:t}){let n=t.contents.find(t=>t.uri===e);if(n==null)throw Error(`MCP App resource not found in read result: ${e}`);if(n.mimeType!==`text/html;profile=mcp-app`)throw Error(`Unsupported MCP App resource MIME type: ${n.mimeType}`);let r=`text`in n&&typeof n.text==`string`?n.text:`blob`in n&&typeof n.blob==`string`?new TextDecoder().decode(ie(n.blob)):void 0;if(r==null)throw Error(`Unsupported MCP App resource content format: ${e}`);return{uri:e,mimeType:X,html:r,meta:Zt(n._meta)}}async function nn({client:e,uri:t,options:n}){if(!t.startsWith(`ui://`))throw Error(`Unsupported MCP App resource URI: ${t}`);return tn({uri:t,resource:await e.readResource({uri:t,options:n})})}var rn=`1.0.0`,an=0,on=[`ConnectionRefused`,`ConnectionClosed`,`FailedToOpenSocket`,`ECONNRESET`,`ECONNREFUSED`,`ETIMEDOUT`,`EPIPE`];function sn(e){if(typeof e==`object`&&e&&`statusCode`in e&&typeof e.statusCode==`number`)return e.statusCode}function cn(e){if(typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`)return e.code}function ln(e){let t=sn(e);if(t!=null)return t===408||t===409||t===429||t>=500;if(P.isInstance(e)&&e.code!=null)return!1;let n=cn(e);return n!=null&&on.includes(n)}function un(e){if(e==null)return an;if(!Number.isInteger(e))throw new P({message:`maxRetries must be an integer`});if(e<0)throw new P({message:`maxRetries must be >= 0`});return e}function dn({timeout:e,maxTotalTimeout:t}){return e==null?t:t==null?e:Math.min(e,t)}function Q(e,t){return t==null?e:new Promise((n,r)=>{let i=()=>{t.removeEventListener(`abort`,a)},a=()=>{i(),r(t.reason)};if(t.aborted){a();return}t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{i(),n(e)}).catch(e=>{i(),r(e)})})}function fn({output:e}){let t=e;return!(`content`in t)||!Array.isArray(t.content)?{type:`json`,value:t}:{type:`content`,value:t.content.map(e=>e.type===`text`&&`text`in e?{type:`text`,text:e.text}:e.type===`image`&&`data`in e&&`mimeType`in e?{type:`file`,mediaType:e.mimeType,data:{type:`data`,data:e.data}}:{type:`text`,text:JSON.stringify(e)})}}async function pn(e){let t=new mn(e);return await t.init(),t}var mn=class{constructor({transport:e,name:t,clientName:n=t??`ai-sdk-mcp-client`,version:r=rn,onUncaughtError:i,maxRetries:a,capabilities:o,initialInitializeResult:s,initializationOptions:c}){this.requestMessageId=0,this.responseHandlers=new Map,this.serverCapabilities={},this._serverInfo={name:``,version:``},this._initializeResult={protocolVersion:C,capabilities:{},serverInfo:this._serverInfo},this.isClosed=!0,this.onUncaughtError=i,this.maxRetries=un(a),this.clientCapabilities=o??{},this.initialInitializeResult=s,this.initializationOptions=c,Wt(e)?this.transport=e:this.transport=Ut(e),this.transport.onclose=()=>this.onClose(),this.transport.onerror=e=>this.onError(e),this.transport.onmessage=e=>{if(`method`in e){`id`in e?this.onRequestMessage(e):this.onError(new P({message:`Unsupported message type`}));return}this.onResponse(e)},this.clientInfo={name:n,version:r}}get serverInfo(){return this._serverInfo}get initializeResult(){return this._initializeResult}get instructions(){return this._serverInstructions}async init(){let e=this.initializationOptions?.signal,t=this.initializationOptions?dn(this.initializationOptions):void 0,n=t==null?void 0:new AbortController,r=e==null?n?.signal:n==null?e:AbortSignal.any([e,n.signal]),i,a;t!=null&&(i=setTimeout(()=>{a=new P({message:`MCP client initialization timed out after ${t}ms`}),n?.abort(a)},t));try{if(this.isClosed=!1,r?.throwIfAborted(),await Q(this.transport.start(),r),this.initialInitializeResult){let e=be.parse(this.initialInitializeResult);return this.applyInitializeResult(e),this}let e=await this.request({request:{method:`initialize`,params:{protocolVersion:C,capabilities:this.clientCapabilities,clientInfo:this.clientInfo}},resultSchema:be,options:{signal:r}});if(e===void 0)throw new P({message:`Server sent invalid initialize result`});return this.applyInitializeResult(e),await this.notification({method:`notifications/initialized`},{signal:r}),this}catch(t){try{await Q(this.transport.close({signal:r}),r)}catch{}throw this.onClose(),a??(e?.aborted?new P({message:`MCP client initialization was aborted`,cause:e.reason}):t)}finally{i!=null&&clearTimeout(i)}}applyInitializeResult(e){if(!me.includes(e.protocolVersion))throw new P({message:`Server's protocol version is not supported: ${e.protocolVersion}`});this.serverCapabilities=e.capabilities,this._serverInfo=e.serverInfo,this._initializeResult=e,this.transport.setProtocolVersion?this.transport.setProtocolVersion(e.protocolVersion):this.transport.protocolVersion=e.protocolVersion,this._serverInstructions=e.instructions}async close(){this.isClosed||(await this.transport?.close(),this.onClose())}send(e,t){return this.transport.send(e,t==null?void 0:{signal:t})}assertCapability(e){switch(e){case`initialize`:break;case`completion/complete`:if(!this.serverCapabilities.completions)throw new P({message:`Server does not support completions`});break;case`tools/list`:case`tools/call`:if(!this.serverCapabilities.tools)throw new P({message:`Server does not support tools`});break;case`resources/list`:case`resources/read`:case`resources/templates/list`:if(!this.serverCapabilities.resources)throw new P({message:`Server does not support resources`});break;case`prompts/list`:case`prompts/get`:if(!this.serverCapabilities.prompts)throw new P({message:`Server does not support prompts`});break;default:throw new P({message:`Unsupported method: ${e}`})}}async request({request:e,resultSchema:t,options:n}){return new Promise((r,i)=>{if(this.isClosed)return i(new P({message:`Attempted to send a request from a closed client`}));this.assertCapability(e.method);let a=n?.signal;a?.throwIfAborted();let o=n==null?void 0:dn(n),s=o==null?void 0:new AbortController,c=a==null?s?.signal:s==null?a:AbortSignal.any([a,s.signal]),l,u=this.requestMessageId++,d={...e,jsonrpc:`2.0`,id:u},f=()=>{i(new P({message:`Request was aborted`,cause:a?.reason}))},p=()=>{this.responseHandlers.delete(u),a?.removeEventListener(`abort`,h),l!=null&&clearTimeout(l)},m=e=>{p(),i(e)},h=()=>{p(),f()};this.responseHandlers.set(u,e=>{if(a?.aborted)return p(),f();if(e instanceof Error)return m(e);try{let n=t.parse(e.result);p(),r(n)}catch(e){let t=new P({message:`Failed to parse server response`,cause:e});m(t)}}),a?.addEventListener(`abort`,h,{once:!0}),o!=null&&(l=setTimeout(()=>{let e=new P({message:`Request timed out after ${o}ms`});s?.abort(e),m(e)},o)),(c==null?this.transport.send(d):this.send(d,c)).catch(e=>{m(e)})})}async listTools({params:e,options:t}={}){return this.request({request:{method:`tools/list`,params:e},resultSchema:Se,options:t})}async callToolWithRetry({options:e,execute:t}){return this.maxRetries===0?t():f({maxRetries:this.maxRetries,abortSignal:e?.signal,shouldRetry:ln,createRetryError:({message:e,errors:t})=>new P({message:e,cause:t[t.length-1]})})(t)}async callTool({name:e,arguments:t={},options:n}){try{return this.callToolWithRetry({options:n,execute:()=>this.request({request:{method:`tools/call`,params:{name:e,arguments:t}},resultSchema:ke,options:n})})}catch(e){throw e}}async listResourcesInternal({params:e,options:t}={}){try{return this.request({request:{method:`resources/list`,params:e},resultSchema:Ee,options:t})}catch(e){throw e}}async readResourceInternal({uri:e,options:t}){try{return this.request({request:{method:`resources/read`,params:{uri:e}},resultSchema:Me,options:t})}catch(e){throw e}}async listResourceTemplatesInternal({options:e}={}){try{return this.request({request:{method:`resources/templates/list`},resultSchema:je,options:e})}catch(e){throw e}}async listPromptsInternal({params:e,options:t}={}){try{return this.request({request:{method:`prompts/list`,params:e},resultSchema:ze,options:t})}catch(e){throw e}}async getPromptInternal({name:e,args:t,options:n}){try{return this.request({request:{method:`prompts/get`,params:{name:e,arguments:t}},resultSchema:Ve,options:n})}catch(e){throw e}}async completeInternal({options:e,...t}){return this.request({request:{method:`completion/complete`,params:t},resultSchema:Ie,options:e})}async notification(e,t){let n={...e,jsonrpc:`2.0`};await Q(this.send(n,t?.signal),t?.signal)}async tools({schemas:e=`automatic`}={}){let t=await this.listTools();return this.toolsFromDefinitions(t,{schemas:e})}toolsFromDefinitions(t,{schemas:n=`automatic`}={}){let r={};for(let{name:i,title:a,description:o,inputSchema:c,annotations:l,_meta:u}of t.tools){let t=a??l?.title;if(n!==`automatic`&&!Object.prototype.hasOwnProperty.call(n,i))continue;let d=this,f=n===`automatic`?void 0:n[i]?.outputSchema,p=$t({_meta:u}),m={clientName:this.clientInfo.name,toolName:i,...t==null?{}:{title:t},...p?.resourceUri==null?{}:{app:{...p,mimeType:X}}},h=async(e,t)=>{var n;(n=t?.abortSignal)==null||n.throwIfAborted();let r=await d.callTool({name:i,arguments:e,options:{signal:t?.abortSignal}});return r.isError||f==null?r:d.extractStructuredContent(r,f,i)};r[i]={...n===`automatic`?e({description:o,title:t,metadata:m,inputSchema:s({...c,properties:c.properties??{},additionalProperties:!1}),execute:h,toModelOutput:fn}):re({description:o,title:t,metadata:m,inputSchema:n[i].inputSchema,...f==null?{}:{outputSchema:f},execute:h,toModelOutput:fn}),_meta:u}}return r}async extractStructuredContent(e,t,n){if(`structuredContent`in e&&e.structuredContent!=null){let r=await c({value:e.structuredContent,schema:ne(t)});if(!r.success)throw new P({message:`Tool "${n}" returned structuredContent that does not match the expected outputSchema`,cause:r.error});return r.value}if(`content`in e&&Array.isArray(e.content)){let r=e.content.find(e=>e.type===`text`);if(r&&`text`in r){let e=await p({text:r.text,schema:t});if(!e.success)throw new P({message:`Tool "${n}" returned content that does not match the expected outputSchema`,cause:e.error});return e.value}}throw new P({message:`Tool "${n}" 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:n}){return this.getPromptInternal({name:e,args:t,options:n})}complete(e){return this.completeInternal(e)}onElicitationRequest(e,t){if(e!==A)throw new P({message:`Unsupported request schema. Only ElicitationRequestSchema is supported.`});this.elicitationRequestHandler=t}async onRequestMessage(e){try{if(e.method===`ping`){await this.transport.send({jsonrpc:`2.0`,id:e.id,result:{}});return}if(e.method!==`elicitation/create`){await this.transport.send({jsonrpc:`2.0`,id:e.id,error:{code:-32601,message:`Unsupported request method: ${e.method}`}});return}if(!this.elicitationRequestHandler){await this.transport.send({jsonrpc:`2.0`,id:e.id,error:{code:-32601,message:`No elicitation handler registered on client`}});return}let t=A.safeParse({method:e.method,params:e.params});if(!t.success){await this.transport.send({jsonrpc:`2.0`,id:e.id,error:{code:-32602,message:`Invalid elicitation request: ${t.error.message}`,data:t.error.issues}});return}try{let n=await this.elicitationRequestHandler(t.data),r=Ue.parse(n);await this.transport.send({jsonrpc:`2.0`,id:e.id,result:r})}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 P({message:`Connection closed`});for(let t of this.responseHandlers.values())t(e);this.responseHandlers.clear()}onError(e){this.onUncaughtError&&this.onUncaughtError(e)}onResponse(e){let t=Number(e.id),n=this.responseHandlers.get(t);if(n===void 0)throw new P({message:`Protocol error: Received a response for an unknown message ID: ${JSON.stringify(e)}`});this.responseHandlers.delete(t),n(`result`in e?e:new P({message:e.error.message,code:e.error.code,data:e.error.data,cause:e.error}))}},hn=new TextEncoder;function $(e){if(typeof e!=`object`||!e)return JSON.stringify(e??null);if(Array.isArray(e))return`[${e.map($).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${$(t[e])}`).join(`,`)}}`}function gn(e){return oe(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}async function _n(e){let t=await crypto.subtle.digest(`SHA-256`,hn.encode($({html:e.html,csp:e.meta?.csp??null,permissions:e.meta?.permissions??null})));return gn(new Uint8Array(t))}function vn(e,t){return e!==t}export{Ue as ElicitResultSchema,A as ElicitationRequestSchema,X as MCP_APP_MIME_TYPE,H as UnauthorizedError,J as auth,pn as createMCPClient,pn as experimental_createMCPClient,vn as detectMCPAppResourceDrift,_n as fingerprintMCPAppResource,qt as mcpAppClientCapabilities,nn as readMCPAppResource,en as splitMCPAppTools,M as validateJSONRPCMessage};