trace-avatar-render 0.1.2 → 0.1.4

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/cli.js CHANGED
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ CORNERS,
3
4
  RenderError,
5
+ brandFile,
6
+ canvasOf,
4
7
  providerOf,
5
8
  render,
6
9
  suggestScript,
7
- voiceOf
8
- } from "./chunk-VTXIXGG4.js";
10
+ voiceOf,
11
+ watermarkOf
12
+ } from "./chunk-2ASNE3WF.js";
9
13
 
10
14
  // src/cli.ts
11
15
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -43,9 +47,16 @@ var USAGE = `Usage: trace-avatar-render <trace.json> --url <page> --out <file.gi
43
47
  --camera zoom in on each action and pan between close ones
44
48
  --zoom <n> how far the camera goes in (default 1.6; implies --camera)
45
49
  --captions <burn|vtt|both> burn the steps' words in, write <out>.vtt + <out>.chapters.vtt, or both
50
+ --captions-at <top|bottom> where burned-in captions sit (default bottom; top when the app's own UI is low)
46
51
  --poster [file] a PNG at the first click (default <out>.png)
47
52
  --title-card [title] a 1.5 s card first (default: the trace's title)
48
53
  --end-card [title] a 2 s card last (default: "Done")
54
+ --canvas <shape> compose onto 9:16 (1080x1920), 4:5, 1:1, 16:9 or WxH: the app between safe margins on the
55
+ background, for Reels, Stories and feeds (--width scales the whole canvas)
56
+ --watermark <text> a small badge on every frame, cards too, e.g. "Created with TraceAvatar \xB7 traceavatar.com"
57
+ --watermark-at <corner> top-left, top-right, bottom-left or bottom-right (default)
58
+ --brand <file.json> the look in one file: canvas, watermark, frame, background, camera, captions, captionsAt,
59
+ titleCard, endCard ({ title, url, logo, color }); flags given here win over it
49
60
 
50
61
  AI (nothing calls a model without --ai):
51
62
  --ai <provider> gateway: our AI gateway (AI_GATEWAY_URL, AI_GATEWAY_KEY), DeepSeek first, then Gemini,
@@ -122,6 +133,7 @@ function parse(argv) {
122
133
  camera: { type: "boolean" },
123
134
  zoom: { type: "string" },
124
135
  captions: { type: "string" },
136
+ "captions-at": { type: "string" },
125
137
  ai: { type: "string" },
126
138
  "ai-vision": { type: "string" },
127
139
  alt: { type: "boolean" },
@@ -132,7 +144,11 @@ function parse(argv) {
132
144
  "no-voice-cache": { type: "boolean" },
133
145
  repair: { type: "boolean" },
134
146
  "repair-vision": { type: "boolean" },
135
- report: { type: "string" }
147
+ report: { type: "string" },
148
+ canvas: { type: "string" },
149
+ watermark: { type: "string" },
150
+ "watermark-at": { type: "string" },
151
+ brand: { type: "string" }
136
152
  }
137
153
  });
138
154
  if (values.help) throw new UsageError("");
@@ -158,6 +174,8 @@ function parse(argv) {
158
174
  if (values.frame && values.frame !== "none" && values.frame !== "browser") throw new UsageError("--frame is none or browser");
159
175
  const captions = values.captions;
160
176
  if (captions !== void 0 && captions !== "burn" && captions !== "vtt" && captions !== "both") throw new UsageError("--captions is burn, vtt or both");
177
+ const captionsAt = values["captions-at"];
178
+ if (captionsAt !== void 0 && captionsAt !== "top" && captionsAt !== "bottom") throw new UsageError("--captions-at is top or bottom");
161
179
  const zoom = num("zoom", values.zoom, 1);
162
180
  if (extra.qa !== void 0 && extra.qa !== true && extra.qa !== "strict") throw new UsageError("--qa takes nothing or strict");
163
181
  if ((extra.qa !== void 0 || values.alt || values["ai-vision"]) && !values.ai) throw new UsageError("--qa, --alt and --ai-vision need --ai");
@@ -178,12 +196,30 @@ function parse(argv) {
178
196
  typed[v.slice(0, k)] = v.slice(k + 1);
179
197
  }
180
198
  if ((security !== void 0 || values.value?.length) && mode !== "perform") throw new UsageError("--security and --value are for --mode perform");
199
+ const tryUsage = (f) => {
200
+ try {
201
+ return f();
202
+ } catch (e) {
203
+ throw new UsageError(e.message);
204
+ }
205
+ };
206
+ if (values.canvas !== void 0) tryUsage(() => canvasOf(values.canvas));
207
+ const at = values["watermark-at"];
208
+ if (at !== void 0 && !CORNERS.includes(at)) throw new UsageError(`--watermark-at is ${CORNERS.join(", ")}`);
209
+ const brand = values.brand !== void 0 ? tryUsage(() => brandFile(values.brand)) : {};
210
+ let watermark = values.watermark !== void 0 ? tryUsage(() => watermarkOf(values.watermark)) : brand.watermark;
211
+ if (at !== void 0) {
212
+ if (watermark === void 0) throw new UsageError("--watermark-at needs a watermark (--watermark, or one in --brand)");
213
+ watermark = { ...typeof watermark === "string" ? { text: watermark } : watermark, at };
214
+ }
181
215
  const width = num("width", values.width, 16);
182
216
  const fps = num("fps", values.fps, 1);
183
217
  const maxWait = num("max-wait", values["max-wait"]);
184
218
  return {
185
219
  trace,
186
220
  options: {
221
+ // The brand first: the flags below win over it.
222
+ ...brand,
187
223
  trace,
188
224
  url: values.url,
189
225
  mode,
@@ -207,9 +243,12 @@ function parse(argv) {
207
243
  ...values.background ? { background: values.background } : {},
208
244
  ...zoom ? { camera: { zoom } } : values.camera ? { camera: true } : {},
209
245
  ...captions ? { captions } : {},
246
+ ...captionsAt ? { captionsAt } : {},
210
247
  ...extra.poster !== void 0 ? { poster: extra.poster } : {},
211
248
  ...extra.title !== void 0 ? { titleCard: extra.title } : {},
212
249
  ...extra.end !== void 0 ? { endCard: extra.end } : {},
250
+ ...values.canvas !== void 0 ? { canvas: values.canvas } : {},
251
+ ...watermark !== void 0 ? { watermark } : {},
213
252
  ...extra.qa !== void 0 ? { qa: true } : {},
214
253
  ...values.alt ? { alt: true } : {},
215
254
  ...values.script ? { script: values.script } : {},
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * trace-avatar-render invoice.trace.json --url http://localhost:3000/app --out invoice.gif --out invoice.mp4\n *\n * Exit codes: 0 rendered, 1 the render failed (a stalled guide, an error in the app), 2 wrong usage.\n */\n\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { apply as applySuggestions, suggest } from 'trace-avatar/assist';\nimport type { Suggestion } from 'trace-avatar/assist';\nimport { providerOf } from './ai';\nimport { suggestScript } from './narration';\nimport { voiceOf } from './voice';\nimport { parseArgs } from 'node:util';\nimport { RenderError } from './capture';\nimport { render } from './render';\n\nexport const USAGE = `Usage: trace-avatar-render <trace.json> --url <page> --out <file.gif|file.mp4> [options]\n\n --url <url> the page the guide starts on (required)\n --out <file> .gif or .mp4; repeat for several (required)\n --mode <overlay|perform> Show me (default) or Do it for me\n --allow-perform needed for perform: it clicks and types for real (use a sandbox account)\n --width <px> output width (GIF default 800, MP4 the capture's)\n --fps <n> frames per second (GIF default 12, MP4 30)\n --viewport <WxH> default: the trace's meta.viewport, else 1280x800\n --scale <n> device pixel ratio of the capture (2 for crisp video)\n --storage-state <file> a signed-in Playwright session\n --max-wait <ms> waits longer than this are cut to it (default 800, 0 keeps them)\n --hide <selector> hidden before capture; repeatable\n --blur <selector> blurred before capture (as well as [data-trace-blur]); repeatable\n --allow-stall render a stalled guide anyway instead of failing\n --navigate a step on another page: load that page, as the app's router would (without it, a\n Show me guide that crosses pages waits on \"Open … to continue\")\n --security [guards] perform: leave these to the viewer (a hand-off): all, or secrets,money,files\n --value <name=text> perform: a value to type, by name or field label (e.g. password=demo-pass); repeatable\n --player <file> the trace-perform.min.js to use (default: the installed trace-avatar)\n --timeline <file> write the timeline and the cuts as JSON\n --timeout <ms> give up after this long (default 120000)\n --report <file> write what happened as JSON: { outcome: passed|stalled|failed, step, reason, message }\n (for CI: one result per guide, whatever the exit code)\n --headed show the browser\n\n Polish (all off by default):\n --frame <none|browser> a browser window around the app, on a background\n --background <css> the background behind the window and on the cards\n --camera zoom in on each action and pan between close ones\n --zoom <n> how far the camera goes in (default 1.6; implies --camera)\n --captions <burn|vtt|both> burn the steps' words in, write <out>.vtt + <out>.chapters.vtt, or both\n --poster [file] a PNG at the first click (default <out>.png)\n --title-card [title] a 1.5 s card first (default: the trace's title)\n --end-card [title] a 2 s card last (default: \"Done\")\n\n AI (nothing calls a model without --ai):\n --ai <provider> gateway: our AI gateway (AI_GATEWAY_URL, AI_GATEWAY_KEY), DeepSeek first, then Gemini,\n then OpenAI; or gateway:<provider>[/<model>][,<provider>…]; openai:<model> (OPENAI_API_KEY,\n OPENAI_BASE_URL for any OpenAI-compatible server); or ./provider.js\n --ai-vision <model> the model for --qa's frames (gateway's DeepSeek default: deepseek-flash)\n --qa [strict] send a frame per step to the AI to look for errors, empty states, a stall, personal\n data; strict exits 1 when anything is flagged (needs a vision model)\n --alt write <out>.alt.txt; with --captions vtt, AI names the chapters\n --repair when a step can't find its element, or a wait's text never shows, propose a fix in\n <out>.repair.json (verified by playing again); still exits 1. With --ai, unsure\n cases are asked (DeepSeek first)\n --repair-vision with --repair and --ai: send a screenshot of the stalled page too (elements only)\n\n Narration (MP4 only; nothing speaks without --voice):\n --voice <voice> gateway (our AI gateway: Gemini speech, AI_GATEWAY_URL/KEY), gateway:gemini/<model>:<voice>,\n openai:<model>[:<voice>] (OPENAI_API_KEY / OPENAI_BASE_URL), say[:<voice>] (macOS, offline),\n or ./voice.js. Each step's caption is spoken; the video holds where a line runs long\n --script <file.json> the spoken lines instead: { \"lines\": [{ \"n\": 1, \"text\": \"…\" }] }\n --voice-out <file.wav> also write the narration track\n --voice-strict fail when a line needs a hold longer than 8 s\n --no-voice-cache don't keep spoken lines in .trace-avatar-cache/voice\n\nSuggestions for a person to accept (the renderer never changes a trace):\n trace-avatar-render suggest <trace.json> --task captions|title|waits|narration --ai <provider> [--tone friendly|terse|formal]\n [--hints hints.json] [--out suggestions.json]\n trace-avatar-render apply <trace.json> <suggestions.json> --accept 1,3|all --out <new.trace.json>\n`;\n\nexport interface Parsed { /** --report */ report?: string; trace: string; options: Parameters<typeof render>[0]; /** --ai, made into a provider by main(). */ ai?: string; /** --ai-vision */ aiVision?: string; /** --voice, made into a Voice by main() */ voice?: string; /** --no-voice-cache */ noVoiceCache?: boolean; /** --qa strict */ strict?: boolean }\n\n/** Parse the command line. Throws a usage message (exit 2) on mistakes. Exported for tests. */\nexport function parse(argv: string[]): Parsed {\n // --poster, --title-card and --end-card take an optional value: take it here when one follows (a\n // following *.json is the trace, not the value).\n const extra: { poster?: string | true; title?: string | true; end?: string | true; qa?: string | true } = {};\n const flags: Record<string, 'poster' | 'title' | 'end' | 'qa'> = { '--poster': 'poster', '--title-card': 'title', '--end-card': 'end', '--qa': 'qa' };\n const rest: string[] = [];\n for (let k = 0; k < argv.length; k += 1) {\n const a = argv[k];\n const eq = a.indexOf('=');\n const name = eq > 0 ? a.slice(0, eq) : a;\n if (flags[name]) {\n if (eq > 0) extra[flags[name]] = a.slice(eq + 1);\n else if (argv[k + 1] !== undefined && !argv[k + 1].startsWith('-') && !/\\.json$/i.test(argv[k + 1]) && (flags[name] !== 'qa' || argv[k + 1] === 'strict')) { extra[flags[name]] = argv[k + 1]; k += 1; }\n else extra[flags[name]] = true;\n continue;\n }\n rest.push(a);\n }\n const { values, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n options: {\n url: { type: 'string' }, out: { type: 'string', multiple: true }, mode: { type: 'string' },\n 'allow-perform': { type: 'boolean' }, width: { type: 'string' }, fps: { type: 'string' },\n viewport: { type: 'string' }, scale: { type: 'string' }, 'storage-state': { type: 'string' },\n 'max-wait': { type: 'string' }, hide: { type: 'string', multiple: true }, blur: { type: 'string', multiple: true },\n 'allow-stall': { type: 'boolean' }, navigate: { type: 'boolean' }, security: { type: 'string' }, value: { type: 'string', multiple: true }, player: { type: 'string' }, timeline: { type: 'string' },\n timeout: { type: 'string' }, headed: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },\n frame: { type: 'string' }, background: { type: 'string' }, camera: { type: 'boolean' }, zoom: { type: 'string' },\n captions: { type: 'string' }, ai: { type: 'string' }, 'ai-vision': { type: 'string' }, alt: { type: 'boolean' },\n voice: { type: 'string' }, script: { type: 'string' }, 'voice-out': { type: 'string' }, 'voice-strict': { type: 'boolean' }, 'no-voice-cache': { type: 'boolean' },\n repair: { type: 'boolean' }, 'repair-vision': { type: 'boolean' }, report: { type: 'string' },\n },\n });\n if (values.help) throw new UsageError('');\n const trace = positionals[0];\n if (!trace) throw new UsageError('a trace file is needed');\n if (positionals.length > 1) throw new UsageError(`one trace at a time (got ${positionals.join(', ')})`);\n if (!values.url) throw new UsageError('--url is needed');\n if (!values.out?.length) throw new UsageError('--out is needed');\n const num = (name: string, v: string | undefined, min = 0) => {\n if (v === undefined) return undefined;\n const n = Number(v);\n if (!Number.isFinite(n) || n < min) throw new UsageError(`--${name} must be a number ≥ ${min}`);\n return n;\n };\n const mode = values.mode ?? 'overlay';\n if (mode !== 'overlay' && mode !== 'perform') throw new UsageError('--mode is overlay or perform');\n let viewport: { w: number; h: number } | undefined;\n if (values.viewport) {\n const m = /^(\\d+)x(\\d+)$/i.exec(values.viewport);\n if (!m) throw new UsageError('--viewport is WIDTHxHEIGHT, e.g. 1280x800');\n viewport = { w: Number(m[1]), h: Number(m[2]) };\n }\n if (values.frame && values.frame !== 'none' && values.frame !== 'browser') throw new UsageError('--frame is none or browser');\n const captions = values.captions;\n if (captions !== undefined && captions !== 'burn' && captions !== 'vtt' && captions !== 'both') throw new UsageError('--captions is burn, vtt or both');\n const zoom = num('zoom', values.zoom, 1);\n if (extra.qa !== undefined && extra.qa !== true && extra.qa !== 'strict') throw new UsageError('--qa takes nothing or strict');\n if ((extra.qa !== undefined || values.alt || values['ai-vision']) && !values.ai) throw new UsageError('--qa, --alt and --ai-vision need --ai');\n if (values['repair-vision'] && !(values.repair && values.ai)) throw new UsageError('--repair-vision needs --repair and --ai');\n if ((values.script || values['voice-out'] || values['voice-strict'] || values['no-voice-cache']) && !values.voice) throw new UsageError('--script, --voice-out, --voice-strict and --no-voice-cache need --voice');\n if (values.voice && !values.out.some((f) => /\\.mp4$/i.test(f))) throw new UsageError('--voice needs an .mp4 output (a GIF has no sound)');\n let security: boolean | string[] | undefined;\n if (values.security !== undefined) {\n const s = values.security.trim().toLowerCase();\n const guards = s === '' || s === 'all' || s === 'true' ? true : s.split(/[\\s,]+/).filter(Boolean);\n if (Array.isArray(guards) && guards.some((g) => !['secrets', 'money', 'files'].includes(g))) throw new UsageError('--security is all, or a list of secrets, money, files');\n security = guards;\n }\n const typed: Record<string, string> = {};\n for (const v of values.value ?? []) {\n const k = v.indexOf('=');\n if (k < 1) throw new UsageError('--value is name=text, e.g. password=demo-pass');\n typed[v.slice(0, k)] = v.slice(k + 1);\n }\n if ((security !== undefined || values.value?.length) && mode !== 'perform') throw new UsageError('--security and --value are for --mode perform');\n const width = num('width', values.width, 16);\n const fps = num('fps', values.fps, 1);\n const maxWait = num('max-wait', values['max-wait']);\n return {\n trace,\n options: {\n trace,\n url: values.url,\n mode,\n allowPerform: !!values['allow-perform'],\n out: values.out.map((file) => ({ file, ...(width ? { width } : {}), ...(fps ? { fps } : {}) })),\n ...(viewport ? { viewport } : {}),\n ...(values.scale ? { scale: num('scale', values.scale, 1) } : {}),\n ...(values['storage-state'] ? { storageState: values['storage-state'] } : {}),\n ...(maxWait !== undefined ? { cuts: { maxWaitMs: maxWait } } : {}),\n ...(values.hide ? { hide: values.hide } : {}),\n ...(values.blur ? { blur: values.blur } : {}),\n allowStall: !!values['allow-stall'],\n ...(values.navigate ? { navigate: true } : {}),\n ...(security !== undefined ? { security } : {}),\n ...(values.value?.length ? { values: typed } : {}),\n ...(values.player ? { player: values.player } : {}),\n ...(values.timeline ? { timeline: values.timeline } : {}),\n ...(values.timeout ? { timeoutMs: num('timeout', values.timeout, 1) } : {}),\n headless: !values.headed,\n ...(values.frame ? { frame: values.frame as 'none' | 'browser' } : {}),\n ...(values.background ? { background: values.background } : {}),\n ...(zoom ? { camera: { zoom } } : values.camera ? { camera: true } : {}),\n ...(captions ? { captions } : {}),\n ...(extra.poster !== undefined ? { poster: extra.poster } : {}),\n ...(extra.title !== undefined ? { titleCard: extra.title } : {}),\n ...(extra.end !== undefined ? { endCard: extra.end } : {}),\n ...(extra.qa !== undefined ? { qa: true } : {}),\n ...(values.alt ? { alt: true } : {}),\n ...(values.script ? { script: values.script } : {}),\n ...(values['voice-out'] ? { voiceOut: values['voice-out'] } : {}),\n ...(values['voice-strict'] ? { voiceStrict: true } : {}),\n ...(values.repair ? { repair: true } : {}),\n ...(values['repair-vision'] ? { repairVision: true } : {}),\n },\n ...(values.ai ? { ai: values.ai } : {}),\n ...(values['ai-vision'] ? { aiVision: values['ai-vision'] } : {}),\n ...(values.voice ? { voice: values.voice } : {}),\n ...(values['no-voice-cache'] ? { noVoiceCache: true } : {}),\n ...(extra.qa === 'strict' ? { strict: true } : {}),\n ...(values.report ? { report: values.report } : {}),\n };\n}\n\n/** What --report writes: one guide's outcome, for CI. */\nexport interface Report {\n outcome: 'passed' | 'stalled' | 'failed';\n /** The stalled step (from 0); null otherwise. */\n step: number | null;\n reason: 'not-found' | 'until-timeout' | null;\n /** The stalled step's caption, or the error. */\n message: string | null;\n /** The repair file, when --repair wrote one. */\n repair?: string;\n}\n\n/** The report for a render's outcome (exported for tests). */\nexport function reportOf(err: unknown, traceFile: string, repairFile?: string): Report {\n if (!err) return { outcome: 'passed', step: null, reason: null, message: null };\n const stall = err instanceof RenderError ? err.stall : undefined;\n if (stall && Number.isInteger(stall.index)) {\n let say: string | null = null;\n try { say = ((JSON.parse(readFileSync(traceFile, 'utf8')) as { steps?: Array<{ say?: string }> }).steps?.[stall.index]?.say) ?? null; } catch { /* the error is enough */ }\n return {\n outcome: 'stalled', step: stall.index, reason: stall.reason === 'until-timeout' ? 'until-timeout' : 'not-found',\n message: say ?? (err as Error).message, ...(repairFile && existsSync(repairFile) ? { repair: repairFile } : {}),\n };\n }\n return { outcome: 'failed', step: null, reason: null, message: (err as Error)?.message ?? String(err) };\n}\n\nexport class UsageError extends Error {}\n\nexport async function main(argv: string[], io = { log: console.log, error: console.error }): Promise<number> {\n if (argv[0] === 'suggest' || argv[0] === 'apply') {\n try { return await (argv[0] === 'suggest' ? suggestCmd(argv.slice(1), io) : applyCmd(argv.slice(1), io)); } catch (e) {\n io.error(`trace-avatar-render ${argv[0]}: ${(e as Error).message}`);\n if (e instanceof UsageError) io.error(USAGE);\n return e instanceof UsageError ? 2 : 1;\n }\n }\n let p: Parsed;\n try { p = parse(argv); } catch (e) {\n const msg = (e as Error).message;\n if (msg) io.error(`trace-avatar-render: ${msg}\\n`);\n io.error(USAGE);\n return e instanceof UsageError && !msg ? 0 : 2;\n }\n try {\n if (p.ai) p.options.ai = await providerOf(p.ai, process.env, p.aiVision ? { vision: p.aiVision } : {});\n if (p.voice) p.options.voice = await voiceOf(p.voice, process.env, p.noVoiceCache ? { cacheDir: null } : {});\n const r = await render(p.options);\n for (const o of r.outputs) io.log(`${o.file} ${o.width}×${o.height} ${o.fps} fps ${(r.durationMs / 1000).toFixed(1)} s ${(o.bytes / 1024).toFixed(0)} KB`);\n if (r.rawMs > r.durationMs + 50) io.log(`cut ${((r.rawMs - r.durationMs) / 1000).toFixed(1)} s of waiting`);\n for (const f of [r.poster, r.vtt, r.chapters, r.alt]) if (f) io.log(f);\n if (r.narration) {\n io.log(`narration: ${r.narration.lines.length} line${r.narration.lines.length === 1 ? '' : 's'}${r.narration.holdMs ? `, the video holds ${(r.narration.holdMs / 1000).toFixed(1)} s for them` : ''} ${r.narration.text}`);\n if (r.narration.wav) io.log(r.narration.wav);\n }\n for (const w of r.warnings ?? []) io.error(`warning: ${w}`);\n if (p.report) writeFileSync(p.report, `${JSON.stringify(reportOf(null, p.trace), null, 2)}\\n`);\n if (r.qa) {\n if (!r.qa.length) io.log('qa: nothing flagged');\n for (const f of r.qa) io.log(`qa: ${(f.at / 1000).toFixed(1)} s ${f.kind} ${f.note}`);\n if (p.strict && r.qa.length) { io.error(`trace-avatar-render: qa flagged ${r.qa.length} problem${r.qa.length > 1 ? 's' : ''} (--qa strict)`); return 1; }\n }\n return 0;\n } catch (e) {\n io.error(`trace-avatar-render: ${(e as Error).message}`);\n if (p.report) {\n const first = p.options.out[0];\n const base = (typeof first === 'string' ? first : first.file).replace(/\\.[^./]+$/, '');\n writeFileSync(p.report, `${JSON.stringify(reportOf(e, p.trace, `${base}.repair.json`), null, 2)}\\n`);\n }\n if (e instanceof RenderError && e.screenshot) {\n const first = p.options.out[0];\n const shot = `${(typeof first === 'string' ? first : first.file).replace(/\\.[^./]+$/, '')}.failure.png`;\n writeFileSync(shot, e.screenshot);\n io.error(`the page at that moment: ${shot}`);\n }\n return 1;\n }\n}\n\nconst readJson = (file: string): unknown => {\n try { return JSON.parse(readFileSync(file, 'utf8')); } catch (e) { throw new Error(`could not read ${file}: ${(e as Error).message}`); }\n};\n\n/** suggest <trace.json> --task … --ai …: suggestions, numbered, as JSON (stdout or --out). */\nasync function suggestCmd(argv: string[], io: { log: (m: string) => void }): Promise<number> {\n const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: {\n task: { type: 'string' }, ai: { type: 'string' }, tone: { type: 'string' }, hints: { type: 'string' }, out: { type: 'string' }, 'send-typed': { type: 'boolean' },\n } });\n const [file] = positionals;\n if (!file) throw new UsageError('suggest needs a trace file');\n const task = values.task;\n if (task !== 'captions' && task !== 'title' && task !== 'waits' && task !== 'narration') throw new UsageError('--task is captions, title, waits or narration');\n if (!values.ai) throw new UsageError('suggest needs --ai');\n if (task === 'narration') {\n // A script file for --script: a person edits it before rendering.\n const r = await suggestScript(await providerOf(values.ai), readJson(file) as Parameters<typeof suggestScript>[1]);\n const out = JSON.stringify({ ...r.script, ...(r.dropped.length ? { dropped: r.dropped } : {}) }, null, 2);\n if (values.out) { writeFileSync(values.out, `${out}\\n`); io.log(`${r.script.lines.length} line${r.script.lines.length === 1 ? '' : 's'} in ${values.out}: edit them, then --script ${values.out}`); } else io.log(out);\n return 0;\n }\n const tone = values.tone;\n if (tone !== undefined && tone !== 'friendly' && tone !== 'terse' && tone !== 'formal') throw new UsageError('--tone is friendly, terse or formal');\n const trace = readJson(file) as Parameters<typeof suggest>[1];\n const hints = values.hints ? (readJson(values.hints) as Parameters<typeof suggest>[2]['hints']) : undefined;\n const r = await suggest(task, trace, { ai: await providerOf(values.ai), ...(hints ? { hints } : {}), ...(tone ? { tone } : {}), ...(values['send-typed'] ? { sendTyped: true } : {}) });\n const out = JSON.stringify({ task, suggestions: r.suggestions.map((sg, k) => ({ id: k + 1, ...sg })), dropped: r.dropped }, null, 2);\n if (values.out) { writeFileSync(values.out, `${out}\\n`); io.log(`${r.suggestions.length} suggestion${r.suggestions.length === 1 ? '' : 's'} in ${values.out}`); } else io.log(out);\n return 0;\n}\n\n/** apply <trace.json> <suggestions.json> --accept 1,3|all --out new.trace.json */\nasync function applyCmd(argv: string[], io: { log: (m: string) => void }): Promise<number> {\n const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { accept: { type: 'string' }, out: { type: 'string' } } });\n const [file, sugFile] = positionals;\n if (!file || !sugFile) throw new UsageError('apply needs a trace file and a suggestions file');\n if (!values.accept) throw new UsageError('apply needs --accept 1,3 (or all): a person picks what goes in');\n if (!values.out) throw new UsageError('apply needs --out for the new trace');\n const all = (readJson(sugFile) as { suggestions?: Array<Suggestion & { id: number }> }).suggestions ?? [];\n const ids = values.accept === 'all' ? all.map((x) => x.id) : values.accept.split(',').map((x) => Number(x.trim()));\n const missing = ids.filter((id) => !all.some((x) => x.id === id));\n if (missing.length) throw new UsageError(`no suggestion ${missing.join(', ')} in ${sugFile}`);\n const next = applySuggestions(readJson(file) as Parameters<typeof applySuggestions>[0], all.filter((x) => ids.includes(x.id)));\n writeFileSync(values.out, `${JSON.stringify(next, null, 2)}\\n`);\n io.log(`applied ${ids.length} of ${all.length} to ${values.out}`);\n return 0;\n}\n\nconst isMain = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('/trace-avatar-render') || process.argv[1]?.endsWith('/cli.js');\nif (isMain) void main(process.argv.slice(2)).then((code) => { process.exitCode = code; });\n"],"mappings":";;;;;;;;;;AAOA,SAAS,YAAY,cAAc,qBAAqB;AACxD,SAAS,SAAS,kBAAkB,eAAe;AAKnD,SAAS,iBAAiB;AAInB,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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;AACT;AAEA,IAAM,SAAS,YAAY,QAAQ,UAAU,QAAQ,KAAK,CAAC,CAAC,MAAM,QAAQ,KAAK,CAAC,GAAG,SAAS,sBAAsB,KAAK,QAAQ,KAAK,CAAC,GAAG,SAAS,SAAS;AAC1J,IAAI,OAAQ,MAAK,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS;AAAE,UAAQ,WAAW;AAAM,CAAC;","names":["r","out"]}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * trace-avatar-render invoice.trace.json --url http://localhost:3000/app --out invoice.gif --out invoice.mp4\n *\n * Exit codes: 0 rendered, 1 the render failed (a stalled guide, an error in the app), 2 wrong usage.\n */\n\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { apply as applySuggestions, suggest } from 'trace-avatar/assist';\nimport type { Suggestion } from 'trace-avatar/assist';\nimport { providerOf } from './ai';\nimport { suggestScript } from './narration';\nimport { voiceOf } from './voice';\nimport { parseArgs } from 'node:util';\nimport { RenderError } from './capture';\nimport { render } from './render';\nimport { brandFile, canvasOf, CORNERS, watermarkOf } from './brand';\nimport type { Corner, Watermark } from './brand';\n\nexport const USAGE = `Usage: trace-avatar-render <trace.json> --url <page> --out <file.gif|file.mp4> [options]\n\n --url <url> the page the guide starts on (required)\n --out <file> .gif or .mp4; repeat for several (required)\n --mode <overlay|perform> Show me (default) or Do it for me\n --allow-perform needed for perform: it clicks and types for real (use a sandbox account)\n --width <px> output width (GIF default 800, MP4 the capture's)\n --fps <n> frames per second (GIF default 12, MP4 30)\n --viewport <WxH> default: the trace's meta.viewport, else 1280x800\n --scale <n> device pixel ratio of the capture (2 for crisp video)\n --storage-state <file> a signed-in Playwright session\n --max-wait <ms> waits longer than this are cut to it (default 800, 0 keeps them)\n --hide <selector> hidden before capture; repeatable\n --blur <selector> blurred before capture (as well as [data-trace-blur]); repeatable\n --allow-stall render a stalled guide anyway instead of failing\n --navigate a step on another page: load that page, as the app's router would (without it, a\n Show me guide that crosses pages waits on \"Open … to continue\")\n --security [guards] perform: leave these to the viewer (a hand-off): all, or secrets,money,files\n --value <name=text> perform: a value to type, by name or field label (e.g. password=demo-pass); repeatable\n --player <file> the trace-perform.min.js to use (default: the installed trace-avatar)\n --timeline <file> write the timeline and the cuts as JSON\n --timeout <ms> give up after this long (default 120000)\n --report <file> write what happened as JSON: { outcome: passed|stalled|failed, step, reason, message }\n (for CI: one result per guide, whatever the exit code)\n --headed show the browser\n\n Polish (all off by default):\n --frame <none|browser> a browser window around the app, on a background\n --background <css> the background behind the window and on the cards\n --camera zoom in on each action and pan between close ones\n --zoom <n> how far the camera goes in (default 1.6; implies --camera)\n --captions <burn|vtt|both> burn the steps' words in, write <out>.vtt + <out>.chapters.vtt, or both\n --captions-at <top|bottom> where burned-in captions sit (default bottom; top when the app's own UI is low)\n --poster [file] a PNG at the first click (default <out>.png)\n --title-card [title] a 1.5 s card first (default: the trace's title)\n --end-card [title] a 2 s card last (default: \"Done\")\n --canvas <shape> compose onto 9:16 (1080x1920), 4:5, 1:1, 16:9 or WxH: the app between safe margins on the\n background, for Reels, Stories and feeds (--width scales the whole canvas)\n --watermark <text> a small badge on every frame, cards too, e.g. \"Created with TraceAvatar · traceavatar.com\"\n --watermark-at <corner> top-left, top-right, bottom-left or bottom-right (default)\n --brand <file.json> the look in one file: canvas, watermark, frame, background, camera, captions, captionsAt,\n titleCard, endCard ({ title, url, logo, color }); flags given here win over it\n\n AI (nothing calls a model without --ai):\n --ai <provider> gateway: our AI gateway (AI_GATEWAY_URL, AI_GATEWAY_KEY), DeepSeek first, then Gemini,\n then OpenAI; or gateway:<provider>[/<model>][,<provider>…]; openai:<model> (OPENAI_API_KEY,\n OPENAI_BASE_URL for any OpenAI-compatible server); or ./provider.js\n --ai-vision <model> the model for --qa's frames (gateway's DeepSeek default: deepseek-flash)\n --qa [strict] send a frame per step to the AI to look for errors, empty states, a stall, personal\n data; strict exits 1 when anything is flagged (needs a vision model)\n --alt write <out>.alt.txt; with --captions vtt, AI names the chapters\n --repair when a step can't find its element, or a wait's text never shows, propose a fix in\n <out>.repair.json (verified by playing again); still exits 1. With --ai, unsure\n cases are asked (DeepSeek first)\n --repair-vision with --repair and --ai: send a screenshot of the stalled page too (elements only)\n\n Narration (MP4 only; nothing speaks without --voice):\n --voice <voice> gateway (our AI gateway: Gemini speech, AI_GATEWAY_URL/KEY), gateway:gemini/<model>:<voice>,\n openai:<model>[:<voice>] (OPENAI_API_KEY / OPENAI_BASE_URL), say[:<voice>] (macOS, offline),\n or ./voice.js. Each step's caption is spoken; the video holds where a line runs long\n --script <file.json> the spoken lines instead: { \"lines\": [{ \"n\": 1, \"text\": \"…\" }] }\n --voice-out <file.wav> also write the narration track\n --voice-strict fail when a line needs a hold longer than 8 s\n --no-voice-cache don't keep spoken lines in .trace-avatar-cache/voice\n\nSuggestions for a person to accept (the renderer never changes a trace):\n trace-avatar-render suggest <trace.json> --task captions|title|waits|narration --ai <provider> [--tone friendly|terse|formal]\n [--hints hints.json] [--out suggestions.json]\n trace-avatar-render apply <trace.json> <suggestions.json> --accept 1,3|all --out <new.trace.json>\n`;\n\nexport interface Parsed { /** --report */ report?: string; trace: string; options: Parameters<typeof render>[0]; /** --ai, made into a provider by main(). */ ai?: string; /** --ai-vision */ aiVision?: string; /** --voice, made into a Voice by main() */ voice?: string; /** --no-voice-cache */ noVoiceCache?: boolean; /** --qa strict */ strict?: boolean }\n\n/** Parse the command line. Throws a usage message (exit 2) on mistakes. Exported for tests. */\nexport function parse(argv: string[]): Parsed {\n // --poster, --title-card and --end-card take an optional value: take it here when one follows (a\n // following *.json is the trace, not the value).\n const extra: { poster?: string | true; title?: string | true; end?: string | true; qa?: string | true } = {};\n const flags: Record<string, 'poster' | 'title' | 'end' | 'qa'> = { '--poster': 'poster', '--title-card': 'title', '--end-card': 'end', '--qa': 'qa' };\n const rest: string[] = [];\n for (let k = 0; k < argv.length; k += 1) {\n const a = argv[k];\n const eq = a.indexOf('=');\n const name = eq > 0 ? a.slice(0, eq) : a;\n if (flags[name]) {\n if (eq > 0) extra[flags[name]] = a.slice(eq + 1);\n else if (argv[k + 1] !== undefined && !argv[k + 1].startsWith('-') && !/\\.json$/i.test(argv[k + 1]) && (flags[name] !== 'qa' || argv[k + 1] === 'strict')) { extra[flags[name]] = argv[k + 1]; k += 1; }\n else extra[flags[name]] = true;\n continue;\n }\n rest.push(a);\n }\n const { values, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n options: {\n url: { type: 'string' }, out: { type: 'string', multiple: true }, mode: { type: 'string' },\n 'allow-perform': { type: 'boolean' }, width: { type: 'string' }, fps: { type: 'string' },\n viewport: { type: 'string' }, scale: { type: 'string' }, 'storage-state': { type: 'string' },\n 'max-wait': { type: 'string' }, hide: { type: 'string', multiple: true }, blur: { type: 'string', multiple: true },\n 'allow-stall': { type: 'boolean' }, navigate: { type: 'boolean' }, security: { type: 'string' }, value: { type: 'string', multiple: true }, player: { type: 'string' }, timeline: { type: 'string' },\n timeout: { type: 'string' }, headed: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },\n frame: { type: 'string' }, background: { type: 'string' }, camera: { type: 'boolean' }, zoom: { type: 'string' },\n captions: { type: 'string' }, 'captions-at': { type: 'string' }, ai: { type: 'string' }, 'ai-vision': { type: 'string' }, alt: { type: 'boolean' },\n voice: { type: 'string' }, script: { type: 'string' }, 'voice-out': { type: 'string' }, 'voice-strict': { type: 'boolean' }, 'no-voice-cache': { type: 'boolean' },\n repair: { type: 'boolean' }, 'repair-vision': { type: 'boolean' }, report: { type: 'string' },\n canvas: { type: 'string' }, watermark: { type: 'string' }, 'watermark-at': { type: 'string' }, brand: { type: 'string' },\n },\n });\n if (values.help) throw new UsageError('');\n const trace = positionals[0];\n if (!trace) throw new UsageError('a trace file is needed');\n if (positionals.length > 1) throw new UsageError(`one trace at a time (got ${positionals.join(', ')})`);\n if (!values.url) throw new UsageError('--url is needed');\n if (!values.out?.length) throw new UsageError('--out is needed');\n const num = (name: string, v: string | undefined, min = 0) => {\n if (v === undefined) return undefined;\n const n = Number(v);\n if (!Number.isFinite(n) || n < min) throw new UsageError(`--${name} must be a number ≥ ${min}`);\n return n;\n };\n const mode = values.mode ?? 'overlay';\n if (mode !== 'overlay' && mode !== 'perform') throw new UsageError('--mode is overlay or perform');\n let viewport: { w: number; h: number } | undefined;\n if (values.viewport) {\n const m = /^(\\d+)x(\\d+)$/i.exec(values.viewport);\n if (!m) throw new UsageError('--viewport is WIDTHxHEIGHT, e.g. 1280x800');\n viewport = { w: Number(m[1]), h: Number(m[2]) };\n }\n if (values.frame && values.frame !== 'none' && values.frame !== 'browser') throw new UsageError('--frame is none or browser');\n const captions = values.captions;\n if (captions !== undefined && captions !== 'burn' && captions !== 'vtt' && captions !== 'both') throw new UsageError('--captions is burn, vtt or both');\n const captionsAt = values['captions-at'];\n if (captionsAt !== undefined && captionsAt !== 'top' && captionsAt !== 'bottom') throw new UsageError('--captions-at is top or bottom');\n const zoom = num('zoom', values.zoom, 1);\n if (extra.qa !== undefined && extra.qa !== true && extra.qa !== 'strict') throw new UsageError('--qa takes nothing or strict');\n if ((extra.qa !== undefined || values.alt || values['ai-vision']) && !values.ai) throw new UsageError('--qa, --alt and --ai-vision need --ai');\n if (values['repair-vision'] && !(values.repair && values.ai)) throw new UsageError('--repair-vision needs --repair and --ai');\n if ((values.script || values['voice-out'] || values['voice-strict'] || values['no-voice-cache']) && !values.voice) throw new UsageError('--script, --voice-out, --voice-strict and --no-voice-cache need --voice');\n if (values.voice && !values.out.some((f) => /\\.mp4$/i.test(f))) throw new UsageError('--voice needs an .mp4 output (a GIF has no sound)');\n let security: boolean | string[] | undefined;\n if (values.security !== undefined) {\n const s = values.security.trim().toLowerCase();\n const guards = s === '' || s === 'all' || s === 'true' ? true : s.split(/[\\s,]+/).filter(Boolean);\n if (Array.isArray(guards) && guards.some((g) => !['secrets', 'money', 'files'].includes(g))) throw new UsageError('--security is all, or a list of secrets, money, files');\n security = guards;\n }\n const typed: Record<string, string> = {};\n for (const v of values.value ?? []) {\n const k = v.indexOf('=');\n if (k < 1) throw new UsageError('--value is name=text, e.g. password=demo-pass');\n typed[v.slice(0, k)] = v.slice(k + 1);\n }\n if ((security !== undefined || values.value?.length) && mode !== 'perform') throw new UsageError('--security and --value are for --mode perform');\n const tryUsage = <T>(f: () => T): T => { try { return f(); } catch (e) { throw new UsageError((e as Error).message); } };\n if (values.canvas !== undefined) tryUsage(() => canvasOf(values.canvas!));\n const at = values['watermark-at'];\n if (at !== undefined && !CORNERS.includes(at as Corner)) throw new UsageError(`--watermark-at is ${CORNERS.join(', ')}`);\n const brand = values.brand !== undefined ? tryUsage(() => brandFile(values.brand!)) : {};\n let watermark: string | Watermark | undefined = values.watermark !== undefined ? tryUsage(() => watermarkOf(values.watermark!)) : brand.watermark;\n if (at !== undefined) {\n if (watermark === undefined) throw new UsageError('--watermark-at needs a watermark (--watermark, or one in --brand)');\n watermark = { ...(typeof watermark === 'string' ? { text: watermark } : watermark), at: at as Corner };\n }\n const width = num('width', values.width, 16);\n const fps = num('fps', values.fps, 1);\n const maxWait = num('max-wait', values['max-wait']);\n return {\n trace,\n options: {\n // The brand first: the flags below win over it.\n ...brand,\n trace,\n url: values.url,\n mode,\n allowPerform: !!values['allow-perform'],\n out: values.out.map((file) => ({ file, ...(width ? { width } : {}), ...(fps ? { fps } : {}) })),\n ...(viewport ? { viewport } : {}),\n ...(values.scale ? { scale: num('scale', values.scale, 1) } : {}),\n ...(values['storage-state'] ? { storageState: values['storage-state'] } : {}),\n ...(maxWait !== undefined ? { cuts: { maxWaitMs: maxWait } } : {}),\n ...(values.hide ? { hide: values.hide } : {}),\n ...(values.blur ? { blur: values.blur } : {}),\n allowStall: !!values['allow-stall'],\n ...(values.navigate ? { navigate: true } : {}),\n ...(security !== undefined ? { security } : {}),\n ...(values.value?.length ? { values: typed } : {}),\n ...(values.player ? { player: values.player } : {}),\n ...(values.timeline ? { timeline: values.timeline } : {}),\n ...(values.timeout ? { timeoutMs: num('timeout', values.timeout, 1) } : {}),\n headless: !values.headed,\n ...(values.frame ? { frame: values.frame as 'none' | 'browser' } : {}),\n ...(values.background ? { background: values.background } : {}),\n ...(zoom ? { camera: { zoom } } : values.camera ? { camera: true } : {}),\n ...(captions ? { captions } : {}),\n ...(captionsAt ? { captionsAt: captionsAt as 'top' | 'bottom' } : {}),\n ...(extra.poster !== undefined ? { poster: extra.poster } : {}),\n ...(extra.title !== undefined ? { titleCard: extra.title } : {}),\n ...(extra.end !== undefined ? { endCard: extra.end } : {}),\n ...(values.canvas !== undefined ? { canvas: values.canvas } : {}),\n ...(watermark !== undefined ? { watermark } : {}),\n ...(extra.qa !== undefined ? { qa: true } : {}),\n ...(values.alt ? { alt: true } : {}),\n ...(values.script ? { script: values.script } : {}),\n ...(values['voice-out'] ? { voiceOut: values['voice-out'] } : {}),\n ...(values['voice-strict'] ? { voiceStrict: true } : {}),\n ...(values.repair ? { repair: true } : {}),\n ...(values['repair-vision'] ? { repairVision: true } : {}),\n },\n ...(values.ai ? { ai: values.ai } : {}),\n ...(values['ai-vision'] ? { aiVision: values['ai-vision'] } : {}),\n ...(values.voice ? { voice: values.voice } : {}),\n ...(values['no-voice-cache'] ? { noVoiceCache: true } : {}),\n ...(extra.qa === 'strict' ? { strict: true } : {}),\n ...(values.report ? { report: values.report } : {}),\n };\n}\n\n/** What --report writes: one guide's outcome, for CI. */\nexport interface Report {\n outcome: 'passed' | 'stalled' | 'failed';\n /** The stalled step (from 0); null otherwise. */\n step: number | null;\n reason: 'not-found' | 'until-timeout' | null;\n /** The stalled step's caption, or the error. */\n message: string | null;\n /** The repair file, when --repair wrote one. */\n repair?: string;\n}\n\n/** The report for a render's outcome (exported for tests). */\nexport function reportOf(err: unknown, traceFile: string, repairFile?: string): Report {\n if (!err) return { outcome: 'passed', step: null, reason: null, message: null };\n const stall = err instanceof RenderError ? err.stall : undefined;\n if (stall && Number.isInteger(stall.index)) {\n let say: string | null = null;\n try { say = ((JSON.parse(readFileSync(traceFile, 'utf8')) as { steps?: Array<{ say?: string }> }).steps?.[stall.index]?.say) ?? null; } catch { /* the error is enough */ }\n return {\n outcome: 'stalled', step: stall.index, reason: stall.reason === 'until-timeout' ? 'until-timeout' : 'not-found',\n message: say ?? (err as Error).message, ...(repairFile && existsSync(repairFile) ? { repair: repairFile } : {}),\n };\n }\n return { outcome: 'failed', step: null, reason: null, message: (err as Error)?.message ?? String(err) };\n}\n\nexport class UsageError extends Error {}\n\nexport async function main(argv: string[], io = { log: console.log, error: console.error }): Promise<number> {\n if (argv[0] === 'suggest' || argv[0] === 'apply') {\n try { return await (argv[0] === 'suggest' ? suggestCmd(argv.slice(1), io) : applyCmd(argv.slice(1), io)); } catch (e) {\n io.error(`trace-avatar-render ${argv[0]}: ${(e as Error).message}`);\n if (e instanceof UsageError) io.error(USAGE);\n return e instanceof UsageError ? 2 : 1;\n }\n }\n let p: Parsed;\n try { p = parse(argv); } catch (e) {\n const msg = (e as Error).message;\n if (msg) io.error(`trace-avatar-render: ${msg}\\n`);\n io.error(USAGE);\n return e instanceof UsageError && !msg ? 0 : 2;\n }\n try {\n if (p.ai) p.options.ai = await providerOf(p.ai, process.env, p.aiVision ? { vision: p.aiVision } : {});\n if (p.voice) p.options.voice = await voiceOf(p.voice, process.env, p.noVoiceCache ? { cacheDir: null } : {});\n const r = await render(p.options);\n for (const o of r.outputs) io.log(`${o.file} ${o.width}×${o.height} ${o.fps} fps ${(r.durationMs / 1000).toFixed(1)} s ${(o.bytes / 1024).toFixed(0)} KB`);\n if (r.rawMs > r.durationMs + 50) io.log(`cut ${((r.rawMs - r.durationMs) / 1000).toFixed(1)} s of waiting`);\n for (const f of [r.poster, r.vtt, r.chapters, r.alt]) if (f) io.log(f);\n if (r.narration) {\n io.log(`narration: ${r.narration.lines.length} line${r.narration.lines.length === 1 ? '' : 's'}${r.narration.holdMs ? `, the video holds ${(r.narration.holdMs / 1000).toFixed(1)} s for them` : ''} ${r.narration.text}`);\n if (r.narration.wav) io.log(r.narration.wav);\n }\n for (const w of r.warnings ?? []) io.error(`warning: ${w}`);\n if (p.report) writeFileSync(p.report, `${JSON.stringify(reportOf(null, p.trace), null, 2)}\\n`);\n if (r.qa) {\n if (!r.qa.length) io.log('qa: nothing flagged');\n for (const f of r.qa) io.log(`qa: ${(f.at / 1000).toFixed(1)} s ${f.kind} ${f.note}`);\n if (p.strict && r.qa.length) { io.error(`trace-avatar-render: qa flagged ${r.qa.length} problem${r.qa.length > 1 ? 's' : ''} (--qa strict)`); return 1; }\n }\n return 0;\n } catch (e) {\n io.error(`trace-avatar-render: ${(e as Error).message}`);\n if (p.report) {\n const first = p.options.out[0];\n const base = (typeof first === 'string' ? first : first.file).replace(/\\.[^./]+$/, '');\n writeFileSync(p.report, `${JSON.stringify(reportOf(e, p.trace, `${base}.repair.json`), null, 2)}\\n`);\n }\n if (e instanceof RenderError && e.screenshot) {\n const first = p.options.out[0];\n const shot = `${(typeof first === 'string' ? first : first.file).replace(/\\.[^./]+$/, '')}.failure.png`;\n writeFileSync(shot, e.screenshot);\n io.error(`the page at that moment: ${shot}`);\n }\n return 1;\n }\n}\n\nconst readJson = (file: string): unknown => {\n try { return JSON.parse(readFileSync(file, 'utf8')); } catch (e) { throw new Error(`could not read ${file}: ${(e as Error).message}`); }\n};\n\n/** suggest <trace.json> --task … --ai …: suggestions, numbered, as JSON (stdout or --out). */\nasync function suggestCmd(argv: string[], io: { log: (m: string) => void }): Promise<number> {\n const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: {\n task: { type: 'string' }, ai: { type: 'string' }, tone: { type: 'string' }, hints: { type: 'string' }, out: { type: 'string' }, 'send-typed': { type: 'boolean' },\n } });\n const [file] = positionals;\n if (!file) throw new UsageError('suggest needs a trace file');\n const task = values.task;\n if (task !== 'captions' && task !== 'title' && task !== 'waits' && task !== 'narration') throw new UsageError('--task is captions, title, waits or narration');\n if (!values.ai) throw new UsageError('suggest needs --ai');\n if (task === 'narration') {\n // A script file for --script: a person edits it before rendering.\n const r = await suggestScript(await providerOf(values.ai), readJson(file) as Parameters<typeof suggestScript>[1]);\n const out = JSON.stringify({ ...r.script, ...(r.dropped.length ? { dropped: r.dropped } : {}) }, null, 2);\n if (values.out) { writeFileSync(values.out, `${out}\\n`); io.log(`${r.script.lines.length} line${r.script.lines.length === 1 ? '' : 's'} in ${values.out}: edit them, then --script ${values.out}`); } else io.log(out);\n return 0;\n }\n const tone = values.tone;\n if (tone !== undefined && tone !== 'friendly' && tone !== 'terse' && tone !== 'formal') throw new UsageError('--tone is friendly, terse or formal');\n const trace = readJson(file) as Parameters<typeof suggest>[1];\n const hints = values.hints ? (readJson(values.hints) as Parameters<typeof suggest>[2]['hints']) : undefined;\n const r = await suggest(task, trace, { ai: await providerOf(values.ai), ...(hints ? { hints } : {}), ...(tone ? { tone } : {}), ...(values['send-typed'] ? { sendTyped: true } : {}) });\n const out = JSON.stringify({ task, suggestions: r.suggestions.map((sg, k) => ({ id: k + 1, ...sg })), dropped: r.dropped }, null, 2);\n if (values.out) { writeFileSync(values.out, `${out}\\n`); io.log(`${r.suggestions.length} suggestion${r.suggestions.length === 1 ? '' : 's'} in ${values.out}`); } else io.log(out);\n return 0;\n}\n\n/** apply <trace.json> <suggestions.json> --accept 1,3|all --out new.trace.json */\nasync function applyCmd(argv: string[], io: { log: (m: string) => void }): Promise<number> {\n const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { accept: { type: 'string' }, out: { type: 'string' } } });\n const [file, sugFile] = positionals;\n if (!file || !sugFile) throw new UsageError('apply needs a trace file and a suggestions file');\n if (!values.accept) throw new UsageError('apply needs --accept 1,3 (or all): a person picks what goes in');\n if (!values.out) throw new UsageError('apply needs --out for the new trace');\n const all = (readJson(sugFile) as { suggestions?: Array<Suggestion & { id: number }> }).suggestions ?? [];\n const ids = values.accept === 'all' ? all.map((x) => x.id) : values.accept.split(',').map((x) => Number(x.trim()));\n const missing = ids.filter((id) => !all.some((x) => x.id === id));\n if (missing.length) throw new UsageError(`no suggestion ${missing.join(', ')} in ${sugFile}`);\n const next = applySuggestions(readJson(file) as Parameters<typeof applySuggestions>[0], all.filter((x) => ids.includes(x.id)));\n writeFileSync(values.out, `${JSON.stringify(next, null, 2)}\\n`);\n io.log(`applied ${ids.length} of ${all.length} to ${values.out}`);\n return 0;\n}\n\nconst isMain = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('/trace-avatar-render') || process.argv[1]?.endsWith('/cli.js');\nif (isMain) void main(process.argv.slice(2)).then((code) => { process.exitCode = code; });\n"],"mappings":";;;;;;;;;;;;;;AAOA,SAAS,YAAY,cAAc,qBAAqB;AACxD,SAAS,SAAS,kBAAkB,eAAe;AAKnD,SAAS,iBAAiB;AAMnB,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0Ed,SAAS,MAAM,MAAwB;AAG5C,QAAM,QAAoG,CAAC;AAC3G,QAAM,QAA2D,EAAE,YAAY,UAAU,gBAAgB,SAAS,cAAc,OAAO,QAAQ,KAAK;AACpJ,QAAM,OAAiB,CAAC;AACxB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GAAG;AACvC,UAAM,IAAI,KAAK,CAAC;AAChB,UAAM,KAAK,EAAE,QAAQ,GAAG;AACxB,UAAM,OAAO,KAAK,IAAI,EAAE,MAAM,GAAG,EAAE,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AAO,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,OAAO,EAAE,KAAK,CAAC,CAAC;AACjH,QAAM,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;AAChE,MAAI,QAAQ,OAAQ,OAAM,IAAI,WAAW,iBAAiB,QAAQ,KAAK,IAAI,CAAC,OAAO,OAAO,EAAE;AAC5F,QAAM,OAAO,iBAAiB,SAAS,IAAI,GAA6C,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,EAAE,CAAC,CAAC;AAC7H,gBAAc,OAAO,KAAK,GAAG,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;AAAA,CAAI;AAC9D,KAAG,IAAI,WAAW,IAAI,MAAM,OAAO,IAAI,MAAM,OAAO,OAAO,GAAG,EAAE;AAChE,SAAO;AACT;AAEA,IAAM,SAAS,YAAY,QAAQ,UAAU,QAAQ,KAAK,CAAC,CAAC,MAAM,QAAQ,KAAK,CAAC,GAAG,SAAS,sBAAsB,KAAK,QAAQ,KAAK,CAAC,GAAG,SAAS,SAAS;AAC1J,IAAI,OAAQ,MAAK,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS;AAAE,UAAQ,WAAW;AAAM,CAAC;","names":["r","out"]}
package/dist/index.d.ts CHANGED
@@ -225,6 +225,57 @@ declare function cameraKeys(actions: readonly Action[], o: CameraOptions): Key[]
225
225
  /** The camera at each output time: the source rect to show. */
226
226
  declare function cameraPath(actions: readonly Action[], o: CameraOptions): (t: number) => Rect;
227
227
 
228
+ /**
229
+ * A brand: the look of a video in one place (canvas, watermark, cards, frame, background, camera, captions),
230
+ * so every clip of a product, or of a showcase, looks the same. PURE except brandFile (reads the file).
231
+ */
232
+
233
+ /** An output picture of a fixed size, the app composed onto it (for social: 9:16 Reels, 4:5 and 1:1 feeds). */
234
+ interface Canvas {
235
+ width: number;
236
+ height: number;
237
+ }
238
+ type CanvasSpec = Canvas | '9:16' | '4:5' | '1:1' | '16:9' | string;
239
+ /** The named shapes, at the sizes the platforms ask for. */
240
+ declare const CANVASES: Record<string, Canvas>;
241
+ type Corner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
242
+ declare const CORNERS: readonly Corner[];
243
+ /** A small badge on every frame (cards too), e.g. "Created with TraceAvatar · traceavatar.com". */
244
+ interface Watermark {
245
+ text: string;
246
+ /** Default bottom-right. */
247
+ at?: Corner;
248
+ /** 0–1, default 0.9. */
249
+ opacity?: number;
250
+ /** An image file (PNG, JPEG, SVG, WebP) shown before the text. */
251
+ logo?: string;
252
+ }
253
+ /** A canvas from a name ('9:16'), 'WIDTHxHEIGHT', or { width, height }. Throws on anything else. */
254
+ declare function canvasOf(v: CanvasSpec): Canvas;
255
+ /** A watermark from its text or its options. Throws on a bad corner or opacity. */
256
+ declare function watermarkOf(v: string | Watermark): Watermark;
257
+ /** What a brand file may set: the polish options, nothing about what is played. */
258
+ interface Brand {
259
+ canvas?: CanvasSpec;
260
+ watermark?: string | Watermark;
261
+ frame?: 'none' | 'browser';
262
+ background?: string;
263
+ camera?: boolean | {
264
+ zoom?: number;
265
+ };
266
+ captions?: 'burn' | 'vtt' | 'both';
267
+ captionsAt?: 'top' | 'bottom';
268
+ titleCard?: boolean | string | CardOptions;
269
+ endCard?: boolean | string | CardOptions;
270
+ }
271
+ /**
272
+ * A brand checked: unknown keys and bad values are refused, naming each. Logo paths are resolved against
273
+ * `dir` (the brand file's folder), so a brand can sit beside its logo.
274
+ */
275
+ declare function brandOf(json: unknown, dir?: string): Brand;
276
+ /** A brand file, read and checked. */
277
+ declare function brandFile(file: string): Brand;
278
+
228
279
  /** Where the capture goes in the output picture. PURE. */
229
280
 
230
281
  type FrameStyle = 'none' | 'browser';
@@ -237,12 +288,14 @@ interface Layout {
237
288
  bar: Rect | null;
238
289
  /** The window (bar + content), for the shadow and corners. */
239
290
  window: Rect;
291
+ /** On a canvas: the picture is the canvas's shape, the app placed on it (always drawn over a background). */
292
+ canvas?: boolean;
240
293
  }
241
294
  /**
242
295
  * The output size for a capture of srcW×srcH shown `width` wide (default: the capture's width, never
243
296
  * upscaled), with or without a browser window around it.
244
297
  */
245
- declare function layoutOf(srcW: number, srcH: number, width: number | undefined, frame?: FrameStyle): Layout;
298
+ declare function layoutOf(srcW: number, srcH: number, width: number | undefined, frame?: FrameStyle, canvas?: Canvas): Layout;
246
299
 
247
300
  /**
248
301
  * The parts of a frame that have text in them (the window's title bar, burned-in captions, title and end
@@ -251,9 +304,17 @@ declare function layoutOf(srcW: number, srcH: number, width: number | undefined,
251
304
 
252
305
  interface CardOptions {
253
306
  title: string;
307
+ /** A line with the avatar's initial (the trace's avatar name, by default). */
254
308
  sub?: string;
309
+ /** The avatar's (and the URL's) colour. */
255
310
  color?: string;
311
+ /** A web address shown large under the title, e.g. "naijaprices.com". */
312
+ url?: string;
313
+ /** An image file (PNG, JPEG, SVG, WebP) above the title. */
314
+ logo?: string;
256
315
  }
316
+ /** An image file as a data: URI, for the layer pages (they load nothing from the network). */
317
+ declare function dataUri(file: string): string;
257
318
  interface Layers {
258
319
  /** The background, the window and its title bar, for a page path. */
259
320
  base(layout: Layout, o: {
@@ -270,6 +331,11 @@ interface Layers {
270
331
  card(layout: Layout, o: CardOptions & {
271
332
  background: string;
272
333
  }): Promise<Image>;
334
+ /** The watermark: a small badge (optional logo, then the text) on transparent pixels. */
335
+ badge(text: string, o: {
336
+ fontPx: number;
337
+ logo?: string;
338
+ }): Promise<Image>;
273
339
  close(): Promise<void>;
274
340
  }
275
341
  /** The default background behind a framed capture. */
@@ -566,12 +632,20 @@ interface RenderOptions {
566
632
  /** 'burn' draws the steps' words into the video (the player's own bubble is then off), 'vtt' writes
567
633
  * <out>.vtt and <out>.chapters.vtt beside the first output, 'both' does both. Default: neither. */
568
634
  captions?: 'burn' | 'vtt' | 'both';
635
+ /** Where burned-in captions sit: 'bottom' (the default) or 'top', for an app whose own UI is at the
636
+ * bottom of the page (a toolbar, a card, a cookie bar) where the caption would cover it. */
637
+ captionsAt?: 'top' | 'bottom';
569
638
  /** A still at the first click: true writes <out>.png beside the first output, or give a path. */
570
639
  poster?: boolean | string;
571
640
  /** A 1.5 s card before the guide: true (the trace's title and avatar), a title, or { title, sub }. */
572
641
  titleCard?: boolean | string | CardOptions;
573
- /** A 2 s card after it: true ("Done"), a title, or { title, sub }. */
642
+ /** A 2 s card after it: true ("Done"), a title, or { title, sub, url, logo }. */
574
643
  endCard?: boolean | string | CardOptions;
644
+ /** Compose onto a picture of this shape: '9:16' (1080×1920), '4:5', '1:1', '16:9', 'WxH' or { width, height }.
645
+ * The app is placed between safe margins on the background; an output's width scales the whole canvas. */
646
+ canvas?: CanvasSpec;
647
+ /** A small badge on every frame, cards included: its text, or { text, at, opacity, logo }. */
648
+ watermark?: string | Watermark;
575
649
  /** The AI for qa and alt (see trace-avatar/assist). Without it nothing calls a model. */
576
650
  ai?: Ai;
577
651
  /** Send a frame per step (640 px) to the AI to look for errors, empty states, a stall, personal data. */
@@ -594,7 +668,7 @@ interface RenderOptions {
594
668
  repairVision?: boolean;
595
669
  }
596
670
  /** What finish() takes besides the capture: the composing options, with the cards resolved. */
597
- type FinishOptions = Pick<RenderOptions, 'cuts' | 'timeline' | 'frame' | 'background' | 'camera' | 'captions' | 'poster'> & {
671
+ type FinishOptions = Pick<RenderOptions, 'cuts' | 'timeline' | 'frame' | 'background' | 'camera' | 'captions' | 'captionsAt' | 'poster' | 'canvas' | 'watermark'> & {
598
672
  cards?: {
599
673
  title?: CardOptions;
600
674
  end?: CardOptions;
@@ -672,6 +746,11 @@ declare function render(o: RenderOptions): Promise<RenderResult>;
672
746
  declare function finish(cap: Capture, outs: Array<OutSpec & {
673
747
  format: OutFormat;
674
748
  }>, o?: FinishOptions): Promise<RenderResult>;
749
+ /** Where a badge w×h sits in a picture W×H: in its corner, a margin of 2.5% of the shorter side from the edges. */
750
+ declare function badgeAt(W: number, H: number, w: number, h: number, at?: Corner): {
751
+ x: number;
752
+ y: number;
753
+ };
675
754
 
676
755
  /**
677
756
  * GIF encoding with gifenc (pure JS, no binaries).
@@ -852,4 +931,4 @@ declare function repairGuide(o: {
852
931
  first?: RenderError;
853
932
  }): Promise<RepairOutcome>;
854
933
 
855
- export { type Action, type CameraOptions, type Capture, type CaptureOptions, type CapturedFrame, type CardOptions, type Cue, DEFAULT_BACKGROUND, DEFAULT_MAX_WAIT_MS, type EditOptions, type FinishOptions, type FrameStyle, GEMINI_TTS, type GifOptions, type GifResult, type GifWriter, type Image, type Layers, type Layout, type NarrationPlan, type OutFormat, type OutSpec, type Pcm, type Phase, type PlanOptions, type PlannedLine, type Rect, RenderError, type RenderOptions, type RenderOutput, type RenderResult, type RepairOutcome, type RepairSuggestion, type Script, type Segment, type Span, TRACK_RATE, type TimelineEvent, type Unresolved, type Voice, ZOOM_KINDS, actionsOf, blank, cached, cameraKeys, cameraPath, captionCues, capture, cardOf, chapterCues, createGifWriter, createLayers, crop, crossfade, cueAt, drawRegion, durationOf, editList, encodeGif, encodeMp4, findFfmpeg, findPlayer, finish, fitWidth, formatOf, frameTimes, fromS16le, fromWav, geminiVoice, layoutOf, linesOf, mix, mp4Args, msOf, narrationText, openAiVoice, outputAt, overlay, pageAt, paletteOf, parseScript, pickFrames, pixel, planNarration, providerOf, render, repairGuide, repairScriptOf, resample, resize, runQa, sayVoice, sourceAt, spansOf, stallInspector, stepCues, suggestScript, toVtt, toWav, trimSilence, voiceOf, withHolds };
934
+ export { type Action, type Brand, CANVASES, CORNERS, type CameraOptions, type Canvas, type CanvasSpec, type Capture, type CaptureOptions, type CapturedFrame, type CardOptions, type Corner, type Cue, DEFAULT_BACKGROUND, DEFAULT_MAX_WAIT_MS, type EditOptions, type FinishOptions, type FrameStyle, GEMINI_TTS, type GifOptions, type GifResult, type GifWriter, type Image, type Layers, type Layout, type NarrationPlan, type OutFormat, type OutSpec, type Pcm, type Phase, type PlanOptions, type PlannedLine, type Rect, RenderError, type RenderOptions, type RenderOutput, type RenderResult, type RepairOutcome, type RepairSuggestion, type Script, type Segment, type Span, TRACK_RATE, type TimelineEvent, type Unresolved, type Voice, type Watermark, ZOOM_KINDS, actionsOf, badgeAt, blank, brandFile, brandOf, cached, cameraKeys, cameraPath, canvasOf, captionCues, capture, cardOf, chapterCues, createGifWriter, createLayers, crop, crossfade, cueAt, dataUri, drawRegion, durationOf, editList, encodeGif, encodeMp4, findFfmpeg, findPlayer, finish, fitWidth, formatOf, frameTimes, fromS16le, fromWav, geminiVoice, layoutOf, linesOf, mix, mp4Args, msOf, narrationText, openAiVoice, outputAt, overlay, pageAt, paletteOf, parseScript, pickFrames, pixel, planNarration, providerOf, render, repairGuide, repairScriptOf, resample, resize, runQa, sayVoice, sourceAt, spansOf, stallInspector, stepCues, suggestScript, toVtt, toWav, trimSilence, voiceOf, watermarkOf, withHolds };
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import {
2
+ CANVASES,
3
+ CORNERS,
2
4
  DEFAULT_BACKGROUND,
3
5
  DEFAULT_MAX_WAIT_MS,
4
6
  GEMINI_TTS,
@@ -6,10 +8,14 @@ import {
6
8
  TRACK_RATE,
7
9
  ZOOM_KINDS,
8
10
  actionsOf,
11
+ badgeAt,
9
12
  blank,
13
+ brandFile,
14
+ brandOf,
10
15
  cached,
11
16
  cameraKeys,
12
17
  cameraPath,
18
+ canvasOf,
13
19
  captionCues,
14
20
  capture,
15
21
  cardOf,
@@ -19,6 +25,7 @@ import {
19
25
  crop,
20
26
  crossfade,
21
27
  cueAt,
28
+ dataUri,
22
29
  drawRegion,
23
30
  durationOf,
24
31
  editList,
@@ -65,9 +72,12 @@ import {
65
72
  toWav,
66
73
  trimSilence,
67
74
  voiceOf,
75
+ watermarkOf,
68
76
  withHolds
69
- } from "./chunk-VTXIXGG4.js";
77
+ } from "./chunk-2ASNE3WF.js";
70
78
  export {
79
+ CANVASES,
80
+ CORNERS,
71
81
  DEFAULT_BACKGROUND,
72
82
  DEFAULT_MAX_WAIT_MS,
73
83
  GEMINI_TTS,
@@ -75,10 +85,14 @@ export {
75
85
  TRACK_RATE,
76
86
  ZOOM_KINDS,
77
87
  actionsOf,
88
+ badgeAt,
78
89
  blank,
90
+ brandFile,
91
+ brandOf,
79
92
  cached,
80
93
  cameraKeys,
81
94
  cameraPath,
95
+ canvasOf,
82
96
  captionCues,
83
97
  capture,
84
98
  cardOf,
@@ -88,6 +102,7 @@ export {
88
102
  crop,
89
103
  crossfade,
90
104
  cueAt,
105
+ dataUri,
91
106
  drawRegion,
92
107
  durationOf,
93
108
  editList,
@@ -134,6 +149,7 @@ export {
134
149
  toWav,
135
150
  trimSilence,
136
151
  voiceOf,
152
+ watermarkOf,
137
153
  withHolds
138
154
  };
139
155
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trace-avatar-render",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Render a trace-avatar guide to a GIF or MP4 by playing it on your real app in headless Chromium.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -60,7 +60,7 @@
60
60
  "gifenc": "^1.0.3",
61
61
  "playwright": "^1.65.0",
62
62
  "pngjs": "^7.0.0",
63
- "trace-avatar": "^0.1.13"
63
+ "trace-avatar": "^0.1.14"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/node": "^22.0.0",