From b7eabb1b11be380155ade8853dbe72e728a8cbb6 Mon Sep 17 00:00:00 2001 From: kicer Date: Wed, 22 Jul 2026 18:03:15 +0800 Subject: [PATCH] fix issues --- server/ai/prompt.js | 2 +- server/handlers.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/ai/prompt.js b/server/ai/prompt.js index 41e6498..f13b17f 100644 --- a/server/ai/prompt.js +++ b/server/ai/prompt.js @@ -28,7 +28,7 @@ function buildSystemPrompt(username, isAdmin) { const attachmentRules = ` ⚠️ 附件规则: - 图片+物品名("这是XX的图片")→ 只返回 purchase_item,绝对不要 is_new/quantity/unit_price -- 引用历史图片("上面/前面/刚刚那张""存入附件/添加到附件/关联到")→ use_recent_image: true,**同时必须提供** purchase_item +- 引用历史图片("上面/前面/刚刚那张""存入附件/添加到附件/加到XX的附件/关联到")→ use_recent_image: true,**同时必须提供** purchase_item - 纯图片+物品名不是新建采购,系统自动关联附件`; const prohibitionRules = ` diff --git a/server/handlers.js b/server/handlers.js index 1ac2a86..f162da7 100644 --- a/server/handlers.js +++ b/server/handlers.js @@ -125,6 +125,17 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) { } catch(e) { console.error('❌ 解析附件失败:', e); } } } + // 安全网:消息提到图片/附件但没带附件 → AI 忘设 use_recent_image,自动补 + if (!usedRecentImage && !attachments?.length && /(图片|附件|加到|存入|关联|作为附件)/.test(originalText)) { + console.log('🔍 安全网: 文本提及附件但无附件,自动尝试 use_recent_image'); + const recentMsg = db.prepare("SELECT attachments FROM messages WHERE room_id = ? AND attachments IS NOT NULL AND attachments != '' AND attachments != '[]' ORDER BY id DESC LIMIT 1").get(roomId); + if (recentMsg) { + try { + const files = JSON.parse(recentMsg.attachments); + if (files.length) { attachments = files; usedRecentImage = true; console.log('✅ 安全网引用图片:', files.length, '个'); } + } catch(e) {} + } + } const createdTime = normalizeTime(aiResult.created_time); let isNew = aiResult.is_new === true;