@draht/coding-agent 2026.10.31-1 → 2026.11.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +131 -0
- package/dist/bundle/chunks/anthropic-messages-UJZ4SGHU.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-NCMJPZVJ.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +8 -5
- package/dist/bundle/chunks/{chunk-IGO52ZOY.js → chunk-3BJ462DN.js} +2 -2
- package/dist/bundle/chunks/chunk-5OXIAQP5.js +2 -0
- package/dist/bundle/chunks/chunk-6M3D4XVD.js +2 -0
- package/dist/bundle/chunks/chunk-AOCWORXE.js +2 -0
- package/dist/bundle/chunks/chunk-BK5LXGIH.js +2 -0
- package/dist/bundle/chunks/chunk-CA23BDNK.js +2 -0
- package/dist/bundle/chunks/chunk-DWOGGNWY.js +18 -0
- package/dist/bundle/chunks/{chunk-7ATV4EYW.js → chunk-EOXOMUKR.js} +1 -1
- package/dist/bundle/chunks/chunk-F5TDVH26.js +159 -0
- package/dist/bundle/chunks/chunk-HJ3PS7QP.js +4 -0
- package/dist/bundle/chunks/chunk-ITKDPD4D.js +12 -0
- package/dist/bundle/chunks/chunk-KFREX3FS.js +10 -0
- package/dist/bundle/chunks/{chunk-E4VZJRJ2.js → chunk-P7O36UDU.js} +2 -2
- package/dist/bundle/chunks/chunk-PMINB7UH.js +1401 -0
- package/dist/bundle/chunks/chunk-PZKD35UB.js +2 -0
- package/dist/bundle/chunks/{chunk-CPFKZX4B.js → chunk-Q2QKCYPU.js} +1 -1
- package/dist/bundle/chunks/chunk-QBUTRTYN.js +2 -0
- package/dist/bundle/chunks/chunk-SUVMF4W5.js +2 -0
- package/dist/bundle/chunks/chunk-UFACUBF2.js +16 -0
- package/dist/bundle/chunks/chunk-VXO6B72D.js +9 -0
- package/dist/bundle/chunks/{chunk-PMDUR6B5.js → chunk-WXASQQBZ.js} +2 -2
- package/dist/bundle/chunks/chunk-Y3NLUJYO.js +2 -0
- package/dist/bundle/chunks/chunk-Y7QE2R34.js +2 -0
- package/dist/bundle/chunks/chunk-YD5VPPI4.js +30 -0
- package/dist/bundle/chunks/chunk-YWRWN7ZB.js +82 -0
- package/dist/bundle/chunks/{cli-HTUB6WOG.js → cli-4SUT6MJ6.js} +10 -10
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-BJVMNETD.js +2 -0
- package/dist/bundle/chunks/{execute-UUPNZJJG.js → execute-ZI7T2SUH.js} +1 -1
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-A2277FHU.js → google-generative-ai-N5IPPKQY.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-2KSVQZQN.js → google-vertex-A4BKUE4H.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/kimi-coding.js +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-Y3DUSEM2.js → llama-cpp-classify-L4URPZ4F.js} +1 -1
- package/dist/bundle/chunks/meta.js +1 -1
- package/dist/bundle/chunks/mistral-conversations-CK2BS74V.js +5 -0
- package/dist/bundle/chunks/openai-codex-responses-XGVNKP4D.js +10 -0
- package/dist/bundle/chunks/openai-completions-72XZO4Q3.js +7 -0
- package/dist/bundle/chunks/{openai-decisions-JRN6M2KB.js → openai-decisions-P5OCXLLD.js} +1 -1
- package/dist/bundle/chunks/openai-responses-RGLZ4E3Q.js +4 -0
- package/dist/bundle/chunks/{openrouter-images-2XTVCXIC.js → openrouter-images-LSBWMZDK.js} +1 -1
- package/dist/bundle/chunks/pi-messages-CL4MEVNS.js +8 -0
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-IB3XQ7E3.js → runtime-F4362CZF.js} +1 -1
- package/dist/bundle/chunks/{runtime-LB35PK4J.js → runtime-FJYRBK3O.js} +1 -1
- package/dist/bundle/chunks/settings-manager-T6G6KKY3.js +2 -0
- package/dist/bundle/chunks/typesafe-system-one-BFYS6AEA.js +2 -0
- package/dist/bundle/chunks/virtual-modules-BPZIVXNK.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +8 -7
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +3 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -5
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +4 -3
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +16 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +104 -30
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/ai-schemas.d.ts +166 -0
- package/dist/core/ai-schemas.d.ts.map +1 -0
- package/dist/core/ai-schemas.js +21 -0
- package/dist/core/ai-schemas.js.map +1 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +3 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/bug-report.d.ts +4 -4
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +2 -0
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +4 -2
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +16 -4
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/exec.d.ts +9 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +104 -60
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/template.css +9 -0
- package/dist/core/export-html/template.js +165 -45
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +3 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/ai-extension-view.d.ts +19 -0
- package/dist/core/extensions/ai-extension-view.d.ts.map +1 -0
- package/dist/core/extensions/ai-extension-view.js +22 -0
- package/dist/core/extensions/ai-extension-view.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +15 -9
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +9 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +55 -11
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +6 -5
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/keybindings.d.ts +2 -2
- package/dist/core/keybindings.js +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mcp-servers.d.ts +21 -38
- package/dist/core/mcp-servers.d.ts.map +1 -1
- package/dist/core/mcp-servers.js +58 -134
- package/dist/core/mcp-servers.js.map +1 -1
- package/dist/core/model-config.d.ts +1717 -1990
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -3
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +16 -9
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +4 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts +24 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +215 -52
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts +1 -0
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +3 -0
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/project-trust.js +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +8 -4
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/resource-loader.d.ts +4 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +38 -23
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +7 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +32 -13
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +4 -2
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +8 -1
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -15
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +9 -0
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js +14 -0
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +5 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -3
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +2 -4
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +41 -25
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +4 -5
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +73 -70
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +2 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +2 -7
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/write.d.ts.map +1 -1
- package/dist/core/tools/renderers/write.js +19 -19
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +11 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/truncate.d.ts +0 -14
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +0 -29
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +15 -8
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +2 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +6 -2
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +2 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +33 -8
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +23 -2
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js +16 -4
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts +2 -0
- package/dist/extensions/mcp/cli.d.ts.map +1 -1
- package/dist/extensions/mcp/cli.js +72 -15
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +4 -7
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +2 -2
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/oauth.d.ts +13 -50
- package/dist/extensions/mcp/oauth.d.ts.map +1 -1
- package/dist/extensions/mcp/oauth.js +53 -319
- package/dist/extensions/mcp/oauth.js.map +1 -1
- package/dist/extensions/mcp/resources.d.ts +1 -1
- package/dist/extensions/mcp/resources.d.ts.map +1 -1
- package/dist/extensions/mcp/resources.js +4 -3
- package/dist/extensions/mcp/resources.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +4 -3
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +4 -3
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts +2 -23
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +6 -58
- package/dist/extensions/mcp/tools.js.map +1 -1
- package/dist/extensions/mcp/ui.d.ts +1 -0
- package/dist/extensions/mcp/ui.d.ts.map +1 -1
- package/dist/extensions/mcp/ui.js +33 -24
- package/dist/extensions/mcp/ui.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +21 -6
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +104 -36
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +16 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +4 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +44 -20
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts +5 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +12 -4
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +5 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +12 -4
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +4 -18
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +2 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +5 -2
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +12 -4
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js +11 -5
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +2 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +4 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +9 -1
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +104 -10
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +2 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.js +3 -2
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts +2 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +25 -20
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +17 -6
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +13 -4
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +14 -3
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts +4 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js +86 -22
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +20 -27
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js +2 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +5 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +12 -4
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +6 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +14 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +2 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +24 -16
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +9 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +3 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +6 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +1 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +16 -4
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +7 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +179 -53
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts +10 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.js +21 -0
- package/dist/modes/interactive/model-search.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +10 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +35 -23
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +19 -10
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +53 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +78 -9
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +5 -2
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/changelog.d.ts +2 -2
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +15 -2
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +4 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/git.d.ts +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +5 -3
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js +4 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +42 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +14 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +5 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +7 -0
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +30 -35
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/cli.md +22 -10
- package/docs/custom-provider.md +2 -0
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +3201 -233
- package/docs/keybindings.md +2 -2
- package/docs/llama-cpp.md +23 -15
- package/docs/message-types.md +1 -1
- package/docs/models-configuration.md +17 -4
- package/docs/models.md +9 -4
- package/docs/packages.md +24 -0
- package/docs/providers.md +1 -1
- package/docs/rpc.md +3 -1
- package/docs/sessions.md +11 -3
- package/docs/settings.md +5 -4
- package/docs/slash-commands.md +3 -2
- package/docs/terminal-setup.md +3 -1
- package/docs/tmux.md +6 -0
- package/docs/tui.md +2 -0
- package/docs/windows.md +27 -0
- package/eval/drahtbank/isolated-tools.ts +0 -1
- package/examples/extensions/antigravity-image-gen.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +27 -31
- package/examples/extensions/debug-provider.ts +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/plan-mode/index.ts +23 -13
- package/examples/extensions/plan-mode/utils.ts +42 -16
- package/examples/extensions/preset.ts +2 -0
- package/examples/extensions/reload-runtime.ts +17 -5
- package/examples/extensions/sandbox/package-lock.json +15 -41
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/index.ts +388 -171
- package/examples/extensions/todo.ts +7 -0
- package/examples/extensions/tools.ts +2 -0
- package/examples/tsconfig.json +188 -0
- package/package.json +15 -16
- package/schemas/models.schema.json +85 -39
- package/schemas/settings.schema.json +17 -0
- package/dist/bundle/chunks/anthropic-messages-CZYDBUW7.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-UKM4K3L6.js +0 -2
- package/dist/bundle/chunks/chunk-2TZWVGCR.js +0 -2
- package/dist/bundle/chunks/chunk-76YNMQ57.js +0 -2
- package/dist/bundle/chunks/chunk-AS6DCLAM.js +0 -1428
- package/dist/bundle/chunks/chunk-BL72B6LV.js +0 -82
- package/dist/bundle/chunks/chunk-C2XCXA6V.js +0 -2
- package/dist/bundle/chunks/chunk-CLKG6K6Z.js +0 -7
- package/dist/bundle/chunks/chunk-FOYIPAAD.js +0 -6
- package/dist/bundle/chunks/chunk-FXCTQRNN.js +0 -2
- package/dist/bundle/chunks/chunk-H5BLLINF.js +0 -11
- package/dist/bundle/chunks/chunk-IT4RIOZD.js +0 -2
- package/dist/bundle/chunks/chunk-N3FZGIII.js +0 -16
- package/dist/bundle/chunks/chunk-OCUU7HYF.js +0 -2
- package/dist/bundle/chunks/chunk-QMN7OD6G.js +0 -2
- package/dist/bundle/chunks/chunk-UCJ7FLSO.js +0 -166
- package/dist/bundle/chunks/chunk-WFHH5SX6.js +0 -4
- package/dist/bundle/chunks/chunk-WYWBXNDO.js +0 -6
- package/dist/bundle/chunks/chunk-XOGEYN4Q.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-V37VPUK4.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-R2NJADHS.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-KJZDJELP.js +0 -10
- package/dist/bundle/chunks/openai-completions-RTWADJBP.js +0 -7
- package/dist/bundle/chunks/openai-responses-B7ASLN2Z.js +0 -4
- package/dist/bundle/chunks/pi-messages-7TX4RC24.js +0 -8
- package/dist/bundle/chunks/settings-manager-YNY5F4RU.js +0 -2
- package/dist/bundle/chunks/typesafe-system-one-7BNMQFXE.js +0 -2
- package/dist/bundle/chunks/virtual-modules-OFCQ5AEG.js +0 -2
|
@@ -1,39 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OAuth sign-in for remote MCP servers.
|
|
2
|
+
* OAuth sign-in for remote MCP servers: draht's credential store and its side of the sign-in.
|
|
3
3
|
*
|
|
4
4
|
* Connections never start a browser flow on their own. They send the stored access token and, after
|
|
5
5
|
* a 401, try the stored refresh token. When that is not possible they fail with
|
|
6
|
-
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp`, which
|
|
7
|
-
*
|
|
8
|
-
* against a loopback callback.
|
|
6
|
+
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp` or `draht mcp login`, which
|
|
7
|
+
* run @draht/mcp's sign-in (PKCE, the operator's Client ID Metadata Document or dynamic client
|
|
8
|
+
* registration) against a loopback callback or a pasted redirect URL.
|
|
9
9
|
*
|
|
10
10
|
* Credentials live in `<agent-dir>/mcp-auth.json`, keyed by server name and URL.
|
|
11
11
|
*/
|
|
12
|
-
import type
|
|
13
|
-
import { type McpOAuthState, type McpOAuthStateStore, type OAuthChallenge } from "@draht/mcp/oauth";
|
|
12
|
+
import { type McpAuthProvider, type McpOAuthServerStore, type McpOAuthSettings, type McpOAuthState, type OAuthChallenge } from "@draht/mcp/oauth";
|
|
14
13
|
import { type AuthStorageBackend } from "../../core/auth-storage.ts";
|
|
15
|
-
export interface McpOAuthSettings {
|
|
16
|
-
clientId?: string;
|
|
17
|
-
/** Already resolved. */
|
|
18
|
-
clientSecret?: string;
|
|
19
|
-
callbackPort?: number;
|
|
20
|
-
/** Loopback redirect URI; see `McpOAuthConfig.callbackUrl`. */
|
|
21
|
-
callbackUrl?: string;
|
|
22
|
-
/** Scopes to request, separated by spaces. */
|
|
23
|
-
scope?: string;
|
|
24
|
-
/** `client_name` for dynamic client registration. Default: `APP_NAME`. */
|
|
25
|
-
clientName?: string;
|
|
26
|
-
/** See `McpOAuthConfig.clientRegistration`. */
|
|
27
|
-
clientRegistration?: "dcr" | "cimd";
|
|
28
|
-
/** Validated by the config boundary, with a trailing slash. Required for `cimd`. */
|
|
29
|
-
clientMetadataBaseUrl?: string;
|
|
30
|
-
/** See `McpOAuthConfig.authServerMetadataUrl`. */
|
|
31
|
-
authServerMetadataUrl?: URL;
|
|
32
|
-
}
|
|
33
|
-
export interface McpOAuthServerStore extends McpOAuthStateStore {
|
|
34
|
-
/** Run `fn` while no other process refreshes the server's tokens. */
|
|
35
|
-
withRefreshLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
36
|
-
}
|
|
37
14
|
/** Per-server OAuth state (client registration, tokens, pending PKCE verifier) in `mcp-auth.json`. */
|
|
38
15
|
export declare class McpOAuthCredentialStore {
|
|
39
16
|
private readonly backend;
|
|
@@ -44,6 +21,7 @@ export declare class McpOAuthCredentialStore {
|
|
|
44
21
|
/**
|
|
45
22
|
* A lock file per server. When the process exits, proper-lockfile removes the locks it holds; when
|
|
46
23
|
* it is killed, the lock goes stale because it is no longer renewed, and the next process takes it over.
|
|
24
|
+
* Throws `McpRefreshLockBusyError` when another process holds the lock for the whole wait.
|
|
47
25
|
*/
|
|
48
26
|
private withRefreshLock;
|
|
49
27
|
/** The stored tokens of a server, for noticing sign-ins done by another process. Does not take over legacy state. */
|
|
@@ -52,27 +30,14 @@ export declare class McpOAuthCredentialStore {
|
|
|
52
30
|
remove(name: string, serverUrl: string): boolean;
|
|
53
31
|
private write;
|
|
54
32
|
}
|
|
55
|
-
export interface McpAuthProvider extends AuthProvider {
|
|
56
|
-
/** Resolves when no refresh is running, so shutdown does not drop rotated tokens before they are saved. */
|
|
57
|
-
settled(): Promise<void>;
|
|
58
|
-
}
|
|
59
33
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* server's `WWW-Authenticate` challenge so sign-in can use its resource metadata URL and scope.
|
|
64
|
-
* `settings` is only called when a refresh is needed, so a secret that fails to resolve fails the
|
|
65
|
-
* refresh instead of the whole connection setup.
|
|
66
|
-
*
|
|
67
|
-
* Many servers rotate refresh tokens, so two refreshes with the same refresh token lose the grant.
|
|
68
|
-
* Requests in this process share one refresh, and other processes are kept out by the store's
|
|
69
|
-
* refresh lock, held from reading the tokens to saving new ones. Tokens that changed meanwhile
|
|
70
|
-
* (another process refreshed them, or the user signed in) are used without refreshing.
|
|
34
|
+
* @draht/mcp's `createMcpAuthProvider` with draht's client identity. `clientMetadataBaseUrl` is the
|
|
35
|
+
* validated base from the configuration (or undefined without `cimd`), apart from `settings` so that
|
|
36
|
+
* reading a cached token never resolves `oauth.clientSecret`.
|
|
71
37
|
*/
|
|
72
38
|
export declare function createMcpAuthProvider(options: {
|
|
73
39
|
serverUrl: string;
|
|
74
40
|
store: McpOAuthServerStore;
|
|
75
|
-
/** Validated CIMD base, or undefined for DCR. Separate from settings so token reads do not resolve secrets. */
|
|
76
41
|
clientMetadataBaseUrl: string | undefined;
|
|
77
42
|
settings: () => McpOAuthSettings;
|
|
78
43
|
onChallenge: (challenge: OAuthChallenge) => void;
|
|
@@ -87,17 +52,15 @@ export interface McpSignInPrompt {
|
|
|
87
52
|
*/
|
|
88
53
|
promptForRedirectUrl(signal: AbortSignal): Promise<string | undefined>;
|
|
89
54
|
}
|
|
90
|
-
export declare class McpSignInCancelledError extends Error {
|
|
91
|
-
constructor();
|
|
92
|
-
}
|
|
93
55
|
/**
|
|
94
56
|
* Sign in to an MCP server. Uses the stored refresh token when possible; otherwise runs the browser
|
|
95
|
-
* authorization code flow
|
|
96
|
-
* step with `McpSignInCancelledError`; requests to
|
|
57
|
+
* authorization code flow against a loopback callback or a pasted redirect URL. Tokens are saved to
|
|
58
|
+
* `store`. Aborting `signal` stops the sign-in at any step with `McpSignInCancelledError`; requests to
|
|
59
|
+
* the authorization server are also time-limited.
|
|
97
60
|
*/
|
|
98
61
|
export declare function signInMcpServer(options: {
|
|
99
62
|
serverUrl: string;
|
|
100
|
-
store:
|
|
63
|
+
store: McpOAuthServerStore;
|
|
101
64
|
settings: McpOAuthSettings;
|
|
102
65
|
challenge?: OAuthChallenge;
|
|
103
66
|
prompt: McpSignInPrompt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,EAIN,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAGlB,KAAK,cAAc,EAGnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,KAAK,kBAAkB,EAA0B,MAAM,4BAA4B,CAAC;AA8B7F,sGAAsG;AACtG,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,wGAAwG;IACxG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,YAAY,OAAO,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,MAAM,EAGzD;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,mBAAmB,CAkB9D;IAED;;;;OAIG;YACW,eAAe;IA8B7B,qHAAqH;IACrH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAI/D;IAED,+GAA+G;IAC/G,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAS/C;IAED,OAAO,CAAC,KAAK;CAOb;AAcD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,EAAE,MAAM,gBAAgB,CAAC;IACjC,WAAW,EAAE,CAAC,SAAS,EAAE,cAAc,KAAK,IAAI,CAAC;CACjD,GAAG,eAAe,CAElB;AAED,MAAM,WAAW,eAAe;IAC/B,uEAAuE;IACvE,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IACrC;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACvE;AAQD;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OAuth sign-in for remote MCP servers.
|
|
2
|
+
* OAuth sign-in for remote MCP servers: draht's credential store and its side of the sign-in.
|
|
3
3
|
*
|
|
4
4
|
* Connections never start a browser flow on their own. They send the stored access token and, after
|
|
5
5
|
* a 401, try the stored refresh token. When that is not possible they fail with
|
|
6
|
-
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp`, which
|
|
7
|
-
*
|
|
8
|
-
* against a loopback callback.
|
|
6
|
+
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp` or `draht mcp login`, which
|
|
7
|
+
* run @draht/mcp's sign-in (PKCE, the operator's Client ID Metadata Document or dynamic client
|
|
8
|
+
* registration) against a loopback callback or a pasted redirect URL.
|
|
9
9
|
*
|
|
10
10
|
* Credentials live in `<agent-dir>/mcp-auth.json`, keyed by server name and URL.
|
|
11
11
|
*/
|
|
@@ -13,53 +13,17 @@ import { createHash } from "node:crypto";
|
|
|
13
13
|
import { mkdirSync } from "node:fs";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { oauthErrorHtml, oauthSuccessHtml } from "@draht/ai/utils/oauth-page";
|
|
16
|
-
import {
|
|
16
|
+
import { mcpNamespace } from "@draht/mcp";
|
|
17
|
+
import { completeMcpSignIn, createMcpAuthProvider as createAuthProvider, listenForLoopbackSignIn, McpRefreshLockBusyError, startMcpSignIn, waitForLoopbackSignIn, } from "@draht/mcp/oauth";
|
|
17
18
|
import lockfile from "proper-lockfile";
|
|
18
19
|
import { APP_NAME, getAgentDir } from "../../config.js";
|
|
19
20
|
import { FileAuthStorageBackend } from "../../core/auth-storage.js";
|
|
20
|
-
import {
|
|
21
|
-
const CALLBACK_HOST = "127.0.0.1";
|
|
22
|
-
const CALLBACK_PATH = "/callback";
|
|
23
|
-
/** Redirect URI for refreshes when none is stored. Refreshing never redirects the user. */
|
|
24
|
-
const FALLBACK_REDIRECT_URL = `http://${CALLBACK_HOST}${CALLBACK_PATH}`;
|
|
25
|
-
/** Access tokens this close to expiry are refreshed before they are sent. */
|
|
26
|
-
const REFRESH_SKEW_MS = 30_000;
|
|
27
|
-
/**
|
|
28
|
-
* Bounds each request to the authorization server, so an unresponsive one cannot hold the refresh lock,
|
|
29
|
-
* delay shutdown, or keep a sign-in waiting for long.
|
|
30
|
-
*/
|
|
31
|
-
const OAUTH_REQUEST_TIMEOUT_MS = 15_000;
|
|
21
|
+
import { isClientMetadataDocumentCallback } from "../../core/mcp-servers.js";
|
|
32
22
|
/** A refresh lock that its holder stopped renewing (the process was killed) is taken over after this. */
|
|
33
23
|
const REFRESH_LOCK_STALE_MS = 20_000;
|
|
34
24
|
/** How long to wait for another process's refresh: longer than a stale lock lives. */
|
|
35
25
|
const REFRESH_LOCK_WAIT_MS = 25_000;
|
|
36
26
|
const REFRESH_LOCK_RETRY_MS = 100;
|
|
37
|
-
function callbackSettings(settings) {
|
|
38
|
-
const url = new URL(settings.callbackUrl ?? `http://${CALLBACK_HOST}${CALLBACK_PATH}`);
|
|
39
|
-
const address = url.hostname.replace(/^\[|\]$/g, "");
|
|
40
|
-
const port = url.port ? Number(url.port) : settings.callbackPort;
|
|
41
|
-
let fixedRedirectUrl;
|
|
42
|
-
// A configured URI with a port is sent exactly as written, since servers compare it as a string.
|
|
43
|
-
if (url.port)
|
|
44
|
-
fixedRedirectUrl = settings.callbackUrl;
|
|
45
|
-
else if (port !== undefined) {
|
|
46
|
-
url.port = String(port);
|
|
47
|
-
fixedRedirectUrl = url.href;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
// `localhost` is served on 127.0.0.1; browsers fall back to it when ::1 refuses.
|
|
51
|
-
host: address === "localhost" ? CALLBACK_HOST : address,
|
|
52
|
-
redirectHost: address,
|
|
53
|
-
port,
|
|
54
|
-
path: url.pathname,
|
|
55
|
-
fixedRedirectUrl,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/** Scopes of both lists, each once. */
|
|
59
|
-
function mergeScopes(...scopes) {
|
|
60
|
-
const merged = [...new Set(scopes.flatMap((scope) => scope?.split(/\s+/).filter(Boolean) ?? []))];
|
|
61
|
-
return merged.length > 0 ? merged.join(" ") : undefined;
|
|
62
|
-
}
|
|
63
27
|
function parseStates(content) {
|
|
64
28
|
if (!content?.trim())
|
|
65
29
|
return {};
|
|
@@ -107,13 +71,15 @@ export class McpOAuthCredentialStore {
|
|
|
107
71
|
/**
|
|
108
72
|
* A lock file per server. When the process exits, proper-lockfile removes the locks it holds; when
|
|
109
73
|
* it is killed, the lock goes stale because it is no longer renewed, and the next process takes it over.
|
|
74
|
+
* Throws `McpRefreshLockBusyError` when another process holds the lock for the whole wait.
|
|
110
75
|
*/
|
|
111
76
|
async withRefreshLock(key, fn) {
|
|
112
77
|
if (!this.lockDir)
|
|
113
78
|
return fn();
|
|
114
79
|
mkdirSync(this.lockDir, { recursive: true, mode: 0o700 });
|
|
115
80
|
const hash = createHash("sha256").update(key).digest("hex").slice(0, 16);
|
|
116
|
-
const release = await lockfile
|
|
81
|
+
const release = await lockfile
|
|
82
|
+
.lock(join(this.lockDir, `mcp-auth-refresh-${hash}`), {
|
|
117
83
|
realpath: false,
|
|
118
84
|
stale: REFRESH_LOCK_STALE_MS,
|
|
119
85
|
retries: {
|
|
@@ -124,6 +90,12 @@ export class McpOAuthCredentialStore {
|
|
|
124
90
|
},
|
|
125
91
|
// The default throws from a timer. A lost lock at worst lets two refreshes overlap.
|
|
126
92
|
onCompromised: () => { },
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
// proper-lockfile reports a lock held by another process as `ELOCKED`.
|
|
96
|
+
if (error instanceof Error && "code" in error && error.code === "ELOCKED")
|
|
97
|
+
throw new McpRefreshLockBusyError();
|
|
98
|
+
throw error;
|
|
127
99
|
});
|
|
128
100
|
try {
|
|
129
101
|
return await fn();
|
|
@@ -158,294 +130,56 @@ export class McpOAuthCredentialStore {
|
|
|
158
130
|
});
|
|
159
131
|
}
|
|
160
132
|
}
|
|
161
|
-
/** `fetch` with `OAUTH_REQUEST_TIMEOUT_MS` per request, on top of the request's own signal. */
|
|
162
|
-
function timedFetch(fetch = globalThis.fetch) {
|
|
163
|
-
return (input, init) => {
|
|
164
|
-
const timeout = AbortSignal.timeout(OAUTH_REQUEST_TIMEOUT_MS);
|
|
165
|
-
return fetch(input, { ...init, signal: init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout });
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function registeredRedirectUrls(client) {
|
|
169
|
-
return client && "redirect_uris" in client ? client.redirect_uris : [];
|
|
170
|
-
}
|
|
171
|
-
/** 12 characters identifying an MCP server URL in callback paths, computed like Codex does. */
|
|
172
|
-
function callbackId(serverUrl) {
|
|
173
|
-
const url = new URL(serverUrl);
|
|
174
|
-
url.hash = "";
|
|
175
|
-
return createHash("sha256").update(url.href).digest().subarray(0, 9).toString("base64url");
|
|
176
|
-
}
|
|
177
133
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* cannot be mixed up with one from another authorization server (RFC 9700 section 4.4.2.2).
|
|
134
|
+
* The redirect URIs the operator's Client ID Metadata Documents list (docs/mcp.md): `/callback` on
|
|
135
|
+
* localhost and 127.0.0.1. draht names no document host: with `cimd`, @draht/mcp takes the documents'
|
|
136
|
+
* base from the validated `oauth.clientMetadataBaseUrl` only, and without `cimd` it registers a client.
|
|
182
137
|
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (metadata.authorization_response_iss_parameter_supported) {
|
|
189
|
-
return { url: new URL("client.json", baseUrl).href, redirectUrl };
|
|
190
|
-
}
|
|
191
|
-
const id = callbackId(serverUrl);
|
|
192
|
-
const redirect = new URL(redirectUrl);
|
|
193
|
-
redirect.pathname = `${CALLBACK_PATH}/${id}`;
|
|
194
|
-
return { url: new URL(`${id}/client.json`, baseUrl).href, redirectUrl: redirect.href };
|
|
195
|
-
}
|
|
196
|
-
function metadataBaseUrl(settings) {
|
|
197
|
-
if (settings.clientRegistration !== "cimd")
|
|
198
|
-
return undefined;
|
|
199
|
-
if (!settings.clientMetadataBaseUrl)
|
|
200
|
-
throw new Error('oauth.clientMetadataBaseUrl is required for "cimd"');
|
|
201
|
-
return settings.clientMetadataBaseUrl;
|
|
202
|
-
}
|
|
203
|
-
/** A cached token belongs to this registration mode and metadata base, or it needs a new sign-in. */
|
|
204
|
-
function matchesClient(state, serverUrl, baseUrl) {
|
|
205
|
-
if (!state || state.serverUrl !== new URL(serverUrl).href)
|
|
206
|
-
return false;
|
|
207
|
-
if (!baseUrl)
|
|
208
|
-
return state.clientMetadataUrl === undefined;
|
|
209
|
-
return (state.clientMetadataUrl === new URL("client.json", baseUrl).href ||
|
|
210
|
-
state.clientMetadataUrl === new URL(`${callbackId(serverUrl)}/client.json`, baseUrl).href);
|
|
211
|
-
}
|
|
212
|
-
function createProvider(serverUrl, store, settings, redirectUrl, onRedirect) {
|
|
213
|
-
const baseUrl = metadataBaseUrl(settings);
|
|
214
|
-
return new McpOAuthProvider({
|
|
215
|
-
serverUrl,
|
|
216
|
-
redirectUrl,
|
|
217
|
-
clientMetadata: { client_name: settings.clientName ?? APP_NAME },
|
|
218
|
-
clientMetadataDocument: baseUrl
|
|
219
|
-
? (metadata) => clientMetadataDocument(baseUrl, serverUrl, redirectUrl, metadata)
|
|
220
|
-
: undefined,
|
|
221
|
-
clientId: settings.clientId,
|
|
222
|
-
clientSecret: settings.clientSecret,
|
|
223
|
-
store,
|
|
224
|
-
onRedirect,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
138
|
+
const CLIENT_METADATA_DOCUMENTS = {
|
|
139
|
+
listsRedirectUrl: isClientMetadataDocumentCallback,
|
|
140
|
+
};
|
|
141
|
+
/** draht's client identity for sign-in and refresh. */
|
|
142
|
+
const DRAHT_CLIENT = { clientName: APP_NAME, clientMetadataDocuments: CLIENT_METADATA_DOCUMENTS };
|
|
227
143
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* server's `WWW-Authenticate` challenge so sign-in can use its resource metadata URL and scope.
|
|
232
|
-
* `settings` is only called when a refresh is needed, so a secret that fails to resolve fails the
|
|
233
|
-
* refresh instead of the whole connection setup.
|
|
234
|
-
*
|
|
235
|
-
* Many servers rotate refresh tokens, so two refreshes with the same refresh token lose the grant.
|
|
236
|
-
* Requests in this process share one refresh, and other processes are kept out by the store's
|
|
237
|
-
* refresh lock, held from reading the tokens to saving new ones. Tokens that changed meanwhile
|
|
238
|
-
* (another process refreshed them, or the user signed in) are used without refreshing.
|
|
144
|
+
* @draht/mcp's `createMcpAuthProvider` with draht's client identity. `clientMetadataBaseUrl` is the
|
|
145
|
+
* validated base from the configuration (or undefined without `cimd`), apart from `settings` so that
|
|
146
|
+
* reading a cached token never resolves `oauth.clientSecret`.
|
|
239
147
|
*/
|
|
240
148
|
export function createMcpAuthProvider(options) {
|
|
241
|
-
|
|
242
|
-
let refreshing;
|
|
243
|
-
/** Replace `staleToken`, the access token that expired or was rejected. */
|
|
244
|
-
const refresh = (staleToken, fetch = globalThis.fetch, challenge) => {
|
|
245
|
-
refreshing ??= store
|
|
246
|
-
.withRefreshLock(async () => {
|
|
247
|
-
const state = await store.load();
|
|
248
|
-
if (!matchesClient(state, serverUrl, options.clientMetadataBaseUrl)) {
|
|
249
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
250
|
-
}
|
|
251
|
-
if (state?.tokens?.access_token !== staleToken)
|
|
252
|
-
return;
|
|
253
|
-
if (!state?.tokens?.refresh_token)
|
|
254
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
255
|
-
const settings = options.settings();
|
|
256
|
-
const redirectUrl = callbackSettings(settings).fixedRedirectUrl ??
|
|
257
|
-
registeredRedirectUrls(state.clientInformation)[0] ??
|
|
258
|
-
FALLBACK_REDIRECT_URL;
|
|
259
|
-
const provider = createProvider(serverUrl, store, settings, redirectUrl, () => { });
|
|
260
|
-
// Refreshes the tokens, or reports that a new sign-in is needed. Not cancellable: a refresh the
|
|
261
|
-
// server answered may have rotated the refresh token, so its answer must be saved.
|
|
262
|
-
const result = await authorizeMcp(provider, {
|
|
263
|
-
serverUrl,
|
|
264
|
-
resourceMetadataUrl: challenge?.resourceMetadataUrl,
|
|
265
|
-
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
266
|
-
scope: challenge?.scope,
|
|
267
|
-
fetch: timedFetch(fetch),
|
|
268
|
-
});
|
|
269
|
-
if (result === "REDIRECT")
|
|
270
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
271
|
-
})
|
|
272
|
-
.finally(() => {
|
|
273
|
-
refreshing = undefined;
|
|
274
|
-
});
|
|
275
|
-
return refreshing;
|
|
276
|
-
};
|
|
277
|
-
return {
|
|
278
|
-
token: async () => {
|
|
279
|
-
await refreshing?.catch(() => undefined);
|
|
280
|
-
const state = await store.load();
|
|
281
|
-
if (!matchesClient(state, serverUrl, options.clientMetadataBaseUrl))
|
|
282
|
-
return undefined;
|
|
283
|
-
const token = state?.tokens?.access_token;
|
|
284
|
-
const expired = state?.tokensExpireAt !== undefined && state.tokensExpireAt - REFRESH_SKEW_MS <= Date.now();
|
|
285
|
-
if (!expired || !state?.tokens?.refresh_token)
|
|
286
|
-
return token;
|
|
287
|
-
// Failures fall through: the request goes out with the old token and a 401 decides what happens.
|
|
288
|
-
await refresh(token).catch(() => undefined);
|
|
289
|
-
const refreshed = await store.load();
|
|
290
|
-
return matchesClient(refreshed, serverUrl, options.clientMetadataBaseUrl)
|
|
291
|
-
? refreshed?.tokens?.access_token
|
|
292
|
-
: undefined;
|
|
293
|
-
},
|
|
294
|
-
onUnauthorized: async (context) => {
|
|
295
|
-
const challenge = parseWwwAuthenticate(context.response.headers.get("www-authenticate"));
|
|
296
|
-
options.onChallenge(challenge);
|
|
297
|
-
// A refresh keeps the granted scope, so more scope needs a new sign-in.
|
|
298
|
-
if (challenge.error === "insufficient_scope")
|
|
299
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
300
|
-
await refresh(context.token, context.fetch, challenge);
|
|
301
|
-
},
|
|
302
|
-
settled: async () => {
|
|
303
|
-
await refreshing?.catch(() => undefined);
|
|
304
|
-
},
|
|
305
|
-
};
|
|
149
|
+
return createAuthProvider({ ...options, ...DRAHT_CLIENT });
|
|
306
150
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
function responseFromRedirectUrl(input, state, redirectUrl) {
|
|
314
|
-
let url;
|
|
315
|
-
try {
|
|
316
|
-
url = new URL(input.trim());
|
|
317
|
-
}
|
|
318
|
-
catch {
|
|
319
|
-
throw new Error("Expected the full redirect URL from the browser address bar");
|
|
320
|
-
}
|
|
321
|
-
// A server-specific redirect URI tells authorization servers apart, so it must match exactly.
|
|
322
|
-
if (url.origin !== redirectUrl.origin || url.pathname !== redirectUrl.pathname) {
|
|
323
|
-
throw new Error("The redirect URL does not match this sign-in's redirect URI");
|
|
324
|
-
}
|
|
325
|
-
const error = url.searchParams.get("error");
|
|
326
|
-
if (error)
|
|
327
|
-
throw new Error(url.searchParams.get("error_description") ?? error);
|
|
328
|
-
if (url.searchParams.get("state") !== state)
|
|
329
|
-
throw new Error("The redirect URL belongs to a different sign-in");
|
|
330
|
-
const code = url.searchParams.get("code");
|
|
331
|
-
if (!code)
|
|
332
|
-
throw new Error("The redirect URL does not contain an authorization code");
|
|
333
|
-
return { code, iss: url.searchParams.get("iss") ?? undefined };
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Wait for the browser callback or a pasted redirect URL, whichever comes first. Aborting `signal`
|
|
337
|
-
* aborts the prompt, which then cancels the sign-in.
|
|
338
|
-
*/
|
|
339
|
-
async function waitForAuthorizationResponse(callback, state, redirectUrl, prompt, signal) {
|
|
340
|
-
const controller = new AbortController();
|
|
341
|
-
const promptSignal = signal ? AbortSignal.any([controller.signal, signal]) : controller.signal;
|
|
342
|
-
const fromBrowser = callback.waitForCallback(state, redirectUrl.pathname);
|
|
343
|
-
const fromUser = prompt.promptForRedirectUrl(promptSignal).then((input) => {
|
|
344
|
-
if (!input?.trim())
|
|
345
|
-
throw new McpSignInCancelledError();
|
|
346
|
-
return responseFromRedirectUrl(input, state, redirectUrl);
|
|
347
|
-
});
|
|
348
|
-
try {
|
|
349
|
-
return await Promise.race([fromBrowser, fromUser]);
|
|
350
|
-
}
|
|
351
|
-
finally {
|
|
352
|
-
// The losing side rejects once the prompt is aborted or the callback server closes.
|
|
353
|
-
controller.abort();
|
|
354
|
-
fromBrowser.catch(() => undefined);
|
|
355
|
-
fromUser.catch(() => undefined);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
/** Listen on `port`, or on a free port when it is taken and not `required`. */
|
|
359
|
-
async function listenForCallback(settings, extraPaths, port, required) {
|
|
360
|
-
const options = {
|
|
361
|
-
host: settings.host,
|
|
362
|
-
redirectHost: settings.redirectHost,
|
|
363
|
-
path: settings.path,
|
|
364
|
-
extraPaths,
|
|
365
|
-
renderPage: (page) => page.ok
|
|
366
|
-
? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.")
|
|
367
|
-
: oauthErrorHtml(page.message, page.details),
|
|
368
|
-
};
|
|
369
|
-
try {
|
|
370
|
-
return await OAuthCallbackServer.listen({ ...options, port: port ?? 0 });
|
|
371
|
-
}
|
|
372
|
-
catch (error) {
|
|
373
|
-
if (required || port === undefined)
|
|
374
|
-
throw error;
|
|
375
|
-
return OAuthCallbackServer.listen(options);
|
|
376
|
-
}
|
|
151
|
+
function renderCallbackPage(page) {
|
|
152
|
+
return page.ok
|
|
153
|
+
? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.")
|
|
154
|
+
: oauthErrorHtml(page.message, page.details);
|
|
377
155
|
}
|
|
378
156
|
/**
|
|
379
157
|
* Sign in to an MCP server. Uses the stored refresh token when possible; otherwise runs the browser
|
|
380
|
-
* authorization code flow
|
|
381
|
-
* step with `McpSignInCancelledError`; requests to
|
|
158
|
+
* authorization code flow against a loopback callback or a pasted redirect URL. Tokens are saved to
|
|
159
|
+
* `store`. Aborting `signal` stops the sign-in at any step with `McpSignInCancelledError`; requests to
|
|
160
|
+
* the authorization server are also time-limited.
|
|
382
161
|
*/
|
|
383
162
|
export async function signInMcpServer(options) {
|
|
384
|
-
const { serverUrl, store, settings, signal } = options;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
await store.save({ serverUrl });
|
|
392
|
-
const stepUp = options.challenge?.error === "insufficient_scope";
|
|
393
|
-
const callbackOptions = callbackSettings(settings);
|
|
394
|
-
// Reuse the port of the registered redirect URI so the registered client stays valid.
|
|
395
|
-
const registered = registeredRedirectUrls(stored?.clientInformation)[0];
|
|
396
|
-
const preferredPort = callbackOptions.port ?? (registered ? Number(new URL(registered).port) || undefined : undefined);
|
|
397
|
-
const cimd = settings.clientRegistration === "cimd";
|
|
398
|
-
const callback = await listenForCallback(callbackOptions,
|
|
399
|
-
// The redirect URI of a server-specific Client ID Metadata Document.
|
|
400
|
-
cimd ? [`${CALLBACK_PATH}/${callbackId(serverUrl)}`] : [], preferredPort, callbackOptions.port !== undefined);
|
|
401
|
-
const redirectUrl = callbackOptions.fixedRedirectUrl ?? callback.redirectUrl;
|
|
163
|
+
const { serverUrl, store, settings, challenge, prompt, signal } = options;
|
|
164
|
+
const { callback, redirectUrl } = await listenForLoopbackSignIn({
|
|
165
|
+
serverUrl,
|
|
166
|
+
store,
|
|
167
|
+
settings,
|
|
168
|
+
renderPage: renderCallbackPage,
|
|
169
|
+
});
|
|
402
170
|
try {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
delete next.oauthState;
|
|
407
|
-
// A registered client cannot use another redirect URI. CIMD tokens were checked against the base above.
|
|
408
|
-
const keepClient = settings.clientId ||
|
|
409
|
-
(cimd ? !stored.clientInformation : registeredRedirectUrls(stored.clientInformation).includes(redirectUrl));
|
|
410
|
-
if (!keepClient) {
|
|
411
|
-
delete next.clientInformation;
|
|
412
|
-
delete next.tokens;
|
|
413
|
-
delete next.tokensExpireAt;
|
|
414
|
-
}
|
|
415
|
-
await store.save(next);
|
|
416
|
-
}
|
|
417
|
-
let authorizationUrl;
|
|
418
|
-
const provider = createProvider(serverUrl, store, settings, redirectUrl, (url) => {
|
|
419
|
-
authorizationUrl = url;
|
|
420
|
-
});
|
|
421
|
-
const flow = {
|
|
422
|
-
serverUrl,
|
|
423
|
-
fetch: timedFetch(),
|
|
424
|
-
signal,
|
|
425
|
-
resourceMetadataUrl: options.challenge?.resourceMetadataUrl,
|
|
426
|
-
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
427
|
-
// A server asking for more scope gets it on top of the configured scope and, since the challenge
|
|
428
|
-
// may list only the missing scopes, on top of the scope granted so far.
|
|
429
|
-
scope: mergeScopes(settings.scope, stepUp ? stepUpScope(stored?.tokens?.scope, options.challenge?.scope) : options.challenge?.scope),
|
|
430
|
-
};
|
|
431
|
-
// A refresh keeps the granted scope; a server asking for more needs the browser flow.
|
|
432
|
-
const skipRefresh = stepUp;
|
|
433
|
-
if ((await authorizeMcp(provider, { ...flow, skipRefresh })) === "AUTHORIZED")
|
|
171
|
+
const signIn = { serverUrl, store, settings, redirectUrl, challenge, signal, ...DRAHT_CLIENT };
|
|
172
|
+
const authorization = await startMcpSignIn(signIn);
|
|
173
|
+
if (authorization.kind === "authorized")
|
|
434
174
|
return;
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
await
|
|
443
|
-
}
|
|
444
|
-
catch (error) {
|
|
445
|
-
// Aborted requests fail with the signal's reason; report them as the cancellation they are.
|
|
446
|
-
if (signal?.aborted)
|
|
447
|
-
throw new McpSignInCancelledError();
|
|
448
|
-
throw error;
|
|
175
|
+
prompt.showAuthorizationUrl(new URL(authorization.authorizationUrl));
|
|
176
|
+
const response = await waitForLoopbackSignIn({
|
|
177
|
+
callback,
|
|
178
|
+
authorization,
|
|
179
|
+
promptForRedirectUrl: (promptSignal) => prompt.promptForRedirectUrl(promptSignal),
|
|
180
|
+
signal,
|
|
181
|
+
});
|
|
182
|
+
await completeMcpSignIn({ ...signIn, authorization, response });
|
|
449
183
|
}
|
|
450
184
|
finally {
|
|
451
185
|
await callback.close();
|