@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,103 @@
|
|
|
1
|
+
import { Effect, Schema, Stream } from "effect";
|
|
2
|
+
import { Route } from "../../route/client.js";
|
|
3
|
+
import { Protocol } from "../../route/protocol.js";
|
|
4
|
+
import { CompactionCheckpointResponse, StreamEvent } from "../../schema/index.js";
|
|
5
|
+
import { OpenResponses } from "../open-responses.js";
|
|
6
|
+
import { ProviderShared } from "../shared.js";
|
|
7
|
+
const onOutputItem = Effect.fnUntraced(function* (state, input) {
|
|
8
|
+
const event = OpenResponses.normalize(state.parser, input);
|
|
9
|
+
const item = event.item;
|
|
10
|
+
if (!item)
|
|
11
|
+
return state;
|
|
12
|
+
const parser = event.output_index === undefined || state.parser.outputItems[event.output_index] === item.id
|
|
13
|
+
? state.parser
|
|
14
|
+
: { ...state.parser, outputItems: { ...state.parser.outputItems, [event.output_index]: item.id } };
|
|
15
|
+
const next = parser === state.parser ? state : { ...state, parser };
|
|
16
|
+
if (event.type === "response.output_item.added" || item.type !== "compaction")
|
|
17
|
+
return next;
|
|
18
|
+
if (event.output_index !== undefined &&
|
|
19
|
+
Object.entries(state.parser.outputItems).some(([index, id]) => id === item.id && Number(index) !== event.output_index))
|
|
20
|
+
return yield* ProviderShared.eventError(parser.id, "Compaction checkpoint appeared in multiple output slots");
|
|
21
|
+
if (!item.encrypted_content)
|
|
22
|
+
return yield* ProviderShared.eventError(parser.id, "Compaction output is missing its encrypted content");
|
|
23
|
+
const previous = state.checkpoints[item.id];
|
|
24
|
+
if (previous && previous.encrypted !== item.encrypted_content)
|
|
25
|
+
return yield* ProviderShared.eventError(parser.id, "Compaction output changed after completion");
|
|
26
|
+
if (previous)
|
|
27
|
+
return next;
|
|
28
|
+
return {
|
|
29
|
+
...next,
|
|
30
|
+
checkpoints: {
|
|
31
|
+
...state.checkpoints,
|
|
32
|
+
[item.id]: { type: "compaction", provider: parser.provider, id: item.id, encrypted: item.encrypted_content },
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
/** Collect a trigger response before acknowledging transport completion. No generation output escapes. */
|
|
37
|
+
export const make = (body) => Effect.fn("ResponsesCheckpoint.execute")(function* (request, executor, options) {
|
|
38
|
+
const source = request.model.route;
|
|
39
|
+
let result;
|
|
40
|
+
// Route registries erase the frame type. The codec validates that boundary before parsing.
|
|
41
|
+
const event = OpenResponses.protocol.stream.event;
|
|
42
|
+
const protocol = Protocol.make({
|
|
43
|
+
id: source.protocol,
|
|
44
|
+
body,
|
|
45
|
+
stream: {
|
|
46
|
+
event,
|
|
47
|
+
initial: (request) => ({
|
|
48
|
+
parser: { id: source.id, provider: request.model.provider, outputItems: {} },
|
|
49
|
+
checkpoints: {},
|
|
50
|
+
}),
|
|
51
|
+
terminal: OpenResponses.terminal,
|
|
52
|
+
step: Effect.fnUntraced(function* (state, event) {
|
|
53
|
+
if (event.response?.id && state.responseID && event.response.id !== state.responseID)
|
|
54
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response ID changed during execution");
|
|
55
|
+
if (event.type === "response.created")
|
|
56
|
+
return [{ ...state, responseID: event.response?.id }, []];
|
|
57
|
+
if (event.type === "error" || event.type === "response.failed")
|
|
58
|
+
return yield* OpenResponses.providerFailure(event, "Compaction request failed");
|
|
59
|
+
if (event.type === "response.incomplete")
|
|
60
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response was incomplete");
|
|
61
|
+
if (event.type === "response.output_item.added" || event.type === "response.output_item.done")
|
|
62
|
+
return [yield* onOutputItem(state, event), []];
|
|
63
|
+
if (event.type !== "response.completed")
|
|
64
|
+
return [state, []];
|
|
65
|
+
const responseID = event.response?.id;
|
|
66
|
+
if (!responseID?.trim())
|
|
67
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response is missing its response ID");
|
|
68
|
+
if (event.response?.status !== undefined && event.response.status !== "completed")
|
|
69
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response did not complete successfully");
|
|
70
|
+
let next = state;
|
|
71
|
+
for (const [index, item] of (event.response?.output ?? []).entries()) {
|
|
72
|
+
next = yield* onOutputItem(next, { type: "response.output_item.done", output_index: index, item });
|
|
73
|
+
}
|
|
74
|
+
const checkpoints = Object.values(next.checkpoints);
|
|
75
|
+
const checkpoint = checkpoints[0];
|
|
76
|
+
if (checkpoints.length !== 1 || !checkpoint)
|
|
77
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response must contain exactly one checkpoint");
|
|
78
|
+
result = new CompactionCheckpointResponse({
|
|
79
|
+
checkpoint,
|
|
80
|
+
responseID,
|
|
81
|
+
usage: OpenResponses.mapUsage(event.response?.usage, OpenResponses.metadataKey(request.model)),
|
|
82
|
+
});
|
|
83
|
+
return [next, [StreamEvent.finish({ reason: "stop" })]];
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const route = Route.make({
|
|
88
|
+
id: source.id,
|
|
89
|
+
provider: source.provider,
|
|
90
|
+
providerMetadataKey: source.providerMetadataKey,
|
|
91
|
+
protocol,
|
|
92
|
+
endpoint: source.endpoint,
|
|
93
|
+
auth: source.auth,
|
|
94
|
+
transport: source.transport,
|
|
95
|
+
});
|
|
96
|
+
const native = yield* body.from(request);
|
|
97
|
+
const prepared = yield* route.prepareTransport(native, request, options);
|
|
98
|
+
yield* route.streamPrepared(prepared, request, { http: executor }, options).pipe(Stream.runDrain);
|
|
99
|
+
if (!result)
|
|
100
|
+
return yield* ProviderShared.eventError(source.id, "Compaction response ended without a checkpoint");
|
|
101
|
+
return result;
|
|
102
|
+
});
|
|
103
|
+
export * as ResponsesCheckpoint from "./responses-checkpoint.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { AIError, type LLMRequest } from "../../schema/index.js";
|
|
3
|
+
import type { CompactOperation } from "../../route/client.js";
|
|
4
|
+
import { OpenResponses } from "../open-responses.js";
|
|
5
|
+
export declare const make: (adapter: OpenResponses.ProviderAdapter, lowerTools: (request: LLMRequest) => Effect.Effect<ReadonlyArray<Record<string, unknown>>, AIError>) => CompactOperation;
|
|
6
|
+
export * as ResponsesCompaction from "./responses-compaction.js";
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, Message, mergeJsonRecords, } from "../../schema/index.js";
|
|
3
|
+
import { stripEffortUpdates } from "../../effort-updates.js";
|
|
4
|
+
import { foldToolUpdates } from "../../tool-updates.js";
|
|
5
|
+
import { Endpoint } from "../../route/endpoint.js";
|
|
6
|
+
import { RequestExecutor } from "../../route/executor.js";
|
|
7
|
+
import { HttpTransport } from "../../route/transport/index.js";
|
|
8
|
+
import { OpenResponses } from "../open-responses.js";
|
|
9
|
+
import { JsonObject, optionalNull, ProviderShared } from "../shared.js";
|
|
10
|
+
import { Media } from "../../media.js";
|
|
11
|
+
// /compact has a smaller wire contract than /responses; keep the request controls it accepts.
|
|
12
|
+
const Body = Schema.Struct({
|
|
13
|
+
model: Schema.String,
|
|
14
|
+
input: Schema.Array(Schema.Unknown),
|
|
15
|
+
instructions: optionalNull(Schema.String),
|
|
16
|
+
previous_response_id: optionalNull(Schema.String),
|
|
17
|
+
service_tier: optionalNull(Schema.String),
|
|
18
|
+
reasoning: Schema.optional(JsonObject),
|
|
19
|
+
text: Schema.optional(JsonObject),
|
|
20
|
+
include: OpenResponses.coreFields.include,
|
|
21
|
+
parallel_tool_calls: OpenResponses.coreFields.parallel_tool_calls,
|
|
22
|
+
tools: Schema.optional(Schema.Array(JsonObject)),
|
|
23
|
+
prompt_cache_key: optionalNull(Schema.String),
|
|
24
|
+
prompt_cache_retention: optionalNull(Schema.String),
|
|
25
|
+
prompt_cache_options: optionalNull(Schema.Struct({ mode: Schema.optional(Schema.String), ttl: Schema.optional(Schema.String) })),
|
|
26
|
+
});
|
|
27
|
+
const Text = Schema.Union([OpenResponses.OpenResponsesInputText, OpenResponses.OpenResponsesOutputText]);
|
|
28
|
+
const File = Schema.Union([
|
|
29
|
+
Schema.Struct({
|
|
30
|
+
...OpenResponses.OpenResponsesInputFile.fields,
|
|
31
|
+
file_url: Schema.String,
|
|
32
|
+
file_data: Schema.optional(Schema.Never),
|
|
33
|
+
}),
|
|
34
|
+
Schema.Struct({
|
|
35
|
+
...OpenResponses.OpenResponsesInputFile.fields,
|
|
36
|
+
file_data: Schema.String,
|
|
37
|
+
file_url: Schema.optional(Schema.Never),
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
const MessageFields = {
|
|
41
|
+
type: Schema.Literal("message"),
|
|
42
|
+
id: Schema.optional(Schema.String),
|
|
43
|
+
status: Schema.optional(Schema.String),
|
|
44
|
+
phase: Schema.optional(OpenResponses.MessagePhase),
|
|
45
|
+
};
|
|
46
|
+
const Response = Schema.Struct({
|
|
47
|
+
object: Schema.Literal("response.compaction"),
|
|
48
|
+
output: Schema.Array(Schema.Union([
|
|
49
|
+
OpenResponses.CompactionItem,
|
|
50
|
+
OpenResponses.OpenResponsesReasoningItem,
|
|
51
|
+
Schema.Struct({
|
|
52
|
+
...MessageFields,
|
|
53
|
+
role: Schema.Literal("user"),
|
|
54
|
+
content: Schema.Array(Schema.Union([Text, OpenResponses.OpenResponsesInputImage, File])).check(Schema.isMinLength(1)),
|
|
55
|
+
}),
|
|
56
|
+
Schema.Struct({
|
|
57
|
+
...MessageFields,
|
|
58
|
+
role: Schema.Literal("assistant"),
|
|
59
|
+
content: Schema.Array(Text).check(Schema.isMinLength(1)),
|
|
60
|
+
}),
|
|
61
|
+
// The system prompt sent as a developer message, echoed back; the next request leads with its own.
|
|
62
|
+
Schema.Struct({ ...MessageFields, role: Schema.Literal("developer"), content: Schema.Unknown }),
|
|
63
|
+
])),
|
|
64
|
+
usage: Schema.optional(Schema.StructWithRest(OpenResponses.OpenResponsesUsage, [JsonObject])),
|
|
65
|
+
});
|
|
66
|
+
export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.execute")(function* (request, executor, options) {
|
|
67
|
+
const route = request.model.route;
|
|
68
|
+
// The standalone compaction endpoint rejects effort updates (`configuration_update`). Every tool goes in
|
|
69
|
+
// top-level `tools`: after compacting a history whose tools were only in `additional_tools`, small models lost
|
|
70
|
+
// track of them more often.
|
|
71
|
+
const folded = foldToolUpdates(stripEffortUpdates(request));
|
|
72
|
+
// The system prompt leads `input` as a developer message, as every step's request does, so `/compact` reads the
|
|
73
|
+
// prefix those requests cached.
|
|
74
|
+
const native = yield* OpenResponses.lowerConversation(folded, adapter);
|
|
75
|
+
const generation = OpenResponses.lowerGeneration(request);
|
|
76
|
+
const tools = folded.tools.length === 0 ? undefined : yield* lowerTools(folded);
|
|
77
|
+
const body = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
|
|
78
|
+
...native,
|
|
79
|
+
service_tier: generation.service_tier,
|
|
80
|
+
reasoning: generation.reasoning,
|
|
81
|
+
text: generation.text,
|
|
82
|
+
include: generation.include,
|
|
83
|
+
parallel_tool_calls: generation.parallel_tool_calls,
|
|
84
|
+
tools,
|
|
85
|
+
prompt_cache_key: generation.prompt_cache_key,
|
|
86
|
+
}, request.http?.body));
|
|
87
|
+
const url = Endpoint.render(route.endpoint, { request, body: native });
|
|
88
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}/compact`;
|
|
89
|
+
const parts = yield* HttpTransport.jsonRequestParts({
|
|
90
|
+
request: {
|
|
91
|
+
...request,
|
|
92
|
+
http: request.http === undefined ? undefined : { ...request.http, body: undefined },
|
|
93
|
+
},
|
|
94
|
+
body,
|
|
95
|
+
endpoint: Endpoint.path(url.toString()),
|
|
96
|
+
auth: route.auth,
|
|
97
|
+
encodeBody: Schema.encodeSync(Schema.fromJsonString(Body)),
|
|
98
|
+
});
|
|
99
|
+
const post = yield* ProviderShared.jsonPostEffect({
|
|
100
|
+
url: parts.url,
|
|
101
|
+
body: parts.bodyText,
|
|
102
|
+
headers: parts.headers,
|
|
103
|
+
encoding: request.http?.encoding,
|
|
104
|
+
});
|
|
105
|
+
const response = yield* RequestExecutor.withTimeout(RequestExecutor.withTls(executor.execute, request.http?.tls), request.http?.timeout)(post, RequestExecutor.withFetch(request.http?.fetch, options?.http));
|
|
106
|
+
const text = yield* RequestExecutor.responseText(response);
|
|
107
|
+
const invalid = (message, cause) => new AIError({
|
|
108
|
+
reason: new InvalidProviderOutputError({
|
|
109
|
+
route: route.id,
|
|
110
|
+
message,
|
|
111
|
+
body: text,
|
|
112
|
+
cause,
|
|
113
|
+
http: RequestExecutor.responseHttp(response),
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
const result = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => invalid("Invalid compaction response", cause)));
|
|
117
|
+
if (!result.output.some((item) => item.type === "compaction"))
|
|
118
|
+
return yield* invalid("Compaction response did not contain a checkpoint");
|
|
119
|
+
return new CompactionResponse({
|
|
120
|
+
replacement: result.output
|
|
121
|
+
.filter((item) => item.type !== "message" || item.role !== "developer")
|
|
122
|
+
.map((item) => toMessage(item, request.model)),
|
|
123
|
+
usage: OpenResponses.mapUsage(result.usage, OpenResponses.metadataKey(request.model)),
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
function toMessage(item, model) {
|
|
127
|
+
if (item.type === "compaction")
|
|
128
|
+
return Message.assistant(CompactionPart.make({ provider: model.provider, id: item.id ?? undefined, encrypted: item.encrypted_content }));
|
|
129
|
+
const key = OpenResponses.metadataKey(model);
|
|
130
|
+
if (item.type === "reasoning") {
|
|
131
|
+
const summary = item.summary.length ? item.summary : [{ text: "" }];
|
|
132
|
+
return Message.assistant(summary.map((part) => ({
|
|
133
|
+
type: "reasoning",
|
|
134
|
+
text: part.text,
|
|
135
|
+
providerMetadata: { [key]: { itemId: item.id, reasoningEncryptedContent: item.encrypted_content } },
|
|
136
|
+
})));
|
|
137
|
+
}
|
|
138
|
+
return Message.make({
|
|
139
|
+
role: item.role,
|
|
140
|
+
providerMetadata: { [key]: { itemId: item.id, type: item.type, status: item.status, phase: item.phase } },
|
|
141
|
+
content: item.content.map((part) => {
|
|
142
|
+
if (part.type === "input_text" || part.type === "output_text")
|
|
143
|
+
return { type: "text", text: part.text };
|
|
144
|
+
if (part.type === "input_image")
|
|
145
|
+
return {
|
|
146
|
+
type: "media",
|
|
147
|
+
media: replayMedia(part.image_url, "image/*"),
|
|
148
|
+
providerMetadata: part.detail === undefined ? undefined : { [key]: { detail: part.detail } },
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
type: "media",
|
|
152
|
+
media: replayMedia(part.file_url === undefined ? part.file_data : part.file_url, "application/octet-stream"),
|
|
153
|
+
filename: part.filename,
|
|
154
|
+
providerMetadata: part.detail === undefined ? undefined : { [key]: { detail: part.detail } },
|
|
155
|
+
};
|
|
156
|
+
}),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** Replayed compaction items carry either a data URL or a remote URL; the data URL's own type wins when present. */
|
|
160
|
+
const replayMedia = (value, fallbackType) => Media.parseDataUrl(value) ??
|
|
161
|
+
(/^https?:\/\//.test(value) ? Media.url(value, { mediaType: fallbackType }) : Media.base64(value, fallbackType));
|
|
162
|
+
export * as ResponsesCompaction from "./responses-compaction.js";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type AIError, type LLMRequest, type ToolResultPart } from "../../schema/index.js";
|
|
3
|
+
import { OpenResponses } from "../open-responses.js";
|
|
4
|
+
export type Item = OpenResponses.OutputItem & {
|
|
5
|
+
readonly status?: string;
|
|
6
|
+
readonly action?: unknown;
|
|
7
|
+
readonly queries?: unknown;
|
|
8
|
+
readonly results?: unknown;
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
readonly container_id?: string;
|
|
11
|
+
readonly outputs?: unknown;
|
|
12
|
+
readonly server_label?: string;
|
|
13
|
+
readonly output?: unknown;
|
|
14
|
+
readonly result?: string;
|
|
15
|
+
readonly output_format?: "png" | "jpeg" | "webp";
|
|
16
|
+
readonly error?: unknown;
|
|
17
|
+
};
|
|
18
|
+
export interface Definition {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly input: (item: Item) => unknown;
|
|
21
|
+
readonly result?: (item: Item) => Effect.Effect<ToolResultPart["result"], AIError>;
|
|
22
|
+
}
|
|
23
|
+
export type Definitions = Readonly<Record<string, Definition>>;
|
|
24
|
+
/** Hosted tools that several Responses providers report with the same item shape. */
|
|
25
|
+
export declare const common: {
|
|
26
|
+
readonly web_search_call: {
|
|
27
|
+
readonly name: "web_search";
|
|
28
|
+
readonly input: (item: Item) => {};
|
|
29
|
+
};
|
|
30
|
+
readonly file_search_call: {
|
|
31
|
+
readonly name: "file_search";
|
|
32
|
+
readonly input: (item: Item) => {
|
|
33
|
+
queries: {};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly code_interpreter_call: {
|
|
37
|
+
readonly name: "code_interpreter";
|
|
38
|
+
readonly input: (item: Item) => {
|
|
39
|
+
code: string | undefined;
|
|
40
|
+
container_id: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly mcp_call: {
|
|
44
|
+
readonly name: "mcp";
|
|
45
|
+
readonly input: (item: Item) => {
|
|
46
|
+
server_label: string | undefined;
|
|
47
|
+
name: string | undefined;
|
|
48
|
+
arguments: string | undefined;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare const isItem: <Tools extends Definitions>(item: OpenResponses.OutputItem, tools: Tools) => item is Item;
|
|
53
|
+
/**
|
|
54
|
+
* Responses stream that turns completed hosted tool items into a provider-executed
|
|
55
|
+
* tool call and result. `override` sees each normalized event first and may handle it.
|
|
56
|
+
*/
|
|
57
|
+
export declare const stream: (adapter: OpenResponses.ProviderAdapter, tools: Definitions, override?: (state: OpenResponses.ParserState, event: OpenResponses.NormalizedEvent) => Effect.Effect<OpenResponses.StepResult, AIError> | undefined) => {
|
|
58
|
+
event: import("effect/Schema").Codec<{
|
|
59
|
+
readonly [x: string]: unknown;
|
|
60
|
+
readonly type: string;
|
|
61
|
+
readonly delta?: string | undefined;
|
|
62
|
+
readonly arguments?: string | undefined;
|
|
63
|
+
readonly text?: string | undefined;
|
|
64
|
+
readonly item_id?: string | undefined;
|
|
65
|
+
readonly output_index?: number | undefined;
|
|
66
|
+
readonly summary_index?: number | undefined;
|
|
67
|
+
readonly item?: {
|
|
68
|
+
readonly [x: string]: unknown;
|
|
69
|
+
readonly type: string;
|
|
70
|
+
readonly id?: string | undefined;
|
|
71
|
+
readonly call_id?: string | undefined;
|
|
72
|
+
readonly name?: string | undefined;
|
|
73
|
+
readonly namespace?: string | undefined;
|
|
74
|
+
readonly arguments?: string | undefined;
|
|
75
|
+
readonly encrypted_content?: string | null | undefined;
|
|
76
|
+
} | null | undefined;
|
|
77
|
+
readonly response?: {
|
|
78
|
+
readonly [x: string]: unknown;
|
|
79
|
+
readonly id?: string | undefined;
|
|
80
|
+
readonly service_tier?: string | null | undefined;
|
|
81
|
+
readonly incomplete_details?: {
|
|
82
|
+
readonly reason?: string | undefined;
|
|
83
|
+
} | null | undefined;
|
|
84
|
+
readonly output?: readonly {
|
|
85
|
+
readonly [x: string]: unknown;
|
|
86
|
+
readonly type: string;
|
|
87
|
+
readonly id?: string | undefined;
|
|
88
|
+
readonly call_id?: string | undefined;
|
|
89
|
+
readonly name?: string | undefined;
|
|
90
|
+
readonly namespace?: string | undefined;
|
|
91
|
+
readonly arguments?: string | undefined;
|
|
92
|
+
readonly encrypted_content?: string | null | undefined;
|
|
93
|
+
}[] | undefined;
|
|
94
|
+
readonly usage?: {
|
|
95
|
+
readonly [x: string]: unknown;
|
|
96
|
+
readonly input_tokens?: number | undefined;
|
|
97
|
+
readonly input_tokens_details?: {
|
|
98
|
+
readonly [x: string]: unknown;
|
|
99
|
+
readonly cached_tokens?: number | undefined;
|
|
100
|
+
readonly cache_write_tokens?: number | undefined;
|
|
101
|
+
} | null | undefined;
|
|
102
|
+
readonly output_tokens?: number | undefined;
|
|
103
|
+
readonly output_tokens_details?: {
|
|
104
|
+
readonly [x: string]: unknown;
|
|
105
|
+
readonly reasoning_tokens?: number | undefined;
|
|
106
|
+
} | null | undefined;
|
|
107
|
+
readonly total_tokens?: number | undefined;
|
|
108
|
+
} | null | undefined;
|
|
109
|
+
readonly error?: unknown;
|
|
110
|
+
} | undefined;
|
|
111
|
+
readonly code?: unknown;
|
|
112
|
+
readonly message?: unknown;
|
|
113
|
+
readonly error?: unknown;
|
|
114
|
+
readonly status?: unknown;
|
|
115
|
+
readonly status_code?: unknown;
|
|
116
|
+
}, string, never, never>;
|
|
117
|
+
initial: (request: LLMRequest) => OpenResponses.ParserState;
|
|
118
|
+
step: (state: OpenResponses.ParserState, input: OpenResponses.Event) => AIError | Effect.Effect<OpenResponses.StepResult, AIError, never>;
|
|
119
|
+
terminal: typeof OpenResponses.terminal;
|
|
120
|
+
};
|
|
121
|
+
export declare const onDone: (state: OpenResponses.ParserState, item: Item, tools: Definitions) => Effect.Effect<OpenResponses.StepResult, AIError>;
|
|
122
|
+
export * as ResponsesHostedTools from "./responses-hosted-tools.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { StreamEvent } from "../../schema/index.js";
|
|
3
|
+
import { OpenResponses } from "../open-responses.js";
|
|
4
|
+
import { Lifecycle } from "./lifecycle.js";
|
|
5
|
+
/** Hosted tools that several Responses providers report with the same item shape. */
|
|
6
|
+
export const common = {
|
|
7
|
+
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
8
|
+
file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
|
|
9
|
+
code_interpreter_call: {
|
|
10
|
+
name: "code_interpreter",
|
|
11
|
+
input: (item) => ({ code: item.code, container_id: item.container_id }),
|
|
12
|
+
},
|
|
13
|
+
mcp_call: {
|
|
14
|
+
name: "mcp",
|
|
15
|
+
input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export const isItem = (item, tools) => item.type in tools;
|
|
19
|
+
/**
|
|
20
|
+
* Responses stream that turns completed hosted tool items into a provider-executed
|
|
21
|
+
* tool call and result. `override` sees each normalized event first and may handle it.
|
|
22
|
+
*/
|
|
23
|
+
export const stream = (adapter, tools, override) => ({
|
|
24
|
+
event: OpenResponses.protocol.stream.event,
|
|
25
|
+
initial: (request) => OpenResponses.initial(request, adapter),
|
|
26
|
+
step: (state, input) => {
|
|
27
|
+
const event = OpenResponses.normalize(state, input);
|
|
28
|
+
const handled = override?.(state, event);
|
|
29
|
+
if (handled)
|
|
30
|
+
return handled;
|
|
31
|
+
if (event.type === "response.output_item.done" && event.item && isItem(event.item, tools))
|
|
32
|
+
return onDone(state, event.item, tools);
|
|
33
|
+
return OpenResponses.step(state, event);
|
|
34
|
+
},
|
|
35
|
+
terminal: OpenResponses.terminal,
|
|
36
|
+
});
|
|
37
|
+
export const onDone = Effect.fnUntraced(function* (state, item, tools) {
|
|
38
|
+
const tool = tools[item.type];
|
|
39
|
+
if (!tool)
|
|
40
|
+
return [state, []];
|
|
41
|
+
const providerMetadata = OpenResponses.providerMetadata(state, { itemId: item.id });
|
|
42
|
+
const events = [];
|
|
43
|
+
const lifecycle = Lifecycle.start(state.lifecycle);
|
|
44
|
+
events.push(StreamEvent.toolCall({
|
|
45
|
+
id: item.id,
|
|
46
|
+
name: tool.name,
|
|
47
|
+
input: tool.input(item),
|
|
48
|
+
providerExecuted: true,
|
|
49
|
+
providerMetadata,
|
|
50
|
+
}), StreamEvent.toolResult({
|
|
51
|
+
id: item.id,
|
|
52
|
+
name: tool.name,
|
|
53
|
+
result: tool.result
|
|
54
|
+
? yield* tool.result(item)
|
|
55
|
+
: item.error !== undefined && item.error !== null
|
|
56
|
+
? { type: "error", value: item.error }
|
|
57
|
+
: { type: "json", value: item },
|
|
58
|
+
providerExecuted: true,
|
|
59
|
+
providerMetadata,
|
|
60
|
+
}));
|
|
61
|
+
return [{ ...state, lifecycle }, events];
|
|
62
|
+
});
|
|
63
|
+
export * as ResponsesHostedTools from "./responses-hosted-tools.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Split an ordered token list into runs of consecutive tokens with the same speaker. */
|
|
2
|
+
export const group = (items, speaker) => items.reduce((turns, item) => {
|
|
3
|
+
const last = turns.at(-1);
|
|
4
|
+
if (last === undefined || speaker(last[0]) !== speaker(item))
|
|
5
|
+
return [...turns, [item]];
|
|
6
|
+
last.push(item);
|
|
7
|
+
return turns;
|
|
8
|
+
}, []);
|
|
9
|
+
export * as SpeakerTurns from "./speaker-turns.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { Media } from "../../media.js";
|
|
3
|
+
import type { MediaProtocol } from "../../route/media-protocol.js";
|
|
4
|
+
import type { AIError, MediaUsage, ProviderMetadata } from "../../schema/index.js";
|
|
5
|
+
import { type SpeechEvent, type SpeechVoice } from "../../speech.js";
|
|
6
|
+
export interface Audio {
|
|
7
|
+
/** Appended in place: the route creates fresh state for each response through `initial`. */
|
|
8
|
+
readonly chunks: Array<Uint8Array>;
|
|
9
|
+
}
|
|
10
|
+
export type StepResult<State> = readonly [State, ReadonlyArray<SpeechEvent>];
|
|
11
|
+
/** Empty chunks (keep-alive records) emit nothing. */
|
|
12
|
+
export declare const delta: <State extends Audio>(state: State, chunk: Uint8Array) => StepResult<State>;
|
|
13
|
+
export declare const step: <State extends Audio>(onRecord: (state: State, frame: string) => Effect.Effect<StepResult<State>, AIError>) => (state: State, frame: string | Uint8Array) => Effect.Effect<StepResult<State>, AIError, never>;
|
|
14
|
+
export declare const timestamps: (texts: ReadonlyArray<string>, starts: ReadonlyArray<number>, ends: ReadonlyArray<number>) => ReadonlyArray<SpeechEvent>;
|
|
15
|
+
export declare const voiceID: (voice: SpeechVoice | undefined) => string | undefined;
|
|
16
|
+
export declare const container: (format: string, sampleRate?: number) => {
|
|
17
|
+
mediaType: string;
|
|
18
|
+
info: {
|
|
19
|
+
format: string;
|
|
20
|
+
sampleRate: number | undefined;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
declare const PCM_MEDIA_TYPES: {
|
|
24
|
+
readonly pcm_s16le: "audio/pcm";
|
|
25
|
+
readonly pcm_f32le: "audio/pcm";
|
|
26
|
+
readonly pcm_mulaw: "audio/mulaw";
|
|
27
|
+
readonly pcm_alaw: "audio/alaw";
|
|
28
|
+
};
|
|
29
|
+
export type PcmEncoding = keyof typeof PCM_MEDIA_TYPES;
|
|
30
|
+
export declare const pcm: (encoding: PcmEncoding, sampleRate: number | undefined, mediaType?: string) => {
|
|
31
|
+
mediaType: string;
|
|
32
|
+
info: {
|
|
33
|
+
format: string;
|
|
34
|
+
encoding: "pcm_alaw" | "pcm_f32le" | "pcm_mulaw" | "pcm_s16le";
|
|
35
|
+
sampleRate: number | undefined;
|
|
36
|
+
channels: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare const sampleRate: (mediaType: string | undefined) => number | undefined;
|
|
40
|
+
/** A declared `mediaType` wins over sniffing: headerless PCM can start with bytes that look like an MPEG frame sync. */
|
|
41
|
+
export declare const finish: (route: MediaProtocol.Identity, state: Audio, output: {
|
|
42
|
+
readonly mediaType: string | undefined;
|
|
43
|
+
readonly info?: Media.Info;
|
|
44
|
+
readonly usage?: MediaUsage;
|
|
45
|
+
readonly providerMetadata?: ProviderMetadata;
|
|
46
|
+
readonly detail?: string;
|
|
47
|
+
}) => Effect.Effect<ReadonlyArray<SpeechEvent>, AIError>;
|
|
48
|
+
export declare const headerUsage: (type: "characters" | "credits", value: string | undefined) => MediaUsage | undefined;
|
|
49
|
+
export * as SpeechStream from "./speech-stream.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { Media } from "../../media.js";
|
|
3
|
+
import { SpeechAudioDeltaEvent, SpeechFinishEvent, SpeechTimestampsEvent, } from "../../speech.js";
|
|
4
|
+
import { concatBytes } from "../../utils/bytes.js";
|
|
5
|
+
/** Empty chunks (keep-alive records) emit nothing. */
|
|
6
|
+
export const delta = (state, chunk) => {
|
|
7
|
+
if (chunk.length === 0)
|
|
8
|
+
return [state, []];
|
|
9
|
+
state.chunks.push(chunk);
|
|
10
|
+
return [state, [SpeechAudioDeltaEvent.make({ chunk })]];
|
|
11
|
+
};
|
|
12
|
+
export const step = (onRecord) => (state, frame) => typeof frame === "string" ? onRecord(state, frame) : Effect.succeed(delta(state, frame));
|
|
13
|
+
export const timestamps = (texts, starts, ends) => texts.length === 0
|
|
14
|
+
? []
|
|
15
|
+
: [
|
|
16
|
+
SpeechTimestampsEvent.make({
|
|
17
|
+
items: texts.map((text, index) => ({ text, startSeconds: starts[index] ?? 0, endSeconds: ends[index] ?? 0 })),
|
|
18
|
+
}),
|
|
19
|
+
];
|
|
20
|
+
export const voiceID = (voice) => (typeof voice === "object" ? voice.id : voice);
|
|
21
|
+
const CONTAINER_MEDIA_TYPES = {
|
|
22
|
+
mp3: "audio/mpeg",
|
|
23
|
+
wav: "audio/wav",
|
|
24
|
+
opus: "audio/ogg",
|
|
25
|
+
aac: "audio/aac",
|
|
26
|
+
flac: "audio/flac",
|
|
27
|
+
};
|
|
28
|
+
export const container = (format, sampleRate) => ({
|
|
29
|
+
mediaType: CONTAINER_MEDIA_TYPES[format],
|
|
30
|
+
info: { format, sampleRate },
|
|
31
|
+
});
|
|
32
|
+
const PCM_MEDIA_TYPES = {
|
|
33
|
+
pcm_s16le: "audio/pcm",
|
|
34
|
+
pcm_f32le: "audio/pcm",
|
|
35
|
+
pcm_mulaw: "audio/mulaw",
|
|
36
|
+
pcm_alaw: "audio/alaw",
|
|
37
|
+
};
|
|
38
|
+
export const pcm = (encoding, sampleRate, mediaType) => ({
|
|
39
|
+
mediaType: mediaType ?? PCM_MEDIA_TYPES[encoding],
|
|
40
|
+
info: { format: "pcm", encoding, sampleRate, channels: 1 },
|
|
41
|
+
});
|
|
42
|
+
export const sampleRate = (mediaType) => {
|
|
43
|
+
const rate = /rate=(\d+)/i.exec(mediaType ?? "")?.[1];
|
|
44
|
+
return rate === undefined ? undefined : Number(rate);
|
|
45
|
+
};
|
|
46
|
+
/** A declared `mediaType` wins over sniffing: headerless PCM can start with bytes that look like an MPEG frame sync. */
|
|
47
|
+
export const finish = (route, state, output) => {
|
|
48
|
+
if (state.chunks.length === 0)
|
|
49
|
+
return Effect.fail(route.frameError(`The provider returned no audio${output.detail === undefined ? "" : ` (${output.detail})`}`));
|
|
50
|
+
return Effect.succeed([
|
|
51
|
+
SpeechFinishEvent.make({
|
|
52
|
+
audio: Media.bytes(concatBytes(state.chunks), output.mediaType, { info: output.info }),
|
|
53
|
+
usage: output.usage,
|
|
54
|
+
providerMetadata: output.providerMetadata,
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
57
|
+
};
|
|
58
|
+
export const headerUsage = (type, value) => {
|
|
59
|
+
const amount = Number(value);
|
|
60
|
+
if (!Number.isFinite(amount))
|
|
61
|
+
return undefined;
|
|
62
|
+
return type === "credits" ? { type, credits: amount } : { type, characters: amount };
|
|
63
|
+
};
|
|
64
|
+
export * as SpeechStream from "./speech-stream.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JsonSchema, type LanguageModel, type LLMRequest } from "../../schema/index.js";
|
|
2
|
+
import { GeminiJsonSchema } from "./gemini-json-schema.js";
|
|
3
|
+
declare const moonshot: (schema: JsonSchema) => JsonSchema;
|
|
4
|
+
declare const tools: (entries: LLMRequest["tools"], model: LanguageModel) => LLMRequest["tools"];
|
|
5
|
+
export declare const ToolSchemaProjection: {
|
|
6
|
+
readonly gemini: typeof GeminiJsonSchema.normalize;
|
|
7
|
+
readonly moonshot: typeof moonshot;
|
|
8
|
+
readonly tools: typeof tools;
|
|
9
|
+
};
|
|
10
|
+
export {};
|