// THE VIDEO ASSISTANT'S OPS (release 38 lane E): "make the joins 0.15 s with // less smear" as checked edits of a video project's manifest. A model (or a // Claude Code session, or nobody: every op is also a field of the Look panel // or the clip editor) proposes them; code checks each against the manifest // as it is; the operator applies them. Nothing here writes a file. // // look {key, value} a LOOK_KEYS render key (common look.mjs), checked by applyLookPatch // slide {travel?, blur?, grain?} the blur slide's knobs, within SLIDE_BOUNDS // room {tail?, head?, maxS?, minGap?} room at the clips' edges, within ROOM_BOUNDS // clip_edges {id, start?, end?} a clip's cut, in source seconds: inside the clip's source // window and at most EDGE_SLACK_SECONDS from where it is, // unless the request itself names more seconds // clip_room {id, tail?, head?, off?, reset?} one clip's room (off: none; reset: the cut's again) // fx {id, param, value} a DECLARED param of a composition the cut draws // (./fxParams.mjs) -- never free HTML // // Each op is applied in turn to a COPY of the manifest, so a later op is // checked against the earlier ones; a refused op refuses itself only, with its // reason. Each kept op carries a diff line ("join 0.22 s → 0.15 s") and the // writer that performs it (`apply`): umtool's updateRender for the look, the // clip editor's writer (runClipEditorOp trim / room) for a clip, updateChrome // for a composition. umtool re-checks an op against the manifest at Apply // time (checkAssistOps on it again), so a proposal made against an older // manifest is applied to the current one or refused -- never written blind. // // PURE. Plain ESM with a .d.mts beside it. import { LOOK_KEYS, LOUDNESS_MAX, LOUDNESS_MIN, ROOM, ROOM_BOUNDS, SLIDE_BOUNDS, SLIDE_DEFAULTS, TRANSITION_DEFAULT, TRANSITION_MAX, TRANSITION_STYLES, applyLookPatch, clipRoom, validateRoom, } from "./look.mjs"; import { COMPOSITION_PARAMS, chromeWithParam, compositionOn, compositionsOn, paramOf, paramValue, paramValueError } from "./fxParams.mjs"; export const ASSIST_OP_NAMES = Object.freeze(["look", "slide", "room", "clip_edges", "clip_room", "fx"]); export const ASSIST_SCOPES = Object.freeze(["look", "clips", "fx", "all"]); /** A clip's edge moves at most this far (s) in one op, unless the request names more seconds. */ export const EDGE_SLACK_SECONDS = 3; /** The shortest cut a clip may have (the clip editor's writer refuses less). */ export const MIN_CUT_SECONDS = 0.5; const SCOPE_OF = Object.freeze({ look: "look", slide: "look", room: "look", clip_edges: "clips", clip_room: "clips", fx: "fx" }); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const fin = (v) => typeof v === "number" && Number.isFinite(v); const r2 = (n) => Math.round(n * 100) / 100; const s2 = (n) => r2(n).toFixed(2).replace(/\.?0+$/, "") || "0"; class Refusal extends Error {} const refuse = (why) => { throw new Refusal(why); }; /** A number from what a model wrote ("0.15", "0.15 s", 0.15). */ function numOf(v, what) { if (fin(v)) return v; if (typeof v === "string") { const m = /^\s*(-?\d+(?:\.\d+)?)\s*(?:s|sec|secs|seconds?|lufs|px)?\s*$/i.exec(v); if (m) return Number(m[1]); } return refuse(`${what} must be a number`); } const boolOf = (v, what) => { if (typeof v === "boolean") return v; if (v === "on" || v === "true") return true; if (v === "off" || v === "false") return false; return refuse(`${what} must be true or false`); }; /** The most seconds the request names ("the first 5 seconds", "2.5 s"), or 0. */ export function secondsNamedIn(request) { let most = 0; for (const m of String(request ?? "").matchAll(/(\d+(?:\.\d+)?)\s*(?:s|secs?|seconds?)\b/gi)) most = Math.max(most, Number(m[1])); return most; } // --------------------------------------------------------------------------- // What each setting is called in a diff line. // --------------------------------------------------------------------------- const STYLE_WORDS = Object.freeze({ fade: "crossfade", fadeblack: "dip to black", fadewhite: "dip to white", dissolve: "dissolve", blurslide: "blur slide" }); /** A look key's value as a person reads it. */ export function lookWords(key, value, render = {}) { switch (key) { case "transition": return value === undefined || value === null ? `${s2(TRANSITION_DEFAULT)} s` : Number(value) === 0 ? "a hard cut" : `${s2(Number(value))} s`; case "transitionStyle": return STYLE_WORDS[value ?? "fade"] ?? String(value); case "headerHeight": case "footerHeight": return value === 0 ? "off" : value === undefined || value === null ? "on" : `${value} px`; case "qr": return value === false ? "off" : "on"; case "loudness": return isObj(value) && fin(value.target) ? `${s2(value.target)} LUFS` : "as recorded"; case "captions": return isObj(value) ? `on${value.size === "l" ? " (large)" : ""}` : "off"; case "room": { const r = isObj(value) ? value : {}; const edges = ["tail", "head"].filter((k) => r[k] === true); return edges.length ? edges.join(" + ") : "off"; } case "blur": return value === "off" ? "uncensored (no clip blurred)" : "blurred where a clip asks"; case "slide": { const s = { ...SLIDE_DEFAULTS, ...(isObj(value) ? value : {}) }; return `travel ${s2(s.travel)}, smear ${s2(s.blur)}, grain ${s2(s.grain)}`; } default: return JSON.stringify(value ?? null); } } const LOOK_LABEL = Object.freeze({ transition: "join", transitionStyle: "join style", headerHeight: "header", footerHeight: "timeline footer", qr: "QR code", loudness: "loudness", captions: "speaker captions", room: "room at the edges", slide: "blur slide", blur: "blurred clips", }); const SLIDE_LABEL = Object.freeze({ travel: "slide travel", blur: "smear", grain: "grain" }); const ROOM_LABEL = Object.freeze({ tail: "room tail", head: "room head", maxS: "room tail up to", minGap: "room's silence gap" }); const onOff = (b) => (b ? "on" : "off"); const arrow = (label, from, to) => `${label} ${from} → ${to}`; // --------------------------------------------------------------------------- // One op, normalised and checked against the manifest as it is. // --------------------------------------------------------------------------- /** A clip's cut and the window it may move in. */ export function clipWindow(entry, render = {}) { const hasCut = fin(entry.cutStart) && fin(entry.cutEnd); const cut = { start: hasCut ? entry.cutStart : entry.start, end: hasCut ? entry.cutEnd : entry.end }; // A clip with a cut moves inside its extent (start–end, what was reviewed // and fetched); one without inside its edges widened by the fetch pad. const pad = hasCut ? 0 : fin(render.fetchPad) ? render.fetchPad : 0; const lo = Math.max(0, (fin(entry.start) ? entry.start : cut.start) - pad); const hi = (fin(entry.end) ? entry.end : cut.end) + pad; return { cut, window: { start: r2(lo), end: r2(hi) }, hasCut }; } const clipOf = (manifest, id) => { if (typeof id !== "string" || !id) refuse("a clip op names its clip (id)"); const e = (manifest.timeline ?? []).find((x) => x?.id === id); if (!e) refuse(`no clip "${id}" in the cut`); if (e.type !== "clip") refuse(`"${id}" is a ${e.type ?? "non-clip"} entry, not a clip`); return e; }; /** A look key's patch value from what a model wrote. */ function lookValueOf(key, value, render) { if (value === null) return null; switch (key) { case "transition": return numOf(value, "the join's length"); case "headerHeight": case "footerHeight": if (typeof value === "boolean") return value ? null : 0; return numOf(value, `the ${LOOK_LABEL[key]}'s height`); case "qr": return boolOf(value, "the QR code"); case "loudness": if (value === false || value === "off") return null; if (isObj(value)) return { target: numOf(value.target, "the loudness target") }; return { target: numOf(value, "the loudness target") }; case "captions": if (value === true || value === "on") return isObj(render.captions) ? render.captions : { style: "speakers" }; if (value === false || value === "off") return null; return value; case "room": if (value === false || value === "off") return null; if (isObj(value)) return { ...(isObj(render.room) ? render.room : {}), ...value }; return value; case "slide": if (isObj(value)) return { ...(isObj(render.slide) ? render.slide : {}), ...value }; return value; default: return value; } } /** * One op against `manifest` (mutated: the op's effect is applied to it). * Returns `{ op, diff, apply }` or throws a Refusal. */ function checkOne(manifest, raw, ctx) { const op = isObj(raw) ? raw : refuse("an op is an object"); const name = op.op; if (!ASSIST_OP_NAMES.includes(name)) refuse(`no op "${String(name)}" — the ops are ${ASSIST_OP_NAMES.join(", ")}`); if (ctx.scope !== "all" && SCOPE_OF[name] !== ctx.scope) refuse(`a ${name} op is outside what was asked about (${ctx.scope})`); const render = isObj(manifest.render) ? manifest.render : {}; const montage = render.montage !== undefined && render.montage !== null; const lookPatch = (patch, diff, norm, label) => { const r = applyLookPatch(manifest, patch); if (r.errors.length) refuse(r.errors.join("; ")); if (JSON.stringify(r.render) === JSON.stringify(render)) refuse(`${label} is already that`); manifest.render = r.render; return { op: norm, diff, apply: { writer: "render", patch } }; }; switch (name) { case "look": { const key = typeof op.key === "string" ? op.key.trim() : ""; if (!LOOK_KEYS.includes(key)) refuse(`"${key}" is not a look setting (${LOOK_KEYS.join(", ")})`); if (montage && (key === "loudness" || key === "captions" || key === "room")) refuse(`a montage has no ${LOOK_LABEL[key]} of the look's (render.montage sets its own)`); const value = lookValueOf(key, op.value, render); const after = value === null ? undefined : value; const diff = arrow(LOOK_LABEL[key], lookWords(key, render[key], render), lookWords(key, after, render)); return lookPatch({ [key]: value }, diff, { op: "look", key, value }, LOOK_LABEL[key]); } case "slide": { const given = Object.keys(SLIDE_BOUNDS).filter((k) => op[k] !== undefined && op[k] !== null); if (!given.length) refuse("a slide op sets travel, blur (the smear) or grain"); const was = { ...SLIDE_DEFAULTS, ...(isObj(render.slide) ? render.slide : {}) }; const next = { ...(isObj(render.slide) ? render.slide : {}) }; const parts = []; for (const k of given) { const v = numOf(op[k], SLIDE_LABEL[k]); const [lo, hi] = SLIDE_BOUNDS[k]; if (v < lo || v > hi) refuse(`${SLIDE_LABEL[k]} ${s2(v)} is outside ${lo}–${hi}`); next[k] = r2(v); if (r2(v) !== r2(was[k])) parts.push(arrow(SLIDE_LABEL[k], s2(was[k]), s2(v))); } if (!parts.length) refuse(`the blur slide is already ${given.map((k) => `${SLIDE_LABEL[k]} ${s2(was[k])}`).join(", ")}`); const style = render.transitionStyle ?? "fade"; const r = lookPatch({ slide: next }, parts.join(", "), { op: "slide", ...Object.fromEntries(given.map((k) => [k, next[k]])) }, "the blur slide"); // The knobs move a blur slide only: say so rather than let it look like it worked. return style === "blurslide" ? r : { ...r, warning: `the join is a ${STYLE_WORDS[style] ?? style}: the slide's knobs show once the join style is blur slide` }; } case "room": { if (montage) refuse("a montage has no room at the edges (it cuts to its phrases)"); const was = isObj(render.room) ? render.room : {}; const next = { ...was }; const parts = []; for (const k of ["tail", "head"]) { if (op[k] === undefined || op[k] === null) continue; // "keep 2 s after the last word": a number for the tail is the tail on, up to that. if (k === "tail" && typeof op[k] !== "boolean" && op.maxS === undefined) { const n = numOf(op[k], "the room's tail"); next.tail = true; op.maxS = n; } else next[k] = boolOf(op[k], ROOM_LABEL[k]); if ((was[k] === true) !== next[k]) parts.push(arrow(ROOM_LABEL[k], onOff(was[k] === true), onOff(next[k]))); } for (const k of ["maxS", "minGap"]) { if (op[k] === undefined || op[k] === null) continue; const v = numOf(op[k], ROOM_LABEL[k]); const [lo, hi] = ROOM_BOUNDS[k]; if (v < lo || v > hi) refuse(`${ROOM_LABEL[k]} ${s2(v)} s is outside ${lo}–${hi} s`); next[k] = r2(v); const before = fin(was[k]) ? was[k] : ROOM[k]; if (r2(before) !== r2(v)) parts.push(arrow(ROOM_LABEL[k], `${s2(before)} s`, `${s2(v)} s`)); } if (!parts.length) refuse("the room is already that"); if (next.tail !== true && next.head !== true && (next.maxS !== undefined || next.minGap !== undefined) && op.tail === undefined && op.head === undefined) { // A number for an edge that is off would do nothing: turn the tail on with it. next.tail = true; op.tail = true; parts.unshift(arrow(ROOM_LABEL.tail, "off", "on")); } const norm = { op: "room", ...Object.fromEntries(["tail", "head", "maxS", "minGap"].filter((k) => op[k] !== undefined && op[k] !== null).map((k) => [k, next[k]])) }; const r = lookPatch({ room: next }, parts.join(", "), norm, "the room"); return (render.transition ?? TRANSITION_DEFAULT) === 0 ? { ...r, warning: "the cut has hard cuts (join 0 s): room needs a join to make room for" } : r; } case "clip_edges": { const e = clipOf(manifest, op.id); const { cut, window } = clipWindow(e, render); const start = op.start === undefined || op.start === null ? cut.start : r2(numOf(op.start, "the clip's in")); const end = op.end === undefined || op.end === null ? cut.end : r2(numOf(op.end, "the clip's out")); if (start === cut.start && end === cut.end) refuse(`${e.id} is already cut ${s2(cut.start)}–${s2(cut.end)} s`); if (!(end - start >= MIN_CUT_SECONDS)) refuse(`${e.id}: a cut is at least ${MIN_CUT_SECONDS} s (${s2(start)}–${s2(end)})`); if (start < window.start - 0.005 || end > window.end + 0.005) { refuse(`${e.id}: ${s2(start)}–${s2(end)} s is outside the clip's source window (${s2(window.start)}–${s2(window.end)} s) — widen it in the clip editor first`); } const slack = Math.max(EDGE_SLACK_SECONDS, ctx.namedSeconds); const moved = Math.max(Math.abs(start - cut.start), Math.abs(end - cut.end)); if (moved > slack + 0.005) { refuse(`${e.id}: moves an edge ${s2(moved)} s; one op moves an edge at most ${s2(slack)} s (name the seconds in the request, or drag it in the clip editor)`); } const parts = []; if (start !== cut.start) parts.push(arrow(`${e.id} in`, `${s2(cut.start)} s`, `${s2(start)} s`)); if (end !== cut.end) parts.push(arrow(`${e.id} out`, `${s2(cut.end)} s`, `${s2(end)} s`)); // The manifest as it would be: the clip editor's trim (a cut inside the extent, or the edges themselves). if (fin(e.cutStart) && fin(e.cutEnd)) { e.cutStart = start; e.cutEnd = end; } else { e.start = start; e.end = end; } return { op: { op: "clip_edges", id: e.id, start, end }, diff: parts.join(", "), apply: { writer: "clip", body: { op: "trim", clip: e.id, cutStart: start, cutEnd: end } } }; } case "clip_room": { const e = clipOf(manifest, op.id); if (montage) refuse("a montage has no room at the edges (it cuts to its phrases)"); const words = (room) => { const r = clipRoom({ room }, render); return room === undefined || room === null ? `the cut's (${r ? ["tail", "head"].filter((k) => r[k]).join(" + ") : "none"})` : room === false ? "none" : r ? ["tail", "head"].filter((k) => r[k]).join(" + ") : "none"; }; let room; if (op.reset === true) room = null; else if (op.off === true) room = false; else { const was = isObj(e.room) ? e.room : {}; room = { ...was }; for (const k of ["tail", "head"]) if (op[k] !== undefined && op[k] !== null) room[k] = boolOf(op[k], `${e.id}'s room ${k}`); if (!Object.keys(room).length) refuse("a clip_room op sets tail, head, off or reset"); } const before = e.room; if (JSON.stringify(before ?? null) === JSON.stringify(room)) refuse(`${e.id}'s room is already ${words(room)}`); const errors = validateRoom({ timeline: [{ ...e, room: room ?? undefined }] }); if (errors.length) refuse(errors.join("; ")); if (room === null) delete e.room; else e.room = room; const norm = { op: "clip_room", id: e.id, ...(room === null ? { reset: true } : room === false ? { off: true } : room) }; return { op: norm, diff: arrow(`${e.id} room`, words(before), words(room ?? undefined)), apply: { writer: "clip", body: { op: "room", clip: e.id, room } } }; } case "fx": { const id = typeof op.id === "string" ? op.id.trim() : ""; const param = typeof op.param === "string" ? op.param.trim() : ""; if (!COMPOSITION_PARAMS[id]) refuse(`"${id}" is not a composition (${Object.keys(COMPOSITION_PARAMS).join(", ")})`); if (!compositionOn(render, id)) refuse(`this cut does not draw ${id}${id === "deck" ? "" : " (turn it on in the Media tab first)"}`); const p = paramOf(id, param); if (!p) refuse(`${id} has no param "${param}" (it declares ${COMPOSITION_PARAMS[id].map((x) => x.key).join(", ")})`); let value = op.value; if (p.kind === "bool" && typeof value !== "boolean") value = boolOf(value, p.label); if ((p.kind === "seconds" || p.kind === "number" || p.kind === "int" || p.kind === "px") && typeof value === "string") value = numOf(value, p.label); if (typeof value === "number" && p.kind !== "int") value = r2(value); const bad = paramValueError(p, value); if (bad) refuse(bad); const was = paramValue(render, id, param); if (JSON.stringify(was) === JSON.stringify(value)) refuse(`${p.label} is already ${JSON.stringify(value)}`); const unit = p.kind === "seconds" ? " s" : ""; const say = (v) => (typeof v === "boolean" ? onOff(v) : typeof v === "number" ? `${s2(v)}${unit}` : String(v)); manifest.render = { ...render, chrome: chromeWithParam(render, id, param, value) }; return { op: { op: "fx", id, param, value }, diff: arrow(p.label, say(was), say(value)), apply: { writer: "chrome", id, param, value } }; } default: return refuse(`no op "${String(name)}"`); } } /** * Check a batch of ops against a manifest. Each op is checked against the * manifest as the ops before it left it. * * @param {unknown} manifest the project's video.manifest.json * @param {readonly unknown[]} ops * @param {{ request?: string, scope?: string }} [o] * @returns {{ ops: { op: object, diff: string, apply: object, warning?: string }[], refused: { index: number, op: unknown, why: string }[], diff: string[], manifest: object }} */ export function checkAssistOps(manifest, ops, { request = "", scope = "all" } = {}) { const m = structuredClone(isObj(manifest) ? manifest : {}); if (!Array.isArray(m.timeline)) m.timeline = []; const ctx = { scope: ASSIST_SCOPES.includes(scope) ? scope : "all", namedSeconds: secondsNamedIn(request) }; const kept = []; const refused = []; for (const [index, raw] of (Array.isArray(ops) ? ops : []).entries()) { try { kept.push(checkOne(m, normalizeAssistOp(structuredClone(raw)), ctx)); } catch (e) { if (!(e instanceof Refusal)) throw e; refused.push({ index, op: raw, why: e.message }); } } return { ops: kept, refused, diff: kept.map((k) => k.diff), manifest: m }; } // --------------------------------------------------------------------------- // What the model reads: the look, the slide, the room, the clips, the // declared params -- trimmed to a character budget. // --------------------------------------------------------------------------- const shortWords = (q, n = 10) => { const w = String(q ?? "").split(/\s+/).filter(Boolean); return w.length > n ? `${w.slice(0, n).join(" ")} …` : w.join(" "); }; /** * The project as the assistant reads it. `scope` leaves out what was not asked * about; the clips the request names come first; a clip past the budget is * listed by its id alone, so an op may still name it. * * @param {unknown} manifest * @param {{ maxChars?: number, request?: string, scope?: string }} [o] * @returns {{ text: string, clips: { shown: string[], short: string[] } }} */ export function assistView(manifest, { maxChars = 6000, request = "", scope = "all" } = {}) { const m = isObj(manifest) ? manifest : {}; const render = isObj(m.render) ? m.render : {}; const want = (s) => scope === "all" || scope === s; const out = []; if (want("look")) { const slide = { ...SLIDE_DEFAULTS, ...(isObj(render.slide) ? render.slide : {}) }; const room = isObj(render.room) ? render.room : {}; out.push( "THE LOOK NOW (look ops: key = value):", `- transition = ${fin(render.transition) ? render.transition : TRANSITION_DEFAULT} (the join between clips, seconds; 0 = a hard cut; up to ${TRANSITION_MAX})`, `- transitionStyle = ${render.transitionStyle ?? "fade"} (one of ${TRANSITION_STYLES.join(", ")}; fade = crossfade, blurslide = a quick blurred push)`, `- headerHeight = ${render.headerHeight ?? "default"}, footerHeight = ${render.footerHeight ?? "default"} (pixels; 0 = off)`, `- qr = ${render.qr === false ? "false" : "true"} (the QR code on each clip)`, `- loudness = ${isObj(render.loudness) ? render.loudness.target : "null (as recorded)"} (target LUFS, ${LOUDNESS_MIN} to ${LOUDNESS_MAX}; higher is louder)`, `- captions = ${isObj(render.captions) ? "true" : "false"} (speaker captions)`, `SLIDE (slide op; used when transitionStyle is blurslide): travel = ${slide.travel} (${SLIDE_BOUNDS.travel.join("–")}), blur = ${slide.blur} (the smear, ${SLIDE_BOUNDS.blur.join("–")}), grain = ${slide.grain} (${SLIDE_BOUNDS.grain.join("–")})`, `ROOM (room op): tail = ${room.tail === true} (the sound runs on to the first silence after the cut), head = ${room.head === true} (a muted lead-in), maxS = ${fin(room.maxS) ? room.maxS : ROOM.maxS} (seconds the tail may run past the cut's end, ${ROOM_BOUNDS.maxS.join("–")}), minGap = ${fin(room.minGap) ? room.minGap : ROOM.minGap} (the silence that ends it, ${ROOM_BOUNDS.minGap.join("–")})`, ); } if (want("fx")) { const on = compositionsOn(render); if (on.length) { out.push("COMPOSITIONS (fx ops: id, param = value now [bounds]):"); for (const id of on) { const ps = COMPOSITION_PARAMS[id].map((p) => { const b = p.kind === "enum" ? p.values.join("|") : p.kind === "bool" ? "true|false" : p.kind === "text" ? `≤${p.maxLength} chars` : `${p.min}–${p.max}`; return `${p.key} = ${JSON.stringify(paramValue(render, id, p.key))} [${b}]`; }); out.push(`- ${id}: ${ps.join("; ")}`); } } else if (scope === "fx") out.push("COMPOSITIONS: none (this cut draws no deck and no effects)"); } const clips = (m.timeline ?? []).filter((e) => isObj(e) && e.type === "clip"); const shown = []; const short = []; if (want("clips") && clips.length) { const head = out.join("\n").length + 200; let left = maxChars - head; const named = (id) => new RegExp(`(^|[^A-Za-z0-9_-])${id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^A-Za-z0-9_-]|$)`, "i").test(request); const order = [...clips].sort((a, b) => Number(named(b.id)) - Number(named(a.id))); const lines = new Map(); const idLine = (e) => `- ${e.id} (not shown in full)`; left -= clips.reduce((n, e) => n + idLine(e).length + 1, 0); for (const e of order) { const { cut, window } = clipWindow(e, render); const r = clipRoom(e, render); const label = e.onscreen?.title ?? e.title ?? e.assist?.why ?? ""; const line = `- ${e.id}: cut ${s2(cut.start)}–${s2(cut.end)} s (${s2(cut.end - cut.start)} s; may move within ${s2(window.start)}–${s2(window.end)})` + `${e.room === false ? ", room off" : isObj(e.room) ? `, room ${r ? ["tail", "head"].filter((k) => r[k]).join("+") || "none" : "none"}` : ""}` + `${label ? ` ${JSON.stringify(shortWords(label, 8))}` : ""}${e.quote ? ` quote: ${JSON.stringify(shortWords(e.quote))}` : ""}`; const extra = line.length - idLine(e).length; if (extra <= left) { left -= extra; lines.set(e.id, line); shown.push(e.id); } else short.push(e.id); } out.push(`CLIPS (clip_edges / clip_room ops, by id; seconds on the recording):`); for (const e of clips) out.push(lines.get(e.id) ?? idLine(e)); } return { text: out.join("\n"), clips: { shown, short } }; } /** The ops, as the model is told them: one shape, `{op, id, key, value}`. */ export const ASSIST_OPS_TEXT = [ 'Operations: objects {"op", "id", "key", "value"} in the `ops` list ("id" is "" when the op names no clip or composition).', "Change only what the request asks for, one op a setting; give the NEW value, never a step or a difference.", '- {"op":"look","id":"","key":"transition","value":0.15} the join between clips, seconds (0 = hard cuts)', '- {"op":"look","id":"","key":"transitionStyle","value":"fade"} one of fade, fadeblack, fadewhite, dissolve, blurslide', '- {"op":"look","id":"","key":"qr","value":false} the QR code on (true) or off (false); key headerHeight / footerHeight: pixels, 0 = off', '- {"op":"look","id":"","key":"loudness","value":-14} the loudness target in LUFS (higher = louder; null = as recorded)', '- {"op":"look","id":"","key":"captions","value":true} speaker captions on or off', '- {"op":"slide","id":"","key":"blur","value":0.3} the blur slide: key travel (how far it pushes), blur (the smear) or grain', '- {"op":"room","id":"","key":"maxS","value":2} room at the clips\' edges: key tail (true/false: the sound runs to the first silence), head (true/false: a muted lead-in), maxS (the most seconds the tail runs past the cut), minGap', '- {"op":"clip_edges","id":"","key":"start","value":S} a clip\'s cut: key start or end, in seconds on its recording', '- {"op":"clip_room","id":"","key":"off","value":true} one clip\'s room: key tail or head (true/false), off (no room for it) or reset (the cut\'s again)', '- {"op":"fx","id":"","key":"","value":V} a listed composition param, within its bounds', ].join("\n"); /** The schema the answer is held to: `{ ops: [{op, id, key, value}], reply }` -- four keys an op, so a strict tool (every key required) is still one plain shape. */ export const ASSIST_OPS_SCHEMA = Object.freeze({ type: "object", properties: { ops: { type: "array", items: { type: "object", properties: { op: { type: "string", enum: [...ASSIST_OP_NAMES] }, id: { type: "string" }, key: { type: "string" }, value: { type: ["number", "string", "boolean", "null"] }, }, required: ["op", "id", "key", "value"], }, }, reply: { type: "string" }, }, required: ["ops", "reply"], }); /** * An op in the model's one shape (`{op, id, key, value}`) as the checker's * own: `{op:"slide", key:"blur", value:0.3}` → `{op:"slide", blur:0.3}`. An op * already in the checker's shape is left as it is. */ export function normalizeAssistOp(raw) { if (!isObj(raw)) return raw; const { op, id, key, value } = raw; const k = typeof key === "string" ? key.trim() : ""; if (op === "look" || !k) return raw; if (op === "fx") return raw.param !== undefined ? raw : { op, id, param: k, value }; if (["slide", "room", "clip_edges", "clip_room"].includes(op) && raw[k] === undefined) { const out = { op, [k]: value }; if (op === "clip_edges" || op === "clip_room") out.id = id; return out; } return raw; }