@zyro-sec/ai 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +23 -0
- package/README.md +1810 -2
- package/example/tutorial.ts +284 -0
- package/package.json +40 -4
- package/script/pack.ts +5 -0
- package/script/recording-cost-report.ts +250 -0
- package/script/setup-recording-env.ts +602 -0
- package/src/ai-client.ts +28 -0
- package/src/cache-policy.ts +249 -0
- package/src/decision-client.ts +88 -0
- package/src/decision.ts +335 -0
- package/src/effect.ts +44 -0
- package/src/effort-updates.ts +25 -0
- package/src/embedding-client.ts +46 -0
- package/src/embedding.ts +167 -0
- package/src/experimental/cloudflare-run-extraction.ts +112 -0
- package/src/experimental/extraction.ts +190 -0
- package/src/experimental/realtime.ts +211 -0
- package/src/experimental.ts +51 -0
- package/src/generation.ts +210 -0
- package/src/image-client.ts +89 -0
- package/src/image.ts +236 -0
- package/src/index.ts +363 -0
- package/src/llm.ts +364 -0
- package/src/loop.ts +214 -0
- package/src/media-client.ts +94 -0
- package/src/media-model.ts +129 -0
- package/src/media.ts +408 -0
- package/src/protocols/alibaba-chat.ts +95 -0
- package/src/protocols/alibaba-images.ts +126 -0
- package/src/protocols/alibaba-messages.ts +49 -0
- package/src/protocols/alibaba-responses.ts +86 -0
- package/src/protocols/anthropic-messages.ts +1664 -0
- package/src/protocols/assemblyai-transcription.ts +209 -0
- package/src/protocols/bedrock-converse.ts +984 -0
- package/src/protocols/bedrock-event-stream.ts +147 -0
- package/src/protocols/cartesia-speech.ts +182 -0
- package/src/protocols/cloudflare-run-decisions.ts +55 -0
- package/src/protocols/cloudflare-workers-ai-images.ts +124 -0
- package/src/protocols/cohere-chat.ts +353 -0
- package/src/protocols/deepgram-speech.ts +148 -0
- package/src/protocols/deepgram-transcription.ts +179 -0
- package/src/protocols/elevenlabs-speech.ts +207 -0
- package/src/protocols/elevenlabs-transcription.ts +211 -0
- package/src/protocols/gemini.ts +908 -0
- package/src/protocols/google-decisions.ts +179 -0
- package/src/protocols/google-embed-content.ts +165 -0
- package/src/protocols/google-images.ts +255 -0
- package/src/protocols/google-interactions-video.ts +264 -0
- package/src/protocols/google-interactions.ts +904 -0
- package/src/protocols/google-speech.ts +157 -0
- package/src/protocols/google-transcription.ts +206 -0
- package/src/protocols/google-vertex-predict-embeddings.ts +104 -0
- package/src/protocols/index.ts +21 -0
- package/src/protocols/meta-images.ts +162 -0
- package/src/protocols/meta-messages.ts +67 -0
- package/src/protocols/meta-responses.ts +249 -0
- package/src/protocols/minimax-images.ts +215 -0
- package/src/protocols/minimax-video.ts +406 -0
- package/src/protocols/mistral-chat.ts +768 -0
- package/src/protocols/open-responses-channel.ts +198 -0
- package/src/protocols/open-responses-continuation.ts +218 -0
- package/src/protocols/open-responses.ts +1636 -0
- package/src/protocols/openai-chat.ts +1431 -0
- package/src/protocols/openai-compatible-chat.ts +22 -0
- package/src/protocols/openai-compatible-responses.ts +21 -0
- package/src/protocols/openai-decisions.ts +174 -0
- package/src/protocols/openai-embeddings.ts +105 -0
- package/src/protocols/openai-freeform.ts +287 -0
- package/src/protocols/openai-images.ts +442 -0
- package/src/protocols/openai-responses.ts +442 -0
- package/src/protocols/openai-speech.ts +164 -0
- package/src/protocols/openai-transcription.ts +295 -0
- package/src/protocols/openrouter-video.ts +215 -0
- package/src/protocols/seedance-video.ts +301 -0
- package/src/protocols/shared.ts +552 -0
- package/src/protocols/system-one.ts +335 -0
- package/src/protocols/utils/bedrock-auth.ts +147 -0
- package/src/protocols/utils/bedrock-cache.ts +56 -0
- package/src/protocols/utils/bedrock-media.ts +121 -0
- package/src/protocols/utils/cache.ts +44 -0
- package/src/protocols/utils/claude-model.ts +19 -0
- package/src/protocols/utils/gateway-protocol.ts +92 -0
- package/src/protocols/utils/gemini-generate-content.ts +172 -0
- package/src/protocols/utils/gemini-json-schema.ts +77 -0
- package/src/protocols/utils/image-sizing.ts +117 -0
- package/src/protocols/utils/lifecycle.ts +120 -0
- package/src/protocols/utils/media-input.ts +98 -0
- package/src/protocols/utils/mistral-tool-id.ts +34 -0
- package/src/protocols/utils/open-responses-options.ts +82 -0
- package/src/protocols/utils/partial-json-options.ts +62 -0
- package/src/protocols/utils/partial-json.ts +283 -0
- package/src/protocols/utils/responses-checkpoint.ts +115 -0
- package/src/protocols/utils/responses-compaction.ts +210 -0
- package/src/protocols/utils/responses-hosted-tools.ts +104 -0
- package/src/protocols/utils/speaker-turns.ts +10 -0
- package/src/protocols/utils/speech-stream.ts +111 -0
- package/src/protocols/utils/tool-schema.ts +115 -0
- package/src/protocols/utils/tool-stream.ts +240 -0
- package/src/protocols/venice-chat.ts +356 -0
- package/src/protocols/xai-images.ts +137 -0
- package/src/protocols/xai-responses.ts +106 -0
- package/src/protocols/xai-video.ts +232 -0
- package/src/protocols/zai-chat.ts +71 -0
- package/src/protocols/zai-images.ts +120 -0
- package/src/protocols/zai-messages.ts +34 -0
- package/src/protocols.ts +1 -0
- package/src/provider-error.ts +291 -0
- package/src/provider-package.ts +32 -0
- package/src/providers/alibaba/chat.ts +1 -0
- package/src/providers/alibaba/embeddings.ts +2 -0
- package/src/providers/alibaba/images.ts +2 -0
- package/src/providers/alibaba/messages.ts +3 -0
- package/src/providers/alibaba/responses.ts +3 -0
- package/src/providers/alibaba.ts +177 -0
- package/src/providers/amazon-bedrock/mantle/chat.ts +2 -0
- package/src/providers/amazon-bedrock/mantle/messages.ts +2 -0
- package/src/providers/amazon-bedrock/mantle/responses.ts +2 -0
- package/src/providers/amazon-bedrock/mantle.ts +2 -0
- package/src/providers/amazon-bedrock-mantle.ts +192 -0
- package/src/providers/amazon-bedrock.ts +81 -0
- package/src/providers/anthropic-compatible.ts +80 -0
- package/src/providers/anthropic.ts +66 -0
- package/src/providers/assemblyai.ts +32 -0
- package/src/providers/azure/chat.ts +2 -0
- package/src/providers/azure/embeddings.ts +2 -0
- package/src/providers/azure/images.ts +2 -0
- package/src/providers/azure/messages.ts +2 -0
- package/src/providers/azure/responses.ts +2 -0
- package/src/providers/azure.ts +240 -0
- package/src/providers/baseten/decisions.ts +2 -0
- package/src/providers/baseten.ts +88 -0
- package/src/providers/byteplus/videos.ts +2 -0
- package/src/providers/byteplus.ts +39 -0
- package/src/providers/cartesia.ts +28 -0
- package/src/providers/cerebras.ts +56 -0
- package/src/providers/cloudflare-ai-gateway/decisions.ts +2 -0
- package/src/providers/cloudflare-ai-gateway.ts +199 -0
- package/src/providers/cloudflare-shared.ts +29 -0
- package/src/providers/cloudflare-workers-ai/decisions.ts +2 -0
- package/src/providers/cloudflare-workers-ai/images.ts +2 -0
- package/src/providers/cloudflare-workers-ai.ts +104 -0
- package/src/providers/cohere/chat.ts +8 -0
- package/src/providers/cohere/embeddings.ts +2 -0
- package/src/providers/cohere.ts +72 -0
- package/src/providers/deepgram.ts +33 -0
- package/src/providers/deepinfra/embeddings.ts +2 -0
- package/src/providers/deepinfra.ts +76 -0
- package/src/providers/deepseek.ts +54 -0
- package/src/providers/digitalocean/decisions.ts +2 -0
- package/src/providers/digitalocean/embeddings.ts +2 -0
- package/src/providers/digitalocean/images.ts +2 -0
- package/src/providers/digitalocean/responses.ts +4 -0
- package/src/providers/digitalocean.ts +144 -0
- package/src/providers/elevenlabs.ts +35 -0
- package/src/providers/fireworks/embeddings.ts +2 -0
- package/src/providers/fireworks.ts +66 -0
- package/src/providers/google/decisions.ts +2 -0
- package/src/providers/google/embeddings.ts +2 -0
- package/src/providers/google/images.ts +2 -0
- package/src/providers/google/interactions.ts +13 -0
- package/src/providers/google/videos.ts +2 -0
- package/src/providers/google-vertex/chat.ts +2 -0
- package/src/providers/google-vertex/embeddings.ts +2 -0
- package/src/providers/google-vertex/gemini.ts +2 -0
- package/src/providers/google-vertex/images.ts +2 -0
- package/src/providers/google-vertex/interactions.ts +2 -0
- package/src/providers/google-vertex/messages.ts +2 -0
- package/src/providers/google-vertex/mistral.ts +2 -0
- package/src/providers/google-vertex/responses.ts +2 -0
- package/src/providers/google-vertex-chat.ts +63 -0
- package/src/providers/google-vertex-interactions.ts +104 -0
- package/src/providers/google-vertex-messages.ts +99 -0
- package/src/providers/google-vertex-mistral.ts +79 -0
- package/src/providers/google-vertex-responses.ts +64 -0
- package/src/providers/google-vertex-shared.ts +176 -0
- package/src/providers/google-vertex.ts +228 -0
- package/src/providers/google.ts +121 -0
- package/src/providers/groq.ts +98 -0
- package/src/providers/index.ts +45 -0
- package/src/providers/meta/chat.ts +2 -0
- package/src/providers/meta/images.ts +2 -0
- package/src/providers/meta/messages.ts +2 -0
- package/src/providers/meta/responses.ts +2 -0
- package/src/providers/meta.ts +161 -0
- package/src/providers/minimax/chat.ts +8 -0
- package/src/providers/minimax/images.ts +4 -0
- package/src/providers/minimax/messages.ts +1 -0
- package/src/providers/minimax/responses.ts +8 -0
- package/src/providers/minimax/videos.ts +4 -0
- package/src/providers/minimax.ts +162 -0
- package/src/providers/mistral.ts +40 -0
- package/src/providers/moonshot/chat.ts +1 -0
- package/src/providers/moonshot/messages.ts +8 -0
- package/src/providers/moonshot/responses.ts +8 -0
- package/src/providers/moonshot.ts +134 -0
- package/src/providers/open-responses-options.ts +4 -0
- package/src/providers/openai/chat.ts +2 -0
- package/src/providers/openai/embeddings.ts +2 -0
- package/src/providers/openai/images.ts +2 -0
- package/src/providers/openai/responses.ts +2 -0
- package/src/providers/openai-compatible/decisions.ts +2 -0
- package/src/providers/openai-compatible/embeddings.ts +2 -0
- package/src/providers/openai-compatible/images.ts +2 -0
- package/src/providers/openai-compatible/responses.ts +1 -0
- package/src/providers/openai-compatible-responses.ts +52 -0
- package/src/providers/openai-compatible.ts +108 -0
- package/src/providers/openai-options.ts +66 -0
- package/src/providers/openai.ts +207 -0
- package/src/providers/opencode/decisions.ts +2 -0
- package/src/providers/opencode.ts +45 -0
- package/src/providers/openrouter/decisions.ts +2 -0
- package/src/providers/openrouter/embeddings.ts +2 -0
- package/src/providers/openrouter/images.ts +2 -0
- package/src/providers/openrouter/responses.ts +3 -0
- package/src/providers/openrouter/videos.ts +2 -0
- package/src/providers/openrouter.ts +347 -0
- package/src/providers/settings.ts +54 -0
- package/src/providers/togetherai.ts +53 -0
- package/src/providers/typesafe-ai/decisions.ts +2 -0
- package/src/providers/typesafe-ai.ts +45 -0
- package/src/providers/venice/responses.ts +4 -0
- package/src/providers/venice.ts +93 -0
- package/src/providers/vercel-ai-gateway/chat.ts +2 -0
- package/src/providers/vercel-ai-gateway/decisions.ts +2 -0
- package/src/providers/vercel-ai-gateway/embeddings.ts +2 -0
- package/src/providers/vercel-ai-gateway/images.ts +2 -0
- package/src/providers/vercel-ai-gateway/messages.ts +2 -0
- package/src/providers/vercel-ai-gateway/responses.ts +2 -0
- package/src/providers/vercel-ai-gateway.ts +300 -0
- package/src/providers/volcengine/videos.ts +2 -0
- package/src/providers/volcengine.ts +39 -0
- package/src/providers/xai/images.ts +2 -0
- package/src/providers/xai/videos.ts +2 -0
- package/src/providers/xai.ts +125 -0
- package/src/providers/zai/chat.ts +1 -0
- package/src/providers/zai/images.ts +2 -0
- package/src/providers/zai-coding-plan/chat.ts +1 -0
- package/src/providers/zai-coding-plan/messages.ts +8 -0
- package/src/providers/zai-coding-plan/responses.ts +8 -0
- package/src/providers/zai-coding-plan.ts +86 -0
- package/src/providers/zai.ts +73 -0
- package/src/providers.ts +1 -0
- package/src/public.ts +204 -0
- package/src/route/auth-options.ts +62 -0
- package/src/route/auth.ts +164 -0
- package/src/route/client.ts +700 -0
- package/src/route/decision.ts +150 -0
- package/src/route/embedding.ts +175 -0
- package/src/route/endpoint.ts +63 -0
- package/src/route/executor-service.ts +191 -0
- package/src/route/executor.ts +361 -0
- package/src/route/framing.ts +112 -0
- package/src/route/index.ts +47 -0
- package/src/route/media-protocol.ts +321 -0
- package/src/route/media.ts +507 -0
- package/src/route/protocol.ts +97 -0
- package/src/route/transport/http.ts +103 -0
- package/src/route/transport/index.ts +59 -0
- package/src/route/transport/websocket-channel.ts +51 -0
- package/src/route/transport/websocket.ts +443 -0
- package/src/route.ts +1 -0
- package/src/schema/errors.ts +246 -0
- package/src/schema/events.ts +744 -0
- package/src/schema/ids.ts +24 -0
- package/src/schema/index.ts +5 -0
- package/src/schema/messages.ts +529 -0
- package/src/schema/options.ts +445 -0
- package/src/speech-client.ts +25 -0
- package/src/speech.ts +211 -0
- package/src/testing.ts +218 -0
- package/src/tool-history.ts +91 -0
- package/src/tool-runtime.ts +107 -0
- package/src/tool-updates.ts +139 -0
- package/src/tool.ts +281 -0
- package/src/transcription-client.ts +19 -0
- package/src/transcription.ts +234 -0
- package/src/utils/bytes.ts +9 -0
- package/src/utils/json.ts +5 -0
- package/src/utils/media-type.ts +93 -0
- package/src/utils/provider-codes.ts +43 -0
- package/src/utils/record.ts +3 -0
- package/src/utils/sanitize.ts +33 -0
- package/src/video-client.ts +66 -0
- package/src/video.ts +181 -0
- package/test/adapter.test.ts +180 -0
- package/test/auth-options.types.ts +283 -0
- package/test/auth.test.ts +112 -0
- package/test/cache-policy.test.ts +578 -0
- package/test/compaction-http.test.ts +96 -0
- package/test/compaction.test.ts +107 -0
- package/test/compile.test.ts +600 -0
- package/test/continuation-scenarios.ts +115 -0
- package/test/decision.test.ts +983 -0
- package/test/decision.types.ts +117 -0
- package/test/effort-updates.test.ts +574 -0
- package/test/embedding.test.ts +455 -0
- package/test/endpoint.test.ts +58 -0
- package/test/error-partial.test.ts +140 -0
- package/test/executor.test.ts +1095 -0
- package/test/exports.test.ts +222 -0
- package/test/extraction.test.ts +227 -0
- package/test/fixtures/audio/dialog.mp3 +0 -0
- package/test/fixtures/audio/hello.mp3 +0 -0
- package/test/fixtures/images/edit-source.jpg +0 -0
- package/test/fixtures/media/restroom.png +0 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-returns-a-json-object.json +34 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-minimal-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-none-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-chat/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-images/edits-an-image.json +33 -0
- package/test/fixtures/recordings/alibaba-images/generates-qwen-image-images.json +33 -0
- package/test/fixtures/recordings/alibaba-images/generates-wan-images.json +33 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-follows-a-json-schema.json +34 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-messages/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-7-plus-streams-thinking-disabled.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-7-plus-streams-thinking-enabled.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-flash-reads-image-bytes.json +34 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-continues-a-stored-response.json +53 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-obeys-named-tool-choice.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-replays-reasoning-through-a-tool-loop-and-follow-up.json +73 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-default-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-high-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-low-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-max-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-medium-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-minimal-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-none-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-streams-xhigh-effort.json +36 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-uses-hosted-code-interpreter.json +35 -0
- package/test/fixtures/recordings/alibaba-responses/qwen-3-8-max-uses-hosted-web-search-and-extraction.json +36 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-text.json +40 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-tool-call.json +41 -0
- package/test/fixtures/recordings/anthropic-compatible-messages/minimax-m3-anthropic-compatible-tool-loop.json +60 -0
- package/test/fixtures/recordings/anthropic-messages/anthropic-opus-4-7-image-tool-result.json +43 -0
- package/test/fixtures/recordings/anthropic-messages-cache/keeps-a-long-tool-turn-inside-the-cache-lookback.json +48 -0
- package/test/fixtures/recordings/anthropic-messages-cache/writes-then-reads-cache-control-on-identical-second-call.json +48 -0
- package/test/fixtures/recordings/assemblyai-transcription/uploads-submits-and-polls-a-transcript.json +98 -0
- package/test/fixtures/recordings/azure/chat-streams-text-from-a-foundry-models-url.json +31 -0
- package/test/fixtures/recordings/azure/chat-streams-text.json +28 -0
- package/test/fixtures/recordings/azure/messages-calls-a-tool.json +31 -0
- package/test/fixtures/recordings/azure/messages-streams-text.json +31 -0
- package/test/fixtures/recordings/azure/responses-calls-a-tool.json +31 -0
- package/test/fixtures/recordings/azure/responses-continues-after-a-tool-result.json +31 -0
- package/test/fixtures/recordings/azure/responses-streams-text.json +31 -0
- package/test/fixtures/recordings/baseten-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/bedrock-converse/continues-after-parallel-tool-results.json +36 -0
- package/test/fixtures/recordings/bedrock-converse/drives-a-tool-loop.json +55 -0
- package/test/fixtures/recordings/bedrock-converse/streams-a-tool-call.json +29 -0
- package/test/fixtures/recordings/bedrock-converse/streams-text.json +29 -0
- package/test/fixtures/recordings/bedrock-converse-cache/writes-then-reads-cachepoint-on-identical-second-call.json +48 -0
- package/test/fixtures/recordings/bedrock-converse-options/constrains-claude-output-to-a-json-schema.json +33 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-claude-effort-with-adaptive-thinking-service-tier-and-request-metadata.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-gpt-oss-reasoning-effort-with-the-priority-tier.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-options/sends-nova-2-reasoning-effort.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-thinking-binding/accepts-the-default-binding-with-no-thinking-configured.json +34 -0
- package/test/fixtures/recordings/bedrock-converse-thinking-binding/keeps-a-session-working-after-the-system-prompt-changes.json +71 -0
- package/test/fixtures/recordings/bedrock-mantle/streams-text.json +33 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/applies-mid-conversation-effort-updates-and-thinking-block-binding-on-opus-5-5.json +57 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/lowers-system-updates-to-wrapped-user-text-on-haiku-4-5-with-budget-thinking.json +37 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/replays-signed-thinking-through-a-tool-loop-and-native-system-update.json +59 -0
- package/test/fixtures/recordings/bedrock-mantle-messages/strips-unsupported-mid-conversation-effort-updates-on-opus-5-0.json +37 -0
- package/test/fixtures/recordings/cartesia-speech/generates-speech.json +34 -0
- package/test/fixtures/recordings/cartesia-speech/streams-speech-with-timestamps.json +33 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-text.json +32 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-tool-call.json +32 -0
- package/test/fixtures/recordings/cerebras-chat/cerebras-gpt-oss-120b-tool-loop.json +50 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-claude-haiku-4-5-text.json +38 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-claude-haiku-4-5-tool-loop.json +58 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-openai-gpt-5-nano-text.json +37 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-openai-gpt-5-nano-tool-loop.json +56 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-workers-ai-gpt-oss-20b-tools-tool-call.json +32 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway/cloudflare-ai-gateway-workers-ai-llama-3-1-8b-text.json +32 -0
- package/test/fixtures/recordings/cloudflare-ai-gateway-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai/cloudflare-workers-ai-gpt-oss-20b-tools-tool-call.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai/cloudflare-workers-ai-llama-3-1-8b-text.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-extraction/extracts-invoice-fields.json +33 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-images/generates-a-flux-2-image-from-multipart-fields.json +32 -0
- package/test/fixtures/recordings/cloudflare-workers-ai-images/generates-a-raw-binary-image.json +33 -0
- package/test/fixtures/recordings/cohere/continues-a-native-tool-call.json +49 -0
- package/test/fixtures/recordings/cohere/streams-compatible-chat-reasoning.json +31 -0
- package/test/fixtures/recordings/cohere/streams-native-text-and-usage.json +31 -0
- package/test/fixtures/recordings/cohere/streams-native-thinking-with-a-budget.json +31 -0
- package/test/fixtures/recordings/cohere-embedding/embeds-text-through-the-compatibility-api.json +33 -0
- package/test/fixtures/recordings/deepgram-speech/generates-speech.json +36 -0
- package/test/fixtures/recordings/deepgram-speech/streams-speech.json +36 -0
- package/test/fixtures/recordings/deepgram-transcription/splits-utterances-at-speaker-changes.json +32 -0
- package/test/fixtures/recordings/deepgram-transcription/transcribes-raw-audio-with-speakers-and-word-timestamps.json +50 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-text.json +32 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-tool-call.json +32 -0
- package/test/fixtures/recordings/deepinfra-chat/deepinfra-llama-3-3-70b-tool-loop.json +50 -0
- package/test/fixtures/recordings/digitalocean-chat/gpt-nano-continues-a-tool-call-with-cache-markers.json +54 -0
- package/test/fixtures/recordings/digitalocean-chat/gpt-nano-reuses-a-cached-prompt.json +53 -0
- package/test/fixtures/recordings/digitalocean-chat/haiku-continues-a-tool-call-with-cache-markers.json +54 -0
- package/test/fixtures/recordings/digitalocean-chat/haiku-reuses-a-cached-prompt.json +53 -0
- package/test/fixtures/recordings/digitalocean-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/digitalocean-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/digitalocean-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/digitalocean-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/elevenlabs-speech/generates-speech.json +35 -0
- package/test/fixtures/recordings/elevenlabs-speech/streams-speech-with-timestamps.json +34 -0
- package/test/fixtures/recordings/elevenlabs-transcription/groups-diarized-words-into-speaker-turns.json +32 -0
- package/test/fixtures/recordings/elevenlabs-transcription/transcribes-audio-with-word-timestamps.json +50 -0
- package/test/fixtures/recordings/gemini/gemini-2-5-flash-image.json +32 -0
- package/test/fixtures/recordings/gemini-cache/reports-cachedcontenttokencount-on-identical-second-call.json +46 -0
- package/test/fixtures/recordings/google-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/google-embedding/embeds-an-image-and-text-into-one-vector-each.json +32 -0
- package/test/fixtures/recordings/google-embedding/embeds-text-through-batchembedcontents.json +32 -0
- package/test/fixtures/recordings/google-embedding/maps-inputtype-to-a-task-type-for-gemini-embedding-001.json +50 -0
- package/test/fixtures/recordings/google-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/google-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/google-interactions/continues-tool-results-with-previous-interaction-id.json +66 -0
- package/test/fixtures/recordings/google-interactions/replays-native-tool-results-and-signatures-statelessly.json +50 -0
- package/test/fixtures/recordings/google-interactions/streams-reasoning-and-retains-thought-signatures.json +32 -0
- package/test/fixtures/recordings/google-interactions/streams-text-and-reports-usage.json +32 -0
- package/test/fixtures/recordings/google-interactions-video/generates-a-video.json +96 -0
- package/test/fixtures/recordings/google-speech/generates-speech.json +32 -0
- package/test/fixtures/recordings/google-speech/streams-speech.json +32 -0
- package/test/fixtures/recordings/google-transcription/streams-speaker-turns.json +32 -0
- package/test/fixtures/recordings/google-transcription/transcribes-with-speakers-and-word-timestamps.json +32 -0
- package/test/fixtures/recordings/google-vertex/calls-a-tool.json +32 -0
- package/test/fixtures/recordings/google-vertex/continues-after-a-tool-result.json +32 -0
- package/test/fixtures/recordings/google-vertex/streams-text.json +32 -0
- package/test/fixtures/recordings/google-vertex-embedding/embeds-gemini-embedding-001-one-text-per-predict-request.json +50 -0
- package/test/fixtures/recordings/google-vertex-embedding/embeds-text-through-predict.json +32 -0
- package/test/fixtures/recordings/groq-chat/continues-qwen-parallel-tool-calls.json +47 -0
- package/test/fixtures/recordings/groq-chat/replays-gpt-oss-reasoning-through-a-tool-loop.json +47 -0
- package/test/fixtures/recordings/groq-chat/streams-qwen-parsed-reasoning.json +29 -0
- package/test/fixtures/recordings/groq-chat/streams-text-with-usage.json +29 -0
- package/test/fixtures/recordings/meta-chat/continues-a-generated-tool-call.json +56 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-default-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-high-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-low-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-max-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-medium-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-minimal-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-chat/streams-text-with-xhigh-reasoning.json +29 -0
- package/test/fixtures/recordings/meta-images/edits-image-bytes-and-returns-png.json +29 -0
- package/test/fixtures/recordings/meta-images/generates-default-webp-bytes.json +29 -0
- package/test/fixtures/recordings/meta-images/replays-a-signed-image-handle-for-a-responses-edit.json +55 -0
- package/test/fixtures/recordings/meta-messages/replays-encrypted-thinking-through-a-tool-loop.json +54 -0
- package/test/fixtures/recordings/meta-messages/streams-text-with-adaptive-thinking.json +36 -0
- package/test/fixtures/recordings/meta-messages/streams-text-with-enabled-thinking.json +36 -0
- package/test/fixtures/recordings/meta-responses/replays-encrypted-reasoning-through-a-tool-loop.json +56 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-default-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-high-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-low-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-max-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-medium-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-minimal-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-responses/streams-text-with-xhigh-reasoning.json +37 -0
- package/test/fixtures/recordings/meta-search/searches-and-replays-grounded-messages.json +56 -0
- package/test/fixtures/recordings/meta-search/searches-and-replays-grounded-responses.json +56 -0
- package/test/fixtures/recordings/minimax-chat/m3-continues-a-tool-loop-with-default-thinking.json +56 -0
- package/test/fixtures/recordings/minimax-chat/m3-streams-text-with-thinking-disabled.json +36 -0
- package/test/fixtures/recordings/minimax-images/generates-an-image.json +32 -0
- package/test/fixtures/recordings/minimax-images/generates-from-a-subject-reference.json +32 -0
- package/test/fixtures/recordings/minimax-messages/m2-7-streams-default-thinking.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-continues-a-tool-loop-with-adaptive-thinking.json +56 -0
- package/test/fixtures/recordings/minimax-messages/m3-generates-a-named-tool-call-with-default-thinking-off.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-streams-adaptive-thinking.json +36 -0
- package/test/fixtures/recordings/minimax-messages/m3-streams-text-with-thinking-disabled.json +36 -0
- package/test/fixtures/recordings/minimax-responses/m3-continues-a-tool-loop-with-effort-minimal.json +56 -0
- package/test/fixtures/recordings/minimax-responses/m3-streams-text-with-effort-none.json +36 -0
- package/test/fixtures/recordings/minimax-video/generates-a-hailuo-video-from-a-first-frame.json +176 -0
- package/test/fixtures/recordings/minimax-video/generates-an-h3-video.json +96 -0
- package/test/fixtures/recordings/mistral-chat/drives-a-tool-loop.json +54 -0
- package/test/fixtures/recordings/mistral-chat/replays-native-reasoning.json +47 -0
- package/test/fixtures/recordings/mistral-chat/streams-text-with-usage.json +29 -0
- package/test/fixtures/recordings/mistral-chat-glm/streams-an-indexed-tool-call.json +36 -0
- package/test/fixtures/recordings/moonshot-chat/k3-reads-image-bytes.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-respects-tool-choice-none.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-respects-tool-choice-required.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-returns-native-structured-output.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-default-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-high-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-low-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/k3-streams-text-with-max-effort.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-disabled-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-6-streams-text-with-enabled-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-highspeed-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-highspeed-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k2-7-code-streams-text-with-default-thinking.json +29 -0
- package/test/fixtures/recordings/moonshot-chat/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-messages/k3-reads-image-bytes.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-respects-tool-choice-none.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-respects-tool-choice-required.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-returns-native-structured-output.json +35 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-default-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-high-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-low-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/k3-streams-text-with-max-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-messages/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/moonshot-responses/k3-reads-image-bytes.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-rejects-unsupported-tool-choice-none.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-rejects-unsupported-tool-choice-required.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-returns-native-structured-output.json +35 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-default-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-high-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-low-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/k3-streams-text-with-max-effort.json +36 -0
- package/test/fixtures/recordings/moonshot-responses/kimi-k3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +74 -0
- package/test/fixtures/recordings/openai-compatible-chat/gemini-parallel-tool-signatures.json +54 -0
- package/test/fixtures/recordings/openai-compatible-chat/togetherai-streams-text.json +28 -0
- package/test/fixtures/recordings/openai-compatible-chat/togetherai-streams-tool-call.json +28 -0
- package/test/fixtures/recordings/openai-decision/decides-choice-score-and-predicate-questions-about-json-state.json +33 -0
- package/test/fixtures/recordings/openai-embedding/embeds-text-with-requested-dimensions.json +33 -0
- package/test/fixtures/recordings/openai-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/openai-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/openai-images/streams-a-partial-image-before-the-final-image.json +32 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-image-tool-result.json +42 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-reasoning-continuation.json +58 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-reasoning.json +38 -0
- package/test/fixtures/recordings/openai-responses/openai-responses-gpt-5-5-tool-loop.json +57 -0
- package/test/fixtures/recordings/openai-responses-cache/caches-the-system-prompt-on-gpt-6-2-sol.json +51 -0
- package/test/fixtures/recordings/openai-responses-cache/reports-cached-tokens-on-identical-second-call.json +51 -0
- package/test/fixtures/recordings/openai-responses-images/generates-and-edits-an-image-with-the-hosted-tool.json +50 -0
- package/test/fixtures/recordings/openai-responses-websocket/continues-a-tool-call-over-one-socket.json +588 -0
- package/test/fixtures/recordings/openai-responses-websocket/reconstructs-full-context-after-reconnect.json +167 -0
- package/test/fixtures/recordings/openai-responses-websocket/recovers-from-explicit-continuation-rejection.json +167 -0
- package/test/fixtures/recordings/openai-speech/generates-speech.json +33 -0
- package/test/fixtures/recordings/openai-speech/streams-speech.json +32 -0
- package/test/fixtures/recordings/openai-transcription/diarizes-speakers-into-segments.json +32 -0
- package/test/fixtures/recordings/openai-transcription/returns-whisper-word-timestamps.json +32 -0
- package/test/fixtures/recordings/openai-transcription/streams-text-deltas.json +32 -0
- package/test/fixtures/recordings/openai-transcription/transcribes-with-a-language-hint.json +32 -0
- package/test/fixtures/recordings/opencode-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/openrouter-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/openrouter-images/edits-an-image-through-input-references.json +32 -0
- package/test/fixtures/recordings/openrouter-images/renders-flux-3-from-an-aspect-ratio-and-tier.json +32 -0
- package/test/fixtures/recordings/openrouter-images/renders-gemini-at-the-requested-2k-tier.json +32 -0
- package/test/fixtures/recordings/openrouter-reasoning-tool-loop.json +55 -0
- package/test/fixtures/recordings/openrouter-reasoning.json +29 -0
- package/test/fixtures/recordings/openrouter-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/openrouter-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/openrouter-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/openrouter-video/generates-a-video.json +113 -0
- package/test/fixtures/recordings/pdf/anthropic-tool-result.json +28 -0
- package/test/fixtures/recordings/pdf/anthropic-user-input.json +28 -0
- package/test/fixtures/recordings/pdf/bedrock-tool-result.json +29 -0
- package/test/fixtures/recordings/pdf/bedrock-user-input.json +29 -0
- package/test/fixtures/recordings/pdf/gemini-tool-result.json +53 -0
- package/test/fixtures/recordings/pdf/gemini-user-input.json +28 -0
- package/test/fixtures/recordings/pdf/openai-tool-result.json +35 -0
- package/test/fixtures/recordings/pdf/openai-user-input.json +34 -0
- package/test/fixtures/recordings/pdf/xai-tool-result.json +35 -0
- package/test/fixtures/recordings/pdf/xai-user-input.json +34 -0
- package/test/fixtures/recordings/typesafe-decision/decides-choice-score-and-predicate-questions.json +33 -0
- package/test/fixtures/recordings/venice-chat/claude-opus-4-8-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/deepseek-v4-flash-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/gemini-3-1-pro-preview-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/gemini-preserves-per-call-signatures-through-parallel-tools.json +71 -0
- package/test/fixtures/recordings/venice-chat/openai-gpt-54-mini-preserves-reasoning-through-a-tool-loop-and-follow-up.json +75 -0
- package/test/fixtures/recordings/venice-chat/qwen-disables-reasoning.json +35 -0
- package/test/fixtures/recordings/venice-chat/surfaces-venice-model-errors.json +33 -0
- package/test/fixtures/recordings/venice-responses/calls-a-freeform-text-tool.json +35 -0
- package/test/fixtures/recordings/venice-responses/continues-a-tool-call.json +53 -0
- package/test/fixtures/recordings/venice-responses/streams-text.json +35 -0
- package/test/fixtures/recordings/vercel-ai-gateway-images/generates-an-image.json +32 -0
- package/test/fixtures/recordings/vercel-ai-gateway-images/sizes-grok-through-xai-provider-options.json +32 -0
- package/test/fixtures/recordings/vercel-ai-gateway-reasoning-tool-loop.json +55 -0
- package/test/fixtures/recordings/vercel-ai-gateway-reasoning.json +29 -0
- package/test/fixtures/recordings/vercel-native/automatically-caches-distinct-claude-system-blocks.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-chat-claude-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-chat-muse-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-claude-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-deepseek-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-messages-gemini-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-responses-gpt-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/continues-responses-grok-reasoning-and-tools.json +49 -0
- package/test/fixtures/recordings/vercel-native/rejects-invalid-credentials-without-retryable-classification.json +31 -0
- package/test/fixtures/recordings/xai-images/edits-an-image.json +28 -0
- package/test/fixtures/recordings/xai-images/generates-an-image.json +28 -0
- package/test/fixtures/recordings/xai-video/generates-a-video.json +129 -0
- package/test/fixtures/recordings/zai-chat/glm-4-5-calls-a-tool-without-streaming-arguments.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-4-7-streams-thinking-disabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-4-7-streams-thinking-enabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-high-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-low-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-max-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-medium-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-minimal-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-none-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-thinking-disabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-thinking-enabled.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-2-streams-xhigh-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-flash-reads-image-bytes.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-preserves-reasoning-through-a-tool-loop-and-follow-up.json +64 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-rejects-disabled-thinking.json +27 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-returns-a-json-object.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-default-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-high-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-low-effort.json +28 -0
- package/test/fixtures/recordings/zai-chat/glm-5-3-streams-max-effort.json +28 -0
- package/test/fixtures/recordings/zai-images/generates-an-image.json +28 -0
- package/test/generate-object.test.ts +281 -0
- package/test/generation.test.ts +191 -0
- package/test/google-interactions-video.test.ts +351 -0
- package/test/http-hooks.test.ts +137 -0
- package/test/http-timeout.test.ts +287 -0
- package/test/image-job.test.ts +199 -0
- package/test/image-sizing.test.ts +47 -0
- package/test/image.test.ts +1114 -0
- package/test/image.types.ts +203 -0
- package/test/keyless-auth.test.ts +85 -0
- package/test/lib/effect.ts +50 -0
- package/test/lib/env.ts +30 -0
- package/test/lib/http.ts +141 -0
- package/test/lib/image.ts +29 -0
- package/test/lib/openai-chunks.ts +27 -0
- package/test/lib/sse.ts +20 -0
- package/test/lib/tool-runtime.ts +152 -0
- package/test/llm-option-types.types.ts +153 -0
- package/test/llm.test.ts +286 -0
- package/test/loop-steps.test.ts +77 -0
- package/test/loop-tools.types.ts +79 -0
- package/test/loop.test.ts +425 -0
- package/test/media-input.test.ts +98 -0
- package/test/media-usage.test.ts +13 -0
- package/test/media.test.ts +340 -0
- package/test/minimax-video.test.ts +553 -0
- package/test/openai-freeform.test.ts +252 -0
- package/test/openrouter-video.test.ts +294 -0
- package/test/partial-json.test.ts +58 -0
- package/test/promise-parity.types.ts +83 -0
- package/test/promise.test.ts +632 -0
- package/test/provider/alibaba-capabilities.recorded.test.ts +253 -0
- package/test/provider/alibaba-images.recorded.test.ts +71 -0
- package/test/provider/alibaba-images.test.ts +199 -0
- package/test/provider/alibaba.recorded.test.ts +165 -0
- package/test/provider/alibaba.test.ts +419 -0
- package/test/provider/anthropic-compaction.test.ts +171 -0
- package/test/provider/anthropic-messages-cache.recorded.test.ts +111 -0
- package/test/provider/anthropic-messages.recorded.test.ts +45 -0
- package/test/provider/anthropic-messages.test.ts +2609 -0
- package/test/provider/anthropic-thinking-binding.test.ts +65 -0
- package/test/provider/assemblyai-transcription.recorded.test.ts +39 -0
- package/test/provider/azure.recorded.test.ts +139 -0
- package/test/provider/azure.test.ts +48 -0
- package/test/provider/bedrock-converse-cache.recorded.test.ts +61 -0
- package/test/provider/bedrock-converse-cache.test.ts +168 -0
- package/test/provider/bedrock-converse-options.recorded.test.ts +119 -0
- package/test/provider/bedrock-converse-options.test.ts +149 -0
- package/test/provider/bedrock-converse-thinking-binding.recorded.test.ts +103 -0
- package/test/provider/bedrock-converse-thinking-binding.test.ts +107 -0
- package/test/provider/bedrock-converse.test.ts +2548 -0
- package/test/provider/bedrock-mantle.test.ts +444 -0
- package/test/provider/bedrock-mistral-ids.test.ts +86 -0
- package/test/provider/cartesia-speech.recorded.test.ts +47 -0
- package/test/provider/checkpoint.test.ts +324 -0
- package/test/provider/cloudflare-workers-ai-images.recorded.test.ts +57 -0
- package/test/provider/cloudflare-workers-ai-images.test.ts +155 -0
- package/test/provider/cloudflare.test.ts +330 -0
- package/test/provider/cohere.recorded.test.ts +94 -0
- package/test/provider/cohere.test.ts +301 -0
- package/test/provider/compaction-websocket.test.ts +50 -0
- package/test/provider/compaction.recorded.test.ts +89 -0
- package/test/provider/compaction.test.ts +178 -0
- package/test/provider/conversation-lowering.test.ts +31 -0
- package/test/provider/decision.recorded.test.ts +211 -0
- package/test/provider/deepgram-speech.recorded.test.ts +41 -0
- package/test/provider/deepgram-transcription.recorded.test.ts +47 -0
- package/test/provider/digitalocean.recorded.test.ts +78 -0
- package/test/provider/digitalocean.test.ts +123 -0
- package/test/provider/elevenlabs-speech.recorded.test.ts +54 -0
- package/test/provider/elevenlabs-transcription.recorded.test.ts +50 -0
- package/test/provider/embedding.recorded.test.ts +109 -0
- package/test/provider/empty-tool-choice.test.ts +80 -0
- package/test/provider/error-retention.test.ts +158 -0
- package/test/provider/explicit-compaction.test.ts +503 -0
- package/test/provider/extraction.recorded.test.ts +46 -0
- package/test/provider/freeform-tools.test.ts +446 -0
- package/test/provider/gemini-cache.recorded.test.ts +49 -0
- package/test/provider/gemini-openai-chat.recorded.test.ts +69 -0
- package/test/provider/gemini.test.ts +2336 -0
- package/test/provider/golden.recorded.test.ts +287 -0
- package/test/provider/google-images.recorded.test.ts +53 -0
- package/test/provider/google-interactions-video.recorded.test.ts +48 -0
- package/test/provider/google-interactions.recorded.test.ts +169 -0
- package/test/provider/google-interactions.test.ts +593 -0
- package/test/provider/google-speech.recorded.test.ts +45 -0
- package/test/provider/google-transcription.recorded.test.ts +54 -0
- package/test/provider/google-vertex-interactions.test.ts +307 -0
- package/test/provider/google-vertex.recorded.test.ts +75 -0
- package/test/provider/google-vertex.test.ts +595 -0
- package/test/provider/groq.recorded.test.ts +187 -0
- package/test/provider/groq.test.ts +134 -0
- package/test/provider/image-detail.test.ts +58 -0
- package/test/provider/media-entrypoints.test.ts +618 -0
- package/test/provider/meta-capabilities.test.ts +216 -0
- package/test/provider/meta-images.recorded.test.ts +119 -0
- package/test/provider/meta-messages.recorded.test.ts +121 -0
- package/test/provider/meta-search.recorded.test.ts +97 -0
- package/test/provider/meta.recorded.test.ts +182 -0
- package/test/provider/meta.test.ts +140 -0
- package/test/provider/minimax-images.recorded.test.ts +52 -0
- package/test/provider/minimax-images.test.ts +236 -0
- package/test/provider/minimax-video.recorded.test.ts +83 -0
- package/test/provider/minimax.recorded.test.ts +257 -0
- package/test/provider/minimax.test.ts +110 -0
- package/test/provider/missing-tool-input.test.ts +73 -0
- package/test/provider/mistral-chat.test.ts +757 -0
- package/test/provider/mistral.recorded.test.ts +170 -0
- package/test/provider/moonshot-capabilities.recorded.test.ts +131 -0
- package/test/provider/moonshot.recorded.test.ts +191 -0
- package/test/provider/moonshot.test.ts +218 -0
- package/test/provider/native-providers.test.ts +299 -0
- package/test/provider/open-responses-errors.test.ts +141 -0
- package/test/provider/open-responses-finals.test.ts +209 -0
- package/test/provider/open-responses-lifecycle.test.ts +526 -0
- package/test/provider/open-responses-replay.test.ts +120 -0
- package/test/provider/openai-chat-reasoning.recorded.test.ts +154 -0
- package/test/provider/openai-chat.test.ts +2505 -0
- package/test/provider/openai-compatible-chat.test.ts +819 -0
- package/test/provider/openai-compatible-responses.test.ts +1139 -0
- package/test/provider/openai-images.recorded.test.ts +91 -0
- package/test/provider/openai-responses-cache.recorded.test.ts +68 -0
- package/test/provider/openai-responses-images.recorded.test.ts +66 -0
- package/test/provider/openai-responses-websocket.recorded.test.ts +221 -0
- package/test/provider/openai-responses.test.ts +5414 -0
- package/test/provider/openai-speech.recorded.test.ts +38 -0
- package/test/provider/openai-transcription.recorded.test.ts +91 -0
- package/test/provider/openrouter-images.recorded.test.ts +76 -0
- package/test/provider/openrouter-video.recorded.test.ts +53 -0
- package/test/provider/openrouter.test.ts +656 -0
- package/test/provider/pdf.recorded.test.ts +211 -0
- package/test/provider/queued-recording.ts +10 -0
- package/test/provider/responses-routes.recorded.test.ts +91 -0
- package/test/provider/seedance-video.recorded.test.ts +52 -0
- package/test/provider/speech-recording.ts +19 -0
- package/test/provider/transcription-recording.ts +41 -0
- package/test/provider/venice.recorded.test.ts +237 -0
- package/test/provider/venice.test.ts +373 -0
- package/test/provider/vercel-ai-gateway-images.recorded.test.ts +55 -0
- package/test/provider/vercel-ai-gateway.recorded.test.ts +125 -0
- package/test/provider/vercel-ai-gateway.test.ts +303 -0
- package/test/provider/xai-images.recorded.test.ts +54 -0
- package/test/provider/xai-images.test.ts +109 -0
- package/test/provider/xai-responses.test.ts +339 -0
- package/test/provider/xai-video.recorded.test.ts +54 -0
- package/test/provider/zai-capabilities.recorded.test.ts +156 -0
- package/test/provider/zai-images.recorded.test.ts +33 -0
- package/test/provider/zai-images.test.ts +163 -0
- package/test/provider/zai.recorded.test.ts +115 -0
- package/test/provider/zai.test.ts +374 -0
- package/test/provider-api-methods.types.ts +8 -0
- package/test/provider-error.test.ts +800 -0
- package/test/provider-model.types.ts +37 -0
- package/test/provider-options/alibaba.types.ts +46 -0
- package/test/provider-options/amazon-bedrock.types.ts +33 -0
- package/test/provider-options/anthropic-compatible.types.ts +13 -0
- package/test/provider-options/anthropic.types.ts +30 -0
- package/test/provider-options/azure.types.ts +13 -0
- package/test/provider-options/checkpoint.types.ts +150 -0
- package/test/provider-options/cloudflare.types.ts +13 -0
- package/test/provider-options/compaction.types.ts +146 -0
- package/test/provider-options/google-vertex-chat.types.ts +7 -0
- package/test/provider-options/google-vertex-interactions.types.ts +29 -0
- package/test/provider-options/google-vertex-messages.types.ts +13 -0
- package/test/provider-options/google-vertex-responses.types.ts +14 -0
- package/test/provider-options/google-vertex.types.ts +17 -0
- package/test/provider-options/google.types.ts +43 -0
- package/test/provider-options/minimax.types.ts +33 -0
- package/test/provider-options/mistral.types.ts +24 -0
- package/test/provider-options/moonshot.types.ts +45 -0
- package/test/provider-options/openai-compatible-responses.types.ts +17 -0
- package/test/provider-options/openai-compatible.types.ts +13 -0
- package/test/provider-options/openai.types.ts +27 -0
- package/test/provider-options/openrouter.types.ts +55 -0
- package/test/provider-options/venice.types.ts +39 -0
- package/test/provider-options/vercel-ai-gateway.types.ts +30 -0
- package/test/provider-options/xai.types.ts +14 -0
- package/test/provider-options/zai.types.ts +42 -0
- package/test/provider-package.test.ts +586 -0
- package/test/raw-events.test.ts +75 -0
- package/test/realtime.test.ts +172 -0
- package/test/recorded-golden.ts +104 -0
- package/test/recorded-runner.ts +101 -0
- package/test/recorded-scenarios.ts +468 -0
- package/test/recorded-test.ts +127 -0
- package/test/recorded-utils.ts +56 -0
- package/test/request-encoding.test.ts +57 -0
- package/test/request-transport.test.ts +74 -0
- package/test/response.test.ts +203 -0
- package/test/route.test.ts +225 -0
- package/test/sanitize.test.ts +80 -0
- package/test/schema.test.ts +412 -0
- package/test/seedance-video.test.ts +418 -0
- package/test/speech.test.ts +297 -0
- package/test/speech.types.ts +33 -0
- package/test/testing.test.ts +372 -0
- package/test/tool-history.test.ts +162 -0
- package/test/tool-runtime.test.ts +926 -0
- package/test/tool-schema-projection.test.ts +427 -0
- package/test/tool-stream.test.ts +252 -0
- package/test/tool-updates.test.ts +849 -0
- package/test/tool.types.ts +131 -0
- package/test/transcription.test.ts +618 -0
- package/test/transcription.types.ts +44 -0
- package/test/video.test.ts +447 -0
- package/test/video.types.ts +110 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +17 -0
- package/tsconfig.types.json +16 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { Base64 } from "effect/encoding"
|
|
3
|
+
import { Media } from "../../media.js"
|
|
4
|
+
import type { MediaProtocol } from "../../route/media-protocol.js"
|
|
5
|
+
import { mergeJsonRecords, type AIError, type ProviderID } from "../../schema/index.js"
|
|
6
|
+
import { encodeJson } from "../../utils/json.js"
|
|
7
|
+
import { ProviderShared } from "../shared.js"
|
|
8
|
+
|
|
9
|
+
/** Owned bytes for multipart uploads; decodes `base64` sources and rejects remote sources. */
|
|
10
|
+
export const inlineBytes = (route: string, asset: Media.Asset): Effect.Effect<Uint8Array, AIError> => {
|
|
11
|
+
if (asset.source.type === "bytes") return Effect.succeed(asset.source.data)
|
|
12
|
+
const inline = asset.inline()
|
|
13
|
+
if (!inline) return Effect.fail(ProviderShared.inlineRequired(route, asset))
|
|
14
|
+
return Effect.fromResult(Base64.decode(inline.base64)).pipe(
|
|
15
|
+
Effect.mapError((cause) => ProviderShared.invalidRequest(`${route} media contains invalid base64 data`, cause)),
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Copied because `BlobPart` requires a plain `ArrayBuffer`. */
|
|
20
|
+
export const blob = (data: Uint8Array, mediaType: string) => {
|
|
21
|
+
const buffer = new ArrayBuffer(data.byteLength)
|
|
22
|
+
new Uint8Array(buffer).set(data)
|
|
23
|
+
return new Blob([buffer], { type: mediaType })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const isScalar = (value: unknown): value is string | number | boolean =>
|
|
27
|
+
typeof value === "string" || typeof value === "number" || typeof value === "boolean"
|
|
28
|
+
|
|
29
|
+
export const query = (route: string, values: Record<string, unknown>): Effect.Effect<MediaProtocol.Query, AIError> => {
|
|
30
|
+
const entries = Object.entries(values).filter(([, value]) => value !== undefined)
|
|
31
|
+
const invalid = entries.find(([, value]) => !isScalar(value) && !(Array.isArray(value) && value.every(isScalar)))
|
|
32
|
+
if (invalid !== undefined)
|
|
33
|
+
return Effect.fail(ProviderShared.invalidRequest(`${route} cannot send "${invalid[0]}" as a query parameter`))
|
|
34
|
+
return Effect.succeed(
|
|
35
|
+
Object.fromEntries(entries.map(([key, value]) => [key, Array.isArray(value) ? value.map(String) : String(value)])),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Provider file handle when the ref belongs to this provider; refs from other providers are never forwarded. */
|
|
40
|
+
export const refID = (asset: Media.Asset, provider: ProviderID) =>
|
|
41
|
+
asset.source.type === "ref" && asset.source.provider === provider ? asset.source.id : undefined
|
|
42
|
+
|
|
43
|
+
/** Decode a provider's base64 output once into an owned `bytes` asset, sniffing the type when it is not declared. */
|
|
44
|
+
export const decodedAsset = (
|
|
45
|
+
invalid: (message: string, cause?: unknown) => AIError,
|
|
46
|
+
label: string,
|
|
47
|
+
data: string,
|
|
48
|
+
mediaType: string | undefined,
|
|
49
|
+
options?: Media.AssetOptions,
|
|
50
|
+
) =>
|
|
51
|
+
Effect.fromResult(Base64.decode(data)).pipe(
|
|
52
|
+
Effect.mapError((cause) => invalid(`${label} contains invalid base64 data`, cause)),
|
|
53
|
+
Effect.map((bytes) => Media.bytes(bytes, mediaType, options)),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* One image of an OpenAI-shaped `data` array, which carries `b64_json`, a `url`, or both. `b64_json` wins; a `data:`
|
|
58
|
+
* URL decodes inline with its own media type, and any other URL stays a URL asset for the caller to download.
|
|
59
|
+
*/
|
|
60
|
+
export const imageOutput = (
|
|
61
|
+
invalid: (message: string, cause?: unknown) => AIError,
|
|
62
|
+
label: string,
|
|
63
|
+
item: { readonly b64_json?: string | null; readonly url?: string | null },
|
|
64
|
+
mediaType: string | undefined,
|
|
65
|
+
options?: Media.AssetOptions,
|
|
66
|
+
) => {
|
|
67
|
+
if (item.b64_json) return decodedAsset(invalid, label, item.b64_json, mediaType, options)
|
|
68
|
+
if (item.url?.startsWith("data:")) {
|
|
69
|
+
const asset = Media.parseDataUrl(item.url, options)
|
|
70
|
+
return asset === undefined ? Effect.fail(invalid(`${label} has an invalid data URL`)) : Effect.succeed(asset)
|
|
71
|
+
}
|
|
72
|
+
if (item.url) return Effect.succeed(Media.url(item.url, { ...options, mediaType }))
|
|
73
|
+
return Effect.fail(invalid(`${label} has neither image data nor a URL`))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Append multipart text fields: strings as-is, other values as JSON, or scalar arrays as one part per item with
|
|
78
|
+
* `repeatArrays`, named `key[]` or `key`. `overlay` keys in `reserved` are dropped so `http.body` cannot replace
|
|
79
|
+
* route-owned fields.
|
|
80
|
+
*/
|
|
81
|
+
export const appendFields = (
|
|
82
|
+
form: FormData,
|
|
83
|
+
fields: Record<string, unknown>,
|
|
84
|
+
options: {
|
|
85
|
+
readonly overlay?: Record<string, unknown>
|
|
86
|
+
readonly reserved: ReadonlySet<string>
|
|
87
|
+
readonly repeatArrays?: "key[]" | "key"
|
|
88
|
+
},
|
|
89
|
+
) => {
|
|
90
|
+
const overlay = Object.entries(options.overlay ?? {}).filter(([key]) => !options.reserved.has(key))
|
|
91
|
+
Object.entries(mergeJsonRecords(fields, Object.fromEntries(overlay)) ?? {}).forEach(([key, value]) => {
|
|
92
|
+
if (Array.isArray(value) && value.every(isScalar) && options.repeatArrays !== undefined)
|
|
93
|
+
return value.forEach((item) => form.append(options.repeatArrays === "key[]" ? `${key}[]` : key, String(item)))
|
|
94
|
+
form.append(key, typeof value === "string" ? value : encodeJson(value))
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export * as MediaInput from "./media-input.js"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LLMRequest } from "../../schema/index.js"
|
|
2
|
+
|
|
3
|
+
export const valid = /^[A-Za-z0-9]{9}$/
|
|
4
|
+
|
|
5
|
+
export const hash = (value: string) => {
|
|
6
|
+
const hash = (seed: number) => {
|
|
7
|
+
let result = seed
|
|
8
|
+
for (const char of value) result = Math.imul(result ^ char.charCodeAt(0), 16777619)
|
|
9
|
+
return (result >>> 0).toString(36)
|
|
10
|
+
}
|
|
11
|
+
return `${hash(2166136261).padStart(7, "0")}${hash(2246822519).padStart(7, "0")}`.slice(-9)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const normalizer = (request: LLMRequest) => {
|
|
15
|
+
const ids = request.messages.flatMap((message) =>
|
|
16
|
+
message.content.flatMap((part) => (part.type === "tool-call" || part.type === "tool-result" ? [part.id] : [])),
|
|
17
|
+
)
|
|
18
|
+
// Reserve valid IDs before projecting any history, including IDs encountered later.
|
|
19
|
+
const used = new Set(ids.filter((id) => valid.test(id)))
|
|
20
|
+
const normalized = new Map<string, string>()
|
|
21
|
+
return (id: string) => {
|
|
22
|
+
if (valid.test(id)) return id
|
|
23
|
+
const previous = normalized.get(id)
|
|
24
|
+
if (previous) return previous
|
|
25
|
+
let attempt = 0
|
|
26
|
+
let candidate = hash(id)
|
|
27
|
+
while (used.has(candidate)) candidate = hash(`${id}:${++attempt}`)
|
|
28
|
+
used.add(candidate)
|
|
29
|
+
normalized.set(id, candidate)
|
|
30
|
+
return candidate
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export * as MistralToolID from "./mistral-tool-id.js"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { ReasoningEffort, ReasoningEfforts, type LLMRequest } from "../../schema/index.js"
|
|
3
|
+
import { lenient, ProviderShared } from "../shared.js"
|
|
4
|
+
|
|
5
|
+
export { ReasoningEffort, ReasoningEfforts }
|
|
6
|
+
|
|
7
|
+
export const TextVerbosities = ["low", "medium", "high"] as const
|
|
8
|
+
export type TextVerbosity = (typeof TextVerbosities)[number] | (string & {})
|
|
9
|
+
export const TextVerbosity = ProviderShared.knownString<(typeof TextVerbosities)[number]>()
|
|
10
|
+
|
|
11
|
+
export const ResponseIncludables = [
|
|
12
|
+
"file_search_call.results",
|
|
13
|
+
"web_search_call.results",
|
|
14
|
+
"web_search_call.action.sources",
|
|
15
|
+
"message.input_image.image_url",
|
|
16
|
+
"computer_call_output.output.image_url",
|
|
17
|
+
"code_interpreter_call.outputs",
|
|
18
|
+
"reasoning.encrypted_content",
|
|
19
|
+
"message.output_text.logprobs",
|
|
20
|
+
] as const
|
|
21
|
+
export type ResponseIncludable = (typeof ResponseIncludables)[number] | (string & {})
|
|
22
|
+
|
|
23
|
+
export const ServiceTiers = ["auto", "default", "flex", "priority"] as const
|
|
24
|
+
export type ServiceTier = (typeof ServiceTiers)[number] | (string & {})
|
|
25
|
+
export const ServiceTier = ProviderShared.knownString<(typeof ServiceTiers)[number]>()
|
|
26
|
+
|
|
27
|
+
export const Truncations = ["auto", "disabled"] as const
|
|
28
|
+
export type Truncation = (typeof Truncations)[number]
|
|
29
|
+
|
|
30
|
+
export const TextVerbositySchema = TextVerbosity
|
|
31
|
+
export const ResponseIncludableSchema = ProviderShared.knownString<(typeof ResponseIncludables)[number]>()
|
|
32
|
+
export const ServiceTierSchema = ServiceTier
|
|
33
|
+
export const TruncationSchema = Schema.Literals(Truncations)
|
|
34
|
+
|
|
35
|
+
export const AllowedTools = Schema.Struct({
|
|
36
|
+
toolNames: Schema.Array(Schema.String),
|
|
37
|
+
mode: Schema.optional(Schema.Literals(["auto", "none", "required"])),
|
|
38
|
+
})
|
|
39
|
+
export type AllowedTools = typeof AllowedTools.Type
|
|
40
|
+
|
|
41
|
+
export const StreamOptions = Schema.Struct({
|
|
42
|
+
includeObfuscation: Schema.optional(Schema.Boolean),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Malformed options are dropped one at a time so a bad `topLogprobs` cannot discard `store` or `reasoningEffort`.
|
|
46
|
+
export const Options = Schema.Struct({
|
|
47
|
+
store: lenient(Schema.Boolean),
|
|
48
|
+
metadata: lenient(Schema.Record(Schema.String, Schema.String)),
|
|
49
|
+
safetyIdentifier: lenient(Schema.String),
|
|
50
|
+
streamOptions: lenient(StreamOptions),
|
|
51
|
+
topLogprobs: lenient(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 20 }))),
|
|
52
|
+
reasoningEffort: lenient(ReasoningEffort),
|
|
53
|
+
reasoningSummary: lenient(Schema.Literals(["auto", "concise", "detailed"])),
|
|
54
|
+
include: lenient(Schema.Array(ResponseIncludableSchema)),
|
|
55
|
+
textVerbosity: lenient(TextVerbositySchema),
|
|
56
|
+
serviceTier: lenient(ServiceTierSchema),
|
|
57
|
+
truncation: lenient(TruncationSchema),
|
|
58
|
+
allowedTools: lenient(AllowedTools),
|
|
59
|
+
maxToolCalls: lenient(Schema.Int),
|
|
60
|
+
parallelToolCalls: lenient(Schema.Boolean),
|
|
61
|
+
})
|
|
62
|
+
export type Options = typeof Options.Type
|
|
63
|
+
|
|
64
|
+
export type Resolved = Omit<Options, "allowedTools"> & {
|
|
65
|
+
readonly allowedTools?: AllowedTools & { readonly mode: NonNullable<AllowedTools["mode"]> }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const decodeOptions = Schema.decodeUnknownSync(Options)
|
|
69
|
+
|
|
70
|
+
export const resolve = (request: LLMRequest): Resolved => {
|
|
71
|
+
const input = decodeOptions(request.providerOptions ?? {})
|
|
72
|
+
return {
|
|
73
|
+
...input,
|
|
74
|
+
include: input.include?.length ? input.include : undefined,
|
|
75
|
+
allowedTools:
|
|
76
|
+
input.allowedTools && input.allowedTools.toolNames.length > 0
|
|
77
|
+
? { ...input.allowedTools, mode: input.allowedTools.mode ?? "auto" }
|
|
78
|
+
: undefined,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export * as OpenResponsesOptions from "./open-responses-options.js"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Adapted from partial-json by the Promplate Dev Team:
|
|
3
|
+
* https://github.com/promplate/partial-json-parser-js/blob/main/src/options.ts
|
|
4
|
+
* Licensed under the MIT License; see partial-json.ts for the complete notice.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* allow partial strings like `"hello \u12` to be parsed as `"hello `
|
|
9
|
+
*/
|
|
10
|
+
export const STR = 0b000000001
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* allow partial numbers like `123.` to be parsed as `123`
|
|
14
|
+
*/
|
|
15
|
+
export const NUM = 0b000000010
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* allow partial arrays like `[1, 2,` to be parsed as `[1, 2]`
|
|
19
|
+
*/
|
|
20
|
+
export const ARR = 0b000000100
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* allow partial objects like `{"a": 1, "b":` to be parsed as `{"a": 1}`
|
|
24
|
+
*/
|
|
25
|
+
export const OBJ = 0b000001000
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* allow `nu` to be parsed as `null`
|
|
29
|
+
*/
|
|
30
|
+
export const NULL = 0b000010000
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* allow `tr` to be parsed as `true`, and `fa` to be parsed as `false`
|
|
34
|
+
*/
|
|
35
|
+
export const BOOL = 0b000100000
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* allow `Na` to be parsed as `NaN`
|
|
39
|
+
*/
|
|
40
|
+
export const NAN = 0b001000000
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* allow `Inf` to be parsed as `Infinity`
|
|
44
|
+
*/
|
|
45
|
+
export const INFINITY = 0b010000000
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* allow `-Inf` to be parsed as `-Infinity`
|
|
49
|
+
*/
|
|
50
|
+
export const _INFINITY = 0b100000000
|
|
51
|
+
|
|
52
|
+
export const INF = INFINITY | _INFINITY
|
|
53
|
+
export const SPECIAL = NULL | BOOL | INF | NAN
|
|
54
|
+
export const ATOM = STR | NUM | SPECIAL
|
|
55
|
+
export const COLLECTION = ARR | OBJ
|
|
56
|
+
export const ALL = ATOM | COLLECTION
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Control what types you allow to be partially parsed.
|
|
60
|
+
* The default is to allow all types to be partially parsed, which in most cases is the best option.
|
|
61
|
+
*/
|
|
62
|
+
export const Allow = { STR, NUM, ARR, OBJ, NULL, BOOL, NAN, INFINITY, _INFINITY, INF, SPECIAL, ATOM, COLLECTION, ALL }
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Adapted from partial-json by the Promplate Dev Team:
|
|
3
|
+
* https://github.com/promplate/partial-json-parser-js
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2023 Promplate Dev Team
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { Schema } from "effect"
|
|
29
|
+
import { decodeJson } from "../../utils/json.js"
|
|
30
|
+
import { Allow } from "./partial-json-options.js"
|
|
31
|
+
export * from "./partial-json-options.js"
|
|
32
|
+
|
|
33
|
+
export class PartialJSON extends Error {}
|
|
34
|
+
export class MalformedJSON extends Error {}
|
|
35
|
+
|
|
36
|
+
const decodeJsonString = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.String))
|
|
37
|
+
|
|
38
|
+
/** Parse complete or incomplete JSON, restricted by the supplied partial-value flags. */
|
|
39
|
+
export function parseJSON(jsonString: string, allowPartial = Allow.ALL): unknown {
|
|
40
|
+
if (typeof jsonString !== "string") throw new TypeError(`expecting str, got ${typeof jsonString}`)
|
|
41
|
+
const input = jsonString.trim()
|
|
42
|
+
if (!input) throw new Error(`${jsonString} is empty`)
|
|
43
|
+
try {
|
|
44
|
+
return decodeJson(input)
|
|
45
|
+
} catch {}
|
|
46
|
+
|
|
47
|
+
const repaired = repairJSON(input)
|
|
48
|
+
if (repaired !== input) {
|
|
49
|
+
try {
|
|
50
|
+
return decodeJson(repaired)
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
return _parseJSON(input, allowPartial)
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (repaired !== input) return _parseJSON(repaired, allowPartial)
|
|
58
|
+
throw error
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const repairJSON = (input: string) => {
|
|
63
|
+
let repaired = ""
|
|
64
|
+
let quoted = false
|
|
65
|
+
|
|
66
|
+
for (let index = 0; index < input.length; index++) {
|
|
67
|
+
const character = input[index]
|
|
68
|
+
if (!quoted) {
|
|
69
|
+
repaired += character
|
|
70
|
+
if (character === '"') quoted = true
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (character === '"') {
|
|
75
|
+
repaired += character
|
|
76
|
+
quoted = false
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (character === "\\") {
|
|
81
|
+
const next = input[index + 1]
|
|
82
|
+
if (next === "u" && /^[0-9a-fA-F]{4}$/.test(input.slice(index + 2, index + 6))) {
|
|
83
|
+
repaired += input.slice(index, index + 6)
|
|
84
|
+
index += 5
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
if (next !== undefined && '"\\/bfnrtu'.includes(next)) {
|
|
88
|
+
repaired += `\\${next}`
|
|
89
|
+
index++
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
repaired += "\\\\"
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const code = character.charCodeAt(0)
|
|
97
|
+
repaired += code <= 0x1f ? `\\u${code.toString(16).padStart(4, "0")}` : character
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return repaired
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const _parseJSON = (jsonString: string, allow: number) => {
|
|
104
|
+
const length = jsonString.length
|
|
105
|
+
let index = 0
|
|
106
|
+
|
|
107
|
+
const markPartialJSON = (message: string): never => {
|
|
108
|
+
throw new PartialJSON(`${message} at position ${index}`)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const throwMalformedError = (message: string): never => {
|
|
112
|
+
throw new MalformedJSON(`${message} at position ${index}`)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const parseAny = (): unknown => {
|
|
116
|
+
skipBlank()
|
|
117
|
+
if (index >= length) markPartialJSON("Unexpected end of input")
|
|
118
|
+
if (jsonString[index] === '"') return parseStr()
|
|
119
|
+
if (jsonString[index] === "{") return parseObj()
|
|
120
|
+
if (jsonString[index] === "[") return parseArr()
|
|
121
|
+
if (
|
|
122
|
+
jsonString.substring(index, index + 4) === "null" ||
|
|
123
|
+
(Allow.NULL & allow && length - index < 4 && "null".startsWith(jsonString.substring(index)))
|
|
124
|
+
) {
|
|
125
|
+
index += 4
|
|
126
|
+
return null
|
|
127
|
+
}
|
|
128
|
+
if (
|
|
129
|
+
jsonString.substring(index, index + 4) === "true" ||
|
|
130
|
+
(Allow.BOOL & allow && length - index < 4 && "true".startsWith(jsonString.substring(index)))
|
|
131
|
+
) {
|
|
132
|
+
index += 4
|
|
133
|
+
return true
|
|
134
|
+
}
|
|
135
|
+
if (
|
|
136
|
+
jsonString.substring(index, index + 5) === "false" ||
|
|
137
|
+
(Allow.BOOL & allow && length - index < 5 && "false".startsWith(jsonString.substring(index)))
|
|
138
|
+
) {
|
|
139
|
+
index += 5
|
|
140
|
+
return false
|
|
141
|
+
}
|
|
142
|
+
if (
|
|
143
|
+
jsonString.substring(index, index + 8) === "Infinity" ||
|
|
144
|
+
(Allow.INFINITY & allow && length - index < 8 && "Infinity".startsWith(jsonString.substring(index)))
|
|
145
|
+
) {
|
|
146
|
+
index += 8
|
|
147
|
+
return Infinity
|
|
148
|
+
}
|
|
149
|
+
if (
|
|
150
|
+
jsonString.substring(index, index + 9) === "-Infinity" ||
|
|
151
|
+
(Allow._INFINITY & allow &&
|
|
152
|
+
1 < length - index &&
|
|
153
|
+
length - index < 9 &&
|
|
154
|
+
"-Infinity".startsWith(jsonString.substring(index)))
|
|
155
|
+
) {
|
|
156
|
+
index += 9
|
|
157
|
+
return -Infinity
|
|
158
|
+
}
|
|
159
|
+
if (
|
|
160
|
+
jsonString.substring(index, index + 3) === "NaN" ||
|
|
161
|
+
(Allow.NAN & allow && length - index < 3 && "NaN".startsWith(jsonString.substring(index)))
|
|
162
|
+
) {
|
|
163
|
+
index += 3
|
|
164
|
+
return NaN
|
|
165
|
+
}
|
|
166
|
+
return parseNum()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const parseStr = (): string => {
|
|
170
|
+
const start = index
|
|
171
|
+
let escape = false
|
|
172
|
+
index++
|
|
173
|
+
while (index < length && (jsonString[index] !== '"' || (escape && jsonString[index - 1] === "\\"))) {
|
|
174
|
+
escape = jsonString[index] === "\\" ? !escape : false
|
|
175
|
+
index++
|
|
176
|
+
}
|
|
177
|
+
if (jsonString.charAt(index) === '"') {
|
|
178
|
+
try {
|
|
179
|
+
return decodeJsonString(jsonString.substring(start, ++index - Number(escape)))
|
|
180
|
+
} catch (error) {
|
|
181
|
+
throwMalformedError(String(error))
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (Allow.STR & allow) {
|
|
185
|
+
try {
|
|
186
|
+
return decodeJsonString(`${jsonString.substring(start, index - Number(escape))}"`)
|
|
187
|
+
} catch {
|
|
188
|
+
return decodeJsonString(`${jsonString.substring(start, jsonString.lastIndexOf("\\"))}"`)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return markPartialJSON("Unterminated string literal")
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const parseObj = (): Record<string, unknown> => {
|
|
195
|
+
index++
|
|
196
|
+
skipBlank()
|
|
197
|
+
const object: Record<string, unknown> = {}
|
|
198
|
+
try {
|
|
199
|
+
while (jsonString[index] !== "}") {
|
|
200
|
+
skipBlank()
|
|
201
|
+
if (index >= length && Allow.OBJ & allow) return object
|
|
202
|
+
const key = parseStr()
|
|
203
|
+
skipBlank()
|
|
204
|
+
index++
|
|
205
|
+
try {
|
|
206
|
+
Object.defineProperty(object, key, {
|
|
207
|
+
value: parseAny(),
|
|
208
|
+
enumerable: true,
|
|
209
|
+
configurable: true,
|
|
210
|
+
writable: true,
|
|
211
|
+
})
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (Allow.OBJ & allow) return object
|
|
214
|
+
throw error
|
|
215
|
+
}
|
|
216
|
+
skipBlank()
|
|
217
|
+
if (jsonString[index] === ",") index++
|
|
218
|
+
}
|
|
219
|
+
} catch {
|
|
220
|
+
if (Allow.OBJ & allow) return object
|
|
221
|
+
return markPartialJSON("Expected '}' at end of object")
|
|
222
|
+
}
|
|
223
|
+
index++
|
|
224
|
+
return object
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const parseArr = (): unknown[] => {
|
|
228
|
+
index++
|
|
229
|
+
const array: unknown[] = []
|
|
230
|
+
try {
|
|
231
|
+
while (jsonString[index] !== "]") {
|
|
232
|
+
array.push(parseAny())
|
|
233
|
+
skipBlank()
|
|
234
|
+
if (jsonString[index] === ",") index++
|
|
235
|
+
}
|
|
236
|
+
} catch {
|
|
237
|
+
if (Allow.ARR & allow) return array
|
|
238
|
+
return markPartialJSON("Expected ']' at end of array")
|
|
239
|
+
}
|
|
240
|
+
index++
|
|
241
|
+
return array
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const parseNum = (): unknown => {
|
|
245
|
+
if (index === 0) {
|
|
246
|
+
if (jsonString === "-") throwMalformedError("Not sure what '-' is")
|
|
247
|
+
try {
|
|
248
|
+
return decodeJson(jsonString)
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (Allow.NUM & allow) {
|
|
251
|
+
try {
|
|
252
|
+
return decodeJson(jsonString.substring(0, jsonString.lastIndexOf("e")))
|
|
253
|
+
} catch {}
|
|
254
|
+
}
|
|
255
|
+
throwMalformedError(String(error))
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const start = index
|
|
260
|
+
if (jsonString[index] === "-") index++
|
|
261
|
+
while (jsonString[index] && !",]}".includes(jsonString[index])) index++
|
|
262
|
+
if (index === length && !(Allow.NUM & allow)) markPartialJSON("Unterminated number literal")
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
return decodeJson(jsonString.substring(start, index))
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (jsonString.substring(start, index) === "-") markPartialJSON("Not sure what '-' is")
|
|
268
|
+
try {
|
|
269
|
+
return decodeJson(jsonString.substring(start, jsonString.lastIndexOf("e")))
|
|
270
|
+
} catch {
|
|
271
|
+
throwMalformedError(String(error))
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const skipBlank = () => {
|
|
277
|
+
while (index < length && " \n\r\t".includes(jsonString[index])) index++
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return parseAny()
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export const parse = parseJSON
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Effect, Schema, Stream } from "effect"
|
|
2
|
+
import { Route, type RouteBody, type TriggerCompactOperation } from "../../route/client.js"
|
|
3
|
+
import { Protocol } from "../../route/protocol.js"
|
|
4
|
+
import { CompactionCheckpointResponse, LLMEvent, type LLMRequest } from "../../schema/index.js"
|
|
5
|
+
import { OpenResponses } from "../open-responses.js"
|
|
6
|
+
import { ProviderShared } from "../shared.js"
|
|
7
|
+
|
|
8
|
+
interface State {
|
|
9
|
+
readonly parser: Pick<OpenResponses.ParserState, "id" | "provider" | "outputItems">
|
|
10
|
+
readonly checkpoints: Readonly<Record<string, CompactionCheckpointResponse["checkpoint"]>>
|
|
11
|
+
readonly responseID?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const onOutputItem = Effect.fnUntraced(function* (state: State, input: OpenResponses.Event) {
|
|
15
|
+
const event = OpenResponses.normalize(state.parser, input)
|
|
16
|
+
const item = event.item
|
|
17
|
+
if (!item) return state
|
|
18
|
+
const parser =
|
|
19
|
+
event.output_index === undefined || state.parser.outputItems[event.output_index] === item.id
|
|
20
|
+
? state.parser
|
|
21
|
+
: { ...state.parser, outputItems: { ...state.parser.outputItems, [event.output_index]: item.id } }
|
|
22
|
+
const next = parser === state.parser ? state : { ...state, parser }
|
|
23
|
+
if (event.type === "response.output_item.added" || item.type !== "compaction") return next
|
|
24
|
+
if (
|
|
25
|
+
event.output_index !== undefined &&
|
|
26
|
+
Object.entries(state.parser.outputItems).some(
|
|
27
|
+
([index, id]) => id === item.id && Number(index) !== event.output_index,
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
return yield* ProviderShared.eventError(parser.id, "Compaction checkpoint appeared in multiple output slots")
|
|
31
|
+
if (!item.encrypted_content)
|
|
32
|
+
return yield* ProviderShared.eventError(parser.id, "Compaction output is missing its encrypted content")
|
|
33
|
+
const previous = state.checkpoints[item.id]
|
|
34
|
+
if (previous && previous.encrypted !== item.encrypted_content)
|
|
35
|
+
return yield* ProviderShared.eventError(parser.id, "Compaction output changed after completion")
|
|
36
|
+
if (previous) return next
|
|
37
|
+
return {
|
|
38
|
+
...next,
|
|
39
|
+
checkpoints: {
|
|
40
|
+
...state.checkpoints,
|
|
41
|
+
[item.id]: { type: "compaction", provider: parser.provider, id: item.id, encrypted: item.encrypted_content },
|
|
42
|
+
},
|
|
43
|
+
} satisfies State
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
/** Collect a trigger response before acknowledging transport completion. No generation output escapes. */
|
|
47
|
+
export const make = <Body>(body: RouteBody<Body>): TriggerCompactOperation =>
|
|
48
|
+
Effect.fn("ResponsesCheckpoint.execute")(function* (request, executor, options) {
|
|
49
|
+
const source = request.model.route
|
|
50
|
+
let result: CompactionCheckpointResponse | undefined
|
|
51
|
+
// Route registries erase the frame type. The codec validates that boundary before parsing.
|
|
52
|
+
const event: Schema.Codec<OpenResponses.Event, unknown> = OpenResponses.protocol.stream.event
|
|
53
|
+
const protocol = Protocol.make({
|
|
54
|
+
id: source.protocol,
|
|
55
|
+
body,
|
|
56
|
+
stream: {
|
|
57
|
+
event,
|
|
58
|
+
initial: (request: LLMRequest): State => ({
|
|
59
|
+
parser: { id: source.id, provider: request.model.provider, outputItems: {} },
|
|
60
|
+
checkpoints: {},
|
|
61
|
+
}),
|
|
62
|
+
terminal: OpenResponses.terminal,
|
|
63
|
+
step: Effect.fnUntraced(function* (state: State, event: OpenResponses.Event) {
|
|
64
|
+
if (event.response?.id && state.responseID && event.response.id !== state.responseID)
|
|
65
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response ID changed during execution")
|
|
66
|
+
if (event.type === "response.created") return [{ ...state, responseID: event.response?.id }, []] as const
|
|
67
|
+
if (event.type === "error" || event.type === "response.failed")
|
|
68
|
+
return yield* OpenResponses.providerFailure(event, "Compaction request failed")
|
|
69
|
+
if (event.type === "response.incomplete")
|
|
70
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response was incomplete")
|
|
71
|
+
if (event.type === "response.output_item.added" || event.type === "response.output_item.done")
|
|
72
|
+
return [yield* onOutputItem(state, event), []] as const
|
|
73
|
+
if (event.type !== "response.completed") return [state, []] as const
|
|
74
|
+
const responseID = event.response?.id
|
|
75
|
+
if (!responseID?.trim())
|
|
76
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response is missing its response ID")
|
|
77
|
+
if (event.response?.status !== undefined && event.response.status !== "completed")
|
|
78
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response did not complete successfully")
|
|
79
|
+
let next = state
|
|
80
|
+
for (const [index, item] of (event.response?.output ?? []).entries()) {
|
|
81
|
+
next = yield* onOutputItem(next, { type: "response.output_item.done", output_index: index, item })
|
|
82
|
+
}
|
|
83
|
+
const checkpoints = Object.values(next.checkpoints)
|
|
84
|
+
const checkpoint = checkpoints[0]
|
|
85
|
+
if (checkpoints.length !== 1 || !checkpoint)
|
|
86
|
+
return yield* ProviderShared.eventError(
|
|
87
|
+
source.id,
|
|
88
|
+
"Compaction response must contain exactly one checkpoint",
|
|
89
|
+
)
|
|
90
|
+
result = new CompactionCheckpointResponse({
|
|
91
|
+
checkpoint,
|
|
92
|
+
responseID,
|
|
93
|
+
usage: OpenResponses.mapUsage(event.response?.usage, OpenResponses.metadataKey(request.model)),
|
|
94
|
+
})
|
|
95
|
+
return [next, [LLMEvent.finish({ reason: { normalized: "stop" } })]] as const
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
const route = Route.make({
|
|
100
|
+
id: source.id,
|
|
101
|
+
provider: source.provider,
|
|
102
|
+
providerMetadataKey: source.providerMetadataKey,
|
|
103
|
+
protocol,
|
|
104
|
+
endpoint: source.endpoint,
|
|
105
|
+
auth: source.auth,
|
|
106
|
+
transport: source.transport,
|
|
107
|
+
})
|
|
108
|
+
const native = yield* body.from(request)
|
|
109
|
+
const prepared = yield* route.prepareTransport(native, request, options)
|
|
110
|
+
yield* route.streamPrepared(prepared, request, { http: executor }, options).pipe(Stream.runDrain)
|
|
111
|
+
if (!result) return yield* ProviderShared.eventError(source.id, "Compaction response ended without a checkpoint")
|
|
112
|
+
return result
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
export * as ResponsesCheckpoint from "./responses-checkpoint.js"
|