@humain/terminal 0.0.2 → 0.0.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +241 -24
- package/README.md +143 -119
- package/dist/cli/args.d.ts +4 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +37 -39
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-check.d.ts +19 -0
- package/dist/cli/auth-check.d.ts.map +1 -0
- package/dist/cli/auth-check.js +50 -0
- package/dist/cli/auth-check.js.map +1 -0
- package/dist/cli/auth-command.d.ts +24 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +103 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +2 -2
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +5 -15
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +42 -83
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/experimental/auth.d.ts +16 -0
- package/dist/cli/experimental/auth.d.ts.map +1 -0
- package/dist/cli/experimental/auth.js +13 -0
- package/dist/cli/experimental/auth.js.map +1 -0
- package/dist/cli/experimental/cli.d.ts +6 -0
- package/dist/cli/experimental/cli.d.ts.map +1 -0
- package/dist/cli/experimental/cli.js +5 -0
- package/dist/cli/experimental/cli.js.map +1 -0
- package/dist/cli/experimental/command-options.d.ts +17 -0
- package/dist/cli/experimental/command-options.d.ts.map +1 -0
- package/dist/cli/experimental/command-options.js +35 -0
- package/dist/cli/experimental/command-options.js.map +1 -0
- package/dist/cli/experimental/command.d.ts +63 -0
- package/dist/cli/experimental/command.d.ts.map +1 -0
- package/dist/cli/experimental/command.js +130 -0
- package/dist/cli/experimental/command.js.map +1 -0
- package/dist/cli/experimental/commands/client.d.ts +13 -0
- package/dist/cli/experimental/commands/client.d.ts.map +1 -0
- package/dist/cli/experimental/commands/client.js +25 -0
- package/dist/cli/experimental/commands/client.js.map +1 -0
- package/dist/cli/experimental/commands/pi.d.ts +15 -0
- package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
- package/dist/cli/experimental/commands/pi.js +28 -0
- package/dist/cli/experimental/commands/pi.js.map +1 -0
- package/dist/cli/experimental/commands/server.d.ts +13 -0
- package/dist/cli/experimental/commands/server.d.ts.map +1 -0
- package/dist/cli/experimental/commands/server.js +25 -0
- package/dist/cli/experimental/commands/server.js.map +1 -0
- package/dist/cli/experimental/transport-address.d.ts +10 -0
- package/dist/cli/experimental/transport-address.d.ts.map +1 -0
- package/dist/cli/experimental/transport-address.js +38 -0
- package/dist/cli/experimental/transport-address.js.map +1 -0
- package/dist/cli/list-models.d.ts +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +2 -2
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +2 -2
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/remote-session.d.ts +53 -0
- package/dist/client/remote-session.d.ts.map +1 -0
- package/dist/client/remote-session.js +340 -0
- package/dist/client/remote-session.js.map +1 -0
- package/dist/client/transcript.d.ts +12 -0
- package/dist/client/transcript.d.ts.map +1 -0
- package/dist/client/transcript.js +98 -0
- package/dist/client/transcript.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -10
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +72 -70
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +25 -9
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +237 -39
- package/dist/core/auth-storage.js.map +1 -1
- 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 +60 -41
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +27 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +5 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts +45 -5
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +29 -5
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +4 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -3
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -10
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +4 -3
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +42 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +30 -13
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +233 -73
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts +12 -7
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +83 -14
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts +6 -3
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +80 -61
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts +8 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +28 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/provider-composer.d.ts +4 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +36 -15
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +73 -67
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +5 -5
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +11 -8
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +3 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +12 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +40 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +5 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -15
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +4 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +11 -7
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +7 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +16 -19
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +4 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +5 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +4 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +5 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +7 -3
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +4 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +6 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +11 -2
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +21 -7
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/humain/agent-execution-protocol.d.ts +218 -0
- package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
- package/dist/humain/agent-execution-protocol.js +204 -0
- package/dist/humain/agent-execution-protocol.js.map +1 -0
- package/dist/humain/agent-execution-runtime.d.ts +35 -0
- package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
- package/dist/humain/agent-execution-runtime.js +170 -0
- package/dist/humain/agent-execution-runtime.js.map +1 -0
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +8 -7
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +660 -0
- package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/dist/humain/mcp-adapter/vendor/README.md +733 -0
- package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
- package/dist/humain/mcp-adapter/vendor/agent-dir.ts +60 -0
- package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
- package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
- package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
- package/dist/humain/mcp-adapter/vendor/cli.js +209 -0
- package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
- package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
- package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +604 -0
- package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
- package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
- package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
- package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
- package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +15923 -0
- package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
- package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
- package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
- package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
- package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
- package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
- package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
- package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
- package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
- package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +666 -0
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
- package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +353 -0
- package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
- package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
- package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
- package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
- package/dist/humain/mcp-adapter/vendor/package.json +178 -0
- package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
- package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
- package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
- package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
- package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
- package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +1124 -0
- package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
- package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
- package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
- package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +276 -0
- package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
- package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
- package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
- package/dist/humain/mcp-adapter/vendor/types.ts +859 -0
- package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
- package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
- package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
- package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
- package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
- package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
- package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
- package/dist/humain/mcp-adapter.d.ts +3 -0
- package/dist/humain/mcp-adapter.d.ts.map +1 -0
- package/dist/humain/mcp-adapter.js +5 -0
- package/dist/humain/mcp-adapter.js.map +1 -0
- package/dist/humain/pi-agent-execution-host.d.ts +34 -0
- package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
- package/dist/humain/pi-agent-execution-host.js +77 -0
- package/dist/humain/pi-agent-execution-host.js.map +1 -0
- package/dist/humain/web-access/host.d.ts +4 -0
- package/dist/humain/web-access/host.d.ts.map +1 -0
- package/dist/humain/web-access/host.js +3 -0
- package/dist/humain/web-access/host.js.map +1 -0
- package/dist/humain/web-access/index.d.ts +3 -0
- package/dist/humain/web-access/index.d.ts.map +1 -0
- package/dist/humain/web-access/index.js +5 -0
- package/dist/humain/web-access/index.js.map +1 -0
- package/dist/humain/web-access/vendor/activity.d.ts +34 -0
- package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/activity.js +68 -0
- package/dist/humain/web-access/vendor/activity.js.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.js +167 -0
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
- package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/bocha.js +219 -0
- package/dist/humain/web-access/vendor/bocha.js.map +1 -0
- package/dist/humain/web-access/vendor/brave.d.ts +4 -0
- package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brave.js +194 -0
- package/dist/humain/web-access/vendor/brave.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.js +519 -0
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts +10 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js +438 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
- package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
- package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/content-find.js +117 -0
- package/dist/humain/web-access/vendor/content-find.js.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.js +151 -0
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts +29 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.js +3554 -0
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +93 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.js +688 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
- package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
- package/dist/humain/web-access/vendor/exa.d.ts +10 -0
- package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/exa.js +426 -0
- package/dist/humain/web-access/vendor/exa.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts +46 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/extract.js +1064 -0
- package/dist/humain/web-access/vendor/extract.js.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.js +27 -0
- package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts +25 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.js +57 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts +12 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.js +239 -0
- package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.js +230 -0
- package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.js +814 -0
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.js +385 -0
- package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
- package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
- package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-api.js +160 -0
- package/dist/humain/web-access/vendor/github-api.js.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.js +635 -0
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/index.d.ts +4 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/index.js +3002 -0
- package/dist/humain/web-access/vendor/index.js.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.js +255 -0
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
- package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/kagi.js +262 -0
- package/dist/humain/web-access/vendor/kagi.js.map +1 -0
- package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ollama.js +216 -0
- package/dist/humain/web-access/vendor/ollama.js.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.js +459 -0
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/page-query.js +79 -0
- package/dist/humain/web-access/vendor/page-query.js.map +1 -0
- package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
- package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/parallel.js +343 -0
- package/dist/humain/web-access/vendor/parallel.js.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
- package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.js +159 -0
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
- package/dist/humain/web-access/vendor/querit.d.ts +10 -0
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/querit.js +335 -0
- package/dist/humain/web-access/vendor/querit.js.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.js +130 -0
- package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
- package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/search1api.js +251 -0
- package/dist/humain/web-access/vendor/search1api.js.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
- package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
- package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searxng.js +238 -0
- package/dist/humain/web-access/vendor/searxng.js.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.js +211 -0
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.js +267 -0
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
- package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
- package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/source-check.js +205 -0
- package/dist/humain/web-access/vendor/source-check.js.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
- package/dist/humain/web-access/vendor/storage.d.ts +55 -0
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/storage.js +485 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts +24 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.js +341 -0
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
- package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
- package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tavily.js +194 -0
- package/dist/humain/web-access/vendor/tavily.js.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.js +331 -0
- package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
- package/dist/humain/web-access/vendor/utils.d.ts +20 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/utils.js +91 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.js +335 -0
- package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.js +331 -0
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
- package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +169 -102
- package/dist/main.js.map +1 -1
- package/dist/modes/agent-exec-mode.d.ts +14 -0
- package/dist/modes/agent-exec-mode.d.ts.map +1 -0
- package/dist/modes/agent-exec-mode.js +92 -0
- package/dist/modes/agent-exec-mode.js.map +1 -0
- package/dist/modes/index.d.ts +4 -2
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +2 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -4
- package/dist/modes/interactive/components/assistant-message.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/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +75 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +30 -0
- package/dist/modes/interactive/components/settings-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 +9 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +45 -9
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +581 -211
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -0
- package/dist/modes/interactive/theme/light.json +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +10 -1
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +5 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +24 -6
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +28 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +12 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +12 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +12 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +55 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +13 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +11 -9
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js +3 -2
- package/dist/rpc-entry.js.map +1 -1
- package/dist/server/create-harness.d.ts +26 -0
- package/dist/server/create-harness.d.ts.map +1 -0
- package/dist/server/create-harness.js +104 -0
- package/dist/server/create-harness.js.map +1 -0
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +48 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +22 -2
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/management-http.d.ts +23 -0
- package/dist/utils/management-http.d.ts.map +1 -0
- package/dist/utils/management-http.js +50 -0
- package/dist/utils/management-http.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +23 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +19 -0
- package/dist/utils/tool-result-images.d.ts.map +1 -0
- package/dist/utils/tool-result-images.js +45 -0
- package/dist/utils/tool-result-images.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +13 -25
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +4 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +23 -5
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +2 -2
- package/docs/custom-provider.md +7 -5
- package/docs/extensions.md +30 -5
- package/docs/humain-terminal.md +21 -1
- package/docs/json.md +24 -19
- package/docs/keybindings.md +46 -14
- package/docs/models.md +32 -11
- package/docs/providers.md +9 -1
- package/docs/quickstart.md +39 -37
- package/docs/rpc.md +31 -11
- package/docs/sdk.md +21 -2
- package/docs/security.md +21 -21
- package/docs/session-format.md +14 -14
- package/docs/settings.md +4 -1
- package/docs/themes.md +5 -3
- package/docs/usage.md +7 -0
- package/examples/extensions/custom-compaction.ts +3 -18
- package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +4 -13
- package/examples/extensions/qna.ts +5 -9
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +9 -20
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +11 -2
- package/examples/sdk/02-custom-model.ts +2 -3
- package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +2771 -535
- package/package.json +40 -11
- package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
- package/src/humain/mcp-adapter/upstream.json +7 -0
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +660 -0
- package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/src/humain/web-access/UPSTREAM.md +17 -0
- package/src/humain/web-access/upstream.json +23 -0
- package/src/humain/web-access/vendor/LICENSE +21 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP OAuth Provider
|
|
3
|
+
*
|
|
4
|
+
* Implementation of the MCP SDK's OAuthClientProvider interface.
|
|
5
|
+
* Handles OAuth client registration, token storage, and authorization redirection.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
UnauthorizedError,
|
|
10
|
+
type AddClientAuthentication,
|
|
11
|
+
type OAuthClientProvider,
|
|
12
|
+
type OAuthDiscoveryState,
|
|
13
|
+
} from "@modelcontextprotocol/client"
|
|
14
|
+
import type {
|
|
15
|
+
OAuthClientInformationMixed,
|
|
16
|
+
OAuthClientMetadata,
|
|
17
|
+
OAuthTokens,
|
|
18
|
+
} from "@modelcontextprotocol/client"
|
|
19
|
+
import {
|
|
20
|
+
getAuthForUrl,
|
|
21
|
+
updateTokens,
|
|
22
|
+
updateClientInfo,
|
|
23
|
+
clearAllCredentials,
|
|
24
|
+
clearClientInfo,
|
|
25
|
+
clearCodeVerifier,
|
|
26
|
+
clearTokens,
|
|
27
|
+
type AuthEntry,
|
|
28
|
+
type AuthStorageOptions,
|
|
29
|
+
type StoredTokens,
|
|
30
|
+
type StoredClientInfo,
|
|
31
|
+
} from "./mcp-auth.ts"
|
|
32
|
+
import { resolveCommandSecret } from "./utils.ts"
|
|
33
|
+
import { getAppClientUri, getAppName } from "./agent-dir.ts"
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Client name advertised during Dynamic Client Registration.
|
|
37
|
+
*
|
|
38
|
+
* A distribution that rebrands pi (arc, tau, …) should register under its own
|
|
39
|
+
* name — otherwise every consent screen its users see asks them to authorize
|
|
40
|
+
* an app they have never run. Stock pi keeps the long-standing
|
|
41
|
+
* "Pi Coding Agent" so existing registrations are unaffected.
|
|
42
|
+
*/
|
|
43
|
+
function defaultClientName(): string {
|
|
44
|
+
const app = getAppName()
|
|
45
|
+
return app === "pi" ? "Pi Coding Agent" : app
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Client homepage advertised during Dynamic Client Registration.
|
|
50
|
+
*
|
|
51
|
+
* RFC 7591 defines client_uri as the home page *of the client*. Under a
|
|
52
|
+
* rebranded pi the client is that distribution, not this adapter, so pointing
|
|
53
|
+
* at the adapter's repository misidentifies it on the consent screen. There is
|
|
54
|
+
* no way to guess the right URL and a wrong one is worse than none, so the
|
|
55
|
+
* field is omitted unless a server config supplies oauth.clientUri.
|
|
56
|
+
*
|
|
57
|
+
* Stock pi keeps the historical value.
|
|
58
|
+
*/
|
|
59
|
+
function defaultClientUri(): string | undefined {
|
|
60
|
+
const declared = getAppClientUri()
|
|
61
|
+
if (declared) return declared
|
|
62
|
+
return getAppName() === "pi" ? "https://github.com/nicobailon/pi-mcp-adapter" : undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type IssuerBoundClientInformation = OAuthClientInformationMixed & { issuer?: string }
|
|
66
|
+
type IssuerBoundTokens = OAuthTokens & { issuer?: string }
|
|
67
|
+
|
|
68
|
+
function issuersMatch(first: string, second: string): boolean {
|
|
69
|
+
return first === second
|
|
70
|
+
|| (first.endsWith("/") && first.slice(0, -1) === second)
|
|
71
|
+
|| (second.endsWith("/") && second.slice(0, -1) === first)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Callback server configuration
|
|
75
|
+
const DEFAULT_OAUTH_CALLBACK_PORT = 19876
|
|
76
|
+
const DEFAULT_OAUTH_CALLBACK_PATH = "/callback"
|
|
77
|
+
|
|
78
|
+
let configuredOAuthCallbackPort = DEFAULT_OAUTH_CALLBACK_PORT
|
|
79
|
+
|
|
80
|
+
if (process.env.MCP_OAUTH_CALLBACK_PORT) {
|
|
81
|
+
const parsedPort = Number.parseInt(process.env.MCP_OAUTH_CALLBACK_PORT, 10)
|
|
82
|
+
if (Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535) {
|
|
83
|
+
configuredOAuthCallbackPort = parsedPort
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let oauthCallbackPort = configuredOAuthCallbackPort
|
|
88
|
+
let oauthCallbackPath = DEFAULT_OAUTH_CALLBACK_PATH
|
|
89
|
+
|
|
90
|
+
export function getConfiguredOAuthCallbackPort(): number {
|
|
91
|
+
return configuredOAuthCallbackPort
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function getOAuthCallbackPort(): number {
|
|
95
|
+
return oauthCallbackPort
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function setOAuthCallbackPort(port: number): void {
|
|
99
|
+
oauthCallbackPort = port
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getOAuthCallbackPath(): string {
|
|
103
|
+
return oauthCallbackPath
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function setOAuthCallbackPath(path: string): void {
|
|
107
|
+
oauthCallbackPath = path.startsWith("/") ? path : `/${path}`
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Configuration options for OAuth */
|
|
111
|
+
export interface McpOAuthConfig {
|
|
112
|
+
grantType?: "authorization_code" | "client_credentials"
|
|
113
|
+
clientId?: string
|
|
114
|
+
clientSecret?: string
|
|
115
|
+
scope?: string
|
|
116
|
+
authorizationParams?: Record<string, string>
|
|
117
|
+
redirectUri?: string
|
|
118
|
+
clientName?: string
|
|
119
|
+
clientUri?: string
|
|
120
|
+
logoUri?: string
|
|
121
|
+
skipIssuerMetadataValidation?: boolean
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const reservedAuthorizationParams = new Set([
|
|
125
|
+
"client_id",
|
|
126
|
+
"code_challenge",
|
|
127
|
+
"code_challenge_method",
|
|
128
|
+
"redirect_uri",
|
|
129
|
+
"resource",
|
|
130
|
+
"response_type",
|
|
131
|
+
"scope",
|
|
132
|
+
"state",
|
|
133
|
+
])
|
|
134
|
+
|
|
135
|
+
function addAuthorizationParams(authorizationUrl: URL, params: Record<string, string> | undefined): URL {
|
|
136
|
+
if (!params) return authorizationUrl
|
|
137
|
+
const nextUrl = new URL(authorizationUrl.toString())
|
|
138
|
+
for (const [key, value] of Object.entries(params)) {
|
|
139
|
+
if (reservedAuthorizationParams.has(key) || nextUrl.searchParams.has(key)) {
|
|
140
|
+
throw new Error(`OAuth authorizationParams.${key} cannot override an authorization flow parameter`)
|
|
141
|
+
}
|
|
142
|
+
nextUrl.searchParams.set(key, value)
|
|
143
|
+
}
|
|
144
|
+
return nextUrl
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Callbacks for OAuth flow interactions */
|
|
148
|
+
export interface McpOAuthCallbacks {
|
|
149
|
+
onRedirect: (url: URL) => void | Promise<void>
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* OAuth provider implementation for MCP servers.
|
|
154
|
+
* Implements the OAuthClientProvider interface from the MCP SDK.
|
|
155
|
+
*/
|
|
156
|
+
export class McpOAuthProvider implements OAuthClientProvider {
|
|
157
|
+
private readonly redirectUrlSnapshot: string | undefined
|
|
158
|
+
private active = true
|
|
159
|
+
private flowClientInfo: StoredClientInfo | undefined
|
|
160
|
+
private flowCodeVerifier: string | undefined
|
|
161
|
+
private flowDiscoveryState: OAuthDiscoveryState | undefined
|
|
162
|
+
private flowIssuerMismatch = false
|
|
163
|
+
private flowState: string | undefined
|
|
164
|
+
|
|
165
|
+
constructor(
|
|
166
|
+
private serverName: string,
|
|
167
|
+
private serverUrl: string,
|
|
168
|
+
private config: McpOAuthConfig,
|
|
169
|
+
private callbacks: McpOAuthCallbacks,
|
|
170
|
+
private storageOptions: AuthStorageOptions = {},
|
|
171
|
+
private runtimeSignal?: AbortSignal,
|
|
172
|
+
initialState?: string,
|
|
173
|
+
) {
|
|
174
|
+
this.flowState = initialState
|
|
175
|
+
this.redirectUrlSnapshot = config.grantType === "client_credentials"
|
|
176
|
+
? undefined
|
|
177
|
+
: config.redirectUri ?? `http://localhost:${getOAuthCallbackPort()}${getOAuthCallbackPath()}`
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private get usesClientCredentials(): boolean {
|
|
181
|
+
return this.config.grantType === "client_credentials"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private get discoveredIssuer(): string | undefined {
|
|
185
|
+
return this.flowDiscoveryState?.authorizationServerMetadata?.issuer
|
|
186
|
+
?? this.flowDiscoveryState?.authorizationServerUrl
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
deactivate(): void {
|
|
190
|
+
this.active = false
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private assertStoredIssuerBindings(entry: AuthEntry | undefined, issuer: string | undefined): void {
|
|
194
|
+
if (this.flowIssuerMismatch) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`OAuth authorization server issuer changed for ${this.serverName}; clear credentials before authenticating again`,
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
if (!entry || !issuer) return
|
|
200
|
+
|
|
201
|
+
const storedIssuers = [entry.clientInfo?.issuer, entry.tokens?.issuer]
|
|
202
|
+
.filter((storedIssuer): storedIssuer is string => storedIssuer !== undefined)
|
|
203
|
+
if (storedIssuers.some(storedIssuer => !issuersMatch(storedIssuer, issuer))) {
|
|
204
|
+
this.flowIssuerMismatch = true
|
|
205
|
+
throw new Error(
|
|
206
|
+
`OAuth authorization server issuer changed for ${this.serverName}; clear credentials before authenticating again`,
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private throwIfInactive(): void {
|
|
212
|
+
if (!this.active) throw new Error("OAuth flow is no longer active")
|
|
213
|
+
this.runtimeSignal?.throwIfAborted()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The redirect URL for OAuth callbacks.
|
|
218
|
+
* This must match the redirect_uri in client metadata.
|
|
219
|
+
*/
|
|
220
|
+
get redirectUrl(): string | undefined {
|
|
221
|
+
return this.redirectUrlSnapshot
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Configured homepage, else the historical default on stock pi, else nothing. */
|
|
225
|
+
private get clientUri(): string | undefined {
|
|
226
|
+
return this.config.clientUri ?? defaultClientUri()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Client metadata for dynamic registration.
|
|
231
|
+
* Describes this client to the OAuth authorization server.
|
|
232
|
+
*/
|
|
233
|
+
get clientMetadata(): OAuthClientMetadata {
|
|
234
|
+
if (this.usesClientCredentials) {
|
|
235
|
+
return {
|
|
236
|
+
client_name: this.config.clientName ?? defaultClientName(),
|
|
237
|
+
...(this.clientUri !== undefined ? { client_uri: this.clientUri } : {}),
|
|
238
|
+
...(this.config.logoUri !== undefined ? { logo_uri: this.config.logoUri } : {}),
|
|
239
|
+
redirect_uris: [],
|
|
240
|
+
grant_types: ["client_credentials"],
|
|
241
|
+
token_endpoint_auth_method: this.config.clientSecret ? "client_secret_post" : "none",
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const redirectUrl = this.redirectUrl
|
|
246
|
+
if (!redirectUrl) {
|
|
247
|
+
throw new Error("redirectUrl is required for authorization_code flow")
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
redirect_uris: [redirectUrl],
|
|
252
|
+
client_name: this.config.clientName ?? defaultClientName(),
|
|
253
|
+
...(this.clientUri !== undefined ? { client_uri: this.clientUri } : {}),
|
|
254
|
+
...(this.config.logoUri !== undefined ? { logo_uri: this.config.logoUri } : {}),
|
|
255
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
256
|
+
response_types: ["code"],
|
|
257
|
+
token_endpoint_auth_method: this.config.clientSecret ? "client_secret_post" : "none",
|
|
258
|
+
...(this.config.scope !== undefined ? { scope: this.config.scope } : {}),
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Get client information (for pre-registered or dynamically registered clients).
|
|
264
|
+
* Returns undefined if no client info exists or if the server URL has changed.
|
|
265
|
+
*/
|
|
266
|
+
async clientInformation(): Promise<OAuthClientInformationMixed | undefined> {
|
|
267
|
+
const issuer = this.discoveredIssuer
|
|
268
|
+
const stored = await getAuthForUrl(this.serverName, this.serverUrl, this.storageOptions)
|
|
269
|
+
this.assertStoredIssuerBindings(stored, issuer)
|
|
270
|
+
|
|
271
|
+
// Check config first (pre-registered client). Store only its issuer binding.
|
|
272
|
+
// The configured secret stays in config and never enters the credential store.
|
|
273
|
+
if (this.config.clientId) {
|
|
274
|
+
const storedClient = stored?.clientInfo?.clientId === this.config.clientId
|
|
275
|
+
? stored.clientInfo
|
|
276
|
+
: undefined
|
|
277
|
+
if (issuer && (storedClient?.issuer !== issuer || storedClient.configPreRegistered !== true)) {
|
|
278
|
+
updateClientInfo(
|
|
279
|
+
this.serverName,
|
|
280
|
+
{ clientId: this.config.clientId, issuer, configPreRegistered: true },
|
|
281
|
+
this.serverUrl,
|
|
282
|
+
this.storageOptions,
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
const clientSecret = this.config.clientSecret?.startsWith("!")
|
|
286
|
+
? resolveCommandSecret(
|
|
287
|
+
this.config.clientSecret,
|
|
288
|
+
`MCP server "${this.serverName}" OAuth clientSecret`,
|
|
289
|
+
)
|
|
290
|
+
: this.config.clientSecret
|
|
291
|
+
return {
|
|
292
|
+
client_id: this.config.clientId,
|
|
293
|
+
client_secret: clientSecret,
|
|
294
|
+
...(issuer !== undefined ? { issuer } : {}),
|
|
295
|
+
} as IssuerBoundClientInformation
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Keep client registration associated with this in-flight flow even if
|
|
299
|
+
// another runtime writes the shared persistent entry for the same name.
|
|
300
|
+
const clientInfo = this.flowClientInfo ?? stored?.clientInfo
|
|
301
|
+
if (clientInfo) {
|
|
302
|
+
// A stored SEP-2352 issuer stub for a config-pre-registered client
|
|
303
|
+
// (identified by the explicit marker, or by the legacy stub shape of
|
|
304
|
+
// {clientId, issuer} with no registration metadata) is only meaningful
|
|
305
|
+
// when the config supplies the matching client secret. Since we reach
|
|
306
|
+
// this branch only when config.clientId is absent, serving the stub
|
|
307
|
+
// would let a token refresh go out with a client_id but no secret,
|
|
308
|
+
// causing invalid_client and credential invalidation. Return undefined
|
|
309
|
+
// so callers treat this as "no client info".
|
|
310
|
+
const isConfigStub = clientInfo.configPreRegistered === true
|
|
311
|
+
|| (clientInfo.clientSecret === undefined
|
|
312
|
+
&& clientInfo.clientIdIssuedAt === undefined
|
|
313
|
+
&& clientInfo.clientSecretExpiresAt === undefined
|
|
314
|
+
&& clientInfo.redirectUris === undefined)
|
|
315
|
+
if (isConfigStub) {
|
|
316
|
+
return undefined
|
|
317
|
+
}
|
|
318
|
+
// Check if client secret has expired
|
|
319
|
+
if (clientInfo.clientSecretExpiresAt && clientInfo.clientSecretExpiresAt < Date.now() / 1000) {
|
|
320
|
+
return undefined
|
|
321
|
+
}
|
|
322
|
+
if (issuer && clientInfo.issuer && !issuersMatch(clientInfo.issuer, issuer)) {
|
|
323
|
+
return undefined
|
|
324
|
+
}
|
|
325
|
+
if (issuer && clientInfo.issuer === undefined) {
|
|
326
|
+
clientInfo.issuer = issuer
|
|
327
|
+
this.flowClientInfo = clientInfo
|
|
328
|
+
updateClientInfo(this.serverName, clientInfo, this.serverUrl, this.storageOptions)
|
|
329
|
+
}
|
|
330
|
+
// Return all registration metadata and the local issuer extension.
|
|
331
|
+
// This keeps the SDK OAuth view and the stored issuer binding consistent.
|
|
332
|
+
return {
|
|
333
|
+
client_id: clientInfo.clientId,
|
|
334
|
+
client_secret: clientInfo.clientSecret,
|
|
335
|
+
...(clientInfo.clientIdIssuedAt !== undefined
|
|
336
|
+
? { client_id_issued_at: clientInfo.clientIdIssuedAt }
|
|
337
|
+
: {}),
|
|
338
|
+
...(clientInfo.clientSecretExpiresAt !== undefined
|
|
339
|
+
? { client_secret_expires_at: clientInfo.clientSecretExpiresAt }
|
|
340
|
+
: {}),
|
|
341
|
+
...(clientInfo.redirectUris !== undefined
|
|
342
|
+
? { redirect_uris: clientInfo.redirectUris }
|
|
343
|
+
: {}),
|
|
344
|
+
...(clientInfo.issuer !== undefined ? { issuer: clientInfo.issuer } : {}),
|
|
345
|
+
} as IssuerBoundClientInformation
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// No client info or URL changed - will trigger dynamic registration
|
|
349
|
+
return undefined
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Save client information from dynamic registration.
|
|
354
|
+
*/
|
|
355
|
+
async saveClientInformation(info: OAuthClientInformationMixed): Promise<void> {
|
|
356
|
+
this.throwIfInactive()
|
|
357
|
+
const issuer = this.discoveredIssuer ?? (info as IssuerBoundClientInformation).issuer
|
|
358
|
+
if (this.config.clientId && info.client_id === this.config.clientId) {
|
|
359
|
+
updateClientInfo(
|
|
360
|
+
this.serverName,
|
|
361
|
+
{
|
|
362
|
+
clientId: info.client_id,
|
|
363
|
+
...(issuer !== undefined ? { issuer } : {}),
|
|
364
|
+
configPreRegistered: true,
|
|
365
|
+
},
|
|
366
|
+
this.serverUrl,
|
|
367
|
+
this.storageOptions,
|
|
368
|
+
)
|
|
369
|
+
return
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const redirectUris = ("redirect_uris" in info ? info.redirect_uris : undefined)
|
|
373
|
+
?? (this.redirectUrl ? [this.redirectUrl] : undefined)
|
|
374
|
+
const clientInfo: StoredClientInfo = {
|
|
375
|
+
clientId: info.client_id,
|
|
376
|
+
...(info.client_secret !== undefined ? { clientSecret: info.client_secret } : {}),
|
|
377
|
+
...(info.client_id_issued_at !== undefined ? { clientIdIssuedAt: info.client_id_issued_at } : {}),
|
|
378
|
+
...(info.client_secret_expires_at !== undefined ? { clientSecretExpiresAt: info.client_secret_expires_at } : {}),
|
|
379
|
+
...(redirectUris !== undefined ? { redirectUris } : {}),
|
|
380
|
+
...(issuer !== undefined ? { issuer } : {}),
|
|
381
|
+
}
|
|
382
|
+
this.flowClientInfo = clientInfo
|
|
383
|
+
updateClientInfo(this.serverName, clientInfo, this.serverUrl, this.storageOptions)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Get stored OAuth tokens.
|
|
388
|
+
* Returns undefined if no tokens exist or if the server URL has changed.
|
|
389
|
+
*/
|
|
390
|
+
async tokens(): Promise<OAuthTokens | undefined> {
|
|
391
|
+
// Use getAuthForUrl to validate tokens are for the current server URL.
|
|
392
|
+
const entry = await getAuthForUrl(this.serverName, this.serverUrl, this.storageOptions)
|
|
393
|
+
if (!entry?.tokens) return undefined
|
|
394
|
+
const issuer = this.discoveredIssuer
|
|
395
|
+
this.assertStoredIssuerBindings(entry, issuer)
|
|
396
|
+
if (issuer && entry.tokens.issuer === undefined) {
|
|
397
|
+
entry.tokens.issuer = issuer
|
|
398
|
+
updateTokens(this.serverName, entry.tokens, this.serverUrl, this.storageOptions)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return {
|
|
402
|
+
access_token: entry.tokens.accessToken,
|
|
403
|
+
token_type: "Bearer",
|
|
404
|
+
refresh_token: entry.tokens.refreshToken,
|
|
405
|
+
expires_in: entry.tokens.expiresAt
|
|
406
|
+
? Math.max(0, Math.floor(entry.tokens.expiresAt - Date.now() / 1000))
|
|
407
|
+
: undefined,
|
|
408
|
+
scope: entry.tokens.scope,
|
|
409
|
+
...(entry.tokens.issuer !== undefined ? { issuer: entry.tokens.issuer } : {}),
|
|
410
|
+
} as IssuerBoundTokens
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Save OAuth tokens.
|
|
415
|
+
*/
|
|
416
|
+
async saveTokens(tokens: OAuthTokens): Promise<void> {
|
|
417
|
+
const issuer = this.discoveredIssuer ?? (tokens as IssuerBoundTokens).issuer
|
|
418
|
+
const storedTokens: StoredTokens = {
|
|
419
|
+
accessToken: tokens.access_token,
|
|
420
|
+
...(tokens.refresh_token !== undefined ? { refreshToken: tokens.refresh_token } : {}),
|
|
421
|
+
// Preserve expiry even when expires_in is 0 (e.g. the SDK re-saving an
|
|
422
|
+
// already-expired token) so expired tokens stay expired instead of
|
|
423
|
+
// being persisted as never-expiring.
|
|
424
|
+
...(tokens.expires_in !== undefined ? { expiresAt: Date.now() / 1000 + tokens.expires_in } : {}),
|
|
425
|
+
...(tokens.scope !== undefined ? { scope: tokens.scope } : {}),
|
|
426
|
+
...(issuer !== undefined ? { issuer } : {}),
|
|
427
|
+
}
|
|
428
|
+
this.throwIfInactive()
|
|
429
|
+
updateTokens(this.serverName, storedTokens, this.serverUrl, this.storageOptions)
|
|
430
|
+
// Discovery must survive the browser redirect so the callback can verify
|
|
431
|
+
// the authorization server that minted the code. Once token issuance
|
|
432
|
+
// succeeds, clear it so a later 401 re-reads PRM and can observe an
|
|
433
|
+
// authorization-server migration.
|
|
434
|
+
this.flowDiscoveryState = undefined
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Redirect the user to the authorization URL.
|
|
439
|
+
* This opens the browser for the user to authenticate.
|
|
440
|
+
*
|
|
441
|
+
* Throws UnauthorizedError when called outside of a user-initiated flow
|
|
442
|
+
* (no oauthState saved by startAuth). That path is reached when the SDK
|
|
443
|
+
* falls through from a failed refresh into a fresh authorization_code
|
|
444
|
+
* flow, which library hosts cannot complete in-process.
|
|
445
|
+
*/
|
|
446
|
+
async redirectToAuthorization(authorizationUrl: URL): Promise<void> {
|
|
447
|
+
if (this.usesClientCredentials) {
|
|
448
|
+
throw new Error("redirectToAuthorization is not used for client_credentials flow")
|
|
449
|
+
}
|
|
450
|
+
// No flow-local state means we're on the post-refresh authorize fallback.
|
|
451
|
+
this.throwIfInactive()
|
|
452
|
+
if (!this.flowState) {
|
|
453
|
+
throw new UnauthorizedError(
|
|
454
|
+
`Re-authentication required for MCP server: ${this.serverName}`,
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
// URL is passed to callback, not logged (may contain sensitive params)
|
|
458
|
+
await this.callbacks.onRedirect(addAuthorizationParams(authorizationUrl, this.config.authorizationParams))
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Save the PKCE code verifier.
|
|
463
|
+
*/
|
|
464
|
+
async saveCodeVerifier(codeVerifier: string): Promise<void> {
|
|
465
|
+
this.throwIfInactive()
|
|
466
|
+
this.flowCodeVerifier = codeVerifier
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Get the stored PKCE code verifier.
|
|
471
|
+
* @throws Error if no code verifier is stored
|
|
472
|
+
*/
|
|
473
|
+
async codeVerifier(): Promise<string> {
|
|
474
|
+
if (this.usesClientCredentials) {
|
|
475
|
+
throw new Error("codeVerifier is not used for client_credentials flow")
|
|
476
|
+
}
|
|
477
|
+
this.throwIfInactive()
|
|
478
|
+
if (!this.flowCodeVerifier) {
|
|
479
|
+
throw new Error(`No code verifier saved for MCP server: ${this.serverName}`)
|
|
480
|
+
}
|
|
481
|
+
return this.flowCodeVerifier
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Keep discovery with the in-flight PKCE verifier. The callback leg uses it
|
|
486
|
+
* to validate the authorization response issuer before token exchange.
|
|
487
|
+
*/
|
|
488
|
+
async saveDiscoveryState(state: OAuthDiscoveryState): Promise<void> {
|
|
489
|
+
this.throwIfInactive()
|
|
490
|
+
this.flowDiscoveryState = structuredClone(state)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
async discoveryState(): Promise<OAuthDiscoveryState | undefined> {
|
|
494
|
+
this.throwIfInactive()
|
|
495
|
+
return this.flowDiscoveryState ? structuredClone(this.flowDiscoveryState) : undefined
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Save the OAuth state parameter for CSRF protection.
|
|
500
|
+
*/
|
|
501
|
+
async saveState(state: string): Promise<void> {
|
|
502
|
+
this.throwIfInactive()
|
|
503
|
+
this.flowState = state
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Get the stored OAuth state parameter.
|
|
508
|
+
* @throws UnauthorizedError if no flow is in progress (see redirectToAuthorization)
|
|
509
|
+
*/
|
|
510
|
+
async state(): Promise<string> {
|
|
511
|
+
if (this.usesClientCredentials) {
|
|
512
|
+
throw new Error("state is not used for client_credentials flow")
|
|
513
|
+
}
|
|
514
|
+
this.throwIfInactive()
|
|
515
|
+
if (!this.flowState) {
|
|
516
|
+
throw new UnauthorizedError(
|
|
517
|
+
`Re-authentication required for MCP server: ${this.serverName}`,
|
|
518
|
+
)
|
|
519
|
+
}
|
|
520
|
+
return this.flowState
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Invalidate credentials when authentication fails.
|
|
525
|
+
* Clears tokens, client info, or all credentials based on the type.
|
|
526
|
+
*/
|
|
527
|
+
async invalidateCredentials(type: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void> {
|
|
528
|
+
this.throwIfInactive()
|
|
529
|
+
switch (type) {
|
|
530
|
+
case "all":
|
|
531
|
+
this.flowClientInfo = undefined
|
|
532
|
+
this.flowCodeVerifier = undefined
|
|
533
|
+
this.flowDiscoveryState = undefined
|
|
534
|
+
this.flowIssuerMismatch = false
|
|
535
|
+
this.flowState = undefined
|
|
536
|
+
clearAllCredentials(this.serverName, this.storageOptions)
|
|
537
|
+
break
|
|
538
|
+
case "client":
|
|
539
|
+
this.flowClientInfo = undefined
|
|
540
|
+
clearClientInfo(this.serverName, this.storageOptions)
|
|
541
|
+
break
|
|
542
|
+
case "tokens":
|
|
543
|
+
clearTokens(this.serverName, this.storageOptions)
|
|
544
|
+
break
|
|
545
|
+
case "verifier":
|
|
546
|
+
clearCodeVerifier(this.serverName, this.storageOptions)
|
|
547
|
+
break
|
|
548
|
+
case "discovery":
|
|
549
|
+
this.flowDiscoveryState = undefined
|
|
550
|
+
break
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Adds configured authorization-code scope without replacing the SDK's
|
|
556
|
+
* default token endpoint authentication behavior.
|
|
557
|
+
*/
|
|
558
|
+
addClientAuthentication: AddClientAuthentication = async (headers, params, _url, metadata) => {
|
|
559
|
+
this.throwIfInactive()
|
|
560
|
+
if (params.get("grant_type") === "authorization_code" && !params.has("scope") && this.config.scope) {
|
|
561
|
+
params.set("scope", this.config.scope)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const clientInfo = await this.clientInformation()
|
|
565
|
+
this.throwIfInactive()
|
|
566
|
+
if (!clientInfo) {
|
|
567
|
+
return
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const supportedMethods = metadata?.token_endpoint_auth_methods_supported ?? []
|
|
571
|
+
const hasClientSecret = clientInfo.client_secret !== undefined
|
|
572
|
+
let authMethod: "client_secret_basic" | "client_secret_post" | "none"
|
|
573
|
+
|
|
574
|
+
if (supportedMethods.length === 0) {
|
|
575
|
+
authMethod = hasClientSecret ? "client_secret_post" : "none"
|
|
576
|
+
} else if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
|
|
577
|
+
authMethod = "client_secret_basic"
|
|
578
|
+
} else if (hasClientSecret && supportedMethods.includes("client_secret_post")) {
|
|
579
|
+
authMethod = "client_secret_post"
|
|
580
|
+
} else if (supportedMethods.includes("none")) {
|
|
581
|
+
authMethod = "none"
|
|
582
|
+
} else {
|
|
583
|
+
authMethod = hasClientSecret ? "client_secret_post" : "none"
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (authMethod === "client_secret_basic") {
|
|
587
|
+
if (!clientInfo.client_secret) {
|
|
588
|
+
throw new Error("client_secret_basic authentication requires a client_secret")
|
|
589
|
+
}
|
|
590
|
+
headers.set("Authorization", `Basic ${Buffer.from(`${clientInfo.client_id}:${clientInfo.client_secret}`).toString("base64")}`)
|
|
591
|
+
return
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (!params.has("client_id")) {
|
|
595
|
+
params.set("client_id", clientInfo.client_id)
|
|
596
|
+
}
|
|
597
|
+
if (authMethod === "client_secret_post" && clientInfo.client_secret && !params.has("client_secret")) {
|
|
598
|
+
params.set("client_secret", clientInfo.client_secret)
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
prepareTokenRequest(scope?: string): URLSearchParams | undefined {
|
|
603
|
+
if (!this.usesClientCredentials) {
|
|
604
|
+
return undefined
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const params = new URLSearchParams({ grant_type: "client_credentials" })
|
|
608
|
+
const requestedScope = scope ?? this.config.scope
|
|
609
|
+
if (requestedScope) {
|
|
610
|
+
params.set("scope", requestedScope)
|
|
611
|
+
}
|
|
612
|
+
return params
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export { DEFAULT_OAUTH_CALLBACK_PORT, DEFAULT_OAUTH_CALLBACK_PATH }
|