use agentname in ws actions and frontend
This commit is contained in:
1 parent
3b2b3507e5
commit
56e4844992
6 files changed
+61
-25
No files matched your search
+16
-6
@@ -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', {})
|
||||
|
||||
Reference in new issue
Block a user