40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { InMemoryMemoryStore, Persona } from '../src';
|
|
|
|
describe('sleepMemory', () => {
|
|
it('objectivizes and persists extracted durable facts through the memory model', async () => {
|
|
const memory = new InMemoryMemoryStore();
|
|
const persona = new Persona('Mina', 'Mina remembers stable details.', {
|
|
memory,
|
|
now: '2026-05-01T10:00:00.000Z',
|
|
models: {
|
|
factExtractor: {
|
|
async extract(input) {
|
|
if (input.includes('Seed:')) {
|
|
return [{ statement: 'Mina remembers stable details.', topics: [{ name: 'persona' }, { name: 'Mina' }] }];
|
|
}
|
|
expect(input).toContain('user@2026-05-01T15:00:00.000Z: 나는 타입스크립트를 2025년부터 시작했어');
|
|
expect(input).toContain('Objectivize');
|
|
return [{
|
|
statement: 'The user started TypeScript in 2025.',
|
|
topics: [{ name: 'user' }, { name: 'TypeScript' }, { name: '2025' }],
|
|
confidence: 0.9,
|
|
}];
|
|
},
|
|
},
|
|
},
|
|
});
|
|
const space = await persona.ready();
|
|
|
|
const drafts = await persona.sleepMemory({
|
|
datetime: '2026-05-02T00:00:00.000Z',
|
|
messageHistory: [{ sender: 'user', time: '2026-05-01T15:00:00.000Z', content: '나는 타입스크립트를 2025년부터 시작했어' }],
|
|
});
|
|
|
|
expect(drafts).toHaveLength(1);
|
|
const facts = await memory.findFacts(space.id, ['TypeScript']);
|
|
expect(facts[0]).toMatchObject({ statement: 'The user started TypeScript in 2025.', source: 'boxbrain.sleepMemory' });
|
|
expect(facts[0]?.topics).toContain('sleepMemory');
|
|
});
|
|
});
|