newtw2
This commit is contained in:
@@ -68,11 +68,15 @@ class SystemOrchestrator:
|
||||
# 店铺隔离:同一客户在不同店铺的对话独立处理
|
||||
session_key = f"{user_id}@{std_msg.acc_id}"
|
||||
|
||||
# 订单消息处理:静默入库并更新状态,但不触发 AI 回复
|
||||
if "[系统订单信息]" in (std_msg.content or ""):
|
||||
# 订单消息 / 纯金额通知:静默入库,不触发 AI 回复
|
||||
msg_text = std_msg.content or ""
|
||||
is_order = "[系统订单信息]" in msg_text
|
||||
is_price_only = bool(re.match(r'^[\s\n]*金?额?[::]?\s*[\d.]+\s*元', msg_text.strip()))
|
||||
is_sku_only = bool(re.match(r'^[\s\n]*(备注[::]|数量[::]|款式[::])', msg_text.strip()))
|
||||
if is_order or is_price_only or is_sku_only:
|
||||
await self._handle_order_packet(platform, std_msg)
|
||||
logger.info(f"[订单消息] user={user_id} acc={std_msg.acc_id} 已入库更新状态")
|
||||
await repo.save_chat(platform, user_id, std_msg.content, "in", acc_id=std_msg.acc_id)
|
||||
await repo.save_chat(platform, user_id, msg_text, "in", acc_id=std_msg.acc_id)
|
||||
return
|
||||
|
||||
preview = (std_msg.content or "").replace("\n", "\\n")
|
||||
@@ -84,7 +88,7 @@ class SystemOrchestrator:
|
||||
)
|
||||
|
||||
# 过滤心跳
|
||||
if not std_msg.content.strip() and not std_msg.image_urls: return
|
||||
if not (std_msg.content or "").strip() and not std_msg.image_urls: return
|
||||
|
||||
# 如果是商家人工回复,静默入库
|
||||
if direction == "out":
|
||||
@@ -180,8 +184,15 @@ class SystemOrchestrator:
|
||||
messages = self._pending_messages.pop(session_key, [])
|
||||
if not messages: return
|
||||
|
||||
# A. 合并与元数据修复
|
||||
combined_content = "\n".join([m.content for m in messages if m.content.strip()])
|
||||
# A. 合并与元数据修复(去重:同一防抖窗口内完全相同的内容只保留一条)
|
||||
seen_contents = set()
|
||||
unique_parts = []
|
||||
for m in messages:
|
||||
c = (m.content or "").strip()
|
||||
if c and c not in seen_contents:
|
||||
seen_contents.add(c)
|
||||
unique_parts.append(c)
|
||||
combined_content = "\n".join(unique_parts)
|
||||
all_image_urls = []
|
||||
acc_id = messages[-1].acc_id
|
||||
acc_type = messages[-1].acc_type
|
||||
@@ -216,12 +227,15 @@ class SystemOrchestrator:
|
||||
|
||||
# D. 思考
|
||||
history = await repo.get_chat_history(user_id, limit=10, acc_id=acc_id)
|
||||
if history and history[-1]['content'] == db_content: history = history[:-1]
|
||||
if history and history[-1].get('content') == db_content: history = history[:-1]
|
||||
|
||||
# 只在“明确又要转接”时注入冷却提示,普通问候/新需求不注入
|
||||
transfer_intent = self._has_transfer_intent(combined_content)
|
||||
if is_in_cooldown and transfer_intent:
|
||||
final_msg.content = f"【系统:当前已向设计师发出转接请求,请勿再次调用转接工具】\n{final_msg.content}"
|
||||
# 冷却期内:禁止再发转接指令,避免反复转接
|
||||
if is_in_cooldown:
|
||||
final_msg.content = (
|
||||
"【系统:设计师已收到转接通知正在赶来,严禁再次调用转人工工具!"
|
||||
"客户再问就回'设计师正在看了哈,稍等一下',换着说不要重复】\n"
|
||||
+ final_msg.content
|
||||
)
|
||||
|
||||
std_res = await self.brain.think_and_reply(final_msg, history=history)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user