@hyperframes/producer 0.9.96 → 0.9.98

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
@@ -4685,6 +4685,15 @@ var OPENING_CAPTURE_SESSION = {
4685
4685
  captureMode: "screenshot",
4686
4686
  captureStep: "opening the capture session"
4687
4687
  };
4688
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
4689
+ try {
4690
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
4691
+ } catch (error) {
4692
+ void opening.then(closeCaptureSession).catch(() => {
4693
+ });
4694
+ throw error;
4695
+ }
4696
+ }
4688
4697
  var OPENING_RISK_SESSION = {
4689
4698
  captureMode: "screenshot",
4690
4699
  captureStep: "opening the screenshot session for effect frames"
@@ -4702,20 +4711,44 @@ var SequentialCaptureStallError = class extends Error {
4702
4711
  };
4703
4712
  function raceAgainstStall(promise, deadlineMs, input, signal) {
4704
4713
  return new Promise((resolve15, reject) => {
4705
- const clock = createStallClock();
4706
- const trip = () => reject(
4707
- signal?.aborted ? new Error(
4708
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4709
- ) : new SequentialCaptureStallError(
4710
- input.session,
4711
- input.stallTimeoutMs,
4712
- input.frameIndex,
4713
- input.totalFrames
4714
- )
4714
+ const abortError3 = () => new Error(
4715
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4715
4716
  );
4717
+ if (signal?.aborted) {
4718
+ promise.catch(() => {
4719
+ });
4720
+ reject(abortError3());
4721
+ return;
4722
+ }
4723
+ const clock = createStallClock();
4724
+ let settled = false;
4725
+ let timer;
4726
+ const cleanup = () => {
4727
+ clearTimeout(timer);
4728
+ signal?.removeEventListener("abort", onAbort);
4729
+ };
4730
+ const onAbort = () => {
4731
+ if (settled) return;
4732
+ settled = true;
4733
+ cleanup();
4734
+ reject(abortError3());
4735
+ };
4736
+ const trip = () => {
4737
+ if (settled) return;
4738
+ settled = true;
4739
+ cleanup();
4740
+ reject(
4741
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
4742
+ input.session,
4743
+ input.stallTimeoutMs,
4744
+ input.frameIndex,
4745
+ input.totalFrames
4746
+ )
4747
+ );
4748
+ };
4749
+ signal?.addEventListener("abort", onAbort, { once: true });
4716
4750
  const deadline = Math.max(0, deadlineMs);
4717
4751
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
4718
- let timer;
4719
4752
  const look = () => {
4720
4753
  const idle = clock.idle(wait);
4721
4754
  if (idle >= deadline) return trip();
@@ -4725,11 +4758,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
4725
4758
  timer = setTimeout(look, wait);
4726
4759
  promise.then(
4727
4760
  (value) => {
4728
- clearTimeout(timer);
4761
+ if (settled) return;
4762
+ settled = true;
4763
+ cleanup();
4729
4764
  resolve15(value);
4730
4765
  },
4731
4766
  (error) => {
4732
- clearTimeout(timer);
4767
+ if (settled) return;
4768
+ settled = true;
4769
+ cleanup();
4733
4770
  reject(error);
4734
4771
  }
4735
4772
  );
@@ -5228,20 +5265,14 @@ async function runCaptureStreamingStage(input) {
5228
5265
  abortSignal
5229
5266
  });
5230
5267
  const openSession = async () => {
5231
- const opening = createCaptureSession(
5232
- fileServer.url,
5233
- framesDir,
5234
- buildCaptureOptions(),
5235
- videoInjector,
5236
- captureCfg
5268
+ assertNotAborted();
5269
+ return openCaptureSessionWithinBudget(
5270
+ withinInitBudget,
5271
+ createCaptureSession(fileServer.url, framesDir, buildCaptureOptions(), videoInjector, {
5272
+ ...captureCfg,
5273
+ signal: abortSignal
5274
+ })
5237
5275
  );
5238
- try {
5239
- return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
5240
- } catch (error) {
5241
- void opening.then(closeCaptureSession, () => {
5242
- });
5243
- throw error;
5244
- }
5245
5276
  };
5246
5277
  const session = probeSession ?? await openSession();
5247
5278
  captureBeyondViewport = session.options.captureBeyondViewport;
@@ -5261,7 +5292,8 @@ async function runCaptureStreamingStage(input) {
5261
5292
  ...captureCfg,
5262
5293
  useDrawElement: false,
5263
5294
  staticFrameDedup: false,
5264
- enableBrowserPool: false
5295
+ enableBrowserPool: false,
5296
+ signal: abortSignal
5265
5297
  }
5266
5298
  );
5267
5299
  if (attemptClosed) {
@@ -5424,17 +5456,23 @@ async function captureSegmentFrames(ctx, segment, encoder) {
5424
5456
  for (let i = segment.startFrame; i < segment.endFrame; i++) {
5425
5457
  ctx.assertNotAborted();
5426
5458
  const time = i * ctx.job.config.fps.den / ctx.job.config.fps.num;
5427
- const { buffer } = await raceAgainstStall(
5428
- ctx.captureFrame(ctx.session, i, time),
5429
- ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5430
- {
5431
- session: ctx.session,
5432
- frameIndex: i,
5433
- totalFrames: ctx.totalFrames,
5434
- stallTimeoutMs: ctx.stallTimeoutMs
5435
- },
5436
- ctx.abortSignal
5437
- );
5459
+ let buffer;
5460
+ try {
5461
+ ({ buffer } = await raceAgainstStall(
5462
+ ctx.captureFrame(ctx.session, i, time),
5463
+ ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5464
+ {
5465
+ session: ctx.session,
5466
+ frameIndex: i,
5467
+ totalFrames: ctx.totalFrames,
5468
+ stallTimeoutMs: ctx.stallTimeoutMs
5469
+ },
5470
+ ctx.abortSignal
5471
+ ));
5472
+ } catch (error) {
5473
+ if (ctx.abortSignal?.aborted) ctx.assertNotAborted();
5474
+ throw error;
5475
+ }
5438
5476
  await verifyDrawElementSample(ctx.session, i, buffer, {
5439
5477
  log: ctx.log,
5440
5478
  verifyMinDb: ctx.verifyMinDb
@@ -13523,25 +13561,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
13523
13561
  assertNotAborted();
13524
13562
  attempt?.throwIfAborted();
13525
13563
  };
13564
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
13565
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
13526
13566
  const videoInjector = createRenderVideoFrameInjector();
13527
- const session = probeSession ?? await createCaptureSession5(
13528
- fileServer.url,
13567
+ const session = probeSession ?? await openSequentialDiskSession({
13568
+ assertAttemptActive,
13569
+ initBudget,
13570
+ fileServerUrl: fileServer.url,
13529
13571
  framesDir,
13530
13572
  captureOptions,
13531
13573
  videoInjector,
13532
- captureCfg
13533
- );
13574
+ captureCfg,
13575
+ attemptSignal
13576
+ });
13534
13577
  captureBeyondViewport = session.options.captureBeyondViewport;
13535
13578
  try {
13536
13579
  if (probeSession) {
13537
13580
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
13538
13581
  probeSession = null;
13539
13582
  }
13540
- await ensureSessionReady(session, {
13541
- frameIndex: resumeFrom,
13542
- totalFrames,
13543
- abortSignal: input.abortSignal
13544
- });
13583
+ await ensureSessionReady(session, initBudget);
13545
13584
  assertAttemptActive();
13546
13585
  lastBrowserConsole = session.browserConsoleBuffer;
13547
13586
  await captureSessionFrames(session, {
@@ -13593,9 +13632,26 @@ function planTransientResume(error, ctx) {
13593
13632
  if (!firstMissing) return null;
13594
13633
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
13595
13634
  }
13635
+ function combineAbortSignals(first, second) {
13636
+ if (first && second) return AbortSignal.any([first, second]);
13637
+ return second ?? first;
13638
+ }
13639
+ async function openSequentialDiskSession(args) {
13640
+ args.assertAttemptActive();
13641
+ return openCaptureSessionWithinBudget(
13642
+ createSessionInitBudget(args.initBudget),
13643
+ createCaptureSession5(
13644
+ args.fileServerUrl,
13645
+ args.framesDir,
13646
+ args.captureOptions,
13647
+ args.videoInjector,
13648
+ { ...args.captureCfg, signal: args.attemptSignal }
13649
+ )
13650
+ );
13651
+ }
13596
13652
  async function ensureSessionReady(session, budget) {
13597
13653
  if (!session.isInitialized) {
13598
- await initializeSession5(session);
13654
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
13599
13655
  return;
13600
13656
  }
13601
13657
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
@@ -14397,12 +14453,17 @@ async function runCaptureHdrStage(input) {
14397
14453
  projectDir,
14398
14454
  compiledDir
14399
14455
  });
14400
- const domSession = await createCaptureSession7(
14401
- fileServer.url,
14402
- framesDir,
14403
- buildCaptureOptions(),
14404
- createRenderVideoFrameInjector(),
14405
- hdrCfg
14456
+ assertNotAborted();
14457
+ const withinInitBudget = createSessionInitBudget({ frameIndex: 0, totalFrames, abortSignal });
14458
+ const domSession = await openCaptureSessionWithinBudget(
14459
+ withinInitBudget,
14460
+ createCaptureSession7(
14461
+ fileServer.url,
14462
+ framesDir,
14463
+ buildCaptureOptions(),
14464
+ createRenderVideoFrameInjector(),
14465
+ { ...hdrCfg, signal: abortSignal }
14466
+ )
14406
14467
  );
14407
14468
  let hdrEncoder = null;
14408
14469
  let hdrEncoderClosed = false;
@@ -14411,7 +14472,7 @@ async function runCaptureHdrStage(input) {
14411
14472
  let releaseHdrImageReservation = null;
14412
14473
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
14413
14474
  try {
14414
- await initializeSession7(domSession);
14475
+ await withinInitBudget(initializeSession7(domSession), domSession);
14415
14476
  assertNotAborted();
14416
14477
  lastBrowserConsole = domSession.browserConsoleBuffer;
14417
14478
  await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
@@ -16367,6 +16428,9 @@ async function executeRenderPipeline(input) {
16367
16428
  memSampler = createMemorySampler();
16368
16429
  const assertNotAborted = () => {
16369
16430
  execution.assertActive(() => new RenderCancelledError("render_cancelled"));
16431
+ if (executionSignal.aborted) {
16432
+ throw tooSlowError ?? audioFailure ?? new RenderCancelledError("render_cancelled");
16433
+ }
16370
16434
  };
16371
16435
  job.startedAt = /* @__PURE__ */ new Date();
16372
16436
  assertNotAborted();
@@ -23319,6 +23383,20 @@ function assertRequestOptionScalars(options) {
23319
23383
  throw new Error("Render request outputResolution is invalid");
23320
23384
  }
23321
23385
  }
23386
+ function isRenderRange(value) {
23387
+ if (!isPlainObject(value)) return false;
23388
+ const seconds = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
23389
+ const { startSeconds, endSeconds } = value;
23390
+ if (!seconds(startSeconds)) return false;
23391
+ return endSeconds === void 0 || seconds(endSeconds) && Number(endSeconds) > Number(startSeconds);
23392
+ }
23393
+ function assertRequestRange(options) {
23394
+ if (options.range !== void 0 && !isRenderRange(options.range)) {
23395
+ throw new Error(
23396
+ "Render request range must be { startSeconds, endSeconds? } in seconds, end after start"
23397
+ );
23398
+ }
23399
+ }
23322
23400
  function assertRequestOptionObjects(options) {
23323
23401
  validateEngineConfigSnapshot2(options.engineConfig);
23324
23402
  if (options.expectedOutputDimensions !== void 0 && !isExpectedOutputDimensions(options.expectedOutputDimensions)) {
@@ -23345,6 +23423,7 @@ function assertRequestOptions(options) {
23345
23423
  }
23346
23424
  assertRequestOptionScalars(options);
23347
23425
  assertRequestOptionObjects(options);
23426
+ assertRequestRange(options);
23348
23427
  }
23349
23428
  function assertNonEmptyPath(value, field) {
23350
23429
  if (typeof value !== "string" || value.length === 0) {
@@ -23403,6 +23482,8 @@ function distributedConfigFromRequest(request, runtime = {}) {
23403
23482
  const options = request.options;
23404
23483
  const distributed = options.distributed;
23405
23484
  if (!distributed) throw new Error("Render request is missing distributed options");
23485
+ if (options.range)
23486
+ throw new Error("A distributed render takes its range from renderSpan, not the request");
23406
23487
  if (options.format === "gif" || options.format === "hls") {
23407
23488
  throw new Error(`Distributed render does not support ${options.format}`);
23408
23489
  }
@@ -4723,6 +4723,15 @@ var OPENING_CAPTURE_SESSION = {
4723
4723
  captureMode: "screenshot",
4724
4724
  captureStep: "opening the capture session"
4725
4725
  };
4726
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
4727
+ try {
4728
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
4729
+ } catch (error) {
4730
+ void opening.then(closeCaptureSession).catch(() => {
4731
+ });
4732
+ throw error;
4733
+ }
4734
+ }
4726
4735
  var OPENING_RISK_SESSION = {
4727
4736
  captureMode: "screenshot",
4728
4737
  captureStep: "opening the screenshot session for effect frames"
@@ -4740,20 +4749,44 @@ var SequentialCaptureStallError = class extends Error {
4740
4749
  };
4741
4750
  function raceAgainstStall(promise, deadlineMs, input, signal) {
4742
4751
  return new Promise((resolve13, reject) => {
4743
- const clock = createStallClock();
4744
- const trip = () => reject(
4745
- signal?.aborted ? new Error(
4746
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4747
- ) : new SequentialCaptureStallError(
4748
- input.session,
4749
- input.stallTimeoutMs,
4750
- input.frameIndex,
4751
- input.totalFrames
4752
- )
4752
+ const abortError3 = () => new Error(
4753
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4753
4754
  );
4755
+ if (signal?.aborted) {
4756
+ promise.catch(() => {
4757
+ });
4758
+ reject(abortError3());
4759
+ return;
4760
+ }
4761
+ const clock = createStallClock();
4762
+ let settled = false;
4763
+ let timer;
4764
+ const cleanup = () => {
4765
+ clearTimeout(timer);
4766
+ signal?.removeEventListener("abort", onAbort);
4767
+ };
4768
+ const onAbort = () => {
4769
+ if (settled) return;
4770
+ settled = true;
4771
+ cleanup();
4772
+ reject(abortError3());
4773
+ };
4774
+ const trip = () => {
4775
+ if (settled) return;
4776
+ settled = true;
4777
+ cleanup();
4778
+ reject(
4779
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
4780
+ input.session,
4781
+ input.stallTimeoutMs,
4782
+ input.frameIndex,
4783
+ input.totalFrames
4784
+ )
4785
+ );
4786
+ };
4787
+ signal?.addEventListener("abort", onAbort, { once: true });
4754
4788
  const deadline = Math.max(0, deadlineMs);
4755
4789
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
4756
- let timer;
4757
4790
  const look = () => {
4758
4791
  const idle = clock.idle(wait);
4759
4792
  if (idle >= deadline) return trip();
@@ -4763,11 +4796,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
4763
4796
  timer = setTimeout(look, wait);
4764
4797
  promise.then(
4765
4798
  (value) => {
4766
- clearTimeout(timer);
4799
+ if (settled) return;
4800
+ settled = true;
4801
+ cleanup();
4767
4802
  resolve13(value);
4768
4803
  },
4769
4804
  (error) => {
4770
- clearTimeout(timer);
4805
+ if (settled) return;
4806
+ settled = true;
4807
+ cleanup();
4771
4808
  reject(error);
4772
4809
  }
4773
4810
  );
@@ -5266,20 +5303,14 @@ async function runCaptureStreamingStage(input) {
5266
5303
  abortSignal
5267
5304
  });
5268
5305
  const openSession = async () => {
5269
- const opening = createCaptureSession(
5270
- fileServer.url,
5271
- framesDir,
5272
- buildCaptureOptions(),
5273
- videoInjector,
5274
- captureCfg
5306
+ assertNotAborted();
5307
+ return openCaptureSessionWithinBudget(
5308
+ withinInitBudget,
5309
+ createCaptureSession(fileServer.url, framesDir, buildCaptureOptions(), videoInjector, {
5310
+ ...captureCfg,
5311
+ signal: abortSignal
5312
+ })
5275
5313
  );
5276
- try {
5277
- return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
5278
- } catch (error) {
5279
- void opening.then(closeCaptureSession, () => {
5280
- });
5281
- throw error;
5282
- }
5283
5314
  };
5284
5315
  const session = probeSession ?? await openSession();
5285
5316
  captureBeyondViewport = session.options.captureBeyondViewport;
@@ -5299,7 +5330,8 @@ async function runCaptureStreamingStage(input) {
5299
5330
  ...captureCfg,
5300
5331
  useDrawElement: false,
5301
5332
  staticFrameDedup: false,
5302
- enableBrowserPool: false
5333
+ enableBrowserPool: false,
5334
+ signal: abortSignal
5303
5335
  }
5304
5336
  );
5305
5337
  if (attemptClosed) {
@@ -5462,17 +5494,23 @@ async function captureSegmentFrames(ctx, segment, encoder) {
5462
5494
  for (let i = segment.startFrame; i < segment.endFrame; i++) {
5463
5495
  ctx.assertNotAborted();
5464
5496
  const time = i * ctx.job.config.fps.den / ctx.job.config.fps.num;
5465
- const { buffer } = await raceAgainstStall(
5466
- ctx.captureFrame(ctx.session, i, time),
5467
- ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5468
- {
5469
- session: ctx.session,
5470
- frameIndex: i,
5471
- totalFrames: ctx.totalFrames,
5472
- stallTimeoutMs: ctx.stallTimeoutMs
5473
- },
5474
- ctx.abortSignal
5475
- );
5497
+ let buffer;
5498
+ try {
5499
+ ({ buffer } = await raceAgainstStall(
5500
+ ctx.captureFrame(ctx.session, i, time),
5501
+ ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5502
+ {
5503
+ session: ctx.session,
5504
+ frameIndex: i,
5505
+ totalFrames: ctx.totalFrames,
5506
+ stallTimeoutMs: ctx.stallTimeoutMs
5507
+ },
5508
+ ctx.abortSignal
5509
+ ));
5510
+ } catch (error) {
5511
+ if (ctx.abortSignal?.aborted) ctx.assertNotAborted();
5512
+ throw error;
5513
+ }
5476
5514
  await verifyDrawElementSample(ctx.session, i, buffer, {
5477
5515
  log: ctx.log,
5478
5516
  verifyMinDb: ctx.verifyMinDb
@@ -13505,25 +13543,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
13505
13543
  assertNotAborted();
13506
13544
  attempt?.throwIfAborted();
13507
13545
  };
13546
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
13547
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
13508
13548
  const videoInjector = createRenderVideoFrameInjector();
13509
- const session = probeSession ?? await createCaptureSession5(
13510
- fileServer.url,
13549
+ const session = probeSession ?? await openSequentialDiskSession({
13550
+ assertAttemptActive,
13551
+ initBudget,
13552
+ fileServerUrl: fileServer.url,
13511
13553
  framesDir,
13512
13554
  captureOptions,
13513
13555
  videoInjector,
13514
- captureCfg
13515
- );
13556
+ captureCfg,
13557
+ attemptSignal
13558
+ });
13516
13559
  captureBeyondViewport = session.options.captureBeyondViewport;
13517
13560
  try {
13518
13561
  if (probeSession) {
13519
13562
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
13520
13563
  probeSession = null;
13521
13564
  }
13522
- await ensureSessionReady(session, {
13523
- frameIndex: resumeFrom,
13524
- totalFrames,
13525
- abortSignal: input.abortSignal
13526
- });
13565
+ await ensureSessionReady(session, initBudget);
13527
13566
  assertAttemptActive();
13528
13567
  lastBrowserConsole = session.browserConsoleBuffer;
13529
13568
  await captureSessionFrames(session, {
@@ -13575,9 +13614,26 @@ function planTransientResume(error, ctx) {
13575
13614
  if (!firstMissing) return null;
13576
13615
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
13577
13616
  }
13617
+ function combineAbortSignals(first, second) {
13618
+ if (first && second) return AbortSignal.any([first, second]);
13619
+ return second ?? first;
13620
+ }
13621
+ async function openSequentialDiskSession(args) {
13622
+ args.assertAttemptActive();
13623
+ return openCaptureSessionWithinBudget(
13624
+ createSessionInitBudget(args.initBudget),
13625
+ createCaptureSession5(
13626
+ args.fileServerUrl,
13627
+ args.framesDir,
13628
+ args.captureOptions,
13629
+ args.videoInjector,
13630
+ { ...args.captureCfg, signal: args.attemptSignal }
13631
+ )
13632
+ );
13633
+ }
13578
13634
  async function ensureSessionReady(session, budget) {
13579
13635
  if (!session.isInitialized) {
13580
- await initializeSession5(session);
13636
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
13581
13637
  return;
13582
13638
  }
13583
13639
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
@@ -14379,12 +14435,17 @@ async function runCaptureHdrStage(input) {
14379
14435
  projectDir,
14380
14436
  compiledDir
14381
14437
  });
14382
- const domSession = await createCaptureSession7(
14383
- fileServer.url,
14384
- framesDir,
14385
- buildCaptureOptions(),
14386
- createRenderVideoFrameInjector(),
14387
- hdrCfg
14438
+ assertNotAborted();
14439
+ const withinInitBudget = createSessionInitBudget({ frameIndex: 0, totalFrames, abortSignal });
14440
+ const domSession = await openCaptureSessionWithinBudget(
14441
+ withinInitBudget,
14442
+ createCaptureSession7(
14443
+ fileServer.url,
14444
+ framesDir,
14445
+ buildCaptureOptions(),
14446
+ createRenderVideoFrameInjector(),
14447
+ { ...hdrCfg, signal: abortSignal }
14448
+ )
14388
14449
  );
14389
14450
  let hdrEncoder = null;
14390
14451
  let hdrEncoderClosed = false;
@@ -14393,7 +14454,7 @@ async function runCaptureHdrStage(input) {
14393
14454
  let releaseHdrImageReservation = null;
14394
14455
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
14395
14456
  try {
14396
- await initializeSession7(domSession);
14457
+ await withinInitBudget(initializeSession7(domSession), domSession);
14397
14458
  assertNotAborted();
14398
14459
  lastBrowserConsole = domSession.browserConsoleBuffer;
14399
14460
  await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
@@ -16349,6 +16410,9 @@ async function executeRenderPipeline(input) {
16349
16410
  memSampler = createMemorySampler();
16350
16411
  const assertNotAborted = () => {
16351
16412
  execution.assertActive(() => new RenderCancelledError("render_cancelled"));
16413
+ if (executionSignal.aborted) {
16414
+ throw tooSlowError ?? audioFailure ?? new RenderCancelledError("render_cancelled");
16415
+ }
16352
16416
  };
16353
16417
  job.startedAt = /* @__PURE__ */ new Date();
16354
16418
  assertNotAborted();
@@ -19145,6 +19209,20 @@ function assertRequestOptionScalars(options) {
19145
19209
  throw new Error("Render request outputResolution is invalid");
19146
19210
  }
19147
19211
  }
19212
+ function isRenderRange(value) {
19213
+ if (!isPlainObject(value)) return false;
19214
+ const seconds = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
19215
+ const { startSeconds, endSeconds } = value;
19216
+ if (!seconds(startSeconds)) return false;
19217
+ return endSeconds === void 0 || seconds(endSeconds) && Number(endSeconds) > Number(startSeconds);
19218
+ }
19219
+ function assertRequestRange(options) {
19220
+ if (options.range !== void 0 && !isRenderRange(options.range)) {
19221
+ throw new Error(
19222
+ "Render request range must be { startSeconds, endSeconds? } in seconds, end after start"
19223
+ );
19224
+ }
19225
+ }
19148
19226
  function assertRequestOptionObjects(options) {
19149
19227
  validateEngineConfigSnapshot2(options.engineConfig);
19150
19228
  if (options.expectedOutputDimensions !== void 0 && !isExpectedOutputDimensions(options.expectedOutputDimensions)) {
@@ -19171,6 +19249,7 @@ function assertRequestOptions(options) {
19171
19249
  }
19172
19250
  assertRequestOptionScalars(options);
19173
19251
  assertRequestOptionObjects(options);
19252
+ assertRequestRange(options);
19174
19253
  }
19175
19254
  function assertNonEmptyPath(value, field) {
19176
19255
  if (typeof value !== "string" || value.length === 0) {
@@ -3,6 +3,7 @@ import { type EngineConfig, type ProresProfile, type VideoFrameFormat } from "@h
3
3
  import { type CanvasResolution, type Fps } from "@hyperframes/core";
4
4
  import type { ProducerLogger } from "./logger.js";
5
5
  import type { RenderConfig } from "./services/renderOrchestrator.js";
6
+ import type { RenderRange } from "./services/render/frameWindow.js";
6
7
  import type { DistributedRenderConfig } from "./services/distributed/plan.js";
7
8
  import { type SerializableDistributedRenderConfig } from "./services/distributed/renderConfigValidation.js";
8
9
  export declare const RENDER_REQUEST_VERSION: 1;
@@ -47,6 +48,7 @@ export interface RenderRequestOptions {
47
48
  hdrMode?: RenderConfig["hdrMode"];
48
49
  chromaSubsampling?: RenderConfig["chromaSubsampling"];
49
50
  pageMotionBlur?: RenderConfig["pageMotionBlur"];
51
+ range?: RenderRange;
50
52
  variables?: Record<string, unknown>;
51
53
  strictVariables?: boolean;
52
54
  expectedOutputDimensions?: ExpectedOutputDimensions;
@@ -49,6 +49,7 @@ export type StalledSession = {
49
49
  captureStep?: string;
50
50
  };
51
51
  export declare const OPENING_CAPTURE_SESSION: StalledSession;
52
+ export declare function openCaptureSessionWithinBudget(withinInitBudget: ReturnType<typeof createSessionInitBudget>, opening: Promise<CaptureSession>): Promise<CaptureSession>;
52
53
  export declare function raceAgainstStall<T>(promise: Promise<T>, deadlineMs: number, input: {
53
54
  session: StalledSession;
54
55
  frameIndex: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.96",
3
+ "version": "0.9.98",
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/core": "0.9.96",
39
- "@hyperframes/engine": "0.9.96",
40
- "@hyperframes/parsers": "0.9.96",
41
- "@hyperframes/lint": "0.9.96",
42
- "@hyperframes/studio-server": "0.9.96"
38
+ "@hyperframes/core": "0.9.98",
39
+ "@hyperframes/lint": "0.9.98",
40
+ "@hyperframes/parsers": "0.9.98",
41
+ "@hyperframes/studio-server": "0.9.98",
42
+ "@hyperframes/engine": "0.9.98"
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.96"
51
+ "@hyperframes/aws-lambda": "0.9.98"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"