@opencode/ai 0.0.0-dev-1285 → 0.0.0-dev-1288

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 (66) hide show
  1. package/README.md +69 -9
  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 +187 -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 +293 -0
  19. package/dist/protocols/openrouter-video.d.ts +36 -0
  20. package/dist/protocols/openrouter-video.js +139 -0
  21. package/dist/protocols/seedance-video.d.ts +45 -0
  22. package/dist/protocols/seedance-video.js +217 -0
  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/byteplus/videos.d.ts +2 -0
  27. package/dist/providers/byteplus/videos.js +1 -0
  28. package/dist/providers/byteplus.d.ts +26 -0
  29. package/dist/providers/byteplus.js +21 -0
  30. package/dist/providers/google/videos.d.ts +2 -0
  31. package/dist/providers/google/videos.js +1 -0
  32. package/dist/providers/google.d.ts +5 -0
  33. package/dist/providers/google.js +7 -0
  34. package/dist/providers/index.d.ts +2 -0
  35. package/dist/providers/index.js +2 -0
  36. package/dist/providers/minimax/videos.d.ts +3 -0
  37. package/dist/providers/minimax/videos.js +1 -0
  38. package/dist/providers/minimax.d.ts +6 -1
  39. package/dist/providers/minimax.js +10 -1
  40. package/dist/providers/openrouter/videos.d.ts +2 -0
  41. package/dist/providers/openrouter/videos.js +1 -0
  42. package/dist/providers/openrouter.d.ts +5 -0
  43. package/dist/providers/openrouter.js +8 -0
  44. package/dist/providers/volcengine/videos.d.ts +2 -0
  45. package/dist/providers/volcengine/videos.js +1 -0
  46. package/dist/providers/volcengine.d.ts +26 -0
  47. package/dist/providers/volcengine.js +21 -0
  48. package/dist/providers/xai/videos.d.ts +2 -0
  49. package/dist/providers/xai/videos.js +1 -0
  50. package/dist/providers/xai.d.ts +4 -3
  51. package/dist/providers/xai.js +5 -1
  52. package/dist/public.d.ts +1 -1
  53. package/dist/route/executor-service.d.ts +6 -0
  54. package/dist/route/executor-service.js +7 -0
  55. package/dist/route/executor.d.ts +7 -1
  56. package/dist/route/executor.js +7 -2
  57. package/dist/route/media-protocol.d.ts +10 -0
  58. package/dist/route/media.js +17 -3
  59. package/dist/route/transport/http.js +1 -1
  60. package/dist/schema/options.d.ts +8 -0
  61. package/dist/schema/options.js +1 -0
  62. package/dist/video-client.d.ts +6 -6
  63. package/dist/video-client.js +13 -11
  64. package/dist/video.d.ts +14 -72
  65. package/dist/video.js +9 -8
  66. package/package.json +47 -3
@@ -2,47 +2,52 @@ import { Effect, Layer, Stream } from "effect";
2
2
  import { resultEvents } from "./generation.js";
3
3
  import { RequestExecutor } from "./route/executor.js";
4
4
  import { AIError, UnsupportedOperationError } from "./schema/index.js";
5
- /** One modality's layer and service accessors, dispatching each request on its route's `kind`. */
5
+ /** `${modality}.${operation}` on a route that is not queued. */
6
+ export const notQueued = (modality, route, operation) => new AIError({
7
+ reason: new UnsupportedOperationError({
8
+ operation: `${modality}.${operation}`,
9
+ provider: route.provider,
10
+ route: route.id,
11
+ message: `${route.provider}/${route.id} is not a queued route; use generate or stream`,
12
+ }),
13
+ });
14
+ /** One modality's operations over an executor, dispatching each request on its route's `kind`. */
15
+ export const operations = (execute, input) => {
16
+ const start = (request) => {
17
+ const route = request.model.route;
18
+ if (route.kind !== "queued")
19
+ return Effect.fail(notQueued(input.modality, route, "start"));
20
+ return route.start(request, execute);
21
+ };
22
+ return {
23
+ start,
24
+ resume: (model, token) => {
25
+ if (model.route.kind !== "queued")
26
+ return Effect.fail(notQueued(input.modality, model.route, "resume"));
27
+ return model.route.resume(model, token, execute);
28
+ },
29
+ generate: (request, options) => {
30
+ const route = request.model.route;
31
+ if (route.kind !== "queued")
32
+ return route.generate(request, execute);
33
+ return start(request).pipe(Effect.flatMap((generation) => generation.await(options)));
34
+ },
35
+ stream: (request, options) => {
36
+ const route = request.model.route;
37
+ if (route.kind === "stream")
38
+ return route.stream(request, execute);
39
+ if (route.kind === "queued")
40
+ return Stream.unwrap(start(request).pipe(Effect.map((generation) => resultEvents(generation, input.responseEvents, options))));
41
+ return Stream.fromIterableEffect(Effect.map(route.generate(request, execute), input.responseEvents));
42
+ },
43
+ };
44
+ };
45
+ /** One modality's layer and service accessors over `operations`. */
6
46
  export const make = (service, input) => ({
7
47
  responseEvents: input.responseEvents,
8
48
  layer: Layer.effect(service, Effect.gen(function* () {
9
49
  const executor = yield* RequestExecutor.Service;
10
- const notQueued = (route, operation) => new AIError({
11
- reason: new UnsupportedOperationError({
12
- operation: `${input.modality}.${operation}`,
13
- provider: route.provider,
14
- route: route.id,
15
- message: `${route.provider}/${route.id} is not a queued route; use generate or stream`,
16
- }),
17
- });
18
- const start = (request) => {
19
- const route = request.model.route;
20
- if (route.kind !== "queued")
21
- return Effect.fail(notQueued(route, "start"));
22
- return route.start(request, executor.execute);
23
- };
24
- return service.of({
25
- start,
26
- resume: (model, token) => {
27
- if (model.route.kind !== "queued")
28
- return Effect.fail(notQueued(model.route, "resume"));
29
- return model.route.resume(model, token, executor.execute);
30
- },
31
- generate: (request, options) => {
32
- const route = request.model.route;
33
- if (route.kind !== "queued")
34
- return route.generate(request, executor.execute);
35
- return start(request).pipe(Effect.flatMap((generation) => generation.await(options)));
36
- },
37
- stream: (request, options) => {
38
- const route = request.model.route;
39
- if (route.kind === "stream")
40
- return route.stream(request, executor.execute);
41
- if (route.kind === "queued")
42
- return Stream.unwrap(start(request).pipe(Effect.map((generation) => resultEvents(generation, input.responseEvents, options))));
43
- return Stream.fromIterableEffect(Effect.map(route.generate(request, executor.execute), input.responseEvents));
44
- },
45
- });
50
+ return service.of(operations(executor.execute, input));
46
51
  })),
47
52
  generate: (request, options) => service.use((client) => client.generate(request, options)),
48
53
  stream: (request, options) => Stream.unwrap(service.useSync((client) => client.stream(request, options))),
package/dist/media.d.ts CHANGED
@@ -190,6 +190,12 @@ export declare const AssetSchema: Schema.decodeTo<Schema.declare<Asset, Asset>,
190
190
  }>>;
191
191
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
192
192
  }>, never, never>;
193
+ /**
194
+ * An image, or a URL or provider file reference whose type it doesn't state, which the provider checks itself. Build one with
195
+ * `Media.image`; an asset known to be a video, audio or document is rejected.
196
+ */
197
+ export declare const ImageAssetSchema: Schema.brand<Schema.declare<Asset, Asset>, "Media.ImageAsset">;
198
+ export type ImageAsset = typeof ImageAssetSchema.Type;
193
199
  export type AssetOptions = Omit<Asset.Input, "source">;
194
200
  export declare const from: (source: Source, options?: AssetOptions) => Asset;
195
201
  export declare const bytes: (data: Uint8Array, mediaType?: string, options?: AssetOptions) => Asset;
@@ -206,6 +212,8 @@ export declare const fromDataUrl: (dataUrl: string, options?: AssetOptions) => A
206
212
  export type Data = Uint8Array | ArrayBuffer | URL | string;
207
213
  /** What file inputs accept: an `Asset` or plain `Data`. */
208
214
  export type Input = Asset | Data;
215
+ /** Normalize input into an `ImageAsset`; throws when it's known not to be an image. */
216
+ export declare const image: (input: Input, mediaType?: string) => ImageAsset;
209
217
  /**
210
218
  * Normalize file input into an `Asset`. Data URLs carry their media type and bytes or base64 are sniffed from magic
211
219
  * bytes; `mediaType` is required when sniffing fails. Assets pass through unchanged.
package/dist/media.js CHANGED
@@ -178,6 +178,13 @@ export const AssetSchema = AssetEncoded.pipe(Schema.decodeTo(AssetInstance, {
178
178
  decode: SchemaGetter.transform((encoded) => new Asset(encoded)),
179
179
  encode: SchemaGetter.transform(encodeAsset),
180
180
  }));
181
+ /**
182
+ * An image, or a URL or provider file reference whose type it doesn't state, which the provider checks itself. Build one with
183
+ * `Media.image`; an asset known to be a video, audio or document is rejected.
184
+ */
185
+ export const ImageAssetSchema = AssetInstance.check(Schema.makeFilter((asset) => asset.kind === "image" ||
186
+ ((asset.source.type === "url" || asset.source.type === "ref") && asset.source.mediaType === undefined) ||
187
+ `expected an image, got ${asset.mediaType}`)).pipe(Schema.brand("Media.ImageAsset"));
181
188
  const download = Effect.fn("Media.download")(function* (source, headers) {
182
189
  const executor = yield* Service;
183
190
  const response = yield* executor.execute(HttpClientRequest.get(source.url).pipe(HttpClientRequest.setHeaders(headers ?? {})));
@@ -222,6 +229,13 @@ export const fromDataUrl = (dataUrl, options) => {
222
229
  throw invalid("Media data URLs must contain a MIME type and base64 data");
223
230
  return asset;
224
231
  };
232
+ /** Normalize input into an `ImageAsset`; throws when it's known not to be an image. */
233
+ export const image = (input, mediaType) => {
234
+ const asset = make(input, mediaType);
235
+ if (!Schema.is(ImageAssetSchema)(asset))
236
+ throw invalid(`expected an image, got ${asset.mediaType}`);
237
+ return asset;
238
+ };
225
239
  /**
226
240
  * Normalize file input into an `Asset`. Data URLs carry their media type and bytes or base64 are sniffed from magic
227
241
  * bytes; `mediaType` is required when sniffing fails. Assets pass through unchanged.
@@ -0,0 +1,38 @@
1
+ import { Schema } from "effect";
2
+ import { MediaProtocol } from "../route/media-protocol.js";
3
+ import { MediaRoute } from "../route/media.js";
4
+ import { type OpenString } from "../schema/index.js";
5
+ import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
6
+ export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
7
+ export declare const PATH = "/interactions";
8
+ /**
9
+ * Provider-native Interactions fields, merged into the body. Common fields (`start`, `end`, `references`,
10
+ * `duration`, `aspect`, `resolution`) live on the request. Edit or extend a video by passing it as a reference with
11
+ * `generation_config.video_config.task`, or continue a generated one with `previous_interaction_id`.
12
+ */
13
+ export type GoogleVideoOptions = {
14
+ readonly previous_interaction_id?: string;
15
+ readonly generation_config?: {
16
+ readonly video_config?: {
17
+ readonly task?: OpenString<"text_to_video" | "image_to_video" | "reference_to_video" | "edit" | "extend">;
18
+ } & Record<string, unknown>;
19
+ } & Record<string, unknown>;
20
+ readonly response_format?: {
21
+ readonly delivery?: OpenString<"inline" | "uri">;
22
+ } & Record<string, unknown>;
23
+ readonly service_tier?: OpenString<"flex" | "standard" | "priority">;
24
+ readonly webhook_config?: {
25
+ readonly uris?: ReadonlyArray<string>;
26
+ readonly user_metadata?: Record<string, unknown>;
27
+ };
28
+ } & Record<string, unknown>;
29
+ export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
30
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
31
+ export declare const Token: Schema.String;
32
+ export type Token = Schema.Schema.Type<typeof Token>;
33
+ export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
34
+ export declare const model: (input: MediaRoute.ModelInput) => VideoModel<GoogleVideoOptions>;
35
+ export declare const GoogleInteractionsVideo: {
36
+ readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
37
+ readonly model: typeof model;
38
+ };
@@ -0,0 +1,187 @@
1
+ import { 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 { mergeJsonRecords, tokenUsage } from "../schema/index.js";
6
+ import { VideoModel, VideoResponse, seconds } from "../video.js";
7
+ import { GoogleInteractions } from "./google-interactions.js";
8
+ import { optionalNull } from "./shared.js";
9
+ import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
10
+ import { MediaInput } from "./utils/media-input.js";
11
+ const route = MediaProtocol.identity({
12
+ id: "google-interactions-video",
13
+ name: "Google Interactions Video",
14
+ provider: "google",
15
+ });
16
+ export const DEFAULT_BASE_URL = GoogleInteractions.DEFAULT_BASE_URL;
17
+ export const PATH = "/interactions";
18
+ // ---------------------------------------------------------------------------
19
+ // 2. Token and response schemas
20
+ // ---------------------------------------------------------------------------
21
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
22
+ export const Token = Schema.String;
23
+ const Content = Schema.Struct({
24
+ type: Schema.String,
25
+ data: optionalNull(Schema.String),
26
+ uri: optionalNull(Schema.String),
27
+ mime_type: optionalNull(Schema.String),
28
+ text: optionalNull(Schema.String),
29
+ });
30
+ const Usage = Schema.StructWithRest(Schema.Struct({
31
+ total_input_tokens: optionalNull(Schema.Number),
32
+ total_output_tokens: optionalNull(Schema.Number),
33
+ total_thought_tokens: optionalNull(Schema.Number),
34
+ total_tokens: optionalNull(Schema.Number),
35
+ }), [Schema.Record(Schema.String, Schema.Unknown)]);
36
+ const Interaction = Schema.Struct({
37
+ id: Schema.String,
38
+ status: Schema.String,
39
+ model: optionalNull(Schema.String),
40
+ steps: optionalNull(Schema.Array(Schema.Struct({ type: Schema.String, content: optionalNull(Schema.Array(Content)) }))),
41
+ usage: optionalNull(Usage),
42
+ errors: optionalNull(Schema.Array(Schema.Struct({ code: optionalNull(Schema.String), message: optionalNull(Schema.String) }))),
43
+ });
44
+ // `incomplete` is terminal ("completed, but contains incomplete results"); the result read decides whether a video
45
+ // came back. `requires_action` and `requires_continuation` are not documented for video and stay running.
46
+ const STATUS = {
47
+ in_progress: "running",
48
+ completed: "completed",
49
+ incomplete: "completed",
50
+ failed: "failed",
51
+ cancelled: "cancelled",
52
+ };
53
+ // ---------------------------------------------------------------------------
54
+ // 3. Failures
55
+ // ---------------------------------------------------------------------------
56
+ // Interaction error codes are documented only as "a URI that identifies the error type"; the last segment carries the
57
+ // canonical Google status name.
58
+ const FAILURE = {
59
+ INVALID_ARGUMENT: "InvalidRequest",
60
+ FAILED_PRECONDITION: "InvalidRequest",
61
+ OUT_OF_RANGE: "InvalidRequest",
62
+ PERMISSION_DENIED: "Authentication",
63
+ UNAUTHENTICATED: "Authentication",
64
+ RESOURCE_EXHAUSTED: "RateLimit",
65
+ };
66
+ const errorCode = (code) => code?.split("/").at(-1)?.trim().toUpperCase().replaceAll("-", "_") || undefined;
67
+ // ---------------------------------------------------------------------------
68
+ // 5. Request body construction
69
+ // ---------------------------------------------------------------------------
70
+ // Omni has no role field for media: it reads one image as the start frame and two as start and end. The task hint
71
+ // pins that reading when only frames, or only references, are sent; with both, the prompt decides.
72
+ const task = (request) => {
73
+ const frames = request.start !== undefined || request.end !== undefined;
74
+ const references = (request.references ?? []).length > 0;
75
+ if (frames && !references)
76
+ return "image_to_video";
77
+ if (references && !frames)
78
+ return "reference_to_video";
79
+ return undefined;
80
+ };
81
+ const fromRequest = Effect.fn("GoogleInteractionsVideo.fromRequest")(function* (request) {
82
+ if (request.end !== undefined && request.start === undefined)
83
+ return yield* route.unsupported("video.end", `${route.name} reads a lone image as the start frame; send start too`);
84
+ if (request.sound === false)
85
+ return yield* route.unsupported("video.sound", `${route.name} always generates audio and has no option to turn it off`);
86
+ const media = yield* Effect.forEach([request.start, request.end, ...(request.references ?? [])].filter((asset) => asset !== undefined), GoogleInteractions.mediaContent);
87
+ const responseFormat = {
88
+ // `auto` follows the input image, which Omni expresses by leaving the ratio out.
89
+ aspect_ratio: request.aspect === "auto" ? undefined : request.aspect,
90
+ resolution: request.resolution?.toLowerCase(),
91
+ duration: request.duration === undefined ? undefined : `${seconds(request.duration)}s`,
92
+ };
93
+ const videoTask = task(request);
94
+ return MediaProtocol.json(mergeJsonRecords({
95
+ model: request.model.id,
96
+ input: [...media, { type: "text", text: request.prompt }],
97
+ background: true,
98
+ response_format: Object.values(responseFormat).some((value) => value !== undefined)
99
+ ? { type: "video", ...responseFormat }
100
+ : undefined,
101
+ generation_config: videoTask === undefined ? undefined : { video_config: { task: videoTask } },
102
+ }, request.providerOptions, request.http?.body) ?? {});
103
+ });
104
+ // ---------------------------------------------------------------------------
105
+ // 6. Response decoding
106
+ // ---------------------------------------------------------------------------
107
+ const decodeStart = route.decodeStarted(Interaction, (value) => ({
108
+ token: value.id,
109
+ snapshot: { id: value.id, status: MediaProtocol.status(STATUS, value.status) },
110
+ }));
111
+ const decodeInteraction = route.decodeJson(Interaction);
112
+ const decodeStatus = Effect.fn("GoogleInteractionsVideo.decodeStatus")(function* (response, context) {
113
+ const output = yield* decodeInteraction(response);
114
+ return { id: context.token, status: MediaProtocol.status(STATUS, output.value.status) };
115
+ });
116
+ const decodeResult = Effect.fn("GoogleInteractionsVideo.decodeResult")(function* (response, context) {
117
+ const output = yield* decodeInteraction(response);
118
+ const decoded = output.value;
119
+ const status = MediaProtocol.status(STATUS, decoded.status);
120
+ if (status === "running")
121
+ return yield* output.pending(context.token);
122
+ const errors = decoded.errors ?? [];
123
+ const codes = errors.flatMap((error) => {
124
+ const code = errorCode(error.code);
125
+ return code === undefined ? [] : [code];
126
+ });
127
+ const messages = errors.flatMap((error) => (error.message?.trim() ? [error.message.trim()] : []));
128
+ if (status === "cancelled")
129
+ return yield* output.ended("cancelled", `${route.name} interaction ${context.token} was cancelled`);
130
+ if (status === "failed") {
131
+ const message = `${route.name} generation failed${codes.length === 0 ? "" : ` (${codes.join(", ")})`}${messages.length === 0 ? "" : `: ${messages.join("\n")}`}`;
132
+ if (codes.some((code) => code === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(code)))
133
+ return yield* output.contentPolicy(message);
134
+ return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, codes[0]));
135
+ }
136
+ const contents = (decoded.steps ?? []).flatMap((step) => (step.type === "model_output" ? (step.content ?? []) : []));
137
+ const videos = yield* Effect.forEach(contents.filter((content) => content.type === "video"), (content, index) => {
138
+ const mediaType = content.mime_type ?? undefined;
139
+ if (content.data)
140
+ return MediaInput.decodedAsset(output.invalid, `${route.name} video ${index}`, content.data, mediaType);
141
+ // `GET /interactions/{id}` documents inline data even for `delivery: "uri"`; a Files API URI needs the API key
142
+ // to download, so it stays a Google reference that can be passed back as input.
143
+ if (content.uri)
144
+ return Effect.succeed(Media.ref(route.provider, content.uri, mediaType));
145
+ return Effect.fail(output.invalid(`${route.name} returned a video without data or a URI`));
146
+ });
147
+ if (videos.length === 0) {
148
+ if (codes.some((code) => code === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(code)))
149
+ return yield* output.contentPolicy(`${route.name} withheld the video${messages.length === 0 ? "" : `: ${messages.join("\n")}`}`);
150
+ return yield* output.invalid(`${route.name} ${decoded.status} without a video`);
151
+ }
152
+ const usage = decoded.usage ?? undefined;
153
+ return new VideoResponse({
154
+ videos,
155
+ usage: usage === undefined
156
+ ? undefined
157
+ : tokenUsage({
158
+ input: usage.total_input_tokens ?? undefined,
159
+ output: usage.total_output_tokens ?? undefined,
160
+ total: usage.total_tokens ?? undefined,
161
+ details: { reasoningTokens: usage.total_thought_tokens ?? undefined, google: usage },
162
+ }),
163
+ providerMetadata: {
164
+ google: {
165
+ interactionId: decoded.id,
166
+ model: decoded.model ?? undefined,
167
+ status: decoded.status,
168
+ },
169
+ },
170
+ });
171
+ });
172
+ // ---------------------------------------------------------------------------
173
+ // 7. Protocol and route
174
+ // ---------------------------------------------------------------------------
175
+ const interactionPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
176
+ export const protocol = MediaProtocol.queued(route, {
177
+ token: Token,
178
+ start: { body: { from: fromRequest }, decode: decodeStart },
179
+ status: { path: interactionPath, decode: decodeStatus },
180
+ result: { path: interactionPath, decode: decodeResult },
181
+ cancel: { method: "POST", path: (token) => `${interactionPath(token)}/cancel` },
182
+ });
183
+ export const model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
184
+ export const GoogleInteractionsVideo = {
185
+ protocol,
186
+ model,
187
+ };
@@ -1,6 +1,8 @@
1
- import { Schema } from "effect";
1
+ import { Effect, Schema } from "effect";
2
2
  import { Route } from "../route/client.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
+ import { AIError } from "../schema/index.js";
5
+ import { Media } from "../media.js";
4
6
  import { Lifecycle } from "./utils/lifecycle.js";
5
7
  import { ToolStream } from "./utils/tool-stream.js";
6
8
  export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
@@ -36,6 +38,17 @@ interface ParserState {
36
38
  readonly steps: Partial<Record<number, OutputStep>>;
37
39
  readonly tools: ToolStream.State<number>;
38
40
  }
41
+ export declare const mediaContent: (asset: Media.Asset) => Effect.Effect<{
42
+ type: "audio" | "document" | "image" | "video";
43
+ uri: string;
44
+ mime_type: string;
45
+ data?: undefined;
46
+ } | {
47
+ uri?: undefined;
48
+ type: "audio" | "document" | "image" | "video";
49
+ data: string;
50
+ mime_type: string;
51
+ }, AIError, never>;
39
52
  export declare const protocol: Protocol<{
40
53
  readonly model: string;
41
54
  readonly input: readonly ({
@@ -172,7 +172,7 @@ const Event = Schema.Union([
172
172
  // =============================================================================
173
173
  // Request Body Construction
174
174
  // =============================================================================
175
- const mediaContent = Effect.fnUntraced(function* (asset) {
175
+ export const mediaContent = Effect.fnUntraced(function* (asset) {
176
176
  if (asset.kind !== "image" &&
177
177
  asset.kind !== "audio" &&
178
178
  asset.kind !== "video" &&
@@ -0,0 +1,45 @@
1
+ import { Schema } from "effect";
2
+ import { MediaProtocol } from "../route/media-protocol.js";
3
+ import { MediaRoute } from "../route/media.js";
4
+ import { type OpenString } from "../schema/index.js";
5
+ import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
6
+ /** The API host without a version: H3 is served under `/v2` and Hailuo under `/v1`. */
7
+ export declare const DEFAULT_BASE_URL = "https://api.minimax.io";
8
+ export declare const PATH = "/v2/video_generation";
9
+ export declare const STATUS_PATH = "/v2/query/video_generation";
10
+ export declare const HAILUO_PATH = "/v1/video_generation";
11
+ export declare const HAILUO_STATUS_PATH = "/v1/query/video_generation";
12
+ export declare const FILE_PATH = "/v1/files/retrieve";
13
+ /**
14
+ * Provider-native options, merged into the body. Common fields (`start`, `end`, `references`, `duration`, `aspect`,
15
+ * `resolution`, `sound`) live on the request. `extra` and `response_format` are H3 (v2) fields; `prompt_optimizer`
16
+ * and `fast_pretreatment` are Hailuo (v1) fields; both APIs take `callback_url`.
17
+ */
18
+ export type MiniMaxVideoOptions = {
19
+ readonly extra?: {
20
+ readonly prompt_expansion_mode?: OpenString<"disabled" | "balanced" | "quality">;
21
+ };
22
+ readonly response_format?: OpenString<"task" | "flat">;
23
+ readonly prompt_optimizer?: boolean;
24
+ readonly fast_pretreatment?: boolean;
25
+ readonly callback_url?: string;
26
+ } & Record<string, unknown>;
27
+ export type Request = VideoRequest<VideoModel<MiniMaxVideoOptions>>;
28
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
29
+ export declare const Token: Schema.String;
30
+ export type Token = Schema.Schema.Type<typeof Token>;
31
+ export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
32
+ export declare const hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
33
+ /** H3 and later models on the v2 API. */
34
+ export declare const h3Model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
35
+ /** Hailuo and the `*-01` models on the v1 API. */
36
+ export declare const hailuoModel: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
37
+ /** Picks the API by model family: Hailuo and `*-01` models use v1, everything else v2. */
38
+ export declare const model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
39
+ export declare const MiniMaxVideo: {
40
+ readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
41
+ readonly hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
42
+ readonly model: typeof model;
43
+ readonly h3Model: typeof h3Model;
44
+ readonly hailuoModel: typeof hailuoModel;
45
+ };