From 058c84775f25b02904253bc3306418b4af75dbff Mon Sep 17 00:00:00 2001 From: ymq Date: Sat, 8 Aug 2026 12:07:07 +0800 Subject: [PATCH] fix: _find_project fuzzy match; start_agent use project_id not org_id --- wwwroot/api/cockpit_chat.dspy | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index acbc125..202852e 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -434,11 +434,19 @@ async def _classify_intent(model_info, message, ctx, history_msgs, questions_tex async def _find_project(sor, name, org_id): - """Find project by name.""" + """Find project by name (supports partial match).""" if not name: return None + # Try exact match first recs = await sor.sqlExe( "SELECT id, name FROM sd_projects WHERE name=${name}$ AND org_id=${oid}$", {"name": name, "oid": org_id}) + if recs: + return recs[0] + # Fuzzy match: name contains keyword + # Use f-string for LIKE to avoid aiomysql % escaping issues + kw = name.replace("'", "''") + sql = f"SELECT id, name FROM sd_projects WHERE name LIKE '%{kw}%' AND org_id='{org_id}' LIMIT 1" + recs = await sor.sqlExe(sql, {}) return recs[0] if recs else None @@ -868,8 +876,8 @@ if action == 'send_message': agent_reply = "请先指定项目。「创建XXX项目」或「切换到XXX项目」" else: tasks = await sor.sqlExe( - "SELECT id, title, state FROM pipeline_tasks WHERE tenant_id=${oid}$ AND state='submitted' LIMIT 5", - {"oid": org_id}) + "SELECT id, title, state FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='submitted' LIMIT 5", + {"pid": pid}) if not tasks: agent_reply = f"项目「{ctx['project_name']}」暂无待执行任务。\n\n请先提交开发任务,例如:设计用户表结构" else: