@opencode/ai 2.2.7 → 2.3.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 (158) hide show
  1. package/README.md +164 -99
  2. package/dist/cache-policy.js +4 -2
  3. package/dist/effect.d.ts +11 -8
  4. package/dist/effect.js +2 -1
  5. package/dist/experimental.d.ts +0 -4
  6. package/dist/experimental.js +0 -3
  7. package/dist/generation.d.ts +10 -10
  8. package/dist/generation.js +8 -14
  9. package/dist/image-client.d.ts +56 -59
  10. package/dist/image-client.js +47 -12
  11. package/dist/image.d.ts +36 -95
  12. package/dist/image.js +11 -14
  13. package/dist/index.d.ts +31 -68
  14. package/dist/index.js +54 -30
  15. package/dist/llm.d.ts +4 -1
  16. package/dist/llm.js +10 -1
  17. package/dist/media-client.d.ts +18 -6
  18. package/dist/media-client.js +42 -37
  19. package/dist/media-model.d.ts +2 -0
  20. package/dist/media-model.js +3 -1
  21. package/dist/media.d.ts +26 -4
  22. package/dist/media.js +52 -11
  23. package/dist/protocols/alibaba-messages.d.ts +24 -2
  24. package/dist/protocols/alibaba-responses.d.ts +26 -0
  25. package/dist/protocols/anthropic-messages.d.ts +70 -6
  26. package/dist/protocols/anthropic-messages.js +74 -9
  27. package/dist/protocols/assemblyai-transcription.js +7 -6
  28. package/dist/protocols/cartesia-speech.d.ts +0 -8
  29. package/dist/protocols/deepgram-speech.d.ts +0 -8
  30. package/dist/protocols/elevenlabs-speech.d.ts +0 -8
  31. package/dist/protocols/google-decisions.d.ts +13 -0
  32. package/dist/protocols/google-decisions.js +133 -0
  33. package/dist/protocols/google-interactions-video.d.ts +38 -0
  34. package/dist/protocols/google-interactions-video.js +185 -0
  35. package/dist/protocols/google-interactions.d.ts +14 -1
  36. package/dist/protocols/google-interactions.js +1 -1
  37. package/dist/protocols/google-speech.d.ts +0 -8
  38. package/dist/protocols/google-transcription.d.ts +0 -8
  39. package/dist/protocols/index.d.ts +1 -0
  40. package/dist/protocols/index.js +1 -0
  41. package/dist/protocols/meta-messages.d.ts +24 -2
  42. package/dist/protocols/meta-responses.d.ts +52 -0
  43. package/dist/protocols/minimax-video.d.ts +45 -0
  44. package/dist/protocols/minimax-video.js +290 -0
  45. package/dist/protocols/open-responses.d.ts +250 -24
  46. package/dist/protocols/open-responses.js +40 -24
  47. package/dist/protocols/openai-chat.js +7 -3
  48. package/dist/protocols/openai-compatible-responses.d.ts +26 -0
  49. package/dist/protocols/openai-freeform.d.ts +1 -1
  50. package/dist/protocols/openai-freeform.js +9 -5
  51. package/dist/protocols/openai-images.d.ts +0 -8
  52. package/dist/protocols/openai-responses.d.ts +153 -0
  53. package/dist/protocols/openai-responses.js +68 -7
  54. package/dist/protocols/openai-speech.d.ts +0 -8
  55. package/dist/protocols/openai-transcription.d.ts +0 -8
  56. package/dist/protocols/openrouter-video.d.ts +36 -0
  57. package/dist/protocols/openrouter-video.js +139 -0
  58. package/dist/protocols/seedance-video.d.ts +45 -0
  59. package/dist/protocols/seedance-video.js +217 -0
  60. package/dist/protocols/system-one.d.ts +45 -1
  61. package/dist/protocols/system-one.js +42 -7
  62. package/dist/protocols/utils/gateway-protocol.js +1 -0
  63. package/dist/protocols/utils/responses-compaction.js +8 -4
  64. package/dist/protocols/xai-responses.d.ts +26 -0
  65. package/dist/protocols/xai-video.d.ts +12 -11
  66. package/dist/protocols/xai-video.js +33 -24
  67. package/dist/protocols/zai-messages.d.ts +24 -2
  68. package/dist/provider-error.js +7 -1
  69. package/dist/providers/alibaba.d.ts +50 -2
  70. package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
  71. package/dist/providers/anthropic-compatible.d.ts +24 -2
  72. package/dist/providers/anthropic.d.ts +24 -2
  73. package/dist/providers/azure.d.ts +76 -2
  74. package/dist/providers/byteplus/videos.d.ts +2 -0
  75. package/dist/providers/byteplus/videos.js +1 -0
  76. package/dist/providers/byteplus.d.ts +26 -0
  77. package/dist/providers/byteplus.js +21 -0
  78. package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
  79. package/dist/providers/digitalocean.d.ts +26 -0
  80. package/dist/providers/google/decisions.d.ts +2 -0
  81. package/dist/providers/google/decisions.js +1 -0
  82. package/dist/providers/google/videos.d.ts +2 -0
  83. package/dist/providers/google/videos.js +1 -0
  84. package/dist/providers/google-vertex-messages.d.ts +24 -2
  85. package/dist/providers/google-vertex-messages.js +1 -0
  86. package/dist/providers/google-vertex-responses.d.ts +26 -0
  87. package/dist/providers/google.d.ts +11 -4
  88. package/dist/providers/google.js +16 -3
  89. package/dist/providers/index.d.ts +2 -1
  90. package/dist/providers/index.js +2 -1
  91. package/dist/providers/meta.d.ts +50 -2
  92. package/dist/providers/minimax/videos.d.ts +3 -0
  93. package/dist/providers/minimax/videos.js +1 -0
  94. package/dist/providers/minimax.d.ts +56 -3
  95. package/dist/providers/minimax.js +10 -1
  96. package/dist/providers/moonshot.d.ts +50 -2
  97. package/dist/providers/openai-compatible/decisions.d.ts +2 -0
  98. package/dist/providers/openai-compatible/decisions.js +1 -0
  99. package/dist/providers/openai-compatible-responses.d.ts +26 -0
  100. package/dist/providers/openai-compatible.d.ts +2 -0
  101. package/dist/providers/openai-compatible.js +14 -0
  102. package/dist/providers/openai.d.ts +26 -0
  103. package/dist/providers/openrouter/videos.d.ts +2 -0
  104. package/dist/providers/openrouter/videos.js +1 -0
  105. package/dist/providers/openrouter.d.ts +31 -0
  106. package/dist/providers/openrouter.js +8 -0
  107. package/dist/providers/venice.d.ts +26 -0
  108. package/dist/providers/volcengine/videos.d.ts +2 -0
  109. package/dist/providers/volcengine/videos.js +1 -0
  110. package/dist/providers/volcengine.d.ts +26 -0
  111. package/dist/providers/volcengine.js +21 -0
  112. package/dist/providers/xai/videos.d.ts +2 -0
  113. package/dist/providers/xai/videos.js +1 -0
  114. package/dist/providers/xai.d.ts +4 -3
  115. package/dist/providers/xai.js +5 -1
  116. package/dist/providers/zai-coding-plan.d.ts +50 -2
  117. package/dist/public.d.ts +7 -4
  118. package/dist/public.js +2 -1
  119. package/dist/route/client.d.ts +2 -0
  120. package/dist/route/client.js +5 -1
  121. package/dist/route/executor-service.d.ts +20 -1
  122. package/dist/route/executor-service.js +35 -1
  123. package/dist/route/executor.d.ts +11 -2
  124. package/dist/route/executor.js +25 -5
  125. package/dist/route/media-protocol.d.ts +21 -15
  126. package/dist/route/media-protocol.js +11 -4
  127. package/dist/route/media.d.ts +2 -0
  128. package/dist/route/media.js +40 -22
  129. package/dist/route/protocol.d.ts +3 -0
  130. package/dist/route/transport/http.js +1 -1
  131. package/dist/schema/events.d.ts +5 -0
  132. package/dist/schema/messages.d.ts +25 -2
  133. package/dist/schema/messages.js +27 -7
  134. package/dist/schema/options.d.ts +18 -2
  135. package/dist/schema/options.js +1 -0
  136. package/dist/speech-client.d.ts +6 -6
  137. package/dist/speech-client.js +4 -4
  138. package/dist/speech.d.ts +7 -88
  139. package/dist/speech.js +1 -3
  140. package/dist/tool-updates.d.ts +34 -0
  141. package/dist/tool-updates.js +93 -0
  142. package/dist/tool.d.ts +6 -1
  143. package/dist/tool.js +1 -1
  144. package/dist/transcription-client.d.ts +6 -6
  145. package/dist/transcription-client.js +1 -2
  146. package/dist/transcription.d.ts +7 -88
  147. package/dist/transcription.js +1 -3
  148. package/dist/video-client.d.ts +16 -84
  149. package/dist/video-client.js +30 -13
  150. package/dist/video.d.ts +54 -1126
  151. package/dist/video.js +29 -65
  152. package/package.json +59 -7
  153. package/dist/protocols/google-video.d.ts +0 -26
  154. package/dist/protocols/google-video.js +0 -146
  155. package/dist/protocols/runway-video.d.ts +0 -38
  156. package/dist/protocols/runway-video.js +0 -141
  157. package/dist/providers/runway.d.ts +0 -20
  158. package/dist/providers/runway.js +0 -17
@@ -0,0 +1,290 @@
1
+ import { Duration, Effect, Schema } from "effect";
2
+ import { Media } from "../media.js";
3
+ import { MediaProtocol } from "../route/media-protocol.js";
4
+ import { MediaRoute } from "../route/media.js";
5
+ import { AIError, QuotaExceededError, mergeJsonRecords } from "../schema/index.js";
6
+ import { VideoModel, VideoResponse, seconds } from "../video.js";
7
+ import { ProviderShared, optionalNull } from "./shared.js";
8
+ // MiniMax runs two video APIs with different bodies, statuses and results: H3 on v2 and Hailuo on v1.
9
+ const route = MediaProtocol.identity({ id: "minimax-video", name: "MiniMax Video", provider: "minimax" });
10
+ const hailuoRoute = MediaProtocol.identity({
11
+ id: "minimax-hailuo-video",
12
+ name: "MiniMax Hailuo Video",
13
+ provider: "minimax",
14
+ });
15
+ /** The API host without a version: H3 is served under `/v2` and Hailuo under `/v1`. */
16
+ export const DEFAULT_BASE_URL = "https://api.minimax.io";
17
+ export const PATH = "/v2/video_generation";
18
+ export const STATUS_PATH = "/v2/query/video_generation";
19
+ export const HAILUO_PATH = "/v1/video_generation";
20
+ export const HAILUO_STATUS_PATH = "/v1/query/video_generation";
21
+ export const FILE_PATH = "/v1/files/retrieve";
22
+ const DOWNLOAD_RETENTION = Duration.hours(1);
23
+ // ---------------------------------------------------------------------------
24
+ // 2. Token and response schemas
25
+ // ---------------------------------------------------------------------------
26
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
27
+ export const Token = Schema.String;
28
+ const BaseResp = optionalNull(Schema.Struct({
29
+ status_code: Schema.Number,
30
+ status_msg: optionalNull(Schema.String),
31
+ }));
32
+ const StartResponse = Schema.Struct({ task_id: Schema.String });
33
+ const Task = Schema.Struct({
34
+ id: optionalNull(Schema.String),
35
+ model: optionalNull(Schema.String),
36
+ status: optionalNull(Schema.String),
37
+ error: optionalNull(Schema.Struct({
38
+ code: optionalNull(Schema.Union([Schema.String, Schema.Number])),
39
+ message: optionalNull(Schema.String),
40
+ })),
41
+ content: optionalNull(Schema.Struct({ url: optionalNull(Schema.String) })),
42
+ resolution: optionalNull(Schema.String),
43
+ duration: optionalNull(Schema.Number),
44
+ ratio: optionalNull(Schema.String),
45
+ usage: optionalNull(Schema.Record(Schema.String, Schema.Unknown)),
46
+ });
47
+ // `response_format: "flat"` moves the task fields from `task` to the top level.
48
+ const TaskResponse = Schema.Struct({ ...Task.fields, task: optionalNull(Task) });
49
+ const HailuoStartResponse = Schema.Struct({ task_id: optionalNull(Schema.String), base_resp: BaseResp });
50
+ const HailuoTask = Schema.Struct({
51
+ status: optionalNull(Schema.String),
52
+ file_id: optionalNull(Schema.String),
53
+ video_width: optionalNull(Schema.Number),
54
+ video_height: optionalNull(Schema.Number),
55
+ base_resp: BaseResp,
56
+ });
57
+ const HailuoFile = Schema.Struct({
58
+ file: optionalNull(Schema.Struct({
59
+ download_url: optionalNull(Schema.String),
60
+ })),
61
+ base_resp: BaseResp,
62
+ });
63
+ const STATUS = {
64
+ queued: "running",
65
+ running: "running",
66
+ succeeded: "completed",
67
+ failed: "failed",
68
+ cancelled: "cancelled",
69
+ };
70
+ const HAILUO_STATUS = {
71
+ Preparing: "running",
72
+ Queueing: "running",
73
+ Processing: "running",
74
+ Success: "completed",
75
+ Fail: "failed",
76
+ };
77
+ // ---------------------------------------------------------------------------
78
+ // 3. Failures
79
+ // ---------------------------------------------------------------------------
80
+ // Error codes from https://platform.minimax.io/docs/api-reference/errorcode; unknown codes are provider-side.
81
+ const FAILURE = {
82
+ 1002: "RateLimit",
83
+ 1004: "Authentication",
84
+ 1039: "RateLimit",
85
+ 2013: "InvalidRequest",
86
+ 2049: "Authentication",
87
+ };
88
+ const INSUFFICIENT_BALANCE = 1008;
89
+ // 1026 flags the input and 1027 the generated video.
90
+ const CONTENT_POLICY = new Set(["1026", "1027"]);
91
+ const failed = (output, name, code, detail) => {
92
+ const message = `${name} generation failed${code === undefined ? "" : ` (${code})`}${detail === undefined ? "" : `: ${detail}`}`;
93
+ if (code !== undefined && CONTENT_POLICY.has(String(code)))
94
+ return output.contentPolicy(message);
95
+ if (code !== undefined && Number(code) === INSUFFICIENT_BALANCE)
96
+ return new AIError({ reason: new QuotaExceededError({ message, body: output.body, http: output.http }) });
97
+ return output.ended("failed", message, MediaProtocol.failure(FAILURE, code));
98
+ };
99
+ // v1 answers errors with HTTP 200 and a non-zero `base_resp.status_code`.
100
+ const baseError = (output, base) => base === undefined || base === null || base.status_code === 0
101
+ ? undefined
102
+ : failed(output, hailuoRoute.name, base.status_code, base.status_msg ?? undefined);
103
+ // ---------------------------------------------------------------------------
104
+ // 5. Request body construction
105
+ // ---------------------------------------------------------------------------
106
+ /** H3 takes URLs, data URIs and `mm_file://{file_id}` references to MiniMax files. */
107
+ const mediaUrl = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => (reference.type === "ref" ? `mm_file://${reference.value}` : reference.value)));
108
+ const ROLES = { image: "reference_image", video: "reference_video", audio: "reference_audio" };
109
+ const item = (asset, role) => mediaUrl(asset).pipe(Effect.map((url) => {
110
+ const type = asset.kind === "video" ? "video_url" : asset.kind === "audio" ? "audio_url" : "image_url";
111
+ return { type, [type]: { url }, role };
112
+ }));
113
+ const reference = (asset) => item(asset, asset.kind === "video" || asset.kind === "audio" ? ROLES[asset.kind] : ROLES.image);
114
+ /** MiniMax spells resolutions in uppercase (`480P`, `768P`, `2K`). */
115
+ const resolution = (request) => request.resolution?.toUpperCase();
116
+ const fromRequest = Effect.fn("MiniMaxVideo.fromRequest")(function* (request) {
117
+ // H3 always generates a soundtrack and has no field for `sound`, so it isn't sent.
118
+ const content = [
119
+ { type: "text", text: request.prompt },
120
+ ...(request.start === undefined ? [] : [yield* item(request.start, "first_frame")]),
121
+ ...(request.end === undefined ? [] : [yield* item(request.end, "last_frame")]),
122
+ ...(yield* Effect.forEach(request.references ?? [], reference)),
123
+ ];
124
+ return MediaProtocol.json(mergeJsonRecords({
125
+ model: request.model.id,
126
+ content,
127
+ resolution: resolution(request),
128
+ duration: request.duration === undefined ? undefined : seconds(request.duration),
129
+ ratio: request.aspect === "auto" ? "adaptive" : request.aspect,
130
+ }, request.providerOptions, request.http?.body) ?? {});
131
+ });
132
+ /** v1 documents URLs and data URLs only, so MiniMax file references aren't sent. */
133
+ const hailuoUrl = (asset) => ProviderShared.mediaReference(asset, undefined, hailuoRoute.name).pipe(Effect.map((reference) => reference.value));
134
+ const hailuoFromRequest = Effect.fn("MiniMaxHailuoVideo.fromRequest")(function* (request) {
135
+ const references = request.references ?? [];
136
+ if (references.some((asset) => asset.kind === "video" || asset.kind === "audio"))
137
+ return yield* hailuoRoute.unsupported("video.references", `${hailuoRoute.name} takes only image (subject) references`);
138
+ // Hailuo output is always silent and its shape follows the model or the first frame, with no field for either.
139
+ // `sound` has nothing to send, so it isn't; an aspect ratio would change the shape the caller asked for.
140
+ if (request.aspect !== undefined && request.aspect !== "auto")
141
+ return yield* hailuoRoute.unsupported("video.aspect", `${hailuoRoute.name} has no aspect ratio input`);
142
+ const subjects = yield* Effect.forEach(references, (asset) => hailuoUrl(asset).pipe(Effect.map((url) => ({ type: "character", image: [url] }))));
143
+ return MediaProtocol.json(mergeJsonRecords({
144
+ model: request.model.id,
145
+ prompt: request.prompt,
146
+ first_frame_image: request.start === undefined ? undefined : yield* hailuoUrl(request.start),
147
+ last_frame_image: request.end === undefined ? undefined : yield* hailuoUrl(request.end),
148
+ subject_reference: subjects.length === 0 ? undefined : subjects,
149
+ duration: request.duration === undefined ? undefined : seconds(request.duration),
150
+ resolution: resolution(request),
151
+ }, request.providerOptions, request.http?.body) ?? {});
152
+ });
153
+ // ---------------------------------------------------------------------------
154
+ // 6. Response decoding
155
+ // ---------------------------------------------------------------------------
156
+ const decodeStart = route.decodeStarted(StartResponse, (value) => ({
157
+ token: value.task_id,
158
+ snapshot: { id: value.task_id, status: "running" },
159
+ }));
160
+ const decodeTask = route.decodeJson(TaskResponse);
161
+ const decodeStatus = Effect.fn("MiniMaxVideo.decodeStatus")(function* (response, context) {
162
+ const output = yield* decodeTask(response);
163
+ const task = output.value.task ?? output.value;
164
+ return { id: context.token, ...MediaProtocol.status(STATUS, task.status ?? "") };
165
+ });
166
+ const decodeResult = Effect.fn("MiniMaxVideo.decodeResult")(function* (response, context) {
167
+ const output = yield* decodeTask(response);
168
+ const task = output.value.task ?? output.value;
169
+ const status = MediaProtocol.state(STATUS, task.status ?? "");
170
+ if (status === "running")
171
+ return yield* output.pending(context.token);
172
+ if (status === "failed")
173
+ return yield* failed(output, route.name, task.error?.code ?? undefined, task.error?.message ?? undefined);
174
+ if (status !== "completed")
175
+ return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
176
+ const url = task.content?.url ?? undefined;
177
+ if (url === undefined)
178
+ return yield* output.invalid(`${route.name} completed without a video URL`);
179
+ const duration = task.duration ?? undefined;
180
+ const total = task.usage?.total_seconds;
181
+ return new VideoResponse({
182
+ // The URL is time-limited without a documented window; reading the result again returns a fresh one.
183
+ videos: [
184
+ Media.url(url, {
185
+ mediaType: "video/mp4",
186
+ info: duration === undefined ? undefined : { durationSeconds: duration },
187
+ }),
188
+ ],
189
+ usage: typeof total === "number" ? { type: "seconds", seconds: total } : undefined,
190
+ providerMetadata: {
191
+ minimax: {
192
+ taskId: context.token,
193
+ model: task.model ?? undefined,
194
+ resolution: task.resolution ?? undefined,
195
+ ratio: task.ratio ?? undefined,
196
+ usage: task.usage ?? undefined,
197
+ },
198
+ },
199
+ });
200
+ });
201
+ const decodeHailuoStart = Effect.fn("MiniMaxHailuoVideo.decodeStart")(function* (response) {
202
+ const output = yield* hailuoRoute.decodeJson(HailuoStartResponse)(response);
203
+ const error = baseError(output, output.value.base_resp);
204
+ if (error)
205
+ return yield* error;
206
+ const taskID = output.value.task_id ?? "";
207
+ if (taskID === "")
208
+ return yield* output.invalid(`${hailuoRoute.name} returned no task_id`);
209
+ return { token: taskID, snapshot: { id: taskID, status: "running" } };
210
+ });
211
+ const decodeHailuoTask = hailuoRoute.decodeJson(HailuoTask);
212
+ const decodeHailuoStatus = Effect.fn("MiniMaxHailuoVideo.decodeStatus")(function* (response, context) {
213
+ const output = yield* decodeHailuoTask(response);
214
+ const status = MediaProtocol.status(HAILUO_STATUS, output.value.status ?? "");
215
+ // A failed task also carries its reason in `base_resp`; any other non-zero code is a failed read.
216
+ const error = status.reason === "failed" ? undefined : baseError(output, output.value.base_resp);
217
+ if (error)
218
+ return yield* error;
219
+ return { id: context.token, ...status };
220
+ });
221
+ const decodeHailuoFile = hailuoRoute.decodeJson(HailuoFile);
222
+ const decodeHailuoResult = Effect.fn("MiniMaxHailuoVideo.decodeResult")(function* (response, context) {
223
+ const output = yield* decodeHailuoTask(response);
224
+ const task = output.value;
225
+ const status = MediaProtocol.state(HAILUO_STATUS, task.status ?? "");
226
+ const error = baseError(output, task.base_resp);
227
+ if (status === "failed")
228
+ return yield* error ?? failed(output, hailuoRoute.name, undefined, undefined);
229
+ if (error)
230
+ return yield* error;
231
+ if (status !== "completed")
232
+ return yield* output.pending(context.token);
233
+ const fileID = task.file_id ?? "";
234
+ if (fileID === "")
235
+ return yield* output.invalid(`${hailuoRoute.name} completed without a file_id`);
236
+ // The task names a file; its download URL takes a second lookup and is valid for one hour.
237
+ const file = yield* decodeHailuoFile(yield* context.get(`${FILE_PATH}?file_id=${encodeURIComponent(fileID)}`));
238
+ const fileError = baseError(file, file.value.base_resp);
239
+ if (fileError)
240
+ return yield* fileError;
241
+ const url = file.value.file?.download_url ?? undefined;
242
+ if (url === undefined)
243
+ return yield* file.invalid(`${hailuoRoute.name} returned no download_url for ${fileID}`);
244
+ const width = task.video_width ?? undefined;
245
+ const height = task.video_height ?? undefined;
246
+ return new VideoResponse({
247
+ videos: [
248
+ yield* MediaProtocol.expiringUrl(url, DOWNLOAD_RETENTION, {
249
+ mediaType: "video/mp4",
250
+ info: width === undefined && height === undefined ? undefined : { width, height },
251
+ }),
252
+ ],
253
+ providerMetadata: {
254
+ minimax: { taskId: context.token, fileId: fileID },
255
+ },
256
+ });
257
+ });
258
+ // ---------------------------------------------------------------------------
259
+ // 7. Protocol and route
260
+ // ---------------------------------------------------------------------------
261
+ export const protocol = MediaProtocol.queued(route, {
262
+ token: Token,
263
+ start: { body: { from: fromRequest }, decode: decodeStart },
264
+ status: { path: (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`, decode: decodeStatus },
265
+ result: { path: (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`, decode: decodeResult },
266
+ // Cancels a queued task; MiniMax rejects it once the task is running.
267
+ cancel: { method: "DELETE", path: (token) => `${PATH}/${encodeURIComponent(token)}` },
268
+ });
269
+ const hailuoStatusPath = (token) => `${HAILUO_STATUS_PATH}?task_id=${encodeURIComponent(token)}`;
270
+ export const hailuoProtocol = MediaProtocol.queued(hailuoRoute, {
271
+ token: Token,
272
+ start: { body: { from: hailuoFromRequest }, decode: decodeHailuoStart },
273
+ status: { path: hailuoStatusPath, decode: decodeHailuoStatus },
274
+ result: { path: hailuoStatusPath, decode: decodeHailuoResult },
275
+ });
276
+ /** H3 and later models on the v2 API. */
277
+ export const h3Model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
278
+ /** Hailuo and the `*-01` models on the v1 API. */
279
+ export const hailuoModel = (input) => VideoModel.fromRoute({ protocol: hailuoProtocol, baseURL: DEFAULT_BASE_URL, path: HAILUO_PATH }, input);
280
+ // v1 is MiniMax's legacy API with a fixed model list; every newer model ships on v2.
281
+ const isHailuo = (modelID) => /^(minimax-hailuo-|[tis]2v-01|video-01)/i.test(modelID);
282
+ /** Picks the API by model family: Hailuo and `*-01` models use v1, everything else v2. */
283
+ export const model = (input) => (isHailuo(input.id) ? hailuoModel(input) : h3Model(input));
284
+ export const MiniMaxVideo = {
285
+ protocol,
286
+ hailuoProtocol,
287
+ model,
288
+ h3Model,
289
+ hailuoModel,
290
+ };
@@ -1,7 +1,7 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { HttpTransport } from "../route/transport/index.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
- import { AIError, LLMEvent, Usage, type LLMRequest, type MediaPart, type ProviderMetadata, type ToolDefinition } from "../schema/index.js";
4
+ import { AIError, LLMEvent, Usage, type LLMRequest, type MediaPart, type ProviderMetadata, type ToolChanges, type ToolDefinition } from "../schema/index.js";
5
5
  import type { Media } from "../media.js";
6
6
  import { OpenResponsesOptions } from "./utils/open-responses-options.js";
7
7
  import { Lifecycle } from "./utils/lifecycle.js";
@@ -105,6 +105,53 @@ export declare const HostedToolReplay: Schema.StructWithRest<Schema.Struct<{
105
105
  readonly id: Schema.String;
106
106
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
107
107
  export type HostedToolReplayItem = Schema.Schema.Type<typeof HostedToolReplay>;
108
+ export declare const Tool: Schema.Struct<{
109
+ readonly type: Schema.tag<"function">;
110
+ readonly name: Schema.String;
111
+ readonly description: Schema.String;
112
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
113
+ readonly strict: Schema.optional<Schema.Boolean>;
114
+ }>;
115
+ export declare const CustomTool: Schema.Struct<{
116
+ readonly type: Schema.tag<"custom">;
117
+ readonly name: Schema.String;
118
+ readonly description: Schema.String;
119
+ readonly format: Schema.Union<readonly [Schema.Struct<{
120
+ readonly type: Schema.tag<"text">;
121
+ }>, Schema.Struct<{
122
+ readonly type: Schema.tag<"grammar">;
123
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
124
+ readonly definition: Schema.String;
125
+ }>]>;
126
+ }>;
127
+ export declare const HostedTool: Schema.StructWithRest<Schema.Struct<{
128
+ readonly type: Schema.String;
129
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
130
+ export type HostedTool = Schema.Schema.Type<typeof HostedTool>;
131
+ export declare const AdditionalTools: Schema.Struct<{
132
+ readonly type: Schema.Literal<"additional_tools">;
133
+ readonly role: Schema.Literal<"developer">;
134
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
135
+ readonly type: Schema.tag<"function">;
136
+ readonly name: Schema.String;
137
+ readonly description: Schema.String;
138
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
139
+ readonly strict: Schema.optional<Schema.Boolean>;
140
+ }>, Schema.Struct<{
141
+ readonly type: Schema.tag<"custom">;
142
+ readonly name: Schema.String;
143
+ readonly description: Schema.String;
144
+ readonly format: Schema.Union<readonly [Schema.Struct<{
145
+ readonly type: Schema.tag<"text">;
146
+ }>, Schema.Struct<{
147
+ readonly type: Schema.tag<"grammar">;
148
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
149
+ readonly definition: Schema.String;
150
+ }>]>;
151
+ }>, Schema.StructWithRest<Schema.Struct<{
152
+ readonly type: Schema.String;
153
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
154
+ }>;
108
155
  export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
109
156
  readonly type: Schema.Literal<"compaction">;
110
157
  readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -114,6 +161,29 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
114
161
  readonly reasoning: Schema.Struct<{
115
162
  readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
116
163
  }>;
164
+ }>, Schema.Struct<{
165
+ readonly type: Schema.Literal<"additional_tools">;
166
+ readonly role: Schema.Literal<"developer">;
167
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
168
+ readonly type: Schema.tag<"function">;
169
+ readonly name: Schema.String;
170
+ readonly description: Schema.String;
171
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
172
+ readonly strict: Schema.optional<Schema.Boolean>;
173
+ }>, Schema.Struct<{
174
+ readonly type: Schema.tag<"custom">;
175
+ readonly name: Schema.String;
176
+ readonly description: Schema.String;
177
+ readonly format: Schema.Union<readonly [Schema.Struct<{
178
+ readonly type: Schema.tag<"text">;
179
+ }>, Schema.Struct<{
180
+ readonly type: Schema.tag<"grammar">;
181
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
182
+ readonly definition: Schema.String;
183
+ }>]>;
184
+ }>, Schema.StructWithRest<Schema.Struct<{
185
+ readonly type: Schema.String;
186
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
117
187
  }>, Schema.Struct<{
118
188
  readonly type: Schema.tag<"message">;
119
189
  readonly role: Schema.tag<"system">;
@@ -226,29 +296,7 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
226
296
  readonly type: Schema.String;
227
297
  readonly id: Schema.String;
228
298
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>;
229
- export declare const Tool: Schema.Struct<{
230
- readonly type: Schema.tag<"function">;
231
- readonly name: Schema.String;
232
- readonly description: Schema.String;
233
- readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
234
- readonly strict: Schema.optional<Schema.Boolean>;
235
- }>;
236
- export declare const CustomTool: Schema.Struct<{
237
- readonly type: Schema.tag<"custom">;
238
- readonly name: Schema.String;
239
- readonly description: Schema.String;
240
- readonly format: Schema.Union<readonly [Schema.Struct<{
241
- readonly type: Schema.tag<"text">;
242
- }>, Schema.Struct<{
243
- readonly type: Schema.tag<"grammar">;
244
- readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
245
- readonly definition: Schema.String;
246
- }>]>;
247
- }>;
248
- export declare const HostedTool: Schema.StructWithRest<Schema.Struct<{
249
- readonly type: Schema.String;
250
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
251
- export type HostedTool = Schema.Schema.Type<typeof HostedTool>;
299
+ type OpenResponsesInputItem = Schema.Schema.Type<typeof InputItem>;
252
300
  export declare const ToolChoice: Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
253
301
  readonly type: Schema.Literals<readonly ["function", "custom"]>;
254
302
  readonly name: Schema.String;
@@ -271,6 +319,29 @@ export declare const coreFields: {
271
319
  readonly reasoning: Schema.Struct<{
272
320
  readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
273
321
  }>;
322
+ }>, Schema.Struct<{
323
+ readonly type: Schema.Literal<"additional_tools">;
324
+ readonly role: Schema.Literal<"developer">;
325
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
326
+ readonly type: Schema.tag<"function">;
327
+ readonly name: Schema.String;
328
+ readonly description: Schema.String;
329
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
330
+ readonly strict: Schema.optional<Schema.Boolean>;
331
+ }>, Schema.Struct<{
332
+ readonly type: Schema.tag<"custom">;
333
+ readonly name: Schema.String;
334
+ readonly description: Schema.String;
335
+ readonly format: Schema.Union<readonly [Schema.Struct<{
336
+ readonly type: Schema.tag<"text">;
337
+ }>, Schema.Struct<{
338
+ readonly type: Schema.tag<"grammar">;
339
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
340
+ readonly definition: Schema.String;
341
+ }>]>;
342
+ }>, Schema.StructWithRest<Schema.Struct<{
343
+ readonly type: Schema.String;
344
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
274
345
  }>, Schema.Struct<{
275
346
  readonly type: Schema.tag<"message">;
276
347
  readonly role: Schema.tag<"system">;
@@ -452,6 +523,29 @@ export declare const OpenResponsesBody: Schema.Struct<{
452
523
  readonly reasoning: Schema.Struct<{
453
524
  readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
454
525
  }>;
526
+ }>, Schema.Struct<{
527
+ readonly type: Schema.Literal<"additional_tools">;
528
+ readonly role: Schema.Literal<"developer">;
529
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
530
+ readonly type: Schema.tag<"function">;
531
+ readonly name: Schema.String;
532
+ readonly description: Schema.String;
533
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
534
+ readonly strict: Schema.optional<Schema.Boolean>;
535
+ }>, Schema.Struct<{
536
+ readonly type: Schema.tag<"custom">;
537
+ readonly name: Schema.String;
538
+ readonly description: Schema.String;
539
+ readonly format: Schema.Union<readonly [Schema.Struct<{
540
+ readonly type: Schema.tag<"text">;
541
+ }>, Schema.Struct<{
542
+ readonly type: Schema.tag<"grammar">;
543
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
544
+ readonly definition: Schema.String;
545
+ }>]>;
546
+ }>, Schema.StructWithRest<Schema.Struct<{
547
+ readonly type: Schema.String;
548
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
455
549
  }>, Schema.Struct<{
456
550
  readonly type: Schema.tag<"message">;
457
551
  readonly role: Schema.tag<"system">;
@@ -915,6 +1009,8 @@ export interface ProviderAdapter {
915
1009
  readonly request: LLMRequest;
916
1010
  }) => MediaInput | undefined;
917
1011
  readonly restoreHostedToolItem?: (item: unknown) => HostedToolReplayItem | undefined;
1012
+ /** Lowers a `Message.tools(...)` marker sent in place; routes without it must fold tool updates. */
1013
+ readonly lowerToolChanges?: (changes: ToolChanges) => Effect.Effect<ReadonlyArray<OpenResponsesInputItem>, AIError>;
918
1014
  }
919
1015
  export interface ParserState {
920
1016
  readonly provider: LLMRequest["model"]["provider"];
@@ -1000,6 +1096,32 @@ export declare const lowerConversation: (request: LLMRequest<import("../schema/o
1000
1096
  readonly reasoning: {
1001
1097
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1002
1098
  };
1099
+ } | {
1100
+ readonly type: "additional_tools";
1101
+ readonly role: "developer";
1102
+ readonly tools: readonly ({
1103
+ readonly type: "custom";
1104
+ readonly name: string;
1105
+ readonly description: string;
1106
+ readonly format: {
1107
+ readonly type: "text";
1108
+ } | {
1109
+ readonly type: "grammar";
1110
+ readonly syntax: "lark" | "regex";
1111
+ readonly definition: string;
1112
+ };
1113
+ } | {
1114
+ readonly type: "function";
1115
+ readonly name: string;
1116
+ readonly description: string;
1117
+ readonly parameters: {
1118
+ readonly [x: string]: unknown;
1119
+ };
1120
+ readonly strict?: boolean | undefined;
1121
+ } | {
1122
+ readonly [x: string]: unknown;
1123
+ readonly type: string;
1124
+ })[];
1003
1125
  } | {
1004
1126
  readonly type: "message";
1005
1127
  readonly role: "system";
@@ -1177,6 +1299,32 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
1177
1299
  readonly reasoning: {
1178
1300
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1179
1301
  };
1302
+ } | {
1303
+ readonly type: "additional_tools";
1304
+ readonly role: "developer";
1305
+ readonly tools: readonly ({
1306
+ readonly type: "custom";
1307
+ readonly name: string;
1308
+ readonly description: string;
1309
+ readonly format: {
1310
+ readonly type: "text";
1311
+ } | {
1312
+ readonly type: "grammar";
1313
+ readonly syntax: "lark" | "regex";
1314
+ readonly definition: string;
1315
+ };
1316
+ } | {
1317
+ readonly type: "function";
1318
+ readonly name: string;
1319
+ readonly description: string;
1320
+ readonly parameters: {
1321
+ readonly [x: string]: unknown;
1322
+ };
1323
+ readonly strict?: boolean | undefined;
1324
+ } | {
1325
+ readonly [x: string]: unknown;
1326
+ readonly type: string;
1327
+ })[];
1180
1328
  } | {
1181
1329
  readonly type: "message";
1182
1330
  readonly role: "system";
@@ -1375,6 +1523,32 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
1375
1523
  readonly reasoning: {
1376
1524
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1377
1525
  };
1526
+ } | {
1527
+ readonly type: "additional_tools";
1528
+ readonly role: "developer";
1529
+ readonly tools: readonly ({
1530
+ readonly type: "custom";
1531
+ readonly name: string;
1532
+ readonly description: string;
1533
+ readonly format: {
1534
+ readonly type: "text";
1535
+ } | {
1536
+ readonly type: "grammar";
1537
+ readonly syntax: "lark" | "regex";
1538
+ readonly definition: string;
1539
+ };
1540
+ } | {
1541
+ readonly type: "function";
1542
+ readonly name: string;
1543
+ readonly description: string;
1544
+ readonly parameters: {
1545
+ readonly [x: string]: unknown;
1546
+ };
1547
+ readonly strict?: boolean | undefined;
1548
+ } | {
1549
+ readonly [x: string]: unknown;
1550
+ readonly type: string;
1551
+ })[];
1378
1552
  } | {
1379
1553
  readonly type: "message";
1380
1554
  readonly role: "system";
@@ -1791,6 +1965,32 @@ export declare const protocol: Protocol<{
1791
1965
  readonly reasoning: {
1792
1966
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1793
1967
  };
1968
+ } | {
1969
+ readonly type: "additional_tools";
1970
+ readonly role: "developer";
1971
+ readonly tools: readonly ({
1972
+ readonly type: "custom";
1973
+ readonly name: string;
1974
+ readonly description: string;
1975
+ readonly format: {
1976
+ readonly type: "text";
1977
+ } | {
1978
+ readonly type: "grammar";
1979
+ readonly syntax: "lark" | "regex";
1980
+ readonly definition: string;
1981
+ };
1982
+ } | {
1983
+ readonly type: "function";
1984
+ readonly name: string;
1985
+ readonly description: string;
1986
+ readonly parameters: {
1987
+ readonly [x: string]: unknown;
1988
+ };
1989
+ readonly strict?: boolean | undefined;
1990
+ } | {
1991
+ readonly [x: string]: unknown;
1992
+ readonly type: string;
1993
+ })[];
1794
1994
  } | {
1795
1995
  readonly type: "message";
1796
1996
  readonly role: "system";
@@ -2047,6 +2247,32 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
2047
2247
  readonly reasoning: {
2048
2248
  readonly effort: OpenResponsesOptions.ReasoningEffort;
2049
2249
  };
2250
+ } | {
2251
+ readonly type: "additional_tools";
2252
+ readonly role: "developer";
2253
+ readonly tools: readonly ({
2254
+ readonly type: "custom";
2255
+ readonly name: string;
2256
+ readonly description: string;
2257
+ readonly format: {
2258
+ readonly type: "text";
2259
+ } | {
2260
+ readonly type: "grammar";
2261
+ readonly syntax: "lark" | "regex";
2262
+ readonly definition: string;
2263
+ };
2264
+ } | {
2265
+ readonly type: "function";
2266
+ readonly name: string;
2267
+ readonly description: string;
2268
+ readonly parameters: {
2269
+ readonly [x: string]: unknown;
2270
+ };
2271
+ readonly strict?: boolean | undefined;
2272
+ } | {
2273
+ readonly [x: string]: unknown;
2274
+ readonly type: string;
2275
+ })[];
2050
2276
  } | {
2051
2277
  readonly type: "message";
2052
2278
  readonly role: "system";