trace-avatar-render 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,324 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ RenderError,
4
+ providerOf,
5
+ render,
6
+ suggestScript,
7
+ voiceOf
8
+ } from "./chunk-BM26YQ4L.js";
9
+
10
+ // src/cli.ts
11
+ import { readFileSync, writeFileSync } from "fs";
12
+ import { apply as applySuggestions, suggest } from "trace-avatar/assist";
13
+ import { parseArgs } from "util";
14
+ var USAGE = `Usage: trace-avatar-render <trace.json> --url <page> --out <file.gif|file.mp4> [options]
15
+
16
+ --url <url> the page the guide starts on (required)
17
+ --out <file> .gif or .mp4; repeat for several (required)
18
+ --mode <overlay|perform> Show me (default) or Do it for me
19
+ --allow-perform needed for perform: it clicks and types for real (use a sandbox account)
20
+ --width <px> output width (GIF default 800, MP4 the capture's)
21
+ --fps <n> frames per second (GIF default 12, MP4 30)
22
+ --viewport <WxH> default: the trace's meta.viewport, else 1280x800
23
+ --scale <n> device pixel ratio of the capture (2 for crisp video)
24
+ --storage-state <file> a signed-in Playwright session
25
+ --max-wait <ms> waits longer than this are cut to it (default 800, 0 keeps them)
26
+ --hide <selector> hidden before capture; repeatable
27
+ --blur <selector> blurred before capture (as well as [data-trace-blur]); repeatable
28
+ --allow-stall render a stalled guide anyway instead of failing
29
+ --player <file> the trace-perform.min.js to use (default: the installed trace-avatar)
30
+ --timeline <file> write the timeline and the cuts as JSON
31
+ --timeout <ms> give up after this long (default 120000)
32
+ --headed show the browser
33
+
34
+ Polish (all off by default):
35
+ --frame <none|browser> a browser window around the app, on a background
36
+ --background <css> the background behind the window and on the cards
37
+ --camera zoom in on each action and pan between close ones
38
+ --zoom <n> how far the camera goes in (default 1.6; implies --camera)
39
+ --captions <burn|vtt|both> burn the steps' words in, write <out>.vtt + <out>.chapters.vtt, or both
40
+ --poster [file] a PNG at the first click (default <out>.png)
41
+ --title-card [title] a 1.5 s card first (default: the trace's title)
42
+ --end-card [title] a 2 s card last (default: "Done")
43
+
44
+ AI (nothing calls a model without --ai):
45
+ --ai <provider> gateway: our AI gateway (AI_GATEWAY_URL, AI_GATEWAY_KEY), DeepSeek first, then Gemini,
46
+ then OpenAI; or gateway:<provider>[/<model>][,<provider>\u2026]; openai:<model> (OPENAI_API_KEY,
47
+ OPENAI_BASE_URL for any OpenAI-compatible server); or ./provider.js
48
+ --ai-vision <model> the model for --qa's frames (gateway's DeepSeek default: deepseek-flash)
49
+ --qa [strict] send a frame per step to the AI to look for errors, empty states, a stall, personal
50
+ data; strict exits 1 when anything is flagged (needs a vision model)
51
+ --alt write <out>.alt.txt; with --captions vtt, AI names the chapters
52
+ --repair when a step can't find its element, propose a fix in <out>.repair.json (verified by
53
+ playing again); still exits 1. With --ai, unsure cases are asked (DeepSeek first)
54
+ --repair-vision with --repair and --ai: send a screenshot of the stalled page too
55
+
56
+ Narration (MP4 only; nothing speaks without --voice):
57
+ --voice <voice> gateway (our AI gateway: Gemini speech, AI_GATEWAY_URL/KEY), gateway:gemini/<model>:<voice>,
58
+ openai:<model>[:<voice>] (OPENAI_API_KEY / OPENAI_BASE_URL), say[:<voice>] (macOS, offline),
59
+ or ./voice.js. Each step's caption is spoken; the video holds where a line runs long
60
+ --script <file.json> the spoken lines instead: { "lines": [{ "n": 1, "text": "\u2026" }] }
61
+ --voice-out <file.wav> also write the narration track
62
+ --voice-strict fail when a line needs a hold longer than 8 s
63
+ --no-voice-cache don't keep spoken lines in .trace-avatar-cache/voice
64
+
65
+ Suggestions for a person to accept (the renderer never changes a trace):
66
+ trace-avatar-render suggest <trace.json> --task captions|title|waits|narration --ai <provider> [--tone friendly|terse|formal]
67
+ [--hints hints.json] [--out suggestions.json]
68
+ trace-avatar-render apply <trace.json> <suggestions.json> --accept 1,3|all --out <new.trace.json>
69
+ `;
70
+ function parse(argv) {
71
+ const extra = {};
72
+ const flags = { "--poster": "poster", "--title-card": "title", "--end-card": "end", "--qa": "qa" };
73
+ const rest = [];
74
+ for (let k = 0; k < argv.length; k += 1) {
75
+ const a = argv[k];
76
+ const eq = a.indexOf("=");
77
+ const name = eq > 0 ? a.slice(0, eq) : a;
78
+ if (flags[name]) {
79
+ if (eq > 0) extra[flags[name]] = a.slice(eq + 1);
80
+ else if (argv[k + 1] !== void 0 && !argv[k + 1].startsWith("-") && !/\.json$/i.test(argv[k + 1]) && (flags[name] !== "qa" || argv[k + 1] === "strict")) {
81
+ extra[flags[name]] = argv[k + 1];
82
+ k += 1;
83
+ } else extra[flags[name]] = true;
84
+ continue;
85
+ }
86
+ rest.push(a);
87
+ }
88
+ const { values, positionals } = parseArgs({
89
+ args: rest,
90
+ allowPositionals: true,
91
+ options: {
92
+ url: { type: "string" },
93
+ out: { type: "string", multiple: true },
94
+ mode: { type: "string" },
95
+ "allow-perform": { type: "boolean" },
96
+ width: { type: "string" },
97
+ fps: { type: "string" },
98
+ viewport: { type: "string" },
99
+ scale: { type: "string" },
100
+ "storage-state": { type: "string" },
101
+ "max-wait": { type: "string" },
102
+ hide: { type: "string", multiple: true },
103
+ blur: { type: "string", multiple: true },
104
+ "allow-stall": { type: "boolean" },
105
+ player: { type: "string" },
106
+ timeline: { type: "string" },
107
+ timeout: { type: "string" },
108
+ headed: { type: "boolean" },
109
+ help: { type: "boolean", short: "h" },
110
+ frame: { type: "string" },
111
+ background: { type: "string" },
112
+ camera: { type: "boolean" },
113
+ zoom: { type: "string" },
114
+ captions: { type: "string" },
115
+ ai: { type: "string" },
116
+ "ai-vision": { type: "string" },
117
+ alt: { type: "boolean" },
118
+ voice: { type: "string" },
119
+ script: { type: "string" },
120
+ "voice-out": { type: "string" },
121
+ "voice-strict": { type: "boolean" },
122
+ "no-voice-cache": { type: "boolean" },
123
+ repair: { type: "boolean" },
124
+ "repair-vision": { type: "boolean" }
125
+ }
126
+ });
127
+ if (values.help) throw new UsageError("");
128
+ const trace = positionals[0];
129
+ if (!trace) throw new UsageError("a trace file is needed");
130
+ if (positionals.length > 1) throw new UsageError(`one trace at a time (got ${positionals.join(", ")})`);
131
+ if (!values.url) throw new UsageError("--url is needed");
132
+ if (!values.out?.length) throw new UsageError("--out is needed");
133
+ const num = (name, v, min = 0) => {
134
+ if (v === void 0) return void 0;
135
+ const n = Number(v);
136
+ if (!Number.isFinite(n) || n < min) throw new UsageError(`--${name} must be a number \u2265 ${min}`);
137
+ return n;
138
+ };
139
+ const mode = values.mode ?? "overlay";
140
+ if (mode !== "overlay" && mode !== "perform") throw new UsageError("--mode is overlay or perform");
141
+ let viewport;
142
+ if (values.viewport) {
143
+ const m = /^(\d+)x(\d+)$/i.exec(values.viewport);
144
+ if (!m) throw new UsageError("--viewport is WIDTHxHEIGHT, e.g. 1280x800");
145
+ viewport = { w: Number(m[1]), h: Number(m[2]) };
146
+ }
147
+ if (values.frame && values.frame !== "none" && values.frame !== "browser") throw new UsageError("--frame is none or browser");
148
+ const captions = values.captions;
149
+ if (captions !== void 0 && captions !== "burn" && captions !== "vtt" && captions !== "both") throw new UsageError("--captions is burn, vtt or both");
150
+ const zoom = num("zoom", values.zoom, 1);
151
+ if (extra.qa !== void 0 && extra.qa !== true && extra.qa !== "strict") throw new UsageError("--qa takes nothing or strict");
152
+ if ((extra.qa !== void 0 || values.alt || values["ai-vision"]) && !values.ai) throw new UsageError("--qa, --alt and --ai-vision need --ai");
153
+ if (values["repair-vision"] && !(values.repair && values.ai)) throw new UsageError("--repair-vision needs --repair and --ai");
154
+ 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");
155
+ if (values.voice && !values.out.some((f) => /\.mp4$/i.test(f))) throw new UsageError("--voice needs an .mp4 output (a GIF has no sound)");
156
+ const width = num("width", values.width, 16);
157
+ const fps = num("fps", values.fps, 1);
158
+ const maxWait = num("max-wait", values["max-wait"]);
159
+ return {
160
+ trace,
161
+ options: {
162
+ trace,
163
+ url: values.url,
164
+ mode,
165
+ allowPerform: !!values["allow-perform"],
166
+ out: values.out.map((file) => ({ file, ...width ? { width } : {}, ...fps ? { fps } : {} })),
167
+ ...viewport ? { viewport } : {},
168
+ ...values.scale ? { scale: num("scale", values.scale, 1) } : {},
169
+ ...values["storage-state"] ? { storageState: values["storage-state"] } : {},
170
+ ...maxWait !== void 0 ? { cuts: { maxWaitMs: maxWait } } : {},
171
+ ...values.hide ? { hide: values.hide } : {},
172
+ ...values.blur ? { blur: values.blur } : {},
173
+ allowStall: !!values["allow-stall"],
174
+ ...values.player ? { player: values.player } : {},
175
+ ...values.timeline ? { timeline: values.timeline } : {},
176
+ ...values.timeout ? { timeoutMs: num("timeout", values.timeout, 1) } : {},
177
+ headless: !values.headed,
178
+ ...values.frame ? { frame: values.frame } : {},
179
+ ...values.background ? { background: values.background } : {},
180
+ ...zoom ? { camera: { zoom } } : values.camera ? { camera: true } : {},
181
+ ...captions ? { captions } : {},
182
+ ...extra.poster !== void 0 ? { poster: extra.poster } : {},
183
+ ...extra.title !== void 0 ? { titleCard: extra.title } : {},
184
+ ...extra.end !== void 0 ? { endCard: extra.end } : {},
185
+ ...extra.qa !== void 0 ? { qa: true } : {},
186
+ ...values.alt ? { alt: true } : {},
187
+ ...values.script ? { script: values.script } : {},
188
+ ...values["voice-out"] ? { voiceOut: values["voice-out"] } : {},
189
+ ...values["voice-strict"] ? { voiceStrict: true } : {},
190
+ ...values.repair ? { repair: true } : {},
191
+ ...values["repair-vision"] ? { repairVision: true } : {}
192
+ },
193
+ ...values.ai ? { ai: values.ai } : {},
194
+ ...values["ai-vision"] ? { aiVision: values["ai-vision"] } : {},
195
+ ...values.voice ? { voice: values.voice } : {},
196
+ ...values["no-voice-cache"] ? { noVoiceCache: true } : {},
197
+ ...extra.qa === "strict" ? { strict: true } : {}
198
+ };
199
+ }
200
+ var UsageError = class extends Error {
201
+ };
202
+ async function main(argv, io = { log: console.log, error: console.error }) {
203
+ if (argv[0] === "suggest" || argv[0] === "apply") {
204
+ try {
205
+ return await (argv[0] === "suggest" ? suggestCmd(argv.slice(1), io) : applyCmd(argv.slice(1), io));
206
+ } catch (e) {
207
+ io.error(`trace-avatar-render ${argv[0]}: ${e.message}`);
208
+ if (e instanceof UsageError) io.error(USAGE);
209
+ return e instanceof UsageError ? 2 : 1;
210
+ }
211
+ }
212
+ let p;
213
+ try {
214
+ p = parse(argv);
215
+ } catch (e) {
216
+ const msg = e.message;
217
+ if (msg) io.error(`trace-avatar-render: ${msg}
218
+ `);
219
+ io.error(USAGE);
220
+ return e instanceof UsageError && !msg ? 0 : 2;
221
+ }
222
+ try {
223
+ if (p.ai) p.options.ai = await providerOf(p.ai, process.env, p.aiVision ? { vision: p.aiVision } : {});
224
+ if (p.voice) p.options.voice = await voiceOf(p.voice, process.env, p.noVoiceCache ? { cacheDir: null } : {});
225
+ const r = await render(p.options);
226
+ for (const o of r.outputs) io.log(`${o.file} ${o.width}\xD7${o.height} ${o.fps} fps ${(r.durationMs / 1e3).toFixed(1)} s ${(o.bytes / 1024).toFixed(0)} KB`);
227
+ if (r.rawMs > r.durationMs + 50) io.log(`cut ${((r.rawMs - r.durationMs) / 1e3).toFixed(1)} s of waiting`);
228
+ for (const f of [r.poster, r.vtt, r.chapters, r.alt]) if (f) io.log(f);
229
+ if (r.narration) {
230
+ io.log(`narration: ${r.narration.lines.length} line${r.narration.lines.length === 1 ? "" : "s"}${r.narration.holdMs ? `, the video holds ${(r.narration.holdMs / 1e3).toFixed(1)} s for them` : ""} ${r.narration.text}`);
231
+ if (r.narration.wav) io.log(r.narration.wav);
232
+ }
233
+ for (const w of r.warnings ?? []) io.error(`warning: ${w}`);
234
+ if (r.qa) {
235
+ if (!r.qa.length) io.log("qa: nothing flagged");
236
+ for (const f of r.qa) io.log(`qa: ${(f.at / 1e3).toFixed(1)} s ${f.kind} ${f.note}`);
237
+ if (p.strict && r.qa.length) {
238
+ io.error(`trace-avatar-render: qa flagged ${r.qa.length} problem${r.qa.length > 1 ? "s" : ""} (--qa strict)`);
239
+ return 1;
240
+ }
241
+ }
242
+ return 0;
243
+ } catch (e) {
244
+ io.error(`trace-avatar-render: ${e.message}`);
245
+ if (e instanceof RenderError && e.screenshot) {
246
+ const first = p.options.out[0];
247
+ const shot = `${(typeof first === "string" ? first : first.file).replace(/\.[^./]+$/, "")}.failure.png`;
248
+ writeFileSync(shot, e.screenshot);
249
+ io.error(`the page at that moment: ${shot}`);
250
+ }
251
+ return 1;
252
+ }
253
+ }
254
+ var readJson = (file) => {
255
+ try {
256
+ return JSON.parse(readFileSync(file, "utf8"));
257
+ } catch (e) {
258
+ throw new Error(`could not read ${file}: ${e.message}`);
259
+ }
260
+ };
261
+ async function suggestCmd(argv, io) {
262
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: {
263
+ task: { type: "string" },
264
+ ai: { type: "string" },
265
+ tone: { type: "string" },
266
+ hints: { type: "string" },
267
+ out: { type: "string" },
268
+ "send-typed": { type: "boolean" }
269
+ } });
270
+ const [file] = positionals;
271
+ if (!file) throw new UsageError("suggest needs a trace file");
272
+ const task = values.task;
273
+ if (task !== "captions" && task !== "title" && task !== "waits" && task !== "narration") throw new UsageError("--task is captions, title, waits or narration");
274
+ if (!values.ai) throw new UsageError("suggest needs --ai");
275
+ if (task === "narration") {
276
+ const r2 = await suggestScript(await providerOf(values.ai), readJson(file));
277
+ const out2 = JSON.stringify({ ...r2.script, ...r2.dropped.length ? { dropped: r2.dropped } : {} }, null, 2);
278
+ if (values.out) {
279
+ writeFileSync(values.out, `${out2}
280
+ `);
281
+ io.log(`${r2.script.lines.length} line${r2.script.lines.length === 1 ? "" : "s"} in ${values.out}: edit them, then --script ${values.out}`);
282
+ } else io.log(out2);
283
+ return 0;
284
+ }
285
+ const tone = values.tone;
286
+ if (tone !== void 0 && tone !== "friendly" && tone !== "terse" && tone !== "formal") throw new UsageError("--tone is friendly, terse or formal");
287
+ const trace = readJson(file);
288
+ const hints = values.hints ? readJson(values.hints) : void 0;
289
+ const r = await suggest(task, trace, { ai: await providerOf(values.ai), ...hints ? { hints } : {}, ...tone ? { tone } : {}, ...values["send-typed"] ? { sendTyped: true } : {} });
290
+ const out = JSON.stringify({ task, suggestions: r.suggestions.map((sg, k) => ({ id: k + 1, ...sg })), dropped: r.dropped }, null, 2);
291
+ if (values.out) {
292
+ writeFileSync(values.out, `${out}
293
+ `);
294
+ io.log(`${r.suggestions.length} suggestion${r.suggestions.length === 1 ? "" : "s"} in ${values.out}`);
295
+ } else io.log(out);
296
+ return 0;
297
+ }
298
+ async function applyCmd(argv, io) {
299
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { accept: { type: "string" }, out: { type: "string" } } });
300
+ const [file, sugFile] = positionals;
301
+ if (!file || !sugFile) throw new UsageError("apply needs a trace file and a suggestions file");
302
+ if (!values.accept) throw new UsageError("apply needs --accept 1,3 (or all): a person picks what goes in");
303
+ if (!values.out) throw new UsageError("apply needs --out for the new trace");
304
+ const all = readJson(sugFile).suggestions ?? [];
305
+ const ids = values.accept === "all" ? all.map((x) => x.id) : values.accept.split(",").map((x) => Number(x.trim()));
306
+ const missing = ids.filter((id) => !all.some((x) => x.id === id));
307
+ if (missing.length) throw new UsageError(`no suggestion ${missing.join(", ")} in ${sugFile}`);
308
+ const next = applySuggestions(readJson(file), all.filter((x) => ids.includes(x.id)));
309
+ writeFileSync(values.out, `${JSON.stringify(next, null, 2)}
310
+ `);
311
+ io.log(`applied ${ids.length} of ${all.length} to ${values.out}`);
312
+ return 0;
313
+ }
314
+ var isMain = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("/trace-avatar-render") || process.argv[1]?.endsWith("/cli.js");
315
+ if (isMain) void main(process.argv.slice(2)).then((code) => {
316
+ process.exitCode = code;
317
+ });
318
+ export {
319
+ USAGE,
320
+ UsageError,
321
+ main,
322
+ parse
323
+ };
324
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +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 { 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 --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 --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, propose a fix in <out>.repair.json (verified by\n playing again); still exits 1. With --ai, unsure cases are asked (DeepSeek first)\n --repair-vision with --repair and --ai: send a screenshot of the stalled page too\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 { 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' }, 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' },\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 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.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 };\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 (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 (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,cAAc,qBAAqB;AAC5C,SAAS,SAAS,kBAAkB,eAAe;AAKnD,SAAS,iBAAiB;AAInB,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;AAA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