@vosjs/cli 0.60.0 → 0.61.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/README.md +2 -2
- package/dist/{assetManifest-MM5WGOWG.js → assetManifest-NS64PLY5.js} +3 -3
- package/dist/{chunk-NE5MHC3D.js → chunk-C4P6MZJG.js} +64 -100
- package/dist/chunk-C4P6MZJG.js.map +1 -0
- package/dist/{chunk-PUXY32AP.js → chunk-EZW6ZCEH.js} +86 -77
- package/dist/chunk-EZW6ZCEH.js.map +1 -0
- package/dist/{chunk-OMDRILG7.js → chunk-LWHVZ5WI.js} +12 -6
- package/dist/chunk-LWHVZ5WI.js.map +1 -0
- package/dist/{chunk-36P5RREC.js → chunk-WCF6KIOK.js} +240 -118
- package/dist/chunk-WCF6KIOK.js.map +1 -0
- package/dist/cli.js +17 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/{run-5DLEKBK2.js → run-IZ72SDZC.js} +5 -5
- package/package.json +6 -6
- package/skills/VERSION +1 -1
- package/skills/vos-authoring/references/schema-reference.md +40 -2
- package/skills/vos-port/SKILL.md +3 -1
- package/skills/vos-port/references/elements-and-context.md +5 -0
- package/skills/vos-port/references/hyperframes.md +1 -1
- package/skills/vos-port/references/remotion.md +1 -1
- package/dist/chunk-36P5RREC.js.map +0 -1
- package/dist/chunk-NE5MHC3D.js.map +0 -1
- package/dist/chunk-OMDRILG7.js.map +0 -1
- package/dist/chunk-PUXY32AP.js.map +0 -1
- /package/dist/{assetManifest-MM5WGOWG.js.map → assetManifest-NS64PLY5.js.map} +0 -0
- /package/dist/{run-5DLEKBK2.js.map → run-IZ72SDZC.js.map} +0 -0
|
@@ -5,14 +5,21 @@ import {
|
|
|
5
5
|
apiJson,
|
|
6
6
|
extensionFor,
|
|
7
7
|
hostedAssetId,
|
|
8
|
+
localFile,
|
|
8
9
|
manifestRefs,
|
|
9
10
|
nameForType,
|
|
10
11
|
resolveMediaType
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WCF6KIOK.js";
|
|
12
13
|
|
|
13
14
|
// src/plugin/assetManifest.ts
|
|
14
|
-
import {
|
|
15
|
-
|
|
15
|
+
import {
|
|
16
|
+
existsSync as existsSync3,
|
|
17
|
+
readFileSync,
|
|
18
|
+
realpathSync,
|
|
19
|
+
rmSync,
|
|
20
|
+
writeFileSync
|
|
21
|
+
} from "fs";
|
|
22
|
+
import { join as join3, relative } from "path";
|
|
16
23
|
|
|
17
24
|
// src/plugin/media.ts
|
|
18
25
|
import { isKeyedOverlay } from "@vosjs/studio-core";
|
|
@@ -131,7 +138,6 @@ async function loadTake(dir) {
|
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
// src/plugin/uploadAsset.ts
|
|
134
|
-
var SINGLE_SHOT_MAX_BYTES = 32 * 1024 * 1024;
|
|
135
141
|
var PART_ATTEMPTS = 3;
|
|
136
142
|
function planParts(totalBytes, partBytes) {
|
|
137
143
|
if (totalBytes <= 0 || partBytes <= 0) return [];
|
|
@@ -147,14 +153,20 @@ function planParts(totalBytes, partBytes) {
|
|
|
147
153
|
}
|
|
148
154
|
function failed(what, r) {
|
|
149
155
|
const detail = typeof r.body.error === "string" ? r.body.error : "";
|
|
150
|
-
|
|
156
|
+
const hint = typeof r.body.hint === "string" ? ` ${r.body.hint}` : "";
|
|
157
|
+
return new Error(`${what} (${r.status})${detail ? `: ${detail}${hint}` : ""}`);
|
|
151
158
|
}
|
|
152
|
-
function asAsset(body) {
|
|
159
|
+
function asAsset(body, reused) {
|
|
160
|
+
const asset = body.asset ?? {};
|
|
153
161
|
return {
|
|
154
|
-
id: String(
|
|
155
|
-
url: String(
|
|
156
|
-
size: typeof
|
|
157
|
-
reused
|
|
162
|
+
id: String(asset.id),
|
|
163
|
+
url: String(asset.fileUrl),
|
|
164
|
+
size: typeof asset.size === "number" ? asset.size : 0,
|
|
165
|
+
reused,
|
|
166
|
+
kind: typeof asset.kind === "string" ? asset.kind : "",
|
|
167
|
+
filename: typeof asset.filename === "string" ? asset.filename : "",
|
|
168
|
+
metadata: asset.metadata && typeof asset.metadata === "object" ? asset.metadata : null,
|
|
169
|
+
notes: Array.isArray(body.notes) ? body.notes.filter((n) => typeof n === "string") : []
|
|
158
170
|
};
|
|
159
171
|
}
|
|
160
172
|
function transient(status) {
|
|
@@ -162,54 +174,24 @@ function transient(status) {
|
|
|
162
174
|
}
|
|
163
175
|
var wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
164
176
|
async function uploadAsset(target, bytes, opts) {
|
|
165
|
-
|
|
166
|
-
throw new Error(
|
|
167
|
-
`${opts.filename} is over ${SINGLE_SHOT_MAX_BYTES / 1024 / 1024} MB, and a file that large cannot be filed into a project on upload yet. Push it without --folder and reference it from a document, which keeps it`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
return bytes.length > SINGLE_SHOT_MAX_BYTES ? uploadInParts(target, bytes, opts) : uploadWhole(target, bytes, opts);
|
|
171
|
-
}
|
|
172
|
-
async function uploadWhole(target, bytes, opts) {
|
|
173
|
-
const res = await apiJson(target.origin, "/api/assets/recording", {
|
|
177
|
+
const begun = await apiJson(target.origin, "/api/assets/uploads", {
|
|
174
178
|
method: "POST",
|
|
175
179
|
key: target.key,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
...opts.durationSeconds && opts.durationSeconds > 0 ? {
|
|
182
|
-
...opts.folderId ? {
|
|
183
|
-
|
|
184
|
-
raw: bytes
|
|
185
|
-
});
|
|
186
|
-
if (res.status !== 201 && res.status !== 200)
|
|
187
|
-
throw failed("upload failed", res);
|
|
188
|
-
return asAsset(res.body);
|
|
189
|
-
}
|
|
190
|
-
async function uploadInParts(target, bytes, opts) {
|
|
191
|
-
const begun = await apiJson(
|
|
192
|
-
target.origin,
|
|
193
|
-
"/api/assets/recording/multipart",
|
|
194
|
-
{
|
|
195
|
-
method: "POST",
|
|
196
|
-
key: target.key,
|
|
197
|
-
body: {
|
|
198
|
-
filename: opts.filename,
|
|
199
|
-
contentType: opts.contentType,
|
|
200
|
-
size: bytes.length,
|
|
201
|
-
contentHash: opts.contentHash,
|
|
202
|
-
...opts.durationSeconds && opts.durationSeconds > 0 ? { durationSeconds: opts.durationSeconds } : {}
|
|
203
|
-
}
|
|
180
|
+
body: {
|
|
181
|
+
filename: opts.filename,
|
|
182
|
+
...opts.contentType ? { contentType: opts.contentType } : {},
|
|
183
|
+
size: bytes.length,
|
|
184
|
+
sha256: opts.contentHash,
|
|
185
|
+
...opts.durationSeconds && opts.durationSeconds > 0 ? { durationSeconds: opts.durationSeconds } : {},
|
|
186
|
+
...opts.folderId ? { folderId: opts.folderId } : {},
|
|
187
|
+
...opts.intent ? { intent: opts.intent } : {}
|
|
204
188
|
}
|
|
205
|
-
);
|
|
189
|
+
});
|
|
206
190
|
if (begun.status !== 201 && begun.status !== 200) {
|
|
207
191
|
throw failed("upload failed", begun);
|
|
208
192
|
}
|
|
209
|
-
if (begun.body.
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
const uploadId = String(begun.body.id);
|
|
193
|
+
if (begun.body.asset) return asAsset(begun.body, true);
|
|
194
|
+
const uploadId = String(begun.body.uploadId);
|
|
213
195
|
const partBytes = Number(begun.body.partBytes);
|
|
214
196
|
if (!Number.isFinite(partBytes) || partBytes <= 0) {
|
|
215
197
|
throw new Error("upload failed: the platform returned no part size");
|
|
@@ -224,7 +206,7 @@ async function uploadInParts(target, bytes, opts) {
|
|
|
224
206
|
try {
|
|
225
207
|
sent = await apiJson(
|
|
226
208
|
target.origin,
|
|
227
|
-
`/api/assets/
|
|
209
|
+
`/api/assets/uploads/${uploadId}/parts/${part.partNumber}`,
|
|
228
210
|
{
|
|
229
211
|
method: "PUT",
|
|
230
212
|
key: target.key,
|
|
@@ -257,19 +239,18 @@ async function uploadInParts(target, bytes, opts) {
|
|
|
257
239
|
}
|
|
258
240
|
const sealed = await apiJson(
|
|
259
241
|
target.origin,
|
|
260
|
-
`/api/assets/
|
|
242
|
+
`/api/assets/uploads/${uploadId}/complete`,
|
|
261
243
|
{ method: "POST", key: target.key, body: { parts: etags } }
|
|
262
244
|
);
|
|
263
245
|
if (sealed.status !== 201 && sealed.status !== 200) {
|
|
264
246
|
throw failed("upload failed", sealed);
|
|
265
247
|
}
|
|
266
|
-
return asAsset(sealed.body);
|
|
248
|
+
return asAsset(sealed.body, false);
|
|
267
249
|
} catch (err) {
|
|
268
|
-
await apiJson(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
).catch(() => void 0);
|
|
250
|
+
await apiJson(target.origin, `/api/assets/uploads/${uploadId}`, {
|
|
251
|
+
method: "DELETE",
|
|
252
|
+
key: target.key
|
|
253
|
+
}).catch(() => void 0);
|
|
273
254
|
throw err;
|
|
274
255
|
}
|
|
275
256
|
}
|
|
@@ -438,6 +419,7 @@ async function uploadDocRefs(refs, dir, target, log) {
|
|
|
438
419
|
log(
|
|
439
420
|
` ${ref.where}: ${ref.key} \u2192 asset ${put.id}${put.reused ? " (reused)" : ""}`
|
|
440
421
|
);
|
|
422
|
+
for (const note of put.notes) log(` ${ref.where}: ${note}`);
|
|
441
423
|
}
|
|
442
424
|
}
|
|
443
425
|
function assetIdOf(url) {
|
|
@@ -545,6 +527,12 @@ async function pullMedia(ctx, dir, doc, log) {
|
|
|
545
527
|
|
|
546
528
|
// src/plugin/assetManifest.ts
|
|
547
529
|
var isUrl = (ref) => /^(https?:|data:|blob:)/.test(ref);
|
|
530
|
+
var homeOrigins = (origin) => [
|
|
531
|
+
origin,
|
|
532
|
+
"https://vos.so",
|
|
533
|
+
"https://www.vos.so"
|
|
534
|
+
];
|
|
535
|
+
var HOME_INDEX = ".hosted.json";
|
|
548
536
|
function cloneManifest(config) {
|
|
549
537
|
return JSON.parse(JSON.stringify(config.assets ?? {}));
|
|
550
538
|
}
|
|
@@ -560,19 +548,22 @@ async function uploadManifest(config, dir, target, log) {
|
|
|
560
548
|
const manifest = cloneManifest(config);
|
|
561
549
|
const local = [];
|
|
562
550
|
for (const { name, index, ref } of refs) {
|
|
563
|
-
const hosted = hostedAssetId(ref);
|
|
551
|
+
const hosted = hostedAssetId(ref, homeOrigins(target.origin));
|
|
564
552
|
if (hosted) {
|
|
565
553
|
setRef(manifest, name, index, `asset:${hosted}`);
|
|
566
554
|
continue;
|
|
567
555
|
}
|
|
568
556
|
if (isUrl(ref)) continue;
|
|
569
|
-
const
|
|
557
|
+
const found = localFile(ref, dir);
|
|
558
|
+
if ("refused" in found) {
|
|
559
|
+
throw new Error(`${where(name, index)} names ${ref}, ${found.refused}`);
|
|
560
|
+
}
|
|
570
561
|
local.push({
|
|
571
562
|
where: where(name, index),
|
|
572
563
|
// The upload helper reads keys against the directory.
|
|
573
|
-
key: relative(dir, file),
|
|
564
|
+
key: relative(realpathSync(dir), found.file),
|
|
574
565
|
set: (url) => {
|
|
575
|
-
const id = hostedAssetId(url);
|
|
566
|
+
const id = hostedAssetId(url, homeOrigins(target.origin));
|
|
576
567
|
setRef(manifest, name, index, id ? `asset:${id}` : url);
|
|
577
568
|
}
|
|
578
569
|
});
|
|
@@ -582,39 +573,57 @@ async function uploadManifest(config, dir, target, log) {
|
|
|
582
573
|
return { uploaded: local.length };
|
|
583
574
|
}
|
|
584
575
|
function localManifestRefs(config) {
|
|
585
|
-
return manifestRefs(config).filter(({ ref }) => !isUrl(ref) && !hostedAssetId(ref)).map(({ name, index }) => where(name, index));
|
|
576
|
+
return manifestRefs(config).filter(({ ref }) => !isUrl(ref) && !hostedAssetId(ref, homeOrigins(""))).map(({ name, index }) => where(name, index));
|
|
586
577
|
}
|
|
587
578
|
async function pullManifest(ctx, dir, config, log) {
|
|
588
|
-
const
|
|
579
|
+
const home = homeOrigins(ctx.origin);
|
|
580
|
+
const hosted = manifestRefs(config).filter(
|
|
581
|
+
({ ref }) => hostedAssetId(ref, home)
|
|
582
|
+
);
|
|
589
583
|
if (hosted.length === 0) return null;
|
|
590
584
|
const manifest = cloneManifest(config);
|
|
585
|
+
const indexPath = join3(dir, "assets", HOME_INDEX);
|
|
586
|
+
let index = {};
|
|
587
|
+
try {
|
|
588
|
+
const parsed = JSON.parse(readFileSync(indexPath, "utf8"));
|
|
589
|
+
if (parsed && typeof parsed === "object") {
|
|
590
|
+
index = parsed;
|
|
591
|
+
}
|
|
592
|
+
} catch {
|
|
593
|
+
}
|
|
591
594
|
const files = [];
|
|
592
|
-
for (const { name, index, ref } of hosted) {
|
|
593
|
-
const id = hostedAssetId(ref);
|
|
594
|
-
const stem =
|
|
595
|
-
const
|
|
595
|
+
for (const { name, index: at, ref } of hosted) {
|
|
596
|
+
const id = hostedAssetId(ref, home);
|
|
597
|
+
const stem = at === null ? name : `${name}-${at}`;
|
|
598
|
+
const known = Object.keys(index).find(
|
|
596
599
|
(f) => f === stem || f.startsWith(`${stem}.`)
|
|
597
|
-
)
|
|
600
|
+
);
|
|
598
601
|
let file;
|
|
599
|
-
if (
|
|
600
|
-
file = `assets/${
|
|
602
|
+
if (known && index[known] === id && existsSync3(join3(dir, "assets", known))) {
|
|
603
|
+
file = `assets/${known}`;
|
|
601
604
|
} else {
|
|
605
|
+
if (known) {
|
|
606
|
+
rmSync(join3(dir, "assets", known), { force: true });
|
|
607
|
+
delete index[known];
|
|
608
|
+
}
|
|
602
609
|
const got = await downloadMedia(ctx, `/api/assets/${id}/file`, {
|
|
603
610
|
dir,
|
|
604
611
|
subdir: "assets",
|
|
605
612
|
stem,
|
|
606
613
|
fallbackExt: "",
|
|
607
|
-
describe: `${where(name,
|
|
614
|
+
describe: `${where(name, at)} (asset ${id})`,
|
|
608
615
|
notFoundHint: "a private file needs a content key of its owner"
|
|
609
616
|
});
|
|
610
617
|
file = got.file;
|
|
618
|
+
index[file.slice("assets/".length)] = id;
|
|
611
619
|
log(
|
|
612
|
-
` ${file} \u2190 ${where(name,
|
|
620
|
+
` ${file} \u2190 ${where(name, at)}, asset ${id} (${Math.round(got.bytes / 1024)} kB)`
|
|
613
621
|
);
|
|
614
622
|
}
|
|
615
623
|
files.push(file);
|
|
616
|
-
setRef(manifest, name,
|
|
624
|
+
setRef(manifest, name, at, `./${file}`);
|
|
617
625
|
}
|
|
626
|
+
writeFileSync(indexPath, JSON.stringify(index, null, 2) + "\n");
|
|
618
627
|
return { assets: manifest, files };
|
|
619
628
|
}
|
|
620
629
|
var HOSTED_FILE_LITERAL = /(?:asset:|\/api\/assets\/)([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})/g;
|
|
@@ -667,4 +676,4 @@ export {
|
|
|
667
676
|
pullManifest,
|
|
668
677
|
hostedLiteralWarnings
|
|
669
678
|
};
|
|
670
|
-
//# sourceMappingURL=chunk-
|
|
679
|
+
//# sourceMappingURL=chunk-EZW6ZCEH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin/assetManifest.ts","../src/plugin/media.ts","../src/plugin/take.ts","../src/plugin/uploadAsset.ts"],"sourcesContent":["/**\n * A program's declared files (`config.assets`) crossing to and from vos.so.\n *\n * On disk a manifest names files beside the config (`./logo.png`), so a\n * program renders offline and reads like the repository it lives in. On the\n * platform a manifest names hosted assets (`asset:<id>`), the one spelling\n * the platform resolves for every surface: a private file reaches a render\n * page, a remix brings its files along, and a file a program still plays is\n * never collected. A push is the crossing one way, `vos fetch --media` the\n * other; neither rewrites the other side's spelling in place.\n */\nimport {\n existsSync,\n readFileSync,\n realpathSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport { join, relative } from 'node:path'\nimport { hostedAssetId, localFile, manifestRefs } from '../programAssets'\nimport { downloadMedia, uploadDocRefs } from './media'\nimport type { DocMediaRef } from './media'\nimport type { UploadTarget } from './uploadAsset'\n\ntype Manifest = Record<string, { ref: string | string[] }>\n\nconst isUrl = (ref: string) => /^(https?:|data:|blob:)/.test(ref)\n\n/** The origins whose `/api/assets/<id>/file` is a hosted file of ours. */\nconst homeOrigins = (origin: string) => [\n origin,\n 'https://vos.so',\n 'https://www.vos.so',\n]\n\n/** `assets/.hosted.json`: which hosted file each file brought home is. */\nconst HOME_INDEX = '.hosted.json'\n\n/** A deep copy of the manifest, so a caller's rewrite never reaches disk. */\nfunction cloneManifest(config: Record<string, unknown>): Manifest {\n return JSON.parse(JSON.stringify(config.assets ?? {})) as Manifest\n}\n\nfunction setRef(\n manifest: Manifest,\n name: string,\n index: number | null,\n next: string,\n): void {\n const decl = manifest[name]\n if (index === null) decl.ref = next\n else (decl.ref as string[])[index] = next\n}\n\nconst where = (name: string, index: number | null) =>\n index === null ? `assets.${name}` : `assets.${name}[${index}]`\n\n/**\n * Upload the manifest's local files and point every entry at its hosted\n * asset as `asset:<id>`; a hosted file spelled as a URL takes the same\n * spelling. `config.assets` is REPLACED on the object (the file on disk is\n * untouched), so everything composed from it afterwards carries the hosted\n * refs. Uploads are content-addressed: a re-push sends nothing.\n */\nexport async function uploadManifest(\n config: Record<string, unknown>,\n dir: string,\n target: UploadTarget,\n log: (line: string) => void,\n): Promise<{ uploaded: number }> {\n const refs = manifestRefs(config)\n if (refs.length === 0) return { uploaded: 0 }\n const manifest = cloneManifest(config)\n const local: DocMediaRef[] = []\n for (const { name, index, ref } of refs) {\n const hosted = hostedAssetId(ref, homeOrigins(target.origin))\n if (hosted) {\n setRef(manifest, name, index, `asset:${hosted}`)\n continue\n }\n if (isUrl(ref)) continue\n // A push uploads what the manifest names, so it holds the same line a\n // render does: only a file inside the program's own directory.\n const found = localFile(ref, dir)\n if ('refused' in found) {\n throw new Error(`${where(name, index)} names ${ref}, ${found.refused}`)\n }\n local.push({\n where: where(name, index),\n // The upload helper reads keys against the directory.\n key: relative(realpathSync(dir), found.file),\n set: (url) => {\n const id = hostedAssetId(url, homeOrigins(target.origin))\n setRef(manifest, name, index, id ? `asset:${id}` : url)\n },\n })\n }\n await uploadDocRefs(local, dir, target, log)\n config.assets = manifest\n return { uploaded: local.length }\n}\n\n/** The manifest entries that are still files on this machine. */\nexport function localManifestRefs(config: Record<string, unknown>): string[] {\n return manifestRefs(config)\n .filter(({ ref }) => !isUrl(ref) && !hostedAssetId(ref, homeOrigins('')))\n .map(({ name, index }) => where(name, index))\n}\n\n/**\n * Bring a fetched program's hosted files home: each `asset:<id>` lands as\n * `assets/<name>.<ext>` beside the config (the bytes choose the extension)\n * and its entry is re-pointed at that file.\n *\n * A file already there is kept only when it IS that hosted file\n * (`assets/.hosted.json` remembers which id each one came from). Kept by\n * name alone, a second fetch after someone changed `logo` left the old\n * picture under the new manifest, and the next push stored the old one\n * again without a word.\n *\n * Returns the rewritten manifest, or null when nothing in it is hosted.\n */\nexport async function pullManifest(\n ctx: { origin: string; key: string | null },\n dir: string,\n config: Record<string, unknown>,\n log: (line: string) => void,\n): Promise<{ assets: Manifest; files: string[] } | null> {\n const home = homeOrigins(ctx.origin)\n const hosted = manifestRefs(config).filter(({ ref }) =>\n hostedAssetId(ref, home),\n )\n if (hosted.length === 0) return null\n const manifest = cloneManifest(config)\n const indexPath = join(dir, 'assets', HOME_INDEX)\n let index: Record<string, string> = {}\n try {\n const parsed: unknown = JSON.parse(readFileSync(indexPath, 'utf8'))\n if (parsed && typeof parsed === 'object') {\n index = parsed as Record<string, string>\n }\n } catch {\n // no index yet: nothing here is known to be a hosted file\n }\n const files: string[] = []\n for (const { name, index: at, ref } of hosted) {\n const id = hostedAssetId(ref, home)!\n const stem = at === null ? name : `${name}-${at}`\n const known = Object.keys(index).find(\n (f) => f === stem || f.startsWith(`${stem}.`),\n )\n let file: string\n if (\n known &&\n index[known] === id &&\n existsSync(join(dir, 'assets', known))\n ) {\n file = `assets/${known}`\n } else {\n // A different hosted file under this name: the old copy goes first,\n // or a changed extension would leave both lying side by side.\n if (known) {\n rmSync(join(dir, 'assets', known), { force: true })\n delete index[known]\n }\n const got = await downloadMedia(ctx, `/api/assets/${id}/file`, {\n dir,\n subdir: 'assets',\n stem,\n fallbackExt: '',\n describe: `${where(name, at)} (asset ${id})`,\n notFoundHint: 'a private file needs a content key of its owner',\n })\n file = got.file\n index[file.slice('assets/'.length)] = id\n log(\n ` ${file} ← ${where(name, at)}, asset ${id} (${Math.round(got.bytes / 1024)} kB)`,\n )\n }\n files.push(file)\n setRef(manifest, name, at, `./${file}`)\n }\n writeFileSync(indexPath, JSON.stringify(index, null, 2) + '\\n')\n return { assets: manifest, files }\n}\n\nconst HOSTED_FILE_LITERAL =\n /(?:asset:|\\/api\\/assets\\/)([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})/g\nconst FUNCTION_FIELDS = ['setup', 'createContent', 'createTimeline', 'onFrame']\n\n/**\n * A hosted file named inside a function instead of in the manifest. The\n * platform cannot give a string in code a URL per surface, so the file does\n * not reach a render of a private program and does not follow a remix.\n * One line per function and file, in words that say the fix.\n */\nexport function hostedLiteralWarnings(\n config: Record<string, unknown>,\n): string[] {\n const out: string[] = []\n const scan = (label: string, src: unknown) => {\n if (typeof src !== 'string') return\n const seen = new Set<string>()\n for (const m of src.matchAll(HOSTED_FILE_LITERAL)) {\n if (seen.has(m[1])) continue\n seen.add(m[1])\n out.push(\n `${label} names hosted file ${m[1]} in code. Declare it instead: \"assets\": { \"name\": { \"ref\": \"asset:${m[1]}\" } }, and read ctx.assets.name, so it loads on every render and follows a remix`,\n )\n }\n }\n for (const field of FUNCTION_FIELDS) scan(field, config[field])\n const stack = Array.isArray(config.stack) ? config.stack : []\n for (const entry of stack as Record<string, unknown>[]) {\n for (const field of ['setup', 'createContent', 'onFrame']) {\n scan(`stack.${String(entry.id)}.${field}`, entry[field])\n }\n }\n return out\n}\n","import { isKeyedOverlay } from '@vosjs/studio-core'\n/**\n * A hosted take comes home: download the recording (and the\n * mic/cam sidecars when the doc carries them) beside a pulled doc.json, and\n * re-anchor the doc's keys to the local files, so `vos digest`, `frames` and\n * `render` run on a pulled take exactly as on a local one. Also writes the\n * take-dir markers (meta.json, cursor.json) from the doc when absent, so the\n * directory IS a take directory to every other verb.\n *\n * Same consent shape as the upload direction: nothing moves without the verb\n * the user ran (`--media`). A file already on disk is kept, never re-fetched.\n */\nimport { createHash } from 'node:crypto'\nimport { createWriteStream, existsSync } from 'node:fs'\nimport {\n mkdir,\n open,\n readFile,\n readdir,\n rename,\n rm,\n stat,\n writeFile,\n} from 'node:fs/promises'\nimport { basename, dirname, join } from 'node:path'\nimport { Readable } from 'node:stream'\nimport { pipeline } from 'node:stream/promises'\nimport { takeMediaFiles, writeJson } from './take'\nimport {\n MEDIA_HEAD_BYTES,\n extensionFor,\n nameForType,\n resolveMediaType,\n} from './container'\nimport { uploadAsset } from './uploadAsset'\nimport type { UploadTarget, UploadedAsset } from './uploadAsset'\nimport type {\n AudioClip,\n ObjectClip,\n OverlayClip,\n ProjectDoc,\n} from '@vosjs/studio-core'\n\n/** The names the recorders write their sidecars under. */\nexport const MIC_NAME = 'mic.webm'\nexport const CAM_NAME = 'cam.webm'\n\n/**\n * A take's own media: the stem each one lives under, and the container to\n * assume when the bytes that come back say nothing. The EXTENSION is not part\n * of the identity — a pulled recording wears whatever its hosted asset holds.\n */\nconst SOURCE_MEDIA = [\n { key: 'videoKey', stem: 'recording', fallbackExt: '.webm' },\n { key: 'micKey', stem: 'mic', fallbackExt: '.webm' },\n { key: 'camKey', stem: 'cam', fallbackExt: '.webm' },\n] as const\n\n/** A take-relative media key: neither a URL, a blob, nor a hosted asset path. */\nexport function isTakeRelativeKey(key: string | undefined): key is string {\n // `media:<id>` names a document media (a layer that shows one); the media\n // itself rides the upload door, so the reference is never a file.\n return (\n !!key &&\n !/^(https?:|blob:|data:|media:|\\/\\/)/.test(key) &&\n !key.startsWith('/api/')\n )\n}\n\n/** The file a take-relative key names, under the take directory. */\nexport const takeRelativeFile = (key: string): string => key.replace(/^\\/+/, '')\n\nexport interface DocMediaRef {\n /** Where the key lives, in words (for a log line). */\n where: string\n key: string\n /** Replace the key in the document. */\n set: (next: string) => void\n}\n\n/**\n * A take's own sidecars, when they are local files: the voice (`micKey`)\n * and the webcam (`camKey`). A push used to DROP them (\"local-only\"), while\n * `vos fetch --media` writes them beside the take as `mic.webm` and\n * `cam.webm`: fetch, then push, and the voice and the webcam were gone from\n * the hosted take, in one log line nobody reads.\n */\nexport function sourceSidecarRefs(\n doc: ProjectDoc,\n keep: (key: string | undefined) => boolean = isTakeRelativeKey,\n): DocMediaRef[] {\n const out: DocMediaRef[] = []\n for (const [field, where] of [\n ['micKey', 'mic track'],\n ['camKey', 'cam track'],\n ] as const) {\n const key = doc.source[field]\n if (!key || !keep(key)) continue\n out.push({\n where,\n key,\n set: (next) => {\n doc.source[field] = next\n },\n })\n }\n return out\n}\n\n/** The 3D props a document places: each names a model file (a GLB). */\nexport function docObjectRefs(\n doc: { objects?: ObjectClip[] },\n keep: (key: string | undefined) => boolean = isTakeRelativeKey,\n): DocMediaRef[] {\n const out: DocMediaRef[] = []\n for (const clip of doc.objects ?? []) {\n const asset = clip.asset as { kind?: string; key?: string }\n if (asset.kind !== 'gltf' || !keep(asset.key)) continue\n out.push({\n where: `object ${clip.id}`,\n key: asset.key as string,\n set: (next) => {\n asset.key = next\n },\n })\n }\n return out\n}\n\n/** The picture and video layers a document places, by key. */\nexport function docOverlayRefs(\n doc: { overlays?: OverlayClip[] },\n keep: (key: string | undefined) => boolean = isTakeRelativeKey,\n): DocMediaRef[] {\n const out: DocMediaRef[] = []\n for (const clip of doc.overlays ?? []) {\n // An HTML layer has no key: its content IS its source, so there is no file\n // to walk, rewrite or bring home.\n if (!isKeyedOverlay(clip) || !keep(clip.key)) continue\n out.push({\n where: `overlay ${clip.id}`,\n key: clip.key,\n set: (next) => {\n clip.key = next\n },\n })\n }\n return out\n}\n\n/**\n * The shared layers either kind of document carries, as files: picture and\n * video overlays, 3D props, and added sound. A program document has no\n * recording, frame or end card, so this is all it can name; a take reads\n * the same three through `docMediaRefs`.\n */\nexport function docLayerRefs(\n doc: {\n overlays?: OverlayClip[]\n objects?: ObjectClip[]\n audio?: AudioClip[]\n },\n keep: (key: string | undefined) => boolean = isTakeRelativeKey,\n): DocMediaRef[] {\n return [\n ...docOverlayRefs(doc, keep),\n ...docObjectRefs(doc, keep),\n ...docAudioRefs(doc, keep),\n ]\n}\n\n/**\n * Every media key a document carries beside its recording, mic and cam:\n * image and video overlay clips (a poster's mark), 3D props, the end card's\n * mark, a background image or loop, added sound. The recording's own keys\n * are `KEYS` and handled by their own path. A push rehosts these; a pull\n * brings them home.\n */\nexport function docMediaRefs(\n doc: ProjectDoc,\n keep: (key: string | undefined) => boolean = isTakeRelativeKey,\n): DocMediaRef[] {\n const out: DocMediaRef[] = []\n // The take's OTHER media (concat): each recording, and its sidecars,\n // rides the upload door like the primary's; a pull brings them home.\n for (const m of doc.media ?? []) {\n if (keep(m.videoKey))\n out.push({\n where: `media ${m.id}`,\n key: m.videoKey,\n set: (next) => {\n m.videoKey = next\n },\n })\n const mic = m.micKey\n if (mic && keep(mic))\n out.push({\n where: `media ${m.id} mic`,\n key: mic,\n set: (next) => {\n m.micKey = next\n },\n })\n const cam = m.camKey\n if (cam && keep(cam))\n out.push({\n where: `media ${m.id} cam`,\n key: cam,\n set: (next) => {\n m.camKey = next\n },\n })\n }\n out.push(...docOverlayRefs(doc, keep))\n // A prop's model was never walked: a take with a GLB pushed a document\n // whose object keyed a file only the pusher's disk held.\n out.push(...docObjectRefs(doc, keep))\n const mark = doc.endCard?.mark\n if (mark && keep(mark.key))\n out.push({\n where: 'end card mark',\n key: mark.key,\n set: (next) => {\n mark.key = next\n },\n })\n const bg = doc.frame.backgroundMedia\n if (bg && keep(bg.key))\n out.push({\n where: 'background',\n key: bg.key,\n set: (next) => {\n bg.key = next\n },\n })\n out.push(...docAudioRefs(doc, keep))\n return out\n}\n\n/**\n * The sound a document adds (`doc.audio`: a score, a voice-over, an effect),\n * for either kind of document. A take reads it through `docMediaRefs`; a\n * program document, which has no recording or frame, reads it here. A\n * catalog track is an absolute URL and is never walked.\n */\nexport function docAudioRefs(\n doc: { audio?: AudioClip[] },\n keep: (key: string | undefined) => boolean = isTakeRelativeKey,\n): DocMediaRef[] {\n const out: DocMediaRef[] = []\n for (const clip of doc.audio ?? []) {\n if (!keep(clip.key)) continue\n out.push({\n where: `audio ${clip.id}`,\n key: clip.key,\n set: (next) => {\n clip.key = next\n },\n })\n }\n return out\n}\n\n/**\n * Upload the files a document names and point its keys at the hosted\n * assets. Each file rides the content-addressed upload door, so a re-push\n * reuses it; the bytes name the type, and the uploaded filename is corrected\n * to match so the asset is never self-contradictory. A key whose file is\n * missing is said and left as it is (the hosted render will 404 on it,\n * honestly). Take pushes and program pushes share it.\n */\nexport async function uploadDocRefs(\n refs: DocMediaRef[],\n dir: string,\n target: UploadTarget,\n log: (line: string) => void,\n): Promise<void> {\n for (const ref of refs) {\n const file = join(dir, takeRelativeFile(ref.key))\n if (!existsSync(file)) {\n log(` ${ref.where}: ${ref.key} is not beside the document — left as is`)\n continue\n }\n const media = await readFile(file)\n const mediaHash = createHash('sha256').update(media).digest('hex')\n const { type } = resolveMediaType({\n head: media.subarray(0, MEDIA_HEAD_BYTES),\n filename: file,\n })\n const name = nameForType(basename(file), type)\n if (name !== basename(file)) {\n log(` ${ref.where}: ${basename(file)} holds ${type} — sent as ${name}`)\n }\n let put: UploadedAsset\n try {\n put = await uploadAsset(target, new Uint8Array(media), {\n filename: name,\n contentType: type,\n contentHash: mediaHash,\n })\n } catch (e) {\n throw new Error(\n `${ref.where} upload failed: ${e instanceof Error ? e.message : String(e)}`,\n )\n }\n ref.set(put.url)\n log(\n ` ${ref.where}: ${ref.key} → asset ${put.id}${put.reused ? ' (reused)' : ''}`,\n )\n for (const note of put.notes) log(` ${ref.where}: ${note}`)\n }\n}\n\n// The extension↔type table and the byte sniffer live in `container.ts`; these\n// stay the door every media caller already knows.\nexport { extensionFor, mediaContentType } from './container'\n\n/** An asset file URL (relative `/api/assets/{id}/file` or absolute). */\nexport function assetIdOf(url: string | undefined): string | null {\n if (!url) return null\n const m = /\\/api\\/assets\\/([A-Za-z0-9_-]+)\\/file/.exec(url)\n return m ? m[1] : null\n}\n\nexport interface MediaPullResult {\n downloaded: { file: string; assetId: string; bytes: number }[]\n kept: string[]\n}\n\n/** The first bytes of a file, enough for every container signature. */\nexport async function readMediaHead(file: string): Promise<Uint8Array> {\n const handle = await open(file, 'r')\n try {\n const buf = Buffer.alloc(MEDIA_HEAD_BYTES)\n const { bytesRead } = await handle.read(buf, 0, MEDIA_HEAD_BYTES, 0)\n return new Uint8Array(buf.subarray(0, bytesRead))\n } finally {\n await handle.close()\n }\n}\n\nexport interface DownloadTarget {\n dir: string\n /** Directory under the take dir, when the file is filed away. */\n subdir?: string\n /** The name without its extension — the extension is the BYTES' to choose. */\n stem: string\n /** The container to assume when the bytes say nothing. */\n fallbackExt: string\n /** What is being fetched, in words, for an error or a log line. */\n describe: string\n /** Added to a 404, where the reason is usually the credential. */\n notFoundHint?: string\n}\n\n/**\n * One media file, brought home under the name its BYTES earn.\n *\n * Streamed to a `.part` sibling first, then sniffed and renamed, so a take\n * never holds a file whose extension lies — whatever the server declared, and\n * whatever the hosted asset happened to be called. A push of a pulled take\n * re-uploads that file, so a wrong name here becomes a wrong Content-Type on\n * the asset, and a render that dies inside the video element.\n */\nexport async function downloadMedia(\n ctx: { origin: string; key: string | null },\n url: string,\n target: DownloadTarget,\n): Promise<{ file: string; bytes: number }> {\n const abs = /^https?:/.test(url) ? url : `${ctx.origin}${url}`\n const res = await fetch(abs, {\n headers: ctx.key ? { authorization: `Bearer ${ctx.key}` } : {},\n })\n if (!res.ok || !res.body) {\n throw new Error(\n `download of ${target.describe} failed (${res.status})${\n res.status === 404 && target.notFoundHint\n ? ` — ${target.notFoundHint}`\n : ''\n }`,\n )\n }\n const into = target.subdir ? join(target.dir, target.subdir) : target.dir\n const partial = join(into, `${target.stem}.part`)\n await mkdir(dirname(partial), { recursive: true })\n try {\n await pipeline(\n Readable.fromWeb(res.body as never),\n createWriteStream(partial),\n )\n const { type } = resolveMediaType({\n head: await readMediaHead(partial),\n declared: res.headers.get('content-type'),\n filename: `${target.stem}${target.fallbackExt}`,\n })\n const name = `${target.stem}${extensionFor(type) || target.fallbackExt}`\n await rename(partial, join(into, name))\n const file = target.subdir ? `${target.subdir}/${name}` : name\n return { file, bytes: (await stat(join(target.dir, file))).size }\n } finally {\n // A rename leaves nothing behind; a failed transfer must not.\n await rm(partial, { force: true })\n }\n}\n\nexport async function pullMedia(\n ctx: { origin: string; key: string | null },\n dir: string,\n doc: ProjectDoc,\n log: (line: string) => void,\n): Promise<MediaPullResult> {\n const result: MediaPullResult = { downloaded: [], kept: [] }\n for (const { key, stem, fallbackExt } of SOURCE_MEDIA) {\n const url = doc.source[key]\n const assetId = assetIdOf(url)\n if (!assetId) continue\n // A file already here is kept whatever container it wears, so a second\n // pull never re-fetches and never leaves two of the same footage.\n const present = takeMediaFiles(dir, stem)[0]\n if (present) {\n result.kept.push(basename(present))\n doc.source[key] = basename(present)\n continue\n }\n const got = await downloadMedia(ctx, url!, {\n dir,\n stem,\n fallbackExt,\n describe: stem,\n notFoundHint: 'a private recording needs a content key of its owner',\n })\n result.downloaded.push({ file: got.file, assetId, bytes: got.bytes })\n log(` ${got.file} ← asset ${assetId} (${Math.round(got.bytes / 1024)} kB)`)\n doc.source[key] = got.file\n }\n // The document's other media (a poster's mark, a pasted ground): a hosted\n // asset comes home under media/<assetId>.<ext> and the key re-anchors to\n // it, so the pulled poster renders and re-pushes as a whole.\n for (const ref of docMediaRefs(doc, (k) => assetIdOf(k) !== null)) {\n const assetId = assetIdOf(ref.key)!\n const existing = existsSync(join(dir, 'media'))\n ? (await readdir(join(dir, 'media'))).find(\n (f) => f === assetId || f.startsWith(`${assetId}.`),\n )\n : undefined\n if (existing) {\n const file = `media/${existing}`\n result.kept.push(file)\n ref.set(file)\n continue\n }\n const got = await downloadMedia(ctx, ref.key, {\n dir,\n subdir: 'media',\n stem: assetId,\n // A type with no extension here (an svg served as such) keeps the bare\n // asset id, exactly as before.\n fallbackExt: '',\n describe: `${ref.where} (${ref.key})`,\n })\n result.downloaded.push({ file: got.file, assetId, bytes: got.bytes })\n log(\n ` ${got.file} ← ${ref.where}, asset ${assetId} (${Math.round(got.bytes / 1024)} kB)`,\n )\n ref.set(got.file)\n }\n // The take-dir markers: meta.json and cursor.json live on the doc for a\n // hosted take; write them out so loadTake() recognizes the directory.\n const metaPath = join(dir, 'meta.json')\n if (!existsSync(metaPath)) await writeJson(metaPath, doc.source.meta, true)\n const cursorPath = join(dir, 'cursor.json')\n if (!existsSync(cursorPath)) await writeJson(cursorPath, doc.source.cursor)\n await writeFile(join(dir, 'doc.json'), JSON.stringify(doc, null, 2))\n return result\n}\n","/**\n * The take directory — the CLI's unit of work, human-inspectable on purpose:\n * take/\n * recording.webm encoded footage (CFR; .mp4 when a pull brought it home\n * in that container, so readers RESOLVE the name)\n * frames/ raw screencast JPEGs + frames.json (kept for re-encode)\n * cursor.json synthesized CursorTrack\n * meta.json RecordingMeta (producer: 'cli')\n * actions.json the script that produced it (replay recipe)\n * doc.json ProjectDoc — the agent-editable surface\n */\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { existsSync, readdirSync, statSync } from 'node:fs'\nimport { basename, join } from 'node:path'\nimport { TAKE_MEDIA_EXTENSIONS } from './container'\nimport type { CursorTrack, ProjectDoc, RecordingMeta } from '@vosjs/studio-core'\nimport type { ActionsFile } from './actions'\n\n/** The name `record` writes its footage under — its encoder emits WebM. */\nexport const RECORDING_NAME = 'recording.webm'\n\n/**\n * A take's own media under `dir`, whatever container it came home in.\n *\n * `record` writes WebM, but a PULLED take wears the container its hosted asset\n * actually holds, so nothing may spell `recording.webm` at a read site: a take\n * whose footage is mp4 must still render, digest and push. Ordered by\n * `TAKE_MEDIA_EXTENSIONS`, so the answer is deterministic if a stale sibling\n * survives.\n */\nexport function takeMediaFiles(dir: string, stem: string): string[] {\n return TAKE_MEDIA_EXTENSIONS.map((ext) => join(dir, `${stem}${ext}`)).filter(\n (file) => existsSync(file),\n )\n}\n\n/**\n * The one file a take's media stem names, falling back to what `record` would\n * write — so a caller can `existsSync` the answer and get an honest\n * \"no footage here\" rather than a path that never existed.\n */\nexport function takeMediaFile(\n dir: string,\n stem: string,\n fallback: string,\n): string {\n return takeMediaFiles(dir, stem)[0] ?? join(dir, fallback)\n}\n\n/** The previous cut, preserved by a re-record. */\nexport const PREV_DOC_NAME = 'doc.prev.json'\n\nexport interface TakePaths {\n dir: string\n recording: string\n /** The recording's bare filename — what a doc key or a served URL spells. */\n recordingName: string\n framesDir: string\n framesIndex: string\n cursor: string\n meta: string\n actions: string\n doc: string\n}\n\nexport function takePaths(dir: string): TakePaths {\n const recording = takeMediaFile(dir, 'recording', RECORDING_NAME)\n return {\n dir,\n recording,\n recordingName: basename(recording),\n framesDir: join(dir, 'frames'),\n framesIndex: join(dir, 'frames.json'),\n cursor: join(dir, 'cursor.json'),\n meta: join(dir, 'meta.json'),\n actions: join(dir, 'actions.json'),\n doc: join(dir, 'doc.json'),\n }\n}\n\nexport async function ensureTakeDir(dir: string): Promise<TakePaths> {\n const p = takePaths(dir)\n await mkdir(p.framesDir, { recursive: true })\n return p\n}\n\n/**\n * Drop the screencast JPEGs once the recording they were encoded into is on\n * disk. They are the bulk of a take (one hero take: 437 MB of a 452 MB\n * directory) and nothing needs them afterwards: the digest reads frames\n * from them WHEN PRESENT and from the video otherwise, which is the path\n * every pulled take already runs on. Refuses unless the recording exists and\n * has bytes, so a failed encode never costs the only copy of the footage.\n * Returns the bytes freed, 0 when it left everything alone.\n */\nexport async function dropScreencastFrames(p: TakePaths): Promise<number> {\n if (!existsSync(p.recording) || statSync(p.recording).size === 0) return 0\n if (!existsSync(p.framesDir)) return 0\n let freed = 0\n for (const name of readdirSync(p.framesDir)) {\n try {\n freed += statSync(join(p.framesDir, name)).size\n } catch {\n // a file gone between the listing and the stat frees nothing\n }\n }\n await rm(p.framesDir, { recursive: true, force: true })\n await rm(p.framesIndex, { force: true })\n return freed\n}\n\n/**\n * Re-record into an existing take WITHOUT destroying the cut (the\n * re-render loop's first rung; `rm -rf` here is what made \"re-renders on the\n * next version\" a false claim). What the old footage produced is cleared\n * (recording, cursor, meta, raw frames, stills/, digest/ — all derived and\n * regenerable); what the human's work lives in survives: `doc.json` moves to\n * `doc.prev.json` — the explicit reuse base `vos plan --reuse` re-anchors\n * onto the new recording — and `actions.json` + `vos.json` stay put. The doc\n * is MOVED, never left in place: a doc.json embeds its footage's cursor and\n * meta (`doc.source`), so leaving it beside new footage would be a document\n * lying about its source, and the auto-plan after recording would replan\n * from the OLD cursor. Returns what was kept, for the terminal to say.\n */\nexport async function prepareReRecord(\n dir: string,\n): Promise<{ prevDoc: boolean; kept: string[] }> {\n const p = takePaths(dir)\n const kept: string[] = []\n let prevDoc = false\n if (existsSync(p.doc)) {\n await rename(p.doc, join(dir, PREV_DOC_NAME))\n prevDoc = true\n kept.push(PREV_DOC_NAME)\n }\n if (existsSync(p.actions)) kept.push('actions.json')\n if (existsSync(join(dir, 'vos.json'))) kept.push('vos.json')\n for (const stale of [\n // Every container, not just the one `record` writes: a pulled take's\n // footage may be mp4, and a survivor would outrank the new recording.\n ...takeMediaFiles(dir, 'recording'),\n ...takeMediaFiles(dir, 'mic'),\n ...takeMediaFiles(dir, 'cam'),\n p.cursor,\n p.meta,\n p.framesIndex,\n p.framesDir,\n join(dir, 'stills'),\n join(dir, 'digest'),\n ]) {\n await rm(stale, { recursive: true, force: true })\n }\n return { prevDoc, kept }\n}\n\nexport async function readJson<T>(file: string): Promise<T> {\n return JSON.parse(await readFile(file, 'utf8')) as T\n}\n\nexport async function writeJson(\n file: string,\n value: unknown,\n pretty = false,\n): Promise<void> {\n await writeFile(\n file,\n pretty ? JSON.stringify(value, null, 2) : JSON.stringify(value),\n )\n}\n\nexport interface TakeData {\n paths: TakePaths\n cursor: CursorTrack\n meta: RecordingMeta\n actions: ActionsFile | null\n doc: ProjectDoc | null\n}\n\n/** Load a take directory; cursor+meta are required, doc/actions optional. */\nexport async function loadTake(dir: string): Promise<TakeData> {\n const paths = takePaths(dir)\n if (!existsSync(paths.meta)) {\n throw new Error(\n `${dir} is not a take directory (missing meta.json) — run record first`,\n )\n }\n const meta = await readJson<RecordingMeta>(paths.meta)\n const cursor = existsSync(paths.cursor)\n ? await readJson<CursorTrack>(paths.cursor)\n : []\n const actions = existsSync(paths.actions)\n ? await readJson<ActionsFile>(paths.actions)\n : null\n const doc = existsSync(paths.doc)\n ? await readJson<ProjectDoc>(paths.doc)\n : null\n return { paths, cursor, meta, actions, doc }\n}\n","/**\n * Uploading a file to vos.so: one door, for every kind and every size.\n *\n * The file is declared first, sent as parts, and sealed. Three reasons it\n * is never one request:\n *\n * - A request body has a ceiling the platform does not set and cannot\n * raise from inside a handler: the edge refuses anything past it before\n * the request arrives, with its own error page rather than a worded\n * refusal. A screen recording of any real length clears that ceiling.\n * - Everything the platform may refuse a file for (its kind, its size, a\n * daily rate, the account's storage) is weighed at the declaring call,\n * before a byte moves, so a refusal costs nothing and arrives in words.\n * - The declaring call is content-addressed: the same bytes pushed twice\n * are recognised and never re-sent, which is what keeps an iterating\n * push from re-uploading a take on every round.\n *\n * The part size is NOT decided here. The platform returns it from the\n * declaring call, so the split can change server-side without a CLI\n * release.\n *\n * What the file IS comes back from the sealing call: the platform reads\n * the stored bytes and answers its kind, the name it is stored under and\n * anything worth saying about it. Nothing here decides what is accepted;\n * `GET /api/limits` lists the kinds and their caps.\n */\nimport { apiJson } from './platform'\nimport type { ApiResult } from './platform'\n\n/** Attempts per part. A part commits nothing until the upload is sealed,\n * so it is always safe to send again. */\nconst PART_ATTEMPTS = 3\n\nexport interface PartPlan {\n /** Part numbers are 1-based. */\n partNumber: number\n start: number\n /** One past the last byte. */\n end: number\n}\n\n/**\n * The slices to send, in order. Every part but the last is exactly\n * `partBytes`; the last is the remainder. The platform holds each part to\n * exactly this length, so the split has to agree with the size that was\n * declared — which is why `partBytes` comes from the platform rather than\n * from a constant here.\n */\nexport function planParts(totalBytes: number, partBytes: number): PartPlan[] {\n if (totalBytes <= 0 || partBytes <= 0) return []\n const parts: PartPlan[] = []\n for (let start = 0; start < totalBytes; start += partBytes) {\n parts.push({\n partNumber: parts.length + 1,\n start,\n end: Math.min(start + partBytes, totalBytes),\n })\n }\n return parts\n}\n\nexport interface UploadedAsset {\n id: string\n /** The path a document names the file by. */\n url: string\n size: number\n /** The platform already had these exact bytes; nothing was sent. */\n reused: boolean\n /** What the bytes are, as the platform read them (video, audio, image,\n * vector, model, font, hdr, recipe, captions). */\n kind: string\n /** The name it is stored under: the extension follows the bytes. */\n filename: string\n /** The frontmatter summary of a recipe, a picture's size, a clip's codec. */\n metadata: Record<string, unknown> | null\n /** What the platform did to the file or wants said about it. */\n notes: string[]\n}\n\nexport interface UploadTarget {\n origin: string\n key: string\n}\n\nexport interface UploadOptions {\n filename: string\n /** Only a hint: the platform types a file by its bytes. It settles the\n * one thing bytes cannot, a WebM that holds sound alone. */\n contentType?: string\n /** sha256 hex — the platform dedupes on it, per owner. */\n contentHash: string\n /** The take's length, so a refusal for one past the hosted cap arrives\n * before anything is sent. The platform measures the file either way. */\n durationSeconds?: number\n /** Parts landed, for a caller that reports a long upload's progress. */\n onPart?: (done: number, total: number) => void\n /** File the asset into one of the caller's folders. */\n folderId?: string\n /**\n * `library`: a file added to keep (`vos asset push`, a recipe).\n * `attached` (the default): a file a document is about to name, which\n * the platform collects if nothing ever does.\n */\n intent?: 'library' | 'attached'\n}\n\nfunction failed(what: string, r: ApiResult): Error {\n const detail = typeof r.body.error === 'string' ? r.body.error : ''\n const hint = typeof r.body.hint === 'string' ? ` ${r.body.hint}` : ''\n return new Error(`${what} (${r.status})${detail ? `: ${detail}${hint}` : ''}`)\n}\n\nfunction asAsset(\n body: Record<string, unknown>,\n reused: boolean,\n): UploadedAsset {\n const asset = (body.asset ?? {}) as Record<string, unknown>\n return {\n id: String(asset.id),\n url: String(asset.fileUrl),\n size: typeof asset.size === 'number' ? asset.size : 0,\n reused,\n kind: typeof asset.kind === 'string' ? asset.kind : '',\n filename: typeof asset.filename === 'string' ? asset.filename : '',\n metadata:\n asset.metadata && typeof asset.metadata === 'object'\n ? (asset.metadata as Record<string, unknown>)\n : null,\n notes: Array.isArray(body.notes)\n ? body.notes.filter((n): n is string => typeof n === 'string')\n : [],\n }\n}\n\n/** Worth sending again: the platform was busy or briefly unreachable. A\n * refusal is a decision and will read the same on a second try. */\nfunction transient(status: number): boolean {\n return status >= 500 || status === 429\n}\n\nconst wait = (ms: number) => new Promise((r) => setTimeout(r, ms))\n\n/** Upload one file as an owned asset: declare it, send its parts, seal it. */\nexport async function uploadAsset(\n target: UploadTarget,\n bytes: Uint8Array,\n opts: UploadOptions,\n): Promise<UploadedAsset> {\n // Declare it first. Every quota is weighed here, before a byte moves, so\n // a refusal costs nothing and arrives in words — and the dedupe answers\n // here too, which is what makes re-pushing a hosted take free.\n const begun = await apiJson(target.origin, '/api/assets/uploads', {\n method: 'POST',\n key: target.key,\n body: {\n filename: opts.filename,\n ...(opts.contentType ? { contentType: opts.contentType } : {}),\n size: bytes.length,\n sha256: opts.contentHash,\n ...(opts.durationSeconds && opts.durationSeconds > 0\n ? { durationSeconds: opts.durationSeconds }\n : {}),\n ...(opts.folderId ? { folderId: opts.folderId } : {}),\n ...(opts.intent ? { intent: opts.intent } : {}),\n },\n })\n if (begun.status !== 201 && begun.status !== 200) {\n throw failed('upload failed', begun)\n }\n // The platform already holds these bytes: nothing to send.\n if (begun.body.asset) return asAsset(begun.body, true)\n\n const uploadId = String(begun.body.uploadId)\n const partBytes = Number(begun.body.partBytes)\n if (!Number.isFinite(partBytes) || partBytes <= 0) {\n throw new Error('upload failed: the platform returned no part size')\n }\n const parts = planParts(bytes.length, partBytes)\n const etags: { partNumber: number; etag: string }[] = []\n\n try {\n for (const part of parts) {\n const chunk = bytes.subarray(part.start, part.end)\n let sent: ApiResult | null = null\n for (let attempt = 1; attempt <= PART_ATTEMPTS; attempt++) {\n try {\n sent = await apiJson(\n target.origin,\n `/api/assets/uploads/${uploadId}/parts/${part.partNumber}`,\n {\n method: 'PUT',\n key: target.key,\n headers: {\n 'Content-Type': 'application/octet-stream',\n 'Content-Length': String(chunk.length),\n },\n raw: chunk,\n },\n )\n } catch (networkError) {\n // Dropped connection, a sleeping machine: worth another try.\n if (attempt === PART_ATTEMPTS) throw networkError\n await wait(500 * 2 ** (attempt - 1))\n continue\n }\n if (sent.status === 200) break\n if (!transient(sent.status) || attempt === PART_ATTEMPTS) {\n throw failed(`part ${part.partNumber} failed`, sent)\n }\n await wait(500 * 2 ** (attempt - 1))\n }\n if (!sent || sent.status !== 200) {\n throw new Error(`part ${part.partNumber} failed`)\n }\n etags.push({\n partNumber: Number(sent.body.partNumber),\n etag: String(sent.body.etag),\n })\n opts.onPart?.(etags.length, parts.length)\n }\n\n // Sealing is where the platform reads the file. A refusal here means\n // the bytes are not what the name said, and it has already taken them\n // back out.\n const sealed = await apiJson(\n target.origin,\n `/api/assets/uploads/${uploadId}/complete`,\n { method: 'POST', key: target.key, body: { parts: etags } },\n )\n if (sealed.status !== 201 && sealed.status !== 200) {\n throw failed('upload failed', sealed)\n }\n return asAsset(sealed.body, false)\n } catch (err) {\n // Hand the parts back rather than leaving them held server-side.\n await apiJson(target.origin, `/api/assets/uploads/${uploadId}`, {\n method: 'DELETE',\n key: target.key,\n }).catch(() => undefined)\n throw err\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA;AAAA,EACE,cAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,QAAAC,OAAM,gBAAgB;;;AClB/B,SAAS,sBAAsB;AAY/B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB,cAAAC,mBAAkB;AAC9C;AAAA,EACE,SAAAC;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,EACA;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,OACK;AACP,SAAS,YAAAC,WAAU,SAAS,QAAAC,aAAY;AACxC,SAAS,gBAAgB;AACzB,SAAS,gB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AC;AAAA,MAC7G;AAAA,IACF;AAAA,EACF;AACA,aAAW,SAAS,gBAAiB,MAAK,OAAO,OAAO,KAAK,CAAC;AAC9D,QAAM,QAAQ,MAAM,QAAQ,OAAO,KAAK,IAAI,OAAO,QAAQ,CAAC;AAC5D,aAAW,SAAS,OAAoC;AACtD,eAAW,SAAS,CAAC,SAAS,iBAAiB,SAAS,GAAG;AACzD,WAAK,SAAS,OAAO,MAAM,EAAE,CAAC,IAAI,KAAK,IAAI,MAAM,KAAK,CAAC;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;","names":["existsSync","join","existsSync","mkdir","readFile","rename","rm","writeFile","basename","join","where","join","existsSync","readFile","basename","mkdir","rename","rm","writeFile","join","existsSync"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ASSET_ROUTE,
|
|
4
|
-
UsageError
|
|
5
|
-
|
|
4
|
+
UsageError,
|
|
5
|
+
serveFile
|
|
6
|
+
} from "./chunk-WCF6KIOK.js";
|
|
6
7
|
|
|
7
8
|
// src/loadConfig.ts
|
|
8
9
|
import { readFile } from "fs/promises";
|
|
@@ -248,9 +249,14 @@ async function runCapturePage(browser, html, opts) {
|
|
|
248
249
|
);
|
|
249
250
|
const files = opts.files ?? {};
|
|
250
251
|
if (Object.keys(files).length > 0) {
|
|
251
|
-
await page.route(`${RENDER_ORIGIN}${ASSET_ROUTE}**`, (route) => {
|
|
252
|
-
const
|
|
253
|
-
|
|
252
|
+
await page.route(`${RENDER_ORIGIN}${ASSET_ROUTE}**`, async (route) => {
|
|
253
|
+
const request = route.request();
|
|
254
|
+
const file = files[new URL(request.url()).pathname];
|
|
255
|
+
if (!file) {
|
|
256
|
+
return route.fulfill({ status: 404, body: "no such declared file" });
|
|
257
|
+
}
|
|
258
|
+
const answer = serveFile(file, await request.headerValue("range"));
|
|
259
|
+
return route.fulfill(answer);
|
|
254
260
|
});
|
|
255
261
|
}
|
|
256
262
|
await page.goto(`${RENDER_ORIGIN}/render`, {
|
|
@@ -555,4 +561,4 @@ export {
|
|
|
555
561
|
setFlags,
|
|
556
562
|
applyDataSets
|
|
557
563
|
};
|
|
558
|
-
//# sourceMappingURL=chunk-
|
|
564
|
+
//# sourceMappingURL=chunk-LWHVZ5WI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/loadConfig.ts","../src/browser.ts","../src/render.ts","../src/outputs.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises'\nimport { existsSync, readFileSync, statSync } from 'node:fs'\nimport { basename, dirname, join } from 'node:path'\nimport {\n CURRENT_CONFIG_VERSION,\n migrateConfig,\n vosConfigJsonSchema,\n} from '@vosjs/core'\nimport { UsageError } from './args'\n\nexport interface LoadedConfig {\n config: Record<string, unknown>\n warnings: string[]\n}\n\n/**\n * What a directory holds, by one deterministic sniff and never a flag:\n * a TAKE carries a recording document (`doc.json` with `source`); a PROGRAM\n * directory carries `config.json`, optionally beside a program document\n * (`doc.json` without `source`: the shared layers, the tween overlay, the\n * program's own length, with `program.config` omitted on disk). An unparsable\n * doc.json counts as a take so the take path reports the real error.\n */\nexport type DirectoryKind = 'take' | 'program' | 'none'\n\nexport function directoryKind(target: string): DirectoryKind {\n try {\n if (!statSync(target).isDirectory()) return 'none'\n } catch {\n return 'none'\n }\n const docPath = join(target, 'doc.json')\n if (existsSync(docPath)) {\n try {\n const doc: unknown = JSON.parse(readFileSync(docPath, 'utf8'))\n if (typeof doc === 'object' && doc !== null && 'source' in doc)\n return 'take'\n } catch {\n return 'take'\n }\n }\n return existsSync(join(target, 'config.json')) ? 'program' : 'none'\n}\n\n/** A directory holding a PROGRAM document (`doc.json` without `source`). */\nfunction hasProgramDoc(dir: string): boolean {\n const docPath = join(dir, 'doc.json')\n if (!existsSync(docPath)) return false\n try {\n const doc: unknown = JSON.parse(readFileSync(docPath, 'utf8'))\n return typeof doc === 'object' && doc !== null && !('source' in doc)\n } catch {\n return false\n }\n}\n\n/**\n * A program directory's config: `config.json`, composed with the program\n * document beside it when there is one (the layers ride as the studio stack\n * entry, the tween overlay is baked into `createTimeline`), so a render of\n * the directory is a render of what the studio and vos.so play.\n */\nexport async function loadProgramDirectory(\n dir: string,\n warnings: string[],\n): Promise<unknown> {\n const config: unknown = JSON.parse(\n await readFile(join(dir, 'config.json'), 'utf8'),\n )\n const docPath = join(dir, 'doc.json')\n if (!existsSync(docPath)) return config\n const doc: unknown = JSON.parse(await readFile(docPath, 'utf8'))\n if (typeof doc !== 'object' || doc === null || 'source' in doc) return config\n if (typeof config !== 'object' || config === null) {\n throw new UsageError(`${dir}/config.json does not contain a JSON object`)\n }\n const raw = doc as Record<string, unknown>\n const program =\n raw.program && typeof raw.program === 'object'\n ? (raw.program as Record<string, unknown>)\n : {}\n const { lowerProgramDoc } = await import('@vosjs/studio-core')\n const composed = lowerProgramDoc(\n { ...raw, program: { ...program, config } } as never,\n { bake: true },\n ).config\n warnings.push(\n 'composed config.json with doc.json (a program document: its layers and tween edits ride the render)',\n )\n return composed\n}\n\n/**\n * The text of a config source: an http(s) URL or a file. A directory that is\n * neither a take nor a program directory is refused in words, since the raw\n * read would report a bare EISDIR.\n */\nexport async function readSourceText(source: string): Promise<string> {\n if (/^https?:\\/\\//.test(source)) {\n const res = await fetch(source)\n if (!res.ok) throw new Error(`fetch ${source} → ${res.status}`)\n return await res.text()\n }\n let isDir = false\n try {\n isDir = statSync(source).isDirectory()\n } catch {\n /* a missing path reads below and reports itself */\n }\n if (isDir) {\n throw new UsageError(\n `${source} is a directory with no config.json and no doc.json — pass a config file, a URL, a program directory or a take`,\n )\n }\n return await readFile(source, 'utf8')\n}\n\n/**\n * Load a VosConfigJson from a file path, an http(s) URL, or a program\n * directory (config.json, composed with a program document when one sits\n * beside it); unwrap API `{ config }` envelopes, migrate old versions, and\n * validate against the schema. A take directory is refused here in words:\n * takes render through the take pipeline (`vos render <take>`).\n */\nexport async function loadVosConfig(source: string): Promise<LoadedConfig> {\n const warnings: string[] = []\n let parsed: unknown\n const kind = /^https?:\\/\\//.test(source) ? 'none' : directoryKind(source)\n if (kind === 'take') {\n throw new UsageError(\n `${source} is a take (its doc.json is a recording document). Render it through the take pipeline: vos render ${source} [out]; vos frames ${source} for stills.`,\n )\n }\n if (kind === 'program') {\n parsed = await loadProgramDirectory(source, warnings)\n return finish(source, parsed, warnings)\n }\n // A program's config.json named directly, with its document beside it:\n // read the directory, or the document's sound and layers silently drop\n // out of a render that looks complete.\n if (\n !/^https?:\\/\\//.test(source) &&\n basename(source) === 'config.json' &&\n hasProgramDoc(dirname(source))\n ) {\n parsed = await loadProgramDirectory(dirname(source), warnings)\n return finish(source, parsed, warnings)\n }\n const raw = await readSourceText(source)\n\n try {\n parsed = JSON.parse(raw)\n } catch (e) {\n throw new UsageError(`${source} is not valid JSON: ${(e as Error).message}`)\n }\n return finish(source, parsed, warnings)\n}\n\nfunction finish(\n source: string,\n parsed: unknown,\n warnings: string[],\n): LoadedConfig {\n if (typeof parsed !== 'object' || parsed === null) {\n throw new UsageError(`${source} does not contain a JSON object`)\n }\n\n // API endpoints wrap the config: { config: {...} }.\n let obj = parsed as Record<string, unknown>\n if (\n typeof obj.config === 'object' &&\n obj.config !== null &&\n !('createTimeline' in obj)\n ) {\n obj = obj.config as Record<string, unknown>\n warnings.push('unwrapped { config } envelope')\n }\n\n const version = obj.version\n const migrated = migrateConfig(obj)\n if (version === undefined) {\n // Plays fine (the stamp happens above), but a storer refuses it.\n warnings.push(\n `config declares no \"version\". Add \"version\": ${CURRENT_CONFIG_VERSION} before pushing it.`,\n )\n } else if (version !== CURRENT_CONFIG_VERSION) {\n warnings.push(\n `migrated config v${String(version)} to v${CURRENT_CONFIG_VERSION}`,\n )\n }\n\n const check = vosConfigJsonSchema.safeParse(migrated)\n if (!check.success) {\n const issues = check.error.issues\n .slice(0, 5)\n .map((i) => ` ${i.path.join('.') || '(root)'}: ${i.message}`)\n .join('\\n')\n throw new UsageError(`invalid vos config:\\n${issues}`)\n }\n\n return { config: migrated, warnings }\n}\n\n/** Best-effort duration from the config (seconds). */\nexport function configDuration(\n config: Record<string, unknown>,\n): number | undefined {\n const d = config.duration\n return typeof d === 'number' && Number.isFinite(d) && d > 0 ? d : undefined\n}\n","import { chromium } from 'playwright'\nimport type { Browser } from 'playwright'\n\nexport class BrowserUnavailableError extends Error {\n constructor(cause: string) {\n super(\n `Could not launch a Chromium-family browser (${cause}).\\n` +\n `Fixes, in order of preference:\\n` +\n ` 1. Install Google Chrome (used automatically), or\\n` +\n ` 2. npx playwright install chromium, or\\n` +\n ` 3. Set VOS_BROWSER_PATH to a Chrome/Chromium executable.`,\n )\n }\n}\n\n/**\n * Launch headless Chromium: explicit VOS_BROWSER_PATH → system Chrome\n * (no download needed) → Playwright's bundled Chromium.\n *\n * `args` are extra Chromium switches (`--browser-arg` on the verbs that\n * record). Some product surfaces cannot be reached without one: a recorder\n * needs a fake capture device to get past a permission prompt, an extension\n * page needs the extension loaded. Passed through verbatim.\n */\nexport async function launchBrowser(args: string[] = []): Promise<Browser> {\n const opts = args.length ? { args } : {}\n const explicit = process.env.VOS_BROWSER_PATH\n if (explicit) {\n return chromium.launch({ ...opts, executablePath: explicit }).catch((e) => {\n throw new BrowserUnavailableError(\n `VOS_BROWSER_PATH failed: ${(e as Error).message}`,\n )\n })\n }\n try {\n return await chromium.launch({ ...opts, channel: 'chrome' })\n } catch {\n try {\n return await chromium.launch(opts)\n } catch (e) {\n throw new BrowserUnavailableError(\n (e as Error).message.split('\\n')[0] ?? 'unknown',\n )\n }\n }\n}\n","import { compileVosConfig, programSize } from '@vosjs/core'\nimport { generateRenderTemplate } from '@vosjs/core/runtime'\nimport { elementsBundleCode } from '@vosjs/elements/bundle'\nimport { tweenRuntimeCode } from '@vosjs/tween/bundle'\nimport type { Browser, Page } from 'playwright'\nimport { ASSET_ROUTE, serveFile } from './programAssets'\nimport type { ProgramAssets } from './programAssets'\n\n/** Fake secure origin the render page is served from (WebCodecs needs one). */\nconst RENDER_ORIGIN = 'https://vos-cli.render'\n\nexport interface RenderCommonOptions {\n config: Record<string, unknown>\n width: number\n height: number\n /** Phase callback for progress reporting. */\n onPhase?: (phase: string) => void\n /**\n * The program's declared files made reachable for this page\n * (`programAssets`): handed to the engine as `ctx.assets`, with the local\n * ones served from disk on the page's own origin.\n */\n assets?: ProgramAssets | null\n}\n\nexport interface RenderVideoOptions extends RenderCommonOptions {\n fps: number\n /** Output duration in seconds. */\n duration: number\n format: 'webm' | 'mp4'\n /** The page's audio producer (a program document's sound); absent = silent. */\n audioProducerCode?: string\n}\n\nexport interface RenderStillOptions extends RenderCommonOptions {\n /** Seek time for the captured frame, seconds. */\n time: number\n}\n\nexport interface RenderResult {\n bytes: Uint8Array\n mimeType: string\n /** Uncaught exceptions the page threw while it rendered (it may still have\n * written a frame, so a caller says them instead of hiding them). */\n pageErrors: string[]\n /** The engine's own '[vos] …' warnings: causes a picture cannot show. */\n engineNotes: string[]\n}\n\ninterface RenderComplete {\n success: boolean\n data?: string\n error?: string\n}\n\n/** What a captured still shows, measured from its pixels. */\nexport interface StillPicture {\n /** Every pixel has alpha 0: the frame is empty, whatever the preview showed. */\n transparent: boolean\n /** Every pixel is the same colour. */\n flat: boolean\n}\n\n/**\n * The sentences a still earns before anyone looks at it (pure). A fully\n * transparent frame is the one a custom blend or a cleared alpha leaves, and\n * it reads as black in most viewers while the live preview draws over its\n * page: say so, because nothing else will.\n */\nexport function stillWarnings(\n picture: StillPicture,\n pageErrors: readonly string[],\n engineNotes: readonly string[] = [],\n): string[] {\n const out: string[] = []\n if (picture.transparent) {\n out.push(\n 'the still is fully transparent (every pixel has alpha 0), though the preview may draw it: something wrote alpha 0, most often a custom material blending (blendDst / blendEquation) or a scene with no background. Give the scene a background or keep the destination alpha in the blend.',\n )\n } else if (picture.flat) {\n out.push(\n 'the still is a single flat colour: nothing drew at this time, or everything is hidden; check the time and the program for errors.',\n )\n }\n // The engine's own notes ('[vos] …') name a cause the picture cannot.\n for (const n of new Set(engineNotes)) out.push(n.replace(/^\\[vos\\]\\s*/, ''))\n for (const e of pageErrors.slice(0, 3)) out.push(`the page threw: ${e}`)\n if (pageErrors.length > 3)\n out.push(`the page threw ${pageErrors.length - 3} more errors`)\n return out\n}\n\nfunction compile(\n config: Record<string, unknown>,\n /** Bake these URLs as the program's `ctx.assets` defaults (a preview). */\n assets?: ProgramAssets | null,\n): string {\n if (!assets) return compileVosConfig(config as never, { tweenEngine: 'vos' })\n // The compiler asks per ref; the resolved table is per name, so walk the\n // manifest in the same order to answer.\n const byRef = new Map<string, string>()\n const manifest = (config.assets ?? {}) as Record<\n string,\n { ref: string | string[] }\n >\n for (const [name, decl] of Object.entries(manifest)) {\n const got = assets.assets[name]\n const refs = Array.isArray(decl.ref) ? decl.ref : [decl.ref]\n const urls = Array.isArray(got) ? got : [got]\n refs.forEach((ref, i) => {\n if (typeof urls[i] === 'string') byRef.set(`${name}\\u0000${ref}`, urls[i])\n })\n }\n return compileVosConfig(config as never, {\n tweenEngine: 'vos',\n resolveAssetRef: (ref, name) => byRef.get(`${name}\\u0000${ref}`) ?? ref,\n })\n}\n\n/** A page on the render origin reads a served file by its full URL. */\nfunction captureAssets(assets: ProgramAssets | null | undefined): {\n assets?: Record<string, string | string[]>\n} {\n if (!assets) return {}\n const absolute = (url: string) =>\n url.startsWith(ASSET_ROUTE) ? `${RENDER_ORIGIN}${url}` : url\n const out: Record<string, string | string[]> = {}\n for (const [name, url] of Object.entries(assets.assets)) {\n out[name] = Array.isArray(url) ? url.map(absolute) : absolute(url)\n }\n return { assets: out }\n}\n\nasync function runCapturePage(\n browser: Browser,\n html: string,\n opts: {\n width: number\n height: number\n timeoutMs: number\n /** Served path → file on disk (a program's declared files). */\n files?: Record<string, string>\n },\n): Promise<RenderComplete & { pageErrors: string[]; engineNotes: string[] }> {\n const context = await browser.newContext({\n viewport: { width: opts.width, height: opts.height },\n })\n const page: Page = await context.newPage()\n const errors: string[] = []\n const pageErrors: string[] = []\n const engineNotes: string[] = []\n page.on('console', (m) => {\n if (m.type() === 'error') errors.push(m.text())\n else if (m.type() === 'warning' && m.text().startsWith('[vos] '))\n engineNotes.push(m.text())\n })\n page.on('pageerror', (e) => {\n pageErrors.push(String(e.message || e))\n })\n try {\n await page.route(`${RENDER_ORIGIN}/**`, (route) =>\n route.fulfill({ status: 200, contentType: 'text/html', body: html }),\n )\n // The program's own files, on the page's origin. Registered after the\n // page route on purpose: the newest matching route answers first.\n const files = opts.files ?? {}\n if (Object.keys(files).length > 0) {\n await page.route(`${RENDER_ORIGIN}${ASSET_ROUTE}**`, async (route) => {\n const request = route.request()\n const file = files[new URL(request.url()).pathname]\n if (!file) {\n return route.fulfill({ status: 404, body: 'no such declared file' })\n }\n const answer = serveFile(file, await request.headerValue('range'))\n return route.fulfill(answer)\n })\n }\n await page.goto(`${RENDER_ORIGIN}/render`, {\n waitUntil: 'domcontentloaded',\n })\n const start = Date.now()\n for (;;) {\n const done = (await page.evaluate(\n 'window.__renderComplete ?? null',\n )) as RenderComplete | null\n if (done) return { ...done, pageErrors, engineNotes }\n if (Date.now() - start > opts.timeoutMs) {\n const all = [...pageErrors, ...errors]\n return {\n success: false,\n error: `render timed out after ${Math.round(opts.timeoutMs / 1000)}s${\n all.length ? ` (page errors: ${all.slice(0, 3).join(' | ')})` : ''\n }`,\n pageErrors,\n engineNotes,\n }\n }\n await new Promise((r) => setTimeout(r, 400))\n }\n } finally {\n await context.close()\n }\n}\n\nfunction decodeDataUrl(\n dataUrl: string,\n pageErrors: string[] = [],\n engineNotes: string[] = [],\n): RenderResult {\n const m = /^data:([^;,]+);base64,(.*)$/s.exec(dataUrl)\n if (!m) throw new Error('capture page returned an unexpected payload')\n return {\n bytes: Uint8Array.from(Buffer.from(m[2], 'base64')),\n mimeType: m[1],\n pageErrors,\n engineNotes,\n }\n}\n\n/** Render a vos config to a video (WebM/MP4) in a headless browser. */\nexport async function renderVideo(\n browser: Browser,\n opts: RenderVideoOptions,\n): Promise<RenderResult> {\n opts.onPhase?.('compile')\n const code = compile(opts.config)\n const html = generateRenderTemplate(code, {\n mode: 'capture-video',\n capture: {\n width: opts.width,\n height: opts.height,\n duration: opts.duration,\n fps: opts.fps,\n format: opts.format,\n ...(opts.audioProducerCode\n ? { audioProducerCode: opts.audioProducerCode }\n : {}),\n ...captureAssets(opts.assets),\n },\n elementsBundleCode,\n tweenEngine: 'vos',\n tweenBundleCode: tweenRuntimeCode,\n })\n opts.onPhase?.('render')\n // Generous ceiling: startup + CDN module fetch + ~4× realtime per frame batch.\n const timeoutMs = 90_000 + opts.duration * opts.fps * 400\n const done = await runCapturePage(browser, html, {\n width: opts.width,\n height: opts.height,\n timeoutMs,\n files: opts.assets?.files,\n })\n if (!done.success || !done.data)\n throw new Error(done.error ?? 'render failed')\n return decodeDataUrl(done.data, done.pageErrors, done.engineNotes)\n}\n\n/** Render a single frame of a vos config to an image in a headless browser. */\nexport async function renderStill(\n browser: Browser,\n opts: RenderStillOptions,\n): Promise<RenderResult> {\n opts.onPhase?.('compile')\n const code = compile(opts.config)\n const html = generateRenderTemplate(code, {\n mode: 'capture-thumbnail',\n capture: {\n width: opts.width,\n height: opts.height,\n duration: Math.max(1, opts.time + 1),\n fps: 30,\n thumbnailTime: opts.time,\n ...captureAssets(opts.assets),\n },\n elementsBundleCode,\n tweenEngine: 'vos',\n tweenBundleCode: tweenRuntimeCode,\n })\n opts.onPhase?.('render')\n const done = await runCapturePage(browser, html, {\n width: opts.width,\n height: opts.height,\n timeoutMs: 120_000,\n files: opts.assets?.files,\n })\n if (!done.success || !done.data)\n throw new Error(done.error ?? 'still render failed')\n return decodeDataUrl(done.data, done.pageErrors, done.engineNotes)\n}\n\n/**\n * Measure a captured still's pixels in a browser page (the canvas is the\n * decoder): whether every pixel is transparent, and whether it is one flat\n * colour. Sampled on a grid, so a large still stays cheap.\n */\nexport async function inspectStill(\n browser: Browser,\n webp: Uint8Array,\n): Promise<StillPicture> {\n const page = await browser.newPage()\n try {\n const src = `data:image/webp;base64,${Buffer.from(webp).toString('base64')}`\n return (await page.evaluate(\n `(async () => {\n const img = new Image()\n img.src = ${JSON.stringify(src)}\n await img.decode()\n const w = img.naturalWidth, h = img.naturalHeight\n const c = document.createElement('canvas')\n c.width = w\n c.height = h\n const g = c.getContext('2d', { willReadFrequently: true })\n g.drawImage(img, 0, 0)\n const d = g.getImageData(0, 0, w, h).data\n const step = Math.max(1, Math.floor(Math.sqrt((w * h) / 40000)))\n let transparent = true, flat = true, first = null\n for (let y = 0; y < h; y += step) {\n for (let x = 0; x < w; x += step) {\n const i = (y * w + x) * 4\n if (d[i + 3] !== 0) transparent = false\n const px = d[i] + ',' + d[i + 1] + ',' + d[i + 2] + ',' + d[i + 3]\n if (first === null) first = px\n else if (px !== first) flat = false\n }\n }\n return { transparent, flat }\n })()`,\n )) as StillPicture\n } finally {\n await page.close()\n }\n}\n\n/**\n * Re-encode a captured WebP still as PNG or JPEG in a browser page, so a\n * still named `.png` holds PNG bytes. The canvas is the encoder; nothing\n * else is installed for it.\n */\nexport async function reencodeStill(\n browser: Browser,\n webp: Uint8Array,\n format: 'png' | 'jpeg',\n): Promise<Uint8Array> {\n const page = await browser.newPage()\n try {\n const src = `data:image/webp;base64,${Buffer.from(webp).toString('base64')}`\n // A string body: a serialized function would carry the bundler's\n // helpers into a page that has none.\n const dataUrl = (await page.evaluate(\n `(async () => {\n const img = new Image()\n img.src = ${JSON.stringify(src)}\n await img.decode()\n const c = document.createElement('canvas')\n c.width = img.naturalWidth\n c.height = img.naturalHeight\n const g = c.getContext('2d')\n ${format === 'jpeg' ? \"g.fillStyle = '#fff'; g.fillRect(0, 0, c.width, c.height)\" : ''}\n g.drawImage(img, 0, 0)\n return c.toDataURL(${JSON.stringify(`image/${format}`)}, 0.92)\n })()`,\n )) as string\n return decodeDataUrl(dataUrl).bytes\n } finally {\n await page.close()\n }\n}\n\nexport interface PreviewPages {\n /** Host page: iframes the player and drives it over the bridge. */\n hostHtml: string\n /** The engine's playback-mode player (waits for a LOAD postMessage). */\n playerHtml: string\n}\n\n/**\n * Pages for `vos preview`. The playback template is the iframe HALF of the\n * player bridge — it renders nothing until a host posts `LOAD`, so the CLI\n * serves a minimal host page that sends `LOAD { code, autoplay }` and shows\n * a transport line (time / duration, click to play-pause).\n */\nexport function previewPages(\n config: Record<string, unknown>,\n /** Declared files, served by the preview server under `ASSET_ROUTE`. */\n assets?: ProgramAssets | null,\n): PreviewPages {\n const code = compile(config, assets)\n const playerHtml = generateRenderTemplate(code, {\n mode: 'playback',\n elementsBundleCode,\n tweenEngine: 'vos',\n tweenBundleCode: tweenRuntimeCode,\n })\n const codeJson = JSON.stringify(code).replace(/<\\//g, '<\\\\/')\n // A program that declares its size plays letterboxed at that aspect, the\n // frame it was designed for; one that declares none fills the window.\n const size = programSize(config)\n const frameCss = size\n ? `iframe{position:absolute;inset:0;margin:auto;border:0;width:min(100vw,calc(100vh * ${size.width} / ${size.height}));height:min(100vh,calc(100vw * ${size.height} / ${size.width}))}`\n : 'iframe{position:absolute;inset:0;width:100%;height:100%;border:0}'\n const hostHtml = `<!doctype html><html><head><meta charset=\"utf-8\"><title>vos preview</title>\n<style>\n html,body{margin:0;height:100%;background:#000;overflow:hidden}\n ${frameCss}\n #cover{position:fixed;inset:0;cursor:pointer}\n #hud{position:fixed;left:12px;bottom:10px;color:#fff;opacity:.75;font:12px/1.4 ui-monospace,monospace;\n background:rgba(0,0,0,.45);padding:4px 8px;border-radius:6px;pointer-events:none}\n</style></head><body>\n<iframe id=\"p\" src=\"/player\" allow=\"autoplay\"></iframe>\n<div id=\"cover\"></div>\n<div id=\"hud\">loading…</div>\n<script>\n const code = ${codeJson}\n const frame = document.getElementById('p')\n const hud = document.getElementById('hud')\n let ready = false\n let playing = true\n const post = (msg) => frame.contentWindow && frame.contentWindow.postMessage(msg, '*')\n const load = () => post({ type: 'LOAD', code, autoplay: true })\n window.addEventListener('message', (e) => {\n const msg = e.data || {}\n if (msg.type === 'BRIDGE_READY') load()\n if (msg.type === 'READY') { ready = true; hud.textContent = '0.0 / ' + msg.duration.toFixed(1) + 's — click to pause' }\n if (msg.type === 'UPDATE') hud.textContent = msg.time.toFixed(1) + ' / ' + msg.duration.toFixed(1) + 's — click to ' + (playing ? 'pause' : 'play')\n if (msg.type === 'ERROR') hud.textContent = 'error: ' + msg.error\n })\n // Belt and braces: if BRIDGE_READY raced the host, retry LOAD until READY.\n let tries = 0\n const iv = setInterval(() => {\n if (ready || tries++ > 20) return clearInterval(iv)\n load()\n }, 400)\n // The iframe swallows clicks — capture them on an overlay above it.\n document.getElementById('cover').addEventListener('click', () => {\n if (!ready) return\n playing = !playing\n post({ type: playing ? 'PLAY' : 'PAUSE' })\n hud.textContent = hud.textContent.replace(/click to (pause|play)/, 'click to ' + (playing ? 'pause' : 'play'))\n })\n</script></body></html>`\n return { hostHtml, playerHtml }\n}\n","/**\n * What the output is, decided from what the person asked for.\n *\n * Pure, so the engine verbs (a program) and the take verbs agree: a file\n * named `out.mp4` IS an mp4, an explicit `--format` that contradicts the\n * name is refused instead of writing one container under the other's name,\n * and a still named `.png` is a PNG.\n */\nimport { UsageError } from './args'\n\nexport type VideoFormat = 'webm' | 'mp4'\nexport type StillFormat = 'webp' | 'png' | 'jpeg'\n\nfunction extOf(path: string | undefined): string {\n return /\\.([a-z0-9]+)$/i.exec(path ?? '')?.[1]?.toLowerCase() ?? ''\n}\n\n/** The video container: the flag, else the output's name, else WebM. */\nexport function videoFormat(\n flag: string | undefined,\n out: string | undefined,\n): VideoFormat {\n const named = extOf(out)\n const fromName: VideoFormat | null =\n named === 'mp4' ? 'mp4' : named === 'webm' ? 'webm' : null\n if (flag !== undefined) {\n if (flag !== 'webm' && flag !== 'mp4')\n throw new UsageError('--format must be webm or mp4')\n if (fromName && fromName !== flag)\n throw new UsageError(\n `--format ${flag} contradicts the output name ${out}: name it .${flag}, or drop --format and the name decides`,\n )\n return flag\n }\n return fromName ?? 'webm'\n}\n\n/** The still's encoding, from its name. The engine captures WebP. */\nexport function stillFormat(out: string): StillFormat {\n const ext = extOf(out)\n if (ext === 'png') return 'png'\n if (ext === 'jpg' || ext === 'jpeg') return 'jpeg'\n if (ext === 'webp' || ext === '') return 'webp'\n throw new UsageError(\n `vos still writes .webp, .png or .jpg, not .${ext}: rename ${out}`,\n )\n}\n\n/**\n * `--times 0,1.5,50%,100%`: seconds or percentages of the duration, in the\n * order given. 100% is clamped a hair inside the end, where the last frame is.\n */\nexport function parseTimes(raw: string, duration: number): number[] {\n const times = raw\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean)\n .map((s) => {\n const pct = /^(\\d+(?:\\.\\d+)?)%$/.exec(s)\n const t = pct ? (Number(pct[1]) / 100) * duration : Number(s)\n if (!Number.isFinite(t) || t < 0)\n throw new UsageError(\n `--times expects seconds or percentages (0,1.5,50%), got \"${s}\"`,\n )\n return Math.min(t, Math.max(0, duration - 1 / 60))\n })\n if (!times.length) throw new UsageError('--times needs at least one time')\n return times\n}\n\n/** Where the still for one time of several goes: `name-1.50s.ext`. */\nexport function stillOutFor(out: string, time: number, many: boolean): string {\n if (!many) return out\n const m = /^(.*?)(\\.[a-z0-9]+)?$/i.exec(out)\n return `${m?.[1] ?? out}-${time.toFixed(2)}s${m?.[2] ?? ''}`\n}\n\n/** Every `--set` value in argv, in order (the parser keeps only the last). */\nexport function setFlags(argv: string[]): string[] {\n const out: string[] = []\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i]\n if (a === '--set' && argv[i + 1] !== undefined) out.push(argv[++i])\n else if (a.startsWith('--set=')) out.push(a.slice('--set='.length))\n }\n return out\n}\n\n/**\n * `--set data.<key>=<value>` on a PROGRAM: the knob-honesty check without a\n * second config. The value reads as JSON when it parses (numbers, booleans,\n * arrays) and as a string otherwise. Patched in memory, never written back.\n */\nexport function applyDataSets(\n config: Record<string, unknown>,\n sets: string[],\n): Record<string, unknown> {\n if (!sets.length) return config\n const data: Record<string, unknown> = {\n ...((config.data as Record<string, unknown> | undefined) ?? {}),\n }\n for (const set of sets) {\n const eq = set.indexOf('=')\n const path = eq === -1 ? set : set.slice(0, eq)\n const m = /^data\\.([A-Za-z0-9_$-]+)$/.exec(path)\n if (eq === -1 || !m)\n throw new UsageError(\n `--set on a program takes data.<key>=<value> (a knob's value), got \"${set}\"`,\n )\n const raw = set.slice(eq + 1)\n let value: unknown = raw\n try {\n value = JSON.parse(raw)\n } catch {\n // a bare word is a string: --set data.name=ROBIN\n }\n data[m[1]] = value\n }\n return { ...config, data }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY,cAAc,gBAAgB;AACnD,SAAS,UAAU,SAAS,YAAY;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAkBA,SAAS,cAAc,QAA+B;AAC3D,MAAI;AACF,QAAI,CAAC,SAAS,MAAM,EAAE,YAAY,EAAG,QAAO;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACA,QAAM,UAAU,KAAK,QAAQ,UAAU;AACvC,MAAI,WAAW,OAAO,GAAG;AACvB,QAAI;AACF,YAAM,MAAe,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;AAC7D,UAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,YAAY;AACzD,eAAO;AAAA,IACX,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,WAAW,KAAK,QAAQ,aAAa,CAAC,IAAI,YAAY;AAC/D;AAGA,SAAS,cAAc,KAAsB;AAC3C,QAAM,UAAU,KAAK,KAAK,UAAU;AACpC,MAAI,CAAC,WAAW,OAAO,EAAG,QAAO;AACjC,MAAI;AACF,UAAM,MAAe,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;AAC7D,WAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,EAAE,YAAY;AAAA,EAClE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQA,eAAsB,qBACpB,KACA,UACkB;AAClB,QAAM,SAAkB,KAAK;AAAA,IAC3B,MAA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