feat(work): stage authenticated remote approvals with scoped execution fencing

This commit is contained in:
ex_tianzy
2026-11-17 11:43:33 +08:00
parent d2881b82b0
commit c80c6a0d27
19 changed files with 1586 additions and 25 deletions
+8 -4
View File
@@ -10,7 +10,7 @@ DELIVERY={None:'尚未接收结果','ready':'已接收结果,等待投递','se
'replied':'结果已发送到当前会话','unknown':'结果投递待核对','discarded':'结果已停止交付'}
def card_content(task_id,execution,delivery,files=None,connection_lost=False):
def card_content(task_id,execution,delivery,files=None,connection_lost=False,remote_approvals=False):
execution=execution if execution in EXECUTION else 'unknown'
color='green' if execution=='completed' else 'red' if execution in {'failed','interrupted'} else 'orange' if execution in {'waiting_for_approval','unknown'} else 'blue'
label=EXECUTION[execution]
@@ -20,7 +20,9 @@ def card_content(task_id,execution,delivery,files=None,connection_lost=False):
{'tag':'div','text':{'tag':'plain_text','content':'文字回复:'+DELIVERY.get(delivery,'状态待核对')}},
{'tag':'note','elements':[{'tag':'plain_text','content':'任务编号:'+task_id}]}]
if execution=='waiting_for_approval':
elements.insert(1,{'tag':'div','text':{'tag':'plain_text','content':'请在客户端查看并确认具体操作。本卡片暂不提供远程批准。'}})
hint=('请在本任务的操作确认卡片中核对动作和影响,选择允许本次或拒绝。'if remote_approvals else
'请在客户端查看并确认具体操作。本卡片暂不提供远程批准。')
elements.insert(1,{'tag':'div','text':{'tag':'plain_text','content':hint}})
if execution=='completed' and delivery!='replied':
elements.insert(1,{'tag':'div','text':{'tag':'plain_text','content':'任务已执行完成,结果交付请看下方状态。'}})
return {'config':{'wide_screen_mode':True,'enable_forward':False},
@@ -28,9 +30,10 @@ def card_content(task_id,execution,delivery,files=None,connection_lost=False):
class TaskCards:
def __init__(self,state,platform,worker_id,clock=time.time,files_enabled=False):
def __init__(self,state,platform,worker_id,clock=time.time,files_enabled=False,remote_approvals=False):
self.state,self.db,self.platform,self.worker_id,self.clock=state,state.db,platform,worker_id,clock
self.files_enabled=files_enabled
self.remote_approvals=remote_approvals
with self.db:
self.db.execute('''CREATE TABLE IF NOT EXISTS work_task_connection_v3(
task_id TEXT PRIMARY KEY,reason TEXT NOT NULL)''')
@@ -57,7 +60,8 @@ class TaskCards:
if task['status']=='unknown' and execution not in {'completed','failed','cancelled','interrupted'}:execution='unknown'
if task['deadline']<=self.clock() and execution not in {'completed','failed','cancelled','interrupted'}:execution='unknown'
lost=self.db.execute('SELECT reason FROM work_task_connection_v3 WHERE task_id=?',(task['turn_id'],)).fetchone()
return card_content(task['turn_id'],execution,delivery['status'] if delivery else None,connection_lost=bool(lost))
return card_content(task['turn_id'],execution,delivery['status'] if delivery else None,
connection_lost=bool(lost),remote_approvals=self.remote_approvals)
async def flush(self):
# Bound one maintenance pass; business result delivery remains independent.