fix: 列表/诊断返回完整ID,详情工具支持前缀匹配兜底
- _t_list_tasks 返回完整ID(不再截断8位) - _t_list_questions 返回完整ID(去掉Q前缀+截断) - _t_list_deliverables 返回完整ID - _t_diagnose_project 列出失败/待执行任务完整ID - _t_task_detail/_t_answer_question/_t_view_deliverable 支持8位前缀匹配兜底
This commit is contained in:
parent
acda8bb7e7
commit
094d66d42b
@ -686,7 +686,7 @@ class AgentExecutor:
|
||||
icon = icons.get(st, "❓")
|
||||
title = (getattr(r, 'title', '') or '')[:60]
|
||||
role = getattr(r, 'role', '')
|
||||
tid = getattr(r, 'id', '')[:8]
|
||||
tid = getattr(r, 'id', '')
|
||||
lines.append(f"| {icon} {st} | {title} | {role} | {tid} |")
|
||||
return "\n".join(lines)
|
||||
|
||||
@ -697,6 +697,11 @@ class AgentExecutor:
|
||||
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT * FROM pipeline_tasks WHERE id=${tid}$", {"tid": tid})
|
||||
if not recs and len(tid) >= 6:
|
||||
# 前缀匹配兜底(兼容 8 位截断 ID)
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT * FROM pipeline_tasks WHERE id LIKE ${prefix}$ LIMIT 1",
|
||||
{"prefix": tid + "%"})
|
||||
if not recs:
|
||||
return f"任务不存在: {tid}"
|
||||
|
||||
@ -767,14 +772,32 @@ class AgentExecutor:
|
||||
fc = getattr(failed[0], "c", 0) if failed else 0
|
||||
vc = getattr(review[0], "c", 0) if review else 0
|
||||
|
||||
return (
|
||||
f"项目诊断:\n"
|
||||
f"- 待执行: {sc}\n"
|
||||
f"- 运行中: {rc}\n"
|
||||
f"- 待审核: {vc}\n"
|
||||
f"- 失败: {fc}\n"
|
||||
f"- 待回答问题: {qc}\n"
|
||||
)
|
||||
lines = [
|
||||
"项目诊断:",
|
||||
f"- 待执行: {sc}",
|
||||
f"- 运行中: {rc}",
|
||||
f"- 待审核: {vc}",
|
||||
f"- 失败: {fc}",
|
||||
f"- 待回答问题: {qc}",
|
||||
]
|
||||
|
||||
# 列出失败/待执行任务完整 ID,方便 agent 直接 task_detail
|
||||
if fc:
|
||||
failed_rows = await sor.sqlExe(
|
||||
"SELECT id, title, role FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='failed' ORDER BY created_at DESC LIMIT 10",
|
||||
{"pid": pid})
|
||||
lines.append("失败任务:")
|
||||
for fr in (failed_rows or []):
|
||||
lines.append(f" - [{getattr(fr, 'role', '?')}] {getattr(fr, 'title', '')} (id={getattr(fr, 'id', '')})")
|
||||
if sc:
|
||||
submitted_rows = await sor.sqlExe(
|
||||
"SELECT id, title, role FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='submitted' ORDER BY created_at ASC LIMIT 10",
|
||||
{"pid": pid})
|
||||
lines.append("待执行任务:")
|
||||
for sr in (submitted_rows or []):
|
||||
lines.append(f" - [{getattr(sr, 'role', '?')}] {getattr(sr, 'title', '')} (id={getattr(sr, 'id', '')})")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
async def _t_list_deliverables(self, sor, p, pid):
|
||||
if not pid:
|
||||
@ -793,7 +816,7 @@ class AgentExecutor:
|
||||
for r in recs:
|
||||
lines.append(
|
||||
f"- [{getattr(r, 'review_status', '?')}] {getattr(r, 'title', '')} "
|
||||
f"({getattr(r, 'deliverable_type', '')})"
|
||||
f"({getattr(r, 'deliverable_type', '')}) id={getattr(r, 'id', '')}"
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
@ -804,6 +827,10 @@ class AgentExecutor:
|
||||
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT * FROM pipeline_deliverables WHERE id=${did}$", {"did": did})
|
||||
if not recs and len(did) >= 6:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT * FROM pipeline_deliverables WHERE id LIKE ${prefix}$ LIMIT 1",
|
||||
{"prefix": did + "%"})
|
||||
if not recs:
|
||||
return f"交付件不存在: {did}"
|
||||
|
||||
@ -833,7 +860,7 @@ class AgentExecutor:
|
||||
|
||||
lines = []
|
||||
for r in recs:
|
||||
lines.append(f"- Q{getattr(r, 'id', '')[:8]}: {getattr(r, 'question', '')[:200]}")
|
||||
lines.append(f"- [{getattr(r, 'id', '')}] {getattr(r, 'question', '')[:200]}")
|
||||
return "\n".join(lines)
|
||||
|
||||
async def _t_answer_question(self, sor, p, pid):
|
||||
@ -842,6 +869,17 @@ class AgentExecutor:
|
||||
if not qid or not answer:
|
||||
return "需要问题ID和回答内容"
|
||||
|
||||
# 先精确匹配,再前缀匹配兜底(兼容截断 ID)
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT id FROM pipeline_agent_questions WHERE id=${qid}$", {"qid": qid})
|
||||
if not recs and len(qid) >= 6:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT id FROM pipeline_agent_questions WHERE id LIKE ${prefix}$ LIMIT 1",
|
||||
{"prefix": qid + "%"})
|
||||
if not recs:
|
||||
return f"问题不存在: {qid}"
|
||||
qid = getattr(recs[0], "id", qid)
|
||||
|
||||
await sor.sqlExe(
|
||||
"UPDATE pipeline_agent_questions SET answered=1, answer=${a}$ WHERE id=${qid}$",
|
||||
{"a": answer, "qid": qid})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user