@neta-art/generation 0.1.21 → 0.1.23

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.
@@ -1,4 +1,4 @@
1
- import { a as compactArray, c as slugifyFileName, i as cloneJson, l as MODEL_SCHEMA, n as getBuiltinGenerationModel, o as compactObject, r as listBuiltinGenerationModels, s as getBlockMeta, t as builtinGenerationModels } from "./builtins-B4Agk9nt.js";
1
+ import { a as compactArray, c as slugifyFileName, i as cloneJson, l as MODEL_SCHEMA, n as getBuiltinGenerationModel, o as compactObject, r as listBuiltinGenerationModels, s as getBlockMeta, t as builtinGenerationModels } from "./builtins-BSD8jn8R.js";
2
2
  import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
3
3
  import { extname, join } from "node:path";
4
4
  import { parse, stringify } from "yaml";
@@ -199,7 +199,7 @@ function transportErrorTarget(rawUrl) {
199
199
  }
200
200
  function transportErrorSummary(error) {
201
201
  const outer = error instanceof Error ? error : new Error(String(error));
202
- const cause = isRecord$6(outer.cause) ? outer.cause : void 0;
202
+ const cause = isRecord$7(outer.cause) ? outer.cause : void 0;
203
203
  return compactObject({
204
204
  name: outer.name,
205
205
  causeName: stringProperty(cause, "name"),
@@ -210,16 +210,16 @@ function transportErrorSummary(error) {
210
210
  });
211
211
  }
212
212
  function stringProperty(value, key) {
213
- if (!isRecord$6(value)) return void 0;
213
+ if (!isRecord$7(value)) return void 0;
214
214
  const item = value[key];
215
215
  return typeof item === "string" && item.trim() ? item.trim() : void 0;
216
216
  }
217
217
  function stringOrNumberProperty(value, key) {
218
- if (!isRecord$6(value)) return void 0;
218
+ if (!isRecord$7(value)) return void 0;
219
219
  const item = value[key];
220
220
  return typeof item === "string" || typeof item === "number" ? item : void 0;
221
221
  }
222
- function isRecord$6(value) {
222
+ function isRecord$7(value) {
223
223
  return typeof value === "object" && value !== null;
224
224
  }
225
225
 
@@ -358,13 +358,13 @@ function mergeTextBlocks(declaration, content) {
358
358
 
359
359
  //#endregion
360
360
  //#region src/adapters/ark-video-generations.ts
361
- const REQUEST_TIMEOUT_MS$7 = 186e4;
362
- const DEFAULT_POLL_INTERVAL_SEC$3 = 2;
363
- const DEFAULT_MAX_WAIT_SEC$3 = 600;
364
- function sleep$3(ms) {
361
+ const REQUEST_TIMEOUT_MS$8 = 186e4;
362
+ const DEFAULT_POLL_INTERVAL_SEC$4 = 2;
363
+ const DEFAULT_MAX_WAIT_SEC$4 = 600;
364
+ function sleep$4(ms) {
365
365
  return new Promise((resolve) => setTimeout(resolve, ms));
366
366
  }
367
- function asString$3(value) {
367
+ function asString$4(value) {
368
368
  return typeof value === "string" && value ? value : void 0;
369
369
  }
370
370
  function asNumber$1(value) {
@@ -373,7 +373,7 @@ function asNumber$1(value) {
373
373
  function asBoolean$1(value) {
374
374
  return typeof value === "boolean" ? value : void 0;
375
375
  }
376
- function normalizeStatus$3(value) {
376
+ function normalizeStatus$4(value) {
377
377
  const status = value.toLowerCase();
378
378
  return status === "success" ? "succeeded" : status;
379
379
  }
@@ -448,8 +448,8 @@ async function resolveMedia$1(input, media) {
448
448
  url: await input.context.resolveSource(item.source)
449
449
  })));
450
450
  }
451
- function extractTaskId$3(response) {
452
- const taskId = asString$3(response.task_id) ?? asString$3(response.id);
451
+ function extractTaskId$4(response) {
452
+ const taskId = asString$4(response.task_id) ?? asString$4(response.id);
453
453
  if (!taskId) throw new GenerationProviderError("Video generation provider did not return a task id", { details: { response } });
454
454
  return taskId;
455
455
  }
@@ -457,9 +457,9 @@ function normalizeTaskStatus(response) {
457
457
  if (response.data) {
458
458
  const wrapper = response.data;
459
459
  const native = wrapper.data;
460
- const status = normalizeStatus$3(asString$3(native?.status) ?? asString$3(wrapper.status) ?? "unknown");
461
- const videoUrl = asString$3(wrapper.result_url) ?? asString$3(native?.content?.video_url);
462
- const firstFrameUrl = asString$3(wrapper.first_frame) ?? asString$3(native?.content?.first_frame);
460
+ const status = normalizeStatus$4(asString$4(native?.status) ?? asString$4(wrapper.status) ?? "unknown");
461
+ const videoUrl = asString$4(wrapper.result_url) ?? asString$4(native?.content?.video_url);
462
+ const firstFrameUrl = asString$4(wrapper.first_frame) ?? asString$4(native?.content?.first_frame);
463
463
  const metadata = {
464
464
  progress: wrapper.progress,
465
465
  resolution: native?.resolution,
@@ -486,7 +486,7 @@ function normalizeTaskStatus(response) {
486
486
  metadata: {}
487
487
  };
488
488
  }
489
- async function requestJson$3(input, path, init) {
489
+ async function requestJson$4(input, path, init) {
490
490
  const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
491
491
  ...init,
492
492
  headers: {
@@ -494,7 +494,7 @@ async function requestJson$3(input, path, init) {
494
494
  "Content-Type": "application/json",
495
495
  ...init.headers
496
496
  }
497
- }, REQUEST_TIMEOUT_MS$7);
497
+ }, REQUEST_TIMEOUT_MS$8);
498
498
  if (!response.ok) {
499
499
  const body = await response.text().catch(() => response.statusText);
500
500
  throw new GenerationProviderError("Video generation provider request failed", {
@@ -514,12 +514,12 @@ async function arkVideoGenerationsAdapter(input) {
514
514
  }));
515
515
  const mode = classifyMedia$1(inputMedia);
516
516
  const media = await resolveMedia$1(input, inputMedia);
517
- const resolution = asString$3(input.parameters.resolution) ?? "720p";
518
- const ratio = asString$3(input.request.parameters?.ratio) ?? asString$3(input.parameters.ratio) ?? "16:9";
517
+ const resolution = asString$4(input.parameters.resolution) ?? "720p";
518
+ const ratio = asString$4(input.request.parameters?.ratio) ?? asString$4(input.parameters.ratio) ?? "16:9";
519
519
  const duration = getIntegerParameter(input.parameters, "duration", 5);
520
- const fps = getIntegerParameter(input.parameters, "fps", 30);
521
- const pollIntervalSec = getIntegerParameter(input.parameters, "poll_interval", DEFAULT_POLL_INTERVAL_SEC$3);
522
- const maxWaitSec = getIntegerParameter(input.parameters, "max_wait", DEFAULT_MAX_WAIT_SEC$3);
520
+ const fps = getIntegerParameter(input.parameters, "fps", 24);
521
+ const pollIntervalSec = getIntegerParameter(input.parameters, "poll_interval", DEFAULT_POLL_INTERVAL_SEC$4);
522
+ const maxWaitSec = getIntegerParameter(input.parameters, "max_wait", DEFAULT_MAX_WAIT_SEC$4);
523
523
  const generateAudio = asBoolean$1(input.parameters.generate_audio) ?? true;
524
524
  const returnLastFrame = asBoolean$1(input.parameters.return_last_frame) ?? true;
525
525
  const cameraFixed = asBoolean$1(input.parameters.camera_fixed) ?? false;
@@ -546,14 +546,14 @@ async function arkVideoGenerationsAdapter(input) {
546
546
  if (firstImage) payload.image = firstImage.url;
547
547
  }
548
548
  payload.metadata = metadata;
549
- const taskId = extractTaskId$3(await requestJson$3(input, "/v1/video/generations", {
549
+ const taskId = extractTaskId$4(await requestJson$4(input, "/v1/video/generations", {
550
550
  method: "POST",
551
551
  body: JSON.stringify(payload)
552
552
  }));
553
553
  const startedAt = Date.now();
554
554
  while (Date.now() - startedAt <= maxWaitSec * 1e3) {
555
- await sleep$3(pollIntervalSec * 1e3);
556
- const rawStatus = await requestJson$3(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
555
+ await sleep$4(pollIntervalSec * 1e3);
556
+ const rawStatus = await requestJson$4(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
557
557
  const status = normalizeTaskStatus(rawStatus);
558
558
  if (status.status === "succeeded") {
559
559
  if (!status.videoUrl) throw new GenerationProviderError("Video generation succeeded but returned no video URL", { details: compactObject({
@@ -600,7 +600,7 @@ async function arkVideoGenerationsAdapter(input) {
600
600
 
601
601
  //#endregion
602
602
  //#region src/adapters/audio-speech.ts
603
- const REQUEST_TIMEOUT_MS$6 = 21e4;
603
+ const REQUEST_TIMEOUT_MS$7 = 21e4;
604
604
  const QWEN_MODELS = new Set([
605
605
  "qwen-tts",
606
606
  "qwen-audio-3.0-tts-plus",
@@ -608,7 +608,7 @@ const QWEN_MODELS = new Set([
608
608
  ]);
609
609
  const QWEN_AUDIO_3_MODELS = new Set(["qwen-audio-3.0-tts-plus", "qwen-audio-3.0-tts-flash"]);
610
610
  const HIGGS_MODEL = "higgs-tts";
611
- function isRecord$5(value) {
611
+ function isRecord$6(value) {
612
612
  return !!value && typeof value === "object" && !Array.isArray(value);
613
613
  }
614
614
  function textBlocks(input) {
@@ -729,8 +729,8 @@ function providerError(response, rawBody) {
729
729
  const requestId = requestIdFromHeaders(response.headers);
730
730
  const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
731
731
  const parsed = contentType.includes("application/json") || contentType.includes("+json") ? parseJson(rawBody) : void 0;
732
- const parsedRecord = isRecord$5(parsed) ? parsed : void 0;
733
- const errorRecord = isRecord$5(parsedRecord?.error) ? parsedRecord.error : void 0;
732
+ const parsedRecord = isRecord$6(parsed) ? parsed : void 0;
733
+ const errorRecord = isRecord$6(parsedRecord?.error) ? parsedRecord.error : void 0;
734
734
  const message = nonEmptyString(errorRecord?.message) ?? (rawBody.trim() ? rawBody : void 0) ?? (response.statusText.trim() ? response.statusText : void 0) ?? "Audio speech provider request failed";
735
735
  const code = nonEmptyString(errorRecord?.code);
736
736
  return new GenerationProviderError(message, {
@@ -753,7 +753,7 @@ function unsupportedSuccessResponse(response, rawBody) {
753
753
  }
754
754
  function parseSuccessResponse(response, rawBody) {
755
755
  const parsed = parseJson(rawBody);
756
- if (!isRecord$5(parsed)) throw unsupportedSuccessResponse(response, rawBody);
756
+ if (!isRecord$6(parsed)) throw unsupportedSuccessResponse(response, rawBody);
757
757
  const urlValue = nonEmptyString(parsed.url);
758
758
  const contentType = nonEmptyString(parsed.content_type);
759
759
  if (!urlValue || parsed.media_type !== "audio" || !contentType || !/^audio\/[^\s/;]+(?:\s*;.*)?$/i.test(contentType)) throw unsupportedSuccessResponse(response, rawBody);
@@ -787,7 +787,7 @@ async function generateAudioSpeech(input) {
787
787
  "Content-Type": "application/json"
788
788
  },
789
789
  body: JSON.stringify(buildPayload$2(input))
790
- }, REQUEST_TIMEOUT_MS$6);
790
+ }, REQUEST_TIMEOUT_MS$7);
791
791
  const rawBody = await response.text().catch(() => "");
792
792
  if (!response.ok) throw providerError(response, rawBody);
793
793
  return [parseSuccessResponse(response, rawBody)];
@@ -796,7 +796,7 @@ const audioSpeechAdapter = Object.assign(generateAudioSpeech, { validate: valida
796
796
 
797
797
  //#endregion
798
798
  //#region src/adapters/gemini-generate-content.ts
799
- const REQUEST_TIMEOUT_MS$5 = 3e5;
799
+ const REQUEST_TIMEOUT_MS$6 = 3e5;
800
800
  const MARKDOWN_IMAGE_DATA_URI_PATTERN = /!\[[^\]]*\]\(data:([^;]+);base64,([^)]+)\)/;
801
801
  function isHttpUrl(value) {
802
802
  return value.startsWith("http://") || value.startsWith("https://");
@@ -911,7 +911,7 @@ async function geminiGenerateContentAdapter(input) {
911
911
  "Content-Type": "application/json"
912
912
  },
913
913
  body: JSON.stringify(payload)
914
- }, REQUEST_TIMEOUT_MS$5);
914
+ }, REQUEST_TIMEOUT_MS$6);
915
915
  if (!response.ok) {
916
916
  const body = await response.text().catch(() => response.statusText);
917
917
  throw new GenerationProviderError("Gemini generation provider request failed", {
@@ -928,9 +928,9 @@ async function geminiGenerateContentAdapter(input) {
928
928
 
929
929
  //#endregion
930
930
  //#region src/adapters/kling-video-generations.ts
931
- const REQUEST_TIMEOUT_MS$4 = 186e4;
932
- const DEFAULT_POLL_INTERVAL_SEC$2 = 5;
933
- const DEFAULT_MAX_WAIT_SEC$2 = 900;
931
+ const REQUEST_TIMEOUT_MS$5 = 186e4;
932
+ const DEFAULT_POLL_INTERVAL_SEC$3 = 5;
933
+ const DEFAULT_MAX_WAIT_SEC$3 = 900;
934
934
  const KLING_MODELS = {
935
935
  "kling-text-to-video": {
936
936
  submitPath: "/kling/v1/videos/text2video",
@@ -954,10 +954,10 @@ const KLING_MODELS = {
954
954
  imageMode: "multi"
955
955
  }
956
956
  };
957
- function sleep$2(ms) {
957
+ function sleep$3(ms) {
958
958
  return new Promise((resolve) => setTimeout(resolve, ms));
959
959
  }
960
- function asString$2(value) {
960
+ function asString$3(value) {
961
961
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
962
962
  }
963
963
  function asInteger$2(value, fallback) {
@@ -966,7 +966,7 @@ function asInteger$2(value, fallback) {
966
966
  function asNumber(value) {
967
967
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
968
968
  }
969
- function isRecord$4(value) {
969
+ function isRecord$5(value) {
970
970
  return !!value && typeof value === "object" && !Array.isArray(value);
971
971
  }
972
972
  function providerMeta(input) {
@@ -975,7 +975,7 @@ function providerMeta(input) {
975
975
  delete rest.role;
976
976
  return rest;
977
977
  }
978
- function normalizeStatus$2(value) {
978
+ function normalizeStatus$3(value) {
979
979
  const status = String(value ?? "").trim().toLowerCase();
980
980
  if (status === "success" || status === "succeed" || status === "succeeded" || status === "completed") return "succeeded";
981
981
  if (status === "queued" || status === "processing" || status === "in_progress" || status === "not_start" || status === "submitted") return "processing";
@@ -1050,11 +1050,11 @@ function buildPayload$1(input, model, prompt, images) {
1050
1050
  };
1051
1051
  if (prompt) payload.prompt = prompt;
1052
1052
  if (!payload.duration) payload.duration = String(asInteger$2(input.parameters.duration, 5));
1053
- if (!payload.mode) payload.mode = asString$2(input.parameters.mode) ?? "std";
1053
+ if (!payload.mode) payload.mode = asString$3(input.parameters.mode) ?? "std";
1054
1054
  if (payload.cfg_scale === void 0) payload.cfg_scale = asNumber(input.parameters.cfg_scale) ?? .5;
1055
- if (!payload.aspect_ratio) payload.aspect_ratio = asString$2(input.parameters.aspect_ratio) ?? "16:9";
1056
- if (payload.negative_prompt === void 0 && asString$2(input.parameters.negative_prompt)) payload.negative_prompt = input.parameters.negative_prompt;
1057
- if (payload.sound === void 0 && asString$2(input.parameters.sound)) payload.sound = input.parameters.sound;
1055
+ if (!payload.aspect_ratio) payload.aspect_ratio = asString$3(input.parameters.aspect_ratio) ?? "16:9";
1056
+ if (payload.negative_prompt === void 0 && asString$3(input.parameters.negative_prompt)) payload.negative_prompt = input.parameters.negative_prompt;
1057
+ if (payload.sound === void 0 && asString$3(input.parameters.sound)) payload.sound = input.parameters.sound;
1058
1058
  if (model.imageMode === "single" && images[0] && !hasPlainImagePayload(payload)) {
1059
1059
  payload.image = images[0].url;
1060
1060
  if (images[1] && payload.image_tail === void 0) payload.image_tail = images[1].url;
@@ -1064,18 +1064,18 @@ function buildPayload$1(input, model, prompt, images) {
1064
1064
  if (payload.seed === void 0 && input.parameters.seed !== void 0) payload.seed = input.parameters.seed;
1065
1065
  return payload;
1066
1066
  }
1067
- function extractTaskId$2(response) {
1068
- const taskId = asString$2(response.task_id) ?? asString$2(response.id) ?? asString$2(response.data?.task_id) ?? asString$2(response.data?.id);
1067
+ function extractTaskId$3(response) {
1068
+ const taskId = asString$3(response.task_id) ?? asString$3(response.id) ?? asString$3(response.data?.task_id) ?? asString$3(response.data?.id);
1069
1069
  if (!taskId) throw new GenerationProviderError("Kling video provider did not return a task id", { details: { response } });
1070
1070
  return taskId;
1071
1071
  }
1072
1072
  function extractStatus(response) {
1073
1073
  const wrapper = response.data;
1074
1074
  const native = wrapper?.data;
1075
- const status = normalizeStatus$2(native?.status ?? wrapper?.task_status ?? wrapper?.status ?? response.task_status ?? response.status);
1075
+ const status = normalizeStatus$3(native?.status ?? wrapper?.task_status ?? wrapper?.status ?? response.task_status ?? response.status);
1076
1076
  const firstVideo = wrapper?.task_result?.videos?.[0] ?? native?.task_result?.videos?.[0];
1077
- 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);
1078
- const message = asString$2(wrapper?.task_status_msg) ?? asString$2(response.error?.message) ?? asString$2(response.message);
1077
+ const videoUrl = asString$3(firstVideo?.url) ?? asString$3(wrapper?.result_url) ?? asString$3(wrapper?.video_url) ?? asString$3(wrapper?.url) ?? asString$3(native?.content?.video_url) ?? asString$3(response.metadata?.url) ?? asString$3(response.result_url) ?? asString$3(response.video_url) ?? asString$3(response.url);
1078
+ const message = asString$3(wrapper?.task_status_msg) ?? asString$3(response.error?.message) ?? asString$3(response.message);
1079
1079
  return {
1080
1080
  status,
1081
1081
  videoUrl,
@@ -1088,7 +1088,7 @@ function extractStatus(response) {
1088
1088
  })
1089
1089
  };
1090
1090
  }
1091
- async function requestJson$2(input, path, init) {
1091
+ async function requestJson$3(input, path, init) {
1092
1092
  const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
1093
1093
  ...init,
1094
1094
  headers: {
@@ -1096,7 +1096,7 @@ async function requestJson$2(input, path, init) {
1096
1096
  "Content-Type": "application/json",
1097
1097
  ...init.headers
1098
1098
  }
1099
- }, REQUEST_TIMEOUT_MS$4);
1099
+ }, REQUEST_TIMEOUT_MS$5);
1100
1100
  const body = await response.text();
1101
1101
  let parsed = {};
1102
1102
  try {
@@ -1108,7 +1108,7 @@ async function requestJson$2(input, path, init) {
1108
1108
  });
1109
1109
  }
1110
1110
  if (!response.ok) {
1111
- const details = isRecord$4(parsed) ? { details: parsed } : {};
1111
+ const details = isRecord$5(parsed) ? { details: parsed } : {};
1112
1112
  throw new GenerationProviderError("Kling video provider request failed", {
1113
1113
  status: response.status,
1114
1114
  body,
@@ -1126,16 +1126,16 @@ async function klingVideoGenerationsAdapter(input) {
1126
1126
  if (!prompt && model.allowPromptlessOmni && !hasPromptlessOmniPayload(meta, images)) throw new GenerationValidationError("Prompt text or Omni media input is required");
1127
1127
  if (model.imageMode === "single" && images.length === 0 && !hasPlainImagePayload(meta)) throw new GenerationValidationError("Image input is required");
1128
1128
  if (model.imageMode === "multi" && images.length === 0 && !hasMultiImagePayload(meta)) throw new GenerationValidationError("Multi-image input is required");
1129
- const taskId = extractTaskId$2(await requestJson$2(input, model.submitPath, {
1129
+ const taskId = extractTaskId$3(await requestJson$3(input, model.submitPath, {
1130
1130
  method: "POST",
1131
1131
  body: JSON.stringify(buildPayload$1(input, model, prompt, images))
1132
1132
  }));
1133
- const pollIntervalSec = asInteger$2(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$2);
1134
- const maxWaitSec = asInteger$2(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$2);
1133
+ const pollIntervalSec = asInteger$2(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$3);
1134
+ const maxWaitSec = asInteger$2(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$3);
1135
1135
  const startedAt = Date.now();
1136
1136
  while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1137
- await sleep$2(pollIntervalSec * 1e3);
1138
- const rawStatus = await requestJson$2(input, `${model.submitPath}/${encodeURIComponent(taskId)}`, { method: "GET" });
1137
+ await sleep$3(pollIntervalSec * 1e3);
1138
+ const rawStatus = await requestJson$3(input, `${model.submitPath}/${encodeURIComponent(taskId)}`, { method: "GET" });
1139
1139
  const status = extractStatus(rawStatus);
1140
1140
  if (status.status === "succeeded") {
1141
1141
  if (!status.videoUrl) throw new GenerationProviderError("Kling video generation succeeded but returned no video URL", { details: compactObject({
@@ -1167,9 +1167,9 @@ async function klingVideoGenerationsAdapter(input) {
1167
1167
 
1168
1168
  //#endregion
1169
1169
  //#region src/adapters/minimax-h3-video-generations.ts
1170
- const REQUEST_TIMEOUT_MS$3 = 186e4;
1171
- const DEFAULT_POLL_INTERVAL_SEC$1 = 2;
1172
- const DEFAULT_MAX_WAIT_SEC$1 = 600;
1170
+ const REQUEST_TIMEOUT_MS$4 = 186e4;
1171
+ const DEFAULT_POLL_INTERVAL_SEC$2 = 2;
1172
+ const DEFAULT_MAX_WAIT_SEC$2 = 600;
1173
1173
  const MIN_DURATION_SEC = 4;
1174
1174
  const MAX_DURATION_SEC = 15;
1175
1175
  const MAX_MEDIA_COUNT = 12;
@@ -1187,10 +1187,10 @@ const H3_RATIOS = [
1187
1187
  "3:4",
1188
1188
  "9:16"
1189
1189
  ];
1190
- function sleep$1(ms) {
1190
+ function sleep$2(ms) {
1191
1191
  return new Promise((resolve) => setTimeout(resolve, ms));
1192
1192
  }
1193
- function asString$1(value) {
1193
+ function asString$2(value) {
1194
1194
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
1195
1195
  }
1196
1196
  function asInteger$1(value, fallback) {
@@ -1199,10 +1199,10 @@ function asInteger$1(value, fallback) {
1199
1199
  function asBoolean(value, fallback) {
1200
1200
  return typeof value === "boolean" ? value : fallback;
1201
1201
  }
1202
- function isRecord$3(value) {
1202
+ function isRecord$4(value) {
1203
1203
  return !!value && typeof value === "object" && !Array.isArray(value);
1204
1204
  }
1205
- function normalizeStatus$1(value) {
1205
+ function normalizeStatus$2(value) {
1206
1206
  const status = String(value ?? "").trim().toLowerCase();
1207
1207
  if ([
1208
1208
  "success",
@@ -1301,7 +1301,7 @@ function buildContent(prompt, media) {
1301
1301
  })];
1302
1302
  }
1303
1303
  function resolveResolution(value) {
1304
- const resolution = (asString$1(value) ?? "768P").toUpperCase();
1304
+ const resolution = (asString$2(value) ?? "768P").toUpperCase();
1305
1305
  if (resolution !== "768P" && resolution !== "2K") throw new GenerationValidationError("MiniMax H3 resolution must be 768P or 2K");
1306
1306
  return resolution;
1307
1307
  }
@@ -1311,14 +1311,13 @@ function resolveDuration(value) {
1311
1311
  return duration;
1312
1312
  }
1313
1313
  function resolveRatio(value, mode) {
1314
- const requested = asString$1(value) ?? DEFAULT_RATIO;
1314
+ const requested = asString$2(value) ?? DEFAULT_RATIO;
1315
1315
  if (!H3_RATIOS.includes(requested)) throw new GenerationValidationError(`MiniMax H3 ratio must be one of: ${H3_RATIOS.join(", ")}`);
1316
- if (mode === "text") return requested === ADAPTIVE_RATIO ? DEFAULT_RATIO : requested;
1317
- return ADAPTIVE_RATIO;
1316
+ return mode === "text" && requested === ADAPTIVE_RATIO ? DEFAULT_RATIO : requested;
1318
1317
  }
1319
- function extractTaskId$1(response) {
1320
- const data = isRecord$3(response.data) ? response.data : void 0;
1321
- const taskId = asString$1(response.task_id) ?? asString$1(response.id) ?? asString$1(data?.task_id) ?? asString$1(data?.id);
1318
+ function extractTaskId$2(response) {
1319
+ const data = isRecord$4(response.data) ? response.data : void 0;
1320
+ const taskId = asString$2(response.task_id) ?? asString$2(response.id) ?? asString$2(data?.task_id) ?? asString$2(data?.id);
1322
1321
  if (!taskId) throw new GenerationProviderError("MiniMax H3 provider did not return a task id", { details: { response } });
1323
1322
  return taskId;
1324
1323
  }
@@ -1334,19 +1333,19 @@ function isTaskPayload(value) {
1334
1333
  "fail_reason"
1335
1334
  ].some((key) => key in value);
1336
1335
  }
1337
- function unwrapTaskPayload(response) {
1338
- const data = isRecord$3(response.data) ? response.data : void 0;
1336
+ function unwrapTaskPayload$1(response) {
1337
+ const data = isRecord$4(response.data) ? response.data : void 0;
1339
1338
  return data && !isTaskPayload(response) ? data : response;
1340
1339
  }
1341
- function extractTaskStatus(response) {
1342
- const payload = unwrapTaskPayload(response);
1343
- const task = isRecord$3(payload.task) ? payload.task : payload;
1344
- const metadata = isRecord$3(payload.metadata) ? payload.metadata : isRecord$3(task.metadata) ? task.metadata : void 0;
1345
- const content = isRecord$3(task.content) ? task.content : void 0;
1346
- const status = normalizeStatus$1(payload.status ?? task.status);
1347
- 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);
1348
- const error = isRecord$3(payload.error) ? payload.error : isRecord$3(task.error) ? task.error : void 0;
1349
- 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);
1340
+ function extractTaskStatus$1(response) {
1341
+ const payload = unwrapTaskPayload$1(response);
1342
+ const task = isRecord$4(payload.task) ? payload.task : payload;
1343
+ const metadata = isRecord$4(payload.metadata) ? payload.metadata : isRecord$4(task.metadata) ? task.metadata : void 0;
1344
+ const content = isRecord$4(task.content) ? task.content : void 0;
1345
+ const status = normalizeStatus$2(payload.status ?? task.status);
1346
+ const videoUrl = asString$2(metadata?.url) ?? asString$2(payload.result_url) ?? asString$2(payload.video_url) ?? asString$2(payload.url) ?? asString$2(task.result_url) ?? asString$2(task.video_url) ?? asString$2(task.url) ?? asString$2(content?.video_url) ?? asString$2(content?.url);
1347
+ const error = isRecord$4(payload.error) ? payload.error : isRecord$4(task.error) ? task.error : void 0;
1348
+ const message = asString$2(error?.message) ?? asString$2(payload.fail_reason) ?? asString$2(payload.message) ?? asString$2(task.fail_reason) ?? asString$2(task.message) ?? asString$2(response.message);
1350
1349
  const outputMetadata = compactObject({
1351
1350
  progress: payload.progress ?? task.progress,
1352
1351
  resolution: payload.resolution ?? task.resolution,
@@ -1360,7 +1359,7 @@ function extractTaskStatus(response) {
1360
1359
  metadata: outputMetadata
1361
1360
  };
1362
1361
  }
1363
- async function requestJson$1(input, path, init) {
1362
+ async function requestJson$2(input, path, init) {
1364
1363
  const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
1365
1364
  ...init,
1366
1365
  headers: {
@@ -1368,7 +1367,7 @@ async function requestJson$1(input, path, init) {
1368
1367
  "Content-Type": "application/json",
1369
1368
  ...init.headers
1370
1369
  }
1371
- }, REQUEST_TIMEOUT_MS$3);
1370
+ }, REQUEST_TIMEOUT_MS$4);
1372
1371
  const body = await response.text();
1373
1372
  let parsed = {};
1374
1373
  try {
@@ -1382,7 +1381,7 @@ async function requestJson$1(input, path, init) {
1382
1381
  if (!response.ok) throw new GenerationProviderError("MiniMax H3 provider request failed", {
1383
1382
  status: response.status,
1384
1383
  body,
1385
- ...isRecord$3(parsed) ? { details: parsed } : {}
1384
+ ...isRecord$4(parsed) ? { details: parsed } : {}
1386
1385
  });
1387
1386
  return parsed;
1388
1387
  }
@@ -1395,8 +1394,8 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1395
1394
  const duration = resolveDuration(input.parameters.duration);
1396
1395
  const resolution = resolveResolution(input.parameters.resolution);
1397
1396
  const ratio = resolveRatio(input.parameters.ratio, mode);
1398
- const pollIntervalSec = Math.max(1, asInteger$1(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$1));
1399
- const maxWaitSec = Math.max(30, asInteger$1(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$1));
1397
+ const pollIntervalSec = Math.max(1, asInteger$1(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$2));
1398
+ const maxWaitSec = Math.max(30, asInteger$1(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$2));
1400
1399
  const aigcWatermark = asBoolean(input.parameters.aigc_watermark, false);
1401
1400
  const payload = {
1402
1401
  model: input.declaration.model,
@@ -1406,15 +1405,15 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1406
1405
  ratio,
1407
1406
  aigc_watermark: aigcWatermark
1408
1407
  };
1409
- const taskId = extractTaskId$1(await requestJson$1(input, "/v1/video/generations", {
1408
+ const taskId = extractTaskId$2(await requestJson$2(input, "/v1/video/generations", {
1410
1409
  method: "POST",
1411
1410
  body: JSON.stringify(payload)
1412
1411
  }));
1413
1412
  const startedAt = Date.now();
1414
1413
  while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1415
- await sleep$1(pollIntervalSec * 1e3);
1416
- const rawStatus = await requestJson$1(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
1417
- const status = extractTaskStatus(rawStatus);
1414
+ await sleep$2(pollIntervalSec * 1e3);
1415
+ const rawStatus = await requestJson$2(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
1416
+ const status = extractTaskStatus$1(rawStatus);
1418
1417
  if (status.status === "succeeded") {
1419
1418
  if (!status.videoUrl) throw new GenerationProviderError("MiniMax H3 generation succeeded but returned no video URL", { details: compactObject({
1420
1419
  taskId,
@@ -1444,7 +1443,7 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1444
1443
 
1445
1444
  //#endregion
1446
1445
  //#region src/adapters/openai-image-edits.ts
1447
- const REQUEST_TIMEOUT_MS$2 = 3e5;
1446
+ const REQUEST_TIMEOUT_MS$3 = 3e5;
1448
1447
  function firstUrlImage(input) {
1449
1448
  const image = input.request.content.find((block) => block.type === "image");
1450
1449
  if (!image) throw new GenerationValidationError("Source image is required");
@@ -1476,7 +1475,7 @@ async function openAiImageEditsAdapter(input) {
1476
1475
  method: "POST",
1477
1476
  headers: { Authorization: `Bearer ${input.context.apiKey}` },
1478
1477
  body
1479
- }, REQUEST_TIMEOUT_MS$2);
1478
+ }, REQUEST_TIMEOUT_MS$3);
1480
1479
  if (!response.ok) {
1481
1480
  const bodyText = await response.text().catch(() => response.statusText);
1482
1481
  throw new GenerationProviderError("Image edit provider request failed", {
@@ -1514,7 +1513,7 @@ async function openAiImageEditsAdapter(input) {
1514
1513
 
1515
1514
  //#endregion
1516
1515
  //#region src/adapters/openai-images.ts
1517
- const REQUEST_TIMEOUT_MS$1 = 3e5;
1516
+ const REQUEST_TIMEOUT_MS$2 = 3e5;
1518
1517
  function collectOpenAiImagesNoOutputDetails(raw) {
1519
1518
  const data = raw.data ?? [];
1520
1519
  return compactObject({
@@ -1553,7 +1552,7 @@ async function openAiImagesAdapter(input) {
1553
1552
  "Content-Type": "application/json"
1554
1553
  },
1555
1554
  body: JSON.stringify(payload)
1556
- }, REQUEST_TIMEOUT_MS$1);
1555
+ }, REQUEST_TIMEOUT_MS$2);
1557
1556
  if (!response.ok) {
1558
1557
  const body = await response.text().catch(() => response.statusText);
1559
1558
  throw new GenerationProviderError("Image generation provider request failed", {
@@ -1591,9 +1590,9 @@ async function openAiImagesAdapter(input) {
1591
1590
 
1592
1591
  //#endregion
1593
1592
  //#region src/adapters/suno-tasks.ts
1594
- const REQUEST_TIMEOUT_MS = 6e4;
1595
- const DEFAULT_POLL_INTERVAL_SEC = 5;
1596
- const DEFAULT_MAX_WAIT_SEC = 600;
1593
+ const REQUEST_TIMEOUT_MS$1 = 6e4;
1594
+ const DEFAULT_POLL_INTERVAL_SEC$1 = 5;
1595
+ const DEFAULT_MAX_WAIT_SEC$1 = 600;
1597
1596
  const DEFAULT_MUSIC_VERSION = "chirp-v5";
1598
1597
  const OPERATION_PATHS = {
1599
1598
  music: {
@@ -1636,20 +1635,20 @@ const FINAL_FAILURE_STATUSES = new Set([
1636
1635
  "canceled",
1637
1636
  "expired"
1638
1637
  ]);
1639
- function sleep(ms) {
1638
+ function sleep$1(ms) {
1640
1639
  return new Promise((resolve) => setTimeout(resolve, ms));
1641
1640
  }
1642
- function isRecord$2(value) {
1641
+ function isRecord$3(value) {
1643
1642
  return !!value && typeof value === "object" && !Array.isArray(value);
1644
1643
  }
1645
- function asString(value) {
1644
+ function asString$1(value) {
1646
1645
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
1647
1646
  }
1648
1647
  function asInteger(value, fallback) {
1649
1648
  return typeof value === "number" && Number.isInteger(value) ? value : fallback;
1650
1649
  }
1651
1650
  function asRecord(value) {
1652
- return isRecord$2(value) ? value : {};
1651
+ return isRecord$3(value) ? value : {};
1653
1652
  }
1654
1653
  function successCode(value) {
1655
1654
  const code = String(value ?? "").trim().toLowerCase();
@@ -1663,19 +1662,19 @@ function requireSuccess(response, fallbackMessage) {
1663
1662
  } });
1664
1663
  return response.data;
1665
1664
  }
1666
- function extractTaskId(value) {
1665
+ function extractTaskId$1(value) {
1667
1666
  if (typeof value === "string" && value.trim()) return value.trim();
1668
- if (!isRecord$2(value)) return void 0;
1667
+ if (!isRecord$3(value)) return void 0;
1669
1668
  for (const key of [
1670
1669
  "task_id",
1671
1670
  "id",
1672
1671
  "taskBatchId"
1673
1672
  ]) {
1674
- const taskId = asString(value[key]);
1673
+ const taskId = asString$1(value[key]);
1675
1674
  if (taskId) return taskId;
1676
1675
  }
1677
1676
  }
1678
- function normalizeStatus(value) {
1677
+ function normalizeStatus$1(value) {
1679
1678
  const status = String(value ?? "").trim().toLowerCase();
1680
1679
  if (status === "finished") return "success";
1681
1680
  if (status === "fail" || status === "rejected") return "failed";
@@ -1683,7 +1682,7 @@ function normalizeStatus(value) {
1683
1682
  }
1684
1683
  function normalizeTask(operation, data) {
1685
1684
  if (Array.isArray(data)) return data.length > 0 ? normalizeTask(operation, data[0]) : null;
1686
- if (!isRecord$2(data)) return null;
1685
+ if (!isRecord$3(data)) return null;
1687
1686
  if ("status" in data || "taskStatus" in data || "task_status" in data || "task_id" in data || "taskBatchId" in data) {
1688
1687
  const hasProviderEnvelope = "taskStatus" in data || "task_status" in data || "taskBatchId" in data || "task_batch_id" in data;
1689
1688
  return {
@@ -1702,8 +1701,8 @@ function normalizeTask(operation, data) {
1702
1701
  };
1703
1702
  }
1704
1703
  function getOperation(input) {
1705
- const fixedOperation = asString(input.declaration.adapter.operation);
1706
- const requestedOperation = asString(input.parameters.operation);
1704
+ const fixedOperation = asString$1(input.declaration.adapter.operation);
1705
+ const requestedOperation = asString$1(input.parameters.operation);
1707
1706
  if (fixedOperation && requestedOperation && fixedOperation !== requestedOperation) throw new GenerationValidationError(`${input.declaration.model} uses Suno operation ${fixedOperation}; parameters.operation cannot override it`);
1708
1707
  const operation = fixedOperation ?? requestedOperation ?? "music";
1709
1708
  if (!OPERATION_PATHS[operation]) throw new GenerationValidationError(`Unsupported Suno operation: ${operation}`);
@@ -1732,13 +1731,13 @@ async function buildPayload(input, operation) {
1732
1731
  if (payload.video_url === void 0) payload.video_url = videoUrl;
1733
1732
  }
1734
1733
  applyFixedPayload(input, payload, asRecord(input.declaration.adapter.payload));
1735
- const fixedTask = asString(input.declaration.adapter.task);
1734
+ const fixedTask = asString$1(input.declaration.adapter.task);
1736
1735
  if (fixedTask) applyFixedPayload(input, payload, { task: fixedTask });
1737
- const task = asString(payload.task);
1736
+ const task = asString$1(payload.task);
1738
1737
  if (task === "image_to_song" && imageUrl) setMetadataParam(payload, "image_url", imageUrl);
1739
1738
  if (task === "video_to_song" && videoUrl) setMetadataParam(payload, "video_url", videoUrl);
1740
1739
  if (task === "cover" && payload.clip_id === void 0) {
1741
- const coverClipId = asString(payload.cover_clip_id);
1740
+ const coverClipId = asString$1(payload.cover_clip_id);
1742
1741
  if (coverClipId) payload.clip_id = coverClipId;
1743
1742
  }
1744
1743
  normalizeMusicTaskPayload(input, operation, payload);
@@ -1754,7 +1753,7 @@ function applyFixedPayload(input, payload, fixed) {
1754
1753
  }
1755
1754
  }
1756
1755
  function setMetadataParam(payload, key, value) {
1757
- const metadataParams = isRecord$2(payload.metadata_params) ? payload.metadata_params : {};
1756
+ const metadataParams = isRecord$3(payload.metadata_params) ? payload.metadata_params : {};
1758
1757
  if (metadataParams[key] === void 0) metadataParams[key] = value;
1759
1758
  payload.metadata_params = metadataParams;
1760
1759
  }
@@ -1764,7 +1763,7 @@ function contentCount(content, type) {
1764
1763
  function normalizeMusicTaskPayload(input, operation, payload) {
1765
1764
  if (operation !== "music") return;
1766
1765
  const taskField = input.declaration.meta?.taskField ?? "task";
1767
- const task = asString(payload[taskField]);
1766
+ const task = asString$1(payload[taskField]);
1768
1767
  if (!task) return;
1769
1768
  const taskVariant = input.declaration.meta?.taskVariants?.[task];
1770
1769
  if (!taskVariant) throw new GenerationValidationError(`Unsupported Suno music task: ${task}`);
@@ -1774,15 +1773,15 @@ function normalizeMusicTaskPayload(input, operation, payload) {
1774
1773
  }
1775
1774
  function validateSunoPayload(operation, payload) {
1776
1775
  const config = OPERATION_PATHS[operation];
1777
- const task = asString(payload.task);
1776
+ const task = asString$1(payload.task);
1778
1777
  if (operation === "music" && task) {
1779
1778
  if (task === "lyrics") throw new GenerationValidationError("Use operation=lyrics instead of task=lyrics");
1780
1779
  }
1781
- if (config?.requireText && !asString(payload[config.textField ?? "prompt"])) throw new GenerationValidationError(`${config.textField ?? "prompt"} text is required`);
1782
- if (operation === "upload_audio" && !asString(payload.url)) throw new GenerationValidationError("Audio url is required for Suno upload_audio");
1783
- if (operation === "concat" && !asString(payload.clip_id)) throw new GenerationValidationError("clip_id is required for Suno concat");
1780
+ if (config?.requireText && !asString$1(payload[config.textField ?? "prompt"])) throw new GenerationValidationError(`${config.textField ?? "prompt"} text is required`);
1781
+ if (operation === "upload_audio" && !asString$1(payload.url)) throw new GenerationValidationError("Audio url is required for Suno upload_audio");
1782
+ if (operation === "concat" && !asString$1(payload.clip_id)) throw new GenerationValidationError("clip_id is required for Suno concat");
1784
1783
  }
1785
- async function requestJson(input, path, init) {
1784
+ async function requestJson$1(input, path, init) {
1786
1785
  const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
1787
1786
  ...init,
1788
1787
  headers: {
@@ -1790,7 +1789,7 @@ async function requestJson(input, path, init) {
1790
1789
  "Content-Type": "application/json",
1791
1790
  ...init.headers
1792
1791
  }
1793
- }, REQUEST_TIMEOUT_MS);
1792
+ }, REQUEST_TIMEOUT_MS$1);
1794
1793
  const body = await response.text();
1795
1794
  let parsed;
1796
1795
  try {
@@ -1808,7 +1807,7 @@ async function requestJson(input, path, init) {
1808
1807
  return parsed;
1809
1808
  }
1810
1809
  function appendUrlBlock(output, type, url, meta) {
1811
- const value = asString(url);
1810
+ const value = asString$1(url);
1812
1811
  if (!value) return;
1813
1812
  output.push({
1814
1813
  type,
@@ -1824,8 +1823,8 @@ function appendSunoContent(output, value, meta = {}) {
1824
1823
  for (const item of value) appendSunoContent(output, item, meta);
1825
1824
  return;
1826
1825
  }
1827
- if (!isRecord$2(value)) return;
1828
- if (isRecord$2(value.clips)) for (const clip of Object.values(value.clips)) appendSunoContent(output, clip, meta);
1826
+ if (!isRecord$3(value)) return;
1827
+ if (isRecord$3(value.clips)) for (const clip of Object.values(value.clips)) appendSunoContent(output, clip, meta);
1829
1828
  if (Array.isArray(value.items)) for (const item of value.items) appendSunoContent(output, item, meta);
1830
1829
  const itemMeta = compactObject({
1831
1830
  ...meta,
@@ -1835,9 +1834,9 @@ function appendSunoContent(output, value, meta = {}) {
1835
1834
  title: value.title,
1836
1835
  status: value.status ?? meta.status,
1837
1836
  model: value.model_name ?? value.modelName,
1838
- duration: value.duration ?? (isRecord$2(value.metadata) ? value.metadata.duration : void 0),
1839
- tags: value.tags ?? (isRecord$2(value.metadata) ? value.metadata.tags : void 0),
1840
- prompt: value.prompt ?? (isRecord$2(value.metadata) ? value.metadata.prompt : void 0),
1837
+ duration: value.duration ?? (isRecord$3(value.metadata) ? value.metadata.duration : void 0),
1838
+ tags: value.tags ?? (isRecord$3(value.metadata) ? value.metadata.tags : void 0),
1839
+ prompt: value.prompt ?? (isRecord$3(value.metadata) ? value.metadata.prompt : void 0),
1841
1840
  progress: value.progress ?? meta.progress,
1842
1841
  progress_message: value.progressMsg ?? value.progress_msg,
1843
1842
  task_batch_id: value.taskBatchId ?? value.task_batch_id,
@@ -1852,13 +1851,13 @@ function appendSunoContent(output, value, meta = {}) {
1852
1851
  appendUrlBlock(output, "audio", value.source_audio_url ?? value.sourceAudioUrl, itemMeta);
1853
1852
  appendUrlBlock(output, "video", value.video_url ?? value.videoUrl ?? value.cld2VideoUrl ?? value.cld2_video_url, itemMeta);
1854
1853
  appendUrlBlock(output, "image", value.image_large_url ?? value.image_url ?? value.imageUrl ?? value.cld2ImageUrl ?? value.cld2_image_url, itemMeta);
1855
- const text = asString(value.upsampled_tags) ?? asString(value.text) ?? asString(value.lyrics);
1854
+ const text = asString$1(value.upsampled_tags) ?? asString$1(value.text) ?? asString$1(value.lyrics);
1856
1855
  if (text) output.push({
1857
1856
  type: "text",
1858
1857
  text,
1859
1858
  meta: itemMeta
1860
1859
  });
1861
- if (isRecord$2(value.data)) appendSunoContent(output, value.data, itemMeta);
1860
+ if (isRecord$3(value.data)) appendSunoContent(output, value.data, itemMeta);
1862
1861
  }
1863
1862
  function buildImmediateResult(operation, data, raw) {
1864
1863
  const output = [];
@@ -1868,7 +1867,7 @@ function buildImmediateResult(operation, data, raw) {
1868
1867
  });
1869
1868
  appendSunoContent(output, data, metadata);
1870
1869
  if (output.length > 0) return output;
1871
- const value = extractTaskId(data) ?? asString(data);
1870
+ const value = extractTaskId$1(data) ?? asString$1(data);
1872
1871
  if (value) output.push({
1873
1872
  type: "text",
1874
1873
  text: value,
@@ -1908,10 +1907,10 @@ function buildResult(operation, task, raw) {
1908
1907
  async function pollSunoTask(input, operation, taskId, pollIntervalSec, maxWaitSec) {
1909
1908
  const startedAt = Date.now();
1910
1909
  while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1911
- await sleep(pollIntervalSec * 1e3);
1910
+ await sleep$1(pollIntervalSec * 1e3);
1912
1911
  let raw;
1913
1912
  try {
1914
- raw = await requestJson(input, `/suno/fetch/${encodeURIComponent(taskId)}`, { method: "GET" });
1913
+ raw = await requestJson$1(input, `/suno/fetch/${encodeURIComponent(taskId)}`, { method: "GET" });
1915
1914
  } catch (error) {
1916
1915
  if (error instanceof GenerationProviderError) throw error;
1917
1916
  continue;
@@ -1919,7 +1918,7 @@ async function pollSunoTask(input, operation, taskId, pollIntervalSec, maxWaitSe
1919
1918
  const data = requireSuccess(raw, "Suno task fetch failed");
1920
1919
  const task = normalizeTask(operation, data);
1921
1920
  if (!task) throw new GenerationProviderError("Suno task fetch returned invalid task data", { details: { data } });
1922
- const status = normalizeStatus(task.status);
1921
+ const status = normalizeStatus$1(task.status);
1923
1922
  if (FINAL_SUCCESS_STATUSES.has(status)) return buildResult(operation, task, data);
1924
1923
  if (FINAL_FAILURE_STATUSES.has(status)) throw new GenerationProviderError("Suno task failed", { details: {
1925
1924
  task_id: taskId,
@@ -1937,15 +1936,177 @@ async function sunoTasksAdapter(input) {
1937
1936
  const payload = await buildPayload(input, operation);
1938
1937
  const config = OPERATION_PATHS[operation];
1939
1938
  if (!config) throw new GenerationValidationError(`Unsupported Suno operation: ${operation}`);
1940
- const raw = await requestJson(input, config.path, {
1939
+ const raw = await requestJson$1(input, config.path, {
1941
1940
  method: "POST",
1942
1941
  body: JSON.stringify(payload)
1943
1942
  });
1944
1943
  const data = requireSuccess(raw, "Suno task submit failed");
1945
1944
  if (!config.poll) return buildImmediateResult(operation, data, raw);
1946
- const taskId = extractTaskId(data);
1945
+ const taskId = extractTaskId$1(data);
1947
1946
  if (!taskId) return buildImmediateResult(operation, data, raw);
1948
- return pollSunoTask(input, operation, taskId, asInteger(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC), asInteger(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC));
1947
+ return pollSunoTask(input, operation, taskId, asInteger(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$1), asInteger(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$1));
1948
+ }
1949
+
1950
+ //#endregion
1951
+ //#region src/adapters/video-upscale-native.ts
1952
+ const REQUEST_TIMEOUT_MS = 186e4;
1953
+ const DEFAULT_POLL_INTERVAL_SEC = 2;
1954
+ const DEFAULT_MAX_WAIT_SEC = 600;
1955
+ function sleep(ms) {
1956
+ return new Promise((resolve) => setTimeout(resolve, ms));
1957
+ }
1958
+ function isRecord$2(value) {
1959
+ return !!value && typeof value === "object" && !Array.isArray(value);
1960
+ }
1961
+ function asString(value) {
1962
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
1963
+ }
1964
+ function normalizeStatus(value) {
1965
+ const status = String(value ?? "").trim().toLowerCase();
1966
+ if ([
1967
+ "success",
1968
+ "succeed",
1969
+ "succeeded",
1970
+ "completed"
1971
+ ].includes(status)) return "succeeded";
1972
+ if ([
1973
+ "queued",
1974
+ "processing",
1975
+ "in_progress",
1976
+ "running",
1977
+ "submitted",
1978
+ "not_start"
1979
+ ].includes(status)) return "processing";
1980
+ if ([
1981
+ "failure",
1982
+ "failed",
1983
+ "error",
1984
+ "cancelled",
1985
+ "canceled",
1986
+ "expired"
1987
+ ].includes(status)) return "failed";
1988
+ return status || "unknown";
1989
+ }
1990
+ function unwrapTaskPayload(response) {
1991
+ const data = isRecord$2(response.data) ? response.data : void 0;
1992
+ const hasTaskFields = [
1993
+ "status",
1994
+ "task",
1995
+ "result_url",
1996
+ "video_url",
1997
+ "url",
1998
+ "error",
1999
+ "progress",
2000
+ "fail_reason"
2001
+ ].some((key) => key in response);
2002
+ return data && !hasTaskFields ? data : response;
2003
+ }
2004
+ function extractTaskId(response) {
2005
+ const data = isRecord$2(response.data) ? response.data : void 0;
2006
+ const taskId = asString(response.task_id) ?? asString(response.id) ?? asString(data?.task_id) ?? asString(data?.id);
2007
+ if (!taskId) throw new GenerationProviderError("Video upscale provider did not return a task id", { details: { response } });
2008
+ return taskId;
2009
+ }
2010
+ function extractTaskStatus(response) {
2011
+ const payload = unwrapTaskPayload(response);
2012
+ const task = isRecord$2(payload.task) ? payload.task : payload;
2013
+ const metadata = isRecord$2(payload.metadata) ? payload.metadata : isRecord$2(task.metadata) ? task.metadata : void 0;
2014
+ const content = isRecord$2(task.content) ? task.content : void 0;
2015
+ const status = normalizeStatus(payload.status ?? task.status);
2016
+ const videoUrl = asString(metadata?.url) ?? asString(payload.result_url) ?? asString(payload.video_url) ?? asString(payload.url) ?? asString(task.result_url) ?? asString(task.video_url) ?? asString(task.url) ?? asString(content?.video_url) ?? asString(content?.url);
2017
+ const error = isRecord$2(payload.error) ? payload.error : isRecord$2(task.error) ? task.error : void 0;
2018
+ const message = asString(error?.message) ?? asString(payload.fail_reason) ?? asString(payload.message) ?? asString(task.fail_reason) ?? asString(task.message) ?? asString(response.message);
2019
+ const outputMetadata = compactObject({
2020
+ progress: payload.progress ?? task.progress,
2021
+ output_width: payload.output_width ?? task.output_width,
2022
+ output_height: payload.output_height ?? task.output_height
2023
+ });
2024
+ return {
2025
+ status: error && status === "unknown" ? "failed" : status,
2026
+ videoUrl,
2027
+ message,
2028
+ metadata: outputMetadata
2029
+ };
2030
+ }
2031
+ async function requestJson(input, path, init) {
2032
+ const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
2033
+ ...init,
2034
+ headers: {
2035
+ Authorization: `Bearer ${input.context.apiKey}`,
2036
+ "Content-Type": "application/json",
2037
+ ...init.headers
2038
+ }
2039
+ }, REQUEST_TIMEOUT_MS);
2040
+ const body = await response.text();
2041
+ let parsed = {};
2042
+ try {
2043
+ parsed = body ? JSON.parse(body) : {};
2044
+ } catch {
2045
+ throw new GenerationProviderError("Video upscale provider returned invalid JSON", {
2046
+ status: response.status,
2047
+ body
2048
+ });
2049
+ }
2050
+ if (!response.ok) throw new GenerationProviderError("Video upscale provider request failed", {
2051
+ status: response.status,
2052
+ body,
2053
+ ...isRecord$2(parsed) ? { details: parsed } : {}
2054
+ });
2055
+ return parsed;
2056
+ }
2057
+ function validateResolvedUrl(value) {
2058
+ let parsed;
2059
+ try {
2060
+ parsed = new URL(value);
2061
+ } catch {
2062
+ throw new GenerationValidationError("video-upscale-native requires an absolute http or https video URL");
2063
+ }
2064
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || parsed.username || parsed.password) throw new GenerationValidationError("video-upscale-native requires an absolute http or https video URL");
2065
+ }
2066
+ async function videoUpscaleNativeAdapter(input) {
2067
+ const video = input.request.content.find((block) => block.type === "video");
2068
+ if (!video || video.type !== "video") throw new GenerationValidationError("video-upscale-native requires one video URL");
2069
+ const videoUrl = await input.context.resolveSource(video.source);
2070
+ validateResolvedUrl(videoUrl);
2071
+ const pollIntervalSec = DEFAULT_POLL_INTERVAL_SEC;
2072
+ const maxWaitSec = DEFAULT_MAX_WAIT_SEC;
2073
+ const taskId = extractTaskId(await requestJson(input, "/v1/video/generations", {
2074
+ method: "POST",
2075
+ body: JSON.stringify({
2076
+ model: input.declaration.model,
2077
+ video_url: videoUrl
2078
+ })
2079
+ }));
2080
+ const startedAt = Date.now();
2081
+ while (Date.now() - startedAt <= maxWaitSec * 1e3) {
2082
+ await sleep(pollIntervalSec * 1e3);
2083
+ const rawStatus = await requestJson(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
2084
+ const status = extractTaskStatus(rawStatus);
2085
+ if (status.status === "succeeded") {
2086
+ if (!status.videoUrl) throw new GenerationProviderError("Video upscale succeeded but returned no video URL", { details: compactObject({
2087
+ taskId,
2088
+ rawStatus,
2089
+ metadata: status.metadata
2090
+ }) });
2091
+ return [{
2092
+ type: "video",
2093
+ source: {
2094
+ type: "url",
2095
+ url: status.videoUrl
2096
+ },
2097
+ meta: {
2098
+ task_id: taskId,
2099
+ status: status.status,
2100
+ ...status.metadata
2101
+ }
2102
+ }];
2103
+ }
2104
+ if (status.status === "failed") throw new GenerationProviderError(`Video upscale failed${status.message ? `: ${status.message}` : ""}`, { details: compactObject({
2105
+ taskId,
2106
+ rawStatus
2107
+ }) });
2108
+ }
2109
+ throw new GenerationTimeoutError("Timed out waiting for video upscale", { taskId });
1949
2110
  }
1950
2111
 
1951
2112
  //#endregion
@@ -1958,7 +2119,8 @@ const builtinGenerationAdapters = {
1958
2119
  "minimax.h3VideoGenerations": minimaxH3VideoGenerationsAdapter,
1959
2120
  "openai.imageEdits": openAiImageEditsAdapter,
1960
2121
  "openai.images": openAiImagesAdapter,
1961
- "suno.tasks": sunoTasksAdapter
2122
+ "suno.tasks": sunoTasksAdapter,
2123
+ "video.upscaleNative": videoUpscaleNativeAdapter
1962
2124
  };
1963
2125
  function tryGetGenerationAdapter(type, adapters = {}) {
1964
2126
  return adapters[type] ?? builtinGenerationAdapters[type];
@@ -2309,5 +2471,5 @@ async function exportBuiltinModelConfigs(directory) {
2309
2471
  }
2310
2472
 
2311
2473
  //#endregion
2312
- export { resolveGenerationMeta as A, minimaxH3VideoGenerationsAdapter as C, arkVideoGenerationsAdapter as D, audioSpeechAdapter as E, GenerationProviderError as F, GenerationTimeoutError as I, GenerationTransportError as L, validateGenerationContent as M, GenerationConfigError as N, mergeGenerationMeta as O, GenerationError as P, GenerationUnsupportedAdapterError 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, GenerationValidationError as z };
2313
- //# sourceMappingURL=export-config-Ct9_V_Pj.js.map
2474
+ export { mergeTextBlocks as A, GenerationValidationError as B, openAiImageEditsAdapter as C, audioSpeechAdapter as D, geminiGenerateContentAdapter as E, GenerationError as F, GenerationProviderError as I, GenerationTimeoutError as L, resolveGenerationParameters as M, validateGenerationContent as N, arkVideoGenerationsAdapter as O, GenerationConfigError as P, GenerationTransportError as R, openAiImagesAdapter as S, klingVideoGenerationsAdapter as T, writeGenerationModelDeclarations as _, createGenerationClientFromDirectory as a, videoUpscaleNativeAdapter as b, defaultGenerationSourceResolver as c, parseGenerationModelDeclaration as d, readGenerationModelDeclaration as f, writeGenerationModelDeclaration as g, stringifyGenerationModelDeclaration as h, createGenerationClient as i, resolveGenerationMeta as j, mergeGenerationMeta 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, minimaxH3VideoGenerationsAdapter as w, sunoTasksAdapter as x, getGenerationAdapter as y, GenerationUnsupportedAdapterError as z };
2475
+ //# sourceMappingURL=export-config-CzgN6UE_.js.map