@qqbrowser/qbot-dsh 0.1.0 → 0.1.2
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/cordis.patch.yml +50 -0
- package/lib/args-w1okyL78.js +9 -0
- package/lib/bin.js +1 -2
- package/lib/client.js +1 -0
- package/lib/content-review-CqDoh3wY.js +1 -0
- package/lib/content-review.js +1 -0
- package/lib/dump-config-CIL0Goqj.js +1 -0
- package/lib/gateway-port-CSFbDyoZ.js +1 -0
- package/lib/index.js +1 -0
- package/lib/llm-gateway-openai.js +17 -0
- package/lib/native-protocol-DdrIh89-.js +2 -0
- package/lib/{plugin-DNAeLZbb.js → plugin-viWCLnSr.js} +1 -1
- package/lib/profile-boot-CxJUSdnu.js +1 -0
- package/lib/profile-boot-DCgBQ4qO.js +8 -0
- package/lib/qb-auth-C2ofR1zn.js +4 -0
- package/lib/qb-auth.js +1 -0
- package/lib/web-search-dsh.js +1 -0
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/dist-cjs/index.js +7 -2
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js +3 -0
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +3 -0
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/package.json +1 -1
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/dist-cjs/index.js +7 -2
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js +3 -0
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +3 -0
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/package.json +1 -1
- package/node_modules/@deepseek-ai/cordis-plugin-hmr/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-agent/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-agent-default-model/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-agent-instructions/lib/index.js +3 -3
- package/node_modules/@deepseek-ai/dsh-agent-instructions/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-agent-loop/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-agent-presets/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-agent-tool-presentation/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-anonymous-user-id/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-api-gateway/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-api-remotes/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-app-boot/lib/index.js +12 -12
- package/node_modules/@deepseek-ai/dsh-app-boot/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-atomic-write/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-attachment/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-attachment-local/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-attachment-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-base/cordis.patch.yml +6 -37
- package/node_modules/@deepseek-ai/dsh-base/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-bash-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-bash-sandbox/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-brand/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-connection/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-hmr/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-locale/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-locale/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-modules/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-runtime/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-schema-form/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-agent-preset/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-agent-preset/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-attachment/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-commands/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-commands/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-conversation/lib/client.js +8 -8
- package/node_modules/@deepseek-ai/dsh-client-ui-conversation/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-cordis/lib/client.js +3 -3
- package/node_modules/@deepseek-ai/dsh-client-ui-cordis/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-deliverables/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-deliverables/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-directory-picker-browse/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-directory-picker-browse/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-directory-picker-native/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-goal/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-goal/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-jobs/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-jobs/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-layout/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-layout/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-message-feedback/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-message-feedback/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-permission-presets/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-permission-presets/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-plan/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-plan/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/lib/client.js +3 -3
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugin-inventory/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugin-inventory/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugins/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugins/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-skill/lib/client.js +3 -3
- package/node_modules/@deepseek-ai/dsh-client-ui-skill/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-subagent/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-subagent/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-theme/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-theme/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-tool/lib/client.js +4 -4
- package/node_modules/@deepseek-ai/dsh-client-ui-tool/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-trajectory/lib/client.js +14 -14
- package/node_modules/@deepseek-ai/dsh-client-ui-trajectory/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-user-questions/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-user-questions/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-workflow-run/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-workflow-run/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-workspace/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-web/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-client-web-react/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-cmdline/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-cmdline/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-code-runtime/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-code-runtime-worker-thread/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-command-compact/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-command-feedback/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-command-goal/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-commands/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-compaction/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-compaction-basic/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-compaction-tool-result-pruner/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-cordis-client-runner/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-cordis-host-runner/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-credentials/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-credentials-local/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-credentials-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-fs/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-fs-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-fs-observation-policy/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-fs-sandbox/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-goal/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-goal-round-driver/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-headless/lib/index.js +4 -4
- package/node_modules/@deepseek-ai/dsh-headless/lib/startup.js +3 -3
- package/node_modules/@deepseek-ai/dsh-headless/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-home-paths/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-apiproxy/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-directory-picker/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-directory-picker-auto/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-directory-picker-browse/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-directory-picker-native/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-frontend-static/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-plugin-inventory/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-host-webserver/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-host-webserver/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-invariants/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-jobs/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-jobs-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-launch-environment/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-llm/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-deepseek/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-retry/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-mcp-client/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-message-feedback/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-native-command/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-output-retention/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-permission-presets/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-persona/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-plan-mode/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-pwsh-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-pwsh-sandbox/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-repeat-tool-reminder/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-policy/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/lib/runner.js +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-schedule/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-scope/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-checkpoint-policy/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-log-export/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-session-log-export/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-persistence/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-projection/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-projection-cache/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-query/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-query-sqlite/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-reference/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-stats/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-telemetry/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-telemetry-otel/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-title/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-title-first-prompt-llm/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-session-title-llm/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-settings/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-settings-file/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-shell/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-shell-env/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-shell-env/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-skill/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-skill-badge/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-skill-filesystem/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-spill/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-spill-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-spill-policy/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-storage/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-storage-domain/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-storage-json/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-subagent/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-subagent-fork-in-process/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-subagent-in-process-driver/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-subagent-spawn-in-process/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-subprocess/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-subprocess/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-subprocess-local/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-system-prompt/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-terminal/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-terminal-bash/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-time-context/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-timeout/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tmux-context/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-token-meter/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-ask-user/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-bash/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-bash-persistent/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-call-timeout-policy/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/index.js +5 -29
- package/node_modules/@deepseek-ai/dsh-tool-cordis/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs-search/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-goal/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-jobs/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-pwsh/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-ralph/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-skill/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-subagent/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-subagent-control/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-subagent-report/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-todo/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-web/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-workflow/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tools/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-typert-loader/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-typert-protocol/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-typert-registry/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-user-approval/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-user-questions/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-web/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-web/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-web-app/cordis.patch.yml +0 -1
- package/node_modules/@deepseek-ai/dsh-web-app/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-web-app/lib/startup.js +4 -5
- package/node_modules/@deepseek-ai/dsh-web-app/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-web-frontend/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-web-search-deepseek/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-workflow/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-workflow-worker-thread/lib/worker.cjs +9 -8
- package/node_modules/@deepseek-ai/dsh-workflow-worker-thread/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-workspace/package.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +4 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +5 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +6 -6
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +5 -5
- package/node_modules/@earendil-works/pi-ai/package.json +1 -1
- package/node_modules/@koromix/koffi-darwin-arm64/darwin_arm64/koffi.node +0 -0
- package/node_modules/@koromix/koffi-darwin-arm64/package.json +1 -1
- package/node_modules/@koromix/koffi-darwin-x64/darwin_x64/koffi.node +0 -0
- package/node_modules/@koromix/koffi-darwin-x64/package.json +1 -1
- package/node_modules/@koromix/koffi-win32-x64/package.json +1 -1
- package/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.node +0 -0
- package/node_modules/@smithy/core/dist-cjs/index.js +3 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +126 -39
- package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +14 -3
- package/node_modules/@smithy/core/dist-cjs/submodules/endpoints/index.browser.js +3 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/endpoints/index.js +3 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.browser.js +10 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +10 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +16 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +4 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +4 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.browser.js +4 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.js +4 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.native.js +4 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/transport/index.js +7 -0
- package/node_modules/@smithy/core/dist-es/legacy-root-exports/util-identity-and-auth/DefaultIdentityProviderConfig.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-decode.js +29 -13
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-encode.js +12 -4
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v1/CborShapeDeserializer.js +9 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v1/CborShapeSerializer.js +7 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/CborShapeDeserializer2.js +44 -15
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/CborShapeSerializer2.js +22 -4
- package/node_modules/@smithy/core/dist-es/submodules/cbor/parseCborBody.js +5 -0
- package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/extensions/checksum.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/get-value-from-text-node.js +4 -1
- package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/object-mapping.js +6 -1
- package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/serde-json.js +4 -1
- package/node_modules/@smithy/core/dist-es/submodules/endpoints/util-endpoints/resolveEndpoint.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +7 -0
- package/node_modules/@smithy/core/dist-es/submodules/event-streams/eventstream-codec/HeaderMarshaller.js +4 -1
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +9 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +5 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/parseRetryAfterHeader.js +4 -1
- package/node_modules/@smithy/core/dist-es/submodules/serde/index.browser.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/serde/index.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/serde/index.native.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/serde/parse-utils.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/transport/hasOwn.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/transport/index.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/transport/toEndpointV1.js +3 -0
- package/node_modules/@smithy/core/package.json +1 -1
- package/node_modules/@smithy/signature-v4/dist-cjs/index.js +19 -7
- package/node_modules/@smithy/signature-v4/dist-es/HeaderFormatter.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/getCanonicalQuery.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/getPayloadHash.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/headerUtil.js +10 -3
- package/node_modules/@smithy/signature-v4/dist-es/moveHeadersToQuery.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/prepareRequest.js +4 -1
- package/node_modules/@smithy/signature-v4/package.json +1 -1
- package/node_modules/koffi/package.json +1 -1
- package/node_modules/koffi/src/koffi/index.cjs +1 -1
- package/node_modules/koffi/src/koffi/index.js +1 -1
- package/node_modules/koffi/src/koffi/indirect.cjs +1 -1
- package/node_modules/koffi/src/koffi/indirect.js +1 -1
- package/node_modules/negotiator/lib/accept.js +54 -0
- package/node_modules/negotiator/lib/charset.js +10 -34
- package/node_modules/negotiator/lib/encoding.js +9 -30
- package/node_modules/negotiator/lib/language.js +15 -36
- package/node_modules/negotiator/lib/mediaType.js +16 -134
- package/node_modules/negotiator/node_modules/content-type/LICENSE +22 -0
- package/node_modules/negotiator/node_modules/content-type/dist/index.js +176 -0
- package/node_modules/negotiator/node_modules/content-type/package.json +1 -0
- package/node_modules/negotiator/package.json +1 -1
- package/node_modules/typebox/build/compile/validator.mjs +1 -1
- package/node_modules/typebox/build/format/_idna.mjs +1 -1
- package/node_modules/typebox/build/format/_puny.mjs +1 -1
- package/node_modules/typebox/build/format/uuid.mjs +1 -1
- package/node_modules/typebox/build/guard/emit.mjs +1 -1
- package/node_modules/typebox/build/guard/guard.mjs +1 -1
- package/node_modules/typebox/build/guard/string.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/_guard.mjs +1 -0
- package/node_modules/typebox/build/schema/engine/boolean.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/index.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/schema.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/type.mjs +1 -1
- package/node_modules/typebox/build/schema/types/_guard.mjs +1 -0
- package/node_modules/typebox/build/schema/types/index.mjs +1 -1
- package/node_modules/typebox/build/schema/types/schema.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ar_001.mjs +1 -1
- package/node_modules/typebox/build/system/locale/bn_BD.mjs +1 -1
- package/node_modules/typebox/build/system/locale/cs_CZ.mjs +1 -1
- package/node_modules/typebox/build/system/locale/de_DE.mjs +1 -1
- package/node_modules/typebox/build/system/locale/el_GR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/en_US.mjs +1 -1
- package/node_modules/typebox/build/system/locale/es_419.mjs +1 -1
- package/node_modules/typebox/build/system/locale/es_AR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/es_ES.mjs +1 -1
- package/node_modules/typebox/build/system/locale/es_MX.mjs +1 -1
- package/node_modules/typebox/build/system/locale/fa_IR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/fil_PH.mjs +1 -1
- package/node_modules/typebox/build/system/locale/fr_CA.mjs +1 -1
- package/node_modules/typebox/build/system/locale/fr_FR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ha_NG.mjs +1 -1
- package/node_modules/typebox/build/system/locale/hi_IN.mjs +1 -1
- package/node_modules/typebox/build/system/locale/hu_HU.mjs +1 -1
- package/node_modules/typebox/build/system/locale/id_ID.mjs +1 -1
- package/node_modules/typebox/build/system/locale/it_IT.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ja_JP.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ko_KR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ms_MY.mjs +1 -1
- package/node_modules/typebox/build/system/locale/nl_NL.mjs +1 -1
- package/node_modules/typebox/build/system/locale/pl_PL.mjs +1 -1
- package/node_modules/typebox/build/system/locale/pt_BR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/pt_PT.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ro_RO.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ru_RU.mjs +1 -1
- package/node_modules/typebox/build/system/locale/sv_SE.mjs +1 -1
- package/node_modules/typebox/build/system/locale/sw_TZ.mjs +1 -1
- package/node_modules/typebox/build/system/locale/th_TH.mjs +1 -1
- package/node_modules/typebox/build/system/locale/tr_TR.mjs +1 -1
- package/node_modules/typebox/build/system/locale/uk_UA.mjs +1 -1
- package/node_modules/typebox/build/system/locale/ur_PK.mjs +1 -1
- package/node_modules/typebox/build/system/locale/vi_VN.mjs +1 -1
- package/node_modules/typebox/build/system/locale/yo_NG.mjs +1 -1
- package/node_modules/typebox/build/system/locale/zh_Hans.mjs +1 -1
- package/node_modules/typebox/build/system/locale/zh_Hant.mjs +1 -1
- package/node_modules/typebox/build/system/memory/clone.mjs +1 -1
- package/node_modules/typebox/build/system/settings/settings.mjs +1 -1
- package/node_modules/typebox/build/type/action/_optional.mjs +1 -0
- package/node_modules/typebox/build/type/action/_readonly.mjs +1 -0
- package/node_modules/typebox/build/type/action/awaited.mjs +1 -0
- package/node_modules/typebox/build/type/action/conditional.mjs +1 -1
- package/node_modules/typebox/build/type/action/index.mjs +1 -1
- package/node_modules/typebox/build/type/action/mapped.mjs +1 -1
- package/node_modules/typebox/build/type/action/module.mjs +1 -1
- package/node_modules/typebox/build/type/action/options.mjs +1 -0
- package/node_modules/typebox/build/type/engine/awaited/instantiate.mjs +1 -0
- package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +1 -1
- package/node_modules/typebox/build/type/engine/call/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/call/resolve_arguments.mjs +1 -1
- package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/cyclic/candidates.mjs +1 -1
- package/node_modules/typebox/build/type/engine/cyclic/check.mjs +1 -1
- package/node_modules/typebox/build/type/engine/cyclic/dependencies.mjs +1 -1
- package/node_modules/typebox/build/type/engine/cyclic/extends.mjs +1 -1
- package/node_modules/typebox/build/type/engine/cyclic/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/enum/enum_to_union.mjs +1 -0
- package/node_modules/typebox/build/type/engine/enum/index.mjs +1 -1
- package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +1 -1
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +1 -1
- package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +1 -1
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/exclude/operation.mjs +1 -1
- package/node_modules/typebox/build/type/engine/extract/operation.mjs +1 -1
- package/node_modules/typebox/build/type/engine/index.mjs +1 -1
- package/node_modules/typebox/build/type/engine/indexable/from_enum.mjs +1 -1
- package/node_modules/typebox/build/type/engine/indexable/from_template_literal.mjs +1 -1
- package/node_modules/typebox/build/type/engine/indexable/from_type.mjs +1 -1
- package/node_modules/typebox/build/type/engine/indexed/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.mjs +1 -1
- package/node_modules/typebox/build/type/engine/keyof/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/mapped/mapped_operation.mjs +1 -1
- package/node_modules/typebox/build/type/engine/mapped/mapped_variants.mjs +1 -1
- package/node_modules/typebox/build/type/engine/module/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/object/from_type.mjs +1 -1
- package/node_modules/typebox/build/type/engine/object/from_union.mjs +1 -1
- package/node_modules/typebox/build/type/engine/options/index.mjs +1 -0
- package/node_modules/typebox/build/type/engine/options/instantiate.mjs +1 -0
- package/node_modules/typebox/build/type/engine/parameters/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/partial/from_intersect.mjs +1 -1
- package/node_modules/typebox/build/type/engine/partial/from_object.mjs +1 -1
- package/node_modules/typebox/build/type/engine/partial/from_type.mjs +1 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_array.mjs +1 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.mjs +1 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_object.mjs +1 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.mjs +1 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_type.mjs +1 -1
- package/node_modules/typebox/build/type/engine/record/from_key_enum.mjs +1 -1
- package/node_modules/typebox/build/type/engine/record/from_key_template_literal.mjs +1 -1
- package/node_modules/typebox/build/type/engine/ref/instantiate.mjs +1 -1
- package/node_modules/typebox/build/type/engine/required/from_intersect.mjs +1 -1
- package/node_modules/typebox/build/type/engine/required/from_object.mjs +1 -1
- package/node_modules/typebox/build/type/engine/required/from_type.mjs +1 -1
- package/node_modules/typebox/build/type/engine/template_literal/decode.mjs +1 -1
- package/node_modules/typebox/build/type/engine/template_literal/encode.mjs +1 -1
- package/node_modules/typebox/build/type/engine/template_literal/is_finite.mjs +1 -1
- package/node_modules/typebox/build/type/engine/this/expand_this.mjs +1 -1
- package/node_modules/typebox/build/type/extends/async_iterator.mjs +1 -0
- package/node_modules/typebox/build/type/extends/enum.mjs +1 -1
- package/node_modules/typebox/build/type/extends/extends_left.mjs +1 -1
- package/node_modules/typebox/build/type/extends/extends_right.mjs +1 -1
- package/node_modules/typebox/build/type/extends/inference.mjs +1 -1
- package/node_modules/typebox/build/type/extends/iterator.mjs +1 -0
- package/node_modules/typebox/build/type/extends/object.mjs +1 -1
- package/node_modules/typebox/build/type/extends/parameters.mjs +1 -1
- package/node_modules/typebox/build/type/extends/promise.mjs +1 -0
- package/node_modules/typebox/build/type/extends/template_literal.mjs +1 -1
- package/node_modules/typebox/build/type/extends/tuple.mjs +1 -1
- package/node_modules/typebox/build/type/extends/union.mjs +1 -1
- package/node_modules/typebox/build/type/script/mapping.mjs +1 -1
- package/node_modules/typebox/build/type/script/parser.mjs +6 -6
- package/node_modules/typebox/build/type/script/script.mjs +1 -1
- package/node_modules/typebox/build/type/script/token/internal/guard.mjs +1 -1
- package/node_modules/typebox/build/type/script/token/until.mjs +1 -1
- package/node_modules/typebox/build/type/types/_immutable.mjs +1 -1
- package/node_modules/typebox/build/type/types/_optional.mjs +1 -1
- package/node_modules/typebox/build/type/types/_readonly.mjs +1 -1
- package/node_modules/typebox/build/type/types/_refine.mjs +1 -1
- package/node_modules/typebox/build/type/types/async_iterator.mjs +1 -0
- package/node_modules/typebox/build/type/types/base.mjs +1 -0
- package/node_modules/typebox/build/type/types/call.mjs +1 -1
- package/node_modules/typebox/build/type/types/deferred.mjs +1 -1
- package/node_modules/typebox/build/type/types/enum.mjs +1 -1
- package/node_modules/typebox/build/type/types/index.mjs +1 -1
- package/node_modules/typebox/build/type/types/iterator.mjs +1 -0
- package/node_modules/typebox/build/type/types/number.mjs +1 -1
- package/node_modules/typebox/build/type/types/promise.mjs +1 -0
- package/node_modules/typebox/build/type/types/record.mjs +1 -1
- package/node_modules/typebox/build/typebox.mjs +1 -1
- package/node_modules/typebox/build/value/clean/clean.mjs +1 -1
- package/node_modules/typebox/build/value/clean/from_base.mjs +1 -0
- package/node_modules/typebox/build/value/clean/from_intersect.mjs +1 -1
- package/node_modules/typebox/build/value/clean/from_type.mjs +1 -1
- package/node_modules/typebox/build/value/clean/from_union.mjs +1 -1
- package/node_modules/typebox/build/value/clone/clone.mjs +1 -1
- package/node_modules/typebox/build/value/codec/decode.mjs +1 -1
- package/node_modules/typebox/build/value/codec/encode.mjs +1 -1
- package/node_modules/typebox/build/value/codec/from_array.mjs +1 -1
- package/node_modules/typebox/build/value/codec/from_object.mjs +1 -1
- package/node_modules/typebox/build/value/codec/from_record.mjs +1 -1
- package/node_modules/typebox/build/value/codec/from_tuple.mjs +1 -1
- package/node_modules/typebox/build/value/codec/from_union.mjs +1 -1
- package/node_modules/typebox/build/value/convert/from_base.mjs +1 -0
- package/node_modules/typebox/build/value/convert/from_enum.mjs +1 -1
- package/node_modules/typebox/build/value/convert/from_template_literal.mjs +1 -1
- package/node_modules/typebox/build/value/convert/from_type.mjs +1 -1
- package/node_modules/typebox/build/value/create/from_async_iterator.mjs +1 -0
- package/node_modules/typebox/build/value/create/from_base.mjs +1 -0
- package/node_modules/typebox/build/value/create/from_enum.mjs +1 -1
- package/node_modules/typebox/build/value/create/from_iterator.mjs +1 -0
- package/node_modules/typebox/build/value/create/from_promise.mjs +1 -0
- package/node_modules/typebox/build/value/create/from_type.mjs +1 -1
- package/node_modules/typebox/build/value/default/from_base.mjs +1 -0
- package/node_modules/typebox/build/value/default/from_object.mjs +1 -1
- package/node_modules/typebox/build/value/default/from_type.mjs +1 -1
- package/node_modules/typebox/build/value/index.mjs +1 -1
- package/node_modules/typebox/build/value/mutate/error.mjs +1 -0
- package/node_modules/typebox/build/value/mutate/from_array.mjs +1 -0
- package/node_modules/typebox/build/value/mutate/from_object.mjs +1 -0
- package/node_modules/typebox/build/value/mutate/from_unknown.mjs +1 -0
- package/node_modules/typebox/build/value/mutate/from_value.mjs +1 -0
- package/node_modules/typebox/build/value/mutate/index.mjs +1 -0
- package/node_modules/typebox/build/value/mutate/mutate.mjs +1 -0
- package/node_modules/typebox/build/value/repair/from_base.mjs +1 -0
- package/node_modules/typebox/build/value/repair/from_enum.mjs +1 -1
- package/node_modules/typebox/build/value/repair/from_type.mjs +1 -1
- package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +1 -1
- package/node_modules/typebox/build/value/value.mjs +1 -1
- package/node_modules/typebox/package.json +1 -1
- package/package.json +1 -1
- package/lib/args-DcHS9iff.js +0 -9
- package/lib/dump-config-xQTUTTDD.js +0 -1
- package/lib/profile-boot-BkordgJK.js +0 -1
- package/lib/profile-boot-DDo03lXi.js +0 -8
- package/node_modules/@deepseek-ai/dsh-content-review/LICENSE +0 -21
- package/node_modules/@deepseek-ai/dsh-content-review/lib/index.js +0 -1
- package/node_modules/@deepseek-ai/dsh-content-review/lib/invariant.js +0 -1
- package/node_modules/@deepseek-ai/dsh-content-review/package.json +0 -1
- package/node_modules/@deepseek-ai/dsh-home-quarantine-macos/LICENSE +0 -21
- package/node_modules/@deepseek-ai/dsh-home-quarantine-macos/lib/index.js +0 -1
- package/node_modules/@deepseek-ai/dsh-home-quarantine-macos/lib/invariant.js +0 -1
- package/node_modules/@deepseek-ai/dsh-home-quarantine-macos/package.json +0 -1
- package/node_modules/@deepseek-ai/dsh-llm-gateway-openai/LICENSE +0 -21
- package/node_modules/@deepseek-ai/dsh-llm-gateway-openai/lib/index.js +0 -17
- package/node_modules/@deepseek-ai/dsh-llm-gateway-openai/lib/invariant.js +0 -1
- package/node_modules/@deepseek-ai/dsh-llm-gateway-openai/package.json +0 -1
- package/node_modules/@deepseek-ai/dsh-qb-auth/LICENSE +0 -21
- package/node_modules/@deepseek-ai/dsh-qb-auth/lib/index.js +0 -4
- package/node_modules/@deepseek-ai/dsh-qb-auth/lib/invariant.js +0 -1
- package/node_modules/@deepseek-ai/dsh-qb-auth/package.json +0 -1
- package/node_modules/@deepseek-ai/dsh-web-search-dsh/LICENSE +0 -21
- package/node_modules/@deepseek-ai/dsh-web-search-dsh/lib/index.js +0 -1
- package/node_modules/@deepseek-ai/dsh-web-search-dsh/lib/invariant.js +0 -1
- package/node_modules/@deepseek-ai/dsh-web-search-dsh/package.json +0 -1
- package/node_modules/@napi-rs/xattr/LICENSE +0 -21
- package/node_modules/@napi-rs/xattr/index.js +0 -567
- package/node_modules/@napi-rs/xattr/package.json +0 -1
- package/node_modules/@napi-rs/xattr-darwin-arm64/package.json +0 -1
- package/node_modules/@napi-rs/xattr-darwin-arm64/xattr.darwin-arm64.node +0 -0
- package/node_modules/@napi-rs/xattr-darwin-x64/package.json +0 -1
- package/node_modules/@napi-rs/xattr-darwin-x64/xattr.darwin-x64.node +0 -0
- package/node_modules/@parcel/watcher/LICENSE +0 -21
- package/node_modules/@parcel/watcher/index.js +0 -44
- package/node_modules/@parcel/watcher/index.js.flow +0 -45
- package/node_modules/@parcel/watcher/package.json +0 -1
- package/node_modules/@parcel/watcher/scripts/build-from-source.js +0 -16
- package/node_modules/@parcel/watcher/wrapper.js +0 -88
- package/node_modules/@parcel/watcher-darwin-arm64/LICENSE +0 -21
- package/node_modules/@parcel/watcher-darwin-arm64/package.json +0 -1
- package/node_modules/@parcel/watcher-darwin-arm64/watcher.node +0 -0
- package/node_modules/@parcel/watcher-darwin-x64/LICENSE +0 -21
- package/node_modules/@parcel/watcher-darwin-x64/package.json +0 -1
- package/node_modules/@parcel/watcher-darwin-x64/watcher.node +0 -0
- package/node_modules/@parcel/watcher-win32-x64/LICENSE +0 -21
- package/node_modules/@parcel/watcher-win32-x64/package.json +0 -1
- package/node_modules/@parcel/watcher-win32-x64/watcher.node +0 -0
- package/node_modules/is-extglob/LICENSE +0 -21
- package/node_modules/is-extglob/index.js +0 -20
- package/node_modules/is-extglob/package.json +0 -1
- package/node_modules/is-glob/LICENSE +0 -21
- package/node_modules/is-glob/index.js +0 -150
- package/node_modules/is-glob/package.json +0 -1
- package/node_modules/typebox/build/type/action/_add_immutable.mjs +0 -1
- package/node_modules/typebox/build/type/action/_add_optional.mjs +0 -1
- package/node_modules/typebox/build/type/action/_add_readonly.mjs +0 -1
- package/node_modules/typebox/build/type/action/_remove_immutable.mjs +0 -1
- package/node_modules/typebox/build/type/action/_remove_optional.mjs +0 -1
- package/node_modules/typebox/build/type/action/_remove_readonly.mjs +0 -1
- package/node_modules/typebox/build/type/action/with.mjs +0 -1
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +0 -1
- package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.mjs +0 -1
- package/node_modules/typebox/build/type/engine/indexable/from_dependent.mjs +0 -1
- package/node_modules/typebox/build/type/engine/object/from_dependent.mjs +0 -1
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +0 -1
- package/node_modules/typebox/build/type/engine/optional/instantiate_remove.mjs +0 -1
- package/node_modules/typebox/build/type/engine/partial/from_dependent.mjs +0 -1
- package/node_modules/typebox/build/type/engine/priority/index.mjs +0 -1
- package/node_modules/typebox/build/type/engine/priority/priority.mjs +0 -1
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +0 -1
- package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.mjs +0 -1
- package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.mjs +0 -1
- package/node_modules/typebox/build/type/engine/required/from_dependent.mjs +0 -1
- package/node_modules/typebox/build/type/engine/with/instantiate.mjs +0 -1
- package/node_modules/typebox/build/type/extends/dependent.mjs +0 -1
- package/node_modules/typebox/build/type/extends/record.mjs +0 -1
- package/node_modules/typebox/build/type/types/dependent.mjs +0 -1
- /package/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/lib/{types-D2_FQYSK.js → types-DE3U0cmQ.js} +0 -0
- /package/node_modules/typebox/build/type/engine/{with → awaited}/index.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
var v=Object.defineProperty;var a=(e,t)=>v(e,"name",{value:t,configurable:!0});import{GoogleGenAI as L,ResourceScope as
|
|
1
|
+
var v=Object.defineProperty;var a=(e,t)=>v(e,"name",{value:t,configurable:!0});import{GoogleGenAI as L,ResourceScope as M,ThinkingLevel as h}from"@google/genai";import{calculateCost as R,clampThinkingLevel as w}from"../models.js";import{formatProviderError as S,normalizeProviderError as G}from"../utils/error-body.js";import{AssistantMessageEventStream as A}from"../utils/event-stream.js";import{providerHeadersToRecord as P}from"../utils/headers.js";import{getProviderEnvValue as k}from"../utils/provider-env.js";import{sanitizeSurrogates as N}from"../utils/sanitize-unicode.js";import{convertMessages as U,convertTools as D,isThinkingPart as H,mapStopReason as V,resolveGoogleFunctionCallingMode as K,retainThoughtSignature as x,supportsGoogleStrictToolSampling as W}from"./google-shared.js";import{buildBaseOptions as j}from"./simple-options.js";const E="v1",B="gcp-vertex-credentials",$={THINKING_LEVEL_UNSPECIFIED:h.THINKING_LEVEL_UNSPECIFIED,MINIMAL:h.MINIMAL,LOW:h.LOW,MEDIUM:h.MEDIUM,HIGH:h.HIGH};let F=0;export const stream=a((e,t,n)=>{const o=new A;return(async()=>{const i={role:"assistant",content:[],api:"google-vertex",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{const l=Y(n),u=l?q(e,l,n?.headers):J(e,ee(n),te(n),n?.headers,n?.env);let f=ne(e,t,n);const p=await n?.onPayload?.(f,e);p!==void 0&&(f=p);const b=await u.models.generateContentStream(f);o.push({type:"start",partial:i});let r=null;const y=i.content,c=a(()=>y.length-1,"blockIndex");for await(const d of b){i.responseId||=d.responseId;const m=d.candidates?.[0];if(m?.content?.parts)for(const s of m.content.parts){if(s.text!==void 0){const g=H(s);(!r||g&&r.type!=="thinking"||!g&&r.type!=="text")&&(r&&(r.type==="text"?o.push({type:"text_end",contentIndex:y.length-1,content:r.text,partial:i}):o.push({type:"thinking_end",contentIndex:c(),content:r.thinking,partial:i})),g?(r={type:"thinking",thinking:"",thinkingSignature:void 0},i.content.push(r),o.push({type:"thinking_start",contentIndex:c(),partial:i})):(r={type:"text",text:""},i.content.push(r),o.push({type:"text_start",contentIndex:c(),partial:i}))),r.type==="thinking"?(r.thinking+=s.text,r.thinkingSignature=x(r.thinkingSignature,s.thoughtSignature),o.push({type:"thinking_delta",contentIndex:c(),delta:s.text,partial:i})):(r.text+=s.text,r.textSignature=x(r.textSignature,s.thoughtSignature),o.push({type:"text_delta",contentIndex:c(),delta:s.text,partial:i}))}if(s.functionCall){r&&(r.type==="text"?o.push({type:"text_end",contentIndex:c(),content:r.text,partial:i}):o.push({type:"thinking_end",contentIndex:c(),content:r.thinking,partial:i}),r=null);const g=s.functionCall.id,I={type:"toolCall",id:!g||i.content.some(O=>O.type==="toolCall"&&O.id===g)?`${s.functionCall.name}_${Date.now()}_${++F}`:g,name:s.functionCall.name||"",arguments:s.functionCall.args??{},...s.thoughtSignature&&{thoughtSignature:s.thoughtSignature}};i.content.push(I),o.push({type:"toolcall_start",contentIndex:c(),partial:i}),o.push({type:"toolcall_delta",contentIndex:c(),delta:JSON.stringify(I.arguments),partial:i}),o.push({type:"toolcall_end",contentIndex:c(),toolCall:I,partial:i})}}m?.finishReason&&(i.stopReason=V(m.finishReason),i.content.some(s=>s.type==="toolCall")&&(i.stopReason="toolUse")),d.usageMetadata&&(i.usage={input:(d.usageMetadata.promptTokenCount||0)-(d.usageMetadata.cachedContentTokenCount||0),output:(d.usageMetadata.candidatesTokenCount||0)+(d.usageMetadata.thoughtsTokenCount||0),cacheRead:d.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:d.usageMetadata.thoughtsTokenCount||0,totalTokens:d.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},R(e,i.usage))}if(r&&(r.type==="text"?o.push({type:"text_end",contentIndex:c(),content:r.text,partial:i}):o.push({type:"thinking_end",contentIndex:c(),content:r.thinking,partial:i})),n?.signal?.aborted)throw new Error("Request was aborted");if(i.stopReason==="aborted"||i.stopReason==="error")throw new Error("An unknown error occurred");o.push({type:"done",reason:i.stopReason,message:i}),o.end()}catch(l){for(const u of i.content)"index"in u&&delete u.index;i.stopReason=n?.signal?.aborted?"aborted":"error",i.errorMessage=S(G(l)),o.push({type:"error",reason:i.stopReason,error:i}),o.end()}})(),o},"stream"),streamSimple=a((e,t,n)=>{const o=j(e,t,n,void 0);if(!n?.reasoning)return stream(e,t,{...o,thinking:{enabled:!1}});const i=w(e,n.reasoning),l=i==="off"?"high":i,u=e;return C(u)||_(u)?stream(e,t,{...o,thinking:{enabled:!0,level:oe(l,u)}}):stream(e,t,{...o,thinking:{enabled:!0,budgetTokens:re(u,l,n.thinkingBudgets)}})},"streamSimple");function J(e,t,n,o,i){const l=Q(i);return new L({vertexai:!0,project:t,location:n,apiVersion:E,...l?{googleAuthOptions:l}:{},httpOptions:T(e,o)})}a(J,"createClient");function q(e,t,n){return new L({vertexai:!0,apiKey:t,apiVersion:E,httpOptions:T(e,n)})}a(q,"createClientWithApiKey");function T(e,t){const n={},o=z(e.baseUrl);o&&(n.baseUrl=o,n.baseUrlResourceScope=M.COLLECTION,X(o)&&(n.apiVersion=""));const i=P({...e.headers,...t});return i&&(n.headers=i),Object.keys(n).length>0?n:void 0}a(T,"buildHttpOptions");function z(e){const t=e.trim();if(!(!t||t.includes("{location}")))return t}a(z,"resolveCustomBaseUrl");function X(e){try{return new URL(e).pathname.split("/").some(n=>/^v\d+(?:beta\d*)?$/.test(n))}catch{return/(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(e)}}a(X,"baseUrlIncludesApiVersion");function Q(e){const t=k("GOOGLE_APPLICATION_CREDENTIALS",e);return t?{keyFilename:t}:void 0}a(Q,"buildGoogleAuthOptions");function Y(e){const t=e?.apiKey?.trim();if(!(!t||t===B||Z(t)))return t}a(Y,"resolveApiKey");function Z(e){return/^<[^>]+>$/.test(e)}a(Z,"isPlaceholderApiKey");function ee(e){const t=e?.project||k("GOOGLE_CLOUD_PROJECT",e?.env)||k("GCLOUD_PROJECT",e?.env);if(!t)throw new Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");return t}a(ee,"resolveProject");function te(e){const t=e?.location||k("GOOGLE_CLOUD_LOCATION",e?.env);if(!t)throw new Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");return t}a(te,"resolveLocation");function ne(e,t,n={}){const o=U(e,t),i={};n.temperature!==void 0&&(i.temperature=n.temperature),n.maxTokens!==void 0&&(i.maxOutputTokens=n.maxTokens);const l=t.tools?.length?K(t.tools,n.toolChoice,W(e.id)):void 0,u={...Object.keys(i).length>0&&i,...t.systemPrompt&&{systemInstruction:N(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:D(t.tools)},...l!==void 0&&{toolConfig:{functionCallingConfig:{mode:l}}}};if(n.thinking?.enabled&&e.reasoning){const p={includeThoughts:!0};n.thinking.level!==void 0?p.thinkingLevel=$[n.thinking.level]:n.thinking.budgetTokens!==void 0&&(p.thinkingBudget=n.thinking.budgetTokens),u.thinkingConfig=p}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(u.thinkingConfig=ie(e));if(n.signal){if(n.signal.aborted)throw new Error("Request aborted");u.abortSignal=n.signal}return{model:e.id,contents:o,config:u}}a(ne,"buildParams");function C(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}a(C,"isGemini3ProModel");function _(e){const t=e.id.toLowerCase();return/gemini-3(?:\.\d+)?-flash/.test(t)||t==="gemini-flash-latest"||t==="gemini-flash-lite-latest"}a(_,"isGemini3FlashModel");function ie(e){const t=e;return C(t)?{thinkingLevel:h.LOW}:_(t)?{thinkingLevel:h.MINIMAL}:{thinkingBudget:0}}a(ie,"getDisabledThinkingConfig");function oe(e,t){if(C(t))switch(e){case"minimal":case"low":return"LOW";case"medium":case"high":return"HIGH"}switch(e){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";case"high":return"HIGH"}}a(oe,"getGemini3ThinkingLevel");function re(e,t,n){return n?.[t]!==void 0?n[t]:e.id.includes("2.5-pro")?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes("2.5-flash")?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1}a(re,"getGoogleBudget");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
[tool image omitted: model does not support images]`:""}`:
|
|
1
|
+
var S=Object.defineProperty;var i=(e,t)=>S(e,"name",{value:t,configurable:!0});import{Mistral as $}from"@mistralai/mistralai";import{calculateCost as E,clampThinkingLevel as O}from"../models.js";import{AssistantMessageEventStream as P}from"../utils/event-stream.js";import{shortHash as D}from"../utils/hash.js";import{parseStreamingJson as R}from"../utils/json-parse.js";import{sanitizeSurrogates as y}from"../utils/sanitize-unicode.js";import{resolveJsonSchemaStrictSampling as L}from"./constrained-sampling.js";import{buildBaseOptions as N}from"./simple-options.js";import{transformMessages as v}from"./transform-messages.js";const _=9,B=4e3;export const stream=i((e,t,o)=>{const n=new P;return(async()=>{const r=U(e);try{const u=o?.apiKey;if(!u)throw new Error(`No API key for provider: ${e.provider}`);const l=new $({apiKey:u,serverURL:e.baseUrl}),m=j(),s=v(t.messages,e,x=>m(x));let c=W(e,t,s,o);const a=await o?.onPayload?.(c,e);a!==void 0&&(c=a);const f=await l.chat.stream(c,q(e,o));if(n.push({type:"start",partial:r}),await F(e,r,n,f),o?.signal?.aborted)throw new Error("Request was aborted");if(r.stopReason==="aborted"||r.stopReason==="error")throw new Error("An unknown error occurred");n.push({type:"done",reason:r.stopReason,message:r}),n.end()}catch(u){for(const l of r.content)delete l.partialArgs;r.stopReason=o?.signal?.aborted?"aborted":"error",r.errorMessage=z(u),n.push({type:"error",reason:r.stopReason,error:r}),n.end()}})(),n},"stream"),streamSimple=i((e,t,o)=>{const n=o?.apiKey;if(!n)throw new Error(`No API key for provider: ${e.provider}`);const r=N(e,t,o,n),u=o?.reasoning?O(e,o.reasoning):void 0,l=u==="off"?void 0:u,m=e.reasoning&&l!==void 0;return stream(e,t,{...r,promptMode:m&&Y(e)?"reasoning":void 0,reasoningEffort:m&&w(e)?Q(e,l):void 0})},"streamSimple");function U(e){return{role:"assistant",content:[],api:e.api,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()}}i(U,"createOutput");function j(){const e=new Map,t=new Map;return o=>{const n=e.get(o);if(n)return n;let r=0;for(;;){const u=I(o,r),l=t.get(u);if(!l||l===o)return e.set(o,u),t.set(u,o),u;r++}}}i(j,"createMistralToolCallIdNormalizer");function I(e,t){const o=e.replace(/[^a-zA-Z0-9]/g,"");if(t===0&&o.length===_)return o;const n=o||e,r=t===0?n:`${n}:${t}`;return D(r).replace(/[^a-zA-Z0-9]/g,"").slice(0,_)}i(I,"deriveMistralToolCallId");function z(e){if(e instanceof Error){const t=e,o=typeof t.statusCode=="number"?t.statusCode:void 0,n=typeof t.body=="string"?t.body.trim():void 0;return o!==void 0&&n?`Mistral API error (${o}): ${K(n,B)}`:o!==void 0?`Mistral API error (${o}): ${e.message}`:e.message}return J(e)}i(z,"formatMistralError");function K(e,t){return e.length<=t?e:`${e.slice(0,t)}... [truncated ${e.length-t} chars]`}i(K,"truncateErrorText");function J(e){try{const t=JSON.stringify(e);return t===void 0?String(e):t}catch{return String(e)}}i(J,"safeJsonStringify");function q(e,t){const o={retries:{strategy:"none"}};t?.signal&&(o.signal=t.signal);const n={};return e.headers&&Object.assign(n,e.headers),t?.headers&&Object.assign(n,t.headers),b(t)&&!n["x-affinity"]&&(n["x-affinity"]=t.sessionId),Object.keys(n).length>0&&(o.headers=n),o}i(q,"buildRequestOptions");function W(e,t,o,n){const r={model:e.id,stream:!0,messages:G(o,e.input.includes("image"))};return t.tools?.length&&(r.tools=Z(t.tools)),n?.temperature!==void 0&&(r.temperature=n.temperature),n?.maxTokens!==void 0&&(r.maxTokens=n.maxTokens),n?.toolChoice&&(r.toolChoice=V(n.toolChoice)),n?.promptMode&&(r.promptMode=n.promptMode),n?.reasoningEffort&&(r.reasoningEffort=n.reasoningEffort),b(n)&&(r.promptCacheKey=n.sessionId),t.systemPrompt&&r.messages.unshift({role:"system",content:y(t.systemPrompt)}),r}i(W,"buildChatPayload");function b(e){return e?.cacheRetention!=="none"&&!!e?.sessionId}i(b,"shouldUsePromptCaching");function H(e,t){const o=e,n=o.promptTokensDetails?.cachedTokens??o.prompt_tokens_details?.cached_tokens??o.promptTokenDetails?.cachedTokens??o.prompt_token_details?.cached_tokens??o.numCachedTokens??o.num_cached_tokens??0,r=typeof n=="number"&&Number.isFinite(n)?n:0;return Math.min(t,Math.max(0,r))}i(H,"getMistralCachedPromptTokens");async function F(e,t,o,n){let r=null;const u=t.content,l=i(()=>u.length-1,"blockIndex"),m=new Map,s=i(c=>{if(c){if(c.type==="text"){o.push({type:"text_end",contentIndex:l(),content:c.text,partial:t});return}c.type==="thinking"&&o.push({type:"thinking_end",contentIndex:l(),content:c.thinking,partial:t})}},"finishCurrentBlock");for await(const c of n){const a=c.data;if(t.responseId||=a.id,a.usage){const d=a.usage.promptTokens||0,g=H(a.usage,d);t.usage.input=Math.max(0,d-g),t.usage.output=a.usage.completionTokens||0,t.usage.cacheRead=g,t.usage.cacheWrite=0,t.usage.totalTokens=a.usage.totalTokens||t.usage.input+t.usage.output+t.usage.cacheRead+t.usage.cacheWrite,E(e,t.usage)}const f=a.choices[0];if(!f)continue;f.finishReason&&(t.stopReason=tt(f.finishReason));const x=f.delta;if(x.content!==null&&x.content!==void 0){const d=typeof x.content=="string"?[x.content]:x.content;for(const g of d){if(typeof g=="string"){const h=y(g);(!r||r.type!=="text")&&(s(r),r={type:"text",text:""},t.content.push(r),o.push({type:"text_start",contentIndex:l(),partial:t})),r.text+=h,o.push({type:"text_delta",contentIndex:l(),delta:h,partial:t});continue}if(g.type==="thinking"){const h=g.thinking.map(p=>"text"in p?p.text:"").filter(p=>p.length>0).join(""),k=y(h);if(!k)continue;(!r||r.type!=="thinking")&&(s(r),r={type:"thinking",thinking:""},t.content.push(r),o.push({type:"thinking_start",contentIndex:l(),partial:t})),r.thinking+=k,o.push({type:"thinking_delta",contentIndex:l(),delta:k,partial:t});continue}if(g.type==="text"){const h=y(g.text);(!r||r.type!=="text")&&(s(r),r={type:"text",text:""},t.content.push(r),o.push({type:"text_start",contentIndex:l(),partial:t})),r.text+=h,o.push({type:"text_delta",contentIndex:l(),delta:h,partial:t})}}}const A=x.toolCalls||[];for(const d of A){r&&(s(r),r=null);const g=d.id&&d.id!=="null"?d.id:I(`toolcall:${d.index??0}`,0),h=`${g}:${d.index||0}`,k=m.get(h);let p;if(k!==void 0){const M=t.content[k];M?.type==="toolCall"&&(p=M)}p||(p={type:"toolCall",id:g,name:d.function.name,arguments:{},partialArgs:""},t.content.push(p),m.set(h,t.content.length-1),o.push({type:"toolcall_start",contentIndex:t.content.length-1,partial:t}));const C=typeof d.function.arguments=="string"?d.function.arguments:JSON.stringify(d.function.arguments||{});p.partialArgs=(p.partialArgs||"")+C,p.arguments=R(p.partialArgs),o.push({type:"toolcall_delta",contentIndex:m.get(h),delta:C,partial:t})}}s(r);for(const c of m.values()){const a=t.content[c];if(a.type!=="toolCall")continue;const f=a;f.arguments=R(f.partialArgs),delete f.partialArgs,o.push({type:"toolcall_end",contentIndex:c,toolCall:f,partial:t})}}i(F,"consumeChatStream");function Z(e){return e.map(t=>{const o=L(t,!0);return{type:"function",function:{name:t.name,description:t.description,parameters:T(t.parameters),strict:o??!1}}})}i(Z,"toFunctionTools");function T(e){if(Array.isArray(e))return e.map(t=>T(t));if(e&&typeof e=="object"){const t={};for(const[o,n]of Object.entries(e))t[o]=T(n);return t}return e}i(T,"stripSymbolKeys");function G(e,t){const o=[];for(const n of e){if(n.role==="user"){if(typeof n.content=="string"){o.push({role:"user",content:y(n.content)});continue}const s=n.content.some(a=>a.type==="image"),c=n.content.filter(a=>a.type==="text"||t).map(a=>a.type==="text"?{type:"text",text:y(a.text)}:{type:"image_url",imageUrl:`data:${a.mimeType};base64,${a.data}`});if(c.length>0){o.push({role:"user",content:c});continue}s&&!t&&o.push({role:"user",content:"(image omitted: model does not support images)"});continue}if(n.role==="assistant"){const s=[],c=[];for(const f of n.content){if(f.type==="text"){f.text.trim().length>0&&s.push({type:"text",text:y(f.text)});continue}if(f.type==="thinking"){f.thinking.trim().length>0&&s.push({type:"thinking",thinking:[{type:"text",text:y(f.thinking)}]});continue}c.push({id:f.id,type:"function",function:{name:f.name,arguments:JSON.stringify(f.arguments||{})}})}const a={role:"assistant"};s.length>0&&(a.content=s),c.length>0&&(a.toolCalls=c),(s.length>0||c.length>0)&&o.push(a);continue}const r=[],u=n.content.filter(s=>s.type==="text").map(s=>s.type==="text"?y(s.text):"").join(`
|
|
2
|
+
`),l=n.content.some(s=>s.type==="image"),m=X(u,l,t,n.isError);r.push({type:"text",text:m});for(const s of n.content)t&&s.type==="image"&&r.push({type:"image_url",imageUrl:`data:${s.mimeType};base64,${s.data}`});o.push({role:"tool",toolCallId:n.toolCallId,name:n.toolName,content:r})}return o}i(G,"toChatMessages");function X(e,t,o,n){const r=e.trim(),u=n?"[tool error] ":"";return r.length>0?`${u}${r}${t&&!o?`
|
|
3
|
+
[tool image omitted: model does not support images]`:""}`:t?o?n?"[tool error] (see attached image)":"(see attached image)":n?"[tool error] (image omitted: model does not support images)":"(image omitted: model does not support images)":n?"[tool error] (no tool output)":"(no tool output)"}i(X,"buildToolResultText");function w(e){return e.id==="mistral-small-2603"||e.id==="mistral-small-latest"||e.id==="mistral-medium-3.5"}i(w,"usesReasoningEffort");function Y(e){return e.reasoning&&!w(e)}i(Y,"usesPromptModeReasoning");function Q(e,t){return e.thinkingLevelMap?.[t]??"high"}i(Q,"mapReasoningEffort");function V(e){if(e)return e==="auto"||e==="none"||e==="any"||e==="required"?e:{type:"function",function:{name:e.function.name}}}i(V,"mapToolChoice");function tt(e){if(e===null)return"stop";switch(e){case"stop":return"stop";case"length":case"model_length":return"length";case"tool_calls":return"toolUse";case"error":return"error";default:return"stop"}}i(tt,"mapChatStopReason");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var me=Object.defineProperty;var o=(e,r)=>me(e,"name",{value:r,configurable:!0});function ye(){return typeof process>"u"||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.("node:os")??null}o(ye,"loadNodeOs");const q=ye();import{clampThinkingLevel as be}from"../models.js";import{registerSessionResourceCleanup as we}from"../session-resources.js";import{combineAbortSignals as he}from"../utils/abort-signals.js";import{splitDeferredTools as Ee}from"../utils/deferred-tools.js";import{appendAssistantMessageDiagnostic as Se,createAssistantMessageDiagnostic as ge,formatThrownValue as $}from"../utils/diagnostics.js";import{formatProviderError as _e,normalizeProviderError as ke}from"../utils/error-body.js";import{AssistantMessageEventStream as Te}from"../utils/event-stream.js";import{headersToRecord as K}from"../utils/headers.js";import{resolveHttpProxyUrlForTarget as Re}from"../utils/node-http-proxy.js";import{uuidv7 as xe}from"../utils/uuid.js";import{createGrammarToolInputProperties as G}from"./constrained-sampling.js";import{clampOpenAIPromptCacheKey as Ce}from"./openai-prompt-cache.js";import{convertResponsesMessages as j,convertResponsesTools as ve,processResponsesStream as V}from"./openai-responses-shared.js";import{buildBaseOptions as Oe}from"./simple-options.js";const Ae="https://chatgpt.com/backend-api",We="https://api.openai.com/auth",Le=0,X=1e3,Me=6e4,De=15e3,Ne=3,Y=new Set(["openai","openai-codex","opencode"]),Ie=1009,qe="websocket_connection_limit_reached",Be="previous_response_not_found",Pe=new Set(["completed","incomplete","failed","cancelled","queued","in_progress"]);function Z(e){if(e.stopReason==="pending")throw new Error("Codex stream ended without a stop reason");if(e.stopReason==="error"||e.stopReason==="aborted")throw new Error(e.errorMessage||"An unknown error occurred")}o(Z,"assertSuccessfulOutput");function Fe(e){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(e)}o(Fe,"isTerminalRateLimitError");function $e(e,r){return e===429&&Fe(r)?!1:e===429||e===500||e===502||e===503||e===504?!0:/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(r)}o($e,"isRetryableError");function Ue(e){const r=e.get("retry-after-ms");if(r!==null){const a=Number(r);if(Number.isFinite(a))return Math.max(0,a)}const t=e.get("retry-after");if(!t)return;const n=Number(t);if(Number.isFinite(n))return Math.max(0,n*1e3);const s=Date.parse(t);if(!Number.isNaN(s))return Math.max(0,s-Date.now())}o(Ue,"getRetryAfterDelayMs");class Q extends Error{static{o(this,"RetryDelayExceededError")}}function Je(e,r){const t=r?.maxRetryDelayMs??Me;if(t>0&&e>t)throw new Q(`Server requested ${Math.ceil(e/1e3)}s retry delay (max: ${Math.ceil(t/1e3)}s)`);return e}o(Je,"validateRetryDelayMs");function ee(e,r){return new Promise((t,n)=>{if(r?.aborted){n(new Error("Request was aborted"));return}const s=setTimeout(t,e);r?.addEventListener("abort",()=>{clearTimeout(s),n(new Error("Request was aborted"))})})}o(ee,"sleep");function te(e){if(e!==void 0){if(!Number.isFinite(e)||e<0)throw new Error(`Invalid timeoutMs: ${String(e)}`);return Math.floor(e)}}o(te,"normalizeTimeoutMs");function ze(){return typeof process>"u"||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.("node:zlib")??null}o(ze,"loadNodeZlib");function He(e){const r=ze();if(!r||typeof r.zstdCompressSync!="function")return null;try{const t=r.zstdCompressSync(e,{params:{[r.constants.ZSTD_c_compressionLevel]:Ne}});return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}catch{return null}}o(He,"compressRequestBodyZstd");export const stream=o((e,r,t)=>{const n=new Te;return(async()=>{const s={role:"assistant",content:[],api:"openai-codex-responses",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{const a=t?.apiKey;if(!a)throw new Error(`No API key for provider: ${e.provider}`);const i=St(a),f=G(r.tools,e.compat?.supportsOpenAIGrammarTools??!1),c=t?.cacheRetention==="none"?void 0:t?.sessionId,u=Ce(c);let p=Ke(e,r,t,u,f);const d=await t?.onPayload?.(p,e);d!==void 0&&(p=d);const S=u||xe(),l=gt(e.headers,t?.headers,i,a,u),g=_t(e.headers,t?.headers,i,a,S),y=JSON.stringify(p),m=te(t?.timeoutMs),C=te(t?.websocketConnectTimeoutMs),b=t?.transport||"auto";let h=!1;const w=b!=="sse"&&ae(c);if(w&&ie(c),b!=="sse"&&!w){let E=!1,k=!1,O=!1;for(;;){E=!1;try{if(await ht(je(e.baseUrl),p,g,s,n,e,()=>{E=!0,h||(h=!0,n.push({type:"start",partial:s}))},m,C,c,f,t),t?.signal?.aborted)throw new Error("Request was aborted");Z(s),n.push({type:"done",reason:s.stopReason,message:s}),n.end();return}catch(R){const M=t?.signal?.aborted,D=!E&&Ye(R),W=Ze(R);if(!M&&W&&!O){O=!0;continue}if(!M&&D&&!k){k=!0;continue}if(M||Xe(R)&&!D||(Se(s,ge("provider_transport_failure",R,{configuredTransport:b,fallbackTransport:E?void 0:"sse",eventsEmitted:E,phase:E?"after_message_stream_start":"before_message_stream_start",requestBytes:new TextEncoder().encode(y).byteLength})),st(c,R),E))throw R;ie(c);break}}}const v=He(y);v&&l.set("content-encoding","zstd");const A=v??y;let _,L;const F=t?.maxRetries??Le;for(let E=0;E<=F;E++){if(t?.signal?.aborted)throw new Error("Request was aborted");try{const k=m!==void 0&&m>0?AbortSignal.timeout(m):void 0,O=he([t?.signal,k]);try{_=await(t?.fetch??globalThis.fetch)(oe(e.baseUrl),{method:"POST",headers:l,body:A,signal:O.signal})}catch(W){throw k?.aborted&&!t?.signal?.aborted?new Error(`Codex SSE response headers timed out after ${m}ms`):W}finally{O.cleanup()}if(await t?.onResponse?.({status:_.status,headers:K(_.headers)},e),_.ok)break;const R=await _.text();if(E<F&&$e(_.status,R)){const W=Ue(_.headers),pe=W===void 0?X*2**E:Je(W,t);await ee(pe,t?.signal);continue}const M=new Response(R,{status:_.status,statusText:_.statusText}),D=await Et(M);throw new Error(D.friendlyMessage||D.message)}catch(k){if(k instanceof Error&&(k.name==="AbortError"||k.message==="Request was aborted"))throw new Error("Request was aborted");if(L=k instanceof Error?k:new Error(String(k)),E<F&&!(L instanceof Q)&&!L.message.includes("usage limit")){const O=X*2**E;await ee(O,t?.signal);continue}throw L}}if(!_?.ok)throw L??new Error("Failed after retries");if(!_.body)throw new Error("No response body");if(h||(h=!0,n.push({type:"start",partial:s})),await Ve(_,s,n,e,f,t),t?.signal?.aborted)throw new Error("Request was aborted");Z(s),n.push({type:"done",reason:s.stopReason,message:s}),n.end()}catch(a){for(const i of s.content)delete i.partialJson,delete i.customInput;s.stopReason=t?.signal?.aborted?"aborted":"error",s.errorMessage=_e(ke(a)),n.push({type:"error",reason:s.stopReason,error:s}),n.end()}})(),n},"stream"),streamSimple=o((e,r,t)=>{const n=t?.apiKey;if(!n)throw new Error(`No API key for provider: ${e.provider}`);const s=Oe(e,r,t,n),a=t?.reasoning?be(e,t.reasoning):void 0;return stream(e,r,{...s,reasoningEffort:a==="off"?void 0:a})},"streamSimple");function Ke(e,r,t,n,s=G(r.tools,e.compat?.supportsOpenAIGrammarTools??!1)){const a=e.compat?.supportsStrictMode??!0,i=e.compat?.supportsOpenAIGrammarTools??!1,f=Ee(r,e.compat?.supportsToolSearch??!1),c=j(e,r,Y,{includeSystemPrompt:!1,grammarToolInputProperties:s,deferredTools:f.deferred,toolOptions:{strict:null,supportsStrictMode:a,supportsOpenAIGrammarTools:i}}),u={model:e.id,store:!1,stream:!0,instructions:r.systemPrompt||"You are a helpful assistant.",input:c,text:{verbosity:t?.textVerbosity||"low"},include:["reasoning.encrypted_content"],prompt_cache_key:n,tool_choice:t?.toolChoice??"auto",parallel_tool_calls:!0};if(t?.temperature!==void 0&&(u.temperature=t.temperature),t?.serviceTier!==void 0&&(u.service_tier=t.serviceTier),f.immediate.length>0&&(u.tools=ve(f.immediate,{strict:null,supportsStrictMode:a,supportsOpenAIGrammarTools:i})),t?.reasoningEffort!==void 0){const p=t.reasoningEffort==="none"?e.thinkingLevelMap?.off??"none":e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort;p!==null&&(u.reasoning={effort:p,summary:t.reasoningSummary??"auto"})}return u}o(Ke,"buildRequestBody");function Ge(e,r){switch(r){case"flex":return .5;case"priority":return e.id==="gpt-5.5"?2.5:2;default:return 1}}o(Ge,"getServiceTierCostMultiplier");function re(e,r,t){const n=Ge(t,r);n!==1&&(e.cost.input*=n,e.cost.output*=n,e.cost.cacheRead*=n,e.cost.cacheWrite*=n,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}o(re,"applyServiceTierPricing");function ne(e,r){return e==="default"&&(r==="flex"||r==="priority")?r:e??r}o(ne,"resolveCodexServiceTier");function oe(e){const t=(e&&e.trim().length>0?e:Ae).replace(/\/+$/,"");return t.endsWith("/codex/responses")?t:t.endsWith("/codex")?`${t}/responses`:`${t}/codex/responses`}o(oe,"resolveCodexUrl");function je(e){const r=new URL(oe(e));return r.protocol==="https:"&&(r.protocol="wss:"),r.protocol==="http:"&&(r.protocol="ws:"),r.toString()}o(je,"resolveCodexWebSocketUrl");async function Ve(e,r,t,n,s,a){await V(se(tt(e,a?.signal)),r,t,n,{serviceTier:a?.serviceTier,grammarToolInputProperties:s,resolveServiceTier:ne,applyServiceTierPricing:o((i,f)=>re(i,f,n),"applyServiceTierPricing")})}o(Ve,"processStream");class N extends Error{static{o(this,"CodexApiError")}code;payload;constructor(r,t){super(r),this.name="CodexApiError",this.code=t?.code,this.payload=t?.payload,this.cause=t?.cause}}class U extends Error{static{o(this,"CodexProtocolError")}payload;constructor(r,t){super(r),this.name="CodexProtocolError",this.payload=t?.payload,this.cause=t?.cause}}function Xe(e){return e instanceof N||e instanceof U}o(Xe,"isCodexNonTransportError");function Ye(e){return e instanceof N&&e.code===qe}o(Ye,"isWebSocketConnectionLimitReachedError");function Ze(e){return e instanceof N&&e.code===Be}o(Ze,"isPreviousResponseNotFoundError");function Qe(e){const r=e.error&&typeof e.error=="object"?e.error:void 0;return{code:typeof e.code=="string"?e.code:typeof r?.code=="string"?r.code:void 0,message:typeof e.message=="string"?e.message:typeof r?.message=="string"?r.message:void 0}}o(Qe,"extractCodexEventError");async function*se(e){for await(const r of e){const t=typeof r.type=="string"?r.type:void 0;if(t){if(t==="error"){const{code:n,message:s}=Qe(r);throw new N(`Codex error: ${s||n||JSON.stringify(r)}`,{code:n,payload:r})}if(t==="response.failed"){const n=r.response,s=n?.error?.code,a=n?.error?.message;throw new N(a||"Codex response failed",{code:s,payload:r})}if(t==="response.done"||t==="response.completed"||t==="response.incomplete"){const n=r.response,s=n&&{...n,status:et(n.status)};yield{...r,type:"response.completed",response:s};return}yield r}}}o(se,"mapCodexEvents");function et(e){if(typeof e=="string")return Pe.has(e)?e:void 0}o(et,"normalizeCodexStatus");async function*tt(e,r){if(!e.body)return;const t=e.body.getReader(),n=new TextDecoder;let s="";const a=o(()=>{t.cancel().catch(()=>{})},"onAbort");r?.addEventListener("abort",a,{once:!0});try{for(;;){if(r?.aborted)throw new Error("Request was aborted");const{done:i,value:f}=await t.read();if(r?.aborted)throw new Error("Request was aborted");if(i)break;s+=n.decode(f,{stream:!0});let c=s.indexOf(`
|
|
1
|
+
var pe=Object.defineProperty;var o=(e,r)=>pe(e,"name",{value:r,configurable:!0});function me(){return typeof process>"u"||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.("node:os")??null}o(me,"loadNodeOs");const q=me();import{clampThinkingLevel as ye}from"../models.js";import{registerSessionResourceCleanup as be}from"../session-resources.js";import{combineAbortSignals as we}from"../utils/abort-signals.js";import{splitDeferredTools as he}from"../utils/deferred-tools.js";import{appendAssistantMessageDiagnostic as Ee,createAssistantMessageDiagnostic as Se,formatThrownValue as $}from"../utils/diagnostics.js";import{formatProviderError as ge,normalizeProviderError as _e}from"../utils/error-body.js";import{AssistantMessageEventStream as ke}from"../utils/event-stream.js";import{headersToRecord as K}from"../utils/headers.js";import{resolveHttpProxyUrlForTarget as Te}from"../utils/node-http-proxy.js";import{uuidv7 as Re}from"../utils/uuid.js";import{createGrammarToolInputProperties as G}from"./constrained-sampling.js";import{clampOpenAIPromptCacheKey as xe}from"./openai-prompt-cache.js";import{convertResponsesMessages as j,convertResponsesTools as Ce,processResponsesStream as V}from"./openai-responses-shared.js";import{buildBaseOptions as ve}from"./simple-options.js";const Oe="https://chatgpt.com/backend-api",Ae="https://api.openai.com/auth",We=0,X=1e3,Le=6e4,De=15e3,Me=3,Y=new Set(["openai","openai-codex","opencode"]),Ne=1009,Ie="websocket_connection_limit_reached",qe="previous_response_not_found",Be=new Set(["completed","incomplete","failed","cancelled","queued","in_progress"]);function Pe(e){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(e)}o(Pe,"isTerminalRateLimitError");function Fe(e,r){return e===429&&Pe(r)?!1:e===429||e===500||e===502||e===503||e===504?!0:/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(r)}o(Fe,"isRetryableError");function $e(e){const r=e.get("retry-after-ms");if(r!==null){const s=Number(r);if(Number.isFinite(s))return Math.max(0,s)}const t=e.get("retry-after");if(!t)return;const n=Number(t);if(Number.isFinite(n))return Math.max(0,n*1e3);const a=Date.parse(t);if(!Number.isNaN(a))return Math.max(0,a-Date.now())}o($e,"getRetryAfterDelayMs");class Z extends Error{static{o(this,"RetryDelayExceededError")}}function Ue(e,r){const t=r?.maxRetryDelayMs??Le;if(t>0&&e>t)throw new Z(`Server requested ${Math.ceil(e/1e3)}s retry delay (max: ${Math.ceil(t/1e3)}s)`);return e}o(Ue,"validateRetryDelayMs");function Q(e,r){return new Promise((t,n)=>{if(r?.aborted){n(new Error("Request was aborted"));return}const a=setTimeout(t,e);r?.addEventListener("abort",()=>{clearTimeout(a),n(new Error("Request was aborted"))})})}o(Q,"sleep");function ee(e){if(e!==void 0){if(!Number.isFinite(e)||e<0)throw new Error(`Invalid timeoutMs: ${String(e)}`);return Math.floor(e)}}o(ee,"normalizeTimeoutMs");function Je(){return typeof process>"u"||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.("node:zlib")??null}o(Je,"loadNodeZlib");function ze(e){const r=Je();if(!r||typeof r.zstdCompressSync!="function")return null;try{const t=r.zstdCompressSync(e,{params:{[r.constants.ZSTD_c_compressionLevel]:Me}});return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}catch{return null}}o(ze,"compressRequestBodyZstd");export const stream=o((e,r,t)=>{const n=new ke;return(async()=>{const a={role:"assistant",content:[],api:"openai-codex-responses",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{const s=t?.apiKey;if(!s)throw new Error(`No API key for provider: ${e.provider}`);const i=Et(s),f=G(r.tools,e.compat?.supportsOpenAIGrammarTools??!1),c=t?.cacheRetention==="none"?void 0:t?.sessionId,u=xe(c);let p=He(e,r,t,u,f);const d=await t?.onPayload?.(p,e);d!==void 0&&(p=d);const S=u||Re(),l=St(e.headers,t?.headers,i,s,u),g=gt(e.headers,t?.headers,i,s,S),y=JSON.stringify(p),m=ee(t?.timeoutMs),C=ee(t?.websocketConnectTimeoutMs),b=t?.transport||"auto";let h=!1;const w=b!=="sse"&&se(c);if(w&&ae(c),b!=="sse"&&!w){let E=!1,k=!1,O=!1;for(;;){E=!1;try{if(await wt(Ge(e.baseUrl),p,g,a,n,e,()=>{E=!0,h||(h=!0,n.push({type:"start",partial:a}))},m,C,c,f,t),t?.signal?.aborted)throw new Error("Request was aborted");n.push({type:"done",reason:a.stopReason,message:a}),n.end();return}catch(R){const D=t?.signal?.aborted,M=!E&&Xe(R),W=Ye(R);if(!D&&W&&!O){O=!0;continue}if(!D&&M&&!k){k=!0;continue}if(D||Ve(R)&&!M||(Ee(a,Se("provider_transport_failure",R,{configuredTransport:b,fallbackTransport:E?void 0:"sse",eventsEmitted:E,phase:E?"after_message_stream_start":"before_message_stream_start",requestBytes:new TextEncoder().encode(y).byteLength})),ot(c,R),E))throw R;ae(c);break}}}const v=ze(y);v&&l.set("content-encoding","zstd");const A=v??y;let _,L;const F=t?.maxRetries??We;for(let E=0;E<=F;E++){if(t?.signal?.aborted)throw new Error("Request was aborted");try{const k=m!==void 0&&m>0?AbortSignal.timeout(m):void 0,O=we([t?.signal,k]);try{_=await fetch(ne(e.baseUrl),{method:"POST",headers:l,body:A,signal:O.signal})}catch(W){throw k?.aborted&&!t?.signal?.aborted?new Error(`Codex SSE response headers timed out after ${m}ms`):W}finally{O.cleanup()}if(await t?.onResponse?.({status:_.status,headers:K(_.headers)},e),_.ok)break;const R=await _.text();if(E<F&&Fe(_.status,R)){const W=$e(_.headers),fe=W===void 0?X*2**E:Ue(W,t);await Q(fe,t?.signal);continue}const D=new Response(R,{status:_.status,statusText:_.statusText}),M=await ht(D);throw new Error(M.friendlyMessage||M.message)}catch(k){if(k instanceof Error&&(k.name==="AbortError"||k.message==="Request was aborted"))throw new Error("Request was aborted");if(L=k instanceof Error?k:new Error(String(k)),E<F&&!(L instanceof Z)&&!L.message.includes("usage limit")){const O=X*2**E;await Q(O,t?.signal);continue}throw L}}if(!_?.ok)throw L??new Error("Failed after retries");if(!_.body)throw new Error("No response body");if(h||(h=!0,n.push({type:"start",partial:a})),await je(_,a,n,e,f,t),t?.signal?.aborted)throw new Error("Request was aborted");n.push({type:"done",reason:a.stopReason,message:a}),n.end()}catch(s){for(const i of a.content)delete i.partialJson,delete i.customInput;a.stopReason=t?.signal?.aborted?"aborted":"error",a.errorMessage=ge(_e(s)),n.push({type:"error",reason:a.stopReason,error:a}),n.end()}})(),n},"stream"),streamSimple=o((e,r,t)=>{const n=t?.apiKey;if(!n)throw new Error(`No API key for provider: ${e.provider}`);const a=ve(e,r,t,n),s=t?.reasoning?ye(e,t.reasoning):void 0;return stream(e,r,{...a,reasoningEffort:s==="off"?void 0:s})},"streamSimple");function He(e,r,t,n,a=G(r.tools,e.compat?.supportsOpenAIGrammarTools??!1)){const s=e.compat?.supportsStrictMode??!0,i=e.compat?.supportsOpenAIGrammarTools??!1,f=he(r,e.compat?.supportsToolSearch??!1),c=j(e,r,Y,{includeSystemPrompt:!1,grammarToolInputProperties:a,deferredTools:f.deferred,toolOptions:{strict:null,supportsStrictMode:s,supportsOpenAIGrammarTools:i}}),u={model:e.id,store:!1,stream:!0,instructions:r.systemPrompt||"You are a helpful assistant.",input:c,text:{verbosity:t?.textVerbosity||"low"},include:["reasoning.encrypted_content"],prompt_cache_key:n,tool_choice:t?.toolChoice??"auto",parallel_tool_calls:!0};if(t?.temperature!==void 0&&(u.temperature=t.temperature),t?.serviceTier!==void 0&&(u.service_tier=t.serviceTier),f.immediate.length>0&&(u.tools=Ce(f.immediate,{strict:null,supportsStrictMode:s,supportsOpenAIGrammarTools:i})),t?.reasoningEffort!==void 0){const p=t.reasoningEffort==="none"?e.thinkingLevelMap?.off??"none":e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort;p!==null&&(u.reasoning={effort:p,summary:t.reasoningSummary??"auto"})}return u}o(He,"buildRequestBody");function Ke(e,r){switch(r){case"flex":return .5;case"priority":return e.id==="gpt-5.5"?2.5:2;default:return 1}}o(Ke,"getServiceTierCostMultiplier");function te(e,r,t){const n=Ke(t,r);n!==1&&(e.cost.input*=n,e.cost.output*=n,e.cost.cacheRead*=n,e.cost.cacheWrite*=n,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}o(te,"applyServiceTierPricing");function re(e,r){return e==="default"&&(r==="flex"||r==="priority")?r:e??r}o(re,"resolveCodexServiceTier");function ne(e){const t=(e&&e.trim().length>0?e:Oe).replace(/\/+$/,"");return t.endsWith("/codex/responses")?t:t.endsWith("/codex")?`${t}/responses`:`${t}/codex/responses`}o(ne,"resolveCodexUrl");function Ge(e){const r=new URL(ne(e));return r.protocol==="https:"&&(r.protocol="wss:"),r.protocol==="http:"&&(r.protocol="ws:"),r.toString()}o(Ge,"resolveCodexWebSocketUrl");async function je(e,r,t,n,a,s){await V(oe(et(e,s?.signal)),r,t,n,{serviceTier:s?.serviceTier,grammarToolInputProperties:a,resolveServiceTier:re,applyServiceTierPricing:o((i,f)=>te(i,f,n),"applyServiceTierPricing")})}o(je,"processStream");class N extends Error{static{o(this,"CodexApiError")}code;payload;constructor(r,t){super(r),this.name="CodexApiError",this.code=t?.code,this.payload=t?.payload,this.cause=t?.cause}}class U extends Error{static{o(this,"CodexProtocolError")}payload;constructor(r,t){super(r),this.name="CodexProtocolError",this.payload=t?.payload,this.cause=t?.cause}}function Ve(e){return e instanceof N||e instanceof U}o(Ve,"isCodexNonTransportError");function Xe(e){return e instanceof N&&e.code===Ie}o(Xe,"isWebSocketConnectionLimitReachedError");function Ye(e){return e instanceof N&&e.code===qe}o(Ye,"isPreviousResponseNotFoundError");function Ze(e){const r=e.error&&typeof e.error=="object"?e.error:void 0;return{code:typeof e.code=="string"?e.code:typeof r?.code=="string"?r.code:void 0,message:typeof e.message=="string"?e.message:typeof r?.message=="string"?r.message:void 0}}o(Ze,"extractCodexEventError");async function*oe(e){for await(const r of e){const t=typeof r.type=="string"?r.type:void 0;if(t){if(t==="error"){const{code:n,message:a}=Ze(r);throw new N(`Codex error: ${a||n||JSON.stringify(r)}`,{code:n,payload:r})}if(t==="response.failed"){const n=r.response,a=n?.error?.code,s=n?.error?.message;throw new N(s||"Codex response failed",{code:a,payload:r})}if(t==="response.done"||t==="response.completed"||t==="response.incomplete"){const n=r.response,a=n&&{...n,status:Qe(n.status)};yield{...r,type:"response.completed",response:a};return}yield r}}}o(oe,"mapCodexEvents");function Qe(e){if(typeof e=="string")return Be.has(e)?e:void 0}o(Qe,"normalizeCodexStatus");async function*et(e,r){if(!e.body)return;const t=e.body.getReader(),n=new TextDecoder;let a="";const s=o(()=>{t.cancel().catch(()=>{})},"onAbort");r?.addEventListener("abort",s,{once:!0});try{for(;;){if(r?.aborted)throw new Error("Request was aborted");const{done:i,value:f}=await t.read();if(r?.aborted)throw new Error("Request was aborted");if(i)break;a+=n.decode(f,{stream:!0});let c=a.indexOf(`
|
|
2
2
|
|
|
3
|
-
`);for(;c!==-1;){const u=
|
|
3
|
+
`);for(;c!==-1;){const u=a.slice(0,c);a=a.slice(c+2);const p=u.split(`
|
|
4
4
|
`).filter(d=>d.startsWith("data:")).map(d=>d.slice(5).trim());if(p.length>0){const d=p.join(`
|
|
5
|
-
`).trim();if(d&&d!=="[DONE]")try{yield JSON.parse(d)}catch(S){throw new U(`Invalid Codex SSE JSON: ${$(S)}`,{cause:S,payload:d})}}c=
|
|
5
|
+
`).trim();if(d&&d!=="[DONE]")try{yield JSON.parse(d)}catch(S){throw new U(`Invalid Codex SSE JSON: ${$(S)}`,{cause:S,payload:d})}}c=a.indexOf(`
|
|
6
6
|
|
|
7
|
-
`)}}}finally{r?.removeEventListener("abort",a);try{await t.cancel()}catch{}try{t.releaseLock()}catch{}}}o(tt,"parseSSE");const rt="responses_websockets=2026-02-06",nt=300*1e3,ot=3300*1e3,T=new Map,I=new Map,B=new Set;function J(e){let r=I.get(e);return r||(r={requests:0,connectionsCreated:0,connectionsReused:0,cachedContextRequests:0,storeTrueRequests:0,fullContextRequests:0,deltaRequests:0,lastInputItems:0,websocketFailures:0,sseFallbacks:0},I.set(e,r)),r}o(J,"getOrCreateWebSocketDebugStats");export function getOpenAICodexWebSocketDebugStats(e){const r=I.get(e);return r?{...r}:void 0}o(getOpenAICodexWebSocketDebugStats,"getOpenAICodexWebSocketDebugStats");export function resetOpenAICodexWebSocketDebugStats(e){if(e){I.delete(e),B.delete(e);return}I.clear(),B.clear()}o(resetOpenAICodexWebSocketDebugStats,"resetOpenAICodexWebSocketDebugStats");export function closeOpenAICodexWebSocketSessions(e){const r=o(t=>{t.idleTimer&&clearTimeout(t.idleTimer),x(t.socket,1e3,"debug_close")},"closeEntry");if(e){const t=T.get(e);t&&r(t),T.delete(e);return}for(const t of T.values())r(t);T.clear()}o(closeOpenAICodexWebSocketSessions,"closeOpenAICodexWebSocketSessions"),we(closeOpenAICodexWebSocketSessions);function ae(e){return e?B.has(e):!1}o(ae,"isWebSocketSseFallbackActive");function ie(e){if(!e)return;const r=J(e);r.sseFallbacks++,r.websocketFallbackActive=ae(e)}o(ie,"recordWebSocketSseFallback");function st(e,r){if(!e)return;B.add(e);const t=J(e);t.websocketFailures++,t.lastWebSocketError=$(r),t.websocketFallbackActive=!0}o(st,"recordWebSocketFailure");let z=null;async function at(e){if(!e&&z)return z;if(typeof process<"u"&&process.versions?.bun){const t=class extends WebSocket{static{o(this,"WebSocketWithProxy")}constructor(n,s){let a={};Array.isArray(s)||typeof s=="string"?a={protocols:s}:a={...s};const i=Re(n.toString().replace(/^wss:/,"https:").replace(/^ws:/,"http:"),e);super(n,{...a,...i?{proxy:i.toString()}:{}})}};return e||(z=t),t}const r=globalThis.WebSocket;return typeof r!="function"?null:r}o(at,"getWebSocketConstructor");class it extends Error{static{o(this,"WebSocketCloseError")}code;reason;wasClean;constructor(r,t){super(r),this.name="WebSocketCloseError",this.code=t?.code,this.reason=t?.reason,this.wasClean=t?.wasClean}}function ct(e){const r=e.readyState;return typeof r=="number"?r:void 0}o(ct,"getWebSocketReadyState");function P(e){const r=ct(e);return r===void 0||r===1}o(P,"isWebSocketReusable");function ut(e){return Date.now()-e.createdAt>=ot}o(ut,"isWebSocketSessionExpired");function x(e,r=1e3,t="done"){try{e.close(r,t)}catch{}}o(x,"closeWebSocketSilently");function ce(e,r){r.idleTimer&&clearTimeout(r.idleTimer),r.idleTimer=setTimeout(()=>{r.busy||(x(r.socket,1e3,"idle_timeout"),T.delete(e))},nt)}o(ce,"scheduleSessionWebSocketExpiry");async function H(e,r,t,n=De,s){const a=await at(s);if(!a)throw new Error("WebSocket transport is not available in this runtime");const i=K(r);return delete i["OpenAI-Beta"],new Promise((f,c)=>{let u=!1,p,d;try{d=new a(e,{headers:i})}catch(b){c(b instanceof Error?b:new Error(String(b)));return}const S=o(()=>{p&&(clearTimeout(p),p=void 0),d.removeEventListener("open",g),d.removeEventListener("error",y),d.removeEventListener("close",m),t?.removeEventListener("abort",C)},"cleanup"),l=o((b,h)=>{u||(u=!0,S(),h&&x(d,1e3,h),c(b))},"fail"),g=o(()=>{u||(u=!0,S(),f(d))},"onOpen"),y=o(b=>{l(ue(b))},"onError"),m=o(b=>{l(de(b))},"onClose"),C=o(()=>{l(new Error("Request was aborted"),"aborted")},"onAbort");d.addEventListener("open",g),d.addEventListener("error",y),d.addEventListener("close",m),t?.addEventListener("abort",C),n>0&&(p=setTimeout(()=>{l(new Error(`WebSocket connect timeout after ${n}ms`),"connect_timeout")},n)),t?.aborted&&C()})}o(H,"connectWebSocket");async function dt(e,r,t,n,s,a){if(!t){const u=await H(e,r,n,s,a);return{socket:u,reused:!1,release:o(()=>x(u),"release")}}const i=T.get(t);if(i){if(i.idleTimer&&(clearTimeout(i.idleTimer),i.idleTimer=void 0),!i.busy&&ut(i))x(i.socket,1e3,"connection_age_limit"),T.delete(t);else if(!i.busy&&P(i.socket))return i.busy=!0,{socket:i.socket,entry:i,reused:!0,release:o(({keep:u}={})=>{if(!u||!P(i.socket)){x(i.socket),T.delete(t);return}i.busy=!1,ce(t,i)},"release")};if(i.busy){const u=await H(e,r,n,s,a);return{socket:u,reused:!1,release:o(()=>{x(u)},"release")}}P(i.socket)||(x(i.socket),T.delete(t))}const f=await H(e,r,n,s,a),c={socket:f,busy:!0,createdAt:Date.now()};return T.set(t,c),{socket:f,entry:c,reused:!1,release:o(({keep:u}={})=>{if(!u||!P(c.socket)){x(c.socket),c.idleTimer&&clearTimeout(c.idleTimer),T.get(t)===c&&T.delete(t);return}c.busy=!1,ce(t,c)},"release")}}o(dt,"acquireWebSocket");function ue(e){if(e&&typeof e=="object"){const r="message"in e?e.message:void 0;if(typeof r=="string"&&r.length>0)return new Error(r);const t="error"in e?e.error:void 0;if(t instanceof Error&&t.message.length>0)return t;if(t&&typeof t=="object"&&"message"in t){const n=t.message;if(typeof n=="string"&&n.length>0)return new Error(n)}}return new Error("WebSocket error")}o(ue,"extractWebSocketError");function de(e){if(e&&typeof e=="object"){const r="code"in e?e.code:void 0,t="reason"in e?e.reason:void 0,n="wasClean"in e?e.wasClean:void 0,s=typeof r=="number"?` ${r}`:"";let a=typeof t=="string"&&t.length>0?` ${t}`:"";return!a&&r===Ie&&(a=" message too big"),new it(`WebSocket closed${s}${a}`.trim(),{code:typeof r=="number"?r:void 0,reason:typeof t=="string"&&t.length>0?t:void 0,wasClean:typeof n=="boolean"?n:void 0})}return new Error("WebSocket closed")}o(de,"extractWebSocketCloseError");async function lt(e){if(typeof e=="string")return e;if(e instanceof ArrayBuffer)return new TextDecoder().decode(new Uint8Array(e));if(ArrayBuffer.isView(e)){const r=e;return new TextDecoder().decode(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}if(e&&typeof e=="object"&&"arrayBuffer"in e){const t=await e.arrayBuffer();return new TextDecoder().decode(new Uint8Array(t))}return null}o(lt,"decodeWebSocketData");async function*ft(e,r,t){const n=[];let s=null,a=!1,i=null,f=!1;const c=o(()=>{if(!s)return;const l=s;s=null,l()},"wake"),u=o(l=>{(async()=>{let g=null;try{if(!l||typeof l!="object"||!("data"in l)||(g=await lt(l.data),!g))return;const y=JSON.parse(g),m=typeof y.type=="string"?y.type:"";(m==="response.completed"||m==="response.done"||m==="response.incomplete")&&(f=!0,a=!0),n.push(y),c()}catch(y){i=new U(`Invalid Codex WebSocket JSON: ${$(y)}`,{cause:y,payload:g}),a=!0,c()}})()},"onMessage"),p=o(l=>{i=ue(l),a=!0,c()},"onError"),d=o(l=>{if(f){a=!0,c();return}i||(i=de(l)),a=!0,c()},"onClose"),S=o(()=>{i=new Error("Request was aborted"),a=!0,c()},"onAbort");e.addEventListener("message",u),e.addEventListener("error",p),e.addEventListener("close",d),r?.addEventListener("abort",S);try{for(;;){if(r?.aborted)throw new Error("Request was aborted");if(n.length>0){yield n.shift();continue}if(a)break;let l;await new Promise((g,y)=>{s=g,t!==void 0&&t>0&&(l=setTimeout(()=>{const m=new Error(`WebSocket idle timeout after ${t}ms`);i=m,a=!0,s=null,x(e,1e3,"idle_timeout"),y(m)},t))}).finally(()=>{l&&clearTimeout(l)})}if(i)throw i;if(!f)throw new Error("WebSocket stream closed before response.completed")}finally{e.removeEventListener("message",u),e.removeEventListener("error",p),e.removeEventListener("close",d),r?.removeEventListener("abort",S)}}o(ft,"parseWebSocket");function le(e){const{input:r,previous_response_id:t,...n}=e;return n}o(le,"requestBodyWithoutInput");function pt(e,r){return JSON.stringify(e??[])===JSON.stringify(r??[])}o(pt,"responseInputsEqual");function mt(e,r){return JSON.stringify(le(e))===JSON.stringify(le(r))}o(mt,"requestBodiesMatchExceptInput");function yt(e,r){if(!mt(e,r.lastRequestBody))return;const t=e.input??[],n=[...r.lastRequestBody.input??[],...r.lastResponseItems];if(t.length<n.length)return;const s=t.slice(0,n.length);if(pt(s,n))return t.slice(n.length)}o(yt,"getCachedWebSocketInputDelta");function bt(e,r){const t=e.continuation;if(!t)return r;const n=yt(r,t);return!n||!t.lastResponseId?(e.continuation=void 0,r):{...r,previous_response_id:t.lastResponseId,input:n}}o(bt,"buildCachedWebSocketRequestBody");async function*wt(e,r){let t=!1;for await(const n of e)t||(t=!0,r()),yield n}o(wt,"startWebSocketOutputOnFirstEvent");async function ht(e,r,t,n,s,a,i,f,c,u,p,d){const{socket:S,entry:l,reused:g,release:y}=await dt(e,t,u,d?.signal,c,d?.env);let m=!0;const C=d?.transport==="websocket-cached"||d?.transport==="auto",b=r,h=C&&l?bt(l,b):b,w=u?J(u):void 0;w&&(w.requests++,g?w.connectionsReused++:w.connectionsCreated++,C&&w.cachedContextRequests++,h.store===!0&&w.storeTrueRequests++,w.lastInputItems=h.input?.length??0,h.previous_response_id?(w.deltaRequests++,w.lastDeltaInputItems=h.input?.length??0,w.lastPreviousResponseId=h.previous_response_id):(w.fullContextRequests++,w.lastDeltaInputItems=void 0,w.lastPreviousResponseId=void 0));try{if(S.send(JSON.stringify({type:"response.create",...h})),await V(wt(se(ft(S,d?.signal,f)),i),n,s,a,{serviceTier:d?.serviceTier,grammarToolInputProperties:p,resolveServiceTier:ne,applyServiceTierPricing:o((v,A)=>re(v,A,a),"applyServiceTierPricing")}),d?.signal?.aborted)m=!1;else if(C&&l&&n.responseId){const v=j(a,{messages:[n]},Y,{includeSystemPrompt:!1,grammarToolInputProperties:p}).filter(A=>A.type!=="function_call_output"&&A.type!=="custom_tool_call_output");l.continuation={lastRequestBody:b,lastResponseId:n.responseId,lastResponseItems:v}}}catch(v){throw l&&(l.continuation=void 0),m=!1,v}finally{y({keep:m})}}o(ht,"processWebSocketStream");async function Et(e){const r=await e.text();let t=r||e.statusText||"Request failed",n;try{const a=JSON.parse(r)?.error;if(a){const i=a.code||a.type||"";if(/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(i)||e.status===429){const f=a.plan_type?` (${a.plan_type.toLowerCase()} plan)`:"",c=a.resets_at?Math.max(0,Math.round((a.resets_at*1e3-Date.now())/6e4)):void 0,u=c!==void 0?` Try again in ~${c} min.`:"";n=`You have hit your ChatGPT usage limit${f}.${u}`.trim()}t=a.message||n||t}}catch{}return{message:t,friendlyMessage:n}}o(Et,"parseErrorResponse");function St(e){try{const r=e.split(".");if(r.length!==3)throw new Error("Invalid token");const n=JSON.parse(atob(r[1]))?.[We]?.chatgpt_account_id;if(!n)throw new Error("No account ID in token");return n}catch{throw new Error("Failed to extract accountId from token")}}o(St,"extractAccountId");function fe(e,r,t,n){const s=new Headers(e);for(const[i,f]of Object.entries(r||{}))f===null?s.delete(i):s.set(i,f);s.set("Authorization",`Bearer ${n}`),s.set("chatgpt-account-id",t),s.set("originator","pi");const a=q?`pi (${q.platform()} ${q.release()}; ${q.arch()})`:"pi (browser)";return s.set("User-Agent",a),s}o(fe,"buildBaseCodexHeaders");function gt(e,r,t,n,s){const a=fe(e,r,t,n);return a.set("OpenAI-Beta","responses=experimental"),a.set("accept","text/event-stream"),a.set("content-type","application/json"),s&&(a.set("session-id",s),a.set("x-client-request-id",s)),a}o(gt,"buildSSEHeaders");function _t(e,r,t,n,s){const a=fe(e,r,t,n);return a.delete("accept"),a.delete("content-type"),a.delete("OpenAI-Beta"),a.delete("openai-beta"),a.set("OpenAI-Beta",rt),a.set("x-client-request-id",s),a.set("session-id",s),a}o(_t,"buildWebSocketHeaders");
|
|
7
|
+
`)}}}finally{r?.removeEventListener("abort",s);try{await t.cancel()}catch{}try{t.releaseLock()}catch{}}}o(et,"parseSSE");const tt="responses_websockets=2026-02-06",rt=300*1e3,nt=3300*1e3,T=new Map,I=new Map,B=new Set;function J(e){let r=I.get(e);return r||(r={requests:0,connectionsCreated:0,connectionsReused:0,cachedContextRequests:0,storeTrueRequests:0,fullContextRequests:0,deltaRequests:0,lastInputItems:0,websocketFailures:0,sseFallbacks:0},I.set(e,r)),r}o(J,"getOrCreateWebSocketDebugStats");export function getOpenAICodexWebSocketDebugStats(e){const r=I.get(e);return r?{...r}:void 0}o(getOpenAICodexWebSocketDebugStats,"getOpenAICodexWebSocketDebugStats");export function resetOpenAICodexWebSocketDebugStats(e){if(e){I.delete(e),B.delete(e);return}I.clear(),B.clear()}o(resetOpenAICodexWebSocketDebugStats,"resetOpenAICodexWebSocketDebugStats");export function closeOpenAICodexWebSocketSessions(e){const r=o(t=>{t.idleTimer&&clearTimeout(t.idleTimer),x(t.socket,1e3,"debug_close")},"closeEntry");if(e){const t=T.get(e);t&&r(t),T.delete(e);return}for(const t of T.values())r(t);T.clear()}o(closeOpenAICodexWebSocketSessions,"closeOpenAICodexWebSocketSessions"),be(closeOpenAICodexWebSocketSessions);function se(e){return e?B.has(e):!1}o(se,"isWebSocketSseFallbackActive");function ae(e){if(!e)return;const r=J(e);r.sseFallbacks++,r.websocketFallbackActive=se(e)}o(ae,"recordWebSocketSseFallback");function ot(e,r){if(!e)return;B.add(e);const t=J(e);t.websocketFailures++,t.lastWebSocketError=$(r),t.websocketFallbackActive=!0}o(ot,"recordWebSocketFailure");let z=null;async function st(e){if(!e&&z)return z;if(typeof process<"u"&&process.versions?.bun){const t=class extends WebSocket{static{o(this,"WebSocketWithProxy")}constructor(n,a){let s={};Array.isArray(a)||typeof a=="string"?s={protocols:a}:s={...a};const i=Te(n.toString().replace(/^wss:/,"https:").replace(/^ws:/,"http:"),e);super(n,{...s,...i?{proxy:i.toString()}:{}})}};return e||(z=t),t}const r=globalThis.WebSocket;return typeof r!="function"?null:r}o(st,"getWebSocketConstructor");class at extends Error{static{o(this,"WebSocketCloseError")}code;reason;wasClean;constructor(r,t){super(r),this.name="WebSocketCloseError",this.code=t?.code,this.reason=t?.reason,this.wasClean=t?.wasClean}}function it(e){const r=e.readyState;return typeof r=="number"?r:void 0}o(it,"getWebSocketReadyState");function P(e){const r=it(e);return r===void 0||r===1}o(P,"isWebSocketReusable");function ct(e){return Date.now()-e.createdAt>=nt}o(ct,"isWebSocketSessionExpired");function x(e,r=1e3,t="done"){try{e.close(r,t)}catch{}}o(x,"closeWebSocketSilently");function ie(e,r){r.idleTimer&&clearTimeout(r.idleTimer),r.idleTimer=setTimeout(()=>{r.busy||(x(r.socket,1e3,"idle_timeout"),T.delete(e))},rt)}o(ie,"scheduleSessionWebSocketExpiry");async function H(e,r,t,n=De,a){const s=await st(a);if(!s)throw new Error("WebSocket transport is not available in this runtime");const i=K(r);return delete i["OpenAI-Beta"],new Promise((f,c)=>{let u=!1,p,d;try{d=new s(e,{headers:i})}catch(b){c(b instanceof Error?b:new Error(String(b)));return}const S=o(()=>{p&&(clearTimeout(p),p=void 0),d.removeEventListener("open",g),d.removeEventListener("error",y),d.removeEventListener("close",m),t?.removeEventListener("abort",C)},"cleanup"),l=o((b,h)=>{u||(u=!0,S(),h&&x(d,1e3,h),c(b))},"fail"),g=o(()=>{u||(u=!0,S(),f(d))},"onOpen"),y=o(b=>{l(ce(b))},"onError"),m=o(b=>{l(ue(b))},"onClose"),C=o(()=>{l(new Error("Request was aborted"),"aborted")},"onAbort");d.addEventListener("open",g),d.addEventListener("error",y),d.addEventListener("close",m),t?.addEventListener("abort",C),n>0&&(p=setTimeout(()=>{l(new Error(`WebSocket connect timeout after ${n}ms`),"connect_timeout")},n)),t?.aborted&&C()})}o(H,"connectWebSocket");async function ut(e,r,t,n,a,s){if(!t){const u=await H(e,r,n,a,s);return{socket:u,reused:!1,release:o(()=>x(u),"release")}}const i=T.get(t);if(i){if(i.idleTimer&&(clearTimeout(i.idleTimer),i.idleTimer=void 0),!i.busy&&ct(i))x(i.socket,1e3,"connection_age_limit"),T.delete(t);else if(!i.busy&&P(i.socket))return i.busy=!0,{socket:i.socket,entry:i,reused:!0,release:o(({keep:u}={})=>{if(!u||!P(i.socket)){x(i.socket),T.delete(t);return}i.busy=!1,ie(t,i)},"release")};if(i.busy){const u=await H(e,r,n,a,s);return{socket:u,reused:!1,release:o(()=>{x(u)},"release")}}P(i.socket)||(x(i.socket),T.delete(t))}const f=await H(e,r,n,a,s),c={socket:f,busy:!0,createdAt:Date.now()};return T.set(t,c),{socket:f,entry:c,reused:!1,release:o(({keep:u}={})=>{if(!u||!P(c.socket)){x(c.socket),c.idleTimer&&clearTimeout(c.idleTimer),T.get(t)===c&&T.delete(t);return}c.busy=!1,ie(t,c)},"release")}}o(ut,"acquireWebSocket");function ce(e){if(e&&typeof e=="object"){const r="message"in e?e.message:void 0;if(typeof r=="string"&&r.length>0)return new Error(r);const t="error"in e?e.error:void 0;if(t instanceof Error&&t.message.length>0)return t;if(t&&typeof t=="object"&&"message"in t){const n=t.message;if(typeof n=="string"&&n.length>0)return new Error(n)}}return new Error("WebSocket error")}o(ce,"extractWebSocketError");function ue(e){if(e&&typeof e=="object"){const r="code"in e?e.code:void 0,t="reason"in e?e.reason:void 0,n="wasClean"in e?e.wasClean:void 0,a=typeof r=="number"?` ${r}`:"";let s=typeof t=="string"&&t.length>0?` ${t}`:"";return!s&&r===Ne&&(s=" message too big"),new at(`WebSocket closed${a}${s}`.trim(),{code:typeof r=="number"?r:void 0,reason:typeof t=="string"&&t.length>0?t:void 0,wasClean:typeof n=="boolean"?n:void 0})}return new Error("WebSocket closed")}o(ue,"extractWebSocketCloseError");async function dt(e){if(typeof e=="string")return e;if(e instanceof ArrayBuffer)return new TextDecoder().decode(new Uint8Array(e));if(ArrayBuffer.isView(e)){const r=e;return new TextDecoder().decode(new Uint8Array(r.buffer,r.byteOffset,r.byteLength))}if(e&&typeof e=="object"&&"arrayBuffer"in e){const t=await e.arrayBuffer();return new TextDecoder().decode(new Uint8Array(t))}return null}o(dt,"decodeWebSocketData");async function*lt(e,r,t){const n=[];let a=null,s=!1,i=null,f=!1;const c=o(()=>{if(!a)return;const l=a;a=null,l()},"wake"),u=o(l=>{(async()=>{let g=null;try{if(!l||typeof l!="object"||!("data"in l)||(g=await dt(l.data),!g))return;const y=JSON.parse(g),m=typeof y.type=="string"?y.type:"";(m==="response.completed"||m==="response.done"||m==="response.incomplete")&&(f=!0,s=!0),n.push(y),c()}catch(y){i=new U(`Invalid Codex WebSocket JSON: ${$(y)}`,{cause:y,payload:g}),s=!0,c()}})()},"onMessage"),p=o(l=>{i=ce(l),s=!0,c()},"onError"),d=o(l=>{if(f){s=!0,c();return}i||(i=ue(l)),s=!0,c()},"onClose"),S=o(()=>{i=new Error("Request was aborted"),s=!0,c()},"onAbort");e.addEventListener("message",u),e.addEventListener("error",p),e.addEventListener("close",d),r?.addEventListener("abort",S);try{for(;;){if(r?.aborted)throw new Error("Request was aborted");if(n.length>0){yield n.shift();continue}if(s)break;let l;await new Promise((g,y)=>{a=g,t!==void 0&&t>0&&(l=setTimeout(()=>{const m=new Error(`WebSocket idle timeout after ${t}ms`);i=m,s=!0,a=null,x(e,1e3,"idle_timeout"),y(m)},t))}).finally(()=>{l&&clearTimeout(l)})}if(i)throw i;if(!f)throw new Error("WebSocket stream closed before response.completed")}finally{e.removeEventListener("message",u),e.removeEventListener("error",p),e.removeEventListener("close",d),r?.removeEventListener("abort",S)}}o(lt,"parseWebSocket");function de(e){const{input:r,previous_response_id:t,...n}=e;return n}o(de,"requestBodyWithoutInput");function ft(e,r){return JSON.stringify(e??[])===JSON.stringify(r??[])}o(ft,"responseInputsEqual");function pt(e,r){return JSON.stringify(de(e))===JSON.stringify(de(r))}o(pt,"requestBodiesMatchExceptInput");function mt(e,r){if(!pt(e,r.lastRequestBody))return;const t=e.input??[],n=[...r.lastRequestBody.input??[],...r.lastResponseItems];if(t.length<n.length)return;const a=t.slice(0,n.length);if(ft(a,n))return t.slice(n.length)}o(mt,"getCachedWebSocketInputDelta");function yt(e,r){const t=e.continuation;if(!t)return r;const n=mt(r,t);return!n||!t.lastResponseId?(e.continuation=void 0,r):{...r,previous_response_id:t.lastResponseId,input:n}}o(yt,"buildCachedWebSocketRequestBody");async function*bt(e,r){let t=!1;for await(const n of e)t||(t=!0,r()),yield n}o(bt,"startWebSocketOutputOnFirstEvent");async function wt(e,r,t,n,a,s,i,f,c,u,p,d){const{socket:S,entry:l,reused:g,release:y}=await ut(e,t,u,d?.signal,c,d?.env);let m=!0;const C=d?.transport==="websocket-cached"||d?.transport==="auto",b=r,h=C&&l?yt(l,b):b,w=u?J(u):void 0;w&&(w.requests++,g?w.connectionsReused++:w.connectionsCreated++,C&&w.cachedContextRequests++,h.store===!0&&w.storeTrueRequests++,w.lastInputItems=h.input?.length??0,h.previous_response_id?(w.deltaRequests++,w.lastDeltaInputItems=h.input?.length??0,w.lastPreviousResponseId=h.previous_response_id):(w.fullContextRequests++,w.lastDeltaInputItems=void 0,w.lastPreviousResponseId=void 0));try{if(S.send(JSON.stringify({type:"response.create",...h})),await V(bt(oe(lt(S,d?.signal,f)),i),n,a,s,{serviceTier:d?.serviceTier,grammarToolInputProperties:p,resolveServiceTier:re,applyServiceTierPricing:o((v,A)=>te(v,A,s),"applyServiceTierPricing")}),d?.signal?.aborted)m=!1;else if(C&&l&&n.responseId){const v=j(s,{messages:[n]},Y,{includeSystemPrompt:!1,grammarToolInputProperties:p}).filter(A=>A.type!=="function_call_output"&&A.type!=="custom_tool_call_output");l.continuation={lastRequestBody:b,lastResponseId:n.responseId,lastResponseItems:v}}}catch(v){throw l&&(l.continuation=void 0),m=!1,v}finally{y({keep:m})}}o(wt,"processWebSocketStream");async function ht(e){const r=await e.text();let t=r||e.statusText||"Request failed",n;try{const s=JSON.parse(r)?.error;if(s){const i=s.code||s.type||"";if(/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(i)||e.status===429){const f=s.plan_type?` (${s.plan_type.toLowerCase()} plan)`:"",c=s.resets_at?Math.max(0,Math.round((s.resets_at*1e3-Date.now())/6e4)):void 0,u=c!==void 0?` Try again in ~${c} min.`:"";n=`You have hit your ChatGPT usage limit${f}.${u}`.trim()}t=s.message||n||t}}catch{}return{message:t,friendlyMessage:n}}o(ht,"parseErrorResponse");function Et(e){try{const r=e.split(".");if(r.length!==3)throw new Error("Invalid token");const n=JSON.parse(atob(r[1]))?.[Ae]?.chatgpt_account_id;if(!n)throw new Error("No account ID in token");return n}catch{throw new Error("Failed to extract accountId from token")}}o(Et,"extractAccountId");function le(e,r,t,n){const a=new Headers(e);for(const[i,f]of Object.entries(r||{}))f===null?a.delete(i):a.set(i,f);a.set("Authorization",`Bearer ${n}`),a.set("chatgpt-account-id",t),a.set("originator","pi");const s=q?`pi (${q.platform()} ${q.release()}; ${q.arch()})`:"pi (browser)";return a.set("User-Agent",s),a}o(le,"buildBaseCodexHeaders");function St(e,r,t,n,a){const s=le(e,r,t,n);return s.set("OpenAI-Beta","responses=experimental"),s.set("accept","text/event-stream"),s.set("content-type","application/json"),a&&(s.set("session-id",a),s.set("x-client-request-id",a)),s}o(St,"buildSSEHeaders");function gt(e,r,t,n,a){const s=le(e,r,t,n);return s.delete("accept"),s.delete("content-type"),s.delete("OpenAI-Beta"),s.delete("openai-beta"),s.set("OpenAI-Beta",tt),s.set("x-client-request-id",a),s.set("session-id",a),s}o(gt,"buildWebSocketHeaders");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var ee=Object.defineProperty;var
|
|
2
|
-
${
|
|
1
|
+
var ee=Object.defineProperty;var u=(e,n)=>ee(e,"name",{value:n,configurable:!0});import te from"openai";import{calculateCost as ne,clampThinkingLevel as re}from"../models.js";import{formatProviderError as se,normalizeProviderError as oe}from"../utils/error-body.js";import{AssistantMessageEventStream as ie}from"../utils/event-stream.js";import{shortHash as ae}from"../utils/hash.js";import{headersToRecord as ue}from"../utils/headers.js";import{parseStreamingJson as N}from"../utils/json-parse.js";import{getProviderEnvValue as fe}from"../utils/provider-env.js";import{retryProviderRequest as le}from"../utils/provider-retry.js";import{sanitizeSurrogates as E}from"../utils/sanitize-unicode.js";import{appendGrammarToolInputJsonDelta as ce,createGrammarToolInputProperties as z,getGrammarToolInput as pe,resolveGrammarConstrainedSampling as ge,resolveJsonSchemaStrictSampling as de}from"./constrained-sampling.js";import{buildCopilotDynamicHeaders as he,hasCopilotVisionInput as me}from"./github-copilot-headers.js";import{clampOpenAIPromptCacheKey as ye}from"./openai-prompt-cache.js";import{buildBaseOptions as ke}from"./simple-options.js";import{transformMessages as Te}from"./transform-messages.js";function G(e,n){if(!e)return!1;const t=n.toLowerCase();for(const[r,s]of Object.entries(e))if(r.toLowerCase()===t&&s!==null&&s.trim().length>0)return!0;return!1}u(G,"hasHeader");function j(e,n,t){if(n)return n;if(G(t,"authorization")||G(t,"cf-aig-authorization"))return"unused";throw new Error(`No API key for provider: ${e}`)}u(j,"getClientApiKey");function Re(e){for(const n of e)if(n.role==="toolResult"||n.role==="assistant"&&n.content.some(t=>t.type==="toolCall"))return!0;return!1}u(Re,"hasToolHistory");function _e(e){const n=new Set;for(const t of e)if(t.role==="toolResult")for(const r of t.addedToolNames??[])n.add(r);return n}u(_e,"getDeferredToolNames");function xe(e,n){if(!e)return[];const t=new Map(e.map(r=>[r.name,r]));return Array.from(n).map(r=>t.get(r)).filter(r=>r!==void 0)}u(xe,"getToolsByName");function K(e){return e.type==="text"}u(K,"isTextContentBlock");function ve(e){return e.type==="thinking"}u(ve,"isThinkingContentBlock");function Ae(e){return e.type==="toolCall"}u(Ae,"isToolCallBlock");function Ce(e){return e.type==="image"}u(Ce,"isImageContentBlock");function Me(e){if(typeof e!="object"||e===null)return!1;const n=e;return n.type==="reasoning.encrypted"&&typeof n.id=="string"&&n.id.length>0&&typeof n.data=="string"&&n.data.length>0}u(Me,"isEncryptedReasoningDetail");function $(e,n){return e||(fe("PI_CACHE_RETENTION",n)==="long"?"long":"short")}u($,"resolveCacheRetention");export const stream=u((e,n,t)=>{const r=new ie;return(async()=>{const s={role:"assistant",content:[],api:e.api,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{const d=j(e.provider,t?.apiKey,t?.headers),l=L(e),T=z(n.tools,l.supportsOpenAIGrammarTools),i=$(t?.cacheRetention,t?.env),h=i==="none"?void 0:t?.sessionId,c=Ie(e,n,d,t?.headers,h,l);let a=we(e,n,t,l,i,T);const y=await t?.onPayload?.(a,e);y!==void 0&&(a=y);const k={...t?.signal?{signal:t.signal}:{},...t?.timeoutMs!==void 0?{timeout:t.timeoutMs}:{},maxRetries:0},{data:A,response:M}=await le(()=>c.chat.completions.create(a,k).withResponse(),{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal});await t?.onResponse?.({status:M.status,headers:ue(M.headers)},e),r.push({type:"start",partial:s});let I=null,m=null,R=!1;const v=new Map,O=new Map,P=new Map,b=s.content,S=u(o=>b.indexOf(o),"getContentIndex"),B=u(o=>{const f=o.customInput?.property;if(f===void 0)return"";const x=o.arguments[f];return typeof x=="string"?x:""},"getCustomToolCallInput"),D=u((o,f,x)=>{const p=o.customInput;if(!p)return;const C=ce(p.jsonBuffer,p.property,f,x);return o.arguments={[p.property]:f},C},"appendCustomToolCallInput"),J=u(o=>{const f=S(o);if(f!==-1){if(o.type==="text")r.push({type:"text_end",contentIndex:f,content:o.text,partial:s});else if(o.type==="thinking")r.push({type:"thinking_end",contentIndex:f,content:o.thinking,partial:s});else if(o.type==="toolCall"){if(o.customInput){const x=D(o,B(o),!0);x!==void 0&&r.push({type:"toolcall_delta",contentIndex:f,delta:x,partial:s})}else o.arguments=N(o.partialArgs);delete o.partialArgs,delete o.customInput,delete o.streamIndex,r.push({type:"toolcall_end",contentIndex:f,toolCall:o,partial:s})}}},"finishBlock"),V=u(()=>(I||(I={type:"text",text:""},b.push(I),r.push({type:"text_start",contentIndex:S(I),partial:s})),I),"ensureTextBlock"),Z=u(o=>(m||(m={type:"thinking",thinking:"",thinkingSignature:o},b.push(m),r.push({type:"thinking_start",contentIndex:S(m),partial:s})),m),"ensureThinkingBlock"),Q=u(o=>{if(!o.id)return;const f=P.get(o.id);f&&(o.thoughtSignature=f,P.delete(o.id))},"applyPendingReasoningDetail"),X=u(o=>{const f=typeof o.index=="number"?o.index:void 0,x=o.function?.name??o.custom?.name??"";let p=f!==void 0?v.get(f):void 0;if(!p&&o.id&&(p=O.get(o.id)),!p){const C=o.custom?T.get(x)??"input":void 0,F=C!==void 0;p={type:"toolCall",id:o.id||"",name:x,arguments:F?{[C]:""}:{},partialArgs:F?void 0:"",customInput:F?{property:C,jsonBuffer:{input:"",started:!1,closed:!1}}:void 0,streamIndex:f},f!==void 0&&v.set(f,p),o.id&&O.set(o.id,p),b.push(p),r.push({type:"toolcall_start",contentIndex:S(p),partial:s})}if(f!==void 0&&p.streamIndex===void 0&&(p.streamIndex=f,v.set(f,p)),o.id&&O.set(o.id,p),!p.name&&x&&(p.name=x),o.custom&&!p.customInput){const C=T.get(p.name)??"input";p.arguments={[C]:""},p.customInput={property:C,jsonBuffer:{input:"",started:!1,closed:!1}},delete p.partialArgs}return Q(p),p},"ensureToolCallBlock");for await(const o of A){if(!o||typeof o!="object")continue;s.responseId||=o.id,typeof o.model=="string"&&o.model.length>0&&o.model!==e.id&&(s.responseModel||=o.model),o.usage&&(s.usage=U(o.usage,e));const f=Array.isArray(o.choices)?o.choices[0]:void 0;if(f){if(!o.usage&&f.usage&&(s.usage=U(f.usage,e)),f.finish_reason){const x=De(f.finish_reason);s.stopReason=x.stopReason,x.errorMessage&&(s.errorMessage=x.errorMessage),R=!0}if(f.delta){if(f.delta.content!==null&&f.delta.content!==void 0&&f.delta.content.length>0){const g=V();g.text+=f.delta.content,r.push({type:"text_delta",contentIndex:S(g),delta:f.delta.content,partial:s})}const x=["reasoning_content","reasoning","reasoning_text"],p=f.delta;let C=null;for(const g of x){const _=p[g];if(typeof _=="string"&&_.length>0){C=g;break}}if(C){const g=p[C];if(typeof g=="string"&&g.length>0){const _=e.provider==="opencode-go"&&C==="reasoning"?"reasoning_content":C,w=Z(_);w.thinking+=g,r.push({type:"thinking_delta",contentIndex:S(w),delta:g,partial:s})}}if(f?.delta?.tool_calls)for(const g of f.delta.tool_calls){const _=X(g);!_.id&&g.id&&(_.id=g.id,O.set(g.id,_));const w=g.function?.name??g.custom?.name;!_.name&&w&&(_.name=w);let q="";if(g.function?.arguments)q=g.function.arguments,_.partialArgs=(_.partialArgs??"")+g.function.arguments,_.arguments=N(_.partialArgs);else if(g.custom?.input){const Y=B(_)+g.custom.input;q=D(_,Y,!1)??""}r.push({type:"toolcall_delta",contentIndex:S(_),delta:q,partial:s})}const F=f.delta.reasoning_details;if(Array.isArray(F)){for(const g of F)if(Me(g)){const _=JSON.stringify(g),w=O.get(g.id);w?w.thoughtSignature=_:P.set(g.id,_)}}}}}for(const o of b)J(o);if(t?.signal?.aborted)throw new Error("Request was aborted");if(s.stopReason==="aborted")throw new Error("Request was aborted");if(s.stopReason==="error")throw new Error(s.errorMessage||"Provider returned an error stop reason");if(!R)throw new Error("Stream ended without finish_reason");r.push({type:"done",reason:s.stopReason,message:s}),r.end()}catch(d){for(const T of s.content)delete T.index,delete T.partialArgs,delete T.customInput,delete T.streamIndex;s.stopReason=t?.signal?.aborted?"aborted":"error",s.errorMessage=se(oe(d));const l=d?.error?.metadata?.raw;l&&!s.errorMessage.includes(String(l))&&(s.errorMessage+=`
|
|
2
|
+
${l}`),r.push({type:"error",reason:s.stopReason,error:s}),r.end()}})(),r},"stream"),streamSimple=u((e,n,t)=>{j(e.provider,t?.apiKey,t?.headers);const r=ke(e,n,t,t?.apiKey),s=t?.reasoning?re(e,t.reasoning):void 0,d=s==="off"?void 0:s,l=t?.toolChoice;return stream(e,n,{...r,reasoningEffort:d,toolChoice:l})},"streamSimple");function Ie(e,n,t,r,s,d=L(e)){const l={...e.headers};if(e.provider==="github-copilot"){const T=me(n.messages),i=he({messages:n.messages,hasImages:T});Object.assign(l,i)}return s&&d.sendSessionAffinityHeaders&&(d.sessionAffinityFormat==="openrouter"?l["x-session-id"]=s:(d.sessionAffinityFormat==="openai"&&(l.session_id=s),l["x-client-request-id"]=s,l["x-session-affinity"]=s)),r&&Object.assign(l,r),new te({apiKey:t,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:l})}u(Ie,"createClient");function we(e,n,t,r=L(e),s=$(t?.cacheRetention,t?.env),d=z(n.tools,r.supportsOpenAIGrammarTools)){const l=convertMessages(e,n,r,{grammarToolInputProperties:d}),T=Fe(r,s),i={model:e.id,messages:l,stream:!0,prompt_cache_key:e.baseUrl.includes("api.openai.com")&&s!=="none"||s==="long"&&r.supportsLongCacheRetention?ye(t?.sessionId):void 0,prompt_cache_retention:s==="long"&&r.supportsLongCacheRetention?"24h":void 0};r.supportsUsageInStreaming!==!1&&(i.stream_options={include_usage:!0}),r.supportsStore&&(i.store=!1),t?.maxTokens&&(r.maxTokensField==="max_tokens"?i.max_tokens=t.maxTokens:i.max_completion_tokens=t.maxTokens),t?.temperature!==void 0&&(i.temperature=t.temperature);const h=r.deferredToolsMode==="kimi"?_e(n.messages):new Set,c=n.tools?.filter(a=>!h.has(a.name));if(c&&c.length>0?(i.tools=W(c,r),r.zaiToolStream&&(i.tool_stream=!0)):Re(n.messages)&&(i.tools=[]),T&&Oe(l,i.tools,T),t?.toolChoice&&(i.tool_choice=t.toolChoice),r.thinkingFormat==="zai"&&e.reasoning){const a=i;if(a.thinking=t?.reasoningEffort?{type:"enabled",clear_thinking:!1}:{type:"disabled"},t?.reasoningEffort&&r.supportsReasoningEffort){const y=e.thinkingLevelMap?.[t.reasoningEffort],k=y===void 0?t.reasoningEffort:y;typeof k=="string"&&(a.reasoning_effort=k)}}else if(r.thinkingFormat==="qwen"&&e.reasoning)i.enable_thinking=!!t?.reasoningEffort;else if(r.thinkingFormat==="qwen-chat-template"&&e.reasoning)i.chat_template_kwargs={enable_thinking:!!t?.reasoningEffort,preserve_thinking:!0};else if(r.thinkingFormat==="chat-template"&&e.reasoning){const a=Se(e,t,r);a&&(i.chat_template_kwargs=a)}else if(r.thinkingFormat==="deepseek"&&e.reasoning)t?.reasoningEffort?i.thinking={type:"enabled"}:e.thinkingLevelMap?.off!==null&&(i.thinking={type:"disabled"}),t?.reasoningEffort&&r.supportsReasoningEffort&&(i.reasoning_effort=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort);else if(r.thinkingFormat==="openrouter"&&e.reasoning){const a=i;t?.reasoningEffort?a.reasoning={effort:e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort}:e.thinkingLevelMap?.off!==null&&(a.reasoning={effort:e.thinkingLevelMap?.off??"none"})}else if(r.thinkingFormat==="ant-ling"&&e.reasoning&&t?.reasoningEffort){const a=e.thinkingLevelMap?.[t.reasoningEffort];typeof a=="string"&&(i.reasoning={effort:a})}else if(r.thinkingFormat==="together"&&e.reasoning){const a=i;a.reasoning={enabled:!!t?.reasoningEffort},t?.reasoningEffort&&r.supportsReasoningEffort&&(a.reasoning_effort=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort)}else if(r.thinkingFormat==="string-thinking"&&e.reasoning){const a=i;t?.reasoningEffort?a.thinking=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort:e.thinkingLevelMap?.off!==null&&(a.thinking=e.thinkingLevelMap?.off??"none")}else if(t?.reasoningEffort&&e.reasoning&&r.supportsReasoningEffort)i.reasoning_effort=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort;else if(!t?.reasoningEffort&&e.reasoning&&r.supportsReasoningEffort){const a=e.thinkingLevelMap?.off;typeof a=="string"&&(i.reasoning_effort=a)}if(e.compat?.openRouterRouting&&(i.provider=e.compat.openRouterRouting),e.compat?.vercelGatewayRouting){const a=e.compat.vercelGatewayRouting;if(a.only||a.order){const y={};a.only&&(y.only=a.only),a.order&&(y.order=a.order),i.providerOptions={gateway:y}}}return i}u(we,"buildParams");function Se(e,n,t){const r={};for(const[s,d]of Object.entries(t.chatTemplateKwargs)){const l=Ee(e,n,d);l!==void 0&&(r[s]=l)}return Object.keys(r).length>0?r:void 0}u(Se,"buildChatTemplateKwargs");function Ee(e,n,t){if(typeof t!="object"||t===null)return t;const r=n?.reasoningEffort;if(!r&&t.omitWhenOff)return;if(t.$var==="thinking.enabled")return!!r;const s=r?e.thinkingLevelMap?.[r]:e.thinkingLevelMap?.off;return s===void 0?r:typeof s=="string"?s:void 0}u(Ee,"resolveChatTemplateKwargValue");function Fe(e,n){if(e.cacheControlFormat!=="anthropic"||n==="none")return;const t=n==="long"&&e.supportsLongCacheRetention?"1h":void 0;return{type:"ephemeral",...t?{ttl:t}:{}}}u(Fe,"getCompatCacheControl");function Oe(e,n,t){be(e,t),qe(n,t),Pe(e,t)}u(Oe,"applyAnthropicCacheControl");function be(e,n){for(const t of e)if(t.role==="system"||t.role==="developer"){Le(t,n);return}}u(be,"addCacheControlToSystemPrompt");function Pe(e,n){for(let t=e.length-1;t>=0;t--){const r=e[t];if((r.role==="user"||r.role==="assistant"||r.role==="tool")&&Be(r,n))return}}u(Pe,"addCacheControlToLastConversationMessage");function qe(e,n){if(!e||e.length===0)return;const t=e[e.length-1];t.cache_control=n}u(qe,"addCacheControlToLastTool");function Le(e,n){return H(e,n)}u(Le,"addCacheControlToInstructionMessage");function Be(e,n){return e.role==="user"||e.role==="assistant"||e.role==="tool"?H(e,n):!1}u(Be,"addCacheControlToMessage");function H(e,n){const t=e.content;if(typeof t=="string")return t.length===0?!1:(e.content=[{type:"text",text:t,cache_control:n}],!0);if(!Array.isArray(t))return!1;for(let r=t.length-1;r>=0;r--){const s=t[r];if(s?.type==="text"){const d=s;return d.cache_control=n,!0}}return!1}u(H,"addCacheControlToTextContent");export function convertMessages(e,n,t,r){const s=[],d=u(i=>{if(i.includes("|")){const h=i.indexOf("|"),c=i.slice(0,h).replace(/[^a-zA-Z0-9_-]/g,"_"),a=i.slice(h+1).replace(/[^a-zA-Z0-9_-]/g,"_"),y=a.length>0?`${c}_${a}`:c;if(y.length<=40)return y;const k=ae(i).slice(0,8);return`${c.slice(0,Math.max(1,40-k.length-1))}_${k}`}return e.provider==="openai"&&i.length>40?i.slice(0,40):i},"normalizeToolCallId"),l=Te(n.messages,e,i=>d(i));if(n.systemPrompt){const h=e.reasoning&&t.supportsDeveloperRole?"developer":"system";s.push({role:h,content:E(n.systemPrompt)})}let T=null;for(let i=0;i<l.length;i++){const h=l[i];if(t.requiresAssistantAfterToolResult&&T==="toolResult"&&h.role==="user"&&s.push({role:"assistant",content:"I have processed the tool results."}),h.role==="user")if(typeof h.content=="string")s.push({role:"user",content:E(h.content)});else{const c=h.content.map(a=>a.type==="text"?{type:"text",text:E(a.text)}:{type:"image_url",image_url:{url:`data:${a.mimeType};base64,${a.data}`}});if(c.length===0)continue;s.push({role:"user",content:c})}else if(h.role==="assistant"){const c={role:"assistant",content:t.requiresAssistantAfterToolResult?"":null},a=h.content.filter(K).filter(m=>m.text.trim().length>0).map(m=>({type:"text",text:E(m.text)})),y=a.map(m=>m.text).join(""),k=h.content.filter(ve).filter(m=>m.thinking.trim().length>0);if(k.length>0)if(t.requiresThinkingAsText){const m=k.map(R=>E(R.thinking)).join(`
|
|
3
3
|
|
|
4
|
-
`);
|
|
5
|
-
`))}else
|
|
6
|
-
`),M=
|
|
4
|
+
`);c.content=[{type:"text",text:m},...a]}else{y.length>0&&(c.content=y);let m=k[0].thinkingSignature;e.provider==="opencode-go"&&m==="reasoning"&&(m="reasoning_content"),m&&m.length>0&&(c[m]=k.map(R=>R.thinking).join(`
|
|
5
|
+
`))}else y.length>0&&(c.content=y);const A=h.content.filter(Ae);if(A.length>0){c.tool_calls=A.map(R=>{const v=r?.grammarToolInputProperties?.get(R.name);return v!==void 0?{id:R.id,type:"custom",custom:{name:R.name,input:E(pe(R.name,R.arguments,v))}}:{id:R.id,type:"function",function:{name:R.name,arguments:JSON.stringify(R.arguments)}}});const m=A.filter(R=>R.thoughtSignature).map(R=>{try{return JSON.parse(R.thoughtSignature)}catch{return null}}).filter(Boolean);m.length>0&&(c.reasoning_details=m)}t.requiresReasoningContentOnAssistantMessages&&e.reasoning&&c.reasoning_content===void 0&&(c.reasoning_content="");const M=c.content;if(!(M!=null&&M.length>0)&&!c.tool_calls)continue;s.push(c)}else if(h.role==="toolResult"){const c=[],a=new Set;let y=i;for(;y<l.length&&l[y].role==="toolResult";y++){const k=l[y],A=k.content.filter(K).map(v=>v.text).join(`
|
|
6
|
+
`),M=k.content.some(v=>v.type==="image"),m=A.length>0?A:M?"(see attached image)":"(no tool output)",R={role:"tool",content:E(m),tool_call_id:k.toolCallId};if(t.requiresToolResultName&&k.toolName&&(R.name=k.toolName),s.push(R),t.deferredToolsMode==="kimi")for(const v of k.addedToolNames??[])a.add(v);if(M&&e.input.includes("image"))for(const v of k.content)Ce(v)&&c.push({type:"image_url",image_url:{url:`data:${v.mimeType};base64,${v.data}`}})}if(i=y-1,c.length>0?(t.requiresAssistantAfterToolResult&&s.push({role:"assistant",content:"I have processed the tool results."}),s.push({role:"user",content:[{type:"text",text:"Attached image(s) from tool result:"},...c]}),T="user"):T="toolResult",a.size>0){const k=xe(n.tools,a);if(k.length>0){const A={role:"system",tools:W(k,t)};s.push(A)}}continue}T=h.role}return s}u(convertMessages,"convertMessages");function W(e,n){return e.map(t=>{const r=ge(t,n.supportsOpenAIGrammarTools);if(r)return{type:"custom",custom:{name:t.name,description:t.description,format:{type:"grammar",grammar:{syntax:r.format,definition:r.definition}}}};const s=de(t,n.supportsStrictMode!==!1);return{type:"function",function:{name:t.name,description:t.description,parameters:t.parameters,...n.supportsStrictMode!==!1&&{strict:s??!1}}}})}u(W,"convertTools");function U(e,n){const t=e.prompt_tokens||0,r=e.prompt_tokens_details?.cached_tokens??e.prompt_cache_hit_tokens??0,s=e.prompt_tokens_details?.cache_write_tokens||0,d=Math.max(0,t-r-s),l=e.completion_tokens||0,T={input:d,output:l,cacheRead:r,cacheWrite:s,reasoning:e.completion_tokens_details?.reasoning_tokens||0,totalTokens:d+l+r+s,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};return ne(n,T),T}u(U,"parseChunkUsage");function De(e){if(e===null)return{stopReason:"stop"};switch(e){case"stop":case"end":return{stopReason:"stop"};case"length":return{stopReason:"length"};case"function_call":case"tool_calls":return{stopReason:"toolUse"};case"content_filter":return{stopReason:"error",errorMessage:"Provider finish_reason: content_filter"};case"network_error":return{stopReason:"error",errorMessage:"Provider finish_reason: network_error"};default:return{stopReason:"error",errorMessage:`Provider finish_reason: ${e}`}}}u(De,"mapStopReason");function Ne(e){const n=e.provider,t=e.baseUrl,r=n==="zai"||n==="zai-coding-cn"||t.includes("api.z.ai")||t.includes("open.bigmodel.cn"),s=n==="together"||t.includes("api.together.ai")||t.includes("api.together.xyz"),d=n==="moonshotai"||n==="moonshotai-cn"||t.includes("api.moonshot."),l=n==="openrouter"||t.includes("openrouter.ai"),T=n==="cloudflare-workers-ai"||t.includes("api.cloudflare.com"),i=n==="cloudflare-ai-gateway"||t.includes("gateway.ai.cloudflare.com"),h=n==="nvidia"||t.includes("integrate.api.nvidia.com"),c=n==="ant-ling"||t.includes("api.ant-ling.com"),a=h||n==="cerebras"||t.includes("cerebras.ai")||n==="xai"||t.includes("api.x.ai")||s||t.includes("chutes.ai")||t.includes("deepseek.com")||r||d||n==="opencode"||t.includes("opencode.ai")||T||i||c,y=t.includes("chutes.ai")||d||i||s||h||c,k=n==="xai"||t.includes("api.x.ai"),A=n==="deepseek"||t.includes("deepseek.com"),M=l&&(e.id.startsWith("anthropic/")||e.id.startsWith("openai/")),I=n==="openrouter"&&e.id.startsWith("anthropic/")?"anthropic":void 0;return{supportsStore:!a,supportsDeveloperRole:M||!a&&!l,supportsReasoningEffort:!k&&!r&&!d&&!s&&!i&&!h&&!c,supportsUsageInStreaming:!0,maxTokensField:y?"max_tokens":"max_completion_tokens",requiresToolResultName:!1,requiresAssistantAfterToolResult:!1,requiresThinkingAsText:!1,requiresReasoningContentOnAssistantMessages:A,thinkingFormat:A?"deepseek":r?"zai":s?"together":c?"ant-ling":l?"openrouter":"openai",openRouterRouting:{},vercelGatewayRouting:{},chatTemplateKwargs:{},zaiToolStream:!1,supportsStrictMode:!d&&!s&&!i&&!h,supportsOpenAIGrammarTools:!1,cacheControlFormat:I,sendSessionAffinityHeaders:!1,deferredToolsMode:void 0,sessionAffinityFormat:l?"openrouter":"openai",supportsLongCacheRetention:!(s||T||i||h||c)}}u(Ne,"detectCompat");function L(e){const n=Ne(e);return e.compat?{supportsStore:e.compat.supportsStore??n.supportsStore,supportsDeveloperRole:e.compat.supportsDeveloperRole??n.supportsDeveloperRole,supportsReasoningEffort:e.compat.supportsReasoningEffort??n.supportsReasoningEffort,supportsUsageInStreaming:e.compat.supportsUsageInStreaming??n.supportsUsageInStreaming,maxTokensField:e.compat.maxTokensField??n.maxTokensField,requiresToolResultName:e.compat.requiresToolResultName??n.requiresToolResultName,requiresAssistantAfterToolResult:e.compat.requiresAssistantAfterToolResult??n.requiresAssistantAfterToolResult,requiresThinkingAsText:e.compat.requiresThinkingAsText??n.requiresThinkingAsText,requiresReasoningContentOnAssistantMessages:e.compat.requiresReasoningContentOnAssistantMessages??n.requiresReasoningContentOnAssistantMessages,thinkingFormat:e.compat.thinkingFormat??n.thinkingFormat,openRouterRouting:e.compat.openRouterRouting??{},vercelGatewayRouting:e.compat.vercelGatewayRouting??n.vercelGatewayRouting,chatTemplateKwargs:e.compat.chatTemplateKwargs??n.chatTemplateKwargs,zaiToolStream:e.compat.zaiToolStream??n.zaiToolStream,supportsStrictMode:e.compat.supportsStrictMode??n.supportsStrictMode,supportsOpenAIGrammarTools:e.compat.supportsOpenAIGrammarTools??n.supportsOpenAIGrammarTools,cacheControlFormat:e.compat.cacheControlFormat??n.cacheControlFormat,sendSessionAffinityHeaders:e.compat.sendSessionAffinityHeaders??n.sendSessionAffinityHeaders,deferredToolsMode:e.compat.deferredToolsMode??n.deferredToolsMode,sessionAffinityFormat:e.compat.sessionAffinityFormat??n.sessionAffinityFormat,supportsLongCacheRetention:e.compat.supportsLongCacheRetention??n.supportsLongCacheRetention}:n}u(L,"getCompat");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),u=o.filter(l=>l.type==="image"),p=
|
|
1
|
+
var w=Object.defineProperty;var f=(i,o)=>w(i,"name",{value:o,configurable:!0});import{calculateCost as R}from"../models.js";import{shortHash as v}from"../utils/hash.js";import{parseStreamingJson as C}from"../utils/json-parse.js";import{sanitizeSurrogates as x}from"../utils/sanitize-unicode.js";import{appendGrammarToolInputJsonDelta as P,getGrammarToolInput as O,resolveGrammarConstrainedSampling as M,resolveJsonSchemaStrictSampling as z}from"./constrained-sampling.js";import{transformMessages as N}from"./transform-messages.js";function j(i,o){const a={v:1,id:i};return o&&(a.phase=o),JSON.stringify(a)}f(j,"encodeTextSignatureV1");function W(i){if(i){if(i.startsWith("{"))try{const o=JSON.parse(i);if(o.v===1&&typeof o.id=="string")return o.phase==="commentary"||o.phase==="final_answer"?{id:o.id,phase:o.phase}:{id:o.id}}catch{}return{id:i}}}f(W,"parseTextSignature");function B(i,o){const a=o.filter(l=>l.type==="text").map(l=>l.text).join(`
|
|
2
|
+
`),u=o.filter(l=>l.type==="image"),p=a.length>0;if(u.length===0||!i.input.includes("image"))return x(p?a:u.length>0?"(see attached image)":"(no tool output)");const g=[];p&&g.push({type:"input_text",text:x(a)});for(const l of u)g.push({type:"input_image",detail:"auto",image_url:`data:${l.mimeType};base64,${l.data}`});return g}f(B,"convertToolResultOutput");export function convertResponsesMessages(i,o,a,u){const p=[],g=new Set,l=f(r=>{const c=r.replace(/[^a-zA-Z0-9_-]/g,"_");return(c.length>64?c.slice(0,64):c).replace(/_+$/,"")},"normalizeIdPart"),k=f(r=>{const c=`fc_${v(r)}`;return c.length>64?c.slice(0,64):c},"buildForeignResponsesItemId"),_=f((r,c,t)=>{if(!a.has(i.provider)||!r.includes("|"))return l(r);const[e,n]=r.split("|"),s=l(e);let m=t.provider!==i.provider||t.api!==i.api?k(n):l(n);return m.startsWith("fc_")||(m=l(`fc_${m}`)),`${s}|${m}`},"normalizeToolCallId"),y=N(o.messages,i,_);if((u?.includeSystemPrompt??!0)&&o.systemPrompt){const r=i.compat,c=i.reasoning&&r?.supportsDeveloperRole!==!1?"developer":"system";p.push({role:c,content:x(o.systemPrompt)})}let I=0;for(const r of y){if(r.role==="user")if(typeof r.content=="string")p.push({role:"user",content:[{type:"input_text",text:x(r.content)}]});else{const c=r.content.map(t=>t.type==="text"?{type:"input_text",text:x(t.text)}:{type:"input_image",detail:"auto",image_url:`data:${t.mimeType};base64,${t.data}`});if(c.length===0)continue;p.push({role:"user",content:c})}else if(r.role==="assistant"){const c=[],t=r,e=t.model!==i.id&&t.provider===i.provider&&t.api===i.api;let n=0;for(const s of r.content)if(s.type==="thinking"){if(s.thinkingSignature){const d=JSON.parse(s.thinkingSignature);c.push(d)}}else if(s.type==="text"){const d=s,m=W(d.textSignature),T=n===0?`msg_pi_${I}`:`msg_pi_${I}_${n}`;n++;let h=m?.id;h?h.length>64&&(h=`msg_${v(h)}`):h=T,c.push({type:"message",role:"assistant",content:[{type:"output_text",text:x(d.text),annotations:[]}],status:"completed",id:h,phase:m?.phase})}else if(s.type==="toolCall"){const d=s,[m,T]=d.id.split("|"),h=u?.grammarToolInputProperties?.get(d.name);let b=T;(e&&b?.startsWith("fc_")||h===void 0&&!b?.startsWith("fc_"))&&(b=void 0),h!==void 0?c.push({type:"custom_tool_call",id:b,call_id:m,name:d.name,input:x(O(d.name,d.arguments,h))}):c.push({type:"function_call",id:b,call_id:m,name:d.name,arguments:JSON.stringify(d.arguments)})}if(c.length===0)continue;p.push(...c)}else if(r.role==="toolResult"){const[c]=r.toolCallId.split("|"),t=B(i,r.content);u?.grammarToolInputProperties?.has(r.toolName)?p.push({type:"custom_tool_call_output",call_id:c,output:t}):p.push({type:"function_call_output",call_id:c,output:t});const e=[];for(const n of r.addedToolNames??[]){const s=u?.deferredTools?.get(n);!s||g.has(n)||(g.add(n),e.push(s))}if(e.length>0){const n=e.map(d=>d.name),s=`pi_tool_load_${v(`${r.toolCallId}:${n.join(",")}`)}`;p.push({type:"tool_search_call",call_id:s,execution:"client",status:"completed",arguments:{query:n.join(" "),limit:n.length}}),p.push({type:"tool_search_output",call_id:s,execution:"client",status:"completed",tools:convertResponsesTools(e,{...u?.toolOptions,deferLoading:!0})})}}I++}return p}f(convertResponsesMessages,"convertResponsesMessages");export function convertResponsesTools(i,o){const a=o?.strict===void 0?!1:o.strict,u=o?.supportsStrictMode??!0,p=o?.supportsOpenAIGrammarTools??!1;return i.map(g=>{const l=M(g,p);if(l)return{type:"custom",name:g.name,description:g.description,format:{type:"grammar",syntax:l.format,definition:l.definition},...o?.deferLoading?{defer_loading:!0}:{}};const k=z(g,u),_={type:"function",name:g.name,description:g.description,parameters:g.parameters,...o?.deferLoading?{defer_loading:!0}:{}};return u&&(_.strict=k??a),_})}f(convertResponsesTools,"convertResponsesTools");function J(i){const o=i.customInput?.property;if(o===void 0)return"";const a=i.arguments[o];return typeof a=="string"?a:""}f(J,"getCustomToolCallInput");function $(i,o,a){const u=i.customInput;if(!u)return;const p=P(u.jsonBuffer,u.property,o,a);return i.arguments={[u.property]:o},p}f($,"appendCustomToolCallInput");export async function processResponsesStream(i,o,a,u,p){let g=!1;const l=new Map,k=new Map,_=f((t,e)=>{const n=l.get(t);return n?.type===e?n:void 0},"getSlot"),y=f((t,e)=>{e!==void 0&&a.push({type:"toolcall_delta",contentIndex:t.contentIndex,delta:e,partial:o})},"pushToolCallDelta"),S=f((t,e)=>{if(e.type==="reasoning"){const n={type:"thinking",thinking:""};o.content.push(n);const s={type:"thinking",block:n,contentIndex:o.content.length-1};return l.set(t,s),a.push({type:"thinking_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="message"){const n={type:"text",text:""};o.content.push(n);const s={type:"text",block:n,contentIndex:o.content.length-1};return l.set(t,s),a.push({type:"text_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="function_call"){const n={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{},partialJson:e.arguments||""};o.content.push(n);const s={type:"toolCall",block:n,contentIndex:o.content.length-1};return l.set(t,s),a.push({type:"toolcall_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="custom_tool_call"){const n=p?.grammarToolInputProperties?.get(e.name)??"input",s=e.input||"",d={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{[n]:s},customInput:{property:n,jsonBuffer:{input:"",started:!1,closed:!1}}};o.content.push(d);const m={type:"toolCall",block:d,contentIndex:o.content.length-1};return l.set(t,m),a.push({type:"toolcall_start",contentIndex:m.contentIndex,partial:o}),m}},"createSlot"),I=f((t,e)=>l.get(t)??S(t,e),"getOrCreateSlot"),r=f(t=>{for(const e of t){if(e.type!=="reasoning"||!e.encrypted_content)continue;const n=k.get(e.id);if(!n?.thinkingSignature)continue;const s=JSON.parse(n.thinkingSignature);s.encrypted_content||(n.thinkingSignature=JSON.stringify({...s,encrypted_content:e.encrypted_content}))}},"backfillReasoningSignatures"),c=f(t=>{if(g=!0,r(t.output??[]),t?.id&&(o.responseId=t.id),t?.usage){const e=t.usage.input_tokens_details,n=e?.cached_tokens||0,s=e?.cache_write_tokens||0;o.usage={input:Math.max(0,(t.usage.input_tokens||0)-n-s),output:t.usage.output_tokens||0,cacheRead:n,cacheWrite:s,reasoning:t.usage.output_tokens_details?.reasoning_tokens||0,totalTokens:t.usage.total_tokens||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}if(R(u,o.usage),p?.applyServiceTierPricing){const e=p.resolveServiceTier?p.resolveServiceTier(t?.service_tier,p.serviceTier):t?.service_tier??p.serviceTier;p.applyServiceTierPricing(o.usage,e)}o.stopReason=E(t?.status),o.content.some(e=>e.type==="toolCall")&&o.stopReason==="stop"&&(o.stopReason="toolUse")},"finalizeResponse");for await(const t of i)if(t.type==="response.created")o.responseId=t.response.id;else if(t.type==="response.output_item.added")S(t.output_index,t.item);else if(t.type==="response.reasoning_summary_text.delta"){const e=_(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,a.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.reasoning_summary_part.done"){const e=_(t.output_index,"thinking");if(!e)continue;e.block.thinking+=`
|
|
3
3
|
|
|
4
|
-
`,
|
|
4
|
+
`,a.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:`
|
|
5
5
|
|
|
6
|
-
`,partial:o})}else if(t.type==="response.reasoning_text.delta"){const e=_(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,
|
|
6
|
+
`,partial:o})}else if(t.type==="response.reasoning_text.delta"){const e=_(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,a.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.output_text.delta"){const e=_(t.output_index,"text");if(!e)continue;e.block.text+=t.delta,a.push({type:"text_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.refusal.delta"){const e=_(t.output_index,"text");if(!e)continue;e.block.text+=t.delta,a.push({type:"text_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.function_call_arguments.delta"){const e=_(t.output_index,"toolCall");if(!e||e.block.partialJson===void 0)continue;e.block.partialJson+=t.delta,e.block.arguments=C(e.block.partialJson),y(e,t.delta)}else if(t.type==="response.function_call_arguments.done"){const e=_(t.output_index,"toolCall");if(!e||e.block.partialJson===void 0)continue;const n=e.block.partialJson;if(e.block.partialJson=t.arguments,e.block.arguments=C(e.block.partialJson),t.arguments.startsWith(n)){const s=t.arguments.slice(n.length);s.length>0&&y(e,s)}}else if(t.type==="response.custom_tool_call_input.delta"){const e=_(t.output_index,"toolCall");if(!e||!e.block.customInput)continue;y(e,$(e.block,J(e.block)+t.delta,!1))}else if(t.type==="response.custom_tool_call_input.done"){const e=_(t.output_index,"toolCall");if(!e||!e.block.customInput)continue;y(e,$(e.block,t.input,!0))}else if(t.type==="response.output_item.done"){const e=t.item,n=I(t.output_index,e);if(e.type==="reasoning"&&n?.type==="thinking"){const s=e.summary?.map(m=>m.text).join(`
|
|
7
7
|
|
|
8
|
-
`)||"",
|
|
8
|
+
`)||"",d=e.content?.map(m=>m.text).join(`
|
|
9
9
|
|
|
10
|
-
`)||"";n.block.thinking=s||
|
|
10
|
+
`)||"";n.block.thinking=s||d||n.block.thinking,n.block.thinkingSignature=JSON.stringify(e),k.set(e.id,n.block),a.push({type:"thinking_end",contentIndex:n.contentIndex,content:n.block.thinking,partial:o}),l.delete(t.output_index)}else e.type==="message"&&n?.type==="text"?(n.block.text=e.content?.map(s=>s.type==="output_text"?s.text:s.refusal).join("")||"",n.block.textSignature=j(e.id,e.phase??void 0),a.push({type:"text_end",contentIndex:n.contentIndex,content:n.block.text,partial:o}),l.delete(t.output_index)):e.type==="function_call"&&n?.type==="toolCall"&&n.block.partialJson!==void 0?(n.block.arguments=C(e.arguments||n.block.partialJson||"{}"),delete n.block.partialJson,a.push({type:"toolcall_end",contentIndex:n.contentIndex,toolCall:n.block,partial:o}),l.delete(t.output_index)):e.type==="custom_tool_call"&&n?.type==="toolCall"&&n.block.customInput&&(y(n,$(n.block,e.input??J(n.block),!0)),delete n.block.customInput,a.push({type:"toolcall_end",contentIndex:n.contentIndex,toolCall:n.block,partial:o}),l.delete(t.output_index))}else if(t.type==="response.completed"||t.type==="response.incomplete")c(t.response);else{if(t.type==="error")throw new Error(`Error Code ${t.code}: ${t.message}`||"Unknown error");if(t.type==="response.failed"){g=!0;const e=t.response?.error,n=t.response?.incomplete_details,s=e?`${e.code||"unknown"}: ${e.message||"no message"}`:n?.reason?`incomplete: ${n.reason}`:"Unknown error (no error details in response)";throw new Error(s)}}if(!g)throw new Error("OpenAI Responses stream ended before a terminal response event")}f(processResponsesStream,"processResponsesStream");function E(i){if(!i)return"stop";switch(i){case"completed":return"stop";case"incomplete":return"length";case"failed":case"cancelled":return"error";case"in_progress":case"queued":return"stop";default:{const o=i;throw new Error(`Unhandled stop reason: ${o}`)}}}f(E,"mapStopReason");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var I=Object.defineProperty;var
|
|
1
|
+
var I=Object.defineProperty;var n=(e,o)=>I(e,"name",{value:o,configurable:!0});import P from"openai";import{clampThinkingLevel as S}from"../models.js";import{splitDeferredTools as C}from"../utils/deferred-tools.js";import{formatProviderError as w,normalizeProviderError as M}from"../utils/error-body.js";import{AssistantMessageEventStream as _}from"../utils/event-stream.js";import{headersToRecord as b}from"../utils/headers.js";import{getProviderEnvValue as x}from"../utils/provider-env.js";import{retryProviderRequest as k}from"../utils/provider-retry.js";import{createGrammarToolInputProperties as g}from"./constrained-sampling.js";import{buildCopilotDynamicHeaders as L,hasCopilotVisionInput as G}from"./github-copilot-headers.js";import{clampOpenAIPromptCacheKey as D}from"./openai-prompt-cache.js";import{convertResponsesMessages as N,convertResponsesTools as K,processResponsesStream as F}from"./openai-responses-shared.js";import{buildBaseOptions as U}from"./simple-options.js";const q=new Set(["openai","openai-codex","opencode"]),H=16;function R(e,o){if(!e)return!1;const r=o.toLowerCase();for(const[t,s]of Object.entries(e))if(t.toLowerCase()===r&&s!==null&&s.trim().length>0)return!0;return!1}n(R,"hasHeader");function v(e,o,r){if(o)return o;if(R(r,"authorization")||R(r,"cf-aig-authorization"))return"unused";throw new Error(`No API key for provider: ${e}`)}n(v,"getClientApiKey");function W(e){return e.provider==="openrouter"||e.baseUrl.includes("openrouter.ai")?"openrouter":"openai"}n(W,"detectSessionAffinityFormat");function y(e,o){return e||(x("PI_CACHE_RETENTION",o)==="long"?"long":"short")}n(y,"resolveCacheRetention");function l(e){return{supportsDeveloperRole:e.compat?.supportsDeveloperRole??!0,sessionAffinityFormat:e.compat?.sessionAffinityFormat??W(e),supportsLongCacheRetention:e.compat?.supportsLongCacheRetention??!0,supportsStrictMode:e.compat?.supportsStrictMode??!1,supportsOpenAIGrammarTools:e.compat?.supportsOpenAIGrammarTools??!1,supportsToolSearch:e.compat?.supportsToolSearch??!1,supportsExplicitPromptCacheMode:e.compat?.supportsExplicitPromptCacheMode??!1}}n(l,"getCompat");function j(e,o){return o==="long"&&e.supportsLongCacheRetention?"24h":void 0}n(j,"getPromptCacheRetention");function z(e){return w(M(e),"OpenAI API error")}n(z,"formatOpenAIResponsesError");export const stream=n((e,o,r)=>{const t=new _;return(async()=>{const s={role:"assistant",content:[],api:e.api,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{const c=v(e.provider,r?.apiKey,r?.headers),p=y(r?.cacheRetention,r?.env)==="none"?void 0:r?.sessionId,u=l(e),i=g(o.tools,u.supportsOpenAIGrammarTools),f=V(e,o,c,r?.headers,p);let m=B(e,o,r,u,i);const d=await r?.onPayload?.(m,e);d!==void 0&&(m=d);const T={...r?.signal?{signal:r.signal}:{},...r?.timeoutMs!==void 0?{timeout:r.timeoutMs}:{},maxRetries:0},{data:A,response:h}=await k(()=>f.responses.create(m,T).withResponse(),{maxRetries:r?.maxRetries,maxRetryDelayMs:r?.maxRetryDelayMs,signal:r?.signal});if(await r?.onResponse?.({status:h.status,headers:b(h.headers)},e),t.push({type:"start",partial:s}),await F(A,s,t,e,{serviceTier:r?.serviceTier,grammarToolInputProperties:i,applyServiceTierPricing:n((O,E)=>$(O,E,e),"applyServiceTierPricing")}),r?.signal?.aborted)throw new Error("Request was aborted");if(s.stopReason==="aborted"||s.stopReason==="error")throw new Error("An unknown error occurred");t.push({type:"done",reason:s.stopReason,message:s}),t.end()}catch(c){for(const a of s.content)delete a.index,delete a.partialJson,delete a.customInput;s.stopReason=r?.signal?.aborted?"aborted":"error",s.errorMessage=z(c),t.push({type:"error",reason:s.stopReason,error:s}),t.end()}})(),t},"stream"),streamSimple=n((e,o,r)=>{v(e.provider,r?.apiKey,r?.headers);const t=U(e,o,r,r?.apiKey),s=r?.reasoning?S(e,r.reasoning):void 0;return stream(e,o,{...t,reasoningEffort:s==="off"?void 0:s})},"streamSimple");function V(e,o,r,t,s){const c=l(e),a={...e.headers};if(e.provider==="github-copilot"){const p=G(o.messages),u=L({messages:o.messages,hasImages:p});Object.assign(a,u)}return s&&(c.sessionAffinityFormat==="openrouter"?a["x-session-id"]=s:(c.sessionAffinityFormat==="openai"&&(a.session_id=s),a["x-client-request-id"]=s)),t&&Object.assign(a,t),new P({apiKey:r,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:a})}n(V,"createClient");function B(e,o,r,t=l(e),s=g(o.tools,t.supportsOpenAIGrammarTools)){const c=C(o,t.supportsToolSearch),a=N(e,o,q,{grammarToolInputProperties:s,deferredTools:c.deferred,toolOptions:{supportsStrictMode:t.supportsStrictMode,supportsOpenAIGrammarTools:t.supportsOpenAIGrammarTools}}),p=y(r?.cacheRetention,r?.env),u=p==="none"&&t.supportsExplicitPromptCacheMode,i={model:e.id,input:a,stream:!0,prompt_cache_key:p==="none"?void 0:D(r?.sessionId),prompt_cache_retention:j(t,p),prompt_cache_options:u?{mode:"explicit"}:void 0,store:!1};if(r?.maxTokens&&(i.max_output_tokens=Math.max(r.maxTokens,H)),r?.temperature!==void 0&&(i.temperature=r?.temperature),r?.serviceTier!==void 0&&(i.service_tier=r.serviceTier),c.immediate.length>0&&(i.tools=K(c.immediate,{supportsStrictMode:t.supportsStrictMode,supportsOpenAIGrammarTools:t.supportsOpenAIGrammarTools})),r?.toolChoice!==void 0&&(i.tool_choice=r.toolChoice),e.reasoning){if(r?.reasoningEffort||r?.reasoningSummary){const f=r?.reasoningEffort?e.thinkingLevelMap?.[r.reasoningEffort]??r.reasoningEffort:"medium";i.reasoning={effort:f,summary:r?.reasoningSummary||"auto"},i.include=["reasoning.encrypted_content"]}else e.provider!=="github-copilot"&&e.thinkingLevelMap?.off!==null&&(i.reasoning={effort:e.thinkingLevelMap?.off??"none"});e.provider==="xai"&&(i.include=["reasoning.encrypted_content"])}return i}n(B,"buildParams");function J(e,o){switch(o){case"flex":return .5;case"priority":return e.id==="gpt-5.5"?2.5:2;default:return 1}}n(J,"getServiceTierCostMultiplier");function $(e,o,r){const t=J(r,o);t!==1&&(e.cost.input*=t,e.cost.output*=t,e.cost.cacheRead*=t,e.cost.cacheWrite*=t,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}n($,"applyServiceTierPricing");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var R=Object.defineProperty;var u=(e,r)=>R(e,"name",{value:r,configurable:!0});import x from"openai";import{formatProviderError as _,normalizeProviderError as k}from"../utils/error-body.js";import{headersToRecord as w,providerHeadersToRecord as T}from"../utils/headers.js";import{retryProviderRequest as v}from"../utils/provider-retry.js";import{sanitizeSurrogates as b}from"../utils/sanitize-unicode.js";export const generateImages=u(async(e,r,t)=>{const a={api:e.api,provider:e.provider,model:e.id,output:[],stopReason:"stop",timestamp:Date.now()};try{const s=t?.apiKey;if(!s)throw new Error(`No API key for provider: ${e.provider}`);const c=M(e,s,t?.headers
|
|
1
|
+
var R=Object.defineProperty;var u=(e,r)=>R(e,"name",{value:r,configurable:!0});import x from"openai";import{formatProviderError as _,normalizeProviderError as k}from"../utils/error-body.js";import{headersToRecord as w,providerHeadersToRecord as T}from"../utils/headers.js";import{retryProviderRequest as v}from"../utils/provider-retry.js";import{sanitizeSurrogates as b}from"../utils/sanitize-unicode.js";export const generateImages=u(async(e,r,t)=>{const a={api:e.api,provider:e.provider,model:e.id,output:[],stopReason:"stop",timestamp:Date.now()};try{const s=t?.apiKey;if(!s)throw new Error(`No API key for provider: ${e.provider}`);const c=M(e,s,t?.headers);let n=P(e,r);const i=await t?.onPayload?.(n,e);i!==void 0&&(n=i);const o={...t?.signal?{signal:t.signal}:{},...t?.timeoutMs!==void 0?{timeout:t.timeoutMs}:{},maxRetries:0},{data:y,response:l}=await v(()=>c.chat.completions.create(n,o).withResponse(),{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal});await t?.onResponse?.({status:l.status,headers:w(l.headers)},e);const p=y;a.responseId=p.id,p.usage&&(a.usage=W(p.usage,e));const m=p.choices[0];if(m){const d=m.message.content;typeof d=="string"&&d.length>0&&a.output.push({type:"text",text:d});for(const h of m.message.images??[]){const f=typeof h.image_url=="string"?h.image_url:h.image_url?.url;if(!f?.startsWith("data:"))continue;const g=f.match(/^data:([^;]+);base64,(.+)$/);g&&a.output.push({type:"image",mimeType:g[1],data:g[2]})}}return a}catch(s){return a.stopReason=t?.signal?.aborted?"aborted":"error",a.errorMessage=_(k(s)),a}},"generateImages");function M(e,r,t){return new x({apiKey:r,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:T({...e.headers,...t})})}u(M,"createClient");function P(e,r){const t=r.input.map(a=>a.type==="text"?{type:"text",text:b(a.text)}:{type:"image_url",image_url:{url:`data:${a.mimeType};base64,${a.data}`}});return{model:e.id,messages:[{role:"user",content:t}],stream:!1,modalities:e.output.includes("text")?["image","text"]:["image"]}}u(P,"buildParams");function W(e,r){const t=e.prompt_tokens||0,a=e.prompt_tokens_details?.cached_tokens||0,s=e.prompt_tokens_details?.cache_write_tokens||0,c=s>0?Math.max(0,a-s):a,n=Math.max(0,t-c-s),i=e.completion_tokens||0,o={input:n,output:i,cacheRead:c,cacheWrite:s,totalTokens:n+i+c+s,cost:{input:r.cost.input/1e6*n,output:r.cost.output/1e6*i,cacheRead:r.cost.cacheRead/1e6*c,cacheWrite:r.cost.cacheWrite/1e6*s,total:0}};return o.cost.total=o.cost.input+o.cost.output+o.cost.cacheRead+o.cost.cacheWrite,o}u(W,"parseUsage");
|