From ba48846ba14b3d4994d03a772d9967d456c30390 Mon Sep 17 00:00:00 2001 From: Shivering Ocelot Date: Thu, 3 Jul 2025 16:48:52 -0500 Subject: [PATCH] show and update agentname/identifier --- backend/app.py | 9 ++- backend/server.py | 2 + frontend/lib/agent_screen.dart | 100 +++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/backend/app.py b/backend/app.py index 8e680ac..286fa0e 100644 --- a/backend/app.py +++ b/backend/app.py @@ -73,11 +73,12 @@ class App: user_connections[remotename] = [] user_connections[remotename].append(channel) - def create_agent(self, user_id, name, description, picture, kind, data): + def create_agent(self, user_id, name, agentname, description, picture, kind, data): with self.sql_session() as session: agent = db.Agent() agent.user_id = user_id agent.name = name + agent.agentname = agentname agent.description = description agent.picture = picture agent.kind = kind @@ -108,7 +109,7 @@ class App: return chat_id # Updates the agent's basic fields, and applies field updates in its data - def update_agent(self, agent_id, name=None, description=None, picture=None, data=None): + def update_agent(self, agent_id, name=None, description=None, picture=None, agentname=None, data=None): with self.sql_session() as session: agent = session.execute( select(db.Agent).where(db.Agent.id == agent_id) @@ -128,6 +129,9 @@ class App: if picture != None: agent.picture = picture summary.append('picture') + if agentname != None: + agent.agentname = agentname + summary.append('agentname') if data: # Assign a copy to trigger a value change @@ -154,6 +158,7 @@ class App: return [{ "id": agent.id, "name": agent.name, + "agentname": agent.agentname, "description": agent.description, "picture": agent.picture, "kind": agent.kind, diff --git a/backend/server.py b/backend/server.py index 04be752..24b682d 100644 --- a/backend/server.py +++ b/backend/server.py @@ -122,6 +122,7 @@ def start_server(app): agent_id = app.create_agent( user_id=user_id, name=body['name'], + agentname=body.get('agentname'), description=body.get('description'), picture=body.get('picture'), kind=body['kind'], @@ -134,6 +135,7 @@ def start_server(app): app.update_agent( agent_id=agent_id, name=body.get('name'), + agentname=body.get('agentname'), description=body.get('description'), picture=body.get('picture'), data=body.get('data', {}) diff --git a/frontend/lib/agent_screen.dart b/frontend/lib/agent_screen.dart index 15b6b73..05c0e9a 100644 --- a/frontend/lib/agent_screen.dart +++ b/frontend/lib/agent_screen.dart @@ -24,6 +24,7 @@ class AgentScreen extends StatefulWidget { class _AgentScreenState extends State { String? _title; + String? _agentname; final TextEditingController nameController = TextEditingController(); String description = ""; List configFields = []; @@ -51,6 +52,8 @@ class _AgentScreenState extends State { final kindResponse = await Backend.sendAction('get-agent-kind-info', {'kind': agentEntry['kind']}); setState(() { + _title = agentEntry['name']; + _agentname = agentEntry['agentname']; description = kindResponse['info']['description']; }); } @@ -106,6 +109,103 @@ class _AgentScreenState extends State { child: Text(description), ) ), + Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: Align( + alignment: Alignment.centerLeft, + child: Row( + children: [ + Text('agent id: ${widget.agentId}, identifier: ${_agentname}'), + ElevatedButton( + onPressed: () { + TextEditingController _textFieldController = TextEditingController(); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('Enter new identifier'), + content: TextField( + controller: _textFieldController, + decoration: InputDecoration(hintText: "agent identifier"), + ), + actions: [ + ElevatedButton( + child: Text('CANCEL'), + onPressed: () { + Navigator.pop(context); + }, + ), + ElevatedButton( + child: Text('OK'), + onPressed: () { + Backend.sendAction("update-agent", { + 'agentId': widget.agentId, + 'agentname': _textFieldController.text, + }).then((response) { + final message = response['error'] != null ? + 'Error updating agent identifier.' : + 'Agent identifier updated.'; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(message)), + ); + }); + Navigator.pop(context); + }, + ), + ], + ); + }, + ); + }, + child: Text('Update identifier'), + ), + ElevatedButton( + onPressed: () { + TextEditingController _textFieldController = TextEditingController(); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('Enter new agent name'), + content: TextField( + controller: _textFieldController, + decoration: InputDecoration(hintText: "name"), + ), + actions: [ + ElevatedButton( + child: Text('CANCEL'), + onPressed: () { + Navigator.pop(context); + }, + ), + ElevatedButton( + child: Text('OK'), + onPressed: () { + Backend.sendAction("update-agent", { + 'agentId': widget.agentId, + 'name': _textFieldController.text, + }).then((response) { + final message = response['error'] != null ? + 'Error updating agent name.' : + 'Agent name updated.'; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(message)), + ); + }); + Navigator.pop(context); + }, + ), + ], + ); + }, + ); + }, + child: Text('Update name'), + ), + ] + ) + ) + ), ListView.builder( shrinkWrap: true, itemCount: configFields.length,