@simpligen/mcp 0.4.2 → 0.5.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 +2 -0
- package/package.json +1 -1
- package/src/bin.js +4 -1
- package/src/client.js +165 -98
- package/src/index.js +2 -1
- package/src/server.js +18 -3
- package/src/studioGate.js +51 -0
- package/src/tools.js +179 -2
package/README.md
CHANGED
|
@@ -22,6 +22,8 @@ The easiest path is in the SimpliGen app: **Settings -> Connect an agent**, pick
|
|
|
22
22
|
|
|
23
23
|
`list_capabilities`, `get_status`, `list_projects`, `create_project`, `upload_file`, `generate`, `get_job`, `wait_for_result`, `list_jobs`, `cancel_job`, `prepare_preset`, `get_result_image`.
|
|
24
24
|
|
|
25
|
+
**Video Studio** (connector 0.5.0 or newer): `list_films`, `create_film`, `get_film`, `update_film_settings`, `add_track`, `move_track`, `detect_tempo`, `add_clip`, `update_clip`, `move_clip`, `trim_clip`, `remove_clip`, `apply_film_plan`, `set_fades`, `add_marker`, `set_export_range`, `render_clips`, `wait_for_renders`, `list_takes`, `use_take`, `export_film`, `list_locations`, `create_location`. An agent can build a whole music video: a song, its tempo, clips on the bars, shots, renders and the export. With the film open in the Video Studio every change shows live and undoes with Ctrl+Z. These tools are listed only when your SimpliGen has the Video Studio (connector 0.5.1 or newer, SimpliGen 1.75 or newer). If the agent starts before SimpliGen is running, they appear within a minute of SimpliGen starting; an agent app that does not refresh its tool list shows them after a restart.
|
|
26
|
+
|
|
25
27
|
`get_result_image` returns a completed job's result image inline (a viewable image block) so the agent can display it in chat. Claude clients cap a tool result at ~1MB and only render base64 image blocks, so large renders are re-encoded to a **full-resolution WebP** preview (same dimensions; quality steps down, and only very large images are resized) that fits the cap. The uncompressed original file path is always included in the caption, so the agent keeps the full-quality artifact. Video results return the file path instead.
|
|
26
28
|
|
|
27
29
|
## Env
|
package/package.json
CHANGED
package/src/bin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
// packages/mcp-server/src/bin.js
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { ControlApiClient } from './client.js';
|
|
@@ -7,6 +7,9 @@ import { createMcpServer } from './server.js';
|
|
|
7
7
|
async function main() {
|
|
8
8
|
const client = new ControlApiClient(); // resolves port (discovery file) + token (SIMPLIGEN_TOKEN)
|
|
9
9
|
const server = createMcpServer(client);
|
|
10
|
+
// Whether the app holds the Video Studio decides which tools the client first sees.
|
|
11
|
+
// A closed app answers at once; a stuck one gets 3 s, then the poll takes over.
|
|
12
|
+
await Promise.race([server.studioGate.refresh(), new Promise((r) => setTimeout(r, 3000).unref())]);
|
|
10
13
|
await server.connect(new StdioServerTransport());
|
|
11
14
|
}
|
|
12
15
|
|
package/src/client.js
CHANGED
|
@@ -1,98 +1,165 @@
|
|
|
1
|
-
// packages/mcp-server/src/client.js
|
|
2
|
-
// Thin client over the SimpliGen local control API. Resolves base URL + token,
|
|
3
|
-
// does authed fetch calls, throws a structured error on non-2xx.
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
// packages/mcp-server/src/client.js
|
|
2
|
+
// Thin client over the SimpliGen local control API. Resolves base URL + token,
|
|
3
|
+
// does authed fetch calls, throws a structured error on non-2xx.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import http from 'node:http';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { resolveUserDataDir, readDiscoveryPort } from './userdata.js';
|
|
8
|
+
|
|
9
|
+
export class ControlApiError extends Error {
|
|
10
|
+
constructor(status, errorCode, message) {
|
|
11
|
+
super(message || errorCode || `HTTP ${status}`);
|
|
12
|
+
this.name = 'ControlApiError';
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.errorCode = errorCode || null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// A film export may run for up to 20 minutes on the app's side. fetch (undici) gives up
|
|
19
|
+
// waiting for the response headers after 5 minutes, so the export goes over node:http
|
|
20
|
+
// with a socket timeout just past the route's own limit.
|
|
21
|
+
export const LONG_REQUEST_TIMEOUT_MS = 21 * 60 * 1000;
|
|
22
|
+
|
|
23
|
+
export class ControlApiClient {
|
|
24
|
+
// opts: { baseUrl?, token?, fetchImpl?, env? }. Falls back to discovery file + env.
|
|
25
|
+
constructor(opts = {}) {
|
|
26
|
+
const env = opts.env || process.env;
|
|
27
|
+
this.token = opts.token || env.SIMPLIGEN_TOKEN || null;
|
|
28
|
+
this.fetch = opts.fetchImpl || globalThis.fetch;
|
|
29
|
+
if (opts.baseUrl) {
|
|
30
|
+
this.baseUrl = opts.baseUrl;
|
|
31
|
+
} else {
|
|
32
|
+
const port = env.SIMPLIGEN_API_PORT ? Number(env.SIMPLIGEN_API_PORT) : readDiscoveryPort(resolveUserDataDir(env));
|
|
33
|
+
this.baseUrl = port ? `http://127.0.0.1:${port}` : null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async #req(method, p, body) {
|
|
38
|
+
this.#ready();
|
|
39
|
+
const res = await this.fetch(`${this.baseUrl}${p}`, {
|
|
40
|
+
method,
|
|
41
|
+
headers: { Authorization: `Bearer ${this.token}`, 'Content-Type': 'application/json' },
|
|
42
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
43
|
+
});
|
|
44
|
+
let json = {};
|
|
45
|
+
try { json = await res.json(); } catch { /* empty body */ }
|
|
46
|
+
if (!res.ok) throw new ControlApiError(res.status, json.errorCode, json.message);
|
|
47
|
+
return json;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#ready() {
|
|
51
|
+
if (!this.baseUrl) throw new ControlApiError(0, 'app_not_running', 'SimpliGen is not running (no control-API port found). Start the app.');
|
|
52
|
+
if (!this.token) throw new ControlApiError(0, 'missing_token', 'No pairing token. Set SIMPLIGEN_TOKEN (Settings -> Connect an agent).');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The same request as #req, over node:http with a long socket timeout (for an export). */
|
|
56
|
+
#longReq(method, p, body) {
|
|
57
|
+
this.#ready();
|
|
58
|
+
const data = body !== undefined ? JSON.stringify(body) : null;
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const req = http.request(new URL(p, this.baseUrl), {
|
|
61
|
+
method,
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Bearer ${this.token}`, 'Content-Type': 'application/json',
|
|
64
|
+
...(data !== null ? { 'Content-Length': Buffer.byteLength(data) } : {}),
|
|
65
|
+
},
|
|
66
|
+
timeout: LONG_REQUEST_TIMEOUT_MS,
|
|
67
|
+
}, (res) => {
|
|
68
|
+
let raw = '';
|
|
69
|
+
res.setEncoding('utf8');
|
|
70
|
+
res.on('data', (c) => { raw += c; });
|
|
71
|
+
res.on('error', reject);
|
|
72
|
+
res.on('end', () => {
|
|
73
|
+
let json = {};
|
|
74
|
+
try { json = raw ? JSON.parse(raw) : {}; } catch { /* not JSON */ }
|
|
75
|
+
if (res.statusCode < 200 || res.statusCode >= 300) reject(new ControlApiError(res.statusCode, json.errorCode, json.message));
|
|
76
|
+
else resolve(json);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
req.on('timeout', () => req.destroy(new ControlApiError(0, 'timeout', 'The app did not answer in time.')));
|
|
80
|
+
req.on('error', reject);
|
|
81
|
+
if (data !== null) req.write(data);
|
|
82
|
+
req.end();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getCapabilities() { return this.#req('GET', '/capabilities'); }
|
|
87
|
+
getStatus() { return this.#req('GET', '/status'); }
|
|
88
|
+
startEngine() { return this.#req('POST', '/engine/start'); }
|
|
89
|
+
stopEngine() { return this.#req('POST', '/engine/stop'); }
|
|
90
|
+
restartEngine() { return this.#req('POST', '/engine/restart'); }
|
|
91
|
+
listProjects() { return this.#req('GET', '/projects'); }
|
|
92
|
+
createProject(name) { return this.#req('POST', '/projects', { name }); }
|
|
93
|
+
listLoras() { return this.#req('GET', '/loras'); }
|
|
94
|
+
generate(args) { return this.#req('POST', '/generate', args); }
|
|
95
|
+
getJob(id) { return this.#req('GET', `/jobs/${encodeURIComponent(id)}`); }
|
|
96
|
+
listJobs() { return this.#req('GET', '/jobs'); }
|
|
97
|
+
cancelJob(id) { return this.#req('POST', `/jobs/${encodeURIComponent(id)}/cancel`, {}); }
|
|
98
|
+
preparePreset(args) { return this.#req('POST', '/presets/prepare', args); }
|
|
99
|
+
getActiveDownloads() { return this.#req('GET', '/presets/prepare'); }
|
|
100
|
+
|
|
101
|
+
listCharacters() { return this.#req('GET', '/characters'); }
|
|
102
|
+
getCharacter(id) { return this.#req('GET', `/characters/${encodeURIComponent(id)}`); }
|
|
103
|
+
listCharacterFeatures() { return this.#req('GET', '/character-features'); }
|
|
104
|
+
listCharacterPresets() { return this.#req('GET', '/character-presets'); }
|
|
105
|
+
createCharacter(args) { return this.#req('POST', '/characters', args); }
|
|
106
|
+
generateCharacterImage(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/generate-image`, args); }
|
|
107
|
+
generateCharacterFrame(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/generate-frame`, args); }
|
|
108
|
+
animateCharacter(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/animate`, args); }
|
|
109
|
+
acceptBase(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/accept-base`, args); }
|
|
110
|
+
setCharacterPreset(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/preset`, args); }
|
|
111
|
+
enhanceCharacterMedia(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/enhance`, args); }
|
|
112
|
+
regenerateCharacterBase(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/regenerate-base`, args); }
|
|
113
|
+
removeCharacter(id) { return this.#req('DELETE', `/characters/${encodeURIComponent(id)}`); }
|
|
114
|
+
|
|
115
|
+
listRecipeBlocks() { return this.#req('GET', '/recipe-blocks'); }
|
|
116
|
+
composeRecipe(args) { return this.#req('POST', '/recipes', args); }
|
|
117
|
+
validateRecipe(args) { return this.#req('POST', '/recipes/validate', args); }
|
|
118
|
+
listRecipes() { return this.#req('GET', '/recipes'); }
|
|
119
|
+
getRecipe(id) { return this.#req('GET', `/recipes/${encodeURIComponent(id)}`); }
|
|
120
|
+
publishRecipe(id, args) { return this.#req('POST', `/recipes/${encodeURIComponent(id)}/publish`, args); }
|
|
121
|
+
runRecipe(id, args) { return this.#req('POST', `/recipes/${encodeURIComponent(id)}/run`, args); }
|
|
122
|
+
listRecipeRuns(id) { return this.#req('GET', `/recipes/${encodeURIComponent(id)}/runs`); }
|
|
123
|
+
getRecipeRun(runId) { return this.#req('GET', `/recipe-runs/${encodeURIComponent(runId)}`); }
|
|
124
|
+
cancelRecipeRun(runId) { return this.#req('POST', `/recipe-runs/${encodeURIComponent(runId)}/cancel`, {}); }
|
|
125
|
+
listSubjects() { return this.#req('GET', '/subjects'); }
|
|
126
|
+
listProducts() { return this.#req('GET', '/products'); }
|
|
127
|
+
createProduct(args) { return this.#req('POST', '/products', args); }
|
|
128
|
+
removeProduct(id) { return this.#req('DELETE', `/products/${encodeURIComponent(id)}`); }
|
|
129
|
+
|
|
130
|
+
// The Video Studio (TASK-1310). Clips and tracks are named by id, name or number.
|
|
131
|
+
#film(filmId, rest = '') { return `/films/${encodeURIComponent(filmId)}${rest}`; }
|
|
132
|
+
#clip(filmId, clip, rest = '') { return this.#film(filmId, `/clips/${encodeURIComponent(String(clip))}${rest}`); }
|
|
133
|
+
listFilms(projectId) { return this.#req('GET', `/films${projectId ? `?projectId=${encodeURIComponent(projectId)}` : ''}`); }
|
|
134
|
+
createFilm(args) { return this.#req('POST', '/films', args); }
|
|
135
|
+
getFilm(filmId) { return this.#req('GET', this.#film(filmId)); }
|
|
136
|
+
updateFilmSettings(filmId, args) { return this.#req('PATCH', this.#film(filmId), args); }
|
|
137
|
+
addTrack(filmId, args) { return this.#req('POST', this.#film(filmId, '/tracks'), args); }
|
|
138
|
+
moveTrack(filmId, track, args) { return this.#req('PATCH', this.#film(filmId, `/tracks/${encodeURIComponent(String(track))}`), args); }
|
|
139
|
+
detectTempo(filmId, args = {}) { return this.#req('POST', this.#film(filmId, '/tempo'), args); }
|
|
140
|
+
addClip(filmId, args = {}) { return this.#req('POST', this.#film(filmId, '/clips'), args); }
|
|
141
|
+
updateClip(filmId, clip, args) { return this.#req('PATCH', this.#clip(filmId, clip), args); }
|
|
142
|
+
moveClip(filmId, clip, args) { return this.#req('POST', this.#clip(filmId, clip, '/move'), args); }
|
|
143
|
+
trimClip(filmId, clip, args) { return this.#req('POST', this.#clip(filmId, clip, '/trim'), args); }
|
|
144
|
+
removeClip(filmId, clip) { return this.#req('DELETE', this.#clip(filmId, clip)); }
|
|
145
|
+
applyFilmPlan(filmId, plan) { return this.#req('POST', this.#film(filmId, '/plan'), plan); }
|
|
146
|
+
setFades(filmId, args) { return this.#req('POST', this.#film(filmId, '/fades'), args); }
|
|
147
|
+
addMarker(filmId, args) { return this.#req('POST', this.#film(filmId, '/markers'), args); }
|
|
148
|
+
setExportRange(filmId, args) { return this.#req('POST', this.#film(filmId, '/export-range'), args); }
|
|
149
|
+
renderClips(filmId, args = {}) { return this.#req('POST', this.#film(filmId, '/renders'), args); }
|
|
150
|
+
listTakes(filmId, clip) { return this.#req('GET', this.#clip(filmId, clip, '/takes')); }
|
|
151
|
+
useTake(filmId, clip, generationId) { return this.#req('POST', this.#clip(filmId, clip, '/take'), { generationId }); }
|
|
152
|
+
exportFilm(filmId) { return this.#longReq('POST', this.#film(filmId, '/export'), {}); }
|
|
153
|
+
listLocations() { return this.#req('GET', '/locations'); }
|
|
154
|
+
createLocation(args) { return this.#req('POST', '/locations', args); }
|
|
155
|
+
|
|
156
|
+
async uploadFile(filePath) {
|
|
157
|
+
let buf;
|
|
158
|
+
try {
|
|
159
|
+
buf = fs.readFileSync(filePath);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
throw new ControlApiError(0, 'file_not_found', `Cannot read file to upload: ${filePath} (${e.code || e.message}).`);
|
|
162
|
+
}
|
|
163
|
+
return this.#req('POST', '/uploads', { filename: path.basename(filePath), dataBase64: buf.toString('base64') });
|
|
164
|
+
}
|
|
165
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// packages/mcp-server/src/index.js
|
|
2
2
|
export { ControlApiClient, ControlApiError } from './client.js';
|
|
3
3
|
export { createMcpServer } from './server.js';
|
|
4
|
-
export { registerTools, TOOL_NAMES } from './tools.js';
|
|
4
|
+
export { registerTools, TOOL_NAMES, STUDIO_TOOL_NAMES } from './tools.js';
|
|
5
|
+
export { createStudioGate } from './studioGate.js';
|
|
5
6
|
export { buildResultImageContent } from './resultImage.js';
|
|
6
7
|
export { resolveUserDataDir, readDiscoveryPort } from './userdata.js';
|
package/src/server.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
// packages/mcp-server/src/server.js
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
4
|
import { registerTools } from './tools.js';
|
|
5
|
+
import { createStudioGate } from './studioGate.js';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const { version } = createRequire(import.meta.url)('../package.json');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {object} client a ControlApiClient
|
|
11
|
+
* @param {{ studioPollMs?: number }} [options] how often to ask the app whether it holds the Video Studio
|
|
12
|
+
*/
|
|
13
|
+
export function createMcpServer(client, { studioPollMs } = {}) {
|
|
14
|
+
const server = new McpServer({ name: 'simpligen', version });
|
|
15
|
+
let gate = null;
|
|
16
|
+
const { studioTools } = registerTools(server, client, { onStatus: (status) => gate?.observe(status) });
|
|
17
|
+
gate = createStudioGate({ client, tools: studioTools, notify: () => server.sendToolListChanged(), pollMs: studioPollMs });
|
|
18
|
+
// The gate asks the app once a client is connected, and stops when it goes.
|
|
19
|
+
server.server.oninitialized = () => gate.start();
|
|
20
|
+
server.server.onclose = () => gate.stop();
|
|
21
|
+
// bin.js reads the status once before connecting, so the first tool list is already right.
|
|
22
|
+
server.studioGate = gate;
|
|
8
23
|
return server;
|
|
9
24
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// packages/mcp-server/src/studioGate.js
|
|
2
|
+
// The Video Studio tools are listed only to an agent whose SimpliGen holds the studio.
|
|
3
|
+
// Without it every film call is refused (studio_not_installed), so listing them only
|
|
4
|
+
// invites calls that cannot work. The app answers whether it holds the studio in
|
|
5
|
+
// /status (videoStudio.held, App 1.75.0 and newer); the gate reads that on start, every
|
|
6
|
+
// pollMs, and whenever the agent asks get_status, and tells the client when the set changes.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {{ client: { getStatus: () => Promise<object> },
|
|
10
|
+
* tools: Array<{ enabled: boolean }>,
|
|
11
|
+
* notify: () => void,
|
|
12
|
+
* pollMs?: number }} deps
|
|
13
|
+
*/
|
|
14
|
+
export function createStudioGate({ client, tools, notify, pollMs = 60_000 }) {
|
|
15
|
+
let held = false;
|
|
16
|
+
let timer = null;
|
|
17
|
+
// Hidden until the app says otherwise. Set directly so a client that is not connected
|
|
18
|
+
// yet is not told, and a whole switch is one notification, not one per tool.
|
|
19
|
+
for (const t of tools) t.enabled = false;
|
|
20
|
+
|
|
21
|
+
const apply = (next) => {
|
|
22
|
+
if (next === held) return;
|
|
23
|
+
held = next;
|
|
24
|
+
for (const t of tools) t.enabled = next;
|
|
25
|
+
notify();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Read one /status answer. An app that does not report the studio does not hold it. */
|
|
29
|
+
const observe = (status) => apply(status?.videoStudio?.held === true);
|
|
30
|
+
|
|
31
|
+
/** Ask the app. A failed read (the app closed for a moment) changes nothing. */
|
|
32
|
+
const refresh = async () => {
|
|
33
|
+
try { observe(await client.getStatus()); } catch { /* keep what we had */ }
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
observe,
|
|
38
|
+
refresh,
|
|
39
|
+
start() {
|
|
40
|
+
if (timer) return;
|
|
41
|
+
refresh();
|
|
42
|
+
timer = setInterval(refresh, pollMs);
|
|
43
|
+
timer.unref?.();
|
|
44
|
+
},
|
|
45
|
+
stop() {
|
|
46
|
+
clearInterval(timer);
|
|
47
|
+
timer = null;
|
|
48
|
+
},
|
|
49
|
+
get held() { return held; },
|
|
50
|
+
};
|
|
51
|
+
}
|
package/src/tools.js
CHANGED
|
@@ -17,20 +17,30 @@ export const TOOL_NAMES = [
|
|
|
17
17
|
'list_recipe_blocks', 'compose_recipe', 'validate_recipe', 'list_recipes', 'get_recipe', 'publish_recipe',
|
|
18
18
|
'run_recipe', 'get_recipe_run', 'wait_for_recipe_run', 'list_recipe_runs', 'cancel_recipe_run',
|
|
19
19
|
'list_subjects', 'list_products', 'create_product', 'remove_product',
|
|
20
|
+
'list_films', 'create_film', 'get_film', 'update_film_settings', 'add_track', 'move_track', 'detect_tempo',
|
|
21
|
+
'add_clip', 'update_clip', 'move_clip', 'trim_clip', 'remove_clip', 'apply_film_plan', 'set_fades', 'add_marker',
|
|
22
|
+
'set_export_range', 'render_clips', 'wait_for_renders', 'list_takes', 'use_take', 'export_film', 'list_locations', 'create_location',
|
|
20
23
|
];
|
|
21
24
|
|
|
25
|
+
// The tools that need the Video Studio. Listed only while the app holds it (studioGate.js).
|
|
26
|
+
export const STUDIO_TOOL_NAMES = TOOL_NAMES.slice(TOOL_NAMES.indexOf('list_films'));
|
|
27
|
+
|
|
22
28
|
const ok = (data) => ({ content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] });
|
|
23
29
|
const fail = (err) => ({ isError: true, content: [{ type: 'text', text: `${err.errorCode ? err.errorCode + ': ' : ''}${err.message || String(err)}` }] });
|
|
24
30
|
const wrap = (fn) => async (args) => { try { return ok(await fn(args)); } catch (e) { return fail(e); } };
|
|
25
31
|
|
|
26
|
-
export function registerTools(
|
|
32
|
+
export function registerTools(host, client, { onStatus } = {}) {
|
|
33
|
+
// Every tool's handle by name, so the studio's can be shown and hidden later.
|
|
34
|
+
const registered = {};
|
|
35
|
+
const server = { registerTool: (name, ...rest) => (registered[name] = host.registerTool(name, ...rest)) };
|
|
36
|
+
|
|
27
37
|
server.registerTool('list_capabilities',
|
|
28
38
|
{ 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: {} },
|
|
29
39
|
wrap(() => client.getCapabilities()));
|
|
30
40
|
|
|
31
41
|
server.registerTool('get_status',
|
|
32
42
|
{ title: 'Get status', description: 'Engine running state, whether cloud is connected, credit balance, and the active project.', inputSchema: {} },
|
|
33
|
-
wrap(() => client.getStatus()));
|
|
43
|
+
wrap(async () => { const status = await client.getStatus(); onStatus?.(status); return status; }));
|
|
34
44
|
|
|
35
45
|
// The engine's lifecycle. get_status could always report it was down and
|
|
36
46
|
// there was nothing an agent could do about it but ask the human to click
|
|
@@ -497,6 +507,171 @@ export function registerTools(server, client) {
|
|
|
497
507
|
{ title: 'Remove a product', description: 'Delete a product and its photo from this device.', inputSchema: { id: z.string() } },
|
|
498
508
|
wrap(({ id }) => client.removeProduct(id)));
|
|
499
509
|
|
|
510
|
+
// ---- The Video Studio (TASK-1310) ---------------------------------------------
|
|
511
|
+
// A film is a timeline of clips (shots to render) over audio tracks. Clips are named by
|
|
512
|
+
// id, by name, or by number (their order on the timeline, earliest first). Times are
|
|
513
|
+
// seconds, or bars once the film has a tempo: a position is { bar } (bar 1 is the
|
|
514
|
+
// first downbeat) and a length is { bars }. Every editing tool answers the film's
|
|
515
|
+
// timeline after the change; with the film open in the studio the change shows live.
|
|
516
|
+
const num = z.preprocess((v) => (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v)) ? Number(v) : v), z.number());
|
|
517
|
+
// null from an agent means "leave it": drop these keys before forwarding.
|
|
518
|
+
const dropNull = (o, keys) => Object.fromEntries(Object.entries(o).filter(([k, v]) => !(keys.includes(k) && v === null)));
|
|
519
|
+
const at = z.union([num, z.object({ seconds: num }), z.object({ bar: num })])
|
|
520
|
+
.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).');
|
|
521
|
+
const length = z.union([num, z.object({ seconds: num }), z.object({ bars: num })])
|
|
522
|
+
.describe('A length: seconds (5, or { "seconds": 5 }), or { "bars": 2 } once the film has a tempo.');
|
|
523
|
+
const trimIn = length.describe('Where the clip starts inside its take: seconds or { bars }, 0 for the start of the take.');
|
|
524
|
+
const filmId = z.string().describe('Film id from list_films or create_film');
|
|
525
|
+
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).');
|
|
526
|
+
const trackRef = z.string().describe('A track: its name, its lane id, or the id of one piece of audio on it.');
|
|
527
|
+
const shot = z.object({
|
|
528
|
+
prompt: z.string().optional().describe('What the shot shows. Name cast members with @name, e.g. "@Kai looks over the city".'),
|
|
529
|
+
seconds: num.optional().describe('How long the shot runs. Shots without seconds share what is left of the clip.'),
|
|
530
|
+
line: z.string().optional().describe('A spoken or sung line in this shot.'),
|
|
531
|
+
speaker: z.string().optional().describe('Who says or sings the line: a cast member\'s name.'),
|
|
532
|
+
framing: z.string().optional().describe('wide, medium, close-up or extreme close-up.'),
|
|
533
|
+
});
|
|
534
|
+
const shots = z.array(shot).describe('The clip\'s shots in order. Replaces the shots it had.');
|
|
535
|
+
const people = z.array(z.string()).describe('Characters by name or id (make them with create_character). At most two.');
|
|
536
|
+
|
|
537
|
+
server.registerTool('list_films',
|
|
538
|
+
{ title: 'List films', description: 'The Video Studio films of a project (default: the current one): id, title, number of clips.', inputSchema: { projectId: z.string().optional() } },
|
|
539
|
+
wrap(({ projectId }) => client.listFilms(projectId)));
|
|
540
|
+
|
|
541
|
+
server.registerTool('create_film',
|
|
542
|
+
{ 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: {
|
|
543
|
+
name: z.string(), projectId: z.string().optional(),
|
|
544
|
+
aspect: z.enum(['16:9', '9:16', '1:1']).optional(), quality: z.enum(['480p', '720p', '1080p']).optional(),
|
|
545
|
+
renderOn: z.enum(['local', 'cloud']).optional(),
|
|
546
|
+
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).'),
|
|
547
|
+
} },
|
|
548
|
+
wrap((a) => client.createFilm(a)));
|
|
549
|
+
|
|
550
|
+
server.registerTool('get_film',
|
|
551
|
+
{ 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 } },
|
|
552
|
+
wrap(({ filmId: id }) => client.getFilm(id)));
|
|
553
|
+
|
|
554
|
+
server.registerTool('update_film_settings',
|
|
555
|
+
{ 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: {
|
|
556
|
+
filmId, aspect: z.enum(['16:9', '9:16', '1:1']).optional(), quality: z.enum(['480p', '720p', '1080p']).optional(),
|
|
557
|
+
hires2x: z.boolean().optional(), renderOn: z.enum(['local', 'cloud']).optional(),
|
|
558
|
+
presets: z.object({ t2v: z.string().optional(), i2v: z.string().optional(), r2v: z.string().optional() }).optional(),
|
|
559
|
+
subject: z.string().optional(), cast: people.optional(), location: z.string().nullable().optional().describe('A location by name or id; null for none.'),
|
|
560
|
+
} },
|
|
561
|
+
wrap(({ filmId: id, ...rest }) => client.updateFilmSettings(id, rest)));
|
|
562
|
+
|
|
563
|
+
server.registerTool('add_track',
|
|
564
|
+
{ 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: {
|
|
565
|
+
filmId, upload: z.string().describe('Handle from upload_file'), name: z.string().optional(),
|
|
566
|
+
kind: z.enum(['singing', 'music', 'dialogue', 'effects']).optional(), at: at.optional(),
|
|
567
|
+
} },
|
|
568
|
+
wrap(({ filmId: id, ...rest }) => client.addTrack(id, rest)));
|
|
569
|
+
|
|
570
|
+
server.registerTool('move_track',
|
|
571
|
+
{ 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: {
|
|
572
|
+
filmId, track: trackRef, at: at.optional(), muted: z.boolean().optional(), volume: num.optional(),
|
|
573
|
+
} },
|
|
574
|
+
wrap(({ filmId: id, track, ...rest }) => client.moveTrack(id, track, rest)));
|
|
575
|
+
|
|
576
|
+
server.registerTool('detect_tempo',
|
|
577
|
+
{ 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() } },
|
|
578
|
+
wrap(({ filmId: id, track }) => client.detectTempo(id, track ? { track } : {})));
|
|
579
|
+
|
|
580
|
+
server.registerTool('add_clip',
|
|
581
|
+
{ 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: {
|
|
582
|
+
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.'),
|
|
583
|
+
} },
|
|
584
|
+
wrap(({ filmId: id, ...rest }) => client.addClip(id, rest)));
|
|
585
|
+
|
|
586
|
+
server.registerTool('update_clip',
|
|
587
|
+
{ title: 'Update a clip', description: 'Write a clip in one step: its shots, who is in it (cast, at most two people) 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 tracks it hears, and its preset.', inputSchema: {
|
|
588
|
+
filmId, clip: clipRef, shots: shots.optional(), cast: people.optional(),
|
|
589
|
+
location: z.string().optional(), link: z.enum(['fresh', 'continue', 'motion', 'none', 'frame']).optional(),
|
|
590
|
+
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 }].'),
|
|
591
|
+
preset: z.string().nullable().optional().describe('This clip\'s own preset (pack:preset); null to follow the film.'),
|
|
592
|
+
} },
|
|
593
|
+
wrap(({ filmId: id, clip, ...rest }) => client.updateClip(id, clip, rest)));
|
|
594
|
+
|
|
595
|
+
server.registerTool('move_clip',
|
|
596
|
+
{ 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).') } },
|
|
597
|
+
wrap(({ filmId: id, clip, ...rest }) => client.moveClip(id, clip, dropNull(rest, ['at']))));
|
|
598
|
+
|
|
599
|
+
server.registerTool('trim_clip',
|
|
600
|
+
{ 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() } },
|
|
601
|
+
wrap(({ filmId: id, clip, ...rest }) => client.trimClip(id, clip, dropNull(rest, ['length', 'trimIn']))));
|
|
602
|
+
|
|
603
|
+
server.registerTool('remove_clip',
|
|
604
|
+
{ 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 } },
|
|
605
|
+
wrap(({ filmId: id, clip }) => client.removeClip(id, clip)));
|
|
606
|
+
|
|
607
|
+
server.registerTool('apply_film_plan',
|
|
608
|
+
{ 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: {
|
|
609
|
+
filmId, mode: z.enum(['append', 'replace']).optional(), discardTakes: z.boolean().optional(),
|
|
610
|
+
start: at.optional(), cast: people.optional(), location: z.string().optional(),
|
|
611
|
+
clips: z.array(z.object({
|
|
612
|
+
bars: num.optional(), seconds: num.optional(), name: z.string().optional(),
|
|
613
|
+
link: z.enum(['fresh', 'continue', 'motion', 'none', 'frame']).optional(), cast: people.optional(), location: z.string().optional(),
|
|
614
|
+
shots,
|
|
615
|
+
})).describe('The clips in order. Each has bars or seconds, and its shots.'),
|
|
616
|
+
} },
|
|
617
|
+
wrap(({ filmId: id, ...plan }) => client.applyFilmPlan(id, plan)));
|
|
618
|
+
|
|
619
|
+
server.registerTool('set_fades',
|
|
620
|
+
{ 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() } },
|
|
621
|
+
wrap(({ filmId: id, ...rest }) => client.setFades(id, rest)));
|
|
622
|
+
|
|
623
|
+
server.registerTool('add_marker',
|
|
624
|
+
{ title: 'Add a marker', description: 'Put a named marker on the ruler.', inputSchema: { filmId, at, name: z.string().optional() } },
|
|
625
|
+
wrap(({ filmId: id, ...rest }) => client.addMarker(id, rest)));
|
|
626
|
+
|
|
627
|
+
server.registerTool('set_export_range',
|
|
628
|
+
{ 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() } },
|
|
629
|
+
wrap(({ filmId: id, ...rest }) => client.setExportRange(id, rest)));
|
|
630
|
+
|
|
631
|
+
server.registerTool('render_clips',
|
|
632
|
+
{ 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.', inputSchema: {
|
|
633
|
+
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.'),
|
|
634
|
+
} },
|
|
635
|
+
wrap(({ filmId: id, clips }) => client.renderClips(id, clips === undefined ? {} : { clips })));
|
|
636
|
+
|
|
637
|
+
server.registerTool('wait_for_renders',
|
|
638
|
+
{ 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() } },
|
|
639
|
+
wrap(async ({ filmId: id, timeoutSeconds = 600, pollMs = 10000 }) => {
|
|
640
|
+
pollMs = Math.max(250, pollMs);
|
|
641
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
642
|
+
for (;;) {
|
|
643
|
+
const timeline = await client.getFilm(id);
|
|
644
|
+
const rendering = (timeline.clips || []).filter((c) => c.take === 'rendering').map((c) => c.number);
|
|
645
|
+
// A linked chain is between takes for a while (nothing reads as rendering): it is
|
|
646
|
+
// not done until the batch says so.
|
|
647
|
+
if (!rendering.length && !timeline.rendersRunning) return { timeline };
|
|
648
|
+
if (Date.now() >= deadline) return { timeline, rendering, note: 'timeout_still_running' };
|
|
649
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
650
|
+
}
|
|
651
|
+
}));
|
|
652
|
+
|
|
653
|
+
server.registerTool('list_takes',
|
|
654
|
+
{ title: 'List takes', description: 'Every render of a clip, newest first, numbered, and which one the clip shows.', inputSchema: { filmId, clip: clipRef } },
|
|
655
|
+
wrap(({ filmId: id, clip }) => client.listTakes(id, clip)));
|
|
656
|
+
|
|
657
|
+
server.registerTool('use_take',
|
|
658
|
+
{ 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() } },
|
|
659
|
+
wrap(({ filmId: id, clip, generationId }) => client.useTake(id, clip, generationId)));
|
|
660
|
+
|
|
661
|
+
server.registerTool('export_film',
|
|
662
|
+
{ 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`.', inputSchema: { filmId } },
|
|
663
|
+
wrap(({ filmId: id }) => client.exportFilm(id)));
|
|
664
|
+
|
|
665
|
+
server.registerTool('list_locations',
|
|
666
|
+
{ title: 'List locations', description: 'The Library\'s locations (places a cast can stand in): id, name, description, whether it has its picture.', inputSchema: {} },
|
|
667
|
+
wrap(() => client.listLocations()));
|
|
668
|
+
|
|
669
|
+
server.registerTool('create_location',
|
|
670
|
+
{ 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: {
|
|
671
|
+
name: z.string(), description: z.string().optional(), upload: z.string().optional(), fromJob: z.string().optional(),
|
|
672
|
+
} },
|
|
673
|
+
wrap((a) => client.createLocation(a)));
|
|
674
|
+
|
|
500
675
|
server.registerTool('cancel_recipe_run',
|
|
501
676
|
{ 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() } },
|
|
502
677
|
wrap(({ runId }) => client.cancelRecipeRun(runId)));
|
|
@@ -508,4 +683,6 @@ export function registerTools(server, client) {
|
|
|
508
683
|
server.registerTool('publish_recipe',
|
|
509
684
|
{ 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.', 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).') } },
|
|
510
685
|
wrap(({ id, changelog, priceTokens }) => client.publishRecipe(id, { changelog, priceTokens })));
|
|
686
|
+
|
|
687
|
+
return { studioTools: STUDIO_TOOL_NAMES.map((name) => registered[name]) };
|
|
511
688
|
}
|