@opencode/ai 2.1.3 → 2.2.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 +283 -114
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/cache-policy.d.ts +4 -0
  5. package/dist/cache-policy.js +20 -6
  6. package/dist/decision-client.d.ts +21 -0
  7. package/dist/decision-client.js +55 -0
  8. package/dist/decision.d.ts +472 -0
  9. package/dist/decision.js +158 -0
  10. package/dist/effect.d.ts +38 -0
  11. package/dist/effect.js +27 -0
  12. package/dist/effort-updates.d.ts +2 -2
  13. package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
  14. package/dist/experimental/cloudflare-run-extraction.js +83 -0
  15. package/dist/experimental/extraction.d.ts +183 -0
  16. package/dist/experimental/extraction.js +102 -0
  17. package/dist/experimental/realtime.d.ts +7 -2
  18. package/dist/experimental/realtime.js +5 -5
  19. package/dist/experimental.d.ts +2 -3
  20. package/dist/experimental.js +1 -2
  21. package/dist/image-client.d.ts +13 -22
  22. package/dist/image-client.js +0 -1
  23. package/dist/image.d.ts +154 -324
  24. package/dist/image.js +4 -11
  25. package/dist/index.d.ts +1426 -34
  26. package/dist/index.js +127 -24
  27. package/dist/llm.d.ts +16 -1
  28. package/dist/llm.js +34 -0
  29. package/dist/media-client.d.ts +2 -1
  30. package/dist/media-model.d.ts +3 -0
  31. package/dist/media-model.js +4 -1
  32. package/dist/media.d.ts +0 -7
  33. package/dist/media.js +0 -6
  34. package/dist/protocols/alibaba-chat.d.ts +32 -12
  35. package/dist/protocols/alibaba-images.d.ts +22 -0
  36. package/dist/protocols/alibaba-images.js +77 -0
  37. package/dist/protocols/alibaba-messages.d.ts +62 -27
  38. package/dist/protocols/alibaba-responses.d.ts +41 -38
  39. package/dist/protocols/anthropic-messages.d.ts +196 -94
  40. package/dist/protocols/anthropic-messages.js +47 -16
  41. package/dist/protocols/bedrock-converse.d.ts +140 -47
  42. package/dist/protocols/bedrock-converse.js +114 -18
  43. package/dist/protocols/bedrock-event-stream.js +1 -0
  44. package/dist/protocols/bfl-images.d.ts +9 -0
  45. package/dist/protocols/bfl-images.js +17 -15
  46. package/dist/protocols/cartesia-speech.d.ts +32 -50
  47. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  48. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  49. package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
  50. package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
  51. package/dist/protocols/cohere-chat.d.ts +7 -8
  52. package/dist/protocols/deepgram-speech.d.ts +32 -50
  53. package/dist/protocols/elevenlabs-speech.d.ts +32 -50
  54. package/dist/protocols/fal-images.d.ts +10 -1
  55. package/dist/protocols/fal-images.js +16 -25
  56. package/dist/protocols/fal-video.js +1 -1
  57. package/dist/protocols/gemini.d.ts +37 -34
  58. package/dist/protocols/gemini.js +13 -8
  59. package/dist/protocols/google-images.d.ts +2 -2
  60. package/dist/protocols/google-images.js +8 -37
  61. package/dist/protocols/google-interactions.d.ts +18 -14
  62. package/dist/protocols/google-interactions.js +14 -7
  63. package/dist/protocols/google-speech.d.ts +32 -50
  64. package/dist/protocols/google-speech.js +0 -1
  65. package/dist/protocols/google-transcription.d.ts +32 -50
  66. package/dist/protocols/google-transcription.js +0 -1
  67. package/dist/protocols/google-video.d.ts +1 -1
  68. package/dist/protocols/google-video.js +2 -7
  69. package/dist/protocols/index.d.ts +3 -0
  70. package/dist/protocols/index.js +3 -0
  71. package/dist/protocols/meta-images.d.ts +7 -1
  72. package/dist/protocols/meta-images.js +10 -8
  73. package/dist/protocols/meta-messages.d.ts +73 -38
  74. package/dist/protocols/meta-messages.js +14 -1
  75. package/dist/protocols/meta-responses.d.ts +84 -78
  76. package/dist/protocols/meta-responses.js +29 -1
  77. package/dist/protocols/mistral-chat.d.ts +81 -78
  78. package/dist/protocols/mistral-chat.js +2 -1
  79. package/dist/protocols/open-responses-channel.js +47 -46
  80. package/dist/protocols/open-responses-continuation.d.ts +8 -2
  81. package/dist/protocols/open-responses-continuation.js +3 -1
  82. package/dist/protocols/open-responses.d.ts +426 -396
  83. package/dist/protocols/open-responses.js +16 -25
  84. package/dist/protocols/openai-chat.d.ts +764 -52
  85. package/dist/protocols/openai-chat.js +38 -25
  86. package/dist/protocols/openai-compatible-chat.d.ts +35 -15
  87. package/dist/protocols/openai-compatible-responses.d.ts +44 -42
  88. package/dist/protocols/openai-decisions.d.ts +22 -0
  89. package/dist/protocols/openai-decisions.js +128 -0
  90. package/dist/protocols/openai-images.d.ts +53 -56
  91. package/dist/protocols/openai-images.js +100 -34
  92. package/dist/protocols/openai-responses.d.ts +322 -264
  93. package/dist/protocols/openai-responses.js +33 -3
  94. package/dist/protocols/openai-speech.d.ts +32 -50
  95. package/dist/protocols/openai-speech.js +15 -5
  96. package/dist/protocols/openai-transcription.d.ts +32 -50
  97. package/dist/protocols/openai-transcription.js +15 -11
  98. package/dist/protocols/replicate-images.js +1 -1
  99. package/dist/protocols/runway-video.d.ts +1 -1
  100. package/dist/protocols/runway-video.js +1 -1
  101. package/dist/protocols/shared.d.ts +9 -1
  102. package/dist/protocols/shared.js +13 -2
  103. package/dist/protocols/stability-images.d.ts +5 -0
  104. package/dist/protocols/stability-images.js +4 -9
  105. package/dist/protocols/system-one.d.ts +101 -0
  106. package/dist/protocols/system-one.js +230 -0
  107. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  108. package/dist/protocols/utils/bedrock-cache.js +7 -6
  109. package/dist/protocols/utils/cache.d.ts +14 -3
  110. package/dist/protocols/utils/cache.js +11 -4
  111. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  112. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  113. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  114. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  115. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  116. package/dist/protocols/utils/image-sizing.js +73 -0
  117. package/dist/protocols/utils/media-input.d.ts +4 -5
  118. package/dist/protocols/utils/media-input.js +8 -5
  119. package/dist/protocols/utils/partial-json-options.d.ts +0 -1
  120. package/dist/protocols/utils/partial-json-options.js +0 -1
  121. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  122. package/dist/protocols/utils/speech-stream.js +0 -1
  123. package/dist/protocols/utils/tool-schema.js +15 -5
  124. package/dist/protocols/utils/tool-stream.d.ts +10 -1
  125. package/dist/protocols/venice-chat.d.ts +71 -53
  126. package/dist/protocols/venice-chat.js +7 -6
  127. package/dist/protocols/xai-images.d.ts +1 -2
  128. package/dist/protocols/xai-images.js +9 -2
  129. package/dist/protocols/xai-responses.d.ts +88 -78
  130. package/dist/protocols/xai-responses.js +28 -2
  131. package/dist/protocols/xai-video.d.ts +1 -1
  132. package/dist/protocols/xai-video.js +11 -8
  133. package/dist/protocols/zai-chat.d.ts +54 -30
  134. package/dist/protocols/zai-chat.js +8 -3
  135. package/dist/protocols/zai-images.d.ts +3 -1
  136. package/dist/protocols/zai-images.js +12 -11
  137. package/dist/protocols/zai-messages.d.ts +72 -35
  138. package/dist/protocols/zai-messages.js +3 -2
  139. package/dist/provider-error.js +24 -7
  140. package/dist/providers/alibaba/images.d.ts +2 -0
  141. package/dist/providers/alibaba/images.js +1 -0
  142. package/dist/providers/alibaba.d.ts +146 -85
  143. package/dist/providers/alibaba.js +16 -8
  144. package/dist/providers/amazon-bedrock-mantle.d.ts +277 -218
  145. package/dist/providers/amazon-bedrock.d.ts +48 -28
  146. package/dist/providers/amazon-bedrock.js +11 -11
  147. package/dist/providers/anthropic-compatible.d.ts +64 -29
  148. package/dist/providers/anthropic.d.ts +64 -29
  149. package/dist/providers/azure/images.d.ts +2 -0
  150. package/dist/providers/azure/images.js +1 -0
  151. package/dist/providers/azure.d.ts +156 -115
  152. package/dist/providers/azure.js +19 -1
  153. package/dist/providers/baseten/decisions.d.ts +2 -0
  154. package/dist/providers/baseten/decisions.js +1 -0
  155. package/dist/providers/baseten.d.ts +75 -25
  156. package/dist/providers/baseten.js +41 -8
  157. package/dist/providers/cerebras.d.ts +66 -24
  158. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  159. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  160. package/dist/providers/cloudflare-ai-gateway.d.ts +409 -272
  161. package/dist/providers/cloudflare-ai-gateway.js +33 -6
  162. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  163. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  164. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  165. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  166. package/dist/providers/cloudflare-workers-ai.d.ts +79 -25
  167. package/dist/providers/cloudflare-workers-ai.js +45 -9
  168. package/dist/providers/cohere.d.ts +117 -75
  169. package/dist/providers/deepinfra.d.ts +66 -24
  170. package/dist/providers/deepseek.d.ts +66 -24
  171. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  172. package/dist/providers/digitalocean/decisions.js +1 -0
  173. package/dist/providers/digitalocean/images.d.ts +2 -0
  174. package/dist/providers/digitalocean/images.js +1 -0
  175. package/dist/providers/digitalocean.d.ts +108 -37
  176. package/dist/providers/digitalocean.js +39 -8
  177. package/dist/providers/fireworks.d.ts +66 -24
  178. package/dist/providers/google/images.d.ts +2 -0
  179. package/dist/providers/google/images.js +1 -0
  180. package/dist/providers/google-vertex/images.d.ts +2 -0
  181. package/dist/providers/google-vertex/images.js +1 -0
  182. package/dist/providers/google-vertex-chat.d.ts +33 -12
  183. package/dist/providers/google-vertex-messages.d.ts +64 -29
  184. package/dist/providers/google-vertex-mistral.d.ts +17 -17
  185. package/dist/providers/google-vertex-responses.d.ts +38 -35
  186. package/dist/providers/google-vertex.d.ts +20 -18
  187. package/dist/providers/google-vertex.js +32 -15
  188. package/dist/providers/google.d.ts +22 -21
  189. package/dist/providers/google.js +15 -8
  190. package/dist/providers/groq.d.ts +66 -28
  191. package/dist/providers/groq.js +0 -6
  192. package/dist/providers/meta.d.ts +144 -85
  193. package/dist/providers/minimax.d.ts +145 -86
  194. package/dist/providers/mistral.d.ts +28 -28
  195. package/dist/providers/moonshot.d.ts +277 -218
  196. package/dist/providers/open-responses-options.d.ts +0 -1
  197. package/dist/providers/open-responses-options.js +1 -1
  198. package/dist/providers/openai/images.d.ts +2 -0
  199. package/dist/providers/openai/images.js +1 -0
  200. package/dist/providers/openai-compatible/images.d.ts +2 -0
  201. package/dist/providers/openai-compatible/images.js +1 -0
  202. package/dist/providers/openai-compatible-responses.d.ts +38 -35
  203. package/dist/providers/openai-compatible.d.ts +36 -13
  204. package/dist/providers/openai-compatible.js +22 -10
  205. package/dist/providers/openai-options.d.ts +3 -2
  206. package/dist/providers/openai-options.js +0 -1
  207. package/dist/providers/openai.d.ts +146 -109
  208. package/dist/providers/openai.js +20 -4
  209. package/dist/providers/opencode/decisions.d.ts +2 -0
  210. package/dist/providers/opencode/decisions.js +1 -0
  211. package/dist/providers/opencode.d.ts +9 -10
  212. package/dist/providers/opencode.js +10 -8
  213. package/dist/providers/openrouter/decisions.d.ts +2 -0
  214. package/dist/providers/openrouter/decisions.js +1 -0
  215. package/dist/providers/openrouter/images.d.ts +2 -0
  216. package/dist/providers/openrouter/images.js +1 -0
  217. package/dist/providers/openrouter.d.ts +128 -47
  218. package/dist/providers/openrouter.js +38 -16
  219. package/dist/providers/togetherai.d.ts +66 -24
  220. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  221. package/dist/providers/typesafe-ai/decisions.js +1 -0
  222. package/dist/providers/typesafe-ai.d.ts +9 -10
  223. package/dist/providers/typesafe-ai.js +10 -8
  224. package/dist/providers/venice.d.ts +214 -20
  225. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  226. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  227. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  228. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  229. package/dist/providers/vercel-ai-gateway.d.ts +10 -16
  230. package/dist/providers/vercel-ai-gateway.js +31 -85
  231. package/dist/providers/xai/images.d.ts +2 -0
  232. package/dist/providers/xai/images.js +1 -0
  233. package/dist/providers/xai.d.ts +40 -17
  234. package/dist/providers/xai.js +15 -8
  235. package/dist/providers/zai/images.d.ts +2 -0
  236. package/dist/providers/zai/images.js +1 -0
  237. package/dist/providers/zai-coding-plan.d.ts +224 -85
  238. package/dist/providers/zai.d.ts +110 -23
  239. package/dist/providers/zai.js +15 -8
  240. package/dist/route/auth-options.d.ts +0 -3
  241. package/dist/route/auth.d.ts +0 -2
  242. package/dist/route/auth.js +0 -2
  243. package/dist/route/client.d.ts +2 -4
  244. package/dist/route/client.js +29 -8
  245. package/dist/route/decision.d.ts +58 -0
  246. package/dist/route/decision.js +75 -0
  247. package/dist/route/executor-service.js +1 -1
  248. package/dist/route/executor.d.ts +1 -1
  249. package/dist/route/framing.d.ts +2 -0
  250. package/dist/route/index.d.ts +3 -0
  251. package/dist/route/index.js +3 -0
  252. package/dist/route/media-protocol.d.ts +1 -0
  253. package/dist/route/media-protocol.js +12 -8
  254. package/dist/route/media.d.ts +5 -1
  255. package/dist/route/media.js +6 -2
  256. package/dist/route/transport/http.js +1 -0
  257. package/dist/route/transport/index.d.ts +1 -0
  258. package/dist/schema/events.d.ts +148 -6
  259. package/dist/schema/events.js +20 -0
  260. package/dist/schema/messages.d.ts +6 -2
  261. package/dist/schema/messages.js +3 -0
  262. package/dist/schema/options.d.ts +5 -3
  263. package/dist/schema/options.js +8 -3
  264. package/dist/speech-client.d.ts +13 -22
  265. package/dist/speech-client.js +0 -1
  266. package/dist/speech.d.ts +148 -283
  267. package/dist/speech.js +2 -4
  268. package/dist/testing.d.ts +25 -24
  269. package/dist/testing.js +3 -21
  270. package/dist/transcription-client.d.ts +13 -22
  271. package/dist/transcription.d.ts +148 -283
  272. package/dist/transcription.js +1 -1
  273. package/dist/utils/media-type.js +22 -1
  274. package/dist/video-client.d.ts +13 -22
  275. package/dist/video-client.js +0 -1
  276. package/dist/video.d.ts +115 -250
  277. package/dist/video.js +3 -5
  278. package/package.json +516 -13
  279. package/dist/experimental/evaluation-client.d.ts +0 -21
  280. package/dist/experimental/evaluation-client.js +0 -64
  281. package/dist/experimental/evaluation.d.ts +0 -242
  282. package/dist/experimental/evaluation.js +0 -115
  283. package/dist/experimental/system-one.d.ts +0 -16
  284. package/dist/experimental/system-one.js +0 -135
  285. package/dist/promise.d.ts +0 -1021
  286. package/dist/promise.js +0 -101
  287. package/dist/provider.d.ts +0 -23
  288. package/dist/provider.js +0 -2
@@ -21,9 +21,26 @@ const XAIResponsesHostedToolItem = Schema.Union([
21
21
  error: Schema.optional(Schema.Unknown),
22
22
  }), [JsonObject]),
23
23
  ]);
24
+ const Options = Schema.Struct({
25
+ minP: Schema.optional(Schema.Number),
26
+ });
27
+ const Body = Schema.Struct({
28
+ ...OpenResponses.OpenResponsesBody.fields,
29
+ top_k: Schema.optional(Schema.Number),
30
+ min_p: Schema.optional(Schema.Number),
31
+ });
24
32
  const adapter = {
25
33
  id: ADAPTER,
26
34
  name: NAME,
35
+ lowerMedia: ({ part, media }) => {
36
+ if (part.media.kind !== "video")
37
+ return undefined;
38
+ const filename = part.filename ?? "file";
39
+ const url = ProviderShared.mediaUrl(part.media);
40
+ if (url)
41
+ return { type: "input_file", filename, file_url: url };
42
+ return media && { type: "input_file", filename, file_data: media.dataUrl };
43
+ },
27
44
  restoreHostedToolItem: (item) => (Schema.is(XAIResponsesHostedToolItem)(item) ? item : undefined),
28
45
  };
29
46
  const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
@@ -34,7 +51,16 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
34
51
  route: request.model.route.id,
35
52
  message: "xAI requires explicit compaction through LLMClient.compact; automatic context management is not supported",
36
53
  });
37
- return yield* OpenResponses.fromRequestWithAdapter(request, adapter);
54
+ const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
55
+ const body = yield* OpenResponses.fromRequestWithAdapter(request, adapter);
56
+ // xAI Responses does not support penalties (they are ignored), but does support top_k.
57
+ return {
58
+ ...body,
59
+ presence_penalty: undefined,
60
+ frequency_penalty: undefined,
61
+ top_k: request.generation?.topK,
62
+ min_p: options.minP,
63
+ };
38
64
  });
39
65
  const HOSTED_TOOLS = {
40
66
  web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
@@ -61,7 +87,7 @@ const step = (state, input) => {
61
87
  export const protocol = Protocol.make({
62
88
  id: ADAPTER,
63
89
  body: {
64
- schema: OpenResponses.OpenResponsesBody,
90
+ schema: Body,
65
91
  from: fromRequest,
66
92
  },
67
93
  stream: {
@@ -8,7 +8,7 @@ export declare const EDIT_PATH = "/videos/edits";
8
8
  export declare const EXTEND_PATH = "/videos/extensions";
9
9
  export declare const STATUS_PATH = "/videos";
10
10
  /**
11
- * Provider-native options. Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspectRatio`,
11
+ * Provider-native options. Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspect`,
12
12
  * `resolution`, `audio`) live on the request. `mode` selects the endpoint a `video` input is sent to.
13
13
  */
14
14
  export type XAIVideoOptions = {
@@ -65,7 +65,7 @@ const fromRequest = Effect.fn("XAIVideo.fromRequest")(function* (request) {
65
65
  reference_images: references.length === 0 ? undefined : references,
66
66
  video,
67
67
  duration: request.durationSeconds,
68
- aspect_ratio: request.aspectRatio,
68
+ aspect_ratio: request.aspect,
69
69
  resolution: request.resolution,
70
70
  generate_audio: request.audio,
71
71
  }, nativeOptions(request.providerOptions), request.http?.body) ?? {});
@@ -98,12 +98,10 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
98
98
  }
99
99
  if (status !== "completed")
100
100
  return yield* output.ended("expired", `${route.name} request ${context.token.requestID} expired`);
101
- // `respect_moderation: false` marks a filtered result; a URL may still be present, so report it as a notice.
102
- const notices = decoded.video?.respect_moderation === false
103
- ? [{ type: "moderated", message: `${route.name} flagged the generated video for moderation` }]
104
- : undefined;
101
+ // `respect_moderation: false` marks a filtered result; a URL may still be present, so only a missing one fails.
102
+ const moderated = decoded.video?.respect_moderation === false;
105
103
  const url = decoded.video?.url ?? undefined;
106
- if (url === undefined && notices !== undefined)
104
+ if (url === undefined && moderated)
107
105
  return yield* output.contentPolicy(`${route.name} withheld the video for moderation`);
108
106
  if (url === undefined)
109
107
  return yield* output.invalid(`${route.name} completed without a video URL`);
@@ -115,8 +113,13 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
115
113
  info: duration === undefined ? undefined : { durationSeconds: duration },
116
114
  }),
117
115
  ],
118
- notices,
119
- providerMetadata: { xai: { requestId: context.token.requestID, model: decoded.model ?? undefined } },
116
+ providerMetadata: {
117
+ xai: {
118
+ requestId: context.token.requestID,
119
+ model: decoded.model ?? undefined,
120
+ respectModeration: decoded.video?.respect_moderation ?? undefined,
121
+ },
122
+ },
120
123
  });
121
124
  });
122
125
  // ---------------------------------------------------------------------------
@@ -1,21 +1,24 @@
1
+ import { Schema } from "effect";
1
2
  import { Protocol } from "../route/protocol.js";
2
3
  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 & {});
4
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
5
+ export type ReasoningEffort = OpenResponsesOptions.ReasoningEffort;
6
+ declare const Options: Schema.Struct<{
7
+ readonly reasoningEffort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
8
+ readonly thinking: Schema.optional<Schema.Struct<{
9
+ readonly type: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled">, import("../schema/options.js").OpenString<"disabled" | "enabled">>>;
8
10
  /** 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
- };
11
+ readonly clear_thinking: Schema.optional<Schema.Boolean>;
12
+ }>>;
13
+ readonly toolStream: Schema.optional<Schema.Boolean>;
14
+ readonly doSample: Schema.optional<Schema.Boolean>;
15
+ readonly responseFormat: Schema.optional<Schema.Struct<{
16
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_object" | "text">, import("../schema/options.js").OpenString<"json_object" | "text">>;
17
+ }>>;
18
+ readonly requestID: Schema.optional<Schema.String>;
19
+ readonly userID: Schema.optional<Schema.String>;
20
+ }>;
21
+ export type OptionsInput = typeof Options.Type;
19
22
  export declare const compatibility: {
20
23
  maxTokensField: "max_tokens";
21
24
  supportsStrictMode: false;
@@ -27,44 +30,54 @@ export declare const protocol: Protocol<{
27
30
  readonly messages: readonly ({
28
31
  readonly role: "system";
29
32
  readonly content: string | readonly ({
30
- readonly type: "text";
31
- readonly text: string;
32
- readonly cache_control?: {
33
- readonly type: "ephemeral";
34
- readonly ttl?: string | undefined;
35
- } | undefined;
36
- } | {
37
33
  readonly type: "image_url";
38
34
  readonly image_url: {
39
35
  readonly url: string;
40
36
  };
37
+ } | {
38
+ readonly type: "video_url";
39
+ readonly video_url: {
40
+ readonly url: string;
41
+ };
41
42
  } | {
42
43
  readonly type: "file";
43
44
  readonly file: {
44
45
  readonly filename: string;
45
46
  readonly file_data: string;
46
47
  };
47
- })[];
48
- } | {
49
- readonly role: "user";
50
- readonly content: string | readonly ({
48
+ } | {
51
49
  readonly type: "text";
52
50
  readonly text: string;
53
51
  readonly cache_control?: {
54
52
  readonly type: "ephemeral";
55
53
  readonly ttl?: string | undefined;
56
54
  } | undefined;
57
- } | {
55
+ })[];
56
+ } | {
57
+ readonly role: "user";
58
+ readonly content: string | readonly ({
58
59
  readonly type: "image_url";
59
60
  readonly image_url: {
60
61
  readonly url: string;
61
62
  };
63
+ } | {
64
+ readonly type: "video_url";
65
+ readonly video_url: {
66
+ readonly url: string;
67
+ };
62
68
  } | {
63
69
  readonly type: "file";
64
70
  readonly file: {
65
71
  readonly filename: string;
66
72
  readonly file_data: string;
67
73
  };
74
+ } | {
75
+ readonly type: "text";
76
+ readonly text: string;
77
+ readonly cache_control?: {
78
+ readonly type: "ephemeral";
79
+ readonly ttl?: string | undefined;
80
+ } | undefined;
68
81
  })[];
69
82
  } | {
70
83
  readonly role: "tool";
@@ -133,7 +146,18 @@ export declare const protocol: Protocol<{
133
146
  } | undefined;
134
147
  readonly store?: boolean | undefined;
135
148
  readonly prompt_cache_key?: string | undefined;
136
- readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
149
+ readonly prompt_cache_retention?: string | undefined;
150
+ readonly prompt_cache_options?: {
151
+ readonly ttl?: string | undefined;
152
+ } | undefined;
153
+ readonly reasoning_effort?: OpenResponsesOptions.ReasoningEffort | undefined;
154
+ readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
155
+ readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
156
+ readonly parallel_tool_calls?: boolean | undefined;
157
+ readonly metadata?: {
158
+ readonly [x: string]: string;
159
+ } | undefined;
160
+ readonly safety_identifier?: string | undefined;
137
161
  readonly tool_stream?: boolean | undefined;
138
162
  readonly max_completion_tokens?: number | undefined;
139
163
  readonly max_tokens?: number | undefined;
@@ -144,12 +168,12 @@ export declare const protocol: Protocol<{
144
168
  readonly seed?: number | undefined;
145
169
  readonly stop?: readonly string[] | undefined;
146
170
  readonly thinking?: {
147
- readonly type?: string | undefined;
171
+ readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
148
172
  readonly clear_thinking?: boolean | undefined;
149
173
  } | undefined;
150
174
  readonly do_sample?: boolean | undefined;
151
175
  readonly response_format?: {
152
- readonly type: string;
176
+ readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
153
177
  } | undefined;
154
178
  readonly request_id?: string | undefined;
155
179
  readonly user_id?: string | undefined;
@@ -2,12 +2,17 @@ import { Effect, Schema } from "effect";
2
2
  import { Protocol } from "../route/protocol.js";
3
3
  import { OpenAIChat } from "./openai-chat.js";
4
4
  import { ProviderShared } from "./shared.js";
5
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
5
6
  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) })),
7
+ reasoningEffort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
8
+ thinking: Schema.optional(Schema.Struct({
9
+ type: Schema.optional(ProviderShared.knownString()),
10
+ /** False retains historical reasoning; omission preserves the endpoint's default. */
11
+ clear_thinking: Schema.optional(Schema.Boolean),
12
+ })),
8
13
  toolStream: Schema.optional(Schema.Boolean),
9
14
  doSample: Schema.optional(Schema.Boolean),
10
- responseFormat: Schema.optional(Schema.Struct({ type: Schema.String })),
15
+ responseFormat: Schema.optional(Schema.Struct({ type: ProviderShared.knownString() })),
11
16
  requestID: Schema.optional(Schema.String),
12
17
  userID: Schema.optional(Schema.String),
13
18
  });
@@ -4,8 +4,10 @@ import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
5
5
  export declare const DEFAULT_BASE_URL = "https://api.z.ai/api/paas/v4";
6
6
  export declare const PATH = "/images/generations";
7
- /** Provider-native options. The common `size` field lives on the request. */
7
+ /** Provider-native options. Common `aspect` and `resolution` lower to `size`. */
8
8
  export type ZAIImageOptions = {
9
+ /** Exact `WIDTHxHEIGHT`; it wins over `aspect` and `resolution`. */
10
+ readonly size?: string;
9
11
  readonly quality?: OpenString<"hd" | "standard">;
10
12
  readonly userID?: string;
11
13
  } & Record<string, unknown>;
@@ -3,6 +3,7 @@ import { ImageModel, ImageResponse } from "../image.js";
3
3
  import { MediaProtocol } from "../route/media-protocol.js";
4
4
  import { MediaRoute } from "../route/media.js";
5
5
  import { mergeJsonRecords } from "../schema/index.js";
6
+ import { ImageSizing } from "./utils/image-sizing.js";
6
7
  const route = MediaProtocol.identity({ id: "zai-images", name: "Z.ai Images", provider: "zai" });
7
8
  export const DEFAULT_BASE_URL = "https://api.z.ai/api/paas/v4";
8
9
  export const PATH = "/images/generations";
@@ -29,8 +30,17 @@ const nativeOptions = (options) => {
29
30
  const { userID, ...native } = options;
30
31
  return { user_id: userID, ...native };
31
32
  };
33
+ /** GLM-Image takes 1024–2048 px edges in steps of 32; CogView takes 512–2048 px in steps of 16. */
34
+ const limits = (model) => model.startsWith("glm-image")
35
+ ? { multiple: 32, minEdge: 1024, maxEdge: 2048, maxPixels: 2 ** 22 }
36
+ : { multiple: 16, minEdge: 512, maxEdge: 2048, maxPixels: 2 ** 21 };
32
37
  const fromRequest = Effect.fn("ZAIImages.fromRequest")(function* (request) {
33
- return MediaProtocol.json(mergeJsonRecords({ model: request.model.id, prompt: request.prompt, size: request.size }, nativeOptions(request.providerOptions), request.http?.body) ?? {});
38
+ const size = yield* ImageSizing.exact(route, request, limits(request.model.id));
39
+ return MediaProtocol.json(mergeJsonRecords({
40
+ model: request.model.id,
41
+ prompt: request.prompt,
42
+ size: size === undefined ? undefined : `${size.width}x${size.height}`,
43
+ }, nativeOptions(request.providerOptions), request.http?.body) ?? {});
34
44
  });
35
45
  // ---------------------------------------------------------------------------
36
46
  // 6. Response decoding
@@ -41,18 +51,9 @@ const decodeResponse = Effect.fn("ZAIImages.decodeResponse")(function* (response
41
51
  const decoded = output.value;
42
52
  if (decoded.data.length === 0)
43
53
  return yield* output.invalid(`${route.name} returned no images`);
44
- const filters = decoded.content_filter ?? [];
45
54
  return new ImageResponse({
46
55
  // Z.ai returns only URLs and no content type; the media type resolves when the asset is materialized.
47
56
  images: yield* Effect.forEach(decoded.data, (item) => MediaProtocol.expiringUrl(item.url, OUTPUT_RETENTION)),
48
- // Z.ai reports applied content filters alongside a successful result; surface them instead of dropping them.
49
- notices: filters.length === 0
50
- ? undefined
51
- : filters.map((filter) => ({
52
- type: "moderated",
53
- message: `${route.name} applied a content filter${filter.role === undefined ? "" : ` for ${filter.role}`}${filter.level === undefined ? "" : ` at level ${filter.level}`}`,
54
- providerMetadata: { zai: filter },
55
- })),
56
57
  providerMetadata: {
57
58
  zai: {
58
59
  created: decoded.created,
@@ -67,7 +68,7 @@ const decodeResponse = Effect.fn("ZAIImages.decodeResponse")(function* (response
67
68
  // 7. Protocol and route
68
69
  // ---------------------------------------------------------------------------
69
70
  export const protocol = MediaProtocol.inline(route, {
70
- unsupported: ["images", "mask", "n", "aspectRatio", "seed", "format"],
71
+ unsupported: ["images", "n"],
71
72
  body: { from: fromRequest },
72
73
  response: { decode: decodeResponse },
73
74
  });
@@ -1,11 +1,13 @@
1
+ import { Schema } from "effect";
1
2
  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
- };
3
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
4
+ declare const Options: Schema.Struct<{
5
+ readonly effort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
6
+ readonly thinking: Schema.optional<Schema.Struct<{
7
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">, import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">>;
8
+ }>>;
9
+ }>;
10
+ export type OptionsInput = typeof Options.Type;
9
11
  export declare const protocol: Protocol<{
10
12
  readonly context_management?: {
11
13
  readonly edits: readonly {
@@ -24,7 +26,7 @@ export declare const protocol: Protocol<{
24
26
  readonly text: string;
25
27
  readonly cache_control?: {
26
28
  readonly type: "ephemeral";
27
- readonly ttl?: "1h" | "5m" | undefined;
29
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
28
30
  } | undefined;
29
31
  }[] | undefined;
30
32
  readonly messages: readonly ({
@@ -34,7 +36,7 @@ export declare const protocol: Protocol<{
34
36
  readonly text: string;
35
37
  readonly cache_control?: {
36
38
  readonly type: "ephemeral";
37
- readonly ttl?: "1h" | "5m" | undefined;
39
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
38
40
  } | undefined;
39
41
  } | {
40
42
  readonly type: "image";
@@ -51,11 +53,28 @@ export declare const protocol: Protocol<{
51
53
  };
52
54
  readonly cache_control?: {
53
55
  readonly type: "ephemeral";
54
- readonly ttl?: "1h" | "5m" | undefined;
56
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
55
57
  } | undefined;
56
58
  readonly transformations?: {
57
59
  readonly oversized_image?: "downsize" | "error" | undefined;
58
60
  } | undefined;
61
+ } | {
62
+ readonly type: "video";
63
+ readonly source: {
64
+ readonly type: "base64";
65
+ readonly media_type: string;
66
+ readonly data: string;
67
+ } | {
68
+ readonly type: "url";
69
+ readonly url: string;
70
+ } | {
71
+ readonly type: "file";
72
+ readonly file_id: string;
73
+ };
74
+ readonly cache_control?: {
75
+ readonly type: "ephemeral";
76
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
77
+ } | undefined;
59
78
  } | {
60
79
  readonly type: "document";
61
80
  readonly source: {
@@ -75,7 +94,7 @@ export declare const protocol: Protocol<{
75
94
  };
76
95
  readonly cache_control?: {
77
96
  readonly type: "ephemeral";
78
- readonly ttl?: "1h" | "5m" | undefined;
97
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
79
98
  } | undefined;
80
99
  readonly title?: string | undefined;
81
100
  readonly context?: string | undefined;
@@ -90,7 +109,7 @@ export declare const protocol: Protocol<{
90
109
  readonly text: string;
91
110
  readonly cache_control?: {
92
111
  readonly type: "ephemeral";
93
- readonly ttl?: "1h" | "5m" | undefined;
112
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
94
113
  } | undefined;
95
114
  } | {
96
115
  readonly type: "image";
@@ -107,11 +126,28 @@ export declare const protocol: Protocol<{
107
126
  };
108
127
  readonly cache_control?: {
109
128
  readonly type: "ephemeral";
110
- readonly ttl?: "1h" | "5m" | undefined;
129
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
111
130
  } | undefined;
112
131
  readonly transformations?: {
113
132
  readonly oversized_image?: "downsize" | "error" | undefined;
114
133
  } | undefined;
134
+ } | {
135
+ readonly type: "video";
136
+ readonly source: {
137
+ readonly type: "base64";
138
+ readonly media_type: string;
139
+ readonly data: string;
140
+ } | {
141
+ readonly type: "url";
142
+ readonly url: string;
143
+ } | {
144
+ readonly type: "file";
145
+ readonly file_id: string;
146
+ };
147
+ readonly cache_control?: {
148
+ readonly type: "ephemeral";
149
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
150
+ } | undefined;
115
151
  } | {
116
152
  readonly type: "document";
117
153
  readonly source: {
@@ -131,7 +167,7 @@ export declare const protocol: Protocol<{
131
167
  };
132
168
  readonly cache_control?: {
133
169
  readonly type: "ephemeral";
134
- readonly ttl?: "1h" | "5m" | undefined;
170
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
135
171
  } | undefined;
136
172
  readonly title?: string | undefined;
137
173
  readonly context?: string | undefined;
@@ -142,43 +178,35 @@ export declare const protocol: Protocol<{
142
178
  readonly is_error?: boolean | undefined;
143
179
  readonly cache_control?: {
144
180
  readonly type: "ephemeral";
145
- readonly ttl?: "1h" | "5m" | undefined;
181
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
146
182
  } | undefined;
147
183
  })[];
148
184
  } | {
149
185
  readonly role: "assistant";
150
186
  readonly content: readonly ({
187
+ readonly type: "compaction";
188
+ readonly content: string | null;
189
+ } | {
151
190
  readonly type: "text";
152
191
  readonly text: string;
153
192
  readonly cache_control?: {
154
193
  readonly type: "ephemeral";
155
- readonly ttl?: "1h" | "5m" | undefined;
156
- } | undefined;
157
- } | {
158
- readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
159
- readonly tool_use_id: string;
160
- readonly content: unknown;
161
- readonly cache_control?: {
162
- readonly type: "ephemeral";
163
- readonly ttl?: "1h" | "5m" | undefined;
194
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
164
195
  } | undefined;
165
- } | {
166
- readonly type: "compaction";
167
- readonly content: string | null;
168
196
  } | {
169
197
  readonly type: "thinking";
170
198
  readonly thinking: string;
171
199
  readonly signature: string;
172
200
  readonly cache_control?: {
173
201
  readonly type: "ephemeral";
174
- readonly ttl?: "1h" | "5m" | undefined;
202
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
175
203
  } | undefined;
176
204
  } | {
177
205
  readonly type: "redacted_thinking";
178
206
  readonly data: string;
179
207
  readonly cache_control?: {
180
208
  readonly type: "ephemeral";
181
- readonly ttl?: "1h" | "5m" | undefined;
209
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
182
210
  } | undefined;
183
211
  } | {
184
212
  readonly type: "tool_use";
@@ -187,7 +215,7 @@ export declare const protocol: Protocol<{
187
215
  readonly input: unknown;
188
216
  readonly cache_control?: {
189
217
  readonly type: "ephemeral";
190
- readonly ttl?: "1h" | "5m" | undefined;
218
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
191
219
  } | undefined;
192
220
  } | {
193
221
  readonly type: "server_tool_use";
@@ -196,7 +224,15 @@ export declare const protocol: Protocol<{
196
224
  readonly input: unknown;
197
225
  readonly cache_control?: {
198
226
  readonly type: "ephemeral";
199
- readonly ttl?: "1h" | "5m" | undefined;
227
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
228
+ } | undefined;
229
+ } | {
230
+ readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
231
+ readonly tool_use_id: string;
232
+ readonly content: unknown;
233
+ readonly cache_control?: {
234
+ readonly type: "ephemeral";
235
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
200
236
  } | undefined;
201
237
  })[];
202
238
  } | {
@@ -206,7 +242,7 @@ export declare const protocol: Protocol<{
206
242
  readonly text: string;
207
243
  readonly cache_control?: {
208
244
  readonly type: "ephemeral";
209
- readonly ttl?: "1h" | "5m" | undefined;
245
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
210
246
  } | undefined;
211
247
  }[];
212
248
  readonly output_config?: {
@@ -221,7 +257,7 @@ export declare const protocol: Protocol<{
221
257
  };
222
258
  readonly cache_control?: {
223
259
  readonly type: "ephemeral";
224
- readonly ttl?: "1h" | "5m" | undefined;
260
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
225
261
  } | undefined;
226
262
  }[] | undefined;
227
263
  readonly tool_choice?: {
@@ -249,7 +285,7 @@ export declare const protocol: Protocol<{
249
285
  } | undefined;
250
286
  readonly cache_control?: {
251
287
  readonly type: "ephemeral";
252
- readonly ttl?: "1h" | "5m" | undefined;
288
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
253
289
  } | undefined;
254
290
  readonly container?: string | {
255
291
  readonly id?: string | null | undefined;
@@ -262,8 +298,9 @@ export declare const protocol: Protocol<{
262
298
  readonly user_id?: string | null | undefined;
263
299
  } | undefined;
264
300
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
301
+ readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
265
302
  readonly thinking?: {
266
- readonly type: string;
303
+ readonly type: import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">;
267
304
  } | undefined;
268
305
  }, string, {
269
306
  readonly [x: string]: unknown;
@@ -3,9 +3,10 @@ import { Protocol } from "../route/protocol.js";
3
3
  import { LLMRequest } from "../schema/index.js";
4
4
  import { AnthropicMessages } from "./anthropic-messages.js";
5
5
  import { ProviderShared } from "./shared.js";
6
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
6
7
  const Options = Schema.Struct({
7
- effort: Schema.optional(Schema.String),
8
- thinking: Schema.optional(Schema.Struct({ type: Schema.String })),
8
+ effort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
9
+ thinking: Schema.optional(Schema.Struct({ type: ProviderShared.knownString() })),
9
10
  });
10
11
  const Body = Schema.Struct({
11
12
  ...AnthropicMessages.AnthropicMessagesBody.fields,