shortcutxl 0.3.76 → 0.3.78
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/BINARY-INVENTORY.json +813 -813
- package/CHANGELOG.md +14 -0
- package/dist/ai/models.d.ts +10 -6
- package/dist/ai/models.generated.d.ts +72 -0
- package/dist/ai/models.generated.js +33 -0
- package/dist/ai/models.js +36 -13
- package/dist/ai/providers/anthropic.d.ts +4 -2
- package/dist/ai/providers/anthropic.js +59 -29
- package/dist/ai/providers/azure-openai-responses.d.ts +2 -1
- package/dist/ai/providers/azure-openai-responses.js +4 -20
- package/dist/ai/providers/google-vertex.d.ts +8 -2
- package/dist/ai/providers/google-vertex.js +66 -54
- package/dist/ai/providers/google.js +15 -48
- package/dist/ai/providers/openai-completions.d.ts +4 -1
- package/dist/ai/providers/openai-completions.js +26 -10
- package/dist/ai/providers/openai-reasoning.d.ts +5 -0
- package/dist/ai/providers/openai-reasoning.js +13 -0
- package/dist/ai/providers/openai-responses-shared.js +1 -1
- package/dist/ai/providers/openai-responses.d.ts +6 -2
- package/dist/ai/providers/openai-responses.js +28 -23
- package/dist/ai/providers/simple-options.d.ts +2 -3
- package/dist/ai/providers/simple-options.js +4 -6
- package/dist/ai/types.d.ts +19 -2
- package/dist/app/agent-session-runtime-adapter.js +7 -6
- package/dist/app/agent-session.d.ts +0 -15
- package/dist/app/agent-session.js +0 -37
- package/dist/app/approvals/approval-errors.d.ts +15 -0
- package/dist/app/approvals/approval-errors.js +14 -0
- package/dist/app/approvals/runtime-approval-gates.d.ts +1 -2
- package/dist/app/approvals/tool-approval.d.ts +1 -0
- package/dist/app/approvals/tool-approval.js +11 -23
- package/dist/app/approvals/types.d.ts +0 -14
- package/dist/app/approvals/types.js +0 -2
- package/dist/app/background/tool-summaries.js +0 -2
- package/dist/app/extensions/slash-commands.js +1 -3
- package/dist/app/local/tools/execute-code/executor.d.ts +1 -1
- package/dist/app/local/tools/execute-code/executor.js +20 -10
- package/dist/app/local/tools/execute-code/tool.js +21 -2
- package/dist/app/modes/action/agent.js +4 -5
- package/dist/app/modes/ask/agent.js +4 -6
- package/dist/app/modes/index.js +20 -10
- package/dist/app/modes/installation/agent.js +4 -5
- package/dist/app/modes/manage/agent.js +3 -4
- package/dist/app/modes/manage/prompt.js +1 -2
- package/dist/app/modes/metadata.d.ts +31 -0
- package/dist/app/modes/metadata.js +35 -0
- package/dist/app/modes/plan/agent.js +5 -8
- package/dist/app/modes/plan/prompt.js +3 -3
- package/dist/app/permissions/runtime-approval-flow.d.ts +1 -5
- package/dist/app/permissions/runtime-approval-flow.js +0 -28
- package/dist/app/permissions/tool-gates.d.ts +2 -3
- package/dist/app/permissions/tool-gates.js +3 -81
- package/dist/app/prompts/com-api.js +1 -1
- package/dist/app/prompts/shared-guidelines.js +7 -3
- package/dist/app/providers/google-vertex-gateway.js +4 -51
- package/dist/app/providers/model-registry.d.ts +1 -0
- package/dist/app/providers/model-registry.js +39 -0
- package/dist/app/providers/model-resolver.js +10 -7
- package/dist/app/providers/register-shortcut-provider.js +6 -6
- package/dist/app/providers/shortcut-api-v2-transport.js +4 -0
- package/dist/app/providers/shortcut-llm-proxy-client.d.ts +2 -2
- package/dist/app/providers/shortcut-llm-proxy-client.js +1 -0
- package/dist/app/resources/package-manager.js +2 -123
- package/dist/app/resources/resource-patterns.d.ts +9 -0
- package/dist/app/resources/resource-patterns.js +120 -0
- package/dist/app/session/forked-agent.d.ts +2 -2
- package/dist/app/session/model-manager.js +3 -2
- package/dist/app/session/session-lifecycle.js +3 -2
- package/dist/app/session/session-models.d.ts +2 -0
- package/dist/app/session/session-models.js +14 -6
- package/dist/app/settings-manager.d.ts +3 -3
- package/dist/app/shared/tools/execute-code/mog.d.ts +3 -1
- package/dist/app/shared/tools/execute-code/mog.js +18 -2
- package/dist/app/tools/bash.js +3 -3
- package/dist/app/tools/execute-code/index.d.ts +1 -0
- package/dist/app/tools/execute-code/index.js +3 -1
- package/dist/app/tools/find-ignore-files.d.ts +3 -0
- package/dist/app/tools/find-ignore-files.js +33 -0
- package/dist/app/tools/find.js +2 -21
- package/dist/app/tools/llm-analysis.js +0 -2
- package/dist/app/tools/refresh-context.d.ts +1 -1
- package/dist/app/tools/session-settings/update-session-settings.js +2 -2
- package/dist/app/tools/switch-mode.js +2 -2
- package/dist/app/tools/take-screenshot.js +0 -2
- package/dist/app/tools/task/runner.js +1 -2
- package/dist/app/tools/task/task.d.ts +1 -3
- package/dist/app/tools/task/task.js +20 -40
- package/dist/app/tools/web-search.js +12 -2
- package/dist/autocomplete/core.d.ts +33 -0
- package/dist/autocomplete/core.js +113 -0
- package/dist/{tui → autocomplete}/fuzzy.d.ts +0 -1
- package/dist/{tui → autocomplete}/fuzzy.js +0 -1
- package/dist/{tui/autocomplete.d.ts → autocomplete/index.d.ts} +0 -1
- package/dist/{tui/autocomplete.js → autocomplete/index.js} +62 -158
- package/dist/cli/args.js +1 -1
- package/dist/cli/list-models.js +1 -1
- package/dist/cli.js +26227 -30480
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -3
- package/dist/contracts/agent-session-store.d.ts +1 -1
- package/dist/contracts/agent-settings.d.ts +1 -0
- package/dist/contracts/agent-settings.js +2 -1
- package/dist/contracts/model-call.d.ts +1 -2
- package/dist/contracts/model-call.js +1 -2
- package/dist/contracts/model-stream.d.ts +1 -0
- package/dist/contracts/model-stream.js +1 -0
- package/dist/contracts/wire.d.ts +10 -7
- package/dist/contracts/wire.js +8 -0
- package/dist/core/agent-engine.js +1 -1
- package/dist/core/core-types.d.ts +1 -21
- package/dist/core/defaults.d.ts +1 -1
- package/dist/core/defaults.js +9 -1
- package/dist/core/prompts/agent-guidelines.d.ts +4 -5
- package/dist/core/prompts/agent-guidelines.js +28 -42
- package/dist/core/session-schema.d.ts +1 -1
- package/dist/embedded-agent/ai-invoke.d.ts +1 -2
- package/dist/embedded-agent/ai-invoke.js +2 -70
- package/dist/embedded-agent/anthropic-messages-transport.d.ts +4 -20
- package/dist/embedded-agent/anthropic-messages-transport.js +23 -786
- package/dist/embedded-agent/bootstrap.js +2 -2
- package/dist/embedded-agent/compose.js +8 -7
- package/dist/embedded-agent/gateway-base-url.d.ts +3 -0
- package/dist/embedded-agent/gateway-base-url.js +35 -0
- package/dist/embedded-agent/google-vertex-transport.d.ts +2 -11
- package/dist/embedded-agent/google-vertex-transport.js +20 -117
- package/dist/embedded-agent/host-runtime-options.d.ts +0 -8
- package/dist/embedded-agent/host-runtime-options.js +10 -2
- package/dist/embedded-agent/host-tools/invoke-llm/contract.d.ts +2 -2
- package/dist/embedded-agent/host-tools/invoke-llm/contract.js +4 -2
- package/dist/embedded-agent/host-tools/sandbox-llm/contract.d.ts +8 -3
- package/dist/embedded-agent/host-tools/sandbox-llm/contract.js +12 -8
- package/dist/embedded-agent/host-tools/sandbox-llm/index.d.ts +1 -1
- package/dist/embedded-agent/host-tools/sandbox-llm/index.js +1 -1
- package/dist/embedded-agent/host-tools/shared/index.d.ts +1 -1
- package/dist/embedded-agent/host-tools/shared/index.js +1 -1
- package/dist/embedded-agent/host-tools/shared/llm-stream-error.d.ts +7 -0
- package/dist/embedded-agent/host-tools/shared/llm-stream-error.js +10 -0
- package/dist/embedded-agent/host-tools/take-screenshot/contract.d.ts +0 -2
- package/dist/embedded-agent/host-tools/take-screenshot/contract.js +1 -3
- package/dist/embedded-agent/host-tools/take-screenshot/index.d.ts +1 -1
- package/dist/embedded-agent/host-tools/take-screenshot/index.js +1 -1
- package/dist/embedded-agent/host-tools/task/agents/clone.js +1 -2
- package/dist/embedded-agent/host-tools/task/contract.js +1 -1
- package/dist/embedded-agent/index.d.ts +3 -4
- package/dist/embedded-agent/index.js +2 -3
- package/dist/embedded-agent/model-selection.d.ts +0 -6
- package/dist/embedded-agent/model-selection.js +15 -8
- package/dist/embedded-agent/openai-completions-transport.d.ts +2 -11
- package/dist/embedded-agent/openai-completions-transport.js +20 -120
- package/dist/embedded-agent/openai-responses-transport.d.ts +2 -11
- package/dist/embedded-agent/openai-responses-transport.js +15 -170
- package/dist/embedded-agent/prompt/build.js +1 -2
- package/dist/embedded-agent/prompt/sections.d.ts +1 -1
- package/dist/embedded-agent/prompt/sections.js +2 -0
- package/dist/embedded-agent/provider-native-request.d.ts +29 -0
- package/dist/embedded-agent/provider-native-request.js +65 -0
- package/dist/embedded-agent/run-stats.d.ts +1 -1
- package/dist/embedded-agent/stream.d.ts +10 -96
- package/dist/embedded-agent/stream.js +31 -556
- package/dist/embedded-agent/suggestions.d.ts +1 -1
- package/dist/embedded-agent/suggestions.js +1 -1
- package/dist/embedded-agent/worker-bridge/host-client.d.ts +7 -0
- package/dist/embedded-agent/worker-bridge/host-client.js +15 -0
- package/dist/embedded-agent/worker-bridge/worker-port.js +17 -1
- package/dist/main.js +18 -14
- package/dist/rpc/index.d.ts +1 -1
- package/dist/rpc/rpc-approval-gates.js +1 -2
- package/dist/rpc/rpc-host.d.ts +4 -0
- package/dist/rpc/rpc-host.js +13 -24
- package/dist/rpc/rpc-types.d.ts +6 -17
- package/dist/shared/platform/open.d.ts +4 -1
- package/dist/shared/platform/open.js +14 -2
- package/dist/shell/approvals/runtime-approval-gates.js +1 -3
- package/dist/shell/components/selectors/model-selector.js +2 -1
- package/dist/shell/components/selectors/session-selector-search.js +1 -1
- package/dist/shell/components/selectors/thinking-selector.js +7 -6
- package/dist/shell/index.d.ts +0 -1
- package/dist/shell/index.js +0 -1
- package/dist/shell/interactive/interactive-mode-options.d.ts +10 -0
- package/dist/shell/interactive/interactive-mode.d.ts +6 -12
- package/dist/shell/interactive/interactive-mode.js +39 -158
- package/dist/shell/interactive/slash-commands.d.ts +0 -34
- package/dist/shell/interactive/slash-commands.js +0 -2
- package/dist/shell/links/local-file-link-input.d.ts +15 -0
- package/dist/shell/links/local-file-link-input.js +38 -0
- package/dist/shell/links/local-file-link.d.ts +7 -0
- package/dist/shell/links/local-file-link.js +35 -0
- package/dist/shell/links/local-file-opener.d.ts +16 -0
- package/dist/shell/links/local-file-opener.js +90 -0
- package/dist/shell/session-client.d.ts +0 -1
- package/dist/shell/session-client.js +0 -6
- package/dist/shell/status/update-check-scheduler.d.ts +30 -0
- package/dist/shell/status/update-check-scheduler.js +71 -0
- package/dist/shell/status/update-reminder-controller.d.ts +22 -0
- package/dist/shell/status/update-reminder-controller.js +40 -0
- package/dist/shell/status/update-reminder.d.ts +6 -0
- package/dist/shell/status/update-reminder.js +4 -0
- package/dist/shell/theme/dark.json +1 -2
- package/dist/shell/theme/light.json +1 -2
- package/dist/shell/theme/runtime.d.ts +2 -3
- package/dist/shell/theme/runtime.js +2 -6
- package/dist/shell/theme/theme-schema.json +1 -6
- package/dist/shortcut-model-catalog.d.ts +7 -2
- package/dist/shortcut-model-catalog.js +134 -10
- package/dist/startup/update-manager.d.ts +6 -6
- package/dist/startup/update-manager.js +23 -38
- package/dist/startup/update-prompt.d.ts +1 -0
- package/dist/startup/update-prompt.js +2 -2
- package/dist/tui/components/editor.d.ts +1 -1
- package/dist/tui/components/editor.js +1 -1
- package/dist/tui/components/markdown.js +15 -6
- package/dist/tui/components/settings-list.js +1 -1
- package/dist/tui/editor-component.d.ts +1 -1
- package/dist/tui/index.d.ts +7 -8
- package/dist/tui/index.js +7 -6
- package/dist/tui/tui.d.ts +2 -0
- package/dist/tui/tui.js +16 -1
- package/dist/tui/utils.d.ts +7 -0
- package/dist/tui/utils.js +58 -8
- package/native-app/main/index.js +3200 -48
- package/native-app/main/{photon_rs-SoVDgheu.js → photon_rs-XkYyYTVA.js} +2 -2
- package/native-app/package.json +1 -1
- package/native-app/preload/index.cjs +2 -0
- package/native-app/renderer/assets/{index-CFc-oZuS.js → index-B4jz6epR.js} +825 -155
- package/native-app/renderer/assets/{index-OhGE0UY4.css → index-C__g36ft.css} +412 -162
- package/native-app/renderer/assets/shortcutagent-DxFsGSkw.png +0 -0
- package/native-app/renderer/index.html +2 -2
- package/package.json +17 -3
- package/skills/add-custom-model/SKILL.md +52 -0
- package/user-docs/dist/index.html +1 -1
- package/user-docs/dist/shortcutxl-docs.pdf +0 -0
- package/xll/ShortcutXL.xll +0 -0
- package/xll/modules/shortcut_xl/_managed.py +26 -7
- package/xll/modules/shortcut_xl/_tracking.py +141 -251
- package/xll/modules/shortcut_xl/api/__init__.py +60 -0
- package/xll/modules/shortcut_xl/api/workbook.py +9 -1
- package/xll/modules/shortcut_xl/api/worksheet.py +4 -1
- package/xll/python/Lib/site-packages/httpx-0.28.1.dist-info/RECORD +1 -1
- package/xll/python/Lib/site-packages/idna-3.18.dist-info/RECORD +1 -1
- package/xll/python/Lib/site-packages/pip/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/build_env/__init__.py +25 -0
- package/xll/python/Lib/site-packages/pip/_internal/build_env/base.py +103 -0
- package/xll/python/Lib/site-packages/pip/_internal/build_env/installer.py +333 -0
- package/xll/python/Lib/site-packages/pip/_internal/build_env/noop.py +42 -0
- package/xll/python/Lib/site-packages/pip/_internal/build_env/venv.py +145 -0
- package/xll/python/Lib/site-packages/pip/_internal/build_env/virtual.py +139 -0
- package/xll/python/Lib/site-packages/pip/_internal/cache.py +4 -1
- package/xll/python/Lib/site-packages/pip/_internal/cli/autocompletion.py +4 -1
- package/xll/python/Lib/site-packages/pip/_internal/cli/base_command.py +11 -14
- package/xll/python/Lib/site-packages/pip/_internal/cli/cmdoptions.py +133 -22
- package/xll/python/Lib/site-packages/pip/_internal/cli/index_command.py +11 -6
- package/xll/python/Lib/site-packages/pip/_internal/cli/main.py +2 -1
- package/xll/python/Lib/site-packages/pip/_internal/cli/main_parser.py +1 -2
- package/xll/python/Lib/site-packages/pip/_internal/cli/parser.py +10 -2
- package/xll/python/Lib/site-packages/pip/_internal/cli/progress_bars.py +2 -2
- package/xll/python/Lib/site-packages/pip/_internal/cli/req_command.py +57 -25
- package/xll/python/Lib/site-packages/pip/_internal/cli/status_codes.py +1 -0
- package/xll/python/Lib/site-packages/pip/_internal/commands/cache.py +7 -6
- package/xll/python/Lib/site-packages/pip/_internal/commands/configuration.py +2 -1
- package/xll/python/Lib/site-packages/pip/_internal/commands/debug.py +4 -5
- package/xll/python/Lib/site-packages/pip/_internal/commands/download.py +4 -0
- package/xll/python/Lib/site-packages/pip/_internal/commands/freeze.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/commands/index.py +10 -3
- package/xll/python/Lib/site-packages/pip/_internal/commands/inspect.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/commands/install.py +6 -6
- package/xll/python/Lib/site-packages/pip/_internal/commands/list.py +11 -6
- package/xll/python/Lib/site-packages/pip/_internal/commands/lock.py +4 -6
- package/xll/python/Lib/site-packages/pip/_internal/commands/show.py +14 -8
- package/xll/python/Lib/site-packages/pip/_internal/commands/wheel.py +7 -1
- package/xll/python/Lib/site-packages/pip/_internal/configuration.py +2 -3
- package/xll/python/Lib/site-packages/pip/_internal/distributions/base.py +5 -3
- package/xll/python/Lib/site-packages/pip/_internal/distributions/installed.py +3 -2
- package/xll/python/Lib/site-packages/pip/_internal/distributions/sdist.py +45 -20
- package/xll/python/Lib/site-packages/pip/_internal/distributions/wheel.py +3 -2
- package/xll/python/Lib/site-packages/pip/_internal/exceptions.py +174 -0
- package/xll/python/Lib/site-packages/pip/_internal/index/collector.py +70 -48
- package/xll/python/Lib/site-packages/pip/_internal/index/package_finder.py +46 -7
- package/xll/python/Lib/site-packages/pip/_internal/index/sources.py +1 -2
- package/xll/python/Lib/site-packages/pip/_internal/locations/_sysconfig.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/locations/base.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/metadata/base.py +10 -5
- package/xll/python/Lib/site-packages/pip/_internal/metadata/importlib/_dists.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/metadata/importlib/_envs.py +8 -3
- package/xll/python/Lib/site-packages/pip/_internal/models/candidate.py +5 -1
- package/xll/python/Lib/site-packages/pip/_internal/models/link.py +53 -13
- package/xll/python/Lib/site-packages/pip/_internal/network/auth.py +38 -21
- package/xll/python/Lib/site-packages/pip/_internal/network/cache.py +2 -2
- package/xll/python/Lib/site-packages/pip/_internal/network/download.py +58 -11
- package/xll/python/Lib/site-packages/pip/_internal/network/session.py +35 -40
- package/xll/python/Lib/site-packages/pip/_internal/network/utils.py +109 -1
- package/xll/python/Lib/site-packages/pip/_internal/operations/check.py +2 -3
- package/xll/python/Lib/site-packages/pip/_internal/operations/install/wheel.py +23 -18
- package/xll/python/Lib/site-packages/pip/_internal/operations/prepare.py +152 -7
- package/xll/python/Lib/site-packages/pip/_internal/req/__init__.py +2 -0
- package/xll/python/Lib/site-packages/pip/_internal/req/constructors.py +54 -69
- package/xll/python/Lib/site-packages/pip/_internal/req/req_file.py +6 -6
- package/xll/python/Lib/site-packages/pip/_internal/req/req_install.py +25 -21
- package/xll/python/Lib/site-packages/pip/_internal/req/req_uninstall.py +13 -8
- package/xll/python/Lib/site-packages/pip/_internal/resolution/base.py +2 -2
- package/xll/python/Lib/site-packages/pip/_internal/resolution/legacy/resolver.py +2 -2
- package/xll/python/Lib/site-packages/pip/_internal/resolution/resolvelib/base.py +1 -1
- package/xll/python/Lib/site-packages/pip/_internal/resolution/resolvelib/candidates.py +0 -1
- package/xll/python/Lib/site-packages/pip/_internal/resolution/resolvelib/factory.py +39 -52
- package/xll/python/Lib/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py +3 -3
- package/xll/python/Lib/site-packages/pip/_internal/resolution/resolvelib/provider.py +3 -0
- package/xll/python/Lib/site-packages/pip/_internal/resolution/resolvelib/resolver.py +9 -0
- package/xll/python/Lib/site-packages/pip/_internal/utils/compat.py +15 -9
- package/xll/python/Lib/site-packages/pip/_internal/utils/deprecation.py +6 -1
- package/xll/python/Lib/site-packages/pip/_internal/utils/filesystem.py +2 -2
- package/xll/python/Lib/site-packages/pip/_internal/utils/logging.py +11 -3
- package/xll/python/Lib/site-packages/pip/_internal/utils/misc.py +48 -4
- package/xll/python/Lib/site-packages/pip/_internal/utils/pylock.py +18 -2
- package/xll/python/Lib/site-packages/pip/_internal/utils/retry.py +2 -1
- package/xll/python/Lib/site-packages/pip/_internal/utils/subprocess.py +4 -3
- package/xll/python/Lib/site-packages/pip/_internal/utils/temp_dir.py +1 -2
- package/xll/python/Lib/site-packages/pip/_internal/utils/unpacking.py +30 -4
- package/xll/python/Lib/site-packages/pip/_internal/utils/urls.py +5 -2
- package/xll/python/Lib/site-packages/pip/_internal/utils/virtualenv.py +2 -36
- package/xll/python/Lib/site-packages/pip/_internal/vcs/git.py +8 -5
- package/xll/python/Lib/site-packages/pip/_internal/vcs/versioncontrol.py +1 -2
- package/xll/python/Lib/site-packages/pip/_internal/wheel_builder.py +5 -1
- package/xll/python/Lib/site-packages/pip/_vendor/bom.cdx.json +231 -0
- package/xll/python/Lib/site-packages/pip/_vendor/certifi/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/certifi/cacert.pem +0 -631
- package/xll/python/Lib/site-packages/pip/_vendor/distlib/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/distlib/compat.py +34 -64
- package/xll/python/Lib/site-packages/pip/_vendor/distlib/resources.py +28 -14
- package/xll/python/Lib/site-packages/pip/_vendor/distlib/scripts.py +7 -3
- package/xll/python/Lib/site-packages/pip/_vendor/distlib/util.py +48 -11
- package/xll/python/Lib/site-packages/pip/_vendor/idna/LICENSE.md +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/idna/__main__.py +6 -0
- package/xll/python/Lib/site-packages/pip/_vendor/idna/cli.py +128 -0
- package/xll/python/Lib/site-packages/pip/_vendor/idna/codec.py +50 -13
- package/xll/python/Lib/site-packages/pip/_vendor/idna/compat.py +26 -0
- package/xll/python/Lib/site-packages/pip/_vendor/idna/core.py +352 -141
- package/xll/python/Lib/site-packages/pip/_vendor/idna/idnadata.py +571 -2983
- package/xll/python/Lib/site-packages/pip/_vendor/idna/intranges.py +5 -7
- package/xll/python/Lib/site-packages/pip/_vendor/idna/package_data.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/idna/uts46data.py +16887 -8832
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/__init__.py +352 -66
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/__main__.py +11 -0
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/_xdg.py +171 -0
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/android.py +92 -41
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/api.py +213 -49
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/macos.py +128 -51
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/unix.py +176 -127
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/version.py +8 -18
- package/xll/python/Lib/site-packages/pip/_vendor/platformdirs/windows.py +185 -68
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/__init__.py +2 -2
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/__main__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/console.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/filter.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/filters/__init__.py +10 -8
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/formatter.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/formatters/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/lexer.py +7 -5
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/lexers/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/lexers/_mapping.py +9 -8
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/lexers/python.py +35 -32
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/modeline.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/plugin.py +3 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/regexopt.py +13 -2
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/scanner.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/sphinxext.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/style.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/styles/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/token.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/unistring.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/pygments/util.py +2 -2
- package/xll/python/Lib/site-packages/pip/_vendor/requests/__init__.py +52 -16
- package/xll/python/Lib/site-packages/pip/_vendor/requests/__version__.py +2 -2
- package/xll/python/Lib/site-packages/pip/_vendor/requests/_internal_utils.py +2 -2
- package/xll/python/Lib/site-packages/pip/_vendor/requests/_types.py +183 -0
- package/xll/python/Lib/site-packages/pip/_vendor/requests/adapters.py +101 -50
- package/xll/python/Lib/site-packages/pip/_vendor/requests/api.py +31 -8
- package/xll/python/Lib/site-packages/pip/_vendor/requests/auth.py +80 -40
- package/xll/python/Lib/site-packages/pip/_vendor/requests/compat.py +9 -3
- package/xll/python/Lib/site-packages/pip/_vendor/requests/cookies.py +143 -79
- package/xll/python/Lib/site-packages/pip/_vendor/requests/exceptions.py +15 -5
- package/xll/python/Lib/site-packages/pip/_vendor/requests/help.py +13 -10
- package/xll/python/Lib/site-packages/pip/_vendor/requests/hooks.py +23 -9
- package/xll/python/Lib/site-packages/pip/_vendor/requests/models.py +265 -126
- package/xll/python/Lib/site-packages/pip/_vendor/requests/py.typed +0 -0
- package/xll/python/Lib/site-packages/pip/_vendor/requests/sessions.py +164 -78
- package/xll/python/Lib/site-packages/pip/_vendor/requests/status_codes.py +2 -2
- package/xll/python/Lib/site-packages/pip/_vendor/requests/structures.py +51 -20
- package/xll/python/Lib/site-packages/pip/_vendor/requests/utils.py +161 -89
- package/xll/python/Lib/site-packages/pip/_vendor/tomli/__init__.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/tomli/_parser.py +9 -4
- package/xll/python/Lib/site-packages/pip/_vendor/tomli/_re.py +13 -9
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/_base_connection.py +3 -1
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/_collections.py +0 -1
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/_version.py +8 -18
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/connection.py +4 -4
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/connectionpool.py +23 -10
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/contrib/emscripten/response.py +5 -1
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py +7 -8
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/contrib/socks.py +1 -1
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/exceptions.py +2 -2
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/fields.py +14 -14
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/poolmanager.py +8 -6
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/response.py +35 -22
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/util/retry.py +8 -0
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/util/ssl_.py +11 -61
- package/xll/python/Lib/site-packages/pip/_vendor/urllib3/util/ssl_match_hostname.py +5 -11
- package/xll/python/Lib/site-packages/pip/_vendor/vendor.txt +8 -8
- package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/METADATA +3 -2
- package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/RECORD +208 -188
- package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/AUTHORS.txt +20 -0
- package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/idna/LICENSE.md +1 -1
- package/xll/python/Lib/site-packages/pywin32-311.dist-info/RECORD +2 -2
- package/xll/python/Scripts/httpx.exe +0 -0
- package/xll/python/Scripts/idna.exe +0 -0
- package/xll/python/Scripts/pip.exe +0 -0
- package/xll/python/Scripts/pip3.13.exe +0 -0
- package/xll/python/Scripts/pip3.exe +0 -0
- package/xll/python/Scripts/pywin32_postinstall.exe +0 -0
- package/xll/python/Scripts/pywin32_testall.exe +0 -0
- package/dist/app/collab/awareness.d.ts +0 -32
- package/dist/app/collab/awareness.js +0 -52
- package/dist/app/collab/collab-client.d.ts +0 -37
- package/dist/app/collab/collab-client.js +0 -208
- package/dist/app/collab/collab-manager.d.ts +0 -91
- package/dist/app/collab/collab-manager.js +0 -218
- package/dist/app/collab/collab-sync.d.ts +0 -62
- package/dist/app/collab/collab-sync.js +0 -215
- package/dist/app/collab/index.d.ts +0 -9
- package/dist/app/collab/index.js +0 -6
- package/dist/app/collab/super-fight.d.ts +0 -90
- package/dist/app/collab/super-fight.js +0 -310
- package/dist/app/collab/sync-bridge.d.ts +0 -35
- package/dist/app/collab/sync-bridge.js +0 -109
- package/dist/app/collab/types.d.ts +0 -75
- package/dist/app/collab/types.js +0 -5
- package/dist/embedded-agent/ai-content.d.ts +0 -52
- package/dist/embedded-agent/ai-content.js +0 -101
- package/dist/embedded-agent/host-tools/shared/llm-stream.d.ts +0 -31
- package/dist/embedded-agent/host-tools/shared/llm-stream.js +0 -136
- package/dist/embedded-agent/model-call-orchestrator.d.ts +0 -22
- package/dist/embedded-agent/model-call-orchestrator.js +0 -22
- package/dist/embedded-agent/stream-errors.d.ts +0 -10
- package/dist/embedded-agent/stream-errors.js +0 -73
- package/dist/embedded-agent/stream-message-state.d.ts +0 -14
- package/dist/embedded-agent/stream-message-state.js +0 -271
- package/dist/embedded-agent/stream-sse.d.ts +0 -78
- package/dist/embedded-agent/stream-sse.js +0 -73
- package/dist/shell/approvals/task-spawn-approval.d.ts +0 -20
- package/dist/shell/approvals/task-spawn-approval.js +0 -93
- package/dist/shell/interactive/collab-command.d.ts +0 -9
- package/dist/shell/interactive/collab-command.js +0 -115
- package/dist/shell/interactive/super-fight-ui.d.ts +0 -80
- package/dist/shell/interactive/super-fight-ui.js +0 -484
- package/dist/shell/status/collab-status.d.ts +0 -18
- package/dist/shell/status/collab-status.js +0 -46
- package/xll/python/Lib/site-packages/pip/_internal/build_env.py +0 -606
- /package/dist/{tui → autocomplete}/skill-autocomplete.js +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/INSTALLER +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/REQUESTED +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/WHEEL +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/entry_points.txt +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/LICENSE.txt +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/cachecontrol/LICENSE.txt +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/certifi/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/distlib/LICENSE.txt +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/distro/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/msgpack/COPYING +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/packaging/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/packaging/LICENSE.APACHE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/packaging/LICENSE.BSD +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/pkg_resources/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/platformdirs/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/pygments/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/pyproject_hooks/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/requests/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/resolvelib/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/rich/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/tomli/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/tomli_w/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/truststore/LICENSE +0 -0
- /package/xll/python/Lib/site-packages/{pip-26.1.2.dist-info → pip-26.2.dist-info}/licenses/src/pip/_vendor/urllib3/LICENSE.txt +0 -0
|
@@ -1,181 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { normalizeTransportFetchError, normalizeTransportStreamError, throwInvalidResponse, throwTransportHttpError } from './transport-errors.js';
|
|
8
|
-
function incompleteStreamError() {
|
|
9
|
-
return new ShortcutXLModelCallErrorEnvelope(createShortcutXLModelCallError(ShortcutXLModelCallErrorCategory.TransientNetwork, 'Anthropic Messages stream ended before terminal message_stop; the upstream stream may have been interrupted or timed out.', networkErrorDetails(ShortcutXLModelStreamFetchStage.ResponseBody)));
|
|
10
|
-
}
|
|
11
|
-
const MODEL_ACCESS_DENIED_DETAILS = {
|
|
12
|
-
providerErrorType: MODEL_ACCESS_DENIED_PROVIDER_ERROR_TYPE,
|
|
13
|
-
retryable: false,
|
|
14
|
-
status: 403
|
|
15
|
-
};
|
|
16
|
-
function streamErrorCategory(details) {
|
|
17
|
-
switch (details.providerErrorType) {
|
|
18
|
-
case 'rate_limit':
|
|
19
|
-
return ShortcutXLModelCallErrorCategory.RateLimited;
|
|
20
|
-
case 'unauthorized':
|
|
21
|
-
return ShortcutXLModelCallErrorCategory.Auth;
|
|
22
|
-
case MODEL_ACCESS_DENIED_PROVIDER_ERROR_TYPE:
|
|
23
|
-
case 'invalid_request':
|
|
24
|
-
return ShortcutXLModelCallErrorCategory.ProviderRejected;
|
|
25
|
-
default:
|
|
26
|
-
return ShortcutXLModelCallErrorCategory.TransientNetwork;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Fall back to matching the free-text message when the structured `error.type`
|
|
31
|
-
* (https://docs.anthropic.com/en/api/errors) is absent or unrecognized. Returns
|
|
32
|
-
* a raw type the shared mapping understands; unknown text is treated as a
|
|
33
|
-
* retryable provider-internal failure.
|
|
34
|
-
*/
|
|
35
|
-
function rawErrorTypeFromText(text) {
|
|
36
|
-
if (text.includes('overload'))
|
|
37
|
-
return 'overloaded_error';
|
|
38
|
-
if (text.includes('rate_limit') || text.includes('rate limit') || text.includes('429')) {
|
|
39
|
-
return 'rate_limit_error';
|
|
40
|
-
}
|
|
41
|
-
if (text.includes('authentication') || text.includes('unauthorized') || text.includes('401')) {
|
|
42
|
-
return 'authentication_error';
|
|
43
|
-
}
|
|
44
|
-
if (text.includes('invalid_request') ||
|
|
45
|
-
text.includes('invalid request') ||
|
|
46
|
-
text.includes('bad_request') ||
|
|
47
|
-
text.includes('not_found') ||
|
|
48
|
-
text.includes('not found') ||
|
|
49
|
-
text.includes('400') ||
|
|
50
|
-
text.includes('422')) {
|
|
51
|
-
return 'invalid_request_error';
|
|
52
|
-
}
|
|
53
|
-
return 'api_error';
|
|
54
|
-
}
|
|
55
|
-
function normalizeAnthropicStreamError(error) {
|
|
56
|
-
const rawType = error?.type?.trim().toLowerCase() ?? '';
|
|
57
|
-
const rawMessage = error?.message?.trim();
|
|
58
|
-
const text = `${rawType} ${rawMessage ?? ''}`.toLowerCase();
|
|
59
|
-
const details = isModelAccessDeniedErrorMessage(rawMessage, undefined)
|
|
60
|
-
? MODEL_ACCESS_DENIED_DETAILS
|
|
61
|
-
: (providerErrorDetailsFromRawType(rawType) ??
|
|
62
|
-
providerErrorDetailsFromRawType(rawErrorTypeFromText(text)) ??
|
|
63
|
-
// Unreachable: rawErrorTypeFromText only returns mapped types.
|
|
64
|
-
networkErrorDetails());
|
|
65
|
-
return {
|
|
66
|
-
category: streamErrorCategory(details),
|
|
67
|
-
details,
|
|
68
|
-
message: safeModelStreamErrorMessage(details)
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function throwProviderStreamError(normalized) {
|
|
72
|
-
throw new ShortcutXLModelCallErrorEnvelope(createShortcutXLModelCallError(normalized.category, normalized.message, normalized.details));
|
|
73
|
-
}
|
|
74
|
-
const AnthropicRuntimeApi = 'anthropic-messages';
|
|
75
|
-
function normalizeBaseUrl(baseUrl) {
|
|
76
|
-
return baseUrl.replace(/\/+$/, '');
|
|
77
|
-
}
|
|
78
|
-
function createAuthHeader(auth) {
|
|
79
|
-
if (auth.headerName === 'Authorization') {
|
|
80
|
-
return {
|
|
81
|
-
Authorization: auth.token.startsWith('Bearer ') ? auth.token : `Bearer ${auth.token}`
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return { 'x-api-key': auth.token };
|
|
85
|
-
}
|
|
86
|
-
const normalizeAiAnthropicBaseUrl = withoutV1Segment;
|
|
87
|
-
function buildGatewayAiModel(request, baseUrl) {
|
|
88
|
-
return {
|
|
89
|
-
api: 'anthropic-messages',
|
|
90
|
-
baseUrl: normalizeAiAnthropicBaseUrl(baseUrl),
|
|
91
|
-
contextWindow: request.model.contextWindow,
|
|
92
|
-
cost: { cacheRead: 0, cacheWrite: 0, input: 0, output: 0 },
|
|
93
|
-
id: request.model.id,
|
|
94
|
-
input: request.model.input,
|
|
95
|
-
maxTokens: request.model.maxTokens,
|
|
96
|
-
name: request.model.name,
|
|
97
|
-
provider: request.model.provider,
|
|
98
|
-
reasoning: request.model.reasoning
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function buildGatewayAiStreamOptions(request, options) {
|
|
102
|
-
const fastMode = shortcutProviderFastModeFromRequest('anthropic', request);
|
|
103
|
-
const configuredHeaders = withProviderFastModeHeaders({
|
|
104
|
-
...request.options?.headers,
|
|
105
|
-
...options.headers
|
|
106
|
-
}, fastMode);
|
|
107
|
-
const apiKey = options.auth.token;
|
|
108
|
-
if (options.auth.headerName === 'Authorization') {
|
|
109
|
-
configuredHeaders.Authorization = options.auth.token.startsWith('Bearer ')
|
|
110
|
-
? options.auth.token
|
|
111
|
-
: `Bearer ${options.auth.token}`;
|
|
112
|
-
configuredHeaders['x-api-key'] = null;
|
|
113
|
-
}
|
|
114
|
-
return withProviderFastModePayloadOverride({
|
|
115
|
-
apiKey,
|
|
116
|
-
cacheRetention: request.options?.cacheRetention,
|
|
117
|
-
fetch: options.fetchImpl,
|
|
118
|
-
fetchOptions: options.fetchOptions,
|
|
119
|
-
headers: configuredHeaders,
|
|
120
|
-
maxRetryDelayMs: request.options?.maxRetryDelayMs,
|
|
121
|
-
maxTokens: request.options?.maxTokens,
|
|
122
|
-
metadata: request.options?.metadata,
|
|
123
|
-
reasoning: request.options?.reasoning,
|
|
124
|
-
signal: options.signal,
|
|
125
|
-
temperature: request.options?.temperature,
|
|
126
|
-
transport: request.options?.transport
|
|
127
|
-
}, fastMode);
|
|
128
|
-
}
|
|
129
|
-
function mapGatewayThinkingEffort(reasoning, _modelId) {
|
|
130
|
-
switch (reasoning) {
|
|
131
|
-
case 'minimal':
|
|
132
|
-
case 'low':
|
|
133
|
-
return 'low';
|
|
134
|
-
case 'medium':
|
|
135
|
-
return 'medium';
|
|
136
|
-
case 'xhigh':
|
|
137
|
-
return 'max';
|
|
138
|
-
case 'high':
|
|
139
|
-
return 'high';
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function withAdaptiveGatewayThinkingPayloadOverride(modelId, options) {
|
|
143
|
-
// Every served Claude model uses adaptive thinking; legacy budget-based
|
|
144
|
-
// thinking (pre-4 Claude) has been retired.
|
|
145
|
-
if (!options.reasoning)
|
|
146
|
-
return options;
|
|
147
|
-
const effort = mapGatewayThinkingEffort(options.reasoning, modelId);
|
|
148
|
-
const onPayload = options.onPayload;
|
|
149
|
-
return {
|
|
150
|
-
...options,
|
|
151
|
-
onPayload: (payload) => {
|
|
152
|
-
if (payload && typeof payload === 'object') {
|
|
153
|
-
Object.assign(payload, {
|
|
154
|
-
output_config: { effort },
|
|
155
|
-
thinking: { type: 'adaptive', display: 'summarized' }
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
onPayload?.(payload);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function streamGatewayAiAnthropic(model, request, options) {
|
|
163
|
-
return streamSimpleAnthropic(model, request.context, withAdaptiveGatewayThinkingPayloadOverride(model.id, options));
|
|
164
|
-
}
|
|
165
|
-
function buildUsage(usage) {
|
|
166
|
-
const output = usage?.output_tokens ?? 0;
|
|
167
|
-
const cacheRead = usage?.cache_read_input_tokens ?? 0;
|
|
168
|
-
const cacheWrite = usage?.cache_creation_input_tokens ?? 0;
|
|
169
|
-
const input = (usage?.input_tokens ?? 0) + cacheRead + cacheWrite;
|
|
170
|
-
return {
|
|
171
|
-
cacheRead,
|
|
172
|
-
cacheWrite,
|
|
173
|
-
cost: { cacheRead: 0, cacheWrite: 0, input: 0, output: 0, total: 0 },
|
|
174
|
-
input,
|
|
175
|
-
output,
|
|
176
|
-
totalTokens: input + output
|
|
177
|
-
};
|
|
178
|
-
}
|
|
1
|
+
import { buildAnthropicMessagesRequest, streamSimpleAnthropic } from '../ai/providers/anthropic.js';
|
|
2
|
+
import { ShortcutXLModelCallTransportKind, ShortcutXLProviderUsageStatus } from '../contracts/model-call.js';
|
|
3
|
+
import { ShortcutXLAgentAssistantContentKind, ShortcutXLModelStreamEventKind, ShortcutXLModelStreamStopReason } from '../contracts/model-stream.js';
|
|
4
|
+
import { shortcutProviderFastModeFromRequest, withProviderFastModeHeaders, withProviderFastModePayload } from './provider-fast-mode.js';
|
|
5
|
+
import { concreteProviderHeaders, createGatewayProviderModel, createGatewayProviderOptions } from './provider-native-request.js';
|
|
6
|
+
import { normalizeTransportFetchError, throwInvalidResponse, throwTransportHttpError } from './transport-errors.js';
|
|
179
7
|
function buildUsageFromAi(usage) {
|
|
180
8
|
return {
|
|
181
9
|
cacheRead: usage?.cacheRead ?? 0,
|
|
@@ -211,15 +39,8 @@ export function toProviderUsageFromAi(usage) {
|
|
|
211
39
|
totalTokens: usage.totalTokens
|
|
212
40
|
};
|
|
213
41
|
}
|
|
214
|
-
function
|
|
215
|
-
|
|
216
|
-
...message,
|
|
217
|
-
content: message.content.map((content) => ({ ...content })),
|
|
218
|
-
usage: {
|
|
219
|
-
...message.usage,
|
|
220
|
-
cost: { ...message.usage.cost }
|
|
221
|
-
}
|
|
222
|
-
};
|
|
42
|
+
async function emitProviderUsage(logger, event) {
|
|
43
|
+
await logger?.recordProviderUsage(event);
|
|
223
44
|
}
|
|
224
45
|
function toShortcutXLAssistantContent(content) {
|
|
225
46
|
switch (content.type) {
|
|
@@ -375,545 +196,6 @@ export function toShortcutXLModelStreamEvent(event) {
|
|
|
375
196
|
}
|
|
376
197
|
}
|
|
377
198
|
}
|
|
378
|
-
function normalizeStopReason(stopReason) {
|
|
379
|
-
if (stopReason === 'tool_use')
|
|
380
|
-
return ShortcutXLModelStreamStopReason.ToolUse;
|
|
381
|
-
if (stopReason === 'max_tokens')
|
|
382
|
-
return ShortcutXLModelStreamStopReason.Length;
|
|
383
|
-
return ShortcutXLModelStreamStopReason.Stop;
|
|
384
|
-
}
|
|
385
|
-
function toAnthropicRole(role) {
|
|
386
|
-
return role === ShortcutXLModelStreamMessageRole.Ai ? 'assistant' : 'user';
|
|
387
|
-
}
|
|
388
|
-
function buildMessages(messages) {
|
|
389
|
-
const system = messages
|
|
390
|
-
.filter((message) => message.role === ShortcutXLModelStreamMessageRole.System)
|
|
391
|
-
.map((message) => message.content)
|
|
392
|
-
.join('\n\n');
|
|
393
|
-
const anthropicMessages = messages
|
|
394
|
-
.filter((message) => message.role !== ShortcutXLModelStreamMessageRole.System)
|
|
395
|
-
.map((message) => ({
|
|
396
|
-
content: message.content,
|
|
397
|
-
role: toAnthropicRole(message.role)
|
|
398
|
-
}));
|
|
399
|
-
return {
|
|
400
|
-
messages: anthropicMessages,
|
|
401
|
-
...(system ? { system } : {})
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function buildRequestBody(call) {
|
|
405
|
-
const messages = buildMessages(call.payload.messages);
|
|
406
|
-
return {
|
|
407
|
-
max_tokens: call.payload.maxTokens ?? 4096,
|
|
408
|
-
...messages,
|
|
409
|
-
model: call.payload.model,
|
|
410
|
-
stream: true,
|
|
411
|
-
...(call.payload.tools
|
|
412
|
-
? {
|
|
413
|
-
tools: call.payload.tools.map((tool) => ({
|
|
414
|
-
description: tool.description,
|
|
415
|
-
input_schema: tool.parameters,
|
|
416
|
-
name: tool.name
|
|
417
|
-
}))
|
|
418
|
-
}
|
|
419
|
-
: {})
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
function parseToolArguments(inputJson) {
|
|
423
|
-
if (!inputJson)
|
|
424
|
-
return {};
|
|
425
|
-
const parsed = JSON.parse(inputJson);
|
|
426
|
-
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
427
|
-
? parsed
|
|
428
|
-
: {};
|
|
429
|
-
}
|
|
430
|
-
async function readSseEvents(response, onEvent) {
|
|
431
|
-
if (!response.body)
|
|
432
|
-
throwInvalidResponse('Anthropic Messages stream response had no body.');
|
|
433
|
-
const decoder = new TextDecoder();
|
|
434
|
-
const reader = response.body.getReader();
|
|
435
|
-
let buffer = '';
|
|
436
|
-
for (;;) {
|
|
437
|
-
const { done, value } = await reader.read();
|
|
438
|
-
if (done)
|
|
439
|
-
break;
|
|
440
|
-
buffer += decoder.decode(value, { stream: true });
|
|
441
|
-
for (;;) {
|
|
442
|
-
const boundary = buffer.indexOf('\n\n');
|
|
443
|
-
if (boundary === -1)
|
|
444
|
-
break;
|
|
445
|
-
const frame = buffer.slice(0, boundary);
|
|
446
|
-
buffer = buffer.slice(boundary + 2);
|
|
447
|
-
const data = frame
|
|
448
|
-
.split('\n')
|
|
449
|
-
.find((line) => line.startsWith('data:'))
|
|
450
|
-
?.slice('data:'.length)
|
|
451
|
-
.trim();
|
|
452
|
-
if (!data || data === '[DONE]')
|
|
453
|
-
continue;
|
|
454
|
-
try {
|
|
455
|
-
await onEvent(JSON.parse(data));
|
|
456
|
-
}
|
|
457
|
-
catch (error) {
|
|
458
|
-
if (error instanceof ShortcutXLModelCallErrorEnvelope)
|
|
459
|
-
throw error;
|
|
460
|
-
throwInvalidResponse(error instanceof SyntaxError
|
|
461
|
-
? 'Anthropic Messages stream emitted malformed JSON.'
|
|
462
|
-
: error instanceof Error
|
|
463
|
-
? error.message
|
|
464
|
-
: String(error));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
async function emitProviderUsage(logger, event) {
|
|
470
|
-
await logger?.recordProviderUsage(event);
|
|
471
|
-
}
|
|
472
|
-
async function streamAnthropicMessagesResponse(options) {
|
|
473
|
-
const blocks = new Map();
|
|
474
|
-
let latestUsage;
|
|
475
|
-
let stopReason;
|
|
476
|
-
let sawMessageStop = false;
|
|
477
|
-
const emit = (event) => options.onEvent(event);
|
|
478
|
-
emit({
|
|
479
|
-
kind: ShortcutXLModelStreamEventKind.Start,
|
|
480
|
-
partial: cloneMessage(options.message)
|
|
481
|
-
});
|
|
482
|
-
await readSseEvents(options.response, async (event) => {
|
|
483
|
-
switch (event.type) {
|
|
484
|
-
case 'message_start':
|
|
485
|
-
latestUsage = { ...latestUsage, ...event.message?.usage };
|
|
486
|
-
return;
|
|
487
|
-
case 'content_block_start': {
|
|
488
|
-
const block = event.content_block;
|
|
489
|
-
if (!block)
|
|
490
|
-
return;
|
|
491
|
-
if (block.type === 'text') {
|
|
492
|
-
blocks.set(event.index, {
|
|
493
|
-
inputJson: '',
|
|
494
|
-
signature: '',
|
|
495
|
-
text: block.text ?? '',
|
|
496
|
-
type: 'text'
|
|
497
|
-
});
|
|
498
|
-
options.message.content[event.index] = {
|
|
499
|
-
text: block.text ?? '',
|
|
500
|
-
type: ShortcutXLAgentAssistantContentKind.Text
|
|
501
|
-
};
|
|
502
|
-
emit({
|
|
503
|
-
contentIndex: event.index,
|
|
504
|
-
kind: ShortcutXLModelStreamEventKind.TextStart,
|
|
505
|
-
partial: cloneMessage(options.message)
|
|
506
|
-
});
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
if (block.type === 'tool_use') {
|
|
510
|
-
blocks.set(event.index, {
|
|
511
|
-
id: block.id,
|
|
512
|
-
inputJson: '',
|
|
513
|
-
name: block.name,
|
|
514
|
-
signature: '',
|
|
515
|
-
text: '',
|
|
516
|
-
type: 'tool_use'
|
|
517
|
-
});
|
|
518
|
-
options.message.content[event.index] = {
|
|
519
|
-
arguments: {},
|
|
520
|
-
id: block.id ?? '',
|
|
521
|
-
name: block.name ?? '',
|
|
522
|
-
type: ShortcutXLAgentAssistantContentKind.ToolCall
|
|
523
|
-
};
|
|
524
|
-
emit({
|
|
525
|
-
contentIndex: event.index,
|
|
526
|
-
kind: ShortcutXLModelStreamEventKind.ToolCallStart,
|
|
527
|
-
partial: cloneMessage(options.message)
|
|
528
|
-
});
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
if (block.type === 'thinking') {
|
|
532
|
-
blocks.set(event.index, {
|
|
533
|
-
inputJson: '',
|
|
534
|
-
signature: '',
|
|
535
|
-
text: block.thinking ?? '',
|
|
536
|
-
type: 'thinking'
|
|
537
|
-
});
|
|
538
|
-
options.message.content[event.index] = {
|
|
539
|
-
redacted: false,
|
|
540
|
-
thinking: block.thinking ?? '',
|
|
541
|
-
thinkingSignature: '',
|
|
542
|
-
type: ShortcutXLAgentAssistantContentKind.Thinking
|
|
543
|
-
};
|
|
544
|
-
emit({
|
|
545
|
-
contentIndex: event.index,
|
|
546
|
-
kind: ShortcutXLModelStreamEventKind.ThinkingStart,
|
|
547
|
-
partial: cloneMessage(options.message)
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
case 'content_block_delta': {
|
|
553
|
-
const block = blocks.get(event.index);
|
|
554
|
-
if (!block || !event.delta)
|
|
555
|
-
return;
|
|
556
|
-
if (event.delta.type === 'text_delta') {
|
|
557
|
-
const delta = event.delta.text ?? '';
|
|
558
|
-
block.text += delta;
|
|
559
|
-
options.message.content[event.index] = {
|
|
560
|
-
text: block.text,
|
|
561
|
-
type: ShortcutXLAgentAssistantContentKind.Text
|
|
562
|
-
};
|
|
563
|
-
emit({
|
|
564
|
-
contentIndex: event.index,
|
|
565
|
-
delta,
|
|
566
|
-
kind: ShortcutXLModelStreamEventKind.TextDelta,
|
|
567
|
-
partial: cloneMessage(options.message)
|
|
568
|
-
});
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
if (event.delta.type === 'input_json_delta') {
|
|
572
|
-
const delta = event.delta.partial_json ?? '';
|
|
573
|
-
block.inputJson += delta;
|
|
574
|
-
emit({
|
|
575
|
-
contentIndex: event.index,
|
|
576
|
-
delta,
|
|
577
|
-
kind: ShortcutXLModelStreamEventKind.ToolCallDelta,
|
|
578
|
-
partial: cloneMessage(options.message)
|
|
579
|
-
});
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
if (event.delta.type === 'thinking_delta') {
|
|
583
|
-
const delta = event.delta.thinking ?? '';
|
|
584
|
-
block.text += delta;
|
|
585
|
-
options.message.content[event.index] = {
|
|
586
|
-
redacted: false,
|
|
587
|
-
thinking: block.text,
|
|
588
|
-
thinkingSignature: block.signature,
|
|
589
|
-
type: ShortcutXLAgentAssistantContentKind.Thinking
|
|
590
|
-
};
|
|
591
|
-
emit({
|
|
592
|
-
contentIndex: event.index,
|
|
593
|
-
delta,
|
|
594
|
-
kind: ShortcutXLModelStreamEventKind.ThinkingDelta,
|
|
595
|
-
partial: cloneMessage(options.message)
|
|
596
|
-
});
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
if (event.delta.type === 'signature_delta') {
|
|
600
|
-
block.signature += event.delta.signature ?? '';
|
|
601
|
-
}
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
case 'content_block_stop': {
|
|
605
|
-
const block = blocks.get(event.index);
|
|
606
|
-
if (!block)
|
|
607
|
-
return;
|
|
608
|
-
const content = options.message.content[event.index];
|
|
609
|
-
if (block.type === 'text') {
|
|
610
|
-
emit({
|
|
611
|
-
contentIndex: event.index,
|
|
612
|
-
kind: ShortcutXLModelStreamEventKind.TextEnd,
|
|
613
|
-
partial: cloneMessage(options.message)
|
|
614
|
-
});
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
if (block.type === 'tool_use') {
|
|
618
|
-
const toolCall = {
|
|
619
|
-
arguments: parseToolArguments(block.inputJson),
|
|
620
|
-
id: block.id ?? '',
|
|
621
|
-
name: block.name ?? '',
|
|
622
|
-
type: ShortcutXLAgentAssistantContentKind.ToolCall
|
|
623
|
-
};
|
|
624
|
-
options.message.content[event.index] = toolCall;
|
|
625
|
-
emit({
|
|
626
|
-
contentIndex: event.index,
|
|
627
|
-
kind: ShortcutXLModelStreamEventKind.ToolCallEnd,
|
|
628
|
-
partial: cloneMessage(options.message),
|
|
629
|
-
toolCall
|
|
630
|
-
});
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
if (block.type === 'thinking' &&
|
|
634
|
-
content?.type === ShortcutXLAgentAssistantContentKind.Thinking) {
|
|
635
|
-
options.message.content[event.index] = { ...content, thinkingSignature: block.signature };
|
|
636
|
-
emit({
|
|
637
|
-
content: block.text,
|
|
638
|
-
contentIndex: event.index,
|
|
639
|
-
kind: ShortcutXLModelStreamEventKind.ThinkingEnd,
|
|
640
|
-
partial: cloneMessage(options.message)
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
case 'message_delta':
|
|
646
|
-
stopReason = event.delta?.stop_reason ?? stopReason;
|
|
647
|
-
latestUsage = { ...latestUsage, ...event.usage };
|
|
648
|
-
return;
|
|
649
|
-
case 'message_stop':
|
|
650
|
-
sawMessageStop = true;
|
|
651
|
-
options.message.usage = buildUsage(latestUsage);
|
|
652
|
-
await emitProviderUsage(options.usageStatusLogger, {
|
|
653
|
-
callId: options.callId,
|
|
654
|
-
model: options.model,
|
|
655
|
-
status: latestUsage
|
|
656
|
-
? ShortcutXLProviderUsageStatus.UsageAvailable
|
|
657
|
-
: ShortcutXLProviderUsageStatus.Unavailable,
|
|
658
|
-
transport: ShortcutXLModelCallTransportKind.AnthropicMessages,
|
|
659
|
-
usage: toProviderUsage(latestUsage)
|
|
660
|
-
});
|
|
661
|
-
const errorDetails = anthropicTerminalStopErrorDetails(stopReason);
|
|
662
|
-
if (errorDetails) {
|
|
663
|
-
const normalized = {
|
|
664
|
-
category: ShortcutXLModelCallErrorCategory.ProviderRejected,
|
|
665
|
-
details: errorDetails,
|
|
666
|
-
message: safeModelStreamErrorMessage(errorDetails)
|
|
667
|
-
};
|
|
668
|
-
options.message.stopReason = ShortcutXLModelStreamStopReason.Error;
|
|
669
|
-
options.message.errorDetails = normalized.details;
|
|
670
|
-
options.message.errorMessage = normalized.message;
|
|
671
|
-
emit({
|
|
672
|
-
error: cloneMessage(options.message),
|
|
673
|
-
kind: ShortcutXLModelStreamEventKind.Error,
|
|
674
|
-
partial: cloneMessage(options.message),
|
|
675
|
-
reason: ShortcutXLModelStreamStopReason.Error
|
|
676
|
-
});
|
|
677
|
-
throwProviderStreamError(normalized);
|
|
678
|
-
}
|
|
679
|
-
options.message.stopReason = normalizeStopReason(stopReason);
|
|
680
|
-
emit({
|
|
681
|
-
kind: ShortcutXLModelStreamEventKind.Done,
|
|
682
|
-
message: cloneMessage(options.message),
|
|
683
|
-
partial: cloneMessage(options.message),
|
|
684
|
-
reason: options.message.stopReason
|
|
685
|
-
});
|
|
686
|
-
return;
|
|
687
|
-
case 'error': {
|
|
688
|
-
const normalized = normalizeAnthropicStreamError(event.error);
|
|
689
|
-
options.message.stopReason = ShortcutXLModelStreamStopReason.Error;
|
|
690
|
-
options.message.errorDetails = normalized.details;
|
|
691
|
-
options.message.errorMessage = normalized.message;
|
|
692
|
-
emit({
|
|
693
|
-
error: cloneMessage(options.message),
|
|
694
|
-
kind: ShortcutXLModelStreamEventKind.Error,
|
|
695
|
-
partial: cloneMessage(options.message),
|
|
696
|
-
reason: ShortcutXLModelStreamStopReason.Error
|
|
697
|
-
});
|
|
698
|
-
throwProviderStreamError(normalized);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
if (!sawMessageStop) {
|
|
703
|
-
const error = incompleteStreamError();
|
|
704
|
-
options.message.stopReason = ShortcutXLModelStreamStopReason.Error;
|
|
705
|
-
// The emitted event is the terminal the host forwards (the thrown envelope
|
|
706
|
-
// below is dropped as a duplicate), so it must carry the structured
|
|
707
|
-
// details itself or classification falls back to message text.
|
|
708
|
-
options.message.errorDetails = networkErrorDetails(ShortcutXLModelStreamFetchStage.ResponseBody);
|
|
709
|
-
options.message.errorMessage = error.message;
|
|
710
|
-
emit({
|
|
711
|
-
error: cloneMessage(options.message),
|
|
712
|
-
kind: ShortcutXLModelStreamEventKind.Error,
|
|
713
|
-
partial: cloneMessage(options.message),
|
|
714
|
-
reason: ShortcutXLModelStreamStopReason.Error
|
|
715
|
-
});
|
|
716
|
-
await emitProviderUsage(options.usageStatusLogger, {
|
|
717
|
-
callId: options.callId,
|
|
718
|
-
model: options.model,
|
|
719
|
-
status: ShortcutXLProviderUsageStatus.Unavailable,
|
|
720
|
-
transport: ShortcutXLModelCallTransportKind.AnthropicMessages,
|
|
721
|
-
usage: undefined
|
|
722
|
-
});
|
|
723
|
-
throw error;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
function aiToolResultContentToAnthropic(content) {
|
|
727
|
-
const hasMedia = content.some((block) => block.type === 'image' || block.type === 'document');
|
|
728
|
-
if (!hasMedia) {
|
|
729
|
-
return content
|
|
730
|
-
.filter((block) => block.type === 'text')
|
|
731
|
-
.map((block) => block.text)
|
|
732
|
-
.join('\n');
|
|
733
|
-
}
|
|
734
|
-
const blocks = content.map((block) => {
|
|
735
|
-
if (block.type === 'text') {
|
|
736
|
-
return { text: block.text, type: 'text' };
|
|
737
|
-
}
|
|
738
|
-
if (block.type === 'document') {
|
|
739
|
-
return {
|
|
740
|
-
source: {
|
|
741
|
-
data: block.data,
|
|
742
|
-
media_type: block.mimeType,
|
|
743
|
-
type: 'base64'
|
|
744
|
-
},
|
|
745
|
-
type: 'document'
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
return {
|
|
749
|
-
source: {
|
|
750
|
-
data: block.data,
|
|
751
|
-
media_type: block.mimeType,
|
|
752
|
-
type: 'base64'
|
|
753
|
-
},
|
|
754
|
-
type: 'image'
|
|
755
|
-
};
|
|
756
|
-
});
|
|
757
|
-
if (!blocks.some((block) => block.type === 'text')) {
|
|
758
|
-
blocks.unshift({ text: '(see attached media)', type: 'text' });
|
|
759
|
-
}
|
|
760
|
-
return blocks.length > 0 ? blocks : [{ text: '', type: 'text' }];
|
|
761
|
-
}
|
|
762
|
-
function aiAssistantContentToAnthropic(content) {
|
|
763
|
-
return content
|
|
764
|
-
.map((block) => {
|
|
765
|
-
if (block.type === 'text') {
|
|
766
|
-
const text = block.text;
|
|
767
|
-
return text.trim().length > 0 ? { text, type: 'text' } : undefined;
|
|
768
|
-
}
|
|
769
|
-
if (block.type === 'toolCall') {
|
|
770
|
-
const toolCall = block;
|
|
771
|
-
return {
|
|
772
|
-
id: toolCall.id,
|
|
773
|
-
input: toolCall.arguments,
|
|
774
|
-
name: toolCall.name,
|
|
775
|
-
type: 'tool_use'
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
return undefined;
|
|
779
|
-
})
|
|
780
|
-
.filter((block) => block !== undefined);
|
|
781
|
-
}
|
|
782
|
-
function getAnthropicCacheControl(baseUrl, cacheRetention) {
|
|
783
|
-
const retention = cacheRetention ??
|
|
784
|
-
(typeof process !== 'undefined' && process.env.PI_CACHE_RETENTION === 'long'
|
|
785
|
-
? 'long'
|
|
786
|
-
: 'short');
|
|
787
|
-
if (retention === 'none')
|
|
788
|
-
return undefined;
|
|
789
|
-
return {
|
|
790
|
-
type: 'ephemeral',
|
|
791
|
-
...(retention === 'long' && normalizeBaseUrl(baseUrl).includes('api.anthropic.com')
|
|
792
|
-
? { ttl: '1h' }
|
|
793
|
-
: {})
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
function buildInvokeRequestBody(request, baseUrl) {
|
|
797
|
-
const messages = [];
|
|
798
|
-
for (let i = 0; i < request.context.messages.length; i += 1) {
|
|
799
|
-
const message = request.context.messages[i];
|
|
800
|
-
if (message.role === 'user') {
|
|
801
|
-
const content = aiUserContentToAnthropicContent(message.content, request.model.input);
|
|
802
|
-
if (typeof content === 'string' && content.trim().length === 0)
|
|
803
|
-
continue;
|
|
804
|
-
if (Array.isArray(content) && content.length === 0)
|
|
805
|
-
continue;
|
|
806
|
-
messages.push({
|
|
807
|
-
content,
|
|
808
|
-
role: 'user'
|
|
809
|
-
});
|
|
810
|
-
continue;
|
|
811
|
-
}
|
|
812
|
-
if (message.role === 'assistant') {
|
|
813
|
-
const content = aiAssistantContentToAnthropic(message.content);
|
|
814
|
-
if (content.length > 0) {
|
|
815
|
-
messages.push({ content, role: 'assistant' });
|
|
816
|
-
}
|
|
817
|
-
continue;
|
|
818
|
-
}
|
|
819
|
-
const toolResults = [
|
|
820
|
-
{
|
|
821
|
-
content: aiToolResultContentToAnthropic(message.content),
|
|
822
|
-
is_error: message.isError,
|
|
823
|
-
tool_use_id: message.toolCallId,
|
|
824
|
-
type: 'tool_result'
|
|
825
|
-
}
|
|
826
|
-
];
|
|
827
|
-
let nextIndex = i + 1;
|
|
828
|
-
while (nextIndex < request.context.messages.length &&
|
|
829
|
-
request.context.messages[nextIndex]?.role === 'toolResult') {
|
|
830
|
-
const nextMessage = request.context.messages[nextIndex];
|
|
831
|
-
toolResults.push({
|
|
832
|
-
content: aiToolResultContentToAnthropic(nextMessage.content),
|
|
833
|
-
is_error: nextMessage.isError,
|
|
834
|
-
tool_use_id: nextMessage.toolCallId,
|
|
835
|
-
type: 'tool_result'
|
|
836
|
-
});
|
|
837
|
-
nextIndex += 1;
|
|
838
|
-
}
|
|
839
|
-
i = nextIndex - 1;
|
|
840
|
-
messages.push({
|
|
841
|
-
content: toolResults,
|
|
842
|
-
role: 'user'
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
const cacheControl = getAnthropicCacheControl(baseUrl, request.options?.cacheRetention);
|
|
846
|
-
if (cacheControl && messages.length > 0) {
|
|
847
|
-
const lastMessage = messages[messages.length - 1];
|
|
848
|
-
if (lastMessage.role === 'user') {
|
|
849
|
-
if (Array.isArray(lastMessage.content)) {
|
|
850
|
-
const lastBlock = lastMessage.content[lastMessage.content.length - 1];
|
|
851
|
-
if (lastBlock &&
|
|
852
|
-
(lastBlock.type === 'text' ||
|
|
853
|
-
lastBlock.type === 'image' ||
|
|
854
|
-
lastBlock.type === 'tool_result')) {
|
|
855
|
-
lastBlock.cache_control = cacheControl;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
else if (typeof lastMessage.content === 'string') {
|
|
859
|
-
lastMessage.content = [
|
|
860
|
-
{
|
|
861
|
-
cache_control: cacheControl,
|
|
862
|
-
text: lastMessage.content,
|
|
863
|
-
type: 'text'
|
|
864
|
-
}
|
|
865
|
-
];
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
return withProviderFastModePayload({
|
|
870
|
-
max_tokens: request.options?.maxTokens ?? 4096,
|
|
871
|
-
messages,
|
|
872
|
-
model: request.model.id,
|
|
873
|
-
stream: false,
|
|
874
|
-
...(request.context.systemPrompt
|
|
875
|
-
? {
|
|
876
|
-
system: [
|
|
877
|
-
{
|
|
878
|
-
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
879
|
-
text: request.context.systemPrompt,
|
|
880
|
-
type: 'text'
|
|
881
|
-
}
|
|
882
|
-
]
|
|
883
|
-
}
|
|
884
|
-
: {}),
|
|
885
|
-
...(request.context.tools
|
|
886
|
-
? {
|
|
887
|
-
tools: request.context.tools.map((tool) => ({
|
|
888
|
-
description: tool.description,
|
|
889
|
-
input_schema: {
|
|
890
|
-
properties: 'properties' in tool.parameters && tool.parameters.properties
|
|
891
|
-
? tool.parameters.properties
|
|
892
|
-
: {},
|
|
893
|
-
required: 'required' in tool.parameters && Array.isArray(tool.parameters.required)
|
|
894
|
-
? tool.parameters.required
|
|
895
|
-
: [],
|
|
896
|
-
type: 'object'
|
|
897
|
-
},
|
|
898
|
-
name: tool.name
|
|
899
|
-
}))
|
|
900
|
-
}
|
|
901
|
-
: {}),
|
|
902
|
-
...(typeof request.options?.toolChoice === 'object'
|
|
903
|
-
? { tool_choice: request.options.toolChoice }
|
|
904
|
-
: typeof request.options?.toolChoice === 'string'
|
|
905
|
-
? { tool_choice: { type: request.options.toolChoice } }
|
|
906
|
-
: {})
|
|
907
|
-
}, shortcutProviderFastModeFromRequest('anthropic', request));
|
|
908
|
-
}
|
|
909
|
-
function concreteHeaders(headers) {
|
|
910
|
-
const result = {};
|
|
911
|
-
for (const [key, value] of Object.entries(headers ?? {})) {
|
|
912
|
-
if (value !== null)
|
|
913
|
-
result[key] = value;
|
|
914
|
-
}
|
|
915
|
-
return result;
|
|
916
|
-
}
|
|
917
199
|
function parseInvokeResponse(data) {
|
|
918
200
|
if (!data || typeof data !== 'object') {
|
|
919
201
|
throwInvalidResponse('Anthropic Messages invoke response must be a JSON object.');
|
|
@@ -946,16 +228,21 @@ function parseInvokeResponse(data) {
|
|
|
946
228
|
}
|
|
947
229
|
export async function invokeAnthropicMessagesModel(request, options) {
|
|
948
230
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
231
|
+
const model = createGatewayProviderModel(request, 'anthropic-messages', options.baseUrl);
|
|
232
|
+
const requestOptions = createGatewayProviderOptions(request, 'anthropic-messages', options, {
|
|
233
|
+
maxTokens: 4096,
|
|
234
|
+
signal: options.signal
|
|
235
|
+
});
|
|
236
|
+
const fastMode = shortcutProviderFastModeFromRequest('anthropic', request);
|
|
949
237
|
let response;
|
|
950
238
|
try {
|
|
951
|
-
response = await fetchImpl(`${
|
|
952
|
-
body: JSON.stringify(
|
|
953
|
-
headers:
|
|
239
|
+
response = await fetchImpl(`${model.baseUrl}/v1/messages`, {
|
|
240
|
+
body: JSON.stringify(withProviderFastModePayload(buildAnthropicMessagesRequest(model, request.context, requestOptions, false), fastMode)),
|
|
241
|
+
headers: concreteProviderHeaders(withProviderFastModeHeaders({
|
|
954
242
|
'anthropic-version': '2023-06-01',
|
|
955
243
|
'content-type': 'application/json',
|
|
956
|
-
...
|
|
957
|
-
|
|
958
|
-
}, shortcutProviderFastModeFromRequest('anthropic', request))),
|
|
244
|
+
...requestOptions.headers
|
|
245
|
+
}, fastMode)),
|
|
959
246
|
method: 'POST',
|
|
960
247
|
credentials: options.fetchOptions?.credentials,
|
|
961
248
|
signal: options.signal
|
|
@@ -986,8 +273,10 @@ export async function invokeAnthropicMessagesModel(request, options) {
|
|
|
986
273
|
return parsed;
|
|
987
274
|
}
|
|
988
275
|
export async function streamAiAnthropicMessagesModelRequest(request, options) {
|
|
989
|
-
const model =
|
|
990
|
-
const stream =
|
|
276
|
+
const model = createGatewayProviderModel(request, 'anthropic-messages', options.baseUrl);
|
|
277
|
+
const stream = streamSimpleAnthropic(model, request.context, createGatewayProviderOptions(request, 'anthropic-messages', options, {
|
|
278
|
+
signal: options.signal
|
|
279
|
+
}));
|
|
991
280
|
let finalMessage;
|
|
992
281
|
for await (const event of stream) {
|
|
993
282
|
if (event.type === 'done') {
|
|
@@ -1011,56 +300,4 @@ export async function streamAiAnthropicMessagesModelRequest(request, options) {
|
|
|
1011
300
|
usage: toProviderUsageFromAi(result?.usage)
|
|
1012
301
|
});
|
|
1013
302
|
}
|
|
1014
|
-
export function createAnthropicMessagesModelStreamTransport(options) {
|
|
1015
|
-
const fetchImpl = options.fetchImpl ?? fetch;
|
|
1016
|
-
return {
|
|
1017
|
-
kind: ShortcutXLModelCallTransportKind.AnthropicMessages,
|
|
1018
|
-
async stream(call, streamOptions) {
|
|
1019
|
-
const message = {
|
|
1020
|
-
api: AnthropicRuntimeApi,
|
|
1021
|
-
content: [],
|
|
1022
|
-
model: call.payload.model,
|
|
1023
|
-
provider: ShortcutXLModelCallTransportKind.AnthropicMessages,
|
|
1024
|
-
role: 'assistant',
|
|
1025
|
-
stopReason: ShortcutXLModelStreamStopReason.Stop,
|
|
1026
|
-
timestamp: Date.now(),
|
|
1027
|
-
usage: buildUsage(undefined)
|
|
1028
|
-
};
|
|
1029
|
-
let response;
|
|
1030
|
-
try {
|
|
1031
|
-
response = await fetchImpl(`${normalizeBaseUrl(options.baseUrl)}/v1/messages`, {
|
|
1032
|
-
body: JSON.stringify(buildRequestBody(call)),
|
|
1033
|
-
headers: {
|
|
1034
|
-
'anthropic-version': '2023-06-01',
|
|
1035
|
-
'content-type': 'application/json',
|
|
1036
|
-
...concreteHeaders(options.headers),
|
|
1037
|
-
...createAuthHeader(options.auth)
|
|
1038
|
-
},
|
|
1039
|
-
method: 'POST',
|
|
1040
|
-
credentials: options.fetchOptions?.credentials,
|
|
1041
|
-
signal: streamOptions.signal
|
|
1042
|
-
});
|
|
1043
|
-
}
|
|
1044
|
-
catch (error) {
|
|
1045
|
-
normalizeTransportFetchError(error, 'Anthropic Messages stream');
|
|
1046
|
-
}
|
|
1047
|
-
if (!response.ok) {
|
|
1048
|
-
await throwTransportHttpError(response);
|
|
1049
|
-
}
|
|
1050
|
-
try {
|
|
1051
|
-
await streamAnthropicMessagesResponse({
|
|
1052
|
-
callId: call.context.requestId,
|
|
1053
|
-
message,
|
|
1054
|
-
model: call.payload.model,
|
|
1055
|
-
onEvent: streamOptions.onEvent,
|
|
1056
|
-
response,
|
|
1057
|
-
usageStatusLogger: options.usageStatusLogger
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
catch (error) {
|
|
1061
|
-
normalizeTransportStreamError(error, 'Anthropic Messages stream');
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
303
|
//# sourceMappingURL=anthropic-messages-transport.js.map
|