UNPKG

@clipwhisperer/common

Version:

ClipWhisperer Common - Shared library providing core utilities, database schemas, authentication, bucket management, and common functionality across all ClipWhisperer microservices

126 lines (125 loc) 5.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.workflowStatusSchema = exports.rendererResponseSchema = exports.hubToRendererRequestSchema = exports.hubToNarratorRequestSchema = exports.narratorResponseSchema = exports.speechMarkSchema = void 0; const zod_1 = require("zod"); /** * Speech Mark Schema - represents precise word timing from AWS Polly */ exports.speechMarkSchema = zod_1.z.object({ time: zod_1.z.number().describe("Start time in seconds"), type: zod_1.z.enum(["word", "sentence", "ssml"]).describe("Type of speech mark"), start: zod_1.z.number().describe("Character start position in text"), end: zod_1.z.number().describe("Character end position in text"), value: zod_1.z.string().describe("The actual word/text"), }); /** * Narrator Service Response Schema */ exports.narratorResponseSchema = zod_1.z.object({ audioId: zod_1.z.string().describe("Unique identifier for the audio file"), audioUrl: zod_1.z.string().describe("URL/path to the generated audio file"), speechMarks: zod_1.z.array(exports.speechMarkSchema).describe("Array of speech marks with timing"), duration: zod_1.z.number().describe("Total audio duration in seconds"), wordCount: zod_1.z.number().describe("Number of words in the text"), metadata: zod_1.z.object({ voiceId: zod_1.z.string().describe("AWS Polly voice used"), engine: zod_1.z.string().describe("AWS Polly engine used"), outputFormat: zod_1.z.string().describe("Audio output format"), fileSize: zod_1.z.number().describe("Audio file size in bytes"), }), }); /** * Hub to Narrator Request Schema */ exports.hubToNarratorRequestSchema = zod_1.z.object({ text: zod_1.z.string().min(1).describe("Text to synthesize"), voiceId: zod_1.z.string().optional().default("Matthew").describe("AWS Polly voice ID"), engine: zod_1.z.string().optional().default("generative").describe("AWS Polly engine"), outputFormat: zod_1.z.string().optional().default("mp3").describe("Audio output format"), metadata: zod_1.z.object({ videoId: zod_1.z.string().describe("Associated video ID"), requestId: zod_1.z.string().describe("Hub request ID for tracking"), }), }); /** * Hub to Renderer Request Schema */ exports.hubToRendererRequestSchema = zod_1.z.object({ videoId: zod_1.z.string().describe("Unique video identifier"), audioUrl: zod_1.z.string().describe("URL to the audio file from Narrator"), speechMarks: zod_1.z.array(exports.speechMarkSchema).describe("Precise word timings from Narrator"), backgroundVideoPath: zod_1.z.string().optional().describe("Path to background video"), config: zod_1.z.object({ fontSize: zod_1.z.number().optional().default(48), fontColor: zod_1.z.string().optional().default("white"), fontFamily: zod_1.z.string().optional().default("Arial"), backgroundColor: zod_1.z.string().optional().default("black@0.7"), wordsPerGroup: zod_1.z.number().optional().default(2).describe("Words to display simultaneously"), minimumDisplayTime: zod_1.z.number().optional().default(1.0).describe("Minimum seconds each text group is shown"), }).optional(), metadata: zod_1.z.object({ requestId: zod_1.z.string().describe("Hub request ID for tracking"), narratorAudioId: zod_1.z.string().describe("Audio ID from Narrator service"), }), }); /** * Renderer Response Schema */ exports.rendererResponseSchema = zod_1.z.object({ videoId: zod_1.z.string().describe("Video identifier"), outputPath: zod_1.z.string().describe("Path to the rendered video"), duration: zod_1.z.number().describe("Video duration in seconds"), fileSize: zod_1.z.number().describe("Video file size in bytes"), wordTimings: zod_1.z.array(zod_1.z.object({ word: zod_1.z.string(), startTime: zod_1.z.number(), endTime: zod_1.z.number(), })).describe("Final word timings used in the video"), metadata: zod_1.z.object({ renderTime: zod_1.z.number().describe("Time taken to render in seconds"), audioSource: zod_1.z.string().describe("Source audio URL"), speechMarksCount: zod_1.z.number().describe("Number of speech marks processed"), }), }); /** * Complete Workflow Status Schema */ exports.workflowStatusSchema = zod_1.z.object({ videoId: zod_1.z.string(), status: zod_1.z.enum([ "pending", "scraping", "scrape_complete", "narrating", "narration_complete", "rendering", "render_complete", "completed", "failed" ]), progress: zod_1.z.number().min(0).max(100).describe("Progress percentage"), currentStep: zod_1.z.string().describe("Current processing step"), steps: zod_1.z.object({ scraping: zod_1.z.object({ status: zod_1.z.enum(["pending", "in_progress", "completed", "failed"]), startTime: zod_1.z.date().optional(), endTime: zod_1.z.date().optional(), data: zod_1.z.any().optional(), }), narration: zod_1.z.object({ status: zod_1.z.enum(["pending", "in_progress", "completed", "failed"]), startTime: zod_1.z.date().optional(), endTime: zod_1.z.date().optional(), data: exports.narratorResponseSchema.optional(), }), rendering: zod_1.z.object({ status: zod_1.z.enum(["pending", "in_progress", "completed", "failed"]), startTime: zod_1.z.date().optional(), endTime: zod_1.z.date().optional(), data: exports.rendererResponseSchema.optional(), }), }), error: zod_1.z.string().optional(), createdAt: zod_1.z.date(), updatedAt: zod_1.z.date(), });