diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index 9965a8f..8b10302 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -447,9 +447,10 @@ async def _exec_tool(sor, tool, params, ctx, uid, org_id): if action == 'send_message': - # AgentIO sends JSON: {"params":{"prompt":"...","model_id":"..."},...} - # FormData sends: action=send_message&message_text=...&model_id=... - # bricks sends prompt/model_id at top level + uid = await get_user() + if not uid: + return json.dumps({"error":"请先登录"},ensure_ascii=False) + org_id = await get_userorgid() or '0' p = params_kw or {} message_text = (p.get('message_text') or '').strip() user_model_id = p.get('model_id', '') @@ -467,8 +468,6 @@ if action == 'send_message': blocked, reason = _security_scan(message_text) if blocked: return json.dumps({"success":True,"agent_reply":f"⚠️ {reason}"},ensure_ascii=False) - uid = await get_user() - org_id = await get_userorgid() or '0' debug(f"AUTH: uid={uid}, org_id={org_id}") async def agent_stream(): @@ -547,6 +546,9 @@ if action == 'send_message': return await stream_response(request, agent_stream, 'text/plain; charset=utf-8') elif action == 'list_messages': + uid = await get_user() + if not uid: + return json.dumps({"error":"请先登录"},ensure_ascii=False) async with DBPools().sqlorContext(dbname) as sor: ms = await sor.sqlExe("SELECT role,content,created_at FROM pipeline_conversations ORDER BY created_at ASC LIMIT 100",{}) result = [{"role":getattr(m,'role',''),"content":getattr(m,'content','')} for m in (ms or [])]