@opencode/ai 0.0.0-beta-19288 → 0.0.0-beta-19296

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.
@@ -1,24 +1,150 @@
1
+ import type { ProviderPackage } from "../provider-package.js";
2
+ import { ZAIChat } from "../protocols/zai-chat.js";
1
3
  import { type ProviderAuthOption } from "../route/auth-options.js";
2
- import { HttpOptions, type ModelID } from "../schema/index.js";
4
+ import { Route, type RouteDefaultsInput } from "../route/client.js";
5
+ import { type ModelID } from "../schema/index.js";
3
6
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
4
- export type Config = ProviderAuthOption<"optional"> & {
7
+ export type ChatOptionsInput = ZAIChat.OptionsInput;
8
+ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
5
9
  readonly baseURL?: string;
6
- readonly headers?: Record<string, string>;
7
- readonly http?: HttpOptions.Input;
10
+ readonly providerOptions?: ChatOptionsInput;
8
11
  };
12
+ export interface Settings extends ProviderPackage.Settings {
13
+ readonly apiKey?: string;
14
+ readonly baseURL?: string;
15
+ readonly providerOptions?: ChatOptionsInput;
16
+ }
9
17
  export type { ZAIImageOptions } from "../protocols/zai-images.js";
18
+ export declare const routes: Route<{
19
+ readonly model: string;
20
+ readonly messages: readonly ({
21
+ readonly role: "system";
22
+ readonly content: string | readonly ({
23
+ readonly type: "text";
24
+ readonly text: string;
25
+ readonly cache_control?: {
26
+ readonly type: "ephemeral";
27
+ readonly ttl?: string | undefined;
28
+ } | undefined;
29
+ } | {
30
+ readonly type: "image_url";
31
+ readonly image_url: {
32
+ readonly url: string;
33
+ };
34
+ })[];
35
+ } | {
36
+ readonly role: "user";
37
+ readonly content: string | readonly ({
38
+ readonly type: "text";
39
+ readonly text: string;
40
+ readonly cache_control?: {
41
+ readonly type: "ephemeral";
42
+ readonly ttl?: string | undefined;
43
+ } | undefined;
44
+ } | {
45
+ readonly type: "image_url";
46
+ readonly image_url: {
47
+ readonly url: string;
48
+ };
49
+ })[];
50
+ } | {
51
+ readonly [x: string]: unknown;
52
+ readonly content: string | null;
53
+ readonly role: "assistant";
54
+ readonly reasoning?: string | undefined;
55
+ readonly reasoning_content?: string | undefined;
56
+ readonly reasoning_text?: string | undefined;
57
+ readonly cache_control?: {
58
+ readonly type: "ephemeral";
59
+ readonly ttl?: string | undefined;
60
+ } | undefined;
61
+ readonly tool_calls?: readonly {
62
+ readonly id: string;
63
+ readonly type: "function";
64
+ readonly function: {
65
+ readonly name: string;
66
+ readonly arguments: string;
67
+ };
68
+ }[] | undefined;
69
+ readonly reasoning_details?: unknown;
70
+ } | {
71
+ readonly content: string;
72
+ readonly role: "tool";
73
+ readonly tool_call_id: string;
74
+ readonly cache_control?: {
75
+ readonly type: "ephemeral";
76
+ readonly ttl?: string | undefined;
77
+ } | undefined;
78
+ })[];
79
+ readonly stream: true;
80
+ readonly max_completion_tokens?: number | undefined;
81
+ readonly max_tokens?: number | undefined;
82
+ readonly tools?: readonly {
83
+ readonly function: {
84
+ readonly description: string;
85
+ readonly name: string;
86
+ readonly parameters: {
87
+ readonly [x: string]: unknown;
88
+ };
89
+ readonly strict?: boolean | undefined;
90
+ };
91
+ readonly type: "function";
92
+ readonly cache_control?: {
93
+ readonly type: "ephemeral";
94
+ readonly ttl?: string | undefined;
95
+ } | undefined;
96
+ }[] | undefined;
97
+ readonly stop?: readonly string[] | undefined;
98
+ readonly temperature?: number | undefined;
99
+ readonly seed?: number | undefined;
100
+ readonly thinking?: {
101
+ readonly type?: string | undefined;
102
+ readonly clear_thinking?: boolean | undefined;
103
+ } | undefined;
104
+ readonly user_id?: string | undefined;
105
+ readonly tool_choice?: "required" | "auto" | "none" | {
106
+ readonly type: "function";
107
+ readonly function: {
108
+ readonly name: string;
109
+ };
110
+ } | undefined;
111
+ readonly top_p?: number | undefined;
112
+ readonly frequency_penalty?: number | undefined;
113
+ readonly presence_penalty?: number | undefined;
114
+ readonly prompt_cache_key?: string | undefined;
115
+ readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
116
+ readonly store?: boolean | undefined;
117
+ readonly stream_options?: {
118
+ readonly include_usage: boolean;
119
+ } | undefined;
120
+ readonly tool_stream?: boolean | undefined;
121
+ readonly response_format?: {
122
+ readonly type: string;
123
+ } | undefined;
124
+ readonly do_sample?: boolean | undefined;
125
+ readonly request_id?: string | undefined;
126
+ }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
10
127
  export declare const configure: (input?: Config) => {
11
128
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
12
- image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
129
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
130
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
131
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
13
132
  configure: (input?: Config) => /*elided*/ any;
14
133
  };
15
134
  export declare const provider: {
16
135
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
17
- image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
136
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
137
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
138
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
18
139
  configure: (input?: Config) => {
19
140
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
20
- image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
141
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
142
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
143
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
21
144
  configure: /*elided*/ any;
22
145
  };
23
146
  };
24
- export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
147
+ export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
148
+ export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
149
+ export declare const model: ProviderPackage.Definition<Settings, ChatOptionsInput>["model"];
150
+ export * as ZAI from "./zai.js";
@@ -1,9 +1,30 @@
1
+ import { ZAIChat } from "../protocols/zai-chat.js";
1
2
  import { ZAIImages } from "../protocols/zai-images.js";
3
+ import { OpenAIChat } from "../protocols/openai-chat.js";
2
4
  import { AuthOptions } from "../route/auth-options.js";
5
+ import { Route } from "../route/client.js";
6
+ import { Endpoint } from "../route/endpoint.js";
3
7
  import { HttpOptions, ProviderID } from "../schema/index.js";
4
8
  export const id = ProviderID.make("zai");
5
9
  const auth = (options) => AuthOptions.bearer(options, "ZAI_API_KEY");
10
+ const chatRoute = Route.make({
11
+ id: "zai-chat",
12
+ provider: id,
13
+ providerMetadataKey: "zai",
14
+ protocol: ZAIChat.protocol,
15
+ endpoint: Endpoint.path("/chat/completions", { baseURL: "https://api.z.ai/api/paas/v4" }),
16
+ framing: OpenAIChat.framing,
17
+ });
18
+ export const routes = [chatRoute];
6
19
  export const configure = (input = {}) => {
20
+ const { apiKey: _apiKey, auth: _auth, baseURL, ...rest } = input;
21
+ const chat = (modelID) => chatRoute
22
+ .with({
23
+ ...rest,
24
+ endpoint: baseURL === undefined ? undefined : { baseURL },
25
+ auth: auth(input),
26
+ })
27
+ .model({ id: modelID, compatibility: ZAIChat.compatibility });
7
28
  const image = (modelID) => ZAIImages.model({
8
29
  id: modelID,
9
30
  auth: auth(input),
@@ -13,9 +34,20 @@ export const configure = (input = {}) => {
13
34
  });
14
35
  return {
15
36
  id,
37
+ model: chat,
38
+ chat,
16
39
  image,
17
40
  configure,
18
41
  };
19
42
  };
20
43
  export const provider = configure();
21
44
  export const image = provider.image;
45
+ export const chat = provider.chat;
46
+ export const model = (modelID, settings) => configure({
47
+ apiKey: settings.apiKey,
48
+ baseURL: settings.baseURL,
49
+ headers: settings.headers,
50
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
51
+ providerOptions: settings.providerOptions,
52
+ }).model(modelID);
53
+ export * as ZAI from "./zai.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-beta-19288",
3
+ "version": "0.0.0-beta-19296",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@clack/prompts": "1.0.0-alpha.1",
32
32
  "@effect/platform-node": "4.0.0-rc.112",
33
- "@opencode/http-recorder": "0.0.0-beta-19288",
33
+ "@opencode/http-recorder": "0.0.0-beta-19296",
34
34
  "@tsconfig/bun": "1.0.9",
35
35
  "@types/bun": "1.4.0",
36
36
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -40,7 +40,7 @@
40
40
  "@aws-sdk/credential-providers": "3.1057.0",
41
41
  "@smithy/eventstream-codec": "4.2.14",
42
42
  "@smithy/util-utf8": "4.2.2",
43
- "@opencode/schema": "0.0.0-beta-19288",
43
+ "@opencode/schema": "0.0.0-beta-19296",
44
44
  "aws4fetch": "1.0.20",
45
45
  "effect": "4.0.0-rc.112",
46
46
  "google-auth-library": "10.5.0"