fix: preserve canvas context for chat image results
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-04-29 16:25:51 +08:00
parent 979c960359
commit 166cc184d1

View File

@ -2066,6 +2066,7 @@ export function CanvasChatPanel({
const detailModeSwitchRef = useRef(false);
const hiddenPromptRef = useRef<string | null>(null);
const autoContextRef = useRef<string | null>(null);
const contextPayloadRef = useRef<any>(null);
const lastWorkflowAutofillSignatureRef = useRef<string | null>(null);
const lastWorkflowAutofillUrlsRef = useRef<string[]>([]);
const pendingLaunchRef = useRef<CanvasLaunchPayload | null>(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;