@bastani/atomic-ai 0.0.0-stage → 0.9.88
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/CHANGELOG.md +1629 -0
- package/LICENSE +22 -0
- package/NOTICE.md +16 -0
- package/README.md +165 -2
- package/dist/api/anthropic-assistant-content.d.ts +24 -0
- package/dist/api/anthropic-assistant-content.d.ts.map +1 -0
- package/dist/api/anthropic-assistant-content.js +99 -0
- package/dist/api/anthropic-assistant-content.js.map +1 -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 +1814 -0
- package/dist/api/anthropic-messages.js.map +1 -0
- package/dist/api/anthropic-messages.lazy.d.ts +3 -0
- package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
- package/dist/api/anthropic-messages.lazy.js +3 -0
- package/dist/api/anthropic-messages.lazy.js.map +1 -0
- package/dist/api/azure-openai-config.d.ts +14 -0
- package/dist/api/azure-openai-config.d.ts.map +1 -0
- package/dist/api/azure-openai-config.js +61 -0
- package/dist/api/azure-openai-config.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts +14 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.js +213 -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 +1301 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +16 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +43 -0
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
- package/dist/api/classifier-shared.d.ts +11 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +90 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-gateway-binding.d.ts +58 -0
- package/dist/api/cloudflare-gateway-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-gateway-binding.js +33 -0
- package/dist/api/cloudflare-gateway-binding.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.js +57 -0
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts +3 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js.map +1 -0
- package/dist/api/cloudflare.d.ts +11 -0
- package/dist/api/cloudflare.d.ts.map +1 -0
- package/dist/api/cloudflare.js +11 -0
- package/dist/api/cloudflare.js.map +1 -0
- package/dist/api/constrained-sampling.d.ts +38 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +271 -0
- package/dist/api/constrained-sampling.js.map +1 -0
- package/dist/api/github-copilot-headers.d.ts +40 -0
- package/dist/api/github-copilot-headers.d.ts.map +1 -0
- package/dist/api/github-copilot-headers.js +76 -0
- package/dist/api/github-copilot-headers.js.map +1 -0
- package/dist/api/google-generative-ai.d.ts +15 -0
- package/dist/api/google-generative-ai.d.ts.map +1 -0
- package/dist/api/google-generative-ai.js +376 -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 +103 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +536 -0
- package/dist/api/google-shared.js.map +1 -0
- package/dist/api/google-vertex.d.ts +17 -0
- package/dist/api/google-vertex.d.ts.map +1 -0
- package/dist/api/google-vertex.js +440 -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 +72 -0
- package/dist/api/lazy.js.map +1 -0
- package/dist/api/llama-cpp-classify.d.ts +33 -0
- package/dist/api/llama-cpp-classify.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.js +368 -0
- package/dist/api/llama-cpp-classify.js.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts +3 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.js +4 -0
- package/dist/api/llama-cpp-classify.lazy.js.map +1 -0
- package/dist/api/mistral-conversations.d.ts +25 -0
- package/dist/api/mistral-conversations.d.ts.map +1 -0
- package/dist/api/mistral-conversations.js +779 -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 +1357 -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 +30 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1529 -0
- package/dist/api/openai-completions.js.map +1 -0
- package/dist/api/openai-completions.lazy.d.ts +3 -0
- package/dist/api/openai-completions.lazy.d.ts.map +1 -0
- package/dist/api/openai-completions.lazy.js +3 -0
- package/dist/api/openai-completions.lazy.js.map +1 -0
- package/dist/api/openai-decisions.d.ts +3 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +157 -0
- package/dist/api/openai-decisions.js.map +1 -0
- package/dist/api/openai-decisions.lazy.d.ts +3 -0
- package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
- package/dist/api/openai-decisions.lazy.js +4 -0
- package/dist/api/openai-decisions.lazy.js.map +1 -0
- package/dist/api/openai-images-options.d.ts +120 -0
- package/dist/api/openai-images-options.d.ts.map +1 -0
- package/dist/api/openai-images-options.js +112 -0
- package/dist/api/openai-images-options.js.map +1 -0
- package/dist/api/openai-images.d.ts +9 -0
- package/dist/api/openai-images.d.ts.map +1 -0
- package/dist/api/openai-images.js +317 -0
- package/dist/api/openai-images.js.map +1 -0
- package/dist/api/openai-images.lazy.d.ts +3 -0
- package/dist/api/openai-images.lazy.d.ts.map +1 -0
- package/dist/api/openai-images.lazy.js +4 -0
- package/dist/api/openai-images.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 +133 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +970 -0
- package/dist/api/openai-responses-shared.js.map +1 -0
- package/dist/api/openai-responses.d.ts +15 -0
- package/dist/api/openai-responses.d.ts.map +1 -0
- package/dist/api/openai-responses.js +444 -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/openai-retry-hint-client.d.ts +10 -0
- package/dist/api/openai-retry-hint-client.d.ts.map +1 -0
- package/dist/api/openai-retry-hint-client.js +17 -0
- package/dist/api/openai-retry-hint-client.js.map +1 -0
- package/dist/api/openrouter-images.d.ts +4 -0
- package/dist/api/openrouter-images.d.ts.map +1 -0
- package/dist/api/openrouter-images.js +135 -0
- package/dist/api/openrouter-images.js.map +1 -0
- package/dist/api/openrouter-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-images.lazy.js +4 -0
- package/dist/api/openrouter-images.lazy.js.map +1 -0
- package/dist/api/pi-messages.d.ts +101 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +338 -0
- package/dist/api/pi-messages.js.map +1 -0
- package/dist/api/pi-messages.lazy.d.ts +3 -0
- package/dist/api/pi-messages.lazy.d.ts.map +1 -0
- package/dist/api/pi-messages.lazy.js +3 -0
- package/dist/api/pi-messages.lazy.js.map +1 -0
- package/dist/api/simple-options.d.ts +17 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +89 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/strict-tool-limits.d.ts +13 -0
- package/dist/api/strict-tool-limits.d.ts.map +1 -0
- package/dist/api/strict-tool-limits.js +50 -0
- package/dist/api/strict-tool-limits.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +48 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +175 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +27 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +353 -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 +29 -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 +52 -0
- package/dist/auth/credential-store.js.map +1 -0
- package/dist/auth/helpers.d.ts +30 -0
- package/dist/auth/helpers.d.ts.map +1 -0
- package/dist/auth/helpers.js +66 -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 +266 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/callback-server.d.ts +31 -0
- package/dist/auth/oauth/callback-server.d.ts.map +1 -0
- package/dist/auth/oauth/callback-server.js +138 -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 +352 -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 +238 -0
- package/dist/auth/oauth/kimi-coding.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +23 -0
- package/dist/auth/oauth/load.d.ts.map +1 -0
- package/dist/auth/oauth/load.js +67 -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 +182 -0
- package/dist/auth/oauth/meta.js.map +1 -0
- package/dist/auth/oauth/oauth-page.d.ts +3 -0
- package/dist/auth/oauth/oauth-page.d.ts.map +1 -0
- package/dist/auth/oauth/oauth-page.js +105 -0
- package/dist/auth/oauth/oauth-page.js.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +3 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.js +271 -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 +360 -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 +159 -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/token-response.d.ts +25 -0
- package/dist/auth/oauth/token-response.d.ts.map +1 -0
- package/dist/auth/oauth/token-response.js +43 -0
- package/dist/auth/oauth/token-response.js.map +1 -0
- package/dist/auth/oauth/trusted-url.d.ts +7 -0
- package/dist/auth/oauth/trusted-url.d.ts.map +1 -0
- package/dist/auth/oauth/trusted-url.js +12 -0
- package/dist/auth/oauth/trusted-url.js.map +1 -0
- package/dist/auth/oauth/xai.d.ts +6 -0
- package/dist/auth/oauth/xai.d.ts.map +1 -0
- package/dist/auth/oauth/xai.js +193 -0
- package/dist/auth/oauth/xai.js.map +1 -0
- package/dist/auth/oauth-refresh-errors.d.ts +46 -0
- package/dist/auth/oauth-refresh-errors.d.ts.map +1 -0
- package/dist/auth/oauth-refresh-errors.js +150 -0
- package/dist/auth/oauth-refresh-errors.js.map +1 -0
- package/dist/auth/resolve.d.ts +62 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +357 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +267 -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 +23 -0
- package/dist/bun-oauth.js.map +1 -0
- package/dist/cache-warming.d.ts +53 -0
- package/dist/cache-warming.d.ts.map +1 -0
- package/dist/cache-warming.js +82 -0
- package/dist/cache-warming.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +118 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +43 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -0
- package/dist/compat/extension-oauth-types.js +2 -0
- package/dist/compat/extension-oauth-types.js.map +1 -0
- package/dist/compat.d.ts +67 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +202 -0
- package/dist/compat.js.map +1 -0
- package/dist/decision-models.d.ts +21 -0
- package/dist/decision-models.d.ts.map +1 -0
- package/dist/decision-models.generated.d.ts +3 -0
- package/dist/decision-models.generated.d.ts.map +1 -0
- package/dist/decision-models.generated.js +47 -0
- package/dist/decision-models.generated.js.map +1 -0
- package/dist/decision-models.js +8 -0
- package/dist/decision-models.js.map +1 -0
- package/dist/env-api-keys.d.ts +28 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +185 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/image-generation-error.d.ts +210 -0
- package/dist/image-generation-error.d.ts.map +1 -0
- package/dist/image-generation-error.js +442 -0
- package/dist/image-generation-error.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 +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy-bedrock-provider.d.ts +10 -0
- package/dist/lazy-bedrock-provider.d.ts.map +1 -0
- package/dist/lazy-bedrock-provider.js +13 -0
- package/dist/lazy-bedrock-provider.js.map +1 -0
- package/dist/lazy-oauth.d.ts +10 -0
- package/dist/lazy-oauth.d.ts.map +1 -0
- package/dist/lazy-oauth.js +22 -0
- package/dist/lazy-oauth.js.map +1 -0
- package/dist/legacy-api-aliases.d.ts +42 -0
- package/dist/legacy-api-aliases.d.ts.map +1 -0
- package/dist/legacy-api-aliases.js +49 -0
- package/dist/legacy-api-aliases.js.map +1 -0
- package/dist/model-catalog.d.ts +33 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +46 -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 +297 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +183 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +185 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +817 -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/provider-id.d.ts +2 -0
- package/dist/provider-id.d.ts.map +1 -0
- package/dist/provider-id.js +4 -0
- package/dist/provider-id.js.map +1 -0
- package/dist/providers/all.d.ts +41 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +145 -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 +5 -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 +5 -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 +4 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +87 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.models.d.ts +5 -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 +3 -0
- package/dist/providers/azure-openai-responses.js.map +1 -0
- package/dist/providers/azure-openai-responses.models.d.ts +3 -0
- package/dist/providers/azure-openai-responses.models.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.models.js +5 -0
- package/dist/providers/azure-openai-responses.models.js.map +1 -0
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.d.ts.map +1 -0
- package/dist/providers/azure.js +41 -0
- package/dist/providers/azure.js.map +1 -0
- package/dist/providers/azure.models.d.ts +5 -0
- package/dist/providers/azure.models.d.ts.map +1 -0
- package/dist/providers/azure.models.js +8 -0
- package/dist/providers/azure.models.js.map +1 -0
- package/dist/providers/baseten.d.ts +3 -0
- package/dist/providers/baseten.d.ts.map +1 -0
- package/dist/providers/baseten.js +15 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +5 -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 +5 -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 +21 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +5 -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 +5 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.js +8 -0
- package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
- package/dist/providers/compat-schema.d.ts +549 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +452 -0
- package/dist/providers/compat-schema.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -0
- package/dist/providers/data/amazon-bedrock.json +1 -0
- package/dist/providers/data/ant-ling.json +1 -0
- package/dist/providers/data/anthropic.json +1 -0
- package/dist/providers/data/azure.json +1 -0
- package/dist/providers/data/baseten.json +1 -0
- package/dist/providers/data/cerebras.json +1 -0
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
- package/dist/providers/data/cloudflare-workers-ai.json +1 -0
- package/dist/providers/data/deepseek.json +1 -0
- package/dist/providers/data/fireworks.json +1 -0
- package/dist/providers/data/github-copilot.json +1 -0
- package/dist/providers/data/google-vertex.json +1 -0
- package/dist/providers/data/google.json +1 -0
- package/dist/providers/data/groq.json +1 -0
- package/dist/providers/data/huggingface.json +1 -0
- package/dist/providers/data/kimi-coding.json +1 -0
- package/dist/providers/data/meta.json +1 -0
- package/dist/providers/data/minimax-cn.json +1 -0
- package/dist/providers/data/minimax.json +1 -0
- package/dist/providers/data/mistral.json +1 -0
- package/dist/providers/data/moonshotai-cn.json +1 -0
- package/dist/providers/data/moonshotai.json +1 -0
- package/dist/providers/data/nvidia.json +1 -0
- package/dist/providers/data/openai-codex.json +1 -0
- package/dist/providers/data/openai-decisions.json +1 -0
- package/dist/providers/data/openai-images.json +1 -0
- package/dist/providers/data/openai.json +1 -0
- package/dist/providers/data/opencode-go.json +1 -0
- package/dist/providers/data/opencode.json +1 -0
- package/dist/providers/data/openrouter.json +1 -0
- package/dist/providers/data/qwen-token-plan-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -0
- package/dist/providers/data/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 +5 -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 +521 -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 +5 -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-account.d.ts +18 -0
- package/dist/providers/github-copilot-account.d.ts.map +1 -0
- package/dist/providers/github-copilot-account.js +57 -0
- package/dist/providers/github-copilot-account.js.map +1 -0
- package/dist/providers/github-copilot-capabilities.d.ts +67 -0
- package/dist/providers/github-copilot-capabilities.d.ts.map +1 -0
- package/dist/providers/github-copilot-capabilities.js +81 -0
- package/dist/providers/github-copilot-capabilities.js.map +1 -0
- package/dist/providers/github-copilot-env.d.ts +41 -0
- package/dist/providers/github-copilot-env.d.ts.map +1 -0
- package/dist/providers/github-copilot-env.js +108 -0
- package/dist/providers/github-copilot-env.js.map +1 -0
- package/dist/providers/github-copilot-errors.d.ts +255 -0
- package/dist/providers/github-copilot-errors.d.ts.map +1 -0
- package/dist/providers/github-copilot-errors.js +764 -0
- package/dist/providers/github-copilot-errors.js.map +1 -0
- package/dist/providers/github-copilot-stream-attempt.d.ts +27 -0
- package/dist/providers/github-copilot-stream-attempt.d.ts.map +1 -0
- package/dist/providers/github-copilot-stream-attempt.js +45 -0
- package/dist/providers/github-copilot-stream-attempt.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +40 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +363 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -0
- package/dist/providers/images/register-builtins.d.ts.map +1 -0
- package/dist/providers/images/register-builtins.js +52 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -0
- package/dist/providers/mistral.models.d.ts.map +1 -0
- package/dist/providers/mistral.models.js +8 -0
- package/dist/providers/mistral.models.js.map +1 -0
- package/dist/providers/model-schema.d.ts +91 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +57 -0
- package/dist/providers/model-schema.js.map +1 -0
- package/dist/providers/moonshotai-cn.d.ts +3 -0
- package/dist/providers/moonshotai-cn.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.js +15 -0
- package/dist/providers/moonshotai-cn.js.map +1 -0
- package/dist/providers/moonshotai-cn.models.d.ts +5 -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 +5 -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/morph.d.ts +3 -0
- package/dist/providers/morph.d.ts.map +1 -0
- package/dist/providers/morph.js +22 -0
- package/dist/providers/morph.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 +5 -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 +25 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/openai-codex.models.d.ts +5 -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-decisions.d.ts +3 -0
- package/dist/providers/openai-decisions.d.ts.map +1 -0
- package/dist/providers/openai-decisions.js +19 -0
- package/dist/providers/openai-decisions.js.map +1 -0
- package/dist/providers/openai-decisions.models.d.ts +5 -0
- package/dist/providers/openai-decisions.models.d.ts.map +1 -0
- package/dist/providers/openai-decisions.models.js +8 -0
- package/dist/providers/openai-decisions.models.js.map +1 -0
- package/dist/providers/openai-images.d.ts +3 -0
- package/dist/providers/openai-images.d.ts.map +1 -0
- package/dist/providers/openai-images.js +19 -0
- package/dist/providers/openai-images.js.map +1 -0
- package/dist/providers/openai-images.models.d.ts +5 -0
- package/dist/providers/openai-images.models.d.ts.map +1 -0
- package/dist/providers/openai-images.models.js +8 -0
- package/dist/providers/openai-images.models.js.map +1 -0
- package/dist/providers/openai-mid-convo-effort.d.ts +2 -0
- package/dist/providers/openai-mid-convo-effort.d.ts.map +1 -0
- package/dist/providers/openai-mid-convo-effort.js +8 -0
- package/dist/providers/openai-mid-convo-effort.js.map +1 -0
- package/dist/providers/openai-subscription-models.d.ts +3 -0
- package/dist/providers/openai-subscription-models.d.ts.map +1 -0
- package/dist/providers/openai-subscription-models.js +19 -0
- package/dist/providers/openai-subscription-models.js.map +1 -0
- package/dist/providers/openai.d.ts +4 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +48 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.models.d.ts +5 -0
- package/dist/providers/openai.models.d.ts.map +1 -0
- package/dist/providers/openai.models.js +8 -0
- package/dist/providers/openai.models.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +5 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +22 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-go.models.d.ts +5 -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.d.ts +5 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +24 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/providers/opencode.models.d.ts +5 -0
- package/dist/providers/opencode.models.d.ts.map +1 -0
- package/dist/providers/opencode.models.js +8 -0
- package/dist/providers/opencode.models.js.map +1 -0
- package/dist/providers/openrouter-api.d.ts +40 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +41 -0
- package/dist/providers/openrouter-api.js.map +1 -0
- package/dist/providers/openrouter.d.ts +13 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +88 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/openrouter.models.d.ts +5 -0
- package/dist/providers/openrouter.models.d.ts.map +1 -0
- package/dist/providers/openrouter.models.js +8 -0
- package/dist/providers/openrouter.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.js +20 -0
- package/dist/providers/qwen-token-plan-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts +5 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.js +20 -0
- package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts +5 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +20 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +5 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
- package/dist/providers/qwen-token-plan.d.ts +3 -0
- package/dist/providers/qwen-token-plan.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.js +20 -0
- package/dist/providers/qwen-token-plan.js.map +1 -0
- package/dist/providers/qwen-token-plan.models.d.ts +5 -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/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 +5 -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 +5 -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 +17 -0
- package/dist/providers/vercel-ai-gateway.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +845 -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/azure-openai-thinking-level-map.d.ts +19 -0
- package/dist/utils/azure-openai-thinking-level-map.d.ts.map +1 -0
- package/dist/utils/azure-openai-thinking-level-map.js +45 -0
- package/dist/utils/azure-openai-thinking-level-map.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/document-input.d.ts +21 -0
- package/dist/utils/document-input.d.ts.map +1 -0
- package/dist/utils/document-input.js +28 -0
- package/dist/utils/document-input.js.map +1 -0
- package/dist/utils/error-body.d.ts +40 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +177 -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 +107 -0
- package/dist/utils/estimate.js.map +1 -0
- package/dist/utils/event-stream.d.ts +24 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +118 -0
- package/dist/utils/event-stream.js.map +1 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.d.ts +4 -0
- package/dist/utils/headers.d.ts.map +1 -0
- package/dist/utils/headers.js +20 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/identity.d.ts +67 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +148 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/inline-images.d.ts +24 -0
- package/dist/utils/inline-images.d.ts.map +1 -0
- package/dist/utils/inline-images.js +55 -0
- package/dist/utils/inline-images.js.map +1 -0
- package/dist/utils/json-parse.d.ts +18 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +167 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +12 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +58 -0
- package/dist/utils/model-operations.js.map +1 -0
- package/dist/utils/models-dev-catalog.d.ts +324 -0
- package/dist/utils/models-dev-catalog.d.ts.map +1 -0
- package/dist/utils/models-dev-catalog.js +3166 -0
- package/dist/utils/models-dev-catalog.js.map +1 -0
- package/dist/utils/models-dev-reasoning-options.d.ts +18 -0
- package/dist/utils/models-dev-reasoning-options.d.ts.map +1 -0
- package/dist/utils/models-dev-reasoning-options.js +20 -0
- package/dist/utils/models-dev-reasoning-options.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 +141 -0
- package/dist/utils/node-http-proxy.js.map +1 -0
- package/dist/utils/oauth-page.d.ts +2 -0
- package/dist/utils/oauth-page.d.ts.map +1 -0
- package/dist/utils/oauth-page.js +2 -0
- package/dist/utils/oauth-page.js.map +1 -0
- package/dist/utils/openrouter-cost.d.ts +24 -0
- package/dist/utils/openrouter-cost.d.ts.map +1 -0
- package/dist/utils/openrouter-cost.js +34 -0
- package/dist/utils/openrouter-cost.js.map +1 -0
- package/dist/utils/overflow.d.ts +73 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +204 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/provider-env.d.ts +12 -0
- package/dist/utils/provider-env.d.ts.map +1 -0
- package/dist/utils/provider-env.js +51 -0
- package/dist/utils/provider-env.js.map +1 -0
- package/dist/utils/provider-retry.d.ts +21 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +100 -0
- package/dist/utils/provider-retry.js.map +1 -0
- package/dist/utils/request-admission.d.ts +12 -0
- package/dist/utils/request-admission.d.ts.map +1 -0
- package/dist/utils/request-admission.js +37 -0
- package/dist/utils/request-admission.js.map +1 -0
- package/dist/utils/retry-hints.d.ts +15 -0
- package/dist/utils/retry-hints.d.ts.map +1 -0
- package/dist/utils/retry-hints.js +130 -0
- package/dist/utils/retry-hints.js.map +1 -0
- package/dist/utils/retry.d.ts +78 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +251 -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/sse.d.ts +29 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +73 -0
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/stream-deadline.d.ts +78 -0
- package/dist/utils/stream-deadline.d.ts.map +1 -0
- package/dist/utils/stream-deadline.js +205 -0
- package/dist/utils/stream-deadline.js.map +1 -0
- package/dist/utils/streaming-json.d.ts +84 -0
- package/dist/utils/streaming-json.d.ts.map +1 -0
- package/dist/utils/streaming-json.js +513 -0
- package/dist/utils/streaming-json.js.map +1 -0
- package/dist/utils/text.d.ts +21 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +45 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/thinking-off.d.ts +23 -0
- package/dist/utils/thinking-off.d.ts.map +1 -0
- package/dist/utils/thinking-off.js +51 -0
- package/dist/utils/thinking-off.js.map +1 -0
- package/dist/utils/transcript.d.ts +101 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +218 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils/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 +46 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +24 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +363 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/version.d.ts +2 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +3 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +138 -4
|
@@ -0,0 +1,1301 @@
|
|
|
1
|
+
import { BedrockRuntimeClient, BedrockRuntimeServiceException, StopReason as BedrockStopReason, CachePointType, CacheTTL, ConversationRole, ConverseStreamCommand, DocumentFormat, ImageFormat, ToolResultStatus, } from "@aws-sdk/client-bedrock-runtime";
|
|
2
|
+
import { NodeHttpHandler } from "@smithy/node-http-handler";
|
|
3
|
+
import { HttpProxyAgent } from "http-proxy-agent";
|
|
4
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
5
|
+
import { calculateCost } from "../models.js";
|
|
6
|
+
import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
|
|
7
|
+
import { assertSupportedDocumentMimeType } from "../utils/document-input.js";
|
|
8
|
+
import { inlineImageMimeType, unsupportedImagePlaceholder } from "../utils/inline-images.js";
|
|
9
|
+
import { normalizeProviderError } from "../utils/error-body.js";
|
|
10
|
+
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
11
|
+
import { providerHeadersToRecord } from "../utils/headers.js";
|
|
12
|
+
import { getClientVersion } from "../utils/identity.js";
|
|
13
|
+
import { resolveHttpProxyUrlForTarget } from "../utils/node-http-proxy.js";
|
|
14
|
+
import { getAtomicEnvValue, getProviderEnvValue } from "../utils/provider-env.js";
|
|
15
|
+
import { getProviderRetryAfterMs } from "../utils/retry-hints.js";
|
|
16
|
+
import { createStreamDeadline, withStreamDeadline } from "../utils/stream-deadline.js";
|
|
17
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
18
|
+
import { ToolCallArgumentsStream } from "../utils/streaming-json.js";
|
|
19
|
+
import { getSystemMessageText } from "../utils/text.js";
|
|
20
|
+
import { appendThinkingOffFallbackDiagnostic, getThinkingOffFallbackLevel } from "../utils/thinking-off.js";
|
|
21
|
+
import { collapseSystemMessages, getCurrentTools, getInitialSystemMessage, withoutInitialSystemMessage, } from "../utils/transcript.js";
|
|
22
|
+
import { ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE, getJsonSchemaToolParameters, prefersJsonSchemaStrictSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
23
|
+
import { adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToContext, clampReasoning, } from "./simple-options.js";
|
|
24
|
+
import { hasExceededStrictToolLimits, isStrictToolLimitErrorMessage, markStrictToolLimitsExceeded, } from "./strict-tool-limits.js";
|
|
25
|
+
import { splitErrorToolResultImages, transformMessages } from "./transform-messages.js";
|
|
26
|
+
const EMPTY_TEXT_PLACEHOLDER = "<empty>";
|
|
27
|
+
const THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
28
|
+
/** Matches the placeholder the Anthropic API path uses for redacted thinking. */
|
|
29
|
+
const REDACTED_THINKING_PLACEHOLDER = "[Reasoning redacted]";
|
|
30
|
+
export const stream = (model, context, options = {}) => {
|
|
31
|
+
const stream = new AssistantMessageEventStream();
|
|
32
|
+
// Bedrock has no mid-conversation system messages; fold them into the leading prompt.
|
|
33
|
+
const normalizedContext = collapseSystemMessages(context);
|
|
34
|
+
(async () => {
|
|
35
|
+
const output = {
|
|
36
|
+
role: "assistant",
|
|
37
|
+
content: [],
|
|
38
|
+
api: "bedrock-converse-stream",
|
|
39
|
+
provider: model.provider,
|
|
40
|
+
model: model.id,
|
|
41
|
+
usage: {
|
|
42
|
+
input: 0,
|
|
43
|
+
output: 0,
|
|
44
|
+
cacheRead: 0,
|
|
45
|
+
cacheWrite: 0,
|
|
46
|
+
totalTokens: 0,
|
|
47
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
48
|
+
},
|
|
49
|
+
stopReason: "pending",
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
};
|
|
52
|
+
const openBlocks = new Map();
|
|
53
|
+
// A profile explicitly configured through pi's auth flow (the `profile`
|
|
54
|
+
// option or scoped `AWS_PROFILE` on the stored credential's env) must win
|
|
55
|
+
// over ambient AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY. The SDK default
|
|
56
|
+
// chain already prefers a configured profile over env keys, but only when
|
|
57
|
+
// `credentials` is not set on the client config. See #6957.
|
|
58
|
+
const optionsProfile = options.profile || options.env?.AWS_PROFILE;
|
|
59
|
+
const config = {
|
|
60
|
+
profile: optionsProfile || getProviderEnvValue("AWS_PROFILE", options.env),
|
|
61
|
+
customUserAgent: bedrockUserAgent(options.identity),
|
|
62
|
+
// AWS counts the initial request as an attempt; preserve SDK defaults when omitted.
|
|
63
|
+
...(options.maxRetries !== undefined ? { maxAttempts: options.maxRetries + 1 } : {}),
|
|
64
|
+
};
|
|
65
|
+
const configuredRegion = getConfiguredBedrockRegion(options);
|
|
66
|
+
const hasAmbientConfiguredProfile = Boolean(getProviderEnvValue("AWS_PROFILE"));
|
|
67
|
+
const endpointRegion = getStandardBedrockEndpointRegion(model.baseUrl);
|
|
68
|
+
const useExplicitEndpoint = shouldUseExplicitBedrockEndpoint(model.baseUrl, configuredRegion, hasAmbientConfiguredProfile);
|
|
69
|
+
// Only pin standard AWS Bedrock runtime endpoints when no region or ambient AWS_PROFILE is configured.
|
|
70
|
+
// This preserves custom endpoints (VPC/proxy) from #3402 without forcing built-in
|
|
71
|
+
// catalog defaults such as us-east-1 to override AWS_REGION/AWS_PROFILE.
|
|
72
|
+
if (useExplicitEndpoint) {
|
|
73
|
+
config.endpoint = model.baseUrl;
|
|
74
|
+
}
|
|
75
|
+
// Resolve bearer token for Bedrock API key auth.
|
|
76
|
+
const skipAuth = getProviderEnvValue("AWS_BEDROCK_SKIP_AUTH", options.env) === "1";
|
|
77
|
+
const bearerToken = options.bearerToken ||
|
|
78
|
+
options.apiKey ||
|
|
79
|
+
getProviderEnvValue("AWS_BEARER_TOKEN_BEDROCK", options.env) ||
|
|
80
|
+
undefined;
|
|
81
|
+
const useBearerToken = bearerToken !== undefined && !skipAuth;
|
|
82
|
+
// in Node.js/Bun environment only
|
|
83
|
+
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
|
|
84
|
+
// Region resolution: ARN-embedded > explicit option > env vars > SDK default chain.
|
|
85
|
+
// When the model ID is an inference profile ARN, extract the region from it.
|
|
86
|
+
// This avoids conflicts with AWS_REGION set for other services.
|
|
87
|
+
const arnRegionMatch = model.id.match(/^arn:aws(?:-[a-z0-9-]+)?:bedrock:([a-z0-9-]+):/);
|
|
88
|
+
if (arnRegionMatch) {
|
|
89
|
+
config.region = arnRegionMatch[1];
|
|
90
|
+
}
|
|
91
|
+
else if (configuredRegion) {
|
|
92
|
+
config.region = configuredRegion;
|
|
93
|
+
}
|
|
94
|
+
else if (endpointRegion && useExplicitEndpoint) {
|
|
95
|
+
config.region = endpointRegion;
|
|
96
|
+
}
|
|
97
|
+
else if (!hasAmbientConfiguredProfile) {
|
|
98
|
+
config.region = "us-east-1";
|
|
99
|
+
}
|
|
100
|
+
// Support proxies that don't need authentication
|
|
101
|
+
if (skipAuth) {
|
|
102
|
+
config.credentials = {
|
|
103
|
+
accessKeyId: "dummy-access-key",
|
|
104
|
+
secretAccessKey: "dummy-secret-key",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const credentials = getConfiguredBedrockCredentials(options.env);
|
|
108
|
+
if (!skipAuth && credentials && !optionsProfile) {
|
|
109
|
+
config.credentials = credentials;
|
|
110
|
+
}
|
|
111
|
+
const proxyUrl = resolveHttpProxyUrlForTarget(model.baseUrl, options.env);
|
|
112
|
+
if (proxyUrl) {
|
|
113
|
+
// Bedrock runtime uses NodeHttp2Handler by default since v3.798.0, which is based
|
|
114
|
+
// on `http2` module and has no support for http agent.
|
|
115
|
+
// Use NodeHttpHandler to support HTTP(S) proxy agents.
|
|
116
|
+
config.requestHandler = new NodeHttpHandler({
|
|
117
|
+
httpAgent: new HttpProxyAgent(proxyUrl),
|
|
118
|
+
httpsAgent: new HttpsProxyAgent(proxyUrl),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else if (getProviderEnvValue("AWS_BEDROCK_FORCE_HTTP1", options.env) === "1") {
|
|
122
|
+
// Some custom endpoints require HTTP/1.1 instead of HTTP/2
|
|
123
|
+
config.requestHandler = new NodeHttpHandler();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Non-Node environment (browser): fall back to us-east-1 since
|
|
128
|
+
// there's no config file resolution available.
|
|
129
|
+
config.region =
|
|
130
|
+
configuredRegion || (endpointRegion && useExplicitEndpoint ? endpointRegion : undefined) || "us-east-1";
|
|
131
|
+
}
|
|
132
|
+
if (useBearerToken) {
|
|
133
|
+
config.token = { token: bearerToken };
|
|
134
|
+
config.authSchemePreference = ["httpBearerAuth"];
|
|
135
|
+
}
|
|
136
|
+
// Kept outside the try so the catch can still correlate a mid-stream failure:
|
|
137
|
+
// exceptions delivered as stream events carry no HTTP metadata of their own.
|
|
138
|
+
let responseRequestId;
|
|
139
|
+
const streamDeadline = createStreamDeadline(options.streamDeadlineMs, options.signal);
|
|
140
|
+
try {
|
|
141
|
+
const supportsStrictMode = model.compat?.supportsStrictMode ?? false;
|
|
142
|
+
const client = new BedrockRuntimeClient(config);
|
|
143
|
+
let observedRawResponse = false;
|
|
144
|
+
if (options.onResponse) {
|
|
145
|
+
addResponseHeadersMiddleware(client, options.onResponse, model, () => {
|
|
146
|
+
observedRawResponse = true;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const customHeaders = providerHeadersToRecord({ ...model.headers, ...options.headers });
|
|
150
|
+
if (customHeaders) {
|
|
151
|
+
addCustomHeadersMiddleware(client, customHeaders);
|
|
152
|
+
}
|
|
153
|
+
const cacheRetention = resolveCacheRetention(options.cacheRetention, options.env);
|
|
154
|
+
const inferenceMaxTokens = options.maxTokens ?? (isAnthropicClaudeModel(model) ? model.maxTokens : undefined);
|
|
155
|
+
const initialSystemMessage = getInitialSystemMessage(normalizedContext.messages);
|
|
156
|
+
const initialSystemPrompt = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : undefined;
|
|
157
|
+
let disablePreferredStrictTools = hasExceededStrictToolLimits(options.sessionId);
|
|
158
|
+
const reasoningOptions = resolveThinkingOffOptions(model, options, output);
|
|
159
|
+
let response;
|
|
160
|
+
for (;;) {
|
|
161
|
+
const tools = convertToolConfig(getCurrentTools(normalizedContext.messages), options.toolChoice, supportsStrictMode, model, disablePreferredStrictTools);
|
|
162
|
+
let commandInput = {
|
|
163
|
+
modelId: model.id,
|
|
164
|
+
messages: convertMessages(normalizedContext, model, cacheRetention, options.env),
|
|
165
|
+
system: buildSystemPrompt(initialSystemPrompt, model, cacheRetention, options.env),
|
|
166
|
+
inferenceConfig: {
|
|
167
|
+
...(inferenceMaxTokens !== undefined && { maxTokens: inferenceMaxTokens }),
|
|
168
|
+
// Claude Fable 5.1 rejects non-default `temperature`, `top_p`, and `top_k` on every
|
|
169
|
+
// request. Generated metadata marks such models `supportsTemperature: false`; every
|
|
170
|
+
// other model keeps sending the field exactly as before.
|
|
171
|
+
// https://platform.claude.com/docs/en/build-with-claude/thinking
|
|
172
|
+
...(options.temperature !== undefined &&
|
|
173
|
+
model.compat?.supportsTemperature !== false && { temperature: options.temperature }),
|
|
174
|
+
},
|
|
175
|
+
toolConfig: tools.toolConfig,
|
|
176
|
+
additionalModelRequestFields: buildAdditionalModelRequestFields(model, reasoningOptions),
|
|
177
|
+
...(options.requestMetadata !== undefined && { requestMetadata: options.requestMetadata }),
|
|
178
|
+
};
|
|
179
|
+
const nextCommandInput = await options?.onPayload?.(commandInput, model);
|
|
180
|
+
if (nextCommandInput !== undefined) {
|
|
181
|
+
commandInput = nextCommandInput;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
response = await client.send(new ConverseStreamCommand(commandInput), {
|
|
185
|
+
abortSignal: streamDeadline.signal,
|
|
186
|
+
});
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
// Bedrock checks the tool schemas before it starts the stream, so a retry never repeats streamed output.
|
|
191
|
+
if (options.signal?.aborted ||
|
|
192
|
+
disablePreferredStrictTools ||
|
|
193
|
+
!tools.hasPreferredStrictTools ||
|
|
194
|
+
!(error instanceof BedrockRuntimeServiceException) ||
|
|
195
|
+
error.name !== "ValidationException" ||
|
|
196
|
+
!isStrictToolLimitErrorMessage(error.message)) {
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
disablePreferredStrictTools = true;
|
|
200
|
+
markStrictToolLimitsExceeded(options.sessionId);
|
|
201
|
+
appendAssistantMessageDiagnostic(output, {
|
|
202
|
+
type: "bedrock_strict_tools_fallback",
|
|
203
|
+
timestamp: Date.now(),
|
|
204
|
+
error: { message: error.message },
|
|
205
|
+
details: { reason: "strict_tool_limits_exceeded" },
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
responseRequestId = normalizeDiagnosticValue(response.$metadata.requestId);
|
|
210
|
+
if (!observedRawResponse && response.$metadata.httpStatusCode !== undefined) {
|
|
211
|
+
const responseHeaders = {};
|
|
212
|
+
if (response.$metadata.requestId) {
|
|
213
|
+
responseHeaders["x-amzn-requestid"] = response.$metadata.requestId;
|
|
214
|
+
}
|
|
215
|
+
await options?.onResponse?.({ status: response.$metadata.httpStatusCode, headers: responseHeaders }, model);
|
|
216
|
+
}
|
|
217
|
+
for await (const item of withStreamDeadline(response.stream, streamDeadline.deadlineMs, streamDeadline.abort)) {
|
|
218
|
+
await options.onProviderStreamEvent?.(item, model);
|
|
219
|
+
if (item.messageStart) {
|
|
220
|
+
if (item.messageStart.role !== ConversationRole.ASSISTANT) {
|
|
221
|
+
throw new Error("Unexpected assistant message start but got user message start instead");
|
|
222
|
+
}
|
|
223
|
+
stream.push({ type: "start", partial: output });
|
|
224
|
+
}
|
|
225
|
+
else if (item.contentBlockStart) {
|
|
226
|
+
handleContentBlockStart(item.contentBlockStart, openBlocks, output, stream);
|
|
227
|
+
}
|
|
228
|
+
else if (item.contentBlockDelta) {
|
|
229
|
+
handleContentBlockDelta(item.contentBlockDelta, openBlocks, output, stream);
|
|
230
|
+
}
|
|
231
|
+
else if (item.contentBlockStop) {
|
|
232
|
+
handleContentBlockStop(item.contentBlockStop, openBlocks, output, stream);
|
|
233
|
+
}
|
|
234
|
+
else if (item.messageStop) {
|
|
235
|
+
output.rawStopReason = item.messageStop.stopReason;
|
|
236
|
+
const { stopReason, errorMessage } = mapStopReason(item.messageStop.stopReason);
|
|
237
|
+
output.stopReason = stopReason;
|
|
238
|
+
if (errorMessage) {
|
|
239
|
+
output.errorMessage = errorMessage;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (item.metadata) {
|
|
243
|
+
handleMetadata(item.metadata, model, output);
|
|
244
|
+
}
|
|
245
|
+
else if (item.internalServerException) {
|
|
246
|
+
throw item.internalServerException;
|
|
247
|
+
}
|
|
248
|
+
else if (item.modelStreamErrorException) {
|
|
249
|
+
throw item.modelStreamErrorException;
|
|
250
|
+
}
|
|
251
|
+
else if (item.validationException) {
|
|
252
|
+
throw item.validationException;
|
|
253
|
+
}
|
|
254
|
+
else if (item.throttlingException) {
|
|
255
|
+
throw item.throttlingException;
|
|
256
|
+
}
|
|
257
|
+
else if (item.serviceUnavailableException) {
|
|
258
|
+
throw item.serviceUnavailableException;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (options.signal?.aborted) {
|
|
262
|
+
throw new Error("Request was aborted");
|
|
263
|
+
}
|
|
264
|
+
if (output.stopReason === "pending") {
|
|
265
|
+
throw new Error("Bedrock stream ended without a stop reason");
|
|
266
|
+
}
|
|
267
|
+
if (output.stopReason === "error" || output.stopReason === "aborted") {
|
|
268
|
+
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
269
|
+
}
|
|
270
|
+
// A stream can settle without stopping every block, so finalize here too.
|
|
271
|
+
flushOpenBlocks(openBlocks, output);
|
|
272
|
+
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
273
|
+
stream.end();
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
flushOpenBlocks(openBlocks, output);
|
|
277
|
+
output.stopReason = options.signal?.aborted ? "aborted" : "error";
|
|
278
|
+
output.errorMessage = formatBedrockError(error);
|
|
279
|
+
output.retryAfterMs =
|
|
280
|
+
typeof error === "object" && error !== null ? getProviderRetryAfterMs(error) : undefined;
|
|
281
|
+
if (output.stopReason === "error") {
|
|
282
|
+
appendBedrockFailureDiagnostic(output, error, responseRequestId);
|
|
283
|
+
}
|
|
284
|
+
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
285
|
+
stream.end();
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
streamDeadline.cleanup();
|
|
289
|
+
}
|
|
290
|
+
})();
|
|
291
|
+
return stream;
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Human-readable prefixes for Bedrock SDK exception names.
|
|
295
|
+
* The downstream retry logic in agent-session matches patterns like
|
|
296
|
+
* `server.?error` and `service.?unavailable`, so we preserve the legacy
|
|
297
|
+
* prefix format rather than using the raw SDK exception name.
|
|
298
|
+
*/
|
|
299
|
+
const BEDROCK_ERROR_PREFIXES = {
|
|
300
|
+
InternalServerException: "Internal server error",
|
|
301
|
+
ModelStreamErrorException: "Model stream error",
|
|
302
|
+
ValidationException: "Validation error",
|
|
303
|
+
ThrottlingException: "Throttling error",
|
|
304
|
+
ServiceUnavailableException: "Service unavailable",
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Some models reject the account/profile's configured Bedrock data retention mode
|
|
308
|
+
* (e.g. "data retention mode 'default' is not available for this model"). Point
|
|
309
|
+
* users at the AWS docs explaining how to configure a supported mode.
|
|
310
|
+
*/
|
|
311
|
+
const BEDROCK_DATA_RETENTION_DOCS_URL = "https://docs.aws.amazon.com/bedrock/latest/userguide/data-retention.html";
|
|
312
|
+
/**
|
|
313
|
+
* Format a Bedrock error with a human-readable prefix.
|
|
314
|
+
* AWS SDK exceptions (both from `client.send()` and from stream event items)
|
|
315
|
+
* extend BedrockRuntimeServiceException. We map the `.name` to a stable
|
|
316
|
+
* human-readable prefix so downstream consumers (retry logic, context-overflow
|
|
317
|
+
* detection) can distinguish error categories via simple string matching.
|
|
318
|
+
*/
|
|
319
|
+
function formatBedrockError(error) {
|
|
320
|
+
const norm = normalizeProviderError(error);
|
|
321
|
+
// Surface the raw HTTP body (with status) when the SDK did not fold it into
|
|
322
|
+
// the message; otherwise fall back to the message. This is what stops a
|
|
323
|
+
// gateway 403 from collapsing to `Unknown: UnknownError`.
|
|
324
|
+
const core = !norm.messageCarriesBody && norm.status !== undefined && norm.body !== undefined
|
|
325
|
+
? `${norm.status}: ${norm.body}`
|
|
326
|
+
: norm.message;
|
|
327
|
+
const dataRetentionHint = /data retention mode/i.test(core)
|
|
328
|
+
? ` See ${BEDROCK_DATA_RETENTION_DOCS_URL} for supported data retention modes.`
|
|
329
|
+
: "";
|
|
330
|
+
if (error instanceof BedrockRuntimeServiceException) {
|
|
331
|
+
const prefix = BEDROCK_ERROR_PREFIXES[error.name] ?? error.name;
|
|
332
|
+
return `${prefix}: ${core}${dataRetentionHint}`;
|
|
333
|
+
}
|
|
334
|
+
return `${core}${dataRetentionHint}`;
|
|
335
|
+
}
|
|
336
|
+
/** Over-long header values are dropped rather than truncated: a truncated request id is not a request id. */
|
|
337
|
+
const MAX_BEDROCK_DIAGNOSTIC_VALUE_CHARS = 200;
|
|
338
|
+
function normalizeDiagnosticValue(value) {
|
|
339
|
+
if (typeof value !== "string")
|
|
340
|
+
return undefined;
|
|
341
|
+
const trimmed = value.trim();
|
|
342
|
+
if (trimmed.length === 0 || trimmed.length > MAX_BEDROCK_DIAGNOSTIC_VALUE_CHARS)
|
|
343
|
+
return undefined;
|
|
344
|
+
return trimmed;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* The SDK puts the modeled code on `error.name` for service exceptions and unmodeled stream errors alike, so
|
|
348
|
+
* do not narrow to `BedrockRuntimeServiceException`. Modeled Bedrock errors all end in `Exception`, unlike
|
|
349
|
+
* transport names such as `TimeoutError`.
|
|
350
|
+
*/
|
|
351
|
+
function extractBedrockErrorCode(error) {
|
|
352
|
+
if (!(error instanceof Error) || !error.name.endsWith("Exception"))
|
|
353
|
+
return undefined;
|
|
354
|
+
return normalizeDiagnosticValue(error.name);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Structured metadata alongside `errorMessage`, which stays byte-identical because `isRetryableAssistantError`
|
|
358
|
+
* matches against it. Unknown fields are omitted, never guessed: a modeled mid-stream exception reaches us as
|
|
359
|
+
* a bare object literal, leaving only `fallbackRequestId`. `details` only, as the throw is not always `Error`.
|
|
360
|
+
*/
|
|
361
|
+
function appendBedrockFailureDiagnostic(output, error, fallbackRequestId) {
|
|
362
|
+
const metadata = error?.$metadata;
|
|
363
|
+
const details = {};
|
|
364
|
+
if (typeof metadata?.httpStatusCode === "number")
|
|
365
|
+
details.status = metadata.httpStatusCode;
|
|
366
|
+
const errorCode = extractBedrockErrorCode(error);
|
|
367
|
+
if (errorCode !== undefined)
|
|
368
|
+
details.errorCode = errorCode;
|
|
369
|
+
const requestId = normalizeDiagnosticValue(metadata?.requestId) ?? fallbackRequestId;
|
|
370
|
+
if (requestId !== undefined)
|
|
371
|
+
details.requestId = requestId;
|
|
372
|
+
if (Object.keys(details).length === 0)
|
|
373
|
+
return;
|
|
374
|
+
appendAssistantMessageDiagnostic(output, { type: "bedrock_response_failure", timestamp: Date.now(), details });
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Header keys that must never be overwritten by caller-supplied headers.
|
|
378
|
+
* `host` and `x-amz-*` participate in the SigV4 canonical request; `authorization`
|
|
379
|
+
* is owned by SigV4 or the bearer-token path (config.token + authSchemePreference).
|
|
380
|
+
* Compared case-insensitively (caller key is lower-cased before lookup).
|
|
381
|
+
*/
|
|
382
|
+
const RESERVED_HEADER_EXACT = new Set(["authorization", "host"]);
|
|
383
|
+
function isReservedHeader(key) {
|
|
384
|
+
const lower = key.toLowerCase();
|
|
385
|
+
return lower.startsWith("x-amz-") || RESERVED_HEADER_EXACT.has(lower);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The client identity as AWS SDK user agent pairs. The SDK appends them to its own `User-Agent` and escapes characters
|
|
389
|
+
* that are not valid in a user agent token, so the detailed form is reduced to name and version.
|
|
390
|
+
*/
|
|
391
|
+
function bedrockUserAgent(identity) {
|
|
392
|
+
const mode = identity?.userAgent ?? "detailed";
|
|
393
|
+
if (typeof mode === "object")
|
|
394
|
+
return mode.custom;
|
|
395
|
+
return mode === "short" ? [["atomic"]] : [["atomic", getClientVersion(identity)]];
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Attach caller-supplied headers to the outgoing Bedrock request via a Smithy
|
|
399
|
+
* `build`-step middleware. The `build` step runs after request serialisation but
|
|
400
|
+
* before SigV4 signing, so injected headers are covered by the signature. Reserved
|
|
401
|
+
* SigV4 / auth headers (`x-amz-*`, `authorization`, `host`) are silently skipped;
|
|
402
|
+
* all other caller headers override any existing same-named header on the request.
|
|
403
|
+
*/
|
|
404
|
+
function addCustomHeadersMiddleware(client, headers) {
|
|
405
|
+
const middleware = (next) => async (args) => {
|
|
406
|
+
const request = args.request;
|
|
407
|
+
if (request && typeof request === "object" && "headers" in request) {
|
|
408
|
+
const requestHeaders = request.headers;
|
|
409
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
410
|
+
if (!isReservedHeader(key)) {
|
|
411
|
+
requestHeaders[key] = value;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return next(args);
|
|
416
|
+
};
|
|
417
|
+
client.middlewareStack.add(middleware, { step: "build", name: "pi-ai-custom-headers", priority: "low" });
|
|
418
|
+
}
|
|
419
|
+
function isSmithyHttpResponse(response) {
|
|
420
|
+
if (!response || typeof response !== "object")
|
|
421
|
+
return false;
|
|
422
|
+
const candidate = response;
|
|
423
|
+
return typeof candidate.statusCode === "number" && !!candidate.headers && typeof candidate.headers === "object";
|
|
424
|
+
}
|
|
425
|
+
function toProviderResponse(response) {
|
|
426
|
+
if (!isSmithyHttpResponse(response))
|
|
427
|
+
return undefined;
|
|
428
|
+
return { status: response.statusCode, headers: { ...response.headers } };
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Bedrock's modeled `$metadata` only preserves selected HTTP metadata (for example
|
|
432
|
+
* requestId), so custom gateway headers are otherwise lost before callers see
|
|
433
|
+
* `onResponse`. Capture the raw Smithy HTTP response at the deserialize step,
|
|
434
|
+
* after the SDK receives the response but before the event stream is consumed.
|
|
435
|
+
*/
|
|
436
|
+
function addResponseHeadersMiddleware(client, onResponse, model, onObserved) {
|
|
437
|
+
const middleware = (next) => async (args) => {
|
|
438
|
+
const result = await next(args);
|
|
439
|
+
const providerResponse = toProviderResponse(result.response);
|
|
440
|
+
if (providerResponse) {
|
|
441
|
+
onObserved();
|
|
442
|
+
await onResponse(providerResponse, model);
|
|
443
|
+
}
|
|
444
|
+
return result;
|
|
445
|
+
};
|
|
446
|
+
client.middlewareStack.add(middleware, { step: "deserialize", name: "pi-ai-response-headers" });
|
|
447
|
+
}
|
|
448
|
+
export const streamSimple = (model, context, options) => {
|
|
449
|
+
const base = {
|
|
450
|
+
...buildBaseOptions(model, context, options, undefined),
|
|
451
|
+
toolChoice: options?.toolChoice,
|
|
452
|
+
};
|
|
453
|
+
if (!options?.reasoning) {
|
|
454
|
+
return stream(model, context, { ...base, reasoning: undefined });
|
|
455
|
+
}
|
|
456
|
+
if (isAnthropicClaudeModel(model)) {
|
|
457
|
+
if (supportsAdaptiveThinking(model.id, model.name)) {
|
|
458
|
+
return stream(model, context, {
|
|
459
|
+
...base,
|
|
460
|
+
reasoning: options.reasoning,
|
|
461
|
+
thinkingBudgets: options.thinkingBudgets,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
// Undefined means the caller did not request an output cap; let the helper use the model cap.
|
|
465
|
+
// Do not coerce to 0 here, or the thinking budget would become the entire maxTokens value.
|
|
466
|
+
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
467
|
+
const maxTokens = clampMaxTokensToContext(model, context, adjusted.maxTokens);
|
|
468
|
+
return stream(model, context, {
|
|
469
|
+
...base,
|
|
470
|
+
maxTokens,
|
|
471
|
+
reasoning: options.reasoning,
|
|
472
|
+
thinkingBudgets: {
|
|
473
|
+
...(options.thinkingBudgets || {}),
|
|
474
|
+
[clampReasoning(options.reasoning)]: Math.min(adjusted.thinkingBudget, Math.max(0, maxTokens - 1024)),
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return stream(model, context, {
|
|
479
|
+
...base,
|
|
480
|
+
reasoning: options.reasoning,
|
|
481
|
+
thinkingBudgets: options.thinkingBudgets,
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
function handleContentBlockStart(event, openBlocks, output, stream) {
|
|
485
|
+
const start = event.start;
|
|
486
|
+
if (start?.toolUse) {
|
|
487
|
+
output.content.push({
|
|
488
|
+
type: "toolCall",
|
|
489
|
+
id: start.toolUse.toolUseId || "",
|
|
490
|
+
name: start.toolUse.name || "",
|
|
491
|
+
arguments: {},
|
|
492
|
+
});
|
|
493
|
+
const contentIndex = output.content.length - 1;
|
|
494
|
+
openBlocks.set(event.contentBlockIndex, { contentIndex, arguments: new ToolCallArgumentsStream() });
|
|
495
|
+
stream.push({ type: "toolcall_start", contentIndex, partial: output });
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function handleContentBlockDelta(event, openBlocks, output, stream) {
|
|
499
|
+
const contentBlockIndex = event.contentBlockIndex;
|
|
500
|
+
const delta = event.delta;
|
|
501
|
+
let open = openBlocks.get(contentBlockIndex);
|
|
502
|
+
let block = open === undefined ? undefined : output.content[open.contentIndex];
|
|
503
|
+
if (delta?.text !== undefined) {
|
|
504
|
+
// If no text block exists yet, create one, as `handleContentBlockStart` is not sent for text blocks
|
|
505
|
+
if (!open) {
|
|
506
|
+
output.content.push({ type: "text", text: "" });
|
|
507
|
+
open = { contentIndex: output.content.length - 1 };
|
|
508
|
+
openBlocks.set(contentBlockIndex, open);
|
|
509
|
+
block = output.content[open.contentIndex];
|
|
510
|
+
stream.push({ type: "text_start", contentIndex: open.contentIndex, partial: output });
|
|
511
|
+
}
|
|
512
|
+
if (block?.type === "text") {
|
|
513
|
+
block.text += delta.text;
|
|
514
|
+
stream.push({ type: "text_delta", contentIndex: open.contentIndex, delta: delta.text, partial: output });
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
else if (delta?.toolUse && block?.type === "toolCall" && open?.arguments !== undefined) {
|
|
518
|
+
block.arguments = open.arguments.append(delta.toolUse.input || "");
|
|
519
|
+
stream.push({
|
|
520
|
+
type: "toolcall_delta",
|
|
521
|
+
contentIndex: open.contentIndex,
|
|
522
|
+
delta: delta.toolUse.input || "",
|
|
523
|
+
partial: output,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
else if (delta?.reasoningContent) {
|
|
527
|
+
if (!open) {
|
|
528
|
+
output.content.push({ type: "thinking", thinking: "", thinkingSignature: "" });
|
|
529
|
+
open = { contentIndex: output.content.length - 1 };
|
|
530
|
+
openBlocks.set(contentBlockIndex, open);
|
|
531
|
+
block = output.content[open.contentIndex];
|
|
532
|
+
stream.push({ type: "thinking_start", contentIndex: open.contentIndex, partial: output });
|
|
533
|
+
}
|
|
534
|
+
if (block?.type === "thinking") {
|
|
535
|
+
const thinkingIndex = open.contentIndex;
|
|
536
|
+
if (delta.reasoningContent.text) {
|
|
537
|
+
block.thinking += delta.reasoningContent.text;
|
|
538
|
+
stream.push({
|
|
539
|
+
type: "thinking_delta",
|
|
540
|
+
contentIndex: thinkingIndex,
|
|
541
|
+
delta: delta.reasoningContent.text,
|
|
542
|
+
partial: output,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
// `thinkingSignature` holds either an Anthropic signature or an opaque redacted
|
|
546
|
+
// payload, never both: mixing them would corrupt whichever arrived first.
|
|
547
|
+
if (delta.reasoningContent.signature && !block.redacted) {
|
|
548
|
+
block.thinkingSignature = (block.thinkingSignature || "") + delta.reasoningContent.signature;
|
|
549
|
+
}
|
|
550
|
+
if (delta.reasoningContent.redactedContent?.length) {
|
|
551
|
+
// Encrypted reasoning from non-Anthropic models on Bedrock (e.g. OpenAI GPT-5.6).
|
|
552
|
+
// The payload is opaque, so keep it verbatim in `thinkingSignature` the way the
|
|
553
|
+
// Anthropic path stores redacted thinking, and replay it on the next turn.
|
|
554
|
+
if (!block.redacted) {
|
|
555
|
+
block.redacted = true;
|
|
556
|
+
block.thinkingSignature = "";
|
|
557
|
+
block.thinking += REDACTED_THINKING_PLACEHOLDER;
|
|
558
|
+
stream.push({
|
|
559
|
+
type: "thinking_delta",
|
|
560
|
+
contentIndex: thinkingIndex,
|
|
561
|
+
delta: REDACTED_THINKING_PLACEHOLDER,
|
|
562
|
+
partial: output,
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
open.redactedChunks ??= [];
|
|
566
|
+
open.redactedChunks.push(delta.reasoningContent.redactedContent);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Encodes buffered encrypted reasoning into `thinkingSignature`. The chunks stay in the stream state, never on the
|
|
573
|
+
* block: `Uint8Array` is not JSON and serializes to an index-keyed object roughly ten times the size of the base64
|
|
574
|
+
* payload.
|
|
575
|
+
*/
|
|
576
|
+
function flushRedactedContent(open, output) {
|
|
577
|
+
const block = output.content[open.contentIndex];
|
|
578
|
+
if (block?.type !== "thinking" || !open.redactedChunks)
|
|
579
|
+
return;
|
|
580
|
+
block.thinkingSignature = bytesToBase64(open.redactedChunks);
|
|
581
|
+
open.redactedChunks = undefined;
|
|
582
|
+
}
|
|
583
|
+
/** Ends the stream state of blocks a stream settled without stopping. */
|
|
584
|
+
function flushOpenBlocks(openBlocks, output) {
|
|
585
|
+
for (const open of openBlocks.values())
|
|
586
|
+
flushRedactedContent(open, output);
|
|
587
|
+
openBlocks.clear();
|
|
588
|
+
}
|
|
589
|
+
function handleMetadata(event, model, output) {
|
|
590
|
+
if (event.usage) {
|
|
591
|
+
output.usage.input = event.usage.inputTokens || 0;
|
|
592
|
+
output.usage.output = event.usage.outputTokens || 0;
|
|
593
|
+
output.usage.cacheRead = event.usage.cacheReadInputTokens || 0;
|
|
594
|
+
output.usage.cacheWrite = event.usage.cacheWriteInputTokens || 0;
|
|
595
|
+
output.usage.cacheWrite1h = event.usage.cacheDetails?.reduce((total, detail) => total + (detail.ttl === CacheTTL.ONE_HOUR ? (detail.inputTokens ?? 0) : 0), 0);
|
|
596
|
+
output.usage.totalTokens = event.usage.totalTokens || output.usage.input + output.usage.output;
|
|
597
|
+
calculateCost(model, output.usage);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function handleContentBlockStop(event, openBlocks, output, stream) {
|
|
601
|
+
const open = openBlocks.get(event.contentBlockIndex);
|
|
602
|
+
if (!open)
|
|
603
|
+
return;
|
|
604
|
+
openBlocks.delete(event.contentBlockIndex);
|
|
605
|
+
const index = open.contentIndex;
|
|
606
|
+
const block = output.content[index];
|
|
607
|
+
switch (block.type) {
|
|
608
|
+
case "text":
|
|
609
|
+
stream.push({ type: "text_end", contentIndex: index, content: block.text, partial: output });
|
|
610
|
+
break;
|
|
611
|
+
case "thinking":
|
|
612
|
+
flushRedactedContent(open, output);
|
|
613
|
+
stream.push({ type: "thinking_end", contentIndex: index, content: block.thinking, partial: output });
|
|
614
|
+
break;
|
|
615
|
+
case "toolCall":
|
|
616
|
+
if (open.arguments !== undefined)
|
|
617
|
+
Object.assign(block, open.arguments.finish());
|
|
618
|
+
stream.push({ type: "toolcall_end", contentIndex: index, toolCall: block, partial: output });
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Check if the model supports adaptive thinking (Opus 4.6+, Sonnet 4.6).
|
|
624
|
+
* Checks both model ID and model name to support application inference profiles
|
|
625
|
+
* whose ARNs don't contain the model name.
|
|
626
|
+
*/
|
|
627
|
+
function getModelMatchCandidates(modelId, modelName) {
|
|
628
|
+
const values = modelName ? [modelId, modelName] : [modelId];
|
|
629
|
+
return values.flatMap((value) => {
|
|
630
|
+
const lower = value.toLowerCase();
|
|
631
|
+
return [lower, lower.replace(/[\s_.:]+/g, "-")];
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
function supportsAdaptiveThinking(modelId, modelName) {
|
|
635
|
+
const candidates = getModelMatchCandidates(modelId, modelName);
|
|
636
|
+
return candidates.some((s) => s.includes("opus-4-6") ||
|
|
637
|
+
s.includes("opus-4-7") ||
|
|
638
|
+
s.includes("opus-4-8") ||
|
|
639
|
+
s.includes("opus-5") ||
|
|
640
|
+
s.includes("sonnet-4-6") ||
|
|
641
|
+
s.includes("sonnet-5") ||
|
|
642
|
+
s.includes("haiku-5") ||
|
|
643
|
+
s.includes("fable-5"));
|
|
644
|
+
}
|
|
645
|
+
function supportsNativeXhighEffort(model) {
|
|
646
|
+
const candidates = getModelMatchCandidates(model.id, model.name);
|
|
647
|
+
return candidates.some((s) => s.includes("opus-4-7") ||
|
|
648
|
+
s.includes("opus-4-8") ||
|
|
649
|
+
s.includes("opus-5") ||
|
|
650
|
+
s.includes("sonnet-5") ||
|
|
651
|
+
s.includes("haiku-5") ||
|
|
652
|
+
s.includes("fable-5"));
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Check if the model accepts `thinking.block_binding`. Opus 4.6 and Sonnet 4.6 reject it with
|
|
656
|
+
* "thinking.adaptive.block_binding: Extra inputs are not permitted".
|
|
657
|
+
*/
|
|
658
|
+
function supportsThinkingBlockBinding(model) {
|
|
659
|
+
const candidates = getModelMatchCandidates(model.id, model.name);
|
|
660
|
+
return candidates.some((s) => s.includes("opus-4-7") ||
|
|
661
|
+
s.includes("opus-4-8") ||
|
|
662
|
+
s.includes("opus-5") ||
|
|
663
|
+
s.includes("sonnet-5") ||
|
|
664
|
+
s.includes("haiku-5") ||
|
|
665
|
+
s.includes("fable-5"));
|
|
666
|
+
}
|
|
667
|
+
function mapThinkingLevelToEffort(model, level) {
|
|
668
|
+
if (level === "xhigh" && supportsNativeXhighEffort(model))
|
|
669
|
+
return "xhigh";
|
|
670
|
+
const mapped = level ? model.thinkingLevelMap?.[level] : undefined;
|
|
671
|
+
if (typeof mapped === "string")
|
|
672
|
+
return mapped;
|
|
673
|
+
switch (level) {
|
|
674
|
+
case "minimal":
|
|
675
|
+
case "low":
|
|
676
|
+
return "low";
|
|
677
|
+
case "medium":
|
|
678
|
+
return "medium";
|
|
679
|
+
case "high":
|
|
680
|
+
return "high";
|
|
681
|
+
default:
|
|
682
|
+
return "high";
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Resolve cache retention preference.
|
|
687
|
+
* Defaults to "short" and uses PI_CACHE_RETENTION for backward compatibility.
|
|
688
|
+
*/
|
|
689
|
+
function resolveCacheRetention(cacheRetention, env) {
|
|
690
|
+
if (cacheRetention) {
|
|
691
|
+
return cacheRetention;
|
|
692
|
+
}
|
|
693
|
+
if (getAtomicEnvValue("CACHE_RETENTION", env) === "long") {
|
|
694
|
+
return "long";
|
|
695
|
+
}
|
|
696
|
+
return "short";
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Check if the model is an Anthropic Claude model on Bedrock.
|
|
700
|
+
* Checks both model ID and model name to support application inference profiles
|
|
701
|
+
* whose ARNs don't contain the model name.
|
|
702
|
+
*/
|
|
703
|
+
function isAnthropicClaudeModel(model) {
|
|
704
|
+
const id = model.id.toLowerCase();
|
|
705
|
+
const name = model.name?.toLowerCase() ?? "";
|
|
706
|
+
return (id.includes("anthropic.claude") ||
|
|
707
|
+
id.includes("anthropic/claude") ||
|
|
708
|
+
name.includes("anthropic.claude") ||
|
|
709
|
+
name.includes("anthropic/claude") ||
|
|
710
|
+
name.includes("claude"));
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Check if the model supports prompt caching.
|
|
714
|
+
* Supported: Claude 3.5 Haiku, Claude 3.7 Sonnet, Claude 4.x models, Claude 5 models
|
|
715
|
+
*
|
|
716
|
+
* For base models and system-defined inference profiles the model ID / ARN
|
|
717
|
+
* contains the model name, so we can decide locally.
|
|
718
|
+
*
|
|
719
|
+
* For application inference profiles (whose ARNs don't contain the model name),
|
|
720
|
+
* also checks model.name which is user-controlled via models.json or registerProvider.
|
|
721
|
+
* As a last resort, set AWS_BEDROCK_FORCE_CACHE=1 to enable cache points.
|
|
722
|
+
* Amazon Nova models have automatic caching and don't need explicit cache points.
|
|
723
|
+
*/
|
|
724
|
+
function supportsPromptCaching(model, env) {
|
|
725
|
+
const candidates = getModelMatchCandidates(model.id, model.name);
|
|
726
|
+
const hasClaudeRef = candidates.some((s) => s.includes("claude"));
|
|
727
|
+
if (!hasClaudeRef) {
|
|
728
|
+
// Application inference profiles don't contain the model name in the ARN.
|
|
729
|
+
// Allow users to force cache points via environment variable.
|
|
730
|
+
if (getProviderEnvValue("AWS_BEDROCK_FORCE_CACHE", env) === "1")
|
|
731
|
+
return true;
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
// Claude 5 models (fable-5, opus-5, sonnet-5, haiku-5)
|
|
735
|
+
if (candidates.some((s) => s.includes("fable-5") || s.includes("opus-5") || s.includes("sonnet-5") || s.includes("haiku-5")))
|
|
736
|
+
return true;
|
|
737
|
+
// Claude 4.x models (opus-4, sonnet-4, haiku-4)
|
|
738
|
+
if (candidates.some((s) => s.includes("-4-")))
|
|
739
|
+
return true;
|
|
740
|
+
// Claude 3.7 Sonnet
|
|
741
|
+
if (candidates.some((s) => s.includes("claude-3-7-sonnet")))
|
|
742
|
+
return true;
|
|
743
|
+
// Claude 3.5 Haiku
|
|
744
|
+
if (candidates.some((s) => s.includes("claude-3-5-haiku")))
|
|
745
|
+
return true;
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Check if the model supports thinking signatures in reasoningContent.
|
|
750
|
+
* Only Anthropic Claude models support the signature field.
|
|
751
|
+
* Other models (OpenAI, Qwen, Minimax, Moonshot, etc.) reject it with:
|
|
752
|
+
* "This model doesn't support the reasoningContent.reasoningText.signature field"
|
|
753
|
+
*
|
|
754
|
+
* Checks both model ID and model name to support application inference profiles.
|
|
755
|
+
*/
|
|
756
|
+
function supportsThinkingSignature(model) {
|
|
757
|
+
return isAnthropicClaudeModel(model);
|
|
758
|
+
}
|
|
759
|
+
function buildSystemPrompt(systemPrompt, model, cacheRetention, env) {
|
|
760
|
+
if (!systemPrompt)
|
|
761
|
+
return undefined;
|
|
762
|
+
const blocks = [{ text: sanitizeSurrogates(systemPrompt) }];
|
|
763
|
+
// Add cache point for supported Claude models when caching is enabled
|
|
764
|
+
if (cacheRetention !== "none" && supportsPromptCaching(model, env)) {
|
|
765
|
+
blocks.push({
|
|
766
|
+
cachePoint: { type: CachePointType.DEFAULT, ...(cacheRetention === "long" ? { ttl: CacheTTL.ONE_HOUR } : {}) },
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
return blocks;
|
|
770
|
+
}
|
|
771
|
+
function normalizeToolCallId(id) {
|
|
772
|
+
const sanitized = id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
773
|
+
return sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;
|
|
774
|
+
}
|
|
775
|
+
function createNonBlankTextBlock(text) {
|
|
776
|
+
const sanitized = sanitizeSurrogates(text);
|
|
777
|
+
return sanitized.trim().length === 0 ? undefined : { text: sanitized };
|
|
778
|
+
}
|
|
779
|
+
function createRequiredTextBlock(text) {
|
|
780
|
+
return createNonBlankTextBlock(text) ?? { text: EMPTY_TEXT_PLACEHOLDER };
|
|
781
|
+
}
|
|
782
|
+
function sanitizeBedrockDocument(value) {
|
|
783
|
+
if (Array.isArray(value)) {
|
|
784
|
+
return value.map(sanitizeBedrockDocument);
|
|
785
|
+
}
|
|
786
|
+
if (value !== null && typeof value === "object") {
|
|
787
|
+
return Object.fromEntries(Object.entries(value)
|
|
788
|
+
.filter(([key]) => key.length > 0)
|
|
789
|
+
.map(([key, nestedValue]) => [key, sanitizeBedrockDocument(nestedValue)]));
|
|
790
|
+
}
|
|
791
|
+
return value;
|
|
792
|
+
}
|
|
793
|
+
function convertToolResultContent(content) {
|
|
794
|
+
const result = [];
|
|
795
|
+
for (const c of content) {
|
|
796
|
+
if (c.type === "image") {
|
|
797
|
+
result.push(createImageBlock(c.mimeType, c.data));
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
const textBlock = createNonBlankTextBlock(c.text);
|
|
801
|
+
if (textBlock)
|
|
802
|
+
result.push(textBlock);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (result.length === 0)
|
|
806
|
+
result.push({ text: EMPTY_TEXT_PLACEHOLDER });
|
|
807
|
+
return result;
|
|
808
|
+
}
|
|
809
|
+
function convertMessages(context, model, cacheRetention, env) {
|
|
810
|
+
const result = [];
|
|
811
|
+
const transformedMessages = transformMessages(withoutInitialSystemMessage(context.messages), model, normalizeToolCallId);
|
|
812
|
+
for (let i = 0; i < transformedMessages.length; i++) {
|
|
813
|
+
const m = transformedMessages[i];
|
|
814
|
+
switch (m.role) {
|
|
815
|
+
case "user": {
|
|
816
|
+
const content = [];
|
|
817
|
+
if (typeof m.content === "string") {
|
|
818
|
+
content.push(createRequiredTextBlock(m.content));
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
for (const c of m.content) {
|
|
822
|
+
switch (c.type) {
|
|
823
|
+
case "text": {
|
|
824
|
+
const textBlock = createNonBlankTextBlock(c.text);
|
|
825
|
+
if (textBlock)
|
|
826
|
+
content.push(textBlock);
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
case "image":
|
|
830
|
+
content.push(createImageBlock(c.mimeType, c.data));
|
|
831
|
+
break;
|
|
832
|
+
case "document":
|
|
833
|
+
content.push({ document: createDocumentBlock(c, content.length) });
|
|
834
|
+
break;
|
|
835
|
+
default:
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (content.length === 0)
|
|
840
|
+
content.push({ text: EMPTY_TEXT_PLACEHOLDER });
|
|
841
|
+
}
|
|
842
|
+
result.push({ role: ConversationRole.USER, content });
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
case "assistant": {
|
|
846
|
+
// Skip assistant messages with empty content (e.g., from aborted requests)
|
|
847
|
+
// Bedrock rejects messages with empty content arrays
|
|
848
|
+
if (m.content.length === 0) {
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
const contentBlocks = [];
|
|
852
|
+
for (const c of m.content) {
|
|
853
|
+
switch (c.type) {
|
|
854
|
+
case "text": {
|
|
855
|
+
// Skip empty text blocks
|
|
856
|
+
const textBlock = createNonBlankTextBlock(c.text);
|
|
857
|
+
if (!textBlock)
|
|
858
|
+
continue;
|
|
859
|
+
contentBlocks.push(textBlock);
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
case "toolCall":
|
|
863
|
+
contentBlocks.push({
|
|
864
|
+
toolUse: { toolUseId: c.id, name: c.name, input: sanitizeBedrockDocument(c.arguments) },
|
|
865
|
+
});
|
|
866
|
+
break;
|
|
867
|
+
case "thinking": {
|
|
868
|
+
// Encrypted reasoning is opaque: replay the stored payload as the
|
|
869
|
+
// `redactedContent` member instead of lowering it to reasoning text.
|
|
870
|
+
if (c.redacted) {
|
|
871
|
+
const redactedContent = decodeRedactedContent(c.thinkingSignature);
|
|
872
|
+
if (redactedContent?.length) {
|
|
873
|
+
contentBlocks.push({ reasoningContent: { redactedContent } });
|
|
874
|
+
}
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
// Skip empty thinking blocks
|
|
878
|
+
const thinking = sanitizeSurrogates(c.thinking);
|
|
879
|
+
if (thinking.trim().length === 0)
|
|
880
|
+
continue;
|
|
881
|
+
// Only Anthropic models support the signature field in reasoningText.
|
|
882
|
+
// For other models, we omit the signature to avoid errors like:
|
|
883
|
+
// "This model doesn't support the reasoningContent.reasoningText.signature field"
|
|
884
|
+
if (supportsThinkingSignature(model)) {
|
|
885
|
+
// Signatures arrive after thinking deltas. If a partial or externally
|
|
886
|
+
// persisted message lacks a signature, Bedrock rejects the replayed
|
|
887
|
+
// reasoning block. Fall back to plain text, matching Anthropic.
|
|
888
|
+
if (!c.thinkingSignature || c.thinkingSignature.trim().length === 0) {
|
|
889
|
+
contentBlocks.push({ text: thinking });
|
|
890
|
+
}
|
|
891
|
+
else {
|
|
892
|
+
contentBlocks.push({
|
|
893
|
+
reasoningContent: {
|
|
894
|
+
reasoningText: {
|
|
895
|
+
text: thinking,
|
|
896
|
+
signature: c.thinkingSignature,
|
|
897
|
+
},
|
|
898
|
+
},
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
contentBlocks.push({
|
|
904
|
+
reasoningContent: {
|
|
905
|
+
reasoningText: { text: thinking },
|
|
906
|
+
},
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
default:
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
// Skip if all content blocks were filtered out
|
|
916
|
+
if (contentBlocks.length === 0) {
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
result.push({
|
|
920
|
+
role: ConversationRole.ASSISTANT,
|
|
921
|
+
content: contentBlocks,
|
|
922
|
+
});
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
case "toolResult": {
|
|
926
|
+
// Collect all consecutive toolResult messages into a single user message
|
|
927
|
+
// Bedrock requires all tool results to be in one message
|
|
928
|
+
const toolResults = [];
|
|
929
|
+
// Claude rejects error tool results that contain anything but text, so for Claude their
|
|
930
|
+
// images follow all tool results of the turn (#10794). Other models keep them in place.
|
|
931
|
+
const errorImages = [];
|
|
932
|
+
let j = i;
|
|
933
|
+
while (j < transformedMessages.length && transformedMessages[j].role === "toolResult") {
|
|
934
|
+
const toolMsg = transformedMessages[j];
|
|
935
|
+
const split = isAnthropicClaudeModel(model) ? splitErrorToolResultImages(toolMsg) : undefined;
|
|
936
|
+
toolResults.push({
|
|
937
|
+
toolResult: {
|
|
938
|
+
toolUseId: toolMsg.toolCallId,
|
|
939
|
+
content: convertToolResultContent(split?.content ?? toolMsg.content),
|
|
940
|
+
status: toolMsg.isError ? ToolResultStatus.ERROR : ToolResultStatus.SUCCESS,
|
|
941
|
+
},
|
|
942
|
+
});
|
|
943
|
+
if (split) {
|
|
944
|
+
errorImages.push({ text: split.caption }, ...split.images.map((image) => createImageBlock(image.mimeType, image.data)));
|
|
945
|
+
}
|
|
946
|
+
j++;
|
|
947
|
+
}
|
|
948
|
+
// Skip the messages we've already processed
|
|
949
|
+
i = j - 1;
|
|
950
|
+
result.push({ role: ConversationRole.USER, content: [...toolResults, ...errorImages] });
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
default:
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
// Add cache point to the last user message for supported Claude models when caching is enabled
|
|
958
|
+
if (cacheRetention !== "none" && supportsPromptCaching(model, env) && result.length > 0) {
|
|
959
|
+
const lastMessage = result[result.length - 1];
|
|
960
|
+
if (lastMessage.role === ConversationRole.USER && lastMessage.content) {
|
|
961
|
+
lastMessage.content.push({
|
|
962
|
+
cachePoint: {
|
|
963
|
+
type: CachePointType.DEFAULT,
|
|
964
|
+
...(cacheRetention === "long" ? { ttl: CacheTTL.ONE_HOUR } : {}),
|
|
965
|
+
},
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return result;
|
|
970
|
+
}
|
|
971
|
+
function convertToolConfig(tools, toolChoice, supportsStrictMode, model, disablePreferredStrictTools) {
|
|
972
|
+
// Validate the requested choice before any early return. A forced choice on a model that
|
|
973
|
+
// rejects it is an error regardless of whether tools were supplied: returning `undefined` for
|
|
974
|
+
// an empty or absent tool list would discard the caller's instruction silently, which is the
|
|
975
|
+
// behavior this guard exists to prevent.
|
|
976
|
+
//
|
|
977
|
+
// Claude Fable 5.1 rejects forced tool use on every request with a 400, whichever platform
|
|
978
|
+
// serves it. Reject rather than rewriting to `auto`, which would discard an explicit caller
|
|
979
|
+
// instruction. Mirrors the guards in `anthropic-messages.ts` and `openai-completions.ts`.
|
|
980
|
+
// https://platform.claude.com/docs/en/build-with-claude/thinking
|
|
981
|
+
if (model.compat?.supportsForcedToolChoice === false) {
|
|
982
|
+
const isForced = toolChoice === "any" || (typeof toolChoice === "object" && toolChoice.type === "tool");
|
|
983
|
+
if (isForced) {
|
|
984
|
+
const requestedLabel = typeof toolChoice === "string" ? toolChoice : `tool "${toolChoice.name}"`;
|
|
985
|
+
throw new Error(`Model ${model.id} does not support forced tool choice (requested: ${requestedLabel}). ` +
|
|
986
|
+
`Use toolChoice "auto" with strict tool use or structured outputs instead.`);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
// `none` is never a forced choice, so this return can never skip a rejection above.
|
|
990
|
+
if (!tools?.length || toolChoice === "none")
|
|
991
|
+
return { toolConfig: undefined, hasPreferredStrictTools: false };
|
|
992
|
+
const strictProfile = isAnthropicClaudeModel(model) ? ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE : undefined;
|
|
993
|
+
let hasPreferredStrictTools = false;
|
|
994
|
+
const bedrockTools = tools.map((tool) => {
|
|
995
|
+
const preferred = prefersJsonSchemaStrictSampling(tool);
|
|
996
|
+
const strict = disablePreferredStrictTools && preferred
|
|
997
|
+
? undefined
|
|
998
|
+
: resolveJsonSchemaStrictSampling(tool, supportsStrictMode, strictProfile);
|
|
999
|
+
if (strict === true && preferred)
|
|
1000
|
+
hasPreferredStrictTools = true;
|
|
1001
|
+
return {
|
|
1002
|
+
toolSpec: {
|
|
1003
|
+
name: tool.name,
|
|
1004
|
+
description: tool.description,
|
|
1005
|
+
inputSchema: { json: getJsonSchemaToolParameters(tool, strict, strictProfile) },
|
|
1006
|
+
...(strict === true ? { strict: true } : {}),
|
|
1007
|
+
},
|
|
1008
|
+
};
|
|
1009
|
+
});
|
|
1010
|
+
let bedrockToolChoice;
|
|
1011
|
+
switch (toolChoice) {
|
|
1012
|
+
case "auto":
|
|
1013
|
+
bedrockToolChoice = { auto: {} };
|
|
1014
|
+
break;
|
|
1015
|
+
case "any":
|
|
1016
|
+
bedrockToolChoice = { any: {} };
|
|
1017
|
+
break;
|
|
1018
|
+
default:
|
|
1019
|
+
if (toolChoice?.type === "tool") {
|
|
1020
|
+
bedrockToolChoice = { tool: { name: toolChoice.name } };
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return { toolConfig: { tools: bedrockTools, toolChoice: bedrockToolChoice }, hasPreferredStrictTools };
|
|
1024
|
+
}
|
|
1025
|
+
function mapStopReason(reason) {
|
|
1026
|
+
switch (reason) {
|
|
1027
|
+
case BedrockStopReason.END_TURN:
|
|
1028
|
+
case BedrockStopReason.STOP_SEQUENCE:
|
|
1029
|
+
return { stopReason: "stop" };
|
|
1030
|
+
case BedrockStopReason.MAX_TOKENS:
|
|
1031
|
+
case BedrockStopReason.MODEL_CONTEXT_WINDOW_EXCEEDED:
|
|
1032
|
+
return { stopReason: "length" };
|
|
1033
|
+
case BedrockStopReason.TOOL_USE:
|
|
1034
|
+
return { stopReason: "toolUse" };
|
|
1035
|
+
default:
|
|
1036
|
+
return reason
|
|
1037
|
+
? { stopReason: "error", errorMessage: `Provider stopped with: ${reason}` }
|
|
1038
|
+
: { stopReason: "error" };
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
function getConfiguredBedrockRegion(options) {
|
|
1042
|
+
return (options.region ||
|
|
1043
|
+
getProviderEnvValue("AWS_REGION", options.env) ||
|
|
1044
|
+
getProviderEnvValue("AWS_DEFAULT_REGION", options.env) ||
|
|
1045
|
+
undefined);
|
|
1046
|
+
}
|
|
1047
|
+
function getConfiguredBedrockCredentials(env) {
|
|
1048
|
+
const accessKeyId = getProviderEnvValue("AWS_ACCESS_KEY_ID", env);
|
|
1049
|
+
const secretAccessKey = getProviderEnvValue("AWS_SECRET_ACCESS_KEY", env);
|
|
1050
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
1051
|
+
return undefined;
|
|
1052
|
+
}
|
|
1053
|
+
const sessionToken = getProviderEnvValue("AWS_SESSION_TOKEN", env);
|
|
1054
|
+
return {
|
|
1055
|
+
accessKeyId,
|
|
1056
|
+
secretAccessKey,
|
|
1057
|
+
...(sessionToken ? { sessionToken } : {}),
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
function getStandardBedrockEndpointRegion(baseUrl) {
|
|
1061
|
+
if (!baseUrl) {
|
|
1062
|
+
return undefined;
|
|
1063
|
+
}
|
|
1064
|
+
try {
|
|
1065
|
+
const { hostname } = new URL(baseUrl);
|
|
1066
|
+
const match = hostname.toLowerCase().match(/^bedrock-runtime(?:-fips)?\.([a-z0-9-]+)\.amazonaws\.com(?:\.cn)?$/);
|
|
1067
|
+
return match?.[1];
|
|
1068
|
+
}
|
|
1069
|
+
catch {
|
|
1070
|
+
return undefined;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function shouldUseExplicitBedrockEndpoint(baseUrl, configuredRegion, hasAmbientConfiguredProfile) {
|
|
1074
|
+
const endpointRegion = getStandardBedrockEndpointRegion(baseUrl);
|
|
1075
|
+
if (!endpointRegion) {
|
|
1076
|
+
return true;
|
|
1077
|
+
}
|
|
1078
|
+
return !configuredRegion && !hasAmbientConfiguredProfile;
|
|
1079
|
+
}
|
|
1080
|
+
function isGovCloudBedrockTarget(model, options) {
|
|
1081
|
+
const region = getConfiguredBedrockRegion(options);
|
|
1082
|
+
if (region?.toLowerCase().startsWith("us-gov-")) {
|
|
1083
|
+
return true;
|
|
1084
|
+
}
|
|
1085
|
+
const modelId = model.id.toLowerCase();
|
|
1086
|
+
return modelId.startsWith("us-gov.") || modelId.startsWith("arn:aws-us-gov:");
|
|
1087
|
+
}
|
|
1088
|
+
function isOpenAiGpt6AstraBedrockModel(model) {
|
|
1089
|
+
return /^(?:global\.|us\.)?openai\.gpt-6-astra$/.test(model.id);
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* With reasoning off, send the model's mapped `off` effort (GPT-6 Sol and Luna map it to `none`) in the same
|
|
1093
|
+
* field its other efforts use, as the OpenAI Responses provider does. Without a mapped value, send nothing
|
|
1094
|
+
* so Bedrock applies the model default.
|
|
1095
|
+
*/
|
|
1096
|
+
function buildOpenAiReasoningOffFields(model) {
|
|
1097
|
+
const off = model.thinkingLevelMap?.off;
|
|
1098
|
+
if (typeof off !== "string")
|
|
1099
|
+
return undefined;
|
|
1100
|
+
if (isOpenAiGpt6AstraBedrockModel(model))
|
|
1101
|
+
return { reasoning_effort: off };
|
|
1102
|
+
const candidates = getModelMatchCandidates(model.id, model.name);
|
|
1103
|
+
if (candidates.some((candidate) => candidate.includes("gpt-oss")))
|
|
1104
|
+
return { reasoning_effort: off };
|
|
1105
|
+
if (candidates.some((candidate) => candidate.includes("gpt-")))
|
|
1106
|
+
return { reasoning: { effort: off } };
|
|
1107
|
+
return undefined;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* The effort `additionalModelRequestFields` asks for: Claude's `output_config.effort`, or an OpenAI model's
|
|
1111
|
+
* `reasoning_effort` or `reasoning.effort`.
|
|
1112
|
+
*/
|
|
1113
|
+
function getRequestedThinkingEffort(fields) {
|
|
1114
|
+
return fields?.output_config?.effort ?? fields?.reasoning_effort ?? fields?.reasoning?.effort;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* A request without a reasoning level is thinking `off`. A model whose thinking map denies `off` runs at its
|
|
1118
|
+
* lowest supported level instead, the same request as selecting that level, when that level sends an effort.
|
|
1119
|
+
* A budget-thinking Claude model keeps sending no thinking fields, which already means no thinking, because
|
|
1120
|
+
* its level request also depends on the token adjustments `streamSimple` makes. The fallback is recorded on
|
|
1121
|
+
* `output`.
|
|
1122
|
+
*/
|
|
1123
|
+
function resolveThinkingOffOptions(model, options, output) {
|
|
1124
|
+
const level = options.reasoning ? undefined : getThinkingOffFallbackLevel(model);
|
|
1125
|
+
if (level === undefined)
|
|
1126
|
+
return options;
|
|
1127
|
+
const reasoningOptions = { ...options, reasoning: level };
|
|
1128
|
+
const providerThinkingLevel = getRequestedThinkingEffort(buildAdditionalModelRequestFields(model, reasoningOptions));
|
|
1129
|
+
if (providerThinkingLevel === undefined)
|
|
1130
|
+
return options;
|
|
1131
|
+
appendThinkingOffFallbackDiagnostic(output, level, providerThinkingLevel);
|
|
1132
|
+
return reasoningOptions;
|
|
1133
|
+
}
|
|
1134
|
+
function buildAdditionalModelRequestFields(model, options) {
|
|
1135
|
+
if (!model.reasoning) {
|
|
1136
|
+
return undefined;
|
|
1137
|
+
}
|
|
1138
|
+
if (!options.reasoning) {
|
|
1139
|
+
return buildOpenAiReasoningOffFields(model);
|
|
1140
|
+
}
|
|
1141
|
+
if (isAnthropicClaudeModel(model)) {
|
|
1142
|
+
// GovCloud Bedrock currently rejects the Claude thinking.display field.
|
|
1143
|
+
// Omit it there until the GovCloud Converse schema catches up.
|
|
1144
|
+
const isGovCloud = isGovCloudBedrockTarget(model, options);
|
|
1145
|
+
const display = isGovCloud ? undefined : (options.thinkingDisplay ?? "summarized");
|
|
1146
|
+
// Replayed signed thinking blocks are bound to the system prompt and tools they were
|
|
1147
|
+
// created with. Bedrock 400s on replay after either changes unless stale blocks are
|
|
1148
|
+
// dropped, matching the Anthropic provider. Skipped on GovCloud like display.
|
|
1149
|
+
const useBlockBinding = !isGovCloud && supportsThinkingBlockBinding(model);
|
|
1150
|
+
const result = supportsAdaptiveThinking(model.id, model.name)
|
|
1151
|
+
? {
|
|
1152
|
+
thinking: {
|
|
1153
|
+
type: "adaptive",
|
|
1154
|
+
...(display !== undefined ? { display } : {}),
|
|
1155
|
+
...(useBlockBinding ? { block_binding: { prefix_mismatch_behavior: "drop_block" } } : {}),
|
|
1156
|
+
},
|
|
1157
|
+
output_config: { effort: mapThinkingLevelToEffort(model, options.reasoning) },
|
|
1158
|
+
...(useBlockBinding ? { anthropic_beta: [THINKING_BINDING_CONTROLS_BETA] } : {}),
|
|
1159
|
+
}
|
|
1160
|
+
: (() => {
|
|
1161
|
+
const defaultBudgets = {
|
|
1162
|
+
minimal: 1024,
|
|
1163
|
+
low: 2048,
|
|
1164
|
+
medium: 8192,
|
|
1165
|
+
high: 16384,
|
|
1166
|
+
xhigh: 16384, // Budget-based Claude clamps extended levels to high
|
|
1167
|
+
max: 16384,
|
|
1168
|
+
};
|
|
1169
|
+
// Custom budgets only cover token-based levels through high.
|
|
1170
|
+
const level = options.reasoning === "xhigh" || options.reasoning === "max" ? "high" : options.reasoning;
|
|
1171
|
+
const budget = options.thinkingBudgets?.[level] ?? defaultBudgets[options.reasoning];
|
|
1172
|
+
return {
|
|
1173
|
+
thinking: {
|
|
1174
|
+
type: "enabled",
|
|
1175
|
+
budget_tokens: budget,
|
|
1176
|
+
...(display !== undefined ? { display } : {}),
|
|
1177
|
+
},
|
|
1178
|
+
};
|
|
1179
|
+
})();
|
|
1180
|
+
if (!supportsAdaptiveThinking(model.id, model.name) && (options.interleavedThinking ?? true)) {
|
|
1181
|
+
result.anthropic_beta = ["interleaved-thinking-2025-05-14"];
|
|
1182
|
+
}
|
|
1183
|
+
return result;
|
|
1184
|
+
}
|
|
1185
|
+
if (isOpenAiGpt6AstraBedrockModel(model)) {
|
|
1186
|
+
// Bedrock maps OpenAI Chat Completions fields that are not part of Converse's
|
|
1187
|
+
// inferenceConfig into additionalModelRequestFields. GPT-6-Astra uses the Chat
|
|
1188
|
+
// Completions spelling rather than the Responses API's nested reasoning object.
|
|
1189
|
+
// https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-openai.html
|
|
1190
|
+
return { reasoning_effort: mapThinkingLevelToEffort(model, options.reasoning) };
|
|
1191
|
+
}
|
|
1192
|
+
const candidates = getModelMatchCandidates(model.id, model.name);
|
|
1193
|
+
if (candidates.some((candidate) => candidate.includes("gpt-oss"))) {
|
|
1194
|
+
return { reasoning_effort: OPENAI_GPT_OSS_EFFORT[options.reasoning] };
|
|
1195
|
+
}
|
|
1196
|
+
if (candidates.some((candidate) => candidate.includes("gpt-"))) {
|
|
1197
|
+
const mapped = model.thinkingLevelMap?.[options.reasoning];
|
|
1198
|
+
return {
|
|
1199
|
+
reasoning: { effort: typeof mapped === "string" ? mapped : OPENAI_GPT_EFFORT[options.reasoning] },
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
return undefined;
|
|
1203
|
+
}
|
|
1204
|
+
const OPENAI_GPT_EFFORT = {
|
|
1205
|
+
minimal: "low",
|
|
1206
|
+
low: "low",
|
|
1207
|
+
medium: "medium",
|
|
1208
|
+
high: "high",
|
|
1209
|
+
xhigh: "xhigh",
|
|
1210
|
+
max: "max",
|
|
1211
|
+
};
|
|
1212
|
+
const OPENAI_GPT_OSS_EFFORT = {
|
|
1213
|
+
minimal: "low",
|
|
1214
|
+
low: "low",
|
|
1215
|
+
medium: "medium",
|
|
1216
|
+
high: "high",
|
|
1217
|
+
xhigh: "high",
|
|
1218
|
+
max: "high",
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Build a Bedrock `DocumentBlock`. Three things differ from the Anthropic path:
|
|
1222
|
+
*
|
|
1223
|
+
* - `name` is **required**, and AWS restricts it to alphanumerics, single whitespace runs,
|
|
1224
|
+
* hyphens, parentheses, and square brackets — then warns the field "is vulnerable to prompt
|
|
1225
|
+
* injections… we recommend that you specify a neutral name." Any caller-supplied name is
|
|
1226
|
+
* sanitized to that character set, and anything left empty falls back to a generated label.
|
|
1227
|
+
* - `source` takes **raw bytes**, not base64: "If you use an Amazon Web Services SDK, you don't
|
|
1228
|
+
* need to encode the bytes in base64." So the base64 payload is decoded here, the opposite of
|
|
1229
|
+
* what the Anthropic converter does.
|
|
1230
|
+
* - Without citations enabled, Converse degrades to plain text extraction rather than full visual
|
|
1231
|
+
* PDF understanding. That limitation is documented rather than worked around here.
|
|
1232
|
+
* https://platform.claude.com/docs/en/build-with-claude/pdf-support
|
|
1233
|
+
*
|
|
1234
|
+
* `DocumentFormat` also has eight non-PDF members, but `format` is hardcoded to PDF because that
|
|
1235
|
+
* is the only media type `DocumentContent` declares — and the seven office/markup formats have no
|
|
1236
|
+
* Anthropic source variant to map onto. The block's own media type is therefore verified rather
|
|
1237
|
+
* than read.
|
|
1238
|
+
*/
|
|
1239
|
+
function createDocumentBlock(block, index) {
|
|
1240
|
+
assertSupportedDocumentMimeType(block);
|
|
1241
|
+
const sanitized = (block.name ?? "")
|
|
1242
|
+
.replace(/[^a-zA-Z0-9\s\-()[\]]/g, " ")
|
|
1243
|
+
.replace(/\s+/g, " ")
|
|
1244
|
+
.trim();
|
|
1245
|
+
return {
|
|
1246
|
+
format: DocumentFormat.PDF,
|
|
1247
|
+
name: sanitized.length > 0 ? sanitized : `document ${index + 1}`,
|
|
1248
|
+
source: { bytes: base64ToBytes(block.data) },
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
const BEDROCK_IMAGE_FORMATS = {
|
|
1252
|
+
"image/jpeg": ImageFormat.JPEG,
|
|
1253
|
+
"image/png": ImageFormat.PNG,
|
|
1254
|
+
"image/gif": ImageFormat.GIF,
|
|
1255
|
+
"image/webp": ImageFormat.WEBP,
|
|
1256
|
+
};
|
|
1257
|
+
/** An image block, or the placeholder text when Bedrock does not accept the image's media type. */
|
|
1258
|
+
function createImageBlock(mimeType, data) {
|
|
1259
|
+
const inlineMimeType = inlineImageMimeType(mimeType);
|
|
1260
|
+
if (!inlineMimeType)
|
|
1261
|
+
return { text: unsupportedImagePlaceholder(mimeType) };
|
|
1262
|
+
return { image: { source: { bytes: base64ToBytes(data) }, format: BEDROCK_IMAGE_FORMATS[inlineMimeType] } };
|
|
1263
|
+
}
|
|
1264
|
+
function base64ToBytes(data) {
|
|
1265
|
+
const binaryString = atob(data);
|
|
1266
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
1267
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
1268
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
1269
|
+
}
|
|
1270
|
+
return bytes;
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Decodes a stored redacted payload. The AWS SDK hands the blob over as bytes, but a
|
|
1274
|
+
* persisted session carries it as base64. A hand-edited or externally produced session
|
|
1275
|
+
* can hold a signature that is not base64; drop that block instead of failing the
|
|
1276
|
+
* whole request.
|
|
1277
|
+
*/
|
|
1278
|
+
function decodeRedactedContent(signature) {
|
|
1279
|
+
if (!signature)
|
|
1280
|
+
return undefined;
|
|
1281
|
+
try {
|
|
1282
|
+
return base64ToBytes(signature);
|
|
1283
|
+
}
|
|
1284
|
+
catch {
|
|
1285
|
+
return undefined;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
function bytesToBase64(chunks) {
|
|
1289
|
+
// Encrypted reasoning runs to tens of KB, so build the binary string in slices
|
|
1290
|
+
// rather than one concatenation per byte. The window stays under the engine's
|
|
1291
|
+
// argument-count limit for spread calls.
|
|
1292
|
+
const WINDOW = 0x8000;
|
|
1293
|
+
let binary = "";
|
|
1294
|
+
for (const chunk of chunks) {
|
|
1295
|
+
for (let i = 0; i < chunk.length; i += WINDOW) {
|
|
1296
|
+
binary += String.fromCharCode(...chunk.subarray(i, i + WINDOW));
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return btoa(binary);
|
|
1300
|
+
}
|
|
1301
|
+
//# sourceMappingURL=bedrock-converse-stream.js.map
|