@amaster.ai/pi-memory-mem0 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/README.md +74 -23
- package/dist/dedup.d.ts +7 -1
- package/dist/dedup.d.ts.map +1 -1
- package/dist/dedup.js +90 -25
- package/dist/dedup.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +136 -18
- package/dist/index.js.map +1 -1
- package/dist/prefetch.d.ts +2 -0
- package/dist/prefetch.d.ts.map +1 -1
- package/dist/prefetch.js +7 -1
- package/dist/prefetch.js.map +1 -1
- package/dist/provider.d.ts +18 -15
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +111 -10
- package/dist/provider.js.map +1 -1
- package/dist/tools.d.ts +4 -4
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +5 -3
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -29,21 +29,67 @@ Safety boundaries:
|
|
|
29
29
|
|
|
30
30
|
### Memory Modes
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
32
|
+
Memory behavior has three independent controls. Each control is optional and falls back to the selected `memoryMode` preset when omitted.
|
|
33
|
+
|
|
34
|
+
#### Independent Behavior Controls
|
|
35
|
+
|
|
36
|
+
| Setting | Controls |
|
|
37
|
+
|---------|----------|
|
|
38
|
+
| `autoCapture` | Automatically send each user + assistant turn to Mem0 for extraction and storage |
|
|
39
|
+
| `autoRecall` | Automatically search Mem0 and inject matching memories before the agent starts |
|
|
40
|
+
| `toolEnabled` | Register the model-callable `mem0_memory` tool for search, add, list, and delete operations |
|
|
41
|
+
|
|
42
|
+
`toolEnabled` affects only the model-callable tool. The user-facing `/mem0` command remains available while the provider is active.
|
|
43
|
+
|
|
44
|
+
`topK` is the shared result limit for automatic recall and `mem0_memory` search. It must be an integer greater than `0`; use `autoRecall: false`, not `topK: 0`, to disable automatic recall.
|
|
45
|
+
|
|
46
|
+
#### Presets and Overrides
|
|
47
|
+
|
|
48
|
+
`memoryMode` remains a convenient preset for the three controls:
|
|
49
|
+
|
|
50
|
+
| `memoryMode` | Auto capture | Auto recall | `mem0_memory` tool | Use Case |
|
|
51
|
+
|--------------|--------------|-------------|--------------------|----------|
|
|
52
|
+
| `hybrid` (default) | ✅ | ✅ | ✅ | Automatic memory plus agent-driven lookup |
|
|
53
|
+
| `active` | ❌ | ❌ | ✅ | No background traffic; the agent decides every read/write |
|
|
54
|
+
| `passive` | ✅ | ✅ | ❌ | Zero tool surface; fully automatic memory |
|
|
55
|
+
|
|
56
|
+
Explicit controls override the preset independently. Unset controls continue to inherit their preset values, so a partial override does not replace the entire mode.
|
|
37
57
|
|
|
38
58
|
```json
|
|
39
59
|
{
|
|
40
60
|
"pi-memory-mem0": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
61
|
+
"memoryMode": "hybrid",
|
|
62
|
+
"autoRecall": false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This keeps the `hybrid` defaults for `autoCapture` and `toolEnabled`, while the explicit `autoRecall: false` disables automatic injection. The agent can still search through `mem0_memory` on demand.
|
|
68
|
+
|
|
69
|
+
The same rule works with any preset. For example, this starts from `passive` and enables only the tool override:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"pi-memory-mem0": {
|
|
74
|
+
"memoryMode": "passive",
|
|
75
|
+
"toolEnabled": true
|
|
43
76
|
}
|
|
44
77
|
}
|
|
45
78
|
```
|
|
46
79
|
|
|
80
|
+
#### Recall Frequency
|
|
81
|
+
|
|
82
|
+
`recallFrequency` controls how often automatic recall runs when `autoRecall` resolves to `true`:
|
|
83
|
+
|
|
84
|
+
| Value | Behavior |
|
|
85
|
+
|-------|----------|
|
|
86
|
+
| `"user-input"` (default) | Search once for each user input and inject the matching memories before that agent run |
|
|
87
|
+
| `"session"` | Search only for the first user input in each persistent session |
|
|
88
|
+
|
|
89
|
+
Session frequency counts the first search attempt even when it returns no matches or times out. The marker is stored in the Pi session, so switching away and resuming the same session does not search again. `/new` and `/fork` create new session IDs and each search once.
|
|
90
|
+
|
|
91
|
+
When `autoRecall` is `false`, no automatic search is started and `recallFrequency` has no runtime effect. It does not affect manual `mem0_memory` or `/mem0 search` calls.
|
|
92
|
+
|
|
47
93
|
## Architecture (Embedded Mode)
|
|
48
94
|
|
|
49
95
|
```
|
|
@@ -60,10 +106,7 @@ User ←→ Agent ←→ Mem0 OSS Memory
|
|
|
60
106
|
|
|
61
107
|
## Quick Start
|
|
62
108
|
|
|
63
|
-
Store configuration in user/agent settings or in a trusted project's
|
|
64
|
-
`.pi/settings.json`. Project settings are ignored when trust is declined and do
|
|
65
|
-
not expand `${ENV_VAR}`; the environment-backed examples below therefore belong
|
|
66
|
-
in user or agent settings.
|
|
109
|
+
Store configuration in user/agent settings or in a trusted project's `.pi/settings.json`. Project settings are ignored when trust is declined and do not expand `${ENV_VAR}`; the environment-backed examples below therefore belong in user or agent settings.
|
|
67
110
|
|
|
68
111
|
### Platform Mode
|
|
69
112
|
|
|
@@ -105,6 +148,7 @@ Calls the OSS REST server directly. The server uses `/memories` and `/search`, n
|
|
|
105
148
|
"baseUrl": "${MEM0_BASE_URL}",
|
|
106
149
|
"apiKey": "${MEM0_API_KEY}",
|
|
107
150
|
"userId": "${PAPERCLIP_COMPANY_ID}",
|
|
151
|
+
"agentId": "${PAPERCLIP_AGENT_ID}",
|
|
108
152
|
"userIdScope": "exact"
|
|
109
153
|
}
|
|
110
154
|
}
|
|
@@ -186,13 +230,18 @@ The configured vector store always owns persistence. To request an intentionally
|
|
|
186
230
|
| Field | Type | Default | Description |
|
|
187
231
|
|-------|------|---------|-------------|
|
|
188
232
|
| `mode` | `"platform"` \| `"embedded"` \| `"self-hosted"` | `"platform"` | Operating mode |
|
|
189
|
-
| `memoryMode` | `"hybrid"` \| `"active"` \| `"passive"` | `"hybrid"` |
|
|
233
|
+
| `memoryMode` | `"hybrid"` \| `"active"` \| `"passive"` | `"hybrid"` | Preset for capture, recall, and tool behavior |
|
|
234
|
+
| `autoCapture` | boolean | selected preset | Override automatic conversation capture |
|
|
235
|
+
| `autoRecall` | boolean | selected preset | Override automatic recall injection |
|
|
236
|
+
| `toolEnabled` | boolean | selected preset | Override `mem0_memory` tool registration |
|
|
237
|
+
| `recallFrequency` | `"user-input"` \| `"session"` | `"user-input"` | Recall on each user input or only the first user input per persistent session; ignored when `autoRecall` is false |
|
|
190
238
|
| `apiKey` | string | — | Platform or self-hosted API key. Supports `${MEM0_API_KEY}` |
|
|
191
239
|
| `baseUrl` | string | `https://api.mem0.ai` | Platform override; required for self-hosted mode |
|
|
192
240
|
| `requestTimeoutMs` | number | `30000` | Self-hosted request timeout |
|
|
193
241
|
| `userId` | string | `$USER` or `"default-user"` | Memory scoping identifier |
|
|
242
|
+
| `agentId` | string | — | Optional agent scope. Supports environment interpolation |
|
|
194
243
|
| `userIdScope` | `"project"` \| `"exact"` | `"project"` | Append the cwd hash or use `userId` verbatim |
|
|
195
|
-
| `topK` |
|
|
244
|
+
| `topK` | integer greater than `0` | `5` | Max results for automatic recall and `mem0_memory` search; use `autoRecall: false` to disable automatic recall |
|
|
196
245
|
| `useRegistryKeys` | boolean | `true` | Whether OSS mode resolves keys from pi registry |
|
|
197
246
|
| `oss.llm` | object | OpenAI gpt-4.1-nano | OSS extraction model |
|
|
198
247
|
| `oss.embedder` | object | OpenAI text-embedding-3-small | OSS embedding model |
|
|
@@ -201,6 +250,8 @@ The configured vector store always owns persistence. To request an intentionally
|
|
|
201
250
|
| `oss.historyDbPath` | string | `<home>/memories/mem0-history.db` | Shortcut for SQLite history DB path |
|
|
202
251
|
| `oss.disableHistory` | boolean | `false` | Disable mem0 operation history |
|
|
203
252
|
|
|
253
|
+
Embedded and self-hosted modes read and write the exact `userId` + `agentId` scope; Platform mode reads the user and agent entity scopes with OR because Mem0 Platform stores them as separate records. Existing memories with a null `agent_id` are not backfilled automatically.
|
|
254
|
+
|
|
204
255
|
## Data Storage
|
|
205
256
|
|
|
206
257
|
| Mode | Vector Data | History |
|
|
@@ -246,7 +297,7 @@ If `better-sqlite3` fails to load (for example, because of a Node ABI mismatch),
|
|
|
246
297
|
|
|
247
298
|
## Tools
|
|
248
299
|
|
|
249
|
-
When
|
|
300
|
+
When the resolved `toolEnabled` value is true, the agent gets one action-dispatched tool:
|
|
250
301
|
|
|
251
302
|
```
|
|
252
303
|
mem0_memory(action="search", query="...") # Semantic search over memories
|
|
@@ -255,9 +306,7 @@ mem0_memory(action="get_all") # List every stored memory
|
|
|
255
306
|
mem0_memory(action="delete", memory_id="...") # Remove a memory by id
|
|
256
307
|
```
|
|
257
308
|
|
|
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`.
|
|
309
|
+
Stored content is credential-redacted first; results are returned with the same `[UNTRUSTED MEMORY DATA]` wrapping as passive recall, including the memory ids needed for `delete`.
|
|
261
310
|
|
|
262
311
|
## Commands
|
|
263
312
|
|
|
@@ -266,6 +315,8 @@ needed for `delete`.
|
|
|
266
315
|
/mem0 search <query> # Semantic search
|
|
267
316
|
/mem0 profile # List all memories
|
|
268
317
|
/mem0 add <text> # Store a memory manually
|
|
318
|
+
/mem0 dedup # Preview exact duplicates in the current scope
|
|
319
|
+
/mem0 dedup --apply # Confirm and remove exact duplicates
|
|
269
320
|
/mem0 delete <id> # Remove a memory by id
|
|
270
321
|
```
|
|
271
322
|
|
|
@@ -276,22 +327,22 @@ needed for `delete`.
|
|
|
276
327
|
- `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
328
|
- `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
|
|
278
329
|
|
|
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.
|
|
330
|
+
They do not interfere with each other, and their tool names do not collide. `pi-memory-mem0` injects recalled text as a custom user-channel message (never the system prompt); `pi-memory` injects its own context separately.
|
|
282
331
|
|
|
283
332
|
## Dedup API
|
|
284
333
|
|
|
285
|
-
The package exports a standalone
|
|
334
|
+
Normal Mem0 writes use inference, so Mem0's own duplicate and conflict handling remains the primary protection. The package also exports a standalone maintenance function for previewing or removing legacy exact duplicates:
|
|
286
335
|
|
|
287
336
|
```ts
|
|
288
337
|
import { dedupMemories } from "@amaster.ai/pi-memory-mem0/dedup";
|
|
289
338
|
|
|
290
339
|
const result = await dedupMemories({
|
|
291
340
|
userId: "my-user",
|
|
341
|
+
agentId: "my-agent",
|
|
292
342
|
config: { mode: "platform", apiKey: "..." },
|
|
343
|
+
dryRun: true,
|
|
293
344
|
});
|
|
294
|
-
// result: { total: 42,
|
|
345
|
+
// result: { total: 42, duplicatesFound: 3, duplicatesRemoved: 0, deleteFailures: 0 }
|
|
295
346
|
```
|
|
296
347
|
|
|
297
|
-
|
|
348
|
+
Dedup normalizes entries using Unicode NFC, case-insensitive comparison, and collapsed whitespace, then keeps the newest exact match. Platform user and agent entity scopes are processed independently; embedded and self-hosted modes use the exact `userId` + `agentId` scope. Platform and embedded scopes are limited to 10,000 memories; self-hosted dedup requests the server maximum of 1,000 and fails closed when that limit is reached, so it only applies to scopes proven to contain at most 999 memories. Invalid or repeated IDs, empty memory content, missing, invalid, or tied timestamps, incomplete pagination, inconsistent Platform counts, and cancellation all fail closed; individual deletion failures are reported, and no automatic background cleanup is installed.
|
package/dist/dedup.d.ts
CHANGED
|
@@ -7,17 +7,23 @@
|
|
|
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
|
-
import { type ProviderResolver } from './provider.js';
|
|
10
|
+
import { type Mem0Provider, type ProviderResolver } from './provider.js';
|
|
11
11
|
import type { Mem0ExtensionConfig } from './types.js';
|
|
12
12
|
export interface DedupOptions {
|
|
13
13
|
userId: string;
|
|
14
|
+
agentId?: string;
|
|
14
15
|
config: Mem0ExtensionConfig;
|
|
15
16
|
resolveProvider?: ProviderResolver;
|
|
16
17
|
signal?: AbortSignal;
|
|
18
|
+
dryRun?: boolean;
|
|
19
|
+
approve?: (preview: DedupResult) => boolean | Promise<boolean>;
|
|
17
20
|
}
|
|
18
21
|
export interface DedupResult {
|
|
19
22
|
total: number;
|
|
23
|
+
duplicatesFound: number;
|
|
20
24
|
duplicatesRemoved: number;
|
|
25
|
+
deleteFailures: number;
|
|
21
26
|
}
|
|
22
27
|
export declare function dedupMemories(opts: DedupOptions): Promise<DedupResult>;
|
|
28
|
+
export declare function dedupProviderMemories(provider: Mem0Provider, opts: Pick<DedupOptions, 'userId' | 'agentId' | 'signal' | 'dryRun' | 'approve'>): Promise<DedupResult>;
|
|
23
29
|
//# sourceMappingURL=dedup.d.ts.map
|
package/dist/dedup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedup.d.ts","sourceRoot":"","sources":["../src/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"dedup.d.ts","sourceRoot":"","sources":["../src/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,KAAK,EAAE,mBAAmB,EAAc,MAAM,YAAY,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,eAAe,CAAC,EAAE,gBAAgB,CAAC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAQ5E;AAED,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC,GAC/E,OAAO,CAAC,WAAW,CAAC,CA6DtB"}
|
package/dist/dedup.js
CHANGED
|
@@ -9,56 +9,121 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { createMem0Provider } from './provider.js';
|
|
11
11
|
export async function dedupMemories(opts) {
|
|
12
|
-
const {
|
|
12
|
+
const { config, resolveProvider } = opts;
|
|
13
13
|
const provider = await createMem0Provider({
|
|
14
14
|
config,
|
|
15
15
|
...(resolveProvider ? { resolveProvider } : {}),
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return dedupProviderMemories(provider, opts);
|
|
18
|
+
}
|
|
19
|
+
export async function dedupProviderMemories(provider, opts) {
|
|
20
|
+
const { userId, agentId, signal, dryRun = false, approve } = opts;
|
|
21
|
+
const scope = {
|
|
22
|
+
userId,
|
|
23
|
+
...(agentId ? { agentId } : {}),
|
|
24
|
+
...(signal ? { signal } : {}),
|
|
25
|
+
};
|
|
26
|
+
if (!provider.getDedupGroups) {
|
|
27
|
+
throw new Error('The configured Mem0 provider does not support safe deduplication.');
|
|
28
|
+
}
|
|
29
|
+
signal?.throwIfAborted();
|
|
30
|
+
const groups = await provider.getDedupGroups(scope);
|
|
31
|
+
signal?.throwIfAborted();
|
|
32
|
+
const memoryIds = new Set();
|
|
33
|
+
for (const item of groups.flat()) {
|
|
34
|
+
signal?.throwIfAborted();
|
|
35
|
+
const { id } = item;
|
|
36
|
+
if (!id || /\s/.test(id) || memoryIds.has(id)) {
|
|
37
|
+
throw new Error('Mem0 dedup received an invalid or duplicate memory ID.');
|
|
38
|
+
}
|
|
39
|
+
memoryIds.add(id);
|
|
40
|
+
if (!item.memory.trim()) {
|
|
41
|
+
throw new Error('Mem0 dedup received empty memory content.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const total = groups.reduce((count, group) => count + group.length, 0);
|
|
45
|
+
const duplicateIds = new Set(groups.flatMap((group) => findDuplicateIds(group, signal)));
|
|
46
|
+
const preview = {
|
|
47
|
+
total,
|
|
48
|
+
duplicatesFound: duplicateIds.size,
|
|
49
|
+
duplicatesRemoved: 0,
|
|
50
|
+
deleteFailures: 0,
|
|
51
|
+
};
|
|
52
|
+
if (dryRun)
|
|
53
|
+
return preview;
|
|
54
|
+
if (approve) {
|
|
55
|
+
const approved = await approve(preview);
|
|
56
|
+
signal?.throwIfAborted();
|
|
57
|
+
if (!approved)
|
|
58
|
+
return preview;
|
|
20
59
|
}
|
|
21
|
-
const duplicateIds = findDuplicateIds(allMemories, signal);
|
|
22
60
|
let removed = 0;
|
|
61
|
+
let failures = 0;
|
|
23
62
|
for (const id of duplicateIds) {
|
|
24
|
-
|
|
25
|
-
break;
|
|
63
|
+
signal?.throwIfAborted();
|
|
26
64
|
try {
|
|
27
65
|
await (signal ? provider.delete(id, { signal }) : provider.delete(id));
|
|
66
|
+
signal?.throwIfAborted();
|
|
28
67
|
removed++;
|
|
29
68
|
}
|
|
30
69
|
catch {
|
|
31
|
-
|
|
70
|
+
signal?.throwIfAborted();
|
|
71
|
+
failures++;
|
|
32
72
|
}
|
|
33
73
|
}
|
|
34
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
total,
|
|
76
|
+
duplicatesFound: duplicateIds.size,
|
|
77
|
+
duplicatesRemoved: removed,
|
|
78
|
+
deleteFailures: failures,
|
|
79
|
+
};
|
|
35
80
|
}
|
|
36
81
|
/**
|
|
37
82
|
* Shared: find IDs of duplicate entries to remove (keeps the newest).
|
|
38
83
|
*/
|
|
39
84
|
function findDuplicateIds(allMemories, signal) {
|
|
40
|
-
const
|
|
41
|
-
const duplicateIds = [];
|
|
85
|
+
const groups = new Map();
|
|
42
86
|
for (const item of allMemories) {
|
|
43
|
-
|
|
44
|
-
break;
|
|
87
|
+
signal?.throwIfAborted();
|
|
45
88
|
const normalized = item.memory.normalize('NFC').replace(/\s+/g, ' ').trim().toLowerCase();
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
89
|
+
const group = groups.get(normalized);
|
|
90
|
+
if (group)
|
|
91
|
+
group.push(item);
|
|
92
|
+
else
|
|
93
|
+
groups.set(normalized, [item]);
|
|
94
|
+
}
|
|
95
|
+
const duplicateIds = [];
|
|
96
|
+
for (const group of groups.values()) {
|
|
97
|
+
if (group.length < 2)
|
|
98
|
+
continue;
|
|
99
|
+
const [first, ...rest] = group;
|
|
100
|
+
if (!first)
|
|
101
|
+
continue;
|
|
102
|
+
let newest = first;
|
|
103
|
+
let newestTime = memoryTime(first);
|
|
104
|
+
const times = new Set([newestTime]);
|
|
105
|
+
for (const item of rest) {
|
|
106
|
+
signal?.throwIfAborted();
|
|
107
|
+
const time = memoryTime(item);
|
|
108
|
+
if (times.has(time)) {
|
|
109
|
+
throw new Error('Mem0 dedup cannot determine the newest duplicate.');
|
|
53
110
|
}
|
|
54
|
-
|
|
55
|
-
|
|
111
|
+
times.add(time);
|
|
112
|
+
if (time > newestTime) {
|
|
113
|
+
newest = item;
|
|
114
|
+
newestTime = time;
|
|
56
115
|
}
|
|
57
116
|
}
|
|
58
|
-
|
|
59
|
-
seen.set(normalized, item);
|
|
60
|
-
}
|
|
117
|
+
duplicateIds.push(...group.filter((item) => item !== newest).map((item) => item.id));
|
|
61
118
|
}
|
|
62
119
|
return duplicateIds;
|
|
63
120
|
}
|
|
121
|
+
function memoryTime(item) {
|
|
122
|
+
const timestamp = item.updated_at ?? item.created_at;
|
|
123
|
+
const time = timestamp ? new Date(timestamp).getTime() : Number.NaN;
|
|
124
|
+
if (!Number.isFinite(time)) {
|
|
125
|
+
throw new Error('Mem0 dedup cannot determine the newest duplicate.');
|
|
126
|
+
}
|
|
127
|
+
return time;
|
|
128
|
+
}
|
|
64
129
|
//# sourceMappingURL=dedup.js.map
|
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,
|
|
1
|
+
{"version":3,"file":"dedup.js","sourceRoot":"","sources":["../src/dedup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAA4C,MAAM,eAAe,CAAC;AAoB7F,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAkB;IACpD,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;IAEzC,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,OAAO,qBAAqB,CAAC,QAAQ,EAAE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C,CAAC;YAC9B,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YACD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAChB,IAAI,IAAI,GAAG,UAAU,EAAE,CAAC;gBACtB,MAAM,GAAG,IAAI,CAAC;gBACd,UAAU,GAAG,IAAI,CAAC;YACpB,CAAC;QACH,CAAC;QACD,YAAY,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,UAAU,CAAC,IAAgB;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC;IACrD,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACpE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* - **active**: LLM-callable mem0_memory tool only
|
|
12
12
|
* - **hybrid** (default): both
|
|
13
13
|
*
|
|
14
|
+
* autoCapture, autoRecall, and toolEnabled independently override the selected
|
|
15
|
+
* mode's defaults. recallFrequency controls whether automatic recall runs for
|
|
16
|
+
* every user input or only the first user input in a session.
|
|
17
|
+
*
|
|
14
18
|
* Passive side: after each conversation turn, user + assistant messages are
|
|
15
19
|
* sent to Mem0 for fact extraction and storage (credentials are redacted
|
|
16
20
|
* first). Recalled memories are injected as a custom message (delivered to
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAqCpE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA0X5D"}
|