@shop-os/modelkit 0.23.0 → 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.cjs CHANGED
@@ -6470,7 +6470,7 @@ var VIDEO_MODELS = [
6470
6470
  exposure: ["cowork", "space_builder"],
6471
6471
  constraints: {
6472
6472
  aspectRatios: [...SEEDANCE_RATIOS],
6473
- resolutions: ["480p", "720p", "1080p"],
6473
+ resolutions: ["480p", "720p", "1080p", "4k"],
6474
6474
  durations: { min: 4, max: 30 },
6475
6475
  references: {
6476
6476
  images: 30,
@@ -6505,10 +6505,58 @@ var VIDEO_MODELS = [
6505
6505
  display: {
6506
6506
  provider: "bytedance",
6507
6507
  logo: BYTEDANCE_LOGO2,
6508
- description: "ByteDance Seedance 2.5 for long-form storytelling and omni-reference generation/editing; up to 50 reference assets and 4-30 second clips at up to 1080p."
6508
+ description: "ByteDance Seedance 2.5 for long-form storytelling and omni-reference generation/editing; up to 50 reference assets and 4-30 second clips at up to 4K."
6509
6509
  },
6510
6510
  capabilities: { acceptsSourceVideo: true, videoEdit: true, ...FRAMES_EXCLUDE_REFERENCES }
6511
6511
  },
6512
+ {
6513
+ // The same BytePlus model in draft mode. Probed 2026-11-17: a draft must be 480p; its
6514
+ // final is a second task on this row (draftTaskId), and 720p or no resolution is refused
6515
+ // there. A 4k final also rendered, but the docs list 1080p only. No alias for the provider
6516
+ // id: that alias resolves usage to seedance-2.5. Edit and extend stay on seedance-2.5.
6517
+ id: "seedance-2.5-draft",
6518
+ aliases: ["seedance-2-5-draft"],
6519
+ label: "Seedance 2.5 Draft",
6520
+ type: "video",
6521
+ adapter: "ark",
6522
+ providerModelId: "dreamina-seedance-2-5-260628",
6523
+ lifecycle: "active",
6524
+ exposure: [],
6525
+ constraints: {
6526
+ aspectRatios: [...SEEDANCE_RATIOS],
6527
+ resolutions: ["480p"],
6528
+ durations: { min: 4, max: 30 },
6529
+ references: {
6530
+ images: 30,
6531
+ videos: 10,
6532
+ audios: 10,
6533
+ videoSeconds: { min: 2, max: 30, total: 30 },
6534
+ ...SEEDANCE_REFERENCE_MEDIA,
6535
+ audioSeconds: { min: 2, max: 30, total: 30 },
6536
+ audioFormats: ["wav", "mp3"],
6537
+ audioMaxBytes: 15 * 1024 * 1024
6538
+ },
6539
+ ratioIgnoredWith: ["firstFrame"],
6540
+ supports: ["generateAudio", "lastFrame", "watermark"],
6541
+ draft: { resolution: "480p", finalResolutions: ["1080p"], ttlDays: 14 },
6542
+ prompt: SEEDANCE_PROMPT,
6543
+ audio: "optional"
6544
+ },
6545
+ defaults: {
6546
+ durationSeconds: 5,
6547
+ resolution: "480p",
6548
+ aspectRatio: "16:9",
6549
+ generateAudio: true
6550
+ },
6551
+ usage: { ...VIDEO_USAGE3 },
6552
+ pricingKind: "video_per_second",
6553
+ display: {
6554
+ provider: "bytedance",
6555
+ logo: BYTEDANCE_LOGO2,
6556
+ 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."
6557
+ },
6558
+ capabilities: { acceptsSourceVideo: false, videoEdit: false, ...FRAMES_EXCLUDE_REFERENCES }
6559
+ },
6512
6560
  {
6513
6561
  // Limits probed on the live API 2026-11-16 (1080p is refused). Extend probe: a 4 s
6514
6562
  // extend returned 4 s of new footage only and billed input + output tokens, as on 2.5.
@@ -8486,6 +8534,13 @@ var ModelConstraintsSchema = import_zod3.z.looseObject({
8486
8534
  maxTotalSeconds: import_zod3.z.number(),
8487
8535
  returns: import_zod3.z.enum(["new", "joined"]).optional()
8488
8536
  }).optional(),
8537
+ // Loose so a kit before 0.24.0 keeps a row that carries it (an unknown `supports` value
8538
+ // would drop the row there).
8539
+ draft: import_zod3.z.looseObject({
8540
+ resolution: VideoResolutionSchema,
8541
+ finalResolutions: import_zod3.z.array(VideoResolutionSchema).min(1),
8542
+ ttlDays: import_zod3.z.number().positive()
8543
+ }).optional(),
8489
8544
  tool: VideoToolConstraintsSchema.optional(),
8490
8545
  model3d: Model3dConstraintsSchema.optional(),
8491
8546
  // Loose on purpose: the read path keeps a row whose value is invalid (the accessors in
@@ -10751,8 +10806,12 @@ var SeedanceErrorSchema = import_zod10.z.object({
10751
10806
  code: import_zod10.z.string().optional(),
10752
10807
  message: import_zod10.z.string().optional()
10753
10808
  });
10754
- function seedanceResolution(req) {
10755
- return req.resolution ?? "720p";
10809
+ function seedanceResolution(req, ctx) {
10810
+ const draft = ctx.model.constraints.draft;
10811
+ if (!draft) return req.resolution ?? "720p";
10812
+ if (req.draftTaskId !== void 0)
10813
+ return req.resolution ?? draft.finalResolutions[0] ?? "1080p";
10814
+ return draft.resolution;
10756
10815
  }
10757
10816
  function seedanceUsage(ctx, req, duration) {
10758
10817
  return {
@@ -10762,7 +10821,7 @@ function seedanceUsage(ctx, req, duration) {
10762
10821
  unit: "seconds",
10763
10822
  quantity: duration,
10764
10823
  durationSeconds: duration,
10765
- resolution: seedanceResolution(req)
10824
+ resolution: seedanceResolution(req, ctx)
10766
10825
  };
10767
10826
  }
10768
10827
  function seedanceInitialDuration(req) {
@@ -10860,8 +10919,67 @@ function seedanceJob(ctx, key, jobId, usage5) {
10860
10919
  }
10861
10920
  };
10862
10921
  }
10863
- async function generateSeedanceVideo(req, ctx) {
10922
+ function draftRefusal(ctx, message) {
10923
+ return new ModelKitError({
10924
+ code: "unsupported_option",
10925
+ message: `${ctx.model.id} ${message}`,
10926
+ provider: "ark",
10927
+ model: ctx.model.id,
10928
+ retryable: false
10929
+ });
10930
+ }
10931
+ function assertDraftRequest(req, ctx) {
10932
+ const draft = ctx.model.constraints.draft;
10933
+ if (!draft) {
10934
+ if (req.draftTaskId !== void 0) throw draftRefusal(ctx, "has no draft mode");
10935
+ return;
10936
+ }
10937
+ if (req.draftTaskId === void 0 && req.resolution !== void 0 && req.resolution !== draft.resolution)
10938
+ throw draftRefusal(ctx, `renders a draft at ${draft.resolution} only`);
10939
+ if (req.draftTaskId === void 0 && req.taskType !== void 0)
10940
+ throw draftRefusal(ctx, "renders drafts without a task type");
10941
+ if (req.draftTaskId !== void 0 && req.resolution !== void 0 && !draft.finalResolutions.includes(req.resolution))
10942
+ throw draftRefusal(
10943
+ ctx,
10944
+ `renders a final from a draft at ${draft.finalResolutions.join(", ")} only`
10945
+ );
10946
+ }
10947
+ async function submitSeedanceTask(ctx, key, body) {
10864
10948
  const modelId = ctx.model.id;
10949
+ const submit = await withRetry(
10950
+ async () => {
10951
+ const res = await arkFetch(ctx, `${arkBaseUrl(ctx)}${SUBMIT_PATH2}`, {
10952
+ method: "POST",
10953
+ headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
10954
+ body: JSON.stringify(body)
10955
+ });
10956
+ if (!res.ok) {
10957
+ const text2 = await res.text().catch(() => "");
10958
+ throwArkError(res.status, text2, modelId);
10959
+ }
10960
+ const parsed = SeedanceResponseSchema.safeParse(await res.json());
10961
+ const decoded = parsed.success ? parsed.data : {};
10962
+ return decoded;
10963
+ },
10964
+ mediaRetryOptions(ctx.call, ctx.signal)
10965
+ );
10966
+ if (!submit.id) throwArkError(void 0, "Seedance task create returned no id", modelId);
10967
+ return submit.id;
10968
+ }
10969
+ async function finalizeSeedanceDraft(req, draftTaskId, ctx) {
10970
+ const key = arkKey(ctx);
10971
+ const body = {
10972
+ model: ctx.model.providerModelId,
10973
+ content: [{ type: "draft_task", draft_task: { id: draftTaskId } }],
10974
+ resolution: seedanceResolution(req, ctx)
10975
+ };
10976
+ if (req.watermark !== void 0) body.watermark = req.watermark;
10977
+ const jobId = await submitSeedanceTask(ctx, key, body);
10978
+ return seedanceJob(ctx, key, jobId, seedanceUsage(ctx, req, seedanceInitialDuration(req)));
10979
+ }
10980
+ async function generateSeedanceVideo(req, ctx) {
10981
+ assertDraftRequest(req, ctx);
10982
+ if (req.draftTaskId !== void 0) return finalizeSeedanceDraft(req, req.draftTaskId, ctx);
10865
10983
  const taskType = req.taskType;
10866
10984
  const hasVideo = Boolean(req.sourceVideo) || (req.referenceVideos?.length ?? 0) > 0;
10867
10985
  if ((taskType === "edit" || taskType === "extend") && !hasVideo) {
@@ -10877,7 +10995,7 @@ async function generateSeedanceVideo(req, ctx) {
10877
10995
  const requestedDuration = seedanceInitialDuration(req);
10878
10996
  let duration = requestedDuration;
10879
10997
  if (taskType === "edit") duration = -1;
10880
- const resolution = seedanceResolution(req);
10998
+ const resolution = seedanceResolution(req, ctx);
10881
10999
  const content = [{ type: "text", text: req.prompt }];
10882
11000
  if (req.firstFrame) {
10883
11001
  content.push({
@@ -10935,25 +11053,8 @@ async function generateSeedanceVideo(req, ctx) {
10935
11053
  if (req.generateAudio !== void 0) body.generate_audio = req.generateAudio;
10936
11054
  if (req.seed !== void 0) body.seed = req.seed;
10937
11055
  if (req.watermark !== void 0) body.watermark = req.watermark;
10938
- const submit = await withRetry(
10939
- async () => {
10940
- const res = await arkFetch(ctx, `${arkBaseUrl(ctx)}${SUBMIT_PATH2}`, {
10941
- method: "POST",
10942
- headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
10943
- body: JSON.stringify(body)
10944
- });
10945
- if (!res.ok) {
10946
- const text2 = await res.text().catch(() => "");
10947
- throwArkError(res.status, text2, modelId);
10948
- }
10949
- const parsed = SeedanceResponseSchema.safeParse(await res.json());
10950
- const decoded = parsed.success ? parsed.data : {};
10951
- return decoded;
10952
- },
10953
- mediaRetryOptions(ctx.call, ctx.signal)
10954
- );
10955
- if (!submit.id) throwArkError(void 0, "Seedance task create returned no id", modelId);
10956
- const jobId = submit.id;
11056
+ if (ctx.model.constraints.draft) body.draft = true;
11057
+ const jobId = await submitSeedanceTask(ctx, key, body);
10957
11058
  const usage5 = seedanceUsage(ctx, req, taskType === "edit" ? requestedDuration : duration);
10958
11059
  return seedanceJob(ctx, key, jobId, usage5);
10959
11060
  }
@@ -18872,6 +18973,25 @@ function resolveVideoResolution(requested, model, onUnsupported, warnings) {
18872
18973
  warnings
18873
18974
  );
18874
18975
  }
18976
+ function resolveDraftFinalResolution(requested, draft, model, onUnsupported, warnings) {
18977
+ const [first] = draft.finalResolutions;
18978
+ if (requested === void 0 || draft.finalResolutions.includes(requested))
18979
+ return requested ?? first;
18980
+ if (onUnsupported === "error") {
18981
+ throw new ModelKitError({
18982
+ code: "unsupported_option",
18983
+ message: `${model.id} renders a final from a draft at ${draft.finalResolutions.join(", ")} only`,
18984
+ model: model.id,
18985
+ retryable: false
18986
+ });
18987
+ }
18988
+ warnings.push({
18989
+ code: "resolution_coerced",
18990
+ field: "resolution",
18991
+ message: `${model.id} renders a final at ${String(first)}, not ${requested}`
18992
+ });
18993
+ return first;
18994
+ }
18875
18995
  function resolveDuration(requested, durations, model, onUnsupported, warnings) {
18876
18996
  if (requested === void 0 || !durations) return requested;
18877
18997
  const inSet = Array.isArray(durations) ? durations.includes(requested) : requested >= durations.min && requested <= durations.max;
@@ -19199,7 +19319,13 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
19199
19319
  );
19200
19320
  if (aspectRatio !== void 0) merged.aspectRatio = aspectRatio;
19201
19321
  fillKlingModeResolution(model, merged);
19202
- const resolution = resolveVideoResolution(merged.resolution, model, onUnsupported, warnings);
19322
+ const resolution = merged.draftTaskId !== void 0 && c.draft ? resolveDraftFinalResolution(
19323
+ request.resolution,
19324
+ c.draft,
19325
+ model,
19326
+ onUnsupported,
19327
+ warnings
19328
+ ) : resolveVideoResolution(merged.resolution, model, onUnsupported, warnings);
19203
19329
  if (resolution !== void 0) merged.resolution = resolution;
19204
19330
  if (takesKlingMode(model)) delete merged.mode;
19205
19331
  const duration = resolveDuration(