@simpligen/mcp 0.8.1 → 0.9.1
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 +71 -47
- package/package.json +37 -37
- package/src/bin.js +18 -13
- package/src/cliArgs.js +51 -0
- package/src/client.js +174 -171
- package/src/index.js +6 -6
- package/src/server.js +15 -15
- package/src/tools.js +784 -784
package/src/tools.js
CHANGED
|
@@ -1,784 +1,784 @@
|
|
|
1
|
-
// packages/mcp-server/src/tools.js
|
|
2
|
-
// Registers SimpliGen MCP tools on an McpServer-shaped object. Each tool calls a
|
|
3
|
-
// ControlApiClient method and returns the JSON result as text content; client
|
|
4
|
-
// errors become an isError tool result (so the agent sees the errorCode/message).
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
import { buildResultImageContent } from './resultImage.js';
|
|
7
|
-
|
|
8
|
-
export const TOOL_NAMES = [
|
|
9
|
-
'list_capabilities', 'get_status', 'start_engine', 'stop_engine', 'restart_engine',
|
|
10
|
-
'list_projects', 'create_project',
|
|
11
|
-
'wait_for_approval', 'get_app_context', 'fill_generate_form', 'open_screen',
|
|
12
|
-
'upload_file', 'generate', 'list_loras', 'get_prompt_guide', 'get_job', 'wait_for_result', 'list_jobs',
|
|
13
|
-
'cancel_job', 'prepare_preset', 'get_result_image',
|
|
14
|
-
'list_characters', 'get_character', 'list_character_features', 'list_character_presets',
|
|
15
|
-
'remove_character', 'create_character', 'generate_character_image', 'generate_character_video',
|
|
16
|
-
'generate_character_frame', 'animate_character', 'set_character_preset',
|
|
17
|
-
'enhance_character_media', 'regenerate_character_base', 'accept_character_base',
|
|
18
|
-
'list_recipe_blocks', 'compose_recipe', 'validate_recipe', 'list_recipes', 'get_recipe', 'publish_recipe',
|
|
19
|
-
'run_recipe', 'get_recipe_run', 'wait_for_recipe_run', 'list_recipe_runs', 'cancel_recipe_run',
|
|
20
|
-
'list_subjects', 'list_products', 'create_product', 'remove_product',
|
|
21
|
-
'list_films', 'create_film', 'get_film', 'update_film_settings', 'add_track', 'move_track', 'detect_tempo',
|
|
22
|
-
'add_clip', 'import_clip', 'update_clip', 'move_clip', 'trim_clip', 'remove_clip', 'apply_film_plan', 'set_fades', 'add_marker',
|
|
23
|
-
'set_export_range', 'render_clips', 'wait_for_renders', 'list_takes', 'use_take', 'export_film', 'list_locations', 'create_location',
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
// The tools that need the Video Studio. Always listed: without the studio each call answers
|
|
27
|
-
// studio_not_installed, which tells an agent why, where a hidden tool tells it nothing.
|
|
28
|
-
export const STUDIO_TOOL_NAMES = TOOL_NAMES.slice(TOOL_NAMES.indexOf('list_films'));
|
|
29
|
-
|
|
30
|
-
const ok = (data) => ({ content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] });
|
|
31
|
-
const fail = (err) => ({ isError: true, content: [{ type: 'text', text: `${err.errorCode ? err.errorCode + ': ' : ''}${err.message || String(err)}` }] });
|
|
32
|
-
const wrap = (fn) => async (args) => { try { return ok(await fn(args)); } catch (e) { return fail(e); } };
|
|
33
|
-
|
|
34
|
-
// In the in-app Assistant the user approves spending and deletions on a card first.
|
|
35
|
-
const APPROVAL_NOTE = ' If the result is awaiting_approval, call wait_for_approval with its proposalId and tell the user an approval card is waiting.';
|
|
36
|
-
|
|
37
|
-
// generate_character_video chains two gated steps; when one waits for the user it stops
|
|
38
|
-
// and tells the agent how to carry on.
|
|
39
|
-
const RESUME_ANIMATE = {
|
|
40
|
-
tool: 'animate_character',
|
|
41
|
-
note: 'The chain stopped at an approval. After wait_for_approval reports done, wait_for_result on the frame job, then call animate_character with that jobId.',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const RESUME_CREATE = { tool: 'get_character', note: 'The base portrait is generated after approval. wait_for_approval returns the new characterId; then poll get_character (or wait_for_result on the base job id, if the create response carries one) until base_image_url is set.' };
|
|
45
|
-
const RESUME_REGEN = { tool: 'wait_for_result', note: 'After approval, wait_for_approval returns the base jobId; call wait_for_result on it, then accept_character_base.' };
|
|
46
|
-
|
|
47
|
-
const NO_PROMPT_GUIDES = 'This SimpliGen version has no prompt guides yet. Update the app, or write the prompt without a guide.';
|
|
48
|
-
|
|
49
|
-
export function registerTools(server, client, { now = Date.now, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
50
|
-
|
|
51
|
-
server.registerTool('list_capabilities',
|
|
52
|
-
{ title: 'List capabilities', description: 'List every SimpliGen preset the agent can generate with (image/video), its inputs/options, whether it is installed locally (localReady) and cloud-eligible + credit cost. Local presets also carry onThisMachine: how likely a run is to finish on this machine (rating, finish %, p90Min: the slow end in minutes on similar cards), the typical minutes on this exact GPU (or notEnoughRunsOnGpu when there is too little data), and what size still fits.', inputSchema: {} },
|
|
53
|
-
wrap(() => client.getCapabilities()));
|
|
54
|
-
|
|
55
|
-
server.registerTool('get_status',
|
|
56
|
-
{ title: 'Get status', description: 'Engine running state, whether cloud is connected, credit balance, and the active project.', inputSchema: {} },
|
|
57
|
-
wrap(() => client.getStatus()));
|
|
58
|
-
|
|
59
|
-
// The engine's lifecycle. get_status could always report it was down and
|
|
60
|
-
// there was nothing an agent could do about it but ask the human to click
|
|
61
|
-
// Start (user report, 2026-09-24). Install, update and repair stay out of
|
|
62
|
-
// reach on purpose: those are multi-GB downloads that belong in front of a
|
|
63
|
-
// person.
|
|
64
|
-
server.registerTool('start_engine',
|
|
65
|
-
{ title: 'Start engine', description: 'Start the local engine if it is not already running. Returns the engine state; a cold boot can outlast the call, in which case engineStarting is true and get_status tells you when it is up. Does nothing if the engine is already running, and will not install one that is missing.', inputSchema: {} },
|
|
66
|
-
wrap(() => client.startEngine()));
|
|
67
|
-
|
|
68
|
-
server.registerTool('stop_engine',
|
|
69
|
-
{ title: 'Stop engine', description: 'Stop the local engine. Frees its VRAM; cloud generation is unaffected.', inputSchema: {} },
|
|
70
|
-
wrap(() => client.stopEngine()));
|
|
71
|
-
|
|
72
|
-
server.registerTool('restart_engine',
|
|
73
|
-
{ title: 'Restart engine', description: 'Restart the local engine. Use it after installing or removing a custom node, or when the engine is wedged.', inputSchema: {} },
|
|
74
|
-
wrap(() => client.restartEngine()));
|
|
75
|
-
|
|
76
|
-
server.registerTool('list_projects',
|
|
77
|
-
{ title: 'List projects', description: 'List projects (output containers).', inputSchema: {} },
|
|
78
|
-
wrap(() => client.listProjects()));
|
|
79
|
-
|
|
80
|
-
server.registerTool('create_project',
|
|
81
|
-
{ title: 'Create project', description: 'Create a new project (output container).', inputSchema: { name: z.string().describe('Project name') } },
|
|
82
|
-
wrap(({ name }) => client.createProject(name)));
|
|
83
|
-
|
|
84
|
-
server.registerTool('upload_file',
|
|
85
|
-
{ title: 'Upload a file', description: 'Upload a local image/video file and get an opaque handle to pass as image/referenceImages/video in generate.', inputSchema: { path: z.string().describe('Absolute local file path') } },
|
|
86
|
-
wrap(({ path }) => client.uploadFile(path)));
|
|
87
|
-
|
|
88
|
-
server.registerTool('generate',
|
|
89
|
-
{
|
|
90
|
-
title: 'Generate', description: 'Start an image or video generation. Before writing the prompt, call get_prompt_guide for the preset and follow it. Inputs (image/referenceImages/video) are handles from upload_file. backend: local | cloud | auto. Returns a jobId (and, for local runs, an expectation with the same fields as onThisMachine for the requested settings); poll with wait_for_result or get_job.' + APPROVAL_NOTE,
|
|
91
|
-
inputSchema: {
|
|
92
|
-
presetId: z.string(), mediaType: z.enum(['image', 'video']), prompt: z.string(),
|
|
93
|
-
packId: z.string().optional(), backend: z.enum(['local', 'cloud', 'auto']).optional(),
|
|
94
|
-
negativePrompt: z.string().optional().describe('Extra terms added to the preset default negative prompt (local runs only); the default is always applied.'),
|
|
95
|
-
project: z.string().optional(),
|
|
96
|
-
image: z.string().optional().describe('upload_file handle'),
|
|
97
|
-
// A bare handle still works, so every agent written against the old
|
|
98
|
-
// schema keeps working. The object form carries the per-image label,
|
|
99
|
-
// which is the DESCRIPTION the app asks for when list_capabilities says
|
|
100
|
-
// inputs.referenceImages.requiresDescriptions is true (LTX 2.5
|
|
101
|
-
// Multi-Reference builds one appearance line per subject from it).
|
|
102
|
-
// Sending images without it on such a preset runs, but the subjects
|
|
103
|
-
// blur together, which is indistinguishable from the model being bad.
|
|
104
|
-
referenceImages: z.array(z.union([
|
|
105
|
-
z.string(),
|
|
106
|
-
z.object({
|
|
107
|
-
handle: z.string().describe('upload_file handle'),
|
|
108
|
-
label: z.string().optional().describe('What this reference IS, e.g. "a woman with red hair". Required in spirit when the preset reports requiresDescriptions.'),
|
|
109
|
-
}),
|
|
110
|
-
])).optional().describe('upload_file handles, or {handle, label} when the preset wants a description per reference'),
|
|
111
|
-
video: z.string().optional().describe('upload_file handle (driving video)'),
|
|
112
|
-
// The App has accepted these three since 1.58.0; this schema never
|
|
113
|
-
// offered them, so no agent could drive an audio preset at all: the
|
|
114
|
-
// error said needs_audio and there was nowhere to put a sound
|
|
115
|
-
// (mavr1k_, 2026-10-01). Passing it inside `options` does not work
|
|
116
|
-
// either, since preflight reads the top level.
|
|
117
|
-
audio: z.string().optional().describe('upload_file handle for the PRIMARY audio track (lip-sync / audio-to-video presets). Required when list_capabilities reports inputs.acceptsAudio true, optional when it reports "optional".'),
|
|
118
|
-
referenceAudios: z.array(z.union([
|
|
119
|
-
z.string(),
|
|
120
|
-
z.object({ handle: z.string(), durationSeconds: z.number().optional() }),
|
|
121
|
-
])).optional().describe('upload_file handles for reference SOUNDS (a voice per subject, where the preset pairs them with references).'),
|
|
122
|
-
referenceVideos: z.array(z.union([
|
|
123
|
-
z.string(),
|
|
124
|
-
z.object({
|
|
125
|
-
handle: z.string(),
|
|
126
|
-
soundtrackMode: z.enum(['own', 'file', 'none']).optional().describe("Where this clip's sound comes from: 'own' (the clip's own audio, the default), 'file' (another upload, see soundtrack), or 'none' (silent)."),
|
|
127
|
-
soundtrack: z.string().optional().describe("upload_file handle for the audio to use. Required with soundtrackMode 'file', ignored otherwise."),
|
|
128
|
-
durationSeconds: z.number().optional(),
|
|
129
|
-
}),
|
|
130
|
-
])).optional().describe('upload_file handles for reference CLIPS (MiniMax H3 scene chaining chains on a clip).'),
|
|
131
|
-
// Appended to the prompt by the app's own dialogue formatter, so the
|
|
132
|
-
// wording matches what the preset was tuned on. MiniMax H3 lip-syncs
|
|
133
|
-
// to it; sending it to a preset that does not declare supportsDialogue
|
|
134
|
-
// changes nothing.
|
|
135
|
-
dialogue: z.string().optional().describe('A spoken line for the character, when list_capabilities reports inputs.supportsDialogue.'),
|
|
136
|
-
dialogueDelivery: z.string().optional().describe('How the line is delivered, e.g. "urgent", "whispered". Only meaningful with dialogue.'),
|
|
137
|
-
loras: z.array(z.object({ name: z.string().describe('LoRA display name from list_loras'), weight: z.number().optional().describe('Strength; defaults to the LoRA default') })).optional().describe('LoRAs to apply. Local backend only, and only for presets where inputs.supportsLoras is true. Use the LoRA trigger words in the prompt so it activates.'),
|
|
138
|
-
// .passthrough(), not the zod default: a plain z.object STRIPS every key it
|
|
139
|
-
// does not name, silently. The App's /generate accepts any Advanced
|
|
140
|
-
// Control the preset declares (unlock, shift, high_steps, ...) and
|
|
141
|
-
// list_capabilities advertises them under options.controls, so an agent
|
|
142
|
-
// was told a control exists, sent it, and got the preset default back
|
|
143
|
-
// with no error: unlock: 1 arrived at the graph as 0.5 (Melvyl, 1.63.0).
|
|
144
|
-
// The App applies only what the preset declares and ignores the rest,
|
|
145
|
-
// so forwarding everything is safe. Known fields stay named so the
|
|
146
|
-
// agent still sees them in the tool's schema.
|
|
147
|
-
options: z.object({
|
|
148
|
-
resolution: z.string().optional().describe('Resolution tier label; see list_capabilities -> options.resolution.'),
|
|
149
|
-
aspectRatio: z.string().optional().describe('Aspect ratio, e.g. "1:1", "16:9", "9:16" (portrait/vertical), "4:3", "3:4". See list_capabilities -> options.aspectRatio for the values each preset accepts. Defaults to 1:1 for images (16:9 for video) if omitted.'),
|
|
150
|
-
durationSeconds: z.number().optional(),
|
|
151
|
-
steps: z.number().optional(),
|
|
152
|
-
cfg: z.number().optional(),
|
|
153
|
-
seed: z.number().optional(),
|
|
154
|
-
negativePrompt: z.string().optional(),
|
|
155
|
-
fasterAttention: z.boolean().optional().describe('Accelerator toggle; absent = preset default.'),
|
|
156
|
-
solAttn: z.boolean().optional().describe('Accelerator toggle; absent = preset default.'),
|
|
157
|
-
spectrum: z.boolean().optional().describe('Accelerator toggle; absent = preset default.'),
|
|
158
|
-
}).passthrough().optional().describe('Run options. Besides the named fields, pass ANY Advanced Control the preset declares under list_capabilities -> options.controls (for example unlock, shift, high_steps) as a top-level key of this object, using the value range that map gives. A key the preset does not declare is ignored.'),
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
wrap((args) => client.generate(args)));
|
|
162
|
-
|
|
163
|
-
server.registerTool('list_loras',
|
|
164
|
-
{ title: 'List LoRAs', description: 'List the installed user LoRAs (name, base model, trigger words) so you can pass them in generate -> loras.', inputSchema: {} },
|
|
165
|
-
wrap(() => client.listLoras()));
|
|
166
|
-
|
|
167
|
-
server.registerTool('get_prompt_guide',
|
|
168
|
-
{
|
|
169
|
-
title: 'Get prompt guide',
|
|
170
|
-
description: 'Read the prompting guide for a preset before writing its prompt: how its model reads a prompt, structure, length, camera and motion wording, negatives, character wording and examples. Follow it when you write the prompt for generate.',
|
|
171
|
-
inputSchema: { presetId: z.string() },
|
|
172
|
-
},
|
|
173
|
-
async ({ presetId }) => {
|
|
174
|
-
try {
|
|
175
|
-
return ok(await client.getPromptGuide(presetId));
|
|
176
|
-
} catch (e) {
|
|
177
|
-
// Any other 404 means the app predates the route.
|
|
178
|
-
if (e && e.status === 404 && e.errorCode !== 'unknown_preset') {
|
|
179
|
-
return { isError: true, content: [{ type: 'text', text: NO_PROMPT_GUIDES }] };
|
|
180
|
-
}
|
|
181
|
-
return fail(e);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
server.registerTool('get_job',
|
|
186
|
-
{ title: 'Get job', description: 'Status + result of a generation job. resultPath is the local file when completed.', inputSchema: { jobId: z.string() } },
|
|
187
|
-
wrap(({ jobId }) => client.getJob(jobId)));
|
|
188
|
-
|
|
189
|
-
server.registerTool('list_jobs',
|
|
190
|
-
{ title: 'List jobs', description: 'Recent generation jobs.', inputSchema: {} },
|
|
191
|
-
wrap(() => client.listJobs()));
|
|
192
|
-
|
|
193
|
-
server.registerTool('cancel_job',
|
|
194
|
-
{ title: 'Cancel job', description: 'Cancel a queued/running job.', inputSchema: { jobId: z.string() } },
|
|
195
|
-
wrap(({ jobId }) => client.cancelJob(jobId)));
|
|
196
|
-
|
|
197
|
-
server.registerTool('prepare_preset',
|
|
198
|
-
{ title: 'Prepare preset', description: 'Start downloading a local preset\'s models (so it becomes localReady). Poll list_capabilities for localReady.', inputSchema: { presetId: z.string(), mediaType: z.enum(['image', 'video']), packId: z.string().optional() } },
|
|
199
|
-
wrap((args) => client.preparePreset(args)));
|
|
200
|
-
|
|
201
|
-
// Convenience: poll get_job until terminal or timeout (no extra endpoint).
|
|
202
|
-
server.registerTool('wait_for_result',
|
|
203
|
-
{ title: 'Wait for result', description: 'Block until a job completes or fails (or the timeout). Returns the final job (resultPath when completed).', inputSchema: { jobId: z.string(), timeoutSeconds: z.number().optional(), pollMs: z.number().optional() } },
|
|
204
|
-
wrap(async ({ jobId, timeoutSeconds = 300, pollMs = 2000 }) => {
|
|
205
|
-
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
206
|
-
// eslint-disable-next-line no-constant-condition
|
|
207
|
-
while (true) {
|
|
208
|
-
const { job } = await client.getJob(jobId);
|
|
209
|
-
if (!job || job.status === 'completed' || job.status === 'failed') return job;
|
|
210
|
-
if (Date.now() >= deadline) return { ...job, note: 'timeout_still_running' };
|
|
211
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
212
|
-
}
|
|
213
|
-
}));
|
|
214
|
-
|
|
215
|
-
// Return a completed job's result image inline (an MCP image block) so the
|
|
216
|
-
// agent can actually display it. Images only; video/unreadable -> path note.
|
|
217
|
-
server.registerTool('get_result_image',
|
|
218
|
-
{ title: 'Get result image', description: 'Return a completed job\'s result image inline as a viewable image so it can be displayed in chat. Large images are re-encoded to a full-resolution WebP preview that fits the client size cap; the uncompressed original file path is always included in the caption. Video results return the file path instead. Call after the job is completed.', inputSchema: { jobId: z.string(), maxBytes: z.number().optional().describe('Inline byte budget before re-encoding/resizing (default ~700KB raw)') } },
|
|
219
|
-
async ({ jobId, maxBytes }) => {
|
|
220
|
-
try {
|
|
221
|
-
const { job } = await client.getJob(jobId);
|
|
222
|
-
return await buildResultImageContent(job, { budgetBytes: maxBytes });
|
|
223
|
-
} catch (e) {
|
|
224
|
-
return fail(e);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// The user's Approve click on an approval card can take minutes: poll in rounds the
|
|
229
|
-
// control API can hold open (25 s max), until the proposal settles or the timeout passes.
|
|
230
|
-
server.registerTool('wait_for_approval',
|
|
231
|
-
{ title: 'Wait for approval', description: 'Block until the user approves or declines an approval card (proposalId from an awaiting_approval result), or the timeout passes. Returns { status: done | declined | expired, ... }: done carries the result of the approved call (for example the jobId), declined carries a reason. On timeout returns { status: pending, note: still_waiting }: call it again.', inputSchema: { proposalId: z.string(), timeoutSeconds: z.number().optional().describe('Total seconds to wait (default 600)') } },
|
|
232
|
-
wrap(async ({ proposalId, timeoutSeconds = 600 }) => {
|
|
233
|
-
const deadline = now() + timeoutSeconds * 1000;
|
|
234
|
-
for (;;) {
|
|
235
|
-
const remaining = Math.ceil((deadline - now()) / 1000);
|
|
236
|
-
if (remaining <= 0) return { status: 'pending', note: 'still_waiting', proposalId };
|
|
237
|
-
const started = now();
|
|
238
|
-
const r = await client.waitForApproval(proposalId, Math.min(25, remaining));
|
|
239
|
-
if (r.status === 'done') {
|
|
240
|
-
const httpStatus = r.result?.status;
|
|
241
|
-
return { status: 'done', ok: httpStatus >= 200 && httpStatus < 300, result: r.result?.json, httpStatus };
|
|
242
|
-
}
|
|
243
|
-
if (r.status !== 'pending' && r.status !== 'running') return r;
|
|
244
|
-
// A server that answers at once instead of holding the call must not be hammered.
|
|
245
|
-
const spent = now() - started;
|
|
246
|
-
if (spent < 1000) await sleep(1000 - spent);
|
|
247
|
-
}
|
|
248
|
-
}));
|
|
249
|
-
|
|
250
|
-
// ---- The app's own screen: what the user sees, and moving it for them ----
|
|
251
|
-
|
|
252
|
-
server.registerTool('get_app_context',
|
|
253
|
-
{ title: 'Get app context', description: 'What the user is looking at in SimpliGen right now: the open screen, the selected preset, character or film, and the current Generate form values.', inputSchema: {} },
|
|
254
|
-
wrap(() => client.getAppContext()));
|
|
255
|
-
|
|
256
|
-
server.registerTool('fill_generate_form',
|
|
257
|
-
{ title: 'Fill the Generate form', description: 'Fill in the Generate screen for the user (preset, prompt and settings) without generating, so they can review it and click Generate themselves.', inputSchema: {
|
|
258
|
-
presetId: z.string(), prompt: z.string(), negativePrompt: z.string().optional(), characterId: z.string().optional(),
|
|
259
|
-
settings: z.record(z.any()).optional().describe('Preset settings keyed by setting id (see list_capabilities).'),
|
|
260
|
-
} },
|
|
261
|
-
wrap((a) => client.fillGenerateForm(a)));
|
|
262
|
-
|
|
263
|
-
server.registerTool('open_screen',
|
|
264
|
-
{ title: 'Open a screen', description: 'Take the user to a screen in SimpliGen. id selects a character when screen is "character".', inputSchema: {
|
|
265
|
-
screen: z.enum(['generate', 'gallery', 'characters', 'character', 'video-studio', 'prompt-library', 'settings']),
|
|
266
|
-
id: z.string().optional(),
|
|
267
|
-
} },
|
|
268
|
-
wrap((a) => client.openScreen(a)));
|
|
269
|
-
|
|
270
|
-
// ---- Character Studio tools ----
|
|
271
|
-
|
|
272
|
-
server.registerTool('list_characters',
|
|
273
|
-
{ title: 'List characters', description: 'List all saved characters in Character Studio.', inputSchema: {} },
|
|
274
|
-
wrap(() => client.listCharacters()));
|
|
275
|
-
|
|
276
|
-
server.registerTool('get_character',
|
|
277
|
-
{ title: 'Get character', description: 'Get a single character by ID, including its current base portrait and identity features.', inputSchema: { characterId: z.string() } },
|
|
278
|
-
wrap(({ characterId }) => client.getCharacter(characterId)));
|
|
279
|
-
|
|
280
|
-
server.registerTool('list_character_features',
|
|
281
|
-
{ title: 'List character features', description: 'List available feature categories and their options (e.g. hairColor, eyeColor) for use with create_character identity.', inputSchema: {} },
|
|
282
|
-
wrap(() => client.listCharacterFeatures()));
|
|
283
|
-
|
|
284
|
-
server.registerTool('list_character_presets',
|
|
285
|
-
{ title: 'List character presets', description: 'List generation presets available for Character Studio. Returns base, identityEdit, and i2v presets as well as enhanceImage and enhanceVideo presets (each with supportedScales). Use the returned ids as presetId/imagePresetId/videoPresetId/basePresetId arguments in other character tools.', inputSchema: {} },
|
|
286
|
-
wrap(() => client.listCharacterPresets()));
|
|
287
|
-
|
|
288
|
-
server.registerTool('remove_character',
|
|
289
|
-
{ title: 'Remove character', description: 'Permanently delete a character and its associated data.' + APPROVAL_NOTE, inputSchema: { characterId: z.string() } },
|
|
290
|
-
wrap(({ characterId }) => client.removeCharacter(characterId)));
|
|
291
|
-
|
|
292
|
-
server.registerTool('create_character',
|
|
293
|
-
{
|
|
294
|
-
title: 'Create character',
|
|
295
|
-
description: 'Create a new character. Three paths: (1) describe -- pass gender and identity features from list_character_features with mode "generate"; the server builds a base portrait automatically and this tool waits until ready. (2) upload as base -- pass baseFilePath pointing to a local image with mode "upload"; the image becomes the base portrait immediately. (3) vision recreate -- describe path but fill identity by having the agent analyse a reference photo first; the agent extracts features and passes them as identity.' + APPROVAL_NOTE,
|
|
296
|
-
inputSchema: {
|
|
297
|
-
name: z.string().describe('Display name for the character'),
|
|
298
|
-
gender: z.enum(['woman', 'man', 'nonbinary']),
|
|
299
|
-
mode: z.enum(['generate', 'upload']).describe('generate: build base portrait from description; upload: use a provided image as base'),
|
|
300
|
-
identity: z.record(z.string()).optional().describe('An object of featureId to optionId pairs chosen from list_character_features (e.g. { hairColor: "black", eyeColor: "green" }). Do not include gender here; pass gender separately.'),
|
|
301
|
-
baseFilePath: z.string().optional().describe('Absolute local image path; required for mode "upload"'),
|
|
302
|
-
timeoutSeconds: z.number().optional().describe('Max seconds to wait for base portrait generation (default 300, mode generate only)'),
|
|
303
|
-
pollMs: z.number().optional().describe('Poll interval in milliseconds (default 2000, mode generate only)'),
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
async ({ name, gender, mode, identity, baseFilePath, timeoutSeconds, pollMs }) => {
|
|
307
|
-
try {
|
|
308
|
-
if (mode === 'upload') {
|
|
309
|
-
const up = await client.uploadFile(baseFilePath);
|
|
310
|
-
const char = await client.createCharacter({ name, gender, mode: 'upload', identity, baseHandle: up.handle });
|
|
311
|
-
if (char?.status === 'awaiting_approval') return ok({ ...char, resume: RESUME_CREATE });
|
|
312
|
-
return ok({ ...char, ready: true });
|
|
313
|
-
}
|
|
314
|
-
// mode === 'generate': create then poll until base_image_url is set
|
|
315
|
-
const c = await client.createCharacter({ name, gender, mode: 'generate', identity });
|
|
316
|
-
if (c?.status === 'awaiting_approval') return ok({ ...c, resume: RESUME_CREATE });
|
|
317
|
-
const { characterId } = c;
|
|
318
|
-
const deadline = Date.now() + (timeoutSeconds ?? 300) * 1000;
|
|
319
|
-
while (true) {
|
|
320
|
-
const { character } = await client.getCharacter(characterId);
|
|
321
|
-
if (character?.base_image_url) return ok(character);
|
|
322
|
-
if (Date.now() >= deadline) return ok({ ...character, base_pending: true });
|
|
323
|
-
await new Promise((r) => setTimeout(r, pollMs ?? 2000));
|
|
324
|
-
}
|
|
325
|
-
} catch (e) {
|
|
326
|
-
return fail(e);
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
server.registerTool('generate_character_image',
|
|
331
|
-
{
|
|
332
|
-
title: 'Generate character image',
|
|
333
|
-
description: 'Generate one or more images of a character in a scene. Returns jobIds; use wait_for_result then get_result_image for each. Pass presetId to override the default image preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
334
|
-
inputSchema: {
|
|
335
|
-
characterId: z.string(),
|
|
336
|
-
prompt: z.string(),
|
|
337
|
-
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
338
|
-
count: z.number().optional(),
|
|
339
|
-
presetId: z.string().optional().describe('Override image preset (id from list_character_presets)'),
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
wrap(({ characterId, prompt, aspect, count, presetId }) => {
|
|
343
|
-
const args = { prompt, aspect, count };
|
|
344
|
-
if (presetId !== undefined) args.presetId = presetId;
|
|
345
|
-
return client.generateCharacterImage(characterId, args);
|
|
346
|
-
}));
|
|
347
|
-
|
|
348
|
-
server.registerTool('generate_character_video',
|
|
349
|
-
{
|
|
350
|
-
title: 'Generate character video',
|
|
351
|
-
description: 'Generate a short video of a character in a scene. Internally generates a frame then animates it (I2V). Returns frameJobId and videoJobId; use wait_for_result then get_result_image on videoJobId. Use framePresetId to override the image-frame preset and videoPresetId to override the video/animate preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
352
|
-
inputSchema: {
|
|
353
|
-
characterId: z.string(),
|
|
354
|
-
prompt: z.string(),
|
|
355
|
-
motion: z.string().optional().describe('Optional motion description or style hint'),
|
|
356
|
-
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
357
|
-
timeoutSeconds: z.number().optional().describe('Max seconds to wait for the frame job (default 300)'),
|
|
358
|
-
pollMs: z.number().optional().describe('Poll interval in milliseconds (default 2000)'),
|
|
359
|
-
framePresetId: z.string().optional().describe('Override image-frame preset (id from list_character_presets)'),
|
|
360
|
-
videoPresetId: z.string().optional().describe('Override video/animate preset (id from list_character_presets)'),
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
async ({ characterId, prompt, motion, aspect, timeoutSeconds = 300, pollMs = 2000, framePresetId, videoPresetId }) => {
|
|
364
|
-
try {
|
|
365
|
-
// 1. Generate a frame (still image for I2V)
|
|
366
|
-
const frame = await client.generateCharacterFrame(characterId, { prompt, aspect, presetId: framePresetId });
|
|
367
|
-
if (frame?.status === 'awaiting_approval') return ok({ ...frame, resume: RESUME_ANIMATE });
|
|
368
|
-
const { jobIds: [frameJobId] } = frame;
|
|
369
|
-
// 2. Wait for frame to complete
|
|
370
|
-
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
371
|
-
while (true) {
|
|
372
|
-
const { job: frameJob } = await client.getJob(frameJobId);
|
|
373
|
-
if (frameJob?.status === 'completed') break;
|
|
374
|
-
if (frameJob?.status === 'failed') return fail({ message: `Frame job failed: ${frameJobId}`, errorCode: 'frame_failed' });
|
|
375
|
-
if (Date.now() >= deadline) return fail({ message: `Frame job timed out: ${frameJobId}`, errorCode: 'frame_timeout' });
|
|
376
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
377
|
-
}
|
|
378
|
-
// 3. Animate from the completed frame
|
|
379
|
-
const video = await client.animateCharacter(characterId, { frameJobId, motion, aspect, presetId: videoPresetId });
|
|
380
|
-
if (video?.status === 'awaiting_approval') return ok({ ...video, resume: RESUME_ANIMATE });
|
|
381
|
-
const { jobIds: [videoJobId] } = video;
|
|
382
|
-
return ok({ frameJobId, videoJobId });
|
|
383
|
-
} catch (e) { return fail(e); }
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
// ---- New Character Studio tools (Task 4) ----
|
|
387
|
-
|
|
388
|
-
server.registerTool('generate_character_frame',
|
|
389
|
-
{
|
|
390
|
-
title: 'Generate character frame',
|
|
391
|
-
description: 'Generate a start-frame image for a character that you can review or enhance before animating. Returns jobIds; use wait_for_result then get_result_image. Pass presetId to override the frame-image preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
392
|
-
inputSchema: {
|
|
393
|
-
characterId: z.string(),
|
|
394
|
-
prompt: z.string(),
|
|
395
|
-
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
396
|
-
presetId: z.string().optional().describe('Override image preset (id from list_character_presets)'),
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
wrap(({ characterId, prompt, aspect, presetId }) => {
|
|
400
|
-
const args = { prompt, aspect };
|
|
401
|
-
if (presetId !== undefined) args.presetId = presetId;
|
|
402
|
-
return client.generateCharacterFrame(characterId, args);
|
|
403
|
-
}));
|
|
404
|
-
|
|
405
|
-
server.registerTool('animate_character',
|
|
406
|
-
{
|
|
407
|
-
title: 'Animate character',
|
|
408
|
-
description: 'Animate a character from a completed image/frame job or a local file path (I2V). jobId may be any completed character image, frame, or upscale job. Returns jobIds; use wait_for_result then get_result_image. Pass videoPresetId to override the video preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
409
|
-
inputSchema: {
|
|
410
|
-
characterId: z.string(),
|
|
411
|
-
jobId: z.string().optional().describe('Any completed character image/frame/upscale jobId to use as the source frame'),
|
|
412
|
-
filePath: z.string().optional().describe('Absolute local image path to use as the source frame'),
|
|
413
|
-
motion: z.string().optional().describe('Optional motion description or style hint'),
|
|
414
|
-
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
415
|
-
videoPresetId: z.string().optional().describe('Override video/animate preset (id from list_character_presets)'),
|
|
416
|
-
},
|
|
417
|
-
},
|
|
418
|
-
wrap(({ characterId, jobId, filePath, motion, aspect, videoPresetId }) =>
|
|
419
|
-
client.animateCharacter(characterId, { frameJobId: jobId, framePath: filePath, motion, aspect, presetId: videoPresetId })));
|
|
420
|
-
|
|
421
|
-
server.registerTool('set_character_preset',
|
|
422
|
-
{
|
|
423
|
-
title: 'Set character preset',
|
|
424
|
-
description: 'Set sticky per-character default presets for image and/or video generation. Ids come from list_character_presets. Pass null to clear a preset back to the system default.',
|
|
425
|
-
inputSchema: {
|
|
426
|
-
characterId: z.string(),
|
|
427
|
-
imagePresetId: z.string().nullable().optional().describe('Default image preset id (null to clear)'),
|
|
428
|
-
videoPresetId: z.string().nullable().optional().describe('Default video preset id (null to clear)'),
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
wrap(({ characterId, imagePresetId, videoPresetId }) => client.setCharacterPreset(characterId, { imagePresetId, videoPresetId })));
|
|
432
|
-
|
|
433
|
-
server.registerTool('enhance_character_media',
|
|
434
|
-
{
|
|
435
|
-
title: 'Enhance character media',
|
|
436
|
-
description: 'Upscale a generated image/video, a local file, or the character base portrait (target: "base"). Returns a jobId; use wait_for_result then get_result_image. scale sets the upscale factor; keepResolution upscales then resizes back to source size for a sharper same-size result; applyAsBase replaces the character base portrait with the upscaled result. Enhance presets come from list_character_presets (enhanceImage/enhanceVideo, each with supportedScales).' + APPROVAL_NOTE,
|
|
437
|
-
inputSchema: {
|
|
438
|
-
characterId: z.string(),
|
|
439
|
-
jobId: z.string().optional().describe('Completed job whose result to enhance'),
|
|
440
|
-
filePath: z.string().optional().describe('Absolute local image/video path to enhance'),
|
|
441
|
-
target: z.enum(['base']).optional().describe('Pass "base" to enhance the character base portrait'),
|
|
442
|
-
mediaType: z.enum(['image', 'video']).optional(),
|
|
443
|
-
presetId: z.string().optional().describe('Enhance preset id from list_character_presets'),
|
|
444
|
-
scale: z.number().optional().describe('Upscale factor (e.g. 2 for 2x)'),
|
|
445
|
-
keepResolution: z.boolean().optional().describe('Upscale then resize back to source dimensions for a sharper same-size result'),
|
|
446
|
-
applyAsBase: z.boolean().optional().describe('Replace the character base portrait with the upscaled result'),
|
|
447
|
-
},
|
|
448
|
-
},
|
|
449
|
-
wrap(({ characterId, jobId, filePath, target, mediaType, presetId, scale, keepResolution, applyAsBase }) =>
|
|
450
|
-
client.enhanceCharacterMedia(characterId, { jobId, filePath, target, mediaType, presetId, scale, keepResolution, applyAsBase })));
|
|
451
|
-
|
|
452
|
-
server.registerTool('regenerate_character_base',
|
|
453
|
-
{
|
|
454
|
-
title: 'Regenerate character base',
|
|
455
|
-
description: 'Switch the base model and regenerate the base portrait IN PLACE (no new character created). Replaces the current base when completed. Uses basePresetId from list_character_presets. Optionally update identity features at the same time. Polls until completed, then auto-accepts the new base.' + APPROVAL_NOTE,
|
|
456
|
-
inputSchema: {
|
|
457
|
-
characterId: z.string(),
|
|
458
|
-
basePresetId: z.string().optional().describe('Base-generation preset id from list_character_presets'),
|
|
459
|
-
identity: z.record(z.string()).optional().describe('Updated identity feature map (featureId -> optionId) to apply alongside the new base'),
|
|
460
|
-
timeoutSeconds: z.number().optional().describe('Max seconds to wait for the base job (default 300)'),
|
|
461
|
-
pollMs: z.number().optional().describe('Poll interval in milliseconds (default 2000)'),
|
|
462
|
-
},
|
|
463
|
-
},
|
|
464
|
-
async ({ characterId, basePresetId, identity, timeoutSeconds = 300, pollMs = 2000 }) => {
|
|
465
|
-
try {
|
|
466
|
-
const regen = await client.regenerateCharacterBase(characterId, { basePresetId, identity });
|
|
467
|
-
if (regen?.status === 'awaiting_approval') return ok({ ...regen, resume: RESUME_REGEN });
|
|
468
|
-
const { baseJobId } = regen;
|
|
469
|
-
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
470
|
-
while (true) {
|
|
471
|
-
const { job } = await client.getJob(baseJobId);
|
|
472
|
-
if (job?.status === 'completed') {
|
|
473
|
-
await client.acceptBase(characterId, { altImageId: baseJobId });
|
|
474
|
-
return ok(await client.getCharacter(characterId));
|
|
475
|
-
}
|
|
476
|
-
if (job?.status === 'failed') return fail({ message: `Base regeneration job failed: ${baseJobId}`, errorCode: 'base_failed' });
|
|
477
|
-
if (Date.now() >= deadline) return ok({ baseJobId, note: 'timeout_still_running' });
|
|
478
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
479
|
-
}
|
|
480
|
-
} catch (e) { return fail(e); }
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
server.registerTool('accept_character_base',
|
|
484
|
-
{
|
|
485
|
-
title: 'Accept character base',
|
|
486
|
-
description: 'Make a finished base-portrait job the base of the character. Use it after an approved regenerate_character_base job finishes (wait_for_result completed).',
|
|
487
|
-
inputSchema: { characterId: z.string(), jobId: z.string().describe('The completed base job id') },
|
|
488
|
-
},
|
|
489
|
-
wrap(({ characterId, jobId }) => client.acceptBase(characterId, { altImageId: jobId })));
|
|
490
|
-
|
|
491
|
-
// --- Recipe authoring: compose multi-step recipes out of packs/presets ---
|
|
492
|
-
|
|
493
|
-
const recipeStep = z.object({
|
|
494
|
-
preset: z.string().describe('The preset this step runs, as "packId:presetId" (from list_recipe_blocks).'),
|
|
495
|
-
entry: z.string().optional().describe('Entry point: create-image | create-video | edit-image | upscale. Inferred from the preset when omitted.'),
|
|
496
|
-
promptInput: z.object({ key: z.string().optional(), label: z.string().optional() }).optional()
|
|
497
|
-
.describe('Name this step\'s prompt input, or set key to an existing input to SHARE a prompt. Default: a dedicated prompt input per step.'),
|
|
498
|
-
negativePrompt: z.string().optional(),
|
|
499
|
-
params: z.record(z.any()).optional().describe('Param bindings, literal or { from: "input:<key>" } (e.g. aspectRatio, seed, duration).'),
|
|
500
|
-
}).passthrough();
|
|
501
|
-
|
|
502
|
-
const recipeInput = z.object({
|
|
503
|
-
key: z.string().describe('Unique slug referenced as input:<key>.'),
|
|
504
|
-
kind: z.string().describe('subject | text | image | video | reference | audio | select | color | number | toggle'),
|
|
505
|
-
label: z.string().optional(),
|
|
506
|
-
required: z.boolean().optional(),
|
|
507
|
-
}).passthrough();
|
|
508
|
-
|
|
509
|
-
const recipeSpec = z.object({
|
|
510
|
-
name: z.string().describe('Recipe name shown to end users.'),
|
|
511
|
-
description: z.string().optional(),
|
|
512
|
-
category: z.string().optional().describe('e.g. product | ugc'),
|
|
513
|
-
mature: z.boolean().optional().describe('Creator-declared: this recipe produces adult content.'),
|
|
514
|
-
// Accepted, not for the benefit of third parties (breaking them is fine), but
|
|
515
|
-
// because an agent composing a recipe mid-transition would otherwise DROP the
|
|
516
|
-
// classification, which publishes adult content as unclassified (TASK-472).
|
|
517
|
-
nsfw: z.boolean().optional().describe('Deprecated alias for `mature`.'),
|
|
518
|
-
version: z.string().optional().describe('Creator-facing semver, default 1.0.0.'),
|
|
519
|
-
inputs: z.array(recipeInput).optional().describe('Extra user-facing inputs (subjects, choices, media holes). A prompt input is auto-created per step, so you rarely list prompts here.'),
|
|
520
|
-
steps: z.array(recipeStep).min(1).describe('The pipeline in order. Each step pins a preset; media output flows into the next step automatically, and a subject input seeds a reference port.'),
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
server.registerTool('list_recipe_blocks',
|
|
524
|
-
{ title: 'List recipe blocks', description: 'The building blocks for authoring a recipe: entry points (create-image/video, edit-image, upscale) and every preset usable as a step, each with its port contract (inputs it needs, what it produces, which entry points it fits). Call this before compose_recipe to choose presets.', inputSchema: {} },
|
|
525
|
-
wrap(() => client.listRecipeBlocks()));
|
|
526
|
-
|
|
527
|
-
server.registerTool('compose_recipe',
|
|
528
|
-
{ title: 'Compose a recipe', description: 'Author a new recipe from a high-level spec and save it as a draft. You give an ordered list of steps (each pinned to a preset from list_recipe_blocks) plus any extra inputs; SimpliGen auto-wires the ports, media chain, and per-step prompt inputs and validates it. Returns { recipeId, valid, errors }. Anyone can compose; publishing later needs a connected account.', inputSchema: { spec: recipeSpec } },
|
|
529
|
-
wrap(({ spec }) => client.composeRecipe({ spec })));
|
|
530
|
-
|
|
531
|
-
server.registerTool('validate_recipe',
|
|
532
|
-
{ title: 'Validate a recipe', description: 'Dry-run without saving: pass a `spec` to compose+validate it, or a `config` to validate an existing recipe config. Returns precise errors (unbound ports, missing presets, type mismatches, cycles) to fix before compose_recipe.', inputSchema: { spec: recipeSpec.optional(), config: z.record(z.any()).optional() } },
|
|
533
|
-
wrap((args) => client.validateRecipe(args)));
|
|
534
|
-
|
|
535
|
-
server.registerTool('list_recipes',
|
|
536
|
-
{ title: 'List recipes', description: 'List every recipe on this device: the ones installed from the Store into UGC Studio / Product Studio (category ugc | product) and drafts authored here. Each entry carries its `inputs` (key, kind, label, required, options) so you know what run_recipe needs: a `subject` input takes a character id from list_characters (or a product id), image/video/audio inputs take upload_file handles, text/select/number inputs take plain values.', inputSchema: {} },
|
|
537
|
-
wrap(() => client.listRecipes()));
|
|
538
|
-
|
|
539
|
-
// --- Running an installed recipe (what drives the UGC + Product Studios) ---
|
|
540
|
-
|
|
541
|
-
server.registerTool('run_recipe',
|
|
542
|
-
{
|
|
543
|
-
title: 'Run a recipe',
|
|
544
|
-
description: 'Run an installed recipe (from list_recipes) with its inputs filled: the same multi-step pipeline UGC Studio / Product Studio runs when a person clicks Generate, so results land in the Gallery grouped the same way. `inputs` is keyed by input key; a subject input takes a character/product id, media inputs take upload_file handles. engine: local (default when every step is installed) | cloud | auto. Returns a runId; poll with wait_for_recipe_run or get_recipe_run. Cloud runs are priced up front and count against this agent\'s spend cap.' + APPROVAL_NOTE,
|
|
545
|
-
inputSchema: {
|
|
546
|
-
id: z.string().describe('Recipe id from list_recipes'),
|
|
547
|
-
inputs: z.record(z.any()).describe('Input values keyed by the recipe\'s input keys (see list_recipes -> inputs).'),
|
|
548
|
-
engine: z.enum(['local', 'cloud', 'auto']).optional().describe('Where the steps render. auto = local if every step is installed, else cloud when connected.'),
|
|
549
|
-
},
|
|
550
|
-
},
|
|
551
|
-
wrap(({ id, inputs, engine }) => client.runRecipe(id, { inputs: inputs || {}, ...(engine ? { engine } : {}) })));
|
|
552
|
-
|
|
553
|
-
server.registerTool('get_recipe_run',
|
|
554
|
-
{ title: 'Get a recipe run', description: 'Status of a recipe run: overall status (running | completed | failed | cancelled), each step with its status and resultPath, and resultPath = the final output once done.', inputSchema: { runId: z.string().describe('Run id from run_recipe') } },
|
|
555
|
-
wrap(({ runId }) => client.getRecipeRun(runId)));
|
|
556
|
-
|
|
557
|
-
server.registerTool('wait_for_recipe_run',
|
|
558
|
-
{ title: 'Wait for a recipe run', description: 'Block until a recipe run completes, fails, is cancelled, or the timeout passes. Returns the final run (resultPath when completed). Multi-step video recipes can take several minutes; call again if it returns timeout_still_running.', inputSchema: { runId: z.string(), timeoutSeconds: z.number().optional(), pollMs: z.number().optional() } },
|
|
559
|
-
wrap(async ({ runId, timeoutSeconds = 600, pollMs = 3000 }) => {
|
|
560
|
-
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
561
|
-
// eslint-disable-next-line no-constant-condition
|
|
562
|
-
while (true) {
|
|
563
|
-
const { run } = await client.getRecipeRun(runId);
|
|
564
|
-
if (run && ['completed', 'failed', 'cancelled'].includes(run.status)) return { run };
|
|
565
|
-
if (Date.now() >= deadline) return { run, note: 'timeout_still_running' };
|
|
566
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
567
|
-
}
|
|
568
|
-
}));
|
|
569
|
-
|
|
570
|
-
server.registerTool('list_recipe_runs',
|
|
571
|
-
{ title: 'List recipe runs', description: 'Recent runs of a recipe (newest first) with their status and results.', inputSchema: { id: z.string().describe('Recipe id') } },
|
|
572
|
-
wrap(({ id }) => client.listRecipeRuns(id)));
|
|
573
|
-
|
|
574
|
-
// --- Products + subjects: what a recipe's `subject` inputs take ---
|
|
575
|
-
|
|
576
|
-
server.registerTool('list_subjects',
|
|
577
|
-
{ title: 'List subjects', description: 'Every subject a recipe\'s `subject` input can take: characters and products (id, type, name). Use a character id from list_characters or a product id from list_products / create_product.', inputSchema: {} },
|
|
578
|
-
wrap(() => client.listSubjects()));
|
|
579
|
-
|
|
580
|
-
server.registerTool('list_products',
|
|
581
|
-
{ title: 'List products', description: 'The products saved on this device (a product = a named thing with a base photo, used by Product Studio and UGC recipes).', inputSchema: {} },
|
|
582
|
-
wrap(() => client.listProducts()));
|
|
583
|
-
|
|
584
|
-
server.registerTool('create_product',
|
|
585
|
-
{
|
|
586
|
-
title: 'Create a product',
|
|
587
|
-
description: 'Save a product from a photo so recipes can use it: upload the photo with upload_file first, then pass its handle. The description and category are woven into recipe prompts, so describe what it is and how it looks. Returns the productId to pass as a `subject` input in run_recipe.',
|
|
588
|
-
inputSchema: {
|
|
589
|
-
name: z.string().describe('Product name shown in the app'),
|
|
590
|
-
image: z.string().describe('upload_file handle of the product photo (clean, well-lit, product centred)'),
|
|
591
|
-
description: z.string().optional().describe('What it is and looks like, e.g. "a matte black ceramic coffee mug with a wooden lid"'),
|
|
592
|
-
category: z.string().optional().describe('e.g. skincare | beverage | electronics'),
|
|
593
|
-
},
|
|
594
|
-
},
|
|
595
|
-
wrap(({ name, image, description, category }) => client.createProduct({ name, image, description, category })));
|
|
596
|
-
|
|
597
|
-
server.registerTool('remove_product',
|
|
598
|
-
{ title: 'Remove a product', description: 'Delete a product and its photo from this device.' + APPROVAL_NOTE, inputSchema: { id: z.string() } },
|
|
599
|
-
wrap(({ id }) => client.removeProduct(id)));
|
|
600
|
-
|
|
601
|
-
// ---- The Video Studio (TASK-1310) ---------------------------------------------
|
|
602
|
-
// A film is a timeline of clips (shots to render) over audio tracks. Clips are named by
|
|
603
|
-
// id, by name, or by number (their order on the timeline, earliest first). Times are
|
|
604
|
-
// seconds, or bars once the film has a tempo: a position is { bar } (bar 1 is the
|
|
605
|
-
// first downbeat) and a length is { bars }. Every editing tool answers the film's
|
|
606
|
-
// timeline after the change; with the film open in the studio the change shows live.
|
|
607
|
-
const num = z.preprocess((v) => (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v)) ? Number(v) : v), z.number());
|
|
608
|
-
// null from an agent means "leave it": drop these keys before forwarding.
|
|
609
|
-
const dropNull = (o, keys) => Object.fromEntries(Object.entries(o).filter(([k, v]) => !(keys.includes(k) && v === null)));
|
|
610
|
-
const at = z.union([num, z.object({ seconds: num }), z.object({ bar: num })])
|
|
611
|
-
.describe('A moment: seconds (3, or { "seconds": 3 }), or { "bar": 5 } once the film has a tempo (bar 1 is the first downbeat; 5.5 is halfway through bar 5).');
|
|
612
|
-
const length = z.union([num, z.object({ seconds: num }), z.object({ bars: num })])
|
|
613
|
-
.describe('A length: seconds (5, or { "seconds": 5 }), or { "bars": 2 } once the film has a tempo.');
|
|
614
|
-
const trimIn = length.describe('Where the clip starts inside its take: seconds or { bars }, 0 for the start of the take.');
|
|
615
|
-
const filmId = z.string().describe('Film id from list_films or create_film');
|
|
616
|
-
const clipRef = z.union([z.string(), z.number()]).describe('A clip: its id, its name, or its number on the timeline (1 is the earliest).');
|
|
617
|
-
const trackRef = z.string().describe('A track: its name, its lane id, or the id of one piece of audio on it.');
|
|
618
|
-
const shot = z.object({
|
|
619
|
-
prompt: z.string().optional().describe('What the shot shows. Name cast members with @name, e.g. "@Kai looks over the city".'),
|
|
620
|
-
seconds: num.optional().describe('How long the shot runs. Shots without seconds share what is left of the clip.'),
|
|
621
|
-
line: z.string().optional().describe('A spoken or sung line in this shot.'),
|
|
622
|
-
speaker: z.string().optional().describe('Who says or sings the line: a cast member\'s name.'),
|
|
623
|
-
framing: z.string().optional().describe('wide, medium, close-up or extreme close-up.'),
|
|
624
|
-
});
|
|
625
|
-
const shots = z.array(shot).describe('The clip\'s shots in order. Replaces the shots it had.');
|
|
626
|
-
const people = z.array(z.string()).describe('Characters by name or id (make them with create_character).
|
|
627
|
-
|
|
628
|
-
server.registerTool('list_films',
|
|
629
|
-
{ title: 'List films', description: 'The Video Studio films of a project (default: the current one): id, title, number of clips. The film tools need the Video Studio in SimpliGen; without it they answer studio_not_installed.', inputSchema: { projectId: z.string().optional() } },
|
|
630
|
-
wrap(({ projectId }) => client.listFilms(projectId)));
|
|
631
|
-
|
|
632
|
-
server.registerTool('create_film',
|
|
633
|
-
{ title: 'Create a film', description: 'Create an empty Video Studio film and answer its timeline. Shape 16:9, 9:16 or 1:1; resolution 480p, 720p or 1080p; renders on this PC (local) or in the cloud. Presets per kind of shot default to the studio\'s own choice.', inputSchema: {
|
|
634
|
-
name: z.string(), projectId: z.string().optional(),
|
|
635
|
-
aspect: z.enum(['16:9', '9:16', '1:1']).optional(), quality: z.enum(['480p', '720p', '1080p']).optional(),
|
|
636
|
-
renderOn: z.enum(['local', 'cloud']).optional(),
|
|
637
|
-
presets: z.object({ t2v: z.string().optional(), i2v: z.string().optional(), r2v: z.string().optional() }).optional().describe('Film presets per kind of shot (pack:preset ids from list_capabilities).'),
|
|
638
|
-
} },
|
|
639
|
-
wrap((a) => client.createFilm(a)));
|
|
640
|
-
|
|
641
|
-
server.registerTool('get_film',
|
|
642
|
-
{ title: 'Get a film', description: 'The film\'s timeline: tempo, cast, every clip (number, name, start and length in seconds and bars, shots, how it starts, its take: none, rendering, current, edited, longer, unknown when it cannot be told yet, or imported for a video brought in and never rendered), tracks, the video lanes above the main row (videoLanes: id and name), markers, the export range, and rendersRunning: true while a render batch is still going on the film (also between the takes of clips that continue from each other, when no clip reads as rendering).', inputSchema: { filmId } },
|
|
643
|
-
wrap(({ filmId: id }) => client.getFilm(id)));
|
|
644
|
-
|
|
645
|
-
server.registerTool('update_film_settings',
|
|
646
|
-
{ title: 'Update film settings', description: 'Change the film\'s shape, resolution, where it renders, presets, Subject & style, and the cast and location every clip inherits.', inputSchema: {
|
|
647
|
-
filmId, aspect: z.enum(['16:9', '9:16', '1:1']).optional(), quality: z.enum(['480p', '720p', '1080p']).optional(),
|
|
648
|
-
hires2x: z.boolean().optional(), renderOn: z.enum(['local', 'cloud']).optional(),
|
|
649
|
-
presets: z.object({ t2v: z.string().optional(), i2v: z.string().optional(), r2v: z.string().optional() }).optional(),
|
|
650
|
-
subject: z.string().optional(), cast: people.optional(), location: z.string().nullable().optional().describe('A location by name or id; null for none.'),
|
|
651
|
-
} },
|
|
652
|
-
wrap(({ filmId: id, ...rest }) => client.updateFilmSettings(id, rest)));
|
|
653
|
-
|
|
654
|
-
server.registerTool('add_track',
|
|
655
|
-
{ title: 'Add a track', description: 'Put an audio file on the film\'s timeline as a new track. Upload it first with upload_file and pass the handle. kind: singing (vocals, drive lip sync), music, dialogue or effects; guessed from the file name when left out.', inputSchema: {
|
|
656
|
-
filmId, upload: z.string().describe('Handle from upload_file'), name: z.string().optional(),
|
|
657
|
-
kind: z.enum(['singing', 'music', 'dialogue', 'effects']).optional(), at: at.optional(),
|
|
658
|
-
} },
|
|
659
|
-
wrap(({ filmId: id, ...rest }) => client.addTrack(id, rest)));
|
|
660
|
-
|
|
661
|
-
server.registerTool('move_track',
|
|
662
|
-
{ title: 'Move a track', description: 'Move a track\'s audio to a new start, mute or unmute it, or set its volume (0 to 1).', inputSchema: {
|
|
663
|
-
filmId, track: trackRef, at: at.optional(), muted: z.boolean().optional(), volume: num.optional(),
|
|
664
|
-
} },
|
|
665
|
-
wrap(({ filmId: id, track, ...rest }) => client.moveTrack(id, track, rest)));
|
|
666
|
-
|
|
667
|
-
server.registerTool('detect_tempo',
|
|
668
|
-
{ title: 'Detect tempo', description: 'Listen to the longest unmuted track (or the one named) and set the film\'s tempo and bar lines from it. Answers the bpm. After this, times can be given in bars.', inputSchema: { filmId, track: trackRef.optional() } },
|
|
669
|
-
wrap(({ filmId: id, track }) => client.detectTempo(id, track ? { track } : {})));
|
|
670
|
-
|
|
671
|
-
server.registerTool('add_clip',
|
|
672
|
-
{ title: 'Add a clip', description: 'Add an empty clip (a shot to render). Starts after the last clip unless `at` is given; length defaults to the model\'s shortest. Write its shots with update_clip.', inputSchema: {
|
|
673
|
-
filmId, at: at.optional(), length: length.optional(), name: z.string().optional(), lane: z.string().optional().describe('A video lane above the main row, by id or name (get_film lists them in videoLanes); leave out for the main row.'),
|
|
674
|
-
} },
|
|
675
|
-
wrap(({ filmId: id, ...rest }) => client.addClip(id, rest)));
|
|
676
|
-
|
|
677
|
-
server.registerTool('import_clip',
|
|
678
|
-
{ title: 'Import a video as a clip', description: 'Put a finished video the user already has (a job from list_jobs or get_job, made anywhere in SimpliGen) on the timeline as a clip, exactly as it is: it plays, trims and exports, and is never re-rendered. Starts after the last clip unless `at` is given; length defaults to the video\'s own. Use this for an approved shot instead of rendering it again.', inputSchema: {
|
|
679
|
-
filmId, generationId: z.string().describe('The finished video\'s job id (jobId from list_jobs or get_job).'),
|
|
680
|
-
at: at.optional(), length: length.optional(), name: z.string().optional(), lane: z.string().optional().describe('A video lane above the main row, by id or name (get_film lists them in videoLanes); leave out for the main row.'),
|
|
681
|
-
} },
|
|
682
|
-
wrap(({ filmId: id, ...rest }) => client.importClip(id, rest)));
|
|
683
|
-
|
|
684
|
-
server.registerTool('update_clip',
|
|
685
|
-
{ title: 'Update a clip', description: 'Write a clip in one step: its shots, who is in it (cast
|
|
686
|
-
filmId, clip: clipRef, shots: shots.optional(), cast: people.optional(),
|
|
687
|
-
location: z.string().optional(), link: z.enum(['fresh', 'continue', 'motion', 'none', 'frame']).optional(),
|
|
688
|
-
hears: z.array(z.object({ track: trackRef, on: z.boolean() })).optional().describe('Which tracks the clip\'s render hears, e.g. [{ "track": "Song", "on": false }].'),
|
|
689
|
-
preset: z.string().nullable().optional().describe('This clip\'s own preset (pack:preset); null to follow the film.'),
|
|
690
|
-
} },
|
|
691
|
-
wrap(({ filmId: id, clip, ...rest }) => client.updateClip(id, clip, rest)));
|
|
692
|
-
|
|
693
|
-
server.registerTool('move_clip',
|
|
694
|
-
{ title: 'Move a clip', description: 'Move a clip to a new start, or to another video lane (leave `at` out to keep its start).', inputSchema: { filmId, clip: clipRef, at: at.nullable().optional(), lane: z.string().nullable().optional().describe('A video lane by id or name (videoLanes in get_film).') } },
|
|
695
|
-
wrap(({ filmId: id, clip, ...rest }) => client.moveClip(id, clip, dropNull(rest, ['at']))));
|
|
696
|
-
|
|
697
|
-
server.registerTool('trim_clip',
|
|
698
|
-
{ title: 'Trim a clip', description: 'Change a clip\'s length on the timeline, or where it starts inside its take (trimIn; 0 resets to the start of the take; leaving it out keeps it).', inputSchema: { filmId, clip: clipRef, length: length.nullable().optional(), trimIn: trimIn.nullable().optional() } },
|
|
699
|
-
wrap(({ filmId: id, clip, ...rest }) => client.trimClip(id, clip, dropNull(rest, ['length', 'trimIn']))));
|
|
700
|
-
|
|
701
|
-
server.registerTool('remove_clip',
|
|
702
|
-
{ title: 'Remove a clip', description: 'Remove a clip from the timeline (and the audio lifted off its renders). With the film open, Ctrl+Z brings it back.', inputSchema: { filmId, clip: clipRef } },
|
|
703
|
-
wrap(({ filmId: id, clip }) => client.removeClip(id, clip)));
|
|
704
|
-
|
|
705
|
-
server.registerTool('apply_film_plan',
|
|
706
|
-
{ title: 'Lay out a film', description: 'Lay out a whole draft in one step: clips on the bars, each with its shots, cast, location and how it starts. Checked as a whole first: every problem comes back at once (invalid_plan with a problems list) and nothing changes unless all of it is valid. mode append (default) adds after the last clip; replace replaces every clip (refused when clips have takes unless discardTakes is true). Clips start at the first downbeat when the film has a tempo and no clips.', inputSchema: {
|
|
707
|
-
filmId, mode: z.enum(['append', 'replace']).optional(), discardTakes: z.boolean().optional(),
|
|
708
|
-
start: at.optional(), cast: people.optional(), location: z.string().optional(),
|
|
709
|
-
clips: z.array(z.object({
|
|
710
|
-
bars: num.optional(), seconds: num.optional(), name: z.string().optional(),
|
|
711
|
-
link: z.enum(['fresh', 'continue', 'motion', 'none', 'frame']).optional(), cast: people.optional(), location: z.string().optional(),
|
|
712
|
-
shots,
|
|
713
|
-
})).describe('The clips in order. Each has bars or seconds, and its shots.'),
|
|
714
|
-
} },
|
|
715
|
-
wrap(({ filmId: id, ...plan }) => client.applyFilmPlan(id, plan)));
|
|
716
|
-
|
|
717
|
-
server.registerTool('set_fades',
|
|
718
|
-
{ title: 'Set fades', description: 'Fade a clip or a track in and out, in seconds.', inputSchema: { filmId, target: z.union([z.string(), z.number()]).describe('A clip (id, name or number) or a track (name or id).'), fadeIn: num.optional(), fadeOut: num.optional() } },
|
|
719
|
-
wrap(({ filmId: id, ...rest }) => client.setFades(id, rest)));
|
|
720
|
-
|
|
721
|
-
server.registerTool('add_marker',
|
|
722
|
-
{ title: 'Add a marker', description: 'Put a named marker on the ruler.', inputSchema: { filmId, at, name: z.string().optional() } },
|
|
723
|
-
wrap(({ filmId: id, ...rest }) => client.addMarker(id, rest)));
|
|
724
|
-
|
|
725
|
-
server.registerTool('set_export_range',
|
|
726
|
-
{ title: 'Set the export range', description: 'Export only from one moment to another, or (clear: true) the whole film. Both `from` and `to` are needed unless `clear` is true.', inputSchema: { filmId, from: at.optional(), to: at.optional(), clear: z.boolean().optional() } },
|
|
727
|
-
wrap(({ filmId: id, ...rest }) => client.setExportRange(id, rest)));
|
|
728
|
-
|
|
729
|
-
server.registerTool('render_clips',
|
|
730
|
-
{ title: 'Render clips', description: 'Render the clips that need it (default) or the clips named. Clips that continue from the clip before render one at a time, each after the take it starts from. Answers once the batch is under way (for clips that do not continue from each other, after queueing them all) with what started, what is held and why, and the cost in the cloud (counted against this agent\'s spend cap). Refused, with nothing started, as exceeds_balance (the cloud balance does not cover it), exceeds_spend_cap (over this agent\'s spend cap) or cost_unknown (the cloud cost is not known yet; try again in a minute). Follow progress with wait_for_renders or get_film.' + APPROVAL_NOTE, inputSchema: {
|
|
731
|
-
filmId, clips: z.union([z.literal('stale'), z.array(clipRef)]).optional().describe('"stale" (default): every clip whose take is missing or out of date; or a list of clips.'),
|
|
732
|
-
} },
|
|
733
|
-
wrap(({ filmId: id, clips }) => client.renderClips(id, clips === undefined ? {} : { clips })));
|
|
734
|
-
|
|
735
|
-
server.registerTool('wait_for_renders',
|
|
736
|
-
{ title: 'Wait for renders', description: 'Wait until no clip of the film is rendering and no render batch is running on it, or the timeout passes, then answer the timeline. Renders take minutes each; call again if it answers timeout_still_running.', inputSchema: { filmId, timeoutSeconds: num.optional(), pollMs: num.optional() } },
|
|
737
|
-
wrap(async ({ filmId: id, timeoutSeconds = 600, pollMs = 10000 }) => {
|
|
738
|
-
pollMs = Math.max(250, pollMs);
|
|
739
|
-
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
740
|
-
for (;;) {
|
|
741
|
-
const timeline = await client.getFilm(id);
|
|
742
|
-
const rendering = (timeline.clips || []).filter((c) => c.take === 'rendering').map((c) => c.number);
|
|
743
|
-
// A linked chain is between takes for a while (nothing reads as rendering): it is
|
|
744
|
-
// not done until the batch says so.
|
|
745
|
-
if (!rendering.length && !timeline.rendersRunning) return { timeline };
|
|
746
|
-
if (Date.now() >= deadline) return { timeline, rendering, note: 'timeout_still_running' };
|
|
747
|
-
await new Promise((r) => setTimeout(r, pollMs));
|
|
748
|
-
}
|
|
749
|
-
}));
|
|
750
|
-
|
|
751
|
-
server.registerTool('list_takes',
|
|
752
|
-
{ title: 'List takes', description: 'Every render of a clip, newest first, numbered, and which one the clip shows.', inputSchema: { filmId, clip: clipRef } },
|
|
753
|
-
wrap(({ filmId: id, clip }) => client.listTakes(id, clip)));
|
|
754
|
-
|
|
755
|
-
server.registerTool('use_take',
|
|
756
|
-
{ title: 'Use a take', description: 'Make one of a clip\'s takes (from list_takes) the one it shows.', inputSchema: { filmId, clip: clipRef, generationId: z.string() } },
|
|
757
|
-
wrap(({ filmId: id, clip, generationId }) => client.useTake(id, clip, generationId)));
|
|
758
|
-
|
|
759
|
-
server.registerTool('export_film',
|
|
760
|
-
{ title: 'Export a film', description: 'Stitch the film (or its export range) into one video with its music, and answer the file path. A long film can take several minutes. Refused with clips_not_ready while clips still need a render; a clip that cannot render at all comes out black and is named in `blanks`.' + APPROVAL_NOTE, inputSchema: { filmId } },
|
|
761
|
-
wrap(({ filmId: id }) => client.exportFilm(id)));
|
|
762
|
-
|
|
763
|
-
server.registerTool('list_locations',
|
|
764
|
-
{ title: 'List locations', description: 'The Library\'s locations (places a cast can stand in): id, name, description, whether it has its picture.', inputSchema: {} },
|
|
765
|
-
wrap(() => client.listLocations()));
|
|
766
|
-
|
|
767
|
-
server.registerTool('create_location',
|
|
768
|
-
{ title: 'Create a location', description: 'Save a location from its picture: an uploaded image (upload, from upload_file) or a finished image job (fromJob, e.g. a generate job you waited for). To make a new place, generate its picture with generate, wait_for_result, then create_location with fromJob.', inputSchema: {
|
|
769
|
-
name: z.string(), description: z.string().optional(), upload: z.string().optional(), fromJob: z.string().optional(),
|
|
770
|
-
} },
|
|
771
|
-
wrap((a) => client.createLocation(a)));
|
|
772
|
-
|
|
773
|
-
server.registerTool('cancel_recipe_run',
|
|
774
|
-
{ title: 'Cancel a recipe run', description: 'Stop a running recipe: no further steps start; a local in-flight step is interrupted (a cloud step already running finishes server-side and is saved).', inputSchema: { runId: z.string() } },
|
|
775
|
-
wrap(({ runId }) => client.cancelRecipeRun(runId)));
|
|
776
|
-
|
|
777
|
-
server.registerTool('get_recipe',
|
|
778
|
-
{ title: 'Get a recipe', description: 'Get a saved recipe and its full config by id.', inputSchema: { id: z.string().describe('Recipe id from compose_recipe or list_recipes') } },
|
|
779
|
-
wrap(({ id }) => client.getRecipe(id)));
|
|
780
|
-
|
|
781
|
-
server.registerTool('publish_recipe',
|
|
782
|
-
{ title: 'Publish a recipe', description: 'Submit a saved recipe to the SimpliGen Creator Marketplace (queued for human review). Requires a connected account: if none, returns not_connected and the user connects once in Settings, then this succeeds on the same recipe. priceTokens sets an optional one-time price (0 or omitted = free). Every preset the recipe uses must be a distributable first-party pack.' + APPROVAL_NOTE, inputSchema: { id: z.string().describe('Recipe id to publish'), changelog: z.string().optional(), priceTokens: z.number().optional().describe('One-time price in tokens (0/omitted = free).') } },
|
|
783
|
-
wrap(({ id, changelog, priceTokens }) => client.publishRecipe(id, { changelog, priceTokens })));
|
|
784
|
-
}
|
|
1
|
+
// packages/mcp-server/src/tools.js
|
|
2
|
+
// Registers SimpliGen MCP tools on an McpServer-shaped object. Each tool calls a
|
|
3
|
+
// ControlApiClient method and returns the JSON result as text content; client
|
|
4
|
+
// errors become an isError tool result (so the agent sees the errorCode/message).
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { buildResultImageContent } from './resultImage.js';
|
|
7
|
+
|
|
8
|
+
export const TOOL_NAMES = [
|
|
9
|
+
'list_capabilities', 'get_status', 'start_engine', 'stop_engine', 'restart_engine',
|
|
10
|
+
'list_projects', 'create_project',
|
|
11
|
+
'wait_for_approval', 'get_app_context', 'fill_generate_form', 'open_screen',
|
|
12
|
+
'upload_file', 'generate', 'list_loras', 'get_prompt_guide', 'get_job', 'wait_for_result', 'list_jobs',
|
|
13
|
+
'cancel_job', 'prepare_preset', 'get_result_image',
|
|
14
|
+
'list_characters', 'get_character', 'list_character_features', 'list_character_presets',
|
|
15
|
+
'remove_character', 'create_character', 'generate_character_image', 'generate_character_video',
|
|
16
|
+
'generate_character_frame', 'animate_character', 'set_character_preset',
|
|
17
|
+
'enhance_character_media', 'regenerate_character_base', 'accept_character_base',
|
|
18
|
+
'list_recipe_blocks', 'compose_recipe', 'validate_recipe', 'list_recipes', 'get_recipe', 'publish_recipe',
|
|
19
|
+
'run_recipe', 'get_recipe_run', 'wait_for_recipe_run', 'list_recipe_runs', 'cancel_recipe_run',
|
|
20
|
+
'list_subjects', 'list_products', 'create_product', 'remove_product',
|
|
21
|
+
'list_films', 'create_film', 'get_film', 'update_film_settings', 'add_track', 'move_track', 'detect_tempo',
|
|
22
|
+
'add_clip', 'import_clip', 'update_clip', 'move_clip', 'trim_clip', 'remove_clip', 'apply_film_plan', 'set_fades', 'add_marker',
|
|
23
|
+
'set_export_range', 'render_clips', 'wait_for_renders', 'list_takes', 'use_take', 'export_film', 'list_locations', 'create_location',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
// The tools that need the Video Studio. Always listed: without the studio each call answers
|
|
27
|
+
// studio_not_installed, which tells an agent why, where a hidden tool tells it nothing.
|
|
28
|
+
export const STUDIO_TOOL_NAMES = TOOL_NAMES.slice(TOOL_NAMES.indexOf('list_films'));
|
|
29
|
+
|
|
30
|
+
const ok = (data) => ({ content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] });
|
|
31
|
+
const fail = (err) => ({ isError: true, content: [{ type: 'text', text: `${err.errorCode ? err.errorCode + ': ' : ''}${err.message || String(err)}` }] });
|
|
32
|
+
const wrap = (fn) => async (args) => { try { return ok(await fn(args)); } catch (e) { return fail(e); } };
|
|
33
|
+
|
|
34
|
+
// In the in-app Assistant the user approves spending and deletions on a card first.
|
|
35
|
+
const APPROVAL_NOTE = ' If the result is awaiting_approval, call wait_for_approval with its proposalId and tell the user an approval card is waiting.';
|
|
36
|
+
|
|
37
|
+
// generate_character_video chains two gated steps; when one waits for the user it stops
|
|
38
|
+
// and tells the agent how to carry on.
|
|
39
|
+
const RESUME_ANIMATE = {
|
|
40
|
+
tool: 'animate_character',
|
|
41
|
+
note: 'The chain stopped at an approval. After wait_for_approval reports done, wait_for_result on the frame job, then call animate_character with that jobId.',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const RESUME_CREATE = { tool: 'get_character', note: 'The base portrait is generated after approval. wait_for_approval returns the new characterId; then poll get_character (or wait_for_result on the base job id, if the create response carries one) until base_image_url is set.' };
|
|
45
|
+
const RESUME_REGEN = { tool: 'wait_for_result', note: 'After approval, wait_for_approval returns the base jobId; call wait_for_result on it, then accept_character_base.' };
|
|
46
|
+
|
|
47
|
+
const NO_PROMPT_GUIDES = 'This SimpliGen version has no prompt guides yet. Update the app, or write the prompt without a guide.';
|
|
48
|
+
|
|
49
|
+
export function registerTools(server, client, { now = Date.now, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
50
|
+
|
|
51
|
+
server.registerTool('list_capabilities',
|
|
52
|
+
{ title: 'List capabilities', description: 'List every SimpliGen preset the agent can generate with (image/video), its inputs/options, whether it is installed locally (localReady) and cloud-eligible + credit cost. Local presets also carry onThisMachine: how likely a run is to finish on this machine (rating, finish %, p90Min: the slow end in minutes on similar cards), the typical minutes on this exact GPU (or notEnoughRunsOnGpu when there is too little data), and what size still fits.', inputSchema: {} },
|
|
53
|
+
wrap(() => client.getCapabilities()));
|
|
54
|
+
|
|
55
|
+
server.registerTool('get_status',
|
|
56
|
+
{ title: 'Get status', description: 'Engine running state, whether cloud is connected, credit balance, and the active project.', inputSchema: {} },
|
|
57
|
+
wrap(() => client.getStatus()));
|
|
58
|
+
|
|
59
|
+
// The engine's lifecycle. get_status could always report it was down and
|
|
60
|
+
// there was nothing an agent could do about it but ask the human to click
|
|
61
|
+
// Start (user report, 2026-09-24). Install, update and repair stay out of
|
|
62
|
+
// reach on purpose: those are multi-GB downloads that belong in front of a
|
|
63
|
+
// person.
|
|
64
|
+
server.registerTool('start_engine',
|
|
65
|
+
{ title: 'Start engine', description: 'Start the local engine if it is not already running. Returns the engine state; a cold boot can outlast the call, in which case engineStarting is true and get_status tells you when it is up. Does nothing if the engine is already running, and will not install one that is missing.', inputSchema: {} },
|
|
66
|
+
wrap(() => client.startEngine()));
|
|
67
|
+
|
|
68
|
+
server.registerTool('stop_engine',
|
|
69
|
+
{ title: 'Stop engine', description: 'Stop the local engine. Frees its VRAM; cloud generation is unaffected.', inputSchema: {} },
|
|
70
|
+
wrap(() => client.stopEngine()));
|
|
71
|
+
|
|
72
|
+
server.registerTool('restart_engine',
|
|
73
|
+
{ title: 'Restart engine', description: 'Restart the local engine. Use it after installing or removing a custom node, or when the engine is wedged.', inputSchema: {} },
|
|
74
|
+
wrap(() => client.restartEngine()));
|
|
75
|
+
|
|
76
|
+
server.registerTool('list_projects',
|
|
77
|
+
{ title: 'List projects', description: 'List projects (output containers).', inputSchema: {} },
|
|
78
|
+
wrap(() => client.listProjects()));
|
|
79
|
+
|
|
80
|
+
server.registerTool('create_project',
|
|
81
|
+
{ title: 'Create project', description: 'Create a new project (output container).', inputSchema: { name: z.string().describe('Project name') } },
|
|
82
|
+
wrap(({ name }) => client.createProject(name)));
|
|
83
|
+
|
|
84
|
+
server.registerTool('upload_file',
|
|
85
|
+
{ title: 'Upload a file', description: 'Upload a local image/video file and get an opaque handle to pass as image/referenceImages/video in generate.', inputSchema: { path: z.string().describe('Absolute local file path') } },
|
|
86
|
+
wrap(({ path }) => client.uploadFile(path)));
|
|
87
|
+
|
|
88
|
+
server.registerTool('generate',
|
|
89
|
+
{
|
|
90
|
+
title: 'Generate', description: 'Start an image or video generation. Before writing the prompt, call get_prompt_guide for the preset and follow it. Inputs (image/referenceImages/video) are handles from upload_file. backend: local | cloud | auto. Returns a jobId (and, for local runs, an expectation with the same fields as onThisMachine for the requested settings); poll with wait_for_result or get_job.' + APPROVAL_NOTE,
|
|
91
|
+
inputSchema: {
|
|
92
|
+
presetId: z.string(), mediaType: z.enum(['image', 'video']), prompt: z.string(),
|
|
93
|
+
packId: z.string().optional(), backend: z.enum(['local', 'cloud', 'auto']).optional(),
|
|
94
|
+
negativePrompt: z.string().optional().describe('Extra terms added to the preset default negative prompt (local runs only); the default is always applied.'),
|
|
95
|
+
project: z.string().optional(),
|
|
96
|
+
image: z.string().optional().describe('upload_file handle'),
|
|
97
|
+
// A bare handle still works, so every agent written against the old
|
|
98
|
+
// schema keeps working. The object form carries the per-image label,
|
|
99
|
+
// which is the DESCRIPTION the app asks for when list_capabilities says
|
|
100
|
+
// inputs.referenceImages.requiresDescriptions is true (LTX 2.5
|
|
101
|
+
// Multi-Reference builds one appearance line per subject from it).
|
|
102
|
+
// Sending images without it on such a preset runs, but the subjects
|
|
103
|
+
// blur together, which is indistinguishable from the model being bad.
|
|
104
|
+
referenceImages: z.array(z.union([
|
|
105
|
+
z.string(),
|
|
106
|
+
z.object({
|
|
107
|
+
handle: z.string().describe('upload_file handle'),
|
|
108
|
+
label: z.string().optional().describe('What this reference IS, e.g. "a woman with red hair". Required in spirit when the preset reports requiresDescriptions.'),
|
|
109
|
+
}),
|
|
110
|
+
])).optional().describe('upload_file handles, or {handle, label} when the preset wants a description per reference'),
|
|
111
|
+
video: z.string().optional().describe('upload_file handle (driving video)'),
|
|
112
|
+
// The App has accepted these three since 1.58.0; this schema never
|
|
113
|
+
// offered them, so no agent could drive an audio preset at all: the
|
|
114
|
+
// error said needs_audio and there was nowhere to put a sound
|
|
115
|
+
// (mavr1k_, 2026-10-01). Passing it inside `options` does not work
|
|
116
|
+
// either, since preflight reads the top level.
|
|
117
|
+
audio: z.string().optional().describe('upload_file handle for the PRIMARY audio track (lip-sync / audio-to-video presets). Required when list_capabilities reports inputs.acceptsAudio true, optional when it reports "optional".'),
|
|
118
|
+
referenceAudios: z.array(z.union([
|
|
119
|
+
z.string(),
|
|
120
|
+
z.object({ handle: z.string(), durationSeconds: z.number().optional() }),
|
|
121
|
+
])).optional().describe('upload_file handles for reference SOUNDS (a voice per subject, where the preset pairs them with references).'),
|
|
122
|
+
referenceVideos: z.array(z.union([
|
|
123
|
+
z.string(),
|
|
124
|
+
z.object({
|
|
125
|
+
handle: z.string(),
|
|
126
|
+
soundtrackMode: z.enum(['own', 'file', 'none']).optional().describe("Where this clip's sound comes from: 'own' (the clip's own audio, the default), 'file' (another upload, see soundtrack), or 'none' (silent)."),
|
|
127
|
+
soundtrack: z.string().optional().describe("upload_file handle for the audio to use. Required with soundtrackMode 'file', ignored otherwise."),
|
|
128
|
+
durationSeconds: z.number().optional(),
|
|
129
|
+
}),
|
|
130
|
+
])).optional().describe('upload_file handles for reference CLIPS (MiniMax H3 scene chaining chains on a clip).'),
|
|
131
|
+
// Appended to the prompt by the app's own dialogue formatter, so the
|
|
132
|
+
// wording matches what the preset was tuned on. MiniMax H3 lip-syncs
|
|
133
|
+
// to it; sending it to a preset that does not declare supportsDialogue
|
|
134
|
+
// changes nothing.
|
|
135
|
+
dialogue: z.string().optional().describe('A spoken line for the character, when list_capabilities reports inputs.supportsDialogue.'),
|
|
136
|
+
dialogueDelivery: z.string().optional().describe('How the line is delivered, e.g. "urgent", "whispered". Only meaningful with dialogue.'),
|
|
137
|
+
loras: z.array(z.object({ name: z.string().describe('LoRA display name from list_loras'), weight: z.number().optional().describe('Strength; defaults to the LoRA default') })).optional().describe('LoRAs to apply. Local backend only, and only for presets where inputs.supportsLoras is true. Use the LoRA trigger words in the prompt so it activates.'),
|
|
138
|
+
// .passthrough(), not the zod default: a plain z.object STRIPS every key it
|
|
139
|
+
// does not name, silently. The App's /generate accepts any Advanced
|
|
140
|
+
// Control the preset declares (unlock, shift, high_steps, ...) and
|
|
141
|
+
// list_capabilities advertises them under options.controls, so an agent
|
|
142
|
+
// was told a control exists, sent it, and got the preset default back
|
|
143
|
+
// with no error: unlock: 1 arrived at the graph as 0.5 (Melvyl, 1.63.0).
|
|
144
|
+
// The App applies only what the preset declares and ignores the rest,
|
|
145
|
+
// so forwarding everything is safe. Known fields stay named so the
|
|
146
|
+
// agent still sees them in the tool's schema.
|
|
147
|
+
options: z.object({
|
|
148
|
+
resolution: z.string().optional().describe('Resolution tier label; see list_capabilities -> options.resolution.'),
|
|
149
|
+
aspectRatio: z.string().optional().describe('Aspect ratio, e.g. "1:1", "16:9", "9:16" (portrait/vertical), "4:3", "3:4". See list_capabilities -> options.aspectRatio for the values each preset accepts. Defaults to 1:1 for images (16:9 for video) if omitted.'),
|
|
150
|
+
durationSeconds: z.number().optional(),
|
|
151
|
+
steps: z.number().optional(),
|
|
152
|
+
cfg: z.number().optional(),
|
|
153
|
+
seed: z.number().optional(),
|
|
154
|
+
negativePrompt: z.string().optional(),
|
|
155
|
+
fasterAttention: z.boolean().optional().describe('Accelerator toggle; absent = preset default.'),
|
|
156
|
+
solAttn: z.boolean().optional().describe('Accelerator toggle; absent = preset default.'),
|
|
157
|
+
spectrum: z.boolean().optional().describe('Accelerator toggle; absent = preset default.'),
|
|
158
|
+
}).passthrough().optional().describe('Run options. Besides the named fields, pass ANY Advanced Control the preset declares under list_capabilities -> options.controls (for example unlock, shift, high_steps) as a top-level key of this object, using the value range that map gives. A key the preset does not declare is ignored.'),
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
wrap((args) => client.generate(args)));
|
|
162
|
+
|
|
163
|
+
server.registerTool('list_loras',
|
|
164
|
+
{ title: 'List LoRAs', description: 'List the installed user LoRAs (name, base model, trigger words) so you can pass them in generate -> loras.', inputSchema: {} },
|
|
165
|
+
wrap(() => client.listLoras()));
|
|
166
|
+
|
|
167
|
+
server.registerTool('get_prompt_guide',
|
|
168
|
+
{
|
|
169
|
+
title: 'Get prompt guide',
|
|
170
|
+
description: 'Read the prompting guide for a preset before writing its prompt: how its model reads a prompt, structure, length, camera and motion wording, negatives, character wording and examples. Follow it when you write the prompt for generate.',
|
|
171
|
+
inputSchema: { presetId: z.string() },
|
|
172
|
+
},
|
|
173
|
+
async ({ presetId }) => {
|
|
174
|
+
try {
|
|
175
|
+
return ok(await client.getPromptGuide(presetId));
|
|
176
|
+
} catch (e) {
|
|
177
|
+
// Any other 404 means the app predates the route.
|
|
178
|
+
if (e && e.status === 404 && e.errorCode !== 'unknown_preset') {
|
|
179
|
+
return { isError: true, content: [{ type: 'text', text: NO_PROMPT_GUIDES }] };
|
|
180
|
+
}
|
|
181
|
+
return fail(e);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
server.registerTool('get_job',
|
|
186
|
+
{ title: 'Get job', description: 'Status + result of a generation job. resultPath is the local file when completed.', inputSchema: { jobId: z.string() } },
|
|
187
|
+
wrap(({ jobId }) => client.getJob(jobId)));
|
|
188
|
+
|
|
189
|
+
server.registerTool('list_jobs',
|
|
190
|
+
{ title: 'List jobs', description: 'Recent generation jobs.', inputSchema: {} },
|
|
191
|
+
wrap(() => client.listJobs()));
|
|
192
|
+
|
|
193
|
+
server.registerTool('cancel_job',
|
|
194
|
+
{ title: 'Cancel job', description: 'Cancel a queued/running job.', inputSchema: { jobId: z.string() } },
|
|
195
|
+
wrap(({ jobId }) => client.cancelJob(jobId)));
|
|
196
|
+
|
|
197
|
+
server.registerTool('prepare_preset',
|
|
198
|
+
{ title: 'Prepare preset', description: 'Start downloading a local preset\'s models (so it becomes localReady). Poll list_capabilities for localReady.', inputSchema: { presetId: z.string(), mediaType: z.enum(['image', 'video']), packId: z.string().optional() } },
|
|
199
|
+
wrap((args) => client.preparePreset(args)));
|
|
200
|
+
|
|
201
|
+
// Convenience: poll get_job until terminal or timeout (no extra endpoint).
|
|
202
|
+
server.registerTool('wait_for_result',
|
|
203
|
+
{ title: 'Wait for result', description: 'Block until a job completes or fails (or the timeout). Returns the final job (resultPath when completed).', inputSchema: { jobId: z.string(), timeoutSeconds: z.number().optional(), pollMs: z.number().optional() } },
|
|
204
|
+
wrap(async ({ jobId, timeoutSeconds = 300, pollMs = 2000 }) => {
|
|
205
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
206
|
+
// eslint-disable-next-line no-constant-condition
|
|
207
|
+
while (true) {
|
|
208
|
+
const { job } = await client.getJob(jobId);
|
|
209
|
+
if (!job || job.status === 'completed' || job.status === 'failed') return job;
|
|
210
|
+
if (Date.now() >= deadline) return { ...job, note: 'timeout_still_running' };
|
|
211
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
214
|
+
|
|
215
|
+
// Return a completed job's result image inline (an MCP image block) so the
|
|
216
|
+
// agent can actually display it. Images only; video/unreadable -> path note.
|
|
217
|
+
server.registerTool('get_result_image',
|
|
218
|
+
{ title: 'Get result image', description: 'Return a completed job\'s result image inline as a viewable image so it can be displayed in chat. Large images are re-encoded to a full-resolution WebP preview that fits the client size cap; the uncompressed original file path is always included in the caption. Video results return the file path instead. Call after the job is completed.', inputSchema: { jobId: z.string(), maxBytes: z.number().optional().describe('Inline byte budget before re-encoding/resizing (default ~700KB raw)') } },
|
|
219
|
+
async ({ jobId, maxBytes }) => {
|
|
220
|
+
try {
|
|
221
|
+
const { job } = await client.getJob(jobId);
|
|
222
|
+
return await buildResultImageContent(job, { budgetBytes: maxBytes });
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return fail(e);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// The user's Approve click on an approval card can take minutes: poll in rounds the
|
|
229
|
+
// control API can hold open (25 s max), until the proposal settles or the timeout passes.
|
|
230
|
+
server.registerTool('wait_for_approval',
|
|
231
|
+
{ title: 'Wait for approval', description: 'Block until the user approves or declines an approval card (proposalId from an awaiting_approval result), or the timeout passes. Returns { status: done | declined | expired, ... }: done carries the result of the approved call (for example the jobId), declined carries a reason. On timeout returns { status: pending, note: still_waiting }: call it again.', inputSchema: { proposalId: z.string(), timeoutSeconds: z.number().optional().describe('Total seconds to wait (default 600)') } },
|
|
232
|
+
wrap(async ({ proposalId, timeoutSeconds = 600 }) => {
|
|
233
|
+
const deadline = now() + timeoutSeconds * 1000;
|
|
234
|
+
for (;;) {
|
|
235
|
+
const remaining = Math.ceil((deadline - now()) / 1000);
|
|
236
|
+
if (remaining <= 0) return { status: 'pending', note: 'still_waiting', proposalId };
|
|
237
|
+
const started = now();
|
|
238
|
+
const r = await client.waitForApproval(proposalId, Math.min(25, remaining));
|
|
239
|
+
if (r.status === 'done') {
|
|
240
|
+
const httpStatus = r.result?.status;
|
|
241
|
+
return { status: 'done', ok: httpStatus >= 200 && httpStatus < 300, result: r.result?.json, httpStatus };
|
|
242
|
+
}
|
|
243
|
+
if (r.status !== 'pending' && r.status !== 'running') return r;
|
|
244
|
+
// A server that answers at once instead of holding the call must not be hammered.
|
|
245
|
+
const spent = now() - started;
|
|
246
|
+
if (spent < 1000) await sleep(1000 - spent);
|
|
247
|
+
}
|
|
248
|
+
}));
|
|
249
|
+
|
|
250
|
+
// ---- The app's own screen: what the user sees, and moving it for them ----
|
|
251
|
+
|
|
252
|
+
server.registerTool('get_app_context',
|
|
253
|
+
{ title: 'Get app context', description: 'What the user is looking at in SimpliGen right now: the open screen, the selected preset, character or film, and the current Generate form values.', inputSchema: {} },
|
|
254
|
+
wrap(() => client.getAppContext()));
|
|
255
|
+
|
|
256
|
+
server.registerTool('fill_generate_form',
|
|
257
|
+
{ title: 'Fill the Generate form', description: 'Fill in the Generate screen for the user (preset, prompt and settings) without generating, so they can review it and click Generate themselves.', inputSchema: {
|
|
258
|
+
presetId: z.string(), prompt: z.string(), negativePrompt: z.string().optional(), characterId: z.string().optional(),
|
|
259
|
+
settings: z.record(z.any()).optional().describe('Preset settings keyed by setting id (see list_capabilities).'),
|
|
260
|
+
} },
|
|
261
|
+
wrap((a) => client.fillGenerateForm(a)));
|
|
262
|
+
|
|
263
|
+
server.registerTool('open_screen',
|
|
264
|
+
{ title: 'Open a screen', description: 'Take the user to a screen in SimpliGen. id selects a character when screen is "character".', inputSchema: {
|
|
265
|
+
screen: z.enum(['generate', 'gallery', 'characters', 'character', 'video-studio', 'prompt-library', 'settings']),
|
|
266
|
+
id: z.string().optional(),
|
|
267
|
+
} },
|
|
268
|
+
wrap((a) => client.openScreen(a)));
|
|
269
|
+
|
|
270
|
+
// ---- Character Studio tools ----
|
|
271
|
+
|
|
272
|
+
server.registerTool('list_characters',
|
|
273
|
+
{ title: 'List characters', description: 'List all saved characters in Character Studio.', inputSchema: {} },
|
|
274
|
+
wrap(() => client.listCharacters()));
|
|
275
|
+
|
|
276
|
+
server.registerTool('get_character',
|
|
277
|
+
{ title: 'Get character', description: 'Get a single character by ID, including its current base portrait and identity features.', inputSchema: { characterId: z.string() } },
|
|
278
|
+
wrap(({ characterId }) => client.getCharacter(characterId)));
|
|
279
|
+
|
|
280
|
+
server.registerTool('list_character_features',
|
|
281
|
+
{ title: 'List character features', description: 'List available feature categories and their options (e.g. hairColor, eyeColor) for use with create_character identity.', inputSchema: {} },
|
|
282
|
+
wrap(() => client.listCharacterFeatures()));
|
|
283
|
+
|
|
284
|
+
server.registerTool('list_character_presets',
|
|
285
|
+
{ title: 'List character presets', description: 'List generation presets available for Character Studio. Returns base, identityEdit, and i2v presets as well as enhanceImage and enhanceVideo presets (each with supportedScales). Use the returned ids as presetId/imagePresetId/videoPresetId/basePresetId arguments in other character tools.', inputSchema: {} },
|
|
286
|
+
wrap(() => client.listCharacterPresets()));
|
|
287
|
+
|
|
288
|
+
server.registerTool('remove_character',
|
|
289
|
+
{ title: 'Remove character', description: 'Permanently delete a character and its associated data.' + APPROVAL_NOTE, inputSchema: { characterId: z.string() } },
|
|
290
|
+
wrap(({ characterId }) => client.removeCharacter(characterId)));
|
|
291
|
+
|
|
292
|
+
server.registerTool('create_character',
|
|
293
|
+
{
|
|
294
|
+
title: 'Create character',
|
|
295
|
+
description: 'Create a new character. Three paths: (1) describe -- pass gender and identity features from list_character_features with mode "generate"; the server builds a base portrait automatically and this tool waits until ready. (2) upload as base -- pass baseFilePath pointing to a local image with mode "upload"; the image becomes the base portrait immediately. (3) vision recreate -- describe path but fill identity by having the agent analyse a reference photo first; the agent extracts features and passes them as identity.' + APPROVAL_NOTE,
|
|
296
|
+
inputSchema: {
|
|
297
|
+
name: z.string().describe('Display name for the character'),
|
|
298
|
+
gender: z.enum(['woman', 'man', 'nonbinary']),
|
|
299
|
+
mode: z.enum(['generate', 'upload']).describe('generate: build base portrait from description; upload: use a provided image as base'),
|
|
300
|
+
identity: z.record(z.string()).optional().describe('An object of featureId to optionId pairs chosen from list_character_features (e.g. { hairColor: "black", eyeColor: "green" }). Do not include gender here; pass gender separately.'),
|
|
301
|
+
baseFilePath: z.string().optional().describe('Absolute local image path; required for mode "upload"'),
|
|
302
|
+
timeoutSeconds: z.number().optional().describe('Max seconds to wait for base portrait generation (default 300, mode generate only)'),
|
|
303
|
+
pollMs: z.number().optional().describe('Poll interval in milliseconds (default 2000, mode generate only)'),
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
async ({ name, gender, mode, identity, baseFilePath, timeoutSeconds, pollMs }) => {
|
|
307
|
+
try {
|
|
308
|
+
if (mode === 'upload') {
|
|
309
|
+
const up = await client.uploadFile(baseFilePath);
|
|
310
|
+
const char = await client.createCharacter({ name, gender, mode: 'upload', identity, baseHandle: up.handle });
|
|
311
|
+
if (char?.status === 'awaiting_approval') return ok({ ...char, resume: RESUME_CREATE });
|
|
312
|
+
return ok({ ...char, ready: true });
|
|
313
|
+
}
|
|
314
|
+
// mode === 'generate': create then poll until base_image_url is set
|
|
315
|
+
const c = await client.createCharacter({ name, gender, mode: 'generate', identity });
|
|
316
|
+
if (c?.status === 'awaiting_approval') return ok({ ...c, resume: RESUME_CREATE });
|
|
317
|
+
const { characterId } = c;
|
|
318
|
+
const deadline = Date.now() + (timeoutSeconds ?? 300) * 1000;
|
|
319
|
+
while (true) {
|
|
320
|
+
const { character } = await client.getCharacter(characterId);
|
|
321
|
+
if (character?.base_image_url) return ok(character);
|
|
322
|
+
if (Date.now() >= deadline) return ok({ ...character, base_pending: true });
|
|
323
|
+
await new Promise((r) => setTimeout(r, pollMs ?? 2000));
|
|
324
|
+
}
|
|
325
|
+
} catch (e) {
|
|
326
|
+
return fail(e);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
server.registerTool('generate_character_image',
|
|
331
|
+
{
|
|
332
|
+
title: 'Generate character image',
|
|
333
|
+
description: 'Generate one or more images of a character in a scene. Returns jobIds; use wait_for_result then get_result_image for each. Pass presetId to override the default image preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
334
|
+
inputSchema: {
|
|
335
|
+
characterId: z.string(),
|
|
336
|
+
prompt: z.string(),
|
|
337
|
+
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
338
|
+
count: z.number().optional(),
|
|
339
|
+
presetId: z.string().optional().describe('Override image preset (id from list_character_presets)'),
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
wrap(({ characterId, prompt, aspect, count, presetId }) => {
|
|
343
|
+
const args = { prompt, aspect, count };
|
|
344
|
+
if (presetId !== undefined) args.presetId = presetId;
|
|
345
|
+
return client.generateCharacterImage(characterId, args);
|
|
346
|
+
}));
|
|
347
|
+
|
|
348
|
+
server.registerTool('generate_character_video',
|
|
349
|
+
{
|
|
350
|
+
title: 'Generate character video',
|
|
351
|
+
description: 'Generate a short video of a character in a scene. Internally generates a frame then animates it (I2V). Returns frameJobId and videoJobId; use wait_for_result then get_result_image on videoJobId. Use framePresetId to override the image-frame preset and videoPresetId to override the video/animate preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
352
|
+
inputSchema: {
|
|
353
|
+
characterId: z.string(),
|
|
354
|
+
prompt: z.string(),
|
|
355
|
+
motion: z.string().optional().describe('Optional motion description or style hint'),
|
|
356
|
+
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
357
|
+
timeoutSeconds: z.number().optional().describe('Max seconds to wait for the frame job (default 300)'),
|
|
358
|
+
pollMs: z.number().optional().describe('Poll interval in milliseconds (default 2000)'),
|
|
359
|
+
framePresetId: z.string().optional().describe('Override image-frame preset (id from list_character_presets)'),
|
|
360
|
+
videoPresetId: z.string().optional().describe('Override video/animate preset (id from list_character_presets)'),
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
async ({ characterId, prompt, motion, aspect, timeoutSeconds = 300, pollMs = 2000, framePresetId, videoPresetId }) => {
|
|
364
|
+
try {
|
|
365
|
+
// 1. Generate a frame (still image for I2V)
|
|
366
|
+
const frame = await client.generateCharacterFrame(characterId, { prompt, aspect, presetId: framePresetId });
|
|
367
|
+
if (frame?.status === 'awaiting_approval') return ok({ ...frame, resume: RESUME_ANIMATE });
|
|
368
|
+
const { jobIds: [frameJobId] } = frame;
|
|
369
|
+
// 2. Wait for frame to complete
|
|
370
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
371
|
+
while (true) {
|
|
372
|
+
const { job: frameJob } = await client.getJob(frameJobId);
|
|
373
|
+
if (frameJob?.status === 'completed') break;
|
|
374
|
+
if (frameJob?.status === 'failed') return fail({ message: `Frame job failed: ${frameJobId}`, errorCode: 'frame_failed' });
|
|
375
|
+
if (Date.now() >= deadline) return fail({ message: `Frame job timed out: ${frameJobId}`, errorCode: 'frame_timeout' });
|
|
376
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
377
|
+
}
|
|
378
|
+
// 3. Animate from the completed frame
|
|
379
|
+
const video = await client.animateCharacter(characterId, { frameJobId, motion, aspect, presetId: videoPresetId });
|
|
380
|
+
if (video?.status === 'awaiting_approval') return ok({ ...video, resume: RESUME_ANIMATE });
|
|
381
|
+
const { jobIds: [videoJobId] } = video;
|
|
382
|
+
return ok({ frameJobId, videoJobId });
|
|
383
|
+
} catch (e) { return fail(e); }
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// ---- New Character Studio tools (Task 4) ----
|
|
387
|
+
|
|
388
|
+
server.registerTool('generate_character_frame',
|
|
389
|
+
{
|
|
390
|
+
title: 'Generate character frame',
|
|
391
|
+
description: 'Generate a start-frame image for a character that you can review or enhance before animating. Returns jobIds; use wait_for_result then get_result_image. Pass presetId to override the frame-image preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
392
|
+
inputSchema: {
|
|
393
|
+
characterId: z.string(),
|
|
394
|
+
prompt: z.string(),
|
|
395
|
+
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
396
|
+
presetId: z.string().optional().describe('Override image preset (id from list_character_presets)'),
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
wrap(({ characterId, prompt, aspect, presetId }) => {
|
|
400
|
+
const args = { prompt, aspect };
|
|
401
|
+
if (presetId !== undefined) args.presetId = presetId;
|
|
402
|
+
return client.generateCharacterFrame(characterId, args);
|
|
403
|
+
}));
|
|
404
|
+
|
|
405
|
+
server.registerTool('animate_character',
|
|
406
|
+
{
|
|
407
|
+
title: 'Animate character',
|
|
408
|
+
description: 'Animate a character from a completed image/frame job or a local file path (I2V). jobId may be any completed character image, frame, or upscale job. Returns jobIds; use wait_for_result then get_result_image. Pass videoPresetId to override the video preset (ids from list_character_presets).' + APPROVAL_NOTE,
|
|
409
|
+
inputSchema: {
|
|
410
|
+
characterId: z.string(),
|
|
411
|
+
jobId: z.string().optional().describe('Any completed character image/frame/upscale jobId to use as the source frame'),
|
|
412
|
+
filePath: z.string().optional().describe('Absolute local image path to use as the source frame'),
|
|
413
|
+
motion: z.string().optional().describe('Optional motion description or style hint'),
|
|
414
|
+
aspect: z.enum(['16:9', '9:16', '1:1']).optional(),
|
|
415
|
+
videoPresetId: z.string().optional().describe('Override video/animate preset (id from list_character_presets)'),
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
wrap(({ characterId, jobId, filePath, motion, aspect, videoPresetId }) =>
|
|
419
|
+
client.animateCharacter(characterId, { frameJobId: jobId, framePath: filePath, motion, aspect, presetId: videoPresetId })));
|
|
420
|
+
|
|
421
|
+
server.registerTool('set_character_preset',
|
|
422
|
+
{
|
|
423
|
+
title: 'Set character preset',
|
|
424
|
+
description: 'Set sticky per-character default presets for image and/or video generation. Ids come from list_character_presets. Pass null to clear a preset back to the system default.',
|
|
425
|
+
inputSchema: {
|
|
426
|
+
characterId: z.string(),
|
|
427
|
+
imagePresetId: z.string().nullable().optional().describe('Default image preset id (null to clear)'),
|
|
428
|
+
videoPresetId: z.string().nullable().optional().describe('Default video preset id (null to clear)'),
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
wrap(({ characterId, imagePresetId, videoPresetId }) => client.setCharacterPreset(characterId, { imagePresetId, videoPresetId })));
|
|
432
|
+
|
|
433
|
+
server.registerTool('enhance_character_media',
|
|
434
|
+
{
|
|
435
|
+
title: 'Enhance character media',
|
|
436
|
+
description: 'Upscale a generated image/video, a local file, or the character base portrait (target: "base"). Returns a jobId; use wait_for_result then get_result_image. scale sets the upscale factor; keepResolution upscales then resizes back to source size for a sharper same-size result; applyAsBase replaces the character base portrait with the upscaled result. Enhance presets come from list_character_presets (enhanceImage/enhanceVideo, each with supportedScales).' + APPROVAL_NOTE,
|
|
437
|
+
inputSchema: {
|
|
438
|
+
characterId: z.string(),
|
|
439
|
+
jobId: z.string().optional().describe('Completed job whose result to enhance'),
|
|
440
|
+
filePath: z.string().optional().describe('Absolute local image/video path to enhance'),
|
|
441
|
+
target: z.enum(['base']).optional().describe('Pass "base" to enhance the character base portrait'),
|
|
442
|
+
mediaType: z.enum(['image', 'video']).optional(),
|
|
443
|
+
presetId: z.string().optional().describe('Enhance preset id from list_character_presets'),
|
|
444
|
+
scale: z.number().optional().describe('Upscale factor (e.g. 2 for 2x)'),
|
|
445
|
+
keepResolution: z.boolean().optional().describe('Upscale then resize back to source dimensions for a sharper same-size result'),
|
|
446
|
+
applyAsBase: z.boolean().optional().describe('Replace the character base portrait with the upscaled result'),
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
wrap(({ characterId, jobId, filePath, target, mediaType, presetId, scale, keepResolution, applyAsBase }) =>
|
|
450
|
+
client.enhanceCharacterMedia(characterId, { jobId, filePath, target, mediaType, presetId, scale, keepResolution, applyAsBase })));
|
|
451
|
+
|
|
452
|
+
server.registerTool('regenerate_character_base',
|
|
453
|
+
{
|
|
454
|
+
title: 'Regenerate character base',
|
|
455
|
+
description: 'Switch the base model and regenerate the base portrait IN PLACE (no new character created). Replaces the current base when completed. Uses basePresetId from list_character_presets. Optionally update identity features at the same time. Polls until completed, then auto-accepts the new base.' + APPROVAL_NOTE,
|
|
456
|
+
inputSchema: {
|
|
457
|
+
characterId: z.string(),
|
|
458
|
+
basePresetId: z.string().optional().describe('Base-generation preset id from list_character_presets'),
|
|
459
|
+
identity: z.record(z.string()).optional().describe('Updated identity feature map (featureId -> optionId) to apply alongside the new base'),
|
|
460
|
+
timeoutSeconds: z.number().optional().describe('Max seconds to wait for the base job (default 300)'),
|
|
461
|
+
pollMs: z.number().optional().describe('Poll interval in milliseconds (default 2000)'),
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
async ({ characterId, basePresetId, identity, timeoutSeconds = 300, pollMs = 2000 }) => {
|
|
465
|
+
try {
|
|
466
|
+
const regen = await client.regenerateCharacterBase(characterId, { basePresetId, identity });
|
|
467
|
+
if (regen?.status === 'awaiting_approval') return ok({ ...regen, resume: RESUME_REGEN });
|
|
468
|
+
const { baseJobId } = regen;
|
|
469
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
470
|
+
while (true) {
|
|
471
|
+
const { job } = await client.getJob(baseJobId);
|
|
472
|
+
if (job?.status === 'completed') {
|
|
473
|
+
await client.acceptBase(characterId, { altImageId: baseJobId });
|
|
474
|
+
return ok(await client.getCharacter(characterId));
|
|
475
|
+
}
|
|
476
|
+
if (job?.status === 'failed') return fail({ message: `Base regeneration job failed: ${baseJobId}`, errorCode: 'base_failed' });
|
|
477
|
+
if (Date.now() >= deadline) return ok({ baseJobId, note: 'timeout_still_running' });
|
|
478
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
479
|
+
}
|
|
480
|
+
} catch (e) { return fail(e); }
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
server.registerTool('accept_character_base',
|
|
484
|
+
{
|
|
485
|
+
title: 'Accept character base',
|
|
486
|
+
description: 'Make a finished base-portrait job the base of the character. Use it after an approved regenerate_character_base job finishes (wait_for_result completed).',
|
|
487
|
+
inputSchema: { characterId: z.string(), jobId: z.string().describe('The completed base job id') },
|
|
488
|
+
},
|
|
489
|
+
wrap(({ characterId, jobId }) => client.acceptBase(characterId, { altImageId: jobId })));
|
|
490
|
+
|
|
491
|
+
// --- Recipe authoring: compose multi-step recipes out of packs/presets ---
|
|
492
|
+
|
|
493
|
+
const recipeStep = z.object({
|
|
494
|
+
preset: z.string().describe('The preset this step runs, as "packId:presetId" (from list_recipe_blocks).'),
|
|
495
|
+
entry: z.string().optional().describe('Entry point: create-image | create-video | edit-image | upscale. Inferred from the preset when omitted.'),
|
|
496
|
+
promptInput: z.object({ key: z.string().optional(), label: z.string().optional() }).optional()
|
|
497
|
+
.describe('Name this step\'s prompt input, or set key to an existing input to SHARE a prompt. Default: a dedicated prompt input per step.'),
|
|
498
|
+
negativePrompt: z.string().optional(),
|
|
499
|
+
params: z.record(z.any()).optional().describe('Param bindings, literal or { from: "input:<key>" } (e.g. aspectRatio, seed, duration).'),
|
|
500
|
+
}).passthrough();
|
|
501
|
+
|
|
502
|
+
const recipeInput = z.object({
|
|
503
|
+
key: z.string().describe('Unique slug referenced as input:<key>.'),
|
|
504
|
+
kind: z.string().describe('subject | text | image | video | reference | audio | select | color | number | toggle'),
|
|
505
|
+
label: z.string().optional(),
|
|
506
|
+
required: z.boolean().optional(),
|
|
507
|
+
}).passthrough();
|
|
508
|
+
|
|
509
|
+
const recipeSpec = z.object({
|
|
510
|
+
name: z.string().describe('Recipe name shown to end users.'),
|
|
511
|
+
description: z.string().optional(),
|
|
512
|
+
category: z.string().optional().describe('e.g. product | ugc'),
|
|
513
|
+
mature: z.boolean().optional().describe('Creator-declared: this recipe produces adult content.'),
|
|
514
|
+
// Accepted, not for the benefit of third parties (breaking them is fine), but
|
|
515
|
+
// because an agent composing a recipe mid-transition would otherwise DROP the
|
|
516
|
+
// classification, which publishes adult content as unclassified (TASK-472).
|
|
517
|
+
nsfw: z.boolean().optional().describe('Deprecated alias for `mature`.'),
|
|
518
|
+
version: z.string().optional().describe('Creator-facing semver, default 1.0.0.'),
|
|
519
|
+
inputs: z.array(recipeInput).optional().describe('Extra user-facing inputs (subjects, choices, media holes). A prompt input is auto-created per step, so you rarely list prompts here.'),
|
|
520
|
+
steps: z.array(recipeStep).min(1).describe('The pipeline in order. Each step pins a preset; media output flows into the next step automatically, and a subject input seeds a reference port.'),
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
server.registerTool('list_recipe_blocks',
|
|
524
|
+
{ title: 'List recipe blocks', description: 'The building blocks for authoring a recipe: entry points (create-image/video, edit-image, upscale) and every preset usable as a step, each with its port contract (inputs it needs, what it produces, which entry points it fits). Call this before compose_recipe to choose presets.', inputSchema: {} },
|
|
525
|
+
wrap(() => client.listRecipeBlocks()));
|
|
526
|
+
|
|
527
|
+
server.registerTool('compose_recipe',
|
|
528
|
+
{ title: 'Compose a recipe', description: 'Author a new recipe from a high-level spec and save it as a draft. You give an ordered list of steps (each pinned to a preset from list_recipe_blocks) plus any extra inputs; SimpliGen auto-wires the ports, media chain, and per-step prompt inputs and validates it. Returns { recipeId, valid, errors }. Anyone can compose; publishing later needs a connected account.', inputSchema: { spec: recipeSpec } },
|
|
529
|
+
wrap(({ spec }) => client.composeRecipe({ spec })));
|
|
530
|
+
|
|
531
|
+
server.registerTool('validate_recipe',
|
|
532
|
+
{ title: 'Validate a recipe', description: 'Dry-run without saving: pass a `spec` to compose+validate it, or a `config` to validate an existing recipe config. Returns precise errors (unbound ports, missing presets, type mismatches, cycles) to fix before compose_recipe.', inputSchema: { spec: recipeSpec.optional(), config: z.record(z.any()).optional() } },
|
|
533
|
+
wrap((args) => client.validateRecipe(args)));
|
|
534
|
+
|
|
535
|
+
server.registerTool('list_recipes',
|
|
536
|
+
{ title: 'List recipes', description: 'List every recipe on this device: the ones installed from the Store into UGC Studio / Product Studio (category ugc | product) and drafts authored here. Each entry carries its `inputs` (key, kind, label, required, options) so you know what run_recipe needs: a `subject` input takes a character id from list_characters (or a product id), image/video/audio inputs take upload_file handles, text/select/number inputs take plain values.', inputSchema: {} },
|
|
537
|
+
wrap(() => client.listRecipes()));
|
|
538
|
+
|
|
539
|
+
// --- Running an installed recipe (what drives the UGC + Product Studios) ---
|
|
540
|
+
|
|
541
|
+
server.registerTool('run_recipe',
|
|
542
|
+
{
|
|
543
|
+
title: 'Run a recipe',
|
|
544
|
+
description: 'Run an installed recipe (from list_recipes) with its inputs filled: the same multi-step pipeline UGC Studio / Product Studio runs when a person clicks Generate, so results land in the Gallery grouped the same way. `inputs` is keyed by input key; a subject input takes a character/product id, media inputs take upload_file handles. engine: local (default when every step is installed) | cloud | auto. Returns a runId; poll with wait_for_recipe_run or get_recipe_run. Cloud runs are priced up front and count against this agent\'s spend cap.' + APPROVAL_NOTE,
|
|
545
|
+
inputSchema: {
|
|
546
|
+
id: z.string().describe('Recipe id from list_recipes'),
|
|
547
|
+
inputs: z.record(z.any()).describe('Input values keyed by the recipe\'s input keys (see list_recipes -> inputs).'),
|
|
548
|
+
engine: z.enum(['local', 'cloud', 'auto']).optional().describe('Where the steps render. auto = local if every step is installed, else cloud when connected.'),
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
wrap(({ id, inputs, engine }) => client.runRecipe(id, { inputs: inputs || {}, ...(engine ? { engine } : {}) })));
|
|
552
|
+
|
|
553
|
+
server.registerTool('get_recipe_run',
|
|
554
|
+
{ title: 'Get a recipe run', description: 'Status of a recipe run: overall status (running | completed | failed | cancelled), each step with its status and resultPath, and resultPath = the final output once done.', inputSchema: { runId: z.string().describe('Run id from run_recipe') } },
|
|
555
|
+
wrap(({ runId }) => client.getRecipeRun(runId)));
|
|
556
|
+
|
|
557
|
+
server.registerTool('wait_for_recipe_run',
|
|
558
|
+
{ title: 'Wait for a recipe run', description: 'Block until a recipe run completes, fails, is cancelled, or the timeout passes. Returns the final run (resultPath when completed). Multi-step video recipes can take several minutes; call again if it returns timeout_still_running.', inputSchema: { runId: z.string(), timeoutSeconds: z.number().optional(), pollMs: z.number().optional() } },
|
|
559
|
+
wrap(async ({ runId, timeoutSeconds = 600, pollMs = 3000 }) => {
|
|
560
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
561
|
+
// eslint-disable-next-line no-constant-condition
|
|
562
|
+
while (true) {
|
|
563
|
+
const { run } = await client.getRecipeRun(runId);
|
|
564
|
+
if (run && ['completed', 'failed', 'cancelled'].includes(run.status)) return { run };
|
|
565
|
+
if (Date.now() >= deadline) return { run, note: 'timeout_still_running' };
|
|
566
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
567
|
+
}
|
|
568
|
+
}));
|
|
569
|
+
|
|
570
|
+
server.registerTool('list_recipe_runs',
|
|
571
|
+
{ title: 'List recipe runs', description: 'Recent runs of a recipe (newest first) with their status and results.', inputSchema: { id: z.string().describe('Recipe id') } },
|
|
572
|
+
wrap(({ id }) => client.listRecipeRuns(id)));
|
|
573
|
+
|
|
574
|
+
// --- Products + subjects: what a recipe's `subject` inputs take ---
|
|
575
|
+
|
|
576
|
+
server.registerTool('list_subjects',
|
|
577
|
+
{ title: 'List subjects', description: 'Every subject a recipe\'s `subject` input can take: characters and products (id, type, name). Use a character id from list_characters or a product id from list_products / create_product.', inputSchema: {} },
|
|
578
|
+
wrap(() => client.listSubjects()));
|
|
579
|
+
|
|
580
|
+
server.registerTool('list_products',
|
|
581
|
+
{ title: 'List products', description: 'The products saved on this device (a product = a named thing with a base photo, used by Product Studio and UGC recipes).', inputSchema: {} },
|
|
582
|
+
wrap(() => client.listProducts()));
|
|
583
|
+
|
|
584
|
+
server.registerTool('create_product',
|
|
585
|
+
{
|
|
586
|
+
title: 'Create a product',
|
|
587
|
+
description: 'Save a product from a photo so recipes can use it: upload the photo with upload_file first, then pass its handle. The description and category are woven into recipe prompts, so describe what it is and how it looks. Returns the productId to pass as a `subject` input in run_recipe.',
|
|
588
|
+
inputSchema: {
|
|
589
|
+
name: z.string().describe('Product name shown in the app'),
|
|
590
|
+
image: z.string().describe('upload_file handle of the product photo (clean, well-lit, product centred)'),
|
|
591
|
+
description: z.string().optional().describe('What it is and looks like, e.g. "a matte black ceramic coffee mug with a wooden lid"'),
|
|
592
|
+
category: z.string().optional().describe('e.g. skincare | beverage | electronics'),
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
wrap(({ name, image, description, category }) => client.createProduct({ name, image, description, category })));
|
|
596
|
+
|
|
597
|
+
server.registerTool('remove_product',
|
|
598
|
+
{ title: 'Remove a product', description: 'Delete a product and its photo from this device.' + APPROVAL_NOTE, inputSchema: { id: z.string() } },
|
|
599
|
+
wrap(({ id }) => client.removeProduct(id)));
|
|
600
|
+
|
|
601
|
+
// ---- The Video Studio (TASK-1310) ---------------------------------------------
|
|
602
|
+
// A film is a timeline of clips (shots to render) over audio tracks. Clips are named by
|
|
603
|
+
// id, by name, or by number (their order on the timeline, earliest first). Times are
|
|
604
|
+
// seconds, or bars once the film has a tempo: a position is { bar } (bar 1 is the
|
|
605
|
+
// first downbeat) and a length is { bars }. Every editing tool answers the film's
|
|
606
|
+
// timeline after the change; with the film open in the studio the change shows live.
|
|
607
|
+
const num = z.preprocess((v) => (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v)) ? Number(v) : v), z.number());
|
|
608
|
+
// null from an agent means "leave it": drop these keys before forwarding.
|
|
609
|
+
const dropNull = (o, keys) => Object.fromEntries(Object.entries(o).filter(([k, v]) => !(keys.includes(k) && v === null)));
|
|
610
|
+
const at = z.union([num, z.object({ seconds: num }), z.object({ bar: num })])
|
|
611
|
+
.describe('A moment: seconds (3, or { "seconds": 3 }), or { "bar": 5 } once the film has a tempo (bar 1 is the first downbeat; 5.5 is halfway through bar 5).');
|
|
612
|
+
const length = z.union([num, z.object({ seconds: num }), z.object({ bars: num })])
|
|
613
|
+
.describe('A length: seconds (5, or { "seconds": 5 }), or { "bars": 2 } once the film has a tempo.');
|
|
614
|
+
const trimIn = length.describe('Where the clip starts inside its take: seconds or { bars }, 0 for the start of the take.');
|
|
615
|
+
const filmId = z.string().describe('Film id from list_films or create_film');
|
|
616
|
+
const clipRef = z.union([z.string(), z.number()]).describe('A clip: its id, its name, or its number on the timeline (1 is the earliest).');
|
|
617
|
+
const trackRef = z.string().describe('A track: its name, its lane id, or the id of one piece of audio on it.');
|
|
618
|
+
const shot = z.object({
|
|
619
|
+
prompt: z.string().optional().describe('What the shot shows. Name cast members with @name, e.g. "@Kai looks over the city".'),
|
|
620
|
+
seconds: num.optional().describe('How long the shot runs. Shots without seconds share what is left of the clip.'),
|
|
621
|
+
line: z.string().optional().describe('A spoken or sung line in this shot.'),
|
|
622
|
+
speaker: z.string().optional().describe('Who says or sings the line: a cast member\'s name.'),
|
|
623
|
+
framing: z.string().optional().describe('wide, medium, close-up or extreme close-up.'),
|
|
624
|
+
});
|
|
625
|
+
const shots = z.array(shot).describe('The clip\'s shots in order. Replaces the shots it had.');
|
|
626
|
+
const people = z.array(z.string()).describe('Characters by name or id (make them with create_character). As many as the preset holds: eight on MiniMax H3, up to four on the LTX cast presets. A cast too big for its preset moves the clip to an installed preset that holds it; only a cast no installed preset holds is refused.');
|
|
627
|
+
|
|
628
|
+
server.registerTool('list_films',
|
|
629
|
+
{ title: 'List films', description: 'The Video Studio films of a project (default: the current one): id, title, number of clips. The film tools need the Video Studio in SimpliGen; without it they answer studio_not_installed.', inputSchema: { projectId: z.string().optional() } },
|
|
630
|
+
wrap(({ projectId }) => client.listFilms(projectId)));
|
|
631
|
+
|
|
632
|
+
server.registerTool('create_film',
|
|
633
|
+
{ title: 'Create a film', description: 'Create an empty Video Studio film and answer its timeline. Shape 16:9, 9:16 or 1:1; resolution 480p, 720p or 1080p; renders on this PC (local) or in the cloud. Presets per kind of shot default to the studio\'s own choice.', inputSchema: {
|
|
634
|
+
name: z.string(), projectId: z.string().optional(),
|
|
635
|
+
aspect: z.enum(['16:9', '9:16', '1:1']).optional(), quality: z.enum(['480p', '720p', '1080p']).optional(),
|
|
636
|
+
renderOn: z.enum(['local', 'cloud']).optional(),
|
|
637
|
+
presets: z.object({ t2v: z.string().optional(), i2v: z.string().optional(), r2v: z.string().optional() }).optional().describe('Film presets per kind of shot (pack:preset ids from list_capabilities).'),
|
|
638
|
+
} },
|
|
639
|
+
wrap((a) => client.createFilm(a)));
|
|
640
|
+
|
|
641
|
+
server.registerTool('get_film',
|
|
642
|
+
{ title: 'Get a film', description: 'The film\'s timeline: tempo, cast, every clip (number, name, start and length in seconds and bars, shots, how it starts, its take: none, rendering, current, edited, longer, unknown when it cannot be told yet, or imported for a video brought in and never rendered), tracks, the video lanes above the main row (videoLanes: id and name), markers, the export range, and rendersRunning: true while a render batch is still going on the film (also between the takes of clips that continue from each other, when no clip reads as rendering).', inputSchema: { filmId } },
|
|
643
|
+
wrap(({ filmId: id }) => client.getFilm(id)));
|
|
644
|
+
|
|
645
|
+
server.registerTool('update_film_settings',
|
|
646
|
+
{ title: 'Update film settings', description: 'Change the film\'s shape, resolution, where it renders, presets, Subject & style, and the cast and location every clip inherits.', inputSchema: {
|
|
647
|
+
filmId, aspect: z.enum(['16:9', '9:16', '1:1']).optional(), quality: z.enum(['480p', '720p', '1080p']).optional(),
|
|
648
|
+
hires2x: z.boolean().optional(), renderOn: z.enum(['local', 'cloud']).optional(),
|
|
649
|
+
presets: z.object({ t2v: z.string().optional(), i2v: z.string().optional(), r2v: z.string().optional() }).optional(),
|
|
650
|
+
subject: z.string().optional(), cast: people.optional(), location: z.string().nullable().optional().describe('A location by name or id; null for none.'),
|
|
651
|
+
} },
|
|
652
|
+
wrap(({ filmId: id, ...rest }) => client.updateFilmSettings(id, rest)));
|
|
653
|
+
|
|
654
|
+
server.registerTool('add_track',
|
|
655
|
+
{ title: 'Add a track', description: 'Put an audio file on the film\'s timeline as a new track. Upload it first with upload_file and pass the handle. kind: singing (vocals, drive lip sync), music, dialogue or effects; guessed from the file name when left out.', inputSchema: {
|
|
656
|
+
filmId, upload: z.string().describe('Handle from upload_file'), name: z.string().optional(),
|
|
657
|
+
kind: z.enum(['singing', 'music', 'dialogue', 'effects']).optional(), at: at.optional(),
|
|
658
|
+
} },
|
|
659
|
+
wrap(({ filmId: id, ...rest }) => client.addTrack(id, rest)));
|
|
660
|
+
|
|
661
|
+
server.registerTool('move_track',
|
|
662
|
+
{ title: 'Move a track', description: 'Move a track\'s audio to a new start, mute or unmute it, or set its volume (0 to 1).', inputSchema: {
|
|
663
|
+
filmId, track: trackRef, at: at.optional(), muted: z.boolean().optional(), volume: num.optional(),
|
|
664
|
+
} },
|
|
665
|
+
wrap(({ filmId: id, track, ...rest }) => client.moveTrack(id, track, rest)));
|
|
666
|
+
|
|
667
|
+
server.registerTool('detect_tempo',
|
|
668
|
+
{ title: 'Detect tempo', description: 'Listen to the longest unmuted track (or the one named) and set the film\'s tempo and bar lines from it. Answers the bpm. After this, times can be given in bars.', inputSchema: { filmId, track: trackRef.optional() } },
|
|
669
|
+
wrap(({ filmId: id, track }) => client.detectTempo(id, track ? { track } : {})));
|
|
670
|
+
|
|
671
|
+
server.registerTool('add_clip',
|
|
672
|
+
{ title: 'Add a clip', description: 'Add an empty clip (a shot to render). Starts after the last clip unless `at` is given; length defaults to the model\'s shortest. Write its shots with update_clip.', inputSchema: {
|
|
673
|
+
filmId, at: at.optional(), length: length.optional(), name: z.string().optional(), lane: z.string().optional().describe('A video lane above the main row, by id or name (get_film lists them in videoLanes); leave out for the main row.'),
|
|
674
|
+
} },
|
|
675
|
+
wrap(({ filmId: id, ...rest }) => client.addClip(id, rest)));
|
|
676
|
+
|
|
677
|
+
server.registerTool('import_clip',
|
|
678
|
+
{ title: 'Import a video as a clip', description: 'Put a finished video the user already has (a job from list_jobs or get_job, made anywhere in SimpliGen) on the timeline as a clip, exactly as it is: it plays, trims and exports, and is never re-rendered. Starts after the last clip unless `at` is given; length defaults to the video\'s own. Use this for an approved shot instead of rendering it again.', inputSchema: {
|
|
679
|
+
filmId, generationId: z.string().describe('The finished video\'s job id (jobId from list_jobs or get_job).'),
|
|
680
|
+
at: at.optional(), length: length.optional(), name: z.string().optional(), lane: z.string().optional().describe('A video lane above the main row, by id or name (get_film lists them in videoLanes); leave out for the main row.'),
|
|
681
|
+
} },
|
|
682
|
+
wrap(({ filmId: id, ...rest }) => client.importClip(id, rest)));
|
|
683
|
+
|
|
684
|
+
server.registerTool('update_clip',
|
|
685
|
+
{ title: 'Update a clip', description: 'Write a clip in one step: its shots, who is in it (cast: as many people as its preset holds) and where (location: a name or id, "none" to drop the film\'s, "film" to inherit it again), how it starts (link: fresh, continue from the clip before, or motion, which needs LTX 2.5 on both clips, with no cast and no last frame, and is refused otherwise), which tracks it hears, and its preset.', inputSchema: {
|
|
686
|
+
filmId, clip: clipRef, shots: shots.optional(), cast: people.optional(),
|
|
687
|
+
location: z.string().optional(), link: z.enum(['fresh', 'continue', 'motion', 'none', 'frame']).optional(),
|
|
688
|
+
hears: z.array(z.object({ track: trackRef, on: z.boolean() })).optional().describe('Which tracks the clip\'s render hears, e.g. [{ "track": "Song", "on": false }].'),
|
|
689
|
+
preset: z.string().nullable().optional().describe('This clip\'s own preset (pack:preset); null to follow the film.'),
|
|
690
|
+
} },
|
|
691
|
+
wrap(({ filmId: id, clip, ...rest }) => client.updateClip(id, clip, rest)));
|
|
692
|
+
|
|
693
|
+
server.registerTool('move_clip',
|
|
694
|
+
{ title: 'Move a clip', description: 'Move a clip to a new start, or to another video lane (leave `at` out to keep its start).', inputSchema: { filmId, clip: clipRef, at: at.nullable().optional(), lane: z.string().nullable().optional().describe('A video lane by id or name (videoLanes in get_film).') } },
|
|
695
|
+
wrap(({ filmId: id, clip, ...rest }) => client.moveClip(id, clip, dropNull(rest, ['at']))));
|
|
696
|
+
|
|
697
|
+
server.registerTool('trim_clip',
|
|
698
|
+
{ title: 'Trim a clip', description: 'Change a clip\'s length on the timeline, or where it starts inside its take (trimIn; 0 resets to the start of the take; leaving it out keeps it).', inputSchema: { filmId, clip: clipRef, length: length.nullable().optional(), trimIn: trimIn.nullable().optional() } },
|
|
699
|
+
wrap(({ filmId: id, clip, ...rest }) => client.trimClip(id, clip, dropNull(rest, ['length', 'trimIn']))));
|
|
700
|
+
|
|
701
|
+
server.registerTool('remove_clip',
|
|
702
|
+
{ title: 'Remove a clip', description: 'Remove a clip from the timeline (and the audio lifted off its renders). With the film open, Ctrl+Z brings it back.', inputSchema: { filmId, clip: clipRef } },
|
|
703
|
+
wrap(({ filmId: id, clip }) => client.removeClip(id, clip)));
|
|
704
|
+
|
|
705
|
+
server.registerTool('apply_film_plan',
|
|
706
|
+
{ title: 'Lay out a film', description: 'Lay out a whole draft in one step: clips on the bars, each with its shots, cast, location and how it starts. Checked as a whole first: every problem comes back at once (invalid_plan with a problems list) and nothing changes unless all of it is valid. mode append (default) adds after the last clip; replace replaces every clip (refused when clips have takes unless discardTakes is true). Clips start at the first downbeat when the film has a tempo and no clips.', inputSchema: {
|
|
707
|
+
filmId, mode: z.enum(['append', 'replace']).optional(), discardTakes: z.boolean().optional(),
|
|
708
|
+
start: at.optional(), cast: people.optional(), location: z.string().optional(),
|
|
709
|
+
clips: z.array(z.object({
|
|
710
|
+
bars: num.optional(), seconds: num.optional(), name: z.string().optional(),
|
|
711
|
+
link: z.enum(['fresh', 'continue', 'motion', 'none', 'frame']).optional(), cast: people.optional(), location: z.string().optional(),
|
|
712
|
+
shots,
|
|
713
|
+
})).describe('The clips in order. Each has bars or seconds, and its shots.'),
|
|
714
|
+
} },
|
|
715
|
+
wrap(({ filmId: id, ...plan }) => client.applyFilmPlan(id, plan)));
|
|
716
|
+
|
|
717
|
+
server.registerTool('set_fades',
|
|
718
|
+
{ title: 'Set fades', description: 'Fade a clip or a track in and out, in seconds.', inputSchema: { filmId, target: z.union([z.string(), z.number()]).describe('A clip (id, name or number) or a track (name or id).'), fadeIn: num.optional(), fadeOut: num.optional() } },
|
|
719
|
+
wrap(({ filmId: id, ...rest }) => client.setFades(id, rest)));
|
|
720
|
+
|
|
721
|
+
server.registerTool('add_marker',
|
|
722
|
+
{ title: 'Add a marker', description: 'Put a named marker on the ruler.', inputSchema: { filmId, at, name: z.string().optional() } },
|
|
723
|
+
wrap(({ filmId: id, ...rest }) => client.addMarker(id, rest)));
|
|
724
|
+
|
|
725
|
+
server.registerTool('set_export_range',
|
|
726
|
+
{ title: 'Set the export range', description: 'Export only from one moment to another, or (clear: true) the whole film. Both `from` and `to` are needed unless `clear` is true.', inputSchema: { filmId, from: at.optional(), to: at.optional(), clear: z.boolean().optional() } },
|
|
727
|
+
wrap(({ filmId: id, ...rest }) => client.setExportRange(id, rest)));
|
|
728
|
+
|
|
729
|
+
server.registerTool('render_clips',
|
|
730
|
+
{ title: 'Render clips', description: 'Render the clips that need it (default) or the clips named. Clips that continue from the clip before render one at a time, each after the take it starts from. Answers once the batch is under way (for clips that do not continue from each other, after queueing them all) with what started, what is held and why, and the cost in the cloud (counted against this agent\'s spend cap). Refused, with nothing started, as exceeds_balance (the cloud balance does not cover it), exceeds_spend_cap (over this agent\'s spend cap) or cost_unknown (the cloud cost is not known yet; try again in a minute). Follow progress with wait_for_renders or get_film.' + APPROVAL_NOTE, inputSchema: {
|
|
731
|
+
filmId, clips: z.union([z.literal('stale'), z.array(clipRef)]).optional().describe('"stale" (default): every clip whose take is missing or out of date; or a list of clips.'),
|
|
732
|
+
} },
|
|
733
|
+
wrap(({ filmId: id, clips }) => client.renderClips(id, clips === undefined ? {} : { clips })));
|
|
734
|
+
|
|
735
|
+
server.registerTool('wait_for_renders',
|
|
736
|
+
{ title: 'Wait for renders', description: 'Wait until no clip of the film is rendering and no render batch is running on it, or the timeout passes, then answer the timeline. Renders take minutes each; call again if it answers timeout_still_running.', inputSchema: { filmId, timeoutSeconds: num.optional(), pollMs: num.optional() } },
|
|
737
|
+
wrap(async ({ filmId: id, timeoutSeconds = 600, pollMs = 10000 }) => {
|
|
738
|
+
pollMs = Math.max(250, pollMs);
|
|
739
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
740
|
+
for (;;) {
|
|
741
|
+
const timeline = await client.getFilm(id);
|
|
742
|
+
const rendering = (timeline.clips || []).filter((c) => c.take === 'rendering').map((c) => c.number);
|
|
743
|
+
// A linked chain is between takes for a while (nothing reads as rendering): it is
|
|
744
|
+
// not done until the batch says so.
|
|
745
|
+
if (!rendering.length && !timeline.rendersRunning) return { timeline };
|
|
746
|
+
if (Date.now() >= deadline) return { timeline, rendering, note: 'timeout_still_running' };
|
|
747
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
748
|
+
}
|
|
749
|
+
}));
|
|
750
|
+
|
|
751
|
+
server.registerTool('list_takes',
|
|
752
|
+
{ title: 'List takes', description: 'Every render of a clip, newest first, numbered, and which one the clip shows.', inputSchema: { filmId, clip: clipRef } },
|
|
753
|
+
wrap(({ filmId: id, clip }) => client.listTakes(id, clip)));
|
|
754
|
+
|
|
755
|
+
server.registerTool('use_take',
|
|
756
|
+
{ title: 'Use a take', description: 'Make one of a clip\'s takes (from list_takes) the one it shows.', inputSchema: { filmId, clip: clipRef, generationId: z.string() } },
|
|
757
|
+
wrap(({ filmId: id, clip, generationId }) => client.useTake(id, clip, generationId)));
|
|
758
|
+
|
|
759
|
+
server.registerTool('export_film',
|
|
760
|
+
{ title: 'Export a film', description: 'Stitch the film (or its export range) into one video with its music, and answer the file path. A long film can take several minutes. Refused with clips_not_ready while clips still need a render; a clip that cannot render at all comes out black and is named in `blanks`.' + APPROVAL_NOTE, inputSchema: { filmId } },
|
|
761
|
+
wrap(({ filmId: id }) => client.exportFilm(id)));
|
|
762
|
+
|
|
763
|
+
server.registerTool('list_locations',
|
|
764
|
+
{ title: 'List locations', description: 'The Library\'s locations (places a cast can stand in): id, name, description, whether it has its picture.', inputSchema: {} },
|
|
765
|
+
wrap(() => client.listLocations()));
|
|
766
|
+
|
|
767
|
+
server.registerTool('create_location',
|
|
768
|
+
{ title: 'Create a location', description: 'Save a location from its picture: an uploaded image (upload, from upload_file) or a finished image job (fromJob, e.g. a generate job you waited for). To make a new place, generate its picture with generate, wait_for_result, then create_location with fromJob.', inputSchema: {
|
|
769
|
+
name: z.string(), description: z.string().optional(), upload: z.string().optional(), fromJob: z.string().optional(),
|
|
770
|
+
} },
|
|
771
|
+
wrap((a) => client.createLocation(a)));
|
|
772
|
+
|
|
773
|
+
server.registerTool('cancel_recipe_run',
|
|
774
|
+
{ title: 'Cancel a recipe run', description: 'Stop a running recipe: no further steps start; a local in-flight step is interrupted (a cloud step already running finishes server-side and is saved).', inputSchema: { runId: z.string() } },
|
|
775
|
+
wrap(({ runId }) => client.cancelRecipeRun(runId)));
|
|
776
|
+
|
|
777
|
+
server.registerTool('get_recipe',
|
|
778
|
+
{ title: 'Get a recipe', description: 'Get a saved recipe and its full config by id.', inputSchema: { id: z.string().describe('Recipe id from compose_recipe or list_recipes') } },
|
|
779
|
+
wrap(({ id }) => client.getRecipe(id)));
|
|
780
|
+
|
|
781
|
+
server.registerTool('publish_recipe',
|
|
782
|
+
{ title: 'Publish a recipe', description: 'Submit a saved recipe to the SimpliGen Creator Marketplace (queued for human review). Requires a connected account: if none, returns not_connected and the user connects once in Settings, then this succeeds on the same recipe. priceTokens sets an optional one-time price (0 or omitted = free). Every preset the recipe uses must be a distributable first-party pack.' + APPROVAL_NOTE, inputSchema: { id: z.string().describe('Recipe id to publish'), changelog: z.string().optional(), priceTokens: z.number().optional().describe('One-time price in tokens (0/omitted = free).') } },
|
|
783
|
+
wrap(({ id, changelog, priceTokens }) => client.publishRecipe(id, { changelog, priceTokens })));
|
|
784
|
+
}
|