fix(webui): let users review a return to the previous task chat
This commit is contained in:
1 parent
ab614478a0
commit
61ab136e58
14 files changed
+62
-4
No files matched your search
@@ -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. Previous
|
||||
messages stay in their original chat. Previous run results remain available.
|
||||
Changing the chat does not run the task, enable it, or change its schedule.
|
||||
|
||||
@@ -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.description
|
||||
assert "generate_image creates images in the current chat" in tool.description
|
||||
assert (
|
||||
"Do not use this for a normal reply in the current chat"
|
||||
|
||||
@@ -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>);
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -1195,6 +1195,7 @@
|
||||
},
|
||||
"automations": {
|
||||
"chat": {
|
||||
"changeBack": "「{{chat}}」に戻す",
|
||||
"conflict": "タスクが別の場所で変更されました。下書きは保持されています。タスクを開き直して最新の設定を確認してください。",
|
||||
"unavailable": "このチャットは利用できないか、作業場所や権限が変わりました。別のチャットを選んでください。",
|
||||
"schedulerBusy": "実行中または待機中のタスクがあります。完了後に再試行してください。",
|
||||
|
||||
@@ -1195,6 +1195,7 @@
|
||||
},
|
||||
"automations": {
|
||||
"chat": {
|
||||
"changeBack": "“{{chat}}”(으)로 되돌리기",
|
||||
"conflict": "다른 곳에서 작업이 변경되었습니다. 초안은 유지됩니다. 작업을 다시 열어 최신 설정을 확인하세요.",
|
||||
"unavailable": "이 채팅을 사용할 수 없거나 작업 공간 또는 권한이 변경되었습니다. 다른 채팅을 선택하세요.",
|
||||
"schedulerBusy": "실행 중이거나 대기 중인 작업이 있습니다. 완료 후 다시 시도하세요.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -1395,6 +1395,7 @@
|
||||
},
|
||||
"automations": {
|
||||
"chat": {
|
||||
"changeBack": "改回「{{chat}}」",
|
||||
"conflict": "任务已在别处修改,草稿已保留。请重新打开任务,核对最新设置后再更换。",
|
||||
"unavailable": "这个聊天已不可用,或工作目录、权限已改变。请选择其他聊天。",
|
||||
"schedulerBusy": "有任务正在执行或排队。请等任务结束后再试。",
|
||||
|
||||
@@ -1195,6 +1195,7 @@
|
||||
},
|
||||
"automations": {
|
||||
"chat": {
|
||||
"changeBack": "改回「{{chat}}」",
|
||||
"conflict": "任務已在別處修改,草稿已保留。請重新開啟任務,確認最新設定後再更換。",
|
||||
"unavailable": "這個聊天已無法使用,或工作目錄、權限已變更。請選擇其他聊天。",
|
||||
"schedulerBusy": "有任務正在執行或排隊。請等任務結束後再試。",
|
||||
|
||||
@@ -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 prompt
|
||||
await 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 () => {
|
||||
|
||||
Reference in new issue
Block a user