@shop-os/modelkit 0.2.9 → 0.2.10

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
@@ -106,6 +106,8 @@ interface VideoRequest {
106
106
  watermark?: boolean;
107
107
  /** Provider-side safety checker toggle (fal MiniMax). Provider default when unset. */
108
108
  safetyChecker?: boolean;
109
+ /** Seedance omni-reference subtask hint. `edit` forces duration -1 and adaptive ratio. */
110
+ taskType?: "reference" | "edit" | "extend";
109
111
  mode?: "standard" | "pro";
110
112
  }
111
113
  /**
@@ -157,9 +159,11 @@ interface MediaPart {
157
159
  cleanup?: () => Promise<void>;
158
160
  }
159
161
  type RequiredInput = "firstFrame" | "sourceVideo" | "references";
160
- type SupportedOption = "seed" | "quality" | "negativePrompt" | "cfgScale" | "generateAudio" | "promptExpansion" | "lastFrame" | "count" | "outputFormat" | "scaleFactor" | "safetySettings" | "temperature" | "upscale" | "watermark" | "safetyChecker" | "instrumental";
162
+ type SupportedOption = "seed" | "quality" | "negativePrompt" | "cfgScale" | "generateAudio" | "promptExpansion" | "lastFrame" | "count" | "outputFormat" | "scaleFactor" | "safetySettings" | "temperature" | "upscale" | "watermark" | "safetyChecker" | "taskType" | "instrumental";
161
163
  interface ReferenceLimits {
162
164
  images?: number;
165
+ /** Lower image cap when a reference video is also sent (Kling V3 Omni: 7 → 4). */
166
+ imagesWithVideo?: number;
163
167
  videos?: number;
164
168
  audios?: number;
165
169
  total?: number;
package/dist/index.d.ts CHANGED
@@ -106,6 +106,8 @@ interface VideoRequest {
106
106
  watermark?: boolean;
107
107
  /** Provider-side safety checker toggle (fal MiniMax). Provider default when unset. */
108
108
  safetyChecker?: boolean;
109
+ /** Seedance omni-reference subtask hint. `edit` forces duration -1 and adaptive ratio. */
110
+ taskType?: "reference" | "edit" | "extend";
109
111
  mode?: "standard" | "pro";
110
112
  }
111
113
  /**
@@ -157,9 +159,11 @@ interface MediaPart {
157
159
  cleanup?: () => Promise<void>;
158
160
  }
159
161
  type RequiredInput = "firstFrame" | "sourceVideo" | "references";
160
- type SupportedOption = "seed" | "quality" | "negativePrompt" | "cfgScale" | "generateAudio" | "promptExpansion" | "lastFrame" | "count" | "outputFormat" | "scaleFactor" | "safetySettings" | "temperature" | "upscale" | "watermark" | "safetyChecker" | "instrumental";
162
+ type SupportedOption = "seed" | "quality" | "negativePrompt" | "cfgScale" | "generateAudio" | "promptExpansion" | "lastFrame" | "count" | "outputFormat" | "scaleFactor" | "safetySettings" | "temperature" | "upscale" | "watermark" | "safetyChecker" | "taskType" | "instrumental";
161
163
  interface ReferenceLimits {
162
164
  images?: number;
165
+ /** Lower image cap when a reference video is also sent (Kling V3 Omni: 7 → 4). */
166
+ imagesWithVideo?: number;
163
167
  videos?: number;
164
168
  audios?: number;
165
169
  total?: number;
package/dist/index.js CHANGED
@@ -1470,6 +1470,7 @@ var VIDEO_MODELS = [
1470
1470
  },
1471
1471
  {
1472
1472
  // generateAudio defaults to false here (trigger-workflows); Space Builder defaults it to true.
1473
+ // omni_reference_task_type edit/extend: adaptive ratio, edit sends duration -1.
1473
1474
  id: "seedance-2.5",
1474
1475
  aliases: ["seedance-2-5", "dreamina-seedance-2-5-260628"],
1475
1476
  label: "Seedance 2.5",
@@ -1484,7 +1485,7 @@ var VIDEO_MODELS = [
1484
1485
  durations: { min: 4, max: 30 },
1485
1486
  references: { images: 30, videos: 10, audios: 10 },
1486
1487
  ratioIgnoredWith: ["firstFrame", "sourceVideo"],
1487
- supports: ["generateAudio", "seed", "lastFrame", "watermark"]
1488
+ supports: ["generateAudio", "seed", "lastFrame", "watermark", "taskType"]
1488
1489
  },
1489
1490
  defaults: {
1490
1491
  durationSeconds: 5,
@@ -1593,6 +1594,9 @@ var VIDEO_MODELS = [
1593
1594
  },
1594
1595
  {
1595
1596
  // mode standard/pro selects 720p/1080p; the endpoint takes no separate resolution.
1597
+ // Replicate: "Max 7 [images] without video, 4 with video"; 4K does not support
1598
+ // reference_video. No `videos` limit yet: the adapter sends no reference video,
1599
+ // so `imagesWithVideo` stays dormant until one is wired through.
1596
1600
  id: "kling-v3-omni-video",
1597
1601
  aliases: ["kwaivgi/kling-v3-omni-video", "kling-v3-omni"],
1598
1602
  label: "Kling V3 Omni",
@@ -1605,7 +1609,7 @@ var VIDEO_MODELS = [
1605
1609
  aspectRatios: [...KLING_RATIOS],
1606
1610
  resolutions: ["720p", "1080p"],
1607
1611
  durations: { min: 3, max: 15 },
1608
- references: { images: 7 },
1612
+ references: { images: 7, imagesWithVideo: 4 },
1609
1613
  supports: ["generateAudio", "lastFrame"]
1610
1614
  },
1611
1615
  defaults: { durationSeconds: 5, aspectRatio: "16:9", generateAudio: false, mode: "pro" },
@@ -1881,6 +1885,7 @@ var SupportedOptionSchema = z.enum([
1881
1885
  "upscale",
1882
1886
  "watermark",
1883
1887
  "safetyChecker",
1888
+ "taskType",
1884
1889
  "instrumental"
1885
1890
  ]);
1886
1891
  var UsageUnitSchema = z.enum([
@@ -1903,6 +1908,7 @@ var ProviderOptionValueSchema = z.lazy(
1903
1908
  var ProviderOptionsSchema = z.record(z.string(), z.record(z.string(), ProviderOptionValueSchema));
1904
1909
  var ReferenceLimitsSchema = z.looseObject({
1905
1910
  images: z.number().optional(),
1911
+ imagesWithVideo: z.number().optional(),
1906
1912
  videos: z.number().optional(),
1907
1913
  audios: z.number().optional(),
1908
1914
  total: z.number().optional(),
@@ -1964,6 +1970,7 @@ var DefaultsSchema = z.looseObject({
1964
1970
  promptExpansion: z.enum(["fast", "balanced", "quality"]).optional(),
1965
1971
  watermark: z.boolean().optional(),
1966
1972
  safetyChecker: z.boolean().optional(),
1973
+ taskType: z.enum(["reference", "edit", "extend"]).optional(),
1967
1974
  mode: z.enum(["standard", "pro"]).optional(),
1968
1975
  instrumental: z.boolean().optional()
1969
1976
  });
@@ -2523,6 +2530,9 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
2523
2530
  model,
2524
2531
  warnings
2525
2532
  );
2533
+ if (limits.imagesWithVideo !== void 0 && (limits.videos ?? 0) > 0 && videos.length > 0 && images.length > limits.imagesWithVideo) {
2534
+ images = trim("referenceImages", images, limits.imagesWithVideo, model, warnings);
2535
+ }
2526
2536
  if (limits.total !== void 0) {
2527
2537
  let over = images.length + videos.length + audios.length - limits.total;
2528
2538
  if (over > 0) {
@@ -2556,7 +2566,8 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
2556
2566
  "promptExpansion",
2557
2567
  "lastFrame",
2558
2568
  "watermark",
2559
- "safetyChecker"
2569
+ "safetyChecker",
2570
+ "taskType"
2560
2571
  ]);
2561
2572
  return { request: merged, warnings };
2562
2573
  }
@@ -4004,9 +4015,22 @@ function seedanceErrorMessage(error, status) {
4004
4015
  return `Seedance task ${status}`;
4005
4016
  }
4006
4017
  async function generateSeedanceVideo(req, ctx) {
4007
- const key = arkKey(ctx);
4008
4018
  const modelId = ctx.model.id;
4009
- const duration = req.durationSeconds ?? 5;
4019
+ const taskType = req.taskType;
4020
+ const hasVideo = Boolean(req.sourceVideo) || (req.referenceVideos?.length ?? 0) > 0;
4021
+ if ((taskType === "edit" || taskType === "extend") && !hasVideo) {
4022
+ throw new ModelKitError({
4023
+ code: "missing_input",
4024
+ message: `${ctx.model.id} ${taskType} task needs a source or reference video`,
4025
+ provider: "ark",
4026
+ model: ctx.model.id,
4027
+ retryable: false
4028
+ });
4029
+ }
4030
+ const key = arkKey(ctx);
4031
+ const requestedDuration = req.durationSeconds ?? 5;
4032
+ let duration = requestedDuration;
4033
+ if (taskType === "edit") duration = -1;
4010
4034
  const resolution = req.resolution ?? "720p";
4011
4035
  const content = [{ type: "text", text: req.prompt }];
4012
4036
  if (req.firstFrame) {
@@ -4058,7 +4082,10 @@ async function generateSeedanceVideo(req, ctx) {
4058
4082
  duration,
4059
4083
  resolution
4060
4084
  };
4061
- if (!hasFrameAnchor && req.aspectRatio !== void 0) body.ratio = req.aspectRatio;
4085
+ if (taskType === "edit" || taskType === "extend") body.ratio = "adaptive";
4086
+ else if (!hasFrameAnchor && req.aspectRatio !== void 0) body.ratio = req.aspectRatio;
4087
+ if (taskType !== void 0 && ctx.model.id === "seedance-2.5")
4088
+ body.omni_reference_task_type = taskType;
4062
4089
  if (req.generateAudio !== void 0) body.generate_audio = req.generateAudio;
4063
4090
  if (req.seed !== void 0) body.seed = req.seed;
4064
4091
  if (req.watermark !== void 0) body.watermark = req.watermark;
@@ -4078,7 +4105,7 @@ async function generateSeedanceVideo(req, ctx) {
4078
4105
  }, retryOptsFor(ctx));
4079
4106
  if (!submit.id) throwArkError(void 0, "Seedance task create returned no id", modelId);
4080
4107
  const jobId = submit.id;
4081
- const usage2 = seedanceUsage(ctx, req, duration);
4108
+ const usage2 = seedanceUsage(ctx, req, taskType === "edit" ? requestedDuration : duration);
4082
4109
  const fetchStatus = async () => {
4083
4110
  const res = await arkFetch(ctx, `${arkBaseUrl(ctx)}${SUBMIT_PATH}/${jobId}`, {
4084
4111
  headers: { Authorization: `Bearer ${key}` }
@@ -4125,6 +4152,10 @@ async function generateSeedanceVideo(req, ctx) {
4125
4152
  "Seedance task succeeded but returned no video_url",
4126
4153
  modelId
4127
4154
  );
4155
+ if (polled.duration !== void 0 && polled.duration > 0) {
4156
+ usage2.quantity = polled.duration;
4157
+ usage2.durationSeconds = polled.duration;
4158
+ }
4128
4159
  const tokens = polled.usage;
4129
4160
  if (tokens?.total_tokens !== void 0 && tokens.completion_tokens !== void 0) {
4130
4161
  usage2.inputTokens = tokens.total_tokens - tokens.completion_tokens;
@@ -5180,7 +5211,7 @@ async function generateOmniVideo(req, ctx, createGenAIClient) {
5180
5211
  const apiKey = googleKey(ctx);
5181
5212
  const modelId = ctx.model.id;
5182
5213
  const providerModelId = ctx.model.providerModelId;
5183
- const duration = req.durationSeconds ?? 8;
5214
+ const duration = req.durationSeconds ?? 10;
5184
5215
  const images = req.referenceImages ?? [];
5185
5216
  const videos = req.referenceVideos ?? [];
5186
5217
  const task = req.sourceVideo ? "edit" : req.firstFrame ? "image_to_video" : images.length > 0 || videos.length > 0 ? "reference_to_video" : "text_to_video";