@marlinjai/studio-mcp 0.7.0 → 0.9.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/README.md +10 -2
- package/dist/cli.js +930 -142
- package/dist/index.d.ts +397 -3
- package/dist/index.js +930 -142
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -257,6 +257,45 @@ var StudioClient = class {
|
|
|
257
257
|
applyWorkflowPatch(savedId2, patch) {
|
|
258
258
|
return this.json("PATCH", `/api/v1/workflows/${encodeURIComponent(savedId2)}`, { json: patch });
|
|
259
259
|
}
|
|
260
|
+
// ── Brand kit and compositions (carousels and reels) ──
|
|
261
|
+
/** A brand's kit: colours, the two type sizes, fonts by role, logos by variant, version. */
|
|
262
|
+
getBrandKit(brandSlug) {
|
|
263
|
+
return this.json("GET", `/api/brands/${encodeURIComponent(brandSlug)}/kit`);
|
|
264
|
+
}
|
|
265
|
+
listCompositions(opts = {}) {
|
|
266
|
+
return this.json("GET", `/api/v1/compositions${projectQuery(opts.projectId)}`);
|
|
267
|
+
}
|
|
268
|
+
/** 201 created; 200 with `replayed: true` when a create with this idempotencyKey already made it. */
|
|
269
|
+
createComposition(body) {
|
|
270
|
+
return this.json("POST", "/api/v1/compositions", { json: body });
|
|
271
|
+
}
|
|
272
|
+
/** A project's assets, newest first, optionally of one subtype (Image, Video, CarouselSlide, Reel, ...). */
|
|
273
|
+
listProjectAssets(projectId, opts = {}) {
|
|
274
|
+
const q = new URLSearchParams();
|
|
275
|
+
if (opts.subtype) q.set("subtype", opts.subtype);
|
|
276
|
+
if (opts.limit) q.set("limit", String(opts.limit));
|
|
277
|
+
const qs = q.toString();
|
|
278
|
+
return this.json("GET", `/api/v1/projects/${encodeURIComponent(projectId)}/assets${qs ? `?${qs}` : ""}`);
|
|
279
|
+
}
|
|
280
|
+
getComposition(compositionId2) {
|
|
281
|
+
return this.json("GET", `/api/v1/compositions/${encodeURIComponent(compositionId2)}`);
|
|
282
|
+
}
|
|
283
|
+
/** 409 stale_revision (with the current composition) or idempotency_mismatch; 422 invalid_patch. */
|
|
284
|
+
patchComposition(compositionId2, patch) {
|
|
285
|
+
return this.json("PATCH", `/api/v1/compositions/${encodeURIComponent(compositionId2)}`, { json: patch });
|
|
286
|
+
}
|
|
287
|
+
/** The company's Lumitra Social projects (409 not_connected / link_broken until an owner connects it in Studio). */
|
|
288
|
+
listSocialProjects(brandSlug) {
|
|
289
|
+
return this.json("GET", `/api/v1/social/projects${brandSlug ? `?brandSlug=${encodeURIComponent(brandSlug)}` : ""}`);
|
|
290
|
+
}
|
|
291
|
+
/** Send the rendered post to Lumitra Social; idempotent on `idempotencyKey`. */
|
|
292
|
+
sendCompositionToSocial(compositionId2, body) {
|
|
293
|
+
return this.json("POST", `/api/v1/compositions/${encodeURIComponent(compositionId2)}/send`, { json: body });
|
|
294
|
+
}
|
|
295
|
+
/** Start (or join) a render. 422 not_ready with `reasons`; 429 render_limit or render_busy (a reel of this company is rendering). */
|
|
296
|
+
renderComposition(compositionId2) {
|
|
297
|
+
return this.json("POST", `/api/v1/compositions/${encodeURIComponent(compositionId2)}/render`);
|
|
298
|
+
}
|
|
260
299
|
/** Stateless dry-run of ops and run params against a document. No side effects. */
|
|
261
300
|
validateWorkflow(body) {
|
|
262
301
|
return this.json("POST", "/api/v1/workflows/validate", { json: body });
|
|
@@ -464,7 +503,7 @@ function resolveConfig(env = process.env) {
|
|
|
464
503
|
}
|
|
465
504
|
|
|
466
505
|
// src/tools.ts
|
|
467
|
-
import { z as
|
|
506
|
+
import { z as z11 } from "zod";
|
|
468
507
|
|
|
469
508
|
// ../lumitra-core/dist/models/index.js
|
|
470
509
|
var veo = (tier, label) => {
|
|
@@ -535,7 +574,10 @@ var ROUTES = [
|
|
|
535
574
|
"720p": "fal/kling-o3-standard-image-to-video",
|
|
536
575
|
"1080p": "fal/kling-o3-pro-image-to-video"
|
|
537
576
|
},
|
|
538
|
-
label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)"
|
|
577
|
+
label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)",
|
|
578
|
+
// Only the Pro tier of reference-to-video is in the catalog: a 720p job
|
|
579
|
+
// with references runs on KIE alone.
|
|
580
|
+
withReferences: { "1080p": "fal/kling-o3-pro-reference-to-video" }
|
|
539
581
|
}
|
|
540
582
|
},
|
|
541
583
|
{
|
|
@@ -1125,8 +1167,15 @@ var CATALOG_ENTRIES = [
|
|
|
1125
1167
|
modality: "video",
|
|
1126
1168
|
task: "image-to-video",
|
|
1127
1169
|
label: "Kling O3 (KIE)",
|
|
1128
|
-
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.",
|
|
1129
|
-
|
|
1170
|
+
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).",
|
|
1171
|
+
// `characterReferences` mirrors KIE_VIDEO_SPECS['kling-3.0-omni/image-to-video']
|
|
1172
|
+
// (catalog.spec checks they agree).
|
|
1173
|
+
capabilities: {
|
|
1174
|
+
needsImageInput: true,
|
|
1175
|
+
maxInputImages: 1,
|
|
1176
|
+
acceptsEndFrame: true,
|
|
1177
|
+
characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 12 }
|
|
1178
|
+
}
|
|
1130
1179
|
},
|
|
1131
1180
|
{
|
|
1132
1181
|
id: "fal/grok-imagine-1-5-image-to-video",
|
|
@@ -1174,6 +1223,22 @@ var CATALOG_ENTRIES = [
|
|
|
1174
1223
|
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.",
|
|
1175
1224
|
capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
|
|
1176
1225
|
},
|
|
1226
|
+
{
|
|
1227
|
+
id: "fal/kling-o3-pro-reference-to-video",
|
|
1228
|
+
provider: "fal",
|
|
1229
|
+
modality: "video",
|
|
1230
|
+
task: "image-to-video",
|
|
1231
|
+
label: "Kling O3 Pro with character references (fal)",
|
|
1232
|
+
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.",
|
|
1233
|
+
// `characterReferences` mirrors FAL_CHARACTER_REFERENCE_LIMITS (catalog.spec
|
|
1234
|
+
// checks they agree).
|
|
1235
|
+
capabilities: {
|
|
1236
|
+
needsImageInput: true,
|
|
1237
|
+
maxInputImages: 1,
|
|
1238
|
+
acceptsEndFrame: true,
|
|
1239
|
+
characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 7 }
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1177
1242
|
{
|
|
1178
1243
|
id: "fal/ltx-2-5-fast-image-to-video",
|
|
1179
1244
|
provider: "fal",
|
|
@@ -1721,12 +1786,28 @@ var KIE_VIDEO_SPECS = {
|
|
|
1721
1786
|
defaultResolution: "720p",
|
|
1722
1787
|
audioSwitch: true,
|
|
1723
1788
|
defaultAudio: false,
|
|
1789
|
+
// KIE's "Single First Frame" and "First and Last Frames" request shapes
|
|
1790
|
+
// both carry `elements`: "up to 3 subjects", and "for a multi-image
|
|
1791
|
+
// subject, provide 2 to 4 images" (docs.kie.ai, kling-3.0-omni
|
|
1792
|
+
// image-to-video, read 2026-10-23). Each element needs a name the prompt
|
|
1793
|
+
// can mention as `@name` and a description.
|
|
1794
|
+
characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 12 },
|
|
1795
|
+
maxPromptChars: 3072,
|
|
1724
1796
|
build: (i) => ({
|
|
1725
1797
|
prompt: i.prompt,
|
|
1726
1798
|
image_urls: i.end ? [i.start, i.end] : [i.start],
|
|
1727
1799
|
duration: i.seconds,
|
|
1728
1800
|
resolution: i.resolution,
|
|
1729
|
-
audio: i.audio
|
|
1801
|
+
audio: i.audio,
|
|
1802
|
+
// Named Element1, Element2, ... so one prompt convention (`@Element1`)
|
|
1803
|
+
// holds on KIE and on the fal twin alike.
|
|
1804
|
+
...i.elements && i.elements.length > 0 ? {
|
|
1805
|
+
elements: i.elements.map((e, n) => ({
|
|
1806
|
+
name: `Element${n + 1}`,
|
|
1807
|
+
description: `character ${n + 1}`,
|
|
1808
|
+
element_input_urls: [e.frontalImageUrl, ...e.referenceImageUrls]
|
|
1809
|
+
}))
|
|
1810
|
+
} : {}
|
|
1730
1811
|
})
|
|
1731
1812
|
}
|
|
1732
1813
|
};
|
|
@@ -1753,6 +1834,10 @@ var KLING_26_I2V_ENDPOINT = "fal-ai/kling-video/v2.6/pro/image-to-video";
|
|
|
1753
1834
|
var KLING_O3_STANDARD_I2V_ENDPOINT = "fal-ai/kling-video/o3/standard/image-to-video";
|
|
1754
1835
|
var KLING_O3_PRO_I2V_ENDPOINT = "fal-ai/kling-video/o3/pro/image-to-video";
|
|
1755
1836
|
var KLING_O3_I2V_ENDPOINTS = [KLING_O3_STANDARD_I2V_ENDPOINT, KLING_O3_PRO_I2V_ENDPOINT];
|
|
1837
|
+
var KLING_O3_PRO_R2V_ENDPOINT = "fal-ai/kling-video/o3/pro/reference-to-video";
|
|
1838
|
+
var FAL_CHARACTER_REFERENCE_LIMITS = {
|
|
1839
|
+
[KLING_O3_PRO_R2V_ENDPOINT]: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 7 }
|
|
1840
|
+
};
|
|
1756
1841
|
var LTX_25_FAST_I2V_ENDPOINT = "lightricks/ltx-2.5/image-to-video/fast";
|
|
1757
1842
|
var LTX_25_PRO_I2V_ENDPOINT = "lightricks/ltx-2.5/image-to-video/pro";
|
|
1758
1843
|
var LTX_25_I2V_ENDPOINTS = [LTX_25_FAST_I2V_ENDPOINT, LTX_25_PRO_I2V_ENDPOINT];
|
|
@@ -1781,7 +1866,8 @@ var VIDEO_FIXED_RESOLUTION = {
|
|
|
1781
1866
|
[KLING_26_I2V_ENDPOINT]: "1080p",
|
|
1782
1867
|
// Not a resolution the caller picks: Kling O3's tier sets the size.
|
|
1783
1868
|
[KLING_O3_STANDARD_I2V_ENDPOINT]: "fixed",
|
|
1784
|
-
[KLING_O3_PRO_I2V_ENDPOINT]: "fixed"
|
|
1869
|
+
[KLING_O3_PRO_I2V_ENDPOINT]: "fixed",
|
|
1870
|
+
[KLING_O3_PRO_R2V_ENDPOINT]: "fixed"
|
|
1785
1871
|
};
|
|
1786
1872
|
var VIDEO_PINNED_DEFAULT_SECONDS = {
|
|
1787
1873
|
[GROK_IMAGINE_I2V_ENDPOINT]: 5,
|
|
@@ -1795,6 +1881,7 @@ var VIDEO_PINNED_DEFAULT_SECONDS = {
|
|
|
1795
1881
|
[KLING_26_I2V_ENDPOINT]: 5,
|
|
1796
1882
|
[KLING_O3_STANDARD_I2V_ENDPOINT]: 5,
|
|
1797
1883
|
[KLING_O3_PRO_I2V_ENDPOINT]: 5,
|
|
1884
|
+
[KLING_O3_PRO_R2V_ENDPOINT]: 5,
|
|
1798
1885
|
// LTX-2.5 defaults to "auto", a length nobody can price up front; 6 s is its
|
|
1799
1886
|
// shortest clip on both tiers.
|
|
1800
1887
|
[LTX_25_FAST_I2V_ENDPOINT]: 6,
|
|
@@ -1844,6 +1931,8 @@ var VIDEO_ALLOWED_VALUES = {
|
|
|
1844
1931
|
},
|
|
1845
1932
|
[KLING_26_I2V_ENDPOINT]: { durationSeconds: { values: [5, 10] } },
|
|
1846
1933
|
...Object.fromEntries(KLING_O3_I2V_ENDPOINTS.map((e) => [e, { durationSeconds: { min: 3, max: 15 } }])),
|
|
1934
|
+
// Reference-to-video renders at a set ratio (default 16:9), not the frame's.
|
|
1935
|
+
[KLING_O3_PRO_R2V_ENDPOINT]: { aspectRatio: ["16:9", "9:16", "1:1"], durationSeconds: { min: 3, max: 15 } },
|
|
1847
1936
|
[LTX_25_FAST_I2V_ENDPOINT]: {
|
|
1848
1937
|
aspectRatio: ["auto", "16:9", "9:16"],
|
|
1849
1938
|
// fal also renders 1440p, which the canvas does not offer.
|
|
@@ -1902,6 +1991,8 @@ var VIDEO_UNSUPPORTED_PARAMS = {
|
|
|
1902
1991
|
[WAN_30_I2V_ENDPOINT]: ["negativePrompt"],
|
|
1903
1992
|
[KLING_26_I2V_ENDPOINT]: ["resolution", "aspectRatio", "seed"],
|
|
1904
1993
|
...Object.fromEntries(KLING_O3_I2V_ENDPOINTS.map((e) => [e, ["resolution", "aspectRatio", "seed", "negativePrompt"]])),
|
|
1994
|
+
// Its tier sets the size; it takes an aspect ratio, but no seed or negative prompt.
|
|
1995
|
+
[KLING_O3_PRO_R2V_ENDPOINT]: ["resolution", "seed", "negativePrompt"],
|
|
1905
1996
|
...Object.fromEntries(LTX_25_I2V_ENDPOINTS.map((e) => [e, ["seed", "negativePrompt"]]))
|
|
1906
1997
|
};
|
|
1907
1998
|
var ROWS = [
|
|
@@ -2614,8 +2705,10 @@ function searchMeshyAnimations(query, limit = 25) {
|
|
|
2614
2705
|
}
|
|
2615
2706
|
return out;
|
|
2616
2707
|
}
|
|
2617
|
-
var PORT_TYPES = ["text", "image", "video", "mask", "mesh3d", "audio", "json"];
|
|
2618
|
-
var INPUT_PORT_TYPES = PORT_TYPES.filter(
|
|
2708
|
+
var PORT_TYPES = ["text", "image", "video", "mask", "mesh3d", "audio", "json", "reference"];
|
|
2709
|
+
var INPUT_PORT_TYPES = PORT_TYPES.filter(
|
|
2710
|
+
(p) => p !== "mask" && p !== "reference"
|
|
2711
|
+
);
|
|
2619
2712
|
|
|
2620
2713
|
// src/rig.ts
|
|
2621
2714
|
var RIG_MODEL_ID = "fal/meshy-rigging";
|
|
@@ -2680,8 +2773,13 @@ var MODEL_TASKS = [
|
|
|
2680
2773
|
"background-remove",
|
|
2681
2774
|
"segmentation"
|
|
2682
2775
|
];
|
|
2683
|
-
var PORT_TYPES2 = ["text", "image", "video", "mask", "mesh3d", "audio", "json"];
|
|
2684
|
-
|
|
2776
|
+
var PORT_TYPES2 = ["text", "image", "video", "mask", "mesh3d", "audio", "json", "reference"];
|
|
2777
|
+
function portContent(port) {
|
|
2778
|
+
return port === "reference" ? "image" : port;
|
|
2779
|
+
}
|
|
2780
|
+
var INPUT_PORT_TYPES2 = PORT_TYPES2.filter(
|
|
2781
|
+
(p) => p !== "mask" && p !== "reference"
|
|
2782
|
+
);
|
|
2685
2783
|
var TASK_PORTS = {
|
|
2686
2784
|
// GENERATE: born from text (or a mesh prompt), no upstream asset input.
|
|
2687
2785
|
"text-to-image": { inputs: ["text"], output: "image" },
|
|
@@ -2693,7 +2791,11 @@ var TASK_PORTS = {
|
|
|
2693
2791
|
// Two image inputs (garment + person); the port type set is coarse (both are
|
|
2694
2792
|
// 'image'), the two-image contract lives in the fal adapter, not the ports.
|
|
2695
2793
|
"virtual-try-on": { inputs: ["image"], output: "image" },
|
|
2696
|
-
|
|
2794
|
+
// The `image` port takes the start frame (and the end frame, or a keyframe
|
|
2795
|
+
// timeline); the `reference` port takes character reference images for the
|
|
2796
|
+
// models that hold identity from them (Kling elements). A model without that
|
|
2797
|
+
// capability gives the reference port no wires at all (`portCardinality`).
|
|
2798
|
+
"image-to-video": { inputs: ["image", "reference"], output: "video" },
|
|
2697
2799
|
// Video-to-video (character replace): a source video plus ONE reference image
|
|
2698
2800
|
// (the person to swap in). The two-input contract lives in the fal adapter.
|
|
2699
2801
|
"video-to-video": { inputs: ["video", "image"], output: "video" },
|
|
@@ -3058,7 +3160,10 @@ var ROUTES2 = [
|
|
|
3058
3160
|
"720p": "fal/kling-o3-standard-image-to-video",
|
|
3059
3161
|
"1080p": "fal/kling-o3-pro-image-to-video"
|
|
3060
3162
|
},
|
|
3061
|
-
label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)"
|
|
3163
|
+
label: "fal renders Kling O3 at 720p (Standard) or 1080p (Pro)",
|
|
3164
|
+
// Only the Pro tier of reference-to-video is in the catalog: a 720p job
|
|
3165
|
+
// with references runs on KIE alone.
|
|
3166
|
+
withReferences: { "1080p": "fal/kling-o3-pro-reference-to-video" }
|
|
3062
3167
|
}
|
|
3063
3168
|
},
|
|
3064
3169
|
{
|
|
@@ -3648,8 +3753,15 @@ var CATALOG_ENTRIES2 = [
|
|
|
3648
3753
|
modality: "video",
|
|
3649
3754
|
task: "image-to-video",
|
|
3650
3755
|
label: "Kling O3 (KIE)",
|
|
3651
|
-
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.",
|
|
3652
|
-
|
|
3756
|
+
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).",
|
|
3757
|
+
// `characterReferences` mirrors KIE_VIDEO_SPECS['kling-3.0-omni/image-to-video']
|
|
3758
|
+
// (catalog.spec checks they agree).
|
|
3759
|
+
capabilities: {
|
|
3760
|
+
needsImageInput: true,
|
|
3761
|
+
maxInputImages: 1,
|
|
3762
|
+
acceptsEndFrame: true,
|
|
3763
|
+
characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 12 }
|
|
3764
|
+
}
|
|
3653
3765
|
},
|
|
3654
3766
|
{
|
|
3655
3767
|
id: "fal/grok-imagine-1-5-image-to-video",
|
|
@@ -3697,6 +3809,22 @@ var CATALOG_ENTRIES2 = [
|
|
|
3697
3809
|
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.",
|
|
3698
3810
|
capabilities: { needsImageInput: true, maxInputImages: 1, acceptsEndFrame: true }
|
|
3699
3811
|
},
|
|
3812
|
+
{
|
|
3813
|
+
id: "fal/kling-o3-pro-reference-to-video",
|
|
3814
|
+
provider: "fal",
|
|
3815
|
+
modality: "video",
|
|
3816
|
+
task: "image-to-video",
|
|
3817
|
+
label: "Kling O3 Pro with character references (fal)",
|
|
3818
|
+
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.",
|
|
3819
|
+
// `characterReferences` mirrors FAL_CHARACTER_REFERENCE_LIMITS (catalog.spec
|
|
3820
|
+
// checks they agree).
|
|
3821
|
+
capabilities: {
|
|
3822
|
+
needsImageInput: true,
|
|
3823
|
+
maxInputImages: 1,
|
|
3824
|
+
acceptsEndFrame: true,
|
|
3825
|
+
characterReferences: { maxElements: 3, minImagesPerElement: 2, maxImagesPerElement: 4, maxTotalImages: 7 }
|
|
3826
|
+
}
|
|
3827
|
+
},
|
|
3700
3828
|
{
|
|
3701
3829
|
id: "fal/ltx-2-5-fast-image-to-video",
|
|
3702
3830
|
provider: "fal",
|
|
@@ -4080,6 +4208,9 @@ function portBinding(task, port) {
|
|
|
4080
4208
|
if (port === "image" && (task === "image-to-3d" || task === "multiview-to-3d" || task === "image-to-video" || task === "image-to-text" || task === "image-to-json")) {
|
|
4081
4209
|
return { key: "inputImageUrl", path: "url" };
|
|
4082
4210
|
}
|
|
4211
|
+
if (port === "reference" && task === "image-to-video") {
|
|
4212
|
+
return { key: "referenceImageUrls", path: "url", wrap: "array" };
|
|
4213
|
+
}
|
|
4083
4214
|
if (port === "mesh3d" && (task === "remesh" || task === "texture" || task === "rig")) {
|
|
4084
4215
|
return { key: "parentAssetId", path: "assetId" };
|
|
4085
4216
|
}
|
|
@@ -4095,7 +4226,7 @@ function portBinding(task, port) {
|
|
|
4095
4226
|
if (port === "video" && task === "video-enhance") {
|
|
4096
4227
|
return { key: "draftCacheUrl", path: "draftCacheUrl" };
|
|
4097
4228
|
}
|
|
4098
|
-
if (port === "image" && task === "image-edit") {
|
|
4229
|
+
if (port === "image" && (task === "image-edit" || task === "image-to-image")) {
|
|
4099
4230
|
return { key: "inputImages", path: "url", wrap: "array" };
|
|
4100
4231
|
}
|
|
4101
4232
|
if (port === "text" && taskNeedsPrompt(task)) {
|
|
@@ -4113,20 +4244,27 @@ function portBinding(task, port) {
|
|
|
4113
4244
|
return null;
|
|
4114
4245
|
}
|
|
4115
4246
|
function canConnect(sourceOut, targetTask, targetPort) {
|
|
4116
|
-
if (sourceOut !== targetPort) return false;
|
|
4247
|
+
if (sourceOut !== portContent(targetPort)) return false;
|
|
4117
4248
|
return portBinding(targetTask, targetPort) !== null;
|
|
4118
4249
|
}
|
|
4119
4250
|
function portCardinality(task, port, model) {
|
|
4120
4251
|
if (portBinding(task, port) === null) return "none";
|
|
4121
|
-
if (port === "image" && task === "image-edit") return "many";
|
|
4252
|
+
if (port === "image" && (task === "image-edit" || task === "image-to-image")) return "many";
|
|
4122
4253
|
if (port === "image" && task === "image-to-video") {
|
|
4123
4254
|
return modelAcceptsKeyframes(model) ? "many" : "two";
|
|
4124
4255
|
}
|
|
4256
|
+
if (port === "reference") {
|
|
4257
|
+
return modelCharacterReferences(model) ? "many" : "none";
|
|
4258
|
+
}
|
|
4125
4259
|
if (port === "image" && task === "video-to-video") {
|
|
4126
4260
|
return modelTakesSeveralReferences(model) ? "many" : "one";
|
|
4127
4261
|
}
|
|
4128
4262
|
return "one";
|
|
4129
4263
|
}
|
|
4264
|
+
function modelCharacterReferences(model) {
|
|
4265
|
+
if (!model) return null;
|
|
4266
|
+
return tryGetModel2(model)?.capabilities?.characterReferences ?? null;
|
|
4267
|
+
}
|
|
4130
4268
|
function modelTakesSeveralReferences(model) {
|
|
4131
4269
|
if (!model) return false;
|
|
4132
4270
|
const cap = tryGetModel2(model)?.capabilities?.maxInputImages;
|
|
@@ -4178,6 +4316,15 @@ function targetCardinality(node, port) {
|
|
|
4178
4316
|
function slotRefusal(node, port, wired) {
|
|
4179
4317
|
const cardinality = targetCardinality(node, port);
|
|
4180
4318
|
let limit = cardinalityLimit(cardinality);
|
|
4319
|
+
if (port === "reference" && node.kind === "task") {
|
|
4320
|
+
const refs = modelCharacterReferences(node.model);
|
|
4321
|
+
if (refs) limit = Math.min(limit, refs.maxTotalImages);
|
|
4322
|
+
if (wired < limit) return null;
|
|
4323
|
+
if (!refs) {
|
|
4324
|
+
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`;
|
|
4325
|
+
}
|
|
4326
|
+
return `node "${node.id}" (${node.model}) takes at most ${limit} character reference images in all`;
|
|
4327
|
+
}
|
|
4181
4328
|
if (cardinality === "many" && node.kind === "task" && node.model) {
|
|
4182
4329
|
const cap = tryGetModel2(node.model)?.capabilities?.maxInputImages;
|
|
4183
4330
|
if (typeof cap === "number" && cap > 0) limit = Math.min(limit, cap);
|
|
@@ -4192,7 +4339,7 @@ function slotRefusal(node, port, wired) {
|
|
|
4192
4339
|
function wireLegality(source, target, port) {
|
|
4193
4340
|
if (source.id === target.id) return { ok: false, code: "cycle", message: `node "${source.id}" cannot wire into itself` };
|
|
4194
4341
|
const produced = sourcePortOf(source);
|
|
4195
|
-
if (produced !== port) {
|
|
4342
|
+
if (produced !== portContent(port)) {
|
|
4196
4343
|
return { ok: false, code: "invalid_port", message: `node "${source.id}" produces ${produced}, not ${port}` };
|
|
4197
4344
|
}
|
|
4198
4345
|
if (target.kind !== "task") {
|
|
@@ -4201,6 +4348,13 @@ function wireLegality(source, target, port) {
|
|
|
4201
4348
|
if (!canConnect(produced, target.task, port)) {
|
|
4202
4349
|
return { ok: false, code: "invalid_port", message: `a ${port} wire into "${target.id}" (${target.task}) is not supported` };
|
|
4203
4350
|
}
|
|
4351
|
+
if (source.kind === "input" && source.cardinality === "many" && port === "reference") {
|
|
4352
|
+
return {
|
|
4353
|
+
ok: false,
|
|
4354
|
+
code: "invalid_port",
|
|
4355
|
+
message: `list input "${source.id}" cannot feed character references; wire one image input per reference image into "${target.id}"`
|
|
4356
|
+
};
|
|
4357
|
+
}
|
|
4204
4358
|
if (source.kind === "input" && source.cardinality === "many" && portBinding(target.task, port)?.wrap !== "array") {
|
|
4205
4359
|
return {
|
|
4206
4360
|
ok: false,
|
|
@@ -4584,6 +4738,7 @@ function taskModality(task) {
|
|
|
4584
4738
|
return "text";
|
|
4585
4739
|
case "image":
|
|
4586
4740
|
case "mask":
|
|
4741
|
+
case "reference":
|
|
4587
4742
|
return "image";
|
|
4588
4743
|
}
|
|
4589
4744
|
}
|
|
@@ -4669,6 +4824,60 @@ function keyframePositionsFor(sourceIds, settings) {
|
|
|
4669
4824
|
}
|
|
4670
4825
|
return { ok: true, frames };
|
|
4671
4826
|
}
|
|
4827
|
+
var REFERENCE_ELEMENTS_SETTING = "referenceElements";
|
|
4828
|
+
function referenceElementsFor(sourceIds, settings, limits) {
|
|
4829
|
+
const raw = settings?.[REFERENCE_ELEMENTS_SETTING];
|
|
4830
|
+
if (raw !== void 0 && (raw === null || typeof raw !== "object" || Array.isArray(raw))) {
|
|
4831
|
+
return { ok: false, reason: `${REFERENCE_ELEMENTS_SETTING} must map a reference source to its character number` };
|
|
4832
|
+
}
|
|
4833
|
+
const explicit = raw ?? {};
|
|
4834
|
+
const numbers = [];
|
|
4835
|
+
for (const id of sourceIds) {
|
|
4836
|
+
const v = Object.prototype.hasOwnProperty.call(explicit, id) ? explicit[id] : 1;
|
|
4837
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 1) {
|
|
4838
|
+
return {
|
|
4839
|
+
ok: false,
|
|
4840
|
+
reason: `reference "${id}" is set to character ${JSON.stringify(v)}; a character number is a whole number from 1`
|
|
4841
|
+
};
|
|
4842
|
+
}
|
|
4843
|
+
numbers.push(v);
|
|
4844
|
+
}
|
|
4845
|
+
if (sourceIds.length > limits.maxTotalImages) {
|
|
4846
|
+
return {
|
|
4847
|
+
ok: false,
|
|
4848
|
+
reason: `this model takes at most ${limits.maxTotalImages} reference images in all, got ${sourceIds.length}`
|
|
4849
|
+
};
|
|
4850
|
+
}
|
|
4851
|
+
const distinct = [...new Set(numbers)].sort((a, b) => a - b);
|
|
4852
|
+
if (distinct.length > limits.maxElements) {
|
|
4853
|
+
return {
|
|
4854
|
+
ok: false,
|
|
4855
|
+
reason: `this model takes at most ${limits.maxElements} character${limits.maxElements === 1 ? "" : "s"} as references, got ${distinct.length}`
|
|
4856
|
+
};
|
|
4857
|
+
}
|
|
4858
|
+
const order = [];
|
|
4859
|
+
const elements = [];
|
|
4860
|
+
for (const [element, n] of distinct.entries()) {
|
|
4861
|
+
const members = numbers.flatMap((m, i) => m === n ? [i] : []);
|
|
4862
|
+
if (members.length > limits.maxImagesPerElement) {
|
|
4863
|
+
return {
|
|
4864
|
+
ok: false,
|
|
4865
|
+
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)`
|
|
4866
|
+
};
|
|
4867
|
+
}
|
|
4868
|
+
if (members.length < limits.minImagesPerElement) {
|
|
4869
|
+
return {
|
|
4870
|
+
ok: false,
|
|
4871
|
+
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`
|
|
4872
|
+
};
|
|
4873
|
+
}
|
|
4874
|
+
for (const i of members) {
|
|
4875
|
+
order.push(i);
|
|
4876
|
+
elements.push(element);
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
return { ok: true, order, elements };
|
|
4880
|
+
}
|
|
4672
4881
|
var TASK_TO_KIND = {
|
|
4673
4882
|
// image
|
|
4674
4883
|
"text-to-image": "generate_image",
|
|
@@ -4839,12 +5048,14 @@ function documentToDefinition(doc, opts = {}) {
|
|
|
4839
5048
|
const b = portBinding(task, port);
|
|
4840
5049
|
const cardinality = portCardinality(task, port, node.model);
|
|
4841
5050
|
const keyframes = port === "image" && task === "image-to-video" && modelAcceptsKeyframes(node.model);
|
|
5051
|
+
const references = port === "reference";
|
|
4842
5052
|
const listKey = orderedPortKey(task, port, 0, node.model) ?? b.key;
|
|
4843
5053
|
const items = [];
|
|
5054
|
+
const itemSources = [];
|
|
4844
5055
|
let uploading = false;
|
|
4845
5056
|
for (const [ordinal, e] of portWires.entries()) {
|
|
4846
5057
|
const source = byId.get(e.source);
|
|
4847
|
-
const single = !keyframes && (cardinality !== "many" || portWires.length === 1);
|
|
5058
|
+
const single = !keyframes && !references && (cardinality !== "many" || portWires.length === 1);
|
|
4848
5059
|
const key = orderedPortKey(task, port, ordinal, node.model) ?? b.key;
|
|
4849
5060
|
const wrap = single && b.wrap === "array";
|
|
4850
5061
|
let item = null;
|
|
@@ -4879,7 +5090,38 @@ function documentToDefinition(doc, opts = {}) {
|
|
|
4879
5090
|
}
|
|
4880
5091
|
if (!item) continue;
|
|
4881
5092
|
if (single) inputs[key] = item;
|
|
4882
|
-
else
|
|
5093
|
+
else {
|
|
5094
|
+
items.push(item);
|
|
5095
|
+
itemSources.push(e.source);
|
|
5096
|
+
}
|
|
5097
|
+
}
|
|
5098
|
+
if (references && !uploading && items.length > 0) {
|
|
5099
|
+
const limits = modelCharacterReferences(node.model);
|
|
5100
|
+
const grouped = limits ? referenceElementsFor(
|
|
5101
|
+
itemSources,
|
|
5102
|
+
node.settings,
|
|
5103
|
+
limits
|
|
5104
|
+
) : {
|
|
5105
|
+
ok: false,
|
|
5106
|
+
reason: `${node.model || "this model"} takes no character references`
|
|
5107
|
+
};
|
|
5108
|
+
if (grouped.ok) {
|
|
5109
|
+
inputs[listKey] = {
|
|
5110
|
+
kind: "list",
|
|
5111
|
+
items: grouped.order.map((i) => items[i])
|
|
5112
|
+
};
|
|
5113
|
+
inputs.referenceElementIndexes = {
|
|
5114
|
+
kind: "literal",
|
|
5115
|
+
value: grouped.elements
|
|
5116
|
+
};
|
|
5117
|
+
} else {
|
|
5118
|
+
issues.push({
|
|
5119
|
+
code: "character_references",
|
|
5120
|
+
nodeId: node.id,
|
|
5121
|
+
message: `Node "${node.id}": ${grouped.reason}`
|
|
5122
|
+
});
|
|
5123
|
+
}
|
|
5124
|
+
continue;
|
|
4883
5125
|
}
|
|
4884
5126
|
if (!uploading && items.length > 0)
|
|
4885
5127
|
inputs[listKey] = { kind: "list", items };
|
|
@@ -4904,6 +5146,13 @@ function documentToDefinition(doc, opts = {}) {
|
|
|
4904
5146
|
}
|
|
4905
5147
|
for (const [key, binding] of Object.entries(node.bakedInputs))
|
|
4906
5148
|
if (!(key in inputs)) inputs[key] = binding;
|
|
5149
|
+
if (task === "image-to-video" && "referenceImageUrls" in inputs && !("inputImageUrl" in inputs)) {
|
|
5150
|
+
issues.push({
|
|
5151
|
+
code: "character_references",
|
|
5152
|
+
nodeId: node.id,
|
|
5153
|
+
message: `Node "${node.id}": character references need a start frame; wire one into the image port.`
|
|
5154
|
+
});
|
|
5155
|
+
}
|
|
4907
5156
|
if (Object.keys(inputs).length === 0 && !promptMissing) {
|
|
4908
5157
|
issues.push({
|
|
4909
5158
|
code: "no_inputs",
|
|
@@ -5366,7 +5615,7 @@ function affectedNodes(doc, ids) {
|
|
|
5366
5615
|
// src/workflowTools.ts
|
|
5367
5616
|
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.');
|
|
5368
5617
|
var opsSchema = PatchSchema.shape.ops.describe(
|
|
5369
|
-
`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.`
|
|
5618
|
+
`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). With more than one character, set which one each image shows with setNodeSetting key "referenceElements", value { "<sourceNodeId>": 2 } (an unnamed source is character 1).`
|
|
5370
5619
|
);
|
|
5371
5620
|
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).");
|
|
5372
5621
|
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -5666,9 +5915,535 @@ var WORKFLOW_TOOLS = [
|
|
|
5666
5915
|
studioWorkflowScreenshot
|
|
5667
5916
|
];
|
|
5668
5917
|
|
|
5669
|
-
// src/
|
|
5918
|
+
// src/compositionTools.ts
|
|
5670
5919
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
5920
|
+
import { z as z9 } from "zod";
|
|
5921
|
+
|
|
5922
|
+
// ../lumitra-core/dist/composition/index.js
|
|
5923
|
+
import { z as z22 } from "zod";
|
|
5671
5924
|
import { z as z8 } from "zod";
|
|
5925
|
+
import { z as z32 } from "zod";
|
|
5926
|
+
var BRAND_KIT_MAX_COLORS = 6;
|
|
5927
|
+
var BRAND_KIT_FONT_ROLES = ["primary", "secondary"];
|
|
5928
|
+
var BRAND_KIT_TYPE_ROLES = ["headline", "body"];
|
|
5929
|
+
var BRAND_KIT_LOGO_VARIANTS = ["light", "dark"];
|
|
5930
|
+
var BRAND_KIT_TYPE_PX_MIN = 12;
|
|
5931
|
+
var BRAND_KIT_TYPE_PX_MAX = 200;
|
|
5932
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
5933
|
+
var COLOR_ID = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
5934
|
+
var BrandKitColorSchema = z8.object({
|
|
5935
|
+
/** Stable id an overlay refers to; survives a rename of the colour. */
|
|
5936
|
+
id: z8.string().regex(COLOR_ID, "a colour id is lowercase letters, digits and hyphens"),
|
|
5937
|
+
name: z8.string().trim().min(1, "a colour needs a name").max(40),
|
|
5938
|
+
hex: z8.string().regex(HEX, "a colour is a hex value like #1a2b3c")
|
|
5939
|
+
}).strict();
|
|
5940
|
+
var TypeSizeSchema = z8.object({
|
|
5941
|
+
px: z8.number().int("a type size is a whole number of pixels").min(BRAND_KIT_TYPE_PX_MIN, `a type size is at least ${BRAND_KIT_TYPE_PX_MIN} px`).max(BRAND_KIT_TYPE_PX_MAX, `a type size is at most ${BRAND_KIT_TYPE_PX_MAX} px`)
|
|
5942
|
+
}).strict();
|
|
5943
|
+
var BrandKitTypeRolesSchema = z8.object({ headline: TypeSizeSchema, body: TypeSizeSchema }).strict().refine((t) => t.headline.px > t.body.px, {
|
|
5944
|
+
message: "the headline size must be larger than the body size",
|
|
5945
|
+
path: ["headline", "px"]
|
|
5946
|
+
});
|
|
5947
|
+
var BrandKitTokensSchema = z8.object({
|
|
5948
|
+
colors: z8.array(BrandKitColorSchema).min(1, "a kit needs at least one colour").max(BRAND_KIT_MAX_COLORS, `a kit holds at most ${BRAND_KIT_MAX_COLORS} colours`).superRefine((colors, ctx) => {
|
|
5949
|
+
const ids = /* @__PURE__ */ new Set();
|
|
5950
|
+
const names = /* @__PURE__ */ new Set();
|
|
5951
|
+
colors.forEach((c, i) => {
|
|
5952
|
+
if (ids.has(c.id)) ctx.addIssue({ code: "custom", message: `colour id "${c.id}" is used twice`, path: [i, "id"] });
|
|
5953
|
+
const name = c.name.trim().toLowerCase();
|
|
5954
|
+
if (names.has(name)) ctx.addIssue({ code: "custom", message: `colour name "${c.name}" is used twice`, path: [i, "name"] });
|
|
5955
|
+
ids.add(c.id);
|
|
5956
|
+
names.add(name);
|
|
5957
|
+
});
|
|
5958
|
+
}),
|
|
5959
|
+
typeRoles: BrandKitTypeRolesSchema
|
|
5960
|
+
}).strict();
|
|
5961
|
+
var BrandKitFontFileMetaSchema = z8.object({
|
|
5962
|
+
weight: z8.number().int().min(100).max(900).refine((w) => w % 100 === 0, "a font weight is a multiple of 100"),
|
|
5963
|
+
style: z8.enum(["normal", "italic"])
|
|
5964
|
+
}).strict();
|
|
5965
|
+
var BrandKitFamilySchema = z8.string().trim().min(1, "a font needs a family name").max(64).regex(/^[\p{L}\p{N} .'-]+$/u, "a font family name holds letters, digits, spaces, dots, apostrophes and hyphens");
|
|
5966
|
+
var COMPOSITION_SCHEMA_VERSION = 1;
|
|
5967
|
+
var COMPOSITION_KINDS = ["carousel", "reel"];
|
|
5968
|
+
var COMPOSITION_ASPECTS = ["4:5", "1:1", "9:16"];
|
|
5969
|
+
var MAX_CAROUSEL_SLIDES = 10;
|
|
5970
|
+
var REEL_MIN_SECONDS = 3;
|
|
5971
|
+
var REEL_MAX_SECONDS = 90;
|
|
5972
|
+
var MIN_CLIP_SECONDS = 0.5;
|
|
5973
|
+
var MAX_REEL_CLIPS = 30;
|
|
5974
|
+
var MAX_OVERLAYS_PER_ITEM = 20;
|
|
5975
|
+
var MAX_REEL_OVERLAYS = 40;
|
|
5976
|
+
var MAX_OVERLAY_TEXT = 500;
|
|
5977
|
+
var MIN_BOX_SIDE = 0.02;
|
|
5978
|
+
var ID = /^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}$/;
|
|
5979
|
+
var CompositionIdSchema = z22.string().regex(ID, "an id is letters, digits and _ . : -");
|
|
5980
|
+
var COLOR_ROLE = z22.string().regex(/^[a-z0-9][a-z0-9-]{0,31}$/, "a colour is named by its kit id");
|
|
5981
|
+
var unit = z22.number().min(0).max(1);
|
|
5982
|
+
var BoxSchema = z22.object({ x: unit, y: unit, w: z22.number().min(MIN_BOX_SIDE).max(1), h: z22.number().min(MIN_BOX_SIDE).max(1) }).strict().refine((b) => b.x + b.w <= 1 + 1e-9 && b.y + b.h <= 1 + 1e-9, "a box must stay inside the frame");
|
|
5983
|
+
var TimingShape = {
|
|
5984
|
+
start: z22.number().min(0).optional(),
|
|
5985
|
+
end: z22.number().positive().optional()
|
|
5986
|
+
};
|
|
5987
|
+
var TextOverlaySchema = z22.object({
|
|
5988
|
+
id: CompositionIdSchema,
|
|
5989
|
+
type: z22.literal("text"),
|
|
5990
|
+
box: BoxSchema,
|
|
5991
|
+
text: z22.string().min(1, "a text overlay needs text").max(MAX_OVERLAY_TEXT),
|
|
5992
|
+
styleRole: z22.enum(BRAND_KIT_TYPE_ROLES),
|
|
5993
|
+
fontRole: z22.enum(BRAND_KIT_FONT_ROLES),
|
|
5994
|
+
weight: z22.number().int().min(100).max(900),
|
|
5995
|
+
italic: z22.boolean(),
|
|
5996
|
+
colorRole: COLOR_ROLE,
|
|
5997
|
+
align: z22.enum(["left", "center", "right"]),
|
|
5998
|
+
/** A colour chip behind the text, for legibility on busy images. */
|
|
5999
|
+
background: z22.object({ colorRole: COLOR_ROLE, opacity: unit, padding: z22.number().min(0).max(0.1) }).strict().optional(),
|
|
6000
|
+
...TimingShape
|
|
6001
|
+
}).strict();
|
|
6002
|
+
var LogoOverlaySchema = z22.object({
|
|
6003
|
+
id: CompositionIdSchema,
|
|
6004
|
+
type: z22.literal("logo"),
|
|
6005
|
+
box: BoxSchema,
|
|
6006
|
+
variant: z22.enum(BRAND_KIT_LOGO_VARIANTS),
|
|
6007
|
+
...TimingShape
|
|
6008
|
+
}).strict();
|
|
6009
|
+
var ShapeOverlaySchema = z22.object({
|
|
6010
|
+
id: CompositionIdSchema,
|
|
6011
|
+
type: z22.literal("shape"),
|
|
6012
|
+
box: BoxSchema,
|
|
6013
|
+
shape: z22.enum(["rect", "pill"]),
|
|
6014
|
+
colorRole: COLOR_ROLE,
|
|
6015
|
+
opacity: unit,
|
|
6016
|
+
...TimingShape
|
|
6017
|
+
}).strict();
|
|
6018
|
+
var OverlaySchema = z22.discriminatedUnion("type", [TextOverlaySchema, LogoOverlaySchema, ShapeOverlaySchema]);
|
|
6019
|
+
var SlideSchema = z22.object({
|
|
6020
|
+
id: CompositionIdSchema,
|
|
6021
|
+
type: z22.literal("slide"),
|
|
6022
|
+
background: z22.object({
|
|
6023
|
+
/** A Studio image asset of the composition's project. */
|
|
6024
|
+
assetId: CompositionIdSchema.optional(),
|
|
6025
|
+
fit: z22.enum(["cover", "contain"]),
|
|
6026
|
+
/** The point of the image kept in view when `cover` crops it. */
|
|
6027
|
+
focal: z22.object({ x: unit, y: unit }).strict(),
|
|
6028
|
+
/** A kit colour behind the image (or instead of one). */
|
|
6029
|
+
fill: COLOR_ROLE.optional()
|
|
6030
|
+
}).strict().refine((b) => b.assetId !== void 0 || b.fill !== void 0, "a slide needs an image or a fill colour"),
|
|
6031
|
+
overlays: z22.array(OverlaySchema).max(MAX_OVERLAYS_PER_ITEM)
|
|
6032
|
+
}).strict();
|
|
6033
|
+
var ClipSchema = z22.object({
|
|
6034
|
+
id: CompositionIdSchema,
|
|
6035
|
+
type: z22.literal("clip"),
|
|
6036
|
+
/** A Studio video asset of the composition's project. */
|
|
6037
|
+
assetId: CompositionIdSchema,
|
|
6038
|
+
/** Seconds into the source clip. */
|
|
6039
|
+
trimIn: z22.number().min(0),
|
|
6040
|
+
trimOut: z22.number().positive(),
|
|
6041
|
+
overlays: z22.array(OverlaySchema).max(MAX_OVERLAYS_PER_ITEM)
|
|
6042
|
+
}).strict().refine((c) => c.trimOut - c.trimIn >= MIN_CLIP_SECONDS - 1e-9, `a clip is at least ${MIN_CLIP_SECONDS} s after trimming`);
|
|
6043
|
+
var ItemSchema = z22.union([SlideSchema, ClipSchema]);
|
|
6044
|
+
var CompositionDocumentSchema = z22.object({
|
|
6045
|
+
schema: z22.literal(COMPOSITION_SCHEMA_VERSION),
|
|
6046
|
+
kind: z22.enum(COMPOSITION_KINDS),
|
|
6047
|
+
aspect: z22.enum(COMPOSITION_ASPECTS),
|
|
6048
|
+
label: z22.string().max(200),
|
|
6049
|
+
/** The brand whose kit the overlays use. */
|
|
6050
|
+
brandSlug: z22.string().min(1).max(64),
|
|
6051
|
+
/** The kit version the document was last edited against; a newer kit is worth a look before rendering. */
|
|
6052
|
+
kitVersionAtEdit: z22.number().int().nonnegative(),
|
|
6053
|
+
items: z22.array(ItemSchema),
|
|
6054
|
+
/** Overlays across the whole reel (a logo bug, an end card line). Always empty on a carousel. */
|
|
6055
|
+
reelOverlays: z22.array(OverlaySchema).max(MAX_OVERLAYS_PER_ITEM)
|
|
6056
|
+
}).strict();
|
|
6057
|
+
var REEL_TARGET = "reel";
|
|
6058
|
+
var TargetSchema = z32.string().min(1).max(128);
|
|
6059
|
+
var index = z32.number().int().nonnegative();
|
|
6060
|
+
var PropsSchema = z32.record(z32.string(), z32.unknown());
|
|
6061
|
+
var SetMetaOpSchema = z32.object({
|
|
6062
|
+
type: z32.literal("setMeta"),
|
|
6063
|
+
props: z32.object({
|
|
6064
|
+
label: z32.string().max(200).optional(),
|
|
6065
|
+
aspect: z32.enum(COMPOSITION_ASPECTS).optional(),
|
|
6066
|
+
kitVersionAtEdit: z32.number().int().nonnegative().optional()
|
|
6067
|
+
}).strict()
|
|
6068
|
+
}).strict();
|
|
6069
|
+
var AddItemOpSchema = z32.object({ type: z32.literal("addItem"), item: ItemSchema, index: index.optional() }).strict();
|
|
6070
|
+
var RemoveItemOpSchema = z32.object({ type: z32.literal("removeItem"), itemId: CompositionIdSchema }).strict();
|
|
6071
|
+
var MoveItemOpSchema = z32.object({ type: z32.literal("moveItem"), itemId: CompositionIdSchema, index }).strict();
|
|
6072
|
+
var SetItemPropsOpSchema = z32.object({ type: z32.literal("setItemProps"), itemId: CompositionIdSchema, props: PropsSchema }).strict();
|
|
6073
|
+
var AddOverlayOpSchema = z32.object({ type: z32.literal("addOverlay"), target: TargetSchema, overlay: OverlaySchema, index: index.optional() }).strict();
|
|
6074
|
+
var RemoveOverlayOpSchema = z32.object({ type: z32.literal("removeOverlay"), target: TargetSchema, overlayId: CompositionIdSchema }).strict();
|
|
6075
|
+
var MoveOverlayOpSchema = z32.object({
|
|
6076
|
+
type: z32.literal("moveOverlay"),
|
|
6077
|
+
target: TargetSchema,
|
|
6078
|
+
overlayId: CompositionIdSchema,
|
|
6079
|
+
/** Another item (or the reel) to move it to; omitted keeps it where it is. */
|
|
6080
|
+
toTarget: TargetSchema.optional(),
|
|
6081
|
+
/** Stacking position in the destination: 0 is at the back. */
|
|
6082
|
+
index
|
|
6083
|
+
}).strict();
|
|
6084
|
+
var SetOverlayPropsOpSchema = z32.object({ type: z32.literal("setOverlayProps"), target: TargetSchema, overlayId: CompositionIdSchema, props: PropsSchema }).strict();
|
|
6085
|
+
var CompositionOpSchema = z32.discriminatedUnion("type", [
|
|
6086
|
+
SetMetaOpSchema,
|
|
6087
|
+
AddItemOpSchema,
|
|
6088
|
+
RemoveItemOpSchema,
|
|
6089
|
+
MoveItemOpSchema,
|
|
6090
|
+
SetItemPropsOpSchema,
|
|
6091
|
+
AddOverlayOpSchema,
|
|
6092
|
+
RemoveOverlayOpSchema,
|
|
6093
|
+
MoveOverlayOpSchema,
|
|
6094
|
+
SetOverlayPropsOpSchema
|
|
6095
|
+
]);
|
|
6096
|
+
var COMPOSITION_OP_TYPES = CompositionOpSchema.options.map((o) => o.shape.type.value);
|
|
6097
|
+
var MAX_COMPOSITION_PATCH_OPS = 200;
|
|
6098
|
+
var CompositionPatchSchema = z32.object({
|
|
6099
|
+
baseRevision: z32.number().int().nonnegative(),
|
|
6100
|
+
ops: z32.array(CompositionOpSchema).min(1).max(MAX_COMPOSITION_PATCH_OPS),
|
|
6101
|
+
idempotencyKey: z32.string().min(1).max(128).optional()
|
|
6102
|
+
}).strict();
|
|
6103
|
+
|
|
6104
|
+
// src/compositionTools.ts
|
|
6105
|
+
var compositionId = z9.string().min(1).describe("The composition id, from studio_composition_create or studio_composition_list.");
|
|
6106
|
+
var opsSchema2 = z9.array(CompositionOpSchema).min(1).max(MAX_COMPOSITION_PATCH_OPS).describe(
|
|
6107
|
+
`The ops to apply in order (1 to ${MAX_COMPOSITION_PATCH_OPS}): ${COMPOSITION_OP_TYPES.join(", ")}. Ids are yours to choose; a later op may reference an id added earlier. Call studio_composition_describe for the overlay shapes and limits.`
|
|
6108
|
+
);
|
|
6109
|
+
function isRecord2(v) {
|
|
6110
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6111
|
+
}
|
|
6112
|
+
function summarize(c) {
|
|
6113
|
+
const doc = c.document;
|
|
6114
|
+
return {
|
|
6115
|
+
id: c.id,
|
|
6116
|
+
projectId: c.projectId,
|
|
6117
|
+
kind: c.kind,
|
|
6118
|
+
label: c.label,
|
|
6119
|
+
brandSlug: c.brandSlug,
|
|
6120
|
+
revision: c.revision,
|
|
6121
|
+
aspect: doc.aspect,
|
|
6122
|
+
kitVersionAtEdit: doc.kitVersionAtEdit,
|
|
6123
|
+
items: doc.items,
|
|
6124
|
+
...doc.kind === "reel" ? { reelOverlays: doc.reelOverlays } : {}
|
|
6125
|
+
};
|
|
6126
|
+
}
|
|
6127
|
+
function mapCompositionFailure(err, ctx, idempotencyKey) {
|
|
6128
|
+
if (!(err instanceof StudioApiError)) return null;
|
|
6129
|
+
const body = isRecord2(err.body) ? err.body : {};
|
|
6130
|
+
const code = typeof body.code === "string" ? body.code : null;
|
|
6131
|
+
const message = typeof body.message === "string" ? ctx.client.redact(body.message) : null;
|
|
6132
|
+
if (err.status === 409 && code === "stale_revision" && isRecord2(body.composition)) {
|
|
6133
|
+
return {
|
|
6134
|
+
ok: false,
|
|
6135
|
+
code,
|
|
6136
|
+
revision: body.revision,
|
|
6137
|
+
composition: summarize(body.composition),
|
|
6138
|
+
hint: "Someone else changed it. Rebase your ops on the composition returned here and apply again with its revision and a NEW idempotencyKey."
|
|
6139
|
+
};
|
|
6140
|
+
}
|
|
6141
|
+
if (err.status === 409 && code === "idempotency_mismatch") {
|
|
6142
|
+
return { ok: false, code, message, hint: "That idempotencyKey belongs to a different patch: send this one with a new key." };
|
|
6143
|
+
}
|
|
6144
|
+
if (err.status === 422 && (code === "invalid_patch" || code === "not_ready")) {
|
|
6145
|
+
return {
|
|
6146
|
+
ok: false,
|
|
6147
|
+
code,
|
|
6148
|
+
...isRecord2(body.error) ? { error: body.error } : {},
|
|
6149
|
+
...Array.isArray(body.reasons) ? { reasons: body.reasons } : {},
|
|
6150
|
+
message,
|
|
6151
|
+
hint: code === "not_ready" ? "Fix every reason (studio_composition_apply), then render again." : "Nothing was applied. error.opIndex names the op to fix; a not_in_kit code means a colour, font, weight or logo the brand kit does not hold (studio_brand_kit_get lists what it does)."
|
|
6152
|
+
};
|
|
6153
|
+
}
|
|
6154
|
+
if (err.status === 429 && code === "render_limit") return { ok: false, code, message };
|
|
6155
|
+
if (err.status === 429 && code === "render_busy") {
|
|
6156
|
+
return {
|
|
6157
|
+
ok: false,
|
|
6158
|
+
code,
|
|
6159
|
+
message,
|
|
6160
|
+
...typeof body.jobId === "string" ? { jobId: body.jobId } : {},
|
|
6161
|
+
hint: "One reel renders at a time per company. Wait for that render (studio_get_job with the jobId), then render this one."
|
|
6162
|
+
};
|
|
6163
|
+
}
|
|
6164
|
+
if (err.status === 404) return { ok: false, code: code ?? "not_found", message: message ?? "Not found in this company." };
|
|
6165
|
+
if (idempotencyKey && (err.status === 0 || err.status >= 500)) {
|
|
6166
|
+
return {
|
|
6167
|
+
ok: false,
|
|
6168
|
+
code: err.status === 0 ? "network_error" : "server_error",
|
|
6169
|
+
message: ctx.client.redact(err.message),
|
|
6170
|
+
idempotencyKey,
|
|
6171
|
+
hint: "The outcome is unknown. Retry with the SAME idempotencyKey: if the patch was applied, the retry replays it instead of applying twice."
|
|
6172
|
+
};
|
|
6173
|
+
}
|
|
6174
|
+
return null;
|
|
6175
|
+
}
|
|
6176
|
+
var studioListAssets = defineTool({
|
|
6177
|
+
name: "studio_list_assets",
|
|
6178
|
+
description: "List a project's assets, newest first: images (subtype Image) a carousel slide can use as its background, videos (Video) a reel can use as clips, and earlier renders (CarouselSlide, Reel). Free, read-only. Returns { assets: [{ id, subtype, url, mimeType, prompt, durationSeconds?, createdAt }] }; use the ids in studio_composition_create or _apply ops.",
|
|
6179
|
+
inputSchema: {
|
|
6180
|
+
projectId: z9.string().min(1).describe("Project id from studio_list_projects."),
|
|
6181
|
+
subtype: z9.enum(["Image", "Video", "CarouselSlide", "Reel"]).optional().describe("Only this kind: Image for slide backgrounds, Video for reel clips."),
|
|
6182
|
+
limit: z9.number().int().min(1).max(200).optional().describe("At most this many (default 50).")
|
|
6183
|
+
},
|
|
6184
|
+
handler: async (args, ctx) => {
|
|
6185
|
+
const { assets } = await ctx.client.listProjectAssets(args.projectId, {
|
|
6186
|
+
...args.subtype ? { subtype: args.subtype } : {},
|
|
6187
|
+
...args.limit ? { limit: args.limit } : {}
|
|
6188
|
+
});
|
|
6189
|
+
return {
|
|
6190
|
+
projectId: args.projectId,
|
|
6191
|
+
assets: assets.map((a) => {
|
|
6192
|
+
const seconds = typeof a.metadata?.durationSeconds === "number" ? a.metadata.durationSeconds : typeof a.metadata?.durationMs === "number" ? a.metadata.durationMs / 1e3 : void 0;
|
|
6193
|
+
return {
|
|
6194
|
+
id: a.id,
|
|
6195
|
+
subtype: a.subtype,
|
|
6196
|
+
url: a.url,
|
|
6197
|
+
mimeType: a.mimeType,
|
|
6198
|
+
prompt: a.prompt,
|
|
6199
|
+
...seconds !== void 0 ? { durationSeconds: seconds } : {},
|
|
6200
|
+
createdAt: a.createdAt
|
|
6201
|
+
};
|
|
6202
|
+
})
|
|
6203
|
+
};
|
|
6204
|
+
}
|
|
6205
|
+
});
|
|
6206
|
+
var studioBrandKitGet = defineTool({
|
|
6207
|
+
name: "studio_brand_kit_get",
|
|
6208
|
+
description: "Read a brand kit: the only colours (by id), type sizes (headline, body), fonts (primary, secondary, with the weights and styles each has) and logos (light, dark) a composition overlay may use. Free, read-only. Use the ids and roles it lists in studio_composition_apply ops; anything else is refused.",
|
|
6209
|
+
inputSchema: { brandSlug: z9.string().min(1).describe("The brand slug, as studio_create_brand made it.") },
|
|
6210
|
+
handler: async (args, ctx) => {
|
|
6211
|
+
const { kit } = await ctx.client.getBrandKit(args.brandSlug);
|
|
6212
|
+
return {
|
|
6213
|
+
brandSlug: args.brandSlug,
|
|
6214
|
+
version: kit.version,
|
|
6215
|
+
colors: kit.colors,
|
|
6216
|
+
typeRoles: kit.typeRoles,
|
|
6217
|
+
fonts: kit.fonts.map((f) => ({ role: f.role, family: f.family, files: f.files.map((x) => ({ weight: x.weight, style: x.style })) })),
|
|
6218
|
+
logos: kit.logos.map((l) => ({ variant: l.variant, width: l.width, height: l.height }))
|
|
6219
|
+
};
|
|
6220
|
+
}
|
|
6221
|
+
});
|
|
6222
|
+
var studioCompositionDescribe = defineTool({
|
|
6223
|
+
name: "studio_composition_describe",
|
|
6224
|
+
description: "Describe the composition vocabulary before building a carousel or reel: the op types, the item and overlay shapes, the aspects and Instagram limits. Free, read-only, no request.",
|
|
6225
|
+
inputSchema: {},
|
|
6226
|
+
handler: async () => ({
|
|
6227
|
+
kinds: COMPOSITION_KINDS,
|
|
6228
|
+
aspects: COMPOSITION_ASPECTS,
|
|
6229
|
+
limits: {
|
|
6230
|
+
carouselSlides: MAX_CAROUSEL_SLIDES,
|
|
6231
|
+
reelClips: MAX_REEL_CLIPS,
|
|
6232
|
+
reelSeconds: { min: REEL_MIN_SECONDS, max: REEL_MAX_SECONDS },
|
|
6233
|
+
overlaysPerItem: MAX_OVERLAYS_PER_ITEM,
|
|
6234
|
+
overlaysPerReel: MAX_REEL_OVERLAYS,
|
|
6235
|
+
reelRendersAtOnce: 1,
|
|
6236
|
+
opsPerPatch: MAX_COMPOSITION_PATCH_OPS
|
|
6237
|
+
},
|
|
6238
|
+
opTypes: COMPOSITION_OP_TYPES,
|
|
6239
|
+
shapes: {
|
|
6240
|
+
slide: '{ id, type: "slide", background: { assetId?, fit: "cover"|"contain", focal: { x, y }, fill? (kit colour id) }, overlays: [] } (an image asset of the project, or a fill)',
|
|
6241
|
+
clip: '{ id, type: "clip", assetId (a video asset of the project), trimIn, trimOut (seconds), overlays: [] }',
|
|
6242
|
+
text: '{ id, type: "text", box: { x, y, w, h } (fractions of the frame), text, styleRole: "headline"|"body", fontRole: "primary"|"secondary", weight (one the font has), italic, colorRole (kit colour id), align: "left"|"center"|"right", background?: { colorRole, opacity, padding }, start?, end? (reels only) }',
|
|
6243
|
+
logo: '{ id, type: "logo", box, variant: "light"|"dark", start?, end? }',
|
|
6244
|
+
shape: '{ id, type: "shape", box, shape: "rect"|"pill", colorRole, opacity, start?, end? }'
|
|
6245
|
+
},
|
|
6246
|
+
targets: `addOverlay, removeOverlay, moveOverlay and setOverlayProps name a target: an item id, or "${REEL_TARGET}" for an overlay across the whole reel.`,
|
|
6247
|
+
rules: [
|
|
6248
|
+
"There is no field for a hex colour, a font family or a pixel size: overlays name kit roles (studio_brand_kit_get).",
|
|
6249
|
+
"Overlays stack in list order; the last is on top.",
|
|
6250
|
+
"A carousel is 4:5 or 1:1, at most 10 slides; a reel is 9:16, 3 to 90 s.",
|
|
6251
|
+
"Setting an optional field to null clears it.",
|
|
6252
|
+
"Rendering is free: studio_composition_render."
|
|
6253
|
+
]
|
|
6254
|
+
})
|
|
6255
|
+
});
|
|
6256
|
+
var studioCompositionList = defineTool({
|
|
6257
|
+
name: "studio_composition_list",
|
|
6258
|
+
description: "List a project's carousels and reels, newest first. Free, read-only.",
|
|
6259
|
+
inputSchema: { projectId: z9.string().min(1).optional().describe("Project id from studio_list_projects; omit for the default project.") },
|
|
6260
|
+
handler: async (args, ctx) => ctx.client.listCompositions(args.projectId !== void 0 ? { projectId: args.projectId } : {})
|
|
6261
|
+
});
|
|
6262
|
+
var studioCompositionCreate = defineTool({
|
|
6263
|
+
name: "studio_composition_create",
|
|
6264
|
+
description: "Create a carousel or reel for a brand, optionally with its first ops (so one call can build a whole carousel). Returns { ok: true, composition } at revision 1, or a refusal { ok: false, code, ... } (invalid_patch names the op; not_in_kit and invalid_asset codes say what to change). Creating and editing are free.",
|
|
6265
|
+
inputSchema: {
|
|
6266
|
+
kind: z9.enum(COMPOSITION_KINDS),
|
|
6267
|
+
brandSlug: z9.string().min(1).describe("The brand whose kit the overlays use."),
|
|
6268
|
+
projectId: z9.string().min(1).optional().describe("Project id from studio_list_projects; its images and clips are what slides and clips may use. Omit for the default project."),
|
|
6269
|
+
aspect: z9.enum(COMPOSITION_ASPECTS).optional().describe("4:5 (default for a carousel) or 1:1; a reel is 9:16."),
|
|
6270
|
+
label: z9.string().max(200).optional(),
|
|
6271
|
+
ops: z9.array(CompositionOpSchema).max(MAX_COMPOSITION_PATCH_OPS).optional(),
|
|
6272
|
+
idempotencyKey: z9.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 post comes back instead of a second one.")
|
|
6273
|
+
},
|
|
6274
|
+
handler: async (args, ctx) => {
|
|
6275
|
+
const idempotencyKey = args.idempotencyKey ?? randomUUID2();
|
|
6276
|
+
try {
|
|
6277
|
+
const { composition, replayed } = await ctx.client.createComposition({
|
|
6278
|
+
idempotencyKey,
|
|
6279
|
+
kind: args.kind,
|
|
6280
|
+
brandSlug: args.brandSlug,
|
|
6281
|
+
...args.projectId !== void 0 ? { projectId: args.projectId } : {},
|
|
6282
|
+
...args.aspect !== void 0 ? { aspect: args.aspect } : {},
|
|
6283
|
+
...args.label !== void 0 ? { label: args.label } : {},
|
|
6284
|
+
...args.ops !== void 0 ? { ops: args.ops } : {}
|
|
6285
|
+
});
|
|
6286
|
+
return { ok: true, composition: summarize(composition), ...replayed ? { replayed: true } : {} };
|
|
6287
|
+
} catch (err) {
|
|
6288
|
+
const mapped = mapCompositionFailure(err, ctx, idempotencyKey);
|
|
6289
|
+
if (mapped) return mapped;
|
|
6290
|
+
throw err;
|
|
6291
|
+
}
|
|
6292
|
+
}
|
|
6293
|
+
});
|
|
6294
|
+
var studioCompositionGet = defineTool({
|
|
6295
|
+
name: "studio_composition_get",
|
|
6296
|
+
description: "Read one carousel or reel: its items, overlays and the revision to build the next patch on. Free, read-only.",
|
|
6297
|
+
inputSchema: { compositionId },
|
|
6298
|
+
handler: async (args, ctx) => {
|
|
6299
|
+
try {
|
|
6300
|
+
return { ok: true, composition: summarize((await ctx.client.getComposition(args.compositionId)).composition) };
|
|
6301
|
+
} catch (err) {
|
|
6302
|
+
const mapped = mapCompositionFailure(err, ctx);
|
|
6303
|
+
if (mapped) return mapped;
|
|
6304
|
+
throw err;
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
});
|
|
6308
|
+
var studioCompositionApply = defineTool({
|
|
6309
|
+
name: "studio_composition_apply",
|
|
6310
|
+
description: "Change a carousel or reel atomically on top of baseRevision. Success: { ok: true, composition, inverse (ops that undo this), idempotencyKey, replayed }. Refusals are results to act on: stale_revision (rebase on the composition returned), invalid_patch (error.opIndex; codes not_in_kit and invalid_asset say what to change), idempotency_mismatch (new key), network_error and server_error (retry with the SAME idempotencyKey).",
|
|
6311
|
+
inputSchema: {
|
|
6312
|
+
compositionId,
|
|
6313
|
+
baseRevision: z9.number().int().nonnegative().describe("The revision the ops were written against."),
|
|
6314
|
+
ops: opsSchema2,
|
|
6315
|
+
idempotencyKey: z9.string().min(1).max(128).optional().describe("Generated when omitted. Pass the same key only to retry the SAME patch after a network or server failure.")
|
|
6316
|
+
},
|
|
6317
|
+
handler: async (args, ctx) => {
|
|
6318
|
+
const idempotencyKey = args.idempotencyKey ?? randomUUID2();
|
|
6319
|
+
try {
|
|
6320
|
+
const res = await ctx.client.patchComposition(args.compositionId, { baseRevision: args.baseRevision, ops: args.ops, idempotencyKey });
|
|
6321
|
+
return { ok: true, composition: summarize(res.composition), inverse: res.inverse, idempotencyKey, replayed: res.replayed === true };
|
|
6322
|
+
} catch (err) {
|
|
6323
|
+
const mapped = mapCompositionFailure(err, ctx, idempotencyKey);
|
|
6324
|
+
if (mapped) return mapped;
|
|
6325
|
+
throw err;
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6328
|
+
});
|
|
6329
|
+
var studioCompositionRender = defineTool({
|
|
6330
|
+
name: "studio_composition_render",
|
|
6331
|
+
description: `Render a carousel to JPEG slides (1080 x 1350 or 1080 x 1080) or a reel to an H.264 MP4 (1080 x 1920), free, on Studio's own server. Waits by default and returns { ok: true, status, assets: [{ id, url }] } (slides in order; a reel is one asset), or { ok: false, code: "not_ready", reasons } listing everything to fix first. An identical render (same post, kit and renderer) is reused rather than redone.`,
|
|
6332
|
+
inputSchema: {
|
|
6333
|
+
compositionId,
|
|
6334
|
+
wait: z9.boolean().default(true),
|
|
6335
|
+
waitSeconds: z9.number().int().min(1).max(3600).default(600)
|
|
6336
|
+
},
|
|
6337
|
+
handler: async (args, ctx) => {
|
|
6338
|
+
let started;
|
|
6339
|
+
try {
|
|
6340
|
+
started = await ctx.client.renderComposition(args.compositionId);
|
|
6341
|
+
} catch (err) {
|
|
6342
|
+
const mapped = mapCompositionFailure(err, ctx);
|
|
6343
|
+
if (mapped) return mapped;
|
|
6344
|
+
throw err;
|
|
6345
|
+
}
|
|
6346
|
+
if (!args.wait) return { ok: true, jobId: started.jobId, reused: started.reused, status: "pending" };
|
|
6347
|
+
const res = await waitForJob(ctx.client, started.jobId, { timeoutMs: args.waitSeconds * 1e3 });
|
|
6348
|
+
const assets = [...res.resultAssets ?? (res.resultAsset ? [res.resultAsset] : [])].map((a) => ({ id: a.id, url: a.url, slideIndex: isRecord2(a.metadata) ? a.metadata.slideIndex : void 0 })).sort((a, b) => Number(a.slideIndex ?? 0) - Number(b.slideIndex ?? 0));
|
|
6349
|
+
if (res.job.status !== "succeeded") {
|
|
6350
|
+
return { ok: false, code: "render_failed", jobId: started.jobId, status: res.job.status, message: res.job.errorMessage ? ctx.client.redact(res.job.errorMessage) : null };
|
|
6351
|
+
}
|
|
6352
|
+
return { ok: true, jobId: started.jobId, reused: started.reused, status: res.job.status, assets };
|
|
6353
|
+
}
|
|
6354
|
+
});
|
|
6355
|
+
var SOCIAL_HINTS = {
|
|
6356
|
+
not_connected: "This company is not connected to Lumitra Social. A company owner or admin connects it once in Studio (Posts editor, Send to Social) with a company API key; ask the user to do that.",
|
|
6357
|
+
link_broken: "Lumitra Social no longer accepts the company key. A company owner or admin must connect again in Studio with a new key; ask the user.",
|
|
6358
|
+
not_rendered: "Render the post as it is now (studio_composition_render), then send again with a NEW idempotencyKey.",
|
|
6359
|
+
idempotency_mismatch: "That idempotencyKey belongs to a different send: use a new one.",
|
|
6360
|
+
social_refused: "Lumitra Social refused it; the message says why (an unknown project slug, for one). Fix that and send with a NEW idempotencyKey.",
|
|
6361
|
+
invalid_body: "Fix the field the message names (a time in the past, for one) and send with a NEW idempotencyKey."
|
|
6362
|
+
};
|
|
6363
|
+
var studioSocialListProjects = defineTool({
|
|
6364
|
+
name: "studio_social_list_projects",
|
|
6365
|
+
description: "List the company's Lumitra Social projects (each is one Instagram account in the planner) to send a post to, and the one this brand last went to. Free, read-only. Returns { ok: true, projects: [{ slug, name, igHandle }], lastProjectSlug }, or { ok: false, code } when the company is not connected (an owner connects it in Studio).",
|
|
6366
|
+
inputSchema: {
|
|
6367
|
+
brandSlug: z9.string().min(1).optional().describe("The brand of the post, to learn which project it went to last.")
|
|
6368
|
+
},
|
|
6369
|
+
handler: async (args, ctx) => {
|
|
6370
|
+
try {
|
|
6371
|
+
const { projects, lastProjectSlug } = await ctx.client.listSocialProjects(args.brandSlug);
|
|
6372
|
+
return { ok: true, projects: projects.map((p) => ({ slug: p.slug, name: p.name, igHandle: p.igHandle ?? null })), lastProjectSlug };
|
|
6373
|
+
} catch (err) {
|
|
6374
|
+
if (err instanceof StudioApiError) {
|
|
6375
|
+
const body = isRecord2(err.body) ? err.body : {};
|
|
6376
|
+
const code = typeof body.code === "string" ? body.code : null;
|
|
6377
|
+
if (code && SOCIAL_HINTS[code]) return { ok: false, code, message: typeof body.message === "string" ? ctx.client.redact(body.message) : null, hint: SOCIAL_HINTS[code] };
|
|
6378
|
+
if (err.status === 503) return { ok: false, code: "social_unavailable", hint: "Lumitra Social did not answer; try again shortly." };
|
|
6379
|
+
}
|
|
6380
|
+
throw err;
|
|
6381
|
+
}
|
|
6382
|
+
}
|
|
6383
|
+
});
|
|
6384
|
+
var studioCompositionSendToSocial = defineTool({
|
|
6385
|
+
name: "studio_composition_send_to_social",
|
|
6386
|
+
description: "Send a rendered post to Lumitra Social as a draft or scheduled post. The post must be rendered at its current revision (studio_composition_render); a reel goes as a reel, a single-slide carousel as a feed image, and a carousel of 2 to 10 slides as an Instagram carousel in the same order as the editor. This creates a post in the company planner, which publishes it to Instagram at scheduledAt: confirm the project, caption and time with the user before sending. Returns { ok: true, send: { status, format, projectSlug, scheduledAt, plannerUrl }, replayed } or a refusal { ok: false, code, hint }. On social_unavailable, network_error or server_error, retry with the SAME idempotencyKey: the send resumes and never posts twice.",
|
|
6387
|
+
inputSchema: {
|
|
6388
|
+
compositionId,
|
|
6389
|
+
projectSlug: z9.string().min(1).describe("The Lumitra Social project slug, from studio_social_list_projects."),
|
|
6390
|
+
caption: z9.string().max(2200).optional(),
|
|
6391
|
+
hashtags: z9.string().max(2200).optional().describe("Space-separated, at most 30 (Instagram counts them with the caption toward 2200 characters)."),
|
|
6392
|
+
scheduledAt: z9.string().datetime({ offset: true }).nullable().optional().describe("ISO date-time with an offset; omit or null for a draft the user schedules in the planner."),
|
|
6393
|
+
idempotencyKey: z9.string().min(1).max(200).optional().describe("Omit on a first send (one is generated); pass the returned one to retry.")
|
|
6394
|
+
},
|
|
6395
|
+
handler: async (args, ctx) => {
|
|
6396
|
+
const idempotencyKey = args.idempotencyKey ?? randomUUID2();
|
|
6397
|
+
try {
|
|
6398
|
+
const { send, replayed } = await ctx.client.sendCompositionToSocial(args.compositionId, {
|
|
6399
|
+
projectSlug: args.projectSlug,
|
|
6400
|
+
...args.caption !== void 0 ? { caption: args.caption } : {},
|
|
6401
|
+
...args.hashtags !== void 0 ? { hashtags: args.hashtags } : {},
|
|
6402
|
+
scheduledAt: args.scheduledAt ?? null,
|
|
6403
|
+
idempotencyKey
|
|
6404
|
+
});
|
|
6405
|
+
return {
|
|
6406
|
+
ok: true,
|
|
6407
|
+
replayed,
|
|
6408
|
+
send: { status: send.status, format: send.format, projectSlug: send.projectSlug, scheduledAt: send.scheduledAt, plannerUrl: send.plannerUrl }
|
|
6409
|
+
};
|
|
6410
|
+
} catch (err) {
|
|
6411
|
+
if (err instanceof StudioApiError) {
|
|
6412
|
+
const body = isRecord2(err.body) ? err.body : {};
|
|
6413
|
+
const code = typeof body.code === "string" ? body.code : null;
|
|
6414
|
+
const message = typeof body.message === "string" ? ctx.client.redact(body.message) : null;
|
|
6415
|
+
if (code && SOCIAL_HINTS[code]) return { ok: false, code, message, hint: SOCIAL_HINTS[code] };
|
|
6416
|
+
if (err.status === 404) return { ok: false, code: "not_found", message: message ?? "Not found in this company." };
|
|
6417
|
+
if (err.status === 0 || err.status >= 500) {
|
|
6418
|
+
return {
|
|
6419
|
+
ok: false,
|
|
6420
|
+
code: err.status === 0 ? "network_error" : code === "social_unavailable" ? code : "server_error",
|
|
6421
|
+
message: message ?? ctx.client.redact(err.message),
|
|
6422
|
+
idempotencyKey,
|
|
6423
|
+
hint: "The outcome may be partial. Retry with the SAME idempotencyKey: the send resumes where it stopped and never posts twice."
|
|
6424
|
+
};
|
|
6425
|
+
}
|
|
6426
|
+
}
|
|
6427
|
+
throw err;
|
|
6428
|
+
}
|
|
6429
|
+
}
|
|
6430
|
+
});
|
|
6431
|
+
var COMPOSITION_TOOLS = [
|
|
6432
|
+
studioListAssets,
|
|
6433
|
+
studioBrandKitGet,
|
|
6434
|
+
studioCompositionDescribe,
|
|
6435
|
+
studioCompositionList,
|
|
6436
|
+
studioCompositionCreate,
|
|
6437
|
+
studioCompositionGet,
|
|
6438
|
+
studioCompositionApply,
|
|
6439
|
+
studioCompositionRender,
|
|
6440
|
+
studioSocialListProjects,
|
|
6441
|
+
studioCompositionSendToSocial
|
|
6442
|
+
];
|
|
6443
|
+
|
|
6444
|
+
// src/manageTools.ts
|
|
6445
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
6446
|
+
import { z as z10 } from "zod";
|
|
5672
6447
|
var TOKEN_TTL_MS = 10 * 60 * 1e3;
|
|
5673
6448
|
var ConfirmationStore = class {
|
|
5674
6449
|
#tokens = /* @__PURE__ */ new Map();
|
|
@@ -5678,7 +6453,7 @@ var ConfirmationStore = class {
|
|
|
5678
6453
|
}
|
|
5679
6454
|
issue(subject) {
|
|
5680
6455
|
this.#sweep();
|
|
5681
|
-
const token =
|
|
6456
|
+
const token = randomUUID3();
|
|
5682
6457
|
this.#tokens.set(token, { subject, expiresAt: this.#now() + TOKEN_TTL_MS });
|
|
5683
6458
|
return token;
|
|
5684
6459
|
}
|
|
@@ -5755,21 +6530,21 @@ function roleRefusal(err, sentence) {
|
|
|
5755
6530
|
}
|
|
5756
6531
|
throw err;
|
|
5757
6532
|
}
|
|
5758
|
-
var confirmationToken =
|
|
6533
|
+
var confirmationToken = z10.string().min(1).optional().describe(
|
|
5759
6534
|
"Only for a client that cannot show a confirmation dialog: the confirmationToken a previous call returned, sent after the person said yes in the chat to the summary it came with."
|
|
5760
6535
|
);
|
|
5761
6536
|
var studioCreateProject = defineTool({
|
|
5762
6537
|
name: "studio_create_project",
|
|
5763
6538
|
description: "Create a project in your company: a workspace that keeps saved workflows, runs, assets and chats together (characters, products, locations, brands and campaigns are shared by every project). Only a name is needed; its slug is derived. A name the company already uses is refused (409 name_taken). Returns the project with its id, for projectId on the other tools.",
|
|
5764
|
-
inputSchema: { name:
|
|
6539
|
+
inputSchema: { name: z10.string().min(1).max(120).describe("The project name, as people in the company will see it.") },
|
|
5765
6540
|
handler: async (args, ctx) => (await ctx.client.createProject(args.name)).project
|
|
5766
6541
|
});
|
|
5767
6542
|
var studioRenameProject = defineTool({
|
|
5768
6543
|
name: "studio_rename_project",
|
|
5769
6544
|
description: `Rename a project of your company (any member may). The slug follows the new name, except for the company's default project, which keeps the slug "default". A name another project of the company uses is refused (409 name_taken).`,
|
|
5770
6545
|
inputSchema: {
|
|
5771
|
-
projectId:
|
|
5772
|
-
name:
|
|
6546
|
+
projectId: z10.string().min(1).describe("The project, from studio_list_projects."),
|
|
6547
|
+
name: z10.string().min(1).max(120).describe("The new name.")
|
|
5773
6548
|
},
|
|
5774
6549
|
annotations: { idempotentHint: true },
|
|
5775
6550
|
handler: async (args, ctx) => (await ctx.client.renameProject(args.projectId, args.name)).project
|
|
@@ -5778,7 +6553,7 @@ var studioDeleteProject = defineTool({
|
|
|
5778
6553
|
name: "studio_delete_project",
|
|
5779
6554
|
description: "Delete a project of your company for everyone, with its saved workflows, runs, assets (and their stored files) and chats. Needs a key with the company admin role. The PERSON confirms every delete in the chat: this tool reads what would be removed and asks them through the client's confirmation dialog before anything happens. If the client has no such dialog, the tool returns `confirmationRequired` with a `summary` and a `confirmationToken`: show the summary to the person exactly as written, and only after they explicitly say yes call again with the token. Never confirm on their behalf. The company's default project cannot be deleted, nor a project with a run or generation still going; the tool says so instead. The record of what the project cost is kept (it moves to the default project).",
|
|
5780
6555
|
inputSchema: {
|
|
5781
|
-
projectId:
|
|
6556
|
+
projectId: z10.string().min(1).describe("The project to delete, from studio_list_projects."),
|
|
5782
6557
|
confirmationToken
|
|
5783
6558
|
},
|
|
5784
6559
|
annotations: { destructiveHint: true },
|
|
@@ -5807,7 +6582,7 @@ var studioDeleteProject = defineTool({
|
|
|
5807
6582
|
var studioListWorkflows = defineTool({
|
|
5808
6583
|
name: "studio_list_workflows",
|
|
5809
6584
|
description: "List the saved workflows of one project (savedId, label, version). Omit projectId for the company's default project. Use the savedId with studio_workflow_get, studio_run_workflow or studio_move_workflow.",
|
|
5810
|
-
inputSchema: { projectId:
|
|
6585
|
+
inputSchema: { projectId: z10.string().min(1).optional().describe("The project, from studio_list_projects. Omit for the default project.") },
|
|
5811
6586
|
annotations: { readOnlyHint: true },
|
|
5812
6587
|
handler: async (args, ctx) => {
|
|
5813
6588
|
const { workflows } = await ctx.client.listWorkflows(args.projectId ? { projectId: args.projectId } : {});
|
|
@@ -5818,9 +6593,9 @@ var studioMoveWorkflow = defineTool({
|
|
|
5818
6593
|
name: "studio_move_workflow",
|
|
5819
6594
|
description: "Move a saved workflow to another project of your company, together with its runs, their jobs and the assets they produced, so every node keeps its results and nothing has to be generated again. Reversible: move it back the same way. projectId is the project it is in now (omit for the default project); toProjectId is required. Refused while a run of the workflow is still going (409 run_in_flight), and for a project of another company (404).",
|
|
5820
6595
|
inputSchema: {
|
|
5821
|
-
savedId:
|
|
5822
|
-
toProjectId:
|
|
5823
|
-
projectId:
|
|
6596
|
+
savedId: z10.string().min(1).describe('The saved workflow, from studio_list_workflows (starts with "saved:").'),
|
|
6597
|
+
toProjectId: z10.string().min(1).describe("The project to move it to, from studio_list_projects."),
|
|
6598
|
+
projectId: z10.string().min(1).optional().describe("The project the workflow is in now. Omit for the default project.")
|
|
5824
6599
|
},
|
|
5825
6600
|
handler: async (args, ctx) => ctx.client.moveWorkflow(args.savedId, { toProjectId: args.toProjectId, ...args.projectId ? { projectId: args.projectId } : {} })
|
|
5826
6601
|
});
|
|
@@ -5835,7 +6610,7 @@ var studioDeleteCampaign = defineTool({
|
|
|
5835
6610
|
name: "studio_delete_campaign",
|
|
5836
6611
|
description: "Delete a campaign of your company with its shot list and every approve and reject decision. Its images stay in the asset library. The PERSON confirms every delete in the chat: this tool shows them what goes and what stays through the client's confirmation dialog before anything happens. If the client has no such dialog, the tool returns `confirmationRequired` with a `summary` and a `confirmationToken`: show the summary to the person exactly as written, and only after they explicitly say yes call again with the token. Never confirm on their behalf. Refused while a shot is still rendering; the tool says so instead.",
|
|
5837
6612
|
inputSchema: {
|
|
5838
|
-
campaignId:
|
|
6613
|
+
campaignId: z10.string().min(1).describe("The campaign, from studio_list_campaigns."),
|
|
5839
6614
|
confirmationToken
|
|
5840
6615
|
},
|
|
5841
6616
|
annotations: { destructiveHint: true },
|
|
@@ -5869,9 +6644,9 @@ var MANAGE_TOOLS = [
|
|
|
5869
6644
|
];
|
|
5870
6645
|
|
|
5871
6646
|
// src/tools.ts
|
|
5872
|
-
var slug =
|
|
5873
|
-
var waitSeconds =
|
|
5874
|
-
var httpUrl =
|
|
6647
|
+
var slug = z11.string().regex(/^[a-z0-9-]+$/, "lowercase letters, numbers and hyphens only").describe("URL-safe identifier: lowercase letters, numbers, hyphens.");
|
|
6648
|
+
var waitSeconds = z11.number().int().min(1).max(3600).default(DEFAULT_TIMEOUT_MS / 1e3).describe("Maximum seconds to wait before giving up and returning the id to poll later. Default 600.");
|
|
6649
|
+
var httpUrl = z11.string().url().refine((u) => /^https?:\/\//i.test(u), "must be an http(s) URL");
|
|
5875
6650
|
function pollOpts(ctx, timeoutSec) {
|
|
5876
6651
|
return { ...ctx.poll, timeoutMs: timeoutSec * 1e3 };
|
|
5877
6652
|
}
|
|
@@ -5947,22 +6722,22 @@ var studioGenerateImage = defineTool({
|
|
|
5947
6722
|
brandSlug: slug.optional().describe(
|
|
5948
6723
|
"Optional. The slug of a brand of your company (create one with studio_create_brand). Omit it to generate without a brand. A slug that names no brand of your company is refused with 404 input_not_found; it is never used as a project name."
|
|
5949
6724
|
),
|
|
5950
|
-
brandMode:
|
|
5951
|
-
prompt:
|
|
6725
|
+
brandMode: z11.string().optional().describe('Optional brand mode (e.g. "illustration"); modes are defined per brand. Only meaningful with brandSlug.'),
|
|
6726
|
+
prompt: z11.string().min(1).describe("What to generate. With brandSlug, the brand style prefix is prepended server-side."),
|
|
5952
6727
|
characterSlug: slug.optional().describe(
|
|
5953
6728
|
"Optional character whose identity references are injected: one of your company's, or one another company shared (see studio_list_characters). A slug your company cannot use is refused with 404 input_not_found."
|
|
5954
6729
|
),
|
|
5955
|
-
projectId:
|
|
6730
|
+
projectId: z11.string().min(1).optional().describe(
|
|
5956
6731
|
'Optional project to file the image under (an id from studio_list_projects; it must be a project of your company, anything else is a 404). Omit it to use the project named after brandSlug, or "default" when there is no brand.'
|
|
5957
6732
|
),
|
|
5958
|
-
model:
|
|
5959
|
-
aspectRatio:
|
|
5960
|
-
imageSize:
|
|
5961
|
-
seed:
|
|
5962
|
-
candidateCount:
|
|
6733
|
+
model: z11.string().optional().describe('Image model id (e.g. "kie/nano-banana-2", "fal/nano-banana-2"). Omit for the Studio default.'),
|
|
6734
|
+
aspectRatio: z11.string().optional().describe('Aspect ratio such as "1:1", "16:9", "3:4".'),
|
|
6735
|
+
imageSize: z11.string().optional().describe('Provider size hint, e.g. "1K", "2K".'),
|
|
6736
|
+
seed: z11.number().int().optional(),
|
|
6737
|
+
candidateCount: z11.number().int().min(1).max(4).optional().describe(
|
|
5963
6738
|
"Number of candidates (1 to 4). Not every model takes a count: most KIE image models render one image whatever is asked, and a `route/...` model runs on KIE first, so expect one there too (its fal fallback may render up to four). The result carries `candidates: { requested, rendered, mayRender? }`, plus a `notice` whenever fewer will be rendered than were asked for; only rendered images are charged."
|
|
5964
6739
|
),
|
|
5965
|
-
wait:
|
|
6740
|
+
wait: z11.boolean().default(true).describe("Poll until the job finishes (default true)."),
|
|
5966
6741
|
waitSeconds
|
|
5967
6742
|
},
|
|
5968
6743
|
handler: async (args, ctx) => {
|
|
@@ -5998,23 +6773,23 @@ var studioGenerate3d = defineTool({
|
|
|
5998
6773
|
name: "studio_generate_3d",
|
|
5999
6774
|
description: "Generate one 3D model (a textured GLB mesh) through 3D AI Studio, from a text prompt or from one image (imageUrl). Text models: studio3d/tripo-3-1-text-to-3d (the default), studio3d/hunyuan-3-1-rapid, studio3d/hunyuan-3-1-pro. Image models: studio3d/trellis-2 (the default when imageUrl is given), studio3d/tripo-3-1-image-to-3d. Submits a job and, when wait=true (default), polls until it finishes (usually one to five minutes) and returns the signed GLB URL and its cost in USD (Studio prices the request it sent, since 3D AI Studio reports no per-job charge). With wait=false it returns the jobId for studio_get_job. The price follows the model and the quality flags; the returned costUsd is the exact amount.",
|
|
6000
6775
|
inputSchema: {
|
|
6001
|
-
prompt:
|
|
6776
|
+
prompt: z11.string().min(1).max(1024).describe("What to model. With imageUrl, a short description of the object in the image."),
|
|
6002
6777
|
imageUrl: httpUrl.optional().describe("Public http(s) URL of one image to model from. Selects an image model."),
|
|
6003
|
-
model:
|
|
6004
|
-
options:
|
|
6005
|
-
enableTexture:
|
|
6006
|
-
enablePbr:
|
|
6007
|
-
textureQuality:
|
|
6008
|
-
geometryQuality:
|
|
6009
|
-
quadRemesh:
|
|
6010
|
-
smartLowPoly:
|
|
6011
|
-
resolution:
|
|
6012
|
-
targetPolycount:
|
|
6013
|
-
topology:
|
|
6014
|
-
seed:
|
|
6778
|
+
model: z11.string().min(1).optional().describe("3D model id from the list in the description. Omit for the default (text or image, by whether imageUrl is given)."),
|
|
6779
|
+
options: z11.object({
|
|
6780
|
+
enableTexture: z11.boolean().optional().describe("Texture the mesh (default true). Off gives bare geometry and costs less."),
|
|
6781
|
+
enablePbr: z11.boolean().optional().describe("Physically-based rendering (PBR) material maps. Default on for Hunyuan Pro, off elsewhere."),
|
|
6782
|
+
textureQuality: z11.enum(["standard", "detailed"]).optional().describe("Tripo texture tier. detailed costs more."),
|
|
6783
|
+
geometryQuality: z11.enum(["standard", "detailed"]).optional().describe("Tripo geometry tier. detailed costs more."),
|
|
6784
|
+
quadRemesh: z11.boolean().optional().describe("Tripo: quad topology instead of triangles."),
|
|
6785
|
+
smartLowPoly: z11.boolean().optional().describe("Tripo text-to-3D: a low-poly mesh."),
|
|
6786
|
+
resolution: z11.enum(["512", "1024", "1536"]).optional().describe("TRELLIS.2 resolution (default 1024)."),
|
|
6787
|
+
targetPolycount: z11.number().int().min(100).max(15e5).optional().describe("Target face count, where the model supports one."),
|
|
6788
|
+
topology: z11.enum(["quad", "triangle"]).optional().describe("Hunyuan Pro polygon type."),
|
|
6789
|
+
seed: z11.number().int().optional()
|
|
6015
6790
|
}).optional().describe("Model-specific quality flags. Each changes the price; the returned costUsd is the price of the request that was sent."),
|
|
6016
|
-
projectId:
|
|
6017
|
-
wait:
|
|
6791
|
+
projectId: z11.string().min(1).optional().describe("Project to file the model under (from studio_list_projects). Omit for the default project."),
|
|
6792
|
+
wait: z11.boolean().default(true).describe("Poll until the job finishes (default true)."),
|
|
6018
6793
|
waitSeconds
|
|
6019
6794
|
},
|
|
6020
6795
|
handler: async (args, ctx) => {
|
|
@@ -6052,8 +6827,8 @@ var studioFindAnimations = defineTool({
|
|
|
6052
6827
|
name: "studio_find_animations",
|
|
6053
6828
|
description: 'Search Meshy\'s animation library (678 presets in five categories: WalkAndRun, BodyMovements, DailyActions, Fighting, Dancing) for the presets studio_rig_3d can apply. Every word of the query must match a preset\'s name, category or subcategory (e.g. "sword", "walking woman", "dance"). Free and local: no request, no cost. Returns id, name and category for up to `limit` matches.',
|
|
6054
6829
|
inputSchema: {
|
|
6055
|
-
query:
|
|
6056
|
-
limit:
|
|
6830
|
+
query: z11.string().describe('Words to match, e.g. "sword slash". Empty returns the first presets in library order.'),
|
|
6831
|
+
limit: z11.number().int().min(1).max(50).default(25)
|
|
6057
6832
|
},
|
|
6058
6833
|
annotations: { readOnlyHint: true },
|
|
6059
6834
|
handler: async (args) => ({ animations: searchAnimations(args.query, args.limit) })
|
|
@@ -6062,12 +6837,12 @@ var studioRig3d = defineTool({
|
|
|
6062
6837
|
name: "studio_rig_3d",
|
|
6063
6838
|
description: "Rig a humanoid 3D model and animate it (Meshy on fal): adds a skeleton and skin weights to a Model3D asset and applies up to 10 animation presets from Meshy's library; walk and run clips always come with the rig. Pass the mesh's assetId (studio_generate_3d returns it as assetId) and presets as names or ids (find them with studio_find_animations). Runs as a one-node workflow, so the cost gate and quota apply. Waits by default (usually one to three minutes) and returns the rigged GLB url, each clip's name and url, and costUsd (what it cost your company: a price per rig plus a price per preset). Humanoid characters only: an animal or an object will fail at the provider.",
|
|
6064
6839
|
inputSchema: {
|
|
6065
|
-
projectId:
|
|
6066
|
-
meshAssetId:
|
|
6067
|
-
animations:
|
|
6068
|
-
heightMeters:
|
|
6069
|
-
visibility:
|
|
6070
|
-
wait:
|
|
6840
|
+
projectId: z11.string().min(1).describe("The project the mesh lives in (from studio_list_projects)."),
|
|
6841
|
+
meshAssetId: z11.string().min(1).describe("The Model3D asset to rig: the assetId studio_generate_3d returned."),
|
|
6842
|
+
animations: z11.array(z11.union([z11.string().min(1), z11.number().int()])).max(RIG_MAX_CLIPS).default([]).describe('Up to 10 presets, each a name ("Double_Combo_Attack", or loosely "double combo attack") or an id. Empty rigs with only the included walk and run.'),
|
|
6843
|
+
heightMeters: z11.number().min(0.3).max(5).optional().describe("The character's approximate height in meters (default 1.7); Meshy scales the rig to it."),
|
|
6844
|
+
visibility: z11.enum(["listed", "unlisted"]).optional(),
|
|
6845
|
+
wait: z11.boolean().default(true).describe("Poll until the rig finishes (default true)."),
|
|
6071
6846
|
waitSeconds
|
|
6072
6847
|
},
|
|
6073
6848
|
handler: async (args, ctx) => {
|
|
@@ -6124,8 +6899,8 @@ var studioGetJob = defineTool({
|
|
|
6124
6899
|
name: "studio_get_job",
|
|
6125
6900
|
description: "Fetch the status of a generation job by jobId: status (queued, running, succeeded, failed, canceled), cost, model, error message and a freshly signed result URL once it succeeded. Set wait=true to block until the job reaches a terminal state.",
|
|
6126
6901
|
inputSchema: {
|
|
6127
|
-
jobId:
|
|
6128
|
-
wait:
|
|
6902
|
+
jobId: z11.string().min(1),
|
|
6903
|
+
wait: z11.boolean().default(false).describe("Poll until terminal (default false: return the current state)."),
|
|
6129
6904
|
waitSeconds
|
|
6130
6905
|
},
|
|
6131
6906
|
annotations: { readOnlyHint: true },
|
|
@@ -6155,7 +6930,7 @@ var studioGetCharacter = defineTool({
|
|
|
6155
6930
|
}
|
|
6156
6931
|
});
|
|
6157
6932
|
var LIKENESS_REFUSAL = `${LIKENESS_CONFIRMATION_REQUIRED_CODE}: ${likenessConfirmationRequiredMessage()}`;
|
|
6158
|
-
var likenessRightsConfirmed =
|
|
6933
|
+
var likenessRightsConfirmed = z11.literal(true, { error: LIKENESS_REFUSAL }).describe(likenessConfirmationToolDescription());
|
|
6159
6934
|
function assertLikenessRightsConfirmed(value) {
|
|
6160
6935
|
if (!isLikenessRightsConfirmed(value)) throw new Error(LIKENESS_REFUSAL);
|
|
6161
6936
|
}
|
|
@@ -6163,11 +6938,11 @@ var studioCreateCharacter = defineTool({
|
|
|
6163
6938
|
name: "studio_create_character",
|
|
6164
6939
|
description: "Create an empty character record (no reference images yet). Prefer studio_mint_character, which generates the 7-view identity sheet and freezes it as references in one call. Use this only when you will upload your own reference images. Requires likenessRightsConfirmed: true, which you may only pass after the human you act for confirmed it for this character. Fails with 409 (code slug_taken) only if your own company already has a character with this slug; a slug another company uses is free to take.",
|
|
6165
6940
|
inputSchema: {
|
|
6166
|
-
name:
|
|
6941
|
+
name: z11.string().min(1).describe('Display name, e.g. "Bruno Hartmann".'),
|
|
6167
6942
|
slug,
|
|
6168
|
-
descriptorPrompt:
|
|
6169
|
-
negativePrompt:
|
|
6170
|
-
defaultModel:
|
|
6943
|
+
descriptorPrompt: z11.string().min(1).describe("The identity description prepended to every generation that uses this character."),
|
|
6944
|
+
negativePrompt: z11.string().optional(),
|
|
6945
|
+
defaultModel: z11.string().optional().describe("Default image model id for this character."),
|
|
6171
6946
|
likenessRightsConfirmed
|
|
6172
6947
|
},
|
|
6173
6948
|
handler: async (args, ctx) => {
|
|
@@ -6187,16 +6962,16 @@ var studioMintCharacter = defineTool({
|
|
|
6187
6962
|
name: "studio_mint_character",
|
|
6188
6963
|
description: "Mint a consistent character from a text description: runs the curated character-sheet workflow (seed face with fal/nano-banana-2, then six identity-pinned edits with fal/nano-banana-2-edit: three-quarter, profile, full-body, close-up, warm lighting, cool lighting), waits for it, creates the character, and uploads the 7 views as frozen references with the right categories. Returns the slug, reference count, per-view URLs, the runId and total cost (about $0.30). The description should cover face, hair, age, build and distinguishing features; wardrobe is standardized to a plain gray tee. Takes 2 to 5 minutes. Requires likenessRightsConfirmed: true, which you may only pass after the human you act for confirmed it for this character; without it the tool refuses before the run starts, so nothing is spent.",
|
|
6189
6964
|
inputSchema: {
|
|
6190
|
-
projectId:
|
|
6191
|
-
name:
|
|
6965
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
6966
|
+
name: z11.string().min(1).describe("Display name."),
|
|
6192
6967
|
slug,
|
|
6193
|
-
description:
|
|
6194
|
-
descriptorPrompt:
|
|
6195
|
-
negativePrompt:
|
|
6196
|
-
defaultModel:
|
|
6197
|
-
seedModel:
|
|
6198
|
-
viewModel:
|
|
6199
|
-
visibility:
|
|
6968
|
+
description: z11.string().min(10).describe("Seed identity description (face, hair, age, build, distinguishing features)."),
|
|
6969
|
+
descriptorPrompt: z11.string().optional().describe("Override for the character's stored descriptor prompt. Defaults to the description."),
|
|
6970
|
+
negativePrompt: z11.string().optional(),
|
|
6971
|
+
defaultModel: z11.string().optional(),
|
|
6972
|
+
seedModel: z11.string().optional().describe("Override the seed text-to-image model (default fal/nano-banana-2)."),
|
|
6973
|
+
viewModel: z11.string().optional().describe("Override the view image-edit model (default fal/nano-banana-2-edit)."),
|
|
6974
|
+
visibility: z11.enum(["listed", "unlisted"]).optional().describe("Whether the run shows in the Studio workflow list."),
|
|
6200
6975
|
likenessRightsConfirmed,
|
|
6201
6976
|
waitSeconds
|
|
6202
6977
|
},
|
|
@@ -6255,12 +7030,12 @@ var studioCreateBrand = defineTool({
|
|
|
6255
7030
|
name: "studio_create_brand",
|
|
6256
7031
|
description: "Create a brand (a style preset: name, slug, optional style prefix prepended to every prompt, optional free-text context). Upload reference images afterwards with studio_upload_brand_reference. Fails with 409 (code slug_taken) only if your own company already has a brand with this slug; a slug another company uses is free to take.",
|
|
6257
7032
|
inputSchema: {
|
|
6258
|
-
name:
|
|
7033
|
+
name: z11.string().min(1),
|
|
6259
7034
|
slug,
|
|
6260
|
-
stylePrefix:
|
|
6261
|
-
context:
|
|
6262
|
-
defaultModel:
|
|
6263
|
-
maxReferenceImages:
|
|
7035
|
+
stylePrefix: z11.string().optional().describe("Text prepended to every prompt generated under this brand."),
|
|
7036
|
+
context: z11.string().optional().describe("Markdown brand context (tone, palette, do/don't)."),
|
|
7037
|
+
defaultModel: z11.string().optional(),
|
|
7038
|
+
maxReferenceImages: z11.number().int().min(0).max(8).optional()
|
|
6264
7039
|
},
|
|
6265
7040
|
handler: async (args, ctx) => {
|
|
6266
7041
|
const { config } = await ctx.client.createBrand({
|
|
@@ -6279,11 +7054,11 @@ var studioUploadBrandReference = defineTool({
|
|
|
6279
7054
|
description: `Upload one reference image to a brand's library from a local file path or an http(s) URL. The Studio converts it to a 512px WebP and injects it into generations under that brand (up to the brand's maxReferenceImages). Category groups references (default "general"); tags and a 1 to 10 quality score are optional.`,
|
|
6280
7055
|
inputSchema: {
|
|
6281
7056
|
brandSlug: slug.describe("The slug of a brand of your company (from studio_create_brand). A slug that names no brand of your company is a 404, and nothing is uploaded."),
|
|
6282
|
-
source:
|
|
6283
|
-
category:
|
|
6284
|
-
label:
|
|
6285
|
-
tags:
|
|
6286
|
-
score:
|
|
7057
|
+
source: z11.string().min(1).describe("Local file path or http(s) URL of an image."),
|
|
7058
|
+
category: z11.string().optional().describe('Library category, default "general".'),
|
|
7059
|
+
label: z11.string().optional().describe("Optional file name / label."),
|
|
7060
|
+
tags: z11.array(z11.string()).optional(),
|
|
7061
|
+
score: z11.number().int().min(1).max(10).optional()
|
|
6287
7062
|
},
|
|
6288
7063
|
handler: async (args, ctx) => {
|
|
6289
7064
|
const file = await loadImageSource(args.source, ctx.client);
|
|
@@ -6298,29 +7073,32 @@ var studioUploadBrandReference = defineTool({
|
|
|
6298
7073
|
}
|
|
6299
7074
|
});
|
|
6300
7075
|
var workflowDefinitionSchema = WorkflowDefinitionSchema.describe(
|
|
6301
|
-
|
|
7076
|
+
`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.`
|
|
6302
7077
|
);
|
|
6303
7078
|
var studioRunWorkflow = defineTool({
|
|
6304
7079
|
name: "studio_run_workflow",
|
|
6305
|
-
description: `Run a generation workflow DAG. Pass an inline definition (nodes of provider calls wired by ref bindings; this is what the hosted Studio accepts) or the savedId of a workflow saved in the Studio (the Studio runs that workflow's current document, exactly what the canvas would run). Params fill {kind:"param"} bindings. Returns the runId plus per-node status, URLs and cost; with wait=true (default) it blocks until the run is terminal (succeeded, failed, partial, cancelled). Each node becomes a paid job. Use an inline definition ONLY for the first batch of a new deliverable (one workflow, a node per item, a stable label); a follow-up on an existing item belongs in that saved workflow as a new node (studio_workflow_apply: addNode plus connect from the node it refines) run here with savedId and nodeIds, because every listed inline run is saved as its own workflow.`,
|
|
7080
|
+
description: `Run a generation workflow DAG. Pass an inline definition (nodes of provider calls wired by ref bindings; this is what the hosted Studio accepts) or the savedId of a workflow saved in the Studio (the Studio runs that workflow's current document, exactly what the canvas would run). Params fill {kind:"param"} bindings. Returns the runId plus per-node status, URLs and cost; with wait=true (default) it blocks until the run is terminal (succeeded, failed, partial, cancelled). Each node becomes a paid job. Use an inline definition ONLY for the first batch of a new deliverable (one workflow, a node per item, a stable label); a follow-up on an existing item belongs in that saved workflow as a new node (studio_workflow_apply: addNode plus connect from the node it refines) run here with savedId and nodeIds, because every listed inline run is saved as its own workflow. A clip with both a start and an end frame is checked for continuity before it is paid for (see acknowledgeContinuity).`,
|
|
6306
7081
|
inputSchema: {
|
|
6307
|
-
projectId:
|
|
7082
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
6308
7083
|
definition: workflowDefinitionSchema.optional(),
|
|
6309
|
-
savedId:
|
|
6310
|
-
params:
|
|
6311
|
-
nodeIds:
|
|
6312
|
-
upstreamGenerations:
|
|
7084
|
+
savedId: z11.string().optional().describe("Id of a saved workflow (from studio_workflow_create, studio_workflow_get or a listed run) to run instead of an inline definition. An unknown id is a 404 naming it; a workflow that is not runnable yet comes back as not_runnable with per-node issues."),
|
|
7085
|
+
params: z11.record(z11.string(), z11.unknown()).optional().describe("Values for the definition's params."),
|
|
7086
|
+
nodeIds: z11.array(z11.string()).optional().describe("Run only this subset of nodes (requires an inline `definition` or a `savedId`)."),
|
|
7087
|
+
upstreamGenerations: z11.record(z11.string(), z11.string()).optional().describe(
|
|
6313
7088
|
'Pin WHICH generation of an upstream node feeds this subset run: { "<upstream node id>": "<node-run id>" } (the per-node `id` that studio_get_run returns). A verified pin is reused even when the planner has no matching cache key for it (an inline first batch, or a node edited and reverted), so a follow-up node wired from an earlier generation runs against exactly that image. An unknown id is refused naming the node, never silently replaced by the latest.'
|
|
6314
7089
|
),
|
|
6315
|
-
runs:
|
|
6316
|
-
visibility:
|
|
6317
|
-
budgetUsd:
|
|
7090
|
+
runs: z11.number().int().min(1).max(8).optional().describe("Repeat a node subset N times (1 to 8)."),
|
|
7091
|
+
visibility: z11.enum(["listed", "unlisted"]).optional().describe("Whether the run shows in the Studio workflow list."),
|
|
7092
|
+
budgetUsd: z11.number().nonnegative().optional().describe(
|
|
6318
7093
|
'S6b: hard cap on the estimated cost, verified server-side before anything is created. An unverifiable estimate (a credits-only or unpriced executing node) refuses too, never proceeds silently. Refusal: { code: "budget_exceeded", estimate }. For `runs`>1 this is the AGGREGATE cap across every iteration.'
|
|
6319
7094
|
),
|
|
6320
|
-
confirm:
|
|
7095
|
+
confirm: z11.boolean().optional().describe(
|
|
6321
7096
|
'S6b: bypasses the confirmation threshold for this one request (a flat $10 today) when the estimate meets or exceeds it. Without this, such a run refuses with { code: "confirmation_required", estimate }.'
|
|
6322
7097
|
),
|
|
6323
|
-
|
|
7098
|
+
acknowledgeContinuity: z11.boolean().optional().describe(
|
|
7099
|
+
'Run despite the continuity check. Before a run executes an image-to-video node with BOTH a start frame (inputImageUrl) and an end frame (endImageUrl), the Studio compares the two frames with a vision model (one small paid check per new pair of frames, remembered for your company, so an unchanged pair is never charged twice): a person or a held object in one frame and not the other makes the video model invent or erase it mid-clip. Frames that disagree refuse with { code: "continuity_mismatch", nodes: [{ nodeId, differences }] }; a check that could not run refuses with { code: "continuity_unchecked", nodes: [{ nodeId, reason }] }. Nothing is spent on either. Show the differences to the person you act for and fix the frames; pass true only when they decide to run anyway.'
|
|
7100
|
+
),
|
|
7101
|
+
wait: z11.boolean().default(true),
|
|
6324
7102
|
waitSeconds
|
|
6325
7103
|
},
|
|
6326
7104
|
handler: async (args, ctx) => {
|
|
@@ -6340,7 +7118,8 @@ var studioRunWorkflow = defineTool({
|
|
|
6340
7118
|
...args.savedId ? { savedId: args.savedId } : {},
|
|
6341
7119
|
...args.visibility ? { visibility: args.visibility } : {},
|
|
6342
7120
|
...args.budgetUsd !== void 0 ? { budgetUsd: args.budgetUsd } : {},
|
|
6343
|
-
...args.confirm !== void 0 ? { confirm: args.confirm } : {}
|
|
7121
|
+
...args.confirm !== void 0 ? { confirm: args.confirm } : {},
|
|
7122
|
+
...args.acknowledgeContinuity !== void 0 ? { acknowledgeContinuity: args.acknowledgeContinuity } : {}
|
|
6344
7123
|
});
|
|
6345
7124
|
if (!args.wait) return { runId: started.runId, runIds: started.runIds, status: started.status };
|
|
6346
7125
|
const run = await waitForRun(ctx.client, started.runId, pollOpts(ctx, args.waitSeconds));
|
|
@@ -6351,8 +7130,8 @@ var studioGetRun = defineTool({
|
|
|
6351
7130
|
name: "studio_get_run",
|
|
6352
7131
|
description: "Fetch a workflow run by runId: overall status (pending, running, succeeded, failed, partial, awaiting_decision, cancelled; cancelled means somebody stopped it), total cost, and per-node status, result URL, cost and error message. Set wait=true to block until the run settles. A run at awaiting_decision is parked on a person at a judge node: waiting returns immediately with a `waiting` block naming the node and its candidates, because polling can never clear it; ask the user to choose and submit their answer with studio_decide_judge.",
|
|
6353
7132
|
inputSchema: {
|
|
6354
|
-
runId:
|
|
6355
|
-
wait:
|
|
7133
|
+
runId: z11.string().min(1),
|
|
7134
|
+
wait: z11.boolean().default(false),
|
|
6356
7135
|
waitSeconds
|
|
6357
7136
|
},
|
|
6358
7137
|
annotations: { readOnlyHint: true },
|
|
@@ -6365,11 +7144,11 @@ var studioDecideJudge = defineTool({
|
|
|
6365
7144
|
name: "studio_decide_judge",
|
|
6366
7145
|
description: "Submit a PERSON'S decision on a parked judge node (a run whose status is awaiting_decision). Approving that candidate resumes the run from that node; rejecting fails the node and stops the branch. Never call this on your own judgement: a judge node exists precisely because a human is meant to look, so show them the candidates from studio_get_run's `waiting` block and pass on the answer they give. `candidate.generationId` comes from that same block, and may be omitted only when the node has exactly one candidate.",
|
|
6367
7146
|
inputSchema: {
|
|
6368
|
-
runId:
|
|
6369
|
-
nodeId:
|
|
6370
|
-
verdict:
|
|
6371
|
-
candidate:
|
|
6372
|
-
reason:
|
|
7147
|
+
runId: z11.string().min(1),
|
|
7148
|
+
nodeId: z11.string().min(1),
|
|
7149
|
+
verdict: z11.enum(["approved", "rejected"]),
|
|
7150
|
+
candidate: z11.object({ generationId: z11.string().min(1), index: z11.number().int().min(0).optional() }).optional(),
|
|
7151
|
+
reason: z11.string().max(500).optional()
|
|
6373
7152
|
},
|
|
6374
7153
|
annotations: { destructiveHint: false, idempotentHint: false },
|
|
6375
7154
|
handler: async (args, ctx) => {
|
|
@@ -6385,8 +7164,8 @@ var studioGetRunOutput = defineTool({
|
|
|
6385
7164
|
name: "studio_get_run_output",
|
|
6386
7165
|
description: "Get a FRESH signed URL for one node's output of a workflow run (signed URLs expire; call this when an earlier URL stopped working). Returns url, kind (image, video, model3d) and mime.",
|
|
6387
7166
|
inputSchema: {
|
|
6388
|
-
runId:
|
|
6389
|
-
nodeId:
|
|
7167
|
+
runId: z11.string().min(1),
|
|
7168
|
+
nodeId: z11.string().min(1)
|
|
6390
7169
|
},
|
|
6391
7170
|
annotations: { readOnlyHint: true },
|
|
6392
7171
|
handler: async (args, ctx) => {
|
|
@@ -6398,21 +7177,24 @@ var studioReplaceCharacterInVideo = defineTool({
|
|
|
6398
7177
|
name: "studio_replace_character_in_video",
|
|
6399
7178
|
description: 'Put a minted character into a video shot through the still-swap route: (1) an image-edit node (fal/nano-banana-2-edit) replaces the person in a scene FRAME with the character; (2) an image-to-video node animates that still (default fal/seedance-pro-image-to-video; with endFrameUrl it switches to fal/kling-v2-5-image-to-video and binds the end keyframe so the clip lands on it). Be honest with the user about what this route is: the video step REGENERATES the motion from the stills, so the original performance, timing and background are recreated rather than preserved; when the original motion must survive exactly, say so before spending. Declare scope: identity (default) takes face, head and hair and keeps the footage body; full_body also takes the character body proportions, which changes the silhouette. Pass preserve with the two or three shot-specific constraints most likely to fail, from looking at the frame (e.g. "keep the open door in front of his body", "match the face soft focus"), or a complete swapPrompt of your own. Never add a realism suffix like "photorealistic" or a promise that every pixel stays identical; the model cannot keep either and the suffix sharpens deliberately soft subjects. Give the character as characterSlug (its full-body reference is used, falling back to three-quarter then face) or as an explicit characterReferenceUrl. Requires a frame URL: extract a representative frame from the video yourself first (this tool does not decode video). Waits for both nodes and returns stillUrl, videoUrl, runId and costUsd (what the take cost your company; about $1.05 with the default models on prepaid credits without a subscription). Inspect the still before paying for more takes, keep generated cuts under 5 seconds, and budget one take plus two retries per shot. Do not use video-to-video swap models on dark or handheld footage.',
|
|
6400
7179
|
inputSchema: {
|
|
6401
|
-
projectId:
|
|
7180
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
6402
7181
|
sceneFrameUrl: httpUrl.describe("Public or signed URL of ONE frame of the target shot (png/jpg)."),
|
|
6403
7182
|
characterSlug: slug.optional().describe(
|
|
6404
7183
|
"Character to insert: one of your company's, or one another company shared. Its full-body reference (fallback three-quarter, face) is resolved automatically. A slug your company cannot use is a 404 before the run starts, so nothing is spent."
|
|
6405
7184
|
),
|
|
6406
7185
|
characterReferenceUrl: httpUrl.optional().describe("Explicit character reference image URL (use instead of characterSlug)."),
|
|
6407
7186
|
endFrameUrl: httpUrl.optional().describe("Optional second approved keyframe for the END of the clip. Switches the video model to Kling (start + end frame) unless videoModel is set explicitly."),
|
|
6408
|
-
scope:
|
|
6409
|
-
preserve:
|
|
6410
|
-
swapPrompt:
|
|
6411
|
-
motionPrompt:
|
|
6412
|
-
videoModel:
|
|
6413
|
-
editModel:
|
|
6414
|
-
aspectRatio:
|
|
6415
|
-
visibility:
|
|
7187
|
+
scope: z11.enum(SWAP_SCOPES).optional().describe("How much of the person to replace. identity (default): face, head and hair from the character, the footage keeps its body. full_body: also the character body proportions; the silhouette changes, so the background behind the old body and every contact point must be re-derived."),
|
|
7188
|
+
preserve: z11.array(z11.string().min(1).max(200)).max(6).optional().describe('Shot-specific constraints most likely to fail, as concrete relationships seen in the frame, one per entry (e.g. "keep the open door in front of his body"). Appended to the composed prompt.'),
|
|
7189
|
+
swapPrompt: z11.string().optional().describe("A complete still-swap edit prompt of your own; replaces the composed one, so scope and preserve are then ignored."),
|
|
7190
|
+
motionPrompt: z11.string().optional().describe("Override the motion description for the video node."),
|
|
7191
|
+
videoModel: z11.string().optional().describe(`Image-to-video model id. Default ${DEFAULT_SWAP_VIDEO_MODEL}, or ${KEYFRAME_SWAP_VIDEO_MODEL} when endFrameUrl is given.`),
|
|
7192
|
+
editModel: z11.string().default(DEFAULT_SWAP_EDIT_MODEL).describe("Image-edit model id for the still swap."),
|
|
7193
|
+
aspectRatio: z11.string().default("16:9"),
|
|
7194
|
+
visibility: z11.enum(["listed", "unlisted"]).optional(),
|
|
7195
|
+
acknowledgeContinuity: z11.boolean().optional().describe(
|
|
7196
|
+
"With endFrameUrl only. The swapped still (the clip's start frame) is compared with the end frame before the clip is paid for; when they do not show the same people and the same objects in their hands, the video node fails with continuity_mismatch and the differences, and nothing is spent on the clip (the still was already made). Fix the end frame, or call again with true when the person you act for decides to run anyway."
|
|
7197
|
+
),
|
|
6416
7198
|
waitSeconds
|
|
6417
7199
|
},
|
|
6418
7200
|
handler: async (args, ctx) => {
|
|
@@ -6448,7 +7230,8 @@ var studioReplaceCharacterInVideo = defineTool({
|
|
|
6448
7230
|
const started = await ctx.client.runWorkflow({
|
|
6449
7231
|
projectId: args.projectId,
|
|
6450
7232
|
definition,
|
|
6451
|
-
...args.visibility ? { visibility: args.visibility } : {}
|
|
7233
|
+
...args.visibility ? { visibility: args.visibility } : {},
|
|
7234
|
+
...args.acknowledgeContinuity !== void 0 ? { acknowledgeContinuity: args.acknowledgeContinuity } : {}
|
|
6452
7235
|
});
|
|
6453
7236
|
const run = await waitForRun(ctx.client, started.runId, pollOpts(ctx, args.waitSeconds));
|
|
6454
7237
|
const stillUrl = nodeUrl(run, SWAP_EDIT_NODE_ID);
|
|
@@ -6477,7 +7260,7 @@ var studioGetSpend = defineTool({
|
|
|
6477
7260
|
name: "studio_get_spend",
|
|
6478
7261
|
description: `Read the spend ledger: total USD and job counts for today, the last 7 days and the last 30 days, plus the most recent paid actions. The amounts are what the company paid (each job's costUsd): for a company on prepaid credits, what left its balance for those jobs. tzOffsetMinutes is the viewer's Date.getTimezoneOffset() so "today" rolls at local midnight (default UTC).`,
|
|
6479
7262
|
inputSchema: {
|
|
6480
|
-
tzOffsetMinutes:
|
|
7263
|
+
tzOffsetMinutes: z11.number().int().min(-840).max(840).optional()
|
|
6481
7264
|
},
|
|
6482
7265
|
annotations: { readOnlyHint: true },
|
|
6483
7266
|
handler: async (args, ctx) => {
|
|
@@ -6505,7 +7288,7 @@ var studioDescribePublished = defineTool({
|
|
|
6505
7288
|
name: "studio_describe_published",
|
|
6506
7289
|
description: "Describe one published recipe by slug: { slug, definition, hasEffects }. definition is the FROZEN workflow (params, node shapes) exactly as it was at publish time, never the live authoring document, which may have moved on since. Read this before studio_run_published to know what params it needs. Free, read-only.",
|
|
6507
7290
|
inputSchema: {
|
|
6508
|
-
slug:
|
|
7291
|
+
slug: z11.string().min(1).describe("The recipe slug, from studio_list_published.")
|
|
6509
7292
|
},
|
|
6510
7293
|
annotations: { readOnlyHint: true },
|
|
6511
7294
|
handler: async (args, ctx) => {
|
|
@@ -6515,19 +7298,22 @@ var studioDescribePublished = defineTool({
|
|
|
6515
7298
|
});
|
|
6516
7299
|
var studioRunPublished = defineTool({
|
|
6517
7300
|
name: "studio_run_published",
|
|
6518
|
-
description: `Run a published recipe by slug. Runs its FROZEN definition (studio_describe_published shows exactly what it needs); params fill the definition's own {kind:"param"} bindings. On success, the recipe's declared post-run effects fire automatically (e.g. character minting creates the character and attaches its reference views); effects never fire on a failed or partial run, by design. A recipe that creates a character (hasEffects, see studio_describe_published) requires likenessRightsConfirmed: true and refuses with { code: "likeness_rights_confirmation_required" } before anything is spent when it is missing. Returns the runId plus per-node status, URLs and cost; with wait=true (default) it blocks until the run is terminal. Each node becomes a paid job. The same $10 confirm-gate as studio_run_workflow applies: an estimate at or over the threshold refuses with { code: "confirmation_required", estimate } unless confirm: true is set.`,
|
|
7301
|
+
description: `Run a published recipe by slug. Runs its FROZEN definition (studio_describe_published shows exactly what it needs); params fill the definition's own {kind:"param"} bindings. On success, the recipe's declared post-run effects fire automatically (e.g. character minting creates the character and attaches its reference views); effects never fire on a failed or partial run, by design. A recipe that creates a character (hasEffects, see studio_describe_published) requires likenessRightsConfirmed: true and refuses with { code: "likeness_rights_confirmation_required" } before anything is spent when it is missing. Returns the runId plus per-node status, URLs and cost; with wait=true (default) it blocks until the run is terminal. Each node becomes a paid job. The same $10 confirm-gate as studio_run_workflow applies: an estimate at or over the threshold refuses with { code: "confirmation_required", estimate } unless confirm: true is set. So does its continuity check before a clip with a start and an end frame (see acknowledgeContinuity).`,
|
|
6519
7302
|
inputSchema: {
|
|
6520
|
-
slug:
|
|
6521
|
-
projectId:
|
|
6522
|
-
params:
|
|
6523
|
-
budgetUsd:
|
|
7303
|
+
slug: z11.string().min(1).describe("The recipe slug, from studio_list_published."),
|
|
7304
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
7305
|
+
params: z11.record(z11.string(), z11.unknown()).optional().describe("Values for the recipe's params (see studio_describe_published)."),
|
|
7306
|
+
budgetUsd: z11.number().nonnegative().optional().describe(
|
|
6524
7307
|
'Hard cap on the estimated cost, verified server-side before anything is created. An unverifiable estimate (a credits-only or unpriced executing node) refuses too. Refusal: { code: "budget_exceeded", estimate }.'
|
|
6525
7308
|
),
|
|
6526
|
-
confirm:
|
|
7309
|
+
confirm: z11.boolean().optional().describe(
|
|
6527
7310
|
'Bypasses the confirmation threshold for this one request (a flat $10 today) when the estimate meets or exceeds it. Without this, such a run refuses with { code: "confirmation_required", estimate }.'
|
|
6528
7311
|
),
|
|
6529
|
-
likenessRightsConfirmed:
|
|
6530
|
-
|
|
7312
|
+
likenessRightsConfirmed: z11.literal(true).optional().describe(`Required when the recipe creates a character; ignored otherwise. ${likenessConfirmationToolDescription()}`),
|
|
7313
|
+
acknowledgeContinuity: z11.boolean().optional().describe(
|
|
7314
|
+
'Run despite the continuity check, exactly as on studio_run_workflow: a recipe with an image-to-video node that has both a start and an end frame refuses with { code: "continuity_mismatch", nodes: [{ nodeId, differences }] } or { code: "continuity_unchecked", nodes: [{ nodeId, reason }] } before anything is spent. Pass true only when the person you act for decides to run anyway.'
|
|
7315
|
+
),
|
|
7316
|
+
wait: z11.boolean().default(true),
|
|
6531
7317
|
waitSeconds
|
|
6532
7318
|
},
|
|
6533
7319
|
handler: async (args, ctx) => {
|
|
@@ -6536,7 +7322,8 @@ var studioRunPublished = defineTool({
|
|
|
6536
7322
|
...args.params ? { params: args.params } : {},
|
|
6537
7323
|
...args.budgetUsd !== void 0 ? { budgetUsd: args.budgetUsd } : {},
|
|
6538
7324
|
...args.confirm !== void 0 ? { confirm: args.confirm } : {},
|
|
6539
|
-
...args.likenessRightsConfirmed === true ? { likenessRightsConfirmed: true } : {}
|
|
7325
|
+
...args.likenessRightsConfirmed === true ? { likenessRightsConfirmed: true } : {},
|
|
7326
|
+
...args.acknowledgeContinuity !== void 0 ? { acknowledgeContinuity: args.acknowledgeContinuity } : {}
|
|
6540
7327
|
});
|
|
6541
7328
|
if (!args.wait) return { runId: started.runId, status: started.status };
|
|
6542
7329
|
const run = await waitForRun(ctx.client, started.runId, pollOpts(ctx, args.waitSeconds));
|
|
@@ -6567,7 +7354,8 @@ var TOOLS = [
|
|
|
6567
7354
|
studioRunPublished,
|
|
6568
7355
|
studioGetUsage,
|
|
6569
7356
|
...WORKFLOW_TOOLS,
|
|
6570
|
-
...MANAGE_TOOLS
|
|
7357
|
+
...MANAGE_TOOLS,
|
|
7358
|
+
...COMPOSITION_TOOLS
|
|
6571
7359
|
];
|
|
6572
7360
|
var TOOL_NAMES = TOOLS.map((t) => t.name);
|
|
6573
7361
|
function toolResult(value) {
|
|
@@ -6585,7 +7373,7 @@ function toolError(message) {
|
|
|
6585
7373
|
}
|
|
6586
7374
|
async function invokeTool(def, args, ctx) {
|
|
6587
7375
|
try {
|
|
6588
|
-
const parsed =
|
|
7376
|
+
const parsed = z11.object(def.inputSchema).parse(args ?? {});
|
|
6589
7377
|
const value = await def.handler(parsed, ctx);
|
|
6590
7378
|
return toolResult(value);
|
|
6591
7379
|
} catch (err) {
|
|
@@ -6636,7 +7424,7 @@ function registerTools(server, base) {
|
|
|
6636
7424
|
|
|
6637
7425
|
// src/server.ts
|
|
6638
7426
|
var SERVER_NAME = "lumitra-studio";
|
|
6639
|
-
var SERVER_VERSION = "0.
|
|
7427
|
+
var SERVER_VERSION = "0.9.0";
|
|
6640
7428
|
function createStudioMcpServer(opts = {}) {
|
|
6641
7429
|
const config = opts.config ?? resolveConfig(opts.env ?? process.env);
|
|
6642
7430
|
const client = new StudioClient(config, {
|
|
@@ -6661,7 +7449,7 @@ function createStudioMcpServer(opts = {}) {
|
|
|
6661
7449
|
|
|
6662
7450
|
// src/cli.ts
|
|
6663
7451
|
import { createServer as createHttpServer } from "http";
|
|
6664
|
-
import { randomUUID as
|
|
7452
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
6665
7453
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6666
7454
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
6667
7455
|
function parseArgs(argv) {
|
|
@@ -6746,7 +7534,7 @@ async function runHttp(args) {
|
|
|
6746
7534
|
});
|
|
6747
7535
|
const addr = httpServer.address();
|
|
6748
7536
|
const port = typeof addr === "object" && addr ? addr.port : args.port;
|
|
6749
|
-
process.stderr.write(`[${SERVER_NAME}] Streamable HTTP on http://${args.host}:${port}/mcp (${TOOL_NAMES.length} tools, instance ${
|
|
7537
|
+
process.stderr.write(`[${SERVER_NAME}] Streamable HTTP on http://${args.host}:${port}/mcp (${TOOL_NAMES.length} tools, instance ${randomUUID4().slice(0, 8)})
|
|
6750
7538
|
`);
|
|
6751
7539
|
const shutdown = () => {
|
|
6752
7540
|
httpServer.close(() => process.exit(0));
|