@zyro-sec/ai 1.0.0 → 1.0.2
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 -13
- 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,1095 @@
|
|
|
1
|
+
import { describe, expect } from "bun:test"
|
|
2
|
+
import { Deferred, Effect, Fiber, Layer, Ref, Stream } from "effect"
|
|
3
|
+
import { Headers, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http"
|
|
4
|
+
import { Socket } from "effect/socket"
|
|
5
|
+
import { ai, AIError, HttpContext, InvalidProviderOutputError, isRetryable, TransportError } from "../src/effect.js"
|
|
6
|
+
import {
|
|
7
|
+
LLMClient,
|
|
8
|
+
RequestExecutor,
|
|
9
|
+
WebSocketTransport,
|
|
10
|
+
type HttpMiddleware,
|
|
11
|
+
type WebSocketChannelExecutor,
|
|
12
|
+
} from "../src/route.js"
|
|
13
|
+
import { route } from "../src/protocols/openai-chat.js"
|
|
14
|
+
import { configure } from "../src/providers/openai.js"
|
|
15
|
+
import { dynamicResponse, fixedResponse, handlerLayer, systemError, truncatedStream } from "./lib/http.js"
|
|
16
|
+
import { deltaChunk } from "./lib/openai-chunks.js"
|
|
17
|
+
import { sseEvents, sseRaw } from "./lib/sse.js"
|
|
18
|
+
import { it } from "./lib/effect.js"
|
|
19
|
+
|
|
20
|
+
const request = HttpClientRequest.post("https://provider.test/v1/chat?api_key=secret&key=secret&debug=1").pipe(
|
|
21
|
+
HttpClientRequest.setHeaders(Headers.fromInput({ authorization: "Bearer secret", "x-safe": "visible" })),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const secretRequest = HttpClientRequest.post("https://provider.test/v1/chat?api_key=query-secret-123&debug=1").pipe(
|
|
25
|
+
HttpClientRequest.setHeaders(Headers.fromInput({ authorization: "Bearer header-secret-456" })),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const sseRequest = HttpClientRequest.post("https://provider.test/v1/messages")
|
|
29
|
+
|
|
30
|
+
const expectAIError = (error: unknown) => {
|
|
31
|
+
expect(error).toBeInstanceOf(AIError)
|
|
32
|
+
if (!(error instanceof AIError)) throw new Error("expected AIError")
|
|
33
|
+
expect(error.reason).toBeInstanceOf(Error)
|
|
34
|
+
expect(error.cause).toBe(error.reason)
|
|
35
|
+
return error
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const largeProviderMessage = `Upstream request failed: ${"validation failed; ".repeat(1_000)}`
|
|
39
|
+
|
|
40
|
+
describe("RequestExecutor", () => {
|
|
41
|
+
it.effect("preserves externally captured HTTP errors without inventing response context", () =>
|
|
42
|
+
Effect.sync(() => {
|
|
43
|
+
const cause = new Error("upstream request failed")
|
|
44
|
+
const body = '{"error":{"message":"Rate limited","trace":"original"}}'
|
|
45
|
+
const error = RequestExecutor.httpFailure({
|
|
46
|
+
message: "Rate limited",
|
|
47
|
+
url: request.url,
|
|
48
|
+
status: 429,
|
|
49
|
+
responseHeaders: { "Retry-After": "2", "X-Request-ID": "req_external" },
|
|
50
|
+
responseBody: body,
|
|
51
|
+
cause,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
expect(error.message).toBe("Rate limited")
|
|
55
|
+
expect(error.reason).toMatchObject({ _tag: "RateLimit", retryAfterMs: 2000 })
|
|
56
|
+
expect(error.reason.body).toBe(body)
|
|
57
|
+
expect(error.reason.cause).toBe(cause)
|
|
58
|
+
expect(error.reason.http).toEqual(
|
|
59
|
+
new HttpContext({
|
|
60
|
+
url: request.url,
|
|
61
|
+
status: 429,
|
|
62
|
+
headers: { "retry-after": "2", "x-request-id": "req_external" },
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
expect(RequestExecutor.httpFailure({ message: "No response", url: request.url }).reason.http).toBeUndefined()
|
|
66
|
+
expect(RequestExecutor.httpFailure({ message: "No URL", status: 500 }).reason.http).toBeUndefined()
|
|
67
|
+
expect(
|
|
68
|
+
RequestExecutor.httpFailure({
|
|
69
|
+
message: "Huge retry-after",
|
|
70
|
+
url: request.url,
|
|
71
|
+
status: 429,
|
|
72
|
+
responseHeaders: { "Retry-After": "1e20" },
|
|
73
|
+
}).reason,
|
|
74
|
+
).toMatchObject({ _tag: "RateLimit", retryAfterMs: Number.MAX_SAFE_INTEGER })
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
it.effect("classifies AWS modeled errors from every restJson1 identity location", () =>
|
|
79
|
+
Effect.sync(() => {
|
|
80
|
+
const cases = [
|
|
81
|
+
{ body: { code: "ThrottlingException" } },
|
|
82
|
+
{ body: { __type: "ThrottlingException" } },
|
|
83
|
+
{ body: { code: "com.amazonaws.bedrock#ThrottlingException:http://internal.amazon.com/coral/" } },
|
|
84
|
+
{ body: {}, headers: { "X-Amzn-Errortype": "ThrottlingException:http://internal.amazon.com/coral/" } },
|
|
85
|
+
]
|
|
86
|
+
for (const item of cases) {
|
|
87
|
+
const body = JSON.stringify({ ...item.body, message: "Slow down" })
|
|
88
|
+
const error = RequestExecutor.httpFailure({
|
|
89
|
+
message: "Slow down",
|
|
90
|
+
url: request.url,
|
|
91
|
+
status: 400,
|
|
92
|
+
responseHeaders: item.headers,
|
|
93
|
+
responseBody: body,
|
|
94
|
+
})
|
|
95
|
+
expect(error.reason._tag).toBe("RateLimit")
|
|
96
|
+
expect(error.reason.body).toBe(body)
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
it.effect("retains the original body-read failure on an HTTP status error", () =>
|
|
102
|
+
Effect.gen(function* () {
|
|
103
|
+
const cause = new Error("response body disconnected")
|
|
104
|
+
const error = yield* Effect.gen(function* () {
|
|
105
|
+
const executor = yield* RequestExecutor.Service
|
|
106
|
+
return yield* executor.execute(request).pipe(Effect.flip)
|
|
107
|
+
}).pipe(
|
|
108
|
+
Effect.provide(
|
|
109
|
+
fixedResponse(
|
|
110
|
+
new ReadableStream({
|
|
111
|
+
start(controller) {
|
|
112
|
+
controller.error(cause)
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
{
|
|
116
|
+
status: 503,
|
|
117
|
+
headers: { "x-request-id": "req_failed_body" },
|
|
118
|
+
},
|
|
119
|
+
),
|
|
120
|
+
),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
expect(error.reason._tag).toBe("ProviderInternal")
|
|
124
|
+
expect(error.reason.cause).toBe(cause)
|
|
125
|
+
expect(error.reason.body).toBeUndefined()
|
|
126
|
+
expect(error.reason.http).toMatchObject({ status: 503, headers: { "x-request-id": "req_failed_body" } })
|
|
127
|
+
}),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
it.effect("parses response body failures at the executor seam", () =>
|
|
131
|
+
Effect.gen(function* () {
|
|
132
|
+
const executor = yield* RequestExecutor.Service
|
|
133
|
+
const error = yield* RequestExecutor.stream(executor, secretRequest).pipe(Stream.runDrain, Effect.flip)
|
|
134
|
+
|
|
135
|
+
expectAIError(error)
|
|
136
|
+
expect(error.message).toBe(
|
|
137
|
+
"Connection lost while reading the response: ECONNRESET: disconnected query-secret-123 header-secret-456",
|
|
138
|
+
)
|
|
139
|
+
expect(error.reason.http).toMatchObject({ status: 200, url: secretRequest.url })
|
|
140
|
+
expect(error.reason.cause).toMatchObject({ code: "ECONNRESET" })
|
|
141
|
+
expect(error.reason).toMatchObject({
|
|
142
|
+
_tag: "Transport",
|
|
143
|
+
transport: "http",
|
|
144
|
+
operation: "read",
|
|
145
|
+
code: "ECONNRESET",
|
|
146
|
+
url: "https://provider.test/v1/chat?api_key=query-secret-123&debug=1",
|
|
147
|
+
})
|
|
148
|
+
}).pipe(
|
|
149
|
+
Effect.provide(
|
|
150
|
+
fixedResponse(
|
|
151
|
+
new ReadableStream({
|
|
152
|
+
start(controller) {
|
|
153
|
+
controller.error(systemError("ECONNRESET", "disconnected query-secret-123 header-secret-456"))
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
{},
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
it.effect("unwraps native transport failure causes", () =>
|
|
163
|
+
Effect.gen(function* () {
|
|
164
|
+
const executor = yield* RequestExecutor.Service
|
|
165
|
+
const error = yield* RequestExecutor.stream(executor, secretRequest).pipe(Stream.runDrain, Effect.flip)
|
|
166
|
+
|
|
167
|
+
expectAIError(error)
|
|
168
|
+
expect(error.message).toBe("Connection lost while reading the response: ECONNRESET: socket closed")
|
|
169
|
+
expect(error.reason.cause).toBeInstanceOf(TypeError)
|
|
170
|
+
expect(error.reason).toMatchObject({
|
|
171
|
+
_tag: "Transport",
|
|
172
|
+
operation: "read",
|
|
173
|
+
code: "ECONNRESET",
|
|
174
|
+
})
|
|
175
|
+
}).pipe(
|
|
176
|
+
Effect.provide(
|
|
177
|
+
fixedResponse(
|
|
178
|
+
new ReadableStream({
|
|
179
|
+
pull(controller) {
|
|
180
|
+
controller.error(new TypeError("fetch failed", { cause: systemError("ECONNRESET", "socket closed") }))
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
{},
|
|
184
|
+
),
|
|
185
|
+
),
|
|
186
|
+
),
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
it.effect("reports a connection lost mid-stream through middleware that re-wraps the body", () =>
|
|
190
|
+
Effect.gen(function* () {
|
|
191
|
+
const executor = yield* RequestExecutor.Service
|
|
192
|
+
const chunks: Array<Uint8Array> = []
|
|
193
|
+
// Session HTTP hooks hand plugins a web Response, so the body is re-wrapped around the original stream.
|
|
194
|
+
const rewrap: HttpMiddleware = (input, handler) =>
|
|
195
|
+
Effect.gen(function* () {
|
|
196
|
+
const response = yield* handler(input)
|
|
197
|
+
const body = yield* Stream.toReadableStreamEffect(response.stream)
|
|
198
|
+
return HttpClientResponse.fromWeb(
|
|
199
|
+
input,
|
|
200
|
+
new Response(body, { status: response.status, headers: response.headers }),
|
|
201
|
+
)
|
|
202
|
+
})
|
|
203
|
+
const error = yield* RequestExecutor.stream(executor, sseRequest, rewrap).pipe(
|
|
204
|
+
Stream.runForEach((chunk) => Effect.sync(() => chunks.push(chunk))),
|
|
205
|
+
Effect.flip,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
expectAIError(error)
|
|
209
|
+
expect(new TextDecoder().decode(chunks[0])).toBe('data: {"type":"ping"}\n\n')
|
|
210
|
+
expect(error.message).toBe("Connection lost while reading the response: ECONNRESET: other side closed")
|
|
211
|
+
expect(error.reason.cause).toBeInstanceOf(TypeError)
|
|
212
|
+
expect(error.reason.http).toMatchObject({ status: 200 })
|
|
213
|
+
expect(error.reason).toMatchObject({ _tag: "Transport", operation: "read", code: "ECONNRESET" })
|
|
214
|
+
expect(isRetryable(error)).toBeTrue()
|
|
215
|
+
}).pipe(
|
|
216
|
+
Effect.provide(
|
|
217
|
+
truncatedStream(
|
|
218
|
+
['data: {"type":"ping"}\n\n'],
|
|
219
|
+
new TypeError("terminated", { cause: systemError("ECONNRESET", "other side closed") }),
|
|
220
|
+
),
|
|
221
|
+
),
|
|
222
|
+
),
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
it.effect("does not report a body read failure without a native cause as a decode error", () =>
|
|
226
|
+
Effect.gen(function* () {
|
|
227
|
+
const executor = yield* RequestExecutor.Service
|
|
228
|
+
const error = yield* RequestExecutor.stream(executor, sseRequest).pipe(Stream.runDrain, Effect.flip)
|
|
229
|
+
|
|
230
|
+
expectAIError(error)
|
|
231
|
+
expect(error.message).toBe("Connection lost while reading the response")
|
|
232
|
+
expect(error.reason).toMatchObject({ _tag: "Transport", operation: "read", code: undefined })
|
|
233
|
+
expect(isRetryable(error)).toBeTrue()
|
|
234
|
+
}).pipe(Effect.provide(truncatedStream(['data: {"type":"ping"}\n\n'], new DOMException("aborted", "AbortError")))),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
it.effect("preserves middleware error messages", () =>
|
|
238
|
+
Effect.gen(function* () {
|
|
239
|
+
const executor = yield* RequestExecutor.Service
|
|
240
|
+
const error = yield* executor
|
|
241
|
+
.execute(request, () => Effect.fail(new Error("plugin rejected request")))
|
|
242
|
+
.pipe(Effect.flip)
|
|
243
|
+
|
|
244
|
+
expectAIError(error)
|
|
245
|
+
expect(error.message).toBe("plugin rejected request")
|
|
246
|
+
expect(error.reason.cause).toBeInstanceOf(Error)
|
|
247
|
+
expect(error.reason.http).toBeUndefined()
|
|
248
|
+
}).pipe(Effect.provide(dynamicResponse(() => Effect.die(new Error("unexpected HTTP request"))))),
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
it.effect("reports the request sent by middleware", () =>
|
|
252
|
+
Effect.gen(function* () {
|
|
253
|
+
const executor = yield* RequestExecutor.Service
|
|
254
|
+
const error = yield* executor
|
|
255
|
+
.execute(request, (original, handler) =>
|
|
256
|
+
handler(
|
|
257
|
+
original.pipe(
|
|
258
|
+
HttpClientRequest.setUrl("https://proxy.test/v1/chat?api_key=proxy-secret"),
|
|
259
|
+
HttpClientRequest.setHeader("authorization", "Bearer proxy-secret"),
|
|
260
|
+
),
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
.pipe(Effect.flip)
|
|
264
|
+
|
|
265
|
+
expectAIError(error)
|
|
266
|
+
expect(error.message).toBe("ECONNRESET: proxy disconnected proxy-secret")
|
|
267
|
+
expect(error.reason.http).toBeUndefined()
|
|
268
|
+
expect(error.reason).toMatchObject({
|
|
269
|
+
_tag: "Transport",
|
|
270
|
+
url: "https://proxy.test/v1/chat?api_key=proxy-secret",
|
|
271
|
+
})
|
|
272
|
+
}).pipe(
|
|
273
|
+
Effect.provide(
|
|
274
|
+
dynamicResponse((input) =>
|
|
275
|
+
Effect.fail(
|
|
276
|
+
new HttpClientError.HttpClientError({
|
|
277
|
+
reason: new HttpClientError.TransportError({
|
|
278
|
+
request: input.request,
|
|
279
|
+
cause: systemError("ECONNRESET", "proxy disconnected proxy-secret"),
|
|
280
|
+
}),
|
|
281
|
+
}),
|
|
282
|
+
),
|
|
283
|
+
),
|
|
284
|
+
),
|
|
285
|
+
),
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
it.effect("runs shared middleware outside per-call middleware", () => {
|
|
289
|
+
const calls: Array<string> = []
|
|
290
|
+
const record = (name: string) => Effect.sync(() => calls.push(name))
|
|
291
|
+
const base = RequestExecutor.layer.pipe(
|
|
292
|
+
Layer.provide(handlerLayer((input) => record("handler").pipe(Effect.as(input.respond("ok"))))),
|
|
293
|
+
)
|
|
294
|
+
return Effect.gen(function* () {
|
|
295
|
+
const executor = yield* RequestExecutor.Service
|
|
296
|
+
yield* executor.execute(request, (input, next) => record("per-call").pipe(Effect.andThen(next(input))))
|
|
297
|
+
expect(calls).toEqual(["outer", "per-call", "handler"])
|
|
298
|
+
calls.length = 0
|
|
299
|
+
yield* executor.execute(request)
|
|
300
|
+
expect(calls).toEqual(["outer", "handler"])
|
|
301
|
+
}).pipe(
|
|
302
|
+
Effect.provide(
|
|
303
|
+
RequestExecutor.middleware((input, next) => record("outer").pipe(Effect.andThen(next(input))), base),
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it.effect("runs scoped middleware between shared and per-call middleware, outer scopes first", () => {
|
|
309
|
+
const calls: Array<string> = []
|
|
310
|
+
const record =
|
|
311
|
+
(name: string): HttpMiddleware =>
|
|
312
|
+
(input, next) =>
|
|
313
|
+
Effect.sync(() => calls.push(name)).pipe(Effect.andThen(next(input)))
|
|
314
|
+
const base = RequestExecutor.layer.pipe(
|
|
315
|
+
Layer.provide(
|
|
316
|
+
handlerLayer((input) => Effect.sync(() => calls.push("handler")).pipe(Effect.as(input.respond("ok")))),
|
|
317
|
+
),
|
|
318
|
+
)
|
|
319
|
+
return Effect.gen(function* () {
|
|
320
|
+
const executor = yield* RequestExecutor.Service
|
|
321
|
+
yield* executor
|
|
322
|
+
.execute(request, record("per-call"))
|
|
323
|
+
.pipe(RequestExecutor.withMiddleware(record("inner")), RequestExecutor.withMiddleware(record("outer")))
|
|
324
|
+
expect(calls).toEqual(["shared", "outer", "inner", "per-call", "handler"])
|
|
325
|
+
calls.length = 0
|
|
326
|
+
// Outside the scope, nothing scoped runs.
|
|
327
|
+
yield* executor.execute(request)
|
|
328
|
+
expect(calls).toEqual(["shared", "handler"])
|
|
329
|
+
}).pipe(Effect.provide(RequestExecutor.middleware(record("shared"), base)))
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
it.effect("applies scoped middleware to a stream and to requests sent through a per-request fetch", () => {
|
|
333
|
+
const seen: Array<string> = []
|
|
334
|
+
const scoped: HttpMiddleware = (input, next) =>
|
|
335
|
+
Effect.sync(() => seen.push(input.url)).pipe(Effect.andThen(next(input)))
|
|
336
|
+
const fetch: typeof globalThis.fetch = Object.assign(async () => new Response("from fetch"), {
|
|
337
|
+
preconnect: globalThis.fetch.preconnect,
|
|
338
|
+
})
|
|
339
|
+
return Effect.gen(function* () {
|
|
340
|
+
const executor = yield* RequestExecutor.Service
|
|
341
|
+
const body = yield* RequestExecutor.stream(executor, request).pipe(
|
|
342
|
+
Stream.decodeText(),
|
|
343
|
+
Stream.mkString,
|
|
344
|
+
RequestExecutor.withMiddleware(scoped),
|
|
345
|
+
)
|
|
346
|
+
expect(body).toBe("ok")
|
|
347
|
+
const fetched = yield* executor
|
|
348
|
+
.execute(sseRequest, RequestExecutor.withFetch(fetch))
|
|
349
|
+
.pipe(RequestExecutor.withMiddleware(scoped))
|
|
350
|
+
expect(yield* fetched.text).toBe("from fetch")
|
|
351
|
+
expect(seen).toEqual([request.url, sseRequest.url])
|
|
352
|
+
}).pipe(
|
|
353
|
+
Effect.provide(
|
|
354
|
+
RequestExecutor.layer.pipe(Layer.provide(handlerLayer((input) => Effect.succeed(input.respond("ok"))))),
|
|
355
|
+
),
|
|
356
|
+
)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
it.effect("doesn't wrap a request that scoped middleware sends itself", () => {
|
|
360
|
+
let wrapped = 0
|
|
361
|
+
return Effect.gen(function* () {
|
|
362
|
+
const executor = yield* RequestExecutor.Service
|
|
363
|
+
const scoped: HttpMiddleware = (input, next) =>
|
|
364
|
+
Effect.gen(function* () {
|
|
365
|
+
wrapped++
|
|
366
|
+
// Such as a token refresh made from inside an auth hook.
|
|
367
|
+
yield* executor.execute(sseRequest).pipe(Effect.orDie)
|
|
368
|
+
return yield* next(input)
|
|
369
|
+
})
|
|
370
|
+
yield* executor.execute(request).pipe(RequestExecutor.withMiddleware(scoped))
|
|
371
|
+
expect(wrapped).toBe(1)
|
|
372
|
+
}).pipe(
|
|
373
|
+
Effect.provide(
|
|
374
|
+
RequestExecutor.layer.pipe(Layer.provide(handlerLayer((input) => Effect.succeed(input.respond("ok"))))),
|
|
375
|
+
),
|
|
376
|
+
)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
it.effect("classifies context overflow responses", () =>
|
|
380
|
+
Effect.gen(function* () {
|
|
381
|
+
const executor = yield* RequestExecutor.Service
|
|
382
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
383
|
+
|
|
384
|
+
expectAIError(error)
|
|
385
|
+
expect(error.reason).toMatchObject({ _tag: "InvalidRequest", classification: "context-overflow" })
|
|
386
|
+
}).pipe(
|
|
387
|
+
Effect.provide(
|
|
388
|
+
fixedResponse('{"error":{"code":"context_length_exceeded","message":"prompt too long"}}', {
|
|
389
|
+
status: 400,
|
|
390
|
+
}),
|
|
391
|
+
),
|
|
392
|
+
),
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
it.effect("classifies generic HTTP 413 payload errors", () =>
|
|
396
|
+
Effect.gen(function* () {
|
|
397
|
+
const executor = yield* RequestExecutor.Service
|
|
398
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
399
|
+
|
|
400
|
+
expectAIError(error)
|
|
401
|
+
expect(error.reason).toMatchObject({
|
|
402
|
+
_tag: "InvalidRequest",
|
|
403
|
+
classification: "payload-too-large",
|
|
404
|
+
})
|
|
405
|
+
expect(error.reason.http?.status).toBe(413)
|
|
406
|
+
}).pipe(Effect.provide(fixedResponse("request too large", { status: 413 }))),
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
it.effect("classifies Anthropic request_too_large as context overflow", () =>
|
|
410
|
+
Effect.gen(function* () {
|
|
411
|
+
const executor = yield* RequestExecutor.Service
|
|
412
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
413
|
+
|
|
414
|
+
expectAIError(error)
|
|
415
|
+
expect(error.reason).toMatchObject({
|
|
416
|
+
_tag: "InvalidRequest",
|
|
417
|
+
classification: "context-overflow",
|
|
418
|
+
})
|
|
419
|
+
expect(error.reason.http?.status).toBe(413)
|
|
420
|
+
}).pipe(
|
|
421
|
+
Effect.provide(
|
|
422
|
+
fixedResponse('{"error":{"type":"request_too_large","message":"Request exceeds the maximum size"}}', {
|
|
423
|
+
status: 413,
|
|
424
|
+
}),
|
|
425
|
+
),
|
|
426
|
+
),
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
it.effect("does not classify ordinary invalid requests as context overflow", () =>
|
|
430
|
+
Effect.gen(function* () {
|
|
431
|
+
const executor = yield* RequestExecutor.Service
|
|
432
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
433
|
+
|
|
434
|
+
expectAIError(error)
|
|
435
|
+
expect(error.reason).toMatchObject({ _tag: "InvalidRequest" })
|
|
436
|
+
expect("classification" in error.reason ? error.reason.classification : undefined).toBeUndefined()
|
|
437
|
+
expect(error.message).toBe("Provider request failed with HTTP 400: invalid parameter")
|
|
438
|
+
}).pipe(Effect.provide(fixedResponse("invalid parameter", { status: 400 }))),
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
it.effect("shows unrecognized provider error bodies", () =>
|
|
442
|
+
Effect.gen(function* () {
|
|
443
|
+
const executor = yield* RequestExecutor.Service
|
|
444
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
445
|
+
|
|
446
|
+
expect(error.message).toBe(
|
|
447
|
+
'Provider request failed with HTTP 422: {"object":"error","message":{"detail":[{"msg":"Input should be less than or equal to 1.5"}]}}',
|
|
448
|
+
)
|
|
449
|
+
}).pipe(
|
|
450
|
+
Effect.provide(
|
|
451
|
+
fixedResponse('{"object":"error","message":{"detail":[{"msg":"Input should be less than or equal to 1.5"}]}}', {
|
|
452
|
+
status: 422,
|
|
453
|
+
}),
|
|
454
|
+
),
|
|
455
|
+
),
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
it.effect("shows messages from common provider error layouts", () =>
|
|
459
|
+
Effect.gen(function* () {
|
|
460
|
+
const executor = yield* RequestExecutor.Service
|
|
461
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
462
|
+
|
|
463
|
+
expect(error.message).toBe("Invalid API Key")
|
|
464
|
+
}).pipe(Effect.provide(fixedResponse('{"detail":"Invalid API Key"}', { status: 401 }))),
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
it.effect("truncates long unrecognized provider error bodies", () =>
|
|
468
|
+
Effect.gen(function* () {
|
|
469
|
+
const executor = yield* RequestExecutor.Service
|
|
470
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
471
|
+
|
|
472
|
+
expect(error.message).toBe(`Provider request failed with HTTP 400: ${"x".repeat(2000)}…`)
|
|
473
|
+
expect(error.reason.body).toHaveLength(5000)
|
|
474
|
+
}).pipe(Effect.provide(fixedResponse("x".repeat(5000), { status: 400 }))),
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
it.effect("does not show HTML error pages", () =>
|
|
478
|
+
Effect.gen(function* () {
|
|
479
|
+
const executor = yield* RequestExecutor.Service
|
|
480
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
481
|
+
|
|
482
|
+
expect(error.message).toBe("Provider request failed with HTTP 502")
|
|
483
|
+
expect(error.reason.body).toContain("Bad Gateway")
|
|
484
|
+
}).pipe(Effect.provide(fixedResponse("<!DOCTYPE html><html><body>Bad Gateway</body></html>", { status: 502 }))),
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
it.effect("preserves structured provider messages from large error bodies", () =>
|
|
488
|
+
Effect.gen(function* () {
|
|
489
|
+
const executor = yield* RequestExecutor.Service
|
|
490
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
491
|
+
|
|
492
|
+
expectAIError(error)
|
|
493
|
+
expect(error.reason).toMatchObject({ _tag: "InvalidRequest" })
|
|
494
|
+
expect(error.message).toBe(largeProviderMessage)
|
|
495
|
+
expect(error.reason.body).toContain(largeProviderMessage)
|
|
496
|
+
}).pipe(
|
|
497
|
+
Effect.provide(
|
|
498
|
+
fixedResponse(
|
|
499
|
+
JSON.stringify({
|
|
500
|
+
model: "test-model",
|
|
501
|
+
error: { type: "invalid_request", message: largeProviderMessage },
|
|
502
|
+
}),
|
|
503
|
+
{ status: 400 },
|
|
504
|
+
),
|
|
505
|
+
),
|
|
506
|
+
),
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
it.effect("shows the body when structured provider messages are empty", () =>
|
|
510
|
+
Effect.gen(function* () {
|
|
511
|
+
const executor = yield* RequestExecutor.Service
|
|
512
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
513
|
+
|
|
514
|
+
expectAIError(error)
|
|
515
|
+
expect(error.reason).toMatchObject({
|
|
516
|
+
_tag: "InvalidRequest",
|
|
517
|
+
})
|
|
518
|
+
expect(error.message).toBe('Provider request failed with HTTP 400: {"error":{"message":" "}}')
|
|
519
|
+
}).pipe(Effect.provide(fixedResponse('{"error":{"message":" "}}', { status: 400 }))),
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
it.effect("classifies provider rate limits hidden behind HTTP 400", () =>
|
|
523
|
+
Effect.gen(function* () {
|
|
524
|
+
const classify = (body: string) =>
|
|
525
|
+
Effect.gen(function* () {
|
|
526
|
+
const executor = yield* RequestExecutor.Service
|
|
527
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
528
|
+
|
|
529
|
+
expectAIError(error)
|
|
530
|
+
expect(error.reason).toMatchObject({ _tag: "RateLimit" })
|
|
531
|
+
}).pipe(Effect.provide(fixedResponse(body, { status: 400 })))
|
|
532
|
+
|
|
533
|
+
yield* classify("Request rate increased too quickly")
|
|
534
|
+
yield* classify('{"type":"error","error":{"type":"too_many_requests"}}')
|
|
535
|
+
yield* classify('{"type":"error","error":{"code":"rate_limit_exceeded"}}')
|
|
536
|
+
}),
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
it.effect("does not let server codes override a 4xx rejection", () =>
|
|
540
|
+
Effect.gen(function* () {
|
|
541
|
+
const classify = (body: string) =>
|
|
542
|
+
Effect.gen(function* () {
|
|
543
|
+
const executor = yield* RequestExecutor.Service
|
|
544
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
545
|
+
|
|
546
|
+
expectAIError(error)
|
|
547
|
+
expect(error.reason).toMatchObject({ _tag: "InvalidRequest" })
|
|
548
|
+
}).pipe(Effect.provide(fixedResponse(body, { status: 400 })))
|
|
549
|
+
|
|
550
|
+
yield* classify('{"code":"resource_exhausted"}')
|
|
551
|
+
yield* classify('{"error":{"type":"server_error","message":"Upstream request failed: Model is unavailable."}}')
|
|
552
|
+
}),
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
it.effect("returns complete diagnostics for rate limits", () =>
|
|
556
|
+
Effect.gen(function* () {
|
|
557
|
+
const executor = yield* RequestExecutor.Service
|
|
558
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
559
|
+
|
|
560
|
+
expectAIError(error)
|
|
561
|
+
expect(error.reason).toMatchObject({
|
|
562
|
+
_tag: "RateLimit",
|
|
563
|
+
retryAfterMs: 0,
|
|
564
|
+
rateLimit: { retryAfterMs: 0 },
|
|
565
|
+
http: {
|
|
566
|
+
url: "https://provider.test/v1/chat?api_key=secret&key=secret&debug=1",
|
|
567
|
+
status: 429,
|
|
568
|
+
headers: {
|
|
569
|
+
"retry-after-ms": "0",
|
|
570
|
+
"x-request-id": "req_123",
|
|
571
|
+
"x-api-key": "secret",
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
})
|
|
575
|
+
expect(error.reason.body).toBe("rate limited")
|
|
576
|
+
}).pipe(
|
|
577
|
+
Effect.provide(
|
|
578
|
+
fixedResponse("rate limited", {
|
|
579
|
+
status: 429,
|
|
580
|
+
headers: { "retry-after-ms": "0", "x-request-id": "req_123", "x-api-key": "secret" },
|
|
581
|
+
}),
|
|
582
|
+
),
|
|
583
|
+
),
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
it.effect("preserves configured header names in diagnostics", () =>
|
|
587
|
+
Effect.gen(function* () {
|
|
588
|
+
const executor = yield* RequestExecutor.Service
|
|
589
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
590
|
+
|
|
591
|
+
expectAIError(error)
|
|
592
|
+
expect(error.reason.http?.headers["x-safe"]).toBe("response-secret")
|
|
593
|
+
}).pipe(
|
|
594
|
+
Effect.provide(fixedResponse("bad", { status: 400, headers: { "x-safe": "response-secret" } })),
|
|
595
|
+
Effect.provideService(Headers.CurrentRedactedNames, ["x-safe"]),
|
|
596
|
+
),
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
it.effect("extracts OpenAI-style rate-limit diagnostics", () =>
|
|
600
|
+
Effect.gen(function* () {
|
|
601
|
+
const executor = yield* RequestExecutor.Service
|
|
602
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
603
|
+
|
|
604
|
+
expectAIError(error)
|
|
605
|
+
expect(error.reason).toMatchObject({ _tag: "RateLimit" })
|
|
606
|
+
expect(error.reason._tag === "RateLimit" ? error.reason.rateLimit : undefined).toEqual({
|
|
607
|
+
retryAfterMs: 0,
|
|
608
|
+
limit: { requests: "500", tokens: "30000" },
|
|
609
|
+
remaining: { requests: "499", tokens: "29900" },
|
|
610
|
+
reset: { requests: "1s", tokens: "10s" },
|
|
611
|
+
})
|
|
612
|
+
}).pipe(
|
|
613
|
+
Effect.provide(
|
|
614
|
+
fixedResponse("rate limited", {
|
|
615
|
+
status: 429,
|
|
616
|
+
headers: {
|
|
617
|
+
"retry-after-ms": "0",
|
|
618
|
+
"x-ratelimit-limit-requests": "500",
|
|
619
|
+
"x-ratelimit-limit-tokens": "30000",
|
|
620
|
+
"x-ratelimit-remaining-requests": "499",
|
|
621
|
+
"x-ratelimit-remaining-tokens": "29900",
|
|
622
|
+
"x-ratelimit-reset-requests": "1s",
|
|
623
|
+
"x-ratelimit-reset-tokens": "10s",
|
|
624
|
+
},
|
|
625
|
+
}),
|
|
626
|
+
),
|
|
627
|
+
),
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
it.effect("extracts Anthropic-style rate-limit diagnostics", () =>
|
|
631
|
+
Effect.gen(function* () {
|
|
632
|
+
const executor = yield* RequestExecutor.Service
|
|
633
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
634
|
+
|
|
635
|
+
expectAIError(error)
|
|
636
|
+
expect(error.reason).toMatchObject({ _tag: "RateLimit" })
|
|
637
|
+
expect(error.reason._tag === "RateLimit" ? error.reason.rateLimit : undefined).toEqual({
|
|
638
|
+
retryAfterMs: 0,
|
|
639
|
+
limit: { requests: "100", "input-tokens": "10000" },
|
|
640
|
+
remaining: { requests: "12", "input-tokens": "9000" },
|
|
641
|
+
reset: { requests: "2026-05-06T12:00:00Z", "input-tokens": "2026-05-06T12:00:10Z" },
|
|
642
|
+
})
|
|
643
|
+
}).pipe(
|
|
644
|
+
Effect.provide(
|
|
645
|
+
fixedResponse("rate limited", {
|
|
646
|
+
status: 429,
|
|
647
|
+
headers: {
|
|
648
|
+
"retry-after-ms": "0",
|
|
649
|
+
"anthropic-ratelimit-requests-limit": "100",
|
|
650
|
+
"anthropic-ratelimit-requests-remaining": "12",
|
|
651
|
+
"anthropic-ratelimit-requests-reset": "2026-05-06T12:00:00Z",
|
|
652
|
+
"anthropic-ratelimit-input-tokens-limit": "10000",
|
|
653
|
+
"anthropic-ratelimit-input-tokens-remaining": "9000",
|
|
654
|
+
"anthropic-ratelimit-input-tokens-reset": "2026-05-06T12:00:10Z",
|
|
655
|
+
},
|
|
656
|
+
}),
|
|
657
|
+
),
|
|
658
|
+
),
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
it.effect("returns provider status failures without retrying", () =>
|
|
662
|
+
Effect.gen(function* () {
|
|
663
|
+
const attempts = yield* Ref.make(0)
|
|
664
|
+
const error = yield* Effect.gen(function* () {
|
|
665
|
+
const executor = yield* RequestExecutor.Service
|
|
666
|
+
return yield* executor.execute(request).pipe(Effect.flip)
|
|
667
|
+
}).pipe(
|
|
668
|
+
Effect.provide(
|
|
669
|
+
dynamicResponse((input) =>
|
|
670
|
+
Effect.gen(function* () {
|
|
671
|
+
const attempt = yield* Ref.getAndUpdate(attempts, (value) => value + 1)
|
|
672
|
+
return attempt === 0
|
|
673
|
+
? input.respond("busy", { status: 503, headers: { "retry-after-ms": "0" } })
|
|
674
|
+
: input.respond("ok", { status: 200 })
|
|
675
|
+
}),
|
|
676
|
+
),
|
|
677
|
+
),
|
|
678
|
+
)
|
|
679
|
+
|
|
680
|
+
expectAIError(error)
|
|
681
|
+
expect(error.reason).toMatchObject({ _tag: "ProviderInternal" })
|
|
682
|
+
expect(error.reason.http?.status).toBe(503)
|
|
683
|
+
expect(yield* Ref.get(attempts)).toBe(1)
|
|
684
|
+
}),
|
|
685
|
+
)
|
|
686
|
+
|
|
687
|
+
it.effect("marks 504 and 529 status responses as provider-internal", () =>
|
|
688
|
+
Effect.gen(function* () {
|
|
689
|
+
const failWith = (status: number) =>
|
|
690
|
+
Effect.gen(function* () {
|
|
691
|
+
const executor = yield* RequestExecutor.Service
|
|
692
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
693
|
+
|
|
694
|
+
expectAIError(error)
|
|
695
|
+
expect(error.reason).toMatchObject({ _tag: "ProviderInternal" })
|
|
696
|
+
expect(error.reason.http?.status).toBe(status)
|
|
697
|
+
}).pipe(
|
|
698
|
+
Effect.provide(
|
|
699
|
+
fixedResponse("provider failure", {
|
|
700
|
+
status,
|
|
701
|
+
headers: { "retry-after-ms": "0" },
|
|
702
|
+
}),
|
|
703
|
+
),
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
yield* failWith(504)
|
|
707
|
+
yield* failWith(529)
|
|
708
|
+
}),
|
|
709
|
+
)
|
|
710
|
+
|
|
711
|
+
it.effect("preserves large authentication error bodies", () =>
|
|
712
|
+
Effect.gen(function* () {
|
|
713
|
+
const attempts = yield* Ref.make(0)
|
|
714
|
+
const error = yield* Effect.gen(function* () {
|
|
715
|
+
const executor = yield* RequestExecutor.Service
|
|
716
|
+
return yield* executor.execute(request).pipe(Effect.flip)
|
|
717
|
+
}).pipe(
|
|
718
|
+
Effect.provide(
|
|
719
|
+
dynamicResponse((input) =>
|
|
720
|
+
Effect.gen(function* () {
|
|
721
|
+
const attempt = yield* Ref.getAndUpdate(attempts, (value) => value + 1)
|
|
722
|
+
return attempt === 0
|
|
723
|
+
? input.respond("x".repeat(20_000), { status: 401 })
|
|
724
|
+
: input.respond("should not retry", { status: 200 })
|
|
725
|
+
}),
|
|
726
|
+
),
|
|
727
|
+
),
|
|
728
|
+
)
|
|
729
|
+
|
|
730
|
+
expectAIError(error)
|
|
731
|
+
expect(error.reason).toMatchObject({ _tag: "Authentication" })
|
|
732
|
+
expect(error.reason.body).toHaveLength(20_000)
|
|
733
|
+
expect(yield* Ref.get(attempts)).toBe(1)
|
|
734
|
+
}),
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
it.effect("preserves response body fields", () =>
|
|
738
|
+
Effect.gen(function* () {
|
|
739
|
+
const executor = yield* RequestExecutor.Service
|
|
740
|
+
const error = yield* executor.execute(request).pipe(Effect.flip)
|
|
741
|
+
|
|
742
|
+
expectAIError(error)
|
|
743
|
+
expect(error.reason.body).toBe('{"error":{"message":"bad","key":"body-secret","detail":"api_key=query-secret"}}')
|
|
744
|
+
}).pipe(
|
|
745
|
+
Effect.provide(
|
|
746
|
+
fixedResponse('{"error":{"message":"bad","key":"body-secret","detail":"api_key=query-secret"}}', {
|
|
747
|
+
status: 400,
|
|
748
|
+
}),
|
|
749
|
+
),
|
|
750
|
+
),
|
|
751
|
+
)
|
|
752
|
+
|
|
753
|
+
it.effect("preserves echoed request values in response bodies", () =>
|
|
754
|
+
Effect.gen(function* () {
|
|
755
|
+
const executor = yield* RequestExecutor.Service
|
|
756
|
+
const error = yield* executor.execute(secretRequest).pipe(Effect.flip)
|
|
757
|
+
|
|
758
|
+
expectAIError(error)
|
|
759
|
+
expect(error.reason.body).toBe("provider echoed query-secret-123 and authorization header-secret-456")
|
|
760
|
+
}).pipe(
|
|
761
|
+
Effect.provide(
|
|
762
|
+
fixedResponse("provider echoed query-secret-123 and authorization header-secret-456", { status: 400 }),
|
|
763
|
+
),
|
|
764
|
+
),
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
it.effect("does not re-execute after a successful response reaches stream parsing", () =>
|
|
768
|
+
Effect.gen(function* () {
|
|
769
|
+
const attempts = yield* Ref.make(0)
|
|
770
|
+
const model = route.with({ endpoint: { baseURL: "https://api.openai.test/v1" } }).model({ id: "gpt-4o-mini" })
|
|
771
|
+
const error = yield* LLMClient.generate(ai.request({ model, prompt: "Say hello." })).pipe(
|
|
772
|
+
Effect.provide(
|
|
773
|
+
dynamicResponse((input) =>
|
|
774
|
+
Ref.update(attempts, (value) => value + 1).pipe(
|
|
775
|
+
Effect.as(
|
|
776
|
+
input.respond(
|
|
777
|
+
sseRaw(
|
|
778
|
+
`data: ${JSON.stringify(deltaChunk({ role: "assistant", content: "Hello" }))}`,
|
|
779
|
+
"data: not-json",
|
|
780
|
+
),
|
|
781
|
+
{ headers: { "content-type": "text/event-stream" } },
|
|
782
|
+
),
|
|
783
|
+
),
|
|
784
|
+
),
|
|
785
|
+
),
|
|
786
|
+
),
|
|
787
|
+
Effect.flip,
|
|
788
|
+
)
|
|
789
|
+
|
|
790
|
+
expectAIError(error)
|
|
791
|
+
expect(error.reason).toMatchObject({ _tag: "InvalidProviderOutput" })
|
|
792
|
+
expect(error.reason.body).toBe("not-json")
|
|
793
|
+
expect(error.reason.cause).toBeDefined()
|
|
794
|
+
expect(error.reason.http).toMatchObject({ status: 200, headers: { "content-type": "text/event-stream" } })
|
|
795
|
+
expect(yield* Ref.get(attempts)).toBe(1)
|
|
796
|
+
}),
|
|
797
|
+
)
|
|
798
|
+
})
|
|
799
|
+
|
|
800
|
+
describe("WebSocket channel execution", () => {
|
|
801
|
+
const model = configure({ baseURL: "https://api.openai.test/v1/", apiKey: "test" }).responses("gpt-4.1-mini")
|
|
802
|
+
const request = ai.request({ model, prompt: "Say hello." })
|
|
803
|
+
const frames = [
|
|
804
|
+
JSON.stringify({ type: "response.output_item.added", item: { type: "message", id: "msg_1" } }),
|
|
805
|
+
JSON.stringify({ type: "response.output_text.delta", item_id: "msg_1", delta: "Hi" }),
|
|
806
|
+
JSON.stringify({ type: "response.completed", response: { id: "resp_1" } }),
|
|
807
|
+
]
|
|
808
|
+
|
|
809
|
+
it.effect("preserves close reasons and native event causes without fabricated HTTP metadata", () =>
|
|
810
|
+
Effect.gen(function* () {
|
|
811
|
+
class TestSocket extends EventTarget {
|
|
812
|
+
readyState = globalThis.WebSocket.OPEN
|
|
813
|
+
send() {}
|
|
814
|
+
close() {}
|
|
815
|
+
}
|
|
816
|
+
const socket = new TestSocket()
|
|
817
|
+
const headers = Headers.fromInput({ authorization: "Bearer secret", "openai-beta": "responses-websocket" })
|
|
818
|
+
let observed: { url: string; options: Socket.WebSocketConstructorOptions | undefined } | undefined
|
|
819
|
+
const connection = yield* WebSocketTransport.open({
|
|
820
|
+
url: "wss://provider.test/responses",
|
|
821
|
+
headers,
|
|
822
|
+
}).pipe(
|
|
823
|
+
Effect.provideService(Socket.WebSocketConstructor, (url, options) => {
|
|
824
|
+
observed = { url, options }
|
|
825
|
+
return socket
|
|
826
|
+
}),
|
|
827
|
+
)
|
|
828
|
+
expect(observed).toEqual({ url: "wss://provider.test/responses", options: { headers } })
|
|
829
|
+
const event = new CloseEvent("close", { code: 1011, reason: "upstream trace: req_close" })
|
|
830
|
+
socket.dispatchEvent(event)
|
|
831
|
+
const error = yield* connection.messages.pipe(Stream.runDrain, Effect.flip)
|
|
832
|
+
|
|
833
|
+
expect(error.reason).toMatchObject({ _tag: "Transport", code: "1011", phase: "close" })
|
|
834
|
+
expect(error.message).toBe("WebSocket closed with code 1011")
|
|
835
|
+
expect(error.reason.body).toBe(event.reason)
|
|
836
|
+
expect(error.reason.cause).toBe(event)
|
|
837
|
+
expect(error.reason.http).toBeUndefined()
|
|
838
|
+
yield* connection.close
|
|
839
|
+
}),
|
|
840
|
+
)
|
|
841
|
+
|
|
842
|
+
it.effect("preserves opening event errors and native send exceptions", () =>
|
|
843
|
+
Effect.gen(function* () {
|
|
844
|
+
const cause = new Error("native send failed")
|
|
845
|
+
class TestSocket extends EventTarget {
|
|
846
|
+
readyState = globalThis.WebSocket.CONNECTING
|
|
847
|
+
send() {
|
|
848
|
+
throw cause
|
|
849
|
+
}
|
|
850
|
+
close() {}
|
|
851
|
+
}
|
|
852
|
+
const socket = new TestSocket()
|
|
853
|
+
const open = WebSocketTransport.fromWebSocket(socket, {
|
|
854
|
+
url: "wss://provider.test/responses",
|
|
855
|
+
headers: Headers.empty,
|
|
856
|
+
})
|
|
857
|
+
const fiber = yield* open.pipe(Effect.flip, Effect.forkChild({ startImmediately: true }))
|
|
858
|
+
const event = new ErrorEvent("error", { message: "handshake rejected", error: cause })
|
|
859
|
+
socket.dispatchEvent(event)
|
|
860
|
+
const error = yield* Fiber.join(fiber)
|
|
861
|
+
expect(error.reason.cause).toBe(cause)
|
|
862
|
+
expect(error.message).toContain("handshake rejected")
|
|
863
|
+
expect(error.reason.http).toBeUndefined()
|
|
864
|
+
|
|
865
|
+
socket.readyState = globalThis.WebSocket.OPEN
|
|
866
|
+
const connection = yield* open
|
|
867
|
+
const sent = yield* connection.sendText("create").pipe(Effect.flip)
|
|
868
|
+
expect(sent.reason.cause).toBe(cause)
|
|
869
|
+
expect(sent.message).toBe(cause.message)
|
|
870
|
+
yield* connection.close
|
|
871
|
+
}),
|
|
872
|
+
)
|
|
873
|
+
|
|
874
|
+
it.effect("preserves raw driver failures and known upgrade metadata", () =>
|
|
875
|
+
Effect.gen(function* () {
|
|
876
|
+
const cause = new Error("driver validation failed")
|
|
877
|
+
const frame = '{ "error": "failed", "trace": "original" }'
|
|
878
|
+
const http = new HttpContext({
|
|
879
|
+
url: "https://provider.test/responses",
|
|
880
|
+
status: 101,
|
|
881
|
+
headers: { upgrade: "websocket" },
|
|
882
|
+
})
|
|
883
|
+
const executor = WebSocketTransport.makeDirect({
|
|
884
|
+
open: () =>
|
|
885
|
+
Effect.succeed({
|
|
886
|
+
http,
|
|
887
|
+
sendText: () => Effect.void,
|
|
888
|
+
messages: Stream.make(frame),
|
|
889
|
+
close: Effect.void,
|
|
890
|
+
}),
|
|
891
|
+
})
|
|
892
|
+
const execution = yield* executor.execute({
|
|
893
|
+
id: "exchange_error",
|
|
894
|
+
connect: { url: "wss://provider.test/responses", headers: Headers.empty },
|
|
895
|
+
fallback: () => Stream.empty,
|
|
896
|
+
driver: {
|
|
897
|
+
create: () => Effect.succeed({ message: "create", mode: "full" }),
|
|
898
|
+
observe: () =>
|
|
899
|
+
Effect.succeed({
|
|
900
|
+
type: "provider-failure",
|
|
901
|
+
error: new AIError({
|
|
902
|
+
reason: new InvalidProviderOutputError({
|
|
903
|
+
message: "Driver failed",
|
|
904
|
+
cause,
|
|
905
|
+
body: "narrowed",
|
|
906
|
+
}),
|
|
907
|
+
}),
|
|
908
|
+
}),
|
|
909
|
+
},
|
|
910
|
+
})
|
|
911
|
+
const error = yield* execution.frames.pipe(Stream.runDrain, Effect.flip)
|
|
912
|
+
|
|
913
|
+
expect(error.message).toBe("Driver failed")
|
|
914
|
+
expect(error.reason.body).toBe(frame)
|
|
915
|
+
expect(error.reason.cause).toBe(cause)
|
|
916
|
+
expect(error.reason.http).toBe(http)
|
|
917
|
+
expect(execution.http).toBe(http)
|
|
918
|
+
}),
|
|
919
|
+
)
|
|
920
|
+
|
|
921
|
+
it.effect("retains diagnostic fields when annotating transport delivery", () =>
|
|
922
|
+
Effect.gen(function* () {
|
|
923
|
+
const cause = new Error("connection closed")
|
|
924
|
+
const executor = WebSocketTransport.makeDirect({
|
|
925
|
+
open: () =>
|
|
926
|
+
Effect.succeed({
|
|
927
|
+
sendText: () => Effect.void,
|
|
928
|
+
messages: Stream.fail(
|
|
929
|
+
new AIError({
|
|
930
|
+
reason: new TransportError({
|
|
931
|
+
message: "Socket closed",
|
|
932
|
+
transport: "websocket",
|
|
933
|
+
operation: "read",
|
|
934
|
+
phase: "close",
|
|
935
|
+
recovery: "retry-full",
|
|
936
|
+
body: "server close detail",
|
|
937
|
+
cause,
|
|
938
|
+
}),
|
|
939
|
+
}),
|
|
940
|
+
),
|
|
941
|
+
close: Effect.void,
|
|
942
|
+
}),
|
|
943
|
+
})
|
|
944
|
+
const execution = yield* executor.execute({
|
|
945
|
+
id: "exchange_closed",
|
|
946
|
+
connect: { url: "wss://provider.test/responses", headers: Headers.empty },
|
|
947
|
+
fallback: () => Stream.empty,
|
|
948
|
+
driver: {
|
|
949
|
+
create: () => Effect.succeed({ message: "create", mode: "full" }),
|
|
950
|
+
observe: (_create, frame) => Effect.succeed({ type: "frame", frame }),
|
|
951
|
+
},
|
|
952
|
+
})
|
|
953
|
+
const error = yield* execution.frames.pipe(Stream.runDrain, Effect.flip)
|
|
954
|
+
|
|
955
|
+
expect(error.message).toBe("Socket closed")
|
|
956
|
+
expect(error.reason.body).toBe("server close detail")
|
|
957
|
+
expect(error.reason.cause).toBe(cause)
|
|
958
|
+
expect(error.reason).toMatchObject({ phase: "close", delivery: "ambiguous", recovery: "retry-full" })
|
|
959
|
+
expect(error.reason.http).toBeUndefined()
|
|
960
|
+
}),
|
|
961
|
+
)
|
|
962
|
+
|
|
963
|
+
it.effect("runs a channel driver through the direct executor", () =>
|
|
964
|
+
Effect.gen(function* () {
|
|
965
|
+
const sent = yield* Ref.make("")
|
|
966
|
+
const closed = yield* Ref.make(false)
|
|
967
|
+
const observed = yield* Ref.make(0)
|
|
968
|
+
const webSocket = WebSocketTransport.makeDirect({
|
|
969
|
+
open: () =>
|
|
970
|
+
Effect.succeed({
|
|
971
|
+
sendText: (message) => Ref.set(sent, message),
|
|
972
|
+
messages: Stream.make("one", "done", "late"),
|
|
973
|
+
close: Ref.set(closed, true),
|
|
974
|
+
}),
|
|
975
|
+
})
|
|
976
|
+
const received = yield* Effect.scoped(
|
|
977
|
+
Effect.gen(function* () {
|
|
978
|
+
const execution = yield* webSocket.execute({
|
|
979
|
+
id: "exchange_1",
|
|
980
|
+
connect: { url: "wss://api.openai.test/v1/responses", headers: Headers.empty },
|
|
981
|
+
fallback: () => Stream.empty,
|
|
982
|
+
driver: {
|
|
983
|
+
create: () => Effect.succeed({ message: "create", mode: "full" }),
|
|
984
|
+
observe: (_create, frame) =>
|
|
985
|
+
Ref.update(observed, (value) => value + 1).pipe(
|
|
986
|
+
Effect.as(
|
|
987
|
+
frame === "done" ? { type: "completed" as const, frame } : { type: "frame" as const, frame },
|
|
988
|
+
),
|
|
989
|
+
),
|
|
990
|
+
},
|
|
991
|
+
})
|
|
992
|
+
return yield* Stream.runCollect(execution.frames)
|
|
993
|
+
}),
|
|
994
|
+
)
|
|
995
|
+
|
|
996
|
+
expect(Array.from(received)).toEqual(["one", "done"])
|
|
997
|
+
expect(yield* Ref.get(sent)).toBe("create")
|
|
998
|
+
expect(yield* Ref.get(observed)).toBe(2)
|
|
999
|
+
expect(yield* Ref.get(closed)).toBe(true)
|
|
1000
|
+
}),
|
|
1001
|
+
)
|
|
1002
|
+
|
|
1003
|
+
it.effect("rejects a closed socket before attempting to send", () =>
|
|
1004
|
+
Effect.gen(function* () {
|
|
1005
|
+
class ClosedBeforeSend extends EventTarget {
|
|
1006
|
+
readyState = globalThis.WebSocket.OPEN
|
|
1007
|
+
sends = 0
|
|
1008
|
+
send() {
|
|
1009
|
+
this.sends++
|
|
1010
|
+
}
|
|
1011
|
+
close() {}
|
|
1012
|
+
}
|
|
1013
|
+
const socket = new ClosedBeforeSend()
|
|
1014
|
+
const connection = yield* WebSocketTransport.fromWebSocket(socket, {
|
|
1015
|
+
url: "wss://api.openai.test/v1/responses",
|
|
1016
|
+
headers: Headers.empty,
|
|
1017
|
+
})
|
|
1018
|
+
socket.readyState = globalThis.WebSocket.CLOSED
|
|
1019
|
+
|
|
1020
|
+
const error = yield* connection.sendText("create").pipe(Effect.flip)
|
|
1021
|
+
|
|
1022
|
+
expect(error.reason).toMatchObject({ _tag: "Transport", phase: "send", delivery: "not-sent" })
|
|
1023
|
+
expect(socket.sends).toBe(0)
|
|
1024
|
+
yield* connection.close
|
|
1025
|
+
}),
|
|
1026
|
+
)
|
|
1027
|
+
|
|
1028
|
+
it.effect("uses HTTP when no per-call WebSocket executor is provided", () =>
|
|
1029
|
+
Effect.gen(function* () {
|
|
1030
|
+
const response = yield* LLMClient.generate(request).pipe(Effect.provide(fixedResponse(sseEvents(...frames))))
|
|
1031
|
+
|
|
1032
|
+
expect(response.text).toBe("Hi")
|
|
1033
|
+
}),
|
|
1034
|
+
)
|
|
1035
|
+
|
|
1036
|
+
it.effect("commits channel execution only after complete consumption", () =>
|
|
1037
|
+
Effect.gen(function* () {
|
|
1038
|
+
const commits = yield* Ref.make(0)
|
|
1039
|
+
const executor = (input: Stream.Stream<string, AIError>): WebSocketChannelExecutor => ({
|
|
1040
|
+
execute: () =>
|
|
1041
|
+
Effect.succeed({
|
|
1042
|
+
frames: input,
|
|
1043
|
+
complete: Ref.update(commits, (value) => value + 1),
|
|
1044
|
+
}),
|
|
1045
|
+
})
|
|
1046
|
+
|
|
1047
|
+
const response = yield* LLMClient.generate(request, {
|
|
1048
|
+
webSocket: executor(Stream.fromArray(frames)),
|
|
1049
|
+
}).pipe(Effect.provide(fixedResponse("")))
|
|
1050
|
+
expect(response.text).toBe("Hi")
|
|
1051
|
+
expect(yield* Ref.get(commits)).toBe(1)
|
|
1052
|
+
|
|
1053
|
+
yield* LLMClient.generate(request, { webSocket: executor(Stream.make("not-json")) }).pipe(
|
|
1054
|
+
Effect.provide(fixedResponse("")),
|
|
1055
|
+
Effect.flip,
|
|
1056
|
+
)
|
|
1057
|
+
expect(yield* Ref.get(commits)).toBe(1)
|
|
1058
|
+
|
|
1059
|
+
yield* LLMClient.stream(request, { webSocket: executor(Stream.fromArray(frames)) }).pipe(
|
|
1060
|
+
Stream.take(1),
|
|
1061
|
+
Stream.runDrain,
|
|
1062
|
+
Effect.provide(fixedResponse("")),
|
|
1063
|
+
)
|
|
1064
|
+
expect(yield* Ref.get(commits)).toBe(1)
|
|
1065
|
+
}),
|
|
1066
|
+
)
|
|
1067
|
+
|
|
1068
|
+
it.effect("does not commit interrupted channel execution", () =>
|
|
1069
|
+
Effect.gen(function* () {
|
|
1070
|
+
const commits = yield* Ref.make(0)
|
|
1071
|
+
const started = yield* Deferred.make<void>()
|
|
1072
|
+
const executor: WebSocketChannelExecutor = {
|
|
1073
|
+
execute: () =>
|
|
1074
|
+
Effect.succeed({
|
|
1075
|
+
frames: Stream.fromEffect(
|
|
1076
|
+
Deferred.succeed(started, undefined).pipe(
|
|
1077
|
+
Effect.as(JSON.stringify({ type: "response.created", response: { id: "resp_1" } })),
|
|
1078
|
+
),
|
|
1079
|
+
).pipe(Stream.concat(Stream.never)),
|
|
1080
|
+
complete: Ref.update(commits, (value) => value + 1),
|
|
1081
|
+
}),
|
|
1082
|
+
}
|
|
1083
|
+
const fiber = yield* LLMClient.stream(request, { webSocket: executor }).pipe(
|
|
1084
|
+
Stream.runDrain,
|
|
1085
|
+
Effect.provide(fixedResponse("")),
|
|
1086
|
+
Effect.forkChild({ startImmediately: true }),
|
|
1087
|
+
)
|
|
1088
|
+
|
|
1089
|
+
yield* Deferred.await(started)
|
|
1090
|
+
yield* Fiber.interrupt(fiber)
|
|
1091
|
+
|
|
1092
|
+
expect(yield* Ref.get(commits)).toBe(0)
|
|
1093
|
+
}),
|
|
1094
|
+
)
|
|
1095
|
+
})
|