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