@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,335 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { activityMonitor } from "./activity.js";
|
|
3
|
+
import { hasCredentialSource, redactCredential, resolveCredential } from "./credential-source.js";
|
|
4
|
+
import { getWebSearchConfigPath } from "./utils.js";
|
|
5
|
+
const QUERIT_SEARCH_URL = "https://api.querit.ai/v1/search";
|
|
6
|
+
const QUERIT_CONTENTS_URL = "https://api.querit.ai/v1/contents";
|
|
7
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
8
|
+
const SEARCH_TIMEOUT_MS = 60_000;
|
|
9
|
+
const CONTENTS_TIMEOUT_MS = 60_000;
|
|
10
|
+
const MAX_CONTENT_URLS = 10;
|
|
11
|
+
let cachedConfig = null;
|
|
12
|
+
function loadConfig() {
|
|
13
|
+
if (cachedConfig)
|
|
14
|
+
return cachedConfig;
|
|
15
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
16
|
+
cachedConfig = {};
|
|
17
|
+
return cachedConfig;
|
|
18
|
+
}
|
|
19
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
26
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
|
|
27
|
+
}
|
|
28
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
29
|
+
throw new Error(`Invalid config in ${CONFIG_PATH}: expected a JSON object`);
|
|
30
|
+
}
|
|
31
|
+
cachedConfig = parsed;
|
|
32
|
+
return cachedConfig;
|
|
33
|
+
}
|
|
34
|
+
async function getApiKey(signal) {
|
|
35
|
+
const key = await resolveCredential({
|
|
36
|
+
provider: "Querit",
|
|
37
|
+
configuredValue: loadConfig().queritApiKey,
|
|
38
|
+
environmentValue: process.env.QUERIT_API_KEY,
|
|
39
|
+
signal,
|
|
40
|
+
});
|
|
41
|
+
if (!key) {
|
|
42
|
+
throw new Error("Querit API key not found. Either:\n" +
|
|
43
|
+
` 1. Create ${CONFIG_PATH} with { "queritApiKey": "your-key" }\n` +
|
|
44
|
+
" 2. Set QUERIT_API_KEY environment variable\n" +
|
|
45
|
+
"Create a key at https://www.querit.ai/en/dashboard/api-keys");
|
|
46
|
+
}
|
|
47
|
+
return key;
|
|
48
|
+
}
|
|
49
|
+
export function isQueritAvailable() {
|
|
50
|
+
return hasCredentialSource({
|
|
51
|
+
provider: "Querit",
|
|
52
|
+
configuredValue: loadConfig().queritApiKey,
|
|
53
|
+
environmentValue: process.env.QUERIT_API_KEY,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function errorMessage(err) {
|
|
57
|
+
return err instanceof Error ? err.message : String(err);
|
|
58
|
+
}
|
|
59
|
+
function requestSignal(signal, timeoutMs) {
|
|
60
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
61
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
62
|
+
}
|
|
63
|
+
function normalizeNumResults(value) {
|
|
64
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
65
|
+
return 5;
|
|
66
|
+
return Math.max(1, Math.min(Math.floor(value), 20));
|
|
67
|
+
}
|
|
68
|
+
function normalizeDomain(value) {
|
|
69
|
+
let input = value.trim().toLowerCase();
|
|
70
|
+
if (!input)
|
|
71
|
+
return null;
|
|
72
|
+
if (input.startsWith("-"))
|
|
73
|
+
input = input.slice(1).trim();
|
|
74
|
+
if (!input)
|
|
75
|
+
return null;
|
|
76
|
+
try {
|
|
77
|
+
const parsed = input.includes("://") ? new URL(input) : new URL(`https://${input}`);
|
|
78
|
+
input = parsed.hostname;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
input = input.split("/")[0]?.split(":")[0] ?? "";
|
|
82
|
+
}
|
|
83
|
+
input = input.replace(/^\.+|\.+$/g, "");
|
|
84
|
+
return /^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$/i.test(input) ? input : null;
|
|
85
|
+
}
|
|
86
|
+
function mapDomainFilter(domainFilter) {
|
|
87
|
+
const include = [];
|
|
88
|
+
const exclude = [];
|
|
89
|
+
for (const raw of domainFilter ?? []) {
|
|
90
|
+
const domain = normalizeDomain(raw);
|
|
91
|
+
if (!domain)
|
|
92
|
+
continue;
|
|
93
|
+
const target = raw.trim().startsWith("-") ? exclude : include;
|
|
94
|
+
if (!target.includes(domain))
|
|
95
|
+
target.push(domain);
|
|
96
|
+
}
|
|
97
|
+
return { include, exclude };
|
|
98
|
+
}
|
|
99
|
+
function mapRecencyFilter(value) {
|
|
100
|
+
if (value === "day")
|
|
101
|
+
return "d1";
|
|
102
|
+
if (value === "week")
|
|
103
|
+
return "w1";
|
|
104
|
+
if (value === "month")
|
|
105
|
+
return "m1";
|
|
106
|
+
if (value === "year")
|
|
107
|
+
return "y1";
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
function buildSearchBody(query, options) {
|
|
111
|
+
const { include, exclude } = mapDomainFilter(options.domainFilter);
|
|
112
|
+
const date = mapRecencyFilter(options.recencyFilter);
|
|
113
|
+
const filters = {};
|
|
114
|
+
if (include.length > 0 || exclude.length > 0) {
|
|
115
|
+
filters.sites = {
|
|
116
|
+
...(include.length > 0 ? { include } : {}),
|
|
117
|
+
...(exclude.length > 0 ? { exclude } : {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (date)
|
|
121
|
+
filters.timeRange = { date };
|
|
122
|
+
return {
|
|
123
|
+
query,
|
|
124
|
+
count: normalizeNumResults(options.numResults),
|
|
125
|
+
...(Object.keys(filters).length > 0 ? { filters } : {}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function normalizeTimeoutMs(value) {
|
|
129
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
130
|
+
return CONTENTS_TIMEOUT_MS;
|
|
131
|
+
return Math.max(1, Math.floor(value));
|
|
132
|
+
}
|
|
133
|
+
function crawlTimeoutSeconds(value) {
|
|
134
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
135
|
+
return 10;
|
|
136
|
+
return Math.max(1, Math.min(Math.ceil(value / 1_000), 60));
|
|
137
|
+
}
|
|
138
|
+
function buildContentsBody(urls, options = {}) {
|
|
139
|
+
return {
|
|
140
|
+
urls,
|
|
141
|
+
format: "markdown",
|
|
142
|
+
crawlTimeout: crawlTimeoutSeconds(options.timeoutMs),
|
|
143
|
+
extrasMeta: true,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async function queritJsonRequest(label, url, apiKey, body, timeoutMs, signal) {
|
|
147
|
+
let response;
|
|
148
|
+
try {
|
|
149
|
+
response = await fetch(url, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
headers: {
|
|
152
|
+
Authorization: `Bearer ${apiKey}`,
|
|
153
|
+
Accept: "application/json",
|
|
154
|
+
"Content-Type": "application/json",
|
|
155
|
+
},
|
|
156
|
+
body: JSON.stringify(body),
|
|
157
|
+
signal: requestSignal(signal, timeoutMs),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
const message = errorMessage(err);
|
|
162
|
+
const isRequestAbort = err instanceof Error
|
|
163
|
+
? err.name === "AbortError" || err.name === "TimeoutError" || /abort|timeout/i.test(message)
|
|
164
|
+
: /abort|timeout/i.test(message);
|
|
165
|
+
if (!signal?.aborted && isRequestAbort) {
|
|
166
|
+
const timeoutError = new Error(`Querit ${label} API request timed out after ${Math.ceil(timeoutMs / 1_000)} seconds`);
|
|
167
|
+
timeoutError.name = "TimeoutError";
|
|
168
|
+
throw timeoutError;
|
|
169
|
+
}
|
|
170
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
171
|
+
if (redactedMessage === message)
|
|
172
|
+
throw err;
|
|
173
|
+
const redactedError = new Error(redactedMessage);
|
|
174
|
+
if (err instanceof Error)
|
|
175
|
+
redactedError.name = err.name;
|
|
176
|
+
throw redactedError;
|
|
177
|
+
}
|
|
178
|
+
const raw = await response.text();
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
throw new Error(`Querit ${label} API error ${response.status}: ${redactCredential(raw, apiKey).slice(0, 300)}`);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
return JSON.parse(raw);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
throw new Error(`Querit ${label} API returned invalid JSON: ${errorMessage(err)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function assertApiSuccess(label, data) {
|
|
190
|
+
const code = Number(data.error_code);
|
|
191
|
+
if (!Number.isFinite(code) || code !== 200) {
|
|
192
|
+
const renderedCode = data.error_code === undefined ? "unknown" : String(data.error_code);
|
|
193
|
+
const message = typeof data.error_msg === "string" && data.error_msg.trim() ? `: ${data.error_msg.trim()}` : "";
|
|
194
|
+
throw new Error(`Querit ${label} API returned error ${renderedCode}${message}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function mapSearchResults(data) {
|
|
198
|
+
const items = data.results?.result;
|
|
199
|
+
if (!Array.isArray(items)) {
|
|
200
|
+
throw new Error("Querit Search API returned an unexpected response shape");
|
|
201
|
+
}
|
|
202
|
+
return items.flatMap((item) => {
|
|
203
|
+
if (!item || typeof item.url !== "string" || item.url.trim().length === 0)
|
|
204
|
+
return [];
|
|
205
|
+
const url = item.url.trim();
|
|
206
|
+
return [{
|
|
207
|
+
title: typeof item.title === "string" && item.title.trim() ? item.title.trim() : url,
|
|
208
|
+
url,
|
|
209
|
+
snippet: typeof item.snippet === "string" ? item.snippet.replace(/\s+/g, " ").trim() : "",
|
|
210
|
+
}];
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function buildAnswer(results) {
|
|
214
|
+
return results.map((result) => {
|
|
215
|
+
if (result.snippet)
|
|
216
|
+
return `${result.snippet}\nSource: ${result.title} (${result.url})`;
|
|
217
|
+
return `Source: ${result.title} (${result.url})`;
|
|
218
|
+
}).join("\n\n");
|
|
219
|
+
}
|
|
220
|
+
function mapContentResult(result, requestedUrl) {
|
|
221
|
+
if (!result || typeof result.content !== "string" || result.content.trim().length === 0)
|
|
222
|
+
return null;
|
|
223
|
+
const metadata = result.extrasMeta;
|
|
224
|
+
return {
|
|
225
|
+
url: requestedUrl,
|
|
226
|
+
title: metadata && typeof metadata.title === "string" ? metadata.title.trim() : "",
|
|
227
|
+
content: result.content.trim(),
|
|
228
|
+
error: null,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function findContentResult(data, requestedUrl, index, requestedCount) {
|
|
232
|
+
if (!Array.isArray(data.results))
|
|
233
|
+
return undefined;
|
|
234
|
+
const exact = data.results.find((item) => item?.url === requestedUrl || item?.extrasMeta?.url === requestedUrl);
|
|
235
|
+
if (exact)
|
|
236
|
+
return exact;
|
|
237
|
+
if (requestedCount === 1)
|
|
238
|
+
return data.results[0];
|
|
239
|
+
return data.results.length === requestedCount ? data.results[index] : undefined;
|
|
240
|
+
}
|
|
241
|
+
function failedContentStatus(data, result, index) {
|
|
242
|
+
if (!Array.isArray(data.statuses))
|
|
243
|
+
return false;
|
|
244
|
+
const status = result?.id
|
|
245
|
+
? data.statuses.find((item) => item?.id === result.id)
|
|
246
|
+
: data.statuses[index];
|
|
247
|
+
return status?.status === "failed";
|
|
248
|
+
}
|
|
249
|
+
async function fetchContentsBatch(urls, apiKey, signal, options = {}) {
|
|
250
|
+
const data = await queritJsonRequest("Contents", QUERIT_CONTENTS_URL, apiKey, buildContentsBody(urls, options), normalizeTimeoutMs(options.timeoutMs), signal);
|
|
251
|
+
assertApiSuccess("Contents", data);
|
|
252
|
+
if (!Array.isArray(data.results) || !Array.isArray(data.statuses)) {
|
|
253
|
+
throw new Error("Querit Contents API returned an unexpected response shape");
|
|
254
|
+
}
|
|
255
|
+
return data;
|
|
256
|
+
}
|
|
257
|
+
async function fetchInlineContent(urls, apiKey, signal) {
|
|
258
|
+
const content = [];
|
|
259
|
+
for (let offset = 0; offset < urls.length; offset += MAX_CONTENT_URLS) {
|
|
260
|
+
const batch = urls.slice(offset, offset + MAX_CONTENT_URLS);
|
|
261
|
+
const data = await fetchContentsBatch(batch, apiKey, signal);
|
|
262
|
+
for (let index = 0; index < batch.length; index++) {
|
|
263
|
+
const requestedUrl = batch[index];
|
|
264
|
+
const result = findContentResult(data, requestedUrl, index, batch.length);
|
|
265
|
+
const mapped = mapContentResult(result, requestedUrl);
|
|
266
|
+
if (mapped)
|
|
267
|
+
content.push(mapped);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return content;
|
|
271
|
+
}
|
|
272
|
+
export async function searchWithQuerit(query, options = {}) {
|
|
273
|
+
const apiKey = await getApiKey(options.signal);
|
|
274
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
275
|
+
try {
|
|
276
|
+
const data = await queritJsonRequest("Search", QUERIT_SEARCH_URL, apiKey, buildSearchBody(query, options), SEARCH_TIMEOUT_MS, options.signal);
|
|
277
|
+
assertApiSuccess("Search", data);
|
|
278
|
+
const results = mapSearchResults(data);
|
|
279
|
+
const response = { answer: buildAnswer(results), results };
|
|
280
|
+
if (options.includeContent && results.length > 0) {
|
|
281
|
+
const inlineContent = await fetchInlineContent(results.map((result) => result.url), apiKey, options.signal);
|
|
282
|
+
if (inlineContent.length > 0)
|
|
283
|
+
response.inlineContent = inlineContent;
|
|
284
|
+
}
|
|
285
|
+
activityMonitor.logComplete(activityId, 200);
|
|
286
|
+
return response;
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
const message = errorMessage(err);
|
|
290
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
291
|
+
if (options.signal?.aborted)
|
|
292
|
+
activityMonitor.logComplete(activityId, 0);
|
|
293
|
+
else
|
|
294
|
+
activityMonitor.logError(activityId, redactedMessage);
|
|
295
|
+
if (redactedMessage === message)
|
|
296
|
+
throw err;
|
|
297
|
+
const redactedError = new Error(redactedMessage);
|
|
298
|
+
if (err instanceof Error)
|
|
299
|
+
redactedError.name = err.name;
|
|
300
|
+
throw redactedError;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
export async function extractWithQuerit(url, signal, options = {}) {
|
|
304
|
+
const apiKey = await getApiKey(signal);
|
|
305
|
+
const activityId = activityMonitor.logStart({ type: "fetch", url });
|
|
306
|
+
try {
|
|
307
|
+
const data = await fetchContentsBatch([url], apiKey, signal, options);
|
|
308
|
+
const result = findContentResult(data, url, 0, 1);
|
|
309
|
+
const mapped = mapContentResult(result, url);
|
|
310
|
+
if (mapped) {
|
|
311
|
+
activityMonitor.logComplete(activityId, 200);
|
|
312
|
+
return mapped;
|
|
313
|
+
}
|
|
314
|
+
if (failedContentStatus(data, result, 0)) {
|
|
315
|
+
throw new Error(`Querit Contents API failed to crawl ${url}`);
|
|
316
|
+
}
|
|
317
|
+
activityMonitor.logComplete(activityId, 200);
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
const message = errorMessage(err);
|
|
322
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
323
|
+
if (signal?.aborted)
|
|
324
|
+
activityMonitor.logComplete(activityId, 0);
|
|
325
|
+
else
|
|
326
|
+
activityMonitor.logError(activityId, redactedMessage);
|
|
327
|
+
if (redactedMessage === message)
|
|
328
|
+
throw err;
|
|
329
|
+
const redactedError = new Error(redactedMessage);
|
|
330
|
+
if (err instanceof Error)
|
|
331
|
+
redactedError.name = err.name;
|
|
332
|
+
throw redactedError;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=querit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"querit.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/querit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,mBAAmB,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G,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACjD,IAAI,GAAG,YAAY,KAAK;YAAE,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACxD,MAAM,aAAa,CAAC;IACrB,CAAC;AAAA,CACD","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { activityMonitor } from \"./activity.ts\";\nimport { hasCredentialSource, redactCredential, resolveCredential } from \"./credential-source.ts\";\nimport type { ExtractedContent, ExtractOptions } from \"./extract.ts\";\nimport type { SearchOptions, SearchResponse } from \"./perplexity.ts\";\nimport { getWebSearchConfigPath } from \"./utils.ts\";\n\nconst QUERIT_SEARCH_URL = \"https://api.querit.ai/v1/search\";\nconst QUERIT_CONTENTS_URL = \"https://api.querit.ai/v1/contents\";\nconst CONFIG_PATH = getWebSearchConfigPath();\nconst SEARCH_TIMEOUT_MS = 60_000;\nconst CONTENTS_TIMEOUT_MS = 60_000;\nconst MAX_CONTENT_URLS = 10;\n\ninterface WebSearchConfig {\n\tqueritApiKey?: unknown;\n}\n\ninterface QueritSearchResult {\n\turl?: string | null;\n\ttitle?: string | null;\n\tsnippet?: string | null;\n\tpage_age?: string | null;\n\tsite_name?: string | null;\n}\n\ninterface QueritSearchResponse {\n\terror_code?: number | string;\n\terror_msg?: string;\n\tsearch_id?: number | string;\n\tresults?: { result?: QueritSearchResult[] };\n}\n\ninterface QueritContentMetadata {\n\ttitle?: string | null;\n\turl?: string | null;\n\tpublishTime?: string | null;\n\tsiteName?: string | null;\n\tsiteIcon?: string | null;\n}\n\ninterface QueritContentResult {\n\tid?: string | null;\n\turl?: string | null;\n\tcontent?: string | null;\n\textrasMeta?: QueritContentMetadata | null;\n}\n\ninterface QueritContentStatus {\n\tid?: string | null;\n\tstatus?: string | null;\n}\n\ninterface QueritContentsResponse {\n\terror_code?: number | string;\n\terror_msg?: string;\n\tsearch_id?: number | string;\n\tresults?: QueritContentResult[];\n\tstatuses?: QueritContentStatus[];\n\tsearchTime?: number;\n}\n\ninterface QueritSearchOptions extends SearchOptions {\n\tincludeContent?: boolean;\n}\n\nlet cachedConfig: WebSearchConfig | null = null;\n\nfunction loadConfig(): WebSearchConfig {\n\tif (cachedConfig) return cachedConfig;\n\tif (!existsSync(CONFIG_PATH)) {\n\t\tcachedConfig = {};\n\t\treturn cachedConfig;\n\t}\n\n\tconst raw = readFileSync(CONFIG_PATH, \"utf-8\");\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);\n\t}\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`Invalid config in ${CONFIG_PATH}: expected a JSON object`);\n\t}\n\tcachedConfig = parsed as WebSearchConfig;\n\treturn cachedConfig;\n}\n\nasync function getApiKey(signal?: AbortSignal): Promise<string> {\n\tconst key = await resolveCredential({\n\t\tprovider: \"Querit\",\n\t\tconfiguredValue: loadConfig().queritApiKey,\n\t\tenvironmentValue: process.env.QUERIT_API_KEY,\n\t\tsignal,\n\t});\n\tif (!key) {\n\t\tthrow new Error(\n\t\t\t\"Querit API key not found. Either:\\n\" +\n\t\t\t` 1. Create ${CONFIG_PATH} with { \"queritApiKey\": \"your-key\" }\\n` +\n\t\t\t\" 2. Set QUERIT_API_KEY environment variable\\n\" +\n\t\t\t\"Create a key at https://www.querit.ai/en/dashboard/api-keys\",\n\t\t);\n\t}\n\treturn key;\n}\n\nexport function isQueritAvailable(): boolean {\n\treturn hasCredentialSource({\n\t\tprovider: \"Querit\",\n\t\tconfiguredValue: loadConfig().queritApiKey,\n\t\tenvironmentValue: process.env.QUERIT_API_KEY,\n\t});\n}\n\nfunction errorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n\nfunction requestSignal(signal: AbortSignal | undefined, timeoutMs: number): AbortSignal {\n\tconst timeout = AbortSignal.timeout(timeoutMs);\n\treturn signal ? AbortSignal.any([signal, timeout]) : timeout;\n}\n\nfunction normalizeNumResults(value: number | undefined): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value)) return 5;\n\treturn Math.max(1, Math.min(Math.floor(value), 20));\n}\n\nfunction normalizeDomain(value: string): string | null {\n\tlet input = value.trim().toLowerCase();\n\tif (!input) return null;\n\tif (input.startsWith(\"-\")) input = input.slice(1).trim();\n\tif (!input) return null;\n\ttry {\n\t\tconst parsed = input.includes(\"://\") ? new URL(input) : new URL(`https://${input}`);\n\t\tinput = parsed.hostname;\n\t} catch {\n\t\tinput = input.split(\"/\")[0]?.split(\":\")[0] ?? \"\";\n\t}\n\tinput = input.replace(/^\\.+|\\.+$/g, \"\");\n\treturn /^[a-z0-9][a-z0-9.-]*\\.[a-z]{2,}$/i.test(input) ? input : null;\n}\n\nfunction mapDomainFilter(domainFilter: string[] | undefined): { include: string[]; exclude: string[] } {\n\tconst include: string[] = [];\n\tconst exclude: string[] = [];\n\tfor (const raw of domainFilter ?? []) {\n\t\tconst domain = normalizeDomain(raw);\n\t\tif (!domain) continue;\n\t\tconst target = raw.trim().startsWith(\"-\") ? exclude : include;\n\t\tif (!target.includes(domain)) target.push(domain);\n\t}\n\treturn { include, exclude };\n}\n\nfunction mapRecencyFilter(value: SearchOptions[\"recencyFilter\"]): string | undefined {\n\tif (value === \"day\") return \"d1\";\n\tif (value === \"week\") return \"w1\";\n\tif (value === \"month\") return \"m1\";\n\tif (value === \"year\") return \"y1\";\n\treturn undefined;\n}\n\nfunction buildSearchBody(query: string, options: QueritSearchOptions): Record<string, unknown> {\n\tconst { include, exclude } = mapDomainFilter(options.domainFilter);\n\tconst date = mapRecencyFilter(options.recencyFilter);\n\tconst filters: Record<string, unknown> = {};\n\tif (include.length > 0 || exclude.length > 0) {\n\t\tfilters.sites = {\n\t\t\t...(include.length > 0 ? { include } : {}),\n\t\t\t...(exclude.length > 0 ? { exclude } : {}),\n\t\t};\n\t}\n\tif (date) filters.timeRange = { date };\n\treturn {\n\t\tquery,\n\t\tcount: normalizeNumResults(options.numResults),\n\t\t...(Object.keys(filters).length > 0 ? { filters } : {}),\n\t};\n}\n\nfunction normalizeTimeoutMs(value: number | undefined): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value)) return CONTENTS_TIMEOUT_MS;\n\treturn Math.max(1, Math.floor(value));\n}\n\nfunction crawlTimeoutSeconds(value: number | undefined): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value)) return 10;\n\treturn Math.max(1, Math.min(Math.ceil(value / 1_000), 60));\n}\n\nfunction buildContentsBody(urls: string[], options: ExtractOptions = {}): Record<string, unknown> {\n\treturn {\n\t\turls,\n\t\tformat: \"markdown\",\n\t\tcrawlTimeout: crawlTimeoutSeconds(options.timeoutMs),\n\t\textrasMeta: true,\n\t};\n}\n\nasync function queritJsonRequest<T>(\n\tlabel: \"Search\" | \"Contents\",\n\turl: string,\n\tapiKey: string,\n\tbody: Record<string, unknown>,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<T> {\n\tlet response: Response;\n\ttry {\n\t\tresponse = await fetch(url, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\tAccept: \"application/json\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tbody: JSON.stringify(body),\n\t\t\tsignal: requestSignal(signal, timeoutMs),\n\t\t});\n\t} catch (err) {\n\t\tconst message = errorMessage(err);\n\t\tconst isRequestAbort = err instanceof Error\n\t\t\t? err.name === \"AbortError\" || err.name === \"TimeoutError\" || /abort|timeout/i.test(message)\n\t\t\t: /abort|timeout/i.test(message);\n\t\tif (!signal?.aborted && isRequestAbort) {\n\t\t\tconst timeoutError = new Error(`Querit ${label} API request timed out after ${Math.ceil(timeoutMs / 1_000)} seconds`);\n\t\t\ttimeoutError.name = \"TimeoutError\";\n\t\t\tthrow timeoutError;\n\t\t}\n\t\tconst redactedMessage = redactCredential(message, apiKey);\n\t\tif (redactedMessage === message) throw err;\n\t\tconst redactedError = new Error(redactedMessage);\n\t\tif (err instanceof Error) redactedError.name = err.name;\n\t\tthrow redactedError;\n\t}\n\n\tconst raw = await response.text();\n\tif (!response.ok) {\n\t\tthrow new Error(`Querit ${label} API error ${response.status}: ${redactCredential(raw, apiKey).slice(0, 300)}`);\n\t}\n\ttry {\n\t\treturn JSON.parse(raw) as T;\n\t} catch (err) {\n\t\tthrow new Error(`Querit ${label} API returned invalid JSON: ${errorMessage(err)}`);\n\t}\n}\n\nfunction assertApiSuccess(label: \"Search\" | \"Contents\", data: QueritSearchResponse | QueritContentsResponse): void {\n\tconst code = Number(data.error_code);\n\tif (!Number.isFinite(code) || code !== 200) {\n\t\tconst renderedCode = data.error_code === undefined ? \"unknown\" : String(data.error_code);\n\t\tconst message = typeof data.error_msg === \"string\" && data.error_msg.trim() ? `: ${data.error_msg.trim()}` : \"\";\n\t\tthrow new Error(`Querit ${label} API returned error ${renderedCode}${message}`);\n\t}\n}\n\nfunction mapSearchResults(data: QueritSearchResponse): SearchResponse[\"results\"] {\n\tconst items = data.results?.result;\n\tif (!Array.isArray(items)) {\n\t\tthrow new Error(\"Querit Search API returned an unexpected response shape\");\n\t}\n\treturn items.flatMap((item) => {\n\t\tif (!item || typeof item.url !== \"string\" || item.url.trim().length === 0) return [];\n\t\tconst url = item.url.trim();\n\t\treturn [{\n\t\t\ttitle: typeof item.title === \"string\" && item.title.trim() ? item.title.trim() : url,\n\t\t\turl,\n\t\t\tsnippet: typeof item.snippet === \"string\" ? item.snippet.replace(/\\s+/g, \" \").trim() : \"\",\n\t\t}];\n\t});\n}\n\nfunction buildAnswer(results: SearchResponse[\"results\"]): string {\n\treturn results.map((result) => {\n\t\tif (result.snippet) return `${result.snippet}\\nSource: ${result.title} (${result.url})`;\n\t\treturn `Source: ${result.title} (${result.url})`;\n\t}).join(\"\\n\\n\");\n}\n\nfunction mapContentResult(result: QueritContentResult | undefined, requestedUrl: string): ExtractedContent | null {\n\tif (!result || typeof result.content !== \"string\" || result.content.trim().length === 0) return null;\n\tconst metadata = result.extrasMeta;\n\treturn {\n\t\turl: requestedUrl,\n\t\ttitle: metadata && typeof metadata.title === \"string\" ? metadata.title.trim() : \"\",\n\t\tcontent: result.content.trim(),\n\t\terror: null,\n\t};\n}\n\nfunction findContentResult(\n\tdata: QueritContentsResponse,\n\trequestedUrl: string,\n\tindex: number,\n\trequestedCount: number,\n): QueritContentResult | undefined {\n\tif (!Array.isArray(data.results)) return undefined;\n\tconst exact = data.results.find((item) => item?.url === requestedUrl || item?.extrasMeta?.url === requestedUrl);\n\tif (exact) return exact;\n\tif (requestedCount === 1) return data.results[0];\n\treturn data.results.length === requestedCount ? data.results[index] : undefined;\n}\n\nfunction failedContentStatus(data: QueritContentsResponse, result: QueritContentResult | undefined, index: number): boolean {\n\tif (!Array.isArray(data.statuses)) return false;\n\tconst status = result?.id\n\t\t? data.statuses.find((item) => item?.id === result.id)\n\t\t: data.statuses[index];\n\treturn status?.status === \"failed\";\n}\n\nasync function fetchContentsBatch(\n\turls: string[],\n\tapiKey: string,\n\tsignal?: AbortSignal,\n\toptions: ExtractOptions = {},\n): Promise<QueritContentsResponse> {\n\tconst data = await queritJsonRequest<QueritContentsResponse>(\n\t\t\"Contents\",\n\t\tQUERIT_CONTENTS_URL,\n\t\tapiKey,\n\t\tbuildContentsBody(urls, options),\n\t\tnormalizeTimeoutMs(options.timeoutMs),\n\t\tsignal,\n\t);\n\tassertApiSuccess(\"Contents\", data);\n\tif (!Array.isArray(data.results) || !Array.isArray(data.statuses)) {\n\t\tthrow new Error(\"Querit Contents API returned an unexpected response shape\");\n\t}\n\treturn data;\n}\n\nasync function fetchInlineContent(urls: string[], apiKey: string, signal?: AbortSignal): Promise<ExtractedContent[]> {\n\tconst content: ExtractedContent[] = [];\n\tfor (let offset = 0; offset < urls.length; offset += MAX_CONTENT_URLS) {\n\t\tconst batch = urls.slice(offset, offset + MAX_CONTENT_URLS);\n\t\tconst data = await fetchContentsBatch(batch, apiKey, signal);\n\t\tfor (let index = 0; index < batch.length; index++) {\n\t\t\tconst requestedUrl = batch[index];\n\t\t\tconst result = findContentResult(data, requestedUrl, index, batch.length);\n\t\t\tconst mapped = mapContentResult(result, requestedUrl);\n\t\t\tif (mapped) content.push(mapped);\n\t\t}\n\t}\n\treturn content;\n}\n\nexport async function searchWithQuerit(\n\tquery: string,\n\toptions: QueritSearchOptions = {},\n): Promise<SearchResponse> {\n\tconst apiKey = await getApiKey(options.signal);\n\tconst activityId = activityMonitor.logStart({ type: \"api\", query });\n\ttry {\n\t\tconst data = await queritJsonRequest<QueritSearchResponse>(\n\t\t\t\"Search\",\n\t\t\tQUERIT_SEARCH_URL,\n\t\t\tapiKey,\n\t\t\tbuildSearchBody(query, options),\n\t\t\tSEARCH_TIMEOUT_MS,\n\t\t\toptions.signal,\n\t\t);\n\t\tassertApiSuccess(\"Search\", data);\n\t\tconst results = mapSearchResults(data);\n\t\tconst response: SearchResponse = { answer: buildAnswer(results), results };\n\t\tif (options.includeContent && results.length > 0) {\n\t\t\tconst inlineContent = await fetchInlineContent(results.map((result) => result.url), apiKey, options.signal);\n\t\t\tif (inlineContent.length > 0) response.inlineContent = inlineContent;\n\t\t}\n\t\tactivityMonitor.logComplete(activityId, 200);\n\t\treturn response;\n\t} catch (err) {\n\t\tconst message = errorMessage(err);\n\t\tconst redactedMessage = redactCredential(message, apiKey);\n\t\tif (options.signal?.aborted) activityMonitor.logComplete(activityId, 0);\n\t\telse activityMonitor.logError(activityId, redactedMessage);\n\t\tif (redactedMessage === message) throw err;\n\t\tconst redactedError = new Error(redactedMessage);\n\t\tif (err instanceof Error) redactedError.name = err.name;\n\t\tthrow redactedError;\n\t}\n}\n\nexport async function extractWithQuerit(\n\turl: string,\n\tsignal?: AbortSignal,\n\toptions: ExtractOptions = {},\n): Promise<ExtractedContent | null> {\n\tconst apiKey = await getApiKey(signal);\n\tconst activityId = activityMonitor.logStart({ type: \"fetch\", url });\n\ttry {\n\t\tconst data = await fetchContentsBatch([url], apiKey, signal, options);\n\t\tconst result = findContentResult(data, url, 0, 1);\n\t\tconst mapped = mapContentResult(result, url);\n\t\tif (mapped) {\n\t\t\tactivityMonitor.logComplete(activityId, 200);\n\t\t\treturn mapped;\n\t\t}\n\t\tif (failedContentStatus(data, result, 0)) {\n\t\t\tthrow new Error(`Querit Contents API failed to crawl ${url}`);\n\t\t}\n\t\tactivityMonitor.logComplete(activityId, 200);\n\t\treturn null;\n\t} catch (err) {\n\t\tconst message = errorMessage(err);\n\t\tconst redactedMessage = redactCredential(message, apiKey);\n\t\tif (signal?.aborted) activityMonitor.logComplete(activityId, 0);\n\t\telse activityMonitor.logError(activityId, redactedMessage);\n\t\tif (redactedMessage === message) throw err;\n\t\tconst redactedError = new Error(redactedMessage);\n\t\tif (err instanceof Error) redactedError.name = err.name;\n\t\tthrow redactedError;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, dependency-free renderer for web_search error / cancel results.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS: the upstream web_search `renderResult` (index.ts) early-returns
|
|
5
|
+
* a SINGLE line on the error/cancel path, before the collapsed/expanded branch.
|
|
6
|
+
* That makes Ctrl+O (app.tools.expand) flip `expanded` with zero visible effect —
|
|
7
|
+
* a dead-end with no diagnostics. It also discards the partial search results
|
|
8
|
+
* gathered before the cancel, so even an expandable view would have nothing to show.
|
|
9
|
+
*
|
|
10
|
+
* This module is the single source of truth for the error/cancel render PLAN
|
|
11
|
+
* (plain strings, no theme/ANSI), so it is unit-testable without pi's runtime
|
|
12
|
+
* (@mariozechner/pi-tui Text/Box). index.ts.renderResult delegates to it and only
|
|
13
|
+
* applies theme colors + creates Text/Box components.
|
|
14
|
+
*
|
|
15
|
+
* Contract for callers:
|
|
16
|
+
* const plan = buildSearchErrorPlan(details);
|
|
17
|
+
* if (plan === null) ... // not an error/cancel result; use the normal renderer
|
|
18
|
+
* // collapsed: [statusLine, ...plan.collapsed, plan.expandHint].filter(Boolean)
|
|
19
|
+
* // expanded: plan.expanded
|
|
20
|
+
*/
|
|
21
|
+
export interface CancelledQueryDetail {
|
|
22
|
+
query: string;
|
|
23
|
+
provider: string | null;
|
|
24
|
+
error: string | null;
|
|
25
|
+
resultCount: number;
|
|
26
|
+
}
|
|
27
|
+
export interface SearchErrorDetails {
|
|
28
|
+
/** The headline error/cancel message, e.g. "Search curation cancelled (stale)." */
|
|
29
|
+
error?: string;
|
|
30
|
+
cancelled?: boolean;
|
|
31
|
+
cancelReason?: string;
|
|
32
|
+
/** Did the curator browser page ever establish a connection? */
|
|
33
|
+
browserConnected?: boolean;
|
|
34
|
+
/** Age (ms) of the last curator heartbeat at cancel time, if known. */
|
|
35
|
+
lastHeartbeatAgeMs?: number | null;
|
|
36
|
+
/** Total queries the user requested. */
|
|
37
|
+
queryCount?: number;
|
|
38
|
+
/** Partial per-query results gathered before the cancel/error. */
|
|
39
|
+
cancelledQueries?: CancelledQueryDetail[];
|
|
40
|
+
/** Arbitrary extra diagnostic lines (e.g. URLs, response id) for non-cancel errors
|
|
41
|
+
* like fetch_content / get_search_content. Shown in the expanded view. */
|
|
42
|
+
extraLines?: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface SearchErrorPlan {
|
|
45
|
+
/** Full diagnostic block, shown when expanded (Ctrl+O). */
|
|
46
|
+
expanded: string[];
|
|
47
|
+
/** Short preview lines, shown under the headline when collapsed. */
|
|
48
|
+
collapsed: string[];
|
|
49
|
+
/** The "... (N more lines, ctrl+o to expand)" hint, or null if nothing is hidden. */
|
|
50
|
+
expandHint: string | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build the error/cancel render plan. Returns null when `details` carries no
|
|
54
|
+
* error/cancel signal (so the caller falls through to the normal success renderer).
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildSearchErrorPlan(details: SearchErrorDetails | undefined | null): SearchErrorPlan | null;
|
|
57
|
+
//# sourceMappingURL=render-search-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-search-error.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/render-search-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAClC,mFAAmF;IACnF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC1C;8EAC0E;IAC1E,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC/B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,oEAAoE;IACpE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,qFAAqF;IACrF,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAMD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,GAAG,eAAe,GAAG,IAAI,CA0G3G","sourcesContent":["/**\n * Pure, dependency-free renderer for web_search error / cancel results.\n *\n * WHY THIS EXISTS: the upstream web_search `renderResult` (index.ts) early-returns\n * a SINGLE line on the error/cancel path, before the collapsed/expanded branch.\n * That makes Ctrl+O (app.tools.expand) flip `expanded` with zero visible effect —\n * a dead-end with no diagnostics. It also discards the partial search results\n * gathered before the cancel, so even an expandable view would have nothing to show.\n *\n * This module is the single source of truth for the error/cancel render PLAN\n * (plain strings, no theme/ANSI), so it is unit-testable without pi's runtime\n * (@mariozechner/pi-tui Text/Box). index.ts.renderResult delegates to it and only\n * applies theme colors + creates Text/Box components.\n *\n * Contract for callers:\n * const plan = buildSearchErrorPlan(details);\n * if (plan === null) ... // not an error/cancel result; use the normal renderer\n * // collapsed: [statusLine, ...plan.collapsed, plan.expandHint].filter(Boolean)\n * // expanded: plan.expanded\n */\n\nexport interface CancelledQueryDetail {\n\tquery: string;\n\tprovider: string | null;\n\terror: string | null; // null = completed ok; string = per-query error\n\tresultCount: number;\n}\n\nexport interface SearchErrorDetails {\n\t/** The headline error/cancel message, e.g. \"Search curation cancelled (stale).\" */\n\terror?: string;\n\tcancelled?: boolean;\n\tcancelReason?: string;\n\t/** Did the curator browser page ever establish a connection? */\n\tbrowserConnected?: boolean;\n\t/** Age (ms) of the last curator heartbeat at cancel time, if known. */\n\tlastHeartbeatAgeMs?: number | null;\n\t/** Total queries the user requested. */\n\tqueryCount?: number;\n\t/** Partial per-query results gathered before the cancel/error. */\n\tcancelledQueries?: CancelledQueryDetail[];\n\t/** Arbitrary extra diagnostic lines (e.g. URLs, response id) for non-cancel errors\n\t * like fetch_content / get_search_content. Shown in the expanded view. */\n\textraLines?: string[];\n}\n\nexport interface SearchErrorPlan {\n\t/** Full diagnostic block, shown when expanded (Ctrl+O). */\n\texpanded: string[];\n\t/** Short preview lines, shown under the headline when collapsed. */\n\tcollapsed: string[];\n\t/** The \"... (N more lines, ctrl+o to expand)\" hint, or null if nothing is hidden. */\n\texpandHint: string | null;\n}\n\nfunction truncate(text: string, max: number): string {\n\treturn text.length > max ? text.slice(0, max - 1) + \"\\u2026\" : text;\n}\n\n/**\n * Build the error/cancel render plan. Returns null when `details` carries no\n * error/cancel signal (so the caller falls through to the normal success renderer).\n */\nexport function buildSearchErrorPlan(details: SearchErrorDetails | undefined | null): SearchErrorPlan | null {\n\tif (!details || (!details.error && !details.cancelled)) {\n\t\treturn null;\n\t}\n\n\tconst headline = details.error ?? \"Search cancelled.\";\n\tconst queries = details.cancelledQueries ?? [];\n\tconst queryCount = typeof details.queryCount === \"number\" && details.queryCount > 0\n\t\t? details.queryCount\n\t\t: queries.length;\n\tconst done = queries.length;\n\tconst errored = queries.filter(q => q.error).length;\n\n\t// Rich diagnostics only make sense when there is something to diagnose: a\n\t// cancelled/curator result with partial data, OR a non-cancel error that carries\n\t// extra detail (urls/response-id for fetch_content, the failed query for\n\t// get_search_content). A bare argument error (e.g. \"No URL\n\t// provided\") stays a clean single line -- no noise.\n\tconst extras = details.extraLines ?? [];\n\tconst rich = details.cancelled === true || queries.length > 0 || extras.length > 0;\n\tif (!rich) {\n\t\treturn { expanded: [headline], collapsed: [], expandHint: null };\n\t}\n\n\t// --- diagnostics block (expanded): curator/cancel-specific only. For non-cancel\n\t// errors (fetch_content/get_search_content) there is no browser or\n\t// query-curation state to report, so we skip this block and show only Details. ---\n\tconst expanded: string[] = [headline, \"\"];\n\n\tif (details.cancelled === true || queries.length > 0) {\n\t\tconst diag: string[] = [];\n\t\tif (details.cancelled) {\n\t\t\tdiag.push(`cancel reason : ${details.cancelReason ?? \"unknown\"}`);\n\t\t}\n\t\t// Browser connection state — the most common stale cause (page never opened).\n\t\tconst browserLabel = details.browserConnected === undefined\n\t\t\t? \"unknown\"\n\t\t\t: details.browserConnected\n\t\t\t\t? \"connected\"\n\t\t\t\t: \"never connected\";\n\t\tdiag.push(`browser : ${browserLabel}`);\n\t\tif (typeof details.lastHeartbeatAgeMs === \"number\" && Number.isFinite(details.lastHeartbeatAgeMs)) {\n\t\t\tdiag.push(`last heartbeat : ${Math.round(details.lastHeartbeatAgeMs / 1000)}s ago`);\n\t\t}\n\t\tif (queryCount > 0) {\n\t\t\tdiag.push(`queries started : ${queryCount}`);\n\t\t\tdiag.push(`queries done : ${done}`);\n\t\t\tif (errored > 0) diag.push(`queries errored : ${errored}`);\n\t\t}\n\t\texpanded.push(\"Diagnostics:\");\n\t\tfor (const line of diag) expanded.push(` ${line}`);\n\t}\n\n\t// --- per-query results gathered before cancel ---\n\tif (queries.length > 0) {\n\t\texpanded.push(\"\");\n\t\texpanded.push(\"Per-query results (gathered before cancel):\");\n\t\tfor (const q of queries) {\n\t\t\tconst dq = truncate(q.query, 52);\n\t\t\tconst tag = q.error ? \"[err] \" : \"[ok] \";\n\t\t\tconst provider = q.provider ? ` (${q.provider})` : \"\";\n\t\t\tconst tail = q.error\n\t\t\t\t? `\\u2014 ${truncate(q.error, 60)}`\n\t\t\t\t: `\\u2014 ${q.resultCount} source${q.resultCount === 1 ? \"\" : \"s\"}`;\n\t\t\texpanded.push(` ${tag}\"${dq}\"${provider} ${tail}`);\n\t\t}\n\t}\n\n\t// --- arbitrary extra detail (non-cancel errors) ---\n\tif (extras.length > 0) {\n\t\texpanded.push(\"\");\n\t\texpanded.push(\"Details:\");\n\t\tfor (const e of extras) expanded.push(` ${e}`);\n\t}\n\n\t// --- collapsed preview ---\n\tconst collapsed: string[] = [];\n\tconst parts: string[] = [];\n\tif (queryCount > 0) {\n\t\tparts.push(`${done}/${queryCount} queries completed`);\n\t}\n\tif (errored > 0) {\n\t\tparts.push(`${errored} errored`);\n\t}\n\tif (details.browserConnected === false) {\n\t\tparts.push(\"browser never connected\");\n\t} else if (details.cancelReason) {\n\t\tparts.push(`reason: ${details.cancelReason}`);\n\t}\n\tif (parts.length > 0) {\n\t\tcollapsed.push(parts.join(\"; \") + \".\");\n\t}\n\t// For non-cancel errors with extra detail, preview the first detail line.\n\tif (collapsed.length === 0 && extras.length > 0) {\n\t\tfor (const e of extras.slice(0, 2)) {\n\t\t\tcollapsed.push(truncate(e, 100));\n\t\t}\n\t}\n\n\t// --- expand hint ---\n\tconst hiddenLines = Math.max(0, expanded.length - (1 + collapsed.length)); // headline + preview shown when collapsed\n\tconst expandHint = hiddenLines > 0\n\t\t? `... (${hiddenLines} more lines, ${expanded.length} total, ctrl+o to expand)`\n\t\t: null;\n\n\treturn { expanded, collapsed, expandHint };\n}\n"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, dependency-free renderer for web_search error / cancel results.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS: the upstream web_search `renderResult` (index.ts) early-returns
|
|
5
|
+
* a SINGLE line on the error/cancel path, before the collapsed/expanded branch.
|
|
6
|
+
* That makes Ctrl+O (app.tools.expand) flip `expanded` with zero visible effect —
|
|
7
|
+
* a dead-end with no diagnostics. It also discards the partial search results
|
|
8
|
+
* gathered before the cancel, so even an expandable view would have nothing to show.
|
|
9
|
+
*
|
|
10
|
+
* This module is the single source of truth for the error/cancel render PLAN
|
|
11
|
+
* (plain strings, no theme/ANSI), so it is unit-testable without pi's runtime
|
|
12
|
+
* (@mariozechner/pi-tui Text/Box). index.ts.renderResult delegates to it and only
|
|
13
|
+
* applies theme colors + creates Text/Box components.
|
|
14
|
+
*
|
|
15
|
+
* Contract for callers:
|
|
16
|
+
* const plan = buildSearchErrorPlan(details);
|
|
17
|
+
* if (plan === null) ... // not an error/cancel result; use the normal renderer
|
|
18
|
+
* // collapsed: [statusLine, ...plan.collapsed, plan.expandHint].filter(Boolean)
|
|
19
|
+
* // expanded: plan.expanded
|
|
20
|
+
*/
|
|
21
|
+
function truncate(text, max) {
|
|
22
|
+
return text.length > max ? text.slice(0, max - 1) + "\u2026" : text;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the error/cancel render plan. Returns null when `details` carries no
|
|
26
|
+
* error/cancel signal (so the caller falls through to the normal success renderer).
|
|
27
|
+
*/
|
|
28
|
+
export function buildSearchErrorPlan(details) {
|
|
29
|
+
if (!details || (!details.error && !details.cancelled)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const headline = details.error ?? "Search cancelled.";
|
|
33
|
+
const queries = details.cancelledQueries ?? [];
|
|
34
|
+
const queryCount = typeof details.queryCount === "number" && details.queryCount > 0
|
|
35
|
+
? details.queryCount
|
|
36
|
+
: queries.length;
|
|
37
|
+
const done = queries.length;
|
|
38
|
+
const errored = queries.filter(q => q.error).length;
|
|
39
|
+
// Rich diagnostics only make sense when there is something to diagnose: a
|
|
40
|
+
// cancelled/curator result with partial data, OR a non-cancel error that carries
|
|
41
|
+
// extra detail (urls/response-id for fetch_content, the failed query for
|
|
42
|
+
// get_search_content). A bare argument error (e.g. "No URL
|
|
43
|
+
// provided") stays a clean single line -- no noise.
|
|
44
|
+
const extras = details.extraLines ?? [];
|
|
45
|
+
const rich = details.cancelled === true || queries.length > 0 || extras.length > 0;
|
|
46
|
+
if (!rich) {
|
|
47
|
+
return { expanded: [headline], collapsed: [], expandHint: null };
|
|
48
|
+
}
|
|
49
|
+
// --- diagnostics block (expanded): curator/cancel-specific only. For non-cancel
|
|
50
|
+
// errors (fetch_content/get_search_content) there is no browser or
|
|
51
|
+
// query-curation state to report, so we skip this block and show only Details. ---
|
|
52
|
+
const expanded = [headline, ""];
|
|
53
|
+
if (details.cancelled === true || queries.length > 0) {
|
|
54
|
+
const diag = [];
|
|
55
|
+
if (details.cancelled) {
|
|
56
|
+
diag.push(`cancel reason : ${details.cancelReason ?? "unknown"}`);
|
|
57
|
+
}
|
|
58
|
+
// Browser connection state — the most common stale cause (page never opened).
|
|
59
|
+
const browserLabel = details.browserConnected === undefined
|
|
60
|
+
? "unknown"
|
|
61
|
+
: details.browserConnected
|
|
62
|
+
? "connected"
|
|
63
|
+
: "never connected";
|
|
64
|
+
diag.push(`browser : ${browserLabel}`);
|
|
65
|
+
if (typeof details.lastHeartbeatAgeMs === "number" && Number.isFinite(details.lastHeartbeatAgeMs)) {
|
|
66
|
+
diag.push(`last heartbeat : ${Math.round(details.lastHeartbeatAgeMs / 1000)}s ago`);
|
|
67
|
+
}
|
|
68
|
+
if (queryCount > 0) {
|
|
69
|
+
diag.push(`queries started : ${queryCount}`);
|
|
70
|
+
diag.push(`queries done : ${done}`);
|
|
71
|
+
if (errored > 0)
|
|
72
|
+
diag.push(`queries errored : ${errored}`);
|
|
73
|
+
}
|
|
74
|
+
expanded.push("Diagnostics:");
|
|
75
|
+
for (const line of diag)
|
|
76
|
+
expanded.push(` ${line}`);
|
|
77
|
+
}
|
|
78
|
+
// --- per-query results gathered before cancel ---
|
|
79
|
+
if (queries.length > 0) {
|
|
80
|
+
expanded.push("");
|
|
81
|
+
expanded.push("Per-query results (gathered before cancel):");
|
|
82
|
+
for (const q of queries) {
|
|
83
|
+
const dq = truncate(q.query, 52);
|
|
84
|
+
const tag = q.error ? "[err] " : "[ok] ";
|
|
85
|
+
const provider = q.provider ? ` (${q.provider})` : "";
|
|
86
|
+
const tail = q.error
|
|
87
|
+
? `\u2014 ${truncate(q.error, 60)}`
|
|
88
|
+
: `\u2014 ${q.resultCount} source${q.resultCount === 1 ? "" : "s"}`;
|
|
89
|
+
expanded.push(` ${tag}"${dq}"${provider} ${tail}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// --- arbitrary extra detail (non-cancel errors) ---
|
|
93
|
+
if (extras.length > 0) {
|
|
94
|
+
expanded.push("");
|
|
95
|
+
expanded.push("Details:");
|
|
96
|
+
for (const e of extras)
|
|
97
|
+
expanded.push(` ${e}`);
|
|
98
|
+
}
|
|
99
|
+
// --- collapsed preview ---
|
|
100
|
+
const collapsed = [];
|
|
101
|
+
const parts = [];
|
|
102
|
+
if (queryCount > 0) {
|
|
103
|
+
parts.push(`${done}/${queryCount} queries completed`);
|
|
104
|
+
}
|
|
105
|
+
if (errored > 0) {
|
|
106
|
+
parts.push(`${errored} errored`);
|
|
107
|
+
}
|
|
108
|
+
if (details.browserConnected === false) {
|
|
109
|
+
parts.push("browser never connected");
|
|
110
|
+
}
|
|
111
|
+
else if (details.cancelReason) {
|
|
112
|
+
parts.push(`reason: ${details.cancelReason}`);
|
|
113
|
+
}
|
|
114
|
+
if (parts.length > 0) {
|
|
115
|
+
collapsed.push(parts.join("; ") + ".");
|
|
116
|
+
}
|
|
117
|
+
// For non-cancel errors with extra detail, preview the first detail line.
|
|
118
|
+
if (collapsed.length === 0 && extras.length > 0) {
|
|
119
|
+
for (const e of extras.slice(0, 2)) {
|
|
120
|
+
collapsed.push(truncate(e, 100));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// --- expand hint ---
|
|
124
|
+
const hiddenLines = Math.max(0, expanded.length - (1 + collapsed.length)); // headline + preview shown when collapsed
|
|
125
|
+
const expandHint = hiddenLines > 0
|
|
126
|
+
? `... (${hiddenLines} more lines, ${expanded.length} total, ctrl+o to expand)`
|
|
127
|
+
: null;
|
|
128
|
+
return { expanded, collapsed, expandHint };
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=render-search-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-search-error.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/render-search-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoCH,SAAS,QAAQ,CAAC,IAAY,EAAE,GAAW,EAAU;IACpD,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAAA,CACpE;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA8C,EAA0B;IAC5G,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,IAAI,mBAAmB,CAAC;IACtD,M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E,CAAC;QACxC,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACvC,CAAC;SAAM,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACxC,CAAC;IACD,0EAA0E;IAC1E,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YACpC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAClC,CAAC;IACF,CAAC;IAED,sBAAsB;IACtB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,0CAA0C;IACrH,MAAM,UAAU,GAAG,WAAW,GAAG,CAAC;QACjC,CAAC,CAAC,QAAQ,WAAW,gBAAgB,QAAQ,CAAC,MAAM,2BAA2B;QAC/E,CAAC,CAAC,IAAI,CAAC;IAER,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAAA,CAC3C","sourcesContent":["/**\n * Pure, dependency-free renderer for web_search error / cancel results.\n *\n * WHY THIS EXISTS: the upstream web_search `renderResult` (index.ts) early-returns\n * a SINGLE line on the error/cancel path, before the collapsed/expanded branch.\n * That makes Ctrl+O (app.tools.expand) flip `expanded` with zero visible effect —\n * a dead-end with no diagnostics. It also discards the partial search results\n * gathered before the cancel, so even an expandable view would have nothing to show.\n *\n * This module is the single source of truth for the error/cancel render PLAN\n * (plain strings, no theme/ANSI), so it is unit-testable without pi's runtime\n * (@mariozechner/pi-tui Text/Box). index.ts.renderResult delegates to it and only\n * applies theme colors + creates Text/Box components.\n *\n * Contract for callers:\n * const plan = buildSearchErrorPlan(details);\n * if (plan === null) ... // not an error/cancel result; use the normal renderer\n * // collapsed: [statusLine, ...plan.collapsed, plan.expandHint].filter(Boolean)\n * // expanded: plan.expanded\n */\n\nexport interface CancelledQueryDetail {\n\tquery: string;\n\tprovider: string | null;\n\terror: string | null; // null = completed ok; string = per-query error\n\tresultCount: number;\n}\n\nexport interface SearchErrorDetails {\n\t/** The headline error/cancel message, e.g. \"Search curation cancelled (stale).\" */\n\terror?: string;\n\tcancelled?: boolean;\n\tcancelReason?: string;\n\t/** Did the curator browser page ever establish a connection? */\n\tbrowserConnected?: boolean;\n\t/** Age (ms) of the last curator heartbeat at cancel time, if known. */\n\tlastHeartbeatAgeMs?: number | null;\n\t/** Total queries the user requested. */\n\tqueryCount?: number;\n\t/** Partial per-query results gathered before the cancel/error. */\n\tcancelledQueries?: CancelledQueryDetail[];\n\t/** Arbitrary extra diagnostic lines (e.g. URLs, response id) for non-cancel errors\n\t * like fetch_content / get_search_content. Shown in the expanded view. */\n\textraLines?: string[];\n}\n\nexport interface SearchErrorPlan {\n\t/** Full diagnostic block, shown when expanded (Ctrl+O). */\n\texpanded: string[];\n\t/** Short preview lines, shown under the headline when collapsed. */\n\tcollapsed: string[];\n\t/** The \"... (N more lines, ctrl+o to expand)\" hint, or null if nothing is hidden. */\n\texpandHint: string | null;\n}\n\nfunction truncate(text: string, max: number): string {\n\treturn text.length > max ? text.slice(0, max - 1) + \"\\u2026\" : text;\n}\n\n/**\n * Build the error/cancel render plan. Returns null when `details` carries no\n * error/cancel signal (so the caller falls through to the normal success renderer).\n */\nexport function buildSearchErrorPlan(details: SearchErrorDetails | undefined | null): SearchErrorPlan | null {\n\tif (!details || (!details.error && !details.cancelled)) {\n\t\treturn null;\n\t}\n\n\tconst headline = details.error ?? \"Search cancelled.\";\n\tconst queries = details.cancelledQueries ?? [];\n\tconst queryCount = typeof details.queryCount === \"number\" && details.queryCount > 0\n\t\t? details.queryCount\n\t\t: queries.length;\n\tconst done = queries.length;\n\tconst errored = queries.filter(q => q.error).length;\n\n\t// Rich diagnostics only make sense when there is something to diagnose: a\n\t// cancelled/curator result with partial data, OR a non-cancel error that carries\n\t// extra detail (urls/response-id for fetch_content, the failed query for\n\t// get_search_content). A bare argument error (e.g. \"No URL\n\t// provided\") stays a clean single line -- no noise.\n\tconst extras = details.extraLines ?? [];\n\tconst rich = details.cancelled === true || queries.length > 0 || extras.length > 0;\n\tif (!rich) {\n\t\treturn { expanded: [headline], collapsed: [], expandHint: null };\n\t}\n\n\t// --- diagnostics block (expanded): curator/cancel-specific only. For non-cancel\n\t// errors (fetch_content/get_search_content) there is no browser or\n\t// query-curation state to report, so we skip this block and show only Details. ---\n\tconst expanded: string[] = [headline, \"\"];\n\n\tif (details.cancelled === true || queries.length > 0) {\n\t\tconst diag: string[] = [];\n\t\tif (details.cancelled) {\n\t\t\tdiag.push(`cancel reason : ${details.cancelReason ?? \"unknown\"}`);\n\t\t}\n\t\t// Browser connection state — the most common stale cause (page never opened).\n\t\tconst browserLabel = details.browserConnected === undefined\n\t\t\t? \"unknown\"\n\t\t\t: details.browserConnected\n\t\t\t\t? \"connected\"\n\t\t\t\t: \"never connected\";\n\t\tdiag.push(`browser : ${browserLabel}`);\n\t\tif (typeof details.lastHeartbeatAgeMs === \"number\" && Number.isFinite(details.lastHeartbeatAgeMs)) {\n\t\t\tdiag.push(`last heartbeat : ${Math.round(details.lastHeartbeatAgeMs / 1000)}s ago`);\n\t\t}\n\t\tif (queryCount > 0) {\n\t\t\tdiag.push(`queries started : ${queryCount}`);\n\t\t\tdiag.push(`queries done : ${done}`);\n\t\t\tif (errored > 0) diag.push(`queries errored : ${errored}`);\n\t\t}\n\t\texpanded.push(\"Diagnostics:\");\n\t\tfor (const line of diag) expanded.push(` ${line}`);\n\t}\n\n\t// --- per-query results gathered before cancel ---\n\tif (queries.length > 0) {\n\t\texpanded.push(\"\");\n\t\texpanded.push(\"Per-query results (gathered before cancel):\");\n\t\tfor (const q of queries) {\n\t\t\tconst dq = truncate(q.query, 52);\n\t\t\tconst tag = q.error ? \"[err] \" : \"[ok] \";\n\t\t\tconst provider = q.provider ? ` (${q.provider})` : \"\";\n\t\t\tconst tail = q.error\n\t\t\t\t? `\\u2014 ${truncate(q.error, 60)}`\n\t\t\t\t: `\\u2014 ${q.resultCount} source${q.resultCount === 1 ? \"\" : \"s\"}`;\n\t\t\texpanded.push(` ${tag}\"${dq}\"${provider} ${tail}`);\n\t\t}\n\t}\n\n\t// --- arbitrary extra detail (non-cancel errors) ---\n\tif (extras.length > 0) {\n\t\texpanded.push(\"\");\n\t\texpanded.push(\"Details:\");\n\t\tfor (const e of extras) expanded.push(` ${e}`);\n\t}\n\n\t// --- collapsed preview ---\n\tconst collapsed: string[] = [];\n\tconst parts: string[] = [];\n\tif (queryCount > 0) {\n\t\tparts.push(`${done}/${queryCount} queries completed`);\n\t}\n\tif (errored > 0) {\n\t\tparts.push(`${errored} errored`);\n\t}\n\tif (details.browserConnected === false) {\n\t\tparts.push(\"browser never connected\");\n\t} else if (details.cancelReason) {\n\t\tparts.push(`reason: ${details.cancelReason}`);\n\t}\n\tif (parts.length > 0) {\n\t\tcollapsed.push(parts.join(\"; \") + \".\");\n\t}\n\t// For non-cancel errors with extra detail, preview the first detail line.\n\tif (collapsed.length === 0 && extras.length > 0) {\n\t\tfor (const e of extras.slice(0, 2)) {\n\t\t\tcollapsed.push(truncate(e, 100));\n\t\t}\n\t}\n\n\t// --- expand hint ---\n\tconst hiddenLines = Math.max(0, expanded.length - (1 + collapsed.length)); // headline + preview shown when collapsed\n\tconst expandHint = hiddenLines > 0\n\t\t? `... (${hiddenLines} more lines, ${expanded.length} total, ctrl+o to expand)`\n\t\t: null;\n\n\treturn { expanded, collapsed, expandHint };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSC Content Extractor
|
|
3
|
+
*
|
|
4
|
+
* Extracts readable content from Next.js React Server Components (RSC) flight payloads.
|
|
5
|
+
* RSC pages embed content as JSON in <script>self.__next_f.push([...])</script> tags.
|
|
6
|
+
*/
|
|
7
|
+
export interface RSCExtractResult {
|
|
8
|
+
title: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function extractRSCContent(html: string): RSCExtractResult | null;
|
|
12
|
+
//# sourceMappingURL=rsc-extract.d.ts.map
|