@opencode/ai 2.2.5 → 2.2.6
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 +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +54 -173
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +54 -72
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +7 -10
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +7 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -23
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +7 -22
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
package/dist/providers/venice.js
CHANGED
|
@@ -22,7 +22,7 @@ const responsesRoute = Route.make({
|
|
|
22
22
|
protocol: OpenResponses.protocol,
|
|
23
23
|
endpoint: Endpoint.path("/responses", { baseURL }),
|
|
24
24
|
transport: OpenResponses.httpTransport,
|
|
25
|
-
|
|
25
|
+
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
|
26
26
|
});
|
|
27
27
|
export const routes = [route, responsesRoute];
|
|
28
28
|
export const configure = (input = {}) => {
|
|
@@ -32,7 +32,11 @@ export const configure = (input = {}) => {
|
|
|
32
32
|
endpoint: { baseURL: endpoint ?? baseURL, query: queryParams },
|
|
33
33
|
auth: AuthOptions.bearer(input, "VENICE_API_KEY"),
|
|
34
34
|
};
|
|
35
|
-
const chat = (modelID) => route.with(options).model({
|
|
35
|
+
const chat = (modelID) => route.with(options).model({
|
|
36
|
+
id: modelID,
|
|
37
|
+
compatibility: VeniceChat.compatibility,
|
|
38
|
+
capabilities: VeniceChat.capabilities,
|
|
39
|
+
});
|
|
36
40
|
const responses = (modelID) => responsesRoute.with(options).model({ id: modelID });
|
|
37
41
|
return { id, model: chat, chat, responses, configure };
|
|
38
42
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
2
2
|
import type { ProviderPackage } from "../provider-package.js";
|
|
3
|
-
import {
|
|
4
|
-
import { Route
|
|
5
|
-
import { ModelID, type ProviderOptions } from "../schema/index.js";
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { Route } from "../route/client.js";
|
|
5
|
+
import { ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
6
6
|
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js";
|
|
7
7
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
8
8
|
export interface GatewayOptions {
|
|
@@ -63,12 +63,12 @@ export type ProviderOptionsInput = OpenResponsesProviderOptionsInput & Omit<Anth
|
|
|
63
63
|
/** Responses API count of stable input items to anchor for caching, sent as top-level `cache_anchor_items`. */
|
|
64
64
|
readonly cacheAnchorItems?: number;
|
|
65
65
|
};
|
|
66
|
-
export type Config = Omit<
|
|
66
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
67
67
|
readonly baseURL?: string;
|
|
68
68
|
readonly providerOptions?: ProviderOptionsInput;
|
|
69
69
|
};
|
|
70
70
|
export type Settings = ProviderPackage.Settings & ProviderOptionsInput & {
|
|
71
|
-
readonly apiKey?: string;
|
|
71
|
+
readonly apiKey?: string | false;
|
|
72
72
|
};
|
|
73
73
|
export declare const routes: Route<{
|
|
74
74
|
readonly [x: string]: unknown;
|
|
@@ -7,12 +7,12 @@ import { OpenAIImages } from "../protocols/openai-images.js";
|
|
|
7
7
|
import { XAIImages } from "../protocols/xai-images.js";
|
|
8
8
|
import { ProviderShared } from "../protocols/shared.js";
|
|
9
9
|
import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js";
|
|
10
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
11
10
|
import { Route } from "../route/client.js";
|
|
12
11
|
import { Endpoint } from "../route/endpoint.js";
|
|
13
12
|
import { Framing } from "../route/framing.js";
|
|
14
13
|
import { MediaRoute } from "../route/media.js";
|
|
15
|
-
import {
|
|
14
|
+
import { ModelID, ProviderID, ProviderMetadata, ReasoningEffort, } from "../schema/index.js";
|
|
15
|
+
import { bearerRouteDefaults, toConfig } from "./settings.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({
|
|
@@ -44,13 +44,14 @@ const prepare = (api) => Effect.fnUntraced(function* (request) {
|
|
|
44
44
|
return { request, body: { providerOptions } };
|
|
45
45
|
const enabled = effort !== "none";
|
|
46
46
|
const thinking = request.providerOptions?.thinking ?? { type: enabled ? "adaptive" : "disabled" };
|
|
47
|
-
const next =
|
|
47
|
+
const next = {
|
|
48
|
+
...request,
|
|
48
49
|
providerOptions: {
|
|
49
50
|
...request.providerOptions,
|
|
50
51
|
effort: enabled ? effort : undefined,
|
|
51
52
|
thinking,
|
|
52
53
|
},
|
|
53
|
-
}
|
|
54
|
+
};
|
|
54
55
|
return { request: next, body: { providerOptions } };
|
|
55
56
|
}
|
|
56
57
|
case "responses":
|
|
@@ -81,7 +82,7 @@ const route = (input) => Route.make({
|
|
|
81
82
|
endpoint: Endpoint.path(input.path, { baseURL }),
|
|
82
83
|
framing: input.framing,
|
|
83
84
|
headers: ({ request }) => request.promptCacheKey ? { "x-session-affinity": request.promptCacheKey } : {},
|
|
84
|
-
|
|
85
|
+
options: input.options,
|
|
85
86
|
});
|
|
86
87
|
const messagesRoute = route({
|
|
87
88
|
id: "vercel-ai-gateway-messages",
|
|
@@ -89,7 +90,7 @@ const messagesRoute = route({
|
|
|
89
90
|
api: "messages",
|
|
90
91
|
path: "/messages",
|
|
91
92
|
framing: AnthropicMessages.framing,
|
|
92
|
-
|
|
93
|
+
options: { headers: { "anthropic-version": "2023-06-01" } },
|
|
93
94
|
});
|
|
94
95
|
const responsesRoute = route({
|
|
95
96
|
id: "vercel-ai-gateway-responses",
|
|
@@ -97,7 +98,7 @@ const responsesRoute = route({
|
|
|
97
98
|
api: "responses",
|
|
98
99
|
path: "/responses",
|
|
99
100
|
framing: Framing.sse,
|
|
100
|
-
|
|
101
|
+
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
|
101
102
|
});
|
|
102
103
|
const chatRoute = route({
|
|
103
104
|
id: "vercel-ai-gateway-chat",
|
|
@@ -117,12 +118,7 @@ const imageSizing = (request) => {
|
|
|
117
118
|
return { providerOptions: { xai: { aspect_ratio: request.aspect, resolution: XAIImages.resolution(request) } } };
|
|
118
119
|
};
|
|
119
120
|
export const configure = (input = {}) => {
|
|
120
|
-
const
|
|
121
|
-
const configured = {
|
|
122
|
-
...defaults,
|
|
123
|
-
endpoint: { baseURL: endpoint ?? baseURL },
|
|
124
|
-
auth: AuthOptions.bearer(input, ["AI_GATEWAY_API_KEY", "VERCEL_OIDC_TOKEN"]),
|
|
125
|
-
};
|
|
121
|
+
const configured = bearerRouteDefaults(input, ["AI_GATEWAY_API_KEY", "VERCEL_OIDC_TOKEN"], baseURL);
|
|
126
122
|
const messages = (modelID) => messagesRoute.with(configured).model({
|
|
127
123
|
id: modelID,
|
|
128
124
|
// Recorded Gateway translations for non-Claude models return thinking with empty signatures.
|
|
@@ -158,25 +154,16 @@ export const messages = provider.messages;
|
|
|
158
154
|
export const responses = provider.responses;
|
|
159
155
|
export const chat = provider.chat;
|
|
160
156
|
export const image = provider.image;
|
|
161
|
-
export const model = (modelID, settings) => configure(
|
|
162
|
-
export const messagesModel = (modelID, settings) => configure(
|
|
163
|
-
export const responsesModel = (modelID, settings) => configure(
|
|
164
|
-
export const chatModel = (modelID, settings) => configure(
|
|
157
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
158
|
+
export const messagesModel = (modelID, settings) => configure(toConfig(settings)).messages(modelID);
|
|
159
|
+
export const responsesModel = (modelID, settings) => configure(toConfig(settings)).responses(modelID);
|
|
160
|
+
export const chatModel = (modelID, settings) => configure(toConfig(settings)).chat(modelID);
|
|
165
161
|
export const imageModel = (modelID, settings) => {
|
|
166
|
-
const input =
|
|
162
|
+
const input = toConfig(settings);
|
|
167
163
|
return configure(input).image(modelID, input.providerOptions);
|
|
168
164
|
};
|
|
169
165
|
export const decisionModel = (modelID, settings) => {
|
|
170
|
-
const input =
|
|
166
|
+
const input = toConfig(settings);
|
|
171
167
|
return configure(input).decision(modelID, input.providerOptions);
|
|
172
168
|
};
|
|
173
|
-
function config({ apiKey, baseURL, headers, body, ...providerOptions } = {}) {
|
|
174
|
-
return {
|
|
175
|
-
apiKey,
|
|
176
|
-
baseURL,
|
|
177
|
-
headers,
|
|
178
|
-
http: body === undefined ? undefined : { body },
|
|
179
|
-
providerOptions,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
169
|
export * as VercelAIGateway from "./vercel-ai-gateway.js";
|
package/dist/providers/xai.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { Route
|
|
3
|
-
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
4
4
|
import { XAIResponses } from "../protocols/xai-responses.js";
|
|
5
5
|
import type { OpenAIOptionsInput } from "./openai-options.js";
|
|
6
6
|
import type { ProviderPackage } from "../provider-package.js";
|
|
@@ -8,12 +8,12 @@ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
|
8
8
|
export type XAIProviderOptionsInput = OpenAIOptionsInput & XAIResponses.OptionsInput & {
|
|
9
9
|
readonly contextManagement?: never;
|
|
10
10
|
};
|
|
11
|
-
export type Config = Omit<
|
|
11
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
12
12
|
readonly baseURL?: string;
|
|
13
13
|
readonly providerOptions?: XAIProviderOptionsInput;
|
|
14
14
|
};
|
|
15
15
|
export type Settings = ProviderPackage.Settings & XAIProviderOptionsInput & {
|
|
16
|
-
readonly apiKey?: string;
|
|
16
|
+
readonly apiKey?: string | false;
|
|
17
17
|
readonly baseURL?: string;
|
|
18
18
|
};
|
|
19
19
|
export type { XAIImageOptions } from "../protocols/xai-images.js";
|
package/dist/providers/xai.js
CHANGED
|
@@ -8,6 +8,7 @@ import { OpenResponsesChannel } from "../protocols/open-responses-channel.js";
|
|
|
8
8
|
import { XAIResponses } from "../protocols/xai-responses.js";
|
|
9
9
|
import { XAIImages } from "../protocols/xai-images.js";
|
|
10
10
|
import { XAIVideo } from "../protocols/xai-video.js";
|
|
11
|
+
import { toConfig } from "./settings.js";
|
|
11
12
|
export const id = ProviderID.make("xai");
|
|
12
13
|
const baseURL = "https://api.x.ai/v1";
|
|
13
14
|
const RESPONSES_WEBSOCKET_ROTATE_AFTER_MS = 24 * 60 * 1000;
|
|
@@ -27,7 +28,7 @@ const responsesRoute = Route.make({
|
|
|
27
28
|
// rejects `instructions` next to `previous_response_id` and keeps the instructions of the response it continues.
|
|
28
29
|
continuation: ({ instructions: _instructions, ...request }) => (request.store === false ? undefined : request),
|
|
29
30
|
}),
|
|
30
|
-
|
|
31
|
+
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
|
31
32
|
});
|
|
32
33
|
const chatRoute = Route.make({
|
|
33
34
|
id: "xai-chat",
|
|
@@ -73,20 +74,11 @@ export const configure = (input = {}) => {
|
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
76
|
export const provider = configure();
|
|
76
|
-
export const model = (modelID, settings) => configure(
|
|
77
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
77
78
|
export const imageModel = (modelID, settings) => {
|
|
78
|
-
const input =
|
|
79
|
+
const input = toConfig(settings);
|
|
79
80
|
return configure(input).image(modelID, input.providerOptions);
|
|
80
81
|
};
|
|
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
|
-
}
|
|
90
82
|
export const responses = provider.responses;
|
|
91
83
|
export const chat = provider.chat;
|
|
92
84
|
export const image = provider.image;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { ZAICodingPlan } from "../zai-coding-plan.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
baseURL,
|
|
5
|
-
headers,
|
|
6
|
-
http: body === undefined ? undefined : { body },
|
|
7
|
-
providerOptions,
|
|
8
|
-
}).messages(modelID);
|
|
2
|
+
import { toConfig } from "../settings.js";
|
|
3
|
+
export const model = (modelID, settings) => ZAICodingPlan.configure(toConfig(settings)).messages(modelID);
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { ZAICodingPlan } from "../zai-coding-plan.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
baseURL,
|
|
5
|
-
headers,
|
|
6
|
-
http: body === undefined ? undefined : { body },
|
|
7
|
-
providerOptions,
|
|
8
|
-
}).responses(modelID);
|
|
2
|
+
import { toConfig } from "../settings.js";
|
|
3
|
+
export const model = (modelID, settings) => ZAICodingPlan.configure(toConfig(settings)).responses(modelID);
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
3
3
|
import { ZAIMessages } from "../protocols/zai-messages.js";
|
|
4
|
-
import {
|
|
5
|
-
import { Route
|
|
6
|
-
import { type ModelID } from "../schema/index.js";
|
|
4
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
5
|
+
import { Route } from "../route/client.js";
|
|
6
|
+
import { type ModelID, type RequestOptions } from "../schema/index.js";
|
|
7
7
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
8
8
|
export type ChatOptionsInput = ZAIChat.OptionsInput;
|
|
9
9
|
export type MessagesOptionsInput = ZAIMessages.OptionsInput;
|
|
10
10
|
export type ResponsesOptionsInput = {
|
|
11
11
|
readonly reasoningEffort?: ZAIChat.ReasoningEffort;
|
|
12
12
|
};
|
|
13
|
-
export type Config = Omit<
|
|
13
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
14
14
|
/** Overrides the selected API's complete base URL. */
|
|
15
15
|
readonly baseURL?: string;
|
|
16
16
|
readonly providerOptions?: ChatOptionsInput | MessagesOptionsInput | ResponsesOptionsInput;
|
|
17
17
|
};
|
|
18
18
|
export type Settings<Options = ChatOptionsInput> = ProviderPackage.Settings & Options & {
|
|
19
|
-
readonly apiKey?: string;
|
|
19
|
+
readonly apiKey?: string | false;
|
|
20
20
|
readonly baseURL?: string;
|
|
21
21
|
};
|
|
22
22
|
export declare const routes: (Route<{
|
|
@@ -3,11 +3,11 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
|
3
3
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
4
4
|
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
5
5
|
import { ZAIMessages } from "../protocols/zai-messages.js";
|
|
6
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
7
6
|
import { Route } from "../route/client.js";
|
|
8
7
|
import { Endpoint } from "../route/endpoint.js";
|
|
9
8
|
import { Framing } from "../route/framing.js";
|
|
10
9
|
import { ProviderID } from "../schema/index.js";
|
|
10
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
11
11
|
export const id = ProviderID.make("zai-coding-plan");
|
|
12
12
|
const chatRoute = Route.make({
|
|
13
13
|
id: "zai-coding-chat",
|
|
@@ -36,13 +36,12 @@ const responsesRoute = Route.make({
|
|
|
36
36
|
});
|
|
37
37
|
export const routes = [chatRoute, messagesRoute, responsesRoute];
|
|
38
38
|
export const configure = (input = {}) => {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
const chat = (modelID) => chatRoute.with(defaults).model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
39
|
+
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY");
|
|
40
|
+
const chat = (modelID) => chatRoute.with(defaults).model({
|
|
41
|
+
id: modelID,
|
|
42
|
+
compatibility: ZAIChat.compatibility,
|
|
43
|
+
capabilities: ZAIChat.capabilities,
|
|
44
|
+
});
|
|
46
45
|
const messages = (modelID) => messagesRoute
|
|
47
46
|
.with(defaults)
|
|
48
47
|
.model({ id: modelID, compatibility: { requireSignature: false } });
|
|
@@ -53,11 +52,5 @@ export const provider = configure();
|
|
|
53
52
|
export const chat = provider.chat;
|
|
54
53
|
export const messages = provider.messages;
|
|
55
54
|
export const responses = provider.responses;
|
|
56
|
-
export const model = (modelID,
|
|
57
|
-
apiKey,
|
|
58
|
-
baseURL,
|
|
59
|
-
headers,
|
|
60
|
-
http: body === undefined ? undefined : { body },
|
|
61
|
-
providerOptions,
|
|
62
|
-
}).model(modelID);
|
|
55
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
63
56
|
export * as ZAICodingPlan from "./zai-coding-plan.js";
|
package/dist/providers/zai.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
3
|
-
import {
|
|
4
|
-
import { Route
|
|
5
|
-
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { Route } from "../route/client.js";
|
|
5
|
+
import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
7
|
export type ChatOptionsInput = ZAIChat.OptionsInput;
|
|
8
|
-
export type Config = Omit<
|
|
8
|
+
export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
9
9
|
readonly baseURL?: string;
|
|
10
10
|
readonly providerOptions?: ChatOptionsInput;
|
|
11
11
|
};
|
|
12
12
|
export type Settings = ProviderPackage.Settings & ChatOptionsInput & {
|
|
13
|
-
readonly apiKey?: string;
|
|
13
|
+
readonly apiKey?: string | false;
|
|
14
14
|
readonly baseURL?: string;
|
|
15
15
|
};
|
|
16
16
|
export type { ZAIImageOptions } from "../protocols/zai-images.js";
|
package/dist/providers/zai.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
2
2
|
import { ZAIImages } from "../protocols/zai-images.js";
|
|
3
3
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
4
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
5
4
|
import { Route } from "../route/client.js";
|
|
6
5
|
import { Endpoint } from "../route/endpoint.js";
|
|
7
6
|
import { MediaRoute } from "../route/media.js";
|
|
8
7
|
import { ProviderID } from "../schema/index.js";
|
|
8
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
9
9
|
export const id = ProviderID.make("zai");
|
|
10
|
-
const auth = (options) => AuthOptions.bearer(options, "ZAI_API_KEY");
|
|
11
10
|
const chatRoute = Route.make({
|
|
12
11
|
id: "zai-chat",
|
|
13
12
|
provider: id,
|
|
@@ -18,15 +17,13 @@ const chatRoute = Route.make({
|
|
|
18
17
|
});
|
|
19
18
|
export const routes = [chatRoute];
|
|
20
19
|
export const configure = (input = {}) => {
|
|
21
|
-
const
|
|
22
|
-
const chat = (modelID) => chatRoute
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
29
|
-
const media = MediaRoute.deployment(input, auth(input));
|
|
20
|
+
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY");
|
|
21
|
+
const chat = (modelID) => chatRoute.with(defaults).model({
|
|
22
|
+
id: modelID,
|
|
23
|
+
compatibility: ZAIChat.compatibility,
|
|
24
|
+
capabilities: ZAIChat.capabilities,
|
|
25
|
+
});
|
|
26
|
+
const media = MediaRoute.deployment(input, defaults.auth);
|
|
30
27
|
const image = (modelID, providerOptions) => ZAIImages.model({ ...media, id: modelID, providerOptions });
|
|
31
28
|
return {
|
|
32
29
|
id,
|
|
@@ -39,18 +36,9 @@ export const configure = (input = {}) => {
|
|
|
39
36
|
export const provider = configure();
|
|
40
37
|
export const image = provider.image;
|
|
41
38
|
export const chat = provider.chat;
|
|
42
|
-
export const model = (modelID, settings) => configure(
|
|
39
|
+
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
43
40
|
export const imageModel = (modelID, settings) => {
|
|
44
|
-
const input =
|
|
41
|
+
const input = toConfig(settings);
|
|
45
42
|
return configure(input).image(modelID, input.providerOptions);
|
|
46
43
|
};
|
|
47
|
-
function config({ apiKey, baseURL, body, headers, ...providerOptions } = {}) {
|
|
48
|
-
return {
|
|
49
|
-
apiKey,
|
|
50
|
-
baseURL,
|
|
51
|
-
headers,
|
|
52
|
-
http: body === undefined ? undefined : { body },
|
|
53
|
-
providerOptions,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
44
|
export * as ZAI from "./zai.js";
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
2
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, GENERATION_KEYS, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishReasonDetails, StepFinish, Finish, MediaEvent, RawEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
|
+
export type { BaseRequest, ContentPartInput, GenerationOptionsFields, HttpOptions, RequestOptions, LanguageModelInput, LanguageModelProviderOptions, LLMRequest, MediaPartInput, RequestTimeout, TimeoutConfig, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, TransportOptions, UsageInput, } from "./schema/index.js";
|
|
4
|
+
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
5
|
+
export type { ImageModelOptions, ImageOptions, ImageRequest, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
|
6
|
+
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
7
|
+
export type { AnswerFor, AnswersFor, DecisionInput, DecisionMediaPartInput, DecisionModelOptions, DecisionOptions, DecisionPartInput, DecisionQuestions, DecisionRequest, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
8
|
+
export { Media } from "./media.js";
|
|
9
|
+
export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
|
|
10
|
+
export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolModelOutputInput, ToolOptions, ToolSchema, ToolToModelOutput, } from "./tool.js";
|
|
11
|
+
export type { LLM } from "./llm.js";
|
|
12
|
+
export type { LLMLoopInput, LLMRequestInput } from "./llm.js";
|
package/dist/public.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
2
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, GENERATION_KEYS, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, SystemMessage, UserMessage, AssistantMessage, ToolMessage, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, FinishReasonDetails, StepFinish, Finish, MediaEvent, RawEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
3
|
+
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageResponse } from "./image.js";
|
|
4
|
+
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
5
|
+
export { Media } from "./media.js";
|
|
@@ -5,12 +5,14 @@ export type AuthOverride = {
|
|
|
5
5
|
readonly auth: Auth.Definition;
|
|
6
6
|
readonly apiKey?: never;
|
|
7
7
|
};
|
|
8
|
+
/** `false` marks a provider that needs no key: no env lookup and no auth header from the package. */
|
|
9
|
+
export type ApiKey = string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>> | false;
|
|
8
10
|
export type OptionalApiKeyAuth = {
|
|
9
|
-
readonly apiKey?:
|
|
11
|
+
readonly apiKey?: ApiKey;
|
|
10
12
|
readonly auth?: never;
|
|
11
13
|
};
|
|
12
14
|
export type RequiredApiKeyAuth = {
|
|
13
|
-
readonly apiKey:
|
|
15
|
+
readonly apiKey: ApiKey;
|
|
14
16
|
readonly auth?: never;
|
|
15
17
|
};
|
|
16
18
|
export type ProviderAuthOption<Mode extends ApiKeyMode> = AuthOverride | (Mode extends "optional" ? OptionalApiKeyAuth : RequiredApiKeyAuth);
|
|
@@ -23,9 +25,11 @@ export type AtLeastOne<T> = {
|
|
|
23
25
|
[K in keyof T]: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
24
26
|
}[keyof T];
|
|
25
27
|
/**
|
|
26
|
-
* Standard
|
|
27
|
-
* override,
|
|
28
|
-
*
|
|
28
|
+
* Standard API-key resolution for providers: honor an explicit `auth`
|
|
29
|
+
* override, skip auth entirely for `apiKey: false`, otherwise resolve `apiKey`
|
|
30
|
+
* (option > config vars) and render it with `apply`.
|
|
29
31
|
*/
|
|
32
|
+
export declare const apiKey: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>, apply: (credential: Auth.Credential) => Auth.Definition) => Auth.Definition;
|
|
33
|
+
/** `apiKey` resolution applied as `Authorization: Bearer <key>`. */
|
|
30
34
|
export declare const bearer: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>) => Auth.Definition;
|
|
31
35
|
export * as AuthOptions from "./auth-options.js";
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { Auth } from "./auth.js";
|
|
2
2
|
/**
|
|
3
|
-
* Standard
|
|
4
|
-
* override,
|
|
5
|
-
*
|
|
3
|
+
* Standard API-key resolution for providers: honor an explicit `auth`
|
|
4
|
+
* override, skip auth entirely for `apiKey: false`, otherwise resolve `apiKey`
|
|
5
|
+
* (option > config vars) and render it with `apply`.
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
7
|
+
export const apiKey = (options, envVar, apply) => {
|
|
8
8
|
if ("auth" in options && options.auth)
|
|
9
9
|
return options.auth;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
10
|
+
const key = "apiKey" in options ? options.apiKey : undefined;
|
|
11
|
+
if (key === false)
|
|
12
|
+
return Auth.none;
|
|
13
|
+
return apply((Array.isArray(envVar) ? envVar : [envVar]).reduce((auth, name) => auth.orElse(Auth.config(name)), Auth.optional(key, "apiKey")));
|
|
13
14
|
};
|
|
15
|
+
/** `apiKey` resolution applied as `Authorization: Bearer <key>`. */
|
|
16
|
+
export const bearer = (options, envVar) => apiKey(options, envVar, (credential) => credential.bearer());
|
|
14
17
|
export * as AuthOptions from "./auth-options.js";
|
package/dist/route/client.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { HttpTransport } from "./transport/index.js";
|
|
|
7
7
|
import type { HttpMiddleware, Transport, TransportRuntime, WebSocketChannelExecutor } from "./transport/index.js";
|
|
8
8
|
import type { Protocol } from "./protocol.js";
|
|
9
9
|
import type { LanguageModelSanitizerCompatibility, ProtocolID, ProviderOptions } from "../schema/index.js";
|
|
10
|
-
import {
|
|
10
|
+
import type { LLMRequestInput } from "../llm.js";
|
|
11
|
+
import { AIError, CompactionResponse, CompactionCheckpointResponse, LLMResponse, LanguageModel, LLMEvent, ProviderID, type LLMRequest, type RequestOptions } from "../schema/index.js";
|
|
11
12
|
export interface RouteBody<Body> {
|
|
12
13
|
/** Schema for the validated provider-native body sent as the JSON request. */
|
|
13
14
|
readonly schema: Schema.Codec<Body, unknown>;
|
|
@@ -28,7 +29,8 @@ export interface Route<Body, Prepared = unknown, Compact extends CompactionOpera
|
|
|
28
29
|
readonly request: LLMRequest;
|
|
29
30
|
}) => Record<string, string>;
|
|
30
31
|
readonly transport: Transport<Body, Prepared, unknown>;
|
|
31
|
-
|
|
32
|
+
/** Options every model built on this route starts from. */
|
|
33
|
+
readonly options?: RequestOptions;
|
|
32
34
|
readonly body: RouteBody<Body>;
|
|
33
35
|
readonly supportsEffortUpdates?: (request: LLMRequest) => boolean;
|
|
34
36
|
readonly sanitizer?: LanguageModelSanitizerCompatibility;
|
|
@@ -48,19 +50,7 @@ export interface Route<Body, Prepared = unknown, Compact extends CompactionOpera
|
|
|
48
50
|
export type AnyRoute<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Route<any, any, Compact>;
|
|
49
51
|
export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "route">;
|
|
50
52
|
export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">;
|
|
51
|
-
export interface
|
|
52
|
-
readonly headers?: Record<string, string>;
|
|
53
|
-
readonly generation?: GenerationOptions;
|
|
54
|
-
readonly providerOptions?: ProviderOptions;
|
|
55
|
-
readonly http?: HttpOptions;
|
|
56
|
-
}
|
|
57
|
-
export interface RouteDefaultsInput {
|
|
58
|
-
readonly headers?: Record<string, string>;
|
|
59
|
-
readonly generation?: GenerationOptions.Input;
|
|
60
|
-
readonly providerOptions?: ProviderOptions;
|
|
61
|
-
readonly http?: HttpOptions.Input;
|
|
62
|
-
}
|
|
63
|
-
export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
|
|
53
|
+
export interface RoutePatch<Body, Prepared> extends RequestOptions {
|
|
64
54
|
readonly compact?: CompactionOperations;
|
|
65
55
|
readonly id?: string;
|
|
66
56
|
readonly provider?: string | ProviderID;
|
|
@@ -99,26 +89,49 @@ export interface EndpointCompactOptions extends Pick<StreamOptions, "http"> {
|
|
|
99
89
|
export interface TriggerCompactOptions extends StreamOptions {
|
|
100
90
|
readonly mechanism: "trigger";
|
|
101
91
|
}
|
|
102
|
-
|
|
103
|
-
readonly
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
type EndpointModel = LanguageModel<ProviderOptions, {
|
|
93
|
+
readonly endpoint: CompactOperation;
|
|
94
|
+
}>;
|
|
95
|
+
type TriggerModel = LanguageModel<ProviderOptions, {
|
|
96
|
+
readonly trigger: TriggerCompactOperation;
|
|
97
|
+
}>;
|
|
98
|
+
/** A text request whose model supports explicit compaction. */
|
|
99
|
+
export type CompactionRequest = LLMRequestInput & {
|
|
100
|
+
readonly model: EndpointModel;
|
|
106
101
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}>;
|
|
102
|
+
/** A text request whose model supports trigger compaction checkpoints. */
|
|
103
|
+
export type CheckpointRequest = LLMRequestInput & {
|
|
104
|
+
readonly model: TriggerModel;
|
|
111
105
|
};
|
|
112
106
|
export interface CompactMethod<R = never> {
|
|
113
|
-
(request:
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}):
|
|
119
|
-
|
|
107
|
+
(request: LLMRequest & {
|
|
108
|
+
readonly model: TriggerModel;
|
|
109
|
+
}, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, R>;
|
|
110
|
+
(request: LLMRequest & {
|
|
111
|
+
readonly model: EndpointModel;
|
|
112
|
+
}, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, R>;
|
|
113
|
+
}
|
|
114
|
+
/** Whether a model, or a text request's model, supports compaction through the given mechanism. */
|
|
115
|
+
export declare function canCompact<Model extends LanguageModel>(model: Model, options: {
|
|
116
|
+
readonly mechanism: "trigger";
|
|
117
|
+
}): model is Model & TriggerModel;
|
|
118
|
+
export declare function canCompact<Request extends {
|
|
119
|
+
readonly model: LanguageModel;
|
|
120
|
+
}>(request: Request, options: {
|
|
120
121
|
readonly mechanism: "trigger";
|
|
121
|
-
}): request is
|
|
122
|
+
}): request is Request & {
|
|
123
|
+
readonly model: TriggerModel;
|
|
124
|
+
};
|
|
125
|
+
export declare function canCompact<Model extends LanguageModel>(model: Model, options?: {
|
|
126
|
+
readonly mechanism?: "endpoint";
|
|
127
|
+
}): model is Model & EndpointModel;
|
|
128
|
+
export declare function canCompact<Request extends {
|
|
129
|
+
readonly model: LanguageModel;
|
|
130
|
+
}>(request: Request, options?: {
|
|
131
|
+
readonly mechanism?: "endpoint";
|
|
132
|
+
}): request is Request & {
|
|
133
|
+
readonly model: EndpointModel;
|
|
134
|
+
};
|
|
122
135
|
declare const LLMClientService_base: Context.ServiceClass<LLMClientService, "@opencode/LLMClient", Interface>;
|
|
123
136
|
export declare class LLMClientService extends LLMClientService_base {
|
|
124
137
|
}
|
|
@@ -144,8 +157,8 @@ export interface MakeInput<Body, Frame, Event, State> {
|
|
|
144
157
|
readonly headers?: (input: {
|
|
145
158
|
readonly request: LLMRequest;
|
|
146
159
|
}) => Record<string, string>;
|
|
147
|
-
/**
|
|
148
|
-
readonly
|
|
160
|
+
/** Options every model built on this route starts from. */
|
|
161
|
+
readonly options?: RequestOptions;
|
|
149
162
|
}
|
|
150
163
|
export interface MakeTransportInput<Body, Prepared, Frame, Event, State> {
|
|
151
164
|
readonly compact?: CompactionOperations;
|
|
@@ -167,8 +180,8 @@ export interface MakeTransportInput<Body, Prepared, Frame, Event, State> {
|
|
|
167
180
|
}) => Record<string, string>;
|
|
168
181
|
/** Runnable transport route. */
|
|
169
182
|
readonly transport: Transport<Body, Prepared, Frame>;
|
|
170
|
-
/**
|
|
171
|
-
readonly
|
|
183
|
+
/** Options every model built on this route starts from. */
|
|
184
|
+
readonly options?: RequestOptions;
|
|
172
185
|
}
|
|
173
186
|
export declare function make<Body, Prepared, Frame, Event, State, Compact extends CompactionOperations>(input: MakeTransportInput<Body, Prepared, Frame, Event, State> & {
|
|
174
187
|
readonly compact: Compact;
|
|
@@ -213,8 +226,8 @@ export declare const generateWith: (stream: Interface["stream"]) => (request: LL
|
|
|
213
226
|
}, CompactionOperations | undefined>>, options?: StreamOptions | undefined) => Effect.Effect<LLMResponse, AIError, never>;
|
|
214
227
|
export declare function stream(request: LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
|
|
215
228
|
export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
|
|
216
|
-
|
|
217
|
-
export declare function
|
|
229
|
+
/** Compact through the client for `options.mechanism`, failing typed when the request's route does not support it. */
|
|
230
|
+
export declare function compactRequest(request: LLMRequest, options?: EndpointCompactOptions | TriggerCompactOptions): Effect.Effect<CompactionResponse | CompactionCheckpointResponse, AIError, Service>;
|
|
218
231
|
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
219
232
|
export declare const Route: {
|
|
220
233
|
readonly make: typeof make;
|