trace-avatar-render 0.1.4 → 0.1.6
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/CHANGELOG.md +14 -1
- package/README.md +14 -1
- package/dist/{chunk-2ASNE3WF.js → chunk-ZNHFXKD3.js} +79 -11
- package/dist/chunk-ZNHFXKD3.js.map +1 -0
- package/dist/cli.js +13 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +186 -162
- package/dist/index.js +5 -1
- package/package.json +1 -1
- package/dist/chunk-2ASNE3WF.js.map +0 -1
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';\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;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AO,SAAS,OAAO,EAA2D,eAAe,CAAC;AACxG,QAAM,MAAM,OAAO,WAAW,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,OAAO,OAAO,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"]}
|
|
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). <file>@<shape> gives that output its own\n canvas (e.g. --out wide.mp4@16:9 --out square.mp4@1:1): several shapes from one capture\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 for (const o of values.out ?? []) { const m = /^.+\\.(?:gif|mp4)@(.+)$/i.exec(o); if (m) tryUsage(() => canvasOf(m[1])); }\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((spec) => {\n const m = /^(.+\\.(?:gif|mp4))@(.+)$/i.exec(spec);\n const file = m ? m[1] : spec;\n return { file, ...(width ? { width } : {}), ...(fps ? { fps } : {}), ...(m ? { canvas: m[2] } : {}) };\n }),\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');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M,EAAE,EAAE,IAAI,OAAO,OAAO,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
|
@@ -1,166 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Browser, Page } from 'playwright';
|
|
2
2
|
import { Ai, preview, Suggestion, Candidate, TextCandidate, applyRaw } from 'trace-avatar/assist';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* The guide's own timeline, and the edit list made from it. PURE: plain numbers in, plain numbers out.
|
|
6
|
-
*
|
|
7
|
-
* Times are wall-clock milliseconds (the page logs Date.now(), the screencast stamps frames in epoch
|
|
8
|
-
* seconds), so events and frames from every page load share one clock.
|
|
9
|
-
*/
|
|
10
|
-
type Phase = 'idle' | 'playing' | 'paused' | 'waiting' | 'ended';
|
|
11
|
-
interface TimelineEvent {
|
|
12
|
-
t: number;
|
|
13
|
-
type: 'ready' | 'play' | 'state' | 'step' | 'stalled' | 'handoff' | 'page' | 'end' | 'error' | 'blocked' | 'unload';
|
|
14
|
-
phase?: Phase;
|
|
15
|
-
index?: number;
|
|
16
|
-
stepType?: string;
|
|
17
|
-
reason?: string;
|
|
18
|
-
message?: string;
|
|
19
|
-
url?: string;
|
|
20
|
-
/** step: where its element was (viewport CSS px). */
|
|
21
|
-
rect?: {
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
w: number;
|
|
25
|
-
h: number;
|
|
26
|
-
};
|
|
27
|
-
/** step: its words. */
|
|
28
|
-
say?: string;
|
|
29
|
-
}
|
|
30
|
-
interface Span {
|
|
31
|
-
from: number;
|
|
32
|
-
to: number;
|
|
33
|
-
phase: Phase;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A kept stretch of the capture, in source time. A hold (from === to, `hold` ms) shows the frame at `from`
|
|
37
|
-
* for that long: the video waits, for instance while a narrated line finishes.
|
|
38
|
-
*/
|
|
39
|
-
interface Segment {
|
|
40
|
-
from: number;
|
|
41
|
-
to: number;
|
|
42
|
-
hold?: number;
|
|
43
|
-
}
|
|
44
|
-
interface EditOptions {
|
|
45
|
-
/** Where the output starts and ends (source time). */
|
|
46
|
-
start: number;
|
|
47
|
-
end: number;
|
|
48
|
-
/** A wait longer than this keeps its first and last half of it; the middle is cut. Default 800. 0 keeps every wait. */
|
|
49
|
-
maxWaitMs?: number;
|
|
50
|
-
}
|
|
51
|
-
declare const DEFAULT_MAX_WAIT_MS = 800;
|
|
52
|
-
/**
|
|
53
|
-
* The player's phase over [start, end]. A page unloading counts as waiting until the next page's player
|
|
54
|
-
* reports a phase again.
|
|
55
|
-
*/
|
|
56
|
-
declare function spansOf(events: readonly TimelineEvent[], start: number, end: number): Span[];
|
|
57
|
-
/** The stretches of the capture to keep: everything, except the middle of each long wait. */
|
|
58
|
-
declare function editList(events: readonly TimelineEvent[], o: EditOptions): Segment[];
|
|
59
|
-
declare const durationOf: (segs: readonly Segment[]) => number;
|
|
60
|
-
/** The source time shown at output time `t` (clamped to the ends). */
|
|
61
|
-
declare function sourceAt(segs: readonly Segment[], t: number): number;
|
|
62
|
-
/** The output time where source time `src` lands, or null when it was cut. */
|
|
63
|
-
declare function outputAt(segs: readonly Segment[], src: number): number | null;
|
|
64
|
-
/**
|
|
65
|
-
* Insert holds: each `{ at, ms }` (at = output time on `segs`) freezes the frame there for `ms`. Later output
|
|
66
|
-
* times move by the holds before them.
|
|
67
|
-
*/
|
|
68
|
-
declare function withHolds(segs: readonly Segment[], holds: ReadonlyArray<{
|
|
69
|
-
at: number;
|
|
70
|
-
ms: number;
|
|
71
|
-
}>): Segment[];
|
|
72
|
-
/** The source time of every output frame at `fps`. */
|
|
73
|
-
declare function frameTimes(segs: readonly Segment[], fps: number): number[];
|
|
74
|
-
/** For each wanted time, the last captured frame at or before it (the first frame before any). */
|
|
75
|
-
declare function pickFrames(captured: readonly number[], want: readonly number[]): number[];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Play a trace on the real app in headless Chromium and capture it.
|
|
79
|
-
*
|
|
80
|
-
* The player (trace-perform.min.js) and a small bootstrap are injected into every page of the context,
|
|
81
|
-
* so a guide that crosses a full page load carries on (the player's resumeKey) and keeps logging its
|
|
82
|
-
* events. Frames come from Chromium's screencast, stamped on the same wall clock as the events.
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
interface CaptureOptions {
|
|
86
|
-
/** The trace object. */
|
|
87
|
-
trace: unknown;
|
|
88
|
-
url: string;
|
|
89
|
-
mode: 'overlay' | 'perform';
|
|
90
|
-
viewport: {
|
|
91
|
-
w: number;
|
|
92
|
-
h: number;
|
|
93
|
-
};
|
|
94
|
-
/** Device pixel ratio. Default 1. */
|
|
95
|
-
scale?: number;
|
|
96
|
-
/** A signed-in session (Playwright storageState file). */
|
|
97
|
-
storageState?: string;
|
|
98
|
-
/** The player build (trace-perform.min.js). */
|
|
99
|
-
playerFile: string;
|
|
100
|
-
/** Selectors hidden before capture (e.g. your own dev toolbars). */
|
|
101
|
-
hide?: string[];
|
|
102
|
-
/** Selectors blurred before capture, as well as [data-trace-blur]. */
|
|
103
|
-
blur?: string[];
|
|
104
|
-
rate?: number;
|
|
105
|
-
/** When a step is on another page, load that page (as an app's router would) instead of waiting for it. */
|
|
106
|
-
navigate?: boolean;
|
|
107
|
-
/** Perform mode: what the guide leaves to the viewer (trace-avatar's `security`). */
|
|
108
|
-
security?: boolean | string[];
|
|
109
|
-
/** Perform mode: values to type, by name or field label (trace-avatar's `values`). */
|
|
110
|
-
values?: Record<string, string>;
|
|
111
|
-
/** The player's own captions: 'none' when the renderer burns them in itself. Default: the player's. */
|
|
112
|
-
captions?: 'bubble' | 'bar' | 'none';
|
|
113
|
-
/** A guide's own pause (or a hand-off) is held this long, then it plays on. Default 1200. */
|
|
114
|
-
pauseHoldMs?: number;
|
|
115
|
-
/** Keep capturing this long after the end. Default 1500. */
|
|
116
|
-
holdEndMs?: number;
|
|
117
|
-
/** Still frames before the guide starts. Default 500. */
|
|
118
|
-
leadMs?: number;
|
|
119
|
-
/** Render a stalled guide anyway (it shows "Looking for …") instead of failing. */
|
|
120
|
-
allowStall?: boolean;
|
|
121
|
-
/** Called on a stall with the live page, before anything else happens; what it returns rides on the RenderError. */
|
|
122
|
-
onStall?: (page: Page, stall: {
|
|
123
|
-
index: number;
|
|
124
|
-
reason: string;
|
|
125
|
-
}) => Promise<unknown>;
|
|
126
|
-
/** Give up after this long. Default 120 000. */
|
|
127
|
-
timeoutMs?: number;
|
|
128
|
-
headless?: boolean;
|
|
129
|
-
}
|
|
130
|
-
interface CapturedFrame {
|
|
131
|
-
t: number;
|
|
132
|
-
png: Buffer;
|
|
133
|
-
}
|
|
134
|
-
interface Capture {
|
|
135
|
-
frames: CapturedFrame[];
|
|
136
|
-
/** The viewport in CSS px and the device pixel ratio (frames are viewport × scale). */
|
|
137
|
-
viewport?: {
|
|
138
|
-
w: number;
|
|
139
|
-
h: number;
|
|
140
|
-
scale: number;
|
|
141
|
-
};
|
|
142
|
-
/** Each page's title, by path. */
|
|
143
|
-
titles?: Record<string, string>;
|
|
144
|
-
events: TimelineEvent[];
|
|
145
|
-
/** When the guide started and when capture stopped (wall ms). */
|
|
146
|
-
playAt: number;
|
|
147
|
-
stopAt: number;
|
|
148
|
-
endAt: number | null;
|
|
149
|
-
}
|
|
150
|
-
declare class RenderError extends Error {
|
|
151
|
-
readonly screenshot?: Buffer | undefined;
|
|
152
|
-
/** A stall: which step, why, and what onStall found on the page. */
|
|
153
|
-
stall?: {
|
|
154
|
-
index: number;
|
|
155
|
-
reason: string;
|
|
156
|
-
data?: unknown;
|
|
157
|
-
};
|
|
158
|
-
constructor(message: string, screenshot?: Buffer | undefined);
|
|
159
|
-
}
|
|
160
|
-
declare function capture(o: CaptureOptions): Promise<Capture>;
|
|
161
|
-
/** Where the player build is: an explicit file, TRACE_AVATAR_PLAYER, or the installed trace-avatar. */
|
|
162
|
-
declare function findPlayer(explicit?: string, env?: NodeJS.ProcessEnv): Promise<string>;
|
|
163
|
-
|
|
164
4
|
/** RGBA pixel helpers. PURE. */
|
|
165
5
|
interface Image {
|
|
166
6
|
width: number;
|
|
@@ -342,6 +182,188 @@ interface Layers {
|
|
|
342
182
|
declare const DEFAULT_BACKGROUND = "linear-gradient(135deg, #dfe7fb 0%, #eef0f6 50%, #f6e9f1 100%)";
|
|
343
183
|
declare function createLayers(browser: Browser): Promise<Layers>;
|
|
344
184
|
|
|
185
|
+
/**
|
|
186
|
+
* The guide's own timeline, and the edit list made from it. PURE: plain numbers in, plain numbers out.
|
|
187
|
+
*
|
|
188
|
+
* Times are wall-clock milliseconds (the page logs Date.now(), the screencast stamps frames in epoch
|
|
189
|
+
* seconds), so events and frames from every page load share one clock.
|
|
190
|
+
*/
|
|
191
|
+
type Phase = 'idle' | 'playing' | 'paused' | 'waiting' | 'ended';
|
|
192
|
+
interface TimelineEvent {
|
|
193
|
+
t: number;
|
|
194
|
+
type: 'ready' | 'play' | 'state' | 'step' | 'stalled' | 'handoff' | 'page' | 'end' | 'error' | 'blocked' | 'unload';
|
|
195
|
+
phase?: Phase;
|
|
196
|
+
index?: number;
|
|
197
|
+
stepType?: string;
|
|
198
|
+
reason?: string;
|
|
199
|
+
message?: string;
|
|
200
|
+
url?: string;
|
|
201
|
+
/** step: where its element was (viewport CSS px). */
|
|
202
|
+
rect?: {
|
|
203
|
+
x: number;
|
|
204
|
+
y: number;
|
|
205
|
+
w: number;
|
|
206
|
+
h: number;
|
|
207
|
+
};
|
|
208
|
+
/** step: its words. */
|
|
209
|
+
say?: string;
|
|
210
|
+
}
|
|
211
|
+
interface Span {
|
|
212
|
+
from: number;
|
|
213
|
+
to: number;
|
|
214
|
+
phase: Phase;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A kept stretch of the capture, in source time. A hold (from === to, `hold` ms) shows the frame at `from`
|
|
218
|
+
* for that long: the video waits, for instance while a narrated line finishes.
|
|
219
|
+
*/
|
|
220
|
+
/** A stretch of the source (from–to), or a frozen moment (`hold` ms at `from`); `card` shows a capture's card instead. */
|
|
221
|
+
interface Segment {
|
|
222
|
+
from: number;
|
|
223
|
+
to: number;
|
|
224
|
+
hold?: number;
|
|
225
|
+
card?: number;
|
|
226
|
+
}
|
|
227
|
+
interface EditOptions {
|
|
228
|
+
/** Where the output starts and ends (source time). */
|
|
229
|
+
start: number;
|
|
230
|
+
end: number;
|
|
231
|
+
/** A wait longer than this keeps its first and last half of it; the middle is cut. Default 800. 0 keeps every wait. */
|
|
232
|
+
maxWaitMs?: number;
|
|
233
|
+
}
|
|
234
|
+
declare const DEFAULT_MAX_WAIT_MS = 800;
|
|
235
|
+
/**
|
|
236
|
+
* The player's phase over [start, end]. A page unloading counts as waiting until the next page's player
|
|
237
|
+
* reports a phase again.
|
|
238
|
+
*/
|
|
239
|
+
declare function spansOf(events: readonly TimelineEvent[], start: number, end: number): Span[];
|
|
240
|
+
/** The stretches of the capture to keep: everything, except the middle of each long wait. */
|
|
241
|
+
declare function editList(events: readonly TimelineEvent[], o: EditOptions): Segment[];
|
|
242
|
+
declare const durationOf: (segs: readonly Segment[]) => number;
|
|
243
|
+
/** The source time shown at output time `t` (clamped to the ends). */
|
|
244
|
+
declare function sourceAt(segs: readonly Segment[], t: number): number;
|
|
245
|
+
/** The output time where source time `src` lands, or null when it was cut. */
|
|
246
|
+
declare function outputAt(segs: readonly Segment[], src: number): number | null;
|
|
247
|
+
/**
|
|
248
|
+
* Insert holds: each `{ at, ms }` (at = output time on `segs`) freezes the frame there for `ms`. Later output
|
|
249
|
+
* times move by the holds before them.
|
|
250
|
+
*/
|
|
251
|
+
declare function withHolds(segs: readonly Segment[], holds: ReadonlyArray<{
|
|
252
|
+
at: number;
|
|
253
|
+
ms: number;
|
|
254
|
+
}>): Segment[];
|
|
255
|
+
/**
|
|
256
|
+
* Insert cards (a director's `d.card`): each `{ t, ms }` (t = source time) is shown for `ms` at that moment, as a
|
|
257
|
+
* held segment marked with its index in `cards`. A card at a cut-out moment goes where the next kept stretch starts.
|
|
258
|
+
*/
|
|
259
|
+
declare function withCards(segs: readonly Segment[], cards: ReadonlyArray<{
|
|
260
|
+
t: number;
|
|
261
|
+
ms: number;
|
|
262
|
+
}>): Segment[];
|
|
263
|
+
/** For every output frame at `fps`, the card it shows (its index), or undefined for the app. */
|
|
264
|
+
declare function cardFrames(segs: readonly Segment[], fps: number): Array<number | undefined>;
|
|
265
|
+
/** The source time of every output frame at `fps`. */
|
|
266
|
+
declare function frameTimes(segs: readonly Segment[], fps: number): number[];
|
|
267
|
+
/** For each wanted time, the last captured frame at or before it (the first frame before any). */
|
|
268
|
+
declare function pickFrames(captured: readonly number[], want: readonly number[]): number[];
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Play a trace on the real app in headless Chromium and capture it.
|
|
272
|
+
*
|
|
273
|
+
* The player (trace-perform.min.js) and a small bootstrap are injected into every page of the context,
|
|
274
|
+
* so a guide that crosses a full page load carries on (the player's resumeKey) and keeps logging its
|
|
275
|
+
* events. Frames come from Chromium's screencast, stamped on the same wall clock as the events.
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
interface CaptureOptions {
|
|
279
|
+
/** The trace object. */
|
|
280
|
+
trace: unknown;
|
|
281
|
+
url: string;
|
|
282
|
+
mode: 'overlay' | 'perform';
|
|
283
|
+
viewport: {
|
|
284
|
+
w: number;
|
|
285
|
+
h: number;
|
|
286
|
+
};
|
|
287
|
+
/** Device pixel ratio. Default 1. */
|
|
288
|
+
scale?: number;
|
|
289
|
+
/** A signed-in session (Playwright storageState file). */
|
|
290
|
+
storageState?: string;
|
|
291
|
+
/** The player build (trace-perform.min.js). */
|
|
292
|
+
playerFile: string;
|
|
293
|
+
/** Selectors hidden before capture (e.g. your own dev toolbars). */
|
|
294
|
+
hide?: string[];
|
|
295
|
+
/** Selectors blurred before capture, as well as [data-trace-blur]. */
|
|
296
|
+
blur?: string[];
|
|
297
|
+
rate?: number;
|
|
298
|
+
/** When a step is on another page, load that page (as an app's router would) instead of waiting for it. */
|
|
299
|
+
navigate?: boolean;
|
|
300
|
+
/** Perform mode: what the guide leaves to the viewer (trace-avatar's `security`). */
|
|
301
|
+
security?: boolean | string[];
|
|
302
|
+
/** Perform mode: values to type, by name or field label (trace-avatar's `values`). */
|
|
303
|
+
values?: Record<string, string>;
|
|
304
|
+
/** The player's own captions: 'none' when the renderer burns them in itself. Default: the player's. */
|
|
305
|
+
captions?: 'bubble' | 'bar' | 'none';
|
|
306
|
+
/** A guide's own pause (or a hand-off) is held this long, then it plays on. Default 1200. */
|
|
307
|
+
pauseHoldMs?: number;
|
|
308
|
+
/** Keep capturing this long after the end. Default 1500. */
|
|
309
|
+
holdEndMs?: number;
|
|
310
|
+
/** Still frames before the guide starts. Default 500. */
|
|
311
|
+
leadMs?: number;
|
|
312
|
+
/** Render a stalled guide anyway (it shows "Looking for …") instead of failing. */
|
|
313
|
+
allowStall?: boolean;
|
|
314
|
+
/** Called on a stall with the live page, before anything else happens; what it returns rides on the RenderError. */
|
|
315
|
+
onStall?: (page: Page, stall: {
|
|
316
|
+
index: number;
|
|
317
|
+
reason: string;
|
|
318
|
+
}) => Promise<unknown>;
|
|
319
|
+
/** Give up after this long. Default 120 000. */
|
|
320
|
+
timeoutMs?: number;
|
|
321
|
+
headless?: boolean;
|
|
322
|
+
}
|
|
323
|
+
interface CapturedFrame {
|
|
324
|
+
t: number;
|
|
325
|
+
png: Buffer;
|
|
326
|
+
}
|
|
327
|
+
interface Capture {
|
|
328
|
+
frames: CapturedFrame[];
|
|
329
|
+
/** The viewport in CSS px and the device pixel ratio (frames are viewport × scale). */
|
|
330
|
+
viewport?: {
|
|
331
|
+
w: number;
|
|
332
|
+
h: number;
|
|
333
|
+
scale: number;
|
|
334
|
+
};
|
|
335
|
+
/** Each page's title, by path. */
|
|
336
|
+
titles?: Record<string, string>;
|
|
337
|
+
events: TimelineEvent[];
|
|
338
|
+
/** When the guide started and when capture stopped (wall ms). */
|
|
339
|
+
playAt: number;
|
|
340
|
+
stopAt: number;
|
|
341
|
+
endAt: number | null;
|
|
342
|
+
/**
|
|
343
|
+
* Cards between scenes (a director clip's `d.card`): each shown for `ms` at source time `t`. A narrated card's
|
|
344
|
+
* step sits just after `t` (t + 1), so its line is spoken over the card, and the card lasts as long as its line.
|
|
345
|
+
*/
|
|
346
|
+
cards?: Array<{
|
|
347
|
+
t: number;
|
|
348
|
+
ms: number;
|
|
349
|
+
card: CardOptions;
|
|
350
|
+
step?: number;
|
|
351
|
+
}>;
|
|
352
|
+
}
|
|
353
|
+
declare class RenderError extends Error {
|
|
354
|
+
readonly screenshot?: Buffer | undefined;
|
|
355
|
+
/** A stall: which step, why, and what onStall found on the page. */
|
|
356
|
+
stall?: {
|
|
357
|
+
index: number;
|
|
358
|
+
reason: string;
|
|
359
|
+
data?: unknown;
|
|
360
|
+
};
|
|
361
|
+
constructor(message: string, screenshot?: Buffer | undefined);
|
|
362
|
+
}
|
|
363
|
+
declare function capture(o: CaptureOptions): Promise<Capture>;
|
|
364
|
+
/** Where the player build is: an explicit file, TRACE_AVATAR_PLAYER, or the installed trace-avatar. */
|
|
365
|
+
declare function findPlayer(explicit?: string, env?: NodeJS.ProcessEnv): Promise<string>;
|
|
366
|
+
|
|
345
367
|
/**
|
|
346
368
|
* Mono 16-bit PCM: read and write WAV, resample, trim silence, and lay lines on one track. PURE.
|
|
347
369
|
*/
|
|
@@ -578,6 +600,8 @@ interface OutSpec {
|
|
|
578
600
|
width?: number;
|
|
579
601
|
/** Default: GIF 12, MP4 30. */
|
|
580
602
|
fps?: number;
|
|
603
|
+
/** This output's own canvas (over the render's `canvas`): several shapes from one capture. */
|
|
604
|
+
canvas?: CanvasSpec;
|
|
581
605
|
}
|
|
582
606
|
interface RenderOptions {
|
|
583
607
|
/** A trace object, or the path of a .trace.json. */
|
|
@@ -931,4 +955,4 @@ declare function repairGuide(o: {
|
|
|
931
955
|
first?: RenderError;
|
|
932
956
|
}): Promise<RepairOutcome>;
|
|
933
957
|
|
|
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 };
|
|
958
|
+
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, cardFrames, 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, withCards, withHolds };
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
canvasOf,
|
|
19
19
|
captionCues,
|
|
20
20
|
capture,
|
|
21
|
+
cardFrames,
|
|
21
22
|
cardOf,
|
|
22
23
|
chapterCues,
|
|
23
24
|
createGifWriter,
|
|
@@ -73,8 +74,9 @@ import {
|
|
|
73
74
|
trimSilence,
|
|
74
75
|
voiceOf,
|
|
75
76
|
watermarkOf,
|
|
77
|
+
withCards,
|
|
76
78
|
withHolds
|
|
77
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-ZNHFXKD3.js";
|
|
78
80
|
export {
|
|
79
81
|
CANVASES,
|
|
80
82
|
CORNERS,
|
|
@@ -95,6 +97,7 @@ export {
|
|
|
95
97
|
canvasOf,
|
|
96
98
|
captionCues,
|
|
97
99
|
capture,
|
|
100
|
+
cardFrames,
|
|
98
101
|
cardOf,
|
|
99
102
|
chapterCues,
|
|
100
103
|
createGifWriter,
|
|
@@ -150,6 +153,7 @@ export {
|
|
|
150
153
|
trimSilence,
|
|
151
154
|
voiceOf,
|
|
152
155
|
watermarkOf,
|
|
156
|
+
withCards,
|
|
153
157
|
withHolds
|
|
154
158
|
};
|
|
155
159
|
//# sourceMappingURL=index.js.map
|