@neta-art/generation 0.1.9 → 0.1.11

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,8 +1,7 @@
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-CcfifHB4.js";
1
+ import { a as cloneJson, c as getBlockMeta, l as slugifyFileName, n as getBuiltinGenerationModel, o as compactArray, r as listBuiltinGenerationModels, s as compactObject, t as builtinGenerationModels } from "./builtins-BvtiQicj.mjs";
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";
5
-
6
5
  //#region src/errors.ts
7
6
  var GenerationError = class extends Error {
8
7
  constructor(message) {
@@ -46,7 +45,6 @@ var GenerationTimeoutError = class extends GenerationProviderError {
46
45
  this.name = "GenerationTimeoutError";
47
46
  }
48
47
  };
49
-
50
48
  //#endregion
51
49
  //#region src/http.ts
52
50
  function headersToRecord(headers) {
@@ -134,7 +132,6 @@ async function fetchWithTimeout(fetchFn, url, init, timeoutMs) {
134
132
  function joinUrl(baseUrl, path) {
135
133
  return `${baseUrl.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
136
134
  }
137
-
138
135
  //#endregion
139
136
  //#region src/validation.ts
140
137
  function specsByType(specs) {
@@ -256,29 +253,11 @@ function mergeTextBlocks(declaration, content) {
256
253
  const separator = textSpec?.merge === "space" ? " " : textSpec?.merge === "concat" ? "" : "\n";
257
254
  return content.filter((block) => block.type === "text").map((block) => block.text).join(separator).trim();
258
255
  }
259
-
260
256
  //#endregion
261
257
  //#region src/adapters/ark-video-generations.ts
262
258
  const REQUEST_TIMEOUT_MS$5 = 186e4;
263
259
  const DEFAULT_POLL_INTERVAL_SEC$2 = 2;
264
260
  const DEFAULT_MAX_WAIT_SEC$2 = 600;
265
- const RESOLUTION_SHORT_EDGE = {
266
- "480p": 480,
267
- "720p": 720,
268
- "1080p": 1080,
269
- "2K": 1440
270
- };
271
- const ASPECT_RATIOS = {
272
- "16:9": [16, 9],
273
- "9:16": [9, 16],
274
- "1:1": [1, 1],
275
- "4:3": [4, 3],
276
- "3:2": [3, 2],
277
- "2:3": [2, 3],
278
- "3:4": [3, 4],
279
- "21:9": [21, 9],
280
- adaptive: null
281
- };
282
261
  function sleep$2(ms) {
283
262
  return new Promise((resolve) => setTimeout(resolve, ms));
284
263
  }
@@ -299,19 +278,6 @@ function getIntegerParameter(parameters, key, fallback) {
299
278
  const value = parameters[key];
300
279
  return typeof value === "number" && Number.isInteger(value) ? value : fallback;
301
280
  }
302
- function resolveSize(resolution, aspectRatio) {
303
- const ratio = ASPECT_RATIOS[aspectRatio];
304
- if (!ratio) return null;
305
- const shortEdge = RESOLUTION_SHORT_EDGE[resolution];
306
- if (!shortEdge) throw new GenerationValidationError(`Unsupported resolution: ${resolution}`);
307
- const [wRatio, hRatio] = ratio;
308
- const width = wRatio >= hRatio ? Math.round(shortEdge * wRatio / hRatio) : shortEdge;
309
- const height = wRatio >= hRatio ? shortEdge : Math.round(shortEdge * hRatio / wRatio);
310
- return {
311
- width: width % 2 === 0 ? width : width + 1,
312
- height: height % 2 === 0 ? height : height + 1
313
- };
314
- }
315
281
  function getMediaRole(block) {
316
282
  const role = getBlockMeta(block)?.role;
317
283
  return typeof role === "string" && role ? role : void 0;
@@ -446,7 +412,7 @@ async function arkVideoGenerationsAdapter(input) {
446
412
  const mode = classifyMedia(inputMedia);
447
413
  const media = await resolveMedia(input, inputMedia);
448
414
  const resolution = asString$2(input.parameters.resolution) ?? "720p";
449
- const aspectRatio = asString$2(input.parameters.aspect_ratio) ?? "16:9";
415
+ const ratio = asString$2(input.request.parameters?.ratio) ?? asString$2(input.request.parameters?.aspect_ratio) ?? asString$2(input.parameters.ratio) ?? "16:9";
450
416
  const duration = getIntegerParameter(input.parameters, "duration", 5);
451
417
  const fps = getIntegerParameter(input.parameters, "fps", 30);
452
418
  const pollIntervalSec = getIntegerParameter(input.parameters, "poll_interval", DEFAULT_POLL_INTERVAL_SEC$2);
@@ -463,22 +429,16 @@ async function arkVideoGenerationsAdapter(input) {
463
429
  const metadata = {
464
430
  duration,
465
431
  fps,
466
- generate_audio: generateAudio
432
+ generate_audio: generateAudio,
433
+ resolution,
434
+ ratio
467
435
  };
468
436
  if (seed !== void 0) metadata.seed = seed;
469
437
  if (returnLastFrame) metadata.return_last_frame = true;
470
438
  if (cameraFixed) metadata.camera_fixed = true;
471
439
  if (watermark) metadata.watermark = true;
472
- if (mode === "frame" || mode === "reference") {
473
- metadata.content = buildMetadataContent(media, mode);
474
- metadata.resolution = resolution;
475
- metadata.ratio = aspectRatio;
476
- } else {
477
- const size = resolveSize(resolution, aspectRatio);
478
- if (size) {
479
- payload.width = size.width;
480
- payload.height = size.height;
481
- }
440
+ if (mode === "frame" || mode === "reference") metadata.content = buildMetadataContent(media, mode);
441
+ else {
482
442
  const firstImage = media.find((item) => item.kind === "image");
483
443
  if (firstImage) payload.image = firstImage.url;
484
444
  }
@@ -534,7 +494,6 @@ async function arkVideoGenerationsAdapter(input) {
534
494
  }
535
495
  throw new GenerationTimeoutError("Timed out waiting for video generation", { taskId });
536
496
  }
537
-
538
497
  //#endregion
539
498
  //#region src/adapters/gemini-generate-content.ts
540
499
  const REQUEST_TIMEOUT_MS$4 = 3e5;
@@ -639,7 +598,7 @@ async function geminiGenerateContentAdapter(input) {
639
598
  const image = {};
640
599
  if (typeof aspectRatio === "string") image.aspectRatio = aspectRatio;
641
600
  if (typeof imageSize === "string") image.imageSize = imageSize;
642
- generationConfig.responseFormat = { image };
601
+ generationConfig.imageConfig = image;
643
602
  }
644
603
  const payload = {
645
604
  contents: [{ parts: [{ text: prompt }, ...imageParts] }],
@@ -666,7 +625,6 @@ async function geminiGenerateContentAdapter(input) {
666
625
  if (output.length === 0) throw new GenerationProviderError("Gemini generation returned no output", { details: collectGeminiNoOutputDetails(raw) });
667
626
  return output;
668
627
  }
669
-
670
628
  //#endregion
671
629
  //#region src/adapters/kling-video-generations.ts
672
630
  const REQUEST_TIMEOUT_MS$3 = 186e4;
@@ -707,7 +665,7 @@ function asInteger$1(value, fallback) {
707
665
  function asNumber(value) {
708
666
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
709
667
  }
710
- function isRecord$2(value) {
668
+ function isRecord$3(value) {
711
669
  return !!value && typeof value === "object" && !Array.isArray(value);
712
670
  }
713
671
  function providerMeta(input) {
@@ -849,7 +807,7 @@ async function requestJson$1(input, path, init) {
849
807
  });
850
808
  }
851
809
  if (!response.ok) {
852
- const details = isRecord$2(parsed) ? { details: parsed } : {};
810
+ const details = isRecord$3(parsed) ? { details: parsed } : {};
853
811
  throw new GenerationProviderError("Kling video provider request failed", {
854
812
  status: response.status,
855
813
  body,
@@ -905,7 +863,6 @@ async function klingVideoGenerationsAdapter(input) {
905
863
  }
906
864
  throw new GenerationTimeoutError("Timed out waiting for Kling video generation", { taskId });
907
865
  }
908
-
909
866
  //#endregion
910
867
  //#region src/adapters/openai-image-edits.ts
911
868
  const REQUEST_TIMEOUT_MS$2 = 3e5;
@@ -975,7 +932,6 @@ async function openAiImageEditsAdapter(input) {
975
932
  if (output.length === 0) throw new GenerationProviderError("Image edit returned no output", { details: collectOpenAiImageEditsNoOutputDetails(raw) });
976
933
  return output;
977
934
  }
978
-
979
935
  //#endregion
980
936
  //#region src/adapters/openai-images.ts
981
937
  const REQUEST_TIMEOUT_MS$1 = 3e5;
@@ -1052,7 +1008,6 @@ async function openAiImagesAdapter(input) {
1052
1008
  if (output.length === 0) throw new GenerationProviderError("Image generation returned no output", { details: collectOpenAiImagesNoOutputDetails(raw) });
1053
1009
  return output;
1054
1010
  }
1055
-
1056
1011
  //#endregion
1057
1012
  //#region src/adapters/suno-tasks.ts
1058
1013
  const REQUEST_TIMEOUT_MS = 6e4;
@@ -1087,12 +1042,12 @@ const OPERATION_PATHS = {
1087
1042
  poll: true
1088
1043
  }
1089
1044
  };
1090
- const FINAL_SUCCESS_STATUSES = new Set([
1045
+ const FINAL_SUCCESS_STATUSES = /* @__PURE__ */ new Set([
1091
1046
  "success",
1092
1047
  "succeeded",
1093
1048
  "completed"
1094
1049
  ]);
1095
- const FINAL_FAILURE_STATUSES = new Set([
1050
+ const FINAL_FAILURE_STATUSES = /* @__PURE__ */ new Set([
1096
1051
  "failure",
1097
1052
  "failed",
1098
1053
  "error",
@@ -1103,7 +1058,7 @@ const FINAL_FAILURE_STATUSES = new Set([
1103
1058
  function sleep(ms) {
1104
1059
  return new Promise((resolve) => setTimeout(resolve, ms));
1105
1060
  }
1106
- function isRecord$1(value) {
1061
+ function isRecord$2(value) {
1107
1062
  return !!value && typeof value === "object" && !Array.isArray(value);
1108
1063
  }
1109
1064
  function asString(value) {
@@ -1113,7 +1068,7 @@ function asInteger(value, fallback) {
1113
1068
  return typeof value === "number" && Number.isInteger(value) ? value : fallback;
1114
1069
  }
1115
1070
  function asRecord(value) {
1116
- return isRecord$1(value) ? value : {};
1071
+ return isRecord$2(value) ? value : {};
1117
1072
  }
1118
1073
  function successCode(value) {
1119
1074
  const code = String(value ?? "").trim().toLowerCase();
@@ -1129,7 +1084,7 @@ function requireSuccess(response, fallbackMessage) {
1129
1084
  }
1130
1085
  function extractTaskId(value) {
1131
1086
  if (typeof value === "string" && value.trim()) return value.trim();
1132
- if (!isRecord$1(value)) return void 0;
1087
+ if (!isRecord$2(value)) return void 0;
1133
1088
  for (const key of [
1134
1089
  "task_id",
1135
1090
  "id",
@@ -1147,7 +1102,7 @@ function normalizeStatus(value) {
1147
1102
  }
1148
1103
  function normalizeTask(operation, data) {
1149
1104
  if (Array.isArray(data)) return data.length > 0 ? normalizeTask(operation, data[0]) : null;
1150
- if (!isRecord$1(data)) return null;
1105
+ if (!isRecord$2(data)) return null;
1151
1106
  if ("status" in data || "taskStatus" in data || "task_status" in data || "task_id" in data || "taskBatchId" in data) {
1152
1107
  const hasProviderEnvelope = "taskStatus" in data || "task_status" in data || "taskBatchId" in data || "task_batch_id" in data;
1153
1108
  return {
@@ -1218,7 +1173,7 @@ function applyFixedPayload(input, payload, fixed) {
1218
1173
  }
1219
1174
  }
1220
1175
  function setMetadataParam(payload, key, value) {
1221
- const metadataParams = isRecord$1(payload.metadata_params) ? payload.metadata_params : {};
1176
+ const metadataParams = isRecord$2(payload.metadata_params) ? payload.metadata_params : {};
1222
1177
  if (metadataParams[key] === void 0) metadataParams[key] = value;
1223
1178
  payload.metadata_params = metadataParams;
1224
1179
  }
@@ -1288,8 +1243,8 @@ function appendSunoContent(output, value, meta = {}) {
1288
1243
  for (const item of value) appendSunoContent(output, item, meta);
1289
1244
  return;
1290
1245
  }
1291
- if (!isRecord$1(value)) return;
1292
- if (isRecord$1(value.clips)) for (const clip of Object.values(value.clips)) appendSunoContent(output, clip, meta);
1246
+ if (!isRecord$2(value)) return;
1247
+ if (isRecord$2(value.clips)) for (const clip of Object.values(value.clips)) appendSunoContent(output, clip, meta);
1293
1248
  if (Array.isArray(value.items)) for (const item of value.items) appendSunoContent(output, item, meta);
1294
1249
  const itemMeta = compactObject({
1295
1250
  ...meta,
@@ -1299,9 +1254,9 @@ function appendSunoContent(output, value, meta = {}) {
1299
1254
  title: value.title,
1300
1255
  status: value.status ?? meta.status,
1301
1256
  model: value.model_name ?? value.modelName,
1302
- duration: value.duration ?? (isRecord$1(value.metadata) ? value.metadata.duration : void 0),
1303
- tags: value.tags ?? (isRecord$1(value.metadata) ? value.metadata.tags : void 0),
1304
- prompt: value.prompt ?? (isRecord$1(value.metadata) ? value.metadata.prompt : void 0),
1257
+ duration: value.duration ?? (isRecord$2(value.metadata) ? value.metadata.duration : void 0),
1258
+ tags: value.tags ?? (isRecord$2(value.metadata) ? value.metadata.tags : void 0),
1259
+ prompt: value.prompt ?? (isRecord$2(value.metadata) ? value.metadata.prompt : void 0),
1305
1260
  progress: value.progress ?? meta.progress,
1306
1261
  progress_message: value.progressMsg ?? value.progress_msg,
1307
1262
  task_batch_id: value.taskBatchId ?? value.task_batch_id,
@@ -1322,7 +1277,7 @@ function appendSunoContent(output, value, meta = {}) {
1322
1277
  text,
1323
1278
  meta: itemMeta
1324
1279
  });
1325
- if (isRecord$1(value.data)) appendSunoContent(output, value.data, itemMeta);
1280
+ if (isRecord$2(value.data)) appendSunoContent(output, value.data, itemMeta);
1326
1281
  }
1327
1282
  function buildImmediateResult(operation, data, raw) {
1328
1283
  const output = [];
@@ -1411,7 +1366,6 @@ async function sunoTasksAdapter(input) {
1411
1366
  if (!taskId) return buildImmediateResult(operation, data, raw);
1412
1367
  return pollSunoTask(input, operation, taskId, asInteger(input.parameters.poll_interval, DEFAULT_POLL_INTERVAL_SEC), asInteger(input.parameters.max_wait, DEFAULT_MAX_WAIT_SEC));
1413
1368
  }
1414
-
1415
1369
  //#endregion
1416
1370
  //#region src/adapters/index.ts
1417
1371
  const builtinGenerationAdapters = {
@@ -1427,19 +1381,18 @@ function getGenerationAdapter(type, adapters = {}) {
1427
1381
  if (!adapter) throw new GenerationUnsupportedAdapterError(type);
1428
1382
  return adapter;
1429
1383
  }
1430
-
1431
1384
  //#endregion
1432
1385
  //#region src/config.ts
1433
- const DECLARATION_EXTENSIONS = new Set([
1386
+ const DECLARATION_EXTENSIONS = /* @__PURE__ */ new Set([
1434
1387
  ".yaml",
1435
1388
  ".yml",
1436
1389
  ".json"
1437
1390
  ]);
1438
- function isRecord(value) {
1391
+ function isRecord$1(value) {
1439
1392
  return !!value && typeof value === "object" && !Array.isArray(value);
1440
1393
  }
1441
1394
  function isParameterSpec(value) {
1442
- if (!isRecord(value)) return false;
1395
+ if (!isRecord$1(value)) return false;
1443
1396
  return [
1444
1397
  "string",
1445
1398
  "number",
@@ -1448,25 +1401,25 @@ function isParameterSpec(value) {
1448
1401
  ].includes(String(value.type));
1449
1402
  }
1450
1403
  function isMetaFieldSpec(value) {
1451
- if (!isRecord(value)) return false;
1404
+ if (!isRecord$1(value)) return false;
1452
1405
  return isParameterSpec(value) || String(value.type) === "object";
1453
1406
  }
1454
1407
  function isMetaTaskVariantSpec(value) {
1455
- if (!isRecord(value)) return false;
1408
+ if (!isRecord$1(value)) return false;
1456
1409
  return (value.description === void 0 || typeof value.description === "string") && (value.required === void 0 || Array.isArray(value.required) && value.required.every((item) => typeof item === "string")) && (value.requiredContent === void 0 || Array.isArray(value.requiredContent) && value.requiredContent.every((item) => typeof item === "string")) && (value.sendTask === void 0 || typeof value.sendTask === "boolean");
1457
1410
  }
1458
1411
  function isMetaSpec(value) {
1459
- if (!isRecord(value)) return false;
1460
- return (value.fields === void 0 || isRecord(value.fields) && Object.values(value.fields).every((field) => isMetaFieldSpec(field))) && (value.taskField === void 0 || typeof value.taskField === "string") && (value.taskVariants === void 0 || isRecord(value.taskVariants) && Object.values(value.taskVariants).every((variant) => isMetaTaskVariantSpec(variant)));
1412
+ if (!isRecord$1(value)) return false;
1413
+ 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)));
1461
1414
  }
1462
1415
  function isGenerationModelDeclaration(value) {
1463
- if (!isRecord(value)) return false;
1416
+ if (!isRecord$1(value)) return false;
1464
1417
  const adapter = value.adapter;
1465
1418
  const content = value.content;
1466
1419
  const parameters = value.parameters;
1467
1420
  const meta = value.meta;
1468
1421
  const examples = value.examples;
1469
- return value.schema === MODEL_SCHEMA && typeof value.model === "string" && value.model.trim().length > 0 && (value.allowUnknownParameters === void 0 || typeof value.allowUnknownParameters === "boolean") && isRecord(adapter) && typeof adapter.type === "string" && isRecord(content) && Array.isArray(content.input) && (parameters === void 0 || isRecord(parameters) && Object.values(parameters).every(isParameterSpec)) && (meta === void 0 || isMetaSpec(meta)) && (examples === void 0 || Array.isArray(examples));
1422
+ return value.schema === "neta.generation.model.v1" && typeof value.model === "string" && value.model.trim().length > 0 && (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));
1470
1423
  }
1471
1424
  function parseGenerationModelDeclaration(rawText, filePath = "model.yaml") {
1472
1425
  const parsed = extname(filePath) === ".json" ? JSON.parse(rawText) : parse(rawText);
@@ -1500,7 +1453,27 @@ async function writeGenerationModelDeclarations(declarations, directory, options
1500
1453
  const ext = options.format === "json" ? "json" : "yaml";
1501
1454
  await Promise.all(declarations.map((declaration) => writeGenerationModelDeclaration(declaration, join(directory, `${slugifyFileName(declaration.model)}.${ext}`), options)));
1502
1455
  }
1503
-
1456
+ //#endregion
1457
+ //#region src/response-fields.ts
1458
+ function numberValue(value) {
1459
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
1460
+ }
1461
+ function stringValue(value) {
1462
+ return typeof value === "string" && value ? value : void 0;
1463
+ }
1464
+ function isRecord(value) {
1465
+ return !!value && typeof value === "object" && !Array.isArray(value);
1466
+ }
1467
+ function extractGenerationResultFields(raw) {
1468
+ if (!isRecord(raw)) return void 0;
1469
+ const usage = isRecord(raw.usage) ? raw.usage : void 0;
1470
+ const fields = {};
1471
+ const requestId = stringValue(raw.request_id);
1472
+ const cost = usage ? numberValue(usage.cost) : void 0;
1473
+ if (requestId !== void 0) fields.requestId = requestId;
1474
+ if (cost !== void 0) fields.cost = cost;
1475
+ return Object.keys(fields).length > 0 ? fields : void 0;
1476
+ }
1504
1477
  //#endregion
1505
1478
  //#region src/source.ts
1506
1479
  const defaultGenerationSourceResolver = (source) => {
@@ -1509,14 +1482,13 @@ const defaultGenerationSourceResolver = (source) => {
1509
1482
  case "base64": return `data:${source.mediaType};base64,${source.data}`;
1510
1483
  }
1511
1484
  };
1512
-
1513
1485
  //#endregion
1514
1486
  //#region src/client.ts
1515
1487
  const DEFAULT_BASE_URL = "https://router.neta.art";
1516
1488
  const REDACTED = "[REDACTED]";
1517
1489
  const SECRET_DEBUG_KEY_PATTERN = /^(authorization|api[-_]?key|token|thoughtSignature)$/i;
1518
1490
  const BASE64_DEBUG_KEY_PATTERN = /^(b64_json|data)$/i;
1519
- const MEDIA_PAYLOAD_KEYS = new Set([
1491
+ const MEDIA_PAYLOAD_KEYS = /* @__PURE__ */ new Set([
1520
1492
  "audio",
1521
1493
  "audio_url",
1522
1494
  "image",
@@ -1582,6 +1554,17 @@ function resolveModels(options) {
1582
1554
  for (const model of models) byModel.set(model.model, cloneJson(model));
1583
1555
  return [...byModel.values()].sort((a, b) => a.model.localeCompare(b.model));
1584
1556
  }
1557
+ function createResultFieldCaptureFetch(fetchFn, onFields) {
1558
+ return (async (input, init) => {
1559
+ const response = await fetchFn(input, init);
1560
+ const contentType = response.headers.get("content-type") ?? "";
1561
+ if (contentType.includes("application/json") || contentType.includes("+json")) try {
1562
+ const fields = extractGenerationResultFields(await response.clone().json());
1563
+ if (fields) onFields(fields);
1564
+ } catch {}
1565
+ return response;
1566
+ });
1567
+ }
1585
1568
  function createGenerationClient(options = {}) {
1586
1569
  const models = resolveModels(options);
1587
1570
  const byModel = new Map(models.map((declaration) => [declaration.model, declaration]));
@@ -1594,35 +1577,53 @@ function createGenerationClient(options = {}) {
1594
1577
  if (!declaration) throw new GenerationConfigError(`Generation model is unavailable: ${model}`);
1595
1578
  return declaration;
1596
1579
  }
1580
+ function validateRequest(request) {
1581
+ const declaration = requireModel(request.model);
1582
+ validateGenerationContent(declaration, request.content);
1583
+ const parameters = resolveGenerationParameters(declaration, request.parameters);
1584
+ const meta = resolveGenerationMeta(declaration, mergeGenerationMeta({
1585
+ ...request.metadata ?? {},
1586
+ ...request.meta ?? {}
1587
+ }, request.content), request.content);
1588
+ return {
1589
+ declaration: cloneJson(declaration),
1590
+ request: cloneJson(request),
1591
+ parameters,
1592
+ meta
1593
+ };
1594
+ }
1595
+ async function runAdapter(request, fetch) {
1596
+ const resolved = validateRequest(request);
1597
+ const apiKey = request.apiKey ?? options.apiKey;
1598
+ if (!apiKey) throw new GenerationConfigError("apiKey is required");
1599
+ return getGenerationAdapter(resolved.declaration.adapter.type, options.adapters)({
1600
+ ...resolved,
1601
+ context: {
1602
+ apiKey,
1603
+ baseUrl: request.baseUrl ?? options.baseUrl ?? DEFAULT_BASE_URL,
1604
+ fetch,
1605
+ resolveSource: options.sourceResolver ?? defaultGenerationSourceResolver
1606
+ }
1607
+ });
1608
+ }
1597
1609
  return {
1598
1610
  validate(request) {
1599
- const declaration = requireModel(request.model);
1600
- validateGenerationContent(declaration, request.content);
1601
- const parameters = resolveGenerationParameters(declaration, request.parameters);
1602
- const meta = resolveGenerationMeta(declaration, mergeGenerationMeta({
1603
- ...request.metadata ?? {},
1604
- ...request.meta ?? {}
1605
- }, request.content), request.content);
1606
- return {
1607
- declaration: cloneJson(declaration),
1608
- request: cloneJson(request),
1609
- parameters,
1610
- meta
1611
- };
1611
+ return validateRequest(request);
1612
1612
  },
1613
1613
  async generate(request) {
1614
- const resolved = this.validate(request);
1615
- const apiKey = request.apiKey ?? options.apiKey;
1616
- if (!apiKey) throw new GenerationConfigError("apiKey is required");
1617
- return getGenerationAdapter(resolved.declaration.adapter.type, options.adapters)({
1618
- ...resolved,
1619
- context: {
1620
- apiKey,
1621
- baseUrl: request.baseUrl ?? options.baseUrl ?? DEFAULT_BASE_URL,
1622
- fetch: adapterFetch,
1623
- resolveSource: options.sourceResolver ?? defaultGenerationSourceResolver
1624
- }
1625
- });
1614
+ return runAdapter(request, adapterFetch);
1615
+ },
1616
+ async generateResult(request) {
1617
+ let capturedFields;
1618
+ return {
1619
+ content: await runAdapter(request, createResultFieldCaptureFetch(adapterFetch, (fields) => {
1620
+ capturedFields = {
1621
+ ...capturedFields,
1622
+ ...fields
1623
+ };
1624
+ })),
1625
+ ...capturedFields ?? {}
1626
+ };
1626
1627
  },
1627
1628
  listModels() {
1628
1629
  return cloneJson(models);
@@ -1661,7 +1662,6 @@ async function createGenerationClientFromDirectory(directory, options = {}) {
1661
1662
  async function createGenerationClientFromFile(filePath, options = {}) {
1662
1663
  return createGenerationClientFromFiles([filePath], options);
1663
1664
  }
1664
-
1665
1665
  //#endregion
1666
1666
  //#region src/export-config.ts
1667
1667
  function stringifyBuiltinModelConfig(model, options = {}) {
@@ -1677,7 +1677,7 @@ async function exportBuiltinModelConfig(model, filePath) {
1677
1677
  async function exportBuiltinModelConfigs(directory) {
1678
1678
  await writeGenerationModelDeclarations(listBuiltinGenerationModels(), directory);
1679
1679
  }
1680
-
1681
1680
  //#endregion
1682
1681
  export { validateGenerationContent as A, klingVideoGenerationsAdapter as C, mergeTextBlocks as D, mergeGenerationMeta as E, GenerationUnsupportedAdapterError as F, GenerationValidationError as I, GenerationError as M, GenerationProviderError as N, resolveGenerationMeta as O, GenerationTimeoutError as P, openAiImageEditsAdapter as S, arkVideoGenerationsAdapter 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, GenerationConfigError as j, resolveGenerationParameters 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, geminiGenerateContentAdapter as w, openAiImagesAdapter as x, getGenerationAdapter as y };
1683
- //# sourceMappingURL=export-config--lWA-0gu.js.map
1682
+
1683
+ //# sourceMappingURL=export-config-C_kTxv5h.mjs.map