feat: require login for send_message and list_messages + dedup uid fetch
This commit is contained in:
parent
b494b242db
commit
3e8fc551ef
@ -447,9 +447,10 @@ async def _exec_tool(sor, tool, params, ctx, uid, org_id):
|
|||||||
|
|
||||||
|
|
||||||
if action == 'send_message':
|
if action == 'send_message':
|
||||||
# AgentIO sends JSON: {"params":{"prompt":"...","model_id":"..."},...}
|
uid = await get_user()
|
||||||
# FormData sends: action=send_message&message_text=...&model_id=...
|
if not uid:
|
||||||
# bricks sends prompt/model_id at top level
|
return json.dumps({"error":"请先登录"},ensure_ascii=False)
|
||||||
|
org_id = await get_userorgid() or '0'
|
||||||
p = params_kw or {}
|
p = params_kw or {}
|
||||||
message_text = (p.get('message_text') or '').strip()
|
message_text = (p.get('message_text') or '').strip()
|
||||||
user_model_id = p.get('model_id', '')
|
user_model_id = p.get('model_id', '')
|
||||||
@ -467,8 +468,6 @@ if action == 'send_message':
|
|||||||
blocked, reason = _security_scan(message_text)
|
blocked, reason = _security_scan(message_text)
|
||||||
if blocked: return json.dumps({"success":True,"agent_reply":f"⚠️ {reason}"},ensure_ascii=False)
|
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}")
|
debug(f"AUTH: uid={uid}, org_id={org_id}")
|
||||||
|
|
||||||
async def agent_stream():
|
async def agent_stream():
|
||||||
@ -547,6 +546,9 @@ if action == 'send_message':
|
|||||||
return await stream_response(request, agent_stream, 'text/plain; charset=utf-8')
|
return await stream_response(request, agent_stream, 'text/plain; charset=utf-8')
|
||||||
|
|
||||||
elif action == 'list_messages':
|
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:
|
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",{})
|
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 [])]
|
result = [{"role":getattr(m,'role',''),"content":getattr(m,'content','')} for m in (ms or [])]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user