cmvr-visual/backend/app/schemas/editors.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

120 lines
4.0 KiB
Python

"""编辑结构验证独立于时间线可执行性,越界草稿必须可以保存。"""
from typing import Literal
from pydantic import Field, model_validator, field_validator
from app.domain.timeline import Strict, Audio
from app.domain.stories import ID
class Binding(Strict):
asset_id: str = Field(min_length=1, max_length=64)
sha256: str | None = Field(default=None, pattern=r"^[0-9a-f]{64}$")
kind: Literal["image", "video", "audio", "text", "json"]
input_hash: str | None = None
context_hash: str | None = None
source: Literal["generated", "manual", "reused"]
locked: bool = False
source_run_id: str | None = None
source_job_id: str | None = None
generation_parameters: dict | None = None
duration_seconds: float | None = Field(default=None, ge=0, allow_inf_nan=False)
duration_frames: int | None = Field(default=None, ge=0)
sample_count: int | None = Field(default=None, ge=0)
class AudioSegment(Strict):
id: str = Field(pattern=ID)
shot_id: str = Field(pattern=ID)
text: str = Field(max_length=2000)
voice: str | None = None
speed: float | None = Field(default=None, ge=0.5, le=2, allow_inf_nan=False)
class EditorAudio(Strict):
mode: Literal["silent", "manual_track", "generated_narration"] = "silent"
voice: str = ""
speed: float = Field(default=1.0, ge=0.5, le=2, allow_inf_nan=False)
track: Audio | None = None
segments: list[AudioSegment] = Field(default_factory=list, max_length=1000)
class Cue(Strict):
id: str = Field(pattern=ID)
anchor: Literal["absolute", "shot", "audio_segment"]
shot_id: str | None = Field(default=None, pattern=ID)
segment_id: str | None = Field(default=None, pattern=ID)
start_frame: int
end_frame: int
text: str = Field(max_length=2000)
text_override: bool = False
timing_override: bool = False
@model_validator(mode="after")
def anchor_fields(self):
if (
self.anchor == "absolute"
and (self.shot_id or self.segment_id)
or self.anchor == "shot"
and (not self.shot_id or self.segment_id)
or self.anchor == "audio_segment"
and (not self.segment_id or self.shot_id)
):
raise ValueError("anchor fields are mutually exclusive")
return self
class EditorCaptions(Strict):
mode: Literal["none", "manual", "script", "ai_script"] = "none"
cues: list[Cue] = Field(default_factory=list, max_length=1000)
class EditorManifest(Strict):
editing_mode: Literal["auto", "manual"] = "auto"
base_run_id: str | None = Field(default=None, pattern=ID)
schema_version: Literal[1] = 1
source_kind: Literal["story", "workflow"]
spec: dict
shot_ids: list[str] = Field(min_length=1, max_length=1000)
bindings: dict[str, Binding] = Field(default_factory=dict, max_length=3000)
audio: EditorAudio = Field(default_factory=EditorAudio)
captions: EditorCaptions = Field(default_factory=EditorCaptions)
class SaveEditor(Strict):
expected_version: int = Field(ge=1)
manifest: EditorManifest
name: str | None = Field(default=None, min_length=1, max_length=255)
@field_validator("name")
@classmethod
def normalized_name(cls, value):
if value is None:
return None
value = value.strip()
if not value:
raise ValueError("name must not be blank")
return value
class RestoreEditor(Strict):
expected_version: int = Field(ge=1)
run_id: str = Field(min_length=1, max_length=32)
class PlanEditor(Strict):
expected_version: int = Field(ge=1)
output_goal: Literal["media", "film"] = "film"
targets: list[str] = Field(default_factory=list, max_length=3002)
force: list[str] = Field(default_factory=list, max_length=3002)
execution_mode: Literal["interactive", "batch"] = "interactive"
output_folder_id: str | None = None
class StartEditor(PlanEditor):
expected_plan_hash: str = Field(pattern=r"^[0-9a-f]{64}$")
class EditorMode(Strict):
expected_version: int = Field(ge=1)
mode: Literal["auto", "manual"]