Image Pipeline Playground
feat(backend/models): define Pydantic schema for DAG node and edge data
Mohammad Rajaeic8faa5758127
diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.pyindex e69de29..6855fa8 100644--- a/backend/app/models/__init__.py+++ b/backend/app/models/__init__.py@@ -0,0 +1,27 @@+"""Public model exports."""++from app.models.graph import (+ Edge,+ ExecuteRequest,+ ExecutionEvent,+ ExecutionEventType,+ Graph,+ NodeInstance,+ NodeMetadata,+ ParamField,+ PortDirection,+ PortSpec,+)++__all__ = [+ "Edge",+ "ExecuteRequest",+ "ExecutionEvent",+ "ExecutionEventType",+ "Graph",+ "NodeInstance",+ "NodeMetadata",+ "ParamField",+ "PortDirection",+ "PortSpec",+]diff --git a/backend/app/models/graph.py b/backend/app/models/graph.pynew file mode 100644index 0000000..cfe902e--- /dev/null+++ b/backend/app/models/graph.py@@ -0,0 +1,90 @@+"""Pydantic schemas for DAG graph data and execution."""++from __future__ import annotations++from enum import Enum+from typing import Any++from pydantic import BaseModel, Field+++class PortDirection(str, Enum):+ INPUT = "input"+ OUTPUT = "output"+++class PortSpec(BaseModel):+ id: str+ name: str+ direction: PortDirection+ data_type: str = "image"+ multiple: bool = False+++class NodeInstance(BaseModel):+ id: str+ type: str+ params: dict[str, Any] = Field(default_factory=dict)+ position: dict[str, float] = Field(default_factory=lambda: {"x": 0.0, "y": 0.0})+++class Edge(BaseModel):+ id: str+ source: str+ source_port: str = "image"+ target: str+ target_port: str = "image"+++class Graph(BaseModel):+ nodes: list[NodeInstance] = Field(default_factory=list)+ edges: list[Edge] = Field(default_factory=list)+++class ExecuteRequest(BaseModel):+ graph: Graph+ seed: int = 0+ sample_count: int = 1+ cache: bool = True+++class ExecutionEventType(str, Enum):+ PROGRESS = "progress"+ PREVIEW = "preview"+ LOG = "log"+ ERROR = "error"+ DONE = "done"+ CANCELLED = "cancelled"+++class ExecutionEvent(BaseModel):+ type: ExecutionEventType+ node_id: str | None = None+ message: str | None = None+ progress: float | None = None+ image_b64: str | None = None+ sample_index: int | None = None+ cache_hit: bool | None = None+ data: dict[str, Any] | None = None+++class ParamField(BaseModel):+ name: str+ label: str+ type: str+ default: Any = None+ minimum: float | None = None+ maximum: float | None = None+ step: float | None = None+ options: list[str] | None = None+ description: str | None = None+++class NodeMetadata(BaseModel):+ type: str+ label: str+ category: str+ description: str = ""+ ports: list[PortSpec] = Field(default_factory=list)+ params: list[ParamField] = Field(default_factory=list)+ stochastic: bool = False