@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 @@
|
|
|
1
|
+
{"version":3,"file":"curator-server.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/curator-server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAmD,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,oBAAo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AU,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;oBAC5J,mBAAmB,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;oBAChE,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;gBAAA,CACnC;gBACD,YAAY,EAAE,GAAG,EAAE,CAAC;oBACnB,IAAI,SAAS;wBAAE,OAAO;oBACtB,gBAAgB,GAAG,IAAI,CAAC;oBACxB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;oBACpB,KAAK,GAAG,kBAAkB,CAAC;oBAC3B,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBAAA,CAC5B;gBACD,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAC;oBAC1B,gBAAgB;oBAChB,kBAAkB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,eAAe;iBAChD,CAAC;aACF,CAAC,CAAC;QAAA,CACH,CAAC,CAAC;IAAA,CACH,CAAC,CAAC;AAAA,CACH","sourcesContent":["import http, { type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { generateCuratorPage } from \"./curator-page.ts\";\nimport type { SummaryMeta } from \"./summary-review.ts\";\nimport { resolveCuratorNetworkConfig } from \"./utils.ts\";\n\nconst STALE_THRESHOLD_MS = 30000;\nconst WATCHDOG_INTERVAL_MS = 1000;\nconst MAX_BODY_SIZE = 64 * 1024;\n\ntype ServerState = \"SEARCHING\" | \"RESULT_SELECTION\" | \"COMPLETED\";\ntype CuratorResultEventData = IndexedCuratorSearchEntry & { slotIndex?: number };\ntype CuratorSearchErrorEventData = { queryIndex: number; query: string; error: string; provider?: string; slotIndex?: number };\ntype CuratorStoredEvent =\n\t| { event: \"result\"; data: CuratorResultEventData }\n\t| { event: \"search-error\"; data: CuratorSearchErrorEventData };\n\nexport interface CuratorServerOptions {\n\tqueries: string[];\n\tsessionToken: string;\n\ttimeout: number;\n\tavailableProviders: { all: boolean; openai: boolean; brave: boolean; parallel: boolean; tinyfish: boolean; search1api: boolean; searchinfinity: boolean; querit: boolean; tavily: boolean; jina: boolean; serpdive: boolean; kagi: boolean; bocha: boolean; ollama: boolean; searxng: boolean; duckduckgo: boolean; perplexity: boolean; exa: boolean; gemini: boolean; anysearch: boolean; xai: boolean; brightdata: boolean; serpbase: boolean };\n\tdefaultProvider: string;\n\tsearchProvider: string;\n\tsummaryModels: Array<{ value: string; label: string }>;\n\tdefaultSummaryModel: string | null;\n}\n\nexport interface CuratorSearchEntry {\n\tanswer: string;\n\tresults: Array<{ title: string; url: string; domain: string; snippet?: string }>;\n\tprovider: string;\n\terror?: string;\n}\n\nexport interface IndexedCuratorSearchEntry extends CuratorSearchEntry {\n\tqueryIndex: number;\n\tquery: string;\n}\n\nexport interface CuratorServerCallbacks {\n\tonSubmit: (payload: { selectedQueryIndices: number[]; summary?: string; summaryMeta?: SummaryMeta; rawResults?: boolean }) => void;\n\tonCancel: (reason: \"user\" | \"timeout\" | \"stale\") => void;\n\tonProviderChange: (provider: string) => void;\n\tonAddSearch: (query: string, provider?: string) => Promise<CuratorSearchEntry[]>;\n\tonAddSearchResults: (entries: IndexedCuratorSearchEntry[]) => void;\n\tonSummarize: (\n\t\tselectedQueryIndices: number[],\n\t\tsignal: AbortSignal,\n\t\tmodel?: string,\n\t\tfeedback?: string,\n\t) => Promise<{ summary: string; meta: SummaryMeta }>;\n\tonRewriteQuery: (query: string, signal: AbortSignal) => Promise<string>;\n}\n\nexport interface CuratorServerHandle {\n\tserver: http.Server;\n\turl: string;\n\tclose: () => void;\n\tpushResult: (queryIndex: number, data: CuratorSearchEntry & { query?: string; slotIndex?: number }) => void;\n\tpushError: (queryIndex: number, error: string, provider?: string, meta?: { query?: string; slotIndex?: number }) => void;\n\tsearchesDone: () => void;\n\t/** Reports browser connection state so a cancelled search can surface WHY it\n\t * went stale (e.g. the browser never connected). */\n\tgetConnectionState: () => { browserConnected: boolean; lastHeartbeatAgeMs: number };\n}\n\nfunction sendJson(res: ServerResponse, status: number, payload: unknown): void {\n\tres.writeHead(status, {\n\t\t\"Content-Type\": \"application/json\",\n\t\t\"Cache-Control\": \"no-store\",\n\t});\n\tres.end(JSON.stringify(payload));\n}\n\nfunction parseJSONBody(req: IncomingMessage): Promise<unknown> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet body = \"\";\n\t\tlet size = 0;\n\t\treq.on(\"data\", (chunk: Buffer) => {\n\t\t\tsize += chunk.length;\n\t\t\tif (size > MAX_BODY_SIZE) {\n\t\t\t\treq.destroy();\n\t\t\t\treject(new Error(\"Request body too large\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbody += chunk.toString();\n\t\t});\n\t\treq.on(\"end\", () => {\n\t\t\ttry {\n\t\t\t\tresolve(JSON.parse(body));\n\t\t\t} catch (err) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\treject(new Error(`Invalid JSON: ${message}`));\n\t\t\t}\n\t\t});\n\t\treq.on(\"error\", reject);\n\t});\n}\n\nasync function parseBodyOrSend(req: IncomingMessage, res: ServerResponse): Promise<unknown | null> {\n\ttry {\n\t\treturn await parseJSONBody(req);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : \"Invalid body\";\n\t\tconst status = message === \"Request body too large\" ? 413 : 400;\n\t\tsendJson(res, status, { ok: false, error: message });\n\t\treturn null;\n\t}\n}\n\nfunction normalizeSelectedIndices(\n\tvalue: unknown,\n\toptions: { allowEmpty: boolean; maxExclusive: number },\n): { ok: true; indices: number[] } | { ok: false; error: string } {\n\tif (!Array.isArray(value)) {\n\t\treturn { ok: false, error: \"Invalid selection\" };\n\t}\n\n\tif (!options.allowEmpty && value.length === 0) {\n\t\treturn { ok: false, error: \"Invalid selection\" };\n\t}\n\n\tconst normalized: number[] = [];\n\tconst seen = new Set<number>();\n\tfor (const item of value) {\n\t\tif (typeof item !== \"number\" || !Number.isInteger(item) || item < 0) {\n\t\t\treturn { ok: false, error: \"Invalid selection\" };\n\t\t}\n\t\tif (item >= options.maxExclusive) {\n\t\t\treturn { ok: false, error: \"Invalid selection\" };\n\t\t}\n\t\tif (seen.has(item)) {\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(item);\n\t\tnormalized.push(item);\n\t}\n\n\tif (!options.allowEmpty && normalized.length === 0) {\n\t\treturn { ok: false, error: \"Invalid selection\" };\n\t}\n\n\treturn { ok: true, indices: normalized };\n}\n\nfunction normalizeSummaryMeta(value: unknown): SummaryMeta | null {\n\tif (!value || typeof value !== \"object\") return null;\n\tconst meta = value as Record<string, unknown>;\n\n\tconst model = meta.model === null\n\t\t? null\n\t\t: typeof meta.model === \"string\"\n\t\t\t? meta.model\n\t\t\t: undefined;\n\tif (model === undefined) return null;\n\n\tconst durationMs = meta.durationMs;\n\tif (typeof durationMs !== \"number\" || !Number.isFinite(durationMs) || durationMs < 0) return null;\n\n\tconst tokenEstimate = meta.tokenEstimate;\n\tif (typeof tokenEstimate !== \"number\" || !Number.isFinite(tokenEstimate) || tokenEstimate < 0) return null;\n\n\tconst fallbackUsed = meta.fallbackUsed;\n\tif (typeof fallbackUsed !== \"boolean\") return null;\n\n\tconst fallbackReason = typeof meta.fallbackReason === \"string\" ? meta.fallbackReason : undefined;\n\tif (meta.fallbackReason !== undefined && fallbackReason === undefined) return null;\n\n\tconst phase = meta.phase === \"summary-model\" || meta.phase === \"deterministic-fallback\"\n\t\t? meta.phase\n\t\t: undefined;\n\tif (meta.phase !== undefined && phase === undefined) return null;\n\tif (phase === \"deterministic-fallback\" && fallbackUsed !== true) return null;\n\tif (phase === \"summary-model\" && fallbackUsed !== false) return null;\n\n\tconst edited = typeof meta.edited === \"boolean\" ? meta.edited : undefined;\n\tif (meta.edited !== undefined && edited === undefined) return null;\n\n\treturn {\n\t\tmodel,\n\t\tdurationMs,\n\t\ttokenEstimate,\n\t\tfallbackUsed,\n\t\t...(fallbackReason !== undefined ? { fallbackReason } : {}),\n\t\t...(phase !== undefined ? { phase } : {}),\n\t\t...(edited !== undefined ? { edited } : {}),\n\t};\n}\n\nexport function startCuratorServer(\n\toptions: CuratorServerOptions,\n\tcallbacks: CuratorServerCallbacks,\n): Promise<CuratorServerHandle> {\n\tconst {\n\t\tqueries,\n\t\tsessionToken,\n\t\ttimeout,\n\t\tavailableProviders,\n\t\tdefaultProvider,\n\t\tsearchProvider,\n\t\tsummaryModels,\n\t\tdefaultSummaryModel,\n\t} = options;\n\tlet browserConnected = false;\n\tlet lastHeartbeatAt = Date.now();\n\tlet stateChangedAt = Date.now();\n\tlet clientIdleMs: number | null = null;\n\tlet clientTimeoutSeconds = timeout;\n\tlet completed = false;\n\tlet watchdog: NodeJS.Timeout | null = null;\n\tlet state: ServerState = \"SEARCHING\";\n\tlet sseResponse: ServerResponse | null = null;\n\tconst streamedEventsByResultIndex = new Map<number, CuratorStoredEvent>();\n\tlet searchStreamDone = queries.length === 0;\n\tlet nextQueryIndex = queries.length;\n\tlet summarizeAbortController: AbortController | null = null;\n\tlet summarizeRequestSeq = 0;\n\n\tlet sseKeepalive: NodeJS.Timeout | null = null;\n\n\tconst abortInFlightSummarize = (): void => {\n\t\tif (!summarizeAbortController) return;\n\t\tsummarizeAbortController.abort();\n\t\tsummarizeAbortController = null;\n\t};\n\n\tconst markCompleted = (): boolean => {\n\t\tif (completed) return false;\n\t\tcompleted = true;\n\t\tstate = \"COMPLETED\";\n\t\tstateChangedAt = Date.now();\n\t\tif (watchdog) {\n\t\t\tclearInterval(watchdog);\n\t\t\twatchdog = null;\n\t\t}\n\t\tif (sseKeepalive) {\n\t\t\tclearInterval(sseKeepalive);\n\t\t\tsseKeepalive = null;\n\t\t}\n\t\tabortInFlightSummarize();\n\t\tif (sseResponse) {\n\t\t\ttry { sseResponse.end(); } catch {}\n\t\t\tsseResponse = null;\n\t\t}\n\t\treturn true;\n\t};\n\n\tconst touchHeartbeat = (): void => {\n\t\tlastHeartbeatAt = Date.now();\n\t\tbrowserConnected = true;\n\t};\n\n\tconst getEffectiveTimeoutMs = (): number => Math.max(1000, Math.floor(clientTimeoutSeconds) * 1000);\n\n\tconst shouldTimeoutFromClientIdle = (): boolean => (\n\t\tstate === \"RESULT_SELECTION\" &&\n\t\tclientIdleMs !== null &&\n\t\tclientIdleMs >= getEffectiveTimeoutMs()\n\t);\n\n\tfunction validateToken(body: unknown, res: ServerResponse): boolean {\n\t\tif (!body || typeof body !== \"object\") {\n\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid body\" });\n\t\t\treturn false;\n\t\t}\n\t\tif ((body as { token?: string }).token !== sessionToken) {\n\t\t\tsendJson(res, 403, { ok: false, error: \"Invalid session\" });\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tfunction isAvailableProvider(provider: string): boolean {\n\t\tif (provider === \"all\") return availableProviders.all;\n\t\tif (provider === \"openai\") return availableProviders.openai;\n\t\tif (provider === \"brave\") return availableProviders.brave;\n\t\tif (provider === \"parallel\") return availableProviders.parallel;\n\t\tif (provider === \"tinyfish\") return availableProviders.tinyfish;\n\t\tif (provider === \"search1api\") return availableProviders.search1api;\n\t\tif (provider === \"searchinfinity\") return availableProviders.searchinfinity;\n\t\tif (provider === \"querit\") return availableProviders.querit;\n\t\tif (provider === \"tavily\") return availableProviders.tavily;\n\t\tif (provider === \"jina\") return availableProviders.jina;\n\t\tif (provider === \"serpdive\") return availableProviders.serpdive;\n\t\tif (provider === \"kagi\") return availableProviders.kagi;\n\t\tif (provider === \"bocha\") return availableProviders.bocha;\n\t\tif (provider === \"ollama\") return availableProviders.ollama;\n\t\tif (provider === \"searxng\") return availableProviders.searxng;\n\t\tif (provider === \"duckduckgo\") return availableProviders.duckduckgo;\n\t\tif (provider === \"perplexity\") return availableProviders.perplexity;\n\t\tif (provider === \"exa\") return availableProviders.exa;\n\t\tif (provider === \"gemini\") return availableProviders.gemini;\n\t\tif (provider === \"anysearch\") return availableProviders.anysearch;\n\t\tif (provider === \"xai\") return availableProviders.xai;\n\t\tif (provider === \"brightdata\") return availableProviders.brightdata;\n\t\tif (provider === \"serpbase\") return availableProviders.serpbase;\n\t\treturn false;\n\t}\n\n\tfunction writeSSE(res: ServerResponse, event: string, data: unknown): boolean {\n\t\tconst payload = `event: ${event}\\ndata: ${JSON.stringify(data)}\\n\\n`;\n\t\ttry {\n\t\t\tres.write(payload);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tfunction sendSSE(event: string, data: unknown): void {\n\t\tconst res = sseResponse;\n\t\tif (res && !res.writableEnded && res.socket && !res.socket.destroyed && writeSSE(res, event, data)) return;\n\t\tif (sseResponse === res) sseResponse = null;\n\t}\n\n\tfunction retainStreamedEvent(event: CuratorStoredEvent): void {\n\t\tstreamedEventsByResultIndex.set(event.data.queryIndex, event);\n\t}\n\n\tfunction getStreamedEvents(): CuratorStoredEvent[] {\n\t\treturn [...streamedEventsByResultIndex.values()];\n\t}\n\n\tfunction replaySSE(res: ServerResponse): void {\n\t\tfor (const item of getStreamedEvents()) {\n\t\t\tif (!writeSSE(res, item.event, item.data)) return;\n\t\t}\n\t\tif (searchStreamDone) writeSSE(res, \"done\", {});\n\t}\n\n\tconst pageHtml = generateCuratorPage(\n\t\tqueries,\n\t\tsessionToken,\n\t\ttimeout,\n\t\tavailableProviders,\n\t\tdefaultProvider,\n\t\tsearchProvider,\n\t\tsummaryModels,\n\t\tdefaultSummaryModel,\n\t);\n\n\tconst server = http.createServer(async (req, res) => {\n\t\ttry {\n\t\t\tconst method = req.method || \"GET\";\n\t\t\tconst url = new URL(req.url || \"/\", `http://${req.headers.host || \"127.0.0.1\"}`);\n\n\t\t\tif (method === \"GET\" && url.pathname === \"/\") {\n\t\t\t\tconst token = url.searchParams.get(\"session\");\n\t\t\t\tif (token !== sessionToken) {\n\t\t\t\t\tres.writeHead(403, { \"Content-Type\": \"text/plain\" });\n\t\t\t\t\tres.end(\"Invalid session\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttouchHeartbeat();\n\t\t\t\tres.writeHead(200, {\n\t\t\t\t\t\"Content-Type\": \"text/html; charset=utf-8\",\n\t\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t\t});\n\t\t\t\tres.end(pageHtml);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"GET\" && url.pathname === \"/events\") {\n\t\t\t\tconst token = url.searchParams.get(\"session\");\n\t\t\t\tif (token !== sessionToken) {\n\t\t\t\t\tres.writeHead(403, { \"Content-Type\": \"text/plain\" });\n\t\t\t\t\tres.end(\"Invalid session\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (state === \"COMPLETED\") {\n\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"No events available\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (sseResponse) {\n\t\t\t\t\ttry { sseResponse.end(); } catch {}\n\t\t\t\t}\n\t\t\t\tres.writeHead(200, {\n\t\t\t\t\t\"Content-Type\": \"text/event-stream\",\n\t\t\t\t\t\"Cache-Control\": \"no-cache\",\n\t\t\t\t\tConnection: \"keep-alive\",\n\t\t\t\t\t\"X-Accel-Buffering\": \"no\",\n\t\t\t\t});\n\t\t\t\tres.flushHeaders();\n\t\t\t\tif (res.socket) res.socket.setNoDelay(true);\n\t\t\t\tsseResponse = res;\n\t\t\t\treplaySSE(res);\n\t\t\t\tif (sseKeepalive) clearInterval(sseKeepalive);\n\t\t\t\tsseKeepalive = setInterval(() => {\n\t\t\t\t\tif (sseResponse) {\n\t\t\t\t\t\ttry { sseResponse.write(\":keepalive\\n\\n\"); } catch {}\n\t\t\t\t\t}\n\t\t\t\t}, 15000);\n\t\t\t\treq.on(\"close\", () => {\n\t\t\t\t\tif (sseResponse === res) sseResponse = null;\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"GET\" && url.pathname === \"/state\") {\n\t\t\t\tconst token = url.searchParams.get(\"session\");\n\t\t\t\tif (token !== sessionToken) {\n\t\t\t\t\tsendJson(res, 403, { ok: false, error: \"Invalid session\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttouchHeartbeat();\n\t\t\t\tsendJson(res, 200, { ok: true, events: getStreamedEvents(), done: searchStreamDone });\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/heartbeat\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\t\t\t\ttouchHeartbeat();\n\t\t\t\tconst heartbeat = body as { idleMs?: unknown; timeoutSec?: unknown };\n\t\t\t\tif (typeof heartbeat.timeoutSec === \"number\" && Number.isFinite(heartbeat.timeoutSec) && heartbeat.timeoutSec > 0) {\n\t\t\t\t\tclientTimeoutSeconds = Math.min(600, Math.floor(heartbeat.timeoutSec));\n\t\t\t\t}\n\t\t\t\tif (typeof heartbeat.idleMs === \"number\" && Number.isFinite(heartbeat.idleMs) && heartbeat.idleMs >= 0) {\n\t\t\t\t\tclientIdleMs = Math.floor(heartbeat.idleMs);\n\t\t\t\t}\n\t\t\t\tconst timedOut = shouldTimeoutFromClientIdle();\n\t\t\t\tsendJson(res, 200, { ok: true });\n\t\t\t\tif (timedOut && markCompleted()) {\n\t\t\t\t\tsetImmediate(() => callbacks.onCancel(\"timeout\"));\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/provider\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\t\t\t\tconst { provider } = body as { provider?: string };\n\t\t\t\tif (typeof provider !== \"string\" || provider.length === 0) {\n\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid provider\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!isAvailableProvider(provider)) {\n\t\t\t\t\tsendJson(res, 400, { ok: false, error: `Provider unavailable: ${provider}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsetImmediate(() => callbacks.onProviderChange(provider));\n\t\t\t\tsendJson(res, 200, { ok: true });\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/search\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\t\t\t\tif (state === \"COMPLETED\") {\n\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"Session closed\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { query, provider } = body as { query?: string; provider?: string };\n\t\t\t\tif (typeof query !== \"string\" || query.trim().length === 0) {\n\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid query\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (provider !== undefined) {\n\t\t\t\t\tif (typeof provider !== \"string\" || provider.length === 0) {\n\t\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid provider\" });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!isAvailableProvider(provider)) {\n\t\t\t\t\t\tsendJson(res, 400, { ok: false, error: `Provider unavailable: ${provider}` });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst qi = nextQueryIndex++;\n\t\t\t\tconst trimmedQuery = query.trim();\n\t\t\t\ttouchHeartbeat();\n\t\t\t\ttry {\n\t\t\t\t\tconst results = await callbacks.onAddSearch(trimmedQuery, provider);\n\t\t\t\t\tif (results.length === 0) throw new Error(\"Search returned no provider results\");\n\t\t\t\t\tconst entries = results.map((result, index): IndexedCuratorSearchEntry => ({\n\t\t\t\t\t\t...result,\n\t\t\t\t\t\tqueryIndex: index === 0 ? qi : nextQueryIndex++,\n\t\t\t\t\t\tquery: trimmedQuery,\n\t\t\t\t\t}));\n\t\t\t\t\tcallbacks.onAddSearchResults(entries);\n\t\t\t\t\tsendJson(res, 200, { ok: true, ...entries[0], entries });\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : \"Search failed\";\n\t\t\t\t\tconst entry: IndexedCuratorSearchEntry = {\n\t\t\t\t\t\tqueryIndex: qi,\n\t\t\t\t\t\tquery: trimmedQuery,\n\t\t\t\t\t\tanswer: \"\",\n\t\t\t\t\t\tresults: [],\n\t\t\t\t\t\terror: message,\n\t\t\t\t\t\tprovider: typeof provider === \"string\" && provider.length > 0 ? provider : defaultProvider,\n\t\t\t\t\t};\n\t\t\t\t\tcallbacks.onAddSearchResults([entry]);\n\t\t\t\t\tsendJson(res, 200, { ok: true, ...entry, entries: [entry] });\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/summarize\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\t\t\t\tif (state === \"COMPLETED\") {\n\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"Session closed\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst parsed = normalizeSelectedIndices((body as { selected?: unknown }).selected, {\n\t\t\t\t\tallowEmpty: false,\n\t\t\t\t\tmaxExclusive: nextQueryIndex,\n\t\t\t\t});\n\t\t\t\tif (\"error\" in parsed) {\n\t\t\t\t\tsendJson(res, 400, { ok: false, error: parsed.error });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet model: string | undefined;\n\t\t\t\tconst bodyModel = (body as { model?: unknown }).model;\n\t\t\t\tif (bodyModel !== undefined) {\n\t\t\t\t\tif (typeof bodyModel !== \"string\") {\n\t\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid model\" });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst trimmedModel = bodyModel.trim();\n\t\t\t\t\tmodel = trimmedModel.length > 0 ? trimmedModel : undefined;\n\t\t\t\t}\n\n\t\t\t\tconst bodyFeedback = (body as { feedback?: unknown }).feedback;\n\t\t\t\tconst feedback = typeof bodyFeedback === \"string\" && bodyFeedback.trim().length > 0\n\t\t\t\t\t? bodyFeedback.trim()\n\t\t\t\t\t: undefined;\n\n\t\t\t\tabortInFlightSummarize();\n\t\t\t\tconst controller = new AbortController();\n\t\t\t\tsummarizeAbortController = controller;\n\t\t\t\tconst requestId = ++summarizeRequestSeq;\n\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await callbacks.onSummarize(parsed.indices, controller.signal, model, feedback);\n\t\t\t\t\tif (requestId !== summarizeRequestSeq || completed) {\n\t\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"Summarize request superseded\" });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tsendJson(res, 200, {\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\tsummary: result.summary,\n\t\t\t\t\t\tmeta: result.meta,\n\t\t\t\t\t});\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : \"Summary generation failed\";\n\t\t\t\t\tconst status = controller.signal.aborted ? 409 : 500;\n\t\t\t\t\tsendJson(res, status, { ok: false, error: message });\n\t\t\t\t} finally {\n\t\t\t\t\tif (summarizeAbortController === controller) {\n\t\t\t\t\t\tsummarizeAbortController = null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/rewrite\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\t\t\t\tif (state === \"COMPLETED\") {\n\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"Session closed\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { query } = body as { query?: unknown };\n\t\t\t\tif (typeof query !== \"string\" || query.trim().length === 0) {\n\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid query\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst controller = new AbortController();\n\t\t\t\treq.on(\"close\", () => controller.abort());\n\t\t\t\ttouchHeartbeat();\n\t\t\t\ttry {\n\t\t\t\t\tconst rewritten = await callbacks.onRewriteQuery(query.trim(), controller.signal);\n\t\t\t\t\tsendJson(res, 200, { ok: true, query: rewritten });\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : \"Rewrite failed\";\n\t\t\t\t\tconst status = controller.signal.aborted ? 409 : 500;\n\t\t\t\t\tsendJson(res, status, { ok: false, error: message });\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/submit\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\n\t\t\t\tconst parsed = normalizeSelectedIndices((body as { selected?: unknown }).selected, {\n\t\t\t\t\tallowEmpty: true,\n\t\t\t\t\tmaxExclusive: nextQueryIndex,\n\t\t\t\t});\n\t\t\t\tif (\"error\" in parsed) {\n\t\t\t\t\tsendJson(res, 400, { ok: false, error: parsed.error });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet summary: string | undefined;\n\t\t\t\tconst bodySummary = (body as { summary?: unknown }).summary;\n\t\t\t\tif (bodySummary !== undefined) {\n\t\t\t\t\tif (typeof bodySummary !== \"string\") {\n\t\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid summary\" });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst trimmedSummary = bodySummary.trim();\n\t\t\t\t\tsummary = trimmedSummary.length > 0 ? trimmedSummary : undefined;\n\t\t\t\t}\n\n\t\t\t\tlet summaryMeta: SummaryMeta | undefined;\n\t\t\t\tconst bodySummaryMeta = (body as { summaryMeta?: unknown }).summaryMeta;\n\t\t\t\tif (bodySummaryMeta !== undefined) {\n\t\t\t\t\tconst parsedSummaryMeta = normalizeSummaryMeta(bodySummaryMeta);\n\t\t\t\t\tif (!parsedSummaryMeta) {\n\t\t\t\t\t\tsendJson(res, 400, { ok: false, error: \"Invalid summaryMeta\" });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tsummaryMeta = parsedSummaryMeta;\n\t\t\t\t}\n\n\t\t\t\tif (state !== \"SEARCHING\" && state !== \"RESULT_SELECTION\") {\n\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"Cannot submit in current state\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!markCompleted()) {\n\t\t\t\t\tsendJson(res, 409, { ok: false, error: \"Session closed\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst rawResults = (body as { rawResults?: unknown }).rawResults === true;\n\t\t\t\tsendJson(res, 200, { ok: true });\n\t\t\t\tsetImmediate(() => callbacks.onSubmit({\n\t\t\t\t\tselectedQueryIndices: parsed.indices,\n\t\t\t\t\t...(summary !== undefined ? { summary } : {}),\n\t\t\t\t\t...(summaryMeta !== undefined ? { summaryMeta } : {}),\n\t\t\t\t\trawResults,\n\t\t\t\t}));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (method === \"POST\" && url.pathname === \"/cancel\") {\n\t\t\t\tconst body = await parseBodyOrSend(req, res);\n\t\t\t\tif (!body) return;\n\t\t\t\tif (!validateToken(body, res)) return;\n\t\t\t\tif (!markCompleted()) {\n\t\t\t\t\tsendJson(res, 200, { ok: true });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { reason } = body as { reason?: string };\n\t\t\t\tsendJson(res, 200, { ok: true });\n\t\t\t\tconst cancelReason = reason === \"timeout\" ? \"timeout\" : \"user\";\n\t\t\t\tsetImmediate(() => callbacks.onCancel(cancelReason));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.writeHead(404, { \"Content-Type\": \"text/plain\" });\n\t\t\tres.end(\"Not found\");\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : \"Server error\";\n\t\t\tsendJson(res, 500, { ok: false, error: message });\n\t\t}\n\t});\n\n\treturn new Promise((resolve, reject) => {\n\t\tconst onError = (err: Error) => {\n\t\t\treject(new Error(`Curator server failed to start: ${err.message}`));\n\t\t};\n\n\t\tconst networkConfig = resolveCuratorNetworkConfig();\n\n\t\tserver.once(\"error\", onError);\n\t\tserver.listen(0, networkConfig.bind, () => {\n\t\t\tserver.off(\"error\", onError);\n\t\t\tconst addr = server.address();\n\t\t\tif (!addr || typeof addr === \"string\") {\n\t\t\t\treject(new Error(\"Curator server: invalid address\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst url = `http://${networkConfig.host}:${addr.port}/?session=${sessionToken}`;\n\n\t\t\twatchdog = setInterval(() => {\n\t\t\t\tif (completed) return;\n\t\t\t\tif (!browserConnected) {\n\t\t\t\t\tconst noBrowserTimeoutMs = Math.max(5000, getEffectiveTimeoutMs());\n\t\t\t\t\tif (state !== \"RESULT_SELECTION\") return;\n\t\t\t\t\tif (Date.now() - stateChangedAt <= noBrowserTimeoutMs) return;\n\t\t\t\t\tif (!markCompleted()) return;\n\t\t\t\t\tsetImmediate(() => callbacks.onCancel(\"timeout\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (shouldTimeoutFromClientIdle()) {\n\t\t\t\t\tif (!markCompleted()) return;\n\t\t\t\t\tsetImmediate(() => callbacks.onCancel(\"timeout\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (Date.now() - lastHeartbeatAt <= STALE_THRESHOLD_MS) return;\n\t\t\t\tconst staleReason = state === \"RESULT_SELECTION\" ? \"timeout\" : \"stale\";\n\t\t\t\tif (!markCompleted()) return;\n\t\t\t\tsetImmediate(() => callbacks.onCancel(staleReason));\n\t\t\t}, WATCHDOG_INTERVAL_MS);\n\n\t\t\tresolve({\n\t\t\t\tserver,\n\t\t\t\turl,\n\t\t\t\tclose: () => {\n\t\t\t\t\tconst wasOpen = markCompleted();\n\t\t\t\t\ttry { server.close(); } catch {}\n\t\t\t\t\tif (wasOpen) {\n\t\t\t\t\t\tsetImmediate(() => callbacks.onCancel(\"stale\"));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tpushResult: (queryIndex, data) => {\n\t\t\t\t\tif (completed) return;\n\t\t\t\t\tnextQueryIndex = Math.max(nextQueryIndex, queryIndex + 1);\n\t\t\t\t\tconst eventData: CuratorResultEventData = { ...data, queryIndex, query: data.query ?? queries[queryIndex] ?? \"\" };\n\t\t\t\t\tretainStreamedEvent({ event: \"result\", data: eventData });\n\t\t\t\t\tsendSSE(\"result\", eventData);\n\t\t\t\t},\n\t\t\t\tpushError: (queryIndex, error, provider, meta) => {\n\t\t\t\t\tif (completed) return;\n\t\t\t\t\tnextQueryIndex = Math.max(nextQueryIndex, queryIndex + 1);\n\t\t\t\t\tconst eventData: CuratorSearchErrorEventData = { queryIndex, query: meta?.query ?? queries[queryIndex] ?? \"\", error, provider, slotIndex: meta?.slotIndex };\n\t\t\t\t\tretainStreamedEvent({ event: \"search-error\", data: eventData });\n\t\t\t\t\tsendSSE(\"search-error\", eventData);\n\t\t\t\t},\n\t\t\t\tsearchesDone: () => {\n\t\t\t\t\tif (completed) return;\n\t\t\t\t\tsearchStreamDone = true;\n\t\t\t\t\tsendSSE(\"done\", {});\n\t\t\t\t\tstate = \"RESULT_SELECTION\";\n\t\t\t\t\tstateChangedAt = Date.now();\n\t\t\t\t},\n\t\t\t\tgetConnectionState: () => ({\n\t\t\t\t\tbrowserConnected,\n\t\t\t\t\tlastHeartbeatAgeMs: Date.now() - lastHeartbeatAt,\n\t\t\t\t}),\n\t\t\t});\n\t\t});\n\t});\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type DatalabMode = "fast" | "balanced" | "accurate";
|
|
2
|
+
export type DatalabProcessingLocation = "eu" | "us";
|
|
3
|
+
export declare const DATALAB_MODE_VALUES: Set<DatalabMode>;
|
|
4
|
+
export declare const DATALAB_LOCATION_VALUES: Set<DatalabProcessingLocation>;
|
|
5
|
+
export declare const DEFAULT_DATALAB_MODE: DatalabMode;
|
|
6
|
+
export declare const DEFAULT_PROCESSING_LOCATION: DatalabProcessingLocation;
|
|
7
|
+
export declare const DEFAULT_DATALAB_TIMEOUT_MS = 120000;
|
|
8
|
+
export declare function isDatalabApiAvailable(): boolean;
|
|
9
|
+
export declare function getDatalabApiKey(signal?: AbortSignal): Promise<string | null>;
|
|
10
|
+
export declare function getDatalabApiBase(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the processing region. US storage and processing is the default;
|
|
13
|
+
* set `DATALAB_PROCESSING_LOCATION=eu` to use EU data residency at Datalab's
|
|
14
|
+
* documented 1.25× usage rate. Only `eu` and `us` are supported by the API.
|
|
15
|
+
* Config errors are thrown with a `Failed to parse` prefix so the
|
|
16
|
+
* extraction fallback chain treats them as fatal, mirroring how malformed
|
|
17
|
+
* web-search config is handled elsewhere.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getDatalabProcessingLocation(): DatalabProcessingLocation;
|
|
20
|
+
export declare function normalizeDatalabMode(value: unknown): DatalabMode;
|
|
21
|
+
export interface DatalabPDFExtractOptions {
|
|
22
|
+
maxPages: number;
|
|
23
|
+
title: string;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
mode?: DatalabMode;
|
|
27
|
+
processingLocation?: DatalabProcessingLocation;
|
|
28
|
+
}
|
|
29
|
+
export interface DatalabPDFExtractResult {
|
|
30
|
+
markdown: string;
|
|
31
|
+
pages: number;
|
|
32
|
+
parseQualityScore?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Convert a PDF buffer to Markdown through the Datalab hosted API.
|
|
36
|
+
*
|
|
37
|
+
* Datalab converts documents with a dedicated extraction engine (Marker),
|
|
38
|
+
* which preserves tables, multi-column reading order, headings, and math
|
|
39
|
+
* where the local `unpdf` fallback only produces flattened text. Conversion
|
|
40
|
+
* is deterministic (no LLM transcription drift), and `accurate` mode handles
|
|
41
|
+
* scanned pages. Completed responses may include a `parse_quality_score` (0–5)
|
|
42
|
+
* for quality gating. Billing is per processed page; the free tier includes a
|
|
43
|
+
* monthly credit (see README) so light use costs nothing.
|
|
44
|
+
*
|
|
45
|
+
* The flow is:
|
|
46
|
+
* 1. request a presigned upload URL for the selected processing region,
|
|
47
|
+
* 2. PUT the PDF bytes directly to storage,
|
|
48
|
+
* 3. confirm the upload to obtain a `datalab://` reference,
|
|
49
|
+
* 4. submit the conversion with that reference, then
|
|
50
|
+
* 5. poll the returned `request_check_url` until `complete` or `failed`.
|
|
51
|
+
*
|
|
52
|
+
* The processing region is fixed at the upload step (US by default; set
|
|
53
|
+
* `DATALAB_PROCESSING_LOCATION=eu` for EU data residency). The convert step
|
|
54
|
+
* deliberately omits `processing_location` because the API rejects multipart form data that
|
|
55
|
+
* carries it; the server processes the file from the storage region it was
|
|
56
|
+
* uploaded to. The uploaded file is deleted best-effort after conversion.
|
|
57
|
+
* The caller's signal and a shared deadline bound the whole exchange.
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractPDFViaDatalab(buffer: ArrayBuffer, options: DatalabPDFExtractOptions): Promise<DatalabPDFExtractResult>;
|
|
60
|
+
//# sourceMappingURL=datalab-pdf-extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datalab-pdf-extract.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/datalab-pdf-extract.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAC3D,MAAM,MAAM,yBAAyB,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpD,eAAO,MAAM,mBAAmB,kBAI9B,CAAC;AACH,eAAO,MAAM,uBAAuB,gCAGlC,CAAC;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAwB,CAAC;AAC5D,eAAO,MAAM,2BAA2B,EAAE,yBAAgC,CAAC;AAC3E,eAAO,MAAM,0BAA0B,SAAqB,CAAC;AAoC7D,wBAAgB,qBAAqB,IAAI,OAAO,CAM/C;AAED,wBAAsB,gBAAgB,CACrC,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOxB;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAM1C;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,IAAI,yBAAyB,CAWxE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAQhE;AAED,MAAM,WAAW,wBAAwB;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,kBAAkB,CAAC,EAAE,yBAAyB,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,oBAAoB,CACzC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,wBAAwB,GAC/B,OAAO,CAAC,uBAAuB,CAAC,CAsIlC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport {\n\thasCredentialSource,\n\tresolveCredential,\n\tredactCredential,\n} from \"./credential-source.ts\";\nimport { getWebSearchConfigPath } from \"./utils.ts\";\n\nconst DEFAULT_API_HOST = \"https://www.datalab.to\";\nconst API_PREFIX = \"/api/v1\";\nconst DEFAULT_TIMEOUT_MS = 120_000;\nconst DEFAULT_POLL_INTERVAL_MS = 1_500;\nconst MAX_RESPONSE_BYTES = 4 * 1024 * 1024;\nconst MAX_ERROR_BODY_BYTES = 300;\nconst CLEANUP_TIMEOUT_MS = 5_000;\nconst CONFIG_PATH = getWebSearchConfigPath();\n\nexport type DatalabMode = \"fast\" | \"balanced\" | \"accurate\";\nexport type DatalabProcessingLocation = \"eu\" | \"us\";\n\nexport const DATALAB_MODE_VALUES = new Set<DatalabMode>([\n\t\"fast\",\n\t\"balanced\",\n\t\"accurate\",\n]);\nexport const DATALAB_LOCATION_VALUES = new Set<DatalabProcessingLocation>([\n\t\"eu\",\n\t\"us\",\n]);\nexport const DEFAULT_DATALAB_MODE: DatalabMode = \"balanced\";\nexport const DEFAULT_PROCESSING_LOCATION: DatalabProcessingLocation = \"us\";\nexport const DEFAULT_DATALAB_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;\n\ninterface DatalabConfig {\n\tdatalabApiKey?: unknown;\n}\n\nlet cachedConfig: DatalabConfig | null = null;\n\nfunction loadConfig(): DatalabConfig {\n\tif (cachedConfig) return cachedConfig;\n\tif (!existsSync(CONFIG_PATH)) {\n\t\tcachedConfig = {};\n\t\treturn cachedConfig;\n\t}\n\n\tconst rawText = readFileSync(CONFIG_PATH, \"utf-8\");\n\ttry {\n\t\tcachedConfig = JSON.parse(rawText) as DatalabConfig;\n\t\treturn cachedConfig;\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);\n\t}\n}\n\nfunction normalizeString(value: unknown): string | null {\n\tif (typeof value !== \"string\") return null;\n\tconst normalized = value.trim();\n\treturn normalized.length > 0 ? normalized : null;\n}\n\nfunction normalizeFileId(value: unknown): string | null {\n\tif (typeof value === \"number\" && Number.isFinite(value)) return String(value);\n\treturn normalizeString(value);\n}\n\nexport function isDatalabApiAvailable(): boolean {\n\treturn hasCredentialSource({\n\t\tprovider: \"Datalab\",\n\t\tconfiguredValue: loadConfig().datalabApiKey,\n\t\tenvironmentValue: process.env.DATALAB_API_KEY,\n\t});\n}\n\nexport async function getDatalabApiKey(\n\tsignal?: AbortSignal,\n): Promise<string | null> {\n\treturn resolveCredential({\n\t\tprovider: \"Datalab\",\n\t\tconfiguredValue: loadConfig().datalabApiKey,\n\t\tenvironmentValue: process.env.DATALAB_API_KEY,\n\t\tsignal,\n\t});\n}\n\nexport function getDatalabApiBase(): string {\n\tconst normalized = normalizeString(process.env.DATALAB_API_BASE)?.replace(\n\t\t/\\/+$/,\n\t\t\"\",\n\t);\n\treturn normalized || `${DEFAULT_API_HOST}${API_PREFIX}`;\n}\n\n/**\n * Resolve the processing region. US storage and processing is the default;\n * set `DATALAB_PROCESSING_LOCATION=eu` to use EU data residency at Datalab's\n * documented 1.25× usage rate. Only `eu` and `us` are supported by the API.\n * Config errors are thrown with a `Failed to parse` prefix so the\n * extraction fallback chain treats them as fatal, mirroring how malformed\n * web-search config is handled elsewhere.\n */\nexport function getDatalabProcessingLocation(): DatalabProcessingLocation {\n\tconst value =\n\t\tnormalizeString(process.env.DATALAB_PROCESSING_LOCATION) ??\n\t\tDEFAULT_PROCESSING_LOCATION;\n\tconst normalized = value.toLowerCase() as DatalabProcessingLocation;\n\tif (!DATALAB_LOCATION_VALUES.has(normalized)) {\n\t\tthrow new Error(\n\t\t\t`Failed to parse DATALAB_PROCESSING_LOCATION: expected \"eu\" or \"us\", got \"${value}\"`,\n\t\t);\n\t}\n\treturn normalized;\n}\n\nexport function normalizeDatalabMode(value: unknown): DatalabMode {\n\tconst raw = normalizeString(value);\n\tif (!raw) return DEFAULT_DATALAB_MODE;\n\tconst normalized = raw.toLowerCase() as DatalabMode;\n\tif (DATALAB_MODE_VALUES.has(normalized)) return normalized;\n\tthrow new Error(\n\t\t`Failed to parse datalab mode: expected \"fast\", \"balanced\", or \"accurate\", got \"${value}\"`,\n\t);\n}\n\nexport interface DatalabPDFExtractOptions {\n\tmaxPages: number;\n\ttitle: string;\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tmode?: DatalabMode;\n\tprocessingLocation?: DatalabProcessingLocation;\n}\n\nexport interface DatalabPDFExtractResult {\n\tmarkdown: string;\n\tpages: number;\n\tparseQualityScore?: number;\n}\n\ninterface DatalabUploadRequest {\n\tfile_id?: unknown;\n\tupload_url?: unknown;\n\treference?: unknown;\n}\n\ninterface DatalabConfirmResponse {\n\tfile_id?: unknown;\n\treference?: unknown;\n}\n\ninterface DatalabConversionState {\n\tstatus?: unknown;\n\tsuccess?: unknown;\n\trequest_check_url?: unknown;\n\tmarkdown?: unknown;\n\tpage_count?: unknown;\n\tparse_quality_score?: unknown;\n\terror?: unknown;\n}\n\n/**\n * Convert a PDF buffer to Markdown through the Datalab hosted API.\n *\n * Datalab converts documents with a dedicated extraction engine (Marker),\n * which preserves tables, multi-column reading order, headings, and math\n * where the local `unpdf` fallback only produces flattened text. Conversion\n * is deterministic (no LLM transcription drift), and `accurate` mode handles\n * scanned pages. Completed responses may include a `parse_quality_score` (0–5)\n * for quality gating. Billing is per processed page; the free tier includes a\n * monthly credit (see README) so light use costs nothing.\n *\n * The flow is:\n * 1. request a presigned upload URL for the selected processing region,\n * 2. PUT the PDF bytes directly to storage,\n * 3. confirm the upload to obtain a `datalab://` reference,\n * 4. submit the conversion with that reference, then\n * 5. poll the returned `request_check_url` until `complete` or `failed`.\n *\n * The processing region is fixed at the upload step (US by default; set\n * `DATALAB_PROCESSING_LOCATION=eu` for EU data residency). The convert step\n * deliberately omits `processing_location` because the API rejects multipart form data that\n * carries it; the server processes the file from the storage region it was\n * uploaded to. The uploaded file is deleted best-effort after conversion.\n * The caller's signal and a shared deadline bound the whole exchange.\n */\nexport async function extractPDFViaDatalab(\n\tbuffer: ArrayBuffer,\n\toptions: DatalabPDFExtractOptions,\n): Promise<DatalabPDFExtractResult> {\n\toptions.signal?.throwIfAborted();\n\tconst apiKey = await getDatalabApiKey(options.signal);\n\toptions.signal?.throwIfAborted();\n\tif (!apiKey) {\n\t\tthrow new Error(\n\t\t\t\"Datalab PDF conversion requires a configured Datalab API key\",\n\t\t);\n\t}\n\n\tconst mode = options.mode ?? normalizeDatalabMode(process.env.DATALAB_MODE);\n\tconst processingLocation =\n\t\toptions.processingLocation ?? getDatalabProcessingLocation();\n\tconst timeoutMs =\n\t\ttypeof options.timeoutMs === \"number\" &&\n\t\tNumber.isFinite(options.timeoutMs) &&\n\t\toptions.timeoutMs > 0\n\t\t\t? Math.floor(options.timeoutMs)\n\t\t\t: DEFAULT_TIMEOUT_MS;\n\tconst deadline = Date.now() + timeoutMs;\n\n\tconst upload = await requestUploadUrl({\n\t\tapiKey,\n\t\ttitle: options.title,\n\t\tprocessingLocation,\n\t\tsignal: options.signal,\n\t\tdeadline,\n\t});\n\tif (typeof upload.upload_url !== \"string\" || !upload.upload_url) {\n\t\tthrow new Error(\"Datalab PDF conversion failed: missing upload_url\");\n\t}\n\tconst uploadFileId = normalizeFileId(upload.file_id);\n\tif (!uploadFileId) {\n\t\tthrow new Error(\"Datalab PDF conversion failed: missing file_id\");\n\t}\n\n\tlet fileId = uploadFileId;\n\tlet reference = normalizeString(upload.reference);\n\n\ttry {\n\t\tconst put = await fetchDatalab(\n\t\t\tupload.upload_url,\n\t\t\t{\n\t\t\t\tmethod: \"PUT\",\n\t\t\t\theaders: { \"content-type\": \"application/pdf\" },\n\t\t\t\tbody: new Blob([buffer], { type: \"application/pdf\" }),\n\t\t\t\tsignal: withTimeout(options.signal, remaining(deadline)),\n\t\t\t},\n\t\t\tapiKey,\n\t\t);\n\t\tif (!put.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`Datalab PDF upload failed: HTTP ${put.status} ${put.statusText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst confirmed = await confirmUpload(\n\t\t\tapiKey,\n\t\t\tString(fileId),\n\t\t\toptions.signal,\n\t\t\tdeadline,\n\t\t);\n\t\tfileId = normalizeFileId(confirmed.file_id) ?? fileId;\n\t\treference = normalizeString(confirmed.reference) ?? reference;\n\t\tif (!reference) {\n\t\t\tthrow new Error(\"Datalab PDF conversion failed: missing file reference\");\n\t\t}\n\n\t\tconst form = new FormData();\n\t\tform.append(\"file_url\", reference);\n\t\tform.append(\"output_format\", \"markdown\");\n\t\tform.append(\"mode\", mode);\n\t\tform.append(\"max_pages\", String(options.maxPages));\n\t\tform.append(\"paginate\", \"true\");\n\n\t\t// The conversion itself must NOT repeat processing_location: the API\n\t\t// rejects multipart form data carrying processing_location (HTTP 403).\n\t\t// The region was already fixed when the presigned upload was issued for\n\t\t// storage in the selected region, so the server processes the file\n\t\t// wherever it was stored (US by default; use the env override for EU).\n\n\t\tconst submit = await fetchDatalab(\n\t\t\t`${getDatalabApiBase()}/convert`,\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: { \"x-api-key\": apiKey },\n\t\t\t\tbody: form,\n\t\t\t\tsignal: withTimeout(options.signal, remaining(deadline)),\n\t\t\t},\n\t\t\tapiKey,\n\t\t);\n\t\tconst state = await readJsonResponse(submit, apiKey);\n\n\t\t// The submit response is an acceptance ack ({ success: true,\n\t\t// request_check_url }) with no status field and no markdown; only the\n\t\t// polled result carries a status. Key on status, never on success.\n\t\tif (state.status === \"complete\") return toResult(state);\n\t\tif (state.status === \"failed\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Datalab PDF conversion failed: ${state.error ?? \"unknown error\"}`,\n\t\t\t);\n\t\t}\n\n\t\tconst checkUrl = normalizeCheckUrl(state.request_check_url);\n\t\twhile (Date.now() < deadline) {\n\t\t\tawait sleep(\n\t\t\t\tMath.min(DEFAULT_POLL_INTERVAL_MS, remaining(deadline)),\n\t\t\t\toptions.signal,\n\t\t\t);\n\t\t\tif (Date.now() >= deadline) break;\n\t\t\tconst poll = await fetchDatalab(\n\t\t\t\tcheckUrl,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: { \"x-api-key\": apiKey },\n\t\t\t\t\tsignal: withTimeout(options.signal, remaining(deadline)),\n\t\t\t\t},\n\t\t\t\tapiKey,\n\t\t\t);\n\t\t\tconst next = await readJsonResponse(poll, apiKey);\n\t\t\tif (next.status === \"complete\") return toResult(next);\n\t\t\tif (next.status === \"failed\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Datalab PDF conversion failed: ${next.error ?? \"unknown error\"}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\"Datalab PDF conversion timed out\");\n\t} finally {\n\t\t// File deletion is best-effort. Do not extend a caller's timeout or\n\t\t// cancellation while waiting for a remote cleanup request.\n\t\tvoid deleteDatalabFile(apiKey, fileId);\n\t}\n}\n\nasync function requestUploadUrl(options: {\n\tapiKey: string;\n\ttitle: string;\n\tprocessingLocation: DatalabProcessingLocation;\n\tsignal: AbortSignal | undefined;\n\tdeadline: number;\n}): Promise<DatalabUploadRequest> {\n\tconst { apiKey, title, processingLocation, signal, deadline } = options;\n\tconst response = await fetchDatalab(\n\t\t`${getDatalabApiBase()}/files/upload`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"x-api-key\": apiKey,\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tfilename: `${datalabFilename(title)}.pdf`,\n\t\t\t\tcontent_type: \"application/pdf\",\n\t\t\t\tprocessing_location: processingLocation,\n\t\t\t}),\n\t\t\tsignal: withTimeout(signal, remaining(deadline)),\n\t\t},\n\t\tapiKey,\n\t);\n\treturn readJsonResponse(response, apiKey);\n}\n\nasync function confirmUpload(\n\tapiKey: string,\n\tfileId: string,\n\tsignal: AbortSignal | undefined,\n\tdeadline: number,\n): Promise<DatalabConfirmResponse> {\n\tconst response = await fetchDatalab(\n\t\t`${getDatalabApiBase()}/files/${encodeURIComponent(fileId)}/confirm`,\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\theaders: { \"x-api-key\": apiKey },\n\t\t\tsignal: withTimeout(signal, remaining(deadline)),\n\t\t},\n\t\tapiKey,\n\t);\n\treturn readJsonResponse(response, apiKey);\n}\n\nasync function deleteDatalabFile(\n\tapiKey: string,\n\tfileId: string,\n): Promise<void> {\n\ttry {\n\t\tawait fetchDatalab(\n\t\t\t`${getDatalabApiBase()}/files/${encodeURIComponent(fileId)}`,\n\t\t\t{\n\t\t\t\tmethod: \"DELETE\",\n\t\t\t\theaders: { \"x-api-key\": apiKey },\n\t\t\t\tsignal: AbortSignal.timeout(CLEANUP_TIMEOUT_MS),\n\t\t\t},\n\t\t\tapiKey,\n\t\t);\n\t} catch {\n\t\t// Best-effort cleanup; a leftover file is not worth failing the conversion.\n\t}\n}\n\nfunction toResult(state: DatalabConversionState): DatalabPDFExtractResult {\n\tconst markdown = normalizeString(state.markdown);\n\tif (!markdown) {\n\t\tthrow new Error(\"Datalab PDF conversion returned empty markdown\");\n\t}\n\tconst quality = state.parse_quality_score;\n\treturn {\n\t\tmarkdown,\n\t\tpages: numericField(state.page_count) ?? countPageMarkers(markdown),\n\t\t...(typeof quality === \"number\" && Number.isFinite(quality)\n\t\t\t? { parseQualityScore: quality }\n\t\t\t: {}),\n\t};\n}\n\nfunction numericField(value: unknown): number | null {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value > 0\n\t\t? Math.floor(value)\n\t\t: null;\n}\n\nfunction countPageMarkers(markdown: string): number {\n\treturn [...markdown.matchAll(/^<!-- Page (\\d+) -->$/gm)].length;\n}\n\nfunction normalizeCheckUrl(value: unknown): string {\n\tif (typeof value !== \"string\" || !value.trim()) {\n\t\tthrow new Error(\"Datalab PDF conversion failed: missing request_check_url\");\n\t}\n\tconst apiBase = getDatalabApiUrl();\n\tlet checkUrl: URL;\n\ttry {\n\t\tcheckUrl = new URL(value.trim(), apiBase);\n\t} catch {\n\t\tthrow new Error(\"Datalab PDF conversion failed: invalid request_check_url\");\n\t}\n\tif (checkUrl.origin !== apiBase.origin) {\n\t\tthrow new Error(\n\t\t\t\"Datalab PDF conversion failed: request_check_url has an unexpected origin\",\n\t\t);\n\t}\n\treturn checkUrl.toString();\n}\n\nfunction getDatalabApiUrl(): URL {\n\ttry {\n\t\treturn new URL(getDatalabApiBase());\n\t} catch {\n\t\tthrow new Error(\n\t\t\t\"Failed to parse DATALAB_API_BASE: expected an absolute URL\",\n\t\t);\n\t}\n}\n\nfunction remaining(deadline: number): number {\n\treturn Math.max(1, deadline - Date.now());\n}\n\nfunction withTimeout(\n\tsignal: AbortSignal | undefined,\n\ttimeoutMs: number,\n): AbortSignal {\n\tconst timeout = AbortSignal.timeout(timeoutMs);\n\treturn signal ? AbortSignal.any([signal, timeout]) : timeout;\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet timer: ReturnType<typeof setTimeout>;\n\t\tconst cleanup = () => signal?.removeEventListener(\"abort\", onAbort);\n\t\tconst onTimeout = () => {\n\t\t\tcleanup();\n\t\t\tresolve();\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tcleanup();\n\t\t\treject(signal?.reason);\n\t\t};\n\n\t\tif (signal?.aborted) {\n\t\t\tonAbort();\n\t\t\treturn;\n\t\t}\n\t\ttimer = setTimeout(onTimeout, ms);\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\n\nasync function fetchDatalab(\n\turl: string,\n\tinit: RequestInit,\n\tapiKey: string,\n): Promise<Response> {\n\ttry {\n\t\treturn await fetch(url, { ...init, redirect: init.redirect ?? \"error\" });\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconst redacted = redactCredential(message, apiKey);\n\t\tif (redacted === message) throw error;\n\t\tconst redactedError = new Error(redacted);\n\t\tif (error instanceof Error) redactedError.name = error.name;\n\t\tthrow redactedError;\n\t}\n}\n\nasync function readJsonResponse(\n\tresponse: Response,\n\tapiKey: string,\n): Promise<Record<string, unknown>> {\n\tconst text = await readResponseText(response);\n\tif (!response.ok) {\n\t\tconst detail = text.trim().slice(0, MAX_ERROR_BODY_BYTES);\n\t\tconst message = detail\n\t\t\t? `Datalab PDF conversion failed: HTTP ${response.status} ${response.statusText}: ${detail}`\n\t\t\t: `Datalab PDF conversion failed: HTTP ${response.status} ${response.statusText}`;\n\t\tthrow new Error(redactCredential(message, apiKey));\n\t}\n\treturn parseJsonRecord(text);\n}\n\nfunction parseJsonRecord(text: string): Record<string, unknown> {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch (error) {\n\t\tthrow new Error(\"Datalab PDF conversion returned invalid JSON\", { cause: error });\n\t}\n\tif (Object.prototype.toString.call(parsed) !== \"[object Object]\") {\n\t\tthrow new Error(\"Datalab PDF conversion returned invalid JSON object\");\n\t}\n\treturn parsed as Record<string, unknown>;\n}\n\nasync function readResponseText(response: Response): Promise<string> {\n\tconst contentLength = Number(response.headers.get(\"content-length\"));\n\tif (Number.isFinite(contentLength) && contentLength > MAX_RESPONSE_BYTES) {\n\t\tthrow new Error(\"Datalab PDF conversion response too large\");\n\t}\n\tif (!response.body) return \"\";\n\n\tconst reader = response.body.getReader();\n\tconst decoder = new TextDecoder();\n\tconst chunks: string[] = [];\n\tlet bytesRead = 0;\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbytesRead += value.byteLength;\n\t\t\tif (bytesRead > MAX_RESPONSE_BYTES) {\n\t\t\t\ttry {\n\t\t\t\t\tawait reader.cancel();\n\t\t\t\t} catch {\n\t\t\t\t\t// The response is already too large; cancellation is best-effort.\n\t\t\t\t}\n\t\t\t\tthrow new Error(\"Datalab PDF conversion response too large\");\n\t\t\t}\n\t\t\tchunks.push(decoder.decode(value, { stream: true }));\n\t\t}\n\t\tchunks.push(decoder.decode());\n\t\treturn chunks.join(\"\");\n\t} finally {\n\t\treader.releaseLock();\n\t}\n}\n\nfunction datalabFilename(title: string): string {\n\treturn (\n\t\ttitle\n\t\t\t.toLowerCase()\n\t\t\t.replace(/[^a-z0-9\\s-]/g, \"\")\n\t\t\t.replace(/\\s+/g, \"-\")\n\t\t\t.replace(/-+/g, \"-\")\n\t\t\t.replace(/^-|-$/g, \"\")\n\t\t\t.slice(0, 60) || \"document\"\n\t);\n}\n"]}
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { hasCredentialSource, resolveCredential, redactCredential, } from "./credential-source.js";
|
|
3
|
+
import { getWebSearchConfigPath } from "./utils.js";
|
|
4
|
+
const DEFAULT_API_HOST = "https://www.datalab.to";
|
|
5
|
+
const API_PREFIX = "/api/v1";
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
7
|
+
const DEFAULT_POLL_INTERVAL_MS = 1_500;
|
|
8
|
+
const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
9
|
+
const MAX_ERROR_BODY_BYTES = 300;
|
|
10
|
+
const CLEANUP_TIMEOUT_MS = 5_000;
|
|
11
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
12
|
+
export const DATALAB_MODE_VALUES = new Set([
|
|
13
|
+
"fast",
|
|
14
|
+
"balanced",
|
|
15
|
+
"accurate",
|
|
16
|
+
]);
|
|
17
|
+
export const DATALAB_LOCATION_VALUES = new Set([
|
|
18
|
+
"eu",
|
|
19
|
+
"us",
|
|
20
|
+
]);
|
|
21
|
+
export const DEFAULT_DATALAB_MODE = "balanced";
|
|
22
|
+
export const DEFAULT_PROCESSING_LOCATION = "us";
|
|
23
|
+
export const DEFAULT_DATALAB_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
24
|
+
let cachedConfig = null;
|
|
25
|
+
function loadConfig() {
|
|
26
|
+
if (cachedConfig)
|
|
27
|
+
return cachedConfig;
|
|
28
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
29
|
+
cachedConfig = {};
|
|
30
|
+
return cachedConfig;
|
|
31
|
+
}
|
|
32
|
+
const rawText = readFileSync(CONFIG_PATH, "utf-8");
|
|
33
|
+
try {
|
|
34
|
+
cachedConfig = JSON.parse(rawText);
|
|
35
|
+
return cachedConfig;
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
39
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function normalizeString(value) {
|
|
43
|
+
if (typeof value !== "string")
|
|
44
|
+
return null;
|
|
45
|
+
const normalized = value.trim();
|
|
46
|
+
return normalized.length > 0 ? normalized : null;
|
|
47
|
+
}
|
|
48
|
+
function normalizeFileId(value) {
|
|
49
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
50
|
+
return String(value);
|
|
51
|
+
return normalizeString(value);
|
|
52
|
+
}
|
|
53
|
+
export function isDatalabApiAvailable() {
|
|
54
|
+
return hasCredentialSource({
|
|
55
|
+
provider: "Datalab",
|
|
56
|
+
configuredValue: loadConfig().datalabApiKey,
|
|
57
|
+
environmentValue: process.env.DATALAB_API_KEY,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export async function getDatalabApiKey(signal) {
|
|
61
|
+
return resolveCredential({
|
|
62
|
+
provider: "Datalab",
|
|
63
|
+
configuredValue: loadConfig().datalabApiKey,
|
|
64
|
+
environmentValue: process.env.DATALAB_API_KEY,
|
|
65
|
+
signal,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function getDatalabApiBase() {
|
|
69
|
+
const normalized = normalizeString(process.env.DATALAB_API_BASE)?.replace(/\/+$/, "");
|
|
70
|
+
return normalized || `${DEFAULT_API_HOST}${API_PREFIX}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolve the processing region. US storage and processing is the default;
|
|
74
|
+
* set `DATALAB_PROCESSING_LOCATION=eu` to use EU data residency at Datalab's
|
|
75
|
+
* documented 1.25× usage rate. Only `eu` and `us` are supported by the API.
|
|
76
|
+
* Config errors are thrown with a `Failed to parse` prefix so the
|
|
77
|
+
* extraction fallback chain treats them as fatal, mirroring how malformed
|
|
78
|
+
* web-search config is handled elsewhere.
|
|
79
|
+
*/
|
|
80
|
+
export function getDatalabProcessingLocation() {
|
|
81
|
+
const value = normalizeString(process.env.DATALAB_PROCESSING_LOCATION) ??
|
|
82
|
+
DEFAULT_PROCESSING_LOCATION;
|
|
83
|
+
const normalized = value.toLowerCase();
|
|
84
|
+
if (!DATALAB_LOCATION_VALUES.has(normalized)) {
|
|
85
|
+
throw new Error(`Failed to parse DATALAB_PROCESSING_LOCATION: expected "eu" or "us", got "${value}"`);
|
|
86
|
+
}
|
|
87
|
+
return normalized;
|
|
88
|
+
}
|
|
89
|
+
export function normalizeDatalabMode(value) {
|
|
90
|
+
const raw = normalizeString(value);
|
|
91
|
+
if (!raw)
|
|
92
|
+
return DEFAULT_DATALAB_MODE;
|
|
93
|
+
const normalized = raw.toLowerCase();
|
|
94
|
+
if (DATALAB_MODE_VALUES.has(normalized))
|
|
95
|
+
return normalized;
|
|
96
|
+
throw new Error(`Failed to parse datalab mode: expected "fast", "balanced", or "accurate", got "${value}"`);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Convert a PDF buffer to Markdown through the Datalab hosted API.
|
|
100
|
+
*
|
|
101
|
+
* Datalab converts documents with a dedicated extraction engine (Marker),
|
|
102
|
+
* which preserves tables, multi-column reading order, headings, and math
|
|
103
|
+
* where the local `unpdf` fallback only produces flattened text. Conversion
|
|
104
|
+
* is deterministic (no LLM transcription drift), and `accurate` mode handles
|
|
105
|
+
* scanned pages. Completed responses may include a `parse_quality_score` (0–5)
|
|
106
|
+
* for quality gating. Billing is per processed page; the free tier includes a
|
|
107
|
+
* monthly credit (see README) so light use costs nothing.
|
|
108
|
+
*
|
|
109
|
+
* The flow is:
|
|
110
|
+
* 1. request a presigned upload URL for the selected processing region,
|
|
111
|
+
* 2. PUT the PDF bytes directly to storage,
|
|
112
|
+
* 3. confirm the upload to obtain a `datalab://` reference,
|
|
113
|
+
* 4. submit the conversion with that reference, then
|
|
114
|
+
* 5. poll the returned `request_check_url` until `complete` or `failed`.
|
|
115
|
+
*
|
|
116
|
+
* The processing region is fixed at the upload step (US by default; set
|
|
117
|
+
* `DATALAB_PROCESSING_LOCATION=eu` for EU data residency). The convert step
|
|
118
|
+
* deliberately omits `processing_location` because the API rejects multipart form data that
|
|
119
|
+
* carries it; the server processes the file from the storage region it was
|
|
120
|
+
* uploaded to. The uploaded file is deleted best-effort after conversion.
|
|
121
|
+
* The caller's signal and a shared deadline bound the whole exchange.
|
|
122
|
+
*/
|
|
123
|
+
export async function extractPDFViaDatalab(buffer, options) {
|
|
124
|
+
options.signal?.throwIfAborted();
|
|
125
|
+
const apiKey = await getDatalabApiKey(options.signal);
|
|
126
|
+
options.signal?.throwIfAborted();
|
|
127
|
+
if (!apiKey) {
|
|
128
|
+
throw new Error("Datalab PDF conversion requires a configured Datalab API key");
|
|
129
|
+
}
|
|
130
|
+
const mode = options.mode ?? normalizeDatalabMode(process.env.DATALAB_MODE);
|
|
131
|
+
const processingLocation = options.processingLocation ?? getDatalabProcessingLocation();
|
|
132
|
+
const timeoutMs = typeof options.timeoutMs === "number" &&
|
|
133
|
+
Number.isFinite(options.timeoutMs) &&
|
|
134
|
+
options.timeoutMs > 0
|
|
135
|
+
? Math.floor(options.timeoutMs)
|
|
136
|
+
: DEFAULT_TIMEOUT_MS;
|
|
137
|
+
const deadline = Date.now() + timeoutMs;
|
|
138
|
+
const upload = await requestUploadUrl({
|
|
139
|
+
apiKey,
|
|
140
|
+
title: options.title,
|
|
141
|
+
processingLocation,
|
|
142
|
+
signal: options.signal,
|
|
143
|
+
deadline,
|
|
144
|
+
});
|
|
145
|
+
if (typeof upload.upload_url !== "string" || !upload.upload_url) {
|
|
146
|
+
throw new Error("Datalab PDF conversion failed: missing upload_url");
|
|
147
|
+
}
|
|
148
|
+
const uploadFileId = normalizeFileId(upload.file_id);
|
|
149
|
+
if (!uploadFileId) {
|
|
150
|
+
throw new Error("Datalab PDF conversion failed: missing file_id");
|
|
151
|
+
}
|
|
152
|
+
let fileId = uploadFileId;
|
|
153
|
+
let reference = normalizeString(upload.reference);
|
|
154
|
+
try {
|
|
155
|
+
const put = await fetchDatalab(upload.upload_url, {
|
|
156
|
+
method: "PUT",
|
|
157
|
+
headers: { "content-type": "application/pdf" },
|
|
158
|
+
body: new Blob([buffer], { type: "application/pdf" }),
|
|
159
|
+
signal: withTimeout(options.signal, remaining(deadline)),
|
|
160
|
+
}, apiKey);
|
|
161
|
+
if (!put.ok) {
|
|
162
|
+
throw new Error(`Datalab PDF upload failed: HTTP ${put.status} ${put.statusText}`);
|
|
163
|
+
}
|
|
164
|
+
const confirmed = await confirmUpload(apiKey, String(fileId), options.signal, deadline);
|
|
165
|
+
fileId = normalizeFileId(confirmed.file_id) ?? fileId;
|
|
166
|
+
reference = normalizeString(confirmed.reference) ?? reference;
|
|
167
|
+
if (!reference) {
|
|
168
|
+
throw new Error("Datalab PDF conversion failed: missing file reference");
|
|
169
|
+
}
|
|
170
|
+
const form = new FormData();
|
|
171
|
+
form.append("file_url", reference);
|
|
172
|
+
form.append("output_format", "markdown");
|
|
173
|
+
form.append("mode", mode);
|
|
174
|
+
form.append("max_pages", String(options.maxPages));
|
|
175
|
+
form.append("paginate", "true");
|
|
176
|
+
// The conversion itself must NOT repeat processing_location: the API
|
|
177
|
+
// rejects multipart form data carrying processing_location (HTTP 403).
|
|
178
|
+
// The region was already fixed when the presigned upload was issued for
|
|
179
|
+
// storage in the selected region, so the server processes the file
|
|
180
|
+
// wherever it was stored (US by default; use the env override for EU).
|
|
181
|
+
const submit = await fetchDatalab(`${getDatalabApiBase()}/convert`, {
|
|
182
|
+
method: "POST",
|
|
183
|
+
headers: { "x-api-key": apiKey },
|
|
184
|
+
body: form,
|
|
185
|
+
signal: withTimeout(options.signal, remaining(deadline)),
|
|
186
|
+
}, apiKey);
|
|
187
|
+
const state = await readJsonResponse(submit, apiKey);
|
|
188
|
+
// The submit response is an acceptance ack ({ success: true,
|
|
189
|
+
// request_check_url }) with no status field and no markdown; only the
|
|
190
|
+
// polled result carries a status. Key on status, never on success.
|
|
191
|
+
if (state.status === "complete")
|
|
192
|
+
return toResult(state);
|
|
193
|
+
if (state.status === "failed") {
|
|
194
|
+
throw new Error(`Datalab PDF conversion failed: ${state.error ?? "unknown error"}`);
|
|
195
|
+
}
|
|
196
|
+
const checkUrl = normalizeCheckUrl(state.request_check_url);
|
|
197
|
+
while (Date.now() < deadline) {
|
|
198
|
+
await sleep(Math.min(DEFAULT_POLL_INTERVAL_MS, remaining(deadline)), options.signal);
|
|
199
|
+
if (Date.now() >= deadline)
|
|
200
|
+
break;
|
|
201
|
+
const poll = await fetchDatalab(checkUrl, {
|
|
202
|
+
method: "GET",
|
|
203
|
+
headers: { "x-api-key": apiKey },
|
|
204
|
+
signal: withTimeout(options.signal, remaining(deadline)),
|
|
205
|
+
}, apiKey);
|
|
206
|
+
const next = await readJsonResponse(poll, apiKey);
|
|
207
|
+
if (next.status === "complete")
|
|
208
|
+
return toResult(next);
|
|
209
|
+
if (next.status === "failed") {
|
|
210
|
+
throw new Error(`Datalab PDF conversion failed: ${next.error ?? "unknown error"}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
throw new Error("Datalab PDF conversion timed out");
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
// File deletion is best-effort. Do not extend a caller's timeout or
|
|
217
|
+
// cancellation while waiting for a remote cleanup request.
|
|
218
|
+
void deleteDatalabFile(apiKey, fileId);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async function requestUploadUrl(options) {
|
|
222
|
+
const { apiKey, title, processingLocation, signal, deadline } = options;
|
|
223
|
+
const response = await fetchDatalab(`${getDatalabApiBase()}/files/upload`, {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers: {
|
|
226
|
+
"x-api-key": apiKey,
|
|
227
|
+
"content-type": "application/json",
|
|
228
|
+
},
|
|
229
|
+
body: JSON.stringify({
|
|
230
|
+
filename: `${datalabFilename(title)}.pdf`,
|
|
231
|
+
content_type: "application/pdf",
|
|
232
|
+
processing_location: processingLocation,
|
|
233
|
+
}),
|
|
234
|
+
signal: withTimeout(signal, remaining(deadline)),
|
|
235
|
+
}, apiKey);
|
|
236
|
+
return readJsonResponse(response, apiKey);
|
|
237
|
+
}
|
|
238
|
+
async function confirmUpload(apiKey, fileId, signal, deadline) {
|
|
239
|
+
const response = await fetchDatalab(`${getDatalabApiBase()}/files/${encodeURIComponent(fileId)}/confirm`, {
|
|
240
|
+
method: "GET",
|
|
241
|
+
headers: { "x-api-key": apiKey },
|
|
242
|
+
signal: withTimeout(signal, remaining(deadline)),
|
|
243
|
+
}, apiKey);
|
|
244
|
+
return readJsonResponse(response, apiKey);
|
|
245
|
+
}
|
|
246
|
+
async function deleteDatalabFile(apiKey, fileId) {
|
|
247
|
+
try {
|
|
248
|
+
await fetchDatalab(`${getDatalabApiBase()}/files/${encodeURIComponent(fileId)}`, {
|
|
249
|
+
method: "DELETE",
|
|
250
|
+
headers: { "x-api-key": apiKey },
|
|
251
|
+
signal: AbortSignal.timeout(CLEANUP_TIMEOUT_MS),
|
|
252
|
+
}, apiKey);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
// Best-effort cleanup; a leftover file is not worth failing the conversion.
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function toResult(state) {
|
|
259
|
+
const markdown = normalizeString(state.markdown);
|
|
260
|
+
if (!markdown) {
|
|
261
|
+
throw new Error("Datalab PDF conversion returned empty markdown");
|
|
262
|
+
}
|
|
263
|
+
const quality = state.parse_quality_score;
|
|
264
|
+
return {
|
|
265
|
+
markdown,
|
|
266
|
+
pages: numericField(state.page_count) ?? countPageMarkers(markdown),
|
|
267
|
+
...(typeof quality === "number" && Number.isFinite(quality)
|
|
268
|
+
? { parseQualityScore: quality }
|
|
269
|
+
: {}),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function numericField(value) {
|
|
273
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
274
|
+
? Math.floor(value)
|
|
275
|
+
: null;
|
|
276
|
+
}
|
|
277
|
+
function countPageMarkers(markdown) {
|
|
278
|
+
return [...markdown.matchAll(/^<!-- Page (\d+) -->$/gm)].length;
|
|
279
|
+
}
|
|
280
|
+
function normalizeCheckUrl(value) {
|
|
281
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
282
|
+
throw new Error("Datalab PDF conversion failed: missing request_check_url");
|
|
283
|
+
}
|
|
284
|
+
const apiBase = getDatalabApiUrl();
|
|
285
|
+
let checkUrl;
|
|
286
|
+
try {
|
|
287
|
+
checkUrl = new URL(value.trim(), apiBase);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
throw new Error("Datalab PDF conversion failed: invalid request_check_url");
|
|
291
|
+
}
|
|
292
|
+
if (checkUrl.origin !== apiBase.origin) {
|
|
293
|
+
throw new Error("Datalab PDF conversion failed: request_check_url has an unexpected origin");
|
|
294
|
+
}
|
|
295
|
+
return checkUrl.toString();
|
|
296
|
+
}
|
|
297
|
+
function getDatalabApiUrl() {
|
|
298
|
+
try {
|
|
299
|
+
return new URL(getDatalabApiBase());
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
throw new Error("Failed to parse DATALAB_API_BASE: expected an absolute URL");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function remaining(deadline) {
|
|
306
|
+
return Math.max(1, deadline - Date.now());
|
|
307
|
+
}
|
|
308
|
+
function withTimeout(signal, timeoutMs) {
|
|
309
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
310
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
311
|
+
}
|
|
312
|
+
function sleep(ms, signal) {
|
|
313
|
+
return new Promise((resolve, reject) => {
|
|
314
|
+
let timer;
|
|
315
|
+
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
316
|
+
const onTimeout = () => {
|
|
317
|
+
cleanup();
|
|
318
|
+
resolve();
|
|
319
|
+
};
|
|
320
|
+
const onAbort = () => {
|
|
321
|
+
clearTimeout(timer);
|
|
322
|
+
cleanup();
|
|
323
|
+
reject(signal?.reason);
|
|
324
|
+
};
|
|
325
|
+
if (signal?.aborted) {
|
|
326
|
+
onAbort();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
timer = setTimeout(onTimeout, ms);
|
|
330
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
async function fetchDatalab(url, init, apiKey) {
|
|
334
|
+
try {
|
|
335
|
+
return await fetch(url, { ...init, redirect: init.redirect ?? "error" });
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
339
|
+
const redacted = redactCredential(message, apiKey);
|
|
340
|
+
if (redacted === message)
|
|
341
|
+
throw error;
|
|
342
|
+
const redactedError = new Error(redacted);
|
|
343
|
+
if (error instanceof Error)
|
|
344
|
+
redactedError.name = error.name;
|
|
345
|
+
throw redactedError;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async function readJsonResponse(response, apiKey) {
|
|
349
|
+
const text = await readResponseText(response);
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
const detail = text.trim().slice(0, MAX_ERROR_BODY_BYTES);
|
|
352
|
+
const message = detail
|
|
353
|
+
? `Datalab PDF conversion failed: HTTP ${response.status} ${response.statusText}: ${detail}`
|
|
354
|
+
: `Datalab PDF conversion failed: HTTP ${response.status} ${response.statusText}`;
|
|
355
|
+
throw new Error(redactCredential(message, apiKey));
|
|
356
|
+
}
|
|
357
|
+
return parseJsonRecord(text);
|
|
358
|
+
}
|
|
359
|
+
function parseJsonRecord(text) {
|
|
360
|
+
let parsed;
|
|
361
|
+
try {
|
|
362
|
+
parsed = JSON.parse(text);
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
throw new Error("Datalab PDF conversion returned invalid JSON", { cause: error });
|
|
366
|
+
}
|
|
367
|
+
if (Object.prototype.toString.call(parsed) !== "[object Object]") {
|
|
368
|
+
throw new Error("Datalab PDF conversion returned invalid JSON object");
|
|
369
|
+
}
|
|
370
|
+
return parsed;
|
|
371
|
+
}
|
|
372
|
+
async function readResponseText(response) {
|
|
373
|
+
const contentLength = Number(response.headers.get("content-length"));
|
|
374
|
+
if (Number.isFinite(contentLength) && contentLength > MAX_RESPONSE_BYTES) {
|
|
375
|
+
throw new Error("Datalab PDF conversion response too large");
|
|
376
|
+
}
|
|
377
|
+
if (!response.body)
|
|
378
|
+
return "";
|
|
379
|
+
const reader = response.body.getReader();
|
|
380
|
+
const decoder = new TextDecoder();
|
|
381
|
+
const chunks = [];
|
|
382
|
+
let bytesRead = 0;
|
|
383
|
+
try {
|
|
384
|
+
while (true) {
|
|
385
|
+
const { done, value } = await reader.read();
|
|
386
|
+
if (done)
|
|
387
|
+
break;
|
|
388
|
+
bytesRead += value.byteLength;
|
|
389
|
+
if (bytesRead > MAX_RESPONSE_BYTES) {
|
|
390
|
+
try {
|
|
391
|
+
await reader.cancel();
|
|
392
|
+
}
|
|
393
|
+
catch {
|
|
394
|
+
// The response is already too large; cancellation is best-effort.
|
|
395
|
+
}
|
|
396
|
+
throw new Error("Datalab PDF conversion response too large");
|
|
397
|
+
}
|
|
398
|
+
chunks.push(decoder.decode(value, { stream: true }));
|
|
399
|
+
}
|
|
400
|
+
chunks.push(decoder.decode());
|
|
401
|
+
return chunks.join("");
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
reader.releaseLock();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function datalabFilename(title) {
|
|
408
|
+
return (title
|
|
409
|
+
.toLowerCase()
|
|
410
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
411
|
+
.replace(/\s+/g, "-")
|
|
412
|
+
.replace(/-+/g, "-")
|
|
413
|
+
.replace(/^-|-$/g, "")
|
|
414
|
+
.slice(0, 60) || "document");
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=datalab-pdf-extract.js.map
|