@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,56 @@
|
|
|
1
|
+
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
2
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
3
|
+
import { OpenResponses } from "../protocols/open-responses.js";
|
|
4
|
+
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
5
|
+
import { ZAIMessages } from "../protocols/zai-messages.js";
|
|
6
|
+
import { Route } from "../route/client.js";
|
|
7
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
8
|
+
import { Framing } from "../route/framing.js";
|
|
9
|
+
import { ProviderID } from "../schema/index.js";
|
|
10
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
11
|
+
export const id = ProviderID.make("zai-coding-plan");
|
|
12
|
+
const chatRoute = Route.make({
|
|
13
|
+
id: "zai-coding-chat",
|
|
14
|
+
provider: id,
|
|
15
|
+
providerMetadataKey: "zai",
|
|
16
|
+
protocol: ZAIChat.protocol,
|
|
17
|
+
endpoint: Endpoint.path("/chat/completions", { baseURL: "https://api.z.ai/api/coding/paas/v4" }),
|
|
18
|
+
framing: OpenAIChat.framing,
|
|
19
|
+
});
|
|
20
|
+
const messagesRoute = Route.make({
|
|
21
|
+
id: "zai-coding-messages",
|
|
22
|
+
provider: id,
|
|
23
|
+
providerMetadataKey: "zai",
|
|
24
|
+
protocol: ZAIMessages.protocol,
|
|
25
|
+
endpoint: Endpoint.path("/messages", { baseURL: "https://api.z.ai/api/anthropic/v1" }),
|
|
26
|
+
framing: AnthropicMessages.framing,
|
|
27
|
+
headers: () => ({ "anthropic-version": "2023-06-01" }),
|
|
28
|
+
});
|
|
29
|
+
const responsesRoute = Route.make({
|
|
30
|
+
id: "zai-coding-responses",
|
|
31
|
+
provider: id,
|
|
32
|
+
providerMetadataKey: "zai",
|
|
33
|
+
protocol: OpenResponses.protocol,
|
|
34
|
+
endpoint: Endpoint.path("/responses", { baseURL: "https://api.z.ai/api/v1" }),
|
|
35
|
+
framing: Framing.sse,
|
|
36
|
+
});
|
|
37
|
+
export const routes = [chatRoute, messagesRoute, responsesRoute];
|
|
38
|
+
export const configure = (input = {}) => {
|
|
39
|
+
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY");
|
|
40
|
+
const chat = (modelID) => chatRoute.with(defaults).model({
|
|
41
|
+
id: modelID,
|
|
42
|
+
compatibility: ZAIChat.compatibility,
|
|
43
|
+
capabilities: ZAIChat.capabilities,
|
|
44
|
+
});
|
|
45
|
+
const messages = (modelID) => messagesRoute
|
|
46
|
+
.with(defaults)
|
|
47
|
+
.model({ id: modelID, compatibility: { requireSignature: false } });
|
|
48
|
+
const responses = (modelID) => responsesRoute.with(defaults).model({ id: modelID });
|
|
49
|
+
return { id, model: chat, chat, messages, responses, configure };
|
|
50
|
+
};
|
|
51
|
+
export const provider = configure();
|
|
52
|
+
export const chat = provider.chat;
|
|
53
|
+
export const messages = provider.messages;
|
|
54
|
+
export const responses = provider.responses;
|
|
55
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
56
|
+
export * as ZAICodingPlan from "./zai-coding-plan.js";
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { Route } from "../route/client.js";
|
|
5
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
6
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
+
export type ChatOptionsInput = ZAIChat.OptionsInput;
|
|
8
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
9
|
+
readonly baseURL?: string;
|
|
10
|
+
readonly providerOptions?: ChatOptionsInput;
|
|
11
|
+
};
|
|
12
|
+
export type Settings = ProviderPackage.Settings & ChatOptionsInput & {
|
|
13
|
+
readonly apiKey?: string | false;
|
|
14
|
+
readonly baseURL?: string;
|
|
15
|
+
};
|
|
16
|
+
export type { ZAIImageOptions } from "../protocols/zai-images.js";
|
|
17
|
+
export declare const routes: Route<{
|
|
18
|
+
readonly model: string;
|
|
19
|
+
readonly messages: readonly ({
|
|
20
|
+
readonly role: "system";
|
|
21
|
+
readonly content: string | readonly ({
|
|
22
|
+
readonly type: "image_url";
|
|
23
|
+
readonly image_url: {
|
|
24
|
+
readonly url: string;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "video_url";
|
|
28
|
+
readonly video_url: {
|
|
29
|
+
readonly url: string;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "file";
|
|
33
|
+
readonly file: {
|
|
34
|
+
readonly filename: string;
|
|
35
|
+
readonly file_data: string;
|
|
36
|
+
};
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "text";
|
|
39
|
+
readonly text: string;
|
|
40
|
+
readonly cache_control?: {
|
|
41
|
+
readonly type: "ephemeral";
|
|
42
|
+
readonly ttl?: string | undefined;
|
|
43
|
+
} | undefined;
|
|
44
|
+
})[];
|
|
45
|
+
} | {
|
|
46
|
+
readonly role: "user";
|
|
47
|
+
readonly content: string | readonly ({
|
|
48
|
+
readonly type: "image_url";
|
|
49
|
+
readonly image_url: {
|
|
50
|
+
readonly url: string;
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "video_url";
|
|
54
|
+
readonly video_url: {
|
|
55
|
+
readonly url: string;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
readonly type: "file";
|
|
59
|
+
readonly file: {
|
|
60
|
+
readonly filename: string;
|
|
61
|
+
readonly file_data: string;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
readonly type: "text";
|
|
65
|
+
readonly text: string;
|
|
66
|
+
readonly cache_control?: {
|
|
67
|
+
readonly type: "ephemeral";
|
|
68
|
+
readonly ttl?: string | undefined;
|
|
69
|
+
} | undefined;
|
|
70
|
+
})[];
|
|
71
|
+
} | {
|
|
72
|
+
readonly role: "tool";
|
|
73
|
+
readonly tool_call_id: string;
|
|
74
|
+
readonly content: string | readonly {
|
|
75
|
+
readonly type: "text";
|
|
76
|
+
readonly text: string;
|
|
77
|
+
readonly cache_control?: {
|
|
78
|
+
readonly type: "ephemeral";
|
|
79
|
+
readonly ttl?: string | undefined;
|
|
80
|
+
} | undefined;
|
|
81
|
+
}[];
|
|
82
|
+
} | {
|
|
83
|
+
readonly [x: string]: unknown;
|
|
84
|
+
readonly role: "assistant";
|
|
85
|
+
readonly content: string | readonly {
|
|
86
|
+
readonly type: "text";
|
|
87
|
+
readonly text: string;
|
|
88
|
+
readonly cache_control?: {
|
|
89
|
+
readonly type: "ephemeral";
|
|
90
|
+
readonly ttl?: string | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
}[] | null;
|
|
93
|
+
readonly tool_calls?: readonly ({
|
|
94
|
+
readonly id: string;
|
|
95
|
+
readonly type: "custom";
|
|
96
|
+
readonly custom: {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly input: string;
|
|
99
|
+
};
|
|
100
|
+
} | {
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly type: "function";
|
|
103
|
+
readonly function: {
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly arguments: string;
|
|
106
|
+
};
|
|
107
|
+
readonly extra_content?: {
|
|
108
|
+
readonly google: {
|
|
109
|
+
readonly thought_signature: string;
|
|
110
|
+
};
|
|
111
|
+
} | undefined;
|
|
112
|
+
})[] | undefined;
|
|
113
|
+
readonly reasoning_content?: string | undefined;
|
|
114
|
+
readonly reasoning?: string | undefined;
|
|
115
|
+
readonly reasoning_text?: string | undefined;
|
|
116
|
+
readonly reasoning_details?: unknown;
|
|
117
|
+
readonly reasoning_opaque?: string | undefined;
|
|
118
|
+
})[];
|
|
119
|
+
readonly tools?: readonly ({
|
|
120
|
+
readonly type: "function";
|
|
121
|
+
readonly function: {
|
|
122
|
+
readonly name: string;
|
|
123
|
+
readonly description: string;
|
|
124
|
+
readonly parameters: {
|
|
125
|
+
readonly [x: string]: unknown;
|
|
126
|
+
};
|
|
127
|
+
readonly strict?: boolean | undefined;
|
|
128
|
+
};
|
|
129
|
+
readonly cache_control?: {
|
|
130
|
+
readonly type: "ephemeral";
|
|
131
|
+
readonly ttl?: string | undefined;
|
|
132
|
+
} | undefined;
|
|
133
|
+
} | {
|
|
134
|
+
readonly type: "custom";
|
|
135
|
+
readonly custom: {
|
|
136
|
+
readonly name: string;
|
|
137
|
+
readonly description: string;
|
|
138
|
+
readonly format: {
|
|
139
|
+
readonly type: "text";
|
|
140
|
+
} | {
|
|
141
|
+
readonly type: "grammar";
|
|
142
|
+
readonly grammar: {
|
|
143
|
+
readonly syntax: "lark" | "regex";
|
|
144
|
+
readonly definition: string;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
readonly cache_control?: {
|
|
149
|
+
readonly type: "ephemeral";
|
|
150
|
+
readonly ttl?: string | undefined;
|
|
151
|
+
} | undefined;
|
|
152
|
+
})[] | undefined;
|
|
153
|
+
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
154
|
+
readonly type: "function";
|
|
155
|
+
readonly function: {
|
|
156
|
+
readonly name: string;
|
|
157
|
+
};
|
|
158
|
+
} | {
|
|
159
|
+
readonly type: "custom";
|
|
160
|
+
readonly custom: {
|
|
161
|
+
readonly name: string;
|
|
162
|
+
};
|
|
163
|
+
} | undefined;
|
|
164
|
+
readonly stream: true;
|
|
165
|
+
readonly stream_options?: {
|
|
166
|
+
readonly include_usage: boolean;
|
|
167
|
+
} | undefined;
|
|
168
|
+
readonly store?: boolean | undefined;
|
|
169
|
+
readonly prompt_cache_key?: string | undefined;
|
|
170
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
171
|
+
readonly prompt_cache_options?: {
|
|
172
|
+
readonly ttl?: string | undefined;
|
|
173
|
+
} | undefined;
|
|
174
|
+
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
175
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
176
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
177
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
178
|
+
readonly metadata?: {
|
|
179
|
+
readonly [x: string]: string;
|
|
180
|
+
} | undefined;
|
|
181
|
+
readonly safety_identifier?: string | undefined;
|
|
182
|
+
readonly tool_stream?: boolean | undefined;
|
|
183
|
+
readonly max_completion_tokens?: number | undefined;
|
|
184
|
+
readonly max_tokens?: number | undefined;
|
|
185
|
+
readonly temperature?: number | undefined;
|
|
186
|
+
readonly top_p?: number | undefined;
|
|
187
|
+
readonly frequency_penalty?: number | undefined;
|
|
188
|
+
readonly presence_penalty?: number | undefined;
|
|
189
|
+
readonly seed?: number | undefined;
|
|
190
|
+
readonly stop?: readonly string[] | undefined;
|
|
191
|
+
readonly thinking?: {
|
|
192
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
193
|
+
readonly clear_thinking?: boolean | undefined;
|
|
194
|
+
} | undefined;
|
|
195
|
+
readonly do_sample?: boolean | undefined;
|
|
196
|
+
readonly response_format?: {
|
|
197
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
198
|
+
} | undefined;
|
|
199
|
+
readonly request_id?: string | undefined;
|
|
200
|
+
readonly user_id?: string | undefined;
|
|
201
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
202
|
+
export declare const configure: (input?: Config) => {
|
|
203
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
204
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
205
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
206
|
+
readonly thinking?: {
|
|
207
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
208
|
+
readonly clear_thinking?: boolean | undefined;
|
|
209
|
+
} | undefined;
|
|
210
|
+
readonly toolStream?: boolean | undefined;
|
|
211
|
+
readonly doSample?: boolean | undefined;
|
|
212
|
+
readonly responseFormat?: {
|
|
213
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
214
|
+
} | undefined;
|
|
215
|
+
readonly requestID?: string | undefined;
|
|
216
|
+
readonly userID?: string | undefined;
|
|
217
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
218
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
219
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
220
|
+
readonly thinking?: {
|
|
221
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
222
|
+
readonly clear_thinking?: boolean | undefined;
|
|
223
|
+
} | undefined;
|
|
224
|
+
readonly toolStream?: boolean | undefined;
|
|
225
|
+
readonly doSample?: boolean | undefined;
|
|
226
|
+
readonly responseFormat?: {
|
|
227
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
228
|
+
} | undefined;
|
|
229
|
+
readonly requestID?: string | undefined;
|
|
230
|
+
readonly userID?: string | undefined;
|
|
231
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
232
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
233
|
+
configure: typeof configure;
|
|
234
|
+
};
|
|
235
|
+
export declare const provider: {
|
|
236
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
237
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
238
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
239
|
+
readonly thinking?: {
|
|
240
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
241
|
+
readonly clear_thinking?: boolean | undefined;
|
|
242
|
+
} | undefined;
|
|
243
|
+
readonly toolStream?: boolean | undefined;
|
|
244
|
+
readonly doSample?: boolean | undefined;
|
|
245
|
+
readonly responseFormat?: {
|
|
246
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
247
|
+
} | undefined;
|
|
248
|
+
readonly requestID?: string | undefined;
|
|
249
|
+
readonly userID?: string | undefined;
|
|
250
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
251
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
252
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
253
|
+
readonly thinking?: {
|
|
254
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
255
|
+
readonly clear_thinking?: boolean | undefined;
|
|
256
|
+
} | undefined;
|
|
257
|
+
readonly toolStream?: boolean | undefined;
|
|
258
|
+
readonly doSample?: boolean | undefined;
|
|
259
|
+
readonly responseFormat?: {
|
|
260
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
261
|
+
} | undefined;
|
|
262
|
+
readonly requestID?: string | undefined;
|
|
263
|
+
readonly userID?: string | undefined;
|
|
264
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
265
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
266
|
+
configure: typeof configure;
|
|
267
|
+
};
|
|
268
|
+
export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
269
|
+
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
270
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
271
|
+
readonly thinking?: {
|
|
272
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
273
|
+
readonly clear_thinking?: boolean | undefined;
|
|
274
|
+
} | undefined;
|
|
275
|
+
readonly toolStream?: boolean | undefined;
|
|
276
|
+
readonly doSample?: boolean | undefined;
|
|
277
|
+
readonly responseFormat?: {
|
|
278
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
279
|
+
} | undefined;
|
|
280
|
+
readonly requestID?: string | undefined;
|
|
281
|
+
readonly userID?: string | undefined;
|
|
282
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
283
|
+
export declare const model: ProviderPackage.Model<Settings, ChatOptionsInput>;
|
|
284
|
+
export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
285
|
+
export * as ZAI from "./zai.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
2
|
+
import { ZAIImages } from "../protocols/zai-images.js";
|
|
3
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
4
|
+
import { Route } from "../route/client.js";
|
|
5
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
6
|
+
import { MediaRoute } from "../route/media.js";
|
|
7
|
+
import { ProviderID } from "../schema/index.js";
|
|
8
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
9
|
+
export const id = ProviderID.make("zai");
|
|
10
|
+
const chatRoute = Route.make({
|
|
11
|
+
id: "zai-chat",
|
|
12
|
+
provider: id,
|
|
13
|
+
providerMetadataKey: "zai",
|
|
14
|
+
protocol: ZAIChat.protocol,
|
|
15
|
+
endpoint: Endpoint.path("/chat/completions", { baseURL: "https://api.z.ai/api/paas/v4" }),
|
|
16
|
+
framing: OpenAIChat.framing,
|
|
17
|
+
});
|
|
18
|
+
export const routes = [chatRoute];
|
|
19
|
+
export const configure = (input = {}) => {
|
|
20
|
+
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY");
|
|
21
|
+
const chat = (modelID) => chatRoute.with(defaults).model({
|
|
22
|
+
id: modelID,
|
|
23
|
+
compatibility: ZAIChat.compatibility,
|
|
24
|
+
capabilities: ZAIChat.capabilities,
|
|
25
|
+
});
|
|
26
|
+
const media = MediaRoute.deployment(input, defaults.auth);
|
|
27
|
+
const image = (modelID, providerOptions) => ZAIImages.model({ ...media, id: modelID, providerOptions });
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
model: chat,
|
|
31
|
+
chat,
|
|
32
|
+
image,
|
|
33
|
+
configure,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const provider = configure();
|
|
37
|
+
export const image = provider.image;
|
|
38
|
+
export const chat = provider.chat;
|
|
39
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
40
|
+
export const imageModel = (modelID, settings) => {
|
|
41
|
+
const input = toConfig(settings);
|
|
42
|
+
return configure(input).image(modelID, input.providerOptions);
|
|
43
|
+
};
|
|
44
|
+
export * as ZAI from "./zai.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers/index.js";
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { isContextOverflow, isRetryable } from "./provider-error.js";
|
|
2
|
+
export { ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, GenerationOptions, HttpTimeout, RequestEncoding, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, ToolChanges, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishDetails, StepFinish, Finish, MediaEvent, RawEvent, StreamEvent, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
|
+
export type { BaseRequest, Capabilities, ContentPartInput, GenerationOptionsFields, HttpOptions, RequestHttpOptions, RequestOptions, LanguageModelInput, LanguageModelProviderOptions, LLMRequest, MediaPartInput, RequestTimeout, TimeoutConfig, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, TextResponse, ToolEntryInput, TransportOptions, UsageInput, } from "./schema/index.js";
|
|
4
|
+
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
5
|
+
export type { ImageJob, ImageModelOptions, ImageOptions, ImageRequest, ImageRequestInput, ImageResolution, ImageRoute, ImageStatus, } from "./image.js";
|
|
6
|
+
export { VideoAspectRatio, VideoDuration, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
7
|
+
export type { VideoJob, VideoModelOptions, VideoOptions, VideoRequest, VideoRequestInput, VideoResolution, VideoRoute, VideoStatus, } from "./video.js";
|
|
8
|
+
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionErrorAnswer, DecisionErrorReason, DecisionUsage, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
9
|
+
export type { DecisionAnswerFor, DecisionAnswersFor, DecisionInput, DecisionMediaPartInput, DecisionModelOptions, DecisionOptions, DecisionPartInput, DecisionQuestions, DecisionRequest, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
10
|
+
export { EmbeddingModel, EmbeddingModelSchema, EmbeddingResponse, EmbeddingUsage, EmbeddingValue } from "./embedding.js";
|
|
11
|
+
export type { EmbeddingInputType, EmbeddingModelOptions, EmbeddingModelRoute, EmbeddingOptions, EmbeddingRequest, EmbeddingRequestInput, EmbeddingValueInput, } from "./embedding.js";
|
|
12
|
+
export { Media } from "./media.js";
|
|
13
|
+
export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Reason as GenerationReason, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
|
|
14
|
+
export type { ExecutableTool, Tool, ToolChangesInput, ToolExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolModelOutputInput, ToolOptions, ToolOutputEncoded, ToolOutputSchema, ToolOutputValue, ToolSchema, ToolToModelOutput, } from "./tool.js";
|
|
15
|
+
export type { LLM } from "./llm.js";
|
|
16
|
+
export type { LLMLoopInput, LLMRequestInput, ObjectResponse } from "./llm.js";
|
|
17
|
+
export type { Collected, CollectResult } from "./loop.js";
|
|
18
|
+
export type { HttpHandler, HttpMiddleware } from "./route/executor-service.js";
|
package/dist/public.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { isContextOverflow, isRetryable } from "./provider-error.js";
|
|
2
|
+
export { ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, GenerationOptions, HttpTimeout, RequestEncoding, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, ToolChanges, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishDetails, StepFinish, Finish, MediaEvent, RawEvent, StreamEvent, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
|
+
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
4
|
+
export { VideoAspectRatio, VideoDuration, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
5
|
+
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionErrorAnswer, DecisionErrorReason, DecisionUsage, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
6
|
+
export { EmbeddingModel, EmbeddingModelSchema, EmbeddingResponse, EmbeddingUsage, EmbeddingValue } from "./embedding.js";
|
|
7
|
+
export { Media } from "./media.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Config, Redacted } from "effect";
|
|
2
|
+
import { Auth } from "./auth.js";
|
|
3
|
+
export type ApiKeyMode = "optional" | "required";
|
|
4
|
+
export type AuthOverride = {
|
|
5
|
+
readonly auth: Auth.Definition;
|
|
6
|
+
readonly apiKey?: never;
|
|
7
|
+
};
|
|
8
|
+
/** `false` marks a provider that needs no key: no env lookup and no auth header from the package. */
|
|
9
|
+
export type ApiKey = string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>> | false;
|
|
10
|
+
export type OptionalApiKeyAuth = {
|
|
11
|
+
readonly apiKey?: ApiKey;
|
|
12
|
+
readonly auth?: never;
|
|
13
|
+
};
|
|
14
|
+
export type RequiredApiKeyAuth = {
|
|
15
|
+
readonly apiKey: ApiKey;
|
|
16
|
+
readonly auth?: never;
|
|
17
|
+
};
|
|
18
|
+
export type ProviderAuthOption<Mode extends ApiKeyMode> = AuthOverride | (Mode extends "optional" ? OptionalApiKeyAuth : RequiredApiKeyAuth);
|
|
19
|
+
/**
|
|
20
|
+
* Require at least one of the keys in `T`. Use for option shapes where any
|
|
21
|
+
* subset of fields is acceptable but at least one must be present (e.g. Azure
|
|
22
|
+
* accepts `resourceName` or `baseURL`).
|
|
23
|
+
*/
|
|
24
|
+
export type AtLeastOne<T> = {
|
|
25
|
+
[K in keyof T]: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
26
|
+
}[keyof T];
|
|
27
|
+
/**
|
|
28
|
+
* Standard API-key resolution for providers: honor an explicit `auth`
|
|
29
|
+
* override, skip auth entirely for `apiKey: false`, otherwise resolve `apiKey`
|
|
30
|
+
* (option > config vars) and render it with `apply`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const apiKey: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>, apply: (credential: Auth.Credential) => Auth.Definition) => Auth.Definition;
|
|
33
|
+
/** `apiKey` resolution applied as `Authorization: Bearer <key>`. */
|
|
34
|
+
export declare const bearer: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>) => Auth.Definition;
|
|
35
|
+
export * as AuthOptions from "./auth-options.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Auth } from "./auth.js";
|
|
2
|
+
/**
|
|
3
|
+
* Standard API-key resolution for providers: honor an explicit `auth`
|
|
4
|
+
* override, skip auth entirely for `apiKey: false`, otherwise resolve `apiKey`
|
|
5
|
+
* (option > config vars) and render it with `apply`.
|
|
6
|
+
*/
|
|
7
|
+
export const apiKey = (options, envVar, apply) => {
|
|
8
|
+
if ("auth" in options && options.auth)
|
|
9
|
+
return options.auth;
|
|
10
|
+
const key = "apiKey" in options ? options.apiKey : undefined;
|
|
11
|
+
if (key === false)
|
|
12
|
+
return Auth.none;
|
|
13
|
+
return apply((Array.isArray(envVar) ? envVar : [envVar]).reduce((auth, name) => auth.orElse(Auth.config(name)), Auth.optional(key, "apiKey")));
|
|
14
|
+
};
|
|
15
|
+
/** `apiKey` resolution applied as `Authorization: Bearer <key>`. */
|
|
16
|
+
export const bearer = (options, envVar) => apiKey(options, envVar, (credential) => credential.bearer());
|
|
17
|
+
export * as AuthOptions from "./auth-options.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Config, Effect, Redacted } from "effect";
|
|
2
|
+
import { Headers } from "effect/http";
|
|
3
|
+
import { AIError, type HttpOptions } from "../schema/index.js";
|
|
4
|
+
export declare class MissingCredentialError extends Error {
|
|
5
|
+
readonly source: string;
|
|
6
|
+
readonly _tag = "MissingCredentialError";
|
|
7
|
+
constructor(source: string, message?: string);
|
|
8
|
+
}
|
|
9
|
+
export type CredentialError = MissingCredentialError | Config.ConfigError;
|
|
10
|
+
export type AuthError = CredentialError | AIError;
|
|
11
|
+
type Secret = string | Redacted.Redacted | Config.Config<string | Redacted.Redacted>;
|
|
12
|
+
export interface AuthInput {
|
|
13
|
+
readonly request: {
|
|
14
|
+
readonly http?: HttpOptions;
|
|
15
|
+
};
|
|
16
|
+
readonly method: "POST" | "GET" | "PUT" | "DELETE";
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly body: string;
|
|
19
|
+
readonly headers: Headers.Headers;
|
|
20
|
+
}
|
|
21
|
+
export interface Credential {
|
|
22
|
+
readonly load: Effect.Effect<Redacted.Redacted, CredentialError>;
|
|
23
|
+
readonly orElse: (that: Credential) => Credential;
|
|
24
|
+
readonly bearer: () => Definition;
|
|
25
|
+
readonly header: (name: string) => Definition;
|
|
26
|
+
readonly pipe: <A>(f: (self: Credential) => A) => A;
|
|
27
|
+
}
|
|
28
|
+
export interface Definition {
|
|
29
|
+
readonly apply: (input: AuthInput) => Effect.Effect<Headers.Headers, AuthError>;
|
|
30
|
+
readonly andThen: (that: Definition) => Definition;
|
|
31
|
+
readonly orElse: (that: Definition) => Definition;
|
|
32
|
+
readonly pipe: <A>(f: (self: Definition) => A) => A;
|
|
33
|
+
}
|
|
34
|
+
export declare const value: (secret: string, source?: string) => Credential;
|
|
35
|
+
export declare const optional: (secret: Secret | undefined, source?: string) => Credential;
|
|
36
|
+
export declare const config: (name: string) => Credential;
|
|
37
|
+
export declare const effect: (load: Effect.Effect<Redacted.Redacted, CredentialError>) => Credential;
|
|
38
|
+
export declare const none: Definition;
|
|
39
|
+
export declare const headers: (input: Headers.Input) => Definition;
|
|
40
|
+
export declare const remove: (name: string) => Definition;
|
|
41
|
+
export declare const custom: (apply: (input: AuthInput) => Effect.Effect<Headers.Headers, AIError>) => Definition;
|
|
42
|
+
export declare const passthrough: Definition;
|
|
43
|
+
export declare function bearer(source: Secret | Credential): Definition;
|
|
44
|
+
export declare function header(name: string): (source: Secret | Credential) => Definition;
|
|
45
|
+
export declare function header(name: string, source: Secret | Credential): Definition;
|
|
46
|
+
export declare function bearerHeader(name: string): (source: Secret | Credential) => Definition;
|
|
47
|
+
export declare function bearerHeader(name: string, source: Secret | Credential): Definition;
|
|
48
|
+
/** `Authorization: <scheme> <secret>` for providers whose scheme is not `Bearer`, such as Deepgram's `Token`. */
|
|
49
|
+
export declare function scheme(name: string): (source: Secret | Credential) => Definition;
|
|
50
|
+
export declare function scheme(name: string, source: Secret | Credential): Definition;
|
|
51
|
+
export declare const toEffect: (input: Definition) => (authInput: AuthInput) => Effect.Effect<Headers.Headers, AIError>;
|
|
52
|
+
export * as Auth from "./auth.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Config, Effect, Option, Redacted } from "effect";
|
|
2
|
+
import { Headers } from "effect/http";
|
|
3
|
+
import { AuthenticationError, AIError } from "../schema/index.js";
|
|
4
|
+
export class MissingCredentialError extends Error {
|
|
5
|
+
source;
|
|
6
|
+
_tag = "MissingCredentialError";
|
|
7
|
+
constructor(source, message = `Missing auth credential: ${source}`) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.source = source;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const credential = (load) => {
|
|
13
|
+
const self = {
|
|
14
|
+
load,
|
|
15
|
+
orElse: (that) => credential(load.pipe(Effect.catch(() => that.load))),
|
|
16
|
+
bearer: () => fromCredential(self, (secret) => ({ authorization: `Bearer ${secret}` })),
|
|
17
|
+
header: (name) => fromCredential(self, (secret) => ({ [name]: secret })),
|
|
18
|
+
pipe: (f) => f(self),
|
|
19
|
+
};
|
|
20
|
+
return self;
|
|
21
|
+
};
|
|
22
|
+
const auth = (apply) => {
|
|
23
|
+
const self = {
|
|
24
|
+
apply,
|
|
25
|
+
andThen: (that) => auth((input) => apply(input).pipe(Effect.flatMap((headers) => that.apply({ ...input, headers })))),
|
|
26
|
+
orElse: (that) => auth((input) => apply(input).pipe(Effect.catch(() => that.apply(input)))),
|
|
27
|
+
pipe: (f) => f(self),
|
|
28
|
+
};
|
|
29
|
+
return self;
|
|
30
|
+
};
|
|
31
|
+
const fromCredential = (source, render) => auth((input) => source.load.pipe(Effect.map((secret) => Headers.setAll(input.headers, render(Redacted.value(secret))))));
|
|
32
|
+
const secretEffect = (secret, source) => {
|
|
33
|
+
const redacted = typeof secret === "string" ? Redacted.make(secret) : secret;
|
|
34
|
+
if (Redacted.value(redacted) === "")
|
|
35
|
+
return Effect.fail(new MissingCredentialError(source));
|
|
36
|
+
return Effect.succeed(redacted);
|
|
37
|
+
};
|
|
38
|
+
const credentialFromSecret = (secret, source) => {
|
|
39
|
+
if (typeof secret === "string" || Redacted.isRedacted(secret))
|
|
40
|
+
return credential(secretEffect(secret, source));
|
|
41
|
+
return credential(Effect.gen(function* () {
|
|
42
|
+
return yield* secretEffect(yield* secret, source);
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
export const value = (secret, source = "value") => credentialFromSecret(secret, source);
|
|
46
|
+
export const optional = (secret, source = "optional value") => secret === undefined
|
|
47
|
+
? credential(Effect.fail(new MissingCredentialError(source)))
|
|
48
|
+
: credentialFromSecret(secret, source);
|
|
49
|
+
export const config = (name) => credential(Effect.gen(function* () {
|
|
50
|
+
const secret = yield* Config.option(Config.Redacted(name));
|
|
51
|
+
if (Option.isSome(secret) && Redacted.value(secret.value) !== "")
|
|
52
|
+
return secret.value;
|
|
53
|
+
return yield* Effect.fail(new MissingCredentialError(name, `${name} is not set`));
|
|
54
|
+
}));
|
|
55
|
+
export const effect = (load) => credential(load);
|
|
56
|
+
export const none = auth((input) => Effect.succeed(input.headers));
|
|
57
|
+
export const headers = (input) => auth((inputAuth) => Effect.succeed(Headers.setAll(inputAuth.headers, input)));
|
|
58
|
+
export const remove = (name) => auth((input) => Effect.succeed(Headers.remove(input.headers, name)));
|
|
59
|
+
export const custom = (apply) => auth(apply);
|
|
60
|
+
export const passthrough = none;
|
|
61
|
+
const credentialInput = (source) => typeof source === "string" || Redacted.isRedacted(source) || Config.isConfig(source)
|
|
62
|
+
? credentialFromSecret(source, "value")
|
|
63
|
+
: source;
|
|
64
|
+
export function bearer(source) {
|
|
65
|
+
return credentialInput(source).bearer();
|
|
66
|
+
}
|
|
67
|
+
export function header(name, source) {
|
|
68
|
+
if (source === undefined) {
|
|
69
|
+
return (next) => credentialInput(next).header(name);
|
|
70
|
+
}
|
|
71
|
+
return credentialInput(source).header(name);
|
|
72
|
+
}
|
|
73
|
+
export function bearerHeader(name, source) {
|
|
74
|
+
const render = (input) => fromCredential(credentialInput(input), (secret) => ({ [name]: `Bearer ${secret}` }));
|
|
75
|
+
if (source === undefined)
|
|
76
|
+
return render;
|
|
77
|
+
return render(source);
|
|
78
|
+
}
|
|
79
|
+
export function scheme(name, source) {
|
|
80
|
+
const render = (input) => fromCredential(credentialInput(input), (secret) => ({ authorization: `${name} ${secret}` }));
|
|
81
|
+
if (source === undefined)
|
|
82
|
+
return render;
|
|
83
|
+
return render(source);
|
|
84
|
+
}
|
|
85
|
+
const toAIError = (error) => {
|
|
86
|
+
if (error instanceof AIError)
|
|
87
|
+
return error;
|
|
88
|
+
const message = error instanceof MissingCredentialError ? error.message : `Failed to resolve auth config: ${error.message}`;
|
|
89
|
+
return new AIError({ reason: new AuthenticationError({ message, cause: error }) });
|
|
90
|
+
};
|
|
91
|
+
export const toEffect = (input) => (authInput) => input.apply(authInput).pipe(Effect.mapError(toAIError));
|
|
92
|
+
export * as Auth from "./auth.js";
|