chore: CRM-NEW baseline

This commit is contained in:
wangliang
2026-10-23 10:35:28 +08:00
commit aa499f6dbf
111 changed files with 15126 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { createContextManager } = require('../src/context');
test('context: long history is compressed into summary + recent', async () => {
const llm = { async chat() { return { content: 'Customer wants wholesale earrings.' }; } };
const cm = createContextManager();
const history = [];
for (let i = 0; i < 30; i += 1) history.push({ role: i % 2 ? 'assistant' : 'user', content: `message ${i}` });
const out = await cm.compressHistory('conv-1', history, llm);
assert.equal(out[0].role, 'system');
assert.match(out[0].content, /Earlier conversation summary/);
assert.equal(out.length, 17); // 1 summary + 16 recent
assert.equal(out[out.length - 1].content, 'message 29');
});
test('context: short history is unchanged', async () => {
const cm = createContextManager();
const history = [{ role: 'user', content: 'hi' }, { role: 'assistant', content: 'hello' }];
const out = await cm.compressHistory('c2', history, { async chat() { throw new Error('should not call'); } });
assert.equal(out.length, 2);
});