feat(chat): 更新发货任务处理逻辑和界面文本

- 移除不必要的状态引用
- 更新上传处理提示文本,使用国际化支持
- 扩展发货任务摘要接口,增加错误信息和短缺信息
- 更新多语言支持的文本,改善用户体验
- 增加批次工作区的汇总信息和操作提示
This commit is contained in:
hugo committed 2026-06-29 14:43:27 +08:00
1 parent 0b083cfdbd
commit 1fc9976ca3
60 files changed
+3876 -639

No files matched your search

+47 -4
View File
@@ -38,6 +38,7 @@ from app.core.errors import (
chat_bp = Blueprint('chat', __name__)
LEAVE_FEATURE_AGENT_NAMES = {'通用入口', '人事规章'}
SHIPPING_NOTICE_AGENT_NAME = '货代发货通知 Agent'
def _can_use_leave_feature(agent_proxy) -> bool:
@@ -52,6 +53,28 @@ def _session_title_from_text(text: str) -> str:
return value[:30] + ('...' if len(value) > 30 else '')
def _user_facing_chat_query(text: str, agent_name: str | None = None) -> str:
"""
将内部 Agent 编排提示转换成业务用户可见话术。
Args:
text: chat_logs.query 中保存的用户侧文本。
agent_name: 当前 Agent 名称,仅对发货通知 Agent 做工具名净化。
Returns:
可直接展示在聊天历史里的用户问题。
"""
value = str(text or '').strip()
if not value or str(agent_name or '').strip() != SHIPPING_NOTICE_AGENT_NAME:
return value
import re
task_match = re.search(r'(SN-\d{8}-[A-Z0-9]+)', value, re.I)
task_no = task_match.group(1).upper() if task_match else ''
if 'create_task' in value or 'get_task_status' in value or 'parse_notice' in value:
return f'继续处理当前发货任务 {task_no}'.strip()
return value
def _serialize_session(session: ChatSession) -> dict:
last_active = session.last_active_at or session.created_at
return {
@@ -909,9 +932,23 @@ def get_chat_messages():
).order_by(ChatLog.created_at.asc()).all()
messages = []
agent_name = str(getattr(g.current_agent, 'name', '') or '').strip()
for log in logs:
if log.query:
messages.append({'role': 'user', 'content': log.query})
messages.append({'role': 'user', 'content': _user_facing_chat_query(log.query, agent_name)})
if (
not log.answer
and not log.message_type
and not log.payload
):
continue
if (
log.query
and log.answer == log.query
and (not log.message_type or log.message_type == 'text')
and not log.payload
):
continue
assistant_msg = {
'role': 'assistant',
'content': log.answer,
@@ -940,10 +977,14 @@ def save_local_message():
raise AppError(code='SYSTEM.INTERNAL_ERROR', message='Missing context', http_status=500)
data = request.get_json() or {}
conversation_id = (data.get('conversation_id') or '').strip()
role = (data.get('role') or 'assistant').strip()
message_type = data.get('type')
content = data.get('content', '')
payload = data.get('payload')
user_query = data.get('query', '')
if role == 'user':
user_query = user_query or content
content = ''
if not message_type:
raise ValidationError('type is required')
@@ -1074,6 +1115,7 @@ def chat_completions():
"""
data = request.get_json() or {}
query = data.get('query')
display_query = str(data.get('display_query') or query or '').strip()
# 前端传入的 conversation_id 在 B2 里代表本地 session_id
conversation_id = data.get('conversation_id')
shipping_task_id = str(data.get('task_id') or '').strip()
@@ -1117,7 +1159,7 @@ def chat_completions():
user_id,
agent_id,
existing_session.session_id,
title=query,
title=display_query,
status='running',
)
external_conversation_id = session.external_conversation_id
@@ -1126,13 +1168,13 @@ def chat_completions():
user_id,
agent_id,
conversation_id,
title=query,
title=display_query,
status='running',
external_conversation_id=conversation_id,
)
external_conversation_id = session.external_conversation_id
else:
session = _ensure_chat_session(user_id, agent_id, None, title=query, status='running')
session = _ensure_chat_session(user_id, agent_id, None, title=display_query, status='running')
normalized_files: list[dict] | None = None
if files is not None:
@@ -1246,6 +1288,7 @@ def chat_completions():
hxops_turn_id=hxops_turn_id if is_file_check_agent else None,
files=normalized_files,
inputs=dify_inputs,
display_query=display_query,
)
def relay_stream():
+18 -1
View File
@@ -23,6 +23,7 @@ from app.services.shipping_notice.constants import (
from app.services.shipping_notice.query_service import (
EXPORT_MIME_TYPE,
get_batch_for_user,
get_conversation_batch_workspace,
get_focus_task_for_batch,
get_task_for_user,
list_batches_for_user,
@@ -67,6 +68,12 @@ def workspace_shipping_batches():
limit = int(request.args.get('limit') or 100)
return jsonify(list_batches_for_user(user.id, limit=limit))
@workspace_shipping_notice_bp.route('/shipping-conversations/<conversation_id>/batch-workspace', methods=['GET'])
def workspace_shipping_conversation_batch_workspace(conversation_id: str):
"""返回一个 Agent 会话下的多批次执行工作台快照。"""
user = _require_user()
return jsonify(get_conversation_batch_workspace(conversation_id, user.id))
@workspace_shipping_notice_bp.route('/shipping-batches/create-from-notices', methods=['POST'])
def workspace_create_shipping_batch_from_notices():
"""接收多份发货通知附件,创建批次并交给后台编排器逐票推进。"""
@@ -448,6 +455,16 @@ def workspace_mark_manual_uploaded(task_no: str):
from app.services.shipping_notice import tools as shipping_tools
return jsonify(shipping_tools.upload_to_freight({'task_id': task.task_no, 'mode': 'manual_confirm'}))
@workspace_shipping_notice_bp.route('/shipping-tasks/<task_no>/retry-upload', methods=['POST'])
def workspace_retry_shipping_upload(task_no: str):
"""用户态重试上传货代系统,直接触发既有 RPA 上传链路。"""
user = _require_user()
task = get_task_for_user(task_no, user.id)
if not task:
raise NotFoundError('Not found')
from app.services.shipping_notice import tools as shipping_tools
return jsonify(shipping_tools.upload_to_freight({'task_id': task.task_no, 'mode': 'retry_upload'}))
@workspace_shipping_notice_bp.route('/shipping-tasks/<task_no>/generate-excel', methods=['POST'])
def workspace_generate_shipping_excel(task_no: str):
"""为指定任务生成出货 Excel,并补充工作台下载链接。"""
@@ -486,4 +503,4 @@ def workspace_retry_shipping_batch_pending(batch_no: str):
if not batch:
raise NotFoundError('Not found')
from app.services.shipping_notice.batch_orchestrator import retry_batch_pending_tasks
return jsonify(retry_batch_pending_tasks(batch.batch_no))
return jsonify(retry_batch_pending_tasks(batch.batch_no))