From b494b242db787da769d1cb5b109fb581e2c4b43e Mon Sep 17 00:00:00 2001 From: ymq Date: Mon, 10 Aug 2026 00:04:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20handle=20None=20user=5Fid=20=E2=80=94=20?= =?UTF-8?q?skip=20DB=20persistence,=20use=20in-memory=20ctx=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/cockpit_chat.dspy | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index a8bec46..9965a8f 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -79,6 +79,8 @@ async def _find_project(sor, name): return recs[0] if recs else None async def _load_ctx(sor, uid): + if not uid: + return {'pid':'','pname':'','ws':'','skills_dir':'','repos':[]} recs = await sor.sqlExe("SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",{"u":uid}) ctx = {'pid':'','pname':'','ws':'','skills_dir':'','repos':[]} if not recs: return ctx @@ -101,6 +103,8 @@ async def _load_ctx(sor, uid): return ctx async def _save_ctx(sor, uid, pid): + if not uid: + return try: await sor.sqlExe("UPDATE pipeline_agent_settings SET current_project_id=${p}$ WHERE user_id=${u}$",{"p":pid or '','u':uid}) ex = await sor.sqlExe("SELECT id FROM pipeline_agent_settings WHERE user_id=${u}$",{"u":uid}) @@ -465,6 +469,7 @@ if action == 'send_message': uid = await get_user() org_id = await get_userorgid() or '0' + debug(f"AUTH: uid={uid}, org_id={org_id}") async def agent_stream(): async with DBPools().sqlorContext(dbname) as sor: @@ -497,7 +502,8 @@ if action == 'send_message': continue msgs.append({"role":'user' if r=='user' else 'assistant',"content":c}) msgs.append({"role":"user","content":message_text}) - await sor.C('pipeline_conversations',{'id':getID(),'role':'user','content':message_text,'msg_type':'text','org_id':org_id,'created_by':uid,'iteration_id':ctx['pid'] or ''}) + if uid: + await sor.C('pipeline_conversations',{'id':getID(),'role':'user','content':message_text,'msg_type':'text','org_id':org_id,'created_by':uid,'iteration_id':ctx['pid'] or ''}) agent_reply = '' for turn in range(10): @@ -535,7 +541,8 @@ if action == 'send_message': d = json.dumps(_w_text(agent_reply), ensure_ascii=False)+'\n' debug(f"YIELD final: {d[:60]}") yield d - await sor.C('pipeline_conversations',{'id':getID(),'role':'agent','content':agent_reply,'msg_type':'text','org_id':org_id,'created_by':'system','iteration_id':ctx['pid'] or ''}) + if uid: + await sor.C('pipeline_conversations',{'id':getID(),'role':'agent','content':agent_reply,'msg_type':'text','org_id':org_id,'created_by':'system','iteration_id':ctx['pid'] or ''}) return await stream_response(request, agent_stream, 'text/plain; charset=utf-8')