@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,41 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
import { Json } from "./json.js";
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
const decodeJson = Schema.decodeUnknownOption(Json);
|
|
5
|
+
/** Error codes a provider error body carries, in their original case. The first is its primary code (`AIError.code`). */
|
|
6
|
+
export function providerCodes(value) {
|
|
7
|
+
const decoded = typeof value === "string" ? Option.getOrUndefined(decodeJson(value)) : value;
|
|
8
|
+
if (!isRecord(decoded))
|
|
9
|
+
return [];
|
|
10
|
+
const error = isRecord(decoded.error) ? decoded.error : undefined;
|
|
11
|
+
const inner = error && isRecord(error.innererror) ? error.innererror : undefined;
|
|
12
|
+
const metadata = error && isRecord(error.metadata) ? error.metadata : undefined;
|
|
13
|
+
const response = isRecord(decoded.response) ? decoded.response : undefined;
|
|
14
|
+
const responseError = response && isRecord(response.error) ? response.error : undefined;
|
|
15
|
+
const exception = isRecord(decoded.exception) ? decoded.exception : undefined;
|
|
16
|
+
return [
|
|
17
|
+
decoded.code,
|
|
18
|
+
...awsErrorType(decoded.__type),
|
|
19
|
+
...awsErrorType(decoded.code),
|
|
20
|
+
decoded.error_type,
|
|
21
|
+
error?.code,
|
|
22
|
+
error?.type,
|
|
23
|
+
error?.status,
|
|
24
|
+
error?.error_type,
|
|
25
|
+
// Google `google.rpc.ErrorInfo` details carry the specific reason.
|
|
26
|
+
...(Array.isArray(error?.details)
|
|
27
|
+
? error.details.map((detail) => (isRecord(detail) ? detail.reason : undefined))
|
|
28
|
+
: []),
|
|
29
|
+
inner?.code,
|
|
30
|
+
metadata?.error_type,
|
|
31
|
+
responseError?.code,
|
|
32
|
+
response?.error_type,
|
|
33
|
+
exception?.type,
|
|
34
|
+
].filter((value) => typeof value === "string");
|
|
35
|
+
}
|
|
36
|
+
// AWS restJson1 reports the modeled error in `X-Amzn-Errortype`, `__type` or `code`, possibly
|
|
37
|
+
// namespaced (`ns#Name`) or suffixed (`Name:uri`). Keep the shape name only.
|
|
38
|
+
// https://smithy.io/2.0/aws/protocols/aws-restjson1-protocol.html#operation-error-serialization
|
|
39
|
+
export function awsErrorType(value) {
|
|
40
|
+
return typeof value === "string" ? [value.replace(/:.*/s, "").replace(/^[^#]*#/, "")] : [];
|
|
41
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Media } from "../media.js";
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
/**
|
|
5
|
+
* Replace lone UTF-16 surrogates in every string, key and nested value. Unchanged
|
|
6
|
+
* subtrees are returned by reference so requests with large histories are not copied.
|
|
7
|
+
*/
|
|
8
|
+
export const sanitizeSurrogates = (value) => {
|
|
9
|
+
if (typeof value === "string")
|
|
10
|
+
return (value.isWellFormed() ? value : value.toWellFormed());
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
const items = value.map(sanitizeSurrogates);
|
|
13
|
+
return (Object.getPrototypeOf(value) === Array.prototype && items.every((item, index) => item === value[index])
|
|
14
|
+
? value
|
|
15
|
+
: items);
|
|
16
|
+
}
|
|
17
|
+
// Media assets carry binary or base64 payloads and a lazy byte cache; flattening them into a record would drop both.
|
|
18
|
+
if (value instanceof Uint8Array || value instanceof Error || value instanceof Media.Asset)
|
|
19
|
+
return value;
|
|
20
|
+
if (!isRecord(value))
|
|
21
|
+
return value;
|
|
22
|
+
const entries = Object.entries(value);
|
|
23
|
+
const sanitized = entries.map(([key, entry]) => [sanitizeSurrogates(key), sanitizeSurrogates(entry)]);
|
|
24
|
+
// Changed nodes and other objects (such as Date) are copied into plain records as before. Unchanged plain
|
|
25
|
+
// records and Schema class instances are kept: a copy would hold the same fields, and Schema constructors
|
|
26
|
+
// decode such a copy back into an equal instance.
|
|
27
|
+
if (sanitized.every(([key, entry], index) => key === entries[index][0] && entry === entries[index][1]) &&
|
|
28
|
+
(Object.getPrototypeOf(value) === Object.prototype || Schema.isSchema(value.constructor)))
|
|
29
|
+
return value;
|
|
30
|
+
return Object.fromEntries(sanitized);
|
|
31
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { MediaRoute } from "./route/media.js";
|
|
3
|
+
import { AIError } from "./schema/index.js";
|
|
4
|
+
import type { VideoJob, VideoModel, VideoRequest, VideoResponse, VideoStatus } from "./video.js";
|
|
5
|
+
export interface Interface {
|
|
6
|
+
readonly start: (request: VideoRequest) => Effect.Effect<VideoJob, AIError>;
|
|
7
|
+
readonly status: (model: VideoModel, id: string) => Effect.Effect<VideoStatus, AIError>;
|
|
8
|
+
readonly result: (model: VideoModel, id: string) => Effect.Effect<VideoResponse, AIError>;
|
|
9
|
+
readonly cancel: (model: VideoModel, id: string) => Effect.Effect<void, AIError>;
|
|
10
|
+
}
|
|
11
|
+
export declare const make: (execute: MediaRoute.Execute) => Interface;
|
|
12
|
+
export * as VideoClient from "./video-client.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { AIError, UnsupportedOperationError } from "./schema/index.js";
|
|
3
|
+
// A video route whose token isn't a string is a programmer defect, not a provider error.
|
|
4
|
+
const decodeID = (token) => Schema.decodeUnknownEffect(Schema.String)(token).pipe(Effect.orDie);
|
|
5
|
+
export const make = (execute) => {
|
|
6
|
+
const attach = (model, id) => model.route.attach(model, id, execute);
|
|
7
|
+
return {
|
|
8
|
+
start: (request) => request.model.route.start(request, execute).pipe(
|
|
9
|
+
// The token, not the snapshot id, is what `status` and `result` decode; `VideoModel.fromRoute` makes it a string.
|
|
10
|
+
Effect.flatMap((generation) => decodeID(generation.token)), Effect.map((id) => ({ id }))),
|
|
11
|
+
status: (model, id) => attach(model, id).pipe(Effect.flatMap((route) => route.status), Effect.map((snapshot) => ({ status: snapshot.status, reason: snapshot.reason, progress: snapshot.progress }))),
|
|
12
|
+
result: (model, id) => attach(model, id).pipe(Effect.flatMap((route) => route.result)),
|
|
13
|
+
cancel: (model, id) => attach(model, id).pipe(Effect.flatMap((route) => route.cancel ??
|
|
14
|
+
Effect.fail(new AIError({
|
|
15
|
+
reason: new UnsupportedOperationError({
|
|
16
|
+
operation: "video.cancel",
|
|
17
|
+
provider: model.provider,
|
|
18
|
+
route: model.route.id,
|
|
19
|
+
message: `${model.provider}/${model.route.id} has no way to cancel a video generation`,
|
|
20
|
+
}),
|
|
21
|
+
})))),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export * as VideoClient from "./video-client.js";
|
package/dist/video.d.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import type { Reason, Status } from "./generation.js";
|
|
3
|
+
import { Media } from "./media.js";
|
|
4
|
+
import { MediaModel } from "./media-model.js";
|
|
5
|
+
import { MediaRoute } from "./route/media.js";
|
|
6
|
+
import { AIError, type OpenString, type BaseRequest } from "./schema/index.js";
|
|
7
|
+
import { AI } from "./ai.js";
|
|
8
|
+
export type VideoOptions = MediaModel.Options;
|
|
9
|
+
/** Video generation is always a queued job: submit, then read its status and result by the provider's job ID. */
|
|
10
|
+
export type VideoRoute = MediaRoute.QueuedRoute<VideoRequest, VideoResponse>;
|
|
11
|
+
export declare class VideoModel<Options extends VideoOptions = VideoOptions> extends MediaModel<VideoRoute, Options> {
|
|
12
|
+
protected readonly _VideoModel: void;
|
|
13
|
+
/** A video route's token is the provider's job ID, so `VideoJob.id` is exactly what `status` and `result` take. */
|
|
14
|
+
static fromRoute<Options extends VideoOptions>(route: MediaModel.QueuedRouteInput<VideoRequest<VideoModel<Options>>, VideoResponse, string>, input: MediaRoute.ModelInput): VideoModel<Options>;
|
|
15
|
+
}
|
|
16
|
+
export declare const VideoModelSchema: Schema.declare<VideoModel<{
|
|
17
|
+
readonly [x: string]: unknown;
|
|
18
|
+
}>, VideoModel<{
|
|
19
|
+
readonly [x: string]: unknown;
|
|
20
|
+
}>>;
|
|
21
|
+
/** A `width:height` ratio, or `auto` to follow the input image. */
|
|
22
|
+
export type VideoAspectRatio = Media.AspectRatio | "auto";
|
|
23
|
+
export declare const VideoAspectRatio: Schema.Union<readonly [Schema.declare<`${number}:${number}`, `${number}:${number}`>, Schema.Literal<"auto">]>;
|
|
24
|
+
/** Common output resolutions; protocols convert them to their provider's spelling and pass other values through. */
|
|
25
|
+
export type VideoResolution = OpenString<"480p" | "720p" | "1080p" | "4k">;
|
|
26
|
+
/** Output length as an Effect duration string in seconds, such as `"8 seconds"`. */
|
|
27
|
+
export type VideoDuration = `${number} second` | `${number} seconds`;
|
|
28
|
+
export declare const VideoDuration: Schema.declare<VideoDuration, VideoDuration>;
|
|
29
|
+
declare const VideoRequestSchema: Schema.Struct<{
|
|
30
|
+
readonly model: Schema.declare<VideoModel<{
|
|
31
|
+
readonly [x: string]: unknown;
|
|
32
|
+
}>, VideoModel<{
|
|
33
|
+
readonly [x: string]: unknown;
|
|
34
|
+
}>>;
|
|
35
|
+
readonly prompt: Schema.String;
|
|
36
|
+
/** Image the video starts on exactly. */
|
|
37
|
+
readonly start: Schema.optional<Schema.brand<Schema.declare<Media.Asset, Media.Asset>, "Media.ImageAsset">>;
|
|
38
|
+
/** Image the video ends on exactly. */
|
|
39
|
+
readonly end: Schema.optional<Schema.brand<Schema.declare<Media.Asset, Media.Asset>, "Media.ImageAsset">>;
|
|
40
|
+
/** Images, videos or audio that guide the subject or style without pinning a frame. */
|
|
41
|
+
readonly references: Schema.optional<Schema.$Array<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
42
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
43
|
+
readonly type: Schema.Literal<"bytes">;
|
|
44
|
+
readonly data: Schema.Uint8Array;
|
|
45
|
+
readonly mediaType: Schema.String;
|
|
46
|
+
}>, Schema.Struct<{
|
|
47
|
+
readonly type: Schema.Literal<"base64">;
|
|
48
|
+
readonly data: Schema.String;
|
|
49
|
+
readonly mediaType: Schema.String;
|
|
50
|
+
}>, Schema.Struct<{
|
|
51
|
+
readonly type: Schema.Literal<"url">;
|
|
52
|
+
readonly url: Schema.String;
|
|
53
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
54
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
55
|
+
}>, Schema.Struct<{
|
|
56
|
+
readonly type: Schema.Literal<"ref">;
|
|
57
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
58
|
+
readonly id: Schema.String;
|
|
59
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
60
|
+
}>]>;
|
|
61
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
62
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
63
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
64
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
65
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
66
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
67
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
68
|
+
readonly format: Schema.optional<Schema.String>;
|
|
69
|
+
}>>;
|
|
70
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
71
|
+
}>, never, never>>>;
|
|
72
|
+
readonly duration: Schema.optional<Schema.declare<VideoDuration, VideoDuration>>;
|
|
73
|
+
readonly aspect: Schema.optional<Schema.Union<readonly [Schema.declare<`${number}:${number}`, `${number}:${number}`>, Schema.Literal<"auto">]>>;
|
|
74
|
+
readonly resolution: Schema.optional<Schema.String>;
|
|
75
|
+
/** Whether the video has a generated soundtrack; unset leaves the model's default. */
|
|
76
|
+
readonly sound: Schema.optional<Schema.Boolean>;
|
|
77
|
+
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
78
|
+
}>;
|
|
79
|
+
/** A normalized video request, the plain object `ai.video.request(...)` returns. */
|
|
80
|
+
export type VideoRequest<Model extends VideoModel = VideoModel> = Omit<typeof VideoRequestSchema.Type, "model" | "providerOptions" | "resolution"> & BaseRequest<Model, VideoModelOptions<Model>> & {
|
|
81
|
+
readonly resolution?: VideoResolution;
|
|
82
|
+
};
|
|
83
|
+
export type VideoModelOptions<Model> = Model extends VideoModel<infer Options> ? Options : never;
|
|
84
|
+
/** Input accepted by `ai.video.request` and `ai.video.start`; a `VideoRequest` is also a valid input. */
|
|
85
|
+
export type VideoRequestInput<Model extends VideoModel = VideoModel> = Omit<VideoRequest<Model>, "start" | "end" | "references" | "providerOptions"> & {
|
|
86
|
+
/** An image: `Media.image(...)`, or a URL, data URL, base64 string or bytes, which must not be a known non-image. */
|
|
87
|
+
readonly start?: Media.ImageAsset | Media.Data;
|
|
88
|
+
readonly end?: Media.ImageAsset | Media.Data;
|
|
89
|
+
readonly references?: ReadonlyArray<Media.Input>;
|
|
90
|
+
readonly providerOptions?: NoInfer<VideoModelOptions<Model>>;
|
|
91
|
+
};
|
|
92
|
+
/** Seconds in a request's `duration`, for protocols that send a number. */
|
|
93
|
+
export declare const seconds: (duration: VideoDuration) => number;
|
|
94
|
+
/** A submitted generation. Store `id` with the model to read the job later, from any process. */
|
|
95
|
+
export interface VideoJob {
|
|
96
|
+
/** The provider's job ID. */
|
|
97
|
+
readonly id: string;
|
|
98
|
+
}
|
|
99
|
+
export interface VideoStatus {
|
|
100
|
+
readonly status: Status;
|
|
101
|
+
/** Set when `status` is `error`. */
|
|
102
|
+
readonly reason?: Reason;
|
|
103
|
+
/** 0..1, only when the provider reports progress. */
|
|
104
|
+
readonly progress?: number;
|
|
105
|
+
}
|
|
106
|
+
declare const VideoResponse_base: Schema.Class<VideoResponse, Schema.Struct<{
|
|
107
|
+
readonly videos: Schema.$Array<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
108
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
109
|
+
readonly type: Schema.Literal<"bytes">;
|
|
110
|
+
readonly data: Schema.Uint8Array;
|
|
111
|
+
readonly mediaType: Schema.String;
|
|
112
|
+
}>, Schema.Struct<{
|
|
113
|
+
readonly type: Schema.Literal<"base64">;
|
|
114
|
+
readonly data: Schema.String;
|
|
115
|
+
readonly mediaType: Schema.String;
|
|
116
|
+
}>, Schema.Struct<{
|
|
117
|
+
readonly type: Schema.Literal<"url">;
|
|
118
|
+
readonly url: Schema.String;
|
|
119
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
120
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
121
|
+
}>, Schema.Struct<{
|
|
122
|
+
readonly type: Schema.Literal<"ref">;
|
|
123
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
124
|
+
readonly id: Schema.String;
|
|
125
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
126
|
+
}>]>;
|
|
127
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
128
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
129
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
130
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
131
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
132
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
133
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
134
|
+
readonly format: Schema.optional<Schema.String>;
|
|
135
|
+
}>>;
|
|
136
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
137
|
+
}>, never, never>>;
|
|
138
|
+
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
139
|
+
readonly type: Schema.Literal<"tokens">;
|
|
140
|
+
readonly input: Schema.optional<Schema.Number>;
|
|
141
|
+
readonly output: Schema.optional<Schema.Number>;
|
|
142
|
+
readonly total: Schema.optional<Schema.Number>;
|
|
143
|
+
readonly details: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
144
|
+
}>, Schema.Struct<{
|
|
145
|
+
readonly type: Schema.Literal<"seconds">;
|
|
146
|
+
readonly seconds: Schema.Number;
|
|
147
|
+
}>, Schema.Struct<{
|
|
148
|
+
readonly type: Schema.Literal<"characters">;
|
|
149
|
+
readonly characters: Schema.Number;
|
|
150
|
+
}>, Schema.Struct<{
|
|
151
|
+
readonly type: Schema.Literal<"credits">;
|
|
152
|
+
readonly credits: Schema.Number;
|
|
153
|
+
}>, Schema.Struct<{
|
|
154
|
+
readonly type: Schema.Literal<"compute">;
|
|
155
|
+
readonly seconds: Schema.Number;
|
|
156
|
+
}>]>>;
|
|
157
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
158
|
+
}>, {}>;
|
|
159
|
+
export declare class VideoResponse extends VideoResponse_base {
|
|
160
|
+
}
|
|
161
|
+
/** Normalize video request input into a plain `VideoRequest`. */
|
|
162
|
+
export declare const request: <const Model extends VideoModel>(input: VideoRequestInput<Model>) => VideoRequest<Model>;
|
|
163
|
+
/** Submit a generation and return at once; nothing polls. */
|
|
164
|
+
export declare function start<const Model extends VideoModel>(input: VideoRequestInput<Model>): Effect.Effect<VideoJob, AIError, AI.Service>;
|
|
165
|
+
/** One status read for a job ID. */
|
|
166
|
+
export declare const status: (model: VideoModel, id: string) => Effect.Effect<VideoStatus, AIError, AI.Service>;
|
|
167
|
+
/** The finished videos; fails while the job is still running, or with the provider's reason when it failed. */
|
|
168
|
+
export declare const result: (model: VideoModel, id: string) => Effect.Effect<VideoResponse, AIError, AI.Service>;
|
|
169
|
+
/** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
|
|
170
|
+
export declare const cancel: (model: VideoModel, id: string) => Effect.Effect<void, AIError, AI.Service>;
|
|
171
|
+
export declare const Video: {
|
|
172
|
+
readonly request: typeof request;
|
|
173
|
+
readonly start: typeof start;
|
|
174
|
+
readonly status: typeof status;
|
|
175
|
+
readonly result: typeof result;
|
|
176
|
+
readonly cancel: typeof cancel;
|
|
177
|
+
};
|
|
178
|
+
export {};
|
package/dist/video.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import { Media } from "./media.js";
|
|
3
|
+
import { MediaModel, composeQueuedRoute, tryRequest } from "./media-model.js";
|
|
4
|
+
import { MediaRoute } from "./route/media.js";
|
|
5
|
+
import { AIError, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
6
|
+
import { AI } from "./ai.js";
|
|
7
|
+
export class VideoModel extends MediaModel {
|
|
8
|
+
/** A video route's token is the provider's job ID, so `VideoJob.id` is exactly what `status` and `result` take. */
|
|
9
|
+
static fromRoute(route, input) {
|
|
10
|
+
return new VideoModel({
|
|
11
|
+
id: input.id,
|
|
12
|
+
provider: route.protocol.provider,
|
|
13
|
+
transport: input.transport,
|
|
14
|
+
providerOptions: input.providerOptions,
|
|
15
|
+
route: composeQueuedRoute(route, input),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const VideoModelSchema = Schema.declare((value) => value instanceof VideoModel, {
|
|
20
|
+
expected: "Video.Model",
|
|
21
|
+
});
|
|
22
|
+
export const VideoAspectRatio = Schema.Union([Media.AspectRatio, Schema.Literal("auto")]);
|
|
23
|
+
export const VideoDuration = Schema.declare((value) => typeof value === "string" && /^\d+(?:\.\d+)? seconds?$/.test(value), { title: "Video.Duration" });
|
|
24
|
+
const VideoRequestSchema = Schema.Struct({
|
|
25
|
+
model: VideoModelSchema,
|
|
26
|
+
prompt: Schema.String,
|
|
27
|
+
/** Image the video starts on exactly. */
|
|
28
|
+
start: Schema.optional(Media.ImageAssetSchema),
|
|
29
|
+
/** Image the video ends on exactly. */
|
|
30
|
+
end: Schema.optional(Media.ImageAssetSchema),
|
|
31
|
+
/** Images, videos or audio that guide the subject or style without pinning a frame. */
|
|
32
|
+
references: Schema.optional(Schema.Array(Media.AssetSchema)),
|
|
33
|
+
duration: Schema.optional(VideoDuration),
|
|
34
|
+
aspect: Schema.optional(VideoAspectRatio),
|
|
35
|
+
resolution: Schema.optional(Schema.String),
|
|
36
|
+
/** Whether the video has a generated soundtrack; unset leaves the model's default. */
|
|
37
|
+
sound: Schema.optional(Schema.Boolean),
|
|
38
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
39
|
+
});
|
|
40
|
+
/** Seconds in a request's `duration`, for protocols that send a number. */
|
|
41
|
+
export const seconds = (duration) => Duration.toSeconds(Duration.fromInputUnsafe(duration));
|
|
42
|
+
export class VideoResponse extends Schema.Class("Video.Response")({
|
|
43
|
+
videos: Schema.Array(Media.AssetSchema),
|
|
44
|
+
usage: Schema.optional(MediaUsage),
|
|
45
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
46
|
+
}) {
|
|
47
|
+
}
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Call API
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
/** Normalize video request input into a plain `VideoRequest`. */
|
|
52
|
+
export const request = (input) => ({
|
|
53
|
+
...input,
|
|
54
|
+
start: input.start === undefined ? undefined : Media.image(input.start),
|
|
55
|
+
end: input.end === undefined ? undefined : Media.image(input.end),
|
|
56
|
+
references: input.references?.map((reference) => Media.make(reference)),
|
|
57
|
+
});
|
|
58
|
+
const validate = Schema.decodeUnknownSync(VideoRequestSchema);
|
|
59
|
+
const requestEffect = (input) => tryRequest(() => {
|
|
60
|
+
const normalized = request(input);
|
|
61
|
+
validate(normalized);
|
|
62
|
+
return normalized;
|
|
63
|
+
});
|
|
64
|
+
export function start(input) {
|
|
65
|
+
return requestEffect(input).pipe(Effect.flatMap((request) => AI.Service.use((ai) => ai.video.start(request))));
|
|
66
|
+
}
|
|
67
|
+
/** One status read for a job ID. */
|
|
68
|
+
export const status = (model, id) => AI.Service.use((ai) => ai.video.status(model, id));
|
|
69
|
+
/** The finished videos; fails while the job is still running, or with the provider's reason when it failed. */
|
|
70
|
+
export const result = (model, id) => AI.Service.use((ai) => ai.video.result(model, id));
|
|
71
|
+
/** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
|
|
72
|
+
export const cancel = (model, id) => AI.Service.use((ai) => ai.video.cancel(model, id));
|
|
73
|
+
export const Video = {
|
|
74
|
+
request,
|
|
75
|
+
start,
|
|
76
|
+
status,
|
|
77
|
+
result,
|
|
78
|
+
cancel,
|
|
79
|
+
};
|