diff --git a/backend/src/app.py b/backend/src/app.py index 0c49a12..9238ffa 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -285,9 +285,13 @@ class App(ChatMixin): # --- Resource Management --- - async def get_agent_resource(self, agent_id, kind, key): - resource = await db.AgentResource.get_or_none(agent_id=agent_id, kind=kind, key=key) - return resource.value if resource else None + async def get_agent_resources(self, agent_id, kind=None, key=None): + filter = {"agent_id": agent_id} + if kind: filter['kind'] = kind + if key: filter['key'] = key + + values = await db.AgentResource.filter(**filter) + return values async def save_agent_resource(self, agent_id, kind, key, value): await db.AgentResource.update_or_create( diff --git a/backend/src/server.py b/backend/src/server.py index 6e59385..14c6fa7 100644 --- a/backend/src/server.py +++ b/backend/src/server.py @@ -223,6 +223,14 @@ async def start_server(app): elif action == "get-agents": 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')) + 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 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), diff --git a/frontend/src/views/Agent.vue b/frontend/src/views/Agent.vue index e95053f..d928041 100644 --- a/frontend/src/views/Agent.vue +++ b/frontend/src/views/Agent.vue @@ -16,13 +16,17 @@ }, }); + // Data const agent = ref({}); const kindInfo = ref({}); const configFields = ref([]); - // Only used for scripted agents. - const actionDefinitions = ref([]); + const resources = ref([]); + const tools = ref([]); const modelList = ref([]); + // UI State + const addingTool = ref(null); + const addingResource = ref(null); // === State Management === // @@ -59,18 +63,12 @@ default: null, enabled: field.value != null, })); + }); - if (dataObject.actions) { - actionDefinitions.value = dataObject.actions.map(name => { - const fieldName = 'action_' + name; - const fieldData = dataObject[fieldName]; - return { - name, - argument: fieldData ? JSON.stringify(fieldData.argument) : "{}", - body: fieldData && fieldData.body || "pass", - } - }); - } + // Replace with a backend call + backend.sendAction('get-agent-resources', {agentId}).then(res => { + tools.value = res.resources.filter(r => r.kind == 'tool'); + resources.value = res.resources.filter(r => !['tool', 'config'].includes(r.kind)); }); } @@ -230,57 +228,34 @@ } } - // == Scripted Agent Actions == // - function createAction () { - const value = prompt(`Enter an identifier for the new action`); - if (value) { - const def = { - name: value, - argument: "{}", - body: "pass", - }; - const actionsField = configFields.value.find(field => field.name == 'actions'); - if (actionsField) { - actionsField.value.push(def.name); - } else { - configFields.value.push({ - name: def.name, - value: [def.name], - enabled: true, - }); - } - saveAction(def); - } else { - ui.alert('Action creation cancelled'); - } + async function saveAddingTool() { + let resource = { + kind: 'tool', + key: addingTool.value.name, + value: JSON.parse(addingTool.value.value), + }; + addingTool.value = null; + + let res = await backend.sendAction("save-agent-resource", { + agentId: agent.value.id, + ...resource + }); + tools.value.push(resource); } - // Update the config fields relevant to the action and saves changes automatically. Doesn't update 'actions'. - function saveAction (actionDef) { - let argSchema; - try { - argSchema = JSON.parse(actionDef.argument); - } catch (e) { - ui.alert("Bad Argument JSON: " + e.message); - return; - } - const fieldName = 'action_' + actionDef.name; - const actionField = configFields.value.find(field => field.name == fieldName); - if (actionField) { - actionField.arguments = argSchema; - actionField.body = actionDef.body; - } else { - configFields.value.push({ - name: fieldName, - value: { - argument: argSchema, - body: actionDef.body, - }, - enabled: true, - }); - } + async function saveAddingResource() { + let resource = { + kind: addingResource.value.kind, + key: addingResource.value.key, + value: JSON.parse(addingResource.value.value), + }; + addingResource.value = null; - saveChanges(); + let res = await backend.sendAction("save-agent-resource", { + agentId: agent.value.id, + ...resource + }); + resources.value.push(resource); } @@ -339,22 +314,6 @@ -