mentedb 0.47.0 → 0.48.0
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 +17 -0
- package/mentedb.darwin-arm64.node +0 -0
- package/mentedb.darwin-x64.node +0 -0
- package/mentedb.linux-arm64-gnu.node +0 -0
- package/mentedb.linux-x64-gnu.node +0 -0
- package/mentedb.win32-x64-msvc.node +0 -0
- package/npm/client.d.ts +23 -4
- package/npm/client.js +29 -6
- package/npm/index.d.ts +3 -1
- package/npm/index.js +6 -1
- package/npm/memoryTool.d.ts +105 -0
- package/npm/memoryTool.js +119 -0
- package/npm/types.d.ts +49 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,6 +109,23 @@ profile) is not exposed by the Node.js package; use the Python SDK or the
|
|
|
109
109
|
server for it. `ingest` calls an LLM and needs `MENTEDB_LLM_PROVIDER`
|
|
110
110
|
(`openai`, `anthropic` or `ollama`) and `MENTEDB_LLM_API_KEY`.
|
|
111
111
|
|
|
112
|
+
## Claude memory tool backend
|
|
113
|
+
|
|
114
|
+
`MemoryTool` backs Claude's client side memory tool (`memory_20250818`) with a
|
|
115
|
+
`mentedb-server` or MenteDB Cloud over `fetch`. Each `/memories` file is a
|
|
116
|
+
memory scoped to the agent:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { MemoryTool } from 'mentedb';
|
|
120
|
+
|
|
121
|
+
const memory = new MemoryTool({ baseUrl: 'http://localhost:6677', token, agentId: '...' });
|
|
122
|
+
// tools: [MemoryTool.TOOL] on the Messages API request, then each turn:
|
|
123
|
+
messages.push({ role: 'user', content: await memory.results(response.content) });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
See [the memory tool guide](../../docs/MEMORY_TOOL.md) and
|
|
127
|
+
[`examples/memory_tool_agent.ts`](examples/memory_tool_agent.ts).
|
|
128
|
+
|
|
112
129
|
## API reference
|
|
113
130
|
|
|
114
131
|
### `MenteDB`
|
|
Binary file
|
package/mentedb.darwin-x64.node
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/npm/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EdgeType, type StoreOptions, type RecallResult, type SearchResult, type ProcessTurnResult, type IngestResult, type ErasureReceipt } from './types';
|
|
1
|
+
import { EdgeType, type StoreOptions, type RecallResult, type SearchResult, type ProcessTurnResult, type IngestResult, type ErasureReceipt, type SessionErasureReceipt, type Memory, type ProvenanceFilter } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* MenteDB client. Wraps the native Rust database engine and exposes a
|
|
4
4
|
* TypeScript-friendly API for storing, recalling, searching, relating, and
|
|
@@ -28,12 +28,22 @@ export declare class MenteDB {
|
|
|
28
28
|
* or pass `provider` ("openai", "anthropic", or "ollama") explicitly.
|
|
29
29
|
*/
|
|
30
30
|
ingest(conversation: string, provider?: string, agentId?: string): IngestResult;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Store a memory and return its UUID. `sessionId`, `source` and
|
|
33
|
+
* `sourceRef` are recorded as its provenance on the first write.
|
|
34
|
+
*/
|
|
32
35
|
store(options: StoreOptions): string;
|
|
36
|
+
/** One stored memory with its provenance. Throws when the id is unknown. */
|
|
37
|
+
getMemory(memoryId: string): Memory;
|
|
38
|
+
/** Ids of every memory written in `sessionId`. */
|
|
39
|
+
memoryIdsInSession(sessionId: string): string[];
|
|
33
40
|
/** Recall memories using an MQL query string. */
|
|
34
41
|
recall(query: string): RecallResult;
|
|
35
|
-
/**
|
|
36
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Vector similarity search returning top-k results, optionally narrowed to
|
|
44
|
+
* memories written in a session and/or from a kind of source.
|
|
45
|
+
*/
|
|
46
|
+
search(embedding: number[], k?: number, filter?: ProvenanceFilter): SearchResult[];
|
|
37
47
|
/** Create a typed, weighted edge between two memories. */
|
|
38
48
|
relate(source: string, target: string, edgeType?: EdgeType, weight?: number): void;
|
|
39
49
|
/** Remove a memory by ID. */
|
|
@@ -49,6 +59,15 @@ export declare class MenteDB {
|
|
|
49
59
|
includeSources?: boolean;
|
|
50
60
|
verify?: boolean;
|
|
51
61
|
}): ErasureReceipt;
|
|
62
|
+
/**
|
|
63
|
+
* Verified erase of every memory written in `sessionId` and everything
|
|
64
|
+
* derived from them, in one erase with one receipt. A session with no
|
|
65
|
+
* memories returns an empty receipt. See docs/PROVENANCE.md.
|
|
66
|
+
*/
|
|
67
|
+
eraseSession(sessionId: string, options?: {
|
|
68
|
+
includeSources?: boolean;
|
|
69
|
+
verify?: boolean;
|
|
70
|
+
}): SessionErasureReceipt;
|
|
52
71
|
/** Flush all data and close the database. */
|
|
53
72
|
close(): void;
|
|
54
73
|
}
|
package/npm/client.js
CHANGED
|
@@ -99,18 +99,32 @@ class MenteDB {
|
|
|
99
99
|
ingest(conversation, provider, agentId) {
|
|
100
100
|
return this.native.ingest(conversation, provider ?? null, agentId ?? null);
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Store a memory and return its UUID. `sessionId`, `source` and
|
|
104
|
+
* `sourceRef` are recorded as its provenance on the first write.
|
|
105
|
+
*/
|
|
103
106
|
store(options) {
|
|
104
|
-
const { content, memoryType = types_1.MemoryType.Episodic, embedding = [], agentId, tags, } = options;
|
|
105
|
-
return this.native.store(content, memoryType, embedding, agentId, tags);
|
|
107
|
+
const { content, memoryType = types_1.MemoryType.Episodic, embedding = [], agentId, tags, sessionId, source, sourceRef, } = options;
|
|
108
|
+
return this.native.store(content, memoryType, embedding, agentId, tags, sessionId ?? null, source ?? null, sourceRef ?? null);
|
|
109
|
+
}
|
|
110
|
+
/** One stored memory with its provenance. Throws when the id is unknown. */
|
|
111
|
+
getMemory(memoryId) {
|
|
112
|
+
return this.native.getMemory(memoryId);
|
|
113
|
+
}
|
|
114
|
+
/** Ids of every memory written in `sessionId`. */
|
|
115
|
+
memoryIdsInSession(sessionId) {
|
|
116
|
+
return this.native.memoryIdsInSession(sessionId);
|
|
106
117
|
}
|
|
107
118
|
/** Recall memories using an MQL query string. */
|
|
108
119
|
recall(query) {
|
|
109
120
|
return this.native.recall(query);
|
|
110
121
|
}
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Vector similarity search returning top-k results, optionally narrowed to
|
|
124
|
+
* memories written in a session and/or from a kind of source.
|
|
125
|
+
*/
|
|
126
|
+
search(embedding, k = 10, filter = {}) {
|
|
127
|
+
return this.native.search(embedding, k, filter.sessionId ?? null, filter.source ?? null);
|
|
114
128
|
}
|
|
115
129
|
/** Create a typed, weighted edge between two memories. */
|
|
116
130
|
relate(source, target, edgeType = types_1.EdgeType.Related, weight = 1.0) {
|
|
@@ -131,6 +145,15 @@ class MenteDB {
|
|
|
131
145
|
const json = this.native.erase(memoryId, options.includeSources, options.verify);
|
|
132
146
|
return JSON.parse(json);
|
|
133
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Verified erase of every memory written in `sessionId` and everything
|
|
150
|
+
* derived from them, in one erase with one receipt. A session with no
|
|
151
|
+
* memories returns an empty receipt. See docs/PROVENANCE.md.
|
|
152
|
+
*/
|
|
153
|
+
eraseSession(sessionId, options = {}) {
|
|
154
|
+
const json = this.native.eraseSession(sessionId, options.includeSources, options.verify);
|
|
155
|
+
return JSON.parse(json);
|
|
156
|
+
}
|
|
134
157
|
/** Flush all data and close the database. */
|
|
135
158
|
close() {
|
|
136
159
|
this.native.close();
|
package/npm/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { MenteDB, CognitionStream, TrajectoryTracker } from './client';
|
|
2
2
|
export { MemoryType, EdgeType } from './types';
|
|
3
|
-
export type { RecallResult, SearchResult, StoreOptions, ErasureReceipt } from './types';
|
|
3
|
+
export type { RecallResult, SearchResult, StoreOptions, ErasureReceipt, SessionErasureReceipt, ErasureOutcome, Memory, Provenance, ProvenanceFilter, } from './types';
|
|
4
|
+
export { MemoryTool, MemoryToolError, MEMORY_TOOL_DEFINITION, DEFAULT_SERVER_URL } from './memoryTool';
|
|
5
|
+
export type { MemoryToolInput, MemoryToolResult, MemoryToolResultBlock, MemoryToolOptions, } from './memoryTool';
|
package/npm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EdgeType = exports.MemoryType = exports.TrajectoryTracker = exports.CognitionStream = exports.MenteDB = void 0;
|
|
3
|
+
exports.DEFAULT_SERVER_URL = exports.MEMORY_TOOL_DEFINITION = exports.MemoryToolError = exports.MemoryTool = exports.EdgeType = exports.MemoryType = exports.TrajectoryTracker = exports.CognitionStream = exports.MenteDB = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "MenteDB", { enumerable: true, get: function () { return client_1.MenteDB; } });
|
|
6
6
|
Object.defineProperty(exports, "CognitionStream", { enumerable: true, get: function () { return client_1.CognitionStream; } });
|
|
@@ -8,3 +8,8 @@ Object.defineProperty(exports, "TrajectoryTracker", { enumerable: true, get: fun
|
|
|
8
8
|
var types_1 = require("./types");
|
|
9
9
|
Object.defineProperty(exports, "MemoryType", { enumerable: true, get: function () { return types_1.MemoryType; } });
|
|
10
10
|
Object.defineProperty(exports, "EdgeType", { enumerable: true, get: function () { return types_1.EdgeType; } });
|
|
11
|
+
var memoryTool_1 = require("./memoryTool");
|
|
12
|
+
Object.defineProperty(exports, "MemoryTool", { enumerable: true, get: function () { return memoryTool_1.MemoryTool; } });
|
|
13
|
+
Object.defineProperty(exports, "MemoryToolError", { enumerable: true, get: function () { return memoryTool_1.MemoryToolError; } });
|
|
14
|
+
Object.defineProperty(exports, "MEMORY_TOOL_DEFINITION", { enumerable: true, get: function () { return memoryTool_1.MEMORY_TOOL_DEFINITION; } });
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_SERVER_URL", { enumerable: true, get: function () { return memoryTool_1.DEFAULT_SERVER_URL; } });
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend for the client side memory tool (`memory_20250818`), stored in MenteDB.
|
|
3
|
+
*
|
|
4
|
+
* The model sends file style commands (`view`, `create`, `str_replace`,
|
|
5
|
+
* `insert`, `delete`, `rename`) against a `/memories` directory. Your tool
|
|
6
|
+
* loop forwards each `tool_use` input to `POST /v1/memory_tool` and copies the
|
|
7
|
+
* reply into a `tool_result` block. `MemoryTool` does both steps. A
|
|
8
|
+
* self-hosted `mentedb-server` and MenteDB Cloud serve the same contract, so
|
|
9
|
+
* only the base URL and credential change.
|
|
10
|
+
*
|
|
11
|
+
* Uses the global `fetch` (Node 18+) and loads no native code, so it can be
|
|
12
|
+
* imported on its own: `import { MemoryTool } from 'mentedb/npm/memoryTool'`.
|
|
13
|
+
*/
|
|
14
|
+
/** Default address of a self-hosted `mentedb-server`. */
|
|
15
|
+
export declare const DEFAULT_SERVER_URL = "http://localhost:6677";
|
|
16
|
+
/** Tool definition to pass in `tools` on a Messages API request. */
|
|
17
|
+
export declare const MEMORY_TOOL_DEFINITION: {
|
|
18
|
+
readonly type: "memory_20250818";
|
|
19
|
+
readonly name: "memory";
|
|
20
|
+
};
|
|
21
|
+
/** The input of a memory `tool_use` block. */
|
|
22
|
+
export interface MemoryToolInput {
|
|
23
|
+
command: 'view' | 'create' | 'str_replace' | 'insert' | 'delete' | 'rename' | string;
|
|
24
|
+
path?: string;
|
|
25
|
+
view_range?: number[];
|
|
26
|
+
file_text?: string;
|
|
27
|
+
old_str?: string;
|
|
28
|
+
new_str?: string;
|
|
29
|
+
insert_line?: number;
|
|
30
|
+
insert_text?: string;
|
|
31
|
+
old_path?: string;
|
|
32
|
+
new_path?: string;
|
|
33
|
+
}
|
|
34
|
+
/** What the server returns for one command. */
|
|
35
|
+
export interface MemoryToolResult {
|
|
36
|
+
content: string;
|
|
37
|
+
is_error: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** A `tool_result` content block, ready to send back in a user message. */
|
|
40
|
+
export interface MemoryToolResultBlock {
|
|
41
|
+
type: 'tool_result';
|
|
42
|
+
tool_use_id: string;
|
|
43
|
+
content: string;
|
|
44
|
+
is_error?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** The parts of an assistant content block this helper reads. */
|
|
47
|
+
export interface ContentBlockLike {
|
|
48
|
+
type: string;
|
|
49
|
+
id?: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
input?: unknown;
|
|
52
|
+
}
|
|
53
|
+
export interface MemoryToolOptions {
|
|
54
|
+
/** e.g. `http://localhost:6677` (self-hosted) or `https://api.mentedb.com` (cloud). */
|
|
55
|
+
baseUrl?: string;
|
|
56
|
+
/** Bearer token: a server JWT, or an `mdb_` key for the cloud. Unset for a server without auth. */
|
|
57
|
+
token?: string;
|
|
58
|
+
/** A named database on a self-hosted server. Unset uses the default database. */
|
|
59
|
+
database?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Whose files to act on. A token bound to an agent always acts as that
|
|
62
|
+
* agent; this is for unbound or admin tokens and servers without auth.
|
|
63
|
+
*/
|
|
64
|
+
agentId?: string;
|
|
65
|
+
/** Optionally split one agent's files further by user. */
|
|
66
|
+
userId?: string;
|
|
67
|
+
/** Per request timeout in milliseconds. Default 30000. */
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
/** A `fetch` implementation. Defaults to the global one. */
|
|
70
|
+
fetch?: typeof fetch;
|
|
71
|
+
}
|
|
72
|
+
/** Auth, transport and server failures. Command failures are results, not errors. */
|
|
73
|
+
export declare class MemoryToolError extends Error {
|
|
74
|
+
readonly status?: number;
|
|
75
|
+
constructor(message: string, status?: number);
|
|
76
|
+
}
|
|
77
|
+
/** Runs memory tool calls against a MenteDB server. */
|
|
78
|
+
export declare class MemoryTool {
|
|
79
|
+
/** Tool definition to pass in `tools` on a Messages API request. */
|
|
80
|
+
static readonly TOOL: {
|
|
81
|
+
readonly type: "memory_20250818";
|
|
82
|
+
readonly name: "memory";
|
|
83
|
+
};
|
|
84
|
+
readonly url: string;
|
|
85
|
+
private readonly token?;
|
|
86
|
+
private readonly agentId?;
|
|
87
|
+
private readonly userId?;
|
|
88
|
+
private readonly timeoutMs;
|
|
89
|
+
private readonly fetchImpl;
|
|
90
|
+
constructor(options?: MemoryToolOptions);
|
|
91
|
+
/**
|
|
92
|
+
* Run one command. Command failures the model can fix (a missing file, a
|
|
93
|
+
* bad range, an invalid path) come back with `is_error` set; auth and
|
|
94
|
+
* server failures throw `MemoryToolError`.
|
|
95
|
+
*/
|
|
96
|
+
execute(input: MemoryToolInput | Record<string, unknown>): Promise<MemoryToolResult>;
|
|
97
|
+
/** Turn one memory `tool_use` block into its `tool_result` block. */
|
|
98
|
+
handle(toolUse: ContentBlockLike): Promise<MemoryToolResultBlock>;
|
|
99
|
+
/**
|
|
100
|
+
* `tool_result` blocks for every memory call in an assistant turn. Pass
|
|
101
|
+
* `response.content`; other blocks are skipped. Send all results in one
|
|
102
|
+
* user message.
|
|
103
|
+
*/
|
|
104
|
+
results(content: ReadonlyArray<ContentBlockLike>): Promise<MemoryToolResultBlock[]>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Backend for the client side memory tool (`memory_20250818`), stored in MenteDB.
|
|
4
|
+
*
|
|
5
|
+
* The model sends file style commands (`view`, `create`, `str_replace`,
|
|
6
|
+
* `insert`, `delete`, `rename`) against a `/memories` directory. Your tool
|
|
7
|
+
* loop forwards each `tool_use` input to `POST /v1/memory_tool` and copies the
|
|
8
|
+
* reply into a `tool_result` block. `MemoryTool` does both steps. A
|
|
9
|
+
* self-hosted `mentedb-server` and MenteDB Cloud serve the same contract, so
|
|
10
|
+
* only the base URL and credential change.
|
|
11
|
+
*
|
|
12
|
+
* Uses the global `fetch` (Node 18+) and loads no native code, so it can be
|
|
13
|
+
* imported on its own: `import { MemoryTool } from 'mentedb/npm/memoryTool'`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.MemoryTool = exports.MemoryToolError = exports.MEMORY_TOOL_DEFINITION = exports.DEFAULT_SERVER_URL = void 0;
|
|
17
|
+
/** Default address of a self-hosted `mentedb-server`. */
|
|
18
|
+
exports.DEFAULT_SERVER_URL = 'http://localhost:6677';
|
|
19
|
+
/** Tool definition to pass in `tools` on a Messages API request. */
|
|
20
|
+
exports.MEMORY_TOOL_DEFINITION = { type: 'memory_20250818', name: 'memory' };
|
|
21
|
+
/** Auth, transport and server failures. Command failures are results, not errors. */
|
|
22
|
+
class MemoryToolError extends Error {
|
|
23
|
+
constructor(message, status) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'MemoryToolError';
|
|
26
|
+
this.status = status;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.MemoryToolError = MemoryToolError;
|
|
30
|
+
/** Runs memory tool calls against a MenteDB server. */
|
|
31
|
+
class MemoryTool {
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
const base = (options.baseUrl ?? exports.DEFAULT_SERVER_URL).replace(/\/+$/, '');
|
|
34
|
+
this.url = options.database
|
|
35
|
+
? `${base}/v1/db/${encodeURIComponent(options.database)}/memory_tool`
|
|
36
|
+
: `${base}/v1/memory_tool`;
|
|
37
|
+
this.token = options.token;
|
|
38
|
+
this.agentId = options.agentId;
|
|
39
|
+
this.userId = options.userId;
|
|
40
|
+
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
41
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Run one command. Command failures the model can fix (a missing file, a
|
|
45
|
+
* bad range, an invalid path) come back with `is_error` set; auth and
|
|
46
|
+
* server failures throw `MemoryToolError`.
|
|
47
|
+
*/
|
|
48
|
+
async execute(input) {
|
|
49
|
+
const body = {};
|
|
50
|
+
for (const [key, value] of Object.entries(input ?? {})) {
|
|
51
|
+
if (value !== undefined && value !== null)
|
|
52
|
+
body[key] = value;
|
|
53
|
+
}
|
|
54
|
+
if (this.agentId !== undefined)
|
|
55
|
+
body.agent_id = this.agentId;
|
|
56
|
+
if (this.userId !== undefined)
|
|
57
|
+
body.user_id = this.userId;
|
|
58
|
+
const headers = { 'content-type': 'application/json' };
|
|
59
|
+
if (this.token)
|
|
60
|
+
headers.authorization = `Bearer ${this.token}`;
|
|
61
|
+
let response;
|
|
62
|
+
try {
|
|
63
|
+
response = await this.fetchImpl(this.url, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers,
|
|
66
|
+
body: JSON.stringify(body),
|
|
67
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
throw new MemoryToolError(`mentedb unreachable at ${this.url}: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
const text = await response.text();
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
throw new MemoryToolError(`mentedb ${response.status}: ${text}`, response.status);
|
|
76
|
+
}
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(text);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new MemoryToolError(`unexpected memory tool reply: ${text}`, response.status);
|
|
83
|
+
}
|
|
84
|
+
const reply = parsed;
|
|
85
|
+
if (!reply || typeof reply.content !== 'string') {
|
|
86
|
+
throw new MemoryToolError(`unexpected memory tool reply: ${text}`, response.status);
|
|
87
|
+
}
|
|
88
|
+
return { content: reply.content, is_error: Boolean(reply.is_error) };
|
|
89
|
+
}
|
|
90
|
+
/** Turn one memory `tool_use` block into its `tool_result` block. */
|
|
91
|
+
async handle(toolUse) {
|
|
92
|
+
const result = await this.execute((toolUse.input ?? {}));
|
|
93
|
+
const block = {
|
|
94
|
+
type: 'tool_result',
|
|
95
|
+
tool_use_id: toolUse.id ?? '',
|
|
96
|
+
content: result.content,
|
|
97
|
+
};
|
|
98
|
+
if (result.is_error)
|
|
99
|
+
block.is_error = true;
|
|
100
|
+
return block;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* `tool_result` blocks for every memory call in an assistant turn. Pass
|
|
104
|
+
* `response.content`; other blocks are skipped. Send all results in one
|
|
105
|
+
* user message.
|
|
106
|
+
*/
|
|
107
|
+
async results(content) {
|
|
108
|
+
const out = [];
|
|
109
|
+
for (const block of content) {
|
|
110
|
+
if (block.type === 'tool_use' && block.name === exports.MEMORY_TOOL_DEFINITION.name) {
|
|
111
|
+
out.push(await this.handle(block));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.MemoryTool = MemoryTool;
|
|
118
|
+
/** Tool definition to pass in `tools` on a Messages API request. */
|
|
119
|
+
MemoryTool.TOOL = exports.MEMORY_TOOL_DEFINITION;
|
package/npm/types.d.ts
CHANGED
|
@@ -31,6 +31,42 @@ export interface StoreOptions {
|
|
|
31
31
|
embedding?: number[];
|
|
32
32
|
agentId?: string;
|
|
33
33
|
tags?: string[];
|
|
34
|
+
/** The session the memory is written in (its provenance). */
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
/** chat, file, api, mcp, import, or another name. Defaults to api. */
|
|
37
|
+
source?: string;
|
|
38
|
+
/** A file path, URL or message id within the source. */
|
|
39
|
+
sourceRef?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Where a memory came from, recorded when it was first written and never
|
|
43
|
+
* changed afterwards. See docs/PROVENANCE.md.
|
|
44
|
+
*/
|
|
45
|
+
export interface Provenance {
|
|
46
|
+
sessionId?: string | null;
|
|
47
|
+
source: string;
|
|
48
|
+
sourceRef?: string | null;
|
|
49
|
+
writtenBy: string;
|
|
50
|
+
/** Microseconds since the Unix epoch. */
|
|
51
|
+
writtenAt: number;
|
|
52
|
+
/** For a derived memory, the memories it was made from. */
|
|
53
|
+
derivedFrom: string[];
|
|
54
|
+
}
|
|
55
|
+
/** One stored memory, as `getMemory` returns it. */
|
|
56
|
+
export interface Memory {
|
|
57
|
+
id: string;
|
|
58
|
+
content: string;
|
|
59
|
+
memoryType: string;
|
|
60
|
+
agentId: string;
|
|
61
|
+
tags: string[];
|
|
62
|
+
createdAt: number;
|
|
63
|
+
/** Absent for a memory written before provenance existed. */
|
|
64
|
+
provenance?: Provenance | null;
|
|
65
|
+
}
|
|
66
|
+
/** Narrow a search to memories by provenance. */
|
|
67
|
+
export interface ProvenanceFilter {
|
|
68
|
+
sessionId?: string;
|
|
69
|
+
source?: string;
|
|
34
70
|
}
|
|
35
71
|
/** A single memory selected for the working-context window. */
|
|
36
72
|
export interface ContextItem {
|
|
@@ -103,8 +139,20 @@ export interface ResidualHit {
|
|
|
103
139
|
kind: 'content' | 'embedding';
|
|
104
140
|
}
|
|
105
141
|
/** Result of `MenteDB.erase`. Carries ids and hashes, never content. */
|
|
106
|
-
export interface ErasureReceipt {
|
|
142
|
+
export interface ErasureReceipt extends ErasureOutcome {
|
|
107
143
|
requested: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Result of `MenteDB.eraseSession`: one erase over every memory written in
|
|
147
|
+
* the session and everything derived from them.
|
|
148
|
+
*/
|
|
149
|
+
export interface SessionErasureReceipt extends ErasureOutcome {
|
|
150
|
+
session_id: string;
|
|
151
|
+
/** The memories written in the session. */
|
|
152
|
+
requested: string[];
|
|
153
|
+
}
|
|
154
|
+
/** What every erase receipt carries. */
|
|
155
|
+
export interface ErasureOutcome {
|
|
108
156
|
erased: ErasedMemory[];
|
|
109
157
|
ancestors_kept: string[];
|
|
110
158
|
profiles_to_review: string[];
|