diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index 144ec0b58..5afef8612 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -2066,6 +2066,7 @@ export function CanvasChatPanel({ const detailModeSwitchRef = useRef(false); const hiddenPromptRef = useRef(null); const autoContextRef = useRef(null); + const contextPayloadRef = useRef(null); const lastWorkflowAutofillSignatureRef = useRef(null); const lastWorkflowAutofillUrlsRef = useRef([]); const pendingLaunchRef = useRef(null); @@ -4561,25 +4562,27 @@ export function CanvasChatPanel({ ? request.id.replace('canvas-', '') : request.id; + const capturedContextPayload = contextPayloadRef.current ?? buildContextPayload(); console.log("[CanvasChat] Preparing request:", { id: rawId, modelId: currentModelIdRef.current, composerMode: activeComposerModeRef.current, agentEntryMode: agentEntryModeRef.current, imageParams: imageParamsRef.current, - contextPayload: buildContextPayload(), + contextPayload: capturedContextPayload, lastMessage: request.messages.at(-1), }); const effectiveComposerMode = activeComposerModeRef.current || activeComposerMode; const effectiveAgentEntryMode = agentEntryModeRef.current; const hiddenPrompt = hiddenPromptRef.current || undefined; const autoContext = autoContextRef.current || undefined; - const contextPayload = buildContextPayload(); + const contextPayload = capturedContextPayload; const requestModel = allModels.find((model) => model.id === currentModelIdRef.current); const requestIsVideoModel = isCanvasVideoModel(requestModel); const requestIsConversationModel = isCanvasConversationOnlyModel(requestModel); hiddenPromptRef.current = null; autoContextRef.current = null; + contextPayloadRef.current = null; return { body: { id: rawId, @@ -8284,6 +8287,7 @@ export function CanvasChatPanel({ const autoContext = buildAutoContext(); autoContextRef.current = clampChatRequestText(autoContext, MAX_CHAT_AUTO_CONTEXT_LENGTH) || null; + contextPayloadRef.current = buildContextPayload() || null; if (textContent) { parts.push({ type: "text" as const, text: textContent }); @@ -8328,6 +8332,7 @@ export function CanvasChatPanel({ }); } catch (error) { releaseSendGuard(activeChatId); + contextPayloadRef.current = null; console.error("[CanvasChat] sendMessage failed:", error); toast.error("发送失败,请重试"); return;