From ed39bf9e2c95bf44c30daa32f84cf5d7fa3b7e58 Mon Sep 17 00:00:00 2001 From: Jafeng <2998840497@qq.com> Date: Sat, 23 Aug 2025 17:07:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=9A=E8=AF=9D=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E4=BC=98=E5=8C=96=E5=A4=B4=E5=83=8F=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/routes/chat.ts | 9 ++++-- frontend/src/App.vue | 19 +++++++++--- frontend/src/stores/conversationStore.ts | 37 ++++++++++++++++++++---- frontend/vite.config.ts | 2 +- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/backend/src/routes/chat.ts b/backend/src/routes/chat.ts index 7274e29..52d6c27 100644 --- a/backend/src/routes/chat.ts +++ b/backend/src/routes/chat.ts @@ -69,9 +69,12 @@ router.post('/chat/stream', auth(false), async (req: AuthRequest, res: Response) router.post('/conversations', auth(), async (req: AuthRequest, res: Response) => { try { - const { modelId, messages, title } = req.body; - const conv = await Conversation.create({ userId: req.userId, modelId, messages, title }); - res.json(conv); + const { modelId, messages, title } = req.body; + // clean messages: remove system/transient or empty entries + const cleaned = (messages||[]).filter((m:any)=>m && typeof m.content==='string' && m.content.trim().length>0); + const computedTitle = title || (cleaned?.[0]?.content ? String(cleaned[0].content).slice(0, 60) : '新对话'); + const conv = await Conversation.create({ userId: req.userId, modelId, messages: cleaned, title: computedTitle }); + res.json(conv); } catch (e:any) { res.status(500).json({ error: e.message }); } diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 167e371..03d2c66 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -11,7 +11,7 @@