update
This commit is contained in:
@@ -12,6 +12,9 @@ def precise_answer(payload):
|
||||
item=payload.evidence[0]
|
||||
if item.status!='ok' or item.resource!=query.resource:
|
||||
return None
|
||||
progress = task_progress_answer(payload, query, item)
|
||||
if progress is not None:
|
||||
return progress
|
||||
computed=bool(query.analysis and item.computation and item.computation.get('complete'))
|
||||
if not (query.operation==item.operation=='count' or computed):
|
||||
return None
|
||||
@@ -63,3 +66,58 @@ def precise_answer(payload):
|
||||
if note:
|
||||
lines+=['','> '+note.replace('\n','\n> ')]
|
||||
return ContinueDecision(answer='\n'.join(lines),source_ids=references)
|
||||
|
||||
|
||||
def task_progress_answer(payload, query, item):
|
||||
"""Summarize registered task fields without inventing completion dates/causes.
|
||||
|
||||
Only the ordinary single-task-list progress question takes this path. Other
|
||||
analysis, requested evidence and missing fields stay with the bounded agent.
|
||||
"""
|
||||
import re
|
||||
from datetime import date
|
||||
if (query.resource != 'tasks' or query.operation != 'list' or query.analysis or query.include
|
||||
or not item.rows or not re.search(r'任务.*(?:进度|进展|完成情况)', payload.message)
|
||||
or re.search(r'原因|为什么|反馈|对比|相比|评分|评价|质量|完成率|风险', payload.message)
|
||||
or any(not row.get('status') or not (row.get('name') or row.get('title')) for row in item.rows)):
|
||||
return None
|
||||
from app.modules.work_assistant.answers import _conditions
|
||||
definitions = {r['id']: r for r in payload.resources}
|
||||
conditions = _conditions(item, definitions)
|
||||
complete = item.offset == 0 and item.total == len(item.rows)
|
||||
done = sum(row['status'] == '已完成' for row in item.rows)
|
||||
active = sum(row['status'] == '进行中' for row in item.rows)
|
||||
other = len(item.rows) - done - active
|
||||
count_scope = '其中' if complete else f'本页展示 {len(item.rows)} 项,其中'
|
||||
lines = [f'共 **{item.total} 项任务**。{count_scope}已完成 **{done} 项**,进行中 **{active} 项**'
|
||||
+ (f',其他状态 **{other} 项**。' if other else '。')]
|
||||
if conditions:
|
||||
lines += ['', conditions]
|
||||
lines += ['', '| 任务名称 | 状态 | 进度 | 截止日期 |', '| --- | --- | --- | --- |']
|
||||
def cell(value):
|
||||
return str(value if value not in (None, '') else '未提供').replace('|', '/').replace('\n', ' ')
|
||||
refs = ['result:0']
|
||||
overdue = []
|
||||
for row in item.rows:
|
||||
name = row.get('name') or row.get('title')
|
||||
progress = row.get('progress')
|
||||
lines.append('| ' + ' | '.join(cell(v) for v in (name, row['status'],
|
||||
f'{progress}%' if progress not in (None, '') else None, row.get('deadline'))) + ' |')
|
||||
if row.get('id') is not None:
|
||||
refs.append(f"tasks:{row['id']}")
|
||||
if row['status'] == '进行中' and row.get('deadline') and payload.today:
|
||||
try:
|
||||
days = (date.fromisoformat(payload.today) - date.fromisoformat(str(row['deadline'])[:10])).days
|
||||
if days > 0:
|
||||
overdue.append((days, name))
|
||||
except ValueError:
|
||||
pass
|
||||
if overdue:
|
||||
lines += ['', ('建议优先核对:' if re.search(r'优先|关注|建议|安排', payload.message) else '已过截止日期的进行中任务:')
|
||||
+ ';'.join(f'{name}({days} 天)' for days, name in sorted(overdue, key=lambda x: -x[0])) + '。']
|
||||
if not complete:
|
||||
lines += ['', '状态数量仅对应本页,未展示记录的完成情况尚未统计。']
|
||||
note = display_note(item.note, definitions.get(item.resource))
|
||||
if note:
|
||||
lines += ['', note]
|
||||
return ContinueDecision(answer='\n'.join(lines), source_ids=refs)
|
||||
|
||||
Reference in New Issue
Block a user