@humain/terminal 0.0.2 → 0.0.3-beta.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 +251 -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/config.d.ts.map +1 -1
- package/dist/config.js +4 -3
- package/dist/config.js.map +1 -1
- 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 +673 -0
- package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/dist/humain/mcp-adapter/vendor/README.md +736 -0
- package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
- package/dist/humain/mcp-adapter/vendor/agent-dir.ts +68 -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 +230 -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 +607 -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 +16279 -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 +667 -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 +363 -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 +179 -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/request-headers-command.ts +336 -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 +1129 -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 +296 -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 +942 -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/auth-fetch.d.ts +13 -0
- package/dist/humain/web-access/vendor/auth-fetch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/auth-fetch.js +134 -0
- package/dist/humain/web-access/vendor/auth-fetch.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 +23 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js +522 -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 +30 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.js +3556 -0
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +94 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.js +690 -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 +48 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/extract.js +1126 -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 +27 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.js +71 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts +19 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.js +370 -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 +832 -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 +3076 -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 +26 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.js +344 -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 +673 -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,866 @@
|
|
|
1
|
+
import http, { type IncomingMessage, type ServerResponse } from "node:http";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { buildAllowAttribute } from "./ui-app-bridge-helpers.ts";
|
|
6
|
+
import {
|
|
7
|
+
type CallToolRequest,
|
|
8
|
+
type CallToolResult,
|
|
9
|
+
} from "@modelcontextprotocol/client";
|
|
10
|
+
import { ContentBlockSchema } from "@modelcontextprotocol/core";
|
|
11
|
+
import type { ConsentManager } from "./consent-manager.ts";
|
|
12
|
+
import { ServerError, wrapError } from "./errors.ts";
|
|
13
|
+
import { formatAuthRequiredMessage } from "./utils.ts";
|
|
14
|
+
import { buildHostHtmlTemplate, buildCspMetaContent } from "./host-html-template.ts";
|
|
15
|
+
import { logger } from "./logger.ts";
|
|
16
|
+
import type { McpServerManager } from "./server-manager.ts";
|
|
17
|
+
import type { McpExtensionState } from "./state.ts";
|
|
18
|
+
import { SessionRecoveryAuthRequiredError, withSessionRecovery, type SessionRecoveryDeps } from "./session-recovery.ts";
|
|
19
|
+
import { ensureToolCallApproved, isToolCallApprovalRequired } from "./tool-approval.ts";
|
|
20
|
+
import { extractUiToolVisibility, isUiToolCallableByApp, isUiToolVisibleToModel } from "./ui-tool-visibility.ts";
|
|
21
|
+
import { resourceNameToToolName } from "./resource-tools.ts";
|
|
22
|
+
import {
|
|
23
|
+
createUiModelContextUpdate,
|
|
24
|
+
extractUiPromptText,
|
|
25
|
+
getVisualizationStreamEnvelope,
|
|
26
|
+
isServerDisabled,
|
|
27
|
+
type McpConfig,
|
|
28
|
+
type UiDisplayMode,
|
|
29
|
+
type UiDisplayModeRequest,
|
|
30
|
+
type UiDisplayModeResult,
|
|
31
|
+
type UiHostContext,
|
|
32
|
+
type UiMessageParams,
|
|
33
|
+
type UiModelContextParams,
|
|
34
|
+
type UiOpenLinkResult,
|
|
35
|
+
type UiProxyRequestBody,
|
|
36
|
+
type UiProxyResult,
|
|
37
|
+
type UiResourceContent,
|
|
38
|
+
type UiSessionMessages,
|
|
39
|
+
type UiStreamSummary,
|
|
40
|
+
} from "./types.ts";
|
|
41
|
+
|
|
42
|
+
const MAX_BODY_SIZE = 2 * 1024 * 1024;
|
|
43
|
+
const ABANDONED_GRACE_MS = 60_000;
|
|
44
|
+
const WATCHDOG_INTERVAL_MS = 5_000;
|
|
45
|
+
const MAX_EVENT_LOG = 128;
|
|
46
|
+
const MAX_CONTEXT_UPDATES = 20;
|
|
47
|
+
const MOSHI_DISCOVERY_PORT_START = 8377;
|
|
48
|
+
const MOSHI_DISCOVERY_PORT_END = 8396;
|
|
49
|
+
let nextMoshiDiscoveryPort = MOSHI_DISCOVERY_PORT_START;
|
|
50
|
+
|
|
51
|
+
export interface UiServerOptions {
|
|
52
|
+
serverName: string;
|
|
53
|
+
toolName: string;
|
|
54
|
+
toolArgs: Record<string, unknown>;
|
|
55
|
+
resource: UiResourceContent;
|
|
56
|
+
manager: McpServerManager;
|
|
57
|
+
/**
|
|
58
|
+
* Live extension config, used to re-read the server definition when
|
|
59
|
+
* recovering a terminated Streamable HTTP session (see
|
|
60
|
+
* session-recovery.ts). Optional so existing embedders/tests that don't
|
|
61
|
+
* need session recovery aren't forced to supply it; without it, proxied
|
|
62
|
+
* tool calls run without recovery (unchanged pre-existing behavior).
|
|
63
|
+
*/
|
|
64
|
+
config?: McpConfig;
|
|
65
|
+
/** Live state enables TUI approval prompts for iframe-originated tool calls. */
|
|
66
|
+
state?: McpExtensionState;
|
|
67
|
+
onNeedsAuth?: SessionRecoveryDeps["onNeedsAuth"];
|
|
68
|
+
consentManager: ConsentManager;
|
|
69
|
+
hostContext?: UiHostContext;
|
|
70
|
+
initialResultPromise?: Promise<CallToolResult>;
|
|
71
|
+
sessionToken?: string;
|
|
72
|
+
port?: number;
|
|
73
|
+
onMessage?: (params: UiMessageParams) => Promise<void> | void;
|
|
74
|
+
onContextUpdate?: (params: UiModelContextParams) => Promise<void> | void;
|
|
75
|
+
onComplete?: (reason: string) => void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface UiServerHandle {
|
|
79
|
+
url: string;
|
|
80
|
+
port: number;
|
|
81
|
+
sessionToken: string;
|
|
82
|
+
serverName: string;
|
|
83
|
+
toolName: string;
|
|
84
|
+
viewer?: "browser" | "glimpse" | "suppressed";
|
|
85
|
+
windowOpen?: boolean;
|
|
86
|
+
close: (reason?: string) => void;
|
|
87
|
+
sendToolInput: (args: Record<string, unknown>) => void;
|
|
88
|
+
sendToolResult: (result: CallToolResult) => void;
|
|
89
|
+
sendResultPatch: (result: CallToolResult) => void;
|
|
90
|
+
sendToolCancelled: (reason: string) => void;
|
|
91
|
+
sendHostContext: (context: UiHostContext) => void;
|
|
92
|
+
/** Get accumulated messages from this session */
|
|
93
|
+
getSessionMessages: () => UiSessionMessages;
|
|
94
|
+
getStreamSummary: () => UiStreamSummary | undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function startUiServer(options: UiServerOptions): Promise<UiServerHandle> {
|
|
98
|
+
const sessionToken = options.sessionToken ?? randomUUID();
|
|
99
|
+
const uiResourceToken = randomUUID();
|
|
100
|
+
const log = logger.child({
|
|
101
|
+
component: "UiServer",
|
|
102
|
+
server: options.serverName,
|
|
103
|
+
tool: options.toolName,
|
|
104
|
+
session: sessionToken.slice(0, 8),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
log.debug("Starting UI server");
|
|
108
|
+
|
|
109
|
+
const sseClients = new Set<ServerResponse>();
|
|
110
|
+
let completed = false;
|
|
111
|
+
let lastHeartbeatAt = Date.now();
|
|
112
|
+
let watchdog: NodeJS.Timeout | null = null;
|
|
113
|
+
let currentDisplayMode: UiDisplayMode = options.hostContext?.displayMode ?? "inline";
|
|
114
|
+
let nextEventId = 1;
|
|
115
|
+
const eventLog: Array<{ id: number; name: string; payload: unknown }> = [];
|
|
116
|
+
let streamSummary: UiStreamSummary | undefined;
|
|
117
|
+
|
|
118
|
+
// Track messages from UI for retrieval
|
|
119
|
+
const sessionMessages: UiSessionMessages = {
|
|
120
|
+
prompts: [],
|
|
121
|
+
notifications: [],
|
|
122
|
+
intents: [],
|
|
123
|
+
contexts: [],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const hostContext: UiHostContext = {
|
|
127
|
+
displayMode: currentDisplayMode,
|
|
128
|
+
availableDisplayModes: ["inline", "fullscreen", "pip"],
|
|
129
|
+
platform: "desktop",
|
|
130
|
+
...options.hostContext,
|
|
131
|
+
// Only include toolInfo if caller provides full tool definition with inputSchema
|
|
132
|
+
// The App validates toolInfo.tool.inputSchema as required object
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const initialStreamContext = hostContext["pi-mcp-adapter/stream"];
|
|
136
|
+
if (initialStreamContext && typeof initialStreamContext === "object") {
|
|
137
|
+
const streamId = (initialStreamContext as { streamId?: unknown }).streamId;
|
|
138
|
+
const mode = (initialStreamContext as { mode?: unknown }).mode;
|
|
139
|
+
if (typeof streamId === "string" && (mode === "eager" || mode === "stream-first")) {
|
|
140
|
+
streamSummary = {
|
|
141
|
+
streamId,
|
|
142
|
+
mode,
|
|
143
|
+
frames: 0,
|
|
144
|
+
phases: [],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const isAppOnlyTool = (toolName: string): boolean => {
|
|
150
|
+
const toolDefinition = options.manager.getConnection(options.serverName)?.tools?.find((tool) => tool.name === toolName);
|
|
151
|
+
if (!toolDefinition) return false;
|
|
152
|
+
const visibility = extractUiToolVisibility(toolDefinition._meta);
|
|
153
|
+
return isUiToolCallableByApp(visibility) && !isUiToolVisibleToModel(visibility);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const recordUiMessage = async (msgParams: UiMessageParams): Promise<void> => {
|
|
157
|
+
const promptText = extractUiPromptText(msgParams);
|
|
158
|
+
|
|
159
|
+
// Track messages by type (order: prompt → intent → notify)
|
|
160
|
+
// Must match the order in index.ts onMessage handler
|
|
161
|
+
if (promptText) {
|
|
162
|
+
sessionMessages.prompts.push(promptText);
|
|
163
|
+
log.debug("UI prompt received", { prompt: promptText.slice(0, 100) });
|
|
164
|
+
} else if (msgParams.type === "intent" || msgParams.intent) {
|
|
165
|
+
const intentName = msgParams.intent ?? "";
|
|
166
|
+
if (intentName) {
|
|
167
|
+
sessionMessages.intents.push({
|
|
168
|
+
intent: intentName,
|
|
169
|
+
...(msgParams.params !== undefined ? { params: msgParams.params } : {}),
|
|
170
|
+
});
|
|
171
|
+
log.debug("UI intent received", { intent: intentName });
|
|
172
|
+
}
|
|
173
|
+
} else if (msgParams.type === "notify" || msgParams.message) {
|
|
174
|
+
const notifyText = msgParams.message ?? "";
|
|
175
|
+
if (notifyText) {
|
|
176
|
+
sessionMessages.notifications.push(notifyText);
|
|
177
|
+
log.debug("UI notification", { message: notifyText.slice(0, 100) });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
await options.onMessage?.(msgParams);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const touchHeartbeat = () => {
|
|
185
|
+
lastHeartbeatAt = Date.now();
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const updateStreamSummary = (payload: unknown) => {
|
|
189
|
+
const envelope = getVisualizationStreamEnvelope((payload as { structuredContent?: unknown } | null)?.structuredContent);
|
|
190
|
+
if (!envelope) return;
|
|
191
|
+
if (!streamSummary) {
|
|
192
|
+
streamSummary = {
|
|
193
|
+
streamId: envelope.streamId,
|
|
194
|
+
mode: "eager",
|
|
195
|
+
frames: 0,
|
|
196
|
+
phases: [],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
streamSummary.frames += 1;
|
|
200
|
+
if (!streamSummary.phases.includes(envelope.phase)) {
|
|
201
|
+
streamSummary.phases.push(envelope.phase);
|
|
202
|
+
}
|
|
203
|
+
streamSummary.finalStatus = envelope.status;
|
|
204
|
+
if (envelope.message !== undefined) streamSummary.lastMessage = envelope.message;
|
|
205
|
+
else delete streamSummary.lastMessage;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const serializeEvent = (eventId: number, name: string, payload: unknown): string => {
|
|
209
|
+
return `id: ${eventId}\nevent: ${name}\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const getLatestCheckpointIndex = () => {
|
|
213
|
+
for (let index = eventLog.length - 1; index >= 0; index -= 1) {
|
|
214
|
+
const entry = eventLog[index];
|
|
215
|
+
if (!entry) continue;
|
|
216
|
+
const envelope = getVisualizationStreamEnvelope((entry.payload as { structuredContent?: unknown } | null)?.structuredContent);
|
|
217
|
+
if (envelope?.frameType === "checkpoint" || envelope?.frameType === "final") {
|
|
218
|
+
return index;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return -1;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const pruneEventLog = () => {
|
|
225
|
+
if (eventLog.length <= MAX_EVENT_LOG) return;
|
|
226
|
+
const latestCheckpointIndex = getLatestCheckpointIndex();
|
|
227
|
+
|
|
228
|
+
if (latestCheckpointIndex > 0) {
|
|
229
|
+
eventLog.splice(0, latestCheckpointIndex);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (eventLog.length > MAX_EVENT_LOG) {
|
|
233
|
+
eventLog.splice(0, eventLog.length - MAX_EVENT_LOG);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const pushEvent = (name: string, payload: unknown) => {
|
|
238
|
+
if (completed) return;
|
|
239
|
+
const eventId = nextEventId++;
|
|
240
|
+
eventLog.push({ id: eventId, name, payload });
|
|
241
|
+
updateStreamSummary(payload);
|
|
242
|
+
pruneEventLog();
|
|
243
|
+
const chunk = serializeEvent(eventId, name, payload);
|
|
244
|
+
for (const client of sseClients) {
|
|
245
|
+
try {
|
|
246
|
+
client.write(chunk);
|
|
247
|
+
} catch {
|
|
248
|
+
sseClients.delete(client);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const replayEvents = (res: ServerResponse, lastEventIdHeader?: string | null) => {
|
|
254
|
+
const parsedLastId = lastEventIdHeader ? Number(lastEventIdHeader) : Number.NaN;
|
|
255
|
+
const eventsToReplay = Number.isFinite(parsedLastId)
|
|
256
|
+
? eventLog.filter((entry) => entry.id > parsedLastId)
|
|
257
|
+
: (() => {
|
|
258
|
+
const latestCheckpointIndex = getLatestCheckpointIndex();
|
|
259
|
+
return latestCheckpointIndex >= 0 ? eventLog.slice(latestCheckpointIndex) : eventLog;
|
|
260
|
+
})();
|
|
261
|
+
|
|
262
|
+
for (const entry of eventsToReplay) {
|
|
263
|
+
try {
|
|
264
|
+
res.write(serializeEvent(entry.id, entry.name, entry.payload));
|
|
265
|
+
} catch {
|
|
266
|
+
sseClients.delete(res);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const closeSse = () => {
|
|
273
|
+
for (const client of sseClients) {
|
|
274
|
+
try {
|
|
275
|
+
client.end();
|
|
276
|
+
} catch {}
|
|
277
|
+
}
|
|
278
|
+
sseClients.clear();
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const stopWatchdog = () => {
|
|
282
|
+
if (!watchdog) return;
|
|
283
|
+
clearInterval(watchdog);
|
|
284
|
+
watchdog = null;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const markCompleted = (reason: string) => {
|
|
288
|
+
if (completed) return;
|
|
289
|
+
log.debug("Session completed", { reason });
|
|
290
|
+
pushEvent("session-complete", { reason });
|
|
291
|
+
completed = true;
|
|
292
|
+
stopWatchdog();
|
|
293
|
+
options.onComplete?.(reason);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const server = http.createServer(async (req, res) => {
|
|
297
|
+
try {
|
|
298
|
+
const method = req.method || "GET";
|
|
299
|
+
const hostHeader = req.headers.host;
|
|
300
|
+
const url = new URL(req.url || "/", `http://${hostHeader || "127.0.0.1"}`);
|
|
301
|
+
if (hostHeader !== undefined && !isAllowedHost(url.hostname)) {
|
|
302
|
+
sendText(res, 403, "Invalid host");
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (method === "HEAD" && url.pathname === "/") {
|
|
307
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
308
|
+
res.end();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (method === "GET" && url.pathname === "/") {
|
|
313
|
+
if (!url.searchParams.has("session")) {
|
|
314
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
|
|
315
|
+
res.end(
|
|
316
|
+
"<!doctype html><html><head><meta charset=\"utf-8\"><title>MCP UI</title></head>" +
|
|
317
|
+
"<body><p>Open the authenticated MCP UI URL shown by Pi.</p></body></html>",
|
|
318
|
+
);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!validateTokenQuery(url, sessionToken, res)) return;
|
|
322
|
+
touchHeartbeat();
|
|
323
|
+
|
|
324
|
+
const html = buildHostHtmlTemplate({
|
|
325
|
+
sessionToken,
|
|
326
|
+
uiResourceToken,
|
|
327
|
+
serverName: options.serverName,
|
|
328
|
+
toolName: options.toolName,
|
|
329
|
+
toolArgs: options.toolArgs,
|
|
330
|
+
resource: options.resource,
|
|
331
|
+
allowAttribute: buildAllowAttribute(options.resource.meta.permissions),
|
|
332
|
+
requireToolConsent: options.consentManager.requiresPrompt(options.serverName),
|
|
333
|
+
cacheToolConsent: options.consentManager.shouldCacheConsent(),
|
|
334
|
+
hostContext,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
res.writeHead(200, {
|
|
338
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
339
|
+
"Cache-Control": "no-store",
|
|
340
|
+
});
|
|
341
|
+
res.end(html);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (method === "GET" && url.pathname === "/events") {
|
|
346
|
+
if (!validateTokenQuery(url, sessionToken, res)) return;
|
|
347
|
+
touchHeartbeat();
|
|
348
|
+
log.debug("SSE client connected", { clientCount: sseClients.size + 1 });
|
|
349
|
+
res.writeHead(200, {
|
|
350
|
+
"Content-Type": "text/event-stream",
|
|
351
|
+
"Cache-Control": "no-cache, no-transform",
|
|
352
|
+
Connection: "keep-alive",
|
|
353
|
+
"X-Accel-Buffering": "no",
|
|
354
|
+
});
|
|
355
|
+
res.write(": connected\n\n");
|
|
356
|
+
sseClients.add(res);
|
|
357
|
+
replayEvents(res, req.headers["last-event-id"] ? String(req.headers["last-event-id"]) : null);
|
|
358
|
+
req.on("close", () => {
|
|
359
|
+
sseClients.delete(res);
|
|
360
|
+
});
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (method === "GET" && url.pathname === "/health") {
|
|
365
|
+
if (!validateTokenQuery(url, sessionToken, res)) return;
|
|
366
|
+
sendJson(res, 200, { ok: true, result: { healthy: true } });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (method === "GET" && url.pathname === "/ui-app") {
|
|
371
|
+
if (!validateTokenQuery(url, uiResourceToken, res, "resource")) return;
|
|
372
|
+
touchHeartbeat();
|
|
373
|
+
// Enforce host metadata independently of where app HTML places its document head.
|
|
374
|
+
const cspContent = buildCspMetaContent(options.resource.meta.csp);
|
|
375
|
+
res.writeHead(200, {
|
|
376
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
377
|
+
"Cache-Control": "no-store",
|
|
378
|
+
"Content-Security-Policy": cspContent,
|
|
379
|
+
});
|
|
380
|
+
res.end(options.resource.html);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (method === "GET" && url.pathname === "/app-bridge.bundle.js") {
|
|
385
|
+
// Serve the pre-bundled AppBridge module
|
|
386
|
+
const bundlePath = path.join(import.meta.dirname, "app-bridge.bundle.js");
|
|
387
|
+
try {
|
|
388
|
+
const content = await fs.readFile(bundlePath, "utf-8");
|
|
389
|
+
res.writeHead(200, {
|
|
390
|
+
"Content-Type": "application/javascript",
|
|
391
|
+
"Cache-Control": "public, max-age=31536000",
|
|
392
|
+
});
|
|
393
|
+
res.end(content);
|
|
394
|
+
} catch {
|
|
395
|
+
sendJson(res, 500, { ok: false, error: "Bundle not found" });
|
|
396
|
+
}
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (method !== "POST") {
|
|
401
|
+
sendJson(res, 404, { ok: false, error: "Not found" });
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const body = await parseBody(req, res);
|
|
406
|
+
if (!body) return;
|
|
407
|
+
if (!validateTokenBody(body, sessionToken, res)) return;
|
|
408
|
+
const params = body.params ?? {};
|
|
409
|
+
touchHeartbeat();
|
|
410
|
+
|
|
411
|
+
if (url.pathname === "/proxy/tools/call") {
|
|
412
|
+
options.consentManager.ensureApproved(options.serverName);
|
|
413
|
+
const callParams = params as CallToolRequest["params"];
|
|
414
|
+
if (!callParams || typeof callParams.name !== "string" || !callParams.name.trim()) {
|
|
415
|
+
sendJson(res, 400, { ok: false, error: "Invalid tools/call params" });
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const connection = options.manager.getConnection(options.serverName);
|
|
420
|
+
if (!connection || connection.status !== "connected") {
|
|
421
|
+
sendJson(res, 503, { ok: false, error: `Server "${options.serverName}" is not connected` });
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (isServerDisabled(options.config?.mcpServers[options.serverName]) || isServerDisabled(connection.definition)) {
|
|
425
|
+
sendJson(res, 503, { ok: false, error: `Server "${options.serverName}" is disabled` });
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const toolDefinitions = Array.isArray(connection.tools) ? connection.tools : [];
|
|
430
|
+
const toolDefinition = toolDefinitions.find((tool) => tool.name === callParams.name);
|
|
431
|
+
if (!toolDefinition) {
|
|
432
|
+
sendJson(res, 403, { ok: false, error: `MCP tool "${callParams.name}" is not callable by apps` });
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const uiVisibility = extractUiToolVisibility(toolDefinition._meta);
|
|
436
|
+
if (!isUiToolCallableByApp(uiVisibility)) {
|
|
437
|
+
sendJson(res, 403, { ok: false, error: `MCP tool "${callParams.name}" is not callable by apps` });
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const callArgs = {
|
|
442
|
+
name: callParams.name,
|
|
443
|
+
arguments:
|
|
444
|
+
callParams.arguments && typeof callParams.arguments === "object" && !Array.isArray(callParams.arguments)
|
|
445
|
+
? callParams.arguments
|
|
446
|
+
: {},
|
|
447
|
+
};
|
|
448
|
+
const toolMeta = {
|
|
449
|
+
name: callParams.name,
|
|
450
|
+
originalName: callParams.name,
|
|
451
|
+
description: toolDefinition?.description ?? "",
|
|
452
|
+
...(toolDefinition?.inputSchema !== undefined ? { inputSchema: toolDefinition.inputSchema } : {}),
|
|
453
|
+
...(uiVisibility !== undefined ? { uiVisibility } : {}),
|
|
454
|
+
};
|
|
455
|
+
const approvalMetadata = new Map(options.state?.toolMetadata);
|
|
456
|
+
const definition = options.config?.mcpServers[options.serverName] ?? options.state?.config.mcpServers[options.serverName];
|
|
457
|
+
approvalMetadata.set(options.serverName, [
|
|
458
|
+
...connection.tools.map(tool => ({
|
|
459
|
+
name: tool.name,
|
|
460
|
+
originalName: tool.name,
|
|
461
|
+
description: tool.description ?? "",
|
|
462
|
+
})),
|
|
463
|
+
...(definition?.exposeResources !== false ? (connection.resources ?? []).map(resource => {
|
|
464
|
+
const originalName = `read_${resourceNameToToolName(resource.name)}`;
|
|
465
|
+
return {
|
|
466
|
+
name: originalName,
|
|
467
|
+
originalName,
|
|
468
|
+
description: resource.description ?? `Read resource: ${resource.uri}`,
|
|
469
|
+
};
|
|
470
|
+
}) : []),
|
|
471
|
+
]);
|
|
472
|
+
const approval = options.state
|
|
473
|
+
? await ensureToolCallApproved(
|
|
474
|
+
options.state,
|
|
475
|
+
options.serverName,
|
|
476
|
+
toolMeta,
|
|
477
|
+
callArgs.arguments,
|
|
478
|
+
options.state.owner?.signal,
|
|
479
|
+
"iframe",
|
|
480
|
+
approvalMetadata,
|
|
481
|
+
)
|
|
482
|
+
: options.config && isToolCallApprovalRequired(options.config, options.serverName, toolMeta, approvalMetadata)
|
|
483
|
+
? { ok: false as const, reason: "approval_required_headless" as const }
|
|
484
|
+
: { ok: true as const };
|
|
485
|
+
if (approval.ok === false) {
|
|
486
|
+
const denied = approval.reason === "denied";
|
|
487
|
+
const message = denied
|
|
488
|
+
? `The user declined approval to run MCP tool "${callParams.name}" on server "${options.serverName}".`
|
|
489
|
+
: `MCP tool "${callParams.name}" on server "${options.serverName}" is approval-gated and requires an interactive session.`;
|
|
490
|
+
sendJson(res, 200, {
|
|
491
|
+
ok: true,
|
|
492
|
+
result: {
|
|
493
|
+
content: [{ type: "text" as const, text: message }],
|
|
494
|
+
details: {
|
|
495
|
+
error: denied ? "approval_denied" : "approval_required",
|
|
496
|
+
server: options.serverName,
|
|
497
|
+
tool: callParams.name,
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
try {
|
|
505
|
+
options.manager.touch(options.serverName);
|
|
506
|
+
options.manager.incrementInFlight(options.serverName);
|
|
507
|
+
const result = options.config
|
|
508
|
+
? await withSessionRecovery(
|
|
509
|
+
{
|
|
510
|
+
manager: options.manager,
|
|
511
|
+
config: options.config,
|
|
512
|
+
...(options.onNeedsAuth ? { onNeedsAuth: options.onNeedsAuth } : {}),
|
|
513
|
+
},
|
|
514
|
+
options.serverName,
|
|
515
|
+
(conn) => conn.client.callTool(callArgs, options.manager.getRequestOptions?.(options.serverName)),
|
|
516
|
+
)
|
|
517
|
+
: await connection.client.callTool(callArgs, options.manager.getRequestOptions?.(options.serverName));
|
|
518
|
+
sendJson(res, 200, { ok: true, result });
|
|
519
|
+
} finally {
|
|
520
|
+
options.manager.decrementInFlight(options.serverName);
|
|
521
|
+
options.manager.touch(options.serverName);
|
|
522
|
+
}
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (url.pathname === "/proxy/ui/consent") {
|
|
527
|
+
const approved = !!(params as { approved?: boolean }).approved;
|
|
528
|
+
options.consentManager.registerDecision(options.serverName, approved);
|
|
529
|
+
sendJson(res, 200, { ok: true, result: { approved } });
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (url.pathname === "/proxy/ui/generated-tool-call-intent") {
|
|
534
|
+
const tool = typeof params.tool === "string" ? params.tool : undefined;
|
|
535
|
+
if (tool && isAppOnlyTool(tool)) {
|
|
536
|
+
log.debug("Ignored generated app-only tool call intent", { tool });
|
|
537
|
+
} else {
|
|
538
|
+
await recordUiMessage({
|
|
539
|
+
type: "intent",
|
|
540
|
+
intent: "call_tool",
|
|
541
|
+
params: {
|
|
542
|
+
...(tool !== undefined ? { tool } : {}),
|
|
543
|
+
...(params.arguments !== undefined ? { arguments: params.arguments } : {}),
|
|
544
|
+
...(params.isError !== undefined ? { isError: params.isError } : {}),
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
sendJson(res, 200, { ok: true, result: {} });
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (url.pathname === "/proxy/ui/message") {
|
|
553
|
+
await recordUiMessage(params as UiMessageParams);
|
|
554
|
+
sendJson(res, 200, { ok: true, result: {} });
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (url.pathname === "/proxy/ui/context") {
|
|
559
|
+
const content = params.content;
|
|
560
|
+
const structuredContent = params.structuredContent;
|
|
561
|
+
if (
|
|
562
|
+
(content !== undefined && (!Array.isArray(content) || content.some((block) => !ContentBlockSchema.safeParse(block).success))) ||
|
|
563
|
+
(structuredContent !== undefined && (!structuredContent || typeof structuredContent !== "object" || Array.isArray(structuredContent)))
|
|
564
|
+
) {
|
|
565
|
+
sendJson(res, 400, { ok: false, error: "Invalid update-model-context params" });
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const ctxParams: UiModelContextParams = {
|
|
569
|
+
...(content !== undefined ? { content: content as NonNullable<UiModelContextParams["content"]> } : {}),
|
|
570
|
+
...(structuredContent !== undefined ? { structuredContent: structuredContent as Record<string, unknown> } : {}),
|
|
571
|
+
};
|
|
572
|
+
const update = createUiModelContextUpdate(ctxParams);
|
|
573
|
+
if (update) {
|
|
574
|
+
sessionMessages.contexts.push(update);
|
|
575
|
+
while (sessionMessages.contexts.length > MAX_CONTEXT_UPDATES) {
|
|
576
|
+
sessionMessages.contexts.shift();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
log.debug("UI context update", { hasContent: !!ctxParams.content, hasUpdate: !!update });
|
|
580
|
+
await options.onContextUpdate?.(ctxParams);
|
|
581
|
+
sendJson(res, 200, { ok: true, result: {} });
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if (url.pathname === "/proxy/ui/open-link") {
|
|
586
|
+
const openParams = params as { url?: string };
|
|
587
|
+
if (!openParams?.url || typeof openParams.url !== "string") {
|
|
588
|
+
sendJson(res, 400, { ok: false, error: "Invalid open-link params" });
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
let result: UiOpenLinkResult = {};
|
|
592
|
+
try {
|
|
593
|
+
new URL(openParams.url);
|
|
594
|
+
} catch {
|
|
595
|
+
result = { isError: true };
|
|
596
|
+
}
|
|
597
|
+
sendJson(res, 200, { ok: true, result });
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (url.pathname === "/proxy/ui/download-file") {
|
|
602
|
+
sendJson(res, 200, { ok: true, result: { isError: true } });
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if (url.pathname === "/proxy/ui/request-display-mode") {
|
|
607
|
+
const displayParams = params as UiDisplayModeRequest;
|
|
608
|
+
const requested = displayParams?.mode;
|
|
609
|
+
const available = hostContext.availableDisplayModes ?? ["inline"];
|
|
610
|
+
if (requested && available.includes(requested)) {
|
|
611
|
+
currentDisplayMode = requested;
|
|
612
|
+
}
|
|
613
|
+
hostContext.displayMode = currentDisplayMode;
|
|
614
|
+
pushEvent("host-context", { displayMode: currentDisplayMode });
|
|
615
|
+
const result: UiDisplayModeResult = { mode: currentDisplayMode };
|
|
616
|
+
sendJson(res, 200, { ok: true, result });
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (url.pathname === "/proxy/ui/heartbeat") {
|
|
621
|
+
sendJson(res, 200, { ok: true, result: {} });
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (url.pathname === "/proxy/ui/complete") {
|
|
626
|
+
const reason = typeof (params as { reason?: string }).reason === "string"
|
|
627
|
+
? (params as { reason?: string }).reason!
|
|
628
|
+
: "done";
|
|
629
|
+
markCompleted(reason);
|
|
630
|
+
sendJson(res, 200, { ok: true, result: {} });
|
|
631
|
+
setTimeout(() => {
|
|
632
|
+
try {
|
|
633
|
+
server.close();
|
|
634
|
+
} catch {}
|
|
635
|
+
closeSse();
|
|
636
|
+
}, 20).unref();
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
sendJson(res, 404, { ok: false, error: "Not found" });
|
|
641
|
+
} catch (error) {
|
|
642
|
+
if (error instanceof SessionRecoveryAuthRequiredError) {
|
|
643
|
+
const fallback = `Server "${options.serverName}" requires OAuth authentication. Run mcp({ action: "auth-start", server: "${options.serverName}" }) to get a browser URL, or /mcp-auth ${options.serverName} in an interactive local session.`;
|
|
644
|
+
const message = error.authMessage ?? (options.config
|
|
645
|
+
? formatAuthRequiredMessage(options.config, options.serverName, fallback)
|
|
646
|
+
: fallback);
|
|
647
|
+
sendJson(res, 401, { ok: false, error: message });
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const wrapped = wrapError(error, { server: options.serverName, tool: options.toolName });
|
|
651
|
+
const status = /approval required|denied/i.test(wrapped.message) ? 403 : 500;
|
|
652
|
+
if (status === 500) {
|
|
653
|
+
log.error("Request handler error", error instanceof Error ? error : undefined);
|
|
654
|
+
}
|
|
655
|
+
sendJson(res, status, { ok: false, error: wrapped.message });
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
if (options.initialResultPromise) {
|
|
660
|
+
options.initialResultPromise.then(
|
|
661
|
+
(result) => pushEvent("tool-result", result),
|
|
662
|
+
(error) => {
|
|
663
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
664
|
+
pushEvent("tool-cancelled", { reason });
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
watchdog = setInterval(() => {
|
|
670
|
+
if (completed) return;
|
|
671
|
+
if (Date.now() - lastHeartbeatAt <= ABANDONED_GRACE_MS) return;
|
|
672
|
+
markCompleted("stale");
|
|
673
|
+
try {
|
|
674
|
+
server.close();
|
|
675
|
+
} catch {}
|
|
676
|
+
closeSse();
|
|
677
|
+
}, WATCHDOG_INTERVAL_MS);
|
|
678
|
+
watchdog.unref();
|
|
679
|
+
|
|
680
|
+
return new Promise((resolve, reject) => {
|
|
681
|
+
const candidates = resolvePortCandidates(options.port);
|
|
682
|
+
let candidateIndex = 0;
|
|
683
|
+
|
|
684
|
+
const listen = () => {
|
|
685
|
+
server.once("error", onError);
|
|
686
|
+
server.listen(candidates[candidateIndex], "127.0.0.1", onListening);
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
const onError = (error: NodeJS.ErrnoException) => {
|
|
690
|
+
server.off("listening", onListening);
|
|
691
|
+
if (error.code === "EADDRINUSE" && candidateIndex < candidates.length - 1) {
|
|
692
|
+
candidateIndex += 1;
|
|
693
|
+
listen();
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
log.error("Failed to start server", error);
|
|
697
|
+
const port = candidates[candidateIndex];
|
|
698
|
+
reject(new ServerError(error.message, {
|
|
699
|
+
...(port !== undefined ? { port } : {}),
|
|
700
|
+
cause: error,
|
|
701
|
+
}));
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
const onListening = () => {
|
|
705
|
+
server.off("error", onError);
|
|
706
|
+
const address = server.address();
|
|
707
|
+
if (!address || typeof address === "string") {
|
|
708
|
+
const err = new ServerError("invalid address");
|
|
709
|
+
log.error("Invalid server address", err);
|
|
710
|
+
reject(err);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
log.debug("Server started", { port: address.port });
|
|
715
|
+
rememberMoshiDiscoveryPort(address.port);
|
|
716
|
+
|
|
717
|
+
const handle: UiServerHandle = {
|
|
718
|
+
url: `http://localhost:${address.port}/?session=${sessionToken}`,
|
|
719
|
+
port: address.port,
|
|
720
|
+
sessionToken,
|
|
721
|
+
serverName: options.serverName,
|
|
722
|
+
toolName: options.toolName,
|
|
723
|
+
close: (reason?: string) => {
|
|
724
|
+
markCompleted(reason ?? "closed");
|
|
725
|
+
try {
|
|
726
|
+
server.close();
|
|
727
|
+
} catch {}
|
|
728
|
+
closeSse();
|
|
729
|
+
},
|
|
730
|
+
sendToolInput: (args: Record<string, unknown>) => {
|
|
731
|
+
pushEvent("tool-input", { arguments: args });
|
|
732
|
+
},
|
|
733
|
+
sendToolResult: (result: CallToolResult) => {
|
|
734
|
+
pushEvent("tool-result", result);
|
|
735
|
+
},
|
|
736
|
+
sendResultPatch: (result: CallToolResult) => {
|
|
737
|
+
pushEvent("result-patch", result);
|
|
738
|
+
},
|
|
739
|
+
sendToolCancelled: (reason: string) => {
|
|
740
|
+
pushEvent("tool-cancelled", { reason });
|
|
741
|
+
},
|
|
742
|
+
sendHostContext: (context: UiHostContext) => {
|
|
743
|
+
Object.assign(hostContext, context);
|
|
744
|
+
pushEvent("host-context", context);
|
|
745
|
+
},
|
|
746
|
+
getSessionMessages: () => ({ ...sessionMessages }),
|
|
747
|
+
getStreamSummary: () => streamSummary ? { ...streamSummary, phases: [...streamSummary.phases] } : undefined,
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
resolve(handle);
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
listen();
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
async function parseBody(
|
|
758
|
+
req: IncomingMessage,
|
|
759
|
+
res: ServerResponse,
|
|
760
|
+
): Promise<UiProxyRequestBody<Record<string, unknown>> | null> {
|
|
761
|
+
try {
|
|
762
|
+
const body = await readBody(req);
|
|
763
|
+
if (!body || typeof body !== "object") {
|
|
764
|
+
sendJson(res, 400, { ok: false, error: "Invalid request body" });
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
return body as UiProxyRequestBody<Record<string, unknown>>;
|
|
768
|
+
} catch (error) {
|
|
769
|
+
sendJson(res, 400, { ok: false, error: error instanceof Error ? error.message : "Invalid body" });
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function readBody(req: IncomingMessage): Promise<unknown> {
|
|
775
|
+
return new Promise((resolve, reject) => {
|
|
776
|
+
let size = 0;
|
|
777
|
+
const chunks: Buffer[] = [];
|
|
778
|
+
|
|
779
|
+
req.on("data", (chunk: Buffer) => {
|
|
780
|
+
size += chunk.length;
|
|
781
|
+
if (size > MAX_BODY_SIZE) {
|
|
782
|
+
req.destroy();
|
|
783
|
+
reject(new Error("Request body too large"));
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
chunks.push(chunk);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
req.on("end", () => {
|
|
790
|
+
try {
|
|
791
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
792
|
+
} catch (error) {
|
|
793
|
+
reject(error);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
req.on("error", reject);
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function resolvePortCandidates(port: number | undefined): number[] {
|
|
802
|
+
if (port !== undefined) return [port];
|
|
803
|
+
const candidates: number[] = [];
|
|
804
|
+
const count = MOSHI_DISCOVERY_PORT_END - MOSHI_DISCOVERY_PORT_START + 1;
|
|
805
|
+
for (let offset = 0; offset < count; offset += 1) {
|
|
806
|
+
const candidate = MOSHI_DISCOVERY_PORT_START + ((nextMoshiDiscoveryPort - MOSHI_DISCOVERY_PORT_START + offset) % count);
|
|
807
|
+
candidates.push(candidate);
|
|
808
|
+
}
|
|
809
|
+
candidates.push(0);
|
|
810
|
+
return candidates;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function rememberMoshiDiscoveryPort(port: number): void {
|
|
814
|
+
if (port < MOSHI_DISCOVERY_PORT_START || port > MOSHI_DISCOVERY_PORT_END) return;
|
|
815
|
+
nextMoshiDiscoveryPort = port >= MOSHI_DISCOVERY_PORT_END ? MOSHI_DISCOVERY_PORT_START : port + 1;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function isAllowedHost(hostname: string): boolean {
|
|
819
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function validateTokenQuery(
|
|
823
|
+
url: URL,
|
|
824
|
+
expected: string,
|
|
825
|
+
res: ServerResponse,
|
|
826
|
+
parameter = "session",
|
|
827
|
+
): boolean {
|
|
828
|
+
const token = url.searchParams.get(parameter);
|
|
829
|
+
if (token !== expected) {
|
|
830
|
+
sendJson(res, 403, { ok: false, error: "Invalid session" });
|
|
831
|
+
return false;
|
|
832
|
+
}
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function validateTokenBody(
|
|
837
|
+
body: UiProxyRequestBody<Record<string, unknown>>,
|
|
838
|
+
expected: string,
|
|
839
|
+
res: ServerResponse,
|
|
840
|
+
): boolean {
|
|
841
|
+
if (body.token !== expected) {
|
|
842
|
+
sendJson(res, 403, { ok: false, error: "Invalid session" });
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
return true;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function sendJson<T>(
|
|
849
|
+
res: ServerResponse,
|
|
850
|
+
status: number,
|
|
851
|
+
payload: UiProxyResult<T>,
|
|
852
|
+
): void {
|
|
853
|
+
res.writeHead(status, {
|
|
854
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
855
|
+
"Cache-Control": "no-store",
|
|
856
|
+
});
|
|
857
|
+
res.end(JSON.stringify(payload));
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function sendText(res: ServerResponse, status: number, text: string): void {
|
|
861
|
+
res.writeHead(status, {
|
|
862
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
863
|
+
"Cache-Control": "no-store",
|
|
864
|
+
});
|
|
865
|
+
res.end(text);
|
|
866
|
+
}
|