dal-code 1.0.57 → 1.0.58

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 (264) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/bundle/chunks/{anthropic-messages-ASQGS6BL.js → anthropic-messages-FOIJU7LX.js} +1 -1
  3. package/dist/bundle/chunks/{azure-openai-responses-ZSCUJBSU.js → azure-openai-responses-7NBJZKX5.js} +1 -1
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  5. package/dist/bundle/chunks/{chunk-YTDTROS5.js → chunk-3QG7FIE4.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-6SPX3U36.js → chunk-4BOWD7PQ.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-F577XLVZ.js → chunk-4PBY6OYS.js} +1 -1
  8. package/dist/bundle/chunks/{chunk-PD6QS7YD.js → chunk-5MF5GEDD.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-KP7CMLOT.js → chunk-B7KZDIWA.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-6PQZ4KMC.js → chunk-C5ELI234.js} +1 -1
  11. package/dist/bundle/chunks/{chunk-FSX34SAZ.js → chunk-CCU76UL3.js} +6 -6
  12. package/dist/bundle/chunks/{chunk-MAJODFX6.js → chunk-DVEPGKL5.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-34D4KVPX.js → chunk-IONGABQF.js} +1 -1
  14. package/dist/bundle/chunks/{chunk-GPI2GHBH.js → chunk-JK74OC6W.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-JPBJUBY4.js → chunk-JXAFVEE4.js} +2 -2
  16. package/dist/bundle/chunks/{chunk-XIJS4F22.js → chunk-LMZYTWXD.js} +1 -1
  17. package/dist/bundle/chunks/{chunk-2E7RGBKM.js → chunk-NYSVXLKF.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-O3XFDBJ3.js → chunk-PMFHJN7I.js} +1 -1
  19. package/dist/bundle/chunks/{chunk-JPCWLZUZ.js → chunk-QFBU27TM.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-MZ7O6YLD.js → chunk-QU2VEHMW.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-LZTZWS3N.js → chunk-SCZEDPDC.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-TNSXMGQB.js → chunk-T5PI6B5P.js} +1 -1
  23. package/dist/bundle/chunks/{chunk-S7K3JBWA.js → chunk-X7I3V6OA.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-IRSW3MVW.js → chunk-XQF5XDEM.js} +2 -2
  25. package/dist/bundle/chunks/{cli-NP7QEFQE.js → cli-NQ7B7BGV.js} +1 -1
  26. package/dist/bundle/chunks/{cli-IDAZVEZ2.js → cli-RY666QAD.js} +1 -1
  27. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-WLKVTF6I.js → cloudflare-workers-ai-system-one-CFGOMWWZ.js} +1 -1
  28. package/dist/bundle/chunks/{execute-VXSJSHXH.js → execute-NJRE4WBO.js} +1 -1
  29. package/dist/bundle/chunks/{google-generative-ai-3HIBMVL4.js → google-generative-ai-ZA2RHPNE.js} +1 -1
  30. package/dist/bundle/chunks/{google-vertex-7PIUZFM3.js → google-vertex-Y2GRWOK7.js} +1 -1
  31. package/dist/bundle/chunks/{llama-cpp-classify-5OLOZHKT.js → llama-cpp-classify-G2JDOFHY.js} +1 -1
  32. package/dist/bundle/chunks/{mcp-GHYUCPI4.js → mcp-45D7KCZZ.js} +1 -1
  33. package/dist/bundle/chunks/{mistral-conversations-6Y33SI3U.js → mistral-conversations-MLV32BRV.js} +1 -1
  34. package/dist/bundle/chunks/{office-2JSKOL7V.js → office-UBOUFRAU.js} +1 -1
  35. package/dist/bundle/chunks/{openai-codex-responses-BYGMMTPH.js → openai-codex-responses-BDK3PY6G.js} +1 -1
  36. package/dist/bundle/chunks/{openai-completions-UWYQMOLR.js → openai-completions-BLXHKAB3.js} +1 -1
  37. package/dist/bundle/chunks/{openai-decisions-I5J7OD62.js → openai-decisions-IGVID576.js} +1 -1
  38. package/dist/bundle/chunks/{openai-responses-LWVKQGLT.js → openai-responses-KHZOEDF2.js} +1 -1
  39. package/dist/bundle/chunks/{openrouter-images-BDUFN6XX.js → openrouter-images-SA6PUASF.js} +1 -1
  40. package/dist/bundle/chunks/{pi-messages-64FHWMQR.js → pi-messages-3VAOLQ2Y.js} +1 -1
  41. package/dist/bundle/chunks/{review-OQEOVDLP.js → review-RZXLHPUZ.js} +1 -1
  42. package/dist/bundle/chunks/{router-3UQE4LBN.js → router-YBVXODIL.js} +1 -1
  43. package/dist/bundle/chunks/{runtime-E7KOB62K.js → runtime-FNCZJKOC.js} +1 -1
  44. package/dist/bundle/chunks/{sdk-5V64WBOZ.js → sdk-X6RX7FNE.js} +1 -1
  45. package/dist/bundle/chunks/{sync-INSWGFSB.js → sync-CRV6BXXC.js} +2 -2
  46. package/dist/bundle/chunks/{typesafe-system-one-7QFJ5JNW.js → typesafe-system-one-ER3DLYNF.js} +1 -1
  47. package/dist/bundle/chunks/{usage-MG7QDPG2.js → usage-LMRFS2HV.js} +1 -1
  48. package/dist/bundle/chunks/{virtual-modules-73ZLFCNE.js → virtual-modules-XIUNRFOZ.js} +1 -1
  49. package/dist/bundle/cli-runtime.js +1 -1
  50. package/dist/bundle/index.js +1 -1
  51. package/dist/bundle/rpc-entry.js +1 -1
  52. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  53. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  54. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  55. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  56. package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
  57. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  58. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  59. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  60. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  61. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  62. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  63. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  64. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  65. package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
  66. package/dist/node_modules/@dalcode/dal-learn/src/engine.js +3 -3
  67. package/dist/node_modules/@dalcode/dal-learn/src/index.js +11 -11
  68. package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +4 -4
  69. package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -2
  70. package/dist/node_modules/@dalcode/dal-learn/src/signals.js +6 -6
  71. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  72. package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
  73. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  74. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +1 -1
  75. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  76. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +1 -1
  77. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
  78. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  79. package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
  80. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  81. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  82. package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
  83. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  84. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  85. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  86. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  87. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  88. package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
  89. package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
  90. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  91. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  92. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  93. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  94. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  95. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  96. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  97. package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
  98. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  99. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
  100. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
  101. package/dist/node_modules/@earendil-works/pi-ai/package.json +3 -3
  102. package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
  103. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  104. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  105. package/dist/node_modules/@earendil-works/pi-schema/package.json +1 -1
  106. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  107. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  108. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  109. package/examples/extensions/gondolin/package-lock.json +2 -2
  110. package/examples/extensions/gondolin/package.json +1 -1
  111. package/examples/extensions/with-deps/package-lock.json +2 -2
  112. package/examples/extensions/with-deps/package.json +1 -1
  113. package/npm-shrinkwrap.json +2 -2
  114. package/package.json +1 -1
  115. package/dist/bun/register-bedrock.js +0 -1
  116. package/dist/cli/experimental/auth.js +0 -1
  117. package/dist/cli/experimental/cli.js +0 -1
  118. package/dist/cli/experimental/command-options.js +0 -1
  119. package/dist/cli/experimental/command.js +0 -1
  120. package/dist/cli/experimental/commands/client.js +0 -1
  121. package/dist/cli/experimental/commands/pi.js +0 -1
  122. package/dist/cli/experimental/commands/server.js +0 -1
  123. package/dist/cli/experimental/transport-address.js +0 -1
  124. package/dist/client/index.js +0 -1
  125. package/dist/client/remote-session.js +0 -1
  126. package/dist/client/transcript.js +0 -1
  127. package/dist/core/provider-attribution.js +0 -1
  128. package/dist/modes/interactive/components/daxnuts.js +0 -1
  129. package/dist/modes/interactive/theme/theme-json.js +0 -12
  130. package/dist/modes/interactive/theme/theme-schema.json +0 -356
  131. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +0 -1
  132. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js +0 -37
  133. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +0 -104
  134. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js +0 -16
  135. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/config.js +0 -1
  136. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/context.js +0 -1
  137. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +0 -10
  138. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/events.js +0 -1
  139. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/assistant.js +0 -1
  140. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/effect-gate.js +0 -1
  141. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/tools.js +0 -1
  142. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/hooks.js +0 -1
  143. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js +0 -17
  144. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/bash.js +0 -1
  145. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/bounded.js +0 -1
  146. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/chord.js +0 -1
  147. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/context.js +0 -1
  148. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/harness.js +0 -1
  149. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/hooks.js +0 -1
  150. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/index.js +0 -1
  151. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/jsonl.js +0 -4
  152. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/collapse.js +0 -3
  153. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/entries.js +0 -1
  154. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/frames.js +0 -1
  155. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/generation.js +0 -1
  156. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/job.js +0 -1
  157. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/plugin.js +0 -1
  158. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/post-tools.js +0 -1
  159. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/task-api.js +0 -1
  160. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/kinds/tool.js +0 -3
  161. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/membrane.js +0 -1
  162. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/memory.js +0 -1
  163. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/scheduler.js +0 -1
  164. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/session.js +0 -1
  165. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/system.js +0 -8
  166. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/types.js +0 -1
  167. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/pico3/view.js +0 -1
  168. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js +0 -5
  169. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/reducer.js +0 -1
  170. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/result.js +0 -1
  171. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/boundary.js +0 -1
  172. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/checkpoint.js +0 -1
  173. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/deferred.js +0 -1
  174. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/generation.js +0 -1
  175. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/reconcile.js +0 -1
  176. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/recovery.js +0 -1
  177. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/response.js +0 -1
  178. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/retry.js +0 -1
  179. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/structural.js +0 -1
  180. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/terminal.js +0 -1
  181. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/tool-placement.js +0 -1
  182. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive/tools.js +0 -1
  183. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/drive.js +0 -1
  184. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/harness.js +0 -1
  185. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/index.js +0 -1
  186. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/lane.js +0 -1
  187. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/progress.js +0 -1
  188. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/reducer.js +0 -1
  189. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/restore.js +0 -1
  190. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/transcript.js +0 -1
  191. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/types.js +0 -1
  192. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/commit.js +0 -1
  193. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/context.js +0 -1
  194. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork-policy.js +0 -1
  195. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.js +0 -1
  196. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/in-memory-storage-state.js +0 -1
  197. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/index.js +0 -1
  198. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.js +0 -1
  199. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js +0 -1
  200. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/fork.js +0 -1
  201. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/index.js +0 -1
  202. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/io.js +0 -3
  203. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/legacy-v3.js +0 -1
  204. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.js +0 -1
  205. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.js +0 -8
  206. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.js +0 -1
  207. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +0 -1
  208. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +0 -5
  209. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl.js +0 -1
  210. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +0 -1
  211. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +0 -1
  212. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.js +0 -1
  213. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/mutation-line.js +0 -1
  214. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +0 -1
  215. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +0 -1
  216. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.js +0 -1
  217. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/datasets.js +0 -1
  218. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/session-repo.js +0 -1
  219. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/benchmark/storage.js +0 -1
  220. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance/session-repo.js +0 -1
  221. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance/storage.js +0 -1
  222. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js +0 -1
  223. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/gating-storage.js +0 -1
  224. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/index.js +0 -1
  225. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/instrumented-storage.js +0 -1
  226. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/storage-decorator.js +0 -1
  227. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/types.js +0 -0
  228. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.js +0 -1
  229. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/values.js +0 -1
  230. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js +0 -10
  231. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js +0 -2
  232. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/telemetry.js +0 -1
  233. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/bash.js +0 -12
  234. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit-diff.js +0 -16
  235. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.js +0 -1
  236. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/file-mutation-queue.js +0 -1
  237. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/image.js +0 -1
  238. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.js +0 -1
  239. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/path-utils.js +0 -1
  240. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js +0 -14
  241. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/tool-context.js +0 -0
  242. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.js +0 -1
  243. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +0 -1
  244. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/adaptive-publisher.js +0 -1
  245. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/output-capture.js +0 -5
  246. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +0 -1
  247. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.js +0 -5
  248. package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/usage.js +0 -1
  249. package/dist/node_modules/@earendil-works/pi-agent-core/dist/node.js +0 -1
  250. package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/index.js +0 -0
  251. package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js +0 -1
  252. package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js +0 -1
  253. package/dist/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.js +0 -74
  254. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +0 -1
  255. package/dist/node_modules/@earendil-works/pi-ai/dist/images-models.js +0 -1
  256. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +0 -1
  257. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +0 -1
  258. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-images.js +0 -1
  259. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.js +0 -1
  260. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/deferred-tools.js +0 -1
  261. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/pi-user-agent.js +0 -1
  262. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.js +0 -1
  263. package/dist/server/create-harness.js +0 -1
  264. package/dist/utils/clipboard-native.js +0 -1
@@ -1,4 +1,4 @@
1
- var Yt=Object.defineProperty;var o=(e,t)=>Yt(e,"name",{value:t,configurable:!0});import{createRequire as Vt}from"node:module";const ks=Vt(import.meta.url);import{getProviderEnvValue as qt}from"./chunk-7DDKXS2Q.js";import{ToolCallArgumentsStream as Ht}from"./chunk-FFMDRXC4.js";import{calculateCost as Kt,createProvider as Jt}from"./chunk-PD6QS7YD.js";import{createAssistantMessageEventStream as be}from"./chunk-4LDEEFCY.js";import{getSystemMessageText as Xt}from"./chunk-GPI2GHBH.js";function Zt(e,t){return{name:e,login:o(async r=>{r.signal.throwIfAborted();let n=await r.prompt({type:"secret",message:`Enter ${e}`});return r.signal.throwIfAborted(),{type:"api_key",key:n}},"login"),resolve:o(async({ctx:r,credential:n,signal:i})=>{if(i.throwIfAborted(),n?.key)return{auth:{apiKey:n.key},env:n.env,source:"stored credential"};for(let s of t){let a=await r.env(s);if(i.throwIfAborted(),a)return{auth:{apiKey:a},source:s}}},"resolve")}}o(Zt,"envApiKeyAuth");function Qt(e){let t,r=o(()=>(t??=e.load(),t),"loaded");return{name:e.name,isSubscription:e.isSubscription,loginLabel:e.loginLabel,login:o(async(n,i)=>(await r()).login(n,i),"login"),refresh:o(async(n,i)=>(await r()).refresh(n,i),"refresh"),toAuth:o(async n=>(await r()).toAuth(n),"toAuth")}}o(Qt,"lazyOAuth");var er=60*6e4,tr=30*6e4,Oe=.05,ke=.15;function rr(e){if(!(e<=1e4))return Math.max(1,Math.floor(Math.min(e*.9,e-1e4)))}o(rr,"getCacheWarmingDelayMs");function nr(e,t){let r=t?.cacheRetention??(qt("PI_CACHE_RETENTION",t?.env)==="long"?"long":"short");if(r==="none")return;let n=e.promptCache?.[r];return n===void 0?void 0:n*1e3}o(nr,"getPromptCacheTtlMs");function ir(e,t){return!t?.reasoning||e.api!=="anthropic-messages"?!0:e.compat?.forceAdaptiveThinking===!0}o(ir,"isCacheWarmingReplayable");function sr(e,t){return{...e,maxTokens:1,disableContinuation:!0,maxRetries:0,signal:t}}o(sr,"getCacheWarmingRequestOptions");function or(e,t,r){let n=ie(e,{cacheRead:t}),i=ie(e,e.cost.cacheWrite>0?{cacheWrite:t}:{input:t}),s=ie(e,{cacheRead:t,output:1}),a=Math.max(0,i-n),f=r==="idle"?ke:1,u=t>0&&(n>0||i>0),c=f*a-s;return{phase:r,warmCost:s,missCost:a,continuationProbability:f,expectedSavings:c,economicsAvailable:u,action:c>=Oe?"warm":"stop"}}o(or,"evaluateCacheWarming");function ie(e,t){let r={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0},...t};return Kt(e,r).total}o(ie,"price");var Ee="faux",xe="faux",we="faux-1",ar="Faux Model",fr="http://localhost:0",ur=3,Re=5,V={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};function _e(e){return{type:"text",text:e}}o(_e,"fauxText");function cr(e){return{type:"thinking",thinking:e}}o(cr,"fauxThinking");function lr(e,t,r={}){return{type:"toolCall",id:r.id??se("tool"),name:e,arguments:t}}o(lr,"fauxToolCall");function dr(e){return typeof e=="string"?[_e(e)]:Array.isArray(e)?e:[e]}o(dr,"normalizeFauxAssistantContent");function hr(e,t={}){return{role:"assistant",content:dr(e),api:Ee,provider:xe,model:we,usage:V,stopReason:t.stopReason??"stop",...t.deferred===void 0?{}:{deferred:t.deferred},...t.errorMessage===void 0?{}:{errorMessage:t.errorMessage},...t.responseId===void 0?{}:{responseId:t.responseId},timestamp:t.timestamp??Date.now()}}o(hr,"fauxAssistantMessage");function Ne(e){return Math.ceil(e.length/4)}o(Ne,"estimateTokens");function se(e){return`${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`}o(se,"randomId");function $e(e){return typeof e=="string"?e:e.map(t=>t.type==="text"?t.text:`[image:${t.mimeType}:${t.data.length}]`).join(`
1
+ var Yt=Object.defineProperty;var o=(e,t)=>Yt(e,"name",{value:t,configurable:!0});import{createRequire as Vt}from"node:module";const ks=Vt(import.meta.url);import{getProviderEnvValue as qt}from"./chunk-7DDKXS2Q.js";import{ToolCallArgumentsStream as Ht}from"./chunk-FFMDRXC4.js";import{calculateCost as Kt,createProvider as Jt}from"./chunk-5MF5GEDD.js";import{createAssistantMessageEventStream as be}from"./chunk-4LDEEFCY.js";import{getSystemMessageText as Xt}from"./chunk-JK74OC6W.js";function Zt(e,t){return{name:e,login:o(async r=>{r.signal.throwIfAborted();let n=await r.prompt({type:"secret",message:`Enter ${e}`});return r.signal.throwIfAborted(),{type:"api_key",key:n}},"login"),resolve:o(async({ctx:r,credential:n,signal:i})=>{if(i.throwIfAborted(),n?.key)return{auth:{apiKey:n.key},env:n.env,source:"stored credential"};for(let s of t){let a=await r.env(s);if(i.throwIfAborted(),a)return{auth:{apiKey:a},source:s}}},"resolve")}}o(Zt,"envApiKeyAuth");function Qt(e){let t,r=o(()=>(t??=e.load(),t),"loaded");return{name:e.name,isSubscription:e.isSubscription,loginLabel:e.loginLabel,login:o(async(n,i)=>(await r()).login(n,i),"login"),refresh:o(async(n,i)=>(await r()).refresh(n,i),"refresh"),toAuth:o(async n=>(await r()).toAuth(n),"toAuth")}}o(Qt,"lazyOAuth");var er=60*6e4,tr=30*6e4,Oe=.05,ke=.15;function rr(e){if(!(e<=1e4))return Math.max(1,Math.floor(Math.min(e*.9,e-1e4)))}o(rr,"getCacheWarmingDelayMs");function nr(e,t){let r=t?.cacheRetention??(qt("PI_CACHE_RETENTION",t?.env)==="long"?"long":"short");if(r==="none")return;let n=e.promptCache?.[r];return n===void 0?void 0:n*1e3}o(nr,"getPromptCacheTtlMs");function ir(e,t){return!t?.reasoning||e.api!=="anthropic-messages"?!0:e.compat?.forceAdaptiveThinking===!0}o(ir,"isCacheWarmingReplayable");function sr(e,t){return{...e,maxTokens:1,disableContinuation:!0,maxRetries:0,signal:t}}o(sr,"getCacheWarmingRequestOptions");function or(e,t,r){let n=ie(e,{cacheRead:t}),i=ie(e,e.cost.cacheWrite>0?{cacheWrite:t}:{input:t}),s=ie(e,{cacheRead:t,output:1}),a=Math.max(0,i-n),f=r==="idle"?ke:1,u=t>0&&(n>0||i>0),c=f*a-s;return{phase:r,warmCost:s,missCost:a,continuationProbability:f,expectedSavings:c,economicsAvailable:u,action:c>=Oe?"warm":"stop"}}o(or,"evaluateCacheWarming");function ie(e,t){let r={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0},...t};return Kt(e,r).total}o(ie,"price");var Ee="faux",xe="faux",we="faux-1",ar="Faux Model",fr="http://localhost:0",ur=3,Re=5,V={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};function _e(e){return{type:"text",text:e}}o(_e,"fauxText");function cr(e){return{type:"thinking",thinking:e}}o(cr,"fauxThinking");function lr(e,t,r={}){return{type:"toolCall",id:r.id??se("tool"),name:e,arguments:t}}o(lr,"fauxToolCall");function dr(e){return typeof e=="string"?[_e(e)]:Array.isArray(e)?e:[e]}o(dr,"normalizeFauxAssistantContent");function hr(e,t={}){return{role:"assistant",content:dr(e),api:Ee,provider:xe,model:we,usage:V,stopReason:t.stopReason??"stop",...t.deferred===void 0?{}:{deferred:t.deferred},...t.errorMessage===void 0?{}:{errorMessage:t.errorMessage},...t.responseId===void 0?{}:{responseId:t.responseId},timestamp:t.timestamp??Date.now()}}o(hr,"fauxAssistantMessage");function Ne(e){return Math.ceil(e.length/4)}o(Ne,"estimateTokens");function se(e){return`${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`}o(se,"randomId");function $e(e){return typeof e=="string"?e:e.map(t=>t.type==="text"?t.text:`[image:${t.mimeType}:${t.data.length}]`).join(`
2
2
  `)}o($e,"contentToText");function Se(e){return e.map(t=>t.type==="text"?t.text:t.type==="thinking"?t.thinking:`${t.name}:${JSON.stringify(t.arguments)}`).join(`
3
3
  `)}o(Se,"assistantContentToText");function pr(e){return[e.toolName,...e.content.map(t=>$e([t]))].join(`
4
4
  `)}o(pr,"toolResultToText");function mr(e){return e.role==="system"?[Xt(e),...e.toolsRemoved?.map(t=>`tool-:${JSON.stringify(t)}`)??[],...e.toolsAdded?.map(t=>`tool+:${JSON.stringify(t)}`)??[]].filter(t=>t.length>0).join(`
@@ -1 +1 @@
1
- var R=Object.defineProperty;var o=(e,r)=>R(e,"name",{value:r,configurable:!0});import{createRequire as b}from"node:module";const S=b(import.meta.url);import{retryProviderRequest as w}from"./chunk-ML5DIOWR.js";import{headersToRecord as q,providerHeadersToRecord as k}from"./chunk-UTB4DTYQ.js";import{calculateCost as x}from"./chunk-PD6QS7YD.js";import{getIdentityHeaders as E}from"./chunk-GPI2GHBH.js";function $(e,r,a){let i=new Error(`${e} returned ${r.status}`);return i.status=r.status,i.headers=r.headers,i.body=a,i}o($,"httpError");function T(e){let r=new Error(`Request timed out after ${e}ms`);return r.name="TimeoutError",r.status=void 0,r.headers=void 0,r.body="",r}o(T,"timeoutError");function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(m,"isRecord");function _(e,r,a){if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${e} returned an invalid ${a}`);return r}o(_,"requiredNumber");function j(e,r,a,i){return k(E(e,i),{authorization:`Bearer ${r}`,"content-type":"application/json"},e.headers,a)??{}}o(j,"requestHeaders");async function A(e,r,a,i,t,y){if(!t?.apiKey)throw new Error(`No API key for provider: ${a.provider}`);let h=t.apiKey,u=i,d=await t.onPayload?.(u,a);d!==void 0&&(u=d);let l=t.fetch??globalThis.fetch,{response:c,json:p}=await w(async()=>{let s=t.timeoutMs!==void 0?AbortSignal.timeout(t.timeoutMs):void 0,g=t.signal&&s?AbortSignal.any([t.signal,s]):t.signal??s;try{let n=await l(r,{method:"POST",headers:j(a,h,t.headers,t.identity),body:JSON.stringify(u),signal:g});if(!n.ok)throw $(e,n,await n.text());return{response:n,json:await n.json()}}catch(n){throw s?.aborted&&!t.signal?.aborted?T(t.timeoutMs):n}},{maxRetries:t.maxRetries??2,maxRetryDelayMs:t.maxRetryDelayMs,signal:t.signal,noRetryStatuses:y});return await t.onResponse?.({status:c.status,headers:q(c.headers)},a),p}o(A,"postClassifierRequest");function f(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:0}o(f,"tokenCount");function C(e,r){if(!m(e)||e.input_tokens===void 0&&e.output_tokens===void 0)return;let a=f(e.input_tokens),i=f(e.output_tokens),t={input:a,output:i,cacheRead:0,cacheWrite:0,totalTokens:a+i,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};return x(r,t),t}o(C,"parseClassifierUsage");export{m as isRecord,C as parseClassifierUsage,A as postClassifierRequest,_ as requiredNumber};
1
+ var R=Object.defineProperty;var o=(e,r)=>R(e,"name",{value:r,configurable:!0});import{createRequire as b}from"node:module";const S=b(import.meta.url);import{retryProviderRequest as w}from"./chunk-ML5DIOWR.js";import{headersToRecord as q,providerHeadersToRecord as k}from"./chunk-UTB4DTYQ.js";import{calculateCost as x}from"./chunk-5MF5GEDD.js";import{getIdentityHeaders as E}from"./chunk-JK74OC6W.js";function $(e,r,a){let i=new Error(`${e} returned ${r.status}`);return i.status=r.status,i.headers=r.headers,i.body=a,i}o($,"httpError");function T(e){let r=new Error(`Request timed out after ${e}ms`);return r.name="TimeoutError",r.status=void 0,r.headers=void 0,r.body="",r}o(T,"timeoutError");function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(m,"isRecord");function _(e,r,a){if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${e} returned an invalid ${a}`);return r}o(_,"requiredNumber");function j(e,r,a,i){return k(E(e,i),{authorization:`Bearer ${r}`,"content-type":"application/json"},e.headers,a)??{}}o(j,"requestHeaders");async function A(e,r,a,i,t,y){if(!t?.apiKey)throw new Error(`No API key for provider: ${a.provider}`);let h=t.apiKey,u=i,d=await t.onPayload?.(u,a);d!==void 0&&(u=d);let l=t.fetch??globalThis.fetch,{response:c,json:p}=await w(async()=>{let s=t.timeoutMs!==void 0?AbortSignal.timeout(t.timeoutMs):void 0,g=t.signal&&s?AbortSignal.any([t.signal,s]):t.signal??s;try{let n=await l(r,{method:"POST",headers:j(a,h,t.headers,t.identity),body:JSON.stringify(u),signal:g});if(!n.ok)throw $(e,n,await n.text());return{response:n,json:await n.json()}}catch(n){throw s?.aborted&&!t.signal?.aborted?T(t.timeoutMs):n}},{maxRetries:t.maxRetries??2,maxRetryDelayMs:t.maxRetryDelayMs,signal:t.signal,noRetryStatuses:y});return await t.onResponse?.({status:c.status,headers:q(c.headers)},a),p}o(A,"postClassifierRequest");function f(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:0}o(f,"tokenCount");function C(e,r){if(!m(e)||e.input_tokens===void 0&&e.output_tokens===void 0)return;let a=f(e.input_tokens),i=f(e.output_tokens),t={input:a,output:i,cacheRead:0,cacheWrite:0,totalTokens:a+i,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};return x(r,t),t}o(C,"parseClassifierUsage");export{m as isRecord,C as parseClassifierUsage,A as postClassifierRequest,_ as requiredNumber};
@@ -1,4 +1,4 @@
1
- var Oe=Object.defineProperty;var s=(e,t)=>Oe(e,"name",{value:t,configurable:!0});import{createRequire as Le}from"node:module";const fr=Le(import.meta.url);import{FileAuthStorageBackend as xe,JSON_RPC_ERROR_CODES as $e,LATEST_PROTOCOL_VERSION as T,McpAuthRequiredError as De,McpClient as He,McpError as Ne,McpHttpError as K,McpSessionExpiredError as Fe,StdioTransport as z,StreamableHttpTransport as Ve,isClientMetadataDocumentCallback as je,isObject as W,mcpNamespace as Be,require_proper_lockfile as qe,resolveConfigValueOrThrow as J,resolveHeadersOrThrow as Ke}from"./chunk-6PQZ4KMC.js";import{sliceTail as Y}from"./chunk-HF334NQU.js";import{APP_NAME as Z,VERSION as We,getAgentDir as G}from"./chunk-R47JBGS3.js";import{__toESM as Je}from"./chunk-JXWJOIH4.js";import{homedir as Q}from"node:os";import{basename as Ye,join as Ze,resolve as Ge}from"node:path";import{setTimeout as Qe}from"node:timers/promises";import{pathToFileURL as Xe}from"node:url";import{createHash as et}from"node:crypto";var tt=class{static{s(this,"MemoryOAuthStateStore")}value;load(){return this.value===void 0?void 0:structuredClone(this.value)}save(e){this.value=structuredClone(e)}},rt=class{static{s(this,"McpOAuthProvider")}redirectUrl;clientMetadata;clientMetadataDocument;serverUrl;configuredClient;store;onRedirect;writes=Promise.resolve();constructor(e){this.serverUrl=String(new URL(e.serverUrl)),this.redirectUrl=String(e.redirectUrl),this.clientMetadata={...e.clientMetadata,redirect_uris:e.clientMetadata.redirect_uris??[this.redirectUrl],grant_types:e.clientMetadata.grant_types??["authorization_code","refresh_token"],response_types:e.clientMetadata.response_types??["code"],token_endpoint_auth_method:e.clientMetadata.token_endpoint_auth_method??(e.clientSecret?"client_secret_post":"none")},this.clientMetadataDocument=e.clientMetadataDocument,this.configuredClient=e.clientId?{client_id:e.clientId,...e.clientSecret?{client_secret:e.clientSecret}:{}}:void 0,this.store=e.store??new tt,this.onRedirect=e.onRedirect}async state(){let e=(await this.load()).oauthState;if(e)return e;let t=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex");return await this.update(r=>({...r,oauthState:t})),t}async clientInformation(){return this.configuredClient??(await this.load()).clientInformation}async saveClientInformation(e){this.configuredClient||await this.update(t=>({...t,clientInformation:e}))}async tokens(){return(await this.load()).tokens}async saveTokens(e){let t=e.expires_in===void 0?void 0:Date.now()+e.expires_in*1e3;await this.update(r=>{let i={...r,tokens:e};return t===void 0?delete i.tokensExpireAt:i.tokensExpireAt=t,i})}async redirectToAuthorization(e){await this.onRedirect(e)}async saveCodeVerifier(e){await this.update(t=>({...t,codeVerifier:e}))}async codeVerifier(){let e=(await this.load()).codeVerifier;if(!e)throw new Error("No OAuth PKCE code verifier is stored");return e}async invalidateCredentials(e){await this.update(t=>{let r={...t};return(e==="all"||e==="client")&&delete r.clientInformation,(e==="all"||e==="tokens")&&(delete r.tokens,delete r.tokensExpireAt),(e==="all"||e==="verifier")&&delete r.codeVerifier,(e==="all"||e==="discovery")&&delete r.discovery,e==="all"&&delete r.oauthState,r})}async saveDiscoveryState(e){await this.update(t=>({...t,discovery:e}))}async discoveryState(){return(await this.load()).discovery}async load(){return await this.writes,this.own(await this.store.load())}async update(e){this.writes=this.writes.then(async()=>{await this.store.save(e(this.own(await this.store.load())))}),await this.writes}own(e){return e?.serverUrl===this.serverUrl?e:{serverUrl:this.serverUrl}}};function P(e,t,r=()=>{}){let{serverUrl:i,settings:n,clientMetadataDocuments:a}=e;return new rt({serverUrl:i,redirectUrl:t,clientMetadata:{client_name:n.clientName??e.clientName},clientMetadataDocument:I(n,a,t)?o=>{if(!a?.listsRedirectUrl(t))throw new Error(`oauth.clientRegistration "cimd" needs Client ID Metadata Documents that list the redirect URI ${t}`);let c=it(i,t,o,a.baseUrl);if(!c&&n.clientRegistration==="cimd")throw new Error('The authorization server does not support Client ID Metadata Documents for public clients; remove oauth.clientRegistration "cimd"');return c}:void 0,clientId:n.clientId,clientSecret:n.clientSecret,store:e.store,onRedirect:r})}s(P,"createOAuthClientProvider");function I(e,t,r){let i=e.clientRegistration??"auto";return i!=="auto"?i==="cimd":!e.clientId&&!e.clientName&&t?.listsRedirectUrl(r)===!0}s(I,"offersClientMetadataDocument");function it(e,t,r,i){if(!r?.client_id_metadata_document_supported||!r.token_endpoint_auth_methods_supported?.includes("none"))return;if(r.authorization_response_iss_parameter_supported)return{url:`${i}/client.json`,redirectUrl:t};let n=new URL(t);return n.pathname=X(n.pathname,e),{url:`${i}/${ee(e)}/client.json`,redirectUrl:n.href}}s(it,"clientMetadataDocument");function X(e,t){return`${e.replace(/\/$/,"")}/${ee(t)}`}s(X,"serverSpecificPath");function ee(e){let t=new URL(e);return t.hash="",et("sha256").update(t.href).digest().subarray(0,9).toString("base64url")}s(ee,"callbackId");function O(e){return e&&"redirect_uris"in e?e.redirect_uris:[]}s(O,"registeredRedirectUrls");var nt=15e3;function te(e=globalThis.fetch){return(t,r)=>{let i=AbortSignal.timeout(nt);return e(t,{...r,signal:r?.signal?AbortSignal.any([r.signal,i]):i})}}s(te,"timedFetch");var re="127.0.0.1",at="/callback",ie=`http://${re}${at}`;function ne(e){let t=e.callbackUrl??ie,r=new URL(t),i=r.hostname.replace(/^\[|\]$/g,""),n=r.port?Number(r.port):e.callbackPort,a;return r.port?a=e.callbackUrl:n!==void 0&&(r.port=String(n),a=r.href),{url:t,host:i==="localhost"?re:i,redirectHost:i,port:n,path:r.pathname,fixedRedirectUrl:a}}s(ne,"loopbackSettings");var _=class extends Error{static{s(this,"OAuthError")}code;errorUri;constructor(e,t,r){super(t||e),this.name="OAuthError",this.code=e,this.errorUri=r}},ae=class extends Error{static{s(this,"OAuthIssuerMismatchError")}expected;received;constructor(e,t){let r=s(i=>i===void 0?"none":JSON.stringify(i),"format");super(`OAuth issuer mismatch: expected ${r(e)}, received ${r(t)}`),this.name="OAuthIssuerMismatchError",this.expected=e,this.received=t}},se=class extends Error{static{s(this,"OAuthInsecureEndpointError")}endpoint;constructor(e){super(`Refusing to send OAuth credentials to non-HTTPS endpoint ${e}`),this.name="OAuthInsecureEndpointError",this.endpoint=e}},st=class extends Error{static{s(this,"OAuthRegistrationError")}status;body;constructor(e,t){super(`OAuth dynamic client registration failed with status ${e}: ${t}`),this.name="OAuthRegistrationError",this.status=e,this.body=t}},v=class extends Error{static{s(this,"McpOAuthAuthorizationRequiredError")}constructor(){super("MCP OAuth authorization requires user interaction"),this.name="McpOAuthAuthorizationRequiredError"}},oe=class extends Error{static{s(this,"McpRefreshLockBusyError")}constructor(){super("Another process is refreshing the MCP server's tokens"),this.name="McpRefreshLockBusyError"}};function U(e,t){if(!W(e))throw new Error(`Invalid ${t}`);return e}s(U,"object");function S(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}s(S,"compact");function y(e,t){if(typeof e!="string"||e.length===0)throw new Error(`Invalid ${t}`);return e}s(y,"requiredString");function L(e){return e==null||e===""}s(L,"absent");function k(e,t){if(!L(e))return y(e,t)}s(k,"optionalString");function p(e,t){if(e!=null){if(!Array.isArray(e)||e.some(r=>typeof r!="string"))throw new Error(`Invalid ${t}`);return[...e]}}s(p,"optionalStrings");function m(e,t){let r=y(e,t);if(!URL.canParse(r)||!ce(new URL(r)))throw new Error(`Invalid ${t}`);return r}s(m,"safeUrl");function ce(e){return e.protocol==="http:"||e.protocol==="https:"}s(ce,"isHttpUrl");function ot(e,t){return L(e)?void 0:m(e,t)}s(ot,"optionalUrl");function ct(e){let t=U(e,"OAuth protected resource metadata");return S({...t,resource:m(t.resource,"OAuth protected resource metadata resource"),authorization_servers:p(t.authorization_servers,"authorization_servers")?.map(r=>m(r,"authorization server URL")),scopes_supported:p(t.scopes_supported,"scopes_supported")})}s(ct,"parseProtectedResourceMetadata");function le(e){let t=U(e,"authorization server metadata"),r=p(t.response_types_supported,"response_types_supported");if(!r)throw new Error("Invalid response_types_supported");return S({...t,issuer:m(t.issuer,"authorization server issuer"),authorization_endpoint:m(t.authorization_endpoint,"authorization endpoint"),token_endpoint:m(t.token_endpoint,"token endpoint"),registration_endpoint:ot(t.registration_endpoint,"registration endpoint"),scopes_supported:p(t.scopes_supported,"scopes_supported"),response_types_supported:r,grant_types_supported:p(t.grant_types_supported,"grant_types_supported"),token_endpoint_auth_methods_supported:p(t.token_endpoint_auth_methods_supported,"token_endpoint_auth_methods_supported"),code_challenge_methods_supported:p(t.code_challenge_methods_supported,"code_challenge_methods_supported"),client_id_metadata_document_supported:typeof t.client_id_metadata_document_supported=="boolean"?t.client_id_metadata_document_supported:void 0,authorization_response_iss_parameter_supported:typeof t.authorization_response_iss_parameter_supported=="boolean"?t.authorization_response_iss_parameter_supported:void 0})}s(le,"parseAuthorizationServerMetadata");function lt(e){let t=U(e,"OAuth token response"),r=L(t.expires_in)?void 0:Number(t.expires_in);if(r!==void 0&&!Number.isFinite(r))throw new Error("Invalid expires_in");return S({access_token:y(t.access_token,"access_token"),token_type:y(t.token_type,"token_type"),expires_in:r,scope:k(t.scope,"scope"),refresh_token:k(t.refresh_token,"refresh_token"),id_token:k(t.id_token,"id_token")})}s(lt,"parseOAuthTokens");function ht(e){let t=U(e,"OAuth client registration response");return S({...t,client_id:y(t.client_id,"client_id"),client_secret:k(t.client_secret,"client_secret"),client_id_issued_at:typeof t.client_id_issued_at=="number"?t.client_id_issued_at:void 0,client_secret_expires_at:typeof t.client_secret_expires_at=="number"?t.client_secret_expires_at:void 0,redirect_uris:p(t.redirect_uris,"redirect_uris")??[]})}s(ht,"parseClientInformation");function R(e){e?.body?.cancel().catch(()=>{})}s(R,"discard");function he(e){return e>=400&&e<500||e===502}s(he,"isDiscoveryMiss");function de(e){return e.endsWith("/")?e.slice(0,-1):e}s(de,"pathSuffix");function E(e,t){let r=e.match(new RegExp(String.raw`(?:^|[,\s])${t}=(?:"([^"]*)"|([^\s,]+))`,"i"));return r?.[1]||r?.[2]||void 0}s(E,"field");function dt(e){if(!e)return{};let t=e.trimStart().split(/\s+/,1)[0]?.toLowerCase();if(t!=="bearer"&&t!=="dpop")return{};let r=E(e,"resource_metadata"),i;if(r)try{i=new URL(r)}catch{}return{resourceMetadataUrl:i,scope:E(e,"scope"),error:E(e,"error"),errorDescription:E(e,"error_description")}}s(dt,"parseWwwAuthenticate");async function M(e,t,r,i){return t(e,{headers:{Accept:"application/json","MCP-Protocol-Version":r},signal:i})}s(M,"fetchMetadata");async function ut(e,t={}){let r=new URL(e),i=t.fetch??globalThis.fetch,n=t.protocolVersion??T,a=await M(t.resourceMetadataUrl?new URL(t.resourceMetadataUrl):new URL(`/.well-known/oauth-protected-resource${de(r.pathname)}`,r.origin),i,n,t.signal);if(!t.resourceMetadataUrl&&r.pathname!=="/"&&he(a.status)&&(R(a),a=await M(new URL("/.well-known/oauth-protected-resource",r.origin),i,n,t.signal)),!a.ok)throw R(a),new Error(`HTTP ${a.status} loading OAuth protected resource metadata`);return ct(await a.json())}s(ut,"discoverProtectedResourceMetadata");function ft(e){let t=new URL(e),r=de(t.pathname),i=[{url:new URL(`/.well-known/oauth-authorization-server${r}`,t.origin),type:"oauth"},{url:new URL(`/.well-known/openid-configuration${r}`,t.origin),type:"oidc"}];return r&&i.push({url:new URL(`${r}/.well-known/openid-configuration`,t.origin),type:"oidc"}),i}s(ft,"buildAuthorizationServerDiscoveryUrls");async function ue(e,t={}){let r=t.fetch??globalThis.fetch;for(let{url:i}of ft(e)){let n=await M(i,r,t.protocolVersion??T,t.signal);if(!n.ok){if(R(n),he(n.status))continue;throw new Error(`HTTP ${n.status} loading authorization server metadata from ${i}`)}let a=le(await n.json());if(!t.skipIssuerValidation){let o=String(e),c=s(l=>l.endsWith("/")?l.slice(0,-1):l,"trim");if(c(a.issuer)!==c(o))throw new ae(o,a.issuer)}return a}}s(ue,"discoverAuthorizationServerMetadata");async function pt(e,t={}){let r;try{r=await ut(e,{resourceMetadataUrl:t.resourceMetadataUrl,fetch:t.fetch,signal:t.signal})}catch(n){if(n instanceof TypeError)throw n}if(t.authorizationServerMetadataUrl){let n=t.authorizationServerMetadataUrl,a=await M(n,t.fetch??globalThis.fetch,T,t.signal);if(!a.ok)throw R(a),new Error(`HTTP ${a.status} loading authorization server metadata from ${n}`);let o=le(await a.json());return{authorizationServerUrl:o.issuer,authorizationServerMetadata:o,resourceMetadata:r}}let i=r?.authorization_servers?.[0]??String(new URL("/",e));return{authorizationServerUrl:i,authorizationServerMetadata:await ue(i,{fetch:t.fetch,skipIssuerValidation:t.skipIssuerValidation,signal:t.signal}),resourceMetadata:r}}s(pt,"discoverOAuthServerInfo");function wt(e){let t=new URL(e);return t.hash="",t}s(wt,"resourceUrlFromServerUrl");function gt(e,t){if(!t)return;let r=wt(e),i=new URL(t.resource);if(r.origin!==i.origin)throw new Error(`Protected resource ${t.resource} does not match MCP server ${r}`);let n=r.pathname.endsWith("/")?r.pathname:`${r.pathname}/`,a=i.pathname.endsWith("/")?i.pathname:`${i.pathname}/`;if(!n.startsWith(a))throw new Error(`Protected resource ${t.resource} does not match MCP server ${r}`);return t.resource}s(gt,"selectResource");function fe(e){return e==="localhost"||e==="127.0.0.1"||e==="[::1]"||e==="::1"}s(fe,"loopback");function mt(e){return e.some(t=>{if(!URL.canParse(t))return!1;let r=new URL(t);return r.protocol!=="http:"&&r.protocol!=="https:"||fe(r.hostname)})?"native":"web"}s(mt,"applicationType");function pe(e){let t=new URL(e);if(t.protocol!=="https:"&&!fe(t.hostname))throw new se(t.href);return t}s(pe,"secureEndpoint");function _t(e,t){let r="token_endpoint_auth_method"in e?e.token_endpoint_auth_method:void 0;return r&&["client_secret_basic","client_secret_post","none"].includes(r)&&(t.length===0||t.includes(r))?r:t.length===0?e.client_secret?"client_secret_basic":"none":e.client_secret&&t.includes("client_secret_basic")?"client_secret_basic":e.client_secret&&t.includes("client_secret_post")?"client_secret_post":t.includes("none")?"none":e.client_secret?"client_secret_post":"none"}s(_t,"selectClientAuthMethod");function vt(e,t,r,i){if(e==="client_secret_basic"){if(!t.client_secret)throw new Error("client_secret_basic requires a client secret");r.set("Authorization",`Basic ${Buffer.from(`${t.client_id}:${t.client_secret}`).toString("base64")}`)}else i.set("client_id",t.client_id),e==="client_secret_post"&&t.client_secret&&i.set("client_secret",t.client_secret)}s(vt,"applyClientAuthentication");async function yt(){let e=crypto.getRandomValues(new Uint8Array(32)),t=Buffer.from(e).toString("base64url"),r=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return{verifier:t,challenge:Buffer.from(r).toString("base64url")}}s(yt,"pkce");async function Ut(e,t){let r=t.metadata;if(r&&!r.response_types_supported.includes("code"))throw new Error("Authorization server does not support authorization codes");if(r?.code_challenge_methods_supported&&!r.code_challenge_methods_supported.includes("S256"))throw new Error("Authorization server does not support PKCE S256");let i=new URL(r?.authorization_endpoint??new URL("/authorize",e));if(!ce(i))throw new Error(`Invalid authorization endpoint ${i.href}`);let{verifier:n,challenge:a}=await yt();return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",t.clientInformation.client_id),i.searchParams.set("code_challenge",a),i.searchParams.set("code_challenge_method","S256"),i.searchParams.set("redirect_uri",String(t.redirectUrl)),t.state&&i.searchParams.set("state",t.state),t.scope&&i.searchParams.set("scope",t.scope),t.scope?.split(/\s+/).includes("offline_access")&&i.searchParams.set("prompt","consent"),t.resource&&i.searchParams.set("resource",t.resource),{authorizationUrl:i,codeVerifier:n}}s(Ut,"startAuthorization");async function we(e,t,r){let i=pe(t.metadata?.token_endpoint??new URL("/token",e)),n=new Headers({Accept:"application/json","content-type":"application/x-www-form-urlencoded"});t.resource&&r.set("resource",t.resource),t.addClientAuthentication?await t.addClientAuthentication(n,r,i,t.metadata):vt(_t(t.clientInformation,t.metadata?.token_endpoint_auth_methods_supported??[]),t.clientInformation,n,r);let a=await(t.fetch??globalThis.fetch)(i,{method:"POST",headers:n,body:r,signal:t.signal}),o=await a.text(),c;try{c=JSON.parse(o)}catch{}if(W(c)&&typeof c.error=="string")throw new _(c.error,typeof c.error_description=="string"?c.error_description:c.error,typeof c.error_uri=="string"?c.error_uri:void 0);if(!a.ok)throw new _("server_error",`HTTP ${a.status}: ${o}`);return lt(c)}s(we,"tokenRequest");async function St(e,t){let r=t.metadata?.registration_endpoint;if(t.metadata&&!r)throw new Error("Authorization server does not support dynamic client registration");let i=await(t.fetch??globalThis.fetch)(new URL(r??new URL("/register",e)),{method:"POST",headers:{Accept:"application/json","content-type":"application/json"},body:JSON.stringify({...t.clientMetadata,application_type:t.clientMetadata.application_type??mt(t.clientMetadata.redirect_uris),...t.scope?{scope:t.scope}:{}}),signal:t.signal});if(!i.ok)throw new st(i.status,await i.text());return ht(await i.json())}s(St,"registerClient");async function kt(e,t){return we(e,t,new URLSearchParams({grant_type:"authorization_code",code:t.code,code_verifier:t.codeVerifier,redirect_uri:String(t.redirectUrl)}))}s(kt,"exchangeAuthorizationCode");async function Rt(e,t){let r=await we(e,t,new URLSearchParams({grant_type:"refresh_token",refresh_token:t.refreshToken}));return{refresh_token:t.refreshToken,...r}}s(Rt,"refreshAuthorization");function ge(e,t){return e.scope===void 0&&t?{...e,scope:t}:e}s(ge,"withScope");function Et(e,t){if(!t)return;let r=[e,t].flatMap(i=>i?.split(/\s+/).filter(Boolean)??[]);return[...new Set(r)].join(" ")}s(Et,"stepUpScope");async function x(e,t,r={}){let i=t.authorizationServerMetadataUrl&&pe(t.authorizationServerMetadataUrl),n=i?void 0:await e.discoveryState?.(),a=n?.authorizationServerUrl?{authorizationServerUrl:n.authorizationServerUrl,authorizationServerMetadata:n.authorizationServerMetadata??await ue(n.authorizationServerUrl,{fetch:t.fetch,skipIssuerValidation:t.skipIssuerValidation,signal:t.signal}),resourceMetadata:n.resourceMetadata}:await pt(t.serverUrl,{resourceMetadataUrl:t.resourceMetadataUrl,authorizationServerMetadataUrl:i,fetch:t.fetch,skipIssuerValidation:t.skipIssuerValidation,signal:t.signal});i||await e.saveDiscoveryState?.({...a,...t.resourceMetadataUrl?{resourceMetadataUrl:t.resourceMetadataUrl.href}:{}});let o=a.authorizationServerMetadata,c=gt(t.serverUrl,a.resourceMetadata),l=t.scope||a.resourceMetadata?.scopes_supported?.join(" ")||e.clientMetadata.scope,h=await e.clientInformation();r.storedClientId=h?.client_id;let d=h?void 0:e.clientMetadataDocument?.(o);if(d){let u=new URL(d.url);if(u.protocol!=="https:"||u.pathname==="/")throw new Error("Invalid OAuth client metadata URL")}let f=d?.redirectUrl??String(e.redirectUrl);if(t.authorizationCode&&t.authorizationRedirectUrl!==void 0&&f!==t.authorizationRedirectUrl)throw new Error(`The code exchange would use the redirect URI ${f}, but the authorization request used ${t.authorizationRedirectUrl}`);let w=h??(d&&{client_id:d.url});if(!w){if(t.refreshOnly)return"REDIRECT";if(t.authorizationCode)throw new Error("OAuth client information is missing during code exchange: the authorization request's client was removed, or the client settings changed");if(!e.saveClientInformation)throw new Error("OAuth client information cannot be persisted");w=await St(a.authorizationServerUrl,{metadata:o,clientMetadata:e.clientMetadata,scope:l,fetch:t.fetch,signal:t.signal}),await e.saveClientInformation(w)}let B={metadata:o,clientInformation:w,resource:c,addClientAuthentication:e.addClientAuthentication,fetch:t.fetch,signal:t.signal};if(t.authorizationCode){let u=t.iss;if((u!==void 0||o?.authorization_response_iss_parameter_supported)&&u!==o?.issuer)throw new ae(o?.issuer,u);let Ie=await kt(a.authorizationServerUrl,{...B,code:t.authorizationCode,codeVerifier:await e.codeVerifier(),redirectUrl:f});return await e.saveTokens(ge(Ie,l)),"AUTHORIZED"}let b=t.skipRefresh?void 0:await e.tokens();if(b?.refresh_token)try{let u=await Rt(a.authorizationServerUrl,{...B,refreshToken:b.refresh_token});return await e.saveTokens(ge(u,b.scope)),"AUTHORIZED"}catch(u){if(t.signal?.aborted||u instanceof se||u instanceof _&&u.code!=="server_error")throw u}if(t.refreshOnly)return"REDIRECT";let Pe=await e.state?.(),q=await Ut(a.authorizationServerUrl,{metadata:o,clientInformation:w,redirectUrl:f,scope:l,state:Pe,resource:c});return await e.saveCodeVerifier(q.codeVerifier),await e.redirectToAuthorization(q.authorizationUrl),"REDIRECT"}s(x,"runFlow");async function $(e,t){let r={};try{return await x(e,t,r)}catch(i){if(i instanceof _&&["invalid_client","unauthorized_client"].includes(i.code)){if(t.refreshOnly){if((await e.clientInformation())?.client_id===r.storedClientId)for(let n of["client","tokens","discovery"])await e.invalidateCredentials?.(n)}else await e.invalidateCredentials?.("all");return x(e,t)}if(i instanceof _&&i.code==="invalid_grant")return await e.invalidateCredentials?.("tokens"),x(e,t);throw i}}s($,"authorizeMcp");var Mt=3e4;function At(e){let{store:t,redirectUrl:r}=e,i,n=s((a,o=globalThis.fetch,c)=>(i??=t.withRefreshLock(async()=>{let l=await t.load();if(l?.tokens?.access_token!==a)return;if(!l?.tokens?.refresh_token)throw new v;let h={...e,settings:e.settings()};if(await me(h,l,{fetch:o,challenge:c,redirectUrl:r})==="REDIRECT")throw new v}).finally(()=>{i=void 0}),i),"refresh");return{token:s(async()=>{await i?.catch(()=>{});let a=await t.load(),o=a?.tokens?.access_token;return!(a?.tokensExpireAt!==void 0&&a.tokensExpireAt-Mt<=Date.now())||!a?.tokens?.refresh_token?o:(await n(o).catch(()=>{}),(await t.load())?.tokens?.access_token)},"token"),onUnauthorized:s(async a=>{let o=dt(a.response.headers.get("www-authenticate"));if(e.onChallenge(o),o.error==="insufficient_scope")throw new v;await n(a.token,a.fetch,o)},"onUnauthorized"),settled:s(async()=>{await i?.catch(()=>{})},"settled")}}s(At,"createMcpAuthProvider");async function me(e,t,r={}){let i=[r.redirectUrl,ne(e.settings).fixedRedirectUrl,O(t.clientInformation)[0]].filter(n=>n!==void 0).find(n=>e.clientMetadataDocuments?.listsRedirectUrl(n))??ie;return $(P(e,i),{serverUrl:e.serverUrl,resourceMetadataUrl:r.challenge?.resourceMetadataUrl,authorizationServerMetadataUrl:e.settings.authServerMetadataUrl,fetch:te(r.fetch),refreshOnly:!0})}s(me,"refreshStoredTokens");import{createServer as Ct}from"node:http";function bt(e){return e.ok?"Authorization complete. You may close this window.":e.details?`${e.message}
1
+ var Oe=Object.defineProperty;var s=(e,t)=>Oe(e,"name",{value:t,configurable:!0});import{createRequire as Le}from"node:module";const fr=Le(import.meta.url);import{FileAuthStorageBackend as xe,JSON_RPC_ERROR_CODES as $e,LATEST_PROTOCOL_VERSION as T,McpAuthRequiredError as De,McpClient as He,McpError as Ne,McpHttpError as K,McpSessionExpiredError as Fe,StdioTransport as z,StreamableHttpTransport as Ve,isClientMetadataDocumentCallback as je,isObject as W,mcpNamespace as Be,require_proper_lockfile as qe,resolveConfigValueOrThrow as J,resolveHeadersOrThrow as Ke}from"./chunk-C5ELI234.js";import{sliceTail as Y}from"./chunk-HF334NQU.js";import{APP_NAME as Z,VERSION as We,getAgentDir as G}from"./chunk-R47JBGS3.js";import{__toESM as Je}from"./chunk-JXWJOIH4.js";import{homedir as Q}from"node:os";import{basename as Ye,join as Ze,resolve as Ge}from"node:path";import{setTimeout as Qe}from"node:timers/promises";import{pathToFileURL as Xe}from"node:url";import{createHash as et}from"node:crypto";var tt=class{static{s(this,"MemoryOAuthStateStore")}value;load(){return this.value===void 0?void 0:structuredClone(this.value)}save(e){this.value=structuredClone(e)}},rt=class{static{s(this,"McpOAuthProvider")}redirectUrl;clientMetadata;clientMetadataDocument;serverUrl;configuredClient;store;onRedirect;writes=Promise.resolve();constructor(e){this.serverUrl=String(new URL(e.serverUrl)),this.redirectUrl=String(e.redirectUrl),this.clientMetadata={...e.clientMetadata,redirect_uris:e.clientMetadata.redirect_uris??[this.redirectUrl],grant_types:e.clientMetadata.grant_types??["authorization_code","refresh_token"],response_types:e.clientMetadata.response_types??["code"],token_endpoint_auth_method:e.clientMetadata.token_endpoint_auth_method??(e.clientSecret?"client_secret_post":"none")},this.clientMetadataDocument=e.clientMetadataDocument,this.configuredClient=e.clientId?{client_id:e.clientId,...e.clientSecret?{client_secret:e.clientSecret}:{}}:void 0,this.store=e.store??new tt,this.onRedirect=e.onRedirect}async state(){let e=(await this.load()).oauthState;if(e)return e;let t=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex");return await this.update(r=>({...r,oauthState:t})),t}async clientInformation(){return this.configuredClient??(await this.load()).clientInformation}async saveClientInformation(e){this.configuredClient||await this.update(t=>({...t,clientInformation:e}))}async tokens(){return(await this.load()).tokens}async saveTokens(e){let t=e.expires_in===void 0?void 0:Date.now()+e.expires_in*1e3;await this.update(r=>{let i={...r,tokens:e};return t===void 0?delete i.tokensExpireAt:i.tokensExpireAt=t,i})}async redirectToAuthorization(e){await this.onRedirect(e)}async saveCodeVerifier(e){await this.update(t=>({...t,codeVerifier:e}))}async codeVerifier(){let e=(await this.load()).codeVerifier;if(!e)throw new Error("No OAuth PKCE code verifier is stored");return e}async invalidateCredentials(e){await this.update(t=>{let r={...t};return(e==="all"||e==="client")&&delete r.clientInformation,(e==="all"||e==="tokens")&&(delete r.tokens,delete r.tokensExpireAt),(e==="all"||e==="verifier")&&delete r.codeVerifier,(e==="all"||e==="discovery")&&delete r.discovery,e==="all"&&delete r.oauthState,r})}async saveDiscoveryState(e){await this.update(t=>({...t,discovery:e}))}async discoveryState(){return(await this.load()).discovery}async load(){return await this.writes,this.own(await this.store.load())}async update(e){this.writes=this.writes.then(async()=>{await this.store.save(e(this.own(await this.store.load())))}),await this.writes}own(e){return e?.serverUrl===this.serverUrl?e:{serverUrl:this.serverUrl}}};function P(e,t,r=()=>{}){let{serverUrl:i,settings:n,clientMetadataDocuments:a}=e;return new rt({serverUrl:i,redirectUrl:t,clientMetadata:{client_name:n.clientName??e.clientName},clientMetadataDocument:I(n,a,t)?o=>{if(!a?.listsRedirectUrl(t))throw new Error(`oauth.clientRegistration "cimd" needs Client ID Metadata Documents that list the redirect URI ${t}`);let c=it(i,t,o,a.baseUrl);if(!c&&n.clientRegistration==="cimd")throw new Error('The authorization server does not support Client ID Metadata Documents for public clients; remove oauth.clientRegistration "cimd"');return c}:void 0,clientId:n.clientId,clientSecret:n.clientSecret,store:e.store,onRedirect:r})}s(P,"createOAuthClientProvider");function I(e,t,r){let i=e.clientRegistration??"auto";return i!=="auto"?i==="cimd":!e.clientId&&!e.clientName&&t?.listsRedirectUrl(r)===!0}s(I,"offersClientMetadataDocument");function it(e,t,r,i){if(!r?.client_id_metadata_document_supported||!r.token_endpoint_auth_methods_supported?.includes("none"))return;if(r.authorization_response_iss_parameter_supported)return{url:`${i}/client.json`,redirectUrl:t};let n=new URL(t);return n.pathname=X(n.pathname,e),{url:`${i}/${ee(e)}/client.json`,redirectUrl:n.href}}s(it,"clientMetadataDocument");function X(e,t){return`${e.replace(/\/$/,"")}/${ee(t)}`}s(X,"serverSpecificPath");function ee(e){let t=new URL(e);return t.hash="",et("sha256").update(t.href).digest().subarray(0,9).toString("base64url")}s(ee,"callbackId");function O(e){return e&&"redirect_uris"in e?e.redirect_uris:[]}s(O,"registeredRedirectUrls");var nt=15e3;function te(e=globalThis.fetch){return(t,r)=>{let i=AbortSignal.timeout(nt);return e(t,{...r,signal:r?.signal?AbortSignal.any([r.signal,i]):i})}}s(te,"timedFetch");var re="127.0.0.1",at="/callback",ie=`http://${re}${at}`;function ne(e){let t=e.callbackUrl??ie,r=new URL(t),i=r.hostname.replace(/^\[|\]$/g,""),n=r.port?Number(r.port):e.callbackPort,a;return r.port?a=e.callbackUrl:n!==void 0&&(r.port=String(n),a=r.href),{url:t,host:i==="localhost"?re:i,redirectHost:i,port:n,path:r.pathname,fixedRedirectUrl:a}}s(ne,"loopbackSettings");var _=class extends Error{static{s(this,"OAuthError")}code;errorUri;constructor(e,t,r){super(t||e),this.name="OAuthError",this.code=e,this.errorUri=r}},ae=class extends Error{static{s(this,"OAuthIssuerMismatchError")}expected;received;constructor(e,t){let r=s(i=>i===void 0?"none":JSON.stringify(i),"format");super(`OAuth issuer mismatch: expected ${r(e)}, received ${r(t)}`),this.name="OAuthIssuerMismatchError",this.expected=e,this.received=t}},se=class extends Error{static{s(this,"OAuthInsecureEndpointError")}endpoint;constructor(e){super(`Refusing to send OAuth credentials to non-HTTPS endpoint ${e}`),this.name="OAuthInsecureEndpointError",this.endpoint=e}},st=class extends Error{static{s(this,"OAuthRegistrationError")}status;body;constructor(e,t){super(`OAuth dynamic client registration failed with status ${e}: ${t}`),this.name="OAuthRegistrationError",this.status=e,this.body=t}},v=class extends Error{static{s(this,"McpOAuthAuthorizationRequiredError")}constructor(){super("MCP OAuth authorization requires user interaction"),this.name="McpOAuthAuthorizationRequiredError"}},oe=class extends Error{static{s(this,"McpRefreshLockBusyError")}constructor(){super("Another process is refreshing the MCP server's tokens"),this.name="McpRefreshLockBusyError"}};function U(e,t){if(!W(e))throw new Error(`Invalid ${t}`);return e}s(U,"object");function S(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}s(S,"compact");function y(e,t){if(typeof e!="string"||e.length===0)throw new Error(`Invalid ${t}`);return e}s(y,"requiredString");function L(e){return e==null||e===""}s(L,"absent");function k(e,t){if(!L(e))return y(e,t)}s(k,"optionalString");function p(e,t){if(e!=null){if(!Array.isArray(e)||e.some(r=>typeof r!="string"))throw new Error(`Invalid ${t}`);return[...e]}}s(p,"optionalStrings");function m(e,t){let r=y(e,t);if(!URL.canParse(r)||!ce(new URL(r)))throw new Error(`Invalid ${t}`);return r}s(m,"safeUrl");function ce(e){return e.protocol==="http:"||e.protocol==="https:"}s(ce,"isHttpUrl");function ot(e,t){return L(e)?void 0:m(e,t)}s(ot,"optionalUrl");function ct(e){let t=U(e,"OAuth protected resource metadata");return S({...t,resource:m(t.resource,"OAuth protected resource metadata resource"),authorization_servers:p(t.authorization_servers,"authorization_servers")?.map(r=>m(r,"authorization server URL")),scopes_supported:p(t.scopes_supported,"scopes_supported")})}s(ct,"parseProtectedResourceMetadata");function le(e){let t=U(e,"authorization server metadata"),r=p(t.response_types_supported,"response_types_supported");if(!r)throw new Error("Invalid response_types_supported");return S({...t,issuer:m(t.issuer,"authorization server issuer"),authorization_endpoint:m(t.authorization_endpoint,"authorization endpoint"),token_endpoint:m(t.token_endpoint,"token endpoint"),registration_endpoint:ot(t.registration_endpoint,"registration endpoint"),scopes_supported:p(t.scopes_supported,"scopes_supported"),response_types_supported:r,grant_types_supported:p(t.grant_types_supported,"grant_types_supported"),token_endpoint_auth_methods_supported:p(t.token_endpoint_auth_methods_supported,"token_endpoint_auth_methods_supported"),code_challenge_methods_supported:p(t.code_challenge_methods_supported,"code_challenge_methods_supported"),client_id_metadata_document_supported:typeof t.client_id_metadata_document_supported=="boolean"?t.client_id_metadata_document_supported:void 0,authorization_response_iss_parameter_supported:typeof t.authorization_response_iss_parameter_supported=="boolean"?t.authorization_response_iss_parameter_supported:void 0})}s(le,"parseAuthorizationServerMetadata");function lt(e){let t=U(e,"OAuth token response"),r=L(t.expires_in)?void 0:Number(t.expires_in);if(r!==void 0&&!Number.isFinite(r))throw new Error("Invalid expires_in");return S({access_token:y(t.access_token,"access_token"),token_type:y(t.token_type,"token_type"),expires_in:r,scope:k(t.scope,"scope"),refresh_token:k(t.refresh_token,"refresh_token"),id_token:k(t.id_token,"id_token")})}s(lt,"parseOAuthTokens");function ht(e){let t=U(e,"OAuth client registration response");return S({...t,client_id:y(t.client_id,"client_id"),client_secret:k(t.client_secret,"client_secret"),client_id_issued_at:typeof t.client_id_issued_at=="number"?t.client_id_issued_at:void 0,client_secret_expires_at:typeof t.client_secret_expires_at=="number"?t.client_secret_expires_at:void 0,redirect_uris:p(t.redirect_uris,"redirect_uris")??[]})}s(ht,"parseClientInformation");function R(e){e?.body?.cancel().catch(()=>{})}s(R,"discard");function he(e){return e>=400&&e<500||e===502}s(he,"isDiscoveryMiss");function de(e){return e.endsWith("/")?e.slice(0,-1):e}s(de,"pathSuffix");function E(e,t){let r=e.match(new RegExp(String.raw`(?:^|[,\s])${t}=(?:"([^"]*)"|([^\s,]+))`,"i"));return r?.[1]||r?.[2]||void 0}s(E,"field");function dt(e){if(!e)return{};let t=e.trimStart().split(/\s+/,1)[0]?.toLowerCase();if(t!=="bearer"&&t!=="dpop")return{};let r=E(e,"resource_metadata"),i;if(r)try{i=new URL(r)}catch{}return{resourceMetadataUrl:i,scope:E(e,"scope"),error:E(e,"error"),errorDescription:E(e,"error_description")}}s(dt,"parseWwwAuthenticate");async function M(e,t,r,i){return t(e,{headers:{Accept:"application/json","MCP-Protocol-Version":r},signal:i})}s(M,"fetchMetadata");async function ut(e,t={}){let r=new URL(e),i=t.fetch??globalThis.fetch,n=t.protocolVersion??T,a=await M(t.resourceMetadataUrl?new URL(t.resourceMetadataUrl):new URL(`/.well-known/oauth-protected-resource${de(r.pathname)}`,r.origin),i,n,t.signal);if(!t.resourceMetadataUrl&&r.pathname!=="/"&&he(a.status)&&(R(a),a=await M(new URL("/.well-known/oauth-protected-resource",r.origin),i,n,t.signal)),!a.ok)throw R(a),new Error(`HTTP ${a.status} loading OAuth protected resource metadata`);return ct(await a.json())}s(ut,"discoverProtectedResourceMetadata");function ft(e){let t=new URL(e),r=de(t.pathname),i=[{url:new URL(`/.well-known/oauth-authorization-server${r}`,t.origin),type:"oauth"},{url:new URL(`/.well-known/openid-configuration${r}`,t.origin),type:"oidc"}];return r&&i.push({url:new URL(`${r}/.well-known/openid-configuration`,t.origin),type:"oidc"}),i}s(ft,"buildAuthorizationServerDiscoveryUrls");async function ue(e,t={}){let r=t.fetch??globalThis.fetch;for(let{url:i}of ft(e)){let n=await M(i,r,t.protocolVersion??T,t.signal);if(!n.ok){if(R(n),he(n.status))continue;throw new Error(`HTTP ${n.status} loading authorization server metadata from ${i}`)}let a=le(await n.json());if(!t.skipIssuerValidation){let o=String(e),c=s(l=>l.endsWith("/")?l.slice(0,-1):l,"trim");if(c(a.issuer)!==c(o))throw new ae(o,a.issuer)}return a}}s(ue,"discoverAuthorizationServerMetadata");async function pt(e,t={}){let r;try{r=await ut(e,{resourceMetadataUrl:t.resourceMetadataUrl,fetch:t.fetch,signal:t.signal})}catch(n){if(n instanceof TypeError)throw n}if(t.authorizationServerMetadataUrl){let n=t.authorizationServerMetadataUrl,a=await M(n,t.fetch??globalThis.fetch,T,t.signal);if(!a.ok)throw R(a),new Error(`HTTP ${a.status} loading authorization server metadata from ${n}`);let o=le(await a.json());return{authorizationServerUrl:o.issuer,authorizationServerMetadata:o,resourceMetadata:r}}let i=r?.authorization_servers?.[0]??String(new URL("/",e));return{authorizationServerUrl:i,authorizationServerMetadata:await ue(i,{fetch:t.fetch,skipIssuerValidation:t.skipIssuerValidation,signal:t.signal}),resourceMetadata:r}}s(pt,"discoverOAuthServerInfo");function wt(e){let t=new URL(e);return t.hash="",t}s(wt,"resourceUrlFromServerUrl");function gt(e,t){if(!t)return;let r=wt(e),i=new URL(t.resource);if(r.origin!==i.origin)throw new Error(`Protected resource ${t.resource} does not match MCP server ${r}`);let n=r.pathname.endsWith("/")?r.pathname:`${r.pathname}/`,a=i.pathname.endsWith("/")?i.pathname:`${i.pathname}/`;if(!n.startsWith(a))throw new Error(`Protected resource ${t.resource} does not match MCP server ${r}`);return t.resource}s(gt,"selectResource");function fe(e){return e==="localhost"||e==="127.0.0.1"||e==="[::1]"||e==="::1"}s(fe,"loopback");function mt(e){return e.some(t=>{if(!URL.canParse(t))return!1;let r=new URL(t);return r.protocol!=="http:"&&r.protocol!=="https:"||fe(r.hostname)})?"native":"web"}s(mt,"applicationType");function pe(e){let t=new URL(e);if(t.protocol!=="https:"&&!fe(t.hostname))throw new se(t.href);return t}s(pe,"secureEndpoint");function _t(e,t){let r="token_endpoint_auth_method"in e?e.token_endpoint_auth_method:void 0;return r&&["client_secret_basic","client_secret_post","none"].includes(r)&&(t.length===0||t.includes(r))?r:t.length===0?e.client_secret?"client_secret_basic":"none":e.client_secret&&t.includes("client_secret_basic")?"client_secret_basic":e.client_secret&&t.includes("client_secret_post")?"client_secret_post":t.includes("none")?"none":e.client_secret?"client_secret_post":"none"}s(_t,"selectClientAuthMethod");function vt(e,t,r,i){if(e==="client_secret_basic"){if(!t.client_secret)throw new Error("client_secret_basic requires a client secret");r.set("Authorization",`Basic ${Buffer.from(`${t.client_id}:${t.client_secret}`).toString("base64")}`)}else i.set("client_id",t.client_id),e==="client_secret_post"&&t.client_secret&&i.set("client_secret",t.client_secret)}s(vt,"applyClientAuthentication");async function yt(){let e=crypto.getRandomValues(new Uint8Array(32)),t=Buffer.from(e).toString("base64url"),r=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return{verifier:t,challenge:Buffer.from(r).toString("base64url")}}s(yt,"pkce");async function Ut(e,t){let r=t.metadata;if(r&&!r.response_types_supported.includes("code"))throw new Error("Authorization server does not support authorization codes");if(r?.code_challenge_methods_supported&&!r.code_challenge_methods_supported.includes("S256"))throw new Error("Authorization server does not support PKCE S256");let i=new URL(r?.authorization_endpoint??new URL("/authorize",e));if(!ce(i))throw new Error(`Invalid authorization endpoint ${i.href}`);let{verifier:n,challenge:a}=await yt();return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",t.clientInformation.client_id),i.searchParams.set("code_challenge",a),i.searchParams.set("code_challenge_method","S256"),i.searchParams.set("redirect_uri",String(t.redirectUrl)),t.state&&i.searchParams.set("state",t.state),t.scope&&i.searchParams.set("scope",t.scope),t.scope?.split(/\s+/).includes("offline_access")&&i.searchParams.set("prompt","consent"),t.resource&&i.searchParams.set("resource",t.resource),{authorizationUrl:i,codeVerifier:n}}s(Ut,"startAuthorization");async function we(e,t,r){let i=pe(t.metadata?.token_endpoint??new URL("/token",e)),n=new Headers({Accept:"application/json","content-type":"application/x-www-form-urlencoded"});t.resource&&r.set("resource",t.resource),t.addClientAuthentication?await t.addClientAuthentication(n,r,i,t.metadata):vt(_t(t.clientInformation,t.metadata?.token_endpoint_auth_methods_supported??[]),t.clientInformation,n,r);let a=await(t.fetch??globalThis.fetch)(i,{method:"POST",headers:n,body:r,signal:t.signal}),o=await a.text(),c;try{c=JSON.parse(o)}catch{}if(W(c)&&typeof c.error=="string")throw new _(c.error,typeof c.error_description=="string"?c.error_description:c.error,typeof c.error_uri=="string"?c.error_uri:void 0);if(!a.ok)throw new _("server_error",`HTTP ${a.status}: ${o}`);return lt(c)}s(we,"tokenRequest");async function St(e,t){let r=t.metadata?.registration_endpoint;if(t.metadata&&!r)throw new Error("Authorization server does not support dynamic client registration");let i=await(t.fetch??globalThis.fetch)(new URL(r??new URL("/register",e)),{method:"POST",headers:{Accept:"application/json","content-type":"application/json"},body:JSON.stringify({...t.clientMetadata,application_type:t.clientMetadata.application_type??mt(t.clientMetadata.redirect_uris),...t.scope?{scope:t.scope}:{}}),signal:t.signal});if(!i.ok)throw new st(i.status,await i.text());return ht(await i.json())}s(St,"registerClient");async function kt(e,t){return we(e,t,new URLSearchParams({grant_type:"authorization_code",code:t.code,code_verifier:t.codeVerifier,redirect_uri:String(t.redirectUrl)}))}s(kt,"exchangeAuthorizationCode");async function Rt(e,t){let r=await we(e,t,new URLSearchParams({grant_type:"refresh_token",refresh_token:t.refreshToken}));return{refresh_token:t.refreshToken,...r}}s(Rt,"refreshAuthorization");function ge(e,t){return e.scope===void 0&&t?{...e,scope:t}:e}s(ge,"withScope");function Et(e,t){if(!t)return;let r=[e,t].flatMap(i=>i?.split(/\s+/).filter(Boolean)??[]);return[...new Set(r)].join(" ")}s(Et,"stepUpScope");async function x(e,t,r={}){let i=t.authorizationServerMetadataUrl&&pe(t.authorizationServerMetadataUrl),n=i?void 0:await e.discoveryState?.(),a=n?.authorizationServerUrl?{authorizationServerUrl:n.authorizationServerUrl,authorizationServerMetadata:n.authorizationServerMetadata??await ue(n.authorizationServerUrl,{fetch:t.fetch,skipIssuerValidation:t.skipIssuerValidation,signal:t.signal}),resourceMetadata:n.resourceMetadata}:await pt(t.serverUrl,{resourceMetadataUrl:t.resourceMetadataUrl,authorizationServerMetadataUrl:i,fetch:t.fetch,skipIssuerValidation:t.skipIssuerValidation,signal:t.signal});i||await e.saveDiscoveryState?.({...a,...t.resourceMetadataUrl?{resourceMetadataUrl:t.resourceMetadataUrl.href}:{}});let o=a.authorizationServerMetadata,c=gt(t.serverUrl,a.resourceMetadata),l=t.scope||a.resourceMetadata?.scopes_supported?.join(" ")||e.clientMetadata.scope,h=await e.clientInformation();r.storedClientId=h?.client_id;let d=h?void 0:e.clientMetadataDocument?.(o);if(d){let u=new URL(d.url);if(u.protocol!=="https:"||u.pathname==="/")throw new Error("Invalid OAuth client metadata URL")}let f=d?.redirectUrl??String(e.redirectUrl);if(t.authorizationCode&&t.authorizationRedirectUrl!==void 0&&f!==t.authorizationRedirectUrl)throw new Error(`The code exchange would use the redirect URI ${f}, but the authorization request used ${t.authorizationRedirectUrl}`);let w=h??(d&&{client_id:d.url});if(!w){if(t.refreshOnly)return"REDIRECT";if(t.authorizationCode)throw new Error("OAuth client information is missing during code exchange: the authorization request's client was removed, or the client settings changed");if(!e.saveClientInformation)throw new Error("OAuth client information cannot be persisted");w=await St(a.authorizationServerUrl,{metadata:o,clientMetadata:e.clientMetadata,scope:l,fetch:t.fetch,signal:t.signal}),await e.saveClientInformation(w)}let B={metadata:o,clientInformation:w,resource:c,addClientAuthentication:e.addClientAuthentication,fetch:t.fetch,signal:t.signal};if(t.authorizationCode){let u=t.iss;if((u!==void 0||o?.authorization_response_iss_parameter_supported)&&u!==o?.issuer)throw new ae(o?.issuer,u);let Ie=await kt(a.authorizationServerUrl,{...B,code:t.authorizationCode,codeVerifier:await e.codeVerifier(),redirectUrl:f});return await e.saveTokens(ge(Ie,l)),"AUTHORIZED"}let b=t.skipRefresh?void 0:await e.tokens();if(b?.refresh_token)try{let u=await Rt(a.authorizationServerUrl,{...B,refreshToken:b.refresh_token});return await e.saveTokens(ge(u,b.scope)),"AUTHORIZED"}catch(u){if(t.signal?.aborted||u instanceof se||u instanceof _&&u.code!=="server_error")throw u}if(t.refreshOnly)return"REDIRECT";let Pe=await e.state?.(),q=await Ut(a.authorizationServerUrl,{metadata:o,clientInformation:w,redirectUrl:f,scope:l,state:Pe,resource:c});return await e.saveCodeVerifier(q.codeVerifier),await e.redirectToAuthorization(q.authorizationUrl),"REDIRECT"}s(x,"runFlow");async function $(e,t){let r={};try{return await x(e,t,r)}catch(i){if(i instanceof _&&["invalid_client","unauthorized_client"].includes(i.code)){if(t.refreshOnly){if((await e.clientInformation())?.client_id===r.storedClientId)for(let n of["client","tokens","discovery"])await e.invalidateCredentials?.(n)}else await e.invalidateCredentials?.("all");return x(e,t)}if(i instanceof _&&i.code==="invalid_grant")return await e.invalidateCredentials?.("tokens"),x(e,t);throw i}}s($,"authorizeMcp");var Mt=3e4;function At(e){let{store:t,redirectUrl:r}=e,i,n=s((a,o=globalThis.fetch,c)=>(i??=t.withRefreshLock(async()=>{let l=await t.load();if(l?.tokens?.access_token!==a)return;if(!l?.tokens?.refresh_token)throw new v;let h={...e,settings:e.settings()};if(await me(h,l,{fetch:o,challenge:c,redirectUrl:r})==="REDIRECT")throw new v}).finally(()=>{i=void 0}),i),"refresh");return{token:s(async()=>{await i?.catch(()=>{});let a=await t.load(),o=a?.tokens?.access_token;return!(a?.tokensExpireAt!==void 0&&a.tokensExpireAt-Mt<=Date.now())||!a?.tokens?.refresh_token?o:(await n(o).catch(()=>{}),(await t.load())?.tokens?.access_token)},"token"),onUnauthorized:s(async a=>{let o=dt(a.response.headers.get("www-authenticate"));if(e.onChallenge(o),o.error==="insufficient_scope")throw new v;await n(a.token,a.fetch,o)},"onUnauthorized"),settled:s(async()=>{await i?.catch(()=>{})},"settled")}}s(At,"createMcpAuthProvider");async function me(e,t,r={}){let i=[r.redirectUrl,ne(e.settings).fixedRedirectUrl,O(t.clientInformation)[0]].filter(n=>n!==void 0).find(n=>e.clientMetadataDocuments?.listsRedirectUrl(n))??ie;return $(P(e,i),{serverUrl:e.serverUrl,resourceMetadataUrl:r.challenge?.resourceMetadataUrl,authorizationServerMetadataUrl:e.settings.authServerMetadataUrl,fetch:te(r.fetch),refreshOnly:!0})}s(me,"refreshStoredTokens");import{createServer as Ct}from"node:http";function bt(e){return e.ok?"Authorization complete. You may close this window.":e.details?`${e.message}
2
2
 
3
3
  ${e.details}`:e.message}s(bt,"plainText");var _e=class ze{static{s(this,"_OAuthCallbackServer")}redirectUrl;server;paths;timeoutMs;renderPage;pending=new Map;constructor(t,r,i,n,a){this.server=t,this.redirectUrl=r,this.paths=i,this.timeoutMs=n,this.renderPage=a}static async listen(t={}){let r=t.host??"127.0.0.1",i=t.redirectHost??r,n=t.path??"/callback",a,o=Ct((l,h)=>a?.handle(l.url??"/",h));await new Promise((l,h)=>{o.once("error",h),o.listen(t.port??0,r,()=>{o.off("error",h),l()})});let c=o.address();if(!c||typeof c=="string")throw new Error("OAuth callback server did not bind to TCP");return a=new ze(o,`http://${i.includes(":")?`[${i}]`:i}:${c.port}${n}`,[n,...t.extraPaths??[]],t.timeoutMs??5*6e4,t.renderPage),a}waitForCallback(t,r){if(this.pending.has(t))throw new Error("OAuth state is already pending");return new Promise((i,n)=>{let a=setTimeout(()=>{this.pending.delete(t),n(new Error("OAuth callback timed out"))},this.timeoutMs);this.pending.set(t,{resolve:i,reject:n,timer:a,path:r})})}async close(){for(let r of this.pending.values())clearTimeout(r.timer),r.reject(new Error("OAuth callback server closed"));this.pending.clear();let t=new Promise((r,i)=>{this.server.close(n=>n?i(n):r())});this.server.closeAllConnections(),await t}reply(t,r,i){this.renderPage?(t.writeHead(r,{"content-type":"text/html; charset=utf-8","cache-control":"no-store"}),t.end(this.renderPage(i))):t.writeHead(r,{"content-type":"text/plain; charset=utf-8"}).end(bt(i))}handle(t,r){let i=new URL(t,this.redirectUrl);if(!this.paths.includes(i.pathname)){this.reply(r,404,{ok:!1,message:"Not found"});return}let n=i.searchParams.get("state"),a=n?this.pending.get(n):void 0;if(!n||!a){this.reply(r,400,{ok:!1,message:"Invalid or expired OAuth state"});return}if(clearTimeout(a.timer),this.pending.delete(n),a.path!==void 0&&i.pathname!==a.path){a.reject(new Error("The authorization response arrived on another redirect URI")),this.reply(r,400,{ok:!1,message:"Unexpected redirect URI"});return}let o=i.searchParams.get("error");if(o){let h=i.searchParams.get("error_description")??o;a.reject(new Error(h)),this.reply(r,200,{ok:!1,message:"Authorization failed. You may close this window.",details:h});return}let c=i.searchParams.get("code");if(!c){a.reject(new Error("OAuth callback did not include an authorization code")),this.reply(r,400,{ok:!1,message:"Missing authorization code"});return}let l=i.searchParams.get("iss");a.resolve({code:c,state:n,...l?{iss:l}:{}}),this.reply(r,200,{ok:!0})}},g=class extends Error{static{s(this,"McpSignInCancelledError")}constructor(){super("Sign-in cancelled"),this.name="McpSignInCancelledError"}};async function Tt(e){if(e.signal?.aborted)throw new g;let t=e.challenge?.error==="insufficient_scope";return!t&&await zt(e)==="AUTHORIZED"?{kind:"authorized"}:D(e.signal,()=>It(e,t))}s(Tt,"startMcpSignIn");async function zt(e){let{store:t,settings:r,challenge:i,redirectUrl:n,signal:a}=e,o=t.withRefreshLock(async()=>{if(a?.aborted)return"REDIRECT";let c=await t.load();return!c?.tokens?.refresh_token||r.clientRegistration==="cimd"&&c.clientInformation&&!r.clientId?"REDIRECT":me(e,c,{challenge:i,redirectUrl:n})});try{return await Pt(a,o)}catch(c){if(c instanceof oe)return"REDIRECT";throw c}}s(zt,"refreshBeforeSignIn");function Pt(e,t){return e?new Promise((r,i)=>{let n=s(()=>i(new g),"abort");e.addEventListener("abort",n,{once:!0}),t.then(r,i).finally(()=>e.removeEventListener("abort",n))}):t}s(Pt,"untilAborted");async function It(e,t){let{store:r,settings:i,redirectUrl:n,challenge:a}=e,o=await r.load();o&&await r.save(Ot(o,e));let c,l=P(e,n,f=>{c=f}),h=Lt(i.scope,t?Et(o?.tokens?.scope,a?.scope):a?.scope);if(await $(l,{...ve(e),scope:h,skipRefresh:!0}),!c)throw new Error("OAuth flow did not produce an authorization URL");let d=c.searchParams.get("scope");return{kind:"redirect",authorizationUrl:c.href,redirectUrl:c.searchParams.get("redirect_uri")??n,state:await l.state(),...d?{scope:d}:{}}}s(It,"startBrowserStep");function Ot(e,t){let{settings:r,redirectUrl:i}=t,n={...e};return delete n.oauthState,r.clientId||(e.clientInformation?r.clientRegistration!=="cimd"&&O(e.clientInformation).includes(i):I(r,t.clientMetadataDocuments,i))||(delete n.clientInformation,delete n.tokens,delete n.tokensExpireAt),n}s(Ot,"stateForSignIn");function Lt(...e){let t=[...new Set(e.flatMap(r=>r?.split(/\s+/).filter(Boolean)??[]))];return t.length>0?t.join(" "):void 0}s(Lt,"mergeScopes");async function xt(e){await D(e.signal,async()=>{let{authorization:t,response:r}=e;if(r.state!==t.state)throw new Error("The authorization response belongs to a different sign-in");if((await e.store.load())?.oauthState!==t.state)throw new Error("Another sign-in to this MCP server started since; sign in again");await $(P(e,e.redirectUrl),{...ve(e),scope:t.scope,authorizationRedirectUrl:t.redirectUrl,authorizationCode:r.code,iss:r.iss})})}s(xt,"completeMcpSignIn");function ve(e){return{serverUrl:e.serverUrl,fetch:te(),signal:e.signal,resourceMetadataUrl:e.challenge?.resourceMetadataUrl,authorizationServerMetadataUrl:e.settings.authServerMetadataUrl}}s(ve,"flowOptions");async function D(e,t){if(e?.aborted)throw new g;try{return await t()}catch(r){throw e?.aborted?new g:r}}s(D,"cancellable");async function $t(e){let{settings:t}=e,r=ne(t),i=O((await e.store.load())?.clientInformation)[0],n=r.port??(i&&Number(new URL(i).port)||void 0),a=I(t,e.clientMetadataDocuments,r.url),o={host:r.host,redirectHost:r.redirectHost,path:r.path,extraPaths:a?[X(r.path,e.serverUrl)]:[],renderPage:e.renderPage},c;try{c=await _e.listen({...o,port:n??0})}catch(l){if(r.port!==void 0||n===void 0)throw l;c=await _e.listen(o)}return{callback:c,redirectUrl:r.fixedRedirectUrl??c.redirectUrl}}s($t,"listenForLoopbackSignIn");async function Dt(e){let{authorization:t}=e,r=new AbortController,i=e.signal?AbortSignal.any([r.signal,e.signal]):r.signal,n=e.callback.waitForCallback(t.state,new URL(t.redirectUrl).pathname),a=e.promptForRedirectUrl?e.promptForRedirectUrl(i).then(o=>{if(!o?.trim())throw new g;return Ht(o,t)}):new Promise((o,c)=>{i.addEventListener("abort",()=>c(new g),{once:!0})});try{return await D(e.signal,()=>Promise.race([n,a]))}finally{r.abort(),n.catch(()=>{}),a.catch(()=>{})}}s(Dt,"waitForLoopbackSignIn");function Ht(e,t){let r;try{r=new URL(e.trim())}catch{throw new Error("Expected the full redirect URL from the browser address bar")}let i=new URL(t.redirectUrl);if(r.origin!==i.origin||r.pathname!==i.pathname)throw new Error("The redirect URL does not match this sign-in's redirect URI");let n=r.searchParams.get("error");if(n)throw new Error(r.searchParams.get("error_description")??n);let a=r.searchParams.get("state");if(a!==t.state)throw new Error("The redirect URL belongs to a different sign-in");let o=r.searchParams.get("code");if(!o)throw new Error("The redirect URL does not contain an authorization code");let c=r.searchParams.get("iss");return{code:o,state:a,...c?{iss:c}:{}}}s(Ht,"responseFromRedirectUrl");import{createHash as Nt}from"node:crypto";import{mkdirSync as Ft}from"node:fs";import{join as ye}from"node:path";var Vt='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 800" aria-hidden="true"><path fill="#F09082" d="M165.29 165.29H517.36V400H400V282.65H165.29Z"/><path fill="#4D9ABF" d="M165.29 282.65H282.65V400H400V517.36H282.65V634.72H165.29Z"/><path fill="#F1BE58" d="M517.36 400H634.72V634.72H517.36Z"/></svg>';function A(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;")}s(A,"escapeHtml");function Ue(e){let t=A(e.title),r=A(e.heading),i=A(e.message),n=e.details?A(e.details):void 0;return`<!doctype html>
4
4
  <html lang="en">
@@ -1,4 +1,4 @@
1
- var Te=Object.defineProperty;var d=(s,e)=>Te(s,"name",{value:e,configurable:!0});import{createRequire as Fe}from"node:module";const It=Fe(import.meta.url);import{fill as De}from"./chunk-G5AMLGXC.js";import{APP_NAME as Me,APP_TITLE as Ne,getAgentDir as $,getSessionsDir as Ae,normalizePath as b,pathsEqual as Re,resolvePath as S}from"./chunk-R47JBGS3.js";import{reportNewerDataFormat as Be,t as Oe,writeFileAtomicSync as Le}from"./chunk-MZ7O6YLD.js";import{uuidv7 as $e}from"./chunk-IEBK4HQA.js";import{getCurrentSystemMessage as Pe}from"./chunk-PD6QS7YD.js";var je=`The conversation history before this point was compacted into the following summary:
1
+ var Te=Object.defineProperty;var d=(s,e)=>Te(s,"name",{value:e,configurable:!0});import{createRequire as Fe}from"node:module";const It=Fe(import.meta.url);import{fill as De}from"./chunk-G5AMLGXC.js";import{APP_NAME as Me,APP_TITLE as Ne,getAgentDir as $,getSessionsDir as Ae,normalizePath as b,pathsEqual as Re,resolvePath as S}from"./chunk-R47JBGS3.js";import{reportNewerDataFormat as Be,t as Oe,writeFileAtomicSync as Le}from"./chunk-QU2VEHMW.js";import{uuidv7 as $e}from"./chunk-IEBK4HQA.js";import{getCurrentSystemMessage as Pe}from"./chunk-5MF5GEDD.js";var je=`The conversation history before this point was compacted into the following summary:
2
2
 
3
3
  <summary>
4
4
  `,ke=`