show and update agentname/identifier
This commit is contained in:
1 parent
6530ff0a24
commit
ba48846ba1
3 files changed
+109
-2
No files matched your search
+7
-2
@@ -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,
|
||||
|
||||
@@ -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', {})
|
||||
|
||||
@@ -24,6 +24,7 @@ class AgentScreen extends StatefulWidget {
|
||||
|
||||
class _AgentScreenState extends State<AgentScreen> {
|
||||
String? _title;
|
||||
String? _agentname;
|
||||
final TextEditingController nameController = TextEditingController();
|
||||
String description = "";
|
||||
List<ConfigField> configFields = [];
|
||||
@@ -51,6 +52,8 @@ class _AgentScreenState extends State<AgentScreen> {
|
||||
|
||||
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<AgentScreen> {
|
||||
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(
|
||||
shrinkWrap: true,
|
||||
itemCount: configFields.length,
|
||||
|
||||
Reference in new issue
Block a user