@hyperframes/aws-lambda 0.6.80 → 0.6.81
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/events.d.ts +2 -8
- package/dist/events.d.ts.map +1 -1
- package/dist/index.js +10 -229
- package/dist/index.js.map +3 -3
- package/dist/sdk/deploySite.d.ts.map +1 -1
- package/dist/sdk/index.js +10 -229
- package/dist/sdk/index.js.map +3 -3
- package/dist/sdk/validateConfig.d.ts +19 -57
- package/dist/sdk/validateConfig.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/sdk/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// src/sdk/deploySite.ts
|
|
2
|
-
import { mkdtempSync,
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdtempSync, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
5
|
-
import { join
|
|
4
|
+
import { join } from "node:path";
|
|
6
5
|
import { HeadObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
7
|
-
import {
|
|
6
|
+
import { hashProjectDir } from "@hyperframes/producer/distributed";
|
|
8
7
|
|
|
9
8
|
// src/s3Transport.ts
|
|
10
9
|
import {
|
|
@@ -99,28 +98,6 @@ async function deploySite(opts) {
|
|
|
99
98
|
rmSync2(workdir, { recursive: true, force: true });
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
|
-
function hashProjectDir(projectDir) {
|
|
103
|
-
const hash = createHash("sha256");
|
|
104
|
-
const files = [];
|
|
105
|
-
function walk(dir, isRoot) {
|
|
106
|
-
for (const entry of readdirSync(dir, { withFileTypes: true }).sort(
|
|
107
|
-
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
108
|
-
)) {
|
|
109
|
-
if (isRoot && PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(entry.name)) continue;
|
|
110
|
-
const full = join(dir, entry.name);
|
|
111
|
-
if (entry.isDirectory()) walk(full, false);
|
|
112
|
-
else if (entry.isFile()) files.push(full);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
walk(projectDir, true);
|
|
116
|
-
for (const file of files) {
|
|
117
|
-
const rel = relative(projectDir, file).replaceAll("\\", "/");
|
|
118
|
-
hash.update(rel);
|
|
119
|
-
hash.update("\0");
|
|
120
|
-
hash.update(readFileSync(file));
|
|
121
|
-
}
|
|
122
|
-
return hash.digest("hex").slice(0, 16);
|
|
123
|
-
}
|
|
124
101
|
async function headObject(s3, bucket, key) {
|
|
125
102
|
try {
|
|
126
103
|
const res = await s3.send(new HeadObjectCommand({ Bucket: bucket, Key: key }));
|
|
@@ -153,130 +130,12 @@ function formatExtension(format) {
|
|
|
153
130
|
}
|
|
154
131
|
|
|
155
132
|
// src/sdk/validateConfig.ts
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
constructor(field, message) {
|
|
163
|
-
super(`[validateConfig] ${field}: ${message}`);
|
|
164
|
-
this.field = field;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
var ALLOWED_FPS = [24, 30, 60];
|
|
168
|
-
var ALLOWED_FORMATS = [
|
|
169
|
-
"mp4",
|
|
170
|
-
"mov",
|
|
171
|
-
"png-sequence",
|
|
172
|
-
"webm"
|
|
173
|
-
];
|
|
174
|
-
var ALLOWED_CODECS = ["h264", "h265"];
|
|
175
|
-
var ALLOWED_QUALITIES = ["draft", "standard", "high"];
|
|
176
|
-
var ALLOWED_RUNTIME_CAPS = ["lambda", "temporal", "cloud-run-job", "k8s-job", "none"];
|
|
177
|
-
var ALLOWED_HDR_MODES = ["auto", "force-sdr"];
|
|
178
|
-
var MAX_DIMENSION = 7680;
|
|
179
|
-
var MIN_DIMENSION = 16;
|
|
180
|
-
var MAX_CHUNK_SIZE = 3600;
|
|
181
|
-
var MAX_PARALLEL_CHUNKS_CEILING = 256;
|
|
182
|
-
function validateDistributedRenderConfig(config) {
|
|
183
|
-
if (config === null || typeof config !== "object") {
|
|
184
|
-
throw new InvalidConfigError("config", "must be an object");
|
|
185
|
-
}
|
|
186
|
-
if (!ALLOWED_FPS.includes(config.fps)) {
|
|
187
|
-
throw new InvalidConfigError(
|
|
188
|
-
"config.fps",
|
|
189
|
-
`must be one of ${ALLOWED_FPS.join(", ")}; got ${String(config.fps)}`
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
validateIntDimension("config.width", config.width);
|
|
193
|
-
validateIntDimension("config.height", config.height);
|
|
194
|
-
if (!ALLOWED_FORMATS.includes(config.format)) {
|
|
195
|
-
throw new InvalidConfigError(
|
|
196
|
-
"config.format",
|
|
197
|
-
`must be one of ${ALLOWED_FORMATS.join(", ")}; got ${String(config.format)}`
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
if (config.codec !== void 0) {
|
|
201
|
-
if (config.format !== "mp4") {
|
|
202
|
-
throw new InvalidConfigError(
|
|
203
|
-
"config.codec",
|
|
204
|
-
`is only valid with format="mp4"; got format=${String(config.format)}`
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (!ALLOWED_CODECS.includes(config.codec)) {
|
|
208
|
-
throw new InvalidConfigError(
|
|
209
|
-
"config.codec",
|
|
210
|
-
`must be one of ${ALLOWED_CODECS.join(", ")}; got ${String(config.codec)}`
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (config.quality !== void 0 && !ALLOWED_QUALITIES.includes(config.quality)) {
|
|
215
|
-
throw new InvalidConfigError(
|
|
216
|
-
"config.quality",
|
|
217
|
-
`must be one of ${ALLOWED_QUALITIES.join(", ")}; got ${String(config.quality)}`
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
if (config.crf !== void 0 && config.bitrate !== void 0) {
|
|
221
|
-
throw new InvalidConfigError("config.crf", "is mutually exclusive with config.bitrate");
|
|
222
|
-
}
|
|
223
|
-
if (config.crf !== void 0 && (!Number.isInteger(config.crf) || config.crf < 0 || config.crf > 51)) {
|
|
224
|
-
throw new InvalidConfigError("config.crf", `must be an integer in [0, 51]; got ${config.crf}`);
|
|
225
|
-
}
|
|
226
|
-
if (config.bitrate !== void 0 && !/^\d+(\.\d+)?[kKmM]?$/.test(config.bitrate)) {
|
|
227
|
-
throw new InvalidConfigError(
|
|
228
|
-
"config.bitrate",
|
|
229
|
-
`must look like "10M" or "5000k"; got ${JSON.stringify(config.bitrate)}`
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
if (config.chunkSize !== void 0) {
|
|
233
|
-
if (!Number.isInteger(config.chunkSize) || config.chunkSize < 1) {
|
|
234
|
-
throw new InvalidConfigError(
|
|
235
|
-
"config.chunkSize",
|
|
236
|
-
`must be a positive integer; got ${config.chunkSize}`
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
if (config.chunkSize > MAX_CHUNK_SIZE) {
|
|
240
|
-
throw new InvalidConfigError(
|
|
241
|
-
"config.chunkSize",
|
|
242
|
-
// Lambda 15-min cap leaves no useful headroom past ~3600 frames
|
|
243
|
-
// at 4 fps capture-equivalent throughput; rejecting up front
|
|
244
|
-
// avoids a 14-minute Plan-state retry storm.
|
|
245
|
-
`must be \u2264 ${MAX_CHUNK_SIZE} (Lambda 15-min cap); got ${config.chunkSize}`
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (config.maxParallelChunks !== void 0) {
|
|
250
|
-
if (!Number.isInteger(config.maxParallelChunks) || config.maxParallelChunks < 1) {
|
|
251
|
-
throw new InvalidConfigError(
|
|
252
|
-
"config.maxParallelChunks",
|
|
253
|
-
`must be a positive integer; got ${config.maxParallelChunks}`
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
if (config.maxParallelChunks > MAX_PARALLEL_CHUNKS_CEILING) {
|
|
257
|
-
throw new InvalidConfigError(
|
|
258
|
-
"config.maxParallelChunks",
|
|
259
|
-
`must be \u2264 ${MAX_PARALLEL_CHUNKS_CEILING}; got ${config.maxParallelChunks}`
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (config.runtimeCap !== void 0 && !ALLOWED_RUNTIME_CAPS.includes(config.runtimeCap)) {
|
|
264
|
-
throw new InvalidConfigError(
|
|
265
|
-
"config.runtimeCap",
|
|
266
|
-
`must be one of ${ALLOWED_RUNTIME_CAPS.join(", ")}; got ${String(config.runtimeCap)}`
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
if (config.hdrMode !== void 0 && !ALLOWED_HDR_MODES.includes(config.hdrMode)) {
|
|
270
|
-
throw new InvalidConfigError(
|
|
271
|
-
"config.hdrMode",
|
|
272
|
-
`distributed mode supports only ${ALLOWED_HDR_MODES.join(", ")}; got ${String(config.hdrMode)}`
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
if (config.variables !== void 0) {
|
|
276
|
-
validateVariablesPayload(config.variables);
|
|
277
|
-
}
|
|
278
|
-
return config;
|
|
279
|
-
}
|
|
133
|
+
import { InvalidConfigError } from "@hyperframes/producer/distributed";
|
|
134
|
+
import {
|
|
135
|
+
InvalidConfigError as InvalidConfigError2,
|
|
136
|
+
validateDistributedRenderConfig,
|
|
137
|
+
validateVariablesPayload
|
|
138
|
+
} from "@hyperframes/producer/distributed";
|
|
280
139
|
var MAX_STEP_FUNCTIONS_INPUT_BYTES = 256 * 1024;
|
|
281
140
|
var LARGE_VARIABLES_DOCS_URL = "https://hyperframes.heygen.com/deploy/templates-on-lambda#working-with-large-variables";
|
|
282
141
|
function validateStepFunctionsInputSize(input) {
|
|
@@ -303,84 +162,6 @@ function validateStepFunctionsInputSize(input) {
|
|
|
303
162
|
);
|
|
304
163
|
}
|
|
305
164
|
}
|
|
306
|
-
function validateVariablesPayload(value) {
|
|
307
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
308
|
-
throw new InvalidConfigError(
|
|
309
|
-
"config.variables",
|
|
310
|
-
`must be a plain JSON object (got ${describeValue(value)})`
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
walkVariables(value, "config.variables", /* @__PURE__ */ new WeakSet());
|
|
314
|
-
}
|
|
315
|
-
var LEAF_REJECTIONS = {
|
|
316
|
-
// `JSON.stringify` silently drops `undefined` leaves — caller would never
|
|
317
|
-
// notice their value isn't actually being sent.
|
|
318
|
-
undefined: "undefined leaves are silently dropped by JSON.stringify \u2014 use null if you mean an absent value",
|
|
319
|
-
function: "functions are not JSON-serializable",
|
|
320
|
-
symbol: "Symbols are not JSON-serializable",
|
|
321
|
-
bigint: "BigInt values throw at JSON.stringify \u2014 encode as a string if you need 64-bit integers"
|
|
322
|
-
};
|
|
323
|
-
function walkVariables(value, path, seen) {
|
|
324
|
-
const t = typeof value;
|
|
325
|
-
if (value === null || t === "string" || t === "boolean") return;
|
|
326
|
-
if (t === "number") {
|
|
327
|
-
if (!Number.isFinite(value)) {
|
|
328
|
-
throw new InvalidConfigError(
|
|
329
|
-
path,
|
|
330
|
-
`non-finite numbers (NaN / Infinity) are not JSON-serializable; got ${String(value)}`
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const leafReject = LEAF_REJECTIONS[t];
|
|
336
|
-
if (leafReject !== void 0) {
|
|
337
|
-
throw new InvalidConfigError(path, leafReject);
|
|
338
|
-
}
|
|
339
|
-
if (seen.has(value)) {
|
|
340
|
-
throw new InvalidConfigError(
|
|
341
|
-
path,
|
|
342
|
-
"circular reference detected \u2014 JSON.stringify cannot serialize cycles"
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
seen.add(value);
|
|
346
|
-
if (Array.isArray(value)) {
|
|
347
|
-
for (let i = 0; i < value.length; i++) {
|
|
348
|
-
walkVariables(value[i], `${path}[${i}]`, seen);
|
|
349
|
-
}
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const proto = Object.getPrototypeOf(value);
|
|
353
|
-
if (proto !== Object.prototype && proto !== null) {
|
|
354
|
-
throw new InvalidConfigError(
|
|
355
|
-
path,
|
|
356
|
-
`non-plain objects are not supported (got ${describeValue(value)}); use a plain {\u2026} object`
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
for (const key of Object.keys(value)) {
|
|
360
|
-
walkVariables(value[key], `${path}.${key}`, seen);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
function describeValue(value) {
|
|
364
|
-
if (value === null) return "null";
|
|
365
|
-
if (Array.isArray(value)) return "array";
|
|
366
|
-
if (typeof value !== "object") return typeof value;
|
|
367
|
-
const ctorName = value.constructor?.name ?? "Object";
|
|
368
|
-
return ctorName === "Object" ? "object" : ctorName;
|
|
369
|
-
}
|
|
370
|
-
function validateIntDimension(field, value) {
|
|
371
|
-
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
372
|
-
throw new InvalidConfigError(field, `must be an integer; got ${String(value)}`);
|
|
373
|
-
}
|
|
374
|
-
if (value < MIN_DIMENSION || value > MAX_DIMENSION) {
|
|
375
|
-
throw new InvalidConfigError(
|
|
376
|
-
field,
|
|
377
|
-
`must be in [${MIN_DIMENSION}, ${MAX_DIMENSION}]; got ${value}`
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
if (value % 2 !== 0) {
|
|
381
|
-
throw new InvalidConfigError(field, `must be even (yuv420p constraint); got ${value}`);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
165
|
|
|
385
166
|
// src/sdk/renderToLambda.ts
|
|
386
167
|
async function renderToLambda(opts) {
|
|
@@ -708,7 +489,7 @@ function isTerminalFailure(status) {
|
|
|
708
489
|
return status === "FAILED" || status === "TIMED_OUT" || status === "ABORTED";
|
|
709
490
|
}
|
|
710
491
|
export {
|
|
711
|
-
InvalidConfigError,
|
|
492
|
+
InvalidConfigError2 as InvalidConfigError,
|
|
712
493
|
MAX_STEP_FUNCTIONS_INPUT_BYTES,
|
|
713
494
|
computeRenderCost,
|
|
714
495
|
deploySite,
|
package/dist/sdk/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/sdk/deploySite.ts", "../../src/s3Transport.ts", "../../src/sdk/renderToLambda.ts", "../../src/formatExtension.ts", "../../src/sdk/validateConfig.ts", "../../src/sdk/getRenderProgress.ts", "../../src/sdk/costAccounting.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * `deploySite` \u2014 upload a project directory to S3 once per content hash\n * and return a reusable handle.\n *\n * `renderToLambda` calls this implicitly when no `siteHandle` is passed,\n * but exposing it as a standalone verb lets adopters bundle a project\n * ahead of time and reuse the handle across many renders without\n * re-tarring the project tree on every call.\n *\n * The handle is **content-addressed**: `siteId` is derived from a SHA-256\n * over the project files. Two `deploySite` calls on an unchanged tree\n * produce the same `siteId` and `HeadObject`-short-circuit the upload.\n */\n\nimport { mkdtempSync, readdirSync, readFileSync, rmSync, statSync } from \"node:fs\";\nimport { createHash } from \"node:crypto\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative } from \"node:path\";\nimport { HeadObjectCommand, S3Client } from \"@aws-sdk/client-s3\";\nimport { PLAN_PROJECT_DIR_SKIP_SEGMENTS } from \"@hyperframes/producer/distributed\";\nimport { formatS3Uri, tarDirectory, uploadFileToS3 } from \"../s3Transport.js\";\n\n/** Options for {@link deploySite}. */\nexport interface DeploySiteOptions {\n /** Local project directory containing `index.html` (and any composition assets). */\n projectDir: string;\n /** S3 bucket the SAM stack / CDK construct provisioned. */\n bucketName: string;\n /** AWS region for the S3 client. Defaults to the SDK's default chain (env / config / IMDS). */\n region?: string;\n /**\n * Override the content-addressed site id. Useful when the caller has a\n * stable external identifier they want to use (e.g. a git SHA); if\n * unset, the hash of the project tree picks it.\n */\n siteId?: string;\n /** Injection seam for tests. Production callers leave unset. */\n s3?: S3Client;\n}\n\n/** Stable handle returned by {@link deploySite}. Pass back to {@link renderToLambda}. */\nexport interface SiteHandle {\n /** Content-addressed (or caller-supplied) identifier; stable across re-uploads of the same tree. */\n siteId: string;\n /** Bucket the site landed in. Surfaced separately so callers don't have to re-parse `projectS3Uri`. */\n bucketName: string;\n /** Full `s3://bucket/sites/<siteId>/project.tar.gz` URI; pass through to `renderToLambda`. */\n projectS3Uri: string;\n /** Tarball size in bytes; useful for \"did we actually skip the upload?\" assertions. */\n bytes: number;\n /** ISO timestamp of the most recent upload OR the existing object the short-circuit found. */\n uploadedAt: string;\n /** `false` if the object already existed and we skipped the PUT. */\n uploaded: boolean;\n}\n\n/**\n * Upload `projectDir` to `s3://bucketName/sites/<siteId>/project.tar.gz`.\n *\n * Short-circuits when an object with the same key already exists in the\n * bucket \u2014 `siteId` derives from the project's content hash, so the same\n * bytes produce the same key, and re-uploading would be redundant.\n */\nexport async function deploySite(opts: DeploySiteOptions): Promise<SiteHandle> {\n if (!statSync(opts.projectDir).isDirectory()) {\n throw new Error(`[deploySite] projectDir is not a directory: ${opts.projectDir}`);\n }\n\n const siteId = opts.siteId ?? hashProjectDir(opts.projectDir);\n const key = `sites/${siteId}/project.tar.gz`;\n const projectS3Uri = formatS3Uri({ bucket: opts.bucketName, key });\n const s3 = opts.s3 ?? new S3Client({ region: opts.region });\n\n // HeadObject short-circuit. Adopters re-rendering the same project on\n // a tight inner loop (CI smoke, demo flows) save the tar+gzip+PUT pass\n // on every iteration.\n const existing = await headObject(s3, opts.bucketName, key);\n if (existing) {\n return {\n siteId,\n bucketName: opts.bucketName,\n projectS3Uri,\n bytes: existing.bytes,\n uploadedAt: existing.lastModified,\n uploaded: false,\n };\n }\n\n const workdir = mkdtempSync(join(tmpdir(), \"hf-deploy-site-\"));\n try {\n const tarball = join(workdir, \"project.tar.gz\");\n await tarDirectory(opts.projectDir, tarball);\n // Note: tarDirectory packs *everything* under `cwd`. We don't need to\n // re-implement the skip list inside the tar pack because the\n // producer's plan stage applies the same skip during its copy; the\n // archive is slightly bigger than the planDir's compiled/ subtree\n // but the cost is bounded by the project's user-authored content.\n const size = statSync(tarball).size;\n await uploadFileToS3(s3, tarball, projectS3Uri, \"application/gzip\");\n return {\n siteId,\n bucketName: opts.bucketName,\n projectS3Uri,\n bytes: size,\n uploadedAt: new Date().toISOString(),\n uploaded: true,\n };\n } finally {\n rmSync(workdir, { recursive: true, force: true });\n }\n}\n\n/**\n * SHA-256 over every regular file under `projectDir` (sorted by relative\n * path) \u2192 16-character hex prefix. The prefix is the `siteId`.\n *\n * The hash includes the relative path plus every byte of each file, so a\n * same-bytes rename still yields a fresh id. We trim to 16 chars because\n * the full 64 isn't useful in an S3 key for legibility.\n *\n * Reads are synchronous: project trees are typically tens of MB at most\n * (HTML/CSS/JS plus a few composition assets), so the simpler shape wins\n * over a streaming pipeline.\n */\nfunction hashProjectDir(projectDir: string): string {\n const hash = createHash(\"sha256\");\n const files: string[] = [];\n function walk(dir: string, isRoot: boolean): void {\n for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) =>\n a.name < b.name ? -1 : a.name > b.name ? 1 : 0,\n )) {\n if (isRoot && PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(entry.name)) continue;\n const full = join(dir, entry.name);\n if (entry.isDirectory()) walk(full, false);\n else if (entry.isFile()) files.push(full);\n }\n }\n walk(projectDir, true);\n for (const file of files) {\n const rel = relative(projectDir, file).replaceAll(\"\\\\\", \"/\");\n hash.update(rel);\n hash.update(\"\\0\");\n hash.update(readFileSync(file));\n }\n return hash.digest(\"hex\").slice(0, 16);\n}\n\nasync function headObject(\n s3: S3Client,\n bucket: string,\n key: string,\n): Promise<{ bytes: number; lastModified: string } | null> {\n try {\n const res = await s3.send(new HeadObjectCommand({ Bucket: bucket, Key: key }));\n return {\n bytes: typeof res.ContentLength === \"number\" ? res.ContentLength : 0,\n lastModified:\n res.LastModified instanceof Date\n ? res.LastModified.toISOString()\n : new Date().toISOString(),\n };\n } catch (err) {\n // The SDK throws different error shapes for 404 vs 403 vs network;\n // a 404 means \"needs upload\" and is the most common case. Anything\n // else propagates so callers see auth / network failures.\n const status = (err as { $metadata?: { httpStatusCode?: number } }).$metadata?.httpStatusCode;\n if (status === 404) return null;\n const name = (err as { name?: string }).name;\n if (name === \"NotFound\" || name === \"NoSuchKey\") return null;\n throw err;\n }\n}\n", "/**\n * Thin S3 transport for the Lambda handler.\n *\n * The OSS distributed primitives are pure functions over local file paths;\n * the Lambda handler bridges S3 \u2194 Lambda's `/tmp` filesystem on each\n * invocation. Functions here are intentionally narrow: parse a URI, download\n * an object to a local path, upload a path/directory, tar-extract a planDir,\n * tar-pack a planDir back out.\n *\n * Tar (not zip) for planDir transit:\n * - planDirs contain symlinks (extract stage materializes them but the\n * compiled/ subtree may include linked assets); tar preserves them, zip\n * does not.\n * - We use the `tar` npm package (pure JS over `node:zlib`) \u2014 AWS\n * Lambda's `nodejs:22` base image ships neither `tar` nor `unzip` in\n * `/usr/bin`, so a system-binary tar would ENOENT in the actual\n * deployment.\n */\n\nimport {\n createReadStream,\n createWriteStream,\n existsSync,\n mkdirSync,\n rmSync,\n statSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { GetObjectCommand, PutObjectCommand, type S3Client } from \"@aws-sdk/client-s3\";\nimport * as tar from \"tar\";\n\n/** Parsed `s3://bucket/key` URI. */\nexport interface S3Location {\n bucket: string;\n key: string;\n}\n\n/** Parse `s3://bucket/key/path` \u2192 `{ bucket, key }`. Throws on malformed input. */\nexport function parseS3Uri(uri: string): S3Location {\n if (!uri.startsWith(\"s3://\")) {\n throw new Error(`[s3Transport] expected s3:// URI, got: ${JSON.stringify(uri)}`);\n }\n const rest = uri.slice(\"s3://\".length);\n const slash = rest.indexOf(\"/\");\n if (slash === -1) {\n throw new Error(`[s3Transport] missing key in s3 URI: ${JSON.stringify(uri)}`);\n }\n const bucket = rest.slice(0, slash);\n const key = rest.slice(slash + 1);\n if (!bucket || !key) {\n throw new Error(`[s3Transport] empty bucket or key in s3 URI: ${JSON.stringify(uri)}`);\n }\n return { bucket, key };\n}\n\n/** Build `s3://bucket/key` from a location. */\nexport function formatS3Uri(loc: S3Location): string {\n return `s3://${loc.bucket}/${loc.key}`;\n}\n\n/** Stream an S3 object to a local file path. Throws if the body is missing. */\nexport async function downloadS3ObjectToFile(\n client: S3Client,\n uri: string,\n destPath: string,\n): Promise<void> {\n const { bucket, key } = parseS3Uri(uri);\n const response = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key }));\n const body = response.Body as NodeJS.ReadableStream | undefined;\n if (!body) {\n throw new Error(`[s3Transport] s3 GetObject returned empty body for ${uri}`);\n }\n mkdirSync(dirname(destPath), { recursive: true });\n await pipeline(body, createWriteStream(destPath));\n}\n\n/**\n * Upload a local file's contents to an S3 URI using a streaming\n * `PutObjectCommand`. PutObject's 5 GB cap comfortably exceeds the\n * distributed pipeline's 2 GB planDir limit and the typical\n * chunk size (\u2264 200 MB), so a single PUT works for every artifact this\n * adapter handles.\n */\nexport async function uploadFileToS3(\n client: S3Client,\n localPath: string,\n uri: string,\n contentType?: string,\n): Promise<void> {\n if (!existsSync(localPath)) {\n throw new Error(`[s3Transport] upload source missing: ${localPath}`);\n }\n const { bucket, key } = parseS3Uri(uri);\n const size = statSync(localPath).size;\n await client.send(\n new PutObjectCommand({\n Bucket: bucket,\n Key: key,\n Body: createReadStream(localPath),\n ContentType: contentType,\n ContentLength: size,\n }),\n );\n}\n\n/**\n * Pack a directory into a `.tar.gz` at `destTarball`. Uses the `tar` npm\n * package (pure JS over `node:zlib`) rather than spawning a system tar\n * binary \u2014 the AWS Lambda Node 22 base image ships a minimal set of\n * userland tools and does NOT include `tar` in `/usr/bin`.\n */\nexport async function tarDirectory(sourceDir: string, destTarball: string): Promise<void> {\n if (!existsSync(sourceDir) || !statSync(sourceDir).isDirectory()) {\n throw new Error(`[s3Transport] tar source must be an existing directory: ${sourceDir}`);\n }\n mkdirSync(dirname(destTarball), { recursive: true });\n await tar.create({ gzip: true, file: destTarball, cwd: sourceDir }, [\".\"]);\n}\n\n/**\n * Extract a `.tar.gz` produced by {@link tarDirectory} into `destDir`.\n * The directory is created (or cleared) before extraction so a retried\n * invocation doesn't observe stale files from a prior run on the same\n * warm Lambda container.\n */\nexport async function untarDirectory(tarballPath: string, destDir: string): Promise<void> {\n if (!existsSync(tarballPath)) {\n throw new Error(`[s3Transport] tarball missing: ${tarballPath}`);\n }\n // Wipe target so the warm container's prior planDir doesn't bleed into\n // the new invocation. Lambda re-uses /tmp across invocations on the same\n // container.\n if (existsSync(destDir)) {\n rmSync(destDir, { recursive: true, force: true });\n }\n mkdirSync(destDir, { recursive: true });\n await tar.extract({ file: tarballPath, cwd: destDir });\n}\n", "/**\n * `renderToLambda` \u2014 start a distributed render against an already-deployed\n * SAM/CDK stack and return a handle the caller can poll with\n * {@link getRenderProgress}.\n *\n * The function does *not* wait for the render to finish. Step Functions\n * standard workflows can run for hours; blocking the caller's process on\n * the SFN execution is the wrong default. The returned `RenderHandle`\n * carries everything the progress / cost / download paths need.\n *\n * Wire order:\n * 1. Validate config (typed throw before any AWS call).\n * 2. `deploySite` if no `siteHandle` was provided.\n * 3. `StartExecution` against the state machine with the same input\n * shape `examples/aws-lambda/scripts/smoke.sh` builds.\n * 4. Return handle. The S3 `outputKey` is deterministic from the\n * execution name so the caller can predict the final object URL.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { SFNClient, StartExecutionCommand } from \"@aws-sdk/client-sfn\";\nimport type { S3Client } from \"@aws-sdk/client-s3\";\nimport type { SerializableDistributedRenderConfig } from \"../events.js\";\nimport { formatExtension } from \"../formatExtension.js\";\nimport { formatS3Uri } from \"../s3Transport.js\";\nimport { deploySite, type SiteHandle } from \"./deploySite.js\";\nimport {\n validateDistributedRenderConfig,\n validateStepFunctionsInputSize,\n} from \"./validateConfig.js\";\n\n/** Options for {@link renderToLambda}. */\nexport interface RenderToLambdaOptions {\n /** Local project directory. Required when `siteHandle` is not supplied. */\n projectDir?: string;\n /** Re-use an existing `deploySite` upload (skips tar+S3 PUT). */\n siteHandle?: SiteHandle;\n /** Validated `SerializableDistributedRenderConfig` (no logger / abortSignal). */\n config: SerializableDistributedRenderConfig;\n /** S3 bucket from the SAM stack output (`RenderBucketName`). */\n bucketName: string;\n /** State machine ARN from the SAM stack output (`RenderStateMachineArn`). */\n stateMachineArn: string;\n /** AWS region; defaults to the SDK default chain. */\n region?: string;\n /**\n * Final output S3 key. Defaults to `renders/<executionName>/output.<ext>`\n * where `<ext>` is derived from `config.format`.\n */\n outputKey?: string;\n /**\n * Step Functions execution name. Defaults to `hf-render-<uuid>`.\n * Used as `renderId` everywhere downstream (history queries, cost\n * accounting, predictable S3 key prefix).\n */\n executionName?: string;\n /** Test injection seam \u2014 production callers leave unset. */\n sfn?: SFNClient;\n /** Test injection seam \u2014 propagated to `deploySite` when applicable. */\n s3?: S3Client;\n}\n\n/** Stable identifier + every URL/ARN the caller needs to follow the render. */\nexport interface RenderHandle {\n /** Same as the Step Functions execution name. */\n renderId: string;\n /** Full execution ARN; pass to {@link getRenderProgress}. */\n executionArn: string;\n bucketName: string;\n stateMachineArn: string;\n outputS3Uri: string;\n projectS3Uri: string;\n startedAt: string;\n}\n\n// fallow-ignore-next-line complexity\nexport async function renderToLambda(opts: RenderToLambdaOptions): Promise<RenderHandle> {\n validateDistributedRenderConfig(opts.config);\n\n if (!opts.bucketName) {\n throw new Error(\"[renderToLambda] bucketName is required\");\n }\n if (!opts.stateMachineArn) {\n throw new Error(\"[renderToLambda] stateMachineArn is required\");\n }\n if (!opts.siteHandle && !opts.projectDir) {\n throw new Error(\"[renderToLambda] either siteHandle or projectDir must be supplied\");\n }\n\n const executionName = opts.executionName ?? `hf-render-${randomUUID()}`;\n const ext = formatExtension(opts.config.format);\n const outputKey = opts.outputKey ?? `renders/${executionName}/output${ext}`;\n const planOutputS3Prefix = formatS3Uri({\n bucket: opts.bucketName,\n key: `renders/${executionName}/`,\n });\n const outputS3Uri = formatS3Uri({ bucket: opts.bucketName, key: outputKey });\n\n const site =\n opts.siteHandle ??\n (await deploySite({\n projectDir: opts.projectDir as string,\n bucketName: opts.bucketName,\n region: opts.region,\n s3: opts.s3,\n }));\n\n const input = {\n ProjectS3Uri: site.projectS3Uri,\n PlanOutputS3Prefix: planOutputS3Prefix,\n OutputS3Uri: outputS3Uri,\n Config: opts.config,\n };\n\n // Reject oversize input client-side. Step Functions Standard caps the\n // execution input at 256 KiB; without this check, the input bloat\n // (typically from `config.variables` containing inlined media) surfaces\n // as `States.DataLimitExceeded` 50 ms into the execution, far from the\n // caller's stack frame. Measured AFTER `deploySite` so the synthesised\n // `ProjectS3Uri` is counted (a few hundred bytes either way, but the\n // check should be against the actual wire payload).\n validateStepFunctionsInputSize(input);\n\n const sfn = opts.sfn ?? new SFNClient({ region: opts.region });\n const startedAt = new Date().toISOString();\n const response = await sfn.send(\n new StartExecutionCommand({\n stateMachineArn: opts.stateMachineArn,\n name: executionName,\n input: JSON.stringify(input),\n }),\n );\n\n if (!response.executionArn) {\n throw new Error(\"[renderToLambda] StartExecution returned no executionArn\");\n }\n\n return {\n renderId: executionName,\n executionArn: response.executionArn,\n bucketName: opts.bucketName,\n stateMachineArn: opts.stateMachineArn,\n outputS3Uri,\n projectS3Uri: site.projectS3Uri,\n startedAt,\n };\n}\n", "/**\n * Map a distributed `format` to the file extension the assembled output\n * should carry on disk + in S3. Shared by `src/handler.ts` (chunk +\n * assemble output paths) and `src/sdk/renderToLambda.ts` (final\n * output key construction) so the two sides agree on what an mp4\n * looks like vs a png-sequence.\n */\n\nimport type { DistributedFormat } from \"@hyperframes/producer/distributed\";\n\nexport type { DistributedFormat } from \"@hyperframes/producer/distributed\";\n\n// Closed-enum lookup table. TS enforces exhaustiveness via the\n// `Record<DistributedFormat, string>` annotation \u2014 adding a format to\n// `DistributedFormat` without adding the matching key here fails to\n// typecheck, which is the same exhaustiveness guarantee a switch +\n// `_exhaustive: never` arm provides but at lower complexity.\nconst FORMAT_EXTENSIONS: Record<DistributedFormat, string> = {\n mp4: \".mp4\",\n mov: \".mov\",\n webm: \".webm\",\n \"png-sequence\": \"\",\n};\n\nexport function formatExtension(format: DistributedFormat): string {\n return FORMAT_EXTENSIONS[format];\n}\n", "/**\n * Client-side validation of `SerializableDistributedRenderConfig` so the\n * SDK fails on shape errors with a typed `InvalidConfigError` *before* a\n * Step Functions execution starts.\n *\n * The producer's `plan` stage validates the same fields server-side, but a\n * caller staring at \"ExecutionFailed: BROWSER_GPU_NOT_SOFTWARE\" five\n * minutes after StartExecution has to dig through Step Functions history\n * to learn that the renderToLambda call passed an unsupported format.\n * Catching the obvious mistakes locally turns that wait into a synchronous\n * throw.\n *\n * The check is deliberately narrow \u2014 it covers the *shape* errors any\n * caller could have surfaced with `tsc` if they passed a literal, plus\n * the `force-hdr` rejection (HDR mp4 isn't supported in distributed\n * mode). webm was previously rejected here too; v0.7+ supports it via\n * closed-GOP concat-copy. Anything deeper (font availability, plan\n * size cap, GPU mode at runtime) needs the actual planner.\n */\n\nimport type { DistributedFormat } from \"../formatExtension.js\";\nimport type { SerializableDistributedRenderConfig } from \"../events.js\";\n\n/** Thrown for any client-side `SerializableDistributedRenderConfig` violation. */\nexport class InvalidConfigError extends Error {\n // Read via Error.prototype.toString; fallow can't see it.\n // fallow-ignore-next-line unused-class-member\n override readonly name = \"InvalidConfigError\";\n /** Dotted JSON-pointer-ish path to the offending field, e.g. `config.fps`. */\n readonly field: string;\n constructor(field: string, message: string) {\n super(`[validateConfig] ${field}: ${message}`);\n this.field = field;\n }\n}\n\nconst ALLOWED_FPS = [24, 30, 60] as const;\nconst ALLOWED_FORMATS = [\n \"mp4\",\n \"mov\",\n \"png-sequence\",\n \"webm\",\n] as const satisfies readonly DistributedFormat[];\nconst ALLOWED_CODECS = [\"h264\", \"h265\"] as const;\nconst ALLOWED_QUALITIES = [\"draft\", \"standard\", \"high\"] as const;\nconst ALLOWED_RUNTIME_CAPS = [\"lambda\", \"temporal\", \"cloud-run-job\", \"k8s-job\", \"none\"] as const;\nconst ALLOWED_HDR_MODES = [\"auto\", \"force-sdr\"] as const;\n\nconst MAX_DIMENSION = 7680;\nconst MIN_DIMENSION = 16;\nconst MAX_CHUNK_SIZE = 3600;\nconst MAX_PARALLEL_CHUNKS_CEILING = 256;\n\n/**\n * Throw an `InvalidConfigError` if `config` is not a valid\n * `SerializableDistributedRenderConfig`. Returns the same reference on\n * success so the call site reads:\n *\n * const validated = validateDistributedRenderConfig(input);\n */\nexport function validateDistributedRenderConfig(\n config: SerializableDistributedRenderConfig,\n): SerializableDistributedRenderConfig {\n if (config === null || typeof config !== \"object\") {\n throw new InvalidConfigError(\"config\", \"must be an object\");\n }\n\n if (!ALLOWED_FPS.includes(config.fps as 24 | 30 | 60)) {\n throw new InvalidConfigError(\n \"config.fps\",\n `must be one of ${ALLOWED_FPS.join(\", \")}; got ${String(config.fps)}`,\n );\n }\n\n validateIntDimension(\"config.width\", config.width);\n validateIntDimension(\"config.height\", config.height);\n\n if (!ALLOWED_FORMATS.includes(config.format)) {\n throw new InvalidConfigError(\n \"config.format\",\n `must be one of ${ALLOWED_FORMATS.join(\", \")}; got ${String(config.format)}`,\n );\n }\n\n if (config.codec !== undefined) {\n if (config.format !== \"mp4\") {\n throw new InvalidConfigError(\n \"config.codec\",\n `is only valid with format=\"mp4\"; got format=${String(config.format)}`,\n );\n }\n if (!ALLOWED_CODECS.includes(config.codec)) {\n throw new InvalidConfigError(\n \"config.codec\",\n `must be one of ${ALLOWED_CODECS.join(\", \")}; got ${String(config.codec)}`,\n );\n }\n }\n\n if (config.quality !== undefined && !ALLOWED_QUALITIES.includes(config.quality)) {\n throw new InvalidConfigError(\n \"config.quality\",\n `must be one of ${ALLOWED_QUALITIES.join(\", \")}; got ${String(config.quality)}`,\n );\n }\n\n if (config.crf !== undefined && config.bitrate !== undefined) {\n throw new InvalidConfigError(\"config.crf\", \"is mutually exclusive with config.bitrate\");\n }\n if (\n config.crf !== undefined &&\n (!Number.isInteger(config.crf) || config.crf < 0 || config.crf > 51)\n ) {\n throw new InvalidConfigError(\"config.crf\", `must be an integer in [0, 51]; got ${config.crf}`);\n }\n if (config.bitrate !== undefined && !/^\\d+(\\.\\d+)?[kKmM]?$/.test(config.bitrate)) {\n throw new InvalidConfigError(\n \"config.bitrate\",\n `must look like \"10M\" or \"5000k\"; got ${JSON.stringify(config.bitrate)}`,\n );\n }\n\n if (config.chunkSize !== undefined) {\n if (!Number.isInteger(config.chunkSize) || config.chunkSize < 1) {\n throw new InvalidConfigError(\n \"config.chunkSize\",\n `must be a positive integer; got ${config.chunkSize}`,\n );\n }\n if (config.chunkSize > MAX_CHUNK_SIZE) {\n throw new InvalidConfigError(\n \"config.chunkSize\",\n // Lambda 15-min cap leaves no useful headroom past ~3600 frames\n // at 4 fps capture-equivalent throughput; rejecting up front\n // avoids a 14-minute Plan-state retry storm.\n `must be \u2264 ${MAX_CHUNK_SIZE} (Lambda 15-min cap); got ${config.chunkSize}`,\n );\n }\n }\n\n if (config.maxParallelChunks !== undefined) {\n if (!Number.isInteger(config.maxParallelChunks) || config.maxParallelChunks < 1) {\n throw new InvalidConfigError(\n \"config.maxParallelChunks\",\n `must be a positive integer; got ${config.maxParallelChunks}`,\n );\n }\n if (config.maxParallelChunks > MAX_PARALLEL_CHUNKS_CEILING) {\n throw new InvalidConfigError(\n \"config.maxParallelChunks\",\n `must be \u2264 ${MAX_PARALLEL_CHUNKS_CEILING}; got ${config.maxParallelChunks}`,\n );\n }\n }\n\n if (config.runtimeCap !== undefined && !ALLOWED_RUNTIME_CAPS.includes(config.runtimeCap)) {\n throw new InvalidConfigError(\n \"config.runtimeCap\",\n `must be one of ${ALLOWED_RUNTIME_CAPS.join(\", \")}; got ${String(config.runtimeCap)}`,\n );\n }\n\n if (config.hdrMode !== undefined && !ALLOWED_HDR_MODES.includes(config.hdrMode)) {\n // `force-hdr` is rejected here on top of the producer's plan-stage\n // rejection \u2014 it makes the typical typo (`\"force-hdr\"` from a copy-\n // paste of in-process config) surface synchronously instead of as a\n // typed Step Functions failure two minutes in.\n throw new InvalidConfigError(\n \"config.hdrMode\",\n `distributed mode supports only ${ALLOWED_HDR_MODES.join(\", \")}; got ${String(config.hdrMode)}`,\n );\n }\n\n if (config.variables !== undefined) {\n validateVariablesPayload(config.variables);\n }\n\n return config;\n}\n\n/**\n * Hard cap on Step Functions Standard workflow execution input \u2014 256 KiB\n * per the AWS limits page. Express workflows cap at 32 KiB; the render\n * stack runs Standard for execution-history visibility, so the larger\n * limit applies. The cap is on the entire serialized input, not just the\n * variables, because users hit it at the wire boundary regardless of\n * which field caused the bloat.\n *\n * Specific to Step Functions Standard. Other workflow runtimes (Temporal,\n * Express SFN, raw Lambda invoke) have different caps; this constant\n * shouldn't be reused for those without confirming the limit.\n */\nexport const MAX_STEP_FUNCTIONS_INPUT_BYTES = 256 * 1024;\n\n/** Pointer to the docs section that explains the URL-your-assets convention. */\nconst LARGE_VARIABLES_DOCS_URL =\n \"https://hyperframes.heygen.com/deploy/templates-on-lambda#working-with-large-variables\";\n\n/**\n * Validate that the serialized Step Functions execution input fits inside\n * the 256 KiB Standard-workflow cap. Measured in UTF-8 bytes (the format\n * Step Functions uses on the wire) \u2014 JS strings count UTF-16 code units,\n * which under-reports for any multi-byte character.\n *\n * Throws {@link InvalidConfigError} with a clear message naming the actual\n * byte count, the cap, and a pointer to the \"working with large variables\"\n * docs section, so users hit the limit at the SDK boundary with actionable\n * guidance instead of as a `States.DataLimitExceeded` 50 ms into the\n * execution.\n */\n// fallow-ignore-next-line complexity\nexport function validateStepFunctionsInputSize(input: unknown): void {\n let serialized: string | undefined;\n try {\n serialized = JSON.stringify(input);\n } catch (err) {\n // JSON.stringify throws on circular refs and BigInt. The variables\n // walker catches both inside `config.variables`, but a non-variables\n // field could hit the same case in a future field addition.\n throw new InvalidConfigError(\n \"config\",\n `Step Functions execution input is not JSON-serializable: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n if (serialized === undefined) {\n // JSON.stringify returns undefined for non-serializable roots\n // (functions, Symbols at the top level).\n throw new InvalidConfigError(\n \"config\",\n \"Step Functions execution input is not JSON-serializable (JSON.stringify returned undefined). \" +\n \"Check that all fields, including config.variables, are plain JSON values.\",\n );\n }\n const byteLength = Buffer.byteLength(serialized, \"utf8\");\n if (byteLength > MAX_STEP_FUNCTIONS_INPUT_BYTES) {\n throw new InvalidConfigError(\n \"config\",\n `Step Functions execution input is ${byteLength} bytes, which exceeds the ` +\n `${MAX_STEP_FUNCTIONS_INPUT_BYTES}-byte (256 KiB) limit for Standard workflows. ` +\n `Variables are for typed data (strings, numbers, structured records); media assets ` +\n `(images, audio, video) should be passed as URL references the composition resolves ` +\n `at render time, not inlined as base64. See ${LARGE_VARIABLES_DOCS_URL} for the ` +\n `URL-your-assets convention.`,\n );\n }\n}\n\n/**\n * Validate that `variables` is a plain JSON-safe object \u2014 no functions,\n * Symbols, `undefined` leaves, BigInts, non-finite numbers, or non-plain\n * objects (Dates, Maps, Sets, class instances). Rejected values would\n * either round-trip incorrectly through Step Functions (`undefined` is\n * silently dropped by `JSON.stringify`) or throw at the wire boundary\n * (`bigint`), so we surface the offending path synchronously.\n *\n * The check is purely structural \u2014 semantic constraints (e.g. \"is this\n * variable declared in `data-composition-variables`?\") belong to the CLI\n * layer where the project's HTML is on disk.\n */\nexport function validateVariablesPayload(value: unknown): void {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n throw new InvalidConfigError(\n \"config.variables\",\n `must be a plain JSON object (got ${describeValue(value)})`,\n );\n }\n walkVariables(value, \"config.variables\", new WeakSet());\n}\n\n/** Per-typeof rejection messages for JSON-unsafe leaves. */\nconst LEAF_REJECTIONS: Partial<Record<string, string>> = {\n // `JSON.stringify` silently drops `undefined` leaves \u2014 caller would never\n // notice their value isn't actually being sent.\n undefined:\n \"undefined leaves are silently dropped by JSON.stringify \u2014 use null if you mean an absent value\",\n function: \"functions are not JSON-serializable\",\n symbol: \"Symbols are not JSON-serializable\",\n bigint: \"BigInt values throw at JSON.stringify \u2014 encode as a string if you need 64-bit integers\",\n};\n\n// fallow-ignore-next-line complexity\nfunction walkVariables(value: unknown, path: string, seen: WeakSet<object>): void {\n const t = typeof value;\n if (value === null || t === \"string\" || t === \"boolean\") return;\n if (t === \"number\") {\n if (!Number.isFinite(value as number)) {\n throw new InvalidConfigError(\n path,\n `non-finite numbers (NaN / Infinity) are not JSON-serializable; got ${String(value)}`,\n );\n }\n return;\n }\n const leafReject = LEAF_REJECTIONS[t];\n if (leafReject !== undefined) {\n throw new InvalidConfigError(path, leafReject);\n }\n // t === \"object\" from here on. Reject circular refs up front \u2014 recursing\n // through a back-edge would stack-overflow with no actionable error.\n if (seen.has(value as object)) {\n throw new InvalidConfigError(\n path,\n \"circular reference detected \u2014 JSON.stringify cannot serialize cycles\",\n );\n }\n seen.add(value as object);\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n walkVariables(value[i], `${path}[${i}]`, seen);\n }\n return;\n }\n // Reject non-plain objects (Date, Map, Set, class instances) up front.\n // Date's `toJSON` does round-trip as a string, but the composition gets a\n // string, not a Date \u2014 explicit reject is clearer than silent type-loss.\n const proto = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto !== null) {\n throw new InvalidConfigError(\n path,\n `non-plain objects are not supported (got ${describeValue(value)}); use a plain {\u2026} object`,\n );\n }\n for (const key of Object.keys(value as Record<string, unknown>)) {\n walkVariables((value as Record<string, unknown>)[key], `${path}.${key}`, seen);\n }\n}\n\n// fallow-ignore-next-line complexity\nfunction describeValue(value: unknown): string {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n if (typeof value !== \"object\") return typeof value;\n // Class instances expose their constructor name; plain objects fall through\n // to the generic \"object\" label. `Object.create(null)` has no constructor \u2014\n // treat its absent name the same as \"Object\" for reporting.\n const ctorName = (value as { constructor?: { name?: string } }).constructor?.name ?? \"Object\";\n return ctorName === \"Object\" ? \"object\" : ctorName;\n}\n\nfunction validateIntDimension(field: string, value: unknown): void {\n if (typeof value !== \"number\" || !Number.isInteger(value)) {\n throw new InvalidConfigError(field, `must be an integer; got ${String(value)}`);\n }\n if (value < MIN_DIMENSION || value > MAX_DIMENSION) {\n throw new InvalidConfigError(\n field,\n `must be in [${MIN_DIMENSION}, ${MAX_DIMENSION}]; got ${value}`,\n );\n }\n if (value % 2 !== 0) {\n // libx264 / libx265 yuv420p require even dimensions; rejecting now\n // beats a Plan-stage ffmpeg crash on dimension parity.\n throw new InvalidConfigError(field, `must be even (yuv420p constraint); got ${value}`);\n }\n}\n", "/**\n * `getRenderProgress` \u2014 read-only progress + cost snapshot for a single\n * render started by {@link renderToLambda}.\n *\n * Pulls one `DescribeExecution` + one `GetExecutionHistory` per call. The\n * history is paginated server-side; the helper loops until exhausted so a\n * 1,000-event Step Functions execution still produces a single\n * `RenderProgress` snapshot.\n *\n * Progress math:\n * - 0 before Plan completes (no frame count is known yet)\n * - 0.1 once Plan completes (we know `totalFrames`)\n * - 0.1 + 0.8 \u00D7 framesEncoded / totalFrames during chunk render\n * - 1.0 after Assemble completes\n *\n * Frame counts come from the parsed Lambda result payloads on each\n * `TaskSucceeded` event \u2014 Plan reports `TotalFrames`, RenderChunk reports\n * `FramesEncoded`. The shape mirrors what the handler produces in\n * `events.ts`, so the parser doesn't need to know anything beyond\n * \"JSON.parse this string and grab two fields.\"\n */\n\nimport {\n DescribeExecutionCommand,\n GetExecutionHistoryCommand,\n type HistoryEvent,\n SFNClient,\n} from \"@aws-sdk/client-sfn\";\nimport {\n type BilledLambdaInvocation,\n computeRenderCost,\n type RenderCost,\n} from \"./costAccounting.js\";\n\n/** Options for {@link getRenderProgress}. */\nexport interface GetRenderProgressOptions {\n /** Execution ARN from a {@link renderToLambda} call. */\n executionArn: string;\n /**\n * Default memory size in MB to assume for Lambda invocations when the\n * history event payload doesn't carry it explicitly. Matches the\n * `LambdaMemoryMb` parameter the stack was deployed with.\n */\n defaultMemorySizeMb?: number;\n region?: string;\n /** Test injection seam. */\n sfn?: SFNClient;\n}\n\n/** Render-status discriminant; mirrors Step Functions execution states. */\nexport type RenderStatus =\n | \"RUNNING\"\n | \"SUCCEEDED\"\n | \"FAILED\"\n | \"TIMED_OUT\"\n | \"ABORTED\"\n | \"PENDING_REDRIVE\";\n\nexport interface RenderError {\n /** State name where the failure surfaced (`Plan`, `RenderChunk`, `Assemble`, or `<unknown>`). */\n state: string;\n /** Error class / type as Step Functions reports it. */\n error: string;\n /** Cause string Step Functions surfaces (often a stringified JSON payload from the handler). */\n cause: string;\n}\n\n/** Snapshot of a single render's progress + cost + errors at one point in time. */\nexport interface RenderProgress {\n status: RenderStatus;\n /** `[0, 1]`; see module doc for the math. */\n overallProgress: number;\n framesRendered: number;\n /** `null` until Plan completes. */\n totalFrames: number | null;\n /** Total Lambda invocations scheduled so far (both optimized + raw task integrations). */\n lambdasInvoked: number;\n costs: RenderCost;\n /** Final output object if Assemble succeeded; `null` otherwise. */\n outputFile: { s3Uri: string; bytes: number | null } | null;\n errors: RenderError[];\n /** `true` once the execution has terminated in a non-`SUCCEEDED` state. */\n fatalErrorEncountered: boolean;\n startedAt: string;\n endedAt: string | null;\n}\n\nconst DEFAULT_MEMORY_MB = 10240;\n\n/** Pull a current progress snapshot for one render. */\nexport async function getRenderProgress(opts: GetRenderProgressOptions): Promise<RenderProgress> {\n if (!opts.executionArn) {\n throw new Error(\"[getRenderProgress] executionArn is required\");\n }\n const sfn = opts.sfn ?? new SFNClient({ region: opts.region });\n const memoryMb = opts.defaultMemorySizeMb ?? DEFAULT_MEMORY_MB;\n\n const describe = await sfn.send(\n new DescribeExecutionCommand({ executionArn: opts.executionArn }),\n );\n const status = (describe.status ?? \"RUNNING\") as RenderStatus;\n const startedAt = describe.startDate?.toISOString() ?? new Date(0).toISOString();\n const endedAt = describe.stopDate?.toISOString() ?? null;\n\n const history = await loadFullHistory(sfn, opts.executionArn);\n const summary = summarizeHistory(history, memoryMb);\n\n const costs = computeRenderCost(summary.lambdaInvocations, summary.stateTransitions);\n const overallProgress = computeOverallProgress({\n status,\n totalFrames: summary.totalFrames,\n framesRendered: summary.framesRendered,\n assembleComplete: summary.assembleComplete,\n });\n\n return {\n status,\n overallProgress,\n framesRendered: summary.framesRendered,\n totalFrames: summary.totalFrames,\n lambdasInvoked: summary.lambdasInvoked,\n costs,\n outputFile: summary.outputFile,\n errors: summary.errors,\n fatalErrorEncountered: isTerminalFailure(status),\n startedAt,\n endedAt,\n };\n}\n\nasync function loadFullHistory(sfn: SFNClient, executionArn: string): Promise<HistoryEvent[]> {\n const events: HistoryEvent[] = [];\n let nextToken: string | undefined;\n for (let page = 0; page < 50; page++) {\n const res = await sfn.send(\n new GetExecutionHistoryCommand({\n executionArn,\n maxResults: 1000,\n nextToken,\n reverseOrder: false,\n }),\n );\n if (res.events) events.push(...res.events);\n nextToken = res.nextToken;\n if (!nextToken) break;\n }\n return events;\n}\n\ninterface HistorySummary {\n lambdaInvocations: BilledLambdaInvocation[];\n stateTransitions: number;\n framesRendered: number;\n totalFrames: number | null;\n lambdasInvoked: number;\n assembleComplete: boolean;\n outputFile: { s3Uri: string; bytes: number | null } | null;\n errors: RenderError[];\n}\n\n/**\n * One pass over the history events that pulls every number {@link getRenderProgress}\n * needs. State transitions = the count of events that advance the state\n * machine (entering/exiting states + map iteration completions). Lambda\n * invocations = `LambdaFunctionScheduled` count. Frame totals come from\n * the success-payload of each Lambda invocation.\n */\nfunction summarizeHistory(events: HistoryEvent[], memoryMb: number): HistorySummary {\n let framesRendered = 0;\n let totalFrames: number | null = null;\n let lambdasInvoked = 0;\n let assembleComplete = false;\n let outputFile: HistorySummary[\"outputFile\"] = null;\n let stateTransitions = 0;\n const errors: RenderError[] = [];\n const lambdaInvocations: BilledLambdaInvocation[] = [];\n\n // Track the state name we most recently entered, so we can:\n // - attach the enclosing state to LambdaFunctionFailed errors, and\n // - identify when the Assemble state finished (StateExited.Assemble)\n // without relying on the inner Lambda payload's `Action` field.\n let currentLambdaState: string | null = null;\n\n for (const ev of events) {\n switch (ev.type) {\n case \"TaskStateEntered\":\n case \"MapStateEntered\":\n case \"PassStateEntered\":\n case \"ChoiceStateEntered\":\n case \"SucceedStateEntered\":\n case \"FailStateEntered\":\n case \"WaitStateEntered\":\n case \"ParallelStateEntered\":\n // Step Functions Standard Workflows bill per *state entry*, not per\n // history event. Lambda invocations produce ~5-7 history events\n // each (Scheduled / Started / Succeeded / TaskStateExited / \u2026);\n // counting every event as a transition over-reports cost by 3-5\u00D7.\n stateTransitions++;\n currentLambdaState = ev.stateEnteredEventDetails?.name ?? currentLambdaState;\n break;\n // Optimized `lambda:invoke` task emits Task* events; raw\n // `lambda:invokeFunction.sync` emits LambdaFunction*. Handle both.\n case \"TaskScheduled\":\n if (ev.taskScheduledEventDetails?.resourceType === \"lambda\") {\n lambdasInvoked++;\n }\n break;\n case \"LambdaFunctionScheduled\":\n lambdasInvoked++;\n break;\n case \"TaskSucceeded\": {\n if (ev.taskSucceededEventDetails?.resourceType !== \"lambda\") break;\n const wrapped = parseJson(ev.taskSucceededEventDetails?.output);\n const payload = unwrapLambdaPayload(wrapped);\n const billedDurationMs = inferBilledMs(payload);\n lambdaInvocations.push({\n billedDurationMs,\n memorySizeMb: memoryMb,\n estimated: billedDurationMs === 0,\n });\n applyPayloadFrameCounts(payload, currentLambdaState, (delta) => {\n framesRendered += delta;\n });\n if (payload && typeof payload === \"object\") {\n const obj = payload as Record<string, unknown>;\n if (typeof obj.TotalFrames === \"number\") totalFrames = obj.TotalFrames;\n }\n break;\n }\n case \"LambdaFunctionSucceeded\": {\n const payload = parseJson(ev.lambdaFunctionSucceededEventDetails?.output);\n const billedDurationMs = inferBilledMs(payload);\n lambdaInvocations.push({\n billedDurationMs,\n memorySizeMb: memoryMb,\n estimated: billedDurationMs === 0,\n });\n applyPayloadFrameCounts(payload, currentLambdaState, (delta) => {\n framesRendered += delta;\n });\n if (payload && typeof payload === \"object\") {\n const obj = payload as Record<string, unknown>;\n if (typeof obj.TotalFrames === \"number\") totalFrames = obj.TotalFrames;\n }\n break;\n }\n case \"TaskStateExited\":\n case \"MapStateExited\":\n // Mark the assemble step complete on its state-exit, independent\n // of the inner Lambda payload shape. The Assemble state's\n // ResultSelector pulls FileSize + OutputS3Uri from the Lambda\n // result, so we re-extract them here from the state exit's\n // own output rather than relying on the Lambda payload.\n if (ev.stateExitedEventDetails?.name === \"Assemble\") {\n assembleComplete = true;\n const exitPayload = parseJson(ev.stateExitedEventDetails?.output);\n if (exitPayload && typeof exitPayload === \"object\") {\n const obj = exitPayload as Record<string, unknown>;\n const out = obj.Output as Record<string, unknown> | undefined;\n const outputS3Uri = typeof out?.OutputS3Uri === \"string\" ? out.OutputS3Uri : null;\n const bytes = typeof out?.FileSize === \"number\" ? out.FileSize : null;\n outputFile = outputS3Uri ? { s3Uri: outputS3Uri, bytes } : outputFile;\n }\n }\n break;\n case \"TaskFailed\":\n if (ev.taskFailedEventDetails?.resourceType !== \"lambda\") break;\n errors.push({\n state: currentLambdaState ?? \"<unknown>\",\n error: ev.taskFailedEventDetails?.error ?? \"UNKNOWN\",\n cause: ev.taskFailedEventDetails?.cause ?? \"\",\n });\n break;\n case \"LambdaFunctionFailed\":\n errors.push({\n state: currentLambdaState ?? \"<unknown>\",\n error: ev.lambdaFunctionFailedEventDetails?.error ?? \"UNKNOWN\",\n cause: ev.lambdaFunctionFailedEventDetails?.cause ?? \"\",\n });\n break;\n case \"ExecutionFailed\":\n errors.push({\n state: \"<execution>\",\n error: ev.executionFailedEventDetails?.error ?? \"UNKNOWN\",\n cause: ev.executionFailedEventDetails?.cause ?? \"\",\n });\n break;\n case \"ExecutionAborted\":\n errors.push({\n state: \"<execution>\",\n error: ev.executionAbortedEventDetails?.error ?? \"ABORTED\",\n cause: ev.executionAbortedEventDetails?.cause ?? \"\",\n });\n break;\n case \"ExecutionTimedOut\":\n errors.push({\n state: \"<execution>\",\n error: \"TIMEOUT\",\n cause: ev.executionTimedOutEventDetails?.cause ?? \"\",\n });\n break;\n default:\n break;\n }\n }\n\n return {\n lambdaInvocations,\n stateTransitions,\n framesRendered,\n totalFrames,\n lambdasInvoked,\n assembleComplete,\n outputFile,\n errors,\n };\n}\n\nfunction parseJson(s: string | undefined): unknown {\n if (!s) return null;\n try {\n return JSON.parse(s);\n } catch {\n return null;\n }\n}\n\n/**\n * Optimized `lambda:invoke` wraps the Lambda response as\n * `{ ExecutedVersion, Payload: {\u2026handler payload\u2026}, StatusCode }`. Raw\n * `lambda:invokeFunction.sync` puts the handler payload at the root.\n * Return the inner `Payload` when present so callers read the same fields\n * either way.\n */\nfunction unwrapLambdaPayload(payload: unknown): unknown {\n if (payload && typeof payload === \"object\" && \"Payload\" in payload) {\n const inner = (payload as { Payload: unknown }).Payload;\n if (inner && typeof inner === \"object\") return inner;\n }\n return payload;\n}\n\n/**\n * Bump `framesRendered` only inside the `RenderChunk` state. Plan and\n * Assemble also report `FramesEncoded`, so a state-blind add would\n * double-count once Assemble runs.\n */\nfunction applyPayloadFrameCounts(\n payload: unknown,\n currentLambdaState: string | null,\n bump: (delta: number) => void,\n): void {\n if (currentLambdaState !== \"RenderChunk\") return;\n if (!payload || typeof payload !== \"object\") return;\n const obj = payload as Record<string, unknown>;\n if (typeof obj.FramesEncoded === \"number\") bump(obj.FramesEncoded);\n}\n\n/**\n * Lambda success payloads from our handler include `DurationMs` \u2014 the\n * wall-clock the handler observed. We use it as a best-effort proxy\n * for `BilledDuration` when SFN doesn't expose the latter directly\n * on `LambdaFunctionSucceeded` (the dedicated `BilledDuration` field\n * is in CloudWatch Metrics, not the SFN history payload).\n */\nfunction inferBilledMs(payload: unknown): number {\n if (!payload || typeof payload !== \"object\") return 0;\n const obj = payload as Record<string, unknown>;\n if (typeof obj.DurationMs === \"number\") return obj.DurationMs;\n return 0;\n}\n\ninterface ComputeProgressArgs {\n status: RenderStatus;\n totalFrames: number | null;\n framesRendered: number;\n assembleComplete: boolean;\n}\n\nfunction computeOverallProgress({\n status,\n totalFrames,\n framesRendered,\n assembleComplete,\n}: ComputeProgressArgs): number {\n if (status === \"SUCCEEDED\") return 1;\n if (assembleComplete) return 1;\n if (totalFrames === null) return 0;\n // 10 % Plan + 80 % chunk render + 10 % Assemble.\n const chunkProgress = Math.min(1, framesRendered / totalFrames);\n return 0.1 + 0.8 * chunkProgress;\n}\n\nfunction isTerminalFailure(status: RenderStatus): boolean {\n return status === \"FAILED\" || status === \"TIMED_OUT\" || status === \"ABORTED\";\n}\n", "/**\n * Per-render cost accounting for {@link getRenderProgress}.\n *\n * AWS bills Lambda by **GB-seconds** (billed-duration \u00D7 memory-in-GiB)\n * and Step Functions standard workflows by **state transitions**. Both\n * inputs are recoverable from the SFN execution history without an\n * extra CloudWatch query \u2014 the history events carry\n * `billedDurationInMillis` and `memorySizeInMB` on each Lambda\n * invocation, and the transition count is simply `history.length`\n * filtered to transition-worthy events.\n *\n * The math is documented inline so the constants stay close to the\n * pricing source they came from. Cost is **best-effort**: AWS pricing\n * varies by region + commitment plan; we use on-demand `us-east-1`\n * rates as of 2026-05 and label the result `displayCost` so callers\n * see the dollar value but downstream automation can also read the\n * raw number.\n */\n\n/** On-demand Lambda price, us-east-1, x86_64, on-demand: USD per GB-second. */\nconst LAMBDA_USD_PER_GB_SECOND = 0.0000166667;\n/** Step Functions Standard Workflows, us-east-1: USD per state transition. */\nconst SFN_USD_PER_TRANSITION = 0.000025;\n\n/** Raw history event subset the cost calc cares about. Caller filters from `getExecutionHistory`. */\nexport interface BilledLambdaInvocation {\n /** Millis of Lambda billed duration. Carried on `TaskSucceeded`/`TaskFailed` events. */\n billedDurationMs: number;\n /** Memory size in MB the function was configured with at invocation time. */\n memorySizeMb: number;\n /** `true` if the event payload did NOT carry a billed duration and we fell back to `Duration` or a constant. */\n estimated: boolean;\n}\n\n/** Result of {@link computeRenderCost}. */\nexport interface RenderCost {\n /** USD accrued to date. */\n accruedSoFarUsd: number;\n /** Human-readable USD string, e.g. `\"$0.0214\"`. */\n displayCost: string;\n breakdown: {\n lambdaUsd: number;\n stepFunctionsUsd: number;\n /** S3 transfer + storage cost varies by tier; we don't try to compute it here. */\n s3Estimate: \"not-included\";\n /** `true` if any Lambda invocation fell back to estimated billing. */\n estimated: boolean;\n };\n}\n\n/**\n * Sum Lambda GB-seconds + SFN transitions into an aggregate USD figure.\n *\n * `stateTransitions` is the count of billable state-machine transitions\n * \u2014 every successful state entry transitions once for standard\n * workflows. Express workflows price differently and are out of scope.\n */\nexport function computeRenderCost(\n lambdaInvocations: BilledLambdaInvocation[],\n stateTransitions: number,\n): RenderCost {\n let lambdaUsd = 0;\n let anyEstimated = false;\n for (const inv of lambdaInvocations) {\n const gbSeconds = (inv.memorySizeMb / 1024) * (inv.billedDurationMs / 1000);\n lambdaUsd += gbSeconds * LAMBDA_USD_PER_GB_SECOND;\n if (inv.estimated) anyEstimated = true;\n }\n const stepFunctionsUsd = stateTransitions * SFN_USD_PER_TRANSITION;\n const accruedSoFarUsd = roundUsd(lambdaUsd + stepFunctionsUsd);\n return {\n accruedSoFarUsd,\n displayCost: formatUsd(accruedSoFarUsd),\n breakdown: {\n lambdaUsd: roundUsd(lambdaUsd),\n stepFunctionsUsd: roundUsd(stepFunctionsUsd),\n s3Estimate: \"not-included\",\n estimated: anyEstimated,\n },\n };\n}\n\nfunction roundUsd(usd: number): number {\n // Four decimal places \u2014 enough resolution for per-chunk granularity on\n // a 10 GB Lambda. Anything finer is noise vs AWS' own rounding.\n return Math.round(usd * 10_000) / 10_000;\n}\n\nfunction formatUsd(usd: number): string {\n return `$${usd.toFixed(4)}`;\n}\n"],
|
|
5
|
-
"mappings": ";AAcA,SAAS,aAAa,aAAa,cAAc,UAAAA,SAAQ,YAAAC,iBAAgB;AACzE,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,mBAAmB,gBAAgB;AAC5C,SAAS,sCAAsC;;;ACA/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AAExB,SAAS,kBAAkB,wBAAuC;AAClE,YAAY,SAAS;AAS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;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,UAAU,GAAgC;AACjD,MAAI,CAAC,EAAG,QAAO;AACf,MAAI;AACF,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AASA,SAAS,oBAAoB,SAA2B;AACtD,MAAI,WAAW,OAAO,YAAY,YAAY,aAAa,SAAS;AAClE,UAAM,QAAS,QAAiC;AAChD,QAAI,SAAS,OAAO,UAAU,SAAU,QAAO;AAAA,EACjD;AACA,SAAO;AACT;AAOA,SAAS,wBACP,SACA,oBACA,MACM;AACN,MAAI,uBAAuB,cAAe;AAC1C,MAAI,CAAC,WAAW,OAAO,YAAY,SAAU;AAC7C,QAAM,MAAM;AACZ,MAAI,OAAO,IAAI,kBAAkB,SAAU,MAAK,IAAI,aAAa;AACnE;AASA,SAAS,cAAc,SAA0B;AAC/C,MAAI,CAAC,WAAW,OAAO,YAAY,SAAU,QAAO;AACpD,QAAM,MAAM;AACZ,MAAI,OAAO,IAAI,eAAe,SAAU,QAAO,IAAI;AACnD,SAAO;AACT;AASA,SAAS,uBAAuB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAgC;AAC9B,MAAI,WAAW,YAAa,QAAO;AACnC,MAAI,iBAAkB,QAAO;AAC7B,MAAI,gBAAgB,KAAM,QAAO;AAEjC,QAAM,gBAAgB,KAAK,IAAI,GAAG,iBAAiB,WAAW;AAC9D,SAAO,MAAM,MAAM;AACrB;AAEA,SAAS,kBAAkB,QAA+B;AACxD,SAAO,WAAW,YAAY,WAAW,eAAe,WAAW;AACrE;",
|
|
6
|
-
"names": ["rmSync", "statSync", "statSync", "rmSync", "SFNClient", "SFNClient"]
|
|
4
|
+
"sourcesContent": ["/**\n * `deploySite` \u2014 upload a project directory to S3 once per content hash\n * and return a reusable handle.\n *\n * `renderToLambda` calls this implicitly when no `siteHandle` is passed,\n * but exposing it as a standalone verb lets adopters bundle a project\n * ahead of time and reuse the handle across many renders without\n * re-tarring the project tree on every call.\n *\n * The handle is **content-addressed**: `siteId` is derived from a SHA-256\n * over the project files. Two `deploySite` calls on an unchanged tree\n * produce the same `siteId` and `HeadObject`-short-circuit the upload.\n */\n\nimport { mkdtempSync, rmSync, statSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { HeadObjectCommand, S3Client } from \"@aws-sdk/client-s3\";\nimport { hashProjectDir } from \"@hyperframes/producer/distributed\";\nimport { formatS3Uri, tarDirectory, uploadFileToS3 } from \"../s3Transport.js\";\n\n/** Options for {@link deploySite}. */\nexport interface DeploySiteOptions {\n /** Local project directory containing `index.html` (and any composition assets). */\n projectDir: string;\n /** S3 bucket the SAM stack / CDK construct provisioned. */\n bucketName: string;\n /** AWS region for the S3 client. Defaults to the SDK's default chain (env / config / IMDS). */\n region?: string;\n /**\n * Override the content-addressed site id. Useful when the caller has a\n * stable external identifier they want to use (e.g. a git SHA); if\n * unset, the hash of the project tree picks it.\n */\n siteId?: string;\n /** Injection seam for tests. Production callers leave unset. */\n s3?: S3Client;\n}\n\n/** Stable handle returned by {@link deploySite}. Pass back to {@link renderToLambda}. */\nexport interface SiteHandle {\n /** Content-addressed (or caller-supplied) identifier; stable across re-uploads of the same tree. */\n siteId: string;\n /** Bucket the site landed in. Surfaced separately so callers don't have to re-parse `projectS3Uri`. */\n bucketName: string;\n /** Full `s3://bucket/sites/<siteId>/project.tar.gz` URI; pass through to `renderToLambda`. */\n projectS3Uri: string;\n /** Tarball size in bytes; useful for \"did we actually skip the upload?\" assertions. */\n bytes: number;\n /** ISO timestamp of the most recent upload OR the existing object the short-circuit found. */\n uploadedAt: string;\n /** `false` if the object already existed and we skipped the PUT. */\n uploaded: boolean;\n}\n\n/**\n * Upload `projectDir` to `s3://bucketName/sites/<siteId>/project.tar.gz`.\n *\n * Short-circuits when an object with the same key already exists in the\n * bucket \u2014 `siteId` derives from the project's content hash, so the same\n * bytes produce the same key, and re-uploading would be redundant.\n */\nexport async function deploySite(opts: DeploySiteOptions): Promise<SiteHandle> {\n if (!statSync(opts.projectDir).isDirectory()) {\n throw new Error(`[deploySite] projectDir is not a directory: ${opts.projectDir}`);\n }\n\n const siteId = opts.siteId ?? hashProjectDir(opts.projectDir);\n const key = `sites/${siteId}/project.tar.gz`;\n const projectS3Uri = formatS3Uri({ bucket: opts.bucketName, key });\n const s3 = opts.s3 ?? new S3Client({ region: opts.region });\n\n // HeadObject short-circuit. Adopters re-rendering the same project on\n // a tight inner loop (CI smoke, demo flows) save the tar+gzip+PUT pass\n // on every iteration.\n const existing = await headObject(s3, opts.bucketName, key);\n if (existing) {\n return {\n siteId,\n bucketName: opts.bucketName,\n projectS3Uri,\n bytes: existing.bytes,\n uploadedAt: existing.lastModified,\n uploaded: false,\n };\n }\n\n const workdir = mkdtempSync(join(tmpdir(), \"hf-deploy-site-\"));\n try {\n const tarball = join(workdir, \"project.tar.gz\");\n await tarDirectory(opts.projectDir, tarball);\n // Note: tarDirectory packs *everything* under `cwd`. We don't need to\n // re-implement the skip list inside the tar pack because the\n // producer's plan stage applies the same skip during its copy; the\n // archive is slightly bigger than the planDir's compiled/ subtree\n // but the cost is bounded by the project's user-authored content.\n const size = statSync(tarball).size;\n await uploadFileToS3(s3, tarball, projectS3Uri, \"application/gzip\");\n return {\n siteId,\n bucketName: opts.bucketName,\n projectS3Uri,\n bytes: size,\n uploadedAt: new Date().toISOString(),\n uploaded: true,\n };\n } finally {\n rmSync(workdir, { recursive: true, force: true });\n }\n}\n\nasync function headObject(\n s3: S3Client,\n bucket: string,\n key: string,\n): Promise<{ bytes: number; lastModified: string } | null> {\n try {\n const res = await s3.send(new HeadObjectCommand({ Bucket: bucket, Key: key }));\n return {\n bytes: typeof res.ContentLength === \"number\" ? res.ContentLength : 0,\n lastModified:\n res.LastModified instanceof Date\n ? res.LastModified.toISOString()\n : new Date().toISOString(),\n };\n } catch (err) {\n // The SDK throws different error shapes for 404 vs 403 vs network;\n // a 404 means \"needs upload\" and is the most common case. Anything\n // else propagates so callers see auth / network failures.\n const status = (err as { $metadata?: { httpStatusCode?: number } }).$metadata?.httpStatusCode;\n if (status === 404) return null;\n const name = (err as { name?: string }).name;\n if (name === \"NotFound\" || name === \"NoSuchKey\") return null;\n throw err;\n }\n}\n", "/**\n * Thin S3 transport for the Lambda handler.\n *\n * The OSS distributed primitives are pure functions over local file paths;\n * the Lambda handler bridges S3 \u2194 Lambda's `/tmp` filesystem on each\n * invocation. Functions here are intentionally narrow: parse a URI, download\n * an object to a local path, upload a path/directory, tar-extract a planDir,\n * tar-pack a planDir back out.\n *\n * Tar (not zip) for planDir transit:\n * - planDirs contain symlinks (extract stage materializes them but the\n * compiled/ subtree may include linked assets); tar preserves them, zip\n * does not.\n * - We use the `tar` npm package (pure JS over `node:zlib`) \u2014 AWS\n * Lambda's `nodejs:22` base image ships neither `tar` nor `unzip` in\n * `/usr/bin`, so a system-binary tar would ENOENT in the actual\n * deployment.\n */\n\nimport {\n createReadStream,\n createWriteStream,\n existsSync,\n mkdirSync,\n rmSync,\n statSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { GetObjectCommand, PutObjectCommand, type S3Client } from \"@aws-sdk/client-s3\";\nimport * as tar from \"tar\";\n\n/** Parsed `s3://bucket/key` URI. */\nexport interface S3Location {\n bucket: string;\n key: string;\n}\n\n/** Parse `s3://bucket/key/path` \u2192 `{ bucket, key }`. Throws on malformed input. */\nexport function parseS3Uri(uri: string): S3Location {\n if (!uri.startsWith(\"s3://\")) {\n throw new Error(`[s3Transport] expected s3:// URI, got: ${JSON.stringify(uri)}`);\n }\n const rest = uri.slice(\"s3://\".length);\n const slash = rest.indexOf(\"/\");\n if (slash === -1) {\n throw new Error(`[s3Transport] missing key in s3 URI: ${JSON.stringify(uri)}`);\n }\n const bucket = rest.slice(0, slash);\n const key = rest.slice(slash + 1);\n if (!bucket || !key) {\n throw new Error(`[s3Transport] empty bucket or key in s3 URI: ${JSON.stringify(uri)}`);\n }\n return { bucket, key };\n}\n\n/** Build `s3://bucket/key` from a location. */\nexport function formatS3Uri(loc: S3Location): string {\n return `s3://${loc.bucket}/${loc.key}`;\n}\n\n/** Stream an S3 object to a local file path. Throws if the body is missing. */\nexport async function downloadS3ObjectToFile(\n client: S3Client,\n uri: string,\n destPath: string,\n): Promise<void> {\n const { bucket, key } = parseS3Uri(uri);\n const response = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key }));\n const body = response.Body as NodeJS.ReadableStream | undefined;\n if (!body) {\n throw new Error(`[s3Transport] s3 GetObject returned empty body for ${uri}`);\n }\n mkdirSync(dirname(destPath), { recursive: true });\n await pipeline(body, createWriteStream(destPath));\n}\n\n/**\n * Upload a local file's contents to an S3 URI using a streaming\n * `PutObjectCommand`. PutObject's 5 GB cap comfortably exceeds the\n * distributed pipeline's 2 GB planDir limit and the typical\n * chunk size (\u2264 200 MB), so a single PUT works for every artifact this\n * adapter handles.\n */\nexport async function uploadFileToS3(\n client: S3Client,\n localPath: string,\n uri: string,\n contentType?: string,\n): Promise<void> {\n if (!existsSync(localPath)) {\n throw new Error(`[s3Transport] upload source missing: ${localPath}`);\n }\n const { bucket, key } = parseS3Uri(uri);\n const size = statSync(localPath).size;\n await client.send(\n new PutObjectCommand({\n Bucket: bucket,\n Key: key,\n Body: createReadStream(localPath),\n ContentType: contentType,\n ContentLength: size,\n }),\n );\n}\n\n/**\n * Pack a directory into a `.tar.gz` at `destTarball`. Uses the `tar` npm\n * package (pure JS over `node:zlib`) rather than spawning a system tar\n * binary \u2014 the AWS Lambda Node 22 base image ships a minimal set of\n * userland tools and does NOT include `tar` in `/usr/bin`.\n */\nexport async function tarDirectory(sourceDir: string, destTarball: string): Promise<void> {\n if (!existsSync(sourceDir) || !statSync(sourceDir).isDirectory()) {\n throw new Error(`[s3Transport] tar source must be an existing directory: ${sourceDir}`);\n }\n mkdirSync(dirname(destTarball), { recursive: true });\n await tar.create({ gzip: true, file: destTarball, cwd: sourceDir }, [\".\"]);\n}\n\n/**\n * Extract a `.tar.gz` produced by {@link tarDirectory} into `destDir`.\n * The directory is created (or cleared) before extraction so a retried\n * invocation doesn't observe stale files from a prior run on the same\n * warm Lambda container.\n */\nexport async function untarDirectory(tarballPath: string, destDir: string): Promise<void> {\n if (!existsSync(tarballPath)) {\n throw new Error(`[s3Transport] tarball missing: ${tarballPath}`);\n }\n // Wipe target so the warm container's prior planDir doesn't bleed into\n // the new invocation. Lambda re-uses /tmp across invocations on the same\n // container.\n if (existsSync(destDir)) {\n rmSync(destDir, { recursive: true, force: true });\n }\n mkdirSync(destDir, { recursive: true });\n await tar.extract({ file: tarballPath, cwd: destDir });\n}\n", "/**\n * `renderToLambda` \u2014 start a distributed render against an already-deployed\n * SAM/CDK stack and return a handle the caller can poll with\n * {@link getRenderProgress}.\n *\n * The function does *not* wait for the render to finish. Step Functions\n * standard workflows can run for hours; blocking the caller's process on\n * the SFN execution is the wrong default. The returned `RenderHandle`\n * carries everything the progress / cost / download paths need.\n *\n * Wire order:\n * 1. Validate config (typed throw before any AWS call).\n * 2. `deploySite` if no `siteHandle` was provided.\n * 3. `StartExecution` against the state machine with the same input\n * shape `examples/aws-lambda/scripts/smoke.sh` builds.\n * 4. Return handle. The S3 `outputKey` is deterministic from the\n * execution name so the caller can predict the final object URL.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { SFNClient, StartExecutionCommand } from \"@aws-sdk/client-sfn\";\nimport type { S3Client } from \"@aws-sdk/client-s3\";\nimport type { SerializableDistributedRenderConfig } from \"../events.js\";\nimport { formatExtension } from \"../formatExtension.js\";\nimport { formatS3Uri } from \"../s3Transport.js\";\nimport { deploySite, type SiteHandle } from \"./deploySite.js\";\nimport {\n validateDistributedRenderConfig,\n validateStepFunctionsInputSize,\n} from \"./validateConfig.js\";\n\n/** Options for {@link renderToLambda}. */\nexport interface RenderToLambdaOptions {\n /** Local project directory. Required when `siteHandle` is not supplied. */\n projectDir?: string;\n /** Re-use an existing `deploySite` upload (skips tar+S3 PUT). */\n siteHandle?: SiteHandle;\n /** Validated `SerializableDistributedRenderConfig` (no logger / abortSignal). */\n config: SerializableDistributedRenderConfig;\n /** S3 bucket from the SAM stack output (`RenderBucketName`). */\n bucketName: string;\n /** State machine ARN from the SAM stack output (`RenderStateMachineArn`). */\n stateMachineArn: string;\n /** AWS region; defaults to the SDK default chain. */\n region?: string;\n /**\n * Final output S3 key. Defaults to `renders/<executionName>/output.<ext>`\n * where `<ext>` is derived from `config.format`.\n */\n outputKey?: string;\n /**\n * Step Functions execution name. Defaults to `hf-render-<uuid>`.\n * Used as `renderId` everywhere downstream (history queries, cost\n * accounting, predictable S3 key prefix).\n */\n executionName?: string;\n /** Test injection seam \u2014 production callers leave unset. */\n sfn?: SFNClient;\n /** Test injection seam \u2014 propagated to `deploySite` when applicable. */\n s3?: S3Client;\n}\n\n/** Stable identifier + every URL/ARN the caller needs to follow the render. */\nexport interface RenderHandle {\n /** Same as the Step Functions execution name. */\n renderId: string;\n /** Full execution ARN; pass to {@link getRenderProgress}. */\n executionArn: string;\n bucketName: string;\n stateMachineArn: string;\n outputS3Uri: string;\n projectS3Uri: string;\n startedAt: string;\n}\n\n// fallow-ignore-next-line complexity\nexport async function renderToLambda(opts: RenderToLambdaOptions): Promise<RenderHandle> {\n validateDistributedRenderConfig(opts.config);\n\n if (!opts.bucketName) {\n throw new Error(\"[renderToLambda] bucketName is required\");\n }\n if (!opts.stateMachineArn) {\n throw new Error(\"[renderToLambda] stateMachineArn is required\");\n }\n if (!opts.siteHandle && !opts.projectDir) {\n throw new Error(\"[renderToLambda] either siteHandle or projectDir must be supplied\");\n }\n\n const executionName = opts.executionName ?? `hf-render-${randomUUID()}`;\n const ext = formatExtension(opts.config.format);\n const outputKey = opts.outputKey ?? `renders/${executionName}/output${ext}`;\n const planOutputS3Prefix = formatS3Uri({\n bucket: opts.bucketName,\n key: `renders/${executionName}/`,\n });\n const outputS3Uri = formatS3Uri({ bucket: opts.bucketName, key: outputKey });\n\n const site =\n opts.siteHandle ??\n (await deploySite({\n projectDir: opts.projectDir as string,\n bucketName: opts.bucketName,\n region: opts.region,\n s3: opts.s3,\n }));\n\n const input = {\n ProjectS3Uri: site.projectS3Uri,\n PlanOutputS3Prefix: planOutputS3Prefix,\n OutputS3Uri: outputS3Uri,\n Config: opts.config,\n };\n\n // Reject oversize input client-side. Step Functions Standard caps the\n // execution input at 256 KiB; without this check, the input bloat\n // (typically from `config.variables` containing inlined media) surfaces\n // as `States.DataLimitExceeded` 50 ms into the execution, far from the\n // caller's stack frame. Measured AFTER `deploySite` so the synthesised\n // `ProjectS3Uri` is counted (a few hundred bytes either way, but the\n // check should be against the actual wire payload).\n validateStepFunctionsInputSize(input);\n\n const sfn = opts.sfn ?? new SFNClient({ region: opts.region });\n const startedAt = new Date().toISOString();\n const response = await sfn.send(\n new StartExecutionCommand({\n stateMachineArn: opts.stateMachineArn,\n name: executionName,\n input: JSON.stringify(input),\n }),\n );\n\n if (!response.executionArn) {\n throw new Error(\"[renderToLambda] StartExecution returned no executionArn\");\n }\n\n return {\n renderId: executionName,\n executionArn: response.executionArn,\n bucketName: opts.bucketName,\n stateMachineArn: opts.stateMachineArn,\n outputS3Uri,\n projectS3Uri: site.projectS3Uri,\n startedAt,\n };\n}\n", "/**\n * Map a distributed `format` to the file extension the assembled output\n * should carry on disk + in S3. Shared by `src/handler.ts` (chunk +\n * assemble output paths) and `src/sdk/renderToLambda.ts` (final\n * output key construction) so the two sides agree on what an mp4\n * looks like vs a png-sequence.\n */\n\nimport type { DistributedFormat } from \"@hyperframes/producer/distributed\";\n\nexport type { DistributedFormat } from \"@hyperframes/producer/distributed\";\n\n// Closed-enum lookup table. TS enforces exhaustiveness via the\n// `Record<DistributedFormat, string>` annotation \u2014 adding a format to\n// `DistributedFormat` without adding the matching key here fails to\n// typecheck, which is the same exhaustiveness guarantee a switch +\n// `_exhaustive: never` arm provides but at lower complexity.\nconst FORMAT_EXTENSIONS: Record<DistributedFormat, string> = {\n mp4: \".mp4\",\n mov: \".mov\",\n webm: \".webm\",\n \"png-sequence\": \"\",\n};\n\nexport function formatExtension(format: DistributedFormat): string {\n return FORMAT_EXTENSIONS[format];\n}\n", "/**\n * Client-side validation for the AWS Lambda adapter.\n *\n * The cloud-agnostic config-shape validation (`validateDistributedRenderConfig`,\n * `validateVariablesPayload`, `InvalidConfigError`) lives in\n * `@hyperframes/producer/distributed` and is shared with the other adapters.\n * This module re-exports those and adds the one piece specific to Step\n * Functions: the 256 KiB Standard-workflow execution-input size cap.\n */\n\nimport { InvalidConfigError } from \"@hyperframes/producer/distributed\";\n\nexport {\n InvalidConfigError,\n validateDistributedRenderConfig,\n validateVariablesPayload,\n} from \"@hyperframes/producer/distributed\";\n\n/**\n * Hard cap on Step Functions Standard workflow execution input \u2014 256 KiB per\n * the AWS limits page. Express workflows cap at 32 KiB; the render stack runs\n * Standard for execution-history visibility, so the larger limit applies. The\n * cap is on the entire serialized input, not just the variables, because\n * users hit it at the wire boundary regardless of which field caused the\n * bloat.\n *\n * Specific to Step Functions Standard. Other workflow runtimes (Temporal,\n * Express SFN, Cloud Workflows, raw Lambda invoke) have different caps; don't\n * reuse this constant for those without confirming the limit.\n */\nexport const MAX_STEP_FUNCTIONS_INPUT_BYTES = 256 * 1024;\n\n/** Pointer to the docs section that explains the URL-your-assets convention. */\nconst LARGE_VARIABLES_DOCS_URL =\n \"https://hyperframes.heygen.com/deploy/templates-on-lambda#working-with-large-variables\";\n\n/**\n * Validate that the serialized Step Functions execution input fits inside the\n * 256 KiB Standard-workflow cap. Measured in UTF-8 bytes (the format Step\n * Functions uses on the wire) \u2014 JS strings count UTF-16 code units, which\n * under-reports for any multi-byte character.\n *\n * Throws {@link InvalidConfigError} with a clear message naming the actual\n * byte count, the cap, and a pointer to the \"working with large variables\"\n * docs section, so users hit the limit at the SDK boundary with actionable\n * guidance instead of as a `States.DataLimitExceeded` 50 ms into the\n * execution.\n */\n// fallow-ignore-next-line complexity\nexport function validateStepFunctionsInputSize(input: unknown): void {\n let serialized: string | undefined;\n try {\n serialized = JSON.stringify(input);\n } catch (err) {\n throw new InvalidConfigError(\n \"config\",\n `Step Functions execution input is not JSON-serializable: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n if (serialized === undefined) {\n throw new InvalidConfigError(\n \"config\",\n \"Step Functions execution input is not JSON-serializable (JSON.stringify returned undefined). \" +\n \"Check that all fields, including config.variables, are plain JSON values.\",\n );\n }\n const byteLength = Buffer.byteLength(serialized, \"utf8\");\n if (byteLength > MAX_STEP_FUNCTIONS_INPUT_BYTES) {\n throw new InvalidConfigError(\n \"config\",\n `Step Functions execution input is ${byteLength} bytes, which exceeds the ` +\n `${MAX_STEP_FUNCTIONS_INPUT_BYTES}-byte (256 KiB) limit for Standard workflows. ` +\n `Variables are for typed data (strings, numbers, structured records); media assets ` +\n `(images, audio, video) should be passed as URL references the composition resolves ` +\n `at render time, not inlined as base64. See ${LARGE_VARIABLES_DOCS_URL} for the ` +\n `URL-your-assets convention.`,\n );\n }\n}\n", "/**\n * `getRenderProgress` \u2014 read-only progress + cost snapshot for a single\n * render started by {@link renderToLambda}.\n *\n * Pulls one `DescribeExecution` + one `GetExecutionHistory` per call. The\n * history is paginated server-side; the helper loops until exhausted so a\n * 1,000-event Step Functions execution still produces a single\n * `RenderProgress` snapshot.\n *\n * Progress math:\n * - 0 before Plan completes (no frame count is known yet)\n * - 0.1 once Plan completes (we know `totalFrames`)\n * - 0.1 + 0.8 \u00D7 framesEncoded / totalFrames during chunk render\n * - 1.0 after Assemble completes\n *\n * Frame counts come from the parsed Lambda result payloads on each\n * `TaskSucceeded` event \u2014 Plan reports `TotalFrames`, RenderChunk reports\n * `FramesEncoded`. The shape mirrors what the handler produces in\n * `events.ts`, so the parser doesn't need to know anything beyond\n * \"JSON.parse this string and grab two fields.\"\n */\n\nimport {\n DescribeExecutionCommand,\n GetExecutionHistoryCommand,\n type HistoryEvent,\n SFNClient,\n} from \"@aws-sdk/client-sfn\";\nimport {\n type BilledLambdaInvocation,\n computeRenderCost,\n type RenderCost,\n} from \"./costAccounting.js\";\n\n/** Options for {@link getRenderProgress}. */\nexport interface GetRenderProgressOptions {\n /** Execution ARN from a {@link renderToLambda} call. */\n executionArn: string;\n /**\n * Default memory size in MB to assume for Lambda invocations when the\n * history event payload doesn't carry it explicitly. Matches the\n * `LambdaMemoryMb` parameter the stack was deployed with.\n */\n defaultMemorySizeMb?: number;\n region?: string;\n /** Test injection seam. */\n sfn?: SFNClient;\n}\n\n/** Render-status discriminant; mirrors Step Functions execution states. */\nexport type RenderStatus =\n | \"RUNNING\"\n | \"SUCCEEDED\"\n | \"FAILED\"\n | \"TIMED_OUT\"\n | \"ABORTED\"\n | \"PENDING_REDRIVE\";\n\nexport interface RenderError {\n /** State name where the failure surfaced (`Plan`, `RenderChunk`, `Assemble`, or `<unknown>`). */\n state: string;\n /** Error class / type as Step Functions reports it. */\n error: string;\n /** Cause string Step Functions surfaces (often a stringified JSON payload from the handler). */\n cause: string;\n}\n\n/** Snapshot of a single render's progress + cost + errors at one point in time. */\nexport interface RenderProgress {\n status: RenderStatus;\n /** `[0, 1]`; see module doc for the math. */\n overallProgress: number;\n framesRendered: number;\n /** `null` until Plan completes. */\n totalFrames: number | null;\n /** Total Lambda invocations scheduled so far (both optimized + raw task integrations). */\n lambdasInvoked: number;\n costs: RenderCost;\n /** Final output object if Assemble succeeded; `null` otherwise. */\n outputFile: { s3Uri: string; bytes: number | null } | null;\n errors: RenderError[];\n /** `true` once the execution has terminated in a non-`SUCCEEDED` state. */\n fatalErrorEncountered: boolean;\n startedAt: string;\n endedAt: string | null;\n}\n\nconst DEFAULT_MEMORY_MB = 10240;\n\n/** Pull a current progress snapshot for one render. */\nexport async function getRenderProgress(opts: GetRenderProgressOptions): Promise<RenderProgress> {\n if (!opts.executionArn) {\n throw new Error(\"[getRenderProgress] executionArn is required\");\n }\n const sfn = opts.sfn ?? new SFNClient({ region: opts.region });\n const memoryMb = opts.defaultMemorySizeMb ?? DEFAULT_MEMORY_MB;\n\n const describe = await sfn.send(\n new DescribeExecutionCommand({ executionArn: opts.executionArn }),\n );\n const status = (describe.status ?? \"RUNNING\") as RenderStatus;\n const startedAt = describe.startDate?.toISOString() ?? new Date(0).toISOString();\n const endedAt = describe.stopDate?.toISOString() ?? null;\n\n const history = await loadFullHistory(sfn, opts.executionArn);\n const summary = summarizeHistory(history, memoryMb);\n\n const costs = computeRenderCost(summary.lambdaInvocations, summary.stateTransitions);\n const overallProgress = computeOverallProgress({\n status,\n totalFrames: summary.totalFrames,\n framesRendered: summary.framesRendered,\n assembleComplete: summary.assembleComplete,\n });\n\n return {\n status,\n overallProgress,\n framesRendered: summary.framesRendered,\n totalFrames: summary.totalFrames,\n lambdasInvoked: summary.lambdasInvoked,\n costs,\n outputFile: summary.outputFile,\n errors: summary.errors,\n fatalErrorEncountered: isTerminalFailure(status),\n startedAt,\n endedAt,\n };\n}\n\nasync function loadFullHistory(sfn: SFNClient, executionArn: string): Promise<HistoryEvent[]> {\n const events: HistoryEvent[] = [];\n let nextToken: string | undefined;\n for (let page = 0; page < 50; page++) {\n const res = await sfn.send(\n new GetExecutionHistoryCommand({\n executionArn,\n maxResults: 1000,\n nextToken,\n reverseOrder: false,\n }),\n );\n if (res.events) events.push(...res.events);\n nextToken = res.nextToken;\n if (!nextToken) break;\n }\n return events;\n}\n\ninterface HistorySummary {\n lambdaInvocations: BilledLambdaInvocation[];\n stateTransitions: number;\n framesRendered: number;\n totalFrames: number | null;\n lambdasInvoked: number;\n assembleComplete: boolean;\n outputFile: { s3Uri: string; bytes: number | null } | null;\n errors: RenderError[];\n}\n\n/**\n * One pass over the history events that pulls every number {@link getRenderProgress}\n * needs. State transitions = the count of events that advance the state\n * machine (entering/exiting states + map iteration completions). Lambda\n * invocations = `LambdaFunctionScheduled` count. Frame totals come from\n * the success-payload of each Lambda invocation.\n */\nfunction summarizeHistory(events: HistoryEvent[], memoryMb: number): HistorySummary {\n let framesRendered = 0;\n let totalFrames: number | null = null;\n let lambdasInvoked = 0;\n let assembleComplete = false;\n let outputFile: HistorySummary[\"outputFile\"] = null;\n let stateTransitions = 0;\n const errors: RenderError[] = [];\n const lambdaInvocations: BilledLambdaInvocation[] = [];\n\n // Track the state name we most recently entered, so we can:\n // - attach the enclosing state to LambdaFunctionFailed errors, and\n // - identify when the Assemble state finished (StateExited.Assemble)\n // without relying on the inner Lambda payload's `Action` field.\n let currentLambdaState: string | null = null;\n\n for (const ev of events) {\n switch (ev.type) {\n case \"TaskStateEntered\":\n case \"MapStateEntered\":\n case \"PassStateEntered\":\n case \"ChoiceStateEntered\":\n case \"SucceedStateEntered\":\n case \"FailStateEntered\":\n case \"WaitStateEntered\":\n case \"ParallelStateEntered\":\n // Step Functions Standard Workflows bill per *state entry*, not per\n // history event. Lambda invocations produce ~5-7 history events\n // each (Scheduled / Started / Succeeded / TaskStateExited / \u2026);\n // counting every event as a transition over-reports cost by 3-5\u00D7.\n stateTransitions++;\n currentLambdaState = ev.stateEnteredEventDetails?.name ?? currentLambdaState;\n break;\n // Optimized `lambda:invoke` task emits Task* events; raw\n // `lambda:invokeFunction.sync` emits LambdaFunction*. Handle both.\n case \"TaskScheduled\":\n if (ev.taskScheduledEventDetails?.resourceType === \"lambda\") {\n lambdasInvoked++;\n }\n break;\n case \"LambdaFunctionScheduled\":\n lambdasInvoked++;\n break;\n case \"TaskSucceeded\": {\n if (ev.taskSucceededEventDetails?.resourceType !== \"lambda\") break;\n const wrapped = parseJson(ev.taskSucceededEventDetails?.output);\n const payload = unwrapLambdaPayload(wrapped);\n const billedDurationMs = inferBilledMs(payload);\n lambdaInvocations.push({\n billedDurationMs,\n memorySizeMb: memoryMb,\n estimated: billedDurationMs === 0,\n });\n applyPayloadFrameCounts(payload, currentLambdaState, (delta) => {\n framesRendered += delta;\n });\n if (payload && typeof payload === \"object\") {\n const obj = payload as Record<string, unknown>;\n if (typeof obj.TotalFrames === \"number\") totalFrames = obj.TotalFrames;\n }\n break;\n }\n case \"LambdaFunctionSucceeded\": {\n const payload = parseJson(ev.lambdaFunctionSucceededEventDetails?.output);\n const billedDurationMs = inferBilledMs(payload);\n lambdaInvocations.push({\n billedDurationMs,\n memorySizeMb: memoryMb,\n estimated: billedDurationMs === 0,\n });\n applyPayloadFrameCounts(payload, currentLambdaState, (delta) => {\n framesRendered += delta;\n });\n if (payload && typeof payload === \"object\") {\n const obj = payload as Record<string, unknown>;\n if (typeof obj.TotalFrames === \"number\") totalFrames = obj.TotalFrames;\n }\n break;\n }\n case \"TaskStateExited\":\n case \"MapStateExited\":\n // Mark the assemble step complete on its state-exit, independent\n // of the inner Lambda payload shape. The Assemble state's\n // ResultSelector pulls FileSize + OutputS3Uri from the Lambda\n // result, so we re-extract them here from the state exit's\n // own output rather than relying on the Lambda payload.\n if (ev.stateExitedEventDetails?.name === \"Assemble\") {\n assembleComplete = true;\n const exitPayload = parseJson(ev.stateExitedEventDetails?.output);\n if (exitPayload && typeof exitPayload === \"object\") {\n const obj = exitPayload as Record<string, unknown>;\n const out = obj.Output as Record<string, unknown> | undefined;\n const outputS3Uri = typeof out?.OutputS3Uri === \"string\" ? out.OutputS3Uri : null;\n const bytes = typeof out?.FileSize === \"number\" ? out.FileSize : null;\n outputFile = outputS3Uri ? { s3Uri: outputS3Uri, bytes } : outputFile;\n }\n }\n break;\n case \"TaskFailed\":\n if (ev.taskFailedEventDetails?.resourceType !== \"lambda\") break;\n errors.push({\n state: currentLambdaState ?? \"<unknown>\",\n error: ev.taskFailedEventDetails?.error ?? \"UNKNOWN\",\n cause: ev.taskFailedEventDetails?.cause ?? \"\",\n });\n break;\n case \"LambdaFunctionFailed\":\n errors.push({\n state: currentLambdaState ?? \"<unknown>\",\n error: ev.lambdaFunctionFailedEventDetails?.error ?? \"UNKNOWN\",\n cause: ev.lambdaFunctionFailedEventDetails?.cause ?? \"\",\n });\n break;\n case \"ExecutionFailed\":\n errors.push({\n state: \"<execution>\",\n error: ev.executionFailedEventDetails?.error ?? \"UNKNOWN\",\n cause: ev.executionFailedEventDetails?.cause ?? \"\",\n });\n break;\n case \"ExecutionAborted\":\n errors.push({\n state: \"<execution>\",\n error: ev.executionAbortedEventDetails?.error ?? \"ABORTED\",\n cause: ev.executionAbortedEventDetails?.cause ?? \"\",\n });\n break;\n case \"ExecutionTimedOut\":\n errors.push({\n state: \"<execution>\",\n error: \"TIMEOUT\",\n cause: ev.executionTimedOutEventDetails?.cause ?? \"\",\n });\n break;\n default:\n break;\n }\n }\n\n return {\n lambdaInvocations,\n stateTransitions,\n framesRendered,\n totalFrames,\n lambdasInvoked,\n assembleComplete,\n outputFile,\n errors,\n };\n}\n\nfunction parseJson(s: string | undefined): unknown {\n if (!s) return null;\n try {\n return JSON.parse(s);\n } catch {\n return null;\n }\n}\n\n/**\n * Optimized `lambda:invoke` wraps the Lambda response as\n * `{ ExecutedVersion, Payload: {\u2026handler payload\u2026}, StatusCode }`. Raw\n * `lambda:invokeFunction.sync` puts the handler payload at the root.\n * Return the inner `Payload` when present so callers read the same fields\n * either way.\n */\nfunction unwrapLambdaPayload(payload: unknown): unknown {\n if (payload && typeof payload === \"object\" && \"Payload\" in payload) {\n const inner = (payload as { Payload: unknown }).Payload;\n if (inner && typeof inner === \"object\") return inner;\n }\n return payload;\n}\n\n/**\n * Bump `framesRendered` only inside the `RenderChunk` state. Plan and\n * Assemble also report `FramesEncoded`, so a state-blind add would\n * double-count once Assemble runs.\n */\nfunction applyPayloadFrameCounts(\n payload: unknown,\n currentLambdaState: string | null,\n bump: (delta: number) => void,\n): void {\n if (currentLambdaState !== \"RenderChunk\") return;\n if (!payload || typeof payload !== \"object\") return;\n const obj = payload as Record<string, unknown>;\n if (typeof obj.FramesEncoded === \"number\") bump(obj.FramesEncoded);\n}\n\n/**\n * Lambda success payloads from our handler include `DurationMs` \u2014 the\n * wall-clock the handler observed. We use it as a best-effort proxy\n * for `BilledDuration` when SFN doesn't expose the latter directly\n * on `LambdaFunctionSucceeded` (the dedicated `BilledDuration` field\n * is in CloudWatch Metrics, not the SFN history payload).\n */\nfunction inferBilledMs(payload: unknown): number {\n if (!payload || typeof payload !== \"object\") return 0;\n const obj = payload as Record<string, unknown>;\n if (typeof obj.DurationMs === \"number\") return obj.DurationMs;\n return 0;\n}\n\ninterface ComputeProgressArgs {\n status: RenderStatus;\n totalFrames: number | null;\n framesRendered: number;\n assembleComplete: boolean;\n}\n\nfunction computeOverallProgress({\n status,\n totalFrames,\n framesRendered,\n assembleComplete,\n}: ComputeProgressArgs): number {\n if (status === \"SUCCEEDED\") return 1;\n if (assembleComplete) return 1;\n if (totalFrames === null) return 0;\n // 10 % Plan + 80 % chunk render + 10 % Assemble.\n const chunkProgress = Math.min(1, framesRendered / totalFrames);\n return 0.1 + 0.8 * chunkProgress;\n}\n\nfunction isTerminalFailure(status: RenderStatus): boolean {\n return status === \"FAILED\" || status === \"TIMED_OUT\" || status === \"ABORTED\";\n}\n", "/**\n * Per-render cost accounting for {@link getRenderProgress}.\n *\n * AWS bills Lambda by **GB-seconds** (billed-duration \u00D7 memory-in-GiB)\n * and Step Functions standard workflows by **state transitions**. Both\n * inputs are recoverable from the SFN execution history without an\n * extra CloudWatch query \u2014 the history events carry\n * `billedDurationInMillis` and `memorySizeInMB` on each Lambda\n * invocation, and the transition count is simply `history.length`\n * filtered to transition-worthy events.\n *\n * The math is documented inline so the constants stay close to the\n * pricing source they came from. Cost is **best-effort**: AWS pricing\n * varies by region + commitment plan; we use on-demand `us-east-1`\n * rates as of 2026-05 and label the result `displayCost` so callers\n * see the dollar value but downstream automation can also read the\n * raw number.\n */\n\n/** On-demand Lambda price, us-east-1, x86_64, on-demand: USD per GB-second. */\nconst LAMBDA_USD_PER_GB_SECOND = 0.0000166667;\n/** Step Functions Standard Workflows, us-east-1: USD per state transition. */\nconst SFN_USD_PER_TRANSITION = 0.000025;\n\n/** Raw history event subset the cost calc cares about. Caller filters from `getExecutionHistory`. */\nexport interface BilledLambdaInvocation {\n /** Millis of Lambda billed duration. Carried on `TaskSucceeded`/`TaskFailed` events. */\n billedDurationMs: number;\n /** Memory size in MB the function was configured with at invocation time. */\n memorySizeMb: number;\n /** `true` if the event payload did NOT carry a billed duration and we fell back to `Duration` or a constant. */\n estimated: boolean;\n}\n\n/** Result of {@link computeRenderCost}. */\nexport interface RenderCost {\n /** USD accrued to date. */\n accruedSoFarUsd: number;\n /** Human-readable USD string, e.g. `\"$0.0214\"`. */\n displayCost: string;\n breakdown: {\n lambdaUsd: number;\n stepFunctionsUsd: number;\n /** S3 transfer + storage cost varies by tier; we don't try to compute it here. */\n s3Estimate: \"not-included\";\n /** `true` if any Lambda invocation fell back to estimated billing. */\n estimated: boolean;\n };\n}\n\n/**\n * Sum Lambda GB-seconds + SFN transitions into an aggregate USD figure.\n *\n * `stateTransitions` is the count of billable state-machine transitions\n * \u2014 every successful state entry transitions once for standard\n * workflows. Express workflows price differently and are out of scope.\n */\nexport function computeRenderCost(\n lambdaInvocations: BilledLambdaInvocation[],\n stateTransitions: number,\n): RenderCost {\n let lambdaUsd = 0;\n let anyEstimated = false;\n for (const inv of lambdaInvocations) {\n const gbSeconds = (inv.memorySizeMb / 1024) * (inv.billedDurationMs / 1000);\n lambdaUsd += gbSeconds * LAMBDA_USD_PER_GB_SECOND;\n if (inv.estimated) anyEstimated = true;\n }\n const stepFunctionsUsd = stateTransitions * SFN_USD_PER_TRANSITION;\n const accruedSoFarUsd = roundUsd(lambdaUsd + stepFunctionsUsd);\n return {\n accruedSoFarUsd,\n displayCost: formatUsd(accruedSoFarUsd),\n breakdown: {\n lambdaUsd: roundUsd(lambdaUsd),\n stepFunctionsUsd: roundUsd(stepFunctionsUsd),\n s3Estimate: \"not-included\",\n estimated: anyEstimated,\n },\n };\n}\n\nfunction roundUsd(usd: number): number {\n // Four decimal places \u2014 enough resolution for per-chunk granularity on\n // a 10 GB Lambda. Anything finer is noise vs AWS' own rounding.\n return Math.round(usd * 10_000) / 10_000;\n}\n\nfunction formatUsd(usd: number): string {\n return `$${usd.toFixed(4)}`;\n}\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