From 572757b933ce974e45a6b324beb4ad149c2c3324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E4=B8=AB=E8=AE=B2=E6=A2=B5?= Date: Sat, 26 Sep 2026 21:46:05 +0800 Subject: [PATCH] feat(ai): confirm before resending a chat message --- .../src/components/editor/AiAssistant.vue | 53 ++++++++++++++++++- apps/desktop/src/i18n/locales/az.ts | 2 + apps/desktop/src/i18n/locales/en.ts | 2 + apps/desktop/src/i18n/locales/es.ts | 2 + apps/desktop/src/i18n/locales/it.ts | 2 + apps/desktop/src/i18n/locales/ja.ts | 2 + apps/desktop/src/i18n/locales/ko.ts | 2 + apps/desktop/src/i18n/locales/pt-BR.ts | 2 + apps/desktop/src/i18n/locales/ru.ts | 2 + apps/desktop/src/i18n/locales/tr.ts | 2 + apps/desktop/src/i18n/locales/zh-CN.ts | 2 + apps/desktop/src/i18n/locales/zh-TW.ts | 2 + .../lib/__tests__/ai/aiMessageEdit.spec.ts | 26 ++++++++- apps/desktop/src/lib/ai/aiMessageEdit.ts | 20 +++++++ 14 files changed, 118 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vue index 7a7f64503c..e5c60b928d 100644 --- a/apps/desktop/src/components/editor/AiAssistant.vue +++ b/apps/desktop/src/components/editor/AiAssistant.vue @@ -178,7 +178,7 @@ import { DBX_TABLE_REFERENCE_DROP_EVENT, clearActiveTableReferencePayload } from import { canSubmitAiPrompt, isAiPromptImeCompositionEvent, shouldSubmitAiPromptOnKeydown } from "@/lib/ai/aiPromptKeyboard"; import { isActionableWriteProposalMessage, isActionableWriteSqlProposal, looksLikeActionProposal, looksLikeWriteSqlProposal, shouldGrantWriteSqlOnShortAffirmative } from "@/lib/ai/aiProposalDetect"; import { classifyIntentByLlm, routeIntentByRules, type AiIntentRouteInput } from "@/lib/ai/aiIntentRouter"; -import { visibleToActualIndex } from "@/lib/ai/aiMessageEdit"; +import { retryableUserMessageIndex, visibleToActualIndex } from "@/lib/ai/aiMessageEdit"; import { shouldShowReasoningCharCount, reasoningCharCountClass } from "@/lib/ai/aiReasoningPresentation"; import { saveTextFile } from "@/lib/export/saveTextFile"; import { buildAiAnalysisExport } from "@/lib/export/aiAnalysisExport"; @@ -4285,6 +4285,37 @@ function canCopyMessage(msg: ChatMessage): boolean { return messageCopyText(msg) !== null; } +/** Returns whether a user message can be submitted again. The helper accepts + * the following visible index so the same eligibility rules cover text, + * mentions, and attachment-only requests. */ +function canRetryUserMessage(visibleIndex: number): boolean { + return retryableUserMessageIndex(visibleMessages.value, visibleIndex + 1) === visibleIndex; +} + +/** Re-runs a user request through the existing edit-and-resend path. This + * removes the selected turn and later replies before sending with the current + * AI configuration. */ +function retryUserMessage(visibleIndex: number) { + if (isGenerating.value) return; + if (!canRetryUserMessage(visibleIndex)) return; + startEditMessage(visibleIndex); + submitEdit(visibleIndex); +} + +const retryConfirmMessageIndex = ref(null); + +function cancelRetryUserMessage() { + retryConfirmMessageIndex.value = null; +} + +function confirmRetryUserMessage() { + const visibleIndex = retryConfirmMessageIndex.value; + retryConfirmMessageIndex.value = null; + if (visibleIndex !== null) retryUserMessage(visibleIndex); +} + +watch(conversationId, cancelRetryUserMessage); + function messageCopyKey(index: number): string { return `message:${index}`; } @@ -5620,8 +5651,26 @@ async function openExternalUrl(url: string) { {{ t("ai.routing.chip", { action: actionLabelFor(routedActionOf(msg)) }) }} -
+
+ + + + + +

+ + {{ t("ai.retryConfirmDescription") }} +

+
+ + +
+
+