@opencode/ai 0.0.0-dev-491 → 0.0.0-dev-519
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/dist/llm.d.ts +0 -1
- package/dist/llm.js +0 -1
- package/dist/protocols/anthropic-messages.js +35 -89
- package/dist/protocols/bedrock-converse.js +2 -3
- package/dist/protocols/cohere-chat.js +0 -3
- package/dist/protocols/gemini.js +26 -40
- 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/shared.d.ts +0 -3
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/providers/baseten.d.ts +1 -1
- package/dist/providers/baseten.js +5 -11
- package/dist/providers/cerebras.d.ts +1 -1
- package/dist/providers/cerebras.js +2 -8
- package/dist/providers/cloudflare-ai-gateway.js +5 -25
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere.d.ts +1 -1
- package/dist/providers/cohere.js +4 -6
- package/dist/providers/deepinfra.d.ts +1 -1
- package/dist/providers/deepinfra.js +3 -6
- package/dist/providers/deepseek.d.ts +1 -1
- package/dist/providers/deepseek.js +2 -8
- package/dist/providers/digitalocean.d.ts +1 -1
- package/dist/providers/digitalocean.js +5 -7
- package/dist/providers/fireworks.d.ts +1 -1
- package/dist/providers/fireworks.js +2 -8
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.js +3 -29
- package/dist/providers/google-vertex-shared.d.ts +30 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/groq.d.ts +1 -1
- package/dist/providers/groq.js +2 -8
- package/dist/providers/meta.d.ts +1 -1
- package/dist/providers/meta.js +2 -8
- package/dist/providers/minimax.d.ts +1 -1
- package/dist/providers/minimax.js +3 -10
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -8
- package/dist/providers/moonshot.d.ts +1 -1
- package/dist/providers/moonshot.js +2 -8
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +5 -8
- package/dist/providers/settings.d.ts +21 -0
- package/dist/providers/settings.js +10 -0
- package/dist/providers/togetherai.d.ts +1 -1
- package/dist/providers/togetherai.js +2 -8
- package/dist/providers/vercel-ai-gateway.d.ts +1 -1
- package/dist/providers/vercel-ai-gateway.js +2 -8
- package/dist/providers/zai-coding-plan.d.ts +1 -1
- package/dist/providers/zai-coding-plan.js +2 -8
- package/dist/providers/zai.d.ts +1 -1
- package/dist/providers/zai.js +4 -12
- package/dist/schema/events.js +31 -64
- package/dist/schema/messages.d.ts +0 -16
- package/dist/schema/messages.js +0 -7
- package/dist/tool-history.js +0 -1
- package/package.json +3 -3
|
@@ -4,14 +4,13 @@ import { MiniMaxImages } from "../protocols/minimax-images.js";
|
|
|
4
4
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
5
5
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
6
6
|
import { ProviderShared } from "../protocols/shared.js";
|
|
7
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
8
7
|
import { Route } from "../route/client.js";
|
|
9
8
|
import { Endpoint } from "../route/endpoint.js";
|
|
10
9
|
import { Framing } from "../route/framing.js";
|
|
11
10
|
import { MediaRoute } from "../route/media.js";
|
|
12
11
|
import { Protocol } from "../route/protocol.js";
|
|
13
12
|
import { ProviderID } from "../schema/index.js";
|
|
14
|
-
import { toConfig } from "./settings.js";
|
|
13
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
15
14
|
export const id = ProviderID.make("minimax");
|
|
16
15
|
const ChatOptions = Schema.Struct({
|
|
17
16
|
thinking: Schema.optional(Schema.Struct({ type: Schema.String })),
|
|
@@ -64,13 +63,7 @@ const responsesRoute = Route.make({
|
|
|
64
63
|
});
|
|
65
64
|
export const routes = [messagesRoute, chatRoute, responsesRoute];
|
|
66
65
|
export const configure = (input = {}) => {
|
|
67
|
-
const
|
|
68
|
-
const auth = AuthOptions.bearer(input, "MINIMAX_API_KEY");
|
|
69
|
-
const defaults = {
|
|
70
|
-
...rest,
|
|
71
|
-
endpoint: baseURL === undefined ? undefined : { baseURL },
|
|
72
|
-
auth,
|
|
73
|
-
};
|
|
66
|
+
const defaults = bearerRouteDefaults(input, "MINIMAX_API_KEY");
|
|
74
67
|
const messages = (modelID) => messagesRoute.with(defaults).model({
|
|
75
68
|
id: modelID,
|
|
76
69
|
compatibility: { requireSignature: false },
|
|
@@ -80,7 +73,7 @@ export const configure = (input = {}) => {
|
|
|
80
73
|
compatibility: { supportsStrictMode: false },
|
|
81
74
|
});
|
|
82
75
|
const responses = (modelID) => responsesRoute.with(defaults).model({ id: modelID });
|
|
83
|
-
const media = MediaRoute.deployment(input, auth);
|
|
76
|
+
const media = MediaRoute.deployment(input, defaults.auth);
|
|
84
77
|
const image = (modelID, providerOptions) => MiniMaxImages.model({ ...media, id: modelID, providerOptions });
|
|
85
78
|
return { id, model: messages, messages, chat, responses, image, configure };
|
|
86
79
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { MistralChat } from "../protocols/mistral-chat.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
import type { RouteDefaultsInput } from "../route/client.js";
|
|
5
5
|
import { type ModelID } from "../schema/index.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { MistralChat } from "../protocols/mistral-chat.js";
|
|
2
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
3
2
|
import { ProviderID } from "../schema/index.js";
|
|
4
|
-
import { toConfig } from "./settings.js";
|
|
3
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
5
4
|
export const id = ProviderID.make("mistral");
|
|
6
5
|
export const route = MistralChat.route;
|
|
7
6
|
export const routes = [route];
|
|
8
7
|
export const configure = (input = {}) => {
|
|
9
|
-
const
|
|
10
|
-
const configured = route.with({
|
|
11
|
-
...defaults,
|
|
12
|
-
endpoint: { baseURL: baseURL ?? MistralChat.DEFAULT_BASE_URL },
|
|
13
|
-
auth: AuthOptions.bearer(input, "MISTRAL_API_KEY"),
|
|
14
|
-
});
|
|
8
|
+
const configured = route.with(bearerRouteDefaults(input, "MISTRAL_API_KEY", MistralChat.DEFAULT_BASE_URL));
|
|
15
9
|
return {
|
|
16
10
|
id,
|
|
17
11
|
model: (modelID) => configured.model({ id: modelID }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
5
5
|
import { type ModelID } from "../schema/index.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -3,13 +3,12 @@ import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
|
3
3
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
4
4
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
5
5
|
import { ProviderShared } from "../protocols/shared.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 { Protocol } from "../route/protocol.js";
|
|
11
10
|
import { ProviderID } from "../schema/index.js";
|
|
12
|
-
import { toConfig } from "./settings.js";
|
|
11
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
13
12
|
export const id = ProviderID.make("moonshotai");
|
|
14
13
|
const ChatOptions = Schema.Struct({
|
|
15
14
|
reasoningEffort: Schema.optional(Schema.String),
|
|
@@ -52,12 +51,7 @@ const responsesRoute = Route.make({
|
|
|
52
51
|
});
|
|
53
52
|
export const routes = [chatRoute, messagesRoute, responsesRoute];
|
|
54
53
|
export const configure = (input = {}) => {
|
|
55
|
-
const
|
|
56
|
-
const defaults = {
|
|
57
|
-
...rest,
|
|
58
|
-
endpoint: baseURL === undefined ? undefined : { baseURL },
|
|
59
|
-
auth: AuthOptions.bearer(input, ["MOONSHOT_API_KEY", "MOONSHOTAI_API_KEY"]),
|
|
60
|
-
};
|
|
54
|
+
const defaults = bearerRouteDefaults(input, ["MOONSHOT_API_KEY", "MOONSHOTAI_API_KEY"]);
|
|
61
55
|
const chat = (modelID) => chatRoute.with(defaults).model({
|
|
62
56
|
id: modelID,
|
|
63
57
|
compatibility: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
5
5
|
import { type ModelID, type OpenString, type ProviderOptions } from "../schema/index.js";
|
|
6
6
|
import type { ProviderPackage } from "../provider-package.js";
|
|
7
7
|
import { HttpTransport } from "../route/transport/index.js";
|
|
@@ -2,7 +2,6 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { Route } from "../route/client.js";
|
|
3
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
4
4
|
import { Protocol } from "../route/protocol.js";
|
|
5
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
6
5
|
import { ProviderID } from "../schema/index.js";
|
|
7
6
|
import { SystemOne } from "../protocols/system-one.js";
|
|
8
7
|
import { OpenAIImages } from "../protocols/openai-images.js";
|
|
@@ -12,7 +11,7 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
|
12
11
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
13
12
|
import { cacheControl } from "../protocols/utils/cache.js";
|
|
14
13
|
import { isRecord, JsonObject, lenient, ProviderShared } from "../protocols/shared.js";
|
|
15
|
-
import { toConfig } from "./settings.js";
|
|
14
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
16
15
|
export const id = ProviderID.make("openrouter");
|
|
17
16
|
const baseURL = "https://openrouter.ai/api/v1";
|
|
18
17
|
const ADAPTER = "openrouter";
|
|
@@ -135,20 +134,18 @@ const responsesRoute = Route.make({
|
|
|
135
134
|
});
|
|
136
135
|
export const routes = [route, responsesRoute];
|
|
137
136
|
export const configure = (input = {}) => {
|
|
138
|
-
const
|
|
139
|
-
const auth = AuthOptions.bearer(input, "OPENROUTER_API_KEY");
|
|
140
|
-
const options = { ...defaults, endpoint: { baseURL: endpoint ?? baseURL }, auth };
|
|
137
|
+
const options = bearerRouteDefaults(input, "OPENROUTER_API_KEY", baseURL);
|
|
141
138
|
const chatRoute = route.with(options);
|
|
142
139
|
const configuredResponses = responsesRoute.with(options);
|
|
143
140
|
const decisionRoute = SystemOne.route.with({
|
|
144
141
|
provider: id,
|
|
145
142
|
providerMetadataKey: "openrouter",
|
|
146
|
-
endpoint:
|
|
147
|
-
auth,
|
|
143
|
+
endpoint: options.endpoint,
|
|
144
|
+
auth: options.auth,
|
|
148
145
|
headers: input.headers,
|
|
149
146
|
http: input.http,
|
|
150
147
|
});
|
|
151
|
-
const media = MediaRoute.deployment({ ...input, baseURL:
|
|
148
|
+
const media = MediaRoute.deployment({ ...input, baseURL: options.endpoint.baseURL }, options.auth);
|
|
152
149
|
const image = (modelID, providerOptions) => OpenAIImages.model({
|
|
153
150
|
...media,
|
|
154
151
|
id: modelID,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import type { Auth } from "../route/auth.js";
|
|
2
4
|
type Connection = "apiKey" | "baseURL" | "body" | "headers";
|
|
3
5
|
/**
|
|
4
6
|
* Splits flat provider settings into connection config, treating every other key as a provider option.
|
|
@@ -16,4 +18,23 @@ export declare function toConfig<Settings extends ProviderPackage.Settings>(sett
|
|
|
16
18
|
[Key in keyof Settings as Key extends Connection ? never : Key]: Settings[Key];
|
|
17
19
|
};
|
|
18
20
|
};
|
|
21
|
+
type BearerInput = ProviderAuthOption<"optional"> & {
|
|
22
|
+
readonly baseURL?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Turns provider config into route defaults with `Authorization: Bearer` auth. The endpoint falls back to
|
|
26
|
+
* `baseURL` when given, otherwise it is left to the route.
|
|
27
|
+
*/
|
|
28
|
+
export declare function bearerRouteDefaults<Input extends BearerInput>(input: Input, envVar: string | ReadonlyArray<string>, baseURL: string): Omit<Input, "apiKey" | "auth" | "baseURL"> & {
|
|
29
|
+
endpoint: {
|
|
30
|
+
baseURL: string;
|
|
31
|
+
};
|
|
32
|
+
auth: Auth.Definition;
|
|
33
|
+
};
|
|
34
|
+
export declare function bearerRouteDefaults<Input extends BearerInput>(input: Input, envVar: string | ReadonlyArray<string>): Omit<Input, "apiKey" | "auth" | "baseURL"> & {
|
|
35
|
+
endpoint: {
|
|
36
|
+
baseURL: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
auth: Auth.Definition;
|
|
39
|
+
};
|
|
19
40
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
1
2
|
export function toConfig({ apiKey, baseURL, body, headers, ...providerOptions } = {}) {
|
|
2
3
|
return {
|
|
3
4
|
apiKey,
|
|
@@ -7,3 +8,12 @@ export function toConfig({ apiKey, baseURL, body, headers, ...providerOptions }
|
|
|
7
8
|
providerOptions,
|
|
8
9
|
};
|
|
9
10
|
}
|
|
11
|
+
export function bearerRouteDefaults(input, envVar, baseURL) {
|
|
12
|
+
const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
|
|
13
|
+
const resolved = endpoint ?? baseURL;
|
|
14
|
+
return {
|
|
15
|
+
...defaults,
|
|
16
|
+
endpoint: resolved === undefined ? undefined : { baseURL: resolved },
|
|
17
|
+
auth: AuthOptions.bearer(input, envVar),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
3
3
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
4
4
|
import { type ModelID } from "../schema/index.js";
|
|
5
5
|
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
2
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
3
2
|
import { Route } from "../route/client.js";
|
|
4
3
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
4
|
import { ProviderID } from "../schema/index.js";
|
|
6
|
-
import { toConfig } from "./settings.js";
|
|
5
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
7
6
|
export const id = ProviderID.make("togetherai");
|
|
8
7
|
const baseURL = "https://api.together.xyz/v1";
|
|
9
8
|
export const route = Route.make({
|
|
@@ -16,12 +15,7 @@ export const route = Route.make({
|
|
|
16
15
|
});
|
|
17
16
|
export const routes = [route];
|
|
18
17
|
export const configure = (input = {}) => {
|
|
19
|
-
const
|
|
20
|
-
const configured = route.with({
|
|
21
|
-
...defaults,
|
|
22
|
-
endpoint: { baseURL: endpoint ?? baseURL },
|
|
23
|
-
auth: AuthOptions.bearer(input, ["TOGETHER_API_KEY", "TOGETHER_AI_API_KEY"]),
|
|
24
|
-
});
|
|
18
|
+
const configured = route.with(bearerRouteDefaults(input, ["TOGETHER_API_KEY", "TOGETHER_AI_API_KEY"], baseURL));
|
|
25
19
|
return {
|
|
26
20
|
id,
|
|
27
21
|
model: (modelID) => configured.model({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
2
2
|
import type { ProviderPackage } from "../provider-package.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
5
5
|
import { ModelID, type ProviderOptions } from "../schema/index.js";
|
|
6
6
|
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js";
|
|
@@ -7,13 +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
14
|
import { ModelID, ProviderID, ProviderMetadata, ReasoningEffort, } from "../schema/index.js";
|
|
16
|
-
import { toConfig } from "./settings.js";
|
|
15
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
17
16
|
export const id = ProviderID.make("vercel-ai-gateway");
|
|
18
17
|
const baseURL = "https://ai-gateway.vercel.sh/v1";
|
|
19
18
|
const GatewayOptionsSchema = Schema.Struct({
|
|
@@ -119,12 +118,7 @@ const imageSizing = (request) => {
|
|
|
119
118
|
return { providerOptions: { xai: { aspect_ratio: request.aspect, resolution: XAIImages.resolution(request) } } };
|
|
120
119
|
};
|
|
121
120
|
export const configure = (input = {}) => {
|
|
122
|
-
const
|
|
123
|
-
const configured = {
|
|
124
|
-
...defaults,
|
|
125
|
-
endpoint: { baseURL: endpoint ?? baseURL },
|
|
126
|
-
auth: AuthOptions.bearer(input, ["AI_GATEWAY_API_KEY", "VERCEL_OIDC_TOKEN"]),
|
|
127
|
-
};
|
|
121
|
+
const configured = bearerRouteDefaults(input, ["AI_GATEWAY_API_KEY", "VERCEL_OIDC_TOKEN"], baseURL);
|
|
128
122
|
const messages = (modelID) => messagesRoute.with(configured).model({
|
|
129
123
|
id: modelID,
|
|
130
124
|
// Recorded Gateway translations for non-Claude models return thinking with empty signatures.
|
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
4
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
5
5
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
6
6
|
import { type ModelID } from "../schema/index.js";
|
|
7
7
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -3,12 +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";
|
|
11
|
-
import { toConfig } from "./settings.js";
|
|
10
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
12
11
|
export const id = ProviderID.make("zai-coding-plan");
|
|
13
12
|
const chatRoute = Route.make({
|
|
14
13
|
id: "zai-coding-chat",
|
|
@@ -37,12 +36,7 @@ const responsesRoute = Route.make({
|
|
|
37
36
|
});
|
|
38
37
|
export const routes = [chatRoute, messagesRoute, responsesRoute];
|
|
39
38
|
export const configure = (input = {}) => {
|
|
40
|
-
const
|
|
41
|
-
const defaults = {
|
|
42
|
-
...rest,
|
|
43
|
-
endpoint: baseURL === undefined ? undefined : { baseURL },
|
|
44
|
-
auth: AuthOptions.bearer(input, "ZAI_API_KEY"),
|
|
45
|
-
};
|
|
39
|
+
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY");
|
|
46
40
|
const chat = (modelID) => chatRoute.with(defaults).model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
47
41
|
const messages = (modelID) => messagesRoute
|
|
48
42
|
.with(defaults)
|
package/dist/providers/zai.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProviderPackage } from "../provider-package.js";
|
|
2
2
|
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
5
5
|
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
package/dist/providers/zai.js
CHANGED
|
@@ -1,14 +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";
|
|
9
|
-
import { toConfig } from "./settings.js";
|
|
8
|
+
import { bearerRouteDefaults, toConfig } from "./settings.js";
|
|
10
9
|
export const id = ProviderID.make("zai");
|
|
11
|
-
const auth = (options) => AuthOptions.bearer(options, "ZAI_API_KEY");
|
|
12
10
|
const chatRoute = Route.make({
|
|
13
11
|
id: "zai-chat",
|
|
14
12
|
provider: id,
|
|
@@ -19,15 +17,9 @@ const chatRoute = Route.make({
|
|
|
19
17
|
});
|
|
20
18
|
export const routes = [chatRoute];
|
|
21
19
|
export const configure = (input = {}) => {
|
|
22
|
-
const
|
|
23
|
-
const chat = (modelID) => chatRoute
|
|
24
|
-
|
|
25
|
-
...rest,
|
|
26
|
-
endpoint: baseURL === undefined ? undefined : { baseURL },
|
|
27
|
-
auth: auth(input),
|
|
28
|
-
})
|
|
29
|
-
.model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
30
|
-
const media = MediaRoute.deployment(input, auth(input));
|
|
20
|
+
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY");
|
|
21
|
+
const chat = (modelID) => chatRoute.with(defaults).model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
22
|
+
const media = MediaRoute.deployment(input, defaults.auth);
|
|
31
23
|
const image = (modelID, providerOptions) => ZAIImages.model({ ...media, id: modelID, providerOptions });
|
|
32
24
|
return {
|
|
33
25
|
id,
|
package/dist/schema/events.js
CHANGED
|
@@ -363,81 +363,48 @@ const appendEvent = (state, event) => {
|
|
|
363
363
|
usage: "usage" in event && event.usage !== undefined ? event.usage : state.usage,
|
|
364
364
|
};
|
|
365
365
|
};
|
|
366
|
-
const
|
|
367
|
-
const reasoningContent = (text, providerMetadata) => providerMetadata === undefined ? { type: "reasoning", text } : { type: "reasoning", text, providerMetadata };
|
|
366
|
+
const contentPart = (type, text, providerMetadata) => providerMetadata === undefined ? { type, text } : { type, text, providerMetadata };
|
|
368
367
|
const contentWith = (state, content) => ({
|
|
369
368
|
...state,
|
|
370
369
|
message: Message.assistant(content),
|
|
371
370
|
});
|
|
372
371
|
const appendContent = (state, part) => contentWith(state, [...state.message.content, part]);
|
|
373
372
|
const replaceContent = (state, index, part) => contentWith(state, state.message.content.map((item, itemIndex) => (itemIndex === index ? part : item)));
|
|
374
|
-
const
|
|
375
|
-
|
|
373
|
+
const contentParts = (state, type) => type === "text" ? state.textParts : state.reasoningParts;
|
|
374
|
+
const withContentParts = (state, type, parts) => (type === "text" ? { ...state, textParts: parts } : { ...state, reasoningParts: parts });
|
|
375
|
+
const ensureContent = (state, type, id, providerMetadata) => {
|
|
376
|
+
const parts = contentParts(state, type);
|
|
377
|
+
if (parts[id])
|
|
376
378
|
return state;
|
|
377
|
-
return {
|
|
378
|
-
...
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
[id]: { contentIndex: state.message.content.length, text: "", providerMetadata },
|
|
382
|
-
},
|
|
383
|
-
};
|
|
384
|
-
};
|
|
385
|
-
const reduceTextDelta = (state, event) => {
|
|
386
|
-
const started = ensureText(state, event.id, event.providerMetadata);
|
|
387
|
-
const current = started.textParts[event.id];
|
|
388
|
-
if (!current)
|
|
389
|
-
return started;
|
|
390
|
-
const text = current.text + event.text;
|
|
391
|
-
const providerMetadata = event.providerMetadata ?? current.providerMetadata;
|
|
392
|
-
return {
|
|
393
|
-
...replaceContent(started, current.contentIndex, textContent(text, providerMetadata)),
|
|
394
|
-
textParts: { ...started.textParts, [event.id]: { ...current, text, providerMetadata } },
|
|
395
|
-
};
|
|
396
|
-
};
|
|
397
|
-
const reduceTextEnd = (state, event) => {
|
|
398
|
-
const current = state.textParts[event.id];
|
|
399
|
-
if (!current)
|
|
400
|
-
return state;
|
|
401
|
-
const text = event.text ?? current.text;
|
|
402
|
-
const providerMetadata = event.providerMetadata ?? current.providerMetadata;
|
|
403
|
-
return {
|
|
404
|
-
...replaceContent(state, current.contentIndex, textContent(text, providerMetadata)),
|
|
405
|
-
textParts: { ...state.textParts, [event.id]: { ...current, text, providerMetadata } },
|
|
406
|
-
};
|
|
379
|
+
return withContentParts(appendContent(state, contentPart(type, "", providerMetadata)), type, {
|
|
380
|
+
...parts,
|
|
381
|
+
[id]: { contentIndex: state.message.content.length, text: "", providerMetadata },
|
|
382
|
+
});
|
|
407
383
|
};
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
...appendContent(state, reasoningContent("", providerMetadata)),
|
|
413
|
-
reasoningParts: {
|
|
414
|
-
...state.reasoningParts,
|
|
415
|
-
[id]: { contentIndex: state.message.content.length, text: "", providerMetadata },
|
|
416
|
-
},
|
|
417
|
-
};
|
|
418
|
-
};
|
|
419
|
-
const reduceReasoningDelta = (state, event) => {
|
|
420
|
-
const started = ensureReasoning(state, event.id, event.providerMetadata);
|
|
421
|
-
const current = started.reasoningParts[event.id];
|
|
384
|
+
const reduceContentDelta = (state, type, event) => {
|
|
385
|
+
const started = ensureContent(state, type, event.id, event.providerMetadata);
|
|
386
|
+
const parts = contentParts(started, type);
|
|
387
|
+
const current = parts[event.id];
|
|
422
388
|
if (!current)
|
|
423
389
|
return started;
|
|
424
390
|
const text = current.text + event.text;
|
|
425
391
|
const providerMetadata = event.providerMetadata ?? current.providerMetadata;
|
|
426
|
-
return {
|
|
427
|
-
...
|
|
428
|
-
|
|
429
|
-
};
|
|
392
|
+
return withContentParts(replaceContent(started, current.contentIndex, contentPart(type, text, providerMetadata)), type, {
|
|
393
|
+
...parts,
|
|
394
|
+
[event.id]: { ...current, text, providerMetadata },
|
|
395
|
+
});
|
|
430
396
|
};
|
|
431
|
-
const
|
|
432
|
-
const
|
|
397
|
+
const reduceContentEnd = (state, type, event) => {
|
|
398
|
+
const parts = contentParts(state, type);
|
|
399
|
+
const current = parts[event.id];
|
|
433
400
|
if (!current)
|
|
434
401
|
return state;
|
|
435
402
|
const text = event.text ?? current.text;
|
|
436
403
|
const providerMetadata = event.providerMetadata ?? current.providerMetadata;
|
|
437
|
-
return {
|
|
438
|
-
...
|
|
439
|
-
|
|
440
|
-
};
|
|
404
|
+
return withContentParts(replaceContent(state, current.contentIndex, contentPart(type, text, providerMetadata)), type, {
|
|
405
|
+
...parts,
|
|
406
|
+
[event.id]: { ...current, text, providerMetadata },
|
|
407
|
+
});
|
|
441
408
|
};
|
|
442
409
|
const reduceToolInputStart = (state, event) => ({
|
|
443
410
|
...state,
|
|
@@ -501,17 +468,17 @@ const reduceResponseState = (state, event) => {
|
|
|
501
468
|
case "compaction":
|
|
502
469
|
return appendContent(next, event);
|
|
503
470
|
case "text-start":
|
|
504
|
-
return
|
|
471
|
+
return ensureContent(next, "text", event.id, event.providerMetadata);
|
|
505
472
|
case "text-delta":
|
|
506
|
-
return
|
|
473
|
+
return reduceContentDelta(next, "text", event);
|
|
507
474
|
case "text-end":
|
|
508
|
-
return
|
|
475
|
+
return reduceContentEnd(next, "text", event);
|
|
509
476
|
case "reasoning-start":
|
|
510
|
-
return
|
|
477
|
+
return ensureContent(next, "reasoning", event.id, event.providerMetadata);
|
|
511
478
|
case "reasoning-delta":
|
|
512
|
-
return
|
|
479
|
+
return reduceContentDelta(next, "reasoning", event);
|
|
513
480
|
case "reasoning-end":
|
|
514
|
-
return
|
|
481
|
+
return reduceContentEnd(next, "reasoning", event);
|
|
515
482
|
case "tool-input-start":
|
|
516
483
|
return reduceToolInputStart(next, event);
|
|
517
484
|
case "tool-input-delta":
|
|
@@ -25,7 +25,6 @@ export declare const TextPart: Schema.Struct<{
|
|
|
25
25
|
readonly type: Schema.Literal<"text">;
|
|
26
26
|
readonly text: Schema.String;
|
|
27
27
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
28
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
29
28
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
30
29
|
}>;
|
|
31
30
|
export type TextPart = Schema.Schema.Type<typeof TextPart>;
|
|
@@ -162,7 +161,6 @@ export declare const ToolCallPart: Schema.Struct<{
|
|
|
162
161
|
readonly input: Schema.Unknown;
|
|
163
162
|
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
164
163
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
165
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
166
164
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
167
165
|
}> & {
|
|
168
166
|
make: (input: Omit<ToolCallPart, "type">) => ToolCallPart;
|
|
@@ -219,7 +217,6 @@ export declare const ToolResultPart: Schema.Struct<{
|
|
|
219
217
|
};
|
|
220
218
|
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
221
219
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
222
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
223
220
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
224
221
|
}> & {
|
|
225
222
|
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
@@ -233,7 +230,6 @@ export declare const ReasoningPart: Schema.Struct<{
|
|
|
233
230
|
readonly text: Schema.String;
|
|
234
231
|
readonly encrypted: Schema.optional<Schema.String>;
|
|
235
232
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
236
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
237
233
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
238
234
|
}>;
|
|
239
235
|
export type ReasoningPart = Schema.Schema.Type<typeof ReasoningPart>;
|
|
@@ -287,7 +283,6 @@ export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.
|
|
|
287
283
|
readonly type: Schema.Literal<"text">;
|
|
288
284
|
readonly text: Schema.String;
|
|
289
285
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
290
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
291
286
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
292
287
|
}>, Schema.Struct<{
|
|
293
288
|
readonly type: Schema.Literal<"media">;
|
|
@@ -334,7 +329,6 @@ export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.
|
|
|
334
329
|
readonly input: Schema.Unknown;
|
|
335
330
|
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
336
331
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
337
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
338
332
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
339
333
|
}> & {
|
|
340
334
|
make: (input: Omit<ToolCallPart, "type">) => ToolCallPart;
|
|
@@ -389,7 +383,6 @@ export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.
|
|
|
389
383
|
};
|
|
390
384
|
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
391
385
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
392
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
393
386
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
394
387
|
}> & {
|
|
395
388
|
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
@@ -401,7 +394,6 @@ export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.
|
|
|
401
394
|
readonly text: Schema.String;
|
|
402
395
|
readonly encrypted: Schema.optional<Schema.String>;
|
|
403
396
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
404
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
405
397
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
406
398
|
}>, Schema.refine<{
|
|
407
399
|
readonly type: "compaction";
|
|
@@ -431,7 +423,6 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
431
423
|
readonly type: Schema.Literal<"text">;
|
|
432
424
|
readonly text: Schema.String;
|
|
433
425
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
434
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
435
426
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
436
427
|
}>, Schema.Struct<{
|
|
437
428
|
readonly type: Schema.Literal<"media">;
|
|
@@ -478,7 +469,6 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
478
469
|
readonly input: Schema.Unknown;
|
|
479
470
|
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
480
471
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
481
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
482
472
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
483
473
|
}> & {
|
|
484
474
|
make: (input: Omit<ToolCallPart, "type">) => ToolCallPart;
|
|
@@ -533,7 +523,6 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
533
523
|
};
|
|
534
524
|
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
535
525
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
536
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
537
526
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
538
527
|
}> & {
|
|
539
528
|
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
@@ -545,7 +534,6 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
545
534
|
readonly text: Schema.String;
|
|
546
535
|
readonly encrypted: Schema.optional<Schema.String>;
|
|
547
536
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
548
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
549
537
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
550
538
|
}>, Schema.refine<{
|
|
551
539
|
readonly type: "compaction";
|
|
@@ -567,7 +555,6 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
567
555
|
readonly effort: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
568
556
|
readonly previous: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
569
557
|
}>]>>;
|
|
570
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
571
558
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
572
559
|
readonly native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
573
560
|
}>, {}>;
|
|
@@ -627,7 +614,6 @@ declare const toolDefinitionFields: {
|
|
|
627
614
|
readonly grammar: Schema.String;
|
|
628
615
|
}>]>>;
|
|
629
616
|
cache: Schema.optional<typeof CacheHint>;
|
|
630
|
-
metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
631
617
|
native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
632
618
|
};
|
|
633
619
|
export type ToolDefinitionInput = Schema.Struct.Type<typeof toolDefinitionFields>;
|
|
@@ -646,7 +632,6 @@ declare const ToolDefinition_base: Schema.Class<ToolDefinition, Schema.Struct<{
|
|
|
646
632
|
readonly grammar: Schema.String;
|
|
647
633
|
}>]>>;
|
|
648
634
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
649
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
650
635
|
readonly native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
651
636
|
readonly type: Schema.Literal<"tool">;
|
|
652
637
|
}>, {}>;
|
|
@@ -712,7 +697,6 @@ export interface LLMRequest<Model extends LanguageModel = LanguageModel> {
|
|
|
712
697
|
readonly cache?: CachePolicy;
|
|
713
698
|
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
|
|
714
699
|
readonly promptCacheKey?: string;
|
|
715
|
-
readonly metadata?: Record<string, unknown>;
|
|
716
700
|
/** Emit a `raw` event with each provider frame before the events parsed from it. */
|
|
717
701
|
readonly includeRaw?: boolean;
|
|
718
702
|
}
|