@opencode/ai 0.0.0-reserved → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/README.md +879 -2
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +129 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +28 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +103 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +252 -0
  11. package/dist/llm.js +74 -0
  12. package/dist/protocols/alibaba-chat.d.ts +225 -0
  13. package/dist/protocols/alibaba-chat.js +75 -0
  14. package/dist/protocols/alibaba-messages.d.ts +350 -0
  15. package/dist/protocols/alibaba-messages.js +40 -0
  16. package/dist/protocols/alibaba-responses.d.ts +255 -0
  17. package/dist/protocols/alibaba-responses.js +80 -0
  18. package/dist/protocols/anthropic-messages.d.ts +980 -0
  19. package/dist/protocols/anthropic-messages.js +1460 -0
  20. package/dist/protocols/bedrock-converse.d.ts +499 -0
  21. package/dist/protocols/bedrock-converse.js +643 -0
  22. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  23. package/dist/protocols/bedrock-event-stream.js +97 -0
  24. package/dist/protocols/gemini.d.ts +285 -0
  25. package/dist/protocols/gemini.js +671 -0
  26. package/dist/protocols/google-images.d.ts +30 -0
  27. package/dist/protocols/google-images.js +181 -0
  28. package/dist/protocols/index.d.ts +12 -0
  29. package/dist/protocols/index.js +12 -0
  30. package/dist/protocols/meta-images.d.ts +26 -0
  31. package/dist/protocols/meta-images.js +89 -0
  32. package/dist/protocols/meta-messages.d.ts +356 -0
  33. package/dist/protocols/meta-messages.js +41 -0
  34. package/dist/protocols/meta-responses.d.ts +473 -0
  35. package/dist/protocols/meta-responses.js +173 -0
  36. package/dist/protocols/mistral-chat.d.ts +540 -0
  37. package/dist/protocols/mistral-chat.js +624 -0
  38. package/dist/protocols/open-responses-channel.d.ts +25 -0
  39. package/dist/protocols/open-responses-channel.js +141 -0
  40. package/dist/protocols/open-responses-continuation.d.ts +16 -0
  41. package/dist/protocols/open-responses-continuation.js +170 -0
  42. package/dist/protocols/open-responses.d.ts +1715 -0
  43. package/dist/protocols/open-responses.js +1228 -0
  44. package/dist/protocols/openai-chat.d.ts +860 -0
  45. package/dist/protocols/openai-chat.js +966 -0
  46. package/dist/protocols/openai-compatible-chat.d.ts +109 -0
  47. package/dist/protocols/openai-compatible-chat.js +19 -0
  48. package/dist/protocols/openai-compatible-responses.d.ts +172 -0
  49. package/dist/protocols/openai-compatible-responses.js +18 -0
  50. package/dist/protocols/openai-images.d.ts +32 -0
  51. package/dist/protocols/openai-images.js +183 -0
  52. package/dist/protocols/openai-responses.d.ts +1389 -0
  53. package/dist/protocols/openai-responses.js +260 -0
  54. package/dist/protocols/shared.d.ts +193 -0
  55. package/dist/protocols/shared.js +290 -0
  56. package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
  57. package/dist/protocols/utils/bedrock-auth.js +85 -0
  58. package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
  59. package/dist/protocols/utils/bedrock-cache.js +49 -0
  60. package/dist/protocols/utils/bedrock-media.d.ts +55 -0
  61. package/dist/protocols/utils/bedrock-media.js +73 -0
  62. package/dist/protocols/utils/cache.d.ts +6 -0
  63. package/dist/protocols/utils/cache.js +5 -0
  64. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  65. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  66. package/dist/protocols/utils/image-input.d.ts +21 -0
  67. package/dist/protocols/utils/image-input.js +20 -0
  68. package/dist/protocols/utils/lifecycle.d.ts +24 -0
  69. package/dist/protocols/utils/lifecycle.js +72 -0
  70. package/dist/protocols/utils/meta-image.d.ts +2 -0
  71. package/dist/protocols/utils/meta-image.js +13 -0
  72. package/dist/protocols/utils/open-responses-options.d.ts +56 -0
  73. package/dist/protocols/utils/open-responses-options.js +61 -0
  74. package/dist/protocols/utils/openai-image.d.ts +5 -0
  75. package/dist/protocols/utils/openai-image.js +18 -0
  76. package/dist/protocols/utils/openai-options.d.ts +16 -0
  77. package/dist/protocols/utils/openai-options.js +14 -0
  78. package/dist/protocols/utils/partial-json-options.d.ts +62 -0
  79. package/dist/protocols/utils/partial-json-options.js +52 -0
  80. package/dist/protocols/utils/partial-json.d.ts +8 -0
  81. package/dist/protocols/utils/partial-json.js +279 -0
  82. package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
  83. package/dist/protocols/utils/responses-checkpoint.js +107 -0
  84. package/dist/protocols/utils/responses-compaction.d.ts +4 -0
  85. package/dist/protocols/utils/responses-compaction.js +129 -0
  86. package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
  87. package/dist/protocols/utils/responses-hosted-tools.js +32 -0
  88. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  89. package/dist/protocols/utils/tool-schema.js +54 -0
  90. package/dist/protocols/utils/tool-stream.d.ts +710 -0
  91. package/dist/protocols/utils/tool-stream.js +155 -0
  92. package/dist/protocols/xai-images.d.ts +26 -0
  93. package/dist/protocols/xai-images.js +106 -0
  94. package/dist/protocols/xai-responses.d.ts +250 -0
  95. package/dist/protocols/xai-responses.js +81 -0
  96. package/dist/protocols/zai-chat.d.ts +202 -0
  97. package/dist/protocols/zai-chat.js +49 -0
  98. package/dist/protocols/zai-images.d.ts +22 -0
  99. package/dist/protocols/zai-images.js +79 -0
  100. package/dist/protocols/zai-messages.d.ts +344 -0
  101. package/dist/protocols/zai-messages.js +27 -0
  102. package/dist/protocols.d.ts +1 -0
  103. package/dist/protocols.js +1 -0
  104. package/dist/provider-error.d.ts +15 -0
  105. package/dist/provider-error.js +125 -0
  106. package/dist/provider-package.d.ts +15 -0
  107. package/dist/provider-package.js +1 -0
  108. package/dist/provider.d.ts +23 -0
  109. package/dist/provider.js +2 -0
  110. package/dist/providers/alibaba/chat.d.ts +1 -0
  111. package/dist/providers/alibaba/chat.js +1 -0
  112. package/dist/providers/alibaba/messages.d.ts +3 -0
  113. package/dist/providers/alibaba/messages.js +1 -0
  114. package/dist/providers/alibaba/responses.d.ts +3 -0
  115. package/dist/providers/alibaba/responses.js +1 -0
  116. package/dist/providers/alibaba.d.ts +711 -0
  117. package/dist/providers/alibaba.js +94 -0
  118. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  119. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  120. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  121. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  122. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  123. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  124. package/dist/providers/amazon-bedrock-mantle.d.ts +313 -0
  125. package/dist/providers/amazon-bedrock-mantle.js +79 -0
  126. package/dist/providers/amazon-bedrock.d.ts +173 -0
  127. package/dist/providers/amazon-bedrock.js +41 -0
  128. package/dist/providers/anthropic-compatible.d.ts +309 -0
  129. package/dist/providers/anthropic-compatible.js +50 -0
  130. package/dist/providers/anthropic.d.ts +307 -0
  131. package/dist/providers/anthropic.js +42 -0
  132. package/dist/providers/azure/chat.d.ts +2 -0
  133. package/dist/providers/azure/chat.js +1 -0
  134. package/dist/providers/azure/responses.d.ts +2 -0
  135. package/dist/providers/azure/responses.js +1 -0
  136. package/dist/providers/azure.d.ts +598 -0
  137. package/dist/providers/azure.js +115 -0
  138. package/dist/providers/baseten.d.ts +228 -0
  139. package/dist/providers/baseten.js +38 -0
  140. package/dist/providers/cerebras.d.ts +227 -0
  141. package/dist/providers/cerebras.js +40 -0
  142. package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
  143. package/dist/providers/cloudflare-ai-gateway.js +65 -0
  144. package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
  145. package/dist/providers/cloudflare-workers-ai.js +51 -0
  146. package/dist/providers/deepinfra.d.ts +227 -0
  147. package/dist/providers/deepinfra.js +43 -0
  148. package/dist/providers/deepseek.d.ts +228 -0
  149. package/dist/providers/deepseek.js +41 -0
  150. package/dist/providers/fireworks.d.ts +228 -0
  151. package/dist/providers/fireworks.js +38 -0
  152. package/dist/providers/google-vertex/chat.d.ts +2 -0
  153. package/dist/providers/google-vertex/chat.js +1 -0
  154. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  155. package/dist/providers/google-vertex/gemini.js +1 -0
  156. package/dist/providers/google-vertex/messages.d.ts +2 -0
  157. package/dist/providers/google-vertex/messages.js +1 -0
  158. package/dist/providers/google-vertex/responses.d.ts +2 -0
  159. package/dist/providers/google-vertex/responses.js +1 -0
  160. package/dist/providers/google-vertex-chat.d.ts +132 -0
  161. package/dist/providers/google-vertex-chat.js +55 -0
  162. package/dist/providers/google-vertex-messages.d.ts +306 -0
  163. package/dist/providers/google-vertex-messages.js +75 -0
  164. package/dist/providers/google-vertex-responses.d.ts +197 -0
  165. package/dist/providers/google-vertex-responses.js +56 -0
  166. package/dist/providers/google-vertex-shared.d.ts +22 -0
  167. package/dist/providers/google-vertex-shared.js +72 -0
  168. package/dist/providers/google-vertex.d.ts +119 -0
  169. package/dist/providers/google-vertex.js +98 -0
  170. package/dist/providers/google.d.ts +114 -0
  171. package/dist/providers/google.js +42 -0
  172. package/dist/providers/groq.d.ts +314 -0
  173. package/dist/providers/groq.js +81 -0
  174. package/dist/providers/index.d.ts +31 -0
  175. package/dist/providers/index.js +31 -0
  176. package/dist/providers/meta/chat.d.ts +2 -0
  177. package/dist/providers/meta/chat.js +1 -0
  178. package/dist/providers/meta/messages.d.ts +2 -0
  179. package/dist/providers/meta/messages.js +1 -0
  180. package/dist/providers/meta/responses.d.ts +2 -0
  181. package/dist/providers/meta/responses.js +1 -0
  182. package/dist/providers/meta.d.ts +636 -0
  183. package/dist/providers/meta.js +113 -0
  184. package/dist/providers/minimax/chat.d.ts +4 -0
  185. package/dist/providers/minimax/chat.js +8 -0
  186. package/dist/providers/minimax/messages.d.ts +1 -0
  187. package/dist/providers/minimax/messages.js +1 -0
  188. package/dist/providers/minimax/responses.d.ts +4 -0
  189. package/dist/providers/minimax/responses.js +8 -0
  190. package/dist/providers/minimax.d.ts +598 -0
  191. package/dist/providers/minimax.js +89 -0
  192. package/dist/providers/mistral.d.ts +207 -0
  193. package/dist/providers/mistral.js +28 -0
  194. package/dist/providers/moonshot/chat.d.ts +1 -0
  195. package/dist/providers/moonshot/chat.js +1 -0
  196. package/dist/providers/moonshot/messages.d.ts +4 -0
  197. package/dist/providers/moonshot/messages.js +8 -0
  198. package/dist/providers/moonshot/responses.d.ts +4 -0
  199. package/dist/providers/moonshot/responses.js +8 -0
  200. package/dist/providers/moonshot.d.ts +596 -0
  201. package/dist/providers/moonshot.js +90 -0
  202. package/dist/providers/open-responses-options.d.ts +6 -0
  203. package/dist/providers/open-responses-options.js +1 -0
  204. package/dist/providers/openai/chat.d.ts +2 -0
  205. package/dist/providers/openai/chat.js +1 -0
  206. package/dist/providers/openai/responses.d.ts +2 -0
  207. package/dist/providers/openai/responses.js +1 -0
  208. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  209. package/dist/providers/openai-compatible/responses.js +1 -0
  210. package/dist/providers/openai-compatible-responses.d.ts +195 -0
  211. package/dist/providers/openai-compatible-responses.js +32 -0
  212. package/dist/providers/openai-compatible.d.ts +130 -0
  213. package/dist/providers/openai-compatible.js +33 -0
  214. package/dist/providers/openai-options.d.ts +26 -0
  215. package/dist/providers/openai-options.js +41 -0
  216. package/dist/providers/openai.d.ts +404 -0
  217. package/dist/providers/openai.js +82 -0
  218. package/dist/providers/openrouter.d.ts +563 -0
  219. package/dist/providers/openrouter.js +114 -0
  220. package/dist/providers/togetherai.d.ts +227 -0
  221. package/dist/providers/togetherai.js +40 -0
  222. package/dist/providers/xai.d.ts +163 -0
  223. package/dist/providers/xai.js +88 -0
  224. package/dist/providers/zai/chat.d.ts +1 -0
  225. package/dist/providers/zai/chat.js +1 -0
  226. package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
  227. package/dist/providers/zai-coding-plan/chat.js +1 -0
  228. package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
  229. package/dist/providers/zai-coding-plan/messages.js +8 -0
  230. package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
  231. package/dist/providers/zai-coding-plan/responses.js +8 -0
  232. package/dist/providers/zai-coding-plan.d.ts +577 -0
  233. package/dist/providers/zai-coding-plan.js +63 -0
  234. package/dist/providers/zai.d.ts +149 -0
  235. package/dist/providers/zai.js +53 -0
  236. package/dist/providers.d.ts +1 -0
  237. package/dist/providers.js +1 -0
  238. package/dist/route/auth-options.d.ts +34 -0
  239. package/dist/route/auth-options.js +14 -0
  240. package/dist/route/auth.d.ts +51 -0
  241. package/dist/route/auth.js +87 -0
  242. package/dist/route/client.d.ts +430 -0
  243. package/dist/route/client.js +307 -0
  244. package/dist/route/endpoint.d.ts +28 -0
  245. package/dist/route/endpoint.js +21 -0
  246. package/dist/route/executor.d.ts +27 -0
  247. package/dist/route/executor.js +183 -0
  248. package/dist/route/framing.d.ts +29 -0
  249. package/dist/route/framing.js +14 -0
  250. package/dist/route/index.d.ts +16 -0
  251. package/dist/route/index.js +9 -0
  252. package/dist/route/protocol.d.ts +76 -0
  253. package/dist/route/protocol.js +16 -0
  254. package/dist/route/transport/http.d.ts +34 -0
  255. package/dist/route/transport/http.js +68 -0
  256. package/dist/route/transport/index.d.ts +41 -0
  257. package/dist/route/transport/index.js +4 -0
  258. package/dist/route/transport/websocket-channel.d.ts +57 -0
  259. package/dist/route/transport/websocket-channel.js +1 -0
  260. package/dist/route/transport/websocket.d.ts +56 -0
  261. package/dist/route/transport/websocket.js +370 -0
  262. package/dist/route.d.ts +1 -0
  263. package/dist/route.js +1 -0
  264. package/dist/schema/errors.d.ts +170 -0
  265. package/dist/schema/errors.js +131 -0
  266. package/dist/schema/events.d.ts +8123 -0
  267. package/dist/schema/events.js +550 -0
  268. package/dist/schema/ids.d.ts +17 -0
  269. package/dist/schema/ids.js +10 -0
  270. package/dist/schema/index.d.ts +5 -0
  271. package/dist/schema/index.js +5 -0
  272. package/dist/schema/messages.d.ts +646 -0
  273. package/dist/schema/messages.js +301 -0
  274. package/dist/schema/options.d.ts +159 -0
  275. package/dist/schema/options.js +189 -0
  276. package/dist/testing.d.ts +1693 -0
  277. package/dist/testing.js +129 -0
  278. package/dist/tool-history.d.ts +2 -0
  279. package/dist/tool-history.js +84 -0
  280. package/dist/tool-runtime.d.ts +15 -0
  281. package/dist/tool-runtime.js +62 -0
  282. package/dist/tool.d.ts +136 -0
  283. package/dist/tool.js +66 -0
  284. package/dist/utils/record.d.ts +2 -0
  285. package/dist/utils/record.js +2 -0
  286. package/dist/utils/sanitize.d.ts +1 -0
  287. package/dist/utils/sanitize.js +12 -0
  288. package/package.json +43 -10
@@ -0,0 +1,202 @@
1
+ import { Protocol } from "../route/protocol.js";
2
+ import { OpenAIChat } from "./openai-chat.js";
3
+ export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | (string & {});
4
+ export type OptionsInput = {
5
+ readonly reasoningEffort?: ReasoningEffort;
6
+ readonly thinking?: {
7
+ readonly type?: "enabled" | "disabled" | (string & {});
8
+ /** False retains historical reasoning; omission preserves the endpoint's default. */
9
+ readonly clear_thinking?: boolean;
10
+ };
11
+ readonly toolStream?: boolean;
12
+ readonly doSample?: boolean;
13
+ readonly responseFormat?: {
14
+ readonly type: "text" | "json_object" | (string & {});
15
+ };
16
+ readonly requestID?: string;
17
+ readonly userID?: string;
18
+ };
19
+ export declare const compatibility: {
20
+ maxTokensField: "max_tokens";
21
+ supportsStore: false;
22
+ supportsStrictMode: false;
23
+ reasoningField: string;
24
+ zaiToolStream: false;
25
+ };
26
+ export declare const protocol: Protocol<{
27
+ readonly model: string;
28
+ readonly messages: readonly ({
29
+ readonly role: "system";
30
+ readonly content: string | readonly ({
31
+ readonly type: "text";
32
+ readonly text: string;
33
+ readonly cache_control?: {
34
+ readonly type: "ephemeral";
35
+ readonly ttl?: string | undefined;
36
+ } | undefined;
37
+ } | {
38
+ readonly type: "image_url";
39
+ readonly image_url: {
40
+ readonly url: string;
41
+ };
42
+ })[];
43
+ } | {
44
+ readonly role: "user";
45
+ readonly content: string | readonly ({
46
+ readonly type: "text";
47
+ readonly text: string;
48
+ readonly cache_control?: {
49
+ readonly type: "ephemeral";
50
+ readonly ttl?: string | undefined;
51
+ } | undefined;
52
+ } | {
53
+ readonly type: "image_url";
54
+ readonly image_url: {
55
+ readonly url: string;
56
+ };
57
+ })[];
58
+ } | {
59
+ readonly [x: string]: unknown;
60
+ readonly content: string | null;
61
+ readonly role: "assistant";
62
+ readonly reasoning?: string | undefined;
63
+ readonly reasoning_content?: string | undefined;
64
+ readonly reasoning_text?: string | undefined;
65
+ readonly cache_control?: {
66
+ readonly type: "ephemeral";
67
+ readonly ttl?: string | undefined;
68
+ } | undefined;
69
+ readonly tool_calls?: readonly {
70
+ readonly id: string;
71
+ readonly type: "function";
72
+ readonly function: {
73
+ readonly name: string;
74
+ readonly arguments: string;
75
+ };
76
+ }[] | undefined;
77
+ readonly reasoning_details?: unknown;
78
+ } | {
79
+ readonly content: string;
80
+ readonly role: "tool";
81
+ readonly tool_call_id: string;
82
+ readonly cache_control?: {
83
+ readonly type: "ephemeral";
84
+ readonly ttl?: string | undefined;
85
+ } | undefined;
86
+ })[];
87
+ readonly stream: true;
88
+ readonly max_completion_tokens?: number | undefined;
89
+ readonly max_tokens?: number | undefined;
90
+ readonly tools?: readonly {
91
+ readonly function: {
92
+ readonly description: string;
93
+ readonly name: string;
94
+ readonly parameters: {
95
+ readonly [x: string]: unknown;
96
+ };
97
+ readonly strict?: boolean | undefined;
98
+ };
99
+ readonly type: "function";
100
+ readonly cache_control?: {
101
+ readonly type: "ephemeral";
102
+ readonly ttl?: string | undefined;
103
+ } | undefined;
104
+ }[] | undefined;
105
+ readonly stop?: readonly string[] | undefined;
106
+ readonly temperature?: number | undefined;
107
+ readonly seed?: number | undefined;
108
+ readonly thinking?: {
109
+ readonly type?: string | undefined;
110
+ readonly clear_thinking?: boolean | undefined;
111
+ } | undefined;
112
+ readonly user_id?: string | undefined;
113
+ readonly tool_choice?: "required" | "auto" | "none" | {
114
+ readonly type: "function";
115
+ readonly function: {
116
+ readonly name: string;
117
+ };
118
+ } | undefined;
119
+ readonly top_p?: number | undefined;
120
+ readonly frequency_penalty?: number | undefined;
121
+ readonly presence_penalty?: number | undefined;
122
+ readonly prompt_cache_key?: string | undefined;
123
+ readonly reasoning_effort?: import("./utils/open-responses-options.js").ReasoningEffort | undefined;
124
+ readonly store?: boolean | undefined;
125
+ readonly stream_options?: {
126
+ readonly include_usage: boolean;
127
+ } | undefined;
128
+ readonly tool_stream?: boolean | undefined;
129
+ readonly response_format?: {
130
+ readonly type: string;
131
+ } | undefined;
132
+ readonly do_sample?: boolean | undefined;
133
+ readonly request_id?: string | undefined;
134
+ }, string, "[DONE]" | {
135
+ readonly [x: string]: unknown;
136
+ readonly error?: {
137
+ readonly [x: string]: unknown;
138
+ readonly message: string;
139
+ readonly code?: string | number | null | undefined;
140
+ } | null | undefined;
141
+ readonly usage?: {
142
+ readonly [x: string]: unknown;
143
+ readonly cached_tokens?: number | null | undefined;
144
+ readonly prompt_tokens?: number | null | undefined;
145
+ readonly completion_tokens?: number | null | undefined;
146
+ readonly total_tokens?: number | null | undefined;
147
+ readonly prompt_tokens_details?: {
148
+ readonly [x: string]: unknown;
149
+ readonly cached_tokens?: number | null | undefined;
150
+ readonly cache_write_tokens?: number | null | undefined;
151
+ } | null | undefined;
152
+ readonly prompt_cache_hit_tokens?: number | null | undefined;
153
+ readonly completion_tokens_details?: {
154
+ readonly [x: string]: unknown;
155
+ readonly reasoning_tokens?: number | null | undefined;
156
+ readonly accepted_prediction_tokens?: number | null | undefined;
157
+ readonly rejected_prediction_tokens?: number | null | undefined;
158
+ } | null | undefined;
159
+ } | null | undefined;
160
+ readonly choices?: readonly {
161
+ readonly [x: string]: unknown;
162
+ readonly delta?: {
163
+ readonly [x: string]: unknown;
164
+ readonly reasoning?: string | null | undefined;
165
+ readonly reasoning_content?: string | null | undefined;
166
+ readonly reasoning_text?: string | null | undefined;
167
+ readonly content?: string | null | undefined;
168
+ readonly refusal?: string | null | undefined;
169
+ readonly tool_calls?: readonly {
170
+ readonly function?: {
171
+ readonly name?: string | null | undefined;
172
+ readonly arguments?: string | null | undefined;
173
+ } | null | undefined;
174
+ readonly id?: string | null | undefined;
175
+ readonly index?: number | null | undefined;
176
+ }[] | null | undefined;
177
+ readonly reasoning_details?: unknown;
178
+ } | null | undefined;
179
+ readonly usage?: {
180
+ readonly [x: string]: unknown;
181
+ readonly cached_tokens?: number | null | undefined;
182
+ readonly prompt_tokens?: number | null | undefined;
183
+ readonly completion_tokens?: number | null | undefined;
184
+ readonly total_tokens?: number | null | undefined;
185
+ readonly prompt_tokens_details?: {
186
+ readonly [x: string]: unknown;
187
+ readonly cached_tokens?: number | null | undefined;
188
+ readonly cache_write_tokens?: number | null | undefined;
189
+ } | null | undefined;
190
+ readonly prompt_cache_hit_tokens?: number | null | undefined;
191
+ readonly completion_tokens_details?: {
192
+ readonly [x: string]: unknown;
193
+ readonly reasoning_tokens?: number | null | undefined;
194
+ readonly accepted_prediction_tokens?: number | null | undefined;
195
+ readonly rejected_prediction_tokens?: number | null | undefined;
196
+ } | null | undefined;
197
+ } | null | undefined;
198
+ readonly finish_reason?: string | null | undefined;
199
+ readonly native_finish_reason?: string | null | undefined;
200
+ }[] | null | undefined;
201
+ }, OpenAIChat.ParserState>;
202
+ export * as ZAIChat from "./zai-chat.js";
@@ -0,0 +1,49 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Protocol } from "../route/protocol.js";
3
+ import { OpenAIChat } from "./openai-chat.js";
4
+ import { ProviderShared } from "./shared.js";
5
+ const Options = Schema.Struct({
6
+ reasoningEffort: Schema.optional(Schema.String),
7
+ thinking: Schema.optional(Schema.Struct({ type: Schema.optional(Schema.String), clear_thinking: Schema.optional(Schema.Boolean) })),
8
+ toolStream: Schema.optional(Schema.Boolean),
9
+ doSample: Schema.optional(Schema.Boolean),
10
+ responseFormat: Schema.optional(Schema.Struct({ type: Schema.String })),
11
+ requestID: Schema.optional(Schema.String),
12
+ userID: Schema.optional(Schema.String),
13
+ });
14
+ const Body = Schema.Struct({
15
+ ...OpenAIChat.bodyFields,
16
+ thinking: Options.fields.thinking,
17
+ do_sample: Options.fields.doSample,
18
+ response_format: Options.fields.responseFormat,
19
+ request_id: Options.fields.requestID,
20
+ user_id: Options.fields.userID,
21
+ });
22
+ const fromRequest = Effect.fn("ZAIChat.fromRequest")(function* (request) {
23
+ const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
24
+ const body = yield* OpenAIChat.protocol.body.from(request);
25
+ return {
26
+ ...body,
27
+ thinking: options.thinking,
28
+ // Tool streaming was introduced in GLM-4.6; older models must not receive the opt-in.
29
+ tool_stream: options.toolStream ??
30
+ (body.tools?.length && /^glm-(?:4\.[67]|5(?:[.-]|$))/i.test(request.model.id) ? true : undefined),
31
+ do_sample: options.doSample,
32
+ response_format: options.responseFormat,
33
+ request_id: options.requestID,
34
+ user_id: options.userID,
35
+ };
36
+ });
37
+ export const compatibility = {
38
+ maxTokensField: "max_tokens",
39
+ supportsStore: false,
40
+ supportsStrictMode: false,
41
+ reasoningField: "reasoning_content",
42
+ zaiToolStream: false,
43
+ };
44
+ export const protocol = Protocol.make({
45
+ id: "zai-chat",
46
+ body: { schema: Body, from: fromRequest },
47
+ stream: OpenAIChat.protocol.stream,
48
+ });
49
+ export * as ZAIChat from "./zai-chat.js";
@@ -0,0 +1,22 @@
1
+ import { ImageModel } from "../image.js";
2
+ import { type Definition as AuthDefinition } from "../route/auth.js";
3
+ import { type HttpOptions } from "../schema/index.js";
4
+ export declare const DEFAULT_BASE_URL = "https://api.z.ai/api/paas/v4";
5
+ export declare const PATH = "/images/generations";
6
+ export type ZAIImageString<Known extends string> = Known | (string & {});
7
+ export type ZAIImageOptions = {
8
+ readonly size?: ZAIImageString<"1024x1024" | "768x1344" | "864x1152" | "1344x768" | "1152x864" | "1440x720" | "720x1440">;
9
+ readonly quality?: ZAIImageString<"hd" | "standard">;
10
+ readonly userID?: string;
11
+ } & Record<string, unknown>;
12
+ export interface ModelInput {
13
+ readonly id: string;
14
+ readonly auth: AuthDefinition;
15
+ readonly baseURL?: string;
16
+ readonly headers?: Record<string, string>;
17
+ readonly http?: HttpOptions;
18
+ }
19
+ export declare const model: (input: ModelInput) => ImageModel<ZAIImageOptions>;
20
+ export declare const ZAIImages: {
21
+ readonly model: (input: ModelInput) => ImageModel<ZAIImageOptions>;
22
+ };
@@ -0,0 +1,79 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Headers, HttpClientRequest } from "effect/unstable/http";
3
+ import { GeneratedImage, ImageModel, ImageResponse } from "../image.js";
4
+ import { Auth } from "../route/auth.js";
5
+ import { mergeHttpOptions, mergeJsonRecords } from "../schema/index.js";
6
+ import { ProviderShared } from "./shared.js";
7
+ import { ImageInputs } from "./utils/image-input.js";
8
+ const ADAPTER = "zai-images";
9
+ export const DEFAULT_BASE_URL = "https://api.z.ai/api/paas/v4";
10
+ export const PATH = "/images/generations";
11
+ const ZAIImageResponse = Schema.Struct({
12
+ created: Schema.optional(Schema.Int),
13
+ id: Schema.optional(Schema.String),
14
+ request_id: Schema.optional(Schema.String),
15
+ data: Schema.Array(Schema.Struct({ url: Schema.String })),
16
+ content_filter: Schema.optional(Schema.Array(Schema.Struct({
17
+ role: Schema.optional(Schema.String),
18
+ level: Schema.optional(Schema.Number),
19
+ }))),
20
+ });
21
+ const nativeOptions = (options) => {
22
+ if (!options)
23
+ return undefined;
24
+ const { userID, ...native } = options;
25
+ return {
26
+ user_id: userID,
27
+ ...native,
28
+ };
29
+ };
30
+ const applyQuery = (url, query) => {
31
+ if (!query)
32
+ return url;
33
+ const next = new URL(url);
34
+ Object.entries(query).forEach(([key, value]) => next.searchParams.set(key, value));
35
+ return next.toString();
36
+ };
37
+ export const model = (input) => {
38
+ const route = {
39
+ id: ADAPTER,
40
+ generate: Effect.fn("ZAIImages.generate")(function* (request, execute) {
41
+ if ((request.images?.length ?? 0) > 0)
42
+ return yield* ImageInputs.invalid("Z.ai hosted image generation does not support image inputs");
43
+ const http = mergeHttpOptions(request.model.http, request.http);
44
+ const requestBody = mergeJsonRecords({ model: request.model.id, prompt: request.prompt }, nativeOptions(request.options), http?.body);
45
+ const text = ProviderShared.encodeJson(requestBody);
46
+ const url = applyQuery(`${(input.baseURL ?? DEFAULT_BASE_URL).replace(/\/$/, "")}${PATH}`, http?.query);
47
+ const headers = yield* Auth.toEffect(input.auth)({
48
+ request,
49
+ method: "POST",
50
+ url,
51
+ body: text,
52
+ headers: Headers.fromInput({ ...input.headers, ...http?.headers }),
53
+ });
54
+ const response = yield* execute(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(text, "application/json")));
55
+ const output = yield* ProviderShared.imageResponse(ADAPTER, "Z.ai Images", response);
56
+ const decoded = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(ZAIImageResponse))(output.body).pipe(Effect.mapError((cause) => output.invalid("Z.ai Images returned an invalid response", cause)));
57
+ if (decoded.data.length === 0)
58
+ return yield* output.invalid("Z.ai Images returned no images");
59
+ return new ImageResponse({
60
+ images: decoded.data.map((item) => new GeneratedImage({
61
+ mediaType: "application/octet-stream",
62
+ data: item.url,
63
+ })),
64
+ providerMetadata: {
65
+ zai: {
66
+ created: decoded.created,
67
+ id: decoded.id,
68
+ requestID: decoded.request_id,
69
+ contentFilter: decoded.content_filter,
70
+ },
71
+ },
72
+ });
73
+ }),
74
+ };
75
+ return ImageModel.make({ id: input.id, provider: "zai", route, http: input.http });
76
+ };
77
+ export const ZAIImages = {
78
+ model,
79
+ };