Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { inMemory } from '../../src/providers/in-memory'
3import { runMemoryAdapterContract } from '../../src/testkit/contract'
4
5runMemoryAdapterContract('inMemory', () => inMemory())
6
7describe('inMemory options', () => {
8 it('runs an extractor on save and surfaces extracted facts on recall', async () => {
9 const adapter = inMemory({
10 extract: (turn) => [
11 { text: `fact: ${turn.user}`, kind: 'fact', importance: 1 },
12 ],
13 })
14 const scope = { threadId: 's1', userId: 'u1' }
15 await adapter.save(scope, { user: 'I live in Berlin', assistant: 'ok' })
16 const result = await adapter.recall(scope, 'Berlin')
17 expect(result.systemPrompt).toContain('fact:')
18 expect(result.systemPrompt.toLowerCase()).toContain('berlin')
19 })
20
21 it('respects the userId dimension of scope', async () => {
22 const adapter = inMemory()
23 await adapter.save(
24 { threadId: 's', userId: 'a' },
25 {
26 user: 'apples are red',
27 assistant: 'ok',
28 },
29 )
30 const sameThreadOtherUser = await adapter.recall(
31 { threadId: 's', userId: 'b' },
32 'apples',
33 )
34 expect(sameThreadOtherUser.systemPrompt).toBe('')
35 })
36
37 it('respects the tenantId dimension of scope', async () => {
38 const adapter = inMemory()
39 await adapter.save(
40 { threadId: 's', userId: 'u', tenantId: 'tenant-a' },
41 {
42 user: 'apples are red',
43 assistant: 'ok',
44 },
45 )
46 const otherTenant = await adapter.recall(
47 { threadId: 's', userId: 'u', tenantId: 'tenant-b' },
48 'apples',
49 )
50 expect(otherTenant.systemPrompt).toBe('')
51
52 const sameTenant = await adapter.recall(
53 { threadId: 's', userId: 'u', tenantId: 'tenant-a' },
54 'apples',
55 )
56 expect(sameTenant.systemPrompt.toLowerCase()).toContain('apples')
57 })
58})