@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,185 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { TranscriptionModel, type TranscriptionRequest, type TranscriptionSegment } from "../transcription.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
6
|
+
export declare const PATH = "/audio/transcriptions";
|
|
7
|
+
export type OpenAITranscriptionOptions = {
|
|
8
|
+
readonly chunking_strategy?: "auto" | {
|
|
9
|
+
readonly type: "server_vad";
|
|
10
|
+
readonly prefix_padding_ms?: number;
|
|
11
|
+
readonly silence_duration_ms?: number;
|
|
12
|
+
readonly threshold?: number;
|
|
13
|
+
};
|
|
14
|
+
readonly include?: ReadonlyArray<"logprobs">;
|
|
15
|
+
readonly keywords?: ReadonlyArray<string>;
|
|
16
|
+
readonly known_speaker_names?: ReadonlyArray<string>;
|
|
17
|
+
readonly known_speaker_references?: ReadonlyArray<string>;
|
|
18
|
+
readonly temperature?: number;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
export type Request = TranscriptionRequest<TranscriptionModel<OpenAITranscriptionOptions>>;
|
|
21
|
+
declare const Transcript: Schema.Struct<{
|
|
22
|
+
text: Schema.String;
|
|
23
|
+
language: Schema.optional<Schema.String>;
|
|
24
|
+
languages: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
25
|
+
readonly code: Schema.String;
|
|
26
|
+
}>>>;
|
|
27
|
+
duration: Schema.optional<Schema.Number>;
|
|
28
|
+
segments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
29
|
+
readonly text: Schema.String;
|
|
30
|
+
readonly start: Schema.Number;
|
|
31
|
+
readonly end: Schema.Number;
|
|
32
|
+
readonly speaker: Schema.optional<Schema.String>;
|
|
33
|
+
}>>>;
|
|
34
|
+
words: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
35
|
+
readonly word: Schema.String;
|
|
36
|
+
readonly start: Schema.Number;
|
|
37
|
+
readonly end: Schema.Number;
|
|
38
|
+
}>>>;
|
|
39
|
+
usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
40
|
+
readonly type: Schema.Literal<"tokens">;
|
|
41
|
+
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
42
|
+
readonly output_tokens: Schema.optional<Schema.Number>;
|
|
43
|
+
readonly total_tokens: Schema.optional<Schema.Number>;
|
|
44
|
+
readonly input_token_details: Schema.optional<Schema.Struct<{
|
|
45
|
+
readonly audio_tokens: Schema.optional<Schema.Number>;
|
|
46
|
+
readonly text_tokens: Schema.optional<Schema.Number>;
|
|
47
|
+
}>>;
|
|
48
|
+
}>, Schema.Struct<{
|
|
49
|
+
readonly type: Schema.Literal<"duration">;
|
|
50
|
+
readonly seconds: Schema.Number;
|
|
51
|
+
}>]>>;
|
|
52
|
+
}>;
|
|
53
|
+
type Transcript = Schema.Schema.Type<typeof Transcript>;
|
|
54
|
+
type Frame = string | {
|
|
55
|
+
readonly document: string;
|
|
56
|
+
};
|
|
57
|
+
interface State {
|
|
58
|
+
readonly segments: Array<TranscriptionSegment>;
|
|
59
|
+
readonly transcript?: Transcript;
|
|
60
|
+
}
|
|
61
|
+
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
62
|
+
readonly type: "text-delta";
|
|
63
|
+
readonly delta: string;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "segment";
|
|
66
|
+
readonly segment: {
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly startSeconds: number;
|
|
69
|
+
readonly endSeconds: number;
|
|
70
|
+
readonly speaker?: string | undefined;
|
|
71
|
+
};
|
|
72
|
+
} | {
|
|
73
|
+
readonly type: "generation-progress";
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly progress?: number | undefined;
|
|
76
|
+
} | {
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly segments?: readonly {
|
|
79
|
+
readonly text: string;
|
|
80
|
+
readonly startSeconds: number;
|
|
81
|
+
readonly endSeconds: number;
|
|
82
|
+
readonly speaker?: string | undefined;
|
|
83
|
+
}[] | undefined;
|
|
84
|
+
readonly words?: readonly {
|
|
85
|
+
readonly text: string;
|
|
86
|
+
readonly startSeconds: number;
|
|
87
|
+
readonly endSeconds: number;
|
|
88
|
+
readonly speaker?: string | undefined;
|
|
89
|
+
readonly confidence?: number | undefined;
|
|
90
|
+
}[] | undefined;
|
|
91
|
+
readonly language?: string | undefined;
|
|
92
|
+
readonly durationSeconds?: number | undefined;
|
|
93
|
+
readonly usage?: {
|
|
94
|
+
readonly type: "seconds";
|
|
95
|
+
readonly seconds: number;
|
|
96
|
+
} | {
|
|
97
|
+
readonly type: "characters";
|
|
98
|
+
readonly characters: number;
|
|
99
|
+
} | {
|
|
100
|
+
readonly type: "credits";
|
|
101
|
+
readonly credits: number;
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: "compute";
|
|
104
|
+
readonly seconds: number;
|
|
105
|
+
} | {
|
|
106
|
+
readonly type: "tokens";
|
|
107
|
+
readonly input?: number | undefined;
|
|
108
|
+
readonly output?: number | undefined;
|
|
109
|
+
readonly total?: number | undefined;
|
|
110
|
+
readonly details?: {
|
|
111
|
+
readonly [x: string]: unknown;
|
|
112
|
+
} | undefined;
|
|
113
|
+
} | undefined;
|
|
114
|
+
readonly providerMetadata?: {
|
|
115
|
+
readonly [x: string]: {
|
|
116
|
+
readonly [x: string]: unknown;
|
|
117
|
+
};
|
|
118
|
+
} | undefined;
|
|
119
|
+
readonly type: "finish";
|
|
120
|
+
}, Frame, State>;
|
|
121
|
+
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<OpenAITranscriptionOptions>;
|
|
122
|
+
export declare const OpenAITranscription: {
|
|
123
|
+
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
124
|
+
readonly type: "text-delta";
|
|
125
|
+
readonly delta: string;
|
|
126
|
+
} | {
|
|
127
|
+
readonly type: "segment";
|
|
128
|
+
readonly segment: {
|
|
129
|
+
readonly text: string;
|
|
130
|
+
readonly startSeconds: number;
|
|
131
|
+
readonly endSeconds: number;
|
|
132
|
+
readonly speaker?: string | undefined;
|
|
133
|
+
};
|
|
134
|
+
} | {
|
|
135
|
+
readonly type: "generation-progress";
|
|
136
|
+
readonly id: string;
|
|
137
|
+
readonly progress?: number | undefined;
|
|
138
|
+
} | {
|
|
139
|
+
readonly text: string;
|
|
140
|
+
readonly segments?: readonly {
|
|
141
|
+
readonly text: string;
|
|
142
|
+
readonly startSeconds: number;
|
|
143
|
+
readonly endSeconds: number;
|
|
144
|
+
readonly speaker?: string | undefined;
|
|
145
|
+
}[] | undefined;
|
|
146
|
+
readonly words?: readonly {
|
|
147
|
+
readonly text: string;
|
|
148
|
+
readonly startSeconds: number;
|
|
149
|
+
readonly endSeconds: number;
|
|
150
|
+
readonly speaker?: string | undefined;
|
|
151
|
+
readonly confidence?: number | undefined;
|
|
152
|
+
}[] | undefined;
|
|
153
|
+
readonly language?: string | undefined;
|
|
154
|
+
readonly durationSeconds?: number | undefined;
|
|
155
|
+
readonly usage?: {
|
|
156
|
+
readonly type: "seconds";
|
|
157
|
+
readonly seconds: number;
|
|
158
|
+
} | {
|
|
159
|
+
readonly type: "characters";
|
|
160
|
+
readonly characters: number;
|
|
161
|
+
} | {
|
|
162
|
+
readonly type: "credits";
|
|
163
|
+
readonly credits: number;
|
|
164
|
+
} | {
|
|
165
|
+
readonly type: "compute";
|
|
166
|
+
readonly seconds: number;
|
|
167
|
+
} | {
|
|
168
|
+
readonly type: "tokens";
|
|
169
|
+
readonly input?: number | undefined;
|
|
170
|
+
readonly output?: number | undefined;
|
|
171
|
+
readonly total?: number | undefined;
|
|
172
|
+
readonly details?: {
|
|
173
|
+
readonly [x: string]: unknown;
|
|
174
|
+
} | undefined;
|
|
175
|
+
} | undefined;
|
|
176
|
+
readonly providerMetadata?: {
|
|
177
|
+
readonly [x: string]: {
|
|
178
|
+
readonly [x: string]: unknown;
|
|
179
|
+
};
|
|
180
|
+
} | undefined;
|
|
181
|
+
readonly type: "finish";
|
|
182
|
+
}, Frame, State>;
|
|
183
|
+
readonly model: typeof model;
|
|
184
|
+
};
|
|
185
|
+
export {};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Effect, Schema, SchemaGetter, Stream } from "effect";
|
|
2
|
+
import { classifyProviderFailure } from "../provider-error.js";
|
|
3
|
+
import { Framing } from "../route/framing.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { MediaRoute } from "../route/media.js";
|
|
6
|
+
import { AIError, mergeJsonRecords, tokenUsage } from "../schema/index.js";
|
|
7
|
+
import { TranscriptionFinishEvent, TranscriptionModel, TranscriptionSegmentEvent, TranscriptionTextDeltaEvent, } from "../transcription.js";
|
|
8
|
+
import { mediaTypeExtension } from "../utils/media-type.js";
|
|
9
|
+
import { ProviderShared } from "./shared.js";
|
|
10
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
11
|
+
const route = MediaProtocol.identity({ id: "openai-transcription", name: "OpenAI Transcription", provider: "openai" });
|
|
12
|
+
export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
13
|
+
export const PATH = "/audio/transcriptions";
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 3. Streaming event schema
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
const Segment = Schema.Struct({
|
|
18
|
+
text: Schema.String,
|
|
19
|
+
start: Schema.Number,
|
|
20
|
+
end: Schema.Number,
|
|
21
|
+
speaker: Schema.optional(Schema.String),
|
|
22
|
+
});
|
|
23
|
+
const Usage = Schema.Union([
|
|
24
|
+
Schema.Struct({
|
|
25
|
+
type: Schema.Literal("tokens"),
|
|
26
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
27
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
28
|
+
total_tokens: Schema.optional(Schema.Number),
|
|
29
|
+
input_token_details: Schema.optional(Schema.Struct({ audio_tokens: Schema.optional(Schema.Number), text_tokens: Schema.optional(Schema.Number) })),
|
|
30
|
+
}),
|
|
31
|
+
Schema.Struct({ type: Schema.Literal("duration"), seconds: Schema.Number }),
|
|
32
|
+
]);
|
|
33
|
+
const transcriptFields = {
|
|
34
|
+
text: Schema.String,
|
|
35
|
+
language: Schema.optional(Schema.String),
|
|
36
|
+
languages: Schema.optional(Schema.Array(Schema.Struct({ code: Schema.String }))),
|
|
37
|
+
duration: Schema.optional(Schema.Number),
|
|
38
|
+
segments: Schema.optional(Schema.Array(Segment)),
|
|
39
|
+
words: Schema.optional(Schema.Array(Schema.Struct({ word: Schema.String, start: Schema.Number, end: Schema.Number }))),
|
|
40
|
+
usage: Schema.optional(Usage),
|
|
41
|
+
};
|
|
42
|
+
const EVENT_TYPES = new Set(["transcript.text.delta", "transcript.text.segment", "transcript.text.done", "error"]);
|
|
43
|
+
/** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
|
|
44
|
+
const UnknownEvent = Schema.Struct({
|
|
45
|
+
type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
|
|
46
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
|
|
47
|
+
decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
|
|
48
|
+
encode: SchemaGetter.forbidden(() => "Unknown OpenAI Transcription stream events are decode-only"),
|
|
49
|
+
}));
|
|
50
|
+
const Event = Schema.Union([
|
|
51
|
+
Schema.Struct({ type: Schema.Literal("transcript.text.delta"), delta: Schema.String }),
|
|
52
|
+
Schema.Struct({ type: Schema.Literal("transcript.text.segment"), ...Segment.fields }),
|
|
53
|
+
Schema.Struct({ type: Schema.Literal("transcript.text.done"), ...transcriptFields }),
|
|
54
|
+
Schema.Struct({
|
|
55
|
+
type: Schema.Literal("error"),
|
|
56
|
+
message: Schema.optional(Schema.String),
|
|
57
|
+
error: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) })),
|
|
58
|
+
}),
|
|
59
|
+
UnknownEvent,
|
|
60
|
+
]);
|
|
61
|
+
const Transcript = Schema.Struct(transcriptFields);
|
|
62
|
+
const decodeEvent = route.decodeFrame(Event);
|
|
63
|
+
const decodeTranscript = route.decodeFrame(Transcript);
|
|
64
|
+
const TRANSCRIBE = { stream: true, timestamps: [], diarize: false, languageField: "language" };
|
|
65
|
+
const capabilities = (model) => {
|
|
66
|
+
if (model.startsWith("whisper"))
|
|
67
|
+
return { ...TRANSCRIBE, stream: false, timestamps: ["segment", "word"] };
|
|
68
|
+
if (model.includes("diarize"))
|
|
69
|
+
return { ...TRANSCRIBE, timestamps: ["segment"], diarize: true };
|
|
70
|
+
// `gpt-transcribe` replaces `language` with `languages[]` and rejects both together.
|
|
71
|
+
if (model.startsWith("gpt-transcribe"))
|
|
72
|
+
return { ...TRANSCRIBE, languageField: "languages" };
|
|
73
|
+
return TRANSCRIBE;
|
|
74
|
+
};
|
|
75
|
+
/** whisper-1 ignores `stream`, so its `stream` mode sends a plain request and emits only `finish`. */
|
|
76
|
+
const streamsEvents = (request) => request.mode === "stream" && capabilities(request.model.id).stream;
|
|
77
|
+
const validate = (request, model) => {
|
|
78
|
+
const id = request.model.id;
|
|
79
|
+
if (request.diarize === true && !model.diarize)
|
|
80
|
+
return Effect.fail(route.unsupported("media.diarize", `${id} does not diarize; use gpt-4o-transcribe-diarize`));
|
|
81
|
+
if (request.prompt !== undefined && model.diarize)
|
|
82
|
+
return Effect.fail(route.unsupported("media.prompt", `${id} does not accept a prompt`));
|
|
83
|
+
if (request.timestamps === undefined ||
|
|
84
|
+
request.timestamps === "none" ||
|
|
85
|
+
model.timestamps.includes(request.timestamps))
|
|
86
|
+
return Effect.void;
|
|
87
|
+
return Effect.fail(route.unsupported("media.timestamps", `${id} does not return ${request.timestamps} timestamps`));
|
|
88
|
+
};
|
|
89
|
+
const RESERVED_FORM_FIELDS = new Set([
|
|
90
|
+
"file",
|
|
91
|
+
"model",
|
|
92
|
+
"prompt",
|
|
93
|
+
"language",
|
|
94
|
+
"response_format",
|
|
95
|
+
"timestamp_granularities",
|
|
96
|
+
"stream",
|
|
97
|
+
]);
|
|
98
|
+
const fromRequest = Effect.fn("OpenAITranscription.fromRequest")(function* (request) {
|
|
99
|
+
const model = capabilities(request.model.id);
|
|
100
|
+
yield* validate(request, model);
|
|
101
|
+
// The API detects the audio format from the upload's filename extension.
|
|
102
|
+
const extension = mediaTypeExtension(request.audio.mediaType);
|
|
103
|
+
if (extension === undefined)
|
|
104
|
+
return yield* ProviderShared.invalidRequest(`${route.name} cannot name a ${request.audio.mediaType} upload; send mp3, mp4, m4a, wav, webm, ogg, or flac audio`);
|
|
105
|
+
const audio = yield* MediaInput.inlineBytes(route.id, request.audio);
|
|
106
|
+
const responseFormat = model.diarize
|
|
107
|
+
? "diarized_json"
|
|
108
|
+
: request.timestamps === undefined || request.timestamps === "none"
|
|
109
|
+
? undefined
|
|
110
|
+
: "verbose_json";
|
|
111
|
+
const form = new FormData();
|
|
112
|
+
form.append("file", MediaInput.blob(audio, request.audio.mediaType), `audio.${extension}`);
|
|
113
|
+
MediaInput.appendFields(form, {
|
|
114
|
+
model: request.model.id,
|
|
115
|
+
language: model.languageField === "language" ? request.language : undefined,
|
|
116
|
+
languages: model.languageField === "languages" && request.language !== undefined ? [request.language] : undefined,
|
|
117
|
+
prompt: request.prompt,
|
|
118
|
+
response_format: responseFormat,
|
|
119
|
+
timestamp_granularities: responseFormat === "verbose_json" ? [request.timestamps] : undefined,
|
|
120
|
+
// Diarizing audio longer than 30 seconds requires a chunking strategy.
|
|
121
|
+
chunking_strategy: model.diarize ? "auto" : undefined,
|
|
122
|
+
stream: streamsEvents(request) ? true : undefined,
|
|
123
|
+
}, {
|
|
124
|
+
overlay: mergeJsonRecords(request.providerOptions, request.http?.body),
|
|
125
|
+
reserved: RESERVED_FORM_FIELDS,
|
|
126
|
+
repeatArrays: "key[]",
|
|
127
|
+
});
|
|
128
|
+
return MediaProtocol.multipart(form);
|
|
129
|
+
});
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// 6. Stream parsing
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
const segment = (value) => ({
|
|
134
|
+
text: value.text.trim(),
|
|
135
|
+
startSeconds: value.start,
|
|
136
|
+
endSeconds: value.end,
|
|
137
|
+
speaker: value.speaker,
|
|
138
|
+
});
|
|
139
|
+
const onEvent = Effect.fnUntraced(function* (state, frame) {
|
|
140
|
+
const event = yield* decodeEvent(frame);
|
|
141
|
+
if (event.type === "unknown")
|
|
142
|
+
return [state, []];
|
|
143
|
+
if (event.type === "error")
|
|
144
|
+
return yield* new AIError({
|
|
145
|
+
reason: classifyProviderFailure({
|
|
146
|
+
message: `${route.name} stream failed: ${event.message ?? event.error?.message ?? "unknown error"}`,
|
|
147
|
+
rawBody: frame,
|
|
148
|
+
}),
|
|
149
|
+
});
|
|
150
|
+
if (event.type === "transcript.text.done")
|
|
151
|
+
return [{ ...state, transcript: event }, []];
|
|
152
|
+
if (event.type === "transcript.text.delta")
|
|
153
|
+
return [state, event.delta.length === 0 ? [] : [TranscriptionTextDeltaEvent.make({ delta: event.delta })]];
|
|
154
|
+
const next = segment(event);
|
|
155
|
+
state.segments.push(next);
|
|
156
|
+
return [state, [TranscriptionSegmentEvent.make({ segment: next })]];
|
|
157
|
+
});
|
|
158
|
+
const step = (state, frame) => typeof frame === "string"
|
|
159
|
+
? onEvent(state, frame)
|
|
160
|
+
: decodeTranscript(frame.document).pipe(Effect.map((transcript) => [{ ...state, transcript }, []]));
|
|
161
|
+
const usage = (value) => {
|
|
162
|
+
if (value === undefined)
|
|
163
|
+
return undefined;
|
|
164
|
+
if (value.type === "duration")
|
|
165
|
+
return { type: "seconds", seconds: value.seconds };
|
|
166
|
+
return tokenUsage({
|
|
167
|
+
input: value.input_tokens,
|
|
168
|
+
output: value.output_tokens,
|
|
169
|
+
total: value.total_tokens,
|
|
170
|
+
details: { openai: value },
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const finish = (state) => {
|
|
174
|
+
const transcript = state.transcript;
|
|
175
|
+
if (transcript === undefined)
|
|
176
|
+
return Effect.fail(route.incomplete());
|
|
177
|
+
const segments = transcript.segments?.map(segment) ?? state.segments;
|
|
178
|
+
return Effect.succeed([
|
|
179
|
+
TranscriptionFinishEvent.make({
|
|
180
|
+
text: transcript.text,
|
|
181
|
+
segments: segments.length === 0 ? undefined : segments,
|
|
182
|
+
words: transcript.words?.map((word) => ({ text: word.word, startSeconds: word.start, endSeconds: word.end })),
|
|
183
|
+
language: (transcript.language ?? transcript.languages?.[0]?.code)?.toLowerCase(),
|
|
184
|
+
durationSeconds: transcript.duration,
|
|
185
|
+
usage: usage(transcript.usage),
|
|
186
|
+
}),
|
|
187
|
+
]);
|
|
188
|
+
};
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// 7. Protocol and route
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
export const protocol = MediaProtocol.stream(route, {
|
|
193
|
+
unsupported: ["speakers"],
|
|
194
|
+
body: { from: fromRequest },
|
|
195
|
+
frames: (bytes, context) => streamsEvents(context.request)
|
|
196
|
+
? Framing.sse.frame(bytes)
|
|
197
|
+
: Framing.document.frame(bytes).pipe(Stream.map((document) => ({ document }))),
|
|
198
|
+
initial: () => ({ segments: [] }),
|
|
199
|
+
step,
|
|
200
|
+
finish,
|
|
201
|
+
});
|
|
202
|
+
export const model = (input) => TranscriptionModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
203
|
+
export const OpenAITranscription = {
|
|
204
|
+
protocol,
|
|
205
|
+
model,
|
|
206
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
6
|
+
export declare const PATH = "/videos";
|
|
7
|
+
/**
|
|
8
|
+
* Provider-native options. Common fields (`start`, `end`, `references`, `duration`, `aspect`, `resolution`, `sound`)
|
|
9
|
+
* live on the request. `provider` routes the request and forwards the upstream provider's own parameters under
|
|
10
|
+
* `provider.options.<slug>` (see each model's `allowed_passthrough_parameters`); `previous_job_id` edits or extends a
|
|
11
|
+
* finished OpenRouter job on the same model.
|
|
12
|
+
*/
|
|
13
|
+
export type OpenRouterVideoOptions = {
|
|
14
|
+
readonly provider?: {
|
|
15
|
+
readonly order?: ReadonlyArray<string>;
|
|
16
|
+
readonly only?: ReadonlyArray<string>;
|
|
17
|
+
readonly ignore?: ReadonlyArray<string>;
|
|
18
|
+
readonly options?: Readonly<Record<string, Record<string, unknown>>>;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
readonly previous_job_id?: string;
|
|
21
|
+
readonly seed?: number;
|
|
22
|
+
readonly size?: string;
|
|
23
|
+
readonly callback_url?: string;
|
|
24
|
+
readonly user?: string;
|
|
25
|
+
readonly session_id?: string;
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
export type Request = VideoRequest<VideoModel<OpenRouterVideoOptions>>;
|
|
28
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
29
|
+
export declare const Token: Schema.String;
|
|
30
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
31
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
32
|
+
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<OpenRouterVideoOptions>;
|
|
33
|
+
export declare const OpenRouterVideo: {
|
|
34
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
35
|
+
readonly model: typeof model;
|
|
36
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { 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 { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { VideoModel, VideoResponse, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
const route = MediaProtocol.identity({ id: "openrouter-video", name: "OpenRouter Video", provider: "openrouter" });
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
10
|
+
export const PATH = "/videos";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// 2. Token and response schemas
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
15
|
+
export const Token = Schema.String;
|
|
16
|
+
const StartResponse = Schema.Struct({ id: Schema.String, status: optionalNull(Schema.String) });
|
|
17
|
+
const Job = Schema.Struct({
|
|
18
|
+
id: optionalNull(Schema.String),
|
|
19
|
+
generation_id: optionalNull(Schema.String),
|
|
20
|
+
status: Schema.String,
|
|
21
|
+
unsigned_urls: optionalNull(Schema.Array(Schema.String)),
|
|
22
|
+
expires_at: optionalNull(Schema.Number),
|
|
23
|
+
error: optionalNull(Schema.String),
|
|
24
|
+
usage: optionalNull(Schema.Struct({
|
|
25
|
+
cost: optionalNull(Schema.Number),
|
|
26
|
+
is_byok: optionalNull(Schema.Boolean),
|
|
27
|
+
})),
|
|
28
|
+
});
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// 3. Status
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
const STATUS = {
|
|
33
|
+
pending: "running",
|
|
34
|
+
in_progress: "running",
|
|
35
|
+
completed: "completed",
|
|
36
|
+
failed: "failed",
|
|
37
|
+
cancelled: "cancelled",
|
|
38
|
+
expired: "expired",
|
|
39
|
+
};
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// 4. Body construction
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
const imagePart = (asset) => ProviderShared.mediaReference(asset, undefined, route.name).pipe(Effect.map((reference) => ({ type: "image_url", image_url: { url: reference.value } })));
|
|
44
|
+
const referencePart = Effect.fn("OpenRouterVideo.referencePart")(function* (asset) {
|
|
45
|
+
// OpenRouter rejects inline video and audio ("Only HTTPS URLs are allowed", verified live); inline images work.
|
|
46
|
+
if ((asset.kind === "video" || asset.kind === "audio") && asset.source.type !== "url")
|
|
47
|
+
return yield* route.unsupported("video.references", `${route.name} only takes reference ${asset.kind} as http(s) URLs`);
|
|
48
|
+
const reference = yield* ProviderShared.mediaReference(asset, undefined, route.name);
|
|
49
|
+
if (asset.kind === "video")
|
|
50
|
+
return { type: "video_url", video_url: { url: reference.value } };
|
|
51
|
+
if (asset.kind === "audio")
|
|
52
|
+
return { type: "audio_url", audio_url: { url: reference.value } };
|
|
53
|
+
return { type: "image_url", image_url: { url: reference.value } };
|
|
54
|
+
});
|
|
55
|
+
const fromRequest = Effect.fn("OpenRouterVideo.fromRequest")(function* (request) {
|
|
56
|
+
const frames = [
|
|
57
|
+
...(request.start === undefined
|
|
58
|
+
? []
|
|
59
|
+
: [{ ...(yield* imagePart(request.start)), frame_type: "first_frame" }]),
|
|
60
|
+
...(request.end === undefined ? [] : [{ ...(yield* imagePart(request.end)), frame_type: "last_frame" }]),
|
|
61
|
+
];
|
|
62
|
+
const inputReferences = yield* Effect.forEach(request.references ?? [], referencePart);
|
|
63
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
64
|
+
model: request.model.id,
|
|
65
|
+
prompt: request.prompt,
|
|
66
|
+
frame_images: frames.length === 0 ? undefined : frames,
|
|
67
|
+
input_references: inputReferences.length === 0 ? undefined : inputReferences,
|
|
68
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
69
|
+
// Leaving the aspect ratio out is how OpenRouter follows the input image on models that can.
|
|
70
|
+
aspect_ratio: request.aspect === "auto" ? undefined : request.aspect,
|
|
71
|
+
resolution: request.resolution === undefined ? undefined : resolution(request.resolution),
|
|
72
|
+
generate_audio: request.sound,
|
|
73
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
74
|
+
});
|
|
75
|
+
// OpenRouter spells the K resolutions in upper case (`1K`, `2K`, `4K`).
|
|
76
|
+
const resolution = (value) => (/^\dk$/.test(value) ? value.toUpperCase() : value);
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// 5. Response decoding
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
81
|
+
token: value.id,
|
|
82
|
+
snapshot: { id: value.id, ...MediaProtocol.status(STATUS, value.status ?? "pending") },
|
|
83
|
+
}));
|
|
84
|
+
const decodeJob = route.decodeJson(Job);
|
|
85
|
+
const decodeStatus = Effect.fn("OpenRouterVideo.decodeStatus")(function* (response, context) {
|
|
86
|
+
const output = yield* decodeJob(response);
|
|
87
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
88
|
+
});
|
|
89
|
+
const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (response, context) {
|
|
90
|
+
const output = yield* decodeJob(response);
|
|
91
|
+
const job = output.value;
|
|
92
|
+
const status = MediaProtocol.state(STATUS, job.status);
|
|
93
|
+
if (status === "running")
|
|
94
|
+
return yield* output.pending(context.token);
|
|
95
|
+
if (status === "failed") {
|
|
96
|
+
const message = `${route.name} generation failed${job.error ? `: ${job.error}` : ""}`;
|
|
97
|
+
if (job.error && /content policy|moderat/i.test(job.error))
|
|
98
|
+
return yield* output.contentPolicy(message);
|
|
99
|
+
return yield* output.ended("failed", message);
|
|
100
|
+
}
|
|
101
|
+
if (status !== "completed")
|
|
102
|
+
return yield* output.ended(status, `${route.name} job ${context.token} ${status}${job.error ? `: ${job.error}` : ""}`);
|
|
103
|
+
const urls = job.unsigned_urls ?? [];
|
|
104
|
+
if (urls.length === 0)
|
|
105
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
106
|
+
// The content URLs are OpenRouter's own and only download with the API key.
|
|
107
|
+
const videos = yield* Effect.forEach(urls, (url) => context.credentials(url).pipe(Effect.map((credentials) => Media.url(url, {
|
|
108
|
+
mediaType: "video/mp4",
|
|
109
|
+
expiresAt: job.expires_at === undefined || job.expires_at === null ? undefined : job.expires_at * 1000,
|
|
110
|
+
...credentials,
|
|
111
|
+
}))));
|
|
112
|
+
return new VideoResponse({
|
|
113
|
+
videos,
|
|
114
|
+
providerMetadata: {
|
|
115
|
+
openrouter: {
|
|
116
|
+
id: context.token,
|
|
117
|
+
generationId: job.generation_id ?? undefined,
|
|
118
|
+
cost: job.usage?.cost ?? undefined,
|
|
119
|
+
isByok: job.usage?.is_byok ?? undefined,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// 6. Protocol and route
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
const jobPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
128
|
+
// OpenRouter has no cancel endpoint; `cancelled` only appears when it stops a job itself.
|
|
129
|
+
export const protocol = MediaProtocol.queued(route, {
|
|
130
|
+
token: Token,
|
|
131
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
132
|
+
status: { path: jobPath, decode: decodeStatus },
|
|
133
|
+
result: { path: jobPath, decode: decodeResult },
|
|
134
|
+
});
|
|
135
|
+
export const model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
136
|
+
export const OpenRouterVideo = {
|
|
137
|
+
protocol,
|
|
138
|
+
model,
|
|
139
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
5
|
+
export declare const VOLCENGINE_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
6
|
+
export declare const BYTEPLUS_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
7
|
+
export declare const PATH = "/contents/generations/tasks";
|
|
8
|
+
/**
|
|
9
|
+
* Provider-native options, merged into the task body. Common fields (`start`, `end`, `references`, `duration`,
|
|
10
|
+
* `aspect`, `resolution`, `sound`) live on the request. `draft_task` adds a `draft_task` content item that turns a
|
|
11
|
+
* Draft video into the final one.
|
|
12
|
+
*/
|
|
13
|
+
export type SeedanceVideoOptions = {
|
|
14
|
+
readonly draft_task?: {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
};
|
|
17
|
+
readonly draft?: boolean;
|
|
18
|
+
readonly frames?: number;
|
|
19
|
+
readonly seed?: number;
|
|
20
|
+
readonly camera_fixed?: boolean;
|
|
21
|
+
readonly watermark?: boolean;
|
|
22
|
+
readonly return_last_frame?: boolean;
|
|
23
|
+
readonly omni_reference_task_type?: "auto" | "reference" | "edit" | "extend" | (string & {});
|
|
24
|
+
readonly output_format?: "mp4" | "mov" | (string & {});
|
|
25
|
+
readonly service_tier?: "default" | "flex" | (string & {});
|
|
26
|
+
readonly callback_url?: string;
|
|
27
|
+
readonly execution_expires_after?: number;
|
|
28
|
+
readonly priority?: number;
|
|
29
|
+
readonly safety_identifier?: string;
|
|
30
|
+
} & Record<string, unknown>;
|
|
31
|
+
export type Request = VideoRequest<VideoModel<SeedanceVideoOptions>>;
|
|
32
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
33
|
+
export declare const Token: Schema.String;
|
|
34
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
35
|
+
export type Provider = "volcengine" | "byteplus";
|
|
36
|
+
export declare const SeedanceVideo: {
|
|
37
|
+
readonly volcengine: {
|
|
38
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
39
|
+
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
40
|
+
};
|
|
41
|
+
readonly byteplus: {
|
|
42
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
43
|
+
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
44
|
+
};
|
|
45
|
+
};
|