@radheim/ai 0.0.0-stage → 2.4.3
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/README.md +1890 -3
- package/dist/ai.d.ts +36 -0
- package/dist/ai.js +46 -0
- package/dist/cache-policy.d.ts +6 -0
- package/dist/cache-policy.js +205 -0
- package/dist/decision-client.d.ts +10 -0
- package/dist/decision-client.js +42 -0
- package/dist/decision.d.ts +378 -0
- package/dist/decision.js +171 -0
- package/dist/effect.d.ts +59 -0
- package/dist/effect.js +33 -0
- package/dist/effort-updates.d.ts +12 -0
- package/dist/effort-updates.js +23 -0
- package/dist/embedding-client.d.ts +10 -0
- package/dist/embedding-client.js +17 -0
- package/dist/embedding.d.ts +113 -0
- package/dist/embedding.js +76 -0
- package/dist/experimental/cloudflare-run-extraction.d.ts +17 -0
- package/dist/experimental/cloudflare-run-extraction.js +85 -0
- package/dist/experimental/extraction.d.ts +153 -0
- package/dist/experimental/extraction.js +103 -0
- package/dist/experimental/realtime.d.ts +80 -0
- package/dist/experimental/realtime.js +96 -0
- package/dist/experimental.d.ts +10 -0
- package/dist/experimental.js +6 -0
- package/dist/fetch-middleware.d.ts +7 -0
- package/dist/fetch-middleware.js +41 -0
- package/dist/generation.d.ts +77 -0
- package/dist/generation.js +109 -0
- package/dist/image-client.d.ts +14 -0
- package/dist/image-client.js +39 -0
- package/dist/image.d.ts +323 -0
- package/dist/image.js +103 -0
- package/dist/index.d.ts +300 -0
- package/dist/index.js +179 -0
- package/dist/llm.d.ts +109 -0
- package/dist/llm.js +177 -0
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +139 -0
- package/dist/media-client.d.ts +30 -0
- package/dist/media-client.js +44 -0
- package/dist/media-model.d.ts +49 -0
- package/dist/media-model.js +55 -0
- package/dist/media.d.ts +237 -0
- package/dist/media.js +285 -0
- package/dist/promise-media.d.ts +20 -0
- package/dist/promise-media.js +16 -0
- package/dist/protocols/alibaba-chat.d.ts +315 -0
- package/dist/protocols/alibaba-chat.js +78 -0
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +413 -0
- package/dist/protocols/alibaba-messages.js +44 -0
- package/dist/protocols/alibaba-responses.d.ts +298 -0
- package/dist/protocols/alibaba-responses.js +67 -0
- package/dist/protocols/anthropic-messages.d.ts +1213 -0
- package/dist/protocols/anthropic-messages.js +1412 -0
- package/dist/protocols/assemblyai-transcription.d.ts +41 -0
- package/dist/protocols/assemblyai-transcription.js +137 -0
- package/dist/protocols/bedrock-converse.d.ts +548 -0
- package/dist/protocols/bedrock-converse.js +801 -0
- package/dist/protocols/bedrock-event-stream.d.ts +14 -0
- package/dist/protocols/bedrock-event-stream.js +100 -0
- package/dist/protocols/cartesia-speech.d.ts +117 -0
- package/dist/protocols/cartesia-speech.js +120 -0
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/cohere-chat.d.ts +184 -0
- package/dist/protocols/cohere-chat.js +317 -0
- package/dist/protocols/deepgram-speech.d.ts +109 -0
- package/dist/protocols/deepgram-speech.js +93 -0
- package/dist/protocols/deepgram-transcription.d.ts +26 -0
- package/dist/protocols/deepgram-transcription.js +119 -0
- package/dist/protocols/elevenlabs-speech.d.ts +112 -0
- package/dist/protocols/elevenlabs-speech.js +111 -0
- package/dist/protocols/elevenlabs-transcription.d.ts +28 -0
- package/dist/protocols/elevenlabs-transcription.js +137 -0
- package/dist/protocols/gemini.d.ts +388 -0
- package/dist/protocols/gemini.js +741 -0
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-images.d.ts +18 -0
- package/dist/protocols/google-images.js +169 -0
- package/dist/protocols/google-interactions-video.d.ts +38 -0
- package/dist/protocols/google-interactions-video.js +185 -0
- package/dist/protocols/google-interactions.d.ts +554 -0
- package/dist/protocols/google-interactions.js +756 -0
- package/dist/protocols/google-speech.d.ts +120 -0
- package/dist/protocols/google-speech.js +94 -0
- package/dist/protocols/google-transcription.d.ts +148 -0
- package/dist/protocols/google-transcription.js +129 -0
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/index.d.ts +21 -0
- package/dist/protocols/index.js +21 -0
- package/dist/protocols/meta-images.d.ts +26 -0
- package/dist/protocols/meta-images.js +101 -0
- package/dist/protocols/meta-messages.d.ts +423 -0
- package/dist/protocols/meta-messages.js +63 -0
- package/dist/protocols/meta-responses.d.ts +533 -0
- package/dist/protocols/meta-responses.js +189 -0
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/minimax-video.d.ts +45 -0
- package/dist/protocols/minimax-video.js +296 -0
- package/dist/protocols/mistral-chat.d.ts +565 -0
- package/dist/protocols/mistral-chat.js +606 -0
- package/dist/protocols/open-responses-channel.d.ts +25 -0
- package/dist/protocols/open-responses-channel.js +137 -0
- package/dist/protocols/open-responses-continuation.d.ts +18 -0
- package/dist/protocols/open-responses-continuation.js +172 -0
- package/dist/protocols/open-responses.d.ts +2509 -0
- package/dist/protocols/open-responses.js +1335 -0
- package/dist/protocols/openai-chat.d.ts +2571 -0
- package/dist/protocols/openai-chat.js +1140 -0
- package/dist/protocols/openai-compatible-chat.d.ts +184 -0
- package/dist/protocols/openai-compatible-chat.js +19 -0
- package/dist/protocols/openai-compatible-responses.d.ts +231 -0
- package/dist/protocols/openai-compatible-responses.js +18 -0
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +141 -0
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- package/dist/protocols/openai-freeform.d.ts +78 -0
- package/dist/protocols/openai-freeform.js +222 -0
- package/dist/protocols/openai-images.d.ts +148 -0
- package/dist/protocols/openai-images.js +303 -0
- package/dist/protocols/openai-responses.d.ts +1600 -0
- package/dist/protocols/openai-responses.js +360 -0
- package/dist/protocols/openai-speech.d.ts +110 -0
- package/dist/protocols/openai-speech.js +112 -0
- package/dist/protocols/openai-transcription.d.ts +185 -0
- package/dist/protocols/openai-transcription.js +206 -0
- package/dist/protocols/openrouter-video.d.ts +36 -0
- package/dist/protocols/openrouter-video.js +139 -0
- package/dist/protocols/seedance-video.d.ts +45 -0
- package/dist/protocols/seedance-video.js +217 -0
- package/dist/protocols/shared.d.ts +249 -0
- package/dist/protocols/shared.js +446 -0
- package/dist/protocols/system-one.d.ts +145 -0
- package/dist/protocols/system-one.js +272 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
- package/dist/protocols/utils/bedrock-auth.js +86 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
- package/dist/protocols/utils/bedrock-cache.js +49 -0
- package/dist/protocols/utils/bedrock-media.d.ts +53 -0
- package/dist/protocols/utils/bedrock-media.js +98 -0
- package/dist/protocols/utils/cache.d.ts +25 -0
- package/dist/protocols/utils/cache.js +33 -0
- package/dist/protocols/utils/claude-model.d.ts +8 -0
- package/dist/protocols/utils/claude-model.js +15 -0
- package/dist/protocols/utils/gateway-protocol.d.ts +17 -0
- package/dist/protocols/utils/gateway-protocol.js +59 -0
- package/dist/protocols/utils/gemini-generate-content.d.ts +75 -0
- package/dist/protocols/utils/gemini-generate-content.js +96 -0
- package/dist/protocols/utils/gemini-json-schema.d.ts +8 -0
- package/dist/protocols/utils/gemini-json-schema.js +76 -0
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/lifecycle.d.ts +24 -0
- package/dist/protocols/utils/lifecycle.js +62 -0
- package/dist/protocols/utils/media-input.d.ts +32 -0
- package/dist/protocols/utils/media-input.js +62 -0
- package/dist/protocols/utils/mistral-tool-id.d.ts +5 -0
- package/dist/protocols/utils/mistral-tool-id.js +31 -0
- package/dist/protocols/utils/open-responses-options.d.ts +54 -0
- package/dist/protocols/utils/open-responses-options.js +59 -0
- package/dist/protocols/utils/partial-json-options.d.ts +61 -0
- package/dist/protocols/utils/partial-json-options.js +51 -0
- package/dist/protocols/utils/partial-json.d.ts +8 -0
- package/dist/protocols/utils/partial-json.js +280 -0
- package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
- package/dist/protocols/utils/responses-checkpoint.js +103 -0
- package/dist/protocols/utils/responses-compaction.d.ts +6 -0
- package/dist/protocols/utils/responses-compaction.js +162 -0
- package/dist/protocols/utils/responses-hosted-tools.d.ts +122 -0
- package/dist/protocols/utils/responses-hosted-tools.js +63 -0
- package/dist/protocols/utils/speaker-turns.d.ts +3 -0
- package/dist/protocols/utils/speaker-turns.js +9 -0
- package/dist/protocols/utils/speech-stream.d.ts +49 -0
- package/dist/protocols/utils/speech-stream.js +64 -0
- package/dist/protocols/utils/tool-schema.d.ts +10 -0
- package/dist/protocols/utils/tool-schema.js +109 -0
- package/dist/protocols/utils/tool-stream.d.ts +478 -0
- package/dist/protocols/utils/tool-stream.js +153 -0
- package/dist/protocols/venice-chat.d.ts +340 -0
- package/dist/protocols/venice-chat.js +283 -0
- package/dist/protocols/xai-images.d.ts +25 -0
- package/dist/protocols/xai-images.js +87 -0
- package/dist/protocols/xai-responses.d.ts +294 -0
- package/dist/protocols/xai-responses.js +86 -0
- package/dist/protocols/xai-video.d.ts +35 -0
- package/dist/protocols/xai-video.js +159 -0
- package/dist/protocols/zai-chat.d.ts +296 -0
- package/dist/protocols/zai-chat.js +56 -0
- package/dist/protocols/zai-images.d.ts +20 -0
- package/dist/protocols/zai-images.js +79 -0
- package/dist/protocols/zai-messages.d.ts +409 -0
- package/dist/protocols/zai-messages.js +30 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +22 -0
- package/dist/provider-error.js +228 -0
- package/dist/provider-package.d.ts +17 -0
- package/dist/provider-package.js +1 -0
- package/dist/providers/alibaba/chat.d.ts +1 -0
- package/dist/providers/alibaba/chat.js +1 -0
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba/messages.d.ts +3 -0
- package/dist/providers/alibaba/messages.js +1 -0
- package/dist/providers/alibaba/responses.d.ts +3 -0
- package/dist/providers/alibaba/responses.js +1 -0
- package/dist/providers/alibaba.d.ts +905 -0
- package/dist/providers/alibaba.js +119 -0
- package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
- package/dist/providers/amazon-bedrock/mantle/messages.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/messages.js +1 -0
- package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
- package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +789 -0
- package/dist/providers/amazon-bedrock-mantle.js +107 -0
- package/dist/providers/amazon-bedrock.d.ts +190 -0
- package/dist/providers/amazon-bedrock.js +44 -0
- package/dist/providers/anthropic-compatible.d.ts +364 -0
- package/dist/providers/anthropic-compatible.js +47 -0
- package/dist/providers/anthropic.d.ts +362 -0
- package/dist/providers/anthropic.js +36 -0
- package/dist/providers/assemblyai.d.ts +19 -0
- package/dist/providers/assemblyai.js +19 -0
- package/dist/providers/azure/chat.d.ts +2 -0
- package/dist/providers/azure/chat.js +1 -0
- package/dist/providers/azure/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure/responses.d.ts +2 -0
- package/dist/providers/azure/responses.js +1 -0
- package/dist/providers/azure.d.ts +1074 -0
- package/dist/providers/azure.js +150 -0
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +384 -0
- package/dist/providers/baseten.js +56 -0
- package/dist/providers/byteplus/videos.d.ts +2 -0
- package/dist/providers/byteplus/videos.js +1 -0
- package/dist/providers/byteplus.d.ts +24 -0
- package/dist/providers/byteplus.js +21 -0
- package/dist/providers/cartesia.d.ts +18 -0
- package/dist/providers/cartesia.js +17 -0
- package/dist/providers/cerebras.d.ts +375 -0
- package/dist/providers/cerebras.js +33 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +1581 -0
- package/dist/providers/cloudflare-ai-gateway.js +120 -0
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +391 -0
- package/dist/providers/cloudflare-workers-ai.js +69 -0
- package/dist/providers/cohere/chat.d.ts +4 -0
- package/dist/providers/cohere/chat.js +3 -0
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +502 -0
- package/dist/providers/cohere.js +55 -0
- package/dist/providers/deepgram.d.ts +22 -0
- package/dist/providers/deepgram.js +20 -0
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +378 -0
- package/dist/providers/deepinfra.js +52 -0
- package/dist/providers/deepseek.d.ts +376 -0
- package/dist/providers/deepseek.js +30 -0
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +874 -0
- package/dist/providers/digitalocean.js +106 -0
- package/dist/providers/elevenlabs.d.ts +22 -0
- package/dist/providers/elevenlabs.js +22 -0
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +379 -0
- package/dist/providers/fireworks.js +40 -0
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.js +1 -0
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google/interactions.d.ts +7 -0
- package/dist/providers/google/interactions.js +3 -0
- package/dist/providers/google/videos.d.ts +2 -0
- package/dist/providers/google/videos.js +1 -0
- package/dist/providers/google-vertex/chat.d.ts +2 -0
- package/dist/providers/google-vertex/chat.js +1 -0
- package/dist/providers/google-vertex/embeddings.d.ts +2 -0
- package/dist/providers/google-vertex/embeddings.js +1 -0
- package/dist/providers/google-vertex/gemini.d.ts +2 -0
- package/dist/providers/google-vertex/gemini.js +1 -0
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex/interactions.d.ts +2 -0
- package/dist/providers/google-vertex/interactions.js +1 -0
- package/dist/providers/google-vertex/messages.d.ts +2 -0
- package/dist/providers/google-vertex/messages.js +1 -0
- package/dist/providers/google-vertex/mistral.d.ts +2 -0
- package/dist/providers/google-vertex/mistral.js +1 -0
- package/dist/providers/google-vertex/responses.d.ts +2 -0
- package/dist/providers/google-vertex/responses.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +204 -0
- package/dist/providers/google-vertex-chat.js +29 -0
- package/dist/providers/google-vertex-interactions.d.ts +111 -0
- package/dist/providers/google-vertex-interactions.js +62 -0
- package/dist/providers/google-vertex-messages.d.ts +362 -0
- package/dist/providers/google-vertex-messages.js +51 -0
- package/dist/providers/google-vertex-mistral.d.ts +120 -0
- package/dist/providers/google-vertex-mistral.js +43 -0
- package/dist/providers/google-vertex-responses.d.ts +253 -0
- package/dist/providers/google-vertex-responses.js +30 -0
- package/dist/providers/google-vertex-shared.d.ts +58 -0
- package/dist/providers/google-vertex-shared.js +128 -0
- package/dist/providers/google-vertex.d.ts +132 -0
- package/dist/providers/google-vertex.js +161 -0
- package/dist/providers/google.d.ts +246 -0
- package/dist/providers/google.js +80 -0
- package/dist/providers/groq.d.ts +470 -0
- package/dist/providers/groq.js +63 -0
- package/dist/providers/index.d.ts +45 -0
- package/dist/providers/index.js +45 -0
- package/dist/providers/meta/chat.d.ts +2 -0
- package/dist/providers/meta/chat.js +1 -0
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta/messages.d.ts +2 -0
- package/dist/providers/meta/messages.js +1 -0
- package/dist/providers/meta/responses.d.ts +2 -0
- package/dist/providers/meta/responses.js +1 -0
- package/dist/providers/meta.d.ts +804 -0
- package/dist/providers/meta.js +96 -0
- package/dist/providers/minimax/chat.d.ts +4 -0
- package/dist/providers/minimax/chat.js +3 -0
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/messages.d.ts +1 -0
- package/dist/providers/minimax/messages.js +1 -0
- package/dist/providers/minimax/responses.d.ts +4 -0
- package/dist/providers/minimax/responses.js +3 -0
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +798 -0
- package/dist/providers/minimax.js +99 -0
- package/dist/providers/mistral.d.ts +208 -0
- package/dist/providers/mistral.js +17 -0
- package/dist/providers/moonshot/chat.d.ts +1 -0
- package/dist/providers/moonshot/chat.js +1 -0
- package/dist/providers/moonshot/messages.d.ts +4 -0
- package/dist/providers/moonshot/messages.js +3 -0
- package/dist/providers/moonshot/responses.d.ts +4 -0
- package/dist/providers/moonshot/responses.js +3 -0
- package/dist/providers/moonshot.d.ts +785 -0
- package/dist/providers/moonshot.js +78 -0
- package/dist/providers/open-responses-options.d.ts +5 -0
- package/dist/providers/open-responses-options.js +1 -0
- package/dist/providers/openai/chat.d.ts +2 -0
- package/dist/providers/openai/chat.js +1 -0
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai/responses.d.ts +2 -0
- package/dist/providers/openai/responses.js +1 -0
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.js +1 -0
- package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
- package/dist/providers/openai-compatible/embeddings.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible/responses.d.ts +1 -0
- package/dist/providers/openai-compatible/responses.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +250 -0
- package/dist/providers/openai-compatible-responses.js +26 -0
- package/dist/providers/openai-compatible.d.ts +208 -0
- package/dist/providers/openai-compatible.js +71 -0
- package/dist/providers/openai-options.d.ts +21 -0
- package/dist/providers/openai-options.js +37 -0
- package/dist/providers/openai.d.ts +522 -0
- package/dist/providers/openai.js +118 -0
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +23 -0
- package/dist/providers/opencode.js +25 -0
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter/responses.d.ts +3 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +1204 -0
- package/dist/providers/openrouter.js +210 -0
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +18 -0
- package/dist/providers/togetherai.d.ts +375 -0
- package/dist/providers/togetherai.js +30 -0
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +23 -0
- package/dist/providers/typesafe-ai.js +25 -0
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +632 -0
- package/dist/providers/venice.js +57 -0
- package/dist/providers/vercel-ai-gateway/chat.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/chat.js +1 -0
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway/messages.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/messages.js +1 -0
- package/dist/providers/vercel-ai-gateway/responses.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/responses.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +111 -0
- package/dist/providers/vercel-ai-gateway.js +181 -0
- package/dist/providers/volcengine/videos.d.ts +2 -0
- package/dist/providers/volcengine/videos.js +1 -0
- package/dist/providers/volcengine.d.ts +24 -0
- package/dist/providers/volcengine.js +21 -0
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +235 -0
- package/dist/providers/xai.js +89 -0
- package/dist/providers/zai/chat.d.ts +1 -0
- package/dist/providers/zai/chat.js +1 -0
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
- package/dist/providers/zai-coding-plan/chat.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
- package/dist/providers/zai-coding-plan/messages.js +3 -0
- package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
- package/dist/providers/zai-coding-plan/responses.js +3 -0
- package/dist/providers/zai-coding-plan.d.ts +846 -0
- package/dist/providers/zai-coding-plan.js +56 -0
- package/dist/providers/zai.d.ts +285 -0
- package/dist/providers/zai.js +44 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/public.d.ts +18 -0
- package/dist/public.js +7 -0
- package/dist/route/auth-options.d.ts +35 -0
- package/dist/route/auth-options.js +17 -0
- package/dist/route/auth.d.ts +52 -0
- package/dist/route/auth.js +92 -0
- package/dist/route/client.d.ts +229 -0
- package/dist/route/client.js +293 -0
- package/dist/route/decision.d.ts +55 -0
- package/dist/route/decision.js +73 -0
- package/dist/route/embedding.d.ts +58 -0
- package/dist/route/embedding.js +85 -0
- package/dist/route/endpoint.d.ts +29 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor-service.d.ts +54 -0
- package/dist/route/executor-service.js +115 -0
- package/dist/route/executor.d.ts +37 -0
- package/dist/route/executor.js +225 -0
- package/dist/route/framing.d.ts +44 -0
- package/dist/route/framing.js +63 -0
- package/dist/route/index.d.ts +21 -0
- package/dist/route/index.js +18 -0
- package/dist/route/media-protocol.d.ts +187 -0
- package/dist/route/media-protocol.js +117 -0
- package/dist/route/media.d.ts +91 -0
- package/dist/route/media.js +251 -0
- package/dist/route/protocol.d.ts +85 -0
- package/dist/route/protocol.js +19 -0
- package/dist/route/transport/http.d.ts +34 -0
- package/dist/route/transport/http.js +67 -0
- package/dist/route/transport/index.d.ts +42 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket-channel.d.ts +56 -0
- package/dist/route/transport/websocket-channel.js +1 -0
- package/dist/route/transport/websocket.d.ts +32 -0
- package/dist/route/transport/websocket.js +315 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +194 -0
- package/dist/schema/errors.js +217 -0
- package/dist/schema/events.d.ts +11001 -0
- package/dist/schema/events.js +542 -0
- package/dist/schema/ids.d.ts +17 -0
- package/dist/schema/ids.js +10 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +2706 -0
- package/dist/schema/messages.js +344 -0
- package/dist/schema/options.d.ts +270 -0
- package/dist/schema/options.js +198 -0
- package/dist/speech.d.ts +266 -0
- package/dist/speech.js +114 -0
- package/dist/test-ai.d.ts +15 -0
- package/dist/test-ai.js +49 -0
- package/dist/testing.d.ts +1585 -0
- package/dist/testing.js +108 -0
- package/dist/tool-history.d.ts +2 -0
- package/dist/tool-history.js +91 -0
- package/dist/tool-runtime.d.ts +22 -0
- package/dist/tool-runtime.js +55 -0
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +150 -0
- package/dist/tool.js +159 -0
- package/dist/transcription.d.ts +254 -0
- package/dist/transcription.js +119 -0
- package/dist/utils/bytes.d.ts +1 -0
- package/dist/utils/bytes.js +10 -0
- package/dist/utils/json.d.ts +4 -0
- package/dist/utils/json.js +4 -0
- package/dist/utils/media-type.d.ts +8 -0
- package/dist/utils/media-type.js +93 -0
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/dist/utils/sanitize.d.ts +5 -0
- package/dist/utils/sanitize.js +31 -0
- package/dist/video-client.d.ts +12 -0
- package/dist/video-client.js +24 -0
- package/dist/video.d.ts +178 -0
- package/dist/video.js +79 -0
- package/package.json +648 -4
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Base64 } from "effect/encoding";
|
|
3
|
+
import { Headers } from "effect/http";
|
|
4
|
+
import { Route } from "../route/client.js";
|
|
5
|
+
import { Auth } from "../route/auth.js";
|
|
6
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
7
|
+
import { Protocol } from "../route/protocol.js";
|
|
8
|
+
import { HttpTransport } from "../route/transport/index.js";
|
|
9
|
+
import { requestTTL } from "../cache-policy.js";
|
|
10
|
+
import { resolveEffortUpdates } from "../effort-updates.js";
|
|
11
|
+
import { addsTools, toolUpdateKinds } from "../tool-updates.js";
|
|
12
|
+
import { OpenResponses } from "./open-responses.js";
|
|
13
|
+
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
14
|
+
import { JsonObject, lenient, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
15
|
+
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
16
|
+
import { OpenResponsesChannel } from "./open-responses-channel.js";
|
|
17
|
+
import { ResponsesCompaction } from "./utils/responses-compaction.js";
|
|
18
|
+
import { ResponsesCheckpoint } from "./utils/responses-checkpoint.js";
|
|
19
|
+
import * as Cache from "./utils/cache.js";
|
|
20
|
+
import { OpenAIFreeform } from "./openai-freeform.js";
|
|
21
|
+
const ADAPTER = "openai-responses";
|
|
22
|
+
const NAME = "OpenAI Responses";
|
|
23
|
+
const WEBSOCKET_PROTOCOL_HEADER = "responses_websockets=2026-02-06";
|
|
24
|
+
const WEBSOCKET_ROTATE_AFTER_MS = 55 * 60 * 1000;
|
|
25
|
+
export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
26
|
+
export const PATH = OpenResponses.PATH;
|
|
27
|
+
export const ContextManagement = Schema.Array(Schema.Struct({
|
|
28
|
+
type: Schema.Literal("compaction"),
|
|
29
|
+
compactThreshold: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
30
|
+
}));
|
|
31
|
+
export const ReasoningMode = ProviderShared.knownString();
|
|
32
|
+
export const ReasoningContext = ProviderShared.knownString();
|
|
33
|
+
const ReasoningOptions = Schema.Struct({
|
|
34
|
+
reasoningMode: lenient(ReasoningMode),
|
|
35
|
+
reasoningContext: lenient(ReasoningContext),
|
|
36
|
+
});
|
|
37
|
+
const OpenAIResponsesImageGenerationTool = Schema.Struct({
|
|
38
|
+
type: Schema.tag("image_generation"),
|
|
39
|
+
action: Schema.optional(Schema.Literals(["auto", "generate", "edit"])),
|
|
40
|
+
background: Schema.optional(Schema.Literals(["auto", "opaque", "transparent"])),
|
|
41
|
+
input_fidelity: Schema.optional(Schema.Literals(["low", "high"])),
|
|
42
|
+
output_compression: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 100 }))),
|
|
43
|
+
output_format: Schema.optional(Schema.Literals(["png", "jpeg", "webp"])),
|
|
44
|
+
partial_images: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
45
|
+
quality: Schema.optional(Schema.Literals(["auto", "low", "medium", "high"])),
|
|
46
|
+
size: Schema.optional(Schema.String.check(Schema.makeFilter((value) => {
|
|
47
|
+
if (value === "auto")
|
|
48
|
+
return undefined;
|
|
49
|
+
const match = /^(\d+)x(\d+)$/.exec(value);
|
|
50
|
+
if (!match)
|
|
51
|
+
return "image size must be `auto` or `{width}x{height}`";
|
|
52
|
+
return Number(match[1]) > 0 && Number(match[2]) > 0 ? undefined : "image dimensions must be positive integers";
|
|
53
|
+
}))),
|
|
54
|
+
});
|
|
55
|
+
const OpenAIResponsesHostedToolItem = Schema.Union([
|
|
56
|
+
Schema.StructWithRest(Schema.Struct({
|
|
57
|
+
type: Schema.tag("computer_call"),
|
|
58
|
+
id: Schema.String,
|
|
59
|
+
status: Schema.optional(Schema.String),
|
|
60
|
+
call_id: Schema.optional(Schema.String),
|
|
61
|
+
action: optionalNull(JsonObject),
|
|
62
|
+
pending_safety_checks: Schema.optional(Schema.Array(JsonObject)),
|
|
63
|
+
}), [JsonObject]),
|
|
64
|
+
Schema.StructWithRest(Schema.Struct({
|
|
65
|
+
type: Schema.tag("web_search_preview_call"),
|
|
66
|
+
id: Schema.String,
|
|
67
|
+
status: Schema.optional(Schema.String),
|
|
68
|
+
action: optionalNull(JsonObject),
|
|
69
|
+
}), [JsonObject]),
|
|
70
|
+
Schema.StructWithRest(Schema.Struct({
|
|
71
|
+
type: Schema.tag("image_generation_call"),
|
|
72
|
+
id: Schema.String,
|
|
73
|
+
status: Schema.optional(Schema.String),
|
|
74
|
+
result: optionalNull(Schema.String),
|
|
75
|
+
output_format: Schema.optional(Schema.Literals(["png", "jpeg", "webp"])),
|
|
76
|
+
revised_prompt: optionalNull(Schema.String),
|
|
77
|
+
}), [JsonObject]),
|
|
78
|
+
]);
|
|
79
|
+
const OpenAIResponsesNamespace = Schema.Struct({
|
|
80
|
+
type: Schema.tag("namespace"),
|
|
81
|
+
name: Schema.String,
|
|
82
|
+
description: Schema.String,
|
|
83
|
+
tools: Schema.Array(OpenResponses.Tool),
|
|
84
|
+
});
|
|
85
|
+
const OpenAIResponsesTools = Schema.Union([
|
|
86
|
+
OpenResponses.Tool,
|
|
87
|
+
OpenResponses.CustomTool,
|
|
88
|
+
OpenAIResponsesNamespace,
|
|
89
|
+
OpenAIResponsesImageGenerationTool,
|
|
90
|
+
]);
|
|
91
|
+
const OpenAIResponsesToolChoice = Schema.Union([
|
|
92
|
+
OpenResponses.ToolChoice,
|
|
93
|
+
Schema.Struct({ type: Schema.tag("image_generation") }),
|
|
94
|
+
]);
|
|
95
|
+
const OpenAIResponsesCoreFields = {
|
|
96
|
+
...OpenResponses.coreFields,
|
|
97
|
+
prompt_cache_retention: Schema.optional(Schema.String),
|
|
98
|
+
prompt_cache_options: Schema.optional(Schema.Struct({ ttl: Schema.optional(Schema.String) })),
|
|
99
|
+
tools: optionalArray(OpenAIResponsesTools),
|
|
100
|
+
tool_choice: Schema.optional(OpenAIResponsesToolChoice),
|
|
101
|
+
reasoning: Schema.optional(Schema.Struct({
|
|
102
|
+
effort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
|
|
103
|
+
summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"])),
|
|
104
|
+
mode: Schema.optional(ReasoningMode),
|
|
105
|
+
context: Schema.optional(ReasoningContext),
|
|
106
|
+
})),
|
|
107
|
+
context_management: Schema.optional(Schema.Array(Schema.Struct({
|
|
108
|
+
type: Schema.Literal("compaction"),
|
|
109
|
+
compact_threshold: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
110
|
+
}))),
|
|
111
|
+
};
|
|
112
|
+
const OpenAIResponsesBody = Schema.Struct({
|
|
113
|
+
...OpenAIResponsesCoreFields,
|
|
114
|
+
stream: Schema.Literal(true),
|
|
115
|
+
});
|
|
116
|
+
/** Request control, never conversation content. */
|
|
117
|
+
export const CompactionTrigger = Schema.Struct({ type: Schema.Literal("compaction_trigger") });
|
|
118
|
+
const CheckpointBody = Schema.Struct({
|
|
119
|
+
...OpenAIResponsesBody.fields,
|
|
120
|
+
input: Schema.Array(Schema.Union([OpenResponses.InputItem, CompactionTrigger])),
|
|
121
|
+
});
|
|
122
|
+
const adapter = {
|
|
123
|
+
id: ADAPTER,
|
|
124
|
+
name: NAME,
|
|
125
|
+
restoreHostedToolItem: (item) => (Schema.is(OpenAIResponsesHostedToolItem)(item) ? item : undefined),
|
|
126
|
+
};
|
|
127
|
+
// GPT-6 and later default to `configuration_update` support, except in `reasoning.mode: "pro"`
|
|
128
|
+
// or alongside automatic `context_management` compaction.
|
|
129
|
+
const supportsEffortUpdates = (request) => {
|
|
130
|
+
if (request.providerOptions?.contextManagement !== undefined)
|
|
131
|
+
return false;
|
|
132
|
+
if (request.providerOptions?.reasoningMode === "pro")
|
|
133
|
+
return false;
|
|
134
|
+
if (Schema.is(Schema.Struct({ mode: Schema.Literal("pro") }))(request.http?.body?.reasoning))
|
|
135
|
+
return false;
|
|
136
|
+
const override = request.model.capabilities?.reasoning?.updates;
|
|
137
|
+
if (override !== undefined)
|
|
138
|
+
return override;
|
|
139
|
+
const match = /(?:^|\/)gpt-(\d+)(?:\.\d+)?(?:-|$)/i.exec(request.model.id);
|
|
140
|
+
return match !== null && Number(match[1]) >= 6;
|
|
141
|
+
};
|
|
142
|
+
// `additional_tools` adds tools, and redefines one by name only when that one was declared through `additional_tools`
|
|
143
|
+
// too. So a model whose `tools.updates` includes "add" gets every tool the request declares in a leading
|
|
144
|
+
// `additional_tools` item instead of top-level `tools`; without "add" nothing goes in place. Later additions and
|
|
145
|
+
// redefinitions ("replace") are later items. The API can't withdraw a tool, so a removal ("remove") is announced in
|
|
146
|
+
// a developer message and the tool stays declared. Hosted tools stay in `tools`, since the model doesn't use one
|
|
147
|
+
// declared in `additional_tools`, and changing one folds.
|
|
148
|
+
const toolUpdates = {
|
|
149
|
+
kinds: ["add", "remove", "replace"],
|
|
150
|
+
placeable: (request) => declaresInPlace(request),
|
|
151
|
+
declarable: (tool) => !isHostedTool(tool),
|
|
152
|
+
};
|
|
153
|
+
const isHostedTool = (tool) => tool.type === "tool" && tool.native !== undefined;
|
|
154
|
+
// Automatic `context_management` compaction drops developer messages, removal notices included, while the tools stay
|
|
155
|
+
// declared, so tool changes fold alongside it.
|
|
156
|
+
const declaresInPlace = (request) => request.providerOptions?.contextManagement === undefined && toolUpdateKinds(request).includes("add");
|
|
157
|
+
const nativeImageToolInput = (tool) => {
|
|
158
|
+
const native = tool.native?.openai;
|
|
159
|
+
return ProviderShared.isRecord(native) && native.type === "image_generation" ? native : undefined;
|
|
160
|
+
};
|
|
161
|
+
const nativeImageTool = (tool) => {
|
|
162
|
+
const native = nativeImageToolInput(tool);
|
|
163
|
+
return Schema.is(OpenAIResponsesImageGenerationTool)(native) ? native : undefined;
|
|
164
|
+
};
|
|
165
|
+
const lowerTool = Effect.fnUntraced(function* (tool, custom) {
|
|
166
|
+
const native = nativeImageToolInput(tool);
|
|
167
|
+
if (native !== undefined) {
|
|
168
|
+
if (Schema.is(OpenAIResponsesImageGenerationTool)(native))
|
|
169
|
+
return native;
|
|
170
|
+
return yield* ProviderShared.invalidRequest("OpenAI Responses image generation tool options are invalid");
|
|
171
|
+
}
|
|
172
|
+
const definition = custom.get(tool.name);
|
|
173
|
+
if (definition)
|
|
174
|
+
return OpenResponses.lowerCustomTool(tool, definition);
|
|
175
|
+
return yield* OpenResponses.lowerTool(NAME, tool);
|
|
176
|
+
});
|
|
177
|
+
// Native namespaces hold only function tools, so deeper levels flatten into
|
|
178
|
+
// the leaf names the same way non-native protocols flatten the whole tree.
|
|
179
|
+
const lowerToolEntry = Effect.fnUntraced(function* (tool, custom) {
|
|
180
|
+
if (tool.type === "tool")
|
|
181
|
+
return yield* lowerTool(tool, custom);
|
|
182
|
+
// OpenAI requires a namespace description; fall back to a generic one so a
|
|
183
|
+
// missing description never blocks the request.
|
|
184
|
+
return {
|
|
185
|
+
type: "namespace",
|
|
186
|
+
name: tool.name,
|
|
187
|
+
description: tool.description ?? `Tools in the ${tool.name} namespace.`,
|
|
188
|
+
tools: yield* Effect.forEach(ProviderShared.flattenTools(tool.tools), (leaf) => OpenResponses.lowerTool(NAME, leaf)),
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
// Lowers one request's tool updates, in message order. Every `additional_tools` item after the first is preceded by
|
|
192
|
+
// a hint that it adds to the tools declared before it, naming tools removed and not declared again since. Without
|
|
193
|
+
// it, models can read the latest item as the whole set.
|
|
194
|
+
const toolChangeLowering = (declaredInPlace, custom) => {
|
|
195
|
+
let declared = declaredInPlace;
|
|
196
|
+
const unavailable = new Set();
|
|
197
|
+
return Effect.fnUntraced(function* (changes) {
|
|
198
|
+
changes.add.forEach((tool) => unavailable.delete(tool.name));
|
|
199
|
+
const hint = declared && changes.add.length > 0 ? [developer(incrementalNotice([...unavailable]))] : [];
|
|
200
|
+
const additions = changes.add.length === 0
|
|
201
|
+
? []
|
|
202
|
+
: [
|
|
203
|
+
{
|
|
204
|
+
type: "additional_tools",
|
|
205
|
+
role: "developer",
|
|
206
|
+
tools: yield* Effect.forEach(changes.add, (tool) => lowerToolEntry(tool, custom)),
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
declared = declared || changes.add.length > 0;
|
|
210
|
+
changes.remove.forEach((name) => unavailable.add(name));
|
|
211
|
+
return [...hint, ...additions, ...(changes.remove.length === 0 ? [] : [developer(removalNotice(changes.remove))])];
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
const developer = (content) => ({ type: "message", role: "developer", content });
|
|
215
|
+
const incrementalNotice = (unavailable) => [
|
|
216
|
+
"Tool update: the tools below are added to the ones you already have. Earlier tools stay available unless marked unavailable, and a tool declared again replaces its earlier definition.",
|
|
217
|
+
...(unavailable.length === 0 ? [] : [`Still unavailable: ${unavailable.join(", ")}.`]),
|
|
218
|
+
].join("\n");
|
|
219
|
+
const removalNotice = (names) => `These tools are no longer available. Do not call them: ${names.join(", ")}.`;
|
|
220
|
+
// The leading declaration: top-level `tools`, or a leading `additional_tools` item on models that add tools in place.
|
|
221
|
+
const lowerToolLayout = Effect.fnUntraced(function* (request, custom) {
|
|
222
|
+
const lower = (tools) => Effect.forEach(tools, (tool) => lowerToolEntry(tool, custom));
|
|
223
|
+
const declared = declaresInPlace(request) ? request.tools.filter((tool) => !isHostedTool(tool)) : [];
|
|
224
|
+
const top = declared.length === 0 ? request.tools : request.tools.filter(isHostedTool);
|
|
225
|
+
return {
|
|
226
|
+
head: declared.length === 0
|
|
227
|
+
? []
|
|
228
|
+
: [{ type: "additional_tools", role: "developer", tools: yield* lower(declared) }],
|
|
229
|
+
tools: top.length === 0 ? undefined : yield* lower(top),
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
const lowerToolChoice = (toolChoice, tools, custom) => ProviderShared.matchToolChoice(toolChoice, {
|
|
233
|
+
auto: () => "auto",
|
|
234
|
+
none: () => "none",
|
|
235
|
+
required: () => "required",
|
|
236
|
+
tool: (name) => tools.some((tool) => tool.type === "tool" && tool.name === name && nativeImageTool(tool) !== undefined)
|
|
237
|
+
? { type: "image_generation" }
|
|
238
|
+
: OpenResponses.namedTool(name, custom),
|
|
239
|
+
});
|
|
240
|
+
const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request) {
|
|
241
|
+
const management = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Schema.UndefinedOr(ContextManagement)))(request.providerOptions?.contextManagement);
|
|
242
|
+
const options = OpenResponsesOptions.resolve(request);
|
|
243
|
+
const reasoning = Schema.decodeUnknownSync(ReasoningOptions)(request.providerOptions ?? {});
|
|
244
|
+
const updates = resolveEffortUpdates(request, options.reasoningEffort);
|
|
245
|
+
const generation = OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort });
|
|
246
|
+
const custom = OpenAIFreeform.tools(request);
|
|
247
|
+
const layout = yield* lowerToolLayout(request, custom);
|
|
248
|
+
const conversation = yield* OpenResponses.lowerConversation(updates.request, {
|
|
249
|
+
...adapter,
|
|
250
|
+
lowerToolChanges: toolChangeLowering(layout.head.length > 0, custom),
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
model: conversation.model,
|
|
254
|
+
input: [...layout.head, ...conversation.input],
|
|
255
|
+
...generation,
|
|
256
|
+
...Cache.openAIRequestTTL(requestTTL(request)),
|
|
257
|
+
...(generation.reasoning || reasoning.reasoningMode || reasoning.reasoningContext
|
|
258
|
+
? {
|
|
259
|
+
reasoning: {
|
|
260
|
+
...generation.reasoning,
|
|
261
|
+
mode: reasoning.reasoningMode,
|
|
262
|
+
context: reasoning.reasoningContext,
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
: {}),
|
|
266
|
+
context_management: management?.map((edit) => ({ type: edit.type, compact_threshold: edit.compactThreshold })),
|
|
267
|
+
tools: layout.tools,
|
|
268
|
+
tool_choice: request.tools.length === 0 && !addsTools(request)
|
|
269
|
+
? undefined
|
|
270
|
+
: (OpenResponses.allowedToolChoice(options, custom) ??
|
|
271
|
+
(request.toolChoice ? lowerToolChoice(request.toolChoice, request.tools, custom) : undefined)),
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
const checkpointBody = {
|
|
275
|
+
schema: CheckpointBody,
|
|
276
|
+
from: Effect.fn("OpenAIResponses.checkpointBody")(function* (request) {
|
|
277
|
+
const overlay = request.http?.body;
|
|
278
|
+
// Complete history is required for stateless replay and SSE recovery. Raw input overrides bypass that contract.
|
|
279
|
+
if (overlay?.input !== undefined ||
|
|
280
|
+
overlay?.previous_response_id !== undefined ||
|
|
281
|
+
overlay?.conversation !== undefined)
|
|
282
|
+
return yield* ProviderShared.invalidRequest("Trigger compaction requires complete canonical history, not an input or continuation override");
|
|
283
|
+
if (overlay?.stream !== undefined && overlay.stream !== true)
|
|
284
|
+
return yield* ProviderShared.invalidRequest("Trigger compaction requires a streamed response");
|
|
285
|
+
const native = yield* fromRequest(request);
|
|
286
|
+
return {
|
|
287
|
+
...native,
|
|
288
|
+
input: [...native.input, { type: "compaction_trigger" }],
|
|
289
|
+
};
|
|
290
|
+
}),
|
|
291
|
+
};
|
|
292
|
+
const hostedToolResult = Effect.fnUntraced(function* (item) {
|
|
293
|
+
const isError = item.error !== undefined && item.error !== null;
|
|
294
|
+
if (item.type === "image_generation_call" && item.result) {
|
|
295
|
+
yield* Effect.fromResult(Base64.decode(item.result)).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "OpenAI Responses returned invalid image base64", undefined, cause)));
|
|
296
|
+
const format = item.output_format ?? "png";
|
|
297
|
+
return {
|
|
298
|
+
type: "content",
|
|
299
|
+
value: [
|
|
300
|
+
{
|
|
301
|
+
type: "file",
|
|
302
|
+
uri: `data:image/${format};base64,${item.result}`,
|
|
303
|
+
mime: `image/${format}`,
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
return isError ? { type: "error", value: item.error } : { type: "json", value: item };
|
|
309
|
+
});
|
|
310
|
+
const HOSTED_TOOLS = {
|
|
311
|
+
...ResponsesHostedTools.common,
|
|
312
|
+
web_search_preview_call: { name: "web_search_preview", input: (item) => item.action ?? {} },
|
|
313
|
+
computer_call: { name: "computer_use", input: (item) => item.action ?? {} },
|
|
314
|
+
image_generation_call: { name: "image_generation", input: () => ({}), result: hostedToolResult },
|
|
315
|
+
};
|
|
316
|
+
export const protocol = Protocol.make({
|
|
317
|
+
id: ADAPTER,
|
|
318
|
+
body: {
|
|
319
|
+
schema: OpenAIResponsesBody,
|
|
320
|
+
from: fromRequest,
|
|
321
|
+
},
|
|
322
|
+
stream: ResponsesHostedTools.stream(adapter, HOSTED_TOOLS, (state, event) => {
|
|
323
|
+
if (event.type !== "response.reasoning_text.delta")
|
|
324
|
+
return undefined;
|
|
325
|
+
return event.item_id !== undefined
|
|
326
|
+
? Effect.succeed(OpenResponses.onReasoningDelta(state, event, event.item_id))
|
|
327
|
+
: ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
|
|
328
|
+
}),
|
|
329
|
+
supportsEffortUpdates,
|
|
330
|
+
toolUpdates,
|
|
331
|
+
namespaces: true,
|
|
332
|
+
});
|
|
333
|
+
const endpoint = Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL });
|
|
334
|
+
const auth = Auth.none;
|
|
335
|
+
export const httpTransport = HttpTransport.sseJson.with();
|
|
336
|
+
export const channelTransport = OpenResponsesChannel.transport;
|
|
337
|
+
export const transport = channelTransport({
|
|
338
|
+
id: ADAPTER,
|
|
339
|
+
name: NAME,
|
|
340
|
+
rotateAfterMs: WEBSOCKET_ROTATE_AFTER_MS,
|
|
341
|
+
headers: (headers) => Headers.set(headers, "openai-beta", headers["openai-beta"] ?? WEBSOCKET_PROTOCOL_HEADER),
|
|
342
|
+
});
|
|
343
|
+
export const route = Route.make({
|
|
344
|
+
compact: {
|
|
345
|
+
endpoint: ResponsesCompaction.make(adapter, (request) => {
|
|
346
|
+
const custom = OpenAIFreeform.tools(request);
|
|
347
|
+
return Effect.forEach(request.tools, (tool) => lowerToolEntry(tool, custom));
|
|
348
|
+
}),
|
|
349
|
+
trigger: ResponsesCheckpoint.make(checkpointBody),
|
|
350
|
+
},
|
|
351
|
+
id: ADAPTER,
|
|
352
|
+
provider: "openai",
|
|
353
|
+
providerMetadataKey: "openai",
|
|
354
|
+
protocol,
|
|
355
|
+
endpoint,
|
|
356
|
+
auth,
|
|
357
|
+
transport,
|
|
358
|
+
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
|
359
|
+
});
|
|
360
|
+
export * as OpenAIResponses from "./openai-responses.js";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
|
+
import { MediaRoute } from "../route/media.js";
|
|
3
|
+
import { type MediaUsage } from "../schema/index.js";
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
|
+
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
7
|
+
export declare const PATH = "/audio/speech";
|
|
8
|
+
/** `voice`, `instructions`, `speed`, and `format` are common request fields; other native body fields pass through. */
|
|
9
|
+
export type OpenAISpeechOptions = {
|
|
10
|
+
/** Defaults to `"sse"` in `stream` mode on models that support it; the merged value selects the response framing. */
|
|
11
|
+
readonly stream_format?: "sse" | "audio";
|
|
12
|
+
} & Record<string, unknown>;
|
|
13
|
+
export type Request = SpeechRequest<SpeechModel<OpenAISpeechOptions>>;
|
|
14
|
+
interface State extends SpeechStream.Audio {
|
|
15
|
+
readonly done: boolean;
|
|
16
|
+
readonly usage?: MediaUsage;
|
|
17
|
+
}
|
|
18
|
+
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
|
+
readonly type: "audio-delta";
|
|
20
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "timestamps";
|
|
23
|
+
readonly items: readonly {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly startSeconds: number;
|
|
26
|
+
readonly endSeconds: number;
|
|
27
|
+
}[];
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "generation-progress";
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly progress?: number | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "finish";
|
|
34
|
+
readonly audio: import("../media.js").Asset;
|
|
35
|
+
readonly usage?: {
|
|
36
|
+
readonly type: "seconds";
|
|
37
|
+
readonly seconds: number;
|
|
38
|
+
} | {
|
|
39
|
+
readonly type: "characters";
|
|
40
|
+
readonly characters: number;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "credits";
|
|
43
|
+
readonly credits: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: "compute";
|
|
46
|
+
readonly seconds: number;
|
|
47
|
+
} | {
|
|
48
|
+
readonly type: "tokens";
|
|
49
|
+
readonly input?: number | undefined;
|
|
50
|
+
readonly output?: number | undefined;
|
|
51
|
+
readonly total?: number | undefined;
|
|
52
|
+
readonly details?: {
|
|
53
|
+
readonly [x: string]: unknown;
|
|
54
|
+
} | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
readonly providerMetadata?: {
|
|
57
|
+
readonly [x: string]: {
|
|
58
|
+
readonly [x: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
} | undefined;
|
|
61
|
+
}, string | Uint8Array<ArrayBufferLike>, State>;
|
|
62
|
+
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<OpenAISpeechOptions>;
|
|
63
|
+
export declare const OpenAISpeech: {
|
|
64
|
+
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
65
|
+
readonly type: "audio-delta";
|
|
66
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
67
|
+
} | {
|
|
68
|
+
readonly type: "timestamps";
|
|
69
|
+
readonly items: readonly {
|
|
70
|
+
readonly text: string;
|
|
71
|
+
readonly startSeconds: number;
|
|
72
|
+
readonly endSeconds: number;
|
|
73
|
+
}[];
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "generation-progress";
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly progress?: number | undefined;
|
|
78
|
+
} | {
|
|
79
|
+
readonly type: "finish";
|
|
80
|
+
readonly audio: import("../media.js").Asset;
|
|
81
|
+
readonly usage?: {
|
|
82
|
+
readonly type: "seconds";
|
|
83
|
+
readonly seconds: number;
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: "characters";
|
|
86
|
+
readonly characters: number;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "credits";
|
|
89
|
+
readonly credits: number;
|
|
90
|
+
} | {
|
|
91
|
+
readonly type: "compute";
|
|
92
|
+
readonly seconds: number;
|
|
93
|
+
} | {
|
|
94
|
+
readonly type: "tokens";
|
|
95
|
+
readonly input?: number | undefined;
|
|
96
|
+
readonly output?: number | undefined;
|
|
97
|
+
readonly total?: number | undefined;
|
|
98
|
+
readonly details?: {
|
|
99
|
+
readonly [x: string]: unknown;
|
|
100
|
+
} | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
readonly providerMetadata?: {
|
|
103
|
+
readonly [x: string]: {
|
|
104
|
+
readonly [x: string]: unknown;
|
|
105
|
+
};
|
|
106
|
+
} | undefined;
|
|
107
|
+
}, string | Uint8Array<ArrayBufferLike>, State>;
|
|
108
|
+
readonly model: typeof model;
|
|
109
|
+
};
|
|
110
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Effect, Schema, SchemaGetter } from "effect";
|
|
2
|
+
import { Framing } from "../route/framing.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
|
|
6
|
+
import { SpeechModel } from "../speech.js";
|
|
7
|
+
import { SpeechStream } from "./utils/speech-stream.js";
|
|
8
|
+
const route = MediaProtocol.identity({ id: "openai-speech", name: "OpenAI Speech", provider: "openai" });
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
10
|
+
export const PATH = "/audio/speech";
|
|
11
|
+
/** `pcm` is raw 24 kHz, 16-bit signed little-endian mono samples without a header. */
|
|
12
|
+
const PCM_SAMPLE_RATE = 24000;
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// 3. Streaming event schema
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
const EVENT_TYPES = new Set(["speech.audio.delta", "speech.audio.done"]);
|
|
17
|
+
/** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
|
|
18
|
+
const UnknownEvent = Schema.Struct({
|
|
19
|
+
type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
|
|
20
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
|
|
21
|
+
decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
|
|
22
|
+
encode: SchemaGetter.forbidden(() => "Unknown OpenAI Speech stream events are decode-only"),
|
|
23
|
+
}));
|
|
24
|
+
const SpeechStreamEvent = Schema.Union([
|
|
25
|
+
Schema.Struct({ type: Schema.Literal("speech.audio.delta"), audio: Schema.Uint8ArrayFromBase64 }),
|
|
26
|
+
Schema.Struct({
|
|
27
|
+
type: Schema.Literal("speech.audio.done"),
|
|
28
|
+
usage: Schema.optional(Schema.Struct({
|
|
29
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
30
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
31
|
+
total_tokens: Schema.optional(Schema.Number),
|
|
32
|
+
})),
|
|
33
|
+
}),
|
|
34
|
+
UnknownEvent,
|
|
35
|
+
]);
|
|
36
|
+
const decodeEvent = route.decodeFrame(SpeechStreamEvent);
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// 5. Request body construction
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// `sse` is not supported for `tts-1` or `tts-1-hd`; those models stream the raw audio body instead.
|
|
41
|
+
const supportsSse = (model) => !/^tts-1(-hd)?(-|$)/.test(model);
|
|
42
|
+
const FORMATS = new Set(["mp3", "opus", "aac", "flac", "wav", "pcm"]);
|
|
43
|
+
const fromRequest = Effect.fn("OpenAISpeech.fromRequest")(function* (request) {
|
|
44
|
+
// Not in `unsupported`: that list would also reject `timestamps: false`, which asks for nothing.
|
|
45
|
+
if (request.timestamps === true)
|
|
46
|
+
return yield* route.unsupported("media.timestamps", `${route.name} does not return timestamps`);
|
|
47
|
+
if (request.format !== undefined && !FORMATS.has(request.format))
|
|
48
|
+
return yield* route.unsupported("media.format", `${route.name} supports the mp3, opus, aac, flac, wav, and pcm formats, not "${request.format}"`);
|
|
49
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
50
|
+
model: request.model.id,
|
|
51
|
+
input: request.text,
|
|
52
|
+
voice: request.voice,
|
|
53
|
+
instructions: request.instructions,
|
|
54
|
+
response_format: request.format,
|
|
55
|
+
speed: request.speed,
|
|
56
|
+
stream_format: request.mode === "stream" && supportsSse(request.model.id) ? "sse" : undefined,
|
|
57
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
58
|
+
});
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// 6. Stream parsing
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
const isSse = (body) => body.type === "json" && body.value.stream_format === "sse";
|
|
63
|
+
const onEvent = Effect.fnUntraced(function* (state, frame) {
|
|
64
|
+
const event = yield* decodeEvent(frame);
|
|
65
|
+
if (event.type === "unknown")
|
|
66
|
+
return [state, []];
|
|
67
|
+
if (event.type === "speech.audio.delta")
|
|
68
|
+
return SpeechStream.delta(state, event.audio);
|
|
69
|
+
const usage = event.usage;
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
...state,
|
|
73
|
+
done: true,
|
|
74
|
+
usage: usage === undefined
|
|
75
|
+
? undefined
|
|
76
|
+
: tokenUsage({
|
|
77
|
+
input: usage.input_tokens,
|
|
78
|
+
output: usage.output_tokens,
|
|
79
|
+
total: usage.total_tokens,
|
|
80
|
+
details: { openai: usage },
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
[],
|
|
84
|
+
];
|
|
85
|
+
});
|
|
86
|
+
const finish = (state, context) => {
|
|
87
|
+
if (isSse(context.body) && !state.done)
|
|
88
|
+
return Effect.fail(route.incomplete());
|
|
89
|
+
// The sent body reflects `providerOptions` and `http.body` overrides of `format`.
|
|
90
|
+
const sent = context.body.type === "json" ? context.body.value.response_format : undefined;
|
|
91
|
+
const format = typeof sent === "string" ? sent : "mp3";
|
|
92
|
+
return SpeechStream.finish(route, state, {
|
|
93
|
+
...(format === "pcm" ? SpeechStream.pcm("pcm_s16le", PCM_SAMPLE_RATE) : SpeechStream.container(format)),
|
|
94
|
+
usage: state.usage,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// 7. Protocol and route
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
export const protocol = MediaProtocol.stream(route, {
|
|
101
|
+
unsupported: ["language"],
|
|
102
|
+
body: { from: fromRequest },
|
|
103
|
+
frames: (bytes, context) => (isSse(context.body) ? Framing.sse.frame(bytes) : bytes),
|
|
104
|
+
initial: () => ({ chunks: [], done: false }),
|
|
105
|
+
step: SpeechStream.step(onEvent),
|
|
106
|
+
finish,
|
|
107
|
+
});
|
|
108
|
+
export const model = (input) => SpeechModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
109
|
+
export const OpenAISpeech = {
|
|
110
|
+
protocol,
|
|
111
|
+
model,
|
|
112
|
+
};
|