From 339bf9101926043d8e044e412ba5f4094a22c6dd Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 1 Feb 2026 12:22:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=94=BB=E5=B8=83?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E9=9D=A2=E6=9D=BF=E5=8F=91=E9=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复 handleSend 中 parts 数组的顺序(文件在前,文本在后) 2. 添加 videoParams: undefined 确保 schema 兼容 3. 添加调试日志帮助排查问题 Co-authored-by: Cursor --- components/canvas/CanvasChatPanel.tsx | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index 16cb278..eae230d 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -153,13 +153,20 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF api: "/api/chat", fetch: fetchWithErrorHandlers, prepareSendMessagesRequest(request) { + console.log("[CanvasChat] Preparing request:", { + id: request.id, + modelId: currentModelIdRef.current, + imageParams: imageParamsRef.current, + lastMessage: request.messages.at(-1), + }); return { body: { id: request.id, message: request.messages.at(-1), selectedChatModel: currentModelIdRef.current, selectedVisibilityType: "private", - imageParams: imageParamsRef.current, // 传递图片参数 + videoParams: undefined, // 必须传递,即使是 undefined + imageParams: imageParamsRef.current || undefined, // 传递图片参数 ...request.body, }, }; @@ -252,31 +259,28 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF return; } - // 构建 parts 数组:文本 + 文件 + // 构建 parts 数组:文件在前,文本在后(与 multimodal-input 一致) const parts: any[] = []; - // 添加文本部分 - if (input.trim()) { - parts.push({ type: "text", text: input }); - } - // 添加文件部分(作为 file 类型的 part) attachments.forEach(a => { parts.push({ - type: "file", + type: "file" as const, mediaType: a.contentType, name: a.name, url: a.url, }); }); - // 如果没有文本但有附件,添加一个空的文本提示 - if (!input.trim() && attachments.length > 0) { - parts.unshift({ type: "text", text: "请处理这张图片" }); + // 添加文本部分 + const textContent = input.trim() || (attachments.length > 0 ? "请处理这张图片" : ""); + if (textContent) { + parts.push({ type: "text" as const, text: textContent }); } + // 使用与 multimodal-input 相同的格式发送消息 sendMessage({ - role: "user" as const, + role: "user", parts: parts, });