@panticonic/pi-ai 0.99.2-vibestudio.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 +21 -0
- package/README.md +1938 -0
- package/SOURCE.json +8858 -0
- 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 +1309 -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-responses.d.ts +17 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.js +262 -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 +1093 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +9 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +30 -0
- package/dist/api/bedrock-converse-stream.lazy.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 +43 -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 +26 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +233 -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 +370 -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 +451 -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 +431 -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 +19 -0
- package/dist/api/lazy.d.ts.map +1 -0
- package/dist/api/lazy.js +70 -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 +365 -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 +749 -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 +32 -0
- package/dist/api/openai-codex-responses.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.js +1374 -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 +26 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1380 -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-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 +29 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +703 -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 +310 -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 +133 -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 +99 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +314 -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 +15 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +66 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +23 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +183 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +8 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +201 -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 +19 -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 +249 -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 +392 -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 +248 -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 +69 -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 +190 -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 +266 -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 +253 -0
- package/dist/auth/oauth/radius.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 +21 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +116 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +240 -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/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +115 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +39 -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 +163 -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 +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.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 +269 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +175 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +177 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +721 -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 +137 -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-openai-responses.d.ts +3 -0
- package/dist/providers/azure-openai-responses.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.js +14 -0
- package/dist/providers/azure-openai-responses.js.map +1 -0
- package/dist/providers/azure-openai-responses.models.d.ts +6 -0
- package/dist/providers/azure-openai-responses.models.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.models.js +8 -0
- package/dist/providers/azure-openai-responses.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/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-openai-responses.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.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 +489 -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 +3 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +35 -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/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 +24 -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 +3 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +21 -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.d.ts +3 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +36 -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 +15 -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.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +15 -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 +15 -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 +63 -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 +78 -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/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/types.d.ts +982 -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/assistant-message-frame.d.ts +82 -0
- package/dist/utils/assistant-message-frame.d.ts.map +1 -0
- package/dist/utils/assistant-message-frame.js +430 -0
- package/dist/utils/assistant-message-frame.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 +25 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +133 -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 +21 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +99 -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/json-parse.d.ts +16 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +113 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +11 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +47 -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/overflow.d.ts +69 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +179 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +12 -0
- package/dist/utils/pi-user-agent.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 +16 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +95 -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 +190 -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/text.d.ts +14 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +36 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/transcript.d.ts +84 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +204 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils/typebox-helpers.d.ts +17 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -0
- package/dist/utils/typebox-helpers.js +21 -0
- package/dist/utils/typebox-helpers.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 +18 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +309 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,1309 @@
|
|
|
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 { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
|
|
5
|
+
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
6
|
+
import { headersToRecord } from "../utils/headers.js";
|
|
7
|
+
import { parseJsonWithRepair, parseStreamingJson } from "../utils/json-parse.js";
|
|
8
|
+
import { getPiUserAgent } from "../utils/pi-user-agent.js";
|
|
9
|
+
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
10
|
+
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
11
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
12
|
+
import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.js";
|
|
13
|
+
import { getCurrentTools, getDeclaredTools, getInitialSystemMessage, hasToolRedefinitions, resolveTranscript, } from "../utils/transcript.js";
|
|
14
|
+
import { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
15
|
+
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
16
|
+
import { adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToContext } from "./simple-options.js";
|
|
17
|
+
import { transformMessages } from "./transform-messages.js";
|
|
18
|
+
/**
|
|
19
|
+
* Resolve cache retention preference.
|
|
20
|
+
* Defaults to "short" and uses PI_CACHE_RETENTION for backward compatibility.
|
|
21
|
+
*/
|
|
22
|
+
function resolveCacheRetention(cacheRetention, env) {
|
|
23
|
+
if (cacheRetention) {
|
|
24
|
+
return cacheRetention;
|
|
25
|
+
}
|
|
26
|
+
if (getProviderEnvValue("PI_CACHE_RETENTION", env) === "long") {
|
|
27
|
+
return "long";
|
|
28
|
+
}
|
|
29
|
+
return "short";
|
|
30
|
+
}
|
|
31
|
+
function getCacheControl(model, cacheRetention, env) {
|
|
32
|
+
const retention = resolveCacheRetention(cacheRetention, env);
|
|
33
|
+
if (retention === "none") {
|
|
34
|
+
return { retention };
|
|
35
|
+
}
|
|
36
|
+
const ttl = retention === "long" && getAnthropicCompat(model).supportsLongCacheRetention ? "1h" : undefined;
|
|
37
|
+
return {
|
|
38
|
+
retention,
|
|
39
|
+
cacheControl: { type: "ephemeral", ...(ttl && { ttl }) },
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Stealth mode: Mimic Claude Code's tool naming exactly
|
|
43
|
+
const claudeCodeVersion = "2.1.280";
|
|
44
|
+
// Claude Code 2.x tool names (canonical casing)
|
|
45
|
+
// Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
|
|
46
|
+
// To update: https://github.com/badlogic/cchistory
|
|
47
|
+
const claudeCodeTools = [
|
|
48
|
+
"Read",
|
|
49
|
+
"Write",
|
|
50
|
+
"Edit",
|
|
51
|
+
"Bash",
|
|
52
|
+
"Grep",
|
|
53
|
+
"Glob",
|
|
54
|
+
"AskUserQuestion",
|
|
55
|
+
"EnterPlanMode",
|
|
56
|
+
"ExitPlanMode",
|
|
57
|
+
"KillShell",
|
|
58
|
+
"NotebookEdit",
|
|
59
|
+
"Skill",
|
|
60
|
+
"Task",
|
|
61
|
+
"TaskOutput",
|
|
62
|
+
"TodoWrite",
|
|
63
|
+
"WebFetch",
|
|
64
|
+
"WebSearch",
|
|
65
|
+
];
|
|
66
|
+
const ccToolLookup = new Map(claudeCodeTools.map((t) => [t.toLowerCase(), t]));
|
|
67
|
+
// Convert tool name to CC canonical casing if it matches (case-insensitive)
|
|
68
|
+
const toClaudeCodeName = (name) => ccToolLookup.get(name.toLowerCase()) ?? name;
|
|
69
|
+
const fromClaudeCodeName = (name, tools) => {
|
|
70
|
+
if (tools && tools.length > 0) {
|
|
71
|
+
const lowerName = name.toLowerCase();
|
|
72
|
+
const matchedTool = tools.find((tool) => tool.name.toLowerCase() === lowerName);
|
|
73
|
+
if (matchedTool)
|
|
74
|
+
return matchedTool.name;
|
|
75
|
+
}
|
|
76
|
+
return name;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Convert content blocks to Anthropic API format
|
|
80
|
+
*/
|
|
81
|
+
function convertContentBlocks(content) {
|
|
82
|
+
// If only text blocks, return as concatenated string for simplicity
|
|
83
|
+
const hasImages = content.some((c) => c.type === "image");
|
|
84
|
+
if (!hasImages) {
|
|
85
|
+
return sanitizeSurrogates(content.map((c) => c.text).join("\n"));
|
|
86
|
+
}
|
|
87
|
+
// If we have images, convert to content block array
|
|
88
|
+
const blocks = content.map((block) => {
|
|
89
|
+
if (block.type === "text") {
|
|
90
|
+
return {
|
|
91
|
+
type: "text",
|
|
92
|
+
text: sanitizeSurrogates(block.text),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
type: "image",
|
|
97
|
+
source: {
|
|
98
|
+
type: "base64",
|
|
99
|
+
media_type: block.mimeType,
|
|
100
|
+
data: block.data,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
// If only images (no text), add placeholder text block
|
|
105
|
+
const hasText = blocks.some((b) => b.type === "text");
|
|
106
|
+
if (!hasText) {
|
|
107
|
+
blocks.unshift({
|
|
108
|
+
type: "text",
|
|
109
|
+
text: "(see attached image)",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return blocks;
|
|
113
|
+
}
|
|
114
|
+
const FINE_GRAINED_TOOL_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14";
|
|
115
|
+
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
116
|
+
const SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
117
|
+
const MID_CONVERSATION_OUTPUT_CONFIG_BETA = "mid-conversation-output-config-2026-07-01";
|
|
118
|
+
const THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
119
|
+
const MID_CONVERSATION_TOOL_CHANGES_BETA = "mid-conversation-tool-changes-2026-07-01";
|
|
120
|
+
/**
|
|
121
|
+
* Stable deferred tool declared whenever native tool changes are in use. Anthropic adds
|
|
122
|
+
* hidden prompt scaffolding as soon as any tool has `defer_loading`; declaring this
|
|
123
|
+
* placeholder from the first request keeps that scaffolding in the cached prefix, so the
|
|
124
|
+
* first real late tool does not invalidate the cache (measured: full miss without it).
|
|
125
|
+
* It is never activated and the model cannot see it.
|
|
126
|
+
*/
|
|
127
|
+
const DEFERRED_TOOL_PLACEHOLDER = {
|
|
128
|
+
name: "__pi_deferred_placeholder__",
|
|
129
|
+
description: "Reserved placeholder. Never available. Never call this.",
|
|
130
|
+
input_schema: { type: "object", properties: {}, required: [] },
|
|
131
|
+
defer_loading: true,
|
|
132
|
+
};
|
|
133
|
+
function shouldUseServerSideFallbackBeta(model) {
|
|
134
|
+
return (model.compat?.allowedFallbackModels?.length ?? 0) > 0;
|
|
135
|
+
}
|
|
136
|
+
function getAnthropicCompat(model) {
|
|
137
|
+
const isOpenRouter = model.provider === "openrouter" || model.baseUrl.includes("openrouter.ai");
|
|
138
|
+
return {
|
|
139
|
+
supportsEagerToolInputStreaming: model.compat?.supportsEagerToolInputStreaming ?? true,
|
|
140
|
+
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
|
|
141
|
+
sendSessionAffinityHeaders: model.compat?.sendSessionAffinityHeaders ?? isOpenRouter,
|
|
142
|
+
sessionAffinityFormat: model.compat?.sessionAffinityFormat ?? (isOpenRouter ? "openrouter" : undefined),
|
|
143
|
+
supportsCacheControlOnTools: model.compat?.supportsCacheControlOnTools ?? true,
|
|
144
|
+
supportsTemperature: model.compat?.supportsTemperature ?? true,
|
|
145
|
+
allowEmptySignature: model.compat?.allowEmptySignature ?? false,
|
|
146
|
+
supportsStrictTools: model.compat?.supportsStrictTools ?? false,
|
|
147
|
+
supportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,
|
|
148
|
+
supportsMidConvoToolChanges: model.compat?.supportsMidConvoToolChanges ?? false,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function mergeHeaders(...headerSources) {
|
|
152
|
+
const merged = {};
|
|
153
|
+
for (const headers of headerSources) {
|
|
154
|
+
if (headers) {
|
|
155
|
+
Object.assign(merged, headers);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return merged;
|
|
159
|
+
}
|
|
160
|
+
function mergeClientHeaders(...headerSources) {
|
|
161
|
+
return mergeHeaders({ "User-Agent": getPiUserAgent() }, ...headerSources);
|
|
162
|
+
}
|
|
163
|
+
function hasHeader(headers, name) {
|
|
164
|
+
if (!headers)
|
|
165
|
+
return false;
|
|
166
|
+
const expected = name.toLowerCase();
|
|
167
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
168
|
+
if (key.toLowerCase() === expected && value !== null && value.trim().length > 0)
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
function hasRequestAuth(apiKey, headers) {
|
|
174
|
+
return (!!apiKey ||
|
|
175
|
+
hasHeader(headers, "authorization") ||
|
|
176
|
+
hasHeader(headers, "x-api-key") ||
|
|
177
|
+
hasHeader(headers, "cf-aig-authorization"));
|
|
178
|
+
}
|
|
179
|
+
function assertRequestAuth(provider, apiKey, headers) {
|
|
180
|
+
if (!hasRequestAuth(apiKey, headers))
|
|
181
|
+
throw new Error(`No API key for provider: ${provider}`);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Anthropic SDK client that never runs the SDK's own credential chain
|
|
185
|
+
* (ANTHROPIC_PROFILE config files, federation env vars). Without this, every
|
|
186
|
+
* client built with `apiKey: null, authToken: null` for header-owned auth would
|
|
187
|
+
* also resolve and exchange SDK credentials behind pi's auth resolver.
|
|
188
|
+
*/
|
|
189
|
+
class PiAnthropic extends Anthropic {
|
|
190
|
+
_shouldResolveDefaultCredentials() {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Workload identity federation config from the ANTHROPIC_* variables the
|
|
196
|
+
* Anthropic SDK documents; the SDK performs the token exchange and refresh.
|
|
197
|
+
* Only for the anthropic provider, since the exchange is an Anthropic API
|
|
198
|
+
* endpoint, and only when no key or auth header was resolved.
|
|
199
|
+
*/
|
|
200
|
+
function getAnthropicFederation(model, apiKey, headers, env) {
|
|
201
|
+
if (model.provider !== "anthropic" || hasRequestAuth(apiKey, headers))
|
|
202
|
+
return undefined;
|
|
203
|
+
const federationRuleId = getProviderEnvValue(ANTHROPIC_FEDERATION_RULE_ID_ENV, env);
|
|
204
|
+
const organizationId = getProviderEnvValue(ANTHROPIC_ORGANIZATION_ID_ENV, env);
|
|
205
|
+
const identityTokenFile = getProviderEnvValue(ANTHROPIC_IDENTITY_TOKEN_FILE_ENV, env);
|
|
206
|
+
if (!federationRuleId || !organizationId || !identityTokenFile)
|
|
207
|
+
return undefined;
|
|
208
|
+
return {
|
|
209
|
+
organization_id: organizationId,
|
|
210
|
+
workspace_id: getProviderEnvValue(ANTHROPIC_WORKSPACE_ID_ENV, env),
|
|
211
|
+
authentication: {
|
|
212
|
+
type: "oidc_federation",
|
|
213
|
+
federation_rule_id: federationRuleId,
|
|
214
|
+
service_account_id: getProviderEnvValue(ANTHROPIC_SERVICE_ACCOUNT_ID_ENV, env),
|
|
215
|
+
identity_token: { source: "file", path: identityTokenFile },
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The SDK caches the federated access token per client, but pi creates a client
|
|
221
|
+
* per request. Keep one client for the current federation config and fetch, and
|
|
222
|
+
* clone it per request with `withOptions()`, which shares the token cache.
|
|
223
|
+
*/
|
|
224
|
+
let federationClient;
|
|
225
|
+
const ANTHROPIC_MESSAGE_EVENTS = new Set([
|
|
226
|
+
"message_start",
|
|
227
|
+
"message_delta",
|
|
228
|
+
"message_stop",
|
|
229
|
+
"content_block_start",
|
|
230
|
+
"content_block_delta",
|
|
231
|
+
"content_block_stop",
|
|
232
|
+
]);
|
|
233
|
+
function flushSseEvent(state) {
|
|
234
|
+
if (!state.event && state.data.length === 0) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const event = {
|
|
238
|
+
event: state.event,
|
|
239
|
+
data: state.data.join("\n"),
|
|
240
|
+
raw: [...state.raw],
|
|
241
|
+
};
|
|
242
|
+
state.event = null;
|
|
243
|
+
state.data = [];
|
|
244
|
+
state.raw = [];
|
|
245
|
+
return event;
|
|
246
|
+
}
|
|
247
|
+
function decodeSseLine(line, state) {
|
|
248
|
+
if (line === "") {
|
|
249
|
+
return flushSseEvent(state);
|
|
250
|
+
}
|
|
251
|
+
state.raw.push(line);
|
|
252
|
+
if (line.startsWith(":")) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
const delimiterIndex = line.indexOf(":");
|
|
256
|
+
const fieldName = delimiterIndex === -1 ? line : line.slice(0, delimiterIndex);
|
|
257
|
+
let value = delimiterIndex === -1 ? "" : line.slice(delimiterIndex + 1);
|
|
258
|
+
if (value.startsWith(" ")) {
|
|
259
|
+
value = value.slice(1);
|
|
260
|
+
}
|
|
261
|
+
if (fieldName === "event") {
|
|
262
|
+
state.event = value;
|
|
263
|
+
}
|
|
264
|
+
else if (fieldName === "data") {
|
|
265
|
+
state.data.push(value);
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
function nextLineBreakIndex(text) {
|
|
270
|
+
const carriageReturnIndex = text.indexOf("\r");
|
|
271
|
+
const newlineIndex = text.indexOf("\n");
|
|
272
|
+
if (carriageReturnIndex === -1) {
|
|
273
|
+
return newlineIndex;
|
|
274
|
+
}
|
|
275
|
+
if (newlineIndex === -1) {
|
|
276
|
+
return carriageReturnIndex;
|
|
277
|
+
}
|
|
278
|
+
return Math.min(carriageReturnIndex, newlineIndex);
|
|
279
|
+
}
|
|
280
|
+
function consumeLine(text) {
|
|
281
|
+
const lineBreakIndex = nextLineBreakIndex(text);
|
|
282
|
+
if (lineBreakIndex === -1) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
let nextIndex = lineBreakIndex + 1;
|
|
286
|
+
if (text[lineBreakIndex] === "\r" && text[nextIndex] === "\n") {
|
|
287
|
+
nextIndex += 1;
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
line: text.slice(0, lineBreakIndex),
|
|
291
|
+
rest: text.slice(nextIndex),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
async function* iterateSseMessages(body, signal) {
|
|
295
|
+
const reader = body.getReader();
|
|
296
|
+
const decoder = new TextDecoder();
|
|
297
|
+
const state = { event: null, data: [], raw: [] };
|
|
298
|
+
let buffer = "";
|
|
299
|
+
try {
|
|
300
|
+
while (true) {
|
|
301
|
+
if (signal?.aborted) {
|
|
302
|
+
throw new Error("Request was aborted");
|
|
303
|
+
}
|
|
304
|
+
const { value, done } = await reader.read();
|
|
305
|
+
if (done) {
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
buffer += decoder.decode(value, { stream: true });
|
|
309
|
+
let consumed = consumeLine(buffer);
|
|
310
|
+
while (consumed) {
|
|
311
|
+
buffer = consumed.rest;
|
|
312
|
+
const event = decodeSseLine(consumed.line, state);
|
|
313
|
+
if (event) {
|
|
314
|
+
yield event;
|
|
315
|
+
}
|
|
316
|
+
consumed = consumeLine(buffer);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
buffer += decoder.decode();
|
|
320
|
+
let consumed = consumeLine(buffer);
|
|
321
|
+
while (consumed) {
|
|
322
|
+
buffer = consumed.rest;
|
|
323
|
+
const event = decodeSseLine(consumed.line, state);
|
|
324
|
+
if (event) {
|
|
325
|
+
yield event;
|
|
326
|
+
}
|
|
327
|
+
consumed = consumeLine(buffer);
|
|
328
|
+
}
|
|
329
|
+
if (buffer.length > 0) {
|
|
330
|
+
const event = decodeSseLine(buffer, state);
|
|
331
|
+
if (event) {
|
|
332
|
+
yield event;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const trailingEvent = flushSseEvent(state);
|
|
336
|
+
if (trailingEvent) {
|
|
337
|
+
yield trailingEvent;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
finally {
|
|
341
|
+
reader.releaseLock();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async function* iterateAnthropicEvents(response, signal) {
|
|
345
|
+
if (!response.body) {
|
|
346
|
+
throw new Error("Attempted to iterate over an Anthropic response with no body");
|
|
347
|
+
}
|
|
348
|
+
let sawMessageStart = false;
|
|
349
|
+
let sawMessageEnd = false;
|
|
350
|
+
for await (const sse of iterateSseMessages(response.body, signal)) {
|
|
351
|
+
if (sse.event === "error") {
|
|
352
|
+
throw new Error(sse.data);
|
|
353
|
+
}
|
|
354
|
+
if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
const event = parseJsonWithRepair(sse.data);
|
|
359
|
+
if (event.type === "message_start") {
|
|
360
|
+
sawMessageStart = true;
|
|
361
|
+
}
|
|
362
|
+
else if (event.type === "message_stop") {
|
|
363
|
+
sawMessageEnd = true;
|
|
364
|
+
}
|
|
365
|
+
yield event;
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
369
|
+
throw new Error(`Could not parse Anthropic SSE event ${sse.event}: ${message}; data=${sse.data}; raw=${sse.raw.join("\\n")}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (sawMessageStart && !sawMessageEnd) {
|
|
373
|
+
throw new Error("Anthropic stream ended before message_stop");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
export const stream = (model, context, options) => {
|
|
377
|
+
const stream = new AssistantMessageEventStream();
|
|
378
|
+
const normalizedContext = resolveTranscript(context, getAnthropicCompat(model).supportsMidConvoSystemMessages);
|
|
379
|
+
const currentTools = getCurrentTools(normalizedContext.messages);
|
|
380
|
+
(async () => {
|
|
381
|
+
const providerThinkingLevel = model.compat?.supportsMidConvoEffort ? (options?.effort ?? "high") : undefined;
|
|
382
|
+
const output = {
|
|
383
|
+
role: "assistant",
|
|
384
|
+
content: [],
|
|
385
|
+
api: model.api,
|
|
386
|
+
provider: model.provider,
|
|
387
|
+
model: model.id,
|
|
388
|
+
...(providerThinkingLevel === undefined ? {} : { providerThinkingLevel }),
|
|
389
|
+
usage: {
|
|
390
|
+
input: 0,
|
|
391
|
+
output: 0,
|
|
392
|
+
cacheRead: 0,
|
|
393
|
+
cacheWrite: 0,
|
|
394
|
+
totalTokens: 0,
|
|
395
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
396
|
+
},
|
|
397
|
+
stopReason: "pending",
|
|
398
|
+
timestamp: Date.now(),
|
|
399
|
+
};
|
|
400
|
+
try {
|
|
401
|
+
let client;
|
|
402
|
+
let isOAuth;
|
|
403
|
+
let usageModel = model;
|
|
404
|
+
let inputTransformations;
|
|
405
|
+
if (options?.client) {
|
|
406
|
+
client = options.client;
|
|
407
|
+
isOAuth = false;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
const apiKey = options?.apiKey;
|
|
411
|
+
const federation = getAnthropicFederation(model, apiKey, options?.headers, options?.env);
|
|
412
|
+
if (!federation)
|
|
413
|
+
assertRequestAuth(model.provider, apiKey, options?.headers);
|
|
414
|
+
let copilotDynamicHeaders;
|
|
415
|
+
if (model.provider === "github-copilot") {
|
|
416
|
+
const hasImages = hasCopilotVisionInput(normalizedContext.messages);
|
|
417
|
+
copilotDynamicHeaders = buildCopilotDynamicHeaders({
|
|
418
|
+
messages: normalizedContext.messages,
|
|
419
|
+
hasImages,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
423
|
+
const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
|
|
424
|
+
const created = createClient(model, apiKey, options?.headers, options?.fetch, copilotDynamicHeaders, cacheSessionId, federation, options?.authType);
|
|
425
|
+
client = created.client;
|
|
426
|
+
isOAuth = created.isOAuthToken;
|
|
427
|
+
}
|
|
428
|
+
let params = buildParams(model, normalizedContext, isOAuth, options);
|
|
429
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
430
|
+
if (nextParams !== undefined) {
|
|
431
|
+
params = { ...nextParams, stream: true };
|
|
432
|
+
}
|
|
433
|
+
const requestOptions = {
|
|
434
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
435
|
+
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
|
|
436
|
+
maxRetries: 0,
|
|
437
|
+
};
|
|
438
|
+
const response = await retryProviderRequest(() => client.beta.messages.create(params, requestOptions).asResponse(), {
|
|
439
|
+
maxRetries: options?.maxRetries,
|
|
440
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
441
|
+
signal: options?.signal,
|
|
442
|
+
});
|
|
443
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
444
|
+
stream.push({ type: "start", partial: output });
|
|
445
|
+
const blocks = output.content;
|
|
446
|
+
for await (const event of iterateAnthropicEvents(response, options?.signal)) {
|
|
447
|
+
await options?.onProviderStreamEvent?.(event, model);
|
|
448
|
+
if (event.type === "message_start") {
|
|
449
|
+
output.responseId = event.message.id;
|
|
450
|
+
const transformations = event.message.input_transformations;
|
|
451
|
+
if (Array.isArray(transformations))
|
|
452
|
+
inputTransformations = transformations;
|
|
453
|
+
const responseModel = event.message.model;
|
|
454
|
+
if (responseModel !== model.id)
|
|
455
|
+
output.responseModel = responseModel;
|
|
456
|
+
const fallbackCost = responseModel === model.id
|
|
457
|
+
? undefined
|
|
458
|
+
: model.compat?.allowedFallbackModels?.find((fallback) => fallback.provider === model.provider && fallback.model === responseModel)?.cost;
|
|
459
|
+
usageModel = fallbackCost ? { ...model, id: responseModel, cost: fallbackCost } : model;
|
|
460
|
+
// Capture initial token usage from message_start event
|
|
461
|
+
// This ensures we have input token counts even if the stream is aborted early
|
|
462
|
+
output.usage.input = event.message.usage.input_tokens || 0;
|
|
463
|
+
output.usage.output = event.message.usage.output_tokens || 0;
|
|
464
|
+
output.usage.cacheRead = event.message.usage.cache_read_input_tokens || 0;
|
|
465
|
+
output.usage.cacheWrite = event.message.usage.cache_creation_input_tokens || 0;
|
|
466
|
+
output.usage.cacheWrite1h = event.message.usage.cache_creation?.ephemeral_1h_input_tokens || 0;
|
|
467
|
+
// Anthropic doesn't provide total_tokens, compute from components
|
|
468
|
+
output.usage.totalTokens =
|
|
469
|
+
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
470
|
+
calculateCost(usageModel, output.usage);
|
|
471
|
+
}
|
|
472
|
+
else if (event.type === "content_block_start") {
|
|
473
|
+
if (event.content_block.type === "fallback") {
|
|
474
|
+
if (output.content.length > 0) {
|
|
475
|
+
throw new Error("Anthropic performed an unsupported mid-output model fallback");
|
|
476
|
+
}
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (event.content_block.type === "text") {
|
|
480
|
+
const block = {
|
|
481
|
+
type: "text",
|
|
482
|
+
text: event.content_block.text ?? "",
|
|
483
|
+
index: event.index,
|
|
484
|
+
};
|
|
485
|
+
output.content.push(block);
|
|
486
|
+
stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
|
|
487
|
+
}
|
|
488
|
+
else if (event.content_block.type === "thinking") {
|
|
489
|
+
const block = {
|
|
490
|
+
type: "thinking",
|
|
491
|
+
thinking: event.content_block.thinking ?? "",
|
|
492
|
+
thinkingSignature: event.content_block.signature ?? "",
|
|
493
|
+
index: event.index,
|
|
494
|
+
};
|
|
495
|
+
output.content.push(block);
|
|
496
|
+
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
|
|
497
|
+
}
|
|
498
|
+
else if (event.content_block.type === "redacted_thinking") {
|
|
499
|
+
const block = {
|
|
500
|
+
type: "thinking",
|
|
501
|
+
thinking: "[Reasoning redacted]",
|
|
502
|
+
thinkingSignature: event.content_block.data,
|
|
503
|
+
redacted: true,
|
|
504
|
+
index: event.index,
|
|
505
|
+
};
|
|
506
|
+
output.content.push(block);
|
|
507
|
+
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
|
|
508
|
+
}
|
|
509
|
+
else if (event.content_block.type === "tool_use") {
|
|
510
|
+
const block = {
|
|
511
|
+
type: "toolCall",
|
|
512
|
+
id: event.content_block.id,
|
|
513
|
+
name: isOAuth
|
|
514
|
+
? fromClaudeCodeName(event.content_block.name, currentTools)
|
|
515
|
+
: event.content_block.name,
|
|
516
|
+
arguments: event.content_block.input ?? {},
|
|
517
|
+
partialJson: "",
|
|
518
|
+
index: event.index,
|
|
519
|
+
};
|
|
520
|
+
output.content.push(block);
|
|
521
|
+
stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else if (event.type === "content_block_delta") {
|
|
525
|
+
if (event.delta.type === "text_delta") {
|
|
526
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
527
|
+
const block = blocks[index];
|
|
528
|
+
if (block && block.type === "text") {
|
|
529
|
+
block.text += event.delta.text;
|
|
530
|
+
stream.push({
|
|
531
|
+
type: "text_delta",
|
|
532
|
+
contentIndex: index,
|
|
533
|
+
delta: event.delta.text,
|
|
534
|
+
partial: output,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
else if (event.delta.type === "thinking_delta") {
|
|
539
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
540
|
+
const block = blocks[index];
|
|
541
|
+
if (block && block.type === "thinking") {
|
|
542
|
+
block.thinking += event.delta.thinking;
|
|
543
|
+
stream.push({
|
|
544
|
+
type: "thinking_delta",
|
|
545
|
+
contentIndex: index,
|
|
546
|
+
delta: event.delta.thinking,
|
|
547
|
+
partial: output,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
else if (event.delta.type === "input_json_delta") {
|
|
552
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
553
|
+
const block = blocks[index];
|
|
554
|
+
if (block && block.type === "toolCall") {
|
|
555
|
+
block.partialJson += event.delta.partial_json;
|
|
556
|
+
block.arguments = parseStreamingJson(block.partialJson);
|
|
557
|
+
stream.push({
|
|
558
|
+
type: "toolcall_delta",
|
|
559
|
+
contentIndex: index,
|
|
560
|
+
delta: event.delta.partial_json,
|
|
561
|
+
partial: output,
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
else if (event.delta.type === "signature_delta") {
|
|
566
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
567
|
+
const block = blocks[index];
|
|
568
|
+
if (block && block.type === "thinking") {
|
|
569
|
+
block.thinkingSignature = block.thinkingSignature || "";
|
|
570
|
+
block.thinkingSignature += event.delta.signature;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
else if (event.type === "content_block_stop") {
|
|
575
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
576
|
+
const block = blocks[index];
|
|
577
|
+
if (block) {
|
|
578
|
+
delete block.index;
|
|
579
|
+
if (block.type === "text") {
|
|
580
|
+
stream.push({
|
|
581
|
+
type: "text_end",
|
|
582
|
+
contentIndex: index,
|
|
583
|
+
content: block.text,
|
|
584
|
+
partial: output,
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
else if (block.type === "thinking") {
|
|
588
|
+
stream.push({
|
|
589
|
+
type: "thinking_end",
|
|
590
|
+
contentIndex: index,
|
|
591
|
+
content: block.thinking,
|
|
592
|
+
partial: output,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
else if (block.type === "toolCall") {
|
|
596
|
+
block.arguments = parseStreamingJson(block.partialJson);
|
|
597
|
+
// Finalize in-place and strip the scratch buffer so replay only
|
|
598
|
+
// carries parsed arguments.
|
|
599
|
+
delete block.partialJson;
|
|
600
|
+
stream.push({
|
|
601
|
+
type: "toolcall_end",
|
|
602
|
+
contentIndex: index,
|
|
603
|
+
toolCall: block,
|
|
604
|
+
partial: output,
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else if (event.type === "message_delta") {
|
|
610
|
+
const transformations = event.input_transformations;
|
|
611
|
+
if (Array.isArray(transformations))
|
|
612
|
+
inputTransformations = transformations;
|
|
613
|
+
if (event.delta.stop_reason) {
|
|
614
|
+
output.rawStopReason = event.delta.stop_reason;
|
|
615
|
+
const stopReasonResult = mapStopReason(event.delta.stop_reason, event.delta.stop_details);
|
|
616
|
+
output.stopReason = stopReasonResult.stopReason;
|
|
617
|
+
if (stopReasonResult.errorMessage) {
|
|
618
|
+
output.errorMessage = stopReasonResult.errorMessage;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
// Only update usage fields if present (not null).
|
|
622
|
+
// Preserves input_tokens from message_start when proxies omit it in message_delta.
|
|
623
|
+
if (event.usage) {
|
|
624
|
+
if (event.usage.input_tokens != null) {
|
|
625
|
+
output.usage.input = event.usage.input_tokens;
|
|
626
|
+
}
|
|
627
|
+
if (event.usage.output_tokens != null) {
|
|
628
|
+
output.usage.output = event.usage.output_tokens;
|
|
629
|
+
}
|
|
630
|
+
if (event.usage.cache_read_input_tokens != null) {
|
|
631
|
+
output.usage.cacheRead = event.usage.cache_read_input_tokens;
|
|
632
|
+
}
|
|
633
|
+
if (event.usage.cache_creation_input_tokens != null) {
|
|
634
|
+
output.usage.cacheWrite = event.usage.cache_creation_input_tokens;
|
|
635
|
+
}
|
|
636
|
+
// Vercel AI Gateway includes the TTL breakdown in deltas, though the SDK only types it on message_start.
|
|
637
|
+
const cacheCreation = event.usage.cache_creation;
|
|
638
|
+
if (cacheCreation?.ephemeral_1h_input_tokens != null) {
|
|
639
|
+
output.usage.cacheWrite1h = cacheCreation.ephemeral_1h_input_tokens;
|
|
640
|
+
}
|
|
641
|
+
// Anthropic reports reasoning tokens as a subset of output tokens.
|
|
642
|
+
const thinkingTokens = event.usage.output_tokens_details?.thinking_tokens;
|
|
643
|
+
if (thinkingTokens != null) {
|
|
644
|
+
output.usage.reasoning = thinkingTokens;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
// Anthropic doesn't provide total_tokens, compute from components
|
|
648
|
+
output.usage.totalTokens =
|
|
649
|
+
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
650
|
+
calculateCost(usageModel, output.usage);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (options?.signal?.aborted) {
|
|
654
|
+
throw new Error("Request was aborted");
|
|
655
|
+
}
|
|
656
|
+
if (output.stopReason === "pending") {
|
|
657
|
+
throw new Error("Anthropic stream ended without a stop reason");
|
|
658
|
+
}
|
|
659
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
660
|
+
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
661
|
+
}
|
|
662
|
+
if (inputTransformations && inputTransformations.length > 0) {
|
|
663
|
+
appendAssistantMessageDiagnostic(output, {
|
|
664
|
+
type: "anthropic_input_transformations",
|
|
665
|
+
timestamp: Date.now(),
|
|
666
|
+
details: {
|
|
667
|
+
transformations: inputTransformations.map((transformation) => ({
|
|
668
|
+
type: transformation.type ?? undefined,
|
|
669
|
+
path: transformation.path ?? undefined,
|
|
670
|
+
reason: transformation.reason ?? undefined,
|
|
671
|
+
})),
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
676
|
+
stream.end();
|
|
677
|
+
}
|
|
678
|
+
catch (error) {
|
|
679
|
+
for (const block of output.content) {
|
|
680
|
+
delete block.index;
|
|
681
|
+
// partialJson is only a streaming scratch buffer; never persist it.
|
|
682
|
+
delete block.partialJson;
|
|
683
|
+
}
|
|
684
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
685
|
+
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
686
|
+
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
687
|
+
stream.end();
|
|
688
|
+
}
|
|
689
|
+
})();
|
|
690
|
+
return stream;
|
|
691
|
+
};
|
|
692
|
+
/**
|
|
693
|
+
* Map ThinkingLevel to Anthropic effort levels for adaptive thinking.
|
|
694
|
+
* Note: effort "max" is available on all adaptive-thinking Claude models, while native
|
|
695
|
+
* "xhigh" is only available on Opus 4.7/4.8, Sonnet 5, and Fable 5.
|
|
696
|
+
*/
|
|
697
|
+
function mapThinkingLevelToEffort(model, level) {
|
|
698
|
+
const mapped = level ? model.thinkingLevelMap?.[level] : undefined;
|
|
699
|
+
if (typeof mapped === "string")
|
|
700
|
+
return mapped;
|
|
701
|
+
switch (level) {
|
|
702
|
+
case "minimal":
|
|
703
|
+
case "low":
|
|
704
|
+
return "low";
|
|
705
|
+
case "medium":
|
|
706
|
+
return "medium";
|
|
707
|
+
case "high":
|
|
708
|
+
return "high";
|
|
709
|
+
default:
|
|
710
|
+
return "high";
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
export const streamSimple = (model, context, options) => {
|
|
714
|
+
if (!getAnthropicFederation(model, options?.apiKey, options?.headers, options?.env)) {
|
|
715
|
+
assertRequestAuth(model.provider, options?.apiKey, options?.headers);
|
|
716
|
+
}
|
|
717
|
+
const base = {
|
|
718
|
+
...buildBaseOptions(model, context, options, options?.apiKey),
|
|
719
|
+
toolChoice: options?.toolChoice,
|
|
720
|
+
};
|
|
721
|
+
if (!options?.reasoning) {
|
|
722
|
+
return stream(model, context, {
|
|
723
|
+
...base,
|
|
724
|
+
thinkingEnabled: false,
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
// For models with adaptive thinking: use an effort level.
|
|
728
|
+
// For older models: use budget-based thinking.
|
|
729
|
+
if (model.compat?.forceAdaptiveThinking === true) {
|
|
730
|
+
const effort = mapThinkingLevelToEffort(model, options.reasoning);
|
|
731
|
+
return stream(model, context, {
|
|
732
|
+
...base,
|
|
733
|
+
thinkingEnabled: true,
|
|
734
|
+
effort,
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
// Undefined means the caller did not request an output cap; let the helper use the model cap.
|
|
738
|
+
// Do not coerce to 0 here, or the thinking budget would become the entire max_tokens value.
|
|
739
|
+
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
740
|
+
const maxTokens = clampMaxTokensToContext(model, context, adjusted.maxTokens);
|
|
741
|
+
return stream(model, context, {
|
|
742
|
+
...base,
|
|
743
|
+
maxTokens,
|
|
744
|
+
thinkingEnabled: true,
|
|
745
|
+
thinkingBudgetTokens: Math.min(adjusted.thinkingBudget, Math.max(0, maxTokens - 1024)),
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
function isOAuthToken(apiKey) {
|
|
749
|
+
return apiKey.includes("sk-ant-oat");
|
|
750
|
+
}
|
|
751
|
+
function createClient(model, apiKey, optionsHeaders, fetch, dynamicHeaders, sessionId, federation, authType) {
|
|
752
|
+
// Copilot: Bearer auth.
|
|
753
|
+
if (model.provider === "github-copilot") {
|
|
754
|
+
const client = new PiAnthropic({
|
|
755
|
+
apiKey: null,
|
|
756
|
+
authToken: apiKey ?? null,
|
|
757
|
+
baseURL: model.baseUrl,
|
|
758
|
+
dangerouslyAllowBrowser: true,
|
|
759
|
+
fetch,
|
|
760
|
+
defaultHeaders: mergeClientHeaders({
|
|
761
|
+
accept: "application/json",
|
|
762
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
763
|
+
}, model.headers, dynamicHeaders, optionsHeaders),
|
|
764
|
+
});
|
|
765
|
+
return { client, isOAuthToken: false };
|
|
766
|
+
}
|
|
767
|
+
// OAuth: Bearer auth, Claude Code identity headers
|
|
768
|
+
if (authType === "oauth" || (authType === undefined && apiKey && isOAuthToken(apiKey))) {
|
|
769
|
+
const client = new PiAnthropic({
|
|
770
|
+
apiKey: null,
|
|
771
|
+
authToken: apiKey,
|
|
772
|
+
baseURL: model.baseUrl,
|
|
773
|
+
dangerouslyAllowBrowser: true,
|
|
774
|
+
fetch,
|
|
775
|
+
defaultHeaders: mergeClientHeaders({
|
|
776
|
+
accept: "application/json",
|
|
777
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
778
|
+
"user-agent": `claude-cli/${claudeCodeVersion}`,
|
|
779
|
+
"x-app": "cli",
|
|
780
|
+
}, model.headers, optionsHeaders),
|
|
781
|
+
});
|
|
782
|
+
return { client, isOAuthToken: true };
|
|
783
|
+
}
|
|
784
|
+
// API key, header-owned auth, or workload identity federation.
|
|
785
|
+
const compat = getAnthropicCompat(model);
|
|
786
|
+
const sessionAffinityHeaders = {};
|
|
787
|
+
if (sessionId && compat.sendSessionAffinityHeaders) {
|
|
788
|
+
const header = compat.sessionAffinityFormat === "openrouter" ? "x-session-id" : "x-session-affinity";
|
|
789
|
+
sessionAffinityHeaders[header] = sessionId;
|
|
790
|
+
}
|
|
791
|
+
const defaultHeaders = mergeClientHeaders({
|
|
792
|
+
accept: "application/json",
|
|
793
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
794
|
+
}, sessionAffinityHeaders, model.headers, optionsHeaders);
|
|
795
|
+
if (federation) {
|
|
796
|
+
const key = JSON.stringify([model.baseUrl, federation]);
|
|
797
|
+
if (federationClient?.key !== key || federationClient.fetch !== fetch) {
|
|
798
|
+
const client = new PiAnthropic({
|
|
799
|
+
apiKey: null,
|
|
800
|
+
authToken: null,
|
|
801
|
+
config: federation,
|
|
802
|
+
baseURL: model.baseUrl,
|
|
803
|
+
dangerouslyAllowBrowser: true,
|
|
804
|
+
fetch,
|
|
805
|
+
});
|
|
806
|
+
federationClient = { key, fetch, client };
|
|
807
|
+
}
|
|
808
|
+
return { client: federationClient.client.withOptions({ defaultHeaders }), isOAuthToken: false };
|
|
809
|
+
}
|
|
810
|
+
const client = new PiAnthropic({
|
|
811
|
+
apiKey: apiKey ?? null,
|
|
812
|
+
authToken: null,
|
|
813
|
+
baseURL: model.baseUrl,
|
|
814
|
+
dangerouslyAllowBrowser: true,
|
|
815
|
+
fetch,
|
|
816
|
+
defaultHeaders,
|
|
817
|
+
});
|
|
818
|
+
return { client, isOAuthToken: false };
|
|
819
|
+
}
|
|
820
|
+
function getBetaFeatures(model, context, isOAuthToken, nativeToolChanges, options) {
|
|
821
|
+
let configuredFeatures;
|
|
822
|
+
for (const headers of [model.headers, options?.headers]) {
|
|
823
|
+
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
824
|
+
if (name.toLowerCase() === "anthropic-beta")
|
|
825
|
+
configuredFeatures = value;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (configuredFeatures === null)
|
|
829
|
+
return [];
|
|
830
|
+
if (configuredFeatures !== undefined) {
|
|
831
|
+
return [
|
|
832
|
+
...new Set(configuredFeatures
|
|
833
|
+
.split(",")
|
|
834
|
+
.map((feature) => feature.trim())
|
|
835
|
+
.filter((feature) => feature.length > 0)),
|
|
836
|
+
];
|
|
837
|
+
}
|
|
838
|
+
const features = [];
|
|
839
|
+
if (isOAuthToken)
|
|
840
|
+
features.push("claude-code-20250219", "oauth-2025-04-20");
|
|
841
|
+
if (shouldUseFineGrainedToolStreamingBeta(model, context))
|
|
842
|
+
features.push(FINE_GRAINED_TOOL_STREAMING_BETA);
|
|
843
|
+
if (model.reasoning &&
|
|
844
|
+
options?.thinkingEnabled === true &&
|
|
845
|
+
(options.interleavedThinking ?? true) &&
|
|
846
|
+
model.compat?.forceAdaptiveThinking !== true) {
|
|
847
|
+
features.push(INTERLEAVED_THINKING_BETA);
|
|
848
|
+
}
|
|
849
|
+
if (shouldUseServerSideFallbackBeta(model))
|
|
850
|
+
features.push(SERVER_SIDE_FALLBACK_BETA);
|
|
851
|
+
if (model.compat?.supportsMidConvoEffort === true) {
|
|
852
|
+
features.push(MID_CONVERSATION_OUTPUT_CONFIG_BETA, THINKING_BINDING_CONTROLS_BETA);
|
|
853
|
+
}
|
|
854
|
+
if (nativeToolChanges)
|
|
855
|
+
features.push(MID_CONVERSATION_TOOL_CHANGES_BETA);
|
|
856
|
+
return [...new Set(features)];
|
|
857
|
+
}
|
|
858
|
+
function buildParams(model, context, isOAuthToken, options) {
|
|
859
|
+
const { cacheControl } = getCacheControl(model, options?.cacheRetention, options?.env);
|
|
860
|
+
const compat = getAnthropicCompat(model);
|
|
861
|
+
const initialSystemMessage = getInitialSystemMessage(context.messages);
|
|
862
|
+
const initialSystemText = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : "";
|
|
863
|
+
const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);
|
|
864
|
+
const conversationMessages = initialSystemMessage ? transformedMessages.slice(1) : transformedMessages;
|
|
865
|
+
// Native tool changes reference tools by name, so a redefined name cannot be expressed,
|
|
866
|
+
// and Anthropic rejects a tool list where every tool is deferred, so there must be an
|
|
867
|
+
// initial active tool to anchor the deferred ones. Otherwise the current tool list is sent.
|
|
868
|
+
const initialTools = initialSystemMessage?.toolsAdded ?? [];
|
|
869
|
+
const nativeToolChanges = compat.supportsMidConvoSystemMessages &&
|
|
870
|
+
compat.supportsMidConvoToolChanges &&
|
|
871
|
+
initialTools.length > 0 &&
|
|
872
|
+
!hasToolRedefinitions(context.messages);
|
|
873
|
+
const converted = convertMessages(conversationMessages, isOAuthToken, cacheControl, compat.allowEmptySignature, model.compat?.supportsMidConvoEffort === true ? model.provider : undefined, nativeToolChanges);
|
|
874
|
+
const activeEffort = options?.effort ?? "high";
|
|
875
|
+
const betaFeatures = getBetaFeatures(model, context, isOAuthToken, nativeToolChanges, options);
|
|
876
|
+
const params = {
|
|
877
|
+
model: model.id,
|
|
878
|
+
messages: model.compat?.supportsMidConvoEffort === true
|
|
879
|
+
? insertThinkingLevelMessages(converted, activeEffort)
|
|
880
|
+
: converted.messages,
|
|
881
|
+
max_tokens: options?.maxTokens ?? model.maxTokens,
|
|
882
|
+
stream: true,
|
|
883
|
+
...(betaFeatures.length > 0 ? { betas: betaFeatures } : {}),
|
|
884
|
+
};
|
|
885
|
+
// For OAuth tokens, we MUST include Claude Code identity
|
|
886
|
+
if (isOAuthToken) {
|
|
887
|
+
params.system = [
|
|
888
|
+
{
|
|
889
|
+
type: "text",
|
|
890
|
+
text: "You are Claude Code, Anthropic's official CLI for Claude.",
|
|
891
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
892
|
+
},
|
|
893
|
+
];
|
|
894
|
+
if (initialSystemText) {
|
|
895
|
+
params.system.push({
|
|
896
|
+
type: "text",
|
|
897
|
+
text: sanitizeSurrogates(initialSystemText),
|
|
898
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
else if (initialSystemText) {
|
|
903
|
+
// Add cache control to system prompt for non-OAuth tokens
|
|
904
|
+
params.system = [
|
|
905
|
+
{
|
|
906
|
+
type: "text",
|
|
907
|
+
text: sanitizeSurrogates(initialSystemText),
|
|
908
|
+
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
909
|
+
},
|
|
910
|
+
];
|
|
911
|
+
}
|
|
912
|
+
// Temperature is incompatible with extended thinking and unsupported on Claude Opus 4.7+.
|
|
913
|
+
if (options?.temperature !== undefined &&
|
|
914
|
+
!options?.thinkingEnabled &&
|
|
915
|
+
model.compat?.supportsMidConvoEffort !== true &&
|
|
916
|
+
compat.supportsTemperature) {
|
|
917
|
+
params.temperature = options.temperature;
|
|
918
|
+
}
|
|
919
|
+
const toolCacheControl = compat.supportsCacheControlOnTools ? cacheControl : undefined;
|
|
920
|
+
if (nativeToolChanges) {
|
|
921
|
+
// Initial tools stay active with the cache breakpoint on the last one. Every later
|
|
922
|
+
// declaration is deferred and only surfaced by its `tool_addition` block; removed
|
|
923
|
+
// tools stay declared and are withdrawn by `tool_removal`. The request-level list
|
|
924
|
+
// therefore only grows, keeping the cached prefix intact across tool changes.
|
|
925
|
+
const initialNames = new Set(initialTools.map((tool) => tool.name));
|
|
926
|
+
const laterTools = getDeclaredTools(context.messages).filter((tool) => !initialNames.has(tool.name));
|
|
927
|
+
params.tools = [
|
|
928
|
+
...convertTools(initialTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl),
|
|
929
|
+
DEFERRED_TOOL_PLACEHOLDER,
|
|
930
|
+
...convertTools(laterTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools).map((tool) => ({ ...tool, defer_loading: true })),
|
|
931
|
+
];
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
const tools = getCurrentTools(context.messages);
|
|
935
|
+
if (tools.length > 0) {
|
|
936
|
+
params.tools = convertTools(tools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
// Managed effort models always use adaptive thinking so prefix mismatches can
|
|
940
|
+
// be dropped instead of surfacing as persistent 400 responses.
|
|
941
|
+
if (model.compat?.supportsMidConvoEffort === true) {
|
|
942
|
+
params.thinking = {
|
|
943
|
+
type: "adaptive",
|
|
944
|
+
display: options?.thinkingDisplay ?? "summarized",
|
|
945
|
+
block_binding: { prefix_mismatch_behavior: "drop_block" },
|
|
946
|
+
};
|
|
947
|
+
params.output_config = { effort: "high" };
|
|
948
|
+
}
|
|
949
|
+
else if (model.reasoning) {
|
|
950
|
+
if (options?.thinkingEnabled) {
|
|
951
|
+
// Default to "summarized" so Opus 4.7 and Mythos Preview behave like
|
|
952
|
+
// older Claude 4 models (whose API default is also "summarized").
|
|
953
|
+
const display = options.thinkingDisplay ?? "summarized";
|
|
954
|
+
if (model.compat?.forceAdaptiveThinking === true) {
|
|
955
|
+
// Adaptive thinking: Claude decides when and how much to think.
|
|
956
|
+
params.thinking = { type: "adaptive", display };
|
|
957
|
+
if (options.effort) {
|
|
958
|
+
params.output_config = { effort: options.effort };
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
// Budget-based thinking for older models
|
|
963
|
+
params.thinking = {
|
|
964
|
+
type: "enabled",
|
|
965
|
+
budget_tokens: options.thinkingBudgetTokens || 1024,
|
|
966
|
+
display,
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
else if (options?.thinkingEnabled === false && model.thinkingLevelMap?.off !== null) {
|
|
971
|
+
params.thinking = { type: "disabled" };
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (options?.metadata) {
|
|
975
|
+
const userId = options.metadata.user_id;
|
|
976
|
+
if (typeof userId === "string") {
|
|
977
|
+
params.metadata = { user_id: userId };
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
if (options?.toolChoice) {
|
|
981
|
+
if (typeof options.toolChoice === "string") {
|
|
982
|
+
params.tool_choice = { type: options.toolChoice };
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
params.tool_choice = options.toolChoice;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const allowedFallbackModels = model.compat?.allowedFallbackModels;
|
|
989
|
+
if (allowedFallbackModels && allowedFallbackModels.length > 0) {
|
|
990
|
+
params.fallbacks = allowedFallbackModels.map((fallback) => ({ model: fallback.model }));
|
|
991
|
+
}
|
|
992
|
+
return params;
|
|
993
|
+
}
|
|
994
|
+
// Normalize tool call IDs to match Anthropic's required pattern and length
|
|
995
|
+
function normalizeToolCallId(id) {
|
|
996
|
+
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
997
|
+
}
|
|
998
|
+
function convertToolResult(msg) {
|
|
999
|
+
return {
|
|
1000
|
+
type: "tool_result",
|
|
1001
|
+
tool_use_id: msg.toolCallId,
|
|
1002
|
+
content: convertContentBlocks(msg.content),
|
|
1003
|
+
is_error: msg.isError,
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
function convertMessages(transformedMessages, isOAuthToken, cacheControl, allowEmptySignature = false, managedProvider, nativeToolChanges = false) {
|
|
1007
|
+
const params = [];
|
|
1008
|
+
const assistantLevels = new Map();
|
|
1009
|
+
// Later system messages are held back and emitted directly before the next assistant
|
|
1010
|
+
// message (or at the end of the transcript). Anthropic requires `tool_result` blocks to
|
|
1011
|
+
// immediately follow their `tool_use`, so a system message between them is rejected; this
|
|
1012
|
+
// also mirrors where the managed-effort system messages are inserted. As a result an
|
|
1013
|
+
// update placed before a user message in the transcript lands after it on the wire.
|
|
1014
|
+
const pendingSystemMessages = [];
|
|
1015
|
+
const flushPendingSystemMessages = () => {
|
|
1016
|
+
params.push(...pendingSystemMessages);
|
|
1017
|
+
pendingSystemMessages.length = 0;
|
|
1018
|
+
};
|
|
1019
|
+
for (let i = 0; i < transformedMessages.length; i++) {
|
|
1020
|
+
const msg = transformedMessages[i];
|
|
1021
|
+
if (msg.role === "system") {
|
|
1022
|
+
// Later system messages only reach this point when the model accepts them natively;
|
|
1023
|
+
// otherwise the transcript was collapsed into the leading message before conversion.
|
|
1024
|
+
const text = renderSystemMessageUpdate(msg);
|
|
1025
|
+
const blocks = [];
|
|
1026
|
+
if (text.length > 0)
|
|
1027
|
+
blocks.push({ type: "text", text: sanitizeSurrogates(text) });
|
|
1028
|
+
if (nativeToolChanges) {
|
|
1029
|
+
for (const tool of msg.toolsRemoved ?? []) {
|
|
1030
|
+
blocks.push({
|
|
1031
|
+
type: "tool_removal",
|
|
1032
|
+
tool: { type: "tool_reference", name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name },
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
for (const tool of msg.toolsAdded ?? []) {
|
|
1036
|
+
blocks.push({
|
|
1037
|
+
type: "tool_addition",
|
|
1038
|
+
tool: { type: "tool_reference", name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name },
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (blocks.length > 0)
|
|
1043
|
+
pendingSystemMessages.push({ role: "system", content: blocks });
|
|
1044
|
+
}
|
|
1045
|
+
else if (msg.role === "user") {
|
|
1046
|
+
if (typeof msg.content === "string") {
|
|
1047
|
+
if (msg.content.trim().length > 0) {
|
|
1048
|
+
params.push({
|
|
1049
|
+
role: "user",
|
|
1050
|
+
content: sanitizeSurrogates(msg.content),
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
const blocks = msg.content.map((item) => {
|
|
1056
|
+
if (item.type === "text") {
|
|
1057
|
+
return {
|
|
1058
|
+
type: "text",
|
|
1059
|
+
text: sanitizeSurrogates(item.text),
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
else {
|
|
1063
|
+
return {
|
|
1064
|
+
type: "image",
|
|
1065
|
+
source: {
|
|
1066
|
+
type: "base64",
|
|
1067
|
+
media_type: item.mimeType,
|
|
1068
|
+
data: item.data,
|
|
1069
|
+
},
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
const filteredBlocks = blocks.filter((b) => {
|
|
1074
|
+
if (b.type === "text") {
|
|
1075
|
+
return b.text.trim().length > 0;
|
|
1076
|
+
}
|
|
1077
|
+
return true;
|
|
1078
|
+
});
|
|
1079
|
+
if (filteredBlocks.length === 0)
|
|
1080
|
+
continue;
|
|
1081
|
+
params.push({
|
|
1082
|
+
role: "user",
|
|
1083
|
+
content: filteredBlocks,
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
else if (msg.role === "assistant") {
|
|
1088
|
+
flushPendingSystemMessages();
|
|
1089
|
+
const blocks = [];
|
|
1090
|
+
for (const block of msg.content) {
|
|
1091
|
+
if (block.type === "text") {
|
|
1092
|
+
if (block.text.trim().length === 0)
|
|
1093
|
+
continue;
|
|
1094
|
+
blocks.push({
|
|
1095
|
+
type: "text",
|
|
1096
|
+
text: sanitizeSurrogates(block.text),
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
else if (block.type === "thinking") {
|
|
1100
|
+
// Redacted thinking: pass the opaque payload back as redacted_thinking
|
|
1101
|
+
if (block.redacted) {
|
|
1102
|
+
blocks.push({
|
|
1103
|
+
type: "redacted_thinking",
|
|
1104
|
+
data: block.thinkingSignature,
|
|
1105
|
+
});
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
const thinkingSignature = block.thinkingSignature;
|
|
1109
|
+
const hasThinkingSignature = !!thinkingSignature && thinkingSignature.trim().length > 0;
|
|
1110
|
+
if (block.thinking.trim().length === 0 && !hasThinkingSignature)
|
|
1111
|
+
continue;
|
|
1112
|
+
// If thinking signature is missing/empty (e.g., from aborted stream),
|
|
1113
|
+
// convert to plain text for Anthropic. Some compatible providers emit
|
|
1114
|
+
// and accept empty signatures, so let marked models preserve the block.
|
|
1115
|
+
if (!hasThinkingSignature) {
|
|
1116
|
+
blocks.push(allowEmptySignature
|
|
1117
|
+
? {
|
|
1118
|
+
type: "thinking",
|
|
1119
|
+
thinking: sanitizeSurrogates(block.thinking),
|
|
1120
|
+
signature: "",
|
|
1121
|
+
}
|
|
1122
|
+
: {
|
|
1123
|
+
type: "text",
|
|
1124
|
+
text: sanitizeSurrogates(block.thinking),
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
blocks.push({
|
|
1129
|
+
type: "thinking",
|
|
1130
|
+
thinking: sanitizeSurrogates(block.thinking),
|
|
1131
|
+
signature: thinkingSignature,
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
else if (block.type === "toolCall") {
|
|
1136
|
+
blocks.push({
|
|
1137
|
+
type: "tool_use",
|
|
1138
|
+
id: block.id,
|
|
1139
|
+
name: isOAuthToken ? toClaudeCodeName(block.name) : block.name,
|
|
1140
|
+
input: block.arguments ?? {},
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
if (blocks.length === 0)
|
|
1145
|
+
continue;
|
|
1146
|
+
const messageIndex = params.length;
|
|
1147
|
+
params.push({
|
|
1148
|
+
role: "assistant",
|
|
1149
|
+
content: blocks,
|
|
1150
|
+
});
|
|
1151
|
+
if (managedProvider !== undefined &&
|
|
1152
|
+
msg.api === "anthropic-messages" &&
|
|
1153
|
+
msg.provider === managedProvider &&
|
|
1154
|
+
isAnthropicEffort(msg.providerThinkingLevel)) {
|
|
1155
|
+
assistantLevels.set(messageIndex, msg.providerThinkingLevel);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
else if (msg.role === "toolResult") {
|
|
1159
|
+
// Collect all consecutive toolResult messages, needed for z.ai Anthropic endpoint.
|
|
1160
|
+
const toolResults = [];
|
|
1161
|
+
let j = i;
|
|
1162
|
+
while (j < transformedMessages.length && transformedMessages[j].role === "toolResult") {
|
|
1163
|
+
toolResults.push(convertToolResult(transformedMessages[j]));
|
|
1164
|
+
j++;
|
|
1165
|
+
}
|
|
1166
|
+
// Skip the messages we've already processed.
|
|
1167
|
+
i = j - 1;
|
|
1168
|
+
params.push({
|
|
1169
|
+
role: "user",
|
|
1170
|
+
content: toolResults,
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
flushPendingSystemMessages();
|
|
1175
|
+
// Add cache_control to the last user or system message to cache conversation history
|
|
1176
|
+
if (cacheControl && params.length > 0) {
|
|
1177
|
+
const lastMessage = params[params.length - 1];
|
|
1178
|
+
if (lastMessage.role === "user" || lastMessage.role === "system") {
|
|
1179
|
+
if (Array.isArray(lastMessage.content)) {
|
|
1180
|
+
const lastBlock = lastMessage.content[lastMessage.content.length - 1];
|
|
1181
|
+
if (lastBlock &&
|
|
1182
|
+
(lastBlock.type === "text" ||
|
|
1183
|
+
lastBlock.type === "image" ||
|
|
1184
|
+
lastBlock.type === "tool_result" ||
|
|
1185
|
+
lastBlock.type === "tool_addition" ||
|
|
1186
|
+
lastBlock.type === "tool_removal")) {
|
|
1187
|
+
lastBlock.cache_control = cacheControl;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
else if (typeof lastMessage.content === "string") {
|
|
1191
|
+
lastMessage.content = [
|
|
1192
|
+
{
|
|
1193
|
+
type: "text",
|
|
1194
|
+
text: lastMessage.content,
|
|
1195
|
+
cache_control: cacheControl,
|
|
1196
|
+
},
|
|
1197
|
+
];
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return { messages: params, assistantLevels };
|
|
1202
|
+
}
|
|
1203
|
+
function isAnthropicEffort(value) {
|
|
1204
|
+
return value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
1205
|
+
}
|
|
1206
|
+
function insertThinkingLevelMessages(converted, activeEffort) {
|
|
1207
|
+
const messages = [];
|
|
1208
|
+
for (let index = 0; index < converted.messages.length; index++) {
|
|
1209
|
+
const historicalEffort = converted.assistantLevels.get(index);
|
|
1210
|
+
if (historicalEffort !== undefined) {
|
|
1211
|
+
messages.push({ role: "system", content: [], output_config: { effort: historicalEffort } });
|
|
1212
|
+
}
|
|
1213
|
+
messages.push(converted.messages[index]);
|
|
1214
|
+
}
|
|
1215
|
+
messages.push({ role: "system", content: [], output_config: { effort: activeEffort } });
|
|
1216
|
+
return messages;
|
|
1217
|
+
}
|
|
1218
|
+
function shouldUseFineGrainedToolStreamingBeta(model, context) {
|
|
1219
|
+
return getCurrentTools(context.messages).length > 0 && !getAnthropicCompat(model).supportsEagerToolInputStreaming;
|
|
1220
|
+
}
|
|
1221
|
+
// Keywords Anthropic strict tool use rejects with a 400 for the whole request.
|
|
1222
|
+
// https://platform.claude.com/docs/en/build-with-claude/structured-outputs#json-schema-limitations
|
|
1223
|
+
const ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS = new Set([
|
|
1224
|
+
"minimum",
|
|
1225
|
+
"maximum",
|
|
1226
|
+
"exclusiveMinimum",
|
|
1227
|
+
"exclusiveMaximum",
|
|
1228
|
+
"multipleOf",
|
|
1229
|
+
"maxItems",
|
|
1230
|
+
"uniqueItems",
|
|
1231
|
+
"minContains",
|
|
1232
|
+
"maxContains",
|
|
1233
|
+
"minProperties",
|
|
1234
|
+
"maxProperties",
|
|
1235
|
+
]);
|
|
1236
|
+
const ANTHROPIC_STRICT_STRING_FORMATS = new Set([
|
|
1237
|
+
"date-time",
|
|
1238
|
+
"time",
|
|
1239
|
+
"date",
|
|
1240
|
+
"duration",
|
|
1241
|
+
"email",
|
|
1242
|
+
"hostname",
|
|
1243
|
+
"uri",
|
|
1244
|
+
"ipv4",
|
|
1245
|
+
"ipv6",
|
|
1246
|
+
"uuid",
|
|
1247
|
+
]);
|
|
1248
|
+
const isAnthropicStrictUnsupportedKeyword = (key, value) => {
|
|
1249
|
+
if (ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS.has(key))
|
|
1250
|
+
return true;
|
|
1251
|
+
if (key === "minItems")
|
|
1252
|
+
return value !== 0 && value !== 1;
|
|
1253
|
+
if (key === "format")
|
|
1254
|
+
return typeof value !== "string" || !ANTHROPIC_STRICT_STRING_FORMATS.has(value);
|
|
1255
|
+
return false;
|
|
1256
|
+
};
|
|
1257
|
+
function convertTools(tools, isOAuthToken, supportsEagerToolInputStreaming, supportsStrictTools, cacheControl) {
|
|
1258
|
+
if (!tools)
|
|
1259
|
+
return [];
|
|
1260
|
+
return tools.map((tool, index) => {
|
|
1261
|
+
const strict = resolveJsonSchemaStrictSampling(tool, supportsStrictTools, isAnthropicStrictUnsupportedKeyword);
|
|
1262
|
+
const parameters = getJsonSchemaToolParameters(tool, strict);
|
|
1263
|
+
const schema = parameters;
|
|
1264
|
+
const legacyInputSchema = {
|
|
1265
|
+
type: "object",
|
|
1266
|
+
properties: schema.properties ?? {},
|
|
1267
|
+
required: schema.required ?? [],
|
|
1268
|
+
};
|
|
1269
|
+
const inputSchema = strict === true
|
|
1270
|
+
? {
|
|
1271
|
+
...parameters,
|
|
1272
|
+
...legacyInputSchema,
|
|
1273
|
+
}
|
|
1274
|
+
: legacyInputSchema;
|
|
1275
|
+
return {
|
|
1276
|
+
name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name,
|
|
1277
|
+
description: tool.description,
|
|
1278
|
+
...(supportsEagerToolInputStreaming ? { eager_input_streaming: true } : {}),
|
|
1279
|
+
...(strict === true ? { strict: true } : {}),
|
|
1280
|
+
input_schema: inputSchema,
|
|
1281
|
+
...(cacheControl && index === tools.length - 1 ? { cache_control: cacheControl } : {}),
|
|
1282
|
+
};
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
function mapStopReason(reason, stopDetails) {
|
|
1286
|
+
switch (reason) {
|
|
1287
|
+
case "end_turn":
|
|
1288
|
+
return { stopReason: "stop" };
|
|
1289
|
+
case "max_tokens":
|
|
1290
|
+
return { stopReason: "length" };
|
|
1291
|
+
case "tool_use":
|
|
1292
|
+
return { stopReason: "toolUse" };
|
|
1293
|
+
case "refusal":
|
|
1294
|
+
return {
|
|
1295
|
+
stopReason: "error",
|
|
1296
|
+
errorMessage: stopDetails?.explanation || `The model refused to complete the request`,
|
|
1297
|
+
};
|
|
1298
|
+
case "pause_turn": // Stop is good enough -> resubmit
|
|
1299
|
+
return { stopReason: "stop" };
|
|
1300
|
+
case "stop_sequence":
|
|
1301
|
+
return { stopReason: "stop" }; // We don't supply stop sequences, so this should never happen
|
|
1302
|
+
case "sensitive": // Content flagged by safety filters (not yet in SDK types)
|
|
1303
|
+
return { stopReason: "error", errorMessage: "Provider stopped with: sensitive" };
|
|
1304
|
+
default:
|
|
1305
|
+
// Handle unknown stop reasons gracefully (API may add new values)
|
|
1306
|
+
throw new Error(`Unhandled stop reason: ${reason}`);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
//# sourceMappingURL=anthropic-messages.js.map
|