@shop-os/modelkit 0.23.1 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -257,6 +257,12 @@ interface VideoRequest {
257
257
  startSeconds: number;
258
258
  resumeSeconds: number;
259
259
  };
260
+ /** Rows with `constraints.draft`: render the final from this draft task (a draft call's
261
+ * `jobId`). The provider reuses
262
+ * the draft's prompt, inputs, duration, ratio, seed and audio, so the adapter sends none of
263
+ * them; `resolution` must be one of `finalResolutions` (default: the first), and
264
+ * `durationSeconds` is only the usage fallback until the task reports its length. */
265
+ draftTaskId?: string;
260
266
  }
261
267
  /**
262
268
  * What a caller passes to generateVideo. `duration` is the AI SDK spelling of
@@ -848,6 +854,14 @@ interface ModelConstraints {
848
854
  * `new`: it returns only the added footage and the caller joins it (Seedance). */
849
855
  returns?: "new" | "joined";
850
856
  };
857
+ /** A draft row (Seedance 2.5 Draft): every call renders a preview at `resolution`, and a call
858
+ * with `VideoRequest.draftTaskId` renders the final from one at one of `finalResolutions`, for
859
+ * `ttlDays` after the draft task was created. Both steps run and bill as this row. */
860
+ draft?: {
861
+ resolution: VideoResolution;
862
+ finalResolutions: VideoResolution[];
863
+ ttlDays: number;
864
+ };
851
865
  /** What a `video-tool` row accepts. Read it through `videoToolConstraints(row)`. */
852
866
  tool?: VideoToolConstraints;
853
867
  /** Required on `model3d` rows. */
@@ -1540,6 +1554,27 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
1540
1554
  joined: "joined";
1541
1555
  }>>;
1542
1556
  }, z.core.$loose>>;
1557
+ draft: z.ZodOptional<z.ZodObject<{
1558
+ resolution: z.ZodEnum<{
1559
+ "360p": "360p";
1560
+ "480p": "480p";
1561
+ "720p": "720p";
1562
+ "768p": "768p";
1563
+ "1080p": "1080p";
1564
+ "2k": "2k";
1565
+ "4k": "4k";
1566
+ }>;
1567
+ finalResolutions: z.ZodArray<z.ZodEnum<{
1568
+ "360p": "360p";
1569
+ "480p": "480p";
1570
+ "720p": "720p";
1571
+ "768p": "768p";
1572
+ "1080p": "1080p";
1573
+ "2k": "2k";
1574
+ "4k": "4k";
1575
+ }>>;
1576
+ ttlDays: z.ZodNumber;
1577
+ }, z.core.$loose>>;
1543
1578
  tool: z.ZodOptional<z.ZodObject<{
1544
1579
  kind: z.ZodEnum<{
1545
1580
  upscale: "upscale";
package/dist/index.d.ts CHANGED
@@ -257,6 +257,12 @@ interface VideoRequest {
257
257
  startSeconds: number;
258
258
  resumeSeconds: number;
259
259
  };
260
+ /** Rows with `constraints.draft`: render the final from this draft task (a draft call's
261
+ * `jobId`). The provider reuses
262
+ * the draft's prompt, inputs, duration, ratio, seed and audio, so the adapter sends none of
263
+ * them; `resolution` must be one of `finalResolutions` (default: the first), and
264
+ * `durationSeconds` is only the usage fallback until the task reports its length. */
265
+ draftTaskId?: string;
260
266
  }
261
267
  /**
262
268
  * What a caller passes to generateVideo. `duration` is the AI SDK spelling of
@@ -848,6 +854,14 @@ interface ModelConstraints {
848
854
  * `new`: it returns only the added footage and the caller joins it (Seedance). */
849
855
  returns?: "new" | "joined";
850
856
  };
857
+ /** A draft row (Seedance 2.5 Draft): every call renders a preview at `resolution`, and a call
858
+ * with `VideoRequest.draftTaskId` renders the final from one at one of `finalResolutions`, for
859
+ * `ttlDays` after the draft task was created. Both steps run and bill as this row. */
860
+ draft?: {
861
+ resolution: VideoResolution;
862
+ finalResolutions: VideoResolution[];
863
+ ttlDays: number;
864
+ };
851
865
  /** What a `video-tool` row accepts. Read it through `videoToolConstraints(row)`. */
852
866
  tool?: VideoToolConstraints;
853
867
  /** Required on `model3d` rows. */
@@ -1540,6 +1554,27 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
1540
1554
  joined: "joined";
1541
1555
  }>>;
1542
1556
  }, z.core.$loose>>;
1557
+ draft: z.ZodOptional<z.ZodObject<{
1558
+ resolution: z.ZodEnum<{
1559
+ "360p": "360p";
1560
+ "480p": "480p";
1561
+ "720p": "720p";
1562
+ "768p": "768p";
1563
+ "1080p": "1080p";
1564
+ "2k": "2k";
1565
+ "4k": "4k";
1566
+ }>;
1567
+ finalResolutions: z.ZodArray<z.ZodEnum<{
1568
+ "360p": "360p";
1569
+ "480p": "480p";
1570
+ "720p": "720p";
1571
+ "768p": "768p";
1572
+ "1080p": "1080p";
1573
+ "2k": "2k";
1574
+ "4k": "4k";
1575
+ }>>;
1576
+ ttlDays: z.ZodNumber;
1577
+ }, z.core.$loose>>;
1543
1578
  tool: z.ZodOptional<z.ZodObject<{
1544
1579
  kind: z.ZodEnum<{
1545
1580
  upscale: "upscale";
package/dist/index.js CHANGED
@@ -363,6 +363,34 @@ var FAL_IMAGE_MODELS = [
363
363
  logo: `${LOBE}/kling-color.png`
364
364
  }
365
365
  },
366
+ {
367
+ // kling/v4/text-to-image; references switch to kling/v4/image-to-image (up to 10,
368
+ // "@Image1".."@Image10"). Per output image: $0.063 at 2K, $0.094 at 4K (Kling price page,
369
+ // 2026-11-17); each reference adds $0.003, which we absorb. Native 8K is ENG-4137.
370
+ id: "kling-image-4.0",
371
+ aliases: [],
372
+ label: "Kling Image 4.0",
373
+ type: "image",
374
+ adapter: "fal",
375
+ providerModelId: "kling/v4/text-to-image",
376
+ lifecycle: "active",
377
+ exposure: EXPOSURE,
378
+ constraints: {
379
+ aspectRatios: [...KLING_RATIOS, "adaptive"],
380
+ sizes: ["2K", "4K"],
381
+ references: { images: 10 },
382
+ supports: ["count"],
383
+ prompt: { referenceSyntax: "numbered", maxChars: 21e3 }
384
+ },
385
+ defaults: { size: "2K", aspectRatio: "adaptive", count: 1 },
386
+ usage: { ...IMAGE_USAGE },
387
+ pricingKind: "image_size",
388
+ display: {
389
+ provider: "kuaishou",
390
+ description: "Kling Image 4.0 for photoreal text-to-image, long in-image text and multi-reference editing; takes a prompt and up to 10 reference images and outputs 2K or 4K.",
391
+ logo: `${LOBE}/kling-color.png`
392
+ }
393
+ },
366
394
  {
367
395
  // fal-ai/kling-image/v3/text-to-image; a reference switches to .../v3/image-to-image, which
368
396
  // takes exactly one image_url and no "auto" ratio. $0.028 per image.
@@ -6353,6 +6381,54 @@ var VIDEO_MODELS = [
6353
6381
  },
6354
6382
  capabilities: { acceptsSourceVideo: true, videoEdit: true, ...FRAMES_EXCLUDE_REFERENCES }
6355
6383
  },
6384
+ {
6385
+ // The same BytePlus model in draft mode. Probed 2026-11-17: a draft must be 480p; its
6386
+ // final is a second task on this row (draftTaskId), and 720p or no resolution is refused
6387
+ // there. A 4k final also rendered, but the docs list 1080p only. No alias for the provider
6388
+ // id: that alias resolves usage to seedance-2.5. Edit and extend stay on seedance-2.5.
6389
+ id: "seedance-2.5-draft",
6390
+ aliases: ["seedance-2-5-draft"],
6391
+ label: "Seedance 2.5 Draft",
6392
+ type: "video",
6393
+ adapter: "ark",
6394
+ providerModelId: "dreamina-seedance-2-5-260628",
6395
+ lifecycle: "active",
6396
+ exposure: [],
6397
+ constraints: {
6398
+ aspectRatios: [...SEEDANCE_RATIOS],
6399
+ resolutions: ["480p"],
6400
+ durations: { min: 4, max: 30 },
6401
+ references: {
6402
+ images: 30,
6403
+ videos: 10,
6404
+ audios: 10,
6405
+ videoSeconds: { min: 2, max: 30, total: 30 },
6406
+ ...SEEDANCE_REFERENCE_MEDIA,
6407
+ audioSeconds: { min: 2, max: 30, total: 30 },
6408
+ audioFormats: ["wav", "mp3"],
6409
+ audioMaxBytes: 15 * 1024 * 1024
6410
+ },
6411
+ ratioIgnoredWith: ["firstFrame"],
6412
+ supports: ["generateAudio", "lastFrame", "watermark"],
6413
+ draft: { resolution: "480p", finalResolutions: ["1080p"], ttlDays: 14 },
6414
+ prompt: SEEDANCE_PROMPT,
6415
+ audio: "optional"
6416
+ },
6417
+ defaults: {
6418
+ durationSeconds: 5,
6419
+ resolution: "480p",
6420
+ aspectRatio: "16:9",
6421
+ generateAudio: true
6422
+ },
6423
+ usage: { ...VIDEO_USAGE3 },
6424
+ pricingKind: "video_per_second",
6425
+ display: {
6426
+ provider: "bytedance",
6427
+ logo: BYTEDANCE_LOGO2,
6428
+ description: "A quick 480p Seedance 2.5 preview. Render the 1080p final from it within 14 days; the final keeps the draft's scene and motion."
6429
+ },
6430
+ capabilities: { acceptsSourceVideo: false, videoEdit: false, ...FRAMES_EXCLUDE_REFERENCES }
6431
+ },
6356
6432
  {
6357
6433
  // Limits probed on the live API 2026-11-16 (1080p is refused). Extend probe: a 4 s
6358
6434
  // extend returned 4 s of new footage only and billed input + output tokens, as on 2.5.
@@ -8330,6 +8406,13 @@ var ModelConstraintsSchema = z3.looseObject({
8330
8406
  maxTotalSeconds: z3.number(),
8331
8407
  returns: z3.enum(["new", "joined"]).optional()
8332
8408
  }).optional(),
8409
+ // Loose so a kit before 0.24.0 keeps a row that carries it (an unknown `supports` value
8410
+ // would drop the row there).
8411
+ draft: z3.looseObject({
8412
+ resolution: VideoResolutionSchema,
8413
+ finalResolutions: z3.array(VideoResolutionSchema).min(1),
8414
+ ttlDays: z3.number().positive()
8415
+ }).optional(),
8333
8416
  tool: VideoToolConstraintsSchema.optional(),
8334
8417
  model3d: Model3dConstraintsSchema.optional(),
8335
8418
  // Loose on purpose: the read path keeps a row whose value is invalid (the accessors in
@@ -9043,6 +9126,20 @@ var FAL_IMAGE_SPECS = /* @__PURE__ */ new Map([
9043
9126
  aspectRatios: KLING_RATIOS3
9044
9127
  }
9045
9128
  ],
9129
+ [
9130
+ // No output_format or seed field. Kling caps non-English prompts at 21,000 characters
9131
+ // (API update 2026-11-17), under the schema's 50,000.
9132
+ "kling/v4/text-to-image",
9133
+ {
9134
+ label: "Kling Image 4.0",
9135
+ maxReferences: 10,
9136
+ maxCount: 9,
9137
+ outputFormats: [],
9138
+ promptMax: 21e3,
9139
+ promptRequired: true,
9140
+ aspectRatios: [...KLING_RATIOS3, "adaptive"]
9141
+ }
9142
+ ],
9046
9143
  [
9047
9144
  "recraft/v4.1/flash/text-to-image",
9048
9145
  {
@@ -10595,8 +10692,12 @@ var SeedanceErrorSchema = z10.object({
10595
10692
  code: z10.string().optional(),
10596
10693
  message: z10.string().optional()
10597
10694
  });
10598
- function seedanceResolution(req) {
10599
- return req.resolution ?? "720p";
10695
+ function seedanceResolution(req, ctx) {
10696
+ const draft = ctx.model.constraints.draft;
10697
+ if (!draft) return req.resolution ?? "720p";
10698
+ if (req.draftTaskId !== void 0)
10699
+ return req.resolution ?? draft.finalResolutions[0] ?? "1080p";
10700
+ return draft.resolution;
10600
10701
  }
10601
10702
  function seedanceUsage(ctx, req, duration) {
10602
10703
  return {
@@ -10606,7 +10707,7 @@ function seedanceUsage(ctx, req, duration) {
10606
10707
  unit: "seconds",
10607
10708
  quantity: duration,
10608
10709
  durationSeconds: duration,
10609
- resolution: seedanceResolution(req)
10710
+ resolution: seedanceResolution(req, ctx)
10610
10711
  };
10611
10712
  }
10612
10713
  function seedanceInitialDuration(req) {
@@ -10704,8 +10805,67 @@ function seedanceJob(ctx, key, jobId, usage5) {
10704
10805
  }
10705
10806
  };
10706
10807
  }
10707
- async function generateSeedanceVideo(req, ctx) {
10808
+ function draftRefusal(ctx, message) {
10809
+ return new ModelKitError({
10810
+ code: "unsupported_option",
10811
+ message: `${ctx.model.id} ${message}`,
10812
+ provider: "ark",
10813
+ model: ctx.model.id,
10814
+ retryable: false
10815
+ });
10816
+ }
10817
+ function assertDraftRequest(req, ctx) {
10818
+ const draft = ctx.model.constraints.draft;
10819
+ if (!draft) {
10820
+ if (req.draftTaskId !== void 0) throw draftRefusal(ctx, "has no draft mode");
10821
+ return;
10822
+ }
10823
+ if (req.draftTaskId === void 0 && req.resolution !== void 0 && req.resolution !== draft.resolution)
10824
+ throw draftRefusal(ctx, `renders a draft at ${draft.resolution} only`);
10825
+ if (req.draftTaskId === void 0 && req.taskType !== void 0)
10826
+ throw draftRefusal(ctx, "renders drafts without a task type");
10827
+ if (req.draftTaskId !== void 0 && req.resolution !== void 0 && !draft.finalResolutions.includes(req.resolution))
10828
+ throw draftRefusal(
10829
+ ctx,
10830
+ `renders a final from a draft at ${draft.finalResolutions.join(", ")} only`
10831
+ );
10832
+ }
10833
+ async function submitSeedanceTask(ctx, key, body) {
10708
10834
  const modelId = ctx.model.id;
10835
+ const submit = await withRetry(
10836
+ async () => {
10837
+ const res = await arkFetch(ctx, `${arkBaseUrl(ctx)}${SUBMIT_PATH2}`, {
10838
+ method: "POST",
10839
+ headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
10840
+ body: JSON.stringify(body)
10841
+ });
10842
+ if (!res.ok) {
10843
+ const text2 = await res.text().catch(() => "");
10844
+ throwArkError(res.status, text2, modelId);
10845
+ }
10846
+ const parsed = SeedanceResponseSchema.safeParse(await res.json());
10847
+ const decoded = parsed.success ? parsed.data : {};
10848
+ return decoded;
10849
+ },
10850
+ mediaRetryOptions(ctx.call, ctx.signal)
10851
+ );
10852
+ if (!submit.id) throwArkError(void 0, "Seedance task create returned no id", modelId);
10853
+ return submit.id;
10854
+ }
10855
+ async function finalizeSeedanceDraft(req, draftTaskId, ctx) {
10856
+ const key = arkKey(ctx);
10857
+ const body = {
10858
+ model: ctx.model.providerModelId,
10859
+ content: [{ type: "draft_task", draft_task: { id: draftTaskId } }],
10860
+ resolution: seedanceResolution(req, ctx)
10861
+ };
10862
+ if (req.watermark !== void 0) body.watermark = req.watermark;
10863
+ const jobId = await submitSeedanceTask(ctx, key, body);
10864
+ return seedanceJob(ctx, key, jobId, seedanceUsage(ctx, req, seedanceInitialDuration(req)));
10865
+ }
10866
+ async function generateSeedanceVideo(req, ctx) {
10867
+ assertDraftRequest(req, ctx);
10868
+ if (req.draftTaskId !== void 0) return finalizeSeedanceDraft(req, req.draftTaskId, ctx);
10709
10869
  const taskType = req.taskType;
10710
10870
  const hasVideo = Boolean(req.sourceVideo) || (req.referenceVideos?.length ?? 0) > 0;
10711
10871
  if ((taskType === "edit" || taskType === "extend") && !hasVideo) {
@@ -10721,7 +10881,7 @@ async function generateSeedanceVideo(req, ctx) {
10721
10881
  const requestedDuration = seedanceInitialDuration(req);
10722
10882
  let duration = requestedDuration;
10723
10883
  if (taskType === "edit") duration = -1;
10724
- const resolution = seedanceResolution(req);
10884
+ const resolution = seedanceResolution(req, ctx);
10725
10885
  const content = [{ type: "text", text: req.prompt }];
10726
10886
  if (req.firstFrame) {
10727
10887
  content.push({
@@ -10779,25 +10939,8 @@ async function generateSeedanceVideo(req, ctx) {
10779
10939
  if (req.generateAudio !== void 0) body.generate_audio = req.generateAudio;
10780
10940
  if (req.seed !== void 0) body.seed = req.seed;
10781
10941
  if (req.watermark !== void 0) body.watermark = req.watermark;
10782
- const submit = await withRetry(
10783
- async () => {
10784
- const res = await arkFetch(ctx, `${arkBaseUrl(ctx)}${SUBMIT_PATH2}`, {
10785
- method: "POST",
10786
- headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
10787
- body: JSON.stringify(body)
10788
- });
10789
- if (!res.ok) {
10790
- const text2 = await res.text().catch(() => "");
10791
- throwArkError(res.status, text2, modelId);
10792
- }
10793
- const parsed = SeedanceResponseSchema.safeParse(await res.json());
10794
- const decoded = parsed.success ? parsed.data : {};
10795
- return decoded;
10796
- },
10797
- mediaRetryOptions(ctx.call, ctx.signal)
10798
- );
10799
- if (!submit.id) throwArkError(void 0, "Seedance task create returned no id", modelId);
10800
- const jobId = submit.id;
10942
+ if (ctx.model.constraints.draft) body.draft = true;
10943
+ const jobId = await submitSeedanceTask(ctx, key, body);
10801
10944
  const usage5 = seedanceUsage(ctx, req, taskType === "edit" ? requestedDuration : duration);
10802
10945
  return seedanceJob(ctx, key, jobId, usage5);
10803
10946
  }
@@ -11781,13 +11924,13 @@ function minimaxH3Image(editEndpoint) {
11781
11924
  var H3_IMAGE_AREAS = { ...TIER_AREAS2, "4K": 4096 * 4096 };
11782
11925
  var MINIMAX_H3_IMAGE = minimaxH3Image("minimax/h3-image/edit");
11783
11926
  var MINIMAX_H3_IMAGE_HIGHSPEED = minimaxH3Image("minimax/h3-image/highspeed/edit");
11784
- function klingImage(editEndpoint, sizes, field) {
11927
+ function klingImage(editEndpoint, sizes, field, fallbackSize = "1K") {
11785
11928
  return {
11786
11929
  editEndpoint,
11787
11930
  build({ label, req, refs, edit: edit2 }, model) {
11788
11931
  const input = {
11789
11932
  prompt: req.prompt,
11790
- resolution: pick(model, label, "size", req.size ?? "1K", sizes)
11933
+ resolution: pick(model, label, "size", req.size ?? fallbackSize, sizes)
11791
11934
  };
11792
11935
  if (req.aspectRatio === "adaptive") {
11793
11936
  if (edit2) input["aspect_ratio"] = "auto";
@@ -11809,6 +11952,12 @@ var KLING_V3 = klingImage(
11809
11952
  { "1K": "1K", "2K": "2K" },
11810
11953
  "image_url"
11811
11954
  );
11955
+ var KLING_V42 = klingImage(
11956
+ "kling/v4/image-to-image",
11957
+ { "2K": "2K", "4K": "4K" },
11958
+ "image_urls",
11959
+ "2K"
11960
+ );
11812
11961
  var RECRAFT_SIZES = {
11813
11962
  "1:1": "square_hd",
11814
11963
  "4:3": "landscape_4_3",
@@ -11865,6 +12014,7 @@ var FAMILIES = /* @__PURE__ */ new Map([
11865
12014
  ["minimax/h3-image/highspeed/text-to-image", MINIMAX_H3_IMAGE_HIGHSPEED],
11866
12015
  ["fal-ai/kling-image/o3/text-to-image", KLING_O3],
11867
12016
  ["fal-ai/kling-image/v3/text-to-image", KLING_V3],
12017
+ ["kling/v4/text-to-image", KLING_V42],
11868
12018
  ["recraft/v4.1/flash/text-to-image", RECRAFT_FLASH],
11869
12019
  ["fal-ai/sensenova-u1-infographic", SENSENOVA],
11870
12020
  ["fal-ai/seedvr/upscale/image", SEEDVR]
@@ -18718,6 +18868,25 @@ function resolveVideoResolution(requested, model, onUnsupported, warnings) {
18718
18868
  warnings
18719
18869
  );
18720
18870
  }
18871
+ function resolveDraftFinalResolution(requested, draft, model, onUnsupported, warnings) {
18872
+ const [first] = draft.finalResolutions;
18873
+ if (requested === void 0 || draft.finalResolutions.includes(requested))
18874
+ return requested ?? first;
18875
+ if (onUnsupported === "error") {
18876
+ throw new ModelKitError({
18877
+ code: "unsupported_option",
18878
+ message: `${model.id} renders a final from a draft at ${draft.finalResolutions.join(", ")} only`,
18879
+ model: model.id,
18880
+ retryable: false
18881
+ });
18882
+ }
18883
+ warnings.push({
18884
+ code: "resolution_coerced",
18885
+ field: "resolution",
18886
+ message: `${model.id} renders a final at ${String(first)}, not ${requested}`
18887
+ });
18888
+ return first;
18889
+ }
18721
18890
  function resolveDuration(requested, durations, model, onUnsupported, warnings) {
18722
18891
  if (requested === void 0 || !durations) return requested;
18723
18892
  const inSet = Array.isArray(durations) ? durations.includes(requested) : requested >= durations.min && requested <= durations.max;
@@ -19045,7 +19214,13 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
19045
19214
  );
19046
19215
  if (aspectRatio !== void 0) merged.aspectRatio = aspectRatio;
19047
19216
  fillKlingModeResolution(model, merged);
19048
- const resolution = resolveVideoResolution(merged.resolution, model, onUnsupported, warnings);
19217
+ const resolution = merged.draftTaskId !== void 0 && c.draft ? resolveDraftFinalResolution(
19218
+ request.resolution,
19219
+ c.draft,
19220
+ model,
19221
+ onUnsupported,
19222
+ warnings
19223
+ ) : resolveVideoResolution(merged.resolution, model, onUnsupported, warnings);
19049
19224
  if (resolution !== void 0) merged.resolution = resolution;
19050
19225
  if (takesKlingMode(model)) delete merged.mode;
19051
19226
  const duration = resolveDuration(