MCPcopy Index your code
hub / github.com/heygen-com/hyperframes / handler

Function handler

packages/aws-lambda/src/handler.ts:84–124  ·  view source on GitHub ↗
(event: LambdaEvent, deps?: HandlerDeps)

Source from the content-addressed store, hash-verified

82 * shape; unwrap until we hit a discriminated event.
83 */
84export async function handler(event: LambdaEvent, deps?: HandlerDeps): Promise<LambdaResult> {
85 const unwrapped = unwrapEvent(event);
86 validateEventS3Uris(unwrapped);
87 primeRuntimeEnv();
88 // Single structured boot log line — CloudWatch Logs Insights queries
89 // key off `event=handler_start` to grep for a specific Action / S3 URI
90 // when triaging without attaching a debugger.
91 logEvent({ event: "handler_start", action: unwrapped.Action, input: summarizeEvent(unwrapped) });
92 try {
93 switch (unwrapped.Action) {
94 case "plan":
95 return await handlePlan(unwrapped, deps);
96 case "renderChunk":
97 return await handleRenderChunk(unwrapped, deps);
98 case "assemble":
99 return await handleAssemble(unwrapped, deps);
100 default: {
101 // Compile-time exhaustiveness: a new LambdaAction member trips
102 // the `never` assignment before the runtime error is reachable.
103 const _exhaustive: never = unwrapped;
104 throw new Error(
105 `[handler] unknown Action: ${JSON.stringify(
106 (_exhaustive as { Action?: string }).Action,
107 )}. Expected one of "plan", "renderChunk", "assemble".`,
108 );
109 }
110 }
111 } catch (err) {
112 // Log before re-throwing so CloudWatch captures the structured
113 // error context alongside Lambda's default stack trace. Otherwise
114 // ops only sees the trace and has to correlate with execution
115 // history to recover the action + input.
116 logEvent({
117 event: "handler_error",
118 action: unwrapped.Action,
119 message: err instanceof Error ? err.message : String(err),
120 name: err instanceof Error ? err.name : undefined,
121 });
122 throw err;
123 }
124}
125
126/**
127 * Walk through Step Functions' Map-state and Task-state envelopes until

Callers 2

runLambdaLocalRenderFunction · 0.90
handler.test.tsFile · 0.70

Calls 8

validateEventS3UrisFunction · 0.85
primeRuntimeEnvFunction · 0.85
unwrapEventFunction · 0.70
logEventFunction · 0.70
summarizeEventFunction · 0.70
handlePlanFunction · 0.70
handleRenderChunkFunction · 0.70
handleAssembleFunction · 0.70

Tested by

no test coverage detected