@neta-art/generation 0.1.18 → 0.1.20
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/dist/cli/index.js +1 -1
- package/dist/{export-config-DJdXXiMl.js → export-config-BnNhaefG.js} +345 -67
- package/dist/export-config-BnNhaefG.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/export-config-DJdXXiMl.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { r as listBuiltinGenerationModels } from "../builtins-B4Agk9nt.js";
|
|
3
|
-
import { h as stringifyGenerationModelDeclaration, i as createGenerationClient, n as exportBuiltinModelConfigs, t as exportBuiltinModelConfig } from "../export-config-
|
|
3
|
+
import { h as stringifyGenerationModelDeclaration, i as createGenerationClient, n as exportBuiltinModelConfigs, t as exportBuiltinModelConfig } from "../export-config-BnNhaefG.js";
|
|
4
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
@@ -270,22 +270,22 @@ function mergeTextBlocks(declaration, content) {
|
|
|
270
270
|
|
|
271
271
|
//#endregion
|
|
272
272
|
//#region src/adapters/ark-video-generations.ts
|
|
273
|
-
const REQUEST_TIMEOUT_MS$
|
|
274
|
-
const DEFAULT_POLL_INTERVAL_SEC$
|
|
275
|
-
const DEFAULT_MAX_WAIT_SEC$
|
|
276
|
-
function sleep$
|
|
273
|
+
const REQUEST_TIMEOUT_MS$7 = 186e4;
|
|
274
|
+
const DEFAULT_POLL_INTERVAL_SEC$3 = 2;
|
|
275
|
+
const DEFAULT_MAX_WAIT_SEC$3 = 600;
|
|
276
|
+
function sleep$3(ms) {
|
|
277
277
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
278
278
|
}
|
|
279
|
-
function asString$
|
|
279
|
+
function asString$3(value) {
|
|
280
280
|
return typeof value === "string" && value ? value : void 0;
|
|
281
281
|
}
|
|
282
282
|
function asNumber$1(value) {
|
|
283
283
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
284
284
|
}
|
|
285
|
-
function asBoolean(value) {
|
|
285
|
+
function asBoolean$1(value) {
|
|
286
286
|
return typeof value === "boolean" ? value : void 0;
|
|
287
287
|
}
|
|
288
|
-
function normalizeStatus$
|
|
288
|
+
function normalizeStatus$3(value) {
|
|
289
289
|
const status = value.toLowerCase();
|
|
290
290
|
return status === "success" ? "succeeded" : status;
|
|
291
291
|
}
|
|
@@ -293,7 +293,7 @@ function getIntegerParameter(parameters, key, fallback) {
|
|
|
293
293
|
const value = parameters[key];
|
|
294
294
|
return typeof value === "number" && Number.isInteger(value) ? value : fallback;
|
|
295
295
|
}
|
|
296
|
-
function getMediaRole(block) {
|
|
296
|
+
function getMediaRole$1(block) {
|
|
297
297
|
const role = getBlockMeta(block)?.role;
|
|
298
298
|
return typeof role === "string" && role ? role : void 0;
|
|
299
299
|
}
|
|
@@ -306,7 +306,7 @@ function isReferenceMedia(item) {
|
|
|
306
306
|
function assertSingleRole(media, role, message) {
|
|
307
307
|
if (media.filter((item) => item.role === role).length > 1) throw new GenerationValidationError(message);
|
|
308
308
|
}
|
|
309
|
-
function classifyMedia(media) {
|
|
309
|
+
function classifyMedia$1(media) {
|
|
310
310
|
if (media.length === 0) return null;
|
|
311
311
|
for (const item of media) {
|
|
312
312
|
if (item.kind === "image" && item.role && item.role !== "first_frame" && item.role !== "last_frame" && item.role !== "reference_image") throw new GenerationValidationError("Image input must use meta.role first_frame, last_frame, or reference_image");
|
|
@@ -353,15 +353,15 @@ function buildMetadataContent(media, mode) {
|
|
|
353
353
|
}
|
|
354
354
|
return content;
|
|
355
355
|
}
|
|
356
|
-
async function resolveMedia(input, media) {
|
|
356
|
+
async function resolveMedia$1(input, media) {
|
|
357
357
|
return Promise.all(media.map(async (item) => ({
|
|
358
358
|
kind: item.kind,
|
|
359
359
|
role: item.role,
|
|
360
360
|
url: await input.context.resolveSource(item.source)
|
|
361
361
|
})));
|
|
362
362
|
}
|
|
363
|
-
function extractTaskId$
|
|
364
|
-
const taskId = asString$
|
|
363
|
+
function extractTaskId$3(response) {
|
|
364
|
+
const taskId = asString$3(response.task_id) ?? asString$3(response.id);
|
|
365
365
|
if (!taskId) throw new GenerationProviderError("Video generation provider did not return a task id", { details: { response } });
|
|
366
366
|
return taskId;
|
|
367
367
|
}
|
|
@@ -369,9 +369,9 @@ function normalizeTaskStatus(response) {
|
|
|
369
369
|
if (response.data) {
|
|
370
370
|
const wrapper = response.data;
|
|
371
371
|
const native = wrapper.data;
|
|
372
|
-
const status = normalizeStatus$
|
|
373
|
-
const videoUrl = asString$
|
|
374
|
-
const firstFrameUrl = asString$
|
|
372
|
+
const status = normalizeStatus$3(asString$3(native?.status) ?? asString$3(wrapper.status) ?? "unknown");
|
|
373
|
+
const videoUrl = asString$3(wrapper.result_url) ?? asString$3(native?.content?.video_url);
|
|
374
|
+
const firstFrameUrl = asString$3(wrapper.first_frame) ?? asString$3(native?.content?.first_frame);
|
|
375
375
|
const metadata = {
|
|
376
376
|
progress: wrapper.progress,
|
|
377
377
|
resolution: native?.resolution,
|
|
@@ -398,7 +398,7 @@ function normalizeTaskStatus(response) {
|
|
|
398
398
|
metadata: {}
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
|
-
async function requestJson$
|
|
401
|
+
async function requestJson$3(input, path, init) {
|
|
402
402
|
const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
|
|
403
403
|
...init,
|
|
404
404
|
headers: {
|
|
@@ -406,7 +406,7 @@ async function requestJson$2(input, path, init) {
|
|
|
406
406
|
"Content-Type": "application/json",
|
|
407
407
|
...init.headers
|
|
408
408
|
}
|
|
409
|
-
}, REQUEST_TIMEOUT_MS$
|
|
409
|
+
}, REQUEST_TIMEOUT_MS$7);
|
|
410
410
|
if (!response.ok) {
|
|
411
411
|
const body = await response.text().catch(() => response.statusText);
|
|
412
412
|
throw new GenerationProviderError("Video generation provider request failed", {
|
|
@@ -422,20 +422,20 @@ async function arkVideoGenerationsAdapter(input) {
|
|
|
422
422
|
const inputMedia = input.request.content.filter((block) => block.type === "image" || block.type === "video").map((block) => ({
|
|
423
423
|
kind: block.type,
|
|
424
424
|
source: block.source,
|
|
425
|
-
role: getMediaRole(block)
|
|
425
|
+
role: getMediaRole$1(block)
|
|
426
426
|
}));
|
|
427
|
-
const mode = classifyMedia(inputMedia);
|
|
428
|
-
const media = await resolveMedia(input, inputMedia);
|
|
429
|
-
const resolution = asString$
|
|
430
|
-
const ratio = asString$
|
|
427
|
+
const mode = classifyMedia$1(inputMedia);
|
|
428
|
+
const media = await resolveMedia$1(input, inputMedia);
|
|
429
|
+
const resolution = asString$3(input.parameters.resolution) ?? "720p";
|
|
430
|
+
const ratio = asString$3(input.request.parameters?.ratio) ?? asString$3(input.parameters.ratio) ?? "16:9";
|
|
431
431
|
const duration = getIntegerParameter(input.parameters, "duration", 5);
|
|
432
432
|
const fps = getIntegerParameter(input.parameters, "fps", 30);
|
|
433
|
-
const pollIntervalSec = getIntegerParameter(input.parameters, "poll_interval", DEFAULT_POLL_INTERVAL_SEC$
|
|
434
|
-
const maxWaitSec = getIntegerParameter(input.parameters, "max_wait", DEFAULT_MAX_WAIT_SEC$
|
|
435
|
-
const generateAudio = asBoolean(input.parameters.generate_audio) ?? true;
|
|
436
|
-
const returnLastFrame = asBoolean(input.parameters.return_last_frame) ?? true;
|
|
437
|
-
const cameraFixed = asBoolean(input.parameters.camera_fixed) ?? false;
|
|
438
|
-
const watermark = asBoolean(input.parameters.watermark) ?? false;
|
|
433
|
+
const pollIntervalSec = getIntegerParameter(input.parameters, "poll_interval", DEFAULT_POLL_INTERVAL_SEC$3);
|
|
434
|
+
const maxWaitSec = getIntegerParameter(input.parameters, "max_wait", DEFAULT_MAX_WAIT_SEC$3);
|
|
435
|
+
const generateAudio = asBoolean$1(input.parameters.generate_audio) ?? true;
|
|
436
|
+
const returnLastFrame = asBoolean$1(input.parameters.return_last_frame) ?? true;
|
|
437
|
+
const cameraFixed = asBoolean$1(input.parameters.camera_fixed) ?? false;
|
|
438
|
+
const watermark = asBoolean$1(input.parameters.watermark) ?? false;
|
|
439
439
|
const seed = asNumber$1(input.parameters.seed);
|
|
440
440
|
const payload = {
|
|
441
441
|
model: input.declaration.model,
|
|
@@ -458,14 +458,14 @@ async function arkVideoGenerationsAdapter(input) {
|
|
|
458
458
|
if (firstImage) payload.image = firstImage.url;
|
|
459
459
|
}
|
|
460
460
|
payload.metadata = metadata;
|
|
461
|
-
const taskId = extractTaskId$
|
|
461
|
+
const taskId = extractTaskId$3(await requestJson$3(input, "/v1/video/generations", {
|
|
462
462
|
method: "POST",
|
|
463
463
|
body: JSON.stringify(payload)
|
|
464
464
|
}));
|
|
465
465
|
const startedAt = Date.now();
|
|
466
466
|
while (Date.now() - startedAt <= maxWaitSec * 1e3) {
|
|
467
|
-
await sleep$
|
|
468
|
-
const rawStatus = await requestJson$
|
|
467
|
+
await sleep$3(pollIntervalSec * 1e3);
|
|
468
|
+
const rawStatus = await requestJson$3(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
|
|
469
469
|
const status = normalizeTaskStatus(rawStatus);
|
|
470
470
|
if (status.status === "succeeded") {
|
|
471
471
|
if (!status.videoUrl) throw new GenerationProviderError("Video generation succeeded but returned no video URL", { details: compactObject({
|
|
@@ -512,7 +512,7 @@ async function arkVideoGenerationsAdapter(input) {
|
|
|
512
512
|
|
|
513
513
|
//#endregion
|
|
514
514
|
//#region src/adapters/audio-speech.ts
|
|
515
|
-
const REQUEST_TIMEOUT_MS$
|
|
515
|
+
const REQUEST_TIMEOUT_MS$6 = 21e4;
|
|
516
516
|
const QWEN_MODELS = new Set([
|
|
517
517
|
"qwen-tts",
|
|
518
518
|
"qwen-audio-3.0-tts-plus",
|
|
@@ -520,7 +520,7 @@ const QWEN_MODELS = new Set([
|
|
|
520
520
|
]);
|
|
521
521
|
const QWEN_AUDIO_3_MODELS = new Set(["qwen-audio-3.0-tts-plus", "qwen-audio-3.0-tts-flash"]);
|
|
522
522
|
const HIGGS_MODEL = "higgs-tts";
|
|
523
|
-
function isRecord$
|
|
523
|
+
function isRecord$5(value) {
|
|
524
524
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
525
525
|
}
|
|
526
526
|
function textBlocks(input) {
|
|
@@ -641,8 +641,8 @@ function providerError(response, rawBody) {
|
|
|
641
641
|
const requestId = requestIdFromHeaders(response.headers);
|
|
642
642
|
const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
|
|
643
643
|
const parsed = contentType.includes("application/json") || contentType.includes("+json") ? parseJson(rawBody) : void 0;
|
|
644
|
-
const parsedRecord = isRecord$
|
|
645
|
-
const errorRecord = isRecord$
|
|
644
|
+
const parsedRecord = isRecord$5(parsed) ? parsed : void 0;
|
|
645
|
+
const errorRecord = isRecord$5(parsedRecord?.error) ? parsedRecord.error : void 0;
|
|
646
646
|
const message = nonEmptyString(errorRecord?.message) ?? (rawBody.trim() ? rawBody : void 0) ?? (response.statusText.trim() ? response.statusText : void 0) ?? "Audio speech provider request failed";
|
|
647
647
|
const code = nonEmptyString(errorRecord?.code);
|
|
648
648
|
return new GenerationProviderError(message, {
|
|
@@ -665,7 +665,7 @@ function unsupportedSuccessResponse(response, rawBody) {
|
|
|
665
665
|
}
|
|
666
666
|
function parseSuccessResponse(response, rawBody) {
|
|
667
667
|
const parsed = parseJson(rawBody);
|
|
668
|
-
if (!isRecord$
|
|
668
|
+
if (!isRecord$5(parsed)) throw unsupportedSuccessResponse(response, rawBody);
|
|
669
669
|
const urlValue = nonEmptyString(parsed.url);
|
|
670
670
|
const contentType = nonEmptyString(parsed.content_type);
|
|
671
671
|
if (!urlValue || parsed.media_type !== "audio" || !contentType || !/^audio\/[^\s/;]+(?:\s*;.*)?$/i.test(contentType)) throw unsupportedSuccessResponse(response, rawBody);
|
|
@@ -699,7 +699,7 @@ async function generateAudioSpeech(input) {
|
|
|
699
699
|
"Content-Type": "application/json"
|
|
700
700
|
},
|
|
701
701
|
body: JSON.stringify(buildPayload$2(input))
|
|
702
|
-
}, REQUEST_TIMEOUT_MS$
|
|
702
|
+
}, REQUEST_TIMEOUT_MS$6);
|
|
703
703
|
const rawBody = await response.text().catch(() => "");
|
|
704
704
|
if (!response.ok) throw providerError(response, rawBody);
|
|
705
705
|
return [parseSuccessResponse(response, rawBody)];
|
|
@@ -708,7 +708,7 @@ const audioSpeechAdapter = Object.assign(generateAudioSpeech, { validate: valida
|
|
|
708
708
|
|
|
709
709
|
//#endregion
|
|
710
710
|
//#region src/adapters/gemini-generate-content.ts
|
|
711
|
-
const REQUEST_TIMEOUT_MS$
|
|
711
|
+
const REQUEST_TIMEOUT_MS$5 = 3e5;
|
|
712
712
|
const MARKDOWN_IMAGE_DATA_URI_PATTERN = /!\[[^\]]*\]\(data:([^;]+);base64,([^)]+)\)/;
|
|
713
713
|
function isHttpUrl(value) {
|
|
714
714
|
return value.startsWith("http://") || value.startsWith("https://");
|
|
@@ -823,7 +823,7 @@ async function geminiGenerateContentAdapter(input) {
|
|
|
823
823
|
"Content-Type": "application/json"
|
|
824
824
|
},
|
|
825
825
|
body: JSON.stringify(payload)
|
|
826
|
-
}, REQUEST_TIMEOUT_MS$
|
|
826
|
+
}, REQUEST_TIMEOUT_MS$5);
|
|
827
827
|
if (!response.ok) {
|
|
828
828
|
const body = await response.text().catch(() => response.statusText);
|
|
829
829
|
throw new GenerationProviderError("Gemini generation provider request failed", {
|
|
@@ -840,9 +840,9 @@ async function geminiGenerateContentAdapter(input) {
|
|
|
840
840
|
|
|
841
841
|
//#endregion
|
|
842
842
|
//#region src/adapters/kling-video-generations.ts
|
|
843
|
-
const REQUEST_TIMEOUT_MS$
|
|
844
|
-
const DEFAULT_POLL_INTERVAL_SEC$
|
|
845
|
-
const DEFAULT_MAX_WAIT_SEC$
|
|
843
|
+
const REQUEST_TIMEOUT_MS$4 = 186e4;
|
|
844
|
+
const DEFAULT_POLL_INTERVAL_SEC$2 = 5;
|
|
845
|
+
const DEFAULT_MAX_WAIT_SEC$2 = 900;
|
|
846
846
|
const KLING_MODELS = {
|
|
847
847
|
"kling-text-to-video": {
|
|
848
848
|
submitPath: "/kling/v1/videos/text2video",
|
|
@@ -866,19 +866,19 @@ const KLING_MODELS = {
|
|
|
866
866
|
imageMode: "multi"
|
|
867
867
|
}
|
|
868
868
|
};
|
|
869
|
-
function sleep$
|
|
869
|
+
function sleep$2(ms) {
|
|
870
870
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
871
871
|
}
|
|
872
|
-
function asString$
|
|
872
|
+
function asString$2(value) {
|
|
873
873
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
874
874
|
}
|
|
875
|
-
function asInteger$
|
|
875
|
+
function asInteger$2(value, fallback) {
|
|
876
876
|
return typeof value === "number" && Number.isInteger(value) ? value : fallback;
|
|
877
877
|
}
|
|
878
878
|
function asNumber(value) {
|
|
879
879
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
880
880
|
}
|
|
881
|
-
function isRecord$
|
|
881
|
+
function isRecord$4(value) {
|
|
882
882
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
883
883
|
}
|
|
884
884
|
function providerMeta(input) {
|
|
@@ -887,7 +887,7 @@ function providerMeta(input) {
|
|
|
887
887
|
delete rest.role;
|
|
888
888
|
return rest;
|
|
889
889
|
}
|
|
890
|
-
function normalizeStatus$
|
|
890
|
+
function normalizeStatus$2(value) {
|
|
891
891
|
const status = String(value ?? "").trim().toLowerCase();
|
|
892
892
|
if (status === "success" || status === "succeed" || status === "succeeded" || status === "completed") return "succeeded";
|
|
893
893
|
if (status === "queued" || status === "processing" || status === "in_progress" || status === "not_start" || status === "submitted") return "processing";
|
|
@@ -961,12 +961,12 @@ function buildPayload$1(input, model, prompt, images) {
|
|
|
961
961
|
model_name: model.defaultModelName
|
|
962
962
|
};
|
|
963
963
|
if (prompt) payload.prompt = prompt;
|
|
964
|
-
if (!payload.duration) payload.duration = String(asInteger$
|
|
965
|
-
if (!payload.mode) payload.mode = asString$
|
|
964
|
+
if (!payload.duration) payload.duration = String(asInteger$2(input.parameters.duration, 5));
|
|
965
|
+
if (!payload.mode) payload.mode = asString$2(input.parameters.mode) ?? "std";
|
|
966
966
|
if (payload.cfg_scale === void 0) payload.cfg_scale = asNumber(input.parameters.cfg_scale) ?? .5;
|
|
967
|
-
if (!payload.aspect_ratio) payload.aspect_ratio = asString$
|
|
968
|
-
if (payload.negative_prompt === void 0 && asString$
|
|
969
|
-
if (payload.sound === void 0 && asString$
|
|
967
|
+
if (!payload.aspect_ratio) payload.aspect_ratio = asString$2(input.parameters.aspect_ratio) ?? "16:9";
|
|
968
|
+
if (payload.negative_prompt === void 0 && asString$2(input.parameters.negative_prompt)) payload.negative_prompt = input.parameters.negative_prompt;
|
|
969
|
+
if (payload.sound === void 0 && asString$2(input.parameters.sound)) payload.sound = input.parameters.sound;
|
|
970
970
|
if (model.imageMode === "single" && images[0] && !hasPlainImagePayload(payload)) {
|
|
971
971
|
payload.image = images[0].url;
|
|
972
972
|
if (images[1] && payload.image_tail === void 0) payload.image_tail = images[1].url;
|
|
@@ -976,18 +976,18 @@ function buildPayload$1(input, model, prompt, images) {
|
|
|
976
976
|
if (payload.seed === void 0 && input.parameters.seed !== void 0) payload.seed = input.parameters.seed;
|
|
977
977
|
return payload;
|
|
978
978
|
}
|
|
979
|
-
function extractTaskId$
|
|
980
|
-
const taskId = asString$
|
|
979
|
+
function extractTaskId$2(response) {
|
|
980
|
+
const taskId = asString$2(response.task_id) ?? asString$2(response.id) ?? asString$2(response.data?.task_id) ?? asString$2(response.data?.id);
|
|
981
981
|
if (!taskId) throw new GenerationProviderError("Kling video provider did not return a task id", { details: { response } });
|
|
982
982
|
return taskId;
|
|
983
983
|
}
|
|
984
984
|
function extractStatus(response) {
|
|
985
985
|
const wrapper = response.data;
|
|
986
986
|
const native = wrapper?.data;
|
|
987
|
-
const status = normalizeStatus$
|
|
987
|
+
const status = normalizeStatus$2(native?.status ?? wrapper?.task_status ?? wrapper?.status ?? response.task_status ?? response.status);
|
|
988
988
|
const firstVideo = wrapper?.task_result?.videos?.[0] ?? native?.task_result?.videos?.[0];
|
|
989
|
-
const videoUrl = asString$
|
|
990
|
-
const message = asString$
|
|
989
|
+
const videoUrl = asString$2(firstVideo?.url) ?? asString$2(wrapper?.result_url) ?? asString$2(wrapper?.video_url) ?? asString$2(wrapper?.url) ?? asString$2(native?.content?.video_url) ?? asString$2(response.metadata?.url) ?? asString$2(response.result_url) ?? asString$2(response.video_url) ?? asString$2(response.url);
|
|
990
|
+
const message = asString$2(wrapper?.task_status_msg) ?? asString$2(response.error?.message) ?? asString$2(response.message);
|
|
991
991
|
return {
|
|
992
992
|
status,
|
|
993
993
|
videoUrl,
|
|
@@ -1000,7 +1000,7 @@ function extractStatus(response) {
|
|
|
1000
1000
|
})
|
|
1001
1001
|
};
|
|
1002
1002
|
}
|
|
1003
|
-
async function requestJson$
|
|
1003
|
+
async function requestJson$2(input, path, init) {
|
|
1004
1004
|
const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
|
|
1005
1005
|
...init,
|
|
1006
1006
|
headers: {
|
|
@@ -1008,7 +1008,7 @@ async function requestJson$1(input, path, init) {
|
|
|
1008
1008
|
"Content-Type": "application/json",
|
|
1009
1009
|
...init.headers
|
|
1010
1010
|
}
|
|
1011
|
-
}, REQUEST_TIMEOUT_MS$
|
|
1011
|
+
}, REQUEST_TIMEOUT_MS$4);
|
|
1012
1012
|
const body = await response.text();
|
|
1013
1013
|
let parsed = {};
|
|
1014
1014
|
try {
|
|
@@ -1020,7 +1020,7 @@ async function requestJson$1(input, path, init) {
|
|
|
1020
1020
|
});
|
|
1021
1021
|
}
|
|
1022
1022
|
if (!response.ok) {
|
|
1023
|
-
const details = isRecord$
|
|
1023
|
+
const details = isRecord$4(parsed) ? { details: parsed } : {};
|
|
1024
1024
|
throw new GenerationProviderError("Kling video provider request failed", {
|
|
1025
1025
|
status: response.status,
|
|
1026
1026
|
body,
|
|
@@ -1038,16 +1038,16 @@ async function klingVideoGenerationsAdapter(input) {
|
|
|
1038
1038
|
if (!prompt && model.allowPromptlessOmni && !hasPromptlessOmniPayload(meta, images)) throw new GenerationValidationError("Prompt text or Omni media input is required");
|
|
1039
1039
|
if (model.imageMode === "single" && images.length === 0 && !hasPlainImagePayload(meta)) throw new GenerationValidationError("Image input is required");
|
|
1040
1040
|
if (model.imageMode === "multi" && images.length === 0 && !hasMultiImagePayload(meta)) throw new GenerationValidationError("Multi-image input is required");
|
|
1041
|
-
const taskId = extractTaskId$
|
|
1041
|
+
const taskId = extractTaskId$2(await requestJson$2(input, model.submitPath, {
|
|
1042
1042
|
method: "POST",
|
|
1043
1043
|
body: JSON.stringify(buildPayload$1(input, model, prompt, images))
|
|
1044
1044
|
}));
|
|
1045
|
-
const pollIntervalSec = asInteger$
|
|
1046
|
-
const maxWaitSec = asInteger$
|
|
1045
|
+
const pollIntervalSec = asInteger$2(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$2);
|
|
1046
|
+
const maxWaitSec = asInteger$2(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$2);
|
|
1047
1047
|
const startedAt = Date.now();
|
|
1048
1048
|
while (Date.now() - startedAt <= maxWaitSec * 1e3) {
|
|
1049
|
-
await sleep$
|
|
1050
|
-
const rawStatus = await requestJson$
|
|
1049
|
+
await sleep$2(pollIntervalSec * 1e3);
|
|
1050
|
+
const rawStatus = await requestJson$2(input, `${model.submitPath}/${encodeURIComponent(taskId)}`, { method: "GET" });
|
|
1051
1051
|
const status = extractStatus(rawStatus);
|
|
1052
1052
|
if (status.status === "succeeded") {
|
|
1053
1053
|
if (!status.videoUrl) throw new GenerationProviderError("Kling video generation succeeded but returned no video URL", { details: compactObject({
|
|
@@ -1077,6 +1077,283 @@ async function klingVideoGenerationsAdapter(input) {
|
|
|
1077
1077
|
throw new GenerationTimeoutError("Timed out waiting for Kling video generation", { taskId });
|
|
1078
1078
|
}
|
|
1079
1079
|
|
|
1080
|
+
//#endregion
|
|
1081
|
+
//#region src/adapters/minimax-h3-video-generations.ts
|
|
1082
|
+
const REQUEST_TIMEOUT_MS$3 = 186e4;
|
|
1083
|
+
const DEFAULT_POLL_INTERVAL_SEC$1 = 2;
|
|
1084
|
+
const DEFAULT_MAX_WAIT_SEC$1 = 600;
|
|
1085
|
+
const MIN_DURATION_SEC = 4;
|
|
1086
|
+
const MAX_DURATION_SEC = 15;
|
|
1087
|
+
const MAX_MEDIA_COUNT = 12;
|
|
1088
|
+
const MAX_REFERENCE_IMAGES = 9;
|
|
1089
|
+
const MAX_REFERENCE_VIDEOS = 3;
|
|
1090
|
+
const MAX_REFERENCE_AUDIO = 3;
|
|
1091
|
+
const DEFAULT_RATIO = "16:9";
|
|
1092
|
+
const ADAPTIVE_RATIO = "adaptive";
|
|
1093
|
+
const H3_RATIOS = [
|
|
1094
|
+
"adaptive",
|
|
1095
|
+
"21:9",
|
|
1096
|
+
"16:9",
|
|
1097
|
+
"4:3",
|
|
1098
|
+
"1:1",
|
|
1099
|
+
"3:4",
|
|
1100
|
+
"9:16"
|
|
1101
|
+
];
|
|
1102
|
+
function sleep$1(ms) {
|
|
1103
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1104
|
+
}
|
|
1105
|
+
function asString$1(value) {
|
|
1106
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
1107
|
+
}
|
|
1108
|
+
function asInteger$1(value, fallback) {
|
|
1109
|
+
return typeof value === "number" && Number.isInteger(value) ? value : fallback;
|
|
1110
|
+
}
|
|
1111
|
+
function asBoolean(value, fallback) {
|
|
1112
|
+
return typeof value === "boolean" ? value : fallback;
|
|
1113
|
+
}
|
|
1114
|
+
function isRecord$3(value) {
|
|
1115
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1116
|
+
}
|
|
1117
|
+
function normalizeStatus$1(value) {
|
|
1118
|
+
const status = String(value ?? "").trim().toLowerCase();
|
|
1119
|
+
if ([
|
|
1120
|
+
"success",
|
|
1121
|
+
"succeed",
|
|
1122
|
+
"succeeded",
|
|
1123
|
+
"completed"
|
|
1124
|
+
].includes(status)) return "succeeded";
|
|
1125
|
+
if ([
|
|
1126
|
+
"queued",
|
|
1127
|
+
"processing",
|
|
1128
|
+
"in_progress",
|
|
1129
|
+
"running",
|
|
1130
|
+
"submitted",
|
|
1131
|
+
"not_start"
|
|
1132
|
+
].includes(status)) return "processing";
|
|
1133
|
+
if ([
|
|
1134
|
+
"failure",
|
|
1135
|
+
"failed",
|
|
1136
|
+
"error",
|
|
1137
|
+
"cancelled",
|
|
1138
|
+
"canceled",
|
|
1139
|
+
"expired"
|
|
1140
|
+
].includes(status)) return "failed";
|
|
1141
|
+
return status || "unknown";
|
|
1142
|
+
}
|
|
1143
|
+
function getMediaRole(block) {
|
|
1144
|
+
const role = getBlockMeta(block)?.role;
|
|
1145
|
+
return typeof role === "string" && role.trim() ? role.trim() : void 0;
|
|
1146
|
+
}
|
|
1147
|
+
function getH3InputMedia(input) {
|
|
1148
|
+
return input.request.content.filter((block) => block.type === "image" || block.type === "video" || block.type === "audio").map((block) => ({
|
|
1149
|
+
kind: block.type,
|
|
1150
|
+
source: block.source,
|
|
1151
|
+
role: getMediaRole(block)
|
|
1152
|
+
}));
|
|
1153
|
+
}
|
|
1154
|
+
function classifyMedia(media) {
|
|
1155
|
+
let firstFrames = 0;
|
|
1156
|
+
let lastFrames = 0;
|
|
1157
|
+
let referenceImages = 0;
|
|
1158
|
+
let referenceVideos = 0;
|
|
1159
|
+
let referenceAudio = 0;
|
|
1160
|
+
for (const item of media) {
|
|
1161
|
+
if (!item.role) throw new GenerationValidationError(`${item.kind} input must use a MiniMax H3 role`);
|
|
1162
|
+
if (item.kind === "image") if (item.role === "first_frame") firstFrames += 1;
|
|
1163
|
+
else if (item.role === "last_frame") lastFrames += 1;
|
|
1164
|
+
else if (item.role === "reference_image") referenceImages += 1;
|
|
1165
|
+
else throw new GenerationValidationError(`image role is not supported by MiniMax H3: ${item.role}`);
|
|
1166
|
+
else if (item.kind === "video") {
|
|
1167
|
+
if (item.role !== "reference_video") throw new GenerationValidationError(`video role must be reference_video for MiniMax H3`);
|
|
1168
|
+
referenceVideos += 1;
|
|
1169
|
+
} else {
|
|
1170
|
+
if (item.role !== "reference_audio") throw new GenerationValidationError(`audio role must be reference_audio for MiniMax H3`);
|
|
1171
|
+
referenceAudio += 1;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
if (firstFrames > 1 || lastFrames > 1) throw new GenerationValidationError("MiniMax H3 supports at most one first_frame and one last_frame image");
|
|
1175
|
+
if (referenceImages > MAX_REFERENCE_IMAGES) throw new GenerationValidationError(`MiniMax H3 supports at most ${MAX_REFERENCE_IMAGES} reference images`);
|
|
1176
|
+
if (referenceVideos > MAX_REFERENCE_VIDEOS) throw new GenerationValidationError(`MiniMax H3 supports at most ${MAX_REFERENCE_VIDEOS} reference videos`);
|
|
1177
|
+
if (referenceAudio > MAX_REFERENCE_AUDIO) throw new GenerationValidationError(`MiniMax H3 supports at most ${MAX_REFERENCE_AUDIO} reference audio files`);
|
|
1178
|
+
if (media.length > MAX_MEDIA_COUNT) throw new GenerationValidationError(`MiniMax H3 supports at most ${MAX_MEDIA_COUNT} media items; received ${referenceImages} reference images, ${referenceVideos} reference videos, ${referenceAudio} reference audio inputs, and ${firstFrames + lastFrames} frame images`);
|
|
1179
|
+
const hasFrames = firstFrames + lastFrames > 0;
|
|
1180
|
+
const hasReferences = referenceImages + referenceVideos + referenceAudio > 0;
|
|
1181
|
+
if (hasFrames && hasReferences) throw new GenerationValidationError("MiniMax H3 cannot mix frame images with reference materials");
|
|
1182
|
+
if (hasFrames) return "frame";
|
|
1183
|
+
if (hasReferences) return "reference";
|
|
1184
|
+
return "text";
|
|
1185
|
+
}
|
|
1186
|
+
async function resolveMedia(input, media) {
|
|
1187
|
+
return Promise.all(media.map(async (item) => ({
|
|
1188
|
+
kind: item.kind,
|
|
1189
|
+
role: item.role,
|
|
1190
|
+
url: await input.context.resolveSource(item.source)
|
|
1191
|
+
})));
|
|
1192
|
+
}
|
|
1193
|
+
function buildContent(prompt, media) {
|
|
1194
|
+
return [{
|
|
1195
|
+
type: "text",
|
|
1196
|
+
text: prompt
|
|
1197
|
+
}, ...media.map((item) => {
|
|
1198
|
+
if (item.kind === "image") return {
|
|
1199
|
+
type: "image_url",
|
|
1200
|
+
image_url: { url: item.url },
|
|
1201
|
+
role: item.role
|
|
1202
|
+
};
|
|
1203
|
+
if (item.kind === "video") return {
|
|
1204
|
+
type: "video_url",
|
|
1205
|
+
video_url: { url: item.url },
|
|
1206
|
+
role: item.role
|
|
1207
|
+
};
|
|
1208
|
+
return {
|
|
1209
|
+
type: "audio_url",
|
|
1210
|
+
audio_url: { url: item.url },
|
|
1211
|
+
role: item.role
|
|
1212
|
+
};
|
|
1213
|
+
})];
|
|
1214
|
+
}
|
|
1215
|
+
function resolveResolution(value) {
|
|
1216
|
+
const resolution = (asString$1(value) ?? "768P").toUpperCase();
|
|
1217
|
+
if (resolution !== "768P" && resolution !== "2K") throw new GenerationValidationError("MiniMax H3 resolution must be 768P or 2K");
|
|
1218
|
+
return resolution;
|
|
1219
|
+
}
|
|
1220
|
+
function resolveDuration(value) {
|
|
1221
|
+
const duration = asInteger$1(value, 5);
|
|
1222
|
+
if (duration < MIN_DURATION_SEC || duration > MAX_DURATION_SEC) throw new GenerationValidationError("MiniMax H3 duration must be an integer between 4 and 15");
|
|
1223
|
+
return duration;
|
|
1224
|
+
}
|
|
1225
|
+
function resolveRatio(value, mode) {
|
|
1226
|
+
const requested = asString$1(value) ?? DEFAULT_RATIO;
|
|
1227
|
+
if (!H3_RATIOS.includes(requested)) throw new GenerationValidationError(`MiniMax H3 ratio must be one of: ${H3_RATIOS.join(", ")}`);
|
|
1228
|
+
if (mode === "text") return requested === ADAPTIVE_RATIO ? DEFAULT_RATIO : requested;
|
|
1229
|
+
return ADAPTIVE_RATIO;
|
|
1230
|
+
}
|
|
1231
|
+
function extractTaskId$1(response) {
|
|
1232
|
+
const data = isRecord$3(response.data) ? response.data : void 0;
|
|
1233
|
+
const taskId = asString$1(response.task_id) ?? asString$1(response.id) ?? asString$1(data?.task_id) ?? asString$1(data?.id);
|
|
1234
|
+
if (!taskId) throw new GenerationProviderError("MiniMax H3 provider did not return a task id", { details: { response } });
|
|
1235
|
+
return taskId;
|
|
1236
|
+
}
|
|
1237
|
+
function isTaskPayload(value) {
|
|
1238
|
+
return [
|
|
1239
|
+
"status",
|
|
1240
|
+
"task",
|
|
1241
|
+
"result_url",
|
|
1242
|
+
"video_url",
|
|
1243
|
+
"url",
|
|
1244
|
+
"error",
|
|
1245
|
+
"progress",
|
|
1246
|
+
"fail_reason"
|
|
1247
|
+
].some((key) => key in value);
|
|
1248
|
+
}
|
|
1249
|
+
function unwrapTaskPayload(response) {
|
|
1250
|
+
const data = isRecord$3(response.data) ? response.data : void 0;
|
|
1251
|
+
return data && !isTaskPayload(response) ? data : response;
|
|
1252
|
+
}
|
|
1253
|
+
function extractTaskStatus(response) {
|
|
1254
|
+
const payload = unwrapTaskPayload(response);
|
|
1255
|
+
const task = isRecord$3(payload.task) ? payload.task : payload;
|
|
1256
|
+
const metadata = isRecord$3(payload.metadata) ? payload.metadata : isRecord$3(task.metadata) ? task.metadata : void 0;
|
|
1257
|
+
const content = isRecord$3(task.content) ? task.content : void 0;
|
|
1258
|
+
const status = normalizeStatus$1(payload.status ?? task.status);
|
|
1259
|
+
const videoUrl = asString$1(metadata?.url) ?? asString$1(payload.result_url) ?? asString$1(payload.video_url) ?? asString$1(payload.url) ?? asString$1(task.result_url) ?? asString$1(task.video_url) ?? asString$1(task.url) ?? asString$1(content?.video_url) ?? asString$1(content?.url);
|
|
1260
|
+
const error = isRecord$3(payload.error) ? payload.error : isRecord$3(task.error) ? task.error : void 0;
|
|
1261
|
+
const message = asString$1(error?.message) ?? asString$1(payload.fail_reason) ?? asString$1(payload.message) ?? asString$1(task.fail_reason) ?? asString$1(task.message) ?? asString$1(response.message);
|
|
1262
|
+
const outputMetadata = compactObject({
|
|
1263
|
+
progress: payload.progress ?? task.progress,
|
|
1264
|
+
resolution: payload.resolution ?? task.resolution,
|
|
1265
|
+
duration: payload.duration ?? task.duration,
|
|
1266
|
+
ratio: payload.ratio ?? task.ratio
|
|
1267
|
+
});
|
|
1268
|
+
return {
|
|
1269
|
+
status: error && status === "unknown" ? "failed" : status,
|
|
1270
|
+
videoUrl,
|
|
1271
|
+
message,
|
|
1272
|
+
metadata: outputMetadata
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
async function requestJson$1(input, path, init) {
|
|
1276
|
+
const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
|
|
1277
|
+
...init,
|
|
1278
|
+
headers: {
|
|
1279
|
+
Authorization: `Bearer ${input.context.apiKey}`,
|
|
1280
|
+
"Content-Type": "application/json",
|
|
1281
|
+
...init.headers
|
|
1282
|
+
}
|
|
1283
|
+
}, REQUEST_TIMEOUT_MS$3);
|
|
1284
|
+
const body = await response.text();
|
|
1285
|
+
let parsed = {};
|
|
1286
|
+
try {
|
|
1287
|
+
parsed = body ? JSON.parse(body) : {};
|
|
1288
|
+
} catch {
|
|
1289
|
+
throw new GenerationProviderError("MiniMax H3 provider returned invalid JSON", {
|
|
1290
|
+
status: response.status,
|
|
1291
|
+
body
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
if (!response.ok) throw new GenerationProviderError("MiniMax H3 provider request failed", {
|
|
1295
|
+
status: response.status,
|
|
1296
|
+
body,
|
|
1297
|
+
...isRecord$3(parsed) ? { details: parsed } : {}
|
|
1298
|
+
});
|
|
1299
|
+
return parsed;
|
|
1300
|
+
}
|
|
1301
|
+
async function minimaxH3VideoGenerationsAdapter(input) {
|
|
1302
|
+
const prompt = mergeTextBlocks(input.declaration, input.request.content);
|
|
1303
|
+
if (!prompt) throw new GenerationValidationError("Prompt text is required");
|
|
1304
|
+
const inputMedia = getH3InputMedia(input);
|
|
1305
|
+
const mode = classifyMedia(inputMedia);
|
|
1306
|
+
const media = await resolveMedia(input, inputMedia);
|
|
1307
|
+
const duration = resolveDuration(input.parameters.duration);
|
|
1308
|
+
const resolution = resolveResolution(input.parameters.resolution);
|
|
1309
|
+
const ratio = resolveRatio(input.parameters.ratio, mode);
|
|
1310
|
+
const pollIntervalSec = Math.max(1, asInteger$1(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$1));
|
|
1311
|
+
const maxWaitSec = Math.max(30, asInteger$1(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$1));
|
|
1312
|
+
const aigcWatermark = asBoolean(input.parameters.aigc_watermark, false);
|
|
1313
|
+
const payload = {
|
|
1314
|
+
model: input.declaration.model,
|
|
1315
|
+
content: buildContent(prompt, media),
|
|
1316
|
+
resolution,
|
|
1317
|
+
duration,
|
|
1318
|
+
ratio,
|
|
1319
|
+
aigc_watermark: aigcWatermark
|
|
1320
|
+
};
|
|
1321
|
+
const taskId = extractTaskId$1(await requestJson$1(input, "/v1/video/generations", {
|
|
1322
|
+
method: "POST",
|
|
1323
|
+
body: JSON.stringify(payload)
|
|
1324
|
+
}));
|
|
1325
|
+
const startedAt = Date.now();
|
|
1326
|
+
while (Date.now() - startedAt <= maxWaitSec * 1e3) {
|
|
1327
|
+
await sleep$1(pollIntervalSec * 1e3);
|
|
1328
|
+
const rawStatus = await requestJson$1(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
|
|
1329
|
+
const status = extractTaskStatus(rawStatus);
|
|
1330
|
+
if (status.status === "succeeded") {
|
|
1331
|
+
if (!status.videoUrl) throw new GenerationProviderError("MiniMax H3 generation succeeded but returned no video URL", { details: compactObject({
|
|
1332
|
+
taskId,
|
|
1333
|
+
rawStatus,
|
|
1334
|
+
metadata: status.metadata
|
|
1335
|
+
}) });
|
|
1336
|
+
return [{
|
|
1337
|
+
type: "video",
|
|
1338
|
+
source: {
|
|
1339
|
+
type: "url",
|
|
1340
|
+
url: status.videoUrl
|
|
1341
|
+
},
|
|
1342
|
+
meta: {
|
|
1343
|
+
task_id: taskId,
|
|
1344
|
+
status: status.status,
|
|
1345
|
+
...status.metadata
|
|
1346
|
+
}
|
|
1347
|
+
}];
|
|
1348
|
+
}
|
|
1349
|
+
if (status.status === "failed") throw new GenerationProviderError(`MiniMax H3 generation failed${status.message ? `: ${status.message}` : ""}`, { details: compactObject({
|
|
1350
|
+
taskId,
|
|
1351
|
+
rawStatus
|
|
1352
|
+
}) });
|
|
1353
|
+
}
|
|
1354
|
+
throw new GenerationTimeoutError("Timed out waiting for MiniMax H3 video generation", { taskId });
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1080
1357
|
//#endregion
|
|
1081
1358
|
//#region src/adapters/openai-image-edits.ts
|
|
1082
1359
|
const REQUEST_TIMEOUT_MS$2 = 3e5;
|
|
@@ -1590,6 +1867,7 @@ const builtinGenerationAdapters = {
|
|
|
1590
1867
|
"openai.audioSpeech": audioSpeechAdapter,
|
|
1591
1868
|
"gemini.generateContent": geminiGenerateContentAdapter,
|
|
1592
1869
|
"kling.videoGenerations": klingVideoGenerationsAdapter,
|
|
1870
|
+
"minimax.h3VideoGenerations": minimaxH3VideoGenerationsAdapter,
|
|
1593
1871
|
"openai.imageEdits": openAiImageEditsAdapter,
|
|
1594
1872
|
"openai.images": openAiImagesAdapter,
|
|
1595
1873
|
"suno.tasks": sunoTasksAdapter
|
|
@@ -1943,5 +2221,5 @@ async function exportBuiltinModelConfigs(directory) {
|
|
|
1943
2221
|
}
|
|
1944
2222
|
|
|
1945
2223
|
//#endregion
|
|
1946
|
-
export {
|
|
1947
|
-
//# sourceMappingURL=export-config-
|
|
2224
|
+
export { resolveGenerationMeta as A, minimaxH3VideoGenerationsAdapter as C, arkVideoGenerationsAdapter as D, audioSpeechAdapter as E, GenerationProviderError as F, GenerationTimeoutError as I, GenerationUnsupportedAdapterError as L, validateGenerationContent as M, GenerationConfigError as N, mergeGenerationMeta as O, GenerationError as P, GenerationValidationError as R, openAiImageEditsAdapter as S, geminiGenerateContentAdapter as T, writeGenerationModelDeclarations as _, createGenerationClientFromDirectory as a, sunoTasksAdapter as b, defaultGenerationSourceResolver as c, parseGenerationModelDeclaration as d, readGenerationModelDeclaration as f, writeGenerationModelDeclaration as g, stringifyGenerationModelDeclaration as h, createGenerationClient as i, resolveGenerationParameters as j, mergeTextBlocks as k, isGenerationModelDeclaration as l, readGenerationModelDeclarationsFromFiles as m, exportBuiltinModelConfigs as n, createGenerationClientFromFile as o, readGenerationModelDeclarationsFromDirectory as p, stringifyBuiltinModelConfig as r, createGenerationClientFromFiles as s, exportBuiltinModelConfig as t, mergeGenerationModelDeclarations as u, builtinGenerationAdapters as v, klingVideoGenerationsAdapter as w, openAiImagesAdapter as x, getGenerationAdapter as y };
|
|
2225
|
+
//# sourceMappingURL=export-config-BnNhaefG.js.map
|