feat: extend workflow and materials workbench

这个提交存在于:
YokiiroBW 2026-07-10 01:25:15 +08:00
父节点 b61c6274e5
当前提交 239041f426
共有 35 个文件被更改,包括 6932 次插入 和 203 次删除

查看文件

@ -122,6 +122,8 @@ def _step_instruction(workflow_type: str, node_key: str) -> str:
}
gradual = {
"profile_brief": "core identity and visual anchors",
"prompt_plan": "prompt matrix for portrait, half body, full body, and design sheet nodes",
"material_bind": "reference material binding rules for style, composition, clothing, shoes, and accessories",
"headshot": "headshot, face, hair, eyes, expression",
"half_body": "half body, upper outfit, posture and silhouette",
"full_body": "full body, complete outfit and proportions",

查看文件

@ -9,6 +9,7 @@ from backend.dto.job_dto import GenerationTask
from backend.services.cost_guard_service import CostGuardService
from backend.services.image_service import ImageService
from backend.services.model_provider_service import ModelProviderService
from backend.services.node_dependency_context_service import NodeDependencyContextService
from backend.services.prompt_expansion_service import PromptExpansionService
from backend.services.queue_service import QueueService
from backend.services.workflow_service import (
@ -247,7 +248,13 @@ class GenerationService:
profile = self.workflow_service.profile_repository.get(profile_id)
if profile is None:
return None
return self.prompt_expansion_service.expand_for_node(profile, node, payload)
enriched_payload = dict(payload)
if "dependency_context" not in enriched_payload:
enriched_payload["dependency_context"] = NodeDependencyContextService(
self.workflow_service,
self.image_service,
).get_context(node.node_id)
return self.prompt_expansion_service.expand_for_node(profile, node, enriched_payload)
def _publish(self, event_type: str, payload: dict[str, Any]) -> None:
if self.event_bus:

查看文件

@ -7,6 +7,7 @@ from uuid import uuid4
from backend.dto.common import ApiError, ErrorCode
from backend.dto.workflow_dto import WorkflowHistoryEntry
from backend.dto.workflow_dto import ProfileWorkflow, WorkflowNode
from backend.services.image_service import ImageService
from backend.services.workflow_service import WorkflowService
from core.audit_service import AuditService
@ -35,9 +36,11 @@ class HistoryService:
) -> WorkflowHistoryEntry:
node = self.workflow_service.get_node(node_id)
workflow = self.workflow_service.get_workflow(node.workflow_id).workflow
payload_metadata = _mapping(payload.get("metadata"))
image_id = str(payload.get("image_id") or "").strip()
if not image_id:
raise ApiError(ErrorCode.VALIDATION_FAILED, "image_id is required", {"field": "image_id"})
next_node = self._resolve_handoff_next_node(workflow, payload_metadata)
image = self.image_service.get_image(image_id)
if image.node_id != node_id:
raise ApiError(
@ -47,12 +50,15 @@ class HistoryService:
)
if image.is_archived:
raise ApiError(ErrorCode.VALIDATION_FAILED, "archived image cannot be adopted", {"image_id": image_id})
selected = self.image_service.select_image(image_id, ctx) if not image.is_selected else image
updated_node = self.workflow_service.update_node(
node_id,
{"status": "selected", "selected_image_id": selected.image_id},
{"status": "selected", "selected_image_id": image.image_id},
ctx,
allow_locked_adoption=True,
)
selected = self.image_service.image_repository.select_exclusive(image) if not image.is_selected else image
if selected is None:
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "image not found", {"image_id": image_id})
history = self.workflow_repository.create_history(
{
"history_id": payload.get("history_id") or new_history_id(),
@ -68,10 +74,19 @@ class HistoryService:
"image_uri": selected.image_uri,
"thumbnail_uri": selected.thumbnail_uri,
"source": "node_adoption",
**(payload.get("metadata") or {}),
**payload_metadata,
},
}
)
self._persist_stage_handoff(
workflow,
updated_node,
selected,
history,
payload_metadata,
next_node,
ctx,
)
self.audit_service.record(
ctx=ctx,
action="adopt_image",
@ -81,6 +96,103 @@ class HistoryService:
)
return history
def _resolve_handoff_next_node(
self,
workflow: ProfileWorkflow,
metadata: dict[str, Any],
) -> WorkflowNode | None:
next_node_id = _optional_text(metadata.get("next_backend_node_id"))
if not next_node_id:
return None
next_node = self.workflow_service.get_node(next_node_id)
if next_node.workflow_id != workflow.workflow_id:
raise ApiError(
ErrorCode.VALIDATION_FAILED,
"next_backend_node_id does not belong to this workflow",
{"workflow_id": workflow.workflow_id, "next_backend_node_id": next_node_id},
)
if next_node.branch_name != workflow.current_branch:
raise ApiError(
ErrorCode.VALIDATION_FAILED,
"next_backend_node_id does not belong to the current branch",
{
"workflow_id": workflow.workflow_id,
"current_branch": workflow.current_branch,
"next_backend_node_id": next_node_id,
"next_branch_name": next_node.branch_name,
},
)
return next_node
def _persist_stage_handoff(
self,
workflow: ProfileWorkflow,
source_node: WorkflowNode,
selected,
history: WorkflowHistoryEntry,
metadata: dict[str, Any],
next_node: WorkflowNode | None,
ctx: RequestContext,
) -> None:
if next_node is None:
return
existing_metadata = dict(workflow.metadata or {})
existing_stage_inputs = existing_metadata.get("stage_inputs")
stage_inputs = dict(existing_stage_inputs) if isinstance(existing_stage_inputs, dict) else {}
handoff_record = {
"schema_version": STAGE_INPUT_SCHEMA_VERSION,
"image_id": selected.image_id,
"image_uri": selected.image_uri,
"thumbnail_uri": selected.thumbnail_uri,
"from_node_id": source_node.node_id,
"from_node_key": source_node.node_key,
"from_review_node_id": metadata.get("ui_review_node_id"),
"source_ui_node_id": metadata.get("source_ui_node_id"),
"next_ui_node_id": metadata.get("next_ui_node_id"),
"history_id": history.history_id,
"role": metadata.get("handoff_role") or "next_stage_input",
"handoff_bucket": metadata.get("handoff_bucket"),
"branch_name": source_node.branch_name,
"model_route": selected.model_route,
"model_used": selected.model_used,
"positive_prompt": selected.positive_prompt or source_node.prompt,
"negative_prompt": selected.negative_prompt or source_node.negative_prompt,
"locked_source_node": True,
"confirmed_at": history.created_at,
}
stage_inputs[next_node.node_id] = handoff_record
handoff_log = existing_metadata.get("stage_review_handoffs")
if not isinstance(handoff_log, list):
handoff_log = []
handoff_log = [
*handoff_log,
{
"history_id": history.history_id,
"from_node_id": source_node.node_id,
"to_node_id": next_node.node_id,
"image_id": selected.image_id,
"role": handoff_record["role"],
"confirmed_at": history.created_at,
},
][-20:]
self.workflow_service.update_workflow(
workflow.workflow_id,
{
"current_node_id": next_node.node_id,
"metadata": {
**existing_metadata,
"stage_input_schema_version": STAGE_INPUT_SCHEMA_VERSION,
"stage_inputs": stage_inputs,
"stage_review_handoffs": handoff_log,
"last_stage_review_confirmed_at": history.created_at,
"last_stage_review_node_id": metadata.get("ui_review_node_id"),
"last_stage_review_image_id": selected.image_id,
"current_stage_input_image_id": selected.image_id,
},
},
ctx,
)
def list_workflow_history(
self,
workflow_id: str,
@ -148,8 +260,15 @@ def new_history_id() -> str:
return f"hist_{uuid4().hex}"
STAGE_INPUT_SCHEMA_VERSION = "2026-07-09.stage-input-bucket.v1"
def _optional_text(value: Any) -> str | None:
if value is None:
return None
text = str(value).strip()
return text or None
def _mapping(value: Any) -> dict[str, Any]:
return value if isinstance(value, dict) else {}

查看文件

@ -0,0 +1,297 @@
"""Normalize workflow material binding payloads for generation nodes."""
from __future__ import annotations
from copy import deepcopy
from typing import Any
from backend.dto.workflow_dto import WorkflowNode
MATERIAL_BINDING_SCHEMA_VERSION = "2026-07-09.material-binding-schema.v1"
REFERENCE_POLICY = {
"mode": "explicit_only",
"default_use_reference": False,
"empty_material_means": "do_not_use_reference",
}
STAGE_NODE_KEYS: dict[str, tuple[str, ...]] = {
"profile-prep": ("profile_brief", "prompt_plan", "material_bind"),
"portrait-draft": ("headshot", "fast_candidates"),
"halfbody-draft": ("half_body",),
"body-sheet": ("full_body", "expression_sheet", "pose_sheet"),
"review-archive": ("style_lock", "final_pack", "fast_final"),
}
STRENGTHS: dict[str, tuple[str, float]] = {
"强": ("strong", 0.85),
"strong": ("strong", 0.85),
"high": ("strong", 0.85),
"中": ("medium", 0.55),
"medium": ("medium", 0.55),
"mid": ("medium", 0.55),
"弱": ("weak", 0.3),
"weak": ("weak", 0.3),
"low": ("weak", 0.3),
}
def normalize_material_bindings(
payload: Any,
workflow_nodes: list[WorkflowNode] | None = None,
) -> dict[str, Any]:
if isinstance(payload, dict) and payload.get("schema_version") == MATERIAL_BINDING_SCHEMA_VERSION:
normalized = deepcopy(payload)
if workflow_nodes:
rules = normalized.get("active_rules")
if not isinstance(rules, list):
rules = [
rule
for rule in normalized.get("rules", [])
if isinstance(rule, dict) and rule.get("use_reference")
]
normalized["by_node_id"] = _index_by_node_id(rules, workflow_nodes)
return normalized
source = _extract_source_payload(payload)
rules = [
_normalize_rule(rule, index + 1)
for index, rule in enumerate(source.get("rules", []) if isinstance(source.get("rules"), list) else [])
if isinstance(rule, dict)
]
active_rules = [rule for rule in rules if rule["use_reference"]]
by_stage = _index_by_stage(active_rules)
by_node_key = _index_by_node_key(active_rules)
by_node_id = _index_by_node_id(active_rules, workflow_nodes or [])
selected_material_ids = _string_list(source.get("selected_material_ids"))
if not selected_material_ids:
selected_material_ids = [rule["material"]["material_id"] for rule in active_rules]
return {
"schema_version": MATERIAL_BINDING_SCHEMA_VERSION,
"reference_policy": deepcopy(REFERENCE_POLICY),
"profile_id": _optional_text(source.get("profile_id")),
"profile_name": _optional_text(source.get("profile_name")),
"selected_material_ids": _unique_texts(selected_material_ids),
"rules": rules,
"active_rules": active_rules,
"by_stage": by_stage,
"by_node_key": by_node_key,
"by_node_id": by_node_id,
"node_parameters": by_node_id,
"prompt_context": _prompt_context(active_rules),
"summary": {
"rule_count": len(rules),
"active_rule_count": len(active_rules),
"has_references": bool(active_rules),
"disabled_categories": [rule["category"] for rule in rules if not rule["use_reference"]],
"target_stage_ids": sorted(by_stage),
"target_node_keys": sorted(by_node_key),
},
}
def material_bindings_for_node(
workflow_metadata: dict[str, Any],
node: WorkflowNode,
workflow_nodes: list[WorkflowNode] | None = None,
) -> dict[str, Any]:
normalized = normalize_material_bindings(workflow_metadata.get("material_bindings"), workflow_nodes)
return node_material_binding_view(normalized, node)
def node_material_binding_view(normalized: dict[str, Any], node: WorkflowNode) -> dict[str, Any]:
by_node_id = normalized.get("by_node_id") if isinstance(normalized.get("by_node_id"), dict) else {}
by_node_key = normalized.get("by_node_key") if isinstance(normalized.get("by_node_key"), dict) else {}
node_view = by_node_id.get(node.node_id)
if not isinstance(node_view, dict):
node_view = _node_view(
active_rules=by_node_key.get(node.node_key, []),
node_id=node.node_id,
node_key=node.node_key,
title=node.title,
)
return {
"schema_version": normalized.get("schema_version", MATERIAL_BINDING_SCHEMA_VERSION),
"reference_policy": normalized.get("reference_policy", deepcopy(REFERENCE_POLICY)),
"summary": normalized.get("summary", {}),
"target_node_id": node.node_id,
"target_node_key": node.node_key,
"target_node_title": node.title,
**node_view,
}
def _extract_source_payload(payload: Any) -> dict[str, Any]:
if not isinstance(payload, dict):
return {}
material_bindings = payload.get("material_bindings")
if isinstance(material_bindings, dict) and isinstance(material_bindings.get("rules"), list):
return material_bindings
if isinstance(payload.get("rules"), list):
return payload
return {}
def _normalize_rule(rule: dict[str, Any], ordinal: int) -> dict[str, Any]:
material_id = _optional_text(rule.get("material_id"))
material_prompt = _optional_text(rule.get("material_prompt"))
category = _optional_text(rule.get("category")) or "other"
target_stages = _target_stages(rule.get("bind_to_stages"))
target_node_keys = _unique_texts(
node_key for stage in target_stages for node_key in STAGE_NODE_KEYS.get(stage["stage_id"], ())
)
strength_label = _optional_text(rule.get("reference_strength")) or "medium"
strength_key, strength_weight = STRENGTHS.get(strength_label.lower(), STRENGTHS.get(strength_label, ("medium", 0.55)))
use_reference = bool(material_id or material_prompt)
return {
"id": _optional_text(rule.get("id")) or f"material_binding_{ordinal:02d}",
"category": category,
"use_reference": use_reference,
"required": bool(rule.get("required")),
"status": _optional_text(rule.get("status")) or ("ready" if use_reference else "pending"),
"conflict": _optional_text(rule.get("conflict")),
"material": {
"material_id": material_id,
"label": _optional_text(rule.get("material_label")),
"group": _optional_text(rule.get("material_group")),
"prompt": material_prompt,
"colors": _string_list(rule.get("material_colors")),
},
"target_stages": target_stages,
"target_node_keys": target_node_keys,
"inheritance_rule": _optional_text(rule.get("inheritance_rule")) or "",
"reference_strength": {
"label": strength_label,
"key": strength_key,
"weight": strength_weight,
},
"generation_params": {
"reference_policy": "explicit_only" if use_reference else "do_not_use_reference",
"reference_strength": strength_key if use_reference else "none",
"reference_weight": strength_weight if use_reference else 0,
},
"expand_to_nodes_later": True,
}
def _target_stages(value: Any) -> list[dict[str, str]]:
if not isinstance(value, list):
return []
stages: list[dict[str, str]] = []
for item in value:
if not isinstance(item, dict):
continue
stage_id = _optional_text(item.get("stage_id") or item.get("id"))
if not stage_id:
continue
stage = {
"stage_id": stage_id,
"stage_title": _optional_text(item.get("stage_title") or item.get("title")) or stage_id,
}
if stage not in stages:
stages.append(stage)
return stages
def _index_by_stage(rules: list[dict[str, Any]]) -> dict[str, dict[str, Any]]:
result: dict[str, dict[str, Any]] = {}
for rule in rules:
for stage in rule["target_stages"]:
stage_id = stage["stage_id"]
bucket = result.setdefault(
stage_id,
{
"stage_id": stage_id,
"stage_title": stage["stage_title"],
"active_bindings": [],
"material_prompts": [],
},
)
bucket["active_bindings"].append(rule)
if rule["material"]["prompt"]:
bucket["material_prompts"].append(rule["material"]["prompt"])
return result
def _index_by_node_key(rules: list[dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
result: dict[str, list[dict[str, Any]]] = {}
for rule in rules:
for node_key in rule["target_node_keys"]:
result.setdefault(node_key, []).append(rule)
return result
def _index_by_node_id(
rules: list[dict[str, Any]],
workflow_nodes: list[WorkflowNode],
) -> dict[str, dict[str, Any]]:
by_node_key = _index_by_node_key(rules)
return {
node.node_id: _node_view(by_node_key.get(node.node_key, []), node.node_id, node.node_key, node.title)
for node in workflow_nodes
if by_node_key.get(node.node_key)
}
def _node_view(
active_rules: list[dict[str, Any]],
node_id: str | None,
node_key: str,
title: str,
) -> dict[str, Any]:
prompts = [rule["material"]["prompt"] for rule in active_rules if rule["material"]["prompt"]]
return {
"target_node_id": node_id,
"target_node_key": node_key,
"target_node_title": title,
"reference_policy": deepcopy(REFERENCE_POLICY),
"has_references": bool(active_rules),
"active_bindings": deepcopy(active_rules),
"material_prompts": prompts,
"prompt_context": ", ".join(prompts),
"generation_params": {
"reference_material_ids": [
rule["material"]["material_id"] for rule in active_rules if rule["material"]["material_id"]
],
"reference_prompts": prompts,
"reference_strengths": [rule["reference_strength"] for rule in active_rules],
},
}
def _prompt_context(rules: list[dict[str, Any]]) -> list[dict[str, str]]:
return [
{
"category": rule["category"],
"material_id": rule["material"]["material_id"] or "",
"prompt": rule["material"]["prompt"] or "",
"target_node_keys": ", ".join(rule["target_node_keys"]),
}
for rule in rules
if rule["material"]["prompt"]
]
def _string_list(value: Any) -> list[str]:
if isinstance(value, str):
return [value] if value.strip() else []
if not isinstance(value, list):
return []
return _unique_texts(str(item).strip() for item in value if str(item or "").strip())
def _unique_texts(values: Any) -> list[str]:
result: list[str] = []
for value in values:
text = str(value or "").strip()
if text and text not in result:
result.append(text)
return result
def _optional_text(value: Any) -> str | None:
if value is None:
return None
text = str(value).strip()
return text or None

查看文件

@ -78,6 +78,12 @@ class MaterialService:
before = self.get_category(category_id)
if "name" in payload and not str(payload["name"]).strip():
raise ApiError(ErrorCode.VALIDATION_FAILED, "category name is required", {"field": "name"})
parent_id = payload.get("parent_id") if "parent_id" in payload else None
if parent_id:
if parent_id == category_id:
raise ApiError(ErrorCode.VALIDATION_FAILED, "category cannot be its own parent", {"field": "parent_id"})
if self.repository.get_category(parent_id) is None:
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "parent category not found", {"parent_id": parent_id})
after = self.repository.update_category(category_id, payload)
if after is None:
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "category not found", {"category_id": category_id})

查看文件

@ -5,7 +5,10 @@ from __future__ import annotations
from typing import Any
from backend.dto.common import ApiError, ErrorCode
from backend.services.material_binding_schema_service import material_bindings_for_node
from backend.services.image_service import ImageService
from backend.services.node_injection_template_service import build_node_injection_contract
from backend.services.prompt_plan_schema_service import prompt_plan_for_node
from backend.services.workflow_service import WorkflowService
@ -37,7 +40,7 @@ class NodeDependencyContextService:
for item in dependencies
if isinstance(item.get("selected_image"), dict)
]
return {
result = {
"workflow_id": target.workflow_id,
"node_id": target.node_id,
"branch_name": target.branch_name,
@ -45,7 +48,17 @@ class NodeDependencyContextService:
"dependencies": dependencies,
"prompt_context": ", ".join(prompt_parts),
"selected_image_ids": selected_image_ids,
"material_bindings": material_bindings_for_node(detail.workflow.metadata, target, detail.nodes),
"prompt_plan": prompt_plan_for_node(detail.workflow.metadata, target, detail.nodes),
}
result["injection_template"] = build_node_injection_contract(
target,
dependency_context=result,
material_bindings=result["material_bindings"],
prompt_plan=result["prompt_plan"],
stage_inputs=_stage_inputs_for_node(detail.workflow.metadata, target.node_id),
)
return result
def _node_context(self, node) -> dict[str, Any]:
selected_image = None
@ -74,3 +87,10 @@ class NodeDependencyContextService:
"selected_image": selected_image,
"metadata": node.metadata,
}
def _stage_inputs_for_node(workflow_metadata: dict[str, Any], node_id: str) -> Any:
stage_inputs = workflow_metadata.get("stage_inputs")
if not isinstance(stage_inputs, dict):
return {}
return stage_inputs.get(node_id) or {}

查看文件

@ -0,0 +1,357 @@
"""Node-specific workflow chat injection contracts."""
from __future__ import annotations
from copy import deepcopy
from typing import Any
from backend.dto.workflow_dto import WorkflowNode
NODE_INJECTION_TEMPLATE_VERSION = "2026-07-09.node-injection-schema.v1"
NODE_KEY_TEMPLATE_KINDS: dict[str, str] = {
"profile_brief": "persona_split",
"prompt_plan": "prompt_plan",
"material_bind": "material_bind",
"headshot": "portrait_generation",
"half_body": "halfbody_generation",
"full_body": "fullbody_generation",
"expression_sheet": "sheet_generation",
"pose_sheet": "pose_generation",
"style_lock": "hires_fix",
"final_pack": "archive",
"fast_profile": "persona_split",
"fast_candidates": "portrait_generation",
"fast_final": "archive",
"questionnaire": "profile_import",
"preview": "prompt_plan",
"virtual_single_image": "single_image_generation",
}
TEMPLATE_INTENTS: dict[str, str] = {
"profile_import": "upsert_profile_fields",
"persona_split": "update_structured_persona",
"prompt_plan": "update_prompt_matrix",
"material_bind": "update_material_bindings",
"portrait_generation": "update_portrait_node",
"halfbody_generation": "update_halfbody_node",
"fullbody_generation": "update_fullbody_node",
"sheet_generation": "update_design_sheet_node",
"pose_generation": "update_pose_sheet_node",
"stage_review": "review_stage_candidate",
"candidate_review": "review_candidates",
"hires_fix": "update_final_refinement",
"archive": "archive_character_workflow",
"single_image_generation": "single_image_generation",
"generic_workflow_node": "update_current_node",
}
EXPECTED_RESPONSE_SCHEMAS: dict[str, dict[str, Any]] = {
"profile_import": {
"intent": "upsert_profile_fields",
"target_language": "zh-CN",
"profile_patch": {
"name": "string?",
"identity": "string?",
"personality": "string?",
"appearance": "string?",
"outfit": "string?",
"style": "string?",
"negative": "string?",
},
"missing_fields": ["string"],
"conflicts": ["string"],
"next_action": "refresh_profile_import | ask_user | enter_persona_split",
},
"persona_split": {
"intent": "update_structured_persona",
"split_fields_patch": {
"identity": "string?",
"appearance": "string?",
"outfit": "string?",
"materials": "string?",
"guardrails": "string?",
},
"locked_fields": ["string"],
"conflicts": ["string"],
"next_action": "refresh_persona_split | enter_prompt_plan",
},
"prompt_plan": {
"intent": "update_prompt_matrix",
"schema_version": "2026-07-09.prompt-plan-schema.v1",
"target_language": "en",
"matrix": [
{
"target_id": "portrait | bust | fullbody | sheet | all",
"target_node_keys": ["headshot | half_body | full_body | expression_sheet | pose_sheet"],
"positive_patch": "string",
"negative_patch": "string?",
"weight_suggestions": [{"label": "string", "value": "number?", "reason": "string"}],
"weight_basis": "string",
"inheritance_fields": ["string"],
"inheritance_changes": ["string"],
"conflicts": ["string"],
"status": "ready | review | pending",
}
],
"guardrails": {
"negative_prompt": "string",
"checks": [{"key": "string", "label": "string", "value": "string", "status": "ready | review | pending"}],
},
"conflicts": [{"target_id": "string", "message": "string", "severity": "info | warn | error"}],
"next_action": "refresh_prompt_plan | enter_material_bind",
},
"material_bind": {
"intent": "update_material_bindings",
"schema_version": "2026-07-09.material-binding-schema.v1",
"reference_policy": {
"mode": "explicit_only",
"default_use_reference": False,
"empty_material_means": "do_not_use_reference",
},
"bindings": [
{
"material_category": "style | composition | clothing | socks | shoes | accessory | other",
"bind_to_stages": [{"stage_id": "string", "stage_title": "string"}],
"target_node_keys": ["headshot | half_body | full_body | expression_sheet | pose_sheet | style_lock"],
"inheritance_rule": "string",
"reference_strength": "string?",
"use_reference": "boolean",
"expand_to_nodes_later": True,
}
],
"conflicts": ["string"],
"next_action": "refresh_material_bind | enter_draft_generation",
},
"portrait_generation": {
"intent": "update_portrait_node",
"target_language": "en",
"prompt_patch": "string",
"negative_patch": "string?",
"face_locks": ["face shape | hairstyle | hair color | eye color | expression"],
"generation_params": {"count": "number?", "aspect_ratio": "1:1", "reference_strength": "string?"},
"next_action": "generate_portrait | rerun_portrait | confirm_use | ask_user",
},
"halfbody_generation": {
"intent": "update_halfbody_node",
"target_language": "en",
"prompt_patch": "string",
"negative_patch": "string?",
"inherited_locks": ["portrait baseline | face | hair | eye direction"],
"outfit_patch": "string?",
"pose_patch": "string?",
"generation_params": {"count": "number?", "aspect_ratio": "3:4", "reference_strength": "string?"},
"next_action": "generate_halfbody | rerun_halfbody | confirm_use | ask_user",
},
"fullbody_generation": {
"intent": "update_fullbody_node",
"target_language": "en",
"prompt_patch": "string",
"negative_patch": "string?",
"proportion_locks": ["head ratio | body proportion | outfit silhouette | shoes and socks"],
"accessory_requirements": ["string"],
"generation_params": {"count": "number?", "aspect_ratio": "2:3", "reference_strength": "string?"},
"next_action": "generate_fullbody | rerun_fullbody | confirm_use | ask_user",
},
"sheet_generation": {
"intent": "update_design_sheet_node",
"target_language": "en",
"prompt_patch": "string",
"negative_patch": "string?",
"sheet_layout": "front view | detail callouts | expression set | material labels",
"inherited_locks": ["portrait | halfbody | fullbody | detail nodes"],
"next_action": "generate_sheet | rerun_sheet | confirm_use | ask_user",
},
"pose_generation": {
"intent": "update_pose_sheet_node",
"target_language": "en",
"prompt_patch": "string",
"negative_patch": "string?",
"pose_targets": ["standing | action | hand pose | prop interaction"],
"inherited_locks": ["identity | outfit | style"],
"next_action": "generate_pose_sheet | rerun_pose_sheet | ask_user",
},
"stage_review": {
"intent": "review_stage_candidate",
"target_language": "en",
"review_stage": "portrait | halfbody | body_sheet",
"same_prompt_regeneration": True,
"primary_image_id": "string?",
"selected_image_ids": ["string"],
"model_route_notes": ["string"],
"defects_to_regenerate": ["string"],
"locked_items": ["string"],
"selection_reason": "string",
"next_action": "regenerate_selected_image | confirm_next_flow | ask_user",
},
"candidate_review": {
"intent": "review_candidates",
"review_dimensions": [
"identity consistency",
"outfit inheritance",
"style consistency",
"image defects",
"policy/negative constraints",
],
"primary_image_id": "string?",
"selected_image_ids": ["string"],
"reject_image_ids": ["string"],
"selection_reason": "string",
"next_round_direction": "string",
"next_action": "select_candidate | regenerate_node | enter_hires_fix",
},
"hires_fix": {
"intent": "update_final_refinement",
"target_language": "en",
"prompt_patch": "string",
"defects_to_fix": ["string"],
"keep_locked_items": ["string"],
"next_action": "regenerate_hires | enter_archive",
},
"archive": {
"intent": "archive_character_workflow",
"archive_summary": "string",
"reusable_tags": ["string"],
"version_note": "string",
"next_action": "save_archive | ask_user",
},
"single_image_generation": {
"intent": "single_image_generation",
"target_language": "en",
"prompt_patch": "string",
"negative_patch": "string?",
"generation_params": {"count": "number?", "aspect_ratio": "string?"},
"next_action": "generate_image | ask_user",
},
"generic_workflow_node": {
"intent": "update_current_node",
"target_language": "en",
"prompt_patch": "string",
"metadata_patch": "object",
"next_action": "refresh_current_node | ask_user",
},
}
CONTEXT_REQUIREMENTS: dict[str, list[str]] = {
"profile_import": ["user_instruction", "current_profile", "source_language"],
"persona_split": ["user_instruction", "current_profile", "structured_persona_fields"],
"prompt_plan": ["user_instruction", "structured_persona_fields", "material_bindings"],
"material_bind": ["user_instruction", "available_materials", "target_stage_ids"],
"portrait_generation": ["user_instruction", "current_profile", "material_bindings"],
"halfbody_generation": ["user_instruction", "upstream_selected_images", "material_bindings"],
"fullbody_generation": ["user_instruction", "upstream_selected_images", "material_bindings"],
"sheet_generation": ["user_instruction", "upstream_selected_images", "material_bindings"],
"pose_generation": ["user_instruction", "upstream_selected_images", "material_bindings"],
"stage_review": ["user_instruction", "selected_draft_image_ids", "upstream_selected_images"],
"candidate_review": ["user_instruction", "selected_draft_image_ids", "review_policy"],
"hires_fix": ["user_instruction", "stage_inputs", "upstream_selected_images"],
"archive": ["user_instruction", "accepted_images", "workflow_history"],
"single_image_generation": ["user_instruction", "current_profile"],
"generic_workflow_node": ["user_instruction", "node_context"],
}
def template_kind_for_node(node: WorkflowNode, requested_kind: str | None = None) -> str:
normalized = str(requested_kind or "").strip()
if normalized in EXPECTED_RESPONSE_SCHEMAS:
return normalized
return NODE_KEY_TEMPLATE_KINDS.get(node.node_key, "generic_workflow_node")
def build_node_injection_contract(
node: WorkflowNode,
*,
requested_kind: str | None = None,
user_instruction: str | None = None,
dependency_context: dict[str, Any] | None = None,
material_bindings: Any | None = None,
prompt_plan: Any | None = None,
stage_inputs: Any | None = None,
selected_draft_image_ids: list[str] | None = None,
ui_context: dict[str, Any] | None = None,
) -> dict[str, Any]:
kind = template_kind_for_node(node, requested_kind)
dependency_context = dependency_context if isinstance(dependency_context, dict) else {}
return {
"version": NODE_INJECTION_TEMPLATE_VERSION,
"template_kind": kind,
"node_key": node.node_key,
"node_id": node.node_id,
"intent": TEMPLATE_INTENTS.get(kind, TEMPLATE_INTENTS["generic_workflow_node"]),
"language_policy": {
"source_language": "auto",
"target_prompt_language": "en",
"translation_mode": "backend_llm",
"preserve_character_names": True,
},
"user_instruction": {
"raw_text": str(user_instruction or "").strip(),
"source_language": "auto",
},
"node_context": {
"title": node.title,
"step_name": node.step_name,
"node_type": node.node_type,
"status": node.status,
"prompt": node.prompt,
"negative_prompt": node.negative_prompt,
"selected_image_id": node.selected_image_id,
"metadata": node.metadata,
},
"dependency_context": {
"dependency_count": dependency_context.get("dependency_count", 0),
"prompt_context": dependency_context.get("prompt_context", ""),
"selected_image_ids": dependency_context.get("selected_image_ids", []),
"dependencies": dependency_context.get("dependencies", []),
},
"material_bindings": material_bindings if material_bindings is not None else [],
"prompt_plan": prompt_plan if prompt_plan is not None else {},
"stage_inputs": stage_inputs if stage_inputs is not None else {},
"selected_draft_image_ids": selected_draft_image_ids or [],
"ui_context": ui_context or {},
"context_requirements": CONTEXT_REQUIREMENTS.get(kind, CONTEXT_REQUIREMENTS["generic_workflow_node"]),
"expected_response_schema": deepcopy(
EXPECTED_RESPONSE_SCHEMAS.get(kind, EXPECTED_RESPONSE_SCHEMAS["generic_workflow_node"])
),
"prompt_contract": [
"Understand the user's source-language instruction.",
"Translate user-facing edits into concise English image-generation prompt language.",
"Preserve locked identity traits, selected upstream images, material bindings, and negative constraints.",
"Return a JSON-compatible object matching expected_response_schema.",
"If the target node is locked, return a branch-required next_action instead of mutating the original chain.",
],
}
def injection_payload_from_generation_request(payload: dict[str, Any]) -> dict[str, Any]:
metadata = payload.get("metadata") if isinstance(payload.get("metadata"), dict) else {}
user_instruction = (
metadata.get("user_instruction")
or payload.get("user_instruction")
or payload.get("prompt_patch")
or payload.get("extra_prompt")
or ""
)
return {
"requested_kind": metadata.get("node_injection_kind") or payload.get("node_injection_kind"),
"user_instruction": str(user_instruction or ""),
"material_bindings": metadata.get("material_binding_rules") or payload.get("material_bindings") or [],
"stage_inputs": metadata.get("stage_inputs") or payload.get("stage_inputs") or {},
"selected_draft_image_ids": _string_list(
metadata.get("selected_draft_image_ids") or payload.get("selected_draft_image_ids")
),
"ui_context": {
"ui_node_id": metadata.get("ui_node_id"),
"ui_node_title": metadata.get("ui_node_title"),
"ui_node_phase": metadata.get("ui_node_phase"),
"review_source_ui_node_id": metadata.get("review_source_ui_node_id"),
"review_next_ui_node_id": metadata.get("review_next_ui_node_id"),
},
}
def _string_list(value: Any) -> list[str]:
if not isinstance(value, list):
return []
return [str(item) for item in value if str(item or "").strip()]

查看文件

@ -6,6 +6,10 @@ from typing import Any
from backend.dto.profile_dto import CharacterProfile
from backend.dto.workflow_dto import WorkflowNode
from backend.services.node_injection_template_service import (
build_node_injection_contract,
injection_payload_from_generation_request,
)
from core.prompt_pipeline import merge_prompt_sections
@ -26,6 +30,11 @@ class PromptExpansionService:
node: WorkflowNode,
payload: dict[str, Any],
) -> dict[str, Any]:
dependency_context = payload.get("dependency_context") if isinstance(payload.get("dependency_context"), dict) else {}
prompt_plan = dependency_context.get("prompt_plan") if isinstance(dependency_context.get("prompt_plan"), dict) else {}
prompt_plan_generation = (
prompt_plan.get("generation_params") if isinstance(prompt_plan.get("generation_params"), dict) else {}
)
variables = {
"profile_name": profile.name,
"node_title": node.title,
@ -43,17 +52,46 @@ class PromptExpansionService:
"negative_parts": [node.negative_prompt],
"variables": variables,
},
{
"parts": _as_list(prompt_plan_generation.get("prompt_patch")),
"negative_parts": _as_list(prompt_plan_generation.get("negative_patch")),
"variables": variables,
},
{
"parts": _payload_parts(payload),
"negative_parts": _payload_negative_parts(payload),
"variables": variables,
},
)
injection_payload = injection_payload_from_generation_request(payload)
dependency_injection = (
dependency_context.get("injection_template")
if isinstance(dependency_context.get("injection_template"), dict)
else {}
)
material_bindings = (
injection_payload["material_bindings"]
or dependency_context.get("material_bindings")
or dependency_injection.get("material_bindings")
or []
)
node_injection = build_node_injection_contract(
node,
requested_kind=injection_payload["requested_kind"],
user_instruction=injection_payload["user_instruction"],
dependency_context=dependency_context,
material_bindings=material_bindings,
prompt_plan=prompt_plan or dependency_injection.get("prompt_plan") or {},
stage_inputs=injection_payload["stage_inputs"],
selected_draft_image_ids=injection_payload["selected_draft_image_ids"],
ui_context=injection_payload["ui_context"],
)
return {
**result.to_dict(),
"source": "profile_node",
"profile_id": profile.profile_id,
"node_id": node.node_id,
"node_injection": node_injection,
}

查看文件

@ -0,0 +1,366 @@
"""Normalize prompt planning output for workflow generation nodes."""
from __future__ import annotations
from copy import deepcopy
from typing import Any
from backend.dto.workflow_dto import WorkflowNode
PROMPT_PLAN_SCHEMA_VERSION = "2026-07-09.prompt-plan-schema.v1"
TARGET_NODE_KEYS: dict[str, tuple[str, ...]] = {
"portrait": ("headshot", "fast_candidates"),
"headshot": ("headshot", "fast_candidates"),
"face": ("headshot", "fast_candidates"),
"bust": ("half_body",),
"halfbody": ("half_body",),
"half_body": ("half_body",),
"fullbody": ("full_body",),
"full_body": ("full_body",),
"body": ("full_body",),
"sheet": ("expression_sheet", "pose_sheet"),
"design_sheet": ("expression_sheet", "pose_sheet"),
"expression_sheet": ("expression_sheet",),
"pose_sheet": ("pose_sheet",),
"all": ("headshot", "fast_candidates", "half_body", "full_body", "expression_sheet", "pose_sheet"),
}
TARGET_TITLES: dict[str, str] = {
"portrait": "Portrait/headshot",
"bust": "Half body",
"fullbody": "Full body",
"sheet": "Design sheet",
"all": "All generation nodes",
}
def normalize_prompt_plan(
payload: Any,
workflow_nodes: list[WorkflowNode] | None = None,
) -> dict[str, Any]:
if isinstance(payload, dict) and payload.get("schema_version") == PROMPT_PLAN_SCHEMA_VERSION:
normalized = deepcopy(payload)
if workflow_nodes:
matrix = normalized.get("matrix") if isinstance(normalized.get("matrix"), list) else []
normalized["by_node_id"] = _index_by_node_id(matrix, workflow_nodes)
normalized["node_parameters"] = normalized["by_node_id"]
return normalized
source = _extract_source_payload(payload)
matrix = [
_normalize_matrix_item(item, index + 1)
for index, item in enumerate(_matrix_items(source))
if isinstance(item, dict)
]
guardrails = _normalize_guardrails(source, matrix)
conflicts = _collect_conflicts(matrix, guardrails)
by_target = {item["target_id"]: item for item in matrix}
by_node_key = _index_by_node_key(matrix)
by_node_id = _index_by_node_id(matrix, workflow_nodes or [])
return {
"schema_version": PROMPT_PLAN_SCHEMA_VERSION,
"target_prompt_language": "en",
"profile_id": _optional_text(source.get("profile_id")),
"profile_name": _optional_text(source.get("profile_name")),
"matrix": matrix,
"guardrails": guardrails,
"conflicts": conflicts,
"by_target": by_target,
"by_node_key": by_node_key,
"by_node_id": by_node_id,
"node_parameters": by_node_id,
"prompt_context": _prompt_context(matrix),
"summary": {
"target_count": len(matrix),
"ready_count": len([item for item in matrix if item["status"] == "ready"]),
"review_count": len([item for item in matrix if item["status"] == "review"]),
"conflict_count": len(conflicts),
"negative_prompt": guardrails["negative_prompt"],
"target_node_keys": sorted(by_node_key),
},
}
def prompt_plan_for_node(
workflow_metadata: dict[str, Any],
node: WorkflowNode,
workflow_nodes: list[WorkflowNode] | None = None,
) -> dict[str, Any]:
normalized = normalize_prompt_plan(workflow_metadata.get("prompt_plan"), workflow_nodes)
return node_prompt_plan_view(normalized, node)
def node_prompt_plan_view(normalized: dict[str, Any], node: WorkflowNode) -> dict[str, Any]:
by_node_id = normalized.get("by_node_id") if isinstance(normalized.get("by_node_id"), dict) else {}
by_node_key = normalized.get("by_node_key") if isinstance(normalized.get("by_node_key"), dict) else {}
node_view = by_node_id.get(node.node_id)
if not isinstance(node_view, dict):
node_view = _node_view(by_node_key.get(node.node_key, []), node.node_id, node.node_key, node.title)
return {
"schema_version": normalized.get("schema_version", PROMPT_PLAN_SCHEMA_VERSION),
"target_prompt_language": normalized.get("target_prompt_language", "en"),
"summary": normalized.get("summary", {}),
"guardrails": normalized.get("guardrails", _normalize_guardrails({}, [])),
"conflicts": normalized.get("conflicts", []),
"target_node_id": node.node_id,
"target_node_key": node.node_key,
"target_node_title": node.title,
**node_view,
}
def _extract_source_payload(payload: Any) -> dict[str, Any]:
if not isinstance(payload, dict):
return {}
for key in ("prompt_plan", "prompt_matrix"):
value = payload.get(key)
if isinstance(value, dict):
return value
return payload
def _matrix_items(source: dict[str, Any]) -> list[Any]:
for key in ("matrix", "items", "targets", "updates"):
value = source.get(key)
if isinstance(value, list):
return value
return []
def _normalize_matrix_item(item: dict[str, Any], ordinal: int) -> dict[str, Any]:
raw_target = _optional_text(item.get("target") or item.get("target_id") or item.get("id")) or f"target_{ordinal:02d}"
target_id = _canonical_target(raw_target)
target_node_keys = _target_node_keys(item, target_id)
positive_prompt = _optional_text(
item.get("positive_prompt")
or item.get("prompt")
or item.get("positive_patch")
or item.get("prompt_patch")
)
negative_prompt = _optional_text(item.get("negative_prompt") or item.get("negative") or item.get("negative_patch"))
conflicts = _string_list(item.get("conflicts") or item.get("conflict"))
status = _status(item.get("status"), conflicts)
return {
"id": _optional_text(item.get("id")) or target_id,
"target_id": target_id,
"target_title": _optional_text(item.get("title") or item.get("target_title")) or TARGET_TITLES.get(target_id, raw_target),
"target_label": _optional_text(item.get("target_label") or item.get("target")) or raw_target,
"target_node_keys": target_node_keys,
"positive_prompt": positive_prompt or "",
"positive_patch": _optional_text(item.get("positive_patch") or item.get("prompt_patch")) or positive_prompt or "",
"negative_prompt": negative_prompt or "",
"negative_patch": _optional_text(item.get("negative_patch")) or negative_prompt or "",
"weight_suggestions": _weight_suggestions(item),
"weight_basis": _optional_text(item.get("weight_basis") or item.get("weightBasis")) or "",
"inheritance_fields": _string_list(item.get("inheritance_fields") or item.get("inherits")),
"inheritance_changes": _string_list(item.get("inheritance_changes")),
"conflicts": conflicts,
"status": status,
"next_action": _optional_text(item.get("next_action")) or ("review_conflicts" if conflicts else "apply_prompt_plan"),
}
def _normalize_guardrails(source: dict[str, Any], matrix: list[dict[str, Any]]) -> dict[str, Any]:
raw_guards = source.get("guardrails") or source.get("guards") or source.get("guard_checks") or []
guard_items = raw_guards if isinstance(raw_guards, list) else []
negative_prompt = _optional_text(source.get("negative_prompt") or source.get("negative"))
if not negative_prompt:
negative_prompt = next((item["negative_prompt"] for item in matrix if item.get("negative_prompt")), "")
checks = [_normalize_guard_item(item) for item in guard_items if isinstance(item, dict)]
if negative_prompt and not any(item["key"] == "negative_prompt" for item in checks):
checks.insert(
0,
{
"key": "negative_prompt",
"label": "Negative prompt",
"value": negative_prompt,
"status": "ready",
"severity": "info",
},
)
return {
"negative_prompt": negative_prompt or "",
"checks": checks,
"language_policy": {
"source_language": "auto",
"target_prompt_language": "en",
"translation_mode": "backend_llm",
},
}
def _normalize_guard_item(item: dict[str, Any]) -> dict[str, str]:
label = _optional_text(item.get("label") or item.get("key")) or "Guard"
status = _status(item.get("status"), _string_list(item.get("conflicts")))
return {
"key": _key(label),
"label": label,
"value": _optional_text(item.get("value")) or "",
"status": status,
"severity": _optional_text(item.get("severity")) or ("warn" if status == "review" else "info"),
}
def _index_by_node_key(matrix: list[dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
result: dict[str, list[dict[str, Any]]] = {}
for item in matrix:
for node_key in item["target_node_keys"]:
result.setdefault(node_key, []).append(item)
return result
def _index_by_node_id(
matrix: list[dict[str, Any]],
workflow_nodes: list[WorkflowNode],
) -> dict[str, dict[str, Any]]:
by_node_key = _index_by_node_key(matrix)
return {
node.node_id: _node_view(by_node_key.get(node.node_key, []), node.node_id, node.node_key, node.title)
for node in workflow_nodes
if by_node_key.get(node.node_key)
}
def _node_view(
items: list[dict[str, Any]],
node_id: str | None,
node_key: str,
title: str,
) -> dict[str, Any]:
positive_parts = [item["positive_patch"] for item in items if item.get("positive_patch")]
negative_parts = [item["negative_patch"] for item in items if item.get("negative_patch")]
return {
"target_node_id": node_id,
"target_node_key": node_key,
"target_node_title": title,
"has_prompt_plan": bool(items),
"matrix_items": deepcopy(items),
"positive_prompt_patches": positive_parts,
"negative_prompt_patches": negative_parts,
"prompt_context": ", ".join(positive_parts),
"generation_params": {
"prompt_patch": ", ".join(positive_parts),
"negative_patch": ", ".join(negative_parts),
"weight_suggestions": [suggestion for item in items for suggestion in item["weight_suggestions"]],
"inheritance_fields": _unique_texts(field for item in items for field in item["inheritance_fields"]),
},
}
def _target_node_keys(item: dict[str, Any], target_id: str) -> list[str]:
explicit = _string_list(item.get("target_node_keys") or item.get("node_keys"))
if explicit:
return explicit
return list(TARGET_NODE_KEYS.get(target_id, TARGET_NODE_KEYS.get("all", ())))
def _canonical_target(value: str) -> str:
normalized = value.strip().lower().replace("-", "_").replace(" ", "_")
aliases = {
"头像": "portrait",
"头像节点": "portrait",
"portrait": "portrait",
"headshot": "portrait",
"face": "portrait",
"半身": "bust",
"半身节点": "bust",
"bust": "bust",
"halfbody": "bust",
"half_body": "bust",
"全身": "fullbody",
"全身节点": "fullbody",
"body": "fullbody",
"fullbody": "fullbody",
"full_body": "fullbody",
"设定图": "sheet",
"设定图节点": "sheet",
"sheet": "sheet",
"design_sheet": "sheet",
"all": "all",
}
return aliases.get(normalized, normalized)
def _weight_suggestions(item: dict[str, Any]) -> list[dict[str, Any]]:
raw = item.get("weight_suggestions") or item.get("weight_changes") or item.get("weight")
if isinstance(raw, str):
return [{"label": raw, "value": None, "reason": _optional_text(item.get("weight_basis") or item.get("weightBasis")) or ""}]
if not isinstance(raw, list):
return []
suggestions = []
for entry in raw:
if isinstance(entry, dict):
suggestions.append(
{
"label": _optional_text(entry.get("label") or entry.get("target")) or "weight",
"value": entry.get("value"),
"reason": _optional_text(entry.get("reason") or entry.get("basis")) or "",
}
)
else:
text = _optional_text(entry)
if text:
suggestions.append({"label": text, "value": None, "reason": ""})
return suggestions
def _collect_conflicts(matrix: list[dict[str, Any]], guardrails: dict[str, Any]) -> list[dict[str, str]]:
conflicts = [
{"target_id": item["target_id"], "message": conflict, "severity": "warn"}
for item in matrix
for conflict in item["conflicts"]
]
for guard in guardrails.get("checks", []):
if guard.get("status") == "review":
conflicts.append({"target_id": "guardrails", "message": guard.get("value", ""), "severity": "warn"})
return conflicts
def _prompt_context(matrix: list[dict[str, Any]]) -> list[dict[str, str]]:
return [
{
"target_id": item["target_id"],
"target_node_keys": ", ".join(item["target_node_keys"]),
"positive_patch": item["positive_patch"],
"negative_patch": item["negative_patch"],
}
for item in matrix
if item.get("positive_patch") or item.get("negative_patch")
]
def _status(value: Any, conflicts: list[str]) -> str:
status = str(value or "").strip().lower()
if status in {"ready", "review", "pending"}:
return status
return "review" if conflicts else "ready"
def _string_list(value: Any) -> list[str]:
if isinstance(value, str):
return [value] if value.strip() else []
if not isinstance(value, list):
return []
return _unique_texts(str(item).strip() for item in value if str(item or "").strip())
def _unique_texts(values: Any) -> list[str]:
result: list[str] = []
for value in values:
text = str(value or "").strip()
if text and text not in result:
result.append(text)
return result
def _optional_text(value: Any) -> str | None:
if value is None:
return None
text = str(value).strip()
return text or None
def _key(value: str) -> str:
return "_".join(value.lower().replace("/", " ").replace("-", " ").split()) or "guard"

查看文件

@ -45,8 +45,9 @@ class ReviewService:
def review_node(self, node_id: str) -> dict[str, Any]:
node = self.workflow_service.get_node(node_id)
workflow = self.workflow_service.get_workflow(node.workflow_id).workflow
images = self.image_repository.list_by_node(node_id, include_archived=True)
return self.review_engine.review_node(node, images)
return self.review_engine.review_node(node, images, workflow.metadata)
def review_workflow(self, workflow_id: str) -> dict[str, Any]:
detail = self.workflow_service.get_workflow(workflow_id)

查看文件

@ -7,6 +7,14 @@ from uuid import uuid4
from backend.dto.common import ApiError, ErrorCode
from backend.dto.workflow_dto import ProfileWorkflow, WorkflowBranch, WorkflowDetail, WorkflowNode
from backend.services.material_binding_schema_service import (
MATERIAL_BINDING_SCHEMA_VERSION,
normalize_material_bindings,
)
from backend.services.prompt_plan_schema_service import (
PROMPT_PLAN_SCHEMA_VERSION,
normalize_prompt_plan,
)
from core.audit_service import AuditService
from core.event_bus import EventBus
from core.fsm import node_transition, workflow_transition
@ -141,6 +149,8 @@ class WorkflowService:
update_payload = dict(payload)
if "display_name" in update_payload:
update_payload["display_name"] = str(update_payload["display_name"]).strip()
if "metadata" in update_payload and isinstance(update_payload["metadata"], dict):
update_payload["metadata"] = self._normalize_workflow_metadata(before, update_payload["metadata"])
after = self.workflow_repository.update_workflow(workflow_id, update_payload)
if after is None:
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "workflow not found", {"workflow_id": workflow_id})
@ -328,10 +338,18 @@ class WorkflowService:
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "node not found", {"node_id": node_id})
return node
def update_node(self, node_id: str, payload: dict[str, Any], ctx: RequestContext) -> WorkflowNode:
def update_node(
self,
node_id: str,
payload: dict[str, Any],
ctx: RequestContext,
*,
allow_locked_adoption: bool = False,
) -> 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 not (allow_locked_adoption and _is_locked_image_adoption(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():
@ -342,6 +360,8 @@ class WorkflowService:
after = self.workflow_repository.update_node(node_id, update_payload)
if after is None:
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "node not found", {"node_id": node_id})
self._sync_material_bindings_from_node(after)
self._sync_prompt_plan_from_node(after)
self.audit_service.record(
ctx=ctx,
action="update_node",
@ -487,6 +507,74 @@ class WorkflowService:
if self.event_bus:
self.event_bus.publish(event_type, payload)
def _normalize_workflow_metadata(
self,
workflow: ProfileWorkflow,
metadata: dict[str, Any],
) -> dict[str, Any]:
material_bindings = metadata.get("material_bindings")
prompt_plan = metadata.get("prompt_plan") or metadata.get("prompt_matrix")
if material_bindings is None and prompt_plan is None:
return metadata
nodes = self.workflow_repository.list_nodes(workflow.workflow_id, branch_name=workflow.current_branch)
normalized = dict(metadata)
if material_bindings is not None:
normalized["material_binding_schema_version"] = MATERIAL_BINDING_SCHEMA_VERSION
normalized["material_bindings"] = normalize_material_bindings(material_bindings, nodes)
if prompt_plan is not None:
normalized["prompt_plan_schema_version"] = PROMPT_PLAN_SCHEMA_VERSION
normalized["prompt_plan"] = normalize_prompt_plan(prompt_plan, nodes)
normalized.pop("prompt_matrix", None)
return normalized
def _sync_material_bindings_from_node(self, node: WorkflowNode) -> None:
if node.node_key != "material_bind" or not isinstance(node.metadata, dict):
return
raw_bindings = node.metadata.get("material_bindings")
if raw_bindings is None:
return
workflow = self.workflow_repository.get_workflow(node.workflow_id)
if workflow is None:
return
nodes = self.workflow_repository.list_nodes(node.workflow_id, branch_name=node.branch_name)
normalized = normalize_material_bindings(raw_bindings, nodes)
self.workflow_repository.update_workflow(
workflow.workflow_id,
{
"metadata": {
**(workflow.metadata or {}),
"material_binding_schema_version": MATERIAL_BINDING_SCHEMA_VERSION,
"material_binding_source_node_id": node.node_id,
"material_binding_updated_at": node.updated_at,
"material_bindings": normalized,
}
},
)
def _sync_prompt_plan_from_node(self, node: WorkflowNode) -> None:
if node.node_key != "prompt_plan" or not isinstance(node.metadata, dict):
return
raw_plan = node.metadata.get("prompt_plan") or node.metadata.get("prompt_matrix")
if raw_plan is None:
return
workflow = self.workflow_repository.get_workflow(node.workflow_id)
if workflow is None:
return
nodes = self.workflow_repository.list_nodes(node.workflow_id, branch_name=node.branch_name)
normalized = normalize_prompt_plan(raw_plan, nodes)
self.workflow_repository.update_workflow(
workflow.workflow_id,
{
"metadata": {
**(workflow.metadata or {}),
"prompt_plan_schema_version": PROMPT_PLAN_SCHEMA_VERSION,
"prompt_plan_source_node_id": node.node_id,
"prompt_plan_updated_at": node.updated_at,
"prompt_plan": normalized,
}
},
)
def new_workflow_id() -> str:
return f"workflow_{uuid4().hex}"
@ -546,6 +634,21 @@ def _node_payload_changes(node: WorkflowNode, payload: dict[str, Any]) -> bool:
return False
def _is_locked_image_adoption(node: WorkflowNode, payload: dict[str, Any]) -> bool:
allowed_keys = {"status", "selected_image_id"}
if any(key not in allowed_keys for key in payload):
return False
selected_image_id = payload.get("selected_image_id")
if not selected_image_id:
return False
target_status = payload.get("status", node.status)
if target_status != "selected":
return False
if node.status == "completed":
return True
return node.status == "selected" and node.selected_image_id == selected_image_id
def _branch_copy_status(node: WorkflowNode, base_sort_order: int | None) -> str:
if base_sort_order is None:
return "draft"

查看文件

@ -13,6 +13,7 @@ from database.db_helper import Database
class SeedCategory:
category_id: str
name: str
parent_id: str | None = None
category_type: str = "material"
sort_order: int = 0
metadata: dict[str, Any] = field(default_factory=dict)
@ -29,6 +30,100 @@ DEFAULT_MATERIAL_CATEGORIES: tuple[SeedCategory, ...] = (
sort_order=50,
metadata={"seed": True, "wardrobe_category": "accessory"},
),
SeedCategory(
"cat_imagestudio_构图",
"构图",
sort_order=110,
metadata={"seed": True, "source": "imagestudio_backend", "frontend_group": "构图"},
),
SeedCategory(
"cat_imagestudio_服装",
"服装",
sort_order=120,
metadata={"seed": True, "source": "imagestudio_backend", "frontend_group": "服装"},
),
SeedCategory(
"cat_imagestudio_风格",
"风格",
sort_order=130,
metadata={"seed": True, "source": "imagestudio_backend", "frontend_group": "风格"},
),
SeedCategory(
"cat_imagestudio_配饰",
"配饰",
sort_order=140,
metadata={"seed": True, "source": "imagestudio_backend", "frontend_group": "配饰"},
),
SeedCategory(
"cat_imagestudio_鞋袜",
"鞋袜",
sort_order=150,
metadata={"seed": True, "source": "imagestudio_backend", "frontend_group": "鞋袜"},
),
SeedCategory(
"cat_imagestudio_accessory_眼部",
"眼部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=210,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_头部",
"头部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=220,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_手部",
"手部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=230,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_胸前",
"胸前",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=240,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_颈部",
"颈部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=250,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_腰部",
"腰部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=260,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_脸部",
"脸部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=270,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
SeedCategory(
"cat_imagestudio_accessory_臂部",
"臂部",
parent_id="cat_imagestudio_配饰",
category_type="accessory_group",
sort_order=280,
metadata={"seed": True, "source": "imagestudio_backend", "parent_category": "配饰"},
),
)
@ -51,12 +146,13 @@ def seed_default_material_categories(database: Database) -> dict[str, Any]:
INSERT INTO material_categories (
category_id, name, parent_id, category_type, sort_order, metadata_json
) VALUES (
{placeholder}, {placeholder}, NULL, {placeholder}, {placeholder}, {placeholder}
{placeholder}, {placeholder}, {placeholder}, {placeholder}, {placeholder}, {placeholder}
)
""",
(
category.category_id,
category.name,
category.parent_id,
category.category_type,
category.sort_order,
json.dumps(category.metadata, ensure_ascii=False, sort_keys=True),

查看文件

@ -0,0 +1,272 @@
# ImageStudio UI / Workflow Progress Handoff
日期:2026-07-09
范围:生成页、快速角色、角色工作流、阶段审查、锁定与分支、后端接口闭环
## 当前总体状态
- 生成页已经形成三条主入口:`图片生成`、`快速角色`、`角色工作流`。
- 三条入口都已经有前端工作台,并已接入或预留对应后端接口:
- 图片生成:走单图工作流与 `nodes/:nodeId/generate`。
- 快速角色:走 `profiles/quick-draft/save` 保存档案并创建工作流关联。
- 角色工作流:走 `profiles/:profileId/workflows`、`workflows/:workflowId/nodes` 和节点级生成/审查/历史接口。
- 当前重点已经从纯 UI 进入“角色工作流闭环”:档案导入、设定拆解、提示词规划、素材绑定、头像/半身/设定图、审查、高清修复、入库。
## 已完成内容
### 快速角色与角色档案
- 创建角色档案问卷已支持简单/复杂模式。
- 复杂问卷字段包含世界观、背景、身高/身材、身体特征、喜好、关系、故事钩子、生成风格、镜头偏好等。
- 问卷字段可留空,不要求全部填写,避免破坏创建体验。
- 生成档案按钮语义已从“生成预览”改为“生成档案”。
- 生成档案后会在右侧角色卡区域生成/选中新角色卡。
- 外部角色卡导入已提供弹窗入口,可粘贴外部人设文本并回填问卷字段。
- 快速角色参考素材选择沿用分类素材卡,默认生产语义应为“不使用参考”,避免无意引入参考图。
### 前期人设准备
- `前期人设准备` 页面布局已调整:导入入口放到侧面,上方主卡片下移,侧边空间更有效。
- 该阶段包含:
- 导入粗略人设
- LLM 设定拆解
- 提示词规划
- 参考素材绑定
- LLM 设定拆解卡片按组展示身份性格、外观锚点、服装素材、约束负面项。
- 大卡片尺寸保持稳定,内部小项目按顺序排列,内容超出时滚动。
- 底部对话框会根据当前节点注入上下文,包括角色档案、节点信息、素材、拆解字段和用户原文,并标记后端 LLM 翻译为英文提示词。
### 提示词规划
- 提示词规划页面已搭建矩阵化展示。
- 支持头像、半身、全身、设定图等目标节点的提示词条目。
- 已加入继承字段、权重依据、负面词和冲突项校验区域。
- 修复过卡片重叠、内容被遮挡、胶囊超出卡片下沿等布局问题。
- 提示词规划 LLM 输出结构已补齐后端 schema,版本为 `2026-07-09.prompt-plan-schema.v1`。
- 后端提示词规划 schema 包含:
- `matrix`:头像、半身、全身、设定图等目标提示词矩阵。
- `weight_suggestions`:权重建议、数值和依据。
- `inheritance_fields` / `inheritance_changes`:继承字段与变更建议。
- `guardrails`:负面提示词、语言策略和检查项。
- `conflicts`:按目标节点归属的冲突项。
- `by_target` / `by_node_key` / `by_node_id`:按目标、后端节点类型和真实节点索引。
- 保存 `prompt_plan` 节点 metadata 或 workflow metadata 时,后端会自动规范化为正式 prompt plan schema。
- 节点依赖上下文会按当前目标节点过滤提示词规划,例如头像节点只拿头像 prompt patch,全身节点只拿全身 prompt patch。
- `PromptExpansionService` 会从 dependency context 自动继承 prompt plan 的 positive/negative patch,并注入生成链路与 `node_injection.prompt_plan`。
### 参考素材绑定
- 参考素材绑定页面已建立。
- 绑定节点已翻译为中文,并改为直接绑定大节点,不再绑定后期生成才会出现的小节点。
- 已按“快速角色参考素材”的交互方式提供素材选择。
- 参考素材选择弹窗已改为悬浮在上方,而不是向下撑开布局。
- 默认生产语义应为“不使用参考”,只有用户显式选择后才注入素材。
- 素材绑定规则已接入后端 metadata 写入与 workflow 级规范化落库。
- 后端素材绑定 schema 版本为 `2026-07-09.material-binding-schema.v1`。
- 保存 `material_bind` 节点时,后端会自动生成:
- `rules`:完整规则,包含未选择素材的“不使用参考”分类。
- `active_rules`:用户显式选择素材后才启用的规则。
- `by_stage`:按前端大阶段索引。
- `by_node_key`:按后端节点类型索引。
- `by_node_id` / `node_parameters`:按真实 workflow node 索引。
- 后端默认参考策略为 `explicit_only`,`default_use_reference=false`,空素材分类不会进入生成参考。
- 节点依赖上下文会按当前目标节点过滤素材,例如头像只拿头像阶段绑定,半身只拿半身阶段绑定。
- `PromptExpansionService` 会从 dependency context 自动继承规范化素材绑定,供后端 LLM 和生成链路注入。
### 角色工作流大节点
- 前端大节点已对齐后端设计,当前角色工作流大节点包括:
- 前期人设准备
- 头像
- 半身像
- 全身与设定图
- 高清修复并入库
- 已补齐半身像节点。
- 前期人设准备暂时不再调整,后续重点转入生成链路与审查链路。
### 头像 / 半身 / 设定图生成逻辑
- 头像节点:
- 第一个节点按钮为“生成头像”。
- 后续轮次按钮为“再跑一轮”。
- 原“再跑一轮”语义下的确认按钮已改为“确认使用”。
- 半身像和全身/设定图已按同样逻辑整理。
- 选中候选后可进入对应阶段审查节点。
- 下方对话框已按当前节点分别注入节点上下文。
### 阶段审查节点
- 已加入 UI 层阶段审查节点:
- `portrait-review`:头像审查
- `halfbody-review`:半身像审查
- `body-sheet-review`:设定图审查
- 阶段审查映射到真实后端节点:
- 头像审查映射到 `headshot`
- 半身像审查映射到 `half_body`
- 设定图审查映射到 `expression_sheet` / 设定图相关节点
- 审查阶段按钮已调整为:
- `选中的图片重新生成`
- `对比候选`
- `确认`
- `选中的图片重新生成` 用于同提示词不同模型复跑,解决某个模型偶尔异常的问题。
- `确认` 用于通过审查并推进到下一阶段。
### 审查确认闭环
- 审查阶段点击 `确认` 已接入真实闭环:
- 调用 `nodes/:nodeId/adopt-image`。
- 将选中图片写入后端采用历史。
- 将上一真实生成节点状态收敛为 `selected`。
- 上一节点进入锁定状态,后续修改需要从该点创建分支。
- 推进 `workflow.current_node_id` 到下一真实节点。
- 在 workflow metadata 的 `stage_inputs` 中记录阶段输入交接。
- 设定图审查确认后,选中的成品稿会放入 `高清修复` 输入桶。
- 前端维护 `workflowInputImagesByNodeId`,用于展示“下一节点输入图”,不伪造图片真实归属。
- 如果下一节点已经锁定,前端不会再尝试修改下一节点 metadata,只记录 workflow 级交接信息。
- 后端 `adopt_node_image` 已消费前端传入的 `next_backend_node_id`、`handoff_bucket`、`handoff_role` 等 metadata。
- 后端会将阶段交接正式写入 `workflow.metadata.stage_inputs`,schema 版本为 `2026-07-09.stage-input-bucket.v1`。
- 后端会同步推进 `workflow.current_node_id` 到下一真实节点,并保留最近阶段审查交接日志 `stage_review_handoffs`。
- 前端已补齐 `workflowReviewAdopt` 操作:
- 头像/半身/设定图阶段显示 `确认采用`。
- 高清修复阶段显示 `确认修复结果`。
- 采用前要求选中的图片是真实后端图片,且必须属于当前后端节点。
- `completed` 节点允许本地切换候选图并执行一次确认采用,但不允许重新生成、重跑或修改提示词。
- `selected` 节点视为最终锁定,只显示创建分支和保存快照。
- 头像/半身采用后优先按后端 `sort_order` 推进到下一真实节点。
- 设定图采用后固定交接到 `高清修复与统一风格`。
- 高清修复采用后交接到 `入库`。
- 采用成功后前端会刷新 workflow、nodes 和 node images,并跳转到下一 UI 节点。
### 后端注入与审查结构
- 已新增 `backend/services/node_injection_template_service.py`,统一定义每个节点的对话注入契约。
- 注入契约包含用户原文、节点上下文、上游选图、素材绑定、阶段输入、语言翻译策略和预期 JSON 返回结构。
- 已补齐 `stage_review` 与 `candidate_review` 注入模板,支持审查节点下方对话框按节点独立注入。
- `prompt_plan` 注入模板已补入正式提示词规划 schema、权重建议、继承字段、负面词和冲突返回结构。
- `material_bind` 注入模板已补入正式素材绑定 schema、默认参考策略和目标后端节点字段。
- `NodeDependencyContextService` 已返回 `injection_template`,供前端或后续 LLM 编排读取。
- `PromptExpansionService` 已返回 `node_injection`,生成链路可以把节点注入契约一并传给后端 LLM。
- `ReviewFlowEngine.review_node` 已返回正式 `stage_review` 结构,schema 版本为 `2026-07-09.stage-review-result.v1`。
- 阶段审查结果结构包含:
- 同提示词多模型候选 `candidates`
- 候选评分 `score`
- 画面缺陷与警告 `defects` / `warnings`
- 选中候选 `selected_candidate`
- 重生成记录 `regeneration_records`
- 人工确认动作 `manual_confirmation`
- 下一阶段输入桶预期结构 `handoff`
### 锁定与分支
- 后端锁定状态包括 `completed` 和 `selected`。
- 普通编辑、重跑、选图、归档或删除锁定节点绑定图片会被阻止。
- 前端在锁定节点显示“从此节点创建分支”入口。
- 创建分支调用:
- `POST workflows/:workflowId/branches`
- `POST workflows/:workflowId/switch-branch`
- 分支规则:
- 切点之前的节点保留完成状态和选中图。
- 切点及之后重置为 `draft` 并清空选中图。
- metadata 记录 `copied_from_node_id`、切点和分支继承信息。
- 为审查确认补充了后端受控例外:
- 允许 `completed -> selected` 的采用收敛。
- 已经 `selected` 后切换到另一张图仍会拒绝,继续要求新建分支。
## 后端接口状态
### 已接入或已使用
- `profiles`
- `profiles/quick-draft`
- `profiles/quick-draft/save`
- `profiles/:profileId/workflows`
- `workflows/:workflowId`
- `workflows/:workflowId/nodes`
- `workflows/:workflowId/execute-character`
- `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/select-image`
- `nodes/:nodeId/adopt-image`
- `nodes/:nodeId/review`
- `nodes/:nodeId/images`
- `images/:imageId`
### 已预留但仍需后端深化
- 最终角色版本入库 schema。
- 角色图库与素材库联动。
## 关键代码位置
- 前端主页面:`frontend/standalone-web/src/App.vue`
- 前端接口定义:`frontend/shared/api/endpoints.ts`
- 后端 workflow 服务:`backend/services/workflow_service.py`
- 后端 history/adopt 服务:`backend/services/history_service.py`
- 后端提示词规划 schema:`backend/services/prompt_plan_schema_service.py`
- 后端素材绑定 schema:`backend/services/material_binding_schema_service.py`
- 后端节点注入模板:`backend/services/node_injection_template_service.py`
- 后端节点依赖上下文:`backend/services/node_dependency_context_service.py`
- 后端审查引擎:`engines/review_flow.py`
- 后端角色工作流服务:`backend/services/character_workflow_service.py`
- 角色工作流节点模板:`engines/character_flow.py`
- 相关测试:
- `tests/test_history_service.py`
- `tests/test_review_service.py`
- `tests/test_prompt_plan_schema_service.py`
- `tests/test_material_binding_schema_service.py`
- `tests/test_prompt_expansion_service.py`
- `tests/test_node_dependency_context_service.py`
- `tests/test_workflow_service.py`
- `tests/test_character_workflow_service.py`
## 已验证
- 前端类型检查:
- `npm.cmd run typecheck`
- 结果:通过。
- 后端 history 测试:
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_history_service`
- 结果:4 tests OK。
- 后端审查/历史/节点注入/单图生成相关测试:
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_review_service tests.test_history_service tests.test_prompt_expansion_service tests.test_node_dependency_context_service tests.test_single_flow_generation`
- 结果:28 tests OK。
- 后端素材绑定 schema / workflow 同步 / 上下文注入测试:
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_material_binding_schema_service tests.test_workflow_service tests.test_node_dependency_context_service tests.test_prompt_expansion_service tests.test_review_service tests.test_history_service`
- 结果:37 tests OK。
- 后端生成链路补充测试:
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_single_flow_generation tests.test_character_workflow_service`
- 结果:15 tests OK。
- 后端提示词规划 schema / workflow 同步 / 上下文注入测试:
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_prompt_plan_schema_service tests.test_workflow_service tests.test_node_dependency_context_service tests.test_prompt_expansion_service`
- 结果:26 tests OK。
- 后端角色工作流核心回归:
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_prompt_plan_schema_service tests.test_material_binding_schema_service tests.test_workflow_service tests.test_node_dependency_context_service tests.test_prompt_expansion_service tests.test_review_service tests.test_history_service tests.test_single_flow_generation tests.test_character_workflow_service`
- 结果:57 tests OK。
- 审查确认采用前端闭环补充验证:
- `npm.cmd run typecheck`
- 结果:通过。
- 使用 Codex bundled Python 运行 `python -m unittest tests.test_prompt_plan_schema_service tests.test_material_binding_schema_service tests.test_review_service tests.test_quick_profile_service tests.test_workflow_service tests.test_node_dependency_context_service tests.test_prompt_expansion_service tests.test_history_service`
- 结果:44 tests OK。
- 本地 dev server:
- `http://127.0.0.1:5173/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/?view=generate`
- HTTP 返回 200。
## 当前限制与风险
- 浏览器插件在一次 reload 验证时超时重置,因此没有执行页面内真实点击确认验证,避免误改本地工作流数据。
- `web/` 静态产物当前有旧资产删除和新资产生成,属于之前构建结果,提交前需要统一确认是否纳入。
- 工作区存在多处既有改动,提交前需要按功能拆分检查,不要把无关改动混进同一版。
- 阶段审查与高清修复输入桶已有后端结构,但还没有做完整页面点击回归。
- 最终入库节点仍需补齐角色版本、图片、提示词、素材引用、审查记录和分支信息的正式 schema。
## 建议下一步
1. 完成最终入库节点:保存角色版本、图片、提示词、素材引用、审查记录和分支信息。
2. 做一次完整浏览器手动回归:头像确认、半身确认、设定图确认、进入高清修复、锁定后创建分支。
3. 视提交策略决定是否纳入当前 `web/` 静态构建产物,避免把无关构建文件混入功能提交。

查看文件

@ -0,0 +1,101 @@
# ImageStudio UI / Workflow Progress Handoff
日期:2026-07-10
分支:`codex/ui-navigation-s130-s145`
范围:未提交变更检查、功能验证、静态构建、推送前总结。
## 推送前状态
- 已执行 `git fetch origin`。
- 检查结果:本地分支相对 `origin/codex/ui-navigation-s130-s145` 为 `0 ahead / 0 behind`,也就是没有“已提交但未推送”的 commit。
- 当前待发布内容来自工作区未提交改动,主要集中在完整工作台 UI、素材库工作台、队列工作台、角色工作流闭环、后端 schema/注入服务和对应测试。
## 已完成内容
### 前端工作台
- `frontend/standalone-web/src/App.vue` 扩展为更完整的 ImageStudio 工作台。
- 顶部导航现在聚焦:概览、生成、素材、角色、图库、设置、日志。
- 新增素材库工作台:
- 素材分类筛选。
- 示例素材卡和后端素材卡统一展示。
- 素材详情弹层。
- 添加分类弹层。
- 刷新素材、上传素材、识别、重识别、确认入库、导入素材包、并入衣橱、进入素材绑定等操作入口。
- 新增队列工作台:
- 活跃、失败、完成、全部筛选。
- 任务详情和批量操作入口。
- 角色工作流继续补齐:
- 提示词规划节点页面。
- 参考素材绑定节点页面。
- 阶段审查和候选图采用动作。
- 锁定节点创建分支入口。
- 最终归档入口的 UI 语义。
- 前端 API 客户端补充 `PUT` 请求方法。
### 后端闭环
- 新增提示词规划 schema 服务:
- `backend/services/prompt_plan_schema_service.py`
- 支持 prompt matrix、target/node 索引、继承字段、权重建议、guardrails 和 conflicts。
- 新增素材绑定 schema 服务:
- `backend/services/material_binding_schema_service.py`
- 支持 explicit-only 默认策略、rules、active rules、by stage、by node key、by node id 和 node parameters。
- 新增节点注入模板服务:
- `backend/services/node_injection_template_service.py`
- 统一生成节点对话注入契约,包含用户原文、节点上下文、素材绑定、提示词规划、阶段输入、草稿图选择和预期返回结构。
- `WorkflowService`:
- 保存 workflow/node metadata 时同步规范化 prompt plan 和 material bindings。
- 允许 completed 节点在采用图片时受控进入 selected。
- `NodeDependencyContextService`:
- 返回 prompt plan、material bindings 和 injection template。
- 按目标节点过滤上游上下文。
- `PromptExpansionService`:
- 注入 prompt plan patch、negative patch 和 node injection。
- `MaterialService`:
- 更新分类时校验 parent_id,避免自引用和无效父分类。
- 审查和历史相关服务继续补齐阶段审查、图片采用、分支锁定和 stage input handoff。
### 静态产物
- 已重新执行 `npm.cmd run build:web`。
- `web/index.html` 已指向新构建产物。
- 新产物:
- `web/assets/index-C91GfaJN.css`
- `web/assets/index-uM7AKRxw.js`
- 旧产物已被构建替换:
- `web/assets/index-B2NiW3rX.js`
- `web/assets/index-CPo7NaFF.css`
## 已验证
- `npm.cmd run typecheck`
- 结果:通过。
- `python -m unittest tests.test_prompt_plan_schema_service tests.test_material_binding_schema_service tests.test_workflow_service tests.test_node_dependency_context_service tests.test_prompt_expansion_service tests.test_review_service tests.test_history_service tests.test_material_service tests.test_character_workflow_service tests.test_plugin_entrypoint tests.test_s0_infrastructure`
- 使用 Codex bundled Python。
- 结果:81 tests OK。
- `npm.cmd run build:web`
- 结果:通过,生成最新 `web/` 静态产物。
- 内置浏览器打开:
- `http://127.0.0.1:5173/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/?view=materials`
- 结果:素材页标题、预览模式提示、示例素材卡、素材操作卡正常渲染。
- 控制台:未发现 error/warn。
- 素材详情弹层:点击示例素材卡后可打开。
## 未完成或仍需补齐
- 当前浏览器验证仍在前端预览模式下完成,没有连接真实 AstrBot 插件后端,因此未覆盖真实落库、文件上传、素材 VLM 识别和衣橱写入。
- 添加分类弹层需要再做一次真实浏览器交互验收;本次自动点击使用的选择器不够稳定,未作为通过项记录。
- 最终入库节点仍需要补齐正式 schema:角色版本、最终图片、提示词、素材引用、审查记录、分支信息和归档元数据。
- 角色图库与素材库的真实联动仍需继续深化。
- 素材上传入口、素材包导入入口目前以 UI/接口入口为主,文件选择、dry-run 预览和导入执行流程还需要后续完整实现。
- 需要在真实后端环境做一次端到端验收:快速角色创建、工作流生成、提示词规划保存、素材绑定保存、阶段审查采用、锁定后分支、最终归档。
## 备注
- 本次检查开始时没有未推送 commit;推送动作应在提交当前工作区改动后执行。
- 已创建本地提交:`feat: extend workflow and materials workbench`。
- 已尝试执行 `git push origin codex/ui-navigation-s130-s145`,但远端 Git HTTP 返回凭据不正确或已过期。
- Forgejo API 认证仍可用,并确认远端 `codex/ui-navigation-s130-s145` 当前仍停在 `b61c6274e5a7ddbcbad1d67f0f0fcfe7da7f3264`。
- 因此当前状态为:本地分支 ahead 1,等待更新本机 Git 凭据后再次推送。
- Windows shell 提示多处 LF/CRLF 警告,未发现影响构建或测试的行为问题。

查看文件

@ -13,54 +13,70 @@ CHARACTER_GRADUAL_STEPS: tuple[dict[str, Any], ...] = (
"description": "Core identity, personality, and visual anchors.",
"sort_order": 10,
},
{
"node_key": "prompt_plan",
"title": "Prompt plan",
"step_name": "prompt_plan",
"description": "Prompt matrix for portrait, half body, full body, and design sheet nodes.",
"node_type": "planning",
"sort_order": 20,
},
{
"node_key": "material_bind",
"title": "Material binding",
"step_name": "material_bind",
"description": "Bind style, composition, clothing, shoes, and accessory references to downstream nodes.",
"node_type": "reference_binding",
"sort_order": 30,
},
{
"node_key": "headshot",
"title": "Headshot",
"step_name": "headshot",
"description": "Face, hair, eyes, and expression direction.",
"sort_order": 20,
"sort_order": 40,
},
{
"node_key": "half_body",
"title": "Half body",
"step_name": "half_body",
"description": "Upper body costume, posture, and silhouette.",
"sort_order": 30,
"sort_order": 50,
},
{
"node_key": "full_body",
"title": "Full body",
"step_name": "full_body",
"description": "Full outfit, proportions, and full-body design.",
"sort_order": 40,
"sort_order": 60,
},
{
"node_key": "expression_sheet",
"title": "Expression sheet",
"step_name": "expression_sheet",
"description": "Reusable expression variants.",
"sort_order": 50,
"sort_order": 70,
},
{
"node_key": "pose_sheet",
"title": "Pose sheet",
"step_name": "pose_sheet",
"description": "Reusable pose and action variants.",
"sort_order": 60,
"sort_order": 80,
},
{
"node_key": "style_lock",
"title": "Style lock",
"step_name": "style_lock",
"description": "Final style pass and prompt consistency lock.",
"sort_order": 70,
"sort_order": 90,
},
{
"node_key": "final_pack",
"title": "Final pack",
"step_name": "final_pack",
"description": "Final accepted images and production metadata.",
"sort_order": 80,
"sort_order": 100,
},
)
@ -69,7 +85,7 @@ def gradual_node_templates() -> list[dict[str, Any]]:
return [
{
**step,
"node_type": "generation",
"node_type": step.get("node_type", "generation"),
"status": "draft",
"branch_name": "main",
"metadata": {"template": "character_gradual_v1"},

查看文件

@ -8,6 +8,8 @@ from typing import Any
from backend.dto.image_dto import GenerationImage
from backend.dto.workflow_dto import ProfileWorkflow, WorkflowNode
STAGE_REVIEW_RESULT_VERSION = "2026-07-09.stage-review-result.v1"
_KNOWN_NODE_STATUSES = {
"draft",
@ -107,7 +109,12 @@ class ReviewFlowEngine:
policy, errors = ReviewPolicy.from_mapping(payload)
return {"valid": not errors, "policy": policy.to_dict(), "errors": errors}
def review_node(self, node: WorkflowNode, images: list[GenerationImage]) -> dict[str, Any]:
def review_node(
self,
node: WorkflowNode,
images: list[GenerationImage],
workflow_metadata: dict[str, Any] | None = None,
) -> dict[str, Any]:
warnings: list[dict[str, Any]] = []
errors: list[dict[str, Any]] = []
selected_image = next((image for image in images if image.image_id == node.selected_image_id), None)
@ -158,6 +165,7 @@ class ReviewFlowEngine:
"node_model_route": node.model_route,
"policy_version": self.policy.version,
},
"stage_review": build_stage_review_result(node, images, workflow_metadata or {}),
}
def review_workflow(
@ -227,3 +235,197 @@ def _normalize_status_list(value: Any) -> tuple[str, ...]:
def _normalize_prompt(value: str) -> str:
return " ".join(str(value or "").lower().replace(",", " ").split())
def build_stage_review_result(
node: WorkflowNode,
images: list[GenerationImage],
workflow_metadata: dict[str, Any] | None = None,
) -> dict[str, Any]:
candidates = [_review_candidate(node, image, index + 1) for index, image in enumerate(images)]
selected_candidate = next(
(
{
"candidate_id": candidate["candidate_id"],
"image_id": candidate["image_id"],
"model_route": candidate["model_route"],
"score": candidate["score"],
"status": candidate["status"],
}
for candidate in candidates
if candidate["image_id"] == node.selected_image_id or candidate["is_selected"]
),
None,
)
return {
"schema_version": STAGE_REVIEW_RESULT_VERSION,
"node_id": node.node_id,
"node_key": node.node_key,
"review_mode": "same_prompt_multi_model",
"prompt_contract": {
"positive_prompt": node.prompt,
"negative_prompt": node.negative_prompt,
"model_route": node.model_route,
"locked_after_confirm": True,
},
"scoring_dimensions": [
"identity_consistency",
"prompt_consistency",
"model_route_consistency",
"visual_defects",
"archive_state",
],
"candidates": candidates,
"selected_candidate": selected_candidate,
"regeneration_records": [
candidate["regeneration"]
for candidate in candidates
if candidate.get("regeneration", {}).get("is_regeneration")
],
"manual_confirmation": {
"action": "adopt_image",
"endpoint": f"nodes/{node.node_id}/adopt-image",
"requires_image_id": True,
"changes_node_status_to": "selected",
"locks_source_node": True,
"branch_required_after_confirm": True,
},
"handoff": {
"current_node_input": _stage_input_for_node(workflow_metadata or {}, node.node_id),
"metadata_key": "stage_inputs",
"expected_next_input_shape": {
"image_id": "string",
"from_node_id": node.node_id,
"history_id": "string",
"role": "next_stage_input | hires_fix_input",
},
},
}
def _review_candidate(node: WorkflowNode, image: GenerationImage, rank: int) -> dict[str, Any]:
metadata = image.metadata if isinstance(image.metadata, dict) else {}
warnings = _candidate_warnings(node, image)
defects = _string_list(metadata.get("review_defects") or metadata.get("defects"))
score_value, score_basis = _candidate_score(metadata, warnings, defects, image.is_archived)
status = "selected" if image.is_selected or image.image_id == node.selected_image_id else "candidate"
if image.is_archived:
status = "archived"
return {
"candidate_id": f"{node.node_id}:{image.image_id}",
"rank": rank,
"image_id": image.image_id,
"image_uri": image.image_uri,
"thumbnail_uri": image.thumbnail_uri,
"model_route": image.model_route,
"model_used": image.model_used,
"seed": image.seed,
"width": image.width,
"height": image.height,
"positive_prompt": image.positive_prompt,
"negative_prompt": image.negative_prompt,
"is_selected": image.is_selected or image.image_id == node.selected_image_id,
"is_archived": image.is_archived,
"status": status,
"warnings": warnings,
"defects": defects,
"score": {
"value": score_value,
"basis": score_basis,
"warnings_count": len(warnings),
"defects_count": len(defects),
},
"regeneration": _regeneration_record(node, image, metadata),
}
def _candidate_warnings(node: WorkflowNode, image: GenerationImage) -> list[dict[str, Any]]:
warnings: list[dict[str, Any]] = []
if image.is_archived:
warnings.append({"code": "ARCHIVED", "message": "candidate image is archived"})
if node.model_route and image.model_route and node.model_route != image.model_route:
warnings.append(
{
"code": "MODEL_ROUTE_MISMATCH",
"message": "candidate model_route differs from node model_route",
"node_model_route": node.model_route,
"image_model_route": image.model_route,
}
)
if node.prompt and image.positive_prompt:
node_prompt = _normalize_prompt(node.prompt)
image_prompt = _normalize_prompt(image.positive_prompt)
if node_prompt and image_prompt and node_prompt not in image_prompt and image_prompt not in node_prompt:
warnings.append({"code": "PROMPT_MISMATCH", "message": "candidate prompt differs from node prompt"})
return warnings
def _candidate_score(
metadata: dict[str, Any],
warnings: list[dict[str, Any]],
defects: list[str],
is_archived: bool,
) -> tuple[int, str]:
explicit = metadata.get("review_score")
if isinstance(explicit, (int, float)):
return max(0, min(100, int(explicit))), "metadata.review_score"
score = 100 - len(warnings) * 10 - len(defects) * 8
if is_archived:
score -= 40
return max(0, min(100, score)), "heuristic"
def _regeneration_record(node: WorkflowNode, image: GenerationImage, metadata: dict[str, Any]) -> dict[str, Any]:
source_image_id = _optional_text(
metadata.get("regenerated_from_image_id")
or metadata.get("source_image_id")
or metadata.get("review_source_image_id")
)
is_regeneration = bool(
source_image_id
or metadata.get("same_prompt_regeneration")
or metadata.get("review_regeneration")
or metadata.get("regeneration_attempt")
)
return {
"is_regeneration": is_regeneration,
"image_id": image.image_id,
"source_image_id": source_image_id,
"node_id": node.node_id,
"same_prompt": bool(metadata.get("same_prompt_regeneration") or metadata.get("review_regeneration")),
"attempt": _optional_int(metadata.get("regeneration_attempt") or metadata.get("review_attempt")),
"model_route": image.model_route,
"created_at": image.created_at,
}
def _stage_input_for_node(workflow_metadata: dict[str, Any], node_id: str) -> dict[str, Any]:
stage_inputs = workflow_metadata.get("stage_inputs")
if not isinstance(stage_inputs, dict):
return {}
value = stage_inputs.get(node_id)
return value if isinstance(value, dict) else {}
def _string_list(value: Any) -> list[str]:
if isinstance(value, str):
return [value] if value.strip() else []
if not isinstance(value, list):
return []
return [str(item).strip() for item in value if str(item or "").strip()]
def _optional_text(value: Any) -> str | None:
if value is None:
return None
text = str(value).strip()
return text or None
def _optional_int(value: Any) -> int | None:
if value is None:
return None
try:
return int(value)
except (TypeError, ValueError):
return None

查看文件

@ -23,6 +23,10 @@ export async function postJson<T>(endpoint: string, body?: unknown) {
return request<T>(endpoint, { method: "POST", body })
}
export async function putJson<T>(endpoint: string, body?: unknown) {
return request<T>(endpoint, { method: "PUT", body })
}
export function getApiTransport(): ApiTransport {
const bridge = typeof window === "undefined" ? undefined : window.AstrBotPluginPage
return bridge && (typeof bridge.apiGet === "function" || typeof bridge.apiPost === "function")
@ -95,6 +99,12 @@ async function requestViaPluginBridge<T>(
if (method === "POST" && typeof bridge.apiPost === "function") {
return bridge.apiPost<T | ApiResponse<T>>(endpoint, options.body)
}
if (method === "PUT" && typeof bridge.apiPut === "function") {
return bridge.apiPut<T | ApiResponse<T>>(endpoint, options.body)
}
if (method === "DELETE" && typeof bridge.apiDelete === "function") {
return bridge.apiDelete<T | ApiResponse<T>>(endpoint)
}
return undefined
}

文件差异内容过多而无法显示 加载差异

查看文件

@ -32,6 +32,7 @@ from backend.route_registry import ROUTES
from backend.services.ui_service import API_BASE
from core.identity import RequestContext
from database import db_helper as _database_db_helper
from database.seed import seed_default_material_categories
try:
if not hasattr(_database_db_helper, "set_runtime_config_overrides"):
@ -91,7 +92,8 @@ def get_runtime_health() -> dict[str, Any]:
def initialize_runtime_database(settings: DatabaseSettings | None = None) -> dict[str, Any]:
database = Database(settings or load_database_settings())
database.initialize()
return {"initialized": True, "backend": database.backend}
seed = seed_default_material_categories(database)
return {"initialized": True, "backend": database.backend, "seed": {"material_categories": seed}}
def apply_astrbot_config_overrides(config: Any | None) -> dict[str, Any]:

查看文件

@ -80,7 +80,9 @@ class CharacterWorkflowServiceTests(unittest.TestCase):
result = self.character_service.execute_workflow(detail.workflow.workflow_id, self.ctx)
self.assertEqual(len(result["completed_node_ids"]), 8)
self.assertEqual(len(result["completed_node_ids"]), 10)
material_bind = next(node for node in result["nodes"] if node["node_key"] == "material_bind")
self.assertIn("reference material binding rules", material_bind["prompt"])
final_pack = result["nodes"][-1]
self.assertEqual(final_pack["node_key"], "final_pack")
self.assertIn("final character pack", final_pack["prompt"])

查看文件

@ -5,6 +5,7 @@ import unittest
from pathlib import Path
from uuid import uuid4
from backend.dto.common import ApiError, ErrorCode
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
@ -94,6 +95,70 @@ class HistoryServiceTests(unittest.TestCase):
listed = self.history_service.list_workflow_history(self.workflow.workflow.workflow_id)
self.assertEqual([entry.history_id for entry in listed], [history.history_id])
def test_adopt_node_image_can_finalize_completed_node(self):
self.workflow_service.update_node(self.node.node_id, {"status": "completed"}, self.ctx)
history = self.history_service.adopt_node_image(
self.node.node_id,
{"image_id": self.image.image_id, "title": "Finalized headshot"},
self.ctx,
)
node = self.workflow_service.get_node(self.node.node_id)
selected = self.image_service.get_image(self.image.image_id)
self.assertEqual(history.action, "adopt_image")
self.assertEqual(node.status, "selected")
self.assertEqual(node.selected_image_id, self.image.image_id)
self.assertTrue(selected.is_selected)
def test_adopt_node_image_persists_stage_handoff_bucket(self):
next_node = self.workflow.nodes[2]
history = self.history_service.adopt_node_image(
self.node.node_id,
{
"image_id": self.image.image_id,
"metadata": {
"source": "standalone_web_stage_review_confirm",
"ui_review_node_id": "portrait-review",
"source_ui_node_id": "portrait-03",
"next_ui_node_id": "hires-fix",
"next_backend_node_id": next_node.node_id,
"handoff_bucket": "hires-fix",
"handoff_role": "hires_fix_input",
},
},
self.ctx,
)
workflow = self.workflow_service.get_workflow(self.workflow.workflow.workflow_id).workflow
stage_input = workflow.metadata["stage_inputs"][next_node.node_id]
self.assertEqual(workflow.current_node_id, next_node.node_id)
self.assertEqual(workflow.metadata["stage_input_schema_version"], "2026-07-09.stage-input-bucket.v1")
self.assertEqual(stage_input["image_id"], self.image.image_id)
self.assertEqual(stage_input["image_uri"], "storage://images/headshot.png")
self.assertEqual(stage_input["from_node_id"], self.node.node_id)
self.assertEqual(stage_input["history_id"], history.history_id)
self.assertEqual(stage_input["role"], "hires_fix_input")
self.assertTrue(stage_input["locked_source_node"])
def test_adopt_node_image_rejects_switching_selected_node_without_branch(self):
self.history_service.adopt_node_image(self.node.node_id, {"image_id": self.image.image_id}, self.ctx)
other = self.image_service.create_image(
{
"node_id": self.node.node_id,
"image_uri": "storage://images/other-headshot.png",
"positive_prompt": "alternate headshot",
},
self.ctx,
)
with self.assertRaises(ApiError) as raised:
self.history_service.adopt_node_image(self.node.node_id, {"image_id": other.image_id}, self.ctx)
self.assertEqual(raised.exception.error_code, ErrorCode.VALIDATION_FAILED)
self.assertEqual(raised.exception.details["suggested_action"], "create_branch")
def test_history_routes_wrap_responses_and_require_permissions(self):
response = adopt_node_image(
self.ctx,

查看文件

@ -0,0 +1,116 @@
from __future__ import annotations
import unittest
from backend.dto.workflow_dto import WorkflowNode
from backend.services.material_binding_schema_service import (
MATERIAL_BINDING_SCHEMA_VERSION,
node_material_binding_view,
normalize_material_bindings,
)
class MaterialBindingSchemaServiceTests(unittest.TestCase):
def test_normalize_material_bindings_indexes_active_rules_by_stage_and_node(self):
headshot = _node("node_headshot", "headshot", "Headshot")
half_body = _node("node_half_body", "half_body", "Half body")
full_body = _node("node_full_body", "full_body", "Full body")
normalized = normalize_material_bindings(
{
"profile_id": "profile_001",
"profile_name": "Nova",
"selected_material_ids": ["mat_style"],
"rules": [
{
"id": "rule_style",
"category": "风格",
"material_id": "mat_style",
"material_label": "Soft light",
"material_group": "style",
"material_prompt": "soft watercolor, clean line art",
"material_colors": ["#f7d9e5"],
"bind_to_stages": [
{"stage_id": "portrait-draft", "stage_title": "头像"},
{"stage_id": "halfbody-draft", "stage_title": "半身像"},
],
"inheritance_rule": "keep style across portrait and half body",
"reference_strength": "强",
"required": True,
"status": "ready",
},
{
"id": "rule_clothing",
"category": "服装",
"material_id": "",
"material_prompt": "",
"bind_to_stages": [{"stage_id": "body-sheet", "stage_title": "设定图"}],
"reference_strength": "中",
},
],
},
[headshot, half_body, full_body],
)
self.assertEqual(normalized["schema_version"], MATERIAL_BINDING_SCHEMA_VERSION)
self.assertFalse(normalized["reference_policy"]["default_use_reference"])
self.assertEqual(normalized["summary"]["rule_count"], 2)
self.assertEqual(normalized["summary"]["active_rule_count"], 1)
self.assertEqual(normalized["summary"]["disabled_categories"], ["服装"])
self.assertIn("portrait-draft", normalized["by_stage"])
self.assertIn("headshot", normalized["by_node_key"])
self.assertIn("half_body", normalized["by_node_key"])
self.assertIn("node_headshot", normalized["by_node_id"])
self.assertNotIn("node_full_body", normalized["by_node_id"])
half_body_view = node_material_binding_view(normalized, half_body)
self.assertTrue(half_body_view["has_references"])
self.assertEqual(half_body_view["active_bindings"][0]["material"]["material_id"], "mat_style")
self.assertEqual(half_body_view["generation_params"]["reference_material_ids"], ["mat_style"])
def test_empty_material_rule_means_do_not_use_reference(self):
headshot = _node("node_headshot", "headshot", "Headshot")
normalized = normalize_material_bindings(
{
"rules": [
{
"category": "构图",
"bind_to_stages": [{"stage_id": "portrait-draft", "stage_title": "头像"}],
"reference_strength": "中",
}
]
},
[headshot],
)
view = node_material_binding_view(normalized, headshot)
self.assertFalse(normalized["summary"]["has_references"])
self.assertFalse(view["has_references"])
self.assertEqual(view["generation_params"]["reference_material_ids"], [])
def _node(node_id: str, node_key: str, title: str) -> WorkflowNode:
return WorkflowNode(
node_id=node_id,
workflow_id="workflow_001",
node_key=node_key,
title=title,
description=None,
step_name=node_key,
node_type="generation",
status="draft",
branch_name="main",
prompt=None,
negative_prompt=None,
model_route=None,
selected_image_id=None,
sort_order=1,
metadata={},
created_at="2026-01-01T00:00:00Z",
updated_at="2026-01-01T00:00:00Z",
)
if __name__ == "__main__":
unittest.main()

查看文件

@ -324,13 +324,30 @@ storage:
self.assertEqual(caught.exception.details["max_size_bytes"], MAX_UPLOAD_BYTES)
def test_material_routes_wrap_responses_and_require_permission(self):
category = create_material_category(self.ctx, {"name": "Accessory"}, self.material_service)
category = create_material_category(self.ctx, {"name": "配饰"}, self.material_service)
self.assertTrue(category["ok"])
category_id = category["data"]["category_id"]
child_category = create_material_category(
self.ctx,
{"name": "头部", "parent_id": category_id, "category_type": "accessory_group"},
self.material_service,
)
self.assertTrue(child_category["ok"])
self.assertEqual(child_category["data"]["parent_id"], category_id)
self.assertEqual(child_category["data"]["category_type"], "accessory_group")
categories = list_material_categories(self.ctx, self.material_service)
self.assertTrue(categories["ok"])
self.assertEqual(len(categories["data"]), 1)
self.assertEqual(len(categories["data"]), 2)
self.assertTrue(any(item["name"] == "头部" and item["parent_id"] == category_id for item in categories["data"]))
bad_child = create_material_category(
self.ctx,
{"name": "断链分类", "parent_id": "cat_missing", "category_type": "accessory_group"},
self.material_service,
)
self.assertFalse(bad_child["ok"])
self.assertEqual(bad_child["error_code"], "RESOURCE_NOT_FOUND")
(self.root / "materials" / "ribbon.png").write_bytes(b"ribbon")
material = create_material(

查看文件

@ -80,8 +80,114 @@ class NodeDependencyContextServiceTests(unittest.TestCase):
self.assertEqual(context["selected_image_ids"], [image.image_id])
self.assertIn("headshot, silver hair", context["prompt_context"])
self.assertEqual(context["dependencies"][0]["selected_image"]["image_uri"], "storage://images/headshot.png")
self.assertEqual(context["injection_template"]["version"], "2026-07-09.node-injection-schema.v1")
self.assertEqual(context["injection_template"]["template_kind"], "material_bind")
self.assertEqual(context["injection_template"]["language_policy"]["translation_mode"], "backend_llm")
self.assertIn("expected_response_schema", context["injection_template"])
self.assertNotIn(str(self.tmp.name), str(context))
def test_context_includes_node_scoped_material_bindings(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,
{"workflow_type": "character_gradual", "display_name": "Gradual"},
self.ctx,
)
material_bind = next(node for node in detail.nodes if node.node_key == "material_bind")
headshot = next(node for node in detail.nodes if node.node_key == "headshot")
half_body = next(node for node in detail.nodes if node.node_key == "half_body")
self.workflow_service.update_node(
material_bind.node_id,
{
"metadata": {
"material_bindings": {
"rules": [
{
"id": "rule_style",
"category": "风格",
"material_id": "mat_style",
"material_label": "Soft light",
"material_prompt": "soft watercolor",
"bind_to_stages": [{"stage_id": "portrait-draft", "stage_title": "头像"}],
"reference_strength": "强",
"status": "ready",
},
{
"id": "rule_clothing",
"category": "服装",
"material_id": "mat_clothing",
"material_label": "White blouse",
"material_prompt": "white lace blouse",
"bind_to_stages": [{"stage_id": "halfbody-draft", "stage_title": "半身像"}],
"reference_strength": "中",
"status": "ready",
},
]
}
}
},
self.ctx,
)
headshot_context = self.context_service.get_context(headshot.node_id)
half_body_context = self.context_service.get_context(half_body.node_id)
self.assertEqual(headshot_context["material_bindings"]["target_node_key"], "headshot")
self.assertEqual(headshot_context["material_bindings"]["generation_params"]["reference_material_ids"], ["mat_style"])
self.assertEqual(half_body_context["material_bindings"]["generation_params"]["reference_material_ids"], ["mat_clothing"])
self.assertEqual(
headshot_context["injection_template"]["material_bindings"]["schema_version"],
"2026-07-09.material-binding-schema.v1",
)
def test_context_includes_node_scoped_prompt_plan(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,
{"workflow_type": "character_gradual", "display_name": "Gradual"},
self.ctx,
)
prompt_plan = next(node for node in detail.nodes if node.node_key == "prompt_plan")
headshot = next(node for node in detail.nodes if node.node_key == "headshot")
full_body = next(node for node in detail.nodes if node.node_key == "full_body")
self.workflow_service.update_node(
prompt_plan.node_id,
{
"metadata": {
"prompt_plan": {
"items": [
{
"id": "portrait",
"title": "头像节点",
"prompt": "Nova, face reference, clear eyes",
"negative": "low quality, blurry",
"inherits": ["name", "hair", "eyes"],
"status": "ready",
},
{
"id": "fullbody",
"title": "全身节点",
"prompt": "Nova, full body standing pose",
"negative": "bad anatomy",
"conflicts": ["shoe details need review"],
"status": "review",
},
]
}
}
},
self.ctx,
)
headshot_context = self.context_service.get_context(headshot.node_id)
full_body_context = self.context_service.get_context(full_body.node_id)
self.assertEqual(headshot_context["prompt_plan"]["target_node_key"], "headshot")
self.assertEqual(headshot_context["prompt_plan"]["generation_params"]["prompt_patch"], "Nova, face reference, clear eyes")
self.assertEqual(full_body_context["prompt_plan"]["generation_params"]["negative_patch"], "bad anatomy")
self.assertEqual(
headshot_context["injection_template"]["prompt_plan"]["schema_version"],
"2026-07-09.prompt-plan-schema.v1",
)
def test_dependency_context_route_requires_authentication(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,

查看文件

@ -7,7 +7,7 @@ from pathlib import Path
from backend.route_registry import ROUTES
from core.identity import RequestContext
from database.db_helper import DatabaseSettings, SqliteSettings
from database.db_helper import Database, DatabaseSettings, SqliteSettings
from database.db_helper import load_database_settings, set_runtime_config_overrides
from main import (
Main,
@ -110,11 +110,27 @@ class PluginEntrypointTests(unittest.TestCase):
def test_initialize_runtime_database_runs_migrations(self):
with tempfile.TemporaryDirectory() as tmp:
db_path = Path(tmp) / "imagestudio.db"
result = initialize_runtime_database(DatabaseSettings(sqlite=SqliteSettings(path=str(db_path))))
settings = DatabaseSettings(sqlite=SqliteSettings(path=str(db_path)))
result = initialize_runtime_database(settings)
self.assertTrue(result["initialized"])
self.assertEqual(result["backend"], "sqlite")
self.assertGreater(result["seed"]["material_categories"]["total"], 0)
self.assertTrue(db_path.exists())
database = Database(settings)
conn = database.connect()
try:
row = conn.execute(
"""
SELECT parent_id, category_type
FROM material_categories
WHERE category_id = 'cat_imagestudio_accessory_头部'
"""
).fetchone()
finally:
conn.close()
self.assertEqual(row["parent_id"], "cat_imagestudio_配饰")
self.assertEqual(row["category_type"], "accessory_group")
def test_astrbot_config_overrides_default_database_settings(self):
try:

查看文件

@ -53,7 +53,27 @@ class PromptExpansionServiceTests(unittest.TestCase):
result = PromptExpansionService().expand_for_node(
profile,
node,
{"prompt_patch": "white blouse", "negative_prompt_patch": "watermark"},
{
"prompt_patch": "white blouse",
"negative_prompt_patch": "watermark",
"metadata": {
"node_injection_kind": "portrait_generation",
"user_instruction": "把眼神改得更坚定",
"selected_draft_image_ids": ["img_draft_001"],
},
"dependency_context": {
"dependency_count": 1,
"prompt_context": "approved headshot",
"selected_image_ids": ["img_headshot_001"],
"dependencies": [],
"material_bindings": {
"schema_version": "2026-07-09.material-binding-schema.v1",
"target_node_key": "headshot",
"generation_params": {"reference_material_ids": ["mat_style"]},
"active_bindings": [{"category": "风格"}],
},
},
},
)
self.assertEqual(
@ -62,6 +82,77 @@ class PromptExpansionServiceTests(unittest.TestCase):
)
self.assertEqual(result["negative_prompt"], "low quality, bad hands, watermark")
self.assertEqual(result["source"], "profile_node")
self.assertEqual(result["node_injection"]["version"], "2026-07-09.node-injection-schema.v1")
self.assertEqual(result["node_injection"]["template_kind"], "portrait_generation")
self.assertEqual(result["node_injection"]["language_policy"]["target_prompt_language"], "en")
self.assertEqual(result["node_injection"]["user_instruction"]["raw_text"], "把眼神改得更坚定")
self.assertEqual(result["node_injection"]["dependency_context"]["selected_image_ids"], ["img_headshot_001"])
self.assertEqual(result["node_injection"]["material_bindings"]["generation_params"]["reference_material_ids"], ["mat_style"])
self.assertEqual(result["node_injection"]["selected_draft_image_ids"], ["img_draft_001"])
def test_expand_for_node_includes_prompt_plan_context(self):
profile = CharacterProfile(
profile_id="profile_001",
name="Nova",
description=None,
base_prompt="portrait of {profile_name}",
appearance_prompt="silver hair",
style_prompt="soft watercolor",
negative_prompt="low quality",
default_model_route="image_low",
owner_platform="webui",
owner_context_id=None,
owner_user_id="user_001",
owner_session_key=None,
avatar_image_uri=None,
status="active",
metadata={},
created_at="2026-01-01T00:00:00Z",
updated_at="2026-01-01T00:00:00Z",
)
node = WorkflowNode(
node_id="node_headshot",
workflow_id="workflow_001",
node_key="headshot",
title="Headshot",
description=None,
step_name=None,
node_type="generation",
status="draft",
branch_name="main",
prompt="base headshot",
negative_prompt="bad hands",
model_route="image_low",
selected_image_id=None,
sort_order=40,
metadata={},
created_at="2026-01-01T00:00:00Z",
updated_at="2026-01-01T00:00:00Z",
)
result = PromptExpansionService().expand_for_node(
profile,
node,
{
"dependency_context": {
"prompt_plan": {
"schema_version": "2026-07-09.prompt-plan-schema.v1",
"target_node_key": "headshot",
"generation_params": {
"prompt_patch": "clear eyes, stronger face lock",
"negative_patch": "duplicate face",
},
}
}
},
)
self.assertEqual(
result["prompt"],
"portrait of Nova, silver hair, soft watercolor, base headshot, clear eyes, stronger face lock",
)
self.assertEqual(result["negative_prompt"], "low quality, bad hands, duplicate face")
self.assertEqual(result["node_injection"]["prompt_plan"]["target_node_key"], "headshot")
def test_expand_prompt_route_requires_authentication(self):
ctx = RequestContext.from_astrbot(username="admin", user_id="user_001")

查看文件

@ -0,0 +1,115 @@
from __future__ import annotations
import unittest
from backend.dto.workflow_dto import WorkflowNode
from backend.services.prompt_plan_schema_service import (
PROMPT_PLAN_SCHEMA_VERSION,
node_prompt_plan_view,
normalize_prompt_plan,
)
class PromptPlanSchemaServiceTests(unittest.TestCase):
def test_normalize_prompt_plan_indexes_matrix_by_target_and_node(self):
headshot = _node("node_headshot", "headshot", "Headshot")
half_body = _node("node_half_body", "half_body", "Half body")
full_body = _node("node_full_body", "full_body", "Full body")
normalized = normalize_prompt_plan(
{
"profile_id": "profile_001",
"profile_name": "Nova",
"items": [
{
"id": "portrait",
"title": "头像节点",
"prompt": "Nova, face reference, clear eyes",
"negative": "low quality, blurry",
"weight": "face identity 1.25",
"weightBasis": "lock identity first",
"inherits": ["name", "hair", "eyes"],
"status": "ready",
},
{
"id": "fullbody",
"title": "全身节点",
"prompt": "Nova, full body standing pose",
"negative": "bad anatomy",
"weight_changes": [{"label": "body proportion", "value": 1.18, "reason": "keep silhouette"}],
"conflicts": ["shoe and accessory inheritance needs review"],
"status": "review",
},
],
"guard_checks": [
{"label": "冲突检查", "value": "shoe and accessory inheritance needs review", "status": "review"}
],
},
[headshot, half_body, full_body],
)
self.assertEqual(normalized["schema_version"], PROMPT_PLAN_SCHEMA_VERSION)
self.assertEqual(normalized["summary"]["target_count"], 2)
self.assertEqual(normalized["summary"]["review_count"], 1)
self.assertEqual(normalized["summary"]["conflict_count"], 2)
self.assertIn("portrait", normalized["by_target"])
self.assertIn("headshot", normalized["by_node_key"])
self.assertIn("full_body", normalized["by_node_key"])
self.assertIn(headshot.node_id, normalized["by_node_id"])
self.assertNotIn(half_body.node_id, normalized["by_node_id"])
headshot_view = node_prompt_plan_view(normalized, headshot)
self.assertTrue(headshot_view["has_prompt_plan"])
self.assertEqual(headshot_view["generation_params"]["prompt_patch"], "Nova, face reference, clear eyes")
self.assertEqual(headshot_view["generation_params"]["negative_patch"], "low quality, blurry")
self.assertEqual(headshot_view["generation_params"]["inheritance_fields"], ["name", "hair", "eyes"])
def test_llm_update_shape_is_accepted(self):
headshot = _node("node_headshot", "headshot", "Headshot")
normalized = normalize_prompt_plan(
{
"updates": [
{
"target": "portrait",
"positive_patch": "clearer gaze, stronger face lock",
"negative_patch": "duplicate face",
"weight_suggestions": [{"label": "eye color", "value": 1.18}],
"inheritance_changes": ["preserve silver hair"],
}
],
"guardrails": {"negative_prompt": "duplicate face"},
},
[headshot],
)
view = node_prompt_plan_view(normalized, headshot)
self.assertEqual(view["generation_params"]["prompt_patch"], "clearer gaze, stronger face lock")
self.assertEqual(view["generation_params"]["negative_patch"], "duplicate face")
self.assertEqual(view["generation_params"]["weight_suggestions"][0]["label"], "eye color")
def _node(node_id: str, node_key: str, title: str) -> WorkflowNode:
return WorkflowNode(
node_id=node_id,
workflow_id="workflow_001",
node_key=node_key,
title=title,
description=None,
step_name=node_key,
node_type="generation",
status="draft",
branch_name="main",
prompt=None,
negative_prompt=None,
model_route=None,
selected_image_id=None,
sort_order=1,
metadata={},
created_at="2026-01-01T00:00:00Z",
updated_at="2026-01-01T00:00:00Z",
)
if __name__ == "__main__":
unittest.main()

查看文件

@ -90,6 +90,8 @@ class ReviewServiceTests(unittest.TestCase):
"node_id": node.node_id,
"image_uri": "storage://images/fast.png",
"positive_prompt": "fast character",
"model_route": "image_low",
"metadata": {"review_score": 91},
},
self.ctx,
)
@ -99,6 +101,11 @@ class ReviewServiceTests(unittest.TestCase):
self.assertTrue(result["passed"])
self.assertEqual(result["summary"]["selected_image_id"], image.image_id)
self.assertEqual(result["stage_review"]["schema_version"], "2026-07-09.stage-review-result.v1")
self.assertEqual(result["stage_review"]["review_mode"], "same_prompt_multi_model")
self.assertEqual(result["stage_review"]["selected_candidate"]["image_id"], image.image_id)
self.assertEqual(result["stage_review"]["candidates"][0]["score"]["value"], 91)
self.assertEqual(result["stage_review"]["manual_confirmation"]["endpoint"], f"nodes/{node.node_id}/adopt-image")
def test_review_warns_about_prompt_and_model_route_mismatch(self):
node = self.workflow.nodes[1]
@ -125,6 +132,47 @@ class ReviewServiceTests(unittest.TestCase):
self.assertIn("MODEL_ROUTE_MISMATCH", [warning["code"] for warning in result["warnings"]])
self.assertIn("PROMPT_MISMATCH", [warning["code"] for warning in result["warnings"]])
def test_review_stage_result_tracks_multi_model_regeneration_candidates(self):
node = self.workflow.nodes[1]
self.workflow_service.update_node(
node.node_id,
{"status": "completed", "prompt": "portrait, silver hair", "model_route": "image_low"},
self.ctx,
)
source = self.image_service.create_image(
{
"node_id": node.node_id,
"image_uri": "storage://images/source.png",
"positive_prompt": "portrait, silver hair",
"model_route": "image_low",
"is_selected": True,
},
self.ctx,
)
rerun = self.image_service.create_image(
{
"node_id": node.node_id,
"image_uri": "storage://images/rerun.png",
"positive_prompt": "portrait, silver hair",
"model_route": "image_high",
"metadata": {
"same_prompt_regeneration": True,
"regenerated_from_image_id": source.image_id,
"regeneration_attempt": 2,
"review_defects": ["face drift"],
},
},
self.ctx,
)
result = self.review_service.review_node(node.node_id)
self.assertEqual(len(result["stage_review"]["candidates"]), 2)
self.assertEqual(result["stage_review"]["selected_candidate"]["image_id"], source.image_id)
self.assertEqual(result["stage_review"]["regeneration_records"][0]["image_id"], rerun.image_id)
self.assertEqual(result["stage_review"]["regeneration_records"][0]["source_image_id"], source.image_id)
self.assertEqual(result["stage_review"]["regeneration_records"][0]["attempt"], 2)
def test_review_workflow_warns_when_selected_images_mix_model_routes(self):
first, second = self.workflow.nodes[:2]
for node, route in ((first, "image_low"), (second, "image_high")):

查看文件

@ -134,9 +134,18 @@ class DatabaseMetadataTests(unittest.TestCase):
conn = database.connect()
try:
count = conn.execute("SELECT COUNT(*) AS total FROM material_categories").fetchone()["total"]
accessory = conn.execute(
"""
SELECT parent_id, category_type
FROM material_categories
WHERE category_id = 'cat_imagestudio_accessory_头部'
"""
).fetchone()
finally:
conn.close()
self.assertEqual(count, len(DEFAULT_MATERIAL_CATEGORIES))
self.assertEqual(accessory["parent_id"], "cat_imagestudio_配饰")
self.assertEqual(accessory["category_type"], "accessory_group")
def test_postgres_is_selected_when_configured(self):
settings = DatabaseSettings(

查看文件

@ -80,7 +80,7 @@ class WorkflowServiceTests(unittest.TestCase):
self.assertEqual(audit["action"], "create_workflow")
self.assertEqual(audit["target_type"], "profile_workflow")
def test_create_character_gradual_workflow_creates_eight_template_nodes(self):
def test_create_character_gradual_workflow_creates_ten_template_nodes(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,
{
@ -91,15 +91,136 @@ class WorkflowServiceTests(unittest.TestCase):
self.ctx,
)
self.assertEqual(len(detail.nodes), 8)
self.assertEqual(len(detail.nodes), 10)
self.assertEqual(detail.nodes[0].node_key, "profile_brief")
self.assertEqual(detail.nodes[1].node_key, "prompt_plan")
self.assertEqual(detail.nodes[2].node_key, "material_bind")
self.assertEqual(detail.nodes[-1].node_key, "final_pack")
self.assertEqual(detail.workflow.current_node_id, detail.nodes[0].node_id)
self.assertEqual(
[node.sort_order for node in self.workflow_service.list_nodes(detail.workflow.workflow_id)],
[10, 20, 30, 40, 50, 60, 70, 80],
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
)
def test_material_bind_node_update_syncs_workflow_material_binding_schema(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,
{
"workflow_type": "character_gradual",
"display_name": "Character gradual",
},
self.ctx,
)
material_bind = next(node for node in detail.nodes if node.node_key == "material_bind")
headshot = next(node for node in detail.nodes if node.node_key == "headshot")
full_body = next(node for node in detail.nodes if node.node_key == "full_body")
self.workflow_service.update_node(
material_bind.node_id,
{
"metadata": {
"material_bindings": {
"selected_material_ids": ["mat_style"],
"rules": [
{
"id": "rule_style",
"category": "风格",
"material_id": "mat_style",
"material_label": "Soft light",
"material_group": "style",
"material_prompt": "soft watercolor, clean line art",
"bind_to_stages": [
{"stage_id": "portrait-draft", "stage_title": "头像"},
{"stage_id": "body-sheet", "stage_title": "设定图"},
],
"inheritance_rule": "keep style consistent",
"reference_strength": "强",
"required": True,
"status": "ready",
},
{
"id": "rule_clothing",
"category": "服装",
"material_id": "",
"material_prompt": "",
"bind_to_stages": [{"stage_id": "halfbody-draft", "stage_title": "半身像"}],
"reference_strength": "中",
},
],
}
}
},
self.ctx,
)
workflow = self.workflow_service.get_workflow(detail.workflow.workflow_id).workflow
material_bindings = workflow.metadata["material_bindings"]
self.assertEqual(workflow.metadata["material_binding_schema_version"], "2026-07-09.material-binding-schema.v1")
self.assertEqual(material_bindings["summary"]["active_rule_count"], 1)
self.assertEqual(material_bindings["summary"]["disabled_categories"], ["服装"])
self.assertIn(headshot.node_id, material_bindings["by_node_id"])
self.assertIn(full_body.node_id, material_bindings["by_node_id"])
self.assertEqual(
material_bindings["by_node_id"][headshot.node_id]["generation_params"]["reference_material_ids"],
["mat_style"],
)
def test_prompt_plan_node_update_syncs_workflow_prompt_plan_schema(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,
{
"workflow_type": "character_gradual",
"display_name": "Character gradual",
},
self.ctx,
)
prompt_plan = next(node for node in detail.nodes if node.node_key == "prompt_plan")
headshot = next(node for node in detail.nodes if node.node_key == "headshot")
full_body = next(node for node in detail.nodes if node.node_key == "full_body")
self.workflow_service.update_node(
prompt_plan.node_id,
{
"metadata": {
"prompt_plan": {
"items": [
{
"id": "portrait",
"title": "头像节点",
"prompt": "Nova, face reference, clear eyes",
"negative": "low quality, blurry",
"weight": "face identity 1.25",
"weightBasis": "lock identity first",
"inherits": ["name", "hair", "eyes"],
"status": "ready",
},
{
"id": "fullbody",
"title": "全身节点",
"prompt": "Nova, full body standing pose",
"negative": "bad anatomy",
"conflicts": ["shoe details need review"],
"status": "review",
},
],
"guard_checks": [
{"label": "负面提示词", "value": "low quality, blurry", "status": "ready"}
],
}
}
},
self.ctx,
)
workflow = self.workflow_service.get_workflow(detail.workflow.workflow_id).workflow
plan = workflow.metadata["prompt_plan"]
self.assertEqual(workflow.metadata["prompt_plan_schema_version"], "2026-07-09.prompt-plan-schema.v1")
self.assertEqual(plan["summary"]["target_count"], 2)
self.assertEqual(plan["summary"]["review_count"], 1)
self.assertIn(headshot.node_id, plan["by_node_id"])
self.assertIn(full_body.node_id, plan["by_node_id"])
self.assertEqual(plan["by_node_id"][headshot.node_id]["generation_params"]["prompt_patch"], "Nova, face reference, clear eyes")
def test_create_fast_character_workflow_creates_fast_template_nodes(self):
detail = self.workflow_service.create_workflow(
self.profile.profile_id,

文件差异因一行或多行过长而隐藏

文件差异因一行或多行过长而隐藏

文件差异因一行或多行过长而隐藏

文件差异因一行或多行过长而隐藏

查看文件

@ -1,3 +1,3 @@
<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">
<script type="module" crossorigin src="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-uM7AKRxw.js"></script>
<link rel="stylesheet" crossorigin href="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-C91GfaJN.css">
<div id="app"></div>