@slatesvideo/shared 0.7.8 → 0.7.10
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/dist/clients/desktop.js +6 -1
- package/dist/manual/content.d.ts +1 -1
- package/dist/manual/content.js +1 -1
- package/dist/operations/index.d.ts +199 -74
- package/dist/operations/index.js +221 -17
- package/dist/operations/surface.js +32 -1
- package/dist/prompts/generation-policy.d.ts +1 -1
- package/dist/skills/brain-check.js +5 -3
- package/dist/skills/served.d.ts +6 -2
- package/dist/skills/served.js +36 -6
- package/package.json +1 -1
package/dist/operations/index.js
CHANGED
|
@@ -97,15 +97,21 @@ export class GuideNotReadError extends Error {
|
|
|
97
97
|
const head = `Refused: this session has not read ${guide}, the guide for ${model}. Nothing was generated or charged. `;
|
|
98
98
|
const body = brainSkills().skills[guide];
|
|
99
99
|
const served = servedBrain();
|
|
100
|
-
|
|
100
|
+
const locked = body === undefined ? served.locked.find(entry => entry.name === guide) : undefined;
|
|
101
|
+
super(body !== undefined
|
|
101
102
|
? head +
|
|
102
103
|
`Call slates_get_prompting_guide with topic "${guide}", rewrite the prompt against it, then call this again. Its card:\n\n` +
|
|
103
104
|
// The card this user's brain serves, so a model guide from their My brain is the one in the refusal.
|
|
104
105
|
describeCraftCard(guide, body)
|
|
105
|
-
:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
: locked
|
|
107
|
+
? // Past this account's tier: no body here, so the server's notice (its card included) is what it reads.
|
|
108
|
+
head +
|
|
109
|
+
`Call slates_get_prompting_guide with topic "${guide}", rewrite the prompt against what it says, then call this again. What it says:\n\n` +
|
|
110
|
+
(locked.notice ?? `${guide} is not open to this account. Run the job on the general rules.`)
|
|
111
|
+
: // No copy here and none locked: the brain never arrived, so asking for the guide again cannot help.
|
|
112
|
+
head +
|
|
113
|
+
`The guide comes from the connected Slates account and is not on this machine (${served.problem ?? 'no brain received yet'}). ` +
|
|
114
|
+
`${CONNECT_FOR_BRAIN}; then call slates_get_prompting_guide with topic "${guide}" and call this again.`);
|
|
109
115
|
this.model = model;
|
|
110
116
|
this.guide = guide;
|
|
111
117
|
}
|
|
@@ -1035,6 +1041,35 @@ export const setAppSettings = {
|
|
|
1035
1041
|
return ok(await ctx.desktop().post('/agent/app-settings', input));
|
|
1036
1042
|
},
|
|
1037
1043
|
};
|
|
1044
|
+
const SPEND_LIMIT = z.number().int().min(0).nullable();
|
|
1045
|
+
export const getSpendLimits = {
|
|
1046
|
+
id: 'slates_get_spend_limits',
|
|
1047
|
+
description: "The project's spend limit and this session's budget, in credits, where a session is this MCP connection or CLI run and a new one starts at the full default budget: each limit (null is none), what is spent against it and what is left, as shown beside Generate. A generation over either one is refused with its cost and what is left; read this before a run of generations.",
|
|
1048
|
+
input: z.object({ projectId: z.string().uuid().optional().describe('Defaults to the open project.') }).strict(),
|
|
1049
|
+
async run(input, ctx) {
|
|
1050
|
+
await ctx.desktop().requireCapability('spend-limits', 'spend limits');
|
|
1051
|
+
return ok(await ctx.desktop().get('/agent/spend-limits', { projectId: input.projectId }));
|
|
1052
|
+
},
|
|
1053
|
+
};
|
|
1054
|
+
export const setSpendLimits = {
|
|
1055
|
+
id: 'slates_set_spend_limits',
|
|
1056
|
+
description: "Set the project's spend limit or this session's budget (per MCP connection or CLI run, not across them), in credits; null removes one. Lowering a limit is yours to do. Raising or removing one, the session budget included, needs the user's OK in chat first: without confirm it changes nothing and returns requires_confirm. Pass confirm=true only after the user says yes, never on your own.",
|
|
1057
|
+
input: z
|
|
1058
|
+
.object({
|
|
1059
|
+
projectId: z.string().uuid().optional().describe('Defaults to the open project.'),
|
|
1060
|
+
projectLimitCredits: SPEND_LIMIT.optional().describe('What this project may spend in all, by hand and by every agent.'),
|
|
1061
|
+
sessionBudgetCredits: SPEND_LIMIT.optional().describe('What this MCP connection or CLI run may spend.'),
|
|
1062
|
+
confirm: z.boolean().optional().describe("Set true only to relay the user's explicit OK to raise or remove a limit."),
|
|
1063
|
+
})
|
|
1064
|
+
.strict(),
|
|
1065
|
+
async run(input, ctx) {
|
|
1066
|
+
if (input.projectLimitCredits === undefined && input.sessionBudgetCredits === undefined) {
|
|
1067
|
+
throw new Error('Pass projectLimitCredits, sessionBudgetCredits or both.');
|
|
1068
|
+
}
|
|
1069
|
+
await ctx.desktop().requireCapability('spend-limits', 'spend limits');
|
|
1070
|
+
return ok(await ctx.desktop().post('/agent/spend-limits', input));
|
|
1071
|
+
},
|
|
1072
|
+
};
|
|
1038
1073
|
export const getAsset = {
|
|
1039
1074
|
id: 'slates_get_asset',
|
|
1040
1075
|
description: 'One asset in full (UUID or badge code): its recorded prompt, model, settings and inputs, its source picture and linked clips, and how many clips and board shots use it. slates_list_assets rows are compact; read this before reusing or explaining one card.',
|
|
@@ -1119,6 +1154,156 @@ export const editAssetTranscript = {
|
|
|
1119
1154
|
return ok(summary, `Saved: ${c.corrected} corrected, ${c.added} added, ${c.removed} removed.${r.recaptioned.length ? ` Remade ${r.recaptioned.length} caption clip${r.recaptioned.length === 1 ? '' : 's'}: ${r.recaptioned.join(', ')}.` : ''}`);
|
|
1120
1155
|
},
|
|
1121
1156
|
};
|
|
1157
|
+
// Cut by transcript (slate roadmap item 13): the desktop route is POST /agent/timeline/cut-transcript, the same
|
|
1158
|
+
// core as the transcript page's Cut (slate `src/main/editor/transcriptCut.ts`).
|
|
1159
|
+
export const cutByTranscript = {
|
|
1160
|
+
id: 'slates_cut_by_transcript',
|
|
1161
|
+
billable: false,
|
|
1162
|
+
description: "Cut words or pauses out of a video or audio clip on the timeline by its transcript, as Cut on the clip's Transcript page does: each stretch leaves the clip, which splits around it, and the gap closes (ripple), at the clip's own in point and speed. Name words by their index in slates_get_asset_transcript's words (from and to, inclusive), pauses by the index of the word each follows, or stretches of the file's own seconds. A word's cut reaches up to 60 ms before it and 100 ms after it into silence, never into a neighbouring word; a pause keeps 100 ms after the word before and 60 ms before the word after, so no word loses its first or last sound. The clip's linked sound and the captions heard from it are cut the same way; trackIds adds more lanes (a picture above it, a music bed) to keep in sync; linked false cuts only the clip's lane. Words an earlier cut left in later pieces are found there. Returns the clips written, ids deleted, durationFrames, each stretch cut in timeline seconds (latest first), removedSec, and timing: aligned words land within a frame or two, recognizer words within about a quarter second (transcribe again with force first). Free. Requires transcript-cut; update Slates on capability refusal.",
|
|
1163
|
+
input: z
|
|
1164
|
+
.object({
|
|
1165
|
+
projectId: z.string().uuid(),
|
|
1166
|
+
clipId: z.string().uuid().describe('The video or audio clip on the timeline whose words to cut.'),
|
|
1167
|
+
words: z.array(z.object({ from: z.number().int().min(0), to: z.number().int().min(0) }).strict()).min(1).optional()
|
|
1168
|
+
.describe("Runs of words to cut, by index in the asset's transcript words, from and to inclusive."),
|
|
1169
|
+
pauses: z.array(z.number().int().min(0)).min(1).optional().describe('Pauses to cut, each by the index of the word it follows.'),
|
|
1170
|
+
ranges: z.array(z.object({ startSec: z.number().min(0), endSec: z.number().min(0) }).strict()).min(1).optional()
|
|
1171
|
+
.describe("Stretches of the file's own seconds to cut, as the transcript counts them."),
|
|
1172
|
+
linked: z.boolean().optional().describe("False: cut only the clip's lane, not its linked sound's. Default true."),
|
|
1173
|
+
trackIds: z.array(z.string().uuid()).min(1).optional().describe('More lanes to cut and close up the same way, to keep them in sync.'),
|
|
1174
|
+
})
|
|
1175
|
+
.strict(),
|
|
1176
|
+
async run(input, ctx) {
|
|
1177
|
+
if (!input.words && !input.pauses && !input.ranges)
|
|
1178
|
+
throw new Error('Name words, pauses or ranges to cut.');
|
|
1179
|
+
await ctx.desktop().requireCapability('transcript-cut', 'cut by transcript');
|
|
1180
|
+
const r = await ctx.desktop().post('/agent/timeline/cut-transcript', input);
|
|
1181
|
+
const rough = r.timing === 'recognizer' ? " These words have the recognizer's rough timing: transcribe again with force for aligned edges." : '';
|
|
1182
|
+
return ok(r, `Cut ${r.cut.length} stretch${r.cut.length === 1 ? '' : 'es'}, ${r.removedSec.toFixed(2)} s in all; the timeline is now ${r.durationFrames} frames.${rough}`);
|
|
1183
|
+
},
|
|
1184
|
+
};
|
|
1185
|
+
// A music clip's beat grid (slate 1.6.4 plan step 3): the desktop routes are /agent/timeline/beats (GET reads,
|
|
1186
|
+
// POST finds), /agent/timeline/beats/edit and /agent/timeline/cut-to-beats, the same core as the Inspector's
|
|
1187
|
+
// Beat grid section (slate `src/main/beats/service.ts`, `src/main/editor/beatCuts.ts`).
|
|
1188
|
+
const beatTarget = {
|
|
1189
|
+
assetId: z.string().min(1).optional().describe('An audio or video asset: its code (AUD-A2) or id. Or name clipId.'),
|
|
1190
|
+
clipId: z.string().uuid().optional().describe('A clip on the timeline: the grid of its file, plus where each beat lands on the cut (onTimeline, in frames).'),
|
|
1191
|
+
};
|
|
1192
|
+
async function beatTargetBody(ctx, input) {
|
|
1193
|
+
if (input.clipId)
|
|
1194
|
+
return { projectId: input.projectId, clipId: input.clipId };
|
|
1195
|
+
if (!input.assetId)
|
|
1196
|
+
throw new Error('Name assetId or clipId.');
|
|
1197
|
+
return { projectId: input.projectId, assetId: (await resolveAssetRefs(ctx, input.projectId, [input.assetId])).get(input.assetId).id };
|
|
1198
|
+
}
|
|
1199
|
+
function beatGridWords(r) {
|
|
1200
|
+
if (!r.beats || !r.summary)
|
|
1201
|
+
return r.hint ?? 'No beat grid yet.';
|
|
1202
|
+
const s = r.summary;
|
|
1203
|
+
const spans = r.lowConfidence?.length ?? 0;
|
|
1204
|
+
const spots = spans ? ` ${spans} span${spans === 1 ? '' : 's'} to check (lowConfidence).` : '';
|
|
1205
|
+
const edits = r.edits?.length ? ` ${r.edits.length} hand edit${r.edits.length === 1 ? '' : 's'} kept.` : '';
|
|
1206
|
+
return `${s.bpm ?? '?'} BPM, ${s.beatsPerBar ?? '?'} beats a bar, ${s.beats} beats${s.tempoChanges ? ', the tempo changes' : ''}.${spots}${edits}${r.picture ? ` Picture: ${r.picture}` : ''}`;
|
|
1207
|
+
}
|
|
1208
|
+
export const getBeatGrid = {
|
|
1209
|
+
id: 'slates_get_beat_grid',
|
|
1210
|
+
description: "Read a music file's beat grid, to check it before cutting to it: every beat in the file's own seconds with its downbeat flag and a confidence from 0 to 1 (hand-placed beats read 1), a summary (BPM, beats a bar, the tempo sections, whether the tempo changes), lowConfidence (the spans to check: runs of unsure beats, and gaps where the tempo says a beat belongs) and the hand edits kept on it. With a clipId it also gives onTimeline: where each beat lands on the cut, in frames, at the clip's in point and speed. picture true saves a PNG of the grid over the waveform (downbeats bright with bar numbers, unsure beats amber) and returns its path; fromSec and toSec frame a stretch. Look at it to judge a span. Never finds beats: beats null with a hint means none yet (slates_find_beats, free). Fix a wrong beat with slates_edit_beat_grid. Requires beat-grid; update Slates on capability refusal.",
|
|
1211
|
+
input: z
|
|
1212
|
+
.object({
|
|
1213
|
+
projectId: z.string().uuid(),
|
|
1214
|
+
...beatTarget,
|
|
1215
|
+
picture: z.boolean().optional().describe('Save a picture of the grid over the waveform and return its path.'),
|
|
1216
|
+
fromSec: z.number().min(0).optional().describe("The picture's first second, in the file's own time."),
|
|
1217
|
+
toSec: z.number().min(0).optional().describe("The picture's last second, in the file's own time."),
|
|
1218
|
+
})
|
|
1219
|
+
.strict(),
|
|
1220
|
+
async run(input, ctx) {
|
|
1221
|
+
await ctx.desktop().requireCapability('beat-grid', 'beat grids');
|
|
1222
|
+
const body = await beatTargetBody(ctx, input);
|
|
1223
|
+
const r = await ctx.desktop().get('/agent/timeline/beats', {
|
|
1224
|
+
...body, ...(input.picture ? { picture: true } : {}), fromSec: input.fromSec, toSec: input.toSec,
|
|
1225
|
+
});
|
|
1226
|
+
return ok(r, `${beatGridWords(r)} ${JSON.stringify(r)}`);
|
|
1227
|
+
},
|
|
1228
|
+
};
|
|
1229
|
+
export const findBeats = {
|
|
1230
|
+
id: 'slates_find_beats',
|
|
1231
|
+
billable: false,
|
|
1232
|
+
description: "Find a music file's beats, downbeats and tempo on the user's machine, as Find beats in the clip's Inspector does. Free: it spends no credits and nothing leaves the machine. The first run downloads the beat model once (the result's downloadedModelMB says how much) and can take a few minutes; if the call times out, the desktop keeps working, so read slates_get_beat_grid before trying again. Hand edits already on the grid are kept and applied over the new beats. Returns the grid as slates_get_beat_grid does; read its lowConfidence spans before you cut. Requires beat-grid; update Slates on capability refusal.",
|
|
1233
|
+
input: z.object({ projectId: z.string().uuid(), ...beatTarget }).strict(),
|
|
1234
|
+
async run(input, ctx) {
|
|
1235
|
+
await ctx.desktop().requireCapability('beat-grid', 'finding beats');
|
|
1236
|
+
const r = await ctx.desktop().post('/agent/timeline/beats', await beatTargetBody(ctx, input));
|
|
1237
|
+
const model = r.downloadedModelMB ? ` Downloaded the ${r.downloadedModelMB} MB beat model first.` : '';
|
|
1238
|
+
return ok(r, `Found the beats.${model} ${beatGridWords(r)} ${JSON.stringify(r)}`);
|
|
1239
|
+
},
|
|
1240
|
+
};
|
|
1241
|
+
const beatEditInput = z.discriminatedUnion('kind', [
|
|
1242
|
+
z.object({ kind: z.literal('shift'), sec: z.number().describe('Seconds to move every beat; negative is earlier.') }).strict(),
|
|
1243
|
+
z.object({
|
|
1244
|
+
kind: z.literal('downbeat'),
|
|
1245
|
+
at: z.number().min(0).describe('The beat nearest this second starts a bar; the bars around it follow.'),
|
|
1246
|
+
beatsPerBar: z.number().int().min(1).max(16).optional().describe('Also set the meter, in beats a bar.'),
|
|
1247
|
+
}).strict(),
|
|
1248
|
+
z.object({
|
|
1249
|
+
kind: z.literal('tempo'),
|
|
1250
|
+
fromSec: z.number().min(0),
|
|
1251
|
+
toSec: z.number().min(0),
|
|
1252
|
+
bpm: z.number().min(30).max(300).describe('Lay beats at this tempo over the span, from the beat nearest fromSec (or fromSec itself).'),
|
|
1253
|
+
}).strict(),
|
|
1254
|
+
z.object({ kind: z.literal('add'), at: z.number().min(0), downbeat: z.boolean().optional() }).strict(),
|
|
1255
|
+
z.object({ kind: z.literal('move'), from: z.number().min(0).describe('The beat nearest this second moves...'), to: z.number().min(0).describe('...to this second.') }).strict(),
|
|
1256
|
+
z.object({ kind: z.literal('delete'), at: z.number().min(0).describe('The beat nearest this second goes.') }).strict(),
|
|
1257
|
+
]);
|
|
1258
|
+
export const editBeatGrid = {
|
|
1259
|
+
id: 'slates_edit_beat_grid',
|
|
1260
|
+
billable: false,
|
|
1261
|
+
description: "Correct a music file's beat grid by hand, as the Beat grid controls in the clip's Inspector do: shift the whole grid (sec), set the downbeat (the beat at a second starts a bar; beatsPerBar sets the meter), lay a tempo over a span (fromSec, toSec, bpm; it works with no grid yet, so a known tempo needs no detection), or add, move or delete one beat. Times are the file's own seconds, as slates_get_beat_grid gives them; a beat is named by the nearest one within 0.15 s. Edits apply in order and are kept: finding the beats again never overwrites them. undo takes back the last edit; clearEdits drops them all. The marks on the clip and the snapping follow at once. Free. Returns the grid as slates_get_beat_grid does. Requires beat-grid; update Slates on capability refusal.",
|
|
1262
|
+
input: z
|
|
1263
|
+
.object({
|
|
1264
|
+
projectId: z.string().uuid(),
|
|
1265
|
+
...beatTarget,
|
|
1266
|
+
edits: z.array(beatEditInput).min(1).optional().describe('Edits to apply, in order.'),
|
|
1267
|
+
undo: z.boolean().optional().describe('Take back the last hand edit.'),
|
|
1268
|
+
clearEdits: z.boolean().optional().describe('Drop every hand edit and show the found beats.'),
|
|
1269
|
+
})
|
|
1270
|
+
.strict(),
|
|
1271
|
+
async run(input, ctx) {
|
|
1272
|
+
if (!input.edits && !input.undo && !input.clearEdits)
|
|
1273
|
+
throw new Error('Send edits, undo: true or clearEdits: true.');
|
|
1274
|
+
await ctx.desktop().requireCapability('beat-grid', 'editing a beat grid');
|
|
1275
|
+
const r = await ctx.desktop().post('/agent/timeline/beats/edit', {
|
|
1276
|
+
...(await beatTargetBody(ctx, input)),
|
|
1277
|
+
...(input.undo ? { undo: true } : input.clearEdits ? { clearEdits: true } : { edits: input.edits }),
|
|
1278
|
+
});
|
|
1279
|
+
return ok(r, `Saved. ${beatGridWords(r)} ${JSON.stringify(r)}`);
|
|
1280
|
+
},
|
|
1281
|
+
};
|
|
1282
|
+
export const cutToBeats = {
|
|
1283
|
+
id: 'slates_cut_to_beats',
|
|
1284
|
+
billable: false,
|
|
1285
|
+
description: "Cut a lane to the music, so its cuts land on the beats of a music clip's grid. mode snap (default) rolls each existing cut on the lane (two clips that meet) to the nearest chosen beat within reachFrames (default half a beat), so the edit keeps its order and its length; mode split cuts the lane's clips at every chosen beat. on downbeat uses only the first beat of each bar; every 2 takes every second one; fromFrame and toFrame hold it to a stretch of the timeline. trackId names the lane (default: the first unlocked video lane with clips). Read the grid first (slates_get_beat_grid) and fix any lowConfidence span it lists, or cuts land on wrong beats. Returns the clips written, cuts (clipId, fromFrame, toFrame), skipped (each cut left where it was, and why) and beatFrames. Free. Requires beat-grid; update Slates on capability refusal.",
|
|
1286
|
+
input: z
|
|
1287
|
+
.object({
|
|
1288
|
+
projectId: z.string().uuid(),
|
|
1289
|
+
musicClipId: z.string().uuid().describe('The music clip on the timeline whose beats the cuts land on.'),
|
|
1290
|
+
trackId: z.string().uuid().optional().describe('The lane to cut. Default: the first unlocked video lane with clips.'),
|
|
1291
|
+
mode: z.enum(['snap', 'split']).optional().describe('snap: move the existing cuts onto beats (default). split: cut the clips at every chosen beat.'),
|
|
1292
|
+
on: z.enum(['beat', 'downbeat']).optional().describe('Every beat (default) or only downbeats.'),
|
|
1293
|
+
every: z.number().int().min(1).max(64).optional().describe('Use every Nth chosen beat. Default 1.'),
|
|
1294
|
+
fromFrame: z.number().min(0).optional().describe('Only beats from this timeline frame on.'),
|
|
1295
|
+
toFrame: z.number().min(0).optional().describe('Only beats up to this timeline frame.'),
|
|
1296
|
+
reachFrames: z.number().min(0).optional().describe('snap: how far a cut may move to reach a beat, in frames. Default half a beat.'),
|
|
1297
|
+
})
|
|
1298
|
+
.strict(),
|
|
1299
|
+
async run(input, ctx) {
|
|
1300
|
+
await ctx.desktop().requireCapability('beat-grid', 'cutting to the beat');
|
|
1301
|
+
const r = await ctx.desktop().post('/agent/timeline/cut-to-beats', input);
|
|
1302
|
+
const split = input.mode === 'split';
|
|
1303
|
+
const skipped = r.skipped.length ? ` ${r.skipped.length} left where ${r.skipped.length === 1 ? 'it was' : 'they were'}: ${r.skipped[0].reason}.` : '';
|
|
1304
|
+
return ok(r, `${split ? 'Cut at' : 'Moved'} ${r.cuts.length} ${split ? 'beat' : 'cut'}${r.cuts.length === 1 ? '' : 's'}${split ? '' : ' onto the beat'}.${skipped}`);
|
|
1305
|
+
},
|
|
1306
|
+
};
|
|
1122
1307
|
export const extractVideoFrame = {
|
|
1123
1308
|
id: 'slates_extract_video_frame',
|
|
1124
1309
|
description: "Save one frame of a clip as a new picture in Media, as the clip card's camera does: at 'first', 'last' (default 'first') or a second. Free. The usual continuity move: extract a clip's last frame and use it as the next clip's first frame. To only look at a clip, use slates_get_asset_video_frames; this one adds a picture to the project.",
|
|
@@ -1902,7 +2087,7 @@ export const saveExternalImage = {
|
|
|
1902
2087
|
};
|
|
1903
2088
|
export const uploadReferenceImage = {
|
|
1904
2089
|
id: 'slates_upload_reference_image',
|
|
1905
|
-
description: 'Add a reference image, video clip, or audio file to a Slates project from disk. Pass either filePath (absolute path to a local file) or dataUrl (base64 data: URL) — exactly one. Set type:"video" to bring in a clip (the user\'s own footage to edit/relocate/trim) or type:"audio" for music/VO/SFX they already have; both are probed on ingest, so duration (and for video, dimensions) are available immediately, and audio gets its waveform. Default type is "image". dataUrl is image-only. Pass label to name it and note to record what it is; without them it is "Imported file". A picture derived from a project asset (edited, masked, upscaled or converted outside Slates) belongs in slates_save_external_image with referenceAssetIds, so its source and prompt are recorded.',
|
|
2090
|
+
description: 'Add a reference image, video clip, or audio file to a Slates project from disk. Pass either filePath (absolute path to a local file) or dataUrl (base64 data: URL) — exactly one. Set type:"video" to bring in a clip (the user\'s own footage to edit/relocate/trim) or type:"audio" for music/VO/SFX they already have; both are probed on ingest, so duration (and for video, dimensions) are available immediately, and audio gets its waveform. A camera clip the timeline cannot play smoothly (ProRes, HEVC, 4K, sparse keyframes) answers playableCopy {state:"making", percent}: the timeline plays that copy once it is made, while export and generation read the original, so nothing waits on it. Default type is "image". dataUrl is image-only. Pass label to name it and note to record what it is; without them it is "Imported file". A picture derived from a project asset (edited, masked, upscaled or converted outside Slates) belongs in slates_save_external_image with referenceAssetIds, so its source and prompt are recorded.',
|
|
1906
2091
|
input: z
|
|
1907
2092
|
.object({
|
|
1908
2093
|
projectId: z.string().uuid(),
|
|
@@ -5287,13 +5472,18 @@ export const getReframeReport = {
|
|
|
5287
5472
|
const reframeClipInput = reframeReportInput.extend({ clipId: z.string().uuid(), framing: z.object({
|
|
5288
5473
|
mode: z.enum(['fill', 'fit']).optional(), focusX: z.number().min(0).max(1).optional(),
|
|
5289
5474
|
focusY: z.number().min(0).max(1).optional(), zoom: z.number().min(1).optional(),
|
|
5290
|
-
}).strict().nullable().describe('Normalized focus and zoom for this clip/aspect. Null resets the override; the desktop binds it to the current take.')
|
|
5475
|
+
}).strict().nullable().optional().describe('Normalized focus and zoom for this clip/aspect. Null resets the override; the desktop binds it to the current take. Required unless follow is set.'),
|
|
5476
|
+
follow: z.enum(['face', 'off']).optional().describe('"face" finds the face in the clip and keys its focusX/focusY to it (smooth, held where the face is lost; every format draws those keys, each keyframe editable by hand or with slates_set_clip_keyframes); "off" removes those keys. Runs on the computer and spends nothing.') });
|
|
5291
5477
|
export const reframeClip = {
|
|
5292
|
-
id: 'slates_reframe_clip', description: 'Set or reset a clip framing override for one delivery aspect and return the desktop computed framing report. Changes focus, fill/fit and zoom without duplicating the timeline or generating media. Requires ad-variant-export; update Slates on capability refusal.',
|
|
5478
|
+
id: 'slates_reframe_clip', description: 'Set or reset a clip framing override for one delivery aspect and return the desktop computed framing report. Changes focus, fill/fit and zoom without duplicating the timeline or generating media. follow: "face" makes a vertical cut follow a talking head (framing, when sent too, lands first) and answers follow: the clip keyframes, samples, found, still and the lost spans in seconds. Requires ad-variant-export, and reframe-follow for follow; update Slates on capability refusal.',
|
|
5293
5479
|
billable: false,
|
|
5294
5480
|
input: reframeClipInput,
|
|
5295
5481
|
async run(input, ctx) {
|
|
5296
5482
|
await ctx.desktop().requireCapability('ad-variant-export', 'clip delivery reframing');
|
|
5483
|
+
if (input.follow)
|
|
5484
|
+
await ctx.desktop().requireCapability('reframe-follow', 'following a face');
|
|
5485
|
+
else if (input.framing === undefined)
|
|
5486
|
+
throw new Error('Send framing (null resets it) or follow');
|
|
5297
5487
|
return ok(await ctx.desktop().post('/agent/timeline/reframe', input));
|
|
5298
5488
|
},
|
|
5299
5489
|
};
|
|
@@ -5955,7 +6145,7 @@ const CAPTION_COMPONENTS = [
|
|
|
5955
6145
|
'caption-neon-accent', 'caption-editorial-emphasis',
|
|
5956
6146
|
];
|
|
5957
6147
|
const htmlCompositionInput = z.string().min(1).describe('A composition: a whole HTML document whose GSAP timeline is registered on window.__timelines.');
|
|
5958
|
-
const htmlVariablesInput = z.record(z.union([z.string(), z.number(), z.boolean()])).describe("Values for the composition's or block's declared variables, by name: text, numbers or true/false.");
|
|
6148
|
+
const htmlVariablesInput = z.record(z.union([z.string(), z.number(), z.boolean()])).describe("Values for the composition's or block's declared variables, by name: text, numbers or true/false. A picture (declared type image) takes an image asset id (UUID) of this project, or \"\" for the layer's own picture, and reads back as its path in the project folder (images/logo.png); a web address or another project's picture is refused.");
|
|
5959
6149
|
export const addCaptions = {
|
|
5960
6150
|
id: 'slates_add_captions',
|
|
5961
6151
|
billable: false,
|
|
@@ -6024,7 +6214,7 @@ const describeFindings = (f) => {
|
|
|
6024
6214
|
};
|
|
6025
6215
|
export const addHtmlClip = {
|
|
6026
6216
|
id: 'slates_add_html_clip',
|
|
6027
|
-
description: "Put an HTML motion layer on the timeline: an animated caption, lower third, end card, title, logo sting or background plate, drawn on an overlay track in preview and export. An HTML clip is a composition, an HTML document with a GSAP timeline registered on window.__timelines. Pass your own html, or block with the name of a registry block (slates_list_motion_blocks) and its variables; html with block replaces the block's document and keeps its files. Slates' composition check runs before the clip lands and its findings come back here: fix every error with slates_update_html_clip before moving on. Keep a transparent foreground and a background plate on separate tracks. Free. Read slates_get_timeline first for the frame rate and where clips sit. Craft: slates_get_prompting_guide (topic: slates-motion).",
|
|
6217
|
+
description: "Put an HTML motion layer on the timeline: an animated caption, lower third, end card, title, logo sting or background plate, drawn on an overlay track in preview and export. An HTML clip is a composition, an HTML document with a GSAP timeline registered on window.__timelines. Pass your own html, or block with the name of a registry block (slates_list_motion_blocks) and its variables; html with block replaces the block's document and keeps its files. It loads the project's own pictures, SVGs, fonts, stylesheets and scripts by their path in the project's folder (images/logo.svg, fonts/Brand.woff2, css/brand.css, js/library.js; the folder is projectsFolder from slates_get_app_settings, then the project id) and no other file; an export fails, naming the font, when a declared font does not load. Slates' composition check runs before the clip lands and its findings come back here: fix every error with slates_update_html_clip before moving on. Keep a transparent foreground and a background plate on separate tracks. Free. Read slates_get_timeline first for the frame rate and where clips sit. Craft: slates_get_prompting_guide (topic: slates-motion).",
|
|
6028
6218
|
input: z
|
|
6029
6219
|
.object({
|
|
6030
6220
|
projectId: z.string().uuid(),
|
|
@@ -6050,7 +6240,7 @@ export const addHtmlClip = {
|
|
|
6050
6240
|
};
|
|
6051
6241
|
export const updateHtmlClip = {
|
|
6052
6242
|
id: 'slates_update_html_clip',
|
|
6053
|
-
description: "Change an HTML clip's composition or its variables. Slates' composition check runs again and its findings come back here: fix every error before moving on. Only what you pass changes. To move or retime one, remove it (slates_remove_clip) and add it again.",
|
|
6243
|
+
description: "Change an HTML clip's composition or its variables. Like slates_add_html_clip, the composition loads the project's own pictures, SVGs, fonts, stylesheets and scripts by their path in the project's folder. Slates' composition check runs again and its findings come back here: fix every error before moving on. Only what you pass changes. To move or retime one, remove it (slates_remove_clip) and add it again.",
|
|
6054
6244
|
input: z
|
|
6055
6245
|
.object({
|
|
6056
6246
|
projectId: z.string().uuid(),
|
|
@@ -6069,7 +6259,7 @@ export const updateHtmlClip = {
|
|
|
6069
6259
|
};
|
|
6070
6260
|
export const checkComposition = {
|
|
6071
6261
|
id: 'slates_check_composition',
|
|
6072
|
-
description: "Check a composition before it lands, with Slates' composition check: its errors and warnings, each with a code, a message and, where it has one, the selector it found. Writes nothing. slates_add_html_clip and slates_update_html_clip run the same check, so use this one while drafting.",
|
|
6262
|
+
description: "Check a composition before it lands, with Slates' composition check: its errors and warnings, each with a code, a message and, where it has one, the selector it found. Writes nothing. A file the composition names by its path in the project's folder (a picture, SVG, font, stylesheet or script) is served to it, so name one there instead of a remote address the check flags. slates_add_html_clip and slates_update_html_clip run the same check, so use this one while drafting.",
|
|
6073
6263
|
input: z.object({ html: htmlCompositionInput }).strict(),
|
|
6074
6264
|
async run(input, ctx) {
|
|
6075
6265
|
await ctx.desktop().requireCapability('html-clips', 'HTML layers');
|
|
@@ -6599,7 +6789,7 @@ export const copyLibraryItemToProject = {
|
|
|
6599
6789
|
// mention. It holds no takes, and importing one generates and spends nothing.
|
|
6600
6790
|
export const getTemplate = {
|
|
6601
6791
|
id: 'slates_get_template',
|
|
6602
|
-
description: "Read a Slates template file without changing anything. With `path`: what it holds (scenes, shots, library items, the models its shots are set to) and its SWAP SLOTS — every Library item (`item:i1`, labelled with its mention, e.g. @candle) and every directly attached reference (`asset:a3`, with its roles) that slates_import_template can point at one of the project's own assets instead. Without `path`: the templates in the user's templates folder, plus any starter templates the app ships.",
|
|
6792
|
+
description: "Read a Slates template file without changing anything. With `path`: what it holds (scenes, shots, library items, the models its shots are set to) and its SWAP SLOTS — every Library item (`item:i1`, labelled with its mention, e.g. @candle, with `extras` (its count of extra pictures) and `palette`) and every directly attached reference (`asset:a3`, with its roles) that slates_import_template can point at one of the project's own assets instead. Without `path`: the templates in the user's templates folder, plus any starter templates the app ships.",
|
|
6603
6793
|
input: z.object({ path: z.string().min(1).optional().describe('Absolute path of a .slatestemplate file. Omit to list saved templates.') }),
|
|
6604
6794
|
async run(input, ctx) {
|
|
6605
6795
|
await ctx.desktop().requireCapability('templates', 'templates');
|
|
@@ -6610,7 +6800,7 @@ export const getTemplate = {
|
|
|
6610
6800
|
};
|
|
6611
6801
|
export const exportTemplate = {
|
|
6612
6802
|
id: 'slates_export_template',
|
|
6613
|
-
description: "Save a board, a scene or one Shot as a template file someone else can start from. Give exactly one of storyboardId, sceneId or shotId. The file carries each Shot's full recipe (prompt, model, settings, reference roles, script words) plus the reference files and the Library items the Shots mention; it carries no takes. The project is untouched. A file saved outside the user's templates folder is not in the template list (slates_get_template without path); the user opens it with Open a file. Returns the path, the counts and a warning for any reference whose file is missing.",
|
|
6803
|
+
description: "Save a board, a scene or one Shot as a template file someone else can start from. Give exactly one of storyboardId, sceneId or shotId. The file carries each Shot's full recipe (prompt, model, settings, reference roles, script words) plus the reference files and the Library items the Shots mention, each with its picture, extra pictures and colours; it carries no takes. The project is untouched. A file saved outside the user's templates folder is not in the template list (slates_get_template without path); the user opens it with Open a file. Returns the path, the counts and a warning for any reference whose file is missing.",
|
|
6614
6804
|
input: z.object({
|
|
6615
6805
|
projectId: z.string().uuid(),
|
|
6616
6806
|
path: z.string().min(1).describe('Absolute path to write, ending in .slatestemplate. Its folder is created if needed.'),
|
|
@@ -6637,7 +6827,7 @@ export const importTemplate = {
|
|
|
6637
6827
|
sceneIndices: z.array(z.number().int().min(0)).min(1).optional().describe('Import only these scene indices from the inspected parts, preserving their order. Omit for the whole template.'),
|
|
6638
6828
|
storyboardId: z.string().uuid().optional(),
|
|
6639
6829
|
sceneId: z.string().uuid().optional(),
|
|
6640
|
-
swaps: z.record(z.string().min(1)).optional().describe('{ "item:i1": "IMG-A12", "asset:a3": "<asset id>" }'),
|
|
6830
|
+
swaps: z.record(z.string().min(1)).optional().describe('{ "item:i1": "IMG-A12", "asset:a3": "<asset id>" }. An item swap also leaves out the template\'s extra pictures and colours for it.'),
|
|
6641
6831
|
useTemplateCategories: z
|
|
6642
6832
|
.boolean()
|
|
6643
6833
|
.optional()
|
|
@@ -6764,7 +6954,7 @@ export const getProductPage = {
|
|
|
6764
6954
|
export const importProduct = {
|
|
6765
6955
|
id: 'slates_import_product',
|
|
6766
6956
|
billable: false,
|
|
6767
|
-
description: "Add a product to the Library from its page, as the app's Add as product does: the product becomes a thing (in Products, or the things categoryId given) with the page's first picture as its picture, the next ones as its extra pictures and the page's bullet points, price and link as its notes; its brand becomes a look with the brand's logo as its picture and the page's and logo's colours as its palette. A look of the same name already in the Library is filled in where empty, never overwritten. Pictures land in a Media folder named after the product. Give url, filePaths (absolute paths to pictures on this computer, the product's first), or both. html is the page's HTML when you already have it (a page that builds itself with JavaScript, read in your own browser); url still names the page and its pictures are still fetched. Free; nothing is generated. The result gives the product and the brand with their mention (@name, #name) for prompts and for slates_break_down_reference roles (itemId), each picture and where it came from, each picture left out with its reason, and notes on what the page lacked.",
|
|
6957
|
+
description: "Add a product to the Library from its page, as the app's Add as product does: the product becomes a thing (in Products, or the things categoryId given) with the page's first picture as its picture, the next ones as its extra pictures and the page's bullet points, price and link as its notes; its brand becomes a look with the brand's logo as its picture and the page's and logo's colours as its palette. A look of the same name already in the Library is filled in where empty, never overwritten. Pictures land in a Media folder named after the product. Give url, filePaths (absolute paths to pictures on this computer, the product's first), or both. html is the page's HTML when you already have it (a page that builds itself with JavaScript, read in your own browser); url still names the page and its pictures are still fetched. itemId fills a thing already in the Library instead of making a product, as the card's Fill from the copied product page… does: the page's pictures go after its extra pictures (the first becomes its picture when it has none; a picture it holds is not added twice), its notes are filled only when empty, and its name and category stay; not with categoryId or name. Free; nothing is generated. The result gives the product and the brand with their mention (@name, #name) for prompts and for slates_break_down_reference roles (itemId), each picture and where it came from, each picture left out with its reason, and notes on what the page lacked.",
|
|
6768
6958
|
input: z
|
|
6769
6959
|
.object({
|
|
6770
6960
|
projectId: z.string().uuid(),
|
|
@@ -6773,6 +6963,7 @@ export const importProduct = {
|
|
|
6773
6963
|
filePaths: z.array(z.string().min(1)).optional().describe('Absolute paths to pictures of the product on this computer, first in the order given.'),
|
|
6774
6964
|
name: z.string().min(1).max(120).optional().describe("The product's name. Defaults to the page's, else the first file's."),
|
|
6775
6965
|
categoryId: z.string().uuid().optional().describe('A things category (slates_list_library) to file the product in. Defaults to Products.'),
|
|
6966
|
+
itemId: z.string().uuid().optional().describe('A thing already in the Library (slates_list_library) to fill from the page instead of making a product.'),
|
|
6776
6967
|
brand: z.boolean().optional().describe('false: make no look for the brand. Default true.'),
|
|
6777
6968
|
maxPictures: z.number().int().min(1).optional().describe('How many pictures to fetch from the page. Default 6; the desktop takes at most 12.'),
|
|
6778
6969
|
})
|
|
@@ -6783,10 +6974,16 @@ export const importProduct = {
|
|
|
6783
6974
|
throw new Error('Give url (the product page), filePaths (pictures on this computer), or both.');
|
|
6784
6975
|
if (input.html && !input.url)
|
|
6785
6976
|
throw new Error('html needs url: the address the page came from.');
|
|
6977
|
+
if (input.itemId) {
|
|
6978
|
+
await ctx.desktop().requireCapability('product-fill', 'filling an item already in the Library from a product page');
|
|
6979
|
+
if (input.categoryId || input.name)
|
|
6980
|
+
throw new Error('itemId fills an item that keeps its name and category: leave out categoryId and name.');
|
|
6981
|
+
}
|
|
6786
6982
|
const r = await ctx.desktop().post('/agent/library/intake', input);
|
|
6787
6983
|
const brand = r.brand ? ` Its brand ${r.brand.mention} ${r.brandReused ? 'was already in the Library and was filled in' : 'is a new look'}.` : '';
|
|
6788
6984
|
const left = r.skipped.length ? ` ${r.skipped.length} picture${r.skipped.length === 1 ? '' : 's'} left out (see skipped).` : '';
|
|
6789
|
-
const
|
|
6985
|
+
const pictures = `${r.pictures.length} ${r.filled ? 'more ' : ''}picture${r.pictures.length === 1 ? '' : 's'}`;
|
|
6986
|
+
const head = `${r.filled ? `Filled ${r.product.mention} with` : `Added ${r.product.mention} with`} ${pictures}.${brand}${left}${r.notes.length ? ` ${r.notes.join(' ')}` : ''}`;
|
|
6790
6987
|
return ok(r, `${head} ${JSON.stringify(r)}`);
|
|
6791
6988
|
},
|
|
6792
6989
|
};
|
|
@@ -8762,11 +8959,18 @@ export const ALL_OPERATIONS = [
|
|
|
8762
8959
|
getUsage,
|
|
8763
8960
|
getAppSettings,
|
|
8764
8961
|
setAppSettings,
|
|
8962
|
+
getSpendLimits,
|
|
8963
|
+
setSpendLimits,
|
|
8765
8964
|
getAsset,
|
|
8766
8965
|
linkAssetSource,
|
|
8767
8966
|
transcribeAsset,
|
|
8768
8967
|
getAssetTranscript,
|
|
8769
8968
|
editAssetTranscript,
|
|
8969
|
+
cutByTranscript,
|
|
8970
|
+
getBeatGrid,
|
|
8971
|
+
findBeats,
|
|
8972
|
+
editBeatGrid,
|
|
8973
|
+
cutToBeats,
|
|
8770
8974
|
extractVideoFrame,
|
|
8771
8975
|
getMe,
|
|
8772
8976
|
getCreditBalance,
|
|
@@ -188,6 +188,11 @@ export const OPERATION_GROUPS = {
|
|
|
188
188
|
'slates_transcribe_asset',
|
|
189
189
|
'slates_get_asset_transcript',
|
|
190
190
|
'slates_edit_asset_transcript',
|
|
191
|
+
'slates_cut_by_transcript',
|
|
192
|
+
'slates_get_beat_grid',
|
|
193
|
+
'slates_find_beats',
|
|
194
|
+
'slates_edit_beat_grid',
|
|
195
|
+
'slates_cut_to_beats',
|
|
191
196
|
'slates_add_html_clip',
|
|
192
197
|
'slates_update_html_clip',
|
|
193
198
|
'slates_check_composition',
|
|
@@ -222,6 +227,8 @@ export const OPERATION_GROUPS = {
|
|
|
222
227
|
'slates_get_usage',
|
|
223
228
|
'slates_get_app_settings',
|
|
224
229
|
'slates_set_app_settings',
|
|
230
|
+
'slates_get_spend_limits',
|
|
231
|
+
'slates_set_spend_limits',
|
|
225
232
|
],
|
|
226
233
|
// A third transport nobody without Blender installed can reach.
|
|
227
234
|
blender: [
|
|
@@ -256,9 +263,32 @@ export const GROUP_SUMMARY = {
|
|
|
256
263
|
library: 'folders, favorites, pins, the Library (user-named categories of saved references: characters, locations, products, looks) and styles, templates (list, export, import), exporting original asset files, moving and copying assets and Library items between projects, moving a project into the current projects folder, revealing files on disk',
|
|
257
264
|
script: 'rich script documents, anchored sections and their saved versions, reusable passages, variations and take input history',
|
|
258
265
|
timeline: 'named cuts and exporting several at once, what made an exported ad (its recipe ID); the timeline (tracks, clips, markers, settings), text, picture and HTML motion layers, captions, video export and FCP7 XML export for DaVinci Resolve or Premiere, clip trimming',
|
|
259
|
-
admin: 'rename / delete / reorder for projects, characters, locations, looks, boards, scenes and frames; shot duplicate, split and merge',
|
|
266
|
+
admin: 'rename / delete / reorder for projects, characters, locations, looks, boards, scenes and frames; shot duplicate, split and merge; spend limits',
|
|
260
267
|
blender: 'the Blender previs bridge — scene inspection, bpy execution, API docs, grey-box render',
|
|
261
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* zod-to-json-schema writes a tuple the draft-07 way, `items: [a, b]`. Claude's API reads tool
|
|
271
|
+
* schemas as draft 2020-12, where `items` must be one schema, so it refuses the whole request with
|
|
272
|
+
* a 400 (and Claude Code drops the tool). 2020-12 spells a tuple `prefixItems`, with `items` taking
|
|
273
|
+
* the old `additionalItems`. Receipt: 2026-10-26, five tools (the keyframe easing's `cubicBezier`,
|
|
274
|
+
* caption `phrases`) unusable in Claude Code and the Studio Agent since 0.6.3.
|
|
275
|
+
*/
|
|
276
|
+
function draft2020Tuples(node) {
|
|
277
|
+
if (Array.isArray(node))
|
|
278
|
+
return node.forEach(draft2020Tuples);
|
|
279
|
+
if (!node || typeof node !== 'object')
|
|
280
|
+
return;
|
|
281
|
+
const n = node;
|
|
282
|
+
if (Array.isArray(n.items)) {
|
|
283
|
+
n.prefixItems = n.items;
|
|
284
|
+
if ('additionalItems' in n)
|
|
285
|
+
n.items = n.additionalItems;
|
|
286
|
+
else
|
|
287
|
+
delete n.items;
|
|
288
|
+
delete n.additionalItems;
|
|
289
|
+
}
|
|
290
|
+
Object.values(n).forEach(draft2020Tuples);
|
|
291
|
+
}
|
|
262
292
|
/**
|
|
263
293
|
* Render one op's tool definition.
|
|
264
294
|
*
|
|
@@ -270,6 +300,7 @@ export const GROUP_SUMMARY = {
|
|
|
270
300
|
export function toolDefinition(op) {
|
|
271
301
|
const schema = zodToJsonSchema(op.input, { $refStrategy: 'none' });
|
|
272
302
|
delete schema.$schema;
|
|
303
|
+
draft2020Tuples(schema);
|
|
273
304
|
// zod-to-json-schema 3 renders a zod 4 schema as `{}`, without an error. That
|
|
274
305
|
// happens when this package resolves the consumer's zod 4 instead of its own
|
|
275
306
|
// zod 3: slate's install lost `node_modules/@slatesvideo/shared/node_modules/zod`
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This is NOT a model capability or provider batch limit. Desktop mirror is
|
|
3
3
|
* generated by slate/scripts/sync-generation-policy.mjs; never edit it there. */
|
|
4
4
|
export declare const IMAGE_QUANTITIES: readonly [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
5
|
-
export declare const MAX_IMAGE_VARIATIONS:
|
|
5
|
+
export declare const MAX_IMAGE_VARIATIONS: 1 | 2 | 9 | 10 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
6
6
|
export type ImageQuantity = typeof IMAGE_QUANTITIES[number];
|
|
7
7
|
export declare const clampImageQuantity: (count?: number) => ImageQuantity;
|
|
8
8
|
/** Default saved-recipe framing, shared by composer restore, quote and dispatch. */
|
|
@@ -65,8 +65,9 @@ export function overlaps(skills, n) {
|
|
|
65
65
|
return pairs;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Each bundled run of words and the files that hold it, built once per bundled record
|
|
69
|
-
*
|
|
68
|
+
* Each bundled run of words and the files that hold it, built once per bundled record (`brainFiles()` returns one
|
|
69
|
+
* object per served file set) and only when a file reaches the check: the loader checks the user's files against
|
|
70
|
+
* all of them on every load, and re-reading tens of thousands of words each time is waste.
|
|
70
71
|
*/
|
|
71
72
|
const bundledIndexes = new WeakMap();
|
|
72
73
|
function bundledIndex(bundled, n) {
|
|
@@ -111,7 +112,7 @@ export function myBrainProblems(files, { shape, bundled = {}, order = Object.key
|
|
|
111
112
|
const caps = shape.caps.mine;
|
|
112
113
|
const n = shape.duplicates.shingleWords;
|
|
113
114
|
const failAt = shape.duplicates.failAt;
|
|
114
|
-
|
|
115
|
+
let index;
|
|
115
116
|
const kept = [];
|
|
116
117
|
let total = 0;
|
|
117
118
|
for (const name of order) {
|
|
@@ -132,6 +133,7 @@ export function myBrainProblems(files, { shape, bundled = {}, order = Object.key
|
|
|
132
133
|
// How many of this file's runs each bundled skill holds, then each of their files already kept.
|
|
133
134
|
const hits = [];
|
|
134
135
|
const inBundled = new Map();
|
|
136
|
+
index ??= bundledIndex(bundled, n);
|
|
135
137
|
for (const key of runs) {
|
|
136
138
|
for (const other of index.get(key) ?? []) {
|
|
137
139
|
const hit = inBundled.get(other) ?? { count: 0, sample: key };
|
package/dist/skills/served.d.ts
CHANGED
|
@@ -24,7 +24,10 @@ export interface ServedBrain {
|
|
|
24
24
|
export declare const BRAIN_CACHE: string;
|
|
25
25
|
/** The brain this process holds now. */
|
|
26
26
|
export declare function servedBrain(): ServedBrain;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Every skill an agent can read here: the public card and router, then the served brain. One object per served
|
|
29
|
+
* file set, so what is built from it once (My brain's duplicate index, brain-check.ts) is found again.
|
|
30
|
+
*/
|
|
28
31
|
export declare function brainFiles(): Readonly<Record<string, string>>;
|
|
29
32
|
interface CloudGet {
|
|
30
33
|
get<T>(path: string): Promise<T>;
|
|
@@ -34,7 +37,8 @@ interface CloudGet {
|
|
|
34
37
|
/**
|
|
35
38
|
* Bring the brain up to the account's tiers and the approved version, one request in flight and at most every
|
|
36
39
|
* REFRESH_EVERY_MS unless forced. A failure keeps what is held (the cache works offline) and records why; a folder
|
|
37
|
-
* source never refreshes.
|
|
40
|
+
* source never refreshes. A sign-out during it wins: the credential it started with still answers the server (a
|
|
41
|
+
* sign-out deletes it locally only), so what it fetched is dropped, neither held nor written to the cache.
|
|
38
42
|
*/
|
|
39
43
|
export declare function refreshServedBrain(cloud: () => CloudGet, { force }?: {
|
|
40
44
|
force?: boolean | undefined;
|
package/dist/skills/served.js
CHANGED
|
@@ -70,13 +70,23 @@ else
|
|
|
70
70
|
({ state, held } = startingCache());
|
|
71
71
|
let checkedAt = 0;
|
|
72
72
|
let inflight;
|
|
73
|
+
/** Bumped by a sign-out or a source change: a refresh started before it drops what it fetched. */
|
|
74
|
+
let generation = 0;
|
|
73
75
|
/** The brain this process holds now. */
|
|
74
76
|
export function servedBrain() {
|
|
75
77
|
return state;
|
|
76
78
|
}
|
|
77
|
-
|
|
79
|
+
let merged = null;
|
|
80
|
+
/**
|
|
81
|
+
* Every skill an agent can read here: the public card and router, then the served brain. One object per served
|
|
82
|
+
* file set, so what is built from it once (My brain's duplicate index, brain-check.ts) is found again.
|
|
83
|
+
*/
|
|
78
84
|
export function brainFiles() {
|
|
79
|
-
|
|
85
|
+
if (state.files === EMPTY.files)
|
|
86
|
+
return SKILLS;
|
|
87
|
+
if (merged?.files !== state.files)
|
|
88
|
+
merged = { files: state.files, all: { ...SKILLS, ...state.files } };
|
|
89
|
+
return merged.all;
|
|
80
90
|
}
|
|
81
91
|
/** Write what this process holds to BRAIN_CACHE, tagged with the credential that fetched it. */
|
|
82
92
|
function writeCache(key) {
|
|
@@ -98,14 +108,19 @@ function writeCache(key) {
|
|
|
98
108
|
/**
|
|
99
109
|
* Bring the brain up to the account's tiers and the approved version, one request in flight and at most every
|
|
100
110
|
* REFRESH_EVERY_MS unless forced. A failure keeps what is held (the cache works offline) and records why; a folder
|
|
101
|
-
* source never refreshes.
|
|
111
|
+
* source never refreshes. A sign-out during it wins: the credential it started with still answers the server (a
|
|
112
|
+
* sign-out deletes it locally only), so what it fetched is dropped, neither held nor written to the cache.
|
|
102
113
|
*/
|
|
103
114
|
export function refreshServedBrain(cloud, { force = false } = {}) {
|
|
104
115
|
if (state.source === 'dir')
|
|
105
116
|
return Promise.resolve(state);
|
|
106
117
|
if (!force && Date.now() - checkedAt < REFRESH_EVERY_MS)
|
|
107
118
|
return Promise.resolve(state);
|
|
108
|
-
|
|
119
|
+
if (inflight)
|
|
120
|
+
return inflight;
|
|
121
|
+
const started = generation;
|
|
122
|
+
const stale = () => started !== generation;
|
|
123
|
+
const run = (async () => {
|
|
109
124
|
let timer;
|
|
110
125
|
const timeout = (p) => Promise.race([p, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error('the brain check timed out')), REFRESH_TIMEOUT_MS); })])
|
|
111
126
|
.finally(() => clearTimeout(timer));
|
|
@@ -114,12 +129,16 @@ export function refreshServedBrain(cloud, { force = false } = {}) {
|
|
|
114
129
|
const client = cloud();
|
|
115
130
|
key = client.credentialKey ?? cliKey();
|
|
116
131
|
const index = await timeout(client.get('/brain'));
|
|
132
|
+
if (stale())
|
|
133
|
+
return state;
|
|
117
134
|
const same = (b) => index.version === b.version && index.tiers.join() === b.tiers.join() && (index.account ?? null) === (b.account ?? null);
|
|
118
135
|
if (held && same(held))
|
|
119
136
|
state = { ...held, source: 'server' };
|
|
120
137
|
held = null;
|
|
121
138
|
if (!same(state)) {
|
|
122
139
|
const bundle = await timeout(client.get('/brain/bundle'));
|
|
140
|
+
if (stale())
|
|
141
|
+
return state;
|
|
123
142
|
if (!bundle?.files || typeof bundle.files !== 'object')
|
|
124
143
|
throw new Error('the brain bundle was malformed');
|
|
125
144
|
state = { version: bundle.version, tiers: bundle.tiers, files: bundle.files, locked: bundle.locked ?? [], source: 'server', account: bundle.account ?? null };
|
|
@@ -135,6 +154,9 @@ export function refreshServedBrain(cloud, { force = false } = {}) {
|
|
|
135
154
|
checkedAt = Date.now();
|
|
136
155
|
}
|
|
137
156
|
catch (error) {
|
|
157
|
+
// Signed out meanwhile: the sign-out already set what is held, the cache and the next check.
|
|
158
|
+
if (stale())
|
|
159
|
+
return state;
|
|
138
160
|
// Offline or signed out: the held brain stands, and the next try waits a minute, not a full interval.
|
|
139
161
|
checkedAt = Date.now() - REFRESH_EVERY_MS + 60_000;
|
|
140
162
|
const code = error;
|
|
@@ -165,9 +187,12 @@ export function refreshServedBrain(cloud, { force = false } = {}) {
|
|
|
165
187
|
})().finally(() => {
|
|
166
188
|
// Cleared after the assignment: a refresh with nothing to await (no login, so `cloud()` throws at once) used to
|
|
167
189
|
// clear it inside the body, before `??=` stored the settled promise, and every later call got that first answer.
|
|
168
|
-
|
|
190
|
+
// Only its own: a sign-out let a newer refresh start, which this one must not orphan.
|
|
191
|
+
if (inflight === run)
|
|
192
|
+
inflight = undefined;
|
|
169
193
|
});
|
|
170
|
-
|
|
194
|
+
inflight = run;
|
|
195
|
+
return run;
|
|
171
196
|
}
|
|
172
197
|
/**
|
|
173
198
|
* Signing out: drop the served brain in this process, and the cache when the login signing out received it. The
|
|
@@ -181,6 +206,9 @@ export function clearServedBrain(signingOut = 'desktop') {
|
|
|
181
206
|
state = EMPTY;
|
|
182
207
|
held = null;
|
|
183
208
|
checkedAt = 0;
|
|
209
|
+
// A refresh in flight belongs to the account signing out: it drops its answer, and the next one starts afresh.
|
|
210
|
+
generation++;
|
|
211
|
+
inflight = undefined;
|
|
184
212
|
const cli = cliKey();
|
|
185
213
|
const cliReceived = !!cli && fromCache()?.token === cli;
|
|
186
214
|
if (cliReceived === (signingOut === 'cli'))
|
|
@@ -197,6 +225,8 @@ export function useBrainSource(dir) {
|
|
|
197
225
|
({ state, held } = startingCache());
|
|
198
226
|
}
|
|
199
227
|
checkedAt = 0;
|
|
228
|
+
generation++;
|
|
229
|
+
inflight = undefined;
|
|
200
230
|
return state;
|
|
201
231
|
}
|
|
202
232
|
//# sourceMappingURL=served.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slatesvideo/shared",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.10",
|
|
4
4
|
"description": "Shared operations layer for the Slates MCP server and CLI: auth, cloud/desktop clients, and the single tool surface both consume. Most users want @slatesvideo/mcp-server or @slatesvideo/cli instead.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|