@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,120 @@
|
|
|
1
|
+
import { CloudflareRunDecisions } from "../protocols/cloudflare-run-decisions.js";
|
|
2
|
+
import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../protocols/index.js";
|
|
3
|
+
import { Auth } from "../route/auth.js";
|
|
4
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
5
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
6
|
+
import { encodeJson } from "../utils/json.js";
|
|
7
|
+
import { CloudflareShared } from "./cloudflare-shared.js";
|
|
8
|
+
export const id = ProviderID.make("cloudflare-ai-gateway");
|
|
9
|
+
export const authEnvVars = ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
|
|
10
|
+
export const baseURL = (input) => CloudflareShared.baseURL(input, id, "CloudflareAIGateway");
|
|
11
|
+
/** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
|
|
12
|
+
export const runBaseURL = (input) => CloudflareShared.runBaseURL(input, id, "CloudflareAIGateway");
|
|
13
|
+
// Cloudflare's REST API rejects parts of the Anthropic Messages and OpenAI Responses request shapes, such as
|
|
14
|
+
// system prompt blocks and `minimal` reasoning effort, so these models use the provider-native gateway endpoints.
|
|
15
|
+
const passthroughURL = (input, provider) => `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(CloudflareShared.requireAccountId(input, id, "CloudflareAIGateway"))}/${encodeURIComponent(gatewayId(input))}/${provider}`;
|
|
16
|
+
const gatewayId = (input) => input.gatewayId?.trim() || "default";
|
|
17
|
+
export const responsesRoute = OpenAIResponses.route.with({
|
|
18
|
+
id: "cloudflare-ai-gateway-responses",
|
|
19
|
+
provider: id,
|
|
20
|
+
endpoint: { baseURL: undefined },
|
|
21
|
+
});
|
|
22
|
+
export const messagesRoute = AnthropicMessages.route.with({
|
|
23
|
+
id: "cloudflare-ai-gateway-messages",
|
|
24
|
+
provider: id,
|
|
25
|
+
endpoint: { baseURL: undefined },
|
|
26
|
+
});
|
|
27
|
+
export const route = OpenAIChat.route.with({
|
|
28
|
+
id: "cloudflare-ai-gateway-chat",
|
|
29
|
+
provider: id,
|
|
30
|
+
endpoint: { baseURL: undefined },
|
|
31
|
+
});
|
|
32
|
+
export const routes = [responsesRoute, messagesRoute, route];
|
|
33
|
+
const credential = (input, apply) => AuthOptions.apiKey({ apiKey: input.gatewayApiKey ?? ("apiKey" in input ? input.apiKey : undefined) }, authEnvVars, apply);
|
|
34
|
+
const headers = (input) => ({
|
|
35
|
+
...(input.metadata === undefined ? {} : { "cf-aig-metadata": encodeJson(input.metadata) }),
|
|
36
|
+
...(input.cacheTtl === undefined ? {} : { "cf-aig-cache-ttl": String(input.cacheTtl) }),
|
|
37
|
+
...(input.cacheKey === undefined ? {} : { "cf-aig-cache-key": input.cacheKey }),
|
|
38
|
+
...(input.skipCache === undefined ? {} : { "cf-aig-skip-cache": String(input.skipCache) }),
|
|
39
|
+
...(input.collectLog === undefined ? {} : { "cf-aig-collect-log": String(input.collectLog) }),
|
|
40
|
+
...input.http?.headers,
|
|
41
|
+
});
|
|
42
|
+
export const configure = (input) => {
|
|
43
|
+
const custom = "auth" in input && input.auth ? input.auth : undefined;
|
|
44
|
+
const rest = {
|
|
45
|
+
endpoint: { baseURL: baseURL(input) },
|
|
46
|
+
auth: custom ?? credential(input, (credential) => credential.bearer()),
|
|
47
|
+
http: { ...input.http, headers: { "cf-aig-gateway-id": gatewayId(input), ...headers(input) } },
|
|
48
|
+
providerOptions: input.providerOptions,
|
|
49
|
+
};
|
|
50
|
+
// A custom baseURL stands in for the REST API, so every model keeps using it with gateway model IDs.
|
|
51
|
+
const native = input.baseURL === undefined;
|
|
52
|
+
const passthrough = (provider) => native
|
|
53
|
+
? {
|
|
54
|
+
...rest,
|
|
55
|
+
endpoint: { baseURL: passthroughURL(input, provider) },
|
|
56
|
+
auth: custom ?? credential(input, Auth.bearerHeader("cf-aig-authorization")),
|
|
57
|
+
http: { ...input.http, headers: headers(input) },
|
|
58
|
+
}
|
|
59
|
+
: rest;
|
|
60
|
+
const responsesConfigured = responsesRoute.with(passthrough("openai"));
|
|
61
|
+
const messagesConfigured = messagesRoute.with(passthrough("anthropic/v1"));
|
|
62
|
+
const chatConfigured = route.with(rest);
|
|
63
|
+
const responses = (value) => responsesConfigured.model({
|
|
64
|
+
id: native ? value.replace(/^openai\//, "") : value,
|
|
65
|
+
});
|
|
66
|
+
const messages = (value) => messagesConfigured.model({
|
|
67
|
+
id: native ? value.replace(/^anthropic\//, "").replaceAll(".", "-") : value,
|
|
68
|
+
});
|
|
69
|
+
const chat = (value) => chatConfigured.model({ id: value.replace(/^workers-ai\//, "") });
|
|
70
|
+
// The Run API base is derived per call so a chat-only configuration without an account still constructs.
|
|
71
|
+
const decision = (value, providerOptions) => CloudflareRunDecisions.route
|
|
72
|
+
.with({
|
|
73
|
+
provider: id,
|
|
74
|
+
endpoint: { baseURL: runBaseURL(input) },
|
|
75
|
+
auth: rest.auth,
|
|
76
|
+
...mergeTransport(input, { http: { headers: rest.http.headers } }),
|
|
77
|
+
})
|
|
78
|
+
.model({ id: value, providerOptions });
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
model: (value) => {
|
|
82
|
+
if (value.startsWith("openai/"))
|
|
83
|
+
return responses(value);
|
|
84
|
+
if (value.startsWith("anthropic/"))
|
|
85
|
+
return messages(value);
|
|
86
|
+
return chat(value);
|
|
87
|
+
},
|
|
88
|
+
chat,
|
|
89
|
+
responses,
|
|
90
|
+
messages,
|
|
91
|
+
decision,
|
|
92
|
+
configure,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export const provider = { id, configure };
|
|
96
|
+
export const model = (modelID, settings) => configure(config(settings)).model(modelID);
|
|
97
|
+
export const chat = (modelID, settings) => configure(config(settings)).chat(modelID);
|
|
98
|
+
export const responses = (modelID, settings) => configure(config(settings)).responses(modelID);
|
|
99
|
+
export const messages = (modelID, settings) => configure(config(settings)).messages(modelID);
|
|
100
|
+
export const decisionModel = (modelID, settings) => {
|
|
101
|
+
const input = config(settings);
|
|
102
|
+
return configure(input).decision(modelID, input.providerOptions);
|
|
103
|
+
};
|
|
104
|
+
function config({ accountId, apiKey, baseURL: configuredBaseURL, body, cacheKey, cacheTtl, collectLog, gatewayApiKey, gatewayId, headers, metadata, skipCache, ...providerOptions }) {
|
|
105
|
+
const connection = configuredBaseURL === undefined ? { accountId: accountId ?? "" } : { baseURL: configuredBaseURL };
|
|
106
|
+
return {
|
|
107
|
+
...connection,
|
|
108
|
+
apiKey,
|
|
109
|
+
cacheKey,
|
|
110
|
+
cacheTtl,
|
|
111
|
+
collectLog,
|
|
112
|
+
gatewayApiKey,
|
|
113
|
+
gatewayId,
|
|
114
|
+
http: { headers, body },
|
|
115
|
+
metadata,
|
|
116
|
+
providerOptions,
|
|
117
|
+
skipCache,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export * as CloudflareAIGateway from "./cloudflare-ai-gateway.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ProviderID } from "../schema/index.js";
|
|
2
|
+
type AccountURL = {
|
|
3
|
+
readonly accountId?: string;
|
|
4
|
+
readonly baseURL?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const requireAccountId: (input: AccountURL, provider: ProviderID, name: string) => string;
|
|
7
|
+
export declare const baseURL: (input: AccountURL, provider: ProviderID, name: string) => string;
|
|
8
|
+
export declare const runBaseURL: (input: AccountURL, provider: ProviderID, name: string) => string;
|
|
9
|
+
export * as CloudflareShared from "./cloudflare-shared.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
2
|
+
import { ProviderConfigurationError } from "../schema/index.js";
|
|
3
|
+
export const requireAccountId = (input, provider, name) => {
|
|
4
|
+
if (input.accountId)
|
|
5
|
+
return input.accountId;
|
|
6
|
+
throw new ProviderConfigurationError({
|
|
7
|
+
provider,
|
|
8
|
+
message: `${name}.configure requires accountId unless baseURL is supplied`,
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export const baseURL = (input, provider, name) => {
|
|
12
|
+
if (input.baseURL)
|
|
13
|
+
return input.baseURL;
|
|
14
|
+
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(requireAccountId(input, provider, name))}/ai/v1`;
|
|
15
|
+
};
|
|
16
|
+
export const runBaseURL = (input, provider, name) => {
|
|
17
|
+
const url = Endpoint.trimBaseUrl(baseURL(input, provider, name));
|
|
18
|
+
if (!url.endsWith("/ai/v1"))
|
|
19
|
+
throw new ProviderConfigurationError({
|
|
20
|
+
provider,
|
|
21
|
+
message: `${name} needs accountId or a baseURL ending in /ai/v1 to derive the Run API base`,
|
|
22
|
+
});
|
|
23
|
+
return `${url.slice(0, -"/v1".length)}/run`;
|
|
24
|
+
};
|
|
25
|
+
export * as CloudflareShared from "./cloudflare-shared.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { decisionModel as model } from "../cloudflare-workers-ai.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { imageModel as model } from "../cloudflare-workers-ai.js";
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
5
|
+
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
6
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
+
export declare const authEnvVars: readonly ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"];
|
|
8
|
+
type WorkersAIURL = AtLeastOne<{
|
|
9
|
+
readonly accountId: string;
|
|
10
|
+
readonly baseURL: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type Config = WorkersAIURL & Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
13
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
14
|
+
};
|
|
15
|
+
export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & WorkersAIURL & {
|
|
16
|
+
readonly apiKey?: string | false;
|
|
17
|
+
};
|
|
18
|
+
export type { CloudflareWorkersAIImageOptions } from "../protocols/cloudflare-workers-ai-images.js";
|
|
19
|
+
export declare const baseURL: (input: WorkersAIURL) => string;
|
|
20
|
+
/** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
|
|
21
|
+
export declare const runBaseURL: (input: WorkersAIURL) => string;
|
|
22
|
+
export declare const route: Route<{
|
|
23
|
+
readonly model: string;
|
|
24
|
+
readonly messages: readonly ({
|
|
25
|
+
readonly role: "system";
|
|
26
|
+
readonly content: string | readonly ({
|
|
27
|
+
readonly type: "image_url";
|
|
28
|
+
readonly image_url: {
|
|
29
|
+
readonly url: string;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "video_url";
|
|
33
|
+
readonly video_url: {
|
|
34
|
+
readonly url: string;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
readonly type: "file";
|
|
38
|
+
readonly file: {
|
|
39
|
+
readonly filename: string;
|
|
40
|
+
readonly file_data: string;
|
|
41
|
+
};
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "text";
|
|
44
|
+
readonly text: string;
|
|
45
|
+
readonly cache_control?: {
|
|
46
|
+
readonly type: "ephemeral";
|
|
47
|
+
readonly ttl?: string | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
})[];
|
|
50
|
+
} | {
|
|
51
|
+
readonly role: "user";
|
|
52
|
+
readonly content: string | readonly ({
|
|
53
|
+
readonly type: "image_url";
|
|
54
|
+
readonly image_url: {
|
|
55
|
+
readonly url: string;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
readonly type: "video_url";
|
|
59
|
+
readonly video_url: {
|
|
60
|
+
readonly url: string;
|
|
61
|
+
};
|
|
62
|
+
} | {
|
|
63
|
+
readonly type: "file";
|
|
64
|
+
readonly file: {
|
|
65
|
+
readonly filename: string;
|
|
66
|
+
readonly file_data: string;
|
|
67
|
+
};
|
|
68
|
+
} | {
|
|
69
|
+
readonly type: "text";
|
|
70
|
+
readonly text: string;
|
|
71
|
+
readonly cache_control?: {
|
|
72
|
+
readonly type: "ephemeral";
|
|
73
|
+
readonly ttl?: string | undefined;
|
|
74
|
+
} | undefined;
|
|
75
|
+
})[];
|
|
76
|
+
} | {
|
|
77
|
+
readonly role: "tool";
|
|
78
|
+
readonly tool_call_id: string;
|
|
79
|
+
readonly content: string | readonly {
|
|
80
|
+
readonly type: "text";
|
|
81
|
+
readonly text: string;
|
|
82
|
+
readonly cache_control?: {
|
|
83
|
+
readonly type: "ephemeral";
|
|
84
|
+
readonly ttl?: string | undefined;
|
|
85
|
+
} | undefined;
|
|
86
|
+
}[];
|
|
87
|
+
} | {
|
|
88
|
+
readonly [x: string]: unknown;
|
|
89
|
+
readonly role: "assistant";
|
|
90
|
+
readonly content: string | readonly {
|
|
91
|
+
readonly type: "text";
|
|
92
|
+
readonly text: string;
|
|
93
|
+
readonly cache_control?: {
|
|
94
|
+
readonly type: "ephemeral";
|
|
95
|
+
readonly ttl?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
}[] | null;
|
|
98
|
+
readonly tool_calls?: readonly ({
|
|
99
|
+
readonly id: string;
|
|
100
|
+
readonly type: "custom";
|
|
101
|
+
readonly custom: {
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly input: string;
|
|
104
|
+
};
|
|
105
|
+
} | {
|
|
106
|
+
readonly id: string;
|
|
107
|
+
readonly type: "function";
|
|
108
|
+
readonly function: {
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly arguments: string;
|
|
111
|
+
};
|
|
112
|
+
readonly extra_content?: {
|
|
113
|
+
readonly google: {
|
|
114
|
+
readonly thought_signature: string;
|
|
115
|
+
};
|
|
116
|
+
} | undefined;
|
|
117
|
+
})[] | undefined;
|
|
118
|
+
readonly reasoning_content?: string | undefined;
|
|
119
|
+
readonly reasoning?: string | undefined;
|
|
120
|
+
readonly reasoning_text?: string | undefined;
|
|
121
|
+
readonly reasoning_details?: unknown;
|
|
122
|
+
readonly reasoning_opaque?: string | undefined;
|
|
123
|
+
})[];
|
|
124
|
+
readonly tools?: readonly ({
|
|
125
|
+
readonly type: "function";
|
|
126
|
+
readonly function: {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly description: string;
|
|
129
|
+
readonly parameters: {
|
|
130
|
+
readonly [x: string]: unknown;
|
|
131
|
+
};
|
|
132
|
+
readonly strict?: boolean | undefined;
|
|
133
|
+
};
|
|
134
|
+
readonly cache_control?: {
|
|
135
|
+
readonly type: "ephemeral";
|
|
136
|
+
readonly ttl?: string | undefined;
|
|
137
|
+
} | undefined;
|
|
138
|
+
} | {
|
|
139
|
+
readonly type: "custom";
|
|
140
|
+
readonly custom: {
|
|
141
|
+
readonly name: string;
|
|
142
|
+
readonly description: string;
|
|
143
|
+
readonly format: {
|
|
144
|
+
readonly type: "text";
|
|
145
|
+
} | {
|
|
146
|
+
readonly type: "grammar";
|
|
147
|
+
readonly grammar: {
|
|
148
|
+
readonly syntax: "lark" | "regex";
|
|
149
|
+
readonly definition: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
readonly cache_control?: {
|
|
154
|
+
readonly type: "ephemeral";
|
|
155
|
+
readonly ttl?: string | undefined;
|
|
156
|
+
} | undefined;
|
|
157
|
+
})[] | undefined;
|
|
158
|
+
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
159
|
+
readonly type: "function";
|
|
160
|
+
readonly function: {
|
|
161
|
+
readonly name: string;
|
|
162
|
+
};
|
|
163
|
+
} | {
|
|
164
|
+
readonly type: "custom";
|
|
165
|
+
readonly custom: {
|
|
166
|
+
readonly name: string;
|
|
167
|
+
};
|
|
168
|
+
} | undefined;
|
|
169
|
+
readonly stream: true;
|
|
170
|
+
readonly stream_options?: {
|
|
171
|
+
readonly include_usage: boolean;
|
|
172
|
+
} | undefined;
|
|
173
|
+
readonly store?: boolean | undefined;
|
|
174
|
+
readonly prompt_cache_key?: string | undefined;
|
|
175
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
176
|
+
readonly prompt_cache_options?: {
|
|
177
|
+
readonly ttl?: string | undefined;
|
|
178
|
+
} | undefined;
|
|
179
|
+
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
180
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
181
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
182
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
183
|
+
readonly metadata?: {
|
|
184
|
+
readonly [x: string]: string;
|
|
185
|
+
} | undefined;
|
|
186
|
+
readonly safety_identifier?: string | undefined;
|
|
187
|
+
readonly tool_stream?: boolean | undefined;
|
|
188
|
+
readonly max_completion_tokens?: number | undefined;
|
|
189
|
+
readonly max_tokens?: number | undefined;
|
|
190
|
+
readonly temperature?: number | undefined;
|
|
191
|
+
readonly top_p?: number | undefined;
|
|
192
|
+
readonly frequency_penalty?: number | undefined;
|
|
193
|
+
readonly presence_penalty?: number | undefined;
|
|
194
|
+
readonly seed?: number | undefined;
|
|
195
|
+
readonly stop?: readonly string[] | undefined;
|
|
196
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
197
|
+
export declare const routes: Route<{
|
|
198
|
+
readonly model: string;
|
|
199
|
+
readonly messages: readonly ({
|
|
200
|
+
readonly role: "system";
|
|
201
|
+
readonly content: string | readonly ({
|
|
202
|
+
readonly type: "image_url";
|
|
203
|
+
readonly image_url: {
|
|
204
|
+
readonly url: string;
|
|
205
|
+
};
|
|
206
|
+
} | {
|
|
207
|
+
readonly type: "video_url";
|
|
208
|
+
readonly video_url: {
|
|
209
|
+
readonly url: string;
|
|
210
|
+
};
|
|
211
|
+
} | {
|
|
212
|
+
readonly type: "file";
|
|
213
|
+
readonly file: {
|
|
214
|
+
readonly filename: string;
|
|
215
|
+
readonly file_data: string;
|
|
216
|
+
};
|
|
217
|
+
} | {
|
|
218
|
+
readonly type: "text";
|
|
219
|
+
readonly text: string;
|
|
220
|
+
readonly cache_control?: {
|
|
221
|
+
readonly type: "ephemeral";
|
|
222
|
+
readonly ttl?: string | undefined;
|
|
223
|
+
} | undefined;
|
|
224
|
+
})[];
|
|
225
|
+
} | {
|
|
226
|
+
readonly role: "user";
|
|
227
|
+
readonly content: string | readonly ({
|
|
228
|
+
readonly type: "image_url";
|
|
229
|
+
readonly image_url: {
|
|
230
|
+
readonly url: string;
|
|
231
|
+
};
|
|
232
|
+
} | {
|
|
233
|
+
readonly type: "video_url";
|
|
234
|
+
readonly video_url: {
|
|
235
|
+
readonly url: string;
|
|
236
|
+
};
|
|
237
|
+
} | {
|
|
238
|
+
readonly type: "file";
|
|
239
|
+
readonly file: {
|
|
240
|
+
readonly filename: string;
|
|
241
|
+
readonly file_data: string;
|
|
242
|
+
};
|
|
243
|
+
} | {
|
|
244
|
+
readonly type: "text";
|
|
245
|
+
readonly text: string;
|
|
246
|
+
readonly cache_control?: {
|
|
247
|
+
readonly type: "ephemeral";
|
|
248
|
+
readonly ttl?: string | undefined;
|
|
249
|
+
} | undefined;
|
|
250
|
+
})[];
|
|
251
|
+
} | {
|
|
252
|
+
readonly role: "tool";
|
|
253
|
+
readonly tool_call_id: string;
|
|
254
|
+
readonly content: string | readonly {
|
|
255
|
+
readonly type: "text";
|
|
256
|
+
readonly text: string;
|
|
257
|
+
readonly cache_control?: {
|
|
258
|
+
readonly type: "ephemeral";
|
|
259
|
+
readonly ttl?: string | undefined;
|
|
260
|
+
} | undefined;
|
|
261
|
+
}[];
|
|
262
|
+
} | {
|
|
263
|
+
readonly [x: string]: unknown;
|
|
264
|
+
readonly role: "assistant";
|
|
265
|
+
readonly content: string | readonly {
|
|
266
|
+
readonly type: "text";
|
|
267
|
+
readonly text: string;
|
|
268
|
+
readonly cache_control?: {
|
|
269
|
+
readonly type: "ephemeral";
|
|
270
|
+
readonly ttl?: string | undefined;
|
|
271
|
+
} | undefined;
|
|
272
|
+
}[] | null;
|
|
273
|
+
readonly tool_calls?: readonly ({
|
|
274
|
+
readonly id: string;
|
|
275
|
+
readonly type: "custom";
|
|
276
|
+
readonly custom: {
|
|
277
|
+
readonly name: string;
|
|
278
|
+
readonly input: string;
|
|
279
|
+
};
|
|
280
|
+
} | {
|
|
281
|
+
readonly id: string;
|
|
282
|
+
readonly type: "function";
|
|
283
|
+
readonly function: {
|
|
284
|
+
readonly name: string;
|
|
285
|
+
readonly arguments: string;
|
|
286
|
+
};
|
|
287
|
+
readonly extra_content?: {
|
|
288
|
+
readonly google: {
|
|
289
|
+
readonly thought_signature: string;
|
|
290
|
+
};
|
|
291
|
+
} | undefined;
|
|
292
|
+
})[] | undefined;
|
|
293
|
+
readonly reasoning_content?: string | undefined;
|
|
294
|
+
readonly reasoning?: string | undefined;
|
|
295
|
+
readonly reasoning_text?: string | undefined;
|
|
296
|
+
readonly reasoning_details?: unknown;
|
|
297
|
+
readonly reasoning_opaque?: string | undefined;
|
|
298
|
+
})[];
|
|
299
|
+
readonly tools?: readonly ({
|
|
300
|
+
readonly type: "function";
|
|
301
|
+
readonly function: {
|
|
302
|
+
readonly name: string;
|
|
303
|
+
readonly description: string;
|
|
304
|
+
readonly parameters: {
|
|
305
|
+
readonly [x: string]: unknown;
|
|
306
|
+
};
|
|
307
|
+
readonly strict?: boolean | undefined;
|
|
308
|
+
};
|
|
309
|
+
readonly cache_control?: {
|
|
310
|
+
readonly type: "ephemeral";
|
|
311
|
+
readonly ttl?: string | undefined;
|
|
312
|
+
} | undefined;
|
|
313
|
+
} | {
|
|
314
|
+
readonly type: "custom";
|
|
315
|
+
readonly custom: {
|
|
316
|
+
readonly name: string;
|
|
317
|
+
readonly description: string;
|
|
318
|
+
readonly format: {
|
|
319
|
+
readonly type: "text";
|
|
320
|
+
} | {
|
|
321
|
+
readonly type: "grammar";
|
|
322
|
+
readonly grammar: {
|
|
323
|
+
readonly syntax: "lark" | "regex";
|
|
324
|
+
readonly definition: string;
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
readonly cache_control?: {
|
|
329
|
+
readonly type: "ephemeral";
|
|
330
|
+
readonly ttl?: string | undefined;
|
|
331
|
+
} | undefined;
|
|
332
|
+
})[] | undefined;
|
|
333
|
+
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
334
|
+
readonly type: "function";
|
|
335
|
+
readonly function: {
|
|
336
|
+
readonly name: string;
|
|
337
|
+
};
|
|
338
|
+
} | {
|
|
339
|
+
readonly type: "custom";
|
|
340
|
+
readonly custom: {
|
|
341
|
+
readonly name: string;
|
|
342
|
+
};
|
|
343
|
+
} | undefined;
|
|
344
|
+
readonly stream: true;
|
|
345
|
+
readonly stream_options?: {
|
|
346
|
+
readonly include_usage: boolean;
|
|
347
|
+
} | undefined;
|
|
348
|
+
readonly store?: boolean | undefined;
|
|
349
|
+
readonly prompt_cache_key?: string | undefined;
|
|
350
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
351
|
+
readonly prompt_cache_options?: {
|
|
352
|
+
readonly ttl?: string | undefined;
|
|
353
|
+
} | undefined;
|
|
354
|
+
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
355
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
356
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
357
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
358
|
+
readonly metadata?: {
|
|
359
|
+
readonly [x: string]: string;
|
|
360
|
+
} | undefined;
|
|
361
|
+
readonly safety_identifier?: string | undefined;
|
|
362
|
+
readonly tool_stream?: boolean | undefined;
|
|
363
|
+
readonly max_completion_tokens?: number | undefined;
|
|
364
|
+
readonly max_tokens?: number | undefined;
|
|
365
|
+
readonly temperature?: number | undefined;
|
|
366
|
+
readonly top_p?: number | undefined;
|
|
367
|
+
readonly frequency_penalty?: number | undefined;
|
|
368
|
+
readonly presence_penalty?: number | undefined;
|
|
369
|
+
readonly seed?: number | undefined;
|
|
370
|
+
readonly stop?: readonly string[] | undefined;
|
|
371
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
372
|
+
export declare const configure: (input: Config) => {
|
|
373
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
374
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
375
|
+
decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
376
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./cloudflare-workers-ai.js").CloudflareWorkersAIImageOptions>;
|
|
377
|
+
experimental: {
|
|
378
|
+
extraction: (modelID: string | ModelID) => import("../experimental.js").ExtractionModel<{
|
|
379
|
+
readonly [x: string]: unknown;
|
|
380
|
+
}>;
|
|
381
|
+
};
|
|
382
|
+
configure: typeof configure;
|
|
383
|
+
};
|
|
384
|
+
export declare const provider: {
|
|
385
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
386
|
+
configure: typeof configure;
|
|
387
|
+
};
|
|
388
|
+
export declare const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
|
|
389
|
+
export declare const imageModel: (modelID: string, settings: Settings) => import("../image.js").ImageModel<import("./cloudflare-workers-ai.js").CloudflareWorkersAIImageOptions>;
|
|
390
|
+
export declare const decisionModel: (modelID: string, settings: Settings) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
|
|
391
|
+
export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CloudflareRunExtraction } from "../experimental/cloudflare-run-extraction.js";
|
|
2
|
+
import { CloudflareRunDecisions } from "../protocols/cloudflare-run-decisions.js";
|
|
3
|
+
import { CloudflareWorkersAIImages } from "../protocols/cloudflare-workers-ai-images.js";
|
|
4
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
5
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
6
|
+
import { Route } from "../route/client.js";
|
|
7
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
8
|
+
import { MediaRoute } from "../route/media.js";
|
|
9
|
+
import { mergeTransport, ProviderID } from "../schema/index.js";
|
|
10
|
+
import { CloudflareShared } from "./cloudflare-shared.js";
|
|
11
|
+
export const id = ProviderID.make("cloudflare-workers-ai");
|
|
12
|
+
export const authEnvVars = ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"];
|
|
13
|
+
export const baseURL = (input) => CloudflareShared.baseURL(input, id, "CloudflareWorkersAI");
|
|
14
|
+
/** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
|
|
15
|
+
export const runBaseURL = (input) => CloudflareShared.runBaseURL(input, id, "CloudflareWorkersAI");
|
|
16
|
+
export const route = Route.make({
|
|
17
|
+
id: "cloudflare-workers-ai",
|
|
18
|
+
provider: id,
|
|
19
|
+
providerMetadataKey: "cloudflare-workers-ai",
|
|
20
|
+
protocol: OpenAIChat.protocol,
|
|
21
|
+
endpoint: Endpoint.path("/chat/completions"),
|
|
22
|
+
framing: OpenAIChat.framing,
|
|
23
|
+
});
|
|
24
|
+
export const routes = [route];
|
|
25
|
+
export const configure = (input) => {
|
|
26
|
+
const { accountId: _accountId, apiKey: _apiKey, auth: _auth, baseURL: _baseURL, ...defaults } = input;
|
|
27
|
+
const auth = AuthOptions.bearer(input, authEnvVars);
|
|
28
|
+
const configured = route.with({ ...defaults, endpoint: { baseURL: baseURL(input) }, auth });
|
|
29
|
+
// The Run API base is derived per call so a chat-only configuration without an account still constructs.
|
|
30
|
+
const runDeployment = () => MediaRoute.deployment({ ...input, baseURL: runBaseURL(input) }, auth);
|
|
31
|
+
const decision = (modelID, providerOptions) => CloudflareRunDecisions.route
|
|
32
|
+
.with({
|
|
33
|
+
provider: id,
|
|
34
|
+
endpoint: { baseURL: runBaseURL(input) },
|
|
35
|
+
auth: auth,
|
|
36
|
+
...mergeTransport(input),
|
|
37
|
+
})
|
|
38
|
+
.model({ id: modelID, providerOptions });
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
model: (modelID) => configured.model({ id: modelID }),
|
|
42
|
+
decision,
|
|
43
|
+
image: (modelID, providerOptions) => CloudflareWorkersAIImages.model({ ...runDeployment(), id: modelID, providerOptions }),
|
|
44
|
+
experimental: {
|
|
45
|
+
extraction: (modelID) => CloudflareRunExtraction.model({ ...runDeployment(), id: modelID }),
|
|
46
|
+
},
|
|
47
|
+
configure,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export const provider = { id, configure };
|
|
51
|
+
export const model = (modelID, settings) => configure(config(settings)).model(modelID);
|
|
52
|
+
export const imageModel = (modelID, settings) => {
|
|
53
|
+
const input = config(settings);
|
|
54
|
+
return configure(input).image(modelID, input.providerOptions);
|
|
55
|
+
};
|
|
56
|
+
export const decisionModel = (modelID, settings) => {
|
|
57
|
+
const input = config(settings);
|
|
58
|
+
return configure(input).decision(modelID, input.providerOptions);
|
|
59
|
+
};
|
|
60
|
+
function config(settings) {
|
|
61
|
+
const { accountId: _, apiKey, baseURL: _url, body, headers, ...providerOptions } = settings;
|
|
62
|
+
return {
|
|
63
|
+
apiKey,
|
|
64
|
+
baseURL: baseURL(settings),
|
|
65
|
+
http: { headers, body },
|
|
66
|
+
providerOptions,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { embeddingModel as model } from "../cohere.js";
|