@psnext/slingcli 2.4.20260507-3 → 2.4.20260509-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/LICENSE +1 -1
- package/README.md +1 -1
- package/bin/sling.js +39 -16
- package/node_modules/@aws-sdk/client-bedrock-runtime/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/agent-loop.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/agent.js +4 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +526 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js +243 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +616 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +348 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/execution-env.js +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/factory.js +9 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js +102 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js +194 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/jsonl.js +92 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/memory.js +42 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/shared.js +31 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +196 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/jsonl.js +170 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/memory.js +90 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js +258 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js +30 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +16 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +97 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js +26 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/proxy.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/package.json +7 -5
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/cli.js +6 -6
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/env-api-keys.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +307 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.js +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.js +22 -0
- package/node_modules/@earendil-works/pi-ai/dist/images.js +14 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/index.js +4 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/models.generated.js +427 -122
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js +129 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js +34 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-codex-responses.js +1 -1
- package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-completions.js +150 -122
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-responses-shared.js +14 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/openai-codex.js +25 -14
- package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/overflow.js +3 -0
- package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/package.json +5 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/bun/register-bedrock.js +4 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/args.js +1 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/config-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/list-models.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/session-picker.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/config.js +52 -30
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/agent-session.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/auth-storage.js +2 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/compaction/branch-summarization.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/compaction/compaction.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/utils.js +153 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/template.css +45 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/template.js +68 -4
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/loader.js +26 -12
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/keybindings.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/model-registry.js +3 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/model-resolver.js +2 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/package-manager.js +22 -5
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/provider-display-names.js +1 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/sdk.js +3 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/bash.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/edit.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/find.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/grep.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/ls.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/read.js +3 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/render-utils.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +205 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/write.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/main.js +2 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/migrations.js +3 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/bash-execution.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/bordered-loader.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/config-selector.js +25 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/custom-editor.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/custom-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/earendil-announcement.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/extension-editor.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/extension-input.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/extension-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/footer.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +4 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/model-selector.js +2 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/oauth-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/session-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/settings-selector.js +4 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/show-images-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/theme-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/thinking-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +3 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/user-message-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/user-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/visual-truncate.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/interactive-mode.js +47 -32
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/dark.json +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/light.json +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/theme.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/package-manager-cli.js +42 -39
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/clipboard.js +9 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/paths.js +16 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/version-check.js +9 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/package.json +9 -8
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/image.js +14 -7
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/markdown.js +24 -84
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/terminal-image.js +10 -4
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/tui.js +73 -4
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/utils.js +33 -7
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/package.json +3 -3
- package/node_modules/@mariozechner/clipboard/README.md +58 -0
- package/node_modules/@mariozechner/clipboard/index.d.ts +23 -0
- package/node_modules/@mariozechner/clipboard-linux-x64-gnu/README.md +3 -0
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/http2.d.ts +4 -1
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/stream/web.d.ts +4 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +1 -1
- package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
- package/node_modules/brace-expansion/package.json +1 -1
- package/node_modules/fast-xml-builder/CHANGELOG.md +4 -0
- package/node_modules/fast-xml-builder/lib/fxb.cjs +1 -1
- package/node_modules/fast-xml-builder/lib/fxb.d.cts +91 -1
- package/node_modules/fast-xml-builder/lib/fxb.min.js +1 -1
- package/node_modules/fast-xml-builder/lib/fxb.min.js.map +1 -1
- package/node_modules/fast-xml-builder/package.json +3 -2
- package/node_modules/fast-xml-builder/src/fxb.d.ts +92 -3
- package/node_modules/fast-xml-builder/src/fxb.js +92 -31
- package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +87 -33
- package/node_modules/get-east-asian-width/lookup-data.js +15 -12
- package/node_modules/get-east-asian-width/lookup.js +25 -22
- package/node_modules/get-east-asian-width/package.json +1 -1
- package/node_modules/jiti/README.md +258 -0
- package/node_modules/jiti/dist/babel.cjs +257 -0
- package/node_modules/jiti/dist/jiti.cjs +1 -0
- package/node_modules/jiti/lib/jiti.mjs +29 -0
- package/node_modules/jiti/lib/types.d.ts +420 -0
- package/node_modules/jiti/package.json +146 -0
- package/node_modules/protobufjs/dist/light/protobuf.js +5 -3
- package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
- package/node_modules/protobufjs/dist/protobuf.js +5 -3
- package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/package.json +1 -1
- package/node_modules/protobufjs/src/namespace.js +3 -1
- package/node_modules/semver/README.md +19 -4
- package/node_modules/semver/bin/semver.js +14 -10
- package/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/semver/index.js +2 -0
- package/node_modules/semver/internal/re.js +1 -1
- package/node_modules/semver/package.json +3 -3
- package/node_modules/semver/range.bnf +5 -4
- package/node_modules/socks/package.json +2 -2
- package/node_modules/xml-naming/README.md +189 -0
- package/node_modules/xml-naming/package.json +54 -0
- package/node_modules/xml-naming/src/index.d.ts +74 -0
- package/node_modules/xml-naming/src/index.js +270 -0
- package/package.json +6 -6
- package/sling-default-packages.json +2 -1
- package/slingshot/index.js +442 -23
- package/node_modules/@mariozechner/jiti/dist/babel.cjs +0 -246
- package/node_modules/@mariozechner/jiti/dist/jiti.cjs +0 -1
- package/node_modules/@mariozechner/jiti/package.json +0 -96
- package/node_modules/@mariozechner/pi-agent-core/dist/index.js +0 -9
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/cli.js +0 -116
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/env-api-keys.js +0 -166
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/index.js +0 -15
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/models.generated.js +0 -16568
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/providers/amazon-bedrock.js +0 -753
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/providers/openai-codex-responses.js +0 -909
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses-shared.js +0 -479
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/utils/oauth/openai-codex.js +0 -374
- package/node_modules/@mariozechner/pi-ai/dist/api-registry.js +0 -44
- package/node_modules/@mariozechner/pi-ai/dist/bedrock-provider.js +0 -6
- package/node_modules/@mariozechner/pi-ai/dist/models.js +0 -71
- package/node_modules/@mariozechner/pi-ai/dist/oauth.js +0 -2
- package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +0 -951
- package/node_modules/@mariozechner/pi-ai/dist/providers/azure-openai-responses.js +0 -208
- package/node_modules/@mariozechner/pi-ai/dist/providers/cloudflare.js +0 -26
- package/node_modules/@mariozechner/pi-ai/dist/providers/faux.js +0 -368
- package/node_modules/@mariozechner/pi-ai/dist/providers/github-copilot-headers.js +0 -29
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-shared.js +0 -329
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-vertex.js +0 -442
- package/node_modules/@mariozechner/pi-ai/dist/providers/google.js +0 -400
- package/node_modules/@mariozechner/pi-ai/dist/providers/mistral.js +0 -535
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js +0 -908
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses.js +0 -220
- package/node_modules/@mariozechner/pi-ai/dist/providers/register-builtins.js +0 -243
- package/node_modules/@mariozechner/pi-ai/dist/providers/simple-options.js +0 -39
- package/node_modules/@mariozechner/pi-ai/dist/providers/transform-messages.js +0 -184
- package/node_modules/@mariozechner/pi-ai/dist/stream.js +0 -27
- package/node_modules/@mariozechner/pi-ai/dist/types.js +0 -2
- package/node_modules/@mariozechner/pi-ai/dist/utils/event-stream.js +0 -81
- package/node_modules/@mariozechner/pi-ai/dist/utils/hash.js +0 -14
- package/node_modules/@mariozechner/pi-ai/dist/utils/headers.js +0 -8
- package/node_modules/@mariozechner/pi-ai/dist/utils/json-parse.js +0 -113
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/anthropic.js +0 -335
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/github-copilot.js +0 -292
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/index.js +0 -121
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/oauth-page.js +0 -105
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/pkce.js +0 -31
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/types.js +0 -2
- package/node_modules/@mariozechner/pi-ai/dist/utils/overflow.js +0 -146
- package/node_modules/@mariozechner/pi-ai/dist/utils/sanitize-unicode.js +0 -26
- package/node_modules/@mariozechner/pi-ai/dist/utils/typebox-helpers.js +0 -21
- package/node_modules/@mariozechner/pi-ai/dist/utils/validation.js +0 -281
- package/node_modules/@mariozechner/pi-ai/package.json +0 -108
- package/node_modules/@mariozechner/pi-coding-agent/dist/bun/register-bedrock.js +0 -4
- package/node_modules/@mariozechner/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.js +0 -22
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/agent-loop.js +0 -458
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/agent.js +0 -398
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/index.js +0 -9
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/proxy.js +0 -278
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/types.js +0 -2
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/package.json +0 -45
- package/node_modules/socks/.claude/settings.local.json +0 -26
- package/node_modules/std-env/LICENCE +0 -22
- package/node_modules/std-env/README.md +0 -118
- package/node_modules/std-env/dist/index.cjs +0 -1
- package/node_modules/std-env/dist/index.d.cts +0 -92
- package/node_modules/std-env/dist/index.d.mts +0 -92
- package/node_modules/std-env/dist/index.d.ts +0 -92
- package/node_modules/std-env/dist/index.mjs +0 -1
- package/node_modules/std-env/package.json +0 -46
- package/node_modules/yoctocolors/base.d.ts +0 -47
- package/node_modules/yoctocolors/base.js +0 -94
- package/node_modules/yoctocolors/index.d.ts +0 -2
- package/node_modules/yoctocolors/index.js +0 -2
- package/node_modules/yoctocolors/license +0 -9
- package/node_modules/yoctocolors/package.json +0 -69
- package/node_modules/yoctocolors/readme.md +0 -138
- /package/node_modules/{@mariozechner/pi-coding-agent/dist/core → @earendil-works/pi-agent-core/dist/harness}/compaction/utils.js +0 -0
- /package/node_modules/{@mariozechner/pi-coding-agent/dist/core/tools → @earendil-works/pi-agent-core/dist/harness/utils}/truncate.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/types.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/api-registry.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/bedrock-provider.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/models.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/oauth.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/providers/amazon-bedrock.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/anthropic.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/azure-openai-responses.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/cloudflare.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/faux.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/github-copilot-headers.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/google-shared.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/google-vertex.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/google.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/mistral.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-responses.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/register-builtins.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/simple-options.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/transform-messages.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/session-resources.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/stream.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/types.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/utils/diagnostics.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/event-stream.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/hash.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/headers.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/json-parse.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/anthropic.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/github-copilot.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/index.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/oauth-page.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/pkce.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/types.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/sanitize-unicode.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/typebox-helpers.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/validation.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/bun/cli.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/bun/restore-sandbox-env.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/file-processor.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/initial-message.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/agent-session-runtime.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/agent-session-services.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/auth-guidance.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/bash-executor.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/compaction/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/defaults.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/diagnostics.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/event-bus.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/exec.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/ansi-to-html.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/template.html +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/tool-renderer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/vendor/highlight.min.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/vendor/marked.min.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/runner.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/types.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/wrapper.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/footer-data-provider.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/messages.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/output-guard.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/prompt-templates.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/resolve-config-value.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/resource-loader.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/session-cwd.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/session-manager.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/settings-manager.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/skills.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/slash-commands.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/source-info.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/system-prompt.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/telemetry.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/timings.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/edit-diff.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/file-mutation-queue.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/output-accumulator.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/path-utils.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/tool-definition-wrapper.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/assets/clankolas.png +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/armin.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/countdown-timer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/daxnuts.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/diff.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/theme-schema.json +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/print-mode.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/jsonl.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/rpc-client.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/rpc-mode.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/rpc-types.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/changelog.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/child-process.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/clipboard-image.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/clipboard-native.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/exif-orientation.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/frontmatter.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/fs-watch.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/git.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/image-convert.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/image-resize.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/mime.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/photon.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/pi-user-agent.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/shell.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/sleep.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/tools-manager.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/autocomplete.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/box.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/cancellable-loader.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/editor.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/input.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/loader.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/select-list.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/settings-list.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/spacer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/text.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/truncated-text.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/editor-component.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/fuzzy.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/keybindings.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/keys.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/kill-ring.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/stdin-buffer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/terminal.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/undo-stack.js +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/LICENSE +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-cli.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-hooks.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-native.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-register.d.mts +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-register.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti/lib/jiti.mjs → jiti/lib/jiti-static.mjs} +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti.cjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti.d.cts +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti.d.mts +0 -0
|
@@ -1,951 +0,0 @@
|
|
|
1
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
-
import { getEnvApiKey } from "../env-api-keys.js";
|
|
3
|
-
import { calculateCost } from "../models.js";
|
|
4
|
-
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
5
|
-
import { headersToRecord } from "../utils/headers.js";
|
|
6
|
-
import { parseJsonWithRepair, parseStreamingJson } from "../utils/json-parse.js";
|
|
7
|
-
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
8
|
-
import { resolveCloudflareBaseUrl } from "./cloudflare.js";
|
|
9
|
-
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
10
|
-
import { adjustMaxTokensForThinking, buildBaseOptions } from "./simple-options.js";
|
|
11
|
-
import { transformMessages } from "./transform-messages.js";
|
|
12
|
-
/**
|
|
13
|
-
* Resolve cache retention preference.
|
|
14
|
-
* Defaults to "short" and uses PI_CACHE_RETENTION for backward compatibility.
|
|
15
|
-
*/
|
|
16
|
-
function resolveCacheRetention(cacheRetention) {
|
|
17
|
-
if (cacheRetention) {
|
|
18
|
-
return cacheRetention;
|
|
19
|
-
}
|
|
20
|
-
if (typeof process !== "undefined" && process.env.PI_CACHE_RETENTION === "long") {
|
|
21
|
-
return "long";
|
|
22
|
-
}
|
|
23
|
-
return "short";
|
|
24
|
-
}
|
|
25
|
-
function getCacheControl(model, cacheRetention) {
|
|
26
|
-
const retention = resolveCacheRetention(cacheRetention);
|
|
27
|
-
if (retention === "none") {
|
|
28
|
-
return { retention };
|
|
29
|
-
}
|
|
30
|
-
const ttl = retention === "long" && getAnthropicCompat(model).supportsLongCacheRetention ? "1h" : undefined;
|
|
31
|
-
return {
|
|
32
|
-
retention,
|
|
33
|
-
cacheControl: { type: "ephemeral", ...(ttl && { ttl }) },
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// Stealth mode: Mimic Claude Code's tool naming exactly
|
|
37
|
-
const claudeCodeVersion = "2.1.75";
|
|
38
|
-
// Claude Code 2.x tool names (canonical casing)
|
|
39
|
-
// Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
|
|
40
|
-
// To update: https://github.com/badlogic/cchistory
|
|
41
|
-
const claudeCodeTools = [
|
|
42
|
-
"Read",
|
|
43
|
-
"Write",
|
|
44
|
-
"Edit",
|
|
45
|
-
"Bash",
|
|
46
|
-
"Grep",
|
|
47
|
-
"Glob",
|
|
48
|
-
"AskUserQuestion",
|
|
49
|
-
"EnterPlanMode",
|
|
50
|
-
"ExitPlanMode",
|
|
51
|
-
"KillShell",
|
|
52
|
-
"NotebookEdit",
|
|
53
|
-
"Skill",
|
|
54
|
-
"Task",
|
|
55
|
-
"TaskOutput",
|
|
56
|
-
"TodoWrite",
|
|
57
|
-
"WebFetch",
|
|
58
|
-
"WebSearch",
|
|
59
|
-
];
|
|
60
|
-
const ccToolLookup = new Map(claudeCodeTools.map((t) => [t.toLowerCase(), t]));
|
|
61
|
-
// Convert tool name to CC canonical casing if it matches (case-insensitive)
|
|
62
|
-
const toClaudeCodeName = (name) => ccToolLookup.get(name.toLowerCase()) ?? name;
|
|
63
|
-
const fromClaudeCodeName = (name, tools) => {
|
|
64
|
-
if (tools && tools.length > 0) {
|
|
65
|
-
const lowerName = name.toLowerCase();
|
|
66
|
-
const matchedTool = tools.find((tool) => tool.name.toLowerCase() === lowerName);
|
|
67
|
-
if (matchedTool)
|
|
68
|
-
return matchedTool.name;
|
|
69
|
-
}
|
|
70
|
-
return name;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Convert content blocks to Anthropic API format
|
|
74
|
-
*/
|
|
75
|
-
function convertContentBlocks(content) {
|
|
76
|
-
// If only text blocks, return as concatenated string for simplicity
|
|
77
|
-
const hasImages = content.some((c) => c.type === "image");
|
|
78
|
-
if (!hasImages) {
|
|
79
|
-
return sanitizeSurrogates(content.map((c) => c.text).join("\n"));
|
|
80
|
-
}
|
|
81
|
-
// If we have images, convert to content block array
|
|
82
|
-
const blocks = content.map((block) => {
|
|
83
|
-
if (block.type === "text") {
|
|
84
|
-
return {
|
|
85
|
-
type: "text",
|
|
86
|
-
text: sanitizeSurrogates(block.text),
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
type: "image",
|
|
91
|
-
source: {
|
|
92
|
-
type: "base64",
|
|
93
|
-
media_type: block.mimeType,
|
|
94
|
-
data: block.data,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
// If only images (no text), add placeholder text block
|
|
99
|
-
const hasText = blocks.some((b) => b.type === "text");
|
|
100
|
-
if (!hasText) {
|
|
101
|
-
blocks.unshift({
|
|
102
|
-
type: "text",
|
|
103
|
-
text: "(see attached image)",
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return blocks;
|
|
107
|
-
}
|
|
108
|
-
const FINE_GRAINED_TOOL_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14";
|
|
109
|
-
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
110
|
-
function getAnthropicCompat(model) {
|
|
111
|
-
return {
|
|
112
|
-
supportsEagerToolInputStreaming: model.compat?.supportsEagerToolInputStreaming ?? true,
|
|
113
|
-
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function mergeHeaders(...headerSources) {
|
|
117
|
-
const merged = {};
|
|
118
|
-
for (const headers of headerSources) {
|
|
119
|
-
if (headers) {
|
|
120
|
-
Object.assign(merged, headers);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return merged;
|
|
124
|
-
}
|
|
125
|
-
const ANTHROPIC_MESSAGE_EVENTS = new Set([
|
|
126
|
-
"message_start",
|
|
127
|
-
"message_delta",
|
|
128
|
-
"message_stop",
|
|
129
|
-
"content_block_start",
|
|
130
|
-
"content_block_delta",
|
|
131
|
-
"content_block_stop",
|
|
132
|
-
]);
|
|
133
|
-
function flushSseEvent(state) {
|
|
134
|
-
if (!state.event && state.data.length === 0) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
const event = {
|
|
138
|
-
event: state.event,
|
|
139
|
-
data: state.data.join("\n"),
|
|
140
|
-
raw: [...state.raw],
|
|
141
|
-
};
|
|
142
|
-
state.event = null;
|
|
143
|
-
state.data = [];
|
|
144
|
-
state.raw = [];
|
|
145
|
-
return event;
|
|
146
|
-
}
|
|
147
|
-
function decodeSseLine(line, state) {
|
|
148
|
-
if (line === "") {
|
|
149
|
-
return flushSseEvent(state);
|
|
150
|
-
}
|
|
151
|
-
state.raw.push(line);
|
|
152
|
-
if (line.startsWith(":")) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
const delimiterIndex = line.indexOf(":");
|
|
156
|
-
const fieldName = delimiterIndex === -1 ? line : line.slice(0, delimiterIndex);
|
|
157
|
-
let value = delimiterIndex === -1 ? "" : line.slice(delimiterIndex + 1);
|
|
158
|
-
if (value.startsWith(" ")) {
|
|
159
|
-
value = value.slice(1);
|
|
160
|
-
}
|
|
161
|
-
if (fieldName === "event") {
|
|
162
|
-
state.event = value;
|
|
163
|
-
}
|
|
164
|
-
else if (fieldName === "data") {
|
|
165
|
-
state.data.push(value);
|
|
166
|
-
}
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
function nextLineBreakIndex(text) {
|
|
170
|
-
const carriageReturnIndex = text.indexOf("\r");
|
|
171
|
-
const newlineIndex = text.indexOf("\n");
|
|
172
|
-
if (carriageReturnIndex === -1) {
|
|
173
|
-
return newlineIndex;
|
|
174
|
-
}
|
|
175
|
-
if (newlineIndex === -1) {
|
|
176
|
-
return carriageReturnIndex;
|
|
177
|
-
}
|
|
178
|
-
return Math.min(carriageReturnIndex, newlineIndex);
|
|
179
|
-
}
|
|
180
|
-
function consumeLine(text) {
|
|
181
|
-
const lineBreakIndex = nextLineBreakIndex(text);
|
|
182
|
-
if (lineBreakIndex === -1) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
let nextIndex = lineBreakIndex + 1;
|
|
186
|
-
if (text[lineBreakIndex] === "\r" && text[nextIndex] === "\n") {
|
|
187
|
-
nextIndex += 1;
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
line: text.slice(0, lineBreakIndex),
|
|
191
|
-
rest: text.slice(nextIndex),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
async function* iterateSseMessages(body, signal) {
|
|
195
|
-
const reader = body.getReader();
|
|
196
|
-
const decoder = new TextDecoder();
|
|
197
|
-
const state = { event: null, data: [], raw: [] };
|
|
198
|
-
let buffer = "";
|
|
199
|
-
try {
|
|
200
|
-
while (true) {
|
|
201
|
-
if (signal?.aborted) {
|
|
202
|
-
throw new Error("Request was aborted");
|
|
203
|
-
}
|
|
204
|
-
const { value, done } = await reader.read();
|
|
205
|
-
if (done) {
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
buffer += decoder.decode(value, { stream: true });
|
|
209
|
-
let consumed = consumeLine(buffer);
|
|
210
|
-
while (consumed) {
|
|
211
|
-
buffer = consumed.rest;
|
|
212
|
-
const event = decodeSseLine(consumed.line, state);
|
|
213
|
-
if (event) {
|
|
214
|
-
yield event;
|
|
215
|
-
}
|
|
216
|
-
consumed = consumeLine(buffer);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
buffer += decoder.decode();
|
|
220
|
-
let consumed = consumeLine(buffer);
|
|
221
|
-
while (consumed) {
|
|
222
|
-
buffer = consumed.rest;
|
|
223
|
-
const event = decodeSseLine(consumed.line, state);
|
|
224
|
-
if (event) {
|
|
225
|
-
yield event;
|
|
226
|
-
}
|
|
227
|
-
consumed = consumeLine(buffer);
|
|
228
|
-
}
|
|
229
|
-
if (buffer.length > 0) {
|
|
230
|
-
const event = decodeSseLine(buffer, state);
|
|
231
|
-
if (event) {
|
|
232
|
-
yield event;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const trailingEvent = flushSseEvent(state);
|
|
236
|
-
if (trailingEvent) {
|
|
237
|
-
yield trailingEvent;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
finally {
|
|
241
|
-
reader.releaseLock();
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
async function* iterateAnthropicEvents(response, signal) {
|
|
245
|
-
if (!response.body) {
|
|
246
|
-
throw new Error("Attempted to iterate over an Anthropic response with no body");
|
|
247
|
-
}
|
|
248
|
-
let sawMessageStart = false;
|
|
249
|
-
let sawMessageEnd = false;
|
|
250
|
-
for await (const sse of iterateSseMessages(response.body, signal)) {
|
|
251
|
-
if (sse.event === "error") {
|
|
252
|
-
throw new Error(sse.data);
|
|
253
|
-
}
|
|
254
|
-
if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
const event = parseJsonWithRepair(sse.data);
|
|
259
|
-
if (event.type === "message_start") {
|
|
260
|
-
sawMessageStart = true;
|
|
261
|
-
}
|
|
262
|
-
else if (event.type === "message_stop") {
|
|
263
|
-
sawMessageEnd = true;
|
|
264
|
-
}
|
|
265
|
-
yield event;
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
269
|
-
throw new Error(`Could not parse Anthropic SSE event ${sse.event}: ${message}; data=${sse.data}; raw=${sse.raw.join("\\n")}`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (sawMessageStart && !sawMessageEnd) {
|
|
273
|
-
throw new Error("Anthropic stream ended before message_stop");
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
export const streamAnthropic = (model, context, options) => {
|
|
277
|
-
const stream = new AssistantMessageEventStream();
|
|
278
|
-
(async () => {
|
|
279
|
-
const output = {
|
|
280
|
-
role: "assistant",
|
|
281
|
-
content: [],
|
|
282
|
-
api: model.api,
|
|
283
|
-
provider: model.provider,
|
|
284
|
-
model: model.id,
|
|
285
|
-
usage: {
|
|
286
|
-
input: 0,
|
|
287
|
-
output: 0,
|
|
288
|
-
cacheRead: 0,
|
|
289
|
-
cacheWrite: 0,
|
|
290
|
-
totalTokens: 0,
|
|
291
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
292
|
-
},
|
|
293
|
-
stopReason: "stop",
|
|
294
|
-
timestamp: Date.now(),
|
|
295
|
-
};
|
|
296
|
-
try {
|
|
297
|
-
let client;
|
|
298
|
-
let isOAuth;
|
|
299
|
-
if (options?.client) {
|
|
300
|
-
client = options.client;
|
|
301
|
-
isOAuth = false;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
const apiKey = options?.apiKey ?? getEnvApiKey(model.provider) ?? "";
|
|
305
|
-
let copilotDynamicHeaders;
|
|
306
|
-
if (model.provider === "github-copilot") {
|
|
307
|
-
const hasImages = hasCopilotVisionInput(context.messages);
|
|
308
|
-
copilotDynamicHeaders = buildCopilotDynamicHeaders({
|
|
309
|
-
messages: context.messages,
|
|
310
|
-
hasImages,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
const created = createClient(model, apiKey, options?.interleavedThinking ?? true, shouldUseFineGrainedToolStreamingBeta(model, context), options?.headers, copilotDynamicHeaders);
|
|
314
|
-
client = created.client;
|
|
315
|
-
isOAuth = created.isOAuthToken;
|
|
316
|
-
}
|
|
317
|
-
let params = buildParams(model, context, isOAuth, options);
|
|
318
|
-
const nextParams = await options?.onPayload?.(params, model);
|
|
319
|
-
if (nextParams !== undefined) {
|
|
320
|
-
params = nextParams;
|
|
321
|
-
}
|
|
322
|
-
const requestOptions = {
|
|
323
|
-
...(options?.signal ? { signal: options.signal } : {}),
|
|
324
|
-
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
|
|
325
|
-
...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
|
|
326
|
-
};
|
|
327
|
-
const response = await client.messages.create({ ...params, stream: true }, requestOptions).asResponse();
|
|
328
|
-
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
329
|
-
stream.push({ type: "start", partial: output });
|
|
330
|
-
const blocks = output.content;
|
|
331
|
-
for await (const event of iterateAnthropicEvents(response, options?.signal)) {
|
|
332
|
-
if (event.type === "message_start") {
|
|
333
|
-
output.responseId = event.message.id;
|
|
334
|
-
// Capture initial token usage from message_start event
|
|
335
|
-
// This ensures we have input token counts even if the stream is aborted early
|
|
336
|
-
output.usage.input = event.message.usage.input_tokens || 0;
|
|
337
|
-
output.usage.output = event.message.usage.output_tokens || 0;
|
|
338
|
-
output.usage.cacheRead = event.message.usage.cache_read_input_tokens || 0;
|
|
339
|
-
output.usage.cacheWrite = event.message.usage.cache_creation_input_tokens || 0;
|
|
340
|
-
// Anthropic doesn't provide total_tokens, compute from components
|
|
341
|
-
output.usage.totalTokens =
|
|
342
|
-
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
343
|
-
calculateCost(model, output.usage);
|
|
344
|
-
}
|
|
345
|
-
else if (event.type === "content_block_start") {
|
|
346
|
-
if (event.content_block.type === "text") {
|
|
347
|
-
const block = {
|
|
348
|
-
type: "text",
|
|
349
|
-
text: "",
|
|
350
|
-
index: event.index,
|
|
351
|
-
};
|
|
352
|
-
output.content.push(block);
|
|
353
|
-
stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
|
|
354
|
-
}
|
|
355
|
-
else if (event.content_block.type === "thinking") {
|
|
356
|
-
const block = {
|
|
357
|
-
type: "thinking",
|
|
358
|
-
thinking: "",
|
|
359
|
-
thinkingSignature: "",
|
|
360
|
-
index: event.index,
|
|
361
|
-
};
|
|
362
|
-
output.content.push(block);
|
|
363
|
-
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
|
|
364
|
-
}
|
|
365
|
-
else if (event.content_block.type === "redacted_thinking") {
|
|
366
|
-
const block = {
|
|
367
|
-
type: "thinking",
|
|
368
|
-
thinking: "[Reasoning redacted]",
|
|
369
|
-
thinkingSignature: event.content_block.data,
|
|
370
|
-
redacted: true,
|
|
371
|
-
index: event.index,
|
|
372
|
-
};
|
|
373
|
-
output.content.push(block);
|
|
374
|
-
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
|
|
375
|
-
}
|
|
376
|
-
else if (event.content_block.type === "tool_use") {
|
|
377
|
-
const block = {
|
|
378
|
-
type: "toolCall",
|
|
379
|
-
id: event.content_block.id,
|
|
380
|
-
name: isOAuth
|
|
381
|
-
? fromClaudeCodeName(event.content_block.name, context.tools)
|
|
382
|
-
: event.content_block.name,
|
|
383
|
-
arguments: event.content_block.input ?? {},
|
|
384
|
-
partialJson: "",
|
|
385
|
-
index: event.index,
|
|
386
|
-
};
|
|
387
|
-
output.content.push(block);
|
|
388
|
-
stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
else if (event.type === "content_block_delta") {
|
|
392
|
-
if (event.delta.type === "text_delta") {
|
|
393
|
-
const index = blocks.findIndex((b) => b.index === event.index);
|
|
394
|
-
const block = blocks[index];
|
|
395
|
-
if (block && block.type === "text") {
|
|
396
|
-
block.text += event.delta.text;
|
|
397
|
-
stream.push({
|
|
398
|
-
type: "text_delta",
|
|
399
|
-
contentIndex: index,
|
|
400
|
-
delta: event.delta.text,
|
|
401
|
-
partial: output,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else if (event.delta.type === "thinking_delta") {
|
|
406
|
-
const index = blocks.findIndex((b) => b.index === event.index);
|
|
407
|
-
const block = blocks[index];
|
|
408
|
-
if (block && block.type === "thinking") {
|
|
409
|
-
block.thinking += event.delta.thinking;
|
|
410
|
-
stream.push({
|
|
411
|
-
type: "thinking_delta",
|
|
412
|
-
contentIndex: index,
|
|
413
|
-
delta: event.delta.thinking,
|
|
414
|
-
partial: output,
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
else if (event.delta.type === "input_json_delta") {
|
|
419
|
-
const index = blocks.findIndex((b) => b.index === event.index);
|
|
420
|
-
const block = blocks[index];
|
|
421
|
-
if (block && block.type === "toolCall") {
|
|
422
|
-
block.partialJson += event.delta.partial_json;
|
|
423
|
-
block.arguments = parseStreamingJson(block.partialJson);
|
|
424
|
-
stream.push({
|
|
425
|
-
type: "toolcall_delta",
|
|
426
|
-
contentIndex: index,
|
|
427
|
-
delta: event.delta.partial_json,
|
|
428
|
-
partial: output,
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
else if (event.delta.type === "signature_delta") {
|
|
433
|
-
const index = blocks.findIndex((b) => b.index === event.index);
|
|
434
|
-
const block = blocks[index];
|
|
435
|
-
if (block && block.type === "thinking") {
|
|
436
|
-
block.thinkingSignature = block.thinkingSignature || "";
|
|
437
|
-
block.thinkingSignature += event.delta.signature;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
else if (event.type === "content_block_stop") {
|
|
442
|
-
const index = blocks.findIndex((b) => b.index === event.index);
|
|
443
|
-
const block = blocks[index];
|
|
444
|
-
if (block) {
|
|
445
|
-
delete block.index;
|
|
446
|
-
if (block.type === "text") {
|
|
447
|
-
stream.push({
|
|
448
|
-
type: "text_end",
|
|
449
|
-
contentIndex: index,
|
|
450
|
-
content: block.text,
|
|
451
|
-
partial: output,
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
else if (block.type === "thinking") {
|
|
455
|
-
stream.push({
|
|
456
|
-
type: "thinking_end",
|
|
457
|
-
contentIndex: index,
|
|
458
|
-
content: block.thinking,
|
|
459
|
-
partial: output,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
else if (block.type === "toolCall") {
|
|
463
|
-
block.arguments = parseStreamingJson(block.partialJson);
|
|
464
|
-
// Finalize in-place and strip the scratch buffer so replay only
|
|
465
|
-
// carries parsed arguments.
|
|
466
|
-
delete block.partialJson;
|
|
467
|
-
stream.push({
|
|
468
|
-
type: "toolcall_end",
|
|
469
|
-
contentIndex: index,
|
|
470
|
-
toolCall: block,
|
|
471
|
-
partial: output,
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
else if (event.type === "message_delta") {
|
|
477
|
-
if (event.delta.stop_reason) {
|
|
478
|
-
output.stopReason = mapStopReason(event.delta.stop_reason);
|
|
479
|
-
}
|
|
480
|
-
// Only update usage fields if present (not null).
|
|
481
|
-
// Preserves input_tokens from message_start when proxies omit it in message_delta.
|
|
482
|
-
if (event.usage.input_tokens != null) {
|
|
483
|
-
output.usage.input = event.usage.input_tokens;
|
|
484
|
-
}
|
|
485
|
-
if (event.usage.output_tokens != null) {
|
|
486
|
-
output.usage.output = event.usage.output_tokens;
|
|
487
|
-
}
|
|
488
|
-
if (event.usage.cache_read_input_tokens != null) {
|
|
489
|
-
output.usage.cacheRead = event.usage.cache_read_input_tokens;
|
|
490
|
-
}
|
|
491
|
-
if (event.usage.cache_creation_input_tokens != null) {
|
|
492
|
-
output.usage.cacheWrite = event.usage.cache_creation_input_tokens;
|
|
493
|
-
}
|
|
494
|
-
// Anthropic doesn't provide total_tokens, compute from components
|
|
495
|
-
output.usage.totalTokens =
|
|
496
|
-
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
497
|
-
calculateCost(model, output.usage);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
if (options?.signal?.aborted) {
|
|
501
|
-
throw new Error("Request was aborted");
|
|
502
|
-
}
|
|
503
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
504
|
-
throw new Error("An unknown error occurred");
|
|
505
|
-
}
|
|
506
|
-
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
507
|
-
stream.end();
|
|
508
|
-
}
|
|
509
|
-
catch (error) {
|
|
510
|
-
for (const block of output.content) {
|
|
511
|
-
delete block.index;
|
|
512
|
-
// partialJson is only a streaming scratch buffer; never persist it.
|
|
513
|
-
delete block.partialJson;
|
|
514
|
-
}
|
|
515
|
-
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
516
|
-
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
517
|
-
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
518
|
-
stream.end();
|
|
519
|
-
}
|
|
520
|
-
})();
|
|
521
|
-
return stream;
|
|
522
|
-
};
|
|
523
|
-
/**
|
|
524
|
-
* Check if a model supports adaptive thinking (Opus 4.6+, Sonnet 4.6)
|
|
525
|
-
*/
|
|
526
|
-
function supportsAdaptiveThinking(modelId) {
|
|
527
|
-
// Adaptive-thinking model IDs (with or without date suffix)
|
|
528
|
-
return (modelId.includes("opus-4-6") ||
|
|
529
|
-
modelId.includes("opus-4.6") ||
|
|
530
|
-
modelId.includes("opus-4-7") ||
|
|
531
|
-
modelId.includes("opus-4.7") ||
|
|
532
|
-
modelId.includes("sonnet-4-6") ||
|
|
533
|
-
modelId.includes("sonnet-4.6"));
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Map ThinkingLevel to Anthropic effort levels for adaptive thinking.
|
|
537
|
-
* Note: effort "max" is only valid on Opus 4.6, while Opus 4.7 supports "xhigh".
|
|
538
|
-
*/
|
|
539
|
-
function mapThinkingLevelToEffort(model, level) {
|
|
540
|
-
const mapped = level ? model.thinkingLevelMap?.[level] : undefined;
|
|
541
|
-
if (typeof mapped === "string")
|
|
542
|
-
return mapped;
|
|
543
|
-
switch (level) {
|
|
544
|
-
case "minimal":
|
|
545
|
-
case "low":
|
|
546
|
-
return "low";
|
|
547
|
-
case "medium":
|
|
548
|
-
return "medium";
|
|
549
|
-
case "high":
|
|
550
|
-
return "high";
|
|
551
|
-
default:
|
|
552
|
-
return "high";
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
export const streamSimpleAnthropic = (model, context, options) => {
|
|
556
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
557
|
-
if (!apiKey) {
|
|
558
|
-
throw new Error(`No API key for provider: ${model.provider}`);
|
|
559
|
-
}
|
|
560
|
-
const base = buildBaseOptions(model, options, apiKey);
|
|
561
|
-
if (!options?.reasoning) {
|
|
562
|
-
return streamAnthropic(model, context, { ...base, thinkingEnabled: false });
|
|
563
|
-
}
|
|
564
|
-
// For Opus 4.6 and Sonnet 4.6: use adaptive thinking with effort level
|
|
565
|
-
// For older models: use budget-based thinking
|
|
566
|
-
if (supportsAdaptiveThinking(model.id)) {
|
|
567
|
-
const effort = mapThinkingLevelToEffort(model, options.reasoning);
|
|
568
|
-
return streamAnthropic(model, context, {
|
|
569
|
-
...base,
|
|
570
|
-
thinkingEnabled: true,
|
|
571
|
-
effort,
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
const adjusted = adjustMaxTokensForThinking(base.maxTokens || 0, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
575
|
-
return streamAnthropic(model, context, {
|
|
576
|
-
...base,
|
|
577
|
-
maxTokens: adjusted.maxTokens,
|
|
578
|
-
thinkingEnabled: true,
|
|
579
|
-
thinkingBudgetTokens: adjusted.thinkingBudget,
|
|
580
|
-
});
|
|
581
|
-
};
|
|
582
|
-
function isOAuthToken(apiKey) {
|
|
583
|
-
return apiKey.includes("sk-ant-oat");
|
|
584
|
-
}
|
|
585
|
-
function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStreamingBeta, optionsHeaders, dynamicHeaders) {
|
|
586
|
-
// Adaptive thinking models (Opus 4.6, Sonnet 4.6) have interleaved thinking built-in.
|
|
587
|
-
// The beta header is deprecated on Opus 4.6 and redundant on Sonnet 4.6, so skip it.
|
|
588
|
-
const needsInterleavedBeta = interleavedThinking && !supportsAdaptiveThinking(model.id);
|
|
589
|
-
const betaFeatures = [];
|
|
590
|
-
if (useFineGrainedToolStreamingBeta) {
|
|
591
|
-
betaFeatures.push(FINE_GRAINED_TOOL_STREAMING_BETA);
|
|
592
|
-
}
|
|
593
|
-
if (needsInterleavedBeta) {
|
|
594
|
-
betaFeatures.push(INTERLEAVED_THINKING_BETA);
|
|
595
|
-
}
|
|
596
|
-
if (model.provider === "cloudflare-ai-gateway") {
|
|
597
|
-
const client = new Anthropic({
|
|
598
|
-
apiKey: null,
|
|
599
|
-
authToken: null,
|
|
600
|
-
baseURL: resolveCloudflareBaseUrl(model),
|
|
601
|
-
dangerouslyAllowBrowser: true,
|
|
602
|
-
defaultHeaders: mergeHeaders({
|
|
603
|
-
accept: "application/json",
|
|
604
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
605
|
-
"cf-aig-authorization": `Bearer ${apiKey}`,
|
|
606
|
-
"x-api-key": null,
|
|
607
|
-
Authorization: null,
|
|
608
|
-
...(betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}),
|
|
609
|
-
}, model.headers, optionsHeaders),
|
|
610
|
-
});
|
|
611
|
-
return { client, isOAuthToken: false };
|
|
612
|
-
}
|
|
613
|
-
// Copilot: Bearer auth, selective betas.
|
|
614
|
-
if (model.provider === "github-copilot") {
|
|
615
|
-
const client = new Anthropic({
|
|
616
|
-
apiKey: null,
|
|
617
|
-
authToken: apiKey,
|
|
618
|
-
baseURL: model.baseUrl,
|
|
619
|
-
dangerouslyAllowBrowser: true,
|
|
620
|
-
defaultHeaders: mergeHeaders({
|
|
621
|
-
accept: "application/json",
|
|
622
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
623
|
-
...(betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}),
|
|
624
|
-
}, model.headers, dynamicHeaders, optionsHeaders),
|
|
625
|
-
});
|
|
626
|
-
return { client, isOAuthToken: false };
|
|
627
|
-
}
|
|
628
|
-
// OAuth: Bearer auth, Claude Code identity headers
|
|
629
|
-
if (isOAuthToken(apiKey)) {
|
|
630
|
-
const client = new Anthropic({
|
|
631
|
-
apiKey: null,
|
|
632
|
-
authToken: apiKey,
|
|
633
|
-
baseURL: model.baseUrl,
|
|
634
|
-
dangerouslyAllowBrowser: true,
|
|
635
|
-
defaultHeaders: mergeHeaders({
|
|
636
|
-
accept: "application/json",
|
|
637
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
638
|
-
"anthropic-beta": ["claude-code-20250219", "oauth-2025-04-20", ...betaFeatures].join(","),
|
|
639
|
-
"user-agent": `claude-cli/${claudeCodeVersion}`,
|
|
640
|
-
"x-app": "cli",
|
|
641
|
-
}, model.headers, optionsHeaders),
|
|
642
|
-
});
|
|
643
|
-
return { client, isOAuthToken: true };
|
|
644
|
-
}
|
|
645
|
-
// API key auth
|
|
646
|
-
const client = new Anthropic({
|
|
647
|
-
apiKey,
|
|
648
|
-
baseURL: model.baseUrl,
|
|
649
|
-
dangerouslyAllowBrowser: true,
|
|
650
|
-
defaultHeaders: mergeHeaders({
|
|
651
|
-
accept: "application/json",
|
|
652
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
653
|
-
...(betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}),
|
|
654
|
-
}, model.headers, optionsHeaders),
|
|
655
|
-
});
|
|
656
|
-
return { client, isOAuthToken: false };
|
|
657
|
-
}
|
|
658
|
-
function buildParams(model, context, isOAuthToken, options) {
|
|
659
|
-
const { cacheControl } = getCacheControl(model, options?.cacheRetention);
|
|
660
|
-
const params = {
|
|
661
|
-
model: model.id,
|
|
662
|
-
messages: convertMessages(context.messages, model, isOAuthToken, cacheControl),
|
|
663
|
-
max_tokens: options?.maxTokens || (model.maxTokens / 3) | 0,
|
|
664
|
-
stream: true,
|
|
665
|
-
};
|
|
666
|
-
// For OAuth tokens, we MUST include Claude Code identity
|
|
667
|
-
if (isOAuthToken) {
|
|
668
|
-
params.system = [
|
|
669
|
-
{
|
|
670
|
-
type: "text",
|
|
671
|
-
text: "You are Claude Code, Anthropic's official CLI for Claude.",
|
|
672
|
-
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
673
|
-
},
|
|
674
|
-
];
|
|
675
|
-
if (context.systemPrompt) {
|
|
676
|
-
params.system.push({
|
|
677
|
-
type: "text",
|
|
678
|
-
text: sanitizeSurrogates(context.systemPrompt),
|
|
679
|
-
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
else if (context.systemPrompt) {
|
|
684
|
-
// Add cache control to system prompt for non-OAuth tokens
|
|
685
|
-
params.system = [
|
|
686
|
-
{
|
|
687
|
-
type: "text",
|
|
688
|
-
text: sanitizeSurrogates(context.systemPrompt),
|
|
689
|
-
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
690
|
-
},
|
|
691
|
-
];
|
|
692
|
-
}
|
|
693
|
-
// Temperature is incompatible with extended thinking (adaptive or budget-based).
|
|
694
|
-
if (options?.temperature !== undefined && !options?.thinkingEnabled) {
|
|
695
|
-
params.temperature = options.temperature;
|
|
696
|
-
}
|
|
697
|
-
if (context.tools && context.tools.length > 0) {
|
|
698
|
-
params.tools = convertTools(context.tools, isOAuthToken, getAnthropicCompat(model).supportsEagerToolInputStreaming, cacheControl);
|
|
699
|
-
}
|
|
700
|
-
// Configure thinking mode: adaptive (Opus 4.6+ and Sonnet 4.6),
|
|
701
|
-
// budget-based (older models), or explicitly disabled.
|
|
702
|
-
if (model.reasoning) {
|
|
703
|
-
if (options?.thinkingEnabled) {
|
|
704
|
-
// Default to "summarized" so Opus 4.7 and Mythos Preview behave like
|
|
705
|
-
// older Claude 4 models (whose API default is also "summarized").
|
|
706
|
-
const display = options.thinkingDisplay ?? "summarized";
|
|
707
|
-
if (supportsAdaptiveThinking(model.id)) {
|
|
708
|
-
// Adaptive thinking: Claude decides when and how much to think.
|
|
709
|
-
params.thinking = { type: "adaptive", display };
|
|
710
|
-
if (options.effort) {
|
|
711
|
-
// The Anthropic SDK types can lag newly supported effort values such as "xhigh".
|
|
712
|
-
params.output_config =
|
|
713
|
-
options.effort === "xhigh"
|
|
714
|
-
? { effort: options.effort }
|
|
715
|
-
: { effort: options.effort };
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
else {
|
|
719
|
-
// Budget-based thinking for older models
|
|
720
|
-
params.thinking = {
|
|
721
|
-
type: "enabled",
|
|
722
|
-
budget_tokens: options.thinkingBudgetTokens || 1024,
|
|
723
|
-
display,
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
else if (options?.thinkingEnabled === false) {
|
|
728
|
-
params.thinking = { type: "disabled" };
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
if (options?.metadata) {
|
|
732
|
-
const userId = options.metadata.user_id;
|
|
733
|
-
if (typeof userId === "string") {
|
|
734
|
-
params.metadata = { user_id: userId };
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (options?.toolChoice) {
|
|
738
|
-
if (typeof options.toolChoice === "string") {
|
|
739
|
-
params.tool_choice = { type: options.toolChoice };
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
params.tool_choice = options.toolChoice;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
return params;
|
|
746
|
-
}
|
|
747
|
-
// Normalize tool call IDs to match Anthropic's required pattern and length
|
|
748
|
-
function normalizeToolCallId(id) {
|
|
749
|
-
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
750
|
-
}
|
|
751
|
-
function convertMessages(messages, model, isOAuthToken, cacheControl) {
|
|
752
|
-
const params = [];
|
|
753
|
-
// Transform messages for cross-provider compatibility
|
|
754
|
-
const transformedMessages = transformMessages(messages, model, normalizeToolCallId);
|
|
755
|
-
for (let i = 0; i < transformedMessages.length; i++) {
|
|
756
|
-
const msg = transformedMessages[i];
|
|
757
|
-
if (msg.role === "user") {
|
|
758
|
-
if (typeof msg.content === "string") {
|
|
759
|
-
if (msg.content.trim().length > 0) {
|
|
760
|
-
params.push({
|
|
761
|
-
role: "user",
|
|
762
|
-
content: sanitizeSurrogates(msg.content),
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
else {
|
|
767
|
-
const blocks = msg.content.map((item) => {
|
|
768
|
-
if (item.type === "text") {
|
|
769
|
-
return {
|
|
770
|
-
type: "text",
|
|
771
|
-
text: sanitizeSurrogates(item.text),
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
return {
|
|
776
|
-
type: "image",
|
|
777
|
-
source: {
|
|
778
|
-
type: "base64",
|
|
779
|
-
media_type: item.mimeType,
|
|
780
|
-
data: item.data,
|
|
781
|
-
},
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
|
-
});
|
|
785
|
-
const filteredBlocks = blocks.filter((b) => {
|
|
786
|
-
if (b.type === "text") {
|
|
787
|
-
return b.text.trim().length > 0;
|
|
788
|
-
}
|
|
789
|
-
return true;
|
|
790
|
-
});
|
|
791
|
-
if (filteredBlocks.length === 0)
|
|
792
|
-
continue;
|
|
793
|
-
params.push({
|
|
794
|
-
role: "user",
|
|
795
|
-
content: filteredBlocks,
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
else if (msg.role === "assistant") {
|
|
800
|
-
const blocks = [];
|
|
801
|
-
for (const block of msg.content) {
|
|
802
|
-
if (block.type === "text") {
|
|
803
|
-
if (block.text.trim().length === 0)
|
|
804
|
-
continue;
|
|
805
|
-
blocks.push({
|
|
806
|
-
type: "text",
|
|
807
|
-
text: sanitizeSurrogates(block.text),
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
else if (block.type === "thinking") {
|
|
811
|
-
// Redacted thinking: pass the opaque payload back as redacted_thinking
|
|
812
|
-
if (block.redacted) {
|
|
813
|
-
blocks.push({
|
|
814
|
-
type: "redacted_thinking",
|
|
815
|
-
data: block.thinkingSignature,
|
|
816
|
-
});
|
|
817
|
-
continue;
|
|
818
|
-
}
|
|
819
|
-
if (block.thinking.trim().length === 0)
|
|
820
|
-
continue;
|
|
821
|
-
// If thinking signature is missing/empty (e.g., from aborted stream),
|
|
822
|
-
// convert to plain text block without <thinking> tags to avoid API rejection
|
|
823
|
-
// and prevent Claude from mimicking the tags in responses
|
|
824
|
-
if (!block.thinkingSignature || block.thinkingSignature.trim().length === 0) {
|
|
825
|
-
blocks.push({
|
|
826
|
-
type: "text",
|
|
827
|
-
text: sanitizeSurrogates(block.thinking),
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
else {
|
|
831
|
-
blocks.push({
|
|
832
|
-
type: "thinking",
|
|
833
|
-
thinking: sanitizeSurrogates(block.thinking),
|
|
834
|
-
signature: block.thinkingSignature,
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
else if (block.type === "toolCall") {
|
|
839
|
-
blocks.push({
|
|
840
|
-
type: "tool_use",
|
|
841
|
-
id: block.id,
|
|
842
|
-
name: isOAuthToken ? toClaudeCodeName(block.name) : block.name,
|
|
843
|
-
input: block.arguments ?? {},
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
if (blocks.length === 0)
|
|
848
|
-
continue;
|
|
849
|
-
params.push({
|
|
850
|
-
role: "assistant",
|
|
851
|
-
content: blocks,
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
else if (msg.role === "toolResult") {
|
|
855
|
-
// Collect all consecutive toolResult messages, needed for z.ai Anthropic endpoint
|
|
856
|
-
const toolResults = [];
|
|
857
|
-
// Add the current tool result
|
|
858
|
-
toolResults.push({
|
|
859
|
-
type: "tool_result",
|
|
860
|
-
tool_use_id: msg.toolCallId,
|
|
861
|
-
content: convertContentBlocks(msg.content),
|
|
862
|
-
is_error: msg.isError,
|
|
863
|
-
});
|
|
864
|
-
// Look ahead for consecutive toolResult messages
|
|
865
|
-
let j = i + 1;
|
|
866
|
-
while (j < transformedMessages.length && transformedMessages[j].role === "toolResult") {
|
|
867
|
-
const nextMsg = transformedMessages[j]; // We know it's a toolResult
|
|
868
|
-
toolResults.push({
|
|
869
|
-
type: "tool_result",
|
|
870
|
-
tool_use_id: nextMsg.toolCallId,
|
|
871
|
-
content: convertContentBlocks(nextMsg.content),
|
|
872
|
-
is_error: nextMsg.isError,
|
|
873
|
-
});
|
|
874
|
-
j++;
|
|
875
|
-
}
|
|
876
|
-
// Skip the messages we've already processed
|
|
877
|
-
i = j - 1;
|
|
878
|
-
// Add a single user message with all tool results
|
|
879
|
-
params.push({
|
|
880
|
-
role: "user",
|
|
881
|
-
content: toolResults,
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
// Add cache_control to the last user message to cache conversation history
|
|
886
|
-
if (cacheControl && params.length > 0) {
|
|
887
|
-
const lastMessage = params[params.length - 1];
|
|
888
|
-
if (lastMessage.role === "user") {
|
|
889
|
-
if (Array.isArray(lastMessage.content)) {
|
|
890
|
-
const lastBlock = lastMessage.content[lastMessage.content.length - 1];
|
|
891
|
-
if (lastBlock &&
|
|
892
|
-
(lastBlock.type === "text" || lastBlock.type === "image" || lastBlock.type === "tool_result")) {
|
|
893
|
-
lastBlock.cache_control = cacheControl;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
else if (typeof lastMessage.content === "string") {
|
|
897
|
-
lastMessage.content = [
|
|
898
|
-
{
|
|
899
|
-
type: "text",
|
|
900
|
-
text: lastMessage.content,
|
|
901
|
-
cache_control: cacheControl,
|
|
902
|
-
},
|
|
903
|
-
];
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
return params;
|
|
908
|
-
}
|
|
909
|
-
function shouldUseFineGrainedToolStreamingBeta(model, context) {
|
|
910
|
-
return !!context.tools?.length && !getAnthropicCompat(model).supportsEagerToolInputStreaming;
|
|
911
|
-
}
|
|
912
|
-
function convertTools(tools, isOAuthToken, supportsEagerToolInputStreaming, cacheControl) {
|
|
913
|
-
if (!tools)
|
|
914
|
-
return [];
|
|
915
|
-
return tools.map((tool, index) => {
|
|
916
|
-
const schema = tool.parameters;
|
|
917
|
-
return {
|
|
918
|
-
name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name,
|
|
919
|
-
description: tool.description,
|
|
920
|
-
...(supportsEagerToolInputStreaming ? { eager_input_streaming: true } : {}),
|
|
921
|
-
input_schema: {
|
|
922
|
-
type: "object",
|
|
923
|
-
properties: schema.properties ?? {},
|
|
924
|
-
required: schema.required ?? [],
|
|
925
|
-
},
|
|
926
|
-
...(cacheControl && index === tools.length - 1 ? { cache_control: cacheControl } : {}),
|
|
927
|
-
};
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
function mapStopReason(reason) {
|
|
931
|
-
switch (reason) {
|
|
932
|
-
case "end_turn":
|
|
933
|
-
return "stop";
|
|
934
|
-
case "max_tokens":
|
|
935
|
-
return "length";
|
|
936
|
-
case "tool_use":
|
|
937
|
-
return "toolUse";
|
|
938
|
-
case "refusal":
|
|
939
|
-
return "error";
|
|
940
|
-
case "pause_turn": // Stop is good enough -> resubmit
|
|
941
|
-
return "stop";
|
|
942
|
-
case "stop_sequence":
|
|
943
|
-
return "stop"; // We don't supply stop sequences, so this should never happen
|
|
944
|
-
case "sensitive": // Content flagged by safety filters (not yet in SDK types)
|
|
945
|
-
return "error";
|
|
946
|
-
default:
|
|
947
|
-
// Handle unknown stop reasons gracefully (API may add new values)
|
|
948
|
-
throw new Error(`Unhandled stop reason: ${reason}`);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
//# sourceMappingURL=anthropic.js.map
|