@mingxy/cerebro 1.8.3 → 1.10.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/client.d.ts +4 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -2
- package/dist/client.js.map +1 -1
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +135 -5
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -25
- package/dist/index.js.map +1 -1
- package/dist/tools.d.ts +2 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +32 -9
- package/dist/tools.js.map +1 -1
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +20 -4
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +386 -380
- package/src/hooks.ts +575 -453
- package/src/index.ts +151 -151
- package/src/tools.ts +35 -7
package/src/client.ts
CHANGED
|
@@ -1,380 +1,386 @@
|
|
|
1
|
-
import { logWarn, logError } from "./logger.js";
|
|
2
|
-
import type { OmemPluginConfig } from "./config.js";
|
|
3
|
-
|
|
4
|
-
function sanitizeContent(text: string, maxLen: number): string {
|
|
5
|
-
let clean = text.replace(/<[\w-]+[^>]*>[\s\S]*?<\/[\w-]+>/g, "");
|
|
6
|
-
clean = clean.replace(/<[\w-]+[^>]*\/>/g, "");
|
|
7
|
-
clean = clean.replace(/\s+/g, " ").trim();
|
|
8
|
-
if (clean.length <= maxLen) return clean;
|
|
9
|
-
return clean.slice(0, maxLen) + "…[truncated]";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function truncateQuery(query: string, maxLen: number): string {
|
|
13
|
-
if (query.length <= maxLen) return query;
|
|
14
|
-
return query.slice(0, maxLen);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IngestOptions {
|
|
18
|
-
mode?: "smart" | "raw";
|
|
19
|
-
agentId?: string;
|
|
20
|
-
sessionId?: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
private
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async
|
|
251
|
-
return this.request("/v1/
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
async
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
1
|
+
import { logWarn, logError } from "./logger.js";
|
|
2
|
+
import type { OmemPluginConfig } from "./config.js";
|
|
3
|
+
|
|
4
|
+
function sanitizeContent(text: string, maxLen: number): string {
|
|
5
|
+
let clean = text.replace(/<[\w-]+[^>]*>[\s\S]*?<\/[\w-]+>/g, "");
|
|
6
|
+
clean = clean.replace(/<[\w-]+[^>]*\/>/g, "");
|
|
7
|
+
clean = clean.replace(/\s+/g, " ").trim();
|
|
8
|
+
if (clean.length <= maxLen) return clean;
|
|
9
|
+
return clean.slice(0, maxLen) + "…[truncated]";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function truncateQuery(query: string, maxLen: number): string {
|
|
13
|
+
if (query.length <= maxLen) return query;
|
|
14
|
+
return query.slice(0, maxLen);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IngestOptions {
|
|
18
|
+
mode?: "smart" | "raw";
|
|
19
|
+
agentId?: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
parentSessionId?: string;
|
|
22
|
+
entityContext?: string;
|
|
23
|
+
tags?: string[];
|
|
24
|
+
projectName?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SearchResult {
|
|
28
|
+
memory: MemoryDto;
|
|
29
|
+
score: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SearchResponse {
|
|
33
|
+
results: SearchResult[];
|
|
34
|
+
trace?: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ListResponse {
|
|
38
|
+
memories: MemoryDto[];
|
|
39
|
+
limit: number;
|
|
40
|
+
offset: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ClusterSummary {
|
|
44
|
+
cluster_id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
summary: string;
|
|
47
|
+
member_count: number;
|
|
48
|
+
relevance_score: number;
|
|
49
|
+
key_memories: MemoryDto[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ClusteredRecallResult {
|
|
53
|
+
cluster_summaries: ClusterSummary[];
|
|
54
|
+
standalone_memories: MemoryDto[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ShouldRecallResponse {
|
|
58
|
+
should_recall: boolean;
|
|
59
|
+
query?: string;
|
|
60
|
+
reason?: string;
|
|
61
|
+
similarity_score?: number;
|
|
62
|
+
confidence?: number;
|
|
63
|
+
memories?: SearchResult[];
|
|
64
|
+
clustered?: ClusteredRecallResult;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface SessionRecallRecord {
|
|
68
|
+
session_id: string;
|
|
69
|
+
memory_ids: string[];
|
|
70
|
+
recall_type: string;
|
|
71
|
+
created_at: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SessionRecallListResponse {
|
|
75
|
+
recalls: SessionRecallRecord[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface MemoryDto {
|
|
79
|
+
id: string;
|
|
80
|
+
content: string;
|
|
81
|
+
l2_content?: string;
|
|
82
|
+
category: string;
|
|
83
|
+
memory_type: string;
|
|
84
|
+
state: string;
|
|
85
|
+
tags: string[];
|
|
86
|
+
source?: string;
|
|
87
|
+
tenant_id: string;
|
|
88
|
+
agent_id?: string;
|
|
89
|
+
importance: number;
|
|
90
|
+
created_at: string;
|
|
91
|
+
updated_at: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class OmemClient {
|
|
95
|
+
constructor(
|
|
96
|
+
private baseUrl: string,
|
|
97
|
+
private apiKey: string,
|
|
98
|
+
private config?: Partial<OmemPluginConfig>,
|
|
99
|
+
) {
|
|
100
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private getCfg<K extends keyof OmemPluginConfig>(key: K, fallback: OmemPluginConfig[K]): OmemPluginConfig[K] {
|
|
104
|
+
return this.config?.[key] ?? fallback;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private async request<T>(
|
|
108
|
+
path: string,
|
|
109
|
+
init: RequestInit = {},
|
|
110
|
+
timeoutMs?: number,
|
|
111
|
+
): Promise<T | null> {
|
|
112
|
+
const url = `${this.baseUrl}${path}`;
|
|
113
|
+
const controller = new AbortController();
|
|
114
|
+
const timeout = setTimeout(
|
|
115
|
+
() => controller.abort(),
|
|
116
|
+
timeoutMs ?? this.getCfg("requestTimeoutMs", 15000),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const res = await fetch(url, {
|
|
121
|
+
...init,
|
|
122
|
+
signal: controller.signal,
|
|
123
|
+
headers: {
|
|
124
|
+
"Content-Type": "application/json",
|
|
125
|
+
"X-API-Key": this.apiKey,
|
|
126
|
+
...(init.headers as Record<string, string>),
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (!res.ok) {
|
|
131
|
+
const errorBody = await res.text().catch(() => "");
|
|
132
|
+
logWarn(`${init.method ?? "GET"} ${path} → ${res.status} ${res.statusText}: ${errorBody}`);
|
|
133
|
+
throw new Error(`[omem] ${res.status} ${res.statusText}${errorBody ? ": " + errorBody : ""}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (res.status === 204) return null;
|
|
137
|
+
|
|
138
|
+
return (await res.json()) as T;
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if ((err as Error).name === "AbortError") {
|
|
141
|
+
logWarn(`${init.method ?? "GET"} ${path} timed out`);
|
|
142
|
+
throw new Error(`[omem] Request timed out (${timeoutMs ?? this.getCfg("requestTimeoutMs", 15000)}ms)`);
|
|
143
|
+
} else {
|
|
144
|
+
logError(`${init.method ?? "GET"} ${path} failed:`, err);
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
} finally {
|
|
148
|
+
clearTimeout(timeout);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private post<T>(path: string, body: unknown, timeoutMs?: number): Promise<T | null> {
|
|
153
|
+
return this.request<T>(path, {
|
|
154
|
+
method: "POST",
|
|
155
|
+
body: JSON.stringify(body),
|
|
156
|
+
}, timeoutMs);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private put<T>(path: string, body: unknown): Promise<T | null> {
|
|
160
|
+
return this.request<T>(path, {
|
|
161
|
+
method: "PUT",
|
|
162
|
+
body: JSON.stringify(body),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private del<T>(path: string): Promise<T | null> {
|
|
167
|
+
return this.request<T>(path, { method: "DELETE" });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async createMemory(
|
|
171
|
+
content: string,
|
|
172
|
+
tags?: string[],
|
|
173
|
+
source?: string,
|
|
174
|
+
scope?: string,
|
|
175
|
+
agentId?: string,
|
|
176
|
+
sessionId?: string,
|
|
177
|
+
visibility?: string,
|
|
178
|
+
category?: string,
|
|
179
|
+
): Promise<MemoryDto | null> {
|
|
180
|
+
const safeContent = sanitizeContent(content, this.getCfg("maxContentChars", 30000));
|
|
181
|
+
return this.post<MemoryDto>("/v1/memories", {
|
|
182
|
+
content: safeContent,
|
|
183
|
+
tags,
|
|
184
|
+
source,
|
|
185
|
+
scope,
|
|
186
|
+
agent_id: agentId,
|
|
187
|
+
session_id: sessionId,
|
|
188
|
+
visibility,
|
|
189
|
+
category,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async searchMemories(
|
|
194
|
+
query: string,
|
|
195
|
+
limit = 10,
|
|
196
|
+
scope?: string,
|
|
197
|
+
tags?: string[],
|
|
198
|
+
): Promise<SearchResult[]> {
|
|
199
|
+
const safeQ = truncateQuery(query, this.getCfg("maxQueryLength", 200));
|
|
200
|
+
const params = new URLSearchParams({ q: safeQ, limit: String(limit) });
|
|
201
|
+
if (scope) params.set("scope", scope);
|
|
202
|
+
if (tags && tags.length > 0) params.set("tags", tags.join(","));
|
|
203
|
+
const res = await this.request<SearchResponse>(
|
|
204
|
+
`/v1/memories/search?${params}`,
|
|
205
|
+
{},
|
|
206
|
+
20_000,
|
|
207
|
+
);
|
|
208
|
+
return res?.results ?? [];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async getMemory(id: string): Promise<MemoryDto | null> {
|
|
212
|
+
return this.request<MemoryDto>(`/v1/memories/${encodeURIComponent(id)}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async updateMemory(
|
|
216
|
+
id: string,
|
|
217
|
+
content: string,
|
|
218
|
+
tags?: string[],
|
|
219
|
+
): Promise<MemoryDto | null> {
|
|
220
|
+
return this.put<MemoryDto>(
|
|
221
|
+
`/v1/memories/${encodeURIComponent(id)}`,
|
|
222
|
+
{ content, tags },
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async deleteMemory(id: string): Promise<void> {
|
|
227
|
+
await this.del(`/v1/memories/${encodeURIComponent(id)}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async ingestMessages(
|
|
231
|
+
messages: Array<{ role: string; content: string }>,
|
|
232
|
+
opts: IngestOptions = {},
|
|
233
|
+
): Promise<unknown> {
|
|
234
|
+
const safeMessages = messages.map(m => ({
|
|
235
|
+
role: m.role,
|
|
236
|
+
content: sanitizeContent(m.content, this.getCfg("maxContentChars", 30000)),
|
|
237
|
+
}));
|
|
238
|
+
return this.post("/v1/memories", {
|
|
239
|
+
messages: safeMessages,
|
|
240
|
+
mode: opts.mode ?? "smart",
|
|
241
|
+
agent_id: opts.agentId,
|
|
242
|
+
session_id: opts.sessionId,
|
|
243
|
+
parent_session_id: opts.parentSessionId,
|
|
244
|
+
entity_context: opts.entityContext,
|
|
245
|
+
tags: opts.tags,
|
|
246
|
+
project_name: opts.projectName,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async getProfile(_query?: string): Promise<unknown> {
|
|
251
|
+
return this.request("/v1/profile");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async getStats(): Promise<unknown> {
|
|
255
|
+
return this.request("/v1/stats");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async listRecent(limit = 20): Promise<MemoryDto[]> {
|
|
259
|
+
const res = await this.request<ListResponse>(
|
|
260
|
+
`/v1/memories?limit=${limit}&offset=0`,
|
|
261
|
+
);
|
|
262
|
+
return res?.memories ?? [];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async createSpace(
|
|
266
|
+
name: string,
|
|
267
|
+
spaceType: string,
|
|
268
|
+
members?: Array<{ user_id: string; role: string }>,
|
|
269
|
+
): Promise<unknown> {
|
|
270
|
+
return this.post("/v1/spaces", { name, space_type: spaceType, members });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async listSpaces(): Promise<unknown[]> {
|
|
274
|
+
const res = await this.request<{ spaces: unknown[] }>("/v1/spaces");
|
|
275
|
+
return res?.spaces ?? [];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async addSpaceMember(
|
|
279
|
+
spaceId: string,
|
|
280
|
+
userId: string,
|
|
281
|
+
role: string,
|
|
282
|
+
): Promise<unknown> {
|
|
283
|
+
return this.post(
|
|
284
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/members`,
|
|
285
|
+
{ user_id: userId, role },
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async shareMemory(
|
|
290
|
+
memoryId: string,
|
|
291
|
+
targetSpace: string,
|
|
292
|
+
): Promise<unknown> {
|
|
293
|
+
return this.post(
|
|
294
|
+
`/v1/memories/${encodeURIComponent(memoryId)}/share`,
|
|
295
|
+
{ target_space: targetSpace },
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async pullMemory(
|
|
300
|
+
memoryId: string,
|
|
301
|
+
sourceSpace: string,
|
|
302
|
+
visibility?: string,
|
|
303
|
+
): Promise<unknown> {
|
|
304
|
+
return this.post(
|
|
305
|
+
`/v1/memories/${encodeURIComponent(memoryId)}/pull`,
|
|
306
|
+
{ source_space: sourceSpace, visibility },
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async reshareMemory(
|
|
311
|
+
memoryId: string,
|
|
312
|
+
targetSpace?: string,
|
|
313
|
+
): Promise<unknown> {
|
|
314
|
+
return this.post(
|
|
315
|
+
`/v1/memories/${encodeURIComponent(memoryId)}/reshare`,
|
|
316
|
+
{ target_space: targetSpace },
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async shouldRecall(
|
|
321
|
+
query_text: string,
|
|
322
|
+
last_query_text: string | undefined,
|
|
323
|
+
session_id: string,
|
|
324
|
+
similarity_threshold?: number,
|
|
325
|
+
max_results?: number,
|
|
326
|
+
project_tags?: string[],
|
|
327
|
+
): Promise<ShouldRecallResponse | null> {
|
|
328
|
+
const res = await this.post<ShouldRecallResponse>("/v1/should-recall", {
|
|
329
|
+
query_text,
|
|
330
|
+
last_query_text,
|
|
331
|
+
session_id,
|
|
332
|
+
similarity_threshold,
|
|
333
|
+
max_results,
|
|
334
|
+
project_tags,
|
|
335
|
+
}, 20_000);
|
|
336
|
+
return res;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async recordSessionRecall(
|
|
340
|
+
session_id: string,
|
|
341
|
+
memory_ids: string[],
|
|
342
|
+
recall_type: string,
|
|
343
|
+
query_text?: string,
|
|
344
|
+
similarity_score?: number,
|
|
345
|
+
llm_confidence?: number,
|
|
346
|
+
): Promise<unknown | null> {
|
|
347
|
+
const body = {
|
|
348
|
+
session_id,
|
|
349
|
+
memory_ids,
|
|
350
|
+
recall_type,
|
|
351
|
+
query_text: query_text ?? "",
|
|
352
|
+
similarity_score: similarity_score ?? 0,
|
|
353
|
+
llm_confidence: llm_confidence ?? 0,
|
|
354
|
+
};
|
|
355
|
+
const res = await this.post("/v1/session-recalls", body, 20_000);
|
|
356
|
+
return res;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async listSessionRecalls(
|
|
360
|
+
session_id: string,
|
|
361
|
+
): Promise<SessionRecallRecord[]> {
|
|
362
|
+
const params = new URLSearchParams({ session_id });
|
|
363
|
+
const res = await this.request<SessionRecallListResponse>(
|
|
364
|
+
`/v1/session-recalls?${params}`,
|
|
365
|
+
);
|
|
366
|
+
return res?.recalls ?? [];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async sessionIngest(
|
|
370
|
+
messages: Array<{ role: string; content: string }>,
|
|
371
|
+
sessionId?: string,
|
|
372
|
+
agentId?: string,
|
|
373
|
+
sessionTitle?: string,
|
|
374
|
+
projectName?: string,
|
|
375
|
+
parentSessionId?: string,
|
|
376
|
+
): Promise<unknown> {
|
|
377
|
+
return this.post("/v1/memories/session-ingest", {
|
|
378
|
+
messages,
|
|
379
|
+
session_id: sessionId,
|
|
380
|
+
agent_id: agentId,
|
|
381
|
+
session_title: sessionTitle,
|
|
382
|
+
project_name: projectName,
|
|
383
|
+
parent_session_id: parentSessionId,
|
|
384
|
+
}, 60000);
|
|
385
|
+
}
|
|
386
|
+
}
|