show and update agentname/identifier

This commit is contained in:
Shivering Ocelot committed 2025-07-03 16:48:52 -05:00
1 parent 6530ff0a24
commit ba48846ba1
3 files changed
+109 -2

No files matched your search

+7 -2
View File
@@ -73,11 +73,12 @@ class App:
user_connections[remotename] = [] user_connections[remotename] = []
user_connections[remotename].append(channel) 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: with self.sql_session() as session:
agent = db.Agent() agent = db.Agent()
agent.user_id = user_id agent.user_id = user_id
agent.name = name agent.name = name
agent.agentname = agentname
agent.description = description agent.description = description
agent.picture = picture agent.picture = picture
agent.kind = kind agent.kind = kind
@@ -108,7 +109,7 @@ class App:
return chat_id return chat_id
# Updates the agent's basic fields, and applies field updates in its data # 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: with self.sql_session() as session:
agent = session.execute( agent = session.execute(
select(db.Agent).where(db.Agent.id == agent_id) select(db.Agent).where(db.Agent.id == agent_id)
@@ -128,6 +129,9 @@ class App:
if picture != None: if picture != None:
agent.picture = picture agent.picture = picture
summary.append('picture') summary.append('picture')
if agentname != None:
agent.agentname = agentname
summary.append('agentname')
if data: if data:
# Assign a copy to trigger a value change # Assign a copy to trigger a value change
@@ -154,6 +158,7 @@ class App:
return [{ return [{
"id": agent.id, "id": agent.id,
"name": agent.name, "name": agent.name,
"agentname": agent.agentname,
"description": agent.description, "description": agent.description,
"picture": agent.picture, "picture": agent.picture,
"kind": agent.kind, "kind": agent.kind,
+2
View File
@@ -122,6 +122,7 @@ def start_server(app):
agent_id = app.create_agent( agent_id = app.create_agent(
user_id=user_id, user_id=user_id,
name=body['name'], name=body['name'],
agentname=body.get('agentname'),
description=body.get('description'), description=body.get('description'),
picture=body.get('picture'), picture=body.get('picture'),
kind=body['kind'], kind=body['kind'],
@@ -134,6 +135,7 @@ def start_server(app):
app.update_agent( app.update_agent(
agent_id=agent_id, agent_id=agent_id,
name=body.get('name'), name=body.get('name'),
agentname=body.get('agentname'),
description=body.get('description'), description=body.get('description'),
picture=body.get('picture'), picture=body.get('picture'),
data=body.get('data', {}) data=body.get('data', {})
+100
View File
@@ -24,6 +24,7 @@ class AgentScreen extends StatefulWidget {
class _AgentScreenState extends State<AgentScreen> { class _AgentScreenState extends State<AgentScreen> {
String? _title; String? _title;
String? _agentname;
final TextEditingController nameController = TextEditingController(); final TextEditingController nameController = TextEditingController();
String description = ""; String description = "";
List<ConfigField> configFields = []; List<ConfigField> configFields = [];
@@ -51,6 +52,8 @@ class _AgentScreenState extends State<AgentScreen> {
final kindResponse = await Backend.sendAction('get-agent-kind-info', {'kind': agentEntry['kind']}); final kindResponse = await Backend.sendAction('get-agent-kind-info', {'kind': agentEntry['kind']});
setState(() { setState(() {
_title = agentEntry['name'];
_agentname = agentEntry['agentname'];
description = kindResponse['info']['description']; description = kindResponse['info']['description'];
}); });
} }
@@ -106,6 +109,103 @@ class _AgentScreenState extends State<AgentScreen> {
child: Text(description), 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: <Widget>[
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: <Widget>[
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( ListView.builder(
shrinkWrap: true, shrinkWrap: true,
itemCount: configFields.length, itemCount: configFields.length,