@hyperframes/aws-lambda 0.6.24 → 0.6.26
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 +4 -4
- package/dist/events.d.ts.map +1 -1
- package/dist/formatExtension.d.ts +2 -1
- package/dist/formatExtension.d.ts.map +1 -1
- package/dist/handler.js +29 -35
- package/dist/handler.js.map +3 -3
- package/dist/index.js +41 -42
- package/dist/index.js.map +3 -3
- package/dist/s3Transport.d.ts +0 -2
- package/dist/s3Transport.d.ts.map +1 -1
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +20 -21
- package/dist/sdk/index.js.map +3 -3
- package/dist/sdk/validateConfig.d.ts +3 -2
- package/dist/sdk/validateConfig.d.ts.map +1 -1
- package/package.json +2 -2
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 readdirSync,\n rmSync,\n statSync,\n} from \"node:fs\";\nimport { dirname, join } 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/** List all regular files under a directory, sorted, returned as absolute paths. */\nexport function listFilesInDirectory(dir: string): string[] {\n const out: string[] = [];\n function walk(d: string): void {\n for (const entry of readdirSync(d, { withFileTypes: true }).sort((a, b) =>\n a.name < b.name ? -1 : a.name > b.name ? 1 : 0,\n )) {\n const full = join(d, entry.name);\n if (entry.isDirectory()) walk(full);\n else if (entry.isFile()) out.push(full);\n }\n }\n walk(dir);\n return out;\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 { validateDistributedRenderConfig } 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\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 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\nexport type DistributedFormat = \"mp4\" | \"mov\" | \"png-sequence\";\n\nexport function formatExtension(format: DistributedFormat): string {\n switch (format) {\n case \"mp4\":\n return \".mp4\";\n case \"mov\":\n return \".mov\";\n case \"png-sequence\":\n return \"\";\n default: {\n const _exhaustive: never = format;\n throw new Error(`[formatExtension] unsupported format: ${_exhaustive as string}`);\n }\n }\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 documented `webm`/`force-hdr` rejections from \u00A75.3 of the\n * distributed-rendering plan. Anything deeper (font availability, plan\n * size cap, GPU mode at runtime) needs the actual planner.\n */\n\nimport type { SerializableDistributedRenderConfig } from \"../events.js\";\n\n/** Thrown for any client-side `SerializableDistributedRenderConfig` violation. */\nexport class InvalidConfigError extends Error {\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 = [\"mp4\", \"mov\", \"png-sequence\"] as const;\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 return config;\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 /** Count of `LambdaFunctionScheduled` events seen in the history so far. */\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 case \"LambdaFunctionScheduled\":\n lambdasInvoked++;\n break;\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 if (payload && typeof payload === \"object\") {\n const obj = payload as Record<string, unknown>;\n if (typeof obj.TotalFrames === \"number\") totalFrames = obj.TotalFrames;\n if (typeof obj.FramesEncoded === \"number\") {\n // Plan and Assemble also return FramesEncoded; count framesRendered\n // only inside the RenderChunk state so we don't double-count\n // it on the Assemble pass. Keyed off the enclosing state name\n // (set by the matching StateEntered) rather than the payload's\n // `Action` field \u2014 `Action` is part of the Lambda event\n // contract and not load-bearing for state-machine identity.\n if (currentLambdaState === \"RenderChunk\") {\n framesRendered += obj.FramesEncoded;\n }\n }\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 \"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 * 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,eAAAA,cAAa,cAAc,UAAAC,SAAQ,YAAAC,iBAAgB;AACzE,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,QAAAC,OAAM,gBAAgB;AAC/B,SAAS,mBAAmB,gBAAgB;AAC5C,SAAS,sCAAsC;;;ACA/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,YAAY;AAE9B,SAAS,kBAAkB,wBAAuC;AAClE,YAAY,SAAS;AASd,SAAS,WAAW,KAAyB;AAClD,MAAI,CAAC,IAAI,WAAW,OAAO,GAAG;AAC5B,UAAM,IAAI,MAAM,0CAA0C,KAAK,UAAU,GAAG,CAAC,EAAE;AAAA,EACjF;AACA,QAAM,OAAO,IAAI,MAAM,QAAQ,MAAM;AACrC,QAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,MAAI,UAAU,IAAI;AAChB,UAAM,IAAI,MAAM,wCAAwC,KAAK,UAAU,GAAG,CAAC,EAAE;AAAA,EAC/E;AACA,QAAM,SAAS,KAAK,MAAM,GAAG,KAAK;AAClC,QAAM,MAAM,KAAK,MAAM,QAAQ,CAAC;AAChC,MAAI,CAAC,UAAU,CAAC,KAAK;AACnB,UAAM,IAAI,MAAM,gDAAgD,KAAK,UAAU,GAAG,CAAC,EAAE;AAAA,EACvF;AACA,SAAO,EAAE,QAAQ,IAAI;AACvB;AAGO,SAAS,YAAY,KAAyB;AACnD,SAAO,QAAQ,IAAI,MAAM,IAAI,IAAI,GAAG;AACtC;AAyBA,eAAsB,eACpB,QACA,WACA,KACA,aACe;AACf,MAAI,CAAC,WAAW,SAAS,GAAG;AAC1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AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;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,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": ["
|
|
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 { validateDistributedRenderConfig } 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\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 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 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 return config;\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 /** Count of `LambdaFunctionScheduled` events seen in the history so far. */\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 case \"LambdaFunctionScheduled\":\n lambdasInvoked++;\n break;\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 if (payload && typeof payload === \"object\") {\n const obj = payload as Record<string, unknown>;\n if (typeof obj.TotalFrames === \"number\") totalFrames = obj.TotalFrames;\n if (typeof obj.FramesEncoded === \"number\") {\n // Plan and Assemble also return FramesEncoded; count framesRendered\n // only inside the RenderChunk state so we don't double-count\n // it on the Assemble pass. Keyed off the enclosing state name\n // (set by the matching StateEntered) rather than the payload's\n // `Action` field \u2014 `Action` is part of the Lambda event\n // contract and not load-bearing for state-machine identity.\n if (currentLambdaState === \"RenderChunk\") {\n framesRendered += obj.FramesEncoded;\n }\n }\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 \"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 * 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;AASd,SAAS,WAAW,KAAyB;AAClD,MAAI,CAAC,IAAI,WAAW,OAAO,GAAG;AAC5B,UAAM,IAAI,MAAM,0CAA0C,KAAK,UAAU,GAAG,CAAC,EAAE;AAAA,EACjF;AACA,QAAM,OAAO,IAAI,MAAM,QAAQ,MAAM;AACrC,QAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,MAAI,UAAU,IAAI;AAChB,UAAM,IAAI,MAAM,wCAAwC,KAAK,UAAU,GAAG,CAAC,EAAE;AAAA,EAC/E;AACA,QAAM,SAAS,KAAK,MAAM,GAAG,KAAK;AAClC,QAAM,MAAM,KAAK,MAAM,QAAQ,CAAC;AAChC,MAAI,CAAC,UAAU,CAAC,KAAK;AACnB,UAAM,IAAI,MAAM,gDAAgD,KAAK,UAAU,GAAG,CAAC,EAAE;AAAA,EACvF;AACA,SAAO,EAAE,QAAQ,IAAI;AACvB;AAGO,SAAS,YAAY,KAAyB;AACnD,SAAO,QAAQ,IAAI,MAAM,IAAI,IAAI,GAAG;AACtC;AAyBA,eAAsB,eACpB,QACA,WACA,KACA,aACe;AACf,MAAI,CAAC,WAAW,SAAS,GAAG;AAC1B,UAAM,IAAI,MAAM,wCAAwC,SAAS,EAAE;AA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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,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"]
|
|
7
7
|
}
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* The check is deliberately narrow — it covers the *shape* errors any
|
|
14
14
|
* caller could have surfaced with `tsc` if they passed a literal, plus
|
|
15
|
-
* the
|
|
16
|
-
*
|
|
15
|
+
* the `force-hdr` rejection (HDR mp4 isn't supported in distributed
|
|
16
|
+
* mode). webm was previously rejected here too; v0.7+ supports it via
|
|
17
|
+
* closed-GOP concat-copy. Anything deeper (font availability, plan
|
|
17
18
|
* size cap, GPU mode at runtime) needs the actual planner.
|
|
18
19
|
*/
|
|
19
20
|
import type { SerializableDistributedRenderConfig } from "../events.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateConfig.d.ts","sourceRoot":"","sources":["../../src/sdk/validateConfig.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"validateConfig.d.ts","sourceRoot":"","sources":["../../src/sdk/validateConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,cAAc,CAAC;AAExE,kFAAkF;AAClF,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAkB,IAAI,wBAAwB;IAC9C,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI3C;AAmBD;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,mCAAmC,GAC1C,mCAAmC,CAgHrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/aws-lambda",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.26",
|
|
4
4
|
"description": "AWS Lambda adapter for HyperFrames distributed rendering — handler, client-side SDK, and CDK construct.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"ffprobe-static": "^3.1.0",
|
|
46
46
|
"puppeteer-core": "^24.39.1",
|
|
47
47
|
"tar": "^7.4.3",
|
|
48
|
-
"@hyperframes/producer": "^0.6.
|
|
48
|
+
"@hyperframes/producer": "^0.6.26"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/aws-lambda": "^8.10.146",
|