设置页改密码(prompt弹窗,免原密码,立即生效);上传附件改为随下一条消息统一告知AI
This commit is contained in:
@@ -63,17 +63,7 @@ router.post('/:id/files', upload.array('files', 10), function (req, res) {
|
||||
db.prepare('INSERT INTO files (session_id, filename, size, created_at) VALUES (?,?,?,?)')
|
||||
.run(req.params.id, f.filename, f.size, Date.now());
|
||||
}
|
||||
// 主动告知 AI:文件名、大小以单行随上传送达会话(live/held/queued 都能送达)。
|
||||
// 附任务目录绝对路径、明确无需列目录验证与确认回复,减少 AI 多余探索;通知失败不影响上传本身。
|
||||
if (uploaded.length) {
|
||||
try {
|
||||
const dir = engine.taskDirOf(req.params.id);
|
||||
const list = uploaded.map(f => f.filename + '(' + f.size + ' 字节)').join(';');
|
||||
engine.postUserMessage(req.params.id,
|
||||
'【系统通知】用户刚通过页面上传了 ' + uploaded.length + ' 个文件,已存在于任务目录 ' + dir + ' 中:' + list +
|
||||
'。文件已确认存在,无需再列目录或读取验证;无需为确认收到而回复,除非用户另有诉求。');
|
||||
} catch (e) { console.warn('[files] 上传通知 AI 失败:', e && e.message || e); }
|
||||
}
|
||||
// 不再自动通知 AI:附件随用户下一条消息统一告知(见 routes/messages.js 的 attachments)
|
||||
res.json({ uploaded });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: String(err && err.message || err) });
|
||||
|
||||
@@ -14,8 +14,31 @@ function wrap(fn) {
|
||||
};
|
||||
}
|
||||
|
||||
// 附件提示词:用户带附件发消息时,服务端在正文前拼一行系统通知,
|
||||
// 与消息一并落库(历史重建时 AI 能看到)。格式:
|
||||
// 【系统通知】用户上传了文件:a.png(大小 1.2 MB)、b.txt(大小 3 KB)
|
||||
// <用户原文>
|
||||
function fmtSize(n) {
|
||||
n = Number(n) || 0;
|
||||
if (n < 1024) return n + ' B';
|
||||
if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB';
|
||||
if (n < 1024 * 1024 * 1024) return (n / 1024 / 1024).toFixed(1) + ' MB';
|
||||
return (n / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
||||
}
|
||||
function composeWithAttachments(content, attachments) {
|
||||
if (!Array.isArray(attachments) || !attachments.length) return content;
|
||||
const list = attachments.slice(0, 20).map(a =>
|
||||
String(a && a.name || 'file').slice(0, 200) + '(大小 ' + fmtSize(a && a.size) + ')'
|
||||
).join('、');
|
||||
const notice = '【系统通知】用户上传了文件:' + list;
|
||||
return content ? notice + '\n' + content : notice;
|
||||
}
|
||||
|
||||
router.post('/:id/messages', wrap((req, res) => {
|
||||
const content = String((req.body && req.body.content) || '').trim();
|
||||
const content = composeWithAttachments(
|
||||
String((req.body && req.body.content) || '').trim(),
|
||||
req.body && req.body.attachments
|
||||
);
|
||||
if (!content) return res.status(400).json({ error: 'content 不能为空' });
|
||||
const r = engine.postUserMessage(req.params.id, content);
|
||||
res.json(r);
|
||||
|
||||
Reference in New Issue
Block a user