@amaster.ai/pi-memory-mem0 0.1.7 → 0.1.9
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/README.md +86 -26
- package/dist/dedup.d.ts +1 -1
- package/dist/dedup.js +3 -3
- package/dist/dedup.js.map +1 -1
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +133 -39
- package/dist/index.js.map +1 -1
- package/dist/prefetch.d.ts +2 -2
- package/dist/prefetch.d.ts.map +1 -1
- package/dist/prefetch.js +21 -5
- package/dist/prefetch.js.map +1 -1
- package/dist/privacy.d.ts +5 -0
- package/dist/privacy.d.ts.map +1 -0
- package/dist/privacy.js +23 -0
- package/dist/privacy.js.map +1 -0
- package/dist/provider.d.ts +13 -5
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +179 -42
- package/dist/provider.js.map +1 -1
- package/dist/tools.d.ts +26 -10
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +100 -72
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +17 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -2,22 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Semantic memory extension powered by [Mem0](https://mem0.ai), with Platform, embedded, and self-hosted backends and three memory modes (hybrid, active, passive).
|
|
6
6
|
|
|
7
7
|
## How It Works
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**Passive side**: after each conversation turn, the user + assistant messages are automatically sent to Mem0 for fact extraction and storage. When you send a prompt, a semantic search is prefetched in the background and relevant memories are recalled before the agent starts — **zero effort required**.
|
|
10
10
|
|
|
11
|
-
**
|
|
11
|
+
**Active side**: the agent gets a `mem0_memory` tool (`search` / `add` / `get_all` / `delete`) so it can look up and manage memories on its own initiative — same idea as the official `@mem0/pi-agent-plugin`, but backed by this package's provider abstraction, so it works with Platform, embedded, **and** self-hosted Mem0.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Safety boundaries:
|
|
14
|
+
|
|
15
|
+
- **Recall channel**: recalled memories are injected as a custom message delivered on the user channel — never into the system prompt. Each entry is wrapped as `[UNTRUSTED MEMORY DATA]` (JSON-quoted), and entries matching prompt-injection patterns are replaced with `[BLOCKED UNTRUSTED MEMORY: ...]`.
|
|
16
|
+
- **Project namespacing**: memories are scoped to `userId:project:<cwd-hash>` by default, so one project's memories are not visible in another. Set `userIdScope: "exact"` when one identity must be shared across projects.
|
|
17
|
+
- **Credential redaction**: private keys, bearer tokens, and `api_key=…`-style values are redacted before anything is stored.
|
|
18
|
+
- **Platform mode disclosure**: in `platform` mode the captured turns leave your machine and are processed by Mem0 Cloud. Use `embedded` or `self-hosted` mode to keep memory traffic off third-party infrastructure.
|
|
19
|
+
|
|
20
|
+
## Modes
|
|
21
|
+
|
|
22
|
+
### Backend Modes
|
|
14
23
|
|
|
15
24
|
| Mode | Vector Store | Persistence | Dependencies | Use Case |
|
|
16
25
|
|------|-------------|-------------|--------------|----------|
|
|
17
26
|
| `platform` | Mem0 Cloud | Cloud-managed | `MEM0_API_KEY` | Quick start, multi-device sync |
|
|
18
|
-
| `
|
|
27
|
+
| `embedded` | Mem0 OSS vector store | Vector-store managed | LLM + Embedding API | Data privacy, no Mem0 Cloud |
|
|
28
|
+
| `self-hosted` | Mem0 OSS REST server | Server-managed | Server URL, optional API key | Shared infrastructure |
|
|
29
|
+
|
|
30
|
+
### Memory Modes
|
|
31
|
+
|
|
32
|
+
| `memoryMode` | Auto capture + recall | `mem0_memory` tool | Use Case |
|
|
33
|
+
|--------------|----------------------|--------------------|----------|
|
|
34
|
+
| `hybrid` (default) | ✅ | ✅ | Best recall: automatic context plus agent-driven lookup |
|
|
35
|
+
| `active` | ❌ | ✅ | No background traffic; the agent decides every read/write |
|
|
36
|
+
| `passive` | ✅ | ❌ | Zero tool surface; fully automatic memory |
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"pi-memory-mem0": {
|
|
41
|
+
"mode": "embedded",
|
|
42
|
+
"memoryMode": "hybrid"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
19
46
|
|
|
20
|
-
## Architecture (
|
|
47
|
+
## Architecture (Embedded Mode)
|
|
21
48
|
|
|
22
49
|
```
|
|
23
50
|
User ←→ Agent ←→ Mem0 OSS Memory
|
|
@@ -50,14 +77,14 @@ in user or agent settings.
|
|
|
50
77
|
}
|
|
51
78
|
```
|
|
52
79
|
|
|
53
|
-
###
|
|
80
|
+
### Embedded Mode (Recommended)
|
|
54
81
|
|
|
55
82
|
Reuses API keys and base URLs from pi's configured model providers — **no extra environment variables needed**.
|
|
56
83
|
|
|
57
84
|
```json
|
|
58
85
|
{
|
|
59
86
|
"pi-memory-mem0": {
|
|
60
|
-
"mode": "
|
|
87
|
+
"mode": "embedded",
|
|
61
88
|
"userId": "${USER}"
|
|
62
89
|
}
|
|
63
90
|
}
|
|
@@ -65,6 +92,24 @@ Reuses API keys and base URLs from pi's configured model providers — **no extr
|
|
|
65
92
|
|
|
66
93
|
Defaults to OpenAI `text-embedding-3-small` (embedding) + `gpt-4.1-nano` (extraction). API keys and base URLs are automatically resolved from pi's model registry.
|
|
67
94
|
|
|
95
|
+
Existing settings with `mode: "open-source"` continue to load as `embedded`, but `open-source` is not part of the supported configuration interface. New settings should use `embedded`.
|
|
96
|
+
|
|
97
|
+
### Self-Hosted Mode
|
|
98
|
+
|
|
99
|
+
Calls the OSS REST server directly. The server uses `/memories` and `/search`, not the Mem0 Platform `/v1` paths.
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"pi-memory-mem0": {
|
|
104
|
+
"mode": "self-hosted",
|
|
105
|
+
"baseUrl": "${MEM0_BASE_URL}",
|
|
106
|
+
"apiKey": "${MEM0_API_KEY}",
|
|
107
|
+
"userId": "${PAPERCLIP_COMPANY_ID}",
|
|
108
|
+
"userIdScope": "exact"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
68
113
|
### Custom Provider
|
|
69
114
|
|
|
70
115
|
When your model registry defines a custom provider with `api: "openai-completions"`, you can use it directly:
|
|
@@ -72,7 +117,7 @@ When your model registry defines a custom provider with `api: "openai-completion
|
|
|
72
117
|
```json
|
|
73
118
|
{
|
|
74
119
|
"pi-memory-mem0": {
|
|
75
|
-
"mode": "
|
|
120
|
+
"mode": "embedded",
|
|
76
121
|
"oss": {
|
|
77
122
|
"llm": {
|
|
78
123
|
"provider": "my-provider",
|
|
@@ -97,7 +142,7 @@ The extension automatically:
|
|
|
97
142
|
```json
|
|
98
143
|
{
|
|
99
144
|
"pi-memory-mem0": {
|
|
100
|
-
"mode": "
|
|
145
|
+
"mode": "embedded",
|
|
101
146
|
"userId": "${USER}",
|
|
102
147
|
"oss": {
|
|
103
148
|
"llm": {
|
|
@@ -121,7 +166,7 @@ For production workloads that need a dedicated vector database:
|
|
|
121
166
|
```json
|
|
122
167
|
{
|
|
123
168
|
"pi-memory-mem0": {
|
|
124
|
-
"mode": "
|
|
169
|
+
"mode": "embedded",
|
|
125
170
|
"oss": {
|
|
126
171
|
"vectorStore": {
|
|
127
172
|
"provider": "qdrant",
|
|
@@ -140,10 +185,13 @@ The configured vector store always owns persistence. To request an intentionally
|
|
|
140
185
|
|
|
141
186
|
| Field | Type | Default | Description |
|
|
142
187
|
|-------|------|---------|-------------|
|
|
143
|
-
| `mode` | `"platform"` \| `"
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
188
|
+
| `mode` | `"platform"` \| `"embedded"` \| `"self-hosted"` | `"platform"` | Operating mode |
|
|
189
|
+
| `memoryMode` | `"hybrid"` \| `"active"` \| `"passive"` | `"hybrid"` | Memory behavior: tool + automation, tool only, or automation only |
|
|
190
|
+
| `apiKey` | string | — | Platform or self-hosted API key. Supports `${MEM0_API_KEY}` |
|
|
191
|
+
| `baseUrl` | string | `https://api.mem0.ai` | Platform override; required for self-hosted mode |
|
|
192
|
+
| `requestTimeoutMs` | number | `30000` | Self-hosted request timeout |
|
|
146
193
|
| `userId` | string | `$USER` or `"default-user"` | Memory scoping identifier |
|
|
194
|
+
| `userIdScope` | `"project"` \| `"exact"` | `"project"` | Append the cwd hash or use `userId` verbatim |
|
|
147
195
|
| `topK` | number | `5` | Max recalled memories per turn |
|
|
148
196
|
| `useRegistryKeys` | boolean | `true` | Whether OSS mode resolves keys from pi registry |
|
|
149
197
|
| `oss.llm` | object | OpenAI gpt-4.1-nano | OSS extraction model |
|
|
@@ -158,9 +206,10 @@ The configured vector store always owns persistence. To request an intentionally
|
|
|
158
206
|
| Mode | Vector Data | History |
|
|
159
207
|
|------|-------------|---------|
|
|
160
208
|
| Platform | Mem0 Cloud | Cloud-managed |
|
|
161
|
-
|
|
|
162
|
-
|
|
|
163
|
-
|
|
|
209
|
+
| Embedded (default paths) | `<home>/memories/mem0-vectors.db` | `<home>/memories/mem0-history.db` |
|
|
210
|
+
| Embedded (`memory`, `dbPath: ":memory:"`) | Process-local SQLite; lost on restart | `<home>/memories/mem0-history.db` |
|
|
211
|
+
| Embedded (Qdrant) | Qdrant server | `<home>/memories/mem0-history.db` |
|
|
212
|
+
| Self-hosted | Remote server | Remote server |
|
|
164
213
|
|
|
165
214
|
The `home` directory is resolved via `resolveHome()` from `@amaster.ai/pi-shared/settings` (defaults to `~/.pi/agent`).
|
|
166
215
|
|
|
@@ -179,7 +228,7 @@ This happens transparently — just configure the provider name as it appears in
|
|
|
179
228
|
|
|
180
229
|
## Installation Notes
|
|
181
230
|
|
|
182
|
-
The default
|
|
231
|
+
The default Embedded configuration depends on `better-sqlite3` (native addon, transitive dependency of `mem0ai`) for both the vector store and history. This remains true for `dbPath: ":memory:"`: it changes where SQLite stores pages, not which vector-store implementation is used.
|
|
183
232
|
|
|
184
233
|
**For pi-agent users**: pi-agent's `package.json` includes `better-sqlite3` in `pnpm.onlyBuiltDependencies` — it compiles automatically during `pnpm install`. No extra steps needed.
|
|
185
234
|
|
|
@@ -197,11 +246,18 @@ If `better-sqlite3` fails to load (for example, because of a Node ABI mismatch),
|
|
|
197
246
|
|
|
198
247
|
## Tools
|
|
199
248
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
249
|
+
When `memoryMode` is `hybrid` or `active`, the agent gets one action-dispatched tool:
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
mem0_memory(action="search", query="...") # Semantic search over memories
|
|
253
|
+
mem0_memory(action="add", content="...") # Store a durable fact
|
|
254
|
+
mem0_memory(action="get_all") # List every stored memory
|
|
255
|
+
mem0_memory(action="delete", memory_id="...") # Remove a memory by id
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Stored content is credential-redacted first; results are returned with the same
|
|
259
|
+
`[UNTRUSTED MEMORY DATA]` wrapping as passive recall, including the memory ids
|
|
260
|
+
needed for `delete`.
|
|
205
261
|
|
|
206
262
|
## Commands
|
|
207
263
|
|
|
@@ -209,16 +265,20 @@ If `better-sqlite3` fails to load (for example, because of a Node ABI mismatch),
|
|
|
209
265
|
/mem0 status # Show current status
|
|
210
266
|
/mem0 search <query> # Semantic search
|
|
211
267
|
/mem0 profile # List all memories
|
|
268
|
+
/mem0 add <text> # Store a memory manually
|
|
269
|
+
/mem0 delete <id> # Remove a memory by id
|
|
212
270
|
```
|
|
213
271
|
|
|
214
272
|
## Relationship with pi-memory
|
|
215
273
|
|
|
216
274
|
`pi-memory-mem0` and `pi-memory` run **independently in parallel** as separate extensions:
|
|
217
275
|
|
|
218
|
-
- `pi-memory`:
|
|
219
|
-
- `pi-memory-mem0`:
|
|
276
|
+
- `pi-memory`: Curated memory — the agent explicitly manages memories via the `memory_add` / `memory_replace` / `memory_remove` / `memory_read` tools, local `.md` files, hard char limits
|
|
277
|
+
- `pi-memory-mem0`: Semantic memory — automatic extraction/storage and semantic recall (passive), plus the `mem0_memory` tool for agent-driven semantic lookup (active); no capacity limits
|
|
220
278
|
|
|
221
|
-
They do not interfere with each other and
|
|
279
|
+
They do not interfere with each other, and their tool names do not collide. `pi-memory-mem0` injects recalled text as a
|
|
280
|
+
custom user-channel message (never the system prompt); `pi-memory` injects its own
|
|
281
|
+
context separately.
|
|
222
282
|
|
|
223
283
|
## Dedup API
|
|
224
284
|
|
package/dist/dedup.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Normalizes content, identifies exact duplicates (case-insensitive, whitespace-collapsed),
|
|
5
5
|
* deletes the older entries, and keeps only the most recently updated.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* All modes use the provider interface. In embedded mode the configured
|
|
8
8
|
* vector store is the source of truth and its IDs remain stable across restarts.
|
|
9
9
|
*/
|
|
10
10
|
import { type ProviderResolver } from './provider.js';
|
package/dist/dedup.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Normalizes content, identifies exact duplicates (case-insensitive, whitespace-collapsed),
|
|
5
5
|
* deletes the older entries, and keeps only the most recently updated.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* All modes use the provider interface. In embedded mode the configured
|
|
8
8
|
* vector store is the source of truth and its IDs remain stable across restarts.
|
|
9
9
|
*/
|
|
10
10
|
import { createMem0Provider } from './provider.js';
|
|
@@ -14,7 +14,7 @@ export async function dedupMemories(opts) {
|
|
|
14
14
|
config,
|
|
15
15
|
...(resolveProvider ? { resolveProvider } : {}),
|
|
16
16
|
});
|
|
17
|
-
const allMemories = await provider.getAll({ userId });
|
|
17
|
+
const allMemories = await provider.getAll({ userId, ...(signal ? { signal } : {}) });
|
|
18
18
|
if (allMemories.length === 0) {
|
|
19
19
|
return { total: 0, duplicatesRemoved: 0 };
|
|
20
20
|
}
|
|
@@ -24,7 +24,7 @@ export async function dedupMemories(opts) {
|
|
|
24
24
|
if (signal?.aborted)
|
|
25
25
|
break;
|
|
26
26
|
try {
|
|
27
|
-
await provider.delete(id);
|
|
27
|
+
await (signal ? provider.delete(id, { signal }) : provider.delete(id));
|
|
28
28
|
removed++;
|
|
29
29
|
}
|
|
30
30
|
catch {
|
package/dist/dedup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedup.js","sourceRoot":"","sources":["../src/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,eAAe,CAAC;AAe1E,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAkB;IACpD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAEzD,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC;QACxC,MAAM;QACN,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"dedup.js","sourceRoot":"","sources":["../src/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,eAAe,CAAC;AAe1E,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAkB;IACpD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAEzD,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC;QACxC,MAAM;QACN,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,E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tC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACvF,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9E,IAAI,WAAW,GAAG,YAAY,EAAE,CAAC;gBAC/B,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBAC/B,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACN,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-memory-mem0 —
|
|
2
|
+
* pi-memory-mem0 — Semantic memory extension powered by Mem0.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Backend modes:
|
|
5
5
|
* - **platform**: Uses Mem0 Cloud API (needs MEM0_API_KEY)
|
|
6
|
-
* - **
|
|
6
|
+
* - **embedded**: Runs Mem0 OSS in-process
|
|
7
|
+
* - **self-hosted**: Calls a remote Mem0 OSS REST server
|
|
8
|
+
*
|
|
9
|
+
* Memory modes (config "memoryMode"):
|
|
10
|
+
* - **passive**: automatic capture + recall injection only
|
|
11
|
+
* - **active**: LLM-callable mem0_memory tool only
|
|
12
|
+
* - **hybrid** (default): both
|
|
13
|
+
*
|
|
14
|
+
* Passive side: after each conversation turn, user + assistant messages are
|
|
15
|
+
* sent to Mem0 for fact extraction and storage (credentials are redacted
|
|
16
|
+
* first). Recalled memories are injected as a custom message (delivered to
|
|
17
|
+
* the model on the user channel, never the system prompt) and wrapped as
|
|
18
|
+
* untrusted data. Active side: the mem0_memory tool lets the agent search,
|
|
19
|
+
* add, list, and delete memories on its own initiative, under the same
|
|
20
|
+
* redaction and untrusted-data boundaries.
|
|
7
21
|
*
|
|
8
22
|
* Configuration via settings.json key "pi-memory-mem0".
|
|
9
23
|
* Supports ${ENV_VAR:-fallback} in user and agent settings.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAkCpE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAoP5D"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-memory-mem0 —
|
|
2
|
+
* pi-memory-mem0 — Semantic memory extension powered by Mem0.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Backend modes:
|
|
5
5
|
* - **platform**: Uses Mem0 Cloud API (needs MEM0_API_KEY)
|
|
6
|
-
* - **
|
|
6
|
+
* - **embedded**: Runs Mem0 OSS in-process
|
|
7
|
+
* - **self-hosted**: Calls a remote Mem0 OSS REST server
|
|
8
|
+
*
|
|
9
|
+
* Memory modes (config "memoryMode"):
|
|
10
|
+
* - **passive**: automatic capture + recall injection only
|
|
11
|
+
* - **active**: LLM-callable mem0_memory tool only
|
|
12
|
+
* - **hybrid** (default): both
|
|
13
|
+
*
|
|
14
|
+
* Passive side: after each conversation turn, user + assistant messages are
|
|
15
|
+
* sent to Mem0 for fact extraction and storage (credentials are redacted
|
|
16
|
+
* first). Recalled memories are injected as a custom message (delivered to
|
|
17
|
+
* the model on the user channel, never the system prompt) and wrapped as
|
|
18
|
+
* untrusted data. Active side: the mem0_memory tool lets the agent search,
|
|
19
|
+
* add, list, and delete memories on its own initiative, under the same
|
|
20
|
+
* redaction and untrusted-data boundaries.
|
|
7
21
|
*
|
|
8
22
|
* Configuration via settings.json key "pi-memory-mem0".
|
|
9
23
|
* Supports ${ENV_VAR:-fallback} in user and agent settings.
|
|
@@ -11,8 +25,9 @@
|
|
|
11
25
|
*/
|
|
12
26
|
import { isProjectTrusted, loadPiSettings } from '@amaster.ai/pi-shared/settings';
|
|
13
27
|
import { Prefetch } from './prefetch.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
28
|
+
import { formatRecalledMemory, redactMemoryText, scopeMemoryUserId } from './privacy.js';
|
|
29
|
+
import { createMem0Provider, normalizeMem0Mode, normalizeMemoryMode, } from './provider.js';
|
|
30
|
+
import { createMem0MemoryTool } from './tools.js';
|
|
16
31
|
const SETTINGS_KEY = 'pi-memory-mem0';
|
|
17
32
|
const STATUS_KEY = 'mem0';
|
|
18
33
|
function loadConfig(cwd, projectTrusted = false) {
|
|
@@ -26,9 +41,11 @@ function loadConfig(cwd, projectTrusted = false) {
|
|
|
26
41
|
return {};
|
|
27
42
|
}
|
|
28
43
|
}
|
|
29
|
-
function resolveUserId(configUserId) {
|
|
44
|
+
function resolveUserId(configUserId, scope = 'project') {
|
|
30
45
|
if (configUserId?.trim())
|
|
31
46
|
return configUserId.trim();
|
|
47
|
+
if (scope === 'exact')
|
|
48
|
+
throw new Error('Mem0 exact userId resolved to an empty value.');
|
|
32
49
|
if (process.env.USER)
|
|
33
50
|
return process.env.USER;
|
|
34
51
|
if (process.env.USERNAME)
|
|
@@ -39,18 +56,31 @@ export default function mem0Extension(pi) {
|
|
|
39
56
|
let provider;
|
|
40
57
|
let prefetch;
|
|
41
58
|
let userId = '';
|
|
59
|
+
let activeMode = '';
|
|
60
|
+
let activeMemoryMode = '';
|
|
61
|
+
let activeToolEnabled = false;
|
|
42
62
|
let lastUserText = '';
|
|
43
63
|
let pendingWrite = Promise.resolve();
|
|
64
|
+
let sessionEpoch = 0;
|
|
44
65
|
pi.on('session_start', async (_event, ctx) => {
|
|
66
|
+
// A newer session_start (or shutdown) can run while this handler is still
|
|
67
|
+
// awaiting provider init (embedded init takes seconds). The epoch check
|
|
68
|
+
// after the await keeps the superseded handler from clobbering the live
|
|
69
|
+
// session's provider, prefetch, and tool-enablement state.
|
|
70
|
+
const epoch = ++sessionEpoch;
|
|
71
|
+
provider = undefined;
|
|
72
|
+
prefetch = undefined;
|
|
73
|
+
activeToolEnabled = false;
|
|
45
74
|
const config = loadConfig(ctx.cwd, isProjectTrusted(ctx));
|
|
46
|
-
const mode = config.mode ?? 'platform';
|
|
47
|
-
// Platform mode requires apiKey; OSS mode requires an LLM provider (env key)
|
|
48
|
-
if (mode === 'platform' && !config.apiKey?.trim()) {
|
|
49
|
-
ctx.ui.setStatus(STATUS_KEY, 'mem0: disabled (no API key)');
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
75
|
try {
|
|
53
|
-
|
|
76
|
+
const mode = normalizeMem0Mode(config.mode);
|
|
77
|
+
const memoryMode = normalizeMemoryMode(config.memoryMode);
|
|
78
|
+
if (mode === 'platform' && !config.apiKey?.trim()) {
|
|
79
|
+
ctx.ui.setStatus(STATUS_KEY, 'mem0: disabled (no API key)');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const resolvedUserId = resolveUserId(config.userId, config.userIdScope);
|
|
83
|
+
const newProvider = await createMem0Provider({
|
|
54
84
|
config,
|
|
55
85
|
resolveProvider: async (providerName) => {
|
|
56
86
|
const registry = ctx.modelRegistry;
|
|
@@ -73,32 +103,48 @@ export default function mem0Extension(pi) {
|
|
|
73
103
|
return result;
|
|
74
104
|
},
|
|
75
105
|
});
|
|
106
|
+
if (epoch !== sessionEpoch)
|
|
107
|
+
return;
|
|
108
|
+
provider = newProvider;
|
|
109
|
+
userId = scopeMemoryUserId(resolvedUserId, ctx.cwd, config.userIdScope);
|
|
110
|
+
activeMode = mode;
|
|
111
|
+
activeMemoryMode = memoryMode;
|
|
112
|
+
if (memoryMode !== 'active') {
|
|
113
|
+
prefetch = new Prefetch(provider, userId, { topK: config.topK ?? 5 });
|
|
114
|
+
}
|
|
115
|
+
if (memoryMode !== 'passive') {
|
|
116
|
+
activeToolEnabled = true;
|
|
117
|
+
pi.registerTool(createMem0MemoryTool({
|
|
118
|
+
getProvider: () => provider,
|
|
119
|
+
getUserId: () => userId,
|
|
120
|
+
isEnabled: () => activeToolEnabled,
|
|
121
|
+
topK: config.topK ?? 5,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
76
124
|
}
|
|
77
125
|
catch (err) {
|
|
126
|
+
if (epoch !== sessionEpoch)
|
|
127
|
+
return;
|
|
128
|
+
provider = undefined;
|
|
129
|
+
prefetch = undefined;
|
|
130
|
+
activeToolEnabled = false;
|
|
78
131
|
ctx.ui.setStatus(STATUS_KEY, 'mem0: init failed');
|
|
79
132
|
ctx.ui.notify(`Mem0 init failed: ${err instanceof Error ? err.message : String(err)}`, 'error');
|
|
80
133
|
return;
|
|
81
134
|
}
|
|
82
|
-
|
|
83
|
-
prefetch = new Prefetch(provider, userId, {
|
|
84
|
-
topK: config.topK ?? 5,
|
|
85
|
-
});
|
|
86
|
-
ctx.ui.setStatus(STATUS_KEY, `mem0: ${mode}`);
|
|
87
|
-
for (const tool of createMem0Tools(provider, userId)) {
|
|
88
|
-
pi.registerTool(tool);
|
|
89
|
-
}
|
|
135
|
+
ctx.ui.setStatus(STATUS_KEY, `mem0: ${activeMode}/${activeMemoryMode}`);
|
|
90
136
|
});
|
|
91
137
|
pi.on('input', async (event) => {
|
|
92
138
|
if (!prefetch)
|
|
93
139
|
return;
|
|
94
140
|
const text = event.text ?? '';
|
|
95
141
|
if (text) {
|
|
96
|
-
prefetch.queue(text);
|
|
142
|
+
prefetch.queue(redactMemoryText(text));
|
|
97
143
|
lastUserText = text;
|
|
98
144
|
}
|
|
99
145
|
});
|
|
100
146
|
pi.on('turn_end', async (event) => {
|
|
101
|
-
if (!provider || !lastUserText)
|
|
147
|
+
if (!provider || !prefetch || !lastUserText)
|
|
102
148
|
return;
|
|
103
149
|
const msg = event.message;
|
|
104
150
|
const text = extractText(msg);
|
|
@@ -107,48 +153,61 @@ export default function mem0Extension(pi) {
|
|
|
107
153
|
const userText = lastUserText;
|
|
108
154
|
lastUserText = '';
|
|
109
155
|
const activeProvider = provider;
|
|
156
|
+
const activeUserId = userId;
|
|
110
157
|
pendingWrite = pendingWrite
|
|
111
158
|
.catch(() => { })
|
|
112
159
|
.then(async () => {
|
|
113
|
-
await activeProvider.add([
|
|
114
|
-
{ role: 'user', content: userText },
|
|
115
|
-
{ role: 'assistant', content: text },
|
|
116
|
-
], { userId });
|
|
160
|
+
const result = await activeProvider.add([
|
|
161
|
+
{ role: 'user', content: redactMemoryText(userText) },
|
|
162
|
+
{ role: 'assistant', content: redactMemoryText(text) },
|
|
163
|
+
], { userId: activeUserId });
|
|
164
|
+
// Extraction legitimately finds nothing in many turns, but a totally
|
|
165
|
+
// silent no-op makes a broken pipeline indistinguishable from a quiet
|
|
166
|
+
// one — gate a diagnostic behind DEBUG.
|
|
167
|
+
if (process.env.DEBUG?.includes('pi-memory-mem0') && !result?.results?.length) {
|
|
168
|
+
console.error('[pi-memory-mem0] turn capture stored no memories (extraction empty?)');
|
|
169
|
+
}
|
|
117
170
|
})
|
|
118
|
-
.catch(() => {
|
|
171
|
+
.catch((err) => {
|
|
172
|
+
console.error(`[pi-memory-mem0] failed to store turn: ${err instanceof Error ? err.message : String(err)}`);
|
|
173
|
+
});
|
|
119
174
|
});
|
|
120
|
-
pi.on('before_agent_start', async (
|
|
175
|
+
pi.on('before_agent_start', async () => {
|
|
121
176
|
if (!prefetch)
|
|
122
177
|
return;
|
|
123
178
|
const recalled = await prefetch.consume();
|
|
124
179
|
if (!recalled)
|
|
125
180
|
return;
|
|
126
181
|
return {
|
|
127
|
-
|
|
182
|
+
message: {
|
|
183
|
+
customType: 'mem0-recall',
|
|
184
|
+
content: recalled,
|
|
185
|
+
display: true,
|
|
186
|
+
},
|
|
128
187
|
};
|
|
129
188
|
});
|
|
130
189
|
pi.on('session_shutdown', async () => {
|
|
190
|
+
sessionEpoch++;
|
|
131
191
|
await pendingWrite;
|
|
132
192
|
provider = undefined;
|
|
133
193
|
prefetch = undefined;
|
|
194
|
+
activeToolEnabled = false;
|
|
134
195
|
lastUserText = '';
|
|
135
196
|
pendingWrite = Promise.resolve();
|
|
136
197
|
});
|
|
137
198
|
pi.registerCommand('mem0', {
|
|
138
|
-
description: 'Mem0 memory commands. Subcommands: status, search <query>, profile
|
|
199
|
+
description: 'Mem0 memory commands. Subcommands: status, search <query>, profile, add <text>, delete <id>.',
|
|
139
200
|
handler: async (args, ctx) => {
|
|
140
201
|
if (!provider) {
|
|
141
202
|
ctx.ui.notify('Mem0 is not active.', 'warning');
|
|
142
203
|
return;
|
|
143
204
|
}
|
|
144
|
-
const config = loadConfig(ctx.cwd, isProjectTrusted(ctx));
|
|
145
|
-
const userId = resolveUserId(config.userId);
|
|
146
205
|
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
147
206
|
const subcommand = parts[0]?.toLowerCase() ?? 'status';
|
|
148
207
|
const rest = parts.slice(1).join(' ').trim();
|
|
149
208
|
switch (subcommand) {
|
|
150
209
|
case 'status': {
|
|
151
|
-
ctx.ui.notify(`Mem0: active (mode: ${
|
|
210
|
+
ctx.ui.notify(`Mem0: active (mode: ${activeMode}/${activeMemoryMode})`, 'info');
|
|
152
211
|
break;
|
|
153
212
|
}
|
|
154
213
|
case 'search': {
|
|
@@ -156,29 +215,64 @@ export default function mem0Extension(pi) {
|
|
|
156
215
|
ctx.ui.notify('Usage: /mem0 search <query>', 'warning');
|
|
157
216
|
break;
|
|
158
217
|
}
|
|
159
|
-
const results = await provider.search(rest, {
|
|
218
|
+
const results = await provider.search(rest, {
|
|
219
|
+
userId,
|
|
220
|
+
topK: 10,
|
|
221
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
222
|
+
});
|
|
160
223
|
if (results.length === 0) {
|
|
161
224
|
ctx.ui.notify('No relevant memories found.', 'info');
|
|
162
225
|
}
|
|
163
226
|
else {
|
|
164
|
-
const lines = results.map((r, i) => `${i + 1}. ${r.memory}`);
|
|
227
|
+
const lines = results.map((r, i) => `${i + 1}. ${formatRecalledMemory(r.memory)}`);
|
|
165
228
|
ctx.ui.notify(`Mem0 search results:\n${lines.join('\n')}`, 'info');
|
|
166
229
|
}
|
|
167
230
|
break;
|
|
168
231
|
}
|
|
169
232
|
case 'profile': {
|
|
170
|
-
const all = await provider.getAll({
|
|
233
|
+
const all = await provider.getAll({
|
|
234
|
+
userId,
|
|
235
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
236
|
+
});
|
|
171
237
|
if (all.length === 0) {
|
|
172
238
|
ctx.ui.notify('No memories stored yet.', 'info');
|
|
173
239
|
}
|
|
174
240
|
else {
|
|
175
|
-
const lines = all.map((m, i) => `${i + 1}. ${m.memory}`);
|
|
241
|
+
const lines = all.map((m, i) => `${i + 1}. ${formatRecalledMemory(m.memory)}`);
|
|
176
242
|
ctx.ui.notify(`Mem0 memories (${all.length}):\n${lines.join('\n')}`, 'info');
|
|
177
243
|
}
|
|
178
244
|
break;
|
|
179
245
|
}
|
|
246
|
+
case 'add': {
|
|
247
|
+
if (!rest) {
|
|
248
|
+
ctx.ui.notify('Usage: /mem0 add <text>', 'warning');
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
const result = await provider.add([{ role: 'user', content: redactMemoryText(rest) }], {
|
|
252
|
+
userId,
|
|
253
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
254
|
+
});
|
|
255
|
+
const created = result?.results ?? [];
|
|
256
|
+
if (created.length === 0) {
|
|
257
|
+
ctx.ui.notify('No memory was extracted from the provided text.', 'info');
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const lines = created.map((m, i) => `${i + 1}. ${formatRecalledMemory(m.memory)}`);
|
|
261
|
+
ctx.ui.notify(`Mem0 saved ${created.length}:\n${lines.join('\n')}`, 'info');
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 'delete': {
|
|
266
|
+
if (!rest) {
|
|
267
|
+
ctx.ui.notify('Usage: /mem0 delete <memory-id>', 'warning');
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
await provider.delete(rest, ctx.signal ? { signal: ctx.signal } : {});
|
|
271
|
+
ctx.ui.notify(`Deleted memory ${rest}.`, 'info');
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
180
274
|
default:
|
|
181
|
-
ctx.ui.notify('Unknown subcommand. Available: status, search, profile.', 'warning');
|
|
275
|
+
ctx.ui.notify('Unknown subcommand. Available: status, search, profile, add, delete.', 'warning');
|
|
182
276
|
}
|
|
183
277
|
},
|
|
184
278
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACzF,OAAO,EACL,kBAAkB,EAElB,iBAAiB,E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AAK,CAAC;aACnB,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/prefetch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Two-phase semantic prefetch — kicks off a background search on
|
|
2
|
+
* Two-phase semantic prefetch — kicks off a background search on input,
|
|
3
3
|
* consumes the result on before_agent_start with a timeout.
|
|
4
4
|
*/
|
|
5
5
|
import type { Mem0Provider } from './provider.js';
|
|
@@ -11,7 +11,7 @@ export declare class Prefetch {
|
|
|
11
11
|
constructor(provider: Mem0Provider, userId: string, opts: {
|
|
12
12
|
topK: number;
|
|
13
13
|
});
|
|
14
|
-
/** Phase 1: kick off a background search (called on
|
|
14
|
+
/** Phase 1: kick off a background search (called on input with user text). */
|
|
15
15
|
queue(query: string): void;
|
|
16
16
|
/** Phase 2: consume the result with a timeout (called on before_agent_start). */
|
|
17
17
|
consume(timeoutMs?: number): Promise<string>;
|