feat: wire character workflow branch locking
这个提交存在于:
父节点
4a53e38555
当前提交
b61c6274e5
共有 28 个文件被更改,包括 4921 次插入 和 264 次删除
2
.gitignore
Vendored
2
.gitignore
Vendored
|
|
@ -6,6 +6,7 @@ __pycache__/
|
|||
.mypy_cache/
|
||||
.venv/
|
||||
venv/
|
||||
pytest-cache-files-*/
|
||||
|
||||
# Node / frontend
|
||||
node_modules/
|
||||
|
|
@ -32,6 +33,7 @@ data/exports/*
|
|||
!data/exports/.gitkeep
|
||||
|
||||
# Local machine/editor noise
|
||||
.tmp/
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ ROUTES: tuple[RouteSpec, ...] = (
|
|||
RouteSpec("POST", "workflows/{workflow_id}/branches", "backend.routes.branch_routes.create_workflow_branch", "write"),
|
||||
RouteSpec("POST", "workflows/{workflow_id}/switch-branch", "backend.routes.branch_routes.switch_workflow_branch", "write"),
|
||||
RouteSpec("GET", "workflows/{workflow_id}/history", "backend.routes.history_routes.list_workflow_history", "read"),
|
||||
RouteSpec("POST", "workflows/{workflow_id}/history", "backend.routes.history_routes.save_workflow_history", "write"),
|
||||
RouteSpec("GET", "nodes/{node_id}", "backend.routes.node_routes.get_node", "read"),
|
||||
RouteSpec("GET", "nodes/{node_id}/dependency-context", "backend.routes.node_routes.get_node_dependency_context", "read"),
|
||||
RouteSpec("PUT", "nodes/{node_id}", "backend.routes.node_routes.update_node", "write"),
|
||||
|
|
|
|||
|
|
@ -49,6 +49,21 @@ def list_workflow_history(
|
|||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def save_workflow_history(
|
||||
ctx: RequestContext,
|
||||
workflow_id: str,
|
||||
payload: dict[str, Any],
|
||||
service: HistoryService | None = None,
|
||||
) -> dict:
|
||||
history_service = service or _create_history_service()
|
||||
|
||||
def action() -> dict[str, Any]:
|
||||
require_write(ctx)
|
||||
return history_service.save_workflow_snapshot(workflow_id, payload, ctx).to_dict()
|
||||
|
||||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def _create_history_service() -> HistoryService:
|
||||
database = Database(load_database_settings())
|
||||
audit_service = AuditService(database)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from database.repositories.job_repository import JobRepository
|
|||
from database.repositories.model_provider_repository import ModelProviderRepository
|
||||
from database.repositories.profile_repository import ProfileRepository
|
||||
from database.repositories.workflow_repository import WorkflowRepository
|
||||
from engines.single_flow import SingleFlowEngine
|
||||
|
||||
|
||||
def list_workflow_nodes(
|
||||
|
|
|
|||
|
|
@ -5,13 +5,16 @@ from __future__ import annotations
|
|||
from typing import Any
|
||||
|
||||
from backend.routes.common import handle_request
|
||||
from backend.services.event_stream_service import get_default_event_bus
|
||||
from backend.services.profile_service import ProfileService
|
||||
from backend.services.quick_profile_service import QuickProfileService
|
||||
from backend.services.workflow_service import WorkflowService
|
||||
from core.audit_service import AuditService
|
||||
from core.identity import RequestContext
|
||||
from core.security import require_authenticated, require_write
|
||||
from database.db_helper import Database, load_database_settings
|
||||
from database.repositories.profile_repository import ProfileRepository
|
||||
from database.repositories.workflow_repository import WorkflowRepository
|
||||
|
||||
|
||||
def list_profiles(
|
||||
|
|
@ -120,25 +123,39 @@ def save_quick_profile_draft(
|
|||
payload: dict[str, Any],
|
||||
service: QuickProfileService | None = None,
|
||||
profile_service: ProfileService | None = None,
|
||||
workflow_service: WorkflowService | None = None,
|
||||
) -> dict:
|
||||
quick_service = service or QuickProfileService()
|
||||
resolved_profile_service = profile_service or _create_profile_service()
|
||||
resolved_workflow_service = workflow_service or _create_workflow_service(
|
||||
resolved_profile_service.repository.database
|
||||
)
|
||||
|
||||
def action() -> dict:
|
||||
require_write(ctx)
|
||||
return quick_service.save_draft(payload, resolved_profile_service, ctx)
|
||||
return quick_service.save_draft(payload, resolved_profile_service, ctx, resolved_workflow_service)
|
||||
|
||||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def _create_profile_service() -> ProfileService:
|
||||
database = Database(load_database_settings())
|
||||
def _create_profile_service(database: Database | None = None) -> ProfileService:
|
||||
database = database or Database(load_database_settings())
|
||||
return ProfileService(
|
||||
repository=ProfileRepository(database),
|
||||
audit_service=AuditService(database),
|
||||
)
|
||||
|
||||
|
||||
def _create_workflow_service(database: Database | None = None) -> WorkflowService:
|
||||
database = database or Database(load_database_settings())
|
||||
return WorkflowService(
|
||||
workflow_repository=WorkflowRepository(database),
|
||||
profile_repository=ProfileRepository(database),
|
||||
audit_service=AuditService(database),
|
||||
event_bus=get_default_event_bus(),
|
||||
)
|
||||
|
||||
|
||||
def _optional_str(value: Any) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from backend.services.workflow_service import WorkflowService
|
|||
from core.identity import RequestContext
|
||||
|
||||
|
||||
CHARACTER_WORKFLOW_TYPES = {"character_fast", "character_gradual"}
|
||||
CHARACTER_WORKFLOW_TYPES = {"character_fast", "character_gradual", "quick_profile"}
|
||||
|
||||
|
||||
class CharacterWorkflowService:
|
||||
|
|
@ -38,7 +38,7 @@ class CharacterWorkflowService:
|
|||
if not active_nodes:
|
||||
raise ApiError(ErrorCode.VALIDATION_FAILED, "workflow has no executable nodes", {"workflow_id": workflow_id})
|
||||
running_workflow = workflow
|
||||
if workflow.status != "running":
|
||||
if workflow.status not in {"running", "completed"}:
|
||||
running_workflow = self.workflow_service.update_workflow(workflow_id, {"status": "running"}, ctx)
|
||||
completed_nodes: list[WorkflowNode] = []
|
||||
prompt_context: list[str] = []
|
||||
|
|
@ -111,6 +111,10 @@ def _negative_prompt(profile: CharacterProfile, node: WorkflowNode) -> str:
|
|||
|
||||
|
||||
def _step_instruction(workflow_type: str, node_key: str) -> str:
|
||||
quick_profile = {
|
||||
"questionnaire": "normalized questionnaire and quick profile archive input",
|
||||
"preview": "saved quick profile prompts ready for structured setting split",
|
||||
}
|
||||
fast = {
|
||||
"fast_profile": "condensed character design brief",
|
||||
"fast_candidates": "candidate batch, varied composition, keep identity consistent",
|
||||
|
|
@ -126,7 +130,12 @@ def _step_instruction(workflow_type: str, node_key: str) -> str:
|
|||
"style_lock": "style consistency lock and final rendering rules",
|
||||
"final_pack": "final character pack, accepted images and reusable metadata",
|
||||
}
|
||||
table = fast if workflow_type == "character_fast" else gradual
|
||||
tables = {
|
||||
"character_fast": fast,
|
||||
"character_gradual": gradual,
|
||||
"quick_profile": quick_profile,
|
||||
}
|
||||
table = tables.get(workflow_type, {})
|
||||
return table.get(node_key, node_key.replace("_", " "))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,11 @@ from backend.services.image_service import ImageService
|
|||
from backend.services.model_provider_service import ModelProviderService
|
||||
from backend.services.prompt_expansion_service import PromptExpansionService
|
||||
from backend.services.queue_service import QueueService
|
||||
from backend.services.workflow_service import WorkflowService
|
||||
from backend.services.workflow_service import (
|
||||
LOCKED_NODE_STATUSES,
|
||||
WorkflowService,
|
||||
locked_node_edit_error,
|
||||
)
|
||||
from core.event_bus import EventBus
|
||||
from core.identity import RequestContext
|
||||
from engines.single_flow import SingleFlowEngine
|
||||
|
|
@ -40,6 +44,23 @@ class GenerationService:
|
|||
|
||||
def generate_node(self, node_id: str, payload: dict[str, Any], ctx: RequestContext) -> dict[str, Any]:
|
||||
node = self.workflow_service.get_node(node_id)
|
||||
idempotency_key = _optional_text(payload.get("idempotency_key"))
|
||||
if idempotency_key:
|
||||
existing_task = self.queue_service.get_job_by_idempotency_key(idempotency_key)
|
||||
if existing_task is not None:
|
||||
if existing_task.node_id != node_id:
|
||||
raise ApiError(
|
||||
ErrorCode.VALIDATION_FAILED,
|
||||
"idempotency_key belongs to another node",
|
||||
{
|
||||
"idempotency_key": idempotency_key,
|
||||
"node_id": node_id,
|
||||
"existing_node_id": existing_task.node_id,
|
||||
},
|
||||
)
|
||||
return self._existing_generation_response(existing_task, node_id)
|
||||
if node.status in LOCKED_NODE_STATUSES:
|
||||
raise locked_node_edit_error(node)
|
||||
workflow = self.workflow_service.get_workflow(node.workflow_id).workflow
|
||||
model_route = str(payload.get("model_route") or node.model_route or "image_low")
|
||||
route_resolution = self._resolve_model_route(model_route)
|
||||
|
|
@ -60,21 +81,6 @@ class GenerationService:
|
|||
else {}
|
||||
),
|
||||
}
|
||||
idempotency_key = _optional_text(payload.get("idempotency_key"))
|
||||
if idempotency_key:
|
||||
existing_task = self.queue_service.get_job_by_idempotency_key(idempotency_key)
|
||||
if existing_task is not None:
|
||||
if existing_task.node_id != node_id:
|
||||
raise ApiError(
|
||||
ErrorCode.VALIDATION_FAILED,
|
||||
"idempotency_key belongs to another node",
|
||||
{
|
||||
"idempotency_key": idempotency_key,
|
||||
"node_id": node_id,
|
||||
"existing_node_id": existing_task.node_id,
|
||||
},
|
||||
)
|
||||
return self._existing_generation_response(existing_task, node_id)
|
||||
task = self.queue_service.create_task(
|
||||
{
|
||||
"profile_id": workflow.profile_id,
|
||||
|
|
|
|||
|
|
@ -97,6 +97,59 @@ class HistoryService:
|
|||
)
|
||||
return self.workflow_repository.list_history(workflow_id, node_id=node_id)
|
||||
|
||||
def save_workflow_snapshot(
|
||||
self,
|
||||
workflow_id: str,
|
||||
payload: dict[str, Any],
|
||||
ctx: RequestContext,
|
||||
) -> WorkflowHistoryEntry:
|
||||
detail = self.workflow_service.get_workflow(workflow_id)
|
||||
workflow = detail.workflow
|
||||
node_id = _optional_text(payload.get("node_id"))
|
||||
node = None
|
||||
if node_id:
|
||||
node = self.workflow_service.get_node(node_id)
|
||||
if node.workflow_id != workflow_id:
|
||||
raise ApiError(
|
||||
ErrorCode.VALIDATION_FAILED,
|
||||
"node does not belong to this workflow",
|
||||
{"workflow_id": workflow_id, "node_id": node_id},
|
||||
)
|
||||
history = self.workflow_repository.create_history(
|
||||
{
|
||||
"history_id": payload.get("history_id") or new_history_id(),
|
||||
"profile_id": workflow.profile_id,
|
||||
"workflow_id": workflow.workflow_id,
|
||||
"node_id": node_id,
|
||||
"image_id": payload.get("image_id"),
|
||||
"branch_name": payload.get("branch_name") or workflow.current_branch or "main",
|
||||
"action": payload.get("action") or "save_version",
|
||||
"title": payload.get("title") or workflow.display_name,
|
||||
"prompt": payload.get("prompt") or (node.prompt if node else None),
|
||||
"metadata": {
|
||||
"source": "workflow_snapshot",
|
||||
"workflow": workflow.to_dict(),
|
||||
"nodes": [item.to_dict() for item in detail.nodes] if payload.get("include_nodes", True) else [],
|
||||
**(payload.get("metadata") if isinstance(payload.get("metadata"), dict) else {}),
|
||||
},
|
||||
}
|
||||
)
|
||||
self.audit_service.record(
|
||||
ctx=ctx,
|
||||
action="save_workflow_snapshot",
|
||||
target_type="workflow_history",
|
||||
target_id=history.history_id,
|
||||
after_snapshot=history.to_dict(),
|
||||
)
|
||||
return history
|
||||
|
||||
|
||||
def new_history_id() -> str:
|
||||
return f"hist_{uuid4().hex}"
|
||||
|
||||
|
||||
def _optional_text(value: Any) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
text = str(value).strip()
|
||||
return text or None
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from uuid import uuid4
|
|||
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
from backend.dto.image_dto import GenerationImage
|
||||
from backend.services.workflow_service import LOCKED_NODE_STATUSES, locked_node_edit_error
|
||||
from core.audit_service import AuditService
|
||||
from core.identity import RequestContext
|
||||
from database.repositories.image_repository import ImageRepository
|
||||
|
|
@ -87,6 +88,7 @@ class ImageService:
|
|||
|
||||
def select_image(self, image_id: str, ctx: RequestContext) -> GenerationImage:
|
||||
before = self.get_image(image_id)
|
||||
self._ensure_image_node_is_editable(before)
|
||||
if before.is_archived:
|
||||
raise ApiError(ErrorCode.VALIDATION_FAILED, "不能选择已归档图片", {"image_id": image_id})
|
||||
after = self.image_repository.select_exclusive(before)
|
||||
|
|
@ -106,6 +108,7 @@ class ImageService:
|
|||
|
||||
def unselect_image(self, image_id: str, ctx: RequestContext) -> GenerationImage:
|
||||
before = self.get_image(image_id)
|
||||
self._ensure_image_node_is_editable(before)
|
||||
after = self.image_repository.update(image_id, {"is_selected": False})
|
||||
if after is None:
|
||||
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "图片不存在", {"image_id": image_id})
|
||||
|
|
@ -125,6 +128,7 @@ class ImageService:
|
|||
|
||||
def archive_image(self, image_id: str, ctx: RequestContext) -> GenerationImage:
|
||||
before = self.get_image(image_id)
|
||||
self._ensure_image_node_is_editable(before)
|
||||
after = self.image_repository.update(
|
||||
image_id,
|
||||
{
|
||||
|
|
@ -149,6 +153,8 @@ class ImageService:
|
|||
return after
|
||||
|
||||
def delete_image_metadata(self, image_id: str, ctx: RequestContext) -> GenerationImage:
|
||||
existing = self.get_image(image_id)
|
||||
self._ensure_image_node_is_editable(existing)
|
||||
before = self.image_repository.delete_metadata(image_id)
|
||||
if before is None:
|
||||
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "图片不存在", {"image_id": image_id})
|
||||
|
|
@ -166,6 +172,13 @@ class ImageService:
|
|||
)
|
||||
return before
|
||||
|
||||
def _ensure_image_node_is_editable(self, image: GenerationImage) -> None:
|
||||
if not image.node_id:
|
||||
return
|
||||
node = self.workflow_repository.get_node(image.node_id)
|
||||
if node and node.status in LOCKED_NODE_STATUSES:
|
||||
raise locked_node_edit_error(node)
|
||||
|
||||
|
||||
def new_image_id() -> str:
|
||||
return f"img_{uuid4().hex}"
|
||||
|
|
|
|||
|
|
@ -6,13 +6,16 @@ the prompt expansion internals without changing the API contract.
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
from backend.services.profile_service import ProfileService
|
||||
from core.identity import RequestContext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from backend.services.workflow_service import WorkflowService
|
||||
|
||||
|
||||
class QuickProfileService:
|
||||
def create_draft(self, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
|
|
@ -71,6 +74,7 @@ class QuickProfileService:
|
|||
payload: dict[str, Any],
|
||||
profile_service: ProfileService,
|
||||
ctx: RequestContext,
|
||||
workflow_service: "WorkflowService | None" = None,
|
||||
) -> dict[str, Any]:
|
||||
draft = payload.get("draft") if isinstance(payload.get("draft"), dict) else {}
|
||||
preview = payload.get("profile_preview") if isinstance(payload.get("profile_preview"), dict) else None
|
||||
|
|
@ -103,10 +107,42 @@ class QuickProfileService:
|
|||
},
|
||||
ctx,
|
||||
)
|
||||
return {
|
||||
result = {
|
||||
"draft_id": draft_id or None,
|
||||
"profile": profile.to_dict(),
|
||||
}
|
||||
should_create_workflow = bool(payload.get("create_workflow", workflow_service is not None))
|
||||
if should_create_workflow:
|
||||
if workflow_service is None:
|
||||
raise ApiError(
|
||||
ErrorCode.VALIDATION_FAILED,
|
||||
"\u7f3a\u5c11\u5feb\u901f\u89d2\u8272\u5de5\u4f5c\u6d41\u670d\u52a1",
|
||||
{"field": "workflow_service"},
|
||||
)
|
||||
workflow_detail = workflow_service.create_workflow(
|
||||
profile.profile_id,
|
||||
{
|
||||
"workflow_type": "quick_profile",
|
||||
"display_name": _text(payload.get("workflow_display_name"))
|
||||
or f"{name} \u5feb\u901f\u89d2\u8272\u5de5\u4f5c\u6d41",
|
||||
"status": _text(payload.get("workflow_status")) or "draft",
|
||||
"metadata": {
|
||||
"source": "quick_profile",
|
||||
"profile_id": profile.profile_id,
|
||||
**({"draft_id": draft_id} if draft_id else {}),
|
||||
"profile_preview": preview,
|
||||
**(
|
||||
{"questionnaire": payload["questionnaire"]}
|
||||
if isinstance(payload.get("questionnaire"), dict)
|
||||
else {}
|
||||
),
|
||||
},
|
||||
},
|
||||
ctx,
|
||||
)
|
||||
result["workflow"] = workflow_detail.workflow.to_dict()
|
||||
result["nodes"] = [node.to_dict() for node in workflow_detail.nodes]
|
||||
return result
|
||||
|
||||
|
||||
def _text(value: Any) -> str:
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ NODE_STATUSES = {
|
|||
"skipped",
|
||||
"discarded",
|
||||
}
|
||||
LOCKED_NODE_STATUSES = {"completed", "selected"}
|
||||
|
||||
|
||||
class WorkflowService:
|
||||
|
|
@ -180,8 +181,11 @@ class WorkflowService:
|
|||
"branch already exists",
|
||||
{"workflow_id": workflow_id, "branch_name": branch_name},
|
||||
)
|
||||
base_branch_name = str(payload.get("base_branch_name") or workflow.current_branch or "main")
|
||||
base_branch_name = str(payload.get("base_branch_name") or workflow.current_branch or "main").strip()
|
||||
base_node_id = payload.get("base_node_id") or workflow.current_node_id
|
||||
copy_nodes = payload.get("copy_nodes", True)
|
||||
if copy_nodes or base_node_id:
|
||||
self._resolve_branch_copy_base(workflow_id, base_branch_name, base_node_id)
|
||||
branch = self.workflow_repository.create_branch(
|
||||
{
|
||||
"branch_id": payload.get("branch_id") or new_branch_id(),
|
||||
|
|
@ -194,8 +198,8 @@ class WorkflowService:
|
|||
}
|
||||
)
|
||||
copied_nodes = []
|
||||
if payload.get("copy_nodes", True):
|
||||
copied_nodes = self._copy_branch_nodes(workflow_id, base_branch_name, branch_name, ctx)
|
||||
if copy_nodes:
|
||||
copied_nodes = self._copy_branch_nodes(workflow_id, base_branch_name, branch_name, ctx, base_node_id)
|
||||
self.audit_service.record(
|
||||
ctx=ctx,
|
||||
action="create_branch",
|
||||
|
|
@ -326,6 +330,8 @@ class WorkflowService:
|
|||
|
||||
def update_node(self, node_id: str, payload: dict[str, Any], ctx: RequestContext) -> WorkflowNode:
|
||||
before = self.get_node(node_id)
|
||||
if before.status in LOCKED_NODE_STATUSES and _node_payload_changes(before, payload):
|
||||
raise locked_node_edit_error(before)
|
||||
if "status" in payload:
|
||||
self._validate_node_status_transition(before.status, str(payload["status"]))
|
||||
if "title" in payload and not str(payload["title"]).strip():
|
||||
|
|
@ -381,10 +387,9 @@ class WorkflowService:
|
|||
from_branch: str,
|
||||
to_branch: str,
|
||||
ctx: RequestContext,
|
||||
base_node_id: str | None = None,
|
||||
) -> list[WorkflowNode]:
|
||||
source_nodes = self.workflow_repository.list_nodes(workflow_id, branch_name=from_branch)
|
||||
if not source_nodes and from_branch != "main":
|
||||
source_nodes = self.workflow_repository.list_nodes(workflow_id, branch_name="main")
|
||||
source_nodes, base_sort_order = self._resolve_branch_copy_base(workflow_id, from_branch, base_node_id)
|
||||
return [
|
||||
self.create_node(
|
||||
workflow_id,
|
||||
|
|
@ -394,13 +399,14 @@ class WorkflowService:
|
|||
"description": node.description,
|
||||
"step_name": node.step_name,
|
||||
"node_type": node.node_type,
|
||||
"status": "draft",
|
||||
"status": _branch_copy_status(node, base_sort_order),
|
||||
"branch_name": to_branch,
|
||||
"prompt": node.prompt,
|
||||
"negative_prompt": node.negative_prompt,
|
||||
"model_route": node.model_route,
|
||||
"selected_image_id": _branch_copy_selected_image_id(node, base_sort_order),
|
||||
"sort_order": node.sort_order,
|
||||
"metadata": {**node.metadata, "copied_from_node_id": node.node_id},
|
||||
"metadata": _branch_copy_metadata(node, base_sort_order),
|
||||
},
|
||||
ctx,
|
||||
audit=False,
|
||||
|
|
@ -408,6 +414,26 @@ class WorkflowService:
|
|||
for node in source_nodes
|
||||
]
|
||||
|
||||
def _resolve_branch_copy_base(
|
||||
self,
|
||||
workflow_id: str,
|
||||
from_branch: str,
|
||||
base_node_id: str | None = None,
|
||||
) -> tuple[list[WorkflowNode], int | None]:
|
||||
source_nodes = self.workflow_repository.list_nodes(workflow_id, branch_name=from_branch)
|
||||
if not source_nodes and from_branch != "main":
|
||||
source_nodes = self.workflow_repository.list_nodes(workflow_id, branch_name="main")
|
||||
base_node = None
|
||||
if base_node_id:
|
||||
base_node = next((node for node in source_nodes if node.node_id == base_node_id), None)
|
||||
if base_node is None:
|
||||
raise ApiError(
|
||||
ErrorCode.VALIDATION_FAILED,
|
||||
"base_node_id does not belong to the source branch",
|
||||
{"workflow_id": workflow_id, "branch_name": from_branch, "base_node_id": base_node_id},
|
||||
)
|
||||
return source_nodes, base_node.sort_order if base_node else None
|
||||
|
||||
def _ensure_profile_exists(self, profile_id: str) -> None:
|
||||
profile = self.profile_repository.get(profile_id)
|
||||
if profile is None or profile.status == "deleted":
|
||||
|
|
@ -474,6 +500,85 @@ def new_branch_id() -> str:
|
|||
return f"branch_{uuid4().hex}"
|
||||
|
||||
|
||||
def locked_node_edit_error(node: WorkflowNode) -> ApiError:
|
||||
return ApiError(
|
||||
ErrorCode.VALIDATION_FAILED,
|
||||
"completed node is locked; create a workflow branch before editing",
|
||||
{
|
||||
"node_id": node.node_id,
|
||||
"workflow_id": node.workflow_id,
|
||||
"branch_name": node.branch_name,
|
||||
"status": node.status,
|
||||
"suggested_action": "create_branch",
|
||||
"base_node_id": node.node_id,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _node_payload_changes(node: WorkflowNode, payload: dict[str, Any]) -> bool:
|
||||
comparable = {
|
||||
"title": node.title,
|
||||
"description": node.description,
|
||||
"step_name": node.step_name,
|
||||
"node_type": node.node_type,
|
||||
"status": node.status,
|
||||
"branch_name": node.branch_name,
|
||||
"prompt": node.prompt,
|
||||
"negative_prompt": node.negative_prompt,
|
||||
"model_route": node.model_route,
|
||||
"selected_image_id": node.selected_image_id,
|
||||
"sort_order": node.sort_order,
|
||||
"metadata": node.metadata,
|
||||
}
|
||||
for key, value in payload.items():
|
||||
if key not in comparable:
|
||||
continue
|
||||
current = comparable[key]
|
||||
if key == "sort_order":
|
||||
try:
|
||||
value = int(value)
|
||||
except (TypeError, ValueError):
|
||||
return True
|
||||
if key == "title" and value is not None:
|
||||
value = str(value).strip()
|
||||
if value != current:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _branch_copy_status(node: WorkflowNode, base_sort_order: int | None) -> str:
|
||||
if base_sort_order is None:
|
||||
return "draft"
|
||||
if node.sort_order < base_sort_order:
|
||||
return node.status
|
||||
return "draft"
|
||||
|
||||
|
||||
def _branch_copy_selected_image_id(node: WorkflowNode, base_sort_order: int | None) -> str | None:
|
||||
if base_sort_order is not None and node.sort_order < base_sort_order:
|
||||
return node.selected_image_id
|
||||
return None
|
||||
|
||||
|
||||
def _branch_copy_metadata(node: WorkflowNode, base_sort_order: int | None) -> dict[str, Any]:
|
||||
metadata = {
|
||||
**node.metadata,
|
||||
"copied_from_node_id": node.node_id,
|
||||
}
|
||||
if base_sort_order is None:
|
||||
return metadata
|
||||
locked_ancestor = node.sort_order < base_sort_order and node.status in LOCKED_NODE_STATUSES
|
||||
metadata.update(
|
||||
{
|
||||
"branch_cut_base_sort_order": base_sort_order,
|
||||
"branch_reset_from_status": node.status,
|
||||
"branch_locked_ancestor": locked_ancestor,
|
||||
"branch_editable_from_cut": node.sort_order >= base_sort_order,
|
||||
}
|
||||
)
|
||||
return metadata
|
||||
|
||||
|
||||
def _initial_node_templates(workflow_type: str) -> list[dict[str, Any]]:
|
||||
if workflow_type == "single_image":
|
||||
return [
|
||||
|
|
|
|||
293
docs/ui-function-entry-index.md
普通文件
293
docs/ui-function-entry-index.md
普通文件
|
|
@ -0,0 +1,293 @@
|
|||
# ImageStudio UI 功能入口与接口索引
|
||||
|
||||
日期:2026-07-07
|
||||
维护规则:每新增一个可点击的功能入口、浮层、工作台入口、页面入口或后端 API 占位,都必须更新本文档。
|
||||
|
||||
## 2026-07-08 已完成闭环总结
|
||||
|
||||
- 快速角色:创建角色档案问卷已扩展为简单/复杂模式,复杂字段支持世界观、背景、身高/身材、身体特征、喜好、关系、故事钩子、画风和镜头偏好;字段可留空,不阻断生成档案。
|
||||
- 快速角色落库:生成档案会调用 `profiles/quick-draft/save`,保存角色档案并创建对应 `quick_profile`/角色工作流关联,前端不会在预览模式伪造落库成功。
|
||||
- 外部角色卡导入:工作流导入入口已提供粘贴导入弹窗,可识别外部人设文本并回填角色档案问卷。
|
||||
- 角色工作流:前期人设准备节点已接入后端角色工作流执行入口 `workflows/:workflowId/execute-character`,成功后进入 LLM 设定拆解节点。
|
||||
- LLM 设定拆解:中间大卡片固定为拆解工作台,身份性格、外观锚点、服装素材、约束负面项按组顺序排列,超出内容滚动展示;右侧详情显示 LLM 拆解摘要。
|
||||
- 节点对话注入:底部对话框会打包当前节点、角色档案、素材、拆解字段和用户原文,标记 `source_language:auto`、`target_prompt_language:en`、`translation_mode:backend_llm` 后提交 `nodes/:nodeId/generate`。
|
||||
- 工作流锁定与分支:后端将 `completed`/`selected` 节点作为锁定节点,禁止原链路继续修改、重跑、选图、归档或删除绑定图片;如需修改,前端提供“从此节点创建分支”,调用 `workflows/:workflowId/branches` 和 `workflows/:workflowId/switch-branch`,从选中节点切分支并保证旧链路干净。
|
||||
- 分支复制规则:从 `base_node_id` 创建分支时,切点之前的节点保留完成状态和选中图;切点及之后重置为 `draft` 并清空选中图,metadata 写入 `copied_from_node_id` 和分支切点信息。
|
||||
- 验证结果:后端锁定/分支/生成/图像/历史相关测试 39 条通过;前端 `vue-tsc --noEmit` 和 `build:web` 通过;浏览器预览工作流三栏布局无控制台错误。
|
||||
|
||||
## 维护方式
|
||||
|
||||
- `入口名称` 写用户在界面上能理解的名称。
|
||||
- `位置` 写清楚入口在哪个页面、哪个卡片或哪个浮层。
|
||||
- `当前动作` 写现在点击会发生什么。
|
||||
- `关联接口` 写已规划或已接入的 endpoint;纯前端占位写 `local/*`。
|
||||
- `状态` 使用:`已接 UI`、`模拟数据`、`占位入口`、`待后端接入`、`已接后端`。
|
||||
|
||||
## 前端入口总览
|
||||
|
||||
### 左侧导航
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联模块 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 概览 | 左侧星图导航 | 切换到概览页 | `overview` | 已接 UI |
|
||||
| 生成 | 左侧星图导航 | 切换到生成页 | `generate` | 已接 UI |
|
||||
| 队列 | 左侧星图导航 | 切换到队列模块 | `queue` | 已接 UI |
|
||||
| 性能 | 左侧星图导航 | 切换到性能详情页 | `performance` | 占位入口 |
|
||||
| 图库 | 左侧星图导航 | 切换到图库模块 | `images` | 占位入口 |
|
||||
| 角色 | 左侧星图导航 | 切换到角色模块 | `suggestions` | 占位入口 |
|
||||
| 素材 | 左侧星图导航 | 切换到素材模块 | `images` | 占位入口 |
|
||||
| 设置 | 左侧星图导航 | 切换到设置模块 | `settings` | 已接 UI |
|
||||
| 日志 | 左侧星图导航 | 切换到日志模块 | `logs` | 已接 UI |
|
||||
|
||||
### 顶部工具区
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 主题切换 | 顶部工具区 | 日间/夜间模式切换 | `local/preferences` | 已接 UI |
|
||||
| 消息中心 | 顶部工具区铃铛 | 打开消息浮层,外部点击关闭 | `local/notifications` | 模拟数据 |
|
||||
| 日志浮层 | 顶部工具区文件图标 | 悬停或点击打开日志浮层 | `logs/generation`, `logs/errors` | 已接 UI |
|
||||
| 后端连接诊断 | 顶部工具区刷新按钮旁 | 显示插件桥/同源 API 连接状态,预览或异常时展开诊断横幅 | `ui/bootstrap` | 已接 UI |
|
||||
| 调色盘 | 顶部工具区调色盘 | 打开主题色选择浮层 | `local/preferences` | 已接 UI |
|
||||
| 搜索 | 顶部搜索框 | 搜索功能入口和模块 | `local/search-index` | 已接 UI |
|
||||
|
||||
## 生成页入口
|
||||
|
||||
### 生成页模式切换
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 图片生成 | 生成页顶部模式按钮 | 切换到图片生成工作台 | `nodes/:nodeId/generate` | 已接 UI / 后端落库 |
|
||||
| 快速角色 | 生成页顶部模式按钮 | 切换到快速角色工作台 | `profiles/quick-draft`, `profiles/quick-draft/save` | 已接 UI / 后端落库 |
|
||||
| 角色工作流 | 生成页顶部模式按钮 | 切换到角色工作流工作台 | `profiles/:profileId/workflows`, `workflows/:workflowId/nodes` | 已接 UI / 后端数据 |
|
||||
|
||||
### 图片生成工作台
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 生图模型选择 | 图片生成底部输入框 | 选择当前生图模型 | `api-discovery/capabilities` | 模拟数据 |
|
||||
| 自然语言输入框 | 图片生成底部 | 输入自然语言生图需求 | `local/prompt-composer` | 占位入口 |
|
||||
| 提交生成 | 图片生成输入框按钮 | 自动准备单图工作流并提交后端生成,返回图片写入预览 | `profiles`, `profiles/:profileId/workflows`, `nodes/:nodeId/generate` | 已接 UI / 后端落库 |
|
||||
| 最近请求 | 图片生成输入框内 | 点击填入历史请求 | `local/recent-prompts` | 模拟数据 |
|
||||
| 图片队列 | 图片生成左侧队列 | 优先展示后端返回图片和最近图库结果,选择后在主图区放大显示 | `images/:imageId` | 已接 UI / 后端数据 |
|
||||
| 图片主预览 | 图片生成中间主图 | 点击打开图片详情卡 | `images/:imageId` | 已接 UI |
|
||||
| 图片详情卡 | 图片预览浮层 | 滚轮缩放、双击缩放、拖拽查看 | `images/:imageId` | 已接 UI |
|
||||
|
||||
## 快速角色入口
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 全部角色档案列表 | 快速角色左侧 | 选择当前角色卡 | `profiles` | 模拟数据 |
|
||||
| 添加档案 | 全部角色档案列表顶部 | 打开创建角色档案问卷,可在生成档案旁切换简单/复杂问卷 | `profiles/quick-draft` | 已接 UI |
|
||||
| 角色预览折角 | 角色预览卡右上角 | 打开角色设定详情大卡片 | `profiles/:profileId` | 已接 UI |
|
||||
| 角色设定详情大卡片 | 角色预览折角打开 | 查看当前角色基础、外观、风格、负面词 | `profiles/:profileId` | 模拟数据 |
|
||||
| 半身像/头像图片 | 角色预览图 | 打开图片详情卡,可缩放拖拽 | `images/:imageId` | 已接 UI |
|
||||
| 角色图片类型卡 | 角色图片区域右侧 | 切换头像、半身、立绘、设定图 | `images/:imageId` | 模拟数据 |
|
||||
| 参考素材卡 | 快速角色参考素材区 | 打开素材选择浮层 | `materials` | 已接 UI |
|
||||
| 不使用参考 | 素材选择浮层顶部 | 清空对应分类素材 | `local/material-selection` | 已接 UI |
|
||||
| 添加素材占位卡 | 素材选择浮层底部 | 记录添加意图,后续跳转素材库新增 | `materials/upload` | 占位入口 |
|
||||
| 配饰细分类 | 配饰素材浮层 | 切换配饰子类并单列展示 | `material-categories` | 模拟数据 |
|
||||
| 生成人设 | 快速角色功能按钮 | 打开问卷大卡片 | `profiles/quick-draft` | 已接 UI |
|
||||
| 保存角色 | 快速角色功能按钮 | 调用后端保存快速角色档案,并创建 `quick_profile` 工作流 | `profiles/quick-draft/save` | 已接 UI / 后端落库 |
|
||||
| 整理素材集 | 快速角色功能按钮 | 后续整理角色专属素材包 | `materials` | 占位入口 |
|
||||
| 衣橱匹配 | 快速角色功能按钮 | 后续按当前人设匹配服装与配饰 | `profiles/:profileId/wardrobe/match` | 占位入口 |
|
||||
| 每日穿搭 | 快速角色功能按钮 | 后续生成长期穿搭方案 | `integrations/private-companion/daily-outfit` | 占位入口 |
|
||||
| 进入工作流 | 快速角色功能按钮 | 切到角色工作流并使用当前人设继续细化 | `profiles/:profileId/workflows` | 已接 UI |
|
||||
|
||||
## 角色工作流入口
|
||||
|
||||
### 节点流程
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 大节点卡 | 角色工作流左侧节点流程 | 优先读取已选角色的后端角色工作流节点,缺数据时回退演示节点 | `workflows/:workflowId/nodes` | 已接 UI / 后端数据 |
|
||||
| 小节点卡 | 大节点内部 | 选择具体节点并联动中间工作幕布 | `nodes/:nodeId` | 已接 UI / 后端数据 |
|
||||
| 前期人设准备 | 大节点 | 展示人设导入、拆解、提示词和素材绑定节点 | `workflows/:workflowId/nodes` | 模拟数据 |
|
||||
| 头像草稿 | 大节点 | 展示头像草稿多轮节点 | `nodes/:nodeId/images` | 模拟数据 |
|
||||
| 全身与设定图 | 大节点 | 展示全身、手部、配饰和设定图拆分节点 | `nodes/:nodeId/images` | 模拟数据 |
|
||||
| 审核修复并入库 | 大节点 | 展示审核、高清修复和归档节点 | `workflows/:workflowId/review` | 模拟数据 |
|
||||
|
||||
### 工作幕布联动
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 导入粗略人设工作台 | 选中 `导入粗略人设` 节点时的中间幕布 | 显示新建人设和选择已有角色卡 | `profiles/quick-draft`, `profiles` | 已接 UI |
|
||||
| 新建粗略人设 | 导入粗略人设工作台左侧右下角 `+` 按钮 | 打开创建角色档案问卷,可选简单/复杂字段 | `profiles/quick-draft` | 已接 UI |
|
||||
| 选择已有角色卡 | 导入粗略人设工作台右侧 | 选择当前角色卡作为工作流输入 | `profiles/:profileId` | 模拟数据 |
|
||||
| 当前导入摘要 | 导入粗略人设工作台底部 | 展示当前导入角色卡、风格、素材和状态 | `profiles/:profileId` | 模拟数据 |
|
||||
| 节点草稿池 | 图片类节点下方 | 按当前后端节点图片显示候选图,缺数据时回退演示图 | `nodes/:nodeId/images` | 已接 UI / 后端数据 |
|
||||
| 多选草稿 | 节点草稿池 | 多选后同步到主预览,并把当前采用图写回后端节点 | `nodes/:nodeId/select-image` | 已接 UI / 后端落库 |
|
||||
| 平铺对比 | 主预览右上角 | 打开多图对比浮层 | `local/workflow-compare` | 已接 UI |
|
||||
| 工作流图片详情 | 主预览图片点击 | 打开图片详情卡,可缩放拖拽 | `images/:imageId` | 已接 UI |
|
||||
| 节点详情 | 右侧节点详情卡 | 展示后端节点阶段、状态、队列任务和产物摘要,缺字段时使用 UI 摘要 | `nodes/:nodeId` | 已接 UI / 后端数据 |
|
||||
|
||||
### 工作流操作按钮
|
||||
|
||||
| 入口名称 | 位置 | 当前动作 | 关联接口 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 创建角色档案 | 前期人设准备 / 导入粗略人设 | 打开创建角色档案问卷,简单字段可直接生成,复杂字段作为可选结构传后端并自动选中角色卡 | `profiles/quick-draft/save` | 已接 UI / 后端落库 |
|
||||
| 导入外部角色卡 | 前期人设准备 / 导入粗略人设 | 打开外部角色卡导入浮层,识别文本后填入创建角色档案问卷 | `local/profile-import-parser`, `profiles/quick-draft` | 已接 UI |
|
||||
| 导入当前角色卡 | 前期人设准备 / 导入粗略人设 | 选中已落库角色卡作为工作流输入,自动加载或创建角色工作流 | `profiles/:profileId`, `profiles/:profileId/workflows` | 已接 UI / 后端落库 |
|
||||
| 进入设定拆解 | 前期人设准备 / 导入粗略人设 | 使用当前已落库角色卡调用后端工作流执行,成功后切到 LLM 拆解节点 | `workflows/:workflowId/nodes`, `workflows/:workflowId/execute-character` | 已接 UI / 后端已接 |
|
||||
| LLM 拆解设定工作台 | 前期人设准备 / LLM 拆解设定 | 展示身份性格、外观锚点、服装素材、约束负面项四组结构化字段,并显示字段完成度 | `workflows/:workflowId/nodes` | 已接 UI / 后端数据 |
|
||||
| 重新拆解设定 | 前期人设准备 / LLM 拆解设定 | 用当前角色档案重新生成结构化字段,后端连通时写回当前节点 | `nodes/:nodeId/generate` | 已接 UI / 后端预留 |
|
||||
| 确认字段 | 前期人设准备 / LLM 拆解设定 | 确认身份、外观、服装、配饰和禁用项,成功后进入提示词规划 | `nodes/:nodeId/complete` | 已接 UI / 后端已接 |
|
||||
| 节点对话注入 | 角色工作流 / 底部对话框 | 自动识别当前节点、角色档案、素材和拆解字段,打包用户原文并标记后端 LLM 翻译为英文提示词后注入节点 | `nodes/:nodeId/generate` | 已接 UI / 后端注入预留 |
|
||||
| 生成提示词矩阵 | 前期人设准备 / 提示词规划 | 后续生成头像、半身、全身和设定图提示词 | `nodes/:nodeId/generate` | 待后端接入 |
|
||||
| 校验负面词 | 前期人设准备 / 提示词规划 | 后续检查负面词、权重和冲突项 | `review/policy/validate` | 待后端接入 |
|
||||
| 绑定参考素材 | 前期人设准备 / 参考素材绑定 | 后续把素材写入节点参数 | `materials`, `nodes/:nodeId` | 待后端接入 |
|
||||
| 打开素材库 | 前期人设准备 / 参考素材绑定 | 跳转素材模块补充素材 | `materials` | 已接 UI |
|
||||
| 生成头像草稿 | 头像草稿阶段 | 按当前后端节点生成头像和半身候选,结果写入节点图片 | `nodes/:nodeId/generate`, `nodes/:nodeId/images` | 已接 UI / 后端落库 |
|
||||
| 对比候选 | 头像草稿阶段 | 打开已选草稿平铺对比 | `local/workflow-compare` | 已接 UI |
|
||||
| 再跑一轮 | 头像草稿阶段 | 将当前后端节点标记重试并再次生成候选 | `nodes/:nodeId/retry`, `nodes/:nodeId/generate` | 已接 UI / 后端落库 |
|
||||
| 生成设定图 | 全身与设定图阶段 | 生成全身、手部、配饰或拆分设定图并写入节点图片 | `nodes/:nodeId/generate`, `nodes/:nodeId/images` | 已接 UI / 后端落库 |
|
||||
| 细节补图 | 全身与设定图阶段 | 后续针对手部、鞋袜、配饰等局部补图 | `nodes/:nodeId/generate` | 待后端接入 |
|
||||
| 重跑当前设定 | 全身与设定图阶段 | 后续保留人设锁定项重跑当前节点 | `nodes/:nodeId/retry` | 待后端接入 |
|
||||
| 审核选图 | 审核修复并入库阶段 | 后续标记采用、备选或废弃版本 | `nodes/:nodeId/review` | 待后端接入 |
|
||||
| 高清修复 | 审核修复并入库阶段 | 对当前后端节点发起高清修复生成,结果写入节点图片 | `nodes/:nodeId/generate`, `nodes/:nodeId/images` | 已接 UI / 后端落库 |
|
||||
| 保存快照 | 各工作流阶段 | 保存当前流程快照、节点参数和选中角色卡摘要到 `workflow_history` | `POST workflows/:workflowId/history` | 已接 UI / 后端已接 |
|
||||
| 从此节点创建分支 | 选中已完成/已采用节点时的右侧操作区 | 已完成节点锁定后,点击会以当前节点为切点复制工作流分支并切换到新分支;切点之前保持锁定,切点及之后重置为草稿 | `POST workflows/:workflowId/branches`, `POST workflows/:workflowId/switch-branch` | 已接 UI / 后端已接 |
|
||||
| 归档图库 | 审核修复并入库阶段 | 后续把最终图放入角色图库 | `images/:imageId/archive` | 待后端接入 |
|
||||
|
||||
## 当前已定义 API endpoint
|
||||
|
||||
源码位置:`frontend/shared/api/endpoints.ts`
|
||||
|
||||
### UI 与概览
|
||||
|
||||
- `ui/bootstrap`
|
||||
- `ui/actions`
|
||||
- `dashboard/summary`
|
||||
|
||||
### 角色与快速角色
|
||||
|
||||
- `profiles`
|
||||
- `profiles/:profileId`
|
||||
- `profiles/:profileId/archive`
|
||||
- `profiles/quick-draft`
|
||||
- `profiles/quick-draft/save`
|
||||
- `profiles/:profileId/workflows`
|
||||
|
||||
### 工作流
|
||||
|
||||
- `workflows/:workflowId`
|
||||
- `workflows/:workflowId/start`
|
||||
- `workflows/:workflowId/cancel`
|
||||
- `workflows/:workflowId/archive`
|
||||
- `workflows/:workflowId/execute-character`
|
||||
- `workflows/:workflowId/nodes`
|
||||
- `workflows/:workflowId/branches`
|
||||
- `workflows/:workflowId/switch-branch`
|
||||
- `workflows/:workflowId/history`
|
||||
- `workflows/:workflowId/review`
|
||||
|
||||
### 节点
|
||||
|
||||
- `nodes/:nodeId`
|
||||
- `nodes/:nodeId/generate`
|
||||
- `nodes/:nodeId/retry`
|
||||
- `nodes/:nodeId/complete`
|
||||
- `nodes/:nodeId/mark-completed`
|
||||
- `nodes/:nodeId/select-image`
|
||||
- `nodes/:nodeId/adopt-image`
|
||||
- `nodes/:nodeId/review`
|
||||
- `nodes/:nodeId/images`
|
||||
|
||||
### 图片
|
||||
|
||||
- `images/:imageId`
|
||||
- `images/:imageId/select`
|
||||
- `images/:imageId/unselect`
|
||||
- `images/:imageId/archive`
|
||||
|
||||
### 队列
|
||||
|
||||
- `jobs`
|
||||
- `jobs/:taskId`
|
||||
- `jobs/:taskId/cancel`
|
||||
- `jobs/:taskId/retry`
|
||||
- `jobs/dead-letter/retry`
|
||||
- `jobs/dead-letter/move-failed`
|
||||
|
||||
### 设置与存储
|
||||
|
||||
- `settings/schema`
|
||||
- `settings/current`
|
||||
- `settings/validate`
|
||||
- `settings/diff`
|
||||
- `settings/save`
|
||||
- `settings/reload`
|
||||
- `settings/export`
|
||||
- `settings/import`
|
||||
- `settings/snapshots`
|
||||
- `settings/snapshots/:snapshotId`
|
||||
- `settings/rollback`
|
||||
- `storage/status`
|
||||
- `storage/migrate`
|
||||
|
||||
### 素材库
|
||||
|
||||
- `material-categories`
|
||||
- `material-categories/:categoryId`
|
||||
- `materials`
|
||||
- `materials/upload`
|
||||
- `materials/:materialId`
|
||||
- `materials/:materialId/recognize`
|
||||
- `materials/:materialId/re-recognize`
|
||||
- `materials/:materialId/confirm`
|
||||
- `assets/import-pack`
|
||||
|
||||
### 衣橱与穿搭
|
||||
|
||||
- `profiles/:profileId/wardrobe`
|
||||
- `profiles/:profileId/wardrobe/import-material`
|
||||
- `profiles/:profileId/wardrobe/items`
|
||||
- `profiles/:profileId/wardrobe/items/:wardrobeItemId`
|
||||
- `profiles/:profileId/wardrobe/:wardrobeItemId`
|
||||
- `profiles/:profileId/wardrobe/match`
|
||||
- `integrations/private-companion/daily-outfit`
|
||||
|
||||
### 模型发现与能力探测
|
||||
|
||||
- `api-discovery/dialects`
|
||||
- `api-discovery/probe-provider`
|
||||
- `api-discovery/probe-model`
|
||||
- `api-discovery/capabilities`
|
||||
- `api-discovery/manual-override`
|
||||
- `api-discovery/validate-render-plan`
|
||||
|
||||
### 日志、事件与安全
|
||||
|
||||
- `logs/generation`
|
||||
- `logs/workflows`
|
||||
- `logs/errors`
|
||||
- `logs/integrations`
|
||||
- `integrations/logs`
|
||||
- `security/audit-logs`
|
||||
- `events/stream`
|
||||
- `web/manifest`
|
||||
|
||||
## 浮层与弹出卡片
|
||||
|
||||
| 浮层名称 | 触发入口 | 当前内容 | 关闭方式 | 状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 消息中心 | 顶部铃铛 | 通知列表 | 外部点击 / 再点按钮 / ESC | 已接 UI |
|
||||
| 日志浮层 | 顶部日志图标 | 生成日志、错误日志 | 外部点击 / ESC | 已接 UI |
|
||||
| 调色盘 | 顶部调色盘 | 主题色选择 | 外部点击 / ESC | 已接 UI |
|
||||
| 图片详情卡 | 图片生成/工作流/快速角色图片 | 大图缩放、双击、拖拽 | 外部点击 / 关闭按钮 / ESC | 已接 UI |
|
||||
| 角色设定详情卡 | 快速角色折角 | 当前角色设定详情 | 外部点击 / 关闭按钮 / ESC | 已接 UI |
|
||||
| 创建角色档案问卷 | 快速角色生成人设/添加档案/工作流新建人设 | 简单/复杂问卷切换;复杂问卷包含世界观、背景、身高身材、喜好、关系和生成偏好,字段可留空;保存时调用后端生成角色档案与 `quick_profile` 工作流 | 外部点击 / 关闭按钮 / ESC | 已接 UI / 后端落库 |
|
||||
| 外部角色卡导入 | 工作流导入粗略人设 / 粘贴导入 | 粘贴外部角色卡、人设文本或设定片段,并识别填入创建角色档案问卷 | 外部点击 / 取消 / 关闭按钮 / ESC | 已接 UI |
|
||||
| 素材选择卡 | 快速角色参考素材 | 不使用、素材候选、添加素材 | 外部点击 / ESC | 已接 UI |
|
||||
| 工作流多图对比 | 角色工作流平铺对比 | 多草稿大图对比 | 关闭按钮 / ESC | 已接 UI |
|
||||
|
||||
## 待补入口记录
|
||||
|
||||
新增功能时先写这里,再实现 UI 或接口。
|
||||
|
||||
| 待补入口 | 预期位置 | 预期接口 | 备注 |
|
||||
| --- | --- | --- | --- |
|
||||
| 素材库添加对应分类素材 | 素材选择浮层底部添加卡 | `materials/upload` | 需要带分类参数,如构图、服装、配饰子类 |
|
||||
| 工作流草稿轮次自动创建 | 角色工作流节点流程 | `workflows/:workflowId/nodes` | 不满意重跑时自动创建草稿 02/03 等小节点 |
|
||||
| 节点锁定元素写入 | 工作流多选草稿/节点详情 | `nodes/:nodeId/select-image` | 选中五官、发色、服装等锁定项 |
|
||||
| 角色编辑界面 | 角色设定详情卡或角色模块 | `profiles/:profileId` | 当前只有详情卡和问卷占位 |
|
||||
| 性能详情页 | 左侧性能入口 | 待定 | 当前只有入口和概览精简卡 |
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { API_BASE } from "./endpoints"
|
||||
import type { ApiResponse } from "../types/api"
|
||||
|
||||
export type ApiTransport = "plugin-bridge" | "direct-fetch"
|
||||
|
||||
export class ApiClientError extends Error {
|
||||
readonly code: string
|
||||
readonly details: Record<string, unknown>
|
||||
|
|
@ -21,6 +23,13 @@ export async function postJson<T>(endpoint: string, body?: unknown) {
|
|||
return request<T>(endpoint, { method: "POST", body })
|
||||
}
|
||||
|
||||
export function getApiTransport(): ApiTransport {
|
||||
const bridge = typeof window === "undefined" ? undefined : window.AstrBotPluginPage
|
||||
return bridge && (typeof bridge.apiGet === "function" || typeof bridge.apiPost === "function")
|
||||
? "plugin-bridge"
|
||||
: "direct-fetch"
|
||||
}
|
||||
|
||||
export async function request<T>(
|
||||
endpoint: string,
|
||||
options: {
|
||||
|
|
@ -34,12 +43,33 @@ export async function request<T>(
|
|||
return unwrapApiResponse(bridgePayload)
|
||||
}
|
||||
|
||||
const response = await fetch(buildUrl(endpoint, options.query), {
|
||||
method: options.method ?? "GET",
|
||||
headers: options.body === undefined ? undefined : { "Content-Type": "application/json" },
|
||||
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
||||
})
|
||||
const payload = (await response.json()) as ApiResponse<T>
|
||||
const url = buildUrl(endpoint, options.query)
|
||||
let response: Response
|
||||
try {
|
||||
response = await fetch(url, {
|
||||
method: options.method ?? "GET",
|
||||
headers: options.body === undefined ? undefined : { "Content-Type": "application/json" },
|
||||
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
||||
})
|
||||
} catch (err) {
|
||||
throw new ApiClientError("network_unreachable", "无法连接 ImageStudio 后端接口", {
|
||||
endpoint,
|
||||
transport: "direct-fetch",
|
||||
url,
|
||||
reason: err instanceof Error ? err.message : String(err),
|
||||
})
|
||||
}
|
||||
|
||||
const payload = await parseResponsePayload<T>(response, endpoint, url)
|
||||
if (!response.ok && !isApiResponse<T>(payload)) {
|
||||
throw new ApiClientError("http_error", `接口请求失败(HTTP ${response.status})`, {
|
||||
endpoint,
|
||||
transport: "direct-fetch",
|
||||
url,
|
||||
status: response.status,
|
||||
status_text: response.statusText,
|
||||
})
|
||||
}
|
||||
return unwrapApiResponse(payload)
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +108,36 @@ function unwrapApiResponse<T>(payload: T | ApiResponse<T>): T {
|
|||
return payload.data
|
||||
}
|
||||
|
||||
async function parseResponsePayload<T>(response: Response, endpoint: string, url: string): Promise<T | ApiResponse<T>> {
|
||||
const contentType = response.headers.get("content-type") ?? ""
|
||||
const isJson = contentType.includes("application/json") || contentType.includes("+json")
|
||||
if (!isJson) {
|
||||
const preview = (await response.text()).slice(0, 240)
|
||||
throw new ApiClientError("invalid_api_response", "接口返回了非 JSON 响应", {
|
||||
endpoint,
|
||||
transport: "direct-fetch",
|
||||
url,
|
||||
status: response.status,
|
||||
status_text: response.statusText,
|
||||
content_type: contentType,
|
||||
preview,
|
||||
})
|
||||
}
|
||||
try {
|
||||
return (await response.json()) as T | ApiResponse<T>
|
||||
} catch (err) {
|
||||
throw new ApiClientError("invalid_api_response", "接口返回格式不正确", {
|
||||
endpoint,
|
||||
transport: "direct-fetch",
|
||||
url,
|
||||
status: response.status,
|
||||
status_text: response.statusText,
|
||||
content_type: contentType,
|
||||
reason: err instanceof Error ? err.message : String(err),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function isApiResponse<T>(payload: T | ApiResponse<T>): payload is ApiResponse<T> {
|
||||
return Boolean(payload && typeof payload === "object" && "ok" in payload)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const endpoints = {
|
|||
workflowStart: (workflowId: string) => `workflows/${workflowId}/start`,
|
||||
workflowCancel: (workflowId: string) => `workflows/${workflowId}/cancel`,
|
||||
workflowArchive: (workflowId: string) => `workflows/${workflowId}/archive`,
|
||||
workflowExecuteCharacter: (workflowId: string) => `workflows/${workflowId}/execute-character`,
|
||||
workflowNodes: (workflowId: string) => `workflows/${workflowId}/nodes`,
|
||||
workflowBranches: (workflowId: string) => `workflows/${workflowId}/branches`,
|
||||
workflowSwitchBranch: (workflowId: string) => `workflows/${workflowId}/switch-branch`,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import type { ProfileWorkflow, WorkflowNode } from "./workflow"
|
||||
|
||||
export interface CharacterProfile {
|
||||
profile_id: string
|
||||
name: string
|
||||
|
|
@ -9,6 +11,7 @@ export interface CharacterProfile {
|
|||
style_prompt?: string | null
|
||||
negative_prompt?: string | null
|
||||
default_model_route?: string | null
|
||||
metadata?: Record<string, unknown>
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
|
@ -30,3 +33,10 @@ export interface QuickProfileDraftResult {
|
|||
negative_prompt: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface QuickProfileDraftSaveResult {
|
||||
draft_id?: string | null
|
||||
profile: CharacterProfile
|
||||
workflow?: ProfileWorkflow
|
||||
nodes?: WorkflowNode[]
|
||||
}
|
||||
|
|
|
|||
文件差异内容过多而无法显示
加载差异
|
|
@ -1,9 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
from backend.routes.workflow_routes import execute_character_workflow
|
||||
from backend.services.character_workflow_service import CharacterWorkflowService
|
||||
from backend.services.profile_service import ProfileService
|
||||
|
|
@ -17,9 +19,10 @@ from database.repositories.workflow_repository import WorkflowRepository
|
|||
|
||||
class CharacterWorkflowServiceTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.tmp_path = Path(".tmp") / f"test_character_workflow_service_{uuid4().hex}"
|
||||
self.tmp_path.mkdir(parents=True, exist_ok=False)
|
||||
self.database = Database(
|
||||
DatabaseSettings(sqlite=SqliteSettings(path=str(Path(self.tmp.name) / "imagestudio.db")))
|
||||
DatabaseSettings(sqlite=SqliteSettings(path=str(self.tmp_path / "imagestudio.db")))
|
||||
)
|
||||
self.database.initialize()
|
||||
self.audit_service = AuditService(self.database)
|
||||
|
|
@ -49,7 +52,7 @@ class CharacterWorkflowServiceTests(unittest.TestCase):
|
|||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
shutil.rmtree(self.tmp_path, ignore_errors=True)
|
||||
|
||||
def test_execute_fast_character_workflow_completes_nodes_with_prompts(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
|
|
@ -83,6 +86,36 @@ class CharacterWorkflowServiceTests(unittest.TestCase):
|
|||
self.assertIn("final character pack", final_pack["prompt"])
|
||||
self.assertIn("consistency reference", final_pack["prompt"])
|
||||
|
||||
def test_execute_completed_character_workflow_requires_branch_before_refresh(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
{"workflow_type": "character_gradual", "display_name": "Gradual"},
|
||||
self.ctx,
|
||||
)
|
||||
first = self.character_service.execute_workflow(detail.workflow.workflow_id, self.ctx)
|
||||
|
||||
with self.assertRaises(ApiError) as raised:
|
||||
self.character_service.execute_workflow(detail.workflow.workflow_id, self.ctx)
|
||||
|
||||
self.assertEqual(first["workflow"]["status"], "completed")
|
||||
self.assertEqual(raised.exception.error_code, ErrorCode.VALIDATION_FAILED)
|
||||
self.assertEqual(raised.exception.details["suggested_action"], "create_branch")
|
||||
|
||||
def test_execute_quick_profile_workflow_completes_profile_draft_nodes(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
{"workflow_type": "quick_profile", "display_name": "Quick profile"},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
result = self.character_service.execute_workflow(detail.workflow.workflow_id, self.ctx)
|
||||
|
||||
self.assertEqual(result["workflow"]["status"], "completed")
|
||||
self.assertEqual([node["node_key"] for node in result["nodes"]], ["questionnaire", "preview"])
|
||||
preview = result["nodes"][-1]
|
||||
self.assertIn("saved quick profile prompts", preview["prompt"])
|
||||
self.assertEqual(preview["metadata"]["execution"]["workflow_type"], "quick_profile")
|
||||
|
||||
def test_execute_character_workflow_route_requires_write_permission(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.routes.history_routes import adopt_node_image, list_workflow_history
|
||||
from backend.routes.history_routes import adopt_node_image, list_workflow_history, save_workflow_history
|
||||
from backend.services.history_service import HistoryService
|
||||
from backend.services.image_service import ImageService
|
||||
from backend.services.profile_service import ProfileService
|
||||
|
|
@ -19,9 +20,10 @@ from database.repositories.workflow_repository import WorkflowRepository
|
|||
|
||||
class HistoryServiceTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.tmp_path = Path(".tmp") / f"test_history_service_{uuid4().hex}"
|
||||
self.tmp_path.mkdir(parents=True, exist_ok=False)
|
||||
self.database = Database(
|
||||
DatabaseSettings(sqlite=SqliteSettings(path=str(Path(self.tmp.name) / "imagestudio.db")))
|
||||
DatabaseSettings(sqlite=SqliteSettings(path=str(self.tmp_path / "imagestudio.db")))
|
||||
)
|
||||
self.database.initialize()
|
||||
self.audit_service = AuditService(self.database)
|
||||
|
|
@ -68,7 +70,7 @@ class HistoryServiceTests(unittest.TestCase):
|
|||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
shutil.rmtree(self.tmp_path, ignore_errors=True)
|
||||
|
||||
def test_adopt_node_image_writes_history_and_selects_image(self):
|
||||
history = self.history_service.adopt_node_image(
|
||||
|
|
@ -106,6 +108,16 @@ class HistoryServiceTests(unittest.TestCase):
|
|||
self.assertTrue(listed["ok"])
|
||||
self.assertEqual(len(listed["data"]), 1)
|
||||
|
||||
snapshot = save_workflow_history(
|
||||
self.ctx,
|
||||
workflow_id,
|
||||
{"title": "Manual snapshot", "include_nodes": True},
|
||||
self.history_service,
|
||||
)
|
||||
self.assertTrue(snapshot["ok"])
|
||||
self.assertEqual(snapshot["data"]["action"], "save_version")
|
||||
self.assertEqual(snapshot["data"]["title"], "Manual snapshot")
|
||||
|
||||
read_only = RequestContext.from_astrbot(username="viewer", user_id="viewer_001")
|
||||
denied = adopt_node_image(
|
||||
read_only,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
from backend.services.image_service import ImageService
|
||||
|
|
@ -18,8 +19,9 @@ from database.repositories.workflow_repository import WorkflowRepository
|
|||
|
||||
class ImageServiceTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
db_path = Path(self.tmp.name) / "imagestudio.db"
|
||||
self.tmp_path = Path(".tmp") / f"test_image_service_{uuid4().hex}"
|
||||
self.tmp_path.mkdir(parents=True, exist_ok=False)
|
||||
db_path = self.tmp_path / "imagestudio.db"
|
||||
self.database = Database(DatabaseSettings(sqlite=SqliteSettings(path=str(db_path))))
|
||||
self.database.initialize()
|
||||
self.audit_service = AuditService(self.database)
|
||||
|
|
@ -58,7 +60,7 @@ class ImageServiceTests(unittest.TestCase):
|
|||
self.node = detail.nodes[0]
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
shutil.rmtree(self.tmp_path, ignore_errors=True)
|
||||
|
||||
def test_create_image_inherits_profile_and_workflow_from_node(self):
|
||||
image = self.image_service.create_image(
|
||||
|
|
@ -130,6 +132,16 @@ class ImageServiceTests(unittest.TestCase):
|
|||
self.assertFalse(unselected.is_selected)
|
||||
self.assertIsNone(node_after.selected_image_id)
|
||||
|
||||
def test_select_image_rejects_locked_completed_node(self):
|
||||
image = self._create_image("storage://images/locked.png")
|
||||
self.workflow_service.update_node(self.node.node_id, {"status": "completed"}, self.ctx)
|
||||
|
||||
with self.assertRaises(ApiError) as raised:
|
||||
self.image_service.select_image(image.image_id, self.ctx)
|
||||
|
||||
self.assertEqual(raised.exception.error_code, ErrorCode.VALIDATION_FAILED)
|
||||
self.assertEqual(raised.exception.details["suggested_action"], "create_branch")
|
||||
|
||||
def test_delete_image_metadata_removes_record_and_writes_audit(self):
|
||||
image = self._create_image("storage://images/delete.png")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,38 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.routes.profile_routes import save_quick_profile_draft
|
||||
from backend.services.profile_service import ProfileService
|
||||
from backend.services.quick_profile_service import QuickProfileService
|
||||
from backend.services.workflow_service import WorkflowService
|
||||
from core.audit_service import AuditService
|
||||
from core.identity import RequestContext
|
||||
from database.db_helper import Database, DatabaseSettings, SqliteSettings
|
||||
from database.repositories.profile_repository import ProfileRepository
|
||||
from database.repositories.workflow_repository import WorkflowRepository
|
||||
|
||||
|
||||
class QuickProfileServiceTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.tmp_path = Path(".tmp") / f"test_quick_profile_service_{uuid4().hex}"
|
||||
self.tmp_path.mkdir(parents=True, exist_ok=False)
|
||||
self.database = Database(
|
||||
DatabaseSettings(sqlite=SqliteSettings(path=str(Path(self.tmp.name) / "imagestudio.db")))
|
||||
DatabaseSettings(sqlite=SqliteSettings(path=str(self.tmp_path / "imagestudio.db")))
|
||||
)
|
||||
self.database.initialize()
|
||||
self.profile_service = ProfileService(ProfileRepository(self.database), AuditService(self.database))
|
||||
self.profile_repository = ProfileRepository(self.database)
|
||||
self.workflow_repository = WorkflowRepository(self.database)
|
||||
self.audit_service = AuditService(self.database)
|
||||
self.profile_service = ProfileService(self.profile_repository, self.audit_service)
|
||||
self.workflow_service = WorkflowService(
|
||||
self.workflow_repository,
|
||||
self.profile_repository,
|
||||
self.audit_service,
|
||||
)
|
||||
self.quick_service = QuickProfileService()
|
||||
self.ctx = RequestContext.from_astrbot(
|
||||
username="admin",
|
||||
|
|
@ -29,7 +41,7 @@ class QuickProfileServiceTests(unittest.TestCase):
|
|||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
shutil.rmtree(self.tmp_path, ignore_errors=True)
|
||||
|
||||
def test_save_draft_persists_preview_as_character_profile(self):
|
||||
draft = self.quick_service.create_draft(
|
||||
|
|
@ -47,7 +59,12 @@ class QuickProfileServiceTests(unittest.TestCase):
|
|||
}
|
||||
)
|
||||
|
||||
saved = self.quick_service.save_draft({"draft": draft}, self.profile_service, self.ctx)
|
||||
saved = self.quick_service.save_draft(
|
||||
{"draft": draft, "create_workflow": True},
|
||||
self.profile_service,
|
||||
self.ctx,
|
||||
self.workflow_service,
|
||||
)
|
||||
|
||||
profile = self.profile_service.get_profile(saved["profile"]["profile_id"])
|
||||
self.assertEqual(profile.name, "Nova")
|
||||
|
|
@ -56,6 +73,11 @@ class QuickProfileServiceTests(unittest.TestCase):
|
|||
self.assertEqual(profile.style_prompt, "watercolor")
|
||||
self.assertEqual(profile.metadata["source"], "quick_profile")
|
||||
self.assertEqual(profile.metadata["draft_id"], draft["draft_id"])
|
||||
self.assertEqual(saved["workflow"]["profile_id"], profile.profile_id)
|
||||
self.assertEqual(saved["workflow"]["workflow_type"], "quick_profile")
|
||||
self.assertEqual(saved["workflow"]["metadata"]["source"], "quick_profile")
|
||||
self.assertEqual(saved["workflow"]["metadata"]["draft_id"], draft["draft_id"])
|
||||
self.assertEqual([node["node_key"] for node in saved["nodes"]], ["questionnaire", "preview"])
|
||||
|
||||
def test_save_quick_profile_route_requires_write_permission(self):
|
||||
draft = self.quick_service.create_draft({"questionnaire": {"name": "Nova"}})
|
||||
|
|
@ -78,6 +100,8 @@ class QuickProfileServiceTests(unittest.TestCase):
|
|||
self.assertEqual(denied["error_code"], "FORBIDDEN")
|
||||
self.assertTrue(allowed["ok"])
|
||||
self.assertEqual(allowed["data"]["profile"]["name"], "Nova")
|
||||
self.assertEqual(allowed["data"]["workflow"]["workflow_type"], "quick_profile")
|
||||
self.assertEqual([node["node_key"] for node in allowed["data"]["nodes"]], ["questionnaire", "preview"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from adapters.astrbot_adapter import (
|
||||
dispatch_extension_request,
|
||||
|
|
@ -44,6 +45,7 @@ class RouteRegistryTests(unittest.TestCase):
|
|||
self.assertIn(("POST", "workflows/{workflow_id}/cancel"), keys)
|
||||
self.assertIn(("POST", "workflows/{workflow_id}/archive"), keys)
|
||||
self.assertIn(("POST", "workflows/{workflow_id}/execute-character"), keys)
|
||||
self.assertIn(("POST", "workflows/{workflow_id}/history"), keys)
|
||||
self.assertIn(("GET", "nodes/{node_id}/review"), keys)
|
||||
self.assertIn(("GET", "nodes/{node_id}/dependency-context"), keys)
|
||||
self.assertIn(("GET", "workflows/{workflow_id}/review"), keys)
|
||||
|
|
@ -92,8 +94,9 @@ class RouteRegistryTests(unittest.TestCase):
|
|||
self.assertTrue(any(route["endpoint"] == "dashboard/summary" for route in manifest["api_routes"]))
|
||||
|
||||
def test_webui_adapter_resolves_standalone_assets(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
root = Path(".tmp") / f"test_route_registry_webui_{uuid4().hex}"
|
||||
try:
|
||||
root.mkdir(parents=True, exist_ok=False)
|
||||
web = root / "web"
|
||||
assets = web / "assets"
|
||||
assets.mkdir(parents=True)
|
||||
|
|
@ -113,13 +116,15 @@ class RouteRegistryTests(unittest.TestCase):
|
|||
"/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/../config.yaml",
|
||||
service,
|
||||
)
|
||||
finally:
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
self.assertTrue(index["ok"])
|
||||
self.assertEqual(index["data"]["relative_path"], "index.html")
|
||||
self.assertEqual(index["data"]["body_base64"], "PGh0bWw-PC9odG1sPg")
|
||||
self.assertEqual(index["data"]["cache_control"], "public, max-age=300")
|
||||
self.assertTrue(script["ok"])
|
||||
self.assertEqual(script["data"]["content_type"], "text/javascript")
|
||||
self.assertIn(script["data"]["content_type"], {"text/javascript", "application/javascript"})
|
||||
self.assertTrue(script["data"]["body_base64"])
|
||||
self.assertFalse(escaped["ok"])
|
||||
self.assertEqual(escaped["error_code"], "FORBIDDEN")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.routes.node_routes import generate_node
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
|
|
@ -34,8 +35,8 @@ from engines.image_provider import GeneratedImagePayload, ImageGenerationResult,
|
|||
|
||||
class SingleFlowGenerationTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self.tmp.name)
|
||||
self.root = Path(".tmp") / f"test_single_flow_generation_{uuid4().hex}"
|
||||
self.root.mkdir(parents=True, exist_ok=False)
|
||||
self.config_path = self.root / "config.yaml"
|
||||
self.config_path.write_text(
|
||||
f"""
|
||||
|
|
@ -93,7 +94,7 @@ storage:
|
|||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
shutil.rmtree(self.root, ignore_errors=True)
|
||||
|
||||
def test_generate_node_creates_task_images_and_vfs_files(self):
|
||||
profile = self.profile_service.create_profile({"name": "Nova"}, self.ctx)
|
||||
|
|
@ -166,6 +167,34 @@ storage:
|
|||
self.assertEqual(len(self.image_service.list_by_node(node_id)), 2)
|
||||
self.assertEqual(len(self.event_bus.history("generation.node_queued")), 1)
|
||||
|
||||
def test_generate_completed_node_requires_branch_for_new_request(self):
|
||||
profile = self.profile_service.create_profile({"name": "Nova"}, self.ctx)
|
||||
workflow = self.workflow_service.create_workflow(
|
||||
profile.profile_id,
|
||||
{"workflow_type": "single_image", "display_name": "Single"},
|
||||
self.ctx,
|
||||
)
|
||||
node_id = workflow.nodes[0].node_id
|
||||
first = generate_node(
|
||||
self.ctx,
|
||||
node_id,
|
||||
{"prompt_patch": "white shirt", "idempotency_key": "node-generate-lock-001"},
|
||||
generation_service=self.generation_service,
|
||||
)
|
||||
|
||||
second = generate_node(
|
||||
self.ctx,
|
||||
node_id,
|
||||
{"prompt_patch": "black shirt", "idempotency_key": "node-generate-lock-002"},
|
||||
generation_service=self.generation_service,
|
||||
)
|
||||
|
||||
self.assertTrue(first["ok"])
|
||||
self.assertFalse(second["ok"])
|
||||
self.assertEqual(second["error_code"], "VALIDATION_FAILED")
|
||||
self.assertEqual(second["details"]["suggested_action"], "create_branch")
|
||||
self.assertEqual(self.queue_service.list_jobs(page=1, page_size=10).total, 1)
|
||||
|
||||
def test_generate_node_records_resolved_model_route(self):
|
||||
self.model_provider_service.upsert_provider(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
from backend.services.profile_service import ProfileService
|
||||
|
|
@ -17,8 +18,9 @@ from database.repositories.workflow_repository import WorkflowRepository
|
|||
|
||||
class WorkflowServiceTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
db_path = Path(self.tmp.name) / "imagestudio.db"
|
||||
self.tmp_path = Path(".tmp") / f"test_workflow_service_{uuid4().hex}"
|
||||
self.tmp_path.mkdir(parents=True, exist_ok=False)
|
||||
db_path = self.tmp_path / "imagestudio.db"
|
||||
self.database = Database(DatabaseSettings(sqlite=SqliteSettings(path=str(db_path))))
|
||||
self.database.initialize()
|
||||
self.audit_service = AuditService(self.database)
|
||||
|
|
@ -41,7 +43,7 @@ class WorkflowServiceTests(unittest.TestCase):
|
|||
self.profile = self.profile_service.create_profile({"name": "Nova"}, self.ctx)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
shutil.rmtree(self.tmp_path, ignore_errors=True)
|
||||
|
||||
def test_create_single_image_workflow_creates_virtual_node(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
|
|
@ -153,6 +155,82 @@ class WorkflowServiceTests(unittest.TestCase):
|
|||
branches = self.workflow_service.list_branches(detail.workflow.workflow_id)
|
||||
self.assertEqual([item.branch_name for item in branches], ["alt_pose"])
|
||||
|
||||
def test_create_branch_from_base_node_preserves_ancestors_and_resets_cut(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
{
|
||||
"workflow_type": "character_fast",
|
||||
"display_name": "Fast character",
|
||||
},
|
||||
self.ctx,
|
||||
)
|
||||
nodes = self.workflow_service.list_nodes(detail.workflow.workflow_id)
|
||||
first, second, third = nodes
|
||||
self.workflow_service.update_node(
|
||||
first.node_id,
|
||||
{"status": "completed", "selected_image_id": "img_first"},
|
||||
self.ctx,
|
||||
)
|
||||
self.workflow_service.update_node(
|
||||
second.node_id,
|
||||
{"status": "completed", "selected_image_id": "img_second"},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
self.workflow_service.create_branch(
|
||||
detail.workflow.workflow_id,
|
||||
{
|
||||
"branch_name": "change_candidates",
|
||||
"base_node_id": second.node_id,
|
||||
"copy_nodes": True,
|
||||
},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
copied_nodes = self.workflow_repository.list_nodes(
|
||||
detail.workflow.workflow_id,
|
||||
branch_name="change_candidates",
|
||||
)
|
||||
copied_first, copied_second, copied_third = copied_nodes
|
||||
self.assertEqual(copied_first.status, "completed")
|
||||
self.assertEqual(copied_first.selected_image_id, "img_first")
|
||||
self.assertTrue(copied_first.metadata["branch_locked_ancestor"])
|
||||
self.assertEqual(copied_second.status, "draft")
|
||||
self.assertIsNone(copied_second.selected_image_id)
|
||||
self.assertTrue(copied_second.metadata["branch_editable_from_cut"])
|
||||
self.assertEqual(copied_second.metadata["copied_from_node_id"], second.node_id)
|
||||
self.assertEqual(copied_third.status, "draft")
|
||||
self.assertIsNone(copied_third.selected_image_id)
|
||||
self.assertEqual(copied_third.metadata["copied_from_node_id"], third.node_id)
|
||||
|
||||
def test_create_branch_rejects_unknown_base_node_without_persisting_branch(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
{
|
||||
"workflow_type": "character_fast",
|
||||
"display_name": "Fast character",
|
||||
},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
with self.assertRaises(ApiError) as raised:
|
||||
self.workflow_service.create_branch(
|
||||
detail.workflow.workflow_id,
|
||||
{
|
||||
"branch_name": "bad_cut",
|
||||
"base_node_id": "node_missing",
|
||||
"copy_nodes": True,
|
||||
},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
self.assertEqual(raised.exception.error_code, ErrorCode.VALIDATION_FAILED)
|
||||
branch_names = [
|
||||
branch.branch_name
|
||||
for branch in self.workflow_service.list_branches(detail.workflow.workflow_id)
|
||||
]
|
||||
self.assertNotIn("bad_cut", branch_names)
|
||||
|
||||
def test_create_and_list_nodes_ordered_by_sort_order(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
|
|
@ -222,6 +300,38 @@ class WorkflowServiceTests(unittest.TestCase):
|
|||
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
def test_completed_node_rejects_mutating_update_until_branch_is_created(self):
|
||||
detail = self.workflow_service.create_workflow(
|
||||
self.profile.profile_id,
|
||||
{
|
||||
"workflow_type": "character_gradual",
|
||||
"display_name": "Manual character flow",
|
||||
"auto_create_nodes": False,
|
||||
},
|
||||
self.ctx,
|
||||
)
|
||||
node = self.workflow_service.create_node(
|
||||
detail.workflow.workflow_id,
|
||||
{"node_key": "portrait", "title": "Portrait"},
|
||||
self.ctx,
|
||||
)
|
||||
completed = self.workflow_service.update_node(
|
||||
node.node_id,
|
||||
{"status": "completed", "prompt": "portrait, silver hair"},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
with self.assertRaises(ApiError) as raised:
|
||||
self.workflow_service.update_node(
|
||||
node.node_id,
|
||||
{"prompt": "portrait, black hair"},
|
||||
self.ctx,
|
||||
)
|
||||
|
||||
self.assertEqual(raised.exception.error_code, ErrorCode.VALIDATION_FAILED)
|
||||
self.assertEqual(raised.exception.details["suggested_action"], "create_branch")
|
||||
self.assertEqual(raised.exception.details["base_node_id"], completed.node_id)
|
||||
|
||||
def test_workflow_service_publishes_status_events(self):
|
||||
event_bus = EventBus()
|
||||
workflow_service = WorkflowService(
|
||||
|
|
|
|||
文件差异因一行或多行过长而隐藏
50
web/assets/index-B2NiW3rX.js
普通文件
50
web/assets/index-B2NiW3rX.js
普通文件
文件差异因一行或多行过长而隐藏
文件差异因一行或多行过长而隐藏
文件差异因一行或多行过长而隐藏
|
|
@ -1,3 +1,3 @@
|
|||
<script type="module" crossorigin src="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-2LShDLc4.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-DEHTkyVO.css">
|
||||
<script type="module" crossorigin src="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-B2NiW3rX.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-CPo7NaFF.css">
|
||||
<div id="app"></div>
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用