AI界面样式参考元宝

This commit is contained in:
2025-11-28 17:31:56 +08:00
parent 89c9712c9c
commit 9415af337c
4 changed files with 608 additions and 336 deletions

View File

@@ -729,24 +729,35 @@ app.get("/sessions", async (req, res) => {
// `,
// [userId]
// );
const [rows] = await pool.query(`
SELECT m.session_id, m.title
FROM ai_chat_messages m
INNER JOIN (
SELECT session_id, MAX(created_at) AS last_time
FROM ai_chat_messages
WHERE user_id = ?
GROUP BY session_id
) t ON m.session_id = t.session_id AND m.created_at = t.last_time
WHERE m.user_id = ?
ORDER BY t.last_time ASC
`, [userId, userId]);
// const [rows] = await pool.query(`
// SELECT m.session_id, m.title
// FROM ai_chat_messages m
// INNER JOIN (
// SELECT session_id, MAX(created_at) AS last_time
// FROM ai_chat_messages
// WHERE user_id = ?
// GROUP BY session_id
// ) t ON m.session_id = t.session_id AND m.created_at = t.last_time
// WHERE m.user_id = ?
// ORDER BY t.last_time ASC
// `, [userId, userId]);
const [rows] = await pool.query(`
SELECT session_id, title
FROM ai_chat_messages
WHERE user_id = ?
AND title IS NOT NULL
AND title != ''
GROUP BY session_id
ORDER BY MIN(created_at) ASC
`, [userId]);
res.json({
code: 0,
userId,
sessions: rows.map((r) => ({ sessId: r.session_id, title: r.title })), // 只返回 session_id 列表
});
res.json({
code: 0,
sessions: rows.map(r => ({
sessId: r.session_id,
title: r.title
}))
});
}
catch (err)
{