i更新
This commit is contained in:
+57
-1
@@ -93,6 +93,13 @@ def normalize_send_mode(value, default=SEND_MODE_AUTO):
|
||||
return SEND_MODE_REVIEW if default == SEND_MODE_REVIEW else SEND_MODE_AUTO
|
||||
|
||||
|
||||
def normalize_review_scope(value):
|
||||
"""本机审核范围(只在审核后发送模式下起作用):follow = 跟随管理后台下发的设置(默认),
|
||||
every = 每条都审核,rules = 按原规则(医疗助理人工回复并核验后该会话恢复自动)。"""
|
||||
from review_policy import normalize_review_scope as normalize
|
||||
return normalize(value)
|
||||
|
||||
|
||||
def cancel_assistant_review_for_state(state, root):
|
||||
"""Close only the explicitly cancelled episode; never start native I/O."""
|
||||
if not isinstance(state, dict) or not state.get("assistant_review_id"):
|
||||
@@ -205,7 +212,10 @@ def delete_pending_reply_file(keys, path="", *, handoff=False, confirm_uncertain
|
||||
return result
|
||||
|
||||
for _key, state in removed:
|
||||
cancel_assistant_review_for_state(state, directory)
|
||||
if handoff:
|
||||
handoff_assistant_review_for_state(state, directory)
|
||||
else:
|
||||
cancel_assistant_review_for_state(state, directory)
|
||||
result["deleted"] = [key for key, _state in removed]
|
||||
result["missing"] = sorted(requested.difference(result["deleted"]).difference(result["protected"]))
|
||||
try:
|
||||
@@ -225,6 +235,34 @@ def delete_pending_reply_file(keys, path="", *, handoff=False, confirm_uncertain
|
||||
return result
|
||||
|
||||
|
||||
def handoff_assistant_review_for_state(state, root, db=None):
|
||||
"""转人工也提醒医疗助理;提醒没开启或核对不了会话时按原方式取消提醒。返回是否已登记提醒。
|
||||
|
||||
只登记(或把已有的待审提醒改成转人工),不在这里发送:发送由监听中的医疗助理提醒线程完成,
|
||||
监听没开时等下次开始监听再发。"""
|
||||
if not isinstance(state, dict):
|
||||
return False
|
||||
event = state.get("database_event") or {}
|
||||
account = str(state.get("account") or event.get("account") or "")
|
||||
coordinator = None
|
||||
notified = False
|
||||
if account:
|
||||
try:
|
||||
from review_assistant import ReviewAssistantCoordinator
|
||||
coordinator = ReviewAssistantCoordinator(root=root, account=account, db=db)
|
||||
notified = bool(coordinator.notify_handoff(state))
|
||||
except Exception as exc:
|
||||
print(f"[助理审核] 转人工提醒登记失败({type(exc).__name__}),按原方式结束提醒")
|
||||
finally:
|
||||
if coordinator is not None:
|
||||
coordinator.close()
|
||||
if notified:
|
||||
print("[助理审核] 已转人工,已登记给医疗助理的提醒")
|
||||
return True
|
||||
cancel_assistant_review_for_state(state, root)
|
||||
return False
|
||||
|
||||
|
||||
def handoff_pending_reply_file(keys, path="", *, confirm_uncertain=False):
|
||||
"""Retire stopped work after explicit human takeover; preserve send evidence."""
|
||||
result = delete_pending_reply_file(keys, path, handoff=True, confirm_uncertain=confirm_uncertain)
|
||||
@@ -398,6 +436,7 @@ class BotThread(threading.Thread):
|
||||
message_batch_window_seconds=MESSAGE_BATCH_WINDOW_SECONDS,
|
||||
send_delay_seconds=SEND_DELAY_SECONDS,
|
||||
send_mode=SEND_MODE_AUTO,
|
||||
review_scope="follow",
|
||||
foreign_draft_autosend_minutes=FOREIGN_DRAFT_AUTOSEND_MINUTES,
|
||||
enable_engine_b=True,
|
||||
engine_b_poll_interval=2.0,
|
||||
@@ -426,6 +465,8 @@ class BotThread(threading.Thread):
|
||||
self.set_send_delay_seconds(send_delay_seconds)
|
||||
self.send_mode = SEND_MODE_AUTO
|
||||
self.set_send_mode(send_mode)
|
||||
self.review_scope = "follow"
|
||||
self.set_review_scope(review_scope)
|
||||
self.foreign_draft_autosend_minutes = FOREIGN_DRAFT_AUTOSEND_MINUTES
|
||||
self.set_foreign_draft_autosend_minutes(foreign_draft_autosend_minutes)
|
||||
self.stop_event = threading.Event()
|
||||
@@ -472,6 +513,14 @@ class BotThread(threading.Thread):
|
||||
if bot is not None:
|
||||
bot.send_mode = mode
|
||||
|
||||
def set_review_scope(self, value):
|
||||
"""本机审核范围:跟随管理后台 / 每条都审核 / 按原规则(只影响之后的回复)。"""
|
||||
scope = normalize_review_scope(value)
|
||||
self.review_scope = scope
|
||||
bot = getattr(self, "bot", None)
|
||||
if bot is not None:
|
||||
bot.review_scope = scope
|
||||
|
||||
def _report_progress(self, text):
|
||||
"""把机器人此刻在做什么送到界面上那行进度文字。"""
|
||||
try:
|
||||
@@ -720,6 +769,7 @@ class BotThread(threading.Thread):
|
||||
bot.message_batch_window_seconds = self.message_batch_window_seconds
|
||||
bot.send_delay_seconds = self.send_delay_seconds
|
||||
bot.send_mode = self.send_mode
|
||||
bot.review_scope = self.review_scope
|
||||
bot.foreign_draft_autosend_minutes = self.foreign_draft_autosend_minutes
|
||||
bot._stop_check = self.stop_event
|
||||
bot.safe_window_mode = True
|
||||
@@ -795,6 +845,10 @@ class BotThread(threading.Thread):
|
||||
"(AI 只把回复填进输入框,不会自动按回车;"
|
||||
"需要自动发送请在设置里切到“自动发送”)"
|
||||
)
|
||||
print("[+] 审核范围:" + {
|
||||
"every": "本机设为每条都审核(人工回复过的会话也不恢复自动)",
|
||||
"rules": "本机设为按原规则(医疗助理人工回复后该会话恢复自动,仍逐条风控)",
|
||||
}.get(self.review_scope, "跟随管理后台统一设置"))
|
||||
else:
|
||||
print("[+] 发送模式:自动发送(通过全部安全校验后自动按回车)")
|
||||
try:
|
||||
@@ -826,6 +880,7 @@ class BotThread(threading.Thread):
|
||||
bot.message_batch_window_seconds = self.message_batch_window_seconds
|
||||
bot.send_delay_seconds = self.send_delay_seconds
|
||||
bot.send_mode = self.send_mode
|
||||
bot.review_scope = self.review_scope
|
||||
bot.foreign_draft_autosend_minutes = self.foreign_draft_autosend_minutes
|
||||
# 引擎 A 开关:关闭时跳过红点截图扫描,只保留队列恢复
|
||||
# (引擎 B 投递的待回复任务仍会被捡起并发送)。
|
||||
@@ -930,6 +985,7 @@ class BotThread(threading.Thread):
|
||||
bot.message_batch_window_seconds = self.message_batch_window_seconds
|
||||
bot.send_delay_seconds = self.send_delay_seconds
|
||||
bot.send_mode = self.send_mode
|
||||
bot.review_scope = self.review_scope
|
||||
try:
|
||||
bot.poll_once()
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user