Files
OpenCode 68a9071cf1 feat: reconcile local master with origin (exa/hot-platform hunters, leaks ledger, latest results)
Local branch had diverged from origin/master (sibling commits on the same base). Rewrote local history linearly on top of origin/master, folding in all local content: exa/hot-platform discovery hunters, leaks ledger, nightly sweep orchestrator, updated .gitignore and skill docs, plus the latest hunt output and vault state. Remote-only files (vault keys, channel scripts) were restored rather than dropped, so the resulting tree is a full union of both sides.
2026-08-07 12:53:47 +08:00

1 line
5.3 KiB
JSON

{"repo": "ask0730/lvyexianzong", "files": {"web-server/controllers/web/ChatController.js": {"2abe477789182334b667ed795df00bcff4c76bc5": {"t": 1786068459.834326, "n": 4574, "h": "0b4b066d505adeb7", "c": "const ChatModel = require('../../models/ChatModel');\nconst axios = require('axios');\n\nclass ChatController {\n // 创建新的对话\n async createChat(req, res) {\n try {\n const userId = req.user._id;\n const chat = new ChatModel({ userId });\n await chat.save();\n res.json({ code: 0, data: chat });\n } catch (error) {\n res.json({ code: -1, msg: '创建对话失败' });\n }\n }\n\n // 发送消息并获取AI回复\n async sendMessage(req, res) {\n try {\n const { chatId, message } = req.body;\n const userId = req.user._id;\n\n const chat = await ChatModel.findOne({ _id: chatId, userId });\n if (!chat) {\n return res.json({ code: -1, msg: '对话不存在' });\n }\n\n // 添加用户消息\n chat.messages.push({\n role: 'user',\n content: message\n });\n\n // 调用DeepSeek API\n const response = await axios.post('https://api.openrouter.ai/api/v1/chat/completions', {\n model: 'deepseek-chat',\n messages: [\n {\n role: 'system',\n content: '你是绿野仙踪团队的专业农业科技客服。请以亲切专业的态度为客户提供服务,重点关注:\\n1. 农业技术咨询:种植技术、病虫害防治、土壤改良等\\n2. 生态农业解决方案:有机种植、生态循环、绿色农业等\\n3. 农业科技产品介绍:智能灌溉、农业物联网等\\n请使用专业但平易近人的语气,确保回答准确且易于理解。'\n },\n ...chat.messages.map(msg => ({\n role: msg.role,\n content: msg.content\n }))\n ],\n temperature: 0.5,\n max_tokens: 1000,\n top_p: 0.8,\n frequency_penalty: 0.1,\n presence_penalty: 0.1\n }, {\n headers: {\n 'Authorization': `Bearer ${process.env.OPENROUTER_API_KEY}`,\n 'Content-Type': 'application/json'\n },\n timeout: 30000\n });\n\n // 添加AI回复\n const aiResponse = response.data.choices[0].message.content;\n chat.messages.push({\n role: 'assistant',\n content: aiResponse\n });\n\n await chat.save();\n res.json({ code: 0, data: { message: aiResponse } });\n } catch (error) {\n console.error('AI回复错误:', error);\n let errorMessage = '获取AI回复失败';\n if (error.response) {\n if (error.response.status === 429) {\n errorMessage = '服务繁忙,请稍后再试';\n } else if (error.response.status === 401) {\n errorMessage = 'API认证失败,请联系管理员';\n }\n } else if (error.code === 'ECONNABORTED') {\n errorMessage = '请求超时,请重试';\n }\n res.json({ code: -1, msg: errorMessage });\n }\n }\n\n // 获取对话历史\n async getChatHistory(req, res) {\n try {\n const userId = req.user._id;\n const { chatId } = req.params;\n\n const chat = await ChatModel.findOne({ _id: chatId, userId });\n if (!chat) {\n return res.json({ code: -1, msg: '对话不存在' });\n }\n\n res.json({ code: 0, data: chat });\n } catch (error) {\n res.json({ code: -1, msg: '获取对话历史失败' });\n }\n }\n\n // 获取用户的所有对话列表\n async getChatList(req, res) {\n try {\n const userId = req.user._id;\n const chats = await ChatModel.find({ userId })\n .select('_id createdAt updatedAt')\n .sort({ updatedAt: -1 });\n\n res.json({ code: 0, data: chats });\n } catch (error) {\n res.json({ code: -1, msg: '获取对话列表失败' });\n }\n }\n\n // 删除对话\n async deleteChat(req, res) {\n try {\n const userId = req.user._id;\n const { chatId } = req.params;\n\n const result = await ChatModel.deleteOne({ _id: chatId, userId });\n if (result.deletedCount === 0) {\n return res.json({ code: -1, msg: '对话不存在或无权删除' });\n }\n\n res.json({ code: 0, msg: '删除成功' });\n } catch (error) {\n res.json({ code: -1, msg: '删除对话失败' });\n }\n }\n}\n\nconst controller = new ChatController();\nmodule.exports = {\n createChat: controller.createChat.bind(controller),\n sendMessage: controller.sendMessage.bind(controller),\n getChatHistory: controller.getChatHistory.bind(controller),\n getChatList: controller.getChatList.bind(controller),\n deleteChat: controller.deleteChat.bind(controller)\n};"}}}}