@hyperframes/studio-server 0.8.143 → 0.8.145

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.
@@ -229,37 +229,74 @@ function getCanonicalProxyCachePath(source, variant, box) {
229
229
  `${key}${PROXY_VARIANT_CONFIG[variant].extension}`
230
230
  );
231
231
  }
232
- function getProxyCachePath(projectDir, absoluteSourcePath, variant = "h264") {
232
+ function getProxyCachePath(projectDir, absoluteSourcePath, variant = "h264", box) {
233
233
  return getCanonicalProxyCachePath(
234
234
  canonicalizeProxySource(projectDir, absoluteSourcePath),
235
- variant
235
+ variant,
236
+ box
236
237
  );
237
238
  }
239
+ var ProxyDroppedError = class extends ProxyTranscodeError {
240
+ constructor() {
241
+ super("media proxy copy dropped: every caller left before it started", null, "");
242
+ this.name = "ProxyDroppedError";
243
+ }
244
+ };
238
245
  var activeTranscodes = 0;
239
246
  var waitQueue = [];
240
- function acquireSlot() {
247
+ function enqueue(job) {
248
+ const firstNormal = job.priority ? waitQueue.findIndex((queued) => !queued.priority) : -1;
249
+ if (firstNormal === -1) waitQueue.push(job);
250
+ else waitQueue.splice(firstNormal, 0, job);
251
+ }
252
+ function dequeue(job) {
253
+ const index = waitQueue.indexOf(job);
254
+ if (index !== -1) waitQueue.splice(index, 1);
255
+ }
256
+ function acquireSlot(job) {
257
+ if (activeTranscodes < MAX_CONCURRENT_TRANSCODES) {
258
+ activeTranscodes++;
259
+ return Promise.resolve();
260
+ }
241
261
  return new Promise((resolveSlot, reject) => {
242
- const tryAcquire = () => {
243
- if (activeTranscodes < MAX_CONCURRENT_TRANSCODES) {
262
+ job.queued = {
263
+ start: () => {
264
+ job.queued = void 0;
244
265
  activeTranscodes++;
245
266
  resolveSlot();
246
- } else {
247
- if (waitQueue.length >= MAX_QUEUED_TRANSCODES) {
248
- reject(new ProxyCapacityError());
249
- return;
250
- }
251
- waitQueue.push(tryAcquire);
267
+ },
268
+ drop: () => {
269
+ job.queued = void 0;
270
+ dequeue(job);
271
+ forget(job);
272
+ reject(new ProxyDroppedError());
252
273
  }
253
274
  };
254
- tryAcquire();
275
+ enqueue(job);
255
276
  });
256
277
  }
278
+ function queueIsFull() {
279
+ return activeTranscodes >= MAX_CONCURRENT_TRANSCODES && waitQueue.length >= MAX_QUEUED_TRANSCODES;
280
+ }
257
281
  function releaseSlot() {
258
282
  activeTranscodes--;
259
- const next = waitQueue.shift();
260
- if (next) next();
283
+ waitQueue.shift()?.queued?.start();
284
+ }
285
+ function prioritize(job) {
286
+ if (job.priority) return;
287
+ job.priority = true;
288
+ if (!job.queued) return;
289
+ dequeue(job);
290
+ enqueue(job);
291
+ }
292
+ function leave(job) {
293
+ job.callers--;
294
+ if (job.callers === 0) job.queued?.drop();
261
295
  }
262
296
  var inFlight = /* @__PURE__ */ new Map();
297
+ function forget(job) {
298
+ if (inFlight.get(job.cachePath)?.job === job) inFlight.delete(job.cachePath);
299
+ }
263
300
  function maintainProxyCache(cacheDir) {
264
301
  try {
265
302
  cleanupProxyCache(cacheDir, { protectedPaths: new Set(inFlight.keys()) });
@@ -421,8 +458,8 @@ async function runFfmpeg(sourcePath, outputPath, variant, box) {
421
458
  });
422
459
  });
423
460
  }
424
- async function transcodeToCache(projectDir, absoluteSourcePath, cachePath, variant, box) {
425
- await acquireSlot();
461
+ async function transcodeToCache(job, projectDir, absoluteSourcePath, cachePath, variant, box) {
462
+ await acquireSlot(job);
426
463
  try {
427
464
  if (existsSync2(cachePath)) return cachePath;
428
465
  const cacheDir = dirname(cachePath);
@@ -440,14 +477,15 @@ async function transcodeToCache(projectDir, absoluteSourcePath, cachePath, varia
440
477
  releaseSlot();
441
478
  }
442
479
  }
443
- var settledProxyCount = 0;
480
+ var proxyActivity = 0;
444
481
  function proxyActivityMark(projectDir) {
445
- if (!existsSync2(projectDir)) return String(settledProxyCount);
482
+ if (!existsSync2(projectDir)) return String(proxyActivity);
446
483
  const cacheDir = join2(realpath(projectDir), CACHE_DIR_NAME) + sep;
447
484
  for (const cachePath of inFlight.keys()) if (cachePath.startsWith(cacheDir)) return null;
448
- return String(settledProxyCount);
485
+ return String(proxyActivity);
449
486
  }
450
- async function resolveProxy(projectDir, absoluteSourcePath, variant = "h264", box) {
487
+ async function resolveProxy(projectDir, absoluteSourcePath, variant = "h264", box, options = {}) {
488
+ options.signal?.throwIfAborted();
451
489
  const source = canonicalizeProxySource(projectDir, absoluteSourcePath);
452
490
  const cachePath = getCanonicalProxyCachePath(source, variant, box);
453
491
  if (existsSync2(cachePath)) {
@@ -460,17 +498,48 @@ async function resolveProxy(projectDir, absoluteSourcePath, variant = "h264", bo
460
498
  if (rememberedFailure.expiresAt > Date.now()) throw rememberedFailure.error;
461
499
  failedTranscodes.delete(cachePath);
462
500
  }
463
- const existing = inFlight.get(cachePath);
464
- if (existing) return existing;
465
- const promise = transcodeToCache(source.projectDir, source.sourcePath, cachePath, variant, box).catch((err) => {
466
- if (!(err instanceof ProxyCapacityError)) rememberFailure(cachePath, err);
467
- throw err;
468
- }).finally(() => {
469
- inFlight.delete(cachePath);
470
- settledProxyCount += 1;
501
+ let entry = inFlight.get(cachePath);
502
+ if (!entry) {
503
+ if (!options.priority && queueIsFull()) {
504
+ proxyActivity += 1;
505
+ throw new ProxyCapacityError();
506
+ }
507
+ const job = {
508
+ cachePath,
509
+ priority: options.priority === true,
510
+ callers: 0
511
+ };
512
+ const promise = transcodeToCache(
513
+ job,
514
+ source.projectDir,
515
+ source.sourcePath,
516
+ cachePath,
517
+ variant,
518
+ box
519
+ ).catch((err) => {
520
+ if (!(err instanceof ProxyDroppedError)) rememberFailure(cachePath, err);
521
+ throw err;
522
+ }).finally(() => {
523
+ forget(job);
524
+ proxyActivity += 1;
525
+ });
526
+ entry = { promise, job };
527
+ inFlight.set(cachePath, entry);
528
+ }
529
+ if (options.priority) prioritize(entry.job);
530
+ return joinJob(entry.promise, entry.job, options.signal);
531
+ }
532
+ function joinJob(promise, job, signal) {
533
+ job.callers++;
534
+ if (!signal) return promise;
535
+ return new Promise((resolveJoin, rejectJoin) => {
536
+ const onAbort = () => {
537
+ leave(job);
538
+ rejectJoin(signal.reason);
539
+ };
540
+ signal.addEventListener("abort", onAbort, { once: true });
541
+ promise.finally(() => signal.removeEventListener("abort", onAbort)).then(resolveJoin, rejectJoin);
471
542
  });
472
- inFlight.set(cachePath, promise);
473
- return promise;
474
543
  }
475
544
 
476
545
  export {
@@ -491,4 +560,4 @@ export {
491
560
  proxyActivityMark,
492
561
  resolveProxy
493
562
  };
494
- //# sourceMappingURL=chunk-6EFY2WPN.js.map
563
+ //# sourceMappingURL=chunk-2VZGTTEG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/proxyTranscoder.ts","../src/helpers/proxyCache.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { existsSync, renameSync, statSync, unlinkSync, utimesSync } from \"node:fs\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport {\n formatPreviewProxyBox,\n hdrToSdrToneMapFilter,\n type PreviewProxyBox,\n} from \"@hyperframes/core\";\nimport { findFfBinary } from \"@hyperframes/parsers/ff-binaries\";\nimport { probeFirstFrameColour, probeMediaMetadata } from \"./mediaMetadata.js\";\nimport { cleanupProxyCache } from \"./proxyCache.js\";\nimport { PROXY_VARIANT_CONFIG, type ProxyVariant } from \"./mediaCodecMap.js\";\nimport { mkdirWithinProject, realpath, realProjectRoot } from \"./safePath.js\";\n\n/**\n * Transcodes browser-hostile local video sources (HEVC, ProRes, ...) into a\n * cached, seekable authoring proxy. Consumed by the preview/play/static\n * project routes (U3/U4) to serve a `?hf-proxy=` request; never used on\n * the render path (render always sees the original file).\n *\n * A started ffmpeg child is never killed for one caller: every caller of a cache\n * key shares it (in-flight dedupe below). A caller's `signal` only detaches that\n * caller, and drops the copy while it is still queued with no caller left.\n */\n\nexport const PROXY_PARAMS_VERSION = \"v5\";\n\nexport const CACHE_DIR_NAME = \".transcode-cache\";\n\nfunction boundedEnvInteger(name: string, fallback: number, min: number, max: number): number {\n const raw = process.env[name]?.trim();\n if (!raw) return fallback;\n const parsed = Number(raw);\n return Number.isSafeInteger(parsed) && parsed >= min && parsed <= max ? parsed : fallback;\n}\n\n// ffmpeg is internally multithreaded, so two concurrent proxy encodes already\n// saturate a typical laptop. Operators of shared/large machines may tune the\n// bounded values without patching the package; invalid values fail safe.\nconst MAX_CONCURRENT_TRANSCODES = boundedEnvInteger(\"HYPERFRAMES_PROXY_MAX_CONCURRENCY\", 2, 1, 16);\nconst MAX_QUEUED_TRANSCODES = boundedEnvInteger(\"HYPERFRAMES_PROXY_MAX_QUEUE\", 8, 0, 256);\n\nconst STDERR_TAIL_MAX_CHARS = 4000;\nexport const TRANSCODE_TIMEOUT_MS = 15 * 60 * 1000;\nconst FAILURE_CACHE_TTL_MS = 60 * 1000;\nexport const PROXY_PENDING_RETRY_AFTER_SECONDS = 2;\nconst ENVIRONMENT_FAILURE_TTL_MS = 5 * PROXY_PENDING_RETRY_AFTER_SECONDS * 1000;\nconst MAX_FAILURE_CACHE_ENTRIES = 128;\nexport const DEFAULT_PROXY_WAIT_TIMEOUT_MS = 2 * 60 * 1000;\n\nexport class ProxyTranscodeError extends Error {\n readonly exitCode: number | null;\n readonly stderrTail: string;\n\n constructor(message: string, exitCode: number | null, stderrTail: string) {\n super(message);\n this.name = \"ProxyTranscodeError\";\n this.exitCode = exitCode;\n this.stderrTail = stderrTail;\n }\n}\n\n/** \"ffmpeg isn't installed\" — an environment condition, not a per-source\n * failure, so the negative cache below keeps it only briefly\n * (installing ffmpeg mid-session must recover without a server restart). */\nclass FfmpegUnavailableError extends ProxyTranscodeError {\n constructor() {\n super(\"ffmpeg binary not found\", null, \"\");\n }\n}\n\nexport class FfmpegMissingFilterError extends ProxyTranscodeError {\n constructor() {\n super(\n \"HDR proxying requires ffmpeg zscale/tonemap filters (libzimg); install an ffmpeg build with libzimg support\",\n null,\n \"\",\n );\n this.name = \"FfmpegMissingFilterError\";\n }\n}\n\nexport class ProxyCapacityError extends ProxyTranscodeError {\n constructor() {\n super(\"media proxy queue is full; retry shortly\", null, \"\");\n this.name = \"ProxyCapacityError\";\n }\n}\n\nexport class ProxySourceOutsideProjectError extends ProxyTranscodeError {\n constructor() {\n super(\"media proxy source must be addressed through the project\", null, \"\");\n this.name = \"ProxySourceOutsideProjectError\";\n }\n}\n\nexport class ProxyWaitTimeoutError extends ProxyTranscodeError {\n constructor(timeoutMs: number) {\n super(`media proxy did not become ready within ${timeoutMs}ms`, null, \"\");\n this.name = \"ProxyWaitTimeoutError\";\n }\n}\n\n/** Bounds one caller's wait without cancelling the shared in-flight ffmpeg\n * job. Other preview/publish callers still receive the completed cache entry. */\nexport async function waitForProxy<T>(\n promise: Promise<T>,\n timeoutMs = DEFAULT_PROXY_WAIT_TIMEOUT_MS,\n): Promise<T> {\n let timer: NodeJS.Timeout | undefined;\n try {\n return await Promise.race([\n promise,\n new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => reject(new ProxyWaitTimeoutError(timeoutMs)), timeoutMs);\n timer.unref();\n }),\n ]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n\n/**\n * Cache key inputs per the plan: project-relative source path (portable across\n * checkouts), canonical source identity (so retargeted external symlinks do\n * not reuse a proxy), mtime and file size (mtime alone can collide on\n * same-second re-exports on coarse-timestamp filesystems; size catches nearly\n * all such cases at zero cost), and a params version token so changing the\n * ffmpeg recipe below invalidates every cached proxy cleanly.\n */\ntype CanonicalProxySource = {\n projectDir: string;\n sourcePath: string;\n relativePath: string;\n cacheIdentity: string;\n};\n\nfunction canonicalizeProxySource(\n projectDir: string,\n absoluteSourcePath: string,\n): CanonicalProxySource {\n const requestedProjectDir = resolve(projectDir);\n const requestedSourcePath = resolve(absoluteSourcePath);\n const requestedRelativePath = relative(requestedProjectDir, requestedSourcePath);\n if (\n requestedRelativePath === \"..\" ||\n requestedRelativePath.startsWith(`..${sep}`) ||\n isAbsolute(requestedRelativePath)\n ) {\n throw new ProxySourceOutsideProjectError();\n }\n\n const canonicalProjectDir = realProjectRoot(projectDir);\n const canonicalSourcePath = realpath(absoluteSourcePath);\n const canonicalRelativePath = relative(canonicalProjectDir, canonicalSourcePath);\n const sourceIsInsideCanonicalProject =\n canonicalRelativePath !== \"..\" &&\n !canonicalRelativePath.startsWith(`..${sep}`) &&\n !isAbsolute(canonicalRelativePath);\n return {\n projectDir: canonicalProjectDir,\n sourcePath: canonicalSourcePath,\n relativePath: requestedRelativePath.normalize(\"NFC\"),\n // An external target needs a stable identity in addition to its project-local\n // symlink path, otherwise retargeting the link can reuse an unrelated proxy.\n cacheIdentity: (sourceIsInsideCanonicalProject\n ? canonicalRelativePath\n : canonicalSourcePath\n ).normalize(\"NFC\"),\n };\n}\n\nfunction buildProxyCacheKey(\n source: CanonicalProxySource,\n variant: ProxyVariant,\n box: PreviewProxyBox | undefined,\n): string {\n const stat = statSync(source.sourcePath);\n const size = box ? `\\0${formatPreviewProxyBox(box)}` : \"\";\n return createHash(\"sha256\")\n .update(\n `${source.relativePath}\\0${source.cacheIdentity}\\0${stat.mtimeMs}\\0${stat.size}\\0${PROXY_PARAMS_VERSION}\\0${variant}${size}`,\n )\n .digest(\"hex\");\n}\n\nfunction getCanonicalProxyCachePath(\n source: CanonicalProxySource,\n variant: ProxyVariant,\n box?: PreviewProxyBox,\n): string {\n const key = buildProxyCacheKey(source, variant, box);\n return join(\n source.projectDir,\n CACHE_DIR_NAME,\n `${key}${PROXY_VARIANT_CONFIG[variant].extension}`,\n );\n}\n\n/**\n * Computes the absolute path a proxy for this source would live at, without\n * transcoding anything, so a host can check cache state. Pass the request's\n * preview box (`hf-proxy-box`) to name a boxed copy.\n */\nexport function getProxyCachePath(\n projectDir: string,\n absoluteSourcePath: string,\n variant: ProxyVariant = \"h264\",\n box?: PreviewProxyBox,\n): string {\n return getCanonicalProxyCachePath(\n canonicalizeProxySource(projectDir, absoluteSourcePath),\n variant,\n box,\n );\n}\n\n// --- global concurrency limiter -------------------------------------------\n// ponytail: a counter + one wait queue is the whole semaphore. Priority copies\n// queue ahead of the rest and are never refused for a full queue, so a few\n// priority asks (the copy a viewer is waiting on) can exceed the cap.\n\n/** One copy per cache key, shared by every caller asking for it. */\ninterface ProxyJob {\n cachePath: string;\n priority: boolean;\n /** Callers still waiting; one without a signal never leaves, so its copy is always made. */\n callers: number;\n /** Set while the job waits for a slot. */\n queued?: { start: () => void; drop: () => void };\n}\n\nclass ProxyDroppedError extends ProxyTranscodeError {\n constructor() {\n super(\"media proxy copy dropped: every caller left before it started\", null, \"\");\n this.name = \"ProxyDroppedError\";\n }\n}\n\nlet activeTranscodes = 0;\nconst waitQueue: ProxyJob[] = [];\n\nfunction enqueue(job: ProxyJob): void {\n const firstNormal = job.priority ? waitQueue.findIndex((queued) => !queued.priority) : -1;\n if (firstNormal === -1) waitQueue.push(job);\n else waitQueue.splice(firstNormal, 0, job);\n}\n\nfunction dequeue(job: ProxyJob): void {\n const index = waitQueue.indexOf(job);\n if (index !== -1) waitQueue.splice(index, 1);\n}\n\nfunction acquireSlot(job: ProxyJob): Promise<void> {\n if (activeTranscodes < MAX_CONCURRENT_TRANSCODES) {\n activeTranscodes++;\n return Promise.resolve();\n }\n return new Promise((resolveSlot, reject) => {\n job.queued = {\n start: () => {\n job.queued = undefined;\n activeTranscodes++;\n resolveSlot();\n },\n drop: () => {\n job.queued = undefined;\n dequeue(job);\n forget(job);\n reject(new ProxyDroppedError());\n },\n };\n enqueue(job);\n });\n}\n\nfunction queueIsFull(): boolean {\n return activeTranscodes >= MAX_CONCURRENT_TRANSCODES && waitQueue.length >= MAX_QUEUED_TRANSCODES;\n}\n\nfunction releaseSlot(): void {\n activeTranscodes--;\n waitQueue.shift()?.queued?.start();\n}\n\nfunction prioritize(job: ProxyJob): void {\n if (job.priority) return;\n job.priority = true;\n if (!job.queued) return;\n dequeue(job);\n enqueue(job);\n}\n\nfunction leave(job: ProxyJob): void {\n job.callers--;\n if (job.callers === 0) job.queued?.drop();\n}\n\n// --- per-key in-flight dedupe ----------------------------------------------\n\nconst inFlight = new Map<string, { promise: Promise<string>; job: ProxyJob }>();\n\nfunction forget(job: ProxyJob): void {\n if (inFlight.get(job.cachePath)?.job === job) inFlight.delete(job.cachePath);\n}\n\nfunction maintainProxyCache(cacheDir: string): void {\n try {\n cleanupProxyCache(cacheDir, { protectedPaths: new Set(inFlight.keys()) });\n } catch (error) {\n // Cache maintenance must never turn a playable preview into an error.\n console.warn(\n `[media-proxy] cache cleanup failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n\nfunction markCacheEntryUsed(cachePath: string): void {\n try {\n const now = new Date();\n utimesSync(cachePath, now, now);\n } catch {\n // A concurrent cleanup may have removed a stale entry after existsSync;\n // the normal miss path below will recreate it on the next request.\n }\n}\n\n// --- negative cache ---------------------------------------------------------\n// A source that failed to transcode fails again identically until the file\n// changes (the cache key embeds mtime+size, so a re-export invalidates this\n// naturally). Remembering the failure per key means repeated `?hf-proxy=`\n// requests for a broken asset rethrow instantly instead of respawning ffmpeg\n// on every retry the browser makes.\ninterface RememberedFailure {\n error: unknown;\n expiresAt: number;\n}\n\nconst failedTranscodes = new Map<string, RememberedFailure>();\n\nlet hdrFilterCheck: { ffmpegPath: string; promise: Promise<void> } | undefined;\n\nfunction ensureHdrFilters(ffmpegPath: string): Promise<void> {\n if (hdrFilterCheck?.ffmpegPath === ffmpegPath) return hdrFilterCheck.promise;\n const promise = new Promise<void>((resolveCheck, rejectCheck) => {\n const proc = spawn(ffmpegPath, [\"-hide_banner\", \"-filters\"], {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n });\n let stdout = \"\";\n proc.stdout?.on(\"data\", (chunk: Buffer) => {\n stdout += chunk.toString();\n });\n proc.on(\"error\", () => rejectCheck(new FfmpegMissingFilterError()));\n proc.on(\"close\", (code) => {\n if (code !== 0 || !/\\bzscale\\b/.test(stdout) || !/\\btonemap\\b/.test(stdout)) {\n rejectCheck(new FfmpegMissingFilterError());\n } else {\n resolveCheck();\n }\n });\n });\n hdrFilterCheck = { ffmpegPath, promise };\n return promise;\n}\n\nfunction rememberFailure(cachePath: string, error: unknown): void {\n const ttlMs =\n error instanceof FfmpegUnavailableError || error instanceof FfmpegMissingFilterError\n ? ENVIRONMENT_FAILURE_TTL_MS\n : FAILURE_CACHE_TTL_MS;\n failedTranscodes.delete(cachePath);\n failedTranscodes.set(cachePath, { error, expiresAt: Date.now() + ttlMs });\n while (failedTranscodes.size > MAX_FAILURE_CACHE_ENTRIES) {\n const oldest = failedTranscodes.keys().next().value;\n if (oldest === undefined) break;\n failedTranscodes.delete(oldest);\n }\n}\n\n/** Test hook: forget remembered transcode failures (module state persists\n * across tests that don't reload the module). */\nexport function clearFailedTranscodesForTest(): void {\n failedTranscodes.clear();\n}\n\n/** Even dimensions; with a box, the source shrinks until its tighter side fills the box, never grows. */\nfunction proxyScaleFilter(box?: PreviewProxyBox): string {\n if (!box) return \"scale=trunc(iw/2)*2:trunc(ih/2)*2\";\n const factor = `min(1\\\\,max(${box.width}/iw\\\\,${box.height}/ih))`;\n const side = (d: string) => `min(trunc(${d}/2)*2\\\\,ceil(${d}*${factor}/2)*2)`;\n return `scale=${side(\"iw\")}:${side(\"ih\")}`;\n}\n\nasync function runFfmpeg(\n sourcePath: string,\n outputPath: string,\n variant: ProxyVariant,\n box: PreviewProxyBox | undefined,\n): Promise<void> {\n const metadata = await probeMediaMetadata(sourcePath);\n const ffmpegPath = findFfBinary(\"ffmpeg\", { configuredMustExist: true });\n if (!ffmpegPath) {\n throw new FfmpegUnavailableError();\n }\n const keepsAlpha = variant === \"vp8\";\n const { hdrTransfer } = metadata.color;\n const toneMap = (hdrTransfer === \"pq\" || hdrTransfer === \"hlg\") && !keepsAlpha;\n if (toneMap) await ensureHdrFilters(ffmpegPath);\n const firstFrame = toneMap ? await probeFirstFrameColour(sourcePath) : {};\n const evenScale = proxyScaleFilter(box);\n const pixelFormat = keepsAlpha ? \"yuva420p\" : \"yuv420p\";\n // The tone map ends in RGB; older ffmpeg (seen on 5.1) converts it with BT.601 unless the matrix is named.\n const videoFilter = toneMap\n ? [\n hdrToSdrToneMapFilter(metadata.color, firstFrame),\n `${evenScale}:out_color_matrix=bt709:out_range=tv`,\n `format=${pixelFormat}`,\n ].join(\",\")\n : [evenScale, `format=${pixelFormat}`].join(\",\");\n\n return new Promise((resolvePromise, reject) => {\n const commonArgs = [\"-y\", \"-i\", sourcePath, \"-vf\", videoFilter];\n const h264Args = [\n \"-c:v\",\n \"libx264\",\n \"-profile:v\",\n \"high\",\n \"-pix_fmt\",\n \"yuv420p\",\n \"-colorspace\",\n \"bt709\",\n \"-color_primaries\",\n \"bt709\",\n \"-color_trc\",\n \"bt709\",\n \"-crf\",\n \"18\",\n \"-preset\",\n \"veryfast\",\n \"-c:a\",\n \"aac\",\n \"-movflags\",\n \"+faststart\",\n ];\n const vp8Args = [\n \"-c:v\",\n \"libvpx\",\n \"-b:v\",\n \"0\",\n \"-crf\",\n \"23\",\n \"-deadline\",\n \"good\",\n \"-pix_fmt\",\n \"yuva420p\",\n \"-colorspace\",\n \"bt709\",\n \"-color_primaries\",\n \"bt709\",\n \"-color_trc\",\n \"bt709\",\n \"-cpu-used\",\n \"4\",\n \"-auto-alt-ref\",\n \"0\",\n \"-metadata:s:v:0\",\n \"alpha_mode=1\",\n \"-ac\",\n \"2\",\n \"-c:a\",\n \"libopus\",\n ];\n const args = [...commonArgs, ...(variant === \"vp8\" ? vp8Args : h264Args), outputPath];\n\n // Hard ceiling so a hung ffmpeg can never permanently occupy one of the\n // global transcode slots: the child is killed and the slot released via\n // the caller's finally. Generous because long assets transcode at\n // roughly real time; a healthy encode of any authoring asset fits.\n const proc = spawn(ffmpegPath, args, {\n stdio: [\"ignore\", \"ignore\", \"pipe\"],\n timeout: TRANSCODE_TIMEOUT_MS,\n killSignal: \"SIGKILL\",\n windowsHide: true,\n });\n let stderrTail = \"\";\n proc.stderr?.on(\"data\", (chunk: Buffer) => {\n stderrTail = (stderrTail + chunk.toString()).slice(-STDERR_TAIL_MAX_CHARS);\n });\n proc.on(\"error\", (err) => {\n reject(new ProxyTranscodeError(`failed to spawn ffmpeg: ${err.message}`, null, stderrTail));\n });\n proc.on(\"close\", (code, signal) => {\n if (code === 0) {\n resolvePromise();\n } else if (signal) {\n reject(\n new ProxyTranscodeError(\n `ffmpeg killed by ${signal} (timeout ${TRANSCODE_TIMEOUT_MS}ms or external kill)`,\n null,\n stderrTail,\n ),\n );\n } else {\n reject(new ProxyTranscodeError(`ffmpeg exited with code ${code}`, code, stderrTail));\n }\n });\n });\n}\n\nasync function transcodeToCache(\n job: ProxyJob,\n projectDir: string,\n absoluteSourcePath: string,\n cachePath: string,\n variant: ProxyVariant,\n box: PreviewProxyBox | undefined,\n): Promise<string> {\n await acquireSlot(job);\n try {\n // Another caller may have finished (or a pre-warm beat us) while queued.\n if (existsSync(cachePath)) return cachePath;\n\n const cacheDir = dirname(cachePath);\n mkdirWithinProject(projectDir, cacheDir);\n const tempPath = join(cacheDir, `.tmp-${randomUUID()}-${basename(cachePath)}`);\n try {\n await runFfmpeg(absoluteSourcePath, tempPath, variant, box);\n renameSync(tempPath, cachePath);\n maintainProxyCache(cacheDir);\n return cachePath;\n } finally {\n // No partial files: if anything above threw, remove whatever ffmpeg\n // may have partially written under the temp name.\n if (existsSync(tempPath)) unlinkSync(tempPath);\n }\n } finally {\n releaseSlot();\n }\n}\n\nlet proxyActivity = 0;\n\n/** Null while this project has a copy in progress; otherwise a mark that moves when any copy finishes or is refused. */\nexport function proxyActivityMark(projectDir: string): string | null {\n if (!existsSync(projectDir)) return String(proxyActivity);\n const cacheDir = join(realpath(projectDir), CACHE_DIR_NAME) + sep;\n for (const cachePath of inFlight.keys()) if (cachePath.startsWith(cacheDir)) return null;\n return String(proxyActivity);\n}\n\n/**\n * Resolves the cached proxy variant for `absoluteSourcePath`, transcoding it at\n * most once per cache key. Concurrent calls for the same key (including a\n * pre-warm call racing an element-triggered one) share one ffmpeg child and\n * one promise; calls for different keys queue through the global concurrency\n * limiter above. Throws `ProxyTranscodeError` on failure (missing ffmpeg or a\n * nonzero exit) — callers (route handlers) decide how to surface that (502).\n * A `box` makes a smaller preview-only copy with its own cache entry; without\n * one the copy keeps the source size (CLI play, static servers, publish).\n * `priority` moves the copy ahead of every normal queued copy; a `signal`\n * lets this caller leave (see the detachment note at the top of this file).\n */\nexport async function resolveProxy(\n projectDir: string,\n absoluteSourcePath: string,\n variant: ProxyVariant = \"h264\",\n box?: PreviewProxyBox,\n options: ResolveProxyOptions = {},\n): Promise<string> {\n options.signal?.throwIfAborted();\n const source = canonicalizeProxySource(projectDir, absoluteSourcePath);\n const cachePath = getCanonicalProxyCachePath(source, variant, box);\n if (existsSync(cachePath)) {\n markCacheEntryUsed(cachePath);\n maintainProxyCache(dirname(cachePath));\n return cachePath;\n }\n\n const rememberedFailure = failedTranscodes.get(cachePath);\n if (rememberedFailure) {\n if (rememberedFailure.expiresAt > Date.now()) throw rememberedFailure.error;\n failedTranscodes.delete(cachePath);\n }\n\n let entry = inFlight.get(cachePath);\n if (!entry) {\n if (!options.priority && queueIsFull()) {\n proxyActivity += 1;\n throw new ProxyCapacityError();\n }\n const job: ProxyJob = {\n cachePath,\n priority: options.priority === true,\n callers: 0,\n };\n const promise = transcodeToCache(\n job,\n source.projectDir,\n source.sourcePath,\n cachePath,\n variant,\n box,\n )\n .catch((err: unknown) => {\n if (!(err instanceof ProxyDroppedError)) rememberFailure(cachePath, err);\n throw err;\n })\n .finally(() => {\n forget(job);\n proxyActivity += 1;\n });\n entry = { promise, job };\n inFlight.set(cachePath, entry);\n }\n if (options.priority) prioritize(entry.job);\n return joinJob(entry.promise, entry.job, options.signal);\n}\n\nexport interface ResolveProxyOptions {\n priority?: boolean;\n signal?: AbortSignal;\n}\n\nfunction joinJob(promise: Promise<string>, job: ProxyJob, signal?: AbortSignal): Promise<string> {\n job.callers++;\n if (!signal) return promise;\n return new Promise((resolveJoin, rejectJoin) => {\n const onAbort = (): void => {\n leave(job);\n rejectJoin(signal.reason);\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n promise\n .finally(() => signal.removeEventListener(\"abort\", onAbort))\n .then(resolveJoin, rejectJoin);\n });\n}\n","import { existsSync, readdirSync, statSync, unlinkSync } from \"node:fs\";\nimport { extname, join } from \"node:path\";\nimport { PROXY_VARIANT_CONFIG } from \"./mediaCodecMap.js\";\n\nconst DEFAULT_MAX_BYTES = 10 * 1024 * 1024 * 1024;\nconst DEFAULT_STALE_TEMP_MS = 60 * 60 * 1000;\nconst DEFAULT_MIN_SWEEP_INTERVAL_MS = 5 * 60 * 1000;\nconst PROXY_EXTENSIONS: ReadonlySet<string> = new Set(\n Object.values(PROXY_VARIANT_CONFIG).map(({ extension }) => extension),\n);\nconst TRANSCODER_PROXY_NAME = /^[0-9a-f]{64}\\.\\w+$/;\nconst TRANSCODER_TEMP_NAME = /^\\.tmp-[0-9a-f-]{36}-[0-9a-f]{64}\\.\\w+$/;\n\nexport interface ProxyCacheCleanupOptions {\n maxBytes?: number;\n maxIdleMs?: number;\n staleTempMs?: number;\n minSweepIntervalMs?: number;\n protectedPaths?: ReadonlySet<string>;\n now?: number;\n dryRun?: boolean;\n}\n\nexport interface ProxyCacheCleanupResult {\n removed: string[];\n bytesBefore: number;\n bytesAfter: number;\n skipped: boolean;\n}\n\ninterface CacheEntry {\n path: string;\n size: number;\n modifiedAt: number;\n protected: boolean;\n}\n\nconst lastSweepAt = new Map<string, number>();\n\nfunction positiveEnvNumber(name: string, fallback: number): number {\n const parsed = Number(process.env[name]);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;\n}\n\nfunction proxyCacheCleanupDefaults(): Required<\n Pick<ProxyCacheCleanupOptions, \"maxBytes\" | \"maxIdleMs\" | \"staleTempMs\" | \"minSweepIntervalMs\">\n> {\n return {\n maxBytes: positiveEnvNumber(\"HYPERFRAMES_PROXY_CACHE_MAX_BYTES\", DEFAULT_MAX_BYTES),\n maxIdleMs: positiveEnvNumber(\"HYPERFRAMES_PROXY_CACHE_MAX_IDLE_DAYS\", 30) * 24 * 60 * 60 * 1000,\n staleTempMs: positiveEnvNumber(\"HYPERFRAMES_PROXY_CACHE_STALE_TEMP_MS\", DEFAULT_STALE_TEMP_MS),\n minSweepIntervalMs: positiveEnvNumber(\n \"HYPERFRAMES_PROXY_CACHE_SWEEP_INTERVAL_MS\",\n DEFAULT_MIN_SWEEP_INTERVAL_MS,\n ),\n };\n}\n\nfunction shouldSkipSweep(cacheDir: string, now: number, minSweepIntervalMs: number): boolean {\n const previousSweep = lastSweepAt.get(cacheDir);\n if (previousSweep !== undefined && now - previousSweep < minSweepIntervalMs) return true;\n lastSweepAt.set(cacheDir, now);\n return false;\n}\n\nfunction readCacheInventory(\n cacheDir: string,\n protectedPaths: ReadonlySet<string>,\n now: number,\n staleTempMs: number,\n): { entries: CacheEntry[]; staleTemps: CacheEntry[] } {\n const entries: CacheEntry[] = [];\n const staleTemps: CacheEntry[] = [];\n for (const dirent of readdirSync(cacheDir, { withFileTypes: true })) {\n if (!dirent.isFile()) continue;\n const path = join(cacheDir, dirent.name);\n const stat = statSync(path);\n const entry = {\n path,\n size: stat.size,\n modifiedAt: stat.mtimeMs,\n protected: protectedPaths.has(path),\n };\n if (TRANSCODER_TEMP_NAME.test(dirent.name)) {\n if (now - stat.mtimeMs >= staleTempMs) staleTemps.push(entry);\n } else if (\n TRANSCODER_PROXY_NAME.test(dirent.name) &&\n PROXY_EXTENSIONS.has(extname(dirent.name))\n ) {\n entries.push(entry);\n }\n }\n const oldestFirst = (a: CacheEntry, b: CacheEntry): number =>\n a.modifiedAt - b.modifiedAt || a.path.localeCompare(b.path);\n entries.sort(oldestFirst);\n staleTemps.sort(oldestFirst);\n return { entries, staleTemps };\n}\n\nfunction evictCacheEntries(\n entries: CacheEntry[],\n staleTemps: CacheEntry[],\n now: number,\n maxIdleMs: number,\n maxBytes: number,\n dryRun: boolean,\n): Omit<ProxyCacheCleanupResult, \"skipped\"> {\n const bytesBefore = entries.reduce((total, entry) => total + entry.size, 0);\n let bytesAfter = bytesBefore;\n const removed: string[] = [];\n const remove = (entry: CacheEntry, countsTowardBudget: boolean): void => {\n if (!dryRun) unlinkSync(entry.path);\n removed.push(entry.path);\n if (countsTowardBudget) bytesAfter -= entry.size;\n };\n\n for (const entry of staleTemps) remove(entry, false);\n const kept: CacheEntry[] = [];\n for (const entry of entries) {\n if (!entry.protected && now - entry.modifiedAt >= maxIdleMs) remove(entry, true);\n else kept.push(entry);\n }\n for (const entry of kept) {\n if (bytesAfter <= maxBytes) break;\n if (!entry.protected && existsSync(entry.path)) remove(entry, true);\n }\n return { removed, bytesBefore, bytesAfter };\n}\n\n/**\n * Opportunistically bounds a project's transparent-proxy cache. Cleanup is\n * synchronous because callers already perform filesystem bookkeeping on the\n * preview request path, but rate limiting keeps the directory scan off the\n * hot path. Errors intentionally bubble so callers can warn without turning\n * a cache-maintenance failure into a preview failure.\n */\nexport function cleanupProxyCache(\n cacheDir: string,\n options: ProxyCacheCleanupOptions = {},\n): ProxyCacheCleanupResult {\n const defaults = proxyCacheCleanupDefaults();\n const now = options.now ?? Date.now();\n const minSweepIntervalMs = options.minSweepIntervalMs ?? defaults.minSweepIntervalMs;\n if (shouldSkipSweep(cacheDir, now, minSweepIntervalMs)) {\n return { removed: [], bytesBefore: 0, bytesAfter: 0, skipped: true };\n }\n if (!existsSync(cacheDir)) {\n return { removed: [], bytesBefore: 0, bytesAfter: 0, skipped: false };\n }\n\n const maxBytes = options.maxBytes ?? defaults.maxBytes;\n const maxIdleMs = options.maxIdleMs ?? defaults.maxIdleMs;\n const staleTempMs = options.staleTempMs ?? defaults.staleTempMs;\n const protectedPaths = options.protectedPaths ?? new Set<string>();\n const { entries, staleTemps } = readCacheInventory(cacheDir, protectedPaths, now, staleTempMs);\n return {\n ...evictCacheEntries(entries, staleTemps, now, maxIdleMs, maxBytes, options.dryRun ?? false),\n skipped: false,\n };\n}\n"],"mappings":";;;;;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YAAQ,EAAE,SAAS,IAAI;AACvB,aAAS,IAAI,WAAW,KAAK;AAAA,EAC/B;AACA,MAAI,QAAQ,SAAU,YAAW,MAAM,GAAG;AAC1C,SAAO,QAAQ,MAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;AACzD;AAOA,SAAS,QAAQ,SAA0B,KAAe,QAAuC;AAC/F,MAAI;AACJ,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,CAAC,aAAa,eAAe;AAC9C,UAAM,UAAU,MAAY;AAC1B,YAAM,GAAG;AACT,iBAAW,OAAO,MAAM;AAAA,IAC1B;AACA,WAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AACxD,YACG,QAAQ,MAAM,OAAO,oBAAoB,SAAS,OAAO,CAAC,EAC1D,KAAK,aAAa,UAAU;AAAA,EACjC,CAAC;AACH;","names":["existsSync","statSync","unlinkSync","join","statSync","join","existsSync","unlinkSync"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PROXY_PARAMS_VERSION,
3
3
  resolveProxy
4
- } from "./chunk-6EFY2WPN.js";
4
+ } from "./chunk-2VZGTTEG.js";
5
5
  import {
6
6
  createMediaCodecProbeCache,
7
7
  proxyVariantFor,
@@ -64,4 +64,4 @@ export {
64
64
  injectMediaCodecMapIntoHtml,
65
65
  injectMediaCodecMap
66
66
  };
67
- //# sourceMappingURL=chunk-AYKLBPP2.js.map
67
+ //# sourceMappingURL=chunk-WE5JQ6V7.js.map
@@ -1,5 +1,5 @@
1
1
  import '@hyperframes/core';
2
- export { a as PreviewApiAdapter, P as PreviewDocumentStore, i as injectMediaCodecMap, f as injectMediaCodecMapIntoHtml, g as isAutoProxyEnabled, p as proxyEtagSalt, r as resolvePreviewMediaCodecProbeCache } from '../mediaProxyPreview-CJ4lbPcF.js';
2
+ export { a as PreviewApiAdapter, P as PreviewDocumentStore, i as injectMediaCodecMap, f as injectMediaCodecMapIntoHtml, g as isAutoProxyEnabled, p as proxyEtagSalt, r as resolvePreviewMediaCodecProbeCache } from '../mediaProxyPreview-uWqly-sz.js';
3
3
  import './mediaCodecMap.js';
4
4
  import '@hyperframes/parsers';
5
5
  import '@hyperframes/core/compiler';
@@ -4,8 +4,8 @@ import {
4
4
  isAutoProxyEnabled,
5
5
  proxyEtagSalt,
6
6
  resolvePreviewMediaCodecProbeCache
7
- } from "../chunk-AYKLBPP2.js";
8
- import "../chunk-6EFY2WPN.js";
7
+ } from "../chunk-WE5JQ6V7.js";
8
+ import "../chunk-2VZGTTEG.js";
9
9
  import "../chunk-RN33UALN.js";
10
10
  import "../chunk-DTKK7TKL.js";
11
11
  import "../chunk-6XMC64FJ.js";
@@ -7,15 +7,9 @@ import { ProxyVariant } from './mediaCodecMap.js';
7
7
  * project routes (U3/U4) to serve a `?hf-proxy=` request; never used on
8
8
  * the render path (render always sees the original file).
9
9
  *
10
- * IMPORTANT — request-lifecycle detachment: nothing here accepts or wires an
11
- * AbortSignal. `resolveProxy` returns a promise shared by every concurrent
12
- * caller for the same cache key (in-flight dedupe below); if a route handler
13
- * killed the ffmpeg child on client abort (page reload, HMR), every other
14
- * caller waiting on that same promise would fail too, and the next request
15
- * would restart a transcode that may have been minutes into a long asset.
16
- * Callers MUST let the child run to completion regardless of request
17
- * cancellation and simply let the held response also abort — the cache
18
- * entry still lands for the next request.
10
+ * A started ffmpeg child is never killed for one caller: every caller of a cache
11
+ * key shares it (in-flight dedupe below). A caller's `signal` only detaches that
12
+ * caller, and drops the copy while it is still queued with no caller left.
19
13
  */
20
14
  declare const PROXY_PARAMS_VERSION = "v5";
21
15
  declare const CACHE_DIR_NAME = ".transcode-cache";
@@ -44,14 +38,14 @@ declare class ProxyWaitTimeoutError extends ProxyTranscodeError {
44
38
  declare function waitForProxy<T>(promise: Promise<T>, timeoutMs?: number): Promise<T>;
45
39
  /**
46
40
  * Computes the absolute path a proxy for this source would live at, without
47
- * transcoding anything. Route handlers use this to check cache state (e.g.
48
- * for ETag/If-None-Match) before deciding whether to await a transcode.
41
+ * transcoding anything, so a host can check cache state. Pass the request's
42
+ * preview box (`hf-proxy-box`) to name a boxed copy.
49
43
  */
50
- declare function getProxyCachePath(projectDir: string, absoluteSourcePath: string, variant?: ProxyVariant): string;
44
+ declare function getProxyCachePath(projectDir: string, absoluteSourcePath: string, variant?: ProxyVariant, box?: PreviewProxyBox): string;
51
45
  /** Test hook: forget remembered transcode failures (module state persists
52
46
  * across tests that don't reload the module). */
53
47
  declare function clearFailedTranscodesForTest(): void;
54
- /** Null while a copy for this project is being made; otherwise a mark that moves when any copy finishes. */
48
+ /** Null while this project has a copy in progress; otherwise a mark that moves when any copy finishes or is refused. */
55
49
  declare function proxyActivityMark(projectDir: string): string | null;
56
50
  /**
57
51
  * Resolves the cached proxy variant for `absoluteSourcePath`, transcoding it at
@@ -62,7 +56,13 @@ declare function proxyActivityMark(projectDir: string): string | null;
62
56
  * nonzero exit) — callers (route handlers) decide how to surface that (502).
63
57
  * A `box` makes a smaller preview-only copy with its own cache entry; without
64
58
  * one the copy keeps the source size (CLI play, static servers, publish).
59
+ * `priority` moves the copy ahead of every normal queued copy; a `signal`
60
+ * lets this caller leave (see the detachment note at the top of this file).
65
61
  */
66
- declare function resolveProxy(projectDir: string, absoluteSourcePath: string, variant?: ProxyVariant, box?: PreviewProxyBox): Promise<string>;
62
+ declare function resolveProxy(projectDir: string, absoluteSourcePath: string, variant?: ProxyVariant, box?: PreviewProxyBox, options?: ResolveProxyOptions): Promise<string>;
63
+ interface ResolveProxyOptions {
64
+ priority?: boolean;
65
+ signal?: AbortSignal;
66
+ }
67
67
 
68
- export { CACHE_DIR_NAME, DEFAULT_PROXY_WAIT_TIMEOUT_MS, FfmpegMissingFilterError, PROXY_PARAMS_VERSION, PROXY_PENDING_RETRY_AFTER_SECONDS, ProxyCapacityError, ProxySourceOutsideProjectError, ProxyTranscodeError, ProxyWaitTimeoutError, TRANSCODE_TIMEOUT_MS, clearFailedTranscodesForTest, getProxyCachePath, proxyActivityMark, resolveProxy, waitForProxy };
68
+ export { CACHE_DIR_NAME, DEFAULT_PROXY_WAIT_TIMEOUT_MS, FfmpegMissingFilterError, PROXY_PARAMS_VERSION, PROXY_PENDING_RETRY_AFTER_SECONDS, ProxyCapacityError, ProxySourceOutsideProjectError, ProxyTranscodeError, ProxyWaitTimeoutError, type ResolveProxyOptions, TRANSCODE_TIMEOUT_MS, clearFailedTranscodesForTest, getProxyCachePath, proxyActivityMark, resolveProxy, waitForProxy };
@@ -14,7 +14,7 @@ import {
14
14
  proxyActivityMark,
15
15
  resolveProxy,
16
16
  waitForProxy
17
- } from "../chunk-6EFY2WPN.js";
17
+ } from "../chunk-2VZGTTEG.js";
18
18
  import "../chunk-RN33UALN.js";
19
19
  import "../chunk-DTKK7TKL.js";
20
20
  import "../chunk-6XMC64FJ.js";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Hono } from 'hono';
2
- import { S as StudioApiAdapter, P as PreviewDocumentStore, M as MediaProcessingJobState } from './mediaProxyPreview-CJ4lbPcF.js';
3
- export { L as LintResult, a as PreviewApiAdapter, R as RenderJobState, b as ResolvedProject, c as StudioSelectionResponse, d as StudioSelectionSnapshot, e as StudioSelectionTextField } from './mediaProxyPreview-CJ4lbPcF.js';
2
+ import { S as StudioApiAdapter, P as PreviewDocumentStore, M as MediaProcessingJobState } from './mediaProxyPreview-uWqly-sz.js';
3
+ export { L as LintResult, a as PreviewApiAdapter, R as RenderJobState, b as ResolvedProject, c as StudioSelectionResponse, d as StudioSelectionSnapshot, e as StudioSelectionTextField } from './mediaProxyPreview-uWqly-sz.js';
4
4
  export { C as ClosedWindow, D as DEFAULT_HISTORY_ROOT, S as HISTORY_START, H as HistoryClosedError, a as HistoryEntry, b as HistoryEntrySide, c as HistoryFileChange, d as HistoryListItem, e as HistoryResult, f as HistoryWho, g as HistoryWindow, M as MAX_WINDOW_IDLE_MS, P as ProjectHistory, h as ProjectHistoryOptions, U as UNDO_MODES, i as UndoMode, o as openProjectHistory } from './projectHistory-Cm8Mdmmv.js';
5
5
  export { HistoryBusyError, HistoryIdError, ProjectHistoryRecord, PrunedHistory, historyCache, listProjectHistories, pruneGoneProjectHistories } from './history/index.js';
6
6
  export { CACHE_DIR_NAME as PROXY_CACHE_DIR_NAME } from './helpers/proxyTranscoder.js';
@@ -113,7 +113,8 @@ interface AppliedFileMutation {
113
113
  writeToken: string | null;
114
114
  }
115
115
  /** Applies prepared HTML mutations with the same journal and receipt semantics as Studio. */
116
- declare function applyFileMutations(projectDir: string, mutations: readonly FileMutationInput[], requestToken?: string, writeFile?: (path: string, content: string, encoding: "utf-8") => void): AppliedFileMutation[];
116
+ declare function applyFileMutations(projectDir: string, mutations: readonly FileMutationInput[], requestToken?: string, writeFile?: WriteFile): AppliedFileMutation[];
117
+ type WriteFile = (path: string, content: string, encoding: "utf-8") => void;
117
118
 
118
119
  /** The bundler options every adapter's `bundle()` uses. This route serves project files under a
119
120
  * `<base href>`, so assets keep their URLs: inlined base64 multiplies the document per reference.
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ import {
67
67
  isAutoProxyEnabled,
68
68
  proxyEtagSalt,
69
69
  resolvePreviewMediaCodecProbeCache
70
- } from "./chunk-AYKLBPP2.js";
70
+ } from "./chunk-WE5JQ6V7.js";
71
71
  import {
72
72
  CACHE_DIR_NAME,
73
73
  PROXY_PENDING_RETRY_AFTER_SECONDS,
@@ -78,7 +78,7 @@ import {
78
78
  proxyActivityMark,
79
79
  resolveProxy,
80
80
  waitForProxy
81
- } from "./chunk-6EFY2WPN.js";
81
+ } from "./chunk-2VZGTTEG.js";
82
82
  import {
83
83
  PROXY_VARIANT_CONFIG,
84
84
  decideMediaProxyEligibility,
@@ -1005,16 +1005,7 @@ function applyFileMutations(projectDir, mutations, requestToken, writeFile = (pa
1005
1005
  }
1006
1006
  return results;
1007
1007
  } catch (error) {
1008
- const rollbackErrors = [];
1009
- for (const mutation of attempted.reverse()) {
1010
- try {
1011
- if (!mutation.written || readFileSync4(mutation.absPath, "utf-8") === mutation.after)
1012
- writeFile(mutation.absPath, mutation.before, "utf-8");
1013
- clearFileWriteReceipt(mutation.absPath, mutation.version, mutation.writeToken);
1014
- } catch (rollbackError) {
1015
- rollbackErrors.push(rollbackError);
1016
- }
1017
- }
1008
+ const rollbackErrors = rollBack(attempted, writeFile);
1018
1009
  if (rollbackErrors.length > 0) {
1019
1010
  throw new AggregateError(
1020
1011
  [error, ...rollbackErrors],
@@ -1024,6 +1015,20 @@ function applyFileMutations(projectDir, mutations, requestToken, writeFile = (pa
1024
1015
  throw error;
1025
1016
  }
1026
1017
  }
1018
+ function rollBack(attempted, writeFile) {
1019
+ const errors = [];
1020
+ for (const mutation of attempted.reverse()) {
1021
+ try {
1022
+ const current = readFileSync4(mutation.absPath, "utf-8");
1023
+ if (mutation.written ? current === mutation.after : current !== mutation.before)
1024
+ writeFile(mutation.absPath, mutation.before, "utf-8");
1025
+ clearFileWriteReceipt(mutation.absPath, mutation.version, mutation.writeToken);
1026
+ } catch (rollbackError) {
1027
+ errors.push(rollbackError);
1028
+ }
1029
+ }
1030
+ return errors;
1031
+ }
1027
1032
  function applyOneMutation(projectDir, mutation, requestToken, writeFile, attempted) {
1028
1033
  const current = readFileSync4(mutation.absPath, "utf-8");
1029
1034
  assertExpectedVersion(mutation, current);
@@ -4506,7 +4511,11 @@ async function lintUncoveredHtml(adapter, projectDir, htmlFiles, coveredFiles) {
4506
4511
  for (const file of htmlFiles) {
4507
4512
  if (coveredFiles.has(file)) continue;
4508
4513
  const content = readFileSync7(join9(projectDir, file), "utf-8");
4509
- const result = await adapter.lint(content, { filePath: file, isSubComposition: true });
4514
+ const result = await adapter.lint(content, {
4515
+ filePath: file,
4516
+ isSubComposition: true,
4517
+ compSrcPath: file
4518
+ });
4510
4519
  for (const finding of result?.findings ?? []) {
4511
4520
  findings.push({ ...finding, file });
4512
4521
  }
@@ -4634,6 +4643,7 @@ function registerRenderRoutes(api, adapter) {
4634
4643
  outputResolution,
4635
4644
  composition,
4636
4645
  variables,
4646
+ useGpu: body.gpu === true && format === "mp4",
4637
4647
  distinctId: typeof body.telemetryDistinctId === "string" ? body.telemetryDistinctId : void 0,
4638
4648
  telemetryOptOut: body.telemetryOptOut === true
4639
4649
  });