From 56e48449922a4c1535baae487b8799d86851f33b Mon Sep 17 00:00:00 2001 From: Shivering Ocelot Date: Sun, 30 Aug 2026 23:42:23 -0500 Subject: [PATCH] use agentname in ws actions and frontend --- backend/src/app.py | 6 ++++++ backend/src/server.py | 22 ++++++++++++++------ frontend/src/backend.js | 4 ++-- frontend/src/components/main/Sidebar.vue | 6 +++--- frontend/src/views/Agent.vue | 22 +++++++++++--------- frontend/src/views/AgentCreate.vue | 26 ++++++++++++++++++++---- 6 files changed, 61 insertions(+), 25 deletions(-) diff --git a/backend/src/app.py b/backend/src/app.py index ffeb0ff..8b8260d 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -103,6 +103,12 @@ class App(ChatMixin): raise Exception(f"Agent not found with id {agent_id}") return agent + async def agent_id_from_name(self, agentname: str): + agent_id = await db.Agent.get_or_none(agentname=agentname).values_list("id", flat=True) + if not agent_id: + raise Exception(f"Agent not found with agentname {agentname}") + return agent_id + async def create_agent(self, user_id, name, agentname, description, picture, kind, data, main_chat_id=None, temporary=False): print("create_agent; user_id, name:", user_id, name) diff --git a/backend/src/server.py b/backend/src/server.py index aaf86e4..90663de 100644 --- a/backend/src/server.py +++ b/backend/src/server.py @@ -169,6 +169,16 @@ async def start_server(app, shutdown_event): body = req.get('body', {}) nonce = req.get('nonce', None) + async def agent_id_from_body (allow_none=False): + if 'agentId' in body: + return body['agentId'] + elif 'agentname' in body: + return await app.agent_id_from_name(body['agentname']) + elif allow_none: + return None + else: + raise Exception("field 'agentId' or 'agentname' required") + if action == "ping": await send({'message': "pong"}) @@ -187,7 +197,7 @@ async def start_server(app, shutdown_event): await send({'message': "agent created", 'agentId': agent_id, 'nonce': nonce}) elif action == "update-agent": - agent_id = body['agentId'] + agent_id = await agent_id_from_body() await app.update_agent( agent_id=agent_id, name=body.get('name'), @@ -217,7 +227,7 @@ async def start_server(app, shutdown_event): await send({'message': "model deleted", 'modelId': body["modelId"], 'nonce': nonce}) elif action == "get-agent-config-fields": - await send({'fields': await app.get_agent_config_fields(body['agentId']), 'nonce': nonce}) + await send({'fields': await app.get_agent_config_fields(await agent_id_from_body()), 'nonce': nonce}) elif action == "get-agent-kinds": await send({'message': "agents retrieved", 'kinds': app.get_agent_kinds(), 'nonce': nonce}) @@ -229,16 +239,16 @@ async def start_server(app, shutdown_event): await send({'message': "agents retrieved", 'agents': await app.get_agents(user_id), 'nonce': nonce}) elif action == "get-agent-resources": - values = await app.get_agent_resources(body['agentId'], body.get('kind'), body.get('key')) + values = await app.get_agent_resources(await agent_id_from_body(), body.get('kind'), body.get('key')) await send({'resources': [{'kind': r.kind, 'key': r.key, 'value': r.value} for r in values], 'nonce': nonce}) elif action == "save-agent-resource": - await app.save_agent_resource(body['agentId'], body['kind'], body['key'], body['value']) + await app.save_agent_resource(await agent_id_from_body(), body['kind'], body['key'], body['value']) await send({'message': "resource saved", 'nonce': nonce}) elif action == "get-agent-runs": await send({ - 'runs': await app.get_agent_runs(agent_id=body.get('agentId'), user_id=user_id), + 'runs': await app.get_agent_runs(agent_id=await agent_id_from_body(allow_none=True), user_id=user_id), 'nonce': nonce }) @@ -307,7 +317,7 @@ async def start_server(app, shutdown_event): continue response = await app.send_agent_prompt( - body['agentId'], + await agent_id_from_body(), body.get('instruction'), body.get('input'), body.get('options', {}) diff --git a/frontend/src/backend.js b/frontend/src/backend.js index 057d61b..753ef7e 100644 --- a/frontend/src/backend.js +++ b/frontend/src/backend.js @@ -326,9 +326,9 @@ export async function getAgents() { return cache.agents; } -export async function getAgent(agentId) { +export async function getAgent(agentname) { const allAgents = await getAgents(); - return allAgents.find(it => it.id == agentId); + return allAgents.find(it => it.agentname == agentname); } export function readStream(streamId) { diff --git a/frontend/src/components/main/Sidebar.vue b/frontend/src/components/main/Sidebar.vue index 059c39f..9dfa635 100644 --- a/frontend/src/components/main/Sidebar.vue +++ b/frontend/src/components/main/Sidebar.vue @@ -38,10 +38,10 @@ document.body.addEventListener('mouseup', documentMouseUp); chats.value = (await backend.getChats()).map(it => { - return {id: it.id, name: it.name}; + return Object.assign({}, it); }); agents.value = (await backend.getAgents()).map(it => { - return {id: it.id, name: it.name}; + return Object.assign({}, it); }); }); @@ -110,7 +110,7 @@ Create Chat