astrbot_plugin_imagestudio/backend/dto/workflow_dto.py

123 行
3.3 KiB
Python

"""Workflow and node DTOs."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
@dataclass(frozen=True)
class ProfileWorkflow:
workflow_id: str
profile_id: str
workflow_type: str
display_name: str
mode: str | None
status: str
current_node_id: str | None
current_branch: str
session_key: str | None
metadata: dict[str, Any]
created_at: str
updated_at: str
def to_dict(self) -> dict[str, Any]:
return {
"workflow_id": self.workflow_id,
"profile_id": self.profile_id,
"workflow_type": self.workflow_type,
"display_name": self.display_name,
"mode": self.mode,
"status": self.status,
"current_node_id": self.current_node_id,
"current_branch": self.current_branch,
"session_key": self.session_key,
"metadata": self.metadata,
"created_at": self.created_at,
"updated_at": self.updated_at,
}
@dataclass(frozen=True)
class WorkflowNode:
node_id: str
workflow_id: str
node_key: str
title: str
description: str | None
step_name: str | None
node_type: str
status: str
branch_name: str
prompt: str | None
negative_prompt: str | None
model_route: str | None
selected_image_id: str | None
sort_order: int
metadata: dict[str, Any]
created_at: str
updated_at: str
def to_dict(self) -> dict[str, Any]:
return {
"node_id": self.node_id,
"workflow_id": self.workflow_id,
"node_key": self.node_key,
"title": self.title,
"description": self.description,
"step_name": self.step_name,
"node_type": self.node_type,
"status": self.status,
"branch_name": self.branch_name,
"prompt": self.prompt,
"negative_prompt": self.negative_prompt,
"model_route": self.model_route,
"selected_image_id": self.selected_image_id,
"sort_order": self.sort_order,
"metadata": self.metadata,
"created_at": self.created_at,
"updated_at": self.updated_at,
}
@dataclass(frozen=True)
class WorkflowDetail:
workflow: ProfileWorkflow
nodes: list[WorkflowNode]
def to_dict(self) -> dict[str, Any]:
return {
"workflow": self.workflow.to_dict(),
"nodes": [node.to_dict() for node in self.nodes],
}
2026-07-05 09:39:17 +08:00
@dataclass(frozen=True)
class WorkflowHistoryEntry:
history_id: str
profile_id: str | None
workflow_id: str
node_id: str | None
image_id: str | None
branch_name: str
action: str
title: str | None
prompt: str | None
metadata: dict[str, Any]
created_at: str
def to_dict(self) -> dict[str, Any]:
return {
"history_id": self.history_id,
"profile_id": self.profile_id,
"workflow_id": self.workflow_id,
"node_id": self.node_id,
"image_id": self.image_id,
"branch_name": self.branch_name,
"action": self.action,
"title": self.title,
"prompt": self.prompt,
"metadata": self.metadata,
"created_at": self.created_at,
}