@humain/terminal 0.0.2 → 0.0.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +241 -24
- package/README.md +143 -119
- package/dist/cli/args.d.ts +4 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +37 -39
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-check.d.ts +19 -0
- package/dist/cli/auth-check.d.ts.map +1 -0
- package/dist/cli/auth-check.js +50 -0
- package/dist/cli/auth-check.js.map +1 -0
- package/dist/cli/auth-command.d.ts +24 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +103 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +2 -2
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +5 -15
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +42 -83
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/experimental/auth.d.ts +16 -0
- package/dist/cli/experimental/auth.d.ts.map +1 -0
- package/dist/cli/experimental/auth.js +13 -0
- package/dist/cli/experimental/auth.js.map +1 -0
- package/dist/cli/experimental/cli.d.ts +6 -0
- package/dist/cli/experimental/cli.d.ts.map +1 -0
- package/dist/cli/experimental/cli.js +5 -0
- package/dist/cli/experimental/cli.js.map +1 -0
- package/dist/cli/experimental/command-options.d.ts +17 -0
- package/dist/cli/experimental/command-options.d.ts.map +1 -0
- package/dist/cli/experimental/command-options.js +35 -0
- package/dist/cli/experimental/command-options.js.map +1 -0
- package/dist/cli/experimental/command.d.ts +63 -0
- package/dist/cli/experimental/command.d.ts.map +1 -0
- package/dist/cli/experimental/command.js +130 -0
- package/dist/cli/experimental/command.js.map +1 -0
- package/dist/cli/experimental/commands/client.d.ts +13 -0
- package/dist/cli/experimental/commands/client.d.ts.map +1 -0
- package/dist/cli/experimental/commands/client.js +25 -0
- package/dist/cli/experimental/commands/client.js.map +1 -0
- package/dist/cli/experimental/commands/pi.d.ts +15 -0
- package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
- package/dist/cli/experimental/commands/pi.js +28 -0
- package/dist/cli/experimental/commands/pi.js.map +1 -0
- package/dist/cli/experimental/commands/server.d.ts +13 -0
- package/dist/cli/experimental/commands/server.d.ts.map +1 -0
- package/dist/cli/experimental/commands/server.js +25 -0
- package/dist/cli/experimental/commands/server.js.map +1 -0
- package/dist/cli/experimental/transport-address.d.ts +10 -0
- package/dist/cli/experimental/transport-address.d.ts.map +1 -0
- package/dist/cli/experimental/transport-address.js +38 -0
- package/dist/cli/experimental/transport-address.js.map +1 -0
- package/dist/cli/list-models.d.ts +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +2 -2
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +2 -2
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/remote-session.d.ts +53 -0
- package/dist/client/remote-session.d.ts.map +1 -0
- package/dist/client/remote-session.js +340 -0
- package/dist/client/remote-session.js.map +1 -0
- package/dist/client/transcript.d.ts +12 -0
- package/dist/client/transcript.d.ts.map +1 -0
- package/dist/client/transcript.js +98 -0
- package/dist/client/transcript.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -10
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +72 -70
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +25 -9
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +237 -39
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +60 -41
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +27 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +5 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts +45 -5
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +29 -5
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +4 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -3
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -10
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +4 -3
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +42 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +30 -13
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +233 -73
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts +12 -7
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +83 -14
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts +6 -3
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +80 -61
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts +8 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +28 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/provider-composer.d.ts +4 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +36 -15
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +73 -67
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +5 -5
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +11 -8
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +3 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +12 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +40 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +5 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -15
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +4 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +11 -7
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +7 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +16 -19
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +4 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +5 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +4 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +5 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +7 -3
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +4 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +6 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +11 -2
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +21 -7
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/humain/agent-execution-protocol.d.ts +218 -0
- package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
- package/dist/humain/agent-execution-protocol.js +204 -0
- package/dist/humain/agent-execution-protocol.js.map +1 -0
- package/dist/humain/agent-execution-runtime.d.ts +35 -0
- package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
- package/dist/humain/agent-execution-runtime.js +170 -0
- package/dist/humain/agent-execution-runtime.js.map +1 -0
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +8 -7
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +660 -0
- package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/dist/humain/mcp-adapter/vendor/README.md +733 -0
- package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
- package/dist/humain/mcp-adapter/vendor/agent-dir.ts +60 -0
- package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
- package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
- package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
- package/dist/humain/mcp-adapter/vendor/cli.js +209 -0
- package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
- package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
- package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +604 -0
- package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
- package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
- package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
- package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
- package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +15923 -0
- package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
- package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
- package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
- package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
- package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
- package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
- package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
- package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
- package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
- package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +666 -0
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
- package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +353 -0
- package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
- package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
- package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
- package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
- package/dist/humain/mcp-adapter/vendor/package.json +178 -0
- package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
- package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
- package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
- package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
- package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
- package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +1124 -0
- package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
- package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
- package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
- package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +276 -0
- package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
- package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
- package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
- package/dist/humain/mcp-adapter/vendor/types.ts +859 -0
- package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
- package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
- package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
- package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
- package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
- package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
- package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
- package/dist/humain/mcp-adapter.d.ts +3 -0
- package/dist/humain/mcp-adapter.d.ts.map +1 -0
- package/dist/humain/mcp-adapter.js +5 -0
- package/dist/humain/mcp-adapter.js.map +1 -0
- package/dist/humain/pi-agent-execution-host.d.ts +34 -0
- package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
- package/dist/humain/pi-agent-execution-host.js +77 -0
- package/dist/humain/pi-agent-execution-host.js.map +1 -0
- package/dist/humain/web-access/host.d.ts +4 -0
- package/dist/humain/web-access/host.d.ts.map +1 -0
- package/dist/humain/web-access/host.js +3 -0
- package/dist/humain/web-access/host.js.map +1 -0
- package/dist/humain/web-access/index.d.ts +3 -0
- package/dist/humain/web-access/index.d.ts.map +1 -0
- package/dist/humain/web-access/index.js +5 -0
- package/dist/humain/web-access/index.js.map +1 -0
- package/dist/humain/web-access/vendor/activity.d.ts +34 -0
- package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/activity.js +68 -0
- package/dist/humain/web-access/vendor/activity.js.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.js +167 -0
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
- package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/bocha.js +219 -0
- package/dist/humain/web-access/vendor/bocha.js.map +1 -0
- package/dist/humain/web-access/vendor/brave.d.ts +4 -0
- package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brave.js +194 -0
- package/dist/humain/web-access/vendor/brave.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.js +519 -0
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts +10 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js +438 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
- package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
- package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/content-find.js +117 -0
- package/dist/humain/web-access/vendor/content-find.js.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.js +151 -0
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts +29 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.js +3554 -0
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +93 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.js +688 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
- package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
- package/dist/humain/web-access/vendor/exa.d.ts +10 -0
- package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/exa.js +426 -0
- package/dist/humain/web-access/vendor/exa.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts +46 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/extract.js +1064 -0
- package/dist/humain/web-access/vendor/extract.js.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.js +27 -0
- package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts +25 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.js +57 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts +12 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.js +239 -0
- package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.js +230 -0
- package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.js +814 -0
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.js +385 -0
- package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
- package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
- package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-api.js +160 -0
- package/dist/humain/web-access/vendor/github-api.js.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.js +635 -0
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/index.d.ts +4 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/index.js +3002 -0
- package/dist/humain/web-access/vendor/index.js.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.js +255 -0
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
- package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/kagi.js +262 -0
- package/dist/humain/web-access/vendor/kagi.js.map +1 -0
- package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ollama.js +216 -0
- package/dist/humain/web-access/vendor/ollama.js.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.js +459 -0
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/page-query.js +79 -0
- package/dist/humain/web-access/vendor/page-query.js.map +1 -0
- package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
- package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/parallel.js +343 -0
- package/dist/humain/web-access/vendor/parallel.js.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
- package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.js +159 -0
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
- package/dist/humain/web-access/vendor/querit.d.ts +10 -0
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/querit.js +335 -0
- package/dist/humain/web-access/vendor/querit.js.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.js +130 -0
- package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
- package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/search1api.js +251 -0
- package/dist/humain/web-access/vendor/search1api.js.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
- package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
- package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searxng.js +238 -0
- package/dist/humain/web-access/vendor/searxng.js.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.js +211 -0
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.js +267 -0
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
- package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
- package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/source-check.js +205 -0
- package/dist/humain/web-access/vendor/source-check.js.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
- package/dist/humain/web-access/vendor/storage.d.ts +55 -0
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/storage.js +485 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts +24 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.js +341 -0
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
- package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
- package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tavily.js +194 -0
- package/dist/humain/web-access/vendor/tavily.js.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.js +331 -0
- package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
- package/dist/humain/web-access/vendor/utils.d.ts +20 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/utils.js +91 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.js +335 -0
- package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.js +331 -0
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
- package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +169 -102
- package/dist/main.js.map +1 -1
- package/dist/modes/agent-exec-mode.d.ts +14 -0
- package/dist/modes/agent-exec-mode.d.ts.map +1 -0
- package/dist/modes/agent-exec-mode.js +92 -0
- package/dist/modes/agent-exec-mode.js.map +1 -0
- package/dist/modes/index.d.ts +4 -2
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +2 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +75 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +30 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +3 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +9 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +45 -9
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +581 -211
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -0
- package/dist/modes/interactive/theme/light.json +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +10 -1
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +5 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +24 -6
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +28 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +12 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +12 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +12 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +55 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +13 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +11 -9
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js +3 -2
- package/dist/rpc-entry.js.map +1 -1
- package/dist/server/create-harness.d.ts +26 -0
- package/dist/server/create-harness.d.ts.map +1 -0
- package/dist/server/create-harness.js +104 -0
- package/dist/server/create-harness.js.map +1 -0
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +48 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +22 -2
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/management-http.d.ts +23 -0
- package/dist/utils/management-http.d.ts.map +1 -0
- package/dist/utils/management-http.js +50 -0
- package/dist/utils/management-http.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +23 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +19 -0
- package/dist/utils/tool-result-images.d.ts.map +1 -0
- package/dist/utils/tool-result-images.js +45 -0
- package/dist/utils/tool-result-images.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +13 -25
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +4 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +23 -5
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +2 -2
- package/docs/custom-provider.md +7 -5
- package/docs/extensions.md +30 -5
- package/docs/humain-terminal.md +21 -1
- package/docs/json.md +24 -19
- package/docs/keybindings.md +46 -14
- package/docs/models.md +32 -11
- package/docs/providers.md +9 -1
- package/docs/quickstart.md +39 -37
- package/docs/rpc.md +31 -11
- package/docs/sdk.md +21 -2
- package/docs/security.md +21 -21
- package/docs/session-format.md +14 -14
- package/docs/settings.md +4 -1
- package/docs/themes.md +5 -3
- package/docs/usage.md +7 -0
- package/examples/extensions/custom-compaction.ts +3 -18
- package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +4 -13
- package/examples/extensions/qna.ts +5 -9
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +9 -20
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +11 -2
- package/examples/sdk/02-custom-model.ts +2 -3
- package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +2771 -535
- package/package.json +40 -11
- package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
- package/src/humain/mcp-adapter/upstream.json +7 -0
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +660 -0
- package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/src/humain/web-access/UPSTREAM.md +17 -0
- package/src/humain/web-access/upstream.json +23 -0
- package/src/humain/web-access/vendor/LICENSE +21 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { getLastGoogleCookieDiagnostic, getGoogleCookies } from "./chrome-cookies.js";
|
|
4
|
+
import { getChromeProfileFromConfig, isBrowserCookieAccessAllowed, normalizeChromeProfile } from "./gemini-web-config.js";
|
|
5
|
+
const GEMINI_APP_URL = "https://gemini.google.com/app";
|
|
6
|
+
const GEMINI_STREAM_GENERATE_URL = "https://gemini.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate";
|
|
7
|
+
const GEMINI_UPLOAD_URL = "https://content-push.googleapis.com/upload";
|
|
8
|
+
const GEMINI_UPLOAD_PUSH_ID = "feeds/mcudyrk2a4khkz";
|
|
9
|
+
const GOOGLE_LIST_ACCOUNTS_URL = "https://accounts.google.com/ListAccounts?gpsia=1&source=ChromiumBrowser&laf=b64bin&json=standard";
|
|
10
|
+
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
11
|
+
const MODEL_HEADER_NAME = "x-goog-ext-525001261-jspb";
|
|
12
|
+
export const DEFAULT_GEMINI_WEB_MODEL = "gemini-3.1-pro";
|
|
13
|
+
const MODEL_HEADERS = {
|
|
14
|
+
[DEFAULT_GEMINI_WEB_MODEL]: '[1,null,null,null,"9d8ca3786ebdfbea",null,null,0,[4]]',
|
|
15
|
+
"gemini-2.5-pro": '[1,null,null,null,"4af6c7f5da75d65d",null,null,0,[4]]',
|
|
16
|
+
"gemini-2.5-flash": '[1,null,null,null,"9ec249fc9ad08861",null,null,0,[4]]',
|
|
17
|
+
};
|
|
18
|
+
const REQUIRED_COOKIES = ["__Secure-1PSID", "__Secure-1PSIDTS"];
|
|
19
|
+
// Gemini Web talks to Google's frontend inside the host agent (pi), whose
|
|
20
|
+
// global undici dispatcher runs HTTP/1.1 with undici's default 16 KiB
|
|
21
|
+
// maxHeaderSize. Google's gemini.google.com /app response headers routinely
|
|
22
|
+
// exceed that budget over HTTP/1.1, so cookie-bearing requests fail with
|
|
23
|
+
// UND_ERR_HEADERS_OVERFLOW surfaced as "fetch failed". Route these requests
|
|
24
|
+
// through a dedicated undici Agent with a larger header budget instead; fall
|
|
25
|
+
// back to the ambient global fetch when undici is not resolvable (e.g.
|
|
26
|
+
// standalone test environments).
|
|
27
|
+
let geminiFetchImpl = null;
|
|
28
|
+
// Test-only hook: lets tests inject a simulated transport instead of patching
|
|
29
|
+
// globalThis.fetch. Gemini Web deliberately bypasses the ambient global fetch
|
|
30
|
+
// (inside the pi host agent it is constrained to undici's 16 KiB
|
|
31
|
+
// maxHeaderSize and cannot serve Google's /app page over HTTP/1.1), so
|
|
32
|
+
// globalThis.fetch patching is no longer a reliable way to intercept these
|
|
33
|
+
// requests.
|
|
34
|
+
export function setGeminiFetchOverrideForTests(fetchImpl) {
|
|
35
|
+
geminiFetchOverride = fetchImpl;
|
|
36
|
+
}
|
|
37
|
+
let geminiFetchOverride = null;
|
|
38
|
+
// The header budget Gemini Web needs for Google frontend responses.
|
|
39
|
+
// Google's /app page exceeds undici's default 16 KiB maxHeaderSize when
|
|
40
|
+
// served over HTTP/1.1, which is how pi's global dispatcher operates.
|
|
41
|
+
export const GEMINI_MAX_HEADER_SIZE = 4 * 1024 * 1024;
|
|
42
|
+
// Build a fetch that routes through a dedicated undici Agent with a larger
|
|
43
|
+
// header budget than the host agent's global dispatcher allows. Exported for
|
|
44
|
+
// tests so the agent configuration can be asserted without network access.
|
|
45
|
+
export function createGeminiFetch(undiciImpl) {
|
|
46
|
+
const agent = new undiciImpl.EnvHttpProxyAgent({
|
|
47
|
+
allowH2: false,
|
|
48
|
+
connectTimeout: 30_000,
|
|
49
|
+
maxHeaderSize: GEMINI_MAX_HEADER_SIZE,
|
|
50
|
+
pipelining: 1,
|
|
51
|
+
});
|
|
52
|
+
return (input, init) => undiciImpl.fetch(input, { ...init, dispatcher: agent });
|
|
53
|
+
}
|
|
54
|
+
export async function resolveGeminiFetch() {
|
|
55
|
+
if (geminiFetchOverride)
|
|
56
|
+
return geminiFetchOverride;
|
|
57
|
+
if (geminiFetchImpl)
|
|
58
|
+
return geminiFetchImpl;
|
|
59
|
+
let undici;
|
|
60
|
+
try {
|
|
61
|
+
undici = await import("undici");
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
geminiFetchImpl = fetch;
|
|
65
|
+
return geminiFetchImpl;
|
|
66
|
+
}
|
|
67
|
+
geminiFetchImpl = createGeminiFetch(undici);
|
|
68
|
+
return geminiFetchImpl;
|
|
69
|
+
}
|
|
70
|
+
export async function isGeminiWebAvailable(chromeProfile) {
|
|
71
|
+
if (!isBrowserCookieAccessAllowed())
|
|
72
|
+
return null;
|
|
73
|
+
const result = await getGoogleCookies({
|
|
74
|
+
profile: normalizeChromeProfile(chromeProfile) ?? getChromeProfileFromConfig(),
|
|
75
|
+
requiredCookies: REQUIRED_COOKIES,
|
|
76
|
+
});
|
|
77
|
+
if (!result)
|
|
78
|
+
return null;
|
|
79
|
+
return result.cookies;
|
|
80
|
+
}
|
|
81
|
+
export function getGeminiWebAvailabilityDiagnostic() {
|
|
82
|
+
return isBrowserCookieAccessAllowed() ? getLastGoogleCookieDiagnostic() : null;
|
|
83
|
+
}
|
|
84
|
+
export async function getActiveGoogleEmail(cookies) {
|
|
85
|
+
const cookieHeader = buildCookieHeader(cookies);
|
|
86
|
+
if (!cookieHeader)
|
|
87
|
+
return null;
|
|
88
|
+
try {
|
|
89
|
+
const html = await fetchWithCookieRedirects(GEMINI_APP_URL, cookieHeader, 10, AbortSignal.timeout(10000));
|
|
90
|
+
const email = extractEmailFromGeminiHtml(html);
|
|
91
|
+
if (email)
|
|
92
|
+
return email;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const response = await fetchWithCookieRedirects(GOOGLE_LIST_ACCOUNTS_URL, cookieHeader, 10, AbortSignal.timeout(10000));
|
|
98
|
+
return extractEmailFromListAccounts(response);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export async function queryWithCookies(prompt, cookieMap, options = {}) {
|
|
105
|
+
const model = options.model ?? DEFAULT_GEMINI_WEB_MODEL;
|
|
106
|
+
if (!MODEL_HEADERS[model]) {
|
|
107
|
+
throw new Error(`Gemini Web does not support model ${model}; configure Gemini API or choose a supported Gemini Web model.`);
|
|
108
|
+
}
|
|
109
|
+
const timeoutMs = options.timeoutMs ?? 120000;
|
|
110
|
+
let fullPrompt = prompt;
|
|
111
|
+
if (options.youtubeUrl) {
|
|
112
|
+
fullPrompt = `${fullPrompt}\n\nYouTube video: ${options.youtubeUrl}`;
|
|
113
|
+
}
|
|
114
|
+
const result = await runGeminiWebOnce(fullPrompt, cookieMap, model, options.files, timeoutMs, options.signal);
|
|
115
|
+
if (result.errorMessage)
|
|
116
|
+
throw new Error(result.errorMessage);
|
|
117
|
+
if (!result.text)
|
|
118
|
+
throw new Error("Gemini Web returned empty response");
|
|
119
|
+
return result.text;
|
|
120
|
+
}
|
|
121
|
+
async function runGeminiWebOnce(prompt, cookieMap, model, files, timeoutMs, signal) {
|
|
122
|
+
const effectiveSignal = withTimeout(signal, timeoutMs);
|
|
123
|
+
const cookieHeader = buildCookieHeader(cookieMap);
|
|
124
|
+
const accessToken = await fetchAccessToken(cookieHeader, effectiveSignal);
|
|
125
|
+
const uploaded = [];
|
|
126
|
+
if (files) {
|
|
127
|
+
for (const filePath of files) {
|
|
128
|
+
uploaded.push(await uploadFile(filePath, cookieHeader, effectiveSignal));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const fReq = buildFReqPayload(prompt, uploaded);
|
|
132
|
+
const params = new URLSearchParams();
|
|
133
|
+
params.set("at", accessToken);
|
|
134
|
+
params.set("f.req", fReq);
|
|
135
|
+
const res = await (await resolveGeminiFetch())(GEMINI_STREAM_GENERATE_URL, {
|
|
136
|
+
method: "POST",
|
|
137
|
+
redirect: "error",
|
|
138
|
+
headers: {
|
|
139
|
+
"content-type": "application/x-www-form-urlencoded;charset=utf-8",
|
|
140
|
+
host: "gemini.google.com",
|
|
141
|
+
origin: "https://gemini.google.com",
|
|
142
|
+
referer: "https://gemini.google.com/",
|
|
143
|
+
"x-same-domain": "1",
|
|
144
|
+
"user-agent": USER_AGENT,
|
|
145
|
+
cookie: cookieHeader,
|
|
146
|
+
[MODEL_HEADER_NAME]: MODEL_HEADERS[model],
|
|
147
|
+
},
|
|
148
|
+
body: params.toString(),
|
|
149
|
+
signal: effectiveSignal,
|
|
150
|
+
});
|
|
151
|
+
const rawText = await res.text();
|
|
152
|
+
if (!res.ok) {
|
|
153
|
+
return { text: "", errorMessage: `Gemini request failed: ${res.status}` };
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return parseStreamGenerateResponse(rawText);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
let errorCode;
|
|
160
|
+
try {
|
|
161
|
+
const json = JSON.parse(trimJsonEnvelope(rawText));
|
|
162
|
+
errorCode = extractErrorCode(json);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
text: "",
|
|
168
|
+
errorCode,
|
|
169
|
+
errorMessage: err instanceof Error ? err.message : String(err),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function fetchAccessToken(cookieHeader, signal) {
|
|
174
|
+
const html = await fetchWithCookieRedirects(GEMINI_APP_URL, cookieHeader, 10, signal);
|
|
175
|
+
for (const key of ["SNlM0e", "thykhd"]) {
|
|
176
|
+
const match = html.match(new RegExp(`"${key}":"(.*?)"`));
|
|
177
|
+
if (match?.[1])
|
|
178
|
+
return match[1];
|
|
179
|
+
}
|
|
180
|
+
throw new Error("Unable to authenticate with Gemini. Make sure you're signed into gemini.google.com in a supported Chromium-based browser.");
|
|
181
|
+
}
|
|
182
|
+
async function fetchWithCookieRedirects(url, cookieHeader, maxRedirects, signal) {
|
|
183
|
+
let current = url;
|
|
184
|
+
const allowedOrigin = new URL(url).origin;
|
|
185
|
+
for (let i = 0; i <= maxRedirects; i++) {
|
|
186
|
+
const res = await (await resolveGeminiFetch())(current, {
|
|
187
|
+
headers: { "user-agent": USER_AGENT, cookie: cookieHeader },
|
|
188
|
+
redirect: "manual",
|
|
189
|
+
signal,
|
|
190
|
+
});
|
|
191
|
+
if (res.status >= 300 && res.status < 400) {
|
|
192
|
+
const location = res.headers.get("location");
|
|
193
|
+
if (location) {
|
|
194
|
+
const next = new URL(location, current);
|
|
195
|
+
if (next.origin !== allowedOrigin) {
|
|
196
|
+
throw new Error(`Refusing to send Google cookies across origins: ${allowedOrigin} -> ${next.origin}`);
|
|
197
|
+
}
|
|
198
|
+
current = next.toString();
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return await res.text();
|
|
203
|
+
}
|
|
204
|
+
throw new Error(`Too many redirects (>${maxRedirects})`);
|
|
205
|
+
}
|
|
206
|
+
function extractEmailFromGeminiHtml(html) {
|
|
207
|
+
const patterns = [
|
|
208
|
+
// Gemini bootstraps the active account in oPEP7c. Prefer it over generic
|
|
209
|
+
// feature/config entries that may contain other signed-in Google accounts.
|
|
210
|
+
/"oPEP7c"\s*:\s*"([^"]+)"/,
|
|
211
|
+
// The Google account menu aria-label is rendered for the active account.
|
|
212
|
+
/aria-label="Google Account:[^"]*?\(([^)]+)\)"/,
|
|
213
|
+
/"displayEmail"\s*:\s*"([^"]+)"/,
|
|
214
|
+
/"defaultEmail"\s*:\s*"([^"]+)"/,
|
|
215
|
+
/"email"\s*:\s*"([^"]+)"/,
|
|
216
|
+
/"identifier"\s*:\s*"([^"]+)"/,
|
|
217
|
+
/"gaiaIdentifier"\s*:\s*"([^"]+)"/,
|
|
218
|
+
];
|
|
219
|
+
for (const pattern of patterns) {
|
|
220
|
+
const match = html.match(pattern);
|
|
221
|
+
const email = normalizeEmail(match?.[1]);
|
|
222
|
+
if (email)
|
|
223
|
+
return email;
|
|
224
|
+
}
|
|
225
|
+
return findFirstEmail(html);
|
|
226
|
+
}
|
|
227
|
+
function extractEmailFromListAccounts(text) {
|
|
228
|
+
const trimmed = text.replace(/^\)\]\}'\s*/, "");
|
|
229
|
+
try {
|
|
230
|
+
return findEmailInValue(JSON.parse(trimmed)) ?? findFirstEmail(trimmed);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return findFirstEmail(trimmed);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function findEmailInValue(value) {
|
|
237
|
+
if (typeof value === "string")
|
|
238
|
+
return normalizeEmail(value);
|
|
239
|
+
if (Array.isArray(value)) {
|
|
240
|
+
for (const item of value) {
|
|
241
|
+
const email = findEmailInValue(item);
|
|
242
|
+
if (email)
|
|
243
|
+
return email;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
if (value && typeof value === "object") {
|
|
248
|
+
for (const item of Object.values(value)) {
|
|
249
|
+
const email = findEmailInValue(item);
|
|
250
|
+
if (email)
|
|
251
|
+
return email;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
function findFirstEmail(text) {
|
|
257
|
+
const normalized = decodeEmailEscapes(text);
|
|
258
|
+
const match = normalized.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i);
|
|
259
|
+
return match?.[0] ?? null;
|
|
260
|
+
}
|
|
261
|
+
function normalizeEmail(value) {
|
|
262
|
+
if (!value)
|
|
263
|
+
return null;
|
|
264
|
+
const normalized = decodeEmailEscapes(value.trim());
|
|
265
|
+
return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(normalized) ? normalized : null;
|
|
266
|
+
}
|
|
267
|
+
function decodeEmailEscapes(value) {
|
|
268
|
+
return value
|
|
269
|
+
.replace(/\\u0040/gi, "@")
|
|
270
|
+
.replace(/\\x40/gi, "@")
|
|
271
|
+
.replace(/@/gi, "@")
|
|
272
|
+
.replace(/@/gi, "@")
|
|
273
|
+
.replace(/\\"/g, "\"")
|
|
274
|
+
.replace(/\\\\/g, "\\");
|
|
275
|
+
}
|
|
276
|
+
async function uploadFile(filePath, cookieHeader, signal) {
|
|
277
|
+
const data = readFileSync(filePath);
|
|
278
|
+
const fileName = basename(filePath);
|
|
279
|
+
const boundary = "----FormBoundary" + Math.random().toString(36).slice(2);
|
|
280
|
+
const header = `--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${fileName}"\r\nContent-Type: application/octet-stream\r\n\r\n`;
|
|
281
|
+
const footer = `\r\n--${boundary}--\r\n`;
|
|
282
|
+
const body = Buffer.concat([
|
|
283
|
+
Buffer.from(header, "utf-8"),
|
|
284
|
+
data,
|
|
285
|
+
Buffer.from(footer, "utf-8"),
|
|
286
|
+
]);
|
|
287
|
+
const res = await (await resolveGeminiFetch())(GEMINI_UPLOAD_URL, {
|
|
288
|
+
method: "POST",
|
|
289
|
+
redirect: "error",
|
|
290
|
+
headers: {
|
|
291
|
+
"content-type": `multipart/form-data; boundary=${boundary}`,
|
|
292
|
+
"push-id": GEMINI_UPLOAD_PUSH_ID,
|
|
293
|
+
"user-agent": USER_AGENT,
|
|
294
|
+
cookie: cookieHeader,
|
|
295
|
+
},
|
|
296
|
+
body,
|
|
297
|
+
signal,
|
|
298
|
+
});
|
|
299
|
+
if (!res.ok) {
|
|
300
|
+
const text = await res.text();
|
|
301
|
+
throw new Error(`File upload failed: ${res.status} (${text.slice(0, 200)})`);
|
|
302
|
+
}
|
|
303
|
+
return { id: await res.text(), name: fileName };
|
|
304
|
+
}
|
|
305
|
+
function buildFReqPayload(prompt, uploaded) {
|
|
306
|
+
const promptPayload = uploaded.length > 0
|
|
307
|
+
? [prompt, 0, null, uploaded.map((file) => [[file.id, 1]])]
|
|
308
|
+
: [prompt];
|
|
309
|
+
const innerList = [promptPayload, null, null];
|
|
310
|
+
return JSON.stringify([null, JSON.stringify(innerList)]);
|
|
311
|
+
}
|
|
312
|
+
function withTimeout(signal, timeoutMs) {
|
|
313
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
314
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
315
|
+
}
|
|
316
|
+
function buildCookieHeader(cookieMap) {
|
|
317
|
+
return Object.entries(cookieMap)
|
|
318
|
+
.filter(([, value]) => typeof value === "string" && value.length > 0)
|
|
319
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
320
|
+
.join("; ");
|
|
321
|
+
}
|
|
322
|
+
function getNestedValue(value, pathParts) {
|
|
323
|
+
let current = value;
|
|
324
|
+
for (const part of pathParts) {
|
|
325
|
+
if (current == null)
|
|
326
|
+
return undefined;
|
|
327
|
+
if (!Array.isArray(current))
|
|
328
|
+
return undefined;
|
|
329
|
+
current = current[part];
|
|
330
|
+
}
|
|
331
|
+
return current;
|
|
332
|
+
}
|
|
333
|
+
function trimJsonEnvelope(text) {
|
|
334
|
+
const start = text.indexOf("[");
|
|
335
|
+
const end = text.lastIndexOf("]");
|
|
336
|
+
if (start === -1 || end === -1 || end <= start) {
|
|
337
|
+
throw new Error("Gemini response did not contain a JSON payload.");
|
|
338
|
+
}
|
|
339
|
+
return text.slice(start, end + 1);
|
|
340
|
+
}
|
|
341
|
+
function extractErrorCode(responseJson) {
|
|
342
|
+
const code = getNestedValue(responseJson, [0, 5, 2, 0, 1, 0]);
|
|
343
|
+
return typeof code === "number" && code >= 0 ? code : undefined;
|
|
344
|
+
}
|
|
345
|
+
function extractCandidateText(candidate) {
|
|
346
|
+
const textRaw = getNestedValue(candidate, [1, 0]);
|
|
347
|
+
let text = typeof textRaw === "string" ? textRaw : "";
|
|
348
|
+
if (/^http:\/\/googleusercontent\.com\/card_content\/\d+/.test(text)) {
|
|
349
|
+
const alt = getNestedValue(candidate, [22, 0]);
|
|
350
|
+
if (typeof alt === "string" && alt.length > 0)
|
|
351
|
+
text = alt;
|
|
352
|
+
}
|
|
353
|
+
return text;
|
|
354
|
+
}
|
|
355
|
+
function parseStreamGenerateResponse(rawText) {
|
|
356
|
+
const responseJson = JSON.parse(trimJsonEnvelope(rawText));
|
|
357
|
+
const errorCode = extractErrorCode(responseJson);
|
|
358
|
+
const parts = Array.isArray(responseJson) ? responseJson : [];
|
|
359
|
+
let firstCandidateSeen = undefined;
|
|
360
|
+
let latestNonEmptyText = "";
|
|
361
|
+
for (let i = 0; i < parts.length; i++) {
|
|
362
|
+
const partBody = getNestedValue(parts[i], [2]);
|
|
363
|
+
if (!partBody || typeof partBody !== "string")
|
|
364
|
+
continue;
|
|
365
|
+
try {
|
|
366
|
+
const parsed = JSON.parse(partBody);
|
|
367
|
+
const candidateList = getNestedValue(parsed, [4]);
|
|
368
|
+
if (!Array.isArray(candidateList) || candidateList.length === 0)
|
|
369
|
+
continue;
|
|
370
|
+
const firstCandidate = candidateList[0];
|
|
371
|
+
if (firstCandidateSeen === undefined)
|
|
372
|
+
firstCandidateSeen = firstCandidate;
|
|
373
|
+
const text = extractCandidateText(firstCandidate);
|
|
374
|
+
if (text.length > 0)
|
|
375
|
+
latestNonEmptyText = text;
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const text = latestNonEmptyText.length > 0
|
|
381
|
+
? latestNonEmptyText
|
|
382
|
+
: extractCandidateText(firstCandidateSeen);
|
|
383
|
+
return { text, errorCode };
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=gemini-web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini-web.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/gemini-web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,6BAA6B,EAAkB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAE1H,MAAM,cAAc,GAAG,+BAA+B,CAAC;AACvD,MAAM,0BAA0B,GAC/B,gGAAgG,CAAC;AAClG,MAAM,iBAAiB,GAAG,4CAA4C,CAAC;AACvE,MAAM,qBAAqB,GAAG,sBAAsB,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AAC,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YAE1E,MAAM,cAAc,GAAI,aAA2B,CAAC,CAAC,CAAC,CAAC;YACvD,IAAI,kBAAkB,KAAK,SAAS;gBAAE,kBAAkB,GAAG,cAAc,CAAC;YAE1E,MAAM,IAAI,GAAG,oBAAoB,CAAC,cAAc,CAAC,CAAC;YAClD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,kBAAkB,GAAG,IAAI,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;QACT,CAAC;IACF,CAAC;IAED,MAAM,IAAI,GAAG,kBAAkB,CAAC,MAAM,GAAG,CAAC;QACzC,CAAC,CAAC,kBAAkB;QACpB,CAAC,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;IAE5C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAAA,CAC3B","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { basename } from \"node:path\";\nimport { getLastGoogleCookieDiagnostic, type CookieMap, getGoogleCookies } from \"./chrome-cookies.ts\";\nimport { getChromeProfileFromConfig, isBrowserCookieAccessAllowed, normalizeChromeProfile } from \"./gemini-web-config.ts\";\n\nconst GEMINI_APP_URL = \"https://gemini.google.com/app\";\nconst GEMINI_STREAM_GENERATE_URL =\n\t\"https://gemini.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate\";\nconst GEMINI_UPLOAD_URL = \"https://content-push.googleapis.com/upload\";\nconst GEMINI_UPLOAD_PUSH_ID = \"feeds/mcudyrk2a4khkz\";\nconst GOOGLE_LIST_ACCOUNTS_URL =\n\t\"https://accounts.google.com/ListAccounts?gpsia=1&source=ChromiumBrowser&laf=b64bin&json=standard\";\n\nconst USER_AGENT =\n\t\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\";\n\nconst MODEL_HEADER_NAME = \"x-goog-ext-525001261-jspb\";\nexport const DEFAULT_GEMINI_WEB_MODEL = \"gemini-3.1-pro\";\nconst MODEL_HEADERS: Record<string, string> = {\n\t[DEFAULT_GEMINI_WEB_MODEL]: '[1,null,null,null,\"9d8ca3786ebdfbea\",null,null,0,[4]]',\n\t\"gemini-2.5-pro\": '[1,null,null,null,\"4af6c7f5da75d65d\",null,null,0,[4]]',\n\t\"gemini-2.5-flash\": '[1,null,null,null,\"9ec249fc9ad08861\",null,null,0,[4]]',\n};\n\nconst REQUIRED_COOKIES = [\"__Secure-1PSID\", \"__Secure-1PSIDTS\"];\n\n// Gemini Web talks to Google's frontend inside the host agent (pi), whose\n// global undici dispatcher runs HTTP/1.1 with undici's default 16 KiB\n// maxHeaderSize. Google's gemini.google.com /app response headers routinely\n// exceed that budget over HTTP/1.1, so cookie-bearing requests fail with\n// UND_ERR_HEADERS_OVERFLOW surfaced as \"fetch failed\". Route these requests\n// through a dedicated undici Agent with a larger header budget instead; fall\n// back to the ambient global fetch when undici is not resolvable (e.g.\n// standalone test environments).\nlet geminiFetchImpl: typeof fetch | null = null;\n\n// Test-only hook: lets tests inject a simulated transport instead of patching\n// globalThis.fetch. Gemini Web deliberately bypasses the ambient global fetch\n// (inside the pi host agent it is constrained to undici's 16 KiB\n// maxHeaderSize and cannot serve Google's /app page over HTTP/1.1), so\n// globalThis.fetch patching is no longer a reliable way to intercept these\n// requests.\nexport function setGeminiFetchOverrideForTests(fetchImpl: typeof fetch | null): void {\n\tgeminiFetchOverride = fetchImpl;\n}\n\nlet geminiFetchOverride: typeof fetch | null = null;\n\n// The header budget Gemini Web needs for Google frontend responses.\n// Google's /app page exceeds undici's default 16 KiB maxHeaderSize when\n// served over HTTP/1.1, which is how pi's global dispatcher operates.\nexport const GEMINI_MAX_HEADER_SIZE = 4 * 1024 * 1024;\n\n// Build a fetch that routes through a dedicated undici Agent with a larger\n// header budget than the host agent's global dispatcher allows. Exported for\n// tests so the agent configuration can be asserted without network access.\nexport function createGeminiFetch(undiciImpl: typeof import(\"undici\")): typeof fetch {\n\tconst agent = new undiciImpl.EnvHttpProxyAgent({\n\t\tallowH2: false,\n\t\tconnectTimeout: 30_000,\n\t\tmaxHeaderSize: GEMINI_MAX_HEADER_SIZE,\n\t\tpipelining: 1,\n\t});\n\t// undici 8 types its fetch request/response structurally differently from\n\t// the DOM lib types (duplex/textStream on Request, Symbol.dispose on\n\t// Headers); the shape this module uses (status, ok, headers.get, text) is\n\t// identical, so bridge the two.\n\ttype UndiciFetch = typeof undiciImpl.fetch;\n\treturn (input, init) =>\n\t\tundiciImpl.fetch(\n\t\t\tinput as unknown as Parameters<UndiciFetch>[0],\n\t\t\t{ ...init, dispatcher: agent } as unknown as Parameters<UndiciFetch>[1],\n\t\t) as unknown as Promise<Response>;\n}\n\nexport async function resolveGeminiFetch(): Promise<typeof fetch> {\n\tif (geminiFetchOverride) return geminiFetchOverride;\n\tif (geminiFetchImpl) return geminiFetchImpl;\n\n\tlet undici: typeof import(\"undici\");\n\ttry {\n\t\tundici = await import(\"undici\");\n\t} catch {\n\t\tgeminiFetchImpl = fetch;\n\t\treturn geminiFetchImpl;\n\t}\n\n\tgeminiFetchImpl = createGeminiFetch(undici);\n\treturn geminiFetchImpl;\n}\n\nexport interface GeminiWebOptions {\n\tyoutubeUrl?: string;\n\tmodel?: string;\n\tfiles?: string[];\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport async function isGeminiWebAvailable(chromeProfile?: string): Promise<CookieMap | null> {\n\tif (!isBrowserCookieAccessAllowed()) return null;\n\n\tconst result = await getGoogleCookies({\n\t\tprofile: normalizeChromeProfile(chromeProfile) ?? getChromeProfileFromConfig(),\n\t\trequiredCookies: REQUIRED_COOKIES,\n\t});\n\tif (!result) return null;\n\treturn result.cookies;\n}\n\nexport function getGeminiWebAvailabilityDiagnostic(): string | null {\n\treturn isBrowserCookieAccessAllowed() ? getLastGoogleCookieDiagnostic() : null;\n}\n\nexport async function getActiveGoogleEmail(cookies: CookieMap): Promise<string | null> {\n\tconst cookieHeader = buildCookieHeader(cookies);\n\tif (!cookieHeader) return null;\n\n\ttry {\n\t\tconst html = await fetchWithCookieRedirects(\n\t\t\tGEMINI_APP_URL,\n\t\t\tcookieHeader,\n\t\t\t10,\n\t\t\tAbortSignal.timeout(10000),\n\t\t);\n\t\tconst email = extractEmailFromGeminiHtml(html);\n\t\tif (email) return email;\n\t} catch {\n\t}\n\n\ttry {\n\t\tconst response = await fetchWithCookieRedirects(\n\t\t\tGOOGLE_LIST_ACCOUNTS_URL,\n\t\t\tcookieHeader,\n\t\t\t10,\n\t\t\tAbortSignal.timeout(10000),\n\t\t);\n\t\treturn extractEmailFromListAccounts(response);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport async function queryWithCookies(\n\tprompt: string,\n\tcookieMap: CookieMap,\n\toptions: GeminiWebOptions = {},\n): Promise<string> {\n\tconst model = options.model ?? DEFAULT_GEMINI_WEB_MODEL;\n\tif (!MODEL_HEADERS[model]) {\n\t\tthrow new Error(`Gemini Web does not support model ${model}; configure Gemini API or choose a supported Gemini Web model.`);\n\t}\n\tconst timeoutMs = options.timeoutMs ?? 120000;\n\n\tlet fullPrompt = prompt;\n\tif (options.youtubeUrl) {\n\t\tfullPrompt = `${fullPrompt}\\n\\nYouTube video: ${options.youtubeUrl}`;\n\t}\n\n\tconst result = await runGeminiWebOnce(fullPrompt, cookieMap, model, options.files, timeoutMs, options.signal);\n\n\tif (result.errorMessage) throw new Error(result.errorMessage);\n\tif (!result.text) throw new Error(\"Gemini Web returned empty response\");\n\treturn result.text;\n}\n\ninterface GeminiWebResult {\n\ttext: string;\n\terrorCode?: number;\n\terrorMessage?: string;\n}\n\nasync function runGeminiWebOnce(\n\tprompt: string,\n\tcookieMap: CookieMap,\n\tmodel: string,\n\tfiles: string[] | undefined,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<GeminiWebResult> {\n\tconst effectiveSignal = withTimeout(signal, timeoutMs);\n\tconst cookieHeader = buildCookieHeader(cookieMap);\n\tconst accessToken = await fetchAccessToken(cookieHeader, effectiveSignal);\n\n\tconst uploaded: Array<{ id: string; name: string }> = [];\n\tif (files) {\n\t\tfor (const filePath of files) {\n\t\t\tuploaded.push(await uploadFile(filePath, cookieHeader, effectiveSignal));\n\t\t}\n\t}\n\n\tconst fReq = buildFReqPayload(prompt, uploaded);\n\tconst params = new URLSearchParams();\n\tparams.set(\"at\", accessToken);\n\tparams.set(\"f.req\", fReq);\n\n\tconst res = await (await resolveGeminiFetch())(GEMINI_STREAM_GENERATE_URL, {\n\t\tmethod: \"POST\",\n\t\tredirect: \"error\",\n\t\theaders: {\n\t\t\t\"content-type\": \"application/x-www-form-urlencoded;charset=utf-8\",\n\t\t\thost: \"gemini.google.com\",\n\t\t\torigin: \"https://gemini.google.com\",\n\t\t\treferer: \"https://gemini.google.com/\",\n\t\t\t\"x-same-domain\": \"1\",\n\t\t\t\"user-agent\": USER_AGENT,\n\t\t\tcookie: cookieHeader,\n\t\t\t[MODEL_HEADER_NAME]: MODEL_HEADERS[model],\n\t\t},\n\t\tbody: params.toString(),\n\t\tsignal: effectiveSignal,\n\t});\n\n\tconst rawText = await res.text();\n\n\tif (!res.ok) {\n\t\treturn { text: \"\", errorMessage: `Gemini request failed: ${res.status}` };\n\t}\n\n\ttry {\n\t\treturn parseStreamGenerateResponse(rawText);\n\t} catch (err) {\n\t\tlet errorCode: number | undefined;\n\t\ttry {\n\t\t\tconst json = JSON.parse(trimJsonEnvelope(rawText));\n\t\t\terrorCode = extractErrorCode(json);\n\t\t} catch {\n\t\t}\n\t\treturn {\n\t\t\ttext: \"\",\n\t\t\terrorCode,\n\t\t\terrorMessage: err instanceof Error ? err.message : String(err),\n\t\t};\n\t}\n}\n\nasync function fetchAccessToken(\n\tcookieHeader: string,\n\tsignal: AbortSignal,\n): Promise<string> {\n\tconst html = await fetchWithCookieRedirects(GEMINI_APP_URL, cookieHeader, 10, signal);\n\n\tfor (const key of [\"SNlM0e\", \"thykhd\"]) {\n\t\tconst match = html.match(new RegExp(`\"${key}\":\"(.*?)\"`));\n\t\tif (match?.[1]) return match[1];\n\t}\n\n\tthrow new Error(\"Unable to authenticate with Gemini. Make sure you're signed into gemini.google.com in a supported Chromium-based browser.\");\n}\n\nasync function fetchWithCookieRedirects(\n\turl: string,\n\tcookieHeader: string,\n\tmaxRedirects: number,\n\tsignal: AbortSignal,\n): Promise<string> {\n\tlet current = url;\n\tconst allowedOrigin = new URL(url).origin;\n\tfor (let i = 0; i <= maxRedirects; i++) {\n\t\tconst res = await (await resolveGeminiFetch())(current, {\n\t\t\theaders: { \"user-agent\": USER_AGENT, cookie: cookieHeader },\n\t\t\tredirect: \"manual\",\n\t\t\tsignal,\n\t\t});\n\t\tif (res.status >= 300 && res.status < 400) {\n\t\t\tconst location = res.headers.get(\"location\");\n\t\t\tif (location) {\n\t\t\t\tconst next = new URL(location, current);\n\t\t\t\tif (next.origin !== allowedOrigin) {\n\t\t\t\t\tthrow new Error(`Refusing to send Google cookies across origins: ${allowedOrigin} -> ${next.origin}`);\n\t\t\t\t}\n\t\t\t\tcurrent = next.toString();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\treturn await res.text();\n\t}\n\tthrow new Error(`Too many redirects (>${maxRedirects})`);\n}\n\nfunction extractEmailFromGeminiHtml(html: string): string | null {\n\tconst patterns = [\n\t\t// Gemini bootstraps the active account in oPEP7c. Prefer it over generic\n\t\t// feature/config entries that may contain other signed-in Google accounts.\n\t\t/\"oPEP7c\"\\s*:\\s*\"([^\"]+)\"/,\n\t\t// The Google account menu aria-label is rendered for the active account.\n\t\t/aria-label=\"Google Account:[^\"]*?\\(([^)]+)\\)\"/,\n\t\t/\"displayEmail\"\\s*:\\s*\"([^\"]+)\"/,\n\t\t/\"defaultEmail\"\\s*:\\s*\"([^\"]+)\"/,\n\t\t/\"email\"\\s*:\\s*\"([^\"]+)\"/,\n\t\t/\"identifier\"\\s*:\\s*\"([^\"]+)\"/,\n\t\t/\"gaiaIdentifier\"\\s*:\\s*\"([^\"]+)\"/,\n\t];\n\n\tfor (const pattern of patterns) {\n\t\tconst match = html.match(pattern);\n\t\tconst email = normalizeEmail(match?.[1]);\n\t\tif (email) return email;\n\t}\n\n\treturn findFirstEmail(html);\n}\n\nfunction extractEmailFromListAccounts(text: string): string | null {\n\tconst trimmed = text.replace(/^\\)\\]\\}'\\s*/, \"\");\n\ttry {\n\t\treturn findEmailInValue(JSON.parse(trimmed)) ?? findFirstEmail(trimmed);\n\t} catch {\n\t\treturn findFirstEmail(trimmed);\n\t}\n}\n\nfunction findEmailInValue(value: unknown): string | null {\n\tif (typeof value === \"string\") return normalizeEmail(value);\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tconst email = findEmailInValue(item);\n\t\t\tif (email) return email;\n\t\t}\n\t\treturn null;\n\t}\n\tif (value && typeof value === \"object\") {\n\t\tfor (const item of Object.values(value as Record<string, unknown>)) {\n\t\t\tconst email = findEmailInValue(item);\n\t\t\tif (email) return email;\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction findFirstEmail(text: string): string | null {\n\tconst normalized = decodeEmailEscapes(text);\n\tconst match = normalized.match(/\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b/i);\n\treturn match?.[0] ?? null;\n}\n\nfunction normalizeEmail(value: string | undefined): string | null {\n\tif (!value) return null;\n\tconst normalized = decodeEmailEscapes(value.trim());\n\treturn /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}$/i.test(normalized) ? normalized : null;\n}\n\nfunction decodeEmailEscapes(value: string): string {\n\treturn value\n\t\t.replace(/\\\\u0040/gi, \"@\")\n\t\t.replace(/\\\\x40/gi, \"@\")\n\t\t.replace(/@/gi, \"@\")\n\t\t.replace(/@/gi, \"@\")\n\t\t.replace(/\\\\\"/g, \"\\\"\")\n\t\t.replace(/\\\\\\\\/g, \"\\\\\");\n}\n\nasync function uploadFile(\n\tfilePath: string,\n\tcookieHeader: string,\n\tsignal: AbortSignal,\n): Promise<{ id: string; name: string }> {\n\tconst data = readFileSync(filePath);\n\tconst fileName = basename(filePath);\n\tconst boundary = \"----FormBoundary\" + Math.random().toString(36).slice(2);\n\tconst header = `--${boundary}\\r\\nContent-Disposition: form-data; name=\"file\"; filename=\"${fileName}\"\\r\\nContent-Type: application/octet-stream\\r\\n\\r\\n`;\n\tconst footer = `\\r\\n--${boundary}--\\r\\n`;\n\n\tconst body = Buffer.concat([\n\t\tBuffer.from(header, \"utf-8\"),\n\t\tdata,\n\t\tBuffer.from(footer, \"utf-8\"),\n\t]);\n\n\tconst res = await (await resolveGeminiFetch())(GEMINI_UPLOAD_URL, {\n\t\tmethod: \"POST\",\n\t\tredirect: \"error\",\n\t\theaders: {\n\t\t\t\"content-type\": `multipart/form-data; boundary=${boundary}`,\n\t\t\t\"push-id\": GEMINI_UPLOAD_PUSH_ID,\n\t\t\t\"user-agent\": USER_AGENT,\n\t\t\tcookie: cookieHeader,\n\t\t},\n\t\tbody,\n\t\tsignal,\n\t});\n\n\tif (!res.ok) {\n\t\tconst text = await res.text();\n\t\tthrow new Error(`File upload failed: ${res.status} (${text.slice(0, 200)})`);\n\t}\n\n\treturn { id: await res.text(), name: fileName };\n}\n\nfunction buildFReqPayload(\n\tprompt: string,\n\tuploaded: Array<{ id: string; name: string }>,\n): string {\n\tconst promptPayload =\n\t\tuploaded.length > 0\n\t\t\t? [prompt, 0, null, uploaded.map((file) => [[file.id, 1]])]\n\t\t\t: [prompt];\n\tconst innerList = [promptPayload, null, null];\n\treturn JSON.stringify([null, JSON.stringify(innerList)]);\n}\n\nfunction withTimeout(signal: AbortSignal | undefined, timeoutMs: number): AbortSignal {\n\tconst timeout = AbortSignal.timeout(timeoutMs);\n\treturn signal ? AbortSignal.any([signal, timeout]) : timeout;\n}\n\nfunction buildCookieHeader(cookieMap: CookieMap): string {\n\treturn Object.entries(cookieMap)\n\t\t.filter(([, value]) => typeof value === \"string\" && value.length > 0)\n\t\t.map(([name, value]) => `${name}=${value}`)\n\t\t.join(\"; \");\n}\n\nfunction getNestedValue(value: unknown, pathParts: number[]): unknown {\n\tlet current: unknown = value;\n\tfor (const part of pathParts) {\n\t\tif (current == null) return undefined;\n\t\tif (!Array.isArray(current)) return undefined;\n\t\tcurrent = (current as unknown[])[part];\n\t}\n\treturn current;\n}\n\nfunction trimJsonEnvelope(text: string): string {\n\tconst start = text.indexOf(\"[\");\n\tconst end = text.lastIndexOf(\"]\");\n\tif (start === -1 || end === -1 || end <= start) {\n\t\tthrow new Error(\"Gemini response did not contain a JSON payload.\");\n\t}\n\treturn text.slice(start, end + 1);\n}\n\nfunction extractErrorCode(responseJson: unknown): number | undefined {\n\tconst code = getNestedValue(responseJson, [0, 5, 2, 0, 1, 0]);\n\treturn typeof code === \"number\" && code >= 0 ? code : undefined;\n}\n\nfunction extractCandidateText(candidate: unknown): string {\n\tconst textRaw = getNestedValue(candidate, [1, 0]);\n\tlet text = typeof textRaw === \"string\" ? textRaw : \"\";\n\n\tif (/^http:\\/\\/googleusercontent\\.com\\/card_content\\/\\d+/.test(text)) {\n\t\tconst alt = getNestedValue(candidate, [22, 0]);\n\t\tif (typeof alt === \"string\" && alt.length > 0) text = alt;\n\t}\n\n\treturn text;\n}\n\nfunction parseStreamGenerateResponse(rawText: string): GeminiWebResult {\n\tconst responseJson = JSON.parse(trimJsonEnvelope(rawText));\n\tconst errorCode = extractErrorCode(responseJson);\n\n\tconst parts = Array.isArray(responseJson) ? responseJson : [];\n\tlet firstCandidateSeen: unknown = undefined;\n\tlet latestNonEmptyText = \"\";\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst partBody = getNestedValue(parts[i], [2]);\n\t\tif (!partBody || typeof partBody !== \"string\") continue;\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(partBody);\n\t\t\tconst candidateList = getNestedValue(parsed, [4]);\n\t\t\tif (!Array.isArray(candidateList) || candidateList.length === 0) continue;\n\n\t\t\tconst firstCandidate = (candidateList as unknown[])[0];\n\t\t\tif (firstCandidateSeen === undefined) firstCandidateSeen = firstCandidate;\n\n\t\t\tconst text = extractCandidateText(firstCandidate);\n\t\t\tif (text.length > 0) latestNonEmptyText = text;\n\t\t} catch {\n\t\t}\n\t}\n\n\tconst text = latestNonEmptyText.length > 0\n\t\t? latestNonEmptyText\n\t\t: extractCandidateText(firstCandidateSeen);\n\n\treturn { text, errorCode };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExtractedContent } from "./extract.ts";
|
|
2
|
+
import type { GitHubUrlInfo } from "./github-extract.ts";
|
|
3
|
+
export declare function checkGhAvailable(): Promise<boolean>;
|
|
4
|
+
export declare function showGhHint(): void;
|
|
5
|
+
export declare function checkRepoSize(owner: string, repo: string): Promise<number | null>;
|
|
6
|
+
export declare function fetchViaApi(url: string, owner: string, repo: string, info: GitHubUrlInfo, sizeNote?: string): Promise<ExtractedContent | null>;
|
|
7
|
+
//# sourceMappingURL=github-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-api.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/github-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQzD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,CASzD;AAED,wBAAgB,UAAU,IAAI,IAAI,CAKjC;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAavF;AA0FD,wBAAsB,WAAW,CAChC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,aAAa,EACnB,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA0DlC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport type { ExtractedContent } from \"./extract.ts\";\nimport type { GitHubUrlInfo } from \"./github-extract.ts\";\n\nconst MAX_TREE_ENTRIES = 200;\nconst MAX_INLINE_FILE_CHARS = 100_000;\n\nlet ghAvailable: boolean | null = null;\nlet ghHintShown = false;\n\nexport async function checkGhAvailable(): Promise<boolean> {\n\tif (ghAvailable !== null) return ghAvailable;\n\n\treturn new Promise((resolve) => {\n\t\texecFile(\"gh\", [\"--version\"], { timeout: 5000 }, (err) => {\n\t\t\tghAvailable = !err;\n\t\t\tresolve(ghAvailable);\n\t\t});\n\t});\n}\n\nexport function showGhHint(): void {\n\tif (!ghHintShown) {\n\t\tghHintShown = true;\n\t\tconsole.error(\"[pi-web-access] Install `gh` CLI for better GitHub repo access including private repos.\");\n\t}\n}\n\nexport async function checkRepoSize(owner: string, repo: string): Promise<number | null> {\n\tif (!(await checkGhAvailable())) return null;\n\n\treturn new Promise((resolve) => {\n\t\texecFile(\"gh\", [\"api\", `repos/${owner}/${repo}`, \"--jq\", \".size\"], { timeout: 10000 }, (err, stdout) => {\n\t\t\tif (err) {\n\t\t\t\tresolve(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst kb = parseInt(stdout.trim(), 10);\n\t\t\tresolve(Number.isNaN(kb) ? null : kb);\n\t\t});\n\t});\n}\n\nasync function getDefaultBranch(owner: string, repo: string): Promise<string | null> {\n\tif (!(await checkGhAvailable())) return null;\n\n\treturn new Promise((resolve) => {\n\t\texecFile(\"gh\", [\"api\", `repos/${owner}/${repo}`, \"--jq\", \".default_branch\"], { timeout: 10000 }, (err, stdout) => {\n\t\t\tif (err) {\n\t\t\t\tresolve(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst branch = stdout.trim();\n\t\t\tresolve(branch || null);\n\t\t});\n\t});\n}\n\nasync function fetchTreeViaApi(owner: string, repo: string, ref: string): Promise<string | null> {\n\tif (!(await checkGhAvailable())) return null;\n\n\treturn new Promise((resolve) => {\n\t\texecFile(\n\t\t\t\"gh\",\n\t\t\t[\"api\", `repos/${owner}/${repo}/git/trees/${ref}?recursive=1`, \"--jq\", \".tree[].path\"],\n\t\t\t{ timeout: 15000, maxBuffer: 5 * 1024 * 1024 },\n\t\t\t(err, stdout) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresolve(null);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst paths = stdout.trim().split(\"\\n\").filter(Boolean);\n\t\t\t\tif (paths.length === 0) {\n\t\t\t\t\tresolve(null);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst truncated = paths.length > MAX_TREE_ENTRIES;\n\t\t\t\tconst display = paths.slice(0, MAX_TREE_ENTRIES).join(\"\\n\");\n\t\t\t\tresolve(truncated ? display + `\\n... (${paths.length} total entries)` : display);\n\t\t\t},\n\t\t);\n\t});\n}\n\nasync function fetchReadmeViaApi(owner: string, repo: string, ref: string): Promise<string | null> {\n\tif (!(await checkGhAvailable())) return null;\n\n\treturn new Promise((resolve) => {\n\t\texecFile(\n\t\t\t\"gh\",\n\t\t\t[\"api\", `repos/${owner}/${repo}/readme?ref=${ref}`, \"--jq\", \".content\"],\n\t\t\t{ timeout: 10000 },\n\t\t\t(err, stdout) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresolve(null);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst decoded = Buffer.from(stdout.trim(), \"base64\").toString(\"utf-8\");\n\t\t\t\t\tresolve(decoded.length > 8192 ? decoded.slice(0, 8192) + \"\\n\\n[README truncated at 8K chars]\" : decoded);\n\t\t\t\t} catch {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t});\n}\n\nasync function fetchFileViaApi(owner: string, repo: string, path: string, ref: string): Promise<string | null> {\n\tif (!(await checkGhAvailable())) return null;\n\n\treturn new Promise((resolve) => {\n\t\texecFile(\n\t\t\t\"gh\",\n\t\t\t[\"api\", `repos/${owner}/${repo}/contents/${path}?ref=${ref}`, \"--jq\", \".content\"],\n\t\t\t{ timeout: 10000, maxBuffer: 2 * 1024 * 1024 },\n\t\t\t(err, stdout) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresolve(null);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tresolve(Buffer.from(stdout.trim(), \"base64\").toString(\"utf-8\"));\n\t\t\t\t} catch {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t});\n}\n\nexport async function fetchViaApi(\n\turl: string,\n\towner: string,\n\trepo: string,\n\tinfo: GitHubUrlInfo,\n\tsizeNote?: string,\n): Promise<ExtractedContent | null> {\n\tconst ref = info.ref || (await getDefaultBranch(owner, repo));\n\tif (!ref) return null;\n\n\tconst lines: string[] = [];\n\tif (sizeNote) {\n\t\tlines.push(sizeNote);\n\t\tlines.push(\"\");\n\t}\n\n\tif (info.type === \"blob\" && info.path) {\n\t\tconst content = await fetchFileViaApi(owner, repo, info.path, ref);\n\t\tif (!content) return null;\n\n\t\tlines.push(`## ${info.path}`);\n\t\tif (content.length > MAX_INLINE_FILE_CHARS) {\n\t\t\tlines.push(content.slice(0, MAX_INLINE_FILE_CHARS));\n\t\t\tlines.push(`\\n[File truncated at 100K chars]`);\n\t\t} else {\n\t\t\tlines.push(content);\n\t\t}\n\n\t\treturn {\n\t\t\turl,\n\t\t\ttitle: `${owner}/${repo} - ${info.path}`,\n\t\t\tcontent: lines.join(\"\\n\"),\n\t\t\terror: null,\n\t\t};\n\t}\n\n\tconst [tree, readme] = await Promise.all([\n\t\tfetchTreeViaApi(owner, repo, ref),\n\t\tfetchReadmeViaApi(owner, repo, ref),\n\t]);\n\n\tif (!tree && !readme) return null;\n\n\tif (tree) {\n\t\tlines.push(\"## Structure\");\n\t\tlines.push(tree);\n\t\tlines.push(\"\");\n\t}\n\n\tif (readme) {\n\t\tlines.push(\"## README.md\");\n\t\tlines.push(readme);\n\t\tlines.push(\"\");\n\t}\n\n\tlines.push(\"This is an API-only view. Clone the repo or use `read`/`bash` for deeper exploration.\");\n\n\tconst title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;\n\treturn {\n\t\turl,\n\t\ttitle,\n\t\tcontent: lines.join(\"\\n\"),\n\t\terror: null,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
const MAX_TREE_ENTRIES = 200;
|
|
3
|
+
const MAX_INLINE_FILE_CHARS = 100_000;
|
|
4
|
+
let ghAvailable = null;
|
|
5
|
+
let ghHintShown = false;
|
|
6
|
+
export async function checkGhAvailable() {
|
|
7
|
+
if (ghAvailable !== null)
|
|
8
|
+
return ghAvailable;
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
execFile("gh", ["--version"], { timeout: 5000 }, (err) => {
|
|
11
|
+
ghAvailable = !err;
|
|
12
|
+
resolve(ghAvailable);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function showGhHint() {
|
|
17
|
+
if (!ghHintShown) {
|
|
18
|
+
ghHintShown = true;
|
|
19
|
+
console.error("[pi-web-access] Install `gh` CLI for better GitHub repo access including private repos.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function checkRepoSize(owner, repo) {
|
|
23
|
+
if (!(await checkGhAvailable()))
|
|
24
|
+
return null;
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
execFile("gh", ["api", `repos/${owner}/${repo}`, "--jq", ".size"], { timeout: 10000 }, (err, stdout) => {
|
|
27
|
+
if (err) {
|
|
28
|
+
resolve(null);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const kb = parseInt(stdout.trim(), 10);
|
|
32
|
+
resolve(Number.isNaN(kb) ? null : kb);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async function getDefaultBranch(owner, repo) {
|
|
37
|
+
if (!(await checkGhAvailable()))
|
|
38
|
+
return null;
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
execFile("gh", ["api", `repos/${owner}/${repo}`, "--jq", ".default_branch"], { timeout: 10000 }, (err, stdout) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
resolve(null);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const branch = stdout.trim();
|
|
46
|
+
resolve(branch || null);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function fetchTreeViaApi(owner, repo, ref) {
|
|
51
|
+
if (!(await checkGhAvailable()))
|
|
52
|
+
return null;
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
execFile("gh", ["api", `repos/${owner}/${repo}/git/trees/${ref}?recursive=1`, "--jq", ".tree[].path"], { timeout: 15000, maxBuffer: 5 * 1024 * 1024 }, (err, stdout) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
resolve(null);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const paths = stdout.trim().split("\n").filter(Boolean);
|
|
60
|
+
if (paths.length === 0) {
|
|
61
|
+
resolve(null);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const truncated = paths.length > MAX_TREE_ENTRIES;
|
|
65
|
+
const display = paths.slice(0, MAX_TREE_ENTRIES).join("\n");
|
|
66
|
+
resolve(truncated ? display + `\n... (${paths.length} total entries)` : display);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function fetchReadmeViaApi(owner, repo, ref) {
|
|
71
|
+
if (!(await checkGhAvailable()))
|
|
72
|
+
return null;
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
execFile("gh", ["api", `repos/${owner}/${repo}/readme?ref=${ref}`, "--jq", ".content"], { timeout: 10000 }, (err, stdout) => {
|
|
75
|
+
if (err) {
|
|
76
|
+
resolve(null);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const decoded = Buffer.from(stdout.trim(), "base64").toString("utf-8");
|
|
81
|
+
resolve(decoded.length > 8192 ? decoded.slice(0, 8192) + "\n\n[README truncated at 8K chars]" : decoded);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
resolve(null);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function fetchFileViaApi(owner, repo, path, ref) {
|
|
90
|
+
if (!(await checkGhAvailable()))
|
|
91
|
+
return null;
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
execFile("gh", ["api", `repos/${owner}/${repo}/contents/${path}?ref=${ref}`, "--jq", ".content"], { timeout: 10000, maxBuffer: 2 * 1024 * 1024 }, (err, stdout) => {
|
|
94
|
+
if (err) {
|
|
95
|
+
resolve(null);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
resolve(Buffer.from(stdout.trim(), "base64").toString("utf-8"));
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
resolve(null);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export async function fetchViaApi(url, owner, repo, info, sizeNote) {
|
|
108
|
+
const ref = info.ref || (await getDefaultBranch(owner, repo));
|
|
109
|
+
if (!ref)
|
|
110
|
+
return null;
|
|
111
|
+
const lines = [];
|
|
112
|
+
if (sizeNote) {
|
|
113
|
+
lines.push(sizeNote);
|
|
114
|
+
lines.push("");
|
|
115
|
+
}
|
|
116
|
+
if (info.type === "blob" && info.path) {
|
|
117
|
+
const content = await fetchFileViaApi(owner, repo, info.path, ref);
|
|
118
|
+
if (!content)
|
|
119
|
+
return null;
|
|
120
|
+
lines.push(`## ${info.path}`);
|
|
121
|
+
if (content.length > MAX_INLINE_FILE_CHARS) {
|
|
122
|
+
lines.push(content.slice(0, MAX_INLINE_FILE_CHARS));
|
|
123
|
+
lines.push(`\n[File truncated at 100K chars]`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
lines.push(content);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
url,
|
|
130
|
+
title: `${owner}/${repo} - ${info.path}`,
|
|
131
|
+
content: lines.join("\n"),
|
|
132
|
+
error: null,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const [tree, readme] = await Promise.all([
|
|
136
|
+
fetchTreeViaApi(owner, repo, ref),
|
|
137
|
+
fetchReadmeViaApi(owner, repo, ref),
|
|
138
|
+
]);
|
|
139
|
+
if (!tree && !readme)
|
|
140
|
+
return null;
|
|
141
|
+
if (tree) {
|
|
142
|
+
lines.push("## Structure");
|
|
143
|
+
lines.push(tree);
|
|
144
|
+
lines.push("");
|
|
145
|
+
}
|
|
146
|
+
if (readme) {
|
|
147
|
+
lines.push("## README.md");
|
|
148
|
+
lines.push(readme);
|
|
149
|
+
lines.push("");
|
|
150
|
+
}
|
|
151
|
+
lines.push("This is an API-only view. Clone the repo or use `read`/`bash` for deeper exploration.");
|
|
152
|
+
const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
|
|
153
|
+
return {
|
|
154
|
+
url,
|
|
155
|
+
title,
|
|
156
|
+
content: lines.join("\n"),
|
|
157
|
+
error: null,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=github-api.js.map
|