@tanstack/ai-memory 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/skills/tanstack-ai-memory/SKILL.md +35 -21
- package/skills/tanstack-ai-memory-hindsight/SKILL.md +9 -3
- package/skills/tanstack-ai-memory-honcho/SKILL.md +9 -3
- package/skills/tanstack-ai-memory-in-memory/SKILL.md +5 -1
- package/skills/tanstack-ai-memory-mem0/SKILL.md +9 -3
- package/skills/tanstack-ai-memory-redis/SKILL.md +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Pluggable memory adapters for TanStack AI memoryMiddleware",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"tanstack-intent"
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@tanstack/ai-event-client": "^0.11.
|
|
56
|
+
"@tanstack/ai-event-client": "^0.11.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@honcho-ai/sdk": ">=2.0.0",
|
|
60
60
|
"@vectorize-io/hindsight-client": ">=0.6.0",
|
|
61
61
|
"ioredis": ">=5.0.0",
|
|
62
62
|
"redis": ">=4.0.0",
|
|
63
|
-
"@tanstack/ai": "^0.
|
|
63
|
+
"@tanstack/ai": "^0.54.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"ioredis": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@vitest/coverage-v8": "4.1.10",
|
|
83
83
|
"ioredis-mock": "^8.9.0",
|
|
84
84
|
"redis": "^4.7.0",
|
|
85
|
-
"@tanstack/ai": "0.
|
|
85
|
+
"@tanstack/ai": "0.54.0"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "vite build",
|
|
@@ -22,28 +22,33 @@ Memory is for cross-turn / cross-session recall, not within-turn history.
|
|
|
22
22
|
## Wire it up
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
import { chat } from '@tanstack/ai'
|
|
25
|
+
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
|
|
26
26
|
import { openaiText } from '@tanstack/ai-openai'
|
|
27
27
|
import { memoryMiddleware } from '@tanstack/ai-memory'
|
|
28
28
|
import { inMemory } from '@tanstack/ai-memory/in-memory'
|
|
29
|
+
import { requireSession } from './auth'
|
|
29
30
|
|
|
30
31
|
const memory = inMemory() // dev/tests only — see the in-memory skill
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
33
|
+
export async function POST(request: Request) {
|
|
34
|
+
const { messages } = await request.json()
|
|
35
|
+
// Resolved by your auth layer from cookies/headers — never from the request body.
|
|
36
|
+
const session = await requireSession(request)
|
|
37
|
+
|
|
38
|
+
const stream = chat({
|
|
39
|
+
adapter: openaiText('gpt-5.5'),
|
|
40
|
+
messages,
|
|
41
|
+
context: { session },
|
|
42
|
+
middleware: [
|
|
43
|
+
memoryMiddleware({
|
|
44
|
+
adapter: memory,
|
|
45
|
+
// Derive scope server-side from trusted session state.
|
|
46
|
+
scope: () => ({ threadId: session.threadId, userId: session.userId }),
|
|
47
|
+
}),
|
|
48
|
+
],
|
|
49
|
+
})
|
|
50
|
+
return toServerSentEventsResponse(stream)
|
|
51
|
+
}
|
|
47
52
|
```
|
|
48
53
|
|
|
49
54
|
`memoryMiddleware` options: `adapter`, `scope` (static or a function of `ctx`),
|
|
@@ -53,12 +58,21 @@ callbacks.
|
|
|
53
58
|
## The contract
|
|
54
59
|
|
|
55
60
|
```ts
|
|
61
|
+
import type {
|
|
62
|
+
MemoryFact,
|
|
63
|
+
MemoryScope,
|
|
64
|
+
MemorySnapshot,
|
|
65
|
+
MemoryTurn,
|
|
66
|
+
RecallResult,
|
|
67
|
+
SaveReceipt,
|
|
68
|
+
} from '@tanstack/ai-memory'
|
|
69
|
+
|
|
56
70
|
interface MemoryAdapter {
|
|
57
|
-
id: string
|
|
58
|
-
recall(scope, query
|
|
59
|
-
save(scope, turn
|
|
60
|
-
inspect
|
|
61
|
-
listFacts
|
|
71
|
+
readonly id: string
|
|
72
|
+
recall: (scope: MemoryScope, query: string) => Promise<RecallResult> // { systemPrompt, fragments?, tools?, toolGuidance? }
|
|
73
|
+
save: (scope: MemoryScope, turn: MemoryTurn) => Promise<Array<SaveReceipt>> // turn = { user, assistant }; extraction lives HERE
|
|
74
|
+
inspect?: (scope: MemoryScope) => Promise<MemorySnapshot> // optional (devtools)
|
|
75
|
+
listFacts?: (scope: MemoryScope) => Promise<Array<MemoryFact>> // optional (devtools)
|
|
62
76
|
}
|
|
63
77
|
```
|
|
64
78
|
|
|
@@ -16,9 +16,15 @@ model can retain/recall/reflect directly.
|
|
|
16
16
|
import { memoryMiddleware } from '@tanstack/ai-memory'
|
|
17
17
|
import { hindsight } from '@tanstack/ai-memory/hindsight'
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// Build per request from the server-validated session — never from req.body.
|
|
20
|
+
function memoryFor(session: { userId: string; threadId: string }) {
|
|
21
|
+
const memory = hindsight({ user: session.userId }) // baseUrl defaults to HINDSIGHT_URL
|
|
22
|
+
|
|
23
|
+
return memoryMiddleware({
|
|
24
|
+
adapter: memory,
|
|
25
|
+
scope: { threadId: session.threadId, userId: session.userId },
|
|
26
|
+
})
|
|
27
|
+
}
|
|
22
28
|
```
|
|
23
29
|
|
|
24
30
|
`@vectorize-io/hindsight-client` is an **optional peer dependency**, loaded lazily on
|
|
@@ -16,9 +16,15 @@ appends the turn's messages to the session.
|
|
|
16
16
|
import { memoryMiddleware } from '@tanstack/ai-memory'
|
|
17
17
|
import { honcho } from '@tanstack/ai-memory/honcho'
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// Build per request from the server-validated session — never from req.body.
|
|
20
|
+
function memoryFor(session: { userId: string; threadId: string }) {
|
|
21
|
+
const memory = honcho({ user: session.userId }) // baseURL defaults to HONCHO_URL
|
|
22
|
+
|
|
23
|
+
return memoryMiddleware({
|
|
24
|
+
adapter: memory,
|
|
25
|
+
scope: { threadId: session.threadId, userId: session.userId },
|
|
26
|
+
})
|
|
27
|
+
}
|
|
22
28
|
```
|
|
23
29
|
|
|
24
30
|
`@honcho-ai/sdk` is an **optional peer dependency**, loaded lazily on first use — install
|
|
@@ -30,7 +30,11 @@ import { inMemory } from '@tanstack/ai-memory/in-memory'
|
|
|
30
30
|
|
|
31
31
|
const memory = inMemory()
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
// A static scope is fine for dev/tests; derive it from the session in real apps.
|
|
34
|
+
memoryMiddleware({
|
|
35
|
+
adapter: memory,
|
|
36
|
+
scope: { threadId: 'demo-thread', userId: 'alice' },
|
|
37
|
+
})
|
|
34
38
|
```
|
|
35
39
|
|
|
36
40
|
## Options
|
|
@@ -14,9 +14,15 @@ server-side. Talks to the server over plain HTTP — **no SDK peer dependency**.
|
|
|
14
14
|
import { memoryMiddleware } from '@tanstack/ai-memory'
|
|
15
15
|
import { mem0 } from '@tanstack/ai-memory/mem0'
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// Build per request from the server-validated session — never from req.body.
|
|
18
|
+
function memoryFor(session: { userId: string; threadId: string }) {
|
|
19
|
+
const memory = mem0({ user: session.userId }) // baseUrl defaults to MEM0_URL
|
|
20
|
+
|
|
21
|
+
return memoryMiddleware({
|
|
22
|
+
adapter: memory,
|
|
23
|
+
scope: { threadId: session.threadId, userId: session.userId },
|
|
24
|
+
})
|
|
25
|
+
}
|
|
20
26
|
```
|
|
21
27
|
|
|
22
28
|
Requires a running mem0 server (self-hosted or hosted). Point it via `baseUrl` (or
|
|
@@ -20,10 +20,16 @@ import Redis from 'ioredis'
|
|
|
20
20
|
import { memoryMiddleware } from '@tanstack/ai-memory'
|
|
21
21
|
import { redis } from '@tanstack/ai-memory/redis'
|
|
22
22
|
|
|
23
|
-
const client = new Redis(process.env.REDIS_URL)
|
|
23
|
+
const client = new Redis(process.env.REDIS_URL ?? 'redis://localhost:6379')
|
|
24
24
|
const memory = redis({ redis: client, prefix: 'myapp:memory' })
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// Resolve scope per request from the server-validated session — never from req.body.
|
|
27
|
+
function memoryFor(session: { userId: string; threadId: string }) {
|
|
28
|
+
return memoryMiddleware({
|
|
29
|
+
adapter: memory,
|
|
30
|
+
scope: { threadId: session.threadId, userId: session.userId },
|
|
31
|
+
})
|
|
32
|
+
}
|
|
27
33
|
```
|
|
28
34
|
|
|
29
35
|
### Option B: `redis` (node-redis v4+)
|
|
@@ -41,7 +47,12 @@ const memory = redis({
|
|
|
41
47
|
prefix: 'myapp:memory',
|
|
42
48
|
})
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
function memoryFor(session: { userId: string; threadId: string }) {
|
|
51
|
+
return memoryMiddleware({
|
|
52
|
+
adapter: memory,
|
|
53
|
+
scope: { threadId: session.threadId, userId: session.userId },
|
|
54
|
+
})
|
|
55
|
+
}
|
|
45
56
|
```
|
|
46
57
|
|
|
47
58
|
node-redis exposes a camelCase API (`sAdd`, `mGet`); `fromNodeRedis` translates it
|