@neta-art/generation 0.1.22 → 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,13 +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
1316
  return mode === "text" && requested === ADAPTIVE_RATIO ? DEFAULT_RATIO : requested;
1317
1317
  }
1318
- function extractTaskId$1(response) {
1319
- const data = isRecord$3(response.data) ? response.data : void 0;
1320
- 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);
1321
1321
  if (!taskId) throw new GenerationProviderError("MiniMax H3 provider did not return a task id", { details: { response } });
1322
1322
  return taskId;
1323
1323
  }
@@ -1333,19 +1333,19 @@ function isTaskPayload(value) {
1333
1333
  "fail_reason"
1334
1334
  ].some((key) => key in value);
1335
1335
  }
1336
- function unwrapTaskPayload(response) {
1337
- 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;
1338
1338
  return data && !isTaskPayload(response) ? data : response;
1339
1339
  }
1340
- function extractTaskStatus(response) {
1341
- const payload = unwrapTaskPayload(response);
1342
- const task = isRecord$3(payload.task) ? payload.task : payload;
1343
- const metadata = isRecord$3(payload.metadata) ? payload.metadata : isRecord$3(task.metadata) ? task.metadata : void 0;
1344
- const content = isRecord$3(task.content) ? task.content : void 0;
1345
- const status = normalizeStatus$1(payload.status ?? task.status);
1346
- 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);
1347
- const error = isRecord$3(payload.error) ? payload.error : isRecord$3(task.error) ? task.error : void 0;
1348
- 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);
1349
1349
  const outputMetadata = compactObject({
1350
1350
  progress: payload.progress ?? task.progress,
1351
1351
  resolution: payload.resolution ?? task.resolution,
@@ -1359,7 +1359,7 @@ function extractTaskStatus(response) {
1359
1359
  metadata: outputMetadata
1360
1360
  };
1361
1361
  }
1362
- async function requestJson$1(input, path, init) {
1362
+ async function requestJson$2(input, path, init) {
1363
1363
  const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
1364
1364
  ...init,
1365
1365
  headers: {
@@ -1367,7 +1367,7 @@ async function requestJson$1(input, path, init) {
1367
1367
  "Content-Type": "application/json",
1368
1368
  ...init.headers
1369
1369
  }
1370
- }, REQUEST_TIMEOUT_MS$3);
1370
+ }, REQUEST_TIMEOUT_MS$4);
1371
1371
  const body = await response.text();
1372
1372
  let parsed = {};
1373
1373
  try {
@@ -1381,7 +1381,7 @@ async function requestJson$1(input, path, init) {
1381
1381
  if (!response.ok) throw new GenerationProviderError("MiniMax H3 provider request failed", {
1382
1382
  status: response.status,
1383
1383
  body,
1384
- ...isRecord$3(parsed) ? { details: parsed } : {}
1384
+ ...isRecord$4(parsed) ? { details: parsed } : {}
1385
1385
  });
1386
1386
  return parsed;
1387
1387
  }
@@ -1394,8 +1394,8 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1394
1394
  const duration = resolveDuration(input.parameters.duration);
1395
1395
  const resolution = resolveResolution(input.parameters.resolution);
1396
1396
  const ratio = resolveRatio(input.parameters.ratio, mode);
1397
- const pollIntervalSec = Math.max(1, asInteger$1(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$1));
1398
- 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));
1399
1399
  const aigcWatermark = asBoolean(input.parameters.aigc_watermark, false);
1400
1400
  const payload = {
1401
1401
  model: input.declaration.model,
@@ -1405,15 +1405,15 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1405
1405
  ratio,
1406
1406
  aigc_watermark: aigcWatermark
1407
1407
  };
1408
- const taskId = extractTaskId$1(await requestJson$1(input, "/v1/video/generations", {
1408
+ const taskId = extractTaskId$2(await requestJson$2(input, "/v1/video/generations", {
1409
1409
  method: "POST",
1410
1410
  body: JSON.stringify(payload)
1411
1411
  }));
1412
1412
  const startedAt = Date.now();
1413
1413
  while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1414
- await sleep$1(pollIntervalSec * 1e3);
1415
- const rawStatus = await requestJson$1(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
1416
- 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);
1417
1417
  if (status.status === "succeeded") {
1418
1418
  if (!status.videoUrl) throw new GenerationProviderError("MiniMax H3 generation succeeded but returned no video URL", { details: compactObject({
1419
1419
  taskId,
@@ -1443,7 +1443,7 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1443
1443
 
1444
1444
  //#endregion
1445
1445
  //#region src/adapters/openai-image-edits.ts
1446
- const REQUEST_TIMEOUT_MS$2 = 3e5;
1446
+ const REQUEST_TIMEOUT_MS$3 = 3e5;
1447
1447
  function firstUrlImage(input) {
1448
1448
  const image = input.request.content.find((block) => block.type === "image");
1449
1449
  if (!image) throw new GenerationValidationError("Source image is required");
@@ -1475,7 +1475,7 @@ async function openAiImageEditsAdapter(input) {
1475
1475
  method: "POST",
1476
1476
  headers: { Authorization: `Bearer ${input.context.apiKey}` },
1477
1477
  body
1478
- }, REQUEST_TIMEOUT_MS$2);
1478
+ }, REQUEST_TIMEOUT_MS$3);
1479
1479
  if (!response.ok) {
1480
1480
  const bodyText = await response.text().catch(() => response.statusText);
1481
1481
  throw new GenerationProviderError("Image edit provider request failed", {
@@ -1513,7 +1513,7 @@ async function openAiImageEditsAdapter(input) {
1513
1513
 
1514
1514
  //#endregion
1515
1515
  //#region src/adapters/openai-images.ts
1516
- const REQUEST_TIMEOUT_MS$1 = 3e5;
1516
+ const REQUEST_TIMEOUT_MS$2 = 3e5;
1517
1517
  function collectOpenAiImagesNoOutputDetails(raw) {
1518
1518
  const data = raw.data ?? [];
1519
1519
  return compactObject({
@@ -1552,7 +1552,7 @@ async function openAiImagesAdapter(input) {
1552
1552
  "Content-Type": "application/json"
1553
1553
  },
1554
1554
  body: JSON.stringify(payload)
1555
- }, REQUEST_TIMEOUT_MS$1);
1555
+ }, REQUEST_TIMEOUT_MS$2);
1556
1556
  if (!response.ok) {
1557
1557
  const body = await response.text().catch(() => response.statusText);
1558
1558
  throw new GenerationProviderError("Image generation provider request failed", {
@@ -1590,9 +1590,9 @@ async function openAiImagesAdapter(input) {
1590
1590
 
1591
1591
  //#endregion
1592
1592
  //#region src/adapters/suno-tasks.ts
1593
- const REQUEST_TIMEOUT_MS = 6e4;
1594
- const DEFAULT_POLL_INTERVAL_SEC = 5;
1595
- 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;
1596
1596
  const DEFAULT_MUSIC_VERSION = "chirp-v5";
1597
1597
  const OPERATION_PATHS = {
1598
1598
  music: {
@@ -1635,20 +1635,20 @@ const FINAL_FAILURE_STATUSES = new Set([
1635
1635
  "canceled",
1636
1636
  "expired"
1637
1637
  ]);
1638
- function sleep(ms) {
1638
+ function sleep$1(ms) {
1639
1639
  return new Promise((resolve) => setTimeout(resolve, ms));
1640
1640
  }
1641
- function isRecord$2(value) {
1641
+ function isRecord$3(value) {
1642
1642
  return !!value && typeof value === "object" && !Array.isArray(value);
1643
1643
  }
1644
- function asString(value) {
1644
+ function asString$1(value) {
1645
1645
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
1646
1646
  }
1647
1647
  function asInteger(value, fallback) {
1648
1648
  return typeof value === "number" && Number.isInteger(value) ? value : fallback;
1649
1649
  }
1650
1650
  function asRecord(value) {
1651
- return isRecord$2(value) ? value : {};
1651
+ return isRecord$3(value) ? value : {};
1652
1652
  }
1653
1653
  function successCode(value) {
1654
1654
  const code = String(value ?? "").trim().toLowerCase();
@@ -1662,19 +1662,19 @@ function requireSuccess(response, fallbackMessage) {
1662
1662
  } });
1663
1663
  return response.data;
1664
1664
  }
1665
- function extractTaskId(value) {
1665
+ function extractTaskId$1(value) {
1666
1666
  if (typeof value === "string" && value.trim()) return value.trim();
1667
- if (!isRecord$2(value)) return void 0;
1667
+ if (!isRecord$3(value)) return void 0;
1668
1668
  for (const key of [
1669
1669
  "task_id",
1670
1670
  "id",
1671
1671
  "taskBatchId"
1672
1672
  ]) {
1673
- const taskId = asString(value[key]);
1673
+ const taskId = asString$1(value[key]);
1674
1674
  if (taskId) return taskId;
1675
1675
  }
1676
1676
  }
1677
- function normalizeStatus(value) {
1677
+ function normalizeStatus$1(value) {
1678
1678
  const status = String(value ?? "").trim().toLowerCase();
1679
1679
  if (status === "finished") return "success";
1680
1680
  if (status === "fail" || status === "rejected") return "failed";
@@ -1682,7 +1682,7 @@ function normalizeStatus(value) {
1682
1682
  }
1683
1683
  function normalizeTask(operation, data) {
1684
1684
  if (Array.isArray(data)) return data.length > 0 ? normalizeTask(operation, data[0]) : null;
1685
- if (!isRecord$2(data)) return null;
1685
+ if (!isRecord$3(data)) return null;
1686
1686
  if ("status" in data || "taskStatus" in data || "task_status" in data || "task_id" in data || "taskBatchId" in data) {
1687
1687
  const hasProviderEnvelope = "taskStatus" in data || "task_status" in data || "taskBatchId" in data || "task_batch_id" in data;
1688
1688
  return {
@@ -1701,8 +1701,8 @@ function normalizeTask(operation, data) {
1701
1701
  };
1702
1702
  }
1703
1703
  function getOperation(input) {
1704
- const fixedOperation = asString(input.declaration.adapter.operation);
1705
- const requestedOperation = asString(input.parameters.operation);
1704
+ const fixedOperation = asString$1(input.declaration.adapter.operation);
1705
+ const requestedOperation = asString$1(input.parameters.operation);
1706
1706
  if (fixedOperation && requestedOperation && fixedOperation !== requestedOperation) throw new GenerationValidationError(`${input.declaration.model} uses Suno operation ${fixedOperation}; parameters.operation cannot override it`);
1707
1707
  const operation = fixedOperation ?? requestedOperation ?? "music";
1708
1708
  if (!OPERATION_PATHS[operation]) throw new GenerationValidationError(`Unsupported Suno operation: ${operation}`);
@@ -1731,13 +1731,13 @@ async function buildPayload(input, operation) {
1731
1731
  if (payload.video_url === void 0) payload.video_url = videoUrl;
1732
1732
  }
1733
1733
  applyFixedPayload(input, payload, asRecord(input.declaration.adapter.payload));
1734
- const fixedTask = asString(input.declaration.adapter.task);
1734
+ const fixedTask = asString$1(input.declaration.adapter.task);
1735
1735
  if (fixedTask) applyFixedPayload(input, payload, { task: fixedTask });
1736
- const task = asString(payload.task);
1736
+ const task = asString$1(payload.task);
1737
1737
  if (task === "image_to_song" && imageUrl) setMetadataParam(payload, "image_url", imageUrl);
1738
1738
  if (task === "video_to_song" && videoUrl) setMetadataParam(payload, "video_url", videoUrl);
1739
1739
  if (task === "cover" && payload.clip_id === void 0) {
1740
- const coverClipId = asString(payload.cover_clip_id);
1740
+ const coverClipId = asString$1(payload.cover_clip_id);
1741
1741
  if (coverClipId) payload.clip_id = coverClipId;
1742
1742
  }
1743
1743
  normalizeMusicTaskPayload(input, operation, payload);
@@ -1753,7 +1753,7 @@ function applyFixedPayload(input, payload, fixed) {
1753
1753
  }
1754
1754
  }
1755
1755
  function setMetadataParam(payload, key, value) {
1756
- const metadataParams = isRecord$2(payload.metadata_params) ? payload.metadata_params : {};
1756
+ const metadataParams = isRecord$3(payload.metadata_params) ? payload.metadata_params : {};
1757
1757
  if (metadataParams[key] === void 0) metadataParams[key] = value;
1758
1758
  payload.metadata_params = metadataParams;
1759
1759
  }
@@ -1763,7 +1763,7 @@ function contentCount(content, type) {
1763
1763
  function normalizeMusicTaskPayload(input, operation, payload) {
1764
1764
  if (operation !== "music") return;
1765
1765
  const taskField = input.declaration.meta?.taskField ?? "task";
1766
- const task = asString(payload[taskField]);
1766
+ const task = asString$1(payload[taskField]);
1767
1767
  if (!task) return;
1768
1768
  const taskVariant = input.declaration.meta?.taskVariants?.[task];
1769
1769
  if (!taskVariant) throw new GenerationValidationError(`Unsupported Suno music task: ${task}`);
@@ -1773,15 +1773,15 @@ function normalizeMusicTaskPayload(input, operation, payload) {
1773
1773
  }
1774
1774
  function validateSunoPayload(operation, payload) {
1775
1775
  const config = OPERATION_PATHS[operation];
1776
- const task = asString(payload.task);
1776
+ const task = asString$1(payload.task);
1777
1777
  if (operation === "music" && task) {
1778
1778
  if (task === "lyrics") throw new GenerationValidationError("Use operation=lyrics instead of task=lyrics");
1779
1779
  }
1780
- if (config?.requireText && !asString(payload[config.textField ?? "prompt"])) throw new GenerationValidationError(`${config.textField ?? "prompt"} text is required`);
1781
- if (operation === "upload_audio" && !asString(payload.url)) throw new GenerationValidationError("Audio url is required for Suno upload_audio");
1782
- 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");
1783
1783
  }
1784
- async function requestJson(input, path, init) {
1784
+ async function requestJson$1(input, path, init) {
1785
1785
  const response = await fetchWithTimeout(input.context.fetch, joinUrl(input.context.baseUrl, path), {
1786
1786
  ...init,
1787
1787
  headers: {
@@ -1789,7 +1789,7 @@ async function requestJson(input, path, init) {
1789
1789
  "Content-Type": "application/json",
1790
1790
  ...init.headers
1791
1791
  }
1792
- }, REQUEST_TIMEOUT_MS);
1792
+ }, REQUEST_TIMEOUT_MS$1);
1793
1793
  const body = await response.text();
1794
1794
  let parsed;
1795
1795
  try {
@@ -1807,7 +1807,7 @@ async function requestJson(input, path, init) {
1807
1807
  return parsed;
1808
1808
  }
1809
1809
  function appendUrlBlock(output, type, url, meta) {
1810
- const value = asString(url);
1810
+ const value = asString$1(url);
1811
1811
  if (!value) return;
1812
1812
  output.push({
1813
1813
  type,
@@ -1823,8 +1823,8 @@ function appendSunoContent(output, value, meta = {}) {
1823
1823
  for (const item of value) appendSunoContent(output, item, meta);
1824
1824
  return;
1825
1825
  }
1826
- if (!isRecord$2(value)) return;
1827
- 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);
1828
1828
  if (Array.isArray(value.items)) for (const item of value.items) appendSunoContent(output, item, meta);
1829
1829
  const itemMeta = compactObject({
1830
1830
  ...meta,
@@ -1834,9 +1834,9 @@ function appendSunoContent(output, value, meta = {}) {
1834
1834
  title: value.title,
1835
1835
  status: value.status ?? meta.status,
1836
1836
  model: value.model_name ?? value.modelName,
1837
- duration: value.duration ?? (isRecord$2(value.metadata) ? value.metadata.duration : void 0),
1838
- tags: value.tags ?? (isRecord$2(value.metadata) ? value.metadata.tags : void 0),
1839
- 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),
1840
1840
  progress: value.progress ?? meta.progress,
1841
1841
  progress_message: value.progressMsg ?? value.progress_msg,
1842
1842
  task_batch_id: value.taskBatchId ?? value.task_batch_id,
@@ -1851,13 +1851,13 @@ function appendSunoContent(output, value, meta = {}) {
1851
1851
  appendUrlBlock(output, "audio", value.source_audio_url ?? value.sourceAudioUrl, itemMeta);
1852
1852
  appendUrlBlock(output, "video", value.video_url ?? value.videoUrl ?? value.cld2VideoUrl ?? value.cld2_video_url, itemMeta);
1853
1853
  appendUrlBlock(output, "image", value.image_large_url ?? value.image_url ?? value.imageUrl ?? value.cld2ImageUrl ?? value.cld2_image_url, itemMeta);
1854
- 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);
1855
1855
  if (text) output.push({
1856
1856
  type: "text",
1857
1857
  text,
1858
1858
  meta: itemMeta
1859
1859
  });
1860
- if (isRecord$2(value.data)) appendSunoContent(output, value.data, itemMeta);
1860
+ if (isRecord$3(value.data)) appendSunoContent(output, value.data, itemMeta);
1861
1861
  }
1862
1862
  function buildImmediateResult(operation, data, raw) {
1863
1863
  const output = [];
@@ -1867,7 +1867,7 @@ function buildImmediateResult(operation, data, raw) {
1867
1867
  });
1868
1868
  appendSunoContent(output, data, metadata);
1869
1869
  if (output.length > 0) return output;
1870
- const value = extractTaskId(data) ?? asString(data);
1870
+ const value = extractTaskId$1(data) ?? asString$1(data);
1871
1871
  if (value) output.push({
1872
1872
  type: "text",
1873
1873
  text: value,
@@ -1907,10 +1907,10 @@ function buildResult(operation, task, raw) {
1907
1907
  async function pollSunoTask(input, operation, taskId, pollIntervalSec, maxWaitSec) {
1908
1908
  const startedAt = Date.now();
1909
1909
  while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1910
- await sleep(pollIntervalSec * 1e3);
1910
+ await sleep$1(pollIntervalSec * 1e3);
1911
1911
  let raw;
1912
1912
  try {
1913
- raw = await requestJson(input, `/suno/fetch/${encodeURIComponent(taskId)}`, { method: "GET" });
1913
+ raw = await requestJson$1(input, `/suno/fetch/${encodeURIComponent(taskId)}`, { method: "GET" });
1914
1914
  } catch (error) {
1915
1915
  if (error instanceof GenerationProviderError) throw error;
1916
1916
  continue;
@@ -1918,7 +1918,7 @@ async function pollSunoTask(input, operation, taskId, pollIntervalSec, maxWaitSe
1918
1918
  const data = requireSuccess(raw, "Suno task fetch failed");
1919
1919
  const task = normalizeTask(operation, data);
1920
1920
  if (!task) throw new GenerationProviderError("Suno task fetch returned invalid task data", { details: { data } });
1921
- const status = normalizeStatus(task.status);
1921
+ const status = normalizeStatus$1(task.status);
1922
1922
  if (FINAL_SUCCESS_STATUSES.has(status)) return buildResult(operation, task, data);
1923
1923
  if (FINAL_FAILURE_STATUSES.has(status)) throw new GenerationProviderError("Suno task failed", { details: {
1924
1924
  task_id: taskId,
@@ -1936,15 +1936,177 @@ async function sunoTasksAdapter(input) {
1936
1936
  const payload = await buildPayload(input, operation);
1937
1937
  const config = OPERATION_PATHS[operation];
1938
1938
  if (!config) throw new GenerationValidationError(`Unsupported Suno operation: ${operation}`);
1939
- const raw = await requestJson(input, config.path, {
1939
+ const raw = await requestJson$1(input, config.path, {
1940
1940
  method: "POST",
1941
1941
  body: JSON.stringify(payload)
1942
1942
  });
1943
1943
  const data = requireSuccess(raw, "Suno task submit failed");
1944
1944
  if (!config.poll) return buildImmediateResult(operation, data, raw);
1945
- const taskId = extractTaskId(data);
1945
+ const taskId = extractTaskId$1(data);
1946
1946
  if (!taskId) return buildImmediateResult(operation, data, raw);
1947
- 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 });
1948
2110
  }
1949
2111
 
1950
2112
  //#endregion
@@ -1957,7 +2119,8 @@ const builtinGenerationAdapters = {
1957
2119
  "minimax.h3VideoGenerations": minimaxH3VideoGenerationsAdapter,
1958
2120
  "openai.imageEdits": openAiImageEditsAdapter,
1959
2121
  "openai.images": openAiImagesAdapter,
1960
- "suno.tasks": sunoTasksAdapter
2122
+ "suno.tasks": sunoTasksAdapter,
2123
+ "video.upscaleNative": videoUpscaleNativeAdapter
1961
2124
  };
1962
2125
  function tryGetGenerationAdapter(type, adapters = {}) {
1963
2126
  return adapters[type] ?? builtinGenerationAdapters[type];
@@ -2308,5 +2471,5 @@ async function exportBuiltinModelConfigs(directory) {
2308
2471
  }
2309
2472
 
2310
2473
  //#endregion
2311
- 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 };
2312
- //# sourceMappingURL=export-config-MvqQsM_g.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