astrbot_plugin_imagestudio/backend/dto/workflow_round_dto.py

149 行
4.5 KiB
Python

"""DTOs for workflow generation rounds and their stable candidate pools."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
@dataclass(frozen=True)
class WorkflowGenerationRound:
round_id: str
workflow_id: str
node_id: str
branch_name: str
round_kind: str
round_number: int
display_code: str
parent_round_id: str | None
status: str
requested_count: int
idempotency_key: str | None
prompt_snapshot: dict[str, Any]
reference_snapshot: dict[str, Any]
feedback_snapshot: dict[str, Any]
metadata: dict[str, Any]
created_at: str
updated_at: str
def to_dict(self) -> dict[str, Any]:
return {
"round_id": self.round_id,
"workflow_id": self.workflow_id,
"node_id": self.node_id,
"branch_name": self.branch_name,
"round_kind": self.round_kind,
"round_number": self.round_number,
"display_code": self.display_code,
"parent_round_id": self.parent_round_id,
"status": self.status,
"requested_count": self.requested_count,
"idempotency_key": self.idempotency_key,
"prompt_snapshot": self.prompt_snapshot,
"reference_snapshot": self.reference_snapshot,
"feedback_snapshot": self.feedback_snapshot,
"metadata": self.metadata,
"created_at": self.created_at,
"updated_at": self.updated_at,
}
@dataclass(frozen=True)
class WorkflowGenerationCandidate:
candidate_id: str
origin_round_id: str
candidate_index: int
generation_status: str
image_id: str | None
current_task_id: str | None
source_candidate_id: str | None
model_route: str | None
provider_id: str | None
provider_model: str | None
prompt_snapshot: dict[str, Any]
failure: dict[str, Any]
metadata: dict[str, Any]
created_at: str
updated_at: str
def to_dict(self) -> dict[str, Any]:
return {
"candidate_id": self.candidate_id,
"origin_round_id": self.origin_round_id,
"candidate_index": self.candidate_index,
"generation_status": self.generation_status,
"image_id": self.image_id,
"current_task_id": self.current_task_id,
"source_candidate_id": self.source_candidate_id,
"model_route": self.model_route,
"provider_id": self.provider_id,
"provider_model": self.provider_model,
"prompt_snapshot": self.prompt_snapshot,
"failure": self.failure,
"metadata": self.metadata,
"created_at": self.created_at,
"updated_at": self.updated_at,
}
@dataclass(frozen=True)
class WorkflowRoundCandidatePoolEntry:
round_id: str
candidate_id: str
display_index: int
display_code: str
pool_state: str
preference_status: str
preference_reason: str | None
is_final: bool
metadata: dict[str, Any]
created_at: str
updated_at: str
def to_dict(self) -> dict[str, Any]:
return {
"round_id": self.round_id,
"candidate_id": self.candidate_id,
"display_index": self.display_index,
"display_code": self.display_code,
"pool_state": self.pool_state,
"preference_status": self.preference_status,
"preference_reason": self.preference_reason,
"is_final": self.is_final,
"metadata": self.metadata,
"created_at": self.created_at,
"updated_at": self.updated_at,
}
@dataclass(frozen=True)
class WorkflowRoundCandidateView:
pool: WorkflowRoundCandidatePoolEntry
candidate: WorkflowGenerationCandidate
image: dict[str, Any] | None = None
task: dict[str, Any] | None = None
def to_dict(self) -> dict[str, Any]:
return {
**self.pool.to_dict(),
"candidate": self.candidate.to_dict(),
"image": self.image,
"task": self.task,
}
@dataclass(frozen=True)
class WorkflowGenerationRoundDetail:
round_record: WorkflowGenerationRound
candidates: tuple[WorkflowRoundCandidateView, ...]
read_only: bool = False
legacy: bool = False
def to_dict(self) -> dict[str, Any]:
return {
"round": self.round_record.to_dict(),
"candidates": [candidate.to_dict() for candidate in self.candidates],
"read_only": self.read_only,
"legacy": self.legacy,
}