@picsart/ai-sdk 5.26.0 → 5.26.2

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.
Files changed (3) hide show
  1. package/index.d.ts +3 -19
  2. package/index.js +192 -147
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -142,19 +142,14 @@ type ModelInputById = {
142
142
  };
143
143
  "eleven-dubbing": {
144
144
  audioUrl: string;
145
- language?: string;
146
- accent?: string;
145
+ language: string;
147
146
  };
148
147
  "eleven-multilingual-sts-v2": {
149
148
  audioUrl: string;
150
149
  voiceId?: string;
151
- language?: string;
152
- accent?: string;
153
150
  removeBackgroundNoise?: boolean;
154
151
  };
155
152
  "eleven-multilingual-v2": {
156
- language?: string;
157
- accent?: string;
158
153
  prompt: string;
159
154
  voiceId?: string;
160
155
  };
@@ -165,7 +160,6 @@ type ModelInputById = {
165
160
  };
166
161
  "eleven-v3": {
167
162
  language?: string;
168
- accent?: string;
169
163
  prompt: string;
170
164
  voiceId?: string;
171
165
  };
@@ -179,7 +173,7 @@ type ModelInputById = {
179
173
  prompt: string;
180
174
  };
181
175
  "eleven-voice-remix": {
182
- voiceId?: string;
176
+ voiceId: string;
183
177
  prompt: string;
184
178
  };
185
179
  "elevenlabs-music-v2": {
@@ -189,7 +183,7 @@ type ModelInputById = {
189
183
  };
190
184
  "elevenlabs-sfx": {
191
185
  prompt: string;
192
- duration?: 1 | 3 | 5 | 8 | 10 | 15;
186
+ duration?: number;
193
187
  };
194
188
  "flux-2-flex": {
195
189
  prompt: string;
@@ -534,7 +528,6 @@ type ModelInputById = {
534
528
  };
535
529
  "kling-motion-control": {
536
530
  prompt?: string;
537
- resolution?: "720p" | "1080p";
538
531
  renderingSpeed?: "std" | "pro";
539
532
  characterOrientation?: "image" | "video";
540
533
  keepOriginalSound?: "yes" | "no";
@@ -543,7 +536,6 @@ type ModelInputById = {
543
536
  };
544
537
  "kling-motion-control-v3": {
545
538
  prompt?: string;
546
- resolution?: "720p" | "1080p";
547
539
  renderingSpeed?: "std" | "pro";
548
540
  characterOrientation?: "image" | "video";
549
541
  keepOriginalSound?: "yes" | "no";
@@ -575,8 +567,6 @@ type ModelInputById = {
575
567
  count?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
576
568
  negativePrompt?: string;
577
569
  imageUrls?: string[];
578
- imageWeight?: number;
579
- humanFidelity?: number;
580
570
  };
581
571
  "kling-v2-6": {
582
572
  prompt: string;
@@ -586,8 +576,6 @@ type ModelInputById = {
586
576
  endFrame?: string;
587
577
  negativePrompt?: string;
588
578
  generateAudio?: boolean;
589
- cfgScale?: number;
590
- renderingSpeed?: "std" | "pro";
591
579
  };
592
580
  "kling-v2a": {
593
581
  videoUrl: string;
@@ -613,7 +601,6 @@ type ModelInputById = {
613
601
  elementList?: Array<{
614
602
  element_id: string;
615
603
  }>;
616
- staticMask?: string;
617
604
  renderingSpeed?: "std" | "pro" | "4k";
618
605
  };
619
606
  "kling-v3-omni": {
@@ -621,7 +608,6 @@ type ModelInputById = {
621
608
  aspectRatio?: "16:9" | "9:16" | "1:1";
622
609
  duration?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
623
610
  resolution?: "720p" | "1080p" | "4k";
624
- renderingSpeed?: "std" | "pro";
625
611
  generateAudio?: boolean;
626
612
  startFrame?: string;
627
613
  endFrame?: string;
@@ -647,7 +633,6 @@ type ModelInputById = {
647
633
  negativePrompt?: string;
648
634
  resolution?: "720p" | "1080p";
649
635
  startFrame?: string;
650
- staticMask?: string;
651
636
  };
652
637
  "kling-video-effects": {
653
638
  templateId?: string;
@@ -657,7 +642,6 @@ type ModelInputById = {
657
642
  prompt: string;
658
643
  aspectRatio?: "16:9" | "9:16" | "1:1";
659
644
  duration?: 5 | 10;
660
- resolution?: "720p" | "1080p";
661
645
  renderingSpeed?: "std" | "pro";
662
646
  generateAudio?: boolean;
663
647
  };
package/index.js CHANGED
@@ -1377,12 +1377,6 @@ var paramPresets = {
1377
1377
  var feat = (label, variant) => ({ label, variant });
1378
1378
 
1379
1379
  // src/vendors/catalog/kling/params.ts
1380
- var klingHumanFidelity = {
1381
- humanFidelity: {
1382
- label: "Face Fidelity",
1383
- descriptor: { kind: "range", min: 0, max: 1, step: 0.05, default: 0.45 }
1384
- }
1385
- };
1386
1380
  var klingCharacterOrientation = {
1387
1381
  characterOrientation: {
1388
1382
  label: "Character Orientation",
@@ -1473,11 +1467,6 @@ var klingV3AdvancedParams = {
1473
1467
  element_id: { kind: "text" }
1474
1468
  }
1475
1469
  }
1476
- },
1477
- staticMask: {
1478
- label: "Static Mask",
1479
- category: "reference",
1480
- descriptor: { kind: "file", accept: "image" }
1481
1470
  }
1482
1471
  };
1483
1472
  var klingOmniAdvancedParams = {
@@ -1580,12 +1569,7 @@ var klingV3TurboVideoBase = {
1580
1569
  ...params.duration(V3_DURATIONS, 5),
1581
1570
  ...params.negativePrompt(),
1582
1571
  ...params.resolution(["720p", "1080p"], "720p"),
1583
- ...params.startFrame("Start Frame"),
1584
- staticMask: {
1585
- label: "Static Mask",
1586
- category: "reference",
1587
- descriptor: { kind: "file", accept: "image" }
1588
- }
1572
+ ...params.startFrame("Start Frame")
1589
1573
  }
1590
1574
  };
1591
1575
  var klingV26VideoBase = {
@@ -1602,9 +1586,7 @@ var klingV26VideoBase = {
1602
1586
  ...paramPresets.videoStartEndWithAudio({
1603
1587
  durations: V26_DURATIONS,
1604
1588
  defaultDuration: 5
1605
- }),
1606
- ...params.cfgScale(0, 1, 0.5, 0.1),
1607
- ...params.renderingSpeed([{ id: "std", label: "Standard" }, { id: "pro", label: "Pro" }], "std")
1589
+ })
1608
1590
  }
1609
1591
  };
1610
1592
  var { MODELS } = defineModels("kling", [
@@ -1620,11 +1602,15 @@ var { MODELS } = defineModels("kling", [
1620
1602
  badge: ["popular", "premium"],
1621
1603
  description: "Long-form video up to 15s with native audio and start/end frame control.",
1622
1604
  constraints: [
1623
- { when: { renderingSpeed: { is: "std" } }, then: { endFrame: { disabled: true, reason: "End frame requires Pro or 4K mode." } } },
1624
1605
  // Backend: `voice_list` requires `sound=on`. Two rules because the
1625
1606
  // `is` operator does not match an unset value (see core/constraints.ts).
1626
1607
  { when: { generateAudio: { is: false } }, then: { voiceList: { disabled: true, reason: "Voice references require generated audio." } } },
1627
- { when: { generateAudio: { exists: false } }, then: { voiceList: { disabled: true, reason: "Voice references require generated audio." } } }
1608
+ { when: { generateAudio: { exists: false } }, then: { voiceList: { disabled: true, reason: "Voice references require generated audio." } } },
1609
+ // Vendor: first/end frames are unsupported in multi-shot mode.
1610
+ { when: { multiShot: { is: true } }, then: {
1611
+ startFrame: { disabled: true, reason: "Frames are unavailable in multi-shot mode." },
1612
+ endFrame: { disabled: true, reason: "Frames are unavailable in multi-shot mode." }
1613
+ } }
1628
1614
  ]
1629
1615
  },
1630
1616
  // ── Video: Kling V3 Turbo (resolution-tiered T2V + I2V) ───────────
@@ -1647,7 +1633,7 @@ var { MODELS } = defineModels("kling", [
1647
1633
  modelId: "kling-v2-6",
1648
1634
  addedAt: "2026-02-11",
1649
1635
  estimatedTime: 60,
1650
- description: "Mature pipeline with audio, adjustable cfg, and standard/pro rendering."
1636
+ description: "Mature pipeline with audio and pro-tier rendering."
1651
1637
  },
1652
1638
  // ── Video: Kling Omni ─────────────────────────────────────────────
1653
1639
  {
@@ -1670,14 +1656,14 @@ var { MODELS } = defineModels("kling", [
1670
1656
  ...params.prompt({ maxLength: 2500 }),
1671
1657
  ...params.aspectRatio(["16:9", "9:16", "1:1"]),
1672
1658
  ...params.duration(V3_DURATIONS, 5),
1659
+ // Quality tier maps straight to the wire `mode`: 720p→std, 1080p→pro, 4k→4k.
1673
1660
  ...params.resolution(["720p", "1080p", "4k"], "720p"),
1674
- ...params.renderingSpeed([{ id: "std", label: "Standard" }, { id: "pro", label: "Pro" }], "std"),
1675
1661
  ...params.generateAudio(false),
1676
1662
  ...params.startFrame("First Frame"),
1677
1663
  ...params.endFrame("End Frame"),
1678
- // Backend states no explicit cap for omni `image_list`; 10 mirrors the
1679
- // omni-image contract. The worker stays the authoritative gate.
1680
- ...params.imageInput(10, "Reference Images"),
1664
+ // Vendor cap: reference images + frames + multi-image elements 7
1665
+ // (4 when a reference video is supplied).
1666
+ ...params.imageInput(7, "Reference Images"),
1681
1667
  ...params.videoInput("Reference Video", "reference", false),
1682
1668
  ...klingOmniReferType,
1683
1669
  ...klingKeepOriginalSound,
@@ -1689,6 +1675,15 @@ var { MODELS } = defineModels("kling", [
1689
1675
  { when: { videoUrl: { exists: true } }, then: {
1690
1676
  resolution: { allowed: ["720p", "1080p"], reason: "4K output is unavailable with a reference video." },
1691
1677
  generateAudio: { disabled: true, reason: "Kling disables generated sound when a reference video is supplied." }
1678
+ } },
1679
+ // Vendor: an end frame requires a first frame.
1680
+ { when: { startFrame: { exists: false } }, then: { endFrame: { disabled: true, reason: "End frame requires a first frame." } } },
1681
+ // Vendor: base-video editing cannot be combined with frames or multi-shot.
1682
+ { when: { referType: { is: "base" }, videoUrl: { exists: true } }, then: {
1683
+ startFrame: { disabled: true, reason: "Base video editing cannot be combined with frames." },
1684
+ endFrame: { disabled: true, reason: "Base video editing cannot be combined with frames." },
1685
+ multiShot: { disabled: true, reason: "Base video editing does not support multi-shot." },
1686
+ multiPrompt: { disabled: true, reason: "Base video editing does not support multi-shot." }
1692
1687
  } }
1693
1688
  ]
1694
1689
  },
@@ -1714,7 +1709,6 @@ var { MODELS } = defineModels("kling", [
1714
1709
  ...params.prompt({ maxLength: 2500 }),
1715
1710
  ...params.aspectRatio(["16:9", "9:16", "1:1"]),
1716
1711
  ...params.duration([5, 10], 5),
1717
- ...params.resolution(["720p", "1080p"], "720p"),
1718
1712
  ...params.renderingSpeed([{ id: "std", label: "Standard" }, { id: "pro", label: "Pro" }], "std"),
1719
1713
  ...params.generateAudio(false)
1720
1714
  }
@@ -1733,7 +1727,6 @@ var { MODELS } = defineModels("kling", [
1733
1727
  features: [feat("Image + Video", "input"), feat("Motion Transfer", "characteristic"), feat("V3", "resolution")],
1734
1728
  paramConfig: {
1735
1729
  ...params.prompt({ required: false, maxLength: 2500 }),
1736
- ...params.resolution(["720p", "1080p"], "720p"),
1737
1730
  ...params.renderingSpeed([{ id: "std", label: "Standard" }, { id: "pro", label: "Pro" }], "std"),
1738
1731
  ...klingCharacterOrientation,
1739
1732
  ...klingKeepOriginalSound,
@@ -1754,7 +1747,6 @@ var { MODELS } = defineModels("kling", [
1754
1747
  features: [feat("Image + Video", "input"), feat("Motion Transfer", "characteristic"), feat("2.6", "resolution")],
1755
1748
  paramConfig: {
1756
1749
  ...params.prompt({ required: false, maxLength: 2500 }),
1757
- ...params.resolution(["720p", "1080p"], "720p"),
1758
1750
  ...params.renderingSpeed([{ id: "std", label: "Standard" }, { id: "pro", label: "Pro" }], "std"),
1759
1751
  ...klingCharacterOrientation,
1760
1752
  ...klingKeepOriginalSound,
@@ -1777,10 +1769,10 @@ var { MODELS } = defineModels("kling", [
1777
1769
  ...params.prompt({ required: false, maxLength: 2500 }),
1778
1770
  ...params.renderingSpeed([{ id: "std", label: "Standard" }, { id: "pro", label: "Pro" }], "std"),
1779
1771
  ...params.imageInput(1, "Face Portrait", true),
1780
- // Swagger marks both sound_file and audio_id individually optional, but the
1781
- // backend requires at least one. UI keeps sound_file required; audio_id
1782
- // remains exposed as an additive alternative for SDK / batch users who
1783
- // pass a TTS-generated reference instead of an uploaded file.
1772
+ // Vendor: exactly ONE of sound_file / audio_id. The UI path keeps the
1773
+ // audio file required; audio_id stays an additive alternative for raw
1774
+ // API callers. The builder never emits both keys (file wins) and the
1775
+ // worker enforces the XOR for un-typed callers.
1784
1776
  ...params.audioInput("Speech Audio", true),
1785
1777
  audioId: {
1786
1778
  label: "TTS Audio ID",
@@ -1846,10 +1838,12 @@ var { MODELS } = defineModels("kling", [
1846
1838
  ...params.aspectRatio(KLING_IMAGE_AR),
1847
1839
  ...params.count([1, 2, 3, 4, 5, 6, 7, 8, 9]),
1848
1840
  ...params.negativePrompt(),
1849
- ...params.imageInput(1, "Restyle Image"),
1850
- ...params.imageWeight(0, 100, 50, 5),
1851
- ...klingHumanFidelity
1852
- }
1841
+ ...params.imageInput(1, "Restyle Image")
1842
+ },
1843
+ constraints: [
1844
+ // Vendor: negative prompts are not supported in image-to-image mode.
1845
+ { when: { imageUrls: { exists: true } }, then: { negativePrompt: { disabled: true, reason: "Negative prompt is ignored in image-to-image mode." } } }
1846
+ ]
1853
1847
  },
1854
1848
  // ── Image: Multi-Image-to-Image ─────────────────────────────────
1855
1849
  {
@@ -1919,13 +1913,20 @@ var { MODELS } = defineModels("kling", [
1919
1913
  default: "image_refer"
1920
1914
  }
1921
1915
  },
1922
- ...params.imageInput(4, "Reference Images (1st = frontal)", false),
1916
+ // Vendor: image_refer requires a frontal image + 1-3 extra angles
1917
+ // (min 2 uploads total — the builder enforces the minimum).
1918
+ ...params.imageInput(4, "Reference Images (1st = frontal, plus 1-3 angles)", false),
1923
1919
  ...params.videoInput("Reference Video", "reference", false),
1924
1920
  elementVoiceId: {
1925
- label: "Voice ID (video elements only)",
1921
+ label: "Voice ID (character/humanoid elements)",
1926
1922
  descriptor: { kind: "text" }
1927
1923
  }
1928
- }
1924
+ },
1925
+ constraints: [
1926
+ { when: { referenceType: { is: "video_refer" } }, then: { imageUrls: { disabled: true, reason: "Video reference uses the reference video, not images." } } },
1927
+ { when: { referenceType: { is: "image_refer" } }, then: { videoUrl: { disabled: true, reason: "Image reference uses reference images, not a video." } } },
1928
+ { when: { referenceType: { exists: false } }, then: { videoUrl: { disabled: true, reason: "Image reference uses reference images, not a video." } } }
1929
+ ]
1929
1930
  },
1930
1931
  {
1931
1932
  id: "kling-video-effects",
@@ -1936,7 +1937,7 @@ var { MODELS } = defineModels("kling", [
1936
1937
  mode: "video",
1937
1938
  inputType: "i2v",
1938
1939
  badge: ["new"],
1939
- description: "Apply 190+ visual effects to photos \u2014 single or dual-image scenes.",
1940
+ description: "Apply curated Kling visual effects to photos \u2014 single or dual-image scenes.",
1940
1941
  features: [feat("Image Input", "input"), feat("Video Effects", "characteristic")],
1941
1942
  paramConfig: {
1942
1943
  ...params.catalog("templateId", {
@@ -1944,7 +1945,8 @@ var { MODELS } = defineModels("kling", [
1944
1945
  source: { workflow: "kling/v1/catalog/templates" },
1945
1946
  default: "korean_baseball"
1946
1947
  }),
1947
- ...params.imageInput(2, "Effect Images", true)
1948
+ // Vendor: ≥300px per side (10MB / aspect-ratio checks stay vendor-side).
1949
+ ...params.imageInput(2, "Effect Images", true, "reference", { minSidePixels: 300 })
1948
1950
  }
1949
1951
  },
1950
1952
  // ── Audio ─────────────────────────────────────────────────────────
@@ -1974,21 +1976,96 @@ var { MODELS } = defineModels("kling", [
1974
1976
  description: "Extract or generate a matching audio track from an uploaded video.",
1975
1977
  features: [feat("Video Input", "input")],
1976
1978
  paramConfig: {
1977
- ...params.videoInput("Source Video")
1979
+ // Vendor: .mp4/.mov only, ≤100MB, 3.0-20.0s — duration and size are
1980
+ // enforced at upload; the 3s floor and container check stay vendor-side.
1981
+ ...params.videoInput("Source Video (3-20s, \u2264100MB)", "reference", true, 20, void 0, 100 * 1024 * 1024)
1978
1982
  }
1979
1983
  }
1980
1984
  ]);
1981
1985
 
1986
+ // src/core/catalogs.ts
1987
+ var metaString = (item, key) => {
1988
+ const v = item.meta?.[key];
1989
+ return typeof v === "string" ? v : void 0;
1990
+ };
1991
+ function toVoiceOption(item, provider) {
1992
+ return {
1993
+ id: item.id,
1994
+ name: item.name,
1995
+ description: item.description ?? "",
1996
+ tags: item.tags,
1997
+ provider,
1998
+ previewUrl: item.preview?.audioUrl
1999
+ };
2000
+ }
2001
+ function toAvatarOption(item, provider) {
2002
+ return {
2003
+ id: item.id,
2004
+ name: item.name,
2005
+ description: item.description ?? "",
2006
+ tags: item.tags,
2007
+ provider,
2008
+ previewImageUrl: item.preview?.imageUrl,
2009
+ previewVideoUrl: item.preview?.videoUrl,
2010
+ gender: metaString(item, "gender"),
2011
+ defaultVoiceId: metaString(item, "defaultVoiceId")
2012
+ };
2013
+ }
2014
+ var registry = /* @__PURE__ */ new Map();
2015
+ var keyOf = (s) => `${s.workflow} ${s.modelId ?? ""}`;
2016
+ var OPTION_ADAPTERS = {
2017
+ voiceId: toVoiceOption,
2018
+ videoId: toAvatarOption
2019
+ };
2020
+ function installHydratedCatalog(source, paramKey, items, provider, version) {
2021
+ const adapt = OPTION_ADAPTERS[paramKey];
2022
+ registry.set(keyOf(source), {
2023
+ paramKey,
2024
+ items,
2025
+ options: items.map((i) => ({ id: i.id, label: i.name })),
2026
+ catalogOptions: adapt ? items.map((i) => adapt(i, provider)) : items,
2027
+ version
2028
+ });
2029
+ }
2030
+ function getHydratedCatalog(source) {
2031
+ return registry.get(keyOf(source));
2032
+ }
2033
+ function getHydratedVoices() {
2034
+ const out = [];
2035
+ for (const c of registry.values()) {
2036
+ if (c.paramKey === "voiceId") out.push(...c.catalogOptions);
2037
+ }
2038
+ return out;
2039
+ }
2040
+
1982
2041
  // src/vendors/catalog/kling/payloads.ts
2042
+ function assertMultiPrompt(multiPrompt, totalDuration, model) {
2043
+ if (!multiPrompt?.length || multiPrompt.length > 6) {
2044
+ throw new ApiError(`${model}: multi-shot mode requires 1-6 storyboard entries in multiPrompt.`, { status: 400, code: "validation_error" });
2045
+ }
2046
+ const durations = multiPrompt.map((s) => Number(s.duration));
2047
+ if (durations.some((d) => !Number.isFinite(d) || d < 1 || d > totalDuration)) {
2048
+ throw new ApiError(`${model}: each storyboard duration must be between 1 and the total duration (${totalDuration}s).`, { status: 400, code: "validation_error" });
2049
+ }
2050
+ const sum = durations.reduce((a, b) => a + b, 0);
2051
+ if (sum !== totalDuration) {
2052
+ throw new ApiError(`${model}: storyboard durations must add up to the total duration (${sum}s \u2260 ${totalDuration}s).`, { status: 400, code: "validation_error" });
2053
+ }
2054
+ }
1983
2055
  var buildKlingV3Payload = (defaultMode = "std") => (input) => {
1984
- const hasEndFrame = !!(input.startFrame && input.endFrame && input.renderingSpeed !== "std");
1985
- const hasSound = !!input.generateAudio && !hasEndFrame;
1986
- const mode = defaultMode === "4k" ? "4k" : hasEndFrame ? "pro" : input.renderingSpeed ?? defaultMode;
2056
+ const hasEndFrame = !!(input.startFrame && input.endFrame);
2057
+ const hasSound = !!input.generateAudio;
2058
+ const mode = input.renderingSpeed ?? defaultMode;
2059
+ const totalDuration = input.duration ?? 5;
2060
+ if (input.multiShot && (input.shotType ?? "customize") !== "intelligence") {
2061
+ assertMultiPrompt(input.multiPrompt, totalDuration, "Kling V3");
2062
+ }
2063
+ const voiceList = hasSound && input.startFrame ? input.voiceList : void 0;
1987
2064
  return {
1988
2065
  ...input.multiShot ? {} : { prompt: input.prompt },
1989
2066
  aspect_ratio: input.aspectRatio ?? "16:9",
1990
2067
  // String(n) is just `string`; wire expects '3'|'5'|...|'15'. Narrowing cast.
1991
- duration: String(input.duration ?? 5),
2068
+ duration: String(totalDuration),
1992
2069
  model_name: "kling-v3",
1993
2070
  ...input.startFrame ? { image: input.startFrame } : {},
1994
2071
  ...hasEndFrame ? { image_tail: input.endFrame } : {},
@@ -1998,26 +2075,25 @@ var buildKlingV3Payload = (defaultMode = "std") => (input) => {
1998
2075
  ...input.multiShot != null ? { multi_shot: input.multiShot } : {},
1999
2076
  ...input.shotType ? { shot_type: input.shotType } : {},
2000
2077
  ...input.multiPrompt ? { multi_prompt: input.multiPrompt } : {},
2001
- // voice_list and element_list are mutex in I2V — voice_list wins
2002
- // when both are set (matches backend behavior, per the workflow schema).
2003
- ...input.voiceList ? { voice_list: input.voiceList } : {},
2004
- ...input.startFrame && input.elementList && !input.voiceList ? { element_list: input.elementList } : {},
2005
- ...input.startFrame && input.staticMask ? { static_mask: input.staticMask } : {}
2078
+ // voice_list requires sound 'on' and exists only on the I2V spec;
2079
+ // element_list is I2V-only and mutex with voice_list (voice_list wins).
2080
+ ...voiceList ? { voice_list: voiceList } : {},
2081
+ ...input.startFrame && input.elementList && !voiceList ? { element_list: input.elementList } : {}
2006
2082
  };
2007
2083
  };
2008
2084
  var buildKlingV3TurboPayload = (input) => ({
2009
- prompt: input.prompt,
2085
+ // Cap the folded string at the declared 2500-char prompt limit: the prompt
2086
+ // alone passed validation, so trimming can only ever hit the negative tail.
2087
+ prompt: input.negativePrompt ? `${input.prompt}. Avoid: ${input.negativePrompt}`.slice(0, 2500) : input.prompt,
2010
2088
  aspect_ratio: input.aspectRatio ?? "16:9",
2011
2089
  // String(n) is just `string`; wire expects '3'|'5'|...|'15'. Narrowing cast.
2012
2090
  duration: String(input.duration ?? 5),
2013
2091
  model_name: "kling-v3-turbo",
2014
2092
  resolution: input.resolution ?? "720p",
2015
- ...input.startFrame ? { image: input.startFrame } : {},
2016
- ...input.negativePrompt ? { negative_prompt: input.negativePrompt } : {},
2017
- ...input.startFrame && input.staticMask ? { static_mask: input.staticMask } : {}
2093
+ ...input.startFrame ? { image: input.startFrame } : {}
2018
2094
  });
2019
2095
  var buildKlingV26Payload = (input) => {
2020
- const hasEndFrame = !!(input.startFrame && input.endFrame && input.renderingSpeed !== "std");
2096
+ const hasEndFrame = !!(input.startFrame && input.endFrame);
2021
2097
  const hasSound = !!input.generateAudio && !hasEndFrame;
2022
2098
  return {
2023
2099
  prompt: input.prompt,
@@ -2028,8 +2104,7 @@ var buildKlingV26Payload = (input) => {
2028
2104
  ...hasEndFrame ? { image_tail: input.endFrame } : {},
2029
2105
  ...input.negativePrompt ? { negative_prompt: input.negativePrompt } : {},
2030
2106
  ...hasSound ? { sound: "on" } : {},
2031
- mode: "pro",
2032
- ...input.cfgScale !== void 0 ? { cfg_scale: input.cfgScale } : {}
2107
+ mode: "pro"
2033
2108
  };
2034
2109
  };
2035
2110
  var stringElementList = (list) => list?.length ? { element_list: list.map((e) => ({ element_id: String(e.element_id) })) } : {};
@@ -2046,15 +2121,19 @@ var buildOmniV3 = (input) => {
2046
2121
  }] : [];
2047
2122
  const hasBaseEdit = videoList[0]?.refer_type === "base";
2048
2123
  const hasReferenceVideo = videoList.length > 0;
2049
- const fourK = input.resolution === "4k" && !hasReferenceVideo;
2050
2124
  const hasSound = !!input.generateAudio && !hasReferenceVideo;
2125
+ const mode = input.resolution === "4k" ? hasReferenceVideo ? "pro" : "4k" : input.resolution === "1080p" ? "pro" : "std";
2126
+ const totalDuration = input.duration ?? 5;
2127
+ if (input.multiShot && !hasBaseEdit) {
2128
+ assertMultiPrompt(input.multiPrompt, totalDuration, "Kling V3 Omni");
2129
+ }
2051
2130
  return {
2052
2131
  ...input.multiShot ? {} : { prompt: input.prompt },
2053
2132
  model_name: "kling-v3-omni",
2054
2133
  ...hasBaseEdit || input.startFrame ? {} : { aspect_ratio: input.aspectRatio ?? "16:9" },
2055
2134
  // String(n) is just `string`; wire expects literal union. Narrowing cast.
2056
- ...hasBaseEdit ? {} : { duration: String(input.duration ?? 5) },
2057
- ...fourK ? { mode: "4k" } : input.renderingSpeed ? { mode: input.renderingSpeed } : {},
2135
+ ...hasBaseEdit ? {} : { duration: String(totalDuration) },
2136
+ mode,
2058
2137
  ...input.multiShot != null ? { multi_shot: input.multiShot } : {},
2059
2138
  ...input.shotType ? { shot_type: input.shotType } : {},
2060
2139
  ...input.multiPrompt ? { multi_prompt: input.multiPrompt } : {},
@@ -2088,8 +2167,7 @@ var buildMotionControl = (backendModelName) => (input) => ({
2088
2167
  var buildKlingAvatarPayload = (input) => ({
2089
2168
  // imageUrls is typed [string, ...string[]] (required tuple).
2090
2169
  image: input.imageUrls[0],
2091
- ...input.audioUrl ? { sound_file: input.audioUrl } : {},
2092
- ...input.audioId ? { audio_id: input.audioId } : {},
2170
+ ...input.audioUrl ? { sound_file: input.audioUrl } : input.audioId ? { audio_id: input.audioId } : {},
2093
2171
  prompt: input.prompt,
2094
2172
  ...input.renderingSpeed ? { mode: input.renderingSpeed } : {}
2095
2173
  });
@@ -2108,10 +2186,8 @@ var buildGenerations = (input) => {
2108
2186
  model_name: "kling-v2-1",
2109
2187
  n: input.count ?? 1,
2110
2188
  ...input.aspectRatio ? { aspect_ratio: input.aspectRatio } : {},
2111
- ...input.negativePrompt ? { negative_prompt: input.negativePrompt } : {},
2112
- ...hasImage ? { image: input.imageUrls[0] } : {},
2113
- ...hasImage && input.imageWeight != null ? { image_fidelity: input.imageWeight / 100 } : {},
2114
- ...input.humanFidelity != null ? { human_fidelity: input.humanFidelity } : {}
2189
+ ...input.negativePrompt && !hasImage ? { negative_prompt: input.negativePrompt } : {},
2190
+ ...hasImage ? { image: input.imageUrls[0] } : {}
2115
2191
  };
2116
2192
  };
2117
2193
  var buildMultiImage = (input) => ({
@@ -2125,26 +2201,36 @@ var buildMultiImage = (input) => ({
2125
2201
  });
2126
2202
  var buildKlingElementsPayload = (input) => {
2127
2203
  const isVideo = input.referenceType === "video_refer";
2204
+ if (isVideo && !input.videoUrl) {
2205
+ throw new ApiError("Kling Elements: video reference requires a reference video.", { status: 400, code: "validation_error" });
2206
+ }
2207
+ if (!isVideo && (input.imageUrls?.length ?? 0) < 2) {
2208
+ throw new ApiError("Kling Elements: image reference requires at least 2 images \u2014 a frontal image plus 1-3 additional angles.", { status: 400, code: "validation_error" });
2209
+ }
2128
2210
  return {
2129
2211
  element_name: input.elementName,
2130
2212
  element_description: input.elementDescription,
2131
2213
  reference_type: input.referenceType ?? "image_refer",
2132
- ...isVideo ? input.videoUrl ? { element_video_list: { refer_videos: [{ video_url: input.videoUrl }] } } : {} : input.imageUrls?.length ? {
2214
+ ...isVideo ? { element_video_list: { refer_videos: [{ video_url: input.videoUrl }] } } : {
2133
2215
  element_image_list: {
2134
2216
  frontal_image: input.imageUrls[0],
2135
- refer_images: (input.imageUrls.slice(1) ?? []).map((url) => ({ image_url: url }))
2217
+ refer_images: input.imageUrls.slice(1).map((url) => ({ image_url: url }))
2136
2218
  }
2137
- } : {},
2219
+ },
2138
2220
  ...input.elementVoiceId ? { element_voice_id: input.elementVoiceId } : {}
2139
2221
  };
2140
2222
  };
2141
2223
  var buildKlingVideoEffectsPayload = (input) => {
2142
- const isDualEffect = input.imageUrls && input.imageUrls.length >= 2;
2224
+ const scene = input.templateId ?? input.style;
2225
+ const catalogItem = getHydratedCatalog({ workflow: "kling/v1/catalog/templates" })?.items.find((item) => item.id === scene);
2226
+ const slots = typeof catalogItem?.meta?.imageSlots === "number" ? catalogItem.meta.imageSlots : scene && KLING_DUAL_IMAGE_EFFECTS.has(scene) ? 2 : 1;
2227
+ const uploaded = input.imageUrls?.length ?? 0;
2228
+ if (uploaded < slots) {
2229
+ throw new ApiError(`Kling Video Effects: the "${scene}" effect requires ${slots} image${slots > 1 ? "s" : ""} (got ${uploaded}).`, { status: 400, code: "validation_error" });
2230
+ }
2143
2231
  return {
2144
- // `style` carried the effect id before the catalog-bound `templateId` param
2145
- // (4.1); persisted history still sends it. Alias removed in the next major.
2146
- effect_scene: input.templateId ?? input.style,
2147
- ...isDualEffect ? { images: input.imageUrls.slice(0, 2) } : input.imageUrls?.[0] ? { image: input.imageUrls[0] } : {}
2232
+ effect_scene: scene,
2233
+ ...slots === 2 ? { images: input.imageUrls.slice(0, 2) } : { image: input.imageUrls[0] }
2148
2234
  };
2149
2235
  };
2150
2236
  var buildKlingT2APayload = (input) => ({
@@ -4531,61 +4617,6 @@ var { MODELS: MODELS14 } = defineModels("seedream", [
4531
4617
  }
4532
4618
  ]);
4533
4619
 
4534
- // src/core/catalogs.ts
4535
- var metaString = (item, key) => {
4536
- const v = item.meta?.[key];
4537
- return typeof v === "string" ? v : void 0;
4538
- };
4539
- function toVoiceOption(item, provider) {
4540
- return {
4541
- id: item.id,
4542
- name: item.name,
4543
- description: item.description ?? "",
4544
- tags: item.tags,
4545
- provider,
4546
- previewUrl: item.preview?.audioUrl
4547
- };
4548
- }
4549
- function toAvatarOption(item, provider) {
4550
- return {
4551
- id: item.id,
4552
- name: item.name,
4553
- description: item.description ?? "",
4554
- tags: item.tags,
4555
- provider,
4556
- previewImageUrl: item.preview?.imageUrl,
4557
- previewVideoUrl: item.preview?.videoUrl,
4558
- gender: metaString(item, "gender"),
4559
- defaultVoiceId: metaString(item, "defaultVoiceId")
4560
- };
4561
- }
4562
- var registry = /* @__PURE__ */ new Map();
4563
- var keyOf = (s) => `${s.workflow} ${s.modelId ?? ""}`;
4564
- var OPTION_ADAPTERS = {
4565
- voiceId: toVoiceOption,
4566
- videoId: toAvatarOption
4567
- };
4568
- function installHydratedCatalog(source, paramKey, items, provider, version) {
4569
- const adapt = OPTION_ADAPTERS[paramKey];
4570
- registry.set(keyOf(source), {
4571
- paramKey,
4572
- items,
4573
- options: items.map((i) => ({ id: i.id, label: i.name })),
4574
- catalogOptions: adapt ? items.map((i) => adapt(i, provider)) : items,
4575
- version
4576
- });
4577
- }
4578
- function getHydratedCatalog(source) {
4579
- return registry.get(keyOf(source));
4580
- }
4581
- function getHydratedVoices() {
4582
- const out = [];
4583
- for (const c of registry.values()) {
4584
- if (c.paramKey === "voiceId") out.push(...c.catalogOptions);
4585
- }
4586
- return out;
4587
- }
4588
-
4589
4620
  // src/core/voices.ts
4590
4621
  var DEFAULT_VOICE_ID = "JBFqnCBsd6RMkjVDRZzb";
4591
4622
  var GEMINI_DEFAULT_VOICE_ID = "Kore";
@@ -6141,8 +6172,9 @@ var buildElevenLabsDubbingPayload = (ctx) => ({
6141
6172
  target_lang: ctx.language
6142
6173
  });
6143
6174
  var buildElevenLabsVoiceRemixPayload = (ctx) => ({
6144
- voice_id: ctx.voiceId ?? DEFAULT_VOICE_ID,
6145
- voice_description: ctx.prompt
6175
+ voice_id: ctx.voiceId,
6176
+ voice_description: ctx.prompt,
6177
+ auto_generate_text: true
6146
6178
  });
6147
6179
  var buildElevenLabsVoiceDesignPayload = (modelId) => (ctx) => ({
6148
6180
  voice_description: ctx.prompt,
@@ -6153,8 +6185,11 @@ var buildElevenLabsVoicePreviewsPayload = (ctx) => ({
6153
6185
  voice_description: ctx.prompt,
6154
6186
  auto_generate_text: true
6155
6187
  });
6156
- var ttsParamConfig = (promptMaxLength) => ({
6157
- ...params.language(true),
6188
+ var ttsParamConfig = (promptMaxLength, withLanguage) => ({
6189
+ // language_code is honoured by eleven_v3 only — the vendor documents it as
6190
+ // "not supported for multilingual_v2 models" (silently ignored there).
6191
+ // No accent param anywhere: no builder ever read it.
6192
+ ...withLanguage ? params.language(false) : {},
6158
6193
  ...params.prompt({ maxLength: promptMaxLength }),
6159
6194
  ...params.voiceId([], DEFAULT_VOICE_ID, { catalog: { workflow: "elevenlabs/v1/catalog/voices" } })
6160
6195
  });
@@ -6173,7 +6208,7 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6173
6208
  badge: ["popular"],
6174
6209
  description: "Latest voice engine with expanded tone and pacing control.",
6175
6210
  features: [feat("Experimental", "characteristic"), feat("Creative Control", "characteristic")],
6176
- paramConfig: ttsParamConfig(5e3)
6211
+ paramConfig: ttsParamConfig(5e3, true)
6177
6212
  },
6178
6213
  {
6179
6214
  id: "eleven-multilingual-v2",
@@ -6188,7 +6223,7 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6188
6223
  badge: ["popular", "fast"],
6189
6224
  description: "Stable multilingual speech across 29+ languages with natural rhythm.",
6190
6225
  features: [feat("Stable", "characteristic"), feat("Professional", "characteristic")],
6191
- paramConfig: ttsParamConfig(1e4)
6226
+ paramConfig: ttsParamConfig(1e4, false)
6192
6227
  },
6193
6228
  // ── Sound Effects ─────────────────────────────────────────────────
6194
6229
  {
@@ -6202,9 +6237,9 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6202
6237
  mode: "audio",
6203
6238
  inputType: "sfx",
6204
6239
  badge: ["popular"],
6205
- description: "Create custom sound effects from a text description \u2014 up to 15 seconds.",
6240
+ description: "Create custom sound effects from a text description \u2014 up to 30 seconds.",
6206
6241
  features: [feat("Sound Effects", "characteristic")],
6207
- paramConfig: { ...params.prompt(), ...params.duration([1, 3, 5, 8, 10, 15], 5) }
6242
+ paramConfig: { ...params.prompt(), ...params.durationRange(0.5, 30, 5, 0.5) }
6208
6243
  },
6209
6244
  // ── Music ─────────────────────────────────────────────────────────
6210
6245
  {
@@ -6258,7 +6293,6 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6258
6293
  paramConfig: {
6259
6294
  ...params.audioInput("Speech Audio", true),
6260
6295
  ...params.voiceId([], DEFAULT_VOICE_ID, { catalog: { workflow: "elevenlabs/v1/catalog/voices" } }),
6261
- ...params.language(true),
6262
6296
  ...p.boolean("removeBackgroundNoise", false, "Remove Background Noise")
6263
6297
  }
6264
6298
  },
@@ -6289,7 +6323,12 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6289
6323
  features: [feat("Multilingual", "characteristic"), feat("Dubbing", "characteristic")],
6290
6324
  paramConfig: {
6291
6325
  ...params.audioInput("Source Audio", true),
6292
- ...params.language(true)
6326
+ // target_lang is the vendor's only required field (ISO 639-1/639-3 code).
6327
+ language: {
6328
+ label: "Target Language (ISO 639 code)",
6329
+ required: true,
6330
+ descriptor: { kind: "text", placeholder: "e.g. es, fr, de" }
6331
+ }
6293
6332
  }
6294
6333
  },
6295
6334
  // ── Voice Design ────────────────────────────────────────────────
@@ -6306,8 +6345,14 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6306
6345
  description: "Remix voice characteristics by describing the desired vocal style.",
6307
6346
  features: [feat("Voice Design", "characteristic"), feat("Remix", "characteristic")],
6308
6347
  paramConfig: {
6309
- ...params.voiceId([], DEFAULT_VOICE_ID, { catalog: { workflow: "elevenlabs/v1/catalog/voices" } }),
6310
- ...params.prompt({ maxLength: 1e3 })
6348
+ // Vendor: "Only your own custom voices can be remixed" the premade
6349
+ // voices catalog cannot serve this model, so voiceId is a plain id input.
6350
+ voiceId: {
6351
+ label: "Voice ID (a custom voice from your workspace)",
6352
+ required: true,
6353
+ descriptor: { kind: "text", placeholder: "Premade/catalog voices are rejected by ElevenLabs" }
6354
+ },
6355
+ ...params.prompt({ minLength: 5, maxLength: 1e3 })
6311
6356
  }
6312
6357
  },
6313
6358
  {
@@ -6322,7 +6367,7 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6322
6367
  inputType: "tts",
6323
6368
  description: "Design a new voice from a text description using v3 engine.",
6324
6369
  features: [feat("Voice Design", "characteristic"), feat("Preview", "characteristic")],
6325
- paramConfig: { ...params.prompt({ maxLength: 1e3 }) }
6370
+ paramConfig: { ...params.prompt({ minLength: 20, maxLength: 1e3 }) }
6326
6371
  },
6327
6372
  {
6328
6373
  id: "eleven-voice-design-v2",
@@ -6336,7 +6381,7 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6336
6381
  inputType: "tts",
6337
6382
  description: "Design a new voice from a text description with multilingual support.",
6338
6383
  features: [feat("Voice Design", "characteristic"), feat("Multilingual", "characteristic"), feat("Preview", "characteristic")],
6339
- paramConfig: { ...params.prompt({ maxLength: 1e3 }) }
6384
+ paramConfig: { ...params.prompt({ minLength: 20, maxLength: 1e3 }) }
6340
6385
  },
6341
6386
  {
6342
6387
  id: "eleven-voice-create",
@@ -6349,7 +6394,7 @@ var { MODELS: MODELS24 } = defineModels("elevenlabs", [
6349
6394
  inputType: "tts",
6350
6395
  description: "Generate voice previews from a description to audition before committing.",
6351
6396
  features: [feat("Voice Design", "characteristic"), feat("Preview", "characteristic")],
6352
- paramConfig: { ...params.prompt({ maxLength: 1e3 }) }
6397
+ paramConfig: { ...params.prompt({ minLength: 20, maxLength: 1e3 }) }
6353
6398
  }
6354
6399
  ]);
6355
6400
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "5.26.0",
3
+ "version": "5.26.2",
4
4
  "type": "module",
5
5
  "description": "Type-safe SDK for 100+ AI models — image, video, audio, and text generation with Picsart",
6
6
  "license": "MIT",