@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,303 @@
|
|
|
1
|
+
import { Effect, Schema, SchemaGetter, Stream } from "effect";
|
|
2
|
+
import { ImageFinishEvent, ImageModel, ImageOutputEvent, ImagePartialEvent, } from "../image.js";
|
|
3
|
+
import { Media } from "../media.js";
|
|
4
|
+
import { classifyProviderFailure } from "../provider-error.js";
|
|
5
|
+
import { Framing } from "../route/framing.js";
|
|
6
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
7
|
+
import { MediaRoute } from "../route/media.js";
|
|
8
|
+
import { AIError, mergeJsonRecords, ProviderID, tokenUsage } from "../schema/index.js";
|
|
9
|
+
import { optionalNull, ProviderShared } from "./shared.js";
|
|
10
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
11
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
12
|
+
const route = MediaProtocol.identity({ id: "openai-images", name: "OpenAI Images", provider: "openai" });
|
|
13
|
+
export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
14
|
+
export const PATH = "/images/generations";
|
|
15
|
+
export const EDIT_PATH = "/images/edits";
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// 2. Response schema
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
const Usage = Schema.Struct({
|
|
20
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
21
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
22
|
+
total_tokens: Schema.optional(Schema.Number),
|
|
23
|
+
input_tokens_details: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
24
|
+
output_tokens_details: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
25
|
+
});
|
|
26
|
+
/** What the provider actually rendered; it can differ from the request when `auto` or a default applied. */
|
|
27
|
+
const Settings = {
|
|
28
|
+
output_format: Schema.optional(Schema.String),
|
|
29
|
+
size: Schema.optional(Schema.String),
|
|
30
|
+
quality: Schema.optional(Schema.String),
|
|
31
|
+
background: Schema.optional(Schema.String),
|
|
32
|
+
};
|
|
33
|
+
const OpenAIImageResponse = Schema.Struct({
|
|
34
|
+
// GPT Image models always return `b64_json`; compatible hosts that default to `url` can return either.
|
|
35
|
+
data: Schema.Array(Schema.Struct({ b64_json: optionalNull(Schema.String), url: optionalNull(Schema.String) })),
|
|
36
|
+
...Settings,
|
|
37
|
+
usage: Schema.optional(Usage),
|
|
38
|
+
});
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// 3. Streaming event schema
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
const EVENT_TYPES = new Set([
|
|
43
|
+
"image_generation.partial_image",
|
|
44
|
+
"image_edit.partial_image",
|
|
45
|
+
"image_generation.completed",
|
|
46
|
+
"image_edit.completed",
|
|
47
|
+
"error",
|
|
48
|
+
]);
|
|
49
|
+
/** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
|
|
50
|
+
const UnknownEvent = Schema.Struct({
|
|
51
|
+
type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
|
|
52
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
|
|
53
|
+
decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
|
|
54
|
+
encode: SchemaGetter.forbidden(() => "Unknown OpenAI Images stream events are decode-only"),
|
|
55
|
+
}));
|
|
56
|
+
const StreamEvent = Schema.Union([
|
|
57
|
+
Schema.Struct({
|
|
58
|
+
type: Schema.Literals(["image_generation.partial_image", "image_edit.partial_image"]),
|
|
59
|
+
b64_json: Schema.String,
|
|
60
|
+
partial_image_index: Schema.Number,
|
|
61
|
+
...Settings,
|
|
62
|
+
output_format: Schema.String,
|
|
63
|
+
}),
|
|
64
|
+
Schema.Struct({
|
|
65
|
+
type: Schema.Literals(["image_generation.completed", "image_edit.completed"]),
|
|
66
|
+
b64_json: Schema.String,
|
|
67
|
+
...Settings,
|
|
68
|
+
output_format: Schema.String,
|
|
69
|
+
usage: Schema.optional(Usage),
|
|
70
|
+
}),
|
|
71
|
+
Schema.Struct({
|
|
72
|
+
type: Schema.Literal("error"),
|
|
73
|
+
error: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) })),
|
|
74
|
+
}),
|
|
75
|
+
UnknownEvent,
|
|
76
|
+
]);
|
|
77
|
+
const decodeEvent = route.decodeFrame(StreamEvent);
|
|
78
|
+
const decodeDocument = Schema.decodeUnknownEffect(Schema.fromJsonString(OpenAIImageResponse));
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// 5. Request body construction
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/** Multipart field names the route owns; `http.body` overlays cannot smuggle replacements for them. */
|
|
83
|
+
const RESERVED_FORM_FIELDS = new Set(["model", "prompt", "image", "image[]", "images", "mask"]);
|
|
84
|
+
const nativeOptions = (options) => {
|
|
85
|
+
if (!options)
|
|
86
|
+
return undefined;
|
|
87
|
+
const { outputCompression, outputFormat, partialImages: _, mask: __, ...native } = options;
|
|
88
|
+
// `response_format: null` drops a provider's default, for hosts that reject the field.
|
|
89
|
+
return {
|
|
90
|
+
output_compression: outputCompression,
|
|
91
|
+
output_format: outputFormat,
|
|
92
|
+
...native,
|
|
93
|
+
response_format: native.response_format ?? undefined,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* `gpt-image-1`, `chatgpt-image` and DALL·E take a fixed list, `gpt-image-2` and later any size within limits. Other
|
|
98
|
+
* models are gateway-hosted (`bfl/flux-2-pro`); the gateway passes `size` through to them as is.
|
|
99
|
+
*/
|
|
100
|
+
const sizes = (model) => {
|
|
101
|
+
const id = model.slice(model.lastIndexOf("/") + 1);
|
|
102
|
+
if (id.startsWith("dall-e-2"))
|
|
103
|
+
return [256, 512, 1024].map((edge) => ({ width: edge, height: edge }));
|
|
104
|
+
if (id.startsWith("dall-e-3"))
|
|
105
|
+
return [
|
|
106
|
+
{ width: 1024, height: 1024 },
|
|
107
|
+
{ width: 1792, height: 1024 },
|
|
108
|
+
{ width: 1024, height: 1792 },
|
|
109
|
+
];
|
|
110
|
+
if (/^(gpt-image-1|chatgpt-image)/.test(id))
|
|
111
|
+
return [
|
|
112
|
+
{ width: 1024, height: 1024 },
|
|
113
|
+
{ width: 1536, height: 1024 },
|
|
114
|
+
{ width: 1024, height: 1536 },
|
|
115
|
+
];
|
|
116
|
+
if (id.startsWith("gpt-image-"))
|
|
117
|
+
return { multiple: 16, maxEdge: 3840, minPixels: 655_360, maxPixels: 8_294_400, maxRatio: 3 };
|
|
118
|
+
return { multiple: 16 };
|
|
119
|
+
};
|
|
120
|
+
const pixelSize = (request) => {
|
|
121
|
+
if (!ImageSizing.isRequested(request))
|
|
122
|
+
return undefined;
|
|
123
|
+
const options = sizes(request.model.id);
|
|
124
|
+
const size = "multiple" in options ? ImageSizing.fit(request, options) : ImageSizing.nearest(request, options);
|
|
125
|
+
return { size: `${size.width}x${size.height}` };
|
|
126
|
+
};
|
|
127
|
+
const streamOptions = (request) => {
|
|
128
|
+
if (request.mode !== "stream")
|
|
129
|
+
return Effect.succeed(undefined);
|
|
130
|
+
if (request.n !== undefined && request.n > 1)
|
|
131
|
+
return Effect.fail(route.unsupported("media.n", `${route.name} streams one image; use Image.generate for n=${request.n}`));
|
|
132
|
+
return Effect.succeed({ stream: true, partial_images: request.providerOptions?.partialImages ?? 2 });
|
|
133
|
+
};
|
|
134
|
+
const isEdit = (request) => (request.images?.length ?? 0) > 0;
|
|
135
|
+
const isInline = (asset) => asset.source.type === "bytes" || asset.source.type === "base64";
|
|
136
|
+
const reference = (asset, provider) => ProviderShared.mediaReference(asset, provider, route.name).pipe(Effect.map((item) => (item.type === "ref" ? { file_id: item.value } : { image_url: item.value })));
|
|
137
|
+
const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request, options) {
|
|
138
|
+
const images = request.images ?? [];
|
|
139
|
+
const mask = request.providerOptions?.mask;
|
|
140
|
+
if (options.imageInput === "references" && mask !== undefined)
|
|
141
|
+
return yield* route.unsupported("media.mask", `${request.model.provider} image edits take no mask`);
|
|
142
|
+
if (mask !== undefined && images.length === 0)
|
|
143
|
+
return yield* ProviderShared.invalidRequest("An OpenAI image mask requires at least one input image");
|
|
144
|
+
if (request.providerOptions?.size !== undefined && ImageSizing.isRequested(request))
|
|
145
|
+
return yield* ProviderShared.invalidRequest("OpenAI providerOptions.size replaces aspect and resolution; set one or the other");
|
|
146
|
+
const fields = mergeJsonRecords({
|
|
147
|
+
n: request.n,
|
|
148
|
+
...options.sizing(request),
|
|
149
|
+
...(yield* streamOptions(request)),
|
|
150
|
+
}, nativeOptions(request.providerOptions), request.http?.body);
|
|
151
|
+
if (options.imageInput === "references") {
|
|
152
|
+
const references = yield* Effect.forEach(images, (image) => ProviderShared.mediaReference(image, undefined, route.name));
|
|
153
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
154
|
+
model: request.model.id,
|
|
155
|
+
prompt: request.prompt,
|
|
156
|
+
input_references: references.length === 0
|
|
157
|
+
? undefined
|
|
158
|
+
: references.map((item) => ({ type: "image_url", image_url: { url: item.value } })),
|
|
159
|
+
}, fields) ?? {});
|
|
160
|
+
}
|
|
161
|
+
// Owned bytes go through multipart edits; remote URLs, file IDs and `json-edits` hosts use the JSON edits body.
|
|
162
|
+
if (options.imageInput === "edits" &&
|
|
163
|
+
images.length > 0 &&
|
|
164
|
+
images.every(isInline) &&
|
|
165
|
+
(mask === undefined || isInline(mask))) {
|
|
166
|
+
const form = new FormData();
|
|
167
|
+
MediaInput.appendFields(form, { model: request.model.id, prompt: request.prompt }, { overlay: fields, reserved: RESERVED_FORM_FIELDS });
|
|
168
|
+
const uploads = yield* Effect.forEach(images, (image) => MediaInput.inlineBytes(route.id, image));
|
|
169
|
+
uploads.forEach((data, index) => form.append("image[]", MediaInput.blob(data, images[index].mediaType), `image-${index}`));
|
|
170
|
+
if (mask !== undefined)
|
|
171
|
+
form.append("mask", MediaInput.blob(yield* MediaInput.inlineBytes(route.id, mask), mask.mediaType), "mask");
|
|
172
|
+
return MediaProtocol.multipart(form);
|
|
173
|
+
}
|
|
174
|
+
const references = yield* Effect.forEach(images, (image) => reference(image, request.model.provider));
|
|
175
|
+
const maskReference = mask === undefined ? undefined : yield* reference(mask, request.model.provider);
|
|
176
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
177
|
+
model: request.model.id,
|
|
178
|
+
prompt: request.prompt,
|
|
179
|
+
images: references.length === 0 ? undefined : references,
|
|
180
|
+
mask: maskReference,
|
|
181
|
+
}, fields) ?? {});
|
|
182
|
+
});
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// 6. Stream parsing
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
const usage = (value, provider) => value === undefined
|
|
187
|
+
? undefined
|
|
188
|
+
: tokenUsage({
|
|
189
|
+
input: value.input_tokens,
|
|
190
|
+
output: value.output_tokens,
|
|
191
|
+
total: value.total_tokens,
|
|
192
|
+
details: { [provider]: value },
|
|
193
|
+
});
|
|
194
|
+
/** `size` echoes the rendered `WIDTHxHEIGHT`; `auto` or any other value leaves the dimensions unknown. */
|
|
195
|
+
const info = (format, size) => {
|
|
196
|
+
const match = size?.match(/^(\d+)x(\d+)$/);
|
|
197
|
+
return match ? { format, width: Number(match[1]), height: Number(match[2]) } : { format };
|
|
198
|
+
};
|
|
199
|
+
const eventImage = (frame, label, data, format, size) => MediaInput.decodedAsset((message, cause) => route.frameError(message, frame, cause), label, data, `image/${format}`, {
|
|
200
|
+
info: info(format, size),
|
|
201
|
+
});
|
|
202
|
+
const onEvent = Effect.fnUntraced(function* (state, frame) {
|
|
203
|
+
const event = yield* decodeEvent(frame);
|
|
204
|
+
if (event.type === "unknown")
|
|
205
|
+
return [state, []];
|
|
206
|
+
if (event.type === "error")
|
|
207
|
+
return yield* new AIError({
|
|
208
|
+
reason: classifyProviderFailure({
|
|
209
|
+
message: `${route.name} stream failed: ${event.error?.message ?? "unknown error"}`,
|
|
210
|
+
rawBody: frame,
|
|
211
|
+
}),
|
|
212
|
+
});
|
|
213
|
+
const format = event.output_format;
|
|
214
|
+
if ("partial_image_index" in event) {
|
|
215
|
+
const image = yield* eventImage(frame, `${route.name} partial image`, event.b64_json, format, event.size);
|
|
216
|
+
return [state, [ImagePartialEvent.make({ index: event.partial_image_index, image })]];
|
|
217
|
+
}
|
|
218
|
+
const image = yield* eventImage(frame, `${route.name} result ${state.completed}`, event.b64_json, format, event.size);
|
|
219
|
+
return [
|
|
220
|
+
{
|
|
221
|
+
completed: state.completed + 1,
|
|
222
|
+
format,
|
|
223
|
+
size: event.size,
|
|
224
|
+
quality: event.quality,
|
|
225
|
+
background: event.background,
|
|
226
|
+
usage: event.usage,
|
|
227
|
+
},
|
|
228
|
+
[ImageOutputEvent.make({ index: state.completed, image })],
|
|
229
|
+
];
|
|
230
|
+
});
|
|
231
|
+
const onDocument = Effect.fnUntraced(function* (frame) {
|
|
232
|
+
const invalid = (message, cause) => route.frameError(message, frame.document, cause);
|
|
233
|
+
const decoded = yield* decodeDocument(frame.document).pipe(Effect.mapError((cause) => invalid(`${route.name} returned an invalid response`, cause)));
|
|
234
|
+
// Compatible hosts may omit `output_format` and ignore the requested one, so the bytes decide unreported types.
|
|
235
|
+
const format = decoded.output_format;
|
|
236
|
+
const mediaType = format === undefined ? undefined : `image/${format}`;
|
|
237
|
+
const images = yield* Effect.forEach(decoded.data, (item, index) => MediaInput.imageOutput(invalid, `${route.name} result ${index}`, item, mediaType, {
|
|
238
|
+
info: info(format, decoded.size),
|
|
239
|
+
}));
|
|
240
|
+
if (images.length === 0)
|
|
241
|
+
return yield* invalid(`${route.name} returned no images`);
|
|
242
|
+
const state = {
|
|
243
|
+
completed: images.length,
|
|
244
|
+
format,
|
|
245
|
+
size: decoded.size,
|
|
246
|
+
quality: decoded.quality,
|
|
247
|
+
background: decoded.background,
|
|
248
|
+
usage: decoded.usage,
|
|
249
|
+
};
|
|
250
|
+
return [state, images.map((image, index) => ImageOutputEvent.make({ index, image }))];
|
|
251
|
+
});
|
|
252
|
+
const step = (state, frame) => (typeof frame === "string" ? onEvent(state, frame) : onDocument(frame));
|
|
253
|
+
const finish = (state, context) => {
|
|
254
|
+
if (state.completed === 0)
|
|
255
|
+
return Effect.fail(route.incomplete());
|
|
256
|
+
const provider = context.request.model.provider;
|
|
257
|
+
return Effect.succeed([
|
|
258
|
+
ImageFinishEvent.make({
|
|
259
|
+
usage: usage(state.usage, provider),
|
|
260
|
+
providerMetadata: {
|
|
261
|
+
[provider]: {
|
|
262
|
+
outputFormat: state.format,
|
|
263
|
+
size: state.size,
|
|
264
|
+
quality: state.quality,
|
|
265
|
+
background: state.background,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
}),
|
|
269
|
+
]);
|
|
270
|
+
};
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// 7. Protocol and route
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
const makeProtocol = (options) => MediaProtocol.stream(route, {
|
|
275
|
+
body: { from: (request) => fromRequest(request, options) },
|
|
276
|
+
frames: (bytes, context) => context.request.mode === "stream"
|
|
277
|
+
? Framing.sse.frame(bytes)
|
|
278
|
+
: Framing.document.frame(bytes).pipe(Stream.map((document) => ({ document }))),
|
|
279
|
+
initial: () => ({ completed: 0 }),
|
|
280
|
+
step,
|
|
281
|
+
finish,
|
|
282
|
+
});
|
|
283
|
+
export const protocol = makeProtocol({ sizing: pixelSize, imageInput: "edits" });
|
|
284
|
+
/**
|
|
285
|
+
* `provider` attributes models, refs, and metadata to an OpenAI-compatible host; it defaults to `openai`. `sizing`
|
|
286
|
+
* replaces the `size` that `aspect` and `resolution` lower to, and `imageInput` how input images are sent.
|
|
287
|
+
*/
|
|
288
|
+
export const model = (input) => {
|
|
289
|
+
const imageInput = input.imageInput ?? "edits";
|
|
290
|
+
const base = input.sizing === undefined && imageInput === "edits"
|
|
291
|
+
? protocol
|
|
292
|
+
: makeProtocol({ sizing: input.sizing ?? pixelSize, imageInput });
|
|
293
|
+
return ImageModel.fromRoute({
|
|
294
|
+
protocol: input.provider === undefined ? base : { ...base, provider: ProviderID.make(input.provider) },
|
|
295
|
+
baseURL: DEFAULT_BASE_URL,
|
|
296
|
+
path: ({ request }) => (imageInput !== "references" && isEdit(request) ? EDIT_PATH : PATH),
|
|
297
|
+
}, input);
|
|
298
|
+
};
|
|
299
|
+
export const OpenAIImages = {
|
|
300
|
+
protocol,
|
|
301
|
+
model,
|
|
302
|
+
pixelSize,
|
|
303
|
+
};
|