@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,184 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import { Protocol } from "../route/protocol.js";
|
|
4
|
+
import { Lifecycle } from "./utils/lifecycle.js";
|
|
5
|
+
import { ToolStream } from "./utils/tool-stream.js";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://api.cohere.com/v2";
|
|
7
|
+
declare const Options: Schema.Struct<{
|
|
8
|
+
readonly thinking: Schema.optional<Schema.Struct<{
|
|
9
|
+
readonly type: Schema.optional<Schema.Literals<readonly ["enabled", "disabled"]>>;
|
|
10
|
+
readonly tokenBudget: Schema.optional<Schema.Int>;
|
|
11
|
+
}>>;
|
|
12
|
+
}>;
|
|
13
|
+
export type ProviderOptionsInput = Schema.Schema.Type<typeof Options>;
|
|
14
|
+
export declare const protocol: Protocol<{
|
|
15
|
+
readonly model: string;
|
|
16
|
+
readonly messages: readonly {
|
|
17
|
+
readonly role: "assistant" | "system" | "tool" | "user";
|
|
18
|
+
readonly content?: string | readonly ({
|
|
19
|
+
readonly type: "text";
|
|
20
|
+
readonly text: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "thinking";
|
|
23
|
+
readonly thinking: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "image_url";
|
|
26
|
+
readonly image_url: {
|
|
27
|
+
readonly url: string;
|
|
28
|
+
};
|
|
29
|
+
})[] | undefined;
|
|
30
|
+
readonly tool_calls?: readonly {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly type: "function";
|
|
33
|
+
readonly function: {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly arguments: string;
|
|
36
|
+
};
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
readonly tool_call_id?: string | undefined;
|
|
39
|
+
readonly tool_plan?: string | undefined;
|
|
40
|
+
}[];
|
|
41
|
+
readonly stream: true;
|
|
42
|
+
readonly tools?: readonly {
|
|
43
|
+
readonly type: "function";
|
|
44
|
+
readonly function: {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly description?: string | undefined;
|
|
47
|
+
readonly parameters: {
|
|
48
|
+
readonly [x: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}[] | undefined;
|
|
52
|
+
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
53
|
+
readonly thinking?: {
|
|
54
|
+
readonly type: string;
|
|
55
|
+
readonly token_budget?: number | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
readonly max_tokens?: number | undefined;
|
|
58
|
+
readonly temperature?: number | undefined;
|
|
59
|
+
readonly p?: number | undefined;
|
|
60
|
+
readonly k?: number | undefined;
|
|
61
|
+
readonly seed?: number | undefined;
|
|
62
|
+
readonly stop_sequences?: readonly string[] | undefined;
|
|
63
|
+
readonly frequency_penalty?: number | undefined;
|
|
64
|
+
readonly presence_penalty?: number | undefined;
|
|
65
|
+
}, string, {
|
|
66
|
+
readonly type: "unknown";
|
|
67
|
+
} | {
|
|
68
|
+
readonly type: "message-start";
|
|
69
|
+
} | {
|
|
70
|
+
readonly type: "content-delta" | "content-start";
|
|
71
|
+
readonly index: number;
|
|
72
|
+
readonly delta: {
|
|
73
|
+
readonly message: {
|
|
74
|
+
readonly content: {
|
|
75
|
+
readonly text?: string | undefined;
|
|
76
|
+
readonly thinking?: string | undefined;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: "content-end";
|
|
82
|
+
readonly index: number;
|
|
83
|
+
} | {
|
|
84
|
+
readonly type: "tool-plan-delta";
|
|
85
|
+
readonly delta: {
|
|
86
|
+
readonly message: {
|
|
87
|
+
readonly tool_plan: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
} | {
|
|
91
|
+
readonly type: "tool-call-delta" | "tool-call-start";
|
|
92
|
+
readonly index: number;
|
|
93
|
+
readonly delta: {
|
|
94
|
+
readonly message: {
|
|
95
|
+
readonly tool_calls: {
|
|
96
|
+
readonly id?: string | undefined;
|
|
97
|
+
readonly function: {
|
|
98
|
+
readonly name?: string | undefined;
|
|
99
|
+
readonly arguments?: string | undefined;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "tool-call-end";
|
|
106
|
+
readonly index: number;
|
|
107
|
+
} | {
|
|
108
|
+
readonly type: "message-end";
|
|
109
|
+
readonly delta: {
|
|
110
|
+
readonly finish_reason: string;
|
|
111
|
+
readonly usage?: {
|
|
112
|
+
readonly tokens?: {
|
|
113
|
+
readonly input_tokens?: number | undefined;
|
|
114
|
+
readonly output_tokens?: number | undefined;
|
|
115
|
+
readonly reasoning_tokens?: number | undefined;
|
|
116
|
+
} | undefined;
|
|
117
|
+
readonly billed_units?: {
|
|
118
|
+
readonly input_tokens?: number | undefined;
|
|
119
|
+
readonly output_tokens?: number | undefined;
|
|
120
|
+
readonly reasoning_tokens?: number | undefined;
|
|
121
|
+
} | undefined;
|
|
122
|
+
readonly cached_tokens?: number | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
};
|
|
125
|
+
} | {
|
|
126
|
+
readonly type: "citation-end" | "citation-start";
|
|
127
|
+
}, {
|
|
128
|
+
readonly lifecycle: Lifecycle.State;
|
|
129
|
+
readonly finished: boolean;
|
|
130
|
+
readonly tools: Partial<Record<number, ToolStream.PendingTool>>;
|
|
131
|
+
}>;
|
|
132
|
+
export declare const route: Route<{
|
|
133
|
+
readonly model: string;
|
|
134
|
+
readonly messages: readonly {
|
|
135
|
+
readonly role: "assistant" | "system" | "tool" | "user";
|
|
136
|
+
readonly content?: string | readonly ({
|
|
137
|
+
readonly type: "text";
|
|
138
|
+
readonly text: string;
|
|
139
|
+
} | {
|
|
140
|
+
readonly type: "thinking";
|
|
141
|
+
readonly thinking: string;
|
|
142
|
+
} | {
|
|
143
|
+
readonly type: "image_url";
|
|
144
|
+
readonly image_url: {
|
|
145
|
+
readonly url: string;
|
|
146
|
+
};
|
|
147
|
+
})[] | undefined;
|
|
148
|
+
readonly tool_calls?: readonly {
|
|
149
|
+
readonly id: string;
|
|
150
|
+
readonly type: "function";
|
|
151
|
+
readonly function: {
|
|
152
|
+
readonly name: string;
|
|
153
|
+
readonly arguments: string;
|
|
154
|
+
};
|
|
155
|
+
}[] | undefined;
|
|
156
|
+
readonly tool_call_id?: string | undefined;
|
|
157
|
+
readonly tool_plan?: string | undefined;
|
|
158
|
+
}[];
|
|
159
|
+
readonly stream: true;
|
|
160
|
+
readonly tools?: readonly {
|
|
161
|
+
readonly type: "function";
|
|
162
|
+
readonly function: {
|
|
163
|
+
readonly name: string;
|
|
164
|
+
readonly description?: string | undefined;
|
|
165
|
+
readonly parameters: {
|
|
166
|
+
readonly [x: string]: unknown;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
}[] | undefined;
|
|
170
|
+
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
171
|
+
readonly thinking?: {
|
|
172
|
+
readonly type: string;
|
|
173
|
+
readonly token_budget?: number | undefined;
|
|
174
|
+
} | undefined;
|
|
175
|
+
readonly max_tokens?: number | undefined;
|
|
176
|
+
readonly temperature?: number | undefined;
|
|
177
|
+
readonly p?: number | undefined;
|
|
178
|
+
readonly k?: number | undefined;
|
|
179
|
+
readonly seed?: number | undefined;
|
|
180
|
+
readonly stop_sequences?: readonly string[] | undefined;
|
|
181
|
+
readonly frequency_penalty?: number | undefined;
|
|
182
|
+
readonly presence_penalty?: number | undefined;
|
|
183
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
184
|
+
export * as CohereChat from "./cohere-chat.js";
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Effect, Schema, SchemaGetter } from "effect";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
4
|
+
import { Framing } from "../route/framing.js";
|
|
5
|
+
import { Protocol } from "../route/protocol.js";
|
|
6
|
+
import { StreamEvent, Usage } from "../schema/index.js";
|
|
7
|
+
import { JsonObject, ProviderShared } from "./shared.js";
|
|
8
|
+
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
|
+
import { ToolStream } from "./utils/tool-stream.js";
|
|
10
|
+
const ADAPTER = "cohere-chat";
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.cohere.com/v2";
|
|
12
|
+
const Options = Schema.Struct({
|
|
13
|
+
thinking: Schema.optional(Schema.Struct({
|
|
14
|
+
type: Schema.optional(Schema.Literals(["enabled", "disabled"])),
|
|
15
|
+
tokenBudget: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
16
|
+
})),
|
|
17
|
+
});
|
|
18
|
+
const Content = Schema.Union([
|
|
19
|
+
Schema.Struct({ type: Schema.Literal("text"), text: Schema.String }),
|
|
20
|
+
Schema.Struct({ type: Schema.Literal("thinking"), thinking: Schema.String }),
|
|
21
|
+
Schema.Struct({ type: Schema.Literal("image_url"), image_url: Schema.Struct({ url: Schema.String }) }),
|
|
22
|
+
]);
|
|
23
|
+
const ToolCall = Schema.Struct({
|
|
24
|
+
id: Schema.String,
|
|
25
|
+
type: Schema.Literal("function"),
|
|
26
|
+
function: Schema.Struct({ name: Schema.String, arguments: Schema.String }),
|
|
27
|
+
});
|
|
28
|
+
const Message = Schema.Struct({
|
|
29
|
+
role: Schema.Literals(["system", "user", "assistant", "tool"]),
|
|
30
|
+
content: Schema.optional(Schema.Union([Schema.String, Schema.Array(Content)])),
|
|
31
|
+
tool_calls: Schema.optional(Schema.Array(ToolCall)),
|
|
32
|
+
tool_call_id: Schema.optional(Schema.String),
|
|
33
|
+
tool_plan: Schema.optional(Schema.String),
|
|
34
|
+
});
|
|
35
|
+
const Body = Schema.Struct({
|
|
36
|
+
model: Schema.String,
|
|
37
|
+
messages: Schema.Array(Message),
|
|
38
|
+
stream: Schema.Literal(true),
|
|
39
|
+
tools: Schema.optional(Schema.Array(Schema.Struct({
|
|
40
|
+
type: Schema.Literal("function"),
|
|
41
|
+
function: Schema.Struct({
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
description: Schema.optional(Schema.String),
|
|
44
|
+
parameters: JsonObject,
|
|
45
|
+
}),
|
|
46
|
+
}))),
|
|
47
|
+
tool_choice: Schema.optional(Schema.Literals(["NONE", "REQUIRED"])),
|
|
48
|
+
thinking: Schema.optional(Schema.Struct({ type: Schema.String, token_budget: Schema.optional(Schema.Number) })),
|
|
49
|
+
max_tokens: Schema.optional(Schema.Number),
|
|
50
|
+
temperature: Schema.optional(Schema.Number),
|
|
51
|
+
p: Schema.optional(Schema.Number),
|
|
52
|
+
k: Schema.optional(Schema.Number),
|
|
53
|
+
seed: Schema.optional(Schema.Number),
|
|
54
|
+
stop_sequences: Schema.optional(Schema.Array(Schema.String)),
|
|
55
|
+
frequency_penalty: Schema.optional(Schema.Number),
|
|
56
|
+
presence_penalty: Schema.optional(Schema.Number),
|
|
57
|
+
});
|
|
58
|
+
const TokenCounts = Schema.Struct({
|
|
59
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
60
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
61
|
+
reasoning_tokens: Schema.optional(Schema.Number),
|
|
62
|
+
});
|
|
63
|
+
const NativeUsage = Schema.Struct({
|
|
64
|
+
tokens: Schema.optional(TokenCounts),
|
|
65
|
+
billed_units: Schema.optional(TokenCounts),
|
|
66
|
+
cached_tokens: Schema.optional(Schema.Number),
|
|
67
|
+
});
|
|
68
|
+
const KNOWN_EVENT_TYPES = new Set([
|
|
69
|
+
"message-start",
|
|
70
|
+
"content-start",
|
|
71
|
+
"content-delta",
|
|
72
|
+
"content-end",
|
|
73
|
+
"tool-plan-delta",
|
|
74
|
+
"tool-call-start",
|
|
75
|
+
"tool-call-delta",
|
|
76
|
+
"tool-call-end",
|
|
77
|
+
"message-end",
|
|
78
|
+
"citation-start",
|
|
79
|
+
"citation-end",
|
|
80
|
+
]);
|
|
81
|
+
// Cohere may add stream event types. Unknown types are ignored, while a malformed known type still fails decoding.
|
|
82
|
+
const UnknownEvent = Schema.Struct({
|
|
83
|
+
type: Schema.String.check(Schema.makeFilter((type) => !KNOWN_EVENT_TYPES.has(type))),
|
|
84
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown") }), {
|
|
85
|
+
decode: SchemaGetter.transform(() => ({ type: "unknown" })),
|
|
86
|
+
encode: SchemaGetter.forbidden(() => "Unknown Cohere stream events are decode-only"),
|
|
87
|
+
}));
|
|
88
|
+
const Event = Schema.Union([
|
|
89
|
+
Schema.Struct({ type: Schema.Literal("message-start") }),
|
|
90
|
+
Schema.Struct({
|
|
91
|
+
type: Schema.Literals(["content-start", "content-delta"]),
|
|
92
|
+
index: Schema.Number,
|
|
93
|
+
delta: Schema.Struct({
|
|
94
|
+
message: Schema.Struct({
|
|
95
|
+
content: Schema.Struct({ text: Schema.optional(Schema.String), thinking: Schema.optional(Schema.String) }),
|
|
96
|
+
}),
|
|
97
|
+
}),
|
|
98
|
+
}),
|
|
99
|
+
Schema.Struct({ type: Schema.Literal("content-end"), index: Schema.Number }),
|
|
100
|
+
Schema.Struct({
|
|
101
|
+
type: Schema.Literal("tool-plan-delta"),
|
|
102
|
+
delta: Schema.Struct({ message: Schema.Struct({ tool_plan: Schema.String }) }),
|
|
103
|
+
}),
|
|
104
|
+
Schema.Struct({
|
|
105
|
+
type: Schema.Literals(["tool-call-start", "tool-call-delta"]),
|
|
106
|
+
index: Schema.Number,
|
|
107
|
+
delta: Schema.Struct({
|
|
108
|
+
message: Schema.Struct({
|
|
109
|
+
tool_calls: Schema.Struct({
|
|
110
|
+
id: Schema.optional(Schema.String),
|
|
111
|
+
function: Schema.Struct({ name: Schema.optional(Schema.String), arguments: Schema.optional(Schema.String) }),
|
|
112
|
+
}),
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
}),
|
|
116
|
+
Schema.Struct({ type: Schema.Literal("tool-call-end"), index: Schema.Number }),
|
|
117
|
+
Schema.Struct({
|
|
118
|
+
type: Schema.Literal("message-end"),
|
|
119
|
+
delta: Schema.Struct({ finish_reason: Schema.String, usage: Schema.optional(NativeUsage) }),
|
|
120
|
+
}),
|
|
121
|
+
// Citation output is outside this basic chat surface.
|
|
122
|
+
Schema.Struct({ type: Schema.Literals(["citation-start", "citation-end"]) }),
|
|
123
|
+
UnknownEvent,
|
|
124
|
+
]);
|
|
125
|
+
const TOOL_CHOICE = { auto: undefined, none: "NONE", required: "REQUIRED", tool: "REQUIRED" };
|
|
126
|
+
const fromRequest = Effect.fn("CohereChat.fromRequest")(function* (request) {
|
|
127
|
+
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
|
|
128
|
+
const definitions = ProviderShared.flattenTools(request.tools);
|
|
129
|
+
const messages = request.system.length
|
|
130
|
+
? [
|
|
131
|
+
{
|
|
132
|
+
role: "system",
|
|
133
|
+
content: request.system.length === 1
|
|
134
|
+
? request.system[0].text
|
|
135
|
+
: request.system.map((part) => ({ type: "text", text: part.text })),
|
|
136
|
+
},
|
|
137
|
+
]
|
|
138
|
+
: [];
|
|
139
|
+
for (const message of request.messages) {
|
|
140
|
+
if (message.role === "system") {
|
|
141
|
+
messages.push({ role: "user", content: (yield* ProviderShared.wrappedSystemUpdate("Cohere Chat", message)).text });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (message.role === "tool") {
|
|
145
|
+
for (const part of message.content) {
|
|
146
|
+
if (part.type !== "tool-result")
|
|
147
|
+
return yield* ProviderShared.unsupportedContent("Cohere Chat", "tool", ["tool-result"]);
|
|
148
|
+
if (part.result.type === "content" && part.result.value.some((item) => item.type === "file"))
|
|
149
|
+
return yield* ProviderShared.invalidRequest("Cohere Chat does not support file content in tool results");
|
|
150
|
+
messages.push({ role: "tool", tool_call_id: part.id, content: ProviderShared.toolResultText(part) });
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const content = [];
|
|
155
|
+
const calls = [];
|
|
156
|
+
const plans = [];
|
|
157
|
+
for (const part of message.content) {
|
|
158
|
+
if (part.type === "text") {
|
|
159
|
+
content.push({ type: "text", text: part.text });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (message.role === "assistant" && part.type === "reasoning") {
|
|
163
|
+
if (part.providerMetadata?.cohere?.toolPlan === true)
|
|
164
|
+
plans.push(part.text);
|
|
165
|
+
else
|
|
166
|
+
content.push({ type: "thinking", thinking: part.text });
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (message.role === "assistant" && part.type === "tool-call") {
|
|
170
|
+
const args = ProviderShared.encodeJson(part.input);
|
|
171
|
+
calls.push({ id: part.id, type: "function", function: { name: part.name, arguments: args } });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (message.role === "user" && part.type === "media" && part.media.mediaType.startsWith("image/")) {
|
|
175
|
+
const url = ProviderShared.mediaUrl(part.media) ??
|
|
176
|
+
(yield* ProviderShared.requireInlineMedia("Cohere Chat", part.media)).dataUrl;
|
|
177
|
+
content.push({ type: "image_url", image_url: { url } });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
return yield* ProviderShared.unsupportedContent("Cohere Chat", message.role, message.role === "user" ? ["text", "media"] : ["text", "reasoning", "tool-call"]);
|
|
181
|
+
}
|
|
182
|
+
messages.push({
|
|
183
|
+
role: message.role,
|
|
184
|
+
content: content.length ? content : undefined,
|
|
185
|
+
tool_calls: calls.length ? calls : undefined,
|
|
186
|
+
tool_plan: plans.length ? plans.join("") : undefined,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const selected = request.toolChoice?.type === "tool" ? request.toolChoice.name : undefined;
|
|
190
|
+
const tools = selected === undefined ? definitions : definitions.filter((tool) => tool.name === selected);
|
|
191
|
+
if (selected !== undefined && tools.length === 0)
|
|
192
|
+
return yield* ProviderShared.invalidRequest("Cohere Chat tool choice must name an available tool");
|
|
193
|
+
if (tools.some((tool) => tool.native !== undefined))
|
|
194
|
+
return yield* ProviderShared.invalidRequest("Cohere Chat does not support provider-defined tools");
|
|
195
|
+
return {
|
|
196
|
+
model: request.model.id,
|
|
197
|
+
messages,
|
|
198
|
+
stream: true,
|
|
199
|
+
tools: tools.length
|
|
200
|
+
? tools.map((tool) => ({
|
|
201
|
+
type: "function",
|
|
202
|
+
function: { name: tool.name, description: tool.description, parameters: tool.inputSchema },
|
|
203
|
+
}))
|
|
204
|
+
: undefined,
|
|
205
|
+
tool_choice: TOOL_CHOICE[request.toolChoice?.type ?? "auto"],
|
|
206
|
+
thinking: options.thinking && {
|
|
207
|
+
type: options.thinking.type ?? "enabled",
|
|
208
|
+
// Cohere rejects budgets above max_tokens; fitting also leaves room for the answer.
|
|
209
|
+
token_budget: options.thinking.tokenBudget === undefined
|
|
210
|
+
? undefined
|
|
211
|
+
: ProviderShared.fitThinkingBudget(options.thinking.tokenBudget, request.maxTokens),
|
|
212
|
+
},
|
|
213
|
+
max_tokens: request.maxTokens,
|
|
214
|
+
temperature: request.temperature,
|
|
215
|
+
p: request.topP,
|
|
216
|
+
k: request.topK,
|
|
217
|
+
seed: request.seed,
|
|
218
|
+
stop_sequences: request.stop,
|
|
219
|
+
frequency_penalty: request.frequencyPenalty,
|
|
220
|
+
presence_penalty: request.presencePenalty,
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
const finishDetails = (raw) => {
|
|
224
|
+
switch (raw) {
|
|
225
|
+
case "COMPLETE":
|
|
226
|
+
case "STOP_SEQUENCE":
|
|
227
|
+
return { reason: "stop", raw };
|
|
228
|
+
case "MAX_TOKENS":
|
|
229
|
+
return { reason: "length", raw };
|
|
230
|
+
case "TOOL_CALL":
|
|
231
|
+
return { reason: "tool-calls", raw };
|
|
232
|
+
case "ERROR":
|
|
233
|
+
case "TIMEOUT":
|
|
234
|
+
return { reason: "error", raw };
|
|
235
|
+
default:
|
|
236
|
+
return { reason: "unknown", raw };
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const mapUsage = (usage) => new Usage({
|
|
240
|
+
inputTokens: usage.tokens?.input_tokens,
|
|
241
|
+
outputTokens: usage.tokens?.output_tokens,
|
|
242
|
+
nonCachedInputTokens: ProviderShared.subtractTokens(usage.tokens?.input_tokens, usage.cached_tokens),
|
|
243
|
+
cacheReadInputTokens: usage.cached_tokens,
|
|
244
|
+
reasoningTokens: usage.tokens?.reasoning_tokens,
|
|
245
|
+
totalTokens: ProviderShared.totalTokens(usage.tokens?.input_tokens, usage.tokens?.output_tokens, undefined),
|
|
246
|
+
providerMetadata: { cohere: usage },
|
|
247
|
+
});
|
|
248
|
+
// Lifecycle deltas open blocks on demand and ends are no-ops for closed blocks, so content-start needs no handling.
|
|
249
|
+
const step = Effect.fnUntraced(function* (state, event) {
|
|
250
|
+
const events = [];
|
|
251
|
+
switch (event.type) {
|
|
252
|
+
case "message-start":
|
|
253
|
+
return [{ ...state, lifecycle: Lifecycle.start(state.lifecycle) }, events];
|
|
254
|
+
case "content-delta": {
|
|
255
|
+
const id = String(event.index);
|
|
256
|
+
const content = event.delta.message.content;
|
|
257
|
+
const lifecycle = content.thinking !== undefined
|
|
258
|
+
? Lifecycle.reasoningDelta(state.lifecycle, events, id, content.thinking)
|
|
259
|
+
: Lifecycle.textDelta(state.lifecycle, events, id, content.text ?? "");
|
|
260
|
+
return [{ ...state, lifecycle }, events];
|
|
261
|
+
}
|
|
262
|
+
case "content-end": {
|
|
263
|
+
const id = String(event.index);
|
|
264
|
+
const lifecycle = Lifecycle.textEnd(Lifecycle.reasoningEnd(state.lifecycle, events, id), events, id);
|
|
265
|
+
return [{ ...state, lifecycle }, events];
|
|
266
|
+
}
|
|
267
|
+
case "tool-plan-delta": {
|
|
268
|
+
const plan = event.delta.message.tool_plan;
|
|
269
|
+
const lifecycle = Lifecycle.reasoningDelta(state.lifecycle, events, "tool-plan", plan, {
|
|
270
|
+
cohere: { toolPlan: true },
|
|
271
|
+
});
|
|
272
|
+
return [{ ...state, lifecycle }, events];
|
|
273
|
+
}
|
|
274
|
+
case "tool-call-start":
|
|
275
|
+
case "tool-call-delta": {
|
|
276
|
+
const call = event.delta.message.tool_calls;
|
|
277
|
+
const result = ToolStream.appendOrStart(ADAPTER, state.tools, event.index, { id: call.id, name: call.function.name, text: call.function.arguments ?? "" }, "Cohere tool call is missing id or name");
|
|
278
|
+
if (ToolStream.isError(result))
|
|
279
|
+
return yield* result;
|
|
280
|
+
return [{ ...state, tools: result.tools }, result.events];
|
|
281
|
+
}
|
|
282
|
+
case "tool-call-end": {
|
|
283
|
+
const result = yield* ToolStream.finish(ADAPTER, state.tools, event.index);
|
|
284
|
+
return [{ ...state, tools: result.tools }, result.events ?? []];
|
|
285
|
+
}
|
|
286
|
+
case "message-end": {
|
|
287
|
+
const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
|
|
288
|
+
events.push(...pending.events);
|
|
289
|
+
const lifecycle = Lifecycle.finish(state.lifecycle, events, {
|
|
290
|
+
...finishDetails(event.delta.finish_reason),
|
|
291
|
+
usage: event.delta.usage && mapUsage(event.delta.usage),
|
|
292
|
+
});
|
|
293
|
+
return [{ tools: pending.tools, lifecycle, finished: true }, events];
|
|
294
|
+
}
|
|
295
|
+
default:
|
|
296
|
+
return [state, events];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
export const protocol = Protocol.make({
|
|
300
|
+
id: ADAPTER,
|
|
301
|
+
body: { schema: Body, from: fromRequest },
|
|
302
|
+
stream: {
|
|
303
|
+
event: Protocol.jsonEvent(Event),
|
|
304
|
+
initial: () => ({ lifecycle: Lifecycle.initial(), tools: ToolStream.empty(), finished: false }),
|
|
305
|
+
step,
|
|
306
|
+
terminal: (event) => event.type === "message-end",
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
export const route = Route.make({
|
|
310
|
+
id: ADAPTER,
|
|
311
|
+
provider: "cohere",
|
|
312
|
+
providerMetadataKey: "cohere",
|
|
313
|
+
protocol,
|
|
314
|
+
endpoint: Endpoint.path("/chat", { baseURL: DEFAULT_BASE_URL }),
|
|
315
|
+
framing: Framing.sse,
|
|
316
|
+
});
|
|
317
|
+
export * as CohereChat from "./cohere-chat.js";
|
|
@@ -0,0 +1,109 @@
|
|
|
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.deepgram.com";
|
|
7
|
+
export declare const PATH = "/v1/speak";
|
|
8
|
+
export type DeepgramEncoding = OpenString<"linear16" | "mulaw" | "alaw" | "mp3" | "opus" | "flac" | "aac">;
|
|
9
|
+
export type DeepgramSpeechOptions = {
|
|
10
|
+
readonly encoding?: DeepgramEncoding;
|
|
11
|
+
readonly container?: OpenString<"wav" | "ogg" | "none">;
|
|
12
|
+
readonly sampleRate?: number;
|
|
13
|
+
readonly bitRate?: number;
|
|
14
|
+
readonly mip_opt_out?: boolean;
|
|
15
|
+
readonly tag?: string;
|
|
16
|
+
} & Record<string, unknown>;
|
|
17
|
+
export type Request = SpeechRequest<SpeechModel<DeepgramSpeechOptions>>;
|
|
18
|
+
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
|
+
readonly type: "audio-delta";
|
|
20
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "timestamps";
|
|
23
|
+
readonly items: readonly {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly startSeconds: number;
|
|
26
|
+
readonly endSeconds: number;
|
|
27
|
+
}[];
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "generation-progress";
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly progress?: number | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "finish";
|
|
34
|
+
readonly audio: import("../media.js").Asset;
|
|
35
|
+
readonly usage?: {
|
|
36
|
+
readonly type: "seconds";
|
|
37
|
+
readonly seconds: number;
|
|
38
|
+
} | {
|
|
39
|
+
readonly type: "characters";
|
|
40
|
+
readonly characters: number;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "credits";
|
|
43
|
+
readonly credits: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: "compute";
|
|
46
|
+
readonly seconds: number;
|
|
47
|
+
} | {
|
|
48
|
+
readonly type: "tokens";
|
|
49
|
+
readonly input?: number | undefined;
|
|
50
|
+
readonly output?: number | undefined;
|
|
51
|
+
readonly total?: number | undefined;
|
|
52
|
+
readonly details?: {
|
|
53
|
+
readonly [x: string]: unknown;
|
|
54
|
+
} | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
readonly providerMetadata?: {
|
|
57
|
+
readonly [x: string]: {
|
|
58
|
+
readonly [x: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
} | undefined;
|
|
61
|
+
}, Uint8Array<ArrayBufferLike>, SpeechStream.Audio>;
|
|
62
|
+
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<DeepgramSpeechOptions>;
|
|
63
|
+
export declare const DeepgramSpeech: {
|
|
64
|
+
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
65
|
+
readonly type: "audio-delta";
|
|
66
|
+
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
67
|
+
} | {
|
|
68
|
+
readonly type: "timestamps";
|
|
69
|
+
readonly items: readonly {
|
|
70
|
+
readonly text: string;
|
|
71
|
+
readonly startSeconds: number;
|
|
72
|
+
readonly endSeconds: number;
|
|
73
|
+
}[];
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "generation-progress";
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly progress?: number | undefined;
|
|
78
|
+
} | {
|
|
79
|
+
readonly type: "finish";
|
|
80
|
+
readonly audio: import("../media.js").Asset;
|
|
81
|
+
readonly usage?: {
|
|
82
|
+
readonly type: "seconds";
|
|
83
|
+
readonly seconds: number;
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: "characters";
|
|
86
|
+
readonly characters: number;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "credits";
|
|
89
|
+
readonly credits: number;
|
|
90
|
+
} | {
|
|
91
|
+
readonly type: "compute";
|
|
92
|
+
readonly seconds: number;
|
|
93
|
+
} | {
|
|
94
|
+
readonly type: "tokens";
|
|
95
|
+
readonly input?: number | undefined;
|
|
96
|
+
readonly output?: number | undefined;
|
|
97
|
+
readonly total?: number | undefined;
|
|
98
|
+
readonly details?: {
|
|
99
|
+
readonly [x: string]: unknown;
|
|
100
|
+
} | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
readonly providerMetadata?: {
|
|
103
|
+
readonly [x: string]: {
|
|
104
|
+
readonly [x: string]: unknown;
|
|
105
|
+
};
|
|
106
|
+
} | undefined;
|
|
107
|
+
}, Uint8Array<ArrayBufferLike>, SpeechStream.Audio>;
|
|
108
|
+
readonly model: typeof model;
|
|
109
|
+
};
|