@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,189 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Base64 } from "effect/encoding";
|
|
3
|
+
import { Protocol } from "../route/protocol.js";
|
|
4
|
+
import { AssistantMessage, StreamEvent, ToolResultPart } from "../schema/index.js";
|
|
5
|
+
import { OpenResponses } from "./open-responses.js";
|
|
6
|
+
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
7
|
+
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
8
|
+
import { detectMediaType } from "../utils/media-type.js";
|
|
9
|
+
const ADAPTER = "meta-responses";
|
|
10
|
+
const NAME = "Meta Responses";
|
|
11
|
+
export const WebSearch = Schema.Struct({
|
|
12
|
+
type: Schema.Literal("web_search"),
|
|
13
|
+
search_context_size: Schema.optional(Schema.String),
|
|
14
|
+
user_location: Schema.optional(Schema.Struct({
|
|
15
|
+
type: Schema.Literal("approximate"),
|
|
16
|
+
city: Schema.optional(Schema.String),
|
|
17
|
+
region: Schema.optional(Schema.String),
|
|
18
|
+
country: Schema.optional(Schema.String),
|
|
19
|
+
timezone: Schema.optional(Schema.String),
|
|
20
|
+
})),
|
|
21
|
+
});
|
|
22
|
+
export const ImageGeneration = Schema.Struct({
|
|
23
|
+
type: Schema.Literal("image_generation"),
|
|
24
|
+
size: Schema.optional(Schema.String),
|
|
25
|
+
output_format: Schema.optional(Schema.String),
|
|
26
|
+
reasoning_strength: Schema.optional(Schema.String),
|
|
27
|
+
enable_image_search: Schema.optional(Schema.Boolean),
|
|
28
|
+
enable_web_search: Schema.optional(Schema.Boolean),
|
|
29
|
+
enable_shell: Schema.optional(Schema.Boolean),
|
|
30
|
+
});
|
|
31
|
+
const NativeTool = Schema.Union([WebSearch, ImageGeneration]);
|
|
32
|
+
const ImageItem = Schema.Struct({
|
|
33
|
+
type: Schema.Literal("image_generation_call"),
|
|
34
|
+
id: Schema.String,
|
|
35
|
+
status: Schema.optional(Schema.String),
|
|
36
|
+
result: optionalNull(Schema.String),
|
|
37
|
+
output_format: Schema.optional(Schema.String),
|
|
38
|
+
error: Schema.optional(Schema.Unknown),
|
|
39
|
+
});
|
|
40
|
+
const MessageAnnotations = Schema.Struct({
|
|
41
|
+
content: Schema.Array(Schema.Struct({ annotations: optionalArray(JsonObject) })),
|
|
42
|
+
});
|
|
43
|
+
const adapter = {
|
|
44
|
+
id: ADAPTER,
|
|
45
|
+
name: NAME,
|
|
46
|
+
nativeTool: (native) => ProviderShared.validateWith(Schema.decodeUnknownEffect(NativeTool))(native.meta),
|
|
47
|
+
restoreHostedToolItem: (item) => (Schema.is(ImageItem)(item) ? item : undefined),
|
|
48
|
+
};
|
|
49
|
+
const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
50
|
+
const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
|
|
51
|
+
const body = yield* OpenResponses.fromRequestWithAdapter({
|
|
52
|
+
...request,
|
|
53
|
+
messages: request.messages.map((message) => message.role !== "assistant"
|
|
54
|
+
? message
|
|
55
|
+
: new AssistantMessage({
|
|
56
|
+
...message,
|
|
57
|
+
content: message.content.map((part) => {
|
|
58
|
+
if (part.type !== "tool-result" ||
|
|
59
|
+
!part.providerExecuted ||
|
|
60
|
+
part.name !== "image_generation" ||
|
|
61
|
+
part.result.type !== "content" ||
|
|
62
|
+
part.providerMetadata?.[key]?.itemId !== part.id)
|
|
63
|
+
return part;
|
|
64
|
+
// Meta's signed image ID carries edit state; replay the handle, not the image bytes as a user message.
|
|
65
|
+
return ToolResultPart.make({
|
|
66
|
+
...part,
|
|
67
|
+
result: {
|
|
68
|
+
type: "json",
|
|
69
|
+
value: { type: "image_generation_call", id: part.id, status: "completed", result: null },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
})),
|
|
74
|
+
}, adapter);
|
|
75
|
+
// Meta cannot see video nested in tool results; attach it after the complete result batch.
|
|
76
|
+
const input = [];
|
|
77
|
+
const videos = [];
|
|
78
|
+
const flushVideos = () => {
|
|
79
|
+
if (videos.length > 0)
|
|
80
|
+
input.push({ type: "message", role: "user", content: videos.splice(0) });
|
|
81
|
+
};
|
|
82
|
+
for (const item of body.input) {
|
|
83
|
+
if (!isFunctionCallOutput(item)) {
|
|
84
|
+
flushVideos();
|
|
85
|
+
input.push(item);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (typeof item.output === "string") {
|
|
89
|
+
input.push(item);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const content = item.output.filter((part) => part.type !== "input_video");
|
|
93
|
+
videos.push(...item.output.filter((part) => part.type === "input_video"));
|
|
94
|
+
input.push({
|
|
95
|
+
...item,
|
|
96
|
+
output: content.length === 0 && item.output.length > 0 ? "Video attached in the following user message." : content,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
flushVideos();
|
|
100
|
+
return { ...body, input };
|
|
101
|
+
});
|
|
102
|
+
// Hosted replay items have an open `type`, so a plain tag check does not narrow the union.
|
|
103
|
+
const isFunctionCallOutput = (item) => item.type === "function_call_output" || item.type === "custom_tool_call_output";
|
|
104
|
+
const HOSTED_TOOLS = {
|
|
105
|
+
web_search_call: ResponsesHostedTools.common.web_search_call,
|
|
106
|
+
image_generation_call: {
|
|
107
|
+
name: "image_generation",
|
|
108
|
+
input: () => ({}),
|
|
109
|
+
result: Effect.fnUntraced(function* (raw) {
|
|
110
|
+
const item = yield* Schema.decodeUnknownEffect(ImageItem)(raw).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned an invalid image item", ProviderShared.encodeJson(raw), cause)));
|
|
111
|
+
if (item.error !== undefined && item.error !== null)
|
|
112
|
+
return { type: "error", value: item.error };
|
|
113
|
+
if (!item.result)
|
|
114
|
+
return yield* ProviderShared.eventError(ADAPTER, "Meta returned an image without data", ProviderShared.encodeJson(raw));
|
|
115
|
+
const data = yield* Effect.fromResult(Base64.decode(item.result)).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned invalid image base64", ProviderShared.encodeJson(raw), cause)));
|
|
116
|
+
// Responses image items can omit output_format, including when PNG/JPEG was requested.
|
|
117
|
+
const mime = item.output_format === undefined
|
|
118
|
+
? (detectMediaType(data) ?? "application/octet-stream")
|
|
119
|
+
: `image/${item.output_format}`;
|
|
120
|
+
return {
|
|
121
|
+
type: "content",
|
|
122
|
+
value: [{ type: "file", uri: `data:${mime};base64,${item.result}`, mime }],
|
|
123
|
+
};
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
const onEvent = Effect.fnUntraced(function* (state, input) {
|
|
128
|
+
const event = OpenResponses.normalize(state, input);
|
|
129
|
+
if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
|
|
130
|
+
return yield* ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
|
|
131
|
+
const result = yield* OpenResponses.step(state, event);
|
|
132
|
+
if (event.type !== "response.output_item.done" || event.item?.type !== "message")
|
|
133
|
+
return result;
|
|
134
|
+
const message = yield* Schema.decodeUnknownEffect(MessageAnnotations)(event.item).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned invalid message annotations", ProviderShared.encodeJson(event), cause)));
|
|
135
|
+
const annotations = message.content.flatMap((part) => part.annotations ?? []);
|
|
136
|
+
if (annotations.length === 0)
|
|
137
|
+
return result;
|
|
138
|
+
return [
|
|
139
|
+
result[0],
|
|
140
|
+
result[1].map((item) => item.type === "text-end"
|
|
141
|
+
? StreamEvent.textEnd({
|
|
142
|
+
...item,
|
|
143
|
+
providerMetadata: {
|
|
144
|
+
...item.providerMetadata,
|
|
145
|
+
[state.providerMetadataKey]: { ...item.providerMetadata?.[state.providerMetadataKey], annotations },
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
: item),
|
|
149
|
+
];
|
|
150
|
+
});
|
|
151
|
+
const step = Effect.fnUntraced(function* (state, input) {
|
|
152
|
+
const completedItems = new Set(state.completedItems);
|
|
153
|
+
const event = OpenResponses.normalize(state, input);
|
|
154
|
+
if (event.type === "response.output_item.done" && event.item && completedItems.has(event.item.id))
|
|
155
|
+
return [state, []];
|
|
156
|
+
const events = [];
|
|
157
|
+
let current = state;
|
|
158
|
+
// Muse Image delivers its image and optional summary only in response.completed.
|
|
159
|
+
// Recover terminal-only items in order, without duplicating Spark's streamed items.
|
|
160
|
+
if (event.type === "response.completed") {
|
|
161
|
+
for (const [index, item] of (event.response?.output ?? []).entries()) {
|
|
162
|
+
const done = OpenResponses.normalize(current, { type: "response.output_item.done", item, output_index: index });
|
|
163
|
+
// Spark changes reasoning IDs in the terminal snapshot; output indices still identify the streamed items.
|
|
164
|
+
if (!done.item || completedItems.has(done.item.id) || completedItems.has(state.outputItems[index] ?? ""))
|
|
165
|
+
continue;
|
|
166
|
+
const result = yield* onEvent(current, done);
|
|
167
|
+
current = result[0];
|
|
168
|
+
events.push(...result[1]);
|
|
169
|
+
completedItems.add(done.item.id);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const result = yield* onEvent(current, event);
|
|
173
|
+
if (event.type === "response.output_item.done" && event.item)
|
|
174
|
+
completedItems.add(event.item.id);
|
|
175
|
+
return [{ ...result[0], completedItems }, [...events, ...result[1]]];
|
|
176
|
+
});
|
|
177
|
+
export const protocol = Protocol.make({
|
|
178
|
+
id: ADAPTER,
|
|
179
|
+
body: { schema: OpenResponses.OpenResponsesBody, from: fromRequest },
|
|
180
|
+
stream: {
|
|
181
|
+
event: OpenResponses.protocol.stream.event,
|
|
182
|
+
initial: (request) => ({ ...OpenResponses.initial(request, adapter), completedItems: new Set() }),
|
|
183
|
+
step,
|
|
184
|
+
terminal: OpenResponses.terminal,
|
|
185
|
+
},
|
|
186
|
+
supportsEffortUpdates: OpenResponses.protocol.supportsEffortUpdates,
|
|
187
|
+
});
|
|
188
|
+
export const httpTransport = OpenResponses.httpTransport;
|
|
189
|
+
export * as MetaResponses from "./meta-responses.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { type OpenString } from "../schema/index.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.minimax.io/v1";
|
|
6
|
+
export declare const PATH = "/image_generation";
|
|
7
|
+
/** Provider-native options. Common `aspect` and `resolution` lower to `aspect_ratio` or `width` and `height`. */
|
|
8
|
+
export type MiniMaxImageOptions = {
|
|
9
|
+
/** Defaults to `base64`, which returns the bytes inline; `url` links expire after 24 hours. */
|
|
10
|
+
readonly responseFormat?: OpenString<"url" | "base64">;
|
|
11
|
+
readonly seed?: number;
|
|
12
|
+
readonly promptOptimizer?: boolean;
|
|
13
|
+
/** Native preset; it replaces `aspect` and `resolution`. */
|
|
14
|
+
readonly aspect_ratio?: string;
|
|
15
|
+
/** Native size, 512 to 2048 in steps of 8 (`image-01` only); it replaces `aspect` and `resolution`. */
|
|
16
|
+
readonly width?: number;
|
|
17
|
+
readonly height?: number;
|
|
18
|
+
} & Record<string, unknown>;
|
|
19
|
+
export type Request = ImageRequest<ImageModel<MiniMaxImageOptions>>;
|
|
20
|
+
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
21
|
+
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<MiniMaxImageOptions>;
|
|
22
|
+
export declare const MiniMaxImages: {
|
|
23
|
+
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
24
|
+
readonly model: typeof model;
|
|
25
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
+
import { Media } from "../media.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { MediaRoute } from "../route/media.js";
|
|
6
|
+
import { AIError, QuotaExceededError, mergeJsonRecords } from "../schema/index.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
9
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
10
|
+
const route = MediaProtocol.identity({ id: "minimax-images", name: "MiniMax Images", provider: "minimax" });
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.minimax.io/v1";
|
|
12
|
+
export const PATH = "/image_generation";
|
|
13
|
+
const OUTPUT_RETENTION = Duration.hours(24);
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 2. Response schema
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
const MiniMaxImageResponse = Schema.Struct({
|
|
18
|
+
id: optionalNull(Schema.String),
|
|
19
|
+
data: optionalNull(Schema.Struct({
|
|
20
|
+
image_urls: optionalNull(Schema.Array(Schema.String)),
|
|
21
|
+
image_base64: optionalNull(Schema.Array(Schema.String)),
|
|
22
|
+
})),
|
|
23
|
+
metadata: optionalNull(Schema.Struct({
|
|
24
|
+
success_count: optionalNull(Schema.Union([Schema.Number, Schema.String])),
|
|
25
|
+
failed_count: optionalNull(Schema.Union([Schema.Number, Schema.String])),
|
|
26
|
+
})),
|
|
27
|
+
base_resp: optionalNull(Schema.Struct({
|
|
28
|
+
status_code: Schema.Number,
|
|
29
|
+
status_msg: optionalNull(Schema.String),
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
32
|
+
const FAILURE = {
|
|
33
|
+
1002: "RateLimit",
|
|
34
|
+
1004: "Authentication",
|
|
35
|
+
2013: "InvalidRequest",
|
|
36
|
+
2049: "Authentication",
|
|
37
|
+
};
|
|
38
|
+
const INSUFFICIENT_BALANCE = 1008;
|
|
39
|
+
const CONTENT_POLICY = 1026;
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// 5. Request body construction
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/** MiniMax's `aspect_ratio` presets and the sizes it renders them at. */
|
|
44
|
+
const PRESETS = {
|
|
45
|
+
"1:1": { width: 1024, height: 1024 },
|
|
46
|
+
"16:9": { width: 1280, height: 720 },
|
|
47
|
+
"4:3": { width: 1152, height: 864 },
|
|
48
|
+
"3:2": { width: 1248, height: 832 },
|
|
49
|
+
"2:3": { width: 832, height: 1248 },
|
|
50
|
+
"3:4": { width: 864, height: 1152 },
|
|
51
|
+
"9:16": { width: 720, height: 1280 },
|
|
52
|
+
"21:9": { width: 1344, height: 576 },
|
|
53
|
+
};
|
|
54
|
+
const LIMITS = { multiple: 8, minEdge: 512, maxEdge: 2048 };
|
|
55
|
+
const nativeOptions = (options = {}) => {
|
|
56
|
+
const { responseFormat, promptOptimizer, ...native } = options;
|
|
57
|
+
return { response_format: responseFormat ?? "base64", prompt_optimizer: promptOptimizer, ...native };
|
|
58
|
+
};
|
|
59
|
+
/** `image-01-live` rejects `21:9`. */
|
|
60
|
+
const presets = (model) => model === "image-01" ? PRESETS : Object.fromEntries(Object.entries(PRESETS).filter(([key]) => key !== "21:9"));
|
|
61
|
+
/** Presets render at about 1K, so they serve a preset aspect with no resolution or `1K`. */
|
|
62
|
+
const preset = (request) => {
|
|
63
|
+
const aspect = request.aspect ?? "1:1";
|
|
64
|
+
if (!Object.hasOwn(presets(request.model.id), aspect))
|
|
65
|
+
return undefined;
|
|
66
|
+
if (request.resolution !== undefined && ImageSizing.tier(request.resolution) !== 1)
|
|
67
|
+
return undefined;
|
|
68
|
+
return aspect;
|
|
69
|
+
};
|
|
70
|
+
/** Only `image-01` takes free `width` and `height`; other models render the presets alone. */
|
|
71
|
+
const sizing = (request) => {
|
|
72
|
+
if (!ImageSizing.isRequested(request))
|
|
73
|
+
return Effect.succeed({});
|
|
74
|
+
const aspect = preset(request);
|
|
75
|
+
if (aspect !== undefined)
|
|
76
|
+
return Effect.succeed({ aspect_ratio: aspect });
|
|
77
|
+
if (request.model.id === "image-01")
|
|
78
|
+
return ImageSizing.exact(route, request, LIMITS);
|
|
79
|
+
const available = presets(request.model.id);
|
|
80
|
+
const closest = ImageSizing.nearest(request, Object.values(available));
|
|
81
|
+
const name = Object.keys(available).find((key) => available[key] === closest);
|
|
82
|
+
return Effect.fail(route.unsupported(request.resolution === undefined ? "media.aspect" : "media.resolution", `${request.model.id} can't render ${[request.aspect, request.resolution].filter((value) => value !== undefined).join(" at ")}; the closest size it takes is ${closest.width}x${closest.height} (${name}). Change aspect or resolution, or set aspect_ratio in providerOptions`));
|
|
83
|
+
};
|
|
84
|
+
const isNativeSize = (options) => options?.aspect_ratio !== undefined || options?.width !== undefined || options?.height !== undefined;
|
|
85
|
+
// The API only takes a `character` (portrait) subject, one per request.
|
|
86
|
+
const subject = (asset) => ProviderShared.mediaReference(asset, undefined, `${route.name} input`).pipe(Effect.map((item) => ({ type: "character", image_file: item.value })));
|
|
87
|
+
const fromRequest = Effect.fn("MiniMaxImages.fromRequest")(function* (request) {
|
|
88
|
+
if ((request.images?.length ?? 0) > 1)
|
|
89
|
+
return yield* route.unsupported("media.images", `${route.name} takes one subject reference image`);
|
|
90
|
+
if (isNativeSize(request.providerOptions) && ImageSizing.isRequested(request))
|
|
91
|
+
return yield* ProviderShared.invalidRequest("MiniMax providerOptions aspect_ratio, width and height replace aspect and resolution; set one or the other");
|
|
92
|
+
const references = yield* Effect.forEach(request.images ?? [], subject);
|
|
93
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
94
|
+
model: request.model.id,
|
|
95
|
+
prompt: request.prompt,
|
|
96
|
+
subject_reference: references.length === 0 ? undefined : references,
|
|
97
|
+
n: request.n,
|
|
98
|
+
...(yield* sizing(request)),
|
|
99
|
+
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
100
|
+
});
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// 6. Response decoding
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
const decodeDocument = route.decodeJson(MiniMaxImageResponse);
|
|
105
|
+
const decodeResponse = Effect.fn("MiniMaxImages.decodeResponse")(function* (response) {
|
|
106
|
+
const output = yield* decodeDocument(response);
|
|
107
|
+
const decoded = output.value;
|
|
108
|
+
// MiniMax answers errors with HTTP 200 and a non-zero `base_resp.status_code`.
|
|
109
|
+
const status = decoded.base_resp;
|
|
110
|
+
if (status && status.status_code !== 0) {
|
|
111
|
+
const message = `${route.name} failed (${status.status_code}): ${status.status_msg ?? "unknown error"}`;
|
|
112
|
+
if (status.status_code === CONTENT_POLICY)
|
|
113
|
+
return yield* output.contentPolicy(message);
|
|
114
|
+
if (status.status_code === INSUFFICIENT_BALANCE)
|
|
115
|
+
return yield* new AIError({ reason: new QuotaExceededError({ message, body: output.body, http: output.http }) });
|
|
116
|
+
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, status.status_code));
|
|
117
|
+
}
|
|
118
|
+
const images = [
|
|
119
|
+
...(yield* Effect.forEach(decoded.data?.image_base64 ?? [], (data, index) => MediaInput.decodedAsset(output.invalid, `${route.name} result ${index}`, data, undefined))),
|
|
120
|
+
// MiniMax returns no content type for URLs; the media type resolves when the asset is materialized.
|
|
121
|
+
...(yield* Effect.forEach(decoded.data?.image_urls ?? [], (url) => MediaProtocol.expiringUrl(url, OUTPUT_RETENTION))),
|
|
122
|
+
];
|
|
123
|
+
const failed = Number(decoded.metadata?.failed_count ?? 0);
|
|
124
|
+
if (images.length === 0 && failed > 0)
|
|
125
|
+
return yield* output.contentPolicy(`${route.name} blocked ${failed} image(s) for content safety`);
|
|
126
|
+
if (images.length === 0)
|
|
127
|
+
return yield* output.invalid(`${route.name} returned no images`);
|
|
128
|
+
return new ImageResponse({
|
|
129
|
+
images,
|
|
130
|
+
providerMetadata: {
|
|
131
|
+
minimax: {
|
|
132
|
+
id: decoded.id ?? undefined,
|
|
133
|
+
successCount: decoded.metadata?.success_count ?? undefined,
|
|
134
|
+
failedCount: decoded.metadata?.failed_count ?? undefined,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// 7. Protocol and route
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
143
|
+
body: { from: fromRequest },
|
|
144
|
+
response: { decode: decodeResponse },
|
|
145
|
+
});
|
|
146
|
+
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
147
|
+
export const MiniMaxImages = {
|
|
148
|
+
protocol,
|
|
149
|
+
model,
|
|
150
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { type OpenString } from "../schema/index.js";
|
|
5
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
|
+
/** The API host without a version: H3 is served under `/v2` and Hailuo under `/v1`. */
|
|
7
|
+
export declare const DEFAULT_BASE_URL = "https://api.minimax.io";
|
|
8
|
+
export declare const PATH = "/v2/video_generation";
|
|
9
|
+
export declare const STATUS_PATH = "/v2/query/video_generation";
|
|
10
|
+
export declare const HAILUO_PATH = "/v1/video_generation";
|
|
11
|
+
export declare const HAILUO_STATUS_PATH = "/v1/query/video_generation";
|
|
12
|
+
export declare const FILE_PATH = "/v1/files/retrieve";
|
|
13
|
+
/**
|
|
14
|
+
* Provider-native options, merged into the body. Common fields (`start`, `end`, `references`, `duration`, `aspect`,
|
|
15
|
+
* `resolution`, `sound`) live on the request. `extra` and `response_format` are H3 (v2) fields; `prompt_optimizer`
|
|
16
|
+
* and `fast_pretreatment` are Hailuo (v1) fields; both APIs take `callback_url`.
|
|
17
|
+
*/
|
|
18
|
+
export type MiniMaxVideoOptions = {
|
|
19
|
+
readonly extra?: {
|
|
20
|
+
readonly prompt_expansion_mode?: OpenString<"disabled" | "balanced" | "quality">;
|
|
21
|
+
};
|
|
22
|
+
readonly response_format?: OpenString<"task" | "flat">;
|
|
23
|
+
readonly prompt_optimizer?: boolean;
|
|
24
|
+
readonly fast_pretreatment?: boolean;
|
|
25
|
+
readonly callback_url?: string;
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
export type Request = VideoRequest<VideoModel<MiniMaxVideoOptions>>;
|
|
28
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
29
|
+
export declare const Token: Schema.String;
|
|
30
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
31
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
32
|
+
export declare const hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
33
|
+
/** H3 and later models on the v2 API. */
|
|
34
|
+
export declare const h3Model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
|
|
35
|
+
/** Hailuo and the `*-01` models on the v1 API. */
|
|
36
|
+
export declare const hailuoModel: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
|
|
37
|
+
/** Picks the API by model family: Hailuo and `*-01` models use v1, everything else v2. */
|
|
38
|
+
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
|
|
39
|
+
export declare const MiniMaxVideo: {
|
|
40
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
41
|
+
readonly hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
42
|
+
readonly model: typeof model;
|
|
43
|
+
readonly h3Model: typeof h3Model;
|
|
44
|
+
readonly hailuoModel: typeof hailuoModel;
|
|
45
|
+
};
|