@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,13 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
3
|
+
import { type ProviderOptions } from "../schema/index.js";
|
|
4
|
+
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
5
|
+
declare const Options: Schema.Struct<{
|
|
6
|
+
/** Token budget for every image and video input; `ultra_high` applies to images only. */
|
|
7
|
+
readonly mediaResolution: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "medium" | "ultra_high">, import("../schema/options.js").OpenString<"high" | "low" | "medium" | "ultra_high">>>;
|
|
8
|
+
}>;
|
|
9
|
+
/** Known fields map to their wire names; anything else is sent as given. */
|
|
10
|
+
export type OptionsInput = ProviderOptions & typeof Options.Encoded;
|
|
11
|
+
export declare const protocol: DecisionRoute.Protocol;
|
|
12
|
+
export declare const route: DecisionRoute.Route;
|
|
13
|
+
export * as GoogleDecisions from "./google-decisions.js";
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { DecisionResponse, DecisionUsage } from "../decision.js";
|
|
3
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
6
|
+
import { AIError, ProviderID, UnsupportedOperationError, mergeJsonRecords, } from "../schema/index.js";
|
|
7
|
+
import { encodeJson } from "../utils/json.js";
|
|
8
|
+
import { JsonObject, knownString, ProviderShared } from "./shared.js";
|
|
9
|
+
import { SystemOne } from "./system-one.js";
|
|
10
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
11
|
+
const ID = "google-decisions";
|
|
12
|
+
const NAME = "Google Decisions";
|
|
13
|
+
export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
14
|
+
const Options = Schema.Struct({
|
|
15
|
+
/** Token budget for every image and video input; `ultra_high` applies to images only. */
|
|
16
|
+
mediaResolution: Schema.optional(knownString()),
|
|
17
|
+
});
|
|
18
|
+
const Usage = Schema.StructWithRest(Schema.Struct({
|
|
19
|
+
total_input_tokens: Schema.optional(Schema.Number),
|
|
20
|
+
total_output_tokens: Schema.optional(Schema.Number),
|
|
21
|
+
total_tokens: Schema.optional(Schema.Number),
|
|
22
|
+
}), [JsonObject]);
|
|
23
|
+
const Response = Schema.Struct({
|
|
24
|
+
answers: Schema.Record(Schema.String, SystemOne.Answer),
|
|
25
|
+
usage: Schema.optional(Usage),
|
|
26
|
+
});
|
|
27
|
+
const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
|
|
28
|
+
const fromRequest = Effect.fn("GoogleDecisions.fromRequest")(function* (request) {
|
|
29
|
+
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
30
|
+
const { mediaResolution: _, ...native } = request.providerOptions ?? {};
|
|
31
|
+
return {
|
|
32
|
+
...mergeJsonRecords(native, request.http?.body),
|
|
33
|
+
model: request.model.id,
|
|
34
|
+
input: separateText(yield* Effect.forEach(request.input, (part) => inputPart(request, part, options.mediaResolution))),
|
|
35
|
+
questions: {
|
|
36
|
+
...(yield* SystemOne.encodeQuestions(request.questions)),
|
|
37
|
+
// Google names System One's predicate criteria `true_description` and `false_description`.
|
|
38
|
+
...Object.fromEntries(request.questions.flatMap((question) => question.type === "predicate" && question.criteria !== undefined
|
|
39
|
+
? [
|
|
40
|
+
[
|
|
41
|
+
question.name,
|
|
42
|
+
{
|
|
43
|
+
type: "noul",
|
|
44
|
+
instructions: question.instructions,
|
|
45
|
+
criteria: {
|
|
46
|
+
...(question.criteria.true === undefined ? {} : { true_description: question.criteria.true }),
|
|
47
|
+
...(question.criteria.false === undefined ? {} : { false_description: question.criteria.false }),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
]
|
|
52
|
+
: [])),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
const inputPart = (request, part, resolution) => {
|
|
57
|
+
if (part.type === "text")
|
|
58
|
+
return Effect.succeed({ type: "text", text: part.text });
|
|
59
|
+
// Google reads every text block as text; JSON is serialized so its keys are never parsed as content blocks.
|
|
60
|
+
if (part.type === "json")
|
|
61
|
+
return Effect.succeed({ type: "text", text: encodeJson(part.value) });
|
|
62
|
+
return mediaPart(request, part.media, resolution);
|
|
63
|
+
};
|
|
64
|
+
// Google joins adjacent text blocks with no separator, so each one after another starts on a new line.
|
|
65
|
+
const separateText = (blocks) => blocks.map((block, index) => block.type === "text" && blocks[index - 1]?.type === "text" ? { ...block, text: `\n${block.text}` } : block);
|
|
66
|
+
const mediaPart = (request, asset, resolution) => {
|
|
67
|
+
const type = asset.kind === "image" || asset.kind === "audio" || asset.kind === "video"
|
|
68
|
+
? asset.kind
|
|
69
|
+
: asset.mediaType.toLowerCase() === "application/pdf"
|
|
70
|
+
? "document"
|
|
71
|
+
: undefined;
|
|
72
|
+
if (type === undefined)
|
|
73
|
+
return Effect.fail(new AIError({
|
|
74
|
+
reason: new UnsupportedOperationError({
|
|
75
|
+
operation: "decision.media",
|
|
76
|
+
provider: request.model.provider,
|
|
77
|
+
route: request.model.route.id,
|
|
78
|
+
message: `${NAME} takes images, audio, video and PDFs; got ${asset.mediaType}`,
|
|
79
|
+
}),
|
|
80
|
+
}));
|
|
81
|
+
const block = {
|
|
82
|
+
type,
|
|
83
|
+
mime_type: asset.mediaType.toLowerCase(),
|
|
84
|
+
// `ultra_high` is image-only, so video keeps Google's default for it.
|
|
85
|
+
...(resolution !== undefined && (type === "image" || (type === "video" && resolution !== "ultra_high"))
|
|
86
|
+
? { resolution }
|
|
87
|
+
: {}),
|
|
88
|
+
};
|
|
89
|
+
const inline = asset.inline();
|
|
90
|
+
if (inline)
|
|
91
|
+
return Effect.succeed({ ...block, data: inline.base64 });
|
|
92
|
+
// Google fetches URLs itself, so one that needs our download credentials can't be forwarded.
|
|
93
|
+
if (asset.source.type === "url" && /^https:\/\//i.test(asset.source.url) && asset.headers === undefined)
|
|
94
|
+
return Effect.succeed({ ...block, uri: asset.source.url });
|
|
95
|
+
const file = MediaInput.refID(asset, ProviderID.make("google"));
|
|
96
|
+
if (file !== undefined)
|
|
97
|
+
return Effect.succeed({ ...block, uri: file });
|
|
98
|
+
return Effect.fail(ProviderShared.invalidRequest(`${NAME} accepts inline media, public HTTPS URLs and Google Files API URIs; materialize ${asset.source.type} media first`));
|
|
99
|
+
};
|
|
100
|
+
const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "google" }).decodeJson(Response);
|
|
101
|
+
export const protocol = DecisionRoute.protocol({
|
|
102
|
+
id: ID,
|
|
103
|
+
name: NAME,
|
|
104
|
+
body: { from: fromRequest },
|
|
105
|
+
response: {
|
|
106
|
+
decode: Effect.fn("GoogleDecisions.decodeResponse")(function* (response, context) {
|
|
107
|
+
const output = yield* decodeDocument(response);
|
|
108
|
+
const data = output.value;
|
|
109
|
+
const answers = data.answers;
|
|
110
|
+
const names = context.request.questions.map((question) => question.name);
|
|
111
|
+
if (Object.keys(answers).length !== names.length || !names.every((name) => Object.hasOwn(answers, name)))
|
|
112
|
+
return yield* output.invalid(`${NAME} answers do not match the requested questions`);
|
|
113
|
+
return new DecisionResponse({
|
|
114
|
+
answers: context.request.questions.map((question) => SystemOne.toAnswer(question, answers[question.name])),
|
|
115
|
+
usage: data.usage === undefined
|
|
116
|
+
? undefined
|
|
117
|
+
: new DecisionUsage({
|
|
118
|
+
inputTokens: data.usage.total_input_tokens,
|
|
119
|
+
outputTokens: data.usage.total_output_tokens,
|
|
120
|
+
totalTokens: ProviderShared.totalTokens(data.usage.total_input_tokens, data.usage.total_output_tokens, data.usage.total_tokens),
|
|
121
|
+
}),
|
|
122
|
+
providerMetadata: data.usage === undefined ? undefined : { [context.providerMetadataKey]: { usage: data.usage } },
|
|
123
|
+
});
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
export const route = DecisionRoute.make({
|
|
128
|
+
id: ID,
|
|
129
|
+
provider: "google",
|
|
130
|
+
protocol,
|
|
131
|
+
endpoint: Endpoint.path("/decisions", { baseURL: DEFAULT_BASE_URL }),
|
|
132
|
+
});
|
|
133
|
+
export * as GoogleDecisions from "./google-decisions.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EmbeddingRoute } from "../route/embedding.js";
|
|
2
|
+
import { type OpenString } from "../schema/index.js";
|
|
3
|
+
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
4
|
+
/** `batchEmbedContents` takes at most 100 requests. */
|
|
5
|
+
export declare const MAX_BATCH = 100;
|
|
6
|
+
export type TaskType = OpenString<"RETRIEVAL_QUERY" | "RETRIEVAL_DOCUMENT" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY">;
|
|
7
|
+
/**
|
|
8
|
+
* Per-value embedding fields, sent with each value. `taskType` replaces the one `inputType` maps to; Gemini Embedding 2
|
|
9
|
+
* ignores task types and documents task prefixes in the text instead (`task: search result | query: …`).
|
|
10
|
+
*/
|
|
11
|
+
export interface OptionsInput {
|
|
12
|
+
readonly [key: string]: unknown;
|
|
13
|
+
readonly taskType?: TaskType;
|
|
14
|
+
readonly title?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Vertex `embedContentConfig` fields; Vertex alone takes `autoTruncate`, `documentOcr` and `audioTrackExtraction`. */
|
|
17
|
+
export interface VertexOptionsInput extends OptionsInput {
|
|
18
|
+
readonly autoTruncate?: boolean;
|
|
19
|
+
readonly documentOcr?: boolean;
|
|
20
|
+
readonly audioTrackExtraction?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Gemini API `batchEmbedContents`: one request per value, so every value gets its own vector. */
|
|
23
|
+
export declare const protocol: EmbeddingRoute.Protocol;
|
|
24
|
+
/**
|
|
25
|
+
* Vertex `embedContent`: one content per request, with options under `embedContentConfig`. Routes using it set
|
|
26
|
+
* `maxValues: 1`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const vertexProtocol: EmbeddingRoute.Protocol;
|
|
29
|
+
export declare const route: EmbeddingRoute.Route;
|
|
30
|
+
export declare const GoogleEmbedContent: {
|
|
31
|
+
readonly protocol: EmbeddingRoute.Protocol;
|
|
32
|
+
readonly vertexProtocol: EmbeddingRoute.Protocol;
|
|
33
|
+
readonly route: EmbeddingRoute.Route;
|
|
34
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
|
|
3
|
+
import { EmbeddingRoute } from "../route/embedding.js";
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
6
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
7
|
+
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
8
|
+
const ID = "google-embed-content";
|
|
9
|
+
const NAME = "Google embedContent";
|
|
10
|
+
export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
11
|
+
/** `batchEmbedContents` takes at most 100 requests. */
|
|
12
|
+
export const MAX_BATCH = 100;
|
|
13
|
+
const Values = Schema.Struct({ values: Schema.Array(Schema.Number) });
|
|
14
|
+
const UsageMetadata = Schema.StructWithRest(Schema.Struct({ promptTokenCount: Schema.optional(Schema.Number) }), [
|
|
15
|
+
Schema.Record(Schema.String, Schema.Unknown),
|
|
16
|
+
]);
|
|
17
|
+
const BatchResponse = Schema.Struct({
|
|
18
|
+
embeddings: Schema.Array(Values),
|
|
19
|
+
usageMetadata: Schema.optional(UsageMetadata),
|
|
20
|
+
});
|
|
21
|
+
const SingleResponse = Schema.Struct({
|
|
22
|
+
embedding: Values,
|
|
23
|
+
usageMetadata: Schema.optional(UsageMetadata),
|
|
24
|
+
truncated: Schema.optional(Schema.Boolean),
|
|
25
|
+
});
|
|
26
|
+
const TASK_TYPES = { query: "RETRIEVAL_QUERY", document: "RETRIEVAL_DOCUMENT" };
|
|
27
|
+
// Each value is its own content: several parts in one content embed into one aggregated vector.
|
|
28
|
+
const content = (value) => typeof value === "string"
|
|
29
|
+
? Effect.succeed({ parts: [{ text: value }] })
|
|
30
|
+
: GeminiGenerateContent.mediaPart(NAME, value).pipe(Effect.map((part) => ({ parts: [part] })));
|
|
31
|
+
const config = (request) => ({
|
|
32
|
+
...(request.inputType === undefined ? {} : { taskType: TASK_TYPES[request.inputType] }),
|
|
33
|
+
...(request.dimensions === undefined ? {} : { outputDimensionality: request.dimensions }),
|
|
34
|
+
...request.providerOptions,
|
|
35
|
+
});
|
|
36
|
+
const identity = MediaProtocol.identity({ id: ID, name: NAME, provider: "google" });
|
|
37
|
+
const decodeBatch = identity.decodeJson(BatchResponse);
|
|
38
|
+
const decodeSingle = identity.decodeJson(SingleResponse);
|
|
39
|
+
const usage = (metadata) => metadata?.promptTokenCount === undefined ? undefined : new EmbeddingUsage({ inputTokens: metadata.promptTokenCount });
|
|
40
|
+
/** Gemini API `batchEmbedContents`: one request per value, so every value gets its own vector. */
|
|
41
|
+
export const protocol = EmbeddingRoute.protocol({
|
|
42
|
+
id: ID,
|
|
43
|
+
name: NAME,
|
|
44
|
+
body: {
|
|
45
|
+
from: Effect.fn("GoogleEmbedContent.fromRequest")(function* (request) {
|
|
46
|
+
const contents = yield* Effect.forEach(request.values, content);
|
|
47
|
+
const fields = config(request);
|
|
48
|
+
return (mergeJsonRecords({ requests: contents.map((item) => ({ model: `models/${request.model.id}`, content: item, ...fields })) }, request.http?.body) ?? {});
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
response: {
|
|
52
|
+
decode: Effect.fn("GoogleEmbedContent.decodeResponse")(function* (response, context) {
|
|
53
|
+
const output = yield* decodeBatch(response);
|
|
54
|
+
return new EmbeddingResponse({
|
|
55
|
+
embeddings: output.value.embeddings.map((item) => item.values),
|
|
56
|
+
usage: usage(output.value.usageMetadata),
|
|
57
|
+
providerMetadata: {
|
|
58
|
+
[context.providerMetadataKey]: output.value.usageMetadata === undefined ? {} : { usageMetadata: output.value.usageMetadata },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Vertex `embedContent`: one content per request, with options under `embedContentConfig`. Routes using it set
|
|
66
|
+
* `maxValues: 1`.
|
|
67
|
+
*/
|
|
68
|
+
export const vertexProtocol = EmbeddingRoute.protocol({
|
|
69
|
+
id: "google-vertex-embed-content",
|
|
70
|
+
name: "Google Vertex embedContent",
|
|
71
|
+
body: {
|
|
72
|
+
from: Effect.fn("GoogleEmbedContent.vertexFromRequest")(function* (request) {
|
|
73
|
+
const contents = yield* Effect.forEach(request.values, content);
|
|
74
|
+
const fields = config(request);
|
|
75
|
+
return (mergeJsonRecords({
|
|
76
|
+
content: contents[0],
|
|
77
|
+
...(Object.keys(fields).length === 0 ? {} : { embedContentConfig: fields }),
|
|
78
|
+
}, request.http?.body) ?? {});
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
response: {
|
|
82
|
+
decode: Effect.fn("GoogleEmbedContent.vertexDecodeResponse")(function* (response, context) {
|
|
83
|
+
const output = yield* decodeSingle(response);
|
|
84
|
+
return new EmbeddingResponse({
|
|
85
|
+
embeddings: [output.value.embedding.values],
|
|
86
|
+
usage: usage(output.value.usageMetadata),
|
|
87
|
+
providerMetadata: {
|
|
88
|
+
[context.providerMetadataKey]: {
|
|
89
|
+
...(output.value.usageMetadata === undefined ? {} : { usageMetadata: output.value.usageMetadata }),
|
|
90
|
+
...(output.value.truncated === undefined ? {} : { truncated: output.value.truncated }),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
export const route = EmbeddingRoute.make({
|
|
98
|
+
id: ID,
|
|
99
|
+
provider: "google",
|
|
100
|
+
protocol,
|
|
101
|
+
endpoint: Endpoint.path(({ request }) => `/models/${request.model.id}:batchEmbedContents`, {
|
|
102
|
+
baseURL: DEFAULT_BASE_URL,
|
|
103
|
+
}),
|
|
104
|
+
maxValues: MAX_BATCH,
|
|
105
|
+
});
|
|
106
|
+
export const GoogleEmbedContent = {
|
|
107
|
+
protocol,
|
|
108
|
+
vertexProtocol,
|
|
109
|
+
route,
|
|
110
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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://generativelanguage.googleapis.com/v1beta";
|
|
6
|
+
/** Provider-native `generationConfig` fields. Common fields (`aspect`, `resolution`, `images`) live on the request. */
|
|
7
|
+
export type GoogleImageOptions = {
|
|
8
|
+
readonly seed?: number;
|
|
9
|
+
readonly thinkingLevel?: OpenString<"MINIMAL" | "LOW" | "MEDIUM" | "HIGH">;
|
|
10
|
+
readonly includeThoughts?: boolean;
|
|
11
|
+
} & Record<string, unknown>;
|
|
12
|
+
export type Request = ImageRequest<ImageModel<GoogleImageOptions>>;
|
|
13
|
+
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
14
|
+
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<GoogleImageOptions>;
|
|
15
|
+
export declare const GoogleImages: {
|
|
16
|
+
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
17
|
+
readonly model: typeof model;
|
|
18
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
8
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
9
|
+
const route = MediaProtocol.identity({ id: "google-images", name: "Google Images", provider: "google" });
|
|
10
|
+
export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// 2. Response schema
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const GoogleUsage = Schema.StructWithRest(Schema.Struct({
|
|
15
|
+
cachedContentTokenCount: Schema.optional(Schema.Number),
|
|
16
|
+
thoughtsTokenCount: Schema.optional(Schema.Number),
|
|
17
|
+
promptTokenCount: Schema.optional(Schema.Number),
|
|
18
|
+
candidatesTokenCount: Schema.optional(Schema.Number),
|
|
19
|
+
totalTokenCount: Schema.optional(Schema.Number),
|
|
20
|
+
promptTokensDetails: Schema.optional(Schema.Unknown),
|
|
21
|
+
candidatesTokensDetails: Schema.optional(Schema.Unknown),
|
|
22
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
23
|
+
const GoogleImageResponse = Schema.Struct({
|
|
24
|
+
candidates: Schema.optional(Schema.Array(Schema.Struct({
|
|
25
|
+
index: Schema.optional(Schema.Number),
|
|
26
|
+
content: Schema.optional(Schema.Struct({
|
|
27
|
+
parts: Schema.Array(Schema.Struct({
|
|
28
|
+
text: Schema.optional(Schema.String),
|
|
29
|
+
thought: Schema.optional(Schema.Boolean),
|
|
30
|
+
thoughtSignature: Schema.optional(Schema.String),
|
|
31
|
+
inlineData: Schema.optional(Schema.Struct({
|
|
32
|
+
mimeType: Schema.String,
|
|
33
|
+
data: Schema.String,
|
|
34
|
+
})),
|
|
35
|
+
})),
|
|
36
|
+
})),
|
|
37
|
+
finishReason: Schema.optional(Schema.String),
|
|
38
|
+
finishMessage: Schema.optional(Schema.String),
|
|
39
|
+
safetyRatings: Schema.optional(Schema.Unknown),
|
|
40
|
+
citationMetadata: Schema.optional(Schema.Unknown),
|
|
41
|
+
groundingMetadata: Schema.optional(Schema.Unknown),
|
|
42
|
+
}))),
|
|
43
|
+
usageMetadata: Schema.optional(GoogleUsage),
|
|
44
|
+
modelVersion: Schema.optional(Schema.String),
|
|
45
|
+
responseId: Schema.optional(Schema.String),
|
|
46
|
+
promptFeedback: Schema.optional(Schema.Unknown),
|
|
47
|
+
});
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// 5. Request body construction
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
const generationConfig = (request) => {
|
|
52
|
+
const { thinkingLevel, includeThoughts, ...native } = request.providerOptions ?? {};
|
|
53
|
+
// Google names the half tier `512` and rejects `0.5K`.
|
|
54
|
+
const imageSize = request.resolution?.toUpperCase() === "0.5K" ? "512" : request.resolution?.toUpperCase();
|
|
55
|
+
const imageConfig = { aspectRatio: request.aspect, imageSize };
|
|
56
|
+
const thinkingConfig = { thinkingLevel, includeThoughts };
|
|
57
|
+
return (mergeJsonRecords({
|
|
58
|
+
responseModalities: ["IMAGE"],
|
|
59
|
+
imageConfig: Object.values(imageConfig).some((value) => value !== undefined) ? imageConfig : undefined,
|
|
60
|
+
thinkingConfig: Object.values(thinkingConfig).some((value) => value !== undefined) ? thinkingConfig : undefined,
|
|
61
|
+
}, native) ?? { responseModalities: ["IMAGE"] });
|
|
62
|
+
};
|
|
63
|
+
const fromRequest = Effect.fn("GoogleImages.fromRequest")(function* (request) {
|
|
64
|
+
if (request.n !== undefined && request.n > 1)
|
|
65
|
+
return yield* route.unsupported("media.n", `${route.name} generates one image per request; call it once per image instead of n=${request.n}`);
|
|
66
|
+
const parts = yield* Effect.forEach(request.images ?? [], (image) => GeminiGenerateContent.mediaPart(route.name, image));
|
|
67
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
68
|
+
contents: [{ role: "user", parts: [{ text: request.prompt }, ...parts] }],
|
|
69
|
+
generationConfig: generationConfig(request),
|
|
70
|
+
}, request.http?.body) ?? {});
|
|
71
|
+
});
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// 6. Response decoding
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
const decodeDocument = route.decodeJson(GoogleImageResponse);
|
|
76
|
+
const decodeResponse = Effect.fn("GoogleImages.decodeResponse")(function* (response) {
|
|
77
|
+
const output = yield* decodeDocument(response);
|
|
78
|
+
const decoded = output.value;
|
|
79
|
+
const candidates = decoded.candidates ?? [];
|
|
80
|
+
const candidateMetadata = candidates.map((candidate, candidateIndex) => ({
|
|
81
|
+
index: candidate.index ?? candidateIndex,
|
|
82
|
+
finishReason: candidate.finishReason,
|
|
83
|
+
finishMessage: candidate.finishMessage,
|
|
84
|
+
safetyRatings: candidate.safetyRatings,
|
|
85
|
+
citationMetadata: candidate.citationMetadata,
|
|
86
|
+
groundingMetadata: candidate.groundingMetadata,
|
|
87
|
+
parts: (candidate.content?.parts ?? []).map((part) => part.inlineData === undefined
|
|
88
|
+
? { type: "text", text: part.text, thought: part.thought, thoughtSignature: part.thoughtSignature }
|
|
89
|
+
: {
|
|
90
|
+
type: "inlineData",
|
|
91
|
+
mediaType: part.inlineData.mimeType,
|
|
92
|
+
thought: part.thought,
|
|
93
|
+
thoughtSignature: part.thoughtSignature,
|
|
94
|
+
}),
|
|
95
|
+
}));
|
|
96
|
+
// Thought parts are drafts; only non-thought inline data is a final image.
|
|
97
|
+
const encoded = candidates.flatMap((candidate, candidateIndex) => (candidate.content?.parts ?? []).flatMap((part, partIndex) => part.inlineData === undefined || part.thought === true
|
|
98
|
+
? []
|
|
99
|
+
: [
|
|
100
|
+
{
|
|
101
|
+
candidate,
|
|
102
|
+
candidateIndex,
|
|
103
|
+
partIndex,
|
|
104
|
+
inlineData: part.inlineData,
|
|
105
|
+
thoughtSignature: part.thoughtSignature,
|
|
106
|
+
},
|
|
107
|
+
]));
|
|
108
|
+
const images = yield* Effect.forEach(encoded, (item) => MediaInput.decodedAsset(output.invalid, `${route.name} candidate ${item.candidateIndex} part ${item.partIndex}`, item.inlineData.data, item.inlineData.mimeType, {
|
|
109
|
+
providerMetadata: {
|
|
110
|
+
google: {
|
|
111
|
+
candidateIndex: item.candidate.index ?? item.candidateIndex,
|
|
112
|
+
partIndex: item.partIndex,
|
|
113
|
+
finishReason: item.candidate.finishReason,
|
|
114
|
+
safetyRatings: item.candidate.safetyRatings,
|
|
115
|
+
citationMetadata: item.candidate.citationMetadata,
|
|
116
|
+
groundingMetadata: item.candidate.groundingMetadata,
|
|
117
|
+
thoughtSignature: item.thoughtSignature,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
121
|
+
if (images.length === 0) {
|
|
122
|
+
const finishReasons = candidates.flatMap((candidate) => candidate.finishReason === undefined ? [] : [candidate.finishReason]);
|
|
123
|
+
// Safety and recitation stops are Google refusing the prompt, not a malformed response.
|
|
124
|
+
if (finishReasons.some(GeminiGenerateContent.contentFiltered))
|
|
125
|
+
return yield* output.contentPolicy(`${route.name} withheld its images (finish reasons: ${finishReasons.join(", ")})`);
|
|
126
|
+
return yield* output.invalid(`${route.name} returned no final images${finishReasons.length === 0 ? "" : ` (finish reasons: ${finishReasons.join(", ")})`}; inspect body for prompt feedback and candidate details`);
|
|
127
|
+
}
|
|
128
|
+
const usage = decoded.usageMetadata;
|
|
129
|
+
const outputTokens = usage?.candidatesTokenCount === undefined ? undefined : usage.candidatesTokenCount + (usage.thoughtsTokenCount ?? 0);
|
|
130
|
+
return new ImageResponse({
|
|
131
|
+
images,
|
|
132
|
+
usage: usage === undefined
|
|
133
|
+
? undefined
|
|
134
|
+
: tokenUsage({
|
|
135
|
+
input: usage.promptTokenCount,
|
|
136
|
+
output: outputTokens,
|
|
137
|
+
total: ProviderShared.totalTokens(usage.promptTokenCount, outputTokens, usage.totalTokenCount),
|
|
138
|
+
details: {
|
|
139
|
+
reasoningTokens: usage.thoughtsTokenCount,
|
|
140
|
+
cacheReadInputTokens: usage.cachedContentTokenCount,
|
|
141
|
+
google: usage,
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
providerMetadata: {
|
|
145
|
+
google: {
|
|
146
|
+
modelVersion: decoded.modelVersion,
|
|
147
|
+
responseId: decoded.responseId,
|
|
148
|
+
promptFeedback: decoded.promptFeedback,
|
|
149
|
+
candidates: candidateMetadata,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// 7. Protocol and route
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
158
|
+
body: { from: fromRequest },
|
|
159
|
+
response: { decode: decodeResponse },
|
|
160
|
+
});
|
|
161
|
+
export const model = (input) => ImageModel.fromRoute({
|
|
162
|
+
protocol,
|
|
163
|
+
baseURL: DEFAULT_BASE_URL,
|
|
164
|
+
path: ({ request }) => `/models/${request.model.id}:generateContent`,
|
|
165
|
+
}, input);
|
|
166
|
+
export const GoogleImages = {
|
|
167
|
+
protocol,
|
|
168
|
+
model,
|
|
169
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { type OpenString } from "../schema/index.js";
|
|
5
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
|
+
export declare const PATH = "/interactions";
|
|
8
|
+
/**
|
|
9
|
+
* Provider-native Interactions fields, merged into the body. Common fields (`start`, `end`, `references`,
|
|
10
|
+
* `duration`, `aspect`, `resolution`) live on the request. Edit or extend a video by passing it as a reference with
|
|
11
|
+
* `generation_config.video_config.task`, or continue a generated one with `previous_interaction_id`.
|
|
12
|
+
*/
|
|
13
|
+
export type GoogleVideoOptions = {
|
|
14
|
+
readonly previous_interaction_id?: string;
|
|
15
|
+
readonly generation_config?: {
|
|
16
|
+
readonly video_config?: {
|
|
17
|
+
readonly task?: OpenString<"text_to_video" | "image_to_video" | "reference_to_video" | "edit" | "extend">;
|
|
18
|
+
} & Record<string, unknown>;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
readonly response_format?: {
|
|
21
|
+
readonly delivery?: OpenString<"inline" | "uri">;
|
|
22
|
+
} & Record<string, unknown>;
|
|
23
|
+
readonly service_tier?: OpenString<"flex" | "standard" | "priority">;
|
|
24
|
+
readonly webhook_config?: {
|
|
25
|
+
readonly uris?: ReadonlyArray<string>;
|
|
26
|
+
readonly user_metadata?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
} & Record<string, unknown>;
|
|
29
|
+
export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
|
|
30
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
31
|
+
export declare const Token: Schema.String;
|
|
32
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
33
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
34
|
+
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<GoogleVideoOptions>;
|
|
35
|
+
export declare const GoogleInteractionsVideo: {
|
|
36
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
37
|
+
readonly model: typeof model;
|
|
38
|
+
};
|