@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,296 @@
|
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import { Media } from "../media.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { AIError, QuotaExceededError, mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { VideoModel, VideoResponse, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
// MiniMax runs two video APIs with different bodies, statuses and results: H3 on v2 and Hailuo on v1.
|
|
9
|
+
const route = MediaProtocol.identity({ id: "minimax-video", name: "MiniMax Video", provider: "minimax" });
|
|
10
|
+
const hailuoRoute = MediaProtocol.identity({
|
|
11
|
+
id: "minimax-hailuo-video",
|
|
12
|
+
name: "MiniMax Hailuo Video",
|
|
13
|
+
provider: "minimax",
|
|
14
|
+
});
|
|
15
|
+
/** The API host without a version: H3 is served under `/v2` and Hailuo under `/v1`. */
|
|
16
|
+
export const DEFAULT_BASE_URL = "https://api.minimax.io";
|
|
17
|
+
export const PATH = "/v2/video_generation";
|
|
18
|
+
export const STATUS_PATH = "/v2/query/video_generation";
|
|
19
|
+
export const HAILUO_PATH = "/v1/video_generation";
|
|
20
|
+
export const HAILUO_STATUS_PATH = "/v1/query/video_generation";
|
|
21
|
+
export const FILE_PATH = "/v1/files/retrieve";
|
|
22
|
+
const DOWNLOAD_RETENTION = Duration.hours(1);
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// 2. Token and response schemas
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
27
|
+
export const Token = Schema.String;
|
|
28
|
+
const BaseResp = optionalNull(Schema.Struct({
|
|
29
|
+
status_code: Schema.Number,
|
|
30
|
+
status_msg: optionalNull(Schema.String),
|
|
31
|
+
}));
|
|
32
|
+
const StartResponse = Schema.Struct({ task_id: Schema.String });
|
|
33
|
+
const Task = Schema.Struct({
|
|
34
|
+
id: optionalNull(Schema.String),
|
|
35
|
+
model: optionalNull(Schema.String),
|
|
36
|
+
status: optionalNull(Schema.String),
|
|
37
|
+
error: optionalNull(Schema.Struct({
|
|
38
|
+
code: optionalNull(Schema.Union([Schema.String, Schema.Number])),
|
|
39
|
+
message: optionalNull(Schema.String),
|
|
40
|
+
})),
|
|
41
|
+
content: optionalNull(Schema.Struct({ url: optionalNull(Schema.String) })),
|
|
42
|
+
resolution: optionalNull(Schema.String),
|
|
43
|
+
duration: optionalNull(Schema.Number),
|
|
44
|
+
ratio: optionalNull(Schema.String),
|
|
45
|
+
usage: optionalNull(Schema.Record(Schema.String, Schema.Unknown)),
|
|
46
|
+
});
|
|
47
|
+
// `response_format: "flat"` moves the task fields from `task` to the top level.
|
|
48
|
+
const TaskResponse = Schema.Struct({ ...Task.fields, task: optionalNull(Task) });
|
|
49
|
+
const HailuoStartResponse = Schema.Struct({ task_id: optionalNull(Schema.String), base_resp: BaseResp });
|
|
50
|
+
const HailuoTask = Schema.Struct({
|
|
51
|
+
status: optionalNull(Schema.String),
|
|
52
|
+
file_id: optionalNull(Schema.String),
|
|
53
|
+
video_width: optionalNull(Schema.Number),
|
|
54
|
+
video_height: optionalNull(Schema.Number),
|
|
55
|
+
base_resp: BaseResp,
|
|
56
|
+
});
|
|
57
|
+
const HailuoFile = Schema.Struct({
|
|
58
|
+
file: optionalNull(Schema.Struct({
|
|
59
|
+
download_url: optionalNull(Schema.String),
|
|
60
|
+
})),
|
|
61
|
+
base_resp: BaseResp,
|
|
62
|
+
});
|
|
63
|
+
const STATUS = {
|
|
64
|
+
queued: "running",
|
|
65
|
+
running: "running",
|
|
66
|
+
succeeded: "completed",
|
|
67
|
+
failed: "failed",
|
|
68
|
+
cancelled: "cancelled",
|
|
69
|
+
};
|
|
70
|
+
const HAILUO_STATUS = {
|
|
71
|
+
Preparing: "running",
|
|
72
|
+
Queueing: "running",
|
|
73
|
+
Processing: "running",
|
|
74
|
+
Success: "completed",
|
|
75
|
+
Fail: "failed",
|
|
76
|
+
};
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// 3. Failures
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Error codes from https://platform.minimax.io/docs/api-reference/errorcode; unknown codes are provider-side.
|
|
81
|
+
const FAILURE = {
|
|
82
|
+
1002: "RateLimit",
|
|
83
|
+
1004: "Authentication",
|
|
84
|
+
1039: "RateLimit",
|
|
85
|
+
2013: "InvalidRequest",
|
|
86
|
+
2049: "Authentication",
|
|
87
|
+
};
|
|
88
|
+
const INSUFFICIENT_BALANCE = 1008;
|
|
89
|
+
// 1026 flags the input and 1027 the generated video.
|
|
90
|
+
const CONTENT_POLICY = new Set(["1026", "1027"]);
|
|
91
|
+
const failed = (output, name, code, detail) => {
|
|
92
|
+
const message = `${name} generation failed${code === undefined ? "" : ` (${code})`}${detail === undefined ? "" : `: ${detail}`}`;
|
|
93
|
+
if (code !== undefined && CONTENT_POLICY.has(String(code)))
|
|
94
|
+
return output.contentPolicy(message);
|
|
95
|
+
if (code !== undefined && Number(code) === INSUFFICIENT_BALANCE)
|
|
96
|
+
return new AIError({ reason: new QuotaExceededError({ message, body: output.body, http: output.http }) });
|
|
97
|
+
return output.ended("failed", message, MediaProtocol.failure(FAILURE, code));
|
|
98
|
+
};
|
|
99
|
+
// v1 answers errors with HTTP 200 and a non-zero `base_resp.status_code`.
|
|
100
|
+
const baseError = (output, base) => base === undefined || base === null || base.status_code === 0
|
|
101
|
+
? undefined
|
|
102
|
+
: failed(output, hailuoRoute.name, base.status_code, base.status_msg ?? undefined);
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// 5. Request body construction
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
/** H3 takes URLs, data URIs and `mm_file://{file_id}` references to MiniMax files. */
|
|
107
|
+
const mediaUrl = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => (reference.type === "ref" ? `mm_file://${reference.value}` : reference.value)));
|
|
108
|
+
const ROLES = { image: "reference_image", video: "reference_video", audio: "reference_audio" };
|
|
109
|
+
const item = (asset, role) => mediaUrl(asset).pipe(Effect.map((url) => {
|
|
110
|
+
const type = asset.kind === "video" ? "video_url" : asset.kind === "audio" ? "audio_url" : "image_url";
|
|
111
|
+
return { type, [type]: { url }, role };
|
|
112
|
+
}));
|
|
113
|
+
const reference = (asset) => item(asset, asset.kind === "video" || asset.kind === "audio" ? ROLES[asset.kind] : ROLES.image);
|
|
114
|
+
/** MiniMax spells resolutions in uppercase (`480P`, `768P`, `2K`). */
|
|
115
|
+
const resolution = (request) => request.resolution?.toUpperCase();
|
|
116
|
+
const fromRequest = Effect.fn("MiniMaxVideo.fromRequest")(function* (request) {
|
|
117
|
+
// H3 always generates a soundtrack and has no field for `sound`, so it isn't sent.
|
|
118
|
+
const content = [
|
|
119
|
+
{ type: "text", text: request.prompt },
|
|
120
|
+
...(request.start === undefined ? [] : [yield* item(request.start, "first_frame")]),
|
|
121
|
+
...(request.end === undefined ? [] : [yield* item(request.end, "last_frame")]),
|
|
122
|
+
...(yield* Effect.forEach(request.references ?? [], reference)),
|
|
123
|
+
];
|
|
124
|
+
// H3 rejects a t2va (text-only) request without a concrete `ratio`, so `auto` and unset default to `16:9`.
|
|
125
|
+
const ratio = content.length === 1 && (request.aspect === undefined || request.aspect === "auto")
|
|
126
|
+
? "16:9"
|
|
127
|
+
: request.aspect === "auto"
|
|
128
|
+
? "adaptive"
|
|
129
|
+
: request.aspect;
|
|
130
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
131
|
+
model: request.model.id,
|
|
132
|
+
content,
|
|
133
|
+
resolution: resolution(request),
|
|
134
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
135
|
+
ratio,
|
|
136
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
137
|
+
});
|
|
138
|
+
/** v1 documents URLs and data URLs only, so MiniMax file references aren't sent. */
|
|
139
|
+
const hailuoUrl = (asset) => ProviderShared.mediaReference(asset, undefined, hailuoRoute.name).pipe(Effect.map((reference) => reference.value));
|
|
140
|
+
const hailuoFromRequest = Effect.fn("MiniMaxHailuoVideo.fromRequest")(function* (request) {
|
|
141
|
+
const references = request.references ?? [];
|
|
142
|
+
if (references.some((asset) => asset.kind === "video" || asset.kind === "audio"))
|
|
143
|
+
return yield* hailuoRoute.unsupported("video.references", `${hailuoRoute.name} takes only image (subject) references`);
|
|
144
|
+
// Hailuo output is always silent and its shape follows the model or the first frame, with no field for either.
|
|
145
|
+
// `sound` has nothing to send, so it isn't; an aspect ratio would change the shape the caller asked for.
|
|
146
|
+
if (request.aspect !== undefined && request.aspect !== "auto")
|
|
147
|
+
return yield* hailuoRoute.unsupported("video.aspect", `${hailuoRoute.name} has no aspect ratio input`);
|
|
148
|
+
const subjects = yield* Effect.forEach(references, (asset) => hailuoUrl(asset).pipe(Effect.map((url) => ({ type: "character", image: [url] }))));
|
|
149
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
150
|
+
model: request.model.id,
|
|
151
|
+
prompt: request.prompt,
|
|
152
|
+
first_frame_image: request.start === undefined ? undefined : yield* hailuoUrl(request.start),
|
|
153
|
+
last_frame_image: request.end === undefined ? undefined : yield* hailuoUrl(request.end),
|
|
154
|
+
subject_reference: subjects.length === 0 ? undefined : subjects,
|
|
155
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
156
|
+
resolution: resolution(request),
|
|
157
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
158
|
+
});
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// 6. Response decoding
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
163
|
+
token: value.task_id,
|
|
164
|
+
snapshot: { id: value.task_id, status: "running" },
|
|
165
|
+
}));
|
|
166
|
+
const decodeTask = route.decodeJson(TaskResponse);
|
|
167
|
+
const decodeStatus = Effect.fn("MiniMaxVideo.decodeStatus")(function* (response, context) {
|
|
168
|
+
const output = yield* decodeTask(response);
|
|
169
|
+
const task = output.value.task ?? output.value;
|
|
170
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, task.status ?? "") };
|
|
171
|
+
});
|
|
172
|
+
const decodeResult = Effect.fn("MiniMaxVideo.decodeResult")(function* (response, context) {
|
|
173
|
+
const output = yield* decodeTask(response);
|
|
174
|
+
const task = output.value.task ?? output.value;
|
|
175
|
+
const status = MediaProtocol.state(STATUS, task.status ?? "");
|
|
176
|
+
if (status === "running")
|
|
177
|
+
return yield* output.pending(context.token);
|
|
178
|
+
if (status === "failed")
|
|
179
|
+
return yield* failed(output, route.name, task.error?.code ?? undefined, task.error?.message ?? undefined);
|
|
180
|
+
if (status !== "completed")
|
|
181
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
|
|
182
|
+
const url = task.content?.url ?? undefined;
|
|
183
|
+
if (url === undefined)
|
|
184
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
185
|
+
const duration = task.duration ?? undefined;
|
|
186
|
+
const total = task.usage?.total_seconds;
|
|
187
|
+
return new VideoResponse({
|
|
188
|
+
// The URL is time-limited without a documented window; reading the result again returns a fresh one.
|
|
189
|
+
videos: [
|
|
190
|
+
Media.url(url, {
|
|
191
|
+
mediaType: "video/mp4",
|
|
192
|
+
info: duration === undefined ? undefined : { durationSeconds: duration },
|
|
193
|
+
}),
|
|
194
|
+
],
|
|
195
|
+
usage: typeof total === "number" ? { type: "seconds", seconds: total } : undefined,
|
|
196
|
+
providerMetadata: {
|
|
197
|
+
minimax: {
|
|
198
|
+
taskId: context.token,
|
|
199
|
+
model: task.model ?? undefined,
|
|
200
|
+
resolution: task.resolution ?? undefined,
|
|
201
|
+
ratio: task.ratio ?? undefined,
|
|
202
|
+
usage: task.usage ?? undefined,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
const decodeHailuoStart = Effect.fn("MiniMaxHailuoVideo.decodeStart")(function* (response) {
|
|
208
|
+
const output = yield* hailuoRoute.decodeJson(HailuoStartResponse)(response);
|
|
209
|
+
const error = baseError(output, output.value.base_resp);
|
|
210
|
+
if (error)
|
|
211
|
+
return yield* error;
|
|
212
|
+
const taskID = output.value.task_id ?? "";
|
|
213
|
+
if (taskID === "")
|
|
214
|
+
return yield* output.invalid(`${hailuoRoute.name} returned no task_id`);
|
|
215
|
+
return { token: taskID, snapshot: { id: taskID, status: "running" } };
|
|
216
|
+
});
|
|
217
|
+
const decodeHailuoTask = hailuoRoute.decodeJson(HailuoTask);
|
|
218
|
+
const decodeHailuoStatus = Effect.fn("MiniMaxHailuoVideo.decodeStatus")(function* (response, context) {
|
|
219
|
+
const output = yield* decodeHailuoTask(response);
|
|
220
|
+
const status = MediaProtocol.status(HAILUO_STATUS, output.value.status ?? "");
|
|
221
|
+
// A failed task also carries its reason in `base_resp`; any other non-zero code is a failed read.
|
|
222
|
+
const error = status.reason === "failed" ? undefined : baseError(output, output.value.base_resp);
|
|
223
|
+
if (error)
|
|
224
|
+
return yield* error;
|
|
225
|
+
return { id: context.token, ...status };
|
|
226
|
+
});
|
|
227
|
+
const decodeHailuoFile = hailuoRoute.decodeJson(HailuoFile);
|
|
228
|
+
const decodeHailuoResult = Effect.fn("MiniMaxHailuoVideo.decodeResult")(function* (response, context) {
|
|
229
|
+
const output = yield* decodeHailuoTask(response);
|
|
230
|
+
const task = output.value;
|
|
231
|
+
const status = MediaProtocol.state(HAILUO_STATUS, task.status ?? "");
|
|
232
|
+
const error = baseError(output, task.base_resp);
|
|
233
|
+
if (status === "failed")
|
|
234
|
+
return yield* error ?? failed(output, hailuoRoute.name, undefined, undefined);
|
|
235
|
+
if (error)
|
|
236
|
+
return yield* error;
|
|
237
|
+
if (status !== "completed")
|
|
238
|
+
return yield* output.pending(context.token);
|
|
239
|
+
const fileID = task.file_id ?? "";
|
|
240
|
+
if (fileID === "")
|
|
241
|
+
return yield* output.invalid(`${hailuoRoute.name} completed without a file_id`);
|
|
242
|
+
// The task names a file; its download URL takes a second lookup and is valid for one hour.
|
|
243
|
+
const file = yield* decodeHailuoFile(yield* context.get(`${FILE_PATH}?file_id=${encodeURIComponent(fileID)}`));
|
|
244
|
+
const fileError = baseError(file, file.value.base_resp);
|
|
245
|
+
if (fileError)
|
|
246
|
+
return yield* fileError;
|
|
247
|
+
const url = file.value.file?.download_url ?? undefined;
|
|
248
|
+
if (url === undefined)
|
|
249
|
+
return yield* file.invalid(`${hailuoRoute.name} returned no download_url for ${fileID}`);
|
|
250
|
+
const width = task.video_width ?? undefined;
|
|
251
|
+
const height = task.video_height ?? undefined;
|
|
252
|
+
return new VideoResponse({
|
|
253
|
+
videos: [
|
|
254
|
+
yield* MediaProtocol.expiringUrl(url, DOWNLOAD_RETENTION, {
|
|
255
|
+
mediaType: "video/mp4",
|
|
256
|
+
info: width === undefined && height === undefined ? undefined : { width, height },
|
|
257
|
+
}),
|
|
258
|
+
],
|
|
259
|
+
providerMetadata: {
|
|
260
|
+
minimax: { taskId: context.token, fileId: fileID },
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
// 7. Protocol and route
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
export const protocol = MediaProtocol.queued(route, {
|
|
268
|
+
token: Token,
|
|
269
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
270
|
+
status: { path: (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`, decode: decodeStatus },
|
|
271
|
+
result: { path: (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`, decode: decodeResult },
|
|
272
|
+
// Cancels a queued task; MiniMax rejects it once the task is running.
|
|
273
|
+
cancel: { method: "DELETE", path: (token) => `${PATH}/${encodeURIComponent(token)}` },
|
|
274
|
+
});
|
|
275
|
+
const hailuoStatusPath = (token) => `${HAILUO_STATUS_PATH}?task_id=${encodeURIComponent(token)}`;
|
|
276
|
+
export const hailuoProtocol = MediaProtocol.queued(hailuoRoute, {
|
|
277
|
+
token: Token,
|
|
278
|
+
start: { body: { from: hailuoFromRequest }, decode: decodeHailuoStart },
|
|
279
|
+
status: { path: hailuoStatusPath, decode: decodeHailuoStatus },
|
|
280
|
+
result: { path: hailuoStatusPath, decode: decodeHailuoResult },
|
|
281
|
+
});
|
|
282
|
+
/** H3 and later models on the v2 API. */
|
|
283
|
+
export const h3Model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
284
|
+
/** Hailuo and the `*-01` models on the v1 API. */
|
|
285
|
+
export const hailuoModel = (input) => VideoModel.fromRoute({ protocol: hailuoProtocol, baseURL: DEFAULT_BASE_URL, path: HAILUO_PATH }, input);
|
|
286
|
+
// v1 is MiniMax's legacy API with a fixed model list; every newer model ships on v2.
|
|
287
|
+
const isHailuo = (modelID) => /^(minimax-hailuo-|[tis]2v-01|video-01)/i.test(modelID);
|
|
288
|
+
/** Picks the API by model family: Hailuo and `*-01` models use v1, everything else v2. */
|
|
289
|
+
export const model = (input) => (isHailuo(input.id) ? hailuoModel(input) : h3Model(input));
|
|
290
|
+
export const MiniMaxVideo = {
|
|
291
|
+
protocol,
|
|
292
|
+
hailuoProtocol,
|
|
293
|
+
model,
|
|
294
|
+
h3Model,
|
|
295
|
+
hailuoModel,
|
|
296
|
+
};
|