@zyro-sec/ai 1.0.0 → 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/example/tutorial.ts +284 -0
- package/package.json +11 -166
- 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,2548 @@
|
|
|
1
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec"
|
|
2
|
+
import { fromUtf8, toUtf8 } from "@smithy/util-utf8"
|
|
3
|
+
import { describe, expect } from "bun:test"
|
|
4
|
+
import { Effect, Ref, Schema, Stream } from "effect"
|
|
5
|
+
import { Base64 } from "effect/encoding"
|
|
6
|
+
import { HttpClientRequest } from "effect/http"
|
|
7
|
+
import {
|
|
8
|
+
ai,
|
|
9
|
+
CacheHint,
|
|
10
|
+
type LanguageModel,
|
|
11
|
+
LLMEvent,
|
|
12
|
+
Media,
|
|
13
|
+
Message,
|
|
14
|
+
tool,
|
|
15
|
+
ToolCallPart,
|
|
16
|
+
ToolChoice,
|
|
17
|
+
ToolDefinition,
|
|
18
|
+
ToolRuntime,
|
|
19
|
+
} from "../../src/effect.js"
|
|
20
|
+
import { LLMClient } from "../../src/route.js"
|
|
21
|
+
import { compileRequest } from "../../src/route/client.js"
|
|
22
|
+
import { AmazonBedrock } from "../../src/providers.js"
|
|
23
|
+
import { it } from "../lib/effect.js"
|
|
24
|
+
import { withProcessEnv } from "../lib/env.js"
|
|
25
|
+
import { dynamicResponse, fixedResponse } from "../lib/http.js"
|
|
26
|
+
import {
|
|
27
|
+
eventSummary,
|
|
28
|
+
expectWeatherToolLoop,
|
|
29
|
+
runWeatherToolLoop,
|
|
30
|
+
weatherTool,
|
|
31
|
+
weatherToolLoopRequest,
|
|
32
|
+
weatherToolName,
|
|
33
|
+
} from "../recorded-scenarios.js"
|
|
34
|
+
import { recordedTests } from "../recorded-test.js"
|
|
35
|
+
|
|
36
|
+
const codec = new EventStreamCodec(toUtf8, fromUtf8)
|
|
37
|
+
const utf8Encoder = new TextEncoder()
|
|
38
|
+
|
|
39
|
+
// Build a single AWS event-stream frame for a Converse stream event. Each
|
|
40
|
+
// frame carries `:message-type=event` + `:event-type=<name>` headers and a
|
|
41
|
+
// JSON payload body.
|
|
42
|
+
const eventFrame = (type: string, payload: object) =>
|
|
43
|
+
codec.encode({
|
|
44
|
+
headers: {
|
|
45
|
+
":message-type": { type: "string", value: "event" },
|
|
46
|
+
":event-type": { type: "string", value: type },
|
|
47
|
+
":content-type": { type: "string", value: "application/json" },
|
|
48
|
+
},
|
|
49
|
+
body: utf8Encoder.encode(JSON.stringify(payload)),
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const exceptionFrame = (type: string, payload: object) =>
|
|
53
|
+
codec.encode({
|
|
54
|
+
headers: {
|
|
55
|
+
":message-type": { type: "string", value: "exception" },
|
|
56
|
+
":exception-type": { type: "string", value: type },
|
|
57
|
+
":content-type": { type: "string", value: "application/json" },
|
|
58
|
+
},
|
|
59
|
+
body: utf8Encoder.encode(JSON.stringify(payload)),
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const errorFrame = (code: string, message: string) =>
|
|
63
|
+
codec.encode({
|
|
64
|
+
headers: {
|
|
65
|
+
":message-type": { type: "string", value: "error" },
|
|
66
|
+
":error-code": { type: "string", value: code },
|
|
67
|
+
":error-message": { type: "string", value: message },
|
|
68
|
+
},
|
|
69
|
+
body: new Uint8Array(),
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const concat = (frames: ReadonlyArray<Uint8Array>) => {
|
|
73
|
+
const total = frames.reduce((sum, frame) => sum + frame.length, 0)
|
|
74
|
+
const out = new Uint8Array(total)
|
|
75
|
+
let offset = 0
|
|
76
|
+
for (const frame of frames) {
|
|
77
|
+
out.set(frame, offset)
|
|
78
|
+
offset += frame.length
|
|
79
|
+
}
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const eventStreamBody = (...payloads: ReadonlyArray<readonly [string, object]>) =>
|
|
84
|
+
concat(payloads.map(([type, payload]) => eventFrame(type, payload)))
|
|
85
|
+
|
|
86
|
+
// Override the default SSE content-type with the binary event-stream type so
|
|
87
|
+
// the cassette layer treats the body as bytes when recording.
|
|
88
|
+
const fixedBytes = (bytes: Uint8Array) =>
|
|
89
|
+
fixedResponse(bytes.slice().buffer, { headers: { "content-type": "application/vnd.amazon.eventstream" } })
|
|
90
|
+
|
|
91
|
+
const fixedByteChunks = (...chunks: ReadonlyArray<Uint8Array>) =>
|
|
92
|
+
fixedResponse(
|
|
93
|
+
new ReadableStream<Uint8Array>({
|
|
94
|
+
start(controller) {
|
|
95
|
+
chunks.forEach((chunk) => controller.enqueue(chunk))
|
|
96
|
+
controller.close()
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
{ headers: { "content-type": "application/vnd.amazon.eventstream" } },
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
// Clears every input the AWS default chain reads so tests do not pick up the
|
|
103
|
+
// developer's profiles, SSO cache, or instance metadata.
|
|
104
|
+
const noAmbientAWS = {
|
|
105
|
+
AWS_ACCESS_KEY_ID: undefined,
|
|
106
|
+
AWS_SECRET_ACCESS_KEY: undefined,
|
|
107
|
+
AWS_SESSION_TOKEN: undefined,
|
|
108
|
+
AWS_BEARER_TOKEN_BEDROCK: undefined,
|
|
109
|
+
AWS_PROFILE: undefined,
|
|
110
|
+
AWS_REGION: undefined,
|
|
111
|
+
AWS_DEFAULT_REGION: undefined,
|
|
112
|
+
AWS_WEB_IDENTITY_TOKEN_FILE: undefined,
|
|
113
|
+
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI: undefined,
|
|
114
|
+
AWS_CONTAINER_CREDENTIALS_FULL_URI: undefined,
|
|
115
|
+
AWS_EC2_METADATA_DISABLED: "true",
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const captureHeaders = (target: LanguageModel) =>
|
|
119
|
+
Effect.gen(function* () {
|
|
120
|
+
const seen: Array<Headers> = []
|
|
121
|
+
yield* LLMClient.generate({ ...baseRequest, model: target }).pipe(
|
|
122
|
+
Effect.provide(
|
|
123
|
+
dynamicResponse((input) =>
|
|
124
|
+
Effect.gen(function* () {
|
|
125
|
+
const request = yield* HttpClientRequest.toWeb(input.request)
|
|
126
|
+
seen.push(request.headers)
|
|
127
|
+
return input.respond(eventStreamBody(["messageStop", { stopReason: "end_turn" }]), {
|
|
128
|
+
headers: { "content-type": "application/vnd.amazon.eventstream" },
|
|
129
|
+
})
|
|
130
|
+
}),
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
return seen[0]!
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const model = AmazonBedrock.configure({
|
|
138
|
+
baseURL: "https://bedrock-runtime.test",
|
|
139
|
+
apiKey: "test-bearer",
|
|
140
|
+
}).model("anthropic.claude-sonnet-4-5-20250929-v1:0")
|
|
141
|
+
|
|
142
|
+
const baseRequest = ai.request({
|
|
143
|
+
id: "req_1",
|
|
144
|
+
model,
|
|
145
|
+
system: "You are concise.",
|
|
146
|
+
prompt: "Say hello.",
|
|
147
|
+
// Wire-shape assertions in this file predate the `cache: "auto"` default;
|
|
148
|
+
// pin the policy off so they only exercise the lowering path itself.
|
|
149
|
+
cache: "none",
|
|
150
|
+
maxTokens: 64,
|
|
151
|
+
temperature: 0,
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
describe("Bedrock Converse route", () => {
|
|
155
|
+
it.effect("prepares Converse target with system, inference config, and messages", () =>
|
|
156
|
+
Effect.gen(function* () {
|
|
157
|
+
const prepared = yield* compileRequest(baseRequest)
|
|
158
|
+
|
|
159
|
+
expect(prepared.body).toEqual({
|
|
160
|
+
modelId: "anthropic.claude-sonnet-4-5-20250929-v1:0",
|
|
161
|
+
system: [{ text: "You are concise." }],
|
|
162
|
+
messages: [{ role: "user", content: [{ text: "Say hello." }] }],
|
|
163
|
+
inferenceConfig: { maxTokens: 64, temperature: 0 },
|
|
164
|
+
})
|
|
165
|
+
}),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
it.effect("omits empty initial system blocks", () =>
|
|
169
|
+
Effect.gen(function* () {
|
|
170
|
+
const empty = yield* compileRequest(ai.request({ model, system: "", prompt: "hello" }))
|
|
171
|
+
const cachedEmpty = yield* compileRequest(
|
|
172
|
+
ai.request({
|
|
173
|
+
model,
|
|
174
|
+
system: [{ type: "text", text: "", cache: new CacheHint({ type: "ephemeral" }) }],
|
|
175
|
+
prompt: "hello",
|
|
176
|
+
cache: "none",
|
|
177
|
+
}),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
expect(empty.body.system).toBeUndefined()
|
|
181
|
+
expect(cachedEmpty.body.system).toBeUndefined()
|
|
182
|
+
}),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
it.effect("omits empty system blocks while preserving order and cache hints", () =>
|
|
186
|
+
Effect.gen(function* () {
|
|
187
|
+
const cache = new CacheHint({ type: "ephemeral" })
|
|
188
|
+
const prepared = yield* compileRequest(
|
|
189
|
+
ai.request({
|
|
190
|
+
model,
|
|
191
|
+
system: [
|
|
192
|
+
{ type: "text", text: "", cache },
|
|
193
|
+
{ type: "text", text: "First." },
|
|
194
|
+
{ type: "text", text: " " },
|
|
195
|
+
{ type: "text", text: "" },
|
|
196
|
+
{ type: "text", text: "Second.", cache },
|
|
197
|
+
],
|
|
198
|
+
prompt: "hello",
|
|
199
|
+
cache: "none",
|
|
200
|
+
}),
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
expect(prepared.body.system).toEqual([
|
|
204
|
+
{ text: "First." },
|
|
205
|
+
{ text: " " },
|
|
206
|
+
{ text: "Second." },
|
|
207
|
+
{ cachePoint: { type: "default" } },
|
|
208
|
+
])
|
|
209
|
+
}),
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
it.effect("passes topK through additionalModelRequestFields as top_k", () =>
|
|
213
|
+
Effect.gen(function* () {
|
|
214
|
+
const prepared = yield* compileRequest({
|
|
215
|
+
...baseRequest,
|
|
216
|
+
maxTokens: 64,
|
|
217
|
+
temperature: 0,
|
|
218
|
+
topK: 40,
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
// Converse's inferenceConfig has no topK; Anthropic/Nova read it from
|
|
222
|
+
// additionalModelRequestFields as top_k.
|
|
223
|
+
expect(prepared.body.inferenceConfig).toEqual({ maxTokens: 64, temperature: 0 })
|
|
224
|
+
expect(prepared.body.additionalModelRequestFields).toEqual({ top_k: 40 })
|
|
225
|
+
}),
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
it.effect("omits maxTokens only for Nova 2 at high reasoning effort", () =>
|
|
229
|
+
Effect.gen(function* () {
|
|
230
|
+
const inferenceConfig = (modelID: string, maxReasoningEffort: string) =>
|
|
231
|
+
compileRequest({
|
|
232
|
+
...baseRequest,
|
|
233
|
+
model: AmazonBedrock.model(modelID, {
|
|
234
|
+
baseURL: "https://bedrock-runtime.test",
|
|
235
|
+
apiKey: "test-bearer",
|
|
236
|
+
body: { additionalModelRequestFields: { reasoningConfig: { type: "enabled", maxReasoningEffort } } },
|
|
237
|
+
}),
|
|
238
|
+
}).pipe(Effect.map((prepared) => prepared.body.inferenceConfig))
|
|
239
|
+
|
|
240
|
+
expect(yield* inferenceConfig("us.amazon.nova-2-lite-v1:0", "high")).toEqual({ temperature: 0 })
|
|
241
|
+
expect(yield* inferenceConfig("us.amazon.nova-2-lite-v1:0", "low")).toEqual({ maxTokens: 64, temperature: 0 })
|
|
242
|
+
expect(yield* inferenceConfig("us.xai.grok-4.6", "high")).toEqual({ maxTokens: 64, temperature: 0 })
|
|
243
|
+
}),
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
it.effect("fits a Claude thinking budget below maxTokens", () =>
|
|
247
|
+
Effect.gen(function* () {
|
|
248
|
+
const fields = (maxTokens: number, budgetTokens: number, topK?: number) =>
|
|
249
|
+
compileRequest({
|
|
250
|
+
...baseRequest,
|
|
251
|
+
model: AmazonBedrock.model("us.anthropic.claude-haiku-4-5-20251001-v1:0", {
|
|
252
|
+
baseURL: "https://bedrock-runtime.test",
|
|
253
|
+
apiKey: "test-bearer",
|
|
254
|
+
thinking: { type: "enabled", budgetTokens },
|
|
255
|
+
}),
|
|
256
|
+
maxTokens,
|
|
257
|
+
topK,
|
|
258
|
+
}).pipe(Effect.map((prepared) => prepared.body.additionalModelRequestFields))
|
|
259
|
+
|
|
260
|
+
expect(yield* fields(64_000, 31_999)).toEqual({ thinking: { type: "enabled", budget_tokens: 31_999 } })
|
|
261
|
+
expect(yield* fields(20_000, 31_999, 40)).toEqual({
|
|
262
|
+
top_k: 40,
|
|
263
|
+
thinking: { type: "enabled", budget_tokens: 10_000 },
|
|
264
|
+
})
|
|
265
|
+
expect(yield* fields(1_500, 31_999)).toEqual({ thinking: { type: "enabled", budget_tokens: 1_024 } })
|
|
266
|
+
}),
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
it.effect("omits additionalModelRequestFields when topK is unset", () =>
|
|
270
|
+
Effect.gen(function* () {
|
|
271
|
+
const prepared = yield* compileRequest(baseRequest)
|
|
272
|
+
expect(prepared.body.additionalModelRequestFields).toBeUndefined()
|
|
273
|
+
}),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
it.effect("lowers chronological system updates to wrapped user text in order", () =>
|
|
277
|
+
Effect.gen(function* () {
|
|
278
|
+
const prepared = yield* compileRequest(
|
|
279
|
+
ai.request({
|
|
280
|
+
model,
|
|
281
|
+
messages: [Message.user("Before."), Message.system("Update."), Message.assistant("After.")],
|
|
282
|
+
cache: "none",
|
|
283
|
+
}),
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
expect(prepared.body.messages).toEqual([
|
|
287
|
+
{ role: "user", content: [{ text: "Before." }, { text: "<system-update>\nUpdate.\n</system-update>" }] },
|
|
288
|
+
{ role: "assistant", content: [{ text: "After." }] },
|
|
289
|
+
])
|
|
290
|
+
}),
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
it.effect("prepares tool config with toolSpec and toolChoice", () =>
|
|
294
|
+
Effect.gen(function* () {
|
|
295
|
+
const prepared = yield* compileRequest({
|
|
296
|
+
...baseRequest,
|
|
297
|
+
tools: [
|
|
298
|
+
ToolDefinition.make({
|
|
299
|
+
name: "lookup",
|
|
300
|
+
description: "Lookup data",
|
|
301
|
+
inputSchema: { type: "object", properties: { query: { type: "string" } }, required: ["query"] },
|
|
302
|
+
}),
|
|
303
|
+
],
|
|
304
|
+
toolChoice: ToolChoice.make({ type: "required" }),
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
expect(prepared.body).toMatchObject({
|
|
308
|
+
toolConfig: {
|
|
309
|
+
tools: [
|
|
310
|
+
{
|
|
311
|
+
toolSpec: {
|
|
312
|
+
name: "lookup",
|
|
313
|
+
description: "Lookup data",
|
|
314
|
+
inputSchema: {
|
|
315
|
+
json: { type: "object", properties: { query: { type: "string" } }, required: ["query"] },
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
toolChoice: { any: {} },
|
|
321
|
+
},
|
|
322
|
+
})
|
|
323
|
+
}),
|
|
324
|
+
)
|
|
325
|
+
;["", " \t\r\n"].forEach((description) => {
|
|
326
|
+
it.effect(`omits blank tool description ${JSON.stringify(description)}`, () =>
|
|
327
|
+
Effect.gen(function* () {
|
|
328
|
+
const prepared = yield* compileRequest({
|
|
329
|
+
...baseRequest,
|
|
330
|
+
tools: [
|
|
331
|
+
ToolDefinition.make({
|
|
332
|
+
name: "lookup",
|
|
333
|
+
description,
|
|
334
|
+
inputSchema: { type: "object", properties: { query: { type: "string" } } },
|
|
335
|
+
}),
|
|
336
|
+
],
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
expect(prepared.body.toolConfig.tools).toEqual([
|
|
340
|
+
{
|
|
341
|
+
toolSpec: {
|
|
342
|
+
name: "lookup",
|
|
343
|
+
inputSchema: { json: { type: "object", properties: { query: { type: "string" } } } },
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
])
|
|
347
|
+
expect(prepared.body.toolConfig.tools[0].toolSpec).not.toHaveProperty("description")
|
|
348
|
+
}),
|
|
349
|
+
)
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it.effect("preserves meaningful tool descriptions including surrounding whitespace", () =>
|
|
353
|
+
Effect.gen(function* () {
|
|
354
|
+
const description = " \tLookup data.\n"
|
|
355
|
+
const prepared = yield* compileRequest({
|
|
356
|
+
...baseRequest,
|
|
357
|
+
tools: [
|
|
358
|
+
ToolDefinition.make({
|
|
359
|
+
name: "lookup",
|
|
360
|
+
description,
|
|
361
|
+
inputSchema: { type: "object" },
|
|
362
|
+
}),
|
|
363
|
+
],
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
expect(prepared.body.toolConfig.tools[0].toolSpec.description).toBe(description)
|
|
367
|
+
}),
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
it.effect("keeps tools and omits the unsupported choice when tool choice is none", () =>
|
|
371
|
+
Effect.gen(function* () {
|
|
372
|
+
const prepared = yield* compileRequest({
|
|
373
|
+
...baseRequest,
|
|
374
|
+
tools: [
|
|
375
|
+
ToolDefinition.make({
|
|
376
|
+
name: "lookup",
|
|
377
|
+
description: "Lookup data",
|
|
378
|
+
inputSchema: { type: "object", properties: { query: { type: "string" } } },
|
|
379
|
+
}),
|
|
380
|
+
],
|
|
381
|
+
toolChoice: ToolChoice.make({ type: "none" }),
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
expect(prepared.body.toolConfig).toMatchObject({
|
|
385
|
+
tools: [
|
|
386
|
+
{
|
|
387
|
+
toolSpec: {
|
|
388
|
+
name: "lookup",
|
|
389
|
+
description: "Lookup data",
|
|
390
|
+
inputSchema: { json: { type: "object", properties: { query: { type: "string" } } } },
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
})
|
|
395
|
+
expect(prepared.body.toolConfig?.toolChoice).toBeUndefined()
|
|
396
|
+
}),
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
it.effect("lowers assistant tool-call + tool-result message history", () =>
|
|
400
|
+
Effect.gen(function* () {
|
|
401
|
+
const prepared = yield* compileRequest(
|
|
402
|
+
ai.request({
|
|
403
|
+
id: "req_history",
|
|
404
|
+
model,
|
|
405
|
+
messages: [
|
|
406
|
+
Message.user("What is the weather?"),
|
|
407
|
+
Message.assistant([ToolCallPart.make({ id: "tool_1", name: "lookup", input: { query: "weather" } })]),
|
|
408
|
+
Message.tool({ id: "tool_1", name: "lookup", result: { forecast: "sunny" } }),
|
|
409
|
+
],
|
|
410
|
+
cache: "none",
|
|
411
|
+
}),
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
expect(prepared.body).toMatchObject({
|
|
415
|
+
messages: [
|
|
416
|
+
{ role: "user", content: [{ text: "What is the weather?" }] },
|
|
417
|
+
{
|
|
418
|
+
role: "assistant",
|
|
419
|
+
content: [{ toolUse: { toolUseId: "tool_1", name: "lookup", input: { query: "weather" } } }],
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
role: "user",
|
|
423
|
+
content: [
|
|
424
|
+
{
|
|
425
|
+
toolResult: {
|
|
426
|
+
toolUseId: "tool_1",
|
|
427
|
+
content: [{ json: { forecast: "sunny" } }],
|
|
428
|
+
status: "success",
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
})
|
|
435
|
+
}),
|
|
436
|
+
)
|
|
437
|
+
;[
|
|
438
|
+
{ name: "browser.tabs.open", expected: "browser_tabs_open" },
|
|
439
|
+
{ name: "$lookup", expected: "_lookup" },
|
|
440
|
+
{ name: "", expected: "_" },
|
|
441
|
+
{ name: " ", expected: "___" },
|
|
442
|
+
{ name: "a".repeat(65), expected: "a".repeat(64) },
|
|
443
|
+
{ name: "lookup_123-ABC", expected: "lookup_123-ABC" },
|
|
444
|
+
{ name: "a".repeat(64), expected: "a".repeat(64) },
|
|
445
|
+
].forEach((item) => {
|
|
446
|
+
it.effect(`replays historical tool name ${JSON.stringify(item.name)} within Bedrock constraints`, () =>
|
|
447
|
+
Effect.gen(function* () {
|
|
448
|
+
const call = ToolCallPart.make({ id: "call_unknown", name: item.name, input: { query: "weather" } })
|
|
449
|
+
const error = `No tool named "${item.name}" is currently available. Please use a tool from the available tool list.`
|
|
450
|
+
const request = ai.request({
|
|
451
|
+
model,
|
|
452
|
+
cache: "none",
|
|
453
|
+
tools: [ToolDefinition.make({ name: "execute", description: "Run code", inputSchema: { type: "object" } })],
|
|
454
|
+
messages: [
|
|
455
|
+
Message.user("Check the weather"),
|
|
456
|
+
Message.assistant([call]),
|
|
457
|
+
Message.tool({ id: call.id, name: call.name, result: error, resultType: "error" }),
|
|
458
|
+
Message.user("Say OK"),
|
|
459
|
+
],
|
|
460
|
+
})
|
|
461
|
+
const prepared = yield* compileRequest(request)
|
|
462
|
+
|
|
463
|
+
expect(prepared.body.messages[1].content).toEqual([
|
|
464
|
+
{ toolUse: { toolUseId: call.id, name: item.expected, input: call.input } },
|
|
465
|
+
])
|
|
466
|
+
expect(prepared.body.messages[2].content).toEqual([
|
|
467
|
+
{ toolResult: { toolUseId: call.id, content: [{ text: error }], status: "error" } },
|
|
468
|
+
{ text: "Say OK" },
|
|
469
|
+
])
|
|
470
|
+
expect(prepared.body.toolConfig.tools.map((tool) => tool.toolSpec.name)).toEqual(["execute"])
|
|
471
|
+
expect(request.messages[1].content[0]).toEqual(call)
|
|
472
|
+
expect(call.name).toBe(item.name)
|
|
473
|
+
}),
|
|
474
|
+
)
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
it.effect("removes empty keys recursively from outbound tool inputs without mutating history", () =>
|
|
478
|
+
Effect.gen(function* () {
|
|
479
|
+
const input = {
|
|
480
|
+
path: "file.ts",
|
|
481
|
+
edits: [
|
|
482
|
+
{ oldText: "a", newText: "b", "": "" },
|
|
483
|
+
null,
|
|
484
|
+
true,
|
|
485
|
+
7,
|
|
486
|
+
"text",
|
|
487
|
+
["kept", { "": false, nested: { "": null, value: "ok" } }],
|
|
488
|
+
],
|
|
489
|
+
nested: { "": "drop", empty: {}, onlyEmpty: { "": 1 } },
|
|
490
|
+
" ": "preserve whitespace key",
|
|
491
|
+
"": "drop",
|
|
492
|
+
}
|
|
493
|
+
const original = structuredClone(input)
|
|
494
|
+
const call = ToolCallPart.make({ id: "tool_1", name: "edit", input })
|
|
495
|
+
const prepared = yield* compileRequest(
|
|
496
|
+
ai.request({ model, messages: [Message.assistant([call])], cache: "none" }),
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
expect(prepared.body.messages[0]).toEqual({
|
|
500
|
+
role: "assistant",
|
|
501
|
+
content: [
|
|
502
|
+
{
|
|
503
|
+
toolUse: {
|
|
504
|
+
toolUseId: "tool_1",
|
|
505
|
+
name: "edit",
|
|
506
|
+
input: {
|
|
507
|
+
path: "file.ts",
|
|
508
|
+
edits: [{ oldText: "a", newText: "b" }, null, true, 7, "text", ["kept", { nested: { value: "ok" } }]],
|
|
509
|
+
nested: { empty: {}, onlyEmpty: {} },
|
|
510
|
+
" ": "preserve whitespace key",
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
],
|
|
515
|
+
})
|
|
516
|
+
expect(input).toEqual(original)
|
|
517
|
+
expect(call.input).toBe(input)
|
|
518
|
+
}),
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
it.effect("keeps empty tool inputs and empties inputs containing only empty keys", () =>
|
|
522
|
+
Effect.gen(function* () {
|
|
523
|
+
const prepared = yield* compileRequest(
|
|
524
|
+
ai.request({
|
|
525
|
+
model,
|
|
526
|
+
messages: [
|
|
527
|
+
Message.assistant([
|
|
528
|
+
ToolCallPart.make({ id: "tool_empty_key", name: "first", input: { "": { value: true } } }),
|
|
529
|
+
ToolCallPart.make({ id: "tool_empty_object", name: "second", input: {} }),
|
|
530
|
+
]),
|
|
531
|
+
],
|
|
532
|
+
cache: "none",
|
|
533
|
+
}),
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
expect(prepared.body.messages[0]).toEqual({
|
|
537
|
+
role: "assistant",
|
|
538
|
+
content: [
|
|
539
|
+
{ toolUse: { toolUseId: "tool_empty_key", name: "first", input: {} } },
|
|
540
|
+
{ toolUse: { toolUseId: "tool_empty_object", name: "second", input: {} } },
|
|
541
|
+
],
|
|
542
|
+
})
|
|
543
|
+
}),
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
it.effect("merges parallel tool results into one user message", () =>
|
|
547
|
+
Effect.gen(function* () {
|
|
548
|
+
const prepared = yield* compileRequest(
|
|
549
|
+
ai.request({
|
|
550
|
+
id: "req_parallel_history",
|
|
551
|
+
model,
|
|
552
|
+
messages: [
|
|
553
|
+
Message.user("Compare the weather."),
|
|
554
|
+
Message.assistant([
|
|
555
|
+
ToolCallPart.make({ id: "tool_paris", name: "lookup", input: { city: "Paris" } }),
|
|
556
|
+
ToolCallPart.make({ id: "tool_london", name: "lookup", input: { city: "London" } }),
|
|
557
|
+
]),
|
|
558
|
+
Message.tool({ id: "tool_paris", name: "lookup", result: { forecast: "sunny" } }),
|
|
559
|
+
Message.tool({ id: "tool_london", name: "lookup", result: { forecast: "rainy" } }),
|
|
560
|
+
],
|
|
561
|
+
cache: "none",
|
|
562
|
+
}),
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
expect(prepared.body.messages).toEqual([
|
|
566
|
+
{ role: "user", content: [{ text: "Compare the weather." }] },
|
|
567
|
+
{
|
|
568
|
+
role: "assistant",
|
|
569
|
+
content: [
|
|
570
|
+
{ toolUse: { toolUseId: "tool_paris", name: "lookup", input: { city: "Paris" } } },
|
|
571
|
+
{ toolUse: { toolUseId: "tool_london", name: "lookup", input: { city: "London" } } },
|
|
572
|
+
],
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
role: "user",
|
|
576
|
+
content: [
|
|
577
|
+
{
|
|
578
|
+
toolResult: {
|
|
579
|
+
toolUseId: "tool_paris",
|
|
580
|
+
content: [{ json: { forecast: "sunny" } }],
|
|
581
|
+
status: "success",
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
toolResult: {
|
|
586
|
+
toolUseId: "tool_london",
|
|
587
|
+
content: [{ json: { forecast: "rainy" } }],
|
|
588
|
+
status: "success",
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
],
|
|
592
|
+
},
|
|
593
|
+
])
|
|
594
|
+
}),
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
it.effect("lowers image content in tool-result messages", () =>
|
|
598
|
+
Effect.gen(function* () {
|
|
599
|
+
const prepared = yield* compileRequest(
|
|
600
|
+
ai.request({
|
|
601
|
+
id: "req_tool_image",
|
|
602
|
+
model,
|
|
603
|
+
messages: [
|
|
604
|
+
Message.user("Capture the screen."),
|
|
605
|
+
Message.assistant([ToolCallPart.make({ id: "tool_1", name: "screenshot", input: {} })]),
|
|
606
|
+
Message.tool({
|
|
607
|
+
id: "tool_1",
|
|
608
|
+
name: "screenshot",
|
|
609
|
+
result: {
|
|
610
|
+
type: "content",
|
|
611
|
+
value: [
|
|
612
|
+
{ type: "text", text: "Screenshot captured." },
|
|
613
|
+
{ type: "file", uri: "data:image/png;base64,AAAA", mime: "image/png" },
|
|
614
|
+
],
|
|
615
|
+
},
|
|
616
|
+
}),
|
|
617
|
+
],
|
|
618
|
+
cache: "none",
|
|
619
|
+
}),
|
|
620
|
+
)
|
|
621
|
+
|
|
622
|
+
expect(prepared.body).toMatchObject({
|
|
623
|
+
messages: [
|
|
624
|
+
{ role: "user", content: [{ text: "Capture the screen." }] },
|
|
625
|
+
{
|
|
626
|
+
role: "assistant",
|
|
627
|
+
content: [{ toolUse: { toolUseId: "tool_1", name: "screenshot", input: {} } }],
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
role: "user",
|
|
631
|
+
content: [
|
|
632
|
+
{
|
|
633
|
+
toolResult: {
|
|
634
|
+
toolUseId: "tool_1",
|
|
635
|
+
content: [{ text: "Screenshot captured." }, { image: { format: "png", source: { bytes: "AAAA" } } }],
|
|
636
|
+
status: "success",
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
},
|
|
641
|
+
],
|
|
642
|
+
})
|
|
643
|
+
}),
|
|
644
|
+
)
|
|
645
|
+
|
|
646
|
+
it.effect("hoists tool-result images beside the result for Bedrock GPT models", () =>
|
|
647
|
+
Effect.gen(function* () {
|
|
648
|
+
const prepared = yield* compileRequest(
|
|
649
|
+
ai.request({
|
|
650
|
+
model: AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test", apiKey: "test-bearer" }).model(
|
|
651
|
+
"global.openai.gpt-6-sol",
|
|
652
|
+
),
|
|
653
|
+
messages: [
|
|
654
|
+
Message.user("What is in this image?"),
|
|
655
|
+
Message.assistant([ToolCallPart.make({ id: "tool_1", name: "read", input: {} })]),
|
|
656
|
+
Message.tool({
|
|
657
|
+
id: "tool_1",
|
|
658
|
+
name: "read",
|
|
659
|
+
result: {
|
|
660
|
+
type: "content",
|
|
661
|
+
value: [
|
|
662
|
+
{ type: "text", text: "Image loaded." },
|
|
663
|
+
{ type: "file", uri: "data:image/png;base64,AAAA", mime: "image/png" },
|
|
664
|
+
{ type: "file", uri: "data:application/pdf;base64,QkI=", mime: "application/pdf", name: "note.pdf" },
|
|
665
|
+
],
|
|
666
|
+
},
|
|
667
|
+
}),
|
|
668
|
+
],
|
|
669
|
+
cache: "none",
|
|
670
|
+
}),
|
|
671
|
+
)
|
|
672
|
+
|
|
673
|
+
expect(prepared.body.messages[2]).toEqual({
|
|
674
|
+
role: "user",
|
|
675
|
+
content: [
|
|
676
|
+
{
|
|
677
|
+
toolResult: {
|
|
678
|
+
toolUseId: "tool_1",
|
|
679
|
+
content: [
|
|
680
|
+
{ text: "Image loaded." },
|
|
681
|
+
{ text: 'Attached file "note.pdf" has document label "note".' },
|
|
682
|
+
{ document: { format: "pdf", name: "note", source: { bytes: "QkI=" } } },
|
|
683
|
+
],
|
|
684
|
+
status: "success",
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
{ image: { format: "png", source: { bytes: "AAAA" } } },
|
|
688
|
+
],
|
|
689
|
+
})
|
|
690
|
+
}),
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
it.effect("hoists tool-result images for other Bedrock model families", () =>
|
|
694
|
+
Effect.gen(function* () {
|
|
695
|
+
for (const id of [
|
|
696
|
+
"qwen.qwen3-vl-235b-a22b",
|
|
697
|
+
"global.xai.grok-4.7",
|
|
698
|
+
"global.moonshotai.kimi-k3",
|
|
699
|
+
"us.meta.llama4-scout-17b-instruct-v1:0",
|
|
700
|
+
]) {
|
|
701
|
+
const prepared = yield* compileRequest(
|
|
702
|
+
ai.request({
|
|
703
|
+
model: AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test", apiKey: "test-bearer" }).model(
|
|
704
|
+
id,
|
|
705
|
+
),
|
|
706
|
+
messages: [
|
|
707
|
+
Message.assistant([ToolCallPart.make({ id: "tool_1", name: "read", input: {} })]),
|
|
708
|
+
Message.tool({
|
|
709
|
+
id: "tool_1",
|
|
710
|
+
name: "read",
|
|
711
|
+
result: {
|
|
712
|
+
type: "content",
|
|
713
|
+
value: [{ type: "file", uri: "data:image/png;base64,AAAA", mime: "image/png" }],
|
|
714
|
+
},
|
|
715
|
+
}),
|
|
716
|
+
],
|
|
717
|
+
cache: "none",
|
|
718
|
+
}),
|
|
719
|
+
)
|
|
720
|
+
expect(prepared.body.messages[1]).toEqual({
|
|
721
|
+
role: "user",
|
|
722
|
+
content: [
|
|
723
|
+
{ toolResult: { toolUseId: "tool_1", content: [{ text: "See attached image." }], status: "success" } },
|
|
724
|
+
{ image: { format: "png", source: { bytes: "AAAA" } } },
|
|
725
|
+
],
|
|
726
|
+
})
|
|
727
|
+
}
|
|
728
|
+
}),
|
|
729
|
+
)
|
|
730
|
+
;["global.anthropic.claude-sonnet-4-5-20250929-v1:0", "us.amazon.nova-pro-v1:0"].forEach((id) => {
|
|
731
|
+
it.effect(`keeps ${id} tool images inside the result`, () =>
|
|
732
|
+
Effect.gen(function* () {
|
|
733
|
+
const prepared = yield* compileRequest(
|
|
734
|
+
ai.request({
|
|
735
|
+
model: AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test", apiKey: "test-bearer" }).model(
|
|
736
|
+
id,
|
|
737
|
+
),
|
|
738
|
+
messages: [
|
|
739
|
+
Message.assistant([ToolCallPart.make({ id: "tool_1", name: "read", input: {} })]),
|
|
740
|
+
Message.tool({
|
|
741
|
+
id: "tool_1",
|
|
742
|
+
name: "read",
|
|
743
|
+
result: {
|
|
744
|
+
type: "content",
|
|
745
|
+
value: [{ type: "file", uri: "data:image/png;base64,AAAA", mime: "image/png" }],
|
|
746
|
+
},
|
|
747
|
+
}),
|
|
748
|
+
],
|
|
749
|
+
cache: "none",
|
|
750
|
+
}),
|
|
751
|
+
)
|
|
752
|
+
|
|
753
|
+
expect(prepared.body.messages[1]).toEqual({
|
|
754
|
+
role: "user",
|
|
755
|
+
content: [
|
|
756
|
+
{
|
|
757
|
+
toolResult: {
|
|
758
|
+
toolUseId: "tool_1",
|
|
759
|
+
content: [{ image: { format: "png", source: { bytes: "AAAA" } } }],
|
|
760
|
+
status: "success",
|
|
761
|
+
},
|
|
762
|
+
},
|
|
763
|
+
],
|
|
764
|
+
})
|
|
765
|
+
}),
|
|
766
|
+
)
|
|
767
|
+
})
|
|
768
|
+
|
|
769
|
+
it.effect("keeps parallel tool results before hoisted images and gives image-only results text", () =>
|
|
770
|
+
Effect.gen(function* () {
|
|
771
|
+
const prepared = yield* compileRequest(
|
|
772
|
+
ai.request({
|
|
773
|
+
model: AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test", apiKey: "test-bearer" }).model(
|
|
774
|
+
"global.openai.gpt-6-sol",
|
|
775
|
+
),
|
|
776
|
+
messages: [
|
|
777
|
+
Message.assistant([
|
|
778
|
+
ToolCallPart.make({ id: "tool_1", name: "first", input: {} }),
|
|
779
|
+
ToolCallPart.make({ id: "tool_2", name: "second", input: {} }),
|
|
780
|
+
]),
|
|
781
|
+
Message.tool({
|
|
782
|
+
id: "tool_1",
|
|
783
|
+
name: "first",
|
|
784
|
+
result: {
|
|
785
|
+
type: "content",
|
|
786
|
+
value: [{ type: "file", uri: "data:image/png;base64,AAAA", mime: "image/png" }],
|
|
787
|
+
},
|
|
788
|
+
}),
|
|
789
|
+
Message.tool({
|
|
790
|
+
id: "tool_2",
|
|
791
|
+
name: "second",
|
|
792
|
+
result: {
|
|
793
|
+
type: "content",
|
|
794
|
+
value: [
|
|
795
|
+
{ type: "text", text: "Second image." },
|
|
796
|
+
{ type: "file", uri: "data:image/jpeg;base64,BBBB", mime: "image/jpeg" },
|
|
797
|
+
],
|
|
798
|
+
},
|
|
799
|
+
}),
|
|
800
|
+
],
|
|
801
|
+
cache: "none",
|
|
802
|
+
}),
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
expect(prepared.body.messages[1]).toEqual({
|
|
806
|
+
role: "user",
|
|
807
|
+
content: [
|
|
808
|
+
{ toolResult: { toolUseId: "tool_1", content: [{ text: "See attached image." }], status: "success" } },
|
|
809
|
+
{ toolResult: { toolUseId: "tool_2", content: [{ text: "Second image." }], status: "success" } },
|
|
810
|
+
{ image: { format: "png", source: { bytes: "AAAA" } } },
|
|
811
|
+
{ image: { format: "jpeg", source: { bytes: "BBBB" } } },
|
|
812
|
+
],
|
|
813
|
+
})
|
|
814
|
+
}),
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
it.effect("decodes text-delta + messageStop + metadata usage from binary event stream", () =>
|
|
818
|
+
Effect.gen(function* () {
|
|
819
|
+
const body = eventStreamBody(
|
|
820
|
+
["messageStart", { role: "assistant" }],
|
|
821
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { text: "Hello" } }],
|
|
822
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { text: "!" } }],
|
|
823
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
824
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
825
|
+
["metadata", { usage: { inputTokens: 5, outputTokens: 2, totalTokens: 7 } }],
|
|
826
|
+
)
|
|
827
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
828
|
+
|
|
829
|
+
expect(response.text).toBe("Hello!")
|
|
830
|
+
const finishes = response.events.filter((event) => event.type === "finish")
|
|
831
|
+
// Bedrock splits the finish across `messageStop` (carries reason) and
|
|
832
|
+
// `metadata` (carries usage). We consolidate them into a single
|
|
833
|
+
// terminal `finish` event with both.
|
|
834
|
+
expect(finishes).toHaveLength(1)
|
|
835
|
+
expect(finishes[0]).toMatchObject({
|
|
836
|
+
type: "finish",
|
|
837
|
+
reason: { normalized: "stop", raw: "end_turn" },
|
|
838
|
+
})
|
|
839
|
+
expect(response.usage).toMatchObject({
|
|
840
|
+
inputTokens: 5,
|
|
841
|
+
outputTokens: 2,
|
|
842
|
+
totalTokens: 7,
|
|
843
|
+
})
|
|
844
|
+
}),
|
|
845
|
+
)
|
|
846
|
+
|
|
847
|
+
it.effect("raw events carry the event payload without decoder fields or padding", () =>
|
|
848
|
+
Effect.gen(function* () {
|
|
849
|
+
const body = eventStreamBody(
|
|
850
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { text: "Hi" }, p: "abc" }],
|
|
851
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
852
|
+
["metadata", { usage: { inputTokens: 5, outputTokens: 1, totalTokens: 6 } }],
|
|
853
|
+
)
|
|
854
|
+
const events = Array.from(
|
|
855
|
+
yield* LLMClient.stream({ ...baseRequest, includeRaw: true }).pipe(
|
|
856
|
+
Stream.runCollect,
|
|
857
|
+
Effect.provide(fixedBytes(body)),
|
|
858
|
+
),
|
|
859
|
+
)
|
|
860
|
+
|
|
861
|
+
expect(events.filter((event) => event.type === "raw").map((event) => event.data)).toEqual([
|
|
862
|
+
{ contentBlockDelta: { contentBlockIndex: 0, delta: { text: "Hi" } } },
|
|
863
|
+
{ messageStop: { stopReason: "end_turn" } },
|
|
864
|
+
{ metadata: { usage: { inputTokens: 5, outputTokens: 1, totalTokens: 6 } } },
|
|
865
|
+
])
|
|
866
|
+
}),
|
|
867
|
+
)
|
|
868
|
+
|
|
869
|
+
it.effect("rejects truncated event-stream frames after message stop", () =>
|
|
870
|
+
Effect.gen(function* () {
|
|
871
|
+
const partialFrames = [
|
|
872
|
+
eventFrame("metadata", { usage: { inputTokens: 5, outputTokens: 2, totalTokens: 7 } }).subarray(0, 3),
|
|
873
|
+
exceptionFrame("modelStreamErrorException", { originalMessage: "Upstream model failed" }).subarray(0, -1),
|
|
874
|
+
]
|
|
875
|
+
|
|
876
|
+
for (const partial of partialFrames) {
|
|
877
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(
|
|
878
|
+
Effect.provide(fixedBytes(concat([eventFrame("messageStop", { stopReason: "end_turn" }), partial]))),
|
|
879
|
+
Effect.flip,
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
expect(error).toMatchObject({
|
|
883
|
+
reason: { _tag: "InvalidProviderOutput", classification: "incomplete-stream" },
|
|
884
|
+
message: `Incomplete Bedrock Converse event-stream frame: ${partial.length} buffered bytes remain at end of stream`,
|
|
885
|
+
})
|
|
886
|
+
expect(error.reason.body).toBe(Base64.encode(partial))
|
|
887
|
+
}
|
|
888
|
+
}),
|
|
889
|
+
)
|
|
890
|
+
|
|
891
|
+
it.effect("decodes frames split across transport chunks through exact-boundary EOF", () =>
|
|
892
|
+
Effect.gen(function* () {
|
|
893
|
+
const body = eventStreamBody(
|
|
894
|
+
["messageStart", { role: "assistant" }],
|
|
895
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { text: "Hello" } }],
|
|
896
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
897
|
+
)
|
|
898
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(
|
|
899
|
+
Effect.provide(fixedByteChunks(body.subarray(0, 2), body.subarray(2, 17), body.subarray(17))),
|
|
900
|
+
)
|
|
901
|
+
|
|
902
|
+
expect(response.text).toBe("Hello")
|
|
903
|
+
expect(response.finishReason).toEqual({ normalized: "stop", raw: "end_turn" })
|
|
904
|
+
}),
|
|
905
|
+
)
|
|
906
|
+
|
|
907
|
+
it.effect("maps model context window exhaustion to length", () =>
|
|
908
|
+
Effect.gen(function* () {
|
|
909
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(
|
|
910
|
+
Effect.provide(fixedBytes(eventStreamBody(["messageStop", { stopReason: "model_context_window_exceeded" }]))),
|
|
911
|
+
)
|
|
912
|
+
|
|
913
|
+
expect(response.finishReason).toEqual({
|
|
914
|
+
normalized: "length",
|
|
915
|
+
raw: "model_context_window_exceeded",
|
|
916
|
+
})
|
|
917
|
+
}),
|
|
918
|
+
)
|
|
919
|
+
|
|
920
|
+
it.effect("fails malformed output stop reasons", () =>
|
|
921
|
+
Effect.gen(function* () {
|
|
922
|
+
for (const reason of ["malformed_model_output", "malformed_tool_use"] as const) {
|
|
923
|
+
const events = yield* Ref.make<ReadonlyArray<LLMEvent>>([])
|
|
924
|
+
const error = yield* LLMClient.stream(baseRequest).pipe(
|
|
925
|
+
Stream.tap((event) => Ref.update(events, (current) => [...current, event])),
|
|
926
|
+
Stream.runDrain,
|
|
927
|
+
Effect.provide(fixedBytes(eventStreamBody(["messageStop", { stopReason: reason }]))),
|
|
928
|
+
Effect.flip,
|
|
929
|
+
)
|
|
930
|
+
|
|
931
|
+
expect(error).toMatchObject({
|
|
932
|
+
reason: { _tag: "InvalidProviderOutput" },
|
|
933
|
+
message: `Bedrock Converse stopped with ${reason}`,
|
|
934
|
+
})
|
|
935
|
+
expect(JSON.parse(error.reason.body ?? "")).toMatchObject({
|
|
936
|
+
headers: { ":event-type": { value: "messageStop" } },
|
|
937
|
+
body: JSON.stringify({ stopReason: reason }),
|
|
938
|
+
})
|
|
939
|
+
expect((yield* Ref.get(events)).some((event) => event.type === "finish")).toBeFalse()
|
|
940
|
+
}
|
|
941
|
+
}),
|
|
942
|
+
)
|
|
943
|
+
|
|
944
|
+
it.effect("adds cache reads and writes to Bedrock input usage", () =>
|
|
945
|
+
Effect.gen(function* () {
|
|
946
|
+
const body = eventStreamBody(
|
|
947
|
+
["messageStart", { role: "assistant" }],
|
|
948
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { text: "Hello" } }],
|
|
949
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
950
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
951
|
+
[
|
|
952
|
+
"metadata",
|
|
953
|
+
{
|
|
954
|
+
usage: {
|
|
955
|
+
inputTokens: 5,
|
|
956
|
+
outputTokens: 2,
|
|
957
|
+
totalTokens: 12,
|
|
958
|
+
cacheReadInputTokens: 3,
|
|
959
|
+
cacheWriteInputTokens: 2,
|
|
960
|
+
},
|
|
961
|
+
},
|
|
962
|
+
],
|
|
963
|
+
)
|
|
964
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
965
|
+
|
|
966
|
+
expect(response.usage).toMatchObject({
|
|
967
|
+
inputTokens: 10,
|
|
968
|
+
nonCachedInputTokens: 5,
|
|
969
|
+
cacheReadInputTokens: 3,
|
|
970
|
+
cacheWriteInputTokens: 2,
|
|
971
|
+
outputTokens: 2,
|
|
972
|
+
totalTokens: 12,
|
|
973
|
+
})
|
|
974
|
+
}),
|
|
975
|
+
)
|
|
976
|
+
|
|
977
|
+
it.effect("preserves usage across later metadata events without usage", () =>
|
|
978
|
+
Effect.gen(function* () {
|
|
979
|
+
const body = eventStreamBody(
|
|
980
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
981
|
+
["metadata", { usage: { inputTokens: 5, outputTokens: 2, totalTokens: 7 } }],
|
|
982
|
+
["metadata", { metrics: { latencyMs: 100 } }],
|
|
983
|
+
)
|
|
984
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
985
|
+
|
|
986
|
+
expect(response.events.filter((event) => event.type === "finish")).toHaveLength(1)
|
|
987
|
+
expect(response.usage).toMatchObject({ inputTokens: 5, outputTokens: 2, totalTokens: 7 })
|
|
988
|
+
}),
|
|
989
|
+
)
|
|
990
|
+
|
|
991
|
+
it.effect("retains metadata usage that arrives before messageStop", () =>
|
|
992
|
+
Effect.gen(function* () {
|
|
993
|
+
const body = eventStreamBody(
|
|
994
|
+
["metadata", { usage: { inputTokens: 5, outputTokens: 2, totalTokens: 7 } }],
|
|
995
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
996
|
+
)
|
|
997
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
998
|
+
|
|
999
|
+
expect(response.events.filter((event) => event.type === "finish")).toHaveLength(1)
|
|
1000
|
+
expect(response.finishReason).toEqual({ normalized: "stop", raw: "end_turn" })
|
|
1001
|
+
expect(response.usage).toMatchObject({ inputTokens: 5, outputTokens: 2, totalTokens: 7 })
|
|
1002
|
+
}),
|
|
1003
|
+
)
|
|
1004
|
+
|
|
1005
|
+
it.effect("rejects metadata-only streams as incomplete with HTTP context", () =>
|
|
1006
|
+
Effect.gen(function* () {
|
|
1007
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(
|
|
1008
|
+
Effect.provide(
|
|
1009
|
+
fixedBytes(eventStreamBody(["metadata", { usage: { inputTokens: 5, outputTokens: 2, totalTokens: 7 } }])),
|
|
1010
|
+
),
|
|
1011
|
+
Effect.flip,
|
|
1012
|
+
)
|
|
1013
|
+
|
|
1014
|
+
expect(error.reason).toMatchObject({
|
|
1015
|
+
_tag: "InvalidProviderOutput",
|
|
1016
|
+
classification: "incomplete-stream",
|
|
1017
|
+
http: {
|
|
1018
|
+
status: 200,
|
|
1019
|
+
headers: { "content-type": "application/vnd.amazon.eventstream" },
|
|
1020
|
+
},
|
|
1021
|
+
})
|
|
1022
|
+
}),
|
|
1023
|
+
)
|
|
1024
|
+
|
|
1025
|
+
it.effect("assembles streamed tool call input", () =>
|
|
1026
|
+
Effect.gen(function* () {
|
|
1027
|
+
const body = eventStreamBody(
|
|
1028
|
+
["messageStart", { role: "assistant" }],
|
|
1029
|
+
[
|
|
1030
|
+
"contentBlockStart",
|
|
1031
|
+
{
|
|
1032
|
+
contentBlockIndex: 0,
|
|
1033
|
+
start: { toolUse: { toolUseId: "tool_1", name: "lookup" } },
|
|
1034
|
+
},
|
|
1035
|
+
],
|
|
1036
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: '{"query"' } } }],
|
|
1037
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: ':"weather"}' } } }],
|
|
1038
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1039
|
+
["messageStop", { stopReason: "tool_use" }],
|
|
1040
|
+
)
|
|
1041
|
+
const response = yield* LLMClient.generate({
|
|
1042
|
+
...baseRequest,
|
|
1043
|
+
tools: [ToolDefinition.make({ name: "lookup", description: "Lookup", inputSchema: { type: "object" } })],
|
|
1044
|
+
}).pipe(Effect.provide(fixedBytes(body)))
|
|
1045
|
+
|
|
1046
|
+
expect(response.toolCalls).toEqual([
|
|
1047
|
+
{ type: "tool-call", id: "tool_1", name: "lookup", input: { query: "weather" } },
|
|
1048
|
+
])
|
|
1049
|
+
const events = response.events.filter((event) => event.type === "tool-input-delta")
|
|
1050
|
+
expect(events).toEqual([
|
|
1051
|
+
{ type: "tool-input-delta", id: "tool_1", name: "lookup", text: '{"query"', input: {} },
|
|
1052
|
+
{
|
|
1053
|
+
type: "tool-input-delta",
|
|
1054
|
+
id: "tool_1",
|
|
1055
|
+
name: "lookup",
|
|
1056
|
+
text: ':"weather"}',
|
|
1057
|
+
input: { query: "weather" },
|
|
1058
|
+
},
|
|
1059
|
+
])
|
|
1060
|
+
expect(response.events.at(-1)).toMatchObject({
|
|
1061
|
+
type: "finish",
|
|
1062
|
+
reason: { normalized: "tool-calls", raw: "tool_use" },
|
|
1063
|
+
})
|
|
1064
|
+
}),
|
|
1065
|
+
)
|
|
1066
|
+
|
|
1067
|
+
it.effect("rejects a provider-emitted dotted name before normalizing its replay", () =>
|
|
1068
|
+
Effect.gen(function* () {
|
|
1069
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(
|
|
1070
|
+
Effect.provide(
|
|
1071
|
+
fixedBytes(
|
|
1072
|
+
eventStreamBody(
|
|
1073
|
+
[
|
|
1074
|
+
"contentBlockStart",
|
|
1075
|
+
{ contentBlockIndex: 0, start: { toolUse: { toolUseId: "call_unknown", name: "browser.tabs.open" } } },
|
|
1076
|
+
],
|
|
1077
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: "{}" } } }],
|
|
1078
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1079
|
+
["messageStop", { stopReason: "tool_use" }],
|
|
1080
|
+
),
|
|
1081
|
+
),
|
|
1082
|
+
),
|
|
1083
|
+
)
|
|
1084
|
+
const call = response.toolCalls[0]
|
|
1085
|
+
if (!call) throw new Error("Expected a tool call")
|
|
1086
|
+
expect(call.name).toBe("browser.tabs.open")
|
|
1087
|
+
const dispatched = yield* ToolRuntime.dispatch(
|
|
1088
|
+
[
|
|
1089
|
+
tool({
|
|
1090
|
+
name: "browser_tabs_open",
|
|
1091
|
+
description: "Open a tab",
|
|
1092
|
+
input: Schema.Struct({}),
|
|
1093
|
+
success: Schema.String,
|
|
1094
|
+
execute: () => Effect.die("A normalized replay name must not select an executor"),
|
|
1095
|
+
}),
|
|
1096
|
+
],
|
|
1097
|
+
call,
|
|
1098
|
+
)
|
|
1099
|
+
expect(dispatched.result).toEqual({
|
|
1100
|
+
type: "error",
|
|
1101
|
+
value:
|
|
1102
|
+
'No tool named "browser.tabs.open" is currently available. Please use a tool from the available tool list.',
|
|
1103
|
+
})
|
|
1104
|
+
|
|
1105
|
+
const prepared = yield* compileRequest(
|
|
1106
|
+
ai.request({
|
|
1107
|
+
model,
|
|
1108
|
+
cache: "none",
|
|
1109
|
+
messages: [response.message, Message.tool({ id: call.id, name: call.name, result: dispatched.result })],
|
|
1110
|
+
}),
|
|
1111
|
+
)
|
|
1112
|
+
expect(prepared.body.messages[0].content).toEqual([
|
|
1113
|
+
{ toolUse: { toolUseId: call.id, name: "browser_tabs_open", input: {} } },
|
|
1114
|
+
])
|
|
1115
|
+
expect(response.toolCalls[0]?.name).toBe("browser.tabs.open")
|
|
1116
|
+
}),
|
|
1117
|
+
)
|
|
1118
|
+
|
|
1119
|
+
it.effect("ignores tool deltas without an open tool block", () =>
|
|
1120
|
+
Effect.gen(function* () {
|
|
1121
|
+
const body = eventStreamBody(
|
|
1122
|
+
["contentBlockDelta", { contentBlockIndex: 5, delta: { toolUse: { input: "{}" } } }],
|
|
1123
|
+
[
|
|
1124
|
+
"contentBlockStart",
|
|
1125
|
+
{
|
|
1126
|
+
contentBlockIndex: 0,
|
|
1127
|
+
start: { toolUse: { toolUseId: "tool_1", name: "lookup" } },
|
|
1128
|
+
},
|
|
1129
|
+
],
|
|
1130
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: '{"query":"weather"}' } } }],
|
|
1131
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1132
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: '{"late":true}' } } }],
|
|
1133
|
+
["messageStop", { stopReason: "tool_use" }],
|
|
1134
|
+
)
|
|
1135
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1136
|
+
|
|
1137
|
+
expect(response.toolCalls).toEqual([
|
|
1138
|
+
{ type: "tool-call", id: "tool_1", name: "lookup", input: { query: "weather" } },
|
|
1139
|
+
])
|
|
1140
|
+
expect(response.events.filter((event) => event.type === "tool-input-delta")).toEqual([
|
|
1141
|
+
{
|
|
1142
|
+
type: "tool-input-delta",
|
|
1143
|
+
id: "tool_1",
|
|
1144
|
+
name: "lookup",
|
|
1145
|
+
text: '{"query":"weather"}',
|
|
1146
|
+
input: { query: "weather" },
|
|
1147
|
+
},
|
|
1148
|
+
])
|
|
1149
|
+
}),
|
|
1150
|
+
)
|
|
1151
|
+
|
|
1152
|
+
it.effect("rejects incomplete tool input at finalization", () =>
|
|
1153
|
+
Effect.gen(function* () {
|
|
1154
|
+
const body = eventStreamBody(
|
|
1155
|
+
["messageStart", { role: "assistant" }],
|
|
1156
|
+
[
|
|
1157
|
+
"contentBlockStart",
|
|
1158
|
+
{
|
|
1159
|
+
contentBlockIndex: 0,
|
|
1160
|
+
start: { toolUse: { toolUseId: "tool_1", name: "lookup" } },
|
|
1161
|
+
},
|
|
1162
|
+
],
|
|
1163
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: '{"query":"partial' } } }],
|
|
1164
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1165
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1166
|
+
)
|
|
1167
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1168
|
+
|
|
1169
|
+
expect(response.toolCalls).toEqual([])
|
|
1170
|
+
expect(response.events.find((event) => event.type === "tool-input-error")).toMatchObject({
|
|
1171
|
+
id: "tool_1",
|
|
1172
|
+
name: "lookup",
|
|
1173
|
+
raw: '{"query":"partial',
|
|
1174
|
+
})
|
|
1175
|
+
expect(response.finishReason).toEqual({ normalized: "tool-calls", raw: "end_turn" })
|
|
1176
|
+
}),
|
|
1177
|
+
)
|
|
1178
|
+
|
|
1179
|
+
it.effect("decodes reasoning deltas", () =>
|
|
1180
|
+
Effect.gen(function* () {
|
|
1181
|
+
const body = eventStreamBody(
|
|
1182
|
+
["messageStart", { role: "assistant" }],
|
|
1183
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { text: "Let me think." } } }],
|
|
1184
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1185
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1186
|
+
)
|
|
1187
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1188
|
+
|
|
1189
|
+
expect(response.reasoning).toBe("Let me think.")
|
|
1190
|
+
}),
|
|
1191
|
+
)
|
|
1192
|
+
|
|
1193
|
+
for (const signature of [undefined, "", " "]) {
|
|
1194
|
+
for (const cache of ["none", "auto"] as const) {
|
|
1195
|
+
it.effect(`drops unsigned reasoning (${JSON.stringify(signature)}, cache: ${cache})`, () =>
|
|
1196
|
+
Effect.gen(function* () {
|
|
1197
|
+
const prepared = yield* compileRequest(
|
|
1198
|
+
ai.request({
|
|
1199
|
+
model,
|
|
1200
|
+
messages: [
|
|
1201
|
+
Message.user("Think"),
|
|
1202
|
+
Message.assistant([
|
|
1203
|
+
{
|
|
1204
|
+
type: "reasoning",
|
|
1205
|
+
text: "Partial thought",
|
|
1206
|
+
providerMetadata: signature === undefined ? undefined : { bedrock: { signature } },
|
|
1207
|
+
cache: new CacheHint({ type: "ephemeral" }),
|
|
1208
|
+
},
|
|
1209
|
+
]),
|
|
1210
|
+
Message.user("Continue"),
|
|
1211
|
+
],
|
|
1212
|
+
cache,
|
|
1213
|
+
}),
|
|
1214
|
+
)
|
|
1215
|
+
expect(prepared.body.messages).toEqual([
|
|
1216
|
+
{
|
|
1217
|
+
role: "user",
|
|
1218
|
+
content:
|
|
1219
|
+
cache === "auto"
|
|
1220
|
+
? [{ text: "Think" }, { text: "Continue" }, { cachePoint: { type: "default" } }]
|
|
1221
|
+
: [{ text: "Think" }, { text: "Continue" }],
|
|
1222
|
+
},
|
|
1223
|
+
])
|
|
1224
|
+
}),
|
|
1225
|
+
)
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
it.effect("omits empty unsigned reasoning without leaving an empty or cache-only assistant", () =>
|
|
1230
|
+
Effect.gen(function* () {
|
|
1231
|
+
const cache = new CacheHint({ type: "ephemeral" })
|
|
1232
|
+
const prepared = yield* compileRequest(
|
|
1233
|
+
ai.request({
|
|
1234
|
+
model,
|
|
1235
|
+
messages: [
|
|
1236
|
+
Message.user("Think"),
|
|
1237
|
+
Message.assistant([
|
|
1238
|
+
{ type: "reasoning", text: "", cache },
|
|
1239
|
+
{ type: "reasoning", text: " ", providerMetadata: { bedrock: { signature: "" } }, cache },
|
|
1240
|
+
]),
|
|
1241
|
+
Message.user([{ type: "text", text: "Continue", cache }]),
|
|
1242
|
+
],
|
|
1243
|
+
cache: "none",
|
|
1244
|
+
}),
|
|
1245
|
+
)
|
|
1246
|
+
expect(prepared.body.messages).toEqual([
|
|
1247
|
+
{
|
|
1248
|
+
role: "user",
|
|
1249
|
+
content: [{ text: "Think" }, { text: "Continue" }, { cachePoint: { type: "default" } }],
|
|
1250
|
+
},
|
|
1251
|
+
])
|
|
1252
|
+
}),
|
|
1253
|
+
)
|
|
1254
|
+
|
|
1255
|
+
it.effect("drops foreign reasoning while preserving signed, redacted, text, and tool blocks", () =>
|
|
1256
|
+
Effect.gen(function* () {
|
|
1257
|
+
const cache = new CacheHint({ type: "ephemeral" })
|
|
1258
|
+
const prepared = yield* compileRequest(
|
|
1259
|
+
ai.request({
|
|
1260
|
+
model,
|
|
1261
|
+
messages: [
|
|
1262
|
+
Message.assistant([
|
|
1263
|
+
{ type: "reasoning", text: "Foreign thought", providerMetadata: { anthropic: { signature: "old" } } },
|
|
1264
|
+
{
|
|
1265
|
+
type: "reasoning",
|
|
1266
|
+
text: "Signed thought",
|
|
1267
|
+
providerMetadata: { bedrock: { signature: "sig_1" } },
|
|
1268
|
+
cache,
|
|
1269
|
+
},
|
|
1270
|
+
{ type: "reasoning", text: "", encrypted: "sig_2", cache },
|
|
1271
|
+
{ type: "reasoning", text: "", providerMetadata: { bedrock: { redactedData: "cmVkYWN0ZWQ=" } }, cache },
|
|
1272
|
+
{ type: "text", text: "Checking" },
|
|
1273
|
+
ToolCallPart.make({ id: "call_1", name: "lookup", input: {} }),
|
|
1274
|
+
]),
|
|
1275
|
+
],
|
|
1276
|
+
tools: [{ name: "lookup", description: "Lookup data", inputSchema: { type: "object" } }],
|
|
1277
|
+
cache: "none",
|
|
1278
|
+
}),
|
|
1279
|
+
)
|
|
1280
|
+
expect(prepared.body.messages).toEqual([
|
|
1281
|
+
{
|
|
1282
|
+
role: "assistant",
|
|
1283
|
+
content: [
|
|
1284
|
+
{ reasoningContent: { reasoningText: { text: "Signed thought", signature: "sig_1" } } },
|
|
1285
|
+
{ reasoningContent: { reasoningText: { text: "", signature: "sig_2" } } },
|
|
1286
|
+
{ reasoningContent: { redactedContent: "cmVkYWN0ZWQ=" } },
|
|
1287
|
+
{ text: "Checking" },
|
|
1288
|
+
{ toolUse: { toolUseId: "call_1", name: "lookup", input: {} } },
|
|
1289
|
+
],
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
role: "user",
|
|
1293
|
+
content: [
|
|
1294
|
+
{ toolResult: { toolUseId: "call_1", content: [{ text: "Tool result missing" }], status: "error" } },
|
|
1295
|
+
],
|
|
1296
|
+
},
|
|
1297
|
+
])
|
|
1298
|
+
}),
|
|
1299
|
+
)
|
|
1300
|
+
|
|
1301
|
+
it.effect("preserves streamed reasoning signatures for continuation lowering", () =>
|
|
1302
|
+
Effect.gen(function* () {
|
|
1303
|
+
const body = eventStreamBody(
|
|
1304
|
+
["messageStart", { role: "assistant" }],
|
|
1305
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { text: "Let me think." } } }],
|
|
1306
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { signature: "sig_1" } } }],
|
|
1307
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1308
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1309
|
+
)
|
|
1310
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1311
|
+
const reasoning = response.events.find((event) => event.type === "reasoning-end")
|
|
1312
|
+
|
|
1313
|
+
expect(reasoning).toEqual({
|
|
1314
|
+
type: "reasoning-end",
|
|
1315
|
+
id: "reasoning-0",
|
|
1316
|
+
providerMetadata: { bedrock: { signature: "sig_1" } },
|
|
1317
|
+
})
|
|
1318
|
+
|
|
1319
|
+
const prepared = yield* compileRequest(
|
|
1320
|
+
ai.request({
|
|
1321
|
+
model,
|
|
1322
|
+
messages: [
|
|
1323
|
+
Message.assistant([
|
|
1324
|
+
{ type: "reasoning", text: "Let me think.", providerMetadata: reasoning?.providerMetadata },
|
|
1325
|
+
]),
|
|
1326
|
+
],
|
|
1327
|
+
cache: "none",
|
|
1328
|
+
}),
|
|
1329
|
+
)
|
|
1330
|
+
expect(prepared.body.messages).toEqual([
|
|
1331
|
+
{
|
|
1332
|
+
role: "assistant",
|
|
1333
|
+
content: [{ reasoningContent: { reasoningText: { text: "Let me think.", signature: "sig_1" } } }],
|
|
1334
|
+
},
|
|
1335
|
+
])
|
|
1336
|
+
}),
|
|
1337
|
+
)
|
|
1338
|
+
|
|
1339
|
+
it.effect("round-trips reassigned provider reasoning and usage metadata in its own namespace", () =>
|
|
1340
|
+
Effect.gen(function* () {
|
|
1341
|
+
const compatible = model.route.with({ provider: "custom-bedrock" }).model({ id: model.id })
|
|
1342
|
+
const redactedData = "cmVkYWN0ZWQtdGhpbmtpbmc="
|
|
1343
|
+
const response = yield* LLMClient.generate({ ...baseRequest, model: compatible }).pipe(
|
|
1344
|
+
Effect.provide(
|
|
1345
|
+
fixedBytes(
|
|
1346
|
+
eventStreamBody(
|
|
1347
|
+
["messageStart", { role: "assistant" }],
|
|
1348
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { text: "Let me think." } } }],
|
|
1349
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { signature: "custom_sig" } } }],
|
|
1350
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1351
|
+
[
|
|
1352
|
+
"contentBlockDelta",
|
|
1353
|
+
{ contentBlockIndex: 1, delta: { reasoningContent: { redactedContent: redactedData } } },
|
|
1354
|
+
],
|
|
1355
|
+
["contentBlockStop", { contentBlockIndex: 1 }],
|
|
1356
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1357
|
+
["metadata", { usage: { inputTokens: 5, outputTokens: 2, totalTokens: 7 } }],
|
|
1358
|
+
),
|
|
1359
|
+
),
|
|
1360
|
+
),
|
|
1361
|
+
)
|
|
1362
|
+
|
|
1363
|
+
expect(response.message.content).toEqual([
|
|
1364
|
+
{
|
|
1365
|
+
type: "reasoning",
|
|
1366
|
+
text: "Let me think.",
|
|
1367
|
+
providerMetadata: { "custom-bedrock": { signature: "custom_sig" } },
|
|
1368
|
+
},
|
|
1369
|
+
{ type: "reasoning", text: "", providerMetadata: { "custom-bedrock": { redactedData } } },
|
|
1370
|
+
])
|
|
1371
|
+
expect(response.usage?.providerMetadata).toEqual({
|
|
1372
|
+
"custom-bedrock": { inputTokens: 5, outputTokens: 2, totalTokens: 7 },
|
|
1373
|
+
})
|
|
1374
|
+
|
|
1375
|
+
const prepared = yield* compileRequest(
|
|
1376
|
+
ai.request({ model: compatible, messages: [response.message], cache: "none" }),
|
|
1377
|
+
)
|
|
1378
|
+
expect(prepared.body.messages).toEqual([
|
|
1379
|
+
{
|
|
1380
|
+
role: "assistant",
|
|
1381
|
+
content: [
|
|
1382
|
+
{ reasoningContent: { reasoningText: { text: "Let me think.", signature: "custom_sig" } } },
|
|
1383
|
+
{ reasoningContent: { redactedContent: redactedData } },
|
|
1384
|
+
],
|
|
1385
|
+
},
|
|
1386
|
+
])
|
|
1387
|
+
}),
|
|
1388
|
+
)
|
|
1389
|
+
|
|
1390
|
+
it.effect("preserves reasoning signatures when contentBlockStop is missing", () =>
|
|
1391
|
+
Effect.gen(function* () {
|
|
1392
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(
|
|
1393
|
+
Effect.provide(
|
|
1394
|
+
fixedBytes(
|
|
1395
|
+
eventStreamBody(
|
|
1396
|
+
["messageStart", { role: "assistant" }],
|
|
1397
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { text: "Let me think." } } }],
|
|
1398
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { signature: "sig_1" } } }],
|
|
1399
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1400
|
+
),
|
|
1401
|
+
),
|
|
1402
|
+
),
|
|
1403
|
+
)
|
|
1404
|
+
|
|
1405
|
+
expect(response.events.find((event) => event.type === "reasoning-delta" && event.text === "")).toEqual({
|
|
1406
|
+
type: "reasoning-delta",
|
|
1407
|
+
id: "reasoning-0",
|
|
1408
|
+
text: "",
|
|
1409
|
+
providerMetadata: { bedrock: { signature: "sig_1" } },
|
|
1410
|
+
})
|
|
1411
|
+
expect(response.message.content).toEqual([
|
|
1412
|
+
{
|
|
1413
|
+
type: "reasoning",
|
|
1414
|
+
text: "Let me think.",
|
|
1415
|
+
providerMetadata: { bedrock: { signature: "sig_1" } },
|
|
1416
|
+
},
|
|
1417
|
+
])
|
|
1418
|
+
|
|
1419
|
+
const prepared = yield* compileRequest(ai.request({ model, messages: [response.message], cache: "none" }))
|
|
1420
|
+
expect(prepared.body.messages).toEqual([
|
|
1421
|
+
{
|
|
1422
|
+
role: "assistant",
|
|
1423
|
+
content: [{ reasoningContent: { reasoningText: { text: "Let me think.", signature: "sig_1" } } }],
|
|
1424
|
+
},
|
|
1425
|
+
])
|
|
1426
|
+
}),
|
|
1427
|
+
)
|
|
1428
|
+
|
|
1429
|
+
it.effect("preserves signature-only reasoning blocks", () =>
|
|
1430
|
+
Effect.gen(function* () {
|
|
1431
|
+
const body = eventStreamBody(
|
|
1432
|
+
["messageStart", { role: "assistant" }],
|
|
1433
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { signature: "sig_1" } } }],
|
|
1434
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1435
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1436
|
+
)
|
|
1437
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1438
|
+
|
|
1439
|
+
expect(response.message.content).toEqual([
|
|
1440
|
+
{ type: "reasoning", text: "", providerMetadata: { bedrock: { signature: "sig_1" } } },
|
|
1441
|
+
])
|
|
1442
|
+
}),
|
|
1443
|
+
)
|
|
1444
|
+
|
|
1445
|
+
it.effect("accepts Vercel-compatible redacted reasoning data deltas", () =>
|
|
1446
|
+
Effect.gen(function* () {
|
|
1447
|
+
const redactedData = "cmVkYWN0ZWQtdGhpbmtpbmc="
|
|
1448
|
+
const body = eventStreamBody(
|
|
1449
|
+
["messageStart", { role: "assistant" }],
|
|
1450
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { data: redactedData } } }],
|
|
1451
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1452
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1453
|
+
)
|
|
1454
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1455
|
+
|
|
1456
|
+
expect(response.events.find((event) => event.type === "reasoning-delta" && event.text === "")).toEqual({
|
|
1457
|
+
type: "reasoning-delta",
|
|
1458
|
+
id: "reasoning-0",
|
|
1459
|
+
text: "",
|
|
1460
|
+
providerMetadata: { bedrock: { redactedData } },
|
|
1461
|
+
})
|
|
1462
|
+
expect(response.message.content).toEqual([
|
|
1463
|
+
{ type: "reasoning", text: "", providerMetadata: { bedrock: { redactedData } } },
|
|
1464
|
+
])
|
|
1465
|
+
}),
|
|
1466
|
+
)
|
|
1467
|
+
|
|
1468
|
+
it.effect("round-trips streamed redacted reasoning with tool use into a continuation request", () =>
|
|
1469
|
+
Effect.gen(function* () {
|
|
1470
|
+
// Bedrock represents redactedContent blobs as base64 strings on its JSON
|
|
1471
|
+
// wire. The provider owns the payload and requires byte-exact replay.
|
|
1472
|
+
const redactedData = "AQID"
|
|
1473
|
+
const response = yield* LLMClient.generate({
|
|
1474
|
+
...baseRequest,
|
|
1475
|
+
tools: [ToolDefinition.make({ name: "lookup", description: "Lookup data", inputSchema: { type: "object" } })],
|
|
1476
|
+
}).pipe(
|
|
1477
|
+
Effect.provide(
|
|
1478
|
+
fixedBytes(
|
|
1479
|
+
eventStreamBody(
|
|
1480
|
+
["messageStart", { role: "assistant" }],
|
|
1481
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { redactedContent: "AQ==" } } }],
|
|
1482
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { redactedContent: "AgM=" } } }],
|
|
1483
|
+
["contentBlockStop", { contentBlockIndex: 0 }],
|
|
1484
|
+
[
|
|
1485
|
+
"contentBlockStart",
|
|
1486
|
+
{
|
|
1487
|
+
contentBlockIndex: 1,
|
|
1488
|
+
start: { toolUse: { toolUseId: "tool_1", name: "lookup" } },
|
|
1489
|
+
},
|
|
1490
|
+
],
|
|
1491
|
+
["contentBlockDelta", { contentBlockIndex: 1, delta: { toolUse: { input: '{"query":"weather"}' } } }],
|
|
1492
|
+
["contentBlockStop", { contentBlockIndex: 1 }],
|
|
1493
|
+
["messageStop", { stopReason: "tool_use" }],
|
|
1494
|
+
),
|
|
1495
|
+
),
|
|
1496
|
+
),
|
|
1497
|
+
)
|
|
1498
|
+
expect(response.events.filter((event) => event.type === "reasoning-delta")).toEqual([])
|
|
1499
|
+
expect(response.events.find((event) => event.type === "reasoning-start")).toEqual({
|
|
1500
|
+
type: "reasoning-start",
|
|
1501
|
+
id: "reasoning-0",
|
|
1502
|
+
providerMetadata: undefined,
|
|
1503
|
+
})
|
|
1504
|
+
expect(response.events.find((event) => event.type === "reasoning-end")).toEqual({
|
|
1505
|
+
type: "reasoning-end",
|
|
1506
|
+
id: "reasoning-0",
|
|
1507
|
+
providerMetadata: { bedrock: { redactedData } },
|
|
1508
|
+
})
|
|
1509
|
+
const prepared = yield* compileRequest(
|
|
1510
|
+
ai.request({
|
|
1511
|
+
model,
|
|
1512
|
+
messages: [
|
|
1513
|
+
Message.user("Say hello."),
|
|
1514
|
+
response.message,
|
|
1515
|
+
Message.tool({ id: "tool_1", name: "lookup", result: "sunny", resultType: "text" }),
|
|
1516
|
+
],
|
|
1517
|
+
tools: [{ name: "lookup", description: "Lookup data", inputSchema: { type: "object" } }],
|
|
1518
|
+
cache: "none",
|
|
1519
|
+
}),
|
|
1520
|
+
)
|
|
1521
|
+
|
|
1522
|
+
expect(prepared.body.messages).toEqual([
|
|
1523
|
+
{ role: "user", content: [{ text: "Say hello." }] },
|
|
1524
|
+
{
|
|
1525
|
+
role: "assistant",
|
|
1526
|
+
content: [
|
|
1527
|
+
{ reasoningContent: { redactedContent: redactedData } },
|
|
1528
|
+
{ toolUse: { toolUseId: "tool_1", name: "lookup", input: { query: "weather" } } },
|
|
1529
|
+
],
|
|
1530
|
+
},
|
|
1531
|
+
{
|
|
1532
|
+
role: "user",
|
|
1533
|
+
content: [{ toolResult: { toolUseId: "tool_1", content: [{ text: "sunny" }], status: "success" } }],
|
|
1534
|
+
},
|
|
1535
|
+
])
|
|
1536
|
+
}),
|
|
1537
|
+
)
|
|
1538
|
+
|
|
1539
|
+
it.effect("keeps redacted reasoning accumulation separate by content block index", () =>
|
|
1540
|
+
Effect.gen(function* () {
|
|
1541
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(
|
|
1542
|
+
Effect.provide(
|
|
1543
|
+
fixedBytes(
|
|
1544
|
+
eventStreamBody(
|
|
1545
|
+
["messageStart", { role: "assistant" }],
|
|
1546
|
+
["contentBlockDelta", { contentBlockIndex: 2, delta: { reasoningContent: { redactedContent: "AQ==" } } }],
|
|
1547
|
+
["contentBlockDelta", { contentBlockIndex: 2, delta: { reasoningContent: { redactedContent: "Ag==" } } }],
|
|
1548
|
+
["contentBlockStop", { contentBlockIndex: 2 }],
|
|
1549
|
+
["contentBlockDelta", { contentBlockIndex: 7, delta: { reasoningContent: { redactedContent: "Aw==" } } }],
|
|
1550
|
+
["contentBlockDelta", { contentBlockIndex: 7, delta: { reasoningContent: { redactedContent: "BA==" } } }],
|
|
1551
|
+
["contentBlockStop", { contentBlockIndex: 7 }],
|
|
1552
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1553
|
+
),
|
|
1554
|
+
),
|
|
1555
|
+
),
|
|
1556
|
+
)
|
|
1557
|
+
|
|
1558
|
+
expect(response.message.content).toEqual([
|
|
1559
|
+
{ type: "reasoning", text: "", providerMetadata: { bedrock: { redactedData: "AQI=" } } },
|
|
1560
|
+
{ type: "reasoning", text: "", providerMetadata: { bedrock: { redactedData: "AwQ=" } } },
|
|
1561
|
+
])
|
|
1562
|
+
}),
|
|
1563
|
+
)
|
|
1564
|
+
|
|
1565
|
+
it.effect("preserves split redacted reasoning when contentBlockStop is missing", () =>
|
|
1566
|
+
Effect.gen(function* () {
|
|
1567
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(
|
|
1568
|
+
Effect.provide(
|
|
1569
|
+
fixedBytes(
|
|
1570
|
+
eventStreamBody(
|
|
1571
|
+
["messageStart", { role: "assistant" }],
|
|
1572
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { redactedContent: "AQ==" } } }],
|
|
1573
|
+
["contentBlockDelta", { contentBlockIndex: 0, delta: { reasoningContent: { redactedContent: "AgM=" } } }],
|
|
1574
|
+
["messageStop", { stopReason: "end_turn" }],
|
|
1575
|
+
),
|
|
1576
|
+
),
|
|
1577
|
+
),
|
|
1578
|
+
)
|
|
1579
|
+
|
|
1580
|
+
expect(response.events.filter((event) => event.type === "reasoning-delta")).toEqual([])
|
|
1581
|
+
expect(response.events.find((event) => event.type === "reasoning-end")).toEqual({
|
|
1582
|
+
type: "reasoning-end",
|
|
1583
|
+
id: "reasoning-0",
|
|
1584
|
+
providerMetadata: { bedrock: { redactedData: "AQID" } },
|
|
1585
|
+
text: undefined,
|
|
1586
|
+
})
|
|
1587
|
+
expect(response.message.content).toEqual([
|
|
1588
|
+
{ type: "reasoning", text: "", providerMetadata: { bedrock: { redactedData: "AQID" } } },
|
|
1589
|
+
])
|
|
1590
|
+
}),
|
|
1591
|
+
)
|
|
1592
|
+
|
|
1593
|
+
it.effect("rejects invalid redacted reasoning base64 with the triggering event", () =>
|
|
1594
|
+
Effect.gen(function* () {
|
|
1595
|
+
const payload = { contentBlockIndex: 0, delta: { reasoningContent: { redactedContent: "%%==" } } }
|
|
1596
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(
|
|
1597
|
+
Effect.provide(fixedBytes(eventStreamBody(["contentBlockDelta", payload]))),
|
|
1598
|
+
Effect.flip,
|
|
1599
|
+
)
|
|
1600
|
+
|
|
1601
|
+
expect(error).toMatchObject({
|
|
1602
|
+
reason: { _tag: "InvalidProviderOutput" },
|
|
1603
|
+
message: "Bedrock Converse reasoningContent.redactedContent contains invalid base64 data",
|
|
1604
|
+
})
|
|
1605
|
+
expect(JSON.parse(error.reason.body ?? "")).toMatchObject({
|
|
1606
|
+
headers: { ":event-type": { value: "contentBlockDelta" } },
|
|
1607
|
+
body: JSON.stringify(payload),
|
|
1608
|
+
})
|
|
1609
|
+
expect(error.reason.cause).toBeInstanceOf(Error)
|
|
1610
|
+
}),
|
|
1611
|
+
)
|
|
1612
|
+
|
|
1613
|
+
it.effect("ignores unknown normal stream events", () =>
|
|
1614
|
+
Effect.gen(function* () {
|
|
1615
|
+
const body = concat([
|
|
1616
|
+
eventFrame("messageStart", { role: "assistant" }),
|
|
1617
|
+
eventFrame("futureEvent", { message: "Ignore this" }),
|
|
1618
|
+
eventFrame("messageStop", { stopReason: "end_turn" }),
|
|
1619
|
+
])
|
|
1620
|
+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
|
|
1621
|
+
|
|
1622
|
+
expect(response.finishReason).toEqual({ normalized: "stop", raw: "end_turn" })
|
|
1623
|
+
}),
|
|
1624
|
+
)
|
|
1625
|
+
|
|
1626
|
+
it.effect("fails unknown stream exceptions after message stop", () =>
|
|
1627
|
+
Effect.gen(function* () {
|
|
1628
|
+
const body = concat([
|
|
1629
|
+
eventFrame("messageStart", { role: "assistant" }),
|
|
1630
|
+
eventFrame("messageStop", { stopReason: "end_turn" }),
|
|
1631
|
+
exceptionFrame("futureException", { message: "A future provider failure" }),
|
|
1632
|
+
])
|
|
1633
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)), Effect.flip)
|
|
1634
|
+
|
|
1635
|
+
expect(error).toMatchObject({ reason: { _tag: "UnknownProvider" }, message: "A future provider failure" })
|
|
1636
|
+
}),
|
|
1637
|
+
)
|
|
1638
|
+
|
|
1639
|
+
it.effect("classifies throttlingException as a rate limit", () =>
|
|
1640
|
+
Effect.gen(function* () {
|
|
1641
|
+
const payload = { message: "Slow down", details: { opaque: [1, 2] }, trace: "outer", p: "padding" }
|
|
1642
|
+
const body = concat([
|
|
1643
|
+
eventFrame("messageStart", { role: "assistant" }),
|
|
1644
|
+
exceptionFrame("throttlingException", payload),
|
|
1645
|
+
])
|
|
1646
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)), Effect.flip)
|
|
1647
|
+
|
|
1648
|
+
expect(error).toMatchObject({ reason: { _tag: "RateLimit" }, message: "Slow down" })
|
|
1649
|
+
expect(JSON.parse(error.reason.body ?? "")).toEqual({
|
|
1650
|
+
headers: {
|
|
1651
|
+
":message-type": { type: "string", value: "exception" },
|
|
1652
|
+
":exception-type": { type: "string", value: "throttlingException" },
|
|
1653
|
+
":content-type": { type: "string", value: "application/json" },
|
|
1654
|
+
},
|
|
1655
|
+
body: JSON.stringify(payload),
|
|
1656
|
+
})
|
|
1657
|
+
expect(error.reason.http).toMatchObject({
|
|
1658
|
+
status: 200,
|
|
1659
|
+
headers: { "content-type": "application/vnd.amazon.eventstream" },
|
|
1660
|
+
})
|
|
1661
|
+
}),
|
|
1662
|
+
)
|
|
1663
|
+
|
|
1664
|
+
it.effect("classifies input-too-long validation exceptions", () =>
|
|
1665
|
+
Effect.gen(function* () {
|
|
1666
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(
|
|
1667
|
+
Effect.provide(
|
|
1668
|
+
fixedBytes(exceptionFrame("validationException", { message: "Input is too long for requested model" })),
|
|
1669
|
+
),
|
|
1670
|
+
Effect.flip,
|
|
1671
|
+
)
|
|
1672
|
+
|
|
1673
|
+
expect(error).toMatchObject({
|
|
1674
|
+
reason: { _tag: "InvalidRequest", classification: "context-overflow" },
|
|
1675
|
+
message: "Input is too long for requested model",
|
|
1676
|
+
})
|
|
1677
|
+
}),
|
|
1678
|
+
)
|
|
1679
|
+
|
|
1680
|
+
it.effect("uses originalMessage and originalStatusCode from model stream exception frames", () =>
|
|
1681
|
+
Effect.gen(function* () {
|
|
1682
|
+
const serverError = yield* LLMClient.generate(baseRequest).pipe(
|
|
1683
|
+
Effect.provide(
|
|
1684
|
+
fixedBytes(
|
|
1685
|
+
exceptionFrame("modelStreamErrorException", {
|
|
1686
|
+
originalMessage: "Upstream model failed",
|
|
1687
|
+
originalStatusCode: 500,
|
|
1688
|
+
}),
|
|
1689
|
+
),
|
|
1690
|
+
),
|
|
1691
|
+
Effect.flip,
|
|
1692
|
+
)
|
|
1693
|
+
const clientError = yield* LLMClient.generate(baseRequest).pipe(
|
|
1694
|
+
Effect.provide(
|
|
1695
|
+
fixedBytes(
|
|
1696
|
+
exceptionFrame("modelStreamErrorException", {
|
|
1697
|
+
originalMessage: "Upstream rejected request",
|
|
1698
|
+
originalStatusCode: 400,
|
|
1699
|
+
}),
|
|
1700
|
+
),
|
|
1701
|
+
),
|
|
1702
|
+
Effect.flip,
|
|
1703
|
+
)
|
|
1704
|
+
|
|
1705
|
+
expect(serverError).toMatchObject({ reason: { _tag: "ProviderInternal" }, message: "Upstream model failed" })
|
|
1706
|
+
expect(clientError).toMatchObject({ reason: { _tag: "InvalidRequest" }, message: "Upstream rejected request" })
|
|
1707
|
+
}),
|
|
1708
|
+
)
|
|
1709
|
+
|
|
1710
|
+
it.effect("fails unmodeled AWS event-stream errors", () =>
|
|
1711
|
+
Effect.gen(function* () {
|
|
1712
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(
|
|
1713
|
+
Effect.provide(fixedBytes(errorFrame("BadStream", "Stream failed"))),
|
|
1714
|
+
Effect.flip,
|
|
1715
|
+
)
|
|
1716
|
+
|
|
1717
|
+
expect(error).toMatchObject({
|
|
1718
|
+
reason: { _tag: "InvalidProviderOutput" },
|
|
1719
|
+
message: "BadStream: Stream failed",
|
|
1720
|
+
})
|
|
1721
|
+
expect(JSON.parse(error.reason.body ?? "")).toMatchObject({
|
|
1722
|
+
headers: { ":error-code": { value: "BadStream" } },
|
|
1723
|
+
body: "",
|
|
1724
|
+
})
|
|
1725
|
+
}),
|
|
1726
|
+
)
|
|
1727
|
+
|
|
1728
|
+
it.effect("retains malformed AWS payloads with headers and decode cause", () =>
|
|
1729
|
+
Effect.gen(function* () {
|
|
1730
|
+
const headers = {
|
|
1731
|
+
":message-type": { type: "string" as const, value: "event" },
|
|
1732
|
+
":event-type": { type: "string" as const, value: "messageStart" },
|
|
1733
|
+
}
|
|
1734
|
+
const body = '{"malformed":'
|
|
1735
|
+
const error = yield* LLMClient.generate(baseRequest).pipe(
|
|
1736
|
+
Effect.provide(fixedBytes(codec.encode({ headers, body: utf8Encoder.encode(body) }))),
|
|
1737
|
+
Effect.flip,
|
|
1738
|
+
)
|
|
1739
|
+
expect(error.reason._tag).toBe("InvalidProviderOutput")
|
|
1740
|
+
expect(JSON.parse(error.reason.body ?? "")).toEqual({ headers, body })
|
|
1741
|
+
expect(error.reason.cause).toBeInstanceOf(Error)
|
|
1742
|
+
expect(error.reason.http?.status).toBe(200)
|
|
1743
|
+
}),
|
|
1744
|
+
)
|
|
1745
|
+
|
|
1746
|
+
it.effect("fails with an authentication error when the default chain cannot resolve credentials", () =>
|
|
1747
|
+
Effect.gen(function* () {
|
|
1748
|
+
const unsignedModel = AmazonBedrock.configure({
|
|
1749
|
+
baseURL: "https://bedrock-runtime.test",
|
|
1750
|
+
profile: "opencode-test-missing-profile",
|
|
1751
|
+
}).model("anthropic.claude-3-5-sonnet-20240620-v1:0")
|
|
1752
|
+
const error = yield* LLMClient.generate({ ...baseRequest, model: unsignedModel }).pipe(
|
|
1753
|
+
Effect.provide(fixedBytes(eventStreamBody(["messageStop", { stopReason: "end_turn" }]))),
|
|
1754
|
+
Effect.flip,
|
|
1755
|
+
)
|
|
1756
|
+
|
|
1757
|
+
expect(error.reason._tag).toBe("Authentication")
|
|
1758
|
+
expect(error.message).toContain("AWS default credential chain failed")
|
|
1759
|
+
}).pipe(withProcessEnv(noAmbientAWS)),
|
|
1760
|
+
)
|
|
1761
|
+
|
|
1762
|
+
it.effect("signs with static credentials using the configured region for the SigV4 scope", () =>
|
|
1763
|
+
Effect.gen(function* () {
|
|
1764
|
+
const signed = AmazonBedrock.configure({
|
|
1765
|
+
baseURL: "https://bedrock-runtime.test",
|
|
1766
|
+
region: "eu-west-1",
|
|
1767
|
+
credentials: {
|
|
1768
|
+
region: "us-east-1",
|
|
1769
|
+
accessKeyId: "AKIAIOSFODNN7EXAMPLE",
|
|
1770
|
+
secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
|
|
1771
|
+
},
|
|
1772
|
+
}).model("anthropic.claude-3-5-sonnet-20240620-v1:0")
|
|
1773
|
+
const headers = yield* captureHeaders(signed)
|
|
1774
|
+
|
|
1775
|
+
expect(headers.get("authorization")).toContain("Credential=AKIAIOSFODNN7EXAMPLE/")
|
|
1776
|
+
expect(headers.get("authorization")).toContain("/eu-west-1/bedrock/aws4_request")
|
|
1777
|
+
expect(headers.get("x-amz-security-token")).toBeNull()
|
|
1778
|
+
}).pipe(withProcessEnv(noAmbientAWS)),
|
|
1779
|
+
)
|
|
1780
|
+
|
|
1781
|
+
it.effect("resolves SigV4 credentials through the AWS default chain on every request", () =>
|
|
1782
|
+
Effect.gen(function* () {
|
|
1783
|
+
const chained = AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test", region: "us-west-2" }).model(
|
|
1784
|
+
"anthropic.claude-3-5-sonnet-20240620-v1:0",
|
|
1785
|
+
)
|
|
1786
|
+
const headers = yield* captureHeaders(chained)
|
|
1787
|
+
|
|
1788
|
+
expect(headers.get("authorization")).toContain("Credential=AKIACHAINEXAMPLE/")
|
|
1789
|
+
expect(headers.get("authorization")).toContain("/us-west-2/bedrock/aws4_request")
|
|
1790
|
+
expect(headers.get("x-amz-security-token")).toBe("chain-session-token")
|
|
1791
|
+
}).pipe(
|
|
1792
|
+
withProcessEnv({
|
|
1793
|
+
...noAmbientAWS,
|
|
1794
|
+
AWS_ACCESS_KEY_ID: "AKIACHAINEXAMPLE",
|
|
1795
|
+
AWS_SECRET_ACCESS_KEY: "chain-secret",
|
|
1796
|
+
AWS_SESSION_TOKEN: "chain-session-token",
|
|
1797
|
+
}),
|
|
1798
|
+
),
|
|
1799
|
+
)
|
|
1800
|
+
|
|
1801
|
+
it.effect("re-resolves rotated chain credentials on the next request without rebuilding the model", () =>
|
|
1802
|
+
Effect.gen(function* () {
|
|
1803
|
+
const chained = AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test", region: "us-west-2" }).model(
|
|
1804
|
+
"anthropic.claude-3-5-sonnet-20240620-v1:0",
|
|
1805
|
+
)
|
|
1806
|
+
const first = yield* captureHeaders(chained)
|
|
1807
|
+
const second = yield* captureHeaders(chained).pipe(
|
|
1808
|
+
withProcessEnv({ AWS_ACCESS_KEY_ID: "AKIAROTATEDEXAMPLE", AWS_SECRET_ACCESS_KEY: "rotated-secret" }),
|
|
1809
|
+
)
|
|
1810
|
+
|
|
1811
|
+
expect(first.get("authorization")).toContain("Credential=AKIACHAINEXAMPLE/")
|
|
1812
|
+
expect(second.get("authorization")).toContain("Credential=AKIAROTATEDEXAMPLE/")
|
|
1813
|
+
}).pipe(
|
|
1814
|
+
withProcessEnv({
|
|
1815
|
+
...noAmbientAWS,
|
|
1816
|
+
AWS_ACCESS_KEY_ID: "AKIACHAINEXAMPLE",
|
|
1817
|
+
AWS_SECRET_ACCESS_KEY: "chain-secret",
|
|
1818
|
+
}),
|
|
1819
|
+
),
|
|
1820
|
+
)
|
|
1821
|
+
|
|
1822
|
+
it.effect("prefers AWS_BEARER_TOKEN_BEDROCK over the credential chain", () =>
|
|
1823
|
+
Effect.gen(function* () {
|
|
1824
|
+
const bearer = AmazonBedrock.configure({ baseURL: "https://bedrock-runtime.test" }).model(
|
|
1825
|
+
"anthropic.claude-3-5-sonnet-20240620-v1:0",
|
|
1826
|
+
)
|
|
1827
|
+
const headers = yield* captureHeaders(bearer)
|
|
1828
|
+
|
|
1829
|
+
expect(headers.get("authorization")).toBe("Bearer env-bearer-token")
|
|
1830
|
+
}).pipe(
|
|
1831
|
+
withProcessEnv({
|
|
1832
|
+
...noAmbientAWS,
|
|
1833
|
+
AWS_BEARER_TOKEN_BEDROCK: "env-bearer-token",
|
|
1834
|
+
AWS_ACCESS_KEY_ID: "AKIACHAINEXAMPLE",
|
|
1835
|
+
AWS_SECRET_ACCESS_KEY: "chain-secret",
|
|
1836
|
+
}),
|
|
1837
|
+
),
|
|
1838
|
+
)
|
|
1839
|
+
|
|
1840
|
+
it.effect("auth: sigv4 ignores an ambient bearer token from configure and settings", () =>
|
|
1841
|
+
Effect.gen(function* () {
|
|
1842
|
+
const configured = AmazonBedrock.configure({ auth: "sigv4", baseURL: "https://bedrock-runtime.test" }).model(
|
|
1843
|
+
"anthropic.claude-3-5-sonnet-20240620-v1:0",
|
|
1844
|
+
)
|
|
1845
|
+
const fromSettings = AmazonBedrock.model("anthropic.claude-3-5-sonnet-20240620-v1:0", {
|
|
1846
|
+
auth: "sigv4",
|
|
1847
|
+
baseURL: "https://bedrock-runtime.test",
|
|
1848
|
+
})
|
|
1849
|
+
|
|
1850
|
+
for (const target of [configured, fromSettings]) {
|
|
1851
|
+
const headers = yield* captureHeaders(target)
|
|
1852
|
+
expect(headers.get("authorization")).toContain("Credential=AKIACHAINEXAMPLE/")
|
|
1853
|
+
expect(headers.get("authorization")).toContain("/ap-southeast-2/bedrock/aws4_request")
|
|
1854
|
+
}
|
|
1855
|
+
expect(() => AmazonBedrock.configure({ auth: "sigv4", apiKey: "k" })).toThrow(
|
|
1856
|
+
expect.objectContaining({
|
|
1857
|
+
_tag: "ProviderConfiguration",
|
|
1858
|
+
provider: "amazon-bedrock",
|
|
1859
|
+
message: "Amazon Bedrock SigV4 auth does not accept apiKey",
|
|
1860
|
+
}),
|
|
1861
|
+
)
|
|
1862
|
+
}).pipe(
|
|
1863
|
+
withProcessEnv({
|
|
1864
|
+
...noAmbientAWS,
|
|
1865
|
+
AWS_BEARER_TOKEN_BEDROCK: "env-bearer-token",
|
|
1866
|
+
AWS_REGION: "ap-southeast-2",
|
|
1867
|
+
AWS_ACCESS_KEY_ID: "AKIACHAINEXAMPLE",
|
|
1868
|
+
AWS_SECRET_ACCESS_KEY: "chain-secret",
|
|
1869
|
+
}),
|
|
1870
|
+
),
|
|
1871
|
+
)
|
|
1872
|
+
|
|
1873
|
+
it.effect("derives the endpoint region from AWS_REGION then AWS_DEFAULT_REGION", () =>
|
|
1874
|
+
Effect.gen(function* () {
|
|
1875
|
+
const fromRegion = AmazonBedrock.configure({ apiKey: "k" }).model("anthropic.claude-3-5-sonnet-20240620-v1:0")
|
|
1876
|
+
expect(fromRegion.route.endpoint.baseURL).toBe("https://bedrock-runtime.eu-central-1.amazonaws.com")
|
|
1877
|
+
|
|
1878
|
+
const fromDefault = yield* Effect.sync(() =>
|
|
1879
|
+
AmazonBedrock.configure({ apiKey: "k" }).model("anthropic.claude-3-5-sonnet-20240620-v1:0"),
|
|
1880
|
+
).pipe(withProcessEnv({ AWS_REGION: undefined }))
|
|
1881
|
+
expect(fromDefault.route.endpoint.baseURL).toBe("https://bedrock-runtime.us-gov-west-1.amazonaws.com")
|
|
1882
|
+
}).pipe(withProcessEnv({ ...noAmbientAWS, AWS_REGION: "eu-central-1", AWS_DEFAULT_REGION: "us-gov-west-1" })),
|
|
1883
|
+
)
|
|
1884
|
+
|
|
1885
|
+
it.effect("emits cachePoint markers after system, user-text, and assistant-text with cache hints", () =>
|
|
1886
|
+
Effect.gen(function* () {
|
|
1887
|
+
const cache = new CacheHint({ type: "ephemeral" })
|
|
1888
|
+
const prepared = yield* compileRequest(
|
|
1889
|
+
ai.request({
|
|
1890
|
+
id: "req_cache",
|
|
1891
|
+
model,
|
|
1892
|
+
system: [{ type: "text", text: "System prefix.", cache }],
|
|
1893
|
+
messages: [
|
|
1894
|
+
Message.user([{ type: "text", text: "User prefix.", cache }]),
|
|
1895
|
+
Message.assistant([{ type: "text", text: "Assistant prefix.", cache }]),
|
|
1896
|
+
],
|
|
1897
|
+
maxTokens: 16,
|
|
1898
|
+
temperature: 0,
|
|
1899
|
+
}),
|
|
1900
|
+
)
|
|
1901
|
+
|
|
1902
|
+
expect(prepared.body).toMatchObject({
|
|
1903
|
+
// System: text block followed by cachePoint marker.
|
|
1904
|
+
system: [{ text: "System prefix." }, { cachePoint: { type: "default" } }],
|
|
1905
|
+
messages: [
|
|
1906
|
+
{
|
|
1907
|
+
role: "user",
|
|
1908
|
+
content: [{ text: "User prefix." }, { cachePoint: { type: "default" } }],
|
|
1909
|
+
},
|
|
1910
|
+
{
|
|
1911
|
+
role: "assistant",
|
|
1912
|
+
content: [{ text: "Assistant prefix." }, { cachePoint: { type: "default" } }],
|
|
1913
|
+
},
|
|
1914
|
+
],
|
|
1915
|
+
})
|
|
1916
|
+
}),
|
|
1917
|
+
)
|
|
1918
|
+
|
|
1919
|
+
it.effect("does not emit cachePoint when no cache hint is set", () =>
|
|
1920
|
+
Effect.gen(function* () {
|
|
1921
|
+
const prepared = yield* compileRequest(baseRequest)
|
|
1922
|
+
expect(prepared.body).toMatchObject({
|
|
1923
|
+
system: [{ text: "You are concise." }],
|
|
1924
|
+
messages: [{ role: "user", content: [{ text: "Say hello." }] }],
|
|
1925
|
+
})
|
|
1926
|
+
}),
|
|
1927
|
+
)
|
|
1928
|
+
|
|
1929
|
+
it.effect("lowers image media into Bedrock image blocks", () =>
|
|
1930
|
+
Effect.gen(function* () {
|
|
1931
|
+
const prepared = yield* compileRequest(
|
|
1932
|
+
ai.request({
|
|
1933
|
+
id: "req_image",
|
|
1934
|
+
model,
|
|
1935
|
+
messages: [
|
|
1936
|
+
Message.user([
|
|
1937
|
+
{ type: "text", text: "What is in this image?" },
|
|
1938
|
+
{ type: "media", media: Media.base64("AAAA", "image/png") },
|
|
1939
|
+
{ type: "media", media: Media.base64("BBBB", "image/jpeg") },
|
|
1940
|
+
{ type: "media", media: Media.base64("CCCC", "image/jpg") },
|
|
1941
|
+
{ type: "media", media: Media.base64("DDDD", "image/webp") },
|
|
1942
|
+
]),
|
|
1943
|
+
],
|
|
1944
|
+
cache: "none",
|
|
1945
|
+
}),
|
|
1946
|
+
)
|
|
1947
|
+
|
|
1948
|
+
expect(prepared.body).toMatchObject({
|
|
1949
|
+
messages: [
|
|
1950
|
+
{
|
|
1951
|
+
role: "user",
|
|
1952
|
+
content: [
|
|
1953
|
+
{ text: "What is in this image?" },
|
|
1954
|
+
{ image: { format: "png", source: { bytes: "AAAA" } } },
|
|
1955
|
+
{ image: { format: "jpeg", source: { bytes: "BBBB" } } },
|
|
1956
|
+
// image/jpg is a non-standard alias; we map it to jpeg.
|
|
1957
|
+
{ image: { format: "jpeg", source: { bytes: "CCCC" } } },
|
|
1958
|
+
{ image: { format: "webp", source: { bytes: "DDDD" } } },
|
|
1959
|
+
],
|
|
1960
|
+
},
|
|
1961
|
+
],
|
|
1962
|
+
})
|
|
1963
|
+
}),
|
|
1964
|
+
)
|
|
1965
|
+
|
|
1966
|
+
it.effect("base64-encodes Uint8Array image bytes", () =>
|
|
1967
|
+
Effect.gen(function* () {
|
|
1968
|
+
const prepared = yield* compileRequest(
|
|
1969
|
+
ai.request({
|
|
1970
|
+
id: "req_image_bytes",
|
|
1971
|
+
model,
|
|
1972
|
+
messages: [
|
|
1973
|
+
Message.user([{ type: "media", media: Media.bytes(new Uint8Array([1, 2, 3, 4, 5]), "image/png") }]),
|
|
1974
|
+
],
|
|
1975
|
+
}),
|
|
1976
|
+
)
|
|
1977
|
+
|
|
1978
|
+
// Buffer.from([1,2,3,4,5]).toString("base64") === "AQIDBAU="
|
|
1979
|
+
expect(prepared.body).toMatchObject({
|
|
1980
|
+
messages: [
|
|
1981
|
+
{
|
|
1982
|
+
role: "user",
|
|
1983
|
+
content: [{ image: { format: "png", source: { bytes: "AQIDBAU=" } } }],
|
|
1984
|
+
},
|
|
1985
|
+
],
|
|
1986
|
+
})
|
|
1987
|
+
}),
|
|
1988
|
+
)
|
|
1989
|
+
|
|
1990
|
+
it.effect("rejects image media that is not valid base64", () =>
|
|
1991
|
+
Effect.gen(function* () {
|
|
1992
|
+
const error = yield* compileRequest(
|
|
1993
|
+
ai.request({
|
|
1994
|
+
model,
|
|
1995
|
+
messages: [Message.user({ type: "media", media: Media.base64("not base64!", "image/png") })],
|
|
1996
|
+
}),
|
|
1997
|
+
).pipe(Effect.flip)
|
|
1998
|
+
|
|
1999
|
+
expect(error).toMatchObject({ reason: { _tag: "InvalidRequest" } })
|
|
2000
|
+
expect(error.message).toContain("Bedrock Converse media data must be valid base64")
|
|
2001
|
+
}),
|
|
2002
|
+
)
|
|
2003
|
+
|
|
2004
|
+
it.effect("rejects remote image URLs that were not materialized", () =>
|
|
2005
|
+
Effect.gen(function* () {
|
|
2006
|
+
const error = yield* compileRequest(
|
|
2007
|
+
ai.request({
|
|
2008
|
+
model,
|
|
2009
|
+
messages: [
|
|
2010
|
+
Message.user({
|
|
2011
|
+
type: "media",
|
|
2012
|
+
media: Media.url("https://example.test/image.png", { mediaType: "image/png" }),
|
|
2013
|
+
}),
|
|
2014
|
+
],
|
|
2015
|
+
}),
|
|
2016
|
+
).pipe(Effect.flip)
|
|
2017
|
+
|
|
2018
|
+
expect(error).toMatchObject({ reason: { _tag: "InvalidRequest" } })
|
|
2019
|
+
expect(error.message).toContain("requires inline media")
|
|
2020
|
+
}),
|
|
2021
|
+
)
|
|
2022
|
+
|
|
2023
|
+
it.effect("lowers document media into Bedrock document blocks with format and name", () =>
|
|
2024
|
+
Effect.gen(function* () {
|
|
2025
|
+
const prepared = yield* compileRequest(
|
|
2026
|
+
ai.request({
|
|
2027
|
+
id: "req_doc",
|
|
2028
|
+
model,
|
|
2029
|
+
cache: "none",
|
|
2030
|
+
messages: [
|
|
2031
|
+
Message.user([
|
|
2032
|
+
{ type: "text", text: "Summarize these documents." },
|
|
2033
|
+
{ type: "media", media: Media.base64("UERGREFUQQ==", "application/pdf"), filename: "report.pdf" },
|
|
2034
|
+
{ type: "media", media: Media.base64("Q1NWREFUQQ==", "text/csv"), filename: "data.csv" },
|
|
2035
|
+
]),
|
|
2036
|
+
],
|
|
2037
|
+
}),
|
|
2038
|
+
)
|
|
2039
|
+
|
|
2040
|
+
expect(prepared.body).toMatchObject({
|
|
2041
|
+
messages: [
|
|
2042
|
+
{
|
|
2043
|
+
role: "user",
|
|
2044
|
+
content: [
|
|
2045
|
+
{ text: "Summarize these documents." },
|
|
2046
|
+
{ text: 'Attached file "report.pdf" has document label "report".' },
|
|
2047
|
+
{ document: { format: "pdf", name: "report", source: { bytes: "UERGREFUQQ==" } } },
|
|
2048
|
+
{ text: 'Attached file "data.csv" has document label "data".' },
|
|
2049
|
+
{ document: { format: "csv", name: "data", source: { bytes: "Q1NWREFUQQ==" } } },
|
|
2050
|
+
],
|
|
2051
|
+
},
|
|
2052
|
+
],
|
|
2053
|
+
})
|
|
2054
|
+
}),
|
|
2055
|
+
)
|
|
2056
|
+
;[
|
|
2057
|
+
{
|
|
2058
|
+
label: "filename punctuation",
|
|
2059
|
+
filename: "report_v1.2?.pdf",
|
|
2060
|
+
expected: "report v1 2",
|
|
2061
|
+
duplicate: "report v1 2 2",
|
|
2062
|
+
},
|
|
2063
|
+
{
|
|
2064
|
+
label: "repeated whitespace",
|
|
2065
|
+
filename: " Quarterly\t \n report.txt",
|
|
2066
|
+
expected: "Quarterly report",
|
|
2067
|
+
duplicate: "Quarterly report 2",
|
|
2068
|
+
},
|
|
2069
|
+
{
|
|
2070
|
+
label: "allowed characters",
|
|
2071
|
+
filename: "Report - Final (v2) [2026]",
|
|
2072
|
+
expected: "Report - Final (v2) [2026]",
|
|
2073
|
+
duplicate: "Report - Final (v2) [2026] 2",
|
|
2074
|
+
},
|
|
2075
|
+
{ label: "accented filename", filename: "résumé.pdf", expected: "r sum", duplicate: "r sum 2" },
|
|
2076
|
+
{ label: "non-Latin filename", filename: "報告書.pdf", expected: "document", duplicate: "document 2" },
|
|
2077
|
+
{ label: "missing filename", filename: undefined, expected: "document", duplicate: "document 2" },
|
|
2078
|
+
{ label: "empty filename", filename: "", expected: "document", duplicate: "document 2" },
|
|
2079
|
+
{ label: "blank filename", filename: " \t\n", expected: "document", duplicate: "document 2" },
|
|
2080
|
+
{ label: "extension-only filename", filename: ".pdf", expected: "document", duplicate: "document 2" },
|
|
2081
|
+
{ label: "symbols-only filename", filename: "@@@.pdf", expected: "document", duplicate: "document 2" },
|
|
2082
|
+
{
|
|
2083
|
+
label: "overlong filename",
|
|
2084
|
+
filename: `${"a".repeat(201)}.txt`,
|
|
2085
|
+
expected: "a".repeat(200),
|
|
2086
|
+
duplicate: `${"a".repeat(198)} 2`,
|
|
2087
|
+
},
|
|
2088
|
+
{
|
|
2089
|
+
label: "maximum-length label",
|
|
2090
|
+
filename: "a".repeat(200),
|
|
2091
|
+
expected: "a".repeat(200),
|
|
2092
|
+
duplicate: `${"a".repeat(198)} 2`,
|
|
2093
|
+
},
|
|
2094
|
+
{
|
|
2095
|
+
label: "whitespace at truncation",
|
|
2096
|
+
filename: `${"a".repeat(199)} b.txt`,
|
|
2097
|
+
expected: "a".repeat(199),
|
|
2098
|
+
duplicate: `${"a".repeat(198)} 2`,
|
|
2099
|
+
},
|
|
2100
|
+
].forEach((item) => {
|
|
2101
|
+
it.effect(`normalizes ${item.label} in user and tool-result documents`, () =>
|
|
2102
|
+
Effect.gen(function* () {
|
|
2103
|
+
const request = ai.request({
|
|
2104
|
+
model,
|
|
2105
|
+
cache: "none",
|
|
2106
|
+
messages: [
|
|
2107
|
+
Message.user([
|
|
2108
|
+
{ type: "text", text: "Read this document" },
|
|
2109
|
+
{ type: "media", media: Media.base64("UERGREFUQQ==", "application/pdf"), filename: item.filename },
|
|
2110
|
+
]),
|
|
2111
|
+
Message.assistant([ToolCallPart.make({ id: "call_read", name: "read", input: {} })]),
|
|
2112
|
+
Message.tool({
|
|
2113
|
+
id: "call_read",
|
|
2114
|
+
name: "read",
|
|
2115
|
+
result: {
|
|
2116
|
+
type: "content",
|
|
2117
|
+
value: [
|
|
2118
|
+
{ type: "text", text: "Read successfully" },
|
|
2119
|
+
{
|
|
2120
|
+
type: "file",
|
|
2121
|
+
uri: "data:application/pdf;base64,UERGREFUQQ==",
|
|
2122
|
+
mime: "application/pdf",
|
|
2123
|
+
name: item.filename,
|
|
2124
|
+
},
|
|
2125
|
+
],
|
|
2126
|
+
},
|
|
2127
|
+
}),
|
|
2128
|
+
],
|
|
2129
|
+
})
|
|
2130
|
+
const original = JSON.stringify(request.messages)
|
|
2131
|
+
const first = yield* compileRequest(request)
|
|
2132
|
+
const second = yield* compileRequest(request)
|
|
2133
|
+
const expected = { format: "pdf", name: item.expected, source: { bytes: "UERGREFUQQ==" } }
|
|
2134
|
+
|
|
2135
|
+
expect(first.body.messages[0].content.find((part) => "document" in part)?.document).toEqual(expected)
|
|
2136
|
+
expect(
|
|
2137
|
+
first.body.messages[2].content[0].toolResult.content.find((part) => "document" in part)?.document,
|
|
2138
|
+
).toEqual({
|
|
2139
|
+
...expected,
|
|
2140
|
+
name: item.duplicate,
|
|
2141
|
+
})
|
|
2142
|
+
expect(second.body).toEqual(first.body)
|
|
2143
|
+
expect(JSON.stringify(request.messages)).toBe(original)
|
|
2144
|
+
}),
|
|
2145
|
+
)
|
|
2146
|
+
})
|
|
2147
|
+
|
|
2148
|
+
it.effect("keeps colliding document labels distinct within a request", () =>
|
|
2149
|
+
Effect.gen(function* () {
|
|
2150
|
+
const prepared = yield* compileRequest(
|
|
2151
|
+
ai.request({
|
|
2152
|
+
model,
|
|
2153
|
+
cache: "none",
|
|
2154
|
+
messages: [
|
|
2155
|
+
Message.user([
|
|
2156
|
+
{ type: "text", text: "Read these documents" },
|
|
2157
|
+
...["report_v1.txt", "report#v1.txt", "report v1 2.txt", "report v1.txt"].map((filename) => ({
|
|
2158
|
+
type: "media" as const,
|
|
2159
|
+
media: Media.base64("SGVsbG8=", "text/plain"),
|
|
2160
|
+
filename,
|
|
2161
|
+
})),
|
|
2162
|
+
]),
|
|
2163
|
+
],
|
|
2164
|
+
}),
|
|
2165
|
+
)
|
|
2166
|
+
expect(prepared.body.messages[0].content.slice(1)).toEqual([
|
|
2167
|
+
{ text: 'Attached file "report_v1.txt" has document label "report v1".' },
|
|
2168
|
+
{ document: { format: "txt", name: "report v1", source: { bytes: "SGVsbG8=" } } },
|
|
2169
|
+
{ text: 'Attached file "report#v1.txt" has document label "report v1 2".' },
|
|
2170
|
+
{ document: { format: "txt", name: "report v1 2", source: { bytes: "SGVsbG8=" } } },
|
|
2171
|
+
{ text: 'Attached file "report v1 2.txt" has document label "report v1 2 2".' },
|
|
2172
|
+
{ document: { format: "txt", name: "report v1 2 2", source: { bytes: "SGVsbG8=" } } },
|
|
2173
|
+
{ text: 'Attached file "report v1.txt" has document label "report v1 3".' },
|
|
2174
|
+
{ document: { format: "txt", name: "report v1 3", source: { bytes: "SGVsbG8=" } } },
|
|
2175
|
+
])
|
|
2176
|
+
}),
|
|
2177
|
+
)
|
|
2178
|
+
|
|
2179
|
+
it.effect("annotates renamed document-only messages with their original filename", () =>
|
|
2180
|
+
Effect.gen(function* () {
|
|
2181
|
+
const prepared = yield* compileRequest(
|
|
2182
|
+
ai.request({
|
|
2183
|
+
model,
|
|
2184
|
+
cache: "none",
|
|
2185
|
+
messages: [
|
|
2186
|
+
Message.user({
|
|
2187
|
+
type: "media",
|
|
2188
|
+
media: Media.base64("UERGREFUQQ==", "application/pdf"),
|
|
2189
|
+
filename: "report.pdf",
|
|
2190
|
+
}),
|
|
2191
|
+
],
|
|
2192
|
+
}),
|
|
2193
|
+
)
|
|
2194
|
+
|
|
2195
|
+
expect(prepared.body.messages).toEqual([
|
|
2196
|
+
{
|
|
2197
|
+
role: "user",
|
|
2198
|
+
content: [
|
|
2199
|
+
{ text: 'Attached file "report.pdf" has document label "report".' },
|
|
2200
|
+
{ document: { format: "pdf", name: "report", source: { bytes: "UERGREFUQQ==" } } },
|
|
2201
|
+
],
|
|
2202
|
+
},
|
|
2203
|
+
])
|
|
2204
|
+
}),
|
|
2205
|
+
)
|
|
2206
|
+
|
|
2207
|
+
it.effect("quotes original filenames in annotations and omits redundant mappings", () =>
|
|
2208
|
+
Effect.gen(function* () {
|
|
2209
|
+
const prepared = yield* compileRequest(
|
|
2210
|
+
ai.request({
|
|
2211
|
+
model,
|
|
2212
|
+
cache: "none",
|
|
2213
|
+
messages: [
|
|
2214
|
+
Message.user([
|
|
2215
|
+
{ type: "text", text: "Read these documents" },
|
|
2216
|
+
...["report", undefined, 'report "final"\n.pdf'].map((filename) => ({
|
|
2217
|
+
type: "media" as const,
|
|
2218
|
+
media: Media.base64("SGVsbG8=", "text/plain"),
|
|
2219
|
+
filename,
|
|
2220
|
+
})),
|
|
2221
|
+
]),
|
|
2222
|
+
],
|
|
2223
|
+
}),
|
|
2224
|
+
)
|
|
2225
|
+
expect(prepared.body.messages[0].content).toEqual([
|
|
2226
|
+
{ text: "Read these documents" },
|
|
2227
|
+
{ document: { format: "txt", name: "report", source: { bytes: "SGVsbG8=" } } },
|
|
2228
|
+
{ document: { format: "txt", name: "document", source: { bytes: "SGVsbG8=" } } },
|
|
2229
|
+
{ text: 'Attached file "report \\"final\\"\\n.pdf" has document label "report final".' },
|
|
2230
|
+
{ document: { format: "txt", name: "report final", source: { bytes: "SGVsbG8=" } } },
|
|
2231
|
+
])
|
|
2232
|
+
}),
|
|
2233
|
+
)
|
|
2234
|
+
|
|
2235
|
+
it.effect("lowers document media in tool results", () =>
|
|
2236
|
+
Effect.gen(function* () {
|
|
2237
|
+
const prepared = yield* compileRequest(
|
|
2238
|
+
ai.request({
|
|
2239
|
+
model,
|
|
2240
|
+
cache: "none",
|
|
2241
|
+
messages: [
|
|
2242
|
+
Message.assistant([ToolCallPart.make({ id: "call_1", name: "read", input: { path: "report.pdf" } })]),
|
|
2243
|
+
Message.tool({
|
|
2244
|
+
id: "call_1",
|
|
2245
|
+
name: "read",
|
|
2246
|
+
result: {
|
|
2247
|
+
type: "content",
|
|
2248
|
+
value: [
|
|
2249
|
+
{ type: "text", text: "Read successfully" },
|
|
2250
|
+
{
|
|
2251
|
+
type: "file",
|
|
2252
|
+
uri: "data:application/pdf;base64,UERGREFUQQ==",
|
|
2253
|
+
mime: "application/pdf",
|
|
2254
|
+
name: "report.pdf",
|
|
2255
|
+
},
|
|
2256
|
+
],
|
|
2257
|
+
},
|
|
2258
|
+
}),
|
|
2259
|
+
],
|
|
2260
|
+
}),
|
|
2261
|
+
)
|
|
2262
|
+
|
|
2263
|
+
expect(prepared.body.messages).toEqual([
|
|
2264
|
+
{
|
|
2265
|
+
role: "assistant",
|
|
2266
|
+
content: [{ toolUse: { toolUseId: "call_1", name: "read", input: { path: "report.pdf" } } }],
|
|
2267
|
+
},
|
|
2268
|
+
{
|
|
2269
|
+
role: "user",
|
|
2270
|
+
content: [
|
|
2271
|
+
{
|
|
2272
|
+
toolResult: {
|
|
2273
|
+
toolUseId: "call_1",
|
|
2274
|
+
status: "success",
|
|
2275
|
+
content: [
|
|
2276
|
+
{ text: "Read successfully" },
|
|
2277
|
+
{ text: 'Attached file "report.pdf" has document label "report".' },
|
|
2278
|
+
{ document: { format: "pdf", name: "report", source: { bytes: "UERGREFUQQ==" } } },
|
|
2279
|
+
],
|
|
2280
|
+
},
|
|
2281
|
+
},
|
|
2282
|
+
],
|
|
2283
|
+
},
|
|
2284
|
+
])
|
|
2285
|
+
}),
|
|
2286
|
+
)
|
|
2287
|
+
|
|
2288
|
+
it.effect("rejects remote media URLs in tool results", () =>
|
|
2289
|
+
Effect.gen(function* () {
|
|
2290
|
+
const error = yield* compileRequest(
|
|
2291
|
+
ai.request({
|
|
2292
|
+
model,
|
|
2293
|
+
messages: [
|
|
2294
|
+
Message.assistant([ToolCallPart.make({ id: "call_1", name: "read", input: {} })]),
|
|
2295
|
+
Message.tool({
|
|
2296
|
+
id: "call_1",
|
|
2297
|
+
name: "read",
|
|
2298
|
+
result: {
|
|
2299
|
+
type: "content",
|
|
2300
|
+
value: [
|
|
2301
|
+
{
|
|
2302
|
+
type: "file",
|
|
2303
|
+
uri: "https://example.test/report.pdf",
|
|
2304
|
+
mime: "application/pdf",
|
|
2305
|
+
name: "report.pdf",
|
|
2306
|
+
},
|
|
2307
|
+
],
|
|
2308
|
+
},
|
|
2309
|
+
}),
|
|
2310
|
+
],
|
|
2311
|
+
}),
|
|
2312
|
+
).pipe(Effect.flip)
|
|
2313
|
+
|
|
2314
|
+
expect(error).toMatchObject({ reason: { _tag: "InvalidRequest" } })
|
|
2315
|
+
expect(error.message).toContain("requires inline media")
|
|
2316
|
+
}),
|
|
2317
|
+
)
|
|
2318
|
+
|
|
2319
|
+
it.effect("rejects unsupported image media types", () =>
|
|
2320
|
+
Effect.gen(function* () {
|
|
2321
|
+
const error = yield* compileRequest(
|
|
2322
|
+
ai.request({
|
|
2323
|
+
id: "req_bad_image",
|
|
2324
|
+
model,
|
|
2325
|
+
messages: [Message.user([{ type: "media", media: Media.base64("x", "image/svg+xml") }])],
|
|
2326
|
+
}),
|
|
2327
|
+
).pipe(Effect.flip)
|
|
2328
|
+
|
|
2329
|
+
expect(error.message).toContain("Bedrock Converse does not support image media type image/svg+xml")
|
|
2330
|
+
}),
|
|
2331
|
+
)
|
|
2332
|
+
|
|
2333
|
+
it.effect("rejects unsupported document media types", () =>
|
|
2334
|
+
Effect.gen(function* () {
|
|
2335
|
+
const error = yield* compileRequest(
|
|
2336
|
+
ai.request({
|
|
2337
|
+
id: "req_bad_doc",
|
|
2338
|
+
model,
|
|
2339
|
+
messages: [
|
|
2340
|
+
Message.user([{ type: "media", media: Media.base64("x", "application/x-tar"), filename: "a.tar" }]),
|
|
2341
|
+
],
|
|
2342
|
+
}),
|
|
2343
|
+
).pipe(Effect.flip)
|
|
2344
|
+
|
|
2345
|
+
expect(error.message).toContain("Bedrock Converse does not support media type application/x-tar")
|
|
2346
|
+
}),
|
|
2347
|
+
)
|
|
2348
|
+
|
|
2349
|
+
it.effect("sends the hint ttl on cachePoint", () =>
|
|
2350
|
+
Effect.gen(function* () {
|
|
2351
|
+
const cache = new CacheHint({ type: "ephemeral", ttl: "1h" })
|
|
2352
|
+
const prepared = yield* compileRequest(
|
|
2353
|
+
ai.request({
|
|
2354
|
+
model,
|
|
2355
|
+
system: [{ type: "text", text: "system", cache }],
|
|
2356
|
+
prompt: "hi",
|
|
2357
|
+
}),
|
|
2358
|
+
)
|
|
2359
|
+
|
|
2360
|
+
expect(prepared.body).toMatchObject({
|
|
2361
|
+
system: [{ text: "system" }, { cachePoint: { type: "default", ttl: "1h" } }],
|
|
2362
|
+
})
|
|
2363
|
+
}),
|
|
2364
|
+
)
|
|
2365
|
+
|
|
2366
|
+
it.effect("appends cachePoint after marked tool definitions and tool-result blocks", () =>
|
|
2367
|
+
Effect.gen(function* () {
|
|
2368
|
+
const cache = new CacheHint({ type: "ephemeral" })
|
|
2369
|
+
const prepared = yield* compileRequest(
|
|
2370
|
+
ai.request({
|
|
2371
|
+
model,
|
|
2372
|
+
tools: [{ name: "lookup", description: "lookup", inputSchema: { type: "object", properties: {} }, cache }],
|
|
2373
|
+
messages: [
|
|
2374
|
+
Message.user("What's the weather?"),
|
|
2375
|
+
Message.assistant([ToolCallPart.make({ id: "call_1", name: "lookup", input: {} })]),
|
|
2376
|
+
Message.tool({ id: "call_1", name: "lookup", result: { temp: 72 }, cache }),
|
|
2377
|
+
],
|
|
2378
|
+
cache: "none",
|
|
2379
|
+
}),
|
|
2380
|
+
)
|
|
2381
|
+
|
|
2382
|
+
expect(prepared.body).toMatchObject({
|
|
2383
|
+
toolConfig: {
|
|
2384
|
+
tools: [{ toolSpec: { name: "lookup" } }, { cachePoint: { type: "default" } }],
|
|
2385
|
+
},
|
|
2386
|
+
messages: [
|
|
2387
|
+
{ role: "user", content: [{ text: "What's the weather?" }] },
|
|
2388
|
+
{ role: "assistant", content: [{ toolUse: { toolUseId: "call_1" } }] },
|
|
2389
|
+
{
|
|
2390
|
+
role: "user",
|
|
2391
|
+
content: [{ toolResult: { toolUseId: "call_1" } }, { cachePoint: { type: "default" } }],
|
|
2392
|
+
},
|
|
2393
|
+
],
|
|
2394
|
+
})
|
|
2395
|
+
}),
|
|
2396
|
+
)
|
|
2397
|
+
|
|
2398
|
+
it.effect("drops cachePoint markers past the 4-per-request cap", () =>
|
|
2399
|
+
Effect.gen(function* () {
|
|
2400
|
+
const cache = new CacheHint({ type: "ephemeral" })
|
|
2401
|
+
const prepared = yield* compileRequest(
|
|
2402
|
+
ai.request({
|
|
2403
|
+
model,
|
|
2404
|
+
system: [
|
|
2405
|
+
{ type: "text", text: "a", cache },
|
|
2406
|
+
{ type: "text", text: "b", cache },
|
|
2407
|
+
{ type: "text", text: "c", cache },
|
|
2408
|
+
{ type: "text", text: "d", cache },
|
|
2409
|
+
{ type: "text", text: "e", cache },
|
|
2410
|
+
{ type: "text", text: "f", cache },
|
|
2411
|
+
],
|
|
2412
|
+
prompt: "hi",
|
|
2413
|
+
}),
|
|
2414
|
+
)
|
|
2415
|
+
|
|
2416
|
+
const system = (prepared.body as { system: Array<{ cachePoint?: unknown }> }).system
|
|
2417
|
+
expect(system.filter((part) => "cachePoint" in part)).toHaveLength(4)
|
|
2418
|
+
}),
|
|
2419
|
+
)
|
|
2420
|
+
})
|
|
2421
|
+
|
|
2422
|
+
// Live recorded integration tests. Run with `RECORD=true AWS_ACCESS_KEY_ID=...
|
|
2423
|
+
// AWS_SECRET_ACCESS_KEY=... [AWS_SESSION_TOKEN=...] bun run test ...` to refresh
|
|
2424
|
+
// cassettes; replay is the default and works without credentials.
|
|
2425
|
+
//
|
|
2426
|
+
// Region is pinned to us-east-1 in tests so the request URL is stable across
|
|
2427
|
+
// machines on replay. If you need to record from a different region (e.g. your
|
|
2428
|
+
// account has access elsewhere), pass `BEDROCK_RECORDING_REGION=eu-west-1` —
|
|
2429
|
+
// but then commit the resulting cassette and others should record from the
|
|
2430
|
+
// same region too.
|
|
2431
|
+
const RECORDING_REGION = process.env.BEDROCK_RECORDING_REGION ?? "us-east-1"
|
|
2432
|
+
|
|
2433
|
+
const recordedModel = () =>
|
|
2434
|
+
AmazonBedrock.configure({
|
|
2435
|
+
// Most newer Anthropic models on Bedrock require a cross-region inference
|
|
2436
|
+
// profile (`us.` prefix). Nova does not require an Anthropic use-case form
|
|
2437
|
+
// and is on-demand-throughput accessible by default for most accounts.
|
|
2438
|
+
credentials: {
|
|
2439
|
+
region: RECORDING_REGION,
|
|
2440
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? "fixture",
|
|
2441
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? "fixture",
|
|
2442
|
+
sessionToken: process.env.AWS_SESSION_TOKEN,
|
|
2443
|
+
},
|
|
2444
|
+
}).model(process.env.BEDROCK_MODEL_ID ?? "us.amazon.nova-micro-v1:0")
|
|
2445
|
+
|
|
2446
|
+
const recorded = recordedTests({
|
|
2447
|
+
prefix: "bedrock-converse",
|
|
2448
|
+
provider: "amazon-bedrock",
|
|
2449
|
+
protocol: "bedrock-converse",
|
|
2450
|
+
requires: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
|
|
2451
|
+
})
|
|
2452
|
+
|
|
2453
|
+
describe("Bedrock Converse recorded", () => {
|
|
2454
|
+
recorded.effect("streams text", () =>
|
|
2455
|
+
Effect.gen(function* () {
|
|
2456
|
+
const llm = yield* LLMClient.Service
|
|
2457
|
+
const response = yield* llm.generate(
|
|
2458
|
+
ai.request({
|
|
2459
|
+
id: "recorded_bedrock_text",
|
|
2460
|
+
model: recordedModel(),
|
|
2461
|
+
system: "Reply with the single word 'Hello'.",
|
|
2462
|
+
prompt: "Say hello.",
|
|
2463
|
+
cache: "none",
|
|
2464
|
+
maxTokens: 16,
|
|
2465
|
+
temperature: 0,
|
|
2466
|
+
}),
|
|
2467
|
+
)
|
|
2468
|
+
|
|
2469
|
+
expect(eventSummary(response.events)).toEqual([
|
|
2470
|
+
{ type: "text", value: "Hello" },
|
|
2471
|
+
{ type: "finish", reason: "stop", usage: { inputTokens: 12, outputTokens: 2, totalTokens: 14 } },
|
|
2472
|
+
])
|
|
2473
|
+
}),
|
|
2474
|
+
)
|
|
2475
|
+
|
|
2476
|
+
recorded.effect.with("streams a tool call", { tags: ["tool"] }, () =>
|
|
2477
|
+
Effect.gen(function* () {
|
|
2478
|
+
const llm = yield* LLMClient.Service
|
|
2479
|
+
const response = yield* llm.generate(
|
|
2480
|
+
ai.request({
|
|
2481
|
+
id: "recorded_bedrock_tool_call",
|
|
2482
|
+
model: recordedModel(),
|
|
2483
|
+
system: "Call tools exactly as requested.",
|
|
2484
|
+
prompt: "Call get_weather with city exactly Paris.",
|
|
2485
|
+
tools: [weatherTool],
|
|
2486
|
+
toolChoice: ToolChoice.make(weatherTool),
|
|
2487
|
+
cache: "none",
|
|
2488
|
+
maxTokens: 80,
|
|
2489
|
+
temperature: 0,
|
|
2490
|
+
}),
|
|
2491
|
+
)
|
|
2492
|
+
|
|
2493
|
+
expect(eventSummary(response.events)).toEqual([
|
|
2494
|
+
{ type: "tool-call", name: weatherToolName, input: { city: "Paris" } },
|
|
2495
|
+
{ type: "finish", reason: "tool-calls", usage: { inputTokens: 419, outputTokens: 16, totalTokens: 435 } },
|
|
2496
|
+
])
|
|
2497
|
+
}),
|
|
2498
|
+
)
|
|
2499
|
+
|
|
2500
|
+
recorded.effect.with("drives a tool loop", { tags: ["tool", "tool-loop", "golden"] }, () =>
|
|
2501
|
+
Effect.gen(function* () {
|
|
2502
|
+
expectWeatherToolLoop(
|
|
2503
|
+
yield* runWeatherToolLoop(
|
|
2504
|
+
weatherToolLoopRequest({
|
|
2505
|
+
id: "recorded_bedrock_tool_loop",
|
|
2506
|
+
model: recordedModel(),
|
|
2507
|
+
}),
|
|
2508
|
+
),
|
|
2509
|
+
)
|
|
2510
|
+
}),
|
|
2511
|
+
)
|
|
2512
|
+
|
|
2513
|
+
recorded.effect.with("continues after parallel tool results", { tags: ["tool", "tool-loop", "parallel"] }, () =>
|
|
2514
|
+
Effect.gen(function* () {
|
|
2515
|
+
const response = yield* LLMClient.generate(
|
|
2516
|
+
ai.request({
|
|
2517
|
+
id: "recorded_bedrock_parallel_tool_results",
|
|
2518
|
+
model: recordedModel(),
|
|
2519
|
+
system: "After receiving both tool results, reply exactly: Paris is sunny; London is rainy.",
|
|
2520
|
+
messages: [
|
|
2521
|
+
Message.user("Compare the weather in Paris and London."),
|
|
2522
|
+
Message.assistant([
|
|
2523
|
+
ToolCallPart.make({ id: "weather_paris", name: weatherToolName, input: { city: "Paris" } }),
|
|
2524
|
+
ToolCallPart.make({ id: "weather_london", name: weatherToolName, input: { city: "London" } }),
|
|
2525
|
+
]),
|
|
2526
|
+
Message.tool({
|
|
2527
|
+
id: "weather_paris",
|
|
2528
|
+
name: weatherToolName,
|
|
2529
|
+
result: { temperature: 22, condition: "sunny" },
|
|
2530
|
+
}),
|
|
2531
|
+
Message.tool({
|
|
2532
|
+
id: "weather_london",
|
|
2533
|
+
name: weatherToolName,
|
|
2534
|
+
result: { temperature: 14, condition: "rainy" },
|
|
2535
|
+
}),
|
|
2536
|
+
],
|
|
2537
|
+
tools: [weatherTool],
|
|
2538
|
+
cache: "none",
|
|
2539
|
+
maxTokens: 40,
|
|
2540
|
+
temperature: 0,
|
|
2541
|
+
}),
|
|
2542
|
+
)
|
|
2543
|
+
|
|
2544
|
+
expect(response.text.trim()).toBe("Paris is sunny; London is rainy.")
|
|
2545
|
+
expect(response.finishReason?.normalized).toBe("stop")
|
|
2546
|
+
}),
|
|
2547
|
+
)
|
|
2548
|
+
})
|