@meshagent/meshagent 0.34.0 → 0.35.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/CHANGELOG.md +5 -0
- package/dist/browser/memory-client.d.ts +200 -0
- package/dist/browser/memory-client.js +532 -6
- package/dist/browser/meshagent-client.d.ts +140 -0
- package/dist/browser/meshagent-client.js +406 -15
- package/dist/esm/memory-client.d.ts +200 -0
- package/dist/esm/memory-client.js +532 -6
- package/dist/esm/meshagent-client.d.ts +140 -0
- package/dist/esm/meshagent-client.js +406 -15
- package/dist/node/memory-client.d.ts +200 -0
- package/dist/node/memory-client.js +532 -6
- package/dist/node/meshagent-client.d.ts +140 -0
- package/dist/node/meshagent-client.js +406 -15
- package/package.json +1 -1
|
@@ -1,11 +1,386 @@
|
|
|
1
1
|
import { EmptyContent, JsonContent } from "./response";
|
|
2
2
|
import { RoomServerException } from "./room-server-client";
|
|
3
|
+
const globalScope = globalThis;
|
|
4
|
+
function bytesToBase64(bytes) {
|
|
5
|
+
if (globalScope.Buffer) {
|
|
6
|
+
return globalScope.Buffer.from(bytes).toString("base64");
|
|
7
|
+
}
|
|
8
|
+
if (!globalScope.btoa) {
|
|
9
|
+
throw new Error("base64 encoding is not available in this runtime");
|
|
10
|
+
}
|
|
11
|
+
let binary = "";
|
|
12
|
+
for (const byte of bytes) {
|
|
13
|
+
binary += String.fromCharCode(byte);
|
|
14
|
+
}
|
|
15
|
+
return globalScope.btoa(binary);
|
|
16
|
+
}
|
|
17
|
+
function base64ToBytes(base64) {
|
|
18
|
+
if (globalScope.Buffer) {
|
|
19
|
+
return Uint8Array.from(globalScope.Buffer.from(base64, "base64"));
|
|
20
|
+
}
|
|
21
|
+
if (!globalScope.atob) {
|
|
22
|
+
throw new Error("base64 decoding is not available in this runtime");
|
|
23
|
+
}
|
|
24
|
+
const binary = globalScope.atob(base64);
|
|
25
|
+
const bytes = new Uint8Array(binary.length);
|
|
26
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
27
|
+
bytes[index] = binary.charCodeAt(index);
|
|
28
|
+
}
|
|
29
|
+
return bytes;
|
|
30
|
+
}
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function unexpectedResponse(operation) {
|
|
35
|
+
return new RoomServerException(`unexpected return type from memory.${operation}`);
|
|
36
|
+
}
|
|
37
|
+
function requireString(value, operation) {
|
|
38
|
+
if (typeof value !== "string") {
|
|
39
|
+
throw unexpectedResponse(operation);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function toOptionalNumber(value) {
|
|
44
|
+
return typeof value === "number" ? value : undefined;
|
|
45
|
+
}
|
|
46
|
+
function toOptionalInteger(value) {
|
|
47
|
+
return typeof value === "number" && Number.isInteger(value) ? value : undefined;
|
|
48
|
+
}
|
|
49
|
+
function toStringArray(value, operation) {
|
|
50
|
+
if (value == null) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
54
|
+
throw unexpectedResponse(operation);
|
|
55
|
+
}
|
|
56
|
+
return [...value];
|
|
57
|
+
}
|
|
58
|
+
function toStringMap(value, operation) {
|
|
59
|
+
if (value == null) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
if (!isRecord(value)) {
|
|
63
|
+
throw unexpectedResponse(operation);
|
|
64
|
+
}
|
|
65
|
+
const metadata = {};
|
|
66
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
67
|
+
if (typeof entryValue !== "string") {
|
|
68
|
+
throw unexpectedResponse(operation);
|
|
69
|
+
}
|
|
70
|
+
metadata[key] = entryValue;
|
|
71
|
+
}
|
|
72
|
+
return metadata;
|
|
73
|
+
}
|
|
74
|
+
function encodeMemoryRecordValue(value) {
|
|
75
|
+
if (value instanceof Uint8Array) {
|
|
76
|
+
return {
|
|
77
|
+
encoding: "base64",
|
|
78
|
+
data: bytesToBase64(value),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (value instanceof Date) {
|
|
82
|
+
return value.toISOString().replace("+00:00", "Z");
|
|
83
|
+
}
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
return value.map((item) => encodeMemoryRecordValue(item));
|
|
86
|
+
}
|
|
87
|
+
if (isRecord(value)) {
|
|
88
|
+
return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [key, encodeMemoryRecordValue(entryValue)]));
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function decodeRowsValue(value, operation) {
|
|
93
|
+
if (!isRecord(value) || typeof value.type !== "string") {
|
|
94
|
+
throw unexpectedResponse(operation);
|
|
95
|
+
}
|
|
96
|
+
switch (value.type) {
|
|
97
|
+
case "null":
|
|
98
|
+
return null;
|
|
99
|
+
case "bool":
|
|
100
|
+
if (typeof value.value !== "boolean") {
|
|
101
|
+
throw unexpectedResponse(operation);
|
|
102
|
+
}
|
|
103
|
+
return value.value;
|
|
104
|
+
case "int":
|
|
105
|
+
if (typeof value.value !== "number") {
|
|
106
|
+
throw unexpectedResponse(operation);
|
|
107
|
+
}
|
|
108
|
+
return Math.trunc(value.value);
|
|
109
|
+
case "float":
|
|
110
|
+
if (typeof value.value !== "number") {
|
|
111
|
+
throw unexpectedResponse(operation);
|
|
112
|
+
}
|
|
113
|
+
return value.value;
|
|
114
|
+
case "text":
|
|
115
|
+
case "date":
|
|
116
|
+
case "timestamp":
|
|
117
|
+
if (typeof value.value !== "string") {
|
|
118
|
+
throw unexpectedResponse(operation);
|
|
119
|
+
}
|
|
120
|
+
return value.value;
|
|
121
|
+
case "binary":
|
|
122
|
+
if (typeof value.data !== "string") {
|
|
123
|
+
throw unexpectedResponse(operation);
|
|
124
|
+
}
|
|
125
|
+
return base64ToBytes(value.data);
|
|
126
|
+
case "list":
|
|
127
|
+
if (!Array.isArray(value.items)) {
|
|
128
|
+
throw unexpectedResponse(operation);
|
|
129
|
+
}
|
|
130
|
+
return value.items.map((item) => decodeRowsValue(item, operation));
|
|
131
|
+
case "struct":
|
|
132
|
+
if (!Array.isArray(value.fields)) {
|
|
133
|
+
throw unexpectedResponse(operation);
|
|
134
|
+
}
|
|
135
|
+
return Object.fromEntries(value.fields.map((field) => {
|
|
136
|
+
if (!isRecord(field) || typeof field.name !== "string") {
|
|
137
|
+
throw unexpectedResponse(operation);
|
|
138
|
+
}
|
|
139
|
+
return [field.name, decodeRowsValue(field.value, operation)];
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function recordsFromRowsChunk(value, operation) {
|
|
144
|
+
if (!isRecord(value) || value.kind !== "rows" || !Array.isArray(value.rows)) {
|
|
145
|
+
throw unexpectedResponse(operation);
|
|
146
|
+
}
|
|
147
|
+
return value.rows.map((row) => {
|
|
148
|
+
if (!isRecord(row) || !Array.isArray(row.columns)) {
|
|
149
|
+
throw unexpectedResponse(operation);
|
|
150
|
+
}
|
|
151
|
+
return Object.fromEntries(row.columns.map((column) => {
|
|
152
|
+
if (!isRecord(column) || typeof column.name !== "string") {
|
|
153
|
+
throw unexpectedResponse(operation);
|
|
154
|
+
}
|
|
155
|
+
return [column.name, decodeRowsValue(column.value, operation)];
|
|
156
|
+
}));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function parseMemoryEntityRecord(value, operation) {
|
|
160
|
+
if (!isRecord(value) || typeof value.name !== "string") {
|
|
161
|
+
throw unexpectedResponse(operation);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
entityId: typeof value.entity_id === "string" ? value.entity_id : null,
|
|
165
|
+
name: value.name,
|
|
166
|
+
entityType: typeof value.entity_type === "string" ? value.entity_type : null,
|
|
167
|
+
context: typeof value.context === "string" ? value.context : null,
|
|
168
|
+
confidence: toOptionalNumber(value.confidence) ?? null,
|
|
169
|
+
createdAt: typeof value.created_at === "string" ? value.created_at : null,
|
|
170
|
+
validAt: typeof value.valid_at === "string" ? value.valid_at : null,
|
|
171
|
+
metadata: toStringMap(value.metadata, operation) ?? null,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function memoryEntityRecordJson(record) {
|
|
175
|
+
return {
|
|
176
|
+
entity_id: record.entityId ?? null,
|
|
177
|
+
name: record.name,
|
|
178
|
+
entity_type: record.entityType ?? null,
|
|
179
|
+
context: record.context ?? null,
|
|
180
|
+
confidence: record.confidence ?? null,
|
|
181
|
+
created_at: record.createdAt ?? null,
|
|
182
|
+
valid_at: record.validAt ?? null,
|
|
183
|
+
metadata: record.metadata ?? null,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function parseMemoryRelationshipRecord(value, operation) {
|
|
187
|
+
if (!isRecord(value) || typeof value.source_entity_id !== "string" || typeof value.target_entity_id !== "string") {
|
|
188
|
+
throw unexpectedResponse(operation);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
sourceEntityId: value.source_entity_id,
|
|
192
|
+
targetEntityId: value.target_entity_id,
|
|
193
|
+
relationshipType: typeof value.relationship_type === "string" && value.relationship_type.length > 0 ? value.relationship_type : "RELATED_TO",
|
|
194
|
+
description: typeof value.description === "string" ? value.description : null,
|
|
195
|
+
confidence: toOptionalNumber(value.confidence) ?? null,
|
|
196
|
+
createdAt: typeof value.created_at === "string" ? value.created_at : null,
|
|
197
|
+
validAt: typeof value.valid_at === "string" ? value.valid_at : null,
|
|
198
|
+
expiredAt: typeof value.expired_at === "string" ? value.expired_at : null,
|
|
199
|
+
invalidAt: typeof value.invalid_at === "string" ? value.invalid_at : null,
|
|
200
|
+
sourceEntityName: typeof value.source_entity_name === "string" ? value.source_entity_name : null,
|
|
201
|
+
targetEntityName: typeof value.target_entity_name === "string" ? value.target_entity_name : null,
|
|
202
|
+
metadata: toStringMap(value.metadata, operation) ?? null,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function memoryRelationshipRecordJson(record) {
|
|
206
|
+
return {
|
|
207
|
+
source_entity_id: record.sourceEntityId,
|
|
208
|
+
target_entity_id: record.targetEntityId,
|
|
209
|
+
relationship_type: record.relationshipType ?? "RELATED_TO",
|
|
210
|
+
description: record.description ?? null,
|
|
211
|
+
confidence: record.confidence ?? null,
|
|
212
|
+
created_at: record.createdAt ?? null,
|
|
213
|
+
valid_at: record.validAt ?? null,
|
|
214
|
+
expired_at: record.expiredAt ?? null,
|
|
215
|
+
invalid_at: record.invalidAt ?? null,
|
|
216
|
+
source_entity_name: record.sourceEntityName ?? null,
|
|
217
|
+
target_entity_name: record.targetEntityName ?? null,
|
|
218
|
+
metadata: record.metadata ?? null,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function parseMemoryDatasetSummary(value, operation) {
|
|
222
|
+
if (!isRecord(value)) {
|
|
223
|
+
throw unexpectedResponse(operation);
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
name: requireString(value.name, operation),
|
|
227
|
+
rows: toOptionalInteger(value.rows) ?? 0,
|
|
228
|
+
columns: toStringArray(value.columns, operation) ?? [],
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function parseMemoryDetails(value, operation) {
|
|
232
|
+
if (!isRecord(value)) {
|
|
233
|
+
throw unexpectedResponse(operation);
|
|
234
|
+
}
|
|
235
|
+
const datasets = value.datasets;
|
|
236
|
+
if (datasets != null && !Array.isArray(datasets)) {
|
|
237
|
+
throw unexpectedResponse(operation);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
name: requireString(value.name, operation),
|
|
241
|
+
namespace: toStringArray(value.namespace, operation) ?? null,
|
|
242
|
+
path: requireString(value.path, operation),
|
|
243
|
+
datasets: (datasets ?? []).map((entry) => parseMemoryDatasetSummary(entry, operation)),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function parseMemoryIngestStats(value, operation) {
|
|
247
|
+
if (!isRecord(value)) {
|
|
248
|
+
throw unexpectedResponse(operation);
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
entities: toOptionalInteger(value.entities) ?? 0,
|
|
252
|
+
relationships: toOptionalInteger(value.relationships) ?? 0,
|
|
253
|
+
sources: toOptionalInteger(value.sources) ?? 0,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function parseMemoryIngestResult(value, operation) {
|
|
257
|
+
if (!isRecord(value)) {
|
|
258
|
+
throw unexpectedResponse(operation);
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
name: requireString(value.name, operation),
|
|
262
|
+
stats: parseMemoryIngestStats(value.stats, operation),
|
|
263
|
+
entityIds: toStringArray(value.entity_ids, operation) ?? [],
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function parseMemoryRecallRelationship(value, operation) {
|
|
267
|
+
if (!isRecord(value)) {
|
|
268
|
+
throw unexpectedResponse(operation);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
sourceEntityId: requireString(value.source_entity_id, operation),
|
|
272
|
+
targetEntityId: requireString(value.target_entity_id, operation),
|
|
273
|
+
relationshipType: requireString(value.relationship_type, operation),
|
|
274
|
+
description: typeof value.description === "string" ? value.description : null,
|
|
275
|
+
createdAt: typeof value.created_at === "string" ? value.created_at : null,
|
|
276
|
+
validAt: typeof value.valid_at === "string" ? value.valid_at : null,
|
|
277
|
+
expiredAt: typeof value.expired_at === "string" ? value.expired_at : null,
|
|
278
|
+
invalidAt: typeof value.invalid_at === "string" ? value.invalid_at : null,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function parseMemoryRecallItem(value, operation) {
|
|
282
|
+
if (!isRecord(value) || typeof value.score !== "number") {
|
|
283
|
+
throw unexpectedResponse(operation);
|
|
284
|
+
}
|
|
285
|
+
const relationships = value.relationships;
|
|
286
|
+
if (relationships != null && !Array.isArray(relationships)) {
|
|
287
|
+
throw unexpectedResponse(operation);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
entityId: requireString(value.entity_id, operation),
|
|
291
|
+
name: requireString(value.name, operation),
|
|
292
|
+
entityType: requireString(value.entity_type, operation),
|
|
293
|
+
context: typeof value.context === "string" ? value.context : null,
|
|
294
|
+
confidence: toOptionalNumber(value.confidence) ?? null,
|
|
295
|
+
createdAt: typeof value.created_at === "string" ? value.created_at : null,
|
|
296
|
+
validAt: typeof value.valid_at === "string" ? value.valid_at : null,
|
|
297
|
+
score: value.score,
|
|
298
|
+
relationships: (relationships ?? []).map((entry) => parseMemoryRecallRelationship(entry, operation)),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function parseMemoryRecallResult(value, operation) {
|
|
302
|
+
if (!isRecord(value)) {
|
|
303
|
+
throw unexpectedResponse(operation);
|
|
304
|
+
}
|
|
305
|
+
const items = value.items;
|
|
306
|
+
if (items != null && !Array.isArray(items)) {
|
|
307
|
+
throw unexpectedResponse(operation);
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
name: requireString(value.name, operation),
|
|
311
|
+
query: requireString(value.query, operation),
|
|
312
|
+
items: (items ?? []).map((entry) => parseMemoryRecallItem(entry, operation)),
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function parseDeleteEntitiesResult(value, operation) {
|
|
316
|
+
if (!isRecord(value)) {
|
|
317
|
+
throw unexpectedResponse(operation);
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
name: requireString(value.name, operation),
|
|
321
|
+
deletedEntities: toOptionalInteger(value.deleted_entities) ?? 0,
|
|
322
|
+
deletedRelationships: toOptionalInteger(value.deleted_relationships) ?? 0,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function parseRelationshipSelector(value, operation) {
|
|
326
|
+
if (!isRecord(value)) {
|
|
327
|
+
throw unexpectedResponse(operation);
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
sourceEntityId: requireString(value.source_entity_id, operation),
|
|
331
|
+
targetEntityId: requireString(value.target_entity_id, operation),
|
|
332
|
+
relationshipType: typeof value.relationship_type === "string" ? value.relationship_type : null,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function relationshipSelectorJson(selector) {
|
|
336
|
+
return {
|
|
337
|
+
source_entity_id: selector.sourceEntityId,
|
|
338
|
+
target_entity_id: selector.targetEntityId,
|
|
339
|
+
relationship_type: selector.relationshipType ?? null,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function parseDeleteRelationshipsResult(value, operation) {
|
|
343
|
+
if (!isRecord(value)) {
|
|
344
|
+
throw unexpectedResponse(operation);
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
name: requireString(value.name, operation),
|
|
348
|
+
deletedRelationships: toOptionalInteger(value.deleted_relationships) ?? 0,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function parseOptimizeDatasetStats(value, operation) {
|
|
352
|
+
if (!isRecord(value)) {
|
|
353
|
+
throw unexpectedResponse(operation);
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
dataset: requireString(value.dataset, operation),
|
|
357
|
+
fragmentsAdded: toOptionalInteger(value.fragments_added) ?? 0,
|
|
358
|
+
fragmentsRemoved: toOptionalInteger(value.fragments_removed) ?? 0,
|
|
359
|
+
filesAdded: toOptionalInteger(value.files_added) ?? 0,
|
|
360
|
+
filesRemoved: toOptionalInteger(value.files_removed) ?? 0,
|
|
361
|
+
oldVersionsRemoved: toOptionalInteger(value.old_versions_removed) ?? 0,
|
|
362
|
+
bytesRemoved: toOptionalInteger(value.bytes_removed) ?? 0,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function parseOptimizeResult(value, operation) {
|
|
366
|
+
if (!isRecord(value)) {
|
|
367
|
+
throw unexpectedResponse(operation);
|
|
368
|
+
}
|
|
369
|
+
const datasets = value.datasets;
|
|
370
|
+
if (datasets != null && !Array.isArray(datasets)) {
|
|
371
|
+
throw unexpectedResponse(operation);
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
name: requireString(value.name, operation),
|
|
375
|
+
datasets: (datasets ?? []).map((entry) => parseOptimizeDatasetStats(entry, operation)),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
3
378
|
export class MemoryClient {
|
|
4
379
|
constructor({ room }) {
|
|
5
380
|
this.room = room;
|
|
6
381
|
}
|
|
7
382
|
unexpectedResponse(operation) {
|
|
8
|
-
return
|
|
383
|
+
return unexpectedResponse(operation);
|
|
9
384
|
}
|
|
10
385
|
async invoke(operation, input) {
|
|
11
386
|
const response = await this.room.invoke({
|
|
@@ -21,13 +396,16 @@ export class MemoryClient {
|
|
|
21
396
|
}
|
|
22
397
|
throw this.unexpectedResponse(operation);
|
|
23
398
|
}
|
|
24
|
-
|
|
25
|
-
const response = await this.invoke("list", {
|
|
26
|
-
namespace: params?.namespace ?? null,
|
|
27
|
-
});
|
|
399
|
+
expectJsonResponse(response, operation) {
|
|
28
400
|
if (!(response instanceof JsonContent)) {
|
|
29
|
-
throw this.unexpectedResponse(
|
|
401
|
+
throw this.unexpectedResponse(operation);
|
|
30
402
|
}
|
|
403
|
+
return response;
|
|
404
|
+
}
|
|
405
|
+
async list(params) {
|
|
406
|
+
const response = this.expectJsonResponse(await this.invoke("list", {
|
|
407
|
+
namespace: params?.namespace ?? null,
|
|
408
|
+
}), "list");
|
|
31
409
|
const memories = response.json["memories"];
|
|
32
410
|
if (!Array.isArray(memories)) {
|
|
33
411
|
return [];
|
|
@@ -49,4 +427,152 @@ export class MemoryClient {
|
|
|
49
427
|
ignore_missing: params.ignoreMissing ?? false,
|
|
50
428
|
});
|
|
51
429
|
}
|
|
430
|
+
async inspect(params) {
|
|
431
|
+
const response = this.expectJsonResponse(await this.invoke("inspect", {
|
|
432
|
+
name: params.name,
|
|
433
|
+
namespace: params.namespace ?? null,
|
|
434
|
+
}), "inspect");
|
|
435
|
+
return parseMemoryDetails(response.json, "inspect");
|
|
436
|
+
}
|
|
437
|
+
async query(params) {
|
|
438
|
+
const response = this.expectJsonResponse(await this.invoke("query", {
|
|
439
|
+
name: params.name,
|
|
440
|
+
namespace: params.namespace ?? null,
|
|
441
|
+
statement: params.statement,
|
|
442
|
+
}), "query");
|
|
443
|
+
const results = response.json["results"];
|
|
444
|
+
if (Array.isArray(results)) {
|
|
445
|
+
return results.map((entry) => {
|
|
446
|
+
if (!isRecord(entry)) {
|
|
447
|
+
throw this.unexpectedResponse("query");
|
|
448
|
+
}
|
|
449
|
+
return { ...entry };
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return recordsFromRowsChunk(response.json, "query");
|
|
453
|
+
}
|
|
454
|
+
async upsertTable(params) {
|
|
455
|
+
await this.invoke("upsert_table", {
|
|
456
|
+
name: params.name,
|
|
457
|
+
namespace: params.namespace ?? null,
|
|
458
|
+
table: params.table,
|
|
459
|
+
records_json: JSON.stringify(encodeMemoryRecordValue(params.records)),
|
|
460
|
+
merge: params.merge ?? true,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
async upsertNodes(params) {
|
|
464
|
+
await this.invoke("upsert_nodes", {
|
|
465
|
+
name: params.name,
|
|
466
|
+
namespace: params.namespace ?? null,
|
|
467
|
+
records_json: JSON.stringify(params.records.map((record) => memoryEntityRecordJson(record))),
|
|
468
|
+
merge: params.merge ?? true,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
async upsertRelationships(params) {
|
|
472
|
+
await this.invoke("upsert_relationships", {
|
|
473
|
+
name: params.name,
|
|
474
|
+
namespace: params.namespace ?? null,
|
|
475
|
+
records_json: JSON.stringify(params.records.map((record) => memoryRelationshipRecordJson(record))),
|
|
476
|
+
merge: params.merge ?? true,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
async ingestText(params) {
|
|
480
|
+
const response = this.expectJsonResponse(await this.invoke("ingest_text", {
|
|
481
|
+
name: params.name,
|
|
482
|
+
namespace: params.namespace ?? null,
|
|
483
|
+
text: params.text,
|
|
484
|
+
strategy: params.strategy ?? "heuristic",
|
|
485
|
+
llm_model: params.llmModel ?? null,
|
|
486
|
+
llm_temperature: params.llmTemperature ?? null,
|
|
487
|
+
}), "ingest_text");
|
|
488
|
+
return parseMemoryIngestResult(response.json, "ingest_text");
|
|
489
|
+
}
|
|
490
|
+
async ingestImage(params) {
|
|
491
|
+
const response = this.expectJsonResponse(await this.invoke("ingest_image", {
|
|
492
|
+
name: params.name,
|
|
493
|
+
namespace: params.namespace ?? null,
|
|
494
|
+
caption: params.caption ?? null,
|
|
495
|
+
data_base64: params.data != null ? bytesToBase64(params.data) : null,
|
|
496
|
+
mime_type: params.mimeType ?? null,
|
|
497
|
+
source: params.source ?? null,
|
|
498
|
+
annotations_json: params.annotations != null ? JSON.stringify(params.annotations) : null,
|
|
499
|
+
strategy: params.strategy ?? "heuristic",
|
|
500
|
+
llm_model: params.llmModel ?? null,
|
|
501
|
+
llm_temperature: params.llmTemperature ?? null,
|
|
502
|
+
}), "ingest_image");
|
|
503
|
+
return parseMemoryIngestResult(response.json, "ingest_image");
|
|
504
|
+
}
|
|
505
|
+
async ingestFile(params) {
|
|
506
|
+
const response = this.expectJsonResponse(await this.invoke("ingest_file", {
|
|
507
|
+
name: params.name,
|
|
508
|
+
namespace: params.namespace ?? null,
|
|
509
|
+
path: params.path ?? null,
|
|
510
|
+
text: params.text ?? null,
|
|
511
|
+
mime_type: params.mimeType ?? null,
|
|
512
|
+
strategy: params.strategy ?? "heuristic",
|
|
513
|
+
llm_model: params.llmModel ?? null,
|
|
514
|
+
llm_temperature: params.llmTemperature ?? null,
|
|
515
|
+
}), "ingest_file");
|
|
516
|
+
return parseMemoryIngestResult(response.json, "ingest_file");
|
|
517
|
+
}
|
|
518
|
+
async ingestFromTable(params) {
|
|
519
|
+
const response = this.expectJsonResponse(await this.invoke("ingest_from_table", {
|
|
520
|
+
name: params.name,
|
|
521
|
+
namespace: params.namespace ?? null,
|
|
522
|
+
table: params.table,
|
|
523
|
+
text_columns: params.textColumns ?? null,
|
|
524
|
+
table_namespace: params.tableNamespace ?? null,
|
|
525
|
+
limit: params.limit ?? null,
|
|
526
|
+
strategy: params.strategy ?? "heuristic",
|
|
527
|
+
llm_model: params.llmModel ?? null,
|
|
528
|
+
llm_temperature: params.llmTemperature ?? null,
|
|
529
|
+
}), "ingest_from_table");
|
|
530
|
+
return parseMemoryIngestResult(response.json, "ingest_from_table");
|
|
531
|
+
}
|
|
532
|
+
async ingestFromStorage(params) {
|
|
533
|
+
const response = this.expectJsonResponse(await this.invoke("ingest_from_storage", {
|
|
534
|
+
name: params.name,
|
|
535
|
+
namespace: params.namespace ?? null,
|
|
536
|
+
paths: params.paths,
|
|
537
|
+
strategy: params.strategy ?? "heuristic",
|
|
538
|
+
llm_model: params.llmModel ?? null,
|
|
539
|
+
llm_temperature: params.llmTemperature ?? null,
|
|
540
|
+
}), "ingest_from_storage");
|
|
541
|
+
return parseMemoryIngestResult(response.json, "ingest_from_storage");
|
|
542
|
+
}
|
|
543
|
+
async recall(params) {
|
|
544
|
+
const response = this.expectJsonResponse(await this.invoke("recall", {
|
|
545
|
+
name: params.name,
|
|
546
|
+
namespace: params.namespace ?? null,
|
|
547
|
+
query: params.query,
|
|
548
|
+
limit: params.limit ?? 5,
|
|
549
|
+
include_relationships: params.includeRelationships ?? true,
|
|
550
|
+
}), "recall");
|
|
551
|
+
return parseMemoryRecallResult(response.json, "recall");
|
|
552
|
+
}
|
|
553
|
+
async deleteEntities(params) {
|
|
554
|
+
const response = this.expectJsonResponse(await this.invoke("delete_entities", {
|
|
555
|
+
name: params.name,
|
|
556
|
+
namespace: params.namespace ?? null,
|
|
557
|
+
entity_ids: params.entityIds,
|
|
558
|
+
}), "delete_entities");
|
|
559
|
+
return parseDeleteEntitiesResult(response.json, "delete_entities");
|
|
560
|
+
}
|
|
561
|
+
async deleteRelationships(params) {
|
|
562
|
+
const response = this.expectJsonResponse(await this.invoke("delete_relationships", {
|
|
563
|
+
name: params.name,
|
|
564
|
+
namespace: params.namespace ?? null,
|
|
565
|
+
relationships: params.relationships.map((relationship) => relationshipSelectorJson(relationship)),
|
|
566
|
+
}), "delete_relationships");
|
|
567
|
+
return parseDeleteRelationshipsResult(response.json, "delete_relationships");
|
|
568
|
+
}
|
|
569
|
+
async optimize(params) {
|
|
570
|
+
const response = this.expectJsonResponse(await this.invoke("optimize", {
|
|
571
|
+
name: params.name,
|
|
572
|
+
namespace: params.namespace ?? null,
|
|
573
|
+
compact: params.compact ?? true,
|
|
574
|
+
cleanup: params.cleanup ?? true,
|
|
575
|
+
}), "optimize");
|
|
576
|
+
return parseOptimizeResult(response.json, "optimize");
|
|
577
|
+
}
|
|
52
578
|
}
|