优化全能创作

This commit is contained in:
Azmat@qq.com
2026-09-14 15:58:20 +08:00
parent 463613c0d7
commit 3fed9b9435
9 changed files with 1538 additions and 139 deletions
+48 -5
View File
@@ -35,11 +35,15 @@ from .creation import (
)
from .creation_agent import (
_ASSET_CARD_LABELS,
_RESTART_CONTINUATION,
apply_confirm_params,
apply_restart_intent,
apply_session_params,
emit_final_confirm_gate,
emit_prompt_gate,
is_greeting,
is_restart_intent,
restore_gated_step_after_cancel,
set_video_gate_stage,
submit_confirmed_image,
submit_confirmed_video,
@@ -134,6 +138,23 @@ _WANTS_CARD_RE = re.compile(
re.IGNORECASE,
)
# 步骤确认卡下,用户往往不会去点「按这个继续」,而是自然地回一句
# 「这个还行」「就这样」「没问题」。这些是确认,不应被误判成修改意见。
_STEP_TEXT_CONFIRM_RE = re.compile(
r"^(?:"
r"好(?:的)?|行|可以(?:了)?|没问题|确认|继续(?:下一步)?|"
r"就这样(?:吧)?|按这个(?:继续|来|做)?|就按这个(?:继续|来|做)?|"
r"(?:这(?:个|样|版|种)?|方案|策略|prompt)(?:还行|可以|挺好|不错|没问题)(?:吧)?"
r")(?:继续(?:下一步)?)?$",
re.IGNORECASE,
)
def _typed_step_confirm_action(text: str) -> str:
"""把对着步骤卡输入的自然语言收成「继续」或「修改」。"""
compact = re.sub(r"[\s,,。.!!??、~~…]+", "", str(text or "").lower())
return "confirm" if _STEP_TEXT_CONFIRM_RE.fullmatch(compact) else "revise"
def _pending_chat_question(conversation: CreationConversation) -> CreationMessage | None:
"""找最近一条未回答的新式追问;卡片既可点选,也兼容直接输入。"""
@@ -1625,7 +1646,9 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
def cancel(self, request, pk=None):
"""终止进行中的整理方案(agent planning)。
仅 `agent_status===planning` 可取消 → **200** `{conversation_id, agent_status: idle}`。
仅 `agent_status===planning` 可取消 → **200** `{conversation_id, agent_status}`。
若取消发生在策略/方案/Prompt 闸门的修订或推进中,恢复该步 `step_confirm`
(清除 submitted),`agent_status` 回到 `awaiting_user`;否则为 `idle`。
非 planning → **409**。打 Redis 取消标供 Celery 在工具轮间隙停跑,立刻释放
`omni:agent:{team_id}` 锁;已落库消息保留。不影响 confirm 出片/出图。
"""
@@ -1640,10 +1663,21 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
{"detail": "当前没有正在整理的方案可终止"},
status=409,
)
restored = restore_gated_step_after_cancel(conversation)
if restored:
now = timezone.now()
CreationConversation.objects.filter(pk=conversation.pk).update(
agent_status=CreationConversation.AgentStatus.AWAITING_USER,
agent_started_at=None,
last_active_at=now,
updated_at=now,
)
conversation.agent_status = CreationConversation.AgentStatus.AWAITING_USER
conversation.agent_started_at = None
return JsonResponse(
{
"conversation_id": str(conversation.id),
"agent_status": CreationConversation.AgentStatus.IDLE,
"agent_status": conversation.agent_status,
},
status=200,
)
@@ -1671,17 +1705,26 @@ class CreationConversationViewSet(TeamScopedViewSetMixin, ModelViewSet):
if not isinstance(refs, list):
return JsonResponse({"detail": "refs 必须是数组"}, status=400)
# 「重新来」优先于未完成追问卡:不能当成模特/商品答案继续旧闸门。
if kind == "text" and text and is_restart_intent(text):
apply_restart_intent(conversation)
force_creative_turn = True
continuation_instruction = _RESTART_CONTINUATION
# 打招呼不应被误当成上一条素材追问的答案;让 agent 立刻简短回应即可。
if kind == "text" and text and not is_greeting(text):
elif kind == "text" and text and not is_greeting(text):
pending = _pending_chat_question(conversation)
if pending is not None:
payload = dict(pending.payload or {})
if payload.get("interaction") == "step_confirm":
# 用户对着步骤确认卡直接打字 = 修改意见
# 用户对着步骤确认卡直接打字:自然肯定句视为继续,其它才作为修改意见。
typed_action = _typed_step_confirm_action(text)
short, force_creative_turn, continuation_instruction = _handle_step_confirm_answer(
conversation,
card=pending,
answers={"step_action": "revise", "feedback": text},
answers={
"step_action": typed_action,
**({"feedback": text} if typed_action == "revise" else {}),
},
user=request.user,
)
if short is not None: