feat: complete quality/observability/KB port batch

This commit is contained in:
wangliang
2026-10-23 11:42:51 +08:00
parent b778570045
commit f343bf1832
12 changed files with 202 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { attachChatToOpportunity } = require('../src/chat-log');
test('chat-log: attaches full conversation as opportunity note', async () => {
const calls = [];
const client = {
async getMessages() {
return [
{ id: 1, sender_type: 'contact', text_content: 'I want 500 rings', private: false },
{ id: 2, sender_type: 'agent', text_content: '<p>Sure, here are options.</p>', private: false },
];
},
};
const twenty = {
async createNote(text) { calls.push(['note', text]); return 'note-1'; },
async linkNoteToOpportunity(note, opp) { calls.push(['link', note, opp]); },
};
const id = await attachChatToOpportunity({ client, twenty, convUuid: 'c1', opportunityId: 'o1' });
assert.equal(id, 'note-1');
assert.match(calls[0][1], /Customer\] I want 500 rings/);
assert.match(calls[0][1], /Agent\] Sure, here are options/);
assert.deepEqual(calls[1], ['link', 'note-1', 'o1']);
});
+12
View File
@@ -0,0 +1,12 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { extractLeadFields } = require('../src/lead-extract');
test('lead extract: parses JSON fields', async () => {
const llm = { enabled: true, async chat() { return { content: '{"company":"ACME","email":"a@b.com","productNeed":"rings","quantity":"500"}' }; } };
const out = await extractLeadFields(llm, 'ACME a@b.com 500 rings');
assert.equal(out.company, 'ACME');
assert.equal(out.quantity, '500');
});