@slatesvideo/shared 0.7.8 → 0.7.9

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.
@@ -614,6 +614,15 @@ type AppSettingsPatch = {
614
614
  studioAgentClaudeEffort?: string;
615
615
  };
616
616
  export declare const setAppSettings: Operation<AppSettingsPatch>;
617
+ export declare const getSpendLimits: Operation<{
618
+ projectId?: string;
619
+ }>;
620
+ export declare const setSpendLimits: Operation<{
621
+ projectId?: string;
622
+ projectLimitCredits?: number | null;
623
+ sessionBudgetCredits?: number | null;
624
+ confirm?: boolean;
625
+ }>;
617
626
  export declare const getAsset: Operation<{
618
627
  projectId: string;
619
628
  assetId: string;
@@ -638,6 +647,118 @@ export declare const editAssetTranscript: Operation<{
638
647
  text: string;
639
648
  recaption?: boolean;
640
649
  }>;
650
+ export declare const cutByTranscript: Operation<{
651
+ projectId: string;
652
+ clipId: string;
653
+ words?: Array<{
654
+ from: number;
655
+ to: number;
656
+ }>;
657
+ pauses?: number[];
658
+ ranges?: Array<{
659
+ startSec: number;
660
+ endSec: number;
661
+ }>;
662
+ linked?: boolean;
663
+ trackIds?: string[];
664
+ }>;
665
+ type BeatTargetInput = {
666
+ projectId: string;
667
+ assetId?: string;
668
+ clipId?: string;
669
+ };
670
+ export declare const getBeatGrid: Operation<BeatTargetInput & {
671
+ picture?: boolean;
672
+ fromSec?: number;
673
+ toSec?: number;
674
+ }>;
675
+ export declare const findBeats: Operation<BeatTargetInput>;
676
+ declare const beatEditInput: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
677
+ kind: z.ZodLiteral<"shift">;
678
+ sec: z.ZodNumber;
679
+ }, "strict", z.ZodTypeAny, {
680
+ kind: "shift";
681
+ sec: number;
682
+ }, {
683
+ kind: "shift";
684
+ sec: number;
685
+ }>, z.ZodObject<{
686
+ kind: z.ZodLiteral<"downbeat">;
687
+ at: z.ZodNumber;
688
+ beatsPerBar: z.ZodOptional<z.ZodNumber>;
689
+ }, "strict", z.ZodTypeAny, {
690
+ at: number;
691
+ kind: "downbeat";
692
+ beatsPerBar?: number | undefined;
693
+ }, {
694
+ at: number;
695
+ kind: "downbeat";
696
+ beatsPerBar?: number | undefined;
697
+ }>, z.ZodObject<{
698
+ kind: z.ZodLiteral<"tempo">;
699
+ fromSec: z.ZodNumber;
700
+ toSec: z.ZodNumber;
701
+ bpm: z.ZodNumber;
702
+ }, "strict", z.ZodTypeAny, {
703
+ kind: "tempo";
704
+ fromSec: number;
705
+ toSec: number;
706
+ bpm: number;
707
+ }, {
708
+ kind: "tempo";
709
+ fromSec: number;
710
+ toSec: number;
711
+ bpm: number;
712
+ }>, z.ZodObject<{
713
+ kind: z.ZodLiteral<"add">;
714
+ at: z.ZodNumber;
715
+ downbeat: z.ZodOptional<z.ZodBoolean>;
716
+ }, "strict", z.ZodTypeAny, {
717
+ at: number;
718
+ kind: "add";
719
+ downbeat?: boolean | undefined;
720
+ }, {
721
+ at: number;
722
+ kind: "add";
723
+ downbeat?: boolean | undefined;
724
+ }>, z.ZodObject<{
725
+ kind: z.ZodLiteral<"move">;
726
+ from: z.ZodNumber;
727
+ to: z.ZodNumber;
728
+ }, "strict", z.ZodTypeAny, {
729
+ kind: "move";
730
+ from: number;
731
+ to: number;
732
+ }, {
733
+ kind: "move";
734
+ from: number;
735
+ to: number;
736
+ }>, z.ZodObject<{
737
+ kind: z.ZodLiteral<"delete">;
738
+ at: z.ZodNumber;
739
+ }, "strict", z.ZodTypeAny, {
740
+ at: number;
741
+ kind: "delete";
742
+ }, {
743
+ at: number;
744
+ kind: "delete";
745
+ }>]>;
746
+ export declare const editBeatGrid: Operation<BeatTargetInput & {
747
+ edits?: Array<z.infer<typeof beatEditInput>>;
748
+ undo?: boolean;
749
+ clearEdits?: boolean;
750
+ }>;
751
+ export declare const cutToBeats: Operation<{
752
+ projectId: string;
753
+ musicClipId: string;
754
+ trackId?: string;
755
+ mode?: 'snap' | 'split';
756
+ on?: 'beat' | 'downbeat';
757
+ every?: number;
758
+ fromFrame?: number;
759
+ toFrame?: number;
760
+ reachFrames?: number;
761
+ }>;
641
762
  export declare const extractVideoFrame: Operation<{
642
763
  projectId: string;
643
764
  assetId: string;
@@ -1626,7 +1747,7 @@ declare const reframeClipInput: z.ZodObject<{
1626
1747
  aspect: z.ZodString;
1627
1748
  } & {
1628
1749
  clipId: z.ZodString;
1629
- framing: z.ZodNullable<z.ZodObject<{
1750
+ framing: z.ZodOptional<z.ZodNullable<z.ZodObject<{
1630
1751
  mode: z.ZodOptional<z.ZodEnum<["fill", "fit"]>>;
1631
1752
  focusX: z.ZodOptional<z.ZodNumber>;
1632
1753
  focusY: z.ZodOptional<z.ZodNumber>;
@@ -1641,29 +1762,32 @@ declare const reframeClipInput: z.ZodObject<{
1641
1762
  focusX?: number | undefined;
1642
1763
  focusY?: number | undefined;
1643
1764
  zoom?: number | undefined;
1644
- }>>;
1765
+ }>>>;
1766
+ follow: z.ZodOptional<z.ZodEnum<["face", "off"]>>;
1645
1767
  }, "strict", z.ZodTypeAny, {
1646
1768
  projectId: string;
1647
1769
  timelineId: string;
1648
- aspect: string;
1649
1770
  clipId: string;
1650
- framing: {
1771
+ aspect: string;
1772
+ framing?: {
1651
1773
  mode?: "fill" | "fit" | undefined;
1652
1774
  focusX?: number | undefined;
1653
1775
  focusY?: number | undefined;
1654
1776
  zoom?: number | undefined;
1655
- } | null;
1777
+ } | null | undefined;
1778
+ follow?: "face" | "off" | undefined;
1656
1779
  }, {
1657
1780
  projectId: string;
1658
1781
  timelineId: string;
1659
- aspect: string;
1660
1782
  clipId: string;
1661
- framing: {
1783
+ aspect: string;
1784
+ framing?: {
1662
1785
  mode?: "fill" | "fit" | undefined;
1663
1786
  focusX?: number | undefined;
1664
1787
  focusY?: number | undefined;
1665
1788
  zoom?: number | undefined;
1666
- } | null;
1789
+ } | null | undefined;
1790
+ follow?: "face" | "off" | undefined;
1667
1791
  }>;
1668
1792
  export declare const reframeClip: Operation<z.infer<typeof reframeClipInput>>;
1669
1793
  export declare const listTimelines: Operation<{
@@ -2253,6 +2377,7 @@ export declare const importProduct: Operation<{
2253
2377
  filePaths?: string[];
2254
2378
  name?: string;
2255
2379
  categoryId?: string;
2380
+ itemId?: string;
2256
2381
  brand?: boolean;
2257
2382
  maxPictures?: number;
2258
2383
  }>;
@@ -2839,14 +2964,14 @@ declare const writeScriptDocumentInput: z.ZodObject<{
2839
2964
  sceneId: string;
2840
2965
  }>]>>;
2841
2966
  }, "strip", z.ZodTypeAny, {
2842
- storyboardId: string;
2843
- expectedRevision: number;
2844
2967
  edits: {
2845
2968
  at: number;
2846
2969
  text: string;
2847
2970
  sceneId: string;
2848
2971
  removed: number;
2849
2972
  }[];
2973
+ storyboardId: string;
2974
+ expectedRevision: number;
2850
2975
  move?: {
2851
2976
  sceneId: string;
2852
2977
  blockId: string;
@@ -2885,14 +3010,14 @@ declare const writeScriptDocumentInput: z.ZodObject<{
2885
3010
  sceneId: string;
2886
3011
  } | undefined;
2887
3012
  }, {
2888
- storyboardId: string;
2889
- expectedRevision: number;
2890
3013
  edits: {
2891
3014
  at: number;
2892
3015
  text: string;
2893
3016
  sceneId: string;
2894
3017
  removed: number;
2895
3018
  }[];
3019
+ storyboardId: string;
3020
+ expectedRevision: number;
2896
3021
  move?: {
2897
3022
  sceneId: string;
2898
3023
  blockId: string;
@@ -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
- super(body !== undefined || served.locked.some(entry => entry.name === guide)
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
- : // No copy here and none locked: the brain never arrived, so asking for the guide again cannot help.
106
- head +
107
- `The guide comes from the connected Slates account and is not on this machine (${served.problem ?? 'no brain received yet'}). ` +
108
- `${CONNECT_FOR_BRAIN}; then call slates_get_prompting_guide with topic "${guide}" and call this again.`);
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 and fonts by their path in the project's folder (images/logo.svg, fonts/Brand.woff2; 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(),
@@ -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 head = `Added ${r.product.mention} with ${r.pictures.length} picture${r.pictures.length === 1 ? '' : 's'}.${brand}${left}${r.notes.length ? ` ${r.notes.join(' ')}` : ''}`;
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,7 +263,7 @@ 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
  };
262
269
  /**
@@ -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: the loader checks the
69
- * user's files against all of them on every load, and re-reading tens of thousands of words each time is waste.
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
- const index = bundledIndex(bundled, n);
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 };