feat(workflow): enhance message stages and image routing
This commit is contained in:
@@ -6,6 +6,12 @@ from collections import defaultdict, deque
|
||||
from copy import deepcopy
|
||||
from typing import Any
|
||||
|
||||
from services.message_policy import (
|
||||
MESSAGE_COMPLETION_POLICIES,
|
||||
MESSAGE_CONFIRMATION,
|
||||
MESSAGE_PLAYBACK,
|
||||
)
|
||||
|
||||
|
||||
SPEC_VERSION = "3"
|
||||
NODE_TYPES = {"start", "agent", "message", "action", "handoff", "end"}
|
||||
@@ -191,11 +197,17 @@ def _normalize_action_data(data: dict[str, Any]) -> None:
|
||||
def _normalize_message_data(data: dict[str, Any]) -> None:
|
||||
"""Fill the small built-in Message contract used by runtime and editor."""
|
||||
data.setdefault("speech", "")
|
||||
data.setdefault("showMessage", False)
|
||||
data.setdefault("title", "重要提示")
|
||||
data.setdefault("message", "")
|
||||
data.setdefault("confirmLabel", "确认")
|
||||
data.setdefault("requireConfirmation", False)
|
||||
if "completionPolicy" not in data:
|
||||
data["completionPolicy"] = (
|
||||
MESSAGE_CONFIRMATION
|
||||
if data.get("requireConfirmation") is True
|
||||
else MESSAGE_PLAYBACK
|
||||
)
|
||||
data.pop("requireConfirmation", None)
|
||||
data.pop("showMessage", None)
|
||||
|
||||
|
||||
def _normalize_settings(settings: dict[str, Any], *, global_prompt: str = "") -> None:
|
||||
@@ -379,19 +391,19 @@ def validate_graph(graph: dict[str, Any]) -> list[str]:
|
||||
elif node_type == "message":
|
||||
data = node.get("data") or {}
|
||||
speech = data.get("speech")
|
||||
show_message = data.get("showMessage")
|
||||
require_confirmation = data.get("requireConfirmation")
|
||||
completion_policy = data.get("completionPolicy")
|
||||
if not isinstance(speech, str):
|
||||
errors.append(f"Message 节点 {node_id} 的播报内容必须是文本")
|
||||
if not isinstance(show_message, bool):
|
||||
errors.append(f"Message 节点 {node_id} 的弹窗开关必须是布尔值")
|
||||
if not isinstance(require_confirmation, bool):
|
||||
errors.append(f"Message 节点 {node_id} 的确认开关必须是布尔值")
|
||||
if require_confirmation and show_message is not True:
|
||||
errors.append(f"Message 节点 {node_id} 等待确认时必须显示弹窗")
|
||||
if not str(speech or "").strip() and show_message is not True:
|
||||
errors.append(f"Message 节点 {node_id} 至少需要播报或显示弹窗")
|
||||
if show_message is True:
|
||||
if (
|
||||
not isinstance(completion_policy, str)
|
||||
or completion_policy not in MESSAGE_COMPLETION_POLICIES
|
||||
):
|
||||
errors.append(
|
||||
f"Message 节点 {node_id} 的完成策略无效:{completion_policy}"
|
||||
)
|
||||
if not str(speech or "").strip():
|
||||
errors.append(f"Message 节点 {node_id} 必须配置播报内容")
|
||||
if completion_policy == MESSAGE_CONFIRMATION:
|
||||
title = data.get("title")
|
||||
message = data.get("message")
|
||||
confirm_label = data.get("confirmLabel")
|
||||
|
||||
Reference in New Issue
Block a user