@diffra-ai/ai 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +2010 -2
- package/dist/api/anthropic-messages.d.ts +71 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -0
- package/dist/api/anthropic-messages.js +1549 -0
- package/dist/api/anthropic-messages.js.map +1 -0
- package/dist/api/anthropic-messages.lazy.d.ts +3 -0
- package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
- package/dist/api/anthropic-messages.lazy.js +3 -0
- package/dist/api/anthropic-messages.lazy.js.map +1 -0
- package/dist/api/azure-openai-config.d.ts +15 -0
- package/dist/api/azure-openai-config.d.ts.map +1 -0
- package/dist/api/azure-openai-config.js +76 -0
- package/dist/api/azure-openai-config.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts +14 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.js +192 -0
- package/dist/api/azure-openai-responses.js.map +1 -0
- package/dist/api/azure-openai-responses.lazy.d.ts +3 -0
- package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.lazy.js +3 -0
- package/dist/api/azure-openai-responses.lazy.js.map +1 -0
- package/dist/api/bedrock-converse-stream.d.ts +38 -0
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.js +1189 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +16 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +43 -0
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
- package/dist/api/classifier-shared.d.ts +23 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +104 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-ai-binding.d.ts +77 -0
- package/dist/api/cloudflare-ai-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-ai-binding.js +72 -0
- package/dist/api/cloudflare-ai-binding.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.js +57 -0
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts +3 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js.map +1 -0
- package/dist/api/cloudflare.d.ts +11 -0
- package/dist/api/cloudflare.d.ts.map +1 -0
- package/dist/api/cloudflare.js +11 -0
- package/dist/api/cloudflare.js.map +1 -0
- package/dist/api/constrained-sampling.d.ts +38 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +257 -0
- package/dist/api/constrained-sampling.js.map +1 -0
- package/dist/api/github-copilot-headers.d.ts +8 -0
- package/dist/api/github-copilot-headers.d.ts.map +1 -0
- package/dist/api/github-copilot-headers.js +29 -0
- package/dist/api/github-copilot-headers.js.map +1 -0
- package/dist/api/google-generative-ai.d.ts +13 -0
- package/dist/api/google-generative-ai.d.ts.map +1 -0
- package/dist/api/google-generative-ai.js +363 -0
- package/dist/api/google-generative-ai.js.map +1 -0
- package/dist/api/google-generative-ai.lazy.d.ts +3 -0
- package/dist/api/google-generative-ai.lazy.d.ts.map +1 -0
- package/dist/api/google-generative-ai.lazy.js +3 -0
- package/dist/api/google-generative-ai.lazy.js.map +1 -0
- package/dist/api/google-shared.d.ts +93 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +501 -0
- package/dist/api/google-shared.js.map +1 -0
- package/dist/api/google-vertex.d.ts +15 -0
- package/dist/api/google-vertex.d.ts.map +1 -0
- package/dist/api/google-vertex.js +427 -0
- package/dist/api/google-vertex.js.map +1 -0
- package/dist/api/google-vertex.lazy.d.ts +3 -0
- package/dist/api/google-vertex.lazy.d.ts.map +1 -0
- package/dist/api/google-vertex.lazy.js +3 -0
- package/dist/api/google-vertex.lazy.js.map +1 -0
- package/dist/api/lazy.d.ts +24 -0
- package/dist/api/lazy.d.ts.map +1 -0
- package/dist/api/lazy.js +91 -0
- package/dist/api/lazy.js.map +1 -0
- package/dist/api/llama-cpp-classify.d.ts +33 -0
- package/dist/api/llama-cpp-classify.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.js +368 -0
- package/dist/api/llama-cpp-classify.js.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts +3 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.js +4 -0
- package/dist/api/llama-cpp-classify.lazy.js.map +1 -0
- package/dist/api/mistral-conversations.d.ts +25 -0
- package/dist/api/mistral-conversations.d.ts.map +1 -0
- package/dist/api/mistral-conversations.js +740 -0
- package/dist/api/mistral-conversations.js.map +1 -0
- package/dist/api/mistral-conversations.lazy.d.ts +3 -0
- package/dist/api/mistral-conversations.lazy.d.ts.map +1 -0
- package/dist/api/mistral-conversations.lazy.js +3 -0
- package/dist/api/mistral-conversations.lazy.js.map +1 -0
- package/dist/api/openai-codex-responses.d.ts +31 -0
- package/dist/api/openai-codex-responses.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.js +1346 -0
- package/dist/api/openai-codex-responses.js.map +1 -0
- package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
- package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.lazy.js +3 -0
- package/dist/api/openai-codex-responses.lazy.js.map +1 -0
- package/dist/api/openai-completions.d.ts +27 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1351 -0
- package/dist/api/openai-completions.js.map +1 -0
- package/dist/api/openai-completions.lazy.d.ts +3 -0
- package/dist/api/openai-completions.lazy.d.ts.map +1 -0
- package/dist/api/openai-completions.lazy.js +3 -0
- package/dist/api/openai-completions.lazy.js.map +1 -0
- package/dist/api/openai-decisions.d.ts +4 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +162 -0
- package/dist/api/openai-decisions.js.map +1 -0
- package/dist/api/openai-decisions.lazy.d.ts +3 -0
- package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
- package/dist/api/openai-decisions.lazy.js +4 -0
- package/dist/api/openai-decisions.lazy.js.map +1 -0
- package/dist/api/openai-prompt-cache.d.ts +3 -0
- package/dist/api/openai-prompt-cache.d.ts.map +1 -0
- package/dist/api/openai-prompt-cache.js +10 -0
- package/dist/api/openai-prompt-cache.js.map +1 -0
- package/dist/api/openai-responses-shared.d.ts +54 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +796 -0
- package/dist/api/openai-responses-shared.js.map +1 -0
- package/dist/api/openai-responses.d.ts +14 -0
- package/dist/api/openai-responses.d.ts.map +1 -0
- package/dist/api/openai-responses.js +335 -0
- package/dist/api/openai-responses.js.map +1 -0
- package/dist/api/openai-responses.lazy.d.ts +3 -0
- package/dist/api/openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-responses.lazy.js +3 -0
- package/dist/api/openai-responses.lazy.js.map +1 -0
- package/dist/api/openrouter-images.d.ts +4 -0
- package/dist/api/openrouter-images.d.ts.map +1 -0
- package/dist/api/openrouter-images.js +135 -0
- package/dist/api/openrouter-images.js.map +1 -0
- package/dist/api/openrouter-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-images.lazy.js +4 -0
- package/dist/api/openrouter-images.lazy.js.map +1 -0
- package/dist/api/pi-messages.d.ts +101 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +329 -0
- package/dist/api/pi-messages.js.map +1 -0
- package/dist/api/pi-messages.lazy.d.ts +3 -0
- package/dist/api/pi-messages.lazy.d.ts.map +1 -0
- package/dist/api/pi-messages.lazy.js +3 -0
- package/dist/api/pi-messages.lazy.js.map +1 -0
- package/dist/api/simple-options.d.ts +17 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +88 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/strict-tool-limits.d.ts +13 -0
- package/dist/api/strict-tool-limits.d.ts.map +1 -0
- package/dist/api/strict-tool-limits.js +50 -0
- package/dist/api/strict-tool-limits.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +49 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +151 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +23 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +214 -0
- package/dist/api/transform-messages.js.map +1 -0
- package/dist/api/typesafe-system-one.d.ts +4 -0
- package/dist/api/typesafe-system-one.d.ts.map +1 -0
- package/dist/api/typesafe-system-one.js +30 -0
- package/dist/api/typesafe-system-one.js.map +1 -0
- package/dist/api/typesafe-system-one.lazy.d.ts +3 -0
- package/dist/api/typesafe-system-one.lazy.d.ts.map +1 -0
- package/dist/api/typesafe-system-one.lazy.js +4 -0
- package/dist/api/typesafe-system-one.lazy.js.map +1 -0
- package/dist/auth/context.d.ts +7 -0
- package/dist/auth/context.d.ts.map +1 -0
- package/dist/auth/context.js +42 -0
- package/dist/auth/context.js.map +1 -0
- package/dist/auth/credential-store.d.ts +17 -0
- package/dist/auth/credential-store.d.ts.map +1 -0
- package/dist/auth/credential-store.js +51 -0
- package/dist/auth/credential-store.js.map +1 -0
- package/dist/auth/helpers.d.ts +22 -0
- package/dist/auth/helpers.d.ts.map +1 -0
- package/dist/auth/helpers.js +53 -0
- package/dist/auth/helpers.js.map +1 -0
- package/dist/auth/oauth/anthropic.d.ts +9 -0
- package/dist/auth/oauth/anthropic.d.ts.map +1 -0
- package/dist/auth/oauth/anthropic.js +257 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/callback-server.d.ts +55 -0
- package/dist/auth/oauth/callback-server.d.ts.map +1 -0
- package/dist/auth/oauth/callback-server.js +146 -0
- package/dist/auth/oauth/callback-server.js.map +1 -0
- package/dist/auth/oauth/device-code.d.ts +24 -0
- package/dist/auth/oauth/device-code.d.ts.map +1 -0
- package/dist/auth/oauth/device-code.js +69 -0
- package/dist/auth/oauth/device-code.js.map +1 -0
- package/dist/auth/oauth/github-copilot.d.ts +6 -0
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -0
- package/dist/auth/oauth/github-copilot.js +385 -0
- package/dist/auth/oauth/github-copilot.js.map +1 -0
- package/dist/auth/oauth/kimi-coding.d.ts +10 -0
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -0
- package/dist/auth/oauth/kimi-coding.js +230 -0
- package/dist/auth/oauth/kimi-coding.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +31 -0
- package/dist/auth/oauth/load.d.ts.map +1 -0
- package/dist/auth/oauth/load.js +72 -0
- package/dist/auth/oauth/load.js.map +1 -0
- package/dist/auth/oauth/meta.d.ts +17 -0
- package/dist/auth/oauth/meta.d.ts.map +1 -0
- package/dist/auth/oauth/meta.js +177 -0
- package/dist/auth/oauth/meta.js.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.js +263 -0
- package/dist/auth/oauth/openai-chatgpt.js.map +1 -0
- package/dist/auth/oauth/openai-codex.d.ts +9 -0
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -0
- package/dist/auth/oauth/openai-codex.js +346 -0
- package/dist/auth/oauth/openai-codex.js.map +1 -0
- package/dist/auth/oauth/openrouter.d.ts +15 -0
- package/dist/auth/oauth/openrouter.d.ts.map +1 -0
- package/dist/auth/oauth/openrouter.js +158 -0
- package/dist/auth/oauth/openrouter.js.map +1 -0
- package/dist/auth/oauth/pkce.d.ts +13 -0
- package/dist/auth/oauth/pkce.d.ts.map +1 -0
- package/dist/auth/oauth/pkce.js +31 -0
- package/dist/auth/oauth/pkce.js.map +1 -0
- package/dist/auth/oauth/radius.d.ts +17 -0
- package/dist/auth/oauth/radius.d.ts.map +1 -0
- package/dist/auth/oauth/radius.js +259 -0
- package/dist/auth/oauth/radius.js.map +1 -0
- package/dist/auth/oauth/trusted-url.d.ts +7 -0
- package/dist/auth/oauth/trusted-url.d.ts.map +1 -0
- package/dist/auth/oauth/trusted-url.js +12 -0
- package/dist/auth/oauth/trusted-url.js.map +1 -0
- package/dist/auth/oauth/xai.d.ts +6 -0
- package/dist/auth/oauth/xai.d.ts.map +1 -0
- package/dist/auth/oauth/xai.js +190 -0
- package/dist/auth/oauth/xai.js.map +1 -0
- package/dist/auth/resolve.d.ts +36 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +140 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +249 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/bedrock-provider.d.ts +5 -0
- package/dist/bedrock-provider.d.ts.map +1 -0
- package/dist/bedrock-provider.js +6 -0
- package/dist/bedrock-provider.js.map +1 -0
- package/dist/bun-oauth.d.ts +3 -0
- package/dist/bun-oauth.d.ts.map +1 -0
- package/dist/bun-oauth.js +25 -0
- package/dist/bun-oauth.js.map +1 -0
- package/dist/cache-warming.d.ts +53 -0
- package/dist/cache-warming.d.ts.map +1 -0
- package/dist/cache-warming.js +82 -0
- package/dist/cache-warming.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +119 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +43 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -0
- package/dist/compat/extension-oauth-types.js +2 -0
- package/dist/compat/extension-oauth-types.js.map +1 -0
- package/dist/compat.d.ts +67 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +202 -0
- package/dist/compat.js.map +1 -0
- package/dist/env-api-keys.d.ts +26 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +165 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/image-models.d.ts +21 -0
- package/dist/image-models.d.ts.map +1 -0
- package/dist/image-models.js +24 -0
- package/dist/image-models.js.map +1 -0
- package/dist/images-api-registry.d.ts +14 -0
- package/dist/images-api-registry.d.ts.map +1 -0
- package/dist/images-api-registry.js +22 -0
- package/dist/images-api-registry.js.map +1 -0
- package/dist/images.d.ts +9 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +19 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy-bedrock-provider.d.ts +10 -0
- package/dist/lazy-bedrock-provider.d.ts.map +1 -0
- package/dist/lazy-bedrock-provider.js +13 -0
- package/dist/lazy-bedrock-provider.js.map +1 -0
- package/dist/lazy-oauth.d.ts +10 -0
- package/dist/lazy-oauth.d.ts.map +1 -0
- package/dist/lazy-oauth.js +23 -0
- package/dist/lazy-oauth.js.map +1 -0
- package/dist/legacy-api-aliases.d.ts +42 -0
- package/dist/legacy-api-aliases.d.ts.map +1 -0
- package/dist/legacy-api-aliases.js +49 -0
- package/dist/legacy-api-aliases.js.map +1 -0
- package/dist/model-catalog.d.ts +33 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +16 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/models-store.d.ts +30 -0
- package/dist/models-store.d.ts.map +1 -0
- package/dist/models-store.js +17 -0
- package/dist/models-store.js.map +1 -0
- package/dist/models.d.ts +285 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +179 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +181 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +753 -0
- package/dist/models.js.map +1 -0
- package/dist/oauth.d.ts +3 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +2 -0
- package/dist/oauth.js.map +1 -0
- package/dist/providers/all.d.ts +34 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +139 -0
- package/dist/providers/all.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +3 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +93 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/amazon-bedrock.models.d.ts +6 -0
- package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.models.js +8 -0
- package/dist/providers/amazon-bedrock.models.js.map +1 -0
- package/dist/providers/ant-ling.d.ts +3 -0
- package/dist/providers/ant-ling.d.ts.map +1 -0
- package/dist/providers/ant-ling.js +15 -0
- package/dist/providers/ant-ling.js.map +1 -0
- package/dist/providers/ant-ling.models.d.ts +6 -0
- package/dist/providers/ant-ling.models.d.ts.map +1 -0
- package/dist/providers/ant-ling.models.js +8 -0
- package/dist/providers/ant-ling.models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +3 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +78 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.models.d.ts +6 -0
- package/dist/providers/anthropic.models.d.ts.map +1 -0
- package/dist/providers/anthropic.models.js +8 -0
- package/dist/providers/anthropic.models.js.map +1 -0
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.d.ts.map +1 -0
- package/dist/providers/azure.js +46 -0
- package/dist/providers/azure.js.map +1 -0
- package/dist/providers/azure.models.d.ts +6 -0
- package/dist/providers/azure.models.d.ts.map +1 -0
- package/dist/providers/azure.models.js +8 -0
- package/dist/providers/azure.models.js.map +1 -0
- package/dist/providers/baseten.d.ts +3 -0
- package/dist/providers/baseten.d.ts.map +1 -0
- package/dist/providers/baseten.js +15 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +6 -0
- package/dist/providers/baseten.models.d.ts.map +1 -0
- package/dist/providers/baseten.models.js +8 -0
- package/dist/providers/baseten.models.js.map +1 -0
- package/dist/providers/cerebras.d.ts +3 -0
- package/dist/providers/cerebras.d.ts.map +1 -0
- package/dist/providers/cerebras.js +15 -0
- package/dist/providers/cerebras.js.map +1 -0
- package/dist/providers/cerebras.models.d.ts +6 -0
- package/dist/providers/cerebras.models.d.ts.map +1 -0
- package/dist/providers/cerebras.models.js +8 -0
- package/dist/providers/cerebras.models.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +5 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.js +25 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +6 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.js +8 -0
- package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
- package/dist/providers/cloudflare-auth.d.ts +4 -0
- package/dist/providers/cloudflare-auth.d.ts.map +1 -0
- package/dist/providers/cloudflare-auth.js +86 -0
- package/dist/providers/cloudflare-auth.js.map +1 -0
- package/dist/providers/cloudflare-stream.d.ts +12 -0
- package/dist/providers/cloudflare-stream.d.ts.map +1 -0
- package/dist/providers/cloudflare-stream.js +27 -0
- package/dist/providers/cloudflare-stream.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
- package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.js +22 -0
- package/dist/providers/cloudflare-workers-ai.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts +6 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.js +8 -0
- package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
- package/dist/providers/compat-schema.d.ts +511 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +466 -0
- package/dist/providers/compat-schema.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -0
- package/dist/providers/data/amazon-bedrock.json +1 -0
- package/dist/providers/data/ant-ling.json +1 -0
- package/dist/providers/data/anthropic.json +1 -0
- package/dist/providers/data/azure.json +1 -0
- package/dist/providers/data/baseten.json +1 -0
- package/dist/providers/data/cerebras.json +1 -0
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
- package/dist/providers/data/cloudflare-workers-ai.json +1 -0
- package/dist/providers/data/deepseek.json +1 -0
- package/dist/providers/data/fireworks.json +1 -0
- package/dist/providers/data/github-copilot.json +1 -0
- package/dist/providers/data/google-vertex.json +1 -0
- package/dist/providers/data/google.json +1 -0
- package/dist/providers/data/groq.json +1 -0
- package/dist/providers/data/huggingface.json +1 -0
- package/dist/providers/data/kimi-coding.json +1 -0
- package/dist/providers/data/meta.json +1 -0
- package/dist/providers/data/minimax-cn.json +1 -0
- package/dist/providers/data/minimax.json +1 -0
- package/dist/providers/data/mistral.json +1 -0
- package/dist/providers/data/moonshotai-cn.json +1 -0
- package/dist/providers/data/moonshotai.json +1 -0
- package/dist/providers/data/nvidia.json +1 -0
- package/dist/providers/data/openai-codex.json +1 -0
- package/dist/providers/data/openai.json +1 -0
- package/dist/providers/data/opencode-go.json +1 -0
- package/dist/providers/data/opencode.json +1 -0
- package/dist/providers/data/openrouter.json +1 -0
- package/dist/providers/data/qwen-token-plan-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -0
- package/dist/providers/data/radius.json +1 -0
- package/dist/providers/data/together.json +1 -0
- package/dist/providers/data/typesafe.json +1 -0
- package/dist/providers/data/vercel-ai-gateway.json +1 -0
- package/dist/providers/data/xai.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
- package/dist/providers/data/xiaomi.json +1 -0
- package/dist/providers/data/zai-coding-cn.json +1 -0
- package/dist/providers/data/zai.json +1 -0
- package/dist/providers/deepseek.d.ts +3 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +15 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/deepseek.models.d.ts +6 -0
- package/dist/providers/deepseek.models.d.ts.map +1 -0
- package/dist/providers/deepseek.models.js +8 -0
- package/dist/providers/deepseek.models.js.map +1 -0
- package/dist/providers/faux.d.ts +103 -0
- package/dist/providers/faux.d.ts.map +1 -0
- package/dist/providers/faux.js +511 -0
- package/dist/providers/faux.js.map +1 -0
- package/dist/providers/fireworks.d.ts +3 -0
- package/dist/providers/fireworks.d.ts.map +1 -0
- package/dist/providers/fireworks.js +19 -0
- package/dist/providers/fireworks.js.map +1 -0
- package/dist/providers/fireworks.models.d.ts +6 -0
- package/dist/providers/fireworks.models.d.ts.map +1 -0
- package/dist/providers/fireworks.models.js +8 -0
- package/dist/providers/fireworks.models.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +5 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +46 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +6 -0
- package/dist/providers/github-copilot.models.d.ts.map +1 -0
- package/dist/providers/github-copilot.models.js +8 -0
- package/dist/providers/github-copilot.models.js.map +1 -0
- package/dist/providers/google-vertex.d.ts +3 -0
- package/dist/providers/google-vertex.d.ts.map +1 -0
- package/dist/providers/google-vertex.js +94 -0
- package/dist/providers/google-vertex.js.map +1 -0
- package/dist/providers/google-vertex.models.d.ts +6 -0
- package/dist/providers/google-vertex.models.d.ts.map +1 -0
- package/dist/providers/google-vertex.models.js +8 -0
- package/dist/providers/google-vertex.models.js.map +1 -0
- package/dist/providers/google.d.ts +3 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +15 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/google.models.d.ts +6 -0
- package/dist/providers/google.models.d.ts.map +1 -0
- package/dist/providers/google.models.js +8 -0
- package/dist/providers/google.models.js.map +1 -0
- package/dist/providers/groq.d.ts +3 -0
- package/dist/providers/groq.d.ts.map +1 -0
- package/dist/providers/groq.js +15 -0
- package/dist/providers/groq.js.map +1 -0
- package/dist/providers/groq.models.d.ts +6 -0
- package/dist/providers/groq.models.d.ts.map +1 -0
- package/dist/providers/groq.models.js +8 -0
- package/dist/providers/groq.models.js.map +1 -0
- package/dist/providers/huggingface.d.ts +3 -0
- package/dist/providers/huggingface.d.ts.map +1 -0
- package/dist/providers/huggingface.js +15 -0
- package/dist/providers/huggingface.js.map +1 -0
- package/dist/providers/huggingface.models.d.ts +6 -0
- package/dist/providers/huggingface.models.d.ts.map +1 -0
- package/dist/providers/huggingface.models.js +8 -0
- package/dist/providers/huggingface.models.js.map +1 -0
- package/dist/providers/images/register-builtins.d.ts +4 -0
- package/dist/providers/images/register-builtins.d.ts.map +1 -0
- package/dist/providers/images/register-builtins.js +34 -0
- package/dist/providers/images/register-builtins.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +3 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +24 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/kimi-coding.models.d.ts +6 -0
- package/dist/providers/kimi-coding.models.d.ts.map +1 -0
- package/dist/providers/kimi-coding.models.js +8 -0
- package/dist/providers/kimi-coding.models.js.map +1 -0
- package/dist/providers/meta.d.ts +3 -0
- package/dist/providers/meta.d.ts.map +1 -0
- package/dist/providers/meta.js +24 -0
- package/dist/providers/meta.js.map +1 -0
- package/dist/providers/meta.models.d.ts +6 -0
- package/dist/providers/meta.models.d.ts.map +1 -0
- package/dist/providers/meta.models.js +8 -0
- package/dist/providers/meta.models.js.map +1 -0
- package/dist/providers/minimax-cn.d.ts +3 -0
- package/dist/providers/minimax-cn.d.ts.map +1 -0
- package/dist/providers/minimax-cn.js +15 -0
- package/dist/providers/minimax-cn.js.map +1 -0
- package/dist/providers/minimax-cn.models.d.ts +6 -0
- package/dist/providers/minimax-cn.models.d.ts.map +1 -0
- package/dist/providers/minimax-cn.models.js +8 -0
- package/dist/providers/minimax-cn.models.js.map +1 -0
- package/dist/providers/minimax.d.ts +3 -0
- package/dist/providers/minimax.d.ts.map +1 -0
- package/dist/providers/minimax.js +15 -0
- package/dist/providers/minimax.js.map +1 -0
- package/dist/providers/minimax.models.d.ts +6 -0
- package/dist/providers/minimax.models.d.ts.map +1 -0
- package/dist/providers/minimax.models.js +8 -0
- package/dist/providers/minimax.models.js.map +1 -0
- package/dist/providers/mistral.d.ts +3 -0
- package/dist/providers/mistral.d.ts.map +1 -0
- package/dist/providers/mistral.js +15 -0
- package/dist/providers/mistral.js.map +1 -0
- package/dist/providers/mistral.models.d.ts +6 -0
- package/dist/providers/mistral.models.d.ts.map +1 -0
- package/dist/providers/mistral.models.js +8 -0
- package/dist/providers/mistral.models.js.map +1 -0
- package/dist/providers/model-schema.d.ts +91 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +68 -0
- package/dist/providers/model-schema.js.map +1 -0
- package/dist/providers/moonshotai-cn.d.ts +3 -0
- package/dist/providers/moonshotai-cn.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.js +15 -0
- package/dist/providers/moonshotai-cn.js.map +1 -0
- package/dist/providers/moonshotai-cn.models.d.ts +6 -0
- package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.models.js +8 -0
- package/dist/providers/moonshotai-cn.models.js.map +1 -0
- package/dist/providers/moonshotai.d.ts +3 -0
- package/dist/providers/moonshotai.d.ts.map +1 -0
- package/dist/providers/moonshotai.js +15 -0
- package/dist/providers/moonshotai.js.map +1 -0
- package/dist/providers/moonshotai.models.d.ts +6 -0
- package/dist/providers/moonshotai.models.d.ts.map +1 -0
- package/dist/providers/moonshotai.models.js +8 -0
- package/dist/providers/moonshotai.models.js.map +1 -0
- package/dist/providers/nvidia.d.ts +3 -0
- package/dist/providers/nvidia.d.ts.map +1 -0
- package/dist/providers/nvidia.js +15 -0
- package/dist/providers/nvidia.js.map +1 -0
- package/dist/providers/nvidia.models.d.ts +6 -0
- package/dist/providers/nvidia.models.d.ts.map +1 -0
- package/dist/providers/nvidia.models.js +8 -0
- package/dist/providers/nvidia.models.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +3 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +22 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/openai-codex.models.d.ts +6 -0
- package/dist/providers/openai-codex.models.d.ts.map +1 -0
- package/dist/providers/openai-codex.models.js +8 -0
- package/dist/providers/openai-codex.models.js.map +1 -0
- package/dist/providers/openai.d.ts +3 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +33 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.models.d.ts +6 -0
- package/dist/providers/openai.models.d.ts.map +1 -0
- package/dist/providers/openai.models.js +8 -0
- package/dist/providers/openai.models.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +5 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +23 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-go.models.d.ts +6 -0
- package/dist/providers/opencode-go.models.d.ts.map +1 -0
- package/dist/providers/opencode-go.models.js +8 -0
- package/dist/providers/opencode-go.models.js.map +1 -0
- package/dist/providers/opencode-headers.d.ts +4 -0
- package/dist/providers/opencode-headers.d.ts.map +1 -0
- package/dist/providers/opencode-headers.js +22 -0
- package/dist/providers/opencode-headers.js.map +1 -0
- package/dist/providers/opencode.d.ts +5 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +26 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/providers/opencode.models.d.ts +6 -0
- package/dist/providers/opencode.models.d.ts.map +1 -0
- package/dist/providers/opencode.models.js +8 -0
- package/dist/providers/opencode.models.js.map +1 -0
- package/dist/providers/openrouter-api.d.ts +40 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +41 -0
- package/dist/providers/openrouter-api.js.map +1 -0
- package/dist/providers/openrouter.d.ts +13 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +87 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/openrouter.models.d.ts +6 -0
- package/dist/providers/openrouter.models.d.ts.map +1 -0
- package/dist/providers/openrouter.models.js +8 -0
- package/dist/providers/openrouter.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.js +20 -0
- package/dist/providers/qwen-token-plan-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.js +20 -0
- package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +20 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
- package/dist/providers/qwen-token-plan.d.ts +3 -0
- package/dist/providers/qwen-token-plan.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.js +20 -0
- package/dist/providers/qwen-token-plan.js.map +1 -0
- package/dist/providers/qwen-token-plan.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.models.js +8 -0
- package/dist/providers/qwen-token-plan.models.js.map +1 -0
- package/dist/providers/radius-config.d.ts +26 -0
- package/dist/providers/radius-config.d.ts.map +1 -0
- package/dist/providers/radius-config.js +64 -0
- package/dist/providers/radius-config.js.map +1 -0
- package/dist/providers/radius.d.ts +9 -0
- package/dist/providers/radius.d.ts.map +1 -0
- package/dist/providers/radius.js +70 -0
- package/dist/providers/radius.js.map +1 -0
- package/dist/providers/radius.models.d.ts +6 -0
- package/dist/providers/radius.models.d.ts.map +1 -0
- package/dist/providers/radius.models.js +8 -0
- package/dist/providers/radius.models.js.map +1 -0
- package/dist/providers/schema-builders.d.ts +10 -0
- package/dist/providers/schema-builders.d.ts.map +1 -0
- package/dist/providers/schema-builders.js +18 -0
- package/dist/providers/schema-builders.js.map +1 -0
- package/dist/providers/together.d.ts +3 -0
- package/dist/providers/together.d.ts.map +1 -0
- package/dist/providers/together.js +15 -0
- package/dist/providers/together.js.map +1 -0
- package/dist/providers/together.models.d.ts +6 -0
- package/dist/providers/together.models.d.ts.map +1 -0
- package/dist/providers/together.models.js +8 -0
- package/dist/providers/together.models.js.map +1 -0
- package/dist/providers/typesafe.d.ts +3 -0
- package/dist/providers/typesafe.d.ts.map +1 -0
- package/dist/providers/typesafe.js +18 -0
- package/dist/providers/typesafe.js.map +1 -0
- package/dist/providers/typesafe.models.d.ts +6 -0
- package/dist/providers/typesafe.models.d.ts.map +1 -0
- package/dist/providers/typesafe.models.js +8 -0
- package/dist/providers/typesafe.models.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +3 -0
- package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.js +18 -0
- package/dist/providers/vercel-ai-gateway.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts +6 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.js +8 -0
- package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
- package/dist/providers/xai.d.ts +3 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +24 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/providers/xai.models.d.ts +6 -0
- package/dist/providers/xai.models.d.ts.map +1 -0
- package/dist/providers/xai.models.js +8 -0
- package/dist/providers/xai.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.js +15 -0
- package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts +6 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js +8 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.js +15 -0
- package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts +6 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js +8 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
- package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +6 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js +8 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
- package/dist/providers/xiaomi.d.ts +3 -0
- package/dist/providers/xiaomi.d.ts.map +1 -0
- package/dist/providers/xiaomi.js +15 -0
- package/dist/providers/xiaomi.js.map +1 -0
- package/dist/providers/xiaomi.models.d.ts +6 -0
- package/dist/providers/xiaomi.models.d.ts.map +1 -0
- package/dist/providers/xiaomi.models.js +8 -0
- package/dist/providers/xiaomi.models.js.map +1 -0
- package/dist/providers/zai-coding-cn.d.ts +3 -0
- package/dist/providers/zai-coding-cn.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.js +15 -0
- package/dist/providers/zai-coding-cn.js.map +1 -0
- package/dist/providers/zai-coding-cn.models.d.ts +6 -0
- package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.models.js +8 -0
- package/dist/providers/zai-coding-cn.models.js.map +1 -0
- package/dist/providers/zai.d.ts +3 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +15 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/providers/zai.models.d.ts +6 -0
- package/dist/providers/zai.models.d.ts.map +1 -0
- package/dist/providers/zai.models.js +8 -0
- package/dist/providers/zai.models.js.map +1 -0
- package/dist/session-resources.d.ts +4 -0
- package/dist/session-resources.d.ts.map +1 -0
- package/dist/session-resources.js +22 -0
- package/dist/session-resources.js.map +1 -0
- package/dist/telemetry.d.ts +288 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +192 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types.d.ts +707 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/abort-signals.d.ts +6 -0
- package/dist/utils/abort-signals.d.ts.map +1 -0
- package/dist/utils/abort-signals.js +34 -0
- package/dist/utils/abort-signals.js.map +1 -0
- package/dist/utils/abort.d.ts +8 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +49 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/diagnostics.d.ts +20 -0
- package/dist/utils/diagnostics.d.ts.map +1 -0
- package/dist/utils/diagnostics.js +25 -0
- package/dist/utils/diagnostics.js.map +1 -0
- package/dist/utils/error-body.d.ts +33 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +161 -0
- package/dist/utils/error-body.js.map +1 -0
- package/dist/utils/estimate.d.ts +17 -0
- package/dist/utils/estimate.d.ts.map +1 -0
- package/dist/utils/estimate.js +95 -0
- package/dist/utils/estimate.js.map +1 -0
- package/dist/utils/event-stream.d.ts +30 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +124 -0
- package/dist/utils/event-stream.js.map +1 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.d.ts +4 -0
- package/dist/utils/headers.d.ts.map +1 -0
- package/dist/utils/headers.js +20 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/identity.d.ts +65 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +141 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/json-parse.d.ts +26 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +138 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +13 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +53 -0
- package/dist/utils/model-operations.js.map +1 -0
- package/dist/utils/models-error.d.ts +8 -0
- package/dist/utils/models-error.d.ts.map +1 -0
- package/dist/utils/models-error.js +19 -0
- package/dist/utils/models-error.js.map +1 -0
- package/dist/utils/node-http-proxy.d.ts +4 -0
- package/dist/utils/node-http-proxy.d.ts.map +1 -0
- package/dist/utils/node-http-proxy.js +133 -0
- package/dist/utils/node-http-proxy.js.map +1 -0
- package/dist/utils/oauth-page.d.ts +3 -0
- package/dist/utils/oauth-page.d.ts.map +1 -0
- package/dist/utils/oauth-page.js +105 -0
- package/dist/utils/oauth-page.js.map +1 -0
- package/dist/utils/openrouter-cost.d.ts +24 -0
- package/dist/utils/openrouter-cost.d.ts.map +1 -0
- package/dist/utils/openrouter-cost.js +34 -0
- package/dist/utils/openrouter-cost.js.map +1 -0
- package/dist/utils/overflow.d.ts +70 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +186 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/provider-env.d.ts +7 -0
- package/dist/utils/provider-env.d.ts.map +1 -0
- package/dist/utils/provider-env.js +44 -0
- package/dist/utils/provider-env.js.map +1 -0
- package/dist/utils/provider-retry.d.ts +18 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +97 -0
- package/dist/utils/provider-retry.js.map +1 -0
- package/dist/utils/retry.d.ts +58 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +257 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/sanitize-unicode.d.ts +22 -0
- package/dist/utils/sanitize-unicode.d.ts.map +1 -0
- package/dist/utils/sanitize-unicode.js +26 -0
- package/dist/utils/sanitize-unicode.js.map +1 -0
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +15 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/streaming-json.d.ts +84 -0
- package/dist/utils/streaming-json.d.ts.map +1 -0
- package/dist/utils/streaming-json.js +513 -0
- package/dist/utils/streaming-json.js.map +1 -0
- package/dist/utils/string-enum.d.ts +17 -0
- package/dist/utils/string-enum.d.ts.map +1 -0
- package/dist/utils/string-enum.js +20 -0
- package/dist/utils/string-enum.js.map +1 -0
- package/dist/utils/text.d.ts +21 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +45 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/transcript.d.ts +101 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +218 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +42 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +20 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +62 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/version.d.ts +2 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +3 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +119 -5
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
import Anthropic, {} from "@anthropic-ai/sdk";
|
|
2
|
+
import { ANTHROPIC_FEDERATION_RULE_ID_ENV, ANTHROPIC_IDENTITY_TOKEN_FILE_ENV, ANTHROPIC_ORGANIZATION_ID_ENV, ANTHROPIC_SERVICE_ACCOUNT_ID_ENV, ANTHROPIC_WORKSPACE_ID_ENV, } from "../env-api-keys.js";
|
|
3
|
+
import { calculateCost } from "../models.js";
|
|
4
|
+
import { registerSessionResourceCleanup } from "../session-resources.js";
|
|
5
|
+
import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
|
|
6
|
+
import { withCauseDetail } from "../utils/error-body.js";
|
|
7
|
+
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
8
|
+
import { shortHash } from "../utils/hash.js";
|
|
9
|
+
import { headersToRecord } from "../utils/headers.js";
|
|
10
|
+
import { getIdentityHeaders } from "../utils/identity.js";
|
|
11
|
+
import { parseJsonWithRepair } from "../utils/json-parse.js";
|
|
12
|
+
import { applyOpenRouterReportedCost, isOpenRouterModel, } from "../utils/openrouter-cost.js";
|
|
13
|
+
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
14
|
+
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
15
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
16
|
+
import { ToolCallArgumentsStream } from "../utils/streaming-json.js";
|
|
17
|
+
import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.js";
|
|
18
|
+
import { getCurrentTools, getInitialSystemMessage, resolveTranscript, } from "../utils/transcript.js";
|
|
19
|
+
import { getJsonSchemaToolParameters, prefersJsonSchemaStrictSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
20
|
+
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
21
|
+
import { adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToContext } from "./simple-options.js";
|
|
22
|
+
import { hasExceededStrictToolLimits, isStrictToolLimitErrorMessage, markStrictToolLimitsExceeded, } from "./strict-tool-limits.js";
|
|
23
|
+
import { splitErrorToolResultImages, transformMessages } from "./transform-messages.js";
|
|
24
|
+
/**
|
|
25
|
+
* Resolve cache retention preference.
|
|
26
|
+
* Defaults to "short" and uses DIFFRA_CACHE_RETENTION for backward compatibility.
|
|
27
|
+
*/
|
|
28
|
+
function resolveCacheRetention(cacheRetention, env) {
|
|
29
|
+
if (cacheRetention) {
|
|
30
|
+
return cacheRetention;
|
|
31
|
+
}
|
|
32
|
+
if (getProviderEnvValue("DIFFRA_CACHE_RETENTION", env) === "long") {
|
|
33
|
+
return "long";
|
|
34
|
+
}
|
|
35
|
+
return "short";
|
|
36
|
+
}
|
|
37
|
+
function getCacheControl(model, cacheRetention, env) {
|
|
38
|
+
const retention = resolveCacheRetention(cacheRetention, env);
|
|
39
|
+
if (retention === "none") {
|
|
40
|
+
return { retention };
|
|
41
|
+
}
|
|
42
|
+
const ttl = retention === "long" && getAnthropicCompat(model).supportsLongCacheRetention ? "1h" : undefined;
|
|
43
|
+
return {
|
|
44
|
+
retention,
|
|
45
|
+
cacheControl: { type: "ephemeral", ...(ttl && { ttl }) },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Stealth mode: Mimic Claude Code's tool naming exactly
|
|
49
|
+
const claudeCodeVersion = "2.1.322";
|
|
50
|
+
// Claude Code 2.x tool names (canonical casing)
|
|
51
|
+
// Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
|
|
52
|
+
// To update: https://github.com/badlogic/cchistory
|
|
53
|
+
const claudeCodeTools = [
|
|
54
|
+
"Read",
|
|
55
|
+
"Write",
|
|
56
|
+
"Edit",
|
|
57
|
+
"Bash",
|
|
58
|
+
"Grep",
|
|
59
|
+
"Glob",
|
|
60
|
+
"AskUserQuestion",
|
|
61
|
+
"EnterPlanMode",
|
|
62
|
+
"ExitPlanMode",
|
|
63
|
+
"KillShell",
|
|
64
|
+
"NotebookEdit",
|
|
65
|
+
"Skill",
|
|
66
|
+
"Task",
|
|
67
|
+
"TaskOutput",
|
|
68
|
+
"TodoWrite",
|
|
69
|
+
"WebFetch",
|
|
70
|
+
"WebSearch",
|
|
71
|
+
];
|
|
72
|
+
const ccToolLookup = new Map(claudeCodeTools.map((t) => [t.toLowerCase(), t]));
|
|
73
|
+
// Convert tool name to CC canonical casing if it matches (case-insensitive)
|
|
74
|
+
const toClaudeCodeName = (name) => ccToolLookup.get(name.toLowerCase()) ?? name;
|
|
75
|
+
const fromClaudeCodeName = (name, tools) => {
|
|
76
|
+
if (tools && tools.length > 0) {
|
|
77
|
+
const lowerName = name.toLowerCase();
|
|
78
|
+
const matchedTool = tools.find((tool) => tool.name.toLowerCase() === lowerName);
|
|
79
|
+
if (matchedTool)
|
|
80
|
+
return matchedTool.name;
|
|
81
|
+
}
|
|
82
|
+
return name;
|
|
83
|
+
};
|
|
84
|
+
function convertImageBlock(image) {
|
|
85
|
+
return {
|
|
86
|
+
type: "image",
|
|
87
|
+
source: {
|
|
88
|
+
type: "base64",
|
|
89
|
+
media_type: image.mimeType,
|
|
90
|
+
data: image.data,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert content blocks to Anthropic API format
|
|
96
|
+
*/
|
|
97
|
+
function convertContentBlocks(content) {
|
|
98
|
+
// If only text blocks, return as concatenated string for simplicity
|
|
99
|
+
const hasImages = content.some((c) => c.type === "image");
|
|
100
|
+
if (!hasImages) {
|
|
101
|
+
return sanitizeSurrogates(content.map((c) => c.text).join("\n"));
|
|
102
|
+
}
|
|
103
|
+
// If we have images, convert to content block array
|
|
104
|
+
const blocks = content.map((block) => {
|
|
105
|
+
if (block.type === "text") {
|
|
106
|
+
return {
|
|
107
|
+
type: "text",
|
|
108
|
+
text: sanitizeSurrogates(block.text),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return convertImageBlock(block);
|
|
112
|
+
});
|
|
113
|
+
// If only images (no text), add placeholder text block
|
|
114
|
+
const hasText = blocks.some((b) => b.type === "text");
|
|
115
|
+
if (!hasText) {
|
|
116
|
+
blocks.unshift({
|
|
117
|
+
type: "text",
|
|
118
|
+
text: "(see attached image)",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return blocks;
|
|
122
|
+
}
|
|
123
|
+
const FINE_GRAINED_TOOL_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14";
|
|
124
|
+
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
125
|
+
const SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
126
|
+
const MID_CONVERSATION_OUTPUT_CONFIG_BETA = "mid-conversation-output-config-2026-07-01";
|
|
127
|
+
const THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
128
|
+
const INLINE_TOOLS_BETA = "inline-tools-2026-09-15";
|
|
129
|
+
const MESSAGE_THREADS_BETA = "message-threads-2026-08-12";
|
|
130
|
+
/**
|
|
131
|
+
* Stable deferred tool declared whenever native tool changes are in use. Anthropic adds
|
|
132
|
+
* hidden prompt scaffolding for mid-conversation tool changes; declaring this placeholder
|
|
133
|
+
* from the first request keeps that scaffolding in the cached prefix, so the first tool
|
|
134
|
+
* change does not invalidate the cache (measured: full miss without it). It is never
|
|
135
|
+
* activated and the model cannot see it.
|
|
136
|
+
*/
|
|
137
|
+
const DEFERRED_TOOL_PLACEHOLDER = {
|
|
138
|
+
name: "__pi_deferred_placeholder__",
|
|
139
|
+
description: "Reserved placeholder. Never available. Never call this.",
|
|
140
|
+
input_schema: { type: "object", properties: {}, required: [] },
|
|
141
|
+
defer_loading: true,
|
|
142
|
+
};
|
|
143
|
+
function shouldUseServerSideFallbackBeta(model) {
|
|
144
|
+
return (model.compat?.allowedFallbackModels?.length ?? 0) > 0;
|
|
145
|
+
}
|
|
146
|
+
function getAnthropicCompat(model) {
|
|
147
|
+
const isOpenRouter = model.provider === "openrouter" || model.baseUrl.includes("openrouter.ai");
|
|
148
|
+
return {
|
|
149
|
+
supportsEagerToolInputStreaming: model.compat?.supportsEagerToolInputStreaming ?? true,
|
|
150
|
+
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
|
|
151
|
+
sendSessionAffinityHeaders: model.compat?.sendSessionAffinityHeaders ?? isOpenRouter,
|
|
152
|
+
sessionAffinityFormat: model.compat?.sessionAffinityFormat ?? (isOpenRouter ? "openrouter" : undefined),
|
|
153
|
+
supportsCacheControlOnTools: model.compat?.supportsCacheControlOnTools ?? true,
|
|
154
|
+
supportsTemperature: model.compat?.supportsTemperature ?? true,
|
|
155
|
+
allowEmptySignature: model.compat?.allowEmptySignature ?? false,
|
|
156
|
+
supportsStrictTools: model.compat?.supportsStrictTools ?? false,
|
|
157
|
+
supportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,
|
|
158
|
+
supportsMidConvoToolChanges: model.compat?.supportsMidConvoToolChanges ?? false,
|
|
159
|
+
// Gateways that drop unknown request fields would silently turn a `continue` into a request
|
|
160
|
+
// without the earlier conversation, so the default is limited to Anthropic's own endpoint.
|
|
161
|
+
// Widen or remove this restriction once proxies generally forward the `thread` field.
|
|
162
|
+
supportsMessageThreads: model.compat?.supportsMessageThreads ?? model.baseUrl.includes("api.anthropic.com"),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Per session: where the next request can continue, or "off" after the endpoint rejected threads. */
|
|
166
|
+
const threadState = new Map();
|
|
167
|
+
const MAX_THREAD_STATE_ENTRIES = 10_000;
|
|
168
|
+
/** Rejections of a `continue` that a new thread fixes: expired, raced, or a fixed setting changed. */
|
|
169
|
+
const NEW_THREAD_ERRORS = new Set([
|
|
170
|
+
"thread_not_found",
|
|
171
|
+
"thread_already_continued",
|
|
172
|
+
"thread_continue_in_flight",
|
|
173
|
+
"thread_fingerprint_mismatch",
|
|
174
|
+
]);
|
|
175
|
+
/**
|
|
176
|
+
* Sets a session's thread state, keeping at most `MAX_THREAD_STATE_ENTRIES` sessions.
|
|
177
|
+
*
|
|
178
|
+
* State is normally freed by `cleanupSessionResources(sessionId)` when a session ends, as diffra's
|
|
179
|
+
* coding agent does. The cap bounds memory for library users that never call it, for example a
|
|
180
|
+
* server passing a new `sessionId` per conversation. Dropping the least recently updated session
|
|
181
|
+
* is cheap: its thread has most likely expired on the server already (after a few minutes idle),
|
|
182
|
+
* and otherwise its next request just starts a new thread.
|
|
183
|
+
*/
|
|
184
|
+
function setThreadState(sessionId, value) {
|
|
185
|
+
// Re-insert so Map order stays oldest-first for the cap.
|
|
186
|
+
threadState.delete(sessionId);
|
|
187
|
+
threadState.set(sessionId, value);
|
|
188
|
+
if (threadState.size > MAX_THREAD_STATE_ENTRIES) {
|
|
189
|
+
const oldest = threadState.keys().next().value;
|
|
190
|
+
if (oldest !== undefined)
|
|
191
|
+
threadState.delete(oldest);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
registerSessionResourceCleanup((sessionId) => {
|
|
195
|
+
if (sessionId)
|
|
196
|
+
threadState.delete(sessionId);
|
|
197
|
+
else
|
|
198
|
+
threadState.clear();
|
|
199
|
+
});
|
|
200
|
+
/**
|
|
201
|
+
* Hash of everything a `continue` builds on: the settings that must stay the same within a thread
|
|
202
|
+
* and the messages the server already holds.
|
|
203
|
+
*
|
|
204
|
+
* - Settings, as sent: the endpoint (a thread exists on one endpoint only), and the fixed request
|
|
205
|
+
* fields. A `continue` omits `system` and `tools` and the server keeps the thread's own, so only
|
|
206
|
+
* this check can notice a change to them, including their cache markers. The server rejects
|
|
207
|
+
* changes to the other fields with `thread_fingerprint_mismatch`; checking them here saves that
|
|
208
|
+
* rejected request. A fixed field missing here costs only that rejection, which also starts a
|
|
209
|
+
* new thread.
|
|
210
|
+
* - Messages, normalized so messages that mean the same to the API hash the same.
|
|
211
|
+
*/
|
|
212
|
+
function hashThreadPrefix(model, params, messages) {
|
|
213
|
+
const { system, tools, thinking, output_config, tool_choice, betas, fallbacks } = params;
|
|
214
|
+
const settings = JSON.stringify([
|
|
215
|
+
model.provider,
|
|
216
|
+
model.baseUrl,
|
|
217
|
+
params.model,
|
|
218
|
+
system,
|
|
219
|
+
tools,
|
|
220
|
+
thinking,
|
|
221
|
+
output_config,
|
|
222
|
+
tool_choice,
|
|
223
|
+
betas,
|
|
224
|
+
fallbacks,
|
|
225
|
+
]);
|
|
226
|
+
const conversation = JSON.stringify(messages, (key, value) => {
|
|
227
|
+
// Cache markers don't change what a message means, but they move: diffra puts one on the newest
|
|
228
|
+
// message, so the message that had it in the last request has none in this one. Extensions
|
|
229
|
+
// may add markers anywhere too.
|
|
230
|
+
if (key === "cache_control")
|
|
231
|
+
return undefined;
|
|
232
|
+
// To attach that marker, the newest user message's string content is sent as one text block;
|
|
233
|
+
// the next request sends the same message as a string: "hi" vs [{ type: "text", text: "hi" }].
|
|
234
|
+
if (key === "content" && typeof value === "string")
|
|
235
|
+
return [{ type: "text", text: value }];
|
|
236
|
+
return value;
|
|
237
|
+
});
|
|
238
|
+
return shortHash(settings + conversation);
|
|
239
|
+
}
|
|
240
|
+
function createThreadRequest(sessionId, params) {
|
|
241
|
+
return { sessionId, body: { ...params, thread: { type: "create" } } };
|
|
242
|
+
}
|
|
243
|
+
function prepareThreadRequest(model, sessionId, params) {
|
|
244
|
+
const state = threadState.get(sessionId);
|
|
245
|
+
if (state === "off")
|
|
246
|
+
return undefined;
|
|
247
|
+
if (state !== undefined &&
|
|
248
|
+
params.messages.length > state.prefixCount &&
|
|
249
|
+
hashThreadPrefix(model, params, params.messages.slice(0, state.prefixCount)) === state.prefixHash) {
|
|
250
|
+
// Each reply can be continued once; deleting also keeps a concurrent request from trying.
|
|
251
|
+
threadState.delete(sessionId);
|
|
252
|
+
const { system: _system, tools: _tools, ...rest } = params;
|
|
253
|
+
return {
|
|
254
|
+
body: {
|
|
255
|
+
...rest,
|
|
256
|
+
messages: params.messages.slice(state.prefixCount),
|
|
257
|
+
thread: { type: "continue", previous_message_id: state.replyId },
|
|
258
|
+
},
|
|
259
|
+
sessionId,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return createThreadRequest(sessionId, params);
|
|
263
|
+
}
|
|
264
|
+
/** The `error_code` Anthropic puts in `error.details` of thread rejections. */
|
|
265
|
+
function getThreadErrorCode(error) {
|
|
266
|
+
const body = error.error;
|
|
267
|
+
const code = body?.error?.details?.error_code;
|
|
268
|
+
return typeof code === "string" ? code : undefined;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Sends a thread request. A rejection about the thread (never a started stream) is resent once in
|
|
272
|
+
* full: as a new thread when the old one can't be continued, or without `thread` when the endpoint
|
|
273
|
+
* can't use threads, which also turns threads off for the session. Other errors are passed on.
|
|
274
|
+
* Returns the response and the thread request that produced it, if any.
|
|
275
|
+
*/
|
|
276
|
+
async function sendThreadRequest(thread, params, send, output, signal) {
|
|
277
|
+
try {
|
|
278
|
+
return { response: await send(thread.body), thread };
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
if (signal?.aborted || !(error instanceof Anthropic.APIError))
|
|
282
|
+
throw error;
|
|
283
|
+
const errorCode = getThreadErrorCode(error);
|
|
284
|
+
const startNewThread = errorCode !== undefined && NEW_THREAD_ERRORS.has(errorCode);
|
|
285
|
+
// The endpoint can't use threads: it can't thread this request, or it doesn't know the
|
|
286
|
+
// `thread` field and rejects it without a code ("thread: Extra inputs are not permitted"),
|
|
287
|
+
// e.g. with an `anthropic-beta` header that lacks the threads beta.
|
|
288
|
+
const threadsUnsupported = errorCode === "thread_unsupported_request" ||
|
|
289
|
+
(errorCode === undefined && error.status === 400 && error.message.includes("thread"));
|
|
290
|
+
// Any other error (prompt too long, unknown model, strict tool limits, ...) is not about the
|
|
291
|
+
// thread, and resending would only fail again.
|
|
292
|
+
if (!startNewThread && !threadsUnsupported)
|
|
293
|
+
throw error;
|
|
294
|
+
// Recorded before the resend, so a failed resend keeps it.
|
|
295
|
+
appendAssistantMessageDiagnostic(output, {
|
|
296
|
+
type: "anthropic_thread_fallback",
|
|
297
|
+
timestamp: Date.now(),
|
|
298
|
+
error: { message: error.message },
|
|
299
|
+
details: { reason: errorCode ?? String(error.status) },
|
|
300
|
+
});
|
|
301
|
+
if (startNewThread) {
|
|
302
|
+
const created = createThreadRequest(thread.sessionId, params);
|
|
303
|
+
return { response: await send(created.body), thread: created };
|
|
304
|
+
}
|
|
305
|
+
// With the threads beta, a request without `thread` is a normal request.
|
|
306
|
+
const response = await send(params);
|
|
307
|
+
setThreadState(thread.sessionId, "off");
|
|
308
|
+
return { response, thread: undefined };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Records where the session's next request can continue: after `output`, the clean reply to the
|
|
313
|
+
* thread request `thread`, whose full request was `params`.
|
|
314
|
+
*/
|
|
315
|
+
function recordThreadReply(model, thread, params, output, isOAuth, allowEmptySignature) {
|
|
316
|
+
// `responseModel` is set only when a fallback model answered; the server does not store those
|
|
317
|
+
// replies, so they cannot be continued.
|
|
318
|
+
if (output.responseId === undefined || output.responseModel !== undefined)
|
|
319
|
+
return;
|
|
320
|
+
// Convert the reply like the next request will, keeping only the assistant message
|
|
321
|
+
// (transformMessages adds placeholder results for trailing tool calls).
|
|
322
|
+
const reply = convertMessages(transformMessages([output], model, normalizeToolCallId), isOAuth, undefined, allowEmptySignature).messages.filter((message) => message.role === "assistant");
|
|
323
|
+
const prefix = [...params.messages, ...reply];
|
|
324
|
+
setThreadState(thread.sessionId, {
|
|
325
|
+
prefixCount: prefix.length,
|
|
326
|
+
prefixHash: hashThreadPrefix(model, params, prefix),
|
|
327
|
+
replyId: output.responseId,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
function mergeHeaders(...headerSources) {
|
|
331
|
+
const merged = {};
|
|
332
|
+
for (const headers of headerSources) {
|
|
333
|
+
if (headers) {
|
|
334
|
+
Object.assign(merged, headers);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return merged;
|
|
338
|
+
}
|
|
339
|
+
function hasHeader(headers, name) {
|
|
340
|
+
if (!headers)
|
|
341
|
+
return false;
|
|
342
|
+
const expected = name.toLowerCase();
|
|
343
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
344
|
+
if (key.toLowerCase() === expected && value !== null && value.trim().length > 0)
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
function hasRequestAuth(apiKey, headers) {
|
|
350
|
+
return (!!apiKey ||
|
|
351
|
+
hasHeader(headers, "authorization") ||
|
|
352
|
+
hasHeader(headers, "x-api-key") ||
|
|
353
|
+
hasHeader(headers, "cf-aig-authorization"));
|
|
354
|
+
}
|
|
355
|
+
function assertRequestAuth(provider, apiKey, headers) {
|
|
356
|
+
if (!hasRequestAuth(apiKey, headers))
|
|
357
|
+
throw new Error(`No API key for provider: ${provider}`);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Anthropic SDK client that never runs the SDK's own credential chain
|
|
361
|
+
* (ANTHROPIC_PROFILE config files, federation env vars). Without this, every
|
|
362
|
+
* client built with `apiKey: null, authToken: null` for header-owned auth would
|
|
363
|
+
* also resolve and exchange SDK credentials behind diffra's auth resolver.
|
|
364
|
+
*/
|
|
365
|
+
class DiffraAnthropic extends Anthropic {
|
|
366
|
+
_shouldResolveDefaultCredentials() {
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Workload identity federation config from the ANTHROPIC_* variables the
|
|
372
|
+
* Anthropic SDK documents; the SDK performs the token exchange and refresh.
|
|
373
|
+
* Only for the anthropic provider, since the exchange is an Anthropic API
|
|
374
|
+
* endpoint, and only when no key or auth header was resolved.
|
|
375
|
+
*/
|
|
376
|
+
function getAnthropicFederation(model, apiKey, headers, env) {
|
|
377
|
+
if (model.provider !== "anthropic" || hasRequestAuth(apiKey, headers))
|
|
378
|
+
return undefined;
|
|
379
|
+
const federationRuleId = getProviderEnvValue(ANTHROPIC_FEDERATION_RULE_ID_ENV, env);
|
|
380
|
+
const organizationId = getProviderEnvValue(ANTHROPIC_ORGANIZATION_ID_ENV, env);
|
|
381
|
+
const identityTokenFile = getProviderEnvValue(ANTHROPIC_IDENTITY_TOKEN_FILE_ENV, env);
|
|
382
|
+
if (!federationRuleId || !organizationId || !identityTokenFile)
|
|
383
|
+
return undefined;
|
|
384
|
+
return {
|
|
385
|
+
organization_id: organizationId,
|
|
386
|
+
workspace_id: getProviderEnvValue(ANTHROPIC_WORKSPACE_ID_ENV, env),
|
|
387
|
+
authentication: {
|
|
388
|
+
type: "oidc_federation",
|
|
389
|
+
federation_rule_id: federationRuleId,
|
|
390
|
+
service_account_id: getProviderEnvValue(ANTHROPIC_SERVICE_ACCOUNT_ID_ENV, env),
|
|
391
|
+
identity_token: { source: "file", path: identityTokenFile },
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The SDK caches the federated access token per client, but diffra creates a client
|
|
397
|
+
* per request. Keep one client for the current federation config and fetch, and
|
|
398
|
+
* clone it per request with `withOptions()`, which shares the token cache.
|
|
399
|
+
*/
|
|
400
|
+
let federationClient;
|
|
401
|
+
const ANTHROPIC_MESSAGE_EVENTS = new Set([
|
|
402
|
+
"message_start",
|
|
403
|
+
"message_delta",
|
|
404
|
+
"message_stop",
|
|
405
|
+
"content_block_start",
|
|
406
|
+
"content_block_delta",
|
|
407
|
+
"content_block_stop",
|
|
408
|
+
]);
|
|
409
|
+
function flushSseEvent(state) {
|
|
410
|
+
if (!state.event && state.data.length === 0) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
const event = {
|
|
414
|
+
event: state.event,
|
|
415
|
+
data: state.data.join("\n"),
|
|
416
|
+
raw: [...state.raw],
|
|
417
|
+
};
|
|
418
|
+
state.event = null;
|
|
419
|
+
state.data = [];
|
|
420
|
+
state.raw = [];
|
|
421
|
+
return event;
|
|
422
|
+
}
|
|
423
|
+
function decodeSseLine(line, state) {
|
|
424
|
+
if (line === "") {
|
|
425
|
+
return flushSseEvent(state);
|
|
426
|
+
}
|
|
427
|
+
state.raw.push(line);
|
|
428
|
+
if (line.startsWith(":")) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
const delimiterIndex = line.indexOf(":");
|
|
432
|
+
const fieldName = delimiterIndex === -1 ? line : line.slice(0, delimiterIndex);
|
|
433
|
+
let value = delimiterIndex === -1 ? "" : line.slice(delimiterIndex + 1);
|
|
434
|
+
if (value.startsWith(" ")) {
|
|
435
|
+
value = value.slice(1);
|
|
436
|
+
}
|
|
437
|
+
if (fieldName === "event") {
|
|
438
|
+
state.event = value;
|
|
439
|
+
}
|
|
440
|
+
else if (fieldName === "data") {
|
|
441
|
+
state.data.push(value);
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
function nextLineBreakIndex(text) {
|
|
446
|
+
const carriageReturnIndex = text.indexOf("\r");
|
|
447
|
+
const newlineIndex = text.indexOf("\n");
|
|
448
|
+
if (carriageReturnIndex === -1) {
|
|
449
|
+
return newlineIndex;
|
|
450
|
+
}
|
|
451
|
+
if (newlineIndex === -1) {
|
|
452
|
+
return carriageReturnIndex;
|
|
453
|
+
}
|
|
454
|
+
return Math.min(carriageReturnIndex, newlineIndex);
|
|
455
|
+
}
|
|
456
|
+
function consumeLine(text) {
|
|
457
|
+
const lineBreakIndex = nextLineBreakIndex(text);
|
|
458
|
+
if (lineBreakIndex === -1) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
let nextIndex = lineBreakIndex + 1;
|
|
462
|
+
if (text[lineBreakIndex] === "\r" && text[nextIndex] === "\n") {
|
|
463
|
+
nextIndex += 1;
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
line: text.slice(0, lineBreakIndex),
|
|
467
|
+
rest: text.slice(nextIndex),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
async function* iterateSseMessages(body, signal) {
|
|
471
|
+
const reader = body.getReader();
|
|
472
|
+
const decoder = new TextDecoder();
|
|
473
|
+
const state = { event: null, data: [], raw: [] };
|
|
474
|
+
let buffer = "";
|
|
475
|
+
try {
|
|
476
|
+
while (true) {
|
|
477
|
+
if (signal?.aborted) {
|
|
478
|
+
throw new Error("Request was aborted");
|
|
479
|
+
}
|
|
480
|
+
const { value, done } = await reader.read();
|
|
481
|
+
if (done) {
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
buffer += decoder.decode(value, { stream: true });
|
|
485
|
+
let consumed = consumeLine(buffer);
|
|
486
|
+
while (consumed) {
|
|
487
|
+
buffer = consumed.rest;
|
|
488
|
+
const event = decodeSseLine(consumed.line, state);
|
|
489
|
+
if (event) {
|
|
490
|
+
yield event;
|
|
491
|
+
}
|
|
492
|
+
consumed = consumeLine(buffer);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
buffer += decoder.decode();
|
|
496
|
+
let consumed = consumeLine(buffer);
|
|
497
|
+
while (consumed) {
|
|
498
|
+
buffer = consumed.rest;
|
|
499
|
+
const event = decodeSseLine(consumed.line, state);
|
|
500
|
+
if (event) {
|
|
501
|
+
yield event;
|
|
502
|
+
}
|
|
503
|
+
consumed = consumeLine(buffer);
|
|
504
|
+
}
|
|
505
|
+
if (buffer.length > 0) {
|
|
506
|
+
const event = decodeSseLine(buffer, state);
|
|
507
|
+
if (event) {
|
|
508
|
+
yield event;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const trailingEvent = flushSseEvent(state);
|
|
512
|
+
if (trailingEvent) {
|
|
513
|
+
yield trailingEvent;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
finally {
|
|
517
|
+
reader.releaseLock();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async function* iterateAnthropicEvents(response, signal) {
|
|
521
|
+
if (!response.body) {
|
|
522
|
+
throw new Error("Attempted to iterate over an Anthropic response with no body");
|
|
523
|
+
}
|
|
524
|
+
let sawMessageStart = false;
|
|
525
|
+
let sawMessageEnd = false;
|
|
526
|
+
for await (const sse of iterateSseMessages(response.body, signal)) {
|
|
527
|
+
if (sse.event === "error") {
|
|
528
|
+
throw new Error(sse.data);
|
|
529
|
+
}
|
|
530
|
+
if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) {
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
const event = parseJsonWithRepair(sse.data);
|
|
535
|
+
if (event.type === "message_start") {
|
|
536
|
+
sawMessageStart = true;
|
|
537
|
+
}
|
|
538
|
+
else if (event.type === "message_stop") {
|
|
539
|
+
sawMessageEnd = true;
|
|
540
|
+
}
|
|
541
|
+
yield event;
|
|
542
|
+
}
|
|
543
|
+
catch (error) {
|
|
544
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
545
|
+
throw new Error(`Could not parse Anthropic SSE event ${sse.event}: ${message}; data=${sse.data}; raw=${sse.raw.join("\\n")}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (sawMessageStart && !sawMessageEnd) {
|
|
549
|
+
throw new Error("Anthropic stream ended before message_stop");
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
export const stream = (model, context, options) => {
|
|
553
|
+
const stream = new AssistantMessageEventStream();
|
|
554
|
+
const compat = getAnthropicCompat(model);
|
|
555
|
+
const normalizedContext = resolveTranscript(context, compat.supportsMidConvoSystemMessages);
|
|
556
|
+
const currentTools = getCurrentTools(normalizedContext.messages);
|
|
557
|
+
(async () => {
|
|
558
|
+
const output = {
|
|
559
|
+
role: "assistant",
|
|
560
|
+
content: [],
|
|
561
|
+
api: model.api,
|
|
562
|
+
provider: model.provider,
|
|
563
|
+
model: model.id,
|
|
564
|
+
usage: {
|
|
565
|
+
input: 0,
|
|
566
|
+
output: 0,
|
|
567
|
+
cacheRead: 0,
|
|
568
|
+
cacheWrite: 0,
|
|
569
|
+
totalTokens: 0,
|
|
570
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
571
|
+
},
|
|
572
|
+
stopReason: "pending",
|
|
573
|
+
timestamp: Date.now(),
|
|
574
|
+
};
|
|
575
|
+
try {
|
|
576
|
+
let client;
|
|
577
|
+
let isOAuth;
|
|
578
|
+
let usageModel = model;
|
|
579
|
+
let inputTransformations;
|
|
580
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
581
|
+
const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
|
|
582
|
+
// Session whose requests may use threads; undefined when threads don't apply. Sessions where
|
|
583
|
+
// the endpoint rejected threads ("off") still send the threads beta, which the resend that
|
|
584
|
+
// turned them off was accepted with; `prepareThreadRequest()` just sends no `thread`.
|
|
585
|
+
const threadSessionId = compat.supportsMessageThreads ? cacheSessionId : undefined;
|
|
586
|
+
if (options?.client) {
|
|
587
|
+
client = options.client;
|
|
588
|
+
isOAuth = false;
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
const apiKey = options?.apiKey;
|
|
592
|
+
const federation = getAnthropicFederation(model, apiKey, options?.headers, options?.env);
|
|
593
|
+
if (!federation)
|
|
594
|
+
assertRequestAuth(model.provider, apiKey, options?.headers);
|
|
595
|
+
let copilotDynamicHeaders;
|
|
596
|
+
if (model.provider === "github-copilot") {
|
|
597
|
+
const hasImages = hasCopilotVisionInput(normalizedContext.messages);
|
|
598
|
+
copilotDynamicHeaders = buildCopilotDynamicHeaders({
|
|
599
|
+
messages: normalizedContext.messages,
|
|
600
|
+
hasImages,
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
const created = createClient(model, apiKey, options?.headers, options?.fetch, copilotDynamicHeaders, cacheSessionId, federation, options?.identity);
|
|
604
|
+
client = created.client;
|
|
605
|
+
isOAuth = created.isOAuthToken;
|
|
606
|
+
}
|
|
607
|
+
const requestOptions = {
|
|
608
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
609
|
+
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
|
|
610
|
+
maxRetries: 0,
|
|
611
|
+
};
|
|
612
|
+
const send = (body) => retryProviderRequest(() => client.beta.messages.create(body, requestOptions).asResponse(), {
|
|
613
|
+
maxRetries: options?.maxRetries,
|
|
614
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
615
|
+
signal: options?.signal,
|
|
616
|
+
});
|
|
617
|
+
let disablePreferredStrictTools = hasExceededStrictToolLimits(options?.sessionId);
|
|
618
|
+
let response;
|
|
619
|
+
let params;
|
|
620
|
+
// The thread request that produced the response; undefined when no `thread` was sent.
|
|
621
|
+
let thread;
|
|
622
|
+
for (;;) {
|
|
623
|
+
options?.signal?.throwIfAborted();
|
|
624
|
+
const built = buildParams(model, normalizedContext, isOAuth, options, {
|
|
625
|
+
disablePreferredStrictTools,
|
|
626
|
+
messageThreads: threadSessionId !== undefined,
|
|
627
|
+
});
|
|
628
|
+
if (built.providerThinkingLevel)
|
|
629
|
+
output.providerThinkingLevel = built.providerThinkingLevel;
|
|
630
|
+
params = built.params;
|
|
631
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
632
|
+
if (nextParams !== undefined) {
|
|
633
|
+
params = { ...nextParams, stream: true };
|
|
634
|
+
}
|
|
635
|
+
const prepared = threadSessionId !== undefined && options?.disableContinuation !== true
|
|
636
|
+
? prepareThreadRequest(model, threadSessionId, params)
|
|
637
|
+
: undefined;
|
|
638
|
+
try {
|
|
639
|
+
const sent = prepared
|
|
640
|
+
? await sendThreadRequest(prepared, params, send, output, options?.signal)
|
|
641
|
+
: { response: await send(params), thread: undefined };
|
|
642
|
+
response = sent.response;
|
|
643
|
+
thread = sent.thread;
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
// Only downgrade a rejected request, never an already-started stream.
|
|
648
|
+
if (options?.signal?.aborted ||
|
|
649
|
+
disablePreferredStrictTools ||
|
|
650
|
+
!built.hasPreferredStrictTools ||
|
|
651
|
+
!(error instanceof Anthropic.APIError) ||
|
|
652
|
+
error.status !== 400 ||
|
|
653
|
+
error.type !== "invalid_request_error" ||
|
|
654
|
+
!isStrictToolLimitErrorMessage(error.message)) {
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
657
|
+
disablePreferredStrictTools = true;
|
|
658
|
+
markStrictToolLimitsExceeded(options?.sessionId);
|
|
659
|
+
appendAssistantMessageDiagnostic(output, {
|
|
660
|
+
type: "anthropic_strict_tools_fallback",
|
|
661
|
+
timestamp: Date.now(),
|
|
662
|
+
error: { message: error.message },
|
|
663
|
+
details: { reason: "strict_tool_limits_exceeded" },
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
668
|
+
stream.push({ type: "start", partial: output });
|
|
669
|
+
// Stream state per Anthropic block index, kept off the content blocks so it never reaches partials.
|
|
670
|
+
const openBlocks = new Map();
|
|
671
|
+
const openBlock = (anthropicIndex) => {
|
|
672
|
+
const open = openBlocks.get(anthropicIndex);
|
|
673
|
+
return open === undefined ? undefined : { ...open, block: output.content[open.contentIndex] };
|
|
674
|
+
};
|
|
675
|
+
for await (const event of iterateAnthropicEvents(response, options?.signal)) {
|
|
676
|
+
await options?.onProviderStreamEvent?.(event, model);
|
|
677
|
+
if (event.type === "message_start") {
|
|
678
|
+
output.responseId = event.message.id;
|
|
679
|
+
const transformations = event.message.input_transformations;
|
|
680
|
+
if (Array.isArray(transformations))
|
|
681
|
+
inputTransformations = transformations;
|
|
682
|
+
const responseModel = event.message.model;
|
|
683
|
+
if (responseModel !== model.id)
|
|
684
|
+
output.responseModel = responseModel;
|
|
685
|
+
const fallbackCost = responseModel === model.id
|
|
686
|
+
? undefined
|
|
687
|
+
: model.compat?.allowedFallbackModels?.find((fallback) => fallback.provider === model.provider && fallback.model === responseModel)?.cost;
|
|
688
|
+
usageModel = fallbackCost ? { ...model, id: responseModel, cost: fallbackCost } : model;
|
|
689
|
+
// Capture initial token usage from message_start event
|
|
690
|
+
// This ensures we have input token counts even if the stream is aborted early
|
|
691
|
+
output.usage.input = event.message.usage.input_tokens || 0;
|
|
692
|
+
output.usage.output = event.message.usage.output_tokens || 0;
|
|
693
|
+
output.usage.cacheRead = event.message.usage.cache_read_input_tokens || 0;
|
|
694
|
+
output.usage.cacheWrite = event.message.usage.cache_creation_input_tokens || 0;
|
|
695
|
+
output.usage.cacheWrite1h = event.message.usage.cache_creation?.ephemeral_1h_input_tokens || 0;
|
|
696
|
+
// Anthropic doesn't provide total_tokens, compute from components
|
|
697
|
+
output.usage.totalTokens =
|
|
698
|
+
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
699
|
+
calculateCost(usageModel, output.usage);
|
|
700
|
+
}
|
|
701
|
+
else if (event.type === "content_block_start") {
|
|
702
|
+
if (event.content_block.type === "fallback") {
|
|
703
|
+
if (output.content.length > 0) {
|
|
704
|
+
throw new Error("Anthropic performed an unsupported mid-output model fallback");
|
|
705
|
+
}
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
if (event.content_block.type === "text") {
|
|
709
|
+
output.content.push({ type: "text", text: event.content_block.text ?? "" });
|
|
710
|
+
openBlocks.set(event.index, { contentIndex: output.content.length - 1 });
|
|
711
|
+
stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
|
|
712
|
+
}
|
|
713
|
+
else if (event.content_block.type === "thinking") {
|
|
714
|
+
output.content.push({
|
|
715
|
+
type: "thinking",
|
|
716
|
+
thinking: event.content_block.thinking ?? "",
|
|
717
|
+
thinkingSignature: event.content_block.signature ?? "",
|
|
718
|
+
});
|
|
719
|
+
openBlocks.set(event.index, { contentIndex: output.content.length - 1 });
|
|
720
|
+
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
|
|
721
|
+
}
|
|
722
|
+
else if (event.content_block.type === "redacted_thinking") {
|
|
723
|
+
output.content.push({
|
|
724
|
+
type: "thinking",
|
|
725
|
+
thinking: "[Reasoning redacted]",
|
|
726
|
+
thinkingSignature: event.content_block.data,
|
|
727
|
+
redacted: true,
|
|
728
|
+
});
|
|
729
|
+
openBlocks.set(event.index, { contentIndex: output.content.length - 1 });
|
|
730
|
+
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
|
|
731
|
+
}
|
|
732
|
+
else if (event.content_block.type === "tool_use") {
|
|
733
|
+
output.content.push({
|
|
734
|
+
type: "toolCall",
|
|
735
|
+
id: event.content_block.id,
|
|
736
|
+
name: isOAuth
|
|
737
|
+
? fromClaudeCodeName(event.content_block.name, currentTools)
|
|
738
|
+
: event.content_block.name,
|
|
739
|
+
arguments: event.content_block.input ?? {},
|
|
740
|
+
});
|
|
741
|
+
openBlocks.set(event.index, {
|
|
742
|
+
contentIndex: output.content.length - 1,
|
|
743
|
+
arguments: new ToolCallArgumentsStream(),
|
|
744
|
+
});
|
|
745
|
+
stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
else if (event.type === "content_block_delta") {
|
|
749
|
+
const open = openBlock(event.index);
|
|
750
|
+
if (event.delta.type === "text_delta") {
|
|
751
|
+
if (open?.block.type === "text") {
|
|
752
|
+
open.block.text += event.delta.text;
|
|
753
|
+
stream.push({
|
|
754
|
+
type: "text_delta",
|
|
755
|
+
contentIndex: open.contentIndex,
|
|
756
|
+
delta: event.delta.text,
|
|
757
|
+
partial: output,
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
else if (event.delta.type === "thinking_delta") {
|
|
762
|
+
if (open?.block.type === "thinking") {
|
|
763
|
+
open.block.thinking += event.delta.thinking;
|
|
764
|
+
stream.push({
|
|
765
|
+
type: "thinking_delta",
|
|
766
|
+
contentIndex: open.contentIndex,
|
|
767
|
+
delta: event.delta.thinking,
|
|
768
|
+
partial: output,
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
else if (event.delta.type === "input_json_delta") {
|
|
773
|
+
if (open?.block.type === "toolCall" && open.arguments !== undefined) {
|
|
774
|
+
open.block.arguments = open.arguments.append(event.delta.partial_json);
|
|
775
|
+
stream.push({
|
|
776
|
+
type: "toolcall_delta",
|
|
777
|
+
contentIndex: open.contentIndex,
|
|
778
|
+
delta: event.delta.partial_json,
|
|
779
|
+
partial: output,
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
else if (event.delta.type === "signature_delta") {
|
|
784
|
+
if (open?.block.type === "thinking") {
|
|
785
|
+
open.block.thinkingSignature = open.block.thinkingSignature || "";
|
|
786
|
+
open.block.thinkingSignature += event.delta.signature;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
else if (event.type === "content_block_stop") {
|
|
791
|
+
const open = openBlock(event.index);
|
|
792
|
+
openBlocks.delete(event.index);
|
|
793
|
+
if (open) {
|
|
794
|
+
const { block, contentIndex: index } = open;
|
|
795
|
+
if (block.type === "text") {
|
|
796
|
+
stream.push({
|
|
797
|
+
type: "text_end",
|
|
798
|
+
contentIndex: index,
|
|
799
|
+
content: block.text,
|
|
800
|
+
partial: output,
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
else if (block.type === "thinking") {
|
|
804
|
+
stream.push({
|
|
805
|
+
type: "thinking_end",
|
|
806
|
+
contentIndex: index,
|
|
807
|
+
content: block.thinking,
|
|
808
|
+
partial: output,
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
else if (block.type === "toolCall" && open.arguments !== undefined) {
|
|
812
|
+
Object.assign(block, open.arguments.finish());
|
|
813
|
+
stream.push({
|
|
814
|
+
type: "toolcall_end",
|
|
815
|
+
contentIndex: index,
|
|
816
|
+
toolCall: block,
|
|
817
|
+
partial: output,
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
else if (event.type === "message_delta") {
|
|
823
|
+
const transformations = event.input_transformations;
|
|
824
|
+
if (Array.isArray(transformations))
|
|
825
|
+
inputTransformations = transformations;
|
|
826
|
+
if (event.delta.stop_reason) {
|
|
827
|
+
output.rawStopReason = event.delta.stop_reason;
|
|
828
|
+
const stopReasonResult = mapStopReason(event.delta.stop_reason, event.delta.stop_details);
|
|
829
|
+
output.stopReason = stopReasonResult.stopReason;
|
|
830
|
+
if (stopReasonResult.errorMessage) {
|
|
831
|
+
output.errorMessage = stopReasonResult.errorMessage;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
// Only update usage fields if present (not null).
|
|
835
|
+
// Preserves input_tokens from message_start when proxies omit it in message_delta.
|
|
836
|
+
if (event.usage) {
|
|
837
|
+
if (event.usage.input_tokens != null) {
|
|
838
|
+
output.usage.input = event.usage.input_tokens;
|
|
839
|
+
}
|
|
840
|
+
if (event.usage.output_tokens != null) {
|
|
841
|
+
output.usage.output = event.usage.output_tokens;
|
|
842
|
+
}
|
|
843
|
+
if (event.usage.cache_read_input_tokens != null) {
|
|
844
|
+
output.usage.cacheRead = event.usage.cache_read_input_tokens;
|
|
845
|
+
}
|
|
846
|
+
if (event.usage.cache_creation_input_tokens != null) {
|
|
847
|
+
output.usage.cacheWrite = event.usage.cache_creation_input_tokens;
|
|
848
|
+
}
|
|
849
|
+
// Vercel AI Gateway includes the TTL breakdown in deltas, though the SDK only types it on message_start.
|
|
850
|
+
const cacheCreation = event.usage.cache_creation;
|
|
851
|
+
if (cacheCreation?.ephemeral_1h_input_tokens != null) {
|
|
852
|
+
output.usage.cacheWrite1h = cacheCreation.ephemeral_1h_input_tokens;
|
|
853
|
+
}
|
|
854
|
+
// Anthropic reports reasoning tokens as a subset of output tokens.
|
|
855
|
+
const thinkingTokens = event.usage.output_tokens_details?.thinking_tokens;
|
|
856
|
+
if (thinkingTokens != null) {
|
|
857
|
+
output.usage.reasoning = thinkingTokens;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
// Anthropic doesn't provide total_tokens, compute from components
|
|
861
|
+
output.usage.totalTokens =
|
|
862
|
+
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
863
|
+
calculateCost(usageModel, output.usage);
|
|
864
|
+
if (isOpenRouterModel(model) && event.usage) {
|
|
865
|
+
// OpenRouter adds billing fields to streamed message_delta usage at runtime,
|
|
866
|
+
// although its OpenAPI schema and the Anthropic SDK do not type those fields.
|
|
867
|
+
applyOpenRouterReportedCost(output.usage, event.usage);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (options?.signal?.aborted) {
|
|
872
|
+
throw new Error("Request was aborted");
|
|
873
|
+
}
|
|
874
|
+
if (output.stopReason === "pending") {
|
|
875
|
+
throw new Error("Anthropic stream ended without a stop reason");
|
|
876
|
+
}
|
|
877
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
878
|
+
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
879
|
+
}
|
|
880
|
+
if (thread)
|
|
881
|
+
recordThreadReply(model, thread, params, output, isOAuth, compat.allowEmptySignature);
|
|
882
|
+
if (inputTransformations && inputTransformations.length > 0) {
|
|
883
|
+
appendAssistantMessageDiagnostic(output, {
|
|
884
|
+
type: "anthropic_input_transformations",
|
|
885
|
+
timestamp: Date.now(),
|
|
886
|
+
details: {
|
|
887
|
+
transformations: inputTransformations.map((transformation) => ({
|
|
888
|
+
type: transformation.type ?? undefined,
|
|
889
|
+
path: transformation.path ?? undefined,
|
|
890
|
+
reason: transformation.reason ?? undefined,
|
|
891
|
+
})),
|
|
892
|
+
},
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
896
|
+
stream.end();
|
|
897
|
+
}
|
|
898
|
+
catch (error) {
|
|
899
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
900
|
+
output.errorMessage = error instanceof Error ? withCauseDetail(error) : JSON.stringify(error);
|
|
901
|
+
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
902
|
+
stream.end();
|
|
903
|
+
}
|
|
904
|
+
})();
|
|
905
|
+
return stream;
|
|
906
|
+
};
|
|
907
|
+
/**
|
|
908
|
+
* Map ThinkingLevel to Anthropic effort levels for adaptive thinking.
|
|
909
|
+
* Note: effort "max" is available on all adaptive-thinking Claude models, while native
|
|
910
|
+
* "xhigh" is only available on Opus 4.7/4.8, Sonnet 5, and Fable 5.
|
|
911
|
+
*/
|
|
912
|
+
function mapThinkingLevelToEffort(model, level) {
|
|
913
|
+
const mapped = level ? model.thinkingLevelMap?.[level] : undefined;
|
|
914
|
+
if (typeof mapped === "string")
|
|
915
|
+
return mapped;
|
|
916
|
+
switch (level) {
|
|
917
|
+
case "minimal":
|
|
918
|
+
case "low":
|
|
919
|
+
return "low";
|
|
920
|
+
case "medium":
|
|
921
|
+
return "medium";
|
|
922
|
+
case "high":
|
|
923
|
+
return "high";
|
|
924
|
+
default:
|
|
925
|
+
return "high";
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
export const streamSimple = (model, context, options) => {
|
|
929
|
+
if (!getAnthropicFederation(model, options?.apiKey, options?.headers, options?.env)) {
|
|
930
|
+
assertRequestAuth(model.provider, options?.apiKey, options?.headers);
|
|
931
|
+
}
|
|
932
|
+
const base = {
|
|
933
|
+
...buildBaseOptions(model, context, options, options?.apiKey),
|
|
934
|
+
toolChoice: options?.toolChoice,
|
|
935
|
+
};
|
|
936
|
+
if (!options?.reasoning) {
|
|
937
|
+
return stream(model, context, {
|
|
938
|
+
...base,
|
|
939
|
+
thinkingEnabled: false,
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
// For models with adaptive thinking: use an effort level.
|
|
943
|
+
// For older models: use budget-based thinking.
|
|
944
|
+
if (model.compat?.forceAdaptiveThinking === true) {
|
|
945
|
+
const effort = mapThinkingLevelToEffort(model, options.reasoning);
|
|
946
|
+
return stream(model, context, {
|
|
947
|
+
...base,
|
|
948
|
+
thinkingEnabled: true,
|
|
949
|
+
effort,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
// Undefined means the caller did not request an output cap; let the helper use the model cap.
|
|
953
|
+
// Do not coerce to 0 here, or the thinking budget would become the entire max_tokens value.
|
|
954
|
+
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
955
|
+
const maxTokens = clampMaxTokensToContext(model, context, adjusted.maxTokens);
|
|
956
|
+
return stream(model, context, {
|
|
957
|
+
...base,
|
|
958
|
+
maxTokens,
|
|
959
|
+
thinkingEnabled: true,
|
|
960
|
+
thinkingBudgetTokens: Math.min(adjusted.thinkingBudget, Math.max(0, maxTokens - 1024)),
|
|
961
|
+
});
|
|
962
|
+
};
|
|
963
|
+
function isOAuthToken(apiKey) {
|
|
964
|
+
return apiKey.includes("sk-ant-oat");
|
|
965
|
+
}
|
|
966
|
+
function createClient(model, apiKey, optionsHeaders, fetch, dynamicHeaders, sessionId, federation, identity) {
|
|
967
|
+
// Copilot: Bearer auth.
|
|
968
|
+
if (model.provider === "github-copilot") {
|
|
969
|
+
const client = new DiffraAnthropic({
|
|
970
|
+
apiKey: null,
|
|
971
|
+
authToken: apiKey ?? null,
|
|
972
|
+
baseURL: model.baseUrl,
|
|
973
|
+
dangerouslyAllowBrowser: true,
|
|
974
|
+
fetch,
|
|
975
|
+
defaultHeaders: mergeHeaders(getIdentityHeaders(model, identity), {
|
|
976
|
+
accept: "application/json",
|
|
977
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
978
|
+
}, model.headers, dynamicHeaders, optionsHeaders),
|
|
979
|
+
});
|
|
980
|
+
return { client, isOAuthToken: false };
|
|
981
|
+
}
|
|
982
|
+
// OAuth: Bearer auth, Claude Code identity headers instead of the client identity.
|
|
983
|
+
if (apiKey && isOAuthToken(apiKey)) {
|
|
984
|
+
const client = new DiffraAnthropic({
|
|
985
|
+
apiKey: null,
|
|
986
|
+
authToken: apiKey,
|
|
987
|
+
baseURL: model.baseUrl,
|
|
988
|
+
dangerouslyAllowBrowser: true,
|
|
989
|
+
fetch,
|
|
990
|
+
defaultHeaders: mergeHeaders({
|
|
991
|
+
accept: "application/json",
|
|
992
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
993
|
+
"user-agent": `claude-cli/${claudeCodeVersion}`,
|
|
994
|
+
"x-app": "cli",
|
|
995
|
+
}, model.headers, optionsHeaders),
|
|
996
|
+
});
|
|
997
|
+
return { client, isOAuthToken: true };
|
|
998
|
+
}
|
|
999
|
+
// API key, header-owned auth, or workload identity federation.
|
|
1000
|
+
const compat = getAnthropicCompat(model);
|
|
1001
|
+
const sessionAffinityHeaders = {};
|
|
1002
|
+
if (sessionId && compat.sendSessionAffinityHeaders) {
|
|
1003
|
+
const header = compat.sessionAffinityFormat === "openrouter" ? "x-session-id" : "x-session-affinity";
|
|
1004
|
+
sessionAffinityHeaders[header] = sessionId;
|
|
1005
|
+
}
|
|
1006
|
+
const defaultHeaders = mergeHeaders(getIdentityHeaders(model, identity), {
|
|
1007
|
+
accept: "application/json",
|
|
1008
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
1009
|
+
}, sessionAffinityHeaders, model.headers, optionsHeaders);
|
|
1010
|
+
if (federation) {
|
|
1011
|
+
const key = JSON.stringify([model.baseUrl, federation]);
|
|
1012
|
+
if (federationClient?.key !== key || federationClient.fetch !== fetch) {
|
|
1013
|
+
const client = new DiffraAnthropic({
|
|
1014
|
+
apiKey: null,
|
|
1015
|
+
authToken: null,
|
|
1016
|
+
config: federation,
|
|
1017
|
+
baseURL: model.baseUrl,
|
|
1018
|
+
dangerouslyAllowBrowser: true,
|
|
1019
|
+
fetch,
|
|
1020
|
+
});
|
|
1021
|
+
federationClient = { key, fetch, client };
|
|
1022
|
+
}
|
|
1023
|
+
return { client: federationClient.client.withOptions({ defaultHeaders }), isOAuthToken: false };
|
|
1024
|
+
}
|
|
1025
|
+
const client = new DiffraAnthropic({
|
|
1026
|
+
apiKey: apiKey ?? null,
|
|
1027
|
+
authToken: null,
|
|
1028
|
+
baseURL: model.baseUrl,
|
|
1029
|
+
dangerouslyAllowBrowser: true,
|
|
1030
|
+
fetch,
|
|
1031
|
+
defaultHeaders,
|
|
1032
|
+
});
|
|
1033
|
+
return { client, isOAuthToken: false };
|
|
1034
|
+
}
|
|
1035
|
+
function getBetaFeatures(model, context, options, { isOAuthToken, nativeToolChanges, messageThreads }) {
|
|
1036
|
+
let configuredFeatures;
|
|
1037
|
+
for (const headers of [model.headers, options?.headers]) {
|
|
1038
|
+
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
1039
|
+
if (name.toLowerCase() === "anthropic-beta")
|
|
1040
|
+
configuredFeatures = value;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (configuredFeatures === null)
|
|
1044
|
+
return [];
|
|
1045
|
+
if (configuredFeatures !== undefined) {
|
|
1046
|
+
return [
|
|
1047
|
+
...new Set(configuredFeatures
|
|
1048
|
+
.split(",")
|
|
1049
|
+
.map((feature) => feature.trim())
|
|
1050
|
+
.filter((feature) => feature.length > 0)),
|
|
1051
|
+
];
|
|
1052
|
+
}
|
|
1053
|
+
const features = [];
|
|
1054
|
+
if (isOAuthToken)
|
|
1055
|
+
features.push("claude-code-20250219", "oauth-2025-04-20");
|
|
1056
|
+
if (shouldUseFineGrainedToolStreamingBeta(model, context))
|
|
1057
|
+
features.push(FINE_GRAINED_TOOL_STREAMING_BETA);
|
|
1058
|
+
if (model.reasoning &&
|
|
1059
|
+
options?.thinkingEnabled === true &&
|
|
1060
|
+
(options.interleavedThinking ?? true) &&
|
|
1061
|
+
model.compat?.forceAdaptiveThinking !== true) {
|
|
1062
|
+
features.push(INTERLEAVED_THINKING_BETA);
|
|
1063
|
+
}
|
|
1064
|
+
if (shouldUseServerSideFallbackBeta(model))
|
|
1065
|
+
features.push(SERVER_SIDE_FALLBACK_BETA);
|
|
1066
|
+
if (model.compat?.supportsMidConvoEffort === true) {
|
|
1067
|
+
features.push(MID_CONVERSATION_OUTPUT_CONFIG_BETA, THINKING_BINDING_CONTROLS_BETA);
|
|
1068
|
+
}
|
|
1069
|
+
if (nativeToolChanges)
|
|
1070
|
+
features.push(INLINE_TOOLS_BETA);
|
|
1071
|
+
if (messageThreads)
|
|
1072
|
+
features.push(MESSAGE_THREADS_BETA);
|
|
1073
|
+
return [...new Set(features)];
|
|
1074
|
+
}
|
|
1075
|
+
function buildParams(model, context, isOAuthToken, options, flags) {
|
|
1076
|
+
const { cacheControl } = getCacheControl(model, options?.cacheRetention, options?.env);
|
|
1077
|
+
const compat = getAnthropicCompat(model);
|
|
1078
|
+
const initialSystemMessage = getInitialSystemMessage(context.messages);
|
|
1079
|
+
const initialSystemText = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : "";
|
|
1080
|
+
const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);
|
|
1081
|
+
const conversationMessages = initialSystemMessage ? transformedMessages.slice(1) : transformedMessages;
|
|
1082
|
+
// Native tool changes keep the request-level tool list fixed and define every later tool
|
|
1083
|
+
// by value in a `tool_addition` block, which also expresses same-name redefinitions.
|
|
1084
|
+
// Anthropic rejects a tool list where every tool is deferred, so there must be an initial
|
|
1085
|
+
// active tool to anchor the placeholder. Otherwise the current tool list is sent.
|
|
1086
|
+
let hasPreferredStrictTools = false;
|
|
1087
|
+
const convertToolDefinitions = (tools, toolCacheControl) => {
|
|
1088
|
+
const definitions = convertTools(tools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl, flags.disablePreferredStrictTools);
|
|
1089
|
+
if (definitions.some((definition, index) => definition.strict === true && prefersJsonSchemaStrictSampling(tools[index]))) {
|
|
1090
|
+
hasPreferredStrictTools = true;
|
|
1091
|
+
}
|
|
1092
|
+
return definitions;
|
|
1093
|
+
};
|
|
1094
|
+
const initialTools = initialSystemMessage?.toolsAdded ?? [];
|
|
1095
|
+
const nativeToolChanges = compat.supportsMidConvoSystemMessages && compat.supportsMidConvoToolChanges && initialTools.length > 0;
|
|
1096
|
+
const thinkingDisabled = model.reasoning && options?.thinkingEnabled === false && model.thinkingLevelMap?.off !== null;
|
|
1097
|
+
// Effort cannot change between messages while thinking is disabled, so "off" sends no effort markers.
|
|
1098
|
+
const effortMessages = model.compat?.supportsMidConvoEffort === true && !thinkingDisabled;
|
|
1099
|
+
const converted = convertMessages(conversationMessages, isOAuthToken, cacheControl, compat.allowEmptySignature, effortMessages ? model.provider : undefined, nativeToolChanges ? convertToolDefinitions : undefined);
|
|
1100
|
+
const activeEffort = options?.effort ?? "high";
|
|
1101
|
+
const betaFeatures = getBetaFeatures(model, context, options, {
|
|
1102
|
+
isOAuthToken,
|
|
1103
|
+
nativeToolChanges,
|
|
1104
|
+
messageThreads: flags.messageThreads,
|
|
1105
|
+
});
|
|
1106
|
+
const params = {
|
|
1107
|
+
model: model.id,
|
|
1108
|
+
messages: effortMessages ? insertThinkingLevelMessages(converted, activeEffort) : converted.messages,
|
|
1109
|
+
max_tokens: options?.maxTokens ?? model.maxTokens,
|
|
1110
|
+
stream: true,
|
|
1111
|
+
...(betaFeatures.length > 0 ? { betas: betaFeatures } : {}),
|
|
1112
|
+
};
|
|
1113
|
+
// For OAuth tokens, we MUST include Claude Code identity
|
|
1114
|
+
if (isOAuthToken) {
|
|
1115
|
+
params.system = [
|
|
1116
|
+
{
|
|
1117
|
+
type: "text",
|
|
1118
|
+
text: "You are Claude Code, Anthropic's official CLI for Claude.",
|
|
1119
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
1120
|
+
},
|
|
1121
|
+
];
|
|
1122
|
+
if (initialSystemText) {
|
|
1123
|
+
params.system.push({
|
|
1124
|
+
type: "text",
|
|
1125
|
+
text: sanitizeSurrogates(initialSystemText),
|
|
1126
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
else if (initialSystemText) {
|
|
1131
|
+
// Add cache control to system prompt for non-OAuth tokens
|
|
1132
|
+
params.system = [
|
|
1133
|
+
{
|
|
1134
|
+
type: "text",
|
|
1135
|
+
text: sanitizeSurrogates(initialSystemText),
|
|
1136
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
1137
|
+
},
|
|
1138
|
+
];
|
|
1139
|
+
}
|
|
1140
|
+
// Temperature is incompatible with extended thinking and unsupported on Claude Opus 4.7+.
|
|
1141
|
+
if (options?.temperature !== undefined &&
|
|
1142
|
+
!options?.thinkingEnabled &&
|
|
1143
|
+
model.compat?.supportsMidConvoEffort !== true &&
|
|
1144
|
+
compat.supportsTemperature) {
|
|
1145
|
+
params.temperature = options.temperature;
|
|
1146
|
+
}
|
|
1147
|
+
const toolCacheControl = compat.supportsCacheControlOnTools ? cacheControl : undefined;
|
|
1148
|
+
if (nativeToolChanges) {
|
|
1149
|
+
// Initial tools stay active with the cache breakpoint on the last one, followed by the
|
|
1150
|
+
// placeholder. The list never changes afterwards: later tools are defined by value in
|
|
1151
|
+
// `tool_addition` blocks and withdrawn by `tool_removal`, so the cached prefix survives
|
|
1152
|
+
// every tool change.
|
|
1153
|
+
params.tools = [...convertToolDefinitions(initialTools, toolCacheControl), DEFERRED_TOOL_PLACEHOLDER];
|
|
1154
|
+
}
|
|
1155
|
+
else {
|
|
1156
|
+
const tools = getCurrentTools(context.messages);
|
|
1157
|
+
if (tools.length > 0) {
|
|
1158
|
+
params.tools = convertToolDefinitions(tools, toolCacheControl);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
if (thinkingDisabled) {
|
|
1162
|
+
// No effort is sent, so the model default applies. Anthropic rejects `block_binding`
|
|
1163
|
+
// with disabled thinking.
|
|
1164
|
+
params.thinking = { type: "disabled" };
|
|
1165
|
+
}
|
|
1166
|
+
else if (effortMessages) {
|
|
1167
|
+
// Managed effort models use adaptive thinking so prefix mismatches can
|
|
1168
|
+
// be dropped instead of surfacing as persistent 400 responses.
|
|
1169
|
+
params.thinking = {
|
|
1170
|
+
type: "adaptive",
|
|
1171
|
+
display: options?.thinkingDisplay ?? "summarized",
|
|
1172
|
+
block_binding: { prefix_mismatch_behavior: "drop_block" },
|
|
1173
|
+
};
|
|
1174
|
+
// Effort markers set the level for every reply. The top-level effort is part of the cached
|
|
1175
|
+
// prompt, so it stays fixed. It is "low" because organizations can cap effort and reject
|
|
1176
|
+
// requests containing any level above the cap.
|
|
1177
|
+
params.output_config = { effort: "low" };
|
|
1178
|
+
}
|
|
1179
|
+
else if (model.reasoning && options?.thinkingEnabled) {
|
|
1180
|
+
// Default to "summarized" so Opus 4.7 and Mythos Preview behave like
|
|
1181
|
+
// older Claude 4 models (whose API default is also "summarized").
|
|
1182
|
+
const display = options.thinkingDisplay ?? "summarized";
|
|
1183
|
+
if (model.compat?.forceAdaptiveThinking === true) {
|
|
1184
|
+
// Adaptive thinking: Claude decides when and how much to think.
|
|
1185
|
+
params.thinking = { type: "adaptive", display };
|
|
1186
|
+
if (options.effort) {
|
|
1187
|
+
params.output_config = { effort: options.effort };
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
// Budget-based thinking for older models
|
|
1192
|
+
params.thinking = {
|
|
1193
|
+
type: "enabled",
|
|
1194
|
+
budget_tokens: options.thinkingBudgetTokens || 1024,
|
|
1195
|
+
display,
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (options?.metadata) {
|
|
1200
|
+
const userId = options.metadata.user_id;
|
|
1201
|
+
if (typeof userId === "string") {
|
|
1202
|
+
params.metadata = { user_id: userId };
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
if (options?.toolChoice) {
|
|
1206
|
+
if (typeof options.toolChoice === "string") {
|
|
1207
|
+
params.tool_choice = { type: options.toolChoice };
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
params.tool_choice = options.toolChoice;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
const allowedFallbackModels = model.compat?.allowedFallbackModels;
|
|
1214
|
+
if (allowedFallbackModels && allowedFallbackModels.length > 0) {
|
|
1215
|
+
params.fallbacks = allowedFallbackModels.map((fallback) => ({ model: fallback.model }));
|
|
1216
|
+
}
|
|
1217
|
+
return { params, hasPreferredStrictTools, providerThinkingLevel: effortMessages ? activeEffort : undefined };
|
|
1218
|
+
}
|
|
1219
|
+
// Normalize tool call IDs to match Anthropic's required pattern and length
|
|
1220
|
+
function normalizeToolCallId(id) {
|
|
1221
|
+
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
1222
|
+
}
|
|
1223
|
+
function convertToolResult(msg, content = msg.content) {
|
|
1224
|
+
return {
|
|
1225
|
+
type: "tool_result",
|
|
1226
|
+
tool_use_id: msg.toolCallId,
|
|
1227
|
+
content: convertContentBlocks(content),
|
|
1228
|
+
is_error: msg.isError,
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
function convertMessages(transformedMessages, isOAuthToken, cacheControl, allowEmptySignature = false, managedProvider,
|
|
1232
|
+
/** Converts tool definitions for native `tool_addition` blocks; undefined when tool changes are not native. */
|
|
1233
|
+
convertToolDefinitions) {
|
|
1234
|
+
const params = [];
|
|
1235
|
+
const assistantLevels = new Map();
|
|
1236
|
+
// Later system messages are held back and emitted directly before the next assistant
|
|
1237
|
+
// message that is sent (or at the end of the transcript). Assistant messages that convert to
|
|
1238
|
+
// no blocks are dropped, so holding past them keeps an update from landing before a user
|
|
1239
|
+
// message (#11091). Anthropic requires `tool_result` blocks to
|
|
1240
|
+
// immediately follow their `tool_use`, so a system message between them is rejected; this
|
|
1241
|
+
// also mirrors where the managed-effort system messages are inserted. As a result an
|
|
1242
|
+
// update placed before a user message in the transcript lands after it on the wire.
|
|
1243
|
+
const pendingSystemMessages = [];
|
|
1244
|
+
const flushPendingSystemMessages = () => {
|
|
1245
|
+
params.push(...pendingSystemMessages);
|
|
1246
|
+
pendingSystemMessages.length = 0;
|
|
1247
|
+
};
|
|
1248
|
+
for (let i = 0; i < transformedMessages.length; i++) {
|
|
1249
|
+
const msg = transformedMessages[i];
|
|
1250
|
+
if (msg.role === "system") {
|
|
1251
|
+
// Later system messages only reach this point when the model accepts them natively;
|
|
1252
|
+
// otherwise the transcript was collapsed into the leading message before conversion.
|
|
1253
|
+
const text = renderSystemMessageUpdate(msg);
|
|
1254
|
+
const blocks = [];
|
|
1255
|
+
if (text.length > 0)
|
|
1256
|
+
blocks.push({ type: "text", text: sanitizeSurrogates(text) });
|
|
1257
|
+
if (convertToolDefinitions) {
|
|
1258
|
+
const added = msg.toolsAdded ?? [];
|
|
1259
|
+
const redefined = new Set(added.map((tool) => tool.name));
|
|
1260
|
+
for (const tool of msg.toolsRemoved ?? []) {
|
|
1261
|
+
// A new definition under the same name replaces the old one, so no removal is needed.
|
|
1262
|
+
if (redefined.has(tool.name))
|
|
1263
|
+
continue;
|
|
1264
|
+
blocks.push({
|
|
1265
|
+
type: "tool_removal",
|
|
1266
|
+
tool: { type: "tool_reference", name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name },
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
for (const definition of convertToolDefinitions(added)) {
|
|
1270
|
+
blocks.push({ type: "tool_addition", tool: { type: "tool_definition", definition } });
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (blocks.length > 0)
|
|
1274
|
+
pendingSystemMessages.push({ role: "system", content: blocks });
|
|
1275
|
+
}
|
|
1276
|
+
else if (msg.role === "user") {
|
|
1277
|
+
if (typeof msg.content === "string") {
|
|
1278
|
+
if (msg.content.trim().length > 0) {
|
|
1279
|
+
params.push({
|
|
1280
|
+
role: "user",
|
|
1281
|
+
content: sanitizeSurrogates(msg.content),
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
const blocks = msg.content.map((item) => {
|
|
1287
|
+
if (item.type === "text") {
|
|
1288
|
+
return {
|
|
1289
|
+
type: "text",
|
|
1290
|
+
text: sanitizeSurrogates(item.text),
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
else {
|
|
1294
|
+
return convertImageBlock(item);
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
const filteredBlocks = blocks.filter((b) => {
|
|
1298
|
+
if (b.type === "text") {
|
|
1299
|
+
return b.text.trim().length > 0;
|
|
1300
|
+
}
|
|
1301
|
+
return true;
|
|
1302
|
+
});
|
|
1303
|
+
if (filteredBlocks.length === 0)
|
|
1304
|
+
continue;
|
|
1305
|
+
params.push({
|
|
1306
|
+
role: "user",
|
|
1307
|
+
content: filteredBlocks,
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
else if (msg.role === "assistant") {
|
|
1312
|
+
const blocks = [];
|
|
1313
|
+
for (const block of msg.content) {
|
|
1314
|
+
if (block.type === "text") {
|
|
1315
|
+
if (block.text.trim().length === 0)
|
|
1316
|
+
continue;
|
|
1317
|
+
blocks.push({
|
|
1318
|
+
type: "text",
|
|
1319
|
+
text: sanitizeSurrogates(block.text),
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
else if (block.type === "thinking") {
|
|
1323
|
+
// Redacted thinking: pass the opaque payload back as redacted_thinking
|
|
1324
|
+
if (block.redacted) {
|
|
1325
|
+
blocks.push({
|
|
1326
|
+
type: "redacted_thinking",
|
|
1327
|
+
data: block.thinkingSignature,
|
|
1328
|
+
});
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
const thinkingSignature = block.thinkingSignature;
|
|
1332
|
+
const hasThinkingSignature = !!thinkingSignature && thinkingSignature.trim().length > 0;
|
|
1333
|
+
if (block.thinking.trim().length === 0 && !hasThinkingSignature)
|
|
1334
|
+
continue;
|
|
1335
|
+
// If thinking signature is missing/empty (e.g., from aborted stream),
|
|
1336
|
+
// convert to plain text for Anthropic. Some compatible providers emit
|
|
1337
|
+
// and accept empty signatures, so let marked models preserve the block.
|
|
1338
|
+
if (!hasThinkingSignature) {
|
|
1339
|
+
blocks.push(allowEmptySignature
|
|
1340
|
+
? {
|
|
1341
|
+
type: "thinking",
|
|
1342
|
+
thinking: sanitizeSurrogates(block.thinking),
|
|
1343
|
+
signature: "",
|
|
1344
|
+
}
|
|
1345
|
+
: {
|
|
1346
|
+
type: "text",
|
|
1347
|
+
text: sanitizeSurrogates(block.thinking),
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
else {
|
|
1351
|
+
blocks.push({
|
|
1352
|
+
type: "thinking",
|
|
1353
|
+
thinking: sanitizeSurrogates(block.thinking),
|
|
1354
|
+
signature: thinkingSignature,
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
else if (block.type === "toolCall") {
|
|
1359
|
+
blocks.push({
|
|
1360
|
+
type: "tool_use",
|
|
1361
|
+
id: block.id,
|
|
1362
|
+
name: isOAuthToken ? toClaudeCodeName(block.name) : block.name,
|
|
1363
|
+
input: block.arguments ?? {},
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
if (blocks.length === 0)
|
|
1368
|
+
continue;
|
|
1369
|
+
flushPendingSystemMessages();
|
|
1370
|
+
const messageIndex = params.length;
|
|
1371
|
+
params.push({
|
|
1372
|
+
role: "assistant",
|
|
1373
|
+
content: blocks,
|
|
1374
|
+
});
|
|
1375
|
+
if (managedProvider !== undefined &&
|
|
1376
|
+
msg.api === "anthropic-messages" &&
|
|
1377
|
+
msg.provider === managedProvider &&
|
|
1378
|
+
isAnthropicEffort(msg.providerThinkingLevel)) {
|
|
1379
|
+
assistantLevels.set(messageIndex, msg.providerThinkingLevel);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
else if (msg.role === "toolResult") {
|
|
1383
|
+
// Collect all consecutive toolResult messages, needed for z.ai Anthropic endpoint.
|
|
1384
|
+
const toolResults = [];
|
|
1385
|
+
// Anthropic rejects error tool results that contain anything but text, so their images follow
|
|
1386
|
+
// all tool results of the turn, which must come first in the user message (#10794).
|
|
1387
|
+
const errorImages = [];
|
|
1388
|
+
let j = i;
|
|
1389
|
+
while (j < transformedMessages.length && transformedMessages[j].role === "toolResult") {
|
|
1390
|
+
const toolMsg = transformedMessages[j];
|
|
1391
|
+
const split = splitErrorToolResultImages(toolMsg);
|
|
1392
|
+
toolResults.push(convertToolResult(toolMsg, split?.content));
|
|
1393
|
+
if (split) {
|
|
1394
|
+
errorImages.push({ type: "text", text: split.caption }, ...split.images.map(convertImageBlock));
|
|
1395
|
+
}
|
|
1396
|
+
j++;
|
|
1397
|
+
}
|
|
1398
|
+
// Skip the messages we've already processed.
|
|
1399
|
+
i = j - 1;
|
|
1400
|
+
params.push({
|
|
1401
|
+
role: "user",
|
|
1402
|
+
content: [...toolResults, ...errorImages],
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
flushPendingSystemMessages();
|
|
1407
|
+
// Add cache_control to the last user or system message to cache conversation history
|
|
1408
|
+
if (cacheControl && params.length > 0) {
|
|
1409
|
+
const lastMessage = params[params.length - 1];
|
|
1410
|
+
if (lastMessage.role === "user" || lastMessage.role === "system") {
|
|
1411
|
+
if (Array.isArray(lastMessage.content)) {
|
|
1412
|
+
const lastBlock = lastMessage.content[lastMessage.content.length - 1];
|
|
1413
|
+
if (lastBlock &&
|
|
1414
|
+
(lastBlock.type === "text" ||
|
|
1415
|
+
lastBlock.type === "image" ||
|
|
1416
|
+
lastBlock.type === "tool_result" ||
|
|
1417
|
+
lastBlock.type === "tool_addition" ||
|
|
1418
|
+
lastBlock.type === "tool_removal")) {
|
|
1419
|
+
lastBlock.cache_control = cacheControl;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
else if (typeof lastMessage.content === "string") {
|
|
1423
|
+
lastMessage.content = [
|
|
1424
|
+
{
|
|
1425
|
+
type: "text",
|
|
1426
|
+
text: lastMessage.content,
|
|
1427
|
+
cache_control: cacheControl,
|
|
1428
|
+
},
|
|
1429
|
+
];
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
return { messages: params, assistantLevels };
|
|
1434
|
+
}
|
|
1435
|
+
function isAnthropicEffort(value) {
|
|
1436
|
+
return value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
1437
|
+
}
|
|
1438
|
+
function insertThinkingLevelMessages(converted, activeEffort) {
|
|
1439
|
+
const messages = [];
|
|
1440
|
+
for (let index = 0; index < converted.messages.length; index++) {
|
|
1441
|
+
const historicalEffort = converted.assistantLevels.get(index);
|
|
1442
|
+
if (historicalEffort !== undefined) {
|
|
1443
|
+
messages.push({ role: "system", content: [], output_config: { effort: historicalEffort } });
|
|
1444
|
+
}
|
|
1445
|
+
messages.push(converted.messages[index]);
|
|
1446
|
+
}
|
|
1447
|
+
messages.push({ role: "system", content: [], output_config: { effort: activeEffort } });
|
|
1448
|
+
return messages;
|
|
1449
|
+
}
|
|
1450
|
+
function shouldUseFineGrainedToolStreamingBeta(model, context) {
|
|
1451
|
+
return getCurrentTools(context.messages).length > 0 && !getAnthropicCompat(model).supportsEagerToolInputStreaming;
|
|
1452
|
+
}
|
|
1453
|
+
// Keywords Anthropic strict tool use rejects with a 400 for the whole request.
|
|
1454
|
+
// https://platform.claude.com/docs/en/build-with-claude/structured-outputs#json-schema-limitations
|
|
1455
|
+
const ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS = new Set([
|
|
1456
|
+
"minimum",
|
|
1457
|
+
"maximum",
|
|
1458
|
+
"exclusiveMinimum",
|
|
1459
|
+
"exclusiveMaximum",
|
|
1460
|
+
"multipleOf",
|
|
1461
|
+
"maxItems",
|
|
1462
|
+
"uniqueItems",
|
|
1463
|
+
"minContains",
|
|
1464
|
+
"maxContains",
|
|
1465
|
+
"minProperties",
|
|
1466
|
+
"maxProperties",
|
|
1467
|
+
]);
|
|
1468
|
+
const ANTHROPIC_STRICT_STRING_FORMATS = new Set([
|
|
1469
|
+
"date-time",
|
|
1470
|
+
"time",
|
|
1471
|
+
"date",
|
|
1472
|
+
"duration",
|
|
1473
|
+
"email",
|
|
1474
|
+
"hostname",
|
|
1475
|
+
"uri",
|
|
1476
|
+
"ipv4",
|
|
1477
|
+
"ipv6",
|
|
1478
|
+
"uuid",
|
|
1479
|
+
]);
|
|
1480
|
+
const isAnthropicStrictUnsupportedKeyword = (key, value) => {
|
|
1481
|
+
if (ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS.has(key))
|
|
1482
|
+
return true;
|
|
1483
|
+
if (key === "minItems")
|
|
1484
|
+
return value !== 0 && value !== 1;
|
|
1485
|
+
if (key === "format")
|
|
1486
|
+
return typeof value !== "string" || !ANTHROPIC_STRICT_STRING_FORMATS.has(value);
|
|
1487
|
+
return false;
|
|
1488
|
+
};
|
|
1489
|
+
function convertTools(tools, isOAuthToken, supportsEagerToolInputStreaming, supportsStrictTools, cacheControl, disablePreferredStrictTools = false) {
|
|
1490
|
+
if (!tools)
|
|
1491
|
+
return [];
|
|
1492
|
+
return tools.map((tool, index) => {
|
|
1493
|
+
const strict = disablePreferredStrictTools && prefersJsonSchemaStrictSampling(tool)
|
|
1494
|
+
? undefined
|
|
1495
|
+
: resolveJsonSchemaStrictSampling(tool, supportsStrictTools, isAnthropicStrictUnsupportedKeyword);
|
|
1496
|
+
const parameters = getJsonSchemaToolParameters(tool, strict);
|
|
1497
|
+
const schema = parameters;
|
|
1498
|
+
// Keep shared definitions so property $refs still resolve, and additionalProperties so the
|
|
1499
|
+
// model knows whether extra arguments are allowed. Other root keywords stay out:
|
|
1500
|
+
// Anthropic rejects root anyOf/oneOf/allOf with a 400.
|
|
1501
|
+
const legacyInputSchema = {
|
|
1502
|
+
type: "object",
|
|
1503
|
+
properties: schema.properties ?? {},
|
|
1504
|
+
required: schema.required ?? [],
|
|
1505
|
+
...(schema.additionalProperties === undefined ? {} : { additionalProperties: schema.additionalProperties }),
|
|
1506
|
+
...(schema.$defs === undefined ? {} : { $defs: schema.$defs }),
|
|
1507
|
+
...(schema.definitions === undefined ? {} : { definitions: schema.definitions }),
|
|
1508
|
+
};
|
|
1509
|
+
const inputSchema = strict === true
|
|
1510
|
+
? {
|
|
1511
|
+
...parameters,
|
|
1512
|
+
...legacyInputSchema,
|
|
1513
|
+
}
|
|
1514
|
+
: legacyInputSchema;
|
|
1515
|
+
return {
|
|
1516
|
+
name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name,
|
|
1517
|
+
description: tool.description,
|
|
1518
|
+
...(supportsEagerToolInputStreaming ? { eager_input_streaming: true } : {}),
|
|
1519
|
+
...(strict === true ? { strict: true } : {}),
|
|
1520
|
+
input_schema: inputSchema,
|
|
1521
|
+
...(cacheControl && index === tools.length - 1 ? { cache_control: cacheControl } : {}),
|
|
1522
|
+
};
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
function mapStopReason(reason, stopDetails) {
|
|
1526
|
+
switch (reason) {
|
|
1527
|
+
case "end_turn":
|
|
1528
|
+
return { stopReason: "stop" };
|
|
1529
|
+
case "max_tokens":
|
|
1530
|
+
return { stopReason: "length" };
|
|
1531
|
+
case "tool_use":
|
|
1532
|
+
return { stopReason: "toolUse" };
|
|
1533
|
+
case "refusal":
|
|
1534
|
+
return {
|
|
1535
|
+
stopReason: "error",
|
|
1536
|
+
errorMessage: stopDetails?.explanation || `The model refused to complete the request`,
|
|
1537
|
+
};
|
|
1538
|
+
case "pause_turn": // Stop is good enough -> resubmit
|
|
1539
|
+
return { stopReason: "stop" };
|
|
1540
|
+
case "stop_sequence":
|
|
1541
|
+
return { stopReason: "stop" }; // We don't supply stop sequences, so this should never happen
|
|
1542
|
+
case "sensitive": // Content flagged by safety filters (not yet in SDK types)
|
|
1543
|
+
return { stopReason: "error", errorMessage: "Provider stopped with: sensitive" };
|
|
1544
|
+
default:
|
|
1545
|
+
// Handle unknown stop reasons gracefully (API may add new values)
|
|
1546
|
+
throw new Error(`Unhandled stop reason: ${reason}`);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
//# sourceMappingURL=anthropic-messages.js.map
|