返回 DeepSeek-Reasonix
topicRemovalCommand.ts
根目录 / desktop / frontend / src / lib / topicRemovalCommand.ts
1 import { app } from "./bridge";
2 import type { Translator } from "./i18n";
3 import type { TopicRemovalInspection, TopicRemovalRequest } from "../generated/desktopContract.generated";
4
5 // Loaded only when the user removes a legacy topic. Retries retain the original
6 // confirmation even when a partial write has already removed the sidebar row.
7 export async function removeProjectTopic(topicId: string, inspect: (id: string) => Promise<TopicRemovalInspection>, requests: Map<string, TopicRemovalRequest>, t: Translator): Promise<void | false> {
8 let request = requests.get(topicId);
9 if (!request) {
10 const view = await inspect(topicId);
11 if (!view.allowed) throw new Error(t(view.reason === "busy" ? "projectTree.sessionError.operationBusy" : "projectTree.sessionError.failed") + (view.reason && view.reason !== "busy" ? `: ${view.reason}` : ""));
12 if (view.disposition !== "discard_placeholder" && !await app.ConfirmAction({
13 title: t("history.moveToTrash"), message: t("history.confirmMoveToTrash"),
14 detail: t("history.archiveExplanation"), confirmLabel: t("history.moveToTrash"), cancelLabel: t("common.cancel"), destructive: true,
15 })) return false;
16 request = { operationId: crypto.randomUUID(), target: view.target, expectedToken: view.token };
17 requests.set(topicId, request);
18 }
19 const result = await app.RemoveTopic(request);
20 if (!result.committed) {
21 if (result.errorCode === "state_conflict") requests.delete(topicId);
22 throw new Error(t(result.errorCode === "state_conflict" ? "projectTree.sessionError.targetChanged" : result.errorCode === "busy" ? "projectTree.sessionError.operationBusy" : "history.purgePending") + (result.errorCode === "operation_failed" && result.errorMessage ? `: ${result.errorMessage}` : ""));
23 }
24 requests.delete(topicId);
25 }
26
26 lines TYPESCRIPT