@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,283 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import { AIError, StreamEvent, } from "../schema/index.js";
|
|
4
|
+
import { classifyProviderFailure } from "../provider-error.js";
|
|
5
|
+
import { OpenAIChat } from "./openai-chat.js";
|
|
6
|
+
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
7
|
+
import { cacheControl } from "./utils/cache.js";
|
|
8
|
+
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
9
|
+
const Parameters = Schema.Struct({
|
|
10
|
+
enableWebSearch: Schema.optional(ProviderShared.knownString()),
|
|
11
|
+
enableWebScraping: Schema.optional(Schema.Boolean),
|
|
12
|
+
enableWebCitations: Schema.optional(Schema.Boolean),
|
|
13
|
+
enableXSearch: Schema.optional(Schema.Boolean),
|
|
14
|
+
stripThinkingResponse: Schema.optional(Schema.Boolean),
|
|
15
|
+
disableThinking: Schema.optional(Schema.Boolean),
|
|
16
|
+
includeVeniceSystemPrompt: Schema.optional(Schema.Boolean),
|
|
17
|
+
characterSlug: Schema.optional(Schema.String),
|
|
18
|
+
includeSearchResultsInStream: Schema.optional(Schema.Boolean),
|
|
19
|
+
returnSearchResultsAsDocuments: Schema.optional(Schema.Boolean),
|
|
20
|
+
});
|
|
21
|
+
const Reasoning = Schema.Struct({
|
|
22
|
+
effort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
|
|
23
|
+
enabled: Schema.optional(Schema.Boolean),
|
|
24
|
+
summary: Schema.optional(ProviderShared.knownString()),
|
|
25
|
+
});
|
|
26
|
+
const Options = Schema.Struct({
|
|
27
|
+
reasoningEffort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
|
|
28
|
+
reasoning: Schema.optional(Reasoning),
|
|
29
|
+
veniceParameters: Schema.optional(Parameters),
|
|
30
|
+
promptCacheKey: Schema.optional(Schema.String),
|
|
31
|
+
promptCacheRetention: Schema.optional(ProviderShared.knownString()),
|
|
32
|
+
parallelToolCalls: Schema.optional(Schema.Boolean),
|
|
33
|
+
maxCompletionTokens: Schema.optional(Schema.Number),
|
|
34
|
+
maxTokens: Schema.optional(Schema.Number),
|
|
35
|
+
minP: Schema.optional(Schema.Number),
|
|
36
|
+
repetitionPenalty: Schema.optional(Schema.Number),
|
|
37
|
+
stopTokenIds: Schema.optional(Schema.Array(Schema.Number)),
|
|
38
|
+
logprobs: Schema.optional(Schema.Boolean),
|
|
39
|
+
topLogprobs: Schema.optional(Schema.Number),
|
|
40
|
+
maxTemp: Schema.optional(Schema.Number),
|
|
41
|
+
minTemp: Schema.optional(Schema.Number),
|
|
42
|
+
responseFormat: Schema.optional(JsonObject),
|
|
43
|
+
user: Schema.optional(Schema.String),
|
|
44
|
+
});
|
|
45
|
+
const ToolCall = Schema.Struct({
|
|
46
|
+
...OpenAIChat.OpenAIChatAssistantToolCall.fields,
|
|
47
|
+
thought_signature: Schema.optional(Schema.String),
|
|
48
|
+
});
|
|
49
|
+
const Assistant = Schema.StructWithRest(Schema.Struct({
|
|
50
|
+
...OpenAIChat.OpenAIChatMessage.cases.assistant.schema.fields,
|
|
51
|
+
tool_calls: optionalArray(Schema.Union([ToolCall, OpenAIChat.OpenAIChatAssistantCustomToolCall])),
|
|
52
|
+
thought_signature: Schema.optional(Schema.String),
|
|
53
|
+
}), [JsonObject]);
|
|
54
|
+
const Messages = Schema.Array(Schema.Union([
|
|
55
|
+
OpenAIChat.OpenAIChatMessage.cases.system,
|
|
56
|
+
OpenAIChat.OpenAIChatMessage.cases.user,
|
|
57
|
+
Assistant,
|
|
58
|
+
OpenAIChat.OpenAIChatMessage.cases.tool,
|
|
59
|
+
]));
|
|
60
|
+
const Body = Schema.Struct({
|
|
61
|
+
...OpenAIChat.bodyFields,
|
|
62
|
+
messages: Messages,
|
|
63
|
+
reasoning: Schema.optional(Reasoning),
|
|
64
|
+
venice_parameters: Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.Boolean])),
|
|
65
|
+
prompt_cache_retention: Options.fields.promptCacheRetention,
|
|
66
|
+
parallel_tool_calls: Options.fields.parallelToolCalls,
|
|
67
|
+
min_p: Options.fields.minP,
|
|
68
|
+
top_k: Schema.optional(Schema.Number),
|
|
69
|
+
repetition_penalty: Options.fields.repetitionPenalty,
|
|
70
|
+
stop_token_ids: Options.fields.stopTokenIds,
|
|
71
|
+
logprobs: Options.fields.logprobs,
|
|
72
|
+
top_logprobs: Options.fields.topLogprobs,
|
|
73
|
+
max_temp: Options.fields.maxTemp,
|
|
74
|
+
min_temp: Options.fields.minTemp,
|
|
75
|
+
response_format: Options.fields.responseFormat,
|
|
76
|
+
user: Options.fields.user,
|
|
77
|
+
});
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// Streaming schemas and state
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
const ToolDelta = Schema.Struct({
|
|
82
|
+
...OpenAIChat.OpenAIChatToolCallDelta.fields,
|
|
83
|
+
thought_signature: optionalNull(Schema.String),
|
|
84
|
+
});
|
|
85
|
+
const Delta = Schema.StructWithRest(Schema.Struct({
|
|
86
|
+
...OpenAIChat.OpenAIChatDelta.schema.fields,
|
|
87
|
+
tool_calls: optionalNull(Schema.Array(ToolDelta)),
|
|
88
|
+
thought_signature: optionalNull(Schema.String),
|
|
89
|
+
}), [JsonObject]);
|
|
90
|
+
const Choice = Schema.StructWithRest(Schema.Struct({ ...OpenAIChat.OpenAIChatChoice.schema.fields, delta: optionalNull(Delta) }), [JsonObject]);
|
|
91
|
+
const Usage = Schema.StructWithRest(Schema.Struct({
|
|
92
|
+
...OpenAIChat.OpenAIChatUsage.schema.fields,
|
|
93
|
+
prompt_tokens_details: optionalNull(Schema.StructWithRest(Schema.Struct({
|
|
94
|
+
cached_tokens: optionalNull(Schema.Number),
|
|
95
|
+
cache_write_tokens: optionalNull(Schema.Number),
|
|
96
|
+
cache_creation_input_tokens: optionalNull(Schema.Number),
|
|
97
|
+
}), [JsonObject])),
|
|
98
|
+
}), [JsonObject]);
|
|
99
|
+
const Event = Schema.StructWithRest(Schema.Struct({
|
|
100
|
+
...OpenAIChat.OpenAIChatEvent.schema.fields,
|
|
101
|
+
choices: optionalNull(Schema.Array(Choice)),
|
|
102
|
+
usage: optionalNull(Usage),
|
|
103
|
+
error: optionalNull(Schema.Union([Schema.String, OpenAIChat.OpenAIChatEvent.schema.fields.error.schema])),
|
|
104
|
+
issues: optionalArray(Schema.Struct({
|
|
105
|
+
message: Schema.String,
|
|
106
|
+
path: Schema.optional(Schema.Array(Schema.Union([Schema.String, Schema.Number]))),
|
|
107
|
+
})),
|
|
108
|
+
}), [JsonObject]);
|
|
109
|
+
const MARKER = "__ENCRYPTED_REASONING__";
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Request lowering
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
114
|
+
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
|
|
115
|
+
const body = yield* OpenAIChat.fromRequest(request, {
|
|
116
|
+
cacheControl: cacheControl(),
|
|
117
|
+
assistant: (source, message) => {
|
|
118
|
+
if (message.role !== "assistant")
|
|
119
|
+
return message;
|
|
120
|
+
const parts = source.content.filter((part) => part.type === "text" || part.type === "reasoning" || part.type === "tool-call");
|
|
121
|
+
const calls = source.content.filter((part) => part.type === "tool-call");
|
|
122
|
+
const signature = parts
|
|
123
|
+
.map((part) => part.providerMetadata?.venice?.messageThoughtSignature)
|
|
124
|
+
.find((value) => typeof value === "string");
|
|
125
|
+
const raw = parts
|
|
126
|
+
.map((part) => part.providerMetadata?.venice?.encryptedReasoningContent)
|
|
127
|
+
.find((value) => typeof value === "string");
|
|
128
|
+
return {
|
|
129
|
+
...message,
|
|
130
|
+
...(signature === undefined ? {} : { thought_signature: signature }),
|
|
131
|
+
...(raw === undefined ? {} : { reasoning_content: raw }),
|
|
132
|
+
tool_calls: message.tool_calls?.map((call, index) => {
|
|
133
|
+
const signature = calls[index]?.providerMetadata?.venice?.thoughtSignature;
|
|
134
|
+
return { ...call, ...(typeof signature === "string" ? { thought_signature: signature } : {}) };
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
...body,
|
|
141
|
+
max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.maxTokens,
|
|
142
|
+
reasoning_effort: undefined,
|
|
143
|
+
reasoning: options.reasoningEffort === undefined
|
|
144
|
+
? options.reasoning
|
|
145
|
+
: { ...options.reasoning, effort: options.reasoningEffort },
|
|
146
|
+
// Match the previous Venice SDK default, not the gateway's added prompt.
|
|
147
|
+
venice_parameters: Object.fromEntries(Object.entries({
|
|
148
|
+
...options.veniceParameters,
|
|
149
|
+
includeVeniceSystemPrompt: options.veniceParameters?.includeVeniceSystemPrompt ?? false,
|
|
150
|
+
})
|
|
151
|
+
.filter(([, value]) => value !== undefined)
|
|
152
|
+
.map(([key, value]) => [key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), value])),
|
|
153
|
+
prompt_cache_retention: options.promptCacheRetention ?? body.prompt_cache_retention,
|
|
154
|
+
parallel_tool_calls: options.parallelToolCalls,
|
|
155
|
+
min_p: options.minP,
|
|
156
|
+
top_k: request.topK,
|
|
157
|
+
repetition_penalty: options.repetitionPenalty,
|
|
158
|
+
stop_token_ids: options.stopTokenIds,
|
|
159
|
+
logprobs: options.logprobs,
|
|
160
|
+
top_logprobs: options.topLogprobs,
|
|
161
|
+
max_temp: options.maxTemp,
|
|
162
|
+
min_temp: options.minTemp,
|
|
163
|
+
response_format: options.responseFormat,
|
|
164
|
+
user: options.user,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
// Venice normalization around the shared Chat state machine
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
const step = Effect.fnUntraced(function* (state, event) {
|
|
171
|
+
if (typeof event.error === "string")
|
|
172
|
+
return yield* new AIError({
|
|
173
|
+
reason: classifyProviderFailure({
|
|
174
|
+
message: [
|
|
175
|
+
event.error,
|
|
176
|
+
...(event.issues ?? []).map((issue) => `${issue.path?.length ? `${issue.path.join(".")}: ` : ""}${issue.message}`),
|
|
177
|
+
].join("; "),
|
|
178
|
+
rawBody: ProviderShared.encodeJson(event),
|
|
179
|
+
}),
|
|
180
|
+
});
|
|
181
|
+
const delta = event.choices?.[0]?.delta;
|
|
182
|
+
const scalar = delta?.reasoning_content ?? "";
|
|
183
|
+
const text = state.pending + scalar;
|
|
184
|
+
const marker = text.indexOf(MARKER);
|
|
185
|
+
const pending = marker >= 0 || state.encrypted
|
|
186
|
+
? 0
|
|
187
|
+
: (Array.from({ length: Math.min(text.length, MARKER.length - 1) }, (_, index) => index + 1)
|
|
188
|
+
.filter((length) => text.endsWith(MARKER.slice(0, length)))
|
|
189
|
+
.at(-1) ?? 0);
|
|
190
|
+
const visible = state.encrypted ? "" : marker >= 0 ? text.slice(0, marker) : text.slice(0, text.length - pending);
|
|
191
|
+
const result = yield* OpenAIChat.protocol.stream.step(state.shared, {
|
|
192
|
+
...event,
|
|
193
|
+
error: event.error,
|
|
194
|
+
usage: event.usage
|
|
195
|
+
? {
|
|
196
|
+
...event.usage,
|
|
197
|
+
prompt_tokens_details: event.usage.prompt_tokens_details
|
|
198
|
+
? {
|
|
199
|
+
...event.usage.prompt_tokens_details,
|
|
200
|
+
cache_write_tokens: event.usage.prompt_tokens_details.cache_write_tokens ??
|
|
201
|
+
event.usage.prompt_tokens_details.cache_creation_input_tokens,
|
|
202
|
+
}
|
|
203
|
+
: event.usage.prompt_tokens_details,
|
|
204
|
+
}
|
|
205
|
+
: event.usage,
|
|
206
|
+
choices: event.choices?.map((choice, index) => index === 0 && choice.delta
|
|
207
|
+
? {
|
|
208
|
+
...choice,
|
|
209
|
+
delta: {
|
|
210
|
+
...choice.delta,
|
|
211
|
+
reasoning_content: visible || undefined,
|
|
212
|
+
// Opaque-only scalar reasoning still needs a canonical part for replay.
|
|
213
|
+
reasoning_details: choice.delta.reasoning_details ?? (marker >= 0 ? [] : undefined),
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
: choice),
|
|
217
|
+
});
|
|
218
|
+
const tools = { ...state.tools };
|
|
219
|
+
for (const call of delta?.tool_calls ?? []) {
|
|
220
|
+
if (!call.thought_signature)
|
|
221
|
+
continue;
|
|
222
|
+
const index = call.index ?? result[0].latestToolIndex;
|
|
223
|
+
const id = call.id ?? (index === undefined ? undefined : (result[0].tools[index]?.id ?? result[0].pendingTools[index]?.id));
|
|
224
|
+
if (id)
|
|
225
|
+
tools[id] = call.thought_signature;
|
|
226
|
+
}
|
|
227
|
+
return [
|
|
228
|
+
{
|
|
229
|
+
shared: result[0],
|
|
230
|
+
pending: pending ? text.slice(-pending) : "",
|
|
231
|
+
reasoning: state.reasoning + scalar,
|
|
232
|
+
encrypted: state.encrypted || marker >= 0,
|
|
233
|
+
signature: delta?.thought_signature ?? state.signature,
|
|
234
|
+
tools,
|
|
235
|
+
},
|
|
236
|
+
result[1],
|
|
237
|
+
];
|
|
238
|
+
});
|
|
239
|
+
const onHalt = Effect.fnUntraced(function* (state) {
|
|
240
|
+
const events = yield* OpenAIChat.finishEvents(state.shared);
|
|
241
|
+
return events.flatMap((event) => {
|
|
242
|
+
if (event.type !== "reasoning-end" &&
|
|
243
|
+
event.type !== "text-end" &&
|
|
244
|
+
event.type !== "tool-call" &&
|
|
245
|
+
event.type !== "tool-input-end")
|
|
246
|
+
return [event];
|
|
247
|
+
const signature = event.type === "tool-call" || event.type === "tool-input-end" ? state.tools[event.id] : undefined;
|
|
248
|
+
const providerMetadata = {
|
|
249
|
+
...event.providerMetadata,
|
|
250
|
+
venice: {
|
|
251
|
+
...event.providerMetadata?.venice,
|
|
252
|
+
...(state.signature ? { messageThoughtSignature: state.signature } : {}),
|
|
253
|
+
...(signature ? { thoughtSignature: signature } : {}),
|
|
254
|
+
...(event.type === "reasoning-end" && state.encrypted ? { encryptedReasoningContent: state.reasoning } : {}),
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
if (event.type === "reasoning-end" && state.pending)
|
|
258
|
+
return [StreamEvent.reasoningDelta({ id: event.id, text: state.pending }), { ...event, providerMetadata }];
|
|
259
|
+
return [{ ...event, providerMetadata }];
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
export const compatibility = {
|
|
263
|
+
maxTokensField: "max_completion_tokens",
|
|
264
|
+
};
|
|
265
|
+
export const capabilities = { cache: { affinity: true } };
|
|
266
|
+
export const protocol = Protocol.make({
|
|
267
|
+
id: "venice-chat",
|
|
268
|
+
body: { schema: Body, from: fromRequest },
|
|
269
|
+
stream: {
|
|
270
|
+
event: Schema.Union([Schema.Literal("[DONE]"), Protocol.jsonEvent(Event)]),
|
|
271
|
+
initial: (request) => ({
|
|
272
|
+
shared: OpenAIChat.protocol.stream.initial(request),
|
|
273
|
+
pending: "",
|
|
274
|
+
reasoning: "",
|
|
275
|
+
encrypted: false,
|
|
276
|
+
tools: {},
|
|
277
|
+
}),
|
|
278
|
+
step: (state, event) => (event === "[DONE]" ? Effect.succeed([state, []]) : step(state, event)),
|
|
279
|
+
terminal: (event) => event === "[DONE]",
|
|
280
|
+
onHalt,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
export * as VeniceChat from "./venice-chat.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { type OpenString } from "../schema/index.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.x.ai/v1";
|
|
6
|
+
export declare const PATH = "/images/generations";
|
|
7
|
+
export declare const EDIT_PATH = "/images/edits";
|
|
8
|
+
/** Provider-native options. Common fields (`n`, `aspect`, `resolution`, `images`) live on the request. */
|
|
9
|
+
export type XAIImageOptions = {
|
|
10
|
+
/** Defaults to `b64_json`; `url` returns a short-lived hosted URL instead. */
|
|
11
|
+
readonly responseFormat?: OpenString<"url" | "b64_json">;
|
|
12
|
+
readonly response_format?: OpenString<"url" | "b64_json">;
|
|
13
|
+
} & Record<string, unknown>;
|
|
14
|
+
export type Request = ImageRequest<ImageModel<XAIImageOptions>>;
|
|
15
|
+
/** xAI renders `1k` or `2k`; other tiers use the nearest one. */
|
|
16
|
+
export declare const resolution: (request: {
|
|
17
|
+
readonly resolution?: string;
|
|
18
|
+
}) => "1k" | "2k" | undefined;
|
|
19
|
+
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
20
|
+
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<XAIImageOptions>;
|
|
21
|
+
export declare const XAIImages: {
|
|
22
|
+
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
23
|
+
readonly model: typeof model;
|
|
24
|
+
readonly resolution: typeof resolution;
|
|
25
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
+
import { Media } from "../media.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { MediaRoute } from "../route/media.js";
|
|
6
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
7
|
+
import { JsonObject, ProviderShared, lenient, optionalNull } from "./shared.js";
|
|
8
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
9
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
10
|
+
const route = MediaProtocol.identity({ id: "xai-images", name: "xAI Images", provider: "xai" });
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.x.ai/v1";
|
|
12
|
+
export const PATH = "/images/generations";
|
|
13
|
+
export const EDIT_PATH = "/images/edits";
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 2. Response schema
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
const XAIImageResponse = Schema.Struct({
|
|
18
|
+
data: Schema.Array(Schema.Struct({
|
|
19
|
+
b64_json: optionalNull(Schema.String),
|
|
20
|
+
url: optionalNull(Schema.String),
|
|
21
|
+
revised_prompt: optionalNull(Schema.String),
|
|
22
|
+
mime_type: optionalNull(Schema.String),
|
|
23
|
+
})),
|
|
24
|
+
usage: lenient(JsonObject),
|
|
25
|
+
});
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// 5. Request body construction
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
const nativeOptions = (options) => {
|
|
30
|
+
const { responseFormat, ...native } = options ?? {};
|
|
31
|
+
return { response_format: responseFormat ?? "b64_json", ...native };
|
|
32
|
+
};
|
|
33
|
+
/** xAI renders `1k` or `2k`; other tiers use the nearest one. */
|
|
34
|
+
export const resolution = (request) => {
|
|
35
|
+
if (request.resolution === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
return (ImageSizing.tier(request.resolution) ?? 1) < 1.5 ? "1k" : "2k";
|
|
38
|
+
};
|
|
39
|
+
const isEdit = (request) => (request.images?.length ?? 0) > 0;
|
|
40
|
+
const reference = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((item) => item.type === "ref" ? { file_id: item.value } : { url: item.value, type: "image_url" }));
|
|
41
|
+
const fromRequest = Effect.fn("XAIImages.fromRequest")(function* (request) {
|
|
42
|
+
const references = yield* Effect.forEach(request.images ?? [], reference);
|
|
43
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
44
|
+
model: request.model.id,
|
|
45
|
+
prompt: request.prompt,
|
|
46
|
+
// xAI takes one edit source as `image` and several as `images`.
|
|
47
|
+
image: references.length === 1 ? references[0] : undefined,
|
|
48
|
+
images: references.length > 1 ? references : undefined,
|
|
49
|
+
n: request.n,
|
|
50
|
+
aspect_ratio: request.aspect,
|
|
51
|
+
resolution: resolution(request),
|
|
52
|
+
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
53
|
+
});
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// 6. Response decoding
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
const decodeDocument = route.decodeJson(XAIImageResponse);
|
|
58
|
+
const decodeResponse = Effect.fn("XAIImages.decodeResponse")(function* (response) {
|
|
59
|
+
const output = yield* decodeDocument(response);
|
|
60
|
+
const decoded = output.value;
|
|
61
|
+
const images = yield* Effect.forEach(decoded.data, (item, index) => MediaInput.imageOutput(output.invalid, `${route.name} result ${index}`, item, item.mime_type ?? undefined, {
|
|
62
|
+
providerMetadata: item.revised_prompt === undefined || item.revised_prompt === null
|
|
63
|
+
? undefined
|
|
64
|
+
: { xai: { revisedPrompt: item.revised_prompt } },
|
|
65
|
+
}));
|
|
66
|
+
if (images.length === 0)
|
|
67
|
+
return yield* output.invalid(`${route.name} returned no images`);
|
|
68
|
+
// xAI reports a USD cost (`cost_in_usd_ticks`) rather than tokens, seconds, or credits; the raw record stays in
|
|
69
|
+
// provider metadata.
|
|
70
|
+
return new ImageResponse({
|
|
71
|
+
images,
|
|
72
|
+
providerMetadata: decoded.usage === undefined ? undefined : { xai: { usage: decoded.usage } },
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// 7. Protocol and route
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
79
|
+
body: { from: fromRequest },
|
|
80
|
+
response: { decode: decodeResponse },
|
|
81
|
+
});
|
|
82
|
+
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: ({ request }) => (isEdit(request) ? EDIT_PATH : PATH) }, input);
|
|
83
|
+
export const XAIImages = {
|
|
84
|
+
protocol,
|
|
85
|
+
model,
|
|
86
|
+
resolution,
|
|
87
|
+
};
|