@humain/terminal 0.0.6 → 0.0.7
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 +52 -0
- package/README.md +10 -4
- package/dist/bundle/chunks/anthropic-messages-GDMGYAZB.js +6 -0
- package/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/bundle/chunks/azure-openai-responses-ZN52D6YC.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +77 -0
- package/dist/bundle/chunks/chunk-3D3G2X5U.js +6 -0
- package/dist/bundle/chunks/chunk-3VI4HD7D.js +31 -0
- package/dist/bundle/chunks/chunk-6R7UI4IY.js +2 -0
- package/dist/bundle/chunks/chunk-72KO4OMP.js +2 -0
- package/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
- package/dist/bundle/chunks/chunk-ARF4OE6X.js +105 -0
- package/dist/bundle/chunks/chunk-BOW22LW6.js +42 -0
- package/dist/bundle/chunks/chunk-BZQ53VGE.js +70 -0
- package/dist/bundle/chunks/chunk-CBHC6EL7.js +133 -0
- package/dist/bundle/chunks/chunk-D7XAASZM.js +4 -0
- package/dist/bundle/chunks/chunk-ECWELYBH.js +17 -0
- package/dist/bundle/chunks/chunk-GMWCTUPB.js +2 -0
- package/dist/bundle/chunks/chunk-H2O6VOXT.js +11 -0
- package/dist/bundle/chunks/chunk-HNVPY4LZ.js +5995 -0
- package/dist/bundle/chunks/chunk-JUUC5AZY.js +2 -0
- package/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
- package/dist/bundle/chunks/chunk-M2GYSCCG.js +44 -0
- package/dist/bundle/chunks/chunk-MA4UUCYX.js +18 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/bundle/chunks/chunk-SGTGQNNP.js +4 -0
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/bundle/chunks/chunk-TXBQIIIO.js +2 -0
- package/dist/bundle/chunks/chunk-WJZ4KLGL.js +2 -0
- package/dist/bundle/chunks/chunk-XNGRGP62.js +2 -0
- package/dist/bundle/chunks/dist-7DSXV2TY.js +9 -0
- package/dist/bundle/chunks/dist-BXEVYJIO.js +7 -0
- package/dist/bundle/chunks/es-P2KNSZYR.js +9 -0
- package/dist/bundle/chunks/es5-FGTJ7ZFW.js +2 -0
- package/dist/bundle/chunks/event-streams-JOSQQSII.js +2 -0
- package/dist/bundle/chunks/extract-2L7ZVN7F.js +106 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-XT7NQJ2E.js +2 -0
- package/dist/bundle/chunks/google-vertex-IDQ6Z53W.js +2 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-HHDZ4FHR.js +5 -0
- package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
- package/dist/bundle/chunks/node-XY3CBY3C.js +294 -0
- package/dist/bundle/chunks/node-ZHY4LHC7.js +15 -0
- package/dist/bundle/chunks/openai-codex-responses-HRVCDY54.js +8 -0
- package/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/bundle/chunks/openai-completions-6QBYTBXY.js +7 -0
- package/dist/bundle/chunks/openai-responses-4MWLJHIK.js +2 -0
- package/dist/bundle/chunks/openrouter-images-Y2PCWAQH.js +2 -0
- package/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/bundle/chunks/pdfjs-UKQT3OWY.js +107 -0
- package/dist/bundle/chunks/pi-messages-57K43J6J.js +8 -0
- package/dist/bundle/chunks/promise-J5TGSM32.js +2 -0
- package/dist/bundle/chunks/radius.js +75 -0
- package/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
- package/dist/bundle/chunks/undici-D6ABF53Q.js +2 -0
- package/dist/bundle/chunks/webapi-AFS5FDJJ.js +5 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli.js +3 -0
- package/dist/bundle/client.js +2 -0
- package/dist/bundle/index.js +2 -0
- package/dist/bundle/rpc-entry.js +3 -0
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +29 -9
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +19 -11
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +50 -14
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +163 -95
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +6 -7
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +4 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +41 -32
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +9 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +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 +115 -48
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +38 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +3 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/keybindings.d.ts +20 -19
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +26 -5
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +5 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +3 -1
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +14 -8
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +22 -14
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +2 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +2 -1
- 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 +3 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +10 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-export.d.ts +4 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +32 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +9 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +51 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +51 -33
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +11 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +16 -3
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +62 -29
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +0 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +2 -5
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +20 -4
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/index.d.ts +4 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +19 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -0
- package/dist/core/tools/powershell.js +39 -0
- package/dist/core/tools/powershell.js.map +1 -0
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +4 -1
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +2 -0
- 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 +6 -2
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/humain/agent-execution-protocol.d.ts +1 -217
- package/dist/humain/agent-execution-protocol.d.ts.map +1 -1
- package/dist/humain/agent-execution-protocol.js +1 -203
- package/dist/humain/agent-execution-protocol.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +107 -16
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +82 -0
- package/dist/humain/mcp-adapter/vendor/README.md +47 -15
- package/dist/humain/mcp-adapter/vendor/cli.js +4 -4
- package/dist/humain/mcp-adapter/vendor/commands.ts +5 -3
- package/dist/humain/mcp-adapter/vendor/config.ts +46 -5
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +103 -92
- package/dist/humain/mcp-adapter/vendor/dist/agent-dir.d.ts +10 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-dir.js +63 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-dir.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.d.ts +8 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js +356 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/config.d.ts +123 -0
- package/dist/humain/mcp-adapter/vendor/dist/config.js +1088 -0
- package/dist/humain/mcp-adapter/vendor/dist/config.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/mcp-bearer-store.d.ts +24 -0
- package/dist/humain/mcp-adapter/vendor/dist/mcp-bearer-store.js +336 -0
- package/dist/humain/mcp-adapter/vendor/dist/mcp-bearer-store.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.d.ts +19 -0
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js +319 -0
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.d.ts +2 -0
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js +156 -0
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/resource-tools.d.ts +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/resource-tools.js +15 -0
- package/dist/humain/mcp-adapter/vendor/dist/resource-tools.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/types.d.ts +566 -0
- package/dist/humain/mcp-adapter/vendor/dist/types.js +287 -0
- package/dist/humain/mcp-adapter/vendor/dist/types.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-app-bridge-helpers.d.ts +6 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-app-bridge-helpers.js +37 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-app-bridge-helpers.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-stream-types.d.ts +104 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-stream-types.js +59 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-stream-types.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-tool-visibility.d.ts +4 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-tool-visibility.js +27 -0
- package/dist/humain/mcp-adapter/vendor/dist/ui-tool-visibility.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/utils.d.ts +32 -0
- package/dist/humain/mcp-adapter/vendor/dist/utils.js +338 -0
- package/dist/humain/mcp-adapter/vendor/dist/utils.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/failure-backoff.ts +23 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +4870 -3878
- package/dist/humain/mcp-adapter/vendor/index.ts +294 -88
- package/dist/humain/mcp-adapter/vendor/init.ts +41 -30
- package/dist/humain/mcp-adapter/vendor/lifecycle.ts +16 -8
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +124 -32
- package/dist/humain/mcp-adapter/vendor/mcp-bearer-store.ts +0 -2
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +2 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +155 -16
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +95 -7
- package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +18 -4
- package/dist/humain/mcp-adapter/vendor/mcp-references.ts +376 -0
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +8 -19
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +20 -12
- package/dist/humain/mcp-adapter/vendor/namespace-tools.ts +276 -0
- package/dist/humain/mcp-adapter/vendor/package.json +26 -8
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +128 -32
- package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +1 -1
- package/dist/humain/mcp-adapter/vendor/search-ranking.ts +2 -0
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +69 -12
- package/dist/humain/mcp-adapter/vendor/state.ts +1 -3
- package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +16 -2
- package/dist/humain/mcp-adapter/vendor/types.ts +51 -2
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +3 -19
- package/dist/humain/mcp-adapter/vendor/ui-session.ts +2 -1
- package/dist/humain/mcp-adapter/vendor/utils.ts +21 -19
- package/dist/humain/mcp-adapter.d.ts.map +1 -1
- package/dist/humain/mcp-adapter.js +4 -0
- package/dist/humain/mcp-adapter.js.map +1 -1
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts +14 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/chrome-cookies.js +85 -33
- package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.d.ts +1 -1
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.js +3 -1
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts +2 -29
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +10 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts +2 -29
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +4 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts +11 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +163 -20
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.d.ts +2 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js +11 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-adc.d.ts +10 -0
- package/dist/humain/web-access/vendor/gemini-adc.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-adc.js +268 -0
- package/dist/humain/web-access/vendor/gemini-adc.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts +7 -1
- package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-api.js +51 -15
- package/dist/humain/web-access/vendor/gemini-api.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +9 -4
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +63 -21
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-url-context.js +3 -2
- package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts +8 -1
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-web-config.js +49 -4
- package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-web.d.ts +2 -1
- package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-web.js +8 -3
- package/dist/humain/web-access/vendor/gemini-web.js.map +1 -1
- package/dist/humain/web-access/vendor/github-api.d.ts +1 -1
- package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/github-api.js +6 -4
- package/dist/humain/web-access/vendor/github-api.js.map +1 -1
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/github-extract.js +50 -3
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/github-issue-pr.d.ts +27 -0
- package/dist/humain/web-access/vendor/github-issue-pr.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-issue-pr.js +701 -0
- package/dist/humain/web-access/vendor/github-issue-pr.js.map +1 -0
- package/dist/humain/web-access/vendor/index.d.ts +3 -31
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +643 -530
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/kimi-search.d.ts +5 -0
- package/dist/humain/web-access/vendor/kimi-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/kimi-search.js +228 -0
- package/dist/humain/web-access/vendor/kimi-search.js.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts +3 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.js +89 -16
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +56 -8
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +6 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +12 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +343 -1
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.d.ts +4 -0
- package/dist/humain/web-access/vendor/xcrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/xcrawl.js +251 -0
- package/dist/humain/web-access/vendor/xcrawl.js.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.js +2 -2
- package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -14
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +9 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +53 -10
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +7 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +118 -55
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +151 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +68 -17
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +11 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +176 -106
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts +16 -0
- package/dist/modes/interactive/session-share.d.ts.map +1 -0
- package/dist/modes/interactive/session-share.js +188 -0
- package/dist/modes/interactive/session-share.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +6 -5
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +16 -13
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +20 -6
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +3 -2
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -7
- 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 +1 -0
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +189 -3
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/changelog.d.ts +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +12 -2
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +2 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/management-http.d.ts +5 -3
- package/dist/utils/management-http.d.ts.map +1 -1
- package/dist/utils/management-http.js +14 -10
- package/dist/utils/management-http.js.map +1 -1
- package/dist/utils/shell.d.ts +3 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +17 -5
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +1 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +64 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/version-check.js +4 -4
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +15 -0
- package/docs/custom-provider.md +5 -2
- package/docs/environment-variables.md +7 -7
- package/docs/extensions.md +17 -7
- package/docs/json.md +7 -2
- package/docs/keybindings.md +8 -8
- package/docs/llama-cpp.md +2 -0
- package/docs/models.md +8 -2
- package/docs/packages.md +2 -2
- package/docs/rpc.md +9 -3
- package/docs/sdk.md +7 -2
- package/docs/settings.md +11 -3
- package/docs/skills.md +3 -2
- package/docs/terminal-setup.md +8 -0
- package/docs/usage.md +10 -7
- package/docs/windows.md +15 -1
- package/examples/extensions/border-status-editor.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +70 -8
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/git-checkpoint.ts +2 -2
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/notify.ts +3 -1
- package/examples/extensions/sandbox/package-lock.json +14 -40
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +4 -4
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/06-extensions.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +293 -221
- package/package.json +21 -18
- package/src/humain/mcp-adapter/UPSTREAM.md +15 -5
- package/src/humain/mcp-adapter/upstream.json +4 -3
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +82 -0
- package/src/humain/web-access/UPSTREAM.md +1 -1
- package/src/humain/web-access/upstream.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/utils.ts"],"names":[],"mappings":"AAQA,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED,UAAU,iBAAiB;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAgCpE;AAMD,wBAAsB,4BAA4B,CACjD,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,EACjB,iBAAiB,EAAE,SAAS,MAAM,EAAE,GAClC,OAAO,CAAC,QAAQ,CAAC,CAmCnB;AAED,MAAM,WAAW,oBAAoB;IACpC,8DAA8D;IAC9D,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb;AAUD,kFAAkF;AAClF,wBAAgB,2BAA2B,IAAI,oBAAoB,CAyBlE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAa9F;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAOnD;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkB/E;AA0BD,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAKzE;AAED,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAG9C;AAED,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAkBD,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAMpD;AAED,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACtD,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAOD,4GAA4G;AAC5G,wBAAgB,uBAAuB,IAAI,IAAI,CAsB9C"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
1
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
4
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { hostname, tmpdir } from "node:os";
|
|
3
6
|
import { join } from "node:path";
|
|
4
7
|
import { getAgentDir } from "../host.js";
|
|
5
8
|
export function getWebSearchConfigDir() {
|
|
@@ -158,4 +161,343 @@ export function mapFfmpegError(err) {
|
|
|
158
161
|
const snippet = trimErrorText(stderr || message);
|
|
159
162
|
return snippet ? `ffmpeg failed: ${snippet}` : "ffmpeg failed";
|
|
160
163
|
}
|
|
164
|
+
const proxyStorage = new AsyncLocalStorage();
|
|
165
|
+
export function normalizeProxyUrl(value, source) {
|
|
166
|
+
if (value === undefined || value === null)
|
|
167
|
+
return null;
|
|
168
|
+
if (typeof value !== "string")
|
|
169
|
+
throw new Error(`${source} must be an http(s) proxy URL string`);
|
|
170
|
+
const trimmed = value.trim();
|
|
171
|
+
if (!trimmed)
|
|
172
|
+
return null;
|
|
173
|
+
let parsed;
|
|
174
|
+
try {
|
|
175
|
+
parsed = new URL(trimmed);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
throw new Error(`${source} must be a valid proxy URL: ${JSON.stringify(trimmed)}`);
|
|
179
|
+
}
|
|
180
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
181
|
+
throw new Error(`${source} must use the http:// or https:// scheme: ${trimmed}`);
|
|
182
|
+
}
|
|
183
|
+
if (!parsed.hostname)
|
|
184
|
+
throw new Error(`${source} must include a proxy host: ${trimmed}`);
|
|
185
|
+
parsed.hash = "";
|
|
186
|
+
parsed.search = "";
|
|
187
|
+
return parsed.toString();
|
|
188
|
+
}
|
|
189
|
+
function redactProxyUrl(value) {
|
|
190
|
+
const parsed = new URL(value);
|
|
191
|
+
if (parsed.username)
|
|
192
|
+
parsed.username = "redacted";
|
|
193
|
+
if (parsed.password)
|
|
194
|
+
parsed.password = "redacted";
|
|
195
|
+
return parsed.toString();
|
|
196
|
+
}
|
|
197
|
+
function loadConfiguredProxy() {
|
|
198
|
+
let configured;
|
|
199
|
+
const path = getWebSearchConfigPath();
|
|
200
|
+
if (existsSync(path)) {
|
|
201
|
+
let raw;
|
|
202
|
+
try {
|
|
203
|
+
raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
207
|
+
throw new Error(`Failed to load proxy config from ${path}: ${message}`);
|
|
208
|
+
}
|
|
209
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw))
|
|
210
|
+
configured = raw.proxy;
|
|
211
|
+
}
|
|
212
|
+
if (configured === undefined)
|
|
213
|
+
return null;
|
|
214
|
+
return normalizeProxyUrl(configured, `proxy in ${getWebSearchConfigPath()}`);
|
|
215
|
+
}
|
|
216
|
+
export function runWithProxy(proxy, fn) {
|
|
217
|
+
const normalized = proxy === undefined
|
|
218
|
+
? loadConfiguredProxy()
|
|
219
|
+
: normalizeProxyUrl(proxy, "proxy");
|
|
220
|
+
return proxyStorage.run(normalized, fn);
|
|
221
|
+
}
|
|
222
|
+
export function getActiveProxy() {
|
|
223
|
+
const scoped = proxyStorage.getStore();
|
|
224
|
+
return scoped !== undefined ? scoped : loadConfiguredProxy();
|
|
225
|
+
}
|
|
226
|
+
export function hasScopedProxyDecision() {
|
|
227
|
+
return proxyStorage.getStore() !== undefined;
|
|
228
|
+
}
|
|
229
|
+
function noProxyEntryMatches(hostname, entry) {
|
|
230
|
+
if (!entry)
|
|
231
|
+
return false;
|
|
232
|
+
if (entry === "*")
|
|
233
|
+
return true;
|
|
234
|
+
let host = entry;
|
|
235
|
+
if (host.startsWith("[")) {
|
|
236
|
+
const close = host.indexOf("]");
|
|
237
|
+
if (close > 0)
|
|
238
|
+
host = host.slice(0, close + 1);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const colon = host.lastIndexOf(":");
|
|
242
|
+
if (colon > -1 && /^\d+$/.test(host.slice(colon + 1)))
|
|
243
|
+
host = host.slice(0, colon);
|
|
244
|
+
}
|
|
245
|
+
host = host.toLowerCase().replace(/^\[|\]$/g, "");
|
|
246
|
+
if (!host)
|
|
247
|
+
return false;
|
|
248
|
+
return hostname === host || hostname.endsWith(host.startsWith(".") ? host : `.${host}`);
|
|
249
|
+
}
|
|
250
|
+
/** True when a URL must NOT be sent through the active proxy. */
|
|
251
|
+
export function isProxyBypassedUrl(url) {
|
|
252
|
+
const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
253
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "127.0.0.1" || hostname === "::1")
|
|
254
|
+
return true;
|
|
255
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
|
256
|
+
if (noProxy && noProxy.split(",").some((entry) => noProxyEntryMatches(hostname, entry.trim())))
|
|
257
|
+
return true;
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
/** Wraps globalThis.fetch so every http(s) call routes through curl while a proxy is active. Idempotent. */
|
|
261
|
+
export function installGlobalProxyFetch() {
|
|
262
|
+
const current = globalThis.fetch;
|
|
263
|
+
if (typeof current !== "function" || current.__piWebAccessProxyFetch === true)
|
|
264
|
+
return;
|
|
265
|
+
const nativeFetch = current;
|
|
266
|
+
const wrapped = ((input, init) => {
|
|
267
|
+
// Explicitly attached proxies survive pLimit context loss. Otherwise only
|
|
268
|
+
// web-access calls inside runWithProxy may use the configured proxy.
|
|
269
|
+
const proxy = init?.__proxy ?? (hasScopedProxyDecision() ? getActiveProxy() : null);
|
|
270
|
+
if (!proxy)
|
|
271
|
+
return nativeFetch(input, init);
|
|
272
|
+
let url = null;
|
|
273
|
+
try {
|
|
274
|
+
url = new URL(typeof input === "string" || input instanceof URL ? input : input.url);
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
url = null;
|
|
278
|
+
}
|
|
279
|
+
if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || isProxyBypassedUrl(url)) {
|
|
280
|
+
return nativeFetch(input, init);
|
|
281
|
+
}
|
|
282
|
+
return fetchViaCurl(url, init ?? {}, proxy);
|
|
283
|
+
});
|
|
284
|
+
wrapped.__piWebAccessProxyFetch = true;
|
|
285
|
+
globalThis.fetch = wrapped;
|
|
286
|
+
}
|
|
287
|
+
function parseHeaderDump(dump) {
|
|
288
|
+
const blocks = dump.split(/\r?\n\r?\n/).filter((block) => /^HTTP\/[\d.]+\s+\d{3}/.test(block.trim()));
|
|
289
|
+
const block = (blocks.length > 0 ? blocks[blocks.length - 1] : "").trim();
|
|
290
|
+
const lines = block.split(/\r?\n/);
|
|
291
|
+
let status = 0;
|
|
292
|
+
let statusText = "";
|
|
293
|
+
const headers = [];
|
|
294
|
+
for (const line of lines) {
|
|
295
|
+
const match = /^HTTP\/[\d.]+\s+(\d{3})(?:\s+(.*))?$/.exec(line.trim());
|
|
296
|
+
if (match) {
|
|
297
|
+
status = Number(match[1]);
|
|
298
|
+
statusText = match[2] ?? "";
|
|
299
|
+
headers.length = 0;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
const separator = line.indexOf(":");
|
|
303
|
+
if (separator > 0) {
|
|
304
|
+
const name = line.slice(0, separator).trim();
|
|
305
|
+
if (name.toLowerCase() === "content-encoding" || name.toLowerCase() === "content-length")
|
|
306
|
+
continue;
|
|
307
|
+
headers.push([name, line.slice(separator + 1).trim()]);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return { status, statusText, headers };
|
|
311
|
+
}
|
|
312
|
+
class CurlTransportError extends Error {
|
|
313
|
+
}
|
|
314
|
+
function quoteCurlConfigValue(value, label) {
|
|
315
|
+
if (/[\0-\x08\x0c\x0e-\x1f\x7f]/.test(value)) {
|
|
316
|
+
throw new Error(`${label} contains unsupported control characters`);
|
|
317
|
+
}
|
|
318
|
+
return `"${value
|
|
319
|
+
.replace(/\\/g, "\\\\")
|
|
320
|
+
.replace(/"/g, '\\"')
|
|
321
|
+
.replace(/\t/g, "\\t")
|
|
322
|
+
.replace(/\n/g, "\\n")
|
|
323
|
+
.replace(/\r/g, "\\r")
|
|
324
|
+
.replace(/\v/g, "\\v")}"`;
|
|
325
|
+
}
|
|
326
|
+
function curlConfigOption(name, value, label = name) {
|
|
327
|
+
return value === undefined ? name : `${name} = ${quoteCurlConfigValue(value, label)}`;
|
|
328
|
+
}
|
|
329
|
+
async function fetchViaCurl(url, init, proxyUrl) {
|
|
330
|
+
let current = url;
|
|
331
|
+
let currentInit = init;
|
|
332
|
+
for (let redirects = 0;; redirects++) {
|
|
333
|
+
const response = await fetchViaCurlOnce(current, currentInit, proxyUrl);
|
|
334
|
+
const location = response.headers.get("location");
|
|
335
|
+
if (!location || ![301, 302, 303, 307, 308].includes(response.status)) {
|
|
336
|
+
if (redirects > 0)
|
|
337
|
+
Object.defineProperty(response, "redirected", { value: true, configurable: true });
|
|
338
|
+
return response;
|
|
339
|
+
}
|
|
340
|
+
if (currentInit.redirect === "manual")
|
|
341
|
+
return response;
|
|
342
|
+
if (currentInit.redirect === "error")
|
|
343
|
+
throw new TypeError(`Proxy fetch redirect blocked from ${current.toString()}`);
|
|
344
|
+
if (redirects === 20)
|
|
345
|
+
throw new Error(`Too many proxy redirects from ${url.toString()}`);
|
|
346
|
+
const next = new URL(location, current);
|
|
347
|
+
if (next.protocol !== "http:" && next.protocol !== "https:")
|
|
348
|
+
throw new Error(`Proxy redirect from ${current.origin} must use HTTP(S)`);
|
|
349
|
+
let headers = new Headers(currentInit.headers);
|
|
350
|
+
let nextInit;
|
|
351
|
+
const method = currentInit.method?.toUpperCase() ?? "GET";
|
|
352
|
+
if (((response.status === 301 || response.status === 302) && method === "POST") || (response.status === 303 && method !== "GET" && method !== "HEAD")) {
|
|
353
|
+
for (const name of ["Content-Encoding", "Content-Language", "Content-Location", "Content-Type"])
|
|
354
|
+
headers.delete(name);
|
|
355
|
+
const { body: _body, ...withoutBody } = currentInit;
|
|
356
|
+
nextInit = { ...withoutBody, method: "GET", headers };
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
nextInit = { ...currentInit, headers };
|
|
360
|
+
}
|
|
361
|
+
if (next.origin !== current.origin) {
|
|
362
|
+
headers = new Headers();
|
|
363
|
+
nextInit = { ...nextInit, headers };
|
|
364
|
+
}
|
|
365
|
+
current = next;
|
|
366
|
+
currentInit = nextInit;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
async function fetchViaCurlOnce(url, init, proxyUrl) {
|
|
370
|
+
const method = (init.method ?? "GET").toUpperCase();
|
|
371
|
+
const headers = new Headers(init.headers);
|
|
372
|
+
const dir = await mkdtemp(join(tmpdir(), "pi-web-access-proxy-"));
|
|
373
|
+
const headerFile = join(dir, "headers");
|
|
374
|
+
const bodyFile = join(dir, "body");
|
|
375
|
+
const requestBodyFile = join(dir, "request-body");
|
|
376
|
+
const config = [
|
|
377
|
+
curlConfigOption("silent"),
|
|
378
|
+
curlConfigOption("show-error"),
|
|
379
|
+
curlConfigOption("compressed"),
|
|
380
|
+
curlConfigOption("connect-timeout", "20"),
|
|
381
|
+
curlConfigOption("proxy", proxyUrl, "proxy URL"),
|
|
382
|
+
curlConfigOption("dump-header", headerFile),
|
|
383
|
+
curlConfigOption("output", bodyFile),
|
|
384
|
+
curlConfigOption("write-out", "%{json}"),
|
|
385
|
+
];
|
|
386
|
+
if (method !== "GET" && method !== "HEAD")
|
|
387
|
+
config.push(curlConfigOption("request", method));
|
|
388
|
+
for (const [name, value] of headers.entries()) {
|
|
389
|
+
if (value === "")
|
|
390
|
+
continue;
|
|
391
|
+
config.push(curlConfigOption("header", `${name}: ${value}`, `header ${name}`));
|
|
392
|
+
}
|
|
393
|
+
const body = init.body;
|
|
394
|
+
if (body !== undefined && body !== null) {
|
|
395
|
+
let buffer;
|
|
396
|
+
if (typeof body === "string")
|
|
397
|
+
buffer = Buffer.from(body, "utf-8");
|
|
398
|
+
else if (body instanceof URLSearchParams)
|
|
399
|
+
buffer = Buffer.from(body.toString(), "utf-8");
|
|
400
|
+
else if (body instanceof ArrayBuffer)
|
|
401
|
+
buffer = Buffer.from(body);
|
|
402
|
+
else if (ArrayBuffer.isView(body))
|
|
403
|
+
buffer = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
404
|
+
else
|
|
405
|
+
throw new Error(`Unsupported request body type for proxy fetch: ${typeof body}`);
|
|
406
|
+
await writeFile(requestBodyFile, buffer, { mode: 0o600 });
|
|
407
|
+
config.push(curlConfigOption("data-binary", `@${requestBodyFile}`));
|
|
408
|
+
if (method === "GET")
|
|
409
|
+
config.push(curlConfigOption("request", "GET"));
|
|
410
|
+
}
|
|
411
|
+
config.push(curlConfigOption("url", url.toString(), "request URL"));
|
|
412
|
+
const configInput = `${config.join("\n")}\n`;
|
|
413
|
+
const signal = init.signal ?? null;
|
|
414
|
+
let stdout;
|
|
415
|
+
try {
|
|
416
|
+
stdout = await new Promise((resolve, reject) => {
|
|
417
|
+
if (signal?.aborted) {
|
|
418
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const child = spawn("curl", ["--config", "-"], { windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
422
|
+
let out = "";
|
|
423
|
+
let stderr = "";
|
|
424
|
+
const onAbort = () => { try {
|
|
425
|
+
child.kill();
|
|
426
|
+
}
|
|
427
|
+
catch { } };
|
|
428
|
+
if (signal) {
|
|
429
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
430
|
+
}
|
|
431
|
+
child.stdout?.on("data", (chunk) => { out += chunk.toString("utf-8"); });
|
|
432
|
+
child.stderr?.on("data", (chunk) => { if (stderr.length < 4096)
|
|
433
|
+
stderr += chunk.toString("utf-8"); });
|
|
434
|
+
child.once("error", (err) => {
|
|
435
|
+
signal?.removeEventListener("abort", onAbort);
|
|
436
|
+
reject(new CurlTransportError(err.code === "ENOENT"
|
|
437
|
+
? "curl executable not found on PATH; proxy transport requires curl"
|
|
438
|
+
: `curl failed to start: ${err.message}`));
|
|
439
|
+
});
|
|
440
|
+
child.once("close", (code) => {
|
|
441
|
+
signal?.removeEventListener("abort", onAbort);
|
|
442
|
+
if (signal?.aborted)
|
|
443
|
+
return reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
444
|
+
if (code !== 0 && !out.trim()) {
|
|
445
|
+
return reject(new CurlTransportError(`curl exited with code ${code ?? "unknown"} via ${redactProxyUrl(proxyUrl)}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
|
|
446
|
+
}
|
|
447
|
+
resolve(out);
|
|
448
|
+
});
|
|
449
|
+
if (!child.stdin) {
|
|
450
|
+
child.kill();
|
|
451
|
+
reject(new CurlTransportError("curl stdin unavailable for protected proxy configuration"));
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
child.stdin.on("error", (err) => reject(new CurlTransportError(`curl stdin failed: ${err.message}`)));
|
|
455
|
+
child.stdin.end(configInput);
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
await rm(dir, { recursive: true, force: true }).catch(() => { });
|
|
460
|
+
if (err instanceof CurlTransportError)
|
|
461
|
+
throw new Error(err.message);
|
|
462
|
+
throw err;
|
|
463
|
+
}
|
|
464
|
+
let bodyBuffer = Buffer.alloc(0);
|
|
465
|
+
let dump = "";
|
|
466
|
+
try {
|
|
467
|
+
[dump, bodyBuffer] = await Promise.all([readFile(headerFile, "utf-8"), readFile(bodyFile)]);
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
// HEAD or empty responses may not produce output files.
|
|
471
|
+
}
|
|
472
|
+
finally {
|
|
473
|
+
await rm(dir, { recursive: true, force: true }).catch(() => { });
|
|
474
|
+
}
|
|
475
|
+
const { status, statusText, headers: responseHeaders } = parseHeaderDump(dump);
|
|
476
|
+
if (status === 0) {
|
|
477
|
+
throw new Error(`Proxy fetch to ${url.toString()} via ${redactProxyUrl(proxyUrl)} returned no HTTP status`);
|
|
478
|
+
}
|
|
479
|
+
let finalUrl = url.toString();
|
|
480
|
+
let redirected = false;
|
|
481
|
+
try {
|
|
482
|
+
const trimmed = stdout.trim();
|
|
483
|
+
if (trimmed.startsWith("{")) {
|
|
484
|
+
const writeOut = JSON.parse(trimmed);
|
|
485
|
+
if (writeOut.url_effective)
|
|
486
|
+
finalUrl = writeOut.url_effective;
|
|
487
|
+
redirected = (writeOut.num_redirects ?? 0) > 0;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch {
|
|
491
|
+
// Older curl without %{json}; the header dump already provided the status.
|
|
492
|
+
}
|
|
493
|
+
const nullBody = status === 204 || status === 205 || status === 304;
|
|
494
|
+
const response = new Response(nullBody ? null : new Uint8Array(bodyBuffer), {
|
|
495
|
+
status,
|
|
496
|
+
statusText: statusText || undefined,
|
|
497
|
+
headers: new Headers(responseHeaders),
|
|
498
|
+
});
|
|
499
|
+
Object.defineProperty(response, "url", { value: finalUrl, configurable: true });
|
|
500
|
+
Object.defineProperty(response, "redirected", { value: redirected, configurable: true });
|
|
501
|
+
return response;
|
|
502
|
+
}
|
|
161
503
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,UAAU,qBAAqB;IACpC,OAAO,WAAW,EAAE,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,sBAAsB;IACrC,OAAO,IAAI,CAAC,qBAAqB,EAAE,EAAE,iBAAiB,CAAC,CAAC;AACzD,CAAC;AAUD,MAAM,UAAU,iBAAiB,CAAC,OAA0B;IAC3D,MAAM,eAAe,GAAG,OAAO,CAAC,gBAAgB,KAAK,SAAS,CAAC;IAC/D,MAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,gB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readFileSync } from \"node:fs\";\nimport { hostname } from \"node:os\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../host.ts\";\n\nexport function getWebSearchConfigDir(): string {\n\treturn getAgentDir();\n}\n\nexport function getWebSearchConfigPath(): string {\n\treturn join(getWebSearchConfigDir(), \"web-search.json\");\n}\n\ninterface ApiBaseUrlOptions {\n\tconfigKey: string;\n\tconfiguredValue: unknown;\n\tdefaultValue: string;\n\tenvironmentKey: string;\n\tenvironmentValue: string | undefined;\n}\n\nexport function resolveApiBaseUrl(options: ApiBaseUrlOptions): string {\n\tconst fromEnvironment = options.environmentValue !== undefined;\n\tconst value = fromEnvironment ? options.environmentValue : options.configuredValue;\n\tif (value === undefined) return options.defaultValue;\n\n\tconst source = fromEnvironment\n\t\t? options.environmentKey\n\t\t: `${options.configKey} in ${getWebSearchConfigPath()}`;\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new Error(`${source} must be an absolute HTTP(S) URL`);\n\t}\n\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value.trim());\n\t} catch {\n\t\tthrow new Error(`${source} must be an absolute HTTP(S) URL`);\n\t}\n\tif (url.protocol !== \"https:\") {\n\t\tthrow new Error(`${source} must be an absolute HTTPS URL`);\n\t}\n\tif (url.username || url.password) {\n\t\tthrow new Error(`${source} must not include credentials`);\n\t}\n\tif (url.search || url.hash) {\n\t\tthrow new Error(`${source} must not include query parameters or fragments`);\n\t}\n\n\turl.search = \"\";\n\turl.hash = \"\";\n\turl.pathname = url.pathname.replace(/\\/+$/, \"\");\n\treturn url.toString().replace(/\\/+$/, \"\");\n}\n\nconst API_REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\nconst API_REQUEST_BODY_HEADERS = [\"Content-Encoding\", \"Content-Language\", \"Content-Location\", \"Content-Type\"];\nconst MAX_API_REDIRECTS = 5;\n\nexport async function fetchWithCredentialRedirects(\n\turl: string,\n\tinit: RequestInit,\n\tcredentialHeaders: readonly string[],\n): Promise<Response> {\n\tlet current = new URL(url);\n\tlet requestInit = init;\n\n\tfor (let redirects = 0; ; redirects++) {\n\t\tconst response = await fetch(current, { ...requestInit, redirect: \"manual\" });\n\t\tif (!API_REDIRECT_STATUSES.has(response.status)) return response;\n\n\t\tconst location = response.headers.get(\"location\");\n\t\tif (!location) return response;\n\t\tif (redirects === MAX_API_REDIRECTS) {\n\t\t\tthrow new Error(`Too many API redirects from ${url}`);\n\t\t}\n\n\t\tconst next = new URL(location, current);\n\t\tif (next.protocol !== \"http:\" && next.protocol !== \"https:\") {\n\t\t\tthrow new Error(`API redirect from ${current.origin} must use HTTP(S)`);\n\t\t}\n\t\tconst method = requestInit.method?.toUpperCase() ?? \"GET\";\n\t\tif (\n\t\t\t((response.status === 301 || response.status === 302) && method === \"POST\")\n\t\t\t|| (response.status === 303 && method !== \"GET\" && method !== \"HEAD\")\n\t\t) {\n\t\t\tconst headers = new Headers(requestInit.headers);\n\t\t\tfor (const name of API_REQUEST_BODY_HEADERS) headers.delete(name);\n\t\t\tconst { body: _body, ...withoutBody } = requestInit;\n\t\t\trequestInit = { ...withoutBody, method: \"GET\", headers };\n\t\t}\n\t\tif (next.origin !== current.origin) {\n\t\t\tconst headers = new Headers(requestInit.headers);\n\t\t\tfor (const name of credentialHeaders) headers.delete(name);\n\t\t\trequestInit = { ...requestInit, headers };\n\t\t}\n\t\tcurrent = next;\n\t}\n}\n\nexport interface CuratorNetworkConfig {\n\t/** Whether remote access was opted into via curatorRemote. */\n\tenabled: boolean;\n\thost: string;\n\tbind: string;\n}\n\nconst LOCAL_CURATOR_NETWORK_DEFAULTS: CuratorNetworkConfig = { enabled: false, host: \"localhost\", bind: \"127.0.0.1\" };\n\nfunction trimmedString(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst trimmed = value.trim();\n\treturn trimmed.length > 0 ? trimmed : undefined;\n}\n\n/** Resolves the curator server bind address and URL host from `curatorRemote`. */\nexport function resolveCuratorNetworkConfig(): CuratorNetworkConfig {\n\tconst configPath = getWebSearchConfigPath();\n\tif (!existsSync(configPath)) return LOCAL_CURATOR_NETWORK_DEFAULTS;\n\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(readFileSync(configPath, \"utf-8\"));\n\t} catch {\n\t\treturn LOCAL_CURATOR_NETWORK_DEFAULTS;\n\t}\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return LOCAL_CURATOR_NETWORK_DEFAULTS;\n\n\tconst curatorRemote = (raw as Record<string, unknown>).curatorRemote;\n\tif (curatorRemote === true) return { enabled: true, host: hostname(), bind: \"0.0.0.0\" };\n\n\tif (curatorRemote && typeof curatorRemote === \"object\" && !Array.isArray(curatorRemote)) {\n\t\tconst obj = curatorRemote as Record<string, unknown>;\n\t\treturn {\n\t\t\tenabled: true,\n\t\t\thost: trimmedString(obj.host) ?? hostname(),\n\t\t\tbind: trimmedString(obj.bind) ?? \"0.0.0.0\",\n\t\t};\n\t}\n\n\treturn LOCAL_CURATOR_NETWORK_DEFAULTS;\n}\n\nexport function formatSeconds(s: number): string {\n\tconst h = Math.floor(s / 3600);\n\tconst m = Math.floor((s % 3600) / 60);\n\tconst sec = s % 60;\n\tif (h > 0) return `${h}:${String(m).padStart(2, \"0\")}:${String(sec).padStart(2, \"0\")}`;\n\treturn `${m}:${String(sec).padStart(2, \"0\")}`;\n}\n\nexport function readExecError(err: unknown): { code?: string; stderr: string; message: string } {\n\tif (!err || typeof err !== \"object\") {\n\t\treturn { stderr: \"\", message: String(err) };\n\t}\n\tconst code = (err as { code?: string }).code;\n\tconst message = (err as { message?: string }).message ?? \"\";\n\tconst stderrRaw = (err as { stderr?: Buffer | string }).stderr;\n\tconst stderr = Buffer.isBuffer(stderrRaw)\n\t\t? stderrRaw.toString(\"utf-8\")\n\t\t: typeof stderrRaw === \"string\"\n\t\t\t? stderrRaw\n\t\t\t: \"\";\n\treturn { code, stderr, message };\n}\n\nexport function isTimeoutError(err: unknown): boolean {\n\tif (!err || typeof err !== \"object\") return false;\n\tif ((err as { killed?: boolean }).killed) return true;\n\tconst name = (err as { name?: string }).name;\n\tconst code = (err as { code?: string }).code;\n\tconst message = (err as { message?: string }).message ?? \"\";\n\treturn name === \"AbortError\" || code === \"ETIMEDOUT\" || message.toLowerCase().includes(\"timed out\");\n}\n\nexport function trimErrorText(text: string): string {\n\treturn text.replace(/\\s+/g, \" \").trim().slice(0, 200);\n}\n\nexport function mapFfmpegError(err: unknown): string {\n\tconst { code, stderr, message } = readExecError(err);\n\tif (code === \"ENOENT\") return \"ffmpeg is not installed. Install with: brew install ffmpeg\";\n\tif (isTimeoutError(err)) return \"ffmpeg timed out extracting frame\";\n\tif (stderr.includes(\"403\")) return \"Stream URL returned 403 — may have expired, try again\";\n\tconst snippet = trimErrorText(stderr || message);\n\treturn snippet ? `ffmpeg failed: ${snippet}` : \"ffmpeg failed\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,UAAU,qBAAqB;IACpC,OAAO,WAAW,EAAE,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,sBAAsB;IACrC,OAAO,IAAI,CAAC,qBAAqB,EAAE,EAAE,iBAAiB,CAAC,CAAC;AACzD,CAAC;AAUD,MAAM,UAAU,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QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;QAC3E,MAAM;QACN,UAAU,EAAE,UAAU,IAAI,SAAS;QACnC,OAAO,EAAE,IAAI,OAAO,CAAC,eAAe,CAAC;KACrC,CAAC,CAAC;IACH,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IAChF,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IACzF,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { spawn } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { hostname, tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../host.ts\";\n\nexport function getWebSearchConfigDir(): string {\n\treturn getAgentDir();\n}\n\nexport function getWebSearchConfigPath(): string {\n\treturn join(getWebSearchConfigDir(), \"web-search.json\");\n}\n\ninterface ApiBaseUrlOptions {\n\tconfigKey: string;\n\tconfiguredValue: unknown;\n\tdefaultValue: string;\n\tenvironmentKey: string;\n\tenvironmentValue: string | undefined;\n}\n\nexport function resolveApiBaseUrl(options: ApiBaseUrlOptions): string {\n\tconst fromEnvironment = options.environmentValue !== undefined;\n\tconst value = fromEnvironment ? options.environmentValue : options.configuredValue;\n\tif (value === undefined) return options.defaultValue;\n\n\tconst source = fromEnvironment\n\t\t? options.environmentKey\n\t\t: `${options.configKey} in ${getWebSearchConfigPath()}`;\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new Error(`${source} must be an absolute HTTP(S) URL`);\n\t}\n\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value.trim());\n\t} catch {\n\t\tthrow new Error(`${source} must be an absolute HTTP(S) URL`);\n\t}\n\tif (url.protocol !== \"https:\") {\n\t\tthrow new Error(`${source} must be an absolute HTTPS URL`);\n\t}\n\tif (url.username || url.password) {\n\t\tthrow new Error(`${source} must not include credentials`);\n\t}\n\tif (url.search || url.hash) {\n\t\tthrow new Error(`${source} must not include query parameters or fragments`);\n\t}\n\n\turl.search = \"\";\n\turl.hash = \"\";\n\turl.pathname = url.pathname.replace(/\\/+$/, \"\");\n\treturn url.toString().replace(/\\/+$/, \"\");\n}\n\nconst API_REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\nconst API_REQUEST_BODY_HEADERS = [\"Content-Encoding\", \"Content-Language\", \"Content-Location\", \"Content-Type\"];\nconst MAX_API_REDIRECTS = 5;\n\nexport async function fetchWithCredentialRedirects(\n\turl: string,\n\tinit: RequestInit,\n\tcredentialHeaders: readonly string[],\n): Promise<Response> {\n\tlet current = new URL(url);\n\tlet requestInit = init;\n\n\tfor (let redirects = 0; ; redirects++) {\n\t\tconst response = await fetch(current, { ...requestInit, redirect: \"manual\" });\n\t\tif (!API_REDIRECT_STATUSES.has(response.status)) return response;\n\n\t\tconst location = response.headers.get(\"location\");\n\t\tif (!location) return response;\n\t\tif (redirects === MAX_API_REDIRECTS) {\n\t\t\tthrow new Error(`Too many API redirects from ${url}`);\n\t\t}\n\n\t\tconst next = new URL(location, current);\n\t\tif (next.protocol !== \"http:\" && next.protocol !== \"https:\") {\n\t\t\tthrow new Error(`API redirect from ${current.origin} must use HTTP(S)`);\n\t\t}\n\t\tconst method = requestInit.method?.toUpperCase() ?? \"GET\";\n\t\tif (\n\t\t\t((response.status === 301 || response.status === 302) && method === \"POST\")\n\t\t\t|| (response.status === 303 && method !== \"GET\" && method !== \"HEAD\")\n\t\t) {\n\t\t\tconst headers = new Headers(requestInit.headers);\n\t\t\tfor (const name of API_REQUEST_BODY_HEADERS) headers.delete(name);\n\t\t\tconst { body: _body, ...withoutBody } = requestInit;\n\t\t\trequestInit = { ...withoutBody, method: \"GET\", headers };\n\t\t}\n\t\tif (next.origin !== current.origin) {\n\t\t\tconst headers = new Headers(requestInit.headers);\n\t\t\tfor (const name of credentialHeaders) headers.delete(name);\n\t\t\trequestInit = { ...requestInit, headers };\n\t\t}\n\t\tcurrent = next;\n\t}\n}\n\nexport interface CuratorNetworkConfig {\n\t/** Whether remote access was opted into via curatorRemote. */\n\tenabled: boolean;\n\thost: string;\n\tbind: string;\n}\n\nconst LOCAL_CURATOR_NETWORK_DEFAULTS: CuratorNetworkConfig = { enabled: false, host: \"localhost\", bind: \"127.0.0.1\" };\n\nfunction trimmedString(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst trimmed = value.trim();\n\treturn trimmed.length > 0 ? trimmed : undefined;\n}\n\n/** Resolves the curator server bind address and URL host from `curatorRemote`. */\nexport function resolveCuratorNetworkConfig(): CuratorNetworkConfig {\n\tconst configPath = getWebSearchConfigPath();\n\tif (!existsSync(configPath)) return LOCAL_CURATOR_NETWORK_DEFAULTS;\n\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(readFileSync(configPath, \"utf-8\"));\n\t} catch {\n\t\treturn LOCAL_CURATOR_NETWORK_DEFAULTS;\n\t}\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return LOCAL_CURATOR_NETWORK_DEFAULTS;\n\n\tconst curatorRemote = (raw as Record<string, unknown>).curatorRemote;\n\tif (curatorRemote === true) return { enabled: true, host: hostname(), bind: \"0.0.0.0\" };\n\n\tif (curatorRemote && typeof curatorRemote === \"object\" && !Array.isArray(curatorRemote)) {\n\t\tconst obj = curatorRemote as Record<string, unknown>;\n\t\treturn {\n\t\t\tenabled: true,\n\t\t\thost: trimmedString(obj.host) ?? hostname(),\n\t\t\tbind: trimmedString(obj.bind) ?? \"0.0.0.0\",\n\t\t};\n\t}\n\n\treturn LOCAL_CURATOR_NETWORK_DEFAULTS;\n}\n\nexport function formatSeconds(s: number): string {\n\tconst h = Math.floor(s / 3600);\n\tconst m = Math.floor((s % 3600) / 60);\n\tconst sec = s % 60;\n\tif (h > 0) return `${h}:${String(m).padStart(2, \"0\")}:${String(sec).padStart(2, \"0\")}`;\n\treturn `${m}:${String(sec).padStart(2, \"0\")}`;\n}\n\nexport function readExecError(err: unknown): { code?: string; stderr: string; message: string } {\n\tif (!err || typeof err !== \"object\") {\n\t\treturn { stderr: \"\", message: String(err) };\n\t}\n\tconst code = (err as { code?: string }).code;\n\tconst message = (err as { message?: string }).message ?? \"\";\n\tconst stderrRaw = (err as { stderr?: Buffer | string }).stderr;\n\tconst stderr = Buffer.isBuffer(stderrRaw)\n\t\t? stderrRaw.toString(\"utf-8\")\n\t\t: typeof stderrRaw === \"string\"\n\t\t\t? stderrRaw\n\t\t\t: \"\";\n\treturn { code, stderr, message };\n}\n\nexport function isTimeoutError(err: unknown): boolean {\n\tif (!err || typeof err !== \"object\") return false;\n\tif ((err as { killed?: boolean }).killed) return true;\n\tconst name = (err as { name?: string }).name;\n\tconst code = (err as { code?: string }).code;\n\tconst message = (err as { message?: string }).message ?? \"\";\n\treturn name === \"AbortError\" || code === \"ETIMEDOUT\" || message.toLowerCase().includes(\"timed out\");\n}\n\nexport function trimErrorText(text: string): string {\n\treturn text.replace(/\\s+/g, \" \").trim().slice(0, 200);\n}\n\nexport function mapFfmpegError(err: unknown): string {\n\tconst { code, stderr, message } = readExecError(err);\n\tif (code === \"ENOENT\") return \"ffmpeg is not installed. Install with: brew install ffmpeg\";\n\tif (isTimeoutError(err)) return \"ffmpeg timed out extracting frame\";\n\tif (stderr.includes(\"403\")) return \"Stream URL returned 403 — may have expired, try again\";\n\tconst snippet = trimErrorText(stderr || message);\n\treturn snippet ? `ffmpeg failed: ${snippet}` : \"ffmpeg failed\";\n}\n\nconst proxyStorage = new AsyncLocalStorage<string | null>();\n\nexport function normalizeProxyUrl(value: unknown, source: string): string | null {\n\tif (value === undefined || value === null) return null;\n\tif (typeof value !== \"string\") throw new Error(`${source} must be an http(s) proxy URL string`);\n\tconst trimmed = value.trim();\n\tif (!trimmed) return null;\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(trimmed);\n\t} catch {\n\t\tthrow new Error(`${source} must be a valid proxy URL: ${JSON.stringify(trimmed)}`);\n\t}\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\tthrow new Error(`${source} must use the http:// or https:// scheme: ${trimmed}`);\n\t}\n\tif (!parsed.hostname) throw new Error(`${source} must include a proxy host: ${trimmed}`);\n\tparsed.hash = \"\";\n\tparsed.search = \"\";\n\treturn parsed.toString();\n}\n\nfunction redactProxyUrl(value: string): string {\n\tconst parsed = new URL(value);\n\tif (parsed.username) parsed.username = \"redacted\";\n\tif (parsed.password) parsed.password = \"redacted\";\n\treturn parsed.toString();\n}\n\nfunction loadConfiguredProxy(): string | null {\n\tlet configured: unknown;\n\tconst path = getWebSearchConfigPath();\n\tif (existsSync(path)) {\n\t\tlet raw: unknown;\n\t\ttry {\n\t\t\traw = JSON.parse(readFileSync(path, \"utf-8\"));\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthrow new Error(`Failed to load proxy config from ${path}: ${message}`);\n\t\t}\n\t\tif (raw && typeof raw === \"object\" && !Array.isArray(raw)) configured = (raw as { proxy?: unknown }).proxy;\n\t}\n\tif (configured === undefined) return null;\n\treturn normalizeProxyUrl(configured, `proxy in ${getWebSearchConfigPath()}`);\n}\n\nexport function runWithProxy<T>(proxy: string | undefined, fn: () => T): T {\n\tconst normalized = proxy === undefined\n\t\t? loadConfiguredProxy()\n\t\t: normalizeProxyUrl(proxy, \"proxy\");\n\treturn proxyStorage.run(normalized, fn);\n}\n\nexport function getActiveProxy(): string | null {\n\tconst scoped = proxyStorage.getStore();\n\treturn scoped !== undefined ? scoped : loadConfiguredProxy();\n}\n\nexport function hasScopedProxyDecision(): boolean {\n\treturn proxyStorage.getStore() !== undefined;\n}\n\nfunction noProxyEntryMatches(hostname: string, entry: string): boolean {\n\tif (!entry) return false;\n\tif (entry === \"*\") return true;\n\tlet host = entry;\n\tif (host.startsWith(\"[\")) {\n\t\tconst close = host.indexOf(\"]\");\n\t\tif (close > 0) host = host.slice(0, close + 1);\n\t} else {\n\t\tconst colon = host.lastIndexOf(\":\");\n\t\tif (colon > -1 && /^\\d+$/.test(host.slice(colon + 1))) host = host.slice(0, colon);\n\t}\n\thost = host.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n\tif (!host) return false;\n\treturn hostname === host || hostname.endsWith(host.startsWith(\".\") ? host : `.${host}`);\n}\n\n/** True when a URL must NOT be sent through the active proxy. */\nexport function isProxyBypassedUrl(url: URL): boolean {\n\tconst hostname = url.hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n\tif (hostname === \"localhost\" || hostname.endsWith(\".localhost\") || hostname === \"127.0.0.1\" || hostname === \"::1\") return true;\n\tconst noProxy = process.env.NO_PROXY || process.env.no_proxy;\n\tif (noProxy && noProxy.split(\",\").some((entry) => noProxyEntryMatches(hostname, entry.trim()))) return true;\n\treturn false;\n}\n\nexport interface ProxiedRequestInit extends RequestInit {\n\t/** Caller-supplied proxy; bypasses AsyncLocalStorage for pLimit-safe contexts. */\n\t__proxy?: string;\n}\n\ninterface ProxiedFetch {\n\t(input: RequestInfo | URL, init?: ProxiedRequestInit): Promise<Response>;\n\t__piWebAccessProxyFetch?: boolean;\n}\n\n/** Wraps globalThis.fetch so every http(s) call routes through curl while a proxy is active. Idempotent. */\nexport function installGlobalProxyFetch(): void {\n\tconst current = globalThis.fetch as ProxiedFetch;\n\tif (typeof current !== \"function\" || current.__piWebAccessProxyFetch === true) return;\n\tconst nativeFetch = current;\n\tconst wrapped: ProxiedFetch = ((input: RequestInfo | URL, init?: ProxiedRequestInit) => {\n\t\t// Explicitly attached proxies survive pLimit context loss. Otherwise only\n\t\t// web-access calls inside runWithProxy may use the configured proxy.\n\t\tconst proxy = init?.__proxy ?? (hasScopedProxyDecision() ? getActiveProxy() : null);\n\t\tif (!proxy) return nativeFetch(input, init);\n\t\tlet url: URL | null = null;\n\t\ttry {\n\t\t\turl = new URL(typeof input === \"string\" || input instanceof URL ? input : input.url);\n\t\t} catch {\n\t\t\turl = null;\n\t\t}\n\t\tif (!url || (url.protocol !== \"http:\" && url.protocol !== \"https:\") || isProxyBypassedUrl(url)) {\n\t\t\treturn nativeFetch(input, init);\n\t\t}\n\t\treturn fetchViaCurl(url, init ?? {}, proxy);\n\t});\n\twrapped.__piWebAccessProxyFetch = true;\n\tglobalThis.fetch = wrapped;\n}\n\nfunction parseHeaderDump(dump: string): { status: number; statusText: string; headers: Array<[string, string]> } {\n\tconst blocks = dump.split(/\\r?\\n\\r?\\n/).filter((block) => /^HTTP\\/[\\d.]+\\s+\\d{3}/.test(block.trim()));\n\tconst block = (blocks.length > 0 ? blocks[blocks.length - 1] : \"\").trim();\n\tconst lines = block.split(/\\r?\\n/);\n\tlet status = 0;\n\tlet statusText = \"\";\n\tconst headers: Array<[string, string]> = [];\n\tfor (const line of lines) {\n\t\tconst match = /^HTTP\\/[\\d.]+\\s+(\\d{3})(?:\\s+(.*))?$/.exec(line.trim());\n\t\tif (match) {\n\t\t\tstatus = Number(match[1]);\n\t\t\tstatusText = match[2] ?? \"\";\n\t\t\theaders.length = 0;\n\t\t\tcontinue;\n\t\t}\n\t\tconst separator = line.indexOf(\":\");\n\t\tif (separator > 0) {\n\t\t\tconst name = line.slice(0, separator).trim();\n\t\t\tif (name.toLowerCase() === \"content-encoding\" || name.toLowerCase() === \"content-length\") continue;\n\t\t\theaders.push([name, line.slice(separator + 1).trim()]);\n\t\t}\n\t}\n\treturn { status, statusText, headers };\n}\n\nclass CurlTransportError extends Error {}\n\nfunction quoteCurlConfigValue(value: string, label: string): string {\n\tif (/[\\0-\\x08\\x0c\\x0e-\\x1f\\x7f]/.test(value)) {\n\t\tthrow new Error(`${label} contains unsupported control characters`);\n\t}\n\treturn `\"${value\n\t\t.replace(/\\\\/g, \"\\\\\\\\\")\n\t\t.replace(/\"/g, '\\\\\"')\n\t\t.replace(/\\t/g, \"\\\\t\")\n\t\t.replace(/\\n/g, \"\\\\n\")\n\t\t.replace(/\\r/g, \"\\\\r\")\n\t\t.replace(/\\v/g, \"\\\\v\")}\"`;\n}\n\nfunction curlConfigOption(name: string, value?: string, label = name): string {\n\treturn value === undefined ? name : `${name} = ${quoteCurlConfigValue(value, label)}`;\n}\n\nasync function fetchViaCurl(url: URL, init: RequestInit, proxyUrl: string): Promise<Response> {\n\tlet current = url;\n\tlet currentInit = init;\n\tfor (let redirects = 0; ; redirects++) {\n\t\tconst response = await fetchViaCurlOnce(current, currentInit, proxyUrl);\n\t\tconst location = response.headers.get(\"location\");\n\t\tif (!location || ![301, 302, 303, 307, 308].includes(response.status)) {\n\t\t\tif (redirects > 0) Object.defineProperty(response, \"redirected\", { value: true, configurable: true });\n\t\t\treturn response;\n\t\t}\n\t\tif (currentInit.redirect === \"manual\") return response;\n\t\tif (currentInit.redirect === \"error\") throw new TypeError(`Proxy fetch redirect blocked from ${current.toString()}`);\n\t\tif (redirects === 20) throw new Error(`Too many proxy redirects from ${url.toString()}`);\n\n\t\tconst next = new URL(location, current);\n\t\tif (next.protocol !== \"http:\" && next.protocol !== \"https:\") throw new Error(`Proxy redirect from ${current.origin} must use HTTP(S)`);\n\n\t\tlet headers = new Headers(currentInit.headers);\n\t\tlet nextInit: RequestInit;\n\t\tconst method = currentInit.method?.toUpperCase() ?? \"GET\";\n\t\tif (((response.status === 301 || response.status === 302) && method === \"POST\") || (response.status === 303 && method !== \"GET\" && method !== \"HEAD\")) {\n\t\t\tfor (const name of [\"Content-Encoding\", \"Content-Language\", \"Content-Location\", \"Content-Type\"]) headers.delete(name);\n\t\t\tconst { body: _body, ...withoutBody } = currentInit;\n\t\t\tnextInit = { ...withoutBody, method: \"GET\", headers };\n\t\t} else {\n\t\t\tnextInit = { ...currentInit, headers };\n\t\t}\n\n\t\tif (next.origin !== current.origin) {\n\t\t\theaders = new Headers();\n\t\t\tnextInit = { ...nextInit, headers };\n\t\t}\n\t\tcurrent = next;\n\t\tcurrentInit = nextInit;\n\t}\n}\n\nasync function fetchViaCurlOnce(url: URL, init: RequestInit, proxyUrl: string): Promise<Response> {\n\tconst method = (init.method ?? \"GET\").toUpperCase();\n\tconst headers = new Headers(init.headers);\n\n\tconst dir = await mkdtemp(join(tmpdir(), \"pi-web-access-proxy-\"));\n\tconst headerFile = join(dir, \"headers\");\n\tconst bodyFile = join(dir, \"body\");\n\tconst requestBodyFile = join(dir, \"request-body\");\n\n\tconst config: string[] = [\n\t\tcurlConfigOption(\"silent\"),\n\t\tcurlConfigOption(\"show-error\"),\n\t\tcurlConfigOption(\"compressed\"),\n\t\tcurlConfigOption(\"connect-timeout\", \"20\"),\n\t\tcurlConfigOption(\"proxy\", proxyUrl, \"proxy URL\"),\n\t\tcurlConfigOption(\"dump-header\", headerFile),\n\t\tcurlConfigOption(\"output\", bodyFile),\n\t\tcurlConfigOption(\"write-out\", \"%{json}\"),\n\t];\n\n\tif (method !== \"GET\" && method !== \"HEAD\") config.push(curlConfigOption(\"request\", method));\n\n\tfor (const [name, value] of headers.entries()) {\n\t\tif (value === \"\") continue;\n\t\tconfig.push(curlConfigOption(\"header\", `${name}: ${value}`, `header ${name}`));\n\t}\n\n\tconst body = init.body;\n\tif (body !== undefined && body !== null) {\n\t\tlet buffer: Buffer;\n\t\tif (typeof body === \"string\") buffer = Buffer.from(body, \"utf-8\");\n\t\telse if (body instanceof URLSearchParams) buffer = Buffer.from(body.toString(), \"utf-8\");\n\t\telse if (body instanceof ArrayBuffer) buffer = Buffer.from(body);\n\t\telse if (ArrayBuffer.isView(body)) buffer = Buffer.from(body.buffer, body.byteOffset, body.byteLength);\n\t\telse throw new Error(`Unsupported request body type for proxy fetch: ${typeof body}`);\n\t\tawait writeFile(requestBodyFile, buffer, { mode: 0o600 });\n\t\tconfig.push(curlConfigOption(\"data-binary\", `@${requestBodyFile}`));\n\t\tif (method === \"GET\") config.push(curlConfigOption(\"request\", \"GET\"));\n\t}\n\n\tconfig.push(curlConfigOption(\"url\", url.toString(), \"request URL\"));\n\tconst configInput = `${config.join(\"\\n\")}\\n`;\n\n\tconst signal = init.signal ?? null;\n\tlet stdout: string;\n\ttry {\n\t\tstdout = await new Promise<string>((resolve, reject) => {\n\t\t\tif (signal?.aborted) {\n\t\t\t\treject(new DOMException(\"The operation was aborted.\", \"AbortError\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst child = spawn(\"curl\", [\"--config\", \"-\"], { windowsHide: true, stdio: [\"pipe\", \"pipe\", \"pipe\"] });\n\t\t\tlet out = \"\";\n\t\t\tlet stderr = \"\";\n\t\t\tconst onAbort = () => { try { child.kill(); } catch {} };\n\t\t\tif (signal) {\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t}\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => { out += chunk.toString(\"utf-8\"); });\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => { if (stderr.length < 4096) stderr += chunk.toString(\"utf-8\"); });\n\t\t\tchild.once(\"error\", (err: NodeJS.ErrnoException) => {\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(new CurlTransportError(err.code === \"ENOENT\"\n\t\t\t\t\t? \"curl executable not found on PATH; proxy transport requires curl\"\n\t\t\t\t\t: `curl failed to start: ${err.message}`));\n\t\t\t});\n\t\t\tchild.once(\"close\", (code) => {\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (signal?.aborted) return reject(new DOMException(\"The operation was aborted.\", \"AbortError\"));\n\t\t\t\tif (code !== 0 && !out.trim()) {\n\t\t\t\t\treturn reject(new CurlTransportError(`curl exited with code ${code ?? \"unknown\"} via ${redactProxyUrl(proxyUrl)}${stderr.trim() ? `: ${stderr.trim()}` : \"\"}`));\n\t\t\t\t}\n\t\t\t\tresolve(out);\n\t\t\t});\n\t\t\tif (!child.stdin) {\n\t\t\t\tchild.kill();\n\t\t\t\treject(new CurlTransportError(\"curl stdin unavailable for protected proxy configuration\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tchild.stdin.on(\"error\", (err) => reject(new CurlTransportError(`curl stdin failed: ${err.message}`)));\n\t\t\tchild.stdin.end(configInput);\n\t\t});\n\t} catch (err) {\n\t\tawait rm(dir, { recursive: true, force: true }).catch(() => {});\n\t\tif (err instanceof CurlTransportError) throw new Error(err.message);\n\t\tthrow err;\n\t}\n\n\tlet bodyBuffer = Buffer.alloc(0);\n\tlet dump = \"\";\n\ttry {\n\t\t[dump, bodyBuffer] = await Promise.all([readFile(headerFile, \"utf-8\"), readFile(bodyFile)]);\n\t} catch {\n\t\t// HEAD or empty responses may not produce output files.\n\t} finally {\n\t\tawait rm(dir, { recursive: true, force: true }).catch(() => {});\n\t}\n\n\tconst { status, statusText, headers: responseHeaders } = parseHeaderDump(dump);\n\tif (status === 0) {\n\t\tthrow new Error(`Proxy fetch to ${url.toString()} via ${redactProxyUrl(proxyUrl)} returned no HTTP status`);\n\t}\n\n\tlet finalUrl = url.toString();\n\tlet redirected = false;\n\ttry {\n\t\tconst trimmed = stdout.trim();\n\t\tif (trimmed.startsWith(\"{\")) {\n\t\t\tconst writeOut = JSON.parse(trimmed) as { url_effective?: string; num_redirects?: number };\n\t\t\tif (writeOut.url_effective) finalUrl = writeOut.url_effective;\n\t\t\tredirected = (writeOut.num_redirects ?? 0) > 0;\n\t\t}\n\t} catch {\n\t\t// Older curl without %{json}; the header dump already provided the status.\n\t}\n\n\tconst nullBody = status === 204 || status === 205 || status === 304;\n\tconst response = new Response(nullBody ? null : new Uint8Array(bodyBuffer), {\n\t\tstatus,\n\t\tstatusText: statusText || undefined,\n\t\theaders: new Headers(responseHeaders),\n\t});\n\tObject.defineProperty(response, \"url\", { value: finalUrl, configurable: true });\n\tObject.defineProperty(response, \"redirected\", { value: redirected, configurable: true });\n\treturn response;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xcrawl.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/xcrawl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA0DrE,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AA2HD,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CA8E1G"}
|