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 @@