@opencode/ai 0.0.0-dev-1286 → 0.0.0-dev-1289

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 (52) hide show
  1. package/README.md +55 -11
  2. package/dist/effect.d.ts +3 -1
  3. package/dist/image-client.d.ts +52 -59
  4. package/dist/image-client.js +47 -8
  5. package/dist/image.d.ts +27 -7
  6. package/dist/image.js +10 -6
  7. package/dist/index.d.ts +12 -7
  8. package/dist/index.js +12 -7
  9. package/dist/media-client.d.ts +13 -5
  10. package/dist/media-client.js +42 -37
  11. package/dist/media.d.ts +8 -0
  12. package/dist/media.js +14 -0
  13. package/dist/protocols/google-interactions-video.d.ts +38 -0
  14. package/dist/protocols/google-interactions-video.js +185 -0
  15. package/dist/protocols/google-interactions.d.ts +14 -1
  16. package/dist/protocols/google-interactions.js +1 -1
  17. package/dist/protocols/minimax-video.d.ts +45 -0
  18. package/dist/protocols/minimax-video.js +290 -0
  19. package/dist/protocols/openrouter-video.d.ts +4 -9
  20. package/dist/protocols/openrouter-video.js +8 -7
  21. package/dist/protocols/seedance-video.d.ts +4 -9
  22. package/dist/protocols/seedance-video.js +9 -8
  23. package/dist/protocols/utils/responses-compaction.js +1 -1
  24. package/dist/protocols/xai-video.d.ts +4 -9
  25. package/dist/protocols/xai-video.js +8 -7
  26. package/dist/providers/google/videos.d.ts +2 -0
  27. package/dist/providers/google/videos.js +1 -0
  28. package/dist/providers/google.d.ts +5 -0
  29. package/dist/providers/google.js +7 -0
  30. package/dist/providers/minimax/videos.d.ts +3 -0
  31. package/dist/providers/minimax/videos.js +1 -0
  32. package/dist/providers/minimax.d.ts +6 -1
  33. package/dist/providers/minimax.js +10 -1
  34. package/dist/providers/xai/videos.d.ts +2 -0
  35. package/dist/providers/xai/videos.js +1 -0
  36. package/dist/providers/xai.d.ts +4 -3
  37. package/dist/providers/xai.js +5 -1
  38. package/dist/public.d.ts +1 -1
  39. package/dist/route/executor-service.d.ts +6 -0
  40. package/dist/route/executor-service.js +7 -0
  41. package/dist/route/executor.d.ts +7 -1
  42. package/dist/route/executor.js +7 -2
  43. package/dist/route/media-protocol.d.ts +5 -0
  44. package/dist/route/media.js +4 -3
  45. package/dist/route/transport/http.js +1 -1
  46. package/dist/schema/options.d.ts +8 -0
  47. package/dist/schema/options.js +1 -0
  48. package/dist/video-client.d.ts +6 -6
  49. package/dist/video-client.js +13 -11
  50. package/dist/video.d.ts +14 -72
  51. package/dist/video.js +9 -8
  52. package/package.json +19 -3
@@ -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: "queued",
65
+ running: "running",
66
+ succeeded: "completed",
67
+ failed: "failed",
68
+ cancelled: "cancelled",
69
+ };
70
+ const HAILUO_STATUS = {
71
+ Preparing: "queued",
72
+ Queueing: "queued",
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: "queued" },
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, status: 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.status(STATUS, task.status ?? "");
170
+ if (status === "queued" || 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: "queued" } };
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 === "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.status(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
+ };
@@ -25,17 +25,12 @@ export type OpenRouterVideoOptions = {
25
25
  readonly session_id?: string;
26
26
  } & Record<string, unknown>;
27
27
  export type Request = VideoRequest<VideoModel<OpenRouterVideoOptions>>;
28
- export declare const Token: Schema.Struct<{
29
- readonly id: Schema.String;
30
- }>;
28
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
29
+ export declare const Token: Schema.String;
31
30
  export type Token = Schema.Schema.Type<typeof Token>;
32
- export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
33
- readonly id: string;
34
- }>;
31
+ export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
35
32
  export declare const model: (input: MediaRoute.ModelInput) => VideoModel<OpenRouterVideoOptions>;
36
33
  export declare const OpenRouterVideo: {
37
- readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
38
- readonly id: string;
39
- }>;
34
+ readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
40
35
  readonly model: typeof model;
41
36
  };
@@ -11,7 +11,8 @@ export const PATH = "/videos";
11
11
  // ---------------------------------------------------------------------------
12
12
  // 2. Token and response schemas
13
13
  // ---------------------------------------------------------------------------
14
- export const Token = Schema.Struct({ id: Schema.String });
14
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
15
+ export const Token = Schema.String;
15
16
  const StartResponse = Schema.Struct({ id: Schema.String, status: optionalNull(Schema.String) });
16
17
  const Job = Schema.Struct({
17
18
  id: optionalNull(Schema.String),
@@ -77,20 +78,20 @@ const resolution = (value) => (/^\dk$/.test(value) ? value.toUpperCase() : value
77
78
  // 5. Response decoding
78
79
  // ---------------------------------------------------------------------------
79
80
  const decodeStart = route.decodeStarted(StartResponse, (value) => ({
80
- token: { id: value.id },
81
+ token: value.id,
81
82
  snapshot: { id: value.id, status: MediaProtocol.status(STATUS, value.status ?? "pending") },
82
83
  }));
83
84
  const decodeJob = route.decodeJson(Job);
84
85
  const decodeStatus = Effect.fn("OpenRouterVideo.decodeStatus")(function* (response, context) {
85
86
  const output = yield* decodeJob(response);
86
- return { id: context.token.id, status: MediaProtocol.status(STATUS, output.value.status) };
87
+ return { id: context.token, status: MediaProtocol.status(STATUS, output.value.status) };
87
88
  });
88
89
  const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (response, context) {
89
90
  const output = yield* decodeJob(response);
90
91
  const job = output.value;
91
92
  const status = MediaProtocol.status(STATUS, job.status);
92
93
  if (status === "queued" || status === "running")
93
- return yield* output.pending(context.token.id);
94
+ return yield* output.pending(context.token);
94
95
  if (status === "failed") {
95
96
  const message = `${route.name} generation failed${job.error ? `: ${job.error}` : ""}`;
96
97
  if (job.error && /content policy|moderat/i.test(job.error))
@@ -98,7 +99,7 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
98
99
  return yield* output.ended("failed", message);
99
100
  }
100
101
  if (status !== "completed")
101
- return yield* output.ended(status, `${route.name} job ${context.token.id} ${status}${job.error ? `: ${job.error}` : ""}`);
102
+ return yield* output.ended(status, `${route.name} job ${context.token} ${status}${job.error ? `: ${job.error}` : ""}`);
102
103
  const urls = job.unsigned_urls ?? [];
103
104
  if (urls.length === 0)
104
105
  return yield* output.invalid(`${route.name} completed without a video URL`);
@@ -112,7 +113,7 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
112
113
  videos,
113
114
  providerMetadata: {
114
115
  openrouter: {
115
- id: context.token.id,
116
+ id: context.token,
116
117
  generationId: job.generation_id ?? undefined,
117
118
  cost: job.usage?.cost ?? undefined,
118
119
  isByok: job.usage?.is_byok ?? undefined,
@@ -123,7 +124,7 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
123
124
  // ---------------------------------------------------------------------------
124
125
  // 6. Protocol and route
125
126
  // ---------------------------------------------------------------------------
126
- const jobPath = (token) => `${PATH}/${encodeURIComponent(token.id)}`;
127
+ const jobPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
127
128
  // OpenRouter has no cancel endpoint; `cancelled` only appears when it stops a job itself.
128
129
  export const protocol = MediaProtocol.queued(route, {
129
130
  token: Token,
@@ -29,22 +29,17 @@ export type SeedanceVideoOptions = {
29
29
  readonly safety_identifier?: string;
30
30
  } & Record<string, unknown>;
31
31
  export type Request = VideoRequest<VideoModel<SeedanceVideoOptions>>;
32
- export declare const Token: Schema.Struct<{
33
- readonly taskID: Schema.String;
34
- }>;
32
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
33
+ export declare const Token: Schema.String;
35
34
  export type Token = Schema.Schema.Type<typeof Token>;
36
35
  export type Provider = "volcengine" | "byteplus";
37
36
  export declare const SeedanceVideo: {
38
37
  readonly volcengine: {
39
- protocol: MediaProtocol.Queued<Request, VideoResponse, {
40
- readonly taskID: string;
41
- }>;
38
+ protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
42
39
  model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
43
40
  };
44
41
  readonly byteplus: {
45
- protocol: MediaProtocol.Queued<Request, VideoResponse, {
46
- readonly taskID: string;
47
- }>;
42
+ protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
48
43
  model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
49
44
  };
50
45
  };
@@ -14,7 +14,8 @@ const OUTPUT_RETENTION = Duration.hours(24);
14
14
  // ---------------------------------------------------------------------------
15
15
  // 2. Token and response schemas
16
16
  // ---------------------------------------------------------------------------
17
- export const Token = Schema.Struct({ taskID: Schema.String });
17
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
18
+ export const Token = Schema.String;
18
19
  const StartResponse = Schema.Struct({ id: Schema.String });
19
20
  const Task = Schema.Struct({
20
21
  id: optionalNull(Schema.String),
@@ -125,20 +126,20 @@ const make = (provider) => {
125
126
  }, nativeOptions(request.providerOptions), request.http?.body) ?? {});
126
127
  });
127
128
  const decodeStart = route.decodeStarted(StartResponse, (value) => ({
128
- token: { taskID: value.id },
129
+ token: value.id,
129
130
  snapshot: { id: value.id, status: "queued" },
130
131
  }));
131
132
  const decodeTask = route.decodeJson(Task);
132
133
  const decodeStatus = Effect.fn("SeedanceVideo.decodeStatus")(function* (response, context) {
133
134
  const output = yield* decodeTask(response);
134
- return { id: context.token.taskID, status: MediaProtocol.status(STATUS, output.value.status) };
135
+ return { id: context.token, status: MediaProtocol.status(STATUS, output.value.status) };
135
136
  });
136
137
  const decodeResult = Effect.fn("SeedanceVideo.decodeResult")(function* (response, context) {
137
138
  const output = yield* decodeTask(response);
138
139
  const task = output.value;
139
140
  const status = MediaProtocol.status(STATUS, task.status);
140
141
  if (status === "queued" || status === "running")
141
- return yield* output.pending(context.token.taskID);
142
+ return yield* output.pending(context.token);
142
143
  if (status === "failed") {
143
144
  const code = task.error?.code ?? undefined;
144
145
  const detail = task.error?.message ?? undefined;
@@ -148,9 +149,9 @@ const make = (provider) => {
148
149
  return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, code?.split(".")[0]));
149
150
  }
150
151
  if (status === "cancelled")
151
- return yield* output.ended("cancelled", `${route.name} task ${context.token.taskID} was cancelled`);
152
+ return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
152
153
  if (status === "expired")
153
- return yield* output.ended("expired", `${route.name} task ${context.token.taskID} expired`);
154
+ return yield* output.ended("expired", `${route.name} task ${context.token} expired`);
154
155
  const videoURL = task.content?.video_url ?? undefined;
155
156
  if (videoURL === undefined)
156
157
  return yield* output.invalid(`${route.name} completed without a video URL`);
@@ -177,7 +178,7 @@ const make = (provider) => {
177
178
  },
178
179
  providerMetadata: {
179
180
  [provider]: {
180
- taskId: context.token.taskID,
181
+ taskId: context.token,
181
182
  model: task.model ?? undefined,
182
183
  seed: task.seed ?? undefined,
183
184
  ratio: task.ratio ?? undefined,
@@ -194,7 +195,7 @@ const make = (provider) => {
194
195
  },
195
196
  });
196
197
  });
197
- const taskPath = (token) => `${PATH}/${token.taskID}`;
198
+ const taskPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
198
199
  // DELETE cancels a queued task. Ark refuses it for a running task, and deletes the record of a finished one.
199
200
  const protocol = MediaProtocol.queued(route, {
200
201
  token: Token,
@@ -88,7 +88,7 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
88
88
  auth: route.auth,
89
89
  encodeBody: Schema.encodeSync(Schema.fromJsonString(Body)),
90
90
  });
91
- const response = yield* executor.execute(ProviderShared.jsonPost({
91
+ const response = yield* RequestExecutor.withTls(executor.execute, request.http?.tls)(ProviderShared.jsonPost({
92
92
  url: parts.url,
93
93
  body: parts.bodyText,
94
94
  headers: parts.headers,
@@ -24,17 +24,12 @@ export type XAIVideoOptions = {
24
24
  }>;
25
25
  } & Record<string, unknown>;
26
26
  export type Request = VideoRequest<VideoModel<XAIVideoOptions>>;
27
- export declare const Token: Schema.Struct<{
28
- readonly requestID: Schema.String;
29
- }>;
27
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
28
+ export declare const Token: Schema.String;
30
29
  export type Token = Schema.Schema.Type<typeof Token>;
31
- export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
32
- readonly requestID: string;
33
- }>;
30
+ export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
34
31
  export declare const model: (input: MediaRoute.ModelInput) => VideoModel<XAIVideoOptions>;
35
32
  export declare const XAIVideo: {
36
- readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
37
- readonly requestID: string;
38
- }>;
33
+ readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
39
34
  readonly model: typeof model;
40
35
  };
@@ -14,7 +14,8 @@ export const STATUS_PATH = "/videos";
14
14
  // ---------------------------------------------------------------------------
15
15
  // 2. Token and response schemas
16
16
  // ---------------------------------------------------------------------------
17
- export const Token = Schema.Struct({ requestID: Schema.String });
17
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
18
+ export const Token = Schema.String;
18
19
  const StartResponse = Schema.Struct({ request_id: Schema.String });
19
20
  const VideoStatus = Schema.Struct({
20
21
  status: Schema.String,
@@ -78,7 +79,7 @@ const fromRequest = Effect.fn("XAIVideo.fromRequest")(function* (request) {
78
79
  // 6. Response decoding
79
80
  // ---------------------------------------------------------------------------
80
81
  const decodeStart = route.decodeStarted(StartResponse, (value) => ({
81
- token: { requestID: value.request_id },
82
+ token: value.request_id,
82
83
  snapshot: { id: value.request_id, status: "running" },
83
84
  }));
84
85
  // `progress` is undocumented but observed live as a 0..100 percentage (recorded cassette: 1 → 10 → 37 → 100).
@@ -87,21 +88,21 @@ const decodeVideoStatus = route.decodeJson(VideoStatus);
87
88
  const decodeStatus = Effect.fn("XAIVideo.decodeStatus")(function* (response, context) {
88
89
  const output = yield* decodeVideoStatus(response);
89
90
  const status = MediaProtocol.status(STATUS, output.value.status);
90
- return { id: context.token.requestID, status, progress: fraction(output.value.progress) };
91
+ return { id: context.token, status, progress: fraction(output.value.progress) };
91
92
  });
92
93
  const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, context) {
93
94
  const output = yield* decodeVideoStatus(response);
94
95
  const decoded = output.value;
95
96
  const status = MediaProtocol.status(STATUS, decoded.status);
96
97
  if (status === "running")
97
- return yield* output.pending(context.token.requestID);
98
+ return yield* output.pending(context.token);
98
99
  if (status === "failed") {
99
100
  const code = decoded.error?.code ?? undefined;
100
101
  const message = decoded.error?.message ?? undefined;
101
102
  return yield* output.ended("failed", `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${message === undefined ? "" : `: ${message}`}`, MediaProtocol.failure(FAILURE, code));
102
103
  }
103
104
  if (status !== "completed")
104
- return yield* output.ended("expired", `${route.name} request ${context.token.requestID} expired`);
105
+ return yield* output.ended("expired", `${route.name} request ${context.token} expired`);
105
106
  // `respect_moderation: false` marks a filtered result; a URL may still be present, so only a missing one fails.
106
107
  const moderated = decoded.video?.respect_moderation === false;
107
108
  const url = decoded.video?.url ?? undefined;
@@ -119,7 +120,7 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
119
120
  ],
120
121
  providerMetadata: {
121
122
  xai: {
122
- requestId: context.token.requestID,
123
+ requestId: context.token,
123
124
  model: decoded.model ?? undefined,
124
125
  respectModeration: decoded.video?.respect_moderation ?? undefined,
125
126
  },
@@ -129,7 +130,7 @@ const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, con
129
130
  // ---------------------------------------------------------------------------
130
131
  // 7. Protocol and route
131
132
  // ---------------------------------------------------------------------------
132
- const statusPath = (token) => `${STATUS_PATH}/${token.requestID}`;
133
+ const statusPath = (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`;
133
134
  export const protocol = MediaProtocol.queued(route, {
134
135
  token: Token,
135
136
  start: { body: { from: fromRequest }, decode: decodeStart },
@@ -0,0 +1,2 @@
1
+ export { videoModel as model } from "../google.js";
2
+ export type { Settings } from "../google.js";
@@ -0,0 +1 @@
1
+ export { videoModel as model } from "../google.js";
@@ -7,6 +7,7 @@ import { GoogleDecisions } from "../protocols/google-decisions.js";
7
7
  import { GoogleInteractions } from "../protocols/google-interactions.js";
8
8
  export type { OptionsInput as GoogleEmbeddingOptions } from "../protocols/google-embed-content.js";
9
9
  export type { GoogleImageOptions } from "../protocols/google-images.js";
10
+ export type { GoogleVideoOptions } from "../protocols/google-interactions-video.js";
10
11
  export type { GoogleSpeechOptions } from "../protocols/google-speech.js";
11
12
  export type { GoogleTranscriptionOptions } from "../protocols/google-transcription.js";
12
13
  export type GeminiOptionsInput = Gemini.OptionsInput;
@@ -181,6 +182,7 @@ export declare const configure: (input?: Config) => {
181
182
  readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
182
183
  }, import("../route.js").CompactionOperations | undefined>;
183
184
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
185
+ video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/google-interactions-video.js").GoogleVideoOptions>;
184
186
  speech: (modelID: string | ModelID) => import("../speech.js").SpeechModel<import("../protocols/google-speech.js").GoogleSpeechOptions>;
185
187
  transcription: (modelID: string | ModelID) => import("../transcription.js").TranscriptionModel<import("../protocols/google-transcription.js").GoogleTranscriptionOptions>;
186
188
  embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<GoogleEmbeddingOptionsInput>;
@@ -199,6 +201,7 @@ export declare const provider: {
199
201
  readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
200
202
  }, import("../route.js").CompactionOperations | undefined>;
201
203
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
204
+ video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/google-interactions-video.js").GoogleVideoOptions>;
202
205
  speech: (modelID: string | ModelID) => import("../speech.js").SpeechModel<import("../protocols/google-speech.js").GoogleSpeechOptions>;
203
206
  transcription: (modelID: string | ModelID) => import("../transcription.js").TranscriptionModel<import("../protocols/google-transcription.js").GoogleTranscriptionOptions>;
204
207
  embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<GoogleEmbeddingOptionsInput>;
@@ -207,9 +210,11 @@ export declare const provider: {
207
210
  };
208
211
  export declare const model: ProviderPackage.Model<Settings, Gemini.ProviderOptionsInput>;
209
212
  export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
213
+ export declare const videoModel: (modelID: string, settings?: Settings) => import("../video.js").VideoModel<import("../protocols/google-interactions-video.js").GoogleVideoOptions>;
210
214
  export declare const embeddingModel: (modelID: string, settings?: Settings) => import("../embedding.js").EmbeddingModel<GoogleEmbeddingOptionsInput>;
211
215
  export declare const decisionModel: (modelID: string, settings?: Settings) => import("../decision.js").DecisionModel<GoogleDecisions.OptionsInput>;
212
216
  export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
217
+ export declare const video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/google-interactions-video.js").GoogleVideoOptions>;
213
218
  export declare const embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<GoogleEmbeddingOptionsInput>;
214
219
  export declare const gemini: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<Gemini.OptionsInput, import("../route.js").CompactionOperations | undefined>;
215
220
  export declare const interactions: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
@@ -6,6 +6,7 @@ import { Gemini } from "../protocols/gemini.js";
6
6
  import { GoogleEmbedContent, } from "../protocols/google-embed-content.js";
7
7
  import { GoogleDecisions } from "../protocols/google-decisions.js";
8
8
  import { GoogleInteractions } from "../protocols/google-interactions.js";
9
+ import { GoogleInteractionsVideo } from "../protocols/google-interactions-video.js";
9
10
  import { GoogleImages } from "../protocols/google-images.js";
10
11
  import { GoogleSpeech } from "../protocols/google-speech.js";
11
12
  import { GoogleTranscription } from "../protocols/google-transcription.js";
@@ -38,6 +39,7 @@ export const configure = (input = {}) => {
38
39
  gemini,
39
40
  interactions: (modelID) => interactionsRoute(input).model({ id: modelID }),
40
41
  image: (modelID, providerOptions) => GoogleImages.model({ ...media, id: modelID, providerOptions }),
42
+ video: (modelID, providerOptions) => GoogleInteractionsVideo.model({ ...media, id: modelID, providerOptions }),
41
43
  speech: (modelID) => GoogleSpeech.model({ ...media, id: modelID }),
42
44
  transcription: (modelID) => GoogleTranscription.model({ ...media, id: modelID }),
43
45
  embedding: (modelID, providerOptions) => embeddingRoute.model({ id: modelID, providerOptions }),
@@ -53,6 +55,10 @@ export const imageModel = (modelID, settings) => {
53
55
  const input = toConfig(settings);
54
56
  return configure(input).image(modelID, input.providerOptions);
55
57
  };
58
+ export const videoModel = (modelID, settings) => {
59
+ const input = toConfig(settings);
60
+ return configure(input).video(modelID, input.providerOptions);
61
+ };
56
62
  export const embeddingModel = (modelID, settings) => {
57
63
  const input = toConfig(settings);
58
64
  return configure(input).embedding(modelID, input.providerOptions);
@@ -62,6 +68,7 @@ export const decisionModel = (modelID, settings) => {
62
68
  return configure(input).decision(modelID, input.providerOptions);
63
69
  };
64
70
  export const image = provider.image;
71
+ export const video = provider.video;
65
72
  export const embedding = provider.embedding;
66
73
  export const gemini = provider.gemini;
67
74
  export const interactions = provider.interactions;
@@ -0,0 +1,3 @@
1
+ import type { MiniMax } from "../minimax.js";
2
+ export { videoModel as model } from "../minimax.js";
3
+ export type Settings = MiniMax.Settings<MiniMax.MiniMaxVideoOptions>;