@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,217 @@
|
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import { Media } from "../media.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { VideoModel, VideoResponse, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
// One Ark API (`/contents/generations/tasks`) served by Volcengine Ark in China and BytePlus ModelArk elsewhere.
|
|
9
|
+
export const VOLCENGINE_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
10
|
+
export const BYTEPLUS_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
11
|
+
export const PATH = "/contents/generations/tasks";
|
|
12
|
+
// Video and last-frame URLs are documented as valid for 24 hours.
|
|
13
|
+
const OUTPUT_RETENTION = Duration.hours(24);
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 2. Token and response schemas
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
18
|
+
export const Token = Schema.String;
|
|
19
|
+
const StartResponse = Schema.Struct({ id: Schema.String });
|
|
20
|
+
const Task = Schema.Struct({
|
|
21
|
+
id: optionalNull(Schema.String),
|
|
22
|
+
model: optionalNull(Schema.String),
|
|
23
|
+
status: Schema.String,
|
|
24
|
+
content: optionalNull(Schema.Struct({
|
|
25
|
+
video_url: optionalNull(Schema.String),
|
|
26
|
+
last_frame_url: optionalNull(Schema.String),
|
|
27
|
+
})),
|
|
28
|
+
error: optionalNull(Schema.Struct({
|
|
29
|
+
code: optionalNull(Schema.String),
|
|
30
|
+
message: optionalNull(Schema.String),
|
|
31
|
+
})),
|
|
32
|
+
usage: optionalNull(Schema.Struct({
|
|
33
|
+
completion_tokens: optionalNull(Schema.Number),
|
|
34
|
+
total_tokens: optionalNull(Schema.Number),
|
|
35
|
+
})),
|
|
36
|
+
updated_at: optionalNull(Schema.Number),
|
|
37
|
+
seed: optionalNull(Schema.Number),
|
|
38
|
+
resolution: optionalNull(Schema.String),
|
|
39
|
+
ratio: optionalNull(Schema.String),
|
|
40
|
+
duration: optionalNull(Schema.Number),
|
|
41
|
+
frames: optionalNull(Schema.Number),
|
|
42
|
+
framespersecond: optionalNull(Schema.Number),
|
|
43
|
+
generate_audio: optionalNull(Schema.Boolean),
|
|
44
|
+
output_format: optionalNull(Schema.String),
|
|
45
|
+
draft: optionalNull(Schema.Boolean),
|
|
46
|
+
service_tier: optionalNull(Schema.String),
|
|
47
|
+
});
|
|
48
|
+
const STATUS = {
|
|
49
|
+
queued: "running",
|
|
50
|
+
running: "running",
|
|
51
|
+
succeeded: "completed",
|
|
52
|
+
failed: "failed",
|
|
53
|
+
cancelled: "cancelled",
|
|
54
|
+
expired: "expired",
|
|
55
|
+
};
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// 3. Failures
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Ark error codes are dotted (`InvalidParameter.TaskTypeConstraint`); the leading segment is the category.
|
|
60
|
+
// `InternalServiceError`, `ServerOverloaded` and unknown codes are provider-side.
|
|
61
|
+
const FAILURE = {
|
|
62
|
+
InvalidParameter: "InvalidRequest",
|
|
63
|
+
MissingParameter: "InvalidRequest",
|
|
64
|
+
InvalidArgumentError: "InvalidRequest",
|
|
65
|
+
InvalidImageURL: "InvalidRequest",
|
|
66
|
+
AuthenticationError: "Authentication",
|
|
67
|
+
AccessDenied: "Authentication",
|
|
68
|
+
QuotaExceeded: "RateLimit",
|
|
69
|
+
RateLimitExceeded: "RateLimit",
|
|
70
|
+
};
|
|
71
|
+
// Input and output moderation codes: `InputImageSensitiveContentDetected.PrivacyInformation`,
|
|
72
|
+
// `OutputVideoSensitiveContentDetected`, `SensitiveContentDetected`, ...
|
|
73
|
+
const moderated = (code) => code !== undefined && code.includes("SensitiveContentDetected");
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// 4. Request body construction
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
const nativeOptions = (options) => {
|
|
78
|
+
if (!options)
|
|
79
|
+
return undefined;
|
|
80
|
+
const { draft_task: _draftTask, ...native } = options;
|
|
81
|
+
return native;
|
|
82
|
+
};
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// 5. Response decoding
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Ark returns `frames` when the request set it, otherwise `duration` rounded down to whole seconds.
|
|
87
|
+
const durationSeconds = (task) => {
|
|
88
|
+
if (task.frames !== undefined && task.frames !== null && task.framespersecond)
|
|
89
|
+
return task.frames / task.framespersecond;
|
|
90
|
+
return task.duration ?? undefined;
|
|
91
|
+
};
|
|
92
|
+
const make = (provider) => {
|
|
93
|
+
const route = MediaProtocol.identity({ id: "seedance-video", name: "Seedance Video", provider });
|
|
94
|
+
// `asset://<ID>` addresses a ModelArk digital character or authorized asset.
|
|
95
|
+
const item = (asset, type, role) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => ({
|
|
96
|
+
type,
|
|
97
|
+
[type]: { url: reference.type === "ref" ? `asset://${reference.value}` : reference.value },
|
|
98
|
+
role,
|
|
99
|
+
})));
|
|
100
|
+
const reference = (asset) => {
|
|
101
|
+
if (asset.kind === "video")
|
|
102
|
+
return item(asset, "video_url", "reference_video");
|
|
103
|
+
if (asset.kind === "audio")
|
|
104
|
+
return item(asset, "audio_url", "reference_audio");
|
|
105
|
+
return item(asset, "image_url", "reference_image");
|
|
106
|
+
};
|
|
107
|
+
// Frames and references are separate Seedance modes; mixing them is sent as-is and rejected by the provider.
|
|
108
|
+
const fromRequest = Effect.fn("SeedanceVideo.fromRequest")(function* (request) {
|
|
109
|
+
const content = [
|
|
110
|
+
// Every media mode accepts an optional prompt, so an empty one adds no text item.
|
|
111
|
+
...(request.prompt === "" ? [] : [{ type: "text", text: request.prompt }]),
|
|
112
|
+
...(request.start === undefined ? [] : [yield* item(request.start, "image_url", "first_frame")]),
|
|
113
|
+
...(request.end === undefined ? [] : [yield* item(request.end, "image_url", "last_frame")]),
|
|
114
|
+
...(yield* Effect.forEach(request.references ?? [], reference)),
|
|
115
|
+
...(request.providerOptions?.draft_task === undefined
|
|
116
|
+
? []
|
|
117
|
+
: [{ type: "draft_task", draft_task: request.providerOptions.draft_task }]),
|
|
118
|
+
];
|
|
119
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
120
|
+
model: request.model.id,
|
|
121
|
+
content,
|
|
122
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
123
|
+
ratio: request.aspect === "auto" ? "adaptive" : request.aspect,
|
|
124
|
+
resolution: request.resolution,
|
|
125
|
+
generate_audio: request.sound,
|
|
126
|
+
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
127
|
+
});
|
|
128
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
129
|
+
token: value.id,
|
|
130
|
+
snapshot: { id: value.id, status: "running" },
|
|
131
|
+
}));
|
|
132
|
+
const decodeTask = route.decodeJson(Task);
|
|
133
|
+
const decodeStatus = Effect.fn("SeedanceVideo.decodeStatus")(function* (response, context) {
|
|
134
|
+
const output = yield* decodeTask(response);
|
|
135
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
136
|
+
});
|
|
137
|
+
const decodeResult = Effect.fn("SeedanceVideo.decodeResult")(function* (response, context) {
|
|
138
|
+
const output = yield* decodeTask(response);
|
|
139
|
+
const task = output.value;
|
|
140
|
+
const status = MediaProtocol.state(STATUS, task.status);
|
|
141
|
+
if (status === "running")
|
|
142
|
+
return yield* output.pending(context.token);
|
|
143
|
+
if (status === "failed") {
|
|
144
|
+
const code = task.error?.code ?? undefined;
|
|
145
|
+
const detail = task.error?.message ?? undefined;
|
|
146
|
+
const message = `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${detail === undefined ? "" : `: ${detail}`}`;
|
|
147
|
+
if (moderated(code))
|
|
148
|
+
return yield* output.contentPolicy(message);
|
|
149
|
+
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, code?.split(".")[0]));
|
|
150
|
+
}
|
|
151
|
+
if (status === "cancelled")
|
|
152
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
|
|
153
|
+
if (status === "expired")
|
|
154
|
+
return yield* output.ended("expired", `${route.name} task ${context.token} expired`);
|
|
155
|
+
const videoURL = task.content?.video_url ?? undefined;
|
|
156
|
+
if (videoURL === undefined)
|
|
157
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
158
|
+
const duration = durationSeconds(task);
|
|
159
|
+
const options = {
|
|
160
|
+
mediaType: task.output_format === "mov" ? "video/quicktime" : "video/mp4",
|
|
161
|
+
info: duration === undefined ? undefined : { durationSeconds: duration },
|
|
162
|
+
};
|
|
163
|
+
// `updated_at` is when the task reached `succeeded`, which starts the URL's retention window.
|
|
164
|
+
const video = task.updated_at === undefined || task.updated_at === null
|
|
165
|
+
? yield* MediaProtocol.expiringUrl(videoURL, OUTPUT_RETENTION, options)
|
|
166
|
+
: Media.url(videoURL, {
|
|
167
|
+
...options,
|
|
168
|
+
expiresAt: task.updated_at * 1000 + Duration.toMillis(OUTPUT_RETENTION),
|
|
169
|
+
});
|
|
170
|
+
return new VideoResponse({
|
|
171
|
+
videos: [video],
|
|
172
|
+
usage: task.usage?.completion_tokens === undefined || task.usage.completion_tokens === null
|
|
173
|
+
? undefined
|
|
174
|
+
: {
|
|
175
|
+
type: "tokens",
|
|
176
|
+
output: task.usage.completion_tokens,
|
|
177
|
+
total: task.usage.total_tokens ?? undefined,
|
|
178
|
+
},
|
|
179
|
+
providerMetadata: {
|
|
180
|
+
[provider]: {
|
|
181
|
+
taskId: context.token,
|
|
182
|
+
model: task.model ?? undefined,
|
|
183
|
+
seed: task.seed ?? undefined,
|
|
184
|
+
ratio: task.ratio ?? undefined,
|
|
185
|
+
resolution: task.resolution ?? undefined,
|
|
186
|
+
duration: task.duration ?? undefined,
|
|
187
|
+
frames: task.frames ?? undefined,
|
|
188
|
+
framesPerSecond: task.framespersecond ?? undefined,
|
|
189
|
+
generateAudio: task.generate_audio ?? undefined,
|
|
190
|
+
outputFormat: task.output_format ?? undefined,
|
|
191
|
+
draft: task.draft ?? undefined,
|
|
192
|
+
serviceTier: task.service_tier ?? undefined,
|
|
193
|
+
lastFrameUrl: task.content?.last_frame_url ?? undefined,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
const taskPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
199
|
+
// DELETE cancels a queued task. Ark refuses it for a running task, and deletes the record of a finished one.
|
|
200
|
+
const protocol = MediaProtocol.queued(route, {
|
|
201
|
+
token: Token,
|
|
202
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
203
|
+
status: { path: taskPath, decode: decodeStatus },
|
|
204
|
+
result: { path: taskPath, decode: decodeResult },
|
|
205
|
+
cancel: { method: "DELETE", path: taskPath },
|
|
206
|
+
});
|
|
207
|
+
const model = (input) => VideoModel.fromRoute({
|
|
208
|
+
protocol,
|
|
209
|
+
baseURL: provider === "volcengine" ? VOLCENGINE_BASE_URL : BYTEPLUS_BASE_URL,
|
|
210
|
+
path: PATH,
|
|
211
|
+
}, input);
|
|
212
|
+
return { protocol, model };
|
|
213
|
+
};
|
|
214
|
+
export const SeedanceVideo = {
|
|
215
|
+
volcengine: make("volcengine"),
|
|
216
|
+
byteplus: make("byteplus"),
|
|
217
|
+
};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { Tool } from "@radheim/schema/tool";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import { Headers, HttpClientRequest } from "effect/http";
|
|
4
|
+
import { Media } from "../media.js";
|
|
5
|
+
import { AIError, type LLMRequest, ToolDefinition, type ContentPart, MediaPart, type OpenString, type ProviderID, type RequestEncoding, type ToolEntry, type ToolResultPart } from "../schema/index.js";
|
|
6
|
+
import { Json, decodeJson, encodeJson } from "../utils/json.js";
|
|
7
|
+
import { isRecord } from "../utils/record.js";
|
|
8
|
+
export { Json, decodeJson, encodeJson, isRecord };
|
|
9
|
+
export declare const JsonObject: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
10
|
+
export declare const optionalArray: <const S extends Schema.Top>(schema: S) => Schema.optional<Schema.$Array<S>>;
|
|
11
|
+
export declare const optionalNull: <const S extends Schema.Top>(schema: S) => Schema.optional<Schema.NullOr<S>>;
|
|
12
|
+
/** Optional provider field where an explicit `null` means absent, so decoding never yields `null`. */
|
|
13
|
+
export declare const optionalNullish: <const S extends Schema.Top>(schema: S) => Schema.decodeTo<Schema.optional<Schema.toType<S>>, Schema.optional<Schema.NullOr<S>>, never, never>;
|
|
14
|
+
/** Optional field whose malformed value decodes to `undefined` instead of failing the enclosing struct. */
|
|
15
|
+
export declare const lenient: <const S extends Schema.Top>(schema: S) => Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<S>, S["DecodingServices"]>>;
|
|
16
|
+
/** Billing an endpoint reports beside its token usage: `cost` is the USD it charged (OpenRouter, LiteLLM, OpenCode Zen). */
|
|
17
|
+
export declare const ReportedBilling: Schema.Struct<{
|
|
18
|
+
readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it, or
|
|
22
|
+
* Copilot's billing from the frames that carry the usage.
|
|
23
|
+
*/
|
|
24
|
+
export declare const reportedBilling: (usage: unknown, ...frames: ReadonlyArray<unknown>) => {
|
|
25
|
+
cost: number;
|
|
26
|
+
} | {
|
|
27
|
+
cost?: undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The filter that blocked a response, from maps keyed by filter name: Azure's `content_filter_results`
|
|
31
|
+
* (`{ hate: { filtered: true } }`) or GitHub Copilot's `copilot_annotations` (`{ TextCopyright: [...] }`).
|
|
32
|
+
*/
|
|
33
|
+
export declare const contentFilterCategory: (...sources: ReadonlyArray<unknown>) => string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Accepts stream frames that carry no `type`, alongside the typed event schema. Gateways inject such frames as
|
|
36
|
+
* keep-alives, so they decode as an ignored event; one with an `error` still decodes as an error event.
|
|
37
|
+
*/
|
|
38
|
+
export declare const withUntypedFrames: <const S extends Schema.Codec<{
|
|
39
|
+
readonly type: string;
|
|
40
|
+
}, {
|
|
41
|
+
readonly type: string;
|
|
42
|
+
}>>(event: S) => Schema.Union<readonly [S, Schema.decodeTo<S, Schema.$Record<Schema.String, Schema.Unknown>, never, never>]>;
|
|
43
|
+
/** Provider-defined string enum: known values for autocomplete, any string accepted at runtime. */
|
|
44
|
+
export declare const knownString: <Known extends string>() => Schema.declare<OpenString<Known>, OpenString<Known>>;
|
|
45
|
+
export declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
46
|
+
export declare const acceptsAffinity: (model: LLMRequest["model"]) => boolean | undefined;
|
|
47
|
+
export declare const sendsPromptCacheKey: (request: LLMRequest) => boolean;
|
|
48
|
+
export declare const promptCacheKey: (request: LLMRequest) => string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Streaming tool-call accumulator. Adapters that build a tool call across
|
|
51
|
+
* multiple `tool-input-delta` chunks store the partial JSON input string here
|
|
52
|
+
* and finalize it with `parseToolInput` once the call completes.
|
|
53
|
+
*/
|
|
54
|
+
export interface ToolAccumulator {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly namespace?: string;
|
|
58
|
+
readonly input: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `Usage.totalTokens` policy shared by every route. Honors a provider-
|
|
62
|
+
* supplied total; otherwise falls back to `inputTokens + outputTokens` only
|
|
63
|
+
* when at least one is defined. Returns `undefined` when neither input nor
|
|
64
|
+
* output is known so routes don't publish a misleading `0`.
|
|
65
|
+
*
|
|
66
|
+
* Under the inclusive `AI.Usage` contract, `inputTokens` includes cached input
|
|
67
|
+
* and `outputTokens` includes reasoning. Protocol mappers normalize those
|
|
68
|
+
* inclusive values before calling this helper. The provider-supplied total is
|
|
69
|
+
* the source of truth when present; otherwise their sum is the canonical total.
|
|
70
|
+
*/
|
|
71
|
+
export declare const totalTokens: (inputTokens: number | undefined, outputTokens: number | undefined, total: number | undefined) => number | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Subtract `subtrahend` from `total`, clamping to zero if the provider
|
|
74
|
+
* reports a non-sensical breakdown (e.g. `cached_tokens > prompt_tokens`).
|
|
75
|
+
* Used by protocol mappers when deriving a non-overlapping breakdown field
|
|
76
|
+
* from a provider's inclusive total — `nonCachedInputTokens` from
|
|
77
|
+
* `inputTokens - cacheReadInputTokens - cacheWriteInputTokens`.
|
|
78
|
+
*
|
|
79
|
+
* If `total` is `undefined`, returns `undefined` (we don't fabricate
|
|
80
|
+
* counts). If `subtrahend` is `undefined`, returns `total` unchanged. The
|
|
81
|
+
* provider-native breakdown stays available on `Usage.providerMetadata` for debugging.
|
|
82
|
+
*/
|
|
83
|
+
export declare const subtractTokens: (total: number | undefined, subtrahend: number | undefined) => number | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Sum a list of optional token counts, returning `undefined` only when
|
|
86
|
+
* every value is `undefined` (so we don't fabricate a `0`). Used by
|
|
87
|
+
* protocol mappers to derive the inclusive `inputTokens` total from a
|
|
88
|
+
* provider that natively reports a non-overlapping breakdown
|
|
89
|
+
* (e.g. Anthropic, whose `input_tokens` is already non-cached only).
|
|
90
|
+
*/
|
|
91
|
+
export declare const sumTokens: (...values: ReadonlyArray<number | undefined>) => number | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Caps an explicit thinking budget at half the output limit. Thinking counts against the output limit, so a budget
|
|
94
|
+
* near it leaves the answer, a tool call, or a summary without room. Smaller budgets, special values such as `-1` and
|
|
95
|
+
* `0`, and requests without an output limit pass through unchanged.
|
|
96
|
+
*/
|
|
97
|
+
export declare const fitThinkingBudget: (budget: number, maxTokens: number | undefined, minimum?: number) => number;
|
|
98
|
+
export declare const eventError: (route: string, message: string, body?: string, cause?: unknown) => AIError;
|
|
99
|
+
export declare const parseJson: (route: string, input: string, message: string) => Effect.Effect<unknown, AIError, never>;
|
|
100
|
+
/**
|
|
101
|
+
* Join the `text` field of a list of parts with newlines. Used by routes
|
|
102
|
+
* that flatten system / message content arrays into a single provider string
|
|
103
|
+
* (OpenAI Chat `system` content, OpenAI Responses `system` content, Gemini
|
|
104
|
+
* `systemInstruction.parts[].text`).
|
|
105
|
+
*/
|
|
106
|
+
export declare const joinText: (parts: ReadonlyArray<{
|
|
107
|
+
readonly text: string;
|
|
108
|
+
}>) => string;
|
|
109
|
+
/**
|
|
110
|
+
* Stable fallback representation for chronological `Message.system(...)`
|
|
111
|
+
* updates on routes that do not support that privileged role natively. The
|
|
112
|
+
* wrapper remains visibly lower-authority user text, preserves the original
|
|
113
|
+
* temporal position, and XML-escapes content so it cannot close the wrapper.
|
|
114
|
+
*/
|
|
115
|
+
export declare const wrapSystemUpdate: (parts: ReadonlyArray<{
|
|
116
|
+
readonly text: string;
|
|
117
|
+
}>) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Chronological system updates deliberately accept text only. Do not insert
|
|
120
|
+
* raw retrieved, tool, or web content into privileged updates: keep untrusted
|
|
121
|
+
* data in ordinary user/tool messages instead.
|
|
122
|
+
*/
|
|
123
|
+
export declare const systemUpdateText: (route: string, message: import("../schema/messages.js").Message) => Effect.Effect<{
|
|
124
|
+
readonly type: "text";
|
|
125
|
+
readonly text: string;
|
|
126
|
+
readonly cache?: import("../schema/options.js").CacheHint | undefined;
|
|
127
|
+
readonly providerMetadata?: {
|
|
128
|
+
readonly [x: string]: {
|
|
129
|
+
readonly [x: string]: unknown;
|
|
130
|
+
};
|
|
131
|
+
} | undefined;
|
|
132
|
+
}[], AIError, never>;
|
|
133
|
+
/** Lower an unsupported privileged update into visible, in-order user text. */
|
|
134
|
+
export declare const wrappedSystemUpdate: (route: string, message: import("../schema/messages.js").Message) => Effect.Effect<{
|
|
135
|
+
type: "text";
|
|
136
|
+
text: string;
|
|
137
|
+
cache: import("../schema/options.js").CacheHint | undefined;
|
|
138
|
+
}, AIError, never>;
|
|
139
|
+
/**
|
|
140
|
+
* Parse the streamed JSON input of a tool call. Treats an empty string as
|
|
141
|
+
* `"{}"` — providers occasionally finish a tool call without ever emitting
|
|
142
|
+
* input deltas (e.g. zero-arg tools). The error message is uniform across
|
|
143
|
+
* routes: `Invalid JSON input for <route> tool call <name>`.
|
|
144
|
+
*/
|
|
145
|
+
export declare const parseToolInput: (route: string, name: string, raw: string) => Effect.Effect<unknown, AIError, never>;
|
|
146
|
+
/** Inline view or a typed `InvalidRequest` for routes that cannot fetch URLs or dereference provider refs. */
|
|
147
|
+
export declare const requireInlineMedia: (route: string, asset: Media.Asset) => Effect.Effect<Media.Inline, AIError>;
|
|
148
|
+
export declare const inlineRequired: (route: string, asset: Media.Asset) => AIError;
|
|
149
|
+
/** The remote URL of a `url` asset, for protocols that accept `http(s)` references natively. */
|
|
150
|
+
export declare const mediaUrl: (asset: Media.Asset) => string | undefined;
|
|
151
|
+
export type MediaReference = {
|
|
152
|
+
readonly type: "dataUrl" | "url" | "ref";
|
|
153
|
+
readonly value: string;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* The one string a provider can address an asset by: inline payloads as a data URL, `url` sources as their URL, and
|
|
157
|
+
* this provider's own `ref` as its id. Other providers' refs are never forwarded and fail typed; omit `provider` for
|
|
158
|
+
* APIs with no file handles at all.
|
|
159
|
+
*/
|
|
160
|
+
export declare const mediaReference: (asset: Media.Asset, provider: ProviderID | undefined, label: string) => Effect.Effect<MediaReference, AIError>;
|
|
161
|
+
/**
|
|
162
|
+
* Lift a tool-result file into a `MediaPart`. Tool files carry either a data URL, a URI, or raw base64 in
|
|
163
|
+
* `uri`; the declared `mime` wins over any data-URL prefix so tool authors control the type the model sees.
|
|
164
|
+
*/
|
|
165
|
+
export declare const toolFileMedia: (item: Tool.FileContent) => MediaPart;
|
|
166
|
+
export declare const toolResultText: (part: ToolResultPart) => string;
|
|
167
|
+
export declare const errorText: (error: unknown) => string;
|
|
168
|
+
/**
|
|
169
|
+
* Canonical invalid-request constructor shared by protocol lowering.
|
|
170
|
+
*/
|
|
171
|
+
export declare const invalidRequest: (message: string, cause?: unknown) => AIError;
|
|
172
|
+
/**
|
|
173
|
+
* Canonical constructor for operations the selected route does not implement.
|
|
174
|
+
* Prefer this over `invalidRequest` when the failure is a missing route
|
|
175
|
+
* capability rather than a malformed caller input, so consumers can branch on
|
|
176
|
+
* `reason._tag` plus `reason.operation` instead of matching message text.
|
|
177
|
+
*/
|
|
178
|
+
export declare const unsupportedOperation: (input: {
|
|
179
|
+
readonly operation: string;
|
|
180
|
+
readonly message: string;
|
|
181
|
+
readonly provider?: ProviderID;
|
|
182
|
+
readonly route?: string;
|
|
183
|
+
readonly cause?: unknown;
|
|
184
|
+
}) => AIError;
|
|
185
|
+
/**
|
|
186
|
+
* Lower namespaces to flat definitions for protocols without a native
|
|
187
|
+
* namespace construct. Leaf names join their namespace path with `_` because
|
|
188
|
+
* `.` is not broadly accepted in provider tool names. A no-op on tools `flattenRequest` already flattened; adapters call
|
|
189
|
+
* it to type their tools.
|
|
190
|
+
*/
|
|
191
|
+
export declare const flattenTools: (tools: ReadonlyArray<ToolEntry>, path?: ReadonlyArray<string>) => ToolDefinition[];
|
|
192
|
+
/**
|
|
193
|
+
* The request as a protocol without native namespaces sees it: tools, tool updates, past calls and a forced choice all
|
|
194
|
+
* use flattened names. `Protocol.make` applies it before `body.from` for such protocols, so adapters only see flat
|
|
195
|
+
* requests.
|
|
196
|
+
*/
|
|
197
|
+
export declare const flattenRequest: (request: LLMRequest) => LLMRequest;
|
|
198
|
+
/**
|
|
199
|
+
* @deprecated Routes without native namespaces already receive flattened requests; use `flattenRequest`. Removed in
|
|
200
|
+
* the next minor.
|
|
201
|
+
*/
|
|
202
|
+
export declare const flattenToolRequest: (request: LLMRequest) => {
|
|
203
|
+
tools: ToolDefinition[];
|
|
204
|
+
request: LLMRequest<import("../schema/options.js").LanguageModel<{
|
|
205
|
+
readonly [x: string]: unknown;
|
|
206
|
+
}, import("../route.js").CompactionOperations | undefined>>;
|
|
207
|
+
};
|
|
208
|
+
export declare const matchToolChoice: <Auto, None, Required, Tool>(toolChoice: NonNullable<LLMRequest["toolChoice"]>, cases: {
|
|
209
|
+
readonly auto: () => Auto;
|
|
210
|
+
readonly none: () => None;
|
|
211
|
+
readonly required: () => Required;
|
|
212
|
+
readonly tool: (name: string) => Tool;
|
|
213
|
+
}) => Auto | None | Required | Tool;
|
|
214
|
+
type ContentType = ContentPart["type"];
|
|
215
|
+
export declare const supportsContent: <const Type extends ContentType>(part: ContentPart, types: ReadonlyArray<Type>) => part is Extract<ContentPart, {
|
|
216
|
+
readonly type: Type;
|
|
217
|
+
}>;
|
|
218
|
+
export declare const unsupportedContent: (route: string, role: LLMRequest["messages"][number]["role"], types: ReadonlyArray<ContentType>) => AIError;
|
|
219
|
+
/**
|
|
220
|
+
* Build a `validate` step from a Schema decoder. Replaces the per-route
|
|
221
|
+
* lambda body `(payload) => decode(payload).pipe(Effect.mapError((e) =>
|
|
222
|
+
* invalid(e.message)))`. Any decode error is translated into
|
|
223
|
+
* `AIError` carrying the original parse-error message.
|
|
224
|
+
*/
|
|
225
|
+
export declare const validateWith: <A, I, E extends {
|
|
226
|
+
readonly message: string;
|
|
227
|
+
}>(decode: (input: I) => Effect.Effect<A, E>) => (payload: I) => Effect.Effect<A, AIError, never>;
|
|
228
|
+
export interface JsonPostInput {
|
|
229
|
+
readonly url: string;
|
|
230
|
+
readonly body: string;
|
|
231
|
+
readonly headers?: Headers.Input;
|
|
232
|
+
readonly encoding?: RequestEncoding;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Build an HTTP POST with a JSON body. Sets `content-type: application/json`
|
|
236
|
+
* automatically after caller-supplied headers so routes cannot accidentally
|
|
237
|
+
* send JSON with a stale content type. The body is passed pre-encoded so
|
|
238
|
+
* routes can choose between
|
|
239
|
+
* `Schema.encodeSync(payload)` and `ProviderShared.encodeJson(payload)`.
|
|
240
|
+
* A `zstd` or `gzip` encoding compresses the body and sets `content-encoding`;
|
|
241
|
+
* it falls back to plain JSON when the runtime has no zlib.
|
|
242
|
+
*/
|
|
243
|
+
export declare const jsonPost: (input: JsonPostInput) => HttpClientRequest.HttpClientRequest;
|
|
244
|
+
/**
|
|
245
|
+
* Effectful variant of `jsonPost` that runs gzip/zstd compression off the JS event loop via async `node:zlib`
|
|
246
|
+
* so large multimodal payloads do not stall concurrent sessions, PTYs, or UI streams.
|
|
247
|
+
*/
|
|
248
|
+
export declare const jsonPostEffect: (input: JsonPostInput) => Effect.Effect<HttpClientRequest.HttpClientRequest, never, never>;
|
|
249
|
+
export * as ProviderShared from "./shared.js";
|