agent-memory-client 0.2.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/dist/index.d.mts +828 -0
- package/dist/index.d.ts +828 -0
- package/dist/index.js +646 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +631 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var MemoryClientError = class _MemoryClientError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "MemoryClientError";
|
|
6
|
+
if (Error.captureStackTrace) {
|
|
7
|
+
Error.captureStackTrace(this, _MemoryClientError);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var MemoryValidationError = class extends MemoryClientError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "MemoryValidationError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var MemoryNotFoundError = class extends MemoryClientError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "MemoryNotFoundError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var MemoryServerError = class extends MemoryClientError {
|
|
24
|
+
statusCode;
|
|
25
|
+
constructor(message, statusCode) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "MemoryServerError";
|
|
28
|
+
this.statusCode = statusCode;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/filters.ts
|
|
33
|
+
var SessionId = class {
|
|
34
|
+
eq;
|
|
35
|
+
in_;
|
|
36
|
+
not_eq;
|
|
37
|
+
not_in;
|
|
38
|
+
ne;
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this.eq = options.eq;
|
|
41
|
+
this.in_ = options.in_;
|
|
42
|
+
this.not_eq = options.not_eq;
|
|
43
|
+
this.not_in = options.not_in;
|
|
44
|
+
this.ne = options.ne;
|
|
45
|
+
}
|
|
46
|
+
toJSON() {
|
|
47
|
+
const result = {};
|
|
48
|
+
if (this.eq !== void 0) result.eq = this.eq;
|
|
49
|
+
if (this.in_ !== void 0) result.in_ = this.in_;
|
|
50
|
+
if (this.not_eq !== void 0) result.not_eq = this.not_eq;
|
|
51
|
+
if (this.not_in !== void 0) result.not_in = this.not_in;
|
|
52
|
+
if (this.ne !== void 0) result.ne = this.ne;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var Namespace = class {
|
|
57
|
+
eq;
|
|
58
|
+
in_;
|
|
59
|
+
not_eq;
|
|
60
|
+
not_in;
|
|
61
|
+
constructor(options = {}) {
|
|
62
|
+
this.eq = options.eq;
|
|
63
|
+
this.in_ = options.in_;
|
|
64
|
+
this.not_eq = options.not_eq;
|
|
65
|
+
this.not_in = options.not_in;
|
|
66
|
+
}
|
|
67
|
+
toJSON() {
|
|
68
|
+
const result = {};
|
|
69
|
+
if (this.eq !== void 0) result.eq = this.eq;
|
|
70
|
+
if (this.in_ !== void 0) result.in_ = this.in_;
|
|
71
|
+
if (this.not_eq !== void 0) result.not_eq = this.not_eq;
|
|
72
|
+
if (this.not_in !== void 0) result.not_in = this.not_in;
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var UserId = class {
|
|
77
|
+
eq;
|
|
78
|
+
in_;
|
|
79
|
+
not_eq;
|
|
80
|
+
not_in;
|
|
81
|
+
constructor(options = {}) {
|
|
82
|
+
this.eq = options.eq;
|
|
83
|
+
this.in_ = options.in_;
|
|
84
|
+
this.not_eq = options.not_eq;
|
|
85
|
+
this.not_in = options.not_in;
|
|
86
|
+
}
|
|
87
|
+
toJSON() {
|
|
88
|
+
const result = {};
|
|
89
|
+
if (this.eq !== void 0) result.eq = this.eq;
|
|
90
|
+
if (this.in_ !== void 0) result.in_ = this.in_;
|
|
91
|
+
if (this.not_eq !== void 0) result.not_eq = this.not_eq;
|
|
92
|
+
if (this.not_in !== void 0) result.not_in = this.not_in;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var Topics = class {
|
|
97
|
+
any;
|
|
98
|
+
all;
|
|
99
|
+
none;
|
|
100
|
+
constructor(options = {}) {
|
|
101
|
+
this.any = options.any;
|
|
102
|
+
this.all = options.all;
|
|
103
|
+
this.none = options.none;
|
|
104
|
+
}
|
|
105
|
+
toJSON() {
|
|
106
|
+
const result = {};
|
|
107
|
+
if (this.any !== void 0) result.any = this.any;
|
|
108
|
+
if (this.all !== void 0) result.all = this.all;
|
|
109
|
+
if (this.none !== void 0) result.none = this.none;
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var Entities = class {
|
|
114
|
+
any;
|
|
115
|
+
all;
|
|
116
|
+
none;
|
|
117
|
+
constructor(options = {}) {
|
|
118
|
+
this.any = options.any;
|
|
119
|
+
this.all = options.all;
|
|
120
|
+
this.none = options.none;
|
|
121
|
+
}
|
|
122
|
+
toJSON() {
|
|
123
|
+
const result = {};
|
|
124
|
+
if (this.any !== void 0) result.any = this.any;
|
|
125
|
+
if (this.all !== void 0) result.all = this.all;
|
|
126
|
+
if (this.none !== void 0) result.none = this.none;
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var CreatedAt = class {
|
|
131
|
+
gte;
|
|
132
|
+
lte;
|
|
133
|
+
eq;
|
|
134
|
+
constructor(options = {}) {
|
|
135
|
+
this.gte = options.gte;
|
|
136
|
+
this.lte = options.lte;
|
|
137
|
+
this.eq = options.eq;
|
|
138
|
+
}
|
|
139
|
+
toJSON() {
|
|
140
|
+
const result = {};
|
|
141
|
+
if (this.gte !== void 0)
|
|
142
|
+
result.gte = this.gte instanceof Date ? this.gte.toISOString() : this.gte;
|
|
143
|
+
if (this.lte !== void 0)
|
|
144
|
+
result.lte = this.lte instanceof Date ? this.lte.toISOString() : this.lte;
|
|
145
|
+
if (this.eq !== void 0)
|
|
146
|
+
result.eq = this.eq instanceof Date ? this.eq.toISOString() : this.eq;
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var LastAccessed = class {
|
|
151
|
+
gte;
|
|
152
|
+
lte;
|
|
153
|
+
eq;
|
|
154
|
+
constructor(options = {}) {
|
|
155
|
+
this.gte = options.gte;
|
|
156
|
+
this.lte = options.lte;
|
|
157
|
+
this.eq = options.eq;
|
|
158
|
+
}
|
|
159
|
+
toJSON() {
|
|
160
|
+
const result = {};
|
|
161
|
+
if (this.gte !== void 0)
|
|
162
|
+
result.gte = this.gte instanceof Date ? this.gte.toISOString() : this.gte;
|
|
163
|
+
if (this.lte !== void 0)
|
|
164
|
+
result.lte = this.lte instanceof Date ? this.lte.toISOString() : this.lte;
|
|
165
|
+
if (this.eq !== void 0)
|
|
166
|
+
result.eq = this.eq instanceof Date ? this.eq.toISOString() : this.eq;
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var EventDate = class {
|
|
171
|
+
gte;
|
|
172
|
+
lte;
|
|
173
|
+
eq;
|
|
174
|
+
constructor(options = {}) {
|
|
175
|
+
this.gte = options.gte;
|
|
176
|
+
this.lte = options.lte;
|
|
177
|
+
this.eq = options.eq;
|
|
178
|
+
}
|
|
179
|
+
toJSON() {
|
|
180
|
+
const result = {};
|
|
181
|
+
if (this.gte !== void 0)
|
|
182
|
+
result.gte = this.gte instanceof Date ? this.gte.toISOString() : this.gte;
|
|
183
|
+
if (this.lte !== void 0)
|
|
184
|
+
result.lte = this.lte instanceof Date ? this.lte.toISOString() : this.lte;
|
|
185
|
+
if (this.eq !== void 0)
|
|
186
|
+
result.eq = this.eq instanceof Date ? this.eq.toISOString() : this.eq;
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
var MemoryType = class {
|
|
191
|
+
eq;
|
|
192
|
+
in_;
|
|
193
|
+
not_eq;
|
|
194
|
+
not_in;
|
|
195
|
+
constructor(options = {}) {
|
|
196
|
+
this.eq = options.eq;
|
|
197
|
+
this.in_ = options.in_;
|
|
198
|
+
this.not_eq = options.not_eq;
|
|
199
|
+
this.not_in = options.not_in;
|
|
200
|
+
}
|
|
201
|
+
toJSON() {
|
|
202
|
+
const result = {};
|
|
203
|
+
if (this.eq !== void 0) result.eq = this.eq;
|
|
204
|
+
if (this.in_ !== void 0) result.in_ = this.in_;
|
|
205
|
+
if (this.not_eq !== void 0) result.not_eq = this.not_eq;
|
|
206
|
+
if (this.not_in !== void 0) result.not_in = this.not_in;
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/client.ts
|
|
212
|
+
var VERSION = "0.1.0";
|
|
213
|
+
var MemoryAPIClient = class {
|
|
214
|
+
config;
|
|
215
|
+
fetchFn;
|
|
216
|
+
constructor(config) {
|
|
217
|
+
this.config = {
|
|
218
|
+
timeout: 3e4,
|
|
219
|
+
...config,
|
|
220
|
+
baseUrl: config.baseUrl.replace(/\/$/, "")
|
|
221
|
+
// Remove trailing slash
|
|
222
|
+
};
|
|
223
|
+
this.fetchFn = config.fetch ?? fetch;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get default headers for requests
|
|
227
|
+
*/
|
|
228
|
+
getHeaders() {
|
|
229
|
+
const headers = {
|
|
230
|
+
"Content-Type": "application/json",
|
|
231
|
+
"User-Agent": `agent-memory-client-js/${VERSION}`,
|
|
232
|
+
"X-Client-Version": VERSION
|
|
233
|
+
};
|
|
234
|
+
if (this.config.apiKey) {
|
|
235
|
+
headers["X-API-Key"] = this.config.apiKey;
|
|
236
|
+
}
|
|
237
|
+
if (this.config.bearerToken) {
|
|
238
|
+
headers["Authorization"] = `Bearer ${this.config.bearerToken}`;
|
|
239
|
+
}
|
|
240
|
+
return headers;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Make an HTTP request with error handling
|
|
244
|
+
*/
|
|
245
|
+
async request(method, path, options = {}) {
|
|
246
|
+
const url = new URL(path, this.config.baseUrl);
|
|
247
|
+
if (options.params) {
|
|
248
|
+
for (const [key, value] of Object.entries(options.params)) {
|
|
249
|
+
if (value !== void 0) {
|
|
250
|
+
if (Array.isArray(value)) {
|
|
251
|
+
for (const item of value) {
|
|
252
|
+
url.searchParams.append(key, String(item));
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
url.searchParams.set(key, String(value));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const controller = new AbortController();
|
|
261
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
262
|
+
try {
|
|
263
|
+
const response = await this.fetchFn(url.toString(), {
|
|
264
|
+
method,
|
|
265
|
+
headers: this.getHeaders(),
|
|
266
|
+
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
267
|
+
signal: controller.signal
|
|
268
|
+
});
|
|
269
|
+
clearTimeout(timeoutId);
|
|
270
|
+
if (!response.ok) {
|
|
271
|
+
return this.handleHttpError(response);
|
|
272
|
+
}
|
|
273
|
+
return await response.json();
|
|
274
|
+
} catch (error) {
|
|
275
|
+
clearTimeout(timeoutId);
|
|
276
|
+
if (error instanceof MemoryClientError) {
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
280
|
+
throw new MemoryClientError(`Request timeout after ${this.config.timeout}ms`);
|
|
281
|
+
}
|
|
282
|
+
throw new MemoryClientError(`Request failed: ${String(error)}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Handle HTTP error responses
|
|
287
|
+
*/
|
|
288
|
+
async handleHttpError(response) {
|
|
289
|
+
let message;
|
|
290
|
+
try {
|
|
291
|
+
const body = await response.json();
|
|
292
|
+
message = body.detail || body.message || JSON.stringify(body);
|
|
293
|
+
} catch {
|
|
294
|
+
message = await response.text();
|
|
295
|
+
}
|
|
296
|
+
if (response.status === 404) {
|
|
297
|
+
throw new MemoryNotFoundError(message);
|
|
298
|
+
}
|
|
299
|
+
throw new MemoryServerError(message, response.status);
|
|
300
|
+
}
|
|
301
|
+
// ==================== Health ====================
|
|
302
|
+
/**
|
|
303
|
+
* Check server health
|
|
304
|
+
*/
|
|
305
|
+
async healthCheck() {
|
|
306
|
+
return this.request("GET", "/v1/health");
|
|
307
|
+
}
|
|
308
|
+
// ==================== Working Memory ====================
|
|
309
|
+
/**
|
|
310
|
+
* List all session IDs
|
|
311
|
+
*/
|
|
312
|
+
async listSessions(options = {}) {
|
|
313
|
+
return this.request("GET", "/v1/working-memory/", {
|
|
314
|
+
params: {
|
|
315
|
+
namespace: options.namespace ?? this.config.defaultNamespace,
|
|
316
|
+
limit: options.limit,
|
|
317
|
+
offset: options.offset
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get working memory for a session
|
|
323
|
+
*/
|
|
324
|
+
async getWorkingMemory(sessionId, options = {}) {
|
|
325
|
+
try {
|
|
326
|
+
return await this.request(
|
|
327
|
+
"GET",
|
|
328
|
+
`/v1/working-memory/${encodeURIComponent(sessionId)}`,
|
|
329
|
+
{
|
|
330
|
+
params: {
|
|
331
|
+
namespace: options.namespace ?? this.config.defaultNamespace,
|
|
332
|
+
model_name: options.modelName ?? this.config.defaultModelName,
|
|
333
|
+
context_window_max: options.contextWindowMax ?? this.config.defaultContextWindowMax
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error instanceof MemoryNotFoundError) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Get or create working memory for a session
|
|
346
|
+
*/
|
|
347
|
+
async getOrCreateWorkingMemory(sessionId, options = {}) {
|
|
348
|
+
const existing = await this.getWorkingMemory(sessionId, options);
|
|
349
|
+
if (existing) {
|
|
350
|
+
return existing;
|
|
351
|
+
}
|
|
352
|
+
const workingMemory = {
|
|
353
|
+
session_id: sessionId,
|
|
354
|
+
namespace: options.namespace ?? this.config.defaultNamespace,
|
|
355
|
+
user_id: options.userId,
|
|
356
|
+
messages: [],
|
|
357
|
+
memories: [],
|
|
358
|
+
ttl_seconds: options.ttlSeconds,
|
|
359
|
+
long_term_memory_strategy: options.longTermMemoryStrategy
|
|
360
|
+
};
|
|
361
|
+
return this.putWorkingMemory(sessionId, workingMemory, options);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Create or update working memory for a session
|
|
365
|
+
*/
|
|
366
|
+
async putWorkingMemory(sessionId, workingMemory, options = {}) {
|
|
367
|
+
const body = {
|
|
368
|
+
session_id: sessionId,
|
|
369
|
+
...workingMemory,
|
|
370
|
+
namespace: workingMemory.namespace ?? options.namespace ?? this.config.defaultNamespace
|
|
371
|
+
};
|
|
372
|
+
return this.request(
|
|
373
|
+
"PUT",
|
|
374
|
+
`/v1/working-memory/${encodeURIComponent(sessionId)}`,
|
|
375
|
+
{
|
|
376
|
+
body,
|
|
377
|
+
params: {
|
|
378
|
+
model_name: options.modelName ?? this.config.defaultModelName,
|
|
379
|
+
context_window_max: options.contextWindowMax ?? this.config.defaultContextWindowMax,
|
|
380
|
+
background: options.background
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Delete working memory for a session
|
|
387
|
+
*/
|
|
388
|
+
async deleteWorkingMemory(sessionId, options = {}) {
|
|
389
|
+
return this.request(
|
|
390
|
+
"DELETE",
|
|
391
|
+
`/v1/working-memory/${encodeURIComponent(sessionId)}`,
|
|
392
|
+
{
|
|
393
|
+
params: {
|
|
394
|
+
namespace: options.namespace ?? this.config.defaultNamespace
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
// ==================== Long-term Memory ====================
|
|
400
|
+
/**
|
|
401
|
+
* Create long-term memory records
|
|
402
|
+
*/
|
|
403
|
+
async createLongTermMemory(memories, options = {}) {
|
|
404
|
+
return this.request("POST", "/v1/long-term-memory/", {
|
|
405
|
+
body: { memories },
|
|
406
|
+
params: {
|
|
407
|
+
namespace: options.namespace ?? this.config.defaultNamespace
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Search long-term memory
|
|
413
|
+
*/
|
|
414
|
+
async searchLongTermMemory(options) {
|
|
415
|
+
const body = {
|
|
416
|
+
text: options.text,
|
|
417
|
+
limit: options.limit,
|
|
418
|
+
offset: options.offset,
|
|
419
|
+
distance_threshold: options.distanceThreshold
|
|
420
|
+
};
|
|
421
|
+
if (options.sessionId) {
|
|
422
|
+
body.session_id = options.sessionId instanceof SessionId ? options.sessionId.toJSON() : options.sessionId;
|
|
423
|
+
}
|
|
424
|
+
if (options.namespace) {
|
|
425
|
+
body.namespace = options.namespace instanceof Namespace ? options.namespace.toJSON() : options.namespace;
|
|
426
|
+
}
|
|
427
|
+
if (options.topics) {
|
|
428
|
+
body.topics = options.topics instanceof Topics ? options.topics.toJSON() : options.topics;
|
|
429
|
+
}
|
|
430
|
+
if (options.entities) {
|
|
431
|
+
body.entities = options.entities instanceof Entities ? options.entities.toJSON() : options.entities;
|
|
432
|
+
}
|
|
433
|
+
if (options.createdAt) {
|
|
434
|
+
body.created_at = options.createdAt instanceof CreatedAt ? options.createdAt.toJSON() : options.createdAt;
|
|
435
|
+
}
|
|
436
|
+
if (options.lastAccessed) {
|
|
437
|
+
body.last_accessed = options.lastAccessed instanceof LastAccessed ? options.lastAccessed.toJSON() : options.lastAccessed;
|
|
438
|
+
}
|
|
439
|
+
if (options.userId) {
|
|
440
|
+
body.user_id = options.userId instanceof UserId ? options.userId.toJSON() : options.userId;
|
|
441
|
+
}
|
|
442
|
+
if (options.memoryType) {
|
|
443
|
+
body.memory_type = options.memoryType instanceof MemoryType ? options.memoryType.toJSON() : options.memoryType;
|
|
444
|
+
}
|
|
445
|
+
if (options.eventDate) {
|
|
446
|
+
body.event_date = options.eventDate instanceof EventDate ? options.eventDate.toJSON() : options.eventDate;
|
|
447
|
+
}
|
|
448
|
+
if (options.recency) {
|
|
449
|
+
body.recency_boost = options.recency.recency_boost;
|
|
450
|
+
body.recency_semantic_weight = options.recency.semantic_weight;
|
|
451
|
+
body.recency_recency_weight = options.recency.recency_weight;
|
|
452
|
+
body.recency_freshness_weight = options.recency.freshness_weight;
|
|
453
|
+
body.recency_novelty_weight = options.recency.novelty_weight;
|
|
454
|
+
body.recency_half_life_last_access_days = options.recency.half_life_last_access_days;
|
|
455
|
+
body.recency_half_life_created_days = options.recency.half_life_created_days;
|
|
456
|
+
body.server_side_recency = options.recency.server_side_recency;
|
|
457
|
+
}
|
|
458
|
+
return this.request("POST", "/v1/long-term-memory/search", {
|
|
459
|
+
body
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Get a long-term memory by ID
|
|
464
|
+
*/
|
|
465
|
+
async getLongTermMemory(memoryId, options = {}) {
|
|
466
|
+
try {
|
|
467
|
+
return await this.request(
|
|
468
|
+
"GET",
|
|
469
|
+
`/v1/long-term-memory/${encodeURIComponent(memoryId)}`,
|
|
470
|
+
{
|
|
471
|
+
params: {
|
|
472
|
+
namespace: options.namespace ?? this.config.defaultNamespace
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
} catch (error) {
|
|
477
|
+
if (error instanceof MemoryNotFoundError) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
throw error;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Delete long-term memories by IDs
|
|
485
|
+
*/
|
|
486
|
+
async deleteLongTermMemories(memoryIds, options = {}) {
|
|
487
|
+
return this.request("DELETE", "/v1/long-term-memory", {
|
|
488
|
+
params: {
|
|
489
|
+
memory_ids: memoryIds,
|
|
490
|
+
namespace: options.namespace ?? this.config.defaultNamespace
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
// ==================== Memory Prompt ====================
|
|
495
|
+
/**
|
|
496
|
+
* Get memory-enhanced prompt
|
|
497
|
+
*/
|
|
498
|
+
async memoryPrompt(request) {
|
|
499
|
+
return this.request("POST", "/v1/memory/prompt", {
|
|
500
|
+
body: request
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
// ==================== Edit Long-term Memory ====================
|
|
504
|
+
/**
|
|
505
|
+
* Edit a long-term memory by ID
|
|
506
|
+
*/
|
|
507
|
+
async editLongTermMemory(memoryId, updates) {
|
|
508
|
+
return this.request(
|
|
509
|
+
"PATCH",
|
|
510
|
+
`/v1/long-term-memory/${encodeURIComponent(memoryId)}`,
|
|
511
|
+
{ body: updates }
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
// ==================== Forget ====================
|
|
515
|
+
/**
|
|
516
|
+
* Run a forgetting pass with the provided policy
|
|
517
|
+
*/
|
|
518
|
+
async forgetLongTermMemories(options) {
|
|
519
|
+
return this.request("POST", "/v1/long-term-memory/forget", {
|
|
520
|
+
params: {
|
|
521
|
+
namespace: options.namespace,
|
|
522
|
+
user_id: options.userId,
|
|
523
|
+
session_id: options.sessionId,
|
|
524
|
+
limit: options.limit,
|
|
525
|
+
dry_run: options.dryRun
|
|
526
|
+
},
|
|
527
|
+
body: {
|
|
528
|
+
policy: options.policy,
|
|
529
|
+
pinned_ids: options.pinnedIds
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
// ==================== Summary Views ====================
|
|
534
|
+
/**
|
|
535
|
+
* List all summary views
|
|
536
|
+
*/
|
|
537
|
+
async listSummaryViews() {
|
|
538
|
+
return this.request("GET", "/v1/summary-views");
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Create a new summary view
|
|
542
|
+
*/
|
|
543
|
+
async createSummaryView(request) {
|
|
544
|
+
return this.request("POST", "/v1/summary-views", {
|
|
545
|
+
body: request
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Get a summary view by ID
|
|
550
|
+
*/
|
|
551
|
+
async getSummaryView(viewId) {
|
|
552
|
+
try {
|
|
553
|
+
return await this.request(
|
|
554
|
+
"GET",
|
|
555
|
+
`/v1/summary-views/${encodeURIComponent(viewId)}`
|
|
556
|
+
);
|
|
557
|
+
} catch (error) {
|
|
558
|
+
if (error instanceof MemoryNotFoundError) {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
throw error;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Delete a summary view
|
|
566
|
+
*/
|
|
567
|
+
async deleteSummaryView(viewId) {
|
|
568
|
+
return this.request(
|
|
569
|
+
"DELETE",
|
|
570
|
+
`/v1/summary-views/${encodeURIComponent(viewId)}`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Run a summary view partition
|
|
575
|
+
*/
|
|
576
|
+
async runSummaryViewPartition(viewId, group) {
|
|
577
|
+
return this.request(
|
|
578
|
+
"POST",
|
|
579
|
+
`/v1/summary-views/${encodeURIComponent(viewId)}/partitions/run`,
|
|
580
|
+
{ body: { group } }
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* List summary view partitions
|
|
585
|
+
*/
|
|
586
|
+
async listSummaryViewPartitions(viewId, options = {}) {
|
|
587
|
+
return this.request(
|
|
588
|
+
"GET",
|
|
589
|
+
`/v1/summary-views/${encodeURIComponent(viewId)}/partitions`,
|
|
590
|
+
{
|
|
591
|
+
params: {
|
|
592
|
+
namespace: options.namespace,
|
|
593
|
+
user_id: options.userId,
|
|
594
|
+
session_id: options.sessionId,
|
|
595
|
+
memory_type: options.memoryType
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Run a full summary view (async task)
|
|
602
|
+
*/
|
|
603
|
+
async runSummaryView(viewId, options = {}) {
|
|
604
|
+
return this.request(
|
|
605
|
+
"POST",
|
|
606
|
+
`/v1/summary-views/${encodeURIComponent(viewId)}/run`,
|
|
607
|
+
{ body: options }
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
// ==================== Tasks ====================
|
|
611
|
+
/**
|
|
612
|
+
* Get a task by ID
|
|
613
|
+
*/
|
|
614
|
+
async getTask(taskId) {
|
|
615
|
+
try {
|
|
616
|
+
return await this.request(
|
|
617
|
+
"GET",
|
|
618
|
+
`/v1/tasks/${encodeURIComponent(taskId)}`
|
|
619
|
+
);
|
|
620
|
+
} catch (error) {
|
|
621
|
+
if (error instanceof MemoryNotFoundError) {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
throw error;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
export { CreatedAt, Entities, EventDate, LastAccessed, MemoryAPIClient, MemoryClientError, MemoryNotFoundError, MemoryServerError, MemoryType, MemoryValidationError, Namespace, SessionId, Topics, UserId };
|
|
630
|
+
//# sourceMappingURL=index.mjs.map
|
|
631
|
+
//# sourceMappingURL=index.mjs.map
|