@shop-os/modelkit 0.23.1 → 0.24.0

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
@@ -6353,6 +6353,54 @@ var VIDEO_MODELS = [
6353
6353
  },
6354
6354
  capabilities: { acceptsSourceVideo: true, videoEdit: true, ...FRAMES_EXCLUDE_REFERENCES }
6355
6355
  },
6356
+ {
6357
+ // The same BytePlus model in draft mode. Probed 2026-11-17: a draft must be 480p; its
6358
+ // final is a second task on this row (draftTaskId), and 720p or no resolution is refused
6359
+ // there. A 4k final also rendered, but the docs list 1080p only. No alias for the provider
6360
+ // id: that alias resolves usage to seedance-2.5. Edit and extend stay on seedance-2.5.
6361
+ id: "seedance-2.5-draft",
6362
+ aliases: ["seedance-2-5-draft"],
6363
+ label: "Seedance 2.5 Draft",
6364
+ type: "video",
6365
+ adapter: "ark",
6366
+ providerModelId: "dreamina-seedance-2-5-260628",
6367
+ lifecycle: "active",
6368
+ exposure: [],
6369
+ constraints: {
6370
+ aspectRatios: [...SEEDANCE_RATIOS],
6371
+ resolutions: ["480p"],
6372
+ durations: { min: 4, max: 30 },
6373
+ references: {
6374
+ images: 30,
6375
+ videos: 10,
6376
+ audios: 10,
6377
+ videoSeconds: { min: 2, max: 30, total: 30 },
6378
+ ...SEEDANCE_REFERENCE_MEDIA,
6379
+ audioSeconds: { min: 2, max: 30, total: 30 },
6380
+ audioFormats: ["wav", "mp3"],
6381
+ audioMaxBytes: 15 * 1024 * 1024
6382
+ },
6383
+ ratioIgnoredWith: ["firstFrame"],
6384
+ supports: ["generateAudio", "lastFrame", "watermark"],
6385
+ draft: { resolution: "480p", finalResolutions: ["1080p"], ttlDays: 14 },
6386
+ prompt: SEEDANCE_PROMPT,
6387
+ audio: "optional"
6388
+ },
6389
+ defaults: {
6390
+ durationSeconds: 5,
6391
+ resolution: "480p",
6392
+ aspectRatio: "16:9",
6393
+ generateAudio: true
6394
+ },
6395
+ usage: { ...VIDEO_USAGE3 },
6396
+ pricingKind: "video_per_second",
6397
+ display: {
6398
+ provider: "bytedance",
6399
+ logo: BYTEDANCE_LOGO2,
6400
+ 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."
6401
+ },
6402
+ capabilities: { acceptsSourceVideo: false, videoEdit: false, ...FRAMES_EXCLUDE_REFERENCES }
6403
+ },
6356
6404
  {
6357
6405
  // Limits probed on the live API 2026-11-16 (1080p is refused). Extend probe: a 4 s
6358
6406
  // extend returned 4 s of new footage only and billed input + output tokens, as on 2.5.
@@ -8330,6 +8378,13 @@ var ModelConstraintsSchema = z3.looseObject({
8330
8378
  maxTotalSeconds: z3.number(),
8331
8379
  returns: z3.enum(["new", "joined"]).optional()
8332
8380
  }).optional(),
8381
+ // Loose so a kit before 0.24.0 keeps a row that carries it (an unknown `supports` value
8382
+ // would drop the row there).
8383
+ draft: z3.looseObject({
8384
+ resolution: VideoResolutionSchema,
8385
+ finalResolutions: z3.array(VideoResolutionSchema).min(1),
8386
+ ttlDays: z3.number().positive()
8387
+ }).optional(),
8333
8388
  tool: VideoToolConstraintsSchema.optional(),
8334
8389
  model3d: Model3dConstraintsSchema.optional(),
8335
8390
  // Loose on purpose: the read path keeps a row whose value is invalid (the accessors in
@@ -10595,8 +10650,12 @@ var SeedanceErrorSchema = z10.object({
10595
10650
  code: z10.string().optional(),
10596
10651
  message: z10.string().optional()
10597
10652
  });
10598
- function seedanceResolution(req) {
10599
- return req.resolution ?? "720p";
10653
+ function seedanceResolution(req, ctx) {
10654
+ const draft = ctx.model.constraints.draft;
10655
+ if (!draft) return req.resolution ?? "720p";
10656
+ if (req.draftTaskId !== void 0)
10657
+ return req.resolution ?? draft.finalResolutions[0] ?? "1080p";
10658
+ return draft.resolution;
10600
10659
  }
10601
10660
  function seedanceUsage(ctx, req, duration) {
10602
10661
  return {
@@ -10606,7 +10665,7 @@ function seedanceUsage(ctx, req, duration) {
10606
10665
  unit: "seconds",
10607
10666
  quantity: duration,
10608
10667
  durationSeconds: duration,
10609
- resolution: seedanceResolution(req)
10668
+ resolution: seedanceResolution(req, ctx)
10610
10669
  };
10611
10670
  }
10612
10671
  function seedanceInitialDuration(req) {
@@ -10704,8 +10763,67 @@ function seedanceJob(ctx, key, jobId, usage5) {
10704
10763
  }
10705
10764
  };
10706
10765
  }
10707
- async function generateSeedanceVideo(req, ctx) {
10766
+ function draftRefusal(ctx, message) {
10767
+ return new ModelKitError({
10768
+ code: "unsupported_option",
10769
+ message: `${ctx.model.id} ${message}`,
10770
+ provider: "ark",
10771
+ model: ctx.model.id,
10772
+ retryable: false
10773
+ });
10774
+ }
10775
+ function assertDraftRequest(req, ctx) {
10776
+ const draft = ctx.model.constraints.draft;
10777
+ if (!draft) {
10778
+ if (req.draftTaskId !== void 0) throw draftRefusal(ctx, "has no draft mode");
10779
+ return;
10780
+ }
10781
+ if (req.draftTaskId === void 0 && req.resolution !== void 0 && req.resolution !== draft.resolution)
10782
+ throw draftRefusal(ctx, `renders a draft at ${draft.resolution} only`);
10783
+ if (req.draftTaskId === void 0 && req.taskType !== void 0)
10784
+ throw draftRefusal(ctx, "renders drafts without a task type");
10785
+ if (req.draftTaskId !== void 0 && req.resolution !== void 0 && !draft.finalResolutions.includes(req.resolution))
10786
+ throw draftRefusal(
10787
+ ctx,
10788
+ `renders a final from a draft at ${draft.finalResolutions.join(", ")} only`
10789
+ );
10790
+ }
10791
+ async function submitSeedanceTask(ctx, key, body) {
10708
10792
  const modelId = ctx.model.id;
10793
+ const submit = await withRetry(
10794
+ async () => {
10795
+ const res = await arkFetch(ctx, `${arkBaseUrl(ctx)}${SUBMIT_PATH2}`, {
10796
+ method: "POST",
10797
+ headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
10798
+ body: JSON.stringify(body)
10799
+ });
10800
+ if (!res.ok) {
10801
+ const text2 = await res.text().catch(() => "");
10802
+ throwArkError(res.status, text2, modelId);
10803
+ }
10804
+ const parsed = SeedanceResponseSchema.safeParse(await res.json());
10805
+ const decoded = parsed.success ? parsed.data : {};
10806
+ return decoded;
10807
+ },
10808
+ mediaRetryOptions(ctx.call, ctx.signal)
10809
+ );
10810
+ if (!submit.id) throwArkError(void 0, "Seedance task create returned no id", modelId);
10811
+ return submit.id;
10812
+ }
10813
+ async function finalizeSeedanceDraft(req, draftTaskId, ctx) {
10814
+ const key = arkKey(ctx);
10815
+ const body = {
10816
+ model: ctx.model.providerModelId,
10817
+ content: [{ type: "draft_task", draft_task: { id: draftTaskId } }],
10818
+ resolution: seedanceResolution(req, ctx)
10819
+ };
10820
+ if (req.watermark !== void 0) body.watermark = req.watermark;
10821
+ const jobId = await submitSeedanceTask(ctx, key, body);
10822
+ return seedanceJob(ctx, key, jobId, seedanceUsage(ctx, req, seedanceInitialDuration(req)));
10823
+ }
10824
+ async function generateSeedanceVideo(req, ctx) {
10825
+ assertDraftRequest(req, ctx);
10826
+ if (req.draftTaskId !== void 0) return finalizeSeedanceDraft(req, req.draftTaskId, ctx);
10709
10827
  const taskType = req.taskType;
10710
10828
  const hasVideo = Boolean(req.sourceVideo) || (req.referenceVideos?.length ?? 0) > 0;
10711
10829
  if ((taskType === "edit" || taskType === "extend") && !hasVideo) {
@@ -10721,7 +10839,7 @@ async function generateSeedanceVideo(req, ctx) {
10721
10839
  const requestedDuration = seedanceInitialDuration(req);
10722
10840
  let duration = requestedDuration;
10723
10841
  if (taskType === "edit") duration = -1;
10724
- const resolution = seedanceResolution(req);
10842
+ const resolution = seedanceResolution(req, ctx);
10725
10843
  const content = [{ type: "text", text: req.prompt }];
10726
10844
  if (req.firstFrame) {
10727
10845
  content.push({
@@ -10779,25 +10897,8 @@ async function generateSeedanceVideo(req, ctx) {
10779
10897
  if (req.generateAudio !== void 0) body.generate_audio = req.generateAudio;
10780
10898
  if (req.seed !== void 0) body.seed = req.seed;
10781
10899
  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;
10900
+ if (ctx.model.constraints.draft) body.draft = true;
10901
+ const jobId = await submitSeedanceTask(ctx, key, body);
10801
10902
  const usage5 = seedanceUsage(ctx, req, taskType === "edit" ? requestedDuration : duration);
10802
10903
  return seedanceJob(ctx, key, jobId, usage5);
10803
10904
  }
@@ -18718,6 +18819,25 @@ function resolveVideoResolution(requested, model, onUnsupported, warnings) {
18718
18819
  warnings
18719
18820
  );
18720
18821
  }
18822
+ function resolveDraftFinalResolution(requested, draft, model, onUnsupported, warnings) {
18823
+ const [first] = draft.finalResolutions;
18824
+ if (requested === void 0 || draft.finalResolutions.includes(requested))
18825
+ return requested ?? first;
18826
+ if (onUnsupported === "error") {
18827
+ throw new ModelKitError({
18828
+ code: "unsupported_option",
18829
+ message: `${model.id} renders a final from a draft at ${draft.finalResolutions.join(", ")} only`,
18830
+ model: model.id,
18831
+ retryable: false
18832
+ });
18833
+ }
18834
+ warnings.push({
18835
+ code: "resolution_coerced",
18836
+ field: "resolution",
18837
+ message: `${model.id} renders a final at ${String(first)}, not ${requested}`
18838
+ });
18839
+ return first;
18840
+ }
18721
18841
  function resolveDuration(requested, durations, model, onUnsupported, warnings) {
18722
18842
  if (requested === void 0 || !durations) return requested;
18723
18843
  const inSet = Array.isArray(durations) ? durations.includes(requested) : requested >= durations.min && requested <= durations.max;
@@ -19045,7 +19165,13 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
19045
19165
  );
19046
19166
  if (aspectRatio !== void 0) merged.aspectRatio = aspectRatio;
19047
19167
  fillKlingModeResolution(model, merged);
19048
- const resolution = resolveVideoResolution(merged.resolution, model, onUnsupported, warnings);
19168
+ const resolution = merged.draftTaskId !== void 0 && c.draft ? resolveDraftFinalResolution(
19169
+ request.resolution,
19170
+ c.draft,
19171
+ model,
19172
+ onUnsupported,
19173
+ warnings
19174
+ ) : resolveVideoResolution(merged.resolution, model, onUnsupported, warnings);
19049
19175
  if (resolution !== void 0) merged.resolution = resolution;
19050
19176
  if (takesKlingMode(model)) delete merged.mode;
19051
19177
  const duration = resolveDuration(