@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,93 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
5
|
+
import { SpeechModel } from "../speech.js";
|
|
6
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
7
|
+
import { SpeechStream } from "./utils/speech-stream.js";
|
|
8
|
+
const route = MediaProtocol.identity({ id: "deepgram-speech", name: "Deepgram", provider: "deepgram" });
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
10
|
+
export const PATH = "/v1/speak";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// 5. Request body construction
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const FORMATS = {
|
|
15
|
+
mp3: { encoding: "mp3" },
|
|
16
|
+
wav: { encoding: "linear16", container: "wav" },
|
|
17
|
+
pcm: { encoding: "linear16", container: "none" },
|
|
18
|
+
opus: { encoding: "opus" },
|
|
19
|
+
flac: { encoding: "flac" },
|
|
20
|
+
aac: { encoding: "aac" },
|
|
21
|
+
};
|
|
22
|
+
const audioFormat = (request) => {
|
|
23
|
+
const format = request.format === undefined ? undefined : FORMATS[request.format];
|
|
24
|
+
return {
|
|
25
|
+
encoding: request.providerOptions?.encoding ?? format?.encoding,
|
|
26
|
+
container: request.providerOptions?.container ?? format?.container,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const queryParameters = (request) => {
|
|
30
|
+
const { encoding: _encoding, container: _container, sampleRate, bitRate, ...native } = request.providerOptions ?? {};
|
|
31
|
+
return MediaInput.query(route.id, {
|
|
32
|
+
...native,
|
|
33
|
+
model: request.model.id,
|
|
34
|
+
...audioFormat(request),
|
|
35
|
+
sample_rate: sampleRate,
|
|
36
|
+
bit_rate: bitRate,
|
|
37
|
+
speed: request.speed,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const fromRequest = Effect.fn("DeepgramSpeech.fromRequest")(function* (request) {
|
|
41
|
+
// Not in `unsupported`: that list would also reject `timestamps: false`, which asks for nothing.
|
|
42
|
+
if (request.timestamps === true)
|
|
43
|
+
return yield* route.unsupported("media.timestamps", `${route.name} does not return timestamps`);
|
|
44
|
+
if (request.format !== undefined &&
|
|
45
|
+
FORMATS[request.format] === undefined &&
|
|
46
|
+
request.providerOptions?.encoding === undefined)
|
|
47
|
+
return yield* route.unsupported("media.format", `${route.name} has no encoding for format "${request.format}"; pass providerOptions.encoding`);
|
|
48
|
+
return MediaProtocol.json(mergeJsonRecords({ text: request.text }, request.http?.body) ?? {}, yield* queryParameters(request));
|
|
49
|
+
});
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// 6. Stream parsing
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
/** Deepgram wraps raw encodings in WAV unless `container` is `none`, and defaults their sample rate per encoding. */
|
|
54
|
+
const HEADERLESS_ENCODINGS = {
|
|
55
|
+
linear16: { encoding: "pcm_s16le", sampleRate: 24000 },
|
|
56
|
+
mulaw: { encoding: "pcm_mulaw", sampleRate: 8000 },
|
|
57
|
+
alaw: { encoding: "pcm_alaw", sampleRate: 8000 },
|
|
58
|
+
};
|
|
59
|
+
const finish = (state, context) => {
|
|
60
|
+
const headers = context.http.headers;
|
|
61
|
+
const mediaType = headers["content-type"];
|
|
62
|
+
const format = audioFormat(context.request);
|
|
63
|
+
const headerless = HEADERLESS_ENCODINGS[format.encoding ?? ""];
|
|
64
|
+
const container = format.container ?? (headerless === undefined ? undefined : "wav");
|
|
65
|
+
const requestID = headers["dg-request-id"];
|
|
66
|
+
const modelName = headers["dg-model-name"];
|
|
67
|
+
return SpeechStream.finish(route, state, {
|
|
68
|
+
...(container === "none" && headerless !== undefined
|
|
69
|
+
? SpeechStream.pcm(headerless.encoding, SpeechStream.sampleRate(mediaType) ?? context.request.providerOptions?.sampleRate ?? headerless.sampleRate, mediaType)
|
|
70
|
+
: // Deepgram's default encoding is MP3; WAV is a container around any encoding.
|
|
71
|
+
{ mediaType, info: { format: container === "wav" ? "wav" : (format.encoding ?? "mp3") } }),
|
|
72
|
+
usage: SpeechStream.headerUsage("characters", headers["dg-char-count"]),
|
|
73
|
+
providerMetadata: requestID === undefined && modelName === undefined
|
|
74
|
+
? undefined
|
|
75
|
+
: { deepgram: { requestId: requestID, modelName } },
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// 7. Protocol and route
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
export const protocol = MediaProtocol.stream(route, {
|
|
82
|
+
unsupported: ["voice", "language", "instructions"],
|
|
83
|
+
body: { from: fromRequest },
|
|
84
|
+
frames: (bytes) => bytes,
|
|
85
|
+
initial: () => ({ chunks: [] }),
|
|
86
|
+
step: (state, frame) => Effect.succeed(SpeechStream.delta(state, frame)),
|
|
87
|
+
finish,
|
|
88
|
+
});
|
|
89
|
+
export const model = (input) => SpeechModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
90
|
+
export const DeepgramSpeech = {
|
|
91
|
+
protocol,
|
|
92
|
+
model,
|
|
93
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
|
+
import { MediaRoute } from "../route/media.js";
|
|
3
|
+
import { type OpenString } from "../schema/index.js";
|
|
4
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
6
|
+
export declare const PATH = "/v1/listen";
|
|
7
|
+
export type DeepgramTranscriptionOptions = {
|
|
8
|
+
readonly smart_format?: boolean;
|
|
9
|
+
readonly punctuate?: boolean;
|
|
10
|
+
readonly paragraphs?: boolean;
|
|
11
|
+
readonly utterances?: boolean;
|
|
12
|
+
readonly detect_language?: boolean | ReadonlyArray<string>;
|
|
13
|
+
readonly keyterm?: ReadonlyArray<string>;
|
|
14
|
+
readonly diarize_model?: OpenString<"latest" | "v1" | "v2">;
|
|
15
|
+
readonly filler_words?: boolean;
|
|
16
|
+
readonly numerals?: boolean;
|
|
17
|
+
readonly mip_opt_out?: boolean;
|
|
18
|
+
readonly tag?: string | ReadonlyArray<string>;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
export type Request = TranscriptionRequest<TranscriptionModel<DeepgramTranscriptionOptions>>;
|
|
21
|
+
export declare const protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
22
|
+
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<DeepgramTranscriptionOptions>;
|
|
23
|
+
export declare const DeepgramTranscription: {
|
|
24
|
+
readonly protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
25
|
+
readonly model: typeof model;
|
|
26
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
5
|
+
import { TranscriptionModel, TranscriptionResponse } from "../transcription.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
8
|
+
import { SpeakerTurns } from "./utils/speaker-turns.js";
|
|
9
|
+
const route = MediaProtocol.identity({ id: "deepgram-transcription", name: "Deepgram", provider: "deepgram" });
|
|
10
|
+
export const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
11
|
+
export const PATH = "/v1/listen";
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// 2. Response schema
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const Word = Schema.Struct({
|
|
16
|
+
word: Schema.String,
|
|
17
|
+
start: Schema.Number,
|
|
18
|
+
end: Schema.Number,
|
|
19
|
+
confidence: Schema.optional(Schema.Number),
|
|
20
|
+
speaker: Schema.optional(Schema.Number),
|
|
21
|
+
punctuated_word: Schema.optional(Schema.String),
|
|
22
|
+
});
|
|
23
|
+
const ListenResponse = Schema.Struct({
|
|
24
|
+
metadata: Schema.optional(Schema.Struct({ request_id: Schema.optional(Schema.String), duration: Schema.optional(Schema.Number) })),
|
|
25
|
+
results: Schema.Struct({
|
|
26
|
+
channels: Schema.Array(Schema.Struct({
|
|
27
|
+
alternatives: Schema.optional(Schema.Array(Schema.Struct({ transcript: Schema.String, words: Schema.optional(Schema.Array(Word)) }))),
|
|
28
|
+
detected_language: Schema.optional(Schema.String),
|
|
29
|
+
})),
|
|
30
|
+
utterances: Schema.optional(Schema.Array(Schema.Struct({
|
|
31
|
+
start: Schema.Number,
|
|
32
|
+
end: Schema.Number,
|
|
33
|
+
transcript: Schema.String,
|
|
34
|
+
speaker: Schema.optional(Schema.Number),
|
|
35
|
+
words: Schema.optional(Schema.Array(Word)),
|
|
36
|
+
}))),
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// 5. Request body construction
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
const query = (request) => MediaInput.query(route.id, mergeJsonRecords({
|
|
43
|
+
model: request.model.id,
|
|
44
|
+
smart_format: true,
|
|
45
|
+
language: request.language,
|
|
46
|
+
// Deepgram assumes English unless asked to detect, unlike the other routes' auto-detection.
|
|
47
|
+
detect_language: request.language === undefined ? true : undefined,
|
|
48
|
+
// `diarize=true` is deprecated in favor of choosing a diarization model.
|
|
49
|
+
diarize_model: request.diarize === true ? "latest" : undefined,
|
|
50
|
+
utterances: request.diarize === true || request.timestamps === "segment" ? true : undefined,
|
|
51
|
+
}, request.providerOptions) ?? {});
|
|
52
|
+
const fromRequest = Effect.fn("DeepgramTranscription.fromRequest")(function* (request) {
|
|
53
|
+
const url = ProviderShared.mediaUrl(request.audio);
|
|
54
|
+
if (url !== undefined)
|
|
55
|
+
return MediaProtocol.json(mergeJsonRecords({ url }, request.http?.body) ?? {}, yield* query(request));
|
|
56
|
+
if (request.http?.body !== undefined)
|
|
57
|
+
return yield* ProviderShared.invalidRequest(`${route.name} sends inline audio as the raw body, so http.body cannot apply`);
|
|
58
|
+
const audio = yield* MediaInput.inlineBytes(route.id, request.audio);
|
|
59
|
+
return MediaProtocol.binary(audio, request.audio.mediaType, yield* query(request));
|
|
60
|
+
});
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// 6. Response decoding
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
const decodeListen = route.decodeJson(ListenResponse);
|
|
65
|
+
const speaker = (value) => (value === undefined ? undefined : String(value));
|
|
66
|
+
const wordText = (word) => word.punctuated_word ?? word.word;
|
|
67
|
+
const decodeResponse = Effect.fn("DeepgramTranscription.decodeResponse")(function* (response) {
|
|
68
|
+
const output = yield* decodeListen(response);
|
|
69
|
+
const channel = output.value.results.channels[0];
|
|
70
|
+
const alternative = channel?.alternatives?.[0];
|
|
71
|
+
if (alternative === undefined)
|
|
72
|
+
return yield* output.invalid(`${route.name} returned no transcript`);
|
|
73
|
+
const duration = output.value.metadata?.duration;
|
|
74
|
+
const requestID = output.value.metadata?.request_id;
|
|
75
|
+
return new TranscriptionResponse({
|
|
76
|
+
text: alternative.transcript,
|
|
77
|
+
// Utterances split on pauses, not speakers: the v2 diarizer labels a whole utterance with one speaker even when
|
|
78
|
+
// its words change speaker, so segments split each utterance at speaker changes.
|
|
79
|
+
segments: output.value.results.utterances?.flatMap((utterance) => utterance.words === undefined || utterance.words.length === 0
|
|
80
|
+
? [
|
|
81
|
+
{
|
|
82
|
+
text: utterance.transcript,
|
|
83
|
+
startSeconds: utterance.start,
|
|
84
|
+
endSeconds: utterance.end,
|
|
85
|
+
speaker: speaker(utterance.speaker),
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
: SpeakerTurns.group(utterance.words, (word) => word.speaker).map((turn) => ({
|
|
89
|
+
text: turn.map(wordText).join(" "),
|
|
90
|
+
startSeconds: turn[0].start,
|
|
91
|
+
endSeconds: turn[turn.length - 1].end,
|
|
92
|
+
speaker: speaker(turn[0].speaker),
|
|
93
|
+
}))),
|
|
94
|
+
words: alternative.words?.map((word) => ({
|
|
95
|
+
text: wordText(word),
|
|
96
|
+
startSeconds: word.start,
|
|
97
|
+
endSeconds: word.end,
|
|
98
|
+
speaker: speaker(word.speaker),
|
|
99
|
+
confidence: word.confidence,
|
|
100
|
+
})),
|
|
101
|
+
language: channel?.detected_language?.toLowerCase(),
|
|
102
|
+
durationSeconds: duration,
|
|
103
|
+
usage: duration === undefined ? undefined : { type: "seconds", seconds: duration },
|
|
104
|
+
providerMetadata: requestID === undefined ? undefined : { deepgram: { requestId: requestID } },
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
// 7. Protocol and route
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
111
|
+
unsupported: ["prompt", "speakers"],
|
|
112
|
+
body: { from: fromRequest },
|
|
113
|
+
response: { decode: decodeResponse },
|
|
114
|
+
});
|
|
115
|
+
export const model = (input) => TranscriptionModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
116
|
+
export const DeepgramTranscription = {
|
|
117
|
+
protocol,
|
|
118
|
+
model,
|
|
119
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
|
+
import { MediaRoute } from "../route/media.js";
|
|
3
|
+
import { type OpenString } from "../schema/index.js";
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
|
+
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
7
|
+
export declare const PATH = "/v1/text-to-speech";
|
|
8
|
+
export type ElevenLabsOutputFormat = OpenString<"mp3_22050_32" | "mp3_24000_48" | "mp3_44100_32" | "mp3_44100_64" | "mp3_44100_96" | "mp3_44100_128" | "mp3_44100_192" | "pcm_8000" | "pcm_16000" | "pcm_22050" | "pcm_24000" | "pcm_32000" | "pcm_44100" | "pcm_48000" | "wav_8000" | "wav_16000" | "wav_22050" | "wav_24000" | "wav_32000" | "wav_44100" | "wav_48000" | "ulaw_8000" | "alaw_8000" | "opus_48000_32" | "opus_48000_64" | "opus_48000_96" | "opus_48000_128" | "opus_48000_192">;
|
|
9
|
+
export type ElevenLabsSpeechOptions = {
|
|
10
|
+
readonly outputFormat?: ElevenLabsOutputFormat;
|
|
11
|
+
readonly voice_settings?: {
|
|
12
|
+
readonly stability?: number;
|
|
13
|
+
readonly similarity_boost?: number;
|
|
14
|
+
readonly style?: number;
|
|
15
|
+
readonly use_speaker_boost?: boolean;
|
|
16
|
+
};
|
|
17
|
+
readonly seed?: number;
|
|
18
|
+
readonly apply_text_normalization?: OpenString<"auto" | "on" | "off">;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
export type Request = SpeechRequest<SpeechModel<ElevenLabsSpeechOptions>>;
|
|
21
|
+
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
22
|
+
readonly type: "audio-delta";
|
|
23
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "timestamps";
|
|
26
|
+
readonly items: readonly {
|
|
27
|
+
readonly text: string;
|
|
28
|
+
readonly startSeconds: number;
|
|
29
|
+
readonly endSeconds: number;
|
|
30
|
+
}[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "generation-progress";
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly progress?: number | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "finish";
|
|
37
|
+
readonly audio: import("../media.js").Asset;
|
|
38
|
+
readonly usage?: {
|
|
39
|
+
readonly type: "seconds";
|
|
40
|
+
readonly seconds: number;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "characters";
|
|
43
|
+
readonly characters: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: "credits";
|
|
46
|
+
readonly credits: number;
|
|
47
|
+
} | {
|
|
48
|
+
readonly type: "compute";
|
|
49
|
+
readonly seconds: number;
|
|
50
|
+
} | {
|
|
51
|
+
readonly type: "tokens";
|
|
52
|
+
readonly input?: number | undefined;
|
|
53
|
+
readonly output?: number | undefined;
|
|
54
|
+
readonly total?: number | undefined;
|
|
55
|
+
readonly details?: {
|
|
56
|
+
readonly [x: string]: unknown;
|
|
57
|
+
} | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
readonly providerMetadata?: {
|
|
60
|
+
readonly [x: string]: {
|
|
61
|
+
readonly [x: string]: unknown;
|
|
62
|
+
};
|
|
63
|
+
} | undefined;
|
|
64
|
+
}, string | Uint8Array<ArrayBufferLike>, SpeechStream.Audio>;
|
|
65
|
+
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<ElevenLabsSpeechOptions>;
|
|
66
|
+
export declare const ElevenLabsSpeech: {
|
|
67
|
+
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
68
|
+
readonly type: "audio-delta";
|
|
69
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
70
|
+
} | {
|
|
71
|
+
readonly type: "timestamps";
|
|
72
|
+
readonly items: readonly {
|
|
73
|
+
readonly text: string;
|
|
74
|
+
readonly startSeconds: number;
|
|
75
|
+
readonly endSeconds: number;
|
|
76
|
+
}[];
|
|
77
|
+
} | {
|
|
78
|
+
readonly type: "generation-progress";
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly progress?: number | undefined;
|
|
81
|
+
} | {
|
|
82
|
+
readonly type: "finish";
|
|
83
|
+
readonly audio: import("../media.js").Asset;
|
|
84
|
+
readonly usage?: {
|
|
85
|
+
readonly type: "seconds";
|
|
86
|
+
readonly seconds: number;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "characters";
|
|
89
|
+
readonly characters: number;
|
|
90
|
+
} | {
|
|
91
|
+
readonly type: "credits";
|
|
92
|
+
readonly credits: number;
|
|
93
|
+
} | {
|
|
94
|
+
readonly type: "compute";
|
|
95
|
+
readonly seconds: number;
|
|
96
|
+
} | {
|
|
97
|
+
readonly type: "tokens";
|
|
98
|
+
readonly input?: number | undefined;
|
|
99
|
+
readonly output?: number | undefined;
|
|
100
|
+
readonly total?: number | undefined;
|
|
101
|
+
readonly details?: {
|
|
102
|
+
readonly [x: string]: unknown;
|
|
103
|
+
} | undefined;
|
|
104
|
+
} | undefined;
|
|
105
|
+
readonly providerMetadata?: {
|
|
106
|
+
readonly [x: string]: {
|
|
107
|
+
readonly [x: string]: unknown;
|
|
108
|
+
};
|
|
109
|
+
} | undefined;
|
|
110
|
+
}, string | Uint8Array<ArrayBufferLike>, SpeechStream.Audio>;
|
|
111
|
+
readonly model: typeof model;
|
|
112
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Framing } from "../route/framing.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 { SpeechModel } from "../speech.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
import { SpeechStream } from "./utils/speech-stream.js";
|
|
9
|
+
const route = MediaProtocol.identity({ id: "elevenlabs-speech", name: "ElevenLabs", provider: "elevenlabs" });
|
|
10
|
+
export const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
11
|
+
export const PATH = "/v1/text-to-speech";
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// 3. Streaming event schema
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const Alignment = Schema.Struct({
|
|
16
|
+
characters: Schema.Array(Schema.String),
|
|
17
|
+
character_start_times_seconds: Schema.Array(Schema.Number),
|
|
18
|
+
character_end_times_seconds: Schema.Array(Schema.Number),
|
|
19
|
+
});
|
|
20
|
+
const TimestampedAudio = Schema.Struct({
|
|
21
|
+
audio_base64: Schema.Uint8ArrayFromBase64,
|
|
22
|
+
alignment: optionalNull(Alignment),
|
|
23
|
+
});
|
|
24
|
+
const decodeRecord = route.decodeFrame(TimestampedAudio);
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// 5. Request body construction
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
const OUTPUT_FORMATS = {
|
|
29
|
+
mp3: "mp3_44100_128",
|
|
30
|
+
pcm: "pcm_24000",
|
|
31
|
+
wav: "wav_24000",
|
|
32
|
+
opus: "opus_48000_64",
|
|
33
|
+
};
|
|
34
|
+
/** WAV is served only by the non-streaming endpoints. */
|
|
35
|
+
const outputFormat = Effect.fnUntraced(function* (request) {
|
|
36
|
+
const format = request.providerOptions?.outputFormat ?? OUTPUT_FORMATS[request.format ?? "mp3"];
|
|
37
|
+
if (format === undefined)
|
|
38
|
+
return yield* route.unsupported("media.format", `${route.name} has no default output format for "${request.format}"; pass providerOptions.outputFormat`);
|
|
39
|
+
if (request.mode === "stream" && format.startsWith("wav_"))
|
|
40
|
+
return yield* route.unsupported("media.format", `${route.name} streams mp3, pcm, opus, ulaw, and alaw but not "${format}"; use generate for WAV`);
|
|
41
|
+
return format;
|
|
42
|
+
});
|
|
43
|
+
const fromRequest = Effect.fn("ElevenLabsSpeech.fromRequest")(function* (request) {
|
|
44
|
+
if (request.voice === undefined)
|
|
45
|
+
return yield* ProviderShared.invalidRequest(`${route.name} requires a voice id; pass it as \`voice\``);
|
|
46
|
+
const { outputFormat: _outputFormat, ...native } = request.providerOptions ?? {};
|
|
47
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
48
|
+
text: request.text,
|
|
49
|
+
model_id: request.model.id,
|
|
50
|
+
language_code: request.language,
|
|
51
|
+
voice_settings: request.speed === undefined ? undefined : { speed: request.speed },
|
|
52
|
+
}, native, request.http?.body) ?? {}, { output_format: yield* outputFormat(request) });
|
|
53
|
+
});
|
|
54
|
+
const path = (request) => `${PATH}/${encodeURIComponent(SpeechStream.voiceID(request.voice) ?? "")}${request.mode === "stream" ? "/stream" : ""}${request.timestamps === true ? "/with-timestamps" : ""}`;
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// 6. Stream parsing
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
const onRecord = Effect.fnUntraced(function* (state, frame) {
|
|
59
|
+
const record = yield* decodeRecord(frame);
|
|
60
|
+
const [next, events] = SpeechStream.delta(state, record.audio_base64);
|
|
61
|
+
const alignment = record.alignment;
|
|
62
|
+
if (!alignment)
|
|
63
|
+
return [next, events];
|
|
64
|
+
return [
|
|
65
|
+
next,
|
|
66
|
+
[
|
|
67
|
+
...events,
|
|
68
|
+
...SpeechStream.timestamps(alignment.characters, alignment.character_start_times_seconds, alignment.character_end_times_seconds),
|
|
69
|
+
],
|
|
70
|
+
];
|
|
71
|
+
});
|
|
72
|
+
const PCM_CODECS = {
|
|
73
|
+
pcm: "pcm_s16le",
|
|
74
|
+
ulaw: "pcm_mulaw",
|
|
75
|
+
alaw: "pcm_alaw",
|
|
76
|
+
};
|
|
77
|
+
const describeOutput = (format) => {
|
|
78
|
+
const [codec = format, rate] = format.split("_");
|
|
79
|
+
const sampleRate = rate === undefined ? undefined : Number(rate);
|
|
80
|
+
const encoding = PCM_CODECS[codec];
|
|
81
|
+
return encoding === undefined ? SpeechStream.container(codec, sampleRate) : SpeechStream.pcm(encoding, sampleRate);
|
|
82
|
+
};
|
|
83
|
+
const finish = Effect.fnUntraced(function* (state, context) {
|
|
84
|
+
const requestID = context.http.headers["request-id"];
|
|
85
|
+
return yield* SpeechStream.finish(route, state, {
|
|
86
|
+
...describeOutput(yield* outputFormat(context.request)),
|
|
87
|
+
// `character-cost` is billed credits, not a character count (3 for 20 characters on `eleven_flash_v2_5`).
|
|
88
|
+
usage: SpeechStream.headerUsage("credits", context.http.headers["character-cost"]),
|
|
89
|
+
providerMetadata: requestID === undefined ? undefined : { elevenlabs: { requestId: requestID } },
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// 7. Protocol and route
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
export const protocol = MediaProtocol.stream(route, {
|
|
96
|
+
unsupported: ["instructions"],
|
|
97
|
+
body: { from: fromRequest },
|
|
98
|
+
frames: (bytes, context) => {
|
|
99
|
+
if (context.request.timestamps !== true)
|
|
100
|
+
return bytes;
|
|
101
|
+
return context.request.mode === "stream" ? Framing.lines.frame(bytes) : Framing.document.frame(bytes);
|
|
102
|
+
},
|
|
103
|
+
initial: () => ({ chunks: [] }),
|
|
104
|
+
step: SpeechStream.step(onRecord),
|
|
105
|
+
finish,
|
|
106
|
+
});
|
|
107
|
+
export const model = (input) => SpeechModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: ({ request }) => path(request) }, input);
|
|
108
|
+
export const ElevenLabsSpeech = {
|
|
109
|
+
protocol,
|
|
110
|
+
model,
|
|
111
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
|
+
import { MediaRoute } from "../route/media.js";
|
|
3
|
+
import { type OpenString } from "../schema/index.js";
|
|
4
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
6
|
+
export declare const PATH = "/v1/speech-to-text";
|
|
7
|
+
export type ElevenLabsTranscriptionOptions = {
|
|
8
|
+
readonly tag_audio_events?: boolean;
|
|
9
|
+
readonly timestamps_granularity?: OpenString<"none" | "word" | "character">;
|
|
10
|
+
readonly diarization_threshold?: number;
|
|
11
|
+
readonly file_format?: OpenString<"pcm_s16le_16" | "other">;
|
|
12
|
+
readonly temperature?: number;
|
|
13
|
+
readonly seed?: number;
|
|
14
|
+
readonly keyterms?: ReadonlyArray<string>;
|
|
15
|
+
readonly no_verbatim?: boolean;
|
|
16
|
+
readonly detect_speaker_roles?: boolean;
|
|
17
|
+
readonly use_speaker_library?: boolean;
|
|
18
|
+
readonly entity_detection?: string | ReadonlyArray<string>;
|
|
19
|
+
readonly entity_redaction?: string | ReadonlyArray<string>;
|
|
20
|
+
readonly entity_redaction_mode?: OpenString<"redacted" | "entity_type" | "enumerated_entity_type">;
|
|
21
|
+
} & Record<string, unknown>;
|
|
22
|
+
export type Request = TranscriptionRequest<TranscriptionModel<ElevenLabsTranscriptionOptions>>;
|
|
23
|
+
export declare const protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
24
|
+
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<ElevenLabsTranscriptionOptions>;
|
|
25
|
+
export declare const ElevenLabsTranscription: {
|
|
26
|
+
readonly protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
27
|
+
readonly model: typeof model;
|
|
28
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
5
|
+
import { TranscriptionModel, TranscriptionResponse } from "../transcription.js";
|
|
6
|
+
import { mediaTypeExtension } from "../utils/media-type.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
9
|
+
import { SpeakerTurns } from "./utils/speaker-turns.js";
|
|
10
|
+
const route = MediaProtocol.identity({
|
|
11
|
+
id: "elevenlabs-transcription",
|
|
12
|
+
name: "ElevenLabs Transcription",
|
|
13
|
+
provider: "elevenlabs",
|
|
14
|
+
});
|
|
15
|
+
export const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
16
|
+
export const PATH = "/v1/speech-to-text";
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// 2. Response schema
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/** `type` is `word`, `spacing` (the whitespace between words), or `audio_event` (`(laughter)`). */
|
|
21
|
+
const Token = Schema.Struct({
|
|
22
|
+
text: Schema.String,
|
|
23
|
+
type: Schema.String,
|
|
24
|
+
start: optionalNull(Schema.Number),
|
|
25
|
+
end: optionalNull(Schema.Number),
|
|
26
|
+
speaker_id: optionalNull(Schema.String),
|
|
27
|
+
logprob: optionalNull(Schema.Number),
|
|
28
|
+
});
|
|
29
|
+
const Transcript = Schema.Struct({
|
|
30
|
+
language_code: optionalNull(Schema.String),
|
|
31
|
+
text: Schema.String,
|
|
32
|
+
words: optionalNull(Schema.Array(Token)),
|
|
33
|
+
transcription_id: optionalNull(Schema.String),
|
|
34
|
+
audio_duration_secs: optionalNull(Schema.Number),
|
|
35
|
+
});
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// 5. Request body construction
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
/** Speaker turns are the only segments ElevenLabs can produce, and `num_speakers` only applies to diarization. */
|
|
40
|
+
const diarizes = (request) => request.diarize === true || request.timestamps === "segment" || request.speakers !== undefined;
|
|
41
|
+
const RESERVED_FORM_FIELDS = new Set([
|
|
42
|
+
"file",
|
|
43
|
+
"cloud_storage_url",
|
|
44
|
+
"source_url",
|
|
45
|
+
"model_id",
|
|
46
|
+
"language_code",
|
|
47
|
+
"diarize",
|
|
48
|
+
"num_speakers",
|
|
49
|
+
]);
|
|
50
|
+
const validate = (request, overlay) => {
|
|
51
|
+
// Webhook requests return 202 with no transcript; the result arrives at a configured webhook instead.
|
|
52
|
+
if (overlay.webhook === true)
|
|
53
|
+
return Effect.fail(route.unsupported("transcription.webhook", `${route.name} does not deliver to webhooks`));
|
|
54
|
+
// Separate multichannel output replaces the transcript with one transcript per channel.
|
|
55
|
+
if (overlay.use_multi_channel === true && overlay.multichannel_output_style !== "combined")
|
|
56
|
+
return Effect.fail(route.unsupported("transcription.multichannel", `${route.name} returns a single transcript; set multichannel_output_style: "combined" to merge channels`));
|
|
57
|
+
if (overlay.timestamps_granularity === "none" && (request.timestamps === "word" || diarizes(request)))
|
|
58
|
+
return Effect.fail(route.unsupported("media.timestamps", `${route.name} cannot return word timestamps or speaker turns with timestamps_granularity: "none"`));
|
|
59
|
+
return Effect.void;
|
|
60
|
+
};
|
|
61
|
+
const fromRequest = Effect.fn("ElevenLabsTranscription.fromRequest")(function* (request) {
|
|
62
|
+
const overlay = mergeJsonRecords(request.providerOptions, request.http?.body) ?? {};
|
|
63
|
+
yield* validate(request, overlay);
|
|
64
|
+
const form = new FormData();
|
|
65
|
+
const url = ProviderShared.mediaUrl(request.audio);
|
|
66
|
+
if (url === undefined) {
|
|
67
|
+
const extension = mediaTypeExtension(request.audio.mediaType);
|
|
68
|
+
const audio = yield* MediaInput.inlineBytes(route.id, request.audio);
|
|
69
|
+
form.append("file", MediaInput.blob(audio, request.audio.mediaType), extension === undefined ? "audio" : `audio.${extension}`);
|
|
70
|
+
}
|
|
71
|
+
MediaInput.appendFields(form, {
|
|
72
|
+
model_id: request.model.id,
|
|
73
|
+
// `cloud_storage_url` is deprecated in favor of `source_url`, which accepts any hosted audio or video URL.
|
|
74
|
+
source_url: url,
|
|
75
|
+
language_code: request.language,
|
|
76
|
+
diarize: diarizes(request) ? true : undefined,
|
|
77
|
+
num_speakers: request.speakers,
|
|
78
|
+
}, { overlay, reserved: RESERVED_FORM_FIELDS, repeatArrays: "key" });
|
|
79
|
+
return MediaProtocol.multipart(form);
|
|
80
|
+
});
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// 6. Response decoding
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
const decodeTranscript = route.decodeJson(Transcript);
|
|
85
|
+
const isTimedWord = (token) => token.type === "word" && typeof token.start === "number" && typeof token.end === "number";
|
|
86
|
+
/** Turn text keeps the provider's own spacing tokens, so languages written without spaces are not re-spaced. */
|
|
87
|
+
const speakerTurns = (tokens) => SpeakerTurns.group(tokens.filter((token) => token.type === "word" || token.type === "spacing"), (token) => token.speaker_id).flatMap((turn) => {
|
|
88
|
+
const words = turn.filter(isTimedWord);
|
|
89
|
+
if (words.length === 0)
|
|
90
|
+
return [];
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
text: turn
|
|
94
|
+
.map((token) => token.text)
|
|
95
|
+
.join("")
|
|
96
|
+
.trim(),
|
|
97
|
+
startSeconds: words[0].start,
|
|
98
|
+
endSeconds: words[words.length - 1].end,
|
|
99
|
+
speaker: turn[0].speaker_id ?? undefined,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
});
|
|
103
|
+
const decodeResponse = Effect.fn("ElevenLabsTranscription.decodeResponse")(function* (response, context) {
|
|
104
|
+
const output = yield* decodeTranscript(response);
|
|
105
|
+
const transcript = output.value;
|
|
106
|
+
const tokens = transcript.words ?? [];
|
|
107
|
+
const duration = transcript.audio_duration_secs ?? undefined;
|
|
108
|
+
const transcriptionID = transcript.transcription_id ?? undefined;
|
|
109
|
+
return new TranscriptionResponse({
|
|
110
|
+
text: transcript.text,
|
|
111
|
+
segments: diarizes(context.request) ? speakerTurns(tokens) : undefined,
|
|
112
|
+
words: tokens.filter(isTimedWord).map((word) => ({
|
|
113
|
+
text: word.text,
|
|
114
|
+
startSeconds: word.start,
|
|
115
|
+
endSeconds: word.end,
|
|
116
|
+
speaker: word.speaker_id ?? undefined,
|
|
117
|
+
confidence: typeof word.logprob === "number" ? Math.exp(word.logprob) : undefined,
|
|
118
|
+
})),
|
|
119
|
+
language: transcript.language_code?.toLowerCase(),
|
|
120
|
+
durationSeconds: duration,
|
|
121
|
+
usage: duration === undefined ? undefined : { type: "seconds", seconds: duration },
|
|
122
|
+
providerMetadata: transcriptionID === undefined ? undefined : { elevenlabs: { transcriptionId: transcriptionID } },
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// 7. Protocol and route
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
129
|
+
unsupported: ["prompt"],
|
|
130
|
+
body: { from: fromRequest },
|
|
131
|
+
response: { decode: decodeResponse },
|
|
132
|
+
});
|
|
133
|
+
export const model = (input) => TranscriptionModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
134
|
+
export const ElevenLabsTranscription = {
|
|
135
|
+
protocol,
|
|
136
|
+
model,
|
|
137
|
+
};
|