mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 06:30:03 +00:00
feat(cloud): default distributed plans to v2 (#3311)
* feat(cloud): default distributed plans to v2 * fix(cloud): address plan v2 review feedback * fix(examples): document explicit v2 samples
This commit is contained in:
@@ -46,13 +46,16 @@ import {
|
||||
import { resolveChromeExecutablePath } from "./chromium.js";
|
||||
import type {
|
||||
AssembleEvent,
|
||||
AssembleV2Event,
|
||||
AssembleResultBody,
|
||||
CloudRunAction,
|
||||
CloudRunEvent,
|
||||
CloudRunResult,
|
||||
PlanEvent,
|
||||
PlanV2Event,
|
||||
PlanResultBody,
|
||||
RenderChunkEvent,
|
||||
RenderChunkV2Event,
|
||||
RenderChunkResultBody,
|
||||
} from "./events.js";
|
||||
import { type DistributedFormat, formatExtension } from "./formatExtension.js";
|
||||
@@ -155,21 +158,22 @@ function validatePlanProtocolShape(event: PlanEvent | RenderChunkEvent | Assembl
|
||||
}
|
||||
if (event.Action === "plan") return;
|
||||
|
||||
const effectiveProtocol = protocol ?? "v2";
|
||||
const hasV1Locator = typeof raw.PlanGcsUri === "string";
|
||||
const hasV2Manifest = typeof raw.PlanV2ManifestGcsUri === "string";
|
||||
const hasV2Prefix = typeof raw.PlanV2ArtifactGcsPrefix === "string";
|
||||
const valid =
|
||||
protocol === "v2"
|
||||
effectiveProtocol === "v2"
|
||||
? !hasV1Locator && hasV2Manifest && hasV2Prefix
|
||||
: hasV1Locator && !hasV2Manifest && !hasV2Prefix;
|
||||
if (!valid) {
|
||||
const error = new Error(
|
||||
`[handler] ${protocol === "v2" ? "v2" : "v1"} ${event.Action} event has mixed or missing plan locators`,
|
||||
`[handler] ${effectiveProtocol} ${event.Action} event has mixed or missing plan locators`,
|
||||
);
|
||||
error.name = "PLAN_PROTOCOL_UNSUPPORTED";
|
||||
throw error;
|
||||
}
|
||||
if (protocol === "v2" && event.Action === "assemble" && event.AudioGcsUri !== null) {
|
||||
if (effectiveProtocol === "v2" && event.Action === "assemble" && event.AudioGcsUri !== null) {
|
||||
const error = new Error("[handler] v2 assemble audio must be materialized from the manifest");
|
||||
error.name = "PLAN_PROTOCOL_UNSUPPORTED";
|
||||
throw error;
|
||||
@@ -254,14 +258,14 @@ function summarizeEvent(
|
||||
return {
|
||||
projectGcsUri: event.ProjectGcsUri,
|
||||
planOutputGcsPrefix: event.PlanOutputGcsPrefix,
|
||||
planProtocol: event.PlanProtocol ?? "v1",
|
||||
planProtocol: event.PlanProtocol ?? "v2",
|
||||
format: event.Config.format,
|
||||
fps: event.Config.fps,
|
||||
};
|
||||
case "renderChunk":
|
||||
return {
|
||||
planProtocol: event.PlanProtocol ?? "v1",
|
||||
...(event.PlanProtocol === "v2"
|
||||
planProtocol: event.PlanProtocol ?? "v2",
|
||||
...(event.PlanProtocol !== "v1"
|
||||
? { planV2ManifestGcsUri: event.PlanV2ManifestGcsUri }
|
||||
: { planGcsUri: event.PlanGcsUri }),
|
||||
chunkIndex: event.ChunkIndex,
|
||||
@@ -269,8 +273,8 @@ function summarizeEvent(
|
||||
};
|
||||
case "assemble":
|
||||
return {
|
||||
planProtocol: event.PlanProtocol ?? "v1",
|
||||
...(event.PlanProtocol === "v2"
|
||||
planProtocol: event.PlanProtocol ?? "v2",
|
||||
...(event.PlanProtocol !== "v1"
|
||||
? { planV2ManifestGcsUri: event.PlanV2ManifestGcsUri }
|
||||
: { planGcsUri: event.PlanGcsUri }),
|
||||
chunkCount: event.ChunkGcsUris.length,
|
||||
@@ -297,7 +301,7 @@ function primeChrome(deps?: HandlerDeps): void {
|
||||
|
||||
// fallow-ignore-next-line complexity
|
||||
async function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanResultBody> {
|
||||
if (event.PlanProtocol === "v2") {
|
||||
if (event.PlanProtocol !== "v1") {
|
||||
return handlePlanV2(event, deps);
|
||||
}
|
||||
const started = Date.now();
|
||||
@@ -365,7 +369,7 @@ async function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanRes
|
||||
*/
|
||||
// fallow-ignore-next-line complexity
|
||||
async function handlePlanV2(
|
||||
event: Extract<PlanEvent, { PlanProtocol: "v2" }>,
|
||||
event: PlanV2Event,
|
||||
deps?: HandlerDeps,
|
||||
): Promise<Extract<PlanResultBody, { PlanProtocol: "v2" }>> {
|
||||
const started = Date.now();
|
||||
@@ -418,7 +422,7 @@ async function handleRenderChunk(
|
||||
event: RenderChunkEvent,
|
||||
deps?: HandlerDeps,
|
||||
): Promise<RenderChunkResultBody> {
|
||||
if (event.PlanProtocol === "v2") {
|
||||
if (event.PlanProtocol !== "v1") {
|
||||
return handleRenderChunkV2(event, deps);
|
||||
}
|
||||
const started = Date.now();
|
||||
@@ -475,7 +479,7 @@ async function handleRenderChunk(
|
||||
/** Materialize only this chunk's verified v2 dependencies before rendering. */
|
||||
// fallow-ignore-next-line complexity
|
||||
async function handleRenderChunkV2(
|
||||
event: Extract<RenderChunkEvent, { PlanProtocol: "v2" }>,
|
||||
event: RenderChunkV2Event,
|
||||
deps?: HandlerDeps,
|
||||
): Promise<RenderChunkResultBody> {
|
||||
const started = Date.now();
|
||||
@@ -548,7 +552,7 @@ async function handleAssemble(
|
||||
event: AssembleEvent,
|
||||
deps?: HandlerDeps,
|
||||
): Promise<AssembleResultBody> {
|
||||
if (event.PlanProtocol === "v2") {
|
||||
if (event.PlanProtocol !== "v1") {
|
||||
return handleAssembleV2(event, deps);
|
||||
}
|
||||
const started = Date.now();
|
||||
@@ -613,7 +617,7 @@ async function handleAssemble(
|
||||
*/
|
||||
// fallow-ignore-next-line complexity
|
||||
async function handleAssembleV2(
|
||||
event: Extract<AssembleEvent, { PlanProtocol: "v2" }>,
|
||||
event: AssembleV2Event,
|
||||
deps?: HandlerDeps,
|
||||
): Promise<AssembleResultBody> {
|
||||
const started = Date.now();
|
||||
@@ -781,12 +785,12 @@ function getEventGcsUris(event: PlanEvent | RenderChunkEvent | AssembleEvent): s
|
||||
case "plan":
|
||||
return [event.ProjectGcsUri, event.PlanOutputGcsPrefix];
|
||||
case "renderChunk":
|
||||
return event.PlanProtocol === "v2"
|
||||
return event.PlanProtocol !== "v1"
|
||||
? [event.PlanV2ManifestGcsUri, event.PlanV2ArtifactGcsPrefix, event.ChunkOutputGcsPrefix]
|
||||
: [event.PlanGcsUri, event.ChunkOutputGcsPrefix];
|
||||
case "assemble":
|
||||
return [
|
||||
...(event.PlanProtocol === "v2"
|
||||
...(event.PlanProtocol !== "v1"
|
||||
? [event.PlanV2ManifestGcsUri, event.PlanV2ArtifactGcsPrefix]
|
||||
: [event.PlanGcsUri]),
|
||||
...event.ChunkGcsUris,
|
||||
|
||||
Reference in New Issue
Block a user