This commit is contained in:
gr
2026-09-30 19:30:58 +08:00
parent d864953656
commit 1f0710e64d
40 changed files with 2531 additions and 692 deletions
+20 -6
View File
@@ -117,6 +117,8 @@ class ProtocolBot:
self.sender=sender or NativeSender(self.db,application_data_dir()/'protocol_sends.sqlite3')
self.generate=generate or self._generate
self.message_batch_window_seconds=8.;self.send_delay_seconds=2.;self.send_mode='auto'
# 本机审核范围:follow = 跟随管理后台(默认),every = 每条都审核,rules = 按原规则
self.review_scope='follow'
self.reply_count=0;self.false_pos_rows=[];self.security_verification_required=False
self._window_ready=True;self._reply_wakeup=threading.Event();self.needs_attention=False
self._since=time.time();self._pending={};self._seen={};self._contact_blocked={};self._manual_handoffs={};self._assistant_cancellations={}
@@ -781,12 +783,13 @@ class ProtocolBot:
self._save()
review,reason=self._needs_review(state)
if review and not state.get('approved'):
if not state.get('awaiting_review') or state.get('review_reason')!=reason:
with self._lock:state.update(awaiting_review=True,review_reason=reason,manual_required=False,manual_reason='')
every=self._review_every_reply()
if not state.get('awaiting_review') or state.get('review_reason')!=reason or bool(state.get('review_every_reply'))!=every:
with self._lock:state.update(awaiting_review=True,review_reason=reason,manual_required=False,manual_reason='',review_every_reply=every)
self._stage(key,'awaiting_review',reason)
return
if not review and (state.get('awaiting_review') or state.get('review_reason')):
with self._lock:state.update(awaiting_review=False,review_reason='')
with self._lock:state.update(awaiting_review=False,review_reason='',review_every_reply=False)
self._stage(key,'ready_to_send','审核策略已更新,等待发送前核对')
if time.time()<float(state.get('send_ready_at',0)):return
if not self._current(key,state):return
@@ -851,6 +854,11 @@ class ProtocolBot:
if self._pending.get(key) is state:self._pending.pop(key,None)
if state.get('contact_retry_evidence'):self._contact_blocked.pop(key,None)
self._save()
def _review_every_reply(self):
if self.send_mode!='review':return False
import ai_config
from review_policy import review_every_reply
return review_every_reply(getattr(self,'review_scope','follow'),getattr(ai_config,'AI_REVIEW_EVERY_REPLY',False))
def _needs_review(self,state):
import ai_config
from review_policy import selective_review_reason
@@ -859,7 +867,8 @@ class ProtocolBot:
if reason:return True,reason
if self._assistant_pending(state):
return True,state.get('review_reason') or '本会话仍有待处理审核,请由医疗助理回复客户'
if self.send_mode=='review' and not self._assistant_call('resumed',state.get('conv_id','')):
# 按原规则:人工回复并核验后该会话恢复自动;选了“每条都审核”就不看恢复记录
if self.send_mode=='review' and (self._review_every_reply() or not self._assistant_call('resumed',state.get('conv_id',''))):
return True,'人工审核后点击“通过并发送”'
return False,''
def _order_mcp_context(self,context):
@@ -982,10 +991,15 @@ class ProtocolBot:
self._assistant_cancellations=previous_cancellations
raise
self._reply_wakeup.set()
# 转人工也提醒医疗助理:已有的待审提醒改成转人工(发过的不重发),没有就新建一条。
# 改成转人工的提醒不算待审核,下面按原方式取消时不会再动它。
notified={key for key,state in removed if self._assistant_call('notify_handoff',state,default='')}
if notified:self._assistant_call('enqueue_notifications',default=None)
self._flush_assistant_cancellations()
for key,state in removed:
if not state.get('assistant_review_id'):self._assistant_call('cancel_review',state)
self.log(f"[协议转人工] {state.get('display_name','')} · 自动队列已移交人工;发送结果未作确认,不自动重发")
if key not in notified and not state.get('assistant_review_id'):self._assistant_call('cancel_review',state)
self.log(f"[协议转人工] {state.get('display_name','')} · 自动队列已移交人工;发送结果未作确认,不自动重发"
+(';已提醒医疗助理' if key in notified else ''))
try:
from queue_log import QueueLog
QueueLog().append(key,state.get('display_name',''),'转人工',