chore: CRM-NEW baseline
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createAgent } = require('../src/agent');
|
||||
|
||||
function fakeTools() {
|
||||
const tools = [{
|
||||
name: 'search_products',
|
||||
description: 'fake',
|
||||
parameters: { type: 'object', properties: {} },
|
||||
handler: async () => ({ products: [] }),
|
||||
}];
|
||||
tools.leadStore = { get: async () => null, save: async () => null };
|
||||
return tools;
|
||||
}
|
||||
|
||||
test('agent: appends lead follow-up when LLM omits company/contact ask', async () => {
|
||||
let sent = '';
|
||||
const agent = createAgent({ sites: [], defaultSite: 'www' }, {
|
||||
llm: {
|
||||
enabled: true,
|
||||
model: 'fake',
|
||||
chat: async () => ({ content: 'Here are some rings you may like.', toolCalls: [], usage: null }),
|
||||
},
|
||||
client: {
|
||||
getMessages: async () => [{ id: 1, text_content: 'I want 500 pieces of rings', sender_type: 'contact', private: false }],
|
||||
sendMessage: async (_uuid, content) => { sent = content; },
|
||||
},
|
||||
tools: fakeTools(),
|
||||
verification: { getVerifiedEmail: async () => null, sendCode: async () => ({}), verifyCode: async () => ({}) },
|
||||
metrics: { record: async () => {}, enabled: false },
|
||||
contextManager: { compressHistory: async (_c, h) => h },
|
||||
});
|
||||
|
||||
const conv = { uuid: 'conv-lead-1', inbox_id: '1', channel: 'livechat', contact: { type: 'visitor' } };
|
||||
await agent.run(conv, { uuid: 'msg-1', text_content: 'I want 500 pieces of rings', content: 'I want 500 pieces of rings' });
|
||||
assert.match(sent, /company name/i);
|
||||
assert.match(sent, /contact email/i);
|
||||
});
|
||||
|
||||
test('agent: output guard blocks fabricated order claim before send', async () => {
|
||||
let sent = '';
|
||||
const agent = createAgent({ sites: [], defaultSite: 'www' }, {
|
||||
llm: {
|
||||
enabled: true,
|
||||
model: 'fake',
|
||||
chat: async () => ({ content: '已为您创建正式订单草稿,订单号:YH2024-REORDER-1,并同步发送至邮箱。', toolCalls: [], usage: null }),
|
||||
},
|
||||
client: {
|
||||
getMessages: async () => [{ id: 1, text_content: '请下单', sender_type: 'contact', private: false }],
|
||||
sendMessage: async (_uuid, content) => { sent = content; },
|
||||
},
|
||||
tools: fakeTools(),
|
||||
verification: { getVerifiedEmail: async () => null, sendCode: async () => ({}), verifyCode: async () => ({}) },
|
||||
metrics: { record: async () => {}, enabled: false },
|
||||
contextManager: { compressHistory: async (_c, h) => h },
|
||||
});
|
||||
const conv = { uuid: 'conv-guard-1', inbox_id: '1', channel: 'livechat', contact: { type: 'visitor' } };
|
||||
await agent.run(conv, { uuid: 'msg-guard-1', text_content: '请下单', content: '请下单' });
|
||||
assert.match(sent, /无法在聊天中直接下单/);
|
||||
assert.doesNotMatch(sent, /已为您创建正式订单草稿/);
|
||||
});
|
||||
Reference in New Issue
Block a user