@opencode/ai 0.0.0-reserved → 2.0.0

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,344 @@
1
+ import { Protocol } from "../route/protocol.js";
2
+ import type { ZAIChat } from "./zai-chat.js";
3
+ export type OptionsInput = {
4
+ readonly effort?: ZAIChat.ReasoningEffort;
5
+ readonly thinking?: {
6
+ readonly type: "enabled" | "adaptive" | "disabled" | (string & {});
7
+ };
8
+ };
9
+ export declare const protocol: Protocol<{
10
+ readonly max_tokens: number;
11
+ readonly model: string;
12
+ readonly messages: readonly ({
13
+ readonly role: "user";
14
+ readonly content: readonly ({
15
+ readonly type: "text";
16
+ readonly text: string;
17
+ readonly cache_control?: {
18
+ readonly type: "ephemeral";
19
+ readonly ttl?: "1h" | "5m" | undefined;
20
+ } | undefined;
21
+ } | {
22
+ readonly type: "image";
23
+ readonly source: {
24
+ readonly type: "base64";
25
+ readonly media_type: string;
26
+ readonly data: string;
27
+ } | {
28
+ readonly type: "url";
29
+ readonly url: string;
30
+ } | {
31
+ readonly type: "file";
32
+ readonly file_id: string;
33
+ };
34
+ readonly cache_control?: {
35
+ readonly type: "ephemeral";
36
+ readonly ttl?: "1h" | "5m" | undefined;
37
+ } | undefined;
38
+ readonly transformations?: {
39
+ readonly oversized_image?: "error" | "downsize" | undefined;
40
+ } | undefined;
41
+ } | {
42
+ readonly type: "document";
43
+ readonly source: {
44
+ readonly type: "base64";
45
+ readonly media_type: "application/pdf";
46
+ readonly data: string;
47
+ } | {
48
+ readonly type: "text";
49
+ readonly media_type: "text/plain";
50
+ readonly data: string;
51
+ } | {
52
+ readonly type: "url";
53
+ readonly url: string;
54
+ } | {
55
+ readonly type: "file";
56
+ readonly file_id: string;
57
+ };
58
+ readonly title?: string | undefined;
59
+ readonly context?: string | undefined;
60
+ readonly cache_control?: {
61
+ readonly type: "ephemeral";
62
+ readonly ttl?: "1h" | "5m" | undefined;
63
+ } | undefined;
64
+ readonly citations?: {
65
+ readonly enabled: boolean;
66
+ } | undefined;
67
+ } | {
68
+ readonly type: "tool_result";
69
+ readonly content: string | readonly ({
70
+ readonly type: "text";
71
+ readonly text: string;
72
+ readonly cache_control?: {
73
+ readonly type: "ephemeral";
74
+ readonly ttl?: "1h" | "5m" | undefined;
75
+ } | undefined;
76
+ } | {
77
+ readonly type: "image";
78
+ readonly source: {
79
+ readonly type: "base64";
80
+ readonly media_type: string;
81
+ readonly data: string;
82
+ } | {
83
+ readonly type: "url";
84
+ readonly url: string;
85
+ } | {
86
+ readonly type: "file";
87
+ readonly file_id: string;
88
+ };
89
+ readonly cache_control?: {
90
+ readonly type: "ephemeral";
91
+ readonly ttl?: "1h" | "5m" | undefined;
92
+ } | undefined;
93
+ readonly transformations?: {
94
+ readonly oversized_image?: "error" | "downsize" | undefined;
95
+ } | undefined;
96
+ } | {
97
+ readonly type: "document";
98
+ readonly source: {
99
+ readonly type: "base64";
100
+ readonly media_type: "application/pdf";
101
+ readonly data: string;
102
+ } | {
103
+ readonly type: "text";
104
+ readonly media_type: "text/plain";
105
+ readonly data: string;
106
+ } | {
107
+ readonly type: "url";
108
+ readonly url: string;
109
+ } | {
110
+ readonly type: "file";
111
+ readonly file_id: string;
112
+ };
113
+ readonly title?: string | undefined;
114
+ readonly context?: string | undefined;
115
+ readonly cache_control?: {
116
+ readonly type: "ephemeral";
117
+ readonly ttl?: "1h" | "5m" | undefined;
118
+ } | undefined;
119
+ readonly citations?: {
120
+ readonly enabled: boolean;
121
+ } | undefined;
122
+ })[];
123
+ readonly tool_use_id: string;
124
+ readonly cache_control?: {
125
+ readonly type: "ephemeral";
126
+ readonly ttl?: "1h" | "5m" | undefined;
127
+ } | undefined;
128
+ readonly is_error?: boolean | undefined;
129
+ })[];
130
+ } | {
131
+ readonly role: "assistant";
132
+ readonly content: readonly ({
133
+ readonly type: "text";
134
+ readonly text: string;
135
+ readonly cache_control?: {
136
+ readonly type: "ephemeral";
137
+ readonly ttl?: "1h" | "5m" | undefined;
138
+ } | undefined;
139
+ } | {
140
+ readonly id: string;
141
+ readonly type: "tool_use";
142
+ readonly name: string;
143
+ readonly input: unknown;
144
+ readonly cache_control?: {
145
+ readonly type: "ephemeral";
146
+ readonly ttl?: "1h" | "5m" | undefined;
147
+ } | undefined;
148
+ } | {
149
+ readonly id: string;
150
+ readonly type: "server_tool_use";
151
+ readonly name: string;
152
+ readonly input: unknown;
153
+ readonly cache_control?: {
154
+ readonly type: "ephemeral";
155
+ readonly ttl?: "1h" | "5m" | undefined;
156
+ } | undefined;
157
+ } | {
158
+ readonly type: "web_search_tool_result" | "code_execution_tool_result" | "web_fetch_tool_result";
159
+ readonly content: unknown;
160
+ readonly tool_use_id: string;
161
+ readonly cache_control?: {
162
+ readonly type: "ephemeral";
163
+ readonly ttl?: "1h" | "5m" | undefined;
164
+ } | undefined;
165
+ } | {
166
+ readonly type: "thinking";
167
+ readonly thinking: string;
168
+ readonly signature: string;
169
+ readonly cache_control?: {
170
+ readonly type: "ephemeral";
171
+ readonly ttl?: "1h" | "5m" | undefined;
172
+ } | undefined;
173
+ } | {
174
+ readonly data: string;
175
+ readonly type: "redacted_thinking";
176
+ readonly cache_control?: {
177
+ readonly type: "ephemeral";
178
+ readonly ttl?: "1h" | "5m" | undefined;
179
+ } | undefined;
180
+ } | {
181
+ readonly type: "compaction";
182
+ readonly content: string | null;
183
+ })[];
184
+ } | {
185
+ readonly role: "system";
186
+ readonly content: readonly {
187
+ readonly type: "text";
188
+ readonly text: string;
189
+ readonly cache_control?: {
190
+ readonly type: "ephemeral";
191
+ readonly ttl?: "1h" | "5m" | undefined;
192
+ } | undefined;
193
+ }[];
194
+ })[];
195
+ readonly stream: true;
196
+ readonly metadata?: {
197
+ readonly user_id?: string | null | undefined;
198
+ } | undefined;
199
+ readonly tools?: readonly {
200
+ readonly description: string;
201
+ readonly name: string;
202
+ readonly input_schema: {
203
+ readonly [x: string]: unknown;
204
+ };
205
+ readonly cache_control?: {
206
+ readonly type: "ephemeral";
207
+ readonly ttl?: "1h" | "5m" | undefined;
208
+ } | undefined;
209
+ }[] | undefined;
210
+ readonly system?: readonly {
211
+ readonly type: "text";
212
+ readonly text: string;
213
+ readonly cache_control?: {
214
+ readonly type: "ephemeral";
215
+ readonly ttl?: "1h" | "5m" | undefined;
216
+ } | undefined;
217
+ }[] | undefined;
218
+ readonly temperature?: number | undefined;
219
+ readonly thinking?: {
220
+ readonly type: string;
221
+ } | undefined;
222
+ readonly service_tier?: "auto" | "standard_only" | undefined;
223
+ readonly container?: string | {
224
+ readonly id?: string | null | undefined;
225
+ readonly skills?: readonly {
226
+ readonly [x: string]: unknown;
227
+ }[] | null | undefined;
228
+ } | null | undefined;
229
+ readonly inference_geo?: string | null | undefined;
230
+ readonly cache_control?: {
231
+ readonly type: "ephemeral";
232
+ readonly ttl?: "1h" | "5m" | undefined;
233
+ } | undefined;
234
+ readonly output_config?: {
235
+ readonly format?: {
236
+ readonly type: "json_schema";
237
+ readonly schema: {
238
+ readonly [x: string]: unknown;
239
+ };
240
+ } | null | undefined;
241
+ readonly effort?: string | undefined;
242
+ } | undefined;
243
+ readonly context_management?: {
244
+ readonly edits: readonly {
245
+ readonly type: "compact_20260112";
246
+ readonly instructions?: string | undefined;
247
+ readonly trigger?: {
248
+ readonly type: "input_tokens";
249
+ readonly value: number;
250
+ } | undefined;
251
+ readonly pause_after_compaction?: boolean | undefined;
252
+ }[];
253
+ } | undefined;
254
+ readonly tool_choice?: {
255
+ readonly type: "auto" | "none" | "any";
256
+ readonly disable_parallel_tool_use?: boolean | undefined;
257
+ } | {
258
+ readonly type: "tool";
259
+ readonly name: string;
260
+ readonly disable_parallel_tool_use?: boolean | undefined;
261
+ } | undefined;
262
+ readonly top_p?: number | undefined;
263
+ readonly top_k?: number | undefined;
264
+ readonly stop_sequences?: readonly string[] | undefined;
265
+ }, string, {
266
+ readonly type: string;
267
+ readonly message?: {
268
+ readonly usage?: {
269
+ readonly [x: string]: unknown;
270
+ readonly input_tokens?: number | null | undefined;
271
+ readonly server_tool_use?: {
272
+ readonly [x: string]: unknown;
273
+ readonly web_search_requests?: number | undefined;
274
+ } | null | undefined;
275
+ readonly output_tokens?: number | undefined;
276
+ readonly cache_creation_input_tokens?: number | null | undefined;
277
+ readonly cache_read_input_tokens?: number | null | undefined;
278
+ readonly output_tokens_details?: {
279
+ readonly [x: string]: unknown;
280
+ readonly thinking_tokens?: number | undefined;
281
+ } | null | undefined;
282
+ readonly iterations?: readonly {
283
+ readonly [x: string]: unknown;
284
+ readonly input_tokens?: number | null | undefined;
285
+ readonly server_tool_use?: {
286
+ readonly [x: string]: unknown;
287
+ readonly web_search_requests?: number | undefined;
288
+ } | null | undefined;
289
+ readonly output_tokens?: number | undefined;
290
+ readonly cache_creation_input_tokens?: number | null | undefined;
291
+ readonly cache_read_input_tokens?: number | null | undefined;
292
+ readonly output_tokens_details?: {
293
+ readonly [x: string]: unknown;
294
+ readonly thinking_tokens?: number | undefined;
295
+ } | null | undefined;
296
+ }[] | undefined;
297
+ } | undefined;
298
+ } | undefined;
299
+ readonly error?: {
300
+ readonly type?: string | undefined;
301
+ readonly message?: string | undefined;
302
+ } | undefined;
303
+ readonly delta?: unknown;
304
+ readonly index?: number | undefined;
305
+ readonly usage?: {
306
+ readonly [x: string]: unknown;
307
+ readonly input_tokens?: number | null | undefined;
308
+ readonly server_tool_use?: {
309
+ readonly [x: string]: unknown;
310
+ readonly web_search_requests?: number | undefined;
311
+ } | null | undefined;
312
+ readonly output_tokens?: number | undefined;
313
+ readonly cache_creation_input_tokens?: number | null | undefined;
314
+ readonly cache_read_input_tokens?: number | null | undefined;
315
+ readonly output_tokens_details?: {
316
+ readonly [x: string]: unknown;
317
+ readonly thinking_tokens?: number | undefined;
318
+ } | null | undefined;
319
+ readonly iterations?: readonly {
320
+ readonly [x: string]: unknown;
321
+ readonly input_tokens?: number | null | undefined;
322
+ readonly server_tool_use?: {
323
+ readonly [x: string]: unknown;
324
+ readonly web_search_requests?: number | undefined;
325
+ } | null | undefined;
326
+ readonly output_tokens?: number | undefined;
327
+ readonly cache_creation_input_tokens?: number | null | undefined;
328
+ readonly cache_read_input_tokens?: number | null | undefined;
329
+ readonly output_tokens_details?: {
330
+ readonly [x: string]: unknown;
331
+ readonly thinking_tokens?: number | undefined;
332
+ } | null | undefined;
333
+ }[] | undefined;
334
+ } | undefined;
335
+ readonly content_block?: unknown;
336
+ }, {
337
+ provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
338
+ compactions: {};
339
+ providerMetadataKey: string;
340
+ tools: Partial<Record<number, import("./utils/tool-stream.js").PendingTool>>;
341
+ reasoningSignatures: {};
342
+ lifecycle: import("./utils/lifecycle.js").State;
343
+ }>;
344
+ export * as ZAIMessages from "./zai-messages.js";
@@ -0,0 +1,27 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Protocol } from "../route/protocol.js";
3
+ import { LLMRequest } from "../schema/index.js";
4
+ import { AnthropicMessages } from "./anthropic-messages.js";
5
+ import { ProviderShared } from "./shared.js";
6
+ const Options = Schema.Struct({
7
+ effort: Schema.optional(Schema.String),
8
+ thinking: Schema.optional(Schema.Struct({ type: Schema.String })),
9
+ });
10
+ const Body = Schema.Struct({
11
+ ...AnthropicMessages.AnthropicMessagesBody.fields,
12
+ thinking: Options.fields.thinking,
13
+ });
14
+ const fromRequest = Effect.fn("ZAIMessages.fromRequest")(function* (request) {
15
+ const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
16
+ // Z.AI accepts enabled thinking without Anthropic's mandatory token budget.
17
+ const body = yield* AnthropicMessages.protocol.body.from(LLMRequest.update(request, {
18
+ providerOptions: { ...request.providerOptions, thinking: undefined },
19
+ }));
20
+ return { ...body, thinking: options.thinking };
21
+ });
22
+ export const protocol = Protocol.make({
23
+ id: "zai-messages",
24
+ body: { schema: Body, from: fromRequest },
25
+ stream: AnthropicMessages.protocol.stream,
26
+ });
27
+ export * as ZAIMessages from "./zai-messages.js";
@@ -0,0 +1 @@
1
+ export * from "./protocols/index.js";
@@ -0,0 +1 @@
1
+ export * from "./protocols/index.js";
@@ -0,0 +1,15 @@
1
+ import { AIError, type HttpContext, type HttpRateLimitDetails } from "./schema/index.js";
2
+ export declare const isContextOverflow: (message: string) => boolean;
3
+ export declare const isPayloadTooLarge: (message: string) => boolean;
4
+ export declare const isContextOverflowFailure: (failure: unknown) => boolean;
5
+ export interface ProviderFailure {
6
+ readonly message: string;
7
+ readonly status?: number | undefined;
8
+ readonly rawBody?: string | undefined;
9
+ readonly data?: unknown;
10
+ readonly http?: HttpContext | undefined;
11
+ readonly cause?: unknown;
12
+ readonly retryAfterMs?: number | undefined;
13
+ readonly rateLimit?: HttpRateLimitDetails | undefined;
14
+ }
15
+ export declare function classifyProviderFailure(input: ProviderFailure): AIError["reason"];
@@ -0,0 +1,125 @@
1
+ import { Option, Schema } from "effect";
2
+ import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderErrorEvent, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
3
+ const patterns = [
4
+ /prompt is too long/i,
5
+ /input is too long for requested model/i,
6
+ /exceeds the context window/i,
7
+ /exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,
8
+ /input token count.*exceeds the maximum/i,
9
+ /tokens in request more than max tokens allowed/i,
10
+ /maximum prompt length is \d+/i,
11
+ /reduce the length of the messages/i,
12
+ /maximum context length is \d+ tokens/i,
13
+ /exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
14
+ /input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
15
+ /exceeds the limit of \d+/i,
16
+ /exceeds the available context size/i,
17
+ /greater than the context length/i,
18
+ /context window exceeds limit/i,
19
+ /exceeded model token limit/i,
20
+ /context[_ ]length[_ ]exceeded/i,
21
+ /context length is only \d+ tokens/i,
22
+ /input length.*exceeds.*context length/i,
23
+ /prompt too long; exceeded (?:max )?context length/i,
24
+ /too large for model with \d+ maximum context length/i,
25
+ /prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,
26
+ /model_context_window_exceeded/i,
27
+ /range of input length should be/i,
28
+ /too many tokens/i,
29
+ /token limit exceeded/i,
30
+ /request_too_large/i,
31
+ ];
32
+ const payloadPatterns = [/request entity too large/i, /payload too large/i, /request too large/i];
33
+ const exclusions = [/^(throttling error|service unavailable):/i, /rate limit/i, /too many requests/i];
34
+ export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
35
+ (patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
36
+ export const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
37
+ export const isContextOverflowFailure = (failure) => failure instanceof AIError
38
+ ? failure.reason._tag === "InvalidRequest" && failure.reason.classification === "context-overflow"
39
+ : Schema.is(ProviderErrorEvent)(failure) && failure.classification === "context-overflow";
40
+ const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
41
+ const QUOTA_CODES = new Set(["insufficient_quota", "usage_not_included", "billing_error"]);
42
+ const AUTH_CODES = new Set(["authentication_error", "permission_error"]);
43
+ const SERVER_CODES = new Set([
44
+ "api_error",
45
+ "internal_error",
46
+ "internalserverexception",
47
+ "modelstreamerrorexception",
48
+ "overloaded_error",
49
+ "server_error",
50
+ "server_is_overloaded",
51
+ "slow_down",
52
+ "serviceunavailableexception",
53
+ ]);
54
+ const INVALID_REQUEST_CODES = new Set(["invalid_prompt", "invalid_request_error", "validationexception"]);
55
+ const RATE_LIMIT_TEXT = /rate increased too quickly|rate[-_\s]?limit|too[_\s]?many[_\s]?requests/i;
56
+ const QUOTA_TEXT = /insufficient[-_\s]?quota|quota[-_\s]?exceeded/i;
57
+ const CONTENT_POLICY_TEXT = /content[-_\s]?policy|content_filter|safety/i;
58
+ const SERVER_ERROR_TEXT = /\b(?:try again|(?:please |you can )?retry (?:the |this |your )?request|try (?:the |this |your )?request again|(?:currently |temporarily )?at capacity|overloaded|temporarily unavailable|service[-_\s]?unavailable|(?:server|internal)[-_\s]?error|server (?:is )?busy|provider returned (?:an )?error|resource[-_\s]?exhausted|upstream (?:connect|connection|request)|request buffer limit while retrying upstream)\b/i;
59
+ // Classification records affirmative evidence about a failure. Deterministic
60
+ // failures need positive identification (a 4xx status, quota/auth/policy
61
+ // signals); anything unrecognized stays UnknownProvider, which the session
62
+ // retry policy treats as retry-eligible because transient failures arrive in
63
+ // unpredictable shapes while deterministic rejections almost always carry a
64
+ // status or known code.
65
+ export function classifyProviderFailure(input) {
66
+ const details = { message: input.message, body: input.rawBody, http: input.http, cause: input.cause };
67
+ const body = input.rawBody ?? "";
68
+ const codes = [...providerCodes(input.data), ...providerCodes(body), ...providerCodes(input.message)].map((code) => code.toLowerCase());
69
+ // Scan the raw payload too so signals missing from the summary message
70
+ // (e.g. overflow phrases nested in a JSON error body) still classify.
71
+ const text = [input.message, body].filter((value) => value.length > 0).join("\n");
72
+ const clientScoped = input.status === undefined || (input.status >= 400 && input.status < 500);
73
+ if (clientScoped &&
74
+ (codes.includes("context_length_exceeded") ||
75
+ codes.includes("model_context_window_exceeded") ||
76
+ codes.includes("request_too_large") ||
77
+ isContextOverflow(text)))
78
+ return new InvalidRequestError({ ...details, classification: "context-overflow" });
79
+ if (input.status === 413 || isPayloadTooLarge(text))
80
+ return new InvalidRequestError({ ...details, classification: "payload-too-large" });
81
+ if (CONTENT_POLICY_TEXT.test(text))
82
+ return new ContentPolicyError(details);
83
+ if (codes.some((code) => QUOTA_CODES.has(code)) || (input.status === 429 && QUOTA_TEXT.test(text)))
84
+ return new QuotaExceededError(details);
85
+ if (input.status === 401 || input.status === 403 || codes.some((code) => AUTH_CODES.has(code)))
86
+ return new AuthenticationError(details);
87
+ if (input.status === 429 ||
88
+ codes.some((code) => code.includes("rate_limit") || code === "too_many_requests" || code === "throttlingexception") ||
89
+ RATE_LIMIT_TEXT.test(text))
90
+ return new RateLimitError({
91
+ ...details,
92
+ retryAfterMs: input.retryAfterMs,
93
+ rateLimit: input.rateLimit,
94
+ });
95
+ if (input.status === 408 ||
96
+ input.status === 409 ||
97
+ (input.status !== undefined && input.status >= 500) ||
98
+ ((input.status === undefined || input.status < 400) &&
99
+ !codes.some((code) => INVALID_REQUEST_CODES.has(code)) &&
100
+ SERVER_ERROR_TEXT.test(text)) ||
101
+ codes.some((code) => SERVER_CODES.has(code) || code.includes("exhausted") || code.includes("unavailable")))
102
+ return new ProviderInternalError({
103
+ ...details,
104
+ retryAfterMs: input.retryAfterMs,
105
+ });
106
+ if (codes.some((code) => INVALID_REQUEST_CODES.has(code)))
107
+ return new InvalidRequestError(details);
108
+ // Any remaining 4xx is a deterministic rejection of this request.
109
+ if (input.status !== undefined && input.status >= 400 && input.status < 500)
110
+ return new InvalidRequestError(details);
111
+ return new UnknownProviderError(details);
112
+ }
113
+ function providerCodes(value) {
114
+ const decoded = typeof value === "string" ? Option.getOrUndefined(decodeJson(value)) : value;
115
+ if (!isRecord(decoded))
116
+ return [];
117
+ const error = isRecord(decoded.error) ? decoded.error : undefined;
118
+ const response = isRecord(decoded.response) ? decoded.response : undefined;
119
+ const responseError = response && isRecord(response.error) ? response.error : undefined;
120
+ const exception = isRecord(decoded.exception) ? decoded.exception : undefined;
121
+ return [decoded.code, error?.code, error?.type, error?.status, responseError?.code, exception?.type].filter((value) => typeof value === "string");
122
+ }
123
+ function isRecord(value) {
124
+ return typeof value === "object" && value !== null;
125
+ }
@@ -0,0 +1,15 @@
1
+ import type { LanguageModel, ProviderOptions } from "./schema/index.js";
2
+ import type { CompactionOperations } from "./route/client.js";
3
+ /**
4
+ * Flat, serializable settings for `model(modelID, settings)`. Each entrypoint declares the connection keys it
5
+ * reads; every other key is a request option for the route's protocol.
6
+ */
7
+ export interface Settings extends Readonly<Record<string, unknown>> {
8
+ readonly baseURL?: string;
9
+ readonly headers?: Readonly<Record<string, string>>;
10
+ readonly body?: Readonly<Record<string, unknown>>;
11
+ }
12
+ export interface Definition<ProviderSettings extends Settings = Settings, Options extends ProviderOptions = ProviderOptions, Compact extends CompactionOperations | undefined = CompactionOperations | undefined> {
13
+ readonly model: (modelID: string, settings: ProviderSettings) => LanguageModel<Options, Compact>;
14
+ }
15
+ export * as ProviderPackage from "./provider-package.js";
@@ -0,0 +1 @@
1
+ export * as ProviderPackage from "./provider-package.js";
@@ -0,0 +1,23 @@
1
+ import type { LanguageModel, ModelID, ProviderID } from "./schema/index.js";
2
+ export type LanguageModelOptions = Pick<LanguageModel.Input, "defaults" | "compatibility">;
3
+ /**
4
+ * Advanced structural provider definition helper. Built-in providers should
5
+ * prefer explicit `configure(options).model(id)` facades so deployment config is
6
+ * chosen before model selection. The optional `apis` map remains for external
7
+ * structural providers that expose multiple route selectors behind one provider.
8
+ */
9
+ export type LanguageModelFactory<Options extends LanguageModelOptions = LanguageModelOptions> = (id: string | ModelID, options?: Options) => LanguageModel;
10
+ type AnyLanguageModelFactory = (...args: never[]) => LanguageModel;
11
+ export interface Definition<Factory extends AnyLanguageModelFactory = LanguageModelFactory> {
12
+ readonly id: ProviderID;
13
+ readonly model: Factory;
14
+ readonly apis?: Record<string, AnyLanguageModelFactory>;
15
+ }
16
+ type DefinitionShape = {
17
+ readonly id: ProviderID;
18
+ readonly model: (...args: never[]) => LanguageModel;
19
+ readonly apis?: Record<string, (...args: never[]) => LanguageModel>;
20
+ };
21
+ type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>;
22
+ export declare const make: <DefinitionType extends DefinitionShape>(definition: NoExtraFields<DefinitionType, DefinitionShape>) => NoExtraFields<DefinitionType, DefinitionShape>;
23
+ export * as Provider from "./provider.js";
@@ -0,0 +1,2 @@
1
+ export const make = (definition) => definition;
2
+ export * as Provider from "./provider.js";
@@ -0,0 +1 @@
1
+ export { model, type Settings } from "../alibaba.js";
@@ -0,0 +1 @@
1
+ export { model } from "../alibaba.js";
@@ -0,0 +1,3 @@
1
+ import type { Alibaba } from "../alibaba.js";
2
+ export { messagesModel as model } from "../alibaba.js";
3
+ export type Settings = Alibaba.Settings<Alibaba.MessagesOptionsInput>;
@@ -0,0 +1 @@
1
+ export { messagesModel as model } from "../alibaba.js";
@@ -0,0 +1,3 @@
1
+ import type { Alibaba } from "../alibaba.js";
2
+ export { responsesModel as model } from "../alibaba.js";
3
+ export type Settings = Alibaba.Settings<Alibaba.ResponsesOptionsInput>;
@@ -0,0 +1 @@
1
+ export { responsesModel as model } from "../alibaba.js";