@opencode/ai 0.0.0-dev-491 → 0.0.0-dev-513
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/protocols/anthropic-messages.js +35 -89
- package/dist/protocols/bedrock-converse.js +2 -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/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/package.json +3 -3
|
@@ -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":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-513",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -520,7 +520,7 @@
|
|
|
520
520
|
"devDependencies": {
|
|
521
521
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
522
522
|
"@effect/platform-node": "4.1.0",
|
|
523
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
523
|
+
"@opencode/http-recorder": "0.0.0-dev-513",
|
|
524
524
|
"@tsconfig/bun": "1.0.9",
|
|
525
525
|
"@types/bun": "1.4.3",
|
|
526
526
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -530,7 +530,7 @@
|
|
|
530
530
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
531
531
|
"@smithy/eventstream-codec": "4.2.14",
|
|
532
532
|
"@smithy/util-utf8": "4.2.2",
|
|
533
|
-
"@opencode/schema": "0.0.0-dev-
|
|
533
|
+
"@opencode/schema": "0.0.0-dev-513",
|
|
534
534
|
"aws4fetch": "1.0.20",
|
|
535
535
|
"effect": "4.1.0",
|
|
536
536
|
"google-auth-library": "10.5.0"
|