@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,849 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Effect, Schema, Stream } from "effect"
|
|
3
|
+
import {
|
|
4
|
+
ai,
|
|
5
|
+
LLMEvent,
|
|
6
|
+
Message,
|
|
7
|
+
tool,
|
|
8
|
+
ToolCallPart,
|
|
9
|
+
ToolDefinition,
|
|
10
|
+
ToolNamespace,
|
|
11
|
+
type LLMRequest,
|
|
12
|
+
} from "../src/effect.js"
|
|
13
|
+
import { AI } from "../src/index.js"
|
|
14
|
+
import { Gemini } from "../src/protocols/gemini.js"
|
|
15
|
+
import { TestLLM } from "../src/testing.js"
|
|
16
|
+
import { Auth } from "../src/route.js"
|
|
17
|
+
import { compileRequest } from "../src/route/client.js"
|
|
18
|
+
import { AnthropicMessages } from "../src/protocols/anthropic-messages.js"
|
|
19
|
+
import { OpenAIChat } from "../src/protocols/openai-chat.js"
|
|
20
|
+
import { OpenAIResponses } from "../src/protocols/openai-responses.js"
|
|
21
|
+
import { gatewayProtocol } from "../src/protocols/utils/gateway-protocol.js"
|
|
22
|
+
import { GoogleVertexMessages, OpenAI } from "../src/providers.js"
|
|
23
|
+
import { planToolUpdates, type ToolUpdate } from "../src/tool-updates.js"
|
|
24
|
+
import { it, testEffect } from "./lib/effect.js"
|
|
25
|
+
import { dynamicResponse } from "./lib/http.js"
|
|
26
|
+
|
|
27
|
+
const defineTool = (name: string, description = `${name} tool`) =>
|
|
28
|
+
ToolDefinition.make({ name, description, inputSchema: { type: "object" } })
|
|
29
|
+
|
|
30
|
+
const read = defineTool("read")
|
|
31
|
+
const edit = defineTool("edit")
|
|
32
|
+
const write = defineTool("write")
|
|
33
|
+
const jira = defineTool("jira")
|
|
34
|
+
const lookup = tool({
|
|
35
|
+
name: "lookup",
|
|
36
|
+
description: "Look something up.",
|
|
37
|
+
input: Schema.Struct({ query: Schema.String }),
|
|
38
|
+
success: Schema.String,
|
|
39
|
+
execute: ({ query }) => Effect.succeed(`found ${query}`),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const ALL: ReadonlyArray<ToolUpdate> = ["add", "remove", "replace"]
|
|
43
|
+
const updates = (list: ReadonlyArray<ToolUpdate>) => ({ tools: { updates: list } })
|
|
44
|
+
|
|
45
|
+
const anthropic = (id: string, list?: ReadonlyArray<ToolUpdate>) =>
|
|
46
|
+
AnthropicMessages.route
|
|
47
|
+
.with({ endpoint: { baseURL: "https://api.anthropic.test/v1/" }, auth: Auth.header("x-api-key", "test") })
|
|
48
|
+
.model({ id, capabilities: list === undefined ? undefined : updates(list) })
|
|
49
|
+
|
|
50
|
+
const openai = (id: string, list?: ReadonlyArray<ToolUpdate>) =>
|
|
51
|
+
OpenAIResponses.route
|
|
52
|
+
.with({ endpoint: { baseURL: "https://api.openai.test/v1/" }, auth: Auth.bearer("test") })
|
|
53
|
+
.model({ id, capabilities: list === undefined ? undefined : updates(list) })
|
|
54
|
+
|
|
55
|
+
const chat = OpenAIChat.route
|
|
56
|
+
.with({ endpoint: { baseURL: "https://api.openai.test/v1/" }, auth: Auth.bearer("test") })
|
|
57
|
+
.model({ id: "gpt-4.1-mini", capabilities: updates(ALL) })
|
|
58
|
+
|
|
59
|
+
const gemini = Gemini.route
|
|
60
|
+
.with({
|
|
61
|
+
endpoint: { baseURL: "https://generativelanguage.test/v1beta/" },
|
|
62
|
+
auth: Auth.header("x-goog-api-key", "test"),
|
|
63
|
+
})
|
|
64
|
+
.model({ id: "gemini-3.5-flash", capabilities: updates(ALL) })
|
|
65
|
+
|
|
66
|
+
const opus5 = anthropic("claude-opus-5", ALL)
|
|
67
|
+
const astra = openai("gpt-6-astra", ALL)
|
|
68
|
+
|
|
69
|
+
const swap = Message.tools({ add: [write], remove: ["edit"] })
|
|
70
|
+
const conversation = [Message.user("Fix it."), Message.assistant("Done."), swap, Message.user("Next.")]
|
|
71
|
+
const folded = [Message.user("Fix it."), Message.assistant("Done."), Message.user("Next.")]
|
|
72
|
+
|
|
73
|
+
const names = (request: LLMRequest) => request.tools.map((entry) => entry.name)
|
|
74
|
+
const markers = (request: LLMRequest) =>
|
|
75
|
+
request.messages.flatMap((message) =>
|
|
76
|
+
message.role === "system" && message.tools ? [{ add: message.tools.add, remove: message.tools.remove }] : [],
|
|
77
|
+
)
|
|
78
|
+
const changes = (add: ReadonlyArray<ToolDefinition>, remove: ReadonlyArray<string> = []) => ({ add, remove })
|
|
79
|
+
|
|
80
|
+
describe("Message.tools", () => {
|
|
81
|
+
test("builds an empty system message whose tools field round-trips through the schema", () => {
|
|
82
|
+
const message = Message.make(
|
|
83
|
+
Message.tools({ add: [{ name: "write", description: "write tool", inputSchema: { type: "object" } }] }),
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
expect(message.role).toBe("system")
|
|
87
|
+
expect(message.content).toEqual([])
|
|
88
|
+
expect(message.tools).toEqual({ add: [write], remove: [] })
|
|
89
|
+
const decoded = Schema.decodeUnknownSync(Message)(Schema.encodeSync(Message)(message))
|
|
90
|
+
expect(decoded.role === "system" && decoded.tools).toEqual({ add: [write], remove: [] })
|
|
91
|
+
expect(decoded.role === "system" && decoded.tools?.add[0]).toBeInstanceOf(ToolDefinition)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test("stores definitions for tool objects and names for removals", () => {
|
|
95
|
+
const message = Message.make(Message.tools({ add: [lookup], remove: [lookup, read, "edit"] }))
|
|
96
|
+
|
|
97
|
+
expect(message.tools).toEqual({ add: [lookup._definition], remove: ["lookup", "read", "edit"] })
|
|
98
|
+
expect(Message.make(Message.system("Note.")).tools).toBeUndefined()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe("planToolUpdates", () => {
|
|
103
|
+
test("folds every marker in history order on a route without in-place changes", () => {
|
|
104
|
+
const result = planToolUpdates(
|
|
105
|
+
ai.request({
|
|
106
|
+
model: chat,
|
|
107
|
+
tools: [read, edit, lookup],
|
|
108
|
+
messages: [
|
|
109
|
+
Message.user("One."),
|
|
110
|
+
Message.tools({ add: [write, defineTool("edit", "edit v2")] }),
|
|
111
|
+
Message.user("Two."),
|
|
112
|
+
Message.tools({ remove: [lookup, "read"] }),
|
|
113
|
+
{ role: "system", content: "Tools changed.", tools: { add: [defineTool("read", "read v2")] } },
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
expect(result.tools).toEqual([defineTool("edit", "edit v2"), write, defineTool("read", "read v2")])
|
|
119
|
+
expect(result.messages).toEqual([Message.user("One."), Message.user("Two."), Message.system("Tools changed.")])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test("keeps the request identity without markers", () => {
|
|
123
|
+
const plain = ai.request({ model: opus5, tools: [read], prompt: "hi" })
|
|
124
|
+
expect(planToolUpdates(plain)).toBe(plain)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const plan = (list: ReadonlyArray<ToolUpdate> | undefined, messages: ReadonlyArray<Message | Message.Input>) =>
|
|
128
|
+
planToolUpdates(ai.request({ model: anthropic("claude-opus-5", list), tools: [read, edit], messages }))
|
|
129
|
+
const history = [
|
|
130
|
+
Message.user("One."),
|
|
131
|
+
Message.tools({ add: [jira] }),
|
|
132
|
+
Message.user("Two."),
|
|
133
|
+
Message.tools({ remove: ["edit"] }),
|
|
134
|
+
Message.user("Three."),
|
|
135
|
+
Message.tools({ add: [write] }),
|
|
136
|
+
Message.user("Four."),
|
|
137
|
+
Message.tools({ add: [defineTool("read", "read v2")] }),
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
test.each([
|
|
141
|
+
["unset", undefined, ["read", "jira", "write"], []],
|
|
142
|
+
["empty", [], ["read", "jira", "write"], []],
|
|
143
|
+
["add", ["add"], ["read", "jira", "write"], []],
|
|
144
|
+
["add + remove", ["add", "remove"], ["read", "jira", "write"], []],
|
|
145
|
+
[
|
|
146
|
+
"add + replace",
|
|
147
|
+
["add", "replace"],
|
|
148
|
+
["read", "jira"],
|
|
149
|
+
[changes([write]), changes([defineTool("read", "read v2")])],
|
|
150
|
+
],
|
|
151
|
+
["remove + replace", ["remove", "replace"], ["read", "jira", "write"], [changes([defineTool("read", "read v2")])]],
|
|
152
|
+
[
|
|
153
|
+
"all",
|
|
154
|
+
ALL,
|
|
155
|
+
["read", "edit"],
|
|
156
|
+
[changes([jira]), changes([], ["edit"]), changes([write]), changes([defineTool("read", "read v2")])],
|
|
157
|
+
],
|
|
158
|
+
] as const)("with updates %s, folds up to the last marker the model can't take in place", (_, list, tools, kept) => {
|
|
159
|
+
const result = plan(list, history)
|
|
160
|
+
expect(names(result)).toEqual([...tools])
|
|
161
|
+
expect(markers(result)).toEqual([...kept])
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test("keeps additions after the last removal in place when only additions are supported", () => {
|
|
165
|
+
const result = plan(["add"], history.slice(0, 6))
|
|
166
|
+
expect(names(result)).toEqual(["read", "jira"])
|
|
167
|
+
expect(markers(result)).toEqual([changes([write])])
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test("counts adding a tool removed earlier as a replacement", () => {
|
|
171
|
+
const result = plan(
|
|
172
|
+
["add", "remove"],
|
|
173
|
+
[Message.user("One."), Message.tools({ remove: ["edit"] }), Message.user("Two."), Message.tools({ add: [edit] })],
|
|
174
|
+
)
|
|
175
|
+
expect(names(result)).toEqual(["read", "edit"])
|
|
176
|
+
expect(markers(result)).toEqual([])
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test("treats removing and adding the same name in one marker as a replacement", () => {
|
|
180
|
+
const v2 = defineTool("edit", "edit v2")
|
|
181
|
+
const messages = [Message.user("One."), Message.tools({ add: [v2], remove: ["edit"] })]
|
|
182
|
+
expect(markers(plan(["replace"], messages))).toEqual([changes([v2])])
|
|
183
|
+
expect(markers(plan(["remove"], messages))).toEqual([])
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test("drops removals of unknown names and markers that change nothing", () => {
|
|
187
|
+
const result = plan(ALL, [
|
|
188
|
+
Message.user("One."),
|
|
189
|
+
Message.tools({ remove: ["ghost", "edit"] }),
|
|
190
|
+
Message.tools({ remove: ["ghost"] }),
|
|
191
|
+
Message.tools({}),
|
|
192
|
+
])
|
|
193
|
+
expect(names(result)).toEqual(["read", "edit"])
|
|
194
|
+
expect(result.messages.map((message) => message.role)).toEqual(["user", "system"])
|
|
195
|
+
expect(markers(result)).toEqual([changes([], ["edit"])])
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
test("folds markers before the conversation starts into the leading declaration", () => {
|
|
199
|
+
const result = plan(ALL, [Message.tools({ add: [jira], remove: ["read"] }), Message.user("One.")])
|
|
200
|
+
expect(names(result)).toEqual(["edit", "jira"])
|
|
201
|
+
expect(result.messages).toEqual([Message.user("One.")])
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test("counts redefining a namespace without some of its tools as a removal", () => {
|
|
205
|
+
const namespace = (...tools: ReadonlyArray<ToolDefinition>) => ToolNamespace.make({ name: "jira", tools })
|
|
206
|
+
const request = (list: ReadonlyArray<ToolUpdate>) =>
|
|
207
|
+
planToolUpdates(
|
|
208
|
+
ai.request({
|
|
209
|
+
model: anthropic("claude-opus-5", list),
|
|
210
|
+
tools: [namespace(read, edit)],
|
|
211
|
+
messages: [Message.user("One."), Message.tools({ add: [namespace(read)] })],
|
|
212
|
+
}),
|
|
213
|
+
)
|
|
214
|
+
expect(markers(request(["add", "replace"]))).toEqual([])
|
|
215
|
+
expect(markers(request(ALL))).toHaveLength(1)
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
describe("leading declaration", () => {
|
|
220
|
+
const routes = [
|
|
221
|
+
["OpenAI Chat", chat],
|
|
222
|
+
["Gemini", gemini],
|
|
223
|
+
["Anthropic without updates", anthropic("claude-opus-5")],
|
|
224
|
+
["Anthropic", opus5],
|
|
225
|
+
["OpenAI Responses without updates", openai("gpt-6-astra")],
|
|
226
|
+
["OpenAI Responses", astra],
|
|
227
|
+
] as const
|
|
228
|
+
|
|
229
|
+
it.effect("top-level tools compile the same as a Message.tools marker that leads the history", () =>
|
|
230
|
+
Effect.gen(function* () {
|
|
231
|
+
for (const [, model] of routes) {
|
|
232
|
+
const direct = yield* compileRequest(
|
|
233
|
+
ai.request({ model, tools: [read, edit], messages: conversation, cache: "none" }),
|
|
234
|
+
)
|
|
235
|
+
const leading = yield* compileRequest(
|
|
236
|
+
ai.request({ model, messages: [Message.tools({ add: [read, edit] }), ...conversation], cache: "none" }),
|
|
237
|
+
)
|
|
238
|
+
expect(leading.body).toEqual(direct.body)
|
|
239
|
+
}
|
|
240
|
+
}),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
it.effect("folding every marker matches listing the final tools up front, with no empty system message", () =>
|
|
244
|
+
Effect.gen(function* () {
|
|
245
|
+
for (const model of [chat, gemini, anthropic("claude-opus-5"), openai("gpt-6-astra")]) {
|
|
246
|
+
const withMarkers = yield* compileRequest(
|
|
247
|
+
ai.request({ model, tools: [read, edit], messages: conversation, cache: "none" }),
|
|
248
|
+
)
|
|
249
|
+
const withoutMarkers = yield* compileRequest(
|
|
250
|
+
ai.request({ model, tools: [read, write], messages: folded, cache: "none" }),
|
|
251
|
+
)
|
|
252
|
+
expect(withMarkers.body).toEqual(withoutMarkers.body)
|
|
253
|
+
}
|
|
254
|
+
}),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
it.effect("tool objects send the same definition from top-level tools and Message.tools", () =>
|
|
258
|
+
Effect.gen(function* () {
|
|
259
|
+
const added = yield* compileRequest(
|
|
260
|
+
ai.request({ model: chat, tools: [read], messages: [Message.user("Go."), Message.tools({ add: [lookup] })] }),
|
|
261
|
+
)
|
|
262
|
+
const direct = yield* compileRequest(ai.request({ model: chat, tools: [read, lookup], prompt: "Go." }))
|
|
263
|
+
|
|
264
|
+
expect(added.body).toEqual(direct.body)
|
|
265
|
+
}),
|
|
266
|
+
)
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
describe("ai.loop", () => {
|
|
270
|
+
const loopIt = testEffect(TestLLM.testLayer())
|
|
271
|
+
|
|
272
|
+
loopIt.effect("runs an executable tool added mid-conversation and not one removed later", () =>
|
|
273
|
+
Effect.gen(function* () {
|
|
274
|
+
const client = yield* TestLLM.Test
|
|
275
|
+
yield* client.push(
|
|
276
|
+
TestLLM.toolCalls(
|
|
277
|
+
LLMEvent.toolCall({ id: "call-1", name: "lookup", input: { query: "weather" } }),
|
|
278
|
+
LLMEvent.toolCall({ id: "call-2", name: "remove_me", input: {} }),
|
|
279
|
+
),
|
|
280
|
+
TestLLM.text("Done.", "text-1"),
|
|
281
|
+
)
|
|
282
|
+
const removeMe = AI.tool({
|
|
283
|
+
name: "remove_me",
|
|
284
|
+
description: "Removed before the model calls it.",
|
|
285
|
+
input: Schema.Struct({}),
|
|
286
|
+
execute: () => "ran",
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
const events = yield* ai
|
|
290
|
+
.loop({
|
|
291
|
+
model: chat,
|
|
292
|
+
tools: [removeMe],
|
|
293
|
+
messages: [Message.user("Look it up."), Message.tools({ add: [lookup], remove: [removeMe] })],
|
|
294
|
+
})
|
|
295
|
+
.pipe(Stream.runCollect)
|
|
296
|
+
const requests = yield* client.requests()
|
|
297
|
+
|
|
298
|
+
expect(requests[0].tools.map((entry) => entry.name)).toEqual(["remove_me"])
|
|
299
|
+
expect(requests[0].messages[1]).toEqual(Message.make(Message.tools({ add: [lookup], remove: ["remove_me"] })))
|
|
300
|
+
expect(Array.from(events).filter(LLMEvent.is.toolResult)).toEqual([
|
|
301
|
+
expect.objectContaining({ id: "call-1", result: { type: "text", value: "found weather" } }),
|
|
302
|
+
expect.objectContaining({ id: "call-2", result: expect.objectContaining({ type: "error" }) }),
|
|
303
|
+
])
|
|
304
|
+
}),
|
|
305
|
+
)
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
describe("protocol wrappers", () => {
|
|
309
|
+
test("forward the tool update encoding", () => {
|
|
310
|
+
const wrapped = gatewayProtocol(AnthropicMessages.protocol, {
|
|
311
|
+
id: "gateway-anthropic",
|
|
312
|
+
prepare: (request) => Effect.succeed({ request, body: {} }),
|
|
313
|
+
})
|
|
314
|
+
expect(wrapped.toolUpdates).toBe(AnthropicMessages.protocol.toolUpdates)
|
|
315
|
+
|
|
316
|
+
const vertex = GoogleVertexMessages.configure({ accessToken: "test", location: "global", project: "test" })
|
|
317
|
+
expect(vertex.model("claude-opus-5").route.toolUpdates).toBe(AnthropicMessages.protocol.toolUpdates)
|
|
318
|
+
})
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
describe("cache policy", () => {
|
|
322
|
+
it.effect("walks the tail breakpoint back past a trailing tools marker", () =>
|
|
323
|
+
Effect.gen(function* () {
|
|
324
|
+
const prepared = yield* compileRequest(
|
|
325
|
+
ai.request({
|
|
326
|
+
model: opus5,
|
|
327
|
+
tools: [read, edit],
|
|
328
|
+
messages: [Message.user("first"), Message.assistant("reply"), Message.user("latest"), swap],
|
|
329
|
+
cache: { messages: { tail: 1 } },
|
|
330
|
+
}),
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
expect(prepared.body.messages.at(-2)).toEqual({
|
|
334
|
+
role: "user",
|
|
335
|
+
content: [{ type: "text", text: "latest", cache_control: { type: "ephemeral" } }],
|
|
336
|
+
})
|
|
337
|
+
expect(prepared.body.messages.at(-1)?.role).toBe("system")
|
|
338
|
+
}),
|
|
339
|
+
)
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
describe("Anthropic Messages tool updates", () => {
|
|
343
|
+
const definition = (value: ToolDefinition) => ({
|
|
344
|
+
type: "tool_addition",
|
|
345
|
+
tool: {
|
|
346
|
+
type: "tool_definition",
|
|
347
|
+
definition: { name: value.name, description: value.description, input_schema: value.inputSchema },
|
|
348
|
+
},
|
|
349
|
+
})
|
|
350
|
+
const removal = (name: string) => ({ type: "tool_removal", tool: { type: "tool_reference", name } })
|
|
351
|
+
|
|
352
|
+
it.effect("lowers markers to native system messages and keeps the top-level tools", () =>
|
|
353
|
+
Effect.gen(function* () {
|
|
354
|
+
const prepared = yield* compileRequest(
|
|
355
|
+
ai.request({ model: opus5, tools: [read, edit], messages: conversation, cache: "none" }),
|
|
356
|
+
)
|
|
357
|
+
const plain = yield* compileRequest(
|
|
358
|
+
ai.request({ model: opus5, tools: [read, write], prompt: "x", cache: "none" }),
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
expect(prepared.body.tools?.map((entry) => entry.name)).toEqual(["read", "edit"])
|
|
362
|
+
expect(prepared.body.messages).toEqual([
|
|
363
|
+
{ role: "user", content: [{ type: "text", text: "Fix it." }] },
|
|
364
|
+
{ role: "assistant", content: [{ type: "text", text: "Done." }] },
|
|
365
|
+
{ role: "user", content: [{ type: "text", text: "Next." }] },
|
|
366
|
+
{ role: "system", content: [definition(write), removal("edit")] },
|
|
367
|
+
])
|
|
368
|
+
const addition = prepared.body.messages[3]?.content[0]
|
|
369
|
+
expect(addition?.type === "tool_addition" && addition.tool.definition).toEqual(plain.body.tools?.[1])
|
|
370
|
+
}),
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
it.effect("redefines a tool with a same-name addition and re-adds a removed one", () =>
|
|
374
|
+
Effect.gen(function* () {
|
|
375
|
+
const v2 = defineTool("edit", "edit v2")
|
|
376
|
+
const prepared = yield* compileRequest(
|
|
377
|
+
ai.request({
|
|
378
|
+
model: opus5,
|
|
379
|
+
tools: [read, edit],
|
|
380
|
+
messages: [
|
|
381
|
+
Message.user("One."),
|
|
382
|
+
Message.tools({ add: [v2] }),
|
|
383
|
+
Message.user("Two."),
|
|
384
|
+
Message.tools({ remove: ["read"] }),
|
|
385
|
+
Message.user("Three."),
|
|
386
|
+
Message.tools({ add: [read] }),
|
|
387
|
+
],
|
|
388
|
+
cache: "none",
|
|
389
|
+
}),
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
expect(prepared.body.tools?.map((entry) => entry.name)).toEqual(["read", "edit"])
|
|
393
|
+
expect(prepared.body.messages.filter((message) => message.role === "system")).toEqual([
|
|
394
|
+
{ role: "system", content: [definition(v2)] },
|
|
395
|
+
{ role: "system", content: [removal("read")] },
|
|
396
|
+
{ role: "system", content: [definition(read)] },
|
|
397
|
+
])
|
|
398
|
+
}),
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
it.effect("removes the tools a redefined namespace leaves out", () =>
|
|
402
|
+
Effect.gen(function* () {
|
|
403
|
+
const prepared = yield* compileRequest(
|
|
404
|
+
ai.request({
|
|
405
|
+
model: opus5,
|
|
406
|
+
tools: [ToolNamespace.make({ name: "jira", tools: [read, edit] })],
|
|
407
|
+
messages: [
|
|
408
|
+
Message.user("One."),
|
|
409
|
+
Message.tools({ add: [ToolNamespace.make({ name: "jira", tools: [read] })] }),
|
|
410
|
+
],
|
|
411
|
+
cache: "none",
|
|
412
|
+
}),
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
expect(prepared.body.messages.at(-1)).toEqual({
|
|
416
|
+
role: "system",
|
|
417
|
+
content: [definition(defineTool("jira_read", "read tool")), removal("jira_edit")],
|
|
418
|
+
})
|
|
419
|
+
}),
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
it.effect("adds tools in place with no top-level tools and keeps tool_choice", () =>
|
|
423
|
+
Effect.gen(function* () {
|
|
424
|
+
const prepared = yield* compileRequest(
|
|
425
|
+
ai.request({
|
|
426
|
+
model: opus5,
|
|
427
|
+
messages: [Message.user("Go."), Message.tools({ add: [jira] })],
|
|
428
|
+
toolChoice: { type: "tool", name: "jira" },
|
|
429
|
+
cache: "none",
|
|
430
|
+
}),
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
expect(prepared.body.tools).toBeUndefined()
|
|
434
|
+
expect(prepared.body.tool_choice).toEqual({ type: "tool", name: "jira" })
|
|
435
|
+
expect(prepared.body.messages.at(-1)).toEqual({ role: "system", content: [definition(jira)] })
|
|
436
|
+
}),
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
it.effect("folds markers that no user message or tool result would precede, keeping later ones in place", () =>
|
|
440
|
+
Effect.gen(function* () {
|
|
441
|
+
const prepared = yield* compileRequest(
|
|
442
|
+
ai.request({
|
|
443
|
+
model: opus5,
|
|
444
|
+
tools: [read, edit],
|
|
445
|
+
messages: [
|
|
446
|
+
Message.user("Fix it."),
|
|
447
|
+
Message.assistant("Done."),
|
|
448
|
+
swap,
|
|
449
|
+
Message.assistant("More."),
|
|
450
|
+
Message.user("Next."),
|
|
451
|
+
Message.tools({ add: [jira] }),
|
|
452
|
+
],
|
|
453
|
+
cache: "none",
|
|
454
|
+
}),
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
expect(prepared.body.tools?.map((entry) => entry.name)).toEqual(["read", "write"])
|
|
458
|
+
expect(prepared.body.messages.at(-1)).toEqual({ role: "system", content: [definition(jira)] })
|
|
459
|
+
expect(prepared.body.messages.filter((message) => message.role === "system")).toHaveLength(1)
|
|
460
|
+
}),
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
it.effect("sends several removals as blocks in one message and nothing for unknown names", () =>
|
|
464
|
+
Effect.gen(function* () {
|
|
465
|
+
const prepared = yield* compileRequest(
|
|
466
|
+
ai.request({
|
|
467
|
+
model: opus5,
|
|
468
|
+
tools: [read, edit, write],
|
|
469
|
+
messages: [Message.user("Go."), Message.tools({ remove: ["read", "ghost", "write"] })],
|
|
470
|
+
cache: "none",
|
|
471
|
+
}),
|
|
472
|
+
)
|
|
473
|
+
const unknown = yield* compileRequest(
|
|
474
|
+
ai.request({
|
|
475
|
+
model: opus5,
|
|
476
|
+
tools: [read],
|
|
477
|
+
messages: [Message.user("Go."), Message.tools({ remove: ["ghost"] })],
|
|
478
|
+
cache: "none",
|
|
479
|
+
}),
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
expect(prepared.body.messages.at(-1)).toEqual({ role: "system", content: [removal("read"), removal("write")] })
|
|
483
|
+
expect(unknown.body.messages).toEqual([{ role: "user", content: [{ type: "text", text: "Go." }] }])
|
|
484
|
+
}),
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
it.effect("moves a marker between a tool call and its result after the result", () =>
|
|
488
|
+
Effect.gen(function* () {
|
|
489
|
+
const prepared = yield* compileRequest(
|
|
490
|
+
ai.request({
|
|
491
|
+
model: opus5,
|
|
492
|
+
tools: [read, edit],
|
|
493
|
+
messages: [
|
|
494
|
+
Message.user("Read it."),
|
|
495
|
+
Message.assistant([ToolCallPart.make({ id: "call_1", name: "read", input: {} })]),
|
|
496
|
+
Message.tools({ add: [write] }),
|
|
497
|
+
Message.tool({ id: "call_1", name: "read", result: { ok: true } }),
|
|
498
|
+
],
|
|
499
|
+
cache: "none",
|
|
500
|
+
}),
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
expect(prepared.body.messages).toEqual([
|
|
504
|
+
{ role: "user", content: [{ type: "text", text: "Read it." }] },
|
|
505
|
+
{ role: "assistant", content: [{ type: "tool_use", id: "call_1", name: "read", input: {} }] },
|
|
506
|
+
{ role: "user", content: [{ type: "tool_result", tool_use_id: "call_1", content: '{"ok":true}' }] },
|
|
507
|
+
{ role: "system", content: [definition(write)] },
|
|
508
|
+
])
|
|
509
|
+
}),
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
it.effect("requests the inline tools beta only when markers are sent", () =>
|
|
513
|
+
Effect.gen(function* () {
|
|
514
|
+
for (const [messages, expected] of [
|
|
515
|
+
[conversation, true],
|
|
516
|
+
[folded, false],
|
|
517
|
+
] as const) {
|
|
518
|
+
const request = ai.request({ model: opus5, tools: [read, edit], messages })
|
|
519
|
+
const compiled = yield* compileRequest(request)
|
|
520
|
+
const prepared = yield* AnthropicMessages.route.prepareTransport(compiled.body, request)
|
|
521
|
+
expect(prepared.request.headers["anthropic-beta"]!.split(",").includes("inline-tools-2026-09-15")).toBe(
|
|
522
|
+
expected,
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
}),
|
|
526
|
+
)
|
|
527
|
+
|
|
528
|
+
it.effect("folds markers when the model lacks updates or system updates", () =>
|
|
529
|
+
Effect.gen(function* () {
|
|
530
|
+
for (const model of [anthropic("claude-opus-5"), anthropic("claude-opus-4-5", ALL)]) {
|
|
531
|
+
const prepared = yield* compileRequest(
|
|
532
|
+
ai.request({ model, tools: [read, edit], messages: conversation, cache: "none" }),
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
expect(prepared.body.messages.some((message) => message.role === "system")).toBe(false)
|
|
536
|
+
expect(prepared.body.tools?.map((entry) => entry.name)).toEqual(["read", "write"])
|
|
537
|
+
}
|
|
538
|
+
}),
|
|
539
|
+
)
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
describe("OpenAI Responses tool updates", () => {
|
|
543
|
+
const additional = (body: OpenAIResponses.OpenAIResponsesBody) =>
|
|
544
|
+
body.input.flatMap((item) =>
|
|
545
|
+
"type" in item && item.type === "additional_tools"
|
|
546
|
+
? [item.tools.map((entry) => ("description" in entry ? `${entry.name}: ${entry.description}` : entry.type))]
|
|
547
|
+
: [],
|
|
548
|
+
)
|
|
549
|
+
const topLevel = (body: OpenAIResponses.OpenAIResponsesBody) =>
|
|
550
|
+
body.tools?.map((entry) => ("name" in entry ? entry.name : entry.type))
|
|
551
|
+
// One line per input item: declared tools, developer text, or the item type.
|
|
552
|
+
const trace = (body: OpenAIResponses.OpenAIResponsesBody) =>
|
|
553
|
+
body.input.map((item) => {
|
|
554
|
+
if ("type" in item && item.type === "additional_tools")
|
|
555
|
+
return `tools: ${item.tools.map((entry) => ("name" in entry ? entry.name : entry.type)).join(", ")}`
|
|
556
|
+
if ("role" in item && item.role === "developer" && typeof item.content === "string") return item.content
|
|
557
|
+
return "role" in item ? item.role : item.type
|
|
558
|
+
})
|
|
559
|
+
const hint = (...unavailable: ReadonlyArray<string>) =>
|
|
560
|
+
[
|
|
561
|
+
"Tool update: the tools below are added to the ones you already have. Earlier tools stay available unless marked unavailable, and a tool declared again replaces its earlier definition.",
|
|
562
|
+
...(unavailable.length === 0 ? [] : [`Still unavailable: ${unavailable.join(", ")}.`]),
|
|
563
|
+
].join("\n")
|
|
564
|
+
|
|
565
|
+
it.effect("declares every tool in a leading additional_tools item and leaves top-level tools out", () =>
|
|
566
|
+
Effect.gen(function* () {
|
|
567
|
+
const prepared = yield* compileRequest(ai.request({ model: astra, tools: [read, edit], prompt: "Go." }))
|
|
568
|
+
const plain = yield* compileRequest(
|
|
569
|
+
ai.request({ model: openai("gpt-6-astra"), tools: [read, edit], prompt: "Go." }),
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
expect(prepared.body.tools).toBeUndefined()
|
|
573
|
+
expect(prepared.body.input).toEqual([
|
|
574
|
+
{ type: "additional_tools", role: "developer", tools: plain.body.tools },
|
|
575
|
+
{ type: "message", role: "user", content: [{ type: "input_text", text: "Go." }] },
|
|
576
|
+
])
|
|
577
|
+
expect(additional(plain.body)).toEqual([])
|
|
578
|
+
}),
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
it.effect("adds and redefines tools with later items, each after an incremental hint", () =>
|
|
582
|
+
Effect.gen(function* () {
|
|
583
|
+
const prepared = yield* compileRequest(
|
|
584
|
+
ai.request({
|
|
585
|
+
model: astra,
|
|
586
|
+
tools: [read, edit],
|
|
587
|
+
messages: [
|
|
588
|
+
Message.user("Fix it."),
|
|
589
|
+
Message.tools({ add: [write] }),
|
|
590
|
+
Message.user("Next."),
|
|
591
|
+
Message.tools({ add: [defineTool("edit", "edit v2")] }),
|
|
592
|
+
],
|
|
593
|
+
}),
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
expect(prepared.body.tools).toBeUndefined()
|
|
597
|
+
expect(additional(prepared.body)).toEqual([
|
|
598
|
+
["read: read tool", "edit: edit tool"],
|
|
599
|
+
["write: write tool"],
|
|
600
|
+
["edit: edit v2"],
|
|
601
|
+
])
|
|
602
|
+
expect(trace(prepared.body)).toEqual([
|
|
603
|
+
"tools: read, edit",
|
|
604
|
+
"user",
|
|
605
|
+
hint(),
|
|
606
|
+
"tools: write",
|
|
607
|
+
"user",
|
|
608
|
+
hint(),
|
|
609
|
+
"tools: edit",
|
|
610
|
+
])
|
|
611
|
+
}),
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
it.effect("sends the first item without a hint when no tools lead the request", () =>
|
|
615
|
+
Effect.gen(function* () {
|
|
616
|
+
const prepared = yield* compileRequest(
|
|
617
|
+
ai.request({
|
|
618
|
+
model: astra,
|
|
619
|
+
messages: [
|
|
620
|
+
Message.user("Go."),
|
|
621
|
+
Message.tools({ add: [jira] }),
|
|
622
|
+
Message.user("More."),
|
|
623
|
+
Message.tools({ add: [write] }),
|
|
624
|
+
],
|
|
625
|
+
}),
|
|
626
|
+
)
|
|
627
|
+
|
|
628
|
+
expect(trace(prepared.body)).toEqual(["user", "tools: jira", "user", hint(), "tools: write"])
|
|
629
|
+
}),
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
it.effect("announces removals, lists them in later hints until re-added, and keeps them declared", () =>
|
|
633
|
+
Effect.gen(function* () {
|
|
634
|
+
const prepared = yield* compileRequest(
|
|
635
|
+
ai.request({
|
|
636
|
+
model: astra,
|
|
637
|
+
tools: [read, edit, write],
|
|
638
|
+
messages: [
|
|
639
|
+
Message.user("One."),
|
|
640
|
+
Message.tools({ remove: ["edit", "write"] }),
|
|
641
|
+
Message.user("Two."),
|
|
642
|
+
Message.tools({ add: [jira] }),
|
|
643
|
+
Message.user("Three."),
|
|
644
|
+
Message.tools({ add: [edit] }),
|
|
645
|
+
],
|
|
646
|
+
}),
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
expect(trace(prepared.body)).toEqual([
|
|
650
|
+
"tools: read, edit, write",
|
|
651
|
+
"user",
|
|
652
|
+
"These tools are no longer available. Do not call them: edit, write.",
|
|
653
|
+
"user",
|
|
654
|
+
hint("edit", "write"),
|
|
655
|
+
"tools: jira",
|
|
656
|
+
"user",
|
|
657
|
+
hint("write"),
|
|
658
|
+
"tools: edit",
|
|
659
|
+
])
|
|
660
|
+
}),
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
it.effect("sends a redefinition and a removal in one marker as an item and an announcement", () =>
|
|
664
|
+
Effect.gen(function* () {
|
|
665
|
+
const prepared = yield* compileRequest(
|
|
666
|
+
ai.request({
|
|
667
|
+
model: astra,
|
|
668
|
+
tools: [read, edit],
|
|
669
|
+
messages: [Message.user("One."), Message.tools({ add: [defineTool("read", "read v2")], remove: ["edit"] })],
|
|
670
|
+
}),
|
|
671
|
+
)
|
|
672
|
+
|
|
673
|
+
expect(trace(prepared.body)).toEqual([
|
|
674
|
+
"tools: read, edit",
|
|
675
|
+
"user",
|
|
676
|
+
hint(),
|
|
677
|
+
"tools: read",
|
|
678
|
+
"These tools are no longer available. Do not call them: edit.",
|
|
679
|
+
])
|
|
680
|
+
}),
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
it.effect("folds removals when the model doesn't list remove", () =>
|
|
684
|
+
Effect.gen(function* () {
|
|
685
|
+
const prepared = yield* compileRequest(
|
|
686
|
+
ai.request({
|
|
687
|
+
model: openai("gpt-6-astra", ["add", "replace"]),
|
|
688
|
+
tools: [read, edit],
|
|
689
|
+
messages: [...conversation, Message.tools({ add: [jira] })],
|
|
690
|
+
}),
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
expect(trace(prepared.body)).toEqual(["tools: read, write", "user", "assistant", "user", hint(), "tools: jira"])
|
|
694
|
+
}),
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
it.effect("folds redefinitions when the model lists replace without add", () =>
|
|
698
|
+
Effect.gen(function* () {
|
|
699
|
+
const prepared = yield* compileRequest(
|
|
700
|
+
ai.request({
|
|
701
|
+
model: openai("gpt-6-astra", ["replace"]),
|
|
702
|
+
tools: [read, edit],
|
|
703
|
+
messages: [Message.user("Go."), Message.tools({ add: [defineTool("edit", "edit v2")] })],
|
|
704
|
+
}),
|
|
705
|
+
)
|
|
706
|
+
|
|
707
|
+
expect(additional(prepared.body)).toEqual([])
|
|
708
|
+
expect(prepared.body.tools?.map((entry) => ("description" in entry ? entry.description : entry.type))).toEqual([
|
|
709
|
+
"read tool",
|
|
710
|
+
"edit v2",
|
|
711
|
+
])
|
|
712
|
+
}),
|
|
713
|
+
)
|
|
714
|
+
|
|
715
|
+
it.effect("folds redefinitions when the model only lists add", () =>
|
|
716
|
+
Effect.gen(function* () {
|
|
717
|
+
const prepared = yield* compileRequest(
|
|
718
|
+
ai.request({
|
|
719
|
+
model: openai("gpt-6-astra", ["add"]),
|
|
720
|
+
tools: [read, edit],
|
|
721
|
+
messages: [Message.user("Go."), Message.tools({ add: [defineTool("edit", "edit v2"), jira] })],
|
|
722
|
+
}),
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
expect(additional(prepared.body)).toEqual([["read: read tool", "edit: edit v2", "jira: jira tool"]])
|
|
726
|
+
}),
|
|
727
|
+
)
|
|
728
|
+
|
|
729
|
+
it.effect("keeps hosted tools top-level and folds changes to them", () =>
|
|
730
|
+
Effect.gen(function* () {
|
|
731
|
+
const image = OpenAI.imageGeneration()
|
|
732
|
+
const prepared = yield* compileRequest(ai.request({ model: astra, tools: [read, image], prompt: "Go." }))
|
|
733
|
+
const added = yield* compileRequest(
|
|
734
|
+
ai.request({
|
|
735
|
+
model: astra,
|
|
736
|
+
tools: [read],
|
|
737
|
+
messages: [Message.user("Go."), Message.tools({ add: [image] })],
|
|
738
|
+
}),
|
|
739
|
+
)
|
|
740
|
+
|
|
741
|
+
expect(topLevel(prepared.body)).toEqual(["image_generation"])
|
|
742
|
+
expect(additional(prepared.body)).toEqual([["read: read tool"]])
|
|
743
|
+
expect(topLevel(added.body)).toEqual(["image_generation"])
|
|
744
|
+
expect(additional(added.body)).toEqual([["read: read tool"]])
|
|
745
|
+
}),
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
it.effect("keeps tool_choice for tools declared only in additional_tools", () =>
|
|
749
|
+
Effect.gen(function* () {
|
|
750
|
+
const prepared = yield* compileRequest(
|
|
751
|
+
ai.request({ model: astra, tools: [read], toolChoice: { type: "tool", name: "read" }, prompt: "Go." }),
|
|
752
|
+
)
|
|
753
|
+
const added = yield* compileRequest(
|
|
754
|
+
ai.request({
|
|
755
|
+
model: astra,
|
|
756
|
+
messages: [Message.user("Go."), Message.tools({ add: [jira] })],
|
|
757
|
+
toolChoice: "required",
|
|
758
|
+
}),
|
|
759
|
+
)
|
|
760
|
+
|
|
761
|
+
expect(prepared.body.tool_choice).toEqual({ type: "function", name: "read" })
|
|
762
|
+
expect(added.body.tool_choice).toBe("required")
|
|
763
|
+
expect(additional(added.body)).toEqual([["jira: jira tool"]])
|
|
764
|
+
}),
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
it.effect("sends a marker's own text after its tool changes", () =>
|
|
768
|
+
Effect.gen(function* () {
|
|
769
|
+
const prepared = yield* compileRequest(
|
|
770
|
+
ai.request({
|
|
771
|
+
model: astra,
|
|
772
|
+
tools: [read],
|
|
773
|
+
messages: [Message.user("Go."), { role: "system", content: "Use jira now.", tools: { add: [jira] } }],
|
|
774
|
+
}),
|
|
775
|
+
)
|
|
776
|
+
|
|
777
|
+
expect(trace(prepared.body)).toEqual(["tools: read", "user", hint(), "tools: jira", "Use jira now."])
|
|
778
|
+
}),
|
|
779
|
+
)
|
|
780
|
+
|
|
781
|
+
it.effect("adds freeform tools as custom tools and replays their calls as custom tool calls", () =>
|
|
782
|
+
Effect.gen(function* () {
|
|
783
|
+
const run = ToolDefinition.make({
|
|
784
|
+
name: "run",
|
|
785
|
+
description: "Run code",
|
|
786
|
+
inputSchema: { type: "object", properties: { code: { type: "string" } }, required: ["code"] },
|
|
787
|
+
freeform: { type: "text" },
|
|
788
|
+
})
|
|
789
|
+
const prepared = yield* compileRequest(
|
|
790
|
+
ai.request({
|
|
791
|
+
model: astra,
|
|
792
|
+
tools: [read],
|
|
793
|
+
messages: [
|
|
794
|
+
Message.user("Run it."),
|
|
795
|
+
Message.tools({ add: [run] }),
|
|
796
|
+
Message.assistant([ToolCallPart.make({ id: "call_1", name: "run", input: { code: "ls" } })]),
|
|
797
|
+
Message.tool({ id: "call_1", name: "run", result: "ok" }),
|
|
798
|
+
],
|
|
799
|
+
}),
|
|
800
|
+
)
|
|
801
|
+
const plain = yield* compileRequest(ai.request({ model: openai("gpt-6-astra"), tools: [read, run], prompt: "x" }))
|
|
802
|
+
|
|
803
|
+
expect(prepared.body.input[3]).toEqual({
|
|
804
|
+
type: "additional_tools",
|
|
805
|
+
role: "developer",
|
|
806
|
+
tools: [plain.body.tools?.[1]],
|
|
807
|
+
})
|
|
808
|
+
expect(plain.body.tools?.[1]?.type).toBe("custom")
|
|
809
|
+
expect(prepared.body.input[4]).toEqual({ type: "custom_tool_call", call_id: "call_1", name: "run", input: "ls" })
|
|
810
|
+
}),
|
|
811
|
+
)
|
|
812
|
+
|
|
813
|
+
it.effect("keeps top-level tools and folds markers without updates", () =>
|
|
814
|
+
Effect.gen(function* () {
|
|
815
|
+
const prepared = yield* compileRequest(
|
|
816
|
+
ai.request({ model: openai("gpt-6-astra"), tools: [read, edit], messages: conversation }),
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
expect(additional(prepared.body)).toEqual([])
|
|
820
|
+
expect(topLevel(prepared.body)).toEqual(["read", "write"])
|
|
821
|
+
}),
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
const checkpoint = { type: "compaction", id: "cmp_1", encrypted_content: "opaque" }
|
|
825
|
+
|
|
826
|
+
testEffect(
|
|
827
|
+
dynamicResponse(({ request, text, respond }) =>
|
|
828
|
+
Effect.sync(() => {
|
|
829
|
+
expect(new URL(request.url).pathname).toEndWith("/responses/compact")
|
|
830
|
+
const body = JSON.parse(text)
|
|
831
|
+
expect(body.tools.map((entry: { name: string }) => entry.name)).toEqual(["read", "write", "jira"])
|
|
832
|
+
expect(body.input.map((item: { type: string }) => item.type)).toEqual(["message", "message", "message"])
|
|
833
|
+
return respond(JSON.stringify({ object: "response.compaction", output: [checkpoint] }))
|
|
834
|
+
}),
|
|
835
|
+
),
|
|
836
|
+
).effect("folds every tool into top-level tools on the compaction endpoint", () =>
|
|
837
|
+
Effect.gen(function* () {
|
|
838
|
+
const result = yield* ai.compact(
|
|
839
|
+
ai.request({
|
|
840
|
+
model: astra,
|
|
841
|
+
tools: [read, edit],
|
|
842
|
+
messages: [...conversation, Message.tools({ add: [jira] })],
|
|
843
|
+
}),
|
|
844
|
+
{ mechanism: "endpoint" },
|
|
845
|
+
)
|
|
846
|
+
expect(result.replacement.map((message) => message.content[0]?.type)).toEqual(["compaction"])
|
|
847
|
+
}),
|
|
848
|
+
)
|
|
849
|
+
})
|