@marlinjai/studio-mcp 0.8.0 → 0.10.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/cli.js CHANGED
@@ -298,7 +298,12 @@ var StudioClient = class {
298
298
  getWorkflowDocument(savedId2, opts = {}) {
299
299
  return this.json("GET", `/api/v1/workflows/${encodeURIComponent(savedId2)}${projectQuery(opts.projectId)}`);
300
300
  }
301
- /** Create a document by applying `ops` to an empty one (the same code path as apply). */
301
+ /**
302
+ * Create a document by applying `ops` to an empty one (the same code path as
303
+ * apply). 201 created; 200 with `replayed: true` when a create with this
304
+ * idempotencyKey already made it; 409 `idempotency_mismatch` when that key
305
+ * made a different one.
306
+ */
302
307
  createWorkflow(body) {
303
308
  return this.json("POST", "/api/v1/workflows", { json: body });
304
309
  }
@@ -582,7 +587,10 @@ var ROUTES = [
582
587
  "720p": "fal/kling-o3-standard-image-to-video",
583
588
  "1080p": "fal/kling-o3-pro-image-to-video"
584
589
  },
585
- label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)"
590
+ label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)",
591
+ // Only the Pro tier of reference-to-video is in the catalog: a 720p job
592
+ // with references runs on KIE alone.
593
+ withReferences: { "1080p": "fal/kling-o3-pro-reference-to-video" }
586
594
  }
587
595
  },
588
596
  {
@@ -1166,14 +1174,36 @@ var CATALOG_ENTRIES = [
1166
1174
  description: "Google Gemini Omni 1.1 Flash via KIE, first-and-last-frame mode. A start frame and an optional end frame, 4, 6, 8 or 10 s, 720p to 4K, 16:9 or 9:16. KIE refuses registered characters in this mode, so identity comes from the frames alone. Accepted a minted character's photoreal stills on 2026-09-24 (set 9:16 for a portrait still: it defaults to 16:9 and crops). No fal equivalent.",
1167
1175
  capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
1168
1176
  },
1177
+ {
1178
+ id: "kie/gemini-omni-flash-1-1-reference-to-video",
1179
+ provider: "kie",
1180
+ modality: "video",
1181
+ task: "image-to-video",
1182
+ label: "Gemini Omni 1.1 Flash with references (KIE)",
1183
+ description: "Google Gemini Omni 1.1 Flash via KIE in its reference mode: the start keyframe and up to 6 character images wired into the reference port go in as up to 7 reference images, and the prompt names the keyframe as the exact scene and first frame and each character's images in order. KIE does not lock the first frame in this mode (it refuses a first frame together with references), so the clip follows the keyframe closely but may not start on it pixel for pixel; for a locked first frame with references use Kling O3. 4, 6, 8 or 10 s, 720p to 4K, 16:9 or 9:16. No end frame.",
1184
+ // `characterReferences` mirrors
1185
+ // KIE_VIDEO_SPECS['google/gemini-omni-flash-1-1/references'] (checked by a spec).
1186
+ capabilities: {
1187
+ needsImageInput: true,
1188
+ maxInputImages: 1,
1189
+ characterReferences: { maxElements: 6, minImagesPerElement: 1, maxImagesPerElement: 6, maxTotalImages: 6 }
1190
+ }
1191
+ },
1169
1192
  {
1170
1193
  id: "kie/kling-o3-image-to-video",
1171
1194
  provider: "kie",
1172
1195
  modality: "video",
1173
1196
  task: "image-to-video",
1174
1197
  label: "Kling O3 (KIE)",
1175
- description: "Kuaishou Kling O3 (KIE calls it Kling 3.0 Omni) via KIE. A start frame and an optional end frame, 3 to 15 s, 720p to 4K in the start frame's shape, silent unless the job sets generateAudio. Accepted a minted character's photoreal stills on 2026-09-24.",
1176
- capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
1198
+ description: "Kuaishou Kling O3 (KIE calls it Kling 3.0 Omni) via KIE. A start frame and an optional end frame, 3 to 15 s, 720p to 4K in the start frame's shape, silent unless the job sets generateAudio. Accepted a minted character's photoreal stills on 2026-09-24. Holds a character's identity through the clip from character references wired into its reference port: up to 3 characters, 2 to 4 images each (frontal view first).",
1199
+ // `characterReferences` mirrors KIE_VIDEO_SPECS['kling-3.0-omni/image-to-video']
1200
+ // (catalog.spec checks they agree).
1201
+ capabilities: {
1202
+ needsImageInput: true,
1203
+ maxInputImages: 1,
1204
+ acceptsEndFrame: true,
1205
+ characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 12 }
1206
+ }
1177
1207
  },
1178
1208
  {
1179
1209
  id: "fal/grok-imagine-1-5-image-to-video",
@@ -1221,6 +1251,22 @@ var CATALOG_ENTRIES = [
1221
1251
  description: "Kuaishou Kling O3 Pro via fal, a fallback for the KIE entry. A start frame and an optional end frame, 3 to 15 s, in the start frame's shape at the tier's size, silent unless the job sets generateAudio. Not yet tested with a minted character.",
1222
1252
  capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
1223
1253
  },
1254
+ {
1255
+ id: "fal/kling-o3-pro-reference-to-video",
1256
+ provider: "fal",
1257
+ modality: "video",
1258
+ task: "image-to-video",
1259
+ label: "Kling O3 Pro with character references (fal)",
1260
+ description: "Kuaishou Kling O3 Pro reference-to-video via fal, the fal fallback for Kling O3 with character references. A start frame, an optional end frame and up to 3 characters wired into the reference port (2 to 4 images each, frontal view first, 7 images in all), 3 to 15 s at the Pro tier's size. Renders at a set aspect ratio (16:9, 9:16 or 1:1, 16:9 unless set), so set the ratio of the start frame. Silent unless the job sets generateAudio.",
1261
+ // `characterReferences` mirrors FAL_CHARACTER_REFERENCE_LIMITS (catalog.spec
1262
+ // checks they agree).
1263
+ capabilities: {
1264
+ needsImageInput: true,
1265
+ maxInputImages: 1,
1266
+ acceptsEndFrame: true,
1267
+ characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 7 }
1268
+ }
1269
+ },
1224
1270
  {
1225
1271
  id: "fal/ltx-2-5-fast-image-to-video",
1226
1272
  provider: "fal",
@@ -1539,6 +1585,21 @@ function routeEntry(id) {
1539
1585
  function tryGetModel(id) {
1540
1586
  return MODEL_CATALOG.find((m) => m.id === id) ?? routeEntry(id);
1541
1587
  }
1588
+ function omniReferencesPrompt(prompt, elements) {
1589
+ const parts = ["Image 1 is the exact scene and the first frame of the video: start the clip on it and keep its setting, framing and light."];
1590
+ let next = 2;
1591
+ for (const [i, e] of elements.entries()) {
1592
+ const count2 = 1 + e.referenceImageUrls.length;
1593
+ const span = count2 === 1 ? `Image ${next} shows` : `Images ${next} to ${next + count2 - 1} show`;
1594
+ parts.push(
1595
+ `${span} character ${i + 1}${count2 > 1 ? ", the first of them from the front" : ""}; keep their face, hair and clothing exactly as shown for the whole clip.`
1596
+ );
1597
+ next += count2;
1598
+ }
1599
+ const text = prompt?.trim() ?? "";
1600
+ return text ? `${parts.join(" ")} ${text}` : parts.join(" ");
1601
+ }
1602
+ var OMNI_MAX_REFERENCE_IMAGES = 7;
1542
1603
  function veoSpec(model, label) {
1543
1604
  return {
1544
1605
  family: "veo",
@@ -1756,6 +1817,44 @@ var KIE_VIDEO_SPECS = {
1756
1817
  ...i.seed !== void 0 ? { seed: i.seed } : {}
1757
1818
  })
1758
1819
  },
1820
+ // Gemini Omni 1.1 Flash in its REFERENCE mode: up to seven `image_urls`
1821
+ // ("Multiple reference images can be uploaded to provide references for
1822
+ // characters, scenes, styles, or storyboards"; "Maximum of 7 images"), and
1823
+ // no locked first frame, because KIE makes `first_frame_url` "mutually
1824
+ // exclusive with `image_urls`" (docs.kie.ai, read 2026-10-24). The start
1825
+ // keyframe goes first among the images and the prompt names it the exact
1826
+ // scene and first frame (`omniReferencesPrompt`); each character's views
1827
+ // follow. Same model, same price as the first-frame mode.
1828
+ "google/gemini-omni-flash-1-1/references": {
1829
+ family: "job",
1830
+ label: "Gemini Omni 1.1 Flash with references",
1831
+ upstreamModel: "google/gemini-omni-flash-1-1",
1832
+ endFrame: false,
1833
+ aspectRatios: ["16:9", "9:16"],
1834
+ resolutions: ["720p", "1080p", "4k"],
1835
+ durations: { values: [4, 6, 8, 10] },
1836
+ defaultSeconds: 8,
1837
+ defaultResolution: "720p",
1838
+ audioSwitch: false,
1839
+ defaultAudio: false,
1840
+ // Six character images, because the start keyframe takes one of the seven.
1841
+ characterReferences: {
1842
+ maxElements: 6,
1843
+ minImagesPerElement: 1,
1844
+ maxImagesPerElement: 6,
1845
+ maxTotalImages: OMNI_MAX_REFERENCE_IMAGES - 1
1846
+ },
1847
+ maxPromptChars: 2e4,
1848
+ referencesPrompt: omniReferencesPrompt,
1849
+ build: (i) => ({
1850
+ prompt: i.prompt,
1851
+ image_urls: [i.start, ...(i.elements ?? []).flatMap((e) => [e.frontalImageUrl, ...e.referenceImageUrls])],
1852
+ duration: String(i.seconds),
1853
+ resolution: i.resolution,
1854
+ ...i.aspectRatio ? { aspect_ratio: i.aspectRatio } : {},
1855
+ ...i.seed !== void 0 ? { seed: i.seed } : {}
1856
+ })
1857
+ },
1759
1858
  "kling-3.0-omni/image-to-video": {
1760
1859
  family: "job",
1761
1860
  label: "Kling O3",
@@ -1768,12 +1867,28 @@ var KIE_VIDEO_SPECS = {
1768
1867
  defaultResolution: "720p",
1769
1868
  audioSwitch: true,
1770
1869
  defaultAudio: false,
1870
+ // KIE's "Single First Frame" and "First and Last Frames" request shapes
1871
+ // both carry `elements`: "up to 3 subjects", and "for a multi-image
1872
+ // subject, provide 2 to 4 images" (docs.kie.ai, kling-3.0-omni
1873
+ // image-to-video, read 2026-10-23). Each element needs a name the prompt
1874
+ // can mention as `@name` and a description.
1875
+ characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 12 },
1876
+ maxPromptChars: 3072,
1771
1877
  build: (i) => ({
1772
1878
  prompt: i.prompt,
1773
1879
  image_urls: i.end ? [i.start, i.end] : [i.start],
1774
1880
  duration: i.seconds,
1775
1881
  resolution: i.resolution,
1776
- audio: i.audio
1882
+ audio: i.audio,
1883
+ // Named Element1, Element2, ... so one prompt convention (`@Element1`)
1884
+ // holds on KIE and on the fal twin alike.
1885
+ ...i.elements && i.elements.length > 0 ? {
1886
+ elements: i.elements.map((e, n) => ({
1887
+ name: `Element${n + 1}`,
1888
+ description: `character ${n + 1}`,
1889
+ element_input_urls: [e.frontalImageUrl, ...e.referenceImageUrls]
1890
+ }))
1891
+ } : {}
1777
1892
  })
1778
1893
  }
1779
1894
  };
@@ -1800,6 +1915,10 @@ var KLING_26_I2V_ENDPOINT = "fal-ai/kling-video/v2.6/pro/image-to-video";
1800
1915
  var KLING_O3_STANDARD_I2V_ENDPOINT = "fal-ai/kling-video/o3/standard/image-to-video";
1801
1916
  var KLING_O3_PRO_I2V_ENDPOINT = "fal-ai/kling-video/o3/pro/image-to-video";
1802
1917
  var KLING_O3_I2V_ENDPOINTS = [KLING_O3_STANDARD_I2V_ENDPOINT, KLING_O3_PRO_I2V_ENDPOINT];
1918
+ var KLING_O3_PRO_R2V_ENDPOINT = "fal-ai/kling-video/o3/pro/reference-to-video";
1919
+ var FAL_CHARACTER_REFERENCE_LIMITS = {
1920
+ [KLING_O3_PRO_R2V_ENDPOINT]: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 7 }
1921
+ };
1803
1922
  var LTX_25_FAST_I2V_ENDPOINT = "lightricks/ltx-2.5/image-to-video/fast";
1804
1923
  var LTX_25_PRO_I2V_ENDPOINT = "lightricks/ltx-2.5/image-to-video/pro";
1805
1924
  var LTX_25_I2V_ENDPOINTS = [LTX_25_FAST_I2V_ENDPOINT, LTX_25_PRO_I2V_ENDPOINT];
@@ -1828,7 +1947,8 @@ var VIDEO_FIXED_RESOLUTION = {
1828
1947
  [KLING_26_I2V_ENDPOINT]: "1080p",
1829
1948
  // Not a resolution the caller picks: Kling O3's tier sets the size.
1830
1949
  [KLING_O3_STANDARD_I2V_ENDPOINT]: "fixed",
1831
- [KLING_O3_PRO_I2V_ENDPOINT]: "fixed"
1950
+ [KLING_O3_PRO_I2V_ENDPOINT]: "fixed",
1951
+ [KLING_O3_PRO_R2V_ENDPOINT]: "fixed"
1832
1952
  };
1833
1953
  var VIDEO_PINNED_DEFAULT_SECONDS = {
1834
1954
  [GROK_IMAGINE_I2V_ENDPOINT]: 5,
@@ -1842,6 +1962,7 @@ var VIDEO_PINNED_DEFAULT_SECONDS = {
1842
1962
  [KLING_26_I2V_ENDPOINT]: 5,
1843
1963
  [KLING_O3_STANDARD_I2V_ENDPOINT]: 5,
1844
1964
  [KLING_O3_PRO_I2V_ENDPOINT]: 5,
1965
+ [KLING_O3_PRO_R2V_ENDPOINT]: 5,
1845
1966
  // LTX-2.5 defaults to "auto", a length nobody can price up front; 6 s is its
1846
1967
  // shortest clip on both tiers.
1847
1968
  [LTX_25_FAST_I2V_ENDPOINT]: 6,
@@ -1891,6 +2012,8 @@ var VIDEO_ALLOWED_VALUES = {
1891
2012
  },
1892
2013
  [KLING_26_I2V_ENDPOINT]: { durationSeconds: { values: [5, 10] } },
1893
2014
  ...Object.fromEntries(KLING_O3_I2V_ENDPOINTS.map((e) => [e, { durationSeconds: { min: 3, max: 15 } }])),
2015
+ // Reference-to-video renders at a set ratio (default 16:9), not the frame's.
2016
+ [KLING_O3_PRO_R2V_ENDPOINT]: { aspectRatio: ["16:9", "9:16", "1:1"], durationSeconds: { min: 3, max: 15 } },
1894
2017
  [LTX_25_FAST_I2V_ENDPOINT]: {
1895
2018
  aspectRatio: ["auto", "16:9", "9:16"],
1896
2019
  // fal also renders 1440p, which the canvas does not offer.
@@ -1949,6 +2072,8 @@ var VIDEO_UNSUPPORTED_PARAMS = {
1949
2072
  [WAN_30_I2V_ENDPOINT]: ["negativePrompt"],
1950
2073
  [KLING_26_I2V_ENDPOINT]: ["resolution", "aspectRatio", "seed"],
1951
2074
  ...Object.fromEntries(KLING_O3_I2V_ENDPOINTS.map((e) => [e, ["resolution", "aspectRatio", "seed", "negativePrompt"]])),
2075
+ // Its tier sets the size; it takes an aspect ratio, but no seed or negative prompt.
2076
+ [KLING_O3_PRO_R2V_ENDPOINT]: ["resolution", "seed", "negativePrompt"],
1952
2077
  ...Object.fromEntries(LTX_25_I2V_ENDPOINTS.map((e) => [e, ["seed", "negativePrompt"]]))
1953
2078
  };
1954
2079
  var ROWS = [
@@ -2661,8 +2786,10 @@ function searchMeshyAnimations(query, limit = 25) {
2661
2786
  }
2662
2787
  return out;
2663
2788
  }
2664
- var PORT_TYPES = ["text", "image", "video", "mask", "mesh3d", "audio", "json"];
2665
- var INPUT_PORT_TYPES = PORT_TYPES.filter((p) => p !== "mask");
2789
+ var PORT_TYPES = ["text", "image", "video", "mask", "mesh3d", "audio", "json", "reference"];
2790
+ var INPUT_PORT_TYPES = PORT_TYPES.filter(
2791
+ (p) => p !== "mask" && p !== "reference"
2792
+ );
2666
2793
 
2667
2794
  // src/rig.ts
2668
2795
  var RIG_MODEL_ID = "fal/meshy-rigging";
@@ -2727,8 +2854,13 @@ var MODEL_TASKS = [
2727
2854
  "background-remove",
2728
2855
  "segmentation"
2729
2856
  ];
2730
- var PORT_TYPES2 = ["text", "image", "video", "mask", "mesh3d", "audio", "json"];
2731
- var INPUT_PORT_TYPES2 = PORT_TYPES2.filter((p) => p !== "mask");
2857
+ var PORT_TYPES2 = ["text", "image", "video", "mask", "mesh3d", "audio", "json", "reference"];
2858
+ function portContent(port) {
2859
+ return port === "reference" ? "image" : port;
2860
+ }
2861
+ var INPUT_PORT_TYPES2 = PORT_TYPES2.filter(
2862
+ (p) => p !== "mask" && p !== "reference"
2863
+ );
2732
2864
  var TASK_PORTS = {
2733
2865
  // GENERATE: born from text (or a mesh prompt), no upstream asset input.
2734
2866
  "text-to-image": { inputs: ["text"], output: "image" },
@@ -2740,7 +2872,11 @@ var TASK_PORTS = {
2740
2872
  // Two image inputs (garment + person); the port type set is coarse (both are
2741
2873
  // 'image'), the two-image contract lives in the fal adapter, not the ports.
2742
2874
  "virtual-try-on": { inputs: ["image"], output: "image" },
2743
- "image-to-video": { inputs: ["image"], output: "video" },
2875
+ // The `image` port takes the start frame (and the end frame, or a keyframe
2876
+ // timeline); the `reference` port takes character reference images for the
2877
+ // models that hold identity from them (Kling elements). A model without that
2878
+ // capability gives the reference port no wires at all (`portCardinality`).
2879
+ "image-to-video": { inputs: ["image", "reference"], output: "video" },
2744
2880
  // Video-to-video (character replace): a source video plus ONE reference image
2745
2881
  // (the person to swap in). The two-input contract lives in the fal adapter.
2746
2882
  "video-to-video": { inputs: ["video", "image"], output: "video" },
@@ -3105,7 +3241,10 @@ var ROUTES2 = [
3105
3241
  "720p": "fal/kling-o3-standard-image-to-video",
3106
3242
  "1080p": "fal/kling-o3-pro-image-to-video"
3107
3243
  },
3108
- label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)"
3244
+ label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)",
3245
+ // Only the Pro tier of reference-to-video is in the catalog: a 720p job
3246
+ // with references runs on KIE alone.
3247
+ withReferences: { "1080p": "fal/kling-o3-pro-reference-to-video" }
3109
3248
  }
3110
3249
  },
3111
3250
  {
@@ -3689,14 +3828,36 @@ var CATALOG_ENTRIES2 = [
3689
3828
  description: "Google Gemini Omni 1.1 Flash via KIE, first-and-last-frame mode. A start frame and an optional end frame, 4, 6, 8 or 10 s, 720p to 4K, 16:9 or 9:16. KIE refuses registered characters in this mode, so identity comes from the frames alone. Accepted a minted character's photoreal stills on 2026-09-24 (set 9:16 for a portrait still: it defaults to 16:9 and crops). No fal equivalent.",
3690
3829
  capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
3691
3830
  },
3831
+ {
3832
+ id: "kie/gemini-omni-flash-1-1-reference-to-video",
3833
+ provider: "kie",
3834
+ modality: "video",
3835
+ task: "image-to-video",
3836
+ label: "Gemini Omni 1.1 Flash with references (KIE)",
3837
+ description: "Google Gemini Omni 1.1 Flash via KIE in its reference mode: the start keyframe and up to 6 character images wired into the reference port go in as up to 7 reference images, and the prompt names the keyframe as the exact scene and first frame and each character's images in order. KIE does not lock the first frame in this mode (it refuses a first frame together with references), so the clip follows the keyframe closely but may not start on it pixel for pixel; for a locked first frame with references use Kling O3. 4, 6, 8 or 10 s, 720p to 4K, 16:9 or 9:16. No end frame.",
3838
+ // `characterReferences` mirrors
3839
+ // KIE_VIDEO_SPECS['google/gemini-omni-flash-1-1/references'] (checked by a spec).
3840
+ capabilities: {
3841
+ needsImageInput: true,
3842
+ maxInputImages: 1,
3843
+ characterReferences: { maxElements: 6, minImagesPerElement: 1, maxImagesPerElement: 6, maxTotalImages: 6 }
3844
+ }
3845
+ },
3692
3846
  {
3693
3847
  id: "kie/kling-o3-image-to-video",
3694
3848
  provider: "kie",
3695
3849
  modality: "video",
3696
3850
  task: "image-to-video",
3697
3851
  label: "Kling O3 (KIE)",
3698
- description: "Kuaishou Kling O3 (KIE calls it Kling 3.0 Omni) via KIE. A start frame and an optional end frame, 3 to 15 s, 720p to 4K in the start frame's shape, silent unless the job sets generateAudio. Accepted a minted character's photoreal stills on 2026-09-24.",
3699
- capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
3852
+ description: "Kuaishou Kling O3 (KIE calls it Kling 3.0 Omni) via KIE. A start frame and an optional end frame, 3 to 15 s, 720p to 4K in the start frame's shape, silent unless the job sets generateAudio. Accepted a minted character's photoreal stills on 2026-09-24. Holds a character's identity through the clip from character references wired into its reference port: up to 3 characters, 2 to 4 images each (frontal view first).",
3853
+ // `characterReferences` mirrors KIE_VIDEO_SPECS['kling-3.0-omni/image-to-video']
3854
+ // (catalog.spec checks they agree).
3855
+ capabilities: {
3856
+ needsImageInput: true,
3857
+ maxInputImages: 1,
3858
+ acceptsEndFrame: true,
3859
+ characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 12 }
3860
+ }
3700
3861
  },
3701
3862
  {
3702
3863
  id: "fal/grok-imagine-1-5-image-to-video",
@@ -3744,6 +3905,22 @@ var CATALOG_ENTRIES2 = [
3744
3905
  description: "Kuaishou Kling O3 Pro via fal, a fallback for the KIE entry. A start frame and an optional end frame, 3 to 15 s, in the start frame's shape at the tier's size, silent unless the job sets generateAudio. Not yet tested with a minted character.",
3745
3906
  capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
3746
3907
  },
3908
+ {
3909
+ id: "fal/kling-o3-pro-reference-to-video",
3910
+ provider: "fal",
3911
+ modality: "video",
3912
+ task: "image-to-video",
3913
+ label: "Kling O3 Pro with character references (fal)",
3914
+ description: "Kuaishou Kling O3 Pro reference-to-video via fal, the fal fallback for Kling O3 with character references. A start frame, an optional end frame and up to 3 characters wired into the reference port (2 to 4 images each, frontal view first, 7 images in all), 3 to 15 s at the Pro tier's size. Renders at a set aspect ratio (16:9, 9:16 or 1:1, 16:9 unless set), so set the ratio of the start frame. Silent unless the job sets generateAudio.",
3915
+ // `characterReferences` mirrors FAL_CHARACTER_REFERENCE_LIMITS (catalog.spec
3916
+ // checks they agree).
3917
+ capabilities: {
3918
+ needsImageInput: true,
3919
+ maxInputImages: 1,
3920
+ acceptsEndFrame: true,
3921
+ characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 7 }
3922
+ }
3923
+ },
3747
3924
  {
3748
3925
  id: "fal/ltx-2-5-fast-image-to-video",
3749
3926
  provider: "fal",
@@ -4127,6 +4304,9 @@ function portBinding(task, port) {
4127
4304
  if (port === "image" && (task === "image-to-3d" || task === "multiview-to-3d" || task === "image-to-video" || task === "image-to-text" || task === "image-to-json")) {
4128
4305
  return { key: "inputImageUrl", path: "url" };
4129
4306
  }
4307
+ if (port === "reference" && task === "image-to-video") {
4308
+ return { key: "referenceImageUrls", path: "url", wrap: "array" };
4309
+ }
4130
4310
  if (port === "mesh3d" && (task === "remesh" || task === "texture" || task === "rig")) {
4131
4311
  return { key: "parentAssetId", path: "assetId" };
4132
4312
  }
@@ -4160,7 +4340,7 @@ function portBinding(task, port) {
4160
4340
  return null;
4161
4341
  }
4162
4342
  function canConnect(sourceOut, targetTask, targetPort) {
4163
- if (sourceOut !== targetPort) return false;
4343
+ if (sourceOut !== portContent(targetPort)) return false;
4164
4344
  return portBinding(targetTask, targetPort) !== null;
4165
4345
  }
4166
4346
  function portCardinality(task, port, model) {
@@ -4169,11 +4349,18 @@ function portCardinality(task, port, model) {
4169
4349
  if (port === "image" && task === "image-to-video") {
4170
4350
  return modelAcceptsKeyframes(model) ? "many" : "two";
4171
4351
  }
4352
+ if (port === "reference") {
4353
+ return modelCharacterReferences(model) ? "many" : "none";
4354
+ }
4172
4355
  if (port === "image" && task === "video-to-video") {
4173
4356
  return modelTakesSeveralReferences(model) ? "many" : "one";
4174
4357
  }
4175
4358
  return "one";
4176
4359
  }
4360
+ function modelCharacterReferences(model) {
4361
+ if (!model) return null;
4362
+ return tryGetModel2(model)?.capabilities?.characterReferences ?? null;
4363
+ }
4177
4364
  function modelTakesSeveralReferences(model) {
4178
4365
  if (!model) return false;
4179
4366
  const cap = tryGetModel2(model)?.capabilities?.maxInputImages;
@@ -4225,6 +4412,15 @@ function targetCardinality(node, port) {
4225
4412
  function slotRefusal(node, port, wired) {
4226
4413
  const cardinality = targetCardinality(node, port);
4227
4414
  let limit = cardinalityLimit(cardinality);
4415
+ if (port === "reference" && node.kind === "task") {
4416
+ const refs = modelCharacterReferences(node.model);
4417
+ if (refs) limit = Math.min(limit, refs.maxTotalImages);
4418
+ if (wired < limit) return null;
4419
+ if (!refs) {
4420
+ return `node "${node.id}" (${node.model || "no model"}) takes no character references; pick a model that holds identity from reference images (Kling elements) or remove the reference wires`;
4421
+ }
4422
+ return `node "${node.id}" (${node.model}) takes at most ${limit} character reference images in all`;
4423
+ }
4228
4424
  if (cardinality === "many" && node.kind === "task" && node.model) {
4229
4425
  const cap = tryGetModel2(node.model)?.capabilities?.maxInputImages;
4230
4426
  if (typeof cap === "number" && cap > 0) limit = Math.min(limit, cap);
@@ -4239,7 +4435,7 @@ function slotRefusal(node, port, wired) {
4239
4435
  function wireLegality(source, target, port) {
4240
4436
  if (source.id === target.id) return { ok: false, code: "cycle", message: `node "${source.id}" cannot wire into itself` };
4241
4437
  const produced = sourcePortOf(source);
4242
- if (produced !== port) {
4438
+ if (produced !== portContent(port)) {
4243
4439
  return { ok: false, code: "invalid_port", message: `node "${source.id}" produces ${produced}, not ${port}` };
4244
4440
  }
4245
4441
  if (target.kind !== "task") {
@@ -4248,6 +4444,13 @@ function wireLegality(source, target, port) {
4248
4444
  if (!canConnect(produced, target.task, port)) {
4249
4445
  return { ok: false, code: "invalid_port", message: `a ${port} wire into "${target.id}" (${target.task}) is not supported` };
4250
4446
  }
4447
+ if (source.kind === "input" && source.cardinality === "many" && port === "reference") {
4448
+ return {
4449
+ ok: false,
4450
+ code: "invalid_port",
4451
+ message: `list input "${source.id}" cannot feed character references; wire one image input per reference image into "${target.id}"`
4452
+ };
4453
+ }
4251
4454
  if (source.kind === "input" && source.cardinality === "many" && portBinding(target.task, port)?.wrap !== "array") {
4252
4455
  return {
4253
4456
  ok: false,
@@ -4631,6 +4834,7 @@ function taskModality(task) {
4631
4834
  return "text";
4632
4835
  case "image":
4633
4836
  case "mask":
4837
+ case "reference":
4634
4838
  return "image";
4635
4839
  }
4636
4840
  }
@@ -4716,6 +4920,60 @@ function keyframePositionsFor(sourceIds, settings) {
4716
4920
  }
4717
4921
  return { ok: true, frames };
4718
4922
  }
4923
+ var REFERENCE_ELEMENTS_SETTING = "referenceElements";
4924
+ function referenceElementsFor(sourceIds, settings, limits) {
4925
+ const raw = settings?.[REFERENCE_ELEMENTS_SETTING];
4926
+ if (raw !== void 0 && (raw === null || typeof raw !== "object" || Array.isArray(raw))) {
4927
+ return { ok: false, reason: `${REFERENCE_ELEMENTS_SETTING} must map a reference source to its character number` };
4928
+ }
4929
+ const explicit = raw ?? {};
4930
+ const numbers = [];
4931
+ for (const id of sourceIds) {
4932
+ const v = Object.prototype.hasOwnProperty.call(explicit, id) ? explicit[id] : 1;
4933
+ if (typeof v !== "number" || !Number.isInteger(v) || v < 1) {
4934
+ return {
4935
+ ok: false,
4936
+ reason: `reference "${id}" is set to character ${JSON.stringify(v)}; a character number is a whole number from 1`
4937
+ };
4938
+ }
4939
+ numbers.push(v);
4940
+ }
4941
+ if (sourceIds.length > limits.maxTotalImages) {
4942
+ return {
4943
+ ok: false,
4944
+ reason: `this model takes at most ${limits.maxTotalImages} reference images in all, got ${sourceIds.length}`
4945
+ };
4946
+ }
4947
+ const distinct = [...new Set(numbers)].sort((a, b) => a - b);
4948
+ if (distinct.length > limits.maxElements) {
4949
+ return {
4950
+ ok: false,
4951
+ reason: `this model takes at most ${limits.maxElements} character${limits.maxElements === 1 ? "" : "s"} as references, got ${distinct.length}`
4952
+ };
4953
+ }
4954
+ const order = [];
4955
+ const elements = [];
4956
+ for (const [element, n] of distinct.entries()) {
4957
+ const members = numbers.flatMap((m, i) => m === n ? [i] : []);
4958
+ if (members.length > limits.maxImagesPerElement) {
4959
+ return {
4960
+ ok: false,
4961
+ reason: `character ${element + 1} has ${members.length} reference images; this model takes at most ${limits.maxImagesPerElement} per character (the first wire is the frontal view)`
4962
+ };
4963
+ }
4964
+ if (members.length < limits.minImagesPerElement) {
4965
+ return {
4966
+ ok: false,
4967
+ reason: `character ${element + 1} has ${members.length} reference image${members.length === 1 ? "" : "s"}; this model needs at least ${limits.minImagesPerElement} per character: the frontal view first, then further views such as three-quarter, back or full body`
4968
+ };
4969
+ }
4970
+ for (const i of members) {
4971
+ order.push(i);
4972
+ elements.push(element);
4973
+ }
4974
+ }
4975
+ return { ok: true, order, elements };
4976
+ }
4719
4977
  var TASK_TO_KIND = {
4720
4978
  // image
4721
4979
  "text-to-image": "generate_image",
@@ -4886,12 +5144,14 @@ function documentToDefinition(doc, opts = {}) {
4886
5144
  const b = portBinding(task, port);
4887
5145
  const cardinality = portCardinality(task, port, node.model);
4888
5146
  const keyframes = port === "image" && task === "image-to-video" && modelAcceptsKeyframes(node.model);
5147
+ const references = port === "reference";
4889
5148
  const listKey = orderedPortKey(task, port, 0, node.model) ?? b.key;
4890
5149
  const items = [];
5150
+ const itemSources = [];
4891
5151
  let uploading = false;
4892
5152
  for (const [ordinal, e] of portWires.entries()) {
4893
5153
  const source = byId.get(e.source);
4894
- const single = !keyframes && (cardinality !== "many" || portWires.length === 1);
5154
+ const single = !keyframes && !references && (cardinality !== "many" || portWires.length === 1);
4895
5155
  const key = orderedPortKey(task, port, ordinal, node.model) ?? b.key;
4896
5156
  const wrap = single && b.wrap === "array";
4897
5157
  let item = null;
@@ -4926,7 +5186,38 @@ function documentToDefinition(doc, opts = {}) {
4926
5186
  }
4927
5187
  if (!item) continue;
4928
5188
  if (single) inputs[key] = item;
4929
- else items.push(item);
5189
+ else {
5190
+ items.push(item);
5191
+ itemSources.push(e.source);
5192
+ }
5193
+ }
5194
+ if (references && !uploading && items.length > 0) {
5195
+ const limits = modelCharacterReferences(node.model);
5196
+ const grouped = limits ? referenceElementsFor(
5197
+ itemSources,
5198
+ node.settings,
5199
+ limits
5200
+ ) : {
5201
+ ok: false,
5202
+ reason: `${node.model || "this model"} takes no character references`
5203
+ };
5204
+ if (grouped.ok) {
5205
+ inputs[listKey] = {
5206
+ kind: "list",
5207
+ items: grouped.order.map((i) => items[i])
5208
+ };
5209
+ inputs.referenceElementIndexes = {
5210
+ kind: "literal",
5211
+ value: grouped.elements
5212
+ };
5213
+ } else {
5214
+ issues.push({
5215
+ code: "character_references",
5216
+ nodeId: node.id,
5217
+ message: `Node "${node.id}": ${grouped.reason}`
5218
+ });
5219
+ }
5220
+ continue;
4930
5221
  }
4931
5222
  if (!uploading && items.length > 0)
4932
5223
  inputs[listKey] = { kind: "list", items };
@@ -4951,6 +5242,13 @@ function documentToDefinition(doc, opts = {}) {
4951
5242
  }
4952
5243
  for (const [key, binding] of Object.entries(node.bakedInputs))
4953
5244
  if (!(key in inputs)) inputs[key] = binding;
5245
+ if (task === "image-to-video" && "referenceImageUrls" in inputs && !("inputImageUrl" in inputs)) {
5246
+ issues.push({
5247
+ code: "character_references",
5248
+ nodeId: node.id,
5249
+ message: `Node "${node.id}": character references need a start frame; wire one into the image port.`
5250
+ });
5251
+ }
4954
5252
  if (Object.keys(inputs).length === 0 && !promptMissing) {
4955
5253
  issues.push({
4956
5254
  code: "no_inputs",
@@ -5410,7 +5708,7 @@ function affectedNodes(doc, ids) {
5410
5708
  // src/workflowTools.ts
5411
5709
  var savedId = z7.string().min(1).describe('The saved workflow id (it carries a "saved:" prefix), from studio_workflow_create or the Studio workflow list.');
5412
5710
  var opsSchema = PatchSchema.shape.ops.describe(
5413
- `The ops to apply in order, 1 to ${MAX_PATCH_OPS}: addNode, removeNode, setNodeProps, setNodeSetting, setBakedInput, connect, disconnect, exposeAsInput, freezeInput, setActiveGeneration, setLayout, group, ungroup, setGroupProps, setDocumentProps. Node ids are yours to choose (UUIDv7 recommended); a later op may reference an id added earlier in the same list.`
5711
+ `The ops to apply in order, 1 to ${MAX_PATCH_OPS}: addNode, removeNode, setNodeProps, setNodeSetting, setBakedInput, connect, disconnect, exposeAsInput, freezeInput, setActiveGeneration, setLayout, group, ungroup, setGroupProps, setDocumentProps. Node ids are yours to choose (UUIDv7 recommended); a later op may reference an id added earlier in the same list. Character references on an image-to-video node: connect each image (an image-source, an image input or an image-producing node) with port "reference", in order, each character's frontal view first; they never count as the start or end frame (those are the "image" port). Only a model whose studio_workflow_describe entry carries characterReferences takes them (Kling O3: 2 to 4 images per character, a locked first frame; Gemini Omni 1.1 Flash with references: 1 to 6 images in all, the start frame sent as the first reference rather than locked). With more than one character, set which one each image shows with setNodeSetting key "referenceElements", value { "<sourceNodeId>": 2 } (an unnamed source is character 1).`
5414
5712
  );
5415
5713
  var paramsSchema = z7.record(z7.string(), z7.unknown()).describe("Run parameters by input-node name, checked against the declared inputs (unknown names, missing required values and wrong shapes are issues).");
5416
5714
  var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -5439,6 +5737,8 @@ function applyErrorOf(raw, ctx) {
5439
5737
  }
5440
5738
  var REBASE_HINT = "Re-read the workflow (studio_workflow_get), rebase your ops on the current revision (node ids are stable) and apply again with that revision as baseRevision.";
5441
5739
  var RETRY_HINT = "The outcome of this attempt is unknown. Retry studio_workflow_apply with the SAME idempotencyKey and baseRevision: if the first attempt landed, the Studio returns its original result instead of applying the patch twice.";
5740
+ var CREATE_RETRY_HINT = "The outcome of this attempt is unknown. Retry studio_workflow_create with the SAME idempotencyKey, label and ops: if the first attempt landed, the Studio returns that workflow (replayed: true) instead of making a second one.";
5741
+ var CREATE_IDEMPOTENCY_HINT = "This is not a replay: that idempotencyKey was already used to create a different workflow. Send this create with a NEW idempotencyKey.";
5442
5742
  var NOT_EDITABLE_HINT = "This workflow is readable (studio_workflow_get) and runnable (studio_run_workflow with its savedId), but it cannot be patched. Build a new workflow with studio_workflow_create instead of trying to edit this one.";
5443
5743
  var LOSSY_HINT = "Read the notes: they name what the import drops for good. To go ahead, resend the SAME ops with acknowledgeLossy: true and a NEW idempotencyKey (the first patch materializes the imported document).";
5444
5744
  var IDEMPOTENCY_HINT = "This is not a replay: that key was used for a different patch. Send this patch again with a NEW idempotencyKey, on the revision above.";
@@ -5501,6 +5801,24 @@ function mapWriteFailure(err, ctx, info) {
5501
5801
  }
5502
5802
  return null;
5503
5803
  }
5804
+ function mapCreateFailure(err, ctx, idempotencyKey) {
5805
+ if (!(err instanceof StudioApiError)) return null;
5806
+ const body = isRecord(err.body) ? err.body : {};
5807
+ if (err.status === 409 && body.code === "idempotency_mismatch") {
5808
+ return { ok: false, code: "idempotency_mismatch", message: messageOf(body, ctx), hint: CREATE_IDEMPOTENCY_HINT };
5809
+ }
5810
+ if (err.status === 0 || err.status >= 500) {
5811
+ return {
5812
+ ok: false,
5813
+ code: err.status === 0 ? "network_error" : "server_error",
5814
+ status: err.status,
5815
+ message: ctx.client.redact(err.message),
5816
+ idempotencyKey,
5817
+ hint: CREATE_RETRY_HINT
5818
+ };
5819
+ }
5820
+ return null;
5821
+ }
5504
5822
  var studioWorkflowDescribe = defineTool({
5505
5823
  name: "studio_workflow_describe",
5506
5824
  description: "Describe the node vocabulary before authoring a workflow (read-only, free). Returns { tasks: [{ task, label, family, modality, jobKind, runnable, output, inputs: [{ port, wireable, cardinality, binding }], prompt: { needed, required, key } | null, settingCount, modelCount }], inputTypes (what an input node can declare), opTypes (what studio_workflow_apply accepts), limits: { maxPatchOps } }. Settings knobs and the model catalog are large, so they are dropped unless includeSettings / includeModels is true; filter with tasks to keep the result small.",
@@ -5576,22 +5894,25 @@ var studioWorkflowGet = defineTool({
5576
5894
  });
5577
5895
  var studioWorkflowCreate = defineTool({
5578
5896
  name: "studio_workflow_create",
5579
- description: 'Create a new saved workflow by applying ops to an empty document (call studio_workflow_describe first for the task vocabulary and ports). Returns { ok: true, savedId, revision, summary } (the studio_workflow_get summary shape, its projection tells you whether it can run). A bad patch returns { ok: false, code: "invalid_patch", error: { opIndex, code, message } } naming the offending op; a missing credential scope returns { ok: false, code: "forbidden", opIndex, missingScope }. Creating is free; running it with studio_run_workflow (savedId) is what spends money.',
5897
+ description: 'Create a new saved workflow by applying ops to an empty document (call studio_workflow_describe first for the task vocabulary and ports). Returns { ok: true, savedId, revision, summary, idempotencyKey } (the studio_workflow_get summary shape, its projection tells you whether it can run), plus replayed: true when an earlier attempt with the same idempotencyKey had already made it (revision is then its current one). A bad patch returns { ok: false, code: "invalid_patch", error: { opIndex, code, message } } naming the offending op; a missing credential scope returns { ok: false, code: "forbidden", opIndex, missingScope }; "idempotency_mismatch" means that key was used for a different create (send a new one); "network_error" / "server_error" carry the idempotencyKey to retry with, so a retry can never make a second workflow. A key is scoped to its project (the same key on another project makes a new workflow), and a retry after the workflow was deleted creates a new one. Creating is free; running it with studio_run_workflow (savedId) is what spends money.',
5580
5898
  inputSchema: {
5581
5899
  ops: opsSchema,
5582
5900
  label: LabelSchema.optional().describe("Display label of the saved workflow."),
5583
- projectId: z7.string().min(1).optional().describe("Project id from studio_list_projects; omit for the default project.")
5901
+ projectId: z7.string().min(1).optional().describe("Project id from studio_list_projects; omit for the default project."),
5902
+ idempotencyKey: z7.string().min(1).max(200).optional().describe("Omit on a first call (one is generated). After a network_error or server_error, retry with the idempotencyKey that result returned: the first workflow comes back instead of a second one.")
5584
5903
  },
5585
5904
  handler: async (args, ctx) => {
5905
+ const idempotencyKey = args.idempotencyKey ?? randomUUID();
5586
5906
  let res;
5587
5907
  try {
5588
5908
  res = await ctx.client.createWorkflow({
5589
5909
  ops: args.ops,
5910
+ idempotencyKey,
5590
5911
  ...args.label !== void 0 ? { label: args.label } : {},
5591
5912
  ...args.projectId !== void 0 ? { projectId: args.projectId } : {}
5592
5913
  });
5593
5914
  } catch (err) {
5594
- const mapped = mapWriteFailure(err, ctx, {});
5915
+ const mapped = mapCreateFailure(err, ctx, idempotencyKey) ?? mapWriteFailure(err, ctx, {});
5595
5916
  if (mapped) return mapped;
5596
5917
  throw err;
5597
5918
  }
@@ -5604,7 +5925,9 @@ var studioWorkflowCreate = defineTool({
5604
5925
  savedId: res.savedId,
5605
5926
  revision: res.revision,
5606
5927
  ...res.projection ? { projection: res.projection } : {}
5607
- })
5928
+ }),
5929
+ idempotencyKey,
5930
+ ...res.replayed === true ? { replayed: true } : {}
5608
5931
  };
5609
5932
  }
5610
5933
  });
@@ -6868,7 +7191,7 @@ var studioUploadBrandReference = defineTool({
6868
7191
  }
6869
7192
  });
6870
7193
  var workflowDefinitionSchema = WorkflowDefinitionSchema.describe(
6871
- 'Inline workflow DAG: { id, label?, params?: [{ name, type: string|number|boolean|json, required?, label?, description?, inputType?, cardinality?: one|many, default? }], nodes: [{ id, task (one of the model tasks listed), model (catalog id, e.g. fal/nano-banana-2-edit), inputs, retry? }] }. Node inputs are bindings: {kind:"literal",value}, {kind:"param",name,wrap?:"array"}, {kind:"ref",node,path:"url",wrap?:"array"} or an ordered {kind:"list",items:[...]} of those. Image-edit nodes take inputImages (an array: one wrapped ref/param, or a list in reference order, scene frame first); image-to-video nodes take inputImageUrl (start frame) and optionally endImageUrl (end frame, on models that accept one), EXCEPT on a keyframes model (fal/flux-3-keyframes-to-video and its -draft tier), which instead takes keyframeImageUrls (an ordered list of up to 10 images) with keyframeFrameIndexes (one strictly increasing frame per image on a fixed 24 fps timeline). Pass one shape or the other, never both.'
7194
+ `Inline workflow DAG: { id, label?, params?: [{ name, type: string|number|boolean|json, required?, label?, description?, inputType?, cardinality?: one|many, default? }], nodes: [{ id, task (one of the model tasks listed), model (catalog id, e.g. fal/nano-banana-2-edit), inputs, retry? }] }. Node inputs are bindings: {kind:"literal",value}, {kind:"param",name,wrap?:"array"}, {kind:"ref",node,path:"url",wrap?:"array"} or an ordered {kind:"list",items:[...]} of those. Image-edit nodes take inputImages (an array: one wrapped ref/param, or a list in reference order, scene frame first); image-to-video nodes take inputImageUrl (start frame) and optionally endImageUrl (end frame, on models that accept one), EXCEPT on a keyframes model (fal/flux-3-keyframes-to-video and its -draft tier), which instead takes keyframeImageUrls (an ordered list of up to 10 images) with keyframeFrameIndexes (one strictly increasing frame per image on a fixed 24 fps timeline). Pass one shape or the other, never both. To hold a character's identity through the clip, an image-to-video node on a model with character references (route/kling-o3, kie/kling-o3-image-to-video, fal/kling-o3-pro-reference-to-video) also takes referenceImageUrls (a list of character photos, grouped by character, each character's frontal view first, 2 to 4 images per character, up to 3 characters) with referenceElementIndexes (the 0-based character of each image, ascending without gaps, e.g. [0,0,0,1,1]); they never count as the start or end frame, and they need inputImageUrl. kie/gemini-omni-flash-1-1-reference-to-video takes the same two fields with 1 to 6 character images in all and no end frame: its start frame goes in as reference image 1, named in the prompt as the exact scene and first frame, because KIE does not lock a first frame in its reference mode.`
6872
7195
  );
6873
7196
  var studioRunWorkflow = defineTool({
6874
7197
  name: "studio_run_workflow",
@@ -7219,7 +7542,7 @@ function registerTools(server, base) {
7219
7542
 
7220
7543
  // src/server.ts
7221
7544
  var SERVER_NAME = "lumitra-studio";
7222
- var SERVER_VERSION = "0.8.0";
7545
+ var SERVER_VERSION = "0.10.0";
7223
7546
  function createStudioMcpServer(opts = {}) {
7224
7547
  const config = opts.config ?? resolveConfig(opts.env ?? process.env);
7225
7548
  const client = new StudioClient(config, {