fix: Gemini 图片生成流程添加智能对话回复

- 在 Gemini/Huanke-Gemini 图片生成流程中添加 conversationalReply 发送逻辑
- 与 Alibaba 图片生成流程保持一致
- 确保无限画布中的智能自动模式能显示 AI 对话回复
This commit is contained in:
Your Name 2026-02-02 00:43:57 +08:00
parent dd0b8e7357
commit 8ff91edb11

View File

@ -752,6 +752,46 @@ export async function POST(request: Request) {
const geminiStream = createUIMessageStream({
execute: async ({ writer }) => {
// 🆕 如果是智能模式且有对话回复,先发送对话消息让用户看到
// 在消息末尾加上特殊标记,告诉前端"图片正在生成中"
const messageWithMarker = smartAutoFriendlyMessage
? `${smartAutoFriendlyMessage}\n\n<!-- GENERATING_IMAGE -->`
: null;
if (messageWithMarker) {
const chatMessageId = generateUUID();
console.log("[Chat API] 💬 Gemini: Sending conversational reply first:", smartAutoFriendlyMessage);
// 发送带标记的对话消息
writer.write({
type: "data-appendMessage",
data: JSON.stringify({
id: chatMessageId,
role: "assistant",
parts: [{ type: "text", text: messageWithMarker }],
}),
});
// 保存对话消息到数据库(不带标记,纯对话)
await saveMessages({
messages: [
{
id: chatMessageId,
chatId: id,
role: "assistant",
parts: [{ type: "text", text: smartAutoFriendlyMessage }],
attachments: [],
createdAt: new Date(),
videoStorageStatus: null,
temporaryVideoUrl: null,
permanentVideoUrl: null,
archivedAt: null,
videoMetadata: null,
},
],
});
}
// 🆕 尝试生成图片的函数(支持备用模型切换)
const tryGenerateImage = async (modelIdToUse: string, isRetry = false): Promise<string> => {
console.log(`[Chat API] ${isRetry ? "🔄 Retry with fallback" : "🚀 Trying"} model: ${modelIdToUse}`);