@neta-art/generation 0.1.24 → 0.1.26

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 GENERATION_MODEL_CATEGORIES, n as getBuiltinGenerationModel, o as compactObject, r as listBuiltinGenerationModels, s as getBlockMeta, t as builtinGenerationModels, u as MODEL_SCHEMA } from "./builtins-Bn6iOBYm.js";
1
+ import { a as compactArray, c as slugifyFileName, d as MODEL_SCHEMA, i as cloneJson, l as GENERATION_MODEL_CATEGORIES, n as getBuiltinGenerationModel, o as compactObject, r as listBuiltinGenerationModels, s as getBlockMeta, t as builtinGenerationModels, u as GENERATION_PRICING_UNITS } from "./builtins-Cvj5PK_9.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";
@@ -223,6 +223,23 @@ function isRecord$7(value) {
223
223
  return typeof value === "object" && value !== null;
224
224
  }
225
225
 
226
+ //#endregion
227
+ //#region src/task-poll.ts
228
+ function sleep(ms) {
229
+ return new Promise((resolve) => {
230
+ setTimeout(resolve, Math.max(0, ms));
231
+ });
232
+ }
233
+ /** Yield immediately, then wait `intervalMs` between later ticks until `maxWaitMs`. */
234
+ async function* taskPollTicks(maxWaitMs, intervalMs) {
235
+ const startedAt = Date.now();
236
+ while (Date.now() - startedAt <= maxWaitMs) {
237
+ yield;
238
+ if (Date.now() - startedAt > maxWaitMs) return;
239
+ await sleep(intervalMs);
240
+ }
241
+ }
242
+
226
243
  //#endregion
227
244
  //#region src/validation.ts
228
245
  function specsByType(specs) {
@@ -359,11 +376,8 @@ function mergeTextBlocks(declaration, content) {
359
376
  //#endregion
360
377
  //#region src/adapters/ark-video-generations.ts
361
378
  const REQUEST_TIMEOUT_MS$8 = 186e4;
362
- const DEFAULT_POLL_INTERVAL_SEC$4 = 2;
379
+ const DEFAULT_POLL_INTERVAL_SEC$4 = 1;
363
380
  const DEFAULT_MAX_WAIT_SEC$4 = 600;
364
- function sleep$4(ms) {
365
- return new Promise((resolve) => setTimeout(resolve, ms));
366
- }
367
381
  function asString$4(value) {
368
382
  return typeof value === "string" && value ? value : void 0;
369
383
  }
@@ -550,9 +564,7 @@ async function arkVideoGenerationsAdapter(input) {
550
564
  method: "POST",
551
565
  body: JSON.stringify(payload)
552
566
  }));
553
- const startedAt = Date.now();
554
- while (Date.now() - startedAt <= maxWaitSec * 1e3) {
555
- await sleep$4(pollIntervalSec * 1e3);
567
+ for await (const _ of taskPollTicks(maxWaitSec * 1e3, pollIntervalSec * 1e3)) {
556
568
  const rawStatus = await requestJson$4(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
557
569
  const status = normalizeTaskStatus(rawStatus);
558
570
  if (status.status === "succeeded") {
@@ -954,9 +966,6 @@ const KLING_MODELS = {
954
966
  imageMode: "multi"
955
967
  }
956
968
  };
957
- function sleep$3(ms) {
958
- return new Promise((resolve) => setTimeout(resolve, ms));
959
- }
960
969
  function asString$3(value) {
961
970
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
962
971
  }
@@ -1132,9 +1141,7 @@ async function klingVideoGenerationsAdapter(input) {
1132
1141
  }));
1133
1142
  const pollIntervalSec = asInteger$2(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC$3);
1134
1143
  const maxWaitSec = asInteger$2(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC$3);
1135
- const startedAt = Date.now();
1136
- while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1137
- await sleep$3(pollIntervalSec * 1e3);
1144
+ for await (const _ of taskPollTicks(maxWaitSec * 1e3, pollIntervalSec * 1e3)) {
1138
1145
  const rawStatus = await requestJson$3(input, `${model.submitPath}/${encodeURIComponent(taskId)}`, { method: "GET" });
1139
1146
  const status = extractStatus(rawStatus);
1140
1147
  if (status.status === "succeeded") {
@@ -1168,10 +1175,8 @@ async function klingVideoGenerationsAdapter(input) {
1168
1175
  //#endregion
1169
1176
  //#region src/adapters/minimax-h3-video-generations.ts
1170
1177
  const REQUEST_TIMEOUT_MS$4 = 186e4;
1171
- const DEFAULT_POLL_INTERVAL_SEC$2 = 2;
1172
- const DEFAULT_MAX_WAIT_SEC$2 = 600;
1173
- const MIN_DURATION_SEC = 4;
1174
- const MAX_DURATION_SEC = 15;
1178
+ const DEFAULT_POLL_INTERVAL_SEC$2 = 1;
1179
+ const DEFAULT_MAX_WAIT_SEC$2 = 1800;
1175
1180
  const MAX_MEDIA_COUNT = 12;
1176
1181
  const MAX_REFERENCE_IMAGES = 9;
1177
1182
  const MAX_REFERENCE_VIDEOS = 3;
@@ -1187,9 +1192,6 @@ const H3_RATIOS = [
1187
1192
  "3:4",
1188
1193
  "9:16"
1189
1194
  ];
1190
- function sleep$2(ms) {
1191
- return new Promise((resolve) => setTimeout(resolve, ms));
1192
- }
1193
1195
  function asString$2(value) {
1194
1196
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
1195
1197
  }
@@ -1301,14 +1303,10 @@ function buildContent(prompt, media) {
1301
1303
  })];
1302
1304
  }
1303
1305
  function resolveResolution(value) {
1304
- const resolution = (asString$2(value) ?? "768P").toUpperCase();
1305
- if (resolution !== "768P" && resolution !== "2K") throw new GenerationValidationError("MiniMax H3 resolution must be 768P or 2K");
1306
- return resolution;
1306
+ return asString$2(value) ?? "768P";
1307
1307
  }
1308
1308
  function resolveDuration(value) {
1309
- const duration = asInteger$1(value, 5);
1310
- if (duration < MIN_DURATION_SEC || duration > MAX_DURATION_SEC) throw new GenerationValidationError("MiniMax H3 duration must be an integer between 4 and 15");
1311
- return duration;
1309
+ return asInteger$1(value, 5);
1312
1310
  }
1313
1311
  function resolveRatio(value, mode) {
1314
1312
  const requested = asString$2(value) ?? DEFAULT_RATIO;
@@ -1409,9 +1407,7 @@ async function minimaxH3VideoGenerationsAdapter(input) {
1409
1407
  method: "POST",
1410
1408
  body: JSON.stringify(payload)
1411
1409
  }));
1412
- const startedAt = Date.now();
1413
- while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1414
- await sleep$2(pollIntervalSec * 1e3);
1410
+ for await (const _ of taskPollTicks(maxWaitSec * 1e3, pollIntervalSec * 1e3)) {
1415
1411
  const rawStatus = await requestJson$2(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
1416
1412
  const status = extractTaskStatus$1(rawStatus);
1417
1413
  if (status.status === "succeeded") {
@@ -1635,9 +1631,6 @@ const FINAL_FAILURE_STATUSES = new Set([
1635
1631
  "canceled",
1636
1632
  "expired"
1637
1633
  ]);
1638
- function sleep$1(ms) {
1639
- return new Promise((resolve) => setTimeout(resolve, ms));
1640
- }
1641
1634
  function isRecord$3(value) {
1642
1635
  return !!value && typeof value === "object" && !Array.isArray(value);
1643
1636
  }
@@ -1905,9 +1898,7 @@ function buildResult(operation, task, raw) {
1905
1898
  });
1906
1899
  }
1907
1900
  async function pollSunoTask(input, operation, taskId, pollIntervalSec, maxWaitSec) {
1908
- const startedAt = Date.now();
1909
- while (Date.now() - startedAt <= maxWaitSec * 1e3) {
1910
- await sleep$1(pollIntervalSec * 1e3);
1901
+ for await (const _ of taskPollTicks(maxWaitSec * 1e3, pollIntervalSec * 1e3)) {
1911
1902
  let raw;
1912
1903
  try {
1913
1904
  raw = await requestJson$1(input, `/suno/fetch/${encodeURIComponent(taskId)}`, { method: "GET" });
@@ -1950,11 +1941,8 @@ async function sunoTasksAdapter(input) {
1950
1941
  //#endregion
1951
1942
  //#region src/adapters/video-upscale-native.ts
1952
1943
  const REQUEST_TIMEOUT_MS = 186e4;
1953
- const DEFAULT_POLL_INTERVAL_SEC = 2;
1944
+ const DEFAULT_POLL_INTERVAL_SEC = 1;
1954
1945
  const DEFAULT_MAX_WAIT_SEC = 600;
1955
- function sleep(ms) {
1956
- return new Promise((resolve) => setTimeout(resolve, ms));
1957
- }
1958
1946
  function isRecord$2(value) {
1959
1947
  return !!value && typeof value === "object" && !Array.isArray(value);
1960
1948
  }
@@ -2077,9 +2065,7 @@ async function videoUpscaleNativeAdapter(input) {
2077
2065
  video_url: videoUrl
2078
2066
  })
2079
2067
  }));
2080
- const startedAt = Date.now();
2081
- while (Date.now() - startedAt <= maxWaitSec * 1e3) {
2082
- await sleep(pollIntervalSec * 1e3);
2068
+ for await (const _ of taskPollTicks(maxWaitSec * 1e3, pollIntervalSec * 1e3)) {
2083
2069
  const rawStatus = await requestJson(input, `/v1/video/generations/${encodeURIComponent(taskId)}`, { method: "GET" });
2084
2070
  const status = extractTaskStatus(rawStatus);
2085
2071
  if (status.status === "succeeded") {
@@ -2173,6 +2159,19 @@ function isMetaTaskVariantSpec(value) {
2173
2159
  function isGenerationModelCategory(value) {
2174
2160
  return typeof value === "string" && GENERATION_MODEL_CATEGORIES.includes(value);
2175
2161
  }
2162
+ function isFiniteNonNegative(value) {
2163
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
2164
+ }
2165
+ function isGenerationModelPricing(value) {
2166
+ if (!isRecord$1(value)) return false;
2167
+ if (typeof value.unit !== "string" || !GENERATION_PRICING_UNITS.includes(value.unit)) return false;
2168
+ if (value.note !== void 0 && typeof value.note !== "string") return false;
2169
+ if (value.amount !== void 0) {
2170
+ if (value.min !== void 0 || value.max !== void 0) return false;
2171
+ return isFiniteNonNegative(value.amount);
2172
+ }
2173
+ return isFiniteNonNegative(value.min) && isFiniteNonNegative(value.max) && value.min <= value.max;
2174
+ }
2176
2175
  function isMetaSpec(value) {
2177
2176
  if (!isRecord$1(value)) return false;
2178
2177
  return (value.fields === void 0 || isRecord$1(value.fields) && Object.values(value.fields).every((field) => isMetaFieldSpec(field))) && (value.taskField === void 0 || typeof value.taskField === "string") && (value.taskVariants === void 0 || isRecord$1(value.taskVariants) && Object.values(value.taskVariants).every((variant) => isMetaTaskVariantSpec(variant)));
@@ -2184,7 +2183,7 @@ function isGenerationModelDeclaration(value) {
2184
2183
  const parameters = value.parameters;
2185
2184
  const meta = value.meta;
2186
2185
  const examples = value.examples;
2187
- return value.schema === MODEL_SCHEMA && typeof value.model === "string" && value.model.trim().length > 0 && (value.category === void 0 || isGenerationModelCategory(value.category)) && (value.hidden === void 0 || typeof value.hidden === "boolean") && (value.allowUnknownParameters === void 0 || typeof value.allowUnknownParameters === "boolean") && isRecord$1(adapter) && typeof adapter.type === "string" && isRecord$1(content) && Array.isArray(content.input) && (parameters === void 0 || isRecord$1(parameters) && Object.values(parameters).every(isParameterSpec)) && (meta === void 0 || isMetaSpec(meta)) && (examples === void 0 || Array.isArray(examples));
2186
+ return value.schema === MODEL_SCHEMA && typeof value.model === "string" && value.model.trim().length > 0 && (value.category === void 0 || isGenerationModelCategory(value.category)) && (value.pricing === void 0 || isGenerationModelPricing(value.pricing)) && (value.hidden === void 0 || typeof value.hidden === "boolean") && (value.allowUnknownParameters === void 0 || typeof value.allowUnknownParameters === "boolean") && isRecord$1(adapter) && typeof adapter.type === "string" && isRecord$1(content) && Array.isArray(content.input) && (parameters === void 0 || isRecord$1(parameters) && Object.values(parameters).every(isParameterSpec)) && (meta === void 0 || isMetaSpec(meta)) && (examples === void 0 || Array.isArray(examples));
2188
2187
  }
2189
2188
  function parseGenerationModelDeclaration(rawText, filePath = "model.yaml") {
2190
2189
  const parsed = extname(filePath) === ".json" ? JSON.parse(rawText) : parse(rawText);
@@ -2475,4 +2474,4 @@ async function exportBuiltinModelConfigs(directory) {
2475
2474
 
2476
2475
  //#endregion
2477
2476
  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 };
2478
- //# sourceMappingURL=export-config-D47KgbO7.js.map
2477
+ //# sourceMappingURL=export-config-B3sM1Bxd.js.map