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, });