@opencode/ai 2.3.0 → 2.3.2
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.
- package/README.md +65 -18
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +3 -1
- package/dist/generation.d.ts +10 -10
- package/dist/generation.js +8 -14
- package/dist/image-client.d.ts +56 -59
- package/dist/image-client.js +47 -8
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +25 -25
- package/dist/index.js +29 -22
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/media-client.d.ts +18 -6
- package/dist/media-client.js +42 -37
- package/dist/media.d.ts +17 -1
- package/dist/media.js +28 -7
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/assemblyai-transcription.js +7 -6
- package/dist/protocols/cartesia-speech.d.ts +0 -8
- package/dist/protocols/deepgram-speech.d.ts +0 -8
- package/dist/protocols/elevenlabs-speech.d.ts +0 -8
- package/dist/protocols/google-interactions-video.d.ts +4 -9
- package/dist/protocols/google-interactions-video.js +9 -10
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/minimax-video.d.ts +6 -15
- package/dist/protocols/minimax-video.js +25 -27
- package/dist/protocols/open-responses.d.ts +410 -138
- package/dist/protocols/open-responses.js +47 -28
- package/dist/protocols/openai-chat.js +7 -3
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-images.d.ts +0 -8
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/openai-speech.d.ts +0 -8
- package/dist/protocols/openai-transcription.d.ts +0 -8
- package/dist/protocols/openrouter-video.d.ts +4 -9
- package/dist/protocols/openrouter-video.js +14 -13
- package/dist/protocols/seedance-video.d.ts +4 -9
- package/dist/protocols/seedance-video.js +13 -12
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +14 -4
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +4 -9
- package/dist/protocols/xai-video.js +13 -9
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/google.d.ts +3 -3
- package/dist/providers/google.js +5 -2
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax.d.ts +50 -2
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter.d.ts +26 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +4 -3
- package/dist/providers/xai.js +5 -1
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +5 -4
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +14 -1
- package/dist/route/executor-service.js +28 -1
- package/dist/route/executor.d.ts +5 -2
- package/dist/route/executor.js +20 -5
- package/dist/route/media-protocol.d.ts +12 -7
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.js +12 -3
- package/dist/route/protocol.d.ts +3 -0
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +24 -1
- package/dist/schema/messages.js +26 -2
- package/dist/schema/options.d.ts +10 -2
- package/dist/speech-client.d.ts +5 -5
- package/dist/speech.d.ts +7 -88
- package/dist/speech.js +1 -3
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/dist/transcription-client.d.ts +5 -5
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +6 -6
- package/dist/video-client.js +13 -11
- package/dist/video.d.ts +17 -73
- package/dist/video.js +9 -8
- package/package.json +7 -3
|
@@ -32,10 +32,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
32
32
|
readonly startSeconds: number;
|
|
33
33
|
readonly endSeconds: number;
|
|
34
34
|
}[];
|
|
35
|
-
} | {
|
|
36
|
-
readonly type: "generation-queued";
|
|
37
|
-
readonly id: string;
|
|
38
|
-
readonly position?: number | undefined;
|
|
39
35
|
} | {
|
|
40
36
|
readonly type: "generation-progress";
|
|
41
37
|
readonly id: string;
|
|
@@ -82,10 +78,6 @@ export declare const CartesiaSpeech: {
|
|
|
82
78
|
readonly startSeconds: number;
|
|
83
79
|
readonly endSeconds: number;
|
|
84
80
|
}[];
|
|
85
|
-
} | {
|
|
86
|
-
readonly type: "generation-queued";
|
|
87
|
-
readonly id: string;
|
|
88
|
-
readonly position?: number | undefined;
|
|
89
81
|
} | {
|
|
90
82
|
readonly type: "generation-progress";
|
|
91
83
|
readonly id: string;
|
|
@@ -25,10 +25,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
25
25
|
readonly startSeconds: number;
|
|
26
26
|
readonly endSeconds: number;
|
|
27
27
|
}[];
|
|
28
|
-
} | {
|
|
29
|
-
readonly type: "generation-queued";
|
|
30
|
-
readonly id: string;
|
|
31
|
-
readonly position?: number | undefined;
|
|
32
28
|
} | {
|
|
33
29
|
readonly type: "generation-progress";
|
|
34
30
|
readonly id: string;
|
|
@@ -75,10 +71,6 @@ export declare const DeepgramSpeech: {
|
|
|
75
71
|
readonly startSeconds: number;
|
|
76
72
|
readonly endSeconds: number;
|
|
77
73
|
}[];
|
|
78
|
-
} | {
|
|
79
|
-
readonly type: "generation-queued";
|
|
80
|
-
readonly id: string;
|
|
81
|
-
readonly position?: number | undefined;
|
|
82
74
|
} | {
|
|
83
75
|
readonly type: "generation-progress";
|
|
84
76
|
readonly id: string;
|
|
@@ -28,10 +28,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
28
28
|
readonly startSeconds: number;
|
|
29
29
|
readonly endSeconds: number;
|
|
30
30
|
}[];
|
|
31
|
-
} | {
|
|
32
|
-
readonly type: "generation-queued";
|
|
33
|
-
readonly id: string;
|
|
34
|
-
readonly position?: number | undefined;
|
|
35
31
|
} | {
|
|
36
32
|
readonly type: "generation-progress";
|
|
37
33
|
readonly id: string;
|
|
@@ -78,10 +74,6 @@ export declare const ElevenLabsSpeech: {
|
|
|
78
74
|
readonly startSeconds: number;
|
|
79
75
|
readonly endSeconds: number;
|
|
80
76
|
}[];
|
|
81
|
-
} | {
|
|
82
|
-
readonly type: "generation-queued";
|
|
83
|
-
readonly id: string;
|
|
84
|
-
readonly position?: number | undefined;
|
|
85
77
|
} | {
|
|
86
78
|
readonly type: "generation-progress";
|
|
87
79
|
readonly id: string;
|
|
@@ -27,17 +27,12 @@ export type GoogleVideoOptions = {
|
|
|
27
27
|
};
|
|
28
28
|
} & Record<string, unknown>;
|
|
29
29
|
export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}>;
|
|
30
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
31
|
+
export declare const Token: Schema.String;
|
|
33
32
|
export type Token = Schema.Schema.Type<typeof Token>;
|
|
34
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
35
|
-
readonly interactionID: string;
|
|
36
|
-
}>;
|
|
33
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
37
34
|
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<GoogleVideoOptions>;
|
|
38
35
|
export declare const GoogleInteractionsVideo: {
|
|
39
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
40
|
-
readonly interactionID: string;
|
|
41
|
-
}>;
|
|
36
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
42
37
|
readonly model: typeof model;
|
|
43
38
|
};
|
|
@@ -18,7 +18,8 @@ export const PATH = "/interactions";
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
19
19
|
// 2. Token and response schemas
|
|
20
20
|
// ---------------------------------------------------------------------------
|
|
21
|
-
|
|
21
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
22
|
+
export const Token = Schema.String;
|
|
22
23
|
const Content = Schema.Struct({
|
|
23
24
|
type: Schema.String,
|
|
24
25
|
data: optionalNull(Schema.String),
|
|
@@ -80,8 +81,6 @@ const task = (request) => {
|
|
|
80
81
|
const fromRequest = Effect.fn("GoogleInteractionsVideo.fromRequest")(function* (request) {
|
|
81
82
|
if (request.end !== undefined && request.start === undefined)
|
|
82
83
|
return yield* route.unsupported("video.end", `${route.name} reads a lone image as the start frame; send start too`);
|
|
83
|
-
if (request.sound === false)
|
|
84
|
-
return yield* route.unsupported("video.sound", `${route.name} always generates audio and has no option to turn it off`);
|
|
85
84
|
const media = yield* Effect.forEach([request.start, request.end, ...(request.references ?? [])].filter((asset) => asset !== undefined), GoogleInteractions.mediaContent);
|
|
86
85
|
const responseFormat = {
|
|
87
86
|
// `auto` follows the input image, which Omni expresses by leaving the ratio out.
|
|
@@ -104,20 +103,20 @@ const fromRequest = Effect.fn("GoogleInteractionsVideo.fromRequest")(function* (
|
|
|
104
103
|
// 6. Response decoding
|
|
105
104
|
// ---------------------------------------------------------------------------
|
|
106
105
|
const decodeStart = route.decodeStarted(Interaction, (value) => ({
|
|
107
|
-
token:
|
|
108
|
-
snapshot: { id: value.id,
|
|
106
|
+
token: value.id,
|
|
107
|
+
snapshot: { id: value.id, ...MediaProtocol.status(STATUS, value.status) },
|
|
109
108
|
}));
|
|
110
109
|
const decodeInteraction = route.decodeJson(Interaction);
|
|
111
110
|
const decodeStatus = Effect.fn("GoogleInteractionsVideo.decodeStatus")(function* (response, context) {
|
|
112
111
|
const output = yield* decodeInteraction(response);
|
|
113
|
-
return { id: context.token
|
|
112
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
114
113
|
});
|
|
115
114
|
const decodeResult = Effect.fn("GoogleInteractionsVideo.decodeResult")(function* (response, context) {
|
|
116
115
|
const output = yield* decodeInteraction(response);
|
|
117
116
|
const decoded = output.value;
|
|
118
|
-
const status = MediaProtocol.
|
|
117
|
+
const status = MediaProtocol.state(STATUS, decoded.status);
|
|
119
118
|
if (status === "running")
|
|
120
|
-
return yield* output.pending(context.token
|
|
119
|
+
return yield* output.pending(context.token);
|
|
121
120
|
const errors = decoded.errors ?? [];
|
|
122
121
|
const codes = errors.flatMap((error) => {
|
|
123
122
|
const code = errorCode(error.code);
|
|
@@ -125,7 +124,7 @@ const decodeResult = Effect.fn("GoogleInteractionsVideo.decodeResult")(function*
|
|
|
125
124
|
});
|
|
126
125
|
const messages = errors.flatMap((error) => (error.message?.trim() ? [error.message.trim()] : []));
|
|
127
126
|
if (status === "cancelled")
|
|
128
|
-
return yield* output.ended("cancelled", `${route.name} interaction ${context.token
|
|
127
|
+
return yield* output.ended("cancelled", `${route.name} interaction ${context.token} was cancelled`);
|
|
129
128
|
if (status === "failed") {
|
|
130
129
|
const message = `${route.name} generation failed${codes.length === 0 ? "" : ` (${codes.join(", ")})`}${messages.length === 0 ? "" : `: ${messages.join("\n")}`}`;
|
|
131
130
|
if (codes.some((code) => code === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(code)))
|
|
@@ -171,7 +170,7 @@ const decodeResult = Effect.fn("GoogleInteractionsVideo.decodeResult")(function*
|
|
|
171
170
|
// ---------------------------------------------------------------------------
|
|
172
171
|
// 7. Protocol and route
|
|
173
172
|
// ---------------------------------------------------------------------------
|
|
174
|
-
const interactionPath = (token) => `${PATH}/${token
|
|
173
|
+
const interactionPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
175
174
|
export const protocol = MediaProtocol.queued(route, {
|
|
176
175
|
token: Token,
|
|
177
176
|
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
@@ -35,10 +35,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
35
35
|
readonly startSeconds: number;
|
|
36
36
|
readonly endSeconds: number;
|
|
37
37
|
}[];
|
|
38
|
-
} | {
|
|
39
|
-
readonly type: "generation-queued";
|
|
40
|
-
readonly id: string;
|
|
41
|
-
readonly position?: number | undefined;
|
|
42
38
|
} | {
|
|
43
39
|
readonly type: "generation-progress";
|
|
44
40
|
readonly id: string;
|
|
@@ -85,10 +81,6 @@ export declare const GoogleSpeech: {
|
|
|
85
81
|
readonly startSeconds: number;
|
|
86
82
|
readonly endSeconds: number;
|
|
87
83
|
}[];
|
|
88
|
-
} | {
|
|
89
|
-
readonly type: "generation-queued";
|
|
90
|
-
readonly id: string;
|
|
91
|
-
readonly position?: number | undefined;
|
|
92
84
|
} | {
|
|
93
85
|
readonly type: "generation-progress";
|
|
94
86
|
readonly id: string;
|
|
@@ -32,10 +32,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
32
32
|
readonly endSeconds: number;
|
|
33
33
|
readonly speaker?: string | undefined;
|
|
34
34
|
};
|
|
35
|
-
} | {
|
|
36
|
-
readonly type: "generation-queued";
|
|
37
|
-
readonly id: string;
|
|
38
|
-
readonly position?: number | undefined;
|
|
39
35
|
} | {
|
|
40
36
|
readonly type: "generation-progress";
|
|
41
37
|
readonly id: string;
|
|
@@ -98,10 +94,6 @@ export declare const GoogleTranscription: {
|
|
|
98
94
|
readonly endSeconds: number;
|
|
99
95
|
readonly speaker?: string | undefined;
|
|
100
96
|
};
|
|
101
|
-
} | {
|
|
102
|
-
readonly type: "generation-queued";
|
|
103
|
-
readonly id: string;
|
|
104
|
-
readonly position?: number | undefined;
|
|
105
97
|
} | {
|
|
106
98
|
readonly type: "generation-progress";
|
|
107
99
|
readonly id: string;
|
|
@@ -228,14 +228,36 @@ export declare const protocol: Protocol<{
|
|
|
228
228
|
})[];
|
|
229
229
|
} | {
|
|
230
230
|
readonly role: "system";
|
|
231
|
-
readonly content: readonly {
|
|
231
|
+
readonly content: readonly ({
|
|
232
|
+
readonly type: "tool_addition";
|
|
233
|
+
readonly tool: {
|
|
234
|
+
readonly type: "tool_definition";
|
|
235
|
+
readonly definition: {
|
|
236
|
+
readonly name: string;
|
|
237
|
+
readonly description: string;
|
|
238
|
+
readonly input_schema: {
|
|
239
|
+
readonly [x: string]: unknown;
|
|
240
|
+
};
|
|
241
|
+
readonly cache_control?: {
|
|
242
|
+
readonly type: "ephemeral";
|
|
243
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
244
|
+
} | undefined;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
} | {
|
|
248
|
+
readonly type: "tool_removal";
|
|
249
|
+
readonly tool: {
|
|
250
|
+
readonly type: "tool_reference";
|
|
251
|
+
readonly name: string;
|
|
252
|
+
};
|
|
253
|
+
} | {
|
|
232
254
|
readonly type: "text";
|
|
233
255
|
readonly text: string;
|
|
234
256
|
readonly cache_control?: {
|
|
235
257
|
readonly type: "ephemeral";
|
|
236
258
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
237
259
|
} | undefined;
|
|
238
|
-
}[];
|
|
260
|
+
})[];
|
|
239
261
|
readonly output_config?: {
|
|
240
262
|
readonly effort: string;
|
|
241
263
|
} | undefined;
|
|
@@ -31,6 +31,32 @@ export declare const protocol: Protocol<{
|
|
|
31
31
|
readonly reasoning: {
|
|
32
32
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
33
33
|
};
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "additional_tools";
|
|
36
|
+
readonly role: "developer";
|
|
37
|
+
readonly tools: readonly ({
|
|
38
|
+
readonly type: "custom";
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly description: string;
|
|
41
|
+
readonly format: {
|
|
42
|
+
readonly type: "text";
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: "grammar";
|
|
45
|
+
readonly syntax: "lark" | "regex";
|
|
46
|
+
readonly definition: string;
|
|
47
|
+
};
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "function";
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly description: string;
|
|
52
|
+
readonly parameters: {
|
|
53
|
+
readonly [x: string]: unknown;
|
|
54
|
+
};
|
|
55
|
+
readonly strict?: boolean | undefined;
|
|
56
|
+
} | {
|
|
57
|
+
readonly [x: string]: unknown;
|
|
58
|
+
readonly type: string;
|
|
59
|
+
})[];
|
|
34
60
|
} | {
|
|
35
61
|
readonly type: "message";
|
|
36
62
|
readonly role: "system";
|
|
@@ -287,6 +313,32 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
287
313
|
readonly reasoning: {
|
|
288
314
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
289
315
|
};
|
|
316
|
+
} | {
|
|
317
|
+
readonly type: "additional_tools";
|
|
318
|
+
readonly role: "developer";
|
|
319
|
+
readonly tools: readonly ({
|
|
320
|
+
readonly type: "custom";
|
|
321
|
+
readonly name: string;
|
|
322
|
+
readonly description: string;
|
|
323
|
+
readonly format: {
|
|
324
|
+
readonly type: "text";
|
|
325
|
+
} | {
|
|
326
|
+
readonly type: "grammar";
|
|
327
|
+
readonly syntax: "lark" | "regex";
|
|
328
|
+
readonly definition: string;
|
|
329
|
+
};
|
|
330
|
+
} | {
|
|
331
|
+
readonly type: "function";
|
|
332
|
+
readonly name: string;
|
|
333
|
+
readonly description: string;
|
|
334
|
+
readonly parameters: {
|
|
335
|
+
readonly [x: string]: unknown;
|
|
336
|
+
};
|
|
337
|
+
readonly strict?: boolean | undefined;
|
|
338
|
+
} | {
|
|
339
|
+
readonly [x: string]: unknown;
|
|
340
|
+
readonly type: string;
|
|
341
|
+
})[];
|
|
290
342
|
} | {
|
|
291
343
|
readonly type: "message";
|
|
292
344
|
readonly role: "system";
|
|
@@ -25,16 +25,11 @@ export type MiniMaxVideoOptions = {
|
|
|
25
25
|
readonly callback_url?: string;
|
|
26
26
|
} & Record<string, unknown>;
|
|
27
27
|
export type Request = VideoRequest<VideoModel<MiniMaxVideoOptions>>;
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
}>;
|
|
35
|
-
export declare const hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
36
|
-
readonly taskID: string;
|
|
37
|
-
}>;
|
|
31
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
32
|
+
export declare const hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
38
33
|
/** H3 and later models on the v2 API. */
|
|
39
34
|
export declare const h3Model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
|
|
40
35
|
/** Hailuo and the `*-01` models on the v1 API. */
|
|
@@ -42,12 +37,8 @@ export declare const hailuoModel: (input: MediaRoute.ModelInput) => VideoModel<M
|
|
|
42
37
|
/** Picks the API by model family: Hailuo and `*-01` models use v1, everything else v2. */
|
|
43
38
|
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
|
|
44
39
|
export declare const MiniMaxVideo: {
|
|
45
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
46
|
-
|
|
47
|
-
}>;
|
|
48
|
-
readonly hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
49
|
-
readonly taskID: string;
|
|
50
|
-
}>;
|
|
40
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
41
|
+
readonly hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
51
42
|
readonly model: typeof model;
|
|
52
43
|
readonly h3Model: typeof h3Model;
|
|
53
44
|
readonly hailuoModel: typeof hailuoModel;
|
|
@@ -23,7 +23,8 @@ const DOWNLOAD_RETENTION = Duration.hours(1);
|
|
|
23
23
|
// ---------------------------------------------------------------------------
|
|
24
24
|
// 2. Token and response schemas
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
|
-
|
|
26
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
27
|
+
export const Token = Schema.String;
|
|
27
28
|
const BaseResp = optionalNull(Schema.Struct({
|
|
28
29
|
status_code: Schema.Number,
|
|
29
30
|
status_msg: optionalNull(Schema.String),
|
|
@@ -60,15 +61,15 @@ const HailuoFile = Schema.Struct({
|
|
|
60
61
|
base_resp: BaseResp,
|
|
61
62
|
});
|
|
62
63
|
const STATUS = {
|
|
63
|
-
queued: "
|
|
64
|
+
queued: "running",
|
|
64
65
|
running: "running",
|
|
65
66
|
succeeded: "completed",
|
|
66
67
|
failed: "failed",
|
|
67
68
|
cancelled: "cancelled",
|
|
68
69
|
};
|
|
69
70
|
const HAILUO_STATUS = {
|
|
70
|
-
Preparing: "
|
|
71
|
-
Queueing: "
|
|
71
|
+
Preparing: "running",
|
|
72
|
+
Queueing: "running",
|
|
72
73
|
Processing: "running",
|
|
73
74
|
Success: "completed",
|
|
74
75
|
Fail: "failed",
|
|
@@ -113,9 +114,7 @@ const reference = (asset) => item(asset, asset.kind === "video" || asset.kind ==
|
|
|
113
114
|
/** MiniMax spells resolutions in uppercase (`480P`, `768P`, `2K`). */
|
|
114
115
|
const resolution = (request) => request.resolution?.toUpperCase();
|
|
115
116
|
const fromRequest = Effect.fn("MiniMaxVideo.fromRequest")(function* (request) {
|
|
116
|
-
// H3 always generates a soundtrack and has no field
|
|
117
|
-
if (request.sound === false)
|
|
118
|
-
return yield* route.unsupported("video.sound", `${route.name} always generates sound and can't be silenced`);
|
|
117
|
+
// H3 always generates a soundtrack and has no field for `sound`, so it isn't sent.
|
|
119
118
|
const content = [
|
|
120
119
|
{ type: "text", text: request.prompt },
|
|
121
120
|
...(request.start === undefined ? [] : [yield* item(request.start, "first_frame")]),
|
|
@@ -137,8 +136,7 @@ const hailuoFromRequest = Effect.fn("MiniMaxHailuoVideo.fromRequest")(function*
|
|
|
137
136
|
if (references.some((asset) => asset.kind === "video" || asset.kind === "audio"))
|
|
138
137
|
return yield* hailuoRoute.unsupported("video.references", `${hailuoRoute.name} takes only image (subject) references`);
|
|
139
138
|
// Hailuo output is always silent and its shape follows the model or the first frame, with no field for either.
|
|
140
|
-
|
|
141
|
-
return yield* hailuoRoute.unsupported("video.sound", `${hailuoRoute.name} generates silent video only`);
|
|
139
|
+
// `sound` has nothing to send, so it isn't; an aspect ratio would change the shape the caller asked for.
|
|
142
140
|
if (request.aspect !== undefined && request.aspect !== "auto")
|
|
143
141
|
return yield* hailuoRoute.unsupported("video.aspect", `${hailuoRoute.name} has no aspect ratio input`);
|
|
144
142
|
const subjects = yield* Effect.forEach(references, (asset) => hailuoUrl(asset).pipe(Effect.map((url) => ({ type: "character", image: [url] }))));
|
|
@@ -156,25 +154,25 @@ const hailuoFromRequest = Effect.fn("MiniMaxHailuoVideo.fromRequest")(function*
|
|
|
156
154
|
// 6. Response decoding
|
|
157
155
|
// ---------------------------------------------------------------------------
|
|
158
156
|
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
159
|
-
token:
|
|
160
|
-
snapshot: { id: value.task_id, status: "
|
|
157
|
+
token: value.task_id,
|
|
158
|
+
snapshot: { id: value.task_id, status: "running" },
|
|
161
159
|
}));
|
|
162
160
|
const decodeTask = route.decodeJson(TaskResponse);
|
|
163
161
|
const decodeStatus = Effect.fn("MiniMaxVideo.decodeStatus")(function* (response, context) {
|
|
164
162
|
const output = yield* decodeTask(response);
|
|
165
163
|
const task = output.value.task ?? output.value;
|
|
166
|
-
return { id: context.token
|
|
164
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, task.status ?? "") };
|
|
167
165
|
});
|
|
168
166
|
const decodeResult = Effect.fn("MiniMaxVideo.decodeResult")(function* (response, context) {
|
|
169
167
|
const output = yield* decodeTask(response);
|
|
170
168
|
const task = output.value.task ?? output.value;
|
|
171
|
-
const status = MediaProtocol.
|
|
172
|
-
if (status === "
|
|
173
|
-
return yield* output.pending(context.token
|
|
169
|
+
const status = MediaProtocol.state(STATUS, task.status ?? "");
|
|
170
|
+
if (status === "running")
|
|
171
|
+
return yield* output.pending(context.token);
|
|
174
172
|
if (status === "failed")
|
|
175
173
|
return yield* failed(output, route.name, task.error?.code ?? undefined, task.error?.message ?? undefined);
|
|
176
174
|
if (status !== "completed")
|
|
177
|
-
return yield* output.ended("cancelled", `${route.name} task ${context.token
|
|
175
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
|
|
178
176
|
const url = task.content?.url ?? undefined;
|
|
179
177
|
if (url === undefined)
|
|
180
178
|
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
@@ -191,7 +189,7 @@ const decodeResult = Effect.fn("MiniMaxVideo.decodeResult")(function* (response,
|
|
|
191
189
|
usage: typeof total === "number" ? { type: "seconds", seconds: total } : undefined,
|
|
192
190
|
providerMetadata: {
|
|
193
191
|
minimax: {
|
|
194
|
-
taskId: context.token
|
|
192
|
+
taskId: context.token,
|
|
195
193
|
model: task.model ?? undefined,
|
|
196
194
|
resolution: task.resolution ?? undefined,
|
|
197
195
|
ratio: task.ratio ?? undefined,
|
|
@@ -208,30 +206,30 @@ const decodeHailuoStart = Effect.fn("MiniMaxHailuoVideo.decodeStart")(function*
|
|
|
208
206
|
const taskID = output.value.task_id ?? "";
|
|
209
207
|
if (taskID === "")
|
|
210
208
|
return yield* output.invalid(`${hailuoRoute.name} returned no task_id`);
|
|
211
|
-
return { token:
|
|
209
|
+
return { token: taskID, snapshot: { id: taskID, status: "running" } };
|
|
212
210
|
});
|
|
213
211
|
const decodeHailuoTask = hailuoRoute.decodeJson(HailuoTask);
|
|
214
212
|
const decodeHailuoStatus = Effect.fn("MiniMaxHailuoVideo.decodeStatus")(function* (response, context) {
|
|
215
213
|
const output = yield* decodeHailuoTask(response);
|
|
216
214
|
const status = MediaProtocol.status(HAILUO_STATUS, output.value.status ?? "");
|
|
217
215
|
// A failed task also carries its reason in `base_resp`; any other non-zero code is a failed read.
|
|
218
|
-
const error = status === "failed" ? undefined : baseError(output, output.value.base_resp);
|
|
216
|
+
const error = status.reason === "failed" ? undefined : baseError(output, output.value.base_resp);
|
|
219
217
|
if (error)
|
|
220
218
|
return yield* error;
|
|
221
|
-
return { id: context.token
|
|
219
|
+
return { id: context.token, ...status };
|
|
222
220
|
});
|
|
223
221
|
const decodeHailuoFile = hailuoRoute.decodeJson(HailuoFile);
|
|
224
222
|
const decodeHailuoResult = Effect.fn("MiniMaxHailuoVideo.decodeResult")(function* (response, context) {
|
|
225
223
|
const output = yield* decodeHailuoTask(response);
|
|
226
224
|
const task = output.value;
|
|
227
|
-
const status = MediaProtocol.
|
|
225
|
+
const status = MediaProtocol.state(HAILUO_STATUS, task.status ?? "");
|
|
228
226
|
const error = baseError(output, task.base_resp);
|
|
229
227
|
if (status === "failed")
|
|
230
228
|
return yield* error ?? failed(output, hailuoRoute.name, undefined, undefined);
|
|
231
229
|
if (error)
|
|
232
230
|
return yield* error;
|
|
233
231
|
if (status !== "completed")
|
|
234
|
-
return yield* output.pending(context.token
|
|
232
|
+
return yield* output.pending(context.token);
|
|
235
233
|
const fileID = task.file_id ?? "";
|
|
236
234
|
if (fileID === "")
|
|
237
235
|
return yield* output.invalid(`${hailuoRoute.name} completed without a file_id`);
|
|
@@ -253,7 +251,7 @@ const decodeHailuoResult = Effect.fn("MiniMaxHailuoVideo.decodeResult")(function
|
|
|
253
251
|
}),
|
|
254
252
|
],
|
|
255
253
|
providerMetadata: {
|
|
256
|
-
minimax: { taskId: context.token
|
|
254
|
+
minimax: { taskId: context.token, fileId: fileID },
|
|
257
255
|
},
|
|
258
256
|
});
|
|
259
257
|
});
|
|
@@ -263,12 +261,12 @@ const decodeHailuoResult = Effect.fn("MiniMaxHailuoVideo.decodeResult")(function
|
|
|
263
261
|
export const protocol = MediaProtocol.queued(route, {
|
|
264
262
|
token: Token,
|
|
265
263
|
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
266
|
-
status: { path: (token) => `${STATUS_PATH}/${token
|
|
267
|
-
result: { path: (token) => `${STATUS_PATH}/${token
|
|
264
|
+
status: { path: (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`, decode: decodeStatus },
|
|
265
|
+
result: { path: (token) => `${STATUS_PATH}/${encodeURIComponent(token)}`, decode: decodeResult },
|
|
268
266
|
// Cancels a queued task; MiniMax rejects it once the task is running.
|
|
269
|
-
cancel: { method: "DELETE", path: (token) => `${PATH}/${token
|
|
267
|
+
cancel: { method: "DELETE", path: (token) => `${PATH}/${encodeURIComponent(token)}` },
|
|
270
268
|
});
|
|
271
|
-
const hailuoStatusPath = (token) => `${HAILUO_STATUS_PATH}?task_id=${encodeURIComponent(token
|
|
269
|
+
const hailuoStatusPath = (token) => `${HAILUO_STATUS_PATH}?task_id=${encodeURIComponent(token)}`;
|
|
272
270
|
export const hailuoProtocol = MediaProtocol.queued(hailuoRoute, {
|
|
273
271
|
token: Token,
|
|
274
272
|
start: { body: { from: hailuoFromRequest }, decode: decodeHailuoStart },
|