checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)
- 新增 inq_synonym 表、62组同义词种子与智能体只读接口 - Python 同义词加载/归一化与 1板/2箱 机读 - 同步当前分支既有协作、报价识别、陆运等改动
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
多段联运私聊:补问、核对、建单、拉群。
|
||||
|
||||
本文件职责:一段一段收齐必填后才建一张工单;不去 TMS 查价。
|
||||
陆运段缺业务类型/报价场景时发选项卡(与单聊同一张卡),卡发不出去仍回落复制清单。
|
||||
不含空运时,销售点「拉产品进群」后按各段线路把人拉进同一个群,并发群摘要。
|
||||
含空运时只提示手动拉人到原有群。报价和成交跟进不在本文件。
|
||||
调用:文字询价 Handler 在 Worker 线程;禁止回调线程同步跑。
|
||||
@@ -29,8 +30,10 @@ from agent.policy.multi_segments import (
|
||||
confirm_text,
|
||||
group_brief,
|
||||
includes_air,
|
||||
land_option_card_segment,
|
||||
merge_supplement,
|
||||
refresh_segments,
|
||||
segment_gap_body,
|
||||
segments_from_payload,
|
||||
segments_to_payload,
|
||||
split_segments,
|
||||
@@ -117,11 +120,19 @@ class MultiTextInquiryFlow:
|
||||
card_meta: Optional[dict[str, Any]] = None,
|
||||
) -> str:
|
||||
"""
|
||||
处理多段拉群卡。错工单/未允许直接丢弃,不改主账。
|
||||
处理多段卡片。错工单/未允许直接丢弃,不改主账。
|
||||
|
||||
新增陆运补问卡(multi_land_options):把点选的业务类型/报价场景写回陆运段,
|
||||
再交给 _open 重新核缺口;卡过期只回过期话术,不写半截值。
|
||||
副作用:点「拉产品进群协同」时建一个群并发摘要、各段模板。
|
||||
调用:卡片 Handler,HTTP 回调线程只入队后由 Worker/本流程执行;本函数会打企微建群。
|
||||
"""
|
||||
if action == copy.BTN_LAND_OPTIONS:
|
||||
return self._submit_land_options_card(
|
||||
sender_id=sender_id,
|
||||
reply=reply,
|
||||
card_meta=card_meta,
|
||||
)
|
||||
sess = self.session_for_action(sender_id, card_meta)
|
||||
card_wo = copy.work_order_from_card_meta(card_meta)
|
||||
if not sess or action not in (sess.allowed or ()):
|
||||
@@ -357,22 +368,155 @@ class MultiTextInquiryFlow:
|
||||
)
|
||||
if refused:
|
||||
return refused
|
||||
ready, updated, gaps = refresh_segments(filled)
|
||||
# 陆运缺业务类型/报价场景时改发选项卡;正文只留点卡提示。
|
||||
options_on_card = land_option_card_segment(filled) is not None
|
||||
ready, updated, gaps = refresh_segments(filled, options_on_card=options_on_card)
|
||||
if not ready:
|
||||
self._reply_gaps(updated, gaps, reply)
|
||||
# 先落书签再出卡:销售点得很快时,回调要靠这份 facts 找回当前草稿。
|
||||
self._save(self._draft(sender_id, updated, phase="clarify", immutable=immutable))
|
||||
self._reply_gaps(updated, gaps, reply, sender_id=sender_id)
|
||||
return "clarify"
|
||||
reply(confirm_text(updated))
|
||||
self._save(self._draft(sender_id, updated, phase="wait_confirm", immutable=immutable))
|
||||
return "wait_confirm"
|
||||
|
||||
def _reply_gaps(self, segments: list[Segment], gaps: str, reply: ReplyFn) -> None:
|
||||
def _reply_gaps(
|
||||
self,
|
||||
segments: list[Segment],
|
||||
gaps: str,
|
||||
reply: ReplyFn,
|
||||
*,
|
||||
sender_id: str,
|
||||
) -> None:
|
||||
"""
|
||||
补问正文。陆运选项走复制清单,不再另发填写样例图。
|
||||
补问正文。陆运缺业务类型/报价场景时另发一张选项卡。
|
||||
|
||||
副作用:出站文字。只在 Worker 里调。
|
||||
一个出站只能带一张卡:除陆运段外还有别的段要补时,先发文字摘要,
|
||||
再单独发卡;只有陆运段缺选项时直接发卡,正文留给卡发不出去时兜底。
|
||||
卡发不出去(出站回落成 content)时是完整的复制清单,销售仍可按编号回文字。
|
||||
|
||||
副作用:出站文字/卡片。只在 Worker 里调。
|
||||
"""
|
||||
reply(gaps)
|
||||
target = land_option_card_segment(segments)
|
||||
if target is None:
|
||||
reply(gaps)
|
||||
return
|
||||
from agent.schema import land_option_card as loc
|
||||
from agent.schema.land_options import option_prompt
|
||||
|
||||
card = loc.land_option_card_payload(
|
||||
task_token=sender_id,
|
||||
facts=target.facts,
|
||||
note=f"段{target.index}:{target.word()}",
|
||||
card_kind=loc.MULTI_CARD_KIND,
|
||||
)
|
||||
if card is None:
|
||||
reply(gaps)
|
||||
return
|
||||
# 只有陆运段一个缺口时不再单独发摘要:卡片本身就是这条补问。
|
||||
others = [
|
||||
seg
|
||||
for seg in segments
|
||||
if seg.index != target.index
|
||||
and segment_gap_body(seg, options_on_card=True).strip()
|
||||
]
|
||||
if others:
|
||||
reply(gaps)
|
||||
# 卡发不出去时,这条 content 就是销售的兜底正文,要和摘要同一口径自成一个补问。
|
||||
fallback = (
|
||||
"请确认并补充以下信息:\n\n"
|
||||
f"段{target.index}:{target.word()}\n"
|
||||
f"{option_prompt(current=target.facts)}"
|
||||
)
|
||||
reply(fallback.strip(), card)
|
||||
|
||||
def _submit_land_options_card(
|
||||
self,
|
||||
*,
|
||||
sender_id: str,
|
||||
reply: ReplyFn,
|
||||
card_meta: Optional[dict[str, Any]] = None,
|
||||
) -> str:
|
||||
"""
|
||||
多段补问里的陆运选项卡提交:把点选项写回陆运段,再往前推一步。
|
||||
|
||||
只认还在 clarify 的多段草稿。已出号、已核对、卡过期都只回过期话术,
|
||||
不写半截值、不新建空单。只选了一项也算数:_open 会把还缺的那项重新问出来。
|
||||
"""
|
||||
from agent.schema import land_option_card as loc
|
||||
from agent.schema.land_options import apply_option_pick
|
||||
|
||||
payload = dict(card_meta or {})
|
||||
sess = self.session_for_action(sender_id, payload)
|
||||
phase = (sess.phase if sess is not None else "") or ""
|
||||
if (
|
||||
sess is None
|
||||
or (sess.business_line or "").upper() != "MULTI"
|
||||
or phase != "clarify"
|
||||
):
|
||||
logger.info(
|
||||
"multi.land_options.expired sender=%s phase=%s",
|
||||
sender_id,
|
||||
phase or "-",
|
||||
)
|
||||
reply(copy.land_options_session_expired())
|
||||
return "land_options_expired"
|
||||
|
||||
segments = self._segments(sess)
|
||||
target = land_option_card_segment(segments)
|
||||
if target is None:
|
||||
logger.info("multi.land_options.no_gap sender=%s", sender_id)
|
||||
reply(copy.land_options_session_expired())
|
||||
return "land_options_expired"
|
||||
|
||||
selected = payload.get("selected_items") or {}
|
||||
pick = loc.resolve_option_pick(selected if isinstance(selected, dict) else {})
|
||||
if not (pick.biz_label or pick.transport_type or pick.route or pick.land_class):
|
||||
logger.info(
|
||||
"multi.land_options.empty sender=%s selected=%s", sender_id, selected
|
||||
)
|
||||
reply(copy.land_options_incomplete())
|
||||
return self._open(
|
||||
sender_id, segments, reply, immutable=sess.immutable_text or ""
|
||||
)
|
||||
if pick.error == "mismatch":
|
||||
# 仅旧三项卡兼容:不写搭不上的组合,清掉线路让销售重选业务类型。
|
||||
logger.info(
|
||||
"multi.land_options.mismatch sender=%s type=%s route=%s",
|
||||
sender_id,
|
||||
pick.transport_type,
|
||||
pick.route,
|
||||
)
|
||||
target.facts = {
|
||||
k: v for k, v in target.facts.items() if k != "线路类别"
|
||||
}
|
||||
reply(
|
||||
copy.land_option_pair_mismatch(
|
||||
transport_type=pick.transport_type, route=pick.route
|
||||
)
|
||||
)
|
||||
return self._open(
|
||||
sender_id, segments, reply, immutable=sess.immutable_text or ""
|
||||
)
|
||||
|
||||
target.facts = apply_option_pick(
|
||||
target.facts,
|
||||
biz_label=pick.biz_label,
|
||||
transport_type=pick.transport_type,
|
||||
route=pick.route,
|
||||
land_class=pick.land_class,
|
||||
)
|
||||
logger.info(
|
||||
"multi.land_options.submit sender=%s biz=%s type=%s route=%s scene=%s",
|
||||
sender_id,
|
||||
target.facts.get("陆运业务类型") or "-",
|
||||
target.facts.get("运输类型") or "-",
|
||||
target.facts.get("线路类别") or "-",
|
||||
target.facts.get("运输分类") or "-",
|
||||
)
|
||||
return self._open(
|
||||
sender_id, segments, reply, immutable=sess.immutable_text or ""
|
||||
)
|
||||
|
||||
def _enrich_segments(
|
||||
self,
|
||||
@@ -507,12 +651,14 @@ class MultiTextInquiryFlow:
|
||||
)
|
||||
if refused:
|
||||
return refused
|
||||
ready, updated, gaps = refresh_segments(segments)
|
||||
options_on_card = land_option_card_segment(segments) is not None
|
||||
ready, updated, gaps = refresh_segments(segments, options_on_card=options_on_card)
|
||||
if not ready:
|
||||
self._reply_gaps(updated, gaps, reply)
|
||||
# 先落书签再出卡:卡回调要靠这份 facts 找回当前草稿。
|
||||
sess.phase = "clarify"
|
||||
self._put_segments(sess, updated)
|
||||
self._save(sess)
|
||||
self._reply_gaps(updated, gaps, reply, sender_id=sess.sender_id)
|
||||
return "clarify"
|
||||
payload = segments_to_payload(updated, keep_prompt_echo=False)
|
||||
created = self._ledger.create_ticket(
|
||||
|
||||
Reference in New Issue
Block a user