@marlinjai/studio-mcp 0.6.0 → 0.8.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 +17 -5
- package/dist/cli.js +952 -112
- package/dist/index.d.ts +490 -3
- package/dist/index.js +952 -112
- package/examples/cursor-mcp.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105,6 +105,37 @@ var StudioClient = class {
|
|
|
105
105
|
listProjects() {
|
|
106
106
|
return this.json("GET", "/api/v1/projects");
|
|
107
107
|
}
|
|
108
|
+
createProject(name) {
|
|
109
|
+
return this.json("POST", "/api/v1/projects", { json: { name } });
|
|
110
|
+
}
|
|
111
|
+
renameProject(projectId, name) {
|
|
112
|
+
return this.json("PATCH", `/api/v1/projects/${encodeURIComponent(projectId)}`, { json: { name } });
|
|
113
|
+
}
|
|
114
|
+
/** What a project holds, which is what deleting it would remove. */
|
|
115
|
+
describeProject(projectId) {
|
|
116
|
+
return this.json("GET", `/api/v1/projects/${encodeURIComponent(projectId)}`);
|
|
117
|
+
}
|
|
118
|
+
deleteProject(projectId) {
|
|
119
|
+
return this.json("DELETE", `/api/v1/projects/${encodeURIComponent(projectId)}`);
|
|
120
|
+
}
|
|
121
|
+
// ── Saved workflows (listing and moving; authoring lives with the workflow tools) ──
|
|
122
|
+
listWorkflows(opts = {}) {
|
|
123
|
+
return this.json("GET", `/api/v1/workflows${projectQuery(opts.projectId)}`);
|
|
124
|
+
}
|
|
125
|
+
moveWorkflow(savedId2, body) {
|
|
126
|
+
return this.json("POST", `/api/v1/workflows/${encodeURIComponent(savedId2)}/move`, { json: body });
|
|
127
|
+
}
|
|
128
|
+
// ── Campaigns ──
|
|
129
|
+
listCampaigns() {
|
|
130
|
+
return this.json("GET", "/api/campaigns");
|
|
131
|
+
}
|
|
132
|
+
/** The campaign and what deleting it would remove or keep. */
|
|
133
|
+
describeCampaign(campaignId) {
|
|
134
|
+
return this.json("GET", `/api/campaigns/${encodeURIComponent(campaignId)}`);
|
|
135
|
+
}
|
|
136
|
+
deleteCampaign(campaignId) {
|
|
137
|
+
return this.json("DELETE", `/api/campaigns/${encodeURIComponent(campaignId)}`);
|
|
138
|
+
}
|
|
108
139
|
// ── Generation jobs ──
|
|
109
140
|
/**
|
|
110
141
|
* One image job. `brandSlug` is optional: without it the image is generated
|
|
@@ -226,6 +257,45 @@ var StudioClient = class {
|
|
|
226
257
|
applyWorkflowPatch(savedId2, patch) {
|
|
227
258
|
return this.json("PATCH", `/api/v1/workflows/${encodeURIComponent(savedId2)}`, { json: patch });
|
|
228
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
|
+
}
|
|
229
299
|
/** Stateless dry-run of ops and run params against a document. No side effects. */
|
|
230
300
|
validateWorkflow(body) {
|
|
231
301
|
return this.json("POST", "/api/v1/workflows/validate", { json: body });
|
|
@@ -433,7 +503,7 @@ function resolveConfig(env = process.env) {
|
|
|
433
503
|
}
|
|
434
504
|
|
|
435
505
|
// src/tools.ts
|
|
436
|
-
import { z as
|
|
506
|
+
import { z as z11 } from "zod";
|
|
437
507
|
|
|
438
508
|
// ../lumitra-core/dist/models/index.js
|
|
439
509
|
var veo = (tier, label) => {
|
|
@@ -4064,7 +4134,7 @@ function portBinding(task, port) {
|
|
|
4064
4134
|
if (port === "video" && task === "video-enhance") {
|
|
4065
4135
|
return { key: "draftCacheUrl", path: "draftCacheUrl" };
|
|
4066
4136
|
}
|
|
4067
|
-
if (port === "image" && task === "image-edit") {
|
|
4137
|
+
if (port === "image" && (task === "image-edit" || task === "image-to-image")) {
|
|
4068
4138
|
return { key: "inputImages", path: "url", wrap: "array" };
|
|
4069
4139
|
}
|
|
4070
4140
|
if (port === "text" && taskNeedsPrompt(task)) {
|
|
@@ -4087,7 +4157,7 @@ function canConnect(sourceOut, targetTask, targetPort) {
|
|
|
4087
4157
|
}
|
|
4088
4158
|
function portCardinality(task, port, model) {
|
|
4089
4159
|
if (portBinding(task, port) === null) return "none";
|
|
4090
|
-
if (port === "image" && task === "image-edit") return "many";
|
|
4160
|
+
if (port === "image" && (task === "image-edit" || task === "image-to-image")) return "many";
|
|
4091
4161
|
if (port === "image" && task === "image-to-video") {
|
|
4092
4162
|
return modelAcceptsKeyframes(model) ? "many" : "two";
|
|
4093
4163
|
}
|
|
@@ -5635,10 +5705,738 @@ var WORKFLOW_TOOLS = [
|
|
|
5635
5705
|
studioWorkflowScreenshot
|
|
5636
5706
|
];
|
|
5637
5707
|
|
|
5708
|
+
// src/compositionTools.ts
|
|
5709
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
5710
|
+
import { z as z9 } from "zod";
|
|
5711
|
+
|
|
5712
|
+
// ../lumitra-core/dist/composition/index.js
|
|
5713
|
+
import { z as z22 } from "zod";
|
|
5714
|
+
import { z as z8 } from "zod";
|
|
5715
|
+
import { z as z32 } from "zod";
|
|
5716
|
+
var BRAND_KIT_MAX_COLORS = 6;
|
|
5717
|
+
var BRAND_KIT_FONT_ROLES = ["primary", "secondary"];
|
|
5718
|
+
var BRAND_KIT_TYPE_ROLES = ["headline", "body"];
|
|
5719
|
+
var BRAND_KIT_LOGO_VARIANTS = ["light", "dark"];
|
|
5720
|
+
var BRAND_KIT_TYPE_PX_MIN = 12;
|
|
5721
|
+
var BRAND_KIT_TYPE_PX_MAX = 200;
|
|
5722
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
5723
|
+
var COLOR_ID = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
5724
|
+
var BrandKitColorSchema = z8.object({
|
|
5725
|
+
/** Stable id an overlay refers to; survives a rename of the colour. */
|
|
5726
|
+
id: z8.string().regex(COLOR_ID, "a colour id is lowercase letters, digits and hyphens"),
|
|
5727
|
+
name: z8.string().trim().min(1, "a colour needs a name").max(40),
|
|
5728
|
+
hex: z8.string().regex(HEX, "a colour is a hex value like #1a2b3c")
|
|
5729
|
+
}).strict();
|
|
5730
|
+
var TypeSizeSchema = z8.object({
|
|
5731
|
+
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`)
|
|
5732
|
+
}).strict();
|
|
5733
|
+
var BrandKitTypeRolesSchema = z8.object({ headline: TypeSizeSchema, body: TypeSizeSchema }).strict().refine((t) => t.headline.px > t.body.px, {
|
|
5734
|
+
message: "the headline size must be larger than the body size",
|
|
5735
|
+
path: ["headline", "px"]
|
|
5736
|
+
});
|
|
5737
|
+
var BrandKitTokensSchema = z8.object({
|
|
5738
|
+
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) => {
|
|
5739
|
+
const ids = /* @__PURE__ */ new Set();
|
|
5740
|
+
const names = /* @__PURE__ */ new Set();
|
|
5741
|
+
colors.forEach((c, i) => {
|
|
5742
|
+
if (ids.has(c.id)) ctx.addIssue({ code: "custom", message: `colour id "${c.id}" is used twice`, path: [i, "id"] });
|
|
5743
|
+
const name = c.name.trim().toLowerCase();
|
|
5744
|
+
if (names.has(name)) ctx.addIssue({ code: "custom", message: `colour name "${c.name}" is used twice`, path: [i, "name"] });
|
|
5745
|
+
ids.add(c.id);
|
|
5746
|
+
names.add(name);
|
|
5747
|
+
});
|
|
5748
|
+
}),
|
|
5749
|
+
typeRoles: BrandKitTypeRolesSchema
|
|
5750
|
+
}).strict();
|
|
5751
|
+
var BrandKitFontFileMetaSchema = z8.object({
|
|
5752
|
+
weight: z8.number().int().min(100).max(900).refine((w) => w % 100 === 0, "a font weight is a multiple of 100"),
|
|
5753
|
+
style: z8.enum(["normal", "italic"])
|
|
5754
|
+
}).strict();
|
|
5755
|
+
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");
|
|
5756
|
+
var COMPOSITION_SCHEMA_VERSION = 1;
|
|
5757
|
+
var COMPOSITION_KINDS = ["carousel", "reel"];
|
|
5758
|
+
var COMPOSITION_ASPECTS = ["4:5", "1:1", "9:16"];
|
|
5759
|
+
var MAX_CAROUSEL_SLIDES = 10;
|
|
5760
|
+
var REEL_MIN_SECONDS = 3;
|
|
5761
|
+
var REEL_MAX_SECONDS = 90;
|
|
5762
|
+
var MIN_CLIP_SECONDS = 0.5;
|
|
5763
|
+
var MAX_REEL_CLIPS = 30;
|
|
5764
|
+
var MAX_OVERLAYS_PER_ITEM = 20;
|
|
5765
|
+
var MAX_REEL_OVERLAYS = 40;
|
|
5766
|
+
var MAX_OVERLAY_TEXT = 500;
|
|
5767
|
+
var MIN_BOX_SIDE = 0.02;
|
|
5768
|
+
var ID = /^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}$/;
|
|
5769
|
+
var CompositionIdSchema = z22.string().regex(ID, "an id is letters, digits and _ . : -");
|
|
5770
|
+
var COLOR_ROLE = z22.string().regex(/^[a-z0-9][a-z0-9-]{0,31}$/, "a colour is named by its kit id");
|
|
5771
|
+
var unit = z22.number().min(0).max(1);
|
|
5772
|
+
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");
|
|
5773
|
+
var TimingShape = {
|
|
5774
|
+
start: z22.number().min(0).optional(),
|
|
5775
|
+
end: z22.number().positive().optional()
|
|
5776
|
+
};
|
|
5777
|
+
var TextOverlaySchema = z22.object({
|
|
5778
|
+
id: CompositionIdSchema,
|
|
5779
|
+
type: z22.literal("text"),
|
|
5780
|
+
box: BoxSchema,
|
|
5781
|
+
text: z22.string().min(1, "a text overlay needs text").max(MAX_OVERLAY_TEXT),
|
|
5782
|
+
styleRole: z22.enum(BRAND_KIT_TYPE_ROLES),
|
|
5783
|
+
fontRole: z22.enum(BRAND_KIT_FONT_ROLES),
|
|
5784
|
+
weight: z22.number().int().min(100).max(900),
|
|
5785
|
+
italic: z22.boolean(),
|
|
5786
|
+
colorRole: COLOR_ROLE,
|
|
5787
|
+
align: z22.enum(["left", "center", "right"]),
|
|
5788
|
+
/** A colour chip behind the text, for legibility on busy images. */
|
|
5789
|
+
background: z22.object({ colorRole: COLOR_ROLE, opacity: unit, padding: z22.number().min(0).max(0.1) }).strict().optional(),
|
|
5790
|
+
...TimingShape
|
|
5791
|
+
}).strict();
|
|
5792
|
+
var LogoOverlaySchema = z22.object({
|
|
5793
|
+
id: CompositionIdSchema,
|
|
5794
|
+
type: z22.literal("logo"),
|
|
5795
|
+
box: BoxSchema,
|
|
5796
|
+
variant: z22.enum(BRAND_KIT_LOGO_VARIANTS),
|
|
5797
|
+
...TimingShape
|
|
5798
|
+
}).strict();
|
|
5799
|
+
var ShapeOverlaySchema = z22.object({
|
|
5800
|
+
id: CompositionIdSchema,
|
|
5801
|
+
type: z22.literal("shape"),
|
|
5802
|
+
box: BoxSchema,
|
|
5803
|
+
shape: z22.enum(["rect", "pill"]),
|
|
5804
|
+
colorRole: COLOR_ROLE,
|
|
5805
|
+
opacity: unit,
|
|
5806
|
+
...TimingShape
|
|
5807
|
+
}).strict();
|
|
5808
|
+
var OverlaySchema = z22.discriminatedUnion("type", [TextOverlaySchema, LogoOverlaySchema, ShapeOverlaySchema]);
|
|
5809
|
+
var SlideSchema = z22.object({
|
|
5810
|
+
id: CompositionIdSchema,
|
|
5811
|
+
type: z22.literal("slide"),
|
|
5812
|
+
background: z22.object({
|
|
5813
|
+
/** A Studio image asset of the composition's project. */
|
|
5814
|
+
assetId: CompositionIdSchema.optional(),
|
|
5815
|
+
fit: z22.enum(["cover", "contain"]),
|
|
5816
|
+
/** The point of the image kept in view when `cover` crops it. */
|
|
5817
|
+
focal: z22.object({ x: unit, y: unit }).strict(),
|
|
5818
|
+
/** A kit colour behind the image (or instead of one). */
|
|
5819
|
+
fill: COLOR_ROLE.optional()
|
|
5820
|
+
}).strict().refine((b) => b.assetId !== void 0 || b.fill !== void 0, "a slide needs an image or a fill colour"),
|
|
5821
|
+
overlays: z22.array(OverlaySchema).max(MAX_OVERLAYS_PER_ITEM)
|
|
5822
|
+
}).strict();
|
|
5823
|
+
var ClipSchema = z22.object({
|
|
5824
|
+
id: CompositionIdSchema,
|
|
5825
|
+
type: z22.literal("clip"),
|
|
5826
|
+
/** A Studio video asset of the composition's project. */
|
|
5827
|
+
assetId: CompositionIdSchema,
|
|
5828
|
+
/** Seconds into the source clip. */
|
|
5829
|
+
trimIn: z22.number().min(0),
|
|
5830
|
+
trimOut: z22.number().positive(),
|
|
5831
|
+
overlays: z22.array(OverlaySchema).max(MAX_OVERLAYS_PER_ITEM)
|
|
5832
|
+
}).strict().refine((c) => c.trimOut - c.trimIn >= MIN_CLIP_SECONDS - 1e-9, `a clip is at least ${MIN_CLIP_SECONDS} s after trimming`);
|
|
5833
|
+
var ItemSchema = z22.union([SlideSchema, ClipSchema]);
|
|
5834
|
+
var CompositionDocumentSchema = z22.object({
|
|
5835
|
+
schema: z22.literal(COMPOSITION_SCHEMA_VERSION),
|
|
5836
|
+
kind: z22.enum(COMPOSITION_KINDS),
|
|
5837
|
+
aspect: z22.enum(COMPOSITION_ASPECTS),
|
|
5838
|
+
label: z22.string().max(200),
|
|
5839
|
+
/** The brand whose kit the overlays use. */
|
|
5840
|
+
brandSlug: z22.string().min(1).max(64),
|
|
5841
|
+
/** The kit version the document was last edited against; a newer kit is worth a look before rendering. */
|
|
5842
|
+
kitVersionAtEdit: z22.number().int().nonnegative(),
|
|
5843
|
+
items: z22.array(ItemSchema),
|
|
5844
|
+
/** Overlays across the whole reel (a logo bug, an end card line). Always empty on a carousel. */
|
|
5845
|
+
reelOverlays: z22.array(OverlaySchema).max(MAX_OVERLAYS_PER_ITEM)
|
|
5846
|
+
}).strict();
|
|
5847
|
+
var REEL_TARGET = "reel";
|
|
5848
|
+
var TargetSchema = z32.string().min(1).max(128);
|
|
5849
|
+
var index = z32.number().int().nonnegative();
|
|
5850
|
+
var PropsSchema = z32.record(z32.string(), z32.unknown());
|
|
5851
|
+
var SetMetaOpSchema = z32.object({
|
|
5852
|
+
type: z32.literal("setMeta"),
|
|
5853
|
+
props: z32.object({
|
|
5854
|
+
label: z32.string().max(200).optional(),
|
|
5855
|
+
aspect: z32.enum(COMPOSITION_ASPECTS).optional(),
|
|
5856
|
+
kitVersionAtEdit: z32.number().int().nonnegative().optional()
|
|
5857
|
+
}).strict()
|
|
5858
|
+
}).strict();
|
|
5859
|
+
var AddItemOpSchema = z32.object({ type: z32.literal("addItem"), item: ItemSchema, index: index.optional() }).strict();
|
|
5860
|
+
var RemoveItemOpSchema = z32.object({ type: z32.literal("removeItem"), itemId: CompositionIdSchema }).strict();
|
|
5861
|
+
var MoveItemOpSchema = z32.object({ type: z32.literal("moveItem"), itemId: CompositionIdSchema, index }).strict();
|
|
5862
|
+
var SetItemPropsOpSchema = z32.object({ type: z32.literal("setItemProps"), itemId: CompositionIdSchema, props: PropsSchema }).strict();
|
|
5863
|
+
var AddOverlayOpSchema = z32.object({ type: z32.literal("addOverlay"), target: TargetSchema, overlay: OverlaySchema, index: index.optional() }).strict();
|
|
5864
|
+
var RemoveOverlayOpSchema = z32.object({ type: z32.literal("removeOverlay"), target: TargetSchema, overlayId: CompositionIdSchema }).strict();
|
|
5865
|
+
var MoveOverlayOpSchema = z32.object({
|
|
5866
|
+
type: z32.literal("moveOverlay"),
|
|
5867
|
+
target: TargetSchema,
|
|
5868
|
+
overlayId: CompositionIdSchema,
|
|
5869
|
+
/** Another item (or the reel) to move it to; omitted keeps it where it is. */
|
|
5870
|
+
toTarget: TargetSchema.optional(),
|
|
5871
|
+
/** Stacking position in the destination: 0 is at the back. */
|
|
5872
|
+
index
|
|
5873
|
+
}).strict();
|
|
5874
|
+
var SetOverlayPropsOpSchema = z32.object({ type: z32.literal("setOverlayProps"), target: TargetSchema, overlayId: CompositionIdSchema, props: PropsSchema }).strict();
|
|
5875
|
+
var CompositionOpSchema = z32.discriminatedUnion("type", [
|
|
5876
|
+
SetMetaOpSchema,
|
|
5877
|
+
AddItemOpSchema,
|
|
5878
|
+
RemoveItemOpSchema,
|
|
5879
|
+
MoveItemOpSchema,
|
|
5880
|
+
SetItemPropsOpSchema,
|
|
5881
|
+
AddOverlayOpSchema,
|
|
5882
|
+
RemoveOverlayOpSchema,
|
|
5883
|
+
MoveOverlayOpSchema,
|
|
5884
|
+
SetOverlayPropsOpSchema
|
|
5885
|
+
]);
|
|
5886
|
+
var COMPOSITION_OP_TYPES = CompositionOpSchema.options.map((o) => o.shape.type.value);
|
|
5887
|
+
var MAX_COMPOSITION_PATCH_OPS = 200;
|
|
5888
|
+
var CompositionPatchSchema = z32.object({
|
|
5889
|
+
baseRevision: z32.number().int().nonnegative(),
|
|
5890
|
+
ops: z32.array(CompositionOpSchema).min(1).max(MAX_COMPOSITION_PATCH_OPS),
|
|
5891
|
+
idempotencyKey: z32.string().min(1).max(128).optional()
|
|
5892
|
+
}).strict();
|
|
5893
|
+
|
|
5894
|
+
// src/compositionTools.ts
|
|
5895
|
+
var compositionId = z9.string().min(1).describe("The composition id, from studio_composition_create or studio_composition_list.");
|
|
5896
|
+
var opsSchema2 = z9.array(CompositionOpSchema).min(1).max(MAX_COMPOSITION_PATCH_OPS).describe(
|
|
5897
|
+
`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.`
|
|
5898
|
+
);
|
|
5899
|
+
function isRecord2(v) {
|
|
5900
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
5901
|
+
}
|
|
5902
|
+
function summarize(c) {
|
|
5903
|
+
const doc = c.document;
|
|
5904
|
+
return {
|
|
5905
|
+
id: c.id,
|
|
5906
|
+
projectId: c.projectId,
|
|
5907
|
+
kind: c.kind,
|
|
5908
|
+
label: c.label,
|
|
5909
|
+
brandSlug: c.brandSlug,
|
|
5910
|
+
revision: c.revision,
|
|
5911
|
+
aspect: doc.aspect,
|
|
5912
|
+
kitVersionAtEdit: doc.kitVersionAtEdit,
|
|
5913
|
+
items: doc.items,
|
|
5914
|
+
...doc.kind === "reel" ? { reelOverlays: doc.reelOverlays } : {}
|
|
5915
|
+
};
|
|
5916
|
+
}
|
|
5917
|
+
function mapCompositionFailure(err, ctx, idempotencyKey) {
|
|
5918
|
+
if (!(err instanceof StudioApiError)) return null;
|
|
5919
|
+
const body = isRecord2(err.body) ? err.body : {};
|
|
5920
|
+
const code = typeof body.code === "string" ? body.code : null;
|
|
5921
|
+
const message = typeof body.message === "string" ? ctx.client.redact(body.message) : null;
|
|
5922
|
+
if (err.status === 409 && code === "stale_revision" && isRecord2(body.composition)) {
|
|
5923
|
+
return {
|
|
5924
|
+
ok: false,
|
|
5925
|
+
code,
|
|
5926
|
+
revision: body.revision,
|
|
5927
|
+
composition: summarize(body.composition),
|
|
5928
|
+
hint: "Someone else changed it. Rebase your ops on the composition returned here and apply again with its revision and a NEW idempotencyKey."
|
|
5929
|
+
};
|
|
5930
|
+
}
|
|
5931
|
+
if (err.status === 409 && code === "idempotency_mismatch") {
|
|
5932
|
+
return { ok: false, code, message, hint: "That idempotencyKey belongs to a different patch: send this one with a new key." };
|
|
5933
|
+
}
|
|
5934
|
+
if (err.status === 422 && (code === "invalid_patch" || code === "not_ready")) {
|
|
5935
|
+
return {
|
|
5936
|
+
ok: false,
|
|
5937
|
+
code,
|
|
5938
|
+
...isRecord2(body.error) ? { error: body.error } : {},
|
|
5939
|
+
...Array.isArray(body.reasons) ? { reasons: body.reasons } : {},
|
|
5940
|
+
message,
|
|
5941
|
+
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)."
|
|
5942
|
+
};
|
|
5943
|
+
}
|
|
5944
|
+
if (err.status === 429 && code === "render_limit") return { ok: false, code, message };
|
|
5945
|
+
if (err.status === 429 && code === "render_busy") {
|
|
5946
|
+
return {
|
|
5947
|
+
ok: false,
|
|
5948
|
+
code,
|
|
5949
|
+
message,
|
|
5950
|
+
...typeof body.jobId === "string" ? { jobId: body.jobId } : {},
|
|
5951
|
+
hint: "One reel renders at a time per company. Wait for that render (studio_get_job with the jobId), then render this one."
|
|
5952
|
+
};
|
|
5953
|
+
}
|
|
5954
|
+
if (err.status === 404) return { ok: false, code: code ?? "not_found", message: message ?? "Not found in this company." };
|
|
5955
|
+
if (idempotencyKey && (err.status === 0 || err.status >= 500)) {
|
|
5956
|
+
return {
|
|
5957
|
+
ok: false,
|
|
5958
|
+
code: err.status === 0 ? "network_error" : "server_error",
|
|
5959
|
+
message: ctx.client.redact(err.message),
|
|
5960
|
+
idempotencyKey,
|
|
5961
|
+
hint: "The outcome is unknown. Retry with the SAME idempotencyKey: if the patch was applied, the retry replays it instead of applying twice."
|
|
5962
|
+
};
|
|
5963
|
+
}
|
|
5964
|
+
return null;
|
|
5965
|
+
}
|
|
5966
|
+
var studioListAssets = defineTool({
|
|
5967
|
+
name: "studio_list_assets",
|
|
5968
|
+
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.",
|
|
5969
|
+
inputSchema: {
|
|
5970
|
+
projectId: z9.string().min(1).describe("Project id from studio_list_projects."),
|
|
5971
|
+
subtype: z9.enum(["Image", "Video", "CarouselSlide", "Reel"]).optional().describe("Only this kind: Image for slide backgrounds, Video for reel clips."),
|
|
5972
|
+
limit: z9.number().int().min(1).max(200).optional().describe("At most this many (default 50).")
|
|
5973
|
+
},
|
|
5974
|
+
handler: async (args, ctx) => {
|
|
5975
|
+
const { assets } = await ctx.client.listProjectAssets(args.projectId, {
|
|
5976
|
+
...args.subtype ? { subtype: args.subtype } : {},
|
|
5977
|
+
...args.limit ? { limit: args.limit } : {}
|
|
5978
|
+
});
|
|
5979
|
+
return {
|
|
5980
|
+
projectId: args.projectId,
|
|
5981
|
+
assets: assets.map((a) => {
|
|
5982
|
+
const seconds = typeof a.metadata?.durationSeconds === "number" ? a.metadata.durationSeconds : typeof a.metadata?.durationMs === "number" ? a.metadata.durationMs / 1e3 : void 0;
|
|
5983
|
+
return {
|
|
5984
|
+
id: a.id,
|
|
5985
|
+
subtype: a.subtype,
|
|
5986
|
+
url: a.url,
|
|
5987
|
+
mimeType: a.mimeType,
|
|
5988
|
+
prompt: a.prompt,
|
|
5989
|
+
...seconds !== void 0 ? { durationSeconds: seconds } : {},
|
|
5990
|
+
createdAt: a.createdAt
|
|
5991
|
+
};
|
|
5992
|
+
})
|
|
5993
|
+
};
|
|
5994
|
+
}
|
|
5995
|
+
});
|
|
5996
|
+
var studioBrandKitGet = defineTool({
|
|
5997
|
+
name: "studio_brand_kit_get",
|
|
5998
|
+
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.",
|
|
5999
|
+
inputSchema: { brandSlug: z9.string().min(1).describe("The brand slug, as studio_create_brand made it.") },
|
|
6000
|
+
handler: async (args, ctx) => {
|
|
6001
|
+
const { kit } = await ctx.client.getBrandKit(args.brandSlug);
|
|
6002
|
+
return {
|
|
6003
|
+
brandSlug: args.brandSlug,
|
|
6004
|
+
version: kit.version,
|
|
6005
|
+
colors: kit.colors,
|
|
6006
|
+
typeRoles: kit.typeRoles,
|
|
6007
|
+
fonts: kit.fonts.map((f) => ({ role: f.role, family: f.family, files: f.files.map((x) => ({ weight: x.weight, style: x.style })) })),
|
|
6008
|
+
logos: kit.logos.map((l) => ({ variant: l.variant, width: l.width, height: l.height }))
|
|
6009
|
+
};
|
|
6010
|
+
}
|
|
6011
|
+
});
|
|
6012
|
+
var studioCompositionDescribe = defineTool({
|
|
6013
|
+
name: "studio_composition_describe",
|
|
6014
|
+
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.",
|
|
6015
|
+
inputSchema: {},
|
|
6016
|
+
handler: async () => ({
|
|
6017
|
+
kinds: COMPOSITION_KINDS,
|
|
6018
|
+
aspects: COMPOSITION_ASPECTS,
|
|
6019
|
+
limits: {
|
|
6020
|
+
carouselSlides: MAX_CAROUSEL_SLIDES,
|
|
6021
|
+
reelClips: MAX_REEL_CLIPS,
|
|
6022
|
+
reelSeconds: { min: REEL_MIN_SECONDS, max: REEL_MAX_SECONDS },
|
|
6023
|
+
overlaysPerItem: MAX_OVERLAYS_PER_ITEM,
|
|
6024
|
+
overlaysPerReel: MAX_REEL_OVERLAYS,
|
|
6025
|
+
reelRendersAtOnce: 1,
|
|
6026
|
+
opsPerPatch: MAX_COMPOSITION_PATCH_OPS
|
|
6027
|
+
},
|
|
6028
|
+
opTypes: COMPOSITION_OP_TYPES,
|
|
6029
|
+
shapes: {
|
|
6030
|
+
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)',
|
|
6031
|
+
clip: '{ id, type: "clip", assetId (a video asset of the project), trimIn, trimOut (seconds), overlays: [] }',
|
|
6032
|
+
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) }',
|
|
6033
|
+
logo: '{ id, type: "logo", box, variant: "light"|"dark", start?, end? }',
|
|
6034
|
+
shape: '{ id, type: "shape", box, shape: "rect"|"pill", colorRole, opacity, start?, end? }'
|
|
6035
|
+
},
|
|
6036
|
+
targets: `addOverlay, removeOverlay, moveOverlay and setOverlayProps name a target: an item id, or "${REEL_TARGET}" for an overlay across the whole reel.`,
|
|
6037
|
+
rules: [
|
|
6038
|
+
"There is no field for a hex colour, a font family or a pixel size: overlays name kit roles (studio_brand_kit_get).",
|
|
6039
|
+
"Overlays stack in list order; the last is on top.",
|
|
6040
|
+
"A carousel is 4:5 or 1:1, at most 10 slides; a reel is 9:16, 3 to 90 s.",
|
|
6041
|
+
"Setting an optional field to null clears it.",
|
|
6042
|
+
"Rendering is free: studio_composition_render."
|
|
6043
|
+
]
|
|
6044
|
+
})
|
|
6045
|
+
});
|
|
6046
|
+
var studioCompositionList = defineTool({
|
|
6047
|
+
name: "studio_composition_list",
|
|
6048
|
+
description: "List a project's carousels and reels, newest first. Free, read-only.",
|
|
6049
|
+
inputSchema: { projectId: z9.string().min(1).optional().describe("Project id from studio_list_projects; omit for the default project.") },
|
|
6050
|
+
handler: async (args, ctx) => ctx.client.listCompositions(args.projectId !== void 0 ? { projectId: args.projectId } : {})
|
|
6051
|
+
});
|
|
6052
|
+
var studioCompositionCreate = defineTool({
|
|
6053
|
+
name: "studio_composition_create",
|
|
6054
|
+
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.",
|
|
6055
|
+
inputSchema: {
|
|
6056
|
+
kind: z9.enum(COMPOSITION_KINDS),
|
|
6057
|
+
brandSlug: z9.string().min(1).describe("The brand whose kit the overlays use."),
|
|
6058
|
+
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."),
|
|
6059
|
+
aspect: z9.enum(COMPOSITION_ASPECTS).optional().describe("4:5 (default for a carousel) or 1:1; a reel is 9:16."),
|
|
6060
|
+
label: z9.string().max(200).optional(),
|
|
6061
|
+
ops: z9.array(CompositionOpSchema).max(MAX_COMPOSITION_PATCH_OPS).optional(),
|
|
6062
|
+
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.")
|
|
6063
|
+
},
|
|
6064
|
+
handler: async (args, ctx) => {
|
|
6065
|
+
const idempotencyKey = args.idempotencyKey ?? randomUUID2();
|
|
6066
|
+
try {
|
|
6067
|
+
const { composition, replayed } = await ctx.client.createComposition({
|
|
6068
|
+
idempotencyKey,
|
|
6069
|
+
kind: args.kind,
|
|
6070
|
+
brandSlug: args.brandSlug,
|
|
6071
|
+
...args.projectId !== void 0 ? { projectId: args.projectId } : {},
|
|
6072
|
+
...args.aspect !== void 0 ? { aspect: args.aspect } : {},
|
|
6073
|
+
...args.label !== void 0 ? { label: args.label } : {},
|
|
6074
|
+
...args.ops !== void 0 ? { ops: args.ops } : {}
|
|
6075
|
+
});
|
|
6076
|
+
return { ok: true, composition: summarize(composition), ...replayed ? { replayed: true } : {} };
|
|
6077
|
+
} catch (err) {
|
|
6078
|
+
const mapped = mapCompositionFailure(err, ctx, idempotencyKey);
|
|
6079
|
+
if (mapped) return mapped;
|
|
6080
|
+
throw err;
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
6083
|
+
});
|
|
6084
|
+
var studioCompositionGet = defineTool({
|
|
6085
|
+
name: "studio_composition_get",
|
|
6086
|
+
description: "Read one carousel or reel: its items, overlays and the revision to build the next patch on. Free, read-only.",
|
|
6087
|
+
inputSchema: { compositionId },
|
|
6088
|
+
handler: async (args, ctx) => {
|
|
6089
|
+
try {
|
|
6090
|
+
return { ok: true, composition: summarize((await ctx.client.getComposition(args.compositionId)).composition) };
|
|
6091
|
+
} catch (err) {
|
|
6092
|
+
const mapped = mapCompositionFailure(err, ctx);
|
|
6093
|
+
if (mapped) return mapped;
|
|
6094
|
+
throw err;
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
6097
|
+
});
|
|
6098
|
+
var studioCompositionApply = defineTool({
|
|
6099
|
+
name: "studio_composition_apply",
|
|
6100
|
+
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).",
|
|
6101
|
+
inputSchema: {
|
|
6102
|
+
compositionId,
|
|
6103
|
+
baseRevision: z9.number().int().nonnegative().describe("The revision the ops were written against."),
|
|
6104
|
+
ops: opsSchema2,
|
|
6105
|
+
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.")
|
|
6106
|
+
},
|
|
6107
|
+
handler: async (args, ctx) => {
|
|
6108
|
+
const idempotencyKey = args.idempotencyKey ?? randomUUID2();
|
|
6109
|
+
try {
|
|
6110
|
+
const res = await ctx.client.patchComposition(args.compositionId, { baseRevision: args.baseRevision, ops: args.ops, idempotencyKey });
|
|
6111
|
+
return { ok: true, composition: summarize(res.composition), inverse: res.inverse, idempotencyKey, replayed: res.replayed === true };
|
|
6112
|
+
} catch (err) {
|
|
6113
|
+
const mapped = mapCompositionFailure(err, ctx, idempotencyKey);
|
|
6114
|
+
if (mapped) return mapped;
|
|
6115
|
+
throw err;
|
|
6116
|
+
}
|
|
6117
|
+
}
|
|
6118
|
+
});
|
|
6119
|
+
var studioCompositionRender = defineTool({
|
|
6120
|
+
name: "studio_composition_render",
|
|
6121
|
+
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.`,
|
|
6122
|
+
inputSchema: {
|
|
6123
|
+
compositionId,
|
|
6124
|
+
wait: z9.boolean().default(true),
|
|
6125
|
+
waitSeconds: z9.number().int().min(1).max(3600).default(600)
|
|
6126
|
+
},
|
|
6127
|
+
handler: async (args, ctx) => {
|
|
6128
|
+
let started;
|
|
6129
|
+
try {
|
|
6130
|
+
started = await ctx.client.renderComposition(args.compositionId);
|
|
6131
|
+
} catch (err) {
|
|
6132
|
+
const mapped = mapCompositionFailure(err, ctx);
|
|
6133
|
+
if (mapped) return mapped;
|
|
6134
|
+
throw err;
|
|
6135
|
+
}
|
|
6136
|
+
if (!args.wait) return { ok: true, jobId: started.jobId, reused: started.reused, status: "pending" };
|
|
6137
|
+
const res = await waitForJob(ctx.client, started.jobId, { timeoutMs: args.waitSeconds * 1e3 });
|
|
6138
|
+
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));
|
|
6139
|
+
if (res.job.status !== "succeeded") {
|
|
6140
|
+
return { ok: false, code: "render_failed", jobId: started.jobId, status: res.job.status, message: res.job.errorMessage ? ctx.client.redact(res.job.errorMessage) : null };
|
|
6141
|
+
}
|
|
6142
|
+
return { ok: true, jobId: started.jobId, reused: started.reused, status: res.job.status, assets };
|
|
6143
|
+
}
|
|
6144
|
+
});
|
|
6145
|
+
var SOCIAL_HINTS = {
|
|
6146
|
+
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.",
|
|
6147
|
+
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.",
|
|
6148
|
+
not_rendered: "Render the post as it is now (studio_composition_render), then send again with a NEW idempotencyKey.",
|
|
6149
|
+
idempotency_mismatch: "That idempotencyKey belongs to a different send: use a new one.",
|
|
6150
|
+
social_refused: "Lumitra Social refused it; the message says why (an unknown project slug, for one). Fix that and send with a NEW idempotencyKey.",
|
|
6151
|
+
invalid_body: "Fix the field the message names (a time in the past, for one) and send with a NEW idempotencyKey."
|
|
6152
|
+
};
|
|
6153
|
+
var studioSocialListProjects = defineTool({
|
|
6154
|
+
name: "studio_social_list_projects",
|
|
6155
|
+
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).",
|
|
6156
|
+
inputSchema: {
|
|
6157
|
+
brandSlug: z9.string().min(1).optional().describe("The brand of the post, to learn which project it went to last.")
|
|
6158
|
+
},
|
|
6159
|
+
handler: async (args, ctx) => {
|
|
6160
|
+
try {
|
|
6161
|
+
const { projects, lastProjectSlug } = await ctx.client.listSocialProjects(args.brandSlug);
|
|
6162
|
+
return { ok: true, projects: projects.map((p) => ({ slug: p.slug, name: p.name, igHandle: p.igHandle ?? null })), lastProjectSlug };
|
|
6163
|
+
} catch (err) {
|
|
6164
|
+
if (err instanceof StudioApiError) {
|
|
6165
|
+
const body = isRecord2(err.body) ? err.body : {};
|
|
6166
|
+
const code = typeof body.code === "string" ? body.code : null;
|
|
6167
|
+
if (code && SOCIAL_HINTS[code]) return { ok: false, code, message: typeof body.message === "string" ? ctx.client.redact(body.message) : null, hint: SOCIAL_HINTS[code] };
|
|
6168
|
+
if (err.status === 503) return { ok: false, code: "social_unavailable", hint: "Lumitra Social did not answer; try again shortly." };
|
|
6169
|
+
}
|
|
6170
|
+
throw err;
|
|
6171
|
+
}
|
|
6172
|
+
}
|
|
6173
|
+
});
|
|
6174
|
+
var studioCompositionSendToSocial = defineTool({
|
|
6175
|
+
name: "studio_composition_send_to_social",
|
|
6176
|
+
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.",
|
|
6177
|
+
inputSchema: {
|
|
6178
|
+
compositionId,
|
|
6179
|
+
projectSlug: z9.string().min(1).describe("The Lumitra Social project slug, from studio_social_list_projects."),
|
|
6180
|
+
caption: z9.string().max(2200).optional(),
|
|
6181
|
+
hashtags: z9.string().max(2200).optional().describe("Space-separated, at most 30 (Instagram counts them with the caption toward 2200 characters)."),
|
|
6182
|
+
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."),
|
|
6183
|
+
idempotencyKey: z9.string().min(1).max(200).optional().describe("Omit on a first send (one is generated); pass the returned one to retry.")
|
|
6184
|
+
},
|
|
6185
|
+
handler: async (args, ctx) => {
|
|
6186
|
+
const idempotencyKey = args.idempotencyKey ?? randomUUID2();
|
|
6187
|
+
try {
|
|
6188
|
+
const { send, replayed } = await ctx.client.sendCompositionToSocial(args.compositionId, {
|
|
6189
|
+
projectSlug: args.projectSlug,
|
|
6190
|
+
...args.caption !== void 0 ? { caption: args.caption } : {},
|
|
6191
|
+
...args.hashtags !== void 0 ? { hashtags: args.hashtags } : {},
|
|
6192
|
+
scheduledAt: args.scheduledAt ?? null,
|
|
6193
|
+
idempotencyKey
|
|
6194
|
+
});
|
|
6195
|
+
return {
|
|
6196
|
+
ok: true,
|
|
6197
|
+
replayed,
|
|
6198
|
+
send: { status: send.status, format: send.format, projectSlug: send.projectSlug, scheduledAt: send.scheduledAt, plannerUrl: send.plannerUrl }
|
|
6199
|
+
};
|
|
6200
|
+
} catch (err) {
|
|
6201
|
+
if (err instanceof StudioApiError) {
|
|
6202
|
+
const body = isRecord2(err.body) ? err.body : {};
|
|
6203
|
+
const code = typeof body.code === "string" ? body.code : null;
|
|
6204
|
+
const message = typeof body.message === "string" ? ctx.client.redact(body.message) : null;
|
|
6205
|
+
if (code && SOCIAL_HINTS[code]) return { ok: false, code, message, hint: SOCIAL_HINTS[code] };
|
|
6206
|
+
if (err.status === 404) return { ok: false, code: "not_found", message: message ?? "Not found in this company." };
|
|
6207
|
+
if (err.status === 0 || err.status >= 500) {
|
|
6208
|
+
return {
|
|
6209
|
+
ok: false,
|
|
6210
|
+
code: err.status === 0 ? "network_error" : code === "social_unavailable" ? code : "server_error",
|
|
6211
|
+
message: message ?? ctx.client.redact(err.message),
|
|
6212
|
+
idempotencyKey,
|
|
6213
|
+
hint: "The outcome may be partial. Retry with the SAME idempotencyKey: the send resumes where it stopped and never posts twice."
|
|
6214
|
+
};
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6217
|
+
throw err;
|
|
6218
|
+
}
|
|
6219
|
+
}
|
|
6220
|
+
});
|
|
6221
|
+
var COMPOSITION_TOOLS = [
|
|
6222
|
+
studioListAssets,
|
|
6223
|
+
studioBrandKitGet,
|
|
6224
|
+
studioCompositionDescribe,
|
|
6225
|
+
studioCompositionList,
|
|
6226
|
+
studioCompositionCreate,
|
|
6227
|
+
studioCompositionGet,
|
|
6228
|
+
studioCompositionApply,
|
|
6229
|
+
studioCompositionRender,
|
|
6230
|
+
studioSocialListProjects,
|
|
6231
|
+
studioCompositionSendToSocial
|
|
6232
|
+
];
|
|
6233
|
+
|
|
6234
|
+
// src/manageTools.ts
|
|
6235
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
6236
|
+
import { z as z10 } from "zod";
|
|
6237
|
+
var TOKEN_TTL_MS = 10 * 60 * 1e3;
|
|
6238
|
+
var ConfirmationStore = class {
|
|
6239
|
+
#tokens = /* @__PURE__ */ new Map();
|
|
6240
|
+
#now;
|
|
6241
|
+
constructor(now = Date.now) {
|
|
6242
|
+
this.#now = now;
|
|
6243
|
+
}
|
|
6244
|
+
issue(subject) {
|
|
6245
|
+
this.#sweep();
|
|
6246
|
+
const token = randomUUID3();
|
|
6247
|
+
this.#tokens.set(token, { subject, expiresAt: this.#now() + TOKEN_TTL_MS });
|
|
6248
|
+
return token;
|
|
6249
|
+
}
|
|
6250
|
+
/** True once for a live token issued for exactly this subject; the token is spent either way. */
|
|
6251
|
+
redeem(token, subject) {
|
|
6252
|
+
this.#sweep();
|
|
6253
|
+
const entry = this.#tokens.get(token);
|
|
6254
|
+
if (!entry) return false;
|
|
6255
|
+
this.#tokens.delete(token);
|
|
6256
|
+
return entry.subject === subject;
|
|
6257
|
+
}
|
|
6258
|
+
#sweep() {
|
|
6259
|
+
const now = this.#now();
|
|
6260
|
+
for (const [token, entry] of this.#tokens) if (entry.expiresAt <= now) this.#tokens.delete(token);
|
|
6261
|
+
}
|
|
6262
|
+
};
|
|
6263
|
+
function count(n, one, many) {
|
|
6264
|
+
return `${n} ${n === 1 ? one : many}`;
|
|
6265
|
+
}
|
|
6266
|
+
function projectDeleteSummary(c) {
|
|
6267
|
+
const removed = [
|
|
6268
|
+
c.workflows > 0 ? count(c.workflows, "saved workflow", "saved workflows") : null,
|
|
6269
|
+
c.runs > 0 ? count(c.runs, "run with its results", "runs with their results") : null,
|
|
6270
|
+
c.assets > 0 ? count(c.assets, "image, video or other asset", "images, videos and other assets") : null,
|
|
6271
|
+
c.chats > 0 ? count(c.chats, "chat", "chats") : null
|
|
6272
|
+
].filter((line) => line !== null);
|
|
6273
|
+
const parts = [
|
|
6274
|
+
`Delete the project "${c.project.name}" for everyone in the company?`,
|
|
6275
|
+
removed.length > 0 ? `This permanently removes ${removed.join(", ")}.` : "The project is empty: only the project itself is removed."
|
|
6276
|
+
];
|
|
6277
|
+
if (c.publishedWorkflows > 0) {
|
|
6278
|
+
parts.push(`${count(c.publishedWorkflows, "of its workflows is", "of its workflows are")} published as a recipe; the published address stops working.`);
|
|
6279
|
+
}
|
|
6280
|
+
if (c.campaignShots > 0) {
|
|
6281
|
+
parts.push(`${count(c.campaignShots, "campaign shot", "campaign shots")} in ${count(c.campaigns, "campaign", "campaigns")} will lose their image (the campaigns stay).`);
|
|
6282
|
+
}
|
|
6283
|
+
parts.push("The record of what the project cost is kept. This cannot be undone.");
|
|
6284
|
+
return parts.join(" ");
|
|
6285
|
+
}
|
|
6286
|
+
function campaignDeleteSummary(c) {
|
|
6287
|
+
const kept = c.imagesKept > 0 ? ` Its ${count(c.imagesKept, "image stays", "images stay")} in the asset library.` : "";
|
|
6288
|
+
return `Delete the campaign "${c.name}" with its ${count(c.shots, "shot", "shots")} and every approve and reject decision?${kept} This cannot be undone.`;
|
|
6289
|
+
}
|
|
6290
|
+
function projectSubject(c) {
|
|
6291
|
+
return ["delete-project", c.project.id, c.project.name, c.workflows, c.publishedWorkflows, c.runs, c.assets, c.chats, c.campaignShots].join(":");
|
|
6292
|
+
}
|
|
6293
|
+
function campaignSubject(c) {
|
|
6294
|
+
return ["delete-campaign", c.id, c.name, c.shots, c.imagesKept].join(":");
|
|
6295
|
+
}
|
|
6296
|
+
var NOT_CONFIRMED_INSTRUCTION = "Nothing was deleted. Show `summary` to the person exactly as written and ask them to confirm in the chat. Only after they explicitly say yes, call this tool again with the same id and `confirmationToken`. Never confirm on their behalf, and never reuse a token for anything else; it expires in ten minutes.";
|
|
6297
|
+
async function confirmWithPerson(ctx, summary, subject, token) {
|
|
6298
|
+
const outcome = ctx.confirm ? await ctx.confirm(summary) : "unavailable";
|
|
6299
|
+
if (outcome === "confirmed") return "proceed";
|
|
6300
|
+
if (outcome === "declined") {
|
|
6301
|
+
return { deleted: false, declined: true, summary, message: "The person declined in the confirmation dialog. Nothing was deleted." };
|
|
6302
|
+
}
|
|
6303
|
+
const store = ctx.confirmations;
|
|
6304
|
+
if (!store) {
|
|
6305
|
+
return { deleted: false, summary, message: "This client cannot ask the person to confirm, so nothing was deleted. Delete it in the Studio app instead." };
|
|
6306
|
+
}
|
|
6307
|
+
if (token && store.redeem(token, subject)) return "proceed";
|
|
6308
|
+
return {
|
|
6309
|
+
deleted: false,
|
|
6310
|
+
confirmationRequired: true,
|
|
6311
|
+
summary,
|
|
6312
|
+
confirmationToken: store.issue(subject),
|
|
6313
|
+
...token ? { note: "The token given was unknown, expired, already used, or what it confirmed has changed since. Ask the person again with this summary." } : {},
|
|
6314
|
+
instruction: NOT_CONFIRMED_INSTRUCTION
|
|
6315
|
+
};
|
|
6316
|
+
}
|
|
6317
|
+
function roleRefusal(err, sentence) {
|
|
6318
|
+
if (err instanceof StudioApiError && err.status === 403) {
|
|
6319
|
+
return { deleted: false, message: `${sentence} Nothing was deleted. Ask a person with that role to do it in the Studio app, or use a key with that role.` };
|
|
6320
|
+
}
|
|
6321
|
+
throw err;
|
|
6322
|
+
}
|
|
6323
|
+
var confirmationToken = z10.string().min(1).optional().describe(
|
|
6324
|
+
"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."
|
|
6325
|
+
);
|
|
6326
|
+
var studioCreateProject = defineTool({
|
|
6327
|
+
name: "studio_create_project",
|
|
6328
|
+
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.",
|
|
6329
|
+
inputSchema: { name: z10.string().min(1).max(120).describe("The project name, as people in the company will see it.") },
|
|
6330
|
+
handler: async (args, ctx) => (await ctx.client.createProject(args.name)).project
|
|
6331
|
+
});
|
|
6332
|
+
var studioRenameProject = defineTool({
|
|
6333
|
+
name: "studio_rename_project",
|
|
6334
|
+
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).`,
|
|
6335
|
+
inputSchema: {
|
|
6336
|
+
projectId: z10.string().min(1).describe("The project, from studio_list_projects."),
|
|
6337
|
+
name: z10.string().min(1).max(120).describe("The new name.")
|
|
6338
|
+
},
|
|
6339
|
+
annotations: { idempotentHint: true },
|
|
6340
|
+
handler: async (args, ctx) => (await ctx.client.renameProject(args.projectId, args.name)).project
|
|
6341
|
+
});
|
|
6342
|
+
var studioDeleteProject = defineTool({
|
|
6343
|
+
name: "studio_delete_project",
|
|
6344
|
+
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).",
|
|
6345
|
+
inputSchema: {
|
|
6346
|
+
projectId: z10.string().min(1).describe("The project to delete, from studio_list_projects."),
|
|
6347
|
+
confirmationToken
|
|
6348
|
+
},
|
|
6349
|
+
annotations: { destructiveHint: true },
|
|
6350
|
+
handler: async (args, ctx) => {
|
|
6351
|
+
const contents = await ctx.client.describeProject(args.projectId);
|
|
6352
|
+
if (contents.project.isDefault) {
|
|
6353
|
+
return { deleted: false, message: `"${contents.project.name}" is the company's default project: work lands there when no other project is selected, so it cannot be deleted. It can be renamed.` };
|
|
6354
|
+
}
|
|
6355
|
+
if (contents.runsInFlight > 0 || contents.jobsInFlight > 0) {
|
|
6356
|
+
return {
|
|
6357
|
+
deleted: false,
|
|
6358
|
+
message: `${count(contents.runsInFlight, "run is", "runs are")} still going and ${count(contents.jobsInFlight, "generation is", "generations are")} still rendering in "${contents.project.name}". Wait until they finish (or stop the runs), then delete it.`
|
|
6359
|
+
};
|
|
6360
|
+
}
|
|
6361
|
+
const summary = projectDeleteSummary(contents);
|
|
6362
|
+
const gate = await confirmWithPerson(ctx, summary, projectSubject(contents), args.confirmationToken);
|
|
6363
|
+
if (gate !== "proceed") return gate;
|
|
6364
|
+
try {
|
|
6365
|
+
const res = await ctx.client.deleteProject(args.projectId);
|
|
6366
|
+
return { deleted: true, project: res.project, fallbackProjectId: res.fallbackProjectId, summary };
|
|
6367
|
+
} catch (err) {
|
|
6368
|
+
return roleRefusal(err, "Deleting a project needs a key with the company admin role; this key does not have it.");
|
|
6369
|
+
}
|
|
6370
|
+
}
|
|
6371
|
+
});
|
|
6372
|
+
var studioListWorkflows = defineTool({
|
|
6373
|
+
name: "studio_list_workflows",
|
|
6374
|
+
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.",
|
|
6375
|
+
inputSchema: { projectId: z10.string().min(1).optional().describe("The project, from studio_list_projects. Omit for the default project.") },
|
|
6376
|
+
annotations: { readOnlyHint: true },
|
|
6377
|
+
handler: async (args, ctx) => {
|
|
6378
|
+
const { workflows } = await ctx.client.listWorkflows(args.projectId ? { projectId: args.projectId } : {});
|
|
6379
|
+
return { workflows: workflows.map((w) => ({ savedId: w.savedId, label: w.label, ...w.version !== void 0 ? { version: w.version } : {} })) };
|
|
6380
|
+
}
|
|
6381
|
+
});
|
|
6382
|
+
var studioMoveWorkflow = defineTool({
|
|
6383
|
+
name: "studio_move_workflow",
|
|
6384
|
+
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).",
|
|
6385
|
+
inputSchema: {
|
|
6386
|
+
savedId: z10.string().min(1).describe('The saved workflow, from studio_list_workflows (starts with "saved:").'),
|
|
6387
|
+
toProjectId: z10.string().min(1).describe("The project to move it to, from studio_list_projects."),
|
|
6388
|
+
projectId: z10.string().min(1).optional().describe("The project the workflow is in now. Omit for the default project.")
|
|
6389
|
+
},
|
|
6390
|
+
handler: async (args, ctx) => ctx.client.moveWorkflow(args.savedId, { toProjectId: args.toProjectId, ...args.projectId ? { projectId: args.projectId } : {} })
|
|
6391
|
+
});
|
|
6392
|
+
var studioListCampaigns = defineTool({
|
|
6393
|
+
name: "studio_list_campaigns",
|
|
6394
|
+
description: "List your company's campaigns, newest first (id, name, studio, shot count, created). Campaigns are shared by every project of the company.",
|
|
6395
|
+
inputSchema: {},
|
|
6396
|
+
annotations: { readOnlyHint: true },
|
|
6397
|
+
handler: async (_args, ctx) => ctx.client.listCampaigns()
|
|
6398
|
+
});
|
|
6399
|
+
var studioDeleteCampaign = defineTool({
|
|
6400
|
+
name: "studio_delete_campaign",
|
|
6401
|
+
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.",
|
|
6402
|
+
inputSchema: {
|
|
6403
|
+
campaignId: z10.string().min(1).describe("The campaign, from studio_list_campaigns."),
|
|
6404
|
+
confirmationToken
|
|
6405
|
+
},
|
|
6406
|
+
annotations: { destructiveHint: true },
|
|
6407
|
+
handler: async (args, ctx) => {
|
|
6408
|
+
const contents = await ctx.client.describeCampaign(args.campaignId);
|
|
6409
|
+
if (contents.shotsRendering > 0) {
|
|
6410
|
+
return {
|
|
6411
|
+
deleted: false,
|
|
6412
|
+
message: `${count(contents.shotsRendering, "shot is", "shots are")} of "${contents.name}" still rendering. Wait until they finish, then delete the campaign.`
|
|
6413
|
+
};
|
|
6414
|
+
}
|
|
6415
|
+
const summary = campaignDeleteSummary(contents);
|
|
6416
|
+
const gate = await confirmWithPerson(ctx, summary, campaignSubject(contents), args.confirmationToken);
|
|
6417
|
+
if (gate !== "proceed") return gate;
|
|
6418
|
+
try {
|
|
6419
|
+
const res = await ctx.client.deleteCampaign(args.campaignId);
|
|
6420
|
+
return { deleted: true, id: res.id, shotsDeleted: res.shotsDeleted, summary };
|
|
6421
|
+
} catch (err) {
|
|
6422
|
+
return roleRefusal(err, "Deleting a campaign needs a key with at least the company member role; this key does not have it.");
|
|
6423
|
+
}
|
|
6424
|
+
}
|
|
6425
|
+
});
|
|
6426
|
+
var MANAGE_TOOLS = [
|
|
6427
|
+
studioCreateProject,
|
|
6428
|
+
studioRenameProject,
|
|
6429
|
+
studioDeleteProject,
|
|
6430
|
+
studioListWorkflows,
|
|
6431
|
+
studioMoveWorkflow,
|
|
6432
|
+
studioListCampaigns,
|
|
6433
|
+
studioDeleteCampaign
|
|
6434
|
+
];
|
|
6435
|
+
|
|
5638
6436
|
// src/tools.ts
|
|
5639
|
-
var slug =
|
|
5640
|
-
var waitSeconds =
|
|
5641
|
-
var httpUrl =
|
|
6437
|
+
var slug = z11.string().regex(/^[a-z0-9-]+$/, "lowercase letters, numbers and hyphens only").describe("URL-safe identifier: lowercase letters, numbers, hyphens.");
|
|
6438
|
+
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.");
|
|
6439
|
+
var httpUrl = z11.string().url().refine((u) => /^https?:\/\//i.test(u), "must be an http(s) URL");
|
|
5642
6440
|
function pollOpts(ctx, timeoutSec) {
|
|
5643
6441
|
return { ...ctx.poll, timeoutMs: timeoutSec * 1e3 };
|
|
5644
6442
|
}
|
|
@@ -5714,22 +6512,22 @@ var studioGenerateImage = defineTool({
|
|
|
5714
6512
|
brandSlug: slug.optional().describe(
|
|
5715
6513
|
"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."
|
|
5716
6514
|
),
|
|
5717
|
-
brandMode:
|
|
5718
|
-
prompt:
|
|
6515
|
+
brandMode: z11.string().optional().describe('Optional brand mode (e.g. "illustration"); modes are defined per brand. Only meaningful with brandSlug.'),
|
|
6516
|
+
prompt: z11.string().min(1).describe("What to generate. With brandSlug, the brand style prefix is prepended server-side."),
|
|
5719
6517
|
characterSlug: slug.optional().describe(
|
|
5720
6518
|
"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."
|
|
5721
6519
|
),
|
|
5722
|
-
projectId:
|
|
6520
|
+
projectId: z11.string().min(1).optional().describe(
|
|
5723
6521
|
'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.'
|
|
5724
6522
|
),
|
|
5725
|
-
model:
|
|
5726
|
-
aspectRatio:
|
|
5727
|
-
imageSize:
|
|
5728
|
-
seed:
|
|
5729
|
-
candidateCount:
|
|
6523
|
+
model: z11.string().optional().describe('Image model id (e.g. "kie/nano-banana-2", "fal/nano-banana-2"). Omit for the Studio default.'),
|
|
6524
|
+
aspectRatio: z11.string().optional().describe('Aspect ratio such as "1:1", "16:9", "3:4".'),
|
|
6525
|
+
imageSize: z11.string().optional().describe('Provider size hint, e.g. "1K", "2K".'),
|
|
6526
|
+
seed: z11.number().int().optional(),
|
|
6527
|
+
candidateCount: z11.number().int().min(1).max(4).optional().describe(
|
|
5730
6528
|
"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."
|
|
5731
6529
|
),
|
|
5732
|
-
wait:
|
|
6530
|
+
wait: z11.boolean().default(true).describe("Poll until the job finishes (default true)."),
|
|
5733
6531
|
waitSeconds
|
|
5734
6532
|
},
|
|
5735
6533
|
handler: async (args, ctx) => {
|
|
@@ -5765,23 +6563,23 @@ var studioGenerate3d = defineTool({
|
|
|
5765
6563
|
name: "studio_generate_3d",
|
|
5766
6564
|
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.",
|
|
5767
6565
|
inputSchema: {
|
|
5768
|
-
prompt:
|
|
6566
|
+
prompt: z11.string().min(1).max(1024).describe("What to model. With imageUrl, a short description of the object in the image."),
|
|
5769
6567
|
imageUrl: httpUrl.optional().describe("Public http(s) URL of one image to model from. Selects an image model."),
|
|
5770
|
-
model:
|
|
5771
|
-
options:
|
|
5772
|
-
enableTexture:
|
|
5773
|
-
enablePbr:
|
|
5774
|
-
textureQuality:
|
|
5775
|
-
geometryQuality:
|
|
5776
|
-
quadRemesh:
|
|
5777
|
-
smartLowPoly:
|
|
5778
|
-
resolution:
|
|
5779
|
-
targetPolycount:
|
|
5780
|
-
topology:
|
|
5781
|
-
seed:
|
|
6568
|
+
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)."),
|
|
6569
|
+
options: z11.object({
|
|
6570
|
+
enableTexture: z11.boolean().optional().describe("Texture the mesh (default true). Off gives bare geometry and costs less."),
|
|
6571
|
+
enablePbr: z11.boolean().optional().describe("Physically-based rendering (PBR) material maps. Default on for Hunyuan Pro, off elsewhere."),
|
|
6572
|
+
textureQuality: z11.enum(["standard", "detailed"]).optional().describe("Tripo texture tier. detailed costs more."),
|
|
6573
|
+
geometryQuality: z11.enum(["standard", "detailed"]).optional().describe("Tripo geometry tier. detailed costs more."),
|
|
6574
|
+
quadRemesh: z11.boolean().optional().describe("Tripo: quad topology instead of triangles."),
|
|
6575
|
+
smartLowPoly: z11.boolean().optional().describe("Tripo text-to-3D: a low-poly mesh."),
|
|
6576
|
+
resolution: z11.enum(["512", "1024", "1536"]).optional().describe("TRELLIS.2 resolution (default 1024)."),
|
|
6577
|
+
targetPolycount: z11.number().int().min(100).max(15e5).optional().describe("Target face count, where the model supports one."),
|
|
6578
|
+
topology: z11.enum(["quad", "triangle"]).optional().describe("Hunyuan Pro polygon type."),
|
|
6579
|
+
seed: z11.number().int().optional()
|
|
5782
6580
|
}).optional().describe("Model-specific quality flags. Each changes the price; the returned costUsd is the price of the request that was sent."),
|
|
5783
|
-
projectId:
|
|
5784
|
-
wait:
|
|
6581
|
+
projectId: z11.string().min(1).optional().describe("Project to file the model under (from studio_list_projects). Omit for the default project."),
|
|
6582
|
+
wait: z11.boolean().default(true).describe("Poll until the job finishes (default true)."),
|
|
5785
6583
|
waitSeconds
|
|
5786
6584
|
},
|
|
5787
6585
|
handler: async (args, ctx) => {
|
|
@@ -5819,8 +6617,8 @@ var studioFindAnimations = defineTool({
|
|
|
5819
6617
|
name: "studio_find_animations",
|
|
5820
6618
|
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.',
|
|
5821
6619
|
inputSchema: {
|
|
5822
|
-
query:
|
|
5823
|
-
limit:
|
|
6620
|
+
query: z11.string().describe('Words to match, e.g. "sword slash". Empty returns the first presets in library order.'),
|
|
6621
|
+
limit: z11.number().int().min(1).max(50).default(25)
|
|
5824
6622
|
},
|
|
5825
6623
|
annotations: { readOnlyHint: true },
|
|
5826
6624
|
handler: async (args) => ({ animations: searchAnimations(args.query, args.limit) })
|
|
@@ -5829,12 +6627,12 @@ var studioRig3d = defineTool({
|
|
|
5829
6627
|
name: "studio_rig_3d",
|
|
5830
6628
|
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.",
|
|
5831
6629
|
inputSchema: {
|
|
5832
|
-
projectId:
|
|
5833
|
-
meshAssetId:
|
|
5834
|
-
animations:
|
|
5835
|
-
heightMeters:
|
|
5836
|
-
visibility:
|
|
5837
|
-
wait:
|
|
6630
|
+
projectId: z11.string().min(1).describe("The project the mesh lives in (from studio_list_projects)."),
|
|
6631
|
+
meshAssetId: z11.string().min(1).describe("The Model3D asset to rig: the assetId studio_generate_3d returned."),
|
|
6632
|
+
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.'),
|
|
6633
|
+
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."),
|
|
6634
|
+
visibility: z11.enum(["listed", "unlisted"]).optional(),
|
|
6635
|
+
wait: z11.boolean().default(true).describe("Poll until the rig finishes (default true)."),
|
|
5838
6636
|
waitSeconds
|
|
5839
6637
|
},
|
|
5840
6638
|
handler: async (args, ctx) => {
|
|
@@ -5891,8 +6689,8 @@ var studioGetJob = defineTool({
|
|
|
5891
6689
|
name: "studio_get_job",
|
|
5892
6690
|
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.",
|
|
5893
6691
|
inputSchema: {
|
|
5894
|
-
jobId:
|
|
5895
|
-
wait:
|
|
6692
|
+
jobId: z11.string().min(1),
|
|
6693
|
+
wait: z11.boolean().default(false).describe("Poll until terminal (default false: return the current state)."),
|
|
5896
6694
|
waitSeconds
|
|
5897
6695
|
},
|
|
5898
6696
|
annotations: { readOnlyHint: true },
|
|
@@ -5922,7 +6720,7 @@ var studioGetCharacter = defineTool({
|
|
|
5922
6720
|
}
|
|
5923
6721
|
});
|
|
5924
6722
|
var LIKENESS_REFUSAL = `${LIKENESS_CONFIRMATION_REQUIRED_CODE}: ${likenessConfirmationRequiredMessage()}`;
|
|
5925
|
-
var likenessRightsConfirmed =
|
|
6723
|
+
var likenessRightsConfirmed = z11.literal(true, { error: LIKENESS_REFUSAL }).describe(likenessConfirmationToolDescription());
|
|
5926
6724
|
function assertLikenessRightsConfirmed(value) {
|
|
5927
6725
|
if (!isLikenessRightsConfirmed(value)) throw new Error(LIKENESS_REFUSAL);
|
|
5928
6726
|
}
|
|
@@ -5930,11 +6728,11 @@ var studioCreateCharacter = defineTool({
|
|
|
5930
6728
|
name: "studio_create_character",
|
|
5931
6729
|
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.",
|
|
5932
6730
|
inputSchema: {
|
|
5933
|
-
name:
|
|
6731
|
+
name: z11.string().min(1).describe('Display name, e.g. "Bruno Hartmann".'),
|
|
5934
6732
|
slug,
|
|
5935
|
-
descriptorPrompt:
|
|
5936
|
-
negativePrompt:
|
|
5937
|
-
defaultModel:
|
|
6733
|
+
descriptorPrompt: z11.string().min(1).describe("The identity description prepended to every generation that uses this character."),
|
|
6734
|
+
negativePrompt: z11.string().optional(),
|
|
6735
|
+
defaultModel: z11.string().optional().describe("Default image model id for this character."),
|
|
5938
6736
|
likenessRightsConfirmed
|
|
5939
6737
|
},
|
|
5940
6738
|
handler: async (args, ctx) => {
|
|
@@ -5954,16 +6752,16 @@ var studioMintCharacter = defineTool({
|
|
|
5954
6752
|
name: "studio_mint_character",
|
|
5955
6753
|
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.",
|
|
5956
6754
|
inputSchema: {
|
|
5957
|
-
projectId:
|
|
5958
|
-
name:
|
|
6755
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
6756
|
+
name: z11.string().min(1).describe("Display name."),
|
|
5959
6757
|
slug,
|
|
5960
|
-
description:
|
|
5961
|
-
descriptorPrompt:
|
|
5962
|
-
negativePrompt:
|
|
5963
|
-
defaultModel:
|
|
5964
|
-
seedModel:
|
|
5965
|
-
viewModel:
|
|
5966
|
-
visibility:
|
|
6758
|
+
description: z11.string().min(10).describe("Seed identity description (face, hair, age, build, distinguishing features)."),
|
|
6759
|
+
descriptorPrompt: z11.string().optional().describe("Override for the character's stored descriptor prompt. Defaults to the description."),
|
|
6760
|
+
negativePrompt: z11.string().optional(),
|
|
6761
|
+
defaultModel: z11.string().optional(),
|
|
6762
|
+
seedModel: z11.string().optional().describe("Override the seed text-to-image model (default fal/nano-banana-2)."),
|
|
6763
|
+
viewModel: z11.string().optional().describe("Override the view image-edit model (default fal/nano-banana-2-edit)."),
|
|
6764
|
+
visibility: z11.enum(["listed", "unlisted"]).optional().describe("Whether the run shows in the Studio workflow list."),
|
|
5967
6765
|
likenessRightsConfirmed,
|
|
5968
6766
|
waitSeconds
|
|
5969
6767
|
},
|
|
@@ -6022,12 +6820,12 @@ var studioCreateBrand = defineTool({
|
|
|
6022
6820
|
name: "studio_create_brand",
|
|
6023
6821
|
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.",
|
|
6024
6822
|
inputSchema: {
|
|
6025
|
-
name:
|
|
6823
|
+
name: z11.string().min(1),
|
|
6026
6824
|
slug,
|
|
6027
|
-
stylePrefix:
|
|
6028
|
-
context:
|
|
6029
|
-
defaultModel:
|
|
6030
|
-
maxReferenceImages:
|
|
6825
|
+
stylePrefix: z11.string().optional().describe("Text prepended to every prompt generated under this brand."),
|
|
6826
|
+
context: z11.string().optional().describe("Markdown brand context (tone, palette, do/don't)."),
|
|
6827
|
+
defaultModel: z11.string().optional(),
|
|
6828
|
+
maxReferenceImages: z11.number().int().min(0).max(8).optional()
|
|
6031
6829
|
},
|
|
6032
6830
|
handler: async (args, ctx) => {
|
|
6033
6831
|
const { config } = await ctx.client.createBrand({
|
|
@@ -6046,11 +6844,11 @@ var studioUploadBrandReference = defineTool({
|
|
|
6046
6844
|
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.`,
|
|
6047
6845
|
inputSchema: {
|
|
6048
6846
|
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."),
|
|
6049
|
-
source:
|
|
6050
|
-
category:
|
|
6051
|
-
label:
|
|
6052
|
-
tags:
|
|
6053
|
-
score:
|
|
6847
|
+
source: z11.string().min(1).describe("Local file path or http(s) URL of an image."),
|
|
6848
|
+
category: z11.string().optional().describe('Library category, default "general".'),
|
|
6849
|
+
label: z11.string().optional().describe("Optional file name / label."),
|
|
6850
|
+
tags: z11.array(z11.string()).optional(),
|
|
6851
|
+
score: z11.number().int().min(1).max(10).optional()
|
|
6054
6852
|
},
|
|
6055
6853
|
handler: async (args, ctx) => {
|
|
6056
6854
|
const file = await loadImageSource(args.source, ctx.client);
|
|
@@ -6069,25 +6867,28 @@ var workflowDefinitionSchema = WorkflowDefinitionSchema.describe(
|
|
|
6069
6867
|
);
|
|
6070
6868
|
var studioRunWorkflow = defineTool({
|
|
6071
6869
|
name: "studio_run_workflow",
|
|
6072
|
-
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.`,
|
|
6870
|
+
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).`,
|
|
6073
6871
|
inputSchema: {
|
|
6074
|
-
projectId:
|
|
6872
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
6075
6873
|
definition: workflowDefinitionSchema.optional(),
|
|
6076
|
-
savedId:
|
|
6077
|
-
params:
|
|
6078
|
-
nodeIds:
|
|
6079
|
-
upstreamGenerations:
|
|
6874
|
+
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."),
|
|
6875
|
+
params: z11.record(z11.string(), z11.unknown()).optional().describe("Values for the definition's params."),
|
|
6876
|
+
nodeIds: z11.array(z11.string()).optional().describe("Run only this subset of nodes (requires an inline `definition` or a `savedId`)."),
|
|
6877
|
+
upstreamGenerations: z11.record(z11.string(), z11.string()).optional().describe(
|
|
6080
6878
|
'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.'
|
|
6081
6879
|
),
|
|
6082
|
-
runs:
|
|
6083
|
-
visibility:
|
|
6084
|
-
budgetUsd:
|
|
6880
|
+
runs: z11.number().int().min(1).max(8).optional().describe("Repeat a node subset N times (1 to 8)."),
|
|
6881
|
+
visibility: z11.enum(["listed", "unlisted"]).optional().describe("Whether the run shows in the Studio workflow list."),
|
|
6882
|
+
budgetUsd: z11.number().nonnegative().optional().describe(
|
|
6085
6883
|
'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.'
|
|
6086
6884
|
),
|
|
6087
|
-
confirm:
|
|
6885
|
+
confirm: z11.boolean().optional().describe(
|
|
6088
6886
|
'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 }.'
|
|
6089
6887
|
),
|
|
6090
|
-
|
|
6888
|
+
acknowledgeContinuity: z11.boolean().optional().describe(
|
|
6889
|
+
'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.'
|
|
6890
|
+
),
|
|
6891
|
+
wait: z11.boolean().default(true),
|
|
6091
6892
|
waitSeconds
|
|
6092
6893
|
},
|
|
6093
6894
|
handler: async (args, ctx) => {
|
|
@@ -6107,7 +6908,8 @@ var studioRunWorkflow = defineTool({
|
|
|
6107
6908
|
...args.savedId ? { savedId: args.savedId } : {},
|
|
6108
6909
|
...args.visibility ? { visibility: args.visibility } : {},
|
|
6109
6910
|
...args.budgetUsd !== void 0 ? { budgetUsd: args.budgetUsd } : {},
|
|
6110
|
-
...args.confirm !== void 0 ? { confirm: args.confirm } : {}
|
|
6911
|
+
...args.confirm !== void 0 ? { confirm: args.confirm } : {},
|
|
6912
|
+
...args.acknowledgeContinuity !== void 0 ? { acknowledgeContinuity: args.acknowledgeContinuity } : {}
|
|
6111
6913
|
});
|
|
6112
6914
|
if (!args.wait) return { runId: started.runId, runIds: started.runIds, status: started.status };
|
|
6113
6915
|
const run = await waitForRun(ctx.client, started.runId, pollOpts(ctx, args.waitSeconds));
|
|
@@ -6118,8 +6920,8 @@ var studioGetRun = defineTool({
|
|
|
6118
6920
|
name: "studio_get_run",
|
|
6119
6921
|
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.",
|
|
6120
6922
|
inputSchema: {
|
|
6121
|
-
runId:
|
|
6122
|
-
wait:
|
|
6923
|
+
runId: z11.string().min(1),
|
|
6924
|
+
wait: z11.boolean().default(false),
|
|
6123
6925
|
waitSeconds
|
|
6124
6926
|
},
|
|
6125
6927
|
annotations: { readOnlyHint: true },
|
|
@@ -6132,11 +6934,11 @@ var studioDecideJudge = defineTool({
|
|
|
6132
6934
|
name: "studio_decide_judge",
|
|
6133
6935
|
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.",
|
|
6134
6936
|
inputSchema: {
|
|
6135
|
-
runId:
|
|
6136
|
-
nodeId:
|
|
6137
|
-
verdict:
|
|
6138
|
-
candidate:
|
|
6139
|
-
reason:
|
|
6937
|
+
runId: z11.string().min(1),
|
|
6938
|
+
nodeId: z11.string().min(1),
|
|
6939
|
+
verdict: z11.enum(["approved", "rejected"]),
|
|
6940
|
+
candidate: z11.object({ generationId: z11.string().min(1), index: z11.number().int().min(0).optional() }).optional(),
|
|
6941
|
+
reason: z11.string().max(500).optional()
|
|
6140
6942
|
},
|
|
6141
6943
|
annotations: { destructiveHint: false, idempotentHint: false },
|
|
6142
6944
|
handler: async (args, ctx) => {
|
|
@@ -6152,8 +6954,8 @@ var studioGetRunOutput = defineTool({
|
|
|
6152
6954
|
name: "studio_get_run_output",
|
|
6153
6955
|
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.",
|
|
6154
6956
|
inputSchema: {
|
|
6155
|
-
runId:
|
|
6156
|
-
nodeId:
|
|
6957
|
+
runId: z11.string().min(1),
|
|
6958
|
+
nodeId: z11.string().min(1)
|
|
6157
6959
|
},
|
|
6158
6960
|
annotations: { readOnlyHint: true },
|
|
6159
6961
|
handler: async (args, ctx) => {
|
|
@@ -6165,21 +6967,24 @@ var studioReplaceCharacterInVideo = defineTool({
|
|
|
6165
6967
|
name: "studio_replace_character_in_video",
|
|
6166
6968
|
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.',
|
|
6167
6969
|
inputSchema: {
|
|
6168
|
-
projectId:
|
|
6970
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
6169
6971
|
sceneFrameUrl: httpUrl.describe("Public or signed URL of ONE frame of the target shot (png/jpg)."),
|
|
6170
6972
|
characterSlug: slug.optional().describe(
|
|
6171
6973
|
"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."
|
|
6172
6974
|
),
|
|
6173
6975
|
characterReferenceUrl: httpUrl.optional().describe("Explicit character reference image URL (use instead of characterSlug)."),
|
|
6174
6976
|
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."),
|
|
6175
|
-
scope:
|
|
6176
|
-
preserve:
|
|
6177
|
-
swapPrompt:
|
|
6178
|
-
motionPrompt:
|
|
6179
|
-
videoModel:
|
|
6180
|
-
editModel:
|
|
6181
|
-
aspectRatio:
|
|
6182
|
-
visibility:
|
|
6977
|
+
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."),
|
|
6978
|
+
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.'),
|
|
6979
|
+
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."),
|
|
6980
|
+
motionPrompt: z11.string().optional().describe("Override the motion description for the video node."),
|
|
6981
|
+
videoModel: z11.string().optional().describe(`Image-to-video model id. Default ${DEFAULT_SWAP_VIDEO_MODEL}, or ${KEYFRAME_SWAP_VIDEO_MODEL} when endFrameUrl is given.`),
|
|
6982
|
+
editModel: z11.string().default(DEFAULT_SWAP_EDIT_MODEL).describe("Image-edit model id for the still swap."),
|
|
6983
|
+
aspectRatio: z11.string().default("16:9"),
|
|
6984
|
+
visibility: z11.enum(["listed", "unlisted"]).optional(),
|
|
6985
|
+
acknowledgeContinuity: z11.boolean().optional().describe(
|
|
6986
|
+
"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."
|
|
6987
|
+
),
|
|
6183
6988
|
waitSeconds
|
|
6184
6989
|
},
|
|
6185
6990
|
handler: async (args, ctx) => {
|
|
@@ -6215,7 +7020,8 @@ var studioReplaceCharacterInVideo = defineTool({
|
|
|
6215
7020
|
const started = await ctx.client.runWorkflow({
|
|
6216
7021
|
projectId: args.projectId,
|
|
6217
7022
|
definition,
|
|
6218
|
-
...args.visibility ? { visibility: args.visibility } : {}
|
|
7023
|
+
...args.visibility ? { visibility: args.visibility } : {},
|
|
7024
|
+
...args.acknowledgeContinuity !== void 0 ? { acknowledgeContinuity: args.acknowledgeContinuity } : {}
|
|
6219
7025
|
});
|
|
6220
7026
|
const run = await waitForRun(ctx.client, started.runId, pollOpts(ctx, args.waitSeconds));
|
|
6221
7027
|
const stillUrl = nodeUrl(run, SWAP_EDIT_NODE_ID);
|
|
@@ -6244,7 +7050,7 @@ var studioGetSpend = defineTool({
|
|
|
6244
7050
|
name: "studio_get_spend",
|
|
6245
7051
|
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).`,
|
|
6246
7052
|
inputSchema: {
|
|
6247
|
-
tzOffsetMinutes:
|
|
7053
|
+
tzOffsetMinutes: z11.number().int().min(-840).max(840).optional()
|
|
6248
7054
|
},
|
|
6249
7055
|
annotations: { readOnlyHint: true },
|
|
6250
7056
|
handler: async (args, ctx) => {
|
|
@@ -6272,7 +7078,7 @@ var studioDescribePublished = defineTool({
|
|
|
6272
7078
|
name: "studio_describe_published",
|
|
6273
7079
|
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.",
|
|
6274
7080
|
inputSchema: {
|
|
6275
|
-
slug:
|
|
7081
|
+
slug: z11.string().min(1).describe("The recipe slug, from studio_list_published.")
|
|
6276
7082
|
},
|
|
6277
7083
|
annotations: { readOnlyHint: true },
|
|
6278
7084
|
handler: async (args, ctx) => {
|
|
@@ -6282,19 +7088,22 @@ var studioDescribePublished = defineTool({
|
|
|
6282
7088
|
});
|
|
6283
7089
|
var studioRunPublished = defineTool({
|
|
6284
7090
|
name: "studio_run_published",
|
|
6285
|
-
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.`,
|
|
7091
|
+
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).`,
|
|
6286
7092
|
inputSchema: {
|
|
6287
|
-
slug:
|
|
6288
|
-
projectId:
|
|
6289
|
-
params:
|
|
6290
|
-
budgetUsd:
|
|
7093
|
+
slug: z11.string().min(1).describe("The recipe slug, from studio_list_published."),
|
|
7094
|
+
projectId: z11.string().min(1).describe("Project id from studio_list_projects."),
|
|
7095
|
+
params: z11.record(z11.string(), z11.unknown()).optional().describe("Values for the recipe's params (see studio_describe_published)."),
|
|
7096
|
+
budgetUsd: z11.number().nonnegative().optional().describe(
|
|
6291
7097
|
'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 }.'
|
|
6292
7098
|
),
|
|
6293
|
-
confirm:
|
|
7099
|
+
confirm: z11.boolean().optional().describe(
|
|
6294
7100
|
'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 }.'
|
|
6295
7101
|
),
|
|
6296
|
-
likenessRightsConfirmed:
|
|
6297
|
-
|
|
7102
|
+
likenessRightsConfirmed: z11.literal(true).optional().describe(`Required when the recipe creates a character; ignored otherwise. ${likenessConfirmationToolDescription()}`),
|
|
7103
|
+
acknowledgeContinuity: z11.boolean().optional().describe(
|
|
7104
|
+
'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.'
|
|
7105
|
+
),
|
|
7106
|
+
wait: z11.boolean().default(true),
|
|
6298
7107
|
waitSeconds
|
|
6299
7108
|
},
|
|
6300
7109
|
handler: async (args, ctx) => {
|
|
@@ -6303,7 +7112,8 @@ var studioRunPublished = defineTool({
|
|
|
6303
7112
|
...args.params ? { params: args.params } : {},
|
|
6304
7113
|
...args.budgetUsd !== void 0 ? { budgetUsd: args.budgetUsd } : {},
|
|
6305
7114
|
...args.confirm !== void 0 ? { confirm: args.confirm } : {},
|
|
6306
|
-
...args.likenessRightsConfirmed === true ? { likenessRightsConfirmed: true } : {}
|
|
7115
|
+
...args.likenessRightsConfirmed === true ? { likenessRightsConfirmed: true } : {},
|
|
7116
|
+
...args.acknowledgeContinuity !== void 0 ? { acknowledgeContinuity: args.acknowledgeContinuity } : {}
|
|
6307
7117
|
});
|
|
6308
7118
|
if (!args.wait) return { runId: started.runId, status: started.status };
|
|
6309
7119
|
const run = await waitForRun(ctx.client, started.runId, pollOpts(ctx, args.waitSeconds));
|
|
@@ -6333,7 +7143,9 @@ var TOOLS = [
|
|
|
6333
7143
|
studioDescribePublished,
|
|
6334
7144
|
studioRunPublished,
|
|
6335
7145
|
studioGetUsage,
|
|
6336
|
-
...WORKFLOW_TOOLS
|
|
7146
|
+
...WORKFLOW_TOOLS,
|
|
7147
|
+
...MANAGE_TOOLS,
|
|
7148
|
+
...COMPOSITION_TOOLS
|
|
6337
7149
|
];
|
|
6338
7150
|
var TOOL_NAMES = TOOLS.map((t) => t.name);
|
|
6339
7151
|
function toolResult(value) {
|
|
@@ -6351,14 +7163,42 @@ function toolError(message) {
|
|
|
6351
7163
|
}
|
|
6352
7164
|
async function invokeTool(def, args, ctx) {
|
|
6353
7165
|
try {
|
|
6354
|
-
const parsed =
|
|
7166
|
+
const parsed = z11.object(def.inputSchema).parse(args ?? {});
|
|
6355
7167
|
const value = await def.handler(parsed, ctx);
|
|
6356
7168
|
return toolResult(value);
|
|
6357
7169
|
} catch (err) {
|
|
6358
7170
|
return toolError(ctx.client.redact(errorMessage(err)));
|
|
6359
7171
|
}
|
|
6360
7172
|
}
|
|
6361
|
-
function
|
|
7173
|
+
function elicitConfirmation(server) {
|
|
7174
|
+
return async (message) => {
|
|
7175
|
+
if (!server.server.getClientCapabilities()?.elicitation) return "unavailable";
|
|
7176
|
+
try {
|
|
7177
|
+
const result = await server.server.elicitInput({
|
|
7178
|
+
message,
|
|
7179
|
+
requestedSchema: {
|
|
7180
|
+
type: "object",
|
|
7181
|
+
properties: {
|
|
7182
|
+
confirm: { type: "boolean", title: "Delete", description: "Yes, delete it. This cannot be undone." }
|
|
7183
|
+
},
|
|
7184
|
+
required: ["confirm"]
|
|
7185
|
+
}
|
|
7186
|
+
});
|
|
7187
|
+
return result.action === "accept" && result.content?.confirm === true ? "confirmed" : "declined";
|
|
7188
|
+
} catch (err) {
|
|
7189
|
+
const code = err?.code;
|
|
7190
|
+
if (code === METHOD_NOT_FOUND || /does not support/i.test(err instanceof Error ? err.message : "")) return "unavailable";
|
|
7191
|
+
return "declined";
|
|
7192
|
+
}
|
|
7193
|
+
};
|
|
7194
|
+
}
|
|
7195
|
+
var METHOD_NOT_FOUND = -32601;
|
|
7196
|
+
function registerTools(server, base) {
|
|
7197
|
+
const ctx = {
|
|
7198
|
+
...base,
|
|
7199
|
+
confirm: base.confirm ?? elicitConfirmation(server),
|
|
7200
|
+
confirmations: base.confirmations ?? new ConfirmationStore()
|
|
7201
|
+
};
|
|
6362
7202
|
for (const def of TOOLS) {
|
|
6363
7203
|
server.registerTool(
|
|
6364
7204
|
def.name,
|
|
@@ -6374,7 +7214,7 @@ function registerTools(server, ctx) {
|
|
|
6374
7214
|
|
|
6375
7215
|
// src/server.ts
|
|
6376
7216
|
var SERVER_NAME = "lumitra-studio";
|
|
6377
|
-
var SERVER_VERSION = "0.
|
|
7217
|
+
var SERVER_VERSION = "0.8.0";
|
|
6378
7218
|
function createStudioMcpServer(opts = {}) {
|
|
6379
7219
|
const config = opts.config ?? resolveConfig(opts.env ?? process.env);
|
|
6380
7220
|
const client = new StudioClient(config, {
|
|
@@ -6399,7 +7239,7 @@ function createStudioMcpServer(opts = {}) {
|
|
|
6399
7239
|
|
|
6400
7240
|
// src/cli.ts
|
|
6401
7241
|
import { createServer as createHttpServer } from "http";
|
|
6402
|
-
import { randomUUID as
|
|
7242
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
6403
7243
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6404
7244
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
6405
7245
|
function parseArgs(argv) {
|
|
@@ -6484,7 +7324,7 @@ async function runHttp(args) {
|
|
|
6484
7324
|
});
|
|
6485
7325
|
const addr = httpServer.address();
|
|
6486
7326
|
const port = typeof addr === "object" && addr ? addr.port : args.port;
|
|
6487
|
-
process.stderr.write(`[${SERVER_NAME}] Streamable HTTP on http://${args.host}:${port}/mcp (${TOOL_NAMES.length} tools, instance ${
|
|
7327
|
+
process.stderr.write(`[${SERVER_NAME}] Streamable HTTP on http://${args.host}:${port}/mcp (${TOOL_NAMES.length} tools, instance ${randomUUID4().slice(0, 8)})
|
|
6488
7328
|
`);
|
|
6489
7329
|
const shutdown = () => {
|
|
6490
7330
|
httpServer.close(() => process.exit(0));
|