From a33ce02fa690ee9f3200f7561b0516c23096927b Mon Sep 17 00:00:00 2001 From: ex_tianzy Date: Thu, 12 Nov 2026 16:16:44 +0800 Subject: [PATCH] fix(work): show attachment delivery separately from text replies --- deployable/relay/task_cards.py | 22 ++++++++++++++++++---- deployable/relay/task_delivery.py | 2 +- deployable/tests/test_task_cards.py | 7 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/deployable/relay/task_cards.py b/deployable/relay/task_cards.py index 8254e09..d906032 100644 --- a/deployable/relay/task_cards.py +++ b/deployable/relay/task_cards.py @@ -10,12 +10,21 @@ DELIVERY={None:'尚未接收结果','ready':'已接收结果,等待投递','se 'replied':'结果已发送到当前会话','unknown':'结果投递待核对','discarded':'结果已停止交付'} -def card_content(task_id,execution,delivery): +def card_content(task_id,execution,delivery,files=None): execution=execution if execution in EXECUTION else 'unknown' color='green' if execution=='completed' else 'red' if execution=='failed' else 'orange' if execution in {'waiting_for_approval','unknown'} else 'blue' elements=[{'tag':'div','text':{'tag':'plain_text','content':'任务状态:'+EXECUTION[execution]}}, - {'tag':'div','text':{'tag':'plain_text','content':'结果交付:'+DELIVERY.get(delivery,'状态待核对')}}, + {'tag':'div','text':{'tag':'plain_text','content':'文字回复:'+DELIVERY.get(delivery,'状态待核对')}}, {'tag':'note','elements':[{'tag':'plain_text','content':'任务编号:'+task_id}]}] + if files is not None: + counts={} + for status in files:counts[status]=counts.get(status,0)+1 + sent=counts.get('sent',0) + pending=sum(counts.get(s,0)for s in ('ready','uploading','uploaded','sending')) + unresolved=len(files)-sent-pending + description=('未收到登记的文件,不代表附件已交付' if not files else + f'已发送{sent}件,待投递{pending}件,异常或待核对{unresolved}件') + elements.insert(2,{'tag':'div','text':{'tag':'plain_text','content':'附件交付:'+description}}) if execution=='waiting_for_approval': elements.insert(1,{'tag':'div','text':{'tag':'plain_text','content':'请在客户端查看并确认具体操作。本卡片暂不提供远程批准。'}}) if execution=='completed' and delivery!='replied': @@ -25,8 +34,9 @@ def card_content(task_id,execution,delivery): class TaskCards: - def __init__(self,state,platform,worker_id,clock=time.time): + def __init__(self,state,platform,worker_id,clock=time.time,files_enabled=False): self.state,self.db,self.platform,self.worker_id,self.clock=state,state.db,platform,worker_id,clock + self.files_enabled=files_enabled with self.db: self.db.execute('''CREATE TABLE IF NOT EXISTS work_task_cards_v3( task_id TEXT PRIMARY KEY,message_id TEXT NOT NULL,digest TEXT NOT NULL, @@ -43,7 +53,11 @@ class TaskCards: execution=row['execution_state'] if row else 'unknown' 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' - return card_content(task['turn_id'],execution,delivery['status'] if delivery else None) + files=None + if self.files_enabled: + files=[r['status']for r in self.db.execute("SELECT status FROM work_files_v1 WHERE task_id=? AND environment=? AND app_id=? AND direction='output'", + (task['turn_id'],self.state.environment,self.state.app_id)).fetchall()] + return card_content(task['turn_id'],execution,delivery['status'] if delivery else None,files) async def flush(self): # Bound one maintenance pass; business result delivery remains independent. diff --git a/deployable/relay/task_delivery.py b/deployable/relay/task_delivery.py index 93de136..2a4cf65 100644 --- a/deployable/relay/task_delivery.py +++ b/deployable/relay/task_delivery.py @@ -43,7 +43,7 @@ class TaskDelivery: self.cards=None if auth.s.work_task_cards_enabled: from .task_cards import TaskCards - self.cards=TaskCards(state,platform,broker.worker_id) + self.cards=TaskCards(state,platform,broker.worker_id,files_enabled=auth.s.work_files_enabled) def current(self, body): self.auth.require_binding(body.host_id,body.binding_owner,body.binding_generation) diff --git a/deployable/tests/test_task_cards.py b/deployable/tests/test_task_cards.py index 2c83f2d..f52211a 100644 --- a/deployable/tests/test_task_cards.py +++ b/deployable/tests/test_task_cards.py @@ -117,6 +117,13 @@ def test_card_projection_never_exposes_task_body_or_markdown_controls(): assert data['config']['enable_forward'] is False +def test_text_delivery_never_claims_attachments_delivered(): + text=json.dumps(card_content('synthetic','completed','replied',[]),ensure_ascii=False) + assert '文字回复:' in text and '未收到登记的文件' in text + mixed=json.dumps(card_content('synthetic','completed','replied',['sent','ready','unknown']),ensure_ascii=False) + assert '已发送1件,待投递1件,异常或待核对1件' in mixed + + async def test_card_uses_task_bound_source_and_skips_foreign_and_expired(env,monkeypatch): task(env);cards,calls,clock=setup_cards(env,monkeypatch) with env['store'].db: