checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)
- 新增 inq_synonym 表、62组同义词种子与智能体只读接口 - Python 同义词加载/归一化与 1板/2箱 机读 - 同步当前分支既有协作、报价识别、陆运等改动
This commit is contained in:
@@ -208,29 +208,35 @@ def ensure_group_bot_line(chat_id: str, fallback: str = "AIR") -> str:
|
||||
return line
|
||||
|
||||
|
||||
def _text_fingerprint(text: str) -> str:
|
||||
def _text_fingerprint(text: str, sender_id: str = "") -> str:
|
||||
"""
|
||||
群文字指纹:去空白后取 sha1 前 20 位。
|
||||
群文字指纹:发送人 + 去空白正文,取 sha1 前 20 位。
|
||||
|
||||
为什么要去空白:同一句在 AIBOT 回调与会话存档里,换行/空格可能被平台改写,
|
||||
原样比较会漏判,导致同一句被办两遍。
|
||||
为什么要带发送人:同群两个不同的人发同一句话不是同一条消息。
|
||||
2026-11-23 真机:林绵勋发报价被拒「只有航线能报」后,吴季林发同一句,
|
||||
旧指纹只看正文,把吴季林那条当成重复静默吞掉,群里表现为「没响应」。
|
||||
"""
|
||||
compact = "".join(str(text or "").split())
|
||||
return hashlib.sha1(compact.encode("utf-8")).hexdigest()[:20]
|
||||
sender = str(sender_id or "").strip()
|
||||
blob = f"{sender}|{compact}" if sender else compact
|
||||
return hashlib.sha1(blob.encode("utf-8")).hexdigest()[:20]
|
||||
|
||||
|
||||
def mark_bot_text_handled(chat_id: str, text: str) -> None:
|
||||
def mark_bot_text_handled(chat_id: str, text: str, sender_id: str = "") -> None:
|
||||
"""
|
||||
记下「这条群文字已由 AIBOT 回调办过」。
|
||||
|
||||
用途:会话存档会旁听到同一句 @BOT(尤其空运),若再走一遍 handler
|
||||
就会把同一份工单摘要/模板发两遍(2026-11-19 测服真机复现)。
|
||||
sender_id 参与指纹:不同人发同一句不能被当成重复。
|
||||
TTL 5 分钟只覆盖存档延迟窗口,过期即失效,不当业务状态用。
|
||||
"""
|
||||
_write_handled(chat_id, text, retry_archive=False)
|
||||
_write_handled(chat_id, text, retry_archive=False, sender_id=sender_id)
|
||||
|
||||
|
||||
def allow_archive_retry(chat_id: str, text: str) -> None:
|
||||
def allow_archive_retry(chat_id: str, text: str, sender_id: str = "") -> None:
|
||||
"""
|
||||
撤销「这句已办过」的去重,允许会话存档那条(明文身份)再办一遍。
|
||||
|
||||
@@ -240,17 +246,19 @@ def allow_archive_retry(chat_id: str, text: str) -> None:
|
||||
结果是销售明明本人点成交,群里却一直回「只有负责该工单的销售可以确认成交状态」。
|
||||
身份换不成明文时,AIBOT 那条的结论不可信,必须让存档补办。
|
||||
"""
|
||||
_write_handled(chat_id, text, retry_archive=True)
|
||||
_write_handled(chat_id, text, retry_archive=True, sender_id=sender_id)
|
||||
|
||||
|
||||
def _write_handled(chat_id: str, text: str, *, retry_archive: bool) -> None:
|
||||
def _write_handled(
|
||||
chat_id: str, text: str, *, retry_archive: bool, sender_id: str = ""
|
||||
) -> None:
|
||||
"""
|
||||
写「已办」标记。retry_archive=True 时打上 `#retry` 后缀,读侧据此不再去重。
|
||||
|
||||
存储值形如 `abcdef0123456789ab`(去重生效)或 `abcdef0123456789ab#retry`(放行存档)。
|
||||
"""
|
||||
room = (chat_id or "").strip()
|
||||
fingerprint = _text_fingerprint(text)
|
||||
fingerprint = _text_fingerprint(text, sender_id)
|
||||
if not room or not fingerprint:
|
||||
return
|
||||
value = fingerprint + _RETRY_SUFFIX if retry_archive else fingerprint
|
||||
@@ -265,15 +273,15 @@ def _write_handled(chat_id: str, text: str, *, retry_archive: bool) -> None:
|
||||
logger.warning("group_bot 记 AIBOT 已办文字失败 chat=%s", room, exc_info=True)
|
||||
|
||||
|
||||
def bot_text_handled(chat_id: str, text: str) -> bool:
|
||||
def bot_text_handled(chat_id: str, text: str, sender_id: str = "") -> bool:
|
||||
"""
|
||||
这条群文字是否已经被 AIBOT 回调办过(同群 5 分钟内同文)。
|
||||
这条群文字是否已经被 AIBOT 回调办过(同群同人 5 分钟内同文)。
|
||||
|
||||
带 `#retry` 后缀表示「AIBOT 那条身份不可信,允许存档补办」,这里返回 False。
|
||||
Redis 不可用时退回进程内记录;两者都没有就返回 False,让存档按老逻辑补听。
|
||||
"""
|
||||
room = (chat_id or "").strip()
|
||||
fingerprint = _text_fingerprint(text)
|
||||
fingerprint = _text_fingerprint(text, sender_id)
|
||||
if not room or not fingerprint:
|
||||
return False
|
||||
with _guard:
|
||||
|
||||
@@ -55,6 +55,8 @@ WSHOTO_ROOM_TICKET = "wshoto:room_ticket"
|
||||
QUOTE_FILE_READY = "quote_file_ready"
|
||||
# 产品刚报价、等选「在TMS上改 / 不用TMS」:短协调,不当六态
|
||||
PENDING_PRODUCT_QUOTE = "pending_product_quote"
|
||||
# 产品报价/销售调价先回识别回执,等成员@机器人回「确认/确定」后再出价格方案/改价
|
||||
PENDING_QUOTE_CONFIRM = "pending_quote_confirm"
|
||||
# 陆运核对卡已出、等确定查价:短协调,不当六态、不当工单号
|
||||
PENDING_LAND_CONFIRM = "pending_land_confirm"
|
||||
# 空运群问过「是否需要取消舱位」:短协调,不当六态
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
"""
|
||||
待确认的报价/调价:机器人先回识别回执,等成员@机器人回「确认/确定」后再出价格方案/改价。
|
||||
|
||||
短协调,不当六态、不当 checkpoint。Redis 正式;进程内兜底给单测和 Redis 不可用。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from agent.redis_coord.keys import PENDING_QUOTE_CONFIRM
|
||||
from agent.redis_coord.runtime import get_redis_runtime
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 两天:跨夜也能确认;过期就当没有待确认。
|
||||
_TTL_SEC = 2 * 24 * 3600
|
||||
_local: dict[str, dict[str, Any]] = {}
|
||||
|
||||
|
||||
def _no(work_order_no: str) -> str:
|
||||
return (work_order_no or "").strip()
|
||||
|
||||
|
||||
def save_pending_confirm(work_order_no: str, payload: dict[str, Any]) -> None:
|
||||
"""记下刚抽出的报价/调价,等成员确认。"""
|
||||
no = _no(work_order_no)
|
||||
if not no or not isinstance(payload, dict) or not payload:
|
||||
return
|
||||
data = dict(payload)
|
||||
data["_ts"] = time.time()
|
||||
_local[no] = data
|
||||
try:
|
||||
client = get_redis_runtime().client
|
||||
client.raw.set(
|
||||
client.key(PENDING_QUOTE_CONFIRM, no),
|
||||
json.dumps(data, ensure_ascii=False),
|
||||
ex=_TTL_SEC,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("写待确认报价失败 wo=%s", no)
|
||||
|
||||
|
||||
def load_pending_confirm(work_order_no: str) -> dict[str, Any]:
|
||||
"""取出待确认报价/调价。没有或过期返回空。"""
|
||||
no = _no(work_order_no)
|
||||
if not no:
|
||||
return {}
|
||||
local = _local.get(no)
|
||||
if local:
|
||||
return dict(local)
|
||||
try:
|
||||
client = get_redis_runtime().client
|
||||
raw = client.raw.get(client.key(PENDING_QUOTE_CONFIRM, no))
|
||||
if not raw:
|
||||
return {}
|
||||
if isinstance(raw, bytes):
|
||||
raw = raw.decode("utf-8")
|
||||
data = json.loads(raw)
|
||||
return dict(data) if isinstance(data, dict) else {}
|
||||
except Exception:
|
||||
logger.exception("读待确认报价失败 wo=%s", no)
|
||||
return {}
|
||||
|
||||
|
||||
def clear_pending_confirm(work_order_no: str) -> None:
|
||||
"""确认/覆盖/作废后清掉,避免下一句误用旧价。"""
|
||||
no = _no(work_order_no)
|
||||
if not no:
|
||||
return
|
||||
_local.pop(no, None)
|
||||
try:
|
||||
client = get_redis_runtime().client
|
||||
client.raw.delete(client.key(PENDING_QUOTE_CONFIRM, no))
|
||||
except Exception:
|
||||
logger.exception("清待确认报价失败 wo=%s", no)
|
||||
Reference in New Issue
Block a user