From 288cd7bf793a4e5eaa4b32b47cb26f69eab1b12d Mon Sep 17 00:00:00 2001 From: 134 Date: Sat, 1 Aug 2026 10:33:49 +0800 Subject: [PATCH] fix(claw): prevent sent text returning to composer --- components/canvas/CanvasChatPanel.tsx | 33 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index a8a080001..bff96deab 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -404,6 +404,7 @@ const CLAWD_TABLE_MAX_BYTES = 10 * 1024 * 1024; const CLAWD_PROCESSING_HINT = "已收到,这个任务稍微繁重一些,处理时间可能会长一点,请耐心等候。"; const CLAWD_SUBMITTED_COMPOSER_RECOVERY_TTL_MS = 30 * 60 * 1000; +const CLAWD_SUBMITTED_COMPOSER_POST_SEND_GUARD_TTL_MS = 15 * 1000; const CLAWD_SUBMITTED_COMPOSER_RESTORE_GUARD_DELAYS_MS = [ 0, 80, 180, 360, 700, 1200, 2000, 3500, 6000, 10000, ]; @@ -11681,6 +11682,7 @@ export function CanvasChatPanel({ clearSelection(); } + let clawdRequestAccepted = false; try { const formData = new FormData(); formData.append("id", rawChatId); @@ -11714,6 +11716,7 @@ export function CanvasChatPanel({ body: formData, signal: clawdAbortController.signal, }); + clawdRequestAccepted = response.ok; const responseData = await readClawdResponse(response, (progress) => { const display = String( progress.display || progress.message || "" @@ -11801,6 +11804,14 @@ export function CanvasChatPanel({ } console.error("[CanvasChat] Claw request failed:", error); pendingClawdSubmissionRef.current = null; + if (clawdRequestAccepted) { + toast.error("Claw 连接中断,已保留已发送消息;任务可能仍在处理中,请稍后刷新历史查看"); + void mutateClawdHistory(); + if (rawChatId) { + void mutate(buildHistoryMessagesUrl(rawChatId, { cacheBust: true })); + } + return; + } if (recentClawdSubmissionRef.current === clawdSubmissionSnapshot) { recentClawdSubmissionRef.current = null; writeStoredClawdComposerSubmissionSnapshot(null); @@ -11853,12 +11864,22 @@ export function CanvasChatPanel({ recentClawdSubmissionRef.current = null; writeStoredClawdComposerSubmissionSnapshot(null); } else { - const refreshedSubmissionSnapshot = { - ...clawdSubmissionSnapshot, - expiresAt: Date.now() + CLAWD_SUBMITTED_COMPOSER_RECOVERY_TTL_MS, - }; - recentClawdSubmissionRef.current = refreshedSubmissionSnapshot; - writeStoredClawdComposerSubmissionSnapshot(refreshedSubmissionSnapshot); + const refreshedSubmissionSnapshot = { + ...clawdSubmissionSnapshot, + expiresAt: + Date.now() + CLAWD_SUBMITTED_COMPOSER_POST_SEND_GUARD_TTL_MS, + }; + recentClawdSubmissionRef.current = refreshedSubmissionSnapshot; + writeStoredClawdComposerSubmissionSnapshot(refreshedSubmissionSnapshot); + scheduleClearRestoredClawdComposerText(); + if (typeof window !== "undefined") { + window.setTimeout(() => { + if (recentClawdSubmissionRef.current === refreshedSubmissionSnapshot) { + recentClawdSubmissionRef.current = null; + writeStoredClawdComposerSubmissionSnapshot(null); + } + }, CLAWD_SUBMITTED_COMPOSER_POST_SEND_GUARD_TTL_MS); + } } } setIsClawdSubmitting(false);