diff --git a/frontend/src/backend.js b/frontend/src/backend.js
index 753ef7e..bc1283c 100644
--- a/frontend/src/backend.js
+++ b/frontend/src/backend.js
@@ -157,6 +157,14 @@ export function sendAction(action, body = {}, callback = null) {
return deferred.promise;
}
+export async function act (action, body, { alert = null, cache = null } = {}) {
+ const res = await sendAction(action, body);
+ if (res.error) { ui.alert(`Error: ${res.error}`); return null; }
+ if (cache) invalidateCache(cache);
+ if (alert) ui.alert(alert);
+ return res;
+}
+
export function ping() {
if (socket && socket.readyState === WebSocket.OPEN) {
const data = JSON.stringify({ path: 'ping' });
diff --git a/frontend/src/ui.js b/frontend/src/ui.js
index 7f90aa5..147e703 100644
--- a/frontend/src/ui.js
+++ b/frontend/src/ui.js
@@ -1,5 +1,6 @@
// Global utility functions related with UI functionality
+import { ref } from 'vue';
import router from './router'
export function goto (path) {
@@ -33,6 +34,15 @@ export function contextMenu (entries) {
});
}
+// Helper object to manage track toggable ui elements
+export function useToggleSet () {
+ const state = ref({});
+ return {
+ has(key) { return Boolean(state.value[key]); },
+ toggle(key) { state.value[key] = !state.value[key]; },
+ };
+}
+
// === Events === //
diff --git a/frontend/src/views/Agent.vue b/frontend/src/views/Agent.vue
index 28087ea..64e2b6f 100644
--- a/frontend/src/views/Agent.vue
+++ b/frontend/src/views/Agent.vue
@@ -148,45 +148,35 @@
// === Configuration === //
- function updateIdentifier() {
+ async function updateIdentifier() {
const value = prompt(`Enter a new identifier for ${agent.value.name}`);
if (value) {
- backend.sendAction("update-agent", {
+ let res = await backend.act("update-agent", {
// agentId is necessary here
agentId: agent.value.id,
// used as value instead of identifier
agentname: value,
- }).then(res => {
- ui.alert(res.error ?
- 'Error updating agent identifier' :
- 'Agent identifier updated'
- );
- if (!res.error) {
- agent.value.agentname = value;
- backend.invalidateCache({agents: true});
- }
+ }, {
+ cache: {agents: true},
+ alert: 'Agent identifier updated'
});
+ if (!res.error) agent.value.agentname = value;
} else {
ui.alert("Cancelled identifier update");
}
}
- function updateName() {
+ async function updateName() {
const value = prompt(`Enter a new name for ${agent.value.name}`);
if (value) {
- backend.sendAction("update-agent", {
+ let res = await backend.sendAction("update-agent", {
agentname: agent.value.agentname,
name: value,
- }).then(res => {
- ui.alert(res.error ?
- 'Error updating agent name' :
- 'Agent name updated'
- );
- if (!res.error) {
- agent.value.name = value;
- backend.invalidateCache({agents: true});
- }
+ }, {
+ alert: 'Agent name updated',
+ cache: {agents: true},
});
+ if (!res.error) agent.value.name = value;
} else {
ui.alert("Cancelled name update");
}
@@ -215,19 +205,13 @@
}
}
- let res = await backend.sendAction("update-agent", {
+ await backend.act("update-agent", {
agentname: agent.value.agentname,
data: dataObject,
+ }, {
+ alert: 'Agent updated',
+ cache: {agents: true},
});
-
- ui.alert(res.error ?
- 'Error updating agent' :
- 'Agent updated'
- );
-
- if (!res.error) {
- backend.invalidateCache({agents: true});
- }
}
async function saveAddingTool() {
@@ -292,8 +276,8 @@
Enable Instruction/Input
-
-
+
+
diff --git a/frontend/src/views/AgentCreate.vue b/frontend/src/views/AgentCreate.vue
index ff3d4ed..00bcf2a 100644
--- a/frontend/src/views/AgentCreate.vue
+++ b/frontend/src/views/AgentCreate.vue
@@ -39,14 +39,13 @@
payload.temporary = true;
}
- let response = await backend.sendAction("create-agent", payload);
+ let response = await backend.act("create-agent", payload, {
+ alert: `Created Agent "${payload.name}"`,
+ cache: {agents: true},
+ });
- if (response.error) {
- ui.alert(`Could not create agent\n${response.error}`);
- } else {
- ui.alert(`Created Agent "${payload.name}"`);
+ if (!response.error) {
backend.invalidateCache({agents: true});
- ui.goto(`/agent/${payload.agentname}`);
}
}
diff --git a/frontend/src/views/Chat.vue b/frontend/src/views/Chat.vue
index 17421b5..7269ae7 100644
--- a/frontend/src/views/Chat.vue
+++ b/frontend/src/views/Chat.vue
@@ -26,7 +26,9 @@
} = session;
// UI state coupled to the document itself
- const expandedLogs = ref({}); // Message ids of logs currently expanded
+
+ // Message ids of logs currently expanded
+ const expandedLogs = ui.useToggleSet();
const inputFieldElem = ref(null);
const chatContainerElem = ref(null);
@@ -109,10 +111,6 @@
// === UI Helper Functions === //
- function toggleLogExpand (message) {
- expandedLogs.value[message.id] = !expandedLogs.value[message.id];
- }
-
async function chatEntryContextMenu (message, logMeta) {
let entries = [
{value: 'pin', title: "Pin message"},
@@ -143,7 +141,7 @@
break;
}
case 'toggle-log': {
- toggleLogExpand(message);
+ expandedLogs.toggle(message.id);
break;
}
case 'delete': {
@@ -178,13 +176,6 @@
});
}
- function inputKeyDown (event) {
- if (event.key == "Enter" && event.ctrlKey) {
- event.preventDefault();
- sendMessage();
- }
- }
-
@@ -203,10 +194,10 @@
:key="msg.id ?? ('thread-' + msg.threadId)"
:message="msg"
@open-menu="chatEntryContextMenu"
- @open-thread="session.activateThread"
+ @open-thread="session.activateThread($event)"
- :log-expanded="expandedLogs[msg.id]"
- @toggle-log="toggleLogExpand(msg)"
+ :log-expanded="expandedLogs.has(msg.id)"
+ @toggle-log="expandedLogs.toggle(msg.id)"
:cancellable="messageRunMap[msg.id]"
@cancel="session.cancelMessageRun(msg.id)"
@@ -218,7 +209,7 @@
{{editInfo}}
-
+
-