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')