@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,198 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ModelID, ProviderID } from "./ids.js";
|
|
3
|
+
import { isRecord } from "../utils/record.js";
|
|
4
|
+
export const JsonSchema = Schema.Record(Schema.String, Schema.Unknown);
|
|
5
|
+
export const mergeJsonRecords = (...items) => {
|
|
6
|
+
const defined = items.filter((item) => item !== undefined);
|
|
7
|
+
if (defined.length === 0)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (defined.length === 1 && Object.values(defined[0]).every((value) => value !== undefined))
|
|
10
|
+
return defined[0];
|
|
11
|
+
const result = {};
|
|
12
|
+
for (const item of defined) {
|
|
13
|
+
for (const [key, value] of Object.entries(item)) {
|
|
14
|
+
if (value === undefined)
|
|
15
|
+
continue;
|
|
16
|
+
result[key] = isRecord(result[key]) && isRecord(value) ? mergeJsonRecords(result[key], value) : value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
20
|
+
};
|
|
21
|
+
const mergeStringRecords = (...items) => {
|
|
22
|
+
const defined = items.filter((item) => item !== undefined);
|
|
23
|
+
if (defined.length === 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (defined.length === 1)
|
|
26
|
+
return defined[0];
|
|
27
|
+
const result = Object.fromEntries(defined.flatMap((item) => Object.entries(item).filter((entry) => entry[1] !== undefined)));
|
|
28
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
29
|
+
};
|
|
30
|
+
export const ProviderOptions = Schema.Record(Schema.String, Schema.Unknown);
|
|
31
|
+
export const ProviderMetadata = Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown)).annotate({
|
|
32
|
+
identifier: "AI.ProviderMetadata",
|
|
33
|
+
});
|
|
34
|
+
export const mergeProviderOptions = (...items) => mergeJsonRecords(...items);
|
|
35
|
+
/** Milliseconds for an HTTP timeout, or `false` to disable it. */
|
|
36
|
+
export const HttpTimeout = Schema.Union([Schema.Number.check(Schema.isGreaterThan(0)), Schema.Literal(false)]);
|
|
37
|
+
/** Applied to `timeout.headers` when a request leaves it unset. */
|
|
38
|
+
export const DEFAULT_HTTP_TIMEOUT_MS = 300_000;
|
|
39
|
+
/**
|
|
40
|
+
* Applied to `timeout.chunk` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
|
|
41
|
+
* clients to allow at least 15 minutes, because their models can stream nothing for minutes while they reason.
|
|
42
|
+
*/
|
|
43
|
+
export const DEFAULT_CHUNK_TIMEOUT_MS = 900_000;
|
|
44
|
+
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
|
|
45
|
+
export const RequestEncoding = Schema.Literals(["zstd", "gzip", "none"]);
|
|
46
|
+
export const timeoutConfig = (timeout) => typeof timeout === "object" ? timeout : { total: timeout };
|
|
47
|
+
const last = (values) => values.findLast((value) => value !== undefined);
|
|
48
|
+
const someDefined = (value) => Object.values(value).some((item) => item !== undefined) ? value : undefined;
|
|
49
|
+
/** Merge transport settings; later items win, headers, query and body merge by key. */
|
|
50
|
+
export const mergeTransport = (...items) => {
|
|
51
|
+
const http = items.map((item) => item?.http);
|
|
52
|
+
const timeouts = http.map((item) => timeoutConfig(item?.timeout));
|
|
53
|
+
return {
|
|
54
|
+
http: someDefined({
|
|
55
|
+
headers: mergeStringRecords(...http.map((item) => item?.headers)),
|
|
56
|
+
timeout: someDefined({
|
|
57
|
+
total: last(timeouts.map((item) => item.total)),
|
|
58
|
+
headers: last(timeouts.map((item) => item.headers)),
|
|
59
|
+
chunk: last(timeouts.map((item) => item.chunk)),
|
|
60
|
+
}),
|
|
61
|
+
query: mergeStringRecords(...http.map((item) => item?.query)),
|
|
62
|
+
body: mergeJsonRecords(...http.map((item) => item?.body)),
|
|
63
|
+
encoding: last(http.map((item) => item?.encoding)),
|
|
64
|
+
tls: last(http.map((item) => item?.tls)),
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/** Portable sampling knobs, set at the top level of text requests, model defaults and route defaults. */
|
|
69
|
+
export const GenerationOptions = Schema.Struct({
|
|
70
|
+
maxTokens: Schema.optionalKey(Schema.Number),
|
|
71
|
+
temperature: Schema.optionalKey(Schema.Number),
|
|
72
|
+
topP: Schema.optionalKey(Schema.Number),
|
|
73
|
+
topK: Schema.optionalKey(Schema.Number),
|
|
74
|
+
frequencyPenalty: Schema.optionalKey(Schema.Number),
|
|
75
|
+
presencePenalty: Schema.optionalKey(Schema.Number),
|
|
76
|
+
seed: Schema.optionalKey(Schema.Number),
|
|
77
|
+
stop: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
78
|
+
});
|
|
79
|
+
/** Pick the generation knobs out of each item; later items win per knob. */
|
|
80
|
+
export const mergeGeneration = (...items) => Object.fromEntries(Object.keys(GenerationOptions.fields).map((key) => [
|
|
81
|
+
key,
|
|
82
|
+
last(items.map((item) => item?.[key])),
|
|
83
|
+
]));
|
|
84
|
+
/** Merge model options; later items win per key. Empty results are `undefined`. */
|
|
85
|
+
export const mergeRequestOptions = (...items) => {
|
|
86
|
+
const merged = Object.entries({
|
|
87
|
+
...mergeTransport(...items),
|
|
88
|
+
...mergeGeneration(...items),
|
|
89
|
+
providerOptions: mergeProviderOptions(...items.map((item) => item?.providerOptions)),
|
|
90
|
+
}).filter(([, value]) => value !== undefined);
|
|
91
|
+
return merged.length === 0 ? undefined : Object.fromEntries(merged);
|
|
92
|
+
};
|
|
93
|
+
export const ReasoningEfforts = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
94
|
+
export const ReasoningEffort = Schema.declare((value) => typeof value === "string", { title: "ReasoningEffort" });
|
|
95
|
+
/** Tool schema sanitizer for a model family. `none` opts out of the protocol and model-name defaults. */
|
|
96
|
+
export const LanguageModelSanitizerCompatibility = Schema.Literals(["gemini", "moonshot", "none"]);
|
|
97
|
+
export const LanguageModelMaxTokensFieldCompatibility = Schema.Literals(["max_completion_tokens", "max_tokens"]);
|
|
98
|
+
export const LanguageModelCacheFormatCompatibility = Schema.Literals(["anthropic", "alibaba"]);
|
|
99
|
+
export class LanguageModelCompatibility extends Schema.Class("AI.LanguageModelCompatibility")({
|
|
100
|
+
sanitizer: Schema.optional(LanguageModelSanitizerCompatibility),
|
|
101
|
+
reasoningField: Schema.optional(Schema.String),
|
|
102
|
+
/** Require every assistant message to include its reasoning field, even when empty. */
|
|
103
|
+
requireReasoning: Schema.optional(Schema.Boolean),
|
|
104
|
+
maxTokensField: Schema.optional(LanguageModelMaxTokensFieldCompatibility),
|
|
105
|
+
requireFinishReason: Schema.optional(Schema.Boolean),
|
|
106
|
+
requireAssistantAfterTool: Schema.optional(Schema.Boolean),
|
|
107
|
+
/** Prompt-cache marker syntax the endpoint accepts. Overrides the route default; both send `cache_control`, and `alibaba` skips tool definitions. */
|
|
108
|
+
cacheFormat: Schema.optional(LanguageModelCacheFormatCompatibility),
|
|
109
|
+
zaiToolStream: Schema.optional(Schema.Boolean),
|
|
110
|
+
requireSignature: Schema.optional(Schema.Boolean),
|
|
111
|
+
/** Supports Anthropic's thinking-prefix mismatch controls. Overrides model-ID detection. */
|
|
112
|
+
supportsThinkingBlockBinding: Schema.optional(Schema.Boolean),
|
|
113
|
+
}) {
|
|
114
|
+
}
|
|
115
|
+
(function (LanguageModelCompatibility) {
|
|
116
|
+
/** Normalize model/upstream compatibility metadata without projecting requests. */
|
|
117
|
+
LanguageModelCompatibility.make = (input) => input instanceof LanguageModelCompatibility ? input : new LanguageModelCompatibility(input);
|
|
118
|
+
})(LanguageModelCompatibility || (LanguageModelCompatibility = {}));
|
|
119
|
+
export class LanguageModel {
|
|
120
|
+
id;
|
|
121
|
+
provider;
|
|
122
|
+
route;
|
|
123
|
+
options;
|
|
124
|
+
capabilities;
|
|
125
|
+
compatibility;
|
|
126
|
+
constructor(input) {
|
|
127
|
+
this.id = input.id;
|
|
128
|
+
this.provider = input.provider;
|
|
129
|
+
this.route = input.route;
|
|
130
|
+
this.options = input.options;
|
|
131
|
+
this.capabilities = input.capabilities;
|
|
132
|
+
this.compatibility = input.compatibility;
|
|
133
|
+
}
|
|
134
|
+
static make(input) {
|
|
135
|
+
return new LanguageModel({
|
|
136
|
+
id: ModelID.make(input.id),
|
|
137
|
+
provider: ProviderID.make(input.provider),
|
|
138
|
+
route: input.route,
|
|
139
|
+
// The route's options are a preset under the model's own.
|
|
140
|
+
options: mergeRequestOptions(input.route.options, input.options),
|
|
141
|
+
capabilities: input.capabilities,
|
|
142
|
+
compatibility: input.compatibility === undefined ? undefined : LanguageModelCompatibility.make(input.compatibility),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
static input(model) {
|
|
146
|
+
return {
|
|
147
|
+
id: model.id,
|
|
148
|
+
provider: model.provider,
|
|
149
|
+
route: model.route,
|
|
150
|
+
options: model.options,
|
|
151
|
+
capabilities: model.capabilities,
|
|
152
|
+
compatibility: model.compatibility,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
static update(model, patch) {
|
|
156
|
+
if (Object.keys(patch).length === 0)
|
|
157
|
+
return model;
|
|
158
|
+
return LanguageModel.make({
|
|
159
|
+
...LanguageModel.input(model),
|
|
160
|
+
...patch,
|
|
161
|
+
route: patch.route ?? model.route,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export const LanguageModelSchema = Schema.declare((value) => value instanceof LanguageModel, {
|
|
166
|
+
expected: "AI.LanguageModel",
|
|
167
|
+
});
|
|
168
|
+
// Provider cache lifetime such as "5m", "30m", "1h" or "24h", in models.dev's duration format. It is sent as given;
|
|
169
|
+
// each provider accepts its own set, and omitting it keeps the provider default.
|
|
170
|
+
export const CacheTTL = Schema.TemplateLiteral([Schema.Number, Schema.Literals(["ms", "s", "m", "h", "d"])]).check(Schema.isPattern(/^\d+(ms|s|m|h|d)$/));
|
|
171
|
+
export class CacheHint extends Schema.Class("AI.CacheHint")({
|
|
172
|
+
type: Schema.Literals(["ephemeral", "persistent"]),
|
|
173
|
+
ttl: Schema.optional(CacheTTL),
|
|
174
|
+
}) {
|
|
175
|
+
}
|
|
176
|
+
// Auto-placement policy for prompt caching. The protocol-neutral lowering step
|
|
177
|
+
// reads this and injects `CacheHint`s at the configured boundaries; the
|
|
178
|
+
// per-protocol body builders then translate those hints into wire markers as
|
|
179
|
+
// usual. `"auto"` is the default for agent loops — it places
|
|
180
|
+
// breakpoints at the last tool definition, the first and last distinct system
|
|
181
|
+
// parts, and the conversation tail so recent prefixes remain reusable during
|
|
182
|
+
// tool loops.
|
|
183
|
+
//
|
|
184
|
+
// Pass `"none"` to opt out entirely (the legacy behavior). Pass the granular
|
|
185
|
+
// object form to choose placements exactly; an object with only `ttl` keeps
|
|
186
|
+
// the automatic placements and sets their lifetime. Routes without inline
|
|
187
|
+
// markers send `ttl` as a request-level cache option where one exists.
|
|
188
|
+
export const CachePolicyObject = Schema.Struct({
|
|
189
|
+
tools: Schema.optional(Schema.Boolean),
|
|
190
|
+
system: Schema.optional(Schema.Boolean),
|
|
191
|
+
messages: Schema.optional(Schema.Union([
|
|
192
|
+
Schema.Literal("latest-user-message"),
|
|
193
|
+
Schema.Literal("latest-assistant"),
|
|
194
|
+
Schema.Struct({ tail: Schema.Natural }),
|
|
195
|
+
])),
|
|
196
|
+
ttl: Schema.optional(CacheTTL),
|
|
197
|
+
});
|
|
198
|
+
export const CachePolicy = Schema.Union([Schema.Literal("auto"), Schema.Literal("none"), CachePolicyObject]);
|
package/dist/speech.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { Effect, Schema, Stream } from "effect";
|
|
2
|
+
import { Media } from "./media.js";
|
|
3
|
+
import { MediaModel } from "./media-model.js";
|
|
4
|
+
import { MediaRoute } from "./route/media.js";
|
|
5
|
+
import { AIError, type OpenString, type BaseRequest } from "./schema/index.js";
|
|
6
|
+
import { AI } from "./ai.js";
|
|
7
|
+
export type SpeechOptions = MediaModel.Options;
|
|
8
|
+
export type SpeechRoute = MediaRoute.AnyRoute<SpeechRequest, SpeechEvent, SpeechResponse>;
|
|
9
|
+
export declare class SpeechModel<Options extends SpeechOptions = SpeechOptions> extends MediaModel<SpeechRoute, Options> {
|
|
10
|
+
protected readonly _SpeechModel: void;
|
|
11
|
+
/** The number of type arguments selects the kind: `<Options>`, `<Options, Frame, State>`, or `<Options, Token>`. */
|
|
12
|
+
static fromRoute<Options extends SpeechOptions>(route: MediaModel.InlineRouteInput<SpeechRequest<SpeechModel<Options>>, SpeechResponse>, input: MediaRoute.ModelInput): SpeechModel<Options>;
|
|
13
|
+
static fromRoute<Options extends SpeechOptions, Frame, State>(route: MediaModel.StreamRouteInput<SpeechRequest<SpeechModel<Options>>, SpeechEvent, Frame, State>, input: MediaRoute.ModelInput): SpeechModel<Options>;
|
|
14
|
+
static fromRoute<Options extends SpeechOptions, Token>(route: MediaModel.QueuedRouteInput<SpeechRequest<SpeechModel<Options>>, SpeechResponse, Token>, input: MediaRoute.ModelInput): SpeechModel<Options>;
|
|
15
|
+
}
|
|
16
|
+
export declare const SpeechModelSchema: Schema.declare<SpeechModel<{
|
|
17
|
+
readonly [x: string]: unknown;
|
|
18
|
+
}>, SpeechModel<{
|
|
19
|
+
readonly [x: string]: unknown;
|
|
20
|
+
}>>;
|
|
21
|
+
/** Provider-native: a name on OpenAI and Gemini, a voice id on ElevenLabs and Cartesia; `{ id }` is an OpenAI custom voice. */
|
|
22
|
+
export declare const SpeechVoice: Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
23
|
+
readonly id: Schema.String;
|
|
24
|
+
}>]>;
|
|
25
|
+
export type SpeechVoice = Schema.Schema.Type<typeof SpeechVoice>;
|
|
26
|
+
export type SpeechFormat = OpenString<"mp3" | "wav" | "pcm" | "opus" | "aac" | "flac">;
|
|
27
|
+
/** Granularity is provider-native: characters on ElevenLabs, words on Cartesia. */
|
|
28
|
+
export declare const SpeechTimestamp: Schema.Struct<{
|
|
29
|
+
readonly text: Schema.String;
|
|
30
|
+
readonly startSeconds: Schema.Number;
|
|
31
|
+
readonly endSeconds: Schema.Number;
|
|
32
|
+
}>;
|
|
33
|
+
export type SpeechTimestamp = Schema.Schema.Type<typeof SpeechTimestamp>;
|
|
34
|
+
declare const SpeechRequestSchema: Schema.Struct<{
|
|
35
|
+
readonly model: Schema.declare<SpeechModel<{
|
|
36
|
+
readonly [x: string]: unknown;
|
|
37
|
+
}>, SpeechModel<{
|
|
38
|
+
readonly [x: string]: unknown;
|
|
39
|
+
}>>;
|
|
40
|
+
readonly text: Schema.String;
|
|
41
|
+
readonly voice: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
42
|
+
readonly id: Schema.String;
|
|
43
|
+
}>]>>;
|
|
44
|
+
readonly format: Schema.optional<Schema.String>;
|
|
45
|
+
readonly speed: Schema.optional<Schema.Number>;
|
|
46
|
+
readonly language: Schema.optional<Schema.String>;
|
|
47
|
+
readonly instructions: Schema.optional<Schema.String>;
|
|
48
|
+
readonly timestamps: Schema.optional<Schema.Boolean>;
|
|
49
|
+
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
50
|
+
}>;
|
|
51
|
+
/** A normalized speech request, the plain object `Speech.request(...)` returns. */
|
|
52
|
+
export type SpeechRequest<Model extends SpeechModel = SpeechModel> = Omit<typeof SpeechRequestSchema.Type, "model" | "providerOptions" | "format"> & BaseRequest<Model, SpeechModelOptions<Model>> & {
|
|
53
|
+
readonly format?: SpeechFormat;
|
|
54
|
+
};
|
|
55
|
+
export type SpeechModelOptions<Model> = Model extends SpeechModel<infer Options> ? Options : never;
|
|
56
|
+
/** Input accepted by `Speech.request` and the calls; a `SpeechRequest` is also a valid input. */
|
|
57
|
+
export type SpeechRequestInput<Model extends SpeechModel = SpeechModel> = Omit<SpeechRequest<Model>, "providerOptions"> & {
|
|
58
|
+
readonly providerOptions?: NoInfer<SpeechModelOptions<Model>>;
|
|
59
|
+
};
|
|
60
|
+
declare const SpeechResponse_base: Schema.Class<SpeechResponse, Schema.Struct<{
|
|
61
|
+
/** The complete audio. Headerless PCM carries `info.encoding`, `info.sampleRate`, and `info.channels`. */
|
|
62
|
+
readonly audio: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
63
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Literal<"bytes">;
|
|
65
|
+
readonly data: Schema.Uint8Array;
|
|
66
|
+
readonly mediaType: Schema.String;
|
|
67
|
+
}>, Schema.Struct<{
|
|
68
|
+
readonly type: Schema.Literal<"base64">;
|
|
69
|
+
readonly data: Schema.String;
|
|
70
|
+
readonly mediaType: Schema.String;
|
|
71
|
+
}>, Schema.Struct<{
|
|
72
|
+
readonly type: Schema.Literal<"url">;
|
|
73
|
+
readonly url: Schema.String;
|
|
74
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
75
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
76
|
+
}>, Schema.Struct<{
|
|
77
|
+
readonly type: Schema.Literal<"ref">;
|
|
78
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
79
|
+
readonly id: Schema.String;
|
|
80
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
81
|
+
}>]>;
|
|
82
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
83
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
84
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
85
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
86
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
87
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
88
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
89
|
+
readonly format: Schema.optional<Schema.String>;
|
|
90
|
+
}>>;
|
|
91
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
92
|
+
}>, never, never>;
|
|
93
|
+
readonly timestamps: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
94
|
+
readonly text: Schema.String;
|
|
95
|
+
readonly startSeconds: Schema.Number;
|
|
96
|
+
readonly endSeconds: Schema.Number;
|
|
97
|
+
}>>>;
|
|
98
|
+
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
99
|
+
readonly type: Schema.Literal<"tokens">;
|
|
100
|
+
readonly input: Schema.optional<Schema.Number>;
|
|
101
|
+
readonly output: Schema.optional<Schema.Number>;
|
|
102
|
+
readonly total: Schema.optional<Schema.Number>;
|
|
103
|
+
readonly details: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
104
|
+
}>, Schema.Struct<{
|
|
105
|
+
readonly type: Schema.Literal<"seconds">;
|
|
106
|
+
readonly seconds: Schema.Number;
|
|
107
|
+
}>, Schema.Struct<{
|
|
108
|
+
readonly type: Schema.Literal<"characters">;
|
|
109
|
+
readonly characters: Schema.Number;
|
|
110
|
+
}>, Schema.Struct<{
|
|
111
|
+
readonly type: Schema.Literal<"credits">;
|
|
112
|
+
readonly credits: Schema.Number;
|
|
113
|
+
}>, Schema.Struct<{
|
|
114
|
+
readonly type: Schema.Literal<"compute">;
|
|
115
|
+
readonly seconds: Schema.Number;
|
|
116
|
+
}>]>>;
|
|
117
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
118
|
+
}>, {}>;
|
|
119
|
+
export declare class SpeechResponse extends SpeechResponse_base {
|
|
120
|
+
}
|
|
121
|
+
export declare const SpeechAudioDeltaEvent: Schema.Struct<{
|
|
122
|
+
readonly type: Schema.tag<"audio-delta">;
|
|
123
|
+
readonly chunk: Schema.Uint8Array;
|
|
124
|
+
}>;
|
|
125
|
+
export declare const SpeechTimestampsEvent: Schema.Struct<{
|
|
126
|
+
readonly type: Schema.tag<"timestamps">;
|
|
127
|
+
readonly items: Schema.$Array<Schema.Struct<{
|
|
128
|
+
readonly text: Schema.String;
|
|
129
|
+
readonly startSeconds: Schema.Number;
|
|
130
|
+
readonly endSeconds: Schema.Number;
|
|
131
|
+
}>>;
|
|
132
|
+
}>;
|
|
133
|
+
/** `audio` is every `audio-delta` chunk concatenated, so the route holds the whole clip in memory until `finish`. */
|
|
134
|
+
export declare const SpeechFinishEvent: Schema.Struct<{
|
|
135
|
+
readonly type: Schema.tag<"finish">;
|
|
136
|
+
readonly audio: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
137
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
138
|
+
readonly type: Schema.Literal<"bytes">;
|
|
139
|
+
readonly data: Schema.Uint8Array;
|
|
140
|
+
readonly mediaType: Schema.String;
|
|
141
|
+
}>, Schema.Struct<{
|
|
142
|
+
readonly type: Schema.Literal<"base64">;
|
|
143
|
+
readonly data: Schema.String;
|
|
144
|
+
readonly mediaType: Schema.String;
|
|
145
|
+
}>, Schema.Struct<{
|
|
146
|
+
readonly type: Schema.Literal<"url">;
|
|
147
|
+
readonly url: Schema.String;
|
|
148
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
149
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
150
|
+
}>, Schema.Struct<{
|
|
151
|
+
readonly type: Schema.Literal<"ref">;
|
|
152
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
153
|
+
readonly id: Schema.String;
|
|
154
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
155
|
+
}>]>;
|
|
156
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
157
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
158
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
159
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
160
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
161
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
162
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
163
|
+
readonly format: Schema.optional<Schema.String>;
|
|
164
|
+
}>>;
|
|
165
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
166
|
+
}>, never, never>;
|
|
167
|
+
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
168
|
+
readonly type: Schema.Literal<"tokens">;
|
|
169
|
+
readonly input: Schema.optional<Schema.Number>;
|
|
170
|
+
readonly output: Schema.optional<Schema.Number>;
|
|
171
|
+
readonly total: Schema.optional<Schema.Number>;
|
|
172
|
+
readonly details: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
173
|
+
}>, Schema.Struct<{
|
|
174
|
+
readonly type: Schema.Literal<"seconds">;
|
|
175
|
+
readonly seconds: Schema.Number;
|
|
176
|
+
}>, Schema.Struct<{
|
|
177
|
+
readonly type: Schema.Literal<"characters">;
|
|
178
|
+
readonly characters: Schema.Number;
|
|
179
|
+
}>, Schema.Struct<{
|
|
180
|
+
readonly type: Schema.Literal<"credits">;
|
|
181
|
+
readonly credits: Schema.Number;
|
|
182
|
+
}>, Schema.Struct<{
|
|
183
|
+
readonly type: Schema.Literal<"compute">;
|
|
184
|
+
readonly seconds: Schema.Number;
|
|
185
|
+
}>]>>;
|
|
186
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
187
|
+
}>;
|
|
188
|
+
export declare const SpeechEvent: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
189
|
+
readonly type: Schema.tag<"generation-progress">;
|
|
190
|
+
readonly id: Schema.String;
|
|
191
|
+
readonly progress: Schema.optional<Schema.Number>;
|
|
192
|
+
}>, Schema.Struct<{
|
|
193
|
+
readonly type: Schema.tag<"audio-delta">;
|
|
194
|
+
readonly chunk: Schema.Uint8Array;
|
|
195
|
+
}>, Schema.Struct<{
|
|
196
|
+
readonly type: Schema.tag<"timestamps">;
|
|
197
|
+
readonly items: Schema.$Array<Schema.Struct<{
|
|
198
|
+
readonly text: Schema.String;
|
|
199
|
+
readonly startSeconds: Schema.Number;
|
|
200
|
+
readonly endSeconds: Schema.Number;
|
|
201
|
+
}>>;
|
|
202
|
+
}>, Schema.Struct<{
|
|
203
|
+
readonly type: Schema.tag<"finish">;
|
|
204
|
+
readonly audio: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
205
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
206
|
+
readonly type: Schema.Literal<"bytes">;
|
|
207
|
+
readonly data: Schema.Uint8Array;
|
|
208
|
+
readonly mediaType: Schema.String;
|
|
209
|
+
}>, Schema.Struct<{
|
|
210
|
+
readonly type: Schema.Literal<"base64">;
|
|
211
|
+
readonly data: Schema.String;
|
|
212
|
+
readonly mediaType: Schema.String;
|
|
213
|
+
}>, Schema.Struct<{
|
|
214
|
+
readonly type: Schema.Literal<"url">;
|
|
215
|
+
readonly url: Schema.String;
|
|
216
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
217
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
218
|
+
}>, Schema.Struct<{
|
|
219
|
+
readonly type: Schema.Literal<"ref">;
|
|
220
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
221
|
+
readonly id: Schema.String;
|
|
222
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
223
|
+
}>]>;
|
|
224
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
225
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
226
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
227
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
228
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
229
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
230
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
231
|
+
readonly format: Schema.optional<Schema.String>;
|
|
232
|
+
}>>;
|
|
233
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
234
|
+
}>, never, never>;
|
|
235
|
+
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
236
|
+
readonly type: Schema.Literal<"tokens">;
|
|
237
|
+
readonly input: Schema.optional<Schema.Number>;
|
|
238
|
+
readonly output: Schema.optional<Schema.Number>;
|
|
239
|
+
readonly total: Schema.optional<Schema.Number>;
|
|
240
|
+
readonly details: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
241
|
+
}>, Schema.Struct<{
|
|
242
|
+
readonly type: Schema.Literal<"seconds">;
|
|
243
|
+
readonly seconds: Schema.Number;
|
|
244
|
+
}>, Schema.Struct<{
|
|
245
|
+
readonly type: Schema.Literal<"characters">;
|
|
246
|
+
readonly characters: Schema.Number;
|
|
247
|
+
}>, Schema.Struct<{
|
|
248
|
+
readonly type: Schema.Literal<"credits">;
|
|
249
|
+
readonly credits: Schema.Number;
|
|
250
|
+
}>, Schema.Struct<{
|
|
251
|
+
readonly type: Schema.Literal<"compute">;
|
|
252
|
+
readonly seconds: Schema.Number;
|
|
253
|
+
}>]>>;
|
|
254
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
255
|
+
}>]>;
|
|
256
|
+
export type SpeechEvent = Schema.Schema.Type<typeof SpeechEvent>;
|
|
257
|
+
/** Normalize speech request input into a plain `SpeechRequest`. */
|
|
258
|
+
export declare const request: <const Model extends SpeechModel>(input: SpeechRequestInput<Model>) => SpeechRequest<Model>;
|
|
259
|
+
export declare function generate<const Model extends SpeechModel>(input: SpeechRequestInput<Model>): Effect.Effect<SpeechResponse, AIError, AI.Service>;
|
|
260
|
+
export declare function stream<const Model extends SpeechModel>(input: SpeechRequestInput<Model>): Stream.Stream<SpeechEvent, AIError, AI.Service>;
|
|
261
|
+
export declare const Speech: {
|
|
262
|
+
readonly request: typeof request;
|
|
263
|
+
readonly generate: typeof generate;
|
|
264
|
+
readonly stream: typeof stream;
|
|
265
|
+
};
|
|
266
|
+
export {};
|
package/dist/speech.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Effect, Schema, Stream } from "effect";
|
|
2
|
+
import { ProgressEvent } from "./generation.js";
|
|
3
|
+
import { Media } from "./media.js";
|
|
4
|
+
import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
|
|
5
|
+
import { MediaRoute } from "./route/media.js";
|
|
6
|
+
import { AIError, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
7
|
+
import { AI } from "./ai.js";
|
|
8
|
+
export class SpeechModel extends MediaModel {
|
|
9
|
+
static fromRoute(route, input) {
|
|
10
|
+
return new SpeechModel({
|
|
11
|
+
id: input.id,
|
|
12
|
+
provider: route.protocol.provider,
|
|
13
|
+
transport: input.transport,
|
|
14
|
+
providerOptions: input.providerOptions,
|
|
15
|
+
route: composeRoute(route, input, collectResponse),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const SpeechModelSchema = Schema.declare((value) => value instanceof SpeechModel, {
|
|
20
|
+
expected: "Speech.Model",
|
|
21
|
+
});
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Request
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
/** Provider-native: a name on OpenAI and Gemini, a voice id on ElevenLabs and Cartesia; `{ id }` is an OpenAI custom voice. */
|
|
26
|
+
export const SpeechVoice = Schema.Union([Schema.String, Schema.Struct({ id: Schema.String })]).annotate({
|
|
27
|
+
identifier: "Speech.Voice",
|
|
28
|
+
});
|
|
29
|
+
/** Granularity is provider-native: characters on ElevenLabs, words on Cartesia. */
|
|
30
|
+
export const SpeechTimestamp = Schema.Struct({
|
|
31
|
+
text: Schema.String,
|
|
32
|
+
startSeconds: Schema.Number,
|
|
33
|
+
endSeconds: Schema.Number,
|
|
34
|
+
}).annotate({ identifier: "Speech.Timestamp" });
|
|
35
|
+
const SpeechRequestSchema = Schema.Struct({
|
|
36
|
+
model: SpeechModelSchema,
|
|
37
|
+
text: Schema.String,
|
|
38
|
+
voice: Schema.optional(SpeechVoice),
|
|
39
|
+
format: Schema.optional(Schema.String),
|
|
40
|
+
speed: Schema.optional(Schema.Number),
|
|
41
|
+
language: Schema.optional(Schema.String),
|
|
42
|
+
instructions: Schema.optional(Schema.String),
|
|
43
|
+
timestamps: Schema.optional(Schema.Boolean),
|
|
44
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
45
|
+
});
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Response and events
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
export class SpeechResponse extends Schema.Class("Speech.Response")({
|
|
50
|
+
/** The complete audio. Headerless PCM carries `info.encoding`, `info.sampleRate`, and `info.channels`. */
|
|
51
|
+
audio: Media.AssetSchema,
|
|
52
|
+
timestamps: Schema.optional(Schema.Array(SpeechTimestamp)),
|
|
53
|
+
usage: Schema.optional(MediaUsage),
|
|
54
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
55
|
+
}) {
|
|
56
|
+
}
|
|
57
|
+
export const SpeechAudioDeltaEvent = Schema.Struct({
|
|
58
|
+
type: Schema.tag("audio-delta"),
|
|
59
|
+
chunk: Schema.Uint8Array,
|
|
60
|
+
}).annotate({ identifier: "Speech.Event.AudioDelta" });
|
|
61
|
+
export const SpeechTimestampsEvent = Schema.Struct({
|
|
62
|
+
type: Schema.tag("timestamps"),
|
|
63
|
+
items: Schema.Array(SpeechTimestamp),
|
|
64
|
+
}).annotate({ identifier: "Speech.Event.Timestamps" });
|
|
65
|
+
/** `audio` is every `audio-delta` chunk concatenated, so the route holds the whole clip in memory until `finish`. */
|
|
66
|
+
export const SpeechFinishEvent = Schema.Struct({
|
|
67
|
+
type: Schema.tag("finish"),
|
|
68
|
+
audio: Media.AssetSchema,
|
|
69
|
+
usage: Schema.optional(MediaUsage),
|
|
70
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
71
|
+
}).annotate({ identifier: "Speech.Event.Finish" });
|
|
72
|
+
export const SpeechEvent = Schema.Union([
|
|
73
|
+
ProgressEvent,
|
|
74
|
+
SpeechAudioDeltaEvent,
|
|
75
|
+
SpeechTimestampsEvent,
|
|
76
|
+
SpeechFinishEvent,
|
|
77
|
+
]).pipe(Schema.toTaggedUnion("type"));
|
|
78
|
+
const collectResponse = (events) => {
|
|
79
|
+
const finish = events.find((event) => event.type === "finish");
|
|
80
|
+
// Every speech protocol's `finish` emits the terminal event or fails, so a completed stream always has one.
|
|
81
|
+
if (finish === undefined)
|
|
82
|
+
return Effect.die(new Error("The speech stream completed without a finish event"));
|
|
83
|
+
const timestamps = events.filter((event) => event.type === "timestamps").flatMap((event) => event.items);
|
|
84
|
+
return Effect.succeed(new SpeechResponse({
|
|
85
|
+
audio: finish.audio,
|
|
86
|
+
timestamps: timestamps.length === 0 ? undefined : timestamps,
|
|
87
|
+
usage: finish.usage,
|
|
88
|
+
providerMetadata: finish.providerMetadata,
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// Request-shaped call API
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
/** Normalize speech request input into a plain `SpeechRequest`. */
|
|
95
|
+
export const request = (input) => ({
|
|
96
|
+
...input,
|
|
97
|
+
});
|
|
98
|
+
const validate = Schema.decodeUnknownSync(SpeechRequestSchema);
|
|
99
|
+
const requestEffect = (input) => tryRequest(() => {
|
|
100
|
+
const normalized = request(input);
|
|
101
|
+
validate(normalized);
|
|
102
|
+
return normalized;
|
|
103
|
+
});
|
|
104
|
+
export function generate(input) {
|
|
105
|
+
return requestEffect(input).pipe(Effect.flatMap((request) => AI.Service.use((ai) => ai.speech.generate(request))));
|
|
106
|
+
}
|
|
107
|
+
export function stream(input) {
|
|
108
|
+
return Stream.unwrap(requestEffect(input).pipe(Effect.flatMap((request) => AI.Service.useSync((ai) => ai.speech.stream(request)))));
|
|
109
|
+
}
|
|
110
|
+
export const Speech = {
|
|
111
|
+
request,
|
|
112
|
+
generate,
|
|
113
|
+
stream,
|
|
114
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
import { AI } from "./ai.js";
|
|
3
|
+
type Interface = AI.Interface;
|
|
4
|
+
/** Any part of `AI`: text operations at the top, and any subset of each media group. */
|
|
5
|
+
export type Implementation = Partial<Pick<Interface, "stream" | "generate" | "compact"> & {
|
|
6
|
+
readonly [Group in Exclude<keyof Interface, "stream" | "generate" | "compact">]: Partial<Interface[Group]>;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* A full `AI` service from the parts a test provides. Calling anything else fails with a
|
|
10
|
+
* "not implemented in this test" defect, so unexpected calls show up instead of reaching a provider.
|
|
11
|
+
*/
|
|
12
|
+
export declare const make: (implementation: Implementation) => Interface;
|
|
13
|
+
/** `AI` provided by `make(implementation)`. */
|
|
14
|
+
export declare const layer: (implementation: Implementation) => Layer.Layer<AI.AIService, never, never>;
|
|
15
|
+
export * as TestAI from "./test-ai.js";
|
package/dist/test-ai.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Effect, Layer, Stream } from "effect";
|
|
2
|
+
import { AI } from "./ai.js";
|
|
3
|
+
/**
|
|
4
|
+
* A full `AI` service from the parts a test provides. Calling anything else fails with a
|
|
5
|
+
* "not implemented in this test" defect, so unexpected calls show up instead of reaching a provider.
|
|
6
|
+
*/
|
|
7
|
+
export const make = (implementation) => ({
|
|
8
|
+
stream: implementation.stream ?? stream("stream"),
|
|
9
|
+
generate: implementation.generate ?? effect("generate"),
|
|
10
|
+
compact: implementation.compact ?? effect("compact"),
|
|
11
|
+
image: {
|
|
12
|
+
generate: implementation.image?.generate ?? effect("image.generate"),
|
|
13
|
+
stream: implementation.image?.stream ?? stream("image.stream"),
|
|
14
|
+
start: implementation.image?.start ?? effect("image.start"),
|
|
15
|
+
status: implementation.image?.status ?? effect("image.status"),
|
|
16
|
+
result: implementation.image?.result ?? effect("image.result"),
|
|
17
|
+
cancel: implementation.image?.cancel ?? effect("image.cancel"),
|
|
18
|
+
},
|
|
19
|
+
video: {
|
|
20
|
+
start: implementation.video?.start ?? effect("video.start"),
|
|
21
|
+
status: implementation.video?.status ?? effect("video.status"),
|
|
22
|
+
result: implementation.video?.result ?? effect("video.result"),
|
|
23
|
+
cancel: implementation.video?.cancel ?? effect("video.cancel"),
|
|
24
|
+
},
|
|
25
|
+
speech: {
|
|
26
|
+
generate: implementation.speech?.generate ?? effect("speech.generate"),
|
|
27
|
+
stream: implementation.speech?.stream ?? stream("speech.stream"),
|
|
28
|
+
start: implementation.speech?.start ?? effect("speech.start"),
|
|
29
|
+
resume: implementation.speech?.resume ?? effect("speech.resume"),
|
|
30
|
+
},
|
|
31
|
+
transcription: {
|
|
32
|
+
generate: implementation.transcription?.generate ?? effect("transcription.generate"),
|
|
33
|
+
stream: implementation.transcription?.stream ?? stream("transcription.stream"),
|
|
34
|
+
start: implementation.transcription?.start ?? effect("transcription.start"),
|
|
35
|
+
resume: implementation.transcription?.resume ?? effect("transcription.resume"),
|
|
36
|
+
},
|
|
37
|
+
decision: {
|
|
38
|
+
generate: implementation.decision?.generate ?? effect("decision.generate"),
|
|
39
|
+
},
|
|
40
|
+
embedding: {
|
|
41
|
+
generate: implementation.embedding?.generate ?? effect("embedding.generate"),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
/** `AI` provided by `make(implementation)`. */
|
|
45
|
+
export const layer = (implementation) => Layer.succeed(AI.Service, make(implementation));
|
|
46
|
+
const notImplemented = (operation) => new Error(`AI.${operation} is not implemented in this test`);
|
|
47
|
+
const effect = (operation) => () => Effect.die(notImplemented(operation));
|
|
48
|
+
const stream = (operation) => () => Stream.die(notImplemented(operation));
|
|
49
|
+
export * as TestAI from "./test-ai.js";
|