@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,14 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Framing } from "../route/framing.js";
|
|
3
|
+
export declare const Frame: Schema.StructWithRest<Schema.Struct<{
|
|
4
|
+
readonly rawBody: Schema.String;
|
|
5
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
6
|
+
export type Frame = typeof Frame.Type;
|
|
7
|
+
/**
|
|
8
|
+
* AWS event-stream framing for Bedrock Converse. Each frame is decoded by
|
|
9
|
+
* `@smithy/eventstream-codec` (length + header + payload + CRC) and rewrapped
|
|
10
|
+
* under its `:event-type` header so the chunk schema can match the JSON
|
|
11
|
+
* payload directly.
|
|
12
|
+
*/
|
|
13
|
+
export declare const framing: (route: string) => Framing.Definition<Frame>;
|
|
14
|
+
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
2
|
+
import { fromUtf8, toUtf8 } from "@smithy/util-utf8";
|
|
3
|
+
import { Effect, Schema, Stream } from "effect";
|
|
4
|
+
import { Base64 } from "effect/encoding";
|
|
5
|
+
import { AIError, AIErrorReason, InvalidProviderOutputError } from "../schema/index.js";
|
|
6
|
+
import { Framing } from "../route/framing.js";
|
|
7
|
+
import { ProviderShared } from "./shared.js";
|
|
8
|
+
// Bedrock streams responses using the AWS event stream binary protocol — each
|
|
9
|
+
// frame is `[length:4][headers-length:4][prelude-crc:4][headers][payload][crc:4]`.
|
|
10
|
+
// We use `@smithy/eventstream-codec` to validate framing and CRCs, then
|
|
11
|
+
// reconstruct the JSON wrapping by `:event-type` so the chunk schema can match.
|
|
12
|
+
const eventCodec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
13
|
+
const utf8 = new TextDecoder();
|
|
14
|
+
const initialFrameBuffer = { buffer: new Uint8Array(0), offset: 0 };
|
|
15
|
+
export const Frame = Schema.StructWithRest(Schema.Struct({ rawBody: Schema.String }), [ProviderShared.JsonObject]);
|
|
16
|
+
const endOfStream = { _tag: "End" };
|
|
17
|
+
const appendChunk = (state, chunk) => {
|
|
18
|
+
const remaining = state.buffer.length - state.offset;
|
|
19
|
+
// Compact: drop the consumed prefix and append the new chunk in one alloc.
|
|
20
|
+
// This bounds buffer growth to at most one network chunk past the live
|
|
21
|
+
// window, regardless of stream length.
|
|
22
|
+
const next = new Uint8Array(remaining + chunk.length);
|
|
23
|
+
next.set(state.buffer.subarray(state.offset), 0);
|
|
24
|
+
next.set(chunk, remaining);
|
|
25
|
+
return { buffer: next, offset: 0 };
|
|
26
|
+
};
|
|
27
|
+
const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
28
|
+
if (input._tag === "End") {
|
|
29
|
+
const remaining = state.buffer.subarray(state.offset);
|
|
30
|
+
if (remaining.length > 0)
|
|
31
|
+
return yield* new AIError({
|
|
32
|
+
reason: new InvalidProviderOutputError({
|
|
33
|
+
route,
|
|
34
|
+
classification: "incomplete-stream",
|
|
35
|
+
message: `Incomplete Bedrock Converse event-stream frame: ${remaining.length} buffered bytes remain at end of stream`,
|
|
36
|
+
body: Base64.encode(remaining),
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
return [state, []];
|
|
40
|
+
}
|
|
41
|
+
let cursor = appendChunk(state, input.bytes);
|
|
42
|
+
const out = [];
|
|
43
|
+
while (cursor.buffer.length - cursor.offset >= 4) {
|
|
44
|
+
const view = cursor.buffer.subarray(cursor.offset);
|
|
45
|
+
const totalLength = new DataView(view.buffer, view.byteOffset, view.byteLength).getUint32(0, false);
|
|
46
|
+
if (view.length < totalLength)
|
|
47
|
+
break;
|
|
48
|
+
const decoded = yield* Effect.try({
|
|
49
|
+
try: () => eventCodec.decode(view.subarray(0, totalLength)),
|
|
50
|
+
catch: (error) => ProviderShared.eventError(route, `Failed to decode Bedrock Converse event-stream frame: ${error instanceof Error ? error.message : String(error)}`, Base64.encode(view.subarray(0, totalLength)), error),
|
|
51
|
+
});
|
|
52
|
+
cursor = { buffer: cursor.buffer, offset: cursor.offset + totalLength };
|
|
53
|
+
const payload = utf8.decode(decoded.body);
|
|
54
|
+
const body = ProviderShared.encodeJson({ headers: decoded.headers, body: payload });
|
|
55
|
+
const messageType = decoded.headers[":message-type"]?.value;
|
|
56
|
+
if (messageType === "error") {
|
|
57
|
+
const code = decoded.headers[":error-code"]?.value;
|
|
58
|
+
const message = decoded.headers[":error-message"]?.value;
|
|
59
|
+
return yield* ProviderShared.eventError(route, [code, message].filter((value) => typeof value === "string").join(": ") ||
|
|
60
|
+
"Bedrock Converse event-stream error", body);
|
|
61
|
+
}
|
|
62
|
+
const eventType = messageType === "event"
|
|
63
|
+
? decoded.headers[":event-type"]?.value
|
|
64
|
+
: messageType === "exception"
|
|
65
|
+
? decoded.headers[":exception-type"]?.value
|
|
66
|
+
: undefined;
|
|
67
|
+
if (typeof eventType !== "string")
|
|
68
|
+
continue;
|
|
69
|
+
if (!payload)
|
|
70
|
+
continue;
|
|
71
|
+
// The AWS event stream pads short payloads with a `p` field. Drop it
|
|
72
|
+
// before handing the object to the chunk schema. JSON decode goes
|
|
73
|
+
// through the shared Schema-driven codec to satisfy the package rule
|
|
74
|
+
// against ad-hoc `JSON.parse` calls.
|
|
75
|
+
const parsed = yield* ProviderShared.parseJson(route, payload, "Failed to parse Bedrock Converse event-stream payload").pipe(Effect.mapError((error) => new AIError({
|
|
76
|
+
reason: AIErrorReason.make({ ...error.reason, message: error.message, cause: error.reason.cause, body }),
|
|
77
|
+
})));
|
|
78
|
+
if (!ProviderShared.isRecord(parsed))
|
|
79
|
+
return yield* ProviderShared.eventError(route, "Failed to parse Bedrock Converse event-stream payload", body);
|
|
80
|
+
const { p: _, ...event } = parsed;
|
|
81
|
+
out.push({
|
|
82
|
+
...(messageType === "exception" ? { exception: { type: eventType, details: event } } : { [eventType]: event }),
|
|
83
|
+
rawBody: body,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return [cursor, out];
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* AWS event-stream framing for Bedrock Converse. Each frame is decoded by
|
|
90
|
+
* `@smithy/eventstream-codec` (length + header + payload + CRC) and rewrapped
|
|
91
|
+
* under its `:event-type` header so the chunk schema can match the JSON
|
|
92
|
+
* payload directly.
|
|
93
|
+
*/
|
|
94
|
+
export const framing = (route) => ({
|
|
95
|
+
id: "aws-event-stream",
|
|
96
|
+
body: (frame) => frame.rawBody,
|
|
97
|
+
raw: ({ rawBody: _, ...event }) => event,
|
|
98
|
+
frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
|
|
99
|
+
});
|
|
100
|
+
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -0,0 +1,117 @@
|
|
|
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.cartesia.ai";
|
|
7
|
+
export declare const API_VERSION = "2026-08-14";
|
|
8
|
+
export declare const BYTES_PATH = "/tts/bytes";
|
|
9
|
+
export declare const SSE_PATH = "/tts/sse";
|
|
10
|
+
export type CartesiaEncoding = SpeechStream.PcmEncoding;
|
|
11
|
+
export type CartesiaSpeechOptions = {
|
|
12
|
+
readonly sampleRate?: 8000 | 16000 | 22050 | 24000 | 44100 | 48000;
|
|
13
|
+
readonly bitRate?: 32000 | 64000 | 96000 | 128000 | 192000;
|
|
14
|
+
readonly encoding?: CartesiaEncoding;
|
|
15
|
+
readonly generation_config?: {
|
|
16
|
+
readonly volume?: number;
|
|
17
|
+
readonly emotion?: OpenString<"neutral" | "calm" | "angry" | "content" | "sad" | "scared">;
|
|
18
|
+
};
|
|
19
|
+
readonly pronunciation_dict_id?: string;
|
|
20
|
+
} & Record<string, unknown>;
|
|
21
|
+
export type Request = SpeechRequest<SpeechModel<CartesiaSpeechOptions>>;
|
|
22
|
+
interface State extends SpeechStream.Audio {
|
|
23
|
+
readonly done: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
26
|
+
readonly type: "audio-delta";
|
|
27
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "timestamps";
|
|
30
|
+
readonly items: readonly {
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly startSeconds: number;
|
|
33
|
+
readonly endSeconds: number;
|
|
34
|
+
}[];
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "generation-progress";
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly progress?: number | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "finish";
|
|
41
|
+
readonly audio: import("../media.js").Asset;
|
|
42
|
+
readonly usage?: {
|
|
43
|
+
readonly type: "seconds";
|
|
44
|
+
readonly seconds: number;
|
|
45
|
+
} | {
|
|
46
|
+
readonly type: "characters";
|
|
47
|
+
readonly characters: number;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "credits";
|
|
50
|
+
readonly credits: number;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "compute";
|
|
53
|
+
readonly seconds: number;
|
|
54
|
+
} | {
|
|
55
|
+
readonly type: "tokens";
|
|
56
|
+
readonly input?: number | undefined;
|
|
57
|
+
readonly output?: number | undefined;
|
|
58
|
+
readonly total?: number | undefined;
|
|
59
|
+
readonly details?: {
|
|
60
|
+
readonly [x: string]: unknown;
|
|
61
|
+
} | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
readonly providerMetadata?: {
|
|
64
|
+
readonly [x: string]: {
|
|
65
|
+
readonly [x: string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
} | undefined;
|
|
68
|
+
}, string | Uint8Array<ArrayBufferLike>, State>;
|
|
69
|
+
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<CartesiaSpeechOptions>;
|
|
70
|
+
export declare const CartesiaSpeech: {
|
|
71
|
+
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
72
|
+
readonly type: "audio-delta";
|
|
73
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "timestamps";
|
|
76
|
+
readonly items: readonly {
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly startSeconds: number;
|
|
79
|
+
readonly endSeconds: number;
|
|
80
|
+
}[];
|
|
81
|
+
} | {
|
|
82
|
+
readonly type: "generation-progress";
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly progress?: number | undefined;
|
|
85
|
+
} | {
|
|
86
|
+
readonly type: "finish";
|
|
87
|
+
readonly audio: import("../media.js").Asset;
|
|
88
|
+
readonly usage?: {
|
|
89
|
+
readonly type: "seconds";
|
|
90
|
+
readonly seconds: number;
|
|
91
|
+
} | {
|
|
92
|
+
readonly type: "characters";
|
|
93
|
+
readonly characters: number;
|
|
94
|
+
} | {
|
|
95
|
+
readonly type: "credits";
|
|
96
|
+
readonly credits: number;
|
|
97
|
+
} | {
|
|
98
|
+
readonly type: "compute";
|
|
99
|
+
readonly seconds: number;
|
|
100
|
+
} | {
|
|
101
|
+
readonly type: "tokens";
|
|
102
|
+
readonly input?: number | undefined;
|
|
103
|
+
readonly output?: number | undefined;
|
|
104
|
+
readonly total?: number | undefined;
|
|
105
|
+
readonly details?: {
|
|
106
|
+
readonly [x: string]: unknown;
|
|
107
|
+
} | undefined;
|
|
108
|
+
} | undefined;
|
|
109
|
+
readonly providerMetadata?: {
|
|
110
|
+
readonly [x: string]: {
|
|
111
|
+
readonly [x: string]: unknown;
|
|
112
|
+
};
|
|
113
|
+
} | undefined;
|
|
114
|
+
}, string | Uint8Array<ArrayBufferLike>, State>;
|
|
115
|
+
readonly model: typeof model;
|
|
116
|
+
};
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { classifyProviderFailure } from "../provider-error.js";
|
|
3
|
+
import { Framing } from "../route/framing.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { MediaRoute } from "../route/media.js";
|
|
6
|
+
import { AIError, mergeJsonRecords } from "../schema/index.js";
|
|
7
|
+
import { SpeechModel } from "../speech.js";
|
|
8
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
9
|
+
import { SpeechStream } from "./utils/speech-stream.js";
|
|
10
|
+
const route = MediaProtocol.identity({ id: "cartesia-speech", name: "Cartesia", provider: "cartesia" });
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.cartesia.ai";
|
|
12
|
+
export const API_VERSION = "2026-08-14";
|
|
13
|
+
export const BYTES_PATH = "/tts/bytes";
|
|
14
|
+
export const SSE_PATH = "/tts/sse";
|
|
15
|
+
const DEFAULT_SAMPLE_RATE = 44100;
|
|
16
|
+
const DEFAULT_BIT_RATE = 128000;
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// 3. Streaming event schema
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/** `phoneme_timestamps` and future record types are ignored. */
|
|
21
|
+
const SseEvent = Schema.Struct({
|
|
22
|
+
type: Schema.String,
|
|
23
|
+
data: Schema.optional(Schema.Uint8ArrayFromBase64),
|
|
24
|
+
word_timestamps: Schema.optional(Schema.Struct({
|
|
25
|
+
words: Schema.Array(Schema.String),
|
|
26
|
+
start: Schema.Array(Schema.Number),
|
|
27
|
+
end: Schema.Array(Schema.Number),
|
|
28
|
+
})),
|
|
29
|
+
status_code: Schema.optional(Schema.Number),
|
|
30
|
+
title: Schema.optional(Schema.String),
|
|
31
|
+
message: Schema.optional(Schema.String),
|
|
32
|
+
error_code: optionalNull(Schema.String),
|
|
33
|
+
});
|
|
34
|
+
const decodeEvent = route.decodeFrame(SseEvent);
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// 5. Request body construction
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
/** Timestamps exist only on the SSE endpoint, so a `generate` that asks for them collects an SSE stream. */
|
|
39
|
+
const usesSse = (request) => request.mode === "stream" || request.timestamps === true;
|
|
40
|
+
const CONTAINERS = { pcm: "raw", wav: "wav", mp3: "mp3" };
|
|
41
|
+
const outputFormat = Effect.fnUntraced(function* (request) {
|
|
42
|
+
const sse = usesSse(request);
|
|
43
|
+
const format = request.format ?? (sse ? "pcm" : "mp3");
|
|
44
|
+
const container = CONTAINERS[format];
|
|
45
|
+
if (container === undefined)
|
|
46
|
+
return yield* route.unsupported("media.format", `${route.name} supports the pcm, wav, and mp3 formats, not "${format}"`);
|
|
47
|
+
if (sse && container !== "raw")
|
|
48
|
+
return yield* route.unsupported("media.format", `${route.name} streams and timestamps only raw PCM; request format "pcm" instead of "${format}"`);
|
|
49
|
+
const sampleRate = request.providerOptions?.sampleRate ?? DEFAULT_SAMPLE_RATE;
|
|
50
|
+
if (container === "mp3")
|
|
51
|
+
return { container, sample_rate: sampleRate, bit_rate: request.providerOptions?.bitRate ?? DEFAULT_BIT_RATE };
|
|
52
|
+
return { container, encoding: request.providerOptions?.encoding ?? "pcm_s16le", sample_rate: sampleRate };
|
|
53
|
+
});
|
|
54
|
+
const fromRequest = Effect.fn("CartesiaSpeech.fromRequest")(function* (request) {
|
|
55
|
+
const voice = SpeechStream.voiceID(request.voice);
|
|
56
|
+
if (voice === undefined)
|
|
57
|
+
return yield* ProviderShared.invalidRequest(`${route.name} requires a voice id; pass it as \`voice\``);
|
|
58
|
+
const { sampleRate: _sampleRate, bitRate: _bitRate, encoding: _encoding, ...native } = request.providerOptions ?? {};
|
|
59
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
60
|
+
model_id: request.model.id,
|
|
61
|
+
transcript: request.text,
|
|
62
|
+
voice,
|
|
63
|
+
output_format: yield* outputFormat(request),
|
|
64
|
+
language: request.language,
|
|
65
|
+
generation_config: request.speed === undefined ? undefined : { speed: request.speed },
|
|
66
|
+
add_timestamps: request.timestamps === true ? true : undefined,
|
|
67
|
+
}, native, request.http?.body) ?? {});
|
|
68
|
+
});
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// 6. Stream parsing
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
const onEvent = Effect.fnUntraced(function* (state, frame) {
|
|
73
|
+
const event = yield* decodeEvent(frame);
|
|
74
|
+
if (event.type === "chunk" && event.data !== undefined)
|
|
75
|
+
return SpeechStream.delta(state, event.data);
|
|
76
|
+
if (event.type === "timestamps" && event.word_timestamps !== undefined) {
|
|
77
|
+
const words = event.word_timestamps;
|
|
78
|
+
return [state, SpeechStream.timestamps(words.words, words.start, words.end)];
|
|
79
|
+
}
|
|
80
|
+
if (event.type === "done")
|
|
81
|
+
return [{ ...state, done: true }, []];
|
|
82
|
+
if (event.type === "error")
|
|
83
|
+
return yield* new AIError({
|
|
84
|
+
reason: classifyProviderFailure({
|
|
85
|
+
message: `${route.name} stream failed${event.title === undefined ? "" : ` (${event.title})`}: ${event.message ?? "unknown error"}`,
|
|
86
|
+
status: event.status_code,
|
|
87
|
+
rawBody: frame,
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
return [state, []];
|
|
91
|
+
});
|
|
92
|
+
const finish = Effect.fnUntraced(function* (state, context) {
|
|
93
|
+
if (usesSse(context.request) && !state.done)
|
|
94
|
+
return yield* route.incomplete();
|
|
95
|
+
const format = yield* outputFormat(context.request);
|
|
96
|
+
return yield* SpeechStream.finish(route, state, format.container === "raw"
|
|
97
|
+
? SpeechStream.pcm(format.encoding, format.sample_rate)
|
|
98
|
+
: SpeechStream.container(format.container, format.sample_rate));
|
|
99
|
+
});
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// 7. Protocol and route
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
export const protocol = MediaProtocol.stream(route, {
|
|
104
|
+
unsupported: ["instructions"],
|
|
105
|
+
body: { from: fromRequest },
|
|
106
|
+
frames: (bytes, context) => (usesSse(context.request) ? Framing.sse.frame(bytes) : bytes),
|
|
107
|
+
initial: () => ({ chunks: [], done: false }),
|
|
108
|
+
step: SpeechStream.step(onEvent),
|
|
109
|
+
finish,
|
|
110
|
+
});
|
|
111
|
+
export const model = (input) => SpeechModel.fromRoute({
|
|
112
|
+
protocol,
|
|
113
|
+
baseURL: DEFAULT_BASE_URL,
|
|
114
|
+
headers: { "Cartesia-Version": API_VERSION },
|
|
115
|
+
path: ({ request }) => (usesSse(request) ? SSE_PATH : BYTES_PATH),
|
|
116
|
+
}, input);
|
|
117
|
+
export const CartesiaSpeech = {
|
|
118
|
+
protocol,
|
|
119
|
+
model,
|
|
120
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
2
|
+
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One body as `input`; media defaults to Clef's top-level lists. */
|
|
3
|
+
export declare const protocol: DecisionRoute.Protocol;
|
|
4
|
+
/** Providers set the Run API base, `.../client/v4/accounts/{account}/ai/run`, with `route.with(...)`. */
|
|
5
|
+
export declare const route: DecisionRoute.Route;
|
|
6
|
+
export declare const CloudflareRunDecisions: {
|
|
7
|
+
readonly protocol: DecisionRoute.Protocol;
|
|
8
|
+
readonly route: DecisionRoute.Route;
|
|
9
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
3
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { SystemOne } from "./system-one.js";
|
|
6
|
+
const ID = "cloudflare-run-decisions";
|
|
7
|
+
const NAME = "Cloudflare Run";
|
|
8
|
+
// Workers AI models answer with the System One response; third-party models such as TypeSafe Jev wrap it in a
|
|
9
|
+
// completed run record.
|
|
10
|
+
const Envelope = Schema.Struct({
|
|
11
|
+
result: Schema.Union([
|
|
12
|
+
SystemOne.Response,
|
|
13
|
+
Schema.Struct({ state: Schema.Literal("Completed"), result: SystemOne.Response }),
|
|
14
|
+
]),
|
|
15
|
+
});
|
|
16
|
+
const decodeEnvelope = MediaProtocol.identity({ id: ID, name: NAME, provider: "cloudflare-workers-ai" }).decodeJson(Envelope);
|
|
17
|
+
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One body as `input`; media defaults to Clef's top-level lists. */
|
|
18
|
+
export const protocol = DecisionRoute.protocol({
|
|
19
|
+
id: ID,
|
|
20
|
+
name: NAME,
|
|
21
|
+
inlineMedia: true,
|
|
22
|
+
body: {
|
|
23
|
+
from: (request) => SystemOne.encodeBody(request, "root").pipe(Effect.map((input) => ({ model: request.model.id, input }))),
|
|
24
|
+
},
|
|
25
|
+
response: {
|
|
26
|
+
decode: (response, context) => decodeEnvelope(response).pipe(Effect.flatMap((output) => SystemOne.toResponse("answers" in output.value.result ? output.value.result : output.value.result.result, context.request, context.providerMetadataKey, output.invalid))),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
/** Providers set the Run API base, `.../client/v4/accounts/{account}/ai/run`, with `route.with(...)`. */
|
|
30
|
+
export const route = DecisionRoute.make({
|
|
31
|
+
id: ID,
|
|
32
|
+
provider: "cloudflare-workers-ai",
|
|
33
|
+
protocol,
|
|
34
|
+
endpoint: Endpoint.path(""),
|
|
35
|
+
});
|
|
36
|
+
export const CloudflareRunDecisions = { protocol, route };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import type { MediaRoute } from "../route/media.js";
|
|
4
|
+
/**
|
|
5
|
+
* Native Run API inputs. Step counts are `steps` on FLUX and Lucid Origin and `num_steps` on the other models;
|
|
6
|
+
* `aspect` and `resolution` lower to `width` and `height`.
|
|
7
|
+
*/
|
|
8
|
+
export type CloudflareWorkersAIImageOptions = {
|
|
9
|
+
readonly width?: number;
|
|
10
|
+
readonly height?: number;
|
|
11
|
+
readonly seed?: number;
|
|
12
|
+
readonly steps?: number;
|
|
13
|
+
readonly num_steps?: number;
|
|
14
|
+
readonly guidance?: number;
|
|
15
|
+
readonly negative_prompt?: string;
|
|
16
|
+
} & Record<string, unknown>;
|
|
17
|
+
export type Request = ImageRequest<ImageModel<CloudflareWorkersAIImageOptions>>;
|
|
18
|
+
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
19
|
+
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<CloudflareWorkersAIImageOptions>;
|
|
20
|
+
export declare const CloudflareWorkersAIImages: {
|
|
21
|
+
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
22
|
+
readonly model: typeof model;
|
|
23
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
+
import { Media } from "../media.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
8
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
9
|
+
const route = MediaProtocol.identity({
|
|
10
|
+
id: "cloudflare-workers-ai-images",
|
|
11
|
+
name: "Cloudflare Workers AI",
|
|
12
|
+
provider: "cloudflare-workers-ai",
|
|
13
|
+
});
|
|
14
|
+
/** FLUX.2 models only accept multipart form fields, even for a prompt alone. */
|
|
15
|
+
const MULTIPART_MODEL_PREFIX = "@cf/black-forest-labs/flux-2-";
|
|
16
|
+
const RESERVED_FORM_FIELDS = new Set(["prompt"]);
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// 2. Response schema
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
const RunResponse = Schema.Struct({
|
|
21
|
+
result: Schema.Struct({
|
|
22
|
+
image: Schema.optional(Schema.String),
|
|
23
|
+
usage: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// 5. Request body construction
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
const fromRequest = Effect.fn("CloudflareWorkersAIImages.fromRequest")(function* (request) {
|
|
30
|
+
if (request.n !== undefined && request.n > 1)
|
|
31
|
+
return yield* route.unsupported("media.n", `${route.name} generates one image per request; call it once per image`);
|
|
32
|
+
const fields = {
|
|
33
|
+
prompt: request.prompt,
|
|
34
|
+
...(yield* ImageSizing.exact(route, request, { multiple: 16, minEdge: 256, maxEdge: 2048 })),
|
|
35
|
+
};
|
|
36
|
+
const native = mergeJsonRecords(request.providerOptions, request.http?.body);
|
|
37
|
+
const images = request.images ?? [];
|
|
38
|
+
if (!request.model.id.startsWith(MULTIPART_MODEL_PREFIX)) {
|
|
39
|
+
if (images.length > 1)
|
|
40
|
+
return yield* route.unsupported("media.images", `${request.model.id} takes one input image as image_b64`);
|
|
41
|
+
const image = images[0]?.inline();
|
|
42
|
+
if (images[0] !== undefined && image === undefined)
|
|
43
|
+
return yield* ProviderShared.inlineRequired(route.id, images[0]);
|
|
44
|
+
return MediaProtocol.json(mergeJsonRecords({ ...fields, image_b64: image?.base64 }, native) ?? {});
|
|
45
|
+
}
|
|
46
|
+
const body = new FormData();
|
|
47
|
+
MediaInput.appendFields(body, fields, { overlay: native, reserved: RESERVED_FORM_FIELDS });
|
|
48
|
+
yield* Effect.forEach(images, (image, index) => MediaInput.inlineBytes(route.id, image).pipe(Effect.map((bytes) => body.append(`input_image_${index}`, MediaInput.blob(bytes, image.mediaType), `image_${index}`))));
|
|
49
|
+
return MediaProtocol.multipart(body);
|
|
50
|
+
});
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// 6. Response decoding
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
const decodeDocument = route.decodeJson(RunResponse);
|
|
55
|
+
// FLUX and Lucid Origin wrap base64 in the Run API envelope; the Stable Diffusion family, DreamShaper, and Phoenix
|
|
56
|
+
// answer with the raw image, whose declared content type does not always match the bytes.
|
|
57
|
+
const decodeResponse = Effect.fn("CloudflareWorkersAIImages.decodeResponse")(function* (response) {
|
|
58
|
+
if (!response.headers["content-type"]?.startsWith("application/json"))
|
|
59
|
+
return new ImageResponse({ images: [Media.bytes(yield* route.bytes(response))] });
|
|
60
|
+
const output = yield* decodeDocument(response);
|
|
61
|
+
const result = output.value.result;
|
|
62
|
+
if (result.image === undefined)
|
|
63
|
+
return yield* output.invalid(`${route.name} returned no image`);
|
|
64
|
+
return new ImageResponse({
|
|
65
|
+
images: [yield* MediaInput.decodedAsset(output.invalid, `${route.name} result`, result.image, undefined)],
|
|
66
|
+
providerMetadata: result.usage === undefined ? undefined : { "cloudflare-workers-ai": { usage: result.usage } },
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// 7. Protocol and route
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
73
|
+
body: { from: fromRequest },
|
|
74
|
+
response: { decode: decodeResponse },
|
|
75
|
+
});
|
|
76
|
+
export const model = (input) => ImageModel.fromRoute({ protocol, path: ({ request }) => `/${request.model.id}` }, input);
|
|
77
|
+
export const CloudflareWorkersAIImages = {
|
|
78
|
+
protocol,
|
|
79
|
+
model,
|
|
80
|
+
};
|