@hyperframes/producer 0.9.61 → 0.9.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@hyperframes/engine";
8
8
 
9
9
  // src/services/renderOrchestrator.ts
10
- import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
10
+ import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
11
11
  import {
12
12
  existsSync as existsSync21,
13
13
  mkdirSync as mkdirSync12,
@@ -385,7 +385,10 @@ import { Readable } from "node:stream";
385
385
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
386
386
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
387
387
  import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
388
- import { PREVIEW_FOR_ANOTHER_SITE_META } from "@hyperframes/core/studio-preview-mark";
388
+ import {
389
+ PREVIEW_FOR_ANOTHER_SITE_META,
390
+ serviceWorkerScriptFetch
391
+ } from "@hyperframes/core/studio-preview-mark";
389
392
  import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
390
393
  import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
391
394
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -1167,6 +1170,12 @@ function createFileServer(options) {
1167
1170
  c.res.headers.set("X-Content-Type-Options", "nosniff");
1168
1171
  });
1169
1172
  answerOwnLoopbackHostOnly(app, () => listeningPort);
1173
+ app.use(async function refuseServiceWorkerScripts(c, next) {
1174
+ const serviceWorker = c.req.header("service-worker");
1175
+ if (!serviceWorkerScriptFetch({ serviceWorker, fetchDest: c.req.header("sec-fetch-dest") }))
1176
+ return next();
1177
+ return c.text("Forbidden", 403);
1178
+ });
1170
1179
  app.get("/*", async (c) => {
1171
1180
  let requestPath = c.req.path;
1172
1181
  if (requestPath === "/") requestPath = "/index.html";
@@ -8124,16 +8133,23 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
8124
8133
  }
8125
8134
  }
8126
8135
  var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
8127
- var mountSrcsUnder = (root) => [...root.querySelectorAll("[data-composition-src]")].map((el) => el.getAttribute("data-composition-src")).filter((srcPath) => !!srcPath && !isUnresolvedAssetPlaceholder(srcPath));
8128
8136
  function compositionSrcsIn(html) {
8129
8137
  const { document: document2 } = parseHTML5(html);
8138
+ const mounts = [];
8130
8139
  const templated = [];
8131
- const templates = [...document2.querySelectorAll("template")];
8132
- for (let template = templates.pop(); template; template = templates.pop()) {
8133
- templated.push(...mountSrcsUnder(template.content));
8134
- templates.push(...template.content.querySelectorAll("template"));
8140
+ const stack = [...document2.children].reverse().map((el) => [el, false]);
8141
+ for (let next = stack.pop(); next; next = stack.pop()) {
8142
+ const [el, inTemplate] = next;
8143
+ const srcPath = el.getAttribute("data-composition-src");
8144
+ if (srcPath && !isUnresolvedAssetPlaceholder(srcPath)) {
8145
+ (inTemplate ? templated : mounts).push(srcPath);
8146
+ }
8147
+ const childrenInTemplate = inTemplate || el.localName === "template";
8148
+ const children = [...el.children];
8149
+ for (let i = children.length - 1; i >= 0; i -= 1)
8150
+ stack.push([children[i], childrenInTemplate]);
8135
8151
  }
8136
- return { mounts: mountSrcsUnder(document2), templated };
8152
+ return { mounts, templated };
8137
8153
  }
8138
8154
  function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
8139
8155
  if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
@@ -13906,7 +13922,7 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
13906
13922
  error: String(failure ?? result?.error)
13907
13923
  }
13908
13924
  );
13909
- return runEncodeStage(input);
13925
+ return runEncodeStage({ ...input, hasAudio: false });
13910
13926
  },
13911
13927
  abort: async () => {
13912
13928
  stop.abort();
@@ -14234,6 +14250,7 @@ var RenderQualityError = class extends Error {
14234
14250
  }
14235
14251
  warnings;
14236
14252
  };
14253
+ var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
14237
14254
  function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
14238
14255
  job.warnings ??= [];
14239
14256
  const existing = new Set(
@@ -15204,8 +15221,14 @@ async function executeRenderPipeline(input) {
15204
15221
  const onProgress = execution.onProgress;
15205
15222
  const tooSlow = new AbortController();
15206
15223
  let tooSlowError;
15224
+ const audioFailed = new AbortController();
15225
+ let audioFailure;
15207
15226
  let calibrationEvaluateTimedOut = false;
15208
- const executionSignal = job.config.maxRenderMs ? AbortSignal.any([tooSlow.signal, ...execution.signal ? [execution.signal] : []]) : execution.signal;
15227
+ const executionSignal = AbortSignal.any([
15228
+ audioFailed.signal,
15229
+ ...job.config.maxRenderMs ? [tooSlow.signal] : [],
15230
+ ...execution.signal ? [execution.signal] : []
15231
+ ]);
15209
15232
  let fileServer = null;
15210
15233
  let probeSession = null;
15211
15234
  let lastBrowserConsole = [];
@@ -16468,33 +16491,41 @@ async function executeRenderPipeline(input) {
16468
16491
  }
16469
16492
  const effectiveQuality = job.config.crf ?? preset.quality;
16470
16493
  const effectiveBitrate = job.config.crf != null ? void 0 : job.config.videoBitrate;
16471
- const audioResult = await audioWait.wait(audioStage);
16472
- const { audioOutputPath, deliverySourcePath, hasAudio } = audioResult;
16473
- perfStages.audioProcessMs = audioResult.audioProcessMs;
16474
- recordLimiterAttenuation(job, audioResult.audioLoweredDb);
16475
- if (audioResult.audioError) {
16476
- const audioFailures = audioResult.audioFailures ?? [];
16477
- const failureOwner = audioFailures.length === 0 ? void 0 : audioFailures.some((failure) => failure.owner === "system") ? "system" : "user";
16478
- const retryable = audioFailures.length === 0 ? void 0 : audioFailures.every((failure) => failure.retryable);
16479
- applyRenderWarningPolicy(
16480
- job,
16481
- [
16482
- {
16483
- code: "audio_processing_failed",
16484
- message: `Audio mix failed; output would be video-only: ${audioResult.audioError}`,
16485
- details: {
16486
- mediaType: "audio",
16487
- audioFailures: audioFailureDiagnostics2(audioFailures),
16488
- failureReasons: [...new Set(audioFailures.map((failure) => failure.reason))],
16489
- failureStages: [...new Set(audioFailures.map((failure) => failure.stage))],
16490
- failureOwner,
16491
- retryable
16494
+ const audioReady = audioStage.then((audioResult) => {
16495
+ perfStages.audioProcessMs = audioResult.audioProcessMs;
16496
+ recordLimiterAttenuation(job, audioResult.audioLoweredDb);
16497
+ if (audioResult.audioError) {
16498
+ const audioFailures = audioResult.audioFailures ?? [];
16499
+ const failureOwner = audioFailures.length === 0 ? void 0 : audioFailures.some((failure) => failure.owner === "system") ? "system" : "user";
16500
+ const retryable = audioFailures.length === 0 ? void 0 : audioFailures.every((failure) => failure.retryable);
16501
+ applyRenderWarningPolicy(
16502
+ job,
16503
+ [
16504
+ {
16505
+ code: "audio_processing_failed",
16506
+ message: `Audio mix failed; output would be video-only: ${audioResult.audioError}`,
16507
+ details: {
16508
+ mediaType: "audio",
16509
+ audioFailures: audioFailureDiagnostics2(audioFailures),
16510
+ failureReasons: [...new Set(audioFailures.map((failure) => failure.reason))],
16511
+ failureStages: [...new Set(audioFailures.map((failure) => failure.stage))],
16512
+ failureOwner,
16513
+ retryable
16514
+ }
16492
16515
  }
16493
- }
16494
- ],
16495
- log
16496
- );
16497
- }
16516
+ ],
16517
+ log
16518
+ );
16519
+ }
16520
+ return audioResult;
16521
+ });
16522
+ audioReady.catch((error) => {
16523
+ if (executionSignal.aborted) return;
16524
+ audioFailure = error;
16525
+ audioFailed.abort(error);
16526
+ });
16527
+ const mixedAudio = () => audioWait.wait(audioReady);
16528
+ if (usableCpuCount2() < MIN_CPUS_TO_CAPTURE_DURING_MIX) await mixedAudio();
16498
16529
  resetCaptureAttemptProgress(job);
16499
16530
  if (capturePlan.kind === "hdr_layered") {
16500
16531
  const layeredPlan = capturePlan;
@@ -16677,7 +16708,7 @@ async function executeRenderPipeline(input) {
16677
16708
  } catch (err) {
16678
16709
  const isVerifyError = isDrawElementVerificationError(err);
16679
16710
  const isDeStall = isDeRendererStallError(err);
16680
- if (!isVerifyError && !isDrawElementCaptureError(err) && !isDeStall || err instanceof RenderCancelledError || executionSignal?.aborted === true) {
16711
+ if (!isVerifyError && !isDrawElementCaptureError(err) && !isDeStall || err instanceof RenderCancelledError || executionSignal.aborted === true) {
16681
16712
  throw err;
16682
16713
  }
16683
16714
  deSelfVerifyFallback = isVerifyError;
@@ -16820,7 +16851,7 @@ async function executeRenderPipeline(input) {
16820
16851
  const isSequentialStall = isSequentialCaptureStallError(err);
16821
16852
  const isParallelStall = isParallelCaptureStallError(err);
16822
16853
  const isEncoderDeath = isRetryableEncoderDeath(err);
16823
- const isCancellation = err instanceof RenderCancelledError || executionSignal?.aborted === true;
16854
+ const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
16824
16855
  if (!shouldRetryViaPinnedFallback({
16825
16856
  isVerifyError,
16826
16857
  isDeCaptureError,
@@ -16949,8 +16980,6 @@ async function executeRenderPipeline(input) {
16949
16980
  height,
16950
16981
  needsAlpha,
16951
16982
  captureImageFormat: captureOptions.format ?? "jpeg",
16952
- hasAudio,
16953
- audioOutputPath,
16954
16983
  isPngSequence,
16955
16984
  isGif,
16956
16985
  preset,
@@ -17003,7 +17032,7 @@ async function executeRenderPipeline(input) {
17003
17032
  captureRes = await invokeDiskCapture(capturePlan);
17004
17033
  } catch (err) {
17005
17034
  await overlap?.abort();
17006
- if (!isDrawElementVerificationError(err) && !isDrawElementCaptureError(err) || err instanceof RenderCancelledError || executionSignal?.aborted === true) {
17035
+ if (!isDrawElementVerificationError(err) && !isDrawElementCaptureError(err) || err instanceof RenderCancelledError || executionSignal.aborted === true) {
17007
17036
  throw err;
17008
17037
  }
17009
17038
  deSelfVerifyFallback = isDrawElementVerificationError(err);
@@ -17062,16 +17091,17 @@ async function executeRenderPipeline(input) {
17062
17091
  perfStages.captureMs = Date.now() - stage4Start;
17063
17092
  perfStages.captureFrameMs = captureFrameMs;
17064
17093
  perfStages.captureSetupMs = Math.max(0, perfStages.captureMs - captureFrameMs);
17094
+ const { hasAudio: hasAudio2, audioOutputPath: audioOutputPath2 } = await mixedAudio();
17065
17095
  const encodeRes = await observeRenderStage(
17066
17096
  observability,
17067
17097
  "encode",
17068
17098
  captureStageObservationData({
17069
- hasAudio,
17099
+ hasAudio: hasAudio2,
17070
17100
  isPngSequence,
17071
17101
  isGif,
17072
17102
  chunkedEncode: enableChunkedEncode
17073
17103
  }),
17074
- () => overlap ? overlap.finish() : runEncodeStage(encodeInput)
17104
+ () => overlap ? overlap.finish() : runEncodeStage({ ...encodeInput, hasAudio: hasAudio2, audioOutputPath: audioOutputPath2 })
17075
17105
  );
17076
17106
  perfStages.encodeMs = encodeRes.encodeMs;
17077
17107
  }
@@ -17091,6 +17121,7 @@ async function executeRenderPipeline(input) {
17091
17121
  if (frameLookup) frameLookup.cleanup();
17092
17122
  closeFileServerSafely(fileServer, "renderOrchestrator", log);
17093
17123
  fileServer = null;
17124
+ const { audioOutputPath, deliverySourcePath, hasAudio } = await mixedAudio();
17094
17125
  if (!isPngSequence && !isGif) {
17095
17126
  const assembleRes = await observeRenderStage(
17096
17127
  observability,
@@ -17226,8 +17257,11 @@ async function executeRenderPipeline(input) {
17226
17257
  framesRendered: job.framesRendered ?? 0,
17227
17258
  error: caught
17228
17259
  });
17229
- const error = surfaceScriptFailure(tooSlowError ?? pageNeverReady ?? caught, job);
17230
- if (!tooSlowError && (error instanceof RenderCancelledError || executionSignal?.aborted)) {
17260
+ const error = surfaceScriptFailure(
17261
+ tooSlowError ?? audioFailure ?? pageNeverReady ?? caught,
17262
+ job
17263
+ );
17264
+ if (!tooSlowError && !audioFailure && (error instanceof RenderCancelledError || executionSignal.aborted)) {
17231
17265
  job.error = error instanceof Error ? error.message : "render_cancelled";
17232
17266
  updateJobStatus(job, "cancelled", "Render cancelled", job.progress, onProgress);
17233
17267
  await eventPublisher.flush();
@@ -17269,7 +17303,7 @@ async function executeRenderPipeline(input) {
17269
17303
  `Parallel capture timed out with ${captureObservability.workerCount ?? "auto"} workers. Video-heavy compositions often need sequential capture. Retry with --workers 1`
17270
17304
  );
17271
17305
  }
17272
- const failedStage = job.currentStage || "pipeline";
17306
+ const failedStage = audioFailure === void 0 ? job.currentStage || "pipeline" : AUDIO_STAGE;
17273
17307
  const observabilitySummary = observability.summary({
17274
17308
  lastBrowserConsole,
17275
17309
  capture: withCapturedBeyondViewport(captureObservability, dedupPerfs),
@@ -20024,7 +20058,7 @@ import {
20024
20058
  probeBeginFrameLiveness as probeBeginFrameLiveness2,
20025
20059
  readWebGlVendorInfoFromCanvas,
20026
20060
  resolveConfig as resolveConfig4,
20027
- usableCpuCount as usableCpuCount2
20061
+ usableCpuCount as usableCpuCount3
20028
20062
  } from "@hyperframes/engine";
20029
20063
 
20030
20064
  // src/services/distributed/planV2.ts
@@ -21448,9 +21482,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21448
21482
  const captureSession = session;
21449
21483
  session = null;
21450
21484
  verifyStarted = Date.now();
21451
- overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, usableCpuCount2()) ? encodeWhileCapturing(encodeInput, framesInChunk, {
21485
+ overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, usableCpuCount3()) ? encodeWhileCapturing(encodeInput, framesInChunk, {
21452
21486
  workerCount: chunkWorkerCount,
21453
- cpuCount: usableCpuCount2()
21487
+ cpuCount: usableCpuCount3()
21454
21488
  }) : null;
21455
21489
  await observeRenderStage(
21456
21490
  new RenderObservabilityRecorder({ pipelineStartMs: start, log }),
@@ -42,7 +42,7 @@ import {
42
42
  import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
43
43
 
44
44
  // src/services/renderOrchestrator.ts
45
- import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
45
+ import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
46
46
  import {
47
47
  existsSync as existsSync21,
48
48
  mkdirSync as mkdirSync12,
@@ -420,7 +420,10 @@ import { Readable } from "node:stream";
420
420
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
421
421
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
422
422
  import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
423
- import { PREVIEW_FOR_ANOTHER_SITE_META } from "@hyperframes/core/studio-preview-mark";
423
+ import {
424
+ PREVIEW_FOR_ANOTHER_SITE_META,
425
+ serviceWorkerScriptFetch
426
+ } from "@hyperframes/core/studio-preview-mark";
424
427
  import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
425
428
  import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
426
429
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -1202,6 +1205,12 @@ function createFileServer(options) {
1202
1205
  c.res.headers.set("X-Content-Type-Options", "nosniff");
1203
1206
  });
1204
1207
  answerOwnLoopbackHostOnly(app, () => listeningPort);
1208
+ app.use(async function refuseServiceWorkerScripts(c, next) {
1209
+ const serviceWorker = c.req.header("service-worker");
1210
+ if (!serviceWorkerScriptFetch({ serviceWorker, fetchDest: c.req.header("sec-fetch-dest") }))
1211
+ return next();
1212
+ return c.text("Forbidden", 403);
1213
+ });
1205
1214
  app.get("/*", async (c) => {
1206
1215
  let requestPath = c.req.path;
1207
1216
  if (requestPath === "/") requestPath = "/index.html";
@@ -8139,16 +8148,23 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
8139
8148
  }
8140
8149
  }
8141
8150
  var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
8142
- var mountSrcsUnder = (root) => [...root.querySelectorAll("[data-composition-src]")].map((el) => el.getAttribute("data-composition-src")).filter((srcPath) => !!srcPath && !isUnresolvedAssetPlaceholder(srcPath));
8143
8151
  function compositionSrcsIn(html) {
8144
8152
  const { document: document2 } = parseHTML5(html);
8153
+ const mounts = [];
8145
8154
  const templated = [];
8146
- const templates = [...document2.querySelectorAll("template")];
8147
- for (let template = templates.pop(); template; template = templates.pop()) {
8148
- templated.push(...mountSrcsUnder(template.content));
8149
- templates.push(...template.content.querySelectorAll("template"));
8155
+ const stack = [...document2.children].reverse().map((el) => [el, false]);
8156
+ for (let next = stack.pop(); next; next = stack.pop()) {
8157
+ const [el, inTemplate] = next;
8158
+ const srcPath = el.getAttribute("data-composition-src");
8159
+ if (srcPath && !isUnresolvedAssetPlaceholder(srcPath)) {
8160
+ (inTemplate ? templated : mounts).push(srcPath);
8161
+ }
8162
+ const childrenInTemplate = inTemplate || el.localName === "template";
8163
+ const children = [...el.children];
8164
+ for (let i = children.length - 1; i >= 0; i -= 1)
8165
+ stack.push([children[i], childrenInTemplate]);
8150
8166
  }
8151
- return { mounts: mountSrcsUnder(document2), templated };
8167
+ return { mounts, templated };
8152
8168
  }
8153
8169
  function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
8154
8170
  if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
@@ -13881,7 +13897,7 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
13881
13897
  error: String(failure ?? result?.error)
13882
13898
  }
13883
13899
  );
13884
- return runEncodeStage(input);
13900
+ return runEncodeStage({ ...input, hasAudio: false });
13885
13901
  },
13886
13902
  abort: async () => {
13887
13903
  stop.abort();
@@ -14209,6 +14225,7 @@ var RenderQualityError = class extends Error {
14209
14225
  }
14210
14226
  warnings;
14211
14227
  };
14228
+ var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
14212
14229
  function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
14213
14230
  job.warnings ??= [];
14214
14231
  const existing = new Set(
@@ -15179,8 +15196,14 @@ async function executeRenderPipeline(input) {
15179
15196
  const onProgress = execution.onProgress;
15180
15197
  const tooSlow = new AbortController();
15181
15198
  let tooSlowError;
15199
+ const audioFailed = new AbortController();
15200
+ let audioFailure;
15182
15201
  let calibrationEvaluateTimedOut = false;
15183
- const executionSignal = job.config.maxRenderMs ? AbortSignal.any([tooSlow.signal, ...execution.signal ? [execution.signal] : []]) : execution.signal;
15202
+ const executionSignal = AbortSignal.any([
15203
+ audioFailed.signal,
15204
+ ...job.config.maxRenderMs ? [tooSlow.signal] : [],
15205
+ ...execution.signal ? [execution.signal] : []
15206
+ ]);
15184
15207
  let fileServer = null;
15185
15208
  let probeSession = null;
15186
15209
  let lastBrowserConsole = [];
@@ -16443,33 +16466,41 @@ async function executeRenderPipeline(input) {
16443
16466
  }
16444
16467
  const effectiveQuality = job.config.crf ?? preset.quality;
16445
16468
  const effectiveBitrate = job.config.crf != null ? void 0 : job.config.videoBitrate;
16446
- const audioResult = await audioWait.wait(audioStage);
16447
- const { audioOutputPath, deliverySourcePath, hasAudio } = audioResult;
16448
- perfStages.audioProcessMs = audioResult.audioProcessMs;
16449
- recordLimiterAttenuation(job, audioResult.audioLoweredDb);
16450
- if (audioResult.audioError) {
16451
- const audioFailures = audioResult.audioFailures ?? [];
16452
- const failureOwner = audioFailures.length === 0 ? void 0 : audioFailures.some((failure) => failure.owner === "system") ? "system" : "user";
16453
- const retryable = audioFailures.length === 0 ? void 0 : audioFailures.every((failure) => failure.retryable);
16454
- applyRenderWarningPolicy(
16455
- job,
16456
- [
16457
- {
16458
- code: "audio_processing_failed",
16459
- message: `Audio mix failed; output would be video-only: ${audioResult.audioError}`,
16460
- details: {
16461
- mediaType: "audio",
16462
- audioFailures: audioFailureDiagnostics2(audioFailures),
16463
- failureReasons: [...new Set(audioFailures.map((failure) => failure.reason))],
16464
- failureStages: [...new Set(audioFailures.map((failure) => failure.stage))],
16465
- failureOwner,
16466
- retryable
16469
+ const audioReady = audioStage.then((audioResult) => {
16470
+ perfStages.audioProcessMs = audioResult.audioProcessMs;
16471
+ recordLimiterAttenuation(job, audioResult.audioLoweredDb);
16472
+ if (audioResult.audioError) {
16473
+ const audioFailures = audioResult.audioFailures ?? [];
16474
+ const failureOwner = audioFailures.length === 0 ? void 0 : audioFailures.some((failure) => failure.owner === "system") ? "system" : "user";
16475
+ const retryable = audioFailures.length === 0 ? void 0 : audioFailures.every((failure) => failure.retryable);
16476
+ applyRenderWarningPolicy(
16477
+ job,
16478
+ [
16479
+ {
16480
+ code: "audio_processing_failed",
16481
+ message: `Audio mix failed; output would be video-only: ${audioResult.audioError}`,
16482
+ details: {
16483
+ mediaType: "audio",
16484
+ audioFailures: audioFailureDiagnostics2(audioFailures),
16485
+ failureReasons: [...new Set(audioFailures.map((failure) => failure.reason))],
16486
+ failureStages: [...new Set(audioFailures.map((failure) => failure.stage))],
16487
+ failureOwner,
16488
+ retryable
16489
+ }
16467
16490
  }
16468
- }
16469
- ],
16470
- log
16471
- );
16472
- }
16491
+ ],
16492
+ log
16493
+ );
16494
+ }
16495
+ return audioResult;
16496
+ });
16497
+ audioReady.catch((error) => {
16498
+ if (executionSignal.aborted) return;
16499
+ audioFailure = error;
16500
+ audioFailed.abort(error);
16501
+ });
16502
+ const mixedAudio = () => audioWait.wait(audioReady);
16503
+ if (usableCpuCount2() < MIN_CPUS_TO_CAPTURE_DURING_MIX) await mixedAudio();
16473
16504
  resetCaptureAttemptProgress(job);
16474
16505
  if (capturePlan.kind === "hdr_layered") {
16475
16506
  const layeredPlan = capturePlan;
@@ -16652,7 +16683,7 @@ async function executeRenderPipeline(input) {
16652
16683
  } catch (err) {
16653
16684
  const isVerifyError = isDrawElementVerificationError(err);
16654
16685
  const isDeStall = isDeRendererStallError(err);
16655
- if (!isVerifyError && !isDrawElementCaptureError(err) && !isDeStall || err instanceof RenderCancelledError || executionSignal?.aborted === true) {
16686
+ if (!isVerifyError && !isDrawElementCaptureError(err) && !isDeStall || err instanceof RenderCancelledError || executionSignal.aborted === true) {
16656
16687
  throw err;
16657
16688
  }
16658
16689
  deSelfVerifyFallback = isVerifyError;
@@ -16795,7 +16826,7 @@ async function executeRenderPipeline(input) {
16795
16826
  const isSequentialStall = isSequentialCaptureStallError(err);
16796
16827
  const isParallelStall = isParallelCaptureStallError(err);
16797
16828
  const isEncoderDeath = isRetryableEncoderDeath(err);
16798
- const isCancellation = err instanceof RenderCancelledError || executionSignal?.aborted === true;
16829
+ const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
16799
16830
  if (!shouldRetryViaPinnedFallback({
16800
16831
  isVerifyError,
16801
16832
  isDeCaptureError,
@@ -16924,8 +16955,6 @@ async function executeRenderPipeline(input) {
16924
16955
  height,
16925
16956
  needsAlpha,
16926
16957
  captureImageFormat: captureOptions.format ?? "jpeg",
16927
- hasAudio,
16928
- audioOutputPath,
16929
16958
  isPngSequence,
16930
16959
  isGif,
16931
16960
  preset,
@@ -16978,7 +17007,7 @@ async function executeRenderPipeline(input) {
16978
17007
  captureRes = await invokeDiskCapture(capturePlan);
16979
17008
  } catch (err) {
16980
17009
  await overlap?.abort();
16981
- if (!isDrawElementVerificationError(err) && !isDrawElementCaptureError(err) || err instanceof RenderCancelledError || executionSignal?.aborted === true) {
17010
+ if (!isDrawElementVerificationError(err) && !isDrawElementCaptureError(err) || err instanceof RenderCancelledError || executionSignal.aborted === true) {
16982
17011
  throw err;
16983
17012
  }
16984
17013
  deSelfVerifyFallback = isDrawElementVerificationError(err);
@@ -17037,16 +17066,17 @@ async function executeRenderPipeline(input) {
17037
17066
  perfStages.captureMs = Date.now() - stage4Start;
17038
17067
  perfStages.captureFrameMs = captureFrameMs;
17039
17068
  perfStages.captureSetupMs = Math.max(0, perfStages.captureMs - captureFrameMs);
17069
+ const { hasAudio: hasAudio2, audioOutputPath: audioOutputPath2 } = await mixedAudio();
17040
17070
  const encodeRes = await observeRenderStage(
17041
17071
  observability,
17042
17072
  "encode",
17043
17073
  captureStageObservationData({
17044
- hasAudio,
17074
+ hasAudio: hasAudio2,
17045
17075
  isPngSequence,
17046
17076
  isGif,
17047
17077
  chunkedEncode: enableChunkedEncode
17048
17078
  }),
17049
- () => overlap ? overlap.finish() : runEncodeStage(encodeInput)
17079
+ () => overlap ? overlap.finish() : runEncodeStage({ ...encodeInput, hasAudio: hasAudio2, audioOutputPath: audioOutputPath2 })
17050
17080
  );
17051
17081
  perfStages.encodeMs = encodeRes.encodeMs;
17052
17082
  }
@@ -17066,6 +17096,7 @@ async function executeRenderPipeline(input) {
17066
17096
  if (frameLookup) frameLookup.cleanup();
17067
17097
  closeFileServerSafely(fileServer, "renderOrchestrator", log);
17068
17098
  fileServer = null;
17099
+ const { audioOutputPath, deliverySourcePath, hasAudio } = await mixedAudio();
17069
17100
  if (!isPngSequence && !isGif) {
17070
17101
  const assembleRes = await observeRenderStage(
17071
17102
  observability,
@@ -17201,8 +17232,11 @@ async function executeRenderPipeline(input) {
17201
17232
  framesRendered: job.framesRendered ?? 0,
17202
17233
  error: caught
17203
17234
  });
17204
- const error = surfaceScriptFailure(tooSlowError ?? pageNeverReady ?? caught, job);
17205
- if (!tooSlowError && (error instanceof RenderCancelledError || executionSignal?.aborted)) {
17235
+ const error = surfaceScriptFailure(
17236
+ tooSlowError ?? audioFailure ?? pageNeverReady ?? caught,
17237
+ job
17238
+ );
17239
+ if (!tooSlowError && !audioFailure && (error instanceof RenderCancelledError || executionSignal.aborted)) {
17206
17240
  job.error = error instanceof Error ? error.message : "render_cancelled";
17207
17241
  updateJobStatus(job, "cancelled", "Render cancelled", job.progress, onProgress);
17208
17242
  await eventPublisher.flush();
@@ -17244,7 +17278,7 @@ async function executeRenderPipeline(input) {
17244
17278
  `Parallel capture timed out with ${captureObservability.workerCount ?? "auto"} workers. Video-heavy compositions often need sequential capture. Retry with --workers 1`
17245
17279
  );
17246
17280
  }
17247
- const failedStage = job.currentStage || "pipeline";
17281
+ const failedStage = audioFailure === void 0 ? job.currentStage || "pipeline" : AUDIO_STAGE;
17248
17282
  const observabilitySummary = observability.summary({
17249
17283
  lastBrowserConsole,
17250
17284
  capture: withCapturedBeyondViewport(captureObservability, dedupPerfs),
@@ -12,17 +12,16 @@
12
12
  export declare const isPrivateSitePath: (relPath: string) => boolean;
13
13
  /**
14
14
  * The files a site upload ships, as `/`-separated paths under `projectDir`. Symlinks are followed
15
- * (root included), top-level {@link PLAN_PROJECT_DIR_SKIP_SEGMENTS} are left out as the plan stage
16
- * does, and a dangling symlink throws. Private files (env, Git, credentials, tool and agent state,
17
- * app records) are left out at every depth, by name or by where a link points; `onPrivate` hears
18
- * each one left out, a folder once. With `onOutside`, a file or folder whose link points outside
19
- * the project is left out too, and `onOutside` hears it, a folder once.
15
+ * (root included), out of the project only with `onOutside` `"include"`; top-level
16
+ * {@link PLAN_PROJECT_DIR_SKIP_SEGMENTS} are left out as the plan stage does, and a dangling link
17
+ * throws. Private files (env, Git, credentials, tool and agent state, app records) are left out at
18
+ * every depth, by name or by link target. `onPrivate` and `onOutside` hear each, a folder once.
20
19
  */
21
- export declare function listSiteFiles(projectDir: string, onPrivate?: (relPath: string) => void, onOutside?: (relPath: string) => void): string[];
20
+ export declare function listSiteFiles(projectDir: string, onPrivate?: (relPath: string) => void, onOutside?: ((relPath: string) => void) | "include"): string[];
22
21
  /**
23
22
  * {@link listSiteFiles} for an upload: one line to `onNotice` names the private files left out.
24
- * Files linked in from outside the project ship only with `includeOutsideFiles`; otherwise a second
25
- * line names each one, since the person may not know a link put them in the project.
23
+ * Files linked in from outside ship only with `includeOutsideFiles`, else a second line names them.
24
+ * The upload reads each path again after this check, so a link swapped in meanwhile still ships.
26
25
  */
27
26
  export declare function listSiteFilesForUpload(projectDir: string, onNotice?: (message: string) => void, includeOutsideFiles?: boolean): string[];
28
27
  /**
@@ -100,12 +100,13 @@ export interface EncodeStageInput {
100
100
  */
101
101
  gopSize?: number;
102
102
  }
103
+ export type VideoEncodeInput = Omit<EncodeStageInput, "hasAudio" | "audioOutputPath">;
103
104
  export interface EncodeStageResult {
104
105
  /** Wall-clock ms for the encode (or png-copy) phase. */
105
106
  encodeMs: number;
106
107
  }
107
108
  export declare function overlapEncoderThreads(workerCount: number, cpuCount: number): number;
108
- export declare function videoEncoderOptions(input: EncodeStageInput, engineCfg: Pick<EngineConfig, "vp9CpuUsed">, softwareEncoderThreads?: number): {
109
+ export declare function videoEncoderOptions(input: VideoEncodeInput, engineCfg: Pick<EngineConfig, "vp9CpuUsed">, softwareEncoderThreads?: number): {
109
110
  fps: Fps;
110
111
  width: number;
111
112
  height: number;
@@ -129,7 +130,7 @@ export declare function videoEncoderOptions(input: EncodeStageInput, engineCfg:
129
130
  * h264 from JPEG only, software or GPU: the streaming encoder then runs the disk encoder's
130
131
  * arguments. Needs a core the capture workers leave free.
131
132
  */
132
- export declare function canEncodeWhileCapturing(input: EncodeStageInput, workerCount: number, cpuCount: number): boolean;
133
+ export declare function canEncodeWhileCapturing(input: VideoEncodeInput, workerCount: number, cpuCount: number): boolean;
133
134
  export interface EncodeWhileCapturing {
134
135
  /** A worker finished writing this frame. */
135
136
  onFrameLanded: (frame: LandedFrame) => void;
@@ -144,7 +145,7 @@ export interface EncodeWhileCapturing {
144
145
  * Feeds frames 0, 1, 2… to the encoder as each lands; capture never waits on it.
145
146
  * On failure `finish` re-runs `runEncodeStage` on the same frames.
146
147
  */
147
- export declare function encodeWhileCapturing(input: EncodeStageInput, totalFrames: number, captureBudget?: {
148
+ export declare function encodeWhileCapturing(input: VideoEncodeInput, totalFrames: number, captureBudget?: {
148
149
  workerCount: number;
149
150
  cpuCount: number;
150
151
  }): EncodeWhileCapturing;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.61",
3
+ "version": "0.9.64",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,11 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/lint": "0.9.61",
39
- "@hyperframes/core": "0.9.61",
40
- "@hyperframes/parsers": "0.9.61",
41
- "@hyperframes/studio-server": "0.9.61",
42
- "@hyperframes/engine": "0.9.61"
38
+ "@hyperframes/engine": "0.9.64",
39
+ "@hyperframes/lint": "0.9.64",
40
+ "@hyperframes/core": "0.9.64",
41
+ "@hyperframes/parsers": "0.9.64",
42
+ "@hyperframes/studio-server": "0.9.64"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^25.0.10",
@@ -48,7 +48,7 @@
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.61"
51
+ "@hyperframes/aws-lambda": "0.9.64"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"