feat(chat): 更新发货任务处理逻辑和界面文本
- 移除不必要的状态引用 - 更新上传处理提示文本,使用国际化支持 - 扩展发货任务摘要接口,增加错误信息和短缺信息 - 更新多语言支持的文本,改善用户体验 - 增加批次工作区的汇总信息和操作提示
This commit is contained in:
1 parent
0b083cfdbd
commit
1fc9976ca3
60 files changed
+3876
-639
No files matched your search
@@ -14,6 +14,36 @@ if TYPE_CHECKING:
|
||||
from app.models import ShippingTask
|
||||
|
||||
|
||||
def _sanitize_user_facing_text(value: str) -> str:
|
||||
"""
|
||||
清理会被 Agent 复述给业务用户的内部项目名。
|
||||
|
||||
核心逻辑:Tool response 会进入 Dify 上下文,先在后端把项目代号替换为业务表达,
|
||||
避免模型把内部系统名称带到对话气泡中。
|
||||
"""
|
||||
text = str(value or "")
|
||||
replacements = (
|
||||
("通过 Hxops 聊天区上传", "在当前对话中上传"),
|
||||
("通过 HXOPS 聊天区上传", "在当前对话中上传"),
|
||||
("通过 hxops 聊天区上传", "在当前对话中上传"),
|
||||
("在 Hxops 聊天区上传", "在当前对话中上传"),
|
||||
("在 HXOPS 聊天区上传", "在当前对话中上传"),
|
||||
("在 hxops 聊天区上传", "在当前对话中上传"),
|
||||
("Hxops 聊天区", "当前对话"),
|
||||
("HXOPS 聊天区", "当前对话"),
|
||||
("hxops 聊天区", "当前对话"),
|
||||
("Hxops Chat", "当前对话"),
|
||||
("HXOPS Chat", "当前对话"),
|
||||
("hxops chat", "当前对话"),
|
||||
("Hxops", "当前系统"),
|
||||
("HXOPS", "当前系统"),
|
||||
("hxops", "当前系统"),
|
||||
)
|
||||
for old, new in replacements:
|
||||
text = text.replace(old, new)
|
||||
return text
|
||||
|
||||
|
||||
def tool_response(
|
||||
*,
|
||||
status: str,
|
||||
@@ -27,6 +57,7 @@ def tool_response(
|
||||
next_required_action: str | None = None,
|
||||
forbidden_next_tools: list[str] | None = None,
|
||||
stop_agent_turn: bool = False,
|
||||
extra: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
构建发货通知 Tool 标准 JSON 响应。
|
||||
@@ -37,6 +68,7 @@ def tool_response(
|
||||
Args:
|
||||
stop_agent_turn: True 时要求 Agent 本回合停止,等待用户操作。
|
||||
forbidden_next_tools: 禁止 Agent 同轮调用的 Tool 名称列表。
|
||||
extra: 需要保留在顶层的兼容字段,例如 batch_no。
|
||||
"""
|
||||
from app.services.shipping_notice.state_machine import (
|
||||
action_buttons_for_checkpoint,
|
||||
@@ -61,7 +93,7 @@ def tool_response(
|
||||
|
||||
payload: dict[str, Any] = {
|
||||
"status": status,
|
||||
"message": message,
|
||||
"message": _sanitize_user_facing_text(message),
|
||||
"data": data or {},
|
||||
}
|
||||
if task_id:
|
||||
@@ -79,9 +111,11 @@ def tool_response(
|
||||
if resolved_checkpoint:
|
||||
payload["checkpoint"] = resolved_checkpoint
|
||||
if next_required_action:
|
||||
payload["next_required_action"] = next_required_action
|
||||
payload["next_required_action"] = _sanitize_user_facing_text(next_required_action)
|
||||
if forbidden_next_tools:
|
||||
payload["forbidden_next_tools"] = forbidden_next_tools
|
||||
if stop_agent_turn:
|
||||
payload["stop_agent_turn"] = True
|
||||
if extra:
|
||||
payload.update(extra)
|
||||
return payload
|
||||
Reference in new issue
Block a user