@zyro-sec/ai 0.0.0-stage → 1.0.1
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/AGENTS.md +23 -0
- package/README.md +1810 -2
- package/example/tutorial.ts +284 -0
- package/package.json +40 -4
- package/script/pack.ts +5 -0
- package/script/recording-cost-report.ts +250 -0
- package/script/setup-recording-env.ts +602 -0
- package/src/ai-client.ts +28 -0
- package/src/cache-policy.ts +249 -0
- package/src/decision-client.ts +88 -0
- package/src/decision.ts +335 -0
- package/src/effect.ts +44 -0
- package/src/effort-updates.ts +25 -0
- package/src/embedding-client.ts +46 -0
- package/src/embedding.ts +167 -0
- package/src/experimental/cloudflare-run-extraction.ts +112 -0
- package/src/experimental/extraction.ts +190 -0
- package/src/experimental/realtime.ts +211 -0
- package/src/experimental.ts +51 -0
- package/src/generation.ts +210 -0
- package/src/image-client.ts +89 -0
- package/src/image.ts +236 -0
- package/src/index.ts +363 -0
- package/src/llm.ts +364 -0
- package/src/loop.ts +214 -0
- package/src/media-client.ts +94 -0
- package/src/media-model.ts +129 -0
- package/src/media.ts +408 -0
- package/src/protocols/alibaba-chat.ts +95 -0
- package/src/protocols/alibaba-images.ts +126 -0
- package/src/protocols/alibaba-messages.ts +49 -0
- package/src/protocols/alibaba-responses.ts +86 -0
- package/src/protocols/anthropic-messages.ts +1664 -0
- package/src/protocols/assemblyai-transcription.ts +209 -0
- package/src/protocols/bedrock-converse.ts +984 -0
- package/src/protocols/bedrock-event-stream.ts +147 -0
- package/src/protocols/cartesia-speech.ts +182 -0
- package/src/protocols/cloudflare-run-decisions.ts +55 -0
- package/src/protocols/cloudflare-workers-ai-images.ts +124 -0
- package/src/protocols/cohere-chat.ts +353 -0
- package/src/protocols/deepgram-speech.ts +148 -0
- package/src/protocols/deepgram-transcription.ts +179 -0
- package/src/protocols/elevenlabs-speech.ts +207 -0
- package/src/protocols/elevenlabs-transcription.ts +211 -0
- package/src/protocols/gemini.ts +908 -0
- package/src/protocols/google-decisions.ts +179 -0
- package/src/protocols/google-embed-content.ts +165 -0
- package/src/protocols/google-images.ts +255 -0
- package/src/protocols/google-interactions-video.ts +264 -0
- package/src/protocols/google-interactions.ts +904 -0
- package/src/protocols/google-speech.ts +157 -0
- package/src/protocols/google-transcription.ts +206 -0
- package/src/protocols/google-vertex-predict-embeddings.ts +104 -0
- package/src/protocols/index.ts +21 -0
- package/src/protocols/meta-images.ts +162 -0
- package/src/protocols/meta-messages.ts +67 -0
- package/src/protocols/meta-responses.ts +249 -0
- package/src/protocols/minimax-images.ts +215 -0
- package/src/protocols/minimax-video.ts +406 -0
- package/src/protocols/mistral-chat.ts +768 -0
- package/src/protocols/open-responses-channel.ts +198 -0
- package/src/protocols/open-responses-continuation.ts +218 -0
- package/src/protocols/open-responses.ts +1636 -0
- package/src/protocols/openai-chat.ts +1431 -0
- package/src/protocols/openai-compatible-chat.ts +22 -0
- package/src/protocols/openai-compatible-responses.ts +21 -0
- package/src/protocols/openai-decisions.ts +174 -0
- package/src/protocols/openai-embeddings.ts +105 -0
- package/src/protocols/openai-freeform.ts +287 -0
- package/src/protocols/openai-images.ts +442 -0
- package/src/protocols/openai-responses.ts +442 -0
- package/src/protocols/openai-speech.ts +164 -0
- package/src/protocols/openai-transcription.ts +295 -0
- package/src/protocols/openrouter-video.ts +215 -0
- package/src/protocols/seedance-video.ts +301 -0
- package/src/protocols/shared.ts +552 -0
- package/src/protocols/system-one.ts +335 -0
- package/src/protocols/utils/bedrock-auth.ts +147 -0
- package/src/protocols/utils/bedrock-cache.ts +56 -0
- package/src/protocols/utils/bedrock-media.ts +121 -0
- package/src/protocols/utils/cache.ts +44 -0
- package/src/protocols/utils/claude-model.ts +19 -0
- package/src/protocols/utils/gateway-protocol.ts +92 -0
- package/src/protocols/utils/gemini-generate-content.ts +172 -0
- package/src/protocols/utils/gemini-json-schema.ts +77 -0
- package/src/protocols/utils/image-sizing.ts +117 -0
- package/src/protocols/utils/lifecycle.ts +120 -0
- package/src/protocols/utils/media-input.ts +98 -0
- package/src/protocols/utils/mistral-tool-id.ts +34 -0
- package/src/protocols/utils/open-responses-options.ts +82 -0
- package/src/protocols/utils/partial-json-options.ts +62 -0
- package/src/protocols/utils/partial-json.ts +283 -0
- package/src/protocols/utils/responses-checkpoint.ts +115 -0
- package/src/protocols/utils/responses-compaction.ts +210 -0
- package/src/protocols/utils/responses-hosted-tools.ts +104 -0
- package/src/protocols/utils/speaker-turns.ts +10 -0
- package/src/protocols/utils/speech-stream.ts +111 -0
- package/src/protocols/utils/tool-schema.ts +115 -0
- package/src/protocols/utils/tool-stream.ts +240 -0
- package/src/protocols/venice-chat.ts +356 -0
- package/src/protocols/xai-images.ts +137 -0
- package/src/protocols/xai-responses.ts +106 -0
- package/src/protocols/xai-video.ts +232 -0
- package/src/protocols/zai-chat.ts +71 -0
- package/src/protocols/zai-images.ts +120 -0
- package/src/protocols/zai-messages.ts +34 -0
- package/src/protocols.ts +1 -0
- package/src/provider-error.ts +291 -0
- package/src/provider-package.ts +32 -0
- package/src/providers/alibaba/chat.ts +1 -0
- package/src/providers/alibaba/embeddings.ts +2 -0
- package/src/providers/alibaba/images.ts +2 -0
- package/src/providers/alibaba/messages.ts +3 -0
- package/src/providers/alibaba/responses.ts +3 -0
- package/src/providers/alibaba.ts +177 -0
- package/src/providers/amazon-bedrock/mantle/chat.ts +2 -0
- package/src/providers/amazon-bedrock/mantle/messages.ts +2 -0
- package/src/providers/amazon-bedrock/mantle/responses.ts +2 -0
- package/src/providers/amazon-bedrock/mantle.ts +2 -0
- package/src/providers/amazon-bedrock-mantle.ts +192 -0
- package/src/providers/amazon-bedrock.ts +81 -0
- package/src/providers/anthropic-compatible.ts +80 -0
- package/src/providers/anthropic.ts +66 -0
- package/src/providers/assemblyai.ts +32 -0
- package/src/providers/azure/chat.ts +2 -0
- package/src/providers/azure/embeddings.ts +2 -0
- package/src/providers/azure/images.ts +2 -0
- package/src/providers/azure/messages.ts +2 -0
- package/src/providers/azure/responses.ts +2 -0
- package/src/providers/azure.ts +240 -0
- package/src/providers/baseten/decisions.ts +2 -0
- package/src/providers/baseten.ts +88 -0
- package/src/providers/byteplus/videos.ts +2 -0
- package/src/providers/byteplus.ts +39 -0
- package/src/providers/cartesia.ts +28 -0
- package/src/providers/cerebras.ts +56 -0
- package/src/providers/cloudflare-ai-gateway/decisions.ts +2 -0
- package/src/providers/cloudflare-ai-gateway.ts +199 -0
- package/src/providers/cloudflare-shared.ts +29 -0
- package/src/providers/cloudflare-workers-ai/decisions.ts +2 -0
- package/src/providers/cloudflare-workers-ai/images.ts +2 -0
- package/src/providers/cloudflare-workers-ai.ts +104 -0
- package/src/providers/cohere/chat.ts +8 -0
- package/src/providers/cohere/embeddings.ts +2 -0
- package/src/providers/cohere.ts +72 -0
- package/src/providers/deepgram.ts +33 -0
- package/src/providers/deepinfra/embeddings.ts +2 -0
- package/src/providers/deepinfra.ts +76 -0
- package/src/providers/deepseek.ts +54 -0
- package/src/providers/digitalocean/decisions.ts +2 -0
- package/src/providers/digitalocean/embeddings.ts +2 -0
- package/src/providers/digitalocean/images.ts +2 -0
- package/src/providers/digitalocean/responses.ts +4 -0
- package/src/providers/digitalocean.ts +144 -0
- package/src/providers/elevenlabs.ts +35 -0
- package/src/providers/fireworks/embeddings.ts +2 -0
- package/src/providers/fireworks.ts +66 -0
- package/src/providers/google/decisions.ts +2 -0
- package/src/providers/google/embeddings.ts +2 -0
- package/src/providers/google/images.ts +2 -0
- package/src/providers/google/interactions.ts +13 -0
- package/src/providers/google/videos.ts +2 -0
- package/src/providers/google-vertex/chat.ts +2 -0
- package/src/providers/google-vertex/embeddings.ts +2 -0
- package/src/providers/google-vertex/gemini.ts +2 -0
- package/src/providers/google-vertex/images.ts +2 -0
- package/src/providers/google-vertex/interactions.ts +2 -0
- package/src/providers/google-vertex/messages.ts +2 -0
- package/src/providers/google-vertex/mistral.ts +2 -0
- package/src/providers/google-vertex/responses.ts +2 -0
- package/src/providers/google-vertex-chat.ts +63 -0
- package/src/providers/google-vertex-interactions.ts +104 -0
- package/src/providers/google-vertex-messages.ts +99 -0
- package/src/providers/google-vertex-mistral.ts +79 -0
- package/src/providers/google-vertex-responses.ts +64 -0
- package/src/providers/google-vertex-shared.ts +176 -0
- package/src/providers/google-vertex.ts +228 -0
- package/src/providers/google.ts +121 -0
- package/src/providers/groq.ts +98 -0
- package/src/providers/index.ts +45 -0
- package/src/providers/meta/chat.ts +2 -0
- package/src/providers/meta/images.ts +2 -0
- package/src/providers/meta/messages.ts +2 -0
- package/src/providers/meta/responses.ts +2 -0
- package/src/providers/meta.ts +161 -0
- package/src/providers/minimax/chat.ts +8 -0
- package/src/providers/minimax/images.ts +4 -0
- package/src/providers/minimax/messages.ts +1 -0
- package/src/providers/minimax/responses.ts +8 -0
- package/src/providers/minimax/videos.ts +4 -0
- package/src/providers/minimax.ts +162 -0
- package/src/providers/mistral.ts +40 -0
- package/src/providers/moonshot/chat.ts +1 -0
- package/src/providers/moonshot/messages.ts +8 -0
- package/src/providers/moonshot/responses.ts +8 -0
- package/src/providers/moonshot.ts +134 -0
- package/src/providers/open-responses-options.ts +4 -0
- package/src/providers/openai/chat.ts +2 -0
- package/src/providers/openai/embeddings.ts +2 -0
- package/src/providers/openai/images.ts +2 -0
- package/src/providers/openai/responses.ts +2 -0
- package/src/providers/openai-compatible/decisions.ts +2 -0
- package/src/providers/openai-compatible/embeddings.ts +2 -0
- package/src/providers/openai-compatible/images.ts +2 -0
- package/src/providers/openai-compatible/responses.ts +1 -0
- package/src/providers/openai-compatible-responses.ts +52 -0
- package/src/providers/openai-compatible.ts +108 -0
- package/src/providers/openai-options.ts +66 -0
- package/src/providers/openai.ts +207 -0
- package/src/providers/opencode/decisions.ts +2 -0
- package/src/providers/opencode.ts +45 -0
- package/src/providers/openrouter/decisions.ts +2 -0
- package/src/providers/openrouter/embeddings.ts +2 -0
- package/src/providers/openrouter/images.ts +2 -0
- package/src/providers/openrouter/responses.ts +3 -0
- package/src/providers/openrouter/videos.ts +2 -0
- package/src/providers/openrouter.ts +347 -0
- package/src/providers/settings.ts +54 -0
- package/src/providers/togetherai.ts +53 -0
- package/src/providers/typesafe-ai/decisions.ts +2 -0
- package/src/providers/typesafe-ai.ts +45 -0
- package/src/providers/venice/responses.ts +4 -0
- package/src/providers/venice.ts +93 -0
- package/src/providers/vercel-ai-gateway/chat.ts +2 -0
- package/src/providers/vercel-ai-gateway/decisions.ts +2 -0
- package/src/providers/vercel-ai-gateway/embeddings.ts +2 -0
- package/src/providers/vercel-ai-gateway/images.ts +2 -0
- package/src/providers/vercel-ai-gateway/messages.ts +2 -0
- package/src/providers/vercel-ai-gateway/responses.ts +2 -0
- package/src/providers/vercel-ai-gateway.ts +300 -0
- package/src/providers/volcengine/videos.ts +2 -0
- package/src/providers/volcengine.ts +39 -0
- package/src/providers/xai/images.ts +2 -0
- package/src/providers/xai/videos.ts +2 -0
- package/src/providers/xai.ts +125 -0
- package/src/providers/zai/chat.ts +1 -0
- package/src/providers/zai/images.ts +2 -0
- package/src/providers/zai-coding-plan/chat.ts +1 -0
- package/src/providers/zai-coding-plan/messages.ts +8 -0
- package/src/providers/zai-coding-plan/responses.ts +8 -0
- package/src/providers/zai-coding-plan.ts +86 -0
- package/src/providers/zai.ts +73 -0
- package/src/providers.ts +1 -0
- package/src/public.ts +204 -0
- package/src/route/auth-options.ts +62 -0
- package/src/route/auth.ts +164 -0
- package/src/route/client.ts +700 -0
- package/src/route/decision.ts +150 -0
- package/src/route/embedding.ts +175 -0
- package/src/route/endpoint.ts +63 -0
- package/src/route/executor-service.ts +191 -0
- package/src/route/executor.ts +361 -0
- package/src/route/framing.ts +112 -0
- package/src/route/index.ts +47 -0
- package/src/route/media-protocol.ts +321 -0
- package/src/route/media.ts +507 -0
- package/src/route/protocol.ts +97 -0
- package/src/route/transport/http.ts +103 -0
- package/src/route/transport/index.ts +59 -0
- package/src/route/transport/websocket-channel.ts +51 -0
- package/src/route/transport/websocket.ts +443 -0
- package/src/route.ts +1 -0
- package/src/schema/errors.ts +246 -0
- package/src/schema/events.ts +744 -0
- package/src/schema/ids.ts +24 -0
- package/src/schema/index.ts +5 -0
- package/src/schema/messages.ts +529 -0
- package/src/schema/options.ts +445 -0
- package/src/speech-client.ts +25 -0
- package/src/speech.ts +211 -0
- package/src/testing.ts +218 -0
- package/src/tool-history.ts +91 -0
- package/src/tool-runtime.ts +107 -0
- package/src/tool-updates.ts +139 -0
- package/src/tool.ts +281 -0
- package/src/transcription-client.ts +19 -0
- package/src/transcription.ts +234 -0
- package/src/utils/bytes.ts +9 -0
- package/src/utils/json.ts +5 -0
- package/src/utils/media-type.ts +93 -0
- package/src/utils/provider-codes.ts +43 -0
- package/src/utils/record.ts +3 -0
- package/src/utils/sanitize.ts +33 -0
- package/src/video-client.ts +66 -0
- package/src/video.ts +181 -0
- package/test/adapter.test.ts +180 -0
- package/test/auth-options.types.ts +283 -0
- package/test/auth.test.ts +112 -0
- package/test/cache-policy.test.ts +578 -0
- package/test/compaction-http.test.ts +96 -0
- package/test/compaction.test.ts +107 -0
- package/test/compile.test.ts +600 -0
- package/test/continuation-scenarios.ts +115 -0
- package/test/decision.test.ts +983 -0
- package/test/decision.types.ts +117 -0
- package/test/effort-updates.test.ts +574 -0
- package/test/embedding.test.ts +455 -0
- package/test/endpoint.test.ts +58 -0
- package/test/error-partial.test.ts +140 -0
- package/test/executor.test.ts +1095 -0
- package/test/exports.test.ts +222 -0
- package/test/extraction.test.ts +227 -0
- package/test/fixtures/audio/dialog.mp3 +0 -0
- package/test/fixtures/audio/hello.mp3 +0 -0
- package/test/fixtures/images/edit-source.jpg +0 -0
- package/test/fixtures/media/restroom.png +0 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-returns-a-json-object.json +34 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-minimal-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-none-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-images/edits-an-image.json +33 -0
- package/test/fixtures/recordings/alibaba-images/generates-qwen-image-images.json +33 -0
- package/test/fixtures/recordings/alibaba-images/generates-wan-images.json +33 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-follows-a-json-schema.json +34 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-continues-a-stored-response.json +53 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-minimal-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-none-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-uses-hosted-code-interpreter.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-uses-hosted-web-search-and-extraction.json +36 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-text.json +40 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-tool-call.json +41 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-tool-loop.json +60 -0
- package/test/fixtures/recordings/anthropic-messages/anthropic-opus-4-7-image-tool-result.json +43 -0
- package/test/fixtures/recordings/anthropic-messages-cache/keeps-a-long-tool-turn-inside-the-cache-lookback.json +48 -0
- package/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json +48 -0
- package/test/fixtures/recordings/assemblyai-transcription/uploads-submits-and-polls-a-transcript.json +98 -0
- package/test/fixtures/recordings/azure/chat-streams-text-from-a-foundry-models-url.json +31 -0
- package/test/fixtures/recordings/azure/chat-streams-text.json +28 -0
- package/test/fixtures/recordings/azure/messages-calls-a-tool.json +31 -0
- package/test/fixtures/recordings/azure/messages-streams-text.json +31 -0
- package/test/fixtures/recordings/azure/responses-calls-a-tool.json +31 -0
- package/test/fixtures/recordings/azure/responses-continues-after-a-tool-result.json +31 -0
- package/test/fixtures/recordings/azure/responses-streams-text.json +31 -0
- package/test/fixtures/recordings/baseten-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/bedrock-converse/continues-after-parallel-tool-results.json +36 -0
- package/test/fixtures/recordings/bedrock-converse/drives-a-tool-loop.json +55 -0
- package/test/fixtures/recordings/bedrock-converse/streams-a-tool-call.json +29 -0
- package/test/fixtures/recordings/bedrock-converse/streams-text.json +29 -0
- package/test/fixtures/recordings/bedrock-converse-cache/writes-then-reads-cachepoint-on-identical-second-call.json +48 -0
- package/test/fixtures/recordings/bedrock-converse-options/constrains-claude-output-to-a-json-schema.json +33 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-claude-effort-with-adaptive-thinking-service-tier-and-request-metadata.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-gpt-oss-reasoning-effort-with-the-priority-tier.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-nova-2-reasoning-effort.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-thinking-binding/accepts-the-default-binding-with-no-thinking-configured.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-thinking-binding/keeps-a-session-working-after-the-system-prompt-changes.json +71 -0
- package/test/fixtures/recordings/bedrock-mantle/streams-text.json +33 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/applies-mid-conversation-effort-updates-and-thinking-block-binding-on-opus-5-5.json +57 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/lowers-system-updates-to-wrapped-user-text-on-haiku-4-5-with-budget-thinking.json +37 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/replays-signed-thinking-through-a-tool-loop-and-native-system-update.json +59 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/strips-unsupported-mid-conversation-effort-updates-on-opus-5-0.json +37 -0
- package/test/fixtures/recordings/cartesia-speech/generates-speech.json +34 -0
- package/test/fixtures/recordings/cartesia-speech/streams-speech-with-timestamps.json +33 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-text.json +32 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-tool-call.json +32 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-tool-loop.json +50 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-claude-haiku-4-5-text.json +38 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-claude-haiku-4-5-tool-loop.json +58 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-openai-gpt-5-nano-text.json +37 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-openai-gpt-5-nano-tool-loop.json +56 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-workers-ai-gpt-oss-20b-tools-tool-call.json +32 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-workers-ai-llama-3-1-8b-text.json +32 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai/cloudflare-workers-ai-gpt-oss-20b-tools-tool-call.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai/cloudflare-workers-ai-llama-3-1-8b-text.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-extraction/extracts-invoice-fields.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-images/generates-a-flux-2-image-from-multipart-fields.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-images/generates-a-raw-binary-image.json +33 -0
- package/test/fixtures/recordings/cohere/continues-a-native-tool-call.json +49 -0
- package/test/fixtures/recordings/cohere/streams-compatible-chat-reasoning.json +31 -0
- package/test/fixtures/recordings/cohere/streams-native-text-and-usage.json +31 -0
- package/test/fixtures/recordings/cohere/streams-native-thinking-with-a-budget.json +31 -0
- package/test/fixtures/recordings/cohere-embedding/embeds-text-through-the-compatibility-api.json +33 -0
- package/test/fixtures/recordings/deepgram-speech/generates-speech.json +36 -0
- package/test/fixtures/recordings/deepgram-speech/streams-speech.json +36 -0
- package/test/fixtures/recordings/deepgram-transcription/splits-utterances-at-speaker-changes.json +32 -0
- package/test/fixtures/recordings/deepgram-transcription/transcribes-raw-audio-with-speakers-and-word-timestamps.json +50 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-text.json +32 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-tool-call.json +32 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-tool-loop.json +50 -0
- package/test/fixtures/recordings/digitalocean-chat/gpt-nano-continues-a-tool-call-with-cache-markers.json +54 -0
- package/test/fixtures/recordings/digitalocean-chat/gpt-nano-reuses-a-cached-prompt.json +53 -0
- package/test/fixtures/recordings/digitalocean-chat/haiku-continues-a-tool-call-with-cache-markers.json +54 -0
- package/test/fixtures/recordings/digitalocean-chat/haiku-reuses-a-cached-prompt.json +53 -0
- package/test/fixtures/recordings/digitalocean-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/digitalocean-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/digitalocean-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/digitalocean-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/elevenlabs-speech/generates-speech.json +35 -0
- package/test/fixtures/recordings/elevenlabs-speech/streams-speech-with-timestamps.json +34 -0
- package/test/fixtures/recordings/elevenlabs-transcription/groups-diarized-words-into-speaker-turns.json +32 -0
- package/test/fixtures/recordings/elevenlabs-transcription/transcribes-audio-with-word-timestamps.json +50 -0
- package/test/fixtures/recordings/gemini/gemini-2-5-flash-image.json +32 -0
- package/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json +46 -0
- package/test/fixtures/recordings/google-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/google-embedding/embeds-an-image-and-text-into-one-vector-each.json +32 -0
- package/test/fixtures/recordings/google-embedding/embeds-text-through-batchembedcontents.json +32 -0
- package/test/fixtures/recordings/google-embedding/maps-inputtype-to-a-task-type-for-gemini-embedding-001.json +50 -0
- package/test/fixtures/recordings/google-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/google-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/google-interactions/continues-tool-results-with-previous-interaction-id.json +66 -0
- package/test/fixtures/recordings/google-interactions/replays-native-tool-results-and-signatures-statelessly.json +50 -0
- package/test/fixtures/recordings/google-interactions/streams-reasoning-and-retains-thought-signatures.json +32 -0
- package/test/fixtures/recordings/google-interactions/streams-text-and-reports-usage.json +32 -0
- package/test/fixtures/recordings/google-interactions-video/generates-a-video.json +96 -0
- package/test/fixtures/recordings/google-speech/generates-speech.json +32 -0
- package/test/fixtures/recordings/google-speech/streams-speech.json +32 -0
- package/test/fixtures/recordings/google-transcription/streams-speaker-turns.json +32 -0
- package/test/fixtures/recordings/google-transcription/transcribes-with-speakers-and-word-timestamps.json +32 -0
- package/test/fixtures/recordings/google-vertex/calls-a-tool.json +32 -0
- package/test/fixtures/recordings/google-vertex/continues-after-a-tool-result.json +32 -0
- package/test/fixtures/recordings/google-vertex/streams-text.json +32 -0
- package/test/fixtures/recordings/google-vertex-embedding/embeds-gemini-embedding-001-one-text-per-predict-request.json +50 -0
- package/test/fixtures/recordings/google-vertex-embedding/embeds-text-through-predict.json +32 -0
- package/test/fixtures/recordings/groq-chat/continues-qwen-parallel-tool-calls.json +47 -0
- package/test/fixtures/recordings/groq-chat/replays-gpt-oss-reasoning-through-a-tool-loop.json +47 -0
- package/test/fixtures/recordings/groq-chat/streams-qwen-parsed-reasoning.json +29 -0
- package/test/fixtures/recordings/groq-chat/streams-text-with-usage.json +29 -0
- package/test/fixtures/recordings/meta-chat/continues-a-generated-tool-call.json +56 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-default-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-high-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-low-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-max-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-medium-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-minimal-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-xhigh-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-images/edits-image-bytes-and-returns-png.json +29 -0
- package/test/fixtures/recordings/meta-images/generates-default-webp-bytes.json +29 -0
- package/test/fixtures/recordings/meta-images/replays-a-signed-image-handle-for-a-responses-edit.json +55 -0
- package/test/fixtures/recordings/meta-messages/replays-encrypted-thinking-through-a-tool-loop.json +54 -0
- package/test/fixtures/recordings/meta-messages/streams-text-with-adaptive-thinking.json +36 -0
- package/test/fixtures/recordings/meta-messages/streams-text-with-enabled-thinking.json +36 -0
- package/test/fixtures/recordings/meta-responses/replays-encrypted-reasoning-through-a-tool-loop.json +56 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-default-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-high-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-low-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-max-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-medium-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-minimal-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-xhigh-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-search/searches-and-replays-grounded-messages.json +56 -0
- package/test/fixtures/recordings/meta-search/searches-and-replays-grounded-responses.json +56 -0
- package/test/fixtures/recordings/minimax-chat/m3-continues-a-tool-loop-with-default-thinking.json +56 -0
- package/test/fixtures/recordings/minimax-chat/m3-streams-text-with-thinking-disabled.json +36 -0
- package/test/fixtures/recordings/minimax-images/generates-an-image.json +32 -0
- package/test/fixtures/recordings/minimax-images/generates-from-a-subject-reference.json +32 -0
- package/test/fixtures/recordings/minimax-messages/m2-7-streams-default-thinking.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-continues-a-tool-loop-with-adaptive-thinking.json +56 -0
- package/test/fixtures/recordings/minimax-messages/m3-generates-a-named-tool-call-with-default-thinking-off.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-streams-adaptive-thinking.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-streams-text-with-thinking-disabled.json +36 -0
- package/test/fixtures/recordings/minimax-responses/m3-continues-a-tool-loop-with-effort-minimal.json +56 -0
- package/test/fixtures/recordings/minimax-responses/m3-streams-text-with-effort-none.json +36 -0
- package/test/fixtures/recordings/minimax-video/generates-a-hailuo-video-from-a-first-frame.json +176 -0
- package/test/fixtures/recordings/minimax-video/generates-an-h3-video.json +96 -0
- package/test/fixtures/recordings/mistral-chat/drives-a-tool-loop.json +54 -0
- package/test/fixtures/recordings/mistral-chat/replays-native-reasoning.json +47 -0
- package/test/fixtures/recordings/mistral-chat/streams-text-with-usage.json +29 -0
- package/test/fixtures/recordings/mistral-chat-glm/streams-an-indexed-tool-call.json +36 -0
- package/test/fixtures/recordings/moonshot-chat/k3-reads-image-bytes.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-respects-tool-choice-none.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-respects-tool-choice-required.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-returns-native-structured-output.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-default-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-high-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-low-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-max-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-disabled-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-enabled-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-highspeed-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-highspeed-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-messages/k3-reads-image-bytes.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-respects-tool-choice-none.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-respects-tool-choice-required.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-returns-native-structured-output.json +35 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-default-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-high-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-low-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-max-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-responses/k3-reads-image-bytes.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-rejects-unsupported-tool-choice-none.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-rejects-unsupported-tool-choice-required.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-returns-native-structured-output.json +35 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-default-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-high-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-low-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-max-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/openai-compatible-chat/gemini-parallel-tool-signatures.json +54 -0
- package/test/fixtures/recordings/openai-compatible-chat/togetherai-streams-text.json +28 -0
- package/test/fixtures/recordings/openai-compatible-chat/togetherai-streams-tool-call.json +28 -0
- package/test/fixtures/recordings/openai-decision/decides-choice-score-and-predicate-questions-about-json-state.json +33 -0
- package/test/fixtures/recordings/openai-embedding/embeds-text-with-requested-dimensions.json +33 -0
- package/test/fixtures/recordings/openai-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/openai-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/openai-images/streams-a-partial-image-before-the-final-image.json +32 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-image-tool-result.json +42 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-reasoning-continuation.json +58 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-reasoning.json +38 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-tool-loop.json +57 -0
- package/test/fixtures/recordings/openai-responses-cache/caches-the-system-prompt-on-gpt-6-2-sol.json +51 -0
- package/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json +51 -0
- package/test/fixtures/recordings/openai-responses-images/generates-and-edits-an-image-with-the-hosted-tool.json +50 -0
- package/test/fixtures/recordings/openai-responses-websocket/continues-a-tool-call-over-one-socket.json +588 -0
- package/test/fixtures/recordings/openai-responses-websocket/reconstructs-full-context-after-reconnect.json +167 -0
- package/test/fixtures/recordings/openai-responses-websocket/recovers-from-explicit-continuation-rejection.json +167 -0
- package/test/fixtures/recordings/openai-speech/generates-speech.json +33 -0
- package/test/fixtures/recordings/openai-speech/streams-speech.json +32 -0
- package/test/fixtures/recordings/openai-transcription/diarizes-speakers-into-segments.json +32 -0
- package/test/fixtures/recordings/openai-transcription/returns-whisper-word-timestamps.json +32 -0
- package/test/fixtures/recordings/openai-transcription/streams-text-deltas.json +32 -0
- package/test/fixtures/recordings/openai-transcription/transcribes-with-a-language-hint.json +32 -0
- package/test/fixtures/recordings/opencode-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/openrouter-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/openrouter-images/edits-an-image-through-input-references.json +32 -0
- package/test/fixtures/recordings/openrouter-images/renders-flux-3-from-an-aspect-ratio-and-tier.json +32 -0
- package/test/fixtures/recordings/openrouter-images/renders-gemini-at-the-requested-2k-tier.json +32 -0
- package/test/fixtures/recordings/openrouter-reasoning-tool-loop.json +55 -0
- package/test/fixtures/recordings/openrouter-reasoning.json +29 -0
- package/test/fixtures/recordings/openrouter-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/openrouter-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/openrouter-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/openrouter-video/generates-a-video.json +113 -0
- package/test/fixtures/recordings/pdf/anthropic-tool-result.json +28 -0
- package/test/fixtures/recordings/pdf/anthropic-user-input.json +28 -0
- package/test/fixtures/recordings/pdf/bedrock-tool-result.json +29 -0
- package/test/fixtures/recordings/pdf/bedrock-user-input.json +29 -0
- package/test/fixtures/recordings/pdf/gemini-tool-result.json +53 -0
- package/test/fixtures/recordings/pdf/gemini-user-input.json +28 -0
- package/test/fixtures/recordings/pdf/openai-tool-result.json +35 -0
- package/test/fixtures/recordings/pdf/openai-user-input.json +34 -0
- package/test/fixtures/recordings/pdf/xai-tool-result.json +35 -0
- package/test/fixtures/recordings/pdf/xai-user-input.json +34 -0
- package/test/fixtures/recordings/typesafe-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/venice-chat/claude-opus-4-8-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/deepseek-v4-flash-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/gemini-3-1-pro-preview-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/gemini-preserves-per-call-signatures-through-parallel-tools.json +71 -0
- package/test/fixtures/recordings/venice-chat/openai-gpt-54-mini-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/qwen-disables-reasoning.json +35 -0
- package/test/fixtures/recordings/venice-chat/surfaces-venice-model-errors.json +33 -0
- package/test/fixtures/recordings/venice-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/venice-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/venice-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/vercel-ai-gateway-images/generates-an-image.json +32 -0
- package/test/fixtures/recordings/vercel-ai-gateway-images/sizes-grok-through-xai-provider-options.json +32 -0
- package/test/fixtures/recordings/vercel-ai-gateway-reasoning-tool-loop.json +55 -0
- package/test/fixtures/recordings/vercel-ai-gateway-reasoning.json +29 -0
- package/test/fixtures/recordings/vercel-native/automatically-caches-distinct-claude-system-blocks.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-chat-claude-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-chat-muse-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-claude-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-deepseek-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-gemini-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-responses-gpt-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-responses-grok-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/rejects-invalid-credentials-without-retryable-classification.json +31 -0
- package/test/fixtures/recordings/xai-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/xai-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/xai-video/generates-a-video.json +129 -0
- package/test/fixtures/recordings/zai-chat/glm-4-5-calls-a-tool-without-streaming-arguments.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-4-7-streams-thinking-disabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-4-7-streams-thinking-enabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-high-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-low-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-max-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-medium-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-minimal-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-none-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-thinking-disabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-thinking-enabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-xhigh-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-flash-reads-image-bytes.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +64 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-rejects-disabled-thinking.json +27 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-returns-a-json-object.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-default-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-high-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-low-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-max-effort.json +28 -0
- package/test/fixtures/recordings/zai-images/generates-an-image.json +28 -0
- package/test/generate-object.test.ts +281 -0
- package/test/generation.test.ts +191 -0
- package/test/google-interactions-video.test.ts +351 -0
- package/test/http-hooks.test.ts +137 -0
- package/test/http-timeout.test.ts +287 -0
- package/test/image-job.test.ts +199 -0
- package/test/image-sizing.test.ts +47 -0
- package/test/image.test.ts +1114 -0
- package/test/image.types.ts +203 -0
- package/test/keyless-auth.test.ts +85 -0
- package/test/lib/effect.ts +50 -0
- package/test/lib/env.ts +30 -0
- package/test/lib/http.ts +141 -0
- package/test/lib/image.ts +29 -0
- package/test/lib/openai-chunks.ts +27 -0
- package/test/lib/sse.ts +20 -0
- package/test/lib/tool-runtime.ts +152 -0
- package/test/llm-option-types.types.ts +153 -0
- package/test/llm.test.ts +286 -0
- package/test/loop-steps.test.ts +77 -0
- package/test/loop-tools.types.ts +79 -0
- package/test/loop.test.ts +425 -0
- package/test/media-input.test.ts +98 -0
- package/test/media-usage.test.ts +13 -0
- package/test/media.test.ts +340 -0
- package/test/minimax-video.test.ts +553 -0
- package/test/openai-freeform.test.ts +252 -0
- package/test/openrouter-video.test.ts +294 -0
- package/test/partial-json.test.ts +58 -0
- package/test/promise-parity.types.ts +83 -0
- package/test/promise.test.ts +632 -0
- package/test/provider/alibaba-capabilities.recorded.test.ts +253 -0
- package/test/provider/alibaba-images.recorded.test.ts +71 -0
- package/test/provider/alibaba-images.test.ts +199 -0
- package/test/provider/alibaba.recorded.test.ts +165 -0
- package/test/provider/alibaba.test.ts +419 -0
- package/test/provider/anthropic-compaction.test.ts +171 -0
- package/test/provider/anthropic-messages-cache.recorded.test.ts +111 -0
- package/test/provider/anthropic-messages.recorded.test.ts +45 -0
- package/test/provider/anthropic-messages.test.ts +2609 -0
- package/test/provider/anthropic-thinking-binding.test.ts +65 -0
- package/test/provider/assemblyai-transcription.recorded.test.ts +39 -0
- package/test/provider/azure.recorded.test.ts +139 -0
- package/test/provider/azure.test.ts +48 -0
- package/test/provider/bedrock-converse-cache.recorded.test.ts +61 -0
- package/test/provider/bedrock-converse-cache.test.ts +168 -0
- package/test/provider/bedrock-converse-options.recorded.test.ts +119 -0
- package/test/provider/bedrock-converse-options.test.ts +149 -0
- package/test/provider/bedrock-converse-thinking-binding.recorded.test.ts +103 -0
- package/test/provider/bedrock-converse-thinking-binding.test.ts +107 -0
- package/test/provider/bedrock-converse.test.ts +2548 -0
- package/test/provider/bedrock-mantle.test.ts +444 -0
- package/test/provider/bedrock-mistral-ids.test.ts +86 -0
- package/test/provider/cartesia-speech.recorded.test.ts +47 -0
- package/test/provider/checkpoint.test.ts +324 -0
- package/test/provider/cloudflare-workers-ai-images.recorded.test.ts +57 -0
- package/test/provider/cloudflare-workers-ai-images.test.ts +155 -0
- package/test/provider/cloudflare.test.ts +330 -0
- package/test/provider/cohere.recorded.test.ts +94 -0
- package/test/provider/cohere.test.ts +301 -0
- package/test/provider/compaction-websocket.test.ts +50 -0
- package/test/provider/compaction.recorded.test.ts +89 -0
- package/test/provider/compaction.test.ts +178 -0
- package/test/provider/conversation-lowering.test.ts +31 -0
- package/test/provider/decision.recorded.test.ts +211 -0
- package/test/provider/deepgram-speech.recorded.test.ts +41 -0
- package/test/provider/deepgram-transcription.recorded.test.ts +47 -0
- package/test/provider/digitalocean.recorded.test.ts +78 -0
- package/test/provider/digitalocean.test.ts +123 -0
- package/test/provider/elevenlabs-speech.recorded.test.ts +54 -0
- package/test/provider/elevenlabs-transcription.recorded.test.ts +50 -0
- package/test/provider/embedding.recorded.test.ts +109 -0
- package/test/provider/empty-tool-choice.test.ts +80 -0
- package/test/provider/error-retention.test.ts +158 -0
- package/test/provider/explicit-compaction.test.ts +503 -0
- package/test/provider/extraction.recorded.test.ts +46 -0
- package/test/provider/freeform-tools.test.ts +446 -0
- package/test/provider/gemini-cache.recorded.test.ts +49 -0
- package/test/provider/gemini-openai-chat.recorded.test.ts +69 -0
- package/test/provider/gemini.test.ts +2336 -0
- package/test/provider/golden.recorded.test.ts +287 -0
- package/test/provider/google-images.recorded.test.ts +53 -0
- package/test/provider/google-interactions-video.recorded.test.ts +48 -0
- package/test/provider/google-interactions.recorded.test.ts +169 -0
- package/test/provider/google-interactions.test.ts +593 -0
- package/test/provider/google-speech.recorded.test.ts +45 -0
- package/test/provider/google-transcription.recorded.test.ts +54 -0
- package/test/provider/google-vertex-interactions.test.ts +307 -0
- package/test/provider/google-vertex.recorded.test.ts +75 -0
- package/test/provider/google-vertex.test.ts +595 -0
- package/test/provider/groq.recorded.test.ts +187 -0
- package/test/provider/groq.test.ts +134 -0
- package/test/provider/image-detail.test.ts +58 -0
- package/test/provider/media-entrypoints.test.ts +618 -0
- package/test/provider/meta-capabilities.test.ts +216 -0
- package/test/provider/meta-images.recorded.test.ts +119 -0
- package/test/provider/meta-messages.recorded.test.ts +121 -0
- package/test/provider/meta-search.recorded.test.ts +97 -0
- package/test/provider/meta.recorded.test.ts +182 -0
- package/test/provider/meta.test.ts +140 -0
- package/test/provider/minimax-images.recorded.test.ts +52 -0
- package/test/provider/minimax-images.test.ts +236 -0
- package/test/provider/minimax-video.recorded.test.ts +83 -0
- package/test/provider/minimax.recorded.test.ts +257 -0
- package/test/provider/minimax.test.ts +110 -0
- package/test/provider/missing-tool-input.test.ts +73 -0
- package/test/provider/mistral-chat.test.ts +757 -0
- package/test/provider/mistral.recorded.test.ts +170 -0
- package/test/provider/moonshot-capabilities.recorded.test.ts +131 -0
- package/test/provider/moonshot.recorded.test.ts +191 -0
- package/test/provider/moonshot.test.ts +218 -0
- package/test/provider/native-providers.test.ts +299 -0
- package/test/provider/open-responses-errors.test.ts +141 -0
- package/test/provider/open-responses-finals.test.ts +209 -0
- package/test/provider/open-responses-lifecycle.test.ts +526 -0
- package/test/provider/open-responses-replay.test.ts +120 -0
- package/test/provider/openai-chat-reasoning.recorded.test.ts +154 -0
- package/test/provider/openai-chat.test.ts +2505 -0
- package/test/provider/openai-compatible-chat.test.ts +819 -0
- package/test/provider/openai-compatible-responses.test.ts +1139 -0
- package/test/provider/openai-images.recorded.test.ts +91 -0
- package/test/provider/openai-responses-cache.recorded.test.ts +68 -0
- package/test/provider/openai-responses-images.recorded.test.ts +66 -0
- package/test/provider/openai-responses-websocket.recorded.test.ts +221 -0
- package/test/provider/openai-responses.test.ts +5414 -0
- package/test/provider/openai-speech.recorded.test.ts +38 -0
- package/test/provider/openai-transcription.recorded.test.ts +91 -0
- package/test/provider/openrouter-images.recorded.test.ts +76 -0
- package/test/provider/openrouter-video.recorded.test.ts +53 -0
- package/test/provider/openrouter.test.ts +656 -0
- package/test/provider/pdf.recorded.test.ts +211 -0
- package/test/provider/queued-recording.ts +10 -0
- package/test/provider/responses-routes.recorded.test.ts +91 -0
- package/test/provider/seedance-video.recorded.test.ts +52 -0
- package/test/provider/speech-recording.ts +19 -0
- package/test/provider/transcription-recording.ts +41 -0
- package/test/provider/venice.recorded.test.ts +237 -0
- package/test/provider/venice.test.ts +373 -0
- package/test/provider/vercel-ai-gateway-images.recorded.test.ts +55 -0
- package/test/provider/vercel-ai-gateway.recorded.test.ts +125 -0
- package/test/provider/vercel-ai-gateway.test.ts +303 -0
- package/test/provider/xai-images.recorded.test.ts +54 -0
- package/test/provider/xai-images.test.ts +109 -0
- package/test/provider/xai-responses.test.ts +339 -0
- package/test/provider/xai-video.recorded.test.ts +54 -0
- package/test/provider/zai-capabilities.recorded.test.ts +156 -0
- package/test/provider/zai-images.recorded.test.ts +33 -0
- package/test/provider/zai-images.test.ts +163 -0
- package/test/provider/zai.recorded.test.ts +115 -0
- package/test/provider/zai.test.ts +374 -0
- package/test/provider-api-methods.types.ts +8 -0
- package/test/provider-error.test.ts +800 -0
- package/test/provider-model.types.ts +37 -0
- package/test/provider-options/alibaba.types.ts +46 -0
- package/test/provider-options/amazon-bedrock.types.ts +33 -0
- package/test/provider-options/anthropic-compatible.types.ts +13 -0
- package/test/provider-options/anthropic.types.ts +30 -0
- package/test/provider-options/azure.types.ts +13 -0
- package/test/provider-options/checkpoint.types.ts +150 -0
- package/test/provider-options/cloudflare.types.ts +13 -0
- package/test/provider-options/compaction.types.ts +146 -0
- package/test/provider-options/google-vertex-chat.types.ts +7 -0
- package/test/provider-options/google-vertex-interactions.types.ts +29 -0
- package/test/provider-options/google-vertex-messages.types.ts +13 -0
- package/test/provider-options/google-vertex-responses.types.ts +14 -0
- package/test/provider-options/google-vertex.types.ts +17 -0
- package/test/provider-options/google.types.ts +43 -0
- package/test/provider-options/minimax.types.ts +33 -0
- package/test/provider-options/mistral.types.ts +24 -0
- package/test/provider-options/moonshot.types.ts +45 -0
- package/test/provider-options/openai-compatible-responses.types.ts +17 -0
- package/test/provider-options/openai-compatible.types.ts +13 -0
- package/test/provider-options/openai.types.ts +27 -0
- package/test/provider-options/openrouter.types.ts +55 -0
- package/test/provider-options/venice.types.ts +39 -0
- package/test/provider-options/vercel-ai-gateway.types.ts +30 -0
- package/test/provider-options/xai.types.ts +14 -0
- package/test/provider-options/zai.types.ts +42 -0
- package/test/provider-package.test.ts +586 -0
- package/test/raw-events.test.ts +75 -0
- package/test/realtime.test.ts +172 -0
- package/test/recorded-golden.ts +104 -0
- package/test/recorded-runner.ts +101 -0
- package/test/recorded-scenarios.ts +468 -0
- package/test/recorded-test.ts +127 -0
- package/test/recorded-utils.ts +56 -0
- package/test/request-encoding.test.ts +57 -0
- package/test/request-transport.test.ts +74 -0
- package/test/response.test.ts +203 -0
- package/test/route.test.ts +225 -0
- package/test/sanitize.test.ts +80 -0
- package/test/schema.test.ts +412 -0
- package/test/seedance-video.test.ts +418 -0
- package/test/speech.test.ts +297 -0
- package/test/speech.types.ts +33 -0
- package/test/testing.test.ts +372 -0
- package/test/tool-history.test.ts +162 -0
- package/test/tool-runtime.test.ts +926 -0
- package/test/tool-schema-projection.test.ts +427 -0
- package/test/tool-stream.test.ts +252 -0
- package/test/tool-updates.test.ts +849 -0
- package/test/tool.types.ts +131 -0
- package/test/transcription.test.ts +618 -0
- package/test/transcription.types.ts +44 -0
- package/test/video.test.ts +447 -0
- package/test/video.types.ts +110 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +17 -0
- package/tsconfig.types.json +16 -0
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
|
+
import { Base64 } from "effect/encoding"
|
|
3
|
+
import { Route } from "../route/client.js"
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js"
|
|
5
|
+
import { Protocol } from "../route/protocol.js"
|
|
6
|
+
import {
|
|
7
|
+
AIError,
|
|
8
|
+
LLMEvent,
|
|
9
|
+
Usage,
|
|
10
|
+
type CacheHint,
|
|
11
|
+
type FinishReason,
|
|
12
|
+
type FinishReasonDetails,
|
|
13
|
+
type LLMRequest,
|
|
14
|
+
type LanguageModel,
|
|
15
|
+
type ProviderMetadata,
|
|
16
|
+
type ProviderOptions,
|
|
17
|
+
type ReasoningPart,
|
|
18
|
+
type ToolCallPart,
|
|
19
|
+
type ToolDefinition,
|
|
20
|
+
type ToolResultPart,
|
|
21
|
+
} from "../schema/index.js"
|
|
22
|
+
import { BedrockEventStream } from "./bedrock-event-stream.js"
|
|
23
|
+
import { classifyProviderFailure } from "../provider-error.js"
|
|
24
|
+
import { JsonObject, optionalArray, ProviderShared } from "./shared.js"
|
|
25
|
+
import { BedrockAuth } from "./utils/bedrock-auth.js"
|
|
26
|
+
import { BedrockCache } from "./utils/bedrock-cache.js"
|
|
27
|
+
import { warnDropped } from "./utils/cache.js"
|
|
28
|
+
import { BedrockMedia } from "./utils/bedrock-media.js"
|
|
29
|
+
import { claudeVersion, supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js"
|
|
30
|
+
import { Lifecycle } from "./utils/lifecycle.js"
|
|
31
|
+
import { MistralToolID } from "./utils/mistral-tool-id.js"
|
|
32
|
+
import { ToolStream } from "./utils/tool-stream.js"
|
|
33
|
+
import { concatBytes } from "../utils/bytes.js"
|
|
34
|
+
|
|
35
|
+
const ADAPTER = "bedrock-converse"
|
|
36
|
+
|
|
37
|
+
export type { Credentials as BedrockCredentials } from "./utils/bedrock-auth.js"
|
|
38
|
+
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// Request Body Schema
|
|
41
|
+
// =============================================================================
|
|
42
|
+
const BedrockTextBlock = Schema.Struct({
|
|
43
|
+
text: Schema.String,
|
|
44
|
+
})
|
|
45
|
+
type BedrockTextBlock = Schema.Schema.Type<typeof BedrockTextBlock>
|
|
46
|
+
|
|
47
|
+
const BedrockToolUseBlock = Schema.Struct({
|
|
48
|
+
toolUse: Schema.Struct({
|
|
49
|
+
toolUseId: Schema.String,
|
|
50
|
+
name: Schema.String,
|
|
51
|
+
input: Schema.Unknown,
|
|
52
|
+
}),
|
|
53
|
+
})
|
|
54
|
+
type BedrockToolUseBlock = Schema.Schema.Type<typeof BedrockToolUseBlock>
|
|
55
|
+
|
|
56
|
+
const BedrockToolResultContentItem = Schema.Union([
|
|
57
|
+
Schema.Struct({ text: Schema.String }),
|
|
58
|
+
Schema.Struct({ json: Schema.Unknown }),
|
|
59
|
+
BedrockMedia.ImageBlock,
|
|
60
|
+
BedrockMedia.DocumentBlock,
|
|
61
|
+
])
|
|
62
|
+
|
|
63
|
+
const BedrockToolResultBlock = Schema.Struct({
|
|
64
|
+
toolResult: Schema.Struct({
|
|
65
|
+
toolUseId: Schema.String,
|
|
66
|
+
content: Schema.Array(BedrockToolResultContentItem),
|
|
67
|
+
status: Schema.optional(Schema.Literals(["success", "error"])),
|
|
68
|
+
}),
|
|
69
|
+
})
|
|
70
|
+
type BedrockToolResultBlock = Schema.Schema.Type<typeof BedrockToolResultBlock>
|
|
71
|
+
|
|
72
|
+
const BedrockReasoningBlock = Schema.Struct({
|
|
73
|
+
reasoningContent: Schema.Union([
|
|
74
|
+
Schema.Struct({
|
|
75
|
+
reasoningText: Schema.Struct({
|
|
76
|
+
text: Schema.String,
|
|
77
|
+
signature: Schema.optional(Schema.String),
|
|
78
|
+
}),
|
|
79
|
+
}),
|
|
80
|
+
Schema.Struct({ redactedContent: Schema.String }),
|
|
81
|
+
]),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const BedrockUserBlock = Schema.Union([
|
|
85
|
+
BedrockTextBlock,
|
|
86
|
+
BedrockMedia.ImageBlock,
|
|
87
|
+
BedrockMedia.DocumentBlock,
|
|
88
|
+
BedrockToolResultBlock,
|
|
89
|
+
BedrockCache.CachePointBlock,
|
|
90
|
+
])
|
|
91
|
+
type BedrockUserBlock = Schema.Schema.Type<typeof BedrockUserBlock>
|
|
92
|
+
|
|
93
|
+
const BedrockAssistantBlock = Schema.Union([
|
|
94
|
+
BedrockTextBlock,
|
|
95
|
+
BedrockReasoningBlock,
|
|
96
|
+
BedrockToolUseBlock,
|
|
97
|
+
BedrockCache.CachePointBlock,
|
|
98
|
+
])
|
|
99
|
+
type BedrockAssistantBlock = Schema.Schema.Type<typeof BedrockAssistantBlock>
|
|
100
|
+
|
|
101
|
+
const BedrockMessage = Schema.Union([
|
|
102
|
+
Schema.Struct({ role: Schema.Literal("user"), content: Schema.Array(BedrockUserBlock) }),
|
|
103
|
+
Schema.Struct({ role: Schema.Literal("assistant"), content: Schema.Array(BedrockAssistantBlock) }),
|
|
104
|
+
]).pipe(Schema.toTaggedUnion("role"))
|
|
105
|
+
type BedrockMessage = Schema.Schema.Type<typeof BedrockMessage>
|
|
106
|
+
|
|
107
|
+
const BedrockSystemBlock = Schema.Union([BedrockTextBlock, BedrockCache.CachePointBlock])
|
|
108
|
+
type BedrockSystemBlock = Schema.Schema.Type<typeof BedrockSystemBlock>
|
|
109
|
+
|
|
110
|
+
const BedrockToolSpec = Schema.Struct({
|
|
111
|
+
toolSpec: Schema.Struct({
|
|
112
|
+
name: Schema.String,
|
|
113
|
+
description: Schema.optional(Schema.String),
|
|
114
|
+
inputSchema: Schema.Struct({
|
|
115
|
+
json: JsonObject,
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
})
|
|
119
|
+
type BedrockToolSpec = Schema.Schema.Type<typeof BedrockToolSpec>
|
|
120
|
+
|
|
121
|
+
const BedrockTool = Schema.Union([BedrockToolSpec, BedrockCache.CachePointBlock])
|
|
122
|
+
type BedrockTool = Schema.Schema.Type<typeof BedrockTool>
|
|
123
|
+
|
|
124
|
+
const BedrockToolChoice = Schema.Union([
|
|
125
|
+
Schema.Struct({ auto: Schema.Struct({}) }),
|
|
126
|
+
Schema.Struct({ any: Schema.Struct({}) }),
|
|
127
|
+
Schema.Struct({ tool: Schema.Struct({ name: Schema.String }) }),
|
|
128
|
+
])
|
|
129
|
+
|
|
130
|
+
// Value sets from the Converse API reference. Unknown values pass through for forward compatibility.
|
|
131
|
+
const ServiceTierType = ProviderShared.knownString<"priority" | "default" | "flex" | "reserved">()
|
|
132
|
+
const GuardrailTrace = ProviderShared.knownString<"enabled" | "disabled" | "enabled_full">()
|
|
133
|
+
const GuardrailStreamProcessingMode = ProviderShared.knownString<"sync" | "async">()
|
|
134
|
+
const TextFormatType = ProviderShared.knownString<"json_schema">()
|
|
135
|
+
|
|
136
|
+
const BedrockBodyFields = {
|
|
137
|
+
modelId: Schema.String,
|
|
138
|
+
messages: Schema.Array(BedrockMessage),
|
|
139
|
+
system: optionalArray(BedrockSystemBlock),
|
|
140
|
+
inferenceConfig: Schema.optional(
|
|
141
|
+
Schema.Struct({
|
|
142
|
+
maxTokens: Schema.optional(Schema.Number),
|
|
143
|
+
temperature: Schema.optional(Schema.Number),
|
|
144
|
+
topP: Schema.optional(Schema.Number),
|
|
145
|
+
stopSequences: optionalArray(Schema.String),
|
|
146
|
+
}),
|
|
147
|
+
),
|
|
148
|
+
toolConfig: Schema.optional(
|
|
149
|
+
Schema.Struct({
|
|
150
|
+
tools: Schema.Array(BedrockTool),
|
|
151
|
+
toolChoice: Schema.optional(BedrockToolChoice),
|
|
152
|
+
}),
|
|
153
|
+
),
|
|
154
|
+
additionalModelRequestFields: Schema.optional(JsonObject),
|
|
155
|
+
serviceTier: Schema.optional(Schema.Struct({ type: ServiceTierType })),
|
|
156
|
+
guardrailConfig: Schema.optional(
|
|
157
|
+
Schema.Struct({
|
|
158
|
+
guardrailIdentifier: Schema.String,
|
|
159
|
+
guardrailVersion: Schema.String,
|
|
160
|
+
trace: Schema.optional(GuardrailTrace),
|
|
161
|
+
streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
|
|
162
|
+
}),
|
|
163
|
+
),
|
|
164
|
+
outputConfig: Schema.optional(
|
|
165
|
+
Schema.Struct({
|
|
166
|
+
textFormat: Schema.Struct({
|
|
167
|
+
type: TextFormatType,
|
|
168
|
+
structure: Schema.Struct({
|
|
169
|
+
jsonSchema: Schema.Struct({
|
|
170
|
+
schema: Schema.String,
|
|
171
|
+
name: Schema.optional(Schema.String),
|
|
172
|
+
description: Schema.optional(Schema.String),
|
|
173
|
+
}),
|
|
174
|
+
}),
|
|
175
|
+
}),
|
|
176
|
+
}),
|
|
177
|
+
),
|
|
178
|
+
requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
179
|
+
}
|
|
180
|
+
const BedrockConverseBody = Schema.Struct(BedrockBodyFields)
|
|
181
|
+
export type BedrockConverseBody = Schema.Schema.Type<typeof BedrockConverseBody>
|
|
182
|
+
|
|
183
|
+
const BedrockUsageSchema = Schema.Struct({
|
|
184
|
+
inputTokens: Schema.optional(Schema.Number),
|
|
185
|
+
outputTokens: Schema.optional(Schema.Number),
|
|
186
|
+
totalTokens: Schema.optional(Schema.Number),
|
|
187
|
+
cacheReadInputTokens: Schema.optional(Schema.Number),
|
|
188
|
+
cacheWriteInputTokens: Schema.optional(Schema.Number),
|
|
189
|
+
})
|
|
190
|
+
type BedrockUsageSchema = Schema.Schema.Type<typeof BedrockUsageSchema>
|
|
191
|
+
|
|
192
|
+
const BedrockStreamException = Schema.Struct({
|
|
193
|
+
message: Schema.optional(Schema.String),
|
|
194
|
+
originalMessage: Schema.optional(Schema.String),
|
|
195
|
+
originalStatusCode: Schema.optional(Schema.Number),
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
// Streaming event shape — the AWS event stream wraps each JSON payload by its
|
|
199
|
+
// `:event-type` header (e.g. `messageStart`, `contentBlockDelta`). We
|
|
200
|
+
// reconstruct that wrapping in `decodeFrames` below so the event schema can
|
|
201
|
+
// stay a plain discriminated record.
|
|
202
|
+
const BedrockEvent = Schema.Struct({
|
|
203
|
+
messageStart: Schema.optional(Schema.Struct({ role: Schema.String })),
|
|
204
|
+
contentBlockStart: Schema.optional(
|
|
205
|
+
Schema.Struct({
|
|
206
|
+
contentBlockIndex: Schema.Number,
|
|
207
|
+
start: Schema.optional(
|
|
208
|
+
Schema.Struct({
|
|
209
|
+
toolUse: Schema.optional(Schema.Struct({ toolUseId: Schema.String, name: Schema.String })),
|
|
210
|
+
}),
|
|
211
|
+
),
|
|
212
|
+
}),
|
|
213
|
+
),
|
|
214
|
+
contentBlockDelta: Schema.optional(
|
|
215
|
+
Schema.Struct({
|
|
216
|
+
contentBlockIndex: Schema.Number,
|
|
217
|
+
delta: Schema.optional(
|
|
218
|
+
Schema.Struct({
|
|
219
|
+
text: Schema.optional(Schema.String),
|
|
220
|
+
toolUse: Schema.optional(Schema.Struct({ input: Schema.String })),
|
|
221
|
+
reasoningContent: Schema.optional(
|
|
222
|
+
Schema.Struct({
|
|
223
|
+
text: Schema.optional(Schema.String),
|
|
224
|
+
signature: Schema.optional(Schema.String),
|
|
225
|
+
// Blob fields in Bedrock's JSON event stream are base64 strings.
|
|
226
|
+
redactedContent: Schema.optional(Schema.String),
|
|
227
|
+
// Vercel's Bedrock provider exposes the same delta under
|
|
228
|
+
// Anthropic's shorter `data` spelling.
|
|
229
|
+
data: Schema.optional(Schema.String),
|
|
230
|
+
}),
|
|
231
|
+
),
|
|
232
|
+
}),
|
|
233
|
+
),
|
|
234
|
+
}),
|
|
235
|
+
),
|
|
236
|
+
contentBlockStop: Schema.optional(Schema.Struct({ contentBlockIndex: Schema.Number })),
|
|
237
|
+
messageStop: Schema.optional(
|
|
238
|
+
Schema.Struct({
|
|
239
|
+
stopReason: Schema.String,
|
|
240
|
+
additionalModelResponseFields: Schema.optional(Schema.Unknown),
|
|
241
|
+
}),
|
|
242
|
+
),
|
|
243
|
+
metadata: Schema.optional(
|
|
244
|
+
Schema.Struct({
|
|
245
|
+
usage: Schema.optional(BedrockUsageSchema),
|
|
246
|
+
metrics: Schema.optional(Schema.Unknown),
|
|
247
|
+
}),
|
|
248
|
+
),
|
|
249
|
+
exception: Schema.optional(Schema.Struct({ type: Schema.String, details: BedrockStreamException })),
|
|
250
|
+
})
|
|
251
|
+
type BedrockEvent = Schema.Schema.Type<typeof BedrockEvent>
|
|
252
|
+
|
|
253
|
+
// =============================================================================
|
|
254
|
+
// Request Lowering
|
|
255
|
+
// =============================================================================
|
|
256
|
+
const lowerToolSpec = (tool: ToolDefinition): BedrockToolSpec => ({
|
|
257
|
+
toolSpec: {
|
|
258
|
+
name: tool.name,
|
|
259
|
+
...(tool.description.trim().length > 0 ? { description: tool.description } : {}),
|
|
260
|
+
inputSchema: { json: tool.inputSchema },
|
|
261
|
+
},
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
const lowerTools = (breakpoints: BedrockCache.Breakpoints, tools: ReadonlyArray<ToolDefinition>): BedrockTool[] => {
|
|
265
|
+
const result: BedrockTool[] = []
|
|
266
|
+
for (const tool of tools) {
|
|
267
|
+
result.push(lowerToolSpec(tool))
|
|
268
|
+
const cachePoint = BedrockCache.block(breakpoints, tool.cache)
|
|
269
|
+
if (cachePoint) result.push(cachePoint)
|
|
270
|
+
}
|
|
271
|
+
return result
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const textWithCache = (
|
|
275
|
+
breakpoints: BedrockCache.Breakpoints,
|
|
276
|
+
text: string,
|
|
277
|
+
cache: CacheHint | undefined,
|
|
278
|
+
): Array<BedrockTextBlock | BedrockCache.CachePointBlock> => {
|
|
279
|
+
const cachePoint = BedrockCache.block(breakpoints, cache)
|
|
280
|
+
return cachePoint ? [{ text }, cachePoint] : [{ text }]
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const lowerToolChoice = (toolChoice: NonNullable<LLMRequest["toolChoice"]>) =>
|
|
284
|
+
ProviderShared.matchToolChoice("Bedrock Converse", toolChoice, {
|
|
285
|
+
auto: () => ({ auto: {} }) as const,
|
|
286
|
+
none: () => undefined,
|
|
287
|
+
required: () => ({ any: {} }) as const,
|
|
288
|
+
tool: (name) => ({ tool: { name } }) as const,
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const providerMetadata = (key: string, metadata: Record<string, unknown>): ProviderMetadata => ({ [key]: metadata })
|
|
292
|
+
|
|
293
|
+
const reasoningSignature = (part: ReasoningPart, providerMetadataKey: string) => {
|
|
294
|
+
const metadata = part.providerMetadata?.[providerMetadataKey]
|
|
295
|
+
if (part.encrypted !== undefined) return part.encrypted
|
|
296
|
+
if (typeof metadata?.signature === "string") return metadata.signature
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const reasoningRedactedData = (part: ReasoningPart, providerMetadataKey: string) => {
|
|
300
|
+
const metadata = part.providerMetadata?.[providerMetadataKey]
|
|
301
|
+
if (typeof metadata?.redactedData === "string") return metadata.redactedData
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const removeEmptyToolInputKeys = (input: unknown): unknown => {
|
|
305
|
+
if (Array.isArray(input)) return input.map(removeEmptyToolInputKeys)
|
|
306
|
+
if (!ProviderShared.isRecord(input)) return input
|
|
307
|
+
return Object.fromEntries(
|
|
308
|
+
Object.entries(input).flatMap(([key, value]) => (key === "" ? [] : [[key, removeEmptyToolInputKeys(value)]])),
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const lowerToolCall = (part: ToolCallPart, normalizeID: (id: string) => string): BedrockToolUseBlock => ({
|
|
313
|
+
toolUse: {
|
|
314
|
+
toolUseId: normalizeID(part.id),
|
|
315
|
+
// Converse rejects replayed names over 64 characters; flattenRequest already fixed invalid characters.
|
|
316
|
+
name: part.name.slice(0, 64),
|
|
317
|
+
input: removeEmptyToolInputKeys(part.input),
|
|
318
|
+
},
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
const lowerToolResultContent = Effect.fnUntraced(function* (part: ToolResultPart, documentNames: Set<string>) {
|
|
322
|
+
if (part.result.type === "text" || part.result.type === "error")
|
|
323
|
+
return [{ text: ProviderShared.toolResultText(part) }]
|
|
324
|
+
if (part.result.type === "json") return [{ json: part.result.value }]
|
|
325
|
+
|
|
326
|
+
const content: Array<Schema.Schema.Type<typeof BedrockToolResultContentItem>> = []
|
|
327
|
+
for (const item of part.result.value) {
|
|
328
|
+
if (item.type === "text") {
|
|
329
|
+
content.push({ text: item.text })
|
|
330
|
+
continue
|
|
331
|
+
}
|
|
332
|
+
const media = yield* BedrockMedia.lower(ProviderShared.toolFileMedia(item), documentNames)
|
|
333
|
+
content.push(...media)
|
|
334
|
+
}
|
|
335
|
+
return content
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
const lowerToolResult = Effect.fnUntraced(function* (
|
|
339
|
+
part: ToolResultPart,
|
|
340
|
+
documentNames: Set<string>,
|
|
341
|
+
normalizeID: (id: string) => string,
|
|
342
|
+
) {
|
|
343
|
+
return {
|
|
344
|
+
toolResult: {
|
|
345
|
+
toolUseId: normalizeID(part.id),
|
|
346
|
+
content: yield* lowerToolResultContent(part, documentNames),
|
|
347
|
+
status: part.result.type === "error" ? "error" : "success",
|
|
348
|
+
},
|
|
349
|
+
} satisfies BedrockToolResultBlock
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
// Keep Claude and Nova tool-result images inline; put other models' images beside the result.
|
|
353
|
+
const keepToolImagesInline = (id: string) => id.includes("anthropic.claude-") || id.includes("amazon.nova-")
|
|
354
|
+
|
|
355
|
+
const lowerMessages = Effect.fnUntraced(function* (request: LLMRequest, breakpoints: BedrockCache.Breakpoints) {
|
|
356
|
+
const messages: BedrockMessage[] = []
|
|
357
|
+
const documentNames = new Set<string>()
|
|
358
|
+
// Mistral can reject replay IDs even when they satisfy Converse's broader ID syntax.
|
|
359
|
+
const normalizeID = request.model.id.includes("mistral.") ? MistralToolID.normalizer(request) : (id: string) => id
|
|
360
|
+
const providerMetadataKey = request.model.route.providerMetadataKey ?? request.model.provider
|
|
361
|
+
const hoistImages = !keepToolImagesInline(request.model.id)
|
|
362
|
+
// Bedrock expects parallel tool results before any images hoisted beside them.
|
|
363
|
+
const pendingImages: BedrockMedia.ImageBlock[] = []
|
|
364
|
+
const flushImages = () => {
|
|
365
|
+
if (pendingImages.length === 0) return
|
|
366
|
+
const previous = messages.at(-1)
|
|
367
|
+
if (previous?.role === "user")
|
|
368
|
+
messages[messages.length - 1] = { role: "user", content: [...previous.content, ...pendingImages] }
|
|
369
|
+
pendingImages.length = 0
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
for (const message of request.messages) {
|
|
373
|
+
if (message.role !== "tool") flushImages()
|
|
374
|
+
if (message.role === "system") {
|
|
375
|
+
const part = yield* ProviderShared.wrappedSystemUpdate("Bedrock Converse", message)
|
|
376
|
+
const content = textWithCache(breakpoints, part.text, part.cache)
|
|
377
|
+
const previous = messages.at(-1)
|
|
378
|
+
if (previous?.role === "user")
|
|
379
|
+
messages[messages.length - 1] = { role: "user", content: [...previous.content, ...content] }
|
|
380
|
+
else messages.push({ role: "user", content })
|
|
381
|
+
continue
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (message.role === "user") {
|
|
385
|
+
const content: BedrockUserBlock[] = []
|
|
386
|
+
for (const part of message.content) {
|
|
387
|
+
if (part.type === "text") {
|
|
388
|
+
content.push(...textWithCache(breakpoints, part.text, part.cache))
|
|
389
|
+
continue
|
|
390
|
+
}
|
|
391
|
+
if (part.type === "media") {
|
|
392
|
+
content.push(...(yield* BedrockMedia.lower(part, documentNames)))
|
|
393
|
+
continue
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const previous = messages.at(-1)
|
|
397
|
+
if (previous?.role === "user")
|
|
398
|
+
messages[messages.length - 1] = { role: "user", content: [...previous.content, ...content] }
|
|
399
|
+
else messages.push({ role: "user", content })
|
|
400
|
+
continue
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (message.role === "assistant") {
|
|
404
|
+
const content: BedrockAssistantBlock[] = []
|
|
405
|
+
for (const part of message.content) {
|
|
406
|
+
if (!ProviderShared.supportsContent(part, ["text", "reasoning", "tool-call"]))
|
|
407
|
+
return yield* ProviderShared.unsupportedContent("Bedrock Converse", "assistant", [
|
|
408
|
+
"text",
|
|
409
|
+
"reasoning",
|
|
410
|
+
"tool-call",
|
|
411
|
+
])
|
|
412
|
+
if (part.type === "text") {
|
|
413
|
+
content.push(...textWithCache(breakpoints, part.text, part.cache))
|
|
414
|
+
continue
|
|
415
|
+
}
|
|
416
|
+
if (part.type === "reasoning") {
|
|
417
|
+
const signature = reasoningSignature(part, providerMetadataKey)
|
|
418
|
+
const redactedData = reasoningRedactedData(part, providerMetadataKey)
|
|
419
|
+
if (signature === undefined && redactedData !== undefined) {
|
|
420
|
+
content.push({ reasoningContent: { redactedContent: redactedData } })
|
|
421
|
+
continue
|
|
422
|
+
}
|
|
423
|
+
if (signature === undefined || signature.trim().length === 0) continue
|
|
424
|
+
content.push({ reasoningContent: { reasoningText: { text: part.text, signature } } })
|
|
425
|
+
continue
|
|
426
|
+
}
|
|
427
|
+
if (part.type === "tool-call") {
|
|
428
|
+
content.push(lowerToolCall(part, normalizeID))
|
|
429
|
+
continue
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (content.length > 0) messages.push({ role: "assistant", content })
|
|
433
|
+
continue
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const content: BedrockUserBlock[] = []
|
|
437
|
+
for (const part of message.content) {
|
|
438
|
+
const result = yield* lowerToolResult(part, documentNames, normalizeID)
|
|
439
|
+
const images: BedrockMedia.ImageBlock[] = hoistImages
|
|
440
|
+
? result.toolResult.content.filter((item) => "image" in item)
|
|
441
|
+
: []
|
|
442
|
+
const nonImageContent = result.toolResult.content.filter((item) => !("image" in item))
|
|
443
|
+
content.push(
|
|
444
|
+
images.length === 0
|
|
445
|
+
? result
|
|
446
|
+
: {
|
|
447
|
+
toolResult: {
|
|
448
|
+
...result.toolResult,
|
|
449
|
+
content: nonImageContent.length > 0 ? nonImageContent : [{ text: "See attached image." }],
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
)
|
|
453
|
+
pendingImages.push(...images)
|
|
454
|
+
const cachePoint = BedrockCache.block(breakpoints, part.cache)
|
|
455
|
+
if (cachePoint) content.push(cachePoint)
|
|
456
|
+
}
|
|
457
|
+
const previous = messages.at(-1)
|
|
458
|
+
if (previous?.role === "user")
|
|
459
|
+
messages[messages.length - 1] = { role: "user", content: [...previous.content, ...content] }
|
|
460
|
+
else messages.push({ role: "user", content })
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
flushImages()
|
|
464
|
+
return messages
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
// System prompts share the cache-point convention: emit the text block, then
|
|
468
|
+
// optionally a positional `cachePoint` marker.
|
|
469
|
+
const lowerSystem = (breakpoints: BedrockCache.Breakpoints, system: ReadonlyArray<LLMRequest["system"][number]>) => {
|
|
470
|
+
const content = system
|
|
471
|
+
.filter((part) => part.text.length > 0)
|
|
472
|
+
.flatMap((part) => textWithCache(breakpoints, part.text, part.cache))
|
|
473
|
+
return content.length === 0 ? undefined : content
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Nova 2 rejects `maxTokens` at high reasoning effort, where its output can exceed the field's maximum. Other models
|
|
477
|
+
// that take `reasoningConfig`, such as Grok on Bedrock, accept it.
|
|
478
|
+
const isNova2 = (model: LanguageModel) => /\bamazon\.nova-2-/.test(model.id)
|
|
479
|
+
const isHighReasoningEffort = Schema.is(
|
|
480
|
+
Schema.Struct({
|
|
481
|
+
additionalModelRequestFields: Schema.Struct({
|
|
482
|
+
reasoningConfig: Schema.Struct({ maxReasoningEffort: Schema.Literal("high") }),
|
|
483
|
+
}),
|
|
484
|
+
}),
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
// Claude 4.6+ pairs effort with adaptive thinking; earlier Claude models take effort beside a manual budget.
|
|
488
|
+
const supportsAdaptiveThinking = (model: LanguageModel) => {
|
|
489
|
+
const version = claudeVersion(model.id)
|
|
490
|
+
return version !== undefined && (version.major > 4 || (version.major === 4 && version.minor >= 6))
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const effortFields = (model: LanguageModel, effort: string) => {
|
|
494
|
+
if (model.id.includes("anthropic")) return { output_config: { effort } }
|
|
495
|
+
// gpt-oss takes the flat chat-completions spelling; newer OpenAI and xAI models take the Responses one.
|
|
496
|
+
if (model.id.includes("openai.gpt-oss")) return { reasoning_effort: effort }
|
|
497
|
+
if (model.id.includes("openai.") || model.id.includes("xai.")) return { reasoning: { effort } }
|
|
498
|
+
return { reasoningConfig: { type: "enabled", maxReasoningEffort: effort } }
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const Options = Schema.Struct({
|
|
502
|
+
/** Claude thinking. `adaptive` and `disabled` apply to Claude models only. */
|
|
503
|
+
thinking: Schema.optional(
|
|
504
|
+
Schema.Union([
|
|
505
|
+
Schema.Struct({ type: Schema.Literal("enabled"), budgetTokens: Schema.Number }),
|
|
506
|
+
Schema.Struct({
|
|
507
|
+
type: Schema.Literal("adaptive"),
|
|
508
|
+
display: Schema.optional(ProviderShared.knownString<"summarized" | "omitted">()),
|
|
509
|
+
}),
|
|
510
|
+
Schema.Struct({ type: Schema.Literal("disabled") }),
|
|
511
|
+
]),
|
|
512
|
+
),
|
|
513
|
+
/** Reasoning effort, sent in the field each model family reads. */
|
|
514
|
+
effort: Schema.optional(ProviderShared.knownString<"low" | "medium" | "high" | "xhigh" | "max">()),
|
|
515
|
+
serviceTier: Schema.optional(ServiceTierType),
|
|
516
|
+
/** Constrains the response text to a JSON schema. */
|
|
517
|
+
outputFormat: Schema.optional(
|
|
518
|
+
Schema.Struct({
|
|
519
|
+
type: TextFormatType,
|
|
520
|
+
schema: JsonObject,
|
|
521
|
+
name: Schema.optional(Schema.String),
|
|
522
|
+
description: Schema.optional(Schema.String),
|
|
523
|
+
}),
|
|
524
|
+
),
|
|
525
|
+
guardrail: Schema.optional(
|
|
526
|
+
Schema.Struct({
|
|
527
|
+
identifier: Schema.String,
|
|
528
|
+
version: Schema.String,
|
|
529
|
+
trace: Schema.optional(GuardrailTrace),
|
|
530
|
+
streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
|
|
531
|
+
}),
|
|
532
|
+
),
|
|
533
|
+
/** Key-value pairs for filtering invocation logs. */
|
|
534
|
+
requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
535
|
+
})
|
|
536
|
+
/** Caller-facing provider options; unknown keys are accepted and ignored. */
|
|
537
|
+
export type OptionsInput = ProviderOptions & typeof Options.Encoded
|
|
538
|
+
const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))
|
|
539
|
+
// Claude on Bedrock requires the thinking budget below `maxTokens`, with a minimum of 1,024.
|
|
540
|
+
const MIN_THINKING_BUDGET = 1_024
|
|
541
|
+
|
|
542
|
+
const isThinkingDisabled = Schema.is(
|
|
543
|
+
Schema.Struct({
|
|
544
|
+
additionalModelRequestFields: Schema.Struct({
|
|
545
|
+
thinking: Schema.Struct({ type: Schema.Literals(["disabled", "between_tools"]) }),
|
|
546
|
+
}),
|
|
547
|
+
}),
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
// Claude 5.1+ binds each thinking signature to the prefix above it. Ask Bedrock to drop the affected blocks instead of
|
|
551
|
+
// failing when that prefix changes. `http.body` overlays this field by field, so callers can still override it.
|
|
552
|
+
const applyThinkingBindingDefault = (request: LLMRequest, thinking: Readonly<Record<string, unknown>> | undefined) => {
|
|
553
|
+
if (thinking?.type === "disabled" || isThinkingDisabled(request.http?.body)) return thinking
|
|
554
|
+
if (!supportsThinkingBlockBinding(request.model)) return thinking
|
|
555
|
+
return {
|
|
556
|
+
...(thinking ?? { type: "adaptive" as const }),
|
|
557
|
+
block_binding: { prefix_mismatch_behavior: "drop_block" },
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request: LLMRequest) {
|
|
562
|
+
const toolChoice = request.toolChoice ? yield* lowerToolChoice(request.toolChoice) : undefined
|
|
563
|
+
const definitions = ProviderShared.flattenTools(request.tools)
|
|
564
|
+
const options = yield* decodeOptions(request.providerOptions ?? {})
|
|
565
|
+
const maxTokens =
|
|
566
|
+
isNova2(request.model) && (options.effort === "high" || isHighReasoningEffort(request.http?.body))
|
|
567
|
+
? undefined
|
|
568
|
+
: request.maxTokens
|
|
569
|
+
const thinking = applyThinkingBindingDefault(
|
|
570
|
+
request,
|
|
571
|
+
(() => {
|
|
572
|
+
if (options.thinking?.type === "enabled")
|
|
573
|
+
return {
|
|
574
|
+
type: "enabled",
|
|
575
|
+
budget_tokens: ProviderShared.fitThinkingBudget(
|
|
576
|
+
options.thinking.budgetTokens,
|
|
577
|
+
maxTokens,
|
|
578
|
+
MIN_THINKING_BUDGET,
|
|
579
|
+
),
|
|
580
|
+
}
|
|
581
|
+
if (options.thinking !== undefined) return options.thinking
|
|
582
|
+
if (options.effort !== undefined && supportsAdaptiveThinking(request.model)) return { type: "adaptive" }
|
|
583
|
+
})(),
|
|
584
|
+
)
|
|
585
|
+
const additionalModelRequestFields = {
|
|
586
|
+
...(request.topK === undefined ? {} : { top_k: request.topK }),
|
|
587
|
+
...(thinking === undefined ? {} : { thinking }),
|
|
588
|
+
...(options.effort === undefined ? {} : effortFields(request.model, options.effort)),
|
|
589
|
+
// Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
|
|
590
|
+
...(thinking?.block_binding === undefined ? {} : { anthropic_beta: [THINKING_BINDING_BETA] }),
|
|
591
|
+
}
|
|
592
|
+
// Bedrock-Claude shares Anthropic's 4-breakpoint cap. Spend the budget in
|
|
593
|
+
// tools → system → messages order to favour the highest-impact prefixes.
|
|
594
|
+
const breakpoints = BedrockCache.breakpoints(request.model)
|
|
595
|
+
const toolConfig = (() => {
|
|
596
|
+
if (definitions.length === 0) return undefined
|
|
597
|
+
return {
|
|
598
|
+
tools: lowerTools(breakpoints, definitions),
|
|
599
|
+
// Converse has no native "none". Keep definitions stable for prompt
|
|
600
|
+
// caching and omit only the unsupported choice.
|
|
601
|
+
toolChoice,
|
|
602
|
+
}
|
|
603
|
+
})()
|
|
604
|
+
const system = lowerSystem(breakpoints, request.system)
|
|
605
|
+
const messages = yield* lowerMessages(request, breakpoints)
|
|
606
|
+
yield* warnDropped(breakpoints, "Bedrock Converse", BedrockCache.BEDROCK_BREAKPOINT_CAP)
|
|
607
|
+
const inferenceConfig = (() => {
|
|
608
|
+
if (
|
|
609
|
+
maxTokens === undefined &&
|
|
610
|
+
request.temperature === undefined &&
|
|
611
|
+
request.topP === undefined &&
|
|
612
|
+
(request.stop === undefined || request.stop.length === 0)
|
|
613
|
+
)
|
|
614
|
+
return undefined
|
|
615
|
+
return {
|
|
616
|
+
maxTokens,
|
|
617
|
+
temperature: request.temperature,
|
|
618
|
+
topP: request.topP,
|
|
619
|
+
stopSequences: request.stop,
|
|
620
|
+
}
|
|
621
|
+
})()
|
|
622
|
+
return {
|
|
623
|
+
modelId: request.model.id,
|
|
624
|
+
messages,
|
|
625
|
+
system,
|
|
626
|
+
inferenceConfig,
|
|
627
|
+
toolConfig,
|
|
628
|
+
// Converse's base inferenceConfig has no topK, thinking or effort; models accept them
|
|
629
|
+
// as model-specific fields, so they go through additionalModelRequestFields.
|
|
630
|
+
additionalModelRequestFields:
|
|
631
|
+
Object.keys(additionalModelRequestFields).length === 0 ? undefined : additionalModelRequestFields,
|
|
632
|
+
serviceTier: options.serviceTier === undefined ? undefined : { type: options.serviceTier },
|
|
633
|
+
guardrailConfig:
|
|
634
|
+
options.guardrail === undefined
|
|
635
|
+
? undefined
|
|
636
|
+
: {
|
|
637
|
+
guardrailIdentifier: options.guardrail.identifier,
|
|
638
|
+
guardrailVersion: options.guardrail.version,
|
|
639
|
+
trace: options.guardrail.trace,
|
|
640
|
+
streamProcessingMode: options.guardrail.streamProcessingMode,
|
|
641
|
+
},
|
|
642
|
+
outputConfig:
|
|
643
|
+
options.outputFormat === undefined
|
|
644
|
+
? undefined
|
|
645
|
+
: {
|
|
646
|
+
textFormat: {
|
|
647
|
+
type: options.outputFormat.type,
|
|
648
|
+
structure: {
|
|
649
|
+
jsonSchema: {
|
|
650
|
+
schema: ProviderShared.encodeJson(options.outputFormat.schema),
|
|
651
|
+
name: options.outputFormat.name,
|
|
652
|
+
description: options.outputFormat.description,
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
requestMetadata: options.requestMetadata,
|
|
658
|
+
}
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
// =============================================================================
|
|
662
|
+
// Stream Parsing
|
|
663
|
+
// =============================================================================
|
|
664
|
+
const mapFinishReason = (reason: string): FinishReason => {
|
|
665
|
+
if (reason === "end_turn" || reason === "stop_sequence") return "stop"
|
|
666
|
+
if (reason === "max_tokens" || reason === "model_context_window_exceeded") return "length"
|
|
667
|
+
if (reason === "tool_use") return "tool-calls"
|
|
668
|
+
if (reason === "content_filtered" || reason === "guardrail_intervened") return "content-filter"
|
|
669
|
+
return "unknown"
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// AWS reports inputTokens separately from cache reads and writes.
|
|
673
|
+
// Bedrock does not break reasoning out of outputTokens for current models.
|
|
674
|
+
const mapUsage = (usage: BedrockUsageSchema | undefined, providerMetadataKey: string): Usage | undefined => {
|
|
675
|
+
if (!usage) return undefined
|
|
676
|
+
const inputTokens = ProviderShared.sumTokens(
|
|
677
|
+
usage.inputTokens,
|
|
678
|
+
usage.cacheReadInputTokens,
|
|
679
|
+
usage.cacheWriteInputTokens,
|
|
680
|
+
)
|
|
681
|
+
return new Usage({
|
|
682
|
+
inputTokens,
|
|
683
|
+
outputTokens: usage.outputTokens,
|
|
684
|
+
nonCachedInputTokens: usage.inputTokens,
|
|
685
|
+
cacheReadInputTokens: usage.cacheReadInputTokens,
|
|
686
|
+
cacheWriteInputTokens: usage.cacheWriteInputTokens,
|
|
687
|
+
totalTokens: ProviderShared.totalTokens(inputTokens, usage.outputTokens, usage.totalTokens),
|
|
688
|
+
providerMetadata: { [providerMetadataKey]: usage },
|
|
689
|
+
})
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
interface ParserState {
|
|
693
|
+
readonly providerMetadataKey: string
|
|
694
|
+
readonly tools: ToolStream.State<number>
|
|
695
|
+
// Bedrock splits the finish into `messageStop` (carries `stopReason`) and
|
|
696
|
+
// `metadata` (carries usage). Hold both in state so `onHalt` can emit exactly
|
|
697
|
+
// one finish after both chunks have had a chance to arrive.
|
|
698
|
+
readonly finishReason: FinishReasonDetails | undefined
|
|
699
|
+
readonly usage: Usage | undefined
|
|
700
|
+
readonly hasToolCalls: boolean
|
|
701
|
+
readonly lifecycle: Lifecycle.State
|
|
702
|
+
readonly reasoningSignatures: Readonly<Record<number, string>>
|
|
703
|
+
readonly reasoningRedactedContent: Readonly<Record<number, Uint8Array[]>>
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const encodeRedactedContent = (chunks: ReadonlyArray<Uint8Array>) => Base64.encode(concatBytes(chunks))
|
|
707
|
+
|
|
708
|
+
const step = (state: ParserState, event: BedrockEvent) =>
|
|
709
|
+
Effect.gen(function* () {
|
|
710
|
+
if (event.contentBlockStart?.start?.toolUse) {
|
|
711
|
+
const index = event.contentBlockStart.contentBlockIndex
|
|
712
|
+
const events: LLMEvent[] = []
|
|
713
|
+
const lifecycle = Lifecycle.stepStart(state.lifecycle, events)
|
|
714
|
+
return [
|
|
715
|
+
{
|
|
716
|
+
...state,
|
|
717
|
+
lifecycle,
|
|
718
|
+
tools: ToolStream.start(state.tools, index, {
|
|
719
|
+
id: event.contentBlockStart.start.toolUse.toolUseId,
|
|
720
|
+
name: event.contentBlockStart.start.toolUse.name,
|
|
721
|
+
}),
|
|
722
|
+
},
|
|
723
|
+
[
|
|
724
|
+
...events,
|
|
725
|
+
LLMEvent.toolInputStart({
|
|
726
|
+
id: event.contentBlockStart.start.toolUse.toolUseId,
|
|
727
|
+
name: event.contentBlockStart.start.toolUse.name,
|
|
728
|
+
}),
|
|
729
|
+
],
|
|
730
|
+
] as const
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (event.contentBlockDelta?.delta?.text) {
|
|
734
|
+
const events: LLMEvent[] = []
|
|
735
|
+
return [
|
|
736
|
+
{
|
|
737
|
+
...state,
|
|
738
|
+
lifecycle: Lifecycle.textDelta(
|
|
739
|
+
state.lifecycle,
|
|
740
|
+
events,
|
|
741
|
+
`text-${event.contentBlockDelta.contentBlockIndex}`,
|
|
742
|
+
event.contentBlockDelta.delta.text,
|
|
743
|
+
),
|
|
744
|
+
},
|
|
745
|
+
events,
|
|
746
|
+
] as const
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (event.contentBlockDelta?.delta?.reasoningContent) {
|
|
750
|
+
const index = event.contentBlockDelta.contentBlockIndex
|
|
751
|
+
const reasoning = event.contentBlockDelta.delta.reasoningContent
|
|
752
|
+
const events: LLMEvent[] = []
|
|
753
|
+
const redactedChunk = yield* (() => {
|
|
754
|
+
if (reasoning.redactedContent === undefined) return Effect.succeed(undefined)
|
|
755
|
+
return Effect.fromResult(Base64.decode(reasoning.redactedContent)).pipe(
|
|
756
|
+
Effect.mapError((cause) =>
|
|
757
|
+
ProviderShared.eventError(
|
|
758
|
+
ADAPTER,
|
|
759
|
+
"Bedrock Converse reasoningContent.redactedContent contains invalid base64 data",
|
|
760
|
+
undefined,
|
|
761
|
+
cause,
|
|
762
|
+
),
|
|
763
|
+
),
|
|
764
|
+
)
|
|
765
|
+
})()
|
|
766
|
+
const redactedChunks = state.reasoningRedactedContent[index] ?? []
|
|
767
|
+
if (redactedChunk !== undefined) redactedChunks.push(redactedChunk)
|
|
768
|
+
const metadata = (() => {
|
|
769
|
+
if (reasoning.signature) return providerMetadata(state.providerMetadataKey, { signature: reasoning.signature })
|
|
770
|
+
if (redactedChunk === undefined && reasoning.data !== undefined)
|
|
771
|
+
return providerMetadata(state.providerMetadataKey, { redactedData: reasoning.data })
|
|
772
|
+
})()
|
|
773
|
+
const lifecycle = (() => {
|
|
774
|
+
if (reasoning.text !== undefined || metadata !== undefined)
|
|
775
|
+
return Lifecycle.reasoningDelta(state.lifecycle, events, `reasoning-${index}`, reasoning.text ?? "", metadata)
|
|
776
|
+
if (redactedChunk !== undefined) return Lifecycle.reasoningStart(state.lifecycle, events, `reasoning-${index}`)
|
|
777
|
+
return state.lifecycle
|
|
778
|
+
})()
|
|
779
|
+
const reasoningRedactedContent = (() => {
|
|
780
|
+
if (redactedChunk !== undefined) return { ...state.reasoningRedactedContent, [index]: redactedChunks }
|
|
781
|
+
if (reasoning.data === undefined) return state.reasoningRedactedContent
|
|
782
|
+
return Object.fromEntries(
|
|
783
|
+
Object.entries(state.reasoningRedactedContent).filter(([key]) => key !== String(index)),
|
|
784
|
+
)
|
|
785
|
+
})()
|
|
786
|
+
const reasoningSignatures = (() => {
|
|
787
|
+
if (!reasoning.signature) return state.reasoningSignatures
|
|
788
|
+
return { ...state.reasoningSignatures, [index]: reasoning.signature }
|
|
789
|
+
})()
|
|
790
|
+
return [
|
|
791
|
+
{
|
|
792
|
+
...state,
|
|
793
|
+
lifecycle,
|
|
794
|
+
reasoningSignatures,
|
|
795
|
+
reasoningRedactedContent,
|
|
796
|
+
},
|
|
797
|
+
events,
|
|
798
|
+
] as const
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (event.contentBlockDelta?.delta?.toolUse) {
|
|
802
|
+
// A delta for a block that is not open, whether it already stopped or never
|
|
803
|
+
// started, has nothing to attach to and is dropped.
|
|
804
|
+
const result = ToolStream.append(
|
|
805
|
+
state.tools,
|
|
806
|
+
event.contentBlockDelta.contentBlockIndex,
|
|
807
|
+
event.contentBlockDelta.delta.toolUse.input,
|
|
808
|
+
)
|
|
809
|
+
if (!result) return [state, []] as const
|
|
810
|
+
const events: LLMEvent[] = []
|
|
811
|
+
const lifecycle = result.events.length ? Lifecycle.stepStart(state.lifecycle, events) : state.lifecycle
|
|
812
|
+
events.push(...result.events)
|
|
813
|
+
return [{ ...state, lifecycle, tools: result.tools }, events] as const
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
if (event.contentBlockStop) {
|
|
817
|
+
const index = event.contentBlockStop.contentBlockIndex
|
|
818
|
+
const result = yield* ToolStream.finish(ADAPTER, state.tools, index)
|
|
819
|
+
const events: LLMEvent[] = []
|
|
820
|
+
const resultEvents = result.events ?? []
|
|
821
|
+
const lifecycle = (() => {
|
|
822
|
+
if (resultEvents.length) return Lifecycle.stepStart(state.lifecycle, events)
|
|
823
|
+
const metadata = (() => {
|
|
824
|
+
const signature = state.reasoningSignatures[index]
|
|
825
|
+
if (signature) return providerMetadata(state.providerMetadataKey, { signature })
|
|
826
|
+
const redactedContent = state.reasoningRedactedContent[index]
|
|
827
|
+
if (redactedContent)
|
|
828
|
+
return providerMetadata(state.providerMetadataKey, {
|
|
829
|
+
redactedData: encodeRedactedContent(redactedContent),
|
|
830
|
+
})
|
|
831
|
+
})()
|
|
832
|
+
return Lifecycle.reasoningEnd(
|
|
833
|
+
Lifecycle.textEnd(state.lifecycle, events, `text-${index}`),
|
|
834
|
+
events,
|
|
835
|
+
`reasoning-${index}`,
|
|
836
|
+
metadata,
|
|
837
|
+
)
|
|
838
|
+
})()
|
|
839
|
+
events.push(...resultEvents)
|
|
840
|
+
return [
|
|
841
|
+
{
|
|
842
|
+
...state,
|
|
843
|
+
hasToolCalls:
|
|
844
|
+
resultEvents.some((event) => LLMEvent.is.toolCall(event) || LLMEvent.is.toolInputError(event)) ||
|
|
845
|
+
state.hasToolCalls,
|
|
846
|
+
lifecycle,
|
|
847
|
+
tools: result.tools,
|
|
848
|
+
reasoningSignatures: Object.fromEntries(
|
|
849
|
+
Object.entries(state.reasoningSignatures).filter(([key]) => key !== String(index)),
|
|
850
|
+
),
|
|
851
|
+
reasoningRedactedContent: Object.fromEntries(
|
|
852
|
+
Object.entries(state.reasoningRedactedContent).filter(([key]) => key !== String(index)),
|
|
853
|
+
),
|
|
854
|
+
},
|
|
855
|
+
events,
|
|
856
|
+
] as const
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (event.messageStop) {
|
|
860
|
+
if (
|
|
861
|
+
event.messageStop.stopReason === "malformed_model_output" ||
|
|
862
|
+
event.messageStop.stopReason === "malformed_tool_use"
|
|
863
|
+
)
|
|
864
|
+
return yield* ProviderShared.eventError(
|
|
865
|
+
ADAPTER,
|
|
866
|
+
`Bedrock Converse stopped with ${event.messageStop.stopReason}`,
|
|
867
|
+
ProviderShared.encodeJson(event),
|
|
868
|
+
)
|
|
869
|
+
return [
|
|
870
|
+
{
|
|
871
|
+
...state,
|
|
872
|
+
finishReason: {
|
|
873
|
+
normalized: mapFinishReason(event.messageStop.stopReason),
|
|
874
|
+
raw: event.messageStop.stopReason,
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
[],
|
|
878
|
+
] as const
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (event.metadata) {
|
|
882
|
+
const usage = mapUsage(event.metadata.usage, state.providerMetadataKey) ?? state.usage
|
|
883
|
+
return [
|
|
884
|
+
{
|
|
885
|
+
...state,
|
|
886
|
+
usage,
|
|
887
|
+
},
|
|
888
|
+
[],
|
|
889
|
+
] as const
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
if (event.exception) {
|
|
893
|
+
const message =
|
|
894
|
+
event.exception.details.message ?? event.exception.details.originalMessage ?? "Bedrock Converse stream error"
|
|
895
|
+
const body = ProviderShared.encodeJson(event)
|
|
896
|
+
return yield* new AIError({
|
|
897
|
+
reason: classifyProviderFailure({
|
|
898
|
+
message,
|
|
899
|
+
status: event.exception.details.originalStatusCode,
|
|
900
|
+
rawBody: body,
|
|
901
|
+
}),
|
|
902
|
+
})
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
return [state, []] as const
|
|
906
|
+
})
|
|
907
|
+
|
|
908
|
+
const framing = BedrockEventStream.framing(ADAPTER)
|
|
909
|
+
|
|
910
|
+
const onHalt = (state: ParserState): ReadonlyArray<LLMEvent> => {
|
|
911
|
+
if (!state.finishReason) return []
|
|
912
|
+
const normalized = (() => {
|
|
913
|
+
if (state.finishReason.normalized === "stop" && state.hasToolCalls) return "tool-calls"
|
|
914
|
+
return state.finishReason.normalized
|
|
915
|
+
})()
|
|
916
|
+
const events: LLMEvent[] = []
|
|
917
|
+
const lifecycle = Object.entries(state.reasoningRedactedContent).reduce((current, [index, chunks]) => {
|
|
918
|
+
const signature = state.reasoningSignatures[Number(index)]
|
|
919
|
+
return Lifecycle.reasoningEnd(
|
|
920
|
+
current,
|
|
921
|
+
events,
|
|
922
|
+
`reasoning-${index}`,
|
|
923
|
+
providerMetadata(
|
|
924
|
+
state.providerMetadataKey,
|
|
925
|
+
signature ? { signature } : { redactedData: encodeRedactedContent(chunks) },
|
|
926
|
+
),
|
|
927
|
+
)
|
|
928
|
+
}, state.lifecycle)
|
|
929
|
+
Lifecycle.finish(lifecycle, events, {
|
|
930
|
+
reason: {
|
|
931
|
+
...state.finishReason,
|
|
932
|
+
normalized,
|
|
933
|
+
},
|
|
934
|
+
usage: state.usage,
|
|
935
|
+
})
|
|
936
|
+
return events
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// =============================================================================
|
|
940
|
+
// Protocol And Bedrock Route
|
|
941
|
+
// =============================================================================
|
|
942
|
+
/**
|
|
943
|
+
* The Bedrock Converse protocol — request body construction, body schema, and
|
|
944
|
+
* the streaming-event state machine.
|
|
945
|
+
*/
|
|
946
|
+
export const protocol = Protocol.make({
|
|
947
|
+
id: ADAPTER,
|
|
948
|
+
body: {
|
|
949
|
+
schema: BedrockConverseBody,
|
|
950
|
+
from: fromRequest,
|
|
951
|
+
},
|
|
952
|
+
stream: {
|
|
953
|
+
event: BedrockEventStream.Frame.pipe(Schema.decodeTo(BedrockEvent)),
|
|
954
|
+
initial: (request) => ({
|
|
955
|
+
providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
|
|
956
|
+
tools: ToolStream.empty<number>(),
|
|
957
|
+
finishReason: undefined,
|
|
958
|
+
usage: undefined,
|
|
959
|
+
hasToolCalls: false,
|
|
960
|
+
lifecycle: Lifecycle.initial(),
|
|
961
|
+
reasoningSignatures: {},
|
|
962
|
+
reasoningRedactedContent: {},
|
|
963
|
+
}),
|
|
964
|
+
step,
|
|
965
|
+
onHalt: (state) => Effect.succeed(onHalt(state)),
|
|
966
|
+
},
|
|
967
|
+
})
|
|
968
|
+
|
|
969
|
+
export const route = Route.make({
|
|
970
|
+
id: ADAPTER,
|
|
971
|
+
provider: "bedrock",
|
|
972
|
+
providerMetadataKey: "bedrock",
|
|
973
|
+
protocol,
|
|
974
|
+
// Bedrock's URL embeds the region in the route endpoint host and the
|
|
975
|
+
// validated modelId in the path. We read the validated body so the URL
|
|
976
|
+
// matches the body that gets signed.
|
|
977
|
+
endpoint: Endpoint.path<BedrockConverseBody>(
|
|
978
|
+
({ body }) => `/model/${encodeURIComponent(body.modelId)}/converse-stream`,
|
|
979
|
+
),
|
|
980
|
+
auth: BedrockAuth.auth,
|
|
981
|
+
framing,
|
|
982
|
+
})
|
|
983
|
+
|
|
984
|
+
export * as BedrockConverse from "./bedrock-converse.js"
|