feat(producer): export distributed render primitives

This commit is contained in:
James
2026-05-14 03:40:44 +00:00
parent b47a3e798b
commit 91a91f66ba
6 changed files with 225 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
/**
* `@hyperframes/producer/distributed` — the distributed render primitives.
*
* See `DISTRIBUTED-RENDERING-PLAN.md` for the full architecture. The three
* activities (`plan` → `renderChunk` × N → `assemble`) are pure functions
* over local file paths; networking + orchestration live in adapters.
*
* Adopters (AWS Lambda, Cloud Run Jobs, Temporal, K8s Jobs, plain SSH):
*
* ```ts
* import {
* plan,
* renderChunk,
* assemble,
* } from "@hyperframes/producer/distributed";
*
* // Controller-side: produce a self-contained planDir + content-addressed planHash.
* const planResult = await plan(projectDir, config, planDir);
*
* // Worker-side: render one chunk. Byte-identical retries on the same
* // (planDir, chunkIndex) — Temporal / Step Functions retry policies are
* // safe to point at this.
* const chunk = await renderChunk(planDir, chunkIndex, outputChunkPath);
*
* // Controller-side: stitch chunks into the final deliverable.
* await assemble(planDir, chunkPaths, audioPath, outputPath);
* ```
*
* No networking, no AWS SDK, no Temporal SDK — those live in adapter
* packages. This module is library code only.
*/
// ── Plan (Activity A) ───────────────────────────────────────────────────────
export {
// Functions
buildChunkSlices,
measurePlanDirBytes,
plan,
rejectUnsupportedDistributedFormat,
resolveChunkPlan,
// Types
type DistributedRenderConfig,
type PlanResult,
// Constants
DEFAULT_CHUNK_SIZE,
DEFAULT_MAX_PARALLEL_CHUNKS,
PLAN_DIR_SIZE_LIMIT_BYTES,
// Error codes + classes
FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED,
FormatNotSupportedInDistributedError,
PLAN_TOO_LARGE,
PlanTooLargeError,
} from "./services/distributed/plan.js";
// ── RenderChunk (Activity B) ────────────────────────────────────────────────
export {
applyRuntimeEnvSnapshot,
readWebGlVendorInfoFromCanvas,
renderChunk,
// Types
type ChunkResult,
// Error codes + classes
FFMPEG_VERSION_MISMATCH,
PLAN_HASH_MISMATCH,
RenderChunkValidationError,
} from "./services/distributed/renderChunk.js";
// ── Assemble (Activity C) ───────────────────────────────────────────────────
export { assemble, type AssembleResult } from "./services/distributed/assemble.js";
// ── Plan-time shared types from `freezePlan` ───────────────────────────────
// Re-exported so adopters that deserialize a planDir's `meta/encoder.json`
// or `meta/chunks.json` see the same shapes the producer wrote them as.
export type {
ChunkSliceJson,
CompositionMetadataJson,
LockedRenderConfig,
} from "./services/render/stages/freezePlan.js";