Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): let users review a return to the previous task chat
Xubin Ren61ab136e58f4
diff --git a/docs/automations.md b/docs/automations.mdindex 3cd0df39d..62ea3c7fa 100644--- a/docs/automations.md+++ b/docs/automations.md@@ -150,6 +150,11 @@ with the channel logo and name. To change it:any intended separate sends. Members of the new chat can see future task messages and results.3. Select **Confirm change**. Wait for the saved confirmation.+Select **Cancel** before saving to return to the task without changes. After a+successful save, select **Change back to** to review a return to the previous+chat. You must confirm this change too. You can also select a previous chat from+the list later. This changes future runs; it does not recall messages already sent.+Future runs use the new chat's history and reply there by default. Previousmessages stay in their original chat. Previous run results remain available.Changing the chat does not run the task, enable it, or change its schedule.diff --git a/tests/tools/test_message_tool_suppress.py b/tests/tools/test_message_tool_suppress.pyindex e3dcb03ba..d632abc11 100644--- a/tests/tools/test_message_tool_suppress.py+++ b/tests/tools/test_message_tool_suppress.py@@ -204,7 +204,8 @@ class TestMessageToolSchema:def test_schema_discourages_current_chat_replies(self) -> None:tool = MessageTool()- assert "Do not use this for the normal reply in the current chat" in tool.description+ assert "For a normal reply, including a scheduled reminder or report, answer naturally instead" in tool.description+ assert "nanobot delivers the final reply to the current chat" in tool.descriptionassert "generate_image creates images in the current chat" in tool.descriptionassert ("Do not use this for a normal reply in the current chat"diff --git a/webui/src/components/settings/system/AutomationChatBinding.tsx b/webui/src/components/settings/system/AutomationChatBinding.tsxindex fc3b012c4..af57febbd 100644--- a/webui/src/components/settings/system/AutomationChatBinding.tsx+++ b/webui/src/components/settings/system/AutomationChatBinding.tsx@@ -46,7 +46,7 @@ export function AutomationChatBinding({ job, token, onSave, children }: {const [draft, setDraft] = useState<{ target: AutomationChat; previous: AutomationChat; revision: string; message: string } | null>(null);const [saving, setSaving] = useState(false);const [error, setError] = useState("");- const [saved, setSaved] = useState<string | null>(null);+ const [saved, setSaved] = useState<{ target: AutomationChat; previous: AutomationChat } | null>(null);const heading = useRef<HTMLHeadingElement>(null);const trigger = useRef<HTMLButtonElement>(null);const returning = useRef(false);@@ -100,7 +100,7 @@ export function AutomationChatBinding({ job, token, onSave, children }: {try {await onSave(job, { target_id: draft.target.id, revision: draft.revision, message: draft.message });setData(previous => previous ? { ...previous, current: draft.target } : previous);- setSaved(draft.target.title); back(); setReload(value => value + 1);+ setSaved({ target: draft.target, previous: draft.previous }); back(); setReload(value => value + 1);} catch (cause) {const reasons: Record<string, string> = {automation_chat_conflict: "conflict", automation_chat_busy: "schedulerBusy",@@ -113,8 +113,15 @@ export function AutomationChatBinding({ job, token, onSave, children }: {<p className="text-[13px] font-medium">{tx("label")}</p>{picker(false)}<p role={saved ? "status" : undefined} className="text-[12px] leading-5 text-muted-foreground">- {job.state.pending ? tx("busy") : saved ? tx("saved", { chat: saved }) : tx("hint")}+ {job.state.pending ? tx("busy") : saved ? tx("saved", { chat: saved.target.title }) : tx("hint")}</p>+ {saved && current?.id === saved.target.id && data?.chats.some(chat => chat.id === saved.previous.id && !chat.unavailable) ? (+ <Button variant="link" size="sm" className="h-11 justify-start whitespace-normal p-0 text-start text-[12px] sm:h-auto" disabled={pickerDisabled}+ onClick={() => {+ setError("");+ setDraft({ target: saved.previous, previous: current, revision: data.revision, message: job.payload.message });+ }}>{tx("changeBack", { chat: saved.previous.title })}</Button>+ ) : null}{loadError ? <Button variant="link" size="sm" onClick={() => setReload(value => value + 1)}>{tx("retry")}</Button> : null}{data && data.chats.length <= (current ? 1 : 0) ? <p className="text-[12px] leading-5 text-muted-foreground">{tx("available")}</p> : null}</div>);diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.jsonindex d566c610c..582d74dd1 100644--- a/webui/src/i18n/locales/en/common.json+++ b/webui/src/i18n/locales/en/common.json@@ -1395,6 +1395,7 @@},"automations": {"chat": {+ "changeBack": "Change back to “{{chat}}”","conflict": "The task changed elsewhere. Your draft is kept. Reopen the task to review the latest settings.","unavailable": "This chat is no longer available with the same workspace and access mode. Select another chat.","schedulerBusy": "A task is running or queued. Wait for it to finish, then try again.",diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.jsonindex 3e4009c6f..f45c165ca 100644--- a/webui/src/i18n/locales/es/common.json+++ b/webui/src/i18n/locales/es/common.json@@ -1196,6 +1196,7 @@},"automations": {"chat": {+ "changeBack": "Volver a «{{chat}}»","conflict": "La tarea cambió en otro lugar. Se conserva el borrador. Abre la tarea de nuevo para revisar los ajustes.","unavailable": "Este chat ya no está disponible con el mismo espacio de trabajo y modo de acceso. Elige otro chat.","schedulerBusy": "Hay una tarea en ejecución o en cola. Espera a que termine e inténtalo de nuevo.",diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.jsonindex d3ea45363..bafda39da 100644--- a/webui/src/i18n/locales/fr/common.json+++ b/webui/src/i18n/locales/fr/common.json@@ -1195,6 +1195,7 @@},"automations": {"chat": {+ "changeBack": "Revenir à « {{chat}} »","conflict": "La tâche a été modifiée ailleurs. Le brouillon est conservé. Rouvrez la tâche pour vérifier ses paramètres.","unavailable": "Cette discussion n’est plus disponible avec le même espace de travail et mode d’accès. Choisissez-en une autre.","schedulerBusy": "Une tâche est en cours ou en attente. Attendez la fin, puis réessayez.",diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.jsonindex 58167ba77..959946c8a 100644--- a/webui/src/i18n/locales/id/common.json+++ b/webui/src/i18n/locales/id/common.json@@ -1195,6 +1195,7 @@},"automations": {"chat": {+ "changeBack": "Kembali ke “{{chat}}”","conflict": "Tugas diubah di tempat lain. Draf disimpan. Buka ulang tugas untuk memeriksa pengaturan terbaru.","unavailable": "Chat ini tidak tersedia lagi dengan ruang kerja dan mode akses yang sama. Pilih chat lain.","schedulerBusy": "Ada tugas berjalan atau mengantre. Tunggu hingga selesai, lalu coba lagi.",diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.jsonindex 775696ca8..7c311465b 100644--- a/webui/src/i18n/locales/ja/common.json+++ b/webui/src/i18n/locales/ja/common.json@@ -1195,6 +1195,7 @@},"automations": {"chat": {+ "changeBack": "「{{chat}}」に戻す","conflict": "タスクが別の場所で変更されました。下書きは保持されています。タスクを開き直して最新の設定を確認してください。","unavailable": "このチャットは利用できないか、作業場所や権限が変わりました。別のチャットを選んでください。","schedulerBusy": "実行中または待機中のタスクがあります。完了後に再試行してください。",diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.jsonindex d4ce79e62..9cb023cf8 100644--- a/webui/src/i18n/locales/ko/common.json+++ b/webui/src/i18n/locales/ko/common.json@@ -1195,6 +1195,7 @@},"automations": {"chat": {+ "changeBack": "“{{chat}}”(으)로 되돌리기","conflict": "다른 곳에서 작업이 변경되었습니다. 초안은 유지됩니다. 작업을 다시 열어 최신 설정을 확인하세요.","unavailable": "이 채팅을 사용할 수 없거나 작업 공간 또는 권한이 변경되었습니다. 다른 채팅을 선택하세요.","schedulerBusy": "실행 중이거나 대기 중인 작업이 있습니다. 완료 후 다시 시도하세요.",diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.jsonindex 41ffc3076..bf8bc31ae 100644--- a/webui/src/i18n/locales/pt-BR/common.json+++ b/webui/src/i18n/locales/pt-BR/common.json@@ -1209,6 +1209,7 @@},"automations": {"chat": {+ "changeBack": "Voltar para “{{chat}}”","conflict": "A tarefa foi alterada em outro lugar. O rascunho foi mantido. Abra a tarefa novamente para conferir os ajustes.","unavailable": "Esta conversa não está mais disponível com o mesmo espaço de trabalho e modo de acesso. Escolha outra conversa.","schedulerBusy": "Há uma tarefa em execução ou na fila. Aguarde a conclusão e tente novamente.",diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.jsonindex d2b3ff228..2e5d441dd 100644--- a/webui/src/i18n/locales/vi/common.json+++ b/webui/src/i18n/locales/vi/common.json@@ -1195,6 +1195,7 @@},"automations": {"chat": {+ "changeBack": "Chuyển lại về “{{chat}}”","conflict": "Tác vụ đã được đổi ở nơi khác. Bản nháp được giữ lại. Mở lại tác vụ để kiểm tra cài đặt mới nhất.","unavailable": "Cuộc trò chuyện này không còn khả dụng với cùng không gian làm việc và quyền truy cập. Hãy chọn cuộc trò chuyện khác.","schedulerBusy": "Có tác vụ đang chạy hoặc chờ. Hãy đợi hoàn tất rồi thử lại.",diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.jsonindex bd211da79..52ddb2006 100644--- a/webui/src/i18n/locales/zh-CN/common.json+++ b/webui/src/i18n/locales/zh-CN/common.json@@ -1395,6 +1395,7 @@},"automations": {"chat": {+ "changeBack": "改回「{{chat}}」","conflict": "任务已在别处修改,草稿已保留。请重新打开任务,核对最新设置后再更换。","unavailable": "这个聊天已不可用,或工作目录、权限已改变。请选择其他聊天。","schedulerBusy": "有任务正在执行或排队。请等任务结束后再试。",diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.jsonindex c5cb17631..de75fc4a3 100644--- a/webui/src/i18n/locales/zh-TW/common.json+++ b/webui/src/i18n/locales/zh-TW/common.json@@ -1195,6 +1195,7 @@},"automations": {"chat": {+ "changeBack": "改回「{{chat}}」","conflict": "任務已在別處修改,草稿已保留。請重新開啟任務,確認最新設定後再更換。","unavailable": "這個聊天已無法使用,或工作目錄、權限已變更。請選擇其他聊天。","schedulerBusy": "有任務正在執行或排隊。請等任務結束後再試。",diff --git a/webui/src/tests/automation-chat-binding.test.tsx b/webui/src/tests/automation-chat-binding.test.tsxindex d0afb0002..fda25a9b3 100644--- a/webui/src/tests/automation-chat-binding.test.tsx+++ b/webui/src/tests/automation-chat-binding.test.tsx@@ -3,6 +3,7 @@ import userEvent from "@testing-library/user-event";import { afterEach, beforeEach, expect, it, vi } from "vitest";import { AutomationDetailDialog } from "@/components/settings/system/AutomationsSettings";import { fetchAutomationChats } from "@/lib/api";+import { setAppLanguage } from "@/i18n";import type { AutomationChatsPayload, SessionAutomationJob } from "@/lib/types";vi.mock("@/lib/api", () => ({ fetchAutomationChats: vi.fn() }));@@ -53,6 +54,40 @@ it("keeps the original route until acknowledgement and saves the reviewed promptawait act(async () => refresh({ ...choices, current: target, revision: "rev-2" }));expect(screen.getByRole("combobox", { name: "Run and reply in" })).toHaveFocus();expect(props.onAction).not.toHaveBeenCalled();+ await user.click(screen.getByRole("button", { name: "Change back to “My planning”" }));+ expect(save).toHaveBeenCalledTimes(1);+ expect(screen.getByRole("group", { name: "Now" })).toHaveTextContent("Product team");+ expect(screen.getByRole("combobox", { name: "Change to" })).toHaveTextContent("My planning");+ await user.click(screen.getByRole("button", { name: "Cancel" }));+ expect(screen.getByRole("combobox", { name: "Run and reply in" })).toHaveTextContent("Product team");+ await user.click(screen.getByRole("button", { name: "Change back to “My planning”" }));+ await user.click(screen.getByRole("button", { name: "Confirm change" }));+ expect(save.mock.calls[1]).toEqual([+ expect.objectContaining({ chat_binding_revision: "rev-2" }),+ { target_id: "source", revision: "rev-2", message: job.payload.message },+ ]);+ await act(async () => finish());+});++it("uses Chinese for the task menu and the change/cancel path", async () => {+ await setAppLanguage("zh-CN");+ const user = userEvent.setup();+ const save = vi.fn();+ render(<AutomationDetailDialog {...props} locale="zh-CN" job={job} onChangeChat={save} />);+ await user.click(screen.getByRole("button", { name: "更多操作" }));+ expect(screen.getByRole("menuitem", { name: "停用" })).toBeInTheDocument();+ expect(screen.getByRole("menuitem", { name: "删除" })).toBeInTheDocument();+ await user.keyboard("{Escape}");+ const picker = screen.getByRole("combobox", { name: "运行与回复" });+ await waitFor(() => expect(picker).toBeEnabled());+ fireEvent.keyDown(picker, { key: "ArrowDown" });+ await user.click(await screen.findByRole("option", { name: /Product team/ }));+ expect(screen.getByRole("heading", { name: "更换聊天" })).toBeInTheDocument();+ expect(screen.getByRole("button", { name: "确认并更换" })).toBeInTheDocument();+ await user.click(screen.getByRole("button", { name: "取消" }));+ expect(screen.getByRole("heading", { name: "Daily report" })).toBeInTheDocument();+ expect(screen.getByRole("combobox", { name: "运行与回复" })).toHaveFocus();+ expect(save).not.toHaveBeenCalled();});it("cancels a chat change without saving the edited instructions", async () => {