// DeepSeek Function Tools 定义 // 阶段一:迁移 purchase / chat / ignore 为工具调用;query 也提供工具入口(避免查询意图误判成新建), // 但其汇总逻辑仍复用 handlers.js 的 query 分支(不做二次调用回填)。 // delete / clear_all 保留旧 JSON 输出路径(在 prompt 中引导走 JSON,见 prompt.js)。 // 图片关联不在工具参数中暴露,由后端根据消息文本/附件自行决定(见 handlers.js 的 create_purchase 分支)。 const STATUS_ENUM = ['待付款', '已付款', '已收货', '已完成']; const INVOICE_ENUM = ['无票', '电子票']; const createPurchaseTool = { type: 'function', function: { name: 'create_purchase', description: '新建一条采购记录。仅在用户明确表达购买/采购/下单/付款/买了/花了等消费意图且不是查询历史时调用。' + '注意:如果用户没有明确提供单价(价格),不要调用本工具,应改为调用 reply_chat 追问价格。', parameters: { type: 'object', properties: { purchase_item: { type: 'string', description: '物品名称,必填' }, quantity: { type: 'number', description: '数量,默认 1' }, unit_price: { type: 'number', description: '单价。必须大于 0,若用户未明确给出价格请不要调用本工具,改为 reply_chat 追问。' }, freight: { type: 'number', description: '运费,默认 0' }, payment_method: { type: 'string', description: '支付方式,如 支付宝/微信,未提及则默认未指定' }, invoice_type: { type: 'string', enum: INVOICE_ENUM, description: '发票类型,默认无票' }, status: { type: 'string', enum: STATUS_ENUM, description: '付款/收货状态。若用户明确说了已付款、交了钱、付了款、已收、已到货、已完成等,必须主动填对应值(如已付款),不要省略。仅当完全没提状态时才用默认待付款。' }, remarks: { type: 'string', description: '备注,如购买平台等' } }, required: ['purchase_item'] } } }; const replyChatTool = { type: 'function', function: { name: 'reply_chat', description: '直接回复一段文本给用户。用于以下情况:' + '1) 纯闲聊(如打招呼、问天气等);' + '2) 用户要求修改/更正/调整/更新已有采购记录时,引导其去采购清单页面手动编辑;' + '3) 用户有购买意图但缺少价格信息时,追问价格;' + '4) 权限不足需要拒绝(如非管理员要求清空记录);' + '5) 其他需要回复但不属于新建采购或查询/删除/清空的情况。', parameters: { type: 'object', properties: { reply: { type: 'string', description: '显示给用户的回复内容' } }, required: ['reply'] } } }; const queryPurchasesTool = { type: 'function', function: { name: 'query_purchases', description: '查询历史采购记录。当用户询问"买过什么/有没有买过/查一下/找找看/搜索/列表/我买过/看看"等查询历史采购的意图时调用。' + '即使物品名听起来奇怪或可能不存在,也必须调用本工具,绝不能调用 create_purchase 或 ignore。' + '调用后系统会搜索本地数据库并生成回答,本工具不直接返回查询结果。', parameters: { type: 'object', properties: { keywords: { type: 'string', description: '用户想查找的物品名或关键词;若查询全部记录则设为空字符串 ""' } }, required: ['keywords'] } } }; const ignoreTool = { type: 'function', function: { name: 'ignore', description: '忽略当前消息,不产生任何回复。用于纯符号、纯表情、明显不是对助手说的话等无关消息。', parameters: { type: 'object', properties: {} } } }; const TOOLS = [createPurchaseTool, replyChatTool, queryPurchasesTool, ignoreTool]; module.exports = { TOOLS };