@opencode/ai 2.1.4 → 2.2.1
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 +339 -166
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +50 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1444 -34
- package/dist/index.js +139 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +3 -1
- package/dist/media-client.js +1 -0
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +59 -4
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +26 -6
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- 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/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +10 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +46 -6
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +212 -27
- package/dist/protocols/open-responses.js +116 -54
- package/dist/protocols/openai-chat.d.ts +1135 -31
- package/dist/protocols/openai-chat.js +155 -60
- package/dist/protocols/openai-compatible-chat.d.ts +57 -5
- package/dist/protocols/openai-compatible-responses.d.ts +28 -8
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +36 -24
- package/dist/protocols/openai-images.js +137 -39
- package/dist/protocols/openai-responses.d.ts +202 -42
- package/dist/protocols/openai-responses.js +49 -10
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +58 -4
- package/dist/protocols/venice-chat.js +2 -2
- package/dist/protocols/xai-images.d.ts +7 -2
- package/dist/protocols/xai-images.js +11 -5
- package/dist/protocols/xai-responses.d.ts +30 -3
- package/dist/protocols/xai-responses.js +30 -3
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +60 -4
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +23 -7
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +137 -28
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +259 -145
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +53 -18
- package/dist/providers/anthropic.d.ts +53 -18
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +129 -24
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +124 -12
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +115 -11
- package/dist/providers/cerebras.js +1 -1
- 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 +290 -60
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- 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 +128 -12
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +115 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +115 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +115 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.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 +390 -20
- package/dist/providers/digitalocean.js +53 -11
- package/dist/providers/fireworks.d.ts +115 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +57 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +53 -18
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +24 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +4 -2
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +6 -5
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +119 -15
- package/dist/providers/groq.js +1 -7
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +254 -146
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +139 -26
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +132 -25
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.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 +24 -4
- package/dist/providers/openai-compatible.d.ts +62 -8
- package/dist/providers/openai-compatible.js +29 -10
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +103 -18
- package/dist/providers/openai.js +23 -5
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +11 -12
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.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 +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +446 -35
- package/dist/providers/openrouter.js +78 -27
- package/dist/providers/togetherai.d.ts +115 -11
- package/dist/providers/togetherai.js +1 -1
- 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 +11 -12
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +261 -9
- package/dist/providers/venice.js +33 -17
- 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/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +16 -22
- package/dist/providers/vercel-ai-gateway.js +41 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +66 -12
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +132 -25
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +62 -9
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +3 -4
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +6 -2
- package/dist/route/media.js +8 -6
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +41 -3
- package/dist/schema/messages.js +23 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +53 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +35 -45
- package/dist/testing.js +14 -75
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +69 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +46 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +497 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/protocols/bfl-images.d.ts +0 -38
- package/dist/protocols/bfl-images.js +0 -153
- package/dist/protocols/fal-images.d.ts +0 -25
- package/dist/protocols/fal-images.js +0 -104
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -39
- package/dist/protocols/stability-images.js +0 -136
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { Headers, HttpClientRequest } from "effect/http";
|
|
3
|
-
import { EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationQuestion, EvaluationResponse, EvaluationRounding, } from "../experimental/evaluation.js";
|
|
4
2
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
5
3
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
6
4
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
7
|
-
import {
|
|
5
|
+
import { OpenAIDecisions } from "../protocols/openai-decisions.js";
|
|
6
|
+
import { OpenAIImages } from "../protocols/openai-images.js";
|
|
7
|
+
import { XAIImages } from "../protocols/xai-images.js";
|
|
8
|
+
import { ProviderShared } from "../protocols/shared.js";
|
|
8
9
|
import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js";
|
|
9
|
-
import { Auth } from "../route/auth.js";
|
|
10
10
|
import { AuthOptions } from "../route/auth-options.js";
|
|
11
11
|
import { Route } from "../route/client.js";
|
|
12
12
|
import { Endpoint } from "../route/endpoint.js";
|
|
13
|
-
import { RequestExecutor } from "../route/executor.js";
|
|
14
13
|
import { Framing } from "../route/framing.js";
|
|
15
|
-
import {
|
|
14
|
+
import { MediaRoute } from "../route/media.js";
|
|
15
|
+
import { LLMRequest, ModelID, ProviderID, ProviderMetadata, ReasoningEffort, } from "../schema/index.js";
|
|
16
16
|
export const id = ProviderID.make("vercel-ai-gateway");
|
|
17
17
|
const baseURL = "https://ai-gateway.vercel.sh/v1";
|
|
18
18
|
const GatewayOptionsSchema = Schema.Struct({
|
|
@@ -107,22 +107,15 @@ const chatRoute = route({
|
|
|
107
107
|
framing: OpenAIChat.framing,
|
|
108
108
|
});
|
|
109
109
|
export const routes = [messagesRoute, responsesRoute, chatRoute];
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
usage: optionalNull(Schema.Struct({
|
|
120
|
-
inputTokens: optionalNull(Schema.Number),
|
|
121
|
-
outputTokens: optionalNull(Schema.Number),
|
|
122
|
-
})),
|
|
123
|
-
rounding: optionalNull(EvaluationRounding),
|
|
124
|
-
providerMetadata: optionalNull(ProviderMetadata),
|
|
125
|
-
});
|
|
110
|
+
// The Gateway passes `size` through to most image models, but Grok ignores it and renders 1024x1024; it only reads
|
|
111
|
+
// sizing from `providerOptions.xai`.
|
|
112
|
+
const imageSizing = (request) => {
|
|
113
|
+
if (!/^(spacexai|xai)\//.test(request.model.id))
|
|
114
|
+
return OpenAIImages.pixelSize(request);
|
|
115
|
+
if (request.aspect === undefined && request.resolution === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
return { providerOptions: { xai: { aspect_ratio: request.aspect, resolution: XAIImages.resolution(request) } } };
|
|
118
|
+
};
|
|
126
119
|
export const configure = (input = {}) => {
|
|
127
120
|
const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
|
|
128
121
|
const configured = {
|
|
@@ -147,80 +140,43 @@ export const configure = (input = {}) => {
|
|
|
147
140
|
return chat(modelID);
|
|
148
141
|
return messages(modelID);
|
|
149
142
|
};
|
|
150
|
-
const
|
|
151
|
-
|
|
143
|
+
const media = MediaRoute.deployment({ ...input, baseURL: configured.endpoint.baseURL }, configured.auth);
|
|
144
|
+
const image = (modelID, providerOptions) => OpenAIImages.model({ ...media, id: modelID, provider: id, providerOptions, sizing: imageSizing });
|
|
145
|
+
const decisionRoute = OpenAIDecisions.route.with({
|
|
152
146
|
provider: id,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const url = new URL(`${(input.baseURL ?? baseURL).replace(/\/$/, "")}/evaluate`);
|
|
158
|
-
Object.entries(req.http?.query ?? {}).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
159
|
-
const body = yield* Schema.encodeUnknownEffect(Schema.fromJsonString(Request))({
|
|
160
|
-
...req.http?.body,
|
|
161
|
-
model: req.model.id,
|
|
162
|
-
state: req.state,
|
|
163
|
-
questions: req.questions,
|
|
164
|
-
providerOptions: req.options,
|
|
165
|
-
}).pipe(Effect.mapError((cause) => new AIError({ reason: new InvalidRequestError({ message: cause.message, cause }) })));
|
|
166
|
-
const headers = yield* Auth.toEffect(configured.auth)({
|
|
167
|
-
request: req,
|
|
168
|
-
method: "POST",
|
|
169
|
-
url: url.toString(),
|
|
170
|
-
body,
|
|
171
|
-
headers: Headers.fromInput({ ...input.headers, ...req.http?.headers }),
|
|
172
|
-
});
|
|
173
|
-
const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
|
|
174
|
-
const http = RequestExecutor.responseHttp(res);
|
|
175
|
-
const fail = (message, cause, body) => new AIError({
|
|
176
|
-
reason: new InvalidProviderOutputError({
|
|
177
|
-
route: "vercel-evaluation",
|
|
178
|
-
message,
|
|
179
|
-
body,
|
|
180
|
-
http,
|
|
181
|
-
cause,
|
|
182
|
-
}),
|
|
183
|
-
});
|
|
184
|
-
const text = yield* res.text.pipe(Effect.mapError((cause) => fail("Failed to read the Vercel AI Gateway evaluation response", cause)));
|
|
185
|
-
const data = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => fail("Vercel AI Gateway returned an invalid evaluation response", cause, text)));
|
|
186
|
-
const inputTokens = data.usage?.inputTokens ?? undefined;
|
|
187
|
-
const outputTokens = data.usage?.outputTokens ?? undefined;
|
|
188
|
-
const usage = data.usage
|
|
189
|
-
? new Usage({
|
|
190
|
-
inputTokens,
|
|
191
|
-
outputTokens,
|
|
192
|
-
totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
|
|
193
|
-
providerMetadata: { gateway: data.usage },
|
|
194
|
-
})
|
|
195
|
-
: undefined;
|
|
196
|
-
return new EvaluationResponse({
|
|
197
|
-
model: ModelID.make(data.model ?? req.model.id),
|
|
198
|
-
answers: data.answers,
|
|
199
|
-
usage,
|
|
200
|
-
rounding: data.rounding ?? undefined,
|
|
201
|
-
providerMetadata: data.providerMetadata ?? undefined,
|
|
202
|
-
});
|
|
203
|
-
}),
|
|
204
|
-
},
|
|
147
|
+
endpoint: { baseURL: configured.endpoint.baseURL },
|
|
148
|
+
auth: configured.auth,
|
|
149
|
+
headers: input.headers,
|
|
150
|
+
http: input.http,
|
|
205
151
|
});
|
|
206
|
-
|
|
152
|
+
const decision = (modelID, providerOptions) => decisionRoute.model({ id: modelID, providerOptions });
|
|
153
|
+
return { id, model, messages, responses, chat, image, decision, configure };
|
|
207
154
|
};
|
|
208
155
|
export const provider = configure();
|
|
209
|
-
export const
|
|
156
|
+
export const decision = provider.decision;
|
|
210
157
|
export const messages = provider.messages;
|
|
211
158
|
export const responses = provider.responses;
|
|
212
159
|
export const chat = provider.chat;
|
|
213
|
-
export const
|
|
214
|
-
export const
|
|
215
|
-
export const
|
|
216
|
-
export const
|
|
217
|
-
|
|
218
|
-
|
|
160
|
+
export const image = provider.image;
|
|
161
|
+
export const model = (modelID, settings) => configure(config(settings)).model(modelID);
|
|
162
|
+
export const messagesModel = (modelID, settings) => configure(config(settings)).messages(modelID);
|
|
163
|
+
export const responsesModel = (modelID, settings) => configure(config(settings)).responses(modelID);
|
|
164
|
+
export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID);
|
|
165
|
+
export const imageModel = (modelID, settings) => {
|
|
166
|
+
const input = config(settings);
|
|
167
|
+
return configure(input).image(modelID, input.providerOptions);
|
|
168
|
+
};
|
|
169
|
+
export const decisionModel = (modelID, settings) => {
|
|
170
|
+
const input = config(settings);
|
|
171
|
+
return configure(input).decision(modelID, input.providerOptions);
|
|
172
|
+
};
|
|
173
|
+
function config({ apiKey, baseURL, headers, body, ...providerOptions } = {}) {
|
|
174
|
+
return {
|
|
219
175
|
apiKey,
|
|
220
176
|
baseURL,
|
|
221
177
|
headers,
|
|
222
178
|
http: body === undefined ? undefined : { body },
|
|
223
179
|
providerOptions,
|
|
224
|
-
}
|
|
180
|
+
};
|
|
225
181
|
}
|
|
226
182
|
export * as VercelAIGateway from "./vercel-ai-gateway.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { imageModel as model } from "../xai.js";
|
package/dist/providers/xai.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
2
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
3
|
-
import { type ModelID } from "../schema/index.js";
|
|
3
|
+
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
4
|
+
import { XAIResponses } from "../protocols/xai-responses.js";
|
|
4
5
|
import type { OpenAIOptionsInput } from "./openai-options.js";
|
|
5
6
|
import type { ProviderPackage } from "../provider-package.js";
|
|
6
7
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
-
export type XAIProviderOptionsInput = OpenAIOptionsInput & {
|
|
8
|
+
export type XAIProviderOptionsInput = OpenAIOptionsInput & XAIResponses.OptionsInput & {
|
|
8
9
|
readonly contextManagement?: never;
|
|
9
10
|
};
|
|
10
|
-
export type
|
|
11
|
+
export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
11
12
|
readonly baseURL?: string;
|
|
12
13
|
readonly providerOptions?: XAIProviderOptionsInput;
|
|
13
14
|
};
|
|
@@ -31,6 +32,11 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
31
32
|
readonly image_url: {
|
|
32
33
|
readonly url: string;
|
|
33
34
|
};
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "video_url";
|
|
37
|
+
readonly video_url: {
|
|
38
|
+
readonly url: string;
|
|
39
|
+
};
|
|
34
40
|
} | {
|
|
35
41
|
readonly type: "file";
|
|
36
42
|
readonly file: {
|
|
@@ -52,6 +58,11 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
52
58
|
readonly image_url: {
|
|
53
59
|
readonly url: string;
|
|
54
60
|
};
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: "video_url";
|
|
63
|
+
readonly video_url: {
|
|
64
|
+
readonly url: string;
|
|
65
|
+
};
|
|
55
66
|
} | {
|
|
56
67
|
readonly type: "file";
|
|
57
68
|
readonly file: {
|
|
@@ -88,7 +99,14 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
88
99
|
readonly ttl?: string | undefined;
|
|
89
100
|
} | undefined;
|
|
90
101
|
}[] | null;
|
|
91
|
-
readonly tool_calls?: readonly {
|
|
102
|
+
readonly tool_calls?: readonly ({
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly type: "custom";
|
|
105
|
+
readonly custom: {
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly input: string;
|
|
108
|
+
};
|
|
109
|
+
} | {
|
|
92
110
|
readonly id: string;
|
|
93
111
|
readonly type: "function";
|
|
94
112
|
readonly function: {
|
|
@@ -100,13 +118,13 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
100
118
|
readonly thought_signature: string;
|
|
101
119
|
};
|
|
102
120
|
} | undefined;
|
|
103
|
-
}[] | undefined;
|
|
121
|
+
})[] | undefined;
|
|
104
122
|
readonly reasoning_content?: string | undefined;
|
|
105
123
|
readonly reasoning?: string | undefined;
|
|
106
124
|
readonly reasoning_text?: string | undefined;
|
|
107
125
|
readonly reasoning_details?: unknown;
|
|
108
126
|
})[];
|
|
109
|
-
readonly tools?: readonly {
|
|
127
|
+
readonly tools?: readonly ({
|
|
110
128
|
readonly type: "function";
|
|
111
129
|
readonly function: {
|
|
112
130
|
readonly name: string;
|
|
@@ -120,12 +138,36 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
120
138
|
readonly type: "ephemeral";
|
|
121
139
|
readonly ttl?: string | undefined;
|
|
122
140
|
} | undefined;
|
|
123
|
-
}
|
|
141
|
+
} | {
|
|
142
|
+
readonly type: "custom";
|
|
143
|
+
readonly custom: {
|
|
144
|
+
readonly name: string;
|
|
145
|
+
readonly description: string;
|
|
146
|
+
readonly format: {
|
|
147
|
+
readonly type: "text";
|
|
148
|
+
} | {
|
|
149
|
+
readonly type: "grammar";
|
|
150
|
+
readonly grammar: {
|
|
151
|
+
readonly syntax: "lark" | "regex";
|
|
152
|
+
readonly definition: string;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
readonly cache_control?: {
|
|
157
|
+
readonly type: "ephemeral";
|
|
158
|
+
readonly ttl?: string | undefined;
|
|
159
|
+
} | undefined;
|
|
160
|
+
})[] | undefined;
|
|
124
161
|
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
125
162
|
readonly type: "function";
|
|
126
163
|
readonly function: {
|
|
127
164
|
readonly name: string;
|
|
128
165
|
};
|
|
166
|
+
} | {
|
|
167
|
+
readonly type: "custom";
|
|
168
|
+
readonly custom: {
|
|
169
|
+
readonly name: string;
|
|
170
|
+
};
|
|
129
171
|
} | undefined;
|
|
130
172
|
readonly stream: true;
|
|
131
173
|
readonly stream_options?: {
|
|
@@ -133,7 +175,18 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
133
175
|
} | undefined;
|
|
134
176
|
readonly store?: boolean | undefined;
|
|
135
177
|
readonly prompt_cache_key?: string | undefined;
|
|
178
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
179
|
+
readonly prompt_cache_options?: {
|
|
180
|
+
readonly ttl?: string | undefined;
|
|
181
|
+
} | undefined;
|
|
136
182
|
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
183
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
184
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
185
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
186
|
+
readonly metadata?: {
|
|
187
|
+
readonly [x: string]: string;
|
|
188
|
+
} | undefined;
|
|
189
|
+
readonly safety_identifier?: string | undefined;
|
|
137
190
|
readonly tool_stream?: boolean | undefined;
|
|
138
191
|
readonly max_completion_tokens?: number | undefined;
|
|
139
192
|
readonly max_tokens?: number | undefined;
|
|
@@ -144,7 +197,7 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
|
|
|
144
197
|
readonly seed?: number | undefined;
|
|
145
198
|
readonly stop?: readonly string[] | undefined;
|
|
146
199
|
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>)[];
|
|
147
|
-
export declare const configure: (input?:
|
|
200
|
+
export declare const configure: (input?: Config) => {
|
|
148
201
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
149
202
|
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, {
|
|
150
203
|
endpoint: import("../route/client.js").CompactOperation;
|
|
@@ -153,7 +206,7 @@ export declare const configure: (input?: LanguageModelOptions) => {
|
|
|
153
206
|
endpoint: import("../route/client.js").CompactOperation;
|
|
154
207
|
}>;
|
|
155
208
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
156
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
209
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
157
210
|
video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
|
|
158
211
|
configure: typeof configure;
|
|
159
212
|
};
|
|
@@ -166,14 +219,15 @@ export declare const provider: {
|
|
|
166
219
|
endpoint: import("../route/client.js").CompactOperation;
|
|
167
220
|
}>;
|
|
168
221
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
169
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
222
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
170
223
|
video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
|
|
171
224
|
configure: typeof configure;
|
|
172
225
|
};
|
|
173
|
-
export declare const model: ProviderPackage.
|
|
226
|
+
export declare const model: ProviderPackage.Model<Settings, XAIProviderOptionsInput, typeof responsesRoute.compact>;
|
|
227
|
+
export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
174
228
|
export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, {
|
|
175
229
|
endpoint: import("../route/client.js").CompactOperation;
|
|
176
230
|
}>;
|
|
177
231
|
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
178
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
232
|
+
export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
|
|
179
233
|
export declare const video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/xai-video.js").XAIVideoOptions>;
|
package/dist/providers/xai.js
CHANGED
|
@@ -67,19 +67,26 @@ export const configure = (input = {}) => {
|
|
|
67
67
|
model: responses,
|
|
68
68
|
responses,
|
|
69
69
|
chat,
|
|
70
|
-
image: (modelID) => XAIImages.model({ ...media, id: modelID }),
|
|
70
|
+
image: (modelID, providerOptions) => XAIImages.model({ ...media, id: modelID, providerOptions }),
|
|
71
71
|
video: (modelID) => XAIVideo.model({ ...media, id: modelID }),
|
|
72
72
|
configure,
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
export const provider = configure();
|
|
76
|
-
export const model = (modelID,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
export const model = (modelID, settings) => configure(config(settings)).model(modelID);
|
|
77
|
+
export const imageModel = (modelID, settings) => {
|
|
78
|
+
const input = config(settings);
|
|
79
|
+
return configure(input).image(modelID, input.providerOptions);
|
|
80
|
+
};
|
|
81
|
+
function config({ apiKey, baseURL, body, headers, ...providerOptions } = {}) {
|
|
82
|
+
return {
|
|
83
|
+
apiKey,
|
|
84
|
+
baseURL,
|
|
85
|
+
headers,
|
|
86
|
+
http: body === undefined ? undefined : { body },
|
|
87
|
+
providerOptions,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
83
90
|
export const responses = provider.responses;
|
|
84
91
|
export const chat = provider.chat;
|
|
85
92
|
export const image = provider.image;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { imageModel as model } from "../zai.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../../provider-package.js";
|
|
2
2
|
import { ZAICodingPlan } from "../zai-coding-plan.js";
|
|
3
3
|
export type Settings = ZAICodingPlan.Settings<ZAICodingPlan.MessagesOptionsInput>;
|
|
4
|
-
export declare const model: ProviderPackage.
|
|
4
|
+
export declare const model: ProviderPackage.Model<Settings, ZAICodingPlan.MessagesOptionsInput>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZAICodingPlan } from "../zai-coding-plan.js";
|
|
2
|
-
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => ZAICodingPlan.configure({
|
|
2
|
+
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions } = {}) => ZAICodingPlan.configure({
|
|
3
3
|
apiKey,
|
|
4
4
|
baseURL,
|
|
5
5
|
headers,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../../provider-package.js";
|
|
2
2
|
import { ZAICodingPlan } from "../zai-coding-plan.js";
|
|
3
3
|
export type Settings = ZAICodingPlan.Settings<ZAICodingPlan.ResponsesOptionsInput>;
|
|
4
|
-
export declare const model: ProviderPackage.
|
|
4
|
+
export declare const model: ProviderPackage.Model<Settings, ZAICodingPlan.ResponsesOptionsInput>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZAICodingPlan } from "../zai-coding-plan.js";
|
|
2
|
-
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => ZAICodingPlan.configure({
|
|
2
|
+
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions } = {}) => ZAICodingPlan.configure({
|
|
3
3
|
apiKey,
|
|
4
4
|
baseURL,
|
|
5
5
|
headers,
|