@hyperframes/producer 0.9.91 → 0.9.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/dist/compileWorker.js +3 -3
- package/dist/distributed.js +6 -5
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/index.js +225 -133
- package/dist/public-server.js +227 -133
- package/dist/server.d.ts +7 -2
- package/dist/services/hdrCompositor.d.ts +7 -0
- package/dist/services/renderOrchestrator.d.ts +7 -0
- package/package.json +7 -7
package/dist/public-server.js
CHANGED
|
@@ -31,8 +31,9 @@ import {
|
|
|
31
31
|
rmSync as rmSync14,
|
|
32
32
|
createReadStream as createReadStream4
|
|
33
33
|
} from "node:fs";
|
|
34
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
34
35
|
import { basename as basename8, resolve as resolve11, dirname as dirname19, join as join40 } from "node:path";
|
|
35
|
-
import { tmpdir as tmpdir4 } from "node:os";
|
|
36
|
+
import { homedir, tmpdir as tmpdir4 } from "node:os";
|
|
36
37
|
import { parseArgs } from "node:util";
|
|
37
38
|
import { isIP } from "node:net";
|
|
38
39
|
import crypto from "node:crypto";
|
|
@@ -3093,6 +3094,7 @@ import {
|
|
|
3093
3094
|
import { readSync as readSync2 } from "fs";
|
|
3094
3095
|
import { join as join7 } from "path";
|
|
3095
3096
|
import {
|
|
3097
|
+
TRANSITIONS,
|
|
3096
3098
|
captureAlphaPng,
|
|
3097
3099
|
applyDomLayerMask,
|
|
3098
3100
|
removeDomLayerMask,
|
|
@@ -3129,6 +3131,31 @@ function isAffineMatrix(m) {
|
|
|
3129
3131
|
function resolveBlitOpacity(opacity) {
|
|
3130
3132
|
return opacity < OPAQUE_ALPHA_THRESHOLD ? opacity : void 0;
|
|
3131
3133
|
}
|
|
3134
|
+
var isTime = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
|
|
3135
|
+
function sanitizeTransitionMeta(raw, warn) {
|
|
3136
|
+
if (!Array.isArray(raw)) return [];
|
|
3137
|
+
const kept = [];
|
|
3138
|
+
for (const [index, entry] of raw.entries()) {
|
|
3139
|
+
if (typeof entry !== "object" || entry === null || !isTime(entry.time) || !isTime(entry.duration) || typeof entry.fromScene !== "string" || typeof entry.toScene !== "string") {
|
|
3140
|
+
warn("[Render] Ignoring malformed shader transition entry", { index });
|
|
3141
|
+
continue;
|
|
3142
|
+
}
|
|
3143
|
+
const { shader } = entry;
|
|
3144
|
+
const known = typeof shader === "string" && Object.hasOwn(TRANSITIONS, shader);
|
|
3145
|
+
if (shader !== void 0 && !known) {
|
|
3146
|
+
warn("[Render] Unknown shader transition; using crossfade", { index });
|
|
3147
|
+
}
|
|
3148
|
+
kept.push({
|
|
3149
|
+
time: entry.time,
|
|
3150
|
+
duration: entry.duration,
|
|
3151
|
+
ease: typeof entry.ease === "string" ? entry.ease : "",
|
|
3152
|
+
fromScene: entry.fromScene,
|
|
3153
|
+
toScene: entry.toScene,
|
|
3154
|
+
...known ? { shader } : {}
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3157
|
+
return kept;
|
|
3158
|
+
}
|
|
3132
3159
|
function cropRgb48le(src, srcW, srcH, cropX, cropY, cropW, cropH) {
|
|
3133
3160
|
const dst = Buffer.alloc(cropW * cropH * RGB48_BYTES_PER_PIXEL);
|
|
3134
3161
|
for (let row = 0; row < cropH; row++) {
|
|
@@ -9512,7 +9539,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
9512
9539
|
}
|
|
9513
9540
|
let result = html;
|
|
9514
9541
|
for (const [url, relPath] of urlToRelPath) {
|
|
9515
|
-
result = result.replaceAll(`"${url}"`, `"${relPath}"`).replaceAll(`'${url}'`, `'${relPath}'`);
|
|
9542
|
+
result = result.replaceAll(`"${url}"`, () => `"${relPath}"`).replaceAll(`'${url}'`, () => `'${relPath}'`);
|
|
9516
9543
|
if (extraRewrite) result = extraRewrite(result, url, relPath);
|
|
9517
9544
|
}
|
|
9518
9545
|
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
@@ -9567,7 +9594,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir, assets) {
|
|
|
9567
9594
|
assets,
|
|
9568
9595
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
9569
9596
|
// replaceAll; this handles the unquoted url(https://..) form.
|
|
9570
|
-
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
9597
|
+
(h, url, rel) => h.replaceAll(`url(${url})`, () => `url(${rel})`)
|
|
9571
9598
|
);
|
|
9572
9599
|
}
|
|
9573
9600
|
function isGoogleFontsUrl(href) {
|
|
@@ -9734,7 +9761,7 @@ function localizeFontFaceUrls(html, downloadDir, assets) {
|
|
|
9734
9761
|
style,
|
|
9735
9762
|
css,
|
|
9736
9763
|
"</style>".length,
|
|
9737
|
-
css.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9764
|
+
css.replaceAll(`url(${url})`, () => `url("${relPath}")`)
|
|
9738
9765
|
)
|
|
9739
9766
|
)
|
|
9740
9767
|
);
|
|
@@ -13575,7 +13602,7 @@ function createHdrImageTransferCache(options = {}) {
|
|
|
13575
13602
|
// src/services/render/stages/captureHdrSequentialLoop.ts
|
|
13576
13603
|
import { join as join30 } from "node:path";
|
|
13577
13604
|
import {
|
|
13578
|
-
TRANSITIONS,
|
|
13605
|
+
TRANSITIONS as TRANSITIONS2,
|
|
13579
13606
|
crossfade
|
|
13580
13607
|
} from "@hyperframes/engine";
|
|
13581
13608
|
async function runSequentialLayeredFrameLoop(input) {
|
|
@@ -13673,7 +13700,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13673
13700
|
});
|
|
13674
13701
|
}
|
|
13675
13702
|
const shaderName = activeTransition.shader;
|
|
13676
|
-
const transitionFn = shaderName ?
|
|
13703
|
+
const transitionFn = shaderName ? TRANSITIONS2[shaderName] ?? crossfade : crossfade;
|
|
13677
13704
|
transitionFn(
|
|
13678
13705
|
transitionBuffers.bufferA,
|
|
13679
13706
|
transitionBuffers.bufferB,
|
|
@@ -13732,7 +13759,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13732
13759
|
// src/services/render/stages/captureHdrHybridLoop.ts
|
|
13733
13760
|
import { join as join32 } from "node:path";
|
|
13734
13761
|
import {
|
|
13735
|
-
TRANSITIONS as
|
|
13762
|
+
TRANSITIONS as TRANSITIONS3,
|
|
13736
13763
|
closeCaptureSession as closeCaptureSession6,
|
|
13737
13764
|
createCaptureSession as createCaptureSession6,
|
|
13738
13765
|
createFrameReorderBuffer as createFrameReorderBuffer2,
|
|
@@ -14017,6 +14044,15 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14017
14044
|
const workerRanges = distributeLayeredHybridFrameRanges(totalFrames, activeWorkerCount);
|
|
14018
14045
|
let framesWritten = 0;
|
|
14019
14046
|
const reorderBuffer = createFrameReorderBuffer2(0, totalFrames);
|
|
14047
|
+
let failure = null;
|
|
14048
|
+
const fail = (err) => {
|
|
14049
|
+
if (failure) return;
|
|
14050
|
+
failure = err instanceof Error ? err : new Error(String(err));
|
|
14051
|
+
reorderBuffer.abort(failure);
|
|
14052
|
+
};
|
|
14053
|
+
const throwIfFailed = () => {
|
|
14054
|
+
if (failure) throw failure;
|
|
14055
|
+
};
|
|
14020
14056
|
const writeEncoded = async (frameIdx, buf) => {
|
|
14021
14057
|
await reorderBuffer.waitForFrame(frameIdx);
|
|
14022
14058
|
const writeStart = Date.now();
|
|
@@ -14043,103 +14079,108 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14043
14079
|
if (!session || !canvas || !range) return;
|
|
14044
14080
|
const ringInFlight = ring ? ring.map(() => null) : [];
|
|
14045
14081
|
let nextRingIdx = 0;
|
|
14046
|
-
|
|
14047
|
-
|
|
14048
|
-
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
const
|
|
14052
|
-
|
|
14053
|
-
|
|
14054
|
-
|
|
14055
|
-
|
|
14056
|
-
|
|
14057
|
-
|
|
14058
|
-
|
|
14059
|
-
|
|
14060
|
-
|
|
14061
|
-
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
|
|
14065
|
-
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14081
|
-
|
|
14082
|
-
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
|
|
14087
|
-
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
|
|
14101
|
-
|
|
14102
|
-
|
|
14082
|
+
try {
|
|
14083
|
+
for (let i = range.start; i < range.end; i++) {
|
|
14084
|
+
throwIfFailed();
|
|
14085
|
+
assertNotAborted();
|
|
14086
|
+
const time = i * job.config.fps.den / job.config.fps.num;
|
|
14087
|
+
const activeTransition = transitionFramesSet.has(i) ? transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame) : void 0;
|
|
14088
|
+
if (activeTransition && ring) {
|
|
14089
|
+
const slot = nextRingIdx;
|
|
14090
|
+
nextRingIdx = (nextRingIdx + 1) % TRANSITION_RING_DEPTH;
|
|
14091
|
+
const prev = ringInFlight[slot];
|
|
14092
|
+
if (prev) await prev;
|
|
14093
|
+
throwIfFailed();
|
|
14094
|
+
const buffers = ring[slot];
|
|
14095
|
+
if (!buffers) continue;
|
|
14096
|
+
await captureTransitionFrameOnWorker({
|
|
14097
|
+
session,
|
|
14098
|
+
frameIdx: i,
|
|
14099
|
+
time,
|
|
14100
|
+
transition: activeTransition,
|
|
14101
|
+
buffers,
|
|
14102
|
+
nativeHdrIds,
|
|
14103
|
+
nativeHdrImageIds,
|
|
14104
|
+
sceneElements,
|
|
14105
|
+
hdrCompositeCtx,
|
|
14106
|
+
width,
|
|
14107
|
+
height,
|
|
14108
|
+
compositeTransfer,
|
|
14109
|
+
hdrTargetTransfer,
|
|
14110
|
+
hdrPerf,
|
|
14111
|
+
log
|
|
14112
|
+
});
|
|
14113
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (i - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
14114
|
+
const frameIdx = i;
|
|
14115
|
+
const shaderName = activeTransition.shader;
|
|
14116
|
+
const dispatch = (async () => {
|
|
14117
|
+
if (poolRef && shaderName) {
|
|
14118
|
+
const blendStart = Date.now();
|
|
14119
|
+
const result = await poolRef.run({
|
|
14120
|
+
shader: shaderName,
|
|
14121
|
+
bufferA: buffers.bufferA,
|
|
14122
|
+
bufferB: buffers.bufferB,
|
|
14123
|
+
output: buffers.output,
|
|
14124
|
+
width,
|
|
14125
|
+
height,
|
|
14126
|
+
progress
|
|
14127
|
+
});
|
|
14128
|
+
buffers.bufferA = result.bufferA;
|
|
14129
|
+
buffers.bufferB = result.bufferB;
|
|
14130
|
+
buffers.output = result.output;
|
|
14131
|
+
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14132
|
+
} else {
|
|
14133
|
+
const transitionFn = shaderName ? TRANSITIONS3[shaderName] ?? crossfade2 : crossfade2;
|
|
14134
|
+
const blendStart = Date.now();
|
|
14135
|
+
transitionFn(
|
|
14136
|
+
buffers.bufferA,
|
|
14137
|
+
buffers.bufferB,
|
|
14138
|
+
buffers.output,
|
|
14139
|
+
width,
|
|
14140
|
+
height,
|
|
14141
|
+
progress
|
|
14142
|
+
);
|
|
14143
|
+
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14144
|
+
}
|
|
14145
|
+
await writeEncoded(frameIdx, buffers.output);
|
|
14146
|
+
})();
|
|
14147
|
+
ringInFlight[slot] = dispatch.then(() => void 0, fail);
|
|
14148
|
+
} else {
|
|
14149
|
+
const stackingInfo = await seekInjectAndQueryStacking(
|
|
14150
|
+
session.page,
|
|
14151
|
+
time,
|
|
14152
|
+
session.onBeforeCapture,
|
|
14153
|
+
nativeHdrIds,
|
|
14154
|
+
hdrPerf,
|
|
14155
|
+
"frameSeekMs",
|
|
14156
|
+
"frameInjectMs",
|
|
14157
|
+
"stackingQueryMs"
|
|
14158
|
+
);
|
|
14159
|
+
canvas.fill(0);
|
|
14160
|
+
const wctx = { ...hdrCompositeCtx, domSession: session };
|
|
14161
|
+
await timeHdrPhaseAsync(
|
|
14162
|
+
hdrPerf,
|
|
14163
|
+
"normalCompositeMs",
|
|
14164
|
+
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
|
|
14165
|
+
);
|
|
14166
|
+
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14167
|
+
writeFileExclusiveSync(
|
|
14168
|
+
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14169
|
+
canvas
|
|
14103
14170
|
);
|
|
14104
|
-
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14105
14171
|
}
|
|
14106
|
-
await writeEncoded(
|
|
14107
|
-
})();
|
|
14108
|
-
ringInFlight[slot] = dispatch.catch((err) => {
|
|
14109
|
-
throw err instanceof Error ? err : new Error(String(err));
|
|
14110
|
-
});
|
|
14111
|
-
} else {
|
|
14112
|
-
const stackingInfo = await seekInjectAndQueryStacking(
|
|
14113
|
-
session.page,
|
|
14114
|
-
time,
|
|
14115
|
-
session.onBeforeCapture,
|
|
14116
|
-
nativeHdrIds,
|
|
14117
|
-
hdrPerf,
|
|
14118
|
-
"frameSeekMs",
|
|
14119
|
-
"frameInjectMs",
|
|
14120
|
-
"stackingQueryMs"
|
|
14121
|
-
);
|
|
14122
|
-
canvas.fill(0);
|
|
14123
|
-
const wctx = { ...hdrCompositeCtx, domSession: session };
|
|
14124
|
-
await timeHdrPhaseAsync(
|
|
14125
|
-
hdrPerf,
|
|
14126
|
-
"normalCompositeMs",
|
|
14127
|
-
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
|
|
14128
|
-
);
|
|
14129
|
-
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14130
|
-
writeFileExclusiveSync(
|
|
14131
|
-
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14132
|
-
canvas
|
|
14133
|
-
);
|
|
14172
|
+
await writeEncoded(i, canvas);
|
|
14134
14173
|
}
|
|
14135
|
-
await writeEncoded(i, canvas);
|
|
14136
14174
|
}
|
|
14175
|
+
} catch (err) {
|
|
14176
|
+
fail(err);
|
|
14177
|
+
} finally {
|
|
14178
|
+
await Promise.all(ringInFlight);
|
|
14137
14179
|
}
|
|
14138
|
-
|
|
14139
|
-
if (pending) await pending;
|
|
14140
|
-
}
|
|
14180
|
+
throwIfFailed();
|
|
14141
14181
|
};
|
|
14142
|
-
await Promise.
|
|
14182
|
+
await Promise.allSettled(sessions.map((_, w) => workerTaskOf(w)));
|
|
14183
|
+
throwIfFailed();
|
|
14143
14184
|
await reorderBuffer.waitForAllDone();
|
|
14144
14185
|
} finally {
|
|
14145
14186
|
for (const s of workerSessions) {
|
|
@@ -14231,23 +14272,27 @@ async function runCaptureHdrStage(input) {
|
|
|
14231
14272
|
assertNotAborted();
|
|
14232
14273
|
lastBrowserConsole = domSession.browserConsoleBuffer;
|
|
14233
14274
|
await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
|
|
14234
|
-
const transitionMeta =
|
|
14235
|
-
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14241
|
-
|
|
14242
|
-
const
|
|
14243
|
-
const
|
|
14244
|
-
|
|
14245
|
-
|
|
14275
|
+
const transitionMeta = sanitizeTransitionMeta(
|
|
14276
|
+
await domSession.page.evaluate(() => window.__hf?.transitions ?? []),
|
|
14277
|
+
(message, meta) => log.warn(message, meta)
|
|
14278
|
+
);
|
|
14279
|
+
const sceneElements = Object.assign(
|
|
14280
|
+
/* @__PURE__ */ Object.create(null),
|
|
14281
|
+
await domSession.page.evaluate(() => {
|
|
14282
|
+
const scenes = document.querySelectorAll(".scene");
|
|
14283
|
+
const map = {};
|
|
14284
|
+
for (const scene of scenes) {
|
|
14285
|
+
if (!scene.id) continue;
|
|
14286
|
+
const ids = /* @__PURE__ */ new Set([scene.id]);
|
|
14287
|
+
const els = scene.querySelectorAll("[id]");
|
|
14288
|
+
for (const el of els) {
|
|
14289
|
+
if (el.id) ids.add(el.id);
|
|
14290
|
+
}
|
|
14291
|
+
map[scene.id] = Array.from(ids);
|
|
14246
14292
|
}
|
|
14247
|
-
map
|
|
14248
|
-
}
|
|
14249
|
-
|
|
14250
|
-
});
|
|
14293
|
+
return map;
|
|
14294
|
+
})
|
|
14295
|
+
);
|
|
14251
14296
|
const fpsDecimal = fpsToNumber7(job.config.fps);
|
|
14252
14297
|
const transitionRanges = transitionMeta.map((t) => ({
|
|
14253
14298
|
...t,
|
|
@@ -15142,6 +15187,13 @@ var RenderCancelledError = class extends Error {
|
|
|
15142
15187
|
this.reason = reason;
|
|
15143
15188
|
}
|
|
15144
15189
|
};
|
|
15190
|
+
var EscapedRejectionError = class extends Error {
|
|
15191
|
+
constructor(cause) {
|
|
15192
|
+
super(cause.message, { cause });
|
|
15193
|
+
Object.assign(this, cause);
|
|
15194
|
+
this.name = cause.name;
|
|
15195
|
+
}
|
|
15196
|
+
};
|
|
15145
15197
|
function createRenderFileLogger(logPath, base = defaultLogger) {
|
|
15146
15198
|
const write = (prefix, args) => {
|
|
15147
15199
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -18106,11 +18158,12 @@ async function executeRenderPipeline(input) {
|
|
|
18106
18158
|
framesRendered: job.framesRendered ?? 0,
|
|
18107
18159
|
error: caught
|
|
18108
18160
|
});
|
|
18161
|
+
const escapedRejection = executionSignal.reason instanceof EscapedRejectionError ? executionSignal.reason : void 0;
|
|
18109
18162
|
const error = surfaceScriptFailure(
|
|
18110
|
-
tooSlowError ?? audioFailure ?? pageNeverReady ?? caught,
|
|
18163
|
+
tooSlowError ?? audioFailure ?? escapedRejection ?? pageNeverReady ?? caught,
|
|
18111
18164
|
job
|
|
18112
18165
|
);
|
|
18113
|
-
if (!tooSlowError && !audioFailure && (error instanceof RenderCancelledError || executionSignal.aborted)) {
|
|
18166
|
+
if (!tooSlowError && !audioFailure && !escapedRejection && (error instanceof RenderCancelledError || executionSignal.aborted)) {
|
|
18114
18167
|
job.error = error instanceof Error ? error.message : "render_cancelled";
|
|
18115
18168
|
updateJobStatus(job, "cancelled", "Render cancelled", job.progress, onProgress);
|
|
18116
18169
|
await eventPublisher.flush();
|
|
@@ -19528,11 +19581,16 @@ function createRenderHandlers(options = {}) {
|
|
|
19528
19581
|
quality: input.quality
|
|
19529
19582
|
});
|
|
19530
19583
|
try {
|
|
19531
|
-
await
|
|
19532
|
-
|
|
19533
|
-
|
|
19534
|
-
|
|
19535
|
-
|
|
19584
|
+
await runInRenderScope(
|
|
19585
|
+
requestId,
|
|
19586
|
+
new AbortController(),
|
|
19587
|
+
(signal) => executeRenderJob(
|
|
19588
|
+
job,
|
|
19589
|
+
input.projectDir,
|
|
19590
|
+
absoluteOutputPath,
|
|
19591
|
+
createBlockingProgressReporter(log, requestId),
|
|
19592
|
+
signal
|
|
19593
|
+
)
|
|
19536
19594
|
);
|
|
19537
19595
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
19538
19596
|
const durationMs = Date.now() - t0;
|
|
@@ -19629,12 +19687,10 @@ function createRenderHandlers(options = {}) {
|
|
|
19629
19687
|
}, SSE_KEEPALIVE_MS);
|
|
19630
19688
|
const release = await renderSemaphore.acquire();
|
|
19631
19689
|
try {
|
|
19632
|
-
await
|
|
19633
|
-
|
|
19634
|
-
|
|
19635
|
-
absoluteOutputPath,
|
|
19636
|
-
reportProgress,
|
|
19637
|
-
abortController.signal
|
|
19690
|
+
await runInRenderScope(
|
|
19691
|
+
requestId,
|
|
19692
|
+
abortController,
|
|
19693
|
+
(signal) => executeRenderJob(job, input.projectDir, absoluteOutputPath, reportProgress, signal)
|
|
19638
19694
|
).finally(release);
|
|
19639
19695
|
clearInterval(keepalive);
|
|
19640
19696
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
@@ -19802,19 +19858,53 @@ function createProducerApp(options = {}) {
|
|
|
19802
19858
|
app.get("/outputs/:token", handlers.outputs);
|
|
19803
19859
|
return app;
|
|
19804
19860
|
}
|
|
19805
|
-
|
|
19806
|
-
|
|
19807
|
-
const
|
|
19808
|
-
|
|
19809
|
-
|
|
19861
|
+
var renderScope = new AsyncLocalStorage();
|
|
19862
|
+
function runInRenderScope(requestId, abortController, run) {
|
|
19863
|
+
const fail = (err) => abortController.abort(new EscapedRejectionError(err));
|
|
19864
|
+
return renderScope.run({ requestId, fail }, () => run(abortController.signal));
|
|
19865
|
+
}
|
|
19866
|
+
function onEscapedRejection(reason, log) {
|
|
19867
|
+
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
19868
|
+
const scope = renderScope.getStore();
|
|
19869
|
+
log.error("Unhandled promise rejection", {
|
|
19870
|
+
requestId: scope?.requestId ?? null,
|
|
19871
|
+
error: err.message,
|
|
19872
|
+
stack: err.stack
|
|
19873
|
+
});
|
|
19874
|
+
scope?.fail(err);
|
|
19875
|
+
}
|
|
19876
|
+
function serverAuth(options, hostname2, port) {
|
|
19877
|
+
const configured = resolveAuthToken(options);
|
|
19878
|
+
if (configured) return { token: configured };
|
|
19879
|
+
if (!isLoopbackHostname(hostname2)) {
|
|
19810
19880
|
throw new Error(
|
|
19811
19881
|
`Refusing to listen on ${hostname2} without an auth token. Set authToken or PRODUCER_AUTH_TOKEN, or listen on a loopback address.`
|
|
19812
19882
|
);
|
|
19813
19883
|
}
|
|
19814
|
-
const
|
|
19884
|
+
const file = resolve11(
|
|
19885
|
+
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join40(homedir(), ".hyperframes", "producer", `${port}.token`)
|
|
19886
|
+
);
|
|
19887
|
+
const token = crypto.randomBytes(32).toString("base64url");
|
|
19888
|
+
mkdirSync13(dirname19(file), { recursive: true, mode: 448 });
|
|
19889
|
+
rmSync14(file, { force: true });
|
|
19890
|
+
writeFileSync7(file, `${token}
|
|
19891
|
+
`, { flag: "wx", mode: 384 });
|
|
19892
|
+
return { token, generatedFile: file };
|
|
19893
|
+
}
|
|
19894
|
+
function startServer(options = {}) {
|
|
19895
|
+
const port = options.port ?? parseInt(process.env.PRODUCER_PORT ?? "9847", 10);
|
|
19896
|
+
const hostname2 = options.hostname || process.env.PRODUCER_HOST || "127.0.0.1";
|
|
19897
|
+
const log = options.logger ?? defaultLogger;
|
|
19898
|
+
const auth = serverAuth(options, hostname2, port);
|
|
19899
|
+
const app = createProducerApp({ ...options, authToken: auth.token });
|
|
19815
19900
|
const server = serve2({ fetch: app.fetch, port, hostname: hostname2 }, (info) => {
|
|
19816
19901
|
const address = info.family === "IPv6" ? `[${info.address}]` : info.address;
|
|
19817
19902
|
log.info(`Listening on http://${address}:${info.port}`);
|
|
19903
|
+
if (auth.generatedFile) {
|
|
19904
|
+
log.info(
|
|
19905
|
+
`No auth token was set, so this run made one: send "Authorization: Bearer <token>" with the token in ${auth.generatedFile}`
|
|
19906
|
+
);
|
|
19907
|
+
}
|
|
19818
19908
|
});
|
|
19819
19909
|
server.setTimeout(0);
|
|
19820
19910
|
server.requestTimeout = 0;
|
|
@@ -19825,6 +19915,7 @@ function startServer(options = {}) {
|
|
|
19825
19915
|
});
|
|
19826
19916
|
async function shutdown(signal) {
|
|
19827
19917
|
log.info(`Received ${signal}, shutting down`);
|
|
19918
|
+
if (auth.generatedFile) rmSync14(auth.generatedFile, { force: true });
|
|
19828
19919
|
const { drainBrowserPool } = await import("@hyperframes/engine");
|
|
19829
19920
|
await drainBrowserPool().catch(() => {
|
|
19830
19921
|
});
|
|
@@ -19846,6 +19937,7 @@ function startServer(options = {}) {
|
|
|
19846
19937
|
}, 3e4).unref();
|
|
19847
19938
|
}
|
|
19848
19939
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
19940
|
+
process.on("unhandledRejection", (reason) => onEscapedRejection(reason, log));
|
|
19849
19941
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
19850
19942
|
return server;
|
|
19851
19943
|
}
|
|
@@ -19864,7 +19956,9 @@ export {
|
|
|
19864
19956
|
createRenderHandlers,
|
|
19865
19957
|
extractSafeRenderErrorCode,
|
|
19866
19958
|
extractSafeRenderErrorMetadata,
|
|
19959
|
+
onEscapedRejection,
|
|
19867
19960
|
parseRenderOptions,
|
|
19868
19961
|
prepareRenderBody,
|
|
19962
|
+
runInRenderScope,
|
|
19869
19963
|
startServer
|
|
19870
19964
|
};
|
package/dist/server.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface HandlerOptions {
|
|
|
40
40
|
projectsDir?: string;
|
|
41
41
|
/** With `confineRequests`: let requests set `debug: true`, which keeps work dirs on disk. Defaults to PRODUCER_ALLOW_DEBUG=1. */
|
|
42
42
|
allowDebug?: boolean;
|
|
43
|
-
/** Bearer token
|
|
43
|
+
/** Bearer token required on every route but /health. Defaults to PRODUCER_AUTH_TOKEN; without one no caller is checked. */
|
|
44
44
|
authToken?: string;
|
|
45
45
|
}
|
|
46
46
|
export interface ServerOptions extends HandlerOptions {
|
|
@@ -48,6 +48,8 @@ export interface ServerOptions extends HandlerOptions {
|
|
|
48
48
|
port?: number;
|
|
49
49
|
/** Address to listen on. Default: PRODUCER_HOST or 127.0.0.1. A non-loopback address requires `authToken`. */
|
|
50
50
|
hostname?: string;
|
|
51
|
+
/** Where a token made for a run without `authToken` is written. Default: PRODUCER_AUTH_TOKEN_FILE or ~/.hyperframes/producer/<port>.token. */
|
|
52
|
+
authTokenFile?: string;
|
|
51
53
|
}
|
|
52
54
|
interface RenderInput {
|
|
53
55
|
projectDir: string;
|
|
@@ -135,13 +137,16 @@ export interface RenderHandlers {
|
|
|
135
137
|
/**
|
|
136
138
|
* Create route handler functions for the producer server.
|
|
137
139
|
*
|
|
138
|
-
*
|
|
140
|
+
* Mount them on any Hono app at any path prefix, behind your own authentication: they check no caller.
|
|
139
141
|
*/
|
|
140
142
|
export declare function createRenderHandlers(options?: HandlerOptions): RenderHandlers;
|
|
141
143
|
/**
|
|
142
144
|
* Create a Hono app with clean public routes for OSS use.
|
|
143
145
|
*/
|
|
144
146
|
export declare function createProducerApp(options?: HandlerOptions): Hono;
|
|
147
|
+
/** Runs a render so a rejection nobody handled inside it fails that render only. */
|
|
148
|
+
export declare function runInRenderScope<T>(requestId: string, abortController: AbortController, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
149
|
+
export declare function onEscapedRejection(reason: unknown, log: ProducerLogger): void;
|
|
145
150
|
/**
|
|
146
151
|
* Start the producer HTTP server with graceful shutdown.
|
|
147
152
|
*/
|
|
@@ -21,6 +21,13 @@ import { type HdrPerfCollector } from "./render/hdrPerf.js";
|
|
|
21
21
|
* shares the contract with composition runtime code.
|
|
22
22
|
*/
|
|
23
23
|
export type HdrTransitionMeta = HfTransitionMeta;
|
|
24
|
+
/**
|
|
25
|
+
* The page's `window.__hf.transitions`, kept only where it is well formed:
|
|
26
|
+
* finite non-negative `time` and `duration` and string scene ids. A `shader`
|
|
27
|
+
* that is not a string or not a registered transition is dropped, which gives
|
|
28
|
+
* the crossfade the layered path already uses for a transition with no shader.
|
|
29
|
+
*/
|
|
30
|
+
export declare function sanitizeTransitionMeta(raw: unknown, warn: (message: string, meta: Record<string, unknown>) => void): HdrTransitionMeta[];
|
|
24
31
|
/** Pre-computed frame range for an active transition. */
|
|
25
32
|
export interface TransitionRange extends HdrTransitionMeta {
|
|
26
33
|
startFrame: number;
|
|
@@ -490,6 +490,13 @@ export declare class RenderCancelledError extends Error {
|
|
|
490
490
|
reason: "user_cancelled" | "timeout" | "aborted";
|
|
491
491
|
constructor(message?: string, reason?: "user_cancelled" | "timeout" | "aborted");
|
|
492
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Aborts a render because a promise rejection nobody handled came from it. The
|
|
495
|
+
* render fails with the original error; it is not reported as a cancel.
|
|
496
|
+
*/
|
|
497
|
+
export declare class EscapedRejectionError extends Error {
|
|
498
|
+
constructor(cause: Error);
|
|
499
|
+
}
|
|
493
500
|
export declare function createRenderFileLogger(logPath: string, base?: ProducerLogger): ProducerLogger;
|
|
494
501
|
export declare function collectVideoReadinessSkipIds(nativeHdrVideoIds: ReadonlySet<string>, extractedVideos: readonly ExtractedVideoReadinessInput[]): string[];
|
|
495
502
|
interface ExtractedVideoReadinessInput {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/producer",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.92",
|
|
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.
|
|
39
|
-
"@hyperframes/engine": "0.9.
|
|
40
|
-
"@hyperframes/
|
|
41
|
-
"@hyperframes/
|
|
42
|
-
"@hyperframes/parsers": "0.9.
|
|
38
|
+
"@hyperframes/core": "0.9.92",
|
|
39
|
+
"@hyperframes/engine": "0.9.92",
|
|
40
|
+
"@hyperframes/studio-server": "0.9.92",
|
|
41
|
+
"@hyperframes/lint": "0.9.92",
|
|
42
|
+
"@hyperframes/parsers": "0.9.92"
|
|
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.
|
|
51
|
+
"@hyperframes/aws-lambda": "0.9.92"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|