@hyperframes/aws-lambda 0.6.36 → 0.6.37

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.
@@ -1 +1 @@
1
- {"version":3,"file":"HyperframesRenderStack.d.ts","sourceRoot":"","sources":["../../src/cdk/HyperframesRenderStack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAY,aAAa,EAAQ,MAAM,aAAa,CAAC;AAE5D,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,kEAAkE;AAClE,MAAM,WAAW,2BAA2B;IAC1C,8FAA8F;IAC9F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IAC/E,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mFAAmF;IACnF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oFAAoF;IACpF,YAAY,CAAC,EAAE,WAAW,GAAG,uBAAuB,CAAC;IACrD,kFAAkF;IAClF,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kEAAkE;IAClE,mBAAmB,CAAC,EAAE,aAAa,CAAC;CACrC;AAOD,qBAAa,sBAAuB,SAAQ,SAAS;IACnD,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,EAAE,MAAM,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MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC;IACzC,iEAAiE;IACjE,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,YAAY,CAAC;gBAE5B,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,GAAE,2BAAgC;IAmHjF;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;CAiJpC"}
package/dist/cdk/index.js CHANGED
@@ -130,17 +130,20 @@ var HyperframesRenderStack = class extends Construct {
130
130
  "BROWSER_GPU_NOT_SOFTWARE",
131
131
  "FONT_FETCH_FAILED",
132
132
  "PLAN_TOO_LARGE",
133
- "FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED"
133
+ "FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED",
134
+ "ChromeBinaryUnavailableError"
134
135
  ];
135
136
  const NON_RETRYABLE_CHUNK = [
136
137
  "FFMPEG_VERSION_MISMATCH",
137
138
  "PLAN_HASH_MISMATCH",
138
- "BROWSER_GPU_NOT_SOFTWARE"
139
+ "BROWSER_GPU_NOT_SOFTWARE",
140
+ "ChromeBinaryUnavailableError"
139
141
  ];
140
142
  const NON_RETRYABLE_ASSEMBLE = [
141
143
  "FFMPEG_VERSION_MISMATCH",
142
144
  "PLAN_HASH_MISMATCH",
143
- "FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED"
145
+ "FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED",
146
+ "ChromeBinaryUnavailableError"
144
147
  ];
145
148
  const plan = new tasks.LambdaInvoke(this, "Plan", {
146
149
  lambdaFunction: this.renderFunction,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/cdk/HyperframesRenderStack.ts"],
4
- "sourcesContent": ["/**\n * `HyperframesRenderStack` \u2014 aws-cdk-lib L2 construct that emits the same\n * topology as `examples/aws-lambda/template.yaml`.\n *\n * Adopters who embed HyperFrames inside their own CDK app can extend this\n * construct or compose alongside it; the construct exposes its `.bucket`,\n * `.renderFunction`, and `.stateMachine` properties so additional\n * resources (alarms, dashboards, SNS topics) can be wired without\n * re-deriving the ARNs from a stack export.\n *\n * `aws-cdk-lib` and `constructs` are **peerDependencies**. The package\n * still type-checks (and the snapshot test still runs) because they're\n * also `devDependencies`, but adopters who only consume the SDK side of\n * `@hyperframes/aws-lambda` don't pull the CDK tree at runtime.\n *\n * Drift from the SAM template is guarded by the snapshot test\n * (`HyperframesRenderStack.snapshot.test.ts`), which diffs the synthed\n * CloudFormation against the SAM-rendered CloudFormation modulo\n * normalisation.\n */\n\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Duration, RemovalPolicy, Size } from \"aws-cdk-lib\";\nimport * as cloudwatch from \"aws-cdk-lib/aws-cloudwatch\";\nimport * as lambda from \"aws-cdk-lib/aws-lambda\";\nimport * as logs from \"aws-cdk-lib/aws-logs\";\nimport * as s3 from \"aws-cdk-lib/aws-s3\";\nimport * as sfn from \"aws-cdk-lib/aws-stepfunctions\";\nimport * as tasks from \"aws-cdk-lib/aws-stepfunctions-tasks\";\nimport { Construct } from \"constructs\";\n\n/** Construction-time props for {@link HyperframesRenderStack}. */\nexport interface HyperframesRenderStackProps {\n /** Name prefix applied to function / state-machine / alarm names. Default `\"hyperframes\"`. */\n projectName?: string;\n /** Lambda memory in MB. Allowed: 2048..10240 in 1024 steps. Default 10240. */\n lambdaMemoryMb?: 2048 | 3072 | 4096 | 5120 | 6144 | 7168 | 8192 | 9216 | 10240;\n /** Per-invocation Lambda timeout. Default 900 (15 min, Lambda hard cap). */\n lambdaTimeoutSec?: number;\n /** Lambda reserved concurrency cap. `undefined` = unreserved (account default). */\n reservedConcurrency?: number;\n /** Which Chrome runtime was bundled into the handler ZIP. Default `\"sparticuz\"`. */\n chromeSource?: \"sparticuz\" | \"chrome-headless-shell\";\n /** Threshold for the runaway-invocations alarm. Default 1000 invocations/hour. */\n chunkInvocationAlarmThreshold?: number;\n /**\n * Absolute path to the handler ZIP produced by\n * `bun run --cwd packages/aws-lambda build:zip`. Defaults to the\n * package-relative path the build script writes to. Adopters who\n * deploy the published handler ZIP set this explicitly.\n */\n handlerZipPath?: string;\n /** S3 bucket retention policy on stack delete. Default RETAIN. */\n bucketRemovalPolicy?: RemovalPolicy;\n}\n\nconst DEFAULT_MEMORY_MB = 10240;\nconst DEFAULT_TIMEOUT_SEC = 900;\nconst DEFAULT_CHROME_SOURCE = \"sparticuz\";\nconst DEFAULT_ALARM_THRESHOLD = 1000;\n\nexport class HyperframesRenderStack extends Construct {\n /** S3 bucket for plan tarballs, chunk outputs, and final renders. */\n readonly bucket: s3.Bucket;\n /** The single Lambda function dispatching plan / renderChunk / assemble. */\n readonly renderFunction: lambda.Function;\n /** The Step Functions state machine orchestrating the render. */\n readonly stateMachine: sfn.StateMachine;\n\n constructor(scope: Construct, id: string, props: HyperframesRenderStackProps = {}) {\n super(scope, id);\n\n const projectName = props.projectName ?? \"hyperframes\";\n const memorySize = props.lambdaMemoryMb ?? DEFAULT_MEMORY_MB;\n const timeoutSec = props.lambdaTimeoutSec ?? DEFAULT_TIMEOUT_SEC;\n const chromeSource = props.chromeSource ?? DEFAULT_CHROME_SOURCE;\n const alarmThreshold = props.chunkInvocationAlarmThreshold ?? DEFAULT_ALARM_THRESHOLD;\n const handlerZipPath = props.handlerZipPath ?? defaultHandlerZipPath();\n\n this.bucket = new s3.Bucket(this, \"RenderBucket\", {\n removalPolicy: props.bucketRemovalPolicy ?? RemovalPolicy.RETAIN,\n blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,\n // `Suspended` is the cheapest mode that still satisfies KMS / replication\n // prerequisites callers can layer on later. Adopters who treat the final\n // mp4 as user-keepable can switch to `Enabled`.\n versioned: false,\n lifecycleRules: [\n {\n id: \"ExpireIntermediates\",\n enabled: true,\n prefix: \"renders/\",\n expiration: Duration.days(7),\n },\n ],\n });\n\n this.renderFunction = new lambda.Function(this, \"RenderFunction\", {\n functionName: `${projectName}-render`,\n runtime: lambda.Runtime.NODEJS_22_X,\n handler: \"handler.handler\",\n code: lambda.Code.fromAsset(handlerZipPath),\n memorySize,\n timeout: Duration.seconds(timeoutSec),\n ephemeralStorageSize: Size.gibibytes(10),\n architecture: lambda.Architecture.X86_64,\n reservedConcurrentExecutions: props.reservedConcurrency,\n tracing: lambda.Tracing.ACTIVE,\n environment: {\n NODE_OPTIONS: \"--enable-source-maps\",\n TMPDIR: \"/tmp\",\n HYPERFRAMES_LAMBDA_CHROME_SOURCE: chromeSource,\n },\n });\n\n // Scoped S3 perms only \u2014 explicitly NOT `CloudWatchLogsFullAccess`,\n // which would grant `logs:*` on `*` and overscope adopter accounts.\n // SAM's AWSLambdaBasicExecutionRole equivalent is included by the\n // default `new lambda.Function` execution role.\n this.bucket.grantReadWrite(this.renderFunction);\n\n const stateMachineLogGroup = new logs.LogGroup(this, \"RenderStateMachineLogGroup\", {\n logGroupName: `/aws/states/${projectName}-render`,\n retention: logs.RetentionDays.ONE_MONTH,\n removalPolicy: RemovalPolicy.DESTROY,\n });\n\n const definition = this.buildStateMachineDefinition();\n\n this.stateMachine = new sfn.StateMachine(this, \"RenderStateMachine\", {\n stateMachineName: `${projectName}-render`,\n stateMachineType: sfn.StateMachineType.STANDARD,\n definitionBody: sfn.DefinitionBody.fromChainable(definition),\n tracingEnabled: true,\n timeout: Duration.hours(1),\n logs: {\n destination: stateMachineLogGroup,\n level: sfn.LogLevel.ERROR,\n includeExecutionData: false,\n },\n });\n\n this.renderFunction.grantInvoke(this.stateMachine);\n\n new cloudwatch.Alarm(this, \"RenderChunkInvocationAlarm\", {\n alarmName: `${projectName}-runaway-chunk-invocations`,\n alarmDescription:\n \"Fires if RenderChunk Lambda invocations exceed the configured threshold in a 1-hour window.\",\n metric: this.renderFunction.metricInvocations({\n period: Duration.hours(1),\n statistic: cloudwatch.Stats.SUM,\n }),\n threshold: alarmThreshold,\n evaluationPeriods: 1,\n comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,\n treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,\n });\n\n new cloudwatch.Alarm(this, \"RenderFunctionErrorsAlarm\", {\n alarmName: `${projectName}-render-function-errors`,\n alarmDescription: \"Fires if the render Lambda reports any errors in a 5-minute window.\",\n metric: this.renderFunction.metricErrors({\n period: Duration.minutes(5),\n statistic: cloudwatch.Stats.SUM,\n }),\n threshold: 1,\n evaluationPeriods: 1,\n comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,\n treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,\n });\n\n new cloudwatch.Alarm(this, \"RenderStateMachineFailedAlarm\", {\n alarmName: `${projectName}-render-state-machine-failed`,\n alarmDescription: \"Fires when the render state machine reports a failed execution.\",\n metric: this.stateMachine.metricFailed({\n period: Duration.minutes(5),\n statistic: cloudwatch.Stats.SUM,\n }),\n threshold: 1,\n evaluationPeriods: 1,\n comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,\n treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,\n });\n }\n\n /**\n * Build the state-machine chain. Kept in a single method so the SAM\n * template and this construct can be diffed shape-for-shape during\n * the snapshot test.\n */\n private buildStateMachineDefinition(): sfn.IChainable {\n const NON_RETRYABLE_PLAN = [\n \"FFMPEG_VERSION_MISMATCH\",\n \"PLAN_HASH_MISMATCH\",\n \"BROWSER_GPU_NOT_SOFTWARE\",\n \"FONT_FETCH_FAILED\",\n \"PLAN_TOO_LARGE\",\n \"FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED\",\n ];\n const NON_RETRYABLE_CHUNK = [\n \"FFMPEG_VERSION_MISMATCH\",\n \"PLAN_HASH_MISMATCH\",\n \"BROWSER_GPU_NOT_SOFTWARE\",\n ];\n const NON_RETRYABLE_ASSEMBLE = [\n \"FFMPEG_VERSION_MISMATCH\",\n \"PLAN_HASH_MISMATCH\",\n \"FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED\",\n ];\n\n const plan = new tasks.LambdaInvoke(this, \"Plan\", {\n lambdaFunction: this.renderFunction,\n payload: sfn.TaskInput.fromObject({\n Action: \"plan\",\n \"ProjectS3Uri.$\": \"$.ProjectS3Uri\",\n \"PlanOutputS3Prefix.$\": \"$.PlanOutputS3Prefix\",\n \"Config.$\": \"$.Config\",\n }),\n resultSelector: {\n \"PlanS3Uri.$\": \"$.Payload.PlanS3Uri\",\n \"PlanHash.$\": \"$.Payload.PlanHash\",\n \"ChunkCount.$\": \"$.Payload.ChunkCount\",\n \"Format.$\": \"$.Payload.Format\",\n \"HasAudio.$\": \"$.Payload.HasAudio\",\n \"AudioS3Uri.$\": \"$.Payload.AudioS3Uri\",\n },\n resultPath: \"$.Plan\",\n });\n plan.addRetry({\n errors: NON_RETRYABLE_PLAN,\n maxAttempts: 0,\n });\n plan.addRetry({\n errors: [\"States.ALL\"],\n interval: Duration.seconds(2),\n maxAttempts: 4,\n backoffRate: 2,\n maxDelay: Duration.seconds(60),\n });\n\n const buildChunkList = new sfn.Pass(this, \"BuildChunkList\", {\n parameters: {\n \"ChunkIndexes.$\": \"States.ArrayRange(0, States.MathAdd($.Plan.ChunkCount, -1), 1)\",\n },\n resultPath: \"$.Iterator\",\n });\n\n const planProducedZero = new sfn.Fail(this, \"PlanProducedZeroChunks\", {\n error: \"PLAN_TOO_LARGE\",\n cause: \"Plan returned ChunkCount=0 \u2014 non-retryable producer-side invariant violation.\",\n });\n\n const renderChunkTask = new tasks.LambdaInvoke(this, \"RenderChunk\", {\n lambdaFunction: this.renderFunction,\n payload: sfn.TaskInput.fromObject({\n Action: \"renderChunk\",\n \"ChunkIndex.$\": \"$.ChunkIndex\",\n \"PlanS3Uri.$\": \"$.PlanS3Uri\",\n \"PlanHash.$\": \"$.PlanHash\",\n \"ChunkOutputS3Prefix.$\": \"$.ChunkOutputS3Prefix\",\n \"Format.$\": \"$.Format\",\n }),\n resultSelector: {\n \"ChunkS3Uri.$\": \"$.Payload.ChunkS3Uri\",\n \"ChunkIndex.$\": \"$.Payload.ChunkIndex\",\n \"Sha256.$\": \"$.Payload.Sha256\",\n },\n });\n renderChunkTask.addRetry({\n errors: NON_RETRYABLE_CHUNK,\n maxAttempts: 0,\n });\n renderChunkTask.addRetry({\n errors: [\"States.ALL\"],\n interval: Duration.seconds(2),\n maxAttempts: 4,\n backoffRate: 2,\n maxDelay: Duration.seconds(60),\n });\n\n const renderChunks = new sfn.Map(this, \"RenderChunks\", {\n itemsPath: \"$.Iterator.ChunkIndexes\",\n itemSelector: {\n \"ChunkIndex.$\": \"$$.Map.Item.Value\",\n \"PlanS3Uri.$\": \"$.Plan.PlanS3Uri\",\n \"PlanHash.$\": \"$.Plan.PlanHash\",\n \"ChunkOutputS3Prefix.$\": \"$.PlanOutputS3Prefix\",\n \"Format.$\": \"$.Plan.Format\",\n },\n maxConcurrencyPath: \"$.Plan.ChunkCount\",\n resultPath: \"$.Chunks\",\n });\n renderChunks.itemProcessor(renderChunkTask);\n\n const assemble = new tasks.LambdaInvoke(this, \"Assemble\", {\n lambdaFunction: this.renderFunction,\n payload: sfn.TaskInput.fromObject({\n Action: \"assemble\",\n \"PlanS3Uri.$\": \"$.Plan.PlanS3Uri\",\n \"ChunkS3Uris.$\": \"$.Chunks[*].ChunkS3Uri\",\n \"AudioS3Uri.$\": \"$.Plan.AudioS3Uri\",\n \"OutputS3Uri.$\": \"$.OutputS3Uri\",\n \"Format.$\": \"$.Plan.Format\",\n }),\n resultSelector: {\n \"OutputS3Uri.$\": \"$.Payload.OutputS3Uri\",\n \"FramesEncoded.$\": \"$.Payload.FramesEncoded\",\n \"FileSize.$\": \"$.Payload.FileSize\",\n },\n resultPath: \"$.Output\",\n });\n assemble.addRetry({\n errors: NON_RETRYABLE_ASSEMBLE,\n maxAttempts: 0,\n });\n assemble.addRetry({\n errors: [\"States.ALL\"],\n interval: Duration.seconds(2),\n maxAttempts: 4,\n backoffRate: 2,\n maxDelay: Duration.seconds(60),\n });\n\n const assertChunkCount = new sfn.Choice(this, \"AssertChunkCount\")\n .when(sfn.Condition.numberGreaterThan(\"$.Plan.ChunkCount\", 0), renderChunks.next(assemble))\n .otherwise(planProducedZero);\n\n return plan.next(buildChunkList).next(assertChunkCount);\n }\n}\n\n/**\n * Default location of the handler ZIP relative to this source file. Two\n * parents up = `packages/aws-lambda/`; the build script writes the ZIP\n * to `packages/aws-lambda/dist/handler.zip`. The package is published with\n * `main: \"./src/index.ts\"`, so this path resolves correctly both in the\n * source tree (during `bun test` / local CDK synth) and in a consumer's\n * `node_modules/@hyperframes/aws-lambda/` install.\n */\nfunction defaultHandlerZipPath(): string {\n const here = dirname(fileURLToPath(import.meta.url));\n return resolve(here, \"..\", \"..\", \"dist\", \"handler.zip\");\n}\n"],
5
- "mappings": ";AAqBA,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAC9B,SAAS,UAAU,eAAe,YAAY;AAC9C,YAAY,gBAAgB;AAC5B,YAAY,YAAY;AACxB,YAAY,UAAU;AACtB,YAAY,QAAQ;AACpB,YAAY,SAAS;AACrB,YAAY,WAAW;AACvB,SAAS,iBAAiB;AA2B1B,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAC5B,IAAM,wBAAwB;AAC9B,IAAM,0BAA0B;AAEzB,IAAM,yBAAN,cAAqC,UAAU;AAAA;AAAA,EAE3C;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,OAAkB,IAAY,QAAqC,CAAC,GAAG;AACjF,UAAM,OAAO,EAAE;AAEf,UAAM,cAAc,MAAM,eAAe;AACzC,UAAM,aAAa,MAAM,kBAAkB;AAC3C,UAAM,aAAa,MAAM,oBAAoB;AAC7C,UAAM,eAAe,MAAM,gBAAgB;AAC3C,UAAM,iBAAiB,MAAM,iCAAiC;AAC9D,UAAM,iBAAiB,MAAM,kBAAkB,sBAAsB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GAAG,aAAa,KAAK,QAAQ,CAAC,EACzF,UAAU,gBAAgB;AAE7B,WAAO,KAAK,KAAK,cAAc,EAAE,KAAK,gBAAgB;AAAA,EACxD;AACF;AAUA,SAAS,wBAAgC;AACvC,QAAM,OAAO,QAAQ,cAAc,YAAY,GAAG,CAAC;AACnD,SAAO,QAAQ,MAAM,MAAM,MAAM,QAAQ,aAAa;AACxD;",
4
+ "sourcesContent": ["/**\n * `HyperframesRenderStack` \u2014 aws-cdk-lib L2 construct that emits the same\n * topology as `examples/aws-lambda/template.yaml`.\n *\n * Adopters who embed HyperFrames inside their own CDK app can extend this\n * construct or compose alongside it; the construct exposes its `.bucket`,\n * `.renderFunction`, and `.stateMachine` properties so additional\n * resources (alarms, dashboards, SNS topics) can be wired without\n * re-deriving the ARNs from a stack export.\n *\n * `aws-cdk-lib` and `constructs` are **peerDependencies**. The package\n * still type-checks (and the snapshot test still runs) because they're\n * also `devDependencies`, but adopters who only consume the SDK side of\n * `@hyperframes/aws-lambda` don't pull the CDK tree at runtime.\n *\n * Drift from the SAM template is guarded by the snapshot test\n * (`HyperframesRenderStack.snapshot.test.ts`), which diffs the synthed\n * CloudFormation against the SAM-rendered CloudFormation modulo\n * normalisation.\n */\n\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Duration, RemovalPolicy, Size } from \"aws-cdk-lib\";\nimport * as cloudwatch from \"aws-cdk-lib/aws-cloudwatch\";\nimport * as lambda from \"aws-cdk-lib/aws-lambda\";\nimport * as logs from \"aws-cdk-lib/aws-logs\";\nimport * as s3 from \"aws-cdk-lib/aws-s3\";\nimport * as sfn from \"aws-cdk-lib/aws-stepfunctions\";\nimport * as tasks from \"aws-cdk-lib/aws-stepfunctions-tasks\";\nimport { Construct } from \"constructs\";\n\n/** Construction-time props for {@link HyperframesRenderStack}. */\nexport interface HyperframesRenderStackProps {\n /** Name prefix applied to function / state-machine / alarm names. Default `\"hyperframes\"`. */\n projectName?: string;\n /** Lambda memory in MB. Allowed: 2048..10240 in 1024 steps. Default 10240. */\n lambdaMemoryMb?: 2048 | 3072 | 4096 | 5120 | 6144 | 7168 | 8192 | 9216 | 10240;\n /** Per-invocation Lambda timeout. Default 900 (15 min, Lambda hard cap). */\n lambdaTimeoutSec?: number;\n /** Lambda reserved concurrency cap. `undefined` = unreserved (account default). */\n reservedConcurrency?: number;\n /** Which Chrome runtime was bundled into the handler ZIP. Default `\"sparticuz\"`. */\n chromeSource?: \"sparticuz\" | \"chrome-headless-shell\";\n /** Threshold for the runaway-invocations alarm. Default 1000 invocations/hour. */\n chunkInvocationAlarmThreshold?: number;\n /**\n * Absolute path to the handler ZIP produced by\n * `bun run --cwd packages/aws-lambda build:zip`. Defaults to the\n * package-relative path the build script writes to. Adopters who\n * deploy the published handler ZIP set this explicitly.\n */\n handlerZipPath?: string;\n /** S3 bucket retention policy on stack delete. Default RETAIN. */\n bucketRemovalPolicy?: RemovalPolicy;\n}\n\nconst DEFAULT_MEMORY_MB = 10240;\nconst DEFAULT_TIMEOUT_SEC = 900;\nconst DEFAULT_CHROME_SOURCE = \"sparticuz\";\nconst DEFAULT_ALARM_THRESHOLD = 1000;\n\nexport class HyperframesRenderStack extends Construct {\n /** S3 bucket for plan tarballs, chunk outputs, and final renders. */\n readonly bucket: s3.Bucket;\n /** The single Lambda function dispatching plan / renderChunk / assemble. */\n readonly renderFunction: lambda.Function;\n /** The Step Functions state machine orchestrating the render. */\n readonly stateMachine: sfn.StateMachine;\n\n constructor(scope: Construct, id: string, props: HyperframesRenderStackProps = {}) {\n super(scope, id);\n\n const projectName = props.projectName ?? \"hyperframes\";\n const memorySize = props.lambdaMemoryMb ?? DEFAULT_MEMORY_MB;\n const timeoutSec = props.lambdaTimeoutSec ?? DEFAULT_TIMEOUT_SEC;\n const chromeSource = props.chromeSource ?? DEFAULT_CHROME_SOURCE;\n const alarmThreshold = props.chunkInvocationAlarmThreshold ?? DEFAULT_ALARM_THRESHOLD;\n const handlerZipPath = props.handlerZipPath ?? defaultHandlerZipPath();\n\n this.bucket = new s3.Bucket(this, \"RenderBucket\", {\n removalPolicy: props.bucketRemovalPolicy ?? RemovalPolicy.RETAIN,\n blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,\n // `Suspended` is the cheapest mode that still satisfies KMS / replication\n // prerequisites callers can layer on later. Adopters who treat the final\n // mp4 as user-keepable can switch to `Enabled`.\n versioned: false,\n lifecycleRules: [\n {\n id: \"ExpireIntermediates\",\n enabled: true,\n prefix: \"renders/\",\n expiration: Duration.days(7),\n },\n ],\n });\n\n this.renderFunction = new lambda.Function(this, \"RenderFunction\", {\n functionName: `${projectName}-render`,\n runtime: lambda.Runtime.NODEJS_22_X,\n handler: \"handler.handler\",\n code: lambda.Code.fromAsset(handlerZipPath),\n memorySize,\n timeout: Duration.seconds(timeoutSec),\n ephemeralStorageSize: Size.gibibytes(10),\n architecture: lambda.Architecture.X86_64,\n reservedConcurrentExecutions: props.reservedConcurrency,\n tracing: lambda.Tracing.ACTIVE,\n environment: {\n NODE_OPTIONS: \"--enable-source-maps\",\n TMPDIR: \"/tmp\",\n HYPERFRAMES_LAMBDA_CHROME_SOURCE: chromeSource,\n },\n });\n\n // Scoped S3 perms only \u2014 explicitly NOT `CloudWatchLogsFullAccess`,\n // which would grant `logs:*` on `*` and overscope adopter accounts.\n // SAM's AWSLambdaBasicExecutionRole equivalent is included by the\n // default `new lambda.Function` execution role.\n this.bucket.grantReadWrite(this.renderFunction);\n\n const stateMachineLogGroup = new logs.LogGroup(this, \"RenderStateMachineLogGroup\", {\n logGroupName: `/aws/states/${projectName}-render`,\n retention: logs.RetentionDays.ONE_MONTH,\n removalPolicy: RemovalPolicy.DESTROY,\n });\n\n const definition = this.buildStateMachineDefinition();\n\n this.stateMachine = new sfn.StateMachine(this, \"RenderStateMachine\", {\n stateMachineName: `${projectName}-render`,\n stateMachineType: sfn.StateMachineType.STANDARD,\n definitionBody: sfn.DefinitionBody.fromChainable(definition),\n tracingEnabled: true,\n timeout: Duration.hours(1),\n logs: {\n destination: stateMachineLogGroup,\n level: sfn.LogLevel.ERROR,\n includeExecutionData: false,\n },\n });\n\n this.renderFunction.grantInvoke(this.stateMachine);\n\n new cloudwatch.Alarm(this, \"RenderChunkInvocationAlarm\", {\n alarmName: `${projectName}-runaway-chunk-invocations`,\n alarmDescription:\n \"Fires if RenderChunk Lambda invocations exceed the configured threshold in a 1-hour window.\",\n metric: this.renderFunction.metricInvocations({\n period: Duration.hours(1),\n statistic: cloudwatch.Stats.SUM,\n }),\n threshold: alarmThreshold,\n evaluationPeriods: 1,\n comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,\n treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,\n });\n\n new cloudwatch.Alarm(this, \"RenderFunctionErrorsAlarm\", {\n alarmName: `${projectName}-render-function-errors`,\n alarmDescription: \"Fires if the render Lambda reports any errors in a 5-minute window.\",\n metric: this.renderFunction.metricErrors({\n period: Duration.minutes(5),\n statistic: cloudwatch.Stats.SUM,\n }),\n threshold: 1,\n evaluationPeriods: 1,\n comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,\n treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,\n });\n\n new cloudwatch.Alarm(this, \"RenderStateMachineFailedAlarm\", {\n alarmName: `${projectName}-render-state-machine-failed`,\n alarmDescription: \"Fires when the render state machine reports a failed execution.\",\n metric: this.stateMachine.metricFailed({\n period: Duration.minutes(5),\n statistic: cloudwatch.Stats.SUM,\n }),\n threshold: 1,\n evaluationPeriods: 1,\n comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,\n treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,\n });\n }\n\n /**\n * Build the state-machine chain. Kept in a single method so the SAM\n * template and this construct can be diffed shape-for-shape during\n * the snapshot test.\n */\n private buildStateMachineDefinition(): sfn.IChainable {\n // `ChromeBinaryUnavailableError` is non-retryable: a wedged warm\n // instance keeps returning the same falsy executablePath until the\n // env recycles, so retries just burn the 4\u00D7 15-min budget.\n const NON_RETRYABLE_PLAN = [\n \"FFMPEG_VERSION_MISMATCH\",\n \"PLAN_HASH_MISMATCH\",\n \"BROWSER_GPU_NOT_SOFTWARE\",\n \"FONT_FETCH_FAILED\",\n \"PLAN_TOO_LARGE\",\n \"FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED\",\n \"ChromeBinaryUnavailableError\",\n ];\n const NON_RETRYABLE_CHUNK = [\n \"FFMPEG_VERSION_MISMATCH\",\n \"PLAN_HASH_MISMATCH\",\n \"BROWSER_GPU_NOT_SOFTWARE\",\n \"ChromeBinaryUnavailableError\",\n ];\n const NON_RETRYABLE_ASSEMBLE = [\n \"FFMPEG_VERSION_MISMATCH\",\n \"PLAN_HASH_MISMATCH\",\n \"FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED\",\n \"ChromeBinaryUnavailableError\",\n ];\n\n const plan = new tasks.LambdaInvoke(this, \"Plan\", {\n lambdaFunction: this.renderFunction,\n payload: sfn.TaskInput.fromObject({\n Action: \"plan\",\n \"ProjectS3Uri.$\": \"$.ProjectS3Uri\",\n \"PlanOutputS3Prefix.$\": \"$.PlanOutputS3Prefix\",\n \"Config.$\": \"$.Config\",\n }),\n resultSelector: {\n \"PlanS3Uri.$\": \"$.Payload.PlanS3Uri\",\n \"PlanHash.$\": \"$.Payload.PlanHash\",\n \"ChunkCount.$\": \"$.Payload.ChunkCount\",\n \"Format.$\": \"$.Payload.Format\",\n \"HasAudio.$\": \"$.Payload.HasAudio\",\n \"AudioS3Uri.$\": \"$.Payload.AudioS3Uri\",\n },\n resultPath: \"$.Plan\",\n });\n plan.addRetry({\n errors: NON_RETRYABLE_PLAN,\n maxAttempts: 0,\n });\n plan.addRetry({\n errors: [\"States.ALL\"],\n interval: Duration.seconds(2),\n maxAttempts: 4,\n backoffRate: 2,\n maxDelay: Duration.seconds(60),\n });\n\n const buildChunkList = new sfn.Pass(this, \"BuildChunkList\", {\n parameters: {\n \"ChunkIndexes.$\": \"States.ArrayRange(0, States.MathAdd($.Plan.ChunkCount, -1), 1)\",\n },\n resultPath: \"$.Iterator\",\n });\n\n const planProducedZero = new sfn.Fail(this, \"PlanProducedZeroChunks\", {\n error: \"PLAN_TOO_LARGE\",\n cause: \"Plan returned ChunkCount=0 \u2014 non-retryable producer-side invariant violation.\",\n });\n\n const renderChunkTask = new tasks.LambdaInvoke(this, \"RenderChunk\", {\n lambdaFunction: this.renderFunction,\n payload: sfn.TaskInput.fromObject({\n Action: \"renderChunk\",\n \"ChunkIndex.$\": \"$.ChunkIndex\",\n \"PlanS3Uri.$\": \"$.PlanS3Uri\",\n \"PlanHash.$\": \"$.PlanHash\",\n \"ChunkOutputS3Prefix.$\": \"$.ChunkOutputS3Prefix\",\n \"Format.$\": \"$.Format\",\n }),\n resultSelector: {\n \"ChunkS3Uri.$\": \"$.Payload.ChunkS3Uri\",\n \"ChunkIndex.$\": \"$.Payload.ChunkIndex\",\n \"Sha256.$\": \"$.Payload.Sha256\",\n },\n });\n renderChunkTask.addRetry({\n errors: NON_RETRYABLE_CHUNK,\n maxAttempts: 0,\n });\n renderChunkTask.addRetry({\n errors: [\"States.ALL\"],\n interval: Duration.seconds(2),\n maxAttempts: 4,\n backoffRate: 2,\n maxDelay: Duration.seconds(60),\n });\n\n const renderChunks = new sfn.Map(this, \"RenderChunks\", {\n itemsPath: \"$.Iterator.ChunkIndexes\",\n itemSelector: {\n \"ChunkIndex.$\": \"$$.Map.Item.Value\",\n \"PlanS3Uri.$\": \"$.Plan.PlanS3Uri\",\n \"PlanHash.$\": \"$.Plan.PlanHash\",\n \"ChunkOutputS3Prefix.$\": \"$.PlanOutputS3Prefix\",\n \"Format.$\": \"$.Plan.Format\",\n },\n maxConcurrencyPath: \"$.Plan.ChunkCount\",\n resultPath: \"$.Chunks\",\n });\n renderChunks.itemProcessor(renderChunkTask);\n\n const assemble = new tasks.LambdaInvoke(this, \"Assemble\", {\n lambdaFunction: this.renderFunction,\n payload: sfn.TaskInput.fromObject({\n Action: \"assemble\",\n \"PlanS3Uri.$\": \"$.Plan.PlanS3Uri\",\n \"ChunkS3Uris.$\": \"$.Chunks[*].ChunkS3Uri\",\n \"AudioS3Uri.$\": \"$.Plan.AudioS3Uri\",\n \"OutputS3Uri.$\": \"$.OutputS3Uri\",\n \"Format.$\": \"$.Plan.Format\",\n }),\n resultSelector: {\n \"OutputS3Uri.$\": \"$.Payload.OutputS3Uri\",\n \"FramesEncoded.$\": \"$.Payload.FramesEncoded\",\n \"FileSize.$\": \"$.Payload.FileSize\",\n },\n resultPath: \"$.Output\",\n });\n assemble.addRetry({\n errors: NON_RETRYABLE_ASSEMBLE,\n maxAttempts: 0,\n });\n assemble.addRetry({\n errors: [\"States.ALL\"],\n interval: Duration.seconds(2),\n maxAttempts: 4,\n backoffRate: 2,\n maxDelay: Duration.seconds(60),\n });\n\n const assertChunkCount = new sfn.Choice(this, \"AssertChunkCount\")\n .when(sfn.Condition.numberGreaterThan(\"$.Plan.ChunkCount\", 0), renderChunks.next(assemble))\n .otherwise(planProducedZero);\n\n return plan.next(buildChunkList).next(assertChunkCount);\n }\n}\n\n/**\n * Default location of the handler ZIP relative to this source file. Two\n * parents up = `packages/aws-lambda/`; the build script writes the ZIP\n * to `packages/aws-lambda/dist/handler.zip`. The package is published with\n * `main: \"./src/index.ts\"`, so this path resolves correctly both in the\n * source tree (during `bun test` / local CDK synth) and in a consumer's\n * `node_modules/@hyperframes/aws-lambda/` install.\n */\nfunction defaultHandlerZipPath(): string {\n const here = dirname(fileURLToPath(import.meta.url));\n return resolve(here, \"..\", \"..\", \"dist\", \"handler.zip\");\n}\n"],
5
+ "mappings": ";AAqBA,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAC9B,SAAS,UAAU,eAAe,YAAY;AAC9C,YAAY,gBAAgB;AAC5B,YAAY,YAAY;AACxB,YAAY,UAAU;AACtB,YAAY,QAAQ;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A,QACf,iBAAiB;AAAA,QACjB,gBAAgB;AAAA,QAChB,iBAAiB;AAAA,QACjB,YAAY;AAAA,MACd,CAAC;AAAA,MACD,gBAAgB;AAAA,QACd,iBAAiB;AAAA,QACjB,mBAAmB;AAAA,QACnB,cAAc;AAAA,MAChB;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AACD,aAAS,SAAS;AAAA,MAChB,QAAQ;AAAA,MACR,aAAa;AAAA,IACf,CAAC;AACD,aAAS,SAAS;AAAA,MAChB,QAAQ,CAAC,YAAY;AAAA,MACrB,UAAU,SAAS,QAAQ,CAAC;AAAA,MAC5B,aAAa;AAAA,MACb,aAAa;AAAA,MACb,UAAU,SAAS,QAAQ,EAAE;AAAA,IAC/B,CAAC;AAED,UAAM,mBAAmB,IAAQ,WAAO,MAAM,kBAAkB,EAC7D,KAAS,cAAU,kBAAkB,qBAAqB,CAAC,GAAG,aAAa,KAAK,QAAQ,CAAC,EACzF,UAAU,gBAAgB;AAE7B,WAAO,KAAK,KAAK,cAAc,EAAE,KAAK,gBAAgB;AAAA,EACxD;AACF;AAUA,SAAS,wBAAgC;AACvC,QAAM,OAAO,QAAQ,cAAc,YAAY,GAAG,CAAC;AACnD,SAAO,QAAQ,MAAM,MAAM,MAAM,QAAQ,aAAa;AACxD;",
6
6
  "names": []
7
7
  }
@@ -33,6 +33,17 @@
33
33
  */
34
34
  /** Discriminator for the two supported Chrome sources. */
35
35
  export type ChromeSource = "sparticuz" | "chrome-headless-shell";
36
+ /**
37
+ * Thrown when the Chrome binary resolver can't produce a usable path.
38
+ * The class name is the SFN `Retry: { ErrorEquals: [...] }` discriminator —
39
+ * see {@link HyperframesRenderStack}'s NON_RETRYABLE_* lists.
40
+ */
41
+ export declare class ChromeBinaryUnavailableError extends Error {
42
+ readonly name = "ChromeBinaryUnavailableError";
43
+ readonly source: ChromeSource;
44
+ readonly resolvedPath: string | null;
45
+ constructor(source: ChromeSource, resolvedPath: string | null, hint: string);
46
+ }
36
47
  /**
37
48
  * Read which Chrome source the bundled ZIP was built against. Defaults to
38
49
  * `"sparticuz"` so a fresh build with no env override picks the primary
@@ -1 +1 @@
1
- {"version":3,"file":"chromium.d.ts","sourceRoot":"","sources":["../src/chromium.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAIH,0DAA0D;AAC1D,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,uBAAuB,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAIlD;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,MAAM,CAAC,CAmBnE;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAI3D;AAED;;;;;;GAMG;AACH,UAAU,uBAAuB;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACnC;AAcD,uEAAuE;AACvE,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,uBAAuB,GAAG,IAAI,GAAG,IAAI,CAEvF"}
1
+ {"version":3,"file":"chromium.d.ts","sourceRoot":"","sources":["../src/chromium.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAIH,0DAA0D;AAC1D,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,uBAAuB,CAAC;AAEjE;;;;GAIG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IAKrD,SAAkB,IAAI,kCAAkC;IACxD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;gBACzB,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM;CAK5E;AAUD;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAIlD;AAED;;;;;;;;;;;GAWG;AAEH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,MAAM,CAAC,CAoCnE;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAI3D;AAED;;;;;;GAMG;AACH,UAAU,uBAAuB;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACnC;AAcD,uEAAuE;AACvE,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,uBAAuB,GAAG,IAAI,GAAG,IAAI,CAEvF"}
package/dist/handler.js CHANGED
@@ -11,6 +11,21 @@ import {
11
11
 
12
12
  // src/chromium.ts
13
13
  import { existsSync } from "node:fs";
14
+ var ChromeBinaryUnavailableError = class extends Error {
15
+ // Lambda's runtime serializes the error envelope's `errorType` from
16
+ // `err.name`; this class-field override sets it across the structured
17
+ // clone. Read indirectly; fallow can't follow.
18
+ // fallow-ignore-next-line unused-class-member
19
+ name = "ChromeBinaryUnavailableError";
20
+ source;
21
+ resolvedPath;
22
+ constructor(source, resolvedPath, hint) {
23
+ super(`[chromium] Chrome binary unavailable (source=${source}): ${hint}`);
24
+ this.source = source;
25
+ this.resolvedPath = resolvedPath;
26
+ }
27
+ };
28
+ var SPARTICUZ_WEDGE_HINT = "@sparticuz/chromium.executablePath() returned a falsy value or a path that doesn't exist on disk. This typically happens after a chunk hits `Sandbox.Timedout` mid-extraction and leaves /tmp in a wedged state \u2014 subsequent invocations land on the same warm instance and never re-extract. Recycle the function (e.g. `aws lambda update-function-configuration ... --environment ...` with a bumped marker var, or redeploy via `hyperframes lambda deploy --skip-build`) to force fresh execution environments. Tracking: investigate the upstream wedge so this auto-recovers.";
14
29
  function resolveChromeSource() {
15
30
  const raw = process.env.HYPERFRAMES_LAMBDA_CHROME_SOURCE?.toLowerCase();
16
31
  if (raw === "chrome-headless-shell" || raw === "shell") return "chrome-headless-shell";
@@ -20,17 +35,28 @@ async function resolveChromeExecutablePath() {
20
35
  const source = resolveChromeSource();
21
36
  if (source === "sparticuz") {
22
37
  const mod = await loadSparticuzChromium();
23
- return mod.executablePath();
38
+ const path = await mod.executablePath();
39
+ if (!path || typeof path !== "string") {
40
+ throw new ChromeBinaryUnavailableError(source, null, SPARTICUZ_WEDGE_HINT);
41
+ }
42
+ if (!existsSync(path)) {
43
+ throw new ChromeBinaryUnavailableError(source, path, SPARTICUZ_WEDGE_HINT);
44
+ }
45
+ return path;
24
46
  }
25
47
  const explicit = process.env.HYPERFRAMES_LAMBDA_CHROME_PATH;
26
48
  if (!explicit) {
27
- throw new Error(
28
- "[chromium] HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary."
49
+ throw new ChromeBinaryUnavailableError(
50
+ source,
51
+ null,
52
+ "HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary."
29
53
  );
30
54
  }
31
55
  if (!existsSync(explicit)) {
32
- throw new Error(
33
- `[chromium] HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist`
56
+ throw new ChromeBinaryUnavailableError(
57
+ source,
58
+ explicit,
59
+ `HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist on disk.`
34
60
  );
35
61
  }
36
62
  return explicit;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/handler.ts", "../src/chromium.ts", "../src/formatExtension.ts", "../src/s3Transport.ts"],
4
- "sourcesContent": ["/**\n * AWS Lambda handler for HyperFrames distributed rendering.\n *\n * One Lambda function, three roles. Step Functions dispatches by setting\n * `event.Action`; the handler unwraps Map-state envelopes, primes the\n * Lambda environment (Chrome path, ffmpeg path, tmpdir), and forwards to\n * the matching OSS primitive from `@hyperframes/producer/distributed`.\n *\n * Everything heavy \u2014 capture, encode, audio mix \u2014 happens inside the OSS\n * primitives. The handler is thin glue: parse event \u2192 S3 download \u2192 call\n * primitive \u2192 S3 upload \u2192 return small JSON result.\n */\n\nimport { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { basename, join } from \"node:path\";\nimport { S3Client } from \"@aws-sdk/client-s3\";\nimport {\n assemble,\n type AssembleResult,\n type ChunkResult,\n type DistributedRenderConfig,\n plan,\n type PlanResult,\n renderChunk,\n} from \"@hyperframes/producer/distributed\";\nimport { resolveChromeExecutablePath } from \"./chromium.js\";\nimport { type DistributedFormat, formatExtension } from \"./formatExtension.js\";\nimport type {\n AssembleEvent,\n AssembleLambdaResult,\n LambdaAction,\n LambdaEvent,\n LambdaResult,\n PlanEvent,\n PlanLambdaResult,\n RenderChunkEvent,\n RenderChunkLambdaResult,\n} from \"./events.js\";\nimport {\n downloadS3ObjectToFile,\n parseS3Uri,\n tarDirectory,\n untarDirectory,\n uploadFileToS3,\n} from \"./s3Transport.js\";\n\n/**\n * Lazily-constructed S3 client. Cached at module scope so warm Lambda\n * containers reuse the underlying HTTP keep-alive pool across invocations.\n */\nlet cachedS3Client: S3Client | null = null;\nfunction getS3Client(): S3Client {\n if (cachedS3Client) return cachedS3Client;\n cachedS3Client = new S3Client({});\n return cachedS3Client;\n}\n\n/**\n * Optional injection points used by the handler's unit tests. Production\n * callers leave these unset; the real OSS primitives are used. Tests\n * inject `s3` and `primitives` directly rather than mutating module\n * state \u2014 the dependency-injection seam is sufficient and avoids a\n * second leak point for cross-test contamination.\n */\nexport interface HandlerDeps {\n s3?: S3Client;\n primitives?: {\n plan: typeof plan;\n renderChunk: typeof renderChunk;\n assemble: typeof assemble;\n };\n /** Override the per-invocation `/tmp` workdir root (defaults to Lambda's `/tmp`). */\n tmpRoot?: string;\n /** Skip Chrome resolution (used by handler dispatch tests that mock renderChunk). */\n skipChromeResolution?: boolean;\n}\n\n/**\n * Lambda entry. Step Functions sometimes wraps the event in\n * `{ Payload: ... }` or `{ Input: ... }` depending on the state machine\n * shape; unwrap until we hit a discriminated event.\n */\nexport async function handler(event: LambdaEvent, deps?: HandlerDeps): Promise<LambdaResult> {\n const unwrapped = unwrapEvent(event);\n primeRuntimeEnv();\n // Single structured boot log line \u2014 CloudWatch Logs Insights queries\n // key off `event=handler_start` to grep for a specific Action / S3 URI\n // when triaging without attaching a debugger.\n logEvent({ event: \"handler_start\", action: unwrapped.Action, input: summarizeEvent(unwrapped) });\n try {\n switch (unwrapped.Action) {\n case \"plan\":\n return await handlePlan(unwrapped, deps);\n case \"renderChunk\":\n return await handleRenderChunk(unwrapped, deps);\n case \"assemble\":\n return await handleAssemble(unwrapped, deps);\n default: {\n // Compile-time exhaustiveness: a new LambdaAction member trips\n // the `never` assignment before the runtime error is reachable.\n const _exhaustive: never = unwrapped;\n throw new Error(\n `[handler] unknown Action: ${JSON.stringify(\n (_exhaustive as { Action?: string }).Action,\n )}. Expected one of \"plan\", \"renderChunk\", \"assemble\".`,\n );\n }\n }\n } catch (err) {\n // Log before re-throwing so CloudWatch captures the structured\n // error context alongside Lambda's default stack trace. Otherwise\n // ops only sees the trace and has to correlate with execution\n // history to recover the action + input.\n logEvent({\n event: \"handler_error\",\n action: unwrapped.Action,\n message: err instanceof Error ? err.message : String(err),\n name: err instanceof Error ? err.name : undefined,\n });\n throw err;\n }\n}\n\n/**\n * Walk through Step Functions' Map-state and Task-state envelopes until\n * the discriminated event is found.\n */\n// Step Functions wraps at most `{Payload: {Input: ...}}` in our state\n// machine; 4 levels is 2\u00D7 headroom for unusual Map / Wait state\n// configurations and prevents infinite loops on malformed input.\nconst MAX_ENVELOPE_DEPTH = 4;\n\nexport function unwrapEvent(event: LambdaEvent): PlanEvent | RenderChunkEvent | AssembleEvent {\n let cursor: LambdaEvent = event;\n for (let i = 0; i < MAX_ENVELOPE_DEPTH; i++) {\n if (cursor && typeof cursor === \"object\") {\n const obj = cursor as Record<string, unknown>;\n if (typeof obj.Action === \"string\" && isLambdaAction(obj.Action)) {\n return cursor as PlanEvent | RenderChunkEvent | AssembleEvent;\n }\n if (\"Payload\" in obj) {\n cursor = obj.Payload as LambdaEvent;\n continue;\n }\n if (\"Input\" in obj) {\n cursor = obj.Input as LambdaEvent;\n continue;\n }\n }\n break;\n }\n throw new Error(\n `[handler] event has no recognised Action; unwrapped ${MAX_ENVELOPE_DEPTH} levels of Payload/Input without finding one.`,\n );\n}\n\nfunction isLambdaAction(value: string): value is LambdaAction {\n return value === \"plan\" || value === \"renderChunk\" || value === \"assemble\";\n}\n\n/**\n * Emit a single JSON line to stdout. CloudWatch ingests each line as a\n * structured event; Logs Insights queries can `filter event=\"...\"` and\n * project specific fields. We write to stdout (not stderr) because\n * Lambda's default destination for both is the same log group, and\n * Logs Insights' INFO/ERROR level parser keys off the JSON `level`\n * field, not the stream.\n */\nfunction logEvent(payload: Record<string, unknown>): void {\n console.log(JSON.stringify(payload));\n}\n\n/**\n * Compact, non-PII summary of a Lambda event for logging. The full\n * event payload can include the entire project config; we only emit\n * the routable fields (S3 URIs, chunk index, format) needed to triage\n * a failure from CloudWatch.\n */\nfunction summarizeEvent(\n event: PlanEvent | RenderChunkEvent | AssembleEvent,\n): Record<string, unknown> {\n switch (event.Action) {\n case \"plan\":\n return {\n projectS3Uri: event.ProjectS3Uri,\n planOutputS3Prefix: event.PlanOutputS3Prefix,\n format: event.Config.format,\n fps: event.Config.fps,\n };\n case \"renderChunk\":\n return {\n planS3Uri: event.PlanS3Uri,\n chunkIndex: event.ChunkIndex,\n format: event.Format,\n };\n case \"assemble\":\n return {\n planS3Uri: event.PlanS3Uri,\n chunkCount: event.ChunkS3Uris.length,\n hasAudio: event.AudioS3Uri !== null,\n outputS3Uri: event.OutputS3Uri,\n format: event.Format,\n };\n }\n}\n\n/**\n * Lambda sets `TMPDIR` to `/tmp` already, but the bundled binaries (Chrome\n * + ffmpeg) live alongside the handler at `/var/task/bin/`. Add that to\n * PATH the first time the handler runs so spawn(\"ffmpeg\", \u2026) inside the\n * OSS primitives resolves to the bundled binary.\n */\nlet runtimeEnvPrimed = false;\nfunction primeRuntimeEnv(): void {\n if (runtimeEnvPrimed) return;\n runtimeEnvPrimed = true;\n const taskRoot = process.env.LAMBDA_TASK_ROOT ?? \"/var/task\";\n const bin = join(taskRoot, \"bin\");\n if (existsSync(bin)) {\n process.env.PATH = `${bin}:${process.env.PATH ?? \"\"}`;\n }\n}\n\n// \u2500\u2500 Plan \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanLambdaResult> {\n const started = Date.now();\n const s3 = deps?.s3 ?? getS3Client();\n const primitive = deps?.primitives?.plan ?? plan;\n\n const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), \"hf-lambda-plan-\"));\n // We use `.tar.gz` (not `.zip`) as the project archive's on-the-wire\n // format because Lambda's Amazon Linux base image ships GNU `tar` but\n // not `unzip` in `/usr/bin`. The smoke script + future CLI both\n // produce tar.gz uploads.\n const projectArchive = join(work, \"project.tar.gz\");\n const projectDir = join(work, \"project\");\n const planDir = join(work, \"plan\");\n\n try {\n await downloadS3ObjectToFile(s3, event.ProjectS3Uri, projectArchive);\n await untarDirectory(projectArchive, projectDir);\n\n const config: DistributedRenderConfig = {\n ...event.Config,\n };\n const result: PlanResult = await primitive(projectDir, config, planDir);\n\n // Upload the planDir as a single tarball. Step Functions cannot pass\n // a directory-shaped artifact between states; we serialize and rely on\n // the consumer (renderChunk / assemble) to untar. Audio is co-located\n // alongside the plan so RenderChunk doesn't have to pull the whole\n // plan tarball when audio isn't relevant to the chunk.\n const planTar = join(work, \"plan.tar.gz\");\n await tarDirectory(planDir, planTar);\n const planTarUri = `${trimTrailingSlash(event.PlanOutputS3Prefix)}/plan.tar.gz`;\n const audioPath = join(planDir, \"audio.aac\");\n const hasAudio = existsSync(audioPath) && statSync(audioPath).size > 0;\n const audioUri = hasAudio ? `${trimTrailingSlash(event.PlanOutputS3Prefix)}/audio.aac` : null;\n // Plan and audio are independent S3 PUTs; run them in parallel so\n // the response returns as soon as the slower of the two completes.\n await Promise.all([\n uploadFileToS3(s3, planTar, planTarUri, \"application/gzip\"),\n hasAudio && audioUri ? uploadFileToS3(s3, audioPath, audioUri, \"audio/aac\") : null,\n ]);\n\n return {\n Action: \"plan\",\n PlanS3Uri: planTarUri,\n PlanHash: result.planHash,\n ChunkCount: result.chunkCount,\n TotalFrames: result.totalFrames,\n Fps: result.fps,\n Width: result.width,\n Height: result.height,\n Format: result.format,\n HasAudio: audioUri !== null,\n AudioS3Uri: audioUri,\n FfmpegVersion: result.ffmpegVersion,\n ProducerVersion: result.producerVersion,\n DurationMs: Date.now() - started,\n };\n } finally {\n cleanupDir(work);\n }\n}\n\n// \u2500\u2500 RenderChunk \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function handleRenderChunk(\n event: RenderChunkEvent,\n deps?: HandlerDeps,\n): Promise<RenderChunkLambdaResult> {\n const started = Date.now();\n const s3 = deps?.s3 ?? getS3Client();\n const primitive = deps?.primitives?.renderChunk ?? renderChunk;\n\n // Sparticuz decompresses Chromium into /tmp on first call; warm starts\n // skip the work (path already cached). Guard the env-var mutation too so\n // a caller-supplied PRODUCER_HEADLESS_SHELL_PATH (e.g. the SAM-local\n // RIE smoke) wins over the auto-resolution.\n if (!deps?.skipChromeResolution && !process.env.PRODUCER_HEADLESS_SHELL_PATH) {\n const chromePath = await resolveChromeExecutablePath();\n // The OSS engine resolves Chrome via `PRODUCER_HEADLESS_SHELL_PATH`\n // first (see `browserManager.resolveHeadlessShellPath`); set it before\n // invoking the primitive so launch picks up the bundled binary.\n process.env.PRODUCER_HEADLESS_SHELL_PATH = chromePath;\n }\n\n const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), \"hf-lambda-chunk-\"));\n const planTar = join(work, \"plan.tar.gz\");\n const planDir = join(work, \"plan\");\n\n try {\n await downloadS3ObjectToFile(s3, event.PlanS3Uri, planTar);\n await untarDirectory(planTar, planDir);\n\n // Verify the plan's hash matches what Step Functions told us to render.\n // The producer's renderChunk re-checks internally (defense-in-depth),\n // but doing it here at the handler boundary lets us fail before paying\n // the Chrome-launch + render cost on a misrouted chunk. Throws a\n // typed PLAN_HASH_MISMATCH that Step Functions can route as\n // non-retryable.\n verifyPlanHash(planDir, event.PlanHash);\n\n const chunkOutputBase = join(\n work,\n event.Format === \"png-sequence\"\n ? `chunk-${pad(event.ChunkIndex)}`\n : `chunk-${pad(event.ChunkIndex)}${formatExtension(event.Format)}`,\n );\n\n const result: ChunkResult = await primitive(planDir, event.ChunkIndex, chunkOutputBase);\n\n const chunkUri = await uploadChunkOutput(\n s3,\n result,\n event.ChunkOutputS3Prefix,\n event.ChunkIndex,\n );\n\n return {\n Action: \"renderChunk\",\n ChunkS3Uri: chunkUri,\n ChunkIndex: event.ChunkIndex,\n Sha256: result.sha256,\n FramesEncoded: result.framesEncoded,\n DurationMs: Date.now() - started,\n };\n } finally {\n cleanupDir(work);\n }\n}\n\nasync function uploadChunkOutput(\n s3: S3Client,\n result: ChunkResult,\n prefix: string,\n chunkIndex: number,\n): Promise<string> {\n const trimmed = trimTrailingSlash(prefix);\n if (result.outputKind === \"file\") {\n const ext = result.outputPath.slice(result.outputPath.lastIndexOf(\".\"));\n const uri = `${trimmed}/chunks/${pad(chunkIndex)}${ext}`;\n await uploadFileToS3(s3, result.outputPath, uri);\n return uri;\n }\n // frame-dir: upload as a tarball so a single S3 object represents the chunk.\n // Assemble's png-sequence path expects a directory per chunk; it untars on\n // its end.\n const tarball = `${result.outputPath}.tar.gz`;\n await tarDirectory(result.outputPath, tarball);\n const uri = `${trimmed}/chunks/${pad(chunkIndex)}.tar.gz`;\n await uploadFileToS3(s3, tarball, uri, \"application/gzip\");\n return uri;\n}\n\n// \u2500\u2500 Assemble \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function handleAssemble(\n event: AssembleEvent,\n deps?: HandlerDeps,\n): Promise<AssembleLambdaResult> {\n const started = Date.now();\n const s3 = deps?.s3 ?? getS3Client();\n const primitive = deps?.primitives?.assemble ?? assemble;\n\n const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), \"hf-lambda-assemble-\"));\n const planTar = join(work, \"plan.tar.gz\");\n const planDir = join(work, \"plan\");\n\n try {\n await downloadS3ObjectToFile(s3, event.PlanS3Uri, planTar);\n await untarDirectory(planTar, planDir);\n\n const chunkPaths = await downloadChunkObjects(s3, event.ChunkS3Uris, work, event.Format);\n\n let audioPath: string | null = null;\n if (event.AudioS3Uri) {\n audioPath = join(planDir, \"audio.aac\");\n await downloadS3ObjectToFile(s3, event.AudioS3Uri, audioPath);\n }\n\n const finalOutput =\n event.Format === \"png-sequence\"\n ? join(work, \"output-frames\")\n : join(work, `output${formatExtension(event.Format)}`);\n\n const result: AssembleResult = await primitive(planDir, chunkPaths, audioPath, finalOutput);\n\n if (event.Format === \"png-sequence\") {\n const tarball = `${finalOutput}.tar.gz`;\n await tarDirectory(finalOutput, tarball);\n await uploadFileToS3(s3, tarball, event.OutputS3Uri, \"application/gzip\");\n } else {\n await uploadFileToS3(s3, finalOutput, event.OutputS3Uri);\n }\n\n return {\n Action: \"assemble\",\n OutputS3Uri: event.OutputS3Uri,\n FramesEncoded: result.framesEncoded,\n FileSize: result.fileSize,\n DurationMs: Date.now() - started,\n };\n } finally {\n cleanupDir(work);\n }\n}\n\nasync function downloadChunkObjects(\n s3: S3Client,\n uris: string[],\n workDir: string,\n format: DistributedFormat,\n): Promise<string[]> {\n const chunksDir = join(workDir, \"chunks\");\n mkdirSync(chunksDir, { recursive: true });\n // Each chunk is an independent S3 GET (+ untar for png-sequence). Run\n // them in parallel \u2014 assemble's wall-clock is otherwise dominated by\n // `\u03A3 chunk-download-ms` instead of `max(chunk-download-ms)`. Preserve\n // the input order by writing into a pre-sized array rather than\n // pushing as each task settles.\n const local: string[] = new Array<string>(uris.length);\n await Promise.all(\n uris.map(async (uri, i) => {\n if (!uri) {\n throw new Error(`[handler] chunk URI at index ${i} is empty`);\n }\n const { key } = parseS3Uri(uri);\n const localPath = join(chunksDir, basename(key));\n await downloadS3ObjectToFile(s3, uri, localPath);\n if (format === \"png-sequence\") {\n const dirPath = join(chunksDir, `frames-${pad(i)}`);\n await untarDirectory(localPath, dirPath);\n local[i] = dirPath;\n } else {\n local[i] = localPath;\n }\n }),\n );\n return local;\n}\n\n// \u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction pad(n: number): string {\n return n.toString().padStart(4, \"0\");\n}\n\nfunction trimTrailingSlash(prefix: string): string {\n return prefix.endsWith(\"/\") ? prefix.slice(0, -1) : prefix;\n}\n\nfunction cleanupDir(dir: string): void {\n try {\n // Lambda warm starts can reuse `/tmp` across invocations; clean up\n // aggressively so we don't leak a chunk-sized footprint between renders.\n rmSync(dir, { recursive: true, force: true });\n } catch {\n // Best-effort \u2014 leak is preferable to crashing on success path.\n }\n}\n\n/**\n * Read the untarred planDir's `plan.json` and assert its `planHash`\n * matches what the Step Functions event claims. Throws on mismatch with\n * a typed `PLAN_HASH_MISMATCH` error name so the state machine's typed\n * non-retryable list routes it correctly.\n *\n * This is defense-in-depth \u2014 the producer's `renderChunk` does the same\n * check internally \u2014 but performing it here lets us fail before paying\n * the Chrome-launch + per-frame capture cost on a misrouted chunk.\n */\nfunction verifyPlanHash(planDir: string, expected: string): void {\n const planJsonPath = join(planDir, \"plan.json\");\n let parsed: { planHash?: unknown };\n try {\n parsed = JSON.parse(readFileSync(planJsonPath, \"utf-8\")) as { planHash?: unknown };\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n const error = new Error(`PLAN_HASH_MISMATCH: failed to read ${planJsonPath}: ${msg}`);\n error.name = \"PLAN_HASH_MISMATCH\";\n throw error;\n }\n const actual = parsed.planHash;\n if (typeof actual !== \"string\" || actual !== expected) {\n const error = new Error(\n `PLAN_HASH_MISMATCH: event PlanHash=${expected} did not match plan.json planHash=${String(actual)}`,\n );\n error.name = \"PLAN_HASH_MISMATCH\";\n throw error;\n }\n}\n", "/**\n * Lambda-runtime Chrome resolver.\n *\n * `renderChunk()` (the only primitive that needs a browser) launches Chrome\n * via the engine's `BrowserManager`. In Lambda we can't ship the full\n * Puppeteer-managed Chrome download \u2014 Puppeteer's Chrome binary is ~330 MB\n * unzipped, well over Lambda's 250 MB ZIP-deploy ceiling.\n *\n * Two valid runtime sources:\n *\n * 1. `@sparticuz/chromium` (primary). Decompresses a Lambda-optimised\n * `chrome-headless-shell` build into `/tmp` at runtime. ~70 MB\n * compressed; the same binary the rest of the ecosystem uses for\n * headless-Chrome-in-Lambda. CDP-level BeginFrame works because the\n * command lives in the protocol, not the binary; the\n * `scripts/probe-beginframe.ts` regression guard pins this.\n *\n * 2. A bundled `chrome-headless-shell` binary (fallback). If\n * `@sparticuz/chromium`'s build ever drops `HeadlessExperimental`\n * support, we fall back to the same `chrome-headless-shell` build\n * the K8s deploy uses. The fallback raises the ZIP from ~70 MB\n * Chrome to ~140 MB Chrome \u2014 still well under 250 MB.\n *\n * The runtime path is selected by the `HYPERFRAMES_LAMBDA_CHROME_SOURCE`\n * env var (set by `build-zip.ts`):\n *\n * \"sparticuz\" \u2192 use `@sparticuz/chromium.executablePath()`\n * \"chrome-headless-shell\" \u2192 use `process.env.HYPERFRAMES_LAMBDA_CHROME_PATH`\n *\n * Adapters that bundle this package can override\n * `HYPERFRAMES_LAMBDA_CHROME_PATH` directly when running outside Lambda\n * (e.g. the SAM-local RIE smoke).\n */\n\nimport { existsSync } from \"node:fs\";\n\n/** Discriminator for the two supported Chrome sources. */\nexport type ChromeSource = \"sparticuz\" | \"chrome-headless-shell\";\n\n/**\n * Read which Chrome source the bundled ZIP was built against. Defaults to\n * `\"sparticuz\"` so a fresh build with no env override picks the primary\n * path.\n */\nexport function resolveChromeSource(): ChromeSource {\n const raw = process.env.HYPERFRAMES_LAMBDA_CHROME_SOURCE?.toLowerCase();\n if (raw === \"chrome-headless-shell\" || raw === \"shell\") return \"chrome-headless-shell\";\n return \"sparticuz\";\n}\n\n/**\n * Resolve the absolute path to a Chrome binary suitable for BeginFrame.\n *\n * For `\"sparticuz\"`: dynamically import `@sparticuz/chromium` and call\n * `chromium.executablePath()`. The module is dynamic so a build-zip that\n * never reaches the import (because the fallback Chrome is bundled) can\n * tree-shake it out.\n *\n * For `\"chrome-headless-shell\"`: read the path from\n * `HYPERFRAMES_LAMBDA_CHROME_PATH`. Throws if absent or non-existent so a\n * misconfigured deploy fails loudly at boot rather than at first frame.\n */\nexport async function resolveChromeExecutablePath(): Promise<string> {\n const source = resolveChromeSource();\n if (source === \"sparticuz\") {\n const mod = await loadSparticuzChromium();\n return mod.executablePath();\n }\n const explicit = process.env.HYPERFRAMES_LAMBDA_CHROME_PATH;\n if (!explicit) {\n throw new Error(\n \"[chromium] HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires \" +\n \"HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary.\",\n );\n }\n if (!existsSync(explicit)) {\n throw new Error(\n `[chromium] HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist`,\n );\n }\n return explicit;\n}\n\n/**\n * Resolve the Chromium launch args for the selected source. For\n * `@sparticuz/chromium` we forward `chromium.args` (Lambda-tuned defaults\n * \u2014 single-process, no-sandbox, /tmp paths). For the shell fallback the\n * engine's own arg builder owns it; we return an empty array so the\n * engine's defaults apply.\n */\nexport async function resolveChromeArgs(): Promise<string[]> {\n if (resolveChromeSource() !== \"sparticuz\") return [];\n const mod = await loadSparticuzChromium();\n return mod.args;\n}\n\n/**\n * Dynamic import wrapper isolated so unit tests can stub the module without\n * jest-style module mocking gymnastics. The narrow type here pins the\n * subset of `@sparticuz/chromium`'s surface this package depends on; if\n * the upstream module ever changes shape the type error here surfaces\n * before runtime.\n */\ninterface SparticuzChromiumModule {\n args: string[];\n executablePath(): Promise<string>;\n}\n\nlet cachedSparticuz: SparticuzChromiumModule | null = null;\n\nasync function loadSparticuzChromium(): Promise<SparticuzChromiumModule> {\n if (cachedSparticuz) return cachedSparticuz;\n const mod = (await import(\"@sparticuz/chromium\")) as\n | SparticuzChromiumModule\n | { default: SparticuzChromiumModule };\n const resolved = \"default\" in mod ? mod.default : mod;\n cachedSparticuz = resolved;\n return resolved;\n}\n\n/** Test-only seam: replace the cached `@sparticuz/chromium` module. */\nexport function _setSparticuzChromiumForTests(mod: SparticuzChromiumModule | null): void {\n cachedSparticuz = mod;\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 * 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"],
5
- "mappings": ";AAaA,SAAS,cAAAA,aAAY,aAAAC,YAAW,aAAa,cAAc,UAAAC,SAAQ,YAAAC,iBAAgB;AACnF,SAAS,cAAc;AACvB,SAAS,UAAU,YAAY;AAC/B,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EAIA;A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cAAM,UAAU,KAAK,WAAW,UAAU,IAAI,CAAC,CAAC,EAAE;AAClD,cAAM,eAAe,WAAW,OAAO;AACvC,cAAM,CAAC,IAAI;AAAA,MACb,OAAO;AACL,cAAM,CAAC,IAAI;AAAA,MACb;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAIA,SAAS,IAAI,GAAmB;AAC9B,SAAO,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG;AACrC;AAEA,SAAS,kBAAkB,QAAwB;AACjD,SAAO,OAAO,SAAS,GAAG,IAAI,OAAO,MAAM,GAAG,EAAE,IAAI;AACtD;AAEA,SAAS,WAAW,KAAmB;AACrC,MAAI;AAGF,IAAAC,QAAO,KAAK,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EAC9C,QAAQ;AAAA,EAER;AACF;AAYA,SAAS,eAAe,SAAiB,UAAwB;AAC/D,QAAM,eAAe,KAAK,SAAS,WAAW;AAC9C,MAAI;AACJ,MAAI;AACF,aAAS,KAAK,MAAM,aAAa,cAAc,OAAO,CAAC;AAAA,EACzD,SAAS,KAAK;AACZ,UAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC3D,UAAM,QAAQ,IAAI,MAAM,sCAAsC,YAAY,KAAK,GAAG,EAAE;AACpF,UAAM,OAAO;AACb,UAAM;AAAA,EACR;AACA,QAAM,SAAS,OAAO;AACtB,MAAI,OAAO,WAAW,YAAY,WAAW,UAAU;AACrD,UAAM,QAAQ,IAAI;AAAA,MAChB,sCAAsC,QAAQ,qCAAqC,OAAO,MAAM,CAAC;AAAA,IACnG;AACA,UAAM,OAAO;AACb,UAAM;AAAA,EACR;AACF;",
4
+ "sourcesContent": ["/**\n * AWS Lambda handler for HyperFrames distributed rendering.\n *\n * One Lambda function, three roles. Step Functions dispatches by setting\n * `event.Action`; the handler unwraps Map-state envelopes, primes the\n * Lambda environment (Chrome path, ffmpeg path, tmpdir), and forwards to\n * the matching OSS primitive from `@hyperframes/producer/distributed`.\n *\n * Everything heavy \u2014 capture, encode, audio mix \u2014 happens inside the OSS\n * primitives. The handler is thin glue: parse event \u2192 S3 download \u2192 call\n * primitive \u2192 S3 upload \u2192 return small JSON result.\n */\n\nimport { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { basename, join } from \"node:path\";\nimport { S3Client } from \"@aws-sdk/client-s3\";\nimport {\n assemble,\n type AssembleResult,\n type ChunkResult,\n type DistributedRenderConfig,\n plan,\n type PlanResult,\n renderChunk,\n} from \"@hyperframes/producer/distributed\";\nimport { resolveChromeExecutablePath } from \"./chromium.js\";\nimport { type DistributedFormat, formatExtension } from \"./formatExtension.js\";\nimport type {\n AssembleEvent,\n AssembleLambdaResult,\n LambdaAction,\n LambdaEvent,\n LambdaResult,\n PlanEvent,\n PlanLambdaResult,\n RenderChunkEvent,\n RenderChunkLambdaResult,\n} from \"./events.js\";\nimport {\n downloadS3ObjectToFile,\n parseS3Uri,\n tarDirectory,\n untarDirectory,\n uploadFileToS3,\n} from \"./s3Transport.js\";\n\n/**\n * Lazily-constructed S3 client. Cached at module scope so warm Lambda\n * containers reuse the underlying HTTP keep-alive pool across invocations.\n */\nlet cachedS3Client: S3Client | null = null;\nfunction getS3Client(): S3Client {\n if (cachedS3Client) return cachedS3Client;\n cachedS3Client = new S3Client({});\n return cachedS3Client;\n}\n\n/**\n * Optional injection points used by the handler's unit tests. Production\n * callers leave these unset; the real OSS primitives are used. Tests\n * inject `s3` and `primitives` directly rather than mutating module\n * state \u2014 the dependency-injection seam is sufficient and avoids a\n * second leak point for cross-test contamination.\n */\nexport interface HandlerDeps {\n s3?: S3Client;\n primitives?: {\n plan: typeof plan;\n renderChunk: typeof renderChunk;\n assemble: typeof assemble;\n };\n /** Override the per-invocation `/tmp` workdir root (defaults to Lambda's `/tmp`). */\n tmpRoot?: string;\n /** Skip Chrome resolution (used by handler dispatch tests that mock renderChunk). */\n skipChromeResolution?: boolean;\n}\n\n/**\n * Lambda entry. Step Functions sometimes wraps the event in\n * `{ Payload: ... }` or `{ Input: ... }` depending on the state machine\n * shape; unwrap until we hit a discriminated event.\n */\nexport async function handler(event: LambdaEvent, deps?: HandlerDeps): Promise<LambdaResult> {\n const unwrapped = unwrapEvent(event);\n primeRuntimeEnv();\n // Single structured boot log line \u2014 CloudWatch Logs Insights queries\n // key off `event=handler_start` to grep for a specific Action / S3 URI\n // when triaging without attaching a debugger.\n logEvent({ event: \"handler_start\", action: unwrapped.Action, input: summarizeEvent(unwrapped) });\n try {\n switch (unwrapped.Action) {\n case \"plan\":\n return await handlePlan(unwrapped, deps);\n case \"renderChunk\":\n return await handleRenderChunk(unwrapped, deps);\n case \"assemble\":\n return await handleAssemble(unwrapped, deps);\n default: {\n // Compile-time exhaustiveness: a new LambdaAction member trips\n // the `never` assignment before the runtime error is reachable.\n const _exhaustive: never = unwrapped;\n throw new Error(\n `[handler] unknown Action: ${JSON.stringify(\n (_exhaustive as { Action?: string }).Action,\n )}. Expected one of \"plan\", \"renderChunk\", \"assemble\".`,\n );\n }\n }\n } catch (err) {\n // Log before re-throwing so CloudWatch captures the structured\n // error context alongside Lambda's default stack trace. Otherwise\n // ops only sees the trace and has to correlate with execution\n // history to recover the action + input.\n logEvent({\n event: \"handler_error\",\n action: unwrapped.Action,\n message: err instanceof Error ? err.message : String(err),\n name: err instanceof Error ? err.name : undefined,\n });\n throw err;\n }\n}\n\n/**\n * Walk through Step Functions' Map-state and Task-state envelopes until\n * the discriminated event is found.\n */\n// Step Functions wraps at most `{Payload: {Input: ...}}` in our state\n// machine; 4 levels is 2\u00D7 headroom for unusual Map / Wait state\n// configurations and prevents infinite loops on malformed input.\nconst MAX_ENVELOPE_DEPTH = 4;\n\nexport function unwrapEvent(event: LambdaEvent): PlanEvent | RenderChunkEvent | AssembleEvent {\n let cursor: LambdaEvent = event;\n for (let i = 0; i < MAX_ENVELOPE_DEPTH; i++) {\n if (cursor && typeof cursor === \"object\") {\n const obj = cursor as Record<string, unknown>;\n if (typeof obj.Action === \"string\" && isLambdaAction(obj.Action)) {\n return cursor as PlanEvent | RenderChunkEvent | AssembleEvent;\n }\n if (\"Payload\" in obj) {\n cursor = obj.Payload as LambdaEvent;\n continue;\n }\n if (\"Input\" in obj) {\n cursor = obj.Input as LambdaEvent;\n continue;\n }\n }\n break;\n }\n throw new Error(\n `[handler] event has no recognised Action; unwrapped ${MAX_ENVELOPE_DEPTH} levels of Payload/Input without finding one.`,\n );\n}\n\nfunction isLambdaAction(value: string): value is LambdaAction {\n return value === \"plan\" || value === \"renderChunk\" || value === \"assemble\";\n}\n\n/**\n * Emit a single JSON line to stdout. CloudWatch ingests each line as a\n * structured event; Logs Insights queries can `filter event=\"...\"` and\n * project specific fields. We write to stdout (not stderr) because\n * Lambda's default destination for both is the same log group, and\n * Logs Insights' INFO/ERROR level parser keys off the JSON `level`\n * field, not the stream.\n */\nfunction logEvent(payload: Record<string, unknown>): void {\n console.log(JSON.stringify(payload));\n}\n\n/**\n * Compact, non-PII summary of a Lambda event for logging. The full\n * event payload can include the entire project config; we only emit\n * the routable fields (S3 URIs, chunk index, format) needed to triage\n * a failure from CloudWatch.\n */\nfunction summarizeEvent(\n event: PlanEvent | RenderChunkEvent | AssembleEvent,\n): Record<string, unknown> {\n switch (event.Action) {\n case \"plan\":\n return {\n projectS3Uri: event.ProjectS3Uri,\n planOutputS3Prefix: event.PlanOutputS3Prefix,\n format: event.Config.format,\n fps: event.Config.fps,\n };\n case \"renderChunk\":\n return {\n planS3Uri: event.PlanS3Uri,\n chunkIndex: event.ChunkIndex,\n format: event.Format,\n };\n case \"assemble\":\n return {\n planS3Uri: event.PlanS3Uri,\n chunkCount: event.ChunkS3Uris.length,\n hasAudio: event.AudioS3Uri !== null,\n outputS3Uri: event.OutputS3Uri,\n format: event.Format,\n };\n }\n}\n\n/**\n * Lambda sets `TMPDIR` to `/tmp` already, but the bundled binaries (Chrome\n * + ffmpeg) live alongside the handler at `/var/task/bin/`. Add that to\n * PATH the first time the handler runs so spawn(\"ffmpeg\", \u2026) inside the\n * OSS primitives resolves to the bundled binary.\n */\nlet runtimeEnvPrimed = false;\nfunction primeRuntimeEnv(): void {\n if (runtimeEnvPrimed) return;\n runtimeEnvPrimed = true;\n const taskRoot = process.env.LAMBDA_TASK_ROOT ?? \"/var/task\";\n const bin = join(taskRoot, \"bin\");\n if (existsSync(bin)) {\n process.env.PATH = `${bin}:${process.env.PATH ?? \"\"}`;\n }\n}\n\n// \u2500\u2500 Plan \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanLambdaResult> {\n const started = Date.now();\n const s3 = deps?.s3 ?? getS3Client();\n const primitive = deps?.primitives?.plan ?? plan;\n\n const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), \"hf-lambda-plan-\"));\n // We use `.tar.gz` (not `.zip`) as the project archive's on-the-wire\n // format because Lambda's Amazon Linux base image ships GNU `tar` but\n // not `unzip` in `/usr/bin`. The smoke script + future CLI both\n // produce tar.gz uploads.\n const projectArchive = join(work, \"project.tar.gz\");\n const projectDir = join(work, \"project\");\n const planDir = join(work, \"plan\");\n\n try {\n await downloadS3ObjectToFile(s3, event.ProjectS3Uri, projectArchive);\n await untarDirectory(projectArchive, projectDir);\n\n const config: DistributedRenderConfig = {\n ...event.Config,\n };\n const result: PlanResult = await primitive(projectDir, config, planDir);\n\n // Upload the planDir as a single tarball. Step Functions cannot pass\n // a directory-shaped artifact between states; we serialize and rely on\n // the consumer (renderChunk / assemble) to untar. Audio is co-located\n // alongside the plan so RenderChunk doesn't have to pull the whole\n // plan tarball when audio isn't relevant to the chunk.\n const planTar = join(work, \"plan.tar.gz\");\n await tarDirectory(planDir, planTar);\n const planTarUri = `${trimTrailingSlash(event.PlanOutputS3Prefix)}/plan.tar.gz`;\n const audioPath = join(planDir, \"audio.aac\");\n const hasAudio = existsSync(audioPath) && statSync(audioPath).size > 0;\n const audioUri = hasAudio ? `${trimTrailingSlash(event.PlanOutputS3Prefix)}/audio.aac` : null;\n // Plan and audio are independent S3 PUTs; run them in parallel so\n // the response returns as soon as the slower of the two completes.\n await Promise.all([\n uploadFileToS3(s3, planTar, planTarUri, \"application/gzip\"),\n hasAudio && audioUri ? uploadFileToS3(s3, audioPath, audioUri, \"audio/aac\") : null,\n ]);\n\n return {\n Action: \"plan\",\n PlanS3Uri: planTarUri,\n PlanHash: result.planHash,\n ChunkCount: result.chunkCount,\n TotalFrames: result.totalFrames,\n Fps: result.fps,\n Width: result.width,\n Height: result.height,\n Format: result.format,\n HasAudio: audioUri !== null,\n AudioS3Uri: audioUri,\n FfmpegVersion: result.ffmpegVersion,\n ProducerVersion: result.producerVersion,\n DurationMs: Date.now() - started,\n };\n } finally {\n cleanupDir(work);\n }\n}\n\n// \u2500\u2500 RenderChunk \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function handleRenderChunk(\n event: RenderChunkEvent,\n deps?: HandlerDeps,\n): Promise<RenderChunkLambdaResult> {\n const started = Date.now();\n const s3 = deps?.s3 ?? getS3Client();\n const primitive = deps?.primitives?.renderChunk ?? renderChunk;\n\n // Sparticuz decompresses Chromium into /tmp on first call; warm starts\n // skip the work (path already cached). Guard the env-var mutation too so\n // a caller-supplied PRODUCER_HEADLESS_SHELL_PATH (e.g. the SAM-local\n // RIE smoke) wins over the auto-resolution.\n if (!deps?.skipChromeResolution && !process.env.PRODUCER_HEADLESS_SHELL_PATH) {\n const chromePath = await resolveChromeExecutablePath();\n // The OSS engine resolves Chrome via `PRODUCER_HEADLESS_SHELL_PATH`\n // first (see `browserManager.resolveHeadlessShellPath`); set it before\n // invoking the primitive so launch picks up the bundled binary.\n process.env.PRODUCER_HEADLESS_SHELL_PATH = chromePath;\n }\n\n const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), \"hf-lambda-chunk-\"));\n const planTar = join(work, \"plan.tar.gz\");\n const planDir = join(work, \"plan\");\n\n try {\n await downloadS3ObjectToFile(s3, event.PlanS3Uri, planTar);\n await untarDirectory(planTar, planDir);\n\n // Verify the plan's hash matches what Step Functions told us to render.\n // The producer's renderChunk re-checks internally (defense-in-depth),\n // but doing it here at the handler boundary lets us fail before paying\n // the Chrome-launch + render cost on a misrouted chunk. Throws a\n // typed PLAN_HASH_MISMATCH that Step Functions can route as\n // non-retryable.\n verifyPlanHash(planDir, event.PlanHash);\n\n const chunkOutputBase = join(\n work,\n event.Format === \"png-sequence\"\n ? `chunk-${pad(event.ChunkIndex)}`\n : `chunk-${pad(event.ChunkIndex)}${formatExtension(event.Format)}`,\n );\n\n const result: ChunkResult = await primitive(planDir, event.ChunkIndex, chunkOutputBase);\n\n const chunkUri = await uploadChunkOutput(\n s3,\n result,\n event.ChunkOutputS3Prefix,\n event.ChunkIndex,\n );\n\n return {\n Action: \"renderChunk\",\n ChunkS3Uri: chunkUri,\n ChunkIndex: event.ChunkIndex,\n Sha256: result.sha256,\n FramesEncoded: result.framesEncoded,\n DurationMs: Date.now() - started,\n };\n } finally {\n cleanupDir(work);\n }\n}\n\nasync function uploadChunkOutput(\n s3: S3Client,\n result: ChunkResult,\n prefix: string,\n chunkIndex: number,\n): Promise<string> {\n const trimmed = trimTrailingSlash(prefix);\n if (result.outputKind === \"file\") {\n const ext = result.outputPath.slice(result.outputPath.lastIndexOf(\".\"));\n const uri = `${trimmed}/chunks/${pad(chunkIndex)}${ext}`;\n await uploadFileToS3(s3, result.outputPath, uri);\n return uri;\n }\n // frame-dir: upload as a tarball so a single S3 object represents the chunk.\n // Assemble's png-sequence path expects a directory per chunk; it untars on\n // its end.\n const tarball = `${result.outputPath}.tar.gz`;\n await tarDirectory(result.outputPath, tarball);\n const uri = `${trimmed}/chunks/${pad(chunkIndex)}.tar.gz`;\n await uploadFileToS3(s3, tarball, uri, \"application/gzip\");\n return uri;\n}\n\n// \u2500\u2500 Assemble \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function handleAssemble(\n event: AssembleEvent,\n deps?: HandlerDeps,\n): Promise<AssembleLambdaResult> {\n const started = Date.now();\n const s3 = deps?.s3 ?? getS3Client();\n const primitive = deps?.primitives?.assemble ?? assemble;\n\n const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), \"hf-lambda-assemble-\"));\n const planTar = join(work, \"plan.tar.gz\");\n const planDir = join(work, \"plan\");\n\n try {\n await downloadS3ObjectToFile(s3, event.PlanS3Uri, planTar);\n await untarDirectory(planTar, planDir);\n\n const chunkPaths = await downloadChunkObjects(s3, event.ChunkS3Uris, work, event.Format);\n\n let audioPath: string | null = null;\n if (event.AudioS3Uri) {\n audioPath = join(planDir, \"audio.aac\");\n await downloadS3ObjectToFile(s3, event.AudioS3Uri, audioPath);\n }\n\n const finalOutput =\n event.Format === \"png-sequence\"\n ? join(work, \"output-frames\")\n : join(work, `output${formatExtension(event.Format)}`);\n\n const result: AssembleResult = await primitive(planDir, chunkPaths, audioPath, finalOutput);\n\n if (event.Format === \"png-sequence\") {\n const tarball = `${finalOutput}.tar.gz`;\n await tarDirectory(finalOutput, tarball);\n await uploadFileToS3(s3, tarball, event.OutputS3Uri, \"application/gzip\");\n } else {\n await uploadFileToS3(s3, finalOutput, event.OutputS3Uri);\n }\n\n return {\n Action: \"assemble\",\n OutputS3Uri: event.OutputS3Uri,\n FramesEncoded: result.framesEncoded,\n FileSize: result.fileSize,\n DurationMs: Date.now() - started,\n };\n } finally {\n cleanupDir(work);\n }\n}\n\nasync function downloadChunkObjects(\n s3: S3Client,\n uris: string[],\n workDir: string,\n format: DistributedFormat,\n): Promise<string[]> {\n const chunksDir = join(workDir, \"chunks\");\n mkdirSync(chunksDir, { recursive: true });\n // Each chunk is an independent S3 GET (+ untar for png-sequence). Run\n // them in parallel \u2014 assemble's wall-clock is otherwise dominated by\n // `\u03A3 chunk-download-ms` instead of `max(chunk-download-ms)`. Preserve\n // the input order by writing into a pre-sized array rather than\n // pushing as each task settles.\n const local: string[] = new Array<string>(uris.length);\n await Promise.all(\n uris.map(async (uri, i) => {\n if (!uri) {\n throw new Error(`[handler] chunk URI at index ${i} is empty`);\n }\n const { key } = parseS3Uri(uri);\n const localPath = join(chunksDir, basename(key));\n await downloadS3ObjectToFile(s3, uri, localPath);\n if (format === \"png-sequence\") {\n const dirPath = join(chunksDir, `frames-${pad(i)}`);\n await untarDirectory(localPath, dirPath);\n local[i] = dirPath;\n } else {\n local[i] = localPath;\n }\n }),\n );\n return local;\n}\n\n// \u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction pad(n: number): string {\n return n.toString().padStart(4, \"0\");\n}\n\nfunction trimTrailingSlash(prefix: string): string {\n return prefix.endsWith(\"/\") ? prefix.slice(0, -1) : prefix;\n}\n\nfunction cleanupDir(dir: string): void {\n try {\n // Lambda warm starts can reuse `/tmp` across invocations; clean up\n // aggressively so we don't leak a chunk-sized footprint between renders.\n rmSync(dir, { recursive: true, force: true });\n } catch {\n // Best-effort \u2014 leak is preferable to crashing on success path.\n }\n}\n\n/**\n * Read the untarred planDir's `plan.json` and assert its `planHash`\n * matches what the Step Functions event claims. Throws on mismatch with\n * a typed `PLAN_HASH_MISMATCH` error name so the state machine's typed\n * non-retryable list routes it correctly.\n *\n * This is defense-in-depth \u2014 the producer's `renderChunk` does the same\n * check internally \u2014 but performing it here lets us fail before paying\n * the Chrome-launch + per-frame capture cost on a misrouted chunk.\n */\nfunction verifyPlanHash(planDir: string, expected: string): void {\n const planJsonPath = join(planDir, \"plan.json\");\n let parsed: { planHash?: unknown };\n try {\n parsed = JSON.parse(readFileSync(planJsonPath, \"utf-8\")) as { planHash?: unknown };\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n const error = new Error(`PLAN_HASH_MISMATCH: failed to read ${planJsonPath}: ${msg}`);\n error.name = \"PLAN_HASH_MISMATCH\";\n throw error;\n }\n const actual = parsed.planHash;\n if (typeof actual !== \"string\" || actual !== expected) {\n const error = new Error(\n `PLAN_HASH_MISMATCH: event PlanHash=${expected} did not match plan.json planHash=${String(actual)}`,\n );\n error.name = \"PLAN_HASH_MISMATCH\";\n throw error;\n }\n}\n", "/**\n * Lambda-runtime Chrome resolver.\n *\n * `renderChunk()` (the only primitive that needs a browser) launches Chrome\n * via the engine's `BrowserManager`. In Lambda we can't ship the full\n * Puppeteer-managed Chrome download \u2014 Puppeteer's Chrome binary is ~330 MB\n * unzipped, well over Lambda's 250 MB ZIP-deploy ceiling.\n *\n * Two valid runtime sources:\n *\n * 1. `@sparticuz/chromium` (primary). Decompresses a Lambda-optimised\n * `chrome-headless-shell` build into `/tmp` at runtime. ~70 MB\n * compressed; the same binary the rest of the ecosystem uses for\n * headless-Chrome-in-Lambda. CDP-level BeginFrame works because the\n * command lives in the protocol, not the binary; the\n * `scripts/probe-beginframe.ts` regression guard pins this.\n *\n * 2. A bundled `chrome-headless-shell` binary (fallback). If\n * `@sparticuz/chromium`'s build ever drops `HeadlessExperimental`\n * support, we fall back to the same `chrome-headless-shell` build\n * the K8s deploy uses. The fallback raises the ZIP from ~70 MB\n * Chrome to ~140 MB Chrome \u2014 still well under 250 MB.\n *\n * The runtime path is selected by the `HYPERFRAMES_LAMBDA_CHROME_SOURCE`\n * env var (set by `build-zip.ts`):\n *\n * \"sparticuz\" \u2192 use `@sparticuz/chromium.executablePath()`\n * \"chrome-headless-shell\" \u2192 use `process.env.HYPERFRAMES_LAMBDA_CHROME_PATH`\n *\n * Adapters that bundle this package can override\n * `HYPERFRAMES_LAMBDA_CHROME_PATH` directly when running outside Lambda\n * (e.g. the SAM-local RIE smoke).\n */\n\nimport { existsSync } from \"node:fs\";\n\n/** Discriminator for the two supported Chrome sources. */\nexport type ChromeSource = \"sparticuz\" | \"chrome-headless-shell\";\n\n/**\n * Thrown when the Chrome binary resolver can't produce a usable path.\n * The class name is the SFN `Retry: { ErrorEquals: [...] }` discriminator \u2014\n * see {@link HyperframesRenderStack}'s NON_RETRYABLE_* lists.\n */\nexport class ChromeBinaryUnavailableError extends Error {\n // Lambda's runtime serializes the error envelope's `errorType` from\n // `err.name`; this class-field override sets it across the structured\n // clone. Read indirectly; fallow can't follow.\n // fallow-ignore-next-line unused-class-member\n override readonly name = \"ChromeBinaryUnavailableError\";\n readonly source: ChromeSource;\n readonly resolvedPath: string | null;\n constructor(source: ChromeSource, resolvedPath: string | null, hint: string) {\n super(`[chromium] Chrome binary unavailable (source=${source}): ${hint}`);\n this.source = source;\n this.resolvedPath = resolvedPath;\n }\n}\n\nconst SPARTICUZ_WEDGE_HINT =\n \"@sparticuz/chromium.executablePath() returned a falsy value or a path that doesn't exist on disk. \" +\n \"This typically happens after a chunk hits `Sandbox.Timedout` mid-extraction and leaves /tmp in a \" +\n \"wedged state \u2014 subsequent invocations land on the same warm instance and never re-extract. \" +\n \"Recycle the function (e.g. `aws lambda update-function-configuration ... --environment ...` with a \" +\n \"bumped marker var, or redeploy via `hyperframes lambda deploy --skip-build`) to force fresh \" +\n \"execution environments. Tracking: investigate the upstream wedge so this auto-recovers.\";\n\n/**\n * Read which Chrome source the bundled ZIP was built against. Defaults to\n * `\"sparticuz\"` so a fresh build with no env override picks the primary\n * path.\n */\nexport function resolveChromeSource(): ChromeSource {\n const raw = process.env.HYPERFRAMES_LAMBDA_CHROME_SOURCE?.toLowerCase();\n if (raw === \"chrome-headless-shell\" || raw === \"shell\") return \"chrome-headless-shell\";\n return \"sparticuz\";\n}\n\n/**\n * Resolve the absolute path to a Chrome binary suitable for BeginFrame.\n *\n * For `\"sparticuz\"`: dynamically import `@sparticuz/chromium` and call\n * `chromium.executablePath()`. The module is dynamic so a build-zip that\n * never reaches the import (because the fallback Chrome is bundled) can\n * tree-shake it out.\n *\n * For `\"chrome-headless-shell\"`: read the path from\n * `HYPERFRAMES_LAMBDA_CHROME_PATH`. Throws if absent or non-existent so a\n * misconfigured deploy fails loudly at boot rather than at first frame.\n */\n// fallow-ignore-next-line complexity\nexport async function resolveChromeExecutablePath(): Promise<string> {\n const source = resolveChromeSource();\n if (source === \"sparticuz\") {\n const mod = await loadSparticuzChromium();\n const path = await mod.executablePath();\n // Guard against the wedge described in ChromeBinaryUnavailableError.\n // sparticuz's contract is \"return the path to a usable binary\" \u2014 when\n // it returns null/undefined/\"\" we can't hand that to puppeteer-core\n // (which will throw an unrelated-looking assertion). Same when the\n // returned path doesn't exist (extraction failed but the function\n // call returned).\n if (!path || typeof path !== \"string\") {\n throw new ChromeBinaryUnavailableError(source, null, SPARTICUZ_WEDGE_HINT);\n }\n if (!existsSync(path)) {\n throw new ChromeBinaryUnavailableError(source, path, SPARTICUZ_WEDGE_HINT);\n }\n return path;\n }\n const explicit = process.env.HYPERFRAMES_LAMBDA_CHROME_PATH;\n if (!explicit) {\n throw new ChromeBinaryUnavailableError(\n source,\n null,\n \"HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires \" +\n \"HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary.\",\n );\n }\n if (!existsSync(explicit)) {\n throw new ChromeBinaryUnavailableError(\n source,\n explicit,\n `HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist on disk.`,\n );\n }\n return explicit;\n}\n\n/**\n * Resolve the Chromium launch args for the selected source. For\n * `@sparticuz/chromium` we forward `chromium.args` (Lambda-tuned defaults\n * \u2014 single-process, no-sandbox, /tmp paths). For the shell fallback the\n * engine's own arg builder owns it; we return an empty array so the\n * engine's defaults apply.\n */\nexport async function resolveChromeArgs(): Promise<string[]> {\n if (resolveChromeSource() !== \"sparticuz\") return [];\n const mod = await loadSparticuzChromium();\n return mod.args;\n}\n\n/**\n * Dynamic import wrapper isolated so unit tests can stub the module without\n * jest-style module mocking gymnastics. The narrow type here pins the\n * subset of `@sparticuz/chromium`'s surface this package depends on; if\n * the upstream module ever changes shape the type error here surfaces\n * before runtime.\n */\ninterface SparticuzChromiumModule {\n args: string[];\n executablePath(): Promise<string>;\n}\n\nlet cachedSparticuz: SparticuzChromiumModule | null = null;\n\nasync function loadSparticuzChromium(): Promise<SparticuzChromiumModule> {\n if (cachedSparticuz) return cachedSparticuz;\n const mod = (await import(\"@sparticuz/chromium\")) as\n | SparticuzChromiumModule\n | { default: SparticuzChromiumModule };\n const resolved = \"default\" in mod ? mod.default : mod;\n cachedSparticuz = resolved;\n return resolved;\n}\n\n/** Test-only seam: replace the cached `@sparticuz/chromium` module. */\nexport function _setSparticuzChromiumForTests(mod: SparticuzChromiumModule | null): void {\n cachedSparticuz = mod;\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 * 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"],
5
+ "mappings": ";AAaA,SAAS,cAAAA,aAAY,aAAAC,YAAW,aAAa,cAAc,UAAAC,SAAQ,YAAAC,iBAAgB;AACnF,SAAS,cAAc;AACvB,SAAS,UAAU,YAAY;AAC/B,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EAIA;AAAA,EAEA;AAAA,OACK;;;ACSP,SAAS,kBAAkB;AAUpB,IAAM,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,sCAAsC,YAAY,KAAK,GAAG,EAAE;AACpF,UAAM,OAAO;AACb,UAAM;AAAA,EACR;AACA,QAAM,SAAS,OAAO;AACtB,MAAI,OAAO,WAAW,YAAY,WAAW,UAAU;AACrD,UAAM,QAAQ,IAAI;AAAA,MAChB,sCAAsC,QAAQ,qCAAqC,OAAO,MAAM,CAAC;AAAA,IACnG;AACA,UAAM,OAAO;AACb,UAAM;AAAA,EACR;AACF;",
6
6
  "names": ["existsSync", "mkdirSync", "rmSync", "statSync", "existsSync", "existsSync", "existsSync", "statSync", "uri", "mkdirSync", "rmSync"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
  export { handler, type HandlerDeps, unwrapEvent } from "./handler.js";
25
25
  export { type AssembleEvent, type AssembleLambdaResult, type LambdaAction, type LambdaEvent, type LambdaResult, type PlanEvent, type PlanLambdaResult, type RenderChunkEvent, type RenderChunkLambdaResult, type SerializableDistributedRenderConfig, } from "./events.js";
26
- export { type ChromeSource, resolveChromeArgs, resolveChromeExecutablePath, resolveChromeSource, } from "./chromium.js";
26
+ export { ChromeBinaryUnavailableError, type ChromeSource, resolveChromeArgs, resolveChromeExecutablePath, resolveChromeSource, } from "./chromium.js";
27
27
  export { downloadS3ObjectToFile, formatS3Uri, parseS3Uri, type S3Location, tarDirectory, untarDirectory, uploadFileToS3, } from "./s3Transport.js";
28
28
  export { deploySite, type DeploySiteOptions, type SiteHandle } from "./sdk/deploySite.js";
29
29
  export { renderToLambda, type RenderHandle, type RenderToLambdaOptions, } from "./sdk/renderToLambda.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,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,KAAK,mCAAmC,GACzC,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,4BAA4B,EAC5B,KAAK,YAAY,EACjB,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,KAAK,UAAU,EACf,YAAY,EACZ,cAAc,EACd,cAAc,GACf,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,qBAAqB,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,sBAAsB,EAC3B,iBAAiB,EACjB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -11,6 +11,21 @@ import {
11
11
 
12
12
  // src/chromium.ts
13
13
  import { existsSync } from "node:fs";
14
+ var ChromeBinaryUnavailableError = class extends Error {
15
+ // Lambda's runtime serializes the error envelope's `errorType` from
16
+ // `err.name`; this class-field override sets it across the structured
17
+ // clone. Read indirectly; fallow can't follow.
18
+ // fallow-ignore-next-line unused-class-member
19
+ name = "ChromeBinaryUnavailableError";
20
+ source;
21
+ resolvedPath;
22
+ constructor(source, resolvedPath, hint) {
23
+ super(`[chromium] Chrome binary unavailable (source=${source}): ${hint}`);
24
+ this.source = source;
25
+ this.resolvedPath = resolvedPath;
26
+ }
27
+ };
28
+ var SPARTICUZ_WEDGE_HINT = "@sparticuz/chromium.executablePath() returned a falsy value or a path that doesn't exist on disk. This typically happens after a chunk hits `Sandbox.Timedout` mid-extraction and leaves /tmp in a wedged state \u2014 subsequent invocations land on the same warm instance and never re-extract. Recycle the function (e.g. `aws lambda update-function-configuration ... --environment ...` with a bumped marker var, or redeploy via `hyperframes lambda deploy --skip-build`) to force fresh execution environments. Tracking: investigate the upstream wedge so this auto-recovers.";
14
29
  function resolveChromeSource() {
15
30
  const raw = process.env.HYPERFRAMES_LAMBDA_CHROME_SOURCE?.toLowerCase();
16
31
  if (raw === "chrome-headless-shell" || raw === "shell") return "chrome-headless-shell";
@@ -20,17 +35,28 @@ async function resolveChromeExecutablePath() {
20
35
  const source = resolveChromeSource();
21
36
  if (source === "sparticuz") {
22
37
  const mod = await loadSparticuzChromium();
23
- return mod.executablePath();
38
+ const path = await mod.executablePath();
39
+ if (!path || typeof path !== "string") {
40
+ throw new ChromeBinaryUnavailableError(source, null, SPARTICUZ_WEDGE_HINT);
41
+ }
42
+ if (!existsSync(path)) {
43
+ throw new ChromeBinaryUnavailableError(source, path, SPARTICUZ_WEDGE_HINT);
44
+ }
45
+ return path;
24
46
  }
25
47
  const explicit = process.env.HYPERFRAMES_LAMBDA_CHROME_PATH;
26
48
  if (!explicit) {
27
- throw new Error(
28
- "[chromium] HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary."
49
+ throw new ChromeBinaryUnavailableError(
50
+ source,
51
+ null,
52
+ "HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary."
29
53
  );
30
54
  }
31
55
  if (!existsSync(explicit)) {
32
- throw new Error(
33
- `[chromium] HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist`
56
+ throw new ChromeBinaryUnavailableError(
57
+ source,
58
+ explicit,
59
+ `HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist on disk.`
34
60
  );
35
61
  }
36
62
  return explicit;
@@ -916,9 +942,35 @@ function summarizeHistory(events, memoryMb) {
916
942
  stateTransitions++;
917
943
  currentLambdaState = ev.stateEnteredEventDetails?.name ?? currentLambdaState;
918
944
  break;
945
+ // Optimized `lambda:invoke` task emits Task* events; raw
946
+ // `lambda:invokeFunction.sync` emits LambdaFunction*. Handle both.
947
+ case "TaskScheduled":
948
+ if (ev.taskScheduledEventDetails?.resourceType === "lambda") {
949
+ lambdasInvoked++;
950
+ }
951
+ break;
919
952
  case "LambdaFunctionScheduled":
920
953
  lambdasInvoked++;
921
954
  break;
955
+ case "TaskSucceeded": {
956
+ if (ev.taskSucceededEventDetails?.resourceType !== "lambda") break;
957
+ const wrapped = parseJson(ev.taskSucceededEventDetails?.output);
958
+ const payload = unwrapLambdaPayload(wrapped);
959
+ const billedDurationMs = inferBilledMs(payload);
960
+ lambdaInvocations.push({
961
+ billedDurationMs,
962
+ memorySizeMb: memoryMb,
963
+ estimated: billedDurationMs === 0
964
+ });
965
+ applyPayloadFrameCounts(payload, currentLambdaState, (delta) => {
966
+ framesRendered += delta;
967
+ });
968
+ if (payload && typeof payload === "object") {
969
+ const obj = payload;
970
+ if (typeof obj.TotalFrames === "number") totalFrames = obj.TotalFrames;
971
+ }
972
+ break;
973
+ }
922
974
  case "LambdaFunctionSucceeded": {
923
975
  const payload = parseJson(ev.lambdaFunctionSucceededEventDetails?.output);
924
976
  const billedDurationMs = inferBilledMs(payload);
@@ -927,14 +979,12 @@ function summarizeHistory(events, memoryMb) {
927
979
  memorySizeMb: memoryMb,
928
980
  estimated: billedDurationMs === 0
929
981
  });
982
+ applyPayloadFrameCounts(payload, currentLambdaState, (delta) => {
983
+ framesRendered += delta;
984
+ });
930
985
  if (payload && typeof payload === "object") {
931
986
  const obj = payload;
932
987
  if (typeof obj.TotalFrames === "number") totalFrames = obj.TotalFrames;
933
- if (typeof obj.FramesEncoded === "number") {
934
- if (currentLambdaState === "RenderChunk") {
935
- framesRendered += obj.FramesEncoded;
936
- }
937
- }
938
988
  }
939
989
  break;
940
990
  }
@@ -952,6 +1002,14 @@ function summarizeHistory(events, memoryMb) {
952
1002
  }
953
1003
  }
954
1004
  break;
1005
+ case "TaskFailed":
1006
+ if (ev.taskFailedEventDetails?.resourceType !== "lambda") break;
1007
+ errors.push({
1008
+ state: currentLambdaState ?? "<unknown>",
1009
+ error: ev.taskFailedEventDetails?.error ?? "UNKNOWN",
1010
+ cause: ev.taskFailedEventDetails?.cause ?? ""
1011
+ });
1012
+ break;
955
1013
  case "LambdaFunctionFailed":
956
1014
  errors.push({
957
1015
  state: currentLambdaState ?? "<unknown>",
@@ -1003,6 +1061,19 @@ function parseJson(s) {
1003
1061
  return null;
1004
1062
  }
1005
1063
  }
1064
+ function unwrapLambdaPayload(payload) {
1065
+ if (payload && typeof payload === "object" && "Payload" in payload) {
1066
+ const inner = payload.Payload;
1067
+ if (inner && typeof inner === "object") return inner;
1068
+ }
1069
+ return payload;
1070
+ }
1071
+ function applyPayloadFrameCounts(payload, currentLambdaState, bump) {
1072
+ if (currentLambdaState !== "RenderChunk") return;
1073
+ if (!payload || typeof payload !== "object") return;
1074
+ const obj = payload;
1075
+ if (typeof obj.FramesEncoded === "number") bump(obj.FramesEncoded);
1076
+ }
1006
1077
  function inferBilledMs(payload) {
1007
1078
  if (!payload || typeof payload !== "object") return 0;
1008
1079
  const obj = payload;
@@ -1025,6 +1096,7 @@ function isTerminalFailure(status) {
1025
1096
  return status === "FAILED" || status === "TIMED_OUT" || status === "ABORTED";
1026
1097
  }
1027
1098
  export {
1099
+ ChromeBinaryUnavailableError,
1028
1100
  InvalidConfigError,
1029
1101
  computeRenderCost,
1030
1102
  deploySite,