Skip to content

Agent Zero AI framework

Fix chat export targeting and import cancellation

Alessandro5581754fba70
diff --git a/tests/test_chat_import_export.py b/tests/test_chat_import_export.py
new file mode 100644
index 000000000..97a91200a
--- /dev/null
+++ b/tests/test_chat_import_export.py
@@ -0,0 +1,58 @@
+"""Chat import/export targeting and native file chooser cancellation."""
+from pathlib import Path
+import re
+import subprocess
+
+
+def test_chat_export_target_and_import_cancellation():
+ source = (Path(__file__).resolve().parents[1]
+ / 'webui/components/sidebar/chats/chats-store.js').read_text()
+ source = re.sub(r'^import\b[\s\S]*?;\n', '', source, flags=re.M)
+ source = source.replace('export { store };', '')
+ script = r'''
+import assert from 'node:assert/strict';
+const createStore = (_name, model) => model;
+const requests = [], downloads = [], notifications = [];
+const getContext = () => 'fallback';
+const setContext = () => {};
+const toast = message => notifications.push(message);
+const toastFetchError = (_message, error) => { throw error; };
+const sendJsonData = async (url, body) => {
+ requests.push({url, body});
+ return url === '/chat_export' ? {ctxid:body.ctxid, content:'{}'} : {ctxids:[]};
+};
+let picker;
+const document = {createElement(tag) {
+ assert.equal(tag, 'input');
+ return picker = {click() {}, files:[]};
+}};
+''' + source + r'''
+store.downloadFile = (...args) => downloads.push(args);
+store.selected = 'active';
+await store.saveChat('clicked');
+assert.deepEqual(requests.at(-1), {url:'/chat_export', body:{ctxid:'clicked'}});
+assert.deepEqual(downloads.at(-1), ['clicked.json', '{}']);
+assert.equal(store.selected, 'active');
+await store.saveChat();
+assert.equal(requests.at(-1).body.ctxid, 'active');
+store.selected = '';
+await store.saveChat();
+assert.equal(requests.at(-1).body.ctxid, 'fallback');
+const count = requests.length, toastCount = notifications.length;
+let loading = store.loadChats();
+assert.equal(picker.accept, '.json');
+assert.equal(picker.multiple, true);
+picker.oncancel();
+await loading;
+loading = store.loadChats();
+await picker.onchange();
+await loading;
+assert.equal(requests.length, count, 'cancel and empty selection must not call chat_load');
+assert.equal(notifications.length, toastCount, 'cancellation is silent');
+store.readJsonFiles = async () => ['{"history":[]}'];
+await store.loadChats();
+assert.deepEqual(requests.at(-1), {url:'/chat_load', body:{chats:['{"history":[]}']}});
+assert.equal(notifications.at(-1), 'Chats loaded.');
+'''
+ subprocess.run(['node', '--input-type=module'], input=script, text=True,
+ check=True, timeout=15)
diff --git a/webui/components/sidebar/AGENTS.md b/webui/components/sidebar/AGENTS.md
index 6d1098655..c09c961ef 100644
--- a/webui/components/sidebar/AGENTS.md
+++ b/webui/components/sidebar/AGENTS.md
@@ -24,6 +24,8 @@
- Chat and task lists reclaim the same part of the sidebar's left content inset so their project bubbles align, while their section headers retain the standard sidebar inset.
- Chat-row action buttons consume layout width only while a pointer row is hovered or while that row is selected on a touch device.
- Built-in chat and task overflow menus follow the standard row actions; plugin controls remain direct row actions.
+- `chats.saveChat(ctxid)` exports an explicit context without changing selection; omitted IDs retain current-chat behavior.
+- Cancelling the Load Chat file chooser resolves without calling `chat_load` or showing a success/error notification.
- `sidebar-row-actions-menu` owns plugin-contributed row-menu actions; list-order plugins register stable sort and divider callbacks through the sidebar store instead of patching chat/task stores or injecting row DOM.
- Bottom version information shows its commit timestamp in UTC without a timezone suffix and remains on one line.
- Avoid text or controls overflowing fixed sidebar widths.
diff --git a/webui/components/sidebar/chats/chats-store.js b/webui/components/sidebar/chats/chats-store.js
index be5072bde..51c761963 100644
--- a/webui/components/sidebar/chats/chats-store.js
+++ b/webui/components/sidebar/chats/chats-store.js
@@ -294,6 +294,7 @@ const model = {
async loadChats() {
try {
const fileContents = await this.readJsonFiles();
+ if (!fileContents.length) return;
const response = await sendJsonData("/chat_load", { chats: fileContents });
if (!response) {
@@ -310,10 +311,10 @@ const model = {
}
},
- // Save current chat
- async saveChat() {
+ // Save the supplied chat, or the current chat when omitted
+ async saveChat(ctxid = null) {
try {
- const context = this.selected || getContext();
+ const context = ctxid || this.selected || getContext();
const response = await sendJsonData("/chat_export", { ctxid: context });
if (!response) {
@@ -334,6 +335,7 @@ const model = {
input.type = "file";
input.accept = ".json";
input.multiple = true;
+ input.oncancel = () => resolve([]);
input.click();